fabric-layers-core
Version:
A fabric.js coordinate-plane (grid) & layers library
14 lines • 357 kB
JavaScript
/* @preserve
* fabric-layers 1.1.17, a fabric.js coordinate-plane (grid) & layers library. https://github.com/ajoslin103/fabric-layers-core#readme
* (c) 2025 fabric-layers contributors
* License: MIT
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FabricLayers={})}(this,function(t){"use strict";var e="1.1.17";function s(t,e,s){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,e);if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function i(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),s.push.apply(s,i)}return s}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function n(t,e){if(null==t)return{};var s,i,r=function(t,e){if(null==t)return{};var s={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(e.indexOf(i)>=0)continue;s[i]=t[i]}return s}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(i=0;i<n.length;i++)s=n[i],e.indexOf(s)>=0||{}.propertyIsEnumerable.call(t,s)&&(r[s]=t[s])}return r}function o(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}class a{constructor(){s(this,"browserShadowBlurConstant",1),s(this,"DPI",96),s(this,"devicePixelRatio","undefined"!=typeof window?window.devicePixelRatio:1),s(this,"perfLimitSizeTotal",2097152),s(this,"maxCacheSideLimit",4096),s(this,"minCacheSideLimit",256),s(this,"disableStyleCopyPaste",!1),s(this,"enableGLFiltering",!0),s(this,"textureSize",4096),s(this,"forceGLPutImageData",!1),s(this,"cachesBoundsOfCurve",!1),s(this,"fontPaths",{}),s(this,"NUM_FRACTION_DIGITS",4)}}const h=new class extends a{constructor(t){super(),this.configure(t)}configure(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(this,t)}addFonts(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.fontPaths=r(r({},this.fontPaths),t)}removeFonts(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).forEach(t=>{delete this.fontPaths[t]})}clearFonts(){this.fontPaths={}}restoreDefaults(t){const e=new a,s=(null==t?void 0:t.reduce((t,s)=>(t[s]=e[s],t),{}))||e;this.configure(s)}},c=function(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];return console[t]("fabric",...s)};class l extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class u extends l{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class d{}class g extends d{testPrecision(t,e){const s="precision ".concat(e," float;\nvoid main(){}"),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const 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(),c("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const f={};let p;const m=()=>p||(p={document:document,window:window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new g,dispose(){},copyPasteData:f}),v=()=>m().document,y=()=>m().window,x=()=>{var t;return Math.max(null!==(t=h.devicePixelRatio)&&void 0!==t?t:y().devicePixelRatio,1)},_=new class{constructor(){s(this,"charWidthsCache",{}),s(this,"boundsOfCurveCache",{})}getFontCache(t){let{fontFamily:e,fontStyle:s,fontWeight:i}=t;e=e.toLowerCase(),this.charWidthsCache[e]||(this.charWidthsCache[e]={});const r=this.charWidthsCache[e],n="".concat(s.toLowerCase(),"_").concat((i+"").toLowerCase());return r[n]||(r[n]={}),r[n]}clearFontCache(t){(t=(t||"").toLowerCase())?this.charWidthsCache[t]&&delete this.charWidthsCache[t]:this.charWidthsCache={}}limitDimsByArea(t){const{perfLimitSizeTotal:e}=h,s=Math.sqrt(e*t);return[Math.floor(s),Math.floor(e/s)]}},b="6.7.1";function w(){}const C=Math.PI/2,S=2*Math.PI,T=Math.PI/180,O=Object.freeze([1,0,0,1,0,0]),k=16,M=.4477152502,D="center",E="left",A="top",j="bottom",P="right",L="none",F=/\r?\n/,R="moving",B="scaling",I="rotating",W="rotate",X="skewing",Y="resizing",z="modifyPoly",V="modifyPath",G="changed",H="scale",N="scaleX",U="scaleY",q="skewX",K="skewY",Z="fill",Q="stroke",J="modified",$="json",tt="svg",et=new class{constructor(){this[$]=new Map,this[tt]=new Map}has(t){return this[$].has(t)}getClass(t){const e=this[$].get(t);if(!e)throw new l("No class registered for ".concat(t));return e}setClass(t,e){e?this[$].set(e,t):(this[$].set(t.type,t),this[$].set(t.type.toLowerCase(),t))}getSVGClass(t){return this[tt].get(t)}setSVGClass(t,e){this[tt].set(null!=e?e:t.type.toLowerCase(),t)}},st=new class extends Array{remove(t){const e=this.indexOf(t);e>-1&&this.splice(e,1)}cancelAll(){const t=this.splice(0);return t.forEach(t=>t.abort()),t}cancelByCanvas(t){if(!t)return[];const e=this.filter(e=>{var s;return e.target===t||"object"==typeof e.target&&(null===(s=e.target)||void 0===s?void 0:s.canvas)===t});return e.forEach(t=>t.abort()),e}cancelByTarget(t){if(!t)return[];const e=this.filter(e=>e.target===t);return e.forEach(t=>t.abort()),e}};class it{constructor(){s(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),"object"==typeof t)return Object.entries(t).forEach(t=>{let[e,s]=t;this.on(e,s)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if("object"==typeof t){const e=[];return Object.entries(t).forEach(t=>{let[s,i]=t;e.push(this.once(s,i))}),()=>e.forEach(t=>t())}if(e){const s=this.on(t,function(){for(var t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];e.call(this,...i),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(void 0===t)for(const t in this.__eventListeners)this._removeEventListener(t);else"object"==typeof t?Object.entries(t).forEach(t=>{let[e,s]=t;this._removeEventListener(e,s)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=null===(s=this.__eventListeners[t])||void 0===s?void 0:s.concat();if(i)for(let t=0;t<i.length;t++)i[t].call(this,e||{})}}const rt=(t,e)=>{const s=t.indexOf(e);return-1!==s&&t.splice(s,1),t},nt=t=>{if(0===t)return 1;switch(Math.abs(t)/C){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},ot=t=>{if(0===t)return 0;const e=t/C,s=Math.sign(t);switch(e){case 1:return s;case 2:return 0;case 3:return-s}return Math.sin(t)};class at{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new at(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new at(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new at(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new at(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new at(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new at(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new at(this.x/t.x,this.y/t.y)}scalarDivide(t){return new at(this.x/t,this.y/t)}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(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new at(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new at(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new at(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(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){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new at(this.x,this.y)}rotate(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ht;const s=ot(t),i=nt(t),r=this.subtract(e);return new at(r.x*i-r.y*s,r.x*s+r.y*i).add(e)}transform(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new at(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const ht=new at(0,0),ct=t=>!!t&&Array.isArray(t._objects);function lt(t){class e extends t{constructor(){super(...arguments),s(this,"_objects",[])}_onObjectAdded(t){}_onObjectRemoved(t){}_onStackOrderChanged(t){}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._objects.push(...e);return e.forEach(t=>this._onObjectAdded(t)),i}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];return this._objects.splice(t,0,...s),s.forEach(t=>this._onObjectAdded(t)),this._objects.length}remove(){const t=this._objects,e=[];for(var s=arguments.length,i=new Array(s),r=0;r<s;r++)i[r]=arguments[r];return i.forEach(s=>{const i=t.indexOf(s);-1!==i&&(t.splice(i,1),e.push(s),this._onObjectRemoved(s))}),e}forEachObject(t){this.getObjects().forEach((e,s,i)=>t(e,s,i))}getObjects(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return 0===e.length?[...this._objects]:this._objects.filter(t=>t.isType(...e))}item(t){return this._objects[t]}isEmpty(){return 0===this._objects.length}size(){return this._objects.length}contains(t,s){return!!this._objects.includes(t)||!!s&&this._objects.some(s=>s instanceof e&&s.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]||(rt(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),0))}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1]||(rt(this._objects,t),this._objects.push(t),this._onStackOrderChanged(t),0))}sendObjectBackwards(t,e){if(!t)return!1;const s=this._objects.indexOf(t);if(0!==s){const i=this.findNewLowerIndex(t,s,e);return rt(this._objects,t),this._objects.splice(i,0,t),this._onStackOrderChanged(t),!0}return!1}bringObjectForward(t,e){if(!t)return!1;const s=this._objects.indexOf(t);if(s!==this._objects.length-1){const i=this.findNewUpperIndex(t,s,e);return rt(this._objects,t),this._objects.splice(i,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(rt(this._objects,t),this._objects.splice(e,0,t),this._onStackOrderChanged(t),!0)}findNewLowerIndex(t,e,s){let i;if(s){i=e;for(let s=e-1;s>=0;--s)if(t.isOverlapping(this._objects[s])){i=s;break}}else i=e-1;return i}findNewUpperIndex(t,e,s){let i;if(s){i=e;for(let s=e+1;s<this._objects.length;++s)if(t.isOverlapping(this._objects[s])){i=s;break}}else i=e+1;return i}collectObjects(t){let{left:e,top:s,width:i,height:r}=t,{includeIntersecting:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[],a=new at(e,s),h=a.add(new at(i,r));for(let t=this._objects.length-1;t>=0;t--){const e=this._objects[t];e.selectable&&e.visible&&(n&&e.intersectsWithRect(a,h)||e.isContainedWithinRect(a,h)||n&&e.containsPoint(a)||n&&e.containsPoint(h))&&o.push(e)}return o}}return e}class ut extends it{_setOptions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(const e in t)this.set(e,t[e])}_setObject(t){for(const 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){const e=this.get(t);return"boolean"==typeof e&&this.set(t,!e),this}get(t){return this[t]}}function dt(t){return y().requestAnimationFrame(t)}let gt=0;const ft=()=>gt++,pt=()=>{const t=v().createElement("canvas");if(!t||void 0===t.getContext)throw new l("Failed to create `canvas` element");return t},mt=t=>{const e=pt();return e.width=t.width,e.height=t.height,e},vt=(t,e,s)=>t.toDataURL("image/".concat(e),s),yt=(t,e,s)=>new Promise((i,r)=>{t.toBlob(i,"image/".concat(e),s)}),xt=t=>t*T,_t=t=>t/T,bt=(t,e,s)=>new at(t).transform(e,s),wt=t=>{const e=1/(t[0]*t[3]-t[1]*t[2]),s=[e*t[3],-e*t[1],-e*t[2],e*t[0],0,0],{x:i,y:r}=new at(t[4],t[5]).transform(s,!0);return s[4]=-i,s[5]=-r,s},Ct=(t,e,s)=>[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],s?0:t[0]*e[4]+t[2]*e[5]+t[4],s?0:t[1]*e[4]+t[3]*e[5]+t[5]],St=(t,e)=>t.reduceRight((t,s)=>s&&t?Ct(s,t,e):s||t,void 0)||O.concat(),Tt=t=>{let[e,s]=t;return Math.atan2(s,e)},Ot=t=>{const e=Tt(t),s=Math.pow(t[0],2)+Math.pow(t[1],2),i=Math.sqrt(s),r=(t[0]*t[3]-t[2]*t[1])/i,n=Math.atan2(t[0]*t[2]+t[1]*t[3],s);return{angle:_t(e),scaleX:i,scaleY:r,skewX:_t(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},kt=function(t){return[1,0,0,1,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0]};function Mt(){let{angle:t=0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{x:e=0,y:s=0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=xt(t),r=nt(i),n=ot(i);return[r,n,-n,r,e?e-(r*e-n*s):0,s?s-(n*e+r*s):0]}const Dt=function(t){return[t,0,0,arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,0,0]},Et=t=>Math.tan(xt(t)),At=t=>[1,0,Et(t),1,0,0],jt=t=>[1,Et(t),0,1,0,0],Pt=t=>{let{scaleX:e=1,scaleY:s=1,flipX:i=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=t,a=Dt(i?-e:e,r?-s:s);return n&&(a=Ct(a,At(n),!0)),o&&(a=Ct(a,jt(o),!0)),a},Lt=t=>{const{translateX:e=0,translateY:s=0,angle:i=0}=t;let r=kt(e,s);i&&(r=Ct(r,Mt({angle:i})));const n=Pt(t);return(t=>t.every((t,e)=>t===O[e]))(n)||(r=Ct(r,n)),r},Ft=function(t){let{signal:e,crossOrigin:s=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(i,r){if(e&&e.aborted)return r(new u("loadImage"));const n=v().createElement("img");let o;e&&(o=function(t){n.src="",r(t)},e.addEventListener("abort",o,{once:!0}));const a=function(){n.onload=n.onerror=null,o&&(null==e||e.removeEventListener("abort",o)),i(n)};t?(n.onload=a,n.onerror=function(){o&&(null==e||e.removeEventListener("abort",o)),r(new l("Error loading ".concat(n.src)))},s&&(n.crossOrigin=s),n.src=t):a()})},Rt=function(t){let{signal:e,reviver:s=w}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((i,r)=>{const n=[];e&&e.addEventListener("abort",r,{once:!0}),Promise.all(t.map(t=>et.getClass(t.type).fromObject(t,{signal:e}).then(e=>(s(t,e),n.push(e),e)))).then(i).catch(t=>{n.forEach(t=>{t.dispose&&t.dispose()}),r(t)}).finally(()=>{e&&e.removeEventListener("abort",r)})})},Bt=function(t){let{signal:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((s,i)=>{const r=[];e&&e.addEventListener("abort",i,{once:!0});const n=Object.values(t).map(t=>t&&t.type&&et.has(t.type)?Rt([t],{signal:e}).then(t=>{let[e]=t;return r.push(e),e}):t),o=Object.keys(t);Promise.all(n).then(t=>t.reduce((t,e,s)=>(t[o[s]]=e,t),{})).then(s).catch(t=>{r.forEach(t=>{t.dispose&&t.dispose()}),i(t)}).finally(()=>{e&&e.removeEventListener("abort",i)})})},It=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce((e,s)=>(s in t&&(e[s]=t[s]),e),{})},Wt=(t,e)=>Object.keys(t).reduce((s,i)=>(e(t[i],i,t)&&(s[i]=t[i]),s),{}),Xt=(t,e)=>parseFloat(Number(t).toFixed(e)),Yt=t=>"matrix("+t.map(t=>Xt(t,h.NUM_FRACTION_DIGITS)).join(" ")+")",zt=t=>!!t&&void 0!==t.toLive,Vt=t=>!!t&&"function"==typeof t.toObject,Gt=t=>!!t&&void 0!==t.offsetX&&"source"in t,Ht=t=>!!t&&"multiSelectionStacking"in t;function Nt(t){const e=t&&Ut(t);let s=0,i=0;if(!t||!e)return{left:s,top:i};let r=t;const n=e.documentElement,o=e.body||{scrollLeft:0,scrollTop:0};for(;r&&(r.parentNode||r.host)&&(r=r.parentNode||r.host,r===e?(s=o.scrollLeft||n.scrollLeft||0,i=o.scrollTop||n.scrollTop||0):(s+=r.scrollLeft||0,i+=r.scrollTop||0),1!==r.nodeType||"fixed"!==r.style.position););return{left:s,top:i}}const Ut=t=>t.ownerDocument||null,qt=t=>{var e;return(null===(e=t.ownerDocument)||void 0===e?void 0:e.defaultView)||null},Kt=function(t,e,s){let{width:i,height:r}=s,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;t.width=i,t.height=r,n>1&&(t.setAttribute("width",(i*n).toString()),t.setAttribute("height",(r*n).toString()),e.scale(n,n))},Zt=(t,e)=>{let{width:s,height:i}=e;s&&(t.style.width="number"==typeof s?"".concat(s,"px"):s),i&&(t.style.height="number"==typeof i?"".concat(i,"px"):i)};function Qt(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect=L,t}class Jt{constructor(t){s(this,"_originalCanvasStyle",void 0),s(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&void 0!==s.getContext?t:t&&v().getElementById(t)||pt();var s;if(e.hasAttribute("data-fabric"))throw new l("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(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;Kt(s,i,t,e)}setCSSDimensions(t){Zt(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ut(t),i={left:0,top:0};if(!s)return i;const r=(null===(e=qt(t))||void 0===e?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(r.borderLeftWidth,10)||0,i.top+=parseInt(r.borderTopWidth,10)||0,i.left+=parseInt(r.paddingLeft,10)||0,i.top+=parseInt(r.paddingTop,10)||0;let n={left:0,top:0};const o=s.documentElement;void 0!==t.getBoundingClientRect&&(n=t.getBoundingClientRect());const a=Nt(t);return{left:n.left+a.left-(o.clientLeft||0)+i.left,top:n.top+a.top-(o.clientTop||0)+i.top}}(this.lower.el)}dispose(){m().dispose(this.lower.el),delete this.lower}}const $t={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...O]};class te extends(lt(ut)){get lowerCanvasEl(){var t;return null===(t=this.elements.lower)||void 0===t?void 0:t.el}get contextContainer(){var t;return null===(t=this.elements.lower)||void 0===t?void 0:t.ctx}static getDefaults(){return te.ownDefaults}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};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 Jt(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const r=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),r}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(c("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?x():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e){const e=r({width:this.width,height:this.height},t);this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const s=t,i=[...this.viewportTransform],r=bt(t,wt(i));i[0]=e,i[3]=e;const n=bt(r,i);i[4]+=s.x-n.x,i[5]+=s.y-n.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new at(0,0),t)}absolutePan(t){const e=[...this.viewportTransform];return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)}relativePan(t){return this.absolutePan(new at(-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=dt(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=wt(this.viewportTransform),i=bt({x:0,y:0},s),r=bt({x:t,y:e},s),n=i.min(r),o=i.max(r);return this.vptCoords={tl:n,tr:new at(o.x,n.y),bl:new at(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(function(t){y().cancelAnimationFrame(t)}(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),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){const s=this.viewportTransform;t.save(),t.transform(...s),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 s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],r=this.viewportTransform,n=this["".concat(e,"Vpt")];if(!s&&!i)return;const o=zt(s);if(s){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=o?s.toLive(t):s,n&&t.transform(...r),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const e=s.gradientTransform||s.patternTransform;e&&t.transform(...e)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:e}=this;this.skipOffscreen=n,n&&t.transform(...r),i.render(t),this.skipOffscreen=e,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new at(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new at(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new at(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 at(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new at(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return bt(this.getCenterPoint(),wt(this.viewportTransform))}_centerObject(t,e){t.setXY(e,D,D),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){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return r(r(r({version:b},It(this,e)),{},{objects:this._objects.filter(t=>!t.excludeFromExport).map(s=>this._toObject(s,t,e))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const r=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),r}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,r=this.overlayImage,n=this.backgroundColor,o=this.overlayColor;return zt(n)?n.excludeFromExport||(s.background=n.toObject(e)):n&&(s.background=n),zt(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),r&&!r.excludeFromExport&&(s.overlayImage=this._toObject(r,t,e)),s}toSVG(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,')" >\n')),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push("</g>\n"),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.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){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),r=h.NUM_FRACTION_DIGITS,n=e.viewBox;let o;if(n)o='viewBox="'.concat(n.x," ").concat(n.y," ").concat(n.width," ").concat(n.height,'" ');else if(this.svgViewportTransformation){const t=this.viewportTransform;o='viewBox="'.concat(Xt(-t[4]/t[0],r)," ").concat(Xt(-t[5]/t[3],r)," ").concat(Xt(this.width/t[0],r)," ").concat(Xt(this.height/t[3],r),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(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="',i,'" ',o,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",b,"</desc>\n","<defs>\n",this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),"</defs>\n")}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(ft()),'<clipPath id="'.concat(e.clipPathId,'" >\n').concat(e.toClipPathSVG(t.reviver),"</clipPath>\n")):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(zt(e)){const s=this["".concat(t,"Vpt")],i=this.viewportTransform,r={isType:()=>!1,width:this.width/(s?i[0]:1),height:this.height/(s?i[3]:1)};return e.toSVG(r,{additionalTransform:s?Yt(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=h.fontPaths;this._objects.forEach(function e(s){t.push(s),ct(s)&&s._objects.forEach(e)}),t.forEach(t=>{if(!(i=t)||"function"!=typeof i._renderText)return;var i;const{styles:r,fontFamily:n}=t;!e[n]&&s[n]&&(e[n]=!0,r&&Object.values(r).forEach(t=>{Object.values(t).forEach(t=>{let{fontFamily:i=""}=t;!e[i]&&s[i]&&(e[i]=!0)})}))});const i=Object.keys(e).map(t=>"\t\t@font-face {\n\t\t\tfont-family: '".concat(t,"';\n\t\t\tsrc: url('").concat(s[t],"');\n\t\t}\n")).join("");return i?'\t<style type="text/css"><![CDATA[\n'.concat(i,"]]></style>\n"):""}_setSVGObjects(t,e){this.forEachObject(s=>{s.excludeFromExport||this._setSVGObject(t,s,e)})}_setSVGObject(t,e,s){t.push(e.toSVG(s))}_setSVGBgOverlayImage(t,e,s){const i=this[e];i&&!i.excludeFromExport&&i.toSVG&&t.push(i.toSVG(s))}_setSVGBgOverlayColor(t,e){const s=this["".concat(e,"Color")];if(s)if(zt(s)){const i=s.repeat||"",r=this.width,n=this.height,o=this["".concat(e,"Vpt")]?Yt(wt(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(r/2,",").concat(n/2,')" x="').concat(s.offsetX-r/2,'" y="').concat(s.offsetY-n/2,'" width="').concat("repeat-y"!==i&&"no-repeat"!==i||!Gt(s)?r:s.source.width,'" height="').concat("repeat-x"!==i&&"no-repeat"!==i||!Gt(s)?n:s.source.height,'" fill="url(#SVGID_').concat(s.id,')"></rect>\n'))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',s,'"',"></rect>\n")}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return Promise.reject(new l("`json` is undefined"));const i="string"==typeof t?JSON.parse(t):t,{objects:r=[],backgroundImage:n,background:o,overlayImage:a,overlay:h,clipPath:c}=i,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([Rt(r,{reviver:e,signal:s}),Bt({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:h,clipPath:c},{signal:s})]).then(t=>{let[e,s]=t;return this.clear(),this.add(...e),this.set(i),this.set(s),this.renderOnAddRemove=u,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=mt(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:r=!1}=t,n=i*(r?this.getRetinaScaling():1);return vt(this.toCanvasElement(n,t),e,s)}toBlob(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:r=!1}=t,n=i*(r?this.getRetinaScaling():1);return yt(this.toCanvasElement(n,t),e,s)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,{width:e,height:s,left:i,top:r,filter:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=(e||this.width)*t,a=(s||this.height)*t,h=this.getZoom(),c=this.width,l=this.height,u=this.skipControlsDrawing,d=h*t,g=this.viewportTransform,f=[d,0,0,d,(g[4]-(i||0))*t,(g[5]-(r||0))*t],p=this.enableRetinaScaling,m=mt({width:o,height:a}),v=n?this._objects.filter(t=>n(t)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=f,this.width=o,this.height=a,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(m.getContext("2d"),v),this.viewportTransform=g,this.width=c,this.height=l,this.calcViewportBoundaries(),this.enableRetinaScaling=p,this.skipControlsDrawing=u,m}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),st.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}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 (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}s(te,"ownDefaults",$t);const ee=["touchstart","touchmove","touchend"],se=t=>ee.includes(t.type)||"touch"===t.pointerType,ie=t=>{t.preventDefault(),t.stopPropagation()},re=t=>{let e=0,s=0,i=0,r=0;for(let n=0,o=t.length;n<o;n++){const{x:o,y:a}=t[n];(o>i||!n)&&(i=o),(o<e||!n)&&(e=o),(a>r||!n)&&(r=a),(a<s||!n)&&(s=a)}return{left:e,top:s,width:i-e,height:r-s}},ne=["translateX","translateY","scaleX","scaleY"],oe=(t,e)=>{const s=Ot(e),{translateX:i,translateY:r,scaleX:o,scaleY:a}=s,h=n(s,ne),c=new at(i,r);t.flipX=!1,t.flipY=!1,Object.assign(t,h),t.set({scaleX:o,scaleY:a}),t.setPositionByOrigin(c,D,D)},ae=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}),he=(t,e,s)=>{const i=t/2,r=e/2,n=[new at(-i,-r),new at(i,-r),new at(-i,r),new at(i,r)].map(t=>t.transform(s)),o=re(n);return new at(o.width,o.height)},ce=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:O;return Ct(wt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:O),t)},le=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:O;return t.transform(ce(e,s))},ue=(t,e)=>{var s;const{transform:{target:i}}=e;null===(s=i.canvas)||void 0===s||s.fire("object:".concat(t),r(r({},e),{},{target:i})),i.fire(t,e)},de={left:-.5,top:-.5,center:0,bottom:.5,right:.5},ge=t=>"string"==typeof t?de[t]:t-.5,fe="not-allowed";function pe(t){return ge(t.originX)===ge(D)&&ge(t.originY)===ge(D)}function me(t){return.5-ge(t)}const ve=(t,e)=>t[e],ye=(t,e,s,i)=>({e:t,transform:e,pointer:new at(s,i)});function xe(t,e){const s=t.getTotalAngle()+_t(Math.atan2(e.y,e.x))+360;return Math.round(s%360/45)}function _e(t,e,s,i,r){var n;let{target:o,corner:a}=t;const h=o.controls[a],c=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/c,u=function(t,e,s,i){const r=t.getRelativeCenterPoint(),n=void 0!==s&&void 0!==i?t.translateToGivenOrigin(r,D,D,s,i):new at(t.left,t.top);return(t.angle?e.rotate(-xt(t.angle),r):e).subtract(n)}(o,new at(i,r),e,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-=h.offsetX,u.y-=h.offsetY,u}const be=(t,e,s,i)=>{const{target:r,offsetX:n,offsetY:o}=e,a=s-n,h=i-o,c=!ve(r,"lockMovementX")&&r.left!==a,l=!ve(r,"lockMovementY")&&r.top!==h;return c&&r.set(E,a),l&&r.set(A,h),(c||l)&&ue(R,ye(t,e,s,i)),c||l},we={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"},Ce=(t,e,s)=>(s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+(e-t)*(2/3-s)*6:t),Se=(t,e,s,i)=>{t/=255,e/=255,s/=255;const r=Math.max(t,e,s),n=Math.min(t,e,s);let o,a;const h=(r+n)/2;if(r===n)o=a=0;else{const i=r-n;switch(a=h>.5?i/(2-r-n):i/(r+n),r){case t:o=(e-s)/i+(e<s?6:0);break;case e:o=(s-t)/i+2;break;case s:o=(t-e)/i+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*h),i]},Te=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"1";return parseFloat(t)/(t.endsWith("%")?100:1)},Oe=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),ke=t=>{let[e,s,i,r=1]=t;const n=Math.round(.3*e+.59*s+.11*i);return[n,n,n,r]};class Me{constructor(t){if(s(this,"isUnrecognised",!1),t)if(t instanceof Me)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,r=1]=t;this.setSource([e,s,i,r])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in we&&(t=we[t]),"transparent"===t?[255,255,255,0]:Me.sourceFromHex(t)||Me.sourceFromRgb(t)||Me.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=Se(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Se(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,i]=this.getSource();return"".concat(Oe(t)).concat(Oe(e)).concat(Oe(s)).concat(Oe(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(ke(this.getSource())),this}toBlackWhite(t){const[e,,,s]=ke(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof Me||(t=new Me(t));const e=this.getSource(),s=t.getSource(),[i,r,n]=e.map((t,e)=>Math.round(.5*t+.5*s[e]));return this.setSource([i,r,n,e[3]]),this}static fromRgb(t){return Me.fromRgba(t)}static fromRgba(t){return new Me(Me.sourceFromRgb(t))}static sourceFromRgb(t){const e=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){const[t,s,i]=e.slice(1,4).map(t=>{const e=parseFloat(t);return t.endsWith("%")?Math.round(2.55*e):e});return[t,s,i,Te(e[4])]}}static fromHsl(t){return Me.fromHsla(t)}static fromHsla(t){return new Me(Me.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.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(!e)return;const s=(Me.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,r=parseFloat(e[3])/100;let n,o,a;if(0===i)n=o=a=r;else{const t=r<=.5?r*(i+1):r+i-r*i,e=2*r-t;n=Ce(e,t,s+1/3),o=Ce(e,t,s),a=Ce(e,t,s-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*a),Te(e[4])]}static fromHex(t){return new Me(Me.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(t=>t+t):e.match(/.{2}/g);const[i,r,n,o=255]=s.map(t=>parseInt(t,16));return[i,r,n,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?_t(s):e.includes("turn")?360*s:s}}const De=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;const s=/\D{0,2}$/.exec(t),i=parseFloat(t),r=h.DPI;switch(null==s?void 0:s[0]){case"mm":return i*r/25.4;case"cm":return i*r/2.54;case"in":return i*r;case"pt":return i*r/72;case"pc":return i*r/72*12;case"em":return i*e;default:return i}},Ee=function(t,e){let s,i,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(e)if(e.toLive)s="url(#SVGID_".concat(e.id,")");else{const t=new Me(e),r=t.getAlpha();s=t.toRgb(),1!==r&&(i=r.toString())}else s="none";return r?"".concat(t,": ").concat(s,"; ").concat(i?"".concat(t,"-opacity: ").concat(i,"; "):""):"".concat(t,'="').concat(s,'" ').concat(i?"".concat(t,'-opacity="').concat(i,'" '):"")};class Ae{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):L,r=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",h=void 0!==this.opacity?this.opacity:"1",c=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),u=Ee(Z,this.fill);return[Ee(Q,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",u,"fill-rule: ",e,"; ","opacity: ",h,";",l,c].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(Yt(s));return"".concat(i).concat(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){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),r=t.indexOf("COMMON_PARTS");return t[r]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=i?'style="'.concat(this.getSvgFilter(),'" '):"",a=this.clipPath,h=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",c=a&&a.absolutePositioned,l=this.stroke,u=this.fill,d=this.shadow,g=[],f=t.indexOf("COMMON_PARTS");let p;a&&(a.clipPathId="CLIPPATH_".concat(ft()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(s),"</clipPath>\n")),c&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),c?"":o+this.getSvgCommons()," >\n");const m=[n,h,e?"":this.addPaintOrder()," ",r?'transform="'.concat(r,'" '):""].join("");return t[f]=m,zt(u)&&g.push(u.toSVG(this)),zt(l)&&g.push(l.toSVG(this)),d&&g.push(d.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),c&&g.push("</g>\n"),s?s(g.join("")):g.join("")}addPaintOrder(){return this.paintFirst!==Z?' paint-order="'.concat(this.paintFirst,'" '):""}}function je(t){return new RegExp("^("+t.join("|")+")\\b","i")}const Pe="textDecorationThickness",Le=["fontSize","fontWeight","fontFamily","fontStyle"],Fe=["underline","overline","linethrough"],Re=[...Le,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],Be=[...Re,...Fe,"textBackgroundColor","direction",Pe],Ie=[...Le,...Fe,Q,"strokeWidth",Z,"deltaY","textBackgroundColor",Pe],We={_reNewline:F,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:E,fontStyle:"normal",lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:E,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,[Pe]:66.667},Xe="justify",Ye="justify-left",ze="justify-right",Ve="justify-center";var Ge,He,Ne;const Ue=String.raw(Ge||(Ge=o(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),qe=String.raw(He||(He=o(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),Ke=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Ue+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Ue+"))?\\s+(.*)"),Ze={cx:E,x:E,r:"radius",cy:A,y:A,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":Pe},Qe="font-size",Je="clip-path";je(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),je(["symbol","image","marker","pattern","view","svg"]);const $e=je(["symbol","g","a","svg","clipPath","defs"]);new RegExp(String.raw(Ne||(Ne=o(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Ue,qe,Ue,qe,Ue,qe,Ue));const ts=new at(1,0),es=new at,ss=(t,e)=>t.rotate(e),is=(t,e)=>new at(e).subtract(t),rs=t=>t.distanceFrom(es),ns=(t,e)=>Math.atan2(hs(t,e),cs(t,e)),os=t=>t.eq(es)?t:t.scalarDivide(rs(t)),as=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return os(new at(-t.y,t.x).scalarMultiply(e?1:-1))},hs=(t,e)=>t.x*e.y-t.y*e.x,cs=(t,e)=>t.x*e.x+t.y*e.y,ls=(t,e,s)=>{if(t.eq(e)||t.eq(s))return!0;const i=hs(e,s),r=hs(e,t),n=hs(s,t);return i>=0?r>=0&&n<=0:!(r<=0&&n>=0)},us="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",ds=new RegExp("(?:\\s|^)"+us+us+"("+Ue+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class gs{constructor(t){const e="string"==typeof t?gs.parseShadow(t):t;Object.assign(this,gs.ownDefaults,e),this.id=ft()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,r=0]=(ds.exec(e)||[]).map(t=>parseFloat(t)||0);return{color:(e.replace(ds,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:i,blur:r}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=ss(new at(this.offsetX,this.offsetY),xt(-t.angle)),s=new Me(this.color);let i=40,r=40;return t.width&&t.height&&(i=100*Xt((Math.abs(e.x)+this.blur)/t.width,h.NUM_FRACTION_DIGITS)+20,r=100*Xt((Math.abs(e.y)+this.blur)/t.height,h.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(r,'%" height="').concat(100+2*r,'%" x="-').concat(i,'%" width="').concat(100+2*i,'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="').concat(Xt(this.blur?this.blur/2:0,h.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(Xt(e.x,h.NUM_FRACTION_DIGITS),'" dy="').concat(Xt(e.y,h.NUM_FRACTION_DIGITS),'" result="oBlur" ></feOffset>\n\t<feFlood flood-color="').concat(s.toRgb(),'" flood-opacity="').concat(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(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=gs.ownDefaults;return this.includeDefaultValues?t:Wt(t,(t,s)=>t!==e[s])}static async fromObject(t){return new this(t)}}s(gs,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),s(gs,"type","shadow"),et.setClass(gs,"shadow");const fs=(t,e,s)=>Math.max(t,Math.min(e,s)),ps=[A,E,N,U,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",q,K],ms=[Z,Q,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],vs={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:E,originY:A,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Z,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},ys=(t,e,s,i)=>-s*Math.cos(t/i*C)+s+e,xs=()=>!1;class _s{constructor(t){let{startValue:e,byValue:i,duration:r=500,delay:n=0,easing:o=ys,onStart:a=w,onChange:h=w,onComplete:c=w,abort:l=xs,target:u}=t;s(this,"_state","pending"),s(this,"durationProgress",0),s(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=r,this.delay=n,this.easing=o,this._onStart=a,this._onChange=h,this._onComplete=c,this._abort=l,this.target=u,this.startValue=e,this.byValue=i,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(){const t=t=>{"pending"===this._state&&(this.startTime=t||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>dt(t),this.delay):dt(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:i,valueProgress:r}=this.calculate(s);this.value=Object.freeze(i),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._onChange(this.value,this.valueProgress,this.durationProgress),dt(this.tick)))}register(){st.push(this)}unregister(){st.remove(this)}abort(){this._state="aborted",this.unregister()}}const bs=["startValue","endValue"];class ws extends _s{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(r(r({},n(t,bs)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Cs=["startValue","endValue"];class Ss extends _s{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(r(r({},n(t,Cs)),{},{startValue:e,byValue:s.map((t,s)=>t-e[s])}))}calculate(t){const e=this.startValue.map((e,s)=>this.easing(t,e,this.byValue[s],this.duration,s));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const Ts=["startValue","endValue","easing","onChange","onComplete","abort"],Os=(t,e,s,i)=>e+s*(1-Math.cos(t/i*C)),ks=t=>t&&((e,s,i)=>t(new Me(e).toRgba(),s,i));class Ms extends _s{constructor(t){let{startValue:e,endValue:s,easing:i=Os,onChange:o,onComplete:a,abort:h}=t,c=n(t,Ts);const l=new Me(e).getSource(),u=new Me(s).getSource();super(r(r({},c),{},{startValue:l,byValue:u.map((t,e)=>t-l[e]),easing:i,onChange:ks(o),onComplete:ks(a),abort:ks(h)}))}calculate(t){const[e,s,i,r]=this.startValue.map((e,s)=>this.easing(t,e,this.byValue[s],this.duration,s)),n=[...[e,s,i].map(Math.round),fs(0,r,1)];return{value:n,valueProgress:n.map((t,e)=>0!==this.byValue[e]?Math.abs((t-this.startValue[e])/this.byValue[e]):0).find(t=>0!==t)||0}}}function Ds(t){const e=(t=>Array.isArray(t.startValue)||Array.isArray(t.endValue))(t)?new Ss(t):new ws(t);return e.start(),e}class Es{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(t=>!this.includes(t))),this}static isPointContained(t,e,s){let i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const r=is(e,s),n=is(e,t).divide(r);return i?Math.abs(n.x)===Math.abs(n.y):n.x===n.y&&n.x>=0&&n.x<=1}}static isPointInPolygon(t,e){const s=new at(t).setX(Math.min(t.x-1,...e.map(t=>t.x)));let i=0;for(let r=0;r<e.length;r++){const n=this.intersectSegmentSegment(e[r],e[(r+1)%e.length],t,s);if(n.includes(t))return!0;i+=Number("Intersection"===n.status)}return i%2==1}static intersectLineLine(t,e,s,i){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],n=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];const o=e.x-t.x,a=e.y-t.y,h=i.x-s.x,c=i.y-s.y,l=t.x-s.x,u=t.y-s.y,d=h*u-c*l,g=o*u-a*l,f=c*o-h*a;if(0!==f){const e=d/f,s=g/f;return(r||0<=e&&e<=1)&&(n||0<=s&&s<=1)?new Es("Intersection").append(new at(t.x+e*o,t.y+e*a)):new Es}if(0===d||0===g){const o=r||n||Es.isPointContained(t,s,i)||Es.isPointContained(e,s,i)||Es.isPointContained(s,t,e)||Es.isPointContained(i,t,e);return new Es(o?"Coincident":void 0)}return new Es("Parallel")}static intersectSegmentLine(t,e,s,i){return Es.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Es.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];const r=new Es,n=s.length;for(let o,a,h,c=0;c<n;c++){if(o=s[c],a=s[(c+1)%n],h=Es.intersectLineLine(t,e,o,a,i,!1),"Coincident"===h.status)return h;r.append(...h.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectSegmentPolygon(t,e,s){return Es.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Es,i=t.length,r=[];for(let n=0;n<i;n++){const o=t[n],a=t[(n+1)%i],h=Es.intersectSegmentPolygon(o,a,e);"Coincident"===h.status?(r.push(h),s.append(o,a)):s.append(...h.points)}return r.length>0&&r.length===t.length?new Es("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),r=e.max(s),n=new at(r.x,i.y),o=new at(i.x,r.y);return Es.intersectPolygonPolygon(t,[i,n,r,o])}}class As extends ut{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(){const t=this.getRelativeXY();return this.group?bt(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=bt(t,wt(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new at(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.originX,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),r=[t,e,s,i];if(this.group){const t=this.group.calcTransformMatrix();return r.map(e=>bt(e,t))}return r}intersectsWithRect(t,e){return"Intersection"===Es.intersectPolygonRectangle(this.getCoords(),t,e).status}intersectsWithObject(t){const e=Es.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){const{left:s,top:i,width:r,height:n}=this.getBoundingRect();return s>=t.x&&s+r<=e.x&&i>=t.y&&i+n<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Es.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.intersectsWithRect(t,e)||this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return re(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(N,t),this._set(U,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?_t(Tt(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||O.concat()}calcACoords(){const t=Mt({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=kt(e,s),r=Ct(i,t),n=this._getTransformedDimensions(),o=n.x/2,a=n.y/2;return{tl:bt({x:-o,y:-a},r),tr:bt({x:o,y:-a},r),bl:bt({x:-o,y:a},r),br:bt({x:o,y:a},r)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],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,ge(this.originX),ge(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((t,e)=>t===s[e])?i.value:(this.group&&(e=Ct(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},r=Lt(i);return this.ownMatrixCache={key:t,value:r},r}_getNonTransformedDimensions(){return new at(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=r({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const o=e.width+i,a=e.height+i;let h;return h=0===e.skewX&&0===e.skewY?new at(o*e.scaleX,a*e.scaleY):he(o,a,Pt(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,r){let n=t.x,o=t.y;const a=ge(i)-ge(e),h=ge(r)-ge(s);if(a||h){const t=this._getTransformedDimensions();n+=a*t.x,o+=h*t.y}return new at(n,o)}translateToCenterPoint(t,e,s){if(e===D&&s===D)return t;const i=this.translateToGivenOrigin(t,e,s,D,D);return this.angle?i.rotate(xt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,D,D,e,s);return this.angle?i.rotate(xt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?bt(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new at(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),r=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:r.x,top:r.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),E,A)}}const js=["type"],Ps=["extraParam"];let Ls=class t extends As{static getDefaults(){return t.ownDefaults}get type(){const t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){c("warn","Setting type has no effect",t)}constructor(e){super(),s(this,"_cacheContext",null),Object.assign(this,t.ownDefaults),this.setOptions(e)}_createCacheCanvas(){this._cacheCanvas=pt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=h.maxCacheSideLimit,r=h.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=h.perfLimitSizeTotal)return e<r&&(t.width=r),s<r&&(t.height=r),t;const n=e/s,[o,a]=_.limitDimsByArea(n),c=fs(r,o,i),l=fs(r,a,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>l&&(t.zoomY/=s/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:r,zoomY:n,x:o,y:a}=this._limitCacheSize(this._getCacheCanvasDimensions()),h=s!==t.width||i!==t.height,c=this.zoomX!==r||this.zoomY!==n;if(!t||!e)return!1;if(h||c){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const h=o/2,c=a/2;return this.cacheTranslationX=Math.round(t.width/2-h)+h,this.cacheTranslationY=Math.round(t.height/2-c)+c,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(r,n),this.zoomX=r,this.zoomY=n,!0}return!1}setOptions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new at(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=Ot(this.calcTransformMatrix());return new at(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}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){t!==N&&t!==U||(e=this._constrainScale(e)),t===N&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof gs||(e=new gs(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&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){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:r}=this,{width:n,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:r,width:n,height:o,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!!(this.paintFirst===Q&&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,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,r=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=r}createClipPathLayer(t,e){const s=mt(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(t=>{t.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const t=wt(this.calcTransformMatrix());i.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const 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){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,zt(s)?"percentage"===s.gradientUnits||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(zt(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_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;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[r,,,n]=(null==s?void 0:s.viewportTransform)||O,o=r*i,a=n*i,c=e.nonScaling?new at(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*h.browserShadowBlurConstant*(o+a)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*a*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!zt(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-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,i,r):t.transform(1,0,0,1,i,r),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:r}}_renderPaintInOrder(t){this.paintFirst===Q?(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){const 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 s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),r=this.getCanvasRetinaScaling(),n=i.x/this.scaleX/r,o=i.y/this.scaleY/r,a=mt({width:Math.ceil(n),height:Math.ceil(o)}),h=a.getContext("2d");h&&(h.beginPath(),h.moveTo(0,0),h.lineTo(n,0),h.lineTo(n,o),h.lineTo(0,o),h.closePath(),h.translate(n/2,o/2),h.scale(i.zoomX/this.scaleX/r,i.zoomY/this.scaleY/r),this._applyPatternGradientTransform(h,e),h.fillStyle=e.toLive(t),h.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/i.zoomX,r*this.scaleY/i.zoomY),t.strokeStyle=null!==(s=h.createPattern(a,"no-repeat"))&&void 0!==s?s:"")}_findCenterFromElement(){return new at(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(et.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=ae(this),s=this.group,i=this.shadow,r=Math.abs,n=t.enableRetinaScaling?x():1,o=(t.multiplier||1)*n,a=t.canvasProvider||(t=>new te(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,s)=>{const i=ce(e,s);oe(t,Ct(i,t.calcOwnMatrix()))})(this,this.getViewportTransform()),this.setCoords();const h=pt(),c=this.getBoundingRect(),l=this.shadow,u=new at;if(l){const t=l.blur,e=l.nonScaling?new at(1,1):this.getObjectScaling();u.x=2*Math.round(r(l.offsetX)+t)*r(e.x),u.y=2*Math.round(r(l.offsetY)+t)*r(e.y)}const d=c.width+u.x,g=c.height+u.y;h.width=Math.ceil(d),h.height=Math.ceil(g);const f=a(h);"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new at(f.width/2,f.height/2),D,D);const p=this.canvas;f._objects=[this],this.set("canvas",f),this.setCoords();const m=f.toCanvasElement(o||1,t);return this.set("canvas",p),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),f._objects=[],f.destroy(),m}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return vt(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return yt(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:t,y:e}=this.getRelativeCenterPoint();this.originX=D,this.originY=D,this.left=t,this.top=e}if(this.set("angle",t),e){const{x:t,y:e}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=t,this.top=e,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){st.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&m().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((t,s)=>{let[i,r]=s;return t[i]=this._animate(i,r,e),t},{})}_animate(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:o,startValue:a,onChange:h,onComplete:c}=s,l=r(r({},s),{},{target:this,startValue:null!=a?a:i.reduce((t,e)=>t[e],this),endValue:e,abort:null==o?void 0:o.bind(this),onChange:(t,e,s)=>{i.reduce((e,s,r)=>(r===i.length-1&&(e[s]=t),e[s]),this),h&&h(t,e,s)},onComplete:(t,e,s)=>{this.setCoords(),c&&c(t,e,s)}});return n?function(t){const e=new Ms(t);return e.start(),e}(l):Ds(l)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let 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()]};const e=this.getAncestors(),s=t.getAncestors();if(0===e.length&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,r=0;r<e.length;r++){if(i=e[r],i===t)return{fork:[this,...e.slice(0,r)],otherFork:[],common:e.slice(r)};for(let n=0;n<s.length;n++){if(this===s[n])return{fork:[],otherFork:[t,...s.slice(0,n)],common:[this,...e]};if(i===s[n])return{fork:[this,...e.slice(0,r)],otherFork:[t,...s.slice(0,n)],common:e.slice(r)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),r=e.otherFork.pop(),n=s._objects.indexOf(i),o=s._objects.indexOf(r);return n>-1&&n>o}toObject(){const e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).concat(t.customProperties,this.constructor.customProperties||[]);let s;const i=h.NUM_FRACTION_DIGITS,{clipPath:n,fill:o,stroke:a,shadow:c,strokeDashArray:l,left:u,top:d,originX:g,originY:f,width:p,height:m,strokeWidth:v,strokeLineCap:y,strokeDashOffset:x,strokeLineJoin:_,strokeUniform:w,strokeMiterLimit:C,scaleX:S,scaleY:T,angle:O,flipX:k,flipY:M,opacity:D,visible:E,backgroundColor:A,fillRule:j,paintFirst:P,globalCompositeOperation:L,skewX:F,skewY:R}=this;n&&!n.excludeFromExport&&(s=n.toObject(e.concat("inverted","absolutePositioned")));const B=t=>Xt(t,i),I=r(r({},It(this,e)),{},{type:this.constructor.type,version:b,originX:g,originY:f,left:B(u),top:B(d),width:B(p),height:B(m),fill:Vt(o)?o.toObject():o,stroke:Vt(a)?a.toObject():a,strokeWidth:B(v),strokeDashArray:l?l.concat():l,strokeLineCap:y,strokeDashOffset:x,strokeLineJoin:_,strokeUniform:w,strokeMiterLimit:B(C),scaleX:B(S),scaleY:B(T),angle:B(O),flipX:k,flipY:M,opacity:B(D),shadow:c?c.toObject():c,visible:E,backgroundColor:A,fillRule:j,paintFirst:P,globalCompositeOperation:L,skewX:B(F),skewY:B(R)},s?{clipPath:s}:null);return this.includeDefaultValues?I:this._removeDefaultValues(I)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Wt(t,(t,e)=>{if(e===E||e===A||"type"===e)return!0;const i=s[e];return t!==i&&!(Array.isArray(t)&&Array.isArray(i)&&0===t.length&&0===i.length)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=n(t,js),s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:i}=s,r=n(s,Ps);return Bt(e,r).then(t=>i?(delete t[i],new this(e[i],t)):new this(t))}static fromObject(t,e){return this._fromObject(t,e)}};s(Ls,"stateProperties",ps),s(Ls,"cacheProperties",ms),s(Ls,"ownDefaults",vs),s(Ls,"type","FabricObject"),s(Ls,"colorProperties",[Z,Q,"backgroundColor"]),s(Ls,"customProperties",[]),et.setClass(Ls),et.setClass(Ls,"object");const Fs=(t,e,s)=>(i,n,o,a)=>{const h=e(i,n,o,a);return h&&ue(t,r(r({},ye(i,n,o,a)),s)),h};function Rs(t){return(e,s,i,r)=>{const{target:n,originX:o,originY:a}=s,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,o,a),l=t(e,s,i,r);return n.setPositionByOrigin(c,s.originX,s.originY),l}}const Bs=Fs(Y,Rs((t,e,s,i)=>{const r=_e(e,e.originX,e.originY,s,i);if(ge(e.originX)===ge(D)||ge(e.originX)===ge(P)&&r.x<0||ge(e.originX)===ge(E)&&r.x>0){const{target:t}=e,s=t.strokeWidth/(t.strokeUniform?t.scaleX:1),i=pe(e)?2:1,n=t.width,o=Math.abs(r.x*i/t.scaleX)-s;return t.set("width",Math.max(o,1)),n!==t.width}return!1}));function Is(t,e,s,i,r){i=i||{};const n=this.sizeX||i.cornerSize||r.cornerSize,o=this.sizeY||i.cornerSize||r.cornerSize,a=void 0!==i.transparentCorners?i.transparentCorners:r.transparentCorners,h=a?Q:Z,c=!a&&(i.cornerStrokeColor||r.cornerStrokeColor);let l,u=e,d=s;t.save(),t.fillStyle=i.cornerColor||r.cornerColor||"",t.strokeStyle=i.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,t.scale(1,o/n),d=s*n/o):o>n?(l=o,t.scale(n/o,1),u=e*o/n):l=n,t.beginPath(),t.arc(u,d,l/2,0,S,!1),t[h](),c&&t.stroke(),t.restore()}function Ws(t,e,s,i,r){i=i||{};const n=this.sizeX||i.cornerSize||r.cornerSize,o=this.sizeY||i.cornerSize||r.cornerSize,a=void 0!==i.transparentCorners?i.transparentCorners:r.transparentCorners,h=a?Q:Z,c=!a&&(i.cornerStrokeColor||r.cornerStrokeColor),l=n/2,u=o/2;t.save(),t.fillStyle=i.cornerColor||r.cornerColor||"",t.strokeStyle=i.cornerStrokeColor||r.cornerStrokeColor||"",t.translate(e,s);const d=r.getTotalAngle();t.rotate(xt(d)),t["".concat(h,"Rect")](-l,-u,n,o),c&&t.strokeRect(-l,-u,n,o),t.restore()}class Xs{constructor(t){s(this,"visible",!0),s(this,"actionName",H),s(this,"angle",0),s(this,"x",0),s(this,"y",0),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"sizeX",0),s(this,"sizeY",0),s(this,"touchSizeX",0),s(this,"touchSizeY",0),s(this,"cursorStyle","crosshair"),s(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var r;let{tl:n,tr:o,br:a,bl:h}=i;return(null===(r=e.canvas)||void 0===r?void 0:r.getActiveObject())===e&&e.isControlVisible(t)&&Es.isPointInPolygon(s,[n,o,a,h])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return null!==(s=null===(i=t._controlsVisibility)||void 0===i?void 0:i[e])&&void 0!==s?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new at(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,r,n){const o=St([kt(s,i),Mt({angle:t}),Dt((r?this.touchSizeX:this.sizeX)||e,(r?this.touchSizeY:this.sizeY)||e)]);return{tl:new at(-.5,-.5).transform(o),tr:new at(.5,-.5).transform(o),br:new at(.5,.5).transform(o),bl:new at(-.5,.5).transform(o)}}render(t,e,s,i,r){"circle"===((i=i||{}).cornerStyle||r.cornerStyle)?Is.call(this,t,e,s,i,r):Ws.call(this,t,e,s,i,r)}}const Ys=(t,e,s)=>s.lockRotation?fe:e.cursorStyle,zs=Fs(I,Rs((t,e,s,i)=>{let{target:r,ex:n,ey:o,theta:a,originX:h,originY:c}=e;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),h,c);if(ve(r,"lockRotation"))return!1;const u=Math.atan2(o-l.y,n-l.x),d=Math.atan2(i-l.y,s-l.x);let g=_t(d-u+a);if(r.snapAngle&&r.snapAngle>0){const t=r.snapAngle,e=r.snapThreshold||t,s=Math.ceil(g/t)*t,i=Math.floor(g/t)*t;Math.abs(g-i)<e?g=i:Math.abs(g-s)<e&&(g=s)}g<0&&(g=360+g),g%=360;const f=r.angle!==g;return r.angle=g,f}));function Vs(t,e){const s=e.canvas,i=t[s.uniScaleKey];return s.uniformScaling&&!i||!s.uniformScaling&&i}function Gs(t,e,s){const i=ve(t,"lockScalingX"),r=ve(t,"lockScalingY");if(i&&r)return!0;if(!e&&(i||r)&&s)return!0;if(i&&"x"===e)return!0;if(r&&"y"===e)return!0;const{width:n,height:o,strokeWidth:a}=t;return 0===n&&0===a&&"y"!==e||0===o&&0===a&&"x"!==e}const Hs=["e","se","s","sw","w","nw","n","ne","e"],Ns=(t,e,s)=>{const i=Vs(t,s);if(Gs(s,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",i))return fe;const r=xe(s,e);return"".concat(Hs[r],"-resize")};function Us(t,e,s,i){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=r.by,a=Vs(t,n);let h,c,l,u,d,g;if(Gs(n,o,a))return!1;if(e.gestureScale)c=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(h=_e(e,e.originX,e.originY,s,i),d="y"!==o?Math.sign(h.x||e.signX||1):1,g="x"!==o?Math.sign(h.y||e.signY||1):1,e.signX||(e.signX=d),e.signY||(e.signY=g),ve(n,"lockScalingFlip")&&(e.signX!==d||e.signY!==g))return!1;if(u=n._getTransformedDimensions(),a&&!o){const t=Math.abs(h.x)+Math.abs(h.y),{original:s}=e,i=t/(Math.abs(u.x*s.scaleX/n.scaleX)+Math.abs(u.y*s.scaleY/n.scaleY));c=s.scaleX*i,l=s.scaleY*i}else c=Math.abs(h.x*n.scaleX/u.x),l=Math.abs(h.y*n.scaleY/u.y);pe(e)&&(c*=2,l*=2),e.signX!==d&&"y"!==o&&(e.originX=me(e.originX),c*=-1,e.signX=d),e.signY!==g&&"x"!==o&&(e.originY=me(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set(N,c),"y"===o&&n.set(U,l)):(!ve(n,"lockScalingX")&&n.set(N,c),!ve(n,"lockScalingY")&&n.set(U,l)),f!==n.scaleX||p!==n.scaleY}const qs=Fs(B,Rs((t,e,s,i)=>Us(t,e,s,i))),Ks=Fs(B,Rs((t,e,s,i)=>Us(t,e,s,i,{by:"x"}))),Zs=Fs(B,Rs((t,e,s,i)=>Us(t,e,s,i,{by:"y"}))),Qs=["target","ex","ey","skewingSide"],Js={x:{counterAxis:"y",scale:N,skew:q,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:U,skew:K,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},$s=["ns","nesw","ew","nwse"];function ti(t,e,s,i,o){const{target:a}=s,{counterAxis:h,origin:c,lockSkewing:l,skew:u,flip:d}=Js[t];if(ve(a,l))return!1;const{origin:g,flip:f}=Js[h],p=ge(s[g])*(a[f]?-1:1),m=-Math.sign(p)*(a[d]?-1:1),v=-(0===a[u]&&_e(s,D,D,i,o)[t]>0||a[u]>0?1:-1)*m*.5+.5,y=Fs(X,Rs((e,s,i,r)=>function(t,e,s){let{target:i,ex:r,ey:o,skewingSide:a}=e,h=n(e,Qs);const{skew:c}=Js[t],l=s.subtract(new at(r,o)).divide(new at(i.scaleX,i.scaleY))[t],u=i[c],d=h[c],g=Math.tan(xt(d)),f="y"===t?i._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:i._getTransformedDimensions({scaleX:1,scaleY:1}).y,p=2*l*a/Math.max(f,1)+g,m=_t(Math.atan(p));i.set(c,m);const v=u!==i[c];if(v&&"y"===t){const{skewX:t,scaleX:e}=i,s=i._getTransformedDimensions({skewY:u}),r=i._getTransformedDimensions(),n=0!==t?s.x/r.x:1;1!==n&&i.set(N,n*e)}return v}(t,s,new at(i,r))));return y(e,r(r({},s),{},{[c]:v,skewingSide:m}),i,o)}function ei(t,e){return t[e.canvas.altActionKey]}const si=(t,e,s)=>{const i=ei(t,s);return 0===e.x?i?q:U:0===e.y?i?K:N:""},ii=(t,e,s)=>ei(t,s)?((t,e,s)=>{if(0!==e.x&&ve(s,"lockSkewingY"))return fe;if(0!==e.y&&ve(s,"lockSkewingX"))return fe;const i=xe(s,e)%4;return"".concat($s[i],"-resize")})(0,e,s):Ns(t,e,s),ri=(t,e,s,i)=>ei(t,e.target)?((t,e,s,i)=>ti("y",t,e,s,i))(t,e,s,i):Ks(t,e,s,i),ni=(t,e,s,i)=>ei(t,e.target)?((t,e,s,i)=>ti("x",t,e,s,i))(t,e,s,i):Zs(t,e,s,i),oi=()=>({ml:new Xs({x:-.5,y:0,cursorStyleHandler:ii,actionHandler:ri,getActionName:si}),mr:new Xs({x:.5,y:0,cursorStyleHandler:ii,actionHandler:ri,getActionName:si}),mb:new Xs({x:0,y:.5,cursorStyleHandler:ii,actionHandler:ni,getActionName:si}),mt:new Xs({x:0,y:-.5,cursorStyleHandler:ii,actionHandler:ni,getActionName:si}),tl:new Xs({x:-.5,y:-.5,cursorStyleHandler:Ns,actionHandler:qs}),tr:new Xs({x:.5,y:-.5,cursorStyleHandler:Ns,actionHandler:qs}),bl:new Xs({x:-.5,y:.5,cursorStyleHandler:Ns,actionHandler:qs}),br:new Xs({x:.5,y:.5,cursorStyleHandler:Ns,actionHandler:qs}),mtr:new Xs({x:0,y:-.5,actionHandler:zs,cursorStyleHandler:Ys,offsetY:-40,withConnection:!0,actionName:W})}),ai=()=>r(r({},oi()),{mr:new Xs({x:.5,y:0,actionHandler:Bs,cursorStyleHandler:ii,actionName:Y}),ml:new Xs({x:-.5,y:0,actionHandler:Bs,cursorStyleHandler:ii,actionName:Y})});class hi extends Ls{static getDefaults(){return r(r({},super.getDefaults()),hi.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),hi.ownDefaults),this.setOptions(t)}static createControls(){return{controls:oi()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(H))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[r,n]=s[i],o=this.controls[r];if(o.shouldActivate(r,this,t,e?n.touchCorner:n.corner))return this.__corner=r,{key:r,control:o,coord:this.oCoords[r]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=kt(e.x,e.y),i=Mt({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),r=Ct(s,i),n=Ct(t,r),o=Ct(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?Ot(this.calcTransformMatrix()):void 0;a&&(a.scaleX=Math.abs(a.scaleX),a.scaleY=Math.abs(a.scaleY));const h=this._calculateCurrentDimensions(a),c={};return this.forEachControl((t,e)=>{const s=t.positionHandler(h,o,this,t);c[e]=Object.assign(s,this._calcCornerCoords(t,s))}),c}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(xt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const i=r({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=r({hasBorders:s,hasControls:i},e),o=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,c=Ct(o,this.calcTransformMatrix()),l=Ot(c);t.save(),t.translate(l.translateX,l.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(l.angle-=180),t.rotate(xt(this.group?l.angle:this.angle)),a&&this.drawBorders(t,l,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const t=he(this.width,this.height,Pt(e)),s=this.isStrokeAccountedForInDimensions()?ht:(this.strokeUniform?(new at).scalarAdd(this.canvas?this.canvas.getZoom():1):new at(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=t.add(s).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,r)=>{i.withConnection&&i.getVisibility(this,r)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:o}=this,a=r({cornerStrokeColor:i,cornerDashArray:n,cornerColor:o},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((e,s)=>{if(e.getVisibility(this,s)){const i=this.oCoords[s];e.render(t,i.x,i.y,a,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(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.entries(t).forEach(t=>{let[e,s]=t;return this.setControlVisible(e,s)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,r=this.height+4;return e.clearRect(-i/2,-r/2,i,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 ci(t,e){return e.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{"constructor"!==s&&Object.defineProperty(t.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),t}s(hi,"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});class li extends hi{}ci(li,[Ae]),et.setClass(li),et.setClass(li,"object");class ui{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new at(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new at(1/this.options.scaleX,1/this.options.scaleY):new at(1,1)}createSideVector(t,e){const s=is(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return 0!==this.options.skewX||0!==this.options.skewY}applySkew(t){const e=new at(t);return e.y+=e.x*Math.tan(xt(this.options.skewY)),e.x+=e.y*Math.tan(xt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const di=new at;class gi extends ui{static getOrthogonalRotationFactor(t,e){const s=e?ns(t,e):(t=>ns(ts,t))(t);return Math.abs(s)<C?-1:1}constructor(t,e,i,r){super(r),s(this,"AB",void 0),s(this,"AC",void 0),s(this,"alpha",void 0),s(this,"bisector",void 0),this.A=new at(t),this.B=new at(e),this.C=new at(i),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=ns(this.AB,this.AC),this.bisector=os(ss(this.AB.eq(di)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),r=as(i),n=gi.getOrthogonalRotationFactor(r,this.bisector);return this.scaleUnitVector(r,s*n)}projectBevel(){const t=[];return(this.alpha%S==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(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),r=this.options.strokeUniform?rs(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return rs(i)/this.strokeProjectionMagnitude<=r&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new at(gi.getOrthogonalRotationFactor(this.bisector),gi.getOrthogonalRotationFactor(new at(this.bisector.y,this.bisector.x)));return[new at(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new at(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(i=>{ls(i,t,e)&&s.push(this.A.add(i))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:r,scaleX:n,scaleY:o,strokeUniform:a}=this.options,h=new at(Math.tan(xt(i)),Math.tan(xt(r))),c=this.strokeProjectionMagnitude,l=a?c/o/Math.sqrt(1/o**2+1/n**2*h.y**2):c/Math.sqrt(1+h.y**2),u=new at(Math.sqrt(Math.max(c**2-l**2,0)),l),d=a?c/Math.sqrt(1+h.x**2*(1/o)**2/(1/n+1/n*h.x*h.y)**2):c/Math.sqrt(1+h.x**2/(1+h.x*h.y)**2),g=new at(d,Math.sqrt(Math.max(c**2-d**2,0)));return[g,g.scalarMultiply(-1),u,u.scalarMultiply(-1)].map(t=>this.applySkew(a?t.multiply(this.strokeUniformScalar):t)).forEach(i=>{ls(i,t,e)&&s.push(this.applySkew(this.A).add(i))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%S==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),r=t[e?1:0].subtract(s),n=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=hs(i,n)>0,a=o?i:r,h=o?r:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(a,h)):t.push(...this.projectRoundNoSkew(a,h)),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}))}}class fi extends ui{constructor(t,e,s){super(s),this.A=new at(t),this.T=new at(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(as(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new at(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 gi(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new at(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(os(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.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 pi=t=>{const e={};return Object.keys(t).forEach(s=>{e[s]={},Object.keys(t[s]).forEach(i=>{e[s][i]=r({},t[s][i])})}),e};let mi;const vi=t=>{if(mi||mi||(mi="Intl"in y()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),mi){const e=mi.segment(t);return Array.from(e).map(t=>{let{segment:e}=t;return e})}return yi(t)},yi=t=>{const e=[];for(let s,i=0;i<t.length;i++)!1!==(s=xi(t,i))&&e.push(s);return e},xi=(t,e)=>{const s=t.charCodeAt(e);if(isNaN(s))return"";if(s<55296||s>57343)return t.charAt(e);if(55296<=s&&s<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";const s=t.charCodeAt(e+1);if(56320>s||s>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";const i=t.charCodeAt(e-1);if(55296>i||i>56319)throw"Low surrogate without preceding high surrogate";return!1},_i=function(t,e){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return 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.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||s&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},bi=(t,e)=>{const s=e.split("\n"),i=[];let r=-1,n={};t=pi(t);for(let e=0;e<s.length;e++){const o=vi(s[e]);if(t[e])for(let s=0;s<o.length;s++){r++;const o=t[e][s];o&&Object.keys(o).length>0&&(_i(n,o,!0)?i.push({start:r,end:r+1,style:o}):i[i.length-1].end++),n=o||{}}else r+=o.length,n={}}return i},wi=(t,e)=>{if(!Array.isArray(t))return pi(t);const s=e.split(F),i={};let n=-1,o=0;for(let e=0;e<s.length;e++){const a=vi(s[e]);for(let s=0;s<a.length;s++)n++,t[o]&&t[o].start<=n&&n<t[o].end&&(i[e]=i[e]||{},i[e][s]=r({},t[o].style),n===t[o].end-1&&o++)}return i},Ci=["display","transform",Z,"fill-opacity","fill-rule","opacity",Q,"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 Si(t,e){const s=t.nodeName,i=t.getAttribute("class"),r=t.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let o;if(o=new RegExp("^"+s,"i"),e=e.replace(o,""),r&&e.length&&(o=new RegExp("#"+r+n,"i"),e=e.replace(o,"")),i&&e.length){const t=i.split(" ");for(let s=t.length;s--;)o=new RegExp("\\."+t[s]+n,"i"),e=e.replace(o,"")}return 0===e.length}function Ti(t,e){let s=!0;const i=Si(t,e.pop());return i&&e.length&&(s=function(t,e){let s,i=!0;for(;t.parentElement&&1===t.parentElement.nodeType&&e.length;)i&&(s=e.pop()),i=Si(t=t.parentElement,s);return 0===e.length}(t,e)),i&&s&&0===e.length}const Oi=t=>{var e;return null!==(e=Ze[t])&&void 0!==e?e:t},ki=new RegExp("(".concat(Ue,")"),"gi");var Mi,Di,Ei,Ai,ji,Pi,Li;const Fi="(".concat(Ue,")"),Ri=String.raw(Mi||(Mi=o(["(skewX)(",")"],["(skewX)\\(","\\)"])),Fi),Bi=String.raw(Di||(Di=o(["(skewY)(",")"],["(skewY)\\(","\\)"])),Fi),Ii=String.raw(Ei||(Ei=o(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Fi,Fi,Fi),Wi=String.raw(Ai||(Ai=o(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Fi,Fi),Xi=String.raw(ji||(ji=o(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Fi,Fi),Yi=String.raw(Pi||(Pi=o(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Fi,Fi,Fi,Fi,Fi,Fi),zi="(?:".concat(Yi,"|").concat(Xi,"|").concat(Ii,"|").concat(Wi,"|").concat(Ri,"|").concat(Bi,")"),Vi="(?:".concat(zi,"*)"),Gi=String.raw(Li||(Li=o(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Vi),Hi=new RegExp(Gi),Ni=new RegExp(zi),Ui=new RegExp(zi,"g");function qi(t){const e=[];if(!(t=(t=>t.replace(ki," $1 ").replace(/,/gi," ").replace(/\s+/gi," "))(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!Hi.test(t))return[...O];for(const s of t.matchAll(Ui)){const t=Ni.exec(s[0]);if(!t)continue;let i=O;const r=t.filter(t=>!!t),[,n,...o]=r,[a,h,c,l,u,d]=o.map(t=>parseFloat(t));switch(n){case"translate":i=kt(a,h);break;case W:i=Mt({angle:a},{x:h,y:c});break;case H:i=Dt(a,h);break;case q:i=At(a);break;case K:i=jt(a);break;case"matrix":i=[a,h,c,l,u,d]}e.push(i)}return St(e)}function Ki(t,e,s,i){const r=Array.isArray(e);let n,o=e;if(t!==Z&&t!==Q||e!==L){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)o=e===L?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)o=s&&s.transformMatrix?Ct(s.transformMatrix,qi(e)):qi(e);else if("visible"===t)o=e!==L&&"hidden"!==e,s&&!1===s.visible&&(o=!1);else if("opacity"===t)o=parseFloat(e),s&&void 0!==s.opacity&&(o*=s.opacity);else if("textAnchor"===t)o="start"===e?E:"end"===e?P:D;else if("charSpacing"===t||t===Pe)n=De(e,i)/i*1e3;else if("paintFirst"===t){const t=e.indexOf(Z),s=e.indexOf(Q);o=Z,(t>-1&&s>-1&&s<t||-1===t&&s>-1)&&(o=Q)}else{if("href"===t||"xlink:href"===t||"font"===t||"id"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=r?e.map(De):De(e,i)}}else o="";return!r&&isNaN(n)?o:n}const Zi={stroke:"strokeOpacity",fill:"fillOpacity"};function Qi(t,e,s){if(!t)return{};let i,n={},o=k;t.parentNode&&$e.test(t.parentNode.nodeName)&&(n=Qi(t.parentElement,e,s),n.fontSize&&(i=o=De(n.fontSize)));const a=r(r(r({},e.reduce((e,s)=>{const i=t.getAttribute(s);return i&&(e[s]=i),e},{})),function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s={};for(const i in e)Ti(t,i.split(" "))&&(s=r(r({},s),e[i]));return s}(t,s)),function(t){const e={},s=t.getAttribute("style");return s?("string"==typeof s?function(t,e){t.replace(/;\s*$/,"").split(";").forEach(t=>{if(!t)return;const[s,i]=t.split(":");e[s.trim().toLowerCase()]=i.trim()})}(s,e):function(t,e){Object.entries(t).forEach(t=>{let[s,i]=t;void 0!==i&&(e[s.toLowerCase()]=i)})}(s,e),e):e}(t));a[Je]&&t.setAttribute(Je,a[Je]),a[Qe]&&(i=De(a[Qe],o),a[Qe]="".concat(i));const h={};for(const t in a){const e=Oi(t),s=Ki(e,a[t],n,i);h[e]=s}h&&h.font&&function(t,e){const s=t.match(Ke);if(!s)return;const i=s[1],r=s[3],n=s[4],o=s[5],a=s[6];i&&(e.fontStyle=i),r&&(e.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),n&&(e.fontSize=De(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}(h.font,h);const c=r(r({},n),h);return $e.test(t.nodeName)?c:function(t){const e=li.getDefaults();return Object.entries(Zi).forEach(s=>{let[i,r]=s;if(void 0===t[r]||""===t[i])return;if(void 0===t[i]){if(!e[i])return;t[i]=e[i]}if(0===t[i].indexOf("url("))return;const n=new Me(t[i]);t[i]=n.setAlpha(Xt(n.getAlpha()*t[r],2)).toRgba()}),t}(c)}const Ji=["left","top","width","height","visible"],$i=["rx","ry"];class tr extends li{static getDefaults(){return r(r({},super.getDefaults()),tr.ownDefaults)}constructor(t){super(),Object.assign(this,tr.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,r=-s/2,n=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,a=0!==n||0!==o;t.beginPath(),t.moveTo(i+n,r),t.lineTo(i+e-n,r),a&&t.bezierCurveTo(i+e-M*n,r,i+e,r+M*o,i+e,r+o),t.lineTo(i+e,r+s-o),a&&t.bezierCurveTo(i+e,r+s-M*o,i+e-M*n,r+s,i+e-n,r+s),t.lineTo(i+n,r+s),a&&t.bezierCurveTo(i+M*n,r+s,i,r+s-M*o,i,r+s-o),t.lineTo(i,r+o),a&&t.bezierCurveTo(i,r+M*o,i+M*n,r,i+n,r),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...$i,...t])}_toSVG(){const{width:t,height:e,rx:s,ry:i}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(s,'" ry="').concat(i,'" width="').concat(t,'" height="').concat(e,'" />\n')]}static async fromElement(t,e,s){const i=Qi(t,this.ATTRIBUTE_NAMES,s),{left:o=0,top:a=0,width:h=0,height:c=0,visible:l=!0}=i,u=n(i,Ji);return new this(r(r(r({},e),u),{},{left:o,top:a,width:h,height:c,visible:Boolean(l&&h&&c)}))}}s(tr,"type","Rect"),s(tr,"cacheProperties",[...ms,...$i]),s(tr,"ownDefaults",{rx:0,ry:0}),s(tr,"ATTRIBUTE_NAMES",[...Ci,"x","y","rx","ry","width","height"]),et.setClass(tr),et.setSVGClass(tr);const er="initialization",sr="added",ir="removed",rr="imperative",nr=(t,e)=>{const{strokeUniform:s,strokeWidth:i,width:r,height:n,group:o}=e,a=o&&o!==t?ce(o.calcTransformMatrix(),t.calcTransformMatrix()):null,h=a?e.getRelativeCenterPoint().transform(a):e.getRelativeCenterPoint(),c=!e.isStrokeAccountedForInDimensions(),l=s&&c?function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:O;return t.transform(ce(e,s),!0)}(new at(i,i),void 0,t.calcTransformMatrix()):ht,u=!s&&c?i:0,d=he(r+u,n+u,St([a,e.calcOwnMatrix()],!0)).add(l).scalarDivide(2);return[h.subtract(d),h.add(d)]};class or{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===er||e===rr||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==er&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===rr&&e.overrides)return e.overrides;if(0===t.length)return;const{left:r,top:n,width:o,height:a}=re(t.map(t=>nr(i,t)).reduce((t,e)=>t.concat(e),[])),h=new at(o,a),c=new at(r,n).add(h.scalarDivide(2));if(s===er){const t=this.getInitialSize(e,{size:h,center:c});return{center:c,relativeCorrection:new at(0,0),size:t}}return{center:c.transform(i.calcOwnMatrix()),size:h}}}s(or,"type","strategy");class ar extends or{shouldPerformLayout(t){return!0}}s(ar,"type","fit-content"),et.setClass(ar);const hr=["strategy"],cr=["target","strategy","bubbles","prevStrategy"],lr="layoutManager";class ur{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new ar;s(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=r(r({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[J,R,Y,I,B,X,G,z,V].map(e=>t.on(e,t=>this.performLayout(e===J?{type:"object_modified",trigger:e,e:t,target:s}:{type:"object_modifying",trigger:e,e:t,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}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){const{target:e,type:s}=t,{canvas:i}=e;if(s===er||s===sr?this.subscribeTargets(t):s===ir&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===rr&&t.deep){const s=n(t,hr);e.forEachObject(t=>t.layoutManager&&t.layoutManager.performLayout(r(r({},s),{},{bubbles:!1,target:t})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,r=s.calcLayoutResult(t,e.getObjects());if(!r)return;const n=i===er?new at:e.getRelativeCenterPoint(),{center:o,correction:a=new at,relativeCorrection:h=new at}=r,c=n.subtract(o).add(a).transform(i===er?O:wt(e.calcOwnMatrix()),!0).add(h);return{result:r,prevCenter:n,nextCenter:o,offset:c}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:r}=e;var n,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===er?s.set({left:null!==(n=t.x)&&void 0!==n?n:r.x+i.x*ge(s.originX),top:null!==(o=t.y)&&void 0!==o?o:r.y+i.y*ge(s.originY)}):(s.setPositionByOrigin(r,D,D),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:o,prevStrategy:a}=t,h=n(t,cr),{canvas:c}=s;s.fire("layout:after",{context:t,result:e}),c&&c.fire("object:layout:after",{context:t,result:e,target:s});const l=s.parent;o&&null!=l&&l.layoutManager&&((h.path||(h.path=[])).push(s),l.layoutManager.performLayout(r(r({},h),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(t=>t.forEach(t=>t())),t.clear()}toObject(){return{type:lr,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}et.setClass(ur,lr);const dr=["type","objects","layoutManager"];class gr extends ur{performLayout(){}}class fr extends(lt(li)){static getDefaults(){return r(r({},super.getDefaults()),fr.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),s(this,"_activeObjects",[]),s(this,"__objectSelectionTracker",void 0),s(this,"__objectSelectionDisposer",void 0),Object.assign(this,fr.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;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!==(s=e.layoutManager)&&void 0!==s?s:new ur,this.layoutManager.performLayout({type:er,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(c("error","Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(c("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((t,e,s)=>this.canEnterGroup(t)&&s.indexOf(t)===e)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),r=super.add(...i);return this._onAfterObjectsChange(sr,i),r}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const r=this._filterObjectsBeforeEnteringGroup(s),n=super.insertAt(t,...r);return this._onAfterObjectsChange(sr,r),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(ir,t),t}_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){const s=this[t];return super._set(t,e),"canvas"===t&&s!==e&&(this._objects||[]).forEach(s=>{s._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const t=i.indexOf(s);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&&oe(t,Ct(wt(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&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||(oe(t,Ct(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=li.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,s){this._renderBackground(t);for(let e=0;e<this._objects.length;e++){var i;const s=this._objects[e];null!==(i=this.canvas)&&void 0!==i&&i.preserveObjectStacking&&s.group!==this?(t.save(),t.transform(...wt(this.calcTransformMatrix())),s.render(t),t.restore()):s.group===this&&s.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.layoutManager.performLayout(r({target:this,type:rr},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(t){return!t.excludeFromExport}).map(function(i){const r=i.includeDefaultValues;i.includeDefaultValues=s;const n=i[t||"toObject"](e);return i.includeDefaultValues=r,n})}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.layoutManager.toObject();return r(r(r({},super.toObject(["subTargetCheck","interactive",...t])),"fit-content"!==e.strategy||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(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"";const e=tr.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS"," >\n"],s=this._createSVGBgRect(t);s&&e.push("\t\t",s);for(let s=0;s<this._objects.length;s++)e.push("\t\t",this._objects[s].toSVG(t));return e.push("</g>\n"),e}getSvgStyles(){const t=void 0!==this.opacity&&1!==this.opacity?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push("\t",s);for(let s=0;s<this._objects.length;s++)e.push("\t",this._objects[s].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:o}=t,a=n(t,dr);return Promise.all([Rt(i,e),Bt(a,e)]).then(t=>{let[e,s]=t;const i=new this(e,r(r(r({},a),s),{},{layoutManager:new gr}));if(o){const t=et.getClass(o.type),e=et.getClass(o.strategy);i.layoutManager=new t(new e)}else i.layoutManager=new ur;return i.layoutManager.subscribeTargets({type:er,target:i,targets:i.getObjects()}),i.setCoords(),i})}}s(fr,"type","Group"),s(fr,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),et.setClass(fr);const pr="\\s*,?\\s*",mr="".concat(pr,"(").concat(Ue,")"),vr="".concat(mr).concat(mr).concat(mr).concat(pr,"([01])").concat(pr,"([01])").concat(mr).concat(mr),yr={m:"l",M:"L"},xr=(t,e,s,i,r,n,o,a,h,c,l)=>{const u=nt(t),d=ot(t),g=nt(e),f=ot(e),p=s*r*g-i*n*f+o,m=i*r*g+s*n*f+a;return["C",c+h*(-s*r*d-i*n*u),l+h*(-i*r*d+s*n*u),p+h*(s*r*f+i*n*g),m+h*(i*r*f-s*n*g),p,m]},_r=(t,e,s,i)=>{const r=Math.atan2(e,t),n=Math.atan2(i,s);return n>=r?n-r:2*Math.PI-(r-n)};function br(t,e,s,i,r,n,o,a){let c;if(h.cachesBoundsOfCurve&&(c=[...arguments].join(),_.boundsOfCurveCache[c]))return _.boundsOfCurveCache[c];const l=Math.sqrt,u=Math.abs,d=[],g=[[0,0],[0,0]];let f=6*t-12*s+6*r,p=-3*t+9*s-9*r+3*o,m=3*s-3*t;for(let t=0;t<2;++t){if(t>0&&(f=6*e-12*i+6*n,p=-3*e+9*i-9*n+3*a,m=3*i-3*e),u(p)<1e-12){if(u(f)<1e-12)continue;const t=-m/f;0<t&&t<1&&d.push(t);continue}const s=f*f-4*m*p;if(s<0)continue;const r=l(s),o=(-f+r)/(2*p);0<o&&o<1&&d.push(o);const h=(-f-r)/(2*p);0<h&&h<1&&d.push(h)}let v=d.length;const y=v,x=Sr(t,e,s,i,r,n,o,a);for(;v--;){const{x:t,y:e}=x(d[v]);g[0][v]=t,g[1][v]=e}g[0][y]=t,g[1][y]=e,g[0][y+1]=o,g[1][y+1]=a;const b=[new at(Math.min(...g[0]),Math.min(...g[1])),new at(Math.max(...g[0]),Math.max(...g[1]))];return h.cachesBoundsOfCurve&&(_.boundsOfCurveCache[c]=b),b}const wr=(t,e,s)=>{let[i,r,n,o,a,h,c,l]=s;const u=((t,e,s,i,r,n,o)=>{if(0===s||0===i)return[];let a=0,h=0,c=0;const l=Math.PI,u=o*T,d=ot(u),g=nt(u),f=.5*(-g*t-d*e),p=.5*(-g*e+d*t),m=s**2,v=i**2,y=p**2,x=f**2,_=m*v-m*y-v*x;let b=Math.abs(s),w=Math.abs(i);if(_<0){const t=Math.sqrt(1-_/(m*v));b*=t,w*=t}else c=(r===n?-1:1)*Math.sqrt(_/(m*y+v*x));const C=c*b*p/w,S=-c*w*f/b,O=g*C-d*S+.5*t,k=d*C+g*S+.5*e;let M=_r(1,0,(f-C)/b,(p-S)/w),D=_r((f-C)/b,(p-S)/w,(-f-C)/b,(-p-S)/w);0===n&&D>0?D-=2*l:1===n&&D<0&&(D+=2*l);const E=Math.ceil(Math.abs(D/l*2)),A=[],j=D/E,P=8/3*Math.sin(j/4)*Math.sin(j/4)/Math.sin(j/2);let L=M+j;for(let t=0;t<E;t++)A[t]=xr(M,L,g,d,b,w,O,k,P,a,h),a=A[t][5],h=A[t][6],M=L,L+=j;return A})(c-t,l-e,r,n,a,h,o);for(let s=0,i=u.length;s<i;s++)u[s][1]+=t,u[s][2]+=e,u[s][3]+=t,u[s][4]+=e,u[s][5]+=t,u[s][6]+=e;return u},Cr=(t,e,s,i)=>Math.sqrt((s-t)**2+(i-e)**2),Sr=(t,e,s,i,r,n,o,a)=>h=>{const c=h**3,l=(t=>3*t**2*(1-t))(h),u=(t=>3*t*(1-t)**2)(h),d=(t=>(1-t)**3)(h);return new at(o*c+r*l+s*u+t*d,a*c+n*l+i*u+e*d)},Tr=t=>t**2,Or=t=>2*t*(1-t),kr=t=>(1-t)**2,Mr=(t,e,s,i,r,n,o,a)=>h=>{const c=Tr(h),l=Or(h),u=kr(h),d=3*(u*(s-t)+l*(r-s)+c*(o-r)),g=3*(u*(i-e)+l*(n-i)+c*(a-n));return Math.atan2(g,d)},Dr=(t,e,s,i,r,n)=>o=>{const a=Tr(o),h=Or(o),c=kr(o);return new at(r*a+s*h+t*c,n*a+i*h+e*c)},Er=(t,e,s,i,r,n)=>o=>{const a=1-o,h=2*(a*(s-t)+o*(r-s)),c=2*(a*(i-e)+o*(n-i));return Math.atan2(c,h)},Ar=(t,e,s)=>{let i=new at(e,s),r=0;for(let e=1;e<=100;e+=1){const s=t(e/100);r+=Cr(i.x,i.y,s.x,s.y),i=s}return r},jr=t=>{let e,s,i=0,r=0,n=0,o=0,a=0;const h=[];for(const c of t){const t={x:r,y:n,command:c[0],length:0};switch(c[0]){case"M":s=t,s.x=o=r=c[1],s.y=a=n=c[2];break;case"L":s=t,s.length=Cr(r,n,c[1],c[2]),r=c[1],n=c[2];break;case"C":e=Sr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),s=t,s.iterator=e,s.angleFinder=Mr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),s.length=Ar(e,r,n),r=c[5],n=c[6];break;case"Q":e=Dr(r,n,c[1],c[2],c[3],c[4]),s=t,s.iterator=e,s.angleFinder=Er(r,n,c[1],c[2],c[3],c[4]),s.length=Ar(e,r,n),r=c[3],n=c[4];break;case"Z":s=t,s.destX=o,s.destY=a,s.length=Cr(r,n,o,a),r=o,n=a}i+=s.length,h.push(s)}return h.push({length:i,x:r,y:n}),h},Pr=function(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:jr(t),i=0;for(;e-s[i].length>0&&i<s.length-2;)e-=s[i].length,i++;const n=s[i],o=e/n.length,a=t[i];switch(n.command){case"M":return{x:n.x,y:n.y,angle:0};case"Z":return r(r({},new at(n.x,n.y).lerp(new at(n.destX,n.destY),o)),{},{angle:Math.atan2(n.destY-n.y,n.destX-n.x)});case"L":return r(r({},new at(n.x,n.y).lerp(new at(a[1],a[2]),o)),{},{angle:Math.atan2(a[2]-n.y,a[1]-n.x)});case"C":case"Q":return((t,e)=>{let s,i=0,n=0,o={x:t.x,y:t.y},a=r({},o),h=.01,c=0;const l=t.iterator,u=t.angleFinder;for(;n<e&&h>1e-4;)a=l(i),c=i,s=Cr(o.x,o.y,a.x,a.y),s+n>e?(i-=h,h/=2):(o=a,i+=h,n+=s);return r(r({},a),{},{angle:u(c)})})(n,e)}},Lr=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Fr=new RegExp(vr,"g"),Rr=new RegExp(Ue,"gi"),Br={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7};function Ir(t,e){const s=t.style;s&&e&&("string"==typeof e?s.cssText+=";"+e:Object.entries(e).forEach(t=>{let[e,i]=t;return s.setProperty(e,i)}))}class Wr extends Jt{constructor(t){let{allowTouchScrolling:e=!1,containerClass:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t),s(this,"upper",void 0),s(this,"container",void 0);const{el:r}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(r,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const o=this.createContainerElement();o.classList.add(i),r.parentNode&&r.parentNode.replaceChild(o,r),o.append(r,n),this.container=o}createUpperCanvas(){const{el:t}=this.lower,e=pt();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(){const t=v().createElement("div");return t.setAttribute("data-fabric","wrapper"),Ir(t,{position:"relative"}),Qt(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Ir(t,r(r({},s),{},{"touch-action":i?"manipulation":L})),Qt(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Kt(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Zt(this.upper.el,t),Zt(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),m().dispose(this.upper.el),delete this.upper,delete this.container}}class Xr extends te{constructor(){super(...arguments),s(this,"targets",[]),s(this,"_hoveredTargets",[]),s(this,"_objectsToRender",void 0),s(this,"_currentTransform",null),s(this,"_groupSelector",null),s(this,"contextTopDirty",!1)}static getDefaults(){return r(r({},super.getDefaults()),Xr.ownDefaults)}get upperCanvasEl(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.el}get contextTop(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Wr(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(){const 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(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,r=this.pixelFindContext;this.clearContext(r),r.save(),r.translate(-e+i,-s+i),r.transform(...this.viewportTransform);const n=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(r),t.selectionBackgroundColor=n,r.restore();const o=Math.round(i*this.getRetinaScaling());return((t,e,s,i)=>{const r=2*(i=Math.round(i))+1,{data:n}=t.getImageData(e-i,s-i,r,r);for(let t=3;t<n.length;t+=4)if(n[t]>0)return!1;return!0})(r,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(e=>!!e&&!0===t[e]):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&-1===s.indexOf(e)&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===H||e===N||e===U||e===Y?i=this.centeredScaling||t.centeredScaling:e===W&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e?(["ml","tl","bl"].includes(e)?s.x=P:["mr","tr","br"].includes(e)&&(s.x=E),["tl","mt","tr"].includes(e)?s.y=j:["bl","mb","br"].includes(e)&&(s.y=A),s):s}_setupCurrentTransform(t,e,s){var i;const n=e.group?le(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:o="",control:a}=e.getActiveControl()||{},h=s&&a?null===(i=a.getActionHandler(t,e,a))||void 0===i?void 0:i.bind(a):be,c=((t,e,s,i)=>{if(!e||!t)return"drag";const r=i.controls[e];return r.getActionName(s,r,i)})(s,o,t,e),l=t[this.centeredKey],u=this._shouldCenterTransform(e,c,l)?{x:D,y:D}:this._getOriginFromCorner(e,o),d={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:o,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:xt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:l,original:r(r({},ae(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:r}=this._groupSelector,n=new at(e,s).transform(this.viewportTransform),o=new at(e+i,s+r).transform(this.viewportTransform),a=this.selectionLineWidth/2;let h=Math.min(n.x,o.x),c=Math.min(n.y,o.y),l=Math.max(n.x,o.x),u=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(h,c,l-h,u-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,h+=a,c+=a,l-=a,u-=a,li.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(h,c,l-h,u-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,se(t)))return s;if(i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const i=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=i,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),r=t.padding/i;if(r){const[t,e,i,n]=s,o=Math.atan2(e.y-t.y,e.x-t.x),a=nt(o)*r,h=ot(o)*r,c=a+h,l=a-h;s=[new at(t.x-l,t.y-c),new at(e.x+c,e.y-l),new at(i.x+l,i.y+c),new at(n.x-c,n.y+l)]}return Es.isPointInPolygon(e,s)}_checkTarget(t,e){if(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,le(e,void 0,this.viewportTransform))){if(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing)return!0;if(!this.isTargetTransparent(t,e.x,e.y))return!0}return!1}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(ct(i)&&i.subTargetCheck){const t=this._searchPossibleTargets(i._objects,e);t&&this.targets.push(t)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&ct(s)&&s.interactive&&this.targets[0]){const t=this.targets;for(let e=t.length-1;e>0;e--){const s=t[e];if(!ct(s)||!s.interactive)return s}return t[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let r=(t=>{const e=Nt(t.target),s=function(t){const e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new at(s.clientX+e.left,s.clientY+e.top)})(t),n=i.width||0,o=i.height||0;n&&o||(A in i&&j in i&&(o=Math.abs(i.top-i.bottom)),P in i&&E in i&&(n=Math.abs(i.right-i.left))),this.calcOffset(),r.x=r.x-this._offset.left,r.y=r.y-this._offset.top,e||(r=le(r,void 0,this.viewportTransform));const a=this.getRetinaScaling();1!==a&&(r.x/=a,r.y/=a);const h=0===n||0===o?new at(1,1):new at(s.width/n,s.height/o);return r.multiply(h)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=pt(),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(){const t=this._activeObject;return Ht(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const r=this.getActiveObjects(),n=[],o=[];t.forEach(t=>{r.includes(t)||(s=!0,t.fire("deselected",{e:e,target:t}),o.push(t))}),r.forEach(i=>{t.includes(i)||(s=!0,i.fire("selected",{e:e,target:i}),n.push(i))}),t.length>0&&r.length>0?(i=!0,s&&this.fire("selection:updated",{e:e,selected:n,deselected:o})):r.length>0?(i=!0,this.fire("selection:created",{e:e,selected:n})):t.length>0&&(i=!0,this.fire("selection:cleared",{e:e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return!(s===t||!this._discardActiveObject(e,t)&&this._activeObject||t.onSelect({e:e})||(this._activeObject=t,Ht(t)&&s!==t&&t.set("canvas",this),t.setCoords(),0))}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),Ht(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(J,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Ht(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){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,s);return t.set(i),r}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&Ht(e)&&this._activeObject===e){const s=It(t,["angle","flipX","flipY",E,N,U,q,K,A]);return((t,e)=>{oe(t,Ct(e,t.calcOwnMatrix()))})(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}s(Xr,"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:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class Yr{constructor(t){s(this,"targets",[]),s(this,"__disposer",void 0);const e=()=>{const{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),rt(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)||void 0===e?void 0:e.isEditing)&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const zr=["target","oldTarget","fireCanvas","e"],Vr={passive:!1},Gr=(t,e)=>{const s=t.getViewportPoint(e),i=t.getScenePoint(e);return{viewportPoint:s,scenePoint:i,pointer:s,absolutePointer:i}},Hr=function(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];return t.addEventListener(...s)},Nr=function(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];return t.removeEventListener(...s)},Ur={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"}};class qr extends Xr{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),s(this,"_isClick",void 0),s(this,"textEditingManager",new Yr(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(Hr,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(qt(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Vr),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Vr)}removeListeners(){this.addOrRemove(Nr,"remove");const t=this._getEventPrefix(),e=Ut(this.upperCanvasEl);Nr(e,"".concat(t,"up"),this._onMouseUp),Nr(e,"touchend",this._onTouchEnd,Vr),Nr(e,"".concat(t,"move"),this._onMouseMove,Vr),Nr(e,"touchmove",this._onMouseMove,Vr),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=r({e:t},Gr(this,t));this.fire("mouse:out",r(r({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",r({},s)),this._hoveredTargets.forEach(t=>{this.fire("mouse:out",r(r({},s),{},{target:t})),t&&t.fire("mouseout",r({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",r({e:t},Gr(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Hr(this.upperCanvasEl,"drag",this._onDragProgress)}ie(t)}_renderDragEffects(t,e,s){let i=!1;const r=this._dropTarget;r&&r!==e&&r!==s&&(r.clearContextTop(),i=!0),null==e||e.clearContextTop(),s!==e&&(null==s||s.clearContextTop());const n=this.contextTop;n.save(),n.transform(...this.viewportTransform),e&&(n.save(),e.transform(n),e.renderDragSourceEffect(t),n.restore(),i=!0),s&&(n.save(),s.transform(n),s.renderDropTargetEffect(t),n.restore(),i=!0),n.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==L,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Nr(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),r=this._dragSource,n={e:t,target:s,subTargets:i,dragSource:r,canDrop:!1,dropTarget:void 0};let o;this.fire(e,n),this._fireEnterLeaveEvents(s,n),s&&(s.canDrop(t)&&(o=s),s.fire(e,n));for(let s=0;s<i.length;s++){const r=i[s];r.canDrop(t)&&(o=r),r.fire(e,n)}this._renderDragEffects(t,r,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",r({e:t,target:e,subTargets:s,dragSource:this._dragSource},Gr(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&ie(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const 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())}getPointerId(t){const 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){let e=!this.allowTouchScrolling;const s=this._activeObject;void 0===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,r=this._getEventPrefix(),n=Ut(i);Hr(n,"touchend",this._onTouchEnd,Vr),e&&Hr(n,"touchmove",this._onMouseMove,Vr),Nr(i,"".concat(r,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Nr(e,"".concat(s,"move"),this._onMouseMove,Vr);const i=Ut(e);Hr(i,"".concat(s,"up"),this._onMouseUp),Hr(i,"".concat(s,"move"),this._onMouseMove,Vr)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ut(this.upperCanvasEl);Nr(s,"touchend",this._onTouchEnd,Vr),Nr(s,"touchmove",this._onMouseMove,Vr),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Hr(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const t=Ut(this.upperCanvasEl);Nr(t,"".concat(s,"up"),this._onMouseUp),Nr(t,"".concat(s,"move"),this._onMouseMove,Vr),Hr(e,"".concat(s,"move"),this._onMouseMove,Vr)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,r=this._target,{button:n}=t;if(n)return(this.fireMiddleClick&&1===n||this.fireRightClick&&2===n)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,a,h=!1;if(s&&(this._finalizeCurrentTransform(t),h=s.actionPerformed),!i){const e=r===this._activeObject;this.handleSelection(t),h||(h=this._shouldRender(r)||!e&&r===this._activeObject)}if(r){const e=r.findControl(this.getViewportPoint(t),se(t)),{key:i,control:n}=e||{};if(a=i,r.selectable&&r!==this._activeObject&&"up"===r.activeOn)this.setActiveObject(r,t),h=!0;else if(n){const e=n.getMouseUpHandler(t,r,n);e&&(o=this.getScenePoint(t),e.call(n,t,s,o.x,o.y))}r.isMoving=!1}if(s&&(s.target!==r||s.corner!==a)){const e=s.target&&s.target.controls[s.corner],i=e&&e.getMouseUpHandler(t,s.target,e);o=o||this.getScenePoint(t),i&&i.call(e,t,s,o.x,o.y)}this._setCursorFromEvent(t,r),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,r&&(r.__corner=void 0),h?this.requestRenderAll():i||null!==(e=this._activeObject)&&void 0!==e&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],o=r(r(r({e:t,target:i,subTargets:n},Gr(this,t)),{},{transform:this._currentTransform},"up:before"===e||"up"===e?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),"down:before"===e||"down"===e?s:{});this.fire("mouse:".concat(e),o),i&&i.fire("mouse".concat(e),o);for(let t=0;t<n.length;t++)n[t]!==i&&n[t].fire("mouse".concat(e),o)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const 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){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&1===i||this.fireRightClick&&2===i)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t))return;if(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)){const e=this.getScenePoint(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);const i=e.findControl(this.getViewportPoint(t),se(t));if(e===this._activeObject&&(i||!n)){this._setupCurrentTransform(t,e,s);const r=i?i.control:void 0,n=this.getScenePoint(t),o=r&&r.getMouseDownHandler(t,e,r);o&&o.call(r,t,this._currentTransform,n.x,n.y)}}r&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),r&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=le(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const e=this.findTarget(t);this._setCursorFromEvent(t,e),this._fireOverOutEvents(t,e)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,r=this.targets,n=Math.max(i.length,r.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let e=0;e<n;e++)this.fireSyntheticInOutEvents("mouse",{e:t,target:r[e],oldTarget:i[e]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,o=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",r(r({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let t=0;t<o;t++)this.fireSyntheticInOutEvents("drag",r(r({},e),{},{target:n[t],oldTarget:i[t]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:o,e:a}=e,h=n(e,zr);const{targetIn:c,targetOut:l,canvasIn:u,canvasOut:d}=Ur[t],g=i!==s;if(i&&g){const t=r(r({},h),{},{e:a,target:i,nextTarget:s},Gr(this,a));o&&this.fire(d,t),i.fire(l,t)}if(s&&g){const t=r(r({},h),{},{e:a,target:s,previousTarget:i},Gr(this,a));o&&this.fire(u,t),s.fire(c,t)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,r=i.group?le(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,r),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:r,target:n}=e,o=!!r&&r(t,e,s.x,s.y);o&&n.setCoords(),"drag"===i&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=Ht(this._activeObject)?this._activeObject:null,r=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(r){const s=r.control;this.setCursor(s.cursorStyleHandler(t,s,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(t=>{s=t.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=Ht(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const i=s.getObjects();if(e===s){const s=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(i,s)||this.searchPossibleTargets(this._objects,s))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],1===s.size()&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(i,t)}else{s.isEditing&&s.exitEditing();const i=new(et.getClass("ActiveSelection"))([],{canvas:this});i.multiSelectAdd(s,e),this._hoveredTarget=i,this._setActiveObject(i,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:r}=this._groupSelector,n=new at(e,s),o=n.add(new at(i,r)),a=n.min(o),h=n.max(o).subtract(a),c=this.collectObjects({left:a.x,top:a.y,width:h.x,height:h.y},{includeIntersecting:!this.selectionFullyContained}),l=n.eq(o)?c[0]?[c[0]]:[]:c.length>1?c.filter(e=>!e.onSelect({e:t})).reverse():c;if(1===l.length)this.setActiveObject(l[0],t);else if(l.length>1){const e=et.getClass("ActiveSelection");this.setActiveObject(new e(l,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const Kr={x1:0,y1:0,x2:0,y2:0},Zr=r(r({},Kr),{},{r1:0,r2:0}),Qr=(t,e)=>isNaN(t)&&"number"==typeof e?e:t,Jr=/^(\d+\.\d+)%|(\d+)%$/;function $r(t){return t&&Jr.test(t)}function tn(t,e){const s="number"==typeof t?t:"string"==typeof t?parseFloat(t)/($r(t)?100:1):NaN;return fs(0,Qr(s,e),1)}const en=/\s*;\s*/,sn=/\s*:\s*/;function rn(t,e){let s,i;const r=t.getAttribute("style");if(r){const t=r.split(en);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){const[r,n]=t[e].split(sn).map(t=>t.trim());"stop-color"===r?s=n:"stop-opacity"===r&&(i=n)}}const n=new Me(s||t.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:tn(t.getAttribute("offset"),0),color:n.toRgb(),opacity:Qr(parseFloat(i||t.getAttribute("stop-opacity")||""),1)*n.getAlpha()*e}}function nn(t,e){const s=[],i=t.getElementsByTagName("stop"),r=tn(e,1);for(let t=i.length;t--;)s.push(rn(i[t],r));return s}function on(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function an(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}function hn(t,e){return t.getAttribute(e)}function cn(t,e){return function(t,e){let s,{width:i,height:r,gradientUnits:n}=e;return Object.keys(t).reduce((e,o)=>{const a=t[o];return"Infinity"===a?s=1:"-Infinity"===a?s=0:(s="string"==typeof a?parseFloat(a):a,"string"==typeof a&&$r(a)&&(s*=.01,"pixels"===n&&("x1"!==o&&"x2"!==o&&"r2"!==o||(s*=i),"y1"!==o&&"y2"!==o||(s*=r)))),e[o]=s,e},{})}("linear"===on(t)?function(t){return{x1:hn(t,"x1")||0,y1:hn(t,"y1")||0,x2:hn(t,"x2")||"100%",y2:hn(t,"y2")||0}}(t):function(t){return{x1:hn(t,"fx")||hn(t,"cx")||"50%",y1:hn(t,"fy")||hn(t,"cy")||"50%",r1:0,x2:hn(t,"cx")||"50%",y2:hn(t,"cy")||"50%",r2:hn(t,"r")||"50%"}}(t),r(r({},e),{},{gradientUnits:an(t)}))}class ln{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:o=0,offsetY:a=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:r(r({},"radial"===e?Zr:Kr),i),colorStops:n,offsetX:o,offsetY:a,gradientTransform:h,id:c?"".concat(c,"_").concat(ft()):ft()})}addColorStop(t){for(const e in t){const s=new Me(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return r(r({},It(this,t)),{},{type:this.type,coords:r({},this.coords),colorStops:this.colorStops.map(t=>r({},t)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():O.concat(),n="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map(t=>r({},t)).sort((t,e)=>t.offset-e.offset);let a=-this.offsetX,h=-this.offsetY;var c;"objectBoundingBox"===n?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),(c=t)&&"function"==typeof c._renderPathCommands&&"percentage"!==this.gradientUnits&&(a-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=a,i[5]-=h;const l=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Yt(i),'"'),""].join(" ");if("linear"===this.type){const{x1:t,y1:e,x2:i,y2:r}=this.coords;s.push("<linearGradient ",l,' x1="',t,'" y1="',e,'" x2="',i,'" y2="',r,'">\n')}else if("radial"===this.type){const{x1:t,y1:e,x2:i,y2:r,r1:n,r2:a}=this.coords,h=n>a;s.push("<radialGradient ",l,' cx="',h?t:i,'" cy="',h?e:r,'" r="',h?n:a,'" fx="',h?i:t,'" fy="',h?r:e,'">\n'),h&&(o.reverse(),o.forEach(t=>{t.offset=1-t.offset}));const c=Math.min(n,a);if(c>0){const t=c/Math.max(n,a);o.forEach(e=>{e.offset+=t*(1-e.offset)})}}return o.forEach(t=>{let{color:e,offset:i,opacity:r}=t;s.push("<stop ",'offset="',100*i+"%",'" style="stop-color:',e,void 0!==r?";stop-opacity: "+r:";",'"/>\n')}),s.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:r,r1:n,r2:o}=this.coords,a="linear"===this.type?t.createLinearGradient(e,s,i,r):t.createRadialGradient(e,s,n,i,r,o);return this.colorStops.forEach(t=>{let{color:e,opacity:s,offset:i}=t;a.addColorStop(i,void 0!==s?new Me(e).setAlpha(s).toRgba():e)}),a}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(r(r({},t),{},{colorStops:e?e.map(t=>r({},t)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=an(t),n=e._findCenterFromElement();return new this(r({id:t.getAttribute("id")||void 0,type:on(t),coords:cn(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:nn(t,s.opacity),gradientUnits:i,gradientTransform:qi(t.getAttribute("gradientTransform")||"")},"pixels"===i?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}s(ln,"type","Gradient"),et.setClass(ln,"gradient"),et.setClass(ln,"linear"),et.setClass(ln,"radial");const un=["type","source","patternTransform"];class dn{get type(){return"pattern"}set type(t){c("warn","Setting type has no effect",t)}constructor(t){s(this,"repeat","repeat"),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"crossOrigin",""),this.id=ft(),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(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return r(r({},It(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Xt(this.offsetX,h.NUM_FRACTION_DIGITS),offsetY:Xt(this.offsetY,h.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:i,repeat:r,id:n}=this,o=Qr(this.offsetX/e,0),a=Qr(this.offsetY/s,0),h="repeat-y"===r||"no-repeat"===r?1+Math.abs(o||0):Qr(i.width/e,0),c="repeat-x"===r||"no-repeat"===r?1+Math.abs(a||0):Qr(i.height/s,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(a,'" width="').concat(h,'" height="').concat(c,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join("\n")}static async fromObject(t,e){let{type:s,source:i,patternTransform:o}=t,a=n(t,un);const h=await Ft(i,r(r({},e),{},{crossOrigin:a.crossOrigin}));return new this(r(r({},a),{},{patternTransform:o&&o.slice(0),source:h}))}}s(dn,"type","Pattern"),et.setClass(dn),et.setClass(dn,"pattern");const gn=["path","left","top"],fn=["d"];class pn extends li{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{path:s,left:i,top:r}=e,o=n(e,gn);super(),Object.assign(this,pn.ownDefaults),this.setOptions(o),this._setPath(t||[],!0),"number"==typeof i&&this.set(E,i),"number"==typeof r&&this.set(A,r)}_setPath(t,e){this.path=(t=>{let e=0,s=0,i=0,r=0;const n=[];let o,a=0,h=0;for(const c of t){const t=[...c];let l;switch(t[0]){case"l":t[1]+=e,t[2]+=s;case"L":e=t[1],s=t[2],l=["L",e,s];break;case"h":t[1]+=e;case"H":e=t[1],l=["L",e,s];break;case"v":t[1]+=s;case"V":s=t[1],l=["L",e,s];break;case"m":t[1]+=e,t[2]+=s;case"M":e=t[1],s=t[2],i=t[1],r=t[2],l=["M",e,s];break;case"c":t[1]+=e,t[2]+=s,t[3]+=e,t[4]+=s,t[5]+=e,t[6]+=s;case"C":a=t[3],h=t[4],e=t[5],s=t[6],l=["C",t[1],t[2],a,h,e,s];break;case"s":t[1]+=e,t[2]+=s,t[3]+=e,t[4]+=s;case"S":"C"===o?(a=2*e-a,h=2*s-h):(a=e,h=s),e=t[3],s=t[4],l=["C",a,h,t[1],t[2],e,s],a=l[3],h=l[4];break;case"q":t[1]+=e,t[2]+=s,t[3]+=e,t[4]+=s;case"Q":a=t[1],h=t[2],e=t[3],s=t[4],l=["Q",a,h,e,s];break;case"t":t[1]+=e,t[2]+=s;case"T":"Q"===o?(a=2*e-a,h=2*s-h):(a=e,h=s),e=t[1],s=t[2],l=["Q",a,h,e,s];break;case"a":t[6]+=e,t[7]+=s;case"A":wr(e,s,t).forEach(t=>n.push(t)),e=t[6],s=t[7];break;case"z":case"Z":e=i,s=r,l=["Z"]}l?(n.push(l),o=l[0]):o=""}return n})(Array.isArray(t)?t:(t=>{var e;const s=[],i=null!==(e=t.match(Lr))&&void 0!==e?e:[];for(const t of i){const e=t[0];if("z"===e||"Z"===e){s.push([e]);continue}const i=Br[e.toLowerCase()];let r=[];if("a"===e||"A"===e){Fr.lastIndex=0;for(let e=null;e=Fr.exec(t);)r.push(...e.slice(1))}else r=t.match(Rr)||[];for(let t=0;t<r.length;t+=i){const n=new Array(i),o=yr[e];n[0]=t>0&&o?o:e;for(let e=0;e<i;e++)n[e+1]=parseFloat(r[t+e]);s.push(n)}}return s})(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new at(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return r(r({},super.toObject(t)),{},{path:this.path.map(t=>t.slice())})}toDatalessObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=((t,e)=>t.map(t=>t.map((t,s)=>0===s||void 0===e?t:Xt(t,e)).join(" ")).join(" "))(this.path,h.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,'" stroke-linecap="round" />\n')]}_getOffsetTransform(){const t=h.NUM_FRACTION_DIGITS;return" translate(".concat(Xt(-this.pathOffset.x,t),", ").concat(Xt(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,D,D)}_calcBoundsFromPath(){const t=[];let e=0,s=0,i=0,r=0;for(const n of this.path)switch(n[0]){case"L":i=n[1],r=n[2],t.push({x:e,y:s},{x:i,y:r});break;case"M":i=n[1],r=n[2],e=i,s=r;break;case"C":t.push(...br(i,r,n[1],n[2],n[3],n[4],n[5],n[6])),i=n[5],r=n[6];break;case"Q":t.push(...br(i,r,n[1],n[2],n[1],n[2],n[3],n[4])),i=n[3],r=n[4];break;case"Z":i=e,r=s}return re(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return r(r({},t),{},{pathOffset:new at(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const i=Qi(t,this.ATTRIBUTE_NAMES,s),{d:o}=i;return new this(o,r(r(r({},n(i,fn)),e),{},{left:void 0,top:void 0}))}}s(pn,"type","Path"),s(pn,"cacheProperties",[...ms,"path","fillRule"]),s(pn,"ATTRIBUTE_NAMES",[...Ci,"d"]),et.setClass(pn),et.setSVGClass(pn);const mn=["left","top","radius"],vn=["radius","startAngle","endAngle","counterClockwise"];class yn extends li{static getDefaults(){return r(r({},super.getDefaults()),yn.ownDefaults)}constructor(t){super(),Object.assign(this,yn.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),"radius"===t&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,xt(this.startAngle),xt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(N)}getRadiusY(){return this.get("radius")*this.get(U)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...vn,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(0===t)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),'" />\n'];{const{radius:e}=this,s=xt(this.startAngle),i=xt(this.endAngle),r=nt(s)*e,n=ot(s)*e,o=nt(i)*e,a=ot(i)*e,h=t>180?1:0,c=this.counterClockwise?0:1;return['<path d="M '.concat(r," ").concat(n," A ").concat(e," ").concat(e," 0 ").concat(h," ").concat(c," ").concat(o," ").concat(a,'" '),"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,s){const i=Qi(t,this.ATTRIBUTE_NAMES,s),{left:o=0,top:a=0,radius:h=0}=i;return new this(r(r({},n(i,mn)),{},{radius:h,left:o-h,top:a-h}))}static fromObject(t){return super._fromObject(t)}}s(yn,"type","Circle"),s(yn,"cacheProperties",[...ms,...vn]),s(yn,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),s(yn,"ATTRIBUTE_NAMES",["cx","cy","r",...Ci]),et.setClass(yn),et.setSVGClass(yn);const xn=["x1","y1","x2","y2"],_n=["x1","y1","x2","y2"],bn=["x1","x2","y1","y2"];class wn extends li{constructor(){let[t,e,s,i]=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0,0,0],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,wn.ownDefaults),this.setOptions(r),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:n,top:o}=r;"number"==typeof n&&this.set(E,n),"number"==typeof o&&this.set(A,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:r,top:n,width:o,height:a}=re([{x:t,y:e},{x:s,y:i}]),h=new at(r+o/2,n+a/2);this.setPositionByOrigin(h,D,D)}_set(t,e){return super._set(t,e),bn.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var i;zt(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=null!==(i=this.stroke)&&void 0!==i?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new at((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return r(r({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:i,width:r,height:n}=this,o=t<=e?-1:1,a=s<=i?-1:1;return{x1:o*r/2,x2:o*-r/2,y1:a*n/2,y2:a*-n/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,'" />\n')]}static async fromElement(t,e,s){const i=Qi(t,this.ATTRIBUTE_NAMES,s),{x1:r=0,y1:o=0,x2:a=0,y2:h=0}=i;return new this([r,o,a,h],n(i,xn))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:o}=t,a=n(t,_n);return this._fromObject(r(r({},a),{},{points:[e,s,i,o]}),{extraParam:"points"})}}s(wn,"type","Line"),s(wn,"cacheProperties",[...ms,...bn]),s(wn,"ATTRIBUTE_NAMES",Ci.concat(bn)),et.setClass(wn),et.setSVGClass(wn);class Cn extends li{static getDefaults(){return r(r({},super.getDefaults()),Cn.ownDefaults)}constructor(t){super(),Object.assign(this,Cn.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}s(Cn,"type","Triangle"),s(Cn,"ownDefaults",{width:100,height:100}),et.setClass(Cn),et.setSVGClass(Cn);const Sn=["rx","ry"];class Tn extends li{static getDefaults(){return r(r({},super.getDefaults()),Tn.ownDefaults)}constructor(t){super(),Object.assign(this,Tn.ownDefaults),this.setOptions(t)}_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(N)}getRy(){return this.get("ry")*this.get(U)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Sn,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(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,S,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Qi(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}s(Tn,"type","Ellipse"),s(Tn,"cacheProperties",[...ms,...Sn]),s(Tn,"ownDefaults",{rx:0,ry:0}),s(Tn,"ATTRIBUTE_NAMES",[...Ci,"cx","cy","rx","ry"]),et.setClass(Tn),et.setSVGClass(Tn);const On=["left","top"],kn={exactBoundingBox:!1};class Mn extends li{static getDefaults(){return r(r({},super.getDefaults()),Mn.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),s(this,"strokeDiff",void 0),Object.assign(this,Mn.ownDefaults),this.setOptions(e),this.points=t;const{left:i,top:r}=e;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof i&&this.set(E,i),"number"==typeof r&&this.set(A,r)}isOpen(){return!0}_projectStrokeOnPoints(t){return function(t,e){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const i=[];if(0===t.length)return i;const r=t.reduce((t,e)=>(t[t.length-1].eq(e)||t.push(new at(e)),t),[new at(t[0])]);if(1===r.length)s=!0;else if(!s){const t=r[0],e=((t,e)=>{for(let s=t.length-1;s>=0;s--)if(e(t[s]))return s;return-1})(r,e=>!e.eq(t));r.splice(e+1)}return r.forEach((t,r,n)=>{let o,a;0===r?(a=n[1],o=s?t:n[n.length-1]):r===n.length-1?(o=n[r-1],a=s?t:n[0]):(o=n[r-1],a=n[r+1]),s&&1===n.length?i.push(...new fi(t,t,e).project()):!s||0!==r&&r!==n.length-1?i.push(...new gi(t,o,a,e).project()):i.push(...new fi(t,0===r?a:o,e).project())}),i}(this.points,t,this.isOpen())}_calcDimensions(t){t=r({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||{});const 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 at,strokeOffset:new at,strokeDiff:new at};const s=re(e),i=Pt(r(r({},t),{},{scaleX:1,scaleY:1})),n=re(this.points.map(t=>bt(t,i,!0))),o=new at(this.scaleX,this.scaleY);let a=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(a-=h*Math.tan(xt(this.skewX)),h-=a*Math.tan(xt(this.skewY))),r(r({},s),{},{pathOffset:new at(a,h),strokeOffset:new at(n.left,n.top).subtract(new at(s.left,s.top)).multiply(o),strokeDiff:new at(s.width,s.height).subtract(new at(n.width,n.height)).multiply(o)})}_findCenterFromElement(){const t=re(this.points);return new at(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:r,pathOffset:n,strokeOffset:o,strokeDiff:a}=this._calcDimensions();this.set({width:i,height:r,pathOffset:n,strokeOffset:o,strokeDiff:a}),t&&this.setPositionByOrigin(new at(e+i/2,s+r/2),D,D)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new at(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.exactBoundingBox){let n;if(Object.keys(t).some(t=>this.strokeUniform||this.constructor.layoutProperties.includes(t))){var e,s;const{width:i,height:r}=this._calcDimensions(t);n=new at(null!==(e=t.width)&&void 0!==e?e:i,null!==(s=t.height)&&void 0!==s?s:r)}else{var i,r;n=new at(null!==(i=t.width)&&void 0!==i?i:this.width,null!==(r=t.height)&&void 0!==r?r:this.height)}return n.multiply(new at(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===N||t===U)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return r(r({},super.toObject(t)),{},{points:this.points.map(t=>{let{x:e,y:s}=t;return{x:e,y:s}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=h.NUM_FRACTION_DIGITS;for(let r=0,n=this.points.length;r<n;r++)t.push(Xt(this.points[r].x-e,i),",",Xt(this.points[r].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),'" />\n')]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let r=0;r<e;r++){const e=this.points[r];t.lineTo(e.x-s,e.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(function(t){if(!t)return[];const e=t.replace(/,/g," ").trim().split(/\s+/),s=[];for(let t=0;t<e.length;t+=2)s.push({x:parseFloat(e[t]),y:parseFloat(e[t+1])});return s}(t.getAttribute("points")),r(r({},n(Qi(t,this.ATTRIBUTE_NAMES,s),On)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}s(Mn,"ownDefaults",kn),s(Mn,"type","Polyline"),s(Mn,"layoutProperties",[q,K,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),s(Mn,"cacheProperties",[...ms,"points"]),s(Mn,"ATTRIBUTE_NAMES",[...Ci]),et.setClass(Mn),et.setSVGClass(Mn);class Dn extends Mn{isOpen(){return!1}}s(Dn,"ownDefaults",kn),s(Dn,"type","Polygon"),et.setClass(Dn),et.setSVGClass(Dn);class En extends li{isEmptyStyles(t){if(!this.styles)return!0;if(void 0!==t&&!this.styles[t])return!0;const e=void 0===t?this.styles:{line:this.styles[t]};for(const t in e)for(const s in e[t])for(const i in e[t][s])return!1;return!0}styleHas(t,e){if(!this.styles)return!1;if(void 0!==e&&!this.styles[e])return!1;const s=void 0===e?this.styles:{0:this.styles[e]};for(const e in s)for(const i in s[e])if(void 0!==s[e][i][t])return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,r=0,n=!0,o=0;for(const o in e){s=0;for(const a in e[o]){const h=e[o][a]||{};r++,void 0!==h[t]?(i?h[t]!==i&&(n=!1):i=h[t],h[t]===this[t]&&delete h[t]):n=!1,0!==Object.keys(h).length?s++:delete e[o][a]}0===s&&delete e[o]}for(let t=0;t<this._textLines.length;t++)o+=this._textLines[t].length;n&&r===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,r;for(i in e){for(r in s=e[i],s)delete s[r][t],0===Object.keys(s[r]).length&&delete s[r];0===Object.keys(s).length&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=Wt(r(r({},this._getStyleDeclaration(s,i)),e),t=>void 0!==t);this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let r=t;r<(e||t);r++)i.push(this.getStyleAtPosition(r,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&null!==(s=i[e])&&void 0!==s?s:{}}getCompleteStyleDeclaration(t,e){return r(r({},It(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_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]}}s(En,"_styleProperties",Ie);const An=/ +/g,jn=/"/g;function Pn(t,e,s,i,r){return"\t\t".concat(function(t,e){let{left:s,top:i,width:r,height:n}=e,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:h.NUM_FRACTION_DIGITS;const a=Ee(Z,t,!1),[c,l,u,d]=[s,i,r,n].map(t=>Xt(t,o));return"<rect ".concat(a,' x="').concat(c,'" y="').concat(l,'" width="').concat(u,'" height="').concat(d,'"></rect>')}(t,{left:e,top:s,width:i,height:r}),"\n")}const Ln=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Fn;class Rn extends En{static getDefaults(){return r(r({},super.getDefaults()),Rn.ownDefaults)}constructor(t,e){super(),s(this,"__charBounds",[]),Object.assign(this,Rn.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=jr(t.path))}_splitText(){const 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(Xe)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,r,n,o;for(let a=0,h=this._textLines.length;a<h;a++)if((this.textAlign===Xe||a!==h-1&&!this.isEndOfWrapping(a))&&(i=0,r=this._textLines[a],e=this.getLineWidth(a),e<this.width&&(o=this.textLines[a].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let e=0;e<=r.length;e++)n=this.__charBounds[a][e],this._reSpaceAndTab.test(r[e])?(n.width+=t,n.kernedWidth+=t,n.left+=i,i+=t):n.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;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 (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const 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){this.paintFirst===Q?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case D:t.textBaseline="middle";break;case"ascender":t.textBaseline=A;break;case"descender":t.textBaseline=j}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const s=this.getLineWidth(e);s>t&&(t=s)}return t}_renderTextLine(t,e,s,i,r,n){this._renderChars(t,e,s,i,r,n)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let e=0,r=this._textLines.length;e<r;e++){const r=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){i+=r;continue}const n=this._textLines[e].length,o=this._getLineLeftOffset(e);let a,h,c=0,l=0,u=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let d=0;d<n;d++){const n=this.__charBounds[e][d];h=this.getValueOfPropertyAt(e,d,"textBackgroundColor"),this.path?(t.save(),t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillStyle=h,h&&t.fillRect(-n.width/2,-r/this.lineHeight*(1-this._fontSizeFraction),n.width,r/this.lineHeight),t.restore()):h!==u?(a=s+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=u,u&&t.fillRect(a,i,c,r/this.lineHeight),l=n.left,c=n.width,u=h):c+=n.kernedWidth}h&&!this.path&&(a=s+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=h,t.fillRect(a,i,c,r/this.lineHeight)),i+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const r=_.getFontCache(e),n=this._getFontDeclaration(e),o=s+t,a=s&&n===this._getFontDeclaration(i),h=e.fontSize/this.CACHE_FONT_SIZE;let c,l,u,d;if(s&&void 0!==r[s]&&(u=r[s]),void 0!==r[t]&&(d=c=r[t]),a&&void 0!==r[o]&&(l=r[o],d=l-u),void 0===c||void 0===u||void 0===l){const i=function(){if(!Fn){const t=mt({width:0,height:0});Fn=t.getContext("2d")}return Fn}();this._setTextStyles(i,e,!0),void 0===c&&(d=c=i.measureText(t).width,r[t]=c),void 0===u&&a&&s&&(u=i.measureText(s).width,r[s]=u),a&&void 0===l&&(l=i.measureText(o).width,r[o]=l,d=l-u)}return{width:c*h,kernedWidth:d*h}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const r=this.pathSide===P,n=this.path,o=this._textLines[t],a=o.length,h=new Array(a);this.__charBounds[t]=h;for(let r=0;r<a;r++){const n=o[r];s=this._getGraphemeBox(n,t,r,e),h[r]=s,i+=s.kernedWidth,e=n}if(h[a]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},n&&n.segmentsInfo){let t=0;const e=n.segmentsInfo[n.segmentsInfo.length-1].length;switch(this.textAlign){case E:t=r?e-i:0;break;case D:t=(e-i)/2;break;case P:t=r?0:e-i}t+=this.pathStartOffset*(r?-1:1);for(let i=r?a-1:0;r?i>=0:i<a;r?i--:i++)s=h[i],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,s),t+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,r=Pr(i.path,s,i.segmentsInfo);e.renderLeft=r.x-i.pathOffset.x,e.renderTop=r.y-i.pathOffset.y,e.angle=r.angle+(this.pathSide===P?Math.PI:0)}_getGraphemeBox(t,e,s,i,r){const n=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},a=this._measureChar(t,n,i,o);let h,c=a.kernedWidth,l=a.width;0!==this.charSpacing&&(h=this._getWidthOfCharSpacing(),l+=h,c+=h);const u={width:l,left:0,height:n.fontSize,kernedWidth:c,deltaY:n.deltaY};if(s>0&&!r){const t=this.__charBounds[e][s-1];u.left=t.left+t.width+a.kernedWidth-a.width}return u}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),r=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const o=this.getHeightOfLine(n),a=o/this.lineHeight,h=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],i+h,r+s+a,n),s+=o}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(Z))&&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,s,i,r,n){const o=this.getHeightOfLine(n),a=this.textAlign.includes(Xe),h=this.path,c=!a&&0===this.charSpacing&&this.isEmptyStyles(n)&&!h,l="ltr"===this.direction,u="ltr"===this.direction?1:-1,d=e.direction;let g,f,p,m,v,y="",x=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",l?"ltr":"rtl"),e.direction=l?"ltr":"rtl",e.textAlign=l?E:P),r-=o*this._fontSizeFraction/this.lineHeight,c)return this._renderChar(t,e,n,0,s.join(""),i,r),void e.restore();for(let o=0,c=s.length-1;o<=c;o++)m=o===c||this.charSpacing||h,y+=s[o],p=this.__charBounds[n][o],0===x?(i+=u*(p.kernedWidth-p.width),x+=p.width):x+=p.kernedWidth,a&&!m&&this._reSpaceAndTab.test(s[o])&&(m=!0),m||(g=g||this.getCompleteStyleDeclaration(n,o),f=this.getCompleteStyleDeclaration(n,o+1),m=_i(g,f,!1)),m&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,n,o,y,-x/2,0),e.restore()):(v=i,this._renderChar(t,e,n,o,y,v,r)),y="",g=f,i+=u*x,x=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=mt({width:e,height:s}),r=i.getContext("2d");return i.width=e,i.height=s,r.beginPath(),r.moveTo(0,0),r.lineTo(e,0),r.lineTo(e,s),r.lineTo(0,s),r.closePath(),r.translate(e/2,s/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,r;return zt(s)?"percentage"===s.gradientUnits||s.gradientTransform||s.patternTransform?(i=-this.width/2,r=-this.height/2,t.translate(i,r),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:r}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,r,n,o){const a=this._getStyleDeclaration(s,i),h=this.getCompleteStyleDeclaration(s,i),c="fillText"===t&&h.fill,l="strokeText"===t&&h.stroke&&h.strokeWidth;if(l||c){if(e.save(),e.font=this._getFontDeclaration(h),a.textBackgroundColor&&this._removeShadow(e),a.deltaY&&(o+=a.deltaY),c){const t=this._setFillStyles(e,h);e.fillText(r,n-t.offsetX,o-t.offsetY)}if(l){const t=this._setStrokeStyles(e,h);e.strokeText(r,n-t.offsetX,o-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,s){const i=this.get2DCursorLocation(t,!0),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:r*s.size,deltaY:n+r*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,r=this.direction,n=this.isEndOfWrapping(t);let o=0;return i===Xe||i===Ve&&!n||i===ze&&!n||i===Ye&&!n?0:(i===D&&(o=s/2),i===P&&(o=s),i===Ve&&(o=s/2),i===ze&&(o=s),"rtl"===r&&(i===P||i===Xe||i===ze?o=0:i===E||i===Ye?o=-s:i!==D&&i!==Ve||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return null!==(i=this._getStyleDeclaration(t,e)[s])&&void 0!==i?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),r=this.path,n=this._getWidthOfCharSpacing(),o="linethrough"===e?.5:"overline"===e?1:0,a=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const c=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=c;continue}const l=this._textLines[h],u=c/this.lineHeight,d=this._getLineLeftOffset(h);let g=0,f=0,p=this.getValueOfPropertyAt(h,0,e),m=this.getValueOfPropertyAt(h,0,Z),v=this.getValueOfPropertyAt(h,0,Pe),y=p,x=m,_=v;const b=s+u*(1-this._fontSizeFraction);let w=this.getHeightOfChar(h,0),C=this.getValueOfPropertyAt(h,0,"deltaY");for(let s=0,n=l.length;s<n;s++){const n=this.__charBounds[h][s];y=this.getValueOfPropertyAt(h,s,e),x=this.getValueOfPropertyAt(h,s,Z),_=this.getValueOfPropertyAt(h,s,Pe);const c=this.getHeightOfChar(h,s),l=this.getValueOfPropertyAt(h,s,"deltaY");if(r&&y&&x){const e=this.fontSize*_/1e3;t.save(),t.fillStyle=m,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,a*c+l-o*e,n.kernedWidth,e),t.restore()}else if((y!==p||x!==m||c!==w||_!==v||l!==C)&&f>0){const e=this.fontSize*v/1e3;let s=i+d+g;"rtl"===this.direction&&(s=this.width-s-f),p&&m&&v&&(t.fillStyle=m,t.fillRect(s,b+a*w+C-o*e,f,e)),g=n.left,f=n.width,p=y,v=_,m=x,w=c,C=l}else f+=n.kernedWidth}let S=i+d+g;"rtl"===this.direction&&(S=this.width-S-f),t.fillStyle=x;const T=this.fontSize*_/1e3;y&&x&&_&&t.fillRect(S,b+a*w+C-o*T,f-n,T),s+=c}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;const n=t.includes("'")||t.includes('"')||t.includes(",")||Rn.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(r?this.CACHE_FONT_SIZE:i,"px"),n].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return vi(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=["\n"];let r=[];for(let t=0;t<e.length;t++)s[t]=this.graphemeSplit(e[t]),r=r.concat(s[t],i);return r.pop(),{_unwrappedLines:s,lines:e,graphemeText:r,graphemeLines:s}}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return r(r({},super.toObject([...Be,...t])),{},{styles:bi(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,r=!1;if("object"==typeof t)for(const e in t)"path"===e&&this.setPathInfo(),i=i||s.includes(e),r=r||"path"===e;else i=s.includes(t),r="path"===t;return r&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Qi(t,Rn.ATTRIBUTE_NAMES,s),o=r(r({},e),i),{textAnchor:a=E,textDecoration:h="",dx:c=0,dy:l=0,top:u=0,left:d=0,fontSize:g=k,strokeWidth:f=1}=o,p=n(o,Ln),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),r({left:d+c,top:u+l,underline:h.includes("underline"),overline:h.includes("overline"),linethrough:h.includes("line-through"),strokeWidth:0,fontSize:g},p)),v=m.getScaledHeight()/m.height,y=((m.height+m.strokeWidth)*m.lineHeight-m.height)*v,x=m.getScaledHeight()+y;let _=0;return a===D&&(_=m.getScaledWidth()/2),a===P&&(_=m.getScaledWidth()),m.set({left:m.left-_,top:m.top-(x-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(r(r({},t),{},{styles:wi(t.styles||{},t.text)}),{extraParam:"text"})}}s(Rn,"textLayoutProperties",Re),s(Rn,"cacheProperties",[...ms,...Be]),s(Rn,"ownDefaults",We),s(Rn,"type","Text"),s(Rn,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),s(Rn,"ATTRIBUTE_NAMES",Ci.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),ci(Rn,[class extends Ae{_toSVG(){const t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){const e=this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0}),s=this.path;return s?e+s._createBaseSVGMarkup(s._toSVG(),{reviver:t,withShadow:!0,additionalTransform:Yt(this.calcOwnMatrix())}):e}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(t){let{textBgRects:e,textSpans:s}=t;const i=this.getSvgTextDecoration(this);return[e.join(""),'\t\t<text xml:space="preserve" ','font-family="'.concat(this.fontFamily.replace(jn,"'"),'" '),'font-size="'.concat(this.fontSize,'" '),this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",i?'text-decoration="'.concat(i,'" '):"","rtl"===this.direction?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",s.join(""),"</text>\n"]}_getSVGTextAndBg(t,e){const s=[],i=[];let r,n=t;this.backgroundColor&&i.push(...Pn(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let t=0,o=this._textLines.length;t<o;t++)r=this._getLineLeftOffset(t),"rtl"===this.direction&&(r+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",t))&&this._setSVGTextLineBg(i,t,e+r,n),this._setSVGTextLineText(s,t,e+r,n),n+=this.getHeightOfLine(t);return{textSpans:s,textBgRects:i}}_createTextCharSpan(t,e,s,i,r){const n=h.NUM_FRACTION_DIGITS,o=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(An)),a=o?'style="'.concat(o,'"'):"",c=e.deltaY,l=c?' dy="'.concat(Xt(c,n),'" '):"",{angle:u,renderLeft:d,renderTop:g,width:f}=r;let p="";if(void 0!==d){const t=f/2;u&&(p=' rotate="'.concat(Xt(_t(u),n),'"'));const e=Mt({angle:_t(u)});e[4]=d,e[5]=g;const r=new at(-t,0).transform(e);s=r.x,i=r.y}return'<tspan x="'.concat(Xt(s,n),'" y="').concat(Xt(i,n),'" ').concat(l).concat(p).concat(a,">").concat((t=>t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"))(t),"</tspan>")}_setSVGTextLineText(t,e,s,i){const r=this.getHeightOfLine(e),n=this.textAlign.includes(Xe),o=this._textLines[e];let a,h,c,l,u,d="",g=0;i+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let r=0,f=o.length-1;r<=f;r++)u=r===f||this.charSpacing||this.path,d+=o[r],c=this.__charBounds[e][r],0===g?(s+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!u&&this._reSpaceAndTab.test(o[r])&&(u=!0),u||(a=a||this.getCompleteStyleDeclaration(e,r),h=this.getCompleteStyleDeclaration(e,r+1),u=_i(a,h,!0)),u&&(l=this._getStyleDeclaration(e,r),t.push(this._createTextCharSpan(d,l,s,i,c)),d="",a=h,"rtl"===this.direction?s-=g:s+=g,g=0)}_setSVGTextLineBg(t,e,s,i){const r=this._textLines[e],n=this.getHeightOfLine(e)/this.lineHeight;let o,a=0,h=0,c=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let l=0;l<r.length;l++){const{left:r,width:u,kernedWidth:d}=this.__charBounds[e][l];o=this.getValueOfPropertyAt(e,l,"textBackgroundColor"),o!==c?(c&&t.push(...Pn(c,s+h,i,a,n)),h=r,a=u,c=o):a+=d}o&&t.push(...Pn(c,s+h,i,a,n))}_getSVGLineTopOffset(t){let e,s=0;for(e=0;e<t;e++)s+=this.getHeightOfLine(e);const i=this.getHeightOfLine(e);return{lineTop:s,offset:(this._fontSizeMult-this._fontSizeFraction)*i/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(t){return"".concat(super.getSvgStyles(t)," text-decoration-thickness: ").concat(Xt(this.textDecorationThickness*this.getObjectScaling().y/10,h.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(t,e){const{fontFamily:s,strokeWidth:i,stroke:r,fill:n,fontSize:o,fontStyle:a,fontWeight:c,deltaY:l,textDecorationThickness:u,linethrough:d,overline:g,underline:f}=t,p=this.getSvgTextDecoration({underline:null!=f?f:this.underline,overline:null!=g?g:this.overline,linethrough:null!=d?d:this.linethrough}),m=u||this.textDecorationThickness;return[r?Ee(Q,r):"",i?"stroke-width: ".concat(i,"; "):"",s?"font-family: ".concat(s.includes("'")||s.includes('"')?s:"'".concat(s,"'"),"; "):"",o?"font-size: ".concat(o,"px; "):"",a?"font-style: ".concat(a,"; "):"",c?"font-weight: ".concat(c,"; "):"",p?"text-decoration: ".concat(p,"; text-decoration-thickness: ").concat(Xt(m*this.getObjectScaling().y/10,h.NUM_FRACTION_DIGITS),"%; "):"",n?Ee(Z,n):"",l?"baseline-shift: ".concat(-l,"; "):"",e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter(e=>t[e.replace("-","")]).join(" ")}}]),et.setClass(Rn),et.setSVGClass(Rn);class Bn{constructor(t){s(this,"target",void 0),s(this,"__mouseDownInPlace",!1),s(this,"__dragStartFired",!1),s(this,"__isDraggingOver",!1),s(this,"__dragStartSelection",void 0),s(this,"__dragImageDisposer",void 0),s(this,"_dispose",void 0),this.target=t;const 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){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const 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,e){var s;let{selectionStart:i,selectionEnd:r}=e;const n=this.target,o=n.canvas,a=new at(n.flipX?-1:1,n.flipY?-1:1),h=n._getCursorBoundaries(i),c=new at(h.left+h.leftOffset,h.top+h.topOffset).multiply(a).transform(n.calcTransformMatrix()),l=o.getScenePoint(t).subtract(c),u=n.getCanvasRetinaScaling(),d=n.getBoundingRect(),g=c.subtract(new at(d.left,d.top)),f=o.viewportTransform,p=g.add(l).transform(f,!0),m=n.backgroundColor,v=pi(n.styles);n.backgroundColor="";const y={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};n.setSelectionStyles(y,0,i),n.setSelectionStyles(y,r,n.text.length),n.dirty=!0;const x=n.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});n.backgroundColor=m,n.styles=v,n.dirty=!0,Ir(x,{position:"fixed",left:"".concat(-x.width,"px"),border:L,width:"".concat(x.width/u,"px"),height:"".concat(x.height/u,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{x.remove()},Ut(t.target||this.target.hiddenTextarea).body.appendChild(x),null===(s=t.dataTransfer)||void 0===s||s.setDragImage(x,p.x,p.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const s=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},i=e._text.slice(s.selectionStart,s.selectionEnd).join(""),n=r({text:e.text,value:i},s);t.dataTransfer.setData("text/plain",i),t.dataTransfer.setData("application/fabric",JSON.stringify({value:i,styles:e.getSelectionStyles(s.selectionStart,s.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,n)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e:e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e:e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(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;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let r=null===(e=s.dataTransfer)||void 0===e?void 0:e.getData("text/plain");if(r&&!i){const e=this.target,i=e.canvas;let n=e.getSelectionStartFromPointer(s);const{styles:o}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},a=r[Math.max(0,r.length-1)],h=0;if(this.__dragStartSelection){const t=this.__dragStartSelection.selectionStart,s=this.__dragStartSelection.selectionEnd;n>t&&n<=s?n=t:n>s&&(n-=s-t),e.removeChars(t,s),delete this.__dragStartSelection}e._reNewline.test(a)&&(e._reNewline.test(e._text[n])||n===e._text.length)&&(r=r.trimEnd()),t.didDrop=!0,t.dropTarget=e,e.insertChars(r,o,n),i.setActiveObject(e),e.enterEditing(s),e.selectionStart=Math.min(n+h,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(G,{index:n+h,action:"drop"}),i.fire("text:changed",{target:e}),i.contextTopDirty=!0,i.requestRenderAll()}}dragEndHandler(t){let{e:e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const t=this.target,i=this.target.canvas,{selectionStart:r,selectionEnd:n}=this.__dragStartSelection,o=(null===(s=e.dataTransfer)||void 0===s?void 0:s.dropEffect)||L;o===L?(t.selectionStart=r,t.selectionEnd=n,t._updateTextarea(),t.hiddenTextarea.focus()):(t.clearContextTop(),"move"===o&&(t.removeChars(r,n),t.selectionStart=t.selectionEnd=r,t.hiddenTextarea&&(t.hiddenTextarea.value=t.text),t._updateTextarea(),t.fire(G,{index:r,action:"dragend"}),i.fire("text:changed",{target:t}),i.requestRenderAll()),t.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const In=/[ \n\.,;!\?\-]/;class Wn extends Rn{constructor(){super(...arguments),s(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(t){let{toValue:e,duration:s,delay:i,onComplete:r}=t;return Ds({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:r,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)||void 0===t||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,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(-1===e||!F.test(s[t-1]))?t-1:t,r=s[i];for(;i>0&&i<s.length&&!In.test(r);)i+=e,r=s[i];return-1===e&&In.test(r)&&i++,i}selectWord(t){var e;t=null!==(e=t)&&void 0!==e?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=null!==(e=t)&&void 0!==e?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,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;const e=this.hiddenTextarea;Ut(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,r=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==r||i!==s&&r!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&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,s){const i=s.slice(0,t),r=this.graphemeSplit(i).length;if(t===e)return{selectionStart:r,selectionEnd:r};const n=s.slice(t,e);return{selectionStart:r,selectionEnd:r+this.graphemeSplit(n).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,r=s.charIndex,n=this.getValueOfPropertyAt(i,r,"fontSize")*this.lineHeight,o=e.leftOffset,a=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,c=h.width/a,l=h.height/a,u=c-n,d=l-n,g=new at(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new at(h.clientWidth/c,h.clientHeight/l));return g.x<0&&(g.x=0),g.x>u&&(g.x=u),g.y<0&&(g.y=0),g.y>d&&(g.y=d),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_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)}_exitEditing(){const 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()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(J),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:r,charIndex:n}=this.get2DCursorLocation(e,!0);if(s!==r){if(this.styles[s])for(let t=i;t<this._unwrappedTextLines[s].length;t++)delete this.styles[s][t];if(this.styles[r])for(let t=n;t<this._unwrappedTextLines[r].length;t++){const e=this.styles[r][t];e&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+t-n]=e)}for(let t=s+1;t<=r;t++)delete this.styles[t];this.shiftLineStyles(r,s-r)}else if(this.styles[s]){const t=this.styles[s],e=n-i;for(let e=i;e<n;e++)delete t[e];for(const i in this.styles[s]){const s=parseInt(i,10);s>=n&&(t[s-e]=t[i],delete t[i])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const r=parseInt(i,10);r>t&&(this.styles[r+e]=s[r],s[r-e]||delete this.styles[r])}}insertNewlineStyleObject(t,e,s,i){const n={},o=this._unwrappedTextLines[t].length,a=o===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][0===e?e:e-1]:void 0;for(const s in this.styles[t]){const i=parseInt(s,10);i>=e&&(h=!0,n[i-e]=this.styles[t][s],a&&0===e||delete this.styles[t][s])}let l=!1;for(h&&!a&&(this.styles[t+s]=n,l=!0),(l||o>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:r({},i[s-1])}:c?this.styles[t+s]={0:r({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],o=n?r({},n):{};s||(s=1);for(const t in o){const i=parseInt(t,10);i>=e&&(n[i+s]=o[i],o[i-s]||delete n[i])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=r({},i[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=r({},a)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),r=[0];let n,o=0;for(let e=0;e<t.length;e++)"\n"===t[e]?(o++,r[o]=0):r[o]++;for(r[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,r[0],s),s=s&&s.slice(r[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+r[0],o),n=1;n<o;n++)r[n]>0?this.insertCharStyleObject(i.lineIndex+n,0,r[n],s):s&&this.styles[i.lineIndex+n]&&s[0]&&(this.styles[i.lineIndex+n][0]=s[0]),s=s&&s.slice(r[n]+1);r[n]>0&&this.insertCharStyleObject(i.lineIndex+n,0,r[n],s)}removeChars(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]: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,s){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const r=this.graphemeSplit(t);this.insertNewStyleBlock(r,s,e),this._text=[...this._text.slice(0,s),...r,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=E:this._selectionDirection===P&&(this._selectionDirection=E,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===P?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=P:this._selectionDirection===E&&(this._selectionDirection=P,this.selectionStart=e),this.selectionEnd=s)}}class Xn extends Wn{initHiddenTextarea(){const t=this.canvas&&Ut(this.canvas.getElement())||v(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(t=>{let[s,i]=t;return e.setAttribute(s,i)});const{top:s,left:i,fontSize:r}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(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=>{let[s,i]=t;return e.addEventListener(s,this[i].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const 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){const e=this.fromPaste,{value:s,selectionStart:i,selectionEnd:r}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const n=()=>{this.updateFromTextArea(),this.fire(G),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void n();const o=this._splitTextIntoLines(s).graphemeText,a=this._text.length,c=o.length,l=this.selectionStart,u=this.selectionEnd,d=l!==u;let g,f,p,v,y=c-a;const x=this.fromStringToGraphemeSelection(i,r,s),_=l>x.selectionStart;d?(f=this._text.slice(l,u),y+=u-l):c<a&&(f=_?this._text.slice(u+y,u):this._text.slice(l,l-y));const b=o.slice(x.selectionEnd-y,x.selectionEnd);if(f&&f.length&&(b.length&&(g=this.getSelectionStyles(l,l+1,!1),g=b.map(()=>g[0])),d?(p=l,v=u):_?(p=u-f.length,v=u):(p=u,v=u+f.length),this.removeStyleFromTo(p,v)),b.length){const{copyPasteData:t}=m();e&&b.join("")===t.copiedText&&!h.disableStyleCopyPaste&&(g=t.copiedTextStyle),this.insertNewStyleBlock(b,l,g)}n()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=m();t.copiedText=this.getSelectedText(),h.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),r=i.lineIndex;if(r===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-s;const n=i.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r+1,o);return this._textLines[r].slice(n).length+a+1+this.missingNewlineOffset(r)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),r=i.lineIndex;if(0===r||t.metaKey||33===t.keyCode)return-s;const n=i.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r-1,o),h=this._textLines[r].slice(0,n),c=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+a-h.length+(1-c)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,r,n=this._getLineLeftOffset(t),o=0;for(let a=0,h=s.length;a<h;a++)if(i=this.__charBounds[t][a].width,n+=i,n>e){r=!0;const t=n-i,s=n,h=Math.abs(t-e);o=Math.abs(s-e)<h?a:a-1;break}return r||(o=s.length-1),o}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){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===P);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),0!==s){const t=this.text.length;this.selectionStart=fs(0,this.selectionStart,t),this.selectionEnd=fs(0,this.selectionEnd,t),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===E?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),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,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===s?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return void 0!==i&&this[e]!==i&&(this[e]=i,!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=E,this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===P&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection=E,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===E&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=P,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=P,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Yn=t=>!!t.button;class zn extends Xn{constructor(){super(...arguments),s(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 Bn(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(t){let{e:e,alreadySelected:s}=t;this.canvas&&this.editable&&!Yn(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}mouseUpHandler(t){let{e:e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const t=this.canvas._activeObject;if(t&&t!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Yn(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(wt(this.calcTransformMatrix())).add(new at(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,r=0;for(let t=0;t<this._textLines.length&&s<=e.y;t++)s+=this.getHeightOfLine(t),r=t,t>0&&(i+=this._textLines[t-1].length+this.missingNewlineOffset(t-1));let n=Math.abs(this._getLineLeftOffset(r));const o=this._textLines[r].length,a=this.__charBounds[r];for(let t=0;t<o;t++){const s=n+a[t].kernedWidth;if(e.x<=s){Math.abs(e.x-s)<=Math.abs(e.x-n)&&i++;break}n=s,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const Vn="moveCursorUp",Gn="moveCursorDown",Hn="moveCursorLeft",Nn="moveCursorRight",Un="exitEditing",qn=(t,e)=>{const s=e.getRetinaScaling();t.setTransform(s,0,0,s,0,0);const i=e.viewportTransform;t.transform(i[0],i[1],i[2],i[3],i[4],i[5])},Kn=r({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:Un,27:Un,33:Vn,34:Gn,35:Nn,36:Hn,37:Hn,38:Vn,39:Nn,40:Gn},keysMapRtl:{9:Un,27:Un,33:Vn,34:Gn,35:Hn,36:Nn,37:Nn,38:Vn,39:Hn,40:Gn},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Zn extends zn{static getDefaults(){return r(r({},super.getDefaults()),Zn.ownDefaults)}get type(){const t=super.type;return"itext"===t?"i-text":t}constructor(t,e){super(t,r(r({},Zn.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof qr&&this.canvas.textEditingManager.remove(this),e instanceof qr&&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(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart||0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionStart||0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let r,n=t;if(i){r=mt(t.canvas),n=r.getContext("2d"),qn(n,this.canvas);const e=this.calcTransformMatrix();n.transform(e[0],e[1],e[2],e[3],e[4],e[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(n,e):this.renderCursor(n,e),i)for(const e of s){const s=e.clipPath,i=mt(t.canvas),r=i.getContext("2d");if(qn(r,this.canvas),!s.absolutePositioned){const t=e.calcTransformMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5])}s.transform(r),s.drawObject(r,!0,{}),this.drawClipPathOnCache(n,s,i)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(r,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),r=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,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,s=0;const{charIndex:i,lineIndex:r}=this.get2DCursorLocation(t);for(let t=0;t<r;t++)e+=this.getHeightOfLine(t);const n=this._getLineLeftOffset(r),o=this.__charBounds[r][i];o&&(s=o.left),0!==this.charSpacing&&i===this._textLines[r].length&&(s-=this._getWidthOfCharSpacing());const a={top:e,left:n+(s>0?s:0)};return"rtl"===this.direction&&(this.textAlign===P||this.textAlign===Xe||this.textAlign===ze?a.left*=-1:this.textAlign===E||this.textAlign===Ye?a.left=n-(s>0?s:0):this.textAlign!==D&&this.textAlign!==Ve||(a.left=n-(s>0?s:0))),a}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,r=s.charIndex>0?s.charIndex-1:0,n=this.getValueOfPropertyAt(i,r,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),a=this.cursorWidth/o,h=this.getValueOfPropertyAt(i,r,"deltaY"),c=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-n*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,r,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-a/2,top:c+e.top+h,width:a,height:n}}_renderCursor(t,e,s){const{color:i,opacity:r,left:n,top:o,width:a,height:h}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=r,t.fillRect(n,o,a,h)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,r=e.selectionEnd,n=this.textAlign.includes(Xe),o=this.get2DCursorLocation(i),a=this.get2DCursorLocation(r),h=o.lineIndex,c=a.lineIndex,l=o.charIndex<0?0:o.charIndex,u=a.charIndex<0?0:a.charIndex;for(let e=h;e<=c;e++){const i=this._getLineLeftOffset(e)||0;let r=this.getHeightOfLine(e),o=0,a=0,d=0;if(e===h&&(a=this.__charBounds[h][l].left),e>=h&&e<c)d=n&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===c)if(0===u)d=this.__charBounds[c][u].left;else{const t=this._getWidthOfCharSpacing();d=this.__charBounds[c][u-1].left+this.__charBounds[c][u-1].width-t}o=r,(this.lineHeight<1||e===c&&this.lineHeight>1)&&(r/=this.lineHeight);let g=s.left+i+a,f=r,p=0;const m=d-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",f=1,p=r):t.fillStyle=this.selectionColor,"rtl"===this.direction&&(this.textAlign===P||this.textAlign===Xe||this.textAlign===ze?g=this.width-g-m:this.textAlign===E||this.textAlign===Ye?g=s.left+i-d:this.textAlign!==D&&this.textAlign!==Ve||(g=s.left+i-d)),t.fillRect(g,s.top+s.topOffset+p,m,f),s.topOffset+=o}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,Z)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}s(Zn,"ownDefaults",Kn),s(Zn,"type","IText"),et.setClass(Zn),et.setClass(Zn,"i-text");class Qn extends Zn{static getDefaults(){return r(r({},super.getDefaults()),Qn.ownDefaults)}constructor(t,e){super(t,r(r({},Qn.ownDefaults),e))}static createControls(){return{controls:ai()}}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(Xe)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const r={};for(let n=0;n<t.graphemeLines.length;n++)"\n"===t.graphemeText[i]&&n>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&n>0&&(s++,i++),r[n]={line:e,offset:s},i+=t.graphemeLines[n].length,s+=t.graphemeLines[n].length;return r}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const t=this._styleMap[e];t&&(e=t.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,r=!1;const n=this._styleMap[t],o=this._styleMap[t+1];n&&(t=n.line,s=n.offset),o&&(i=o.line,r=i===t,e=o.offset);const a=void 0===t?this.styles:{line:this.styles[t]};for(const t in a)for(const i in a[t]){const n=parseInt(i,10);if(n>=s&&(!r||n<e))for(const e in a[t][i])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let t=0;t<s.wordsData.length;t++)i.push(...this._wrapLine(t,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((t,r)=>{let n=0;const o=e?this.graphemeSplit(t):this.wordSplit(t);return 0===o.length?[{word:[],width:0}]:o.map(t=>{const o=e?[t]:this.graphemeSplit(t),a=this._measureWord(o,r,n);return i=Math.max(a,i),n+=o.length+s.length,{word:o,width:a}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=0;for(let n=0,o=t.length;n<o;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,s){let{largestWordWidth:i,wordsData:r}=s,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=this._getWidthOfCharSpacing(),a=this.splitByGrapheme,h=[],c=a?"":" ";let l=0,u=[],d=0,g=0,f=!0;e-=n;const p=Math.max(e,i,this.dynamicMinWidth),m=r[t];let v;for(d=0,v=0;v<m.length;v++){const{word:e,width:s}=m[v];d+=e.length,l+=g+s-o,l>p&&!f?(h.push(u),u=[],l=s,f=!0):l+=o,f||a||u.push(c),u=u.concat(e),g=a?0:this._measureWord([c],t,d),d++,f=!1}return v&&h.push(u),i+n>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+n),h}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:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let t=0;t<s.length;t++)i[t]=s[t].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const s=this._styleMap[e].line;t.set("".concat(s),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}s(Qn,"type","Textbox"),s(Qn,"textLayoutProperties",[...Zn.textLayoutProperties,"width"]),s(Qn,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),et.setClass(Qn);class Jn extends or{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:r}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:n,height:o}=re(nr(s,i)),a=new at(n,o);if(i.absolutePositioned)return{center:le(i.getRelativeCenterPoint(),void 0,r?r.calcTransformMatrix():void 0),size:a};{const r=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:s=new at,correction:i=new at}=this.calcBoundingBox(e,t)||{};return{center:s.add(r),correction:i.subtract(r),size:a}}return{center:s.getRelativeCenterPoint().add(r),size:a}}}}s(Jn,"type","clip-path"),et.setClass(Jn);class $n extends or{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new at(s.width||i.x,s.height||i.y)}}s($n,"type","fixed"),et.setClass($n);class to extends ur{subscribeTargets(t){const 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){const e=t.target,s=e.getObjects();t.targets.reduce((t,e)=>(e.parent&&t.add(e.parent),t),new Set).forEach(t=>{!s.some(e=>e.parent===t)&&t.layoutManager.unsubscribeTargets({target:t,targets:[e]})})}}class eo extends fr{static getDefaults(){return r(r({},super.getDefaults()),eo.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,eo.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:r}=e;this.groupInit(t,{left:s,top:i,layoutManager:null!=r?r:new to})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];"selection-order"===this.multiSelectionStacking?this.add(...e):e.forEach(t=>{const e=this._objects.findIndex(e=>e.isInFrontOf(t)),s=-1===e?this.size():e;this.insertAt(s,t)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(c("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);const s=new Set;e.forEach(t=>{const{parent:e}=t;e&&s.add(e)}),t===ir?s.forEach(t=>{t._onAfterObjectsChange(sr,e)}):s.forEach(t=>{t._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=r(r({hasControls:!1},s),{},{forActiveSelection:!0});for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,i);super._renderControls(t,e),t.restore()}}s(eo,"type","ActiveSelection"),s(eo,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),et.setClass(eo),et.setClass(eo,"activeSelection");class so{constructor(){s(this,"resources",{})}applyFilters(t,e,s,i,r){const n=r.getContext("2d");if(!n)return;n.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:n.getImageData(0,0,s,i),originalEl:e,originalImageData:n.getImageData(0,0,s,i),canvasEl:r,ctx:n,filterBackend:this};t.forEach(t=>{t.applyTo(o)});const{imageData:a}=o;return a.width===s&&a.height===i||(r.width=a.width,r.height=a.height),n.putImageData(a,0,0),o}}class io{constructor(){let{tileSize:t=h.textureSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),s(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=mt({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,r,n){const o=this.gl,a=r.getContext("2d");if(!o||!a)return;let h;n&&(h=this.getCachedTexture(n,e));const c={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,h?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:h||this.createTexture(o,s,i,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:r},l=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,l),t.forEach(t=>{t&&t.applyTo(c)}),function(t){const e=t.targetCanvas,s=e.width,i=e.height,r=t.destinationWidth,n=t.destinationHeight;s===r&&i===n||(e.width=r,e.height=n)}(c),this.copyGLTo2D(o,c),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(c.sourceTexture),o.deleteTexture(c.targetTexture),o.deleteFramebuffer(l),a.setTransform(1,0,0,1,0,0),c}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,r){const{NEAREST:n,TEXTURE_2D:o,RGBA:a,UNSIGNED_BYTE:h,CLAMP_TO_EDGE:c,TEXTURE_MAG_FILTER:l,TEXTURE_MIN_FILTER:u,TEXTURE_WRAP_S:d,TEXTURE_WRAP_T:g}=t,f=t.createTexture();return t.bindTexture(o,f),t.texParameteri(o,l,r||n),t.texParameteri(o,u,r||n),t.texParameteri(o,d,c),t.texParameteri(o,g,c),i?t.texImage2D(o,0,a,a,h,i):t.texImage2D(o,0,a,e,s,0,a,h,null),f}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const r=this.createTexture(this.gl,e.width,e.height,e,s);return r&&(i[t]=r),r}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,r=i.getContext("2d");if(!r)return;r.translate(0,i.height),r.scale(1,-1);const n=s.height-i.height;r.drawImage(s,0,n,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,r=e.destinationHeight,n=i*r*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,n),a=new Uint8ClampedArray(this.imageBuffer,0,n);t.readPixels(0,0,i,r,t.RGBA,t.UNSIGNED_BYTE,o);const h=new ImageData(a,i,r);s.putImageData(h,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),r=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),r&&(e.vendor=r.toLowerCase())}return this.gpuInfo=e,e}}let ro;function no(){return!ro&&(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(ro=function(){const{WebGLProbe:t}=m();return t.queryWebGL(pt()),h.enableGLFiltering&&t.isSupported(h.textureSize)?new io({tileSize:h.textureSize}):new so}()),ro}const oo=["filters","resizeFilter","src","crossOrigin","type"],ao=["cropX","cropY"];class ho extends li{static getDefaults(){return r(r({},super.getDefaults()),ho.ownDefaults)}constructor(t,e){super(),s(this,"_lastScaleX",1),s(this,"_lastScaleY",1),s(this,"_filterScalingX",1),s(this,"_filterScalingY",1),this.filters=[],Object.assign(this,ho.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(ft()),this.setElement("string"==typeof t?(this.canvas&&Ut(this.canvas.getElement())||v()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),null===(e=t.classList)||void 0===e||e.add(ho.CSS_CANVAS),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=no(!1);e instanceof io&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&m().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const 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;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=[];return this.filters.forEach(t=>{t&&e.push(t.toObject())}),r(r({},super.toObject([...ao,...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(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let r=[],n=[],o="",a="";if(!e)return[];if(this.hasCrop()){const t=ft();r.push('<clipPath id="imageCrop_'+t+'">\n','\t<rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+'" />\n',"</clipPath>\n"),o=' clip-path="url(#imageCrop_'+t+')" '}if(this.imageSmoothing||(a=' image-rendering="optimizeSpeed"'),t.push("\t<image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(a).concat(o,"></image>\n")),this.stroke||this.strokeDashArray){const t=this.fill;this.fill=null,n=['\t<rect x="'.concat(s,'" y="').concat(i,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),'" />\n')],this.fill=t}return r=this.paintFirst!==Z?r.concat(n,t):r.concat(t,n),r}getSrc(t){const 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){let{crossOrigin:e,signal:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Ft(t,{crossOrigin:e,signal:s}).then(t=>{void 0!==e&&this.set({crossOrigin:e}),this.setElement(t)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),i=s.x,r=s.y,n=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&r>e)return this._element=n,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=r);const o=mt(n),{width:a,height:h}=n;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=r,no().applyFilters([t],n,a,h,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.filters||[];if(t=t.filter(t=>t&&!t.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),0===t.length)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const t=mt({width:s,height:i});this._element=t,this._filteredEl=t}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);no().applyFilters(t,this._originalElement,s,i,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){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,r=this.width,n=this.height,o=Math.max(this.cropX,0),a=Math.max(this.cropY,0),h=e.naturalWidth||e.width,c=e.naturalHeight||e.height,l=o*s,u=a*i,d=Math.min(r*s,h-l),g=Math.min(n*i,c-u),f=-r/2,p=-n/2,m=Math.min(r,h/s-o),v=Math.min(n,c/i-a);e&&t.drawImage(e,l,u,d,g,f,p,m,v)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=(t=>{const[e,s]=t.trim().split(" "),[i,r]=(n=e)&&n!==L?[n.slice(1,4),n.slice(5,8)]:n===L?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:s||"meet",alignX:i,alignY:r}})(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let r,n=this._element.width,o=this._element.height,a=1,h=1,c=0,l=0,u=0,d=0;return!t||t.alignX===L&&t.alignY===L?(a=e/n,h=s/o):("meet"===t.meetOrSlice&&(a=h=((t,e)=>Math.min(e.width/t.width,e.height/t.height))(this._element,i),r=(e-n*a)/2,"Min"===t.alignX&&(c=-r),"Max"===t.alignX&&(c=r),r=(s-o*h)/2,"Min"===t.alignY&&(l=-r),"Max"===t.alignY&&(l=r)),"slice"===t.meetOrSlice&&(a=h=((t,e)=>Math.max(e.width/t.width,e.height/t.height))(this._element,i),r=n-e/a,"Mid"===t.alignX&&(u=r/2),"Max"===t.alignX&&(u=r),r=o-s/h,"Mid"===t.alignY&&(d=r/2),"Max"===t.alignY&&(d=r),n=e/a,o=s/h)),{width:n,height:o,scaleX:a,scaleY:h,offsetLeft:c,offsetTop:l,cropX:u,cropY:d}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:o,crossOrigin:a,type:h}=t,c=n(t,oo);return Promise.all([Ft(o,r(r({},e),{},{crossOrigin:a})),s&&Rt(s,e),i&&Rt([i],e),Bt(c,e)]).then(t=>{let[e,s=[],[i]=[],n={}]=t;return new this(e,r(r({},c),{},{src:o,filters:s,resizeFilter:i},n))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Ft(t,{crossOrigin:e,signal:s}).then(t=>new this(t,i))}static async fromElement(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const i=Qi(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"]||i.href,e,i).catch(t=>(c("log","Unable to parse Image",t),null))}}s(ho,"type","Image"),s(ho,"cacheProperties",[...ms,...ao]),s(ho,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),s(ho,"CSS_CANVAS","canvas-img"),s(ho,"ATTRIBUTE_NAMES",[...Ci,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),et.setClass(ho),et.setSVGClass(ho),je(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const co=t=>void 0!==t.webgl,lo="precision highp float",uo="\n ".concat(lo,";\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }"),go=["type"],fo=["type"],po=new RegExp(lo,"g");class mo{get type(){return this.constructor.type}constructor(){let t=n(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},go);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return uo}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){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getFragmentSource(),s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:i="highp"}}=m();"highp"!==i&&(e=e.replace(po,lo.replace("highp",i)));const r=t.createShader(t.VERTEX_SHADER),n=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!r||!n||!o)throw new l("Vertex, fragment shader or program creation error");if(t.shaderSource(r,s),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new l("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new l("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new l('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const a=this.getUniformLocations(t,o)||{};return a.uStepW=t.getUniformLocation(o,"uStepW"),a.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:a}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,i={};for(let r=0;r<s.length;r++)i[s[r]]=t.getUniformLocation(e,s[r]);return i}sendAttributeData(t,e,s){const i=e.aPosition,r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,i)),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++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){co(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);0===t.pass&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),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){const{sourceWidth:e,sourceHeight:s}=t,i=mt({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return r({type:this.type},t.reduce((t,e)=>(t[e]=this[e],t),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(n(t,fo))}}s(mo,"type","BaseFilter"),s(mo,"uniformLocations",[]);const vo={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 "};class yo extends mo{getCacheKey(){return"".concat(this.type,"_").concat(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 ".concat(vo[this.mode],"\n }\n }\n ")}applyTo2d(t){let{imageData:{data:e}}=t;const s=new Me(this.color).getSource(),i=this.alpha,r=s[0]*i,n=s[1]*i,o=s[2]*i,a=1-i;for(let t=0;t<e.length;t+=4){const s=e[t],i=e[t+1],h=e[t+2];let c,l,u;switch(this.mode){case"multiply":c=s*r/255,l=i*n/255,u=h*o/255;break;case"screen":c=255-(255-s)*(255-r)/255,l=255-(255-i)*(255-n)/255,u=255-(255-h)*(255-o)/255;break;case"add":c=s+r,l=i+n,u=h+o;break;case"difference":c=Math.abs(s-r),l=Math.abs(i-n),u=Math.abs(h-o);break;case"subtract":c=s-r,l=i-n,u=h-o;break;case"darken":c=Math.min(s,r),l=Math.min(i,n),u=Math.min(h,o);break;case"lighten":c=Math.max(s,r),l=Math.max(i,n),u=Math.max(h,o);break;case"overlay":c=r<128?2*s*r/255:255-2*(255-s)*(255-r)/255,l=n<128?2*i*n/255:255-2*(255-i)*(255-n)/255,u=o<128?2*h*o/255:255-2*(255-h)*(255-o)/255;break;case"exclusion":c=r+s-2*r*s/255,l=n+i-2*n*i/255,u=o+h-2*o*h/255;break;case"tint":c=r+s*a,l=n+i*a,u=o+h*a}e[t]=c,e[t+1]=l,e[t+2]=u}}sendUniformData(t,e){const s=new Me(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}s(yo,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),s(yo,"type","BlendColor"),s(yo,"uniformLocations",["uColor"]),et.setClass(yo);const xo={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 "},_o=["type","image"];class bo extends mo{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return xo[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){const e=t.context,s=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,s,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:s}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/s,1]}applyTo2d(t){let{imageData:{data:e,width:s,height:i},filterBackend:{resources:r}}=t;const n=this.image;r.blendImage||(r.blendImage=pt());const o=r.blendImage,a=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):a.clearRect(0,0,s,i),a.setTransform(n.scaleX,0,0,n.scaleY,n.left,n.top),a.drawImage(n.getElement(),0,0,s,i);const h=a.getImageData(0,0,s,i).data;for(let t=0;t<e.length;t+=4){const s=e[t],i=e[t+1],r=e[t+2],n=e[t+3],o=h[t],a=h[t+1],c=h[t+2],l=h[t+3];switch(this.mode){case"multiply":e[t]=s*o/255,e[t+1]=i*a/255,e[t+2]=r*c/255,e[t+3]=n*l/255;break;case"mask":e[t+3]=l}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return r(r({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,o=n(t,_o);return ho.fromObject(i,e).then(t=>new this(r(r({},o),{},{image:t})))}}s(bo,"type","BlendImage"),s(bo,"defaults",{mode:"multiply",alpha:1}),s(bo,"uniformLocations",["uTransformMatrix","uImage"]),et.setClass(bo);class wo extends mo{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){co(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(t){let{imageData:{data:e,width:s,height:i}}=t;this.aspectRatio=s/i,this.horizontal=!0;let r=this.getBlurValue()*s;const n=new Uint8ClampedArray(e),o=4*s;for(let t=0;t<e.length;t+=4){let s=0,i=0,a=0,h=0,c=0;const l=t-t%o,u=l+o;for(let n=-14;n<15;n++){const o=n/15,d=4*Math.floor(r*o),g=1-Math.abs(o);let f=t+d;f<l?f=l:f>u&&(f=u);const p=e[f+3]*g;s+=e[f]*p,i+=e[f+1]*p,a+=e[f+2]*p,h+=p,c+=g}n[t]=s/h,n[t+1]=i/h,n[t+2]=a/h,n[t+3]=h/c}this.horizontal=!1,r=this.getBlurValue()*i;for(let t=0;t<n.length;t+=4){let s=0,i=0,a=0,h=0,c=0;const l=t%o,u=n.length-o+l;for(let e=-14;e<15;e++){const d=e/15,g=Math.floor(r*d)*o,f=1-Math.abs(d);let p=t+g;p<l?p=l:p>u&&(p=u);const m=n[p+3]*f;s+=n[p]*m,i+=n[p+1]*m,a+=n[p+2]*m,h+=m,c+=f}e[t]=s/h,e[t+1]=i/h,e[t+2]=a/h,e[t+3]=h/c}}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return 0===this.blur}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:s}=this;return e?s>1&&(t=1/s):s<1&&(t=s),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}s(wo,"type","Blur"),s(wo,"defaults",{blur:0}),s(wo,"uniformLocations",["uDelta"]),et.setClass(wo);class Co extends mo{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(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let t=0;t<e.length;t+=4)e[t]+=s,e[t+1]+=s,e[t+2]+=s}isNeutralState(){return 0===this.brightness}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}s(Co,"type","Brightness"),s(Co,"defaults",{brightness:0}),s(Co,"uniformLocations",["uBrightness"]),et.setClass(Co);const So={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class To extends mo{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){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2];if(e[t]=r*s[0]+n*s[1]+o*s[2]+255*s[4],e[t+1]=r*s[5]+n*s[6]+o*s[7]+255*s[9],e[t+2]=r*s[10]+n*s[11]+o*s[12]+255*s[14],!i){const i=e[t+3];e[t]+=i*s[3],e[t+1]+=i*s[8],e[t+2]+=i*s[13],e[t+3]=r*s[15]+n*s[16]+o*s[17]+i*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],r=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,r)}toObject(){return r(r({},super.toObject()),{},{matrix:[...this.matrix]})}}function Oo(t,e){var i;const r=(s(i=class extends To{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",t),s(i,"defaults",{colorsOnly:!1,matrix:e}),i);return et.setClass(r,t),r}s(To,"type","ColorMatrix"),s(To,"defaults",So),s(To,"uniformLocations",["uColorMatrix","uConstants"]),et.setClass(To),Oo("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Oo("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Oo("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Oo("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Oo("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Oo("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Oo("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]);class ko extends mo{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){co(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=>et.getClass(t.type).fromObject(t,e))).then(t=>new this({subFilters:t}))}}s(ko,"type","Composed"),et.setClass(ko);class Mo extends mo{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(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let t=0;t<e.length;t+=4)e[t]=i*(e[t]-128)+128,e[t+1]=i*(e[t+1]-128)+128,e[t+2]=i*(e[t+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}s(Mo,"type","Contrast"),s(Mo,"defaults",{contrast:0}),s(Mo,"uniformLocations",["uContrast"]),et.setClass(Mo);const Do={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 "};class Eo extends mo{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Do[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,r=Math.round(Math.sqrt(i.length)),n=Math.floor(r/2),o=e.width,a=e.height,h=t.ctx.createImageData(o,a),c=h.data,l=this.opaque?1:0;let u,d,g,f,p,m,v,y,x,_,b,w,C;for(b=0;b<a;b++)for(_=0;_<o;_++){for(p=4*(b*o+_),u=0,d=0,g=0,f=0,C=0;C<r;C++)for(w=0;w<r;w++)v=b+C-n,m=_+w-n,v<0||v>=a||m<0||m>=o||(y=4*(v*o+m),x=i[C*r+w],u+=s[y]*x,d+=s[y+1]*x,g+=s[y+2]*x,l||(f+=s[y+3]*x));c[p]=u,c[p+1]=d,c[p+2]=g,c[p+3]=l?s[p+3]:f}t.imageData=h}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return r(r({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}s(Eo,"type","Convolute"),s(Eo,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),s(Eo,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),et.setClass(Eo);const Ao="Gamma";class jo extends mo{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(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],r=1/s[1],n=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let t=0;t<256;t++)o.r[t]=255*Math.pow(t/255,i),o.g[t]=255*Math.pow(t/255,r),o.b[t]=255*Math.pow(t/255,n);for(let t=0;t<e.length;t+=4)e[t]=o.r[e[t]],e[t+1]=o.g[e[t+1]],e[t+2]=o.b[e[t+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return 1===t[0]&&1===t[1]&&1===t[2]}toObject(){return{type:Ao,gamma:this.gamma.concat()}}}s(jo,"type",Ao),s(jo,"defaults",{gamma:[1,1,1]}),s(jo,"uniformLocations",["uGamma"]),et.setClass(jo);const Po={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 "};class Lo extends mo{applyTo2d(t){let{imageData:{data:e}}=t;for(let t,s=0;s<e.length;s+=4){const i=e[s],r=e[s+1],n=e[s+2];switch(this.mode){case"average":t=(i+r+n)/3;break;case"lightness":t=(Math.min(i,r,n)+Math.max(i,r,n))/2;break;case"luminosity":t=.21*i+.72*r+.07*n}e[s+2]=e[s+1]=e[s]=t}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Po[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}s(Lo,"type","Grayscale"),s(Lo,"defaults",{mode:"average"}),s(Lo,"uniformLocations",["uMode"]),et.setClass(Lo);const Fo=r(r({},So),{},{rotation:0});class Ro extends To{calculateMatrix(){const t=this.rotation*Math.PI,e=nt(t),s=ot(t),i=1/3,r=Math.sqrt(i)*s,n=1-e;this.matrix=[e+n/3,i*n-r,i*n+r,0,0,i*n+r,e+i*n,i*n-r,0,0,i*n-r,i*n+r,e+i*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}}}s(Ro,"type","HueRotation"),s(Ro,"defaults",Fo),et.setClass(Ro);class Bo extends mo{applyTo2d(t){let{imageData:{data:e}}=t;for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+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))}}s(Bo,"type","Invert"),s(Bo,"defaults",{alpha:!1,invert:!0}),s(Bo,"uniformLocations",["uInvert","uAlpha"]),et.setClass(Bo);class Io extends mo{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(t){let{imageData:{data:e}}=t;const s=this.noise;for(let t=0;t<e.length;t+=4){const i=(.5-Math.random())*s;e[t]+=i,e[t+1]+=i,e[t+2]+=i}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return 0===this.noise}}s(Io,"type","Noise"),s(Io,"defaults",{noise:0}),s(Io,"uniformLocations",["uNoise","uSeed"]),et.setClass(Io);class Wo extends mo{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let t=0;t<i;t+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const n=4*t*s+4*r,o=e[n],a=e[n+1],h=e[n+2],c=e[n+3];for(let n=t;n<Math.min(t+this.blocksize,i);n++)for(let t=r;t<Math.min(r+this.blocksize,s);t++){const i=4*n*s+4*t;e[i]=o,e[i+1]=a,e[i+2]=h,e[i+3]=c}}}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)}}s(Wo,"type","Pixelate"),s(Wo,"defaults",{blocksize:4}),s(Wo,"uniformLocations",["uBlocksize"]),et.setClass(Wo);class Xo extends mo{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(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new Me(this.color).getSource(),r=[i[0]-s,i[1]-s,i[2]-s],n=[i[0]+s,i[1]+s,i[2]+s];for(let t=0;t<e.length;t+=4){const s=e[t],i=e[t+1],o=e[t+2];s>r[0]&&i>r[1]&&o>r[2]&&s<n[0]&&i<n[1]&&o<n[2]&&(e[t+3]=0)}}sendUniformData(t,e){const s=new Me(this.color).getSource(),i=this.distance,r=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],n=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,r),t.uniform4fv(e.uHigh,n)}}s(Xo,"type","RemoveColor"),s(Xo,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),s(Xo,"uniformLocations",["uLow","uHigh"]),et.setClass(Xo);class Yo extends mo{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let r=1;r<=s;r++)i[r-1]=t(r*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[".concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(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){co(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;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const r=e.width,n=e.height,o=Math.round(r*s),a=Math.round(n*i);let h;h="sliceHack"===this.resizeType?this.sliceByTwo(t,r,n,o,a):"hermite"===this.resizeType?this.hermiteFastResize(t,r,n,o,a):"bilinear"===this.resizeType?this.bilinearFiltering(t,r,n,o,a):"lanczos"===this.resizeType?this.lanczosResize(t,r,n,o,a):new ImageData(o,a),t.imageData=h}sliceByTwo(t,e,s,i,r){const n=t.imageData,o=.5;let a=!1,h=!1,c=e*o,l=s*o;const u=t.filterBackend.resources;let d=0,g=0;const f=e;let p=0;u.sliceByTwo||(u.sliceByTwo=pt());const m=u.sliceByTwo;(m.width<1.5*e||m.height<s)&&(m.width=1.5*e,m.height=s);const v=m.getContext("2d");for(v.clearRect(0,0,1.5*e,s),v.putImageData(n,0,0),i=Math.floor(i),r=Math.floor(r);!a||!h;)e=c,s=l,i<Math.floor(c*o)?c=Math.floor(c*o):(c=i,a=!0),r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,h=!0),v.drawImage(m,d,g,e,s,f,p,c,l),d=f,g=p,p+=l;return v.getImageData(d,g,i,r)}lanczosResize(t,e,s,i,r){const n=t.imageData.data,o=t.ctx.createImageData(i,r),a=o.data,h=this.lanczosCreate(this.lanczosLobes),c=this.rcpScaleX,l=this.rcpScaleY,u=2/this.rcpScaleX,d=2/this.rcpScaleY,g=Math.ceil(c*this.lanczosLobes/2),f=Math.ceil(l*this.lanczosLobes/2),p={},m={x:0,y:0},v={x:0,y:0};return function t(y){let x,_,b,w,C,S,T,O,k,M,D;for(m.x=(y+.5)*c,v.x=Math.floor(m.x),x=0;x<r;x++){for(m.y=(x+.5)*l,v.y=Math.floor(m.y),C=0,S=0,T=0,O=0,k=0,_=v.x-g;_<=v.x+g;_++)if(!(_<0||_>=e)){M=Math.floor(1e3*Math.abs(_-m.x)),p[M]||(p[M]={});for(let t=v.y-f;t<=v.y+f;t++)t<0||t>=s||(D=Math.floor(1e3*Math.abs(t-m.y)),p[M][D]||(p[M][D]=h(Math.sqrt(Math.pow(M*u,2)+Math.pow(D*d,2))/1e3)),b=p[M][D],b>0&&(w=4*(t*e+_),C+=b,S+=b*n[w],T+=b*n[w+1],O+=b*n[w+2],k+=b*n[w+3]))}w=4*(x*i+y),a[w]=S/C,a[w+1]=T/C,a[w+2]=O/C,a[w+3]=k/C}return++y<i?t(y):o}(0)}bilinearFiltering(t,e,s,i,r){let n,o,a,h,c,l,u,d,g,f,p,m,v,y=0;const x=this.rcpScaleX,_=this.rcpScaleY,b=4*(e-1),w=t.imageData.data,C=t.ctx.createImageData(i,r),S=C.data;for(u=0;u<r;u++)for(d=0;d<i;d++)for(c=Math.floor(x*d),l=Math.floor(_*u),g=x*d-c,f=_*u-l,v=4*(l*e+c),p=0;p<4;p++)n=w[v+p],o=w[v+4+p],a=w[v+b+p],h=w[v+b+4+p],m=n*(1-g)*(1-f)+o*g*(1-f)+a*f*(1-g)+h*g*f,S[y++]=m;return C}hermiteFastResize(t,e,s,i,r){const n=this.rcpScaleX,o=this.rcpScaleY,a=Math.ceil(n/2),h=Math.ceil(o/2),c=t.imageData.data,l=t.ctx.createImageData(i,r),u=l.data;for(let t=0;t<r;t++)for(let s=0;s<i;s++){const r=4*(s+t*i);let l=0,d=0,g=0,f=0,p=0,m=0,v=0;const y=(t+.5)*o;for(let i=Math.floor(t*o);i<(t+1)*o;i++){const t=Math.abs(y-(i+.5))/h,r=(s+.5)*n,o=t*t;for(let t=Math.floor(s*n);t<(s+1)*n;t++){let s=Math.abs(r-(t+.5))/a;const n=Math.sqrt(o+s*s);n>1&&n<-1||(l=2*n*n*n-3*n*n+1,l>0&&(s=4*(t+i*e),v+=l*c[s+3],g+=l,c[s+3]<255&&(l=l*c[s+3]/250),f+=l*c[s],p+=l*c[s+1],m+=l*c[s+2],d+=l))}}u[r]=f/d,u[r+1]=p/d,u[r+2]=m/d,u[r+3]=v/g}return l}}s(Yo,"type","Resize"),s(Yo,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),s(Yo,"uniformLocations",["uDelta","uTaps"]),et.setClass(Yo);class zo extends mo{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(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let t=0;t<e.length;t+=4){const i=e[t],r=e[t+1],n=e[t+2],o=Math.max(i,r,n);e[t]+=o!==i?(o-i)*s:0,e[t+1]+=o!==r?(o-r)*s:0,e[t+2]+=o!==n?(o-n)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return 0===this.saturation}}s(zo,"type","Saturation"),s(zo,"defaults",{saturation:0}),s(zo,"uniformLocations",["uSaturation"]),et.setClass(zo);class Vo extends mo{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(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let t=0;t<e.length;t+=4){const i=e[t],r=e[t+1],n=e[t+2],o=Math.max(i,r,n),a=(i+r+n)/3,h=2*Math.abs(o-a)/255*s;e[t]+=o!==i?(o-i)*h:0,e[t+1]+=o!==r?(o-r)*h:0,e[t+2]+=o!==n?(o-n)*h:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return 0===this.vibrance}}s(Vo,"type","Vibrance"),s(Vo,"defaults",{vibrance:0}),s(Vo,"uniformLocations",["uVibrance"]),et.setClass(Vo);class Go extends at{constructor(t,e){let s=0,i=0;arguments.length>1?(s=Number(t)||0,i=Number(e)||0):t?"object"==typeof t&&("x"in t&&"y"in t?(s=Number(t.x)||0,i=Number(t.y)||0):Array.isArray(t)&&t.length>=2&&(s=Number(t[0])||0,i=Number(t[1])||0)):[s,i]=[0,0],super(s,i)}setX(t){this.x=Number(t)||0}setY(t){this.y=Number(t)||0}copy(t){t&&"object"==typeof t&&"x"in t&&"y"in t&&(this.x=Number(t.x)||0,this.y=Number(t.y)||0)}getArray(){return[this.x,this.y]}}const Ho={SELECT:"SELECT",GRAB:"GRAB",MEASURE:"MEASURE",DRAW:"DRAW"},No={NONE:"NONE",TOP_LEFT:"TOP_LEFT",TOP_RIGHT:"TOP_RIGHT",BOTTOM_LEFT:"BOTTOM_LEFT",BOTTOM_RIGHT:"BOTTOM_RIGHT"},Uo={center:new Go,zoom:1,minZoom:0,maxZoom:20,gridEnabled:!0,zoomEnabled:!0,selectEnabled:!0,mode:Ho.SELECT,showGrid:!0,originPin:No.NONE,enablePan:!0},qo={position:new Go,minZoom:1,maxZoom:20},Ko={url:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAy8SURBVHhe7Z1r1BVVGcdn5n0hQZMyL62VEGmIN4xqhaV2QQwE0cxLSHbRMsH6nvVdQEWgPpUo0kUDQQGt5eqLIaho2jKF1irAoEi8QEtdXApEV/2e2SPC4Zl59z5n5szl7P9af877cp7/s/d+nnln9uzZe0/QQPTDEfC8IAivCYLoh/x8J1zF7+v4fQvcAXfBAwnlZ/k/vhMbsQ0W8jvacLrxFfsU3x4Vw6kk6Wo+F8DVJG0bfDsMov/lSfFpfAePmbLCr5myPbqN95OIi/mcx+dzcJ+WsG5QyjZ1CObzOZnPY6WCHvnjKAI8lc9FfG7TklEFUrd/JXWUulJnj05xJryFgG7WAl5lUucXqfuspA0ebggn8M8KgviWFtw6kTbQyQxW0qaL4qZ5ZCG6jECt0QLZBNK2tbTxK0ljPd5DOAmu1oLWRNJW7iTijmzP42z4gBakXiBtfxCOkUD0GoZAOkjRf7TA9BKJwX+JxWw4VALTA5DOUPSCFoyiKAcafBn+hQo8AX8PH4LLEsrP8n98JzaxbVcPTspbT2wmUofGYjCcqzU+TxLILZTzMJxDQK8Ngj4Zxv0oPAaGcCCIjdiiEa34EF/iM9qilZknKWcelFg1CucQyGe0BndK89caPBAF0Qw+x8IiB2DEN2XEZS2XsrU6dUpi9Sz+PyEFNgDyMCXapTW0XeLvFRwv5lNuqT4QF1MOhlEHbl3juuR6MOBvN7H7uimmvpijNa5dEhBuFcPr8XuccV8pUCepW763s/i91bivF94H79ca5Er+EmQkbSn8gjiuCT4Pl1D3XEYy8SUd1do8WzgBrtUa4kr83Avlul5XyHX81xwI72jtcyF+HocnitMq4yM0tuNbPPyshp+LPTYDn4UdXxqILbeKwfDYYwUxkgpu1CpuS/Qv05u/MfHXQEjbOussot+Eo1OMv+pA/vI3aRW2JT4Wwg/H3pqNk+CdWgxsSaw34+Pk2FsFcDwVWq9V1IZo/03Pflriq4cgU8qinVpMbIh2A06kv1Uq6O2HT2oVtCF66dicFnvqTYyCbXeYib1MYC317qDtWz20MuTpZ9kGQR+8Q4uRDdEuj72UgLYHeejo/SDx4XEQ0U1arGyI+Dbjo2sIp2kVGYg0cn9vXu9tEfcLiJEevyyilfULXcGZVHK3VoksonmDSn458eGRivhx+etaDLOIZg9imWBTKAZR0HNaBbKI5k20MhjiYYdxEjMtlllE8zzaQh8lO3dWqNR+dH5GrDsuJHbOi17QzTfy/PElrcCBGS+h8mgL4dV6TLOJcLzR5wfu96O/aoVlkd7+9xO9R9uIZmqxzSKajQhzHR+YpRWURTSFnYp6EG1ceuNpbLlgtFzHtULSyKlLRqhkgMMjH0TE1GnEVXKG7nQj7wwPaQWkkYK53Qs+ZqQeOYKYut0eovmtkbaNcILmOItc969MxB65I7pCi3kWyWEnYy+upx1ZGu1RMO7SYp9GcvhUonNFdInmMI3Y70B0vNF6FIgPEevXtBykEftLE60Lwqc0Z+kMb0iEHoUj/I6eA53Y/zER2iL8ouYojdjLciuPriJ8XMtFGrF3Ghyy7vlzenkb+08bmUcX8UmJvZYTjdhb3xGMwvEBzYlG7JcYmUcJuE/LiUbJKfajjSwbt2gONOL0Lez9Hjjl4QxyYD1Ih70sQ8+EjPn/QxNrxF5WrHiUi6VabjSS239in/WMILpYE6YRgX/GXz7O1XKTRnI8JdGpWKSJNPqef5UQWs8sxnix0RyJYzg6XtFEOsPrEp1H6Qi/pefoSJLjVxHIBhitCCdqAo04kVE/vy1qdSDb51qPDmKr7lBm/cwZ218YiUeFsFjLlUZs1bkaf9aMNXIEyV64HpVCNEXLlUaMZfLoYfslycpeq/tJ7OT0r11DPMrF0eTG6jKAnYzfHLrCOLpKM9SI8Qqj8aggrDfd5AQg71g4iPmakcYoiGYmGo/KIbpRy5lGjH9iNAaPaUYag6C/KduXNRD9YzgIrLajwXit0cQrdKOXNKNWYidDibIBlEc1MZgcWQ3lY7cd+0EiGs4vVo8Vse10kqFH8bB6lC85x1Z2UA3O0ww0YpvbXHOPwmC9hgNb2c7Ofqk3trXfubL5CKdrudMotgiim7UvNQZBn3/6V3n0Wz8dJPc/FoXVjlUYy772I0XgUWmMkFxpOWwltrIzW7BK+7KVOJVe49Ei8Kg0hpIry7u6+D0J4Trty1biVF62YLPfvke5IEfRBi2HrcRUFo3YvQQBwydj9x51gNWUcck9ttEO7ctWYiivVPGoBx7RcthKcr8TW7uXOWAo1wuPemCllsNWSu6xtVsDgKGfAVwfWM0Ultxj6w+ABsLpAPCXgObB6RLgO4HNg1Mn0N8GNg+2t4FbsbXbBwBjPxBUD7gMBD0tAj8U3Cy4DgU7PQyKJxB4VBouD4Pugv5xcLPQP07LnUZyL4+D/YSQZiG8RsudRmxlQkjf+dqXGjEecIMBj9LhsMFHn0wJc5oUKq9l96g2bDv1ByeF+mnhzYFMC9+q5a6V2B2cFi5wWBgSnGMkHhVEWwtDBNZLwyhgRqLxqBzaXhrmF4c2BC6LQw97k4vL8vDXsPfLw6sHWR7+qpazVmLXujxcELlsEHFJIvKoDKLJWq40YvsCgiOe6/gtYuqNe7RcacRW2yImnKQZa+QI8ptEVQu5bBLltE0cB8y3E51H6Qi/qeVIoxwoCDhgdDicRkJ59btHJRCu0XKkEeOsy7d9R0KI4Fyj8ygR1k//hOQ4swN/FAZ+s+h6YYmWG43kdhv2Q4wsHQ4bDMT3k2cYmUcJOJ0cuGwXb7XBx2k4dXlhxG+MzKME3KvlRCM5lad/1i+SfFhzojFx/Ckj8+gixjr+of7OyKwQOr0p3N8RlAH7LeKF2F+YCG0RPq05SiP2302EHoUjvF7LQRqxfyYRuiCaqjlLI/YywOBfHFk8jpNYazlII/aXJVpX2O0e8i4R3G10HgVioRb7NMqZPNG1g/AizWkWOdquSMQeuSO6XIt5FslhJy+PjmF9RyCkkq+j8a+Pzx8yZ8P19fEuPf9UjKZg68EGIUedLCSNjNwjBxDL8Akt1mlEkusg3WytkCyimWekHjlgrhbjLKK51UjzgTwj+JtWUBbR+HcLdIxohhbbLKLZiDDrBZFtYbxW2EDk1HXYmyk8XBBdqcV0ICJ0HfSxxjytwCzSiP3oCqtQgzGe2O3TYppFdAuMvBgMolLWk0ffJZo30Y4zLjws8Bli9oYWyyyikcmeg42L4nAWBe3RKpBFaZCMKyQ+PFIRTiBWTrd7QjR7EY8xPgqH/RLkQ0kluRz4PkE6oqug82nfsPtL92/TKzIwaeRNiQ+Pg4hmarGyIeK5xkf3sVyrkA3R3gH7Yi+9DYnB7VqMbIj2wdhLSeBe0+2B0aFEvwaOij31Jj4OrVdmt5LYy3bvA87xKxoncPqy2pZMI9qdvdkviK/3Vpt0akQr2/adaHyVj5Op0GatorbEx8/hSbG3ZkOS9jMtBrYk1i/iY3jsrUI4hYpt0ipsS/TbORvckPhrIKRt0Xat7bZMkn+q8Vc9yH5D67WKuxA/f4BNWnQig2CPam11IbGV0/6I2GOFIac4q71qs0hj38HPr2Cd31Us2+n8krZYbcKVRfzII/baXCLlSdQyrSGuJHjyXFvWHlwgjmuC8+F91N1pHkUa8bUclt7bbwdtDxZpJKCPch29Dr8fNO4rBeokK6ajjk/1hxK/txv3tUV4LUHZrTWuXeJPtjhbxOelfA6LiykHx1KHqXxKXTrq3LUSf3vCIPyGKab+4DoePqs1tFMmB8My/H/PlFPoPobim+t6XNb9lG21v6Ir8fsn/I+VApsECZ7zfAJXEry/U45sgz6LRE1PNriWnrNsdW/zvgOxEVs0oo3308VXsEp8a2XmScqR5/lN3owznEggO75VdCHl7YUvwQ1UQJaxPQJXwqUJ5Wf5P74Tm9h2r+arKFIet3jhJOrQExgK59Boq33tm0xisI9YyAROiUnPQe6TV2iB6QXSdjnz1HmcIy9Ekzn9tf1UrG6krWto85Sk8R7vIbqc4HQ8ilhVStto41eTxnqkI17PJr1u6w0QqkraIBtocFcinV8PV5wFZxPEwm+/8qbU2dQ9OFsa4tEZhhBQGfW7h89CBl/yoNSNOi7mU9bj13Lsvg4YRoClA7WAz+dhLg9c2qGUbeoge+/HdSpzWLpnMYrr6zQ+fwqldy2DOFZvzXCh+DS+4zdtUFZcZi/PZ6wsZGWMvAzpApIkD6Ju5md5QaJ0xNbx+xa4A+6CBxLKz/J/W7GRiZYylIwm+pHxET+KHgkLX3XTXQTB/wEErHoK8OgOXgAAAABJRU5ErkJggg==",size:[128,128],anchor:[64,64]};li.prototype.originX="center",li.prototype.originY="center",li.prototype.lockUniScaling=!0,li.prototype.lockScalingFlip=!0,li.prototype.transparentCorners=!1,li.prototype.centeredScaling=!0,li.prototype.cornerColor="blue",li.prototype.borderColor="blue",li.prototype.borderOpacity=.7,li.prototype.cornerOpacity=.7,li.prototype.cornerStrokeColor="blue",li.prototype.borderColor="#ff0099",li.prototype.cornerColor="#00eaff",li.prototype.cornerStrokeColor="#00bbff",li.prototype.objectCaching=!1,fr.prototype.objectCaching=!0,fr.prototype.selectionBackgroundColor="rgba(45,207,171,0.25)",li.prototype.borderDashArray=[3,3],li.prototype.padding=5,li.prototype.getBounds=function(){const t=[];return t.push(new Go(this.left-this.width/2,this.top-this.height/2)),t.push(new Go(this.left+this.width/2,this.top+this.height/2)),t};const Zo=function(t){return"number"==typeof t&&!isNaN(t)};var Qo=(t,e)=>{const s=(e=e||t.currentTarget).getBoundingClientRect(),i=t.originalEvent||t;let r=0,n=0;t.touches&&t.touches.length?Zo(t.touches[0].pageX)&&Zo(t.touches[0].pageY)?(r=t.touches[0].pageX,n=t.touches[0].pageY):Zo(t.touches[0].clientX)&&Zo(t.touches[0].clientY)&&(r=i.touches[0].clientX,n=i.touches[0].clientY):Zo(t.pageX)&&Zo(t.pageY)?(r=t.pageX,n=t.pageY):t.currentPoint&&Zo(t.currentPoint.x)&&Zo(t.currentPoint.y)&&(r=t.currentPoint.x,n=t.currentPoint.y);let o=!1;return"which"in t?o=3==t.which:"button"in t&&(o=2==t.button),{x:r-s.left,y:n-s.top,isRight:o}};window.addEventListener("touchmove",()=>{});class Jo{constructor(t){let e,s,i,r,n,o,a,h,c,l,u,{source:d=document,update:g,stop:f,multiplier:p=1,friction:m=.92,initialValues:v,boundX:y,boundY:x,bounce:_=!0}=t,b=0,w=0,C=.3*p,S=!1,T=!1,O=!1,k=!1,M=[];function D(){document.removeEventListener("touchmove",P,!!ta()&&{passive:!1}),document.removeEventListener("touchend",L),document.removeEventListener("touchcancel",F),document.removeEventListener("mousemove",P,!!ta()&&{passive:!1}),document.removeEventListener("mouseup",L)}function E(){g.call(d,b,w)}function A(t){if("touchmove"===t.type||"touchstart"===t.type||"touchend"===t.type){const e=t.targetTouches[0]||t.changedTouches[0];return{x:e.clientX,y:e.clientY,id:e.identifier}}return{x:t.clientX,y:t.clientY,id:null}}function j(t){const e=A(t);T||O||(T=!0,k=!1,c=e.id,n=a=e.x,o=h=e.y,M=[],R(n,o),D(),document.addEventListener("touchmove",P,!!ta()&&{passive:!1}),document.addEventListener("touchend",L),document.addEventListener("touchcancel",F),document.addEventListener("mousemove",P,!!ta()&&{passive:!1}),document.addEventListener("mouseup",L))}function P(t){t.preventDefault();const e=A(t);T&&e.id===c&&(a=e.x,h=e.y,R(n,o),function(){S||$o(B);S=!0}())}function L(t){const e=A(t);T&&e.id===c&&F()}function F(){T=!1,R(n,o),function(){const t=M[0],e=M[M.length-1],s=e.x-t.x,i=e.y-t.y,r=(e.time-t.time)/15/p;l=s/r||0,u=i/r||0;const n=W();Math.abs(l)>1||Math.abs(u)>1||!n.inBounds?(k=!0,$o(X)):f&&f(d)}(),D()}function R(t,e){const s=Date.now();for(;M.length>0&&!(s-M[0].time<=100);)M.shift();M.push({x:t,y:e,time:s})}function B(){const t=a-n,e=h-o;if(b+=t*p,w+=e*p,_){const s=W();0!==s.x&&(b-=t*I(s.x)*p),0!==s.y&&(w-=e*I(s.y)*p)}else W(!0);E(),n=a,o=h,S=!1}function I(t){return 5e-6*Math.pow(t,2)+1e-4*t+.55}function W(t){let n=0,o=0;return void 0!==e&&b<e?n=e-b:void 0!==s&&b>s&&(n=s-b),void 0!==i&&w<i?o=i-w:void 0!==r&&w>r&&(o=r-w),t&&(0!==n&&(b=n>0?e:s),0!==o&&(w=o>0?i:r)),{x:n,y:o,inBounds:0===n&&0===o}}function X(){if(!k)return;l*=m,u*=m,b+=l,w+=u;const t=W();if(Math.abs(l)>C||Math.abs(u)>C||!t.inBounds){if(_){const e=2.5;if(0!==t.x)if(t.x*l<=0)l+=.04*t.x;else{const s=t.x>0?e:-e;l=.11*(t.x+s)}if(0!==t.y)if(t.y*u<=0)u+=.04*t.y;else{const s=t.y>0?e:-e;u=.11*(t.y+s)}}else 0!==t.x&&(b=t.x>0?e:s,l=0),0!==t.y&&(w=t.y>0?i:r,u=0);E(),$o(X)}else k=!1,f&&f(d)}!function(){if(d="string"==typeof d?document.querySelector(d):d,!d)throw new Error("IMPETUS: source not found.");if(!g)throw new Error("IMPETUS: update function not defined.");v&&(v[0]&&(b=v[0]),v[1]&&(w=v[1]),E()),y&&(e=y[0],s=y[1]),x&&(i=x[0],r=x[1]),d.addEventListener("touchstart",j),d.addEventListener("mousedown",j)}(),this.destroy=function(){return d.removeEventListener("touchstart",j),d.removeEventListener("mousedown",j),D(),null},this.pause=function(){D(),T=!1,O=!0},this.resume=function(){O=!1},this.setValues=function(t,e){"number"==typeof t&&(b=t),"number"==typeof e&&(w=e)},this.setMultiplier=function(t){p=t,C=.3*p},this.setBoundX=function(t){e=t[0],s=t[1]},this.setBoundY=function(t){i=t[0],r=t[1]}}}const $o=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)};function ta(){let t=!1;try{const e=Object.defineProperty({},"passive",{get(){t=!0}});window.addEventListener("test",null,e)}catch(t){}return ta=()=>t,t}function ea(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var sa={exports:{}};
/*!
* EventEmitter2
* https://github.com/hij1nx/EventEmitter2
*
* Copyright (c) 2013 hij1nx
* Licensed under the MIT license.
*/!function(t){!function(e){var s=Object.hasOwnProperty,i=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},r="object"==typeof process&&"function"==typeof process.nextTick,n="function"==typeof Symbol,o="object"==typeof Reflect,a="function"==typeof setImmediate?setImmediate:setTimeout,h=n?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(t){var e=Object.getOwnPropertyNames(t);return e.push.apply(e,Object.getOwnPropertySymbols(t)),e}:Object.keys;function c(){this._events={},this._conf&&l.call(this,this._conf)}function l(t){t&&(this._conf=t,t.delimiter&&(this.delimiter=t.delimiter),t.maxListeners!==e&&(this._maxListeners=t.maxListeners),t.wildcard&&(this.wildcard=t.wildcard),t.newListener&&(this._newListener=t.newListener),t.removeListener&&(this._removeListener=t.removeListener),t.verboseMemoryLeak&&(this.verboseMemoryLeak=t.verboseMemoryLeak),t.ignoreErrors&&(this.ignoreErrors=t.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function u(t,e){var s="(node) warning: possible EventEmitter memory leak detected. "+t+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(s+=" Event name: "+e+"."),"undefined"!=typeof process&&process.emitWarning){var i=new Error(s);i.name="MaxListenersExceededWarning",i.emitter=this,i.count=t,process.emitWarning(i)}else console.error(s),console.trace&&console.trace()}var d=function(t,e,s){var i=arguments.length;switch(i){case 0:return[];case 1:return[t];case 2:return[t,e];case 3:return[t,e,s];default:for(var r=new Array(i);i--;)r[i]=arguments[i];return r}};function g(t,s){for(var i={},r=t.length,n=0;n<r;n++)i[t[n]]=n<0?s[n]:e;return i}function f(t,e,s){var i,r;if(this._emitter=t,this._target=e,this._listeners={},this._listenersCount=0,(s.on||s.off)&&(i=s.on,r=s.off),e.addEventListener?(i=e.addEventListener,r=e.removeEventListener):e.addListener?(i=e.addListener,r=e.removeListener):e.on&&(i=e.on,r=e.off),!i&&!r)throw Error("target does not implement any known event API");if("function"!=typeof i)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=i,this._off=r;var n=t._observers;n?n.push(this):t._observers=[this]}function p(t,i,r,n){var o=Object.assign({},i);if(!t)return o;if("object"!=typeof t)throw TypeError("options must be an object");var a,h,c,l=Object.keys(t),u=l.length;function d(t){throw Error('Invalid "'+a+'" option value'+(t?". Reason: "+t:""))}for(var g=0;g<u;g++){if(a=l[g],!s.call(i,a))throw Error('Unknown "'+a+'" option');(h=t[a])!==e&&(c=r[a],o[a]=c?c(h,d):h)}return o}function m(t,e){return"function"==typeof t&&t.hasOwnProperty("prototype")||e("value must be a constructor"),t}function v(t){var e="value must be type of "+t.join("|"),s=t.length,i=t[0],r=t[1];return 1===s?function(t,s){if(typeof t===i)return t;s(e)}:2===s?function(t,s){var n=typeof t;if(n===i||n===r)return t;s(e)}:function(i,r){for(var n=typeof i,o=s;o-- >0;)if(n===t[o])return i;r(e)}}Object.assign(f.prototype,{subscribe:function(t,e,s){var i=this,r=this._target,n=this._emitter,o=this._listeners,a=function(){var i=d.apply(null,arguments),o={data:i,name:e,original:t};s?!1!==s.call(r,o)&&n.emit.apply(n,[o.name].concat(i)):n.emit.apply(n,[e].concat(i))};if(o[t])throw Error("Event '"+t+"' is already listening");this._listenersCount++,n._newListener&&n._removeListener&&!i._onNewListener?(this._onNewListener=function(s){s===e&&null===o[t]&&(o[t]=a,i._on.call(r,t,a))},n.on("newListener",this._onNewListener),this._onRemoveListener=function(s){s===e&&!n.hasListeners(s)&&o[t]&&(o[t]=null,i._off.call(r,t,a))},o[t]=null,n.on("removeListener",this._onRemoveListener)):(o[t]=a,i._on.call(r,t,a))},unsubscribe:function(t){var e,s,i,r=this,n=this._listeners,o=this._emitter,a=this._off,c=this._target;if(t&&"string"!=typeof t)throw TypeError("event must be a string");function l(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var t=b.call(o,r);o._observers.splice(t,1)}if(t){if(!(e=n[t]))return;a.call(c,t,e),delete n[t],--this._listenersCount||l()}else{for(i=(s=h(n)).length;i-- >0;)t=s[i],a.call(c,t,n[t]);this._listeners={},this._listenersCount=0,l()}}});var y=v(["function"]),x=v(["object","function"]);function _(t,e,s){var i,r,n,o=0,a=new t(function(h,c,l){function u(){r&&(r=null),o&&(clearTimeout(o),o=0)}s=p(s,{timeout:0,overload:!1},{timeout:function(t,e){return("number"!=typeof(t*=1)||t<0||!Number.isFinite(t))&&e("timeout must be a positive number"),t}}),i=!s.overload&&"function"==typeof t.prototype.cancel&&"function"==typeof l;var d=function(t){u(),h(t)},g=function(t){u(),c(t)};i?e(d,g,l):(r=[function(t){g(t||Error("canceled"))}],e(d,g,function(t){if(n)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof t)throw TypeError("onCancel callback must be a function");r.push(t)}),n=!0),s.timeout>0&&(o=setTimeout(function(){var t=Error("timeout");t.code="ETIMEDOUT",o=0,a.cancel(t),c(t)},s.timeout))});return i||(a.cancel=function(t){if(r){for(var e=r.length,s=1;s<e;s++)r[s](t);r[0](t),r=null}}),a}function b(t){var e=this._observers;if(!e)return-1;for(var s=e.length,i=0;i<s;i++)if(e[i]._target===t)return i;return-1}function w(t,e,s,i,r){if(!s)return null;if(0===i){var n=typeof e;if("string"===n){var o,a,c=0,l=0,u=this.delimiter,d=u.length;if(-1!==(a=e.indexOf(u))){o=new Array(5);do{o[c++]=e.slice(l,a),l=a+d}while(-1!==(a=e.indexOf(u,l)));o[c++]=e.slice(l),e=o,r=c}else e=[e],r=1}else"object"===n?r=e.length:(e=[e],r=1)}var g,f,p,m,v,y,x,_=null,b=e[i],C=e[i+1];if(i===r)s._listeners&&("function"==typeof s._listeners?(t&&t.push(s._listeners),_=[s]):(t&&t.push.apply(t,s._listeners),_=[s]));else{if("*"===b){for(a=(y=h(s)).length;a-- >0;)"_listeners"!==(g=y[a])&&(x=w(t,e,s[g],i+1,r))&&(_?_.push.apply(_,x):_=x);return _}if("**"===b){for((v=i+1===r||i+2===r&&"*"===C)&&s._listeners&&(_=w(t,e,s,r,r)),a=(y=h(s)).length;a-- >0;)"_listeners"!==(g=y[a])&&("*"===g||"**"===g?(s[g]._listeners&&!v&&(x=w(t,e,s[g],r,r))&&(_?_.push.apply(_,x):_=x),x=w(t,e,s[g],i,r)):x=w(t,e,s[g],g===C?i+2:i,r),x&&(_?_.push.apply(_,x):_=x));return _}s[b]&&(_=w(t,e,s[b],i+1,r))}if((f=s["*"])&&w(t,e,f,i+1,r),p=s["**"])if(i<r)for(p._listeners&&w(t,e,p,r,r),a=(y=h(p)).length;a-- >0;)"_listeners"!==(g=y[a])&&(g===C?w(t,e,p[g],i+2,r):g===b?w(t,e,p[g],i+1,r):((m={})[g]=p[g],w(t,e,{"**":m},i+1,r)));else p._listeners?w(t,e,p,r,r):p["*"]&&p["*"]._listeners&&w(t,e,p["*"],r,r);return _}function C(t,e,s){var i,r,n=0,o=0,a=this.delimiter,h=a.length;if("string"==typeof t)if(-1!==(i=t.indexOf(a))){r=new Array(5);do{r[n++]=t.slice(o,i),o=i+h}while(-1!==(i=t.indexOf(a,o)));r[n++]=t.slice(o)}else r=[t],n=1;else r=t,n=t.length;if(n>1)for(i=0;i+1<n;i++)if("**"===r[i]&&"**"===r[i+1])return;var c,l=this.listenerTree;for(i=0;i<n;i++)if(l=l[c=r[i]]||(l[c]={}),i===n-1)return l._listeners?("function"==typeof l._listeners&&(l._listeners=[l._listeners]),s?l._listeners.unshift(e):l._listeners.push(e),!l._listeners.warned&&this._maxListeners>0&&l._listeners.length>this._maxListeners&&(l._listeners.warned=!0,u.call(this,l._listeners.length,c))):l._listeners=e,!0;return!0}function S(t,e,s,i){for(var r,n,o,a,c=h(t),l=c.length,u=t._listeners;l-- >0;)r=t[n=c[l]],o="_listeners"===n?s:s?s.concat(n):[n],a=i||"symbol"==typeof n,u&&e.push(a?o:o.join(this.delimiter)),"object"==typeof r&&S.call(this,r,e,o,a);return e}function T(t){for(var e,s,i,r=h(t),n=r.length;n-- >0;)(e=t[s=r[n]])&&(i=!0,"_listeners"===s||T(e)||delete t[s]);return i}function O(t,e,s){this.emitter=t,this.event=e,this.listener=s}function k(t,s,i){if(!0===i)o=!0;else if(!1===i)n=!0;else{if(!i||"object"!=typeof i)throw TypeError("options should be an object or true");var n=i.async,o=i.promisify,h=i.nextTick,c=i.objectify}if(n||h||o){var l=s,u=s._origin||s;if(h&&!r)throw Error("process.nextTick is not supported");o===e&&(o="AsyncFunction"===s.constructor.name),s=function(){var t=arguments,e=this,s=this.event;return o?h?Promise.resolve():new Promise(function(t){a(t)}).then(function(){return e.event=s,l.apply(e,t)}):(h?process.nextTick:a)(function(){e.event=s,l.apply(e,t)})},s._async=!0,s._origin=u}return[s,c?new O(this,t,s):this]}function M(t){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,l.call(this,t)}O.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},M.EventEmitter2=M,M.prototype.listenTo=function(t,s,r){if("object"!=typeof t)throw TypeError("target musts be an object");var n=this;function o(e){if("object"!=typeof e)throw TypeError("events must be an object");var s,i=r.reducers,o=b.call(n,t);s=-1===o?new f(n,t,r):n._observers[o];for(var a,c=h(e),l=c.length,u="function"==typeof i,d=0;d<l;d++)a=c[d],s.subscribe(a,e[a]||a,u?i:i&&i[a])}return r=p(r,{on:e,off:e,reducers:e},{on:y,off:y,reducers:x}),i(s)?o(g(s)):o("string"==typeof s?g(s.split(/\s+/)):s),this},M.prototype.stopListeningTo=function(t,e){var s=this._observers;if(!s)return!1;var i,r=s.length,n=!1;if(t&&"object"!=typeof t)throw TypeError("target should be an object");for(;r-- >0;)i=s[r],t&&i._target!==t||(i.unsubscribe(e),n=!0);return n},M.prototype.delimiter=".",M.prototype.setMaxListeners=function(t){t!==e&&(this._maxListeners=t,this._conf||(this._conf={}),this._conf.maxListeners=t)},M.prototype.getMaxListeners=function(){return this._maxListeners},M.prototype.event="",M.prototype.once=function(t,e,s){return this._once(t,e,!1,s)},M.prototype.prependOnceListener=function(t,e,s){return this._once(t,e,!0,s)},M.prototype._once=function(t,e,s,i){return this._many(t,1,e,s,i)},M.prototype.many=function(t,e,s,i){return this._many(t,e,s,!1,i)},M.prototype.prependMany=function(t,e,s,i){return this._many(t,e,s,!0,i)},M.prototype._many=function(t,e,s,i,r){var n=this;if("function"!=typeof s)throw new Error("many only accepts instances of Function");function o(){return 0===--e&&n.off(t,o),s.apply(this,arguments)}return o._origin=s,this._on(t,o,i,r)},M.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var t,e,s,i,r,o,a=arguments[0],h=this.wildcard;if("newListener"===a&&!this._newListener&&!this._events.newListener)return!1;if(h&&(t=a,"newListener"!==a&&"removeListener"!==a&&"object"==typeof a)){if(s=a.length,n)for(i=0;i<s;i++)if("symbol"==typeof a[i]){o=!0;break}o||(a=a.join(this.delimiter))}var l,u=arguments.length;if(this._all&&this._all.length)for(i=0,s=(l=this._all.slice()).length;i<s;i++)switch(this.event=a,u){case 1:l[i].call(this,a);break;case 2:l[i].call(this,a,arguments[1]);break;case 3:l[i].call(this,a,arguments[1],arguments[2]);break;default:l[i].apply(this,arguments)}if(h)l=[],w.call(this,l,t,this.listenerTree,0,s);else{if("function"==typeof(l=this._events[a])){switch(this.event=a,u){case 1:l.call(this);break;case 2:l.call(this,arguments[1]);break;case 3:l.call(this,arguments[1],arguments[2]);break;default:for(e=new Array(u-1),r=1;r<u;r++)e[r-1]=arguments[r];l.apply(this,e)}return!0}l&&(l=l.slice())}if(l&&l.length){if(u>3)for(e=new Array(u-1),r=1;r<u;r++)e[r-1]=arguments[r];for(i=0,s=l.length;i<s;i++)switch(this.event=a,u){case 1:l[i].call(this);break;case 2:l[i].call(this,arguments[1]);break;case 3:l[i].call(this,arguments[1],arguments[2]);break;default:l[i].apply(this,e)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===a)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},M.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var t,e,s,i,r,o,a=arguments[0],h=this.wildcard;if("newListener"===a&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(h&&(t=a,"newListener"!==a&&"removeListener"!==a&&"object"==typeof a)){if(i=a.length,n)for(r=0;r<i;r++)if("symbol"==typeof a[r]){e=!0;break}e||(a=a.join(this.delimiter))}var l,u=[],d=arguments.length;if(this._all)for(r=0,i=this._all.length;r<i;r++)switch(this.event=a,d){case 1:u.push(this._all[r].call(this,a));break;case 2:u.push(this._all[r].call(this,a,arguments[1]));break;case 3:u.push(this._all[r].call(this,a,arguments[1],arguments[2]));break;default:u.push(this._all[r].apply(this,arguments))}if(h?(l=[],w.call(this,l,t,this.listenerTree,0)):l=this._events[a],"function"==typeof l)switch(this.event=a,d){case 1:u.push(l.call(this));break;case 2:u.push(l.call(this,arguments[1]));break;case 3:u.push(l.call(this,arguments[1],arguments[2]));break;default:for(s=new Array(d-1),o=1;o<d;o++)s[o-1]=arguments[o];u.push(l.apply(this,s))}else if(l&&l.length){if(l=l.slice(),d>3)for(s=new Array(d-1),o=1;o<d;o++)s[o-1]=arguments[o];for(r=0,i=l.length;r<i;r++)switch(this.event=a,d){case 1:u.push(l[r].call(this));break;case 2:u.push(l[r].call(this,arguments[1]));break;case 3:u.push(l[r].call(this,arguments[1],arguments[2]));break;default:u.push(l[r].apply(this,s))}}else if(!this.ignoreErrors&&!this._all&&"error"===a)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(u)},M.prototype.on=function(t,e,s){return this._on(t,e,!1,s)},M.prototype.prependListener=function(t,e,s){return this._on(t,e,!0,s)},M.prototype.onAny=function(t){return this._onAny(t,!1)},M.prototype.prependAny=function(t){return this._onAny(t,!0)},M.prototype.addListener=M.prototype.on,M.prototype._onAny=function(t,e){if("function"!=typeof t)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),e?this._all.unshift(t):this._all.push(t),this},M.prototype._on=function(t,s,i,r){if("function"==typeof t)return this._onAny(t,s),this;if("function"!=typeof s)throw new Error("on only accepts instances of Function");this._events||c.call(this);var n,o=this;return r!==e&&(s=(n=k.call(this,t,s,r))[0],o=n[1]),this._newListener&&this.emit("newListener",t,s),this.wildcard?(C.call(this,t,s,i),o):(this._events[t]?("function"==typeof this._events[t]&&(this._events[t]=[this._events[t]]),i?this._events[t].unshift(s):this._events[t].push(s),!this._events[t].warned&&this._maxListeners>0&&this._events[t].length>this._maxListeners&&(this._events[t].warned=!0,u.call(this,this._events[t].length,t))):this._events[t]=s,o)},M.prototype.off=function(t,e){if("function"!=typeof e)throw new Error("removeListener only takes instances of Function");var s,r=[];if(this.wildcard){var n="string"==typeof t?t.split(this.delimiter):t.slice();if(!(r=w.call(this,null,n,this.listenerTree,0)))return this}else{if(!this._events[t])return this;s=this._events[t],r.push({_listeners:s})}for(var o=0;o<r.length;o++){var a=r[o];if(s=a._listeners,i(s)){for(var h=-1,c=0,l=s.length;c<l;c++)if(s[c]===e||s[c].listener&&s[c].listener===e||s[c]._origin&&s[c]._origin===e){h=c;break}if(h<0)continue;return this.wildcard?a._listeners.splice(h,1):this._events[t].splice(h,1),0===s.length&&(this.wildcard?delete a._listeners:delete this._events[t]),this._removeListener&&this.emit("removeListener",t,e),this}(s===e||s.listener&&s.listener===e||s._origin&&s._origin===e)&&(this.wildcard?delete a._listeners:delete this._events[t],this._removeListener&&this.emit("removeListener",t,e))}return this.listenerTree&&T(this.listenerTree),this},M.prototype.offAny=function(t){var e,s=0,i=0;if(t&&this._all&&this._all.length>0){for(s=0,i=(e=this._all).length;s<i;s++)if(t===e[s])return e.splice(s,1),this._removeListener&&this.emit("removeListenerAny",t),this}else{if(e=this._all,this._removeListener)for(s=0,i=e.length;s<i;s++)this.emit("removeListenerAny",e[s]);this._all=[]}return this},M.prototype.removeListener=M.prototype.off,M.prototype.removeAllListeners=function(t){if(t===e)return!this._events||c.call(this),this;if(this.wildcard){var s,i=w.call(this,null,t,this.listenerTree,0);if(!i)return this;for(s=0;s<i.length;s++)i[s]._listeners=null;this.listenerTree&&T(this.listenerTree)}else this._events&&(this._events[t]=null);return this},M.prototype.listeners=function(t){var s,i,r,n,o,a=this._events;if(t===e){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!a)return[];for(n=(s=h(a)).length,r=[];n-- >0;)"function"==typeof(i=a[s[n]])?r.push(i):r.push.apply(r,i);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],l="string"==typeof t?t.split(this.delimiter):t.slice();return w.call(this,c,l,o,0),c}return a&&(i=a[t])?"function"==typeof i?[i]:i:[]},M.prototype.eventNames=function(t){var e=this._events;return this.wildcard?S.call(this,this.listenerTree,[],null,t):e?h(e):[]},M.prototype.listenerCount=function(t){return this.listeners(t).length},M.prototype.hasListeners=function(t){if(this.wildcard){var s=[],i="string"==typeof t?t.split(this.delimiter):t.slice();return w.call(this,s,i,this.listenerTree,0),s.length>0}var r=this._events,n=this._all;return!!(n&&n.length||r&&(t===e?h(r).length:r[t]))},M.prototype.listenersAny=function(){return this._all?this._all:[]},M.prototype.waitFor=function(t,s){var i=this,r=typeof s;return"number"===r?s={timeout:s}:"function"===r&&(s={filter:s}),_((s=p(s,{timeout:0,filter:e,handleError:!1,Promise:Promise,overload:!1},{filter:y,Promise:m})).Promise,function(e,r,n){function o(){var n=s.filter;if(!n||n.apply(i,arguments))if(i.off(t,o),s.handleError){var a=arguments[0];a?r(a):e(d.apply(null,arguments).slice(1))}else e(d.apply(null,arguments))}n(function(){i.off(t,o)}),i._on(t,o,!1)},{timeout:s.timeout,overload:s.overload})};var D=M.prototype;Object.defineProperties(M,{defaultMaxListeners:{get:function(){return D._maxListeners},set:function(t){if("number"!=typeof t||t<0||Number.isNaN(t))throw TypeError("n must be a non-negative number");D._maxListeners=t},enumerable:!0},once:{value:function(t,e,s){return _((s=p(s,{Promise:Promise,timeout:0,overload:!1},{Promise:m})).Promise,function(s,i,r){var n;if("function"==typeof t.addEventListener)return n=function(){s(d.apply(null,arguments))},r(function(){t.removeEventListener(e,n)}),void t.addEventListener(e,n,{once:!0});var o,a=function(){o&&t.removeListener("error",o),s(d.apply(null,arguments))};"error"!==e&&(o=function(s){t.removeListener(e,a),i(s)},t.once("error",o)),r(function(){o&&t.removeListener("error",o),t.removeListener(e,a)}),t.once(e,a)},{timeout:s.timeout,overload:s.overload})},writable:!0,configurable:!0}}),Object.defineProperties(D,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),t.exports=M}()}(sa);var ia=ea(sa.exports),ra={left:0,top:0};function na(t,e,s){e=e||t.currentTarget||t.srcElement,Array.isArray(s)||(s=[0,0]);var i,r=t.clientX||0,n=t.clientY||0,o=(i=e)===window||i===document||i===document.body?ra:i.getBoundingClientRect();return s[0]=r-o.left,s[1]=n-o.top,s}function oa(t){t=t||window;var e=new ia,s=[null,null],i=0,r=0,n=!1,o=!1;return Object.defineProperties(e,{pinching:()=>2===i,fingers:()=>s}),h(),e.enable=h,e.disable=function(){if(!o)return;o=!1,i=0,s[0]=null,s[1]=null,r=0,n=!1,t.removeEventListener("touchstart",c,!1),t.removeEventListener("touchmove",l,!1),t.removeEventListener("touchend",u,!1),t.removeEventListener("touchcancel",u,!1)},e.indexOfTouch=a,e;function a(t){for(var e=t.identifier,i=0;i<s.length;i++)if(s[i]&&s[i].touch&&s[i].touch.identifier===e)return i;return-1}function h(){o||(o=!0,t.addEventListener("touchstart",c,!1),t.addEventListener("touchmove",l,!1),t.addEventListener("touchend",u,!1),t.addEventListener("touchcancel",u,!1))}function c(o){for(var h=0;h<o.changedTouches.length;h++){var c=o.changedTouches[h];if(-1===a(c.identifier)&&i<2){var l=0===i,u=s[0]?1:0,g=s[0]?0:1,f=new aa;s[u]=f,i++,f.touch=c,na(c,t,f.position);var p=s[g]?s[g].touch:void 0;if(e.emit("place",c,p),!l){var m=d();n=!1,e.emit("start",m),r=m}}}}function l(n){for(var o=!1,h=0;h<n.changedTouches.length;h++){var c=n.changedTouches[h],l=a(c);-1!==l&&(o=!0,s[l].touch=c,na(c,t,s[l].position))}if(2===i&&o){var u=d();e.emit("change",u,r),r=u}}function u(t){for(var r=0;r<t.changedTouches.length;r++){var o=t.changedTouches[r],h=a(o);if(-1!==h){s[h]=null,i--;var c=0===h?1:0,l=s[c]?s[c].touch:void 0;e.emit("lift",o,l)}}n||2===i||(n=!0,e.emit("end"))}function d(){return i<2?0:function(t,e){var s=e[0]-t[0],i=e[1]-t[1];return Math.sqrt(s*s+i*i)}(s[0].position,s[1].position)}}function aa(){this.position=[0,0],this.touch=null}function ha(t){return window["webkit"+t]||window["moz"+t]||window["ms"+t]}var ca=0;function la(t){var e=+new Date,s=Math.max(0,16-(e-ca));return ca=e+s,window.setTimeout(t,s)}var ua=window.requestAnimationFrame||ha("RequestAnimationFrame")||la,da=window.cancelAnimationFrame||ha("CancelAnimationFrame")||ha("CancelRequestAnimationFrame")||function(t){window.clearTimeout(t)};const ga=(t,e,s)=>{if(!s||ua!==la)return ua.call(window,function(t,e){var s=Array.prototype.slice;if(t.bind)return t.bind.apply(t,s.call(arguments,1));var i=s.call(arguments,2);return function(){return t.apply(e,i.length?i.concat(s.call(arguments)):arguments)}}(t,e));t.call(e)};ga.cancel=t=>{t&&da.call(window,t)};class fa{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:80,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:12,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,r=arguments.length>4&&void 0!==arguments[4]&&arguments[4];t===document&&(t=document.scrollingElement||document.documentElement||document.body.parentNode||document.body),this.speed=e,this.smooth=s,this.moving=!1,this.scrollTop=3e3*i,this.pos=this.scrollTop,this.frame=t===document.body&&document.documentElement?document.documentElement:t,t.addEventListener("wheel",o,{passive:r}),t.addEventListener("DOMMouseScroll",o,{passive:r});const n=this;function o(t){t.preventDefault();const e=n.normalizeWheelDelta(t);n.pos+=-e*n.speed,n.moving||n.update(t)}}normalizeWheelDelta(t){return t.detail?t.wheelDelta?t.wheelDelta/t.detail/40*(t.detail>0?1:-1):-t.detail/3:t.wheelDelta/120}update(t){this.moving=!0;const e=(this.pos-this.scrollTop)/this.smooth;this.scrollTop+=e,this.onUpdate&&this.onUpdate(e,t);const s=this;Math.abs(e)>1?pa(()=>{s.update()}):this.moving=!1}}var pa=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3)};function ma(t,e,s){return s>e?Math.max(Math.min(t,s),e):Math.max(Math.min(t,e),s)}function va(t,e){return Math.sqrt(t*t+e*e)}var ya=Math.abs,xa=Math.min;function _a(t,e,s,i){var r=ya(t-e);return null==s&&(s=_a.DBL_EPSILON),null==i&&(i=s),r<=s||(r<=i*xa(ya(t),ya(e))||t===e)}_a.FLT_EPSILON=1.1920929e-7,_a.DBL_EPSILON=2220446049250313e-31;var ba=Math.log10||function(t){return Math.log(t)/Math.log(10)};function wa(t,e,s){var i=t%e;return s||(s=_a.FLT_EPSILON),!i||!(!_a(0,i,s,0)&&!_a(Math.abs(e),Math.abs(i),s,0))}function Ca(t,e){var s=Math.floor(ba(t)),i=Math.pow(10,s),r=e.map(t=>t*i);i=Math.pow(10,s+1),r=r.concat(e.map(t=>t*i));for(var n=0,o=0;o<r.length&&!((n=r[o])>=t);o++);return n}var Sa=(t,e)=>{e||(e=[0,""]),t=String(t);var s=parseFloat(t,10);return e[0]=s,e[1]=t.match(/[\d.\-\+]*\s*(.*)/)[1]||"",e},Ta={ch:8,ex:7.15625,em:16,rem:16,in:96,cm:96/2.54,mm:96/25.4,pt:96/72,pc:16,px:1};function Oa(t){if(!t)return null;if(Ta[t])return Ta[t];var e=Sa(t);if(!isNaN(e[0])&&e[1]){var s=Oa(e[1]);return"number"==typeof s?e[0]*s:null}return null}var ka=t=>{if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.getPrototypeOf({})};class Ma extends ia{constructor(t){super(t),this._options=t||{},Object.assign(this,t)}}function Da(t,e){let s=t.replace(/[^\d,]/g,"").split(",");return null==e&&(e=s[3]||1),s[3]=e,"rgba("+s.join(",")+")"}const Ea={steps:[1,2,5],distance:20,unit:10,lines:t=>{const e=t.coordinate,s=t.step=Ca(e.distance*e.zoom,e.steps);return function(t,e,s){if(null!=t&&"number"!=typeof t)throw new Error("start must be a number or null");if(null!=e&&"number"!=typeof e)throw new Error("stop must be a number or null");if(null!=s&&"number"!=typeof s)throw new Error("step must be a number or null");null==e&&(e=t||0,t=0),null==s&&(s=e>t?1:-1);for(var i=[],r=t<e;r?t<e:t>e;t+=s)i.push(t);return i}(Math.floor(t.offset/s)*s,Math.ceil((t.offset+t.range)/s+1)*s,s)},lineColor:t=>{if(!t.lines)return;const e=t.coordinate,s=Da(e.color,.1),i=Da(e.color,.3),r=t.step,n=Math.ceil(ba(r)),o=10**n,a=10**(n+1),h=r/10,c=t.lines.map(t=>wa(t,a,h)?i:wa(t,o,h)?s:null);return c},ticks:t=>{if(!t.lines)return;const e=t.coordinate,s=Ca(1.1*Ca(1.1*t.step,e.steps),e.steps),i=s/10,r=4*t.axisWidth;return t.lines.map(t=>wa(t,s,i)?_a(t,0,i)?null:r:null)},labels:t=>{if(!t.lines)return;const e=t.coordinate,s=Ca(1.1*Ca(1.1*t.step,e.steps),e.steps),i=s/100;return t.lines.map(t=>wa(t,s,i)?_a(t,0,i)?"y"===e.orientation?null:"0":(t=Number((t/100).toFixed(2)),e.format(t)):null)}};class Aa{constructor(t,e){Object.assign(this,e),this.orientation=t||"x"}getCoords(t){const e=[];if(!t)return e;for(let s=0;s<t.length;s+=1){const i=this.getRatio(t[s]);e.push(i),e.push(0),e.push(i),e.push(1)}return e}getRange(){let t=this.width;return"y"===this.orientation&&(t=this.height),t*this.zoom}getRatio(t){return(t-this.offset)/this.range}setOffset(t){this.offset=t}update(t){t=t||{},Object.assign(this,t),this.range=this.getRange()}}class ja extends Ma{constructor(t,e){super(e),this.canvas=t,this.context=this.canvas.getContext("2d"),this.state={},this.setDefaults(),this.update(e)}setOriginPin(t){this.isPinned="NONE"!==t,this.pinnedCorner=t,this.emit("originpin:change",t),this.pinnedAbsolute={x:this.getPinnedX(),y:this.getPinnedY()}}setPinMargin(t){this.pinMargin=t,this.emit("pinmargin:change",t)}setZoomOverMouse(t){this.zoomOverMouse=t,this.emit("zoomovermouse:change",t)}getPinnedX(){const{width:t}=this.canvas,e=t/this.center.zoom,s=this.pinMargin/this.center.zoom;return this.pinnedCorner.includes("RIGHT")?-(e/2-s):e/2-s}getPinnedY(){const{height:t}=this.canvas,e=t/this.center.zoom,s=this.pinMargin/this.center.zoom;return this.pinnedCorner.includes("BOTTOM")?e/2-s:-e/2+s}render(){return this.draw(),this}getCenterCoords(){let t=this.state.x,[e,s]=t.shape,[i,r,n,o]=t.padding,a=t.opposite.coordinate.getCoords([t.coordinate.axisOrigin],t.opposite);const h=i+a[1]*(s-i-n);t=this.state.y,[e,s]=t.shape,[i,r,n,o]=t.padding,a=t.opposite.coordinate.getCoords([t.coordinate.axisOrigin],t.opposite);return{x:o+a[0]*(e-r-o),y:h}}setSize(t,e){this.setWidth(t),this.setHeight(e)}setWidth(t){this.canvas.width=t}setHeight(t){this.canvas.height=t}update(t){t||(t={});const e=[this.canvas.width,this.canvas.height];return this.state.x=this.calcCoordinate(this.axisX,e,this),this.state.y=this.calcCoordinate(this.axisY,e,this),this.state.x.opposite=this.state.y,this.state.y.opposite=this.state.x,this.emit("update",t),this}update2(t){this.isPinned&&(t.x=this.getPinnedX(),t.y=this.getPinnedY());const e=[this.canvas.width,this.canvas.height];Object.assign(this.center,t),this.state.x=this.calcCoordinate(this.axisX,e,this),this.state.y=this.calcCoordinate(this.axisY,e,this),this.state.x.opposite=this.state.y,this.state.y.opposite=this.state.x,this.emit("update",t),this.axisX.offset=t.x,this.axisX.zoom=1/t.zoom,this.axisY.offset=t.y,this.axisY.zoom=1/t.zoom}calcCoordinate(t,e){const s={coordinate:t,shape:e,grid:this};if(s.range=t.getRange(s),s.offset=ma(t.offset-s.range*ma(.5,0,1),Math.max(t.min,1-Number.MAX_VALUE),Math.min(t.max,Number.MAX_VALUE)-s.range),s.zoom=t.zoom,s.axisColor="number"==typeof t.axisColor?Da(t.color,t.axisColor):t.axisColor||t.color,s.axisWidth=t.axisWidth||t.lineWidth,s.lineWidth=t.lineWidth,s.tickAlign=t.tickAlign,s.labelColor=s.color,"number"==typeof t.padding?s.padding=Array(4).fill(t.padding):t.padding instanceof Function?s.padding=t.padding(s):s.padding=t.padding,"number"==typeof t.fontSize)s.fontSize=t.fontSize;else{const e=Sa(t.fontSize);s.fontSize=e[0]*Oa(e[1])}let i,r,n;if(s.fontFamily=t.fontFamily||"sans-serif",i=t.lines instanceof Function?t.lines(s):t.lines||[],s.lines=i,t.lineColor instanceof Function)s.lineColors=t.lineColor(s);else if(Array.isArray(t.lineColor))s.lineColors=t.lineColor;else{let e=Da(t.color,t.lineColor);"number"!=typeof t.lineColor&&(e=!1===t.lineColor||null==t.lineColor?null:t.color),s.lineColors=Array(i.length).fill(e)}if(t.ticks instanceof Function)r=t.ticks(s);else if(Array.isArray(t.ticks))r=t.ticks;else{const e=!0===t.ticks||!0===t.ticks?2*s.axisWidth:t.ticks||0;r=Array(i.length).fill(e)}return s.ticks=r,n=!0===t.labels?s.lines:t.labels instanceof Function?t.labels(s):Array.isArray(t.labels)||ka(t.labels)?t.labels:Array(s.lines.length).fill(null),s.labels=n,ka(r)&&(s.ticks=Array(i.length).fill(0)),ka(n)&&(s.labels=Array(s.lines.length).fill(null)),ka(r)&&Object.keys(r).forEach((t,e)=>{s.ticks.push(e),s.lines.push(parseFloat(t)),s.lineColors.push(null),s.labels.push(null)}),ka(n)&&Object.keys(n).forEach((t,e)=>{s.labels.push(t),s.lines.push(parseFloat(e)),s.lineColors.push(null),s.ticks.push(null)}),s}setDefaults(){this.pixelRatio=window.devicePixelRatio,this.autostart=!0,this.interactions=!0,this.defaults=Object.assign({type:"linear",name:"",units:"",state:{},minZoom:-1/0,maxZoom:1/0,min:-1/0,max:1/0,offset:0,origin:.5,center:{x:0,y:0,zoom:1},zoom:1,zoomEnabled:!0,panEnabled:!0,pinnedCorner:"NONE",pinnedAbsolute:{x:0,y:0},isPinned:!1,pinMargin:0,labels:!0,fontSize:"11pt",fontFamily:"sans-serif",padding:0,color:"rgb(0,0,0,1)",lines:!0,tick:8,tickAlign:.5,lineWidth:1,distance:13,style:"lines",lineColor:.4,axis:!0,axisOrigin:0,axisWidth:2,axisColor:.8,getCoords:()=>[0,0,0,0],getRatio:()=>0,format:t=>t},Ea,this._options),this.axisX=new Aa("x",this.defaults),this.axisY=new Aa("y",this.defaults),this.axisX=Object.assign({},this.defaults,{orientation:"x",offset:this.center.x,getCoords:(t,e)=>{const s=[];if(!t)return s;for(let i=0;i<t.length;i+=1){const r=e.coordinate.getRatio(t[i],e);s.push(r),s.push(0),s.push(r),s.push(1)}return s},getRange:t=>t.shape[0]*t.coordinate.zoom,getRatio:(t,e)=>(t-e.offset)/e.range}),this.axisY=Object.assign({},this.defaults,{orientation:"y",offset:this.center.y,getCoords:(t,e)=>{const s=[];if(!t)return s;for(let i=0;i<t.length;i+=1){const r=e.coordinate.getRatio(t[i],e);s.push(0),s.push(r),s.push(1),s.push(r)}return s},getRange:t=>t.shape[1]*t.coordinate.zoom,getRatio:(t,e)=>1-(t-e.offset)/e.range}),Object.assign(this,this.defaults),Object.assign(this,this._options),this.center=new Go(this.center)}draw(){return this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawLines(this.state.x),this.drawLines(this.state.y),this}drawLines(t){if(!t||!t.coordinate)return;const e=this.context,[s,i]=t.shape,[r,n,o,a]=t.padding;let h=t.opposite.coordinate.getRatio(t.coordinate.axisOrigin,t.opposite);h=ma(h,0,1);const c=t.coordinate.getCoords(t.lines,t);e.lineWidth=1;for(let h=0,l=0;h<c.length;h+=4,l+=1){const u=t.lineColors[l];if(!u)continue;e.strokeStyle=u,e.beginPath();const d=0+a+c[h]*(s-n-a),g=0+r+c[h+1]*(i-o-r),f=0+a+c[h+2]*(s-n-a),p=0+r+c[h+3]*(i-o-r);e.moveTo(d,g),e.lineTo(f,p),e.stroke(),e.closePath()}const l=[];for(let t=0;t<c.length;t+=4){const e=c[t],s=c[t+1],i=c[t+2]-e,r=c[t+3]-s,n=va(i,r);l.push(i/n),l.push(r/n)}const u=[];t.labelCoords=[];const d=t.ticks;for(let e=0,g=0,f=0;e<l.length;f+=1,e+=2,g+=4){const p=c[g],m=c[g+1],v=(c[g+2]-p)*h,y=(c[g+3]-m)*h,x=[l[e]*d[f]/(s-a-n),l[e+1]*d[f]/(i-r-o)];u.push(l[e]*(v+x[0]*t.tickAlign)+p),u.push(l[e+1]*(y+x[1]*t.tickAlign)+m),u.push(l[e]*(v-x[0]*(1-t.tickAlign))+p),u.push(l[e+1]*(y-x[1]*(1-t.tickAlign))+m),t.labelCoords.push(l[e]*v+p),t.labelCoords.push(l[e+1]*y+m)}if(d.length){e.lineWidth=t.axisWidth/2,e.beginPath();for(let h=0,c=0;h<u.length;h+=4,c+=1){if(_a(t.lines[c],t.opposite.coordinate.axisOrigin))continue;const l=0+a+u[h]*(s-a-n),d=0+r+u[h+1]*(i-r-o),g=0+a+u[h+2]*(s-a-n),f=0+r+u[h+3]*(i-r-o);e.moveTo(l,d),e.lineTo(g,f)}e.strokeStyle=t.axisColor,e.stroke(),e.closePath()}if(t.coordinate.axis&&t.axisColor){const h=t.opposite.coordinate.getCoords([t.coordinate.axisOrigin],t.opposite);e.lineWidth=t.axisWidth/2;const c=0+a+ma(h[0],0,1)*(s-n-a),l=0+r+ma(h[1],0,1)*(i-r-o),u=0+a+ma(h[2],0,1)*(s-n-a),d=0+r+ma(h[3],0,1)*(i-r-o);e.beginPath(),e.moveTo(c,l),e.lineTo(u,d),e.strokeStyle=t.axisColor,e.stroke(),e.closePath()}this.drawLabels(t)}drawLabels(t){if(t.labels){const e=this.context,[s,i]=t.shape,[r,n,o,a]=t.padding;e.font=`300 ${t.fontSize}px ${t.fontFamily}`,e.fillStyle=t.labelColor,e.textBaseline="top";const h=t.fontSize,c=t.axisWidth+1.5,l=t.tickAlign<.5?-h-2*t.axisWidth:2*t.axisWidth,u="y"===t.coordinate.orientation&&!t.opposite.disabled;for(let d=0;d<t.labels.length;d+=1){let g=t.labels[d];if(null==g)continue;if(u&&_a(t.lines[d],t.opposite.coordinate.axisOrigin))continue;const f=e.measureText(g).width;let p=t.labelCoords[2*d]*(s-a-n)+c+a;"y"===t.coordinate.orientation&&(p=ma(p,c,s-f-1-t.axisWidth),g*=-1);let m=t.labelCoords[2*d+1]*(i-r-o)+l+r;"x"===t.coordinate.orientation&&(m=ma(m,0,i-h-l)),e.fillText(g,p,m)}}}}const Pa=t=>class extends t{setMode(t){switch(this.mode=t,t){case Ho.SELECT:this.canvas.isDrawingMode=!1,this.canvas.interactive=!0,this.canvas.selection=!0,this.canvas.hoverCursor="default",this.canvas.moveCursor="default";break;case Ho.GRAB:this.canvas.isDrawingMode=!1,this.canvas.interactive=!1,this.canvas.selection=!1,this.canvas.discardActiveObject(),this.canvas.hoverCursor="move",this.canvas.moveCursor="move";break;case Ho.MEASURE:this.canvas.isDrawingMode=!0,this.canvas.freeDrawingBrush.color="transparent",this.canvas.discardActiveObject();break;case Ho.DRAW:this.canvas.isDrawingMode=!0}}setModeAsDraw(){this.setMode(Ho.DRAW)}setModeAsSelect(){this.setMode(Ho.SELECT)}setModeAsMeasure(){this.setMode(Ho.MEASURE)}setModeAsGrab(){this.setMode(Ho.GRAB)}isSelectMode(){return this.mode===Ho.SELECT}isGrabMode(){return this.mode===Ho.GRAB}isMeasureMode(){return this.mode===Ho.MEASURE}isDrawMode(){return this.mode===Ho.DRAW}};class La{constructor(t){if((t=t||{}).hasBorders=!1,t.selectable=!1,t.hasControls=!1,t.class="measurer",t.scale=t.scale||1,this.options=t||{},this.start=this.options.start,this.end=this.options.end,this.canvas=this.options.map.canvas,this.completed=!1,!this.start||!this.end)throw new Error("start must be defined");this.draw()}clear(){this.objects&&this.objects.forEach(t=>{this.canvas.remove(t)})}draw(){this.clear();let{start:t,end:e}=this;t=new Go(t),e=new Go(e);const s=t.add(e).multiply(.5);this.line=new fabric.Line([t.x,t.y,e.x,e.y],{stroke:this.options.stroke||"#3e82ff",hasControls:!1,hasBorders:!1,selectable:!1,evented:!1,strokeDashArray:[5,5]});const i={left:t.x,top:t.y,strokeWidth:1,radius:this.options.radius||1,fill:this.options.fill||"#3e82ff",stroke:this.options.stroke||"#3e82ff",hasControls:!1,hasBorders:!1},r={left:t.x,top:t.y,strokeWidth:1,radius:this.options.radius||5,fill:this.options.fill||"#3e82ff33",stroke:this.options.stroke||"#3e82ff",hasControls:!1,hasBorders:!1};this.circle1=new fabric.Circle(r),this.circle2=new fabric.Circle({...r,left:e.x,top:e.y}),this.circle11=new fabric.Circle(i),this.circle22=new fabric.Circle({...i,left:e.x,top:e.y});let n=Math.round(t.distanceFrom(e));n=n/100+" m",this.text=new fabric.Text(n,{textBackgroundColor:"black",fill:"white",left:s.x,top:s.y-10,fontSize:12,hasControls:!1,hasBorders:!1,selectable:!1,evented:!1}),this.objects=[this.line,this.text,this.circle11,this.circle22,this.circle1,this.circle2],this.objects.forEach(t=>{this.canvas.add(t)}),this.line.hasControls=!1,this.line.hasBorders=!1,this.line.selectable=!1,this.line.evented=!1,this.registerListeners()}setStart(t){this.start=t,this.draw()}setEnd(t){this.end=t,this.draw()}complete(){this.completed=!0}registerListeners(){this.circle2.on("moving",t=>{this.setEnd(t.pointer)}),this.circle1.on("moving",t=>{this.setStart(t.pointer)})}applyScale(t){this.start.x*=t,this.start.y*=t,this.end.x*=t,this.end.y*=t,this.draw()}}class Fa{constructor(t){this.map=t,this.measurer=null}onMouseMove(t){const e={x:t.absolutePointer.x,y:t.absolutePointer.y};this.measurer&&!this.measurer.completed&&(this.measurer.setEnd(e),this.map.canvas.requestRenderAll())}onClick(t){const e={x:t.absolutePointer.x,y:t.absolutePointer.y};this.measurer?this.measurer.completed||(this.measurer.setEnd(e),this.measurer.complete()):this.measurer=new La({start:e,end:e,map:this.map})}}class Ra{constructor(t){this.superclass=t||class{}}with(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.reduce((t,e)=>e(t),this.superclass)}}let Ba=class extends((t=>new Ra(t))(Ma).with(Pa)){constructor(t,e){super(e),this.defaults=Object.assign({},Uo),Object.assign(this,this.defaults),this.originPin="NONE",this.pinMargin=10,this.zoomOverMouse=!0,Object.assign(this,this._options),this.center=new Go(this.center),this.container=t||document.body;const s=document.createElement("canvas");this.container.appendChild(s),s.setAttribute("id","fabric-layers-canvas"),s.width=this.width||this.container.clientWidth,s.height=this.height||this.container.clientHeight,this.canvas=new fabric.Canvas(s,{preserveObjectStacking:!0,renderOnAddRemove:!0}),this.context=this.canvas.getContext("2d"),this.on("render",()=>{this.autostart&&this.clear()}),this.originX=-this.canvas.width/2,this.originY=-this.canvas.height/2,this.canvas.absolutePan({x:this.originX,y:this.originY}),this.x=this.center.x,this.y=this.center.y,this.dx=0,this.dy=0,this.showGrid&&this.addGrid(),this.setMode(this.mode||Ho.GRAB);const i=this;((t,e)=>{t instanceof Function&&(e=t,t=document.documentElement||document.body),"string"==typeof t&&(t=document.querySelector(t));let s={x:0,y:0};const i=()=>{let t=!1;try{const e=Object.defineProperty({},"passive",{get(){t=!0}});window.addEventListener("test",null,e),window.removeEventListener("test",null,e)}catch(e){t=!1}return t};let r,n,o=0,a=0,h=!0;const c=function(t){h=!0};t.addEventListener("mousedown",c);const l=t=>{s=Qo(t)};t.addEventListener("mousemove",l);const u=function(t){t&&(s=Qo(t))};t.addEventListener("wheel",u,!!i()&&{passive:!0}),t.addEventListener("touchstart",c,!!i()&&{passive:!0}),t.addEventListener("contextmenu",t=>(t.preventDefault(),!1),!1);let d=0,g=0;r=new Jo({source:t,update(e,i){h&&(h=!1,o=s.x,a=s.y);const r={target:t,type:"mouse",dx:e-g,dy:i-d,dz:0,x:s.x,y:s.y,x0:o,y0:a,isRight:s.isRight};g=e,d=i,y(r)},stop(){y({target:t,type:"mouse",dx:0,dy:0,dz:0,x:s.x,y:s.y,x0:o,y0:a})},multiplier:1,friction:.75}),n=new fa(t,80,12,0),n.onUpdate=(e,i)=>{y({target:t,type:"mouse",dx:0,dy:0,dz:e,x:s.x,y:s.y,x0:s.x,y0:s.y})};const f=oa(t);let p,m,v;function y(t){null==v?v=ga(()=>{if(e(t),v=null,m){const t=m;m=null,y(t)}}):m?(m.dx+=t.dx,m.dy+=t.dy,m.dz+=t.dz,m.x=t.x,m.y=t.y):m=t}f.on("start",t=>{const e=f.fingers[0],s=f.fingers[1];p=[.5*s.position[0]+.5*e.position[0],.5*s.position[1]+.5*e.position[1]],r&&r.pause()}),f.on("end",()=>{p&&(p=null,r&&r.resume())}),f.on("change",(e,s)=>{f.pinching&&p&&y({target:t,type:"touch",dx:0,dy:0,dz:2*-(e-s),x:p[0],y:p[1],x0:p[0],y0:p[0]})})})(this.container,t=>{i.panzoom(t)}),this.registerListeners(),setTimeout(()=>{this.emit("ready",this)},300),this.measurement=new Fa(this)}addLayer(t){if(t.shape){if(this.canvas.add(t.shape),this.canvas._objects.sort((t,e)=>t.zIndex-e.zIndex),t.shape.keepOnZoom){const e=1/this.zoom;t.shape.set("scaleX",e),t.shape.set("scaleY",e),t.shape.setCoords(),this.emit(`${t.class}scaling`,t)}t.class&&this.emit(`${t.class}:added`,t),this.canvas.requestRenderAll()}else console.error("shape is undefined")}removeLayer(t){t&&t.shape&&(t.class&&this.emit(`${t.class}:removed`,t),this.canvas.remove(t.shape))}addGrid(){this.gridCanvas=this.cloneCanvas(),this.gridCanvas.setAttribute("id","fabric-layers-grid-canvas"),this.grid=new ja(this.gridCanvas,this),this.grid.setOriginPin(this.originPin),this.grid.setPinMargin(this.pinMargin),this.grid.setZoomOverMouse(this.zoomOverMouse),this.grid.draw()}moveTo(t,e){void 0!==e&&(t.zIndex=e),this.grid&&this.grid.isPinned||this.canvas.moveTo(t.shape,t.zIndex)}cloneCanvas(t){t=t||this.canvas;const e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.style.position="absolute",e.style.top="0",e.style.left="0",t.wrapperEl.appendChild(e),e}setZoom(t){const{width:e,height:s}=this.canvas;this.zoom=ma(t,this.minZoom,this.maxZoom),this.dx=0,this.dy=0,this.x=e/2,this.y=s/2,this.update(),setTimeout(()=>{this.update()},0)}getBounds(){let t=1/0,e=-1/0,s=1/0,i=-1/0;return this.canvas.forEachObject(r=>{r.getBounds().forEach(r=>{t=Math.min(t,r.x),e=Math.max(e,r.x),s=Math.min(s,r.y),i=Math.max(i,r.y)})}),[new Go(t,s),new Go(e,i)]}fitBounds(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;this.onResize();const{width:e,height:s}=this.canvas;this.originX=-this.canvas.width/2,this.originY=-this.canvas.height/2;const i=this.getBounds();this.center.x=(i[0].x+i[1].x)/2,this.center.y=-(i[0].y+i[1].y)/2;const r=e/(Math.abs(i[0].x-i[1].x)+t),n=s/(Math.abs(i[0].y-i[1].y)+t);this.zoom=Math.min(r,n),this.canvas.setZoom(this.zoom),this.canvas.absolutePan({x:this.originX+this.center.x*this.zoom,y:this.originY-this.center.y*this.zoom}),this.update(),setTimeout(()=>{this.update()},0)}setCursor(t){this.container.style.cursor=t}reset(){const{width:t,height:e}=this.canvas;this.zoom=this._options.zoom||1,this.center=new Go,this.originX=-this.canvas.width/2,this.originY=-this.canvas.height/2,this.canvas.absolutePan({x:this.originX,y:this.originY}),this.x=t/2,this.y=e/2,this.update(),setTimeout(()=>{this.update()},0)}onResize(t,e){const s=this.canvas.width,i=this.canvas.height;t=t||this.container.clientWidth,e=e||this.container.clientHeight,this.canvas.setWidth(t),this.canvas.setHeight(e),this.grid&&this.grid.setSize(t,e);const r=t/2-s/2,n=e/2-i/2;this.canvas.relativePan({x:r,y:n}),this.update()}update(){const t=this.canvas;this.grid&&this.grid.update2({x:this.center.x,y:this.center.y,zoom:this.zoom}),this.emit("update",this),this.grid&&this.grid.render(),this.isGrabMode()||this.isRight?(t.relativePan(new Go(this.dx,this.dy)),this.emit("panning"),this.setCursor("grab")):this.setCursor("pointer");const e=Date.now();if(!this.lastUpdatedTime&&Math.abs(this.lastUpdatedTime-e)<100)return;this.lastUpdatedTime=e;const s=t.getObjects();let i=!1;for(let t=0;t<s.length;t+=1){const e=s[t];e.keepOnZoom&&(e.set("scaleX",1/this.zoom),e.set("scaleY",1/this.zoom),e.setCoords(),i=!0,this.emit(`${e.class}scaling`,e))}i&&t.requestRenderAll()}panzoom(t){const{width:e,height:s}=this.canvas,i=ma(-t.dz,.75*-s,.75*s)/s,r=1/this.zoom;let n=r*(1-i);n=ma(n,this.minZoom,this.maxZoom);let{x:o,y:a}=this.center;if(this.isGrabMode()||t.isRight?(o-=r*t.dx,a+=r*t.dy,this.setCursor("grab")):this.setCursor("pointer"),this.zoomEnabled){let i,h;this.grid&&this.grid.zoomOverMouse?(i=t.x/e-.5,h=.5-t.y/s):(i=0,h=0),o-=e*(n-r)*i,a-=s*(n-r)*h}this.center.setX(o),this.center.setY(a),this.zoom=1/n,this.dx=t.dx,this.dy=t.dy,this.x=t.x0,this.y=t.y0,this.isRight=t.isRight,this.update()}setView(t){this.dx=0,this.dy=0,this.x=0,this.y=0,t.y*=-1;const e=this.center.x-t.x,s=-this.center.y+t.y;this.center.copy(t),this.canvas.relativePan(new Go(e*this.zoom,s*this.zoom)),this.canvas.renderAll(),this.update(),setTimeout(()=>{this.update()},0)}setOriginPin(t){this.originPin=t,this.grid&&this.grid.setOriginPin(t)}setPinMargin(t){this.pinMargin=t,this.grid&&this.grid.setPinMargin(t)}setZoomOverMouse(t){this.zoomOverMouse=t,this.grid&&this.grid.setZoomOverMouse(t)}registerListeners(){const t=this;this.canvas.on("object:scaling",e=>{if(e.target.class)return t.emit(`${e.target.class}:scaling`,e.target.parent),void e.target.parent.emit("scaling",e.target.parent);const s=e.target;if(!s.getObjects)return;const i=s.getObjects();s.removeWithUpdate();for(let e=0;e<i.length;e+=1){const s=i[e];s.orgYaw=s.parent.yaw||0,s.fire("moving",s.parent),t.emit(`${s.class}:moving`,s.parent)}t.update(),t.canvas.requestRenderAll()}),this.canvas.on("object:rotating",e=>{if(e.target.class)return t.emit(`${e.target.class}:rotating`,e.target.parent,e.target.angle),void e.target.parent.emit("rotating",e.target.parent,e.target.angle);const s=e.target;if(!s.getObjects)return;const i=s.getObjects();for(let e=0;e<i.length;e+=1){const r=i[e];"marker"===r.class&&(r._set("angle",-s.angle),r.parent.yaw=-s.angle+(r.orgYaw||0),r.fire("moving",r.parent),t.emit(`${r.class}:moving`,r.parent),r.fire("rotating",r.parent),t.emit(`${r.class}:rotating`,r.parent))}this.update()}),this.canvas.on("object:moving",e=>{if(e.target.class)return t.emit(`${e.target.class}:moving`,e.target.parent),void e.target.parent.emit("moving",e.target.parent);const s=e.target;if(!s.getObjects)return;const i=s.getObjects();for(let e=0;e<i.length;e+=1){const s=i[e];s.class&&(s.fire("moving",s.parent),t.emit(`${s.class}:moving`,s.parent))}this.update()}),this.canvas.on("object:moved",e=>{if(e.target.class)return t.emit(`${e.target.class}dragend`,e),t.emit(`${e.target.class}:moved`,e.target.parent),e.target.parent.emit("moved",e.target.parent),void this.update();const s=e.target;if(!s.getObjects)return;const i=s.getObjects();for(let e=0;e<i.length;e+=1){const s=i[e];s.class&&(s.fire("moved",s.parent),t.emit(`${s.class}:moved`,s.parent))}this.update()}),window.addEventListener("resize",()=>{t.onResize()})}unregisterListeners(){this.canvas.off("object:moving"),this.canvas.off("object:moved")}getMarkerById(t){const e=this.canvas.getObjects();for(let s=0;s<e.length;s+=1){const i=e[s];if("marker"===i.class&&i.id===t)return i.parent}return null}getMarkers(){const t=[],e=this.canvas.getObjects();for(let s=0;s<e.length;s+=1){const i=e[s];"marker"===i.class&&t.push(i.parent)}return t}};class Ia extends Ma{constructor(t){super(t),this.label=void 0!==this.label?this.label:null,this.draggable=this.draggable||!1,this.zIndex=this.zIndex||1,this.opacity=this.opacity||1,this.keepOnZoom=this.keepOnZoom||!1,this.clickable=this.clickable||!1,this.hoverCursor=this.hoverCursor||this.clickable?"pointer":"default",this.moveCursor=this.moveCursor||"move",this.style={zIndex:this.zIndex,class:this.class,parent:this,keepOnZoom:this.keepOnZoom,id:this.id,hasControls:!1,hasBorders:!1,lockMovementX:!this.draggable,lockMovementY:!this.draggable,draggable:this.draggable,clickable:this.clickable,evented:this.clickable,selectable:this.draggable,hoverCursor:this.hoverCursor,moveCursor:this.moveCursor}}setOptions(t){this.shape&&(Object.keys(t).forEach(e=>{this.shape.set(e,t[e])}),this.shape.canvas&&this.shape.canvas.renderAll())}addTo(t){t?(this._map=t,this._map.addLayer(this)):this._map&&this._map.removeLayer(this)}}class Wa extends wn{constructor(t,e){(e=e||{}).strokeWidth=e.strokeWidth||1,e.class="line",super(t,e),this._strokeWidth=e.strokeWidth}_renderStroke(t){const e=this._strokeWidth/this.canvas.getZoom();this.strokeWidth=e>.01?e:.01,super._renderStroke(t),this.setCoords()}}class Xa extends Ia{constructor(t,e,s){(s=s||{}).zIndex=s.zIndex||10,s.class="connector",super(s),t&&e?(this.start=t,this.end=e,this.strokeWidth=this.strokeWidth||1,Object.assign(this.style,{strokeWidth:this.strokeWidth,stroke:this.color||"grey",fill:this.fill||!1,selectable:!1}),this.draw(),this.registerListeners()):console.error("start or end is missing")}registerListeners(){const t=this;this.start.on("update:links",()=>{t.shape.set({x1:t.start.position.x,y1:t.start.position.y})}),this.end.on("update:links",()=>{t.shape.set({x2:t.end.position.x,y2:t.end.position.y})})}draw(){this.shape=new Wa([this.start.position.x,this.start.position.y,this.end.position.x,this.end.position.y],this.style)}redraw(){this.shape.set({x1:this.start.position.x,y1:this.start.position.y,x2:this.end.position.x,y2:this.end.position.y})}setStart(t){this.start=t,this.redraw()}setEnd(t){this.end=t,this.redraw()}setColor(t){this.color=t,this.style.stroke=t,this.shape.set("stroke",t),this.shape.canvas&&this.shape.canvas.renderAll()}setStrokeWidth(t){this.strokeWidth=t,this.style.strokeWidth=t,this.shape.set("strokeWidth",t),this.shape.canvas&&this.shape.canvas.renderAll()}}class Ya extends fr{constructor(t,e){super(t,e=e||{})}getBounds(){const t=[];return t.push(new Go(this.left-this.width/2,this.top-this.height/2)),t.push(new Go(this.left+this.width/2,this.top+this.height/2)),t}}class za extends yn{}class Va extends Ia{constructor(t,e){(e=e||{}).zIndex=e.zIndex||100,e.keepOnZoom=void 0===e.keepOnZoom||e.keepOnZoom,e.position=new Go(t),e.rotation=e.rotation||0,e.yaw=e.yaw||0,e.clickable=void 0===e.clickable||e.clickable,e.class="marker",super(e);const s=this;this.text=this.text||"",this.size=this.size||10,this.textColor=this.textColor||"black",this.fill=this.fill||"white",this.stroke=this.stroke||"red",Object.assign(this.style,{left:this.position.x,top:this.position.y,angle:this.rotation,yaw:this.yaw,clickable:this.clickable}),this.text&&(this.textObj=new fabric.Text(this.text,{fontSize:this.size,fill:this.textColor})),this.icon?fabric.Image.fromURL(this.icon.url,t=>{s.image=t.scaleToWidth(this.size),this.init()},{selectable:!1,evented:this.evented,clickable:this.clickable,opacity:this.opacity}):(this.circle=new za({radius:this.size,strokeWidth:2,stroke:this.stroke,fill:this.fill}),this.init())}init(){const t=[];this.image&&t.push(this.image),this.circle&&t.push(this.circle),this.textObj&&t.push(this.textObj),this.shape=new Ya(t,this.style),this.links=this.links||[],this.addLinks(),this.registerListeners(),process.nextTick(()=>{this.emit("ready")})}registerListeners(){const t=this;this.shape.on("moving",()=>{t.onShapeDrag()}),this.shape.on("rotating",()=>{t.emit("rotating")}),this.shape.on("mousedown",e=>{t.onShapeMouseDown(e)}),this.shape.on("mousemove",e=>{t.onShapeMouseMove(e)}),this.shape.on("mouseup",e=>{t.onShapeMouseUp(e)}),this.shape.on("mouseover",()=>{t.emit("mouseover",t)}),this.shape.on("mouseout",()=>{t.emit("mouseout",t)})}setPosition(t){this.position=new Go(t),this.shape&&(this.shape.set({left:this.position.x,top:this.position.y}),this.emit("update:links"),this.shape.canvas&&this.shape.canvas.renderAll())}setRotation(t){this.rotation=t,this.shape&&(this.shape.set({angle:this.rotation}),this.shape.canvas&&this.shape.canvas.renderAll())}setOptions(t){this.shape&&(Object.keys(t).forEach(e=>{switch(e){case"textColor":this.setTextColor(t[e]);break;case"stroke":this.setStroke(t[e]);break;case"fill":this.setColor(t[e])}}),this.shape.canvas&&this.shape.canvas.renderAll())}setTextColor(t){this.text&&this.textObj&&(this.textObj.setColor(t),this.textObj.canvas.renderAll())}setText(t){this.text&&this.textObj&&(this.textObj.set({text:t}),this.textObj.canvas.renderAll())}setStroke(t){this.circle&&this.circle.set("stroke",t)}setColor(t){this.circle&&this.circle.setColor(t)}setLinks(t){this.links=t,this.addLinks()}setSize(t){this.image?(this.image.scaleToWidth(t),this.image.canvas&&this.image.canvas.renderAll()):this.circle&&this.circle.setRadius(t)}addLinks(){this.connectors=[],this.links.forEach(t=>{const e=new Xa(this,t);this.connectors.push(e)}),this.addConnectors()}addConnectors(){const t=this;this.connectors.forEach(e=>{t._map.addLayer(e)})}onAdded(){this.addConnectors()}onShapeDrag(){const t=this.shape.calcTransformMatrix(),[,,,,e,s]=t;this.position=new Go(e,s),this.emit("update:links"),this.emit("moving")}onShapeMouseDown(t){this.dragStart=t}onShapeMouseMove(t){if(this.dragStart){this.emit("dragstart");const e=new fabric.Point(t.pointer.x,t.pointer.y),s=new fabric.Point(this.dragStart.pointer.x,this.dragStart.pointer.y);e.distanceFrom(s)>3&&(this.dragStart=null,this.dragging=!0)}this.dragging?this.emit("drag"):this.emit("hover")}onShapeMouseUp(){this.dragging?this.emit("moved"):this.emit("click"),this.dragStart=null,this.dragging=!1}}class Ga extends ho{constructor(t){super(t),this.defaults=Object.assign({},Ko),Object.assign({},this.defaults),Object.assign({},this._options)}}class Ha extends Ia{constructor(t,e){(e=e||{}).points=t||[],super(e),this.lines=[],this.class="polyline",this.strokeWidth=1,this.lineOptions={strokeWidth:this.strokeWidth,stroke:this.color||"grey",fill:this.fill||!1},this.shape=new Ya([],{selectable:!1,hasControls:!1,class:this.class,parent:this}),this.setPoints(this._points)}addPoint(t){if(this.points.push(new Go(t)),this.points.length>1){const t=this.points.length-1,e=this.points.length-2,s=this.points[t],i=this.points[e],r=new fabric.Line(s.getArray().concat(i.getArray()),this.lineOptions);this.lines.push(r),this.shape.addWithUpdate(r)}}setStrokeWidth(t){this.lines.forEach(e=>{e.setStrokeWidth(t)})}setPoints(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.removeLines(),this.points=[];for(let e=0;e<t.length;e+=1){const s=new Go(t[e]);this.points.push(s),this.addPoint()}}removeLines(){for(let t=0;t<this.lines.length;t+=1)this.shape.remove(this.lines[t]);this.lines=[]}}class Na extends tr{constructor(t,e){(e=e||{}).strokeWidth=e.strokeWidth||1,e.class="rect",super(t,e),this._strokeWidth=e.strokeWidth}_renderStroke(t){this.strokeWidth=this._strokeWidth/this.canvas.getZoom(),super._renderStroke(t)}}class Ua extends Cn{constructor(t,e){(e=e||{}).headLength=e.headLength||10,e.stroke=e.stroke||"#207cca";const[s,i,r,n]=t,o=r-s,a=n-i;let h=Math.atan2(a,o);h*=180/Math.PI,h+=90,void 0!==e.lastAngle&&(h=e.lastAngle,console.log(`Angle: ${h}`)),super({angle:h,fill:e.stroke,top:n,left:r,height:e.headLength,width:e.headLength,originX:"center",originY:"center",selectable:!1})}}class qa extends fr{constructor(t,e){(e=e||{}).strokeWidth=e.strokeWidth||5,e.stroke=e.stroke||"#7db9e8",e.class="arrow",super([],Object.assign(e,{evented:!1})),this.pointArray=[t,Object.assign({},t)],this.options=e,this.draw()}draw(){this.head&&this.remove(this.head),this.polyline&&this.remove(this.polyline),this.polyline=new fabric.Polyline(this.pointArray,Object.assign(this.options,{strokeLineJoin:"round",fill:!1})),this.addWithUpdate(this.polyline);const t=this.getLastPoints(),e=new fabric.Point(t[0],t[1]),s=new fabric.Point(t[2],t[3]),i=e.distanceFrom(s);console.log(`dis = ${i}`),this.head=new Ua(t,Object.assign(this.options,{headLength:2*this.strokeWidth,lastAngle:i<=10?this.lastAngle:void 0})),i>10&&(this.lastAngle=this.head.angle),this.addWithUpdate(this.head)}addPoint(t){this.pointArray.push(t),this.draw()}addTempPoint(t){const e=this.pointArray.length,s=this.pointArray[e-1];s.x=t.x,s.y=t.y,this.draw()}getLastPoints(){const t=this.pointArray.length,e=this.pointArray[t-2],s=this.pointArray[t-1];return[e.x,e.y,s.x,s.y]}setColor(t){this._objects.forEach(e=>{e.setColor(t)})}}const Ka="select",Za="drawing",Qa="arrow",Ja="text";"undefined"!=typeof window&&console.log("fabric-layers-core ",e);const $a={version:e,Map:Ba,Marker:Va,OriginPin:No};if("undefined"!=typeof window){const t=window.FabricLayers;window.FabricLayers=$a,window.FabricLayers.noConflict=function(){return window.FabricLayers=t,this}}t.Axis=Aa,t.Connector=Xa,t.FabricLayersCircle=za,t.FabricLayersGroup=Ya,t.FabricLayersLine=Wa,t.FabricLayersPaintingCanvas=class extends Ma{constructor(t,e){super(e),this.container=t;const s=document.createElement("canvas");this.container.appendChild(s),s.setAttribute("id","fabric-layers-paint-canvas"),s.width=this.width||this.container.clientWidth,s.height=this.height||this.container.clientHeight,this.currentColor=this.currentColor||"black",this.fontFamily=this.fontFamily||"Roboto",this.canvas=new qr(s,{freeDrawingCursor:"none",freeDrawingLineWidth:this.lineWidth}),this.arrows=[],this.setLineWidth(this.lineWidth||10),this.addCursor(),this.addListeners(),this.setModeAsArrow()}setModeAsDrawing(){this.mode=Za,this.canvas.isDrawingMode=!0,this.canvas.selection=!1,this.onModeChanged()}isDrawingMode(){return this.mode===Za}setModeAsSelect(){this.mode=Ka,this.canvas.isDrawingMode=!1,this.canvas.selection=!0,this.onModeChanged()}isSelectMode(){return this.mode===Ka}setModeAsArrow(){this.mode=Qa,this.canvas.isDrawingMode=!1,this.canvas.selection=!1,this.onModeChanged()}isArrowMode(){return this.mode===Qa}setModeAsText(){this.mode=Ja,this.canvas.isDrawingMode=!1,this.canvas.selection=!1,this.onModeChanged()}isTextMode(){return this.mode===Ja}onModeChanged(){this.updateCursor(),this.emit("mode-changed",this.mode),this.canvas._objects.forEach(t=>{t.evented=this.isSelectMode()})}addListeners(){const t=this.canvas;t.on("mouse:move",e=>{const s=t.getPointer(e.e);this.mousecursor&&this.mousecursor.set({top:s.y,left:s.x}).setCoords().canvas.renderAll(),this.isTextMode()?console.log("text"):this.isArrowMode()&&(this.activeArrow&&this.activeArrow.addTempPoint(s),this.canvas.requestRenderAll())}),t.on("mouse:out",()=>{this.mousecursor&&(this.mousecursor.set({left:-1e3,top:-1e3}).setCoords(),this.cursor.renderAll())}),t.on("mouse:up",e=>{t.mouseDown&&t.fire("mouse:click",e),t.mouseDown=!1}),t.on("mouse:move",e=>{t.mouseDown=!1}),t.on("mouse:down",e=>{t.mouseDown=!0}),t.on("mouse:click",e=>{console.log("mouse click",e);const s=t.getPointer(e.e);if(!e.target)if(this.isTextMode()){const e=new Zn("Text",{left:s.x,top:s.y,width:100,fontSize:20,fontFamily:this.fontFamily,lockUniScaling:!0,fill:this.currentColor,stroke:this.currentColor});t.add(e).setActiveObject(e).renderAll(),this.setModeAsSelect()}else this.isArrowMode()&&(console.log("arrow mode"),this.activeArrow?this.activeArrow.addPoint(s):(this.activeArrow=new qa(s,{stroke:this.currentColor,strokeWidth:this.lineWidth}),this.canvas.add(this.activeArrow)),this.canvas.requestRenderAll())}),t.on("mouse:dblclick",t=>{console.log("mouse:dbclick"),this.isArrowMode()&&this.activeArrow&&(this.arrows.push(this.activeArrow),this.activeArrow=null)}),t.on("selection:created",t=>{this.emit("selected")}),t.on("selection:cleared",t=>{this.emit("unselected")})}removeSelected(){this.canvas.remove(this.canvas.getActiveObject()),this.canvas.getActiveObjects().forEach(t=>{this.canvas.remove(t)}),this.canvas.discardActiveObject().renderAll()}updateCursor(){if(!this.cursor)return;const t=this.canvas;this.mousecursor&&(this.cursor.remove(this.mousecursor),this.mousecursor=null);let e=null;e=this.isDrawingMode()?new yn({left:-1e3,top:-1e3,radius:t.freeDrawingBrushWidth/2,fill:"rgba(255,0,0,0.3)",stroke:"black",originX:"center",originY:"center"}):this.isTextMode()?new pn("M0,-10 V10",{left:-1e3,top:-1e3,radius:t.freeDrawingBrushWidth/2,fill:"rgba(255,0,0,0.3)",stroke:"rgba(0,0,0,0.3)",originX:"center",originY:"center",scaleX:1,scaleY:1}):new pn("M0,-10 V10 M-10,0 H10",{left:-1e3,top:-1e3,radius:t.freeDrawingBrushWidth/2,fill:"rgba(255,0,0,0.3)",stroke:"rgba(0,0,0,0.3)",originX:"center",originY:"center"}),this.isSelectMode()?(e=null,this.canvas.defaultCursor="default"):this.canvas.defaultCursor="none",e&&this.cursor.add(e),this.mousecursor=e}addCursor(){const t=this.canvas,e=document.createElement("canvas");this.canvas.wrapperEl.appendChild(e),e.setAttribute("id","fabric-layers-cursor-canvas"),e.style.position="absolute",e.style.top="0",e.style.pointerEvents="none",e.width=this.width||this.container.clientWidth,e.height=this.height||this.container.clientHeight,this.cursorCanvas=e,t.defaultCursor="none",this.cursor=new te(e),this.updateCursor()}setColor(t){this.currentColor=t,this.canvas.freeDrawingBrush.color=t;const e=this.canvas.getActiveObject();e&&(e.set("stroke",t),e.set("fill",t),this.canvas.requestRenderAll()),this.mousecursor&&this.mousecursor.set({left:100,top:100,fill:t}).setCoords().canvas.renderAll()}setLineWidth(t){this.lineWidth=t,this.canvas.freeDrawingBrushWidth=t,this.mousecursor&&this.mousecursor.set({left:100,top:100,radius:t/2}).setCoords().canvas.renderAll()}setFontFamily(t){this.fontFamily=t;const e=this.canvas.getActiveObject();e&&"i-text"===e.type&&(e.set("fontFamily",t),this.canvas.requestRenderAll())}clear(){this.arrows=[],this.canvas.clear()}},t.FabricLayersPoint=Go,t.FabricLayersRect=Na,t.Grid=ja,t.ICON=Ko,t.Icon=Ga,t.Layer=Ia,t.MAP=Uo,t.MARKER=qo,t.Map=Ba,t.Marker=Va,t.MarkerGroup=class extends Ia{constructor(t,e){(e=e||{}).bounds=t,e.zIndex=e.zIndex||50,e.class="markergroup",super(e),this.bounds?(this.style={strokeWidth:1,stroke:this.stroke||"black",fill:this.color||"#88888822",class:this.class,zIndex:this.zIndex,parent:this},this.draw()):console.error("bounds is missing!")}setBounds(t){this.bounds=t,this.draw()}draw(){const t=this.bounds[1][0]-this.bounds[0][0],e=this.bounds[1][1]-this.bounds[0][1];this.coords={left:this.bounds[0][0]+t/2,top:this.bounds[0][1]+e/2,width:t,height:e},this.shape?this.shape.set(this.coords):(Object.assign(this.style,this.coords),this.shape=new Na(this.style))}},t.Modes=Ho,t.OriginPin=No,t.Polyline=Ha,t.default=$a,t.gridStyle=Ea,t.icon=t=>new Ga(t),t.polyline=(t,e)=>new Ha(t,e),t.version=e,Object.defineProperty(t,"__esModule",{value:!0})});