UNPKG

fabric-warpvas

Version:

This JavaScript library helps you efficiently build image warping tools on Fabric.js

3 lines 96.1 kB
function t(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 r=s.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(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 e(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,r)}return s}function s(s){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?e(Object(i),!0).forEach((function(e){t(s,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(t){Object.defineProperty(s,t,Object.getOwnPropertyDescriptor(i,t))}))}return s}function r(t,e){if(null==t)return{};var s,r,i=function(t,e){if(null==t)return{};var s={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)>=0)continue;s[r]=t[r]}return s}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(r=0;r<n.length;r++)s=n[r],e.indexOf(s)>=0||{}.propertyIsEnumerable.call(t,s)&&(i[s]=t[s])}return i}function i(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}let n=class{constructor(){t(this,"browserShadowBlurConstant",1),t(this,"DPI",96),t(this,"devicePixelRatio","undefined"!=typeof window?window.devicePixelRatio:1),t(this,"perfLimitSizeTotal",2097152),t(this,"maxCacheSideLimit",4096),t(this,"minCacheSideLimit",256),t(this,"disableStyleCopyPaste",!1),t(this,"enableGLFiltering",!0),t(this,"textureSize",4096),t(this,"forceGLPutImageData",!1),t(this,"cachesBoundsOfCurve",!1),t(this,"fontPaths",{}),t(this,"NUM_FRACTION_DIGITS",4)}};const o=new class extends n{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=s(s({},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 n,s=(null==t?void 0:t.reduce(((t,s)=>(t[s]=e[s],t)),{}))||e;this.configure(s)}},a=function(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),r=1;r<e;r++)s[r-1]=arguments[r];return console[t]("fabric",...s)};let c=class extends Error{constructor(t,e){super("fabric: ".concat(t),e)}},h=class{},l=class extends h{testPrecision(t,e){const s="precision ".concat(e," float;\nvoid main(){}"),r=t.createShader(t.FRAGMENT_SHADER);return!!r&&(t.shaderSource(r,s),t.compileShader(r),!!t.getShaderParameter(r,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(),a("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}};const u={};let d;const g=()=>d||(d={document:document,window:window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new l,dispose(){},copyPasteData:u}),f=()=>g().document,p=()=>g().window,m=()=>{var t;return Math.max(null!==(t=o.devicePixelRatio)&&void 0!==t?t:p().devicePixelRatio,1)};const y=new class{constructor(){t(this,"charWidthsCache",{}),t(this,"boundsOfCurveCache",{})}getFontCache(t){let{fontFamily:e,fontStyle:s,fontWeight:r}=t;e=e.toLowerCase(),this.charWidthsCache[e]||(this.charWidthsCache[e]={});const i=this.charWidthsCache[e],n="".concat(s.toLowerCase(),"_").concat((r+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(t){(t=(t||"").toLowerCase())?this.charWidthsCache[t]&&delete this.charWidthsCache[t]:this.charWidthsCache={}}limitDimsByArea(t){const{perfLimitSizeTotal:e}=o,s=Math.sqrt(e*t);return[Math.floor(s),Math.floor(e/s)]}};const v="6.6.5";function w(){}const b=Math.PI/2,C=2*Math.PI,x=Math.PI/180,k=Object.freeze([1,0,0,1,0,0]),S=.4477152502,_="center",O="left",F="top",P="right",j="none",A="scaling",D="rotate",T="scale",M="scaleX",X="scaleY",Y="skewX",E="skewY",R="fill",V="stroke",B="json",L="svg";const I=new class{constructor(){this[B]=new Map,this[L]=new Map}has(t){return this[B].has(t)}getClass(t){const e=this[B].get(t);if(!e)throw new c("No class registered for ".concat(t));return e}setClass(t,e){e?this[B].set(e,t):(this[B].set(t.type,t),this[B].set(t.type.toLowerCase(),t))}getSVGClass(t){return this[L].get(t)}setSVGClass(t,e){this[L].set(null!=e?e:t.type.toLowerCase(),t)}},z=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}};let G=class{constructor(){t(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,r]=t;e.push(this.once(s,r))})),()=>e.forEach((t=>t()))}if(e){const s=this.on(t,(function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];e.call(this,...r),s()}));return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],r=s.indexOf(e);r>-1&&s.splice(r,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 r=null===(s=this.__eventListeners[t])||void 0===s?void 0:s.concat();if(r)for(let t=0;t<r.length;t++)r[t].call(this,e||{})}};const N=(t,e)=>{const s=t.indexOf(e);return-1!==s&&t.splice(s,1),t},W=t=>{if(0===t)return 1;switch(Math.abs(t)/b){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},H=t=>{if(0===t)return 0;const e=t/b,s=Math.sign(t);switch(e){case 1:return s;case 2:return 0;case 3:return-s}return Math.sin(t)};let q=class t{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(e){return new t(this.x+e.x,this.y+e.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(e){return new t(this.x+e,this.y+e)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(e){return new t(this.x-e.x,this.y-e.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(e){return new t(this.x-e,this.y-e)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(e){return new t(this.x*e.x,this.y*e.y)}scalarMultiply(e){return new t(this.x*e,this.y*e)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(e){return new t(this.x/e.x,this.y/e.y)}scalarDivide(e){return new t(this.x/e,this.y/e)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;return s=Math.max(Math.min(1,s),0),new t(this.x+(e.x-this.x)*s,this.y+(e.y-this.y)*s)}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(e){return new t(Math.min(this.x,e.x),Math.min(this.y,e.y))}max(e){return new t(Math.max(this.x,e.x),Math.max(this.y,e.y))}toString(){return"".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 t(this.x,this.y)}rotate(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U;const r=H(e),i=W(e),n=this.subtract(s);return new t(n.x*i-n.y*r,n.x*r+n.y*i).add(s)}transform(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new t(e[0]*this.x+e[2]*this.y+(s?0:e[4]),e[1]*this.x+e[3]*this.y+(s?0:e[5]))}};const U=new q(0,0);let J=class extends G{_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 $(t){return p().requestAnimationFrame(t)}let Z=0;const K=()=>Z++,Q=()=>{const t=f().createElement("canvas");if(!t||void 0===t.getContext)throw new c("Failed to create `canvas` element");return t},tt=t=>{const e=Q();return e.width=t.width,e.height=t.height,e},et=(t,e,s)=>t.toDataURL("image/".concat(e),s),st=(t,e,s)=>new Promise(((r,i)=>{t.toBlob(r,"image/".concat(e),s)})),rt=t=>t*x,it=t=>t/x,nt=(t,e,s)=>new q(t).transform(e,s),ot=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:r,y:i}=new q(t[4],t[5]).transform(s,!0);return s[4]=-r,s[5]=-i,s},at=(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]],ct=(t,e)=>t.reduceRight(((t,s)=>s&&t?at(s,t,e):s||t),void 0)||k.concat(),ht=t=>{let[e,s]=t;return Math.atan2(s,e)},lt=t=>{const e=ht(t),s=Math.pow(t[0],2)+Math.pow(t[1],2),r=Math.sqrt(s),i=(t[0]*t[3]-t[2]*t[1])/r,n=Math.atan2(t[0]*t[2]+t[1]*t[3],s);return{angle:it(e),scaleX:r,scaleY:i,skewX:it(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},ut=function(t){return[1,0,0,1,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0]};function dt(){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 r=rt(t),i=W(r),n=H(r);return[i,n,-n,i,e?e-(i*e-n*s):0,s?s-(n*e+i*s):0]}const gt=function(t){return[t,0,0,arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,0,0]},ft=t=>Math.tan(rt(t)),pt=t=>[1,0,ft(t),1,0,0],mt=t=>[1,ft(t),0,1,0,0],yt=t=>{let{scaleX:e=1,scaleY:s=1,flipX:r=!1,flipY:i=!1,skewX:n=0,skewY:o=0}=t,a=gt(r?-e:e,i?-s:s);return n&&(a=at(a,pt(n),!0)),o&&(a=at(a,mt(o),!0)),a},vt=t=>{const{translateX:e=0,translateY:s=0,angle:r=0}=t;let i=ut(e,s);r&&(i=at(i,dt({angle:r})));const n=yt(t);return(t=>t.every(((t,e)=>t===k[e])))(n)||(i=at(i,n)),i},wt=function(t){let{signal:e,reviver:s=w}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((r,i)=>{const n=[];e&&e.addEventListener("abort",i,{once:!0}),Promise.all(t.map((t=>I.getClass(t.type).fromObject(t,{signal:e}).then((e=>(s(t,e),n.push(e),e)))))).then(r).catch((t=>{n.forEach((t=>{t.dispose&&t.dispose()})),i(t)})).finally((()=>{e&&e.removeEventListener("abort",i)}))}))},bt=function(t){let{signal:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((s,r)=>{const i=[];e&&e.addEventListener("abort",r,{once:!0});const n=Object.values(t).map((t=>t&&t.type&&I.has(t.type)?wt([t],{signal:e}).then((t=>{let[e]=t;return i.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=>{i.forEach((t=>{t.dispose&&t.dispose()})),r(t)})).finally((()=>{e&&e.removeEventListener("abort",r)}))}))},Ct=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce(((e,s)=>(s in t&&(e[s]=t[s]),e)),{})},xt=(t,e)=>Object.keys(t).reduce(((s,r)=>(e(t[r],r,t)&&(s[r]=t[r]),s)),{}),kt=(t,e)=>parseFloat(Number(t).toFixed(e)),St=t=>"matrix("+t.map((t=>kt(t,o.NUM_FRACTION_DIGITS))).join(" ")+")",_t=t=>!!t&&void 0!==t.toLive,Ot=t=>!!t&&"function"==typeof t.toObject,Ft=t=>!!t&&void 0!==t.offsetX&&"source"in t;const Pt=t=>t.ownerDocument||null;function jt(t){var e;const s=t&&Pt(t),r={left:0,top:0};if(!s)return r;const i=(null===(e=(t=>{var e;return(null===(e=t.ownerDocument)||void 0===e?void 0:e.defaultView)||null})(t))||void 0===e?void 0:e.getComputedStyle(t,null))||{};r.left+=parseInt(i.borderLeftWidth,10)||0,r.top+=parseInt(i.borderTopWidth,10)||0,r.left+=parseInt(i.paddingLeft,10)||0,r.top+=parseInt(i.paddingTop,10)||0;let n={left:0,top:0};const o=s.documentElement;void 0!==t.getBoundingClientRect&&(n=t.getBoundingClientRect());const a=function(t){const e=t&&Pt(t);let s=0,r=0;if(!t||!e)return{left:s,top:r};let i=t;const n=e.documentElement,o=e.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===e?(s=o.scrollLeft||n.scrollLeft||0,r=o.scrollTop||n.scrollTop||0):(s+=i.scrollLeft||0,r+=i.scrollTop||0),1!==i.nodeType||"fixed"!==i.style.position););return{left:s,top:r}}(t);return{left:n.left+a.left-(o.clientLeft||0)+r.left,top:n.top+a.top-(o.clientTop||0)+r.top}}let At=class{constructor(e){t(this,"_originalCanvasStyle",void 0),t(this,"lower",void 0);const s=this.createLowerCanvas(e);this.lower={el:s,ctx:s.getContext("2d")}}createLowerCanvas(t){const e=(t=>!!t&&void 0!==t.getContext)(t)?t:t&&f().getElementById(t)||Q();if(e.hasAttribute("data-fabric"))throw new c("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:r}=this.lower;r.classList.remove("lower-canvas"),r.removeAttribute("data-fabric"),r.setAttribute("width","".concat(e)),r.setAttribute("height","".concat(s)),r.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:r}=this.lower;!function(t,e,s){let{width:r,height:i}=s,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;t.width=r,t.height=i,n>1&&(t.setAttribute("width",(r*n).toString()),t.setAttribute("height",(i*n).toString()),e.scale(n,n))}(s,r,t,e)}setCSSDimensions(t){((t,e)=>{let{width:s,height:r}=e;s&&(t.style.width="number"==typeof s?"".concat(s,"px"):s),r&&(t.style.height="number"==typeof r?"".concat(r,"px"):r)})(this.lower.el,t)}calcOffset(){return jt(this.lower.el)}dispose(){g().dispose(this.lower.el),delete this.lower}};const Dt={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...k]};class Tt extends(function(e){class s extends e{constructor(){super(...arguments),t(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 r=this._objects.push(...e);return e.forEach((t=>this._onObjectAdded(t))),r}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),r=1;r<e;r++)s[r-1]=arguments[r];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,r=new Array(s),i=0;i<s;i++)r[i]=arguments[i];return r.forEach((s=>{const r=t.indexOf(s);-1!==r&&(t.splice(r,1),e.push(s),this._onObjectRemoved(s))})),e}forEachObject(t){this.getObjects().forEach(((e,s,r)=>t(e,s,r)))}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,e){return!!this._objects.includes(t)||!!e&&this._objects.some((e=>e instanceof s&&e.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]||(N(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),0))}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1]||(N(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 r=this.findNewLowerIndex(t,s,e);return N(this._objects,t),this._objects.splice(r,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 r=this.findNewUpperIndex(t,s,e);return N(this._objects,t),this._objects.splice(r,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(N(this._objects,t),this._objects.splice(e,0,t),this._onStackOrderChanged(t),!0)}findNewLowerIndex(t,e,s){let r;if(s){r=e;for(let s=e-1;s>=0;--s)if(t.isOverlapping(this._objects[s])){r=s;break}}else r=e-1;return r}findNewUpperIndex(t,e,s){let r;if(s){r=e;for(let s=e+1;s<this._objects.length;++s)if(t.isOverlapping(this._objects[s])){r=s;break}}else r=e+1;return r}collectObjects(t){let{left:e,top:s,width:r,height:i}=t,{includeIntersecting:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[],a=new q(e,s),c=a.add(new q(r,i));for(let t=this._objects.length-1;t>=0;t--){const e=this._objects[t];e.selectable&&e.visible&&(n&&e.intersectsWithRect(a,c)||e.isContainedWithinRect(a,c)||n&&e.containsPoint(a)||n&&e.containsPoint(c))&&o.push(e)}return o}}return s}(J)){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 Tt.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 At(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),r=1;r<e;r++)s[r-1]=arguments[r];const i=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),i}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(a("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?m():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:r=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e){const e=s({width:this.width,height:this.height},t);this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}r||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,r=[...this.viewportTransform],i=nt(t,ot(r));r[0]=e,r[3]=e;const n=nt(i,r);r[4]+=s.x-n.x,r[5]+=s.y-n.y,this.setViewportTransform(r)}setZoom(t){this.zoomToPoint(new q(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 q(-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=$((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,s=ot(this.viewportTransform),r=nt({x:0,y:0},s),i=nt({x:t,y:e},s),n=r.min(i),o=r.max(i);return this.vptCoords={tl:n,tr:new q(o.x,n.y),bl:new q(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(function(t){p().cancelAnimationFrame(t)}(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,r=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),r&&(r._set("canvas",this),r.shouldCache(),r._transformDone=!0,r.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,r)),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,r=e.length;s<r;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],r=this["".concat(e,"Image")],i=this.viewportTransform,n=this["".concat(e,"Vpt")];if(!s&&!r)return;const o=_t(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(...i),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(r){t.save();const{skipOffscreen:e}=this;this.skipOffscreen=n,n&&t.transform(...i),r.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 q(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new q(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new q(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 q(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new q(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return nt(this.getCenterPoint(),ot(this.viewportTransform))}_centerObject(t,e){t.setXY(e,_,_),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 r=this.clipPath,i=r&&!r.excludeFromExport?this._toObject(r,t,e):null;return s(s(s({version:v},Ct(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 r;this.includeDefaultValues||(r=t.includeDefaultValues,t.includeDefaultValues=!1);const i=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!r),i}__serializeBgOverlay(t,e){const s={},r=this.backgroundImage,i=this.overlayImage,n=this.backgroundColor,o=this.overlayColor;return _t(n)?n.excludeFromExport||(s.background=n.toObject(e)):n&&(s.background=n),_t(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),r&&!r.excludeFromExport&&(s.backgroundImage=this._toObject(r,t,e)),i&&!i.excludeFromExport&&(s.overlayImage=this._toObject(i,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),r=e.height||"".concat(this.height),i=o.NUM_FRACTION_DIGITS,n=e.viewBox;let a;if(n)a='viewBox="'.concat(n.x," ").concat(n.y," ").concat(n.width," ").concat(n.height,'" ');else if(this.svgViewportTransformation){const t=this.viewportTransform;a='viewBox="'.concat(kt(-t[4]/t[0],i)," ").concat(kt(-t[5]/t[3],i)," ").concat(kt(this.width/t[0],i)," ").concat(kt(this.height/t[3],i),'" ')}else a='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="',r,'" ',a,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",v,"</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(K()),'<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(_t(e)){const s=this["".concat(t,"Vpt")],r=this.viewportTransform,i={isType:()=>!1,width:this.width/(s?r[0]:1),height:this.height/(s?r[3]:1)};return e.toSVG(i,{additionalTransform:s?St(r):""})}})).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=o.fontPaths;this._objects.forEach((function e(s){t.push(s),(t=>!!t&&Array.isArray(t._objects))(s)&&s._objects.forEach(e)})),t.forEach((t=>{if(!(t=>!!t&&"function"==typeof t._renderText)(t))return;const{styles:r,fontFamily:i}=t;!e[i]&&s[i]&&(e[i]=!0,r&&Object.values(r).forEach((t=>{Object.values(t).forEach((t=>{let{fontFamily:r=""}=t;!e[r]&&s[r]&&(e[r]=!0)}))})))}));const r=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 r?'\t<style type="text/css"><![CDATA[\n'.concat(r,"]]></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 r=this[e];r&&!r.excludeFromExport&&r.toSVG&&t.push(r.toSVG(s))}_setSVGBgOverlayColor(t,e){const s=this["".concat(e,"Color")];if(s)if(_t(s)){const r=s.repeat||"",i=this.width,n=this.height,o=this["".concat(e,"Vpt")]?St(ot(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(i/2,",").concat(n/2,')" x="').concat(s.offsetX-i/2,'" y="').concat(s.offsetY-n/2,'" width="').concat("repeat-y"!==r&&"no-repeat"!==r||!Ft(s)?i:s.source.width,'" height="').concat("repeat-x"!==r&&"no-repeat"!==r||!Ft(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 c("`json` is undefined"));const r="string"==typeof t?JSON.parse(t):t,{objects:i=[],backgroundImage:n,background:o,overlayImage:a,overlay:h,clipPath:l}=r,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([wt(i,{reviver:e,signal:s}),bt({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:h,clipPath:l},{signal:s})]).then((t=>{let[e,s]=t;return this.clear(),this.add(...e),this.set(r),this.set(s),this.renderOnAddRemove=u,this}))}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=tt(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:r=1,enableRetinaScaling:i=!1}=t,n=r*(i?this.getRetinaScaling():1);return et(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:r=1,enableRetinaScaling:i=!1}=t,n=r*(i?this.getRetinaScaling():1);return st(this.toCanvasElement(n,t),e,s)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,{width:e,height:s,left:r,top:i,filter:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=(e||this.width)*t,a=(s||this.height)*t,c=this.getZoom(),h=this.width,l=this.height,u=this.skipControlsDrawing,d=c*t,g=this.viewportTransform,f=[d,0,0,d,(g[4]-(r||0))*t,(g[5]-(i||0))*t],p=this.enableRetinaScaling,m=tt({width:o,height:a}),y=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"),y),this.viewportTransform=g,this.width=h,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}),z.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," }>")}}t(Tt,"ownDefaults",Dt);const Mt=t=>{let e=0,s=0,r=0,i=0;for(let n=0,o=t.length;n<o;n++){const{x:o,y:a}=t[n];(o>r||!n)&&(r=o),(o<e||!n)&&(e=o),(a>i||!n)&&(i=a),(a<s||!n)&&(s=a)}return{left:e,top:s,width:r-e,height:i-s}},Xt=["translateX","translateY","scaleX","scaleY"],Yt=(t,e,s)=>{const r=t/2,i=e/2,n=[new q(-r,-i),new q(r,-i),new q(-r,i),new q(r,i)].map((t=>t.transform(s))),o=Mt(n);return new q(o.width,o.height)},Et=(t,e,s)=>{const i=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:k;return at(ot(arguments.length>1&&void 0!==arguments[1]?arguments[1]:k),t)}(e,s);return((t,e)=>{const s=lt(e),{translateX:i,translateY:n,scaleX:o,scaleY:a}=s,c=r(s,Xt),h=new q(i,n);t.flipX=!1,t.flipY=!1,Object.assign(t,c),t.set({scaleX:o,scaleY:a}),t.setPositionByOrigin(h,_,_)})(t,at(i,t.calcOwnMatrix())),i},Rt={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Vt=t=>"string"==typeof t?Rt[t]:t-.5,Bt="not-allowed";function Lt(t){return.5-Vt(t)}const It=(t,e)=>t[e];function zt(t,e){const s=t.getTotalAngle()+it(Math.atan2(e.y,e.x))+360;return Math.round(s%360/45)}function Gt(t,e,s,r,i){var n;let{target:o,corner:a}=t;const c=o.controls[a],h=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/h,u=function(t,e,s,r){const i=t.getRelativeCenterPoint(),n=void 0!==s&&void 0!==r?t.translateToGivenOrigin(i,_,_,s,r):new q(t.left,t.top);return(t.angle?e.rotate(-rt(t.angle),i):e).subtract(n)}(o,new q(r,i),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-=c.offsetX,u.y-=c.offsetY,u}const Nt={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"},Wt=(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),Ht=(t,e,s,r)=>{t/=255,e/=255,s/=255;const i=Math.max(t,e,s),n=Math.min(t,e,s);let o,a;const c=(i+n)/2;if(i===n)o=a=0;else{const r=i-n;switch(a=c>.5?r/(2-i-n):r/(i+n),i){case t:o=(e-s)/r+(e<s?6:0);break;case e:o=(s-t)/r+2;break;case s:o=(t-e)/r+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*c),r]},qt=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"1";return parseFloat(t)/(t.endsWith("%")?100:1)},Ut=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),Jt=t=>{let[e,s,r,i=1]=t;const n=Math.round(.3*e+.59*s+.11*r);return[n,n,n,i]};let $t=class e{constructor(s){if(t(this,"isUnrecognised",!1),s)if(s instanceof e)this.setSource([...s._source]);else if(Array.isArray(s)){const[t,e,r,i=1]=s;this.setSource([t,e,r,i])}else this.setSource(this._tryParsingColor(s));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in Nt&&(t=Nt[t]),"transparent"===t?[255,255,255,0]:e.sourceFromHex(t)||e.sourceFromRgb(t)||e.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]=Ht(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,r]=Ht(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(r,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,r]=this.getSource();return"".concat(Ut(t)).concat(Ut(e)).concat(Ut(s)).concat(Ut(Math.round(255*r)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Jt(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Jt(this.getSource()),r=e<(t||127)?0:255;return this.setSource([r,r,r,s]),this}overlayWith(t){t instanceof e||(t=new e(t));const s=this.getSource(),r=t.getSource(),[i,n,o]=s.map(((t,e)=>Math.round(.5*t+.5*r[e])));return this.setSource([i,n,o,s[3]]),this}static fromRgb(t){return e.fromRgba(t)}static fromRgba(t){return new e(e.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,r]=e.slice(1,4).map((t=>{const e=parseFloat(t);return t.endsWith("%")?Math.round(2.55*e):e}));return[t,s,r,qt(e[4])]}}static fromHsl(t){return e.fromHsla(t)}static fromHsla(t){return new e(e.sourceFromHsl(t))}static sourceFromHsl(t){const s=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(!s)return;const r=(e.parseAngletoDegrees(s[1])%360+360)%360/360,i=parseFloat(s[2])/100,n=parseFloat(s[3])/100;let o,a,c;if(0===i)o=a=c=n;else{const t=n<=.5?n*(i+1):n+i-n*i,e=2*n-t;o=Wt(e,t,r+1/3),a=Wt(e,t,r),c=Wt(e,t,r-1/3)}return[Math.round(255*o),Math.round(255*a),Math.round(255*c),qt(s[4])]}static fromHex(t){return new e(e.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[r,i,n,o=255]=s.map((t=>parseInt(t,16)));return[r,i,n,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?it(s):e.includes("turn")?360*s:s}};const Zt=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:16;const s=/\D{0,2}$/.exec(t),r=parseFloat(t),i=o.DPI;switch(null==s?void 0:s[0]){case"mm":return r*i/25.4;case"cm":return r*i/2.54;case"in":return r*i;case"pt":return r*i/72;case"pc":return r*i/72*12;case"em":return r*e;default:return r}},Kt=function(t,e){let s,r,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(e)if(e.toLive)s="url(#SVGID_".concat(e.id,")");else{const t=new $t(e),i=t.getAlpha();s=t.toRgb(),1!==i&&(r=i.toString())}else s="none";return i?"".concat(t,": ").concat(s,"; ").concat(r?"".concat(t,"-opacity: ").concat(r,"; "):""):"".concat(t,'="').concat(s,'" ').concat(r?"".concat(t,'-opacity="').concat(r,'" '):"")};function Qt(t){return new RegExp("^("+t.join("|")+")\\b","i")}var te;const ee=String.raw(te||(te=i(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),se=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+ee+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+ee+"))?\\s+(.*)"),re={cx:O,x:O,r:"radius",cy:F,y:F,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"},ie="font-size",ne="clip-path";Qt(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Qt(["symbol","image","marker","pattern","view","svg"]);const oe=Qt(["symbol","g","a","svg","clipPath","defs"]);new q(1,0),new q;const ae=(t,e)=>new q(e).subtract(t),ce="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",he=new RegExp("(?:\\s|^)"+ce+ce+"("+ee+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");let le=class t{constructor(e){const s="string"==typeof e?t.parseShadow(e):e;Object.assign(this,t.ownDefaults,s),this.id=K()}static parseShadow(t){const e=t.trim(),[,s=0,r=0,i=0]=(he.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(he,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:r,blur:i}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=((t,e)=>t.rotate(e))(new q(this.offsetX,this.offsetY),rt(-t.angle)),s=new $t(this.color);let r=40,i=40;return t.width&&t.height&&(r=100*kt((Math.abs(e.x)+this.blur)/t.width,o.NUM_FRACTION_DIGITS)+20,i=100*kt((Math.abs(e.y)+this.blur)/t.height,o.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(i,'%" height="').concat(100+2*i,'%" x="-').concat(r,'%" width="').concat(100+2*r,'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="').concat(kt(this.blur?this.blur/2:0,o.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(kt(e.x,o.NUM_FRACTION_DIGITS),'" dy="').concat(kt(e.y,o.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 e={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},s=t.ownDefaults;return this.includeDefaultValues?e:xt(e,((t,e)=>t!==s[e]))}static async fromObject(t){return new this(t)}};t(le,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),t(le,"type","shadow"),I.setClass(le,"shadow");const ue=(t,e,s)=>Math.max(t,Math.min(e,s)),de=[F,O,M,X,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Y,E],ge=[R,V,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],fe={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:O,originY:F,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:R,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},pe=(t,e,s,r)=>-s*Math.cos(t/r*b)+s+e,me=()=>!1;let ye=class{constructor(e){let{startValue:s,byValue:r,duration:i=500,delay:n=0,easing:o=pe,onStart:a=w,onChange:c=w,onComplete:h=w,abort:l=me,target:u}=e;t(this,"_state","pending"),t(this,"durationProgress",0),t(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=o,this._onStart=a,this._onChange=c,this._onComplete=h,this._abort=l,this.target=u,this.startValue=s,this.byValue=r,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((()=>$(t)),this.delay):$(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:r,valueProgress:i}=this.calculate(s);this.value=Object.freeze(r),this.valueProgress=i,"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),$(this.tick)))}register(){z.push(this)}unregister(){z.remove(this)}abort(){this._state="aborted",this.unregister()}};const ve=["startValue","endValue"];let we=class extends ye{constructor(t){let{startValue:e=0,endValue:i=100}=t;super(s(s({},r(t,ve)),{},{startValue:e,byValue:i-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 be=["startValue","endValue"];let Ce=class extends ye{constructor(t){let{startValue:e=[0],endValue:i=[100]}=t;super(s(s({},r(t,be)),{},{startValue:e,byValue:i.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 xe=["startValue","endValue","easing","onChange","onComplete","abort"],ke=(t,e,s,r)=>e+s*(1-Math.cos(t/r*b)),Se=t=>t&&((e,s,r)=>t(new $t(e).toRgba(),s,r));let _e=class extends ye{constructor(t){let{startValue:e,endValue:i,easing:n=ke,onChange:o,onComplete:a,abort:c}=t,h=r(t,xe);const l=new $t(e).getSource(),u=new $t(i).getSource();super(s(s({},h),{},{startValue:l,byValue:u.map(((t,e)=>t-l[e])),easing:n,onChange:Se(o),onComplete:Se(a),abort:Se(c)}))}calculate(t){const[e,s,r,i]=this.startValue.map(((e,s)=>this.easing(t,e,this.byValue[s],this.duration,s))),n=[...[e,s,r].map(Math.round),ue(0,i,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}}};let Oe=class t{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 r=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&&(r||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&&(r||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const i=ae(e,s),n=ae(e,t).divide(i);return r?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 q(t).setX(Math.min(t.x-1,...e.map((t=>t.x))));let r=0;for(let i=0;i<e.length;i++){const n=this.intersectSegmentSegment(e[i],e[(i+1)%e.length],t,s);if(n.includes(t))return!0;r+=Number("Intersection"===n.status)}return r%2==1}static intersectLineLine(e,s,r,i){let n=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];const a=s.x-e.x,c=s.y-e.y,h=i.x-r.x,l=i.y-r.y,u=e.x-r.x,d=e.y-r.y,g=h*d-l*u,f=a*d-c*u,p=l*a-h*c;if(0!==p){const s=g/p,r=f/p;return(n||0<=s&&s<=1)&&(o||0<=r&&r<=1)?new t("Intersection").append(new q(e.x+s*a,e.y+s*c)):new t}if(0===g||0===f){const a=n||o||t.isPointContained(e,r,i)||t.isPointContained(s,r,i)||t.isPointContained(r,e,s)||t.isPointContained(i,e,s);return new t(a?"Coincident":void 0)}return new t("Parallel")}static intersectSegmentLine(e,s,r,i){return t.intersectLineLine(e,s,r,i,!1,!0)}static intersectSegmentSegment(e,s,r,i){return t.intersectLineLine(e,s,r,i,!1,!1)}static intersectLinePolygon(e,s,r){let i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];const n=new t,o=r.length;for(let a,c,h,l=0;l<o;l++){if(a=r[l],c=r[(l+1)%o],h=t.intersectLineLine(e,s,a,c,i,!1),"Coincident"===h.status)return h;n.append(...h.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(e,s,r){return t.intersectLinePolygon(e,s,r,!1)}static intersectPolygonPolygon(e,s){const r=new t,i=e.length,n=[];for(let o=0;o<i;o++){const a=e[o],c=e[(o+1)%i],h=t.intersectSegmentPolygon(a,c,s);"Coincident"===h.status?(n.push(h),r.append(a,c)):r.append(...h.points)}return n.length>0&&n.length===e.length?new t("Coincident"):(r.points.length>0&&(r.status="Intersection"),r)}static intersectPolygonRectangle(e,s,r){const i=s.min(r),n=s.max(r),o=new q(n.x,i.y),a=new q(i.x,n.y);return t.intersectPolygonPolygon(e,[i,o,n,a])}};class Fe extends J{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?nt(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=nt(t,ot(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new q(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:r}=this.aCoords||(this.aCoords=this.calcACoords()),i=[t,e,s,r];if(this.group){const t=this.group.calcTransformMatrix();return i.map((e=>nt(e,t)))}return i}intersectsWithRect(t,e){return"Intersection"===Oe.intersectPolygonRectangle(this.getCoords(),t,e).status}intersectsWithObject(t){const e=Oe.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:r,width:i,height:n}=this.getBoundingRect();return s>=t.x&&s+i<=e.x&&r>=t.y&&r+n<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Oe.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 Mt(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(M,t),this._set(X,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?it(ht(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||k.concat()}calcACoords(){const t=dt({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),r=ut(e,s),i=at(r,t),n=this._getTransformedDimensions(),o=n.x/2,a=n.y/2;return{tl:nt({x:-o,y:-a},i),tr:nt({x:o,y:-a},i),bl:nt({x:-o,y:a},i),br:nt({x:o,y:a},i)}}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,Vt(this.originX),Vt(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),r=this.matrixCache;return r&&r.key.every(((t,e)=>t===s[e]))?r.value:(this.group&&(e=at(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(),r={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},i=vt(r);return this.ownMatrixCache={key:t,value:i},i}_getNonTransformedDimensions(){return new q(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=s({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),r=e.strokeWidth;let i=r,n=0;this.strokeUniform&&(i=0,n=r);const o=e.width+i,a=e.height+i;let c;return c=0===e.skewX&&0===e.skewY?new q(o*e.scaleX,a*e.scaleY):Yt(o,a,yt(e)),c.scalarAdd(n)}translateToGivenOrigin(t,e,s,r,i){let n=t.x,o=t.y;const a=Vt(r)-Vt(e),c=Vt(i)-Vt(s);if(a||c){const t=this._getTransformedDimensions();n+=a*t.x,o+=c*t.y}return new q(n,o)}translateToCenterPoint(t,e,s){if(e===_&&s===_)return t;const r=this.translateToGivenOrigin(t,e,s,_,_);return this.angle?r.rotate(rt(this.angle),t):r}translateToOriginPoint(t,e,s){const r=this.translateToGivenOrigin(t,_,_,e,s);return this.angle?r.rotate(rt(this.angle),t):r}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?nt(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new q(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const r=this.translateToCenterPoint(t,e,s),i=this.translateToOriginPoint(r,this.originX,this.originY);this.set({left:i.x,top:i.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),O,F)}}const Pe=["type"],je=["extraParam"];class Ae extends Fe{static getDefaults(){return Ae.ownDefaults}get type(){const t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){a("warn","Setting type has no effect",t)}constructor(e){super(),t(this,"_cacheContext",null),Object.assign(this,Ae.ownDefaults),this.setOptions(e)}_createCacheCanvas(){this._cacheCanvas=Q(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,r=o.maxCacheSideLimit,i=o.minCacheSideLimit;if(e<=r&&s<=r&&e*s<=o.perfLimitSizeTotal)return e<i&&(t.width=i),s<i&&(t.height=i),t;const n=e/s,[a,c]=y.limitDimsByArea(n),h=ue(i,a,r),l=ue(i,c,r);return e>h&&(t.zoomX/=e/h,t.width=h,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,r=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(r+2),zoomX:t.x,zoomY:t.y,x:s,y:r}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:r,zoomX:i,zoomY:n,x:o,y:a}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||r!==t.height,h=this.zoomX!==i||this.zoomY!==n;if(!t||!e)return!1;if(c||h){s!==t.width||r!==t.height?(t.width=s,t.height=r):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const c=o/2,h=a/2;return this.cacheTranslationX=Math.round(t.width/2-c)+c,this.cacheTranslationY=Math.round(t.height/2-h)+h,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(i,n),this.zoomX=i,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 q(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=lt(this.calcTransformMatrix());return new q(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!==M&&t!==X||(e=this._constrainScale(e)),t===M&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof le||(e=new le(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:r,cacheTranslationY:i}=this,{width:n,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:r,cacheTranslationY:i,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===V&&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 r=this.fill,i=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=r,this.stroke=i}createClipPathLayer(t,e){const s=tt(e),r=s.getContext("2d");if(r.translate(e.cacheTranslationX,e.cacheTranslationY),r.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach((t=>{t.transform(r)})),e.parentClipPaths.push(t),t.absolutePositioned){const t=ot(this.calcTransformMatrix());r.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return t.transform(r),t.drawObject(r,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const r=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,r)}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,_t(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&&(_t(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,r=this.getCanvasRetinaScaling(),[i,,,n]=(null==s?void 0:s.viewportTransform)||k,a=i*r,c=n*r,h=e.nonScaling?new q(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*o.browserShadowBlurConstant*(a+c)*(h.x+h.y)/4,t.shadowOffsetX=e.offsetX*a*h.x,t.shadowOffsetY=e.offsetY*c*h.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!_t(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,r=-this.width/2+e.offsetX||0,i=-this.height/2+e.offsetY||0;return"percentage"===e.gradientUnits?t.transform(this.width,0,0,this.height,r,i):t.transform(1,0,0,1,r,i),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:r,offsetY:i}}_renderPaintInOrder(t){this.paintFirst===V?(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 r=this._limitCacheSize(this._getCacheCanvasDimensions()),i=this.getCanvasRetinaScaling(),n=r.x/this.scaleX/i,o=r.y/this.scaleY/i,a=tt({width:Math.ceil(n),height:Math.ceil(o)}),c=a.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(n,0),c.lineTo(n,o),c.lineTo(0,o),c.closePath(),c.translate(n/2,o/2),c.scale(r.zoomX/this.scaleX/i,r.zoomY/this.scaleY/i),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(i*this.scaleX/r.zoomX,i*this.scaleY/r.zoomY),t.strokeStyle=null!==(s=c.createPattern(a,"no-repeat"))&&void 0!==s?s:"")}_findCenterFromElement(){return new q(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(I.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=(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}))(this),s=this.group,r=this.shadow,i=Math.abs,n=t.enableRetinaScaling?m():1,o=(t.multiplier||1)*n,a=t.canvasProvider||(t=>new Tt(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&&Et(this,this.getViewportTransform()),this.setCoords();const c=Q(),h=this.getBoundingRect(),l=this.shadow,u=new q;if(l){const t=l.blur,e=l.nonScaling?new q(1,1):this.getObjectScaling();u.x=2*Math.round(i(l.offsetX)+t)*i(e.x),u.y=2*Math.round(i(l.offsetY)+t)*i(e.y)}const d=h.width+u.x,g=h.height+u.y;c.width=Math.ceil(d),c.height=Math.ceil(g);const f=a(c);"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new q(f.width/2,f.height/2),_,_);const p=this.canvas;f._objects=[this],this.set("canvas",f),this.setCoords();const y=f.toCanvasElement(o||1,t);return this.set("canvas",p),this.shadow=r,s&&(this.group=s),this.set(e),this.setCoords(),f._objects=[],f.destroy(),y}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return et(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return st(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:r}=this;if(e){const{x:t,y:e}=this.getRelativeCenterPoint();this.originX=_,this.originY=_,this.left=t,this.top=e}if(this.set("angle",t),e){const{x:t,y:e}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,r);this.left=t,this.top=e,this.originX=s,this.originY=r}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){z.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&g().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce(((t,s)=>{let[r,i]=s;return t[r]=this._animate(r,i,e),t}),{})}_animate(t,e){let r=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:c,onComplete:h}=r,l=s(s({},r),{},{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),c&&c(t,e,s)},onComplete:(t,e,s)=>{this.setCoords(),h&&h(t,e,s)}});return n?function(t){const e=new _e(t);return e.start(),e}(l):function(t){const e=(t=>Array.isArray(t.startValue)||Array.isArray(t.endValue))(t)?new Ce(t):new we(t);return e.start(),e}(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 r,i=0;i<e.length;i++){if(r=e[i],r===t)return{fork:[this,...e.slice(0,i)],otherFork:[],common:e.slice(i)};for(let n=0;n<s.length;n++){if(this===s[n])return{fork:[],otherFork:[t,...s.slice(0,n)],common:[this,...e]};if(r===s[n])return{fork:[this,...e.slice(0,i)],otherFork:[t,...s.slice(0,n)],common:e.slice(i)}}}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 r=e.fork.pop(),i=e.otherFork.pop(),n=s._objects.indexOf(r),o=s._objects.indexOf(i);return n>-1&&n>o}toObject(){const t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).concat(Ae.customProperties,this.constructor.customProperties||[]);let e;const r=o.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:a,shadow:c,strokeDashArray:h,left:l,top:u,originX:d,originY:g,width:f,height:p,strokeWidth:m,strokeLineCap:y,strokeDashOffset:w,strokeLineJoin:b,strokeUniform:C,strokeMiterLimit:x,scaleX:k,scaleY:S,angle:_,flipX:O,flipY:F,opacity:P,visible:j,backgroundColor:A,fillRule:D,paintFirst:T,globalCompositeOperation:M,skewX:X,skewY:Y}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const E=t=>kt(t,r),R=s(s({},Ct(this,t)),{},{type:this.constructor.type,version:v,originX:d,originY:g,left:E(l),top:E(u),width:E(f),height:E(p),fill:Ot(n)?n.toObject():n,stroke:Ot(a)?a.toObject():a,strokeWidth:E(m),strokeDashArray:h?h.concat():h,strokeLineCap:y,strokeDashOffset:w,strokeLineJoin:b,strokeUniform:C,strokeMiterLimit:E(x),scaleX:E(k),scaleY:E(S),angle:E(_),flipX:O,flipY:F,opacity:E(P),shadow:c?c.toObject():c,visible:j,backgroundColor:A,fillRule:D,paintFirst:T,globalCompositeOperation:M,skewX:E(X),skewY:E(Y)},e?{clipPath:e}:null);return this.includeDefaultValues?R:this._removeDefaultValues(R)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return xt(t,((t,e)=>{if(e===O||e===F||"type"===e)return!0;const r=s[e];return t!==r&&!(Array.isArray(t)&&Array.isArray(r)&&0===t.length&&0===r.length)}))}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=r(t,Pe),s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:i}=s,n=r(s,je);return bt(e,n).then((t=>i?(delete t[i],new this(e[i],t)):new this(t)))}static fromObject(t,e){return this._fromObject(t,e)}}t(Ae,"stateProperties",de),t(Ae,"cacheProperties",ge),t(Ae,"ownDefaults",fe),t(Ae,"type","FabricObject"),t(Ae,"colorProperties",[R,V,"backgroundColor"]),t(Ae,"customProperties",[]),I.setClass(Ae),I.setClass(Ae,"object");const De=(t,e,r)=>(i,n,o,a)=>{const c=e(i,n,o,a);return c&&((t,e)=>{var r;const{transform:{target:i}}=e;null===(r=i.canvas)||void 0===r||r.fire("object:".concat(t),s(s({},e),{},{target:i})),i.fire(t,e)})(t,s(s({},((t,e,s,r)=>({e:t,transform:e,pointer:new q(s,r)}))(i,n,o,a)),r)),c};function Te(t){return(e,s,r,i)=>{const{target:n,originX:o,originY:a}=s,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=t(e,s,r,i);return n.setPositionByOrigin(h,s.originX,s.originY),l}}function Me(t,e,s,r,i){r=r||{};const n=this.sizeX||r.cornerSize||i.cornerSize,o=this.sizeY||r.cornerSize||i.cornerSize,a=void 0!==r.transparentCorners?r.transparentCorners:i.transparentCorners,c=a?V:R,h=!a&&(r.cornerStrokeColor||i.cornerStrokeColor);let l,u=e,d=s;t.save(),t.fillStyle=r.cornerColor||i.cornerColor||"",t.strokeStyle=r.cornerStrokeColor||i.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,C,!1),t[c](),h&&t.stroke(),t.restore()}function Xe(t,e,s,r,i){r=r||{};const n=this.sizeX||r.cornerSize||i.cornerSize,o=this.sizeY||r.cornerSize||i.cornerSize,a=void 0!==r.transparentCorners?r.transparentCorners:i.transparentCorners,c=a?V:R,h=!a&&(r.cornerStrokeColor||i.cornerStrokeColor),l=n/2,u=o/2;t.save(),t.fillStyle=r.cornerColor||i.cornerColor||"",t.strokeStyle=r.cornerStrokeColor||i.cornerStrokeColor||"",t.translate(e,s);const d=i.getTotalAngle();t.rotate(rt(d)),t["".concat(c,"Rect")](-l,-u,n,o),h&&t.strokeRect(-l,-u,n,o),t.restore()}let Ye=class{constructor(e){t(this,"visible",!0),t(this,"actionName",T),t(this,"angle",0),t(this,"x",0),t(this,"y",0),t(this,"offsetX",0),t(this,"offsetY",0),t(this,"sizeX",0),t(this,"sizeY",0),t(this,"touchSizeX",0),t(this,"touchSizeY",0),t(this,"cursorStyle","crosshair"),t(this,"withConnection",!1),Object.assign(this,e)}shouldActivate(t,e,s,r){var i;let{tl:n,tr:o,br:a,bl:c}=r;return(null===(i=e.canvas)||void 0===i?void 0:i.getActiveObject())===e&&e.isControlVisible(t)&&Oe.isPointInPolygon(s,[n,o,a,c])}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,r;return null!==(s=null===(r=t._controlsVisibility)||void 0===r?void 0:r[e])&&void 0!==s?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,r){return new q(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,r,i,n){const o=ct([ut(s,r),dt({angle:t}),gt((i?this.touchSizeX:this.sizeX)||e,(i?this.touchSizeY:this.sizeY)||e)]);return{tl:new q(-.5,-.5).transform(o),tr:new q(.5,-.5).transform(o),br:new q(.5,.5).transform(o),bl:new q(-.5,.5).transform(o)}}render(t,e,s,r,i){"circle"===((r=r||{}).cornerStyle||i.cornerStyle)?Me.call(this,t,e,s,r,i):Xe.call(this,t,e,s,r,i)}};const Ee=(t,e,s)=>s.lockRotation?Bt:e.cursorStyle,Re=De("rotating",Te(((t,e,s,r)=>{let{target:i,ex:n,ey:o,theta:a,originX:c,originY:h}=e;const l=i.translateToOriginPoint(i.getRelativeCenterPoint(),c,h);if(It(i,"lockRotation"))return!1;const u=Math.atan2(o-l.y,n-l.x),d=Math.atan2(r-l.y,s-l.x);let g=it(d-u+a);if(i.snapAngle&&i.snapAngle>0){const t=i.snapAngle,e=i.snapThreshold||t,s=Math.ceil(g/t)*t,r=Math.floor(g/t)*t;Math.abs(g-r)<e?g=r:Math.abs(g-s)<e&&(g=s)}g<0&&(g=360+g),g%=360;const f=i.angle!==g;return i.angle=g,f})));function Ve(t,e){const s=e.canvas,r=t[s.uniScaleKey];return s.uniformScaling&&!r||!s.uniformScaling&&r}function Be(t,e,s){const r=It(t,"lockScalingX"),i=It(t,"lockScalingY");if(r&&i)return!0;if(!e&&(r||i)&&s)return!0;if(r&&"x"===e)return!0;if(i&&"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 Le=["e","se","s","sw","w","nw","n","ne","e"],Ie=(t,e,s)=>{const r=Ve(t,s);if(Be(s,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",r))return Bt;const i=zt(s,e);return"".concat(Le[i],"-resize")};function ze(t,e,s,r){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=i.by,a=Ve(t,n);let c,h,l,u,d,g;if(Be(n,o,a))return!1;if(e.gestureScale)h=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(c=Gt(e,e.originX,e.originY,s,r),d="y"!==o?Math.sign(c.x||e.signX||1):1,g="x"!==o?Math.sign(c.y||e.signY||1):1,e.signX||(e.signX=d),e.signY||(e.signY=g),It(n,"lockScalingFlip")&&(e.signX!==d||e.signY!==g))return!1;if(u=n._getTransformedDimensions(),a&&!o){const t=Math.abs(c.x)+Math.abs(c.y),{original:s}=e,r=t/(Math.abs(u.x*s.scaleX/n.scaleX)+Math.abs(u.y*s.scaleY/n.scaleY));h=s.scaleX*r,l=s.scaleY*r}else h=Math.abs(c.x*n.scaleX/u.x),l=Math.abs(c.y*n.scaleY/u.y);(function(t){return Vt(t.originX)===Vt(_)&&Vt(t.originY)===Vt(_)})(e)&&(h*=2,l*=2),e.signX!==d&&"y"!==o&&(e.originX=Lt(e.originX),h*=-1,e.signX=d),e.signY!==g&&"x"!==o&&(e.originY=Lt(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set(M,h),"y"===o&&n.set(X,l)):(!It(n,"lockScalingX")&&n.set(M,h),!It(n,"lockScalingY")&&n.set(X,l)),f!==n.scaleX||p!==n.scaleY}const Ge=De(A,Te(((t,e,s,r)=>ze(t,e,s,r)))),Ne=De(A,Te(((t,e,s,r)=>ze(t,e,s,r,{by:"x"})))),We=De(A,Te(((t,e,s,r)=>ze(t,e,s,r,{by:"y"})))),He=["target","ex","ey","skewingSide"],qe={x:{counterAxis:"y",scale:M,skew:Y,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:X,skew:E,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},Ue=["ns","nesw","ew","nwse"];function Je(t,e,i,n,o){const{target:a}=i,{counterAxis:c,origin:h,lockSkewing:l,skew:u,flip:d}=qe[t];if(It(a,l))return!1;const{origin:g,flip:f}=qe[c],p=Vt(i[g])*(a[f]?-1:1),m=-Math.sign(p)*(a[d]?-1:1),y=-(0===a[u]&&Gt(i,_,_,n,o)[t]>0||a[u]>0?1:-1)*m*.5+.5,v=De("skewing",Te(((e,s,i,n)=>function(t,e,s){let{target:i,ex:n,ey:o,skewingSide:a}=e,c=r(e,He);const{skew:h}=qe[t],l=s.subtract(new q(n,o)).divide(new q(i.scaleX,i.scaleY))[t],u=i[h],d=c[h],g=Math.tan(rt(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=it(Math.atan(p));i.set(h,m);const y=u!==i[h];if(y&&"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(M,n*e)}return y}(t,s,new q(i,n)))));return v(e,s(s({},i),{},{[h]:y,skewingSide:m}),n,o)}function $e(t,e){return t[e.canvas.altActionKey]}const Ze=(t,e,s)=>{const r=$e(t,s);return 0===e.x?r?Y:X:0===e.y?r?E:M:""},Ke=(t,e,s)=>$e(t,s)?((t,e,s)=>{if(0!==e.x&&It(s,"lockSkewingY"))return Bt;if(0!==e.y&&It(s,"lockSkewingX"))return Bt;const r=zt(s,e)%4;return"".concat(Ue[r],"-resize")})(0,e,s):Ie(t,e,s),Qe=(t,e,s,r)=>$e(t,e.target)?((t,e,s,r)=>Je("y",t,e,s,r))(t,e,s,r):Ne(t,e,s,r),ts=(t,e,s,r)=>$e(t,e.target)?((t,e,s,r)=>Je("x",t,e,s,r))(t,e,s,r):We(t,e,s,r);let es=class t extends Ae{static getDefaults(){return s(s({},super.getDefaults()),t.ownDefaults)}constructor(e){super(),Object.assign(this,this.constructor.createControls(),t.ownDefaults),this.setOptions(e)}static createControls(){return{controls:{ml:new Ye({x:-.5,y:0,cursorStyleHandler:Ke,actionHandler:Qe,getActionName:Ze}),mr:new Ye({x:.5,y:0,cursorStyleHandler:Ke,actionHandler:Qe,getActionName:Ze}),mb:new Ye({x:0,y:.5,cursorStyleHandler:Ke,actionHandler:ts,getActionName:Ze}),mt:new Ye({x:0,y:-.5,cursorStyleHandler:Ke,actionHandler:ts,getActionName:Ze}),tl:new Ye({x:-.5,y:-.5,cursorStyleHandler:Ie,actionHandler:Ge}),tr:new Ye({x:.5,y:-.5,cursorStyleHandler:Ie,actionHandler:Ge}),bl:new Ye({x:-.5,y:.5,cursorStyleHandler:Ie,actionHandler:Ge}),br:new Ye({x:.5,y:.5,cursorStyleHandler:Ie,actionHandler:Ge}),mtr:new Ye({x:0,y:-.5,actionHandler:Re,cursorStyleHandler:Ee,offsetY:-40,withConnection:!0,actionName:D})}}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,r=e.action;if(this===s&&r&&r.startsWith(T))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 r=s.length-1;r>=0;r--){const[i,n]=s[r],o=this.controls[i];if(o.shouldActivate(i,this,t,e?n.touchCorner:n.corner))return this.__corner=i,{key:i,control:o,coord:this.oCoords[i]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=ut(e.x,e.y),r=dt({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),i=at(s,r),n=at(t,i),o=at(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?lt(this.calcTransformMatrix()):void 0;a&&(a.scaleX=Math.abs(a.scaleX),a.scaleY=Math.abs(a.scaleY));const c=this._calculateCurrentDimensions(a),h={};return this.forEachControl(((t,e)=>{const s=t.positionHandler(c,o,this,t);h[e]=Object.assign(s,this._calcCornerCoords(t,s))})),h}_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(),r=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/r[0],1/r[3]),t.rotate(rt(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 r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const i=s({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},r);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:r,hasControls:i}=this,n=s({hasBorders:r,hasControls:i},e),o=this.getViewportTransform(),a=n.hasBorders,c=n.hasControls,h=at(o,this.calcTransformMatrix()),l=lt(h);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(rt(this.group?l.angle:this.angle)),a&&this.drawBorders(t,l,e),c&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let r;if(s&&s.forActiveSelection||this.group){const t=Yt(this.width,this.height,yt(e)),s=this.isStrokeAccountedForInDimensions()?U:(this.strokeUniform?(new q).scalarAdd(this.canvas?this.canvas.getZoom():1):new q(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);r=t.add(s).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else r=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,r,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl(((r,i)=>{r.withConnection&&r.getVisibility(this,i)&&(s=!0,t.moveTo(r.x*e.x,r.y*e.y),t.lineTo(r.x*e.x+r.offsetX,r.y*e.y+r.offsetY))})),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.save();const r=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:o}=this,a=s({cornerStrokeColor:i,cornerDashArray:n,cornerColor:o},e);t.setTransform(r,0,0,r,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 r=this.oCoords[s];e.render(t,r.x,r.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 r=this.width+4,i=this.height+4;return e.clearRect(-r/2,-i/2,r,i),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){}};t(es,"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});let ss=class extends es{};(function(t,e){e.forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((s=>{"constructor"!==s&&Object.defineProperty(t.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))}))}))})(ss,[class{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",r=this.strokeDashArray?this.strokeDashArray.join(" "):j,i=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=void 0!==this.opacity?this.opacity:"1",h=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),u=Kt(R,this.fill);return[Kt(V,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",r,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",i,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",u,"fill-rule: ",e,"; ","opacity: ",c,";",l,h].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(),r='transform="'.concat(St(s));return"".concat(r).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 r=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),i=t.indexOf("COMMON_PARTS");return t[i]=r,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:r,additionalTransform:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=r?'style="'.concat(this.getSvgFilter(),'" '):"",a=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",h=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(K()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(s),"</clipPath>\n")),h&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),h?"":o+this.getSvgCommons()," >\n");const m=[n,c,e?"":this.addPaintOrder()," ",i?'transform="'.concat(i,'" '):""].join("");return t[f]=m,_t(u)&&g.push(u.toSVG(this)),_t(l)&&g.push(l.toSVG(this)),d&&g.push(d.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),h&&g.push("</g>\n"),s?s(g.join("")):g.join("")}addPaintOrder(){return this.paintFirst!==R?' paint-order="'.concat(this.paintFirst,'" '):""}}]),I.setClass(ss),I.setClass(ss,"object");const rs=["display","transform",R,"fill-opacity","fill-rule","opacity",V,"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 is(t,e){const s=t.nodeName,r=t.getAttribute("class"),i=t.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let o;if(o=new RegExp("^"+s,"i"),e=e.replace(o,""),i&&e.length&&(o=new RegExp("#"+i+n,"i"),e=e.replace(o,"")),r&&e.length){const t=r.split(" ");for(let s=t.length;s--;)o=new RegExp("\\."+t[s]+n,"i"),e=e.replace(o,"")}return 0===e.length}function ns(t,e){let s=!0;const r=is(t,e.pop());return r&&e.length&&(s=function(t,e){let s,r=!0;for(;t.parentElement&&1===t.parentElement.nodeType&&e.length;)r&&(s=e.pop()),r=is(t=t.parentElement,s);return 0===e.length}(t,e)),r&&s&&0===e.length}const os=t=>{var e;return null!==(e=re[t])&&void 0!==e?e:t},as=new RegExp("(".concat(ee,")"),"gi"),cs=t=>t.replace(as," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var hs,ls,us,ds,gs,fs,ps;const ms="(".concat(ee,")"),ys=String.raw(hs||(hs=i(["(skewX)(",")"],["(skewX)\\(","\\)"])),ms),vs=String.raw(ls||(ls=i(["(skewY)(",")"],["(skewY)\\(","\\)"])),ms),ws=String.raw(us||(us=i(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),ms,ms,ms),bs=String.raw(ds||(ds=i(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),ms,ms),Cs=String.raw(gs||(gs=i(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),ms,ms),xs=String.raw(fs||(fs=i(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),ms,ms,ms,ms,ms,ms),ks="(?:".concat(xs,"|").concat(Cs,"|").concat(ws,"|").concat(bs,"|").concat(ys,"|").concat(vs,")"),Ss="(?:".concat(ks,"*)"),_s=String.raw(ps||(ps=i(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Ss),Os=new RegExp(_s),Fs=new RegExp(ks),Ps=new RegExp(ks,"g");function js(t){const e=[];if(!(t=cs(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!Os.test(t))return[...k];for(const s of t.matchAll(Ps)){const t=Fs.exec(s[0]);if(!t)continue;let r=k;const i=t.filter((t=>!!t)),[,n,...o]=i,[a,c,h,l,u,d]=o.map((t=>parseFloat(t)));switch(n){case"translate":r=ut(a,c);break;case D:r=dt({angle:a},{x:c,y:h});break;case T:r=gt(a,c);break;case Y:r=pt(a);break;case E:r=mt(a);break;case"matrix":r=[a,c,h,l,u,d]}e.push(r)}return ct(e)}function As(t,e,s,r){const i=Array.isArray(e);let n,o=e;if(t!==R&&t!==V||e!==j){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)o=e===j?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)o=s&&s.transformMatrix?at(s.transformMatrix,js(e)):js(e);else if("visible"===t)o=e!==j&&"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?O:"end"===e?P:_;else if("charSpacing"===t)n=Zt(e,r)/r*1e3;else if("paintFirst"===t){const t=e.indexOf(R),s=e.indexOf(V);o=R,(t>-1&&s>-1&&s<t||-1===t&&s>-1)&&(o=V)}else{if("href"===t||"xlink:href"===t||"font"===t||"id"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=i?e.map(Zt):Zt(e,r)}}else o="";return!i&&isNaN(n)?o:n}function Ds(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,r]=t.split(":");e[s.trim().toLowerCase()]=r.trim()}))}(s,e):function(t,e){Object.entries(t).forEach((t=>{let[s,r]=t;void 0!==r&&(e[s.toLowerCase()]=r)}))}(s,e),e):e}const Ts={stroke:"strokeOpacity",fill:"fillOpacity"};function Ms(t,e,r){if(!t)return{};let i,n={},o=16;t.parentNode&&oe.test(t.parentNode.nodeName)&&(n=Ms(t.parentElement,e,r),n.fontSize&&(i=o=Zt(n.fontSize)));const a=s(s(s({},e.reduce(((e,s)=>{const r=t.getAttribute(s);return r&&(e[s]=r),e}),{})),function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r={};for(const i in e)ns(t,i.split(" "))&&(r=s(s({},r),e[i]));return r}(t,r)),Ds(t));a[ne]&&t.setAttribute(ne,a[ne]),a[ie]&&(i=Zt(a[ie],o),a[ie]="".concat(i));const c={};for(const t in a){const e=os(t),s=As(e,a[t],n,i);c[e]=s}c&&c.font&&function(t,e){const s=t.match(se);if(!s)return;const r=s[1],i=s[3],n=s[4],o=s[5],a=s[6];r&&(e.fontStyle=r),i&&(e.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(e.fontSize=Zt(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}(c.font,c);const h=s(s({},n),c);return oe.test(t.nodeName)?h:function(t){const e=ss.getDefaults();return Object.entries(Ts).forEach((s=>{let[r,i]=s;if(void 0===t[i]||""===t[r])return;if(void 0===t[r]){if(!e[r])return;t[r]=e[r]}if(0===t[r].indexOf("url("))return;const n=new $t(t[r]);t[r]=n.setAlpha(kt(n.getAlpha()*t[i],2)).toRgba()})),t}(h)}const Xs=["left","top","radius"],Ys=["radius","startAngle","endAngle","counterClockwise"];class Es extends ss{static getDefaults(){return s(s({},super.getDefaults()),Es.ownDefaults)}constructor(t){super(),Object.assign(this,Es.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,rt(this.startAngle),rt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(M)}getRadiusY(){return this.get("radius")*this.get(X)}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([...Ys,...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=rt(this.startAngle),r=rt(this.endAngle),i=W(s)*e,n=H(s)*e,o=W(r)*e,a=H(r)*e,c=t>180?1:0,h=this.counterClockwise?0:1;return['<path d="M '.concat(i," ").concat(n," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(h," ").concat(o," ").concat(a,'" '),"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,i){const n=Ms(t,this.ATTRIBUTE_NAMES,i),{left:o=0,top:a=0,radius:c=0}=n;return new this(s(s({},r(n,Xs)),{},{radius:c,left:o-c,top:a-c}))}static fromObject(t){return super._fromObject(t)}}t(Es,"type","Circle"),t(Es,"cacheProperties",[...ge,...Ys]),t(Es,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),t(Es,"ATTRIBUTE_NAMES",["cx","cy","r",...rs]),I.setClass(Es),I.setSVGClass(Es);const Rs=(t,e)=>{var s;const r=null!==(s=t.viewportTransform)&&void 0!==s?s:[1,0,0,1,0,0];return new q(e.x,e.y).transform(ot(r))},Vs=(t,e)=>{const{left:s=0,top:r=0}=t;if("path"===e.type){const t=e,i=t.calcOwnMatrix(),n=t.pathOffset.transform(i,!0);return new q(s+n.x,r+n.y).transform(ot(i))}const i=e.calcOwnMatrix();return new q(s,r).transform(ot(i))},Bs=(t,e)=>()=>{let s=!1;const r=t=>{s=t.key.toUpperCase()===e.toUpperCase()},i=t=>{s=t.key.toUpperCase()===e.toUpperCase()},n=t=>{if(s&&t.target&&t.transform){const{left:e=0,top:s=0}=t.target,{left:r,top:i}=t.transform.original;Math.abs(e-r)>Math.abs(s-i)?t.target.set({top:i}).setCoords():t.target.set({left:r}).setCoords()}};return t.on("object:moving",n),window.addEventListener("keydown",r),window.addEventListener("keyup",i),()=>{t.off("object:moving",n),window.removeEventListener("keydown",r),window.removeEventListener("keyup",i)}};export{Rs as a,ss as b,Vs as c,Ms as d,t as e,Es as f,I as g,ge as h,q as i,O as j,Mt as k,F as l,S as m,r as n,rs as o,_ as p,_t as q,Bs as r,ot as s,s as t,lt as u};
//# sourceMappingURL=register-limit-move-event-_gHDOT2-.js.map