web-to-print 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/canvas-helpers-A6rp5rPD.js +765 -0
- package/dist/cjs/index-IFGFRm-i.js +1649 -0
- package/dist/cjs/index.cjs.js +232 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/logo-BUX-b45R.js +18 -0
- package/dist/cjs/web-to-print.cjs.js +25 -0
- package/dist/cjs/wtp-editor_2.cjs.entry.js +12386 -0
- package/dist/cjs/wtp-logo-renderer.cjs.entry.js +353 -0
- package/dist/cjs/wtp-print-area-editor.cjs.entry.js +431 -0
- package/dist/collection/collection-manifest.json +16 -0
- package/dist/collection/components/wtp-editor/wtp-editor.css +124 -0
- package/dist/collection/components/wtp-editor/wtp-editor.js +1114 -0
- package/dist/collection/components/wtp-logo-renderer/wtp-logo-renderer.css +30 -0
- package/dist/collection/components/wtp-logo-renderer/wtp-logo-renderer.js +455 -0
- package/dist/collection/components/wtp-logo-upload/wtp-logo-upload.css +428 -0
- package/dist/collection/components/wtp-logo-upload/wtp-logo-upload.js +573 -0
- package/dist/collection/components/wtp-print-area-editor/wtp-print-area-editor.css +20 -0
- package/dist/collection/components/wtp-print-area-editor/wtp-print-area-editor.js +600 -0
- package/dist/collection/examples/schaeffler--big.svg +1 -0
- package/dist/collection/index.js +8 -0
- package/dist/collection/types/editor.js +1 -0
- package/dist/collection/types/index.js +2 -0
- package/dist/collection/types/labels.js +30 -0
- package/dist/collection/types/logo.js +13 -0
- package/dist/collection/utils/background-removal.js +717 -0
- package/dist/collection/utils/canvas-helpers.js +380 -0
- package/dist/collection/utils/format-detection.js +48 -0
- package/dist/collection/utils/html-render-helpers.js +106 -0
- package/dist/collection/utils/image-preview.js +54 -0
- package/dist/collection/utils/logo-validation.js +141 -0
- package/dist/collection/utils/pdf-export.js +224 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/p-5qCsRzlt.js +1 -0
- package/dist/components/p-Bn9gR_8e.js +1 -0
- package/dist/components/p-D8pVJRuX.js +1 -0
- package/dist/components/wtp-editor.d.ts +11 -0
- package/dist/components/wtp-editor.js +1 -0
- package/dist/components/wtp-logo-renderer.d.ts +11 -0
- package/dist/components/wtp-logo-renderer.js +1 -0
- package/dist/components/wtp-logo-upload.d.ts +11 -0
- package/dist/components/wtp-logo-upload.js +1 -0
- package/dist/components/wtp-print-area-editor.d.ts +11 -0
- package/dist/components/wtp-print-area-editor.js +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/canvas-helpers-CK8OAq2J.js +748 -0
- package/dist/esm/index-CUetmLbL.js +1641 -0
- package/dist/esm/index.js +228 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/logo-D8pVJRuX.js +15 -0
- package/dist/esm/web-to-print.js +21 -0
- package/dist/esm/wtp-editor_2.entry.js +12383 -0
- package/dist/esm/wtp-logo-renderer.entry.js +351 -0
- package/dist/esm/wtp-print-area-editor.entry.js +429 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/components/wtp-editor/wtp-editor.d.ts +101 -0
- package/dist/types/components/wtp-logo-renderer/wtp-logo-renderer.d.ts +55 -0
- package/dist/types/components/wtp-logo-upload/wtp-logo-upload.d.ts +76 -0
- package/dist/types/components/wtp-print-area-editor/wtp-print-area-editor.d.ts +43 -0
- package/dist/types/components.d.ts +507 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/stencil-public-runtime.d.ts +1860 -0
- package/dist/types/types/editor.d.ts +79 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types/types/labels.d.ts +30 -0
- package/dist/types/types/logo.d.ts +47 -0
- package/dist/types/utils/background-removal.d.ts +95 -0
- package/dist/types/utils/canvas-helpers.d.ts +60 -0
- package/dist/types/utils/format-detection.d.ts +4 -0
- package/dist/types/utils/html-render-helpers.d.ts +44 -0
- package/dist/types/utils/image-preview.d.ts +13 -0
- package/dist/types/utils/logo-validation.d.ts +2 -0
- package/dist/types/utils/pdf-export.d.ts +32 -0
- package/dist/web-to-print/index.esm.js +1 -0
- package/dist/web-to-print/p-611ec561.entry.js +1 -0
- package/dist/web-to-print/p-703e4c52.entry.js +1 -0
- package/dist/web-to-print/p-CK8OAq2J.js +1 -0
- package/dist/web-to-print/p-CUetmLbL.js +2 -0
- package/dist/web-to-print/p-D8pVJRuX.js +1 -0
- package/dist/web-to-print/p-DQuL1Twl.js +1 -0
- package/dist/web-to-print/p-b532777b.entry.js +1 -0
- package/dist/web-to-print/web-to-print.esm.js +1 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +68 -0
- package/readme.md +490 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,e,i){const s="undefined"!=typeof HTMLElement?HTMLElement.prototype:null;for(;t&&t!==s;){const s=Object.getOwnPropertyDescriptor(t,e);if(s&&(!i||s.get))return s;t=Object.getPrototypeOf(t)}}var e,i=(e,i)=>{var s;Object.entries(null!=(s=i.o.i)?s:{}).map((([s,[r]])=>{if(31&r||32&r){const r=e[s],n=t(Object.getPrototypeOf(e),s,!0)||Object.getOwnPropertyDescriptor(e,s);n&&Object.defineProperty(e,s,{get(){return n.get.call(this)},set(t){n.set.call(this,t)},configurable:!0,enumerable:!0}),i.u.has(s)?e[s]=i.u.get(s):void 0!==r&&(e[s]=r)}}))},s=t=>{if(t.__stencil__getHostRef)return t.__stencil__getHostRef()},r=(t,e)=>e in t,n=(t,e)=>(0,console.error)(t,e),h=new Map,o="undefined"!=typeof window?window:{},a=o.HTMLElement||class{},l={p:0,S:"",jmp:t=>t(),raf:t=>requestAnimationFrame(t),ael:(t,e,i,s)=>t.addEventListener(e,i,s),rel:(t,e,i,s)=>t.removeEventListener(e,i,s),ce:(t,e)=>new CustomEvent(t,e)},u=(()=>{try{return!!o.document.adoptedStyleSheets&&(new CSSStyleSheet,"function"==typeof(new CSSStyleSheet).replaceSync)}catch(t){}return!1})(),c=!!u&&(()=>!!o.document&&Object.getOwnPropertyDescriptor(o.document.adoptedStyleSheets,"length").writable)(),f=!1,d=[],g=[],p=(t,e)=>i=>{t.push(i),f||(f=!0,e&&4&l.p?y(v):l.raf(v))},m=t=>{for(let e=0;e<t.length;e++)try{t[e](performance.now())}catch(t){n(t)}t.length=0},v=()=>{m(d),m(g),(f=d.length>0)&&l.raf(v)},y=t=>Promise.resolve(void 0).then(t),w=p(g,!0),b=t=>{const e=new URL(t,l.S);return e.origin!==o.location.origin?e.href:e.pathname},x=t=>l.S=t;function C(){const t=this.attachShadow({mode:"open"});void 0===e&&(e=null),e&&(c?t.adoptedStyleSheets.push(e):t.adoptedStyleSheets=[...t.adoptedStyleSheets,e])}var S,_,M=new WeakMap,T=t=>"sc-"+t._,k=t=>"object"==(t=typeof t)||"function"===t,F=(t,e,...i)=>{let s=null,r=null,n=!1,h=!1;const o=[],a=e=>{for(let i=0;i<e.length;i++)s=e[i],Array.isArray(s)?a(s):null!=s&&"boolean"!=typeof s&&((n="function"!=typeof t&&!k(s))&&(s=String(s)),n&&h?o[o.length-1].k+=s:o.push(n?O(null,s):s),h=n)};if(a(i),e){e.key&&(r=e.key);{const t=e.className||e.class;t&&(e.class="object"!=typeof t?t:Object.keys(t).filter((e=>t[e])).join(" "))}}const l=O(t,null);return l.F=e,o.length>0&&(l.O=o),l.D=r,l},O=(t,e)=>({p:0,$:t,k:null!=e?e:null,j:null,O:null,F:null,D:null}),D={},$=t=>{if(!t)return;const e=Object.keys(t);if(0===e.length)return;let i=!1;for(const s of e){if(i)break;for(const e of t[s])if("string"==typeof e){i=!0;break}}if(!i)return t;const s={};for(const i of e)s[i]=t[i].map((t=>"string"==typeof t?{[t]:0}:t));return s},j=(t,e)=>null==t||k(t)?t:4&e?"false"!==t&&(""===t||!!t):2&e?"string"==typeof t?parseFloat(t):"number"==typeof t?t:NaN:1&e?String(t):t,A=(t,e)=>{const i=t;return{emit:t=>E(i,e,{bubbles:!0,composed:!0,cancelable:!0,detail:t})}},E=(t,e,i)=>{const s=l.ce(e,i);return t.dispatchEvent(s),s},P=(t,e,i,n,h,a)=>{if(i===n)return;let u=r(t,e),c=e.toLowerCase();if("class"===e){const e=t.classList,s=B(i);let r=B(n);e.remove(...s.filter((t=>t&&!r.includes(t)))),e.add(...r.filter((t=>t&&!s.includes(t))))}else if("style"===e){for(const e in i)n&&null!=n[e]||(e.includes("-")?t.style.removeProperty(e):t.style[e]="");for(const e in n)i&&n[e]===i[e]||(e.includes("-")?t.style.setProperty(e,n[e]):t.style[e]=n[e])}else if("key"===e);else if("ref"===e)n&&Z(n,t);else if(t.__lookupSetter__(e)||"o"!==e[0]||"n"!==e[1]){if("a"===e[0]&&e.startsWith("attr:")){const i=e.slice(5);let r;{const e=s(t);if(e&&e.o&&e.o.i){const t=e.o.i[i];t&&t[1]&&(r=t[1])}}return r||(r=i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()),void(null==n||!1===n?!1===n&&""!==t.getAttribute(r)||t.removeAttribute(r):t.setAttribute(r,!0===n?"":n))}if("p"===e[0]&&e.startsWith("prop:")){const i=e.slice(5);try{t[i]=n}catch(t){}return}{const s=k(n);if((u||s&&null!==n)&&!h)try{if(t.tagName.includes("-"))t[e]!==n&&(t[e]=n);else{const s=null==n?"":n;"list"===e?u=!1:null!=i&&t[e]===s||("function"==typeof t.__lookupSetter__(e)?t[e]=s:t.setAttribute(e,s))}}catch(t){}null==n||!1===n?!1===n&&""!==t.getAttribute(e)||t.removeAttribute(e):(!u||4&a||h)&&!s&&1===t.nodeType&&t.setAttribute(e,n=!0===n?"":n)}}else if(e="-"===e[2]?e.slice(3):r(o,c)?c.slice(2):c[2]+e.slice(3),i||n){const s=e.endsWith(R);e=e.replace(I,""),i&&l.rel(t,e,i,s),n&&l.ael(t,e,n,s)}},L=/\s/,B=t=>("object"==typeof t&&t&&"baseVal"in t&&(t=t.baseVal),t&&"string"==typeof t?t.split(L):[]),R="Capture",I=new RegExp(R+"$"),Y=(t,e,i)=>{const s=11===e.j.nodeType&&e.j.host?e.j.host:e.j,r=t&&t.F||{},n=e.F||{};for(const t of X(Object.keys(r)))t in n||P(s,t,r[t],void 0,i,e.p);for(const t of X(Object.keys(n)))P(s,t,r[t],n[t],i,e.p)};function X(t){return t.includes("ref")?[...t.filter((t=>"ref"!==t)),"ref"]:t}var W=!1,z=!1,N=[],H=[],G=(t,e,i)=>{const s=e.O[i];let r,n,h=0;if(null!=s.k)r=s.j=o.document.createTextNode(s.k);else{if(z||(z="svg"===s.$),!o.document)throw new Error("You are trying to render a Stencil component in an environment that doesn't support the DOM.");if(r=s.j=o.document.createElementNS(z?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml",s.$),z&&"foreignObject"===s.$&&(z=!1),Y(null,s,z),null!=S&&void 0!==S&&r["s-si"]!==S&&r.classList.add(r["s-si"]=S),s.O){const e="template"===s.$?r.content:r;for(h=0;h<s.O.length;++h)n=G(t,s,h),n&&e.appendChild(n)}"svg"===s.$?z=!1:"foreignObject"===r.tagName&&(z=!0)}return r["s-hn"]=_,r},V=(t,e,i,s,r,n)=>{let h,o=t;for(o.shadowRoot&&o.tagName===_&&(o=o.shadowRoot),"template"===i.$&&(o=o.content);r<=n;++r)s[r]&&(h=G(null,i,r),h&&(s[r].j=h,Q(o,h,e)))},U=(t,e,i)=>{for(let s=e;s<=i;++s){const e=t[s];if(e){const t=e.j;J(e),t&&t.remove()}}},q=(t,e,i=!1)=>t.$===e.$&&(i?(i&&!t.D&&e.D&&(t.D=e.D),!0):t.D===e.D),K=(t,e,i=!1)=>{const s=e.j=t.j,r=t.O,n=e.O,h=e.$,o=e.k;null==o?(z="svg"===h||"foreignObject"!==h&&z,"slot"!==h||W||t.P!==e.P&&(e.j["s-sn"]=e.P||"",(t=>{l.p|=1;const e=t.closest(_.toLowerCase());if(null!=e){const i=Array.from(e.__childNodes||e.childNodes).find((t=>t["s-cr"])),s=Array.from(t.__childNodes||t.childNodes);for(const t of i?s.reverse():s)null!=t["s-sh"]&&(Q(e,t,null!=i?i:null),t["s-sh"]=void 0)}l.p&=-2})(e.j.parentElement)),Y(t,e,z),null!==r&&null!==n?((t,e,i,s,r=!1)=>{let n,h,o=0,a=0,l=0,u=0,c=e.length-1,f=e[0],d=e[c],g=s.length-1,p=s[0],m=s[g];const v="template"===i.$?t.content:t;for(;o<=c&&a<=g;)if(null==f)f=e[++o];else if(null==d)d=e[--c];else if(null==p)p=s[++a];else if(null==m)m=s[--g];else if(q(f,p,r))K(f,p,r),f=e[++o],p=s[++a];else if(q(d,m,r))K(d,m,r),d=e[--c],m=s[--g];else if(q(f,m,r))K(f,m,r),Q(v,f.j,d.j.nextSibling),f=e[++o],m=s[--g];else if(q(d,p,r))K(d,p,r),Q(v,d.j,f.j),d=e[--c],p=s[++a];else{for(l=-1,u=o;u<=c;++u)if(e[u]&&null!==e[u].D&&e[u].D===p.D){l=u;break}l>=0?(h=e[l],h.$!==p.$?n=G(e&&e[a],i,l):(K(h,p,r),e[l]=void 0,n=h.j),p=s[++a]):(n=G(e&&e[a],i,a),p=s[++a]),n&&Q(f.j.parentNode,n,f.j)}o>c?V(t,null==s[g+1]?null:s[g+1].j,i,s,a,g):a>g&&U(e,o,c)})(s,r,e,n,i):null!==n?(null!==t.k&&(s.textContent=""),V(s,null,e,n,0,n.length-1)):!i&&null!==r&&U(r,0,r.length-1),z&&"svg"===h&&(z=!1)):t.k!==o&&(s.data=o)},J=t=>{t.F&&t.F.ref&&N.push((()=>t.F.ref(null))),t.O&&t.O.map(J)},Z=(t,e)=>{H.push((()=>t(e)))},Q=(t,e,i)=>t.__insertBefore?t.__insertBefore(e,i):null==t?void 0:t.insertBefore(e,i),tt=(t,e,i=!1)=>{const s=t.$hostElement$,r=t.o,n=t.L||O(null,null);var h;const o=(h=e)&&h.$===D?e:F(null,null,e);if(_=s.tagName,i&&o.F)for(const t of Object.keys(o.F))s.hasAttribute(t)&&!["key","ref","style","class"].includes(t)&&(o.F[t]=s[t]);o.$=null,o.p|=4,t.L=o,o.j=n.j=s.shadowRoot||s,S=s["s-sc"],W=!(!(1&r.p)||128&r.p),K(n,o,i),N.forEach((t=>t())),N.length=0,H.forEach((t=>t())),H.length=0},et=(t,e)=>{if(e&&!t.R&&e["s-p"]){const i=e["s-p"].push(new Promise((s=>t.R=()=>{e["s-p"].splice(i-1,1),s()})))}},it=(t,e)=>{if(t.p|=16,4&t.p)return void(t.p|=512);et(t,t.I);const i=()=>st(t,e);if(!e)return w(i);queueMicrotask((()=>{i()}))},st=(t,e)=>{const i=t.$hostElement$,s=i;if(!s)throw new Error(`Can't render component <${i.tagName.toLowerCase()} /> with invalid Stencil runtime! Make sure this imported component is compiled with a \`externalRuntime: true\` flag. For more information, please refer to https://stenciljs.com/docs/custom-elements#externalruntime`);let r;return r=ut(s,e?"componentWillLoad":"componentWillUpdate",void 0,i),r=rt(r,(()=>ut(s,"componentWillRender",void 0,i))),rt(r,(()=>ht(t,s,e)))},rt=(t,e)=>nt(t)?t.then(e).catch((t=>{console.error(t),e()})):e(),nt=t=>t instanceof Promise||t&&t.then&&"function"==typeof t.then,ht=async(t,e,i)=>{var s;const r=t.$hostElement$,n=r["s-rc"];i&&(t=>{const e=t.o,i=t.$hostElement$,s=e.p,r=((t,e)=>{var i,s,r;const n=T(e),a=h.get(n);if(!o.document)return n;if(t=11===t.nodeType?t:o.document,a)if("string"==typeof a){let r,h=M.get(t=t.head||t);if(h||M.set(t,h=new Set),!h.has(n)){r=o.document.createElement("style"),r.textContent=a;const f=null!=(i=l.Y)?i:function(){var t,e,i;return null!=(i=null==(e=null==(t=o.document.head)?void 0:t.querySelector('meta[name="csp-nonce"]'))?void 0:e.getAttribute("content"))?i:void 0}();if(null!=f&&r.setAttribute("nonce",f),!(1&e.p))if("HEAD"===t.nodeName){const e=t.querySelectorAll("link[rel=preconnect]"),i=e.length>0?e[e.length-1].nextSibling:t.querySelector("style");t.insertBefore(r,(null==i?void 0:i.parentNode)===t?i:null)}else if("host"in t)if(u){const e=new(null!=(s=t.defaultView)?s:t.ownerDocument.defaultView).CSSStyleSheet;e.replaceSync(a),c?t.adoptedStyleSheets.unshift(e):t.adoptedStyleSheets=[e,...t.adoptedStyleSheets]}else{const e=t.querySelector("style");e?e.textContent=a+e.textContent:t.prepend(r)}else t.append(r);1&e.p&&t.insertBefore(r,null),4&e.p&&(r.textContent+="slot-fb{display:contents}slot-fb[hidden]{display:none}"),h&&h.add(n)}}else{let e=M.get(t);if(e||M.set(t,e=new Set),!e.has(n)){const i=null!=(r=t.defaultView)?r:t.ownerDocument.defaultView;let s;if(a.constructor===i.CSSStyleSheet)s=a;else{s=new i.CSSStyleSheet;for(let t=0;t<a.cssRules.length;t++)s.insertRule(a.cssRules[t].cssText,t)}c?t.adoptedStyleSheets.push(s):t.adoptedStyleSheets=[...t.adoptedStyleSheets,s],e.add(n)}}return n})(i.shadowRoot?i.shadowRoot:i.getRootNode(),e);10&s&&(i["s-sc"]=r,i.classList.add(r+"-h"))})(t);ot(t,e,r,i),n&&(n.map((t=>t())),r["s-rc"]=void 0);{const e=null!=(s=r["s-p"])?s:[],i=()=>at(t);0===e.length?i():(Promise.all(e).then(i).catch(i),t.p|=4,e.length=0)}},ot=(t,e,i,s)=>{try{e=e.render(),t.p&=-17,t.p|=2,tt(t,e,s)}catch(e){n(e,t.$hostElement$)}return null},at=t=>{const e=t.$hostElement$,i=e,s=t.I;ut(i,"componentDidRender",void 0,e),64&t.p?ut(i,"componentDidUpdate",void 0,e):(t.p|=64,ct(e),ut(i,"componentDidLoad",void 0,e),t.X(e),s||lt()),t.R&&(t.R(),t.R=void 0),512&t.p&&y((()=>it(t,!1))),t.p&=-517},lt=()=>{y((()=>E(o,"appload",{detail:{namespace:"web-to-print"}})))},ut=(t,e,i,s)=>{if(t&&t[e])try{return t[e](i)}catch(t){n(t,s)}},ct=t=>t.classList.add("hydrated"),ft=(t,e,i,r)=>{const h=s(t);if(!h)return;const o=t,a=h.u.get(e),l=h.p,u=o;i=j(i,r.i[e][0]);const c=Number.isNaN(a)&&Number.isNaN(i);if(i!==a&&!c){if(h.u.set(e,i),r.W){const t=r.W[e];t&&t.map((t=>{try{const[[s,r]]=Object.entries(t);(128&l||1&r)&&(u?u[s](i,a,e):h.N.push((()=>{h.H[s](i,a,e)})))}catch(t){n(t,o)}}))}if(2&l){if(u.componentShouldUpdate&&!1===u.componentShouldUpdate(i,a,e)&&!(16&l))return;16&l||it(h,!1)}}},dt=(e,i)=>{var r,n;const h=e.prototype;{e.watchers&&!i.W&&(i.W=$(e.watchers)),e.deserializers&&!i.G&&(i.G=e.deserializers),e.serializers&&!i.V&&(i.V=e.serializers);const o=Object.entries(null!=(r=i.i)?r:{});o.map((([e,[r]])=>{if(31&r||32&r){const{get:n,set:o}=t(h,e)||{};n&&(i.i[e][0]|=2048),o&&(i.i[e][0]|=4096),Object.defineProperty(h,e,{get(){return n?n.apply(this):(t=e,s(this).u.get(t));var t},configurable:!0,enumerable:!0}),Object.defineProperty(h,e,{set(t){const n=s(this);if(n){if(o)return void 0===(32&r?this[e]:n.$hostElement$[e])&&n.u.get(e)&&(t=n.u.get(e)),o.apply(this,[j(t,r)]),void ft(this,e,t=32&r?this[e]:n.$hostElement$[e],i);ft(this,e,t,i)}}})}}));{const t=new Map;h.attributeChangedCallback=function(e,r,n){l.jmp((()=>{var a;const l=t.get(e),u=s(this);if(this.hasOwnProperty(l),h.hasOwnProperty(l)&&"number"==typeof this[l]&&this[l]==n)return;if(null==l){const t=null==u?void 0:u.p;if(u&&t&&!(8&t)&&n!==r){const s=this,h=null==(a=i.W)?void 0:a[e];null==h||h.forEach((i=>{const[[h,o]]=Object.entries(i);null!=s[h]&&(128&t||1&o)&&s[h].call(s,n,r,e)}))}return}const c=o.find((([t])=>t===l)),f=c&&4&c[1][0],d=f&&null===n&&void 0===this[l];f&&(n=null!==n&&"false"!==n);const g=Object.getOwnPropertyDescriptor(h,l);d||n==this[l]||g.get&&!g.set||(this[l]=n)}))},e.observedAttributes=Array.from(new Set([...Object.keys(null!=(n=i.W)?n:{}),...o.filter((([t,e])=>31&e[0])).map((([e,i])=>{const s=i[1]||e;return t.set(s,e),s}))]))}}return e},gt=(t,e)=>{const r={p:e[0],_:e[1]};try{r.i=e[2],r.W=$(t.W),r.G=t.G,r.V=t.V;const o=t.prototype.connectedCallback,a=t.prototype.disconnectedCallback;return Object.assign(t.prototype,{__hasHostListenerAttached:!1,__registerHost(){((t,e)=>{const s={p:0,$hostElement$:t,o:e,u:new Map,U:new Map};s.K=new Promise((t=>s.X=t)),t["s-p"]=[],t["s-rc"]=[];const r=s;t.__stencil__getHostRef=()=>r,512&e.p&&i(t,s)})(this,r)},connectedCallback(){if(!this.__hasHostListenerAttached){if(!s(this))return;this.__hasHostListenerAttached=!0}(t=>{if(!(1&l.p)){const e=s(t);if(!e)return;const i=e.o,r=()=>{};if(1&e.p)(null==e?void 0:e.H)||(null==e?void 0:e.K)&&e.K.then((()=>{}));else{e.p|=1;{let i=t;for(;i=i.parentNode||i.host;)if(i["s-p"]){et(e,e.I=i);break}}i.i&&Object.entries(i.i).map((([e,[i]])=>{if(31&i&&Object.prototype.hasOwnProperty.call(t,e)){const i=t[e];delete t[e],t[e]=i}})),(async(t,e,i)=>{let s;try{if(!(32&e.p)&&(e.p|=32,s=t.constructor,customElements.whenDefined(t.localName).then((()=>e.p|=128)),s&&s.style)){let t;"string"==typeof s.style&&(t=s.style);const e=T(i);if(!h.has(e)){const s=()=>{};((t,e,i)=>{let s=h.get(t);u&&i?(s=s||new CSSStyleSheet,"string"==typeof s?s=e:s.replaceSync(e)):s=e,h.set(t,s)})(e,t,!!(1&i.p)),s()}}const r=e.I,n=()=>it(e,!0);r&&r["s-rc"]?r["s-rc"].push(n):n()}catch(i){n(i,t),e.R&&(e.R(),e.R=void 0),e.X&&e.X(t)}})(t,e,i)}r()}})(this),o&&o.call(this)},disconnectedCallback(){(async t=>{1&l.p||s(t),M.has(t)&&M.delete(t),t.shadowRoot&&M.has(t.shadowRoot)&&M.delete(t.shadowRoot)})(this),a&&a.call(this)},__attachShadow(){if(this.shadowRoot){if("open"!==this.shadowRoot.mode)throw new Error(`Unable to re-use existing shadow root for ${r._}! Mode is set to ${this.shadowRoot.mode} but Stencil only supports open shadow roots.`)}else C.call(this,r)}}),Object.defineProperty(t,"is",{value:r._,configurable:!0}),dt(t,r)}catch(e){return n(e),t}},pt=t=>l.Y=t,mt=t=>Object.assign(l,t),vt=new WeakMap;function yt(t,e){let i=vt.get(e);i||(i={p:0,o:{p:0,_:e.tagName},$hostElement$:e},vt.set(e,i)),tt(i,t)}function wt(t){return t}function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function xt(t){var e=function(t){if("object"!=bt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=bt(i))return i;throw TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==bt(e)?e:e+""}function Ct(t,e,i){return(e=xt(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}var St=class{constructor(){Ct(this,"browserShadowBlurConstant",1),Ct(this,"DPI",96),Ct(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),Ct(this,"perfLimitSizeTotal",2097152),Ct(this,"maxCacheSideLimit",4096),Ct(this,"minCacheSideLimit",256),Ct(this,"disableStyleCopyPaste",!1),Ct(this,"enableGLFiltering",!0),Ct(this,"textureSize",4096),Ct(this,"forceGLPutImageData",!1),Ct(this,"cachesBoundsOfCurve",!1),Ct(this,"fontPaths",{}),Ct(this,"NUM_FRACTION_DIGITS",4)}};const _t=new class extends St{constructor(t){super(),this.configure(t)}configure(t={}){Object.assign(this,t)}addFonts(t={}){this.fontPaths={...this.fontPaths,...t}}removeFonts(t=[]){t.forEach((t=>{delete this.fontPaths[t]}))}clearFonts(){this.fontPaths={}}restoreDefaults(t){let e=new St,i=(null==t?void 0:t.reduce(((t,i)=>(t[i]=e[i],t)),{}))||e;this.configure(i)}},Mt=(t,...e)=>console[t]("fabric",...e);var Tt=class extends Error{constructor(t,e){super(`fabric: ${t}`,e)}},kt=class extends Tt{constructor(t){super(`${t} 'options.signal' is in 'aborted' state`)}},Ft=class{},Ot=class extends Ft{testPrecision(t,e){let i=`precision ${e} float;\nvoid main(){}`,s=t.createShader(t.FRAGMENT_SHADER);return!!s&&(t.shaderSource(s,i),t.compileShader(s),!!t.getShaderParameter(s,t.COMPILE_STATUS))}queryWebGL(t){let e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find((t=>this.testPrecision(e,t))),e.getExtension("WEBGL_lose_context").loseContext(),Mt("log",`WebGL: max texture size ${this.maxTextureSize}`))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}};const Dt={};let $t;const jt=()=>$t||($t={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Ot,dispose(){},copyPasteData:Dt}),At=()=>jt().document,Et=()=>jt().window,Pt=()=>{var t;return Math.max(null==(t=_t.devicePixelRatio)?Et().devicePixelRatio:t,1)},Lt=new class{constructor(){Ct(this,"boundsOfCurveCache",{}),this.charWidthsCache=new Map}getFontCache({fontFamily:t,fontStyle:e,fontWeight:i}){t=t.toLowerCase();let s=this.charWidthsCache;s.has(t)||s.set(t,new Map);let r=s.get(t),n=`${e.toLowerCase()}_${(i+"").toLowerCase()}`;return r.has(n)||r.set(n,new Map),r.get(n)}clearFontCache(t){t?this.charWidthsCache.delete((t||"").toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(t){let{perfLimitSizeTotal:e}=_t,i=Math.sqrt(e*t);return[Math.floor(i),Math.floor(e/i)]}},Bt="7.4.0";function Rt(){}const It=Math.PI/2,Yt=Math.PI/4,Xt=2*Math.PI,Wt=Math.PI/180,zt=Object.freeze([1,0,0,1,0,0]),Nt="center",Ht="left",Gt="bottom",Vt="right",Ut="none",qt=/\r?\n/,Kt="moving",Jt="scaling",Zt="rotating",Qt="rotate",te="skewing",ee="resizing",ie="modifyPoly",se="changed",re="scale",ne="scaleX",he="scaleY",oe="skewX",ae="skewY",le="fill",ue="stroke",ce="modified",fe="normal",de="json",ge=new class{constructor(){this[de]=new Map,this.svg=new Map}has(t){return this[de].has(t)}getClass(t){let e=this[de].get(t);if(!e)throw new Tt(`No class registered for ${t}`);return e}setClass(t,e){e?this[de].set(e,t):(this[de].set(t.type,t),this[de].set(t.type.toLowerCase(),t))}getSVGClass(t){return this.svg.get(t)}setSVGClass(t,e){this.svg.set(null==e?t.type.toLowerCase():e,t)}},pe=new class extends Array{remove(t){let e=this.indexOf(t);e>-1&&this.splice(e,1)}cancelAll(){let t=this.splice(0);return t.forEach((t=>t.abort())),t}cancelByCanvas(t){if(!t)return[];let e=this.filter((e=>{var i;return e.target===t||"object"==typeof e.target&&(null==(i=e.target)?void 0:i.canvas)===t}));return e.forEach((t=>t.abort())),e}cancelByTarget(t){if(!t)return[];let e=this.filter((e=>e.target===t));return e.forEach((t=>t.abort())),e}};var me=class{constructor(){Ct(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),"object"==typeof t)return Object.entries(t).forEach((([t,e])=>{this.on(t,e)})),()=>this.off(t);if(e){let i=t;return this.__eventListeners[i]||(this.__eventListeners[i]=[]),this.__eventListeners[i].push(e),()=>this.off(i,e)}return()=>!1}once(t,e){if("object"==typeof t){let e=[];return Object.entries(t).forEach((([t,i])=>{e.push(this.once(t,i))})),()=>e.forEach((t=>t()))}if(e){let i=this.on(t,(function(...t){e.call(this,...t),i()}));return i}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){let i=this.__eventListeners[t],s=i.indexOf(e);s>-1&&i.splice(s,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(void 0===t)for(let t in this.__eventListeners)this._removeEventListener(t);else"object"==typeof t?Object.entries(t).forEach((([t,e])=>{this._removeEventListener(t,e)})):this._removeEventListener(t,e)}fire(t,e){var i;if(!this.__eventListeners)return;let s=null==(i=this.__eventListeners[t])?void 0:i.concat();if(s)for(let t=0;t<s.length;t++)s[t].call(this,e||{})}};const ve=(t,e)=>{let i=t.indexOf(e);return-1!==i&&t.splice(i,1),t},ye=t=>{if(0===t)return 1;switch(Math.abs(t)/It){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},we=t=>{if(0===t)return 0;let e=t/It,i=Math.sign(t);switch(e){case 1:return i;case 2:return 0;case 3:return-i}return Math.sin(t)};var be=class t{constructor(t=0,e=0){"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(e){return new t(this.x+e.x,this.y+e.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(e){return new t(this.x+e,this.y+e)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(e){return new t(this.x-e.x,this.y-e.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(e){return new t(this.x-e,this.y-e)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(e){return new t(this.x*e.x,this.y*e.y)}scalarMultiply(e){return new t(this.x*e,this.y*e)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(e){return new t(this.x/e.x,this.y/e.y)}scalarDivide(e){return new t(this.x/e,this.y/e)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(e,i=.5){return i=Math.max(Math.min(1,i),0),new t(this.x+(e.x-this.x)*i,this.y+(e.y-this.y)*i)}distanceFrom(t){let e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}midPointFrom(t){return this.lerp(t)}min(e){return new t(Math.min(this.x,e.x),Math.min(this.y,e.y))}max(e){return new t(Math.max(this.x,e.x),Math.max(this.y,e.y))}toString(){return`${this.x},${this.y}`}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){let e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i}clone(){return new t(this.x,this.y)}rotate(e,i=xe){let s=we(e),r=ye(e),n=this.subtract(i);return new t(n.x*r-n.y*s,n.x*s+n.y*r).add(i)}transform(e,i=!1){return new t(e[0]*this.x+e[2]*this.y+(i?0:e[4]),e[1]*this.x+e[3]*this.y+(i?0:e[5]))}};const xe=new be(0,0),Ce=t=>!!t&&Array.isArray(t._objects);function Se(t){class e extends t{constructor(...t){super(...t),Ct(this,"_objects",[])}_onObjectAdded(t){}_onObjectRemoved(t){}_onStackOrderChanged(t){}add(...t){let e=this._objects.push(...t);return t.forEach((t=>this._onObjectAdded(t))),e}insertAt(t,...e){return this._objects.splice(t,0,...e),e.forEach((t=>this._onObjectAdded(t))),this._objects.length}remove(...t){let e=this._objects,i=[];return t.forEach((t=>{let s=e.indexOf(t);-1!==s&&(e.splice(s,1),i.push(t),this._onObjectRemoved(t))})),i}forEachObject(t){this.getObjects().forEach(((e,i,s)=>t(e,i,s)))}getObjects(...t){return 0===t.length?[...this._objects]:this._objects.filter((e=>e.isType(...t)))}item(t){return this._objects[t]}isEmpty(){return 0===this._objects.length}size(){return this._objects.length}contains(t,i){return!!this._objects.includes(t)||!!i&&this._objects.some((i=>i instanceof e&&i.contains(t,!0)))}complexity(){return this._objects.reduce(((t,e)=>t+(e.complexity?e.complexity():0)),0)}sendObjectToBack(t){return!(!t||t===this._objects[0]||(ve(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),0))}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1]||(ve(this._objects,t),this._objects.push(t),this._onStackOrderChanged(t),0))}sendObjectBackwards(t,e){if(!t)return!1;let i=this._objects.indexOf(t);if(0!==i){let s=this.findNewLowerIndex(t,i,e);return ve(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}bringObjectForward(t,e){if(!t)return!1;let i=this._objects.indexOf(t);if(i!==this._objects.length-1){let s=this.findNewUpperIndex(t,i,e);return ve(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(ve(this._objects,t),this._objects.splice(e,0,t),this._onStackOrderChanged(t),!0)}findNewLowerIndex(t,e,i){let s;if(i){s=e;for(let i=e-1;i>=0;--i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e-1;return s}findNewUpperIndex(t,e,i){let s;if(i){s=e;for(let i=e+1;i<this._objects.length;++i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e+1;return s}collectObjects({left:t,top:e,width:i,height:s},{includeIntersecting:r=!0}={}){let n=[],h=new be(t,e),o=h.add(new be(i,s));for(let t=this._objects.length-1;t>=0;t--){let e=this._objects[t];e.selectable&&e.visible&&(r&&e.intersectsWithRect(h,o)||e.isContainedWithinRect(h,o)||r&&e.containsPoint(h)||r&&e.containsPoint(o))&&n.push(e)}return n}}return e}var _e=class extends me{_setOptions(t={}){for(let e in t)this.set(e,t[e])}_setObject(t){for(let e in t)this._set(e,t[e])}set(t,e){return"object"==typeof t?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){let e=this.get(t);return"boolean"==typeof e&&this.set(t,!e),this}get(t){return this[t]}};function Me(t){return Et().requestAnimationFrame(t)}let Te=0;const ke=()=>Te++,Fe=()=>{let t=At().createElement("canvas");if(!t||void 0===t.getContext)throw new Tt("Failed to create `canvas` element");return t},Oe=t=>{let e=Fe();return e.width=t.width,e.height=t.height,e},De=(t,e,i)=>t.toDataURL(`image/${e}`,i),$e=(t,e,i)=>new Promise((s=>{t.toBlob(s,`image/${e}`,i)})),je=t=>t*Wt,Ae=t=>t/Wt,Ee=(t,e,i)=>new be(t).transform(e,i),Pe=t=>{let e=1/(t[0]*t[3]-t[1]*t[2]),i=[e*t[3],-e*t[1],-e*t[2],e*t[0],0,0],{x:s,y:r}=new be(t[4],t[5]).transform(i,!0);return i[4]=-s,i[5]=-r,i},Le=(t,e,i)=>[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],i?0:t[0]*e[4]+t[2]*e[5]+t[4],i?0:t[1]*e[4]+t[3]*e[5]+t[5]],Be=(t,e)=>t.reduceRight(((t,i)=>i&&t?Le(i,t,e):i||t),void 0)||zt.concat(),Re=([t,e])=>Math.atan2(e,t),Ie=([t,e])=>Math.sqrt(t*t+e*e),Ye=([,,t,e])=>Math.sqrt(t*t+e*e),Xe=t=>{let e=Re(t),i=t[0]**2+t[1]**2,s=Math.sqrt(i),r=(t[0]*t[3]-t[2]*t[1])/s,n=Math.atan2(t[0]*t[2]+t[1]*t[3],i);return{angle:Ae(e),scaleX:s,scaleY:r,skewX:Ae(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},We=(t,e=0)=>[1,0,0,1,t,e];function ze({angle:t=0}={},{x:e=0,y:i=0}={}){let s=je(t),r=ye(s),n=we(s);return[r,n,-n,r,e?e-(r*e-n*i):0,i?i-(n*e+r*i):0]}const Ne=(t,e=t)=>[t,0,0,e,0,0],He=t=>Math.tan(je(t)),Ge=t=>[1,0,He(t),1,0,0],Ve=t=>[1,He(t),0,1,0,0],Ue=({scaleX:t=1,scaleY:e=1,flipX:i=!1,flipY:s=!1,skewX:r=0,skewY:n=0})=>{let h=Ne(i?-t:t,s?-e:e);return r&&(h=Le(h,Ge(r),!0)),n&&(h=Le(h,Ve(n),!0)),h},qe=(t,{signal:e,crossOrigin:i=null}={})=>new Promise((function(s,r){if(e&&e.aborted)return r(new kt("loadImage"));let n,h=At().createElement("img");e&&(n=function(t){h.src="",r(t)},e.addEventListener("abort",n,{once:!0}));let o=function(){h.onload=h.onerror=null,n&&(null==e||e.removeEventListener("abort",n)),s(h)};t?(h.onload=o,h.onerror=function(){n&&(null==e||e.removeEventListener("abort",n)),r(new Tt(`Error loading ${h.src}`))},i&&(h.crossOrigin=i),h.src=t):o()})),Ke=(t,{signal:e,reviver:i=Rt}={})=>new Promise(((s,r)=>{let n=[];e&&e.addEventListener("abort",r,{once:!0}),Promise.allSettled(t.map((t=>ge.getClass(t.type).fromObject(t,{signal:e})))).then((async e=>{for(let[s,r]of e.entries())if("fulfilled"===r.status&&(await i(t[s],r.value),n.push(r.value)),"rejected"===r.status){let e=await i(t[s],void 0,r.reason);e&&n.push(e)}s(n)})).catch((t=>{n.forEach((t=>{t.dispose&&t.dispose()})),r(t)})).finally((()=>{e&&e.removeEventListener("abort",r)}))})),Je=(t,{signal:e}={})=>new Promise(((i,s)=>{let r=[];e&&e.addEventListener("abort",s,{once:!0});let n=Object.values(t).map((t=>t&&t.type&&ge.has(t.type)?Ke([t],{signal:e}).then((([t])=>(r.push(t),t))):t)),h=Object.keys(t);Promise.all(n).then((t=>t.reduce(((t,e,i)=>(t[h[i]]=e,t)),{}))).then(i).catch((t=>{r.forEach((t=>{t.dispose&&t.dispose()})),s(t)})).finally((()=>{e&&e.removeEventListener("abort",s)}))})),Ze=(t,e=[])=>e.reduce(((e,i)=>(i in t&&(e[i]=t[i]),e)),{}),Qe=(t,e)=>Object.keys(t).reduce(((i,s)=>(e(t[s],s,t)&&(i[s]=t[s]),i)),{}),ti=(t,e)=>parseFloat(Number(t).toFixed(e)),ei=t=>"matrix("+t.map((t=>ti(t,_t.NUM_FRACTION_DIGITS))).join(" ")+")",ii=t=>!!t&&void 0!==t.toLive,si=t=>!!t&&"function"==typeof t.toObject,ri=t=>!!t&&void 0!==t.offsetX&&"source"in t,ni=t=>!!t&&"multiSelectionStacking"in t;function hi(t){let e=t&&oi(t),i=0,s=0;if(!t||!e)return{left:i,top:s};let r=t,n=e.documentElement,h=e.body||{scrollLeft:0,scrollTop:0};for(;r&&(r.parentNode||r.host)&&(r=r.parentNode||r.host,r===e?(i=h.scrollLeft||n.scrollLeft||0,s=h.scrollTop||n.scrollTop||0):(i+=r.scrollLeft||0,s+=r.scrollTop||0),1!==r.nodeType||"fixed"!==r.style.position););return{left:i,top:s}}const oi=t=>t.ownerDocument||null,ai=t=>{var e;return(null==(e=t.ownerDocument)?void 0:e.defaultView)||null},li=(t,e,{width:i,height:s},r=1)=>{t.width=i,t.height=s,r>1&&(t.setAttribute("width",(i*r).toString()),t.setAttribute("height",(s*r).toString()),e.scale(r,r))},ui=(t,{width:e,height:i})=>{e&&(t.style.width="number"==typeof e?`${e}px`:e),i&&(t.style.height="number"==typeof i?`${i}px`:i)};function ci(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect=Ut,t}var fi=class{constructor(t){Ct(this,"_originalCanvasStyle",void 0),Ct(this,"lower",void 0);let e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){let e=(i=t)&&void 0!==i.getContext?t:t&&At().getElementById(t)||Fe();var i;if(e.hasAttribute("data-fabric"))throw new Tt("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM({width:t,height:e}){let{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width",`${t}`),i.setAttribute("height",`${e}`),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){let{el:i,ctx:s}=this.lower;li(i,s,t,e)}setCSSDimensions(t){ui(this.lower.el,t)}calcOffset(){return function(t){var e;let i=t&&oi(t),s={left:0,top:0};if(!i)return s;let r=(null==(e=ai(t))?void 0:e.getComputedStyle(t,null))||{};s.left+=parseInt(r.borderLeftWidth,10)||0,s.top+=parseInt(r.borderTopWidth,10)||0,s.left+=parseInt(r.paddingLeft,10)||0,s.top+=parseInt(r.paddingTop,10)||0;let n={left:0,top:0},h=i.documentElement;void 0!==t.getBoundingClientRect&&(n=t.getBoundingClientRect());let o=hi(t);return{left:n.left+o.left-(h.clientLeft||0)+s.left,top:n.top+o.top-(h.clientTop||0)+s.top}}(this.lower.el)}dispose(){jt().dispose(this.lower.el),delete this.lower}};const di={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...zt],patternQuality:"best"},gi=t=>t.toString().replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">");let pi;const mi=t=>{if(pi||pi||(pi="Intl"in Et()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),pi){let e=pi.segment(t);return Array.from(e).map((({segment:t})=>t))}return vi(t)},vi=t=>{let e=[];for(let i,s=0;s<t.length;s++)!1!==(i=yi(t,s))&&e.push(i);return e},yi=(t,e)=>{let i=t.charCodeAt(e);if(isNaN(i))return"";if(i<55296||i>57343)return t.charAt(e);if(55296<=i&&i<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";let i=t.charCodeAt(e+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return t.charAt(e)+t.charAt(e+1)}if(0===e)throw"Low surrogate without preceding high surrogate";let s=t.charCodeAt(e-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var wi=class t extends(Se(_e)){get lowerCanvasEl(){var t;return null==(t=this.elements.lower)?void 0:t.el}get contextContainer(){var t;return null==(t=this.elements.lower)?void 0:t.ctx}static getDefaults(){return t.ownDefaults}constructor(t,e={}){super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new fi(t)}add(...t){let e=super.add(...t);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),e}insertAt(t,...e){let i=super.insertAt(t,...e);return e.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),i}remove(...t){let e=super.remove(...t);return e.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),e}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(Mt("warn","Canvas is trying to add an object that belongs to a different canvas.\nResulting to default behavior: removing object from previous canvas and adding to new canvas"),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}getRetinaScaling(){return this.enableRetinaScaling?Pt():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}_setDimensionsImpl(t,{cssOnly:e=!1,backstoreOnly:i=!1}={}){if(!e){let e={width:this.width,height:this.height,...t};this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}i||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return Ie(this.viewportTransform)}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){let i=t,s=[...this.viewportTransform],r=Ee(t,Pe(s));s[0]=e,s[3]=e;let n=Ee(r,s);s[4]+=i.x-n.x,s[5]+=i.y-n.y,this.setViewportTransform(s)}setZoom(t){this.zoomToPoint(new be(0,0),t)}absolutePan(t){let e=[...this.viewportTransform];return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)}relativePan(t){return this.absolutePan(new be(-t.x-this.viewportTransform[4],-t.y-this.viewportTransform[5]))}getElement(){return this.elements.lower.el}clearContext(t){t.clearRect(0,0,this.width,this.height)}getContext(){return this.elements.lower.ctx}clear(){this.remove(...this.getObjects()),this.backgroundImage=void 0,this.overlayImage=void 0,this.backgroundColor="",this.overlayColor="",this.clearContext(this.getContext()),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll()}renderAll(){this.cancelRequestedRender(),this.destroyed||this.renderCanvas(this.getContext(),this._objects)}renderAndReset(){this.nextRenderHandle=0,this.renderAll()}requestRenderAll(){this.nextRenderHandle||this.disposed||this.destroyed||(this.nextRenderHandle=Me((()=>this.renderAndReset())))}calcViewportBoundaries(){let t=this.width,e=this.height,i=Pe(this.viewportTransform),s=Ee({x:0,y:0},i),r=Ee({x:t,y:e},i),n=s.min(r),h=s.max(r);return this.vptCoords={tl:n,tr:new be(h.x,n.y),bl:new be(n.x,h.y),br:h}}cancelRequestedRender(){this.nextRenderHandle&&(function(t){Et().cancelAnimationFrame(t)}(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;let i=this.viewportTransform,s=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality=this.patternQuality,this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),s&&(s._set("canvas",this),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,s)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){let i=this.viewportTransform;t.save(),t.transform(...i),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let i=0,s=e.length;i<s;++i)e[i]&&e[i].render(t)}_renderBackgroundOrOverlay(t,e){let i=this[`${e}Color`],s=this[`${e}Image`],r=this.viewportTransform,n=this[`${e}Vpt`];if(!i&&!s)return;let h=ii(i);if(i){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=h?i.toLive(t):i,n&&t.transform(...r),h){t.transform(1,0,0,1,i.offsetX||0,i.offsetY||0);let e=i.gradientTransform||i.patternTransform;e&&t.transform(...e)}t.fill(),t.restore()}if(s){t.save();let{skipOffscreen:e}=this;this.skipOffscreen=n,n&&t.transform(...r),s.render(t),this.skipOffscreen=e,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenterPoint(){return new be(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new be(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new be(t.getCenterPoint().x,this.getCenterPoint().y))}centerObject(t){return this._centerObject(t,this.getCenterPoint())}viewportCenterObject(t){return this._centerObject(t,this.getVpCenter())}viewportCenterObjectH(t){return this._centerObject(t,new be(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new be(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return Ee(this.getCenterPoint(),Pe(this.viewportTransform))}_centerObject(t,e){t.setXY(e,Nt,Nt),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){let i=this.clipPath,s=i&&!i.excludeFromExport?this._toObject(i,t,e):null;return{version:Bt,...Ze(this,e),objects:this._objects.filter((t=>!t.excludeFromExport)).map((i=>this._toObject(i,t,e))),...this.__serializeBgOverlay(t,e),...s?{clipPath:s}:null}}_toObject(t,e,i){let s;this.includeDefaultValues||(s=t.includeDefaultValues,t.includeDefaultValues=!1);let r=t[e](i);return this.includeDefaultValues||(t.includeDefaultValues=!!s),r}__serializeBgOverlay(t,e){let i={},s=this.backgroundImage,r=this.overlayImage,n=this.backgroundColor,h=this.overlayColor;return ii(n)?n.excludeFromExport||(i.background=n.toObject(e)):n&&(i.background=n),ii(h)?h.excludeFromExport||(i.overlay=h.toObject(e)):h&&(i.overlay=h),s&&!s.excludeFromExport&&(i.backgroundImage=this._toObject(s,t,e)),r&&!r.excludeFromExport&&(i.overlayImage=this._toObject(r,t,e)),i}toSVG(t={},e){t.reviver=e;let i=[];var s;return this._setSVGPreamble(i,t),this._setSVGHeader(i,t),this.clipPath&&i.push(`<g clip-path="url(#${gi(null==(s=this.clipPath.clipPathId)?"":s)})" >\n`),this._setSVGBgOverlayColor(i,"background"),this._setSVGBgOverlayImage(i,"backgroundImage",e),this._setSVGObjects(i,e),this.clipPath&&i.push("</g>\n"),this._setSVGBgOverlayColor(i,"overlay"),this._setSVGBgOverlayImage(i,"overlayImage",e),i.push("</svg>"),i.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",'" standalone="no" ?>\n','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ','"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')}_setSVGHeader(t,e){let i,s=e.width||`${this.width}`,r=e.height||`${this.height}`,n=_t.NUM_FRACTION_DIGITS,h=e.viewBox;if(h)i=`viewBox="${h.x} ${h.y} ${h.width} ${h.height}" `;else if(this.svgViewportTransformation){let t=this.viewportTransform;i=`viewBox="${ti(-t[4]/t[0],n)} ${ti(-t[5]/t[3],n)} ${ti(this.width/t[0],n)} ${ti(this.height/t[3],n)}" `}else i=`viewBox="0 0 ${this.width} ${this.height}" `;t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',r,'" ',i,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",Bt,"</desc>\n","<defs>\n",this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),"</defs>\n")}createSVGClipPathMarkup(t){let e=this.clipPath;return e?(e.clipPathId=`CLIPPATH_${ke()}`,`<clipPath id="${e.clipPathId}" >\n${e.toClipPathSVG(t.reviver)}</clipPath>\n`):""}createSVGRefElementsMarkup(){return["background","overlay"].map((t=>{let e=this[`${t}Color`];if(ii(e)){let i=this[`${t}Vpt`],s=this.viewportTransform;return e.toSVG({isType:()=>!1,width:this.width/(i?s[0]:1),height:this.height/(i?s[3]:1)},{additionalTransform:i?ei(s):""})}})).join("")}createSVGFontFacesMarkup(){let t=[],e={},i=_t.fontPaths;this._objects.forEach((function e(i){t.push(i),Ce(i)&&i._objects.forEach(e)})),t.forEach((t=>{if(!(s=t)||"function"!=typeof s._renderText)return;var s;let{styles:r,fontFamily:n}=t;!e[n]&&i[n]&&(e[n]=!0,r&&Object.values(r).forEach((t=>{Object.values(t).forEach((({fontFamily:t=""})=>{!e[t]&&i[t]&&(e[t]=!0)}))})))}));let s=Object.keys(e).map((t=>`\t\t@font-face {\n\t\t\tfont-family: '${t}';\n\t\t\tsrc: url('${i[t]}');\n\t\t}\n`)).join("");return s?`\t<style type="text/css"><![CDATA[\n${s}]]></style>\n`:""}_setSVGObjects(t,e){this.forEachObject((i=>{i.excludeFromExport||this._setSVGObject(t,i,e)}))}_setSVGObject(t,e,i){t.push(e.toSVG(i))}_setSVGBgOverlayImage(t,e,i){let s=this[e];s&&!s.excludeFromExport&&s.toSVG&&t.push(s.toSVG(i))}_setSVGBgOverlayColor(t,e){let i=this[`${e}Color`];if(i)if(ii(i)){let s=i.repeat||"",r=this.width,n=this.height,h=this[`${e}Vpt`]?ei(Pe(this.viewportTransform)):"";t.push(`<rect transform="${h} translate(${r/2},${n/2})" x="${i.offsetX-r/2}" y="${i.offsetY-n/2}" width="${"repeat-y"!==s&&"no-repeat"!==s||!ri(i)?r:i.source.width}" height="${"repeat-x"!==s&&"no-repeat"!==s||!ri(i)?n:i.source.height}" fill="url(#SVGID_${i.id})"></rect>\n`)}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',i,'"',"></rect>\n")}loadFromJSON(t,e,{signal:i}={}){if(!t)return Promise.reject(new Tt("`json` is undefined"));let{objects:s=[],...r}="string"==typeof t?JSON.parse(t):t,{backgroundImage:n,background:h,overlayImage:o,overlay:a,clipPath:l}=r,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([Ke(s,{reviver:e,signal:i}),Je({backgroundImage:n,backgroundColor:h,overlayImage:o,overlayColor:a,clipPath:l},{signal:i})]).then((([t,e])=>(this.clear(),this.add(...t),this.set(r),this.set(e),this.renderOnAddRemove=u,this)))}clone(t){let e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){let t=Oe(this);return new this.constructor(t)}toDataURL(t={}){let{format:e="png",quality:i=1,multiplier:s=1,enableRetinaScaling:r=!1}=t,n=s*(r?this.getRetinaScaling():1);return De(this.toCanvasElement(n,t),e,i)}toBlob(t={}){let{format:e="png",quality:i=1,multiplier:s=1,enableRetinaScaling:r=!1}=t,n=s*(r?this.getRetinaScaling():1);return $e(this.toCanvasElement(n,t),e,i)}toCanvasElement(t=1,{width:e,height:i,left:s,top:r,filter:n}={}){let h=(e||this.width)*t,o=(i||this.height)*t,a=this.getZoom(),l=this.width,u=this.height,c=this.skipControlsDrawing,f=a*t,d=this.viewportTransform,g=[f,0,0,f,(d[4]-(s||0))*t,(d[5]-(r||0))*t],p=this.enableRetinaScaling,m=Oe({width:h,height:o}),v=n?this._objects.filter((t=>n(t))):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=g,this.width=h,this.height=o,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(m.getContext("2d"),v),this.viewportTransform=d,this.width=l,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=p,this.skipControlsDrawing=c,m}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),pe.cancelByCanvas(this),this.disposed=!0,new Promise(((t,e)=>{let i=()=>{this.destroy(),t(!0)};i.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=i:i()}))}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject((t=>t.dispose())),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return`#<Canvas (${this.complexity()}): { objects: ${this._objects.length} }>`}};Ct(wi,"ownDefaults",di);const bi=["touchstart","touchmove","touchend"],xi=t=>bi.includes(t.type)||"touch"===t.pointerType,Ci=t=>{t.preventDefault(),t.stopPropagation()},Si=t=>{let e=0,i=0,s=0,r=0;for(let n=0,h=t.length;n<h;n++){let{x:h,y:o}=t[n];(h>s||!n)&&(s=h),(h<e||!n)&&(e=h),(o>r||!n)&&(r=o),(o<i||!n)&&(i=o)}return{left:e,top:i,width:s-e,height:r-i}},_i=(t,e)=>{let{translateX:i,translateY:s,scaleX:r,scaleY:n,...h}=Xe(e),o=new be(i,s);t.flipX=!1,t.flipY=!1,Object.assign(t,h),t.set({scaleX:r,scaleY:n}),t.setPositionByOrigin(o,Nt,Nt)},Mi=t=>({scaleX:t.scaleX,scaleY:t.scaleY,skewX:t.skewX,skewY:t.skewY,angle:t.angle,left:t.left,flipX:t.flipX,flipY:t.flipY,top:t.top}),Ti=(t,e,i)=>{let s=t/2,r=e/2,n=Si([new be(-s,-r),new be(s,-r),new be(-s,r),new be(s,r)].map((t=>t.transform(i))));return new be(n.width,n.height)},ki=(t=zt,e=zt)=>Le(Pe(e),t),Fi=(t,e=zt,i=zt)=>t.transform(ki(e,i)),Oi={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Di=t=>"string"==typeof t?Oi[t]:t-.5,$i=new be(1,0),ji=new be,Ai=(t,e)=>t.rotate(e),Ei=(t,e)=>new be(e).subtract(t),Pi=t=>t.distanceFrom(ji),Li=(t,e)=>Math.atan2(Yi(t,e),Xi(t,e)),Bi=t=>Li($i,t),Ri=t=>t.eq(ji)?t:t.scalarDivide(Pi(t)),Ii=(t,e=!0)=>Ri(new be(-t.y,t.x).scalarMultiply(e?1:-1)),Yi=(t,e)=>t.x*e.y-t.y*e.x,Xi=(t,e)=>t.x*e.x+t.y*e.y,Wi=(t,e,i)=>{if(t.eq(e)||t.eq(i))return!0;let s=Yi(e,i),r=Yi(e,t),n=Yi(i,t);return s>=0?r>=0&&n<=0:!(r<=0&&n>=0)},zi="not-allowed";function Ni(t){return Di(t.originX)===Di("center")&&Di(t.originY)===Di("center")}function Hi(t){return.5-Di(t)}const Gi=(t,e)=>t[e],Vi=(t,e,i,s)=>({e:t,transform:e,pointer:new be(i,s)});function Ui(t,e,i){let s=i,r=Bi(Ei(Fi(t.getCenterPoint(),t.canvas.viewportTransform,void 0),s))+Xt;return Math.round(r%Xt/Yt)}function qi({target:t,corner:e},i,s,r,n){var h;let o=t.controls[e],a=(null==(h=t.canvas)?void 0:h.getZoom())||1,l=t.padding/a,u=function(t,e,i,s){let r=t.getRelativeCenterPoint(),n=void 0!==i&&void 0!==s?t.translateToGivenOrigin(r,Nt,Nt,i,s):new be(t.left,t.top);return(t.angle?e.rotate(-je(t.angle),r):e).subtract(n)}(t,new be(r,n),i,s);return u.x>=l&&(u.x-=l),u.x<=-l&&(u.x+=l),u.y>=l&&(u.y-=l),u.y<=l&&(u.y+=l),u.x-=o.offsetX,u.y-=o.offsetY,u}const Ki=new RegExp(String.raw`[\0-\x1F\x7F;<>\\]|\/\*|\*\/|url\s*\(|expression\s*\(|(?:java|vb)script\s*:|data\s*:|@import\b`,"iu"),Ji=t=>"string"==typeof t&&t.trim().length>0&&!Ki.test(t),Zi=(t,e="")=>{let i=Number(t);return Number.isFinite(i)?`${i}`:e},Qi=(t,e="")=>"string"==typeof t&&Ji(t)?t:e,ts=t=>t.replace(/\s+/g," "),es={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},is=(t,e,i)=>(i<0&&(i+=1),i>1&&--i,i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t),ss=(t,e,i,s)=>{t/=255,e/=255,i/=255;let r,n,h=Math.max(t,e,i),o=Math.min(t,e,i),a=(h+o)/2;if(h===o)r=n=0;else{let s=h-o;switch(n=a>.5?s/(2-h-o):s/(h+o),h){case t:r=(e-i)/s+(e<i?6:0);break;case e:r=(i-t)/s+2;break;case i:r=(t-e)/s+4}r/=6}return[Math.round(360*r),Math.round(100*n),Math.round(100*a),s]},rs=(t="1")=>parseFloat(t)/(t.endsWith("%")?100:1),ns=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),hs=([t,e,i,s=1])=>{let r=Math.round(.3*t+.59*e+.11*i);return[r,r,r,s]};var os=class t{constructor(e){if(Ct(this,"isUnrecognised",!1),e)if(e instanceof t)this.setSource([...e._source]);else if(Array.isArray(e)){let[t,i,s,r=1]=e;this.setSource([t,i,s,r])}else this.setSource(this._tryParsingColor(e));else this.setSource([0,0,0,1])}_tryParsingColor(e){return(e=e.toLowerCase())in es&&(e=es[e]),"transparent"===e?[255,255,255,0]:t.sourceFromHex(e)||t.sourceFromRgb(e)||t.sourceFromHsl(e)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){let[t,e,i]=this.getSource();return`rgb(${t},${e},${i})`}toRgba(){return`rgba(${this.getSource().join(",")})`}toHsl(){let[t,e,i]=ss(...this.getSource());return`hsl(${t},${e}%,${i}%)`}toHsla(){let[t,e,i,s]=ss(...this.getSource());return`hsla(${t},${e}%,${i}%,${s})`}toHex(){return this.toHexa().slice(0,6)}toHexa(){let[t,e,i,s]=this.getSource();return`${ns(t)}${ns(e)}${ns(i)}${ns(Math.round(255*s))}`}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(hs(this.getSource())),this}toBlackWhite(t){let[e,,,i]=hs(this.getSource()),s=e<(t||127)?0:255;return this.setSource([s,s,s,i]),this}overlayWith(e){e instanceof t||(e=new t(e));let i=this.getSource(),s=e.getSource(),[r,n,h]=i.map(((t,e)=>Math.round(.5*t+.5*s[e])));return this.setSource([r,n,h,i[3]]),this}static fromRgb(e){return t.fromRgba(e)}static fromRgba(e){return new t(t.sourceFromRgb(e))}static sourceFromRgb(t){let e=ts(t).match(/^rgba?\(\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d{0,3}(?:\.\d+)?%?)\s?)?\)$/i);if(e){let[t,i,s]=e.slice(1,4).map((t=>{let e=parseFloat(t);return t.endsWith("%")?Math.round(2.55*e):e}));return[t,i,s,rs(e[4])]}}static fromHsl(e){return t.fromHsla(e)}static fromHsla(e){return new t(t.sourceFromHsl(e))}static sourceFromHsl(e){let i=ts(e).match(/^hsla?\(\s?([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d*(?:\.\d+)?%?)\s?)?\)$/i);if(!i)return;let s,r,n,h=(t.parseAngletoDegrees(i[1])%360+360)%360/360,o=parseFloat(i[2])/100,a=parseFloat(i[3])/100;if(0===o)s=r=n=a;else{let t=a<=.5?a*(o+1):a+o-a*o,e=2*a-t;s=is(e,t,h+1/3),r=is(e,t,h),n=is(e,t,h-1/3)}return[Math.round(255*s),Math.round(255*r),Math.round(255*n),rs(i[4])]}static fromHex(e){return new t(t.sourceFromHex(e))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){let e,i=t.slice(t.indexOf("#")+1);e=i.length<=4?i.split("").map((t=>t+t)):i.match(/.{2}/g);let[s,r,n,h=255]=e.map((t=>parseInt(t,16)));return[s,r,n,h/255]}}static parseAngletoDegrees(t){let e=t.toLowerCase(),i=parseFloat(e);return e.includes("rad")?Ae(i):e.includes("turn")?360*i:i}};const as=(t,e=16)=>{let i=/\D{0,2}$/.exec(t),s=parseFloat(t),r=_t.DPI;switch(null==i?void 0:i[0]){case"mm":return s*r/25.4;case"cm":return s*r/2.54;case"in":return s*r;case"pt":return s*r/72;case"pc":return s*r/72*12;case"em":return s*e;default:return s}},ls=(t,e,i=!0)=>{let s,r;if(e)if(e.toLive)s=`url(#SVGID_${gi(e.id)})`;else{let t=String(e);if(Ji(t)){let e=new os(t),i=e.getAlpha();s=e.toRgb(),1!==i&&(r=i.toString())}else s=new os("black").toRgb()}else s="none";return i?`${t}: ${s}; ${r?`${t}-opacity: ${r}; `:""}`:`${t}="${s}" ${r?`${t}-opacity="${r}" `:""}`};var us=class{getSvgStyles(t){let e=null==this.fillRule?"nonzero":Qi(this.fillRule),i=null==this.strokeWidth?"0":Zi(this.strokeWidth),s=null==this.strokeDashArray?Ut:this.strokeDashArray.every((t=>Number.isFinite(Number(t))))?this.strokeDashArray.join(" "):"",r=null==this.strokeDashOffset?"0":Zi(this.strokeDashOffset),n=null==this.strokeLineCap?"butt":Qi(this.strokeLineCap),h=null==this.strokeLineJoin?"miter":Qi(this.strokeLineJoin),o=null==this.strokeMiterLimit?"4":Zi(this.strokeMiterLimit),a=null==this.opacity?"1":Zi(this.opacity),l=this.visible?"":" visibility: hidden;",u=t?"":this.getSvgFilter(),c=ls(le,this.fill);return[ls(ue,this.stroke),i?`stroke-width: ${i}; `:"",s?`stroke-dasharray: ${s}; `:"",n?`stroke-linecap: ${n}; `:"",r?`stroke-dashoffset: ${r}; `:"",h?`stroke-linejoin: ${h}; `:"",o?`stroke-miterlimit: ${o}; `:"",c,e?`fill-rule: ${e}; `:"",a?`opacity: ${a};`:"",u,l].map((t=>gi(t))).join("")}getSvgFilter(){return this.shadow?`filter: url(#SVGID_${gi(this.shadow.id)});`:""}getSvgCommons(){return[this.id?`id="${gi(String(this.id))}" `:"",this.clipPath?`clip-path="url(#${gi(this.clipPath.clipPathId)})" `:""].join("")}getSvgTransform(t,e=""){return`transform="${ei(t?this.calcTransformMatrix():this.calcOwnMatrix())}${e}" `}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t,{reviver:e,additionalTransform:i=""}={}){let s=[this.getSvgTransform(!0,i),this.getSvgCommons()].join(""),r=t.indexOf("COMMON_PARTS");return t[r]=s,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t,{noStyle:e,reviver:i,withShadow:s,additionalTransform:r}={}){let n,h=e?"":`style="${this.getSvgStyles()}" `,o=s?`style="${this.getSvgFilter()}" `:"",a=this.clipPath,l=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=a&&a.absolutePositioned,c=this.stroke,f=this.fill,d=this.shadow,g=[],p=t.indexOf("COMMON_PARTS");return a&&(a.clipPathId=`CLIPPATH_${ke()}`,n=`<clipPath id="${a.clipPathId}" >\n${a.toClipPathSVG(i)}</clipPath>\n`),u&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),u?"":o+this.getSvgCommons()," >\n"),t[p]=[h,l,e?"":this.addPaintOrder()," ",r?`transform="${r}" `:""].join(""),ii(f)&&g.push(f.toSVG(this)),ii(c)&&g.push(c.toSVG(this)),d&&g.push(d.toSVG(this)),a&&g.push(n),g.push(t.join("")),g.push("</g>\n"),u&&g.push("</g>\n"),i?i(g.join("")):g.join("")}addPaintOrder(){return"fill"===this.paintFirst?"":` paint-order="${gi(this.paintFirst)}" `}};function cs(t){return RegExp("^("+t.join("|")+")\\b","i")}const fs="textDecorationThickness",ds="textDecorationColor",gs=["fontSize","fontWeight","fontFamily","fontStyle"],ps=["underline","overline","linethrough"],ms=[...gs,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],vs=[...ms,...ps,"textBackgroundColor","direction",fs,ds],ys=[...gs,...ps,ue,"strokeWidth",le,"deltaY","textBackgroundColor",fs,ds],ws={_reNewline:qt,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:fe,fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:Ht,fontStyle:fe,lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:Ht,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[fs]:66.667},bs="justify",xs=String.raw`[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?`,Cs=RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+xs+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+xs+"))?\\s+(.*)"),Ss={cx:Ht,x:Ht,r:"radius",cy:"top",y:"top",display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":fs,"text-decoration-color":ds},_s="font-size",Ms="clip-path";cs(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),cs(["symbol","image","marker","pattern","view","svg"]);const Ts=cs(["symbol","g","a","svg","clipPath","defs"]),ks="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Fs=RegExp("(?:\\s|^)"+ks+ks+"("+xs+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");var Os=class t{constructor(e={}){let i="string"==typeof e?t.parseShadow(e):e;Object.assign(this,t.ownDefaults,i),this.id=ke()}static parseShadow(t){let e=t.trim(),[,i=0,s=0,r=0]=(Fs.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(Fs,"")||"rgb(0,0,0)").trim(),offsetX:i,offsetY:s,blur:r}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){let e=Ai(new be(this.offsetX,this.offsetY),je(-t.angle)),i=_t.NUM_FRACTION_DIGITS,s=new os(this.color),r=40,n=40;return t.width&&t.height&&(r=100*ti((Math.abs(e.x)+this.blur)/t.width,i)+20,n=100*ti((Math.abs(e.y)+this.blur)/t.height,i)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),`<filter id="SVGID_${gi(this.id)}" y="-${n}%" height="${100+2*n}%" x="-${r}%" width="${100+2*r}%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="${ti(this.blur?this.blur/2:0,i)}"></feGaussianBlur>\n\t<feOffset dx="${ti(e.x,i)}" dy="${ti(e.y,i)}" result="oBlur" ></feOffset>\n\t<feFlood flood-color="${s.toRgb()}" flood-opacity="${s.getAlpha()}"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n`}toObject(){let e={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},i=t.ownDefaults;return this.includeDefaultValues?e:Qe(e,((t,e)=>t!==i[e]))}static async fromObject(t){return new this(t)}};Ct(Os,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),Ct(Os,"type","shadow"),ge.setClass(Os,"shadow");const Ds=(t,e,i)=>Math.max(t,Math.min(e,i)),$s=["top",Ht,ne,he,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",oe,ae],js=[le,ue,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],As={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:Nt,originY:Nt,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:le,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},Es=(t,e,i,s)=>-i*Math.cos(t/s*It)+i+e,Ps=()=>!1;var Ls=class{constructor({startValue:t,byValue:e,duration:i=500,delay:s=0,easing:r=Es,onStart:n=Rt,onChange:h=Rt,onComplete:o=Rt,abort:a=Ps,target:l}){Ct(this,"_state","pending"),Ct(this,"durationProgress",0),Ct(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=s,this.easing=r,this._onStart=n,this._onChange=h,this._onComplete=o,this._abort=a,this.target=l,this.startValue=t,this.byValue=e,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return"aborted"===this._state||"completed"===this._state}start(){let t=t=>{"pending"===this._state&&(this.startTime=t||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?this.timeout=Et().setTimeout((()=>Me(t)),this.delay):Me(t)}tick(t){let e=(t||+new Date)-this.startTime,i=Math.min(e,this.duration);this.durationProgress=i/this.duration;let{value:s,valueProgress:r}=this.calculate(i);this.value=Object.freeze(s),this.valueProgress=r,"aborted"!==this._state&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister(),this.timeout=null):(this._onChange(this.value,this.valueProgress,this.durationProgress),Me(this.tick)))}register(){pe.push(this)}unregister(){pe.remove(this)}abort(){this._state="aborted",this.unregister(),this.timeout&&Et().clearTimeout(this.timeout)}},Bs=class extends Ls{constructor({startValue:t=0,endValue:e=100,...i}){super({...i,startValue:t,byValue:e-t})}calculate(t){let e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}},Rs=class extends Ls{constructor({startValue:t=[0],endValue:e=[100],...i}){super({...i,startValue:t,byValue:e.map(((e,i)=>e-t[i]))})}calculate(t){let e=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i)));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}};const Is=(t,e,i,s)=>e+i*(1-Math.cos(t/s*It)),Ys=t=>t&&((e,i,s)=>t(new os(e).toRgba(),i,s));var Xs=class extends Ls{constructor({startValue:t,endValue:e,easing:i=Is,onChange:s,onComplete:r,abort:n,...h}){let o=new os(t).getSource(),a=new os(e).getSource();super({...h,startValue:o,byValue:a.map(((t,e)=>t-o[e])),easing:i,onChange:Ys(s),onComplete:Ys(r),abort:Ys(n)})}calculate(t){let[e,i,s,r]=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i))),n=[...[e,i,s].map(Math.round),Ds(0,r,1)];return{value:n,valueProgress:n.map(((t,e)=>0===this.byValue[e]?0:Math.abs((t-this.startValue[e])/this.byValue[e]))).find((t=>0!==t))||0}}};function Ws(t){let e=(t=>Array.isArray(t.startValue)||Array.isArray(t.endValue))(t)?new Rs(t):new Bs(t);return e.start(),e}var zs=class t{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some((e=>e.eq(t)))}append(...t){return this.points=this.points.concat(t.filter((t=>!this.includes(t)))),this}static isPointContained(t,e,i,s=!1){if(e.eq(i))return t.eq(e);if(e.x===i.x)return t.x===e.x&&(s||t.y>=Math.min(e.y,i.y)&&t.y<=Math.max(e.y,i.y));if(e.y===i.y)return t.y===e.y&&(s||t.x>=Math.min(e.x,i.x)&&t.x<=Math.max(e.x,i.x));{let r=Ei(e,i),n=Ei(e,t).divide(r);return s?Math.abs(n.x)===Math.abs(n.y):n.x===n.y&&n.x>=0&&n.x<=1}}static isPointInPolygon(t,e){let i=new be(t).setX(Math.min(t.x-1,...e.map((t=>t.x)))),s=0;for(let r=0;r<e.length;r++){let n=this.intersectSegmentSegment(e[r],e[(r+1)%e.length],t,i);if(n.includes(t))return!0;s+=Number("Intersection"===n.status)}return s%2==1}static intersectLineLine(e,i,s,r,n=!0,h=!0){let o=i.x-e.x,a=i.y-e.y,l=r.x-s.x,u=r.y-s.y,c=e.x-s.x,f=e.y-s.y,d=l*f-u*c,g=o*f-a*c,p=u*o-l*a;if(0!==p){let i=d/p,s=g/p;return(n||0<=i&&i<=1)&&(h||0<=s&&s<=1)?new t("Intersection").append(new be(e.x+i*o,e.y+i*a)):new t}return new t(0===d||0===g?n||h||t.isPointContained(e,s,r)||t.isPointContained(i,s,r)||t.isPointContained(s,e,i)||t.isPointContained(r,e,i)?"Coincident":void 0:"Parallel")}static intersectSegmentLine(e,i,s,r){return t.intersectLineLine(e,i,s,r,!1,!0)}static intersectSegmentSegment(e,i,s,r){return t.intersectLineLine(e,i,s,r,!1,!1)}static intersectLinePolygon(e,i,s,r=!0){let n=new t,h=s.length;for(let o,a,l,u=0;u<h;u++){if(o=s[u],a=s[(u+1)%h],l=t.intersectLineLine(e,i,o,a,r,!1),"Coincident"===l.status)return l;n.append(...l.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(e,i,s){return t.intersectLinePolygon(e,i,s,!1)}static intersectPolygonPolygon(e,i){let s=new t,r=e.length,n=[];for(let h=0;h<r;h++){let o=e[h],a=e[(h+1)%r],l=t.intersectSegmentPolygon(o,a,i);"Coincident"===l.status?(n.push(l),s.append(o,a)):s.append(...l.points)}return n.length>0&&n.length===e.length?new t("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(e,i,s){let r=i.min(s),n=i.max(s),h=new be(n.x,r.y),o=new be(r.x,n.y);return t.intersectPolygonPolygon(e,[r,h,n,o])}},Ns=class extends _e{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){let t=this.getRelativeXY();return this.group?Ee(t,this.group.calcTransformMatrix()):t}setXY(t,e,i){this.group&&(t=Ee(t,Pe(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,i)}getRelativeXY(){return new be(this.left,this.top)}setRelativeXY(t,e=this.originX,i=this.originY){this.setPositionByOrigin(t,e,i)}isStrokeAccountedForInDimensions(){return!1}getCoords(){let{tl:t,tr:e,br:i,bl:s}=this.aCoords||(this.aCoords=this.calcACoords()),r=[t,e,i,s];if(this.group){let t=this.group.calcTransformMatrix();return r.map((e=>Ee(e,t)))}return r}intersectsWithRect(t,e){return"Intersection"===zs.intersectPolygonRectangle(this.getCoords(),t,e).status}intersectsWithObject(t){let e=zs.intersectPolygonPolygon(this.getCoords(),t.getCoords());return"Intersection"===e.status||"Coincident"===e.status||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every((e=>t.containsPoint(e)))}isContainedWithinRect(t,e){let{left:i,top:s,width:r,height:n}=this.getBoundingRect();return i>=t.x&&i+r<=e.x&&s>=t.y&&s+n<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return zs.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;let{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some((i=>i.x<=e.x&&i.x>=t.x&&i.y<=e.y&&i.y>=t.y))||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;let{tl:t,br:e}=this.canvas.vptCoords;return!!this.intersectsWithRect(t,e)||this.getCoords().every((i=>(i.x>=e.x||i.x<=t.x)&&(i.y>=e.y||i.y<=t.y)))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return Si(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(ne,t),this._set(he,t),this.setCoords()}scaleToWidth(t){let e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){let e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return(null==(t=this.canvas)?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?Ae(Re(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return(null==(t=this.canvas)?void 0:t.viewportTransform)||zt.concat()}calcACoords(){let t=ze({angle:this.angle}),{x:e,y:i}=this.getRelativeCenterPoint(),s=Le(We(e,i),t),r=this._getTransformedDimensions(),n=r.x/2,h=r.y/2;return{tl:Ee({x:-n,y:-h},s),tr:Ee({x:n,y:-h},s),bl:Ee({x:-n,y:h},s),br:Ee({x:n,y:h},s)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(t=!1){let e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Di(this.originX),Di(this.originY)),e}calcTransformMatrix(t=!1){let e=this.calcOwnMatrix();if(t||!this.group)return e;let i=this.transformMatrixKey(t),s=this.matrixCache;return s&&s.key.every(((t,e)=>t===i[e]))?s.value:(this.group&&(e=Le(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:i,value:e},e)}calcOwnMatrix(){let t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key.every(((e,i)=>e===t[i])))return e.value;let i=this.getRelativeCenterPoint(),s=(t=>{let{translateX:e=0,translateY:i=0,angle:s=0}=t,r=We(e,i);s&&(r=Le(r,ze({angle:s})));let n=Ue(t);return(t=>t.every(((t,e)=>t===zt[e])))(n)||(r=Le(r,n)),r})({angle:this.angle,translateX:i.x,translateY:i.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY});return this.ownMatrixCache={key:t,value:s},s}_getNonTransformedDimensions(){return new be(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){var e;let i=null==(e=this.canvas)?void 0:e.viewportTransform,s=this._getTransformedDimensions(t);return i?s.multiply(new be(Ie(i),Ye(i))).scalarAdd(2*this.padding):s.scalarAdd(2*this.padding)}_getTransformedDimensions(t={}){let e={scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth,...t},i=e.strokeWidth,s=i,r=0;this.strokeUniform&&(s=0,r=i);let n,h=e.width+s,o=e.height+s;return n=0===e.skewX&&0===e.skewY?new be(h*e.scaleX,o*e.scaleY):Ti(h,o,Ue(e)),n.scalarAdd(r)}translateToGivenOrigin(t,e,i,s,r){let n=t.x,h=t.y,o=Di(s)-Di(e),a=Di(r)-Di(i);if(o||a){let t=this._getTransformedDimensions();n+=o*t.x,h+=a*t.y}return new be(n,h)}translateToCenterPoint(t,e,i){if("center"===e&&"center"===i)return t;let s=this.translateToGivenOrigin(t,e,i,Nt,Nt);return this.angle?s.rotate(je(this.angle),t):s}translateToOriginPoint(t,e,i){let s=this.translateToGivenOrigin(t,Nt,Nt,e,i);return this.angle?s.rotate(je(this.angle),t):s}getCenterPoint(){let t=this.getRelativeCenterPoint();return this.group?Ee(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new be(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.getPositionByOrigin(t,e)}getPositionByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,i){let s=this.translateToCenterPoint(t,e,i),r=this.translateToOriginPoint(s,this.originX,this.originY);this.set({left:r.x,top:r.y})}_getLeftTopCoords(){return this.getPositionByOrigin(Ht,"top")}positionByLeftTop(t){return this.setPositionByOrigin(t,Ht,"top")}},Hs=class t extends Ns{static getDefaults(){return t.ownDefaults}get type(){let t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){Mt("warn","Setting type has no effect",t)}constructor(e){super(),Ct(this,"_cacheContext",null),Object.assign(this,t.ownDefaults),this.setOptions(e)}_createCacheCanvas(){this._cacheCanvas=Fe(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){let e=t.width,i=t.height,s=_t.maxCacheSideLimit,r=_t.minCacheSideLimit;if(e<=s&&i<=s&&e*i<=_t.perfLimitSizeTotal)return e<r&&(t.width=r),i<r&&(t.height=r),t;let n=e/i,[h,o]=Lt.limitDimsByArea(n),a=Ds(r,h,s),l=Ds(r,o,s);return e>a&&(t.zoomX/=e/a,t.width=a,t.capped=!0),i>l&&(t.zoomY/=i/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){let t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),i=e.x*t.x/this.scaleX,s=e.y*t.y/this.scaleY;return{width:Math.ceil(i+2),height:Math.ceil(s+2),zoomX:t.x,zoomY:t.y,x:i,y:s}}_updateCacheCanvas(){let t=this._cacheCanvas,e=this._cacheContext,{width:i,height:s,zoomX:r,zoomY:n,x:h,y:o}=this._limitCacheSize(this._getCacheCanvasDimensions());if(!t||!e)return!1;if(i!==t.width||s!==t.height||this.zoomX!==r||this.zoomY!==n){i!==t.width||s!==t.height?(t.width=i,t.height=s):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));let a=h/2,l=o/2;return this.cacheTranslationX=Math.round(t.width/2-a)+a,this.cacheTranslationY=Math.round(t.height/2-l)+l,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(r,n),this.zoomX=r,this.zoomY=n,!0}return!1}setOptions(t={}){this._setOptions(t)}transform(t){let e=this.calcTransformMatrix(!(this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop));t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}getObjectScaling(){if(!this.group)return new be(Math.abs(this.scaleX),Math.abs(this.scaleY));let t=Xe(this.calcTransformMatrix());return new be(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){let t=this.getObjectScaling();if(this.canvas){let e=this.canvas.getZoom(),i=this.getCanvasRetinaScaling();return t.scalarMultiply(e*i)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:0===t?1e-4:t}_set(t,e){"scaleX"!==t&&"scaleY"!==t||(e=this._constrainScale(e)),"scaleX"===t&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof Os||(e=new Os(e));let i=this[t]!==e;return this[t]=e,i&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||i&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return 0===this.opacity||!this.width&&!this.height&&0===this.strokeWidth||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){let{zoomX:e,zoomY:i,cacheTranslationX:s,cacheTranslationY:r}=this,{width:n,height:h}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:i,cacheTranslationX:s,cacheTranslationY:r,width:n,height:h,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return!!this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth}hasFill(){return!!this.fill&&"transparent"!==this.fill}needsItsOwnCache(){return!!("stroke"===this.paintFirst&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)}drawClipPathOnCache(t,e,i){t.save(),t.globalCompositeOperation=e.inverted?"destination-out":"destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(i,0,0),t.restore()}drawObject(t,e,i){let s=this.fill,r=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this.fire("before:render",{ctx:t}),this._render(t),this._drawClipPath(t,this.clipPath,i),this.fill=s,this.stroke=r}createClipPathLayer(t,e){let i=Oe(e),s=i.getContext("2d");if(s.translate(e.cacheTranslationX,e.cacheTranslationY),s.scale(e.zoomX,e.zoomY),t._cacheCanvas=i,e.parentClipPaths.forEach((t=>{t.transform(s)})),e.parentClipPaths.push(t),t.absolutePositioned){let t=Pe(this.calcTransformMatrix());s.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return t.transform(s),t.drawObject(s,!0,e),i}_drawClipPath(t,e,i){if(!e)return;e._transformDone=!0;let s=this.createClipPathLayer(e,i);this.drawClipPathOnCache(t,e,s)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(t=!1){if(this.isNotVisible())return!1;let e=this._cacheCanvas,i=this._cacheContext;return!(!e||!i||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&i&&!t&&(i.save(),i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,e.width,e.height),i.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;let e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){let i=e.stroke;i&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,ii(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?this._applyPatternForTransformedGradient(t,i):(t.strokeStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.strokeStyle=e.stroke)}_setFillStyles(t,{fill:e}){e&&(ii(e)?(t.fillStyle=e.toLive(t),this._applyPatternGradientTransform(t,e)):t.fillStyle=e)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&0!==e.length&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;let e=this.shadow,i=this.canvas,s=this.getCanvasRetinaScaling(),[r,,,n]=(null==i?void 0:i.viewportTransform)||zt,h=r*s,o=n*s,a=e.nonScaling?new be(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*_t.browserShadowBlurConstant*(h+o)*(a.x+a.y)/4,t.shadowOffsetX=e.offsetX*h*a.x,t.shadowOffsetY=e.offsetY*o*a.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!ii(e))return{offsetX:0,offsetY:0};let i=e.gradientTransform||e.patternTransform,s=-this.width/2+e.offsetX||0,r=-this.height/2+e.offsetY||0;return"percentage"===e.gradientUnits?t.transform(this.width,0,0,this.height,s,r):t.transform(1,0,0,1,s,r),i&&t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),{offsetX:s,offsetY:r}}_renderPaintInOrder(t){"stroke"===this.paintFirst?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),"evenodd"===this.fillRule?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&0!==this.strokeWidth){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){let e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var i;let s=this._limitCacheSize(this._getCacheCanvasDimensions()),r=this.getCanvasRetinaScaling(),n=s.x/this.scaleX/r,h=s.y/this.scaleY/r,o=Oe({width:Math.ceil(n),height:Math.ceil(h)}),a=o.getContext("2d");a&&(a.beginPath(),a.moveTo(0,0),a.lineTo(n,0),a.lineTo(n,h),a.lineTo(0,h),a.closePath(),a.translate(n/2,h/2),a.scale(s.zoomX/this.scaleX/r,s.zoomY/this.scaleY/r),this._applyPatternGradientTransform(a,e),a.fillStyle=e.toLive(t),a.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/s.zoomX,r*this.scaleY/s.zoomY),t.strokeStyle=null==(i=a.createPattern(o,"no-repeat"))?"":i)}_findCenterFromElement(){return new be(this.left+this.width/2,this.top+this.height/2)}clone(t){let e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){let e=this.toCanvasElement(t);return new(ge.getClass("image"))(e)}toCanvasElement(t={}){let e=Mi(this),i=this.group,s=this.shadow,r=Math.abs,n=t.enableRetinaScaling?Pt():1,h=(t.multiplier||1)*n,o=t.canvasProvider||(t=>new wi(t,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&(t=>{t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)})(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&((t,e)=>{let i=ki(e,void 0);_i(t,Le(i,t.calcOwnMatrix()))})(this,this.getViewportTransform()),this.setCoords();let a=Fe(),l=this.getBoundingRect(),u=this.shadow,c=new be;if(u){let t=u.blur,e=u.nonScaling?new be(1,1):this.getObjectScaling();c.x=2*Math.round(r(u.offsetX)+t)*r(e.x),c.y=2*Math.round(r(u.offsetY)+t)*r(e.y)}let f=l.height+c.y;a.width=Math.ceil(l.width+c.x),a.height=Math.ceil(f);let d=o(a);"jpeg"===t.format&&(d.backgroundColor="#fff"),this.setPositionByOrigin(new be(d.width/2,d.height/2),Nt,Nt);let g=this.canvas;d._objects=[this],this.set("canvas",d),this.setCoords();let p=d.toCanvasElement(h||1,t);return this.set("canvas",g),this.shadow=s,i&&(this.group=i),this.set(e),this.setCoords(),d._objects=[],d.destroy(),p}toDataURL(t={}){return De(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(t={}){return $e(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(...t){return t.includes(this.constructor.type)||t.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){let{centeredRotation:e,originX:i,originY:s}=this;if(e){let{x:t,y:e}=this.getRelativeCenterPoint();this.originX=Nt,this.originY=Nt,this.left=t,this.top=e}if(this.set("angle",t),e){let{x:t,y:e}=this.getPositionByOrigin(i,s);this.left=t,this.top=e,this.originX=i,this.originY=s}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){pe.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&jt().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce(((t,[i,s])=>(t[i]=this._animate(i,s,e),t)),{})}_animate(t,e,i={}){let s=t.split("."),r=this.constructor.colorProperties.includes(s[s.length-1]),{abort:n,startValue:h,onChange:o,onComplete:a}=i,l={...i,target:this,startValue:null==h?s.reduce(((t,e)=>t[e]),this):h,endValue:e,abort:null==n?void 0:n.bind(this),onChange:(t,e,i)=>{s.reduce(((e,i,r)=>(r===s.length-1&&(e[i]=t),e[i])),this),o&&o(t,e,i)},onComplete:(t,e,i)=>{this.setCoords(),a&&a(t,e,i)}};return r?function(t){let e=new Xs(t);return e.start(),e}(l):Ws(l)}isDescendantOf(t){let{parent:e,group:i}=this;return e===t||i===t||!!e&&e.isDescendantOf(t)||!!i&&i!==e&&i.isDescendantOf(t)}getAncestors(){let t=[],e=this;do{e=e.parent,e&&t.push(e)}while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};let e=this.getAncestors(),i=t.getAncestors();if(0===e.length&&i.length>0&&this===i[i.length-1])return{fork:[],otherFork:[t,...i.slice(0,i.length-1)],common:[this]};for(let s,r=0;r<e.length;r++){if(s=e[r],s===t)return{fork:[this,...e.slice(0,r)],otherFork:[],common:e.slice(r)};for(let n=0;n<i.length;n++){if(this===i[n])return{fork:[],otherFork:[t,...i.slice(0,n)],common:[this,...e]};if(s===i[n])return{fork:[this,...e.slice(0,r)],otherFork:[t,...i.slice(0,n)],common:e.slice(r)}}}return{fork:[this,...e],otherFork:[t,...i],common:[]}}hasCommonAncestors(t){let e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;let e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;let i=e.common[0]||this.canvas;if(!i)return;let s=e.fork.pop(),r=e.otherFork.pop(),n=i._objects.indexOf(s),h=i._objects.indexOf(r);return n>-1&&n>h}toObject(e=[]){let i,s=e.concat(t.customProperties,this.constructor.customProperties||[]),r=_t.NUM_FRACTION_DIGITS,{clipPath:n,fill:h,stroke:o,shadow:a,strokeDashArray:l,left:u,top:c,originX:f,originY:d,width:g,height:p,strokeWidth:m,strokeLineCap:v,strokeDashOffset:y,strokeLineJoin:w,strokeUniform:b,strokeMiterLimit:x,scaleX:C,scaleY:S,angle:_,flipX:M,flipY:T,opacity:k,visible:F,backgroundColor:O,fillRule:D,paintFirst:$,globalCompositeOperation:j,skewX:A,skewY:E}=this;n&&!n.excludeFromExport&&(i=n.toObject(s.concat("inverted","absolutePositioned")));let P=t=>ti(t,r),L={...Ze(this,s),type:this.constructor.type,version:Bt,originX:f,originY:d,left:P(u),top:P(c),width:P(g),height:P(p),fill:si(h)?h.toObject():h,stroke:si(o)?o.toObject():o,strokeWidth:P(m),strokeDashArray:l&&l.concat(),strokeLineCap:v,strokeDashOffset:y,strokeLineJoin:w,strokeUniform:b,strokeMiterLimit:P(x),scaleX:P(C),scaleY:P(S),angle:P(_),flipX:M,flipY:T,opacity:P(k),shadow:a&&a.toObject(),visible:F,backgroundColor:O,fillRule:D,paintFirst:$,globalCompositeOperation:j,skewX:P(A),skewY:P(E),...i?{clipPath:i}:null};return this.includeDefaultValues?L:this._removeDefaultValues(L)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){let e=this.constructor.getDefaults(),i=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Qe(t,((t,e)=>{if("left"===e||"top"===e||"type"===e)return!0;let s=i[e];return t!==s&&!(Array.isArray(t)&&Array.isArray(s)&&0===t.length&&0===s.length)}))}toString(){return`#<${this.constructor.type}>`}static _fromObject({type:t,...e},{extraParam:i,...s}={}){return Je(e,s).then((t=>i?(delete t[i],new this(e[i],t)):new this(t)))}static fromObject(t,e){return this._fromObject(t,e)}};Ct(Hs,"stateProperties",$s),Ct(Hs,"cacheProperties",js),Ct(Hs,"ownDefaults",As),Ct(Hs,"type","FabricObject"),Ct(Hs,"colorProperties",[le,ue,"backgroundColor"]),Ct(Hs,"customProperties",[]),ge.setClass(Hs),ge.setClass(Hs,"object");const Gs=(t,e)=>{var i;let{transform:{target:s}}=e;null==(i=s.canvas)||i.fire(`object:${t}`,{...e,target:s}),s.fire(t,e)},Vs=(t,e,i)=>(s,r,n,h)=>{let o=e(s,r,n,h);return o&&Gs(t,{...Vi(s,r,n,h),...i}),o};function Us(t){return(e,i,s,r)=>{let{target:n,originX:h,originY:o}=i,a=n.getPositionByOrigin(h,o),l=t(e,i,s,r);return n.setPositionByOrigin(a,i.originX,i.originY),l}}const qs=((t,e,i,s)=>(e,i,r,n)=>{let h=qi(i,i.originX,i.originY,r,n).x,o=Di(i.originX);if(0===o||o>0&&h<0||o<0&&h>0){let{target:e}=i,r=e.strokeWidth/(e.strokeUniform?e[s]:1),n=Ni(i)?2:1,o=e[t],a=Math.abs(h*n/e[s])-r;return e.set(t,Math.max(a,1)),o!==e[t]}return!1})("width",0,0,"scaleX"),Ks=Vs(ee,Us(qs));function Js(t,e,i,s,r){t.save();let{stroke:n,xSize:h,ySize:o,opName:a}=this.commonRenderProps(t,e,i,r,s),l=h;h>o?t.scale(1,o/h):o>h&&(l=o,t.scale(h/o,1)),t.beginPath(),t.arc(0,0,l/2,0,Xt,!1),t[a](),n&&t.stroke(),t.restore()}function Zs(t,e,i,s,r){t.save();let{stroke:n,xSize:h,ySize:o,opName:a}=this.commonRenderProps(t,e,i,r,s),l=h/2,u=o/2;t[`${a}Rect`](-l,-u,h,o),n&&t.strokeRect(-l,-u,h,o),t.restore()}var Qs=class{constructor(t){Ct(this,"visible",!0),Ct(this,"actionName",re),Ct(this,"angle",0),Ct(this,"x",0),Ct(this,"y",0),Ct(this,"offsetX",0),Ct(this,"offsetY",0),Ct(this,"sizeX",0),Ct(this,"sizeY",0),Ct(this,"touchSizeX",0),Ct(this,"touchSizeY",0),Ct(this,"cursorStyle","crosshair"),Ct(this,"withConnection",!1),Object.assign(this,t)}getTransformAnchorPoint(){var t;return null==(t=this.transformAnchorPoint)?new be(.5-this.x,.5-this.y):t}shouldActivate(t,e,i,{tl:s,tr:r,br:n,bl:h}){var o;return(null==(o=e.canvas)?void 0:o.getActiveObject())===e&&e.isControlVisible(t)&&zs.isPointInPolygon(i,[s,r,n,h])}getActionHandler(t,e,i){return this.actionHandler}getMouseDownHandler(t,e,i){return this.mouseDownHandler}getMouseUpHandler(t,e,i){return this.mouseUpHandler}cursorStyleHandler(t,e,i,s){return e.cursorStyle}getActionName(t,e,i){return e.actionName}getVisibility(t,e){var i,s;return null==(i=null==(s=t._controlsVisibility)?void 0:s[e])?this.visible:i}setVisibility(t,e,i){this.visible=t}positionHandler(t,e,i,s){return new be(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,i,s,r,n){let h=Be([We(i,s),ze({angle:t}),Ne((r?this.touchSizeX:this.sizeX)||e,(r?this.touchSizeY:this.sizeY)||e)]);return{tl:new be(-.5,-.5).transform(h),tr:new be(.5,-.5).transform(h),br:new be(.5,.5).transform(h),bl:new be(-.5,.5).transform(h)}}commonRenderProps(t,e,i,s,r={}){let{cornerSize:n,cornerColor:h,transparentCorners:o,cornerStrokeColor:a}=r,l=n||s.cornerSize,u=this.sizeX||l,c=this.sizeY||l,f=void 0===o?s.transparentCorners:o,d=f?ue:le,g=a||s.cornerStrokeColor,p=!f&&!!g;return t.fillStyle=h||s.cornerColor||"",t.strokeStyle=g||"",t.translate(e,i),t.rotate(je(s.getTotalAngle())),{stroke:p,xSize:u,ySize:c,transparentCorners:f,opName:d}}render(t,e,i,s,r){"circle"===((s=s||{}).cornerStyle||r.cornerStyle)?Js.call(this,t,e,i,s,r):Zs.call(this,t,e,i,s,r)}};const tr=(t,e,i)=>i.lockRotation?zi:e.cursorStyle,er=Vs(Zt,Us(((t,{target:e,ex:i,ey:s,theta:r,originX:n,originY:h},o,a)=>{let l=e.getPositionByOrigin(n,h);if(Gi(e,"lockRotation"))return!1;let u=Math.atan2(s-l.y,i-l.x),c=Ae(Math.atan2(a-l.y,o-l.x)-u+r);if(e.snapAngle&&e.snapAngle>0){let t=e.snapAngle,i=e.snapThreshold||t,s=Math.ceil(c/t)*t,r=Math.floor(c/t)*t;Math.abs(c-r)<i?c=r:Math.abs(c-s)<i&&(c=s)}c<0&&(c=360+c),c%=360;let f=e.angle!==c;return e.angle=c,f})));function ir(t,e){let i=e.canvas,s=t[i.uniScaleKey];return i.uniformScaling&&!s||!i.uniformScaling&&s}function sr(t,e,i){let s=Gi(t,"lockScalingX"),r=Gi(t,"lockScalingY");if(s&&r||!e&&(s||r)&&i||s&&"x"===e||r&&"y"===e)return!0;let{width:n,height:h,strokeWidth:o}=t;return 0===n&&0===o&&"y"!==e||0===h&&0===o&&"x"!==e}const rr=["e","se","s","sw","w","nw","n","ne","e"],nr=(t,e,i,s)=>{let r=ir(t,i);return sr(i,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",r)?zi:`${rr[Ui(i,0,s)]}-resize`};function hr(t,e,i,s,r={}){let n,h,o,a,l,u,c=e.target,f=r.by,d=ir(t,c);if(sr(c,f,d))return!1;if(e.gestureScale)h=e.scaleX*e.gestureScale,o=e.scaleY*e.gestureScale;else{if(n=qi(e,e.originX,e.originY,i,s),l="y"===f?1:Math.sign(n.x||e.signX||1),u="x"===f?1:Math.sign(n.y||e.signY||1),e.signX||(e.signX=l),e.signY||(e.signY=u),Gi(c,"lockScalingFlip")&&(e.signX!==l||e.signY!==u))return!1;if(a=c._getTransformedDimensions(),d&&!f){let t=Math.abs(n.x)+Math.abs(n.y),{original:i}=e,s=t/(Math.abs(a.x*i.scaleX/c.scaleX)+Math.abs(a.y*i.scaleY/c.scaleY));h=i.scaleX*s,o=i.scaleY*s}else h=Math.abs(n.x*c.scaleX/a.x),o=Math.abs(n.y*c.scaleY/a.y);Ni(e)&&(h*=2,o*=2),e.signX!==l&&"y"!==f&&(e.originX=Hi(e.originX),h*=-1,e.signX=l),e.signY!==u&&"x"!==f&&(e.originY=Hi(e.originY),o*=-1,e.signY=u)}let g=c.scaleX,p=c.scaleY;return f?("x"===f&&c.set("scaleX",h),"y"===f&&c.set("scaleY",o)):(!Gi(c,"lockScalingX")&&c.set("scaleX",h),!Gi(c,"lockScalingY")&&c.set("scaleY",o)),g!==c.scaleX||p!==c.scaleY}const or=Vs(Jt,Us(((t,e,i,s)=>hr(t,e,i,s)))),ar=Vs(Jt,Us(((t,e,i,s)=>hr(t,e,i,s,{by:"x"})))),lr=Vs(Jt,Us(((t,e,i,s)=>hr(t,e,i,s,{by:"y"})))),ur={x:{counterAxis:"y",scale:ne,skew:oe,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:he,skew:ae,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},cr=["ns","nesw","ew","nwse"];function fr(t,e,i,s,r){let{target:n}=i,{counterAxis:h,origin:o,lockSkewing:a,skew:l,flip:u}=ur[t];if(Gi(n,a))return!1;let{origin:c,flip:f}=ur[h],d=Di(i[c])*(n[f]?-1:1),g=-Math.sign(d)*(n[u]?-1:1),p=-(0===n[l]&&qi(i,"center","center",s,r)[t]>0||n[l]>0?1:-1)*g*.5+.5;return Vs(te,Us(((e,i,s,r)=>function(t,{target:e,ex:i,ey:s,skewingSide:r,...n},h){let{skew:o}=ur[t],a=h.subtract(new be(i,s)).divide(new be(e.scaleX,e.scaleY))[t],l=e[o],u=Math.tan(je(n[o])),c="y"===t?e._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:e._getTransformedDimensions({scaleX:1,scaleY:1}).y,f=2*a*r/Math.max(c,1)+u,d=Ae(Math.atan(f));e.set(o,d);let g=l!==e[o];if(g&&"y"===t){let{skewX:t,scaleX:i}=e,s=e._getTransformedDimensions({skewY:l}),r=e._getTransformedDimensions(),n=0===t?1:s.x/r.x;1!==n&&e.set("scaleX",n*i)}return g}(t,i,new be(s,r)))))(e,{...i,[o]:p,skewingSide:g},s,r)}function dr(t,e){return t[e.canvas.altActionKey]}const gr=(t,e,i)=>{let s=dr(t,i);return 0===e.x?s?oe:he:0===e.y?s?ae:ne:""},pr=(t,e,i,s)=>dr(t,i)?((t,e,i,s)=>0!==e.x&&Gi(i,"lockSkewingY")||0!==e.y&&Gi(i,"lockSkewingX")?zi:`${cr[Ui(i,0,s)%4]}-resize`)(0,e,i,s):nr(t,e,i,s),mr=(t,e,i,s)=>dr(t,e.target)?((t,e,i,s)=>fr("y",t,e,i,s))(t,e,i,s):ar(t,e,i,s),vr=(t,e,i,s)=>dr(t,e.target)?((t,e,i,s)=>fr("x",t,e,i,s))(t,e,i,s):lr(t,e,i,s),yr=()=>({ml:new Qs({x:-.5,y:0,cursorStyleHandler:pr,actionHandler:mr,getActionName:gr}),mr:new Qs({x:.5,y:0,cursorStyleHandler:pr,actionHandler:mr,getActionName:gr}),mb:new Qs({x:0,y:.5,cursorStyleHandler:pr,actionHandler:vr,getActionName:gr}),mt:new Qs({x:0,y:-.5,cursorStyleHandler:pr,actionHandler:vr,getActionName:gr}),tl:new Qs({x:-.5,y:-.5,cursorStyleHandler:nr,actionHandler:or}),tr:new Qs({x:.5,y:-.5,cursorStyleHandler:nr,actionHandler:or}),bl:new Qs({x:-.5,y:.5,cursorStyleHandler:nr,actionHandler:or}),br:new Qs({x:.5,y:.5,cursorStyleHandler:nr,actionHandler:or}),mtr:new Qs({x:0,y:-.5,actionHandler:er,cursorStyleHandler:tr,offsetY:-40,withConnection:!0,actionName:Qt})});var wr=class t extends Hs{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e){super(),Object.assign(this,this.constructor.createControls(),t.ownDefaults),this.setOptions(e)}static createControls(){return{controls:yr()}}_updateCacheCanvas(){let t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){let e=t._currentTransform,i=e.action;if(this===e.target&&i&&i.startsWith("scale"))return!1}return super._updateCacheCanvas()}getActiveControl(){let t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t,e=!1){if(!this.hasControls||!this.canvas)return;this.__corner=void 0;let i=Object.entries(this.oCoords);for(let s=i.length-1;s>=0;s--){let[r,n]=i[s],h=this.controls[r];if(h.shouldActivate(r,this,t,e?n.touchCorner:n.corner))return this.__corner=r,{key:r,control:h,coord:this.oCoords[r]}}}calcOCoords(){let t=this.getViewportTransform(),e=Ie(t),i=Ye(t),s=this.getCenterPoint(),r=Le(Le(t,Le(We(s.x,s.y),ze({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}))),[1/e,0,0,1/i,0,0]),n=this.group?Xe(this.calcTransformMatrix()):void 0;n&&(n.scaleX=Math.abs(n.scaleX),n.scaleY=Math.abs(n.scaleY));let h=this._calculateCurrentDimensions(n),o={};return this.forEachControl(((t,e)=>{let i=t.positionHandler(h,r,this,t);o[e]=Object.assign(i,this._calcCornerCoords(t,i))})),o}_calcCornerCoords(t,e){let i=this.getTotalAngle();return{corner:t.calcCornerCoords(i,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(i,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(let e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();let e=this.getRelativeCenterPoint(),i=this._calculateCurrentDimensions(),s=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/s[0],1/s[3]),t.rotate(je(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-i.x/2,-i.y/2,i.x,i.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e,i={}){let s={hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray,...i};t.save(),t.strokeStyle=s.borderColor,this._setLineDash(t,s.borderDashArray),this.strokeBorders(t,e),s.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t,e={}){let{hasBorders:i,hasControls:s}=this,r={hasBorders:i,hasControls:s,...e},n=this.getViewportTransform(),h=r.hasBorders,o=r.hasControls,a=Xe(Le(n,this.calcTransformMatrix()));t.save(),t.translate(a.translateX,a.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(a.angle-=180);let l=Re(n);t.rotate(this.group?je(a.angle):je(this.angle)+l),h&&this.drawBorders(t,a,e),o&&this.drawControls(t,e),t.restore()}drawBorders(t,e,i){let s;if(i&&i.forActiveSelection||this.group){let t=Ti(this.width,this.height,Ue(e)),i=this.isStrokeAccountedForInDimensions()?xe:(this.strokeUniform?(new be).scalarAdd(this.canvas?this.canvas.getZoom():1):new be(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);s=t.add(i).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else s=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,s,i)}drawControlsConnectingLines(t,e){let i=!1;t.beginPath(),this.forEachControl(((s,r)=>{s.withConnection&&s.getVisibility(this,r)&&(i=!0,t.moveTo(s.x*e.x,s.y*e.y),t.lineTo(s.x*e.x+s.offsetX,s.y*e.y+s.offsetY))})),i&&t.stroke()}drawControls(t,e={}){t.save();let i=this.getCanvasRetinaScaling(),{cornerStrokeColor:s,cornerDashArray:r,cornerColor:n}=this,h={cornerStrokeColor:s,cornerDashArray:r,cornerColor:n,...e};t.setTransform(i,0,0,i,0,0),t.strokeStyle=t.fillStyle=h.cornerColor,this.transparentCorners||(t.strokeStyle=h.cornerStrokeColor),this._setLineDash(t,h.cornerDashArray),this.forEachControl(((e,i)=>{if(e.getVisibility(this,i)){let s=this.oCoords[i];e.render(t,s.x,s.y,h,this)}})),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(t={}){Object.entries(t).forEach((([t,e])=>this.setControlVisible(t,e)))}clearContextTop(t){if(!this.canvas)return;let e=this.canvas.contextTop;if(!e)return;let i=this.canvas.viewportTransform;e.save(),e.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this.transform(e);let s=this.width+4,r=this.height+4;return e.clearRect(-s/2,-r/2,s,r),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}};function br(t,e){return e.forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i)||Object.create(null))}))})),t}Ct(wr,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});var xr=class extends wr{};br(xr,[us]),ge.setClass(xr),ge.setClass(xr,"object");var Cr=class{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new be(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new be(1/this.options.scaleX,1/this.options.scaleY):new be(1,1)}createSideVector(t,e){let i=Ei(t,e);return this.options.strokeUniform?i.multiply(this.scale):i}projectOrthogonally(t,e,i){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,i)))}isSkewed(){return 0!==this.options.skewX||0!==this.options.skewY}applySkew(t){let e=new be(t);return e.y+=e.x*Math.tan(je(this.options.skewY)),e.x+=e.y*Math.tan(je(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}};const Sr=new be;var _r=class t extends Cr{static getOrthogonalRotationFactor(t,e){let i=e?Li(t,e):Bi(t);return Math.abs(i)<It?-1:1}constructor(t,e,i,s){super(s),Ct(this,"AB",void 0),Ct(this,"AC",void 0),Ct(this,"alpha",void 0),Ct(this,"bisector",void 0),this.A=new be(t),this.B=new be(e),this.C=new be(i),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Li(this.AB,this.AC),this.bisector=Ri(Ai(this.AB.eq(Sr)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(e,i,s=this.strokeProjectionMagnitude){let r=Ii(this.createSideVector(e,i)),n=t.getOrthogonalRotationFactor(r,this.bisector);return this.scaleUnitVector(r,s*n)}projectBevel(){let t=[];return(this.alpha%Xt==0?[this.B]:[this.B,this.C]).forEach((e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))})),t}projectMiter(){let t=[],e=Math.abs(this.alpha),i=1/Math.sin(e/2),s=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*i),r=this.options.strokeUniform?Pi(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Pi(s)/this.strokeProjectionMagnitude<=r&&t.push(this.applySkew(this.A.add(s))),t.push(...this.projectBevel()),t}projectRoundNoSkew(e,i){let s=[],r=new be(t.getOrthogonalRotationFactor(this.bisector),t.getOrthogonalRotationFactor(new be(this.bisector.y,this.bisector.x)));return[new be(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(r),new be(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(r)].forEach((t=>{Wi(t,e,i)&&s.push(this.A.add(t))})),s}projectRoundWithSkew(t,e){let i=[],{skewX:s,skewY:r,scaleX:n,scaleY:h,strokeUniform:o}=this.options,a=new be(Math.tan(je(s)),Math.tan(je(r))),l=this.strokeProjectionMagnitude,u=o?l/h/Math.sqrt(1/h**2+1/n**2*a.y**2):l/Math.sqrt(1+a.y**2),c=new be(Math.sqrt(Math.max(l**2-u**2,0)),u),f=o?l/Math.sqrt(1+a.x**2*(1/h)**2/(1/n+1/n*a.x*a.y)**2):l/Math.sqrt(1+a.x**2/(1+a.x*a.y)**2),d=new be(f,Math.sqrt(Math.max(l**2-f**2,0)));return[d,d.scalarMultiply(-1),c,c.scalarMultiply(-1)].map((t=>this.applySkew(o?t.multiply(this.strokeUniformScalar):t))).forEach((s=>{Wi(s,t,e)&&i.push(this.applySkew(this.A).add(s))})),i}projectRound(){let t=[];t.push(...this.projectBevel());let e=this.alpha%Xt==0,i=this.applySkew(this.A),s=t[e?0:2].subtract(i),r=t[+!!e].subtract(i),n=Yi(s,this.applySkew(e?this.AB.scalarMultiply(-1):this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)))>0,h=n?s:r,o=n?r:s;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,o)):t.push(...this.projectRoundNoSkew(h,o)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector})))}},Mr=class extends Cr{constructor(t,e,i){super(i),this.A=new be(t),this.T=new be(e)}calcOrthogonalProjection(t,e,i=this.strokeProjectionMagnitude){let s=this.createSideVector(t,e);return this.scaleUnitVector(Ii(s),i)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){let t=[];if(!this.isSkewed()&&this.A.eq(this.T)){let e=new be(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new _r(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){let t=[];if(this.A.eq(this.T)){let e=new be(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{let e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),i=this.scaleUnitVector(Ri(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),s=this.A.add(i);t.push(s.add(e),s.subtract(e))}return t.map((t=>this.applySkew(t)))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t})))}};const Tr=t=>{let e={};return Object.keys(t).forEach((i=>{e[i]={},Object.keys(t[i]).forEach((s=>{e[i][s]={...t[i][s]}}))})),e},kr=(t,e,i=!1)=>t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.textDecorationThickness!==e.textDecorationThickness||t.textDecorationColor!==e.textDecorationColor||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||i&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough),Fr=(t,e)=>{let i=e.split("\n"),s=[],r=-1,n={};t=Tr(t);for(let e=0;e<i.length;e++){let h=mi(i[e]);if(t[e])for(let i=0;i<h.length;i++){r++;let h=t[e][i];h&&Object.keys(h).length>0&&(kr(n,h,!0)?s.push({start:r,end:r+1,style:h}):s[s.length-1].end++),n=h||{}}else r+=h.length,n={}}return s},Or=(t,e)=>{if(!Array.isArray(t))return Tr(t);let i=e.split(qt),s={},r=-1,n=0;for(let e=0;e<i.length;e++){let h=mi(i[e]);for(let i=0;i<h.length;i++)r++,t[n]&&t[n].start<=r&&r<t[n].end&&(s[e]=s[e]||{},s[e][i]={...t[n].style},r===t[n].end-1&&n++)}return s},Dr=["display","transform",le,"fill-opacity","fill-rule","opacity",ue,"stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"];function $r(t,e){let i,s=t.nodeName,r=t.getAttribute("class"),n=t.getAttribute("id"),h="(?![a-zA-Z\\-]+)";if(i=RegExp("^"+s,"i"),e=e.replace(i,""),n&&e.length&&(i=RegExp("#"+n+h,"i"),e=e.replace(i,"")),r&&e.length){let t=r.split(" ");for(let s=t.length;s--;)i=RegExp("\\."+t[s]+h,"i"),e=e.replace(i,"")}return 0===e.length}function jr(t,e){let i=!0,s=$r(t,e.pop());return s&&e.length&&(i=function(t,e){let i,s=!0;for(;t.parentElement&&1===t.parentElement.nodeType&&e.length;)s&&(i=e.pop()),s=$r(t=t.parentElement,i);return 0===e.length}(t,e)),s&&i&&0===e.length}function Ar(t,e={}){let i={};for(let s in e)jr(t,s.split(" "))&&(i={...i,...e[s]});return i}const Er=t=>{var e;return null==(e=Ss[t])?t:e},Pr=RegExp(`(${xs})`,"gi"),Lr=`(${xs})`,Br=String.raw`(skewX)\(${Lr}\)`,Rr=String.raw`(skewY)\(${Lr}\)`,Ir=String.raw`(rotate)\(${Lr}(?: ${Lr} ${Lr})?\)`,Yr=String.raw`(scale)\(${Lr}(?: ${Lr})?\)`,Xr=String.raw`(translate)\(${Lr}(?: ${Lr})?\)`,Wr=`(?:${String.raw`(matrix)\(${Lr} ${Lr} ${Lr} ${Lr} ${Lr} ${Lr}\)`}|${Xr}|${Ir}|${Yr}|${Br}|${Rr})`,zr=String.raw`^\s*(?:${`(?:${Wr}*)`}?)\s*$`,Nr=new RegExp(zr),Hr=new RegExp(Wr),Gr=new RegExp(Wr,"g");function Vr(t){let e=[];if(!(t=(t=>ts(t.replace(Pr," $1 ").replace(/,/gi," ")))(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!Nr.test(t))return[...zt];for(let i of t.matchAll(Gr)){let t=Hr.exec(i[0]);if(!t)continue;let s=zt,[,r,...n]=t.filter((t=>!!t)),[h,o,a,l,u,c]=n.map((t=>parseFloat(t)));switch(r){case"translate":s=We(h,o);break;case Qt:s=ze({angle:h},{x:o,y:a});break;case re:s=Ne(h,o);break;case oe:s=Ge(h);break;case ae:s=Ve(h);break;case"matrix":s=[h,o,a,l,u,c]}e.push(s)}return Be(e)}function Ur(t,e,i,s){let r,n=Array.isArray(e),h=e;if("fill"!==t&&"stroke"!==t||"none"!==e){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)h="none"===e?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)h=i&&i.transformMatrix?Le(i.transformMatrix,Vr(e)):Vr(e);else if("visible"===t)h="none"!==e&&"hidden"!==e,i&&!1===i.visible&&(h=!1);else if("opacity"===t)h=parseFloat(e),i&&void 0!==i.opacity&&(h*=i.opacity);else if("textAnchor"===t)h="start"===e?Ht:"end"===e?Vt:Nt;else if("charSpacing"===t||"textDecorationThickness"===t)r=as(e,s)/s*1e3;else if("paintFirst"===t){let t=e.indexOf(le),i=e.indexOf(ue);h=le,(t>-1&&i>-1&&i<t||-1===t&&i>-1)&&(h=ue)}else{if("href"===t||"xlink:href"===t||"font"===t||"id"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;r=n?e.map(as):as(e,s)}}else h="";return!n&&isNaN(r)?h:r}function qr(t){let e={},i=t.getAttribute("style");return i&&("string"==typeof i?function(t,e){t.replace(/;\s*$/,"").split(";").forEach((t=>{if(!t)return;let[i,s]=t.split(":");e[i.trim().toLowerCase()]=s.trim()}))}(i,e):function(t,e){Object.entries(t).forEach((([t,i])=>{void 0!==i&&(e[t.toLowerCase()]=i)}))}(i,e)),e}const Kr={stroke:"strokeOpacity",fill:"fillOpacity"};function Jr(t,e,i){if(!t)return{};let s,r={},n=16;t.parentNode&&Ts.test(t.parentNode.nodeName)&&(r=Jr(t.parentElement,e,i),r.fontSize&&(s=n=as(r.fontSize)));let h={...e.reduce(((e,i)=>{let s=t.getAttribute(i);return s&&(e[i]=s),e}),{}),...Ar(t,i),...qr(t)};h["clip-path"]&&t.setAttribute(Ms,h[Ms]),h["font-size"]&&(s=as(h[_s],n),h[_s]=`${s}`);let o={};for(let t in h){let e=Er(t);o[e]=Ur(e,h[t],r,s)}o&&o.font&&function(t,e){let i=t.match(Cs);if(!i)return;let s=i[1],r=i[3],n=i[4],h=i[5],o=i[6];s&&(e.fontStyle=s),r&&(e.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),n&&(e.fontSize=as(n)),o&&(e.fontFamily=o),h&&(e.lineHeight="normal"===h?1:h)}(o.font,o);let a={...r,...o};return Ts.test(t.nodeName)?a:function(t){let e=xr.getDefaults();return Object.entries(Kr).forEach((([i,s])=>{if(void 0===t[s]||""===t[i])return;if(void 0===t[i]){if(!e[i])return;t[i]=e[i]}if(0===t[i].indexOf("url("))return;let r=new os(t[i]);t[i]=r.setAlpha(ti(r.getAlpha()*t[s],2)).toRgba()})),t}(a)}const Zr=["rx","ry"];var Qr=class t extends xr{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e){super(),Object.assign(this,t.ownDefaults),this.setOptions(e),this._initRxRy()}_initRxRy(){let{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){let{width:e,height:i}=this,s=-e/2,r=-i/2,n=this.rx?Math.min(this.rx,e/2):0,h=this.ry?Math.min(this.ry,i/2):0,o=0!==n||0!==h;t.beginPath(),t.moveTo(s+n,r),t.lineTo(s+e-n,r),o&&t.bezierCurveTo(s+e-.4477152502*n,r,s+e,r+.4477152502*h,s+e,r+h),t.lineTo(s+e,r+i-h),o&&t.bezierCurveTo(s+e,r+i-.4477152502*h,s+e-.4477152502*n,r+i,s+e-n,r+i),t.lineTo(s+n,r+i),o&&t.bezierCurveTo(s+.4477152502*n,r+i,s,r+i-.4477152502*h,s,r+i-h),t.lineTo(s,r+h),o&&t.bezierCurveTo(s,r+.4477152502*h,s+.4477152502*n,r,s+n,r),t.closePath(),this._renderPaintInOrder(t)}toObject(t=[]){return super.toObject([...Zr,...t])}_toSVG(){let{width:t,height:e,rx:i,ry:s}=this;return["<rect ","COMMON_PARTS",`x="${-t/2}" y="${-e/2}" rx="${gi(i)}" ry="${gi(s)}" width="${gi(t)}" height="${gi(e)}" />\n`]}static async fromElement(t,e,i){let{left:s=0,top:r=0,width:n=0,height:h=0,visible:o=!0,...a}=Jr(t,this.ATTRIBUTE_NAMES,i);return new this({...e,...a,left:s,top:r,width:n,height:h,visible:!!(o&&n&&h)})}};Ct(Qr,"type","Rect"),Ct(Qr,"cacheProperties",[...js,...Zr]),Ct(Qr,"ownDefaults",{rx:0,ry:0}),Ct(Qr,"ATTRIBUTE_NAMES",[...Dr,"x","y","rx","ry","width","height"]),ge.setClass(Qr),ge.setSVGClass(Qr);const tn="initialization",en="added",sn=(t,e)=>{let{strokeUniform:i,strokeWidth:s,width:r,height:n,group:h}=e,o=h&&h!==t?ki(h.calcTransformMatrix(),t.calcTransformMatrix()):null,a=o?e.getRelativeCenterPoint().transform(o):e.getRelativeCenterPoint(),l=!e.isStrokeAccountedForInDimensions(),u=i&&l?((t,e=zt,i=zt)=>t.transform(ki(e,i),!0))(new be(s,s),void 0,t.calcTransformMatrix()):xe,c=!i&&l?s:0,f=Ti(r+c,n+c,Be([o,e.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[a.subtract(f),a.add(f)]};var rn=class{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout({type:t,prevStrategy:e,strategy:i}){return"initialization"===t||"imperative"===t||!!e&&i!==e}shouldLayoutClipPath({type:t,target:{clipPath:e}}){return"initialization"!==t&&e&&!e.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){let{type:i,target:s}=e;if("imperative"===i&&e.overrides)return e.overrides;if(0===t.length)return;let{left:r,top:n,width:h,height:o}=Si(t.map((t=>sn(s,t))).reduce(((t,e)=>t.concat(e)),[])),a=new be(h,o),l=new be(r,n).add(a.scalarDivide(2));if("initialization"===i){let t=this.getInitialSize(e,{size:a,center:l});return{center:l,relativeCorrection:new be(0,0),size:t}}return{center:l.transform(s.calcOwnMatrix()),size:a}}};Ct(rn,"type","strategy");var nn=class extends rn{shouldPerformLayout(t){return!0}};Ct(nn,"type","fit-content"),ge.setClass(nn);const hn="layoutManager";var on=class{constructor(t=new nn){Ct(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){let e={bubbles:!0,strategy:this.strategy,...t,prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}};this.onBeforeLayout(e);let i=this.getLayoutResult(e);i&&this.commitLayout(e,i),this.onAfterLayout(e,i),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){let{target:i}=e;return[ce,Kt,ee,Zt,Jt,te,se,ie,"modifyPath"].map((e=>t.on(e,(t=>this.performLayout("modified"===e?{type:"object_modified",trigger:e,e:t,target:i}:{type:"object_modifying",trigger:e,e:t,target:i})))))}subscribe(t,e){this.unsubscribe(t,e);let i=this.attachHandlers(t,e);this._subscriptions.set(t,i)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach((t=>t())),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach((e=>this.unsubscribe(e,t)))}subscribeTargets(t){t.targets.forEach((e=>this.subscribe(e,t)))}onBeforeLayout(t){let{target:e,type:i}=t,{canvas:s}=e;if("initialization"===i||"added"===i?this.subscribeTargets(t):"removed"===i&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),s&&s.fire("object:layout:before",{target:e,context:t}),"imperative"===i&&t.deep){let{strategy:i,...s}=t;e.forEachObject((t=>t.layoutManager&&t.layoutManager.performLayout({...s,bubbles:!1,target:t})))}}getLayoutResult(t){let{target:e,strategy:i,type:s}=t,r=i.calcLayoutResult(t,e.getObjects());if(!r)return;let n="initialization"===s?new be:e.getRelativeCenterPoint(),{center:h,correction:o=new be,relativeCorrection:a=new be}=r;return{result:r,prevCenter:n,nextCenter:h,offset:n.subtract(h).add(o).transform("initialization"===s?zt:Pe(e.calcOwnMatrix()),!0).add(a)}}commitLayout(t,e){let{target:i}=t,{result:{size:s},nextCenter:r}=e;var n,h;i.set({width:s.x,height:s.y}),this.layoutObjects(t,e),"initialization"===t.type?i.set({left:null==(n=t.x)?r.x+s.x*Di(i.originX):n,top:null==(h=t.y)?r.y+s.y*Di(i.originY):h}):(i.setPositionByOrigin(r,Nt,Nt),i.setCoords(),i.set("dirty",!0))}layoutObjects(t,e){let{target:i}=t;i.forEachObject((s=>{s.group===i&&this.layoutObject(t,e,s)})),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,i.clipPath)}layoutObject(t,{offset:e},i){i.set({left:i.left+e.x,top:i.top+e.y})}onAfterLayout(t,e){let{target:i,strategy:s,bubbles:r,prevStrategy:n,...h}=t,{canvas:o}=i;i.fire("layout:after",{context:t,result:e}),o&&o.fire("object:layout:after",{context:t,result:e,target:i});let a=i.parent;r&&null!=a&&a.layoutManager&&((h.path||(h.path=[])).push(i),a.layoutManager.performLayout({...h,target:a})),i.set("dirty",!0)}dispose(){let{_subscriptions:t}=this;t.forEach((t=>t.forEach((t=>t())))),t.clear()}toObject(){return{type:hn,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}};ge.setClass(on,hn);var an=class extends on{performLayout(){}},ln=class t extends(Se(xr)){static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e=[],i={}){super(),Ct(this,"_activeObjects",[]),Ct(this,"__objectSelectionTracker",void 0),Ct(this,"__objectSelectionDisposer",void 0),Object.assign(this,t.ownDefaults),this.setOptions(i),this.groupInit(e,i)}groupInit(t,e){var i;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject((t=>{this.enterGroup(t,!1)})),this.layoutManager=null==(i=e.layoutManager)?new on:i,this.layoutManager.performLayout({type:tn,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Mt("error","Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(Mt("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter(((t,e,i)=>this.canEnterGroup(t)&&i.indexOf(t)===e))}add(...t){let e=this._filterObjectsBeforeEnteringGroup(t),i=super.add(...e);return this._onAfterObjectsChange(en,e),i}insertAt(t,...e){let i=this._filterObjectsBeforeEnteringGroup(e),s=super.insertAt(t,...i);return this._onAfterObjectsChange(en,i),s}remove(...t){let e=super.remove(...t);return this._onAfterObjectsChange("removed",e),e}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){let i=this[t];return super._set(t,e),"canvas"===t&&i!==e&&(this._objects||[]).forEach((i=>{i._set(t,e)})),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,{target:e}){let i=this._activeObjects;if(t)i.push(e),this._set("dirty",!0);else if(i.length>0){let t=i.indexOf(e);t>-1&&(i.splice(t,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&_i(t,Le(Pe(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);let i=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();i&&(i===t||t.isDescendantOf(i))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(_i(t,Le(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);let i=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;i>-1&&this._activeObjects.splice(i,1)}shouldCache(){let t=xr.prototype.shouldCache.call(this);if(t)for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return this.ownCaching=!1,!1;return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,i){this._renderBackground(t);for(let e=0;e<this._objects.length;e++){var s;let i=this._objects[e];null!=(s=this.canvas)&&s.preserveObjectStacking&&i.group!==this?(t.save(),t.transform(...Pe(this.calcTransformMatrix())),i.render(t),t.restore()):i.group===this&&i.render(t)}this._drawClipPath(t,this.clipPath,i)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}triggerLayout(t={}){this.layoutManager.performLayout({target:this,type:"imperative",...t})}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){let i=this.includeDefaultValues;return this._objects.filter((function(t){return!t.excludeFromExport})).map((function(s){let r=s.includeDefaultValues;s.includeDefaultValues=i;let n=s[t||"toObject"](e);return s.includeDefaultValues=r,n}))}toObject(t=[]){let e=this.layoutManager.toObject();return{...super.toObject(["subTargetCheck","interactive",...t]),..."fit-content"!==e.strategy||this.includeDefaultValues?{layoutManager:e}:{},objects:this.__serializeObjects("toObject",t)}}toString(){return`#<Group: (${this.complexity()})>`}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject((t=>{this._watchObject(!1,t),t.dispose()})),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";let e=Qr.prototype._toSVG.call(this),i=e.indexOf("COMMON_PARTS");e[i]='for="group" ';let s=e.join("");return t?t(s):s}_toSVG(t){let e=["<g ","COMMON_PARTS"," >\n"],i=this._createSVGBgRect(t);i&&e.push("\t\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t\t",this._objects[i].toSVG(t));return e.push("</g>\n"),e}getSvgStyles(){let t=void 0!==this.opacity&&1!==this.opacity?`opacity: ${gi(this.opacity)};`:"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){let e=[],i=this._createSVGBgRect(t);i&&e.push("\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject({type:t,objects:e=[],layoutManager:i,...s},r){return Promise.all([Ke(e,r),Je(s,r)]).then((([t,e])=>{let r=new this(t,{...s,...e,layoutManager:new an});return r.layoutManager=i?new(ge.getClass(i.type))(new(ge.getClass(i.strategy))):new on,r.layoutManager.subscribeTargets({type:tn,target:r,targets:r.getObjects()}),r.setCoords(),r}))}};Ct(ln,"type","Group"),Ct(ln,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),ge.setClass(ln);const un="\\s*,?\\s*",cn=`${un}(${xs})`,fn=`${cn}${cn}${cn}${un}([01])${un}([01])${cn}${cn}`,dn={m:"l",M:"L"},gn=(t,e,i,s,r,n,h,o,a,l,u)=>{let c=ye(t),f=we(t),d=ye(e),g=we(e),p=i*r*d-s*n*g+h,m=s*r*d+i*n*g+o;return["C",l+a*(-i*r*f-s*n*c),u+a*(-s*r*f+i*n*c),p+a*(i*r*g+s*n*d),m+a*(s*r*g-i*n*d),p,m]},pn=(t,e,i,s)=>{let r=Math.atan2(e,t),n=Math.atan2(s,i);return n>=r?n-r:2*Math.PI-(r-n)};function mn(t,e,i,s,r,n,h,o){let a;if(_t.cachesBoundsOfCurve&&(a=[...arguments].join(),Lt.boundsOfCurveCache[a]))return Lt.boundsOfCurveCache[a];let l=Math.sqrt,u=Math.abs,c=[],f=[[0,0],[0,0]],d=6*t-12*i+6*r,g=-3*t+9*i-9*r+3*h,p=3*i-3*t;for(let t=0;t<2;++t){if(t>0&&(d=6*e-12*s+6*n,g=-3*e+9*s-9*n+3*o,p=3*s-3*e),u(g)<1e-12){if(u(d)<1e-12)continue;let t=-p/d;0<t&&t<1&&c.push(t);continue}let i=d*d-4*p*g;if(i<0)continue;let r=l(i),h=(-d+r)/(2*g);0<h&&h<1&&c.push(h);let a=(-d-r)/(2*g);0<a&&a<1&&c.push(a)}let m=c.length,v=m,y=wn(t,e,i,s,r,n,h,o);for(;m--;){let{x:t,y:e}=y(c[m]);f[0][m]=t,f[1][m]=e}f[0][v]=t,f[1][v]=e,f[0][v+1]=h,f[1][v+1]=o;let w=[new be(Math.min(...f[0]),Math.min(...f[1])),new be(Math.max(...f[0]),Math.max(...f[1]))];return _t.cachesBoundsOfCurve&&(Lt.boundsOfCurveCache[a]=w),w}const vn=(t,e,[i,s,r,n,h,o,a,l])=>{let u=((t,e,i,s,r,n,h)=>{if(0===i||0===s)return[];let o=0,a=0,l=0,u=Math.PI,c=h*Wt,f=we(c),d=ye(c),g=.5*(-d*t-f*e),p=.5*(-d*e+f*t),m=i**2,v=s**2,y=p**2,w=g**2,b=m*v-m*y-v*w,x=Math.abs(i),C=Math.abs(s);if(b<0){let t=Math.sqrt(1-b/(m*v));x*=t,C*=t}else l=(r===n?-1:1)*Math.sqrt(b/(m*y+v*w));let S=l*x*p/C,_=-l*C*g/x,M=d*S-f*_+.5*t,T=f*S+d*_+.5*e,k=pn(1,0,(g-S)/x,(p-_)/C),F=pn((g-S)/x,(p-_)/C,(-g-S)/x,(-p-_)/C);0===n&&F>0?F-=2*u:1===n&&F<0&&(F+=2*u);let O=Math.ceil(Math.abs(F/u*2)),D=[],$=F/O,j=8/3*Math.sin($/4)*Math.sin($/4)/Math.sin($/2),A=k+$;for(let t=0;t<O;t++)D[t]=gn(k,A,d,f,x,C,M,T,j,o,a),o=D[t][5],a=D[t][6],k=A,A+=$;return D})(a-t,l-e,s,r,h,o,n);for(let i=0,s=u.length;i<s;i++)u[i][1]+=t,u[i][2]+=e,u[i][3]+=t,u[i][4]+=e,u[i][5]+=t,u[i][6]+=e;return u},yn=(t,e,i,s)=>Math.sqrt((i-t)**2+(s-e)**2),wn=(t,e,i,s,r,n,h,o)=>a=>{let l=a**3,u=(t=>3*t**2*(1-t))(a),c=(t=>3*t*(1-t)**2)(a),f=(t=>(1-t)**3)(a);return new be(h*l+r*u+i*c+t*f,o*l+n*u+s*c+e*f)},bn=t=>t**2,xn=t=>2*t*(1-t),Cn=t=>(1-t)**2,Sn=(t,e,i,s,r,n,h,o)=>a=>{let l=bn(a),u=xn(a),c=Cn(a);return Math.atan2(3*(c*(s-e)+u*(n-s)+l*(o-n)),3*(c*(i-t)+u*(r-i)+l*(h-r)))},_n=(t,e,i,s,r,n)=>h=>{let o=bn(h),a=xn(h),l=Cn(h);return new be(r*o+i*a+t*l,n*o+s*a+e*l)},Mn=(t,e,i,s,r,n)=>h=>{let o=1-h;return Math.atan2(2*(o*(s-e)+h*(n-s)),2*(o*(i-t)+h*(r-i)))},Tn=(t,e,i)=>{let s=new be(e,i),r=0;for(let e=1;e<=100;e+=1){let i=t(e/100);r+=yn(s.x,s.y,i.x,i.y),s=i}return r},kn=t=>{let e,i,s=0,r=0,n=0,h=0,o=0,a=[];for(let l of t){let t={x:r,y:n,command:l[0],length:0};switch(l[0]){case"M":i=t,i.x=h=r=l[1],i.y=o=n=l[2];break;case"L":i=t,i.length=yn(r,n,l[1],l[2]),r=l[1],n=l[2];break;case"C":e=wn(r,n,l[1],l[2],l[3],l[4],l[5],l[6]),i=t,i.iterator=e,i.angleFinder=Sn(r,n,l[1],l[2],l[3],l[4],l[5],l[6]),i.length=Tn(e,r,n),r=l[5],n=l[6];break;case"Q":e=_n(r,n,l[1],l[2],l[3],l[4]),i=t,i.iterator=e,i.angleFinder=Mn(r,n,l[1],l[2],l[3],l[4]),i.length=Tn(e,r,n),r=l[3],n=l[4];break;case"Z":i=t,i.destX=h,i.destY=o,i.length=yn(r,n,h,o),r=h,n=o}s+=i.length,a.push(i)}return a.push({length:s,x:r,y:n}),a},Fn=RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),On=new RegExp(fn,"g"),Dn=new RegExp(xs,"gi"),$n={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},jn=(t,e)=>t.map((t=>t.map(((t,i)=>0===i||void 0===e?t:ti(t,e))).join(" "))).join(" ");function An(t,e){let i=t.style;i&&Object.entries(e).forEach((([t,e])=>i.setProperty(t,e)))}var En=class extends fi{constructor(t,{allowTouchScrolling:e=!1,containerClass:i=""}={}){super(t),Ct(this,"upper",void 0),Ct(this,"container",void 0);let{el:s}=this.lower,r=this.createUpperCanvas();this.upper={el:r,ctx:r.getContext("2d")},this.applyCanvasStyle(s,{allowTouchScrolling:e}),this.applyCanvasStyle(r,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});let n=this.createContainerElement();n.classList.add(i),s.parentNode&&s.parentNode.replaceChild(n,s),n.append(s,r),this.container=n}createUpperCanvas(){let{el:t}=this.lower,e=Fe();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){let t=At().createElement("div");return t.setAttribute("data-fabric","wrapper"),An(t,{position:"relative"}),ci(t),t}applyCanvasStyle(t,e){let{styles:i,allowTouchScrolling:s}=e;An(t,{...i,"touch-action":s?"manipulation":Ut}),ci(t)}setDimensions(t,e){super.setDimensions(t,e);let{el:i,ctx:s}=this.upper;li(i,s,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),ui(this.upper.el,t),ui(this.container,t)}cleanupDOM(t){let e=this.container,{el:i}=this.lower,{el:s}=this.upper;super.cleanupDOM(t),e.removeChild(s),e.removeChild(i),e.parentNode&&e.parentNode.replaceChild(i,e)}dispose(){super.dispose(),jt().dispose(this.upper.el),delete this.upper,delete this.container}};const Pn=(t,e,i,s)=>{let{target:r,offsetX:n,offsetY:h}=e,o=i-n,a=s-h,l=!Gi(r,"lockMovementX")&&r.left!==o,u=!Gi(r,"lockMovementY")&&r.top!==a;return l&&r.set("left",o),u&&r.set("top",a),(l||u)&&Gs(Kt,Vi(t,e,i,s)),l||u};var Ln=class t extends wi{constructor(...t){super(...t),Ct(this,"_hoveredTargets",[]),Ct(this,"_currentTransform",null),Ct(this,"_groupSelector",null),Ct(this,"contextTopDirty",!1)}static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}get upperCanvasEl(){var t;return null==(t=this.elements.upper)?void 0:t.el}get contextTop(){var t;return null==(t=this.elements.upper)?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new En(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){let t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){let t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;let e=this.getRetinaScaling(),i=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=i,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,i){let s=this.targetFindTolerance,r=this.pixelFindContext;this.clearContext(r),r.save(),r.translate(-e+s,-i+s),r.transform(...this.viewportTransform);let n=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(r),t.selectionBackgroundColor=n,r.restore();let h=Math.round(s*this.getRetinaScaling());return((t,e,i,s)=>{let r=2*(s=Math.round(s))+1,{data:n}=t.getImageData(e-s,i-s,r,r);for(let t=3;t<n.length;t+=4)if(n[t]>0)return!1;return!0})(r,h,h,h)}_isSelectionKeyPressed(t){let e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((e=>!!e&&!0===t[e])):t[e])}_shouldClearSelection(t,e){let i=this.getActiveObjects(),s=this._activeObject;return!!(!e||e&&s&&i.length>1&&-1===i.indexOf(e)&&s!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&s&&s!==e)}_shouldCenterTransform(t,e,i){if(!t)return;let s;return"scale"===e||"scaleX"===e||"scaleY"===e||"resizing"===e?s=this.centeredScaling||t.centeredScaling:"rotate"===e&&(s=this.centeredRotation||t.centeredRotation),s?!i:i}_getOriginFromCorner(t,e){let i=e?t.controls[e].getTransformAnchorPoint():{x:t.originX,y:t.originY};return e?(["ml","tl","bl"].includes(e)?i.x=Vt:["mr","tr","br"].includes(e)&&(i.x=Ht),["tl","mt","tr"].includes(e)?i.y=Gt:["bl","mb","br"].includes(e)&&(i.y="top"),i):i}_setupCurrentTransform(t,e,i){var s;let r=e.group?Fi(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:n="",control:h}=e.getActiveControl()||{},o=i&&h?null==(s=h.getActionHandler(t,e,h))?void 0:s.bind(h):Pn,a=((t,e,i,s)=>{if(!e||!t)return"drag";let r=s.controls[e];return r.getActionName(i,r,s)})(i,n,t,e),l=t[this.centeredKey],u=this._shouldCenterTransform(e,a,l)?{x:Nt,y:Nt}:this._getOriginFromCorner(e,n),{scaleX:c,scaleY:f,skewX:d,skewY:g,left:p,top:m,angle:v,width:y,height:w,cropX:b,cropY:x}=e,C={target:e,action:a,actionHandler:o,actionPerformed:!1,corner:n,scaleX:c,scaleY:f,skewX:d,skewY:g,offsetX:r.x-p,offsetY:r.y-m,originX:u.x,originY:u.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:je(v),width:y,height:w,shiftKey:t.shiftKey,altKey:l,original:{...Mi(e),originX:u.x,originY:u.y,cropX:b,cropY:x}};this._currentTransform=C,this.fire("before:transform",{e:t,transform:C})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){let{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new be(e,i).transform(this.viewportTransform),h=new be(e+s,i+r).transform(this.viewportTransform),o=this.selectionLineWidth/2,a=Math.min(n.x,h.x),l=Math.min(n.y,h.y),u=Math.max(n.x,h.x),c=Math.max(n.y,h.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(a,l,u-a,c-l)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,a+=o,l+=o,u-=o,c-=o,xr.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(a,l,u-a,c-l))}findTarget(t){if(this._targetInfo)return this._targetInfo;if(this.skipTargetFind)return{subTargets:[],currentSubTargets:[]};let e=this.getScenePoint(t),i=this._activeObject,s=this.getActiveObjects(),r=this.searchPossibleTargets(this._objects,e),{subTargets:n,container:h,target:o}=r,a={...r,currentSubTargets:n,currentContainer:h,currentTarget:o};if(!i)return a;let l={...this.searchPossibleTargets([i],e),currentSubTargets:n,currentContainer:h,currentTarget:o};return i.findControl(this.getViewportPoint(t),xi(t))?{...l,target:i}:l.target&&(s.length>1||!this.preserveObjectStacking||this.preserveObjectStacking&&t[this.altSelectionKey])?l:a}_pointIsInObjectSelectionArea(t,e){let i=t.getCoords(),s=this.getZoom(),r=t.padding/s;if(r){let[t,e,s,n]=i,h=Math.atan2(e.y-t.y,e.x-t.x),o=ye(h)*r,a=we(h)*r,l=o+a,u=o-a;i=[new be(t.x-u,t.y-l),new be(e.x+l,e.y-u),new be(s.x+u,s.y+l),new be(n.x-l,n.y+u)]}return zs.isPointInPolygon(e,i)}_checkTarget(t,e){if(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,e)){if(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing)return!0;{let i=e.transform(this.viewportTransform);if(!this.isTargetTransparent(t,i.x,i.y))return!0}}return!1}_searchPossibleTargets(t,e,i){let s=t.length;for(;s--;){let r=t[s];if(this._checkTarget(r,e)){if(Ce(r)&&r.subTargetCheck){let{target:t}=this._searchPossibleTargets(r._objects,e,i);t&&i.push(t)}return{target:r,subTargets:i}}}return{subTargets:[]}}searchPossibleTargets(t,e){let i=this._searchPossibleTargets(t,e,[]);i.container=i.target;let{container:s,subTargets:r}=i;if(s&&Ce(s)&&s.interactive&&r[0]){for(let t=r.length-1;t>0;t--){let e=r[t];if(!Ce(e)||!e.interactive)return i.target=e,i}return i.target=r[0],i}return i}getViewportPoint(t){return this._viewportPoint?this._viewportPoint:this._getPointerImpl(t,!0)}getScenePoint(t){return this._scenePoint?this._scenePoint:this._getPointerImpl(t)}_getPointerImpl(t,e=!1){let i=this.upperCanvasEl,s=i.getBoundingClientRect(),r=(t=>{let e=hi(t.target),i=function(t){let e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new be(i.clientX+e.left,i.clientY+e.top)})(t),n=s.width||0,h=s.height||0;n&&h||("top"in s&&"bottom"in s&&(h=Math.abs(s.top-s.bottom)),"right"in s&&"left"in s&&(n=Math.abs(s.right-s.left))),this.calcOffset(),r.x-=this._offset.left,r.y-=this._offset.top,e||(r=Fi(r,void 0,this.viewportTransform));let o=this.getRetinaScaling();1!==o&&(r.x/=o,r.y/=o);let a=0===n||0===h?new be(1,1):new be(i.width/n,i.height/h);return r.multiply(a)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Fe(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){let t=this._activeObject;return ni(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let i=!1,s=!1,r=this.getActiveObjects(),n=[],h=[];t.forEach((t=>{r.includes(t)||(i=!0,t.fire("deselected",{e,target:t}),h.push(t))})),r.forEach((s=>{t.includes(s)||(i=!0,s.fire("selected",{e,target:s}),n.push(s))})),t.length>0&&r.length>0?(s=!0,i&&this.fire("selection:updated",{e,selected:n,deselected:h})):r.length>0?(s=!0,this.fire("selection:created",{e,selected:n})):t.length>0&&(s=!0,this.fire("selection:cleared",{e,deselected:h})),s&&(this._objectsToRender=void 0)}setActiveObject(t,e){let i=this.getActiveObjects(),s=this._setActiveObject(t,e);return this._fireSelectionEvents(i,e),s}_setActiveObject(t,e){let i=this._activeObject;return!(i===t||!this._discardActiveObject(e,t)&&this._activeObject||t.onSelect({e})||(this._activeObject=t,ni(t)&&i!==t&&t.set("canvas",this),t.setCoords(),0))}_discardActiveObject(t,e){let i=this._activeObject;return!!i&&!i.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===i&&this.endCurrentTransform(t),ni(i)&&i===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){let e=this.getActiveObjects(),i=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[i]});let s=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),s}endCurrentTransform(t){let e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){let e=this._currentTransform,i=e.target,s={e:t,target:i,transform:e,action:e.action};i._scaling&&(i._scaling=!1),i.setCoords(),e.actionPerformed&&(this.fire("object:modified",s),i.fire(ce,s))}setViewportTransform(t){super.setViewportTransform(t);let e=this._activeObject;e&&e.setCoords()}destroy(){let t=this._activeObject;ni(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){let e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,i){let s=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,i);return t.set(s),r}_realizeGroupTransformOnObject(t){let{group:e}=t;if(e&&ni(e)&&this._activeObject===e){let i=Ze(t,["angle","flipX","flipY",Ht,ne,he,oe,ae,"top"]);return((t,e)=>{_i(t,Le(e,t.calcOwnMatrix()))})(t,e.calcOwnMatrix()),i}return{}}_setSVGObject(t,e,i){let s=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,i),e.set(s)}};Ct(Ln,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!0,fireRightClick:!0,fireMiddleClick:!0,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!0});var Bn=class{constructor(t){Ct(this,"targets",[]),Ct(this,"__disposer",void 0);let e=()=>{let{hiddenTextarea:e}=t.getActiveObject()||{};e&&e.focus()},i=t.upperCanvasEl;i.addEventListener("click",e),this.__disposer=()=>i.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),ve(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;null!=(e=this.target)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}};const Rn={passive:!1},In=(t,e)=>({viewportPoint:t.getViewportPoint(e),scenePoint:t.getScenePoint(e)}),Yn=(t,...e)=>t.addEventListener(...e),Xn=(t,...e)=>t.removeEventListener(...e),Wn={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};var zn=class extends Ln{constructor(t,e={}){super(t,e),Ct(this,"_isClick",void 0),Ct(this,"textEditingManager",new Bn(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((t=>{this[t]=this[t].bind(this)})),this.addOrRemove(Yn)}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e=!1){let i=this.upperCanvasEl,s=this._getEventPrefix();t(ai(i),"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,`${s}move`,this._onMouseMove,Rn),t(i,`${s}out`,this._onMouseOut),t(i,`${s}enter`,this._onMouseEnter),t(i,"wheel",this._onMouseWheel,{passive:!1}),t(i,"contextmenu",this._onContextMenu),e||(t(i,"click",this._onClick),t(i,"dblclick",this._onClick)),t(i,"dragstart",this._onDragStart),t(i,"dragend",this._onDragEnd),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,Rn)}removeListeners(){this.addOrRemove(Xn);let t=this._getEventPrefix(),e=oi(this.upperCanvasEl);Xn(e,`${t}up`,this._onMouseUp),Xn(e,"touchend",this._onTouchEnd,Rn),Xn(e,`${t}move`,this._onMouseMove,Rn),Xn(e,"touchmove",this._onMouseMove,Rn),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_onMouseOut(t){let e=this._hoveredTarget,i={e:t,...In(this,t)};this.fire("mouse:out",{...i,target:e}),this._hoveredTarget=void 0,e&&e.fire("mouseout",{...i}),this._hoveredTargets.forEach((t=>{this.fire("mouse:out",{...i,target:t}),t&&t.fire("mouseout",{...i})})),this._hoveredTargets=[]}_onMouseEnter(t){let{target:e}=this.findTarget(t);this._currentTransform||e||(this.fire("mouse:over",{e:t,...In(this,t)}),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;let e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;let i={e:t,target:e};return this.fire("dragstart",i),e.fire("dragstart",i),void Yn(this.upperCanvasEl,"drag",this._onDragProgress)}Ci(t)}_renderDragEffects(t,e,i){let s=!1,r=this._dropTarget;r&&r!==e&&r!==i&&(r.clearContextTop(),s=!0),null==e||e.clearContextTop(),i!==e&&(null==i||i.clearContextTop());let n=this.contextTop;n.save(),n.transform(...this.viewportTransform),e&&(n.save(),e.transform(n),e.renderDragSourceEffect(t),n.restore(),s=!0),i&&(n.save(),i.transform(n),i.renderDropTargetEffect(t),n.restore(),s=!0),n.restore(),s&&(this.contextTopDirty=!0)}_onDragEnd(t){let{currentSubTargets:e}=this.findTarget(t),i=!!t.dataTransfer&&"none"!==t.dataTransfer.dropEffect,s={e:t,target:this._dragSource,subTargets:e,dragSource:this._dragSource,didDrop:i,dropTarget:i?this._activeObject:void 0};Xn(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",s),this._dragSource&&this._dragSource.fire("dragend",s),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){let e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}_onDragOver(t){let e,i="dragover",{currentContainer:s,currentSubTargets:r}=this.findTarget(t),n=this._dragSource,h={e:t,target:s,subTargets:r,dragSource:n,canDrop:!1,dropTarget:void 0};this.fire(i,h),this._fireEnterLeaveEvents(t,s,h),s&&(s.canDrop(t)&&(e=s),s.fire(i,h));for(let s=0;s<r.length;s++){let n=r[s];n.canDrop(t)&&(e=n),n.fire(i,h)}this._renderDragEffects(t,n,e),this._dropTarget=e}_onDragEnter(t){let{currentContainer:e,currentSubTargets:i}=this.findTarget(t),s={e:t,target:e,subTargets:i,dragSource:this._dragSource};this.fire("dragenter",s),this._fireEnterLeaveEvents(t,e,s)}_onDragLeave(t){let{currentSubTargets:e}=this.findTarget(t),i={e:t,target:this._draggedoverTarget,subTargets:e,dragSource:this._dragSource};this.fire("dragleave",i),this._fireEnterLeaveEvents(t,void 0,i),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this._hoveredTargets=[]}_onDrop(t){let{currentContainer:e,currentSubTargets:i}=this.findTarget(t),s=this._basicEventHandler("drop:before",{e:t,target:e,subTargets:i,dragSource:this._dragSource,...In(this,t)});s.didDrop=!1,s.dropTarget=void 0,this._basicEventHandler("drop",s),this.fire("drop:after",s)}_onContextMenu(t){let{target:e,subTargets:i}=this.findTarget(t),s=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:i});return this.stopContextMenu&&Ci(t),this._basicEventHandler("contextmenu",s),!1}_onClick(t){let e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),2==e&&"dblclick"===t.type&&this._handleEvent(t,"dblclick"),3==e&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}fireEventFromPointerEvent(t,e,i,s={}){this._cacheTransformEventData(t);let{target:r,subTargets:n}=this.findTarget(t),h={e:t,target:r,subTargets:n,...In(this,t),transform:this._currentTransform,...s};this.fire(e,h),r&&r.fire(i,h);for(let t=0;t<n.length;t++)n[t]!==r&&n[t].fire(i,h);this._resetTransformEventData()}getPointerId(t){let e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){this._cacheTransformEventData(t);let e=!this.allowTouchScrolling,i=this._activeObject;void 0===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t);let{target:s}=this.findTarget(t);(this.isDrawingMode||i&&s===i)&&(e=!0),e&&t.preventDefault();let r=this.upperCanvasEl,n=this._getEventPrefix(),h=oi(r);Yn(h,"touchend",this._onTouchEnd,Rn),e&&Yn(h,"touchmove",this._onMouseMove,Rn),Xn(r,`${n}down`,this._onMouseDown),this._resetTransformEventData()}_onMouseDown(t){this._cacheTransformEventData(t),this.__onMouseDown(t);let e=this.upperCanvasEl,i=this._getEventPrefix();Xn(e,`${i}move`,this._onMouseMove,Rn);let s=oi(e);Yn(s,`${i}up`,this._onMouseUp),Yn(s,`${i}move`,this._onMouseMove,Rn),this._resetTransformEventData()}_onTouchEnd(t){if(t.touches.length>0)return;this._cacheTransformEventData(t),this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;let e=this._getEventPrefix(),i=oi(this.upperCanvasEl);Xn(i,"touchend",this._onTouchEnd,Rn),Xn(i,"touchmove",this._onMouseMove,Rn),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{Yn(this.upperCanvasEl,`${e}down`,this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this._cacheTransformEventData(t),this.__onMouseUp(t);let e=this.upperCanvasEl,i=this._getEventPrefix();if(this._isMainEvent(t)){let t=oi(this.upperCanvasEl);Xn(t,`${i}up`,this._onMouseUp),Xn(t,`${i}move`,this._onMouseMove,Rn),Yn(e,`${i}move`,this._onMouseMove,Rn)}this._resetTransformEventData()}_onMouseMove(t){this._cacheTransformEventData(t);let e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t),this._resetTransformEventData()}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){let e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._handleEvent(t,"up:before");let i=this._currentTransform,s=this._isClick,{target:r}=this.findTarget(t),{button:n}=t;if(n)return void((this.fireMiddleClick&&1===n||this.fireRightClick&&2===n)&&this._handleEvent(t,"up"));if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let h,o,a=!1;if(i&&(this._finalizeCurrentTransform(t),a=i.actionPerformed),!s){let e=r===this._activeObject;this.handleSelection(t),a||(a=this._shouldRender(r)||!e&&r===this._activeObject)}if(r){let{key:e,control:s}=r.findControl(this.getViewportPoint(t),xi(t))||{};if(o=e,r.selectable&&r!==this._activeObject&&"up"===r.activeOn)this.setActiveObject(r,t),a=!0;else if(s){let e=s.getMouseUpHandler(t,r,s);e&&(h=this.getScenePoint(t),e.call(s,t,i,h.x,h.y))}r.isMoving=!1}if(i&&(i.target!==r||i.corner!==o)){let e=i.target&&i.target.controls[i.corner],s=e&&e.getMouseUpHandler(t,i.target,e);h=h||this.getScenePoint(t),s&&s.call(e,t,i,h.x,h.y)}this._setCursorFromEvent(t,r),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,r&&(r.__corner=void 0),a?this.requestRenderAll():s||null!=(e=this._activeObject)&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){let{target:i,subTargets:s=[]}=e;this.fire(t,e),i&&i.fire(t,e);for(let r=0;r<s.length;r++)s[r]!==i&&s[r].fire(t,e);return e}_handleEvent(t,e,i){let{target:s,subTargets:r}=this.findTarget(t),n={e:t,target:s,subTargets:r,...In(this,t),transform:this._currentTransform,..."down:before"===e||"down"===e?i:{}};"up:before"!==e&&"up"!==e||(n.isClick=this._isClick),this.fire(`mouse:${e}`,n),s&&s.fire(`mouse${e}`,n);for(let t=0;t<r.length;t++)r[t]!==s&&r[t].fire(`mouse${e}`,n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());let e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){let e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){let e=this.getScenePoint(t);this._isCurrentlyDrawing=!!this.freeDrawingBrush&&!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}),this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._handleEvent(t,"down:before");let{target:e}=this.findTarget(t),i=!!e&&e===this._activeObject,{button:s}=t;if(s)return void((this.fireMiddleClick&&1===s||this.fireRightClick&&2===s)&&this._handleEvent(t,"down",{alreadySelected:i}));if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let r=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,r=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){let e=this.getScenePoint(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(i=!!e&&e===this._activeObject,e){e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);let s=e.findControl(this.getViewportPoint(t),xi(t));if(e===this._activeObject&&(s||!n)){this._setupCurrentTransform(t,e,i);let r=s?s.control:void 0,n=this.getScenePoint(t),h=r&&r.getMouseDownHandler(t,e,r);h&&h.call(r,t,this._currentTransform,n.x,n.y)}}r&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:i}),r&&this.requestRenderAll()}_resetTransformEventData(){this._targetInfo=this._viewportPoint=this._scenePoint=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._viewportPoint=this.getViewportPoint(t),this._scenePoint=Fi(this._viewportPoint,void 0,this.viewportTransform),this._targetInfo=this.findTarget(t),this._currentTransform&&(this._targetInfo.target=this._currentTransform.target)}__onMouseMove(t){if(this._isClick=!1,this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;let e=this._groupSelector;if(e){let i=this.getScenePoint(t);e.deltaX=i.x-e.x,e.deltaY=i.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{let{target:e}=this.findTarget(t);this._setCursorFromEvent(t,e),this._fireOverOutEvents(t,e)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move")}_fireOverOutEvents(t,e){let{_hoveredTarget:i,_hoveredTargets:s}=this,{subTargets:r,currentTarget:n}=this.findTarget(t),h=Math.max(s.length,r.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:i,actualTarget:n,oldActualTarget:this._hoveredActualTarget,fireCanvas:!0});for(let n=0;n<h;n++)r[n]===e||s[n]&&s[n]===i||this.fireSyntheticInOutEvents("mouse",{e:t,target:r[n],oldTarget:s[n]});this._hoveredActualTarget=n,this._hoveredTarget=e,this._hoveredTargets=r}_fireEnterLeaveEvents(t,e,i){let s=this._draggedoverTarget,r=this._hoveredTargets,{subTargets:n}=this.findTarget(t),h=Math.max(r.length,n.length);this.fireSyntheticInOutEvents("drag",{...i,target:e,oldTarget:s,fireCanvas:!0});for(let t=0;t<h;t++)this.fireSyntheticInOutEvents("drag",{...i,target:n[t],oldTarget:r[t]});this._draggedoverTarget=e}fireSyntheticInOutEvents(t,{target:e,oldTarget:i,actualTarget:s,oldActualTarget:r,fireCanvas:n,e:h,...o}){let{targetIn:a,targetOut:l,canvasIn:u,canvasOut:c}=Wn[t],f=i!==e,d=r!==s,g=e&&f,p=s&&d,m=i&&f,v=r&&d,y={...o,e:h,...In(this,h)},w={...y,target:i,nextTarget:e,actualTarget:r,nextActualTarget:s};(m||v)&&n&&this.fire(c,w),m&&i.fire(l,w),v&&i!==r&&r.fire(l,w);let b={...y,target:e,previousTarget:i,actualTarget:s,previousActualTarget:r};(g||p)&&n&&this.fire(u,b),g&&e.fire(a,b),p&&s!==e&&s.fire(a,b)}_transformObject(t){let e=this.getScenePoint(t),i=this._currentTransform,s=i.target,r=s.group?Fi(e,void 0,s.group.calcTransformMatrix()):e;i.shiftKey=t.shiftKey,i.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,i,r),i.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,i){let{action:s,actionHandler:r,target:n}=e,h=!!r&&r(t,e,i.x,i.y);h&&n.setCoords(),"drag"===s&&h&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||h}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let i=e.hoverCursor||this.hoverCursor,s=ni(this._activeObject)?this._activeObject:null,r=(!s||e.group!==s)&&e.findControl(this.getViewportPoint(t));if(r){let{control:i,coord:s}=r;this.setCursor(i.cursorStyleHandler(t,i,e,s))}else{if(e.subTargetCheck){let{subTargets:e}=this.findTarget(t);e.concat().reverse().forEach((t=>{i=t.hoverCursor||i}))}this.setCursor(i)}}handleMultiSelection(t,e){let i=this._activeObject,s=ni(i);if(i&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(i!==e||s)&&(s||!e.isDescendantOf(i)&&!i.isDescendantOf(e))&&!e.onSelect({e:t})&&!i.getActiveControl()){if(s){let s=i.getObjects(),r=[];if(e===i){let i=this.getScenePoint(t),n=this.searchPossibleTargets(s,i);if(n.target?(e=n.target,r=n.subTargets):(n=this.searchPossibleTargets(this._objects,i),e=n.target,r=n.subTargets),!e||!e.selectable)return!1}e.group===i?(i.remove(e),this._hoveredTarget=e,this._hoveredTargets=r,1===i.size()&&this._setActiveObject(i.item(0),t)):(i.multiSelectAdd(e),this._hoveredTarget=i,this._hoveredTargets=r),this._fireSelectionEvents(s,t)}else{i.isEditing&&i.exitEditing();let s=new(ge.getClass("ActiveSelection"))([],{canvas:this});s.multiSelectAdd(i,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([i],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;let{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new be(e,i),h=n.add(new be(s,r)),o=n.min(h),a=n.max(h).subtract(o),l=this.collectObjects({left:o.x,top:o.y,width:a.x,height:a.y},{includeIntersecting:!this.selectionFullyContained}),u=n.eq(h)?l[0]?[l[0]]:[]:l.length>1?l.filter((e=>!e.onSelect({e:t}))).reverse():l;if(1===u.length)this.setActiveObject(u[0],t);else if(u.length>1){let e=ge.getClass("ActiveSelection");this.setActiveObject(new e(u,{canvas:this}),t)}return this._groupSelector=null,!0}toCanvasElement(t=1,e){let{upper:i}=this.elements;i.ctx=void 0;let s=super.toCanvasElement(t,e);return i.ctx=i.el.getContext("2d"),s}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}};const Nn={x1:0,y1:0,x2:0,y2:0},Hn={...Nn,r1:0,r2:0},Gn=(t,e)=>isNaN(t)&&"number"==typeof e?e:t;function Vn(t){return t&&/%$/.test(t)&&Number.isFinite(parseFloat(t))}function Un(t,e){return Ds(0,Gn("number"==typeof t?t:"string"==typeof t?parseFloat(t)/(Vn(t)?100:1):NaN,e),1)}const qn=/\s*;\s*/,Kn=/\s*:\s*/;function Jn(t,e){let i,s,r=t.getAttribute("style");if(r){let t=r.split(qn);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){let[r,n]=t[e].split(Kn).map((t=>t.trim()));"stop-color"===r?i=n:"stop-opacity"===r&&(s=n)}}i=i||t.getAttribute("stop-color")||"rgb(0,0,0)",s=Gn(parseFloat(s||t.getAttribute("stop-opacity")||""),1);let n=new os(i);return n.setAlpha(n.getAlpha()*s*e),{offset:Un(t.getAttribute("offset"),0),color:n.toRgba()}}function Zn(t,e){let i=[],s=t.getElementsByTagName("stop"),r=Un(e,1);for(let t=s.length;t--;)i.push(Jn(s[t],r));return i}function Qn(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function th(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}function eh(t,e){return t.getAttribute(e)}function ih(t,e){return function(t,{width:e,height:i,gradientUnits:s}){let r;return Object.entries(t).reduce(((t,[n,h])=>{if("Infinity"===h)r=1;else if("-Infinity"===h)r=0;else{let t="string"==typeof h;r=t?parseFloat(h):h,t&&Vn(h)&&(r*=.01,"pixels"===s&&("x1"!==n&&"x2"!==n&&"r2"!==n||(r*=e),"y1"!==n&&"y2"!==n||(r*=i)))}return t[n]=r,t}),{})}("linear"===Qn(t)?function(t){return{x1:eh(t,"x1")||0,y1:eh(t,"y1")||0,x2:eh(t,"x2")||"100%",y2:eh(t,"y2")||0}}(t):function(t){return{x1:eh(t,"fx")||eh(t,"cx")||"50%",y1:eh(t,"fy")||eh(t,"cy")||"50%",r1:0,x2:eh(t,"cx")||"50%",y2:eh(t,"cy")||"50%",r2:eh(t,"r")||"50%"}}(t),{...e,gradientUnits:th(t)})}var sh=class{constructor(t){let{type:e="linear",gradientUnits:i="pixels",coords:s={},colorStops:r=[],offsetX:n=0,offsetY:h=0,gradientTransform:o,id:a}=t||{};Object.assign(this,{type:e,gradientUnits:i,coords:{..."radial"===e?Hn:Nn,...s},colorStops:r,offsetX:n,offsetY:h,gradientTransform:o,id:a?`${a}_${ke()}`:ke()})}addColorStop(t){for(let e in t)this.colorStops.push({offset:parseFloat(e),color:t[e]});return this}toObject(t){return{...Ze(this,t),type:this.type,coords:{...this.coords},colorStops:this.colorStops.map((t=>({...t}))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0}}toSVG(t,{additionalTransform:e}={}){let i=[],s=this.gradientTransform?this.gradientTransform.concat():zt.concat(),r="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",n=this.colorStops.map((t=>({...t}))).sort(((t,e)=>t.offset-e.offset)),h=-this.offsetX,o=-this.offsetY;var a;"objectBoundingBox"===r?(h/=t.width,o/=t.height):(h+=t.width/2,o+=t.height/2),(a=t)&&"function"==typeof a._renderPathCommands&&"percentage"!==this.gradientUnits&&(h-=t.pathOffset.x,o-=t.pathOffset.y),s[4]-=h,s[5]-=o;let l=[`id="SVGID_${gi(String(this.id))}"`,`gradientUnits="${r}"`,`gradientTransform="${e?e+" ":""}${ei(s)}"`,""].join(" "),u=t=>parseFloat(String(t));if("linear"===this.type){let{x1:t,y1:e,x2:s,y2:r}=this.coords,n=u(t),h=u(e),o=u(s),a=u(r);i.push("<linearGradient ",l,' x1="',n,'" y1="',h,'" x2="',o,'" y2="',a,'">\n')}else if("radial"===this.type){let{x1:t,y1:e,x2:s,y2:r,r1:h,r2:o}=this.coords,a=u(t),c=u(e),f=u(s),d=u(r),g=u(h),p=u(o),m=g>p;i.push("<radialGradient ",l,' cx="',m?a:f,'" cy="',m?c:d,'" r="',m?g:p,'" fx="',m?f:a,'" fy="',m?d:c,'">\n'),m&&(n.reverse(),n.forEach((t=>{t.offset=1-t.offset})));let v=Math.min(g,p);if(v>0){let t=v/Math.max(g,p);n.forEach((e=>{e.offset+=t*(1-e.offset)}))}}return n.forEach((({color:t,offset:e})=>{let s=String(t),r=Ji(s)?s:new os(s).toRgba();i.push(`<stop offset="${100*e}%" style="stop-color:${gi(r)};"/>\n`)})),i.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),i.join("")}toLive(t){let{x1:e,y1:i,x2:s,y2:r,r1:n,r2:h}=this.coords,o="linear"===this.type?t.createLinearGradient(e,i,s,r):t.createRadialGradient(e,i,n,s,r,h);return this.colorStops.forEach((({color:t,offset:e})=>{o.addColorStop(e,t)})),o}static async fromObject(t){let{colorStops:e,gradientTransform:i}=t;return new this({...t,colorStops:e?e.map((t=>({...t}))):void 0,gradientTransform:i?[...i]:void 0})}static fromElement(t,e,i){let s=th(t),r=e._findCenterFromElement();return new this({id:t.getAttribute("id")||void 0,type:Qn(t),coords:ih(t,{width:i.viewBoxWidth||i.width,height:i.viewBoxHeight||i.height}),colorStops:Zn(t,i.opacity),gradientUnits:s,gradientTransform:Vr(t.getAttribute("gradientTransform")||""),..."pixels"===s?{offsetX:e.width/2-r.x,offsetY:e.height/2-r.y}:{offsetX:0,offsetY:0}})}};Ct(sh,"type","Gradient"),ge.setClass(sh,"gradient"),ge.setClass(sh,"linear"),ge.setClass(sh,"radial");var rh=class{get type(){return"pattern"}set type(t){Mt("warn","Setting type has no effect",t)}constructor(t){Ct(this,"repeat","repeat"),Ct(this,"offsetX",0),Ct(this,"offsetY",0),Ct(this,"crossOrigin",""),this.id=ke(),Object.assign(this,t)}isImageSource(){return!!this.source&&"string"==typeof this.source.src}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&0!==this.source.naturalWidth&&0!==this.source.naturalHeight)?t.createPattern(this.source,this.repeat):null}toObject(t=[]){let{repeat:e,crossOrigin:i}=this;return{...Ze(this,t),type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:i,offsetX:ti(this.offsetX,_t.NUM_FRACTION_DIGITS),offsetY:ti(this.offsetY,_t.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null}}toSVG({width:t,height:e}){let{source:i,repeat:s,id:r}=this,n=Gn(this.offsetX/t,0),h=Gn(this.offsetY/e,0),o="repeat-y"===s||"no-repeat"===s?1+Math.abs(n||0):Gn(i.width/t,0),a="repeat-x"===s||"no-repeat"===s?1+Math.abs(h||0):Gn(i.height/e,0);return[`<pattern id="SVGID_${gi(r)}" x="${n}" y="${h}" width="${o}" height="${a}">`,`<image x="0" y="0" width="${i.width}" height="${i.height}" xlink:href="${gi(this.sourceToString())}"></image>`,"</pattern>",""].join("\n")}static async fromObject({type:t,source:e,patternTransform:i,...s},r){let n=await qe(e,{...r,crossOrigin:s.crossOrigin});return new this({...s,patternTransform:i&&i.slice(0),source:n})}};Ct(rh,"type","Pattern"),ge.setClass(rh),ge.setClass(rh,"pattern");var nh=class t extends xr{constructor(e,{path:i,left:s,top:r,...n}={}){super(),Object.assign(this,t.ownDefaults),this.setOptions(n),this._setPath(e||[],!0),"number"==typeof s&&this.set("left",s),"number"==typeof r&&this.set("top",r)}_setPath(t,e){this.path=(t=>{let e,i=0,s=0,r=0,n=0,h=[],o=0,a=0;for(let l of t){let t,u=[...l];switch(u[0]){case"l":u[1]+=i,u[2]+=s;case"L":i=u[1],s=u[2],t=["L",i,s];break;case"h":u[1]+=i;case"H":i=u[1],t=["L",i,s];break;case"v":u[1]+=s;case"V":s=u[1],t=["L",i,s];break;case"m":u[1]+=i,u[2]+=s;case"M":i=u[1],s=u[2],r=u[1],n=u[2],t=["M",i,s];break;case"c":u[1]+=i,u[2]+=s,u[3]+=i,u[4]+=s,u[5]+=i,u[6]+=s;case"C":o=u[3],a=u[4],i=u[5],s=u[6],t=["C",u[1],u[2],o,a,i,s];break;case"s":u[1]+=i,u[2]+=s,u[3]+=i,u[4]+=s;case"S":"C"===e?(o=2*i-o,a=2*s-a):(o=i,a=s),i=u[3],s=u[4],t=["C",o,a,u[1],u[2],i,s],o=t[3],a=t[4];break;case"q":u[1]+=i,u[2]+=s,u[3]+=i,u[4]+=s;case"Q":o=u[1],a=u[2],i=u[3],s=u[4],t=["Q",o,a,i,s];break;case"t":u[1]+=i,u[2]+=s;case"T":"Q"===e?(o=2*i-o,a=2*s-a):(o=i,a=s),i=u[1],s=u[2],t=["Q",o,a,i,s];break;case"a":u[6]+=i,u[7]+=s;case"A":vn(i,s,u).forEach((t=>h.push(t))),i=u[6],s=u[7];break;case"z":case"Z":i=r,s=n,t=["Z"]}t?(h.push(t),e=t[0]):e=""}return h})(Array.isArray(t)?t:(t=>{var e;let i=[],s=null==(e=t.match(Fn))?[]:e;for(let t of s){let e=t[0];if("z"===e||"Z"===e){i.push([e]);continue}let s=$n[e.toLowerCase()],r=[];if("a"===e||"A"===e){let e;for(On.lastIndex=0;e=On.exec(t);)r.push(...e.slice(1))}else r=t.match(Dn)||[];for(let t=0;t<r.length;t+=s){let n=Array(s),h=dn[e];n[0]=t>0&&h?h:e;for(let e=0;e<s;e++)n[e+1]=parseFloat(r[t+e]);i.push(n)}}return i})(t)),this.setBoundingBox(e)}_findCenterFromElement(){let t=this._calcBoundsFromPath();return new be(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){let e=-this.pathOffset.x,i=-this.pathOffset.y;t.beginPath();for(let s of this.path)switch(s[0]){case"L":t.lineTo(s[1]+e,s[2]+i);break;case"M":t.moveTo(s[1]+e,s[2]+i);break;case"C":t.bezierCurveTo(s[1]+e,s[2]+i,s[3]+e,s[4]+i,s[5]+e,s[6]+i);break;case"Q":t.quadraticCurveTo(s[1]+e,s[2]+i,s[3]+e,s[4]+i);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return`#<Path (${this.complexity()}): { "top": ${this.top}, "left": ${this.left} }>`}toObject(t=[]){return{...super.toObject(t),path:this.path.map((t=>t.slice()))}}toDatalessObject(t=[]){let e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){return["<path ","COMMON_PARTS",`d="${jn(this.path,_t.NUM_FRACTION_DIGITS)}" stroke-linecap="round" />\n`]}_getOffsetTransform(){let t=_t.NUM_FRACTION_DIGITS;return` translate(${ti(-this.pathOffset.x,t)}, ${ti(-this.pathOffset.y,t)})`}toClipPathSVG(t){let e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){let e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){let{width:e,height:i,pathOffset:s}=this._calcDimensions();this.set({width:e,height:i,pathOffset:s}),t&&this.setPositionByOrigin(s,"center","center")}_calcBoundsFromPath(){let t=[],e=0,i=0,s=0,r=0;for(let n of this.path)switch(n[0]){case"L":s=n[1],r=n[2],t.push({x:e,y:i},{x:s,y:r});break;case"M":s=n[1],r=n[2],e=s,i=r;break;case"C":t.push(...mn(s,r,n[1],n[2],n[3],n[4],n[5],n[6])),s=n[5],r=n[6];break;case"Q":t.push(...mn(s,r,n[1],n[2],n[1],n[2],n[3],n[4])),s=n[3],r=n[4];break;case"Z":s=e,r=i}return Si(t)}_calcDimensions(){let t=this._calcBoundsFromPath();return{...t,pathOffset:new be(t.left+t.width/2,t.top+t.height/2)}}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,i){let{d:s,...r}=Jr(t,this.ATTRIBUTE_NAMES,i);return new this(s,{...r,...e,left:void 0,top:void 0})}};Ct(nh,"type","Path"),Ct(nh,"cacheProperties",[...js,"path","fillRule"]),Ct(nh,"ATTRIBUTE_NAMES",[...Dr,"d"]),ge.setClass(nh),ge.setSVGClass(nh);const hh=["radius","startAngle","endAngle","counterClockwise"];var oh=class t extends xr{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e){super(),Object.assign(this,t.ownDefaults),this.setOptions(e)}_set(t,e){return super._set(t,e),"radius"===t&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,je(this.startAngle),je(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(ne)}getRadiusY(){return this.get("radius")*this.get(he)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(t=[]){return super.toObject([...hh,...t])}_toSVG(){let{radius:t,startAngle:e,endAngle:i}=this,s=(i-e)%360;if(0===s)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',`${gi(t)}`,'" />\n'];{let r=je(e),n=je(i),h=ye(r)*t,o=we(r)*t,a=ye(n)*t,l=we(n)*t;return[`<path d="M ${h} ${o} A ${t} ${t} 0 ${+(s>180)} ${+!this.counterClockwise} ${a} ${l}" `,"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,i){let{left:s=0,top:r=0,radius:n=0,...h}=Jr(t,this.ATTRIBUTE_NAMES,i);return new this({...h,radius:n,left:s-n,top:r-n})}static fromObject(t){return super._fromObject(t)}};Ct(oh,"type","Circle"),Ct(oh,"cacheProperties",[...js,...hh]),Ct(oh,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),Ct(oh,"ATTRIBUTE_NAMES",["cx","cy","r",...Dr]),ge.setClass(oh),ge.setSVGClass(oh);const ah=["x1","x2","y1","y2"];var lh=class t extends xr{constructor([e,i,s,r]=[0,0,0,0],n={}){super(),Object.assign(this,t.ownDefaults),this.setOptions(n),this.x1=e,this.x2=s,this.y1=i,this.y2=r,this._setWidthHeight();let{left:h,top:o}=n;"number"==typeof h&&this.set("left",h),"number"==typeof o&&this.set("top",o)}_setWidthHeight(){let{x1:t,y1:e,x2:i,y2:s}=this;this.width=Math.abs(i-t),this.height=Math.abs(s-e);let{left:r,top:n,width:h,height:o}=Si([{x:t,y:e},{x:i,y:s}]),a=new be(r+h/2,n+o/2);this.setPositionByOrigin(a,Nt,Nt)}_set(t,e){return super._set(t,e),ah.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();let e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;let i=t.strokeStyle;var s;t.strokeStyle=ii(this.stroke)?this.stroke.toLive(t):null==(s=this.stroke)?t.fillStyle:s,this.stroke&&this._renderStroke(t),t.strokeStyle=i}_findCenterFromElement(){return new be((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(t=[]){return{...super.toObject(t),...this.calcLinePoints()}}_getNonTransformedDimensions(){let t=super._getNonTransformedDimensions();return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t}calcLinePoints(){let{x1:t,x2:e,y1:i,y2:s,width:r,height:n}=this,h=t<=e?-.5:.5,o=i<=s?-.5:.5;return{x1:h*r,x2:h*-r,y1:o*n,y2:o*-n}}_toSVG(){let{x1:t,x2:e,y1:i,y2:s}=this.calcLinePoints();return["<line ","COMMON_PARTS",`x1="${t}" y1="${i}" x2="${e}" y2="${s}" />\n`]}static async fromElement(t,e,i){let{x1:s=0,y1:r=0,x2:n=0,y2:h=0,...o}=Jr(t,this.ATTRIBUTE_NAMES,i);return new this([s,r,n,h],o)}static fromObject({x1:t,y1:e,x2:i,y2:s,...r}){return this._fromObject({...r,points:[t,e,i,s]},{extraParam:"points"})}};Ct(lh,"type","Line"),Ct(lh,"cacheProperties",[...js,...ah]),Ct(lh,"ATTRIBUTE_NAMES",Dr.concat(ah)),ge.setClass(lh),ge.setSVGClass(lh);var uh=class t extends xr{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e){super(),Object.assign(this,t.ownDefaults),this.setOptions(e)}_render(t){let e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,i),t.lineTo(0,-i),t.lineTo(e,i),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){let t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',`${-t} ${e},0 ${-e},${t} ${e}`,'" />']}};Ct(uh,"type","Triangle"),Ct(uh,"ownDefaults",{width:100,height:100}),ge.setClass(uh),ge.setSVGClass(uh);const ch=["rx","ry"];var fh=class t extends xr{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e){super(),Object.assign(this,t.ownDefaults),this.setOptions(e)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(ne)}getRy(){return this.get("ry")*this.get(he)}toObject(t=[]){return super.toObject([...ch,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",`cx="0" cy="0" rx="${gi(this.rx)}" ry="${gi(this.ry)}" />\n`]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Xt,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,i){let s=Jr(t,this.ATTRIBUTE_NAMES,i);return s.left=(s.left||0)-s.rx,s.top=(s.top||0)-s.ry,new this(s)}};Ct(fh,"type","Ellipse"),Ct(fh,"cacheProperties",[...js,...ch]),Ct(fh,"ownDefaults",{rx:0,ry:0}),Ct(fh,"ATTRIBUTE_NAMES",[...Dr,"cx","cy","rx","ry"]),ge.setClass(fh),ge.setSVGClass(fh);const dh={exactBoundingBox:!1};var gh=class t extends xr{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e=[],i={}){super(),Ct(this,"strokeDiff",void 0),Object.assign(this,t.ownDefaults),this.setOptions(i),this.points=e;let{left:s,top:r}=i;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof s&&this.set("left",s),"number"==typeof r&&this.set("top",r)}isOpen(){return!0}_projectStrokeOnPoints(t){return((t,e,i=!1)=>{let s=[];if(0===t.length)return s;let r=t.reduce(((t,e)=>(t[t.length-1].eq(e)||t.push(new be(e)),t)),[new be(t[0])]);if(1===r.length)i=!0;else if(!i){let t=r[0],e=((t,e)=>{for(let i=t.length-1;i>=0;i--)if(e(t[i]))return i;return-1})(r,(e=>!e.eq(t)));r.splice(e+1)}return r.forEach(((t,r,n)=>{let h,o;0===r?(o=n[1],h=i?t:n[n.length-1]):r===n.length-1?(h=n[r-1],o=i?t:n[0]):(h=n[r-1],o=n[r+1]),i&&1===n.length?s.push(...new Mr(t,t,e).project()):!i||0!==r&&r!==n.length-1?s.push(...new _r(t,h,o,e).project()):s.push(...new Mr(t,0===r?o:h,e).project())})),s})(this.points,t,this.isOpen())}_calcDimensions(t){t={scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth,...t||{}};let e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map((t=>t.projectedPoint)):this.points;if(0===e.length)return{left:0,top:0,width:0,height:0,pathOffset:new be,strokeOffset:new be,strokeDiff:new be};let i=Si(e),s=Ue({...t,scaleX:1,scaleY:1}),r=Si(this.points.map((t=>Ee(t,s,!0)))),n=new be(this.scaleX,this.scaleY),h=i.left+i.width/2,o=i.top+i.height/2;return this.exactBoundingBox&&(h-=o*Math.tan(je(this.skewX)),o-=h*Math.tan(je(this.skewY))),{...i,pathOffset:new be(h,o),strokeOffset:new be(r.left,r.top).subtract(new be(i.left,i.top)).multiply(n),strokeDiff:new be(i.width,i.height).subtract(new be(r.width,r.height)).multiply(n)}}_findCenterFromElement(){let t=Si(this.points);return new be(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){let{left:e,top:i,width:s,height:r,pathOffset:n,strokeOffset:h,strokeDiff:o}=this._calcDimensions();this.set({width:s,height:r,pathOffset:n,strokeOffset:h,strokeDiff:o}),t&&this.setPositionByOrigin(new be(e+s/2,i+r/2),"center","center")}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new be(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(t={}){if(this.exactBoundingBox){let n;if(Object.keys(t).some((t=>this.strokeUniform||this.constructor.layoutProperties.includes(t)))){var e,i;let{width:s,height:r}=this._calcDimensions(t);n=new be(null==(e=t.width)?s:e,null==(i=t.height)?r:i)}else{var s,r;n=new be(null==(s=t.width)?this.width:s,null==(r=t.height)?this.height:r)}return n.multiply(new be(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){let i=this.initialized&&this[t]!==e,s=super._set(t,e);return this.exactBoundingBox&&i&&(("scaleX"===t||"scaleY"===t)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),s}toObject(t=[]){return{...super.toObject(t),points:this.points.map((({x:t,y:e})=>({x:t,y:e})))}}_toSVG(){let t=this.pathOffset.x,e=this.pathOffset.y,i=_t.NUM_FRACTION_DIGITS,s=this.points.map((({x:s,y:r})=>`${ti(s-t,i)},${ti(r-e,i)}`)).join(" ");return[`<${gi(this.constructor.type).toLowerCase()} `,"COMMON_PARTS",`points="${s}" />\n`]}_render(t){let e=this.points.length,i=this.pathOffset.x,s=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-i,this.points[0].y-s);for(let r=0;r<e;r++){let e=this.points[r];t.lineTo(e.x-i,e.y-s)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,i){let s=function(t){if(!t)return[];let e=t.replace(/,/g," ").trim().split(/\s+/),i=[];for(let t=0;t<e.length;t+=2)i.push({x:parseFloat(e[t]),y:parseFloat(e[t+1])});return i}(t.getAttribute("points")),{left:r,top:n,...h}=Jr(t,this.ATTRIBUTE_NAMES,i);return new this(s,{...h,...e})}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}};Ct(gh,"ownDefaults",dh),Ct(gh,"type","Polyline"),Ct(gh,"layoutProperties",[oe,ae,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),Ct(gh,"cacheProperties",[...js,"points"]),Ct(gh,"ATTRIBUTE_NAMES",[...Dr]),ge.setClass(gh),ge.setSVGClass(gh);var ph=class extends gh{isOpen(){return!1}};Ct(ph,"ownDefaults",dh),Ct(ph,"type","Polygon"),ge.setClass(ph),ge.setSVGClass(ph);var mh=class extends xr{isEmptyStyles(t){if(!this.styles||void 0!==t&&!this.styles[t])return!0;let e=void 0===t?this.styles:{line:this.styles[t]};for(let t in e)for(let i in e[t])for(let s in e[t][i])return!1;return!0}styleHas(t,e){if(!this.styles||void 0!==e&&!this.styles[e])return!1;let i=void 0===e?this.styles:{0:this.styles[e]};for(let e in i)for(let s in i[e])if(void 0!==i[e][s][t])return!0;return!1}cleanStyle(t){if(!this.styles)return!1;let e,i,s=this.styles,r=0,n=!0,h=0;for(let h in s){e=0;for(let o in s[h]){let a=s[h][o]||{};r++,void 0===a[t]?n=!1:(i?a[t]!==i&&(n=!1):i=a[t],a[t]===this[t]&&delete a[t]),0===Object.keys(a).length?delete s[h][o]:e++}0===e&&delete s[h]}for(let t=0;t<this._textLines.length;t++)h+=this._textLines[t].length;n&&r===h&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;let e,i,s,r=this.styles;for(i in r){for(s in e=r[i],e)delete e[s][t],0===Object.keys(e[s]).length&&delete e[s];0===Object.keys(e).length&&delete r[i]}}_extendStyles(t,e){let{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);this._getLineStyle(i)||this._setLineStyle(i);let r=Qe({...this._getStyleDeclaration(i,s),...e},(t=>void 0!==t));this._setStyleDeclaration(i,s,r)}getSelectionStyles(t,e,i){let s=[];for(let r=t;r<(e||t);r++)s.push(this.getStyleAtPosition(r,i));return s}getStyleAtPosition(t,e){let{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(i,s):this._getStyleDeclaration(i,s)}setSelectionStyles(t,e,i){for(let s=e;s<(i||e);s++)this._extendStyles(s,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var i;let s=this.styles&&this.styles[t];return s&&null!=(i=s[e])?i:{}}getCompleteStyleDeclaration(t,e){return{...Ze(this,this.constructor._styleProperties),...this._getStyleDeclaration(t,e)}}_setStyleDeclaration(t,e,i){this.styles[t][e]=i}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}};Ct(mh,"_styleProperties",ys);const vh=/ +/g,yh=/"/g;function wh(t,e,i,s,r){return`\t\t${((t,{left:e,top:i,width:s,height:r},n=_t.NUM_FRACTION_DIGITS)=>{let h=ls(le,t,!1),[o,a,l,u]=[e,i,s,r].map((t=>ti(t,n)));return`<rect ${h} x="${o}" y="${a}" width="${l}" height="${u}"></rect>`})(t,{left:e,top:i,width:s,height:r})}\n`}let bh;var xh=class t extends mh{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e,i){super(),Ct(this,"__charBounds",[]),Object.assign(this,t.ownDefaults),this.setOptions(i),this.styles||(this.styles={}),this.text=e,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){let t=this.path;t&&(t.segmentsInfo=kn(t.path))}_splitText(){let t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes("justify")&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,r,n,h;for(let o=0,a=this._textLines.length;o<a;o++)if(("justify"===this.textAlign||o!==a-1&&!this.isEndOfWrapping(o))&&(s=0,r=this._textLines[o],e=this.getLineWidth(o),e<this.width&&(h=this.textLines[o].match(this._reSpacesAndTabs)))){i=h.length,t=(this.width-e)/i;for(let e=0;e<=r.length;e++)n=this.__charBounds[o][e],this._reSpaceAndTab.test(r[e])?(n.width+=t,n.kernedWidth+=t,n.left+=s,s+=t):n.left+=s}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){let i,s=e?this._unwrappedTextLines:this._textLines;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return`#<Text (${this.complexity()}): { "text": "${this.text}", "fontFamily": "${this.fontFamily}" }>`}_getCacheCanvasDimensions(){let t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){let e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,i){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case Nt:t.textBaseline="middle";break;case"ascender":t.textBaseline="top";break;case"descender":t.textBaseline=Gt}t.font=this._getFontDeclaration(e,i)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,i=this._textLines.length;e<i;e++){let i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,i,s,r,n){this._renderChars(t,e,i,s,r,n)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;let e=t.fillStyle,i=this._getLeftOffset(),s=this._getTopOffset();for(let e=0,r=this._textLines.length;e<r;e++){let r=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){s+=r;continue}let n,h,o=this._textLines[e].length,a=this._getLineLeftOffset(e),l=0,u=0,c=this.getValueOfPropertyAt(e,0,"textBackgroundColor"),f=this.getHeightOfLineImpl(e);for(let r=0;r<o;r++){let o=this.__charBounds[e][r];h=this.getValueOfPropertyAt(e,r,"textBackgroundColor"),this.path?(t.save(),t.translate(o.renderLeft,o.renderTop),t.rotate(o.angle),t.fillStyle=h,h&&t.fillRect(-o.width/2,-f*(1-this._fontSizeFraction),o.width,f),t.restore()):h===c?l+=o.kernedWidth:(n=i+a+u,"rtl"===this.direction&&(n=this.width-n-l),t.fillStyle=c,c&&t.fillRect(n,s,l,f),u=o.left,l=o.width,c=h)}h&&!this.path&&(n=i+a+u,"rtl"===this.direction&&(n=this.width-n-l),t.fillStyle=h,t.fillRect(n,s,l,f)),s+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,s){let r,n,h,o,a=Lt.getFontCache(e),l=this._getFontDeclaration(e),u=i?i+t:t,c=i&&l===this._getFontDeclaration(s),f=e.fontSize/this.CACHE_FONT_SIZE;if(i&&a.has(i)&&(h=a.get(i)),a.has(t)&&(o=r=a.get(t)),c&&a.has(u)&&(n=a.get(u),o=n-h),void 0===r||void 0===h||void 0===n){let s=(bh||(bh=Oe({width:0,height:0}).getContext("2d")),bh);this._setTextStyles(s,e,!0),void 0===r&&(o=r=s.measureText(t).width,a.set(t,r)),void 0===h&&c&&i&&(h=s.measureText(i).width,a.set(i,h)),c&&void 0===n&&(n=s.measureText(u).width,a.set(u,n),o=n-h)}return{width:r*f,kernedWidth:o*f}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){let e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,i,s=0,r=this.pathSide===Vt,n=this.path,h=this._textLines[t],o=h.length,a=Array(o);this.__charBounds[t]=a;for(let r=0;r<o;r++){let n=h[r];i=this._getGraphemeBox(n,t,r,e),a[r]=i,s+=i.kernedWidth,e=n}if(a[o]={left:i?i.left+i.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},n&&n.segmentsInfo){let t=0,e=n.segmentsInfo[n.segmentsInfo.length-1].length;switch(this.textAlign){case Ht:t=r?e-s:0;break;case Nt:t=(e-s)/2;break;case Vt:t=r?0:e-s}t+=this.pathStartOffset*(r?-1:1);for(let s=r?o-1:0;r?s>=0:s<o;r?s--:s++)i=a[s],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,i),t+=i.kernedWidth}return{width:s,numOfSpaces:0}}_setGraphemeOnPath(t,e){let i=this.path,s=((t,e,i=kn(t))=>{let s=0;for(;e-i[s].length>0&&s<i.length-2;)e-=i[s].length,s++;let r=i[s],n=e/r.length,h=t[s];switch(r.command){case"M":return{x:r.x,y:r.y,angle:0};case"Z":return{...new be(r.x,r.y).lerp(new be(r.destX,r.destY),n),angle:Math.atan2(r.destY-r.y,r.destX-r.x)};case"L":return{...new be(r.x,r.y).lerp(new be(h[1],h[2]),n),angle:Math.atan2(h[2]-r.y,h[1]-r.x)};case"C":case"Q":return((t,e)=>{let i,s=0,r=0,n={x:t.x,y:t.y},h={...n},o=.01,a=0,l=t.iterator,u=t.angleFinder;for(;r<e&&o>1e-4;)h=l(s),a=s,i=yn(n.x,n.y,h.x,h.y),i+r>e?(s-=o,o/=2):(n=h,s+=o,r+=i);return{...h,angle:u(a)}})(r,e)}})(i.path,t+e.kernedWidth/2,i.segmentsInfo);e.renderLeft=s.x-i.pathOffset.x,e.renderTop=s.y-i.pathOffset.y,e.angle=s.angle+("right"===this.pathSide?Math.PI:0)}_getGraphemeBox(t,e,i,s,r){let n,h=this.getCompleteStyleDeclaration(e,i),o=s?this.getCompleteStyleDeclaration(e,i-1):{},a=this._measureChar(t,h,s,o),l=a.kernedWidth,u=a.width;0!==this.charSpacing&&(n=this._getWidthOfCharSpacing(),u+=n,l+=n);let c={width:u,left:0,height:h.fontSize,kernedWidth:l,deltaY:h.deltaY};if(i>0&&!r){let t=this.__charBounds[e][i-1];c.left=t.left+t.width+a.kernedWidth-a.width}return c}getHeightOfLineImpl(t){let e=this.__lineHeights;if(e[t])return e[t];let i=this.getHeightOfChar(t,0);for(let e=1,s=this._textLines[t].length;e<s;e++)i=Math.max(this.getHeightOfChar(t,e),i);return e[t]=i*this._fontSizeMult}getHeightOfLine(t){return this.getHeightOfLineImpl(t)*this.lineHeight}calcTextHeight(){let t=0;for(let e=0,i=this._textLines.length;e<i;e++)t+=e===i-1?this.getHeightOfLineImpl(e):this.getHeightOfLine(e);return t}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let i=0,s=this._getLeftOffset(),r=this._getTopOffset();for(let n=0,h=this._textLines.length;n<h;n++)this._renderTextLine(e,t,this._textLines[n],s+this._getLineLeftOffset(n),r+i+this.getHeightOfLineImpl(n),n),i+=this.getHeightOfLine(n);t.restore()}_renderTextFill(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,i,s,r,n){let h,o,a,l,u,c=this.textAlign.includes(bs),f=this.path,d=!c&&0===this.charSpacing&&this.isEmptyStyles(n)&&!f,g="ltr"===this.direction,p="ltr"===this.direction?1:-1,m=e.direction,v="",y=0;if(e.save(),m!==this.direction&&(e.canvas.setAttribute("dir",g?"ltr":"rtl"),e.direction=g?"ltr":"rtl",e.textAlign=g?Ht:Vt),r-=this.getHeightOfLineImpl(n)*this._fontSizeFraction,d)return this._renderChar(t,e,n,0,i.join(""),s,r),void e.restore();for(let d=0,g=i.length-1;d<=g;d++)l=d===g||this.charSpacing||f,v+=i[d],a=this.__charBounds[n][d],0===y?(s+=p*(a.kernedWidth-a.width),y+=a.width):y+=a.kernedWidth,c&&!l&&this._reSpaceAndTab.test(i[d])&&(l=!0),l||(h=h||this.getCompleteStyleDeclaration(n,d),o=this.getCompleteStyleDeclaration(n,d+1),l=kr(h,o,!1)),l&&(f?(e.save(),e.translate(a.renderLeft,a.renderTop),e.rotate(a.angle),this._renderChar(t,e,n,d,v,-y/2,0),e.restore()):(u=s,this._renderChar(t,e,n,d,v,u,r)),v="",h=o,s+=p*y,y=0);e.restore()}_applyPatternGradientTransformText(t){let e=this.width+this.strokeWidth,i=this.height+this.strokeWidth,s=Oe({width:e,height:i}),r=s.getContext("2d");return s.width=e,s.height=i,r.beginPath(),r.moveTo(0,0),r.lineTo(e,0),r.lineTo(e,i),r.lineTo(0,i),r.closePath(),r.translate(e/2,i/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(s,"no-repeat")}handleFiller(t,e,i){let s,r;return ii(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?(s=-this.width/2,r=-this.height/2,t.translate(s,r),t[e]=this._applyPatternGradientTransformText(i),{offsetX:s,offsetY:r}):(t[e]=i.toLive(t),this._applyPatternGradientTransform(t,i)):(t[e]=i,{offsetX:0,offsetY:0})}_setStrokeStyles(t,{stroke:e,strokeWidth:i}){return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",e)}_setFillStyles(t,{fill:e}){return this.handleFiller(t,"fillStyle",e)}_renderChar(t,e,i,s,r,n,h){let o=this._getStyleDeclaration(i,s),a=this.getCompleteStyleDeclaration(i,s),l="fillText"===t&&a.fill,u="strokeText"===t&&a.stroke&&a.strokeWidth;if(u||l){if(e.save(),e.font=this._getFontDeclaration(a),o.textBackgroundColor&&this._removeShadow(e),o.deltaY&&(h+=o.deltaY),l){let t=this._setFillStyles(e,a);e.fillText(r,n-t.offsetX,h-t.offsetY)}if(u){let t=this._setStrokeStyles(e,a);e.strokeText(r,n-t.offsetX,h-t.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,i){let s=this.get2DCursorLocation(t,!0),r=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"fontSize"),n=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"deltaY");this.setSelectionStyles({fontSize:r*i.size,deltaY:n+r*i.baseline},t,e)}_getLineLeftOffset(t){let e=this.getLineWidth(t),i=this.width-e,s=this.textAlign,r=this.direction,n=this.isEndOfWrapping(t),h=0;return"justify"===s||"justify-center"===s&&!n||"justify-right"===s&&!n||"justify-left"===s&&!n?0:("center"===s&&(h=i/2),"right"===s&&(h=i),"justify-center"===s&&(h=i/2),"justify-right"===s&&(h=i),"rtl"===r&&("right"===s||"justify-right"===s?h=0:"left"===s||"justify-left"===s?h=-i:"center"!==s&&"justify-center"!==s||(h=-i/2)),h)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];let{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0===this.charSpacing?0:this.fontSize*this.charSpacing/1e3}getValueOfPropertyAt(t,e,i){var s;return null==(s=this._getStyleDeclaration(t,e)[i])?this[i]:s}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let i=this._getTopOffset(),s=this._getLeftOffset(),r=this.path,n=this._getWidthOfCharSpacing(),h="linethrough"===e?.5:+("overline"===e),o=this.offsets[e];for(let a=0,l=this._textLines.length;a<l;a++){let l=this.getHeightOfLine(a);if(!this[e]&&!this.styleHas(e,a)){i+=l;continue}let u,c=this._textLines[a],f=l/this.lineHeight,d=this._getLineLeftOffset(a),g=0,p=0,m=this.getValueOfPropertyAt(a,0,e),v=this.getValueOfPropertyAt(a,0,le),y=this.getValueOfPropertyAt(a,0,"textDecorationColor")||v,w=this.getValueOfPropertyAt(a,0,fs),b=m,x=y,C=w,S=i+f*(1-this._fontSizeFraction),_=this.getHeightOfChar(a,0),M=this.getValueOfPropertyAt(a,0,"deltaY");for(let i=0,n=c.length;i<n;i++){let n=this.__charBounds[a][i];b=this.getValueOfPropertyAt(a,i,e),u=this.getValueOfPropertyAt(a,i,le),x=this.getValueOfPropertyAt(a,i,"textDecorationColor")||u,C=this.getValueOfPropertyAt(a,i,fs);let l=this.getHeightOfChar(a,i),c=this.getValueOfPropertyAt(a,i,"deltaY");if(r&&b&&u){let e=this.fontSize*C/1e3;t.save(),t.fillStyle=x,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,o*l+c-h*e,n.kernedWidth,e),t.restore()}else if((b!==m||u!==v||x!==y||l!==_||C!==w||c!==M)&&p>0){let e=this.fontSize*w/1e3,i=s+d+g;"rtl"===this.direction&&(i=this.width-i-p),m&&y&&w&&(t.fillStyle=y,t.fillRect(i,S+o*_+M-h*e,p,e)),g=n.left,p=n.width,m=b,y=x,w=C,v=u,_=l,M=c}else p+=n.kernedWidth}let T=s+d+g;"rtl"===this.direction&&(T=this.width-T-p),t.fillStyle=x;let k=this.fontSize*C/1e3;b&&x&&C&&t.fillRect(T,S+o*_+M-h*k,p-n,k),i+=l}this._removeShadow(t)}_getFontDeclaration({fontFamily:e=this.fontFamily,fontStyle:i=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:r=this.fontSize}={},n){let h=e.includes("'")||e.includes('"')||e.includes(",")||t.genericFonts.includes(e.toLowerCase())?e:`"${e}"`;return[i,s,`${n?this.CACHE_FONT_SIZE:r}px`,h].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return mi(t)}_splitTextIntoLines(t){let e=t.split(this._reNewline),i=Array(e.length),s=["\n"],r=[];for(let t=0;t<e.length;t++)i[t]=this.graphemeSplit(e[t]),r=r.concat(i[t],s);return r.pop(),{_unwrappedLines:i,lines:e,graphemeText:r,graphemeLines:i}}toObject(t=[]){return{...super.toObject([...vs,...t]),styles:Fr(this.styles,this.text),...this.path?{path:this.path.toObject()}:{}}}set(t,e){let{textLayoutProperties:i}=this.constructor;super.set(t,e);let s=!1,r=!1;if("object"==typeof t)for(let e in t)"path"===e&&this.setPathInfo(),s=s||i.includes(e),r=r||"path"===e;else s=i.includes(t),r="path"===t;return r&&this.setPathInfo(),s&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(e,i,s){let r=Jr(e,t.ATTRIBUTE_NAMES,s),{textAnchor:n=Ht,textDecoration:h="",dx:o=0,dy:a=0,top:l=0,left:u=0,fontSize:c=16,strokeWidth:f=1,...d}={...i,...r},g=new this(ts(e.textContent||"").trim(),{left:u+o,top:l+a,underline:h.includes("underline"),overline:h.includes("overline"),linethrough:h.includes("line-through"),strokeWidth:0,fontSize:c,...d}),p=g.getScaledHeight()/g.height,m=((g.height+g.strokeWidth)*g.lineHeight-g.height)*p,v=g.getScaledHeight()+m,y=0;return"center"===n&&(y=g.getScaledWidth()/2),"right"===n&&(y=g.getScaledWidth()),g.set({left:g.left-y,top:g.top-(v-g.fontSize*(.07+g._fontSizeFraction))/g.lineHeight,strokeWidth:f}),g}static fromObject(t){return this._fromObject({...t,styles:Or(t.styles||{},t.text)},{extraParam:"text"})}};Ct(xh,"textLayoutProperties",ms),Ct(xh,"cacheProperties",[...js,...vs]),Ct(xh,"ownDefaults",ws),Ct(xh,"type","Text"),Ct(xh,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),Ct(xh,"ATTRIBUTE_NAMES",Dr.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-decoration-thickness","text-decoration-color","text-anchor")),br(xh,[class extends us{_toSVG(){let t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){let e=this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0}),i=this.path;return i?e+i._createBaseSVGMarkup(i._toSVG(),{reviver:t,withShadow:!0,additionalTransform:ei(this.calcOwnMatrix())}):e}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg({textBgRects:t,textSpans:e}){let i=this.getSvgTextDecoration(this);return[t.join(""),'\t\t<text xml:space="preserve" ',`font-family="${gi(this.fontFamily.replace(yh,"'"))}" `,`font-size="${gi(this.fontSize)}" `,this.fontStyle?`font-style="${gi(this.fontStyle)}" `:"",this.fontWeight?`font-weight="${gi(this.fontWeight)}" `:"",i?`text-decoration="${i}" `:"","rtl"===this.direction?'direction="rtl" ':"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),"</text>\n"]}_getSVGTextAndBg(t,e){let i,s=[],r=[],n=t;this.backgroundColor&&r.push(wh(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let t=0,h=this._textLines.length;t<h;t++)i=this._getLineLeftOffset(t),"rtl"===this.direction&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",t))&&this._setSVGTextLineBg(r,t,e+i,n),this._setSVGTextLineText(s,t,e+i,n),n+=this.getHeightOfLine(t);return{textSpans:s,textBgRects:r}}_createTextCharSpan(t,e,i,s,r){let n=_t.NUM_FRACTION_DIGITS,h=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(vh)),o=h?`style="${h}"`:"",a=e.deltaY,l=a?` dy="${ti(a,n)}" `:"",{angle:u,renderLeft:c,renderTop:f,width:d}=r,g="";if(void 0!==c){let t=d/2;u&&(g=` rotate="${ti(Ae(u),n)}"`);let e=ze({angle:Ae(u)});e[4]=c,e[5]=f;let r=new be(-t,0).transform(e);i=r.x,s=r.y}return`<tspan x="${ti(i,n)}" y="${ti(s,n)}" ${l}${g}${o}>${gi(t)}</tspan>`}_setSVGTextLineText(t,e,i,s){let r,n,h,o,a,l=this.getHeightOfLine(e),u=this.textAlign.includes(bs),c=this._textLines[e],f="",d=0;s+=l*(1-this._fontSizeFraction)/this.lineHeight;for(let l=0,g=c.length-1;l<=g;l++)a=l===g||this.charSpacing||this.path,f+=c[l],h=this.__charBounds[e][l],0===d?(i+=h.kernedWidth-h.width,d+=h.width):d+=h.kernedWidth,u&&!a&&this._reSpaceAndTab.test(c[l])&&(a=!0),a||(r=r||this.getCompleteStyleDeclaration(e,l),n=this.getCompleteStyleDeclaration(e,l+1),a=kr(r,n,!0)),a&&(o=this._getStyleDeclaration(e,l),t.push(this._createTextCharSpan(f,o,i,s,h)),f="",r=n,"rtl"===this.direction?i-=d:i+=d,d=0)}_setSVGTextLineBg(t,e,i,s){let r,n=this._textLines[e],h=this.getHeightOfLine(e)/this.lineHeight,o=0,a=0,l=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let u=0;u<n.length;u++){let{left:n,width:c,kernedWidth:f}=this.__charBounds[e][u];r=this.getValueOfPropertyAt(e,u,"textBackgroundColor"),r===l?o+=f:(l&&t.push(wh(l,i+a,s,o,h)),a=n,o=c,l=r)}r&&t.push(wh(l,i+a,s,o,h))}getSvgStyles(t){let e=Ji(this.textDecorationColor)?` text-decoration-color: ${gi(this[ds])};`:"";return`${super.getSvgStyles(t)} text-decoration-thickness: ${ti(this.textDecorationThickness*this.getObjectScaling().y/10,_t.NUM_FRACTION_DIGITS)}%;${e} white-space: pre;`}getSvgSpanStyles(t,e){let{fontFamily:i,strokeWidth:s,stroke:r,fill:n,fontSize:h,fontStyle:o,fontWeight:a,textDecorationThickness:l,textDecorationColor:u,linethrough:c,overline:f,underline:d}=t,g=this.getSvgTextDecoration({underline:null==d?this.underline:d,overline:null==f?this.overline:f,linethrough:null==c?this.linethrough:c}),p=l||this.textDecorationThickness,m=u||this.textDecorationColor,v=Zi(s),y=Qi(i),w=Zi(h),b=Qi(o),x=Zi(a)||Qi(a),C=Qi(m);return[r?ls(ue,r):"",v?`stroke-width: ${gi(v)}; `:"",y?`font-family: ${y.includes("'")||y.includes('"')?gi(y):`'${gi(y)}'`}; `:"",w?`font-size: ${gi(w)}px; `:"",b?`font-style: ${gi(b)}; `:"",x?`font-weight: ${gi(x)}; `:"",g?`text-decoration: ${g}; text-decoration-thickness: ${ti(p*this.getObjectScaling().y/10,_t.NUM_FRACTION_DIGITS)}%;${C?` text-decoration-color: ${gi(C)};`:""} `:"",n?ls(le,n):"",e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter((e=>t[e.replace("-","")])).join(" ")}}]),ge.setClass(xh),ge.setSVGClass(xh);var Ch=class{constructor(t){Ct(this,"target",void 0),Ct(this,"__mouseDownInPlace",!1),Ct(this,"__dragStartFired",!1),Ct(this,"__isDraggingOver",!1),Ct(this,"__dragStartSelection",void 0),Ct(this,"__dragImageDisposer",void 0),Ct(this,"_dispose",void 0),this.target=t;let e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach((t=>t())),this._dispose=void 0}}isPointerOverSelection(t){let e=this.target,i=e.getSelectionStartFromPointer(t);return e.isEditing&&i>=e.selectionStart&&i<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){let e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,{selectionStart:e,selectionEnd:i}){var s;let r=this.target,n=r.canvas,h=new be(r.flipX?-1:1,r.flipY?-1:1),o=r._getCursorBoundaries(e),a=new be(o.left+o.leftOffset,o.top+o.topOffset).multiply(h).transform(r.calcTransformMatrix()),l=n.getScenePoint(t).subtract(a),u=r.getCanvasRetinaScaling(),c=r.getBoundingRect(),f=a.subtract(new be(c.left,c.top)),d=n.viewportTransform,g=f.add(l).transform(d,!0),p=r.backgroundColor,m=Tr(r.styles);r.backgroundColor="";let v={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(v,0,e),r.setSelectionStyles(v,i,r.text.length),r.dirty=!0;let y=r.toCanvasElement({enableRetinaScaling:n.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=p,r.styles=m,r.dirty=!0,An(y,{position:"fixed",left:-y.width+"px",border:Ut,width:y.width/u+"px",height:y.height/u+"px"}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{y.remove()},oi(t.target||this.target.hiddenTextarea).body.appendChild(y),null==(s=t.dataTransfer)||s.setDragImage(y,g.x,g.y)}onDragStart(t){this.__dragStartFired=!0;let e=this.target,i=this.isActive();if(i&&t.dataTransfer){let i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},s=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r={text:e.text,value:s,...i};t.dataTransfer.setData("text/plain",s),t.dataTransfer.setData("application/fabric",JSON.stringify({value:s,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),i}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){let e=this.target.getSelectionStartFromPointer(t),i=this.__dragStartSelection;return e<i.selectionStart||e>i.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler({e:t}){let e=this.targetCanDrop(t);!this.__isDraggingOver&&e&&(this.__isDraggingOver=!0)}dragOverHandler(t){let{e}=t,i=this.targetCanDrop(e);!this.__isDraggingOver&&i?this.__isDraggingOver=!0:this.__isDraggingOver&&!i&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;let{e:i}=t,s=i.defaultPrevented;this.__isDraggingOver=!1,i.preventDefault();let r=null==(e=i.dataTransfer)?void 0:e.getData("text/plain");if(r&&!s){let e=this.target,s=e.canvas,n=e.getSelectionStartFromPointer(i),{styles:h}=i.dataTransfer.types.includes("application/fabric")?JSON.parse(i.dataTransfer.getData("application/fabric")):{},o=r[Math.max(0,r.length-1)];if(this.__dragStartSelection){let t=this.__dragStartSelection.selectionStart,i=this.__dragStartSelection.selectionEnd;n>t&&n<=i?n=t:n>i&&(n-=i-t),e.removeChars(t,i),delete this.__dragStartSelection}e._reNewline.test(o)&&(e._reNewline.test(e._text[n])||n===e._text.length)&&(r=r.trimEnd()),t.didDrop=!0,t.dropTarget=e,e.insertChars(r,h,n),s.setActiveObject(e),e.enterEditing(i),e.selectionStart=Math.min(n+0,e._text.length),e.selectionEnd=Math.min(e.selectionStart+r.length,e._text.length),e.hiddenTextarea.value=e.text,e._updateTextarea(),e.hiddenTextarea.focus(),e.fire(se,{index:n+0,action:"drop"}),s.fire("text:changed",{target:e}),s.contextTopDirty=!0,s.requestRenderAll()}}dragEndHandler({e:t}){if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var e;let i=this.target,s=this.target.canvas,{selectionStart:r,selectionEnd:n}=this.__dragStartSelection,h=(null==(e=t.dataTransfer)?void 0:e.dropEffect)||"none";"none"===h?(i.selectionStart=r,i.selectionEnd=n,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),"move"===h&&(i.removeChars(r,n),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(se,{index:r,action:"dragend"}),s.fire("text:changed",{target:i}),s.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}};const Sh=/[ \n\.,;!\?\-]/;var _h=class extends xh{constructor(...t){super(...t),Ct(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor({toValue:t,duration:e,delay:i,onComplete:s}){return Ws({startValue:this._currentCursorOpacity,endValue:t,duration:e,delay:i,onComplete:s,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:t=>{this._currentCursorOpacity=t,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;null==(t=this._currentTickCompleteState)||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,i=t-1;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i--;for(;/\S/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findWordBoundaryRight(t){let e=0,i=t;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i++;for(;/\S/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}findLineBoundaryLeft(t){let e=0,i=t-1;for(;!/\n/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findLineBoundaryRight(t){let e=0,i=t;for(;!/\n/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}searchWordBoundary(t,e){let i=this._text,s=t>0&&this._reSpace.test(i[t])&&(-1===e||!qt.test(i[t-1]))?t-1:t,r=i[s];for(;s>0&&s<i.length&&!Sh.test(r);)s+=e,r=i[s];return-1===e&&Sh.test(r)&&s++,s}selectWord(t){var e;t=null==(e=t)?this.selectionStart:e;let i=this.searchWordBoundary(t,-1),s=Math.max(i,this.searchWordBoundary(t,1));this.selectionStart=i,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=null==(e=t)?this.selectionStart:e;let i=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);this.selectionStart=i,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;let e=this.hiddenTextarea;oi(e).activeElement!==e&&e.focus();let i=this.getSelectionStartFromPointer(t),s=this.selectionStart,r=this.selectionEnd;(i===this.__selectionStartOnMouseDown&&s!==r||s!==i&&r!==i)&&(i>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=i):(this.selectionStart=i,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===s&&this.selectionEnd===r||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,i){let s=i.slice(0,t),r=this.graphemeSplit(s).length;if(t===e)return{selectionStart:r,selectionEnd:r};let n=i.slice(t,e);return{selectionStart:r,selectionEnd:r+this.graphemeSplit(n).length}}fromGraphemeToStringSelection(t,e,i){let s=i.slice(0,t).join("").length;return t===e?{selectionStart:s,selectionEnd:s}:{selectionStart:s,selectionEnd:s+i.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){let t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){let{hiddenTextarea:t,direction:e,textAlign:i,inCompositionMode:s}=this;if(!t)return;let r="justify"===i?"ltr"===e?Ht:Vt:i.replace("justify-",""),n=this.getPositionByOrigin(r,"top");this.cursorOffsetCache={},this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setPositionByOrigin(n,r,"top"),this.setCoords();let h=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=h.selectionEnd,s||(this.selectionStart=h.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){let t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};let t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),i=this.get2DCursorLocation(t),s=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize")*this.lineHeight,r=e.leftOffset,n=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,o=h.width/n,a=h.height/n,l=o-s,u=a-s,c=new be(e.left+r,e.top+e.topOffset+s).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new be(h.clientWidth/o,h.clientHeight/a));return c.x<0&&(c.x=0),c.x>l&&(c.x=l),c.y<0&&(c.y=0),c.y>u&&(c.y=u),c.x+=this.canvas._offset.left,c.y+=this.canvas._offset.top,{left:`${c.x}px`,top:`${c.y}px`,fontSize:`${s}px`,charHeight:s}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}exitEditingImpl(){let t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){let t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(let t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){let{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t,!0),{lineIndex:r,charIndex:n}=this.get2DCursorLocation(e,!0);if(i!==r){if(this.styles[i])for(let t=s;t<this._unwrappedTextLines[i].length;t++)delete this.styles[i][t];if(this.styles[r])for(let t=n;t<this._unwrappedTextLines[r].length;t++){let e=this.styles[r][t];e&&(this.styles[i]||(this.styles[i]={}),this.styles[i][s+t-n]=e)}for(let t=i+1;t<=r;t++)delete this.styles[t];this.shiftLineStyles(r,i-r)}else if(this.styles[i]){let t=this.styles[i],e=n-s;for(let e=s;e<n;e++)delete t[e];for(let s in this.styles[i]){let i=parseInt(s,10);i>=n&&(t[i-e]=t[s],delete t[s])}}}shiftLineStyles(t,e){let i=Object.assign({},this.styles);for(let s in this.styles){let r=parseInt(s,10);r>t&&(this.styles[r+e]=i[r],i[r-e]||delete this.styles[r])}}insertNewlineStyleObject(t,e,i,s){let r={},n=this._unwrappedTextLines[t].length,h=n===e,o=!1;i||(i=1),this.shiftLineStyles(t,i);let a=this.styles[t]?this.styles[t][0===e?e:e-1]:void 0;for(let i in this.styles[t]){let s=parseInt(i,10);s>=e&&(o=!0,r[s-e]=this.styles[t][i],h&&0===e||delete this.styles[t][i])}let l=!1;for(o&&!h&&(this.styles[t+i]=r,l=!0),(l||n>e)&&i--;i>0;)s&&s[i-1]?this.styles[t+i]={0:{...s[i-1]}}:a?this.styles[t+i]={0:{...a}}:delete this.styles[t+i],i--;this._forceClearCache=!0}insertCharStyleObject(t,e,i,s){this.styles||(this.styles={});let r=this.styles[t],n=r?{...r}:{};i||(i=1);for(let t in n){let s=parseInt(t,10);s>=e&&(r[s+i]=n[s],n[s-i]||delete r[s])}if(this._forceClearCache=!0,s){for(;i--;)Object.keys(s[i]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+i]={...s[i]});return}if(!r)return;let h=r[e?e-1:1];for(;h&&i--;)this.styles[t][e+i]={...h}}insertNewStyleBlock(t,e,i){let s,r=this.get2DCursorLocation(e,!0),n=[0],h=0;for(let e=0;e<t.length;e++)"\n"===t[e]?(h++,n[h]=0):n[h]++;for(n[0]>0&&(this.insertCharStyleObject(r.lineIndex,r.charIndex,n[0],i),i=i&&i.slice(n[0]+1)),h&&this.insertNewlineStyleObject(r.lineIndex,r.charIndex+n[0],h),s=1;s<h;s++)n[s]>0?this.insertCharStyleObject(r.lineIndex+s,0,n[s],i):i&&this.styles[r.lineIndex+s]&&i[0]&&(this.styles[r.lineIndex+s][0]=i[0]),i=i&&i.slice(n[s]+1);n[s]>0&&this.insertCharStyleObject(r.lineIndex+s,0,n[s],i)}removeChars(t,e=t+1){this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,i,s=i){s>i&&this.removeStyleFromTo(i,s);let r=this.graphemeSplit(t);this.insertNewStyleBlock(r,i,e),this._text=[...this._text.slice(0,i),...r,...this._text.slice(s)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,i){i<=t?(e===t?this._selectionDirection=Ht:"right"===this._selectionDirection&&(this._selectionDirection=Ht,this.selectionEnd=t),this.selectionStart=i):i>t&&i<e?"right"===this._selectionDirection?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection=Vt:"left"===this._selectionDirection&&(this._selectionDirection=Vt,this.selectionStart=e),this.selectionEnd=i)}},Mh=class extends _h{initHiddenTextarea(){let t=this.canvas&&oi(this.canvas.getElement())||At(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off",name:"fabricTextarea"}).map((([t,i])=>e.setAttribute(t,i)));let{top:i,left:s,fontSize:r}=this._calcTextareaPosition();e.style.cssText=`position: absolute; top: ${i}; left: ${s}; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ${r};`,(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map((([t,i])=>e.addEventListener(t,this[i].bind(this)))),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;let e="rtl"===this.direction?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){let e=this.fromPaste,{value:i,selectionStart:s,selectionEnd:r}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;let n=()=>{this.updateFromTextArea(),this.fire(se),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void n();let h,o,a,l,u=this._splitTextIntoLines(i).graphemeText,c=this._text.length,f=u.length,d=this.selectionStart,g=this.selectionEnd,p=d!==g,m=f-c,v=this.fromStringToGraphemeSelection(s,r,i),y=d>v.selectionStart;p?(o=this._text.slice(d,g),m+=g-d):f<c&&(o=y?this._text.slice(g+m,g):this._text.slice(d,d-m));let w=u.slice(v.selectionEnd-m,v.selectionEnd);if(o&&o.length&&(w.length&&(h=this.getSelectionStyles(d,d+1,!1),h=w.map((()=>h[0]))),p?(a=d,l=g):y?(a=g-o.length,l=g):(a=g,l=g+o.length),this.removeStyleFromTo(a,l)),w.length){let{copyPasteData:t}=jt();e&&w.join("")===t.copiedText&&!_t.disableStyleCopyPaste&&(h=t.copiedTextStyle),this.insertNewStyleBlock(w,d,h)}n()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate({target:t}){let{selectionStart:e,selectionEnd:i}=t;this.compositionStart=e,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;let{copyPasteData:t}=jt();t.copiedText=this.getSelectedText(),t.copiedTextStyle=_t.disableStyleCopyPaste?void 0:this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let i,s=this._getLineLeftOffset(t);return e>0&&(i=this.__charBounds[t][e-1],s+=i.left+i.width),s}getDownCursorOffset(t,e){let i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(r===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-i;let n=s.charIndex,h=this._getWidthBeforeCursor(r,n),o=this._getIndexOnLine(r+1,h);return this._textLines[r].slice(n).length+o+1+this.missingNewlineOffset(r)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){let i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(0===r||t.metaKey||33===t.keyCode)return-i;let n=s.charIndex,h=this._getWidthBeforeCursor(r,n),o=this._getIndexOnLine(r-1,h),a=this._textLines[r].slice(0,n),l=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+o-a.length+(1-l)}_getIndexOnLine(t,e){let i,s,r=this._textLines[t],n=this._getLineLeftOffset(t),h=0;for(let o=0,a=r.length;o<a;o++)if(i=this.__charBounds[t][o].width,n+=i,n>e){s=!0;let t=n,r=Math.abs(n-i-e);h=Math.abs(t-e)<r?o:o-1;break}return s||(h=r.length-1),h}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){let i=this[`get${t}CursorOffset`](e,this._selectionDirection===Vt);if(e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i){let t=this.text.length;this.selectionStart=Ds(0,this.selectionStart,t),this.selectionEnd=Ds(0,this.selectionEnd,t),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,"left"===this._selectionDirection?this.selectionStart+t:this.selectionEnd+t),0!==t}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t}moveCursorLeft(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorLeftOrRight("Left",t)}_move(t,e,i){let s;if(t.altKey)s=this[`findWordBoundary${i}`](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===i?-1:1,!0;s=this[`findLineBoundary${i}`](this[e])}return void 0!==s&&this[e]!==s&&(this[e]=s,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=Ht,this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return"right"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0===this.selectionStart?void 0:(this._selectionDirection=Ht,this._moveLeft(t,"selectionStart"))}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){let i=`moveCursor${t}${e.shiftKey?"WithShift":"WithoutShift"}`;this._currentCursorOpacity=1,this[i](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return"left"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd===this._text.length?void 0:(this._selectionDirection=Vt,this._moveRight(t,"selectionEnd"))}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Vt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}};const Th=t=>!!t.button;var kh=class extends Mh{constructor(...t){super(...t),Ct(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new Ch(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler({e:t,alreadySelected:e}){this.canvas&&this.editable&&!Th(t)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(t)||(this.canvas.textEditingManager.register(this),e&&(this.inCompositionMode=!1,this.setCursorByClick(t)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=e||this.isEditing)))}mouseUpHandler({e:t,transform:e}){let i=this.draggableTextDelegate.end(t);if(this.canvas){this.canvas.textEditingManager.unregister(this);let t=this.canvas._activeObject;if(t&&t!==this)return}!this.editable||this.group&&!this.group.interactive||e&&e.actionPerformed||Th(t)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(t),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(t){let e=this.getSelectionStartFromPointer(t);t.shiftKey?this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){let e=this.canvas.getScenePoint(t).transform(Pe(this.calcTransformMatrix())).add(new be(-this._getLeftOffset(),-this._getTopOffset())),i=0,s=0,r=0;for(let t=0;t<this._textLines.length&&i<=e.y;t++)i+=this.getHeightOfLine(t),r=t,t>0&&(s+=this._textLines[t-1].length+this.missingNewlineOffset(t-1));let n=Math.abs(this._getLineLeftOffset(r)),h=this._textLines[r].length,o=this.__charBounds[r];for(let t=0;t<h;t++){let i=n+o[t].kernedWidth;if(e.x<=i){Math.abs(e.x-i)<=Math.abs(e.x-n)&&s++;break}n=i,s++}return Math.min(this.flipX?h-s:s,this._text.length)}};const Fh="moveCursorUp",Oh="moveCursorDown",Dh="moveCursorLeft",$h="moveCursorRight",jh="exitEditing",Ah=(t,e)=>{let i=e.getRetinaScaling();t.setTransform(i,0,0,i,0,0);let s=e.viewportTransform;t.transform(s[0],s[1],s[2],s[3],s[4],s[5])},Eh={selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:jh,27:jh,33:Fh,34:Oh,35:$h,36:Dh,37:Dh,38:Fh,39:$h,40:Oh},keysMapRtl:{9:jh,27:jh,33:Fh,34:Oh,35:Dh,36:$h,37:$h,38:Fh,39:Dh,40:Oh},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"},_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1};var Ph=class t extends kh{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}get type(){let t=super.type;return"itext"===t?"i-text":t}constructor(e,i){super(e,{...t.ownDefaults,...i}),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof zn&&this.canvas.textEditingManager.remove(this),e instanceof zn&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(t=this.selectionStart||0,e=this.selectionEnd,i){return super.getSelectionStyles(t,e,i)}setSelectionStyles(t,e=this.selectionStart||0,i=this.selectionEnd){return super.setSelectionStyles(t,e,i)}get2DCursorLocation(t=this.selectionStart,e){return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){let e=this.isEditing;this.isEditing=!1;let i=super.toCanvasElement(t);return this.isEditing=e,i}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;let t=this.clearContextTop(!0);if(!t)return;let e,i=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),r=s.length>0,n=t;if(r){e=Oe(t.canvas),n=e.getContext("2d"),Ah(n,this.canvas);let i=this.calcTransformMatrix();n.transform(i[0],i[1],i[2],i[3],i[4],i[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(n,i):this.renderCursor(n,i),r)for(let e of s){let i=e.clipPath,s=Oe(t.canvas),r=s.getContext("2d");if(Ah(r,this.canvas),!i.absolutePositioned){let t=e.calcTransformMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5])}i.transform(r),i.drawObject(r,!0,{}),this.drawClipPathOnCache(n,i,s)}r&&(t.setTransform(1,0,0,1,0,0),t.drawImage(e,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){let t=[],e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(t=this.selectionStart,e){let i=this._getLeftOffset(),s=this._getTopOffset(),r=this._getCursorBoundariesOffsets(t,e);return{left:i,top:s,leftOffset:r.left,topOffset:r.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,i=0,{charIndex:s,lineIndex:r}=this.get2DCursorLocation(t),{textAlign:n,direction:h}=this;for(let t=0;t<r;t++)e+=this.getHeightOfLine(t);let o=this._getLineLeftOffset(r),a=this.__charBounds[r][s];a&&(i=a.left),0!==this.charSpacing&&s===this._textLines[r].length&&(i-=this._getWidthOfCharSpacing());let l=o+(i>0?i:0);return"rtl"===h&&("right"===n||"justify"===n||"justify-right"===n?l*=-1:"left"===n||"justify-left"===n?l=o-(i>0?i:0):"center"!==n&&"justify-center"!==n||(l=o-(i>0?i:0))),{top:e,left:l}}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(t=this.selectionStart,e=this._getCursorBoundaries(t)){let i=this.get2DCursorLocation(t),s=i.lineIndex,r=i.charIndex>0?i.charIndex-1:0,n=this.getValueOfPropertyAt(s,r,"fontSize"),h=this.getObjectScaling().x*this.canvas.getZoom(),o=this.cursorWidth/h,a=this.getValueOfPropertyAt(s,r,"deltaY"),l=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(s)/this.lineHeight-n*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(s,r,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-o/2,top:l+e.top+a,width:o,height:n}}_renderCursor(t,e,i){let{color:s,opacity:r,left:n,top:h,width:o,height:a}=this.getCursorRenderingData(i,e);t.fillStyle=s,t.globalAlpha=r,t.fillRect(n,h,o,a)}renderSelection(t,e){this._renderSelection(t,{selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd},e)}renderDragSourceEffect(){let t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){let e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,i){let{textAlign:s,direction:r}=this,n=e.selectionStart,h=e.selectionEnd,o=s.includes(bs),a=this.get2DCursorLocation(n),l=this.get2DCursorLocation(h),u=a.lineIndex,c=l.lineIndex,f=a.charIndex<0?0:a.charIndex,d=l.charIndex<0?0:l.charIndex;for(let e=u;e<=c;e++){let n=this._getLineLeftOffset(e)||0,h=this.getHeightOfLine(e),a=0,l=0;if(e===u&&(a=this.__charBounds[u][f].left),e>=u&&e<c)l=o&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===c)if(0===d)l=this.__charBounds[c][d].left;else{let t=this._getWidthOfCharSpacing();l=this.__charBounds[c][d-1].left+this.__charBounds[c][d-1].width-t}let g=h;(this.lineHeight<1||e===c&&this.lineHeight>1)&&(h/=this.lineHeight);let p=i.left+n+a,m=h,v=0,y=l-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",m=1,v=h):t.fillStyle=this.selectionColor,"rtl"===r&&("right"===s||"justify"===s||"justify-right"===s?p=this.width-p-y:"left"===s||"justify-left"===s?p=i.left+n-l:"center"!==s&&"justify-center"!==s||(p=i.left+n-l)),t.fillRect(p,i.top+i.topOffset+v,y,m),i.topOffset+=g}}getCurrentCharFontSize(){let t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){let t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,le)}_getCurrentCharIndex(){let t=this.get2DCursorLocation(this.selectionStart,!0);return{l:t.lineIndex,c:t.charIndex>0?t.charIndex-1:0}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}};Ct(Ph,"ownDefaults",Eh),Ct(Ph,"type","IText"),ge.setClass(Ph),ge.setClass(Ph,"i-text");var Lh=class t extends Ph{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e,i){super(e,{...t.ownDefaults,...i})}static createControls(){return{controls:{...yr(),mr:new Qs({x:.5,y:0,actionHandler:Ks,cursorStyleHandler:pr,actionName:ee}),ml:new Qs({x:-.5,y:0,actionHandler:Ks,cursorStyleHandler:pr,actionName:ee})}}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes("justify")&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,i=0,s=0,r={};for(let n=0;n<t.graphemeLines.length;n++)"\n"===t.graphemeText[s]&&n>0?(i=0,s++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[s])&&n>0&&(i++,s++),r[n]={line:e,offset:i},s+=t.graphemeLines[n].length,i+=t.graphemeLines[n].length;return r}styleHas(t,e){if(this._styleMap&&!this.isWrapping){let t=this._styleMap[e];t&&(e=t.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,i,s=0,r=!1,n=this._styleMap[t],h=this._styleMap[t+1];n&&(t=n.line,s=n.offset),h&&(e=h.line,r=e===t,i=h.offset);let o=void 0===t?this.styles:{line:this.styles[t]};for(let t in o)for(let e in o[t]){let n=parseInt(e,10);if(n>=s&&(!r||n<i))for(let i in o[t][e])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){let i=this._styleMap[t];if(!i)return{};t=i.line,e=i.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,i){let s=this._styleMap[t];super._setStyleDeclaration(s.line,s.offset+e,i)}_deleteStyleDeclaration(t,e){let i=this._styleMap[t];super._deleteStyleDeclaration(i.line,i.offset+e)}_getLineStyle(t){return!!this.styles[this._styleMap[t].line]}_setLineStyle(t){super._setLineStyle(this._styleMap[t].line)}_wrapText(t,e){this.isWrapping=!0;let i=this.getGraphemeDataForRender(t),s=[];for(let t=0;t<i.wordsData.length;t++)s.push(...this._wrapLine(t,e,i));return this.isWrapping=!1,s}getGraphemeDataForRender(t){let e=this.splitByGrapheme,i=e?"":" ",s=0;return{wordsData:t.map(((t,r)=>{let n=0,h=e?this.graphemeSplit(t):this.wordSplit(t);return 0===h.length?[{word:[],width:0}]:h.map((t=>{let h=e?[t]:this.graphemeSplit(t),o=this._measureWord(h,r,n);return s=Math.max(o,s),n+=h.length+i.length,{word:h,width:o}}))})),largestWordWidth:s}}_measureWord(t,e,i=0){let s,r=0;for(let n=0,h=t.length;n<h;n++)r+=this._getGraphemeBox(t[n],e,n+i,s,!0).kernedWidth,s=t[n];return r}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,{largestWordWidth:i,wordsData:s},r=0){let n,h=this._getWidthOfCharSpacing(),o=this.splitByGrapheme,a=[],l=o?"":" ",u=0,c=[],f=0,d=0,g=!0,p=Math.max(e-=r,i,this.dynamicMinWidth),m=s[t];for(n=0;n<m.length;n++){let{word:e,width:i}=m[n];f+=e.length,u+=d+i-h,u>p&&!g?(a.push(c),c=[],u=i,g=!0):u+=h,g||o||c.push(l),c=c.concat(e),d=o?0:this._measureWord([l],t,f),f++,g=!1}return n&&a.push(c),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-h+r),a}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?+!!this.isEndOfWrapping(t):1}_splitTextIntoLines(t){let e=super._splitTextIntoLines(t),i=this._wrapText(e.lines,this.width),s=Array(i.length);for(let t=0;t<i.length;t++)s[t]=i[t].join("");return e.lines=s,e.graphemeLines=i,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){let t=new Map;for(let e in this._styleMap){let i=parseInt(e,10);this._textLines[i]&&t.set(`${this._styleMap[e].line}`,!0)}for(let e in this.styles)t.has(e)||delete this.styles[e]}toObject(t=[]){return super.toObject(["minWidth","splitByGrapheme",...t])}};Ct(Lh,"type","Textbox"),Ct(Lh,"textLayoutProperties",[...Ph.textLayoutProperties,"width"]),Ct(Lh,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),ge.setClass(Lh);var Bh=class extends rn{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){let{target:i}=t,{clipPath:s,group:r}=i;if(!s||!this.shouldPerformLayout(t))return;let{width:n,height:h}=Si(sn(i,s)),o=new be(n,h);if(s.absolutePositioned)return{center:Fi(s.getRelativeCenterPoint(),void 0,r?r.calcTransformMatrix():void 0),size:o};{let r=s.getRelativeCenterPoint().transform(i.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){let{center:i=new be,correction:s=new be}=this.calcBoundingBox(e,t)||{};return{center:i.add(r),correction:s.subtract(r),size:o}}return{center:i.getRelativeCenterPoint().add(r),size:o}}}};Ct(Bh,"type","clip-path"),ge.setClass(Bh);var Rh=class extends rn{getInitialSize({target:t},{size:e}){return new be(t.width||e.x,t.height||e.y)}};Ct(Rh,"type","fixed"),ge.setClass(Rh);var Ih=class extends on{subscribeTargets(t){let e=t.target;t.targets.reduce(((t,e)=>(e.parent&&t.add(e.parent),t)),new Set).forEach((t=>{t.layoutManager.subscribeTargets({target:t,targets:[e]})}))}unsubscribeTargets(t){let e=t.target,i=e.getObjects();t.targets.reduce(((t,e)=>(e.parent&&t.add(e.parent),t)),new Set).forEach((t=>{!i.some((e=>e.parent===t))&&t.layoutManager.unsubscribeTargets({target:t,targets:[e]})}))}},Yh=class t extends ln{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e=[],i={}){super(),Object.assign(this,t.ownDefaults),this.setOptions(i);let{left:s,top:r,layoutManager:n}=i;this.groupInit(e,{left:s,top:r,layoutManager:null==n?new Ih:n})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(...t){"selection-order"===this.multiSelectionStacking?this.add(...t):t.forEach((t=>{let e=this._objects.findIndex((e=>e.isInFrontOf(t))),i=-1===e?this.size():e;this.insertAt(i,t)}))}canEnterGroup(t){return this.getObjects().some((e=>e.isDescendantOf(t)||t.isDescendantOf(e)))?(Mt("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);let i=new Set;e.forEach((t=>{let{parent:e}=t;e&&i.add(e)})),i.forEach("removed"===t?t=>{t._onAfterObjectsChange(en,e)}:t=>{t._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return`#<ActiveSelection: (${this.complexity()})>`}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,i){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;let s={hasControls:!1,...i,forActiveSelection:!0};for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,s);super._renderControls(t,e),t.restore()}};Ct(Yh,"type","ActiveSelection"),Ct(Yh,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),ge.setClass(Yh),ge.setClass(Yh,"activeSelection");var Xh=class{constructor(){Ct(this,"resources",{})}applyFilters(t,e,i,s,r){let n=r.getContext("2d",{willReadFrequently:!0,desynchronized:!0});if(!n)return;n.drawImage(e,0,0,i,s);let h={sourceWidth:i,sourceHeight:s,imageData:n.getImageData(0,0,i,s),originalEl:e,originalImageData:n.getImageData(0,0,i,s),canvasEl:r,ctx:n,filterBackend:this};t.forEach((t=>{t.applyTo(h)}));let{imageData:o}=h;return o.width===i&&o.height===s||(r.width=o.width,r.height=o.height),n.putImageData(o,0,0),h}},Wh=class{constructor({tileSize:t=_t.textureSize}={}){Ct(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),Ct(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){let i=Oe({width:t,height:e}),s=i.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});s&&(s.clearColor(0,0,0,0),this.canvas=i,this.gl=s)}applyFilters(t,e,i,s,r,n){let h,o=this.gl,a=r.getContext("2d");if(!o||!a)return;n&&(h=this.getCachedTexture(n,e));let l={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:i,sourceHeight:s,destinationWidth:i,destinationHeight:s,context:o,sourceTexture:this.createTexture(o,i,s,h?void 0:e),targetTexture:this.createTexture(o,i,s),originalTexture:h||this.createTexture(o,i,s,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:r},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),t.forEach((t=>{t&&t.applyTo(l)})),function(t){let e=t.targetCanvas,i=t.destinationWidth,s=t.destinationHeight;e.width===i&&e.height===s||(e.width=i,e.height=s)}(l),this.copyGLTo2D(o,l),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(l.sourceTexture),o.deleteTexture(l.targetTexture),o.deleteFramebuffer(u),a.setTransform(1,0,0,1,0,0),l}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,i,s,r){let{NEAREST:n,TEXTURE_2D:h,RGBA:o,UNSIGNED_BYTE:a,CLAMP_TO_EDGE:l,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:c,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:d}=t,g=t.createTexture();return t.bindTexture(h,g),t.texParameteri(h,u,r||n),t.texParameteri(h,c,r||n),t.texParameteri(h,f,l),t.texParameteri(h,d,l),s?t.texImage2D(h,0,o,o,a,s):t.texImage2D(h,0,o,e,i,0,o,a,null),g}getCachedTexture(t,e,i){let{textureCache:s}=this;if(s[t])return s[t];{let r=this.createTexture(this.gl,e.width,e.height,e,i);return r&&(s[t]=r),r}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){let i=t.canvas,s=e.targetCanvas,r=s.getContext("2d");r&&(r.translate(0,s.height),r.scale(1,-1),r.drawImage(i,0,i.height-s.height,s.width,s.height,0,0,s.width,s.height))}copyGLTo2DPutImageData(t,e){let i=e.targetCanvas.getContext("2d"),s=e.destinationWidth,r=e.destinationHeight,n=s*r*4;if(!i)return;let h=new Uint8Array(this.imageBuffer,0,n),o=new Uint8ClampedArray(this.imageBuffer,0,n);t.readPixels(0,0,s,r,t.RGBA,t.UNSIGNED_BYTE,h);let a=new ImageData(o,s,r);i.putImageData(a,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;let t=this.gl,e={renderer:"",vendor:""};if(!t)return e;let i=t.getExtension("WEBGL_debug_renderer_info");if(i){let s=t.getParameter(i.UNMASKED_RENDERER_WEBGL),r=t.getParameter(i.UNMASKED_VENDOR_WEBGL);s&&(e.renderer=s.toLowerCase()),r&&(e.vendor=r.toLowerCase())}return this.gpuInfo=e,e}};let zh;function Nh(t=!0){return!zh&&t&&(zh=function(){let{WebGLProbe:t}=jt();return t.queryWebGL(Fe()),_t.enableGLFiltering&&t.isSupported(_t.textureSize)?new Wh({tileSize:_t.textureSize}):new Xh}()),zh}const Hh=["cropX","cropY"];var Gh=class t extends xr{static getDefaults(){return{...super.getDefaults(),...t.ownDefaults}}constructor(e,i){super(),Ct(this,"_lastScaleX",1),Ct(this,"_lastScaleY",1),Ct(this,"_filterScalingX",1),Ct(this,"_filterScalingY",1),this.filters=[],Object.assign(this,t.ownDefaults),this.setOptions(i),this.cacheKey=`texture${ke()}`,this.setElement("string"==typeof e?(this.canvas&&oi(this.canvas.getElement())||At()).getElementById(e):e,i)}getElement(){return this._element}setElement(t,e={}){this.removeTexture(this.cacheKey),this.removeTexture(`${this.cacheKey}_filtered`),this._element=t,this._originalElement=t,this._setWidthHeight(e),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){let e=Nh(!1);e instanceof Wh&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture(`${this.cacheKey}_filtered`),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach((t=>{let e=this[t];e&&jt().dispose(e),this[t]=void 0}))}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){let t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||0===this.strokeWidth)return;let e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,-i),t.lineTo(e,-i),t.lineTo(e,i),t.lineTo(-e,i),t.lineTo(-e,-i),t.closePath()}toObject(t=[]){let e=[];return this.filters.forEach((t=>{t&&e.push(t.toObject())})),{...super.toObject([...Hh,...t]),src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e,...this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{}}}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){let t=[],e=this._element,i=-this.width/2,s=-this.height/2,r=[],n=[],h="",o="";if(!e)return[];if(this.hasCrop()){let t=ke();r.push('<clipPath id="imageCrop_'+t+'">\n','\t<rect x="'+i+'" y="'+s+'" width="'+gi(this.width)+'" height="'+gi(this.height)+'" />\n',"</clipPath>\n"),h=' clip-path="url(#imageCrop_'+t+')" '}if(this.imageSmoothing||(o=' image-rendering="optimizeSpeed"'),t.push("\t<image ","COMMON_PARTS",`xlink:href="${gi(this.getSrc(!0))}" x="${i-this.cropX}" y="${s-this.cropY}" width="${e.width||e.naturalWidth}" height="${e.height||e.naturalHeight}"${o}${h}></image>\n`),this.stroke||this.strokeDashArray){let t=this.fill;this.fill=null,n=[`\t<rect x="${i}" y="${s}" width="${gi(this.width)}" height="${gi(this.height)}" style="${this.getSvgStyles()}" />\n`],this.fill=t}return r="fill"===this.paintFirst?r.concat(t,n):r.concat(n,t),r}getSrc(t){let e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t,{crossOrigin:e,signal:i}={}){return qe(t,{crossOrigin:e,signal:i}).then((t=>{void 0!==e&&this.set({crossOrigin:e}),this.setElement(t)}))}toString(){return`#<Image: { src: "${this.getSrc()}" }>`}applyResizeFilters(){let t=this.resizeFilter,e=this.minimumScaleTrigger,i=this.getTotalObjectScaling(),s=i.x,r=i.y,n=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||s>e&&r>e)return this._element=n,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=s,void(this._lastScaleY=r);let h=Oe(n),{width:o,height:a}=n;this._element=h,this._lastScaleX=t.scaleX=s,this._lastScaleY=t.scaleY=r,Nh().applyFilters([t],n,o,a,this._element),this._filterScalingX=h.width/this._originalElement.width,this._filterScalingY=h.height/this._originalElement.height}applyFilters(t=this.filters||[]){if(t=t.filter((t=>t&&!t.isNeutralState())),this.set("dirty",!0),this.removeTexture(`${this.cacheKey}_filtered`),0===t.length)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);let e=this._originalElement,i=e.naturalWidth||e.width,s=e.naturalHeight||e.height;if(this._element===this._originalElement){let t=Oe({width:i,height:s});this._element=t,this._filteredEl=t}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,i,s),this._lastScaleX=1,this._lastScaleY=1);Nh().applyFilters(t,this._originalElement,i,s,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){let e=this._element;if(!e)return;let i=this._filterScalingX,s=this._filterScalingY,r=this.width,n=this.height,h=Math.max(this.cropX,0),o=Math.max(this.cropY,0),a=e.naturalWidth||e.width,l=e.naturalHeight||e.height,u=h*i,c=o*s,f=Math.min(r*i,a-u),d=Math.min(n*s,l-c),g=-r/2,p=-n/2,m=Math.min(r,a/i-h),v=Math.min(n,l/s-o);e&&t.drawImage(e,u,c,f,d,g,p,m,v)}_needsResize(){let t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight({width:t,height:e}={}){let i=this.getOriginalSize();this.width=t||i.width,this.height=e||i.height}parsePreserveAspectRatioAttribute(){let t,e=(t=>{let[e,i]=t.trim().split(" "),[s,r]=(n=e)&&"none"!==n?[n.slice(1,4),n.slice(5,8)]:"none"===n?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:i||"meet",alignX:s,alignY:r}})(this.preserveAspectRatio||""),i=this.width,s=this.height,r={width:i,height:s},n=this._element.width,h=this._element.height,o=1,a=1,l=0,u=0,c=0,f=0;return!e||"none"===e.alignX&&"none"===e.alignY?(o=i/n,a=s/h):("meet"===e.meetOrSlice&&(o=a=((t,e)=>Math.min(e.width/t.width,e.height/t.height))(this._element,r),t=(i-n*o)/2,"Min"===e.alignX&&(l=-t),"Max"===e.alignX&&(l=t),t=(s-h*a)/2,"Min"===e.alignY&&(u=-t),"Max"===e.alignY&&(u=t)),"slice"===e.meetOrSlice&&(o=a=((t,e)=>Math.max(e.width/t.width,e.height/t.height))(this._element,r),t=n-i/o,"Mid"===e.alignX&&(c=t/2),"Max"===e.alignX&&(c=t),t=h-s/a,"Mid"===e.alignY&&(f=t/2),"Max"===e.alignY&&(f=t),n=i/o,h=s/a)),{width:n,height:h,scaleX:o,scaleY:a,offsetLeft:l,offsetTop:u,cropX:c,cropY:f}}static fromObject({filters:t,resizeFilter:e,src:i,crossOrigin:s,type:r,...n},h){return Promise.all([qe(i,{...h,crossOrigin:s}),t&&Ke(t,h),e?Ke([e],h):[],Je(n,h)]).then((([t,e=[],[s],r={}])=>new this(t,{...n,src:i,filters:e,resizeFilter:s,...r})))}static fromURL(t,{crossOrigin:e=null,signal:i}={},s){return qe(t,{crossOrigin:e,signal:i}).then((t=>new this(t,s)))}static async fromElement(t,e={},i){let s=Jr(t,this.ATTRIBUTE_NAMES,i);return this.fromURL(s["xlink:href"]||s.href,e,s).catch((t=>(Mt("log","Unable to parse Image",t),null)))}};Ct(Gh,"type","Image"),Ct(Gh,"cacheProperties",[...js,...Hh]),Ct(Gh,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),Ct(Gh,"ATTRIBUTE_NAMES",[...Dr,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),ge.setClass(Gh),ge.setSVGClass(Gh),cs(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const Vh=t=>void 0!==t.webgl,Uh="precision highp float",qh=`\n ${Uh};\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }`,Kh=new RegExp(Uh,"g");var Jh=class{get type(){return this.constructor.type}constructor({type:t,...e}={}){Object.assign(this,this.constructor.defaults,e)}getFragmentSource(){return qh}getVertexSource(){return"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n void main() {\n vTexCoord = aPosition;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }"}createProgram(t,e=this.getFragmentSource(),i=this.getVertexSource()){let{WebGLProbe:{GLPrecision:s="highp"}}=jt();"highp"!==s&&(e=e.replace(Kh,Uh.replace("highp",s)));let r=t.createShader(t.VERTEX_SHADER),n=t.createShader(t.FRAGMENT_SHADER),h=t.createProgram();if(!r||!n||!h)throw new Tt("Vertex, fragment shader or program creation error");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Tt(`Vertex shader compile error for ${this.type}: ${t.getShaderInfoLog(r)}`);if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Tt(`Fragment shader compile error for ${this.type}: ${t.getShaderInfoLog(n)}`);if(t.attachShader(h,r),t.attachShader(h,n),t.linkProgram(h),!t.getProgramParameter(h,t.LINK_STATUS))throw new Tt(`Shader link error for "${this.type}" ${t.getProgramInfoLog(h)}`);let o=this.getUniformLocations(t,h)||{};return o.uStepW=t.getUniformLocation(h,"uStepW"),o.uStepH=t.getUniformLocation(h,"uStepH"),{program:h,attributeLocations:this.getAttributeLocations(t,h),uniformLocations:o}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){let i=this.constructor.uniformLocations,s={};for(let r=0;r<i.length;r++)s[i[r]]=t.getUniformLocation(e,i[r]);return s}sendAttributeData(t,e,i){let s=e.aPosition,r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,i,t.STATIC_DRAW)}_setupFrameBuffer(t){let e=t.context;if(t.passes>1){let i=t.destinationWidth,s=t.destinationHeight;t.sourceWidth===i&&t.sourceHeight===s||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,i,s)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;let e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){Vh(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){let e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){let e=t.context,i=this.retrieveShader(t);e.bindTexture(e.TEXTURE_2D,0===t.pass&&t.originalTexture?t.originalTexture:t.sourceTexture),e.useProgram(i.program),this.sendAttributeData(e,i.attributeLocations,t.aPosition),e.uniform1f(i.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(i.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,i.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,i){t.activeTexture(i),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){let{sourceWidth:e,sourceHeight:i}=t;t.helpLayer=Oe({width:e,height:i})}}toObject(){let t=Object.keys(this.constructor.defaults||{});return{type:this.type,...t.reduce(((t,e)=>(t[e]=this[e],t)),{})}}toJSON(){return this.toObject()}static async fromObject({type:t,...e},i){return new this(e)}};Ct(Jh,"type","BaseFilter"),Ct(Jh,"uniformLocations",[]);const Zh={multiply:"gl_FragColor.rgb *= uColor.rgb;\n",screen:"gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);\n",add:"gl_FragColor.rgb += uColor.rgb;\n",difference:"gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);\n",subtract:"gl_FragColor.rgb -= uColor.rgb;\n",lighten:"gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);\n",darken:"gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);\n",exclusion:"gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);\n",overlay:"\n if (uColor.r < 0.5) {\n gl_FragColor.r *= 2.0 * uColor.r;\n } else {\n gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);\n }\n if (uColor.g < 0.5) {\n gl_FragColor.g *= 2.0 * uColor.g;\n } else {\n gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);\n }\n if (uColor.b < 0.5) {\n gl_FragColor.b *= 2.0 * uColor.b;\n } else {\n gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);\n }\n ",tint:"\n gl_FragColor.rgb *= (1.0 - uColor.a);\n gl_FragColor.rgb += uColor.rgb;\n "};var Qh=class extends Jh{getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return`\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n gl_FragColor = color;\n if (color.a > 0.0) {\n ${Zh[this.mode]}\n }\n }\n `}applyTo2d({imageData:{data:t}}){let e=new os(this.color).getSource(),i=this.alpha,s=e[0]*i,r=e[1]*i,n=e[2]*i,h=1-i;for(let e=0;e<t.length;e+=4){let i,o,a,l=t[e],u=t[e+1],c=t[e+2];switch(this.mode){case"multiply":i=l*s/255,o=u*r/255,a=c*n/255;break;case"screen":i=255-(255-l)*(255-s)/255,o=255-(255-u)*(255-r)/255,a=255-(255-c)*(255-n)/255;break;case"add":i=l+s,o=u+r,a=c+n;break;case"difference":i=Math.abs(l-s),o=Math.abs(u-r),a=Math.abs(c-n);break;case"subtract":i=l-s,o=u-r,a=c-n;break;case"darken":i=Math.min(l,s),o=Math.min(u,r),a=Math.min(c,n);break;case"lighten":i=Math.max(l,s),o=Math.max(u,r),a=Math.max(c,n);break;case"overlay":i=s<128?2*l*s/255:255-2*(255-l)*(255-s)/255,o=r<128?2*u*r/255:255-2*(255-u)*(255-r)/255,a=n<128?2*c*n/255:255-2*(255-c)*(255-n)/255;break;case"exclusion":i=s+l-2*s*l/255,o=r+u-2*r*u/255,a=n+c-2*n*c/255;break;case"tint":i=s+l*h,o=r+u*h,a=n+c*h}t[e]=i,t[e+1]=o,t[e+2]=a}}sendUniformData(t,e){let i=new os(this.color).getSource();i[0]=this.alpha*i[0]/255,i[1]=this.alpha*i[1]/255,i[2]=this.alpha*i[2]/255,i[3]=this.alpha,t.uniform4fv(e.uColor,i)}};Ct(Qh,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),Ct(Qh,"type","BlendColor"),Ct(Qh,"uniformLocations",["uColor"]),ge.setClass(Qh);const to={multiply:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.rgba *= color2.rgba;\n gl_FragColor = color;\n }\n ",mask:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.a = color2.a;\n gl_FragColor = color;\n }\n "};var eo=class extends Jh{getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return to[this.mode]}getVertexSource(){return"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n uniform mat3 uTransformMatrix;\n void main() {\n vTexCoord = aPosition;\n vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }\n "}applyToWebGL(t){let e=t.context,i=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,i,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){let t=this.image,{width:e,height:i}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/i,1]}applyTo2d({imageData:{data:t,width:e,height:i},filterBackend:{resources:s}}){let r=this.image;s.blendImage||(s.blendImage=Fe());let n=s.blendImage,h=n.getContext("2d");n.width!==e||n.height!==i?(n.width=e,n.height=i):h.clearRect(0,0,e,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,e,i);let o=h.getImageData(0,0,e,i).data;for(let e=0;e<t.length;e+=4){let i=t[e],s=t[e+1],r=t[e+2],n=t[e+3],h=o[e],a=o[e+1],l=o[e+2],u=o[e+3];switch(this.mode){case"multiply":t[e]=i*h/255,t[e+1]=s*a/255,t[e+2]=r*l/255,t[e+3]=n*u/255;break;case"mask":t[e+3]=u}}}sendUniformData(t,e){let i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)}toObject(){return{...super.toObject(),image:this.image&&this.image.toObject()}}static async fromObject({type:t,image:e,...i},s){return Gh.fromObject(e,s).then((t=>new this({...i,image:t})))}};Ct(eo,"type","BlendImage"),Ct(eo,"defaults",{mode:"multiply",alpha:1}),Ct(eo,"uniformLocations",["uTransformMatrix","uImage"]),ge.setClass(eo);var io=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n const float nSamples = 15.0;\n vec3 v3offset = vec3(12.9898, 78.233, 151.7182);\n float random(vec3 scale) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n }\n void main() {\n vec4 color = vec4(0.0);\n float totalC = 0.0;\n float totalA = 0.0;\n float offset = random(v3offset);\n for (float t = -nSamples; t <= nSamples; t++) {\n float percent = (t + offset - 0.5) / nSamples;\n vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);\n float weight = 1.0 - abs(percent);\n float alpha = weight * sample.a;\n color.rgb += sample.rgb * alpha;\n color.a += alpha;\n totalA += weight;\n totalC += alpha;\n }\n gl_FragColor.rgb = color.rgb / totalC;\n gl_FragColor.a = color.a / totalA;\n }\n "}applyTo(t){Vh(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d({imageData:{data:t,width:e,height:i}}){this.aspectRatio=e/i,this.horizontal=!0;let s=this.getBlurValue()*e,r=new Uint8ClampedArray(t),n=4*e;for(let e=0;e<t.length;e+=4){let i=0,h=0,o=0,a=0,l=0,u=e-e%n,c=u+n;for(let r=-14;r<15;r++){let n=r/15,f=4*Math.floor(s*n),d=1-Math.abs(n),g=e+f;g<u?g=u:g>c&&(g=c);let p=t[g+3]*d;i+=t[g]*p,h+=t[g+1]*p,o+=t[g+2]*p,a+=p,l+=d}r[e]=i/a,r[e+1]=h/a,r[e+2]=o/a,r[e+3]=a/l}this.horizontal=!1,s=this.getBlurValue()*i;for(let e=0;e<r.length;e+=4){let i=0,h=0,o=0,a=0,l=0,u=e%n,c=r.length-n+u;for(let t=-14;t<15;t++){let f=t/15,d=Math.floor(s*f)*n,g=1-Math.abs(f),p=e+d;p<u?p=u:p>c&&(p=c);let m=r[p+3]*g;i+=r[p]*m,h+=r[p+1]*m,o+=r[p+2]*m,a+=m,l+=g}t[e]=i/a,t[e+1]=h/a,t[e+2]=o/a,t[e+3]=a/l}}sendUniformData(t,e){let i=this.chooseRightDelta();t.uniform2fv(e.uDelta,i)}isNeutralState(){return 0===this.blur}getBlurValue(){let t=1,{horizontal:e,aspectRatio:i}=this;return e?i>1&&(t=1/i):i<1&&(t=i),t*this.blur*.12}chooseRightDelta(){let t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}};Ct(io,"type","Blur"),Ct(io,"defaults",{blur:0}),Ct(io,"uniformLocations",["uDelta"]),ge.setClass(io);var so=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBrightness;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += uBrightness;\n gl_FragColor = color;\n }\n"}applyTo2d({imageData:{data:t}}){let e=Math.round(255*this.brightness);for(let i=0;i<t.length;i+=4)t[i]+=e,t[i+1]+=e,t[i+2]+=e}isNeutralState(){return 0===this.brightness}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}};Ct(so,"type","Brightness"),Ct(so,"defaults",{brightness:0}),Ct(so,"uniformLocations",["uBrightness"]),ge.setClass(so);const ro={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};var no=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n uniform mat4 uColorMatrix;\n uniform vec4 uConstants;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color *= uColorMatrix;\n color += uConstants;\n gl_FragColor = color;\n }"}applyTo2d(t){let e=t.imageData.data,i=this.matrix,s=this.colorsOnly;for(let t=0;t<e.length;t+=4){let r=e[t],n=e[t+1],h=e[t+2];if(e[t]=r*i[0]+n*i[1]+h*i[2]+255*i[4],e[t+1]=r*i[5]+n*i[6]+h*i[7]+255*i[9],e[t+2]=r*i[10]+n*i[11]+h*i[12]+255*i[14],!s){let s=e[t+3];e[t]+=s*i[3],e[t+1]+=s*i[8],e[t+2]+=s*i[13],e[t+3]=r*i[15]+n*i[16]+h*i[17]+s*i[18]+255*i[19]}}}sendUniformData(t,e){let i=this.matrix,s=[i[4],i[9],i[14],i[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,[i[0],i[1],i[2],i[3],i[5],i[6],i[7],i[8],i[10],i[11],i[12],i[13],i[15],i[16],i[17],i[18]]),t.uniform4fv(e.uConstants,s)}toObject(){return{...super.toObject(),matrix:[...this.matrix]}}};function ho(t,e){var i;let s=(Ct(i=class extends no{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",t),Ct(i,"defaults",{colorsOnly:!1,matrix:e}),i);return ge.setClass(s,t),s}Ct(no,"type","ColorMatrix"),Ct(no,"defaults",ro),Ct(no,"uniformLocations",["uColorMatrix","uConstants"]),ge.setClass(no),ho("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),ho("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),ho("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),ho("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),ho("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),ho("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),ho("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);var oo=class extends Jh{constructor(t={}){super(t),this.subFilters=t.subFilters||[]}applyTo(t){Vh(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach((e=>{e.applyTo(t)}))}toObject(){return{type:this.type,subFilters:this.subFilters.map((t=>t.toObject()))}}isNeutralState(){return!this.subFilters.some((t=>!t.isNeutralState()))}static fromObject(t,e){return Promise.all((t.subFilters||[]).map((t=>ge.getClass(t.type).fromObject(t,e)))).then((t=>new this({subFilters:t})))}};Ct(oo,"type","Composed"),ge.setClass(oo);var ao=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uContrast;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\n color.rgb = contrastF * (color.rgb - 0.5) + 0.5;\n gl_FragColor = color;\n }"}isNeutralState(){return 0===this.contrast}applyTo2d({imageData:{data:t}}){let e=Math.floor(255*this.contrast),i=259*(e+255)/(255*(259-e));for(let e=0;e<t.length;e+=4)t[e]=i*(t[e]-128)+128,t[e+1]=i*(t[e+1]-128)+128,t[e+2]=i*(t[e+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}};Ct(ao,"type","Contrast"),Ct(ao,"defaults",{contrast:0}),Ct(ao,"uniformLocations",["uContrast"]),ge.setClass(ao);const lo={Convolute_3_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_3_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_5_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_5_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_7_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_7_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_9_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_9_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n "};var uo=class extends Jh{getCacheKey(){return`${this.type}_${Math.sqrt(this.matrix.length)}_${+!!this.opaque}`}getFragmentSource(){return lo[this.getCacheKey()]}applyTo2d(t){let e,i,s,r,n,h,o,a,l,u,c,f,d,g=t.imageData,p=g.data,m=this.matrix,v=Math.round(Math.sqrt(m.length)),y=Math.floor(v/2),w=g.width,b=g.height,x=t.ctx.createImageData(w,b),C=x.data,S=+!!this.opaque;for(c=0;c<b;c++)for(u=0;u<w;u++){for(n=4*(c*w+u),e=0,i=0,s=0,r=0,d=0;d<v;d++)for(f=0;f<v;f++)o=c+d-y,h=u+f-y,o<0||o>=b||h<0||h>=w||(a=4*(o*w+h),l=m[d*v+f],e+=p[a]*l,i+=p[a+1]*l,s+=p[a+2]*l,S||(r+=p[a+3]*l));C[n]=e,C[n+1]=i,C[n+2]=s,C[n+3]=S?p[n+3]:r}t.imageData=x}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return{...super.toObject(),opaque:this.opaque,matrix:[...this.matrix]}}};Ct(uo,"type","Convolute"),Ct(uo,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),Ct(uo,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),ge.setClass(uo);const co="Gamma";var fo=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec3 uGamma;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec3 correction = (1.0 / uGamma);\n color.r = pow(color.r, correction.r);\n color.g = pow(color.g, correction.g);\n color.b = pow(color.b, correction.b);\n gl_FragColor = color;\n gl_FragColor.rgb *= color.a;\n }\n"}constructor(t={}){super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d({imageData:{data:t}}){let e=this.gamma,i=1/e[0],s=1/e[1],r=1/e[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});let n=this.rgbValues;for(let t=0;t<256;t++)n.r[t]=255*(t/255)**i,n.g[t]=255*(t/255)**s,n.b[t]=255*(t/255)**r;for(let e=0;e<t.length;e+=4)t[e]=n.r[t[e]],t[e+1]=n.g[t[e+1]],t[e+2]=n.b[t[e+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){let{gamma:t}=this;return 1===t[0]&&1===t[1]&&1===t[2]}toObject(){return{type:co,gamma:this.gamma.concat()}}};Ct(fo,"type",co),Ct(fo,"defaults",{gamma:[1,1,1]}),Ct(fo,"uniformLocations",["uGamma"]),ge.setClass(fo);const go={average:"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float average = (color.r + color.b + color.g) / 3.0;\n gl_FragColor = vec4(average, average, average, color.a);\n }\n ",lightness:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n ",luminosity:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n "};var po=class extends Jh{applyTo2d({imageData:{data:t}}){for(let e,i=0;i<t.length;i+=4){let s=t[i],r=t[i+1],n=t[i+2];switch(this.mode){case"average":e=(s+r+n)/3;break;case"lightness":e=(Math.min(s,r,n)+Math.max(s,r,n))/2;break;case"luminosity":e=.21*s+.72*r+.07*n}t[i+2]=t[i+1]=t[i]=e}}getCacheKey(){return`${this.type}_${this.mode}`}getFragmentSource(){return go[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}};Ct(po,"type","Grayscale"),Ct(po,"defaults",{mode:"average"}),Ct(po,"uniformLocations",["uMode"]),ge.setClass(po);const mo={...ro,rotation:0};var vo=class extends no{calculateMatrix(){let t=this.rotation*Math.PI,e=ye(t),i=we(t),s=1/3,r=Math.sqrt(s)*i,n=1-e;this.matrix=[e+n/3,s*n-r,s*n+r,0,0,s*n+r,e+s*n,s*n-r,0,0,s*n-r,s*n+r,e+s*n,0,0,0,0,0,1,0]}isNeutralState(){return 0===this.rotation}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}};Ct(vo,"type","HueRotation"),Ct(vo,"defaults",mo),ge.setClass(vo);var yo=class extends Jh{applyTo2d({imageData:{data:t}}){for(let e=0;e<t.length;e+=4)t[e]=255-t[e],t[e+1]=255-t[e+1],t[e+2]=255-t[e+2],this.alpha&&(t[e+3]=255-t[e+3])}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uInvert;\n uniform int uAlpha;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n if (uInvert == 1) {\n if (uAlpha == 1) {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);\n } else {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n }\n } else {\n gl_FragColor = color;\n }\n }\n"}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}};Ct(yo,"type","Invert"),Ct(yo,"defaults",{alpha:!1,invert:!0}),Ct(yo,"uniformLocations",["uInvert","uAlpha"]),ge.setClass(yo);var wo=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uStepH;\n uniform float uNoise;\n uniform float uSeed;\n varying vec2 vTexCoord;\n float rand(vec2 co, float seed, float vScale) {\n return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n }\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\n gl_FragColor = color;\n }\n"}applyTo2d({imageData:{data:t}}){let e=this.noise;for(let i=0;i<t.length;i+=4){let s=(.5-Math.random())*e;t[i]+=s,t[i+1]+=s,t[i+2]+=s}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return 0===this.noise}};Ct(wo,"type","Noise"),Ct(wo,"defaults",{noise:0}),Ct(wo,"uniformLocations",["uNoise","uSeed"]),ge.setClass(wo);var bo=class extends Jh{applyTo2d({imageData:{data:t,width:e,height:i}}){for(let s=0;s<i;s+=this.blocksize)for(let r=0;r<e;r+=this.blocksize){let n=4*s*e+4*r,h=t[n],o=t[n+1],a=t[n+2],l=t[n+3];for(let n=s;n<Math.min(s+this.blocksize,i);n++)for(let i=r;i<Math.min(r+this.blocksize,e);i++){let s=4*n*e+4*i;t[s]=h,t[s+1]=o,t[s+2]=a,t[s+3]=l}}}isNeutralState(){return 1===this.blocksize}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBlocksize;\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n float blockW = uBlocksize * uStepW;\n float blockH = uBlocksize * uStepH;\n int posX = int(vTexCoord.x / blockW);\n int posY = int(vTexCoord.y / blockH);\n float fposX = float(posX);\n float fposY = float(posY);\n vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\n vec4 color = texture2D(uTexture, squareCoords);\n gl_FragColor = color;\n }\n"}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}};Ct(bo,"type","Pixelate"),Ct(bo,"defaults",{blocksize:4}),Ct(bo,"uniformLocations",["uBlocksize"]),ge.setClass(bo);var xo=class extends Jh{getFragmentSource(){return"\nprecision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\n gl_FragColor.a = 0.0;\n }\n}\n"}applyTo2d({imageData:{data:t}}){let e=255*this.distance,i=new os(this.color).getSource(),s=[i[0]-e,i[1]-e,i[2]-e],r=[i[0]+e,i[1]+e,i[2]+e];for(let e=0;e<t.length;e+=4){let i=t[e],n=t[e+1],h=t[e+2];i>s[0]&&n>s[1]&&h>s[2]&&i<r[0]&&n<r[1]&&h<r[2]&&(t[e+3]=0)}}sendUniformData(t,e){let i=new os(this.color).getSource(),s=this.distance,r=[i[0]/255+s,i[1]/255+s,i[2]/255+s,1];t.uniform4fv(e.uLow,[0+i[0]/255-s,0+i[1]/255-s,0+i[2]/255-s,1]),t.uniform4fv(e.uHigh,r)}};Ct(xo,"type","RemoveColor"),Ct(xo,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),Ct(xo,"uniformLocations",["uLow","uHigh"]),ge.setClass(xo);var Co=class extends Jh{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){return Math.ceil(this.lanczosLobes/this.tempScale)}getCacheKey(){let t=this.getFilterWindow();return`${this.type}_${t}`}getFragmentSource(){let t=this.getFilterWindow();return this.generateShader(t)}getTaps(){let t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,i=this.getFilterWindow(),s=Array(i);for(let r=1;r<=i;r++)s[r-1]=t(r*e);return s}generateShader(t){let e=Array(t);for(let i=1;i<=t;i++)e[i-1]=`${i}.0 * uDelta`;return`\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[${t}];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ${e.map(((t,e)=>`\n color += texture2D(uTexture, vTexCoord + ${t}) * uTaps[${e}] + texture2D(uTexture, vTexCoord - ${t}) * uTaps[${e}];\n sum += 2.0 * uTaps[${e}];\n `)).join("\n")}\n gl_FragColor = color / sum;\n }\n `}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Vh(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return 1===this.scaleX&&1===this.scaleY}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<1.1920929e-7&&e>-1.1920929e-7)return 1;let i=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(i)/i}}applyTo2d(t){let e=t.imageData,i=this.scaleX,s=this.scaleY;this.rcpScaleX=1/i,this.rcpScaleY=1/s;let r,n=e.width,h=e.height,o=Math.round(n*i),a=Math.round(h*s);r="sliceHack"===this.resizeType?this.sliceByTwo(t,n,h,o,a):"hermite"===this.resizeType?this.hermiteFastResize(t,n,h,o,a):"bilinear"===this.resizeType?this.bilinearFiltering(t,n,h,o,a):"lanczos"===this.resizeType?this.lanczosResize(t,n,h,o,a):new ImageData(o,a),t.imageData=r}sliceByTwo(t,e,i,s,r){let n=t.imageData,h=.5,o=!1,a=!1,l=e*h,u=i*h,c=t.filterBackend.resources,f=0,d=0,g=e,p=0;c.sliceByTwo||(c.sliceByTwo=Fe());let m=c.sliceByTwo;(m.width<1.5*e||m.height<i)&&(m.width=1.5*e,m.height=i);let v=m.getContext("2d");for(v.clearRect(0,0,1.5*e,i),v.putImageData(n,0,0),s=Math.floor(s),r=Math.floor(r);!o||!a;)e=l,i=u,s<Math.floor(l*h)?l=Math.floor(l*h):(l=s,o=!0),r<Math.floor(u*h)?u=Math.floor(u*h):(u=r,a=!0),v.drawImage(m,f,d,e,i,g,p,l,u),f=g,d=p,p+=u;return v.getImageData(f,d,s,r)}lanczosResize(t,e,i,s,r){let n=t.imageData.data,h=t.ctx.createImageData(s,r),o=h.data,a=this.lanczosCreate(this.lanczosLobes),l=this.rcpScaleX,u=this.rcpScaleY,c=2/this.rcpScaleX,f=2/this.rcpScaleY,d=Math.ceil(l*this.lanczosLobes/2),g=Math.ceil(u*this.lanczosLobes/2),p={},m={x:0,y:0},v={x:0,y:0};return function t(y){let w,b,x,C,S,_,M,T,k,F,O;for(m.x=(y+.5)*l,v.x=Math.floor(m.x),w=0;w<r;w++){for(m.y=(w+.5)*u,v.y=Math.floor(m.y),S=0,_=0,M=0,T=0,k=0,b=v.x-d;b<=v.x+d;b++)if(!(b<0||b>=e)){F=Math.floor(1e3*Math.abs(b-m.x)),p[F]||(p[F]={});for(let t=v.y-g;t<=v.y+g;t++)t<0||t>=i||(O=Math.floor(1e3*Math.abs(t-m.y)),p[F][O]||(p[F][O]=a(Math.sqrt((F*c)**2+(O*f)**2)/1e3)),x=p[F][O],x>0&&(C=4*(t*e+b),S+=x,_+=x*n[C],M+=x*n[C+1],T+=x*n[C+2],k+=x*n[C+3]))}C=4*(w*s+y),o[C]=_/S,o[C+1]=M/S,o[C+2]=T/S,o[C+3]=k/S}return++y<s?t(y):h}(0)}bilinearFiltering(t,e,i,s,r){let n,h,o,a,l,u,c,f,d,g,p,m,v,y=0,w=this.rcpScaleX,b=this.rcpScaleY,x=4*(e-1),C=t.imageData.data,S=t.ctx.createImageData(s,r),_=S.data;for(c=0;c<r;c++)for(f=0;f<s;f++)for(l=Math.floor(w*f),u=Math.floor(b*c),d=w*f-l,g=b*c-u,v=4*(u*e+l),p=0;p<4;p++)n=C[v+p],h=C[v+4+p],o=C[v+x+p],a=C[v+x+4+p],m=n*(1-d)*(1-g)+h*d*(1-g)+o*g*(1-d)+a*d*g,_[y++]=m;return S}hermiteFastResize(t,e,i,s,r){let n=this.rcpScaleX,h=this.rcpScaleY,o=Math.ceil(n/2),a=Math.ceil(h/2),l=t.imageData.data,u=t.ctx.createImageData(s,r),c=u.data;for(let t=0;t<r;t++)for(let i=0;i<s;i++){let r,u=4*(i+t*s),f=0,d=0,g=0,p=0,m=0,v=0,y=(t+.5)*h;for(let s=Math.floor(t*h);s<(t+1)*h;s++){let t=Math.abs(y-(s+.5))/a,h=(i+.5)*n,u=t*t;for(let t=Math.floor(i*n);t<(i+1)*n;t++){let i=Math.abs(h-(t+.5))/o,n=Math.sqrt(u+i*i);n>1&&n<-1||(r=2*n*n*n-3*n*n+1,r>0&&(i=4*(t+s*e),v+=r*l[i+3],d+=r,l[i+3]<255&&(r=r*l[i+3]/250),g+=r*l[i],p+=r*l[i+1],m+=r*l[i+2],f+=r))}}c[u]=g/f,c[u+1]=p/f,c[u+2]=m/f,c[u+3]=v/d}return u}};Ct(Co,"type","Resize"),Ct(Co,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),Ct(Co,"uniformLocations",["uDelta","uTaps"]),ge.setClass(Co);var So=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uSaturation;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float rgMax = max(color.r, color.g);\n float rgbMax = max(rgMax, color.b);\n color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\n color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\n color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d({imageData:{data:t}}){let e=-this.saturation;for(let i=0;i<t.length;i+=4){let s=t[i],r=t[i+1],n=t[i+2],h=Math.max(s,r,n);t[i]+=h===s?0:(h-s)*e,t[i+1]+=h===r?0:(h-r)*e,t[i+2]+=h===n?0:(h-n)*e}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return 0===this.saturation}};Ct(So,"type","Saturation"),Ct(So,"defaults",{saturation:0}),Ct(So,"uniformLocations",["uSaturation"]),ge.setClass(So);var _o=class extends Jh{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uVibrance;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float max = max(color.r, max(color.g, color.b));\n float avg = (color.r + color.g + color.b) / 3.0;\n float amt = (abs(max - avg) * 2.0) * uVibrance;\n color.r += max != color.r ? (max - color.r) * amt : 0.00;\n color.g += max != color.g ? (max - color.g) * amt : 0.00;\n color.b += max != color.b ? (max - color.b) * amt : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d({imageData:{data:t}}){let e=-this.vibrance;for(let i=0;i<t.length;i+=4){let s=t[i],r=t[i+1],n=t[i+2],h=Math.max(s,r,n),o=2*Math.abs(h-(s+r+n)/3)/255*e;t[i]+=h===s?0:(h-s)*o,t[i+1]+=h===r?0:(h-r)*o,t[i+2]+=h===n?0:(h-n)*o}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return 0===this.vibrance}};function Mo(){return crypto.randomUUID()}async function To(t,e,i="contain"){const s=await async function(t){if(t.startsWith("data:")||t.startsWith("blob:"))return Gh.fromURL(t);try{return await Gh.fromURL(t,{crossOrigin:"anonymous"})}catch{}try{const e=`http://localhost:3001/?url=${encodeURIComponent(t)}`;return await Gh.fromURL(e,{crossOrigin:"anonymous"})}catch{}return Gh.fromURL(t)}(e),r=t.getWidth(),n=t.getHeight();let h,o;if("fill"===i)h=r/(s.width??r),o=n/(s.height??n);else{const e=s.width??r,a=s.height??n,l="contain"===i?Math.min(r/e,n/a):Math.max(r/e,n/a);h=l,o=l,"contain"===i&&t.setDimensions({width:e*l,height:a*l})}const a=t.getWidth(),l=t.getHeight();s.set({scaleX:h,scaleY:o,originX:"center",originY:"center",left:a/2,top:l/2,selectable:!1,evented:!1,excludeFromExport:!0});const u=t.getObjects().find((t=>!0===t._isBackground));void 0!==u&&t.remove(u),s._isBackground=!0,t.insertAt(0,s),t.renderAll()}function ko(t,e,i){return[{x:t.topLeft.x*e,y:t.topLeft.y*i},{x:t.topRight.x*e,y:t.topRight.y*i},{x:t.bottomRight.x*e,y:t.bottomRight.y*i},{x:t.bottomLeft.x*e,y:t.bottomLeft.y*i}]}function Fo(t,e,i,s=0){return{topLeft:{x:t[0].x/e,y:t[0].y/i},topRight:{x:t[1].x/e,y:t[1].y/i},bottomRight:{x:t[2].x/e,y:t[2].y/i},bottomLeft:{x:t[3].x/e,y:t[3].y/i},...0!==s?{bulge:s}:{}}}function Oo(){return{topLeft:{x:.35,y:.325},topRight:{x:.65,y:.325},bottomRight:{x:.65,y:.675},bottomLeft:{x:.35,y:.675}}}function Do(t,e,i,s,r){const[n,h,o,a]=ko(i,s,r),l=(n.x+h.x+o.x+a.x)/4,u=(n.y+h.y+o.y+a.y)/4,c=(Math.hypot(h.x-n.x,h.y-n.y)+Math.hypot(o.x-a.x,o.y-a.y))/2,f=(Math.hypot(a.x-n.x,a.y-n.y)+Math.hypot(o.x-h.x,o.y-h.y))/2,d=180*Math.atan2(o.y-a.y,o.x-a.x)/Math.PI,g=Math.min(c/t,f/e);return{x:l,y:u,scaleX:g,scaleY:g,angle:d}}function $o(t,e,i,s){const r=t.width,n=t.height,h=Math.ceil(Math.abs(.5*e*i/s))+1,o=document.createElement("canvas");o.width=r,o.height=n+2*h;const a=o.getContext("2d");for(let o=0;o<r;o++){const l=r>1?o/(r-1):.5;a.drawImage(t,o,0,1,n,o,h+-2*l*(1-l)*e*i/s,1,n)}return o}function jo(t){if(!t.startsWith("data:image/svg+xml"))return null;const e=t.indexOf(";base64,");if(-1!==e)return atob(t.slice(e+8));const i=t.indexOf(",");return-1===i?null:decodeURIComponent(t.slice(i+1))}function Ao(t){const e=jo(t);if(null===e)return null;const i=e.match(/\bwidth=["']([.\d]+)/),s=e.match(/\bheight=["']([.\d]+)/);if(null!==i&&null!==s)return{width:Math.round(parseFloat(i[1])),height:Math.round(parseFloat(s[1]))};const r=e.match(/viewBox=["']\s*[\d.]+\s+[\d.]+\s+([\d.]+)\s+([\d.]+)/);return null!==r?{width:Math.round(parseFloat(r[1])),height:Math.round(parseFloat(r[2]))}:null}function Eo(t,e=4e3){const i=jo(t);if(null===i)return{dataUrl:t,scaleApplied:1};const s=(new DOMParser).parseFromString(i,"image/svg+xml"),r=s.documentElement;if("svg"!==r.tagName)return{dataUrl:t,scaleApplied:1};const n=r.getAttribute("viewBox");let h,o;if(null!==n){const t=n.trim().split(/[\s,]+/);h=parseFloat(t[2])||0,o=parseFloat(t[3])||0}else h=parseFloat(r.getAttribute("width")||"")||0,o=parseFloat(r.getAttribute("height")||"")||0;if(h<=0||o<=0)return{dataUrl:t,scaleApplied:1};const a=Math.max(h,o);if(a>=e)return{dataUrl:t,scaleApplied:1};const l=e/a,u=Math.round(h*l),c=Math.round(o*l);r.setAttribute("width",String(u)),r.setAttribute("height",String(c)),null===n&&r.setAttribute("viewBox",`0 0 ${h} ${o}`);const f=(new XMLSerializer).serializeToString(s),d=(new TextEncoder).encode(f);let g="";for(let t=0;t<d.length;t++)g+=String.fromCharCode(d[t]);return{dataUrl:"data:image/svg+xml;base64,"+btoa(g),scaleApplied:l}}async function Po(t,e=1){const i=jo(t);if(null===i)return t;const s=(new DOMParser).parseFromString(i,"image/svg+xml"),r=s.documentElement;if("svg"!==r.tagName)return t;const n=document.createElement("div");let h;n.style.cssText="visibility:hidden;position:absolute;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden",n.appendChild(r),document.body.appendChild(n);try{h=r.getBBox()}catch{return n.remove(),t}if(n.remove(),h.width<=0||h.height<=0)return t;const o=r.getAttribute("viewBox");if(null!==o){const e=o.trim().split(/[\s,]+/).map(Number);if(4===e.length&&Math.abs(e[0]-h.x)<1&&Math.abs(e[1]-h.y)<1&&Math.abs(e[2]-h.width)<1&&Math.abs(e[3]-h.height)<1)return t}r.setAttribute("viewBox",`${h.x-e} ${h.y-e} ${h.width+2*e} ${h.height+2*e}`);const a=h.height+2*e;r.setAttribute("width",String(h.width+2*e)),r.setAttribute("height",String(a)),r.parentNode!==s&&s.appendChild(r);const l=(new XMLSerializer).serializeToString(s),u=(new TextEncoder).encode(l);let c="";for(let t=0;t<u.length;t++)c+=String.fromCharCode(u[t]);return"data:image/svg+xml;base64,"+btoa(c)}Ct(_o,"type","Vibrance"),Ct(_o,"defaults",{vibrance:0}),Ct(_o,"uniformLocations",["uVibrance"]),ge.setClass(_o);export{a as H,xr as J,be as N,pt as a,mt as b,gt as c,A as d,To as e,Mo as f,b as g,Do as h,Ph as i,zn as j,F as k,$o as l,Po as m,Ao as n,Oo as o,ko as p,Fo as q,yt as r,x as s,wt as t,Eo as u,Qs as v,Gh as w}
|