fabric 6.0.0-beta13 → 6.0.0-beta15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +9 -0
- package/CHANGELOG.md +35 -1
- package/CONTRIBUTING.md +9 -9
- package/dist/fabric.d.ts +36 -3
- package/dist/index.js +218 -324
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +214 -323
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +218 -324
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +214 -323
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/Intersection.d.ts +8 -0
- package/dist/src/canvas/Canvas.d.ts +1 -1
- package/dist/src/canvas/CanvasOptions.d.ts +1 -1
- package/dist/src/canvas/DOMManagers/CanvasDOMManager.d.ts +1 -1
- package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.d.ts +2 -2
- package/dist/src/canvas/SelectableCanvas.d.ts +10 -15
- package/dist/src/canvas/StaticCanvas.d.ts +2 -2
- package/dist/src/controls/Control.d.ts +8 -8
- package/dist/src/controls/index.d.ts +1 -1
- package/dist/src/controls/polyControl.d.ts +25 -0
- package/dist/src/filters/BlendImage.d.ts +4 -4
- package/dist/src/shapes/Group.d.ts +5 -1
- package/dist/src/shapes/IText/ITextBehavior.d.ts +2 -2
- package/dist/src/shapes/Image.d.ts +11 -11
- package/dist/src/shapes/Object/InteractiveObject.d.ts +2 -3
- package/dist/src/shapes/Object/Object.d.ts +4 -4
- package/dist/src/shapes/Object/ObjectGeometry.d.ts +3 -29
- package/dist/src/shapes/Object/types/FabricObjectProps.d.ts +1 -1
- package/dist/src/shapes/Path.d.ts +1 -1
- package/dist/src/shapes/Text/StyledText.d.ts +2 -2
- package/dist/src/shapes/Text/Text.d.ts +7 -7
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +7 -7
- package/dist/src/shapes/Text/constants.d.ts +2 -2
- package/dist/src/util/animation/AnimationRegistry.d.ts +4 -4
- package/dist/src/util/internals/console.d.ts +8 -0
- package/dist/src/util/misc/dom.d.ts +1 -1
- package/dist/src/util/misc/svgParsing.d.ts +2 -1
- package/dist/src/util/typeAssertions.d.ts +2 -2
- package/fabric.ts +45 -3
- package/jest.extend.ts +3 -1
- package/package.json +5 -6
- package/playwright.setup.ts +82 -14
- package/src/ClassRegistry.ts +3 -1
- package/src/Collection.ts +2 -3
- package/src/Intersection.spec.ts +74 -0
- package/src/Intersection.ts +30 -0
- package/src/Pattern/Pattern.ts +2 -1
- package/src/benchmarks/README.md +7 -0
- package/src/benchmarks/calcCornerCoords.mjs +117 -0
- package/src/benchmarks/raycasting.mjs +154 -0
- package/src/canvas/Canvas.ts +23 -11
- package/src/canvas/CanvasOptions.ts +1 -1
- package/src/canvas/DOMManagers/CanvasDOMManager.ts +1 -1
- package/src/canvas/DOMManagers/StaticCanvasDOMManager.ts +7 -7
- package/src/canvas/SelectableCanvas.ts +30 -43
- package/src/canvas/StaticCanvas.ts +9 -7
- package/src/canvas/__tests__/SelectableCanvas.spec.ts +60 -0
- package/src/canvas/__tests__/__snapshots__/eventData.test.ts.snap +193 -2
- package/src/canvas/__tests__/eventData.test.ts +40 -1
- package/src/controls/Control.spec.ts +41 -0
- package/src/controls/Control.ts +36 -44
- package/src/controls/index.ts +1 -1
- package/src/controls/polyControl.ts +8 -5
- package/src/filters/BaseFilter.ts +8 -6
- package/src/filters/BlendImage.ts +4 -4
- package/src/filters/GLProbes/WebGLProbe.ts +2 -1
- package/src/parser/elements_parser.ts +2 -2
- package/src/parser/loadSVGFromString.test.ts +36 -0
- package/src/parser/parseSVGDocument.ts +2 -1
- package/src/parser/parseUseDirectives.ts +6 -2
- package/src/parser/recursivelyParseGradientsXlink.ts +1 -3
- package/src/shapes/ActiveSelection.spec.ts +35 -1
- package/src/shapes/ActiveSelection.ts +3 -1
- package/src/shapes/Group.ts +7 -8
- package/src/shapes/IText/IText.test.ts +43 -0
- package/src/shapes/IText/IText.ts +1 -1
- package/src/shapes/IText/ITextBehavior.ts +2 -2
- package/src/shapes/IText/__snapshots__/IText.test.ts.snap +50 -0
- package/src/shapes/Image.ts +15 -14
- package/src/shapes/Object/FabricObject.spec.ts +16 -0
- package/src/shapes/Object/InteractiveObject.spec.ts +43 -0
- package/src/shapes/Object/InteractiveObject.ts +20 -30
- package/src/shapes/Object/Object.ts +6 -5
- package/src/shapes/Object/ObjectGeometry.ts +11 -126
- package/src/shapes/Object/types/FabricObjectProps.ts +1 -1
- package/src/shapes/Text/StyledText.ts +5 -2
- package/src/shapes/Text/Text.spec.ts +9 -9
- package/src/shapes/Text/Text.ts +16 -15
- package/src/shapes/Text/TextSVGExportMixin.spec.ts +29 -0
- package/src/shapes/Text/TextSVGExportMixin.ts +16 -13
- package/src/shapes/Text/__snapshots__/Text.spec.ts.snap +6 -6
- package/src/shapes/Text/constants.ts +2 -2
- package/src/util/animation/AnimationRegistry.ts +7 -6
- package/src/util/internals/console.ts +18 -0
- package/src/util/internals/dom_request.ts +2 -1
- package/src/util/misc/dom.ts +3 -2
- package/src/util/misc/objectEnlive.ts +3 -2
- package/src/util/misc/planeChange.ts +3 -2
- package/src/util/misc/svgParsing.ts +22 -9
- package/src/util/transform_matrix_removal.ts +3 -3
- package/src/util/typeAssertions.ts +2 -2
- package/typedoc.config.json +6 -0
- package/typedoc.json +3 -2
- package/dist/src/parser/elementById.d.ts +0 -7
- package/src/parser/elementById.ts +0 -18
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fabric={})}(this,(function(t){"use strict";function e(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,s)}return i}function i(t){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?e(Object(r),!0).forEach((function(e){s(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(t,e,i){return(e=o(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function r(t,e){if(null==t)return{};var i,s,r=function(t,e){if(null==t)return{};var i,s,r={},n=Object.keys(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||(r[i]=t[i]);return r}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(r[i]=t[i])}return r}function n(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function o(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var s=i.call(t,e||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}class a{constructor(){s(this,"browserShadowBlurConstant",1),s(this,"DPI",96),s(this,"devicePixelRatio",1),s(this,"perfLimitSizeTotal",2097152),s(this,"maxCacheSideLimit",4096),s(this,"minCacheSideLimit",256),s(this,"disableStyleCopyPaste",!1),s(this,"enableGLFiltering",!0),s(this,"textureSize",4096),s(this,"forceGLPutImageData",!1),s(this,"cachesBoundsOfCurve",!0),s(this,"fontPaths",{}),s(this,"NUM_FRACTION_DIGITS",4)}}const h=new class extends a{constructor(t){super(),this.configure(t)}configure(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(this,t)}addFonts(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.fontPaths=i(i({},this.fontPaths),t)}removeFonts(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).forEach((t=>{delete this.fontPaths[t]}))}clearFonts(){this.fontPaths={}}restoreDefaults(t){const e=new a,i=(null==t?void 0:t.reduce(((t,i)=>(t[i]=e[i],t)),{}))||e;this.configure(i)}};class c{}class l extends c{testPrecision(t,e){const i="precision ".concat(e," float;\nvoid main(){}"),s=t.createShader(t.FRAGMENT_SHADER);return!!s&&(t.shaderSource(s,i),t.compileShader(s),!!t.getShaderParameter(s,t.COMPILE_STATUS))}queryWebGL(t){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))),console.log("fabric: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const d={};let u,g=!1;let f;const p=()=>f||(g||(h.configure({devicePixelRatio:window.devicePixelRatio||1}),u="ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,g=!0),{document:document,window:window,isTouchSupported:u,WebGLProbe:new l,dispose(){},copyPasteData:d}),m=()=>p().document,v=()=>p().window;const _=new class{constructor(){s(this,"charWidthsCache",{}),s(this,"boundsOfCurveCache",{})}getFontCache(t){let{fontFamily:e,fontStyle:i,fontWeight:s}=t;e=e.toLowerCase(),this.charWidthsCache[e]||(this.charWidthsCache[e]={});const r=this.charWidthsCache[e],n="".concat(i.toLowerCase(),"_").concat((s+"").toLowerCase());return r[n]||(r[n]={}),r[n]}clearFontCache(t){(t=(t||"").toLowerCase())?this.charWidthsCache[t]&&delete this.charWidthsCache[t]:this.charWidthsCache={}}limitDimsByArea(t){const{perfLimitSizeTotal:e}=h,i=Math.sqrt(e*t);return[Math.floor(i),Math.floor(e/i)]}};const y="6.0.0-beta13";function x(){}const C=Math.PI/2,b=2*Math.PI,S=Math.PI/180,w=Object.freeze([1,0,0,1,0,0]),T=16,O=.4477152502,k="center",D="left",M="top",P="bottom",E="right",A="none",j=/\r?\n/,F="json",L="svg";const R=new class{constructor(){this[F]=new Map,this[L]=new Map}getClass(t){const e=this[F].get(t);if(!e)throw new Error("No class registered for ".concat(t));return e}setClass(t,e){e?this[F].set(e,t):(this[F].set(t.type,t),this[F].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)}};const B=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 i;return"object"==typeof e.target&&(null===(i=e.target)||void 0===i?void 0:i.canvas)===t}));return e.forEach((t=>t.abort())),e}cancelByTarget(t){if(!t)return[];const e=this.filter((e=>e.target===t));return e.forEach((t=>t.abort())),e}};class I{constructor(){s(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),"object"==typeof t)return Object.entries(t).forEach((t=>{let[e,i]=t;this.on(e,i)})),()=>this.off(t);if(e){const i=t;return this.__eventListeners[i]||(this.__eventListeners[i]=[]),this.__eventListeners[i].push(e),()=>this.off(i,e)}return()=>!1}once(t,e){if("object"==typeof t){const e=[];return Object.entries(t).forEach((t=>{let[i,s]=t;e.push(this.once(i,s))})),()=>e.forEach((t=>t()))}if(e){const i=this.on(t,(function(){for(var t=arguments.length,s=new Array(t),r=0;r<t;r++)s[r]=arguments[r];e.call(this,...s),i()}));return i}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const i=this.__eventListeners[t],s=i.indexOf(e);s>-1&&i.splice(s,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(void 0===t)for(const t in this.__eventListeners)this._removeEventListener(t);else"object"==typeof t?Object.entries(t).forEach((t=>{let[e,i]=t;this._removeEventListener(e,i)})):this._removeEventListener(t,e)}fire(t,e){var i;if(!this.__eventListeners)return;const s=null===(i=this.__eventListeners[t])||void 0===i?void 0:i.concat();if(s)for(let t=0;t<s.length;t++)s[t].call(this,e||{})}}const X=(t,e)=>Math.floor(Math.random()*(e-t+1))+t,Y=(t,e)=>isNaN(t)&&"number"==typeof e?e:t,W=(t,e)=>{const i=t.indexOf(e);return-1!==i&&t.splice(i,1),t},V=t=>{if(0===t)return 1;switch(Math.abs(t)/C){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},G=t=>{if(0===t)return 0;const e=t/C,i=Math.sign(t);switch(e){case 1:return i;case 2:return 0;case 3:return-i}return Math.sin(t)};class z{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new z(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new z(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new z(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new z(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new z(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new z(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new z(this.x/t.x,this.y/t.y)}scalarDivide(t){return new z(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new z(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}midPointFrom(t){return this.lerp(t)}min(t){return new z(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new z(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i}clone(){return new z(this.x,this.y)}rotate(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:H;const i=G(t),s=V(t),r=this.subtract(e);return new z(r.x*s-r.y*i,r.x*i+r.y*s).add(e)}transform(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new z(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const H=new z(0,0);function U(t){class e extends t{constructor(){super(...arguments),s(this,"_objects",[])}_onObjectAdded(t){}_onObjectRemoved(t){}_onStackOrderChanged(t){}add(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];const s=this._objects.push(...e);return e.forEach((t=>this._onObjectAdded(t))),s}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return this._objects.splice(t,0,...i),i.forEach((t=>this._onObjectAdded(t))),this._objects.length}remove(){const t=this._objects,e=[];for(var i=arguments.length,s=new Array(i),r=0;r<i;r++)s[r]=arguments[r];return s.forEach((i=>{const s=t.indexOf(i);-1!==s&&(t.splice(s,1),e.push(i),this._onObjectRemoved(i))})),e}forEachObject(t){this.getObjects().forEach(((e,i,s)=>t(e,i,s)))}getObjects(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];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,i){return!!this._objects.includes(t)||!!i&&this._objects.some((i=>i instanceof e&&i.contains(t,!0)))}complexity(){return this._objects.reduce(((t,e)=>t+=e.complexity?e.complexity():0),0)}sendObjectToBack(t){return!(!t||t===this._objects[0])&&(W(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),!0)}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1])&&(W(this._objects,t),this._objects.push(t),this._onStackOrderChanged(t),!0)}sendObjectBackwards(t,e){if(!t)return!1;const i=this._objects.indexOf(t);if(0!==i){const s=this.findNewLowerIndex(t,i,e);return W(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}bringObjectForward(t,e){if(!t)return!1;const i=this._objects.indexOf(t);if(i!==this._objects.length-1){const s=this.findNewUpperIndex(t,i,e);return W(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(W(this._objects,t),this._objects.splice(e,0,t),this._onStackOrderChanged(t),!0)}findNewLowerIndex(t,e,i){let s;if(i){s=e;for(let i=e-1;i>=0;--i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e-1;return s}findNewUpperIndex(t,e,i){let s;if(i){s=e;for(let i=e+1;i<this._objects.length;++i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e+1;return s}collectObjects(t){let{left:e,top:i,width:s,height:r}=t,{includeIntersecting:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[],a=new z(e,i),h=a.add(new z(s,r));for(let t=this._objects.length-1;t>=0;t--){const e=this._objects[t];e.selectable&&e.visible&&(n&&e.intersectsWithRect(a,h,!0)||e.isContainedWithinRect(a,h,!0)||n&&e.containsPoint(a,void 0,!0)||n&&e.containsPoint(h,void 0,!0))&&o.push(e)}return o}}return e}class N extends I{_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 q(t){return v().requestAnimationFrame(t)}function K(t){return v().cancelAnimationFrame(t)}let J=0;const Z=()=>J++,Q=()=>{const t=m().createElement("canvas");if(!t||void 0===t.getContext)throw new Error("Failed to create `canvas` element");return t},$=()=>m().createElement("img"),tt=(t,e,i)=>t.toDataURL("image/".concat(e),i),et=t=>t*S,it=t=>t/S,st=["translateX","translateY","angle"],rt=(t,e,i)=>new z(t).transform(e,i),nt=t=>{const e=1/(t[0]*t[3]-t[1]*t[2]),i=[e*t[3],-e*t[1],-e*t[2],e*t[0],0,0],{x:s,y:r}=new z(t[4],t[5]).transform(i,!0);return i[4]=-s,i[5]=-r,i},ot=(t,e,i)=>[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],i?0:t[0]*e[4]+t[2]*e[5]+t[4],i?0:t[1]*e[4]+t[3]*e[5]+t[5]],at=(t,e)=>t.reduceRight(((t,i)=>i?ot(i,t,e):t),w),ht=t=>{const e=Math.atan2(t[1],t[0]),i=Math.pow(t[0],2)+Math.pow(t[1],2),s=Math.sqrt(i),r=(t[0]*t[3]-t[2]*t[1])/s,n=Math.atan2(t[0]*t[2]+t[1]*t[3],i);return{angle:it(e),scaleX:s,scaleY:r,skewX:it(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},ct=function(t){return[1,0,0,1,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0]};function lt(){let{angle:t=0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{x:e=0,y:i=0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=et(t),r=V(s),n=G(s);return[r,n,-n,r,e?e-(r*e-n*i):0,i?i-(n*e+r*i):0]}const dt=function(t){return[t,0,0,arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,0,0]},ut=t=>Math.tan(et(t)),gt=t=>[1,0,ut(t),1,0,0],ft=t=>[1,ut(t),0,1,0,0],pt=t=>{let{scaleX:e=1,scaleY:i=1,flipX:s=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=t;return at([dt(s?-e:e,r?-i:i),n&>(n),o&&ft(o)],!0)},mt=t=>{let{translateX:e=0,translateY:i=0,angle:s=0}=t,n=r(t,st);return at([ct(e,i),s&<({angle:s}),pt(n)])},vt=function(t){let{signal:e,crossOrigin:i=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(s,r){if(e&&e.aborted)return r(new Error("`options.signal` is in `aborted` state"));const n=$();let o;e&&(o=function(t){n.src="",r(t)},e.addEventListener("abort",o,{once:!0}));const a=function(){n.onload=n.onerror=null,o&&(null==e||e.removeEventListener("abort",o)),s(n)};t?(n.onload=a,n.onerror=function(){o&&(null==e||e.removeEventListener("abort",o)),r(new Error("Error loading "+n.src))},i&&(n.crossOrigin=i),n.src=t):a()}))},_t=function(t){let{signal:e,reviver:i=x}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((s,r)=>{const n=[];e&&e.addEventListener("abort",r,{once:!0}),Promise.all(t.map((t=>R.getClass(t.type).fromObject(t,{signal:e,reviver:i}).then((e=>(i(t,e),n.push(e),e)))))).then(s).catch((t=>{n.forEach((t=>{t.dispose&&t.dispose()})),r(t)})).finally((()=>{e&&e.removeEventListener("abort",r)}))}))},yt=function(t){let{signal:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((i,s)=>{const r=[];e&&e.addEventListener("abort",s,{once:!0});const n=Object.values(t).map((t=>t?t.colorStops?new(R.getClass("gradient"))(t):t.type?_t([t],{signal:e}).then((t=>{let[e]=t;return r.push(e),e})):t.source?R.getClass("pattern").fromObject(t,{signal:e}).then((t=>(r.push(t),t))):t:t)),o=Object.keys(t);Promise.all(n).then((t=>t.reduce(((t,e,i)=>(t[o[i]]=e,t)),{}))).then(i).catch((t=>{r.forEach((t=>{t.dispose&&t.dispose()})),s(t)})).finally((()=>{e&&e.removeEventListener("abort",s)}))}))},xt=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce(((e,i)=>(i in t&&(e[i]=t[i]),e)),{})},Ct=(t,e)=>Object.keys(t).reduce(((i,s)=>(e(t[s],s,t)&&(i[s]=t[s]),i)),{}),bt={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"},St=(t,e,i)=>(i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t),wt=(t,e,i,s)=>{t/=255,e/=255,i/=255;const r=Math.max(t,e,i),n=Math.min(t,e,i);let o,a;const h=(r+n)/2;if(r===n)o=a=0;else{const s=r-n;switch(a=h>.5?s/(2-r-n):s/(r+n),r){case t:o=(e-i)/s+(e<i?6:0);break;case e:o=(i-t)/s+2;break;case i:o=(t-e)/s+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*h),s]},Tt=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"1";return parseFloat(t)/(t.endsWith("%")?100:1)},Ot=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),kt=t=>{let[e,i,s,r=1]=t;const n=Math.round(.3*e+.59*i+.11*s);return[n,n,n,r]};class Dt{constructor(t){if(t)if(t instanceof Dt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,i,s,r=1]=t;this.setSource([e,i,s,r])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in bt&&(t=bt[t]),"transparent"===t?[255,255,255,0]:Dt.sourceFromHex(t)||Dt.sourceFromRgb(t)||Dt.sourceFromHsl(t)||[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,i]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(i,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,i]=wt(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(i,"%)")}toHsla(){const[t,e,i,s]=wt(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(i,"%,").concat(s,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,i,s]=this.getSource();return"".concat(Ot(t)).concat(Ot(e)).concat(Ot(i)).concat(Ot(Math.round(255*s)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(kt(this.getSource())),this}toBlackWhite(t){const[e,,,i]=kt(this.getSource()),s=e<(t||127)?0:255;return this.setSource([s,s,s,i]),this}overlayWith(t){t instanceof Dt||(t=new Dt(t));const e=this.getSource(),i=t.getSource(),[s,r,n]=e.map(((t,e)=>Math.round(.5*t+.5*i[e])));return this.setSource([s,r,n,e[3]]),this}static fromRgb(t){return Dt.fromRgba(t)}static fromRgba(t){return new Dt(Dt.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,i,s]=e.slice(1,4).map((t=>{const e=parseFloat(t);return t.endsWith("%")?Math.round(2.55*e):e}));return[t,i,s,Tt(e[4])]}}static fromHsl(t){return Dt.fromHsla(t)}static fromHsla(t){return new Dt(Dt.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{1,3})\s*[\s|,]\s*(\d{1,3}%)\s*[\s|,]\s*(\d{1,3}%)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const i=(parseFloat(e[1])%360+360)%360/360,s=parseFloat(e[2])/100,r=parseFloat(e[3])/100;let n,o,a;if(0===s)n=o=a=r;else{const t=r<=.5?r*(s+1):r+s-r*s,e=2*r-t;n=St(e,t,i+1/3),o=St(e,t,i),a=St(e,t,i-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*a),Tt(e[4])]}static fromHex(t){return new Dt(Dt.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 i;i=e.length<=4?e.split("").map((t=>t+t)):e.match(/.{2}/g);const[s,r,n,o=255]=i.map((t=>parseInt(t,16)));return[s,r,n,o/255]}}}const Mt=(t,e)=>parseFloat(Number(t).toFixed(e)),Pt=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:T;const i=/\D{0,2}$/.exec(t),s=parseFloat(t),r=h.DPI;switch(null==i?void 0:i[0]){case"mm":return s*r/25.4;case"cm":return s*r/2.54;case"in":return s*r;case"pt":return s*r/72;case"pc":return s*r/72*12;case"em":return s*e;default:return s}},Et=t=>{const[e,i]=t.trim().split(" "),[s,r]=(n=e)&&n!==A?[n.slice(1,4),n.slice(5,8)]:n===A?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:i||"meet",alignX:s,alignY:r}},At=t=>"matrix("+t.map((t=>Mt(t,h.NUM_FRACTION_DIGITS))).join(" ")+")",jt=(t,e)=>{if(e){if(e.toLive)return"".concat(t,": url(#SVGID_").concat(e.id,"); ");{const i=new Dt(e),s=i.getAlpha();let r="".concat(t,": ").concat(i.toRgb(),"; ");return 1!==s&&(r+="".concat(t,"-opacity: ").concat(s.toString(),"; ")),r}}return"".concat(t,": none; ")},Ft=function(t,e){let{left:i,top:s,width:r,height:n}=e,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:h.NUM_FRACTION_DIGITS;const a=jt("fill",t),[c,l,d,u]=[i,s,r,n].map((t=>Mt(t,o)));return"<rect ".concat(a,' x="').concat(c,'" y="').concat(l,'" width="').concat(d,'" height="').concat(u,'"></rect>')},Lt=t=>!!t&&void 0!==t.toLive,Rt=t=>!!t&&"function"==typeof t.toObject,Bt=t=>!!t&&void 0!==t.offsetX&&void 0!==t.source,It=t=>!!t&&Array.isArray(t._objects),Xt=t=>!!t&&t.isType("Text","IText","Textbox"),Yt=t=>!!t&&t.isType("IText","Textbox"),Wt=t=>!!t&&"function"==typeof t.onDragStart&&"function"==typeof t.shouldStartDragging;function Vt(t){const e=t&&Gt(t);let i=0,s=0;if(!t||!e)return{left:i,top:s};const r=e.documentElement,n=e.body||{scrollLeft:0,scrollTop:0};for(;t&&(t.parentNode||t.host)&&((t=t.parentNode||t.host)===e?(i=n.scrollLeft||r.scrollLeft||0,s=n.scrollTop||r.scrollTop||0):(i+=t.scrollLeft||0,s+=t.scrollTop||0),1!==t.nodeType||"fixed"!==t.style.position););return{left:i,top:s}}const Gt=t=>t.ownerDocument||null,zt=t=>{var e;return(null===(e=t.ownerDocument)||void 0===e?void 0:e.defaultView)||null};function Ht(t,e){const i=t.style;i&&("string"==typeof e?t.style.cssText+=";"+e:Object.entries(e).forEach((t=>{let[e,s]=t;return i.setProperty(e,s)})))}const Ut=function(t,e,i){let{width:s,height:r}=i,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;t.width=s,t.height=r,n>1&&(t.setAttribute("width",(s*n).toString()),t.setAttribute("height",(r*n).toString()),e.scale(n,n))};const Nt=(t,e)=>{let{width:i,height:s}=e;i&&(t.style.width="number"==typeof i?"".concat(i,"px"):i),s&&(t.style.height="number"==typeof s?"".concat(s,"px"):s)};function qt(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect=A,t}class Kt{constructor(t){s(this,"_originalCanvasStyle",void 0),s(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(i=t)&&void 0!==i.getContext?t:m().getElementById(t)||Q();var i;if(e.hasAttribute("data-fabric"))throw new Error("fabric.js: trying to initialize a canvas that has already been initialized");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:i}=t;const{el:s}=this.lower;s.classList.remove("lower-canvas"),s.removeAttribute("data-fabric"),s.setAttribute("width","".concat(e)),s.setAttribute("height","".concat(i)),s.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:i,ctx:s}=this.lower;Ut(i,s,t,e)}setCSSDimensions(t){Nt(this.lower.el,t)}calcOffset(){return function(t){var e;let i={left:0,top:0};const s=t&&Gt(t),r={left:0,top:0},n={borderLeftWidth:D,borderTopWidth:M,paddingLeft:D,paddingTop:M};if(!s)return r;const o=(null===(e=zt(t))||void 0===e?void 0:e.getComputedStyle(t,null))||{};for(const t in n)r[n[t]]+=parseInt(o[t],10)||0;const a=s.documentElement;void 0!==t.getBoundingClientRect&&(i=t.getBoundingClientRect());const h=Vt(t);return{left:i.left+h.left-(a.clientLeft||0)+r.left,top:i.top+h.top-(a.clientTop||0)+r.top}}(this.lower.el)}dispose(){p().dispose(this.lower.el),delete this.lower}}const Jt={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...w]};class Zt extends(U(N)){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 Zt.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.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new Kt(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];const r=super.insertAt(t,...i);return i.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),r}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(console.warn("fabric.Canvas: 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()}_isRetinaScaling(){return h.devicePixelRatio>1&&this.enableRetinaScaling}getRetinaScaling(){return this._isRetinaScaling()?Math.max(1,h.devicePixelRatio):1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.setDimensions({width:t},e)}setHeight(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e){const e=i({width:this.width,height:this.height},t);this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t){let{cssOnly:e=!1,backstoreOnly:i=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._setDimensionsImpl(t,{cssOnly:e,backstoreOnly:i}),e||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){const e=this.backgroundImage,i=this.overlayImage,s=this._objects.length;this.viewportTransform=t;for(let t=0;t<s;t++){const e=this._objects[t];e.group||e.setCoords()}e&&e.setCoords(),i&&i.setCoords(),this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const i=t,s=[...this.viewportTransform],r=rt(t,nt(s));s[0]=e,s[3]=e;const n=rt(r,s);s[4]+=i.x-n.x,s[5]+=i.y-n.y,this.setViewportTransform(s)}setZoom(t){this.zoomToPoint(new z(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 z(-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=q((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,i=nt(this.viewportTransform),s=rt({x:0,y:0},i),r=rt({x:t,y:e},i),n=s.min(r),o=s.max(r);return this.vptCoords={tl:n,tr:new z(o.x,n.y),bl:new z(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(K(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const i=this.viewportTransform,s=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(i[0],i[1],i[2],i[3],i[4],i[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.drawControls(t),s&&(s._set("canvas",this),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,s)),this._renderOverlay(t),this.controlsAboveOverlay&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const i=this.viewportTransform;t.save(),t.transform(...i),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let i=0,s=e.length;i<s;++i)e[i]&&e[i].render(t)}_renderBackgroundOrOverlay(t,e){const i=this["".concat(e,"Color")],s=this["".concat(e,"Image")],r=this.viewportTransform,n=this["".concat(e,"Vpt")];if(!i&&!s)return;const o=Lt(i);if(i){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?i.toLive(t):i,n&&t.transform(...r),o){t.transform(1,0,0,1,i.offsetX||0,i.offsetY||0);const e=i.gradientTransform||i.patternTransform;e&&t.transform(...e)}t.fill(),t.restore()}if(s){t.save();const{skipOffscreen:e}=this;this.skipOffscreen=n,n&&t.transform(...r),s.render(t),this.skipOffscreen=e,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new z(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new z(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new z(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 z(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new z(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return rt(this.getCenterPoint(),nt(this.viewportTransform))}_centerObject(t,e){t.setXY(e,k,k),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,r=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return i(i(i({version:y},xt(this,e)),{},{objects:this._objects.filter((t=>!t.excludeFromExport)).map((i=>this._toObject(i,t,e)))},this.__serializeBgOverlay(t,e)),r?{clipPath:r}:null)}_toObject(t,e,i){let s;this.includeDefaultValues||(s=t.includeDefaultValues,t.includeDefaultValues=!1);const r=t[e](i);return this.includeDefaultValues||(t.includeDefaultValues=!!s),r}__serializeBgOverlay(t,e){const i={},s=this.backgroundImage,r=this.overlayImage,n=this.backgroundColor,o=this.overlayColor;return Lt(n)?n.excludeFromExport||(i.background=n.toObject(e)):n&&(i.background=n),Lt(o)?o.excludeFromExport||(i.overlay=o.toObject(e)):o&&(i.overlay=o),s&&!s.excludeFromExport&&(i.backgroundImage=this._toObject(s,t,e)),r&&!r.excludeFromExport&&(i.overlayImage=this._toObject(r,t,e)),i}toSVG(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const i=[];return this._setSVGPreamble(i,t),this._setSVGHeader(i,t),this.clipPath&&i.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,')" >\n')),this._setSVGBgOverlayColor(i,"background"),this._setSVGBgOverlayImage(i,"backgroundImage",e),this._setSVGObjects(i,e),this.clipPath&&i.push("</g>\n"),this._setSVGBgOverlayColor(i,"overlay"),this._setSVGBgOverlayImage(i,"overlayImage",e),i.push("</svg>"),i.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",'" standalone="no" ?>\n','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ','"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')}_setSVGHeader(t,e){const i=e.width||"".concat(this.width),s=e.height||"".concat(this.height),r=h.NUM_FRACTION_DIGITS,n=e.viewBox;let o;if(n)o='viewBox="'.concat(n.x," ").concat(n.y," ").concat(n.width," ").concat(n.height,'" ');else if(this.svgViewportTransformation){const t=this.viewportTransform;o='viewBox="'.concat(Mt(-t[4]/t[0],r)," ").concat(Mt(-t[5]/t[3],r)," ").concat(Mt(this.width/t[0],r)," ").concat(Mt(this.height/t[3],r),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',i,'" ','height="',s,'" ',o,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",y,"</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(Z()),'<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(Lt(e)){const i=this["".concat(t,"Vpt")],s=this.viewportTransform,r={isType:()=>!1,width:this.width/(i?s[0]:1),height:this.height/(i?s[3]:1)};return e.toSVG(r,{additionalTransform:i?At(s):""})}})).join("")}createSVGFontFacesMarkup(){const t=[],e={},i=h.fontPaths;this._objects.forEach((function e(i){t.push(i),It(i)&&i._objects.forEach(e)})),t.forEach((t=>{if(!Xt(t))return;const{styles:s,fontFamily:r}=t;!e[r]&&i[r]&&(e[r]=!0,s&&Object.values(s).forEach((t=>{Object.values(t).forEach((t=>{let{fontFamily:s=""}=t;!e[s]&&i[s]&&(e[s]=!0)}))})))}));const s=Object.keys(e).map((t=>"\t\t@font-face {\n\t\t\tfont-family: '".concat(t,"';\n\t\t\tsrc: url('").concat(i[t],"');\n\t\t}\n"))).join("");return s?'\t<style type="text/css"><![CDATA[\n'.concat(s,"]]></style>\n"):""}_setSVGObjects(t,e){this.forEachObject((i=>{i.excludeFromExport||this._setSVGObject(t,i,e)}))}_setSVGObject(t,e,i){t.push(e.toSVG(i))}_setSVGBgOverlayImage(t,e,i){const s=this[e];s&&!s.excludeFromExport&&s.toSVG&&t.push(s.toSVG(i))}_setSVGBgOverlayColor(t,e){const i=this["".concat(e,"Color")];if(i)if(Lt(i)){const s=i.repeat||"",r=this.width,n=this.height,o=this["".concat(e,"Vpt")]?At(nt(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(r/2,",").concat(n/2,')" x="').concat(i.offsetX-r/2,'" y="').concat(i.offsetY-n/2,'" width="').concat("repeat-y"!==s&&"no-repeat"!==s||!Bt(i)?r:i.source.width,'" height="').concat("repeat-x"!==s&&"no-repeat"!==s||!Bt(i)?n:i.source.height,'" fill="url(#SVGID_').concat(i.id,')"></rect>\n'))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',i,'"',"></rect>\n")}loadFromJSON(t,e){let{signal:i}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return Promise.reject(new Error("fabric.js: `json` is undefined"));const s="string"==typeof t?JSON.parse(t):t,{objects:r=[],backgroundImage:n,background:o,overlayImage:a,overlay:h,clipPath:c}=s,l=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([_t(r,{reviver:e,signal:i}),yt({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:h,clipPath:c},{signal:i})]).then((t=>{let[e,i]=t;return this.clear(),this.add(...e),this.set(s),this.set(i),this.renderOnAddRemove=l,this}))}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=Q();return t.width=this.width,t.height=this.height,new this.constructor(t)}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{format:e="png",quality:i=1,multiplier:s=1,enableRetinaScaling:r=!1}=t,n=s*(r?this.getRetinaScaling():1);return tt(this.toCanvasElement(n,t),e,i)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,{width:e,height:i,left:s,top:r,filter:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=(e||this.width)*t,a=(i||this.height)*t,h=this.getZoom(),c=this.width,l=this.height,d=h*t,u=this.viewportTransform,g=[d,0,0,d,(u[4]-(s||0))*t,(u[5]-(r||0))*t],f=this.enableRetinaScaling,p=Q(),m=n?this._objects.filter((t=>n(t))):this._objects;return p.width=o,p.height=a,this.enableRetinaScaling=!1,this.viewportTransform=g,this.width=o,this.height=a,this.calcViewportBoundaries(),this.renderCanvas(p.getContext("2d"),m),this.viewportTransform=u,this.width=c,this.height=l,this.calcViewportBoundaries(),this.enableRetinaScaling=f,p}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),this.disposed=!0,new Promise(((t,e)=>{const i=()=>{this.destroy(),t(!0)};i.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=i:i()}))}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject((t=>t.dispose())),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}s(Zt,"ownDefaults",Jt);const Qt=["touchstart","touchmove","touchend"];const $t=t=>{const e=Vt(t.target),i=function(t){const e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new z(i.clientX+e.left,i.clientY+e.top)},te=t=>Qt.includes(t.type)||"touch"===t.pointerType,ee=t=>{t.preventDefault(),t.stopPropagation()},ie=t=>{if(0===t.length)return{left:0,top:0,width:0,height:0};const{min:e,max:i}=t.reduce(((t,e)=>{let{min:i,max:s}=t;return{min:i.min(e),max:s.max(e)}}),{min:new z(t[0]),max:new z(t[0])}),s=i.subtract(e);return{left:e.x,top:e.y,width:s.x,height:s.y}},se=["translateX","translateY","scaleX","scaleY"],re=(t,e)=>ne(t,ot(e,t.calcOwnMatrix())),ne=(t,e)=>{const i=ht(e),{translateX:s,translateY:n,scaleX:o,scaleY:a}=i,h=r(i,se),c=new z(s,n);t.flipX=!1,t.flipY=!1,Object.assign(t,h),t.set({scaleX:o,scaleY:a}),t.setPositionByOrigin(c,k,k)},oe=t=>{t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)},ae=t=>({scaleX:t.scaleX,scaleY:t.scaleY,skewX:t.skewX,skewY:t.skewY,angle:t.angle,left:t.left,flipX:t.flipX,flipY:t.flipY,top:t.top}),he=(t,e,i)=>{const s=t/2,r=e/2,n=pt(i),o=[new z(-s,-r),new z(s,-r),new z(-s,r),new z(s,r)].map((t=>t.transform(n))),a=ie(o);return new z(a.width,a.height)},ce=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:w;return ot(nt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:w),t)},le=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:w,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:w;return t.transform(ce(e,i))},de=(t,e,i)=>{const s=ce(e,i);return ne(t,ot(s,t.calcOwnMatrix())),s},ue=(t,e)=>{var s;const{transform:{target:r}}=e;null===(s=r.canvas)||void 0===s||s.fire("object:".concat(t),i(i({},e),{},{target:r})),r.fire(t,e)},ge={left:-.5,top:-.5,center:0,bottom:.5,right:.5},fe=t=>"string"==typeof t?ge[t]:t-.5,pe="not-allowed";function me(t){return t.originX===k&&t.originY===k}function ve(t){return.5-fe(t)}const _e=(t,e)=>t[e],ye=(t,e,i,s)=>({e:t,transform:e,pointer:new z(i,s)});function xe(t,e){const i=t.getTotalAngle()+it(Math.atan2(e.y,e.x))+360;return Math.round(i%360/45)}function Ce(t,e,i,s,r){var n;let{target:o,corner:a}=t;const h=o.controls[a],c=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/c,d=function(t,e,i,s){const r=t.getRelativeCenterPoint(),n=void 0!==i&&void 0!==s?t.translateToGivenOrigin(r,k,k,i,s):new z(t.left,t.top);return(t.angle?e.rotate(-et(t.angle),r):e).subtract(n)}(o,new z(s,r),e,i);return d.x>=l&&(d.x-=l),d.x<=-l&&(d.x+=l),d.y>=l&&(d.y-=l),d.y<=l&&(d.y+=l),d.x-=h.offsetX,d.y-=h.offsetY,d}const be=(t,e,i,s)=>{const{target:r,offsetX:n,offsetY:o}=e,a=i-n,h=s-o,c=!_e(r,"lockMovementX")&&r.left!==a,l=!_e(r,"lockMovementY")&&r.top!==h;return c&&r.set(D,a),l&&r.set(M,h),(c||l)&&ue("moving",ye(t,e,i,s)),c||l};class Se{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",i=this.strokeWidth?this.strokeWidth:"0",s=this.strokeDashArray?this.strokeDashArray.join(" "):A,r=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",h=void 0!==this.opacity?this.opacity:"1",c=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),d=jt("fill",this.fill);return[jt("stroke",this.stroke),"stroke-width: ",i,"; ","stroke-dasharray: ",s,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",d,"fill-rule: ",e,"; ","opacity: ",h,";",l,c].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const i=t?this.calcTransformMatrix():this.calcOwnMatrix(),s='transform="'.concat(At(i));return"".concat(s).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:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[this.getSvgTransform(!0,i),this.getSvgCommons()].join(""),r=t.indexOf("COMMON_PARTS");return t[r]=s,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:i,withShadow:s,additionalTransform:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=s?'style="'.concat(this.getSvgFilter(),'" '):"",a=this.clipPath,h=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",c=a&&a.absolutePositioned,l=this.stroke,d=this.fill,u=this.shadow,g=[],f=t.indexOf("COMMON_PARTS");let p;a&&(a.clipPathId="CLIPPATH_".concat(Z()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(i),"</clipPath>\n")),c&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),c?"":o+this.getSvgCommons()," >\n");const m=[n,h,e?"":this.addPaintOrder()," ",r?'transform="'.concat(r,'" '):""].join("");return t[f]=m,Lt(d)&&g.push(d.toSVG(this)),Lt(l)&&g.push(l.toSVG(this)),u&&g.push(u.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),c&&g.push("</g>\n"),i?i(g.join("")):g.join("")}addPaintOrder(){return"fill"!==this.paintFirst?' paint-order="'.concat(this.paintFirst,'" '):""}}const we=(t,e,i,s)=>(t<Math.abs(e)?(t=e,s=i/4):s=0===e&&0===t?i/b*Math.asin(1):i/b*Math.asin(e/t),{a:t,c:e,p:i,s:s}),Te=(t,e,i,s,r)=>t*Math.pow(2,10*(s-=1))*Math.sin((s*r-e)*b/i),Oe=(t,e,i,s)=>-i*Math.cos(t/s*C)+i+e,ke=(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,De=(t,e,i,s)=>i-ke(s-t,0,i,s)+e;var Me=Object.freeze({__proto__:null,defaultEasing:Oe,easeInBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},easeInBounce:De,easeInCirc:(t,e,i,s)=>-i*(Math.sqrt(1-(t/=s)*t)-1)+e,easeInCubic:(t,e,i,s)=>i*(t/s)**3+e,easeInElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(1===(t/=s))return e+i;n||(n=.3*s);const{a:o,s:a,p:h}=we(r,i,n,1.70158);return-Te(o,a,h,t,s)+e},easeInExpo:(t,e,i,s)=>0===t?e:i*2**(10*(t/s-1))+e,easeInOutBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInOutBounce:(t,e,i,s)=>t<s/2?.5*De(2*t,0,i,s)+e:.5*ke(2*t-s,0,i,s)+.5*i+e,easeInOutCirc:(t,e,i,s)=>(t/=s/2)<1?-i/2*(Math.sqrt(1-t**2)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e,easeInOutCubic:(t,e,i,s)=>(t/=s/2)<1?i/2*t**3+e:i/2*((t-2)**3+2)+e,easeInOutElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(2===(t/=s/2))return e+i;n||(n=s*(.3*1.5));const{a:o,s:a,p:h,c:c}=we(r,i,n,1.70158);return t<1?-.5*Te(o,a,h,t,s)+e:o*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*b/h)*.5+c+e},easeInOutExpo:(t,e,i,s)=>0===t?e:t===s?e+i:(t/=s/2)<1?i/2*2**(10*(t-1))+e:i/2*-(2**(-10*--t)+2)+e,easeInOutQuad:(t,e,i,s)=>(t/=s/2)<1?i/2*t**2+e:-i/2*(--t*(t-2)-1)+e,easeInOutQuart:(t,e,i,s)=>(t/=s/2)<1?i/2*t**4+e:-i/2*((t-=2)*t**3-2)+e,easeInOutQuint:(t,e,i,s)=>(t/=s/2)<1?i/2*t**5+e:i/2*((t-2)**5+2)+e,easeInOutSine:(t,e,i,s)=>-i/2*(Math.cos(Math.PI*t/s)-1)+e,easeInQuad:(t,e,i,s)=>i*(t/=s)*t+e,easeInQuart:(t,e,i,s)=>i*(t/=s)*t**3+e,easeInQuint:(t,e,i,s)=>i*(t/s)**5+e,easeInSine:(t,e,i,s)=>-i*Math.cos(t/s*C)+i+e,easeOutBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeOutBounce:ke,easeOutCirc:(t,e,i,s)=>i*Math.sqrt(1-(t=t/s-1)*t)+e,easeOutCubic:(t,e,i,s)=>i*((t/s-1)**3+1)+e,easeOutElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(1===(t/=s))return e+i;n||(n=.3*s);const{a:o,s:a,p:h,c:c}=we(r,i,n,1.70158);return o*2**(-10*t)*Math.sin((t*s-a)*b/h)+c+e},easeOutExpo:(t,e,i,s)=>t===s?e+i:i*-(2**(-10*t/s)+1)+e,easeOutQuad:(t,e,i,s)=>-i*(t/=s)*(t-2)+e,easeOutQuart:(t,e,i,s)=>-i*((t=t/s-1)*t**3-1)+e,easeOutQuint:(t,e,i,s)=>i*((t/s-1)**5+1)+e,easeOutSine:(t,e,i,s)=>i*Math.sin(t/s*C)+e});const Pe=()=>!1;class Ee{constructor(t){let{startValue:e,byValue:i,duration:r=500,delay:n=0,easing:o=Oe,onStart:a=x,onChange:h=x,onComplete:c=x,abort:l=Pe,target:d}=t;s(this,"_state","pending"),s(this,"durationProgress",0),s(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=r,this.delay=n,this.easing=o,this._onStart=a,this._onChange=h,this._onComplete=c,this._abort=l,this.target=d,this.startValue=e,this.byValue=i,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return"aborted"===this._state||"completed"===this._state}start(){const t=t=>{"pending"===this._state&&(this.startTime=t||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout((()=>q(t)),this.delay):q(t)}tick(t){const e=(t||+new Date)-this.startTime,i=Math.min(e,this.duration);this.durationProgress=i/this.duration;const{value:s,valueProgress:r}=this.calculate(i);this.value=Object.freeze(s),this.valueProgress=r,"aborted"!==this._state&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),q(this.tick)))}register(){B.push(this)}unregister(){B.remove(this)}abort(){this._state="aborted",this.unregister()}}const Ae=["startValue","endValue"];class je extends Ee{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(i(i({},r(t,Ae)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Fe=["startValue","endValue"];class Le extends Ee{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(i(i({},r(t,Fe)),{},{startValue:e,byValue:s.map(((t,i)=>t-e[i]))}))}calculate(t){const e=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i)));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const Re=(t,e,i)=>Math.max(t,Math.min(e,i)),Be=["startValue","endValue","easing","onChange","onComplete","abort"],Ie=(t,e,i,s)=>e+i*(1-Math.cos(t/s*C)),Xe=t=>t&&((e,i,s)=>t(new Dt(e).toRgba(),i,s));class Ye extends Ee{constructor(t){let{startValue:e,endValue:s,easing:n=Ie,onChange:o,onComplete:a,abort:h}=t,c=r(t,Be);const l=new Dt(e).getSource(),d=new Dt(s).getSource();super(i(i({},c),{},{startValue:l,byValue:d.map(((t,e)=>t-l[e])),easing:n,onChange:Xe(o),onComplete:Xe(a),abort:Xe(h)}))}calculate(t){const[e,i,s,r]=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i))),n=[...[e,i,s].map(Math.round),Re(0,r,1)];return{value:n,valueProgress:n.map(((t,e)=>0!==this.byValue[e]?Math.abs((t-this.startValue[e])/this.byValue[e]):0)).find((t=>0!==t))||0}}}const We=t=>Array.isArray(t.startValue)||Array.isArray(t.endValue);function Ve(t){const e=We(t)?new Le(t):new je(t);return e.start(),e}function Ge(t){const e=new Ye(t);return e.start(),e}const ze=new z(1,0),He=new z,Ue=(t,e)=>t.rotate(e),Ne=(t,e)=>new z(e).subtract(t),qe=t=>t.distanceFrom(He),Ke=(t,e)=>Math.atan2($e(t,e),ti(t,e)),Je=t=>Ke(ze,t),Ze=t=>t.eq(He)?t:t.scalarDivide(qe(t)),Qe=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return Ze(new z(-t.y,t.x).scalarMultiply(e?1:-1))},$e=(t,e)=>t.x*e.y-t.y*e.x,ti=(t,e)=>t.x*e.x+t.y*e.y,ei=(t,e,i)=>{if(t.eq(e)||t.eq(i))return!0;const s=$e(e,i),r=$e(e,t),n=$e(i,t);return s>=0?r>=0&&n<=0:!(r<=0&&n>=0)};class ii{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),i=0;i<t;i++)e[i]=arguments[i];return this.points=this.points.concat(e.filter((t=>!this.includes(t)))),this}static isPointContained(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e.eq(i))return t.eq(e);if(e.x===i.x)return t.x===e.x&&(s||t.y>=Math.min(e.y,i.y)&&t.y<=Math.max(e.y,i.y));if(e.y===i.y)return t.y===e.y&&(s||t.x>=Math.min(e.x,i.x)&&t.x<=Math.max(e.x,i.x));{const r=Ne(e,i),n=Ne(e,t).divide(r);return s?Math.abs(n.x)===Math.abs(n.y):n.x===n.y&&n.x>=0&&n.x<=1}}static intersectLineLine(t,e,i,s){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],n=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];const o=e.x-t.x,a=e.y-t.y,h=s.x-i.x,c=s.y-i.y,l=t.x-i.x,d=t.y-i.y,u=h*d-c*l,g=o*d-a*l,f=c*o-h*a;if(0!==f){const e=u/f,i=g/f;return(r||0<=e&&e<=1)&&(n||0<=i&&i<=1)?new ii("Intersection").append(new z(t.x+e*o,t.y+e*a)):new ii}if(0===u||0===g){const o=r||n||ii.isPointContained(t,i,s)||ii.isPointContained(e,i,s)||ii.isPointContained(i,t,e)||ii.isPointContained(s,t,e);return new ii(o?"Coincident":void 0)}return new ii("Parallel")}static intersectSegmentLine(t,e,i,s){return ii.intersectLineLine(t,e,i,s,!1,!0)}static intersectSegmentSegment(t,e,i,s){return ii.intersectLineLine(t,e,i,s,!1,!1)}static intersectLinePolygon(t,e,i){let s=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];const r=new ii,n=i.length;for(let o,a,h,c=0;c<n;c++){if(o=i[c],a=i[(c+1)%n],h=ii.intersectLineLine(t,e,o,a,s,!1),"Coincident"===h.status)return h;r.append(...h.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectSegmentPolygon(t,e,i){return ii.intersectLinePolygon(t,e,i,!1)}static intersectPolygonPolygon(t,e){const i=new ii,s=t.length,r=[];for(let n=0;n<s;n++){const o=t[n],a=t[(n+1)%s],h=ii.intersectSegmentPolygon(o,a,e);"Coincident"===h.status?(r.push(h),i.append(o,a)):i.append(...h.points)}return r.length>0&&r.length===t.length?new ii("Coincident"):(i.points.length>0&&(i.status="Intersection"),i)}static intersectPolygonRectangle(t,e,i){const s=e.min(i),r=e.max(i),n=new z(r.x,s.y),o=new z(s.x,r.y);return ii.intersectPolygonPolygon(t,[s,n,r,o])}}class si extends N{_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=i({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let r=s,n=0;this.strokeUniform&&(r=0,n=s);const o=e.width+r,a=e.height+r;let h;return h=0===e.skewX&&0===e.skewY?new z(o*e.scaleX,a*e.scaleY):he(o,a,e),h.scalarAdd(n)}translateToGivenOrigin(t,e,i,s,r){let n=t.x,o=t.y;const a=fe(s)-fe(e),h=fe(r)-fe(i);if(a||h){const t=this._getTransformedDimensions();n+=a*t.x,o+=h*t.y}return new z(n,o)}translateToCenterPoint(t,e,i){const s=this.translateToGivenOrigin(t,e,i,k,k);return this.angle?s.rotate(et(this.angle),t):s}translateToOriginPoint(t,e,i){const s=this.translateToGivenOrigin(t,k,k,e,i);return this.angle?s.rotate(et(this.angle),t):s}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?rt(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new z(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,i){const s=this.translateToCenterPoint(t,e,i),r=this.translateToOriginPoint(s,this.originX,this.originY);this.set({left:r.x,top:r.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),D,M)}}class ri extends si{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?rt(t,this.group.calcTransformMatrix()):t}setXY(t,e,i){this.group&&(t=rt(t,nt(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,i)}getRelativeXY(){return new z(this.left,this.top)}setRelativeXY(t,e,i){this.setPositionByOrigin(t,e||this.originX,i||this.originY)}_getCoords(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?t?this.calcACoords():this.calcLineCoords():(this.aCoords||(this.aCoords=this.calcACoords()),this.lineCoords||(this.lineCoords=this.calcLineCoords()),t?this.aCoords:this.lineCoords)}getCoords(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{tl:i,tr:s,br:r,bl:n}=this._getCoords(t,e),o=[i,s,r,n];if(this.group){const t=this.group.calcTransformMatrix();return o.map((e=>rt(e,t)))}return o}intersectsWithRect(t,e,i,s){const r=this.getCoords(i,s);return"Intersection"===ii.intersectPolygonRectangle(r,t,e).status}intersectsWithObject(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=ii.intersectPolygonPolygon(this.getCoords(e,i),t.getCoords(e,i));return"Intersection"===s.status||"Coincident"===s.status||t.isContainedWithinObject(this,e,i)||this.isContainedWithinObject(t,e,i)}isContainedWithinObject(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=this.getCoords(e,i),r=e?t.aCoords:t.lineCoords,n=t._getImageLines(r);for(let e=0;e<4;e++)if(!t.containsPoint(s[e],n))return!1;return!0}isContainedWithinRect(t,e,i,s){const r=this.getBoundingRect(i,s);return r.left>=t.x&&r.left+r.width<=e.x&&r.top>=t.y&&r.top+r.height<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=this._getCoords(i,s),n=e||this._getImageLines(r),o=this._findCrossPoints(t,n);return 0!==o&&o%2==1}isOnScreen(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!this.canvas)return!1;const{tl:e,br:i}=this.canvas.vptCoords;return!!this.getCoords(!0,t).some((t=>t.x<=i.x&&t.x>=e.x&&t.y<=i.y&&t.y>=e.y))||(!!this.intersectsWithRect(e,i,!0,t)||this._containsCenterOfCanvas(e,i,t))}_containsCenterOfCanvas(t,e,i){const s=t.midPointFrom(e);return this.containsPoint(s,void 0,!0,i)}isPartiallyOnScreen(t){if(!this.canvas)return!1;const{tl:e,br:i}=this.canvas.vptCoords;if(this.intersectsWithRect(e,i,!0,t))return!0;return this.getCoords(!0,t).every((t=>(t.x>=i.x||t.x<=e.x)&&(t.y>=i.y||t.y<=e.y)))&&this._containsCenterOfCanvas(e,i,t)}_getImageLines(t){let{tl:e,tr:i,bl:s,br:r}=t;return{topline:{o:e,d:i},rightline:{o:i,d:r},bottomline:{o:r,d:s},leftline:{o:s,d:e}}}_findCrossPoints(t,e){let i=0;for(const s in e){let r;const n=e[s];if(!(n.o.y<t.y&&n.d.y<t.y)&&!(n.o.y>=t.y&&n.d.y>=t.y)){if(n.o.x===n.d.x&&n.o.x>=t.x)r=n.o.x;else{const e=0,i=(n.d.y-n.o.y)/(n.d.x-n.o.x);r=-(t.y-e*t.x-(n.o.y-i*n.o.x))/(e-i)}if(r>=t.x&&(i+=1),2===i)break}}return i}getBoundingRect(t,e){return ie(this.getCoords(t,e))}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set("scaleX",t),this._set("scaleY",t),this.setCoords()}scaleToWidth(t,e){const i=this.getBoundingRect(e).width/this.getScaledWidth();return this.scale(t/this.width/i)}scaleToHeight(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.getBoundingRect(e).height/this.getScaledHeight();return this.scale(t/this.height/i)}getCanvasRetinaScaling(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?ht(this.calcTransformMatrix()).angle:this.angle}calcLineCoords(){const t=this.getViewportTransform(),e=this.padding,i=et(this.getTotalAngle()),s=V(i)*e,r=G(i)*e,n=s+r,o=s-r,{tl:a,tr:h,bl:c,br:l}=this.calcACoords(),d={tl:rt(a,t),tr:rt(h,t),bl:rt(c,t),br:rt(l,t)};return e&&(d.tl.x-=o,d.tl.y-=n,d.tr.x+=n,d.tr.y-=o,d.bl.x-=n,d.bl.y+=o,d.br.x+=o,d.br.y+=n),d}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||w.concat()}calcACoords(){const t=lt({angle:this.angle}),{x:e,y:i}=this.getRelativeCenterPoint(),s=ct(e,i),r=ot(s,t),n=this._getTransformedDimensions(),o=n.x/2,a=n.y/2;return{tl:rt({x:-o,y:-a},r),tr:rt({x:o,y:-a},r),bl:rt({x:-o,y:a},r),br:rt({x:o,y:a},r)}}setCoords(){this.aCoords=this.calcACoords(),this.lineCoords=this.group?this.aCoords:this.calcLineCoords()}transformMatrixKey(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e="_";let i="";return!t&&this.group&&(i=this.group.transformMatrixKey(t)+e),i+this.top+e+this.left+e+this.scaleX+e+this.scaleY+e+this.skewX+e+this.skewY+e+this.angle+e+this.originX+e+this.originY+e+this.width+e+this.height+e+this.strokeWidth+this.flipX+this.flipY}calcTransformMatrix(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const i=this.transformMatrixKey(t),s=this.matrixCache;return s&&s.key===i?s.value:(this.group&&(e=ot(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:i,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const i=this.getRelativeCenterPoint(),s={angle:this.angle,translateX:i.x,translateY:i.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},r=mt(s);return this.ownMatrixCache={key:t,value:r},r}_getNonTransformedDimensions(){return new z(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}}class ni extends ri{getParent(t){return((e=this.group)&&e.isType("ActiveSelection")?this.__owningGroup:this.group)||(t?void 0:this.canvas);var e}isDescendantOf(t){return this.__owningGroup===t||this.group===t||this.canvas===t||!!this.__owningGroup&&this.__owningGroup.isDescendantOf(t)||!!this.group&&this.group.isDescendantOf(t)}getAncestors(t){const e=[];let i=this;do{i=i instanceof ni?i.getParent(t):void 0,i&&e.push(i)}while(i);return e}findCommonAncestors(t,e){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors(e)]};const i=this.getAncestors(e),s=t.getAncestors(e);if(0===i.length&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let e,r=0;r<i.length;r++){if(e=i[r],e===t)return{fork:[this,...i.slice(0,r)],otherFork:[],common:i.slice(r)};for(let n=0;n<s.length;n++){if(this===s[n])return{fork:[],otherFork:[t,...s.slice(0,n)],common:[this,...i]};if(e===s[n])return{fork:[this,...i.slice(0,r)],otherFork:[t,...s.slice(0,n)],common:i.slice(r)}}}return{fork:[this,...i],otherFork:[t,...s],common:[]}}hasCommonAncestors(t,e){const i=this.findCommonAncestors(t,e);return i&&!!i.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(!e)return;if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const i=e.common[0];if(!i)return;const s=e.fork.pop(),r=e.otherFork.pop(),n=i._objects.indexOf(s),o=i._objects.indexOf(r);return n>-1&&n>o}}class oi extends ni{animate(t,e){return Object.entries(t).reduce(((t,i)=>{let[s,r]=i;return t[s]=this._animate(s,r,e),t}),{})}_animate(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=t.split("."),r=this.colorProperties.includes(s[s.length-1]),{easing:n,duration:o,abort:a,startValue:h,onChange:c,onComplete:l}=i,d={target:this,startValue:null!=h?h:s.reduce(((t,e)=>t[e]),this),endValue:e,easing:n,duration:o,abort:null==a?void 0:a.bind(this),onChange:(t,e,i)=>{s.reduce(((e,i,r)=>(r===s.length-1&&(e[i]=t),e[i])),this),c&&c(t,e,i)},onComplete:(t,e,i)=>{this.setCoords(),l&&l(t,e,i)}};return r?Ge(d):Ve(d)}}class ai{constructor(t){const e="string"==typeof t?ai.parseShadow(t):t;Object.assign(this,this.constructor.ownDefaults);for(const t in e)this[t]=e[t];this.id=Z()}static parseShadow(t){const e=t.trim(),[i,s=0,r=0,n=0]=(ai.reOffsetsAndBlur.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(ai.reOffsetsAndBlur,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:r,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Ue(new z(this.offsetX,this.offsetY),et(-t.angle)),i=new Dt(this.color);let s=40,r=40;return t.width&&t.height&&(s=100*Mt((Math.abs(e.x)+this.blur)/t.width,h.NUM_FRACTION_DIGITS)+20,r=100*Mt((Math.abs(e.y)+this.blur)/t.height,h.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(r,'%" height="').concat(100+2*r,'%" x="-').concat(s,'%" width="').concat(100+2*s,'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="').concat(Mt(this.blur?this.blur/2:0,h.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(Mt(e.x,h.NUM_FRACTION_DIGITS),'" dy="').concat(Mt(e.y,h.NUM_FRACTION_DIGITS),'" result="oBlur" ></feOffset>\n\t<feFlood flood-color="').concat(i.toRgb(),'" flood-opacity="').concat(i.getAlpha(),'"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n')}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling},e=ai.ownDefaults;return this.includeDefaultValues?t:Ct(t,((t,i)=>t!==e[i]))}}s(ai,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),s(ai,"reOffsetsAndBlur",/(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/);const hi=t=>JSON.parse(JSON.stringify(t)),ci=[M,D,"scaleX","scaleY","flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible","skewX","skewY"],li=["fill","stroke","strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],di={originX:D,originY:M,top:0,left:0,width:0,height:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1,opacity:1,angle:0,skewX:0,skewY:0,cornerSize:13,touchCornerSize:24,transparentCorners:!0,hoverCursor:null,moveCursor:null,padding:0,borderColor:"rgb(178,204,255)",borderDashArray:null,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,centeredScaling:!1,centeredRotation:!0,fill:"rgb(0,0,0)",fillRule:"nonzero",globalCompositeOperation:"source-over",backgroundColor:"",selectionBackgroundColor:"",stroke:null,strokeWidth:1,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,shadow:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,minScaleLimit:0,selectable:!0,evented:!0,visible:!0,hasControls:!0,hasBorders:!0,perPixelTargetFind:!1,includeDefaultValues:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,excludeFromExport:!1,objectCaching:!0,noScaleCache:!0,strokeUniform:!1,dirty:!0,paintFirst:"fill",activeOn:"down",colorProperties:["fill","stroke","backgroundColor"],clipPath:void 0,inverted:!1,absolutePositioned:!1,FX_DURATION:500},ui=["extraParam"];let gi=class t extends oi{static getDefaults(){return i({},t.ownDefaults)}get type(){const t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){console.warn("Setting type has no effect",t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(),s(this,"_cacheContext",null),Object.assign(this,this.constructor.getDefaults()),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=Q(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,i=t.height,s=h.maxCacheSideLimit,r=h.minCacheSideLimit;if(e<=s&&i<=s&&e*i<=h.perfLimitSizeTotal)return e<r&&(t.width=r),i<r&&(t.height=r),t;const n=e/i,[o,a]=_.limitDimsByArea(n),c=Re(r,o,s),l=Re(r,a,s);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),i>l&&(t.zoomY/=i/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),i=e.x*t.x/this.scaleX,s=e.y*t.y/this.scaleY;return{width:i+2,height:s+2,zoomX:t.x,zoomY:t.y,x:i,y:s}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,i=this._limitCacheSize(this._getCacheCanvasDimensions()),s=h.minCacheSideLimit,r=i.width,n=i.height,o=i.zoomX,a=i.zoomY,c=r!==this.cacheWidth||n!==this.cacheHeight,l=this.zoomX!==o||this.zoomY!==a;if(!t||!e)return!1;let d,u,g=c||l,f=0,p=0,m=!1;if(c){const t=this._cacheCanvas.width,e=this._cacheCanvas.height,o=r>t||n>e;m=o||(r<.9*t||n<.9*e)&&t>s&&e>s,o&&!i.capped&&(r>s||n>s)&&(f=.1*r,p=.1*n)}return Xt(this)&&this.path&&(g=!0,m=!0,f+=this.getHeightOfLine(0)*this.zoomX,p+=this.getHeightOfLine(0)*this.zoomY),!!g&&(m?(t.width=Math.ceil(r+f),t.height=Math.ceil(n+p)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=i.x/2,u=i.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-u)+u,this.cacheWidth=r,this.cacheHeight=n,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,a),this.zoomX=o,this.zoomY=a,!0)}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,i=this.calcTransformMatrix(!e);t.transform(i[0],i[1],i[2],i[3],i[4],i[5])}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=h.NUM_FRACTION_DIGITS,s=this.clipPath&&!this.clipPath.excludeFromExport?i(i({},this.clipPath.toObject(t)),{},{inverted:this.clipPath.inverted,absolutePositioned:this.clipPath.absolutePositioned}):null,r=i(i({},xt(this,t)),{},{type:this.constructor.type,version:y,originX:this.originX,originY:this.originY,left:Mt(this.left,e),top:Mt(this.top,e),width:Mt(this.width,e),height:Mt(this.height,e),fill:Rt(this.fill)?this.fill.toObject():this.fill,stroke:Rt(this.stroke)?this.stroke.toObject():this.stroke,strokeWidth:Mt(this.strokeWidth,e),strokeDashArray:this.strokeDashArray?this.strokeDashArray.concat():this.strokeDashArray,strokeLineCap:this.strokeLineCap,strokeDashOffset:this.strokeDashOffset,strokeLineJoin:this.strokeLineJoin,strokeUniform:this.strokeUniform,strokeMiterLimit:Mt(this.strokeMiterLimit,e),scaleX:Mt(this.scaleX,e),scaleY:Mt(this.scaleY,e),angle:Mt(this.angle,e),flipX:this.flipX,flipY:this.flipY,opacity:Mt(this.opacity,e),shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible,backgroundColor:this.backgroundColor,fillRule:this.fillRule,paintFirst:this.paintFirst,globalCompositeOperation:this.globalCompositeOperation,skewX:Mt(this.skewX,e),skewY:Mt(this.skewY,e)},s?{clipPath:s}:null);return this.includeDefaultValues?r:this._removeDefaultValues(r)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),i=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Ct(t,((t,e)=>{if(e===D||e===M||"type"===e)return!0;const s=i[e];return t!==s&&!(Array.isArray(t)&&Array.isArray(s)&&0===t.length&&0===s.length)}))}toString(){return"#<".concat(this.constructor.type,">")}getObjectScaling(){if(!this.group)return new z(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=ht(this.calcTransformMatrix());return new z(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),i=this.getCanvasRetinaScaling();return t.scalarMultiply(e*i)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:0===t?1e-4:t}_set(t,e){const i=this[t]!==e;if("scaleX"!==t&&"scaleY"!==t||(e=this._constrainScale(e)),"scaleX"===t&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof ai?"dirty"===t&&this.group&&this.group.set("dirty",e):e=new ai(e),this[t]=e,i){const e=this.group&&this.group.isOnACache();this.constructor.cacheProperties.includes(t)?(this.dirty=!0,e&&this.group.set("dirty",!0)):e&&this.constructor.stateProperties.includes(t)&&this.group.set("dirty",!0)}return 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),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null,this.cacheWidth=0,this.cacheHeight=0}hasStroke(){return this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth}hasFill(){return this.fill&&"transparent"!==this.fill}needsItsOwnCache(){return!("stroke"!==this.paintFirst||!this.hasFill()||!this.hasStroke()||"object"!=typeof this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.group||!this.group.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const e=nt(this.calcTransformMatrix());t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const i=this.fill,s=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=i,this.stroke=s}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}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;if(this._cacheCanvas&&this._cacheContext&&!t&&this._updateCacheCanvas())return!0;if(this.dirty||this.clipPath&&this.clipPath.absolutePositioned){if(this._cacheCanvas&&this._cacheContext&&!t){const t=this.cacheWidth/this.zoomX,e=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-t/2,-e/2,t,e)}return!0}return!1}_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 i=e.stroke;i&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,Lt(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?this._applyPatternForTransformedGradient(t,i):(t.strokeStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:i}=e;i&&(Lt(i)?(t.fillStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.fillStyle=i)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&0!==e.length&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,i=this.canvas,s=this.getCanvasRetinaScaling(),[r,,,n]=(null==i?void 0:i.viewportTransform)||w,o=r*s,a=n*s,c=e.nonScaling?new z(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*h.browserShadowBlurConstant*(o+a)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*a*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!Lt(e))return{offsetX:0,offsetY:0};const i=e.gradientTransform||e.patternTransform,s=-this.width/2+e.offsetX||0,r=-this.height/2+e.offsetY||0;return"percentage"===e.gradientUnits?t.transform(this.width,0,0,this.height,s,r):t.transform(1,0,0,1,s,r),i&&t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),{offsetX:s,offsetY:r}}_renderPaintInOrder(t){"stroke"===this.paintFirst?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),"evenodd"===this.fillRule?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&0!==this.strokeWidth){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){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 i;const s=this._limitCacheSize(this._getCacheCanvasDimensions()),r=Q(),n=this.getCanvasRetinaScaling(),o=s.x/this.scaleX/n,a=s.y/this.scaleY/n;r.width=Math.ceil(o),r.height=Math.ceil(a);const h=r.getContext("2d");h&&(h.beginPath(),h.moveTo(0,0),h.lineTo(o,0),h.lineTo(o,a),h.lineTo(0,a),h.closePath(),h.translate(o/2,a/2),h.scale(s.zoomX/this.scaleX/n,s.zoomY/this.scaleY/n),this._applyPatternGradientTransform(h,e),h.fillStyle=e.toLive(t),h.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/s.zoomX,n*this.scaleY/s.zoomY),t.strokeStyle=null!==(i=h.createPattern(r,"no-repeat"))&&void 0!==i?i:"")}_findCenterFromElement(){return new z(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(R.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=ae(this),i=this.group,s=this.shadow,r=Math.abs,n=t.enableRetinaScaling?Math.max(h.devicePixelRatio,1):1,o=(t.multiplier||1)*n;delete this.group,t.withoutTransform&&oe(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&de(this,this.getViewportTransform());const a=Q(),c=this.getBoundingRect(!0,!0),l=this.shadow,d=new z;if(l){const t=l.blur,e=l.nonScaling?new z(1,1):this.getObjectScaling();d.x=2*Math.round(r(l.offsetX)+t)*r(e.x),d.y=2*Math.round(r(l.offsetY)+t)*r(e.y)}const u=c.width+d.x,g=c.height+d.y;a.width=Math.ceil(u),a.height=Math.ceil(g);const f=new Zt(a,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1});"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new z(f.width/2,f.height/2),k,k);const p=this.canvas;f._objects=[this],this.set("canvas",f),this.setCoords();const m=f.toCanvasElement(o||1,t);return this.set("canvas",p),this.shadow=s,i&&(this.group=i),this.set(e),this.setCoords(),f._objects=[],f.destroy(),m}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return tt(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:i,originY:s}=this;if(e){const{x:t,y:e}=this.getRelativeCenterPoint();this.originX=k,this.originY=k,this.left=t,this.top=e}if(this.set("angle",t),e){const{x:t,y:e}=this.translateToOriginPoint(this.getRelativeCenterPoint(),i,s);this.left=t,this.top=e,this.originX=i,this.originY=s}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){B.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&p().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}static _fromObject(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:s}=e,n=r(e,ui);return yt(hi(t),n).then((t=>{const e=i(i({},n),t);if(s){const{[s]:t,type:i}=e;return new this(t,r(e,[s,"type"].map(o)))}return new this(e)}))}static fromObject(t,e){return this._fromObject(t,e)}};s(gi,"stateProperties",ci),s(gi,"cacheProperties",li),s(gi,"ownDefaults",di),s(gi,"type","FabricObject"),R.setClass(gi),R.setClass(gi,"object");const fi=(t,e)=>(i,s,r,n)=>{const o=e(i,s,r,n);return o&&ue(t,ye(i,s,r,n)),o};function pi(t){return(e,i,s,r)=>{const{target:n,originX:o,originY:a}=i,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,o,a),l=t(e,i,s,r);return n.setPositionByOrigin(c,i.originX,i.originY),l}}const mi=fi("resizing",pi(((t,e,i,s)=>{const r=Ce(e,e.originX,e.originY,i,s);if(e.originX===k||e.originX===E&&r.x<0||e.originX===D&&r.x>0){const{target:t}=e,i=t.strokeWidth/(t.strokeUniform?t.scaleX:1),s=me(e)?2:1,n=t.width,o=Math.ceil(Math.abs(r.x*s/t.scaleX)-i);return t.set("width",Math.max(o,0)),n!==t.width}return!1})));function vi(t,e,i,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,h=a?"stroke":"fill",c=!a&&(s.cornerStrokeColor||r.cornerStrokeColor);let l,d=e,u=i;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,t.scale(1,o/n),u=i*n/o):o>n?(l=o,t.scale(n/o,1),d=e*o/n):l=n,t.lineWidth=1,t.beginPath(),t.arc(d,u,l/2,0,b,!1),t[h](),c&&t.stroke(),t.restore()}function _i(t,e,i,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,h=a?"stroke":"fill",c=!a&&(s.cornerStrokeColor||r.cornerStrokeColor),l=n/2,d=o/2;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",t.lineWidth=1,t.translate(e,i);const u=r.getTotalAngle();t.rotate(et(u)),t["".concat(h,"Rect")](-l,-d,n,o),c&&t.strokeRect(-l,-d,n,o),t.restore()}class yi{constructor(t){s(this,"visible",!0),s(this,"actionName","scale"),s(this,"angle",0),s(this,"x",0),s(this,"y",0),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"sizeX",null),s(this,"sizeY",null),s(this,"touchSizeX",null),s(this,"touchSizeY",null),s(this,"cursorStyle","crosshair"),s(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e){var i;return(null===(i=e.canvas)||void 0===i?void 0:i.getActiveObject())===e&&e.isControlVisible(t)}getActionHandler(t,e,i){return this.actionHandler}getMouseDownHandler(t,e,i){return this.mouseDownHandler}getMouseUpHandler(t,e,i){return this.mouseUpHandler}cursorStyleHandler(t,e,i){return e.cursorStyle}getActionName(t,e,i){return e.actionName}getVisibility(t,e){var i,s;return null!==(i=null===(s=t._controlsVisibility)||void 0===s?void 0:s[e])&&void 0!==i?i:this.visible}setVisibility(t,e,i){this.visible=t}positionHandler(t,e,i,s){return new z(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,i,s,r){let n,o,a,h;const c=r?this.touchSizeX:this.sizeX,l=r?this.touchSizeY:this.sizeY;if(c&&l&&c!==l){const e=Math.atan2(l,c),i=Math.sqrt(c*c+l*l)/2,s=e-et(t),r=C-e-et(t);n=i*V(s),o=i*G(s),a=i*V(r),h=i*G(r)}else{const i=(c&&l?c:e)*Math.SQRT1_2,s=et(45-t);n=a=i*V(s),o=h=i*G(s)}return{tl:new z(i-h,s-a),tr:new z(i+n,s-o),bl:new z(i-n,s+o),br:new z(i+h,s+a)}}render(t,e,i,s,r){if("circle"===((s=s||{}).cornerStyle||r.cornerStyle))vi.call(this,t,e,i,s,r);else _i.call(this,t,e,i,s,r)}}const xi=(t,e,i)=>i.lockRotation?pe:e.cursorStyle,Ci=fi("rotating",pi(((t,e,i,s)=>{let{target:r,ex:n,ey:o,theta:a,originX:h,originY:c}=e;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),h,c);if(_e(r,"lockRotation"))return!1;const d=Math.atan2(o-l.y,n-l.x),u=Math.atan2(s-l.y,i-l.x);let g=it(u-d+a);if(r.snapAngle&&r.snapAngle>0){const t=r.snapAngle,e=r.snapThreshold||t,i=Math.ceil(g/t)*t,s=Math.floor(g/t)*t;Math.abs(g-s)<e?g=s:Math.abs(g-i)<e&&(g=i)}g<0&&(g=360+g),g%=360;const f=r.angle!==g;return r.angle=g,f})));function bi(t,e){const i=e.canvas,s=t[i.uniScaleKey];return i.uniformScaling&&!s||!i.uniformScaling&&s}function Si(t,e,i){const s=_e(t,"lockScalingX"),r=_e(t,"lockScalingY");return!(!s||!r)||(!(e||!s&&!r||!i)||(!(!s||"x"!==e)||!(!r||"y"!==e)))}const wi=["e","se","s","sw","w","nw","n","ne","e"],Ti=(t,e,i)=>{const s=bi(t,i);if(Si(i,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",s))return pe;const r=xe(i,e);return"".concat(wi[r],"-resize")};function Oi(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=r.by,a=bi(t,n);let h,c,l,d,u,g;if(Si(n,o,a))return!1;if(e.gestureScale)c=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(h=Ce(e,e.originX,e.originY,i,s),u="y"!==o?Math.sign(h.x||e.signX||1):1,g="x"!==o?Math.sign(h.y||e.signY||1):1,e.signX||(e.signX=u),e.signY||(e.signY=g),_e(n,"lockScalingFlip")&&(e.signX!==u||e.signY!==g))return!1;if(d=n._getTransformedDimensions(),a&&!o){const t=Math.abs(h.x)+Math.abs(h.y),{original:i}=e,s=t/(Math.abs(d.x*i.scaleX/n.scaleX)+Math.abs(d.y*i.scaleY/n.scaleY));c=i.scaleX*s,l=i.scaleY*s}else c=Math.abs(h.x*n.scaleX/d.x),l=Math.abs(h.y*n.scaleY/d.y);me(e)&&(c*=2,l*=2),e.signX!==u&&"y"!==o&&(e.originX=ve(e.originX),c*=-1,e.signX=u),e.signY!==g&&"x"!==o&&(e.originY=ve(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set("scaleX",c),"y"===o&&n.set("scaleY",l)):(!_e(n,"lockScalingX")&&n.set("scaleX",c),!_e(n,"lockScalingY")&&n.set("scaleY",l)),f!==n.scaleX||p!==n.scaleY}const ki=fi("scaling",pi(((t,e,i,s)=>Oi(t,e,i,s)))),Di=fi("scaling",pi(((t,e,i,s)=>Oi(t,e,i,s,{by:"x"})))),Mi=fi("scaling",pi(((t,e,i,s)=>Oi(t,e,i,s,{by:"y"})))),Pi=["target","ex","ey","skewingSide"],Ei={x:{counterAxis:"y",scale:"scaleX",skew:"skewX",lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:"scaleY",skew:"skewY",lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},Ai=["ns","nesw","ew","nwse"],ji=(t,e,i)=>{if(0!==e.x&&_e(i,"lockSkewingY"))return pe;if(0!==e.y&&_e(i,"lockSkewingX"))return pe;const s=xe(i,e)%4;return"".concat(Ai[s],"-resize")};function Fi(t,e,s,n,o){const{target:a}=s,{counterAxis:h,origin:c,lockSkewing:l,skew:d,flip:u}=Ei[t];if(_e(a,l))return!1;const{origin:g,flip:f}=Ei[h],p=fe(s[g])*(a[f]?-1:1),m=-Math.sign(p)*(a[u]?-1:1),v=.5*-((0===a[d]&&Ce(s,k,k,n,o)[t]>0||a[d]>0?1:-1)*m)+.5,_=fi("skewing",pi(((e,i,s,n)=>function(t,e,i){let{target:s,ex:n,ey:o,skewingSide:a}=e,h=r(e,Pi);const{skew:c}=Ei[t],l=i.subtract(new z(n,o)).divide(new z(s.scaleX,s.scaleY))[t],d=s[c],u=h[c],g=Math.tan(et(u)),f="y"===t?s._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:s._getTransformedDimensions({scaleX:1,scaleY:1}).y,p=2*l*a/Math.max(f,1)+g,m=it(Math.atan(p));s.set(c,m);const v=d!==s[c];if(v&&"y"===t){const{skewX:t,scaleX:e}=s,i=s._getTransformedDimensions({skewY:d}),r=s._getTransformedDimensions(),n=0!==t?i.x/r.x:1;1!==n&&s.set("scaleX",n*e)}return v}(t,i,new z(s,n)))));return _(e,i(i({},s),{},{[c]:v,skewingSide:m}),n,o)}const Li=(t,e,i,s)=>Fi("x",t,e,i,s),Ri=(t,e,i,s)=>Fi("y",t,e,i,s);function Bi(t,e){return t[e.canvas.altActionKey]}const Ii=(t,e,i)=>{const s=Bi(t,i);return 0===e.x?s?"skewX":"scaleY":0===e.y?s?"skewY":"scaleX":""},Xi=(t,e,i)=>Bi(t,i)?ji(0,e,i):Ti(t,e,i),Yi=(t,e,i,s)=>Bi(t,e.target)?Ri(t,e,i,s):Di(t,e,i,s),Wi=(t,e,i,s)=>Bi(t,e.target)?Li(t,e,i,s):Mi(t,e,i,s),Vi=()=>({ml:new yi({x:-.5,y:0,cursorStyleHandler:Xi,actionHandler:Yi,getActionName:Ii}),mr:new yi({x:.5,y:0,cursorStyleHandler:Xi,actionHandler:Yi,getActionName:Ii}),mb:new yi({x:0,y:.5,cursorStyleHandler:Xi,actionHandler:Wi,getActionName:Ii}),mt:new yi({x:0,y:-.5,cursorStyleHandler:Xi,actionHandler:Wi,getActionName:Ii}),tl:new yi({x:-.5,y:-.5,cursorStyleHandler:Ti,actionHandler:ki}),tr:new yi({x:.5,y:-.5,cursorStyleHandler:Ti,actionHandler:ki}),bl:new yi({x:-.5,y:.5,cursorStyleHandler:Ti,actionHandler:ki}),br:new yi({x:.5,y:.5,cursorStyleHandler:Ti,actionHandler:ki}),mtr:new yi({x:0,y:-.5,actionHandler:Ci,cursorStyleHandler:xi,offsetY:-40,withConnection:!0,actionName:"rotate"})}),Gi=()=>({mr:new yi({x:.5,y:0,actionHandler:mi,cursorStyleHandler:Xi,actionName:"resizing"}),ml:new yi({x:-.5,y:0,actionHandler:mi,cursorStyleHandler:Xi,actionName:"resizing"})}),zi=()=>i(i({},Vi()),Gi());class Hi extends gi{static getDefaults(){return i(i({},super.getDefaults()),{},{controls:Vi()},Hi.ownDefaults)}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform.target,i=t._currentTransform.action;if(this===e&&i.startsWith("scale"))return!1}return super._updateCacheCanvas()}getActiveControl(){return this.__corner}_findTargetCorner(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasControls||!this.canvas)return"";this.__corner=void 0;const i=Object.entries(this.oCoords);for(let s=i.length-1;s>=0;s--){const[r,n]=i[s];if(this.controls[r].shouldActivate(r,this)){const i=this._getImageLines(e?n.touchCorner:n.corner),s=this._findCrossPoints(t,i);if(0!==s&&s%2==1)return this.__corner=r,r}}return""}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),i=ct(e.x,e.y),s=lt({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),r=ot(i,s),n=ot(t,r),o=ot(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?ht(this.calcTransformMatrix()):void 0,h=this._calculateCurrentDimensions(a),c={};return this.forEachControl(((t,e)=>{const i=t.positionHandler(h,o,this,t);c[e]=Object.assign(i,this._calcCornerCoords(t,i))})),c}_calcCornerCoords(t,e){return{corner:t.calcCornerCoords(this.angle,this.cornerSize,e.x,e.y,!1),touchCorner:t.calcCornerCoords(this.angle,this.touchCornerSize,e.x,e.y,!0)}}setCoords(){super.setCoords(),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(),i=this._calculateCurrentDimensions(),s=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/s[0],1/s[3]),t.rotate(et(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-i.x/2,-i.y/2,i.x,i.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=i({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=r.borderColor,this._setLineDash(t,r.borderDashArray),this.strokeBorders(t,e),r.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{hasBorders:s,hasControls:r}=this,n=i({hasBorders:s,hasControls:r},e),o=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,c=ot(o,this.calcTransformMatrix()),l=ht(c);t.save(),t.translate(l.translateX,l.translateY),t.lineWidth=1*this.borderScaleFactor,this.group||(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(l.angle-=180),t.rotate(et(this.group?l.angle:this.angle)),a&&this.drawBorders(t,l,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,i){let s;if(i&&i.forActiveSelection||this.group){const t=he(this.width,this.height,e),i=(this.strokeUniform?(new z).scalarAdd(this.canvas?this.canvas.getZoom():1):new z(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);s=t.add(i).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else s=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,s,i)}drawControlsConnectingLines(t,e){let i=!1;t.beginPath(),this.forEachControl(((s,r)=>{s.withConnection&&s.getVisibility(this,r)&&(i=!0,t.moveTo(s.x*e.x,s.y*e.y),t.lineTo(s.x*e.x+s.offsetX,s.y*e.y+s.offsetY))})),i&&t.stroke()}drawControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:r,cornerDashArray:n,cornerColor:o}=this,a=i({cornerStrokeColor:r,cornerDashArray:n,cornerColor:o},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.setCoords(),this.forEachControl(((e,i)=>{if(e.getVisibility(this,i)){const s=this.oCoords[i];e.render(t,s.x,s.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,i]=t;return this.setControlVisible(e,i)}))}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const i=this.canvas.viewportTransform;e.save(),e.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this.transform(e);const s=this.width+4,r=this.height+4;return e.clearRect(-s/2,-r/2,s,r),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Ui(t,e){return e.forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i)||Object.create(null))}))})),t}s(Hi,"ownDefaults",{});class Ni extends Hi{}Ui(Ni,[Se]),R.setClass(Ni),R.setClass(Ni,"object");const qi=(t,e,i,s)=>{const r=2*(s=Math.round(s))+1,{data:n}=t.getImageData(e-s,i-s,r,r);for(let t=3;t<n.length;t+=4){if(n[t]>0)return!1}return!0},Ki=["display","transform","fill","fill-opacity","fill-rule","opacity","stroke","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 Ji(t){return new RegExp("^("+t.join("|")+")\\b","i")}var Zi,Qi;const $i=String.raw(Zi||(Zi=n(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),ts="http://www.w3.org/2000/svg";String.raw(Qi||(Qi=n(["(?:s+,?s*|,s*|$)"],["(?:\\s+,?\\s*|,\\s*|$)"])));const es=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+$i+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+$i+"))?\\s+(.*)"),is={cx:D,x:D,r:"radius",cy:M,y:M,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"},ss="font-size",rs="clip-path",ns=Ji(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),os=Ji(["symbol","image","marker","pattern","view","svg"]),as=Ji(["symbol","g","a","svg","clipPath","defs"]),hs=new RegExp("^\\s*("+$i+"+)\\s*,?\\s*("+$i+"+)\\s*,?\\s*("+$i+"+)\\s*,?\\s*("+$i+"+)\\s*$");function cs(t,e){const i=t.nodeName,s=t.getAttribute("class"),r=t.getAttribute("id");let n;if(n=new RegExp("^"+i,"i"),e=e.replace(n,""),r&&e.length&&(n=new RegExp("#"+r+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")),s&&e.length){const t=s.split(" ");for(let i=t.length;i--;)n=new RegExp("\\."+t[i]+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")}return 0===e.length}function ls(t,e){let i=!0;const s=cs(t,e.pop());return s&&e.length&&(i=function(t,e){let i,s=!0;for(;t.parentElement&&1===t.parentElement.nodeType&&e.length;)s&&(i=e.pop()),s=cs(t=t.parentElement,i);return 0===e.length}(t,e)),s&&i&&0===e.length}const ds=t=>{var e;return null!==(e=is[t])&&void 0!==e?e:t},us=t=>t.replace(new RegExp("(".concat($i,")"),"gi")," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var gs,fs,ps,ms,vs,_s,ys;const xs="(".concat($i,")"),Cs=String.raw(gs||(gs=n(["(skewX)(",")"],["(skewX)\\(","\\)"])),xs),bs=String.raw(fs||(fs=n(["(skewY)(",")"],["(skewY)\\(","\\)"])),xs),Ss=String.raw(ps||(ps=n(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),xs,xs,xs),ws=String.raw(ms||(ms=n(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),xs,xs),Ts=String.raw(vs||(vs=n(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),xs,xs),Os=String.raw(_s||(_s=n(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),xs,xs,xs,xs,xs,xs),ks="(?:".concat(Os,"|").concat(Ts,"|").concat(Ss,"|").concat(ws,"|").concat(Cs,"|").concat(bs,")"),Ds="(?:".concat(ks,"*)"),Ms=String.raw(ys||(ys=n(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Ds),Ps=new RegExp(Ms),Es=new RegExp(ks,"g");function As(t){const e=[];if(!(t=us(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!Ps.test(t))return[...w];for(const i of t.matchAll(Es)){const t=new RegExp(ks).exec(i[0]);if(!t)continue;let s=w;const r=t.filter((t=>!!t)),[,n,...o]=r,[a,h,c,l,d,u]=o.map((t=>parseFloat(t)));switch(n){case"translate":s=ct(a,h);break;case"rotate":s=lt({angle:a},{x:h,y:c});break;case"scale":s=dt(a,h);break;case"skewX":s=gt(a);break;case"skewY":s=ft(a);break;case"matrix":s=[a,h,c,l,d,u]}e.push(s)}return at(e)}function js(t,e,i,s){const r=Array.isArray(e);let n,o=e;if("fill"!==t&&"stroke"!==t||e!==A){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)o=e===A?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)o=i&&i.transformMatrix?ot(i.transformMatrix,As(e)):As(e);else if("visible"===t)o=e!==A&&"hidden"!==e,i&&!1===i.visible&&(o=!1);else if("opacity"===t)o=parseFloat(e),i&&void 0!==i.opacity&&(o*=i.opacity);else if("textAnchor"===t)o="start"===e?D:"end"===e?E:k;else if("charSpacing"===t)n=Pt(e,s)/s*1e3;else if("paintFirst"===t){const t=e.indexOf("fill"),i=e.indexOf("stroke");o="fill",(t>-1&&i>-1&&i<t||-1===t&&i>-1)&&(o="stroke")}else{if("href"===t||"xlink:href"===t||"font"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=r?e.map(Pt):Pt(e,s)}}else o="";return!r&&isNaN(n)?o:n}function Fs(t,e){const i=t.match(es);if(!i)return;const s=i[1],r=i[3],n=i[4],o=i[5],a=i[6];s&&(e.fontStyle=s),r&&(e.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),n&&(e.fontSize=Pt(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}function Ls(t){const e={},i=t.getAttribute("style");return i?("string"==typeof i?function(t,e){t.replace(/;\s*$/,"").split(";").forEach((t=>{const[i,s]=t.split(":");e[i.trim().toLowerCase()]=s.trim()}))}(i,e):function(t,e){Object.entries(t).forEach((t=>{let[i,s]=t;void 0!==s&&(e[i.toLowerCase()]=s)}))}(i,e),e):e}const Rs={stroke:"strokeOpacity",fill:"fillOpacity"};function Bs(t,e,s){if(!t)return{};let r,n={},o=T;t.parentNode&&as.test(t.parentNode.nodeName)&&(n=Bs(t.parentElement,e,s),n.fontSize&&(r=o=Pt(n.fontSize)));const a=i(i(i({},e.reduce(((e,i)=>{const s=t.getAttribute(i);return s&&(e[i]=s),e}),{})),function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s={};for(const r in e)ls(t,r.split(" "))&&(s=i(i({},s),e[r]));return s}(t,s)),Ls(t));a[rs]&&t.setAttribute(rs,a[rs]),a[ss]&&(r=Pt(a[ss],o),a[ss]="".concat(r));const h={};for(const t in a){const e=ds(t),i=js(e,a[t],n,r);h[e]=i}h&&h.font&&Fs(h.font,h);const c=i(i({},n),h);return as.test(t.nodeName)?c:function(t){const e=Ni.getDefaults();return Object.entries(Rs).forEach((i=>{let[s,r]=i;if(void 0===t[r]||""===t[s])return;if(void 0===t[s]){if(!e[s])return;t[s]=e[s]}if(0===t[s].indexOf("url("))return;const n=new Dt(t[s]);t[s]=n.setAlpha(Mt(n.getAlpha()*t[r],2)).toRgba()})),t}(c)}const Is=["left","top","width","height","visible"],Xs=["rx","ry"];class Ys extends Ni{static getDefaults(){return i(i({},super.getDefaults()),Ys.ownDefaults)}constructor(t){super(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:i}=this,s=-e/2,r=-i/2,n=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,i/2):0,a=0!==n||0!==o;t.beginPath(),t.moveTo(s+n,r),t.lineTo(s+e-n,r),a&&t.bezierCurveTo(s+e-O*n,r,s+e,r+O*o,s+e,r+o),t.lineTo(s+e,r+i-o),a&&t.bezierCurveTo(s+e,r+i-O*o,s+e-O*n,r+i,s+e-n,r+i),t.lineTo(s+n,r+i),a&&t.bezierCurveTo(s+O*n,r+i,s,r+i-O*o,s,r+i-o),t.lineTo(s,r+o),a&&t.bezierCurveTo(s,r+O*o,s+O*n,r,s+n,r),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Xs,...t])}_toSVG(){const{width:t,height:e,rx:i,ry:s}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(i,'" ry="').concat(s,'" width="').concat(t,'" height="').concat(e,'" />\n')]}static async fromElement(t,e,s){const n=Bs(t,this.ATTRIBUTE_NAMES,s),{left:o=0,top:a=0,width:h=0,height:c=0,visible:l=!0}=n,d=r(n,Is);return new this(i(i(i({},e),d),{},{left:o,top:a,width:h,height:c,visible:Boolean(l&&h&&c)}))}}s(Ys,"type","Rect"),s(Ys,"cacheProperties",[...li,...Xs]),s(Ys,"ownDefaults",{rx:0,ry:0}),s(Ys,"ATTRIBUTE_NAMES",[...Ki,"x","y","rx","ry","width","height"]),R.setClass(Ys),R.setSVGClass(Ys);const Ws=["objects"];class Vs extends(U(Ni)){static getDefaults(){return i(i({},super.getDefaults()),Vs.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;super(),s(this,"_activeObjects",[]),s(this,"__objectSelectionTracker",void 0),s(this,"__objectSelectionDisposer",void 0),s(this,"_firstLayoutDone",!1),this._objects=t.slice(),this.__objectMonitor=this.__objectMonitor.bind(this),this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.set(i(i({},e),{},{angle:0,skewX:0,skewY:0})),this.forEachObject((t=>{this.enterGroup(t,!1)})),this._applyLayoutStrategy({type:"initialization",options:e,objectsRelativeToGroup:r})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(console.error("fabric.Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(console.error("fabric.Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter(((t,e,i)=>this.canEnterGroup(t)&&i.indexOf(t)===e))}add(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];const s=this._filterObjectsBeforeEnteringGroup(e),r=super.add(...s);return this._onAfterObjectsChange("added",s),r}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];const r=this._filterObjectsBeforeEnteringGroup(i),n=super.insertAt(t,...r);return this._onAfterObjectsChange("added",r),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange("removed",t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onRelativeObjectAdded(t){this.enterGroup(t,!1),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this._applyLayoutStrategy({type:t,targets:e}),this._set("dirty",!0)}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const i=this[t];return super._set(t,e),"canvas"===t&&i!==e&&this.forEachObject((i=>{i._set(t,e)})),"layout"===t&&i!==e&&this._applyLayoutStrategy({type:"layout_change",layout:e,prevLayout:i}),"interactive"===t&&this.forEachObject((t=>this._watchObject(e,t))),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectMonitor(t){this._applyLayoutStrategy(i(i({},t),{},{type:"object_modified"})),this._set("dirty",!0)}__objectSelectionMonitor(t,e){let{target:i}=e;if(t)this._activeObjects.push(i),this._set("dirty",!0);else if(this._activeObjects.length>0){const t=this._activeObjects.indexOf(i);t>-1&&(this._activeObjects.splice(t,1),this._set("dirty",!0))}}_watchObject(t,e){const i=t?"on":"off";t&&this._watchObject(!1,e),e[i]("changed",this.__objectMonitor),e[i]("modified",this.__objectMonitor),e[i]("selected",this.__objectSelectionTracker),e[i]("deselected",this.__objectSelectionDisposer)}enterGroup(t,e){return t.group&&t.group.remove(t),this._enterGroup(t,e),!0}_enterGroup(t,e){e&&ne(t,ot(nt(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this.interactive&&this._watchObject(!0,t);const i=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();i&&(i===t||t.isDescendantOf(i))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(ne(t,ot(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const i=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;i>-1&&this._activeObjects.splice(i,1)}shouldCache(){const t=Ni.prototype.shouldCache.call(this);if(t)for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return this.ownCaching=!1,!1;return t}willDrawShadow(){if(Ni.prototype.willDrawShadow.call(this))return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.group&&this.group.isOnACache()}drawObject(t){this._renderBackground(t);for(let i=0;i<this._objects.length;i++){var e;null!==(e=this.canvas)&&void 0!==e&&e.preserveObjectStacking&&this._objects[i].group!==this?(t.save(),t.transform(...nt(this.calcTransformMatrix())),this._objects[i].render(t),t.restore()):this._objects[i].group===this&&this._objects[i].render(t)}this._drawClipPath(t,this.clipPath)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}triggerLayout(t){t&&t.layout&&(t.prevLayout=this.layout,this.layout=t.layout),this._applyLayoutStrategy({type:"imperative",context:t})}_adjustObjectPosition(t,e){t.set({left:t.left+e.x,top:t.top+e.y})}_applyLayoutStrategy(t){const e="initialization"===t.type;if(!e&&!this._firstLayoutDone)return;const i=e&&t.options,s=i&&{angle:i.angle||0,skewX:i.skewX||0,skewY:i.skewY||0},r=this.getRelativeCenterPoint();let n,o=this.getLayoutStrategyResult(this.layout,[...this._objects],t);if(o){const i=new z(o.centerX,o.centerY),a=r.subtract(i).add(new z(o.correctionX||0,o.correctionY||0));n=a.transform(nt(this.calcOwnMatrix()),!0),this.set({width:o.width,height:o.height}),!t.objectsRelativeToGroup&&this.forEachObject((t=>{t.group===this&&this._adjustObjectPosition(t,n)})),!e&&"clip-path"!==this.layout&&this.clipPath&&!this.clipPath.absolutePositioned&&this._adjustObjectPosition(this.clipPath,n),i.eq(r)&&!s||(this.setPositionByOrigin(i,k,k),s&&this.set(s),this.setCoords())}else{if(!e)return;o={centerX:r.x,centerY:r.y,width:this.width,height:this.height},s&&this.set(s),n=new z}this._firstLayoutDone=!0,this.onLayout(t,o),this.fire("layout",{context:t,result:o,diff:n}),this.group&&this.group._applyLayoutStrategy&&(t.path||(t.path=[]),t.path.push(this),this.group._applyLayoutStrategy(t))}getLayoutStrategyResult(t,e,i){if("fit-content-lazy"===t&&"added"===i.type&&e.length>i.targets.length){const e=i.targets.concat(this);return this.prepareBoundingBox(t,e,i)}if("fit-content"===t||"fit-content-lazy"===t||"fixed"===t&&("initialization"===i.type||"imperative"===i.type))return this.prepareBoundingBox(t,e,i);if("clip-path"===t&&this.clipPath){const s=this.clipPath,r=s._getTransformedDimensions();if(s.absolutePositioned&&("initialization"===i.type||"layout_change"===i.type)){let t=s.getCenterPoint();if(this.group){const e=nt(this.group.calcTransformMatrix());t=rt(t,e)}return{centerX:t.x,centerY:t.y,width:r.x,height:r.y}}if(!s.absolutePositioned){let n;const o=s.getRelativeCenterPoint(),a=rt(o,this.calcOwnMatrix(),!0);if("initialization"===i.type||"layout_change"===i.type){const r=this.prepareBoundingBox(t,e,i)||{};return n=new z(r.centerX||0,r.centerY||0),{centerX:n.x+a.x,centerY:n.y+a.y,correctionX:r.correctionX-a.x,correctionY:r.correctionY-a.y,width:s.width,height:s.height}}return n=this.getRelativeCenterPoint(),{centerX:n.x+a.x,centerY:n.y+a.y,width:r.x,height:r.y}}}}prepareBoundingBox(t,e,s){return"initialization"===s.type?this.prepareInitialBoundingBox(t,e,s):"imperative"===s.type&&s.context?i(i({},this.getObjectsBoundingBox(e)||{}),s.context):this.getObjectsBoundingBox(e)}prepareInitialBoundingBox(t,e,i){const s=i.options||{},r="number"==typeof s.left,n="number"==typeof s.top,o="number"==typeof s.width,a="number"==typeof s.height;if(r&&n&&o&&a&&i.objectsRelativeToGroup||0===e.length)return;const h=this.getObjectsBoundingBox(e)||{},{centerX:c=0,centerY:l=0,width:d=0,height:u=0}=h,g=o?this.width:d,f=a?this.height:u,p=new z(c,l),m=new z(fe(this.originX),fe(this.originY)),v=new z(g,f),_=this._getTransformedDimensions({width:0,height:0}),y=this._getTransformedDimensions({width:g,height:f,strokeWidth:0}),x=this._getTransformedDimensions({width:h.width,height:h.height,strokeWidth:0}),C=new z(0,0),b=m.scalarAdd(.5),S=y.multiply(b),w=new z(o?x.x/2:S.x,a?x.y/2:S.y),T=new z(r?this.left-(y.x+_.x)*m.x:p.x-w.x,n?this.top-(y.y+_.y)*m.y:p.y-w.y),O=new z(r?T.x-p.x+x.x*(o?.5:0):-(o?.5*(y.x-_.x):y.x*b.x),n?T.y-p.y+x.y*(a?.5:0):-(a?.5*(y.y-_.y):y.y*b.y)).add(C),k=new z(o?-y.x/2:0,a?-y.y/2:0).add(O);return{centerX:T.x,centerY:T.y,correctionX:k.x,correctionY:k.y,width:v.x,height:v.y}}getObjectsBoundingBox(t,e){if(0===t.length)return null;const i=[];t.forEach((t=>{const e=t.getRelativeCenterPoint();let s=t._getTransformedDimensions().scalarDivide(2);if(t.angle){const e=et(t.angle),i=Math.abs(G(e)),r=Math.abs(V(e)),n=s.x*r+s.y*i,o=s.x*i+s.y*r;s=new z(n,o)}i.push(e.subtract(s),e.add(s))}));const{left:s,top:r,width:n,height:o}=ie(i),a=new z(n,o),h=(e?new z:new z(s,r)).add(a.scalarDivide(2)).transform(this.calcOwnMatrix());return{centerX:h.x,centerY:h.y,width:a.x,height:a.y}}onLayout(t,e){}__serializeObjects(t,e){const i=this.includeDefaultValues;return this._objects.filter((function(t){return!t.excludeFromExport})).map((function(s){const r=s.includeDefaultValues;s.includeDefaultValues=i;const n=s[t||"toObject"](e);return s.includeDefaultValues=r,n}))}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(["layout","subTargetCheck","interactive",...t])),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this._activeObjects=[],this.forEachObject((t=>{this._watchObject(!1,t),t.dispose()})),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=Ys.prototype._toSVG.call(this),i=e.indexOf("COMMON_PARTS");e[i]='for="group" ';const s=e.join("");return t?t(s):s}_toSVG(t){const e=["<g ","COMMON_PARTS"," >\n"],i=this._createSVGBgRect(t);i&&e.push("\t\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t\t",this._objects[i].toSVG(t));return e.push("</g>\n"),e}getSvgStyles(){const t=void 0!==this.opacity&&1!==this.opacity?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],i=this._createSVGBgRect(t);i&&e.push("\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t){let{objects:e=[]}=t,s=r(t,Ws);return Promise.all([_t(e),yt(s)]).then((t=>{let[e,r]=t;return new this(e,i(i({},s),r),!0)}))}}s(Vs,"stateProperties",[...Ni.stateProperties,"layout"]),s(Vs,"type","Group"),s(Vs,"ownDefaults",{layout:"fit-content",strokeWidth:0,subTargetCheck:!1,interactive:!1}),R.setClass(Vs);class Gs extends Vs{constructor(){super(...arguments),s(this,"multiSelectionStacking","canvas-stacking")}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];"selection-order"===this.multiSelectionStacking?this.add(...e):e.forEach((t=>{const e=this._objects.findIndex((e=>e.isInFrontOf(t))),i=-1===e?this.size():e;this.insertAt(i,t)}))}enterGroup(t,e){if(t.group){const e=t.group;e._exitGroup(t),t.__owningGroup=e}return this._enterGroup(t,e),!0}exitGroup(t,e){this._exitGroup(t,e);const i=t.__owningGroup;i&&(i._enterGroup(t,!0),delete t.__owningGroup)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const i=[];e.forEach((t=>{t.group&&!i.includes(t.group)&&i.push(t.group)})),"removed"===t?i.forEach((t=>{t._onAfterObjectsChange("added",e)})):i.forEach((t=>{t._set("dirty",!0)}))}onDeselect(){return this.removeAll(),!1}_applyLayoutStrategy(t){super._applyLayoutStrategy(t),0===this._objects.length&&Object.assign(this,{left:0,top:0,angle:0,scaleX:1,scaleY:1,skewX:0,skewY:0,flipX:!1,flipY:!1})}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,super._renderControls(t,e);const r=i(i({hasControls:!1},s),{},{forActiveSelection:!0});for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,r);t.restore()}}s(Gs,"type","ActiveSelection"),R.setClass(Gs),R.setClass(Gs,"activeSelection");class zs{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new z(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new z(1/this.options.scaleX,1/this.options.scaleY):new z(1,1)}createSideVector(t,e){const i=Ne(t,e);return this.options.strokeUniform?i.multiply(this.scale):i}projectOrthogonally(t,e,i){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,i)))}isSkewed(){return 0!==this.options.skewX||0!==this.options.skewY}applySkew(t){const e=new z(t);return e.y+=e.x*Math.tan(et(this.options.skewY)),e.x+=e.y*Math.tan(et(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const Hs=new z;class Us extends zs{static getOrthogonalRotationFactor(t,e){const i=e?Ke(t,e):Je(t);return Math.abs(i)<C?-1:1}constructor(t,e,i,r){super(r),s(this,"AB",void 0),s(this,"AC",void 0),s(this,"alpha",void 0),s(this,"bisector",void 0),this.A=new z(t),this.B=new z(e),this.C=new z(i),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Ke(this.AB,this.AC),this.bisector=Ze(Ue(this.AB.eq(Hs)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const s=this.createSideVector(t,e),r=Qe(s),n=Us.getOrthogonalRotationFactor(r,this.bisector);return this.scaleUnitVector(r,i*n)}projectBevel(){const t=[];return(this.alpha%b==0?[this.B]:[this.B,this.C]).forEach((e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))})),t}projectMiter(){const t=[],e=Math.abs(this.alpha),i=1/Math.sin(e/2),s=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*i),r=this.options.strokeUniform?qe(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return qe(s)/this.strokeProjectionMagnitude<=r&&t.push(this.applySkew(this.A.add(s))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const i=[],s=new z(Us.getOrthogonalRotationFactor(this.bisector),Us.getOrthogonalRotationFactor(new z(this.bisector.y,this.bisector.x)));return[new z(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s),new z(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s)].forEach((s=>{ei(s,t,e)&&i.push(this.A.add(s))})),i}projectRoundWithSkew(t,e){const i=[],{skewX:s,skewY:r,scaleX:n,scaleY:o,strokeUniform:a}=this.options,h=new z(Math.tan(et(s)),Math.tan(et(r))),c=this.strokeProjectionMagnitude,l=a?c/o/Math.sqrt(1/o**2+1/n**2*h.y**2):c/Math.sqrt(1+h.y**2),d=new z(Math.sqrt(Math.max(c**2-l**2,0)),l),u=a?c/Math.sqrt(1+h.x**2*(1/o)**2/(1/n+1/n*h.x*h.y)**2):c/Math.sqrt(1+h.x**2/(1+h.x*h.y)**2),g=new z(u,Math.sqrt(Math.max(c**2-u**2,0)));return[g,g.scalarMultiply(-1),d,d.scalarMultiply(-1)].map((t=>this.applySkew(a?t.multiply(this.strokeUniformScalar):t))).forEach((s=>{ei(s,t,e)&&i.push(this.applySkew(this.A).add(s))})),i}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%b==0,i=this.applySkew(this.A),s=t[e?0:2].subtract(i),r=t[e?1:0].subtract(i),n=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=$e(s,n)>0,a=o?s:r,h=o?r:s;return this.isSkewed()?t.push(...this.projectRoundWithSkew(a,h)):t.push(...this.projectRoundNoSkew(a,h)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector})))}}class Ns extends zs{constructor(t,e,i){super(i),this.A=new z(t),this.T=new z(e)}calcOrthogonalProjection(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const s=this.createSideVector(t,e);return this.scaleUnitVector(Qe(s),i)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new z(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new Us(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new z(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),i=this.scaleUnitVector(Ze(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),s=this.A.add(i);t.push(s.add(e),s.subtract(e))}return t.map((t=>this.applySkew(t)))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t})))}}const qs=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=[];if(0===t.length)return s;const r=t.reduce(((t,e)=>(t[t.length-1].eq(e)||t.push(new z(e)),t)),[new z(t[0])]);if(1===r.length)i=!0;else if(!i){const t=r[0],e=((t,e)=>{for(let i=t.length-1;i>=0;i--)if(e(t[i],i,t))return i;return-1})(r,(e=>!e.eq(t)));r.splice(e+1)}return r.forEach(((t,r,n)=>{let o,a;0===r?(a=n[1],o=i?t:n[n.length-1]):r===n.length-1?(o=n[r-1],a=i?t:n[0]):(o=n[r-1],a=n[r+1]),i&&1===n.length?s.push(...new Ns(t,t,e).project()):!i||0!==r&&r!==n.length-1?s.push(...new Us(t,o,a,e).project()):s.push(...new Ns(t,0===r?a:o,e).project())})),s},Ks=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||i&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},Js=(t,e)=>{const i=e.split("\n"),s=[];let r=-1,n={};t=hi(t);for(let e=0;e<i.length;e++)if(t[e])for(let o=0;o<i[e].length;o++){r++;const i=t[e][o];i&&Object.keys(i).length>0&&(Ks(n,i,!0)?s.push({start:r,end:r+1,style:i}):s[s.length-1].end++),n=i||{}}else r+=i[e].length,n={};return s},Zs=(t,e)=>{if(!Array.isArray(t))return hi(t);const s=e.split(j),r={};let n=-1,o=0;for(let e=0;e<s.length;e++)for(let a=0;a<s[e].length;a++)n++,t[o]&&t[o].start<=n&&n<t[o].end&&(r[e]=r[e]||{},r[e][a]=i({},t[o].style),n===t[o].end-1&&o++);return r},Qs=(t,e)=>Math.min(e.width/t.width,e.height/t.height),$s=(t,e)=>Math.max(e.width/t.width,e.height/t.height),tr=t=>t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),er=t=>{const e=[];for(let i,s=0;s<t.length;s++)!1!==(i=ir(t,s))&&e.push(i);return e},ir=(t,e)=>{const i=t.charCodeAt(e);if(isNaN(i))return"";if(i<55296||i>57343)return t.charAt(e);if(55296<=i&&i<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";const i=t.charCodeAt(e+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return t.charAt(e)+t.charAt(e+1)}if(0===e)throw"Low surrogate without preceding high surrogate";const s=t.charCodeAt(e-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var sr,rr=Object.freeze({__proto__:null,capitalize:function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"".concat(t.charAt(0).toUpperCase()).concat(e?t.slice(1):t.slice(1).toLowerCase())},escapeXml:tr,graphemeSplit:er});const nr="(".concat($i,")"),or="(M) (?:".concat(nr," ").concat(nr," ?)+"),ar="(L) (?:".concat(nr," ").concat(nr," ?)+"),hr="(H) (?:".concat(nr," ?)+"),cr="(V) (?:".concat(nr," ?)+"),lr=String.raw(sr||(sr=n(["(Z)s*"],["(Z)\\s*"]))),dr="(C) (?:".concat(nr," ").concat(nr," ").concat(nr," ").concat(nr," ").concat(nr," ").concat(nr," ?)+"),ur="(S) (?:".concat(nr," ").concat(nr," ").concat(nr," ").concat(nr," ?)+"),gr="(Q) (?:".concat(nr," ").concat(nr," ").concat(nr," ").concat(nr," ?)+"),fr="(T) (?:".concat(nr," ").concat(nr," ?)+"),pr="(A) (?:".concat(nr," ").concat(nr," ").concat(nr," ([01]) ?([01]) ").concat(nr," ").concat(nr," ?)+"),mr="(?:(?:".concat(or,")")+"|(?:".concat(ar,")")+"|(?:".concat(hr,")")+"|(?:".concat(cr,")")+"|(?:".concat(lr,")")+"|(?:".concat(dr,")")+"|(?:".concat(ur,")")+"|(?:".concat(gr,")")+"|(?:".concat(fr,")")+"|(?:".concat(pr,"))"),vr={m:"l",M:"L"},_r=(t,e,i,s,r,n,o,a,h,c,l)=>{const d=V(t),u=G(t),g=V(e),f=G(e),p=i*r*g-s*n*f+o,m=s*r*g+i*n*f+a;return["C",c+h*(-i*r*u-s*n*d),l+h*(-s*r*u+i*n*d),p+h*(i*r*f+s*n*g),m+h*(s*r*f-i*n*g),p,m]},yr=(t,e,i,s)=>{const r=Math.atan2(e,t),n=Math.atan2(s,i);return n>=r?n-r:2*Math.PI-(r-n)};function xr(t,e,i,s,r,n,o,a){let c;if(h.cachesBoundsOfCurve&&(c=[...arguments].join(),_.boundsOfCurveCache[c]))return _.boundsOfCurveCache[c];const l=Math.sqrt,d=Math.abs,u=[],g=[[0,0],[0,0]];let f=6*t-12*i+6*r,p=-3*t+9*i-9*r+3*o,m=3*i-3*t;for(let t=0;t<2;++t){if(t>0&&(f=6*e-12*s+6*n,p=-3*e+9*s-9*n+3*a,m=3*s-3*e),d(p)<1e-12){if(d(f)<1e-12)continue;const t=-m/f;0<t&&t<1&&u.push(t);continue}const i=f*f-4*m*p;if(i<0)continue;const r=l(i),o=(-f+r)/(2*p);0<o&&o<1&&u.push(o);const h=(-f-r)/(2*p);0<h&&h<1&&u.push(h)}let v=u.length;const y=v,x=wr(t,e,i,s,r,n,o,a);for(;v--;){const{x:t,y:e}=x(u[v]);g[0][v]=t,g[1][v]=e}g[0][y]=t,g[1][y]=e,g[0][y+1]=o,g[1][y+1]=a;const C=[new z(Math.min(...g[0]),Math.min(...g[1])),new z(Math.max(...g[0]),Math.max(...g[1]))];return h.cachesBoundsOfCurve&&(_.boundsOfCurveCache[c]=C),C}const Cr=(t,e,i)=>{let[s,r,n,o,a,h,c,l]=i;const d=((t,e,i,s,r,n,o)=>{if(0===i||0===s)return[];let a=0,h=0,c=0;const l=Math.PI,d=o*S,u=G(d),g=V(d),f=.5*(-g*t-u*e),p=.5*(-g*e+u*t),m=i**2,v=s**2,_=p**2,y=f**2,x=m*v-m*_-v*y;let C=Math.abs(i),b=Math.abs(s);if(x<0){const t=Math.sqrt(1-x/(m*v));C*=t,b*=t}else c=(r===n?-1:1)*Math.sqrt(x/(m*_+v*y));const w=c*C*p/b,T=-c*b*f/C,O=g*w-u*T+.5*t,k=u*w+g*T+.5*e;let D=yr(1,0,(f-w)/C,(p-T)/b),M=yr((f-w)/C,(p-T)/b,(-f-w)/C,(-p-T)/b);0===n&&M>0?M-=2*l:1===n&&M<0&&(M+=2*l);const P=Math.ceil(Math.abs(M/l*2)),E=new Array(P),A=M/P,j=8/3*Math.sin(A/4)*Math.sin(A/4)/Math.sin(A/2);let F=D+A;for(let t=0;t<P;t++)E[t]=_r(D,F,g,u,C,b,O,k,j,a,h),a=E[t][5],h=E[t][6],D=F,F+=A;return E})(c-t,l-e,r,n,a,h,o);for(let i=0,s=d.length;i<s;i++)d[i][1]+=t,d[i][2]+=e,d[i][3]+=t,d[i][4]+=e,d[i][5]+=t,d[i][6]+=e;return d},br=t=>{let e=0,i=0,s=0,r=0;const n=[];let o,a=0,h=0;for(const c of t){const t=[...c];let l;switch(t[0]){case"l":t[1]+=e,t[2]+=i;case"L":e=t[1],i=t[2],l=["L",e,i];break;case"h":t[1]+=e;case"H":e=t[1],l=["L",e,i];break;case"v":t[1]+=i;case"V":i=t[1],l=["L",e,i];break;case"m":t[1]+=e,t[2]+=i;case"M":e=t[1],i=t[2],s=t[1],r=t[2],l=["M",e,i];break;case"c":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i,t[5]+=e,t[6]+=i;case"C":a=t[3],h=t[4],e=t[5],i=t[6],l=["C",t[1],t[2],a,h,e,i];break;case"s":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"S":"C"===o?(a=2*e-a,h=2*i-h):(a=e,h=i),e=t[3],i=t[4],l=["C",a,h,t[1],t[2],e,i],a=l[3],h=l[4];break;case"q":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"Q":a=t[1],h=t[2],e=t[3],i=t[4],l=["Q",a,h,e,i];break;case"t":t[1]+=e,t[2]+=i;case"T":"Q"===o?(a=2*e-a,h=2*i-h):(a=e,h=i),e=t[1],i=t[2],l=["Q",a,h,e,i];break;case"a":t[6]+=e,t[7]+=i;case"A":Cr(e,i,t).forEach((t=>n.push(t))),e=t[6],i=t[7];break;case"z":case"Z":e=s,i=r,l=["Z"]}l?(n.push(l),o=l[0]):o=""}return n},Sr=(t,e,i,s)=>Math.sqrt((i-t)**2+(s-e)**2),wr=(t,e,i,s,r,n,o,a)=>h=>{const c=h**3,l=(t=>3*t**2*(1-t))(h),d=(t=>3*t*(1-t)**2)(h),u=(t=>(1-t)**3)(h);return new z(o*c+r*l+i*d+t*u,a*c+n*l+s*d+e*u)},Tr=t=>t**2,Or=t=>2*t*(1-t),kr=t=>(1-t)**2,Dr=(t,e,i,s,r,n,o,a)=>h=>{const c=Tr(h),l=Or(h),d=kr(h),u=3*(d*(i-t)+l*(r-i)+c*(o-r)),g=3*(d*(s-e)+l*(n-s)+c*(a-n));return Math.atan2(g,u)},Mr=(t,e,i,s,r,n)=>o=>{const a=Tr(o),h=Or(o),c=kr(o);return new z(r*a+i*h+t*c,n*a+s*h+e*c)},Pr=(t,e,i,s,r,n)=>o=>{const a=1-o,h=2*(a*(i-t)+o*(r-i)),c=2*(a*(s-e)+o*(n-s));return Math.atan2(c,h)},Er=(t,e,i)=>{let s=new z(e,i),r=0;for(let e=1;e<=100;e+=1){const i=t(e/100);r+=Sr(s.x,s.y,i.x,i.y),s=i}return r},Ar=(t,e)=>{let s,r=0,n=0,o={x:t.x,y:t.y},a=i({},o),h=.01,c=0;const l=t.iterator,d=t.angleFinder;for(;n<e&&h>1e-4;)a=l(r),c=r,s=Sr(o.x,o.y,a.x,a.y),s+n>e?(r-=h,h/=2):(o=a,r+=h,n+=s);return i(i({},a),{},{angle:d(c)})},jr=t=>{let e,i,s=0,r=0,n=0,o=0,a=0;const h=[];for(const c of t){const t={x:r,y:n,command:c[0],length:0};switch(c[0]){case"M":i=t,i.x=o=r=c[1],i.y=a=n=c[2];break;case"L":i=t,i.length=Sr(r,n,c[1],c[2]),r=c[1],n=c[2];break;case"C":e=wr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),i=t,i.iterator=e,i.angleFinder=Dr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),i.length=Er(e,r,n),r=c[5],n=c[6];break;case"Q":e=Mr(r,n,c[1],c[2],c[3],c[4]),i=t,i.iterator=e,i.angleFinder=Pr(r,n,c[1],c[2],c[3],c[4]),i.length=Er(e,r,n),r=c[3],n=c[4];break;case"Z":i=t,i.destX=o,i.destY=a,i.length=Sr(r,n,o,a),r=o,n=a}s+=i.length,h.push(i)}return h.push({length:s,x:r,y:n}),h},Fr=function(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:jr(t),r=0;for(;e-s[r].length>0&&r<s.length-2;)e-=s[r].length,r++;const n=s[r],o=e/n.length,a=t[r];switch(n.command){case"M":return{x:n.x,y:n.y,angle:0};case"Z":return i(i({},new z(n.x,n.y).lerp(new z(n.destX,n.destY),o)),{},{angle:Math.atan2(n.destY-n.y,n.destX-n.x)});case"L":return i(i({},new z(n.x,n.y).lerp(new z(a[1],a[2]),o)),{},{angle:Math.atan2(a[2]-n.y,a[1]-n.x)});case"C":case"Q":return Ar(n,e)}},Lr=t=>{t=us(t);const e=[];for(const i of t.matchAll(new RegExp(mr,"gi"))){let t=i[0];const s=[];let r;do{if(r=new RegExp(mr,"i").exec(t),!r)break;const e=r.filter((t=>t));e.shift();const i=e.map((t=>{const e=Number.parseFloat(t);return Number.isNaN(e)?t:e}));if(s.push(i),e.length<=1)break;e.shift(),t=t.replace(new RegExp("".concat(e.join(" ?")," ?$")),"")}while(r);s.reverse().forEach(((t,i)=>{const s=vr[t[0]];i>0&&("l"==s||"L"==s)&&(t[0]=s),e.push(t)}))}return e},Rr=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=new z(t[0]),s=new z(t[1]),r=1,n=0;const o=[],a=t.length,h=a>2;let c;for(h&&(r=t[2].x<s.x?-1:t[2].x===s.x?0:1,n=t[2].y<s.y?-1:t[2].y===s.y?0:1),o.push(["M",i.x-r*e,i.y-n*e]),c=1;c<a;c++){if(!i.eq(s)){const t=i.midPointFrom(s);o.push(["Q",i.x,i.y,t.x,t.y])}i=t[c],c+1<t.length&&(s=t[c+1])}return h&&(r=i.x>t[c-2].x?1:i.x===t[c-2].x?0:-1,n=i.y>t[c-2].y?1:i.y===t[c-2].y?0:-1),o.push(["L",i.x+r*e,i.y+n*e]),o},Br=(t,e)=>t.map((t=>t.map(((t,i)=>0===i||void 0===e?t:Mt(t,e))).join(" "))).join(" ");function Ir(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.onComplete||x,s=new(v().XMLHttpRequest),r=e.signal,n=function(){s.abort()},o=function(){r&&r.removeEventListener("abort",n),s.onerror=s.ontimeout=x};if(r&&r.aborted)throw new Error("`options.signal` is in `aborted` state");return r&&r.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){4===s.readyState&&(o(),i(s),s.onreadystatechange=x)},s.onerror=s.ontimeout=o,s.open("get",t,!0),s.send(),s}const Xr=(t,e)=>{let i=t._findCenterFromElement();t.transformMatrix&&((t=>{if(t.transformMatrix){const{scaleX:e,scaleY:i,angle:s,skewX:r}=ht(t.transformMatrix);t.flipX=!1,t.flipY=!1,t.set("scaleX",e),t.set("scaleY",i),t.angle=s,t.skewX=r,t.skewY=0}})(t),i=i.transform(t.transformMatrix)),delete t.transformMatrix,e&&(t.scaleX*=e.scaleX,t.scaleY*=e.scaleY,t.cropX=e.cropX,t.cropY=e.cropY,i.x+=e.offsetLeft,i.y+=e.offsetTop,t.width=e.width,t.height=e.height),t.setPositionByOrigin(i,k,k)};var Yr=Object.freeze({__proto__:null,addTransformToObject:re,animate:Ve,animateColor:Ge,applyTransformToObject:ne,calcAngleBetweenVectors:Ke,calcDimensionsMatrix:pt,calcPlaneChangeMatrix:ce,calcVectorRotation:Je,cancelAnimFrame:K,capValue:Re,composeMatrix:mt,copyCanvasElement:t=>{var e;const i=Q();return i.width=t.width,i.height=t.height,null===(e=i.getContext("2d"))||void 0===e||e.drawImage(t,0,0),i},cos:V,createCanvasElement:Q,createImage:$,createRotateMatrix:lt,createScaleMatrix:dt,createSkewXMatrix:gt,createSkewYMatrix:ft,createTranslateMatrix:ct,createVector:Ne,crossProduct:$e,degreesToRadians:et,dotProduct:ti,ease:Me,enlivenObjectEnlivables:yt,enlivenObjects:_t,findScaleToCover:$s,findScaleToFit:Qs,getBoundsOfCurve:xr,getOrthonormalVector:Qe,getPathSegmentsInfo:jr,getPointOnPath:Fr,getPointer:$t,getRandomInt:X,getRegularPolygonPath:(t,e)=>{const i=2*Math.PI/t;let s=-C;t%2==0&&(s+=i/2);const r=new Array(t+1);for(let n=0;n<t;n++){const t=n*i+s,{x:o,y:a}=new z(V(t),G(t)).scalarMultiply(e);r[n]=[0===n?"M":"L",o,a]}return r[t]=["Z"],r},getSmoothPathFromPoints:Rr,getSvgAttributes:t=>{const e=["instantiated_by_use","style","id","class"];switch(t){case"linearGradient":return e.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return e.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return e.concat(["offset","stop-color","stop-opacity"])}return e},getUnitVector:Ze,groupSVGElements:t=>t&&1===t.length?t[0]:new Vs(t),hasStyleChanged:Ks,invertTransform:nt,isBetweenVectors:ei,isIdentityMatrix:t=>t.every(((t,e)=>t===w[e])),isTouchEvent:te,isTransparent:qi,joinPath:Br,loadImage:vt,magnitude:qe,makeBoundingBoxFromPoints:ie,makePathSimpler:br,matrixToSVG:At,mergeClipPaths:(t,e)=>{var i;let s=t,r=e;s.inverted&&!r.inverted&&(s=e,r=t),de(r,null===(i=r.group)||void 0===i?void 0:i.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&r.inverted;return n&&(s.inverted=r.inverted=!1),new Vs([s],{clipPath:r,inverted:n})},multiplyTransformMatrices:ot,multiplyTransformMatrixArray:at,parsePath:Lr,parsePreserveAspectRatioAttribute:Et,parseUnit:Pt,pick:xt,projectStrokeOnPoints:qs,qrDecompose:ht,radiansToDegrees:it,removeFromArray:W,removeTransformFromObject:(t,e)=>{const i=nt(e),s=ot(i,t.calcOwnMatrix());ne(t,s)},removeTransformMatrixForSvgParsing:Xr,request:Ir,requestAnimFrame:q,resetObjectTransform:oe,rotatePoint:(t,e,i)=>t.rotate(i,e),rotateVector:Ue,saveObjectTransform:ae,sendObjectToPlane:de,sendPointToPlane:le,setStyle:Ht,sin:G,sizeAfterTransform:he,string:rr,stylesFromArray:Zs,stylesToArray:Js,toDataURL:tt,toFixed:Mt,transformPath:(t,e,i)=>(i&&(e=ot(e,[1,0,0,1,-i.x,-i.y])),t.map((t=>{const i=[...t];for(let s=1;s<t.length-1;s+=2){const{x:r,y:n}=rt({x:t[s],y:t[s+1]},e);i[s]=r,i[s+1]=n}return i}))),transformPoint:rt,transformPointRelativeToCanvas:(t,e,i,s)=>{if("child"!==i&&"sibling"!==i)throw new Error("fabric.js: received bad argument ".concat(i));if("child"!==s&&"sibling"!==s)throw new Error("fabric.js: received bad argument ".concat(s));if(i===s)return t;const r=e.viewportTransform;return t.transform("child"===s?nt(r):r)}});class Wr extends Kt{constructor(t){let{allowTouchScrolling:e=!1,containerClass:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t),s(this,"upper",void 0),s(this,"container",void 0);const{el:r}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(r,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e});const o=this.createContainerElement();o.classList.add(i),r.parentNode&&r.parentNode.replaceChild(o,r),o.append(r,n),this.container=o}createUpperCanvas(){const{el:t}=this.lower,e=Q();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=m().createElement("div");return t.setAttribute("data-fabric","wrapper"),Ht(t,{position:"relative"}),qt(t),t}applyCanvasStyle(t,e){let{allowTouchScrolling:i}=e;Ht(t,{position:"absolute",left:"0",top:"0"}),function(t,e){const i=e?"manipulation":A;Ht(t,{"touch-action":i,"-ms-touch-action":i})}(t,i),qt(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:i,ctx:s}=this.upper;Ut(i,s,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Nt(this.upper.el,t),Nt(this.container,t)}cleanupDOM(t){const e=this.container,{el:i}=this.lower,{el:s}=this.upper;super.cleanupDOM(t),e.removeChild(s),e.removeChild(i),e.parentNode&&e.parentNode.replaceChild(i,e)}dispose(){super.dispose(),p().dispose(this.upper.el),delete this.upper,delete this.container}}const Vr=["activeSelection"];class Gr extends Zt{static getDefaults(){return i(i({},super.getDefaults()),Gr.ownDefaults)}get upperCanvasEl(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.el}get contextTop(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.ctx}get wrapperEl(){return this.elements.container}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{activeSelection:i=new Gs}=e;super(t,r(e,Vr)),s(this,"targets",[]),s(this,"_hoveredTargets",[]),s(this,"_objectsToRender",[]),s(this,"_currentTransform",null),s(this,"_groupSelector",null),s(this,"contextTopDirty",!1),s(this,"_activeSelection",void 0),this._activeSelection=i,this._activeSelection.set("canvas",this),this._activeSelection.setCoords()}initElements(t){this.elements=new Wr(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}_normalizePointer(t,e){return rt(this.restorePointerVpt(e),nt(t.calcTransformMatrix()))}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),i=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=i,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,i){const s=this.targetFindTolerance,r=this.pixelFindContext;this.clearContext(r),r.save(),r.translate(-e+s,-i+s),r.transform(...this.viewportTransform);const n=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(r),t.selectionBackgroundColor=n,r.restore();const o=Math.round(s*this.getRetinaScaling());return qi(r,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((e=>!!e&&!0===t[e])):t[e])}_shouldClearSelection(t,e){const i=this.getActiveObjects(),s=this._activeObject;return!!(!e||e&&s&&i.length>1&&-1===i.indexOf(e)&&s!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&s&&s!==e)}_shouldCenterTransform(t,e,i){if(!t)return;let s;return"scale"===e||"scaleX"===e||"scaleY"===e||"resizing"===e?s=this.centeredScaling||t.centeredScaling:"rotate"===e&&(s=this.centeredRotation||t.centeredRotation),s?!i:i}_getOriginFromCorner(t,e){const i={x:t.originX,y:t.originY};return["ml","tl","bl"].includes(e)?i.x=E:["mr","tr","br"].includes(e)&&(i.x=D),["tl","mt","tr"].includes(e)?i.y=P:["bl","mb","br"].includes(e)&&(i.y=M),i}_setupCurrentTransform(t,e,s){if(!e)return;const r=e.group?le(this.getPointer(t),void 0,e.group.calcTransformMatrix()):this.getPointer(t),n=e.getActiveControl()||"",o=!!n&&e.controls[n],a=s&&o?o.getActionHandler(t,e,o):be,h=((t,e,i,s)=>{if(!e||!t)return"drag";const r=s.controls[e];return r.getActionName(i,r,s)})(s,n,t,e),c=this._getOriginFromCorner(e,n),l=t[this.centeredKey],d={target:e,action:h,actionHandler:a,actionPerformed:!1,corner:n,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:r.x-e.left,offsetY:r.y-e.top,originX:c.x,originY:c.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:et(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:l,original:i(i({},ae(e)),{},{originX:c.x,originY:c.y})};this._shouldCenterTransform(e,h,l)&&(d.originX=k,d.originY=k),this._currentTransform=d,this._beforeTransform(t)}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new z(e,i).transform(this.viewportTransform),o=new z(e+s,i+r).transform(this.viewportTransform),a=this.selectionLineWidth/2;let h=Math.min(n.x,o.x),c=Math.min(n.y,o.y),l=Math.max(n.x,o.x),d=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(h,c,l-h,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,h+=a,c+=a,l-=a,d-=a,Ni.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(h,c,l-h,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getPointer(t,!0),i=this._activeObject,s=this.getActiveObjects();if(this.targets=[],i&&s.length>=1){if(i._findTargetCorner(e,te(t)))return i;if(s.length>1&&this.searchPossibleTargets([i],e))return i;if(i===this.searchPossibleTargets([i],e)){if(this.preserveObjectStacking){const s=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==i?(this.targets=s,i):r}return i}}return this.searchPossibleTargets(this._objects,e)}_checkTarget(t,e,i){if(e&&e.visible&&e.evented&&e.containsPoint(t)){if(!this.perPixelTargetFind&&!e.perPixelTargetFind||e.isEditing)return!0;if(!this.isTargetTransparent(e,i.x,i.y))return!0}return!1}_searchPossibleTargets(t,e){let i,s=t.length;for(;s--;){const r=t[s],n=r.group?this._normalizePointer(r.group,e):e;if(this._checkTarget(n,r,e)){if(i=t[s],It(i)&&i.subTargetCheck){const t=this._searchPossibleTargets(i._objects,e);t&&this.targets.push(t)}break}}return i}searchPossibleTargets(t,e){const i=this._searchPossibleTargets(t,e);return i&&It(i)&&i.interactive&&this.targets[0]?this.targets[0]:i}restorePointerVpt(t){return t.transform(nt(this.viewportTransform))}getPointer(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this._absolutePointer&&!e)return this._absolutePointer;if(this._pointer&&e)return this._pointer;const i=this.upperCanvasEl,s=i.getBoundingClientRect();let r=$t(t),n=s.width||0,o=s.height||0;n&&o||(M in s&&P in s&&(o=Math.abs(s.top-s.bottom)),E in s&&D in s&&(n=Math.abs(s.right-s.left))),this.calcOffset(),r.x=r.x-this._offset.left,r.y=r.y-this._offset.top,e||(r=this.restorePointerVpt(r));const a=this.getRetinaScaling();1!==a&&(r.x/=a,r.y/=a);const h=0===n||0===o?new z(1,1):new z(i.width/n,i.height/o);return r.multiply(h)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Q(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveSelection(){return this._activeSelection}getActiveObjects(){const t=this._activeObject;return t?t===this._activeSelection?[...t._objects]:[t]:[]}_fireSelectionEvents(t,e){let i=!1,s=!1;const r=this.getActiveObjects(),n=[],o=[];t.forEach((t=>{r.includes(t)||(i=!0,t.fire("deselected",{e:e,target:t}),o.push(t))})),r.forEach((s=>{t.includes(s)||(i=!0,s.fire("selected",{e:e,target:s}),n.push(s))})),t.length>0&&r.length>0?(s=!0,i&&this.fire("selection:updated",{e:e,selected:n,deselected:o})):r.length>0?(s=!0,this.fire("selection:created",{e:e,selected:n})):t.length>0&&(s=!0,this.fire("selection:cleared",{e:e,deselected:o})),s&&(this._objectsToRender=void 0)}setActiveObject(t,e){const i=this.getActiveObjects(),s=this._setActiveObject(t,e);return this._fireSelectionEvents(i,e),s}_setActiveObject(t,e){return this._activeObject!==t&&(!(!this._discardActiveObject(e,t)&&this._activeObject)&&(!t.onSelect({e:e})&&(this._activeObject=t,!0)))}_discardActiveObject(t,e){const i=this._activeObject;return!!i&&(!i.onDeselect({e:t,object:e})&&(i===this._activeSelection&&(this._activeSelection.removeAll(),oe(this._activeSelection)),this._currentTransform&&this._currentTransform.target===i&&this.endCurrentTransform(t),this._activeObject=void 0,!0))}discardActiveObject(t){const e=this.getActiveObjects(),i=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[i]});const s=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),s}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeSelection;t.removeAll(),this._activeSelection=void 0,t.dispose(),super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,i){const s=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,i);return t.set(s),r}_realizeGroupTransformOnObject(t){if(t.group&&t.group===this._activeSelection&&this._activeObject===t.group){const e=xt(t,["angle","flipX","flipY",D,"scaleX","scaleY","skewX","skewY",M]);return re(t,this._activeObject.calcOwnMatrix()),e}return{}}_setSVGObject(t,e,i){const s=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,i),e.set(s)}}s(Gr,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class zr{constructor(t){s(this,"targets",[]),s(this,"__disposer",void 0);const e=()=>{const e=t.getActiveObject();Yt(e)&&e.hiddenTextarea&&e.hiddenTextarea.focus()},i=t.upperCanvasEl;i.addEventListener("click",e),this.__disposer=()=>i.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),W(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;(null===(e=this.target)||void 0===e?void 0:e.isEditing)&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const Hr=["target","oldTarget","fireCanvas","e"],Ur={passive:!1};function Nr(t,e){return!!t.button&&t.button===e-1}const qr=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return t.addEventListener(...i)},Kr=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return t.removeEventListener(...i)},Jr={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Zr extends Gr{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),s(this,"_isClick",void 0),s(this,"textEditingManager",new zr(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((t=>{this[t]=this[t].bind(this)})),this.addOrRemove(qr,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const i=this.upperCanvasEl,s=this._getEventPrefix();t(zt(i),"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,"".concat(s,"move"),this._onMouseMove,Ur),t(i,"".concat(s,"out"),this._onMouseOut),t(i,"".concat(s,"enter"),this._onMouseEnter),t(i,"wheel",this._onMouseWheel),t(i,"contextmenu",this._onContextMenu),t(i,"dblclick",this._onDoubleClick),t(i,"dragstart",this._onDragStart),t(i,"dragend",this._onDragEnd),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,Ur)}removeListeners(){this.addOrRemove(Kr,"remove");const t=this._getEventPrefix(),e=Gt(this.upperCanvasEl);Kr(e,"".concat(t,"up"),this._onMouseUp),Kr(e,"touchend",this._onTouchEnd,Ur),Kr(e,"".concat(t,"move"),this._onMouseMove,Ur),Kr(e,"touchmove",this._onMouseMove,Ur)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s={e:t,isClick:!1,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t)};this.fire("mouse:out",i(i({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",i({},s)),this._hoveredTargets.forEach((t=>{this.fire("mouse:out",i(i({},s),{},{target:t})),t&&t.fire("mouseout",i({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",{e:t,isClick:!1,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t)}),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(Wt(e)&&e.onDragStart(t)){this._dragSource=e;const i={e:t,target:e};return this.fire("dragstart",i),e.fire("dragstart",i),void qr(this.upperCanvasEl,"drag",this._onDragProgress)}ee(t)}_renderDragEffects(t,e,i){let s=!1;const r=this._dropTarget;r&&r!==e&&r!==i&&(r.clearContextTop(),s=!0),null==e||e.clearContextTop(),i!==e&&(null==i||i.clearContextTop());const n=this.contextTop;n.save(),n.transform(...this.viewportTransform),e&&(n.save(),e.transform(n),e.renderDragSourceEffect(t),n.restore(),s=!0),i&&(n.save(),i.transform(n),i.renderDropTargetEffect(t),n.restore(),s=!0),n.restore(),s&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==A,i=e?this._activeObject:void 0,s={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:i};Kr(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",s),this._dragSource&&this._dragSource.fire("dragend",s),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){this.targets=[];return{target:this._searchPossibleTargets(this._objects,this.getPointer(t,!0)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:i,targets:s}=this.findDragTargets(t),r=this._dragSource,n={e:t,target:i,subTargets:s,dragSource:r,canDrop:!1,dropTarget:void 0};let o;this.fire(e,n),this._fireEnterLeaveEvents(i,n),i&&(i.canDrop(t)&&(o=i),i.fire(e,n));for(let i=0;i<s.length;i++){const r=s[i];r.canDrop(t)&&(o=r),r.fire(e,n)}this._renderDragEffects(t,r,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:i}=this.findDragTargets(t),s={e:t,target:e,subTargets:i,dragSource:this._dragSource};this.fire("dragenter",s),this._fireEnterLeaveEvents(e,s)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:i}=this.findDragTargets(t),s=this._basicEventHandler("drop:before",{e:t,target:e,subTargets:i,dragSource:this._dragSource,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t)});s.didDrop=!1,s.dropTarget=void 0,this._basicEventHandler("drop",s),this.fire("drop:after",s)}_onContextMenu(t){const e=this.findTarget(t),i=this.targets||[],s=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:i});return this.stopContextMenu&&ee(t),this._basicEventHandler("contextmenu",s),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||(!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId))}_onTouchStart(t){t.preventDefault(),null===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix(),s=Gt(e);qr(s,"touchend",this._onTouchEnd,Ur),qr(s,"touchmove",this._onMouseMove,Ur),Kr(e,"".concat(i,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();Kr(e,"".concat(i,"move"),this._onMouseMove,Ur);const s=Gt(e);qr(s,"".concat(i,"up"),this._onMouseUp),qr(s,"".concat(i,"move"),this._onMouseMove,Ur)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),this.mainTouchId=null;const e=this._getEventPrefix(),i=Gt(this.upperCanvasEl);Kr(i,"touchend",this._onTouchEnd,Ur),Kr(i,"touchmove",this._onMouseMove,Ur),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{qr(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();if(this._isMainEvent(t)){const t=Gt(this.upperCanvasEl);Kr(t,"".concat(i,"up"),this._onMouseUp),Kr(t,"".concat(i,"move"),this._onMouseMove,Ur),qr(e,"".concat(i,"move"),this._onMouseMove,Ur)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||Wt(e)&&!e.shouldStartDragging())&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!(!!e!=!!t||e&&t&&e!==t)||(Yt(e),!1)}__onMouseUp(t){const e=this._currentTransform;this._cacheTransformEventData(t);const i=this._target,s=this._isClick;if(this._handleEvent(t,"up:before"),Nr(t,3))return void(this.fireRightClick&&this._handleEvent(t,"up",3,s));if(Nr(t,2))return this.fireMiddleClick&&this._handleEvent(t,"up",2,s),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let r,n,o=!1;if(e&&(this._finalizeCurrentTransform(t),o=e.actionPerformed),!s){const e=i===this._activeObject;this.handleSelection(t),o||(o=this._shouldRender(i)||!e&&i===this._activeObject)}if(i){if(n=i._findTargetCorner(this.getPointer(t,!0),te(t)),i.selectable&&i!==this._activeObject&&"up"===i.activeOn)this.setActiveObject(i,t),o=!0;else{const s=i.controls[n],o=s&&s.getMouseUpHandler(t,i,s);o&&(r=this.getPointer(t),o(t,e,r.x,r.y))}i.isMoving=!1}if(e&&(e.target!==i||e.corner!==n)){const i=e.target&&e.target.controls[e.corner],s=i&&i.getMouseUpHandler(t,e.target,i);r=r||this.getPointer(t),s&&s(t,e,r.x,r.y)}this._setCursorFromEvent(t,i),this._handleEvent(t,"up",1,s),this._groupSelector=null,this._currentTransform=null,i&&(i.__corner=void 0),o?this.requestRenderAll():s||Yt(this._activeObject)&&this._activeObject.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:i,subTargets:s=[]}=e;this.fire(t,e),i&&i.fire(t,e);for(let i=0;i<s.length;i++)s[i].fire(t,e);return e}_handleEvent(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=this._target,n=this.targets||[],o={e:t,target:r,subTargets:n,button:i,isClick:s,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t),transform:this._currentTransform};"up"===e&&(o.currentTarget=this.findTarget(t),o.currentSubTargets=this.targets),this.fire("mouse:".concat(e),o),r&&r.fire("mouse".concat(e),o);for(let t=0;t<n.length;t++)n[t].fire("mouse".concat(e),o)}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,i=e.target,s={e:t,target:i,transform:e,action:e.action};i._scaling&&(i._scaling=!1),i.setCoords(),e.actionPerformed&&(this.fire("object:modified",s),i.fire("modified",s))}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getPointer(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getPointer(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getPointer(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;if(Nr(t,3))return void(this.fireRightClick&&this._handleEvent(t,"down",3));if(Nr(t,2))return void(this.fireMiddleClick&&this._handleEvent(t,"down",2));if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t))return;if(this._currentTransform)return;let i=this._shouldRender(e),s=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,s=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const e=this.getPointer(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(e){const i=e===this._activeObject;e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);const r=e._findTargetCorner(this.getPointer(t,!0),te(t));if(e===this._activeObject&&(r||!s)){this._setupCurrentTransform(t,e,i);const s=e.controls[r],n=this.getPointer(t),o=s&&s.getMouseDownHandler(t,e,s);o&&o(t,this._currentTransform,n.x,n.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getPointer(t,!0),this._absolutePointer=this.restorePointerVpt(this._pointer),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}_beforeTransform(t){const e=this._currentTransform;this.fire("before:transform",{e:t,transform:e})}__onMouseMove(t){if(this._isClick=!1,this._handleEvent(t,"move:before"),this._cacheTransformEventData(t),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const i=this.getPointer(t);e.deltaX=i.x-e.x,e.deltaY=i.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const e=this.findTarget(t);this._setCursorFromEvent(t,e),this._fireOverOutEvents(t,e)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const i=this._hoveredTarget,s=this._hoveredTargets,r=this.targets,n=Math.max(s.length,r.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:i,fireCanvas:!0});for(let e=0;e<n;e++)this.fireSyntheticInOutEvents("mouse",{e:t,target:r[e],oldTarget:s[e]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,r=this._hoveredTargets,n=this.targets,o=Math.max(r.length,n.length);this.fireSyntheticInOutEvents("drag",i(i({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let t=0;t<o;t++)this.fireSyntheticInOutEvents("drag",i(i({},e),{},{target:n[t],oldTarget:r[t]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:n,fireCanvas:o,e:a}=e,h=r(e,Hr);const{targetIn:c,targetOut:l,canvasIn:d,canvasOut:u}=Jr[t],g=n!==s;if(n&&g){const t=i(i({},h),{},{e:a,target:n,nextTarget:s,isClick:!1,pointer:this.getPointer(a,!0),absolutePointer:this.getPointer(a)});o&&this.fire(d,t),n.fire(l,t)}if(s&&g){const t=i(i({},h),{},{e:a,target:s,previousTarget:n,isClick:!1,pointer:this.getPointer(a,!0),absolutePointer:this.getPointer(a)});o&&this.fire(u,t),s.fire(c,t)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getPointer(t),i=this._currentTransform,s=i.target,r=s.group?le(e,void 0,s.group.calcTransformMatrix()):e;i.reset=!1,i.shiftKey=t.shiftKey,i.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,i,r),i.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,i){const s=i.x,r=i.y,n=e.action,o=e.actionHandler;let a=!1;o&&(a=o(t,e,s,r)),"drag"===n&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let i=e.hoverCursor||this.hoverCursor;const s=this._activeObject===this._activeSelection?this._activeObject:null,r=(!s||e.group!==s)&&e._findTargetCorner(this.getPointer(t,!0));if(r){const i=e.controls[r];this.setCursor(i.cursorStyleHandler(t,i,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((t=>{i=t.hoverCursor||i})),this.setCursor(i)}handleMultiSelection(t,e){const i=this._activeObject,s=this._activeSelection,r=i===s;if(i&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(i!==e||r)&&(r||!e.isDescendantOf(i)&&!i.isDescendantOf(e))&&!e.onSelect({e:t})&&!i.getActiveControl()){if(r){const i=s.getObjects();if(e===s){const s=this.getPointer(t,!0);if(!(e=this.searchPossibleTargets(i,s)||this.searchPossibleTargets(this._objects,s))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],1===s.size()&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(i,t)}else Yt(i)&&i.exitEditing(),s.multiSelectAdd(i,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([i],t);return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new z(e,i),o=n.add(new z(s,r)),a=n.min(o),h=n.max(o).subtract(a),c=n.eq(o),l=this.collectObjects({left:a.x,top:a.y,width:h.x,height:h.y},{includeIntersecting:!this.selectionFullyContained}),d=c?l[0]?[l[0]]:[]:l.length>1?l.filter((e=>!e.onSelect({e:t}))).reverse():l;return 1===d.length?this.setActiveObject(d[0],t):d.length>1&&(this._activeSelection.add(...d),this.setActiveObject(this._activeSelection,t)),this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const Qr={x1:0,y1:0,x2:0,y2:0},$r=i(i({},Qr),{},{r1:0,r2:0}),tn=/^(\d+\.\d+)%|(\d+)%$/;function en(t){return t&&tn.test(t)}function sn(t,e){const i="number"==typeof t?t:"string"==typeof t?parseFloat(t)/(en(t)?100:1):NaN;return Re(0,Y(i,e),1)}const rn=/\s*;\s*/,nn=/\s*:\s*/;function on(t,e){let i,s;const r=t.getAttribute("style");if(r){const t=r.split(rn);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){const[r,n]=t[e].split(nn).map((t=>t.trim()));"stop-color"===r?i=n:"stop-opacity"===r&&(s=n)}}const n=new Dt(i||t.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:sn(t.getAttribute("offset"),0),color:n.toRgb(),opacity:Y(parseFloat(s||t.getAttribute("stop-opacity")||""),1)*n.getAlpha()*e}}function an(t,e){const i=[],s=t.getElementsByTagName("stop"),r=sn(e,1);for(let t=s.length;t--;)i.push(on(s[t],r));return i}function hn(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function cn(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}function ln(t,e){return t.getAttribute(e)}function dn(t,e){return function(t,e){let i,{width:s,height:r,gradientUnits:n}=e;return Object.keys(t).reduce(((e,o)=>{const a=t[o];return"Infinity"===a?i=1:"-Infinity"===a?i=0:(i="string"==typeof a?parseFloat(a):a,"string"==typeof a&&en(a)&&(i*=.01,"pixels"===n&&("x1"!==o&&"x2"!==o&&"r2"!==o||(i*=s),"y1"!==o&&"y2"!==o||(i*=r)))),e[o]=i,e}),{})}("linear"===hn(t)?function(t){return{x1:ln(t,"x1")||0,y1:ln(t,"y1")||0,x2:ln(t,"x2")||"100%",y2:ln(t,"y2")||0}}(t):function(t){return{x1:ln(t,"fx")||ln(t,"cx")||"50%",y1:ln(t,"fy")||ln(t,"cy")||"50%",r1:0,x2:ln(t,"cx")||"50%",y2:ln(t,"cy")||"50%",r2:ln(t,"r")||"50%"}}(t),i(i({},e),{},{gradientUnits:cn(t)}))}class un{constructor(t){let{type:e="linear",gradientUnits:s="pixels",coords:r,colorStops:n=[],offsetX:o=0,offsetY:a=0,gradientTransform:h,id:c}=t;this.id=c?"".concat(c,"_").concat(Z()):Z(),this.type=e,this.gradientUnits=s,this.gradientTransform=h,this.offsetX=o,this.offsetY=a,this.coords=i(i({},"radial"===this.type?$r:Qr),r),this.colorStops=n.slice()}addColorStop(t){for(const e in t){const i=new Dt(t[e]);this.colorStops.push({offset:parseFloat(e),color:i.toRgb(),opacity:i.getAlpha()})}return this}toObject(t){return i(i({},xt(this,t)),{},{type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[],r=this.gradientTransform?this.gradientTransform.concat():w.concat(),n="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map((t=>i({},t))).sort(((t,e)=>t.offset-e.offset));let a=-this.offsetX,h=-this.offsetY;var c;"objectBoundingBox"===n?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),(c=t)&&c.isType("Path")&&"percentage"!==this.gradientUnits&&(a-=t.pathOffset.x,h-=t.pathOffset.y),r[4]-=a,r[5]-=h;const l=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(At(r),'"'),""].join(" ");if("linear"===this.type){const{x1:t,y1:e,x2:i,y2:r}=this.coords;s.push("<linearGradient ",l,' x1="',t,'" y1="',e,'" x2="',i,'" y2="',r,'">\n')}else if("radial"===this.type){const{x1:t,y1:e,x2:i,y2:r,r1:n,r2:a}=this.coords,h=n>a;s.push("<radialGradient ",l,' cx="',h?t:i,'" cy="',h?e:r,'" r="',h?n:a,'" fx="',h?i:t,'" fy="',h?r:e,'">\n'),h&&(o.reverse(),o.forEach((t=>{t.offset=1-t.offset})));const c=Math.min(n,a);if(c>0){const t=c/Math.max(n,a);o.forEach((e=>{e.offset+=t*(1-e.offset)}))}}return o.forEach((t=>{let{color:e,offset:i,opacity:r}=t;s.push("<stop ",'offset="',100*i+"%",'" style="stop-color:',e,void 0!==r?";stop-opacity: "+r:";",'"/>\n')})),s.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),s.join("")}toLive(t){const e=this.coords,i="linear"===this.type?t.createLinearGradient(e.x1,e.y1,e.x2,e.y2):t.createRadialGradient(e.x1,e.y1,e.r1,e.x2,e.y2,e.r2);return this.colorStops.forEach((t=>{let{color:e,opacity:s,offset:r}=t;i.addColorStop(r,void 0!==s?new Dt(e).setAlpha(s).toRgba():e)})),i}static fromElement(t,e,s){const r=cn(t),n=e._findCenterFromElement();return new this(i({id:t.getAttribute("id")||void 0,type:hn(t),coords:dn(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:an(t,s.opacity),gradientUnits:r,gradientTransform:As(t.getAttribute("gradientTransform")||"")},"pixels"===r?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}s(un,"type","Gradient"),R.setClass(un,"gradient");const gn=["source"];class fn{get type(){return"pattern"}set type(t){console.warn("Setting type has no effect",t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"repeat","repeat"),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"crossOrigin",""),s(this,"patternTransform",null),this.id=Z(),Object.assign(this,t)}isImageSource(){return!!this.source&&"string"==typeof this.source.src}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&0!==this.source.naturalWidth&&0!==this.source.naturalHeight)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return i(i({},xt(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Mt(this.offsetX,h.NUM_FRACTION_DIGITS),offsetY:Mt(this.offsetY,h.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:i}=t;const{source:s,repeat:r,id:n}=this,o=Y(this.offsetX/e,0),a=Y(this.offsetY/i,0),h="repeat-y"===r||"no-repeat"===r?1+Math.abs(o||0):Y(s.width/e,0),c="repeat-x"===r||"no-repeat"===r?1+Math.abs(a||0):Y(s.height/i,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(a,'" width="').concat(h,'" height="').concat(c,'">'),'<image x="0" y="0" width="'.concat(s.width,'" height="').concat(s.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join("\n")}static async fromObject(t,e){let{source:s}=t,n=r(t,gn);const o=await vt(s,i(i({},e),{},{crossOrigin:n.crossOrigin}));return new this(i(i({},n),{},{source:o}))}}s(fn,"type","Pattern"),R.setClass(fn),R.setClass(fn,"pattern");class pn{constructor(t){s(this,"color","rgb(0, 0, 0)"),s(this,"width",1),s(this,"shadow",null),s(this,"strokeLineCap","round"),s(this,"strokeLineJoin","round"),s(this,"strokeMiterLimit",10),s(this,"strokeDashArray",null),s(this,"limitedToCanvasSize",!1),this.canvas=t}_setBrushStyles(t){t.strokeStyle=this.color,t.lineWidth=this.width,t.lineCap=this.strokeLineCap,t.miterLimit=this.strokeMiterLimit,t.lineJoin=this.strokeLineJoin,t.setLineDash(this.strokeDashArray||[])}_saveAndTransform(t){const e=this.canvas.viewportTransform;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}needsFullRender(){return new Dt(this.color).getAlpha()<1||!!this.shadow}_setShadow(){if(!this.shadow||!this.canvas)return;const t=this.canvas,e=this.shadow,i=t.contextTop,s=t.getZoom()*t.getRetinaScaling();i.shadowColor=e.color,i.shadowBlur=e.blur*s,i.shadowOffsetX=e.offsetX*s,i.shadowOffsetY=e.offsetY*s}_resetShadow(){const t=this.canvas.contextTop;t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0}_isOutSideCanvas(t){return t.x<0||t.x>this.canvas.getWidth()||t.y<0||t.y>this.canvas.getHeight()}}const mn=["path","left","top"],vn=["d"];class _n extends Ni{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{path:i,left:s,top:n}=e;super(r(e,mn)),this._setPath(t||[],!0),"number"==typeof s&&this.set(D,s),"number"==typeof n&&this.set(M,n)}_setPath(t,e){this.path=br(Array.isArray(t)?t:Lr(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new z(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){let e=0,i=0,s=0,r=0,n=0,o=0;const a=-this.pathOffset.x,h=-this.pathOffset.y;t.beginPath();for(const c of this.path)switch(c[0]){case"L":s=c[1],r=c[2],t.lineTo(s+a,r+h);break;case"M":s=c[1],r=c[2],e=s,i=r,t.moveTo(s+a,r+h);break;case"C":s=c[5],r=c[6],n=c[3],o=c[4],t.bezierCurveTo(c[1]+a,c[2]+h,n+a,o+h,s+a,r+h);break;case"Q":t.quadraticCurveTo(c[1]+a,c[2]+h,c[3]+a,c[4]+h),s=c[3],r=c[4],n=c[1],o=c[2];break;case"Z":s=e,r=i,t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),{},{path:hi(this.path)})}toDatalessObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=Br(this.path,h.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,'" stroke-linecap="round" />\n')]}_getOffsetTransform(){const t=h.NUM_FRACTION_DIGITS;return" translate(".concat(Mt(-this.pathOffset.x,t),", ").concat(Mt(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:i,pathOffset:s}=this._calcDimensions();this.set({width:e,height:i,pathOffset:s}),t&&this.setPositionByOrigin(s,k,k)}_calcBoundsFromPath(){const t=[];let e=0,i=0,s=0,r=0;for(const n of this.path)switch(n[0]){case"L":s=n[1],r=n[2],t.push(new z(e,i),new z(s,r));break;case"M":s=n[1],r=n[2],e=s,i=r;break;case"C":t.push(...xr(s,r,n[1],n[2],n[3],n[4],n[5],n[6])),s=n[5],r=n[6];break;case"Q":t.push(...xr(s,r,n[1],n[2],n[1],n[2],n[3],n[4])),s=n[3],r=n[4];break;case"Z":s=e,r=i}return ie(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return i(i({},t),{},{pathOffset:new z(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const n=Bs(t,this.ATTRIBUTE_NAMES,s),{d:o}=n;return new this(o,i(i(i({},r(n,vn)),e),{},{left:void 0,top:void 0}))}}s(_n,"type","Path"),s(_n,"cacheProperties",[...li,"path","fillRule"]),s(_n,"ATTRIBUTE_NAMES",[...Ki,"d"]),R.setClass(_n),R.setSVGClass(_n);class yn extends pn{constructor(t){super(t),s(this,"decimate",.4),s(this,"drawStraightLine",!1),s(this,"straightLineKey","shiftKey"),this._points=[],this._hasStraightLine=!1}needsFullRender(){return super.needsFullRender()||this._hasStraightLine}static drawSegment(t,e,i){const s=e.midPointFrom(i);return t.quadraticCurveTo(e.x,e.y,s.x,s.y),s}onMouseDown(t,e){let{e:i}=e;this.canvas._isMainEvent(i)&&(this.drawStraightLine=!!this.straightLineKey&&i[this.straightLineKey],this._prepareForDrawing(t),this._addPoint(t),this._render())}onMouseMove(t,e){let{e:i}=e;if(this.canvas._isMainEvent(i)&&(this.drawStraightLine=!!this.straightLineKey&&i[this.straightLineKey],(!0!==this.limitedToCanvasSize||!this._isOutSideCanvas(t))&&this._addPoint(t)&&this._points.length>1))if(this.needsFullRender())this.canvas.clearContext(this.canvas.contextTop),this._render();else{const t=this._points,e=t.length,i=this.canvas.contextTop;this._saveAndTransform(i),this.oldEnd&&(i.beginPath(),i.moveTo(this.oldEnd.x,this.oldEnd.y)),this.oldEnd=yn.drawSegment(i,t[e-2],t[e-1]),i.stroke(),i.restore()}}onMouseUp(t){let{e:e}=t;return!this.canvas._isMainEvent(e)||(this.drawStraightLine=!1,this.oldEnd=void 0,this._finalizeAndAddPath(),!1)}_prepareForDrawing(t){this._reset(),this._addPoint(t),this.canvas.contextTop.moveTo(t.x,t.y)}_addPoint(t){return!(this._points.length>1&&t.eq(this._points[this._points.length-1]))&&(this.drawStraightLine&&this._points.length>1&&(this._hasStraightLine=!0,this._points.pop()),this._points.push(t),!0)}_reset(){this._points=[],this._setBrushStyles(this.canvas.contextTop),this._setShadow(),this._hasStraightLine=!1}_render(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.contextTop,e=this._points[0],i=this._points[1];if(this._saveAndTransform(t),t.beginPath(),2===this._points.length&&e.x===i.x&&e.y===i.y){const t=this.width/1e3;e.x-=t,i.x+=t}t.moveTo(e.x,e.y);for(let s=1;s<this._points.length;s++)yn.drawSegment(t,e,i),e=this._points[s],i=this._points[s+1];t.lineTo(e.x,e.y),t.stroke(),t.restore()}convertPointsToSVGPath(t){const e=this.width/1e3;return Rr(t,e)}createPath(t){const e=new _n(t,{fill:null,stroke:this.color,strokeWidth:this.width,strokeLineCap:this.strokeLineCap,strokeMiterLimit:this.strokeMiterLimit,strokeLineJoin:this.strokeLineJoin,strokeDashArray:this.strokeDashArray});return this.shadow&&(this.shadow.affectStroke=!0,e.shadow=new ai(this.shadow)),e}decimatePoints(t,e){if(t.length<=2)return t;let i,s=t[0];const r=this.canvas.getZoom(),n=Math.pow(e/r,2),o=t.length-1,a=[s];for(let e=1;e<o-1;e++)i=Math.pow(s.x-t[e].x,2)+Math.pow(s.y-t[e].y,2),i>=n&&(s=t[e],a.push(s));return a.push(t[o]),a}_finalizeAndAddPath(){this.canvas.contextTop.closePath(),this.decimate&&(this._points=this.decimatePoints(this._points,this.decimate));const t=this.convertPointsToSVGPath(this._points);if(function(t){return"M 0 0 Q 0 0 0 0 L 0 0"===Br(t)}(t))return void this.canvas.requestRenderAll();const e=this.createPath(t);this.canvas.clearContext(this.canvas.contextTop),this.canvas.fire("before:path:created",{path:e}),this.canvas.add(e),this.canvas.requestRenderAll(),e.setCoords(),this._resetShadow(),this.canvas.fire("path:created",{path:e})}}const xn=["left","top","radius"],Cn=["radius","startAngle","endAngle"];class bn extends Ni{static getDefaults(){return i(i({},super.getDefaults()),bn.ownDefaults)}_set(t,e){return super._set(t,e),"radius"===t&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,et(this.startAngle),et(this.endAngle),!1),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get("scaleX")}getRadiusY(){return this.get("radius")*this.get("scaleY")}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([...Cn,...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,i=et(this.startAngle),s=et(this.endAngle),r=V(i)*e,n=G(i)*e,o=V(s)*e,a=G(s)*e,h=t>180?"1":"0";return['<path d="M '.concat(r," ").concat(n)," A ".concat(e," ").concat(e)," 0 ","".concat(h," 1")," ".concat(o," ").concat(a),'" ',"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,s){const n=Bs(t,this.ATTRIBUTE_NAMES,s),{left:o=0,top:a=0,radius:h=0}=n;return new this(i(i({},r(n,xn)),{},{radius:h,left:o-h,top:a-h}))}static fromObject(t){return super._fromObject(t)}}s(bn,"type","Circle"),s(bn,"cacheProperties",[...li,...Cn]),s(bn,"ownDefaults",{radius:0,startAngle:0,endAngle:360}),s(bn,"ATTRIBUTE_NAMES",["cx","cy","r",...Ki]),R.setClass(bn),R.setSVGClass(bn);const Sn=["x1","y1","x2","y2"],wn=["x1","y1","x2","y2"],Tn=["x1","x2","y1","y2"];class On extends Ni{constructor(){let[t,e,s,r]=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0,0,0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i(i({},n),{},{x1:t,y1:e,x2:s,y2:r})),this._setWidthHeight();const{left:o,top:a}=n;"number"==typeof o&&this.set(D,o),"number"==typeof a&&this.set(M,a)}_setWidthHeight(){const{x1:t,y1:e,x2:i,y2:s}=this;this.width=Math.abs(i-t),this.height=Math.abs(s-e);const{left:r,top:n,width:o,height:a}=ie([{x:t,y:e},{x:i,y:s}]),h=new z(r+o/2,n+a/2);this.setPositionByOrigin(h,k,k)}_set(t,e){return super._set(t,e),Tn.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const i=t.strokeStyle;var s;Lt(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=null!==(s=this.stroke)&&void 0!==s?s:t.fillStyle;this.stroke&&this._renderStroke(t),t.strokeStyle=i}_findCenterFromElement(){return new z((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:i,y2:s,width:r,height:n}=this,o=t<=e?-1:1,a=i<=s?-1:1;return{x1:o*r/2,x2:o*-r/2,y1:a*n/2,y2:a*-n/2}}_toSVG(){const{x1:t,x2:e,y1:i,y2:s}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(i,'" x2="').concat(e,'" y2="').concat(s,'" />\n')]}static async fromElement(t,e,i){const s=Bs(t,this.ATTRIBUTE_NAMES,i),{x1:n=0,y1:o=0,x2:a=0,y2:h=0}=s;return new this([n,o,a,h],r(s,Sn))}static fromObject(t){let{x1:e,y1:s,x2:n,y2:o}=t,a=r(t,wn);return this._fromObject(i(i({},a),{},{points:[e,s,n,o]}),{extraParam:"points"})}}s(On,"type","Line"),s(On,"cacheProperties",[...li,...Tn]),s(On,"ATTRIBUTE_NAMES",Ki.concat(Tn)),R.setClass(On),R.setSVGClass(On);class kn extends Ni{static getDefaults(){return i(i({},super.getDefaults()),kn.ownDefaults)}_render(t){const e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,i),t.lineTo(0,-i),t.lineTo(e,i),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}s(kn,"type","Triangle"),s(kn,"ownDefaults",{width:100,height:100}),R.setClass(kn),R.setSVGClass(kn);const Dn=["rx","ry"];class Mn extends Ni{static getDefaults(){return i(i({},super.getDefaults()),Mn.ownDefaults)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get("scaleX")}getRy(){return this.get("ry")*this.get("scaleY")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Dn,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,'" />\n')]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,b,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,i){const s=Bs(t,this.ATTRIBUTE_NAMES,i);return s.left=(s.left||0)-s.rx,s.top=(s.top||0)-s.ry,new this(s)}}function Pn(t){if(!t)return[];const e=t.replace(/,/g," ").trim().split(/\s+/),i=[];for(let t=0;t<e.length;t+=2)i.push({x:parseFloat(e[t]),y:parseFloat(e[t+1])});return i}s(Mn,"type","Ellipse"),s(Mn,"cacheProperties",[...li,...Dn]),s(Mn,"ownDefaults",{rx:0,ry:0}),s(Mn,"ATTRIBUTE_NAMES",[...Ki,"cx","cy","rx","ry"]),R.setClass(Mn),R.setSVGClass(Mn);const En=["left","top"],An={exactBoundingBox:!1};class jn extends Ni{static getDefaults(){return i(i({},super.getDefaults()),jn.ownDefaults)}constructor(){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i({points:arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]},t)),s(this,"strokeDiff",void 0);const{left:e,top:r}=t;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof e&&this.set(D,e),"number"==typeof r&&this.set(M,r)}isOpen(){return!0}_projectStrokeOnPoints(t){return qs(this.points,t,this.isOpen())}_calcDimensions(t){t=i({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map((t=>t.projectedPoint)):this.points;if(0===e.length)return{left:0,top:0,width:0,height:0,pathOffset:new z,strokeOffset:new z,strokeDiff:new z};const s=ie(e),r=pt(i(i({},t),{},{scaleX:1,scaleY:1})),n=ie(this.points.map((t=>rt(t,r,!0)))),o=s.left+s.width/2,a=s.top+s.height/2,h=o-a*Math.tan(et(this.skewX)),c=a-h*Math.tan(et(this.skewY)),l=new z(this.scaleX,this.scaleY);return i(i({},s),{},{pathOffset:new z(h,c),strokeOffset:new z(n.left,n.top).subtract(new z(s.left,s.top)).multiply(l),strokeDiff:new z(s.width,s.height).subtract(new z(n.width,n.height)).multiply(l)})}_findCenterFromElement(){const t=ie(this.points);return new z(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:i,width:s,height:r,pathOffset:n,strokeOffset:o,strokeDiff:a}=this._calcDimensions();this.set({width:s,height:r,pathOffset:n,strokeOffset:o,strokeDiff:a}),t&&this.setPositionByOrigin(new z(e+s/2,i+r/2),k,k)}_getNonTransformedDimensions(){return this.exactBoundingBox?new z(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.exactBoundingBox){let n;if(Object.keys(t).some((t=>this.strokeUniform||this.constructor.layoutProperties.includes(t)))){var e,i;const{width:s,height:r}=this._calcDimensions(t);n=new z(null!==(e=t.width)&&void 0!==e?e:s,null!==(i=t.height)&&void 0!==i?i:r)}else{var s,r;n=new z(null!==(s=t.width)&&void 0!==s?s:this.width,null!==(r=t.height)&&void 0!==r?r:this.height)}return n.multiply(new z(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const i=this.initialized&&this[t]!==e,s=super._set(t,e);return this.exactBoundingBox&&i&&(("scaleX"===t||"scaleY"===t)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),s}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),{},{points:hi(this.points)})}_toSVG(){const t=[],e=this.pathOffset.x,i=this.pathOffset.y,s=h.NUM_FRACTION_DIGITS;for(let r=0,n=this.points.length;r<n;r++)t.push(Mt(this.points[r].x-e,s),",",Mt(this.points[r].y-i,s)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),'" />\n')]}_render(t){const e=this.points.length,i=this.pathOffset.x,s=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-i,this.points[0].y-s);for(let r=0;r<e;r++){const e=this.points[r];t.lineTo(e.x-i,e.y-s)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(Pn(t.getAttribute("points")),i(i({},r(Bs(t,this.ATTRIBUTE_NAMES,s),En)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}s(jn,"ownDefaults",An),s(jn,"type","Polyline"),s(jn,"layoutProperties",["skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),s(jn,"cacheProperties",[...li,"points"]),s(jn,"ATTRIBUTE_NAMES",[...Ki]),R.setClass(jn),R.setSVGClass(jn);class Fn extends jn{static getDefaults(){return i(i({},super.getDefaults()),jn.ownDefaults)}isOpen(){return!1}}s(Fn,"ownDefaults",An),s(Fn,"type","Polygon"),R.setClass(Fn),R.setSVGClass(Fn);const Ln=["fontSize","fontWeight","fontFamily","fontStyle"],Rn=["underline","overline","linethrough"],Bn=[...Ln,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],In=[...Bn,...Rn,"textBackgroundColor","direction"],Xn=[...Ln,...Rn,"stroke","strokeWidth","fill","deltaY","textBackgroundColor"],Yn={_reNewline:j,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:D,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:D,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},Wn="justify",Vn="justify-left",Gn="justify-right",zn="justify-center";class Hn extends Ni{isEmptyStyles(t){if(!this.styles)return!0;if(void 0!==t&&!this.styles[t])return!0;const e=void 0===t?this.styles:{line:this.styles[t]};for(const t in e)for(const i in e[t])for(const s in e[t][i])return!1;return!0}styleHas(t,e){if(!this.styles)return!1;if(void 0!==e&&!this.styles[e])return!1;const i=void 0===e?this.styles:{0:this.styles[e]};for(const e in i)for(const s in i[e])if(void 0!==i[e][s][t])return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let i,s,r=0,n=!0,o=0;for(const o in e){i=0;for(const a in e[o]){const h=e[o][a]||{};r++,void 0!==h[t]?(s?h[t]!==s&&(n=!1):s=h[t],h[t]===this[t]&&delete h[t]):n=!1,0!==Object.keys(h).length?i++:delete e[o][a]}0===i&&delete e[o]}for(let t=0;t<this._textLines.length;t++)o+=this._textLines[t].length;n&&r===o&&(this[t]=s,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let i,s,r;for(s in e){for(r in i=e[s],i)delete i[r][t],0===Object.keys(i[r]).length&&delete i[r];0===Object.keys(i).length&&delete e[s]}}_extendStyles(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);this._getLineStyle(i)||this._setLineStyle(i),Object.keys(this._getStyleDeclaration(i,s)).length||this._setStyleDeclaration(i,s,{}),Object.assign(this._getStyleDeclaration(i,s),e)}getSelectionStyles(t,e,i){const s=[];for(let r=t;r<(e||t);r++)s.push(this.getStyleAtPosition(r,i));return s}getStyleAtPosition(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(i,s):this._getStyleDeclaration(i,s)}setSelectionStyles(t,e,i){for(let s=e;s<(i||e);s++)this._extendStyles(s,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var i;const s=this.styles&&this.styles[t];return s&&null!==(i=s[e])&&void 0!==i?i:{}}getCompleteStyleDeclaration(t,e){return i(i({},xt(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,i){this.styles[t][e]=i}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}s(Hn,"_styleProperties",Xn);const Un=/ +/g,Nn=/"/g;function qn(t,e,i,s,r){return"\t\t".concat(Ft(t,{left:e,top:i,width:s,height:r}),"\n")}const Kn=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Jn;class Zn extends Hn{static getDefaults(){return i(i({},super.getDefaults()),Zn.ownDefaults)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i(i({},e),{},{text:t,styles:(null==e?void 0:e.styles)||{}})),s(this,"__charBounds",[]),this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=jr(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(Wn)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,r,n,o;for(let a=0,h=this._textLines.length;a<h;a++)if((this.textAlign===Wn||a!==h-1&&!this.isEndOfWrapping(a))&&(s=0,r=this._textLines[a],e=this.getLineWidth(a),e<this.width&&(o=this.textLines[a].match(this._reSpacesAndTabs)))){i=o.length,t=(this.width-e)/i;for(let e=0;e<=r.length;e++)n=this.__charBounds[a][e],this._reSpaceAndTab.test(r[e])?(n.width+=t,n.kernedWidth+=t,n.left+=s,s+=t):n.left+=s}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const i=e?this._unwrappedTextLines:this._textLines;let s;for(s=0;s<i.length;s++){if(t<=i[s].length)return{lineIndex:s,charIndex:t};t-=i[s].length+this.missingNewlineOffset(s,e)}return{lineIndex:s-1,charIndex:i[s-1].length<t?i[s-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,i){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case k:t.textBaseline="middle";break;case"ascender":t.textBaseline=M;break;case"descender":t.textBaseline=P}t.font=this._getFontDeclaration(e,i)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,i=this._textLines.length;e<i;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,i,s,r,n){this._renderChars(t,e,i,s,r,n)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,i=this._getLeftOffset();let s=this._getTopOffset();for(let e=0,r=this._textLines.length;e<r;e++){const r=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){s+=r;continue}const n=this._textLines[e].length,o=this._getLineLeftOffset(e);let a,h,c=0,l=0,d=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let u=0;u<n;u++){const n=this.__charBounds[e][u];h=this.getValueOfPropertyAt(e,u,"textBackgroundColor"),this.path?(t.save(),t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillStyle=h,h&&t.fillRect(-n.width/2,-r/this.lineHeight*(1-this._fontSizeFraction),n.width,r/this.lineHeight),t.restore()):h!==d?(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=d,d&&t.fillRect(a,s,c,r/this.lineHeight),l=n.left,c=n.width,d=h):c+=n.kernedWidth}h&&!this.path&&(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=h,t.fillRect(a,s,c,r/this.lineHeight)),s+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,s){const r=_.getFontCache(e),n=this._getFontDeclaration(e),o=i+t,a=i&&n===this._getFontDeclaration(s),h=e.fontSize/this.CACHE_FONT_SIZE;let c,l,d,u;if(i&&void 0!==r[i]&&(d=r[i]),void 0!==r[t]&&(u=c=r[t]),a&&void 0!==r[o]&&(l=r[o],u=l-d),void 0===c||void 0===d||void 0===l){const s=(Jn||(Jn=Q().getContext("2d")),Jn);this._setTextStyles(s,e,!0),void 0===c&&(u=c=s.measureText(t).width,r[t]=c),void 0===d&&a&&i&&(d=s.measureText(i).width,r[i]=d),a&&void 0===l&&(l=s.measureText(o).width,r[o]=l,u=l-d)}return{width:c*h,kernedWidth:u*h}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,i,s=0;const r=this.pathSide===E,n=this.path,o=this._textLines[t],a=o.length,h=new Array(a);this.__charBounds[t]=h;for(let r=0;r<a;r++){const n=o[r];i=this._getGraphemeBox(n,t,r,e),h[r]=i,s+=i.kernedWidth,e=n}if(h[a]={left:i?i.left+i.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},n&&n.segmentsInfo){let t=0;const e=n.segmentsInfo[n.segmentsInfo.length-1].length;switch(this.textAlign){case D:t=r?e-s:0;break;case k:t=(e-s)/2;break;case E:t=r?0:e-s}t+=this.pathStartOffset*(r?-1:1);for(let s=r?a-1:0;r?s>=0:s<a;r?s--:s++)i=h[s],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,i),t+=i.kernedWidth}return{width:s,numOfSpaces:0}}_setGraphemeOnPath(t,e){const i=t+e.kernedWidth/2,s=this.path,r=Fr(s.path,i,s.segmentsInfo);e.renderLeft=r.x-s.pathOffset.x,e.renderTop=r.y-s.pathOffset.y,e.angle=r.angle+(this.pathSide===E?Math.PI:0)}_getGraphemeBox(t,e,i,s,r){const n=this.getCompleteStyleDeclaration(e,i),o=s?this.getCompleteStyleDeclaration(e,i-1):{},a=this._measureChar(t,n,s,o);let h,c=a.kernedWidth,l=a.width;0!==this.charSpacing&&(h=this._getWidthOfCharSpacing(),l+=h,c+=h);const d={width:l,left:0,height:n.fontSize,kernedWidth:c,deltaY:n.deltaY};if(i>0&&!r){const t=this.__charBounds[e][i-1];d.left=t.left+t.width+a.kernedWidth-a.width}return d}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let i=1,s=this._textLines[t].length;i<s;i++)e=Math.max(this.getHeightOfChar(t,i),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let i=0,s=this._textLines.length;i<s;i++)t=this.getHeightOfLine(i),e+=i===s-1?t/this.lineHeight:t;return e}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let i=0;const s=this._getLeftOffset(),r=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const o=this.getHeightOfLine(n),a=o/this.lineHeight,h=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],s+h,r+i+a,n),i+=o}t.restore()}_renderTextFill(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,i,s,r,n){const o=this.getHeightOfLine(n),a=this.textAlign.includes(Wn),h=this.path,c=!a&&0===this.charSpacing&&this.isEmptyStyles(n)&&!h,l="ltr"===this.direction,d="ltr"===this.direction?1:-1,u=e.direction;let g,f,p,m,v,_="",y=0;if(e.save(),u!==this.direction&&(e.canvas.setAttribute("dir",l?"ltr":"rtl"),e.direction=l?"ltr":"rtl",e.textAlign=l?D:E),r-=o*this._fontSizeFraction/this.lineHeight,c)return this._renderChar(t,e,n,0,i.join(""),s,r),void e.restore();for(let o=0,c=i.length-1;o<=c;o++)m=o===c||this.charSpacing||h,_+=i[o],p=this.__charBounds[n][o],0===y?(s+=d*(p.kernedWidth-p.width),y+=p.width):y+=p.kernedWidth,a&&!m&&this._reSpaceAndTab.test(i[o])&&(m=!0),m||(g=g||this.getCompleteStyleDeclaration(n,o),f=this.getCompleteStyleDeclaration(n,o+1),m=Ks(g,f,!1)),m&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,n,o,_,-y/2,0),e.restore()):(v=s,this._renderChar(t,e,n,o,_,v,r)),_="",g=f,s+=d*y,y=0);e.restore()}_applyPatternGradientTransformText(t){const e=Q(),i=this.width+this.strokeWidth,s=this.height+this.strokeWidth,r=e.getContext("2d");return e.width=i,e.height=s,r.beginPath(),r.moveTo(0,0),r.lineTo(i,0),r.lineTo(i,s),r.lineTo(0,s),r.closePath(),r.translate(i/2,s/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(e,"no-repeat")}handleFiller(t,e,i){let s,r;return Lt(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?(s=-this.width/2,r=-this.height/2,t.translate(s,r),t[e]=this._applyPatternGradientTransformText(i),{offsetX:s,offsetY:r}):(t[e]=i.toLive(t),this._applyPatternGradientTransform(t,i)):(t[e]=i,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:i,strokeWidth:s}=e;return t.lineWidth=s,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",i)}_setFillStyles(t,e){let{fill:i}=e;return this.handleFiller(t,"fillStyle",i)}_renderChar(t,e,i,s,r,n,o){const a=this._getStyleDeclaration(i,s),h=this.getCompleteStyleDeclaration(i,s),c="fillText"===t&&h.fill,l="strokeText"===t&&h.stroke&&h.strokeWidth;if(l||c){if(e.save(),e.font=this._getFontDeclaration(h),a.textBackgroundColor&&this._removeShadow(e),a.deltaY&&(o+=a.deltaY),c){const t=this._setFillStyles(e,h);e.fillText(r,n-t.offsetX,o-t.offsetY)}if(l){const t=this._setStrokeStyles(e,h);e.strokeText(r,n-t.offsetX,o-t.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,i){const s=this.get2DCursorLocation(t,!0),r=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"fontSize"),n=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"deltaY"),o={fontSize:r*i.size,deltaY:n+r*i.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),i=this.width-e,s=this.textAlign,r=this.direction,n=this.isEndOfWrapping(t);let o=0;return s===Wn||s===zn&&!n||s===Gn&&!n||s===Vn&&!n?0:(s===k&&(o=i/2),s===E&&(o=i),s===zn&&(o=i/2),s===Gn&&(o=i),"rtl"===r&&(s===E||s===Wn||s===Gn?o=0:s===D||s===Vn?o=-i:s!==k&&s!==zn||(o=-i/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,i){var s;return null!==(s=this._getStyleDeclaration(t,e)[i])&&void 0!==s?s:this[i]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let i=this._getTopOffset();const s=this._getLeftOffset(),r=this.path,n=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let a=0,h=this._textLines.length;a<h;a++){const h=this.getHeightOfLine(a);if(!this[e]&&!this.styleHas(e,a)){i+=h;continue}const c=this._textLines[a],l=h/this.lineHeight,d=this._getLineLeftOffset(a);let u,g,f=0,p=0,m=this.getValueOfPropertyAt(a,0,e),v=this.getValueOfPropertyAt(a,0,"fill");const _=i+l*(1-this._fontSizeFraction);let y=this.getHeightOfChar(a,0),x=this.getValueOfPropertyAt(a,0,"deltaY");for(let i=0,n=c.length;i<n;i++){const n=this.__charBounds[a][i];u=this.getValueOfPropertyAt(a,i,e),g=this.getValueOfPropertyAt(a,i,"fill");const h=this.getHeightOfChar(a,i),c=this.getValueOfPropertyAt(a,i,"deltaY");if(r&&u&&g)t.save(),t.fillStyle=v,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,o*h+c,n.kernedWidth,this.fontSize/15),t.restore();else if((u!==m||g!==v||h!==y||c!==x)&&p>0){let e=s+d+f;"rtl"===this.direction&&(e=this.width-e-p),m&&v&&(t.fillStyle=v,t.fillRect(e,_+o*y+x,p,this.fontSize/15)),f=n.left,p=n.width,m=u,v=g,y=h,x=c}else p+=n.kernedWidth}let C=s+d+f;"rtl"===this.direction&&(C=this.width-C-p),t.fillStyle=g,u&&g&&t.fillRect(C,_+o*y+x,p-n,this.fontSize/15),i+=h}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:i=this.fontWeight,fontSize:s=this.fontSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;const n=t.includes("'")||t.includes('"')||t.includes(",")||Zn.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,i,"".concat(r?this.CACHE_FONT_SIZE:s,"px"),n].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return er(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),i=new Array(e.length),s=["\n"];let r=[];for(let t=0;t<e.length;t++)i[t]=this.graphemeSplit(e[t]),r=r.concat(i[t],s);return r.pop(),{_unwrappedLines:i,lines:e,graphemeText:r,graphemeLines:i}}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject([...In,...t])),{},{styles:Js(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:i}=this.constructor;super.set(t,e);let s=!1,r=!1;if("object"==typeof t)for(const e in t)"path"===e&&this.setPathInfo(),s=s||i.includes(e),r=r||"path"===e;else s=i.includes(t),r="path"===t;return r&&this.setPathInfo(),s&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const n=Bs(t,Zn.ATTRIBUTE_NAMES,s),o=i(i({},e),n),{textAnchor:a=D,textDecoration:h="",dx:c=0,dy:l=0,top:d=0,left:u=0,fontSize:g=T,strokeWidth:f=1}=o,p=r(o,Kn),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),i({left:u+c,top:d+l,underline:h.includes("underline"),overline:h.includes("overline"),linethrough:h.includes("line-through"),strokeWidth:0,fontSize:g},p)),v=m.getScaledHeight()/m.height,_=((m.height+m.strokeWidth)*m.lineHeight-m.height)*v,y=m.getScaledHeight()+_;let x=0;return a===k&&(x=m.getScaledWidth()/2),a===E&&(x=m.getScaledWidth()),m.set({left:m.left-x,top:m.top-(y-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(i(i({},t),{},{styles:Zs(t.styles||{},t.text)}),{extraParam:"text"})}}s(Zn,"textLayoutProperties",Bn),s(Zn,"cacheProperties",[...li,...In]),s(Zn,"ownDefaults",Yn),s(Zn,"type","Text"),s(Zn,"genericFonts",["sans-serif","serif","cursive","fantasy","monospace"]),s(Zn,"ATTRIBUTE_NAMES",Ki.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Ui(Zn,[class extends Se{_toSVG(){const t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(t){let{textBgRects:e,textSpans:i}=t;const s=this.getSvgTextDecoration(this);return[e.join(""),'\t\t<text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(Nn,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"","rtl"===this.direction?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",i.join(""),"</text>\n"]}_getSVGTextAndBg(t,e){const i=[],s=[];let r,n=t;this.backgroundColor&&s.push(...qn(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let t=0,o=this._textLines.length;t<o;t++)r=this._getLineLeftOffset(t),"rtl"===this.direction&&(r+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",t))&&this._setSVGTextLineBg(s,t,e+r,n),this._setSVGTextLineText(i,t,e+r,n),n+=this.getHeightOfLine(t);return{textSpans:i,textBgRects:s}}_createTextCharSpan(t,e,i,s){const r=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(Un)),n=r?'style="'.concat(r,'"'):"",o=e.deltaY,a=o?' dy="'.concat(Mt(o,h.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Mt(i,h.NUM_FRACTION_DIGITS),'" y="').concat(Mt(s,h.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(tr(t),"</tspan>")}_setSVGTextLineText(t,e,i,s){const r=this.getHeightOfLine(e),n=this.textAlign.includes(Wn),o=this._textLines[e];let a,h,c,l,d,u="",g=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let r=0,f=o.length-1;r<=f;r++)d=r===f||this.charSpacing,u+=o[r],c=this.__charBounds[e][r],0===g?(i+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(o[r])&&(d=!0),d||(a=a||this.getCompleteStyleDeclaration(e,r),h=this.getCompleteStyleDeclaration(e,r+1),d=Ks(a,h,!0)),d&&(l=this._getStyleDeclaration(e,r),t.push(this._createTextCharSpan(u,l,i,s)),u="",a=h,"rtl"===this.direction?i-=g:i+=g,g=0)}_setSVGTextLineBg(t,e,i,s){const r=this._textLines[e],n=this.getHeightOfLine(e)/this.lineHeight;let o,a=0,h=0,c=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let l=0;l<r.length;l++){const{left:r,width:d,kernedWidth:u}=this.__charBounds[e][l];o=this.getValueOfPropertyAt(e,l,"textBackgroundColor"),o!==c?(c&&t.push(...qn(c,i+h,s,a,n)),h=r,a=d,c=o):a+=u}o&&t.push(...qn(c,i+h,s,a,n))}_getSVGLineTopOffset(t){let e,i=0;for(e=0;e<t;e++)i+=this.getHeightOfLine(e);const s=this.getHeightOfLine(e);return{lineTop:i,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(t){return"".concat(super.getSvgStyles(t)," white-space: pre;")}getSvgSpanStyles(t,e){const{fontFamily:i,strokeWidth:s,stroke:r,fill:n,fontSize:o,fontStyle:a,fontWeight:h,deltaY:c}=t,l=this.getSvgTextDecoration(t);return[r?jt("stroke",r):"",s?"stroke-width: ".concat(s,"; "):"",i?"font-family: ".concat(i.includes("'")||i.includes('"')?i:"'".concat(i,"'"),"; "):"",o?"font-size: ".concat(o,"px; "):"",a?"font-style: ".concat(a,"; "):"",h?"font-weight: ".concat(h,"; "):"",l?"text-decoration: ".concat(l,"; "):l,n?jt("fill",n):"",c?"baseline-shift: ".concat(-c,"; "):"",e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter((e=>t[e.replace("-","")])).join(" ")}}]),R.setClass(Zn),R.setSVGClass(Zn);class Qn{constructor(t){s(this,"target",void 0),s(this,"__mouseDownInPlace",!1),s(this,"__dragStartFired",!1),s(this,"__isDraggingOver",!1),s(this,"__dragStartSelection",void 0),s(this,"__dragImageDisposer",void 0),s(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach((t=>t())),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,i=e.getSelectionStartFromPointer(t);return e.isEditing&&i>=e.selectionStart&&i<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var i;let{selectionStart:s,selectionEnd:r}=e;const n=this.target,o=n.canvas,a=new z(n.flipX?-1:1,n.flipY?-1:1),h=n._getCursorBoundaries(s),c=new z(h.left+h.leftOffset,h.top+h.topOffset).multiply(a).transform(n.calcTransformMatrix()),l=o.getPointer(t).subtract(c),d=o._isRetinaScaling(),u=n.getCanvasRetinaScaling(),g=n.getBoundingRect(!0),f=c.subtract(new z(g.left,g.top)),p=o.viewportTransform,m=f.add(l).transform(p,!0),v=n.backgroundColor,_=hi(n.styles);n.backgroundColor="";const y={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};n.setSelectionStyles(y,0,s),n.setSelectionStyles(y,r,n.text.length),n.dirty=!0;const x=n.toCanvasElement({enableRetinaScaling:d,viewportTransform:!0});n.backgroundColor=v,n.styles=_,n.dirty=!0,Ht(x,{position:"fixed",left:"".concat(-x.width,"px"),border:A,width:"".concat(x.width/u,"px"),height:"".concat(x.height/u,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{x.remove()},Gt(t.target||this.target.hiddenTextarea).body.appendChild(x),null===(i=t.dataTransfer)||void 0===i||i.setDragImage(x,m.x,m.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const s=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},r=e._text.slice(s.selectionStart,s.selectionEnd).join(""),n=i({text:e.text,value:r},s);t.dataTransfer.setData("text/plain",r),t.dataTransfer.setData("application/fabric",JSON.stringify({value:r,styles:e.getSelectionStyles(s.selectionStart,s.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,n)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),i=this.__dragStartSelection;return e<i.selectionStart||e>i.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e:e}=t;const i=this.targetCanDrop(e);!this.__isDraggingOver&&i&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e:e}=t,i=this.targetCanDrop(e);!this.__isDraggingOver&&i?this.__isDraggingOver=!0:this.__isDraggingOver&&!i&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:i}=t,s=i.defaultPrevented;this.__isDraggingOver=!1,i.preventDefault();let r=null===(e=i.dataTransfer)||void 0===e?void 0:e.getData("text/plain");if(r&&!s){const e=this.target,s=e.canvas;let n=e.getSelectionStartFromPointer(i);const{styles:o}=i.dataTransfer.types.includes("application/fabric")?JSON.parse(i.dataTransfer.getData("application/fabric")):{},a=r[Math.max(0,r.length-1)],h=0;if(this.__dragStartSelection){const t=this.__dragStartSelection.selectionStart,i=this.__dragStartSelection.selectionEnd;n>t&&n<=i?n=t:n>i&&(n-=i-t),e.removeChars(t,i),delete this.__dragStartSelection}e._reNewline.test(a)&&(e._reNewline.test(e._text[n])||n===e._text.length)&&(r=r.trimEnd()),t.didDrop=!0,t.dropTarget=e,e.insertChars(r,o,n),s.setActiveObject(e),e.enterEditing(i),e.selectionStart=Math.min(n+h,e._text.length),e.selectionEnd=Math.min(e.selectionStart+r.length,e._text.length),e.hiddenTextarea.value=e.text,e._updateTextarea(),e.hiddenTextarea.focus(),e.fire("changed",{index:n+h,action:"drop"}),s.fire("text:changed",{target:e}),s.contextTopDirty=!0,s.requestRenderAll()}}dragEndHandler(t){let{e:e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var i;const t=this.target,s=this.target.canvas,{selectionStart:r,selectionEnd:n}=this.__dragStartSelection,o=(null===(i=e.dataTransfer)||void 0===i?void 0:i.dropEffect)||A;o===A?(t.selectionStart=r,t.selectionEnd=n,t._updateTextarea(),t.hiddenTextarea.focus()):(t.clearContextTop(),"move"===o&&(t.removeChars(r,n),t.selectionStart=t.selectionEnd=r,t.hiddenTextarea&&(t.hiddenTextarea.value=t.text),t._updateTextarea(),t.fire("changed",{index:r,action:"dragend"}),s.fire("text:changed",{target:t}),s.requestRenderAll()),t.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const $n=/[ \n\.,;!\?\-]/;class to extends Zn{constructor(){super(...arguments),s(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:i,delay:s,onComplete:r}=t;return Ve({startValue:this._currentCursorOpacity,endValue:e,duration:i,delay:s,onComplete:r,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:t=>{this._currentCursorOpacity=t,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:1,duration:this.cursorDuration,delay:t,onComplete:this._onTickComplete})}_onTickComplete(){var t;null===(t=this._currentTickCompleteState)||void 0===t||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:100,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,i=t-1;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i--;for(;/\S/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findWordBoundaryRight(t){let e=0,i=t;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i++;for(;/\S/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}findLineBoundaryLeft(t){let e=0,i=t-1;for(;!/\n/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findLineBoundaryRight(t){let e=0,i=t;for(;!/\n/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}searchWordBoundary(t,e){const i=this._text;let s=t>0&&this._reSpace.test(i[t])&&(-1===e||!j.test(i[t-1]))?t-1:t,r=i[s];for(;s>0&&s<i.length&&!$n.test(r);)s+=e,r=i[s];return-1===e&&$n.test(r)&&s++,s}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),i=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Gt(e).activeElement!==e&&e.focus();const i=this.getSelectionStartFromPointer(t),s=this.selectionStart,r=this.selectionEnd;(i===this.__selectionStartOnMouseDown&&s!==r||s!==i&&r!==i)&&(i>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=i):(this.selectionStart=i,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===s&&this.selectionEnd===r||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,i){const s=i.slice(0,t),r=this.graphemeSplit(s).length;if(t===e)return{selectionStart:r,selectionEnd:r};const n=i.slice(t,e);return{selectionStart:r,selectionEnd:r+this.graphemeSplit(n).length}}fromGraphemeToStringSelection(t,e,i){const s=i.slice(0,t).join("").length;if(t===e)return{selectionStart:s,selectionEnd:s};return{selectionStart:s,selectionEnd:s+i.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),i=this.get2DCursorLocation(t),s=i.lineIndex,r=i.charIndex,n=this.getValueOfPropertyAt(s,r,"fontSize")*this.lineHeight,o=e.leftOffset,a=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,c=h.width/a,l=h.height/a,d=c-n,u=l-n,g=new z(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new z(h.clientWidth/c,h.clientHeight/l));return g.x<0&&(g.x=0),g.x>d&&(g.x=d),g.y<0&&(g.y=0),g.y>u&&(g.y=u),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t,!0),{lineIndex:r,charIndex:n}=this.get2DCursorLocation(e,!0);if(i!==r){if(this.styles[i])for(let t=s;t<this._unwrappedTextLines[i].length;t++)delete this.styles[i][t];if(this.styles[r])for(let t=n;t<this._unwrappedTextLines[r].length;t++){const e=this.styles[r][t];e&&(this.styles[i]||(this.styles[i]={}),this.styles[i][s+t-n]=e)}for(let t=i+1;t<=r;t++)delete this.styles[t];this.shiftLineStyles(r,i-r)}else if(this.styles[i]){const t=this.styles[i],e=n-s;for(let e=s;e<n;e++)delete t[e];for(const s in this.styles[i]){const i=parseInt(s,10);i>=n&&(t[i-e]=t[s],delete t[s])}}}shiftLineStyles(t,e){const i=Object.assign({},this.styles);for(const s in this.styles){const r=parseInt(s,10);r>t&&(this.styles[r+e]=i[r],i[r-e]||delete this.styles[r])}}insertNewlineStyleObject(t,e,s,r){const n={},o=this._unwrappedTextLines[t].length===e;let a=!1;s||(s=1),this.shiftLineStyles(t,s);const h=this.styles[t]?this.styles[t][0===e?e:e-1]:void 0;for(const i in this.styles[t]){const s=parseInt(i,10);s>=e&&(a=!0,n[s-e]=this.styles[t][i],o&&0===e||delete this.styles[t][i])}let c=!1;for(a&&!o&&(this.styles[t+s]=n,c=!0),c&&s--;s>0;)r&&r[s-1]?this.styles[t+s]={0:i({},r[s-1])}:h?this.styles[t+s]={0:i({},h)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,r){this.styles||(this.styles={});const n=this.styles[t],o=n?i({},n):{};s||(s=1);for(const t in o){const i=parseInt(t,10);i>=e&&(n[i+s]=o[i],o[i-s]||delete n[i])}if(this._forceClearCache=!0,r){for(;s--;)Object.keys(r[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=i({},r[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=i({},a)}insertNewStyleBlock(t,e,i){const s=this.get2DCursorLocation(e,!0),r=[0];let n,o=0;for(let e=0;e<t.length;e++)"\n"===t[e]?(o++,r[o]=0):r[o]++;for(r[0]>0&&(this.insertCharStyleObject(s.lineIndex,s.charIndex,r[0],i),i=i&&i.slice(r[0]+1)),o&&this.insertNewlineStyleObject(s.lineIndex,s.charIndex+r[0],o),n=1;n<o;n++)r[n]>0?this.insertCharStyleObject(s.lineIndex+n,0,r[n],i):i&&this.styles[s.lineIndex+n]&&i[0]&&(this.styles[s.lineIndex+n][0]=i[0]),i=i&&i.slice(r[n]+1);r[n]>0&&this.insertCharStyleObject(s.lineIndex+n,0,r[n],i)}removeChars(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i;s>i&&this.removeStyleFromTo(i,s);const r=this.graphemeSplit(t);this.insertNewStyleBlock(r,i,e),this._text=[...this._text.slice(0,i),...r,...this._text.slice(s)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,i){i<=t?(e===t?this._selectionDirection=D:this._selectionDirection===E&&(this._selectionDirection=D,this.selectionEnd=t),this.selectionStart=i):i>t&&i<e?this._selectionDirection===E?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection=E:this._selectionDirection===D&&(this._selectionDirection=E,this.selectionStart=e),this.selectionEnd=i)}}class eo extends to{initHiddenTextarea(){const t=this.canvas&&Gt(this.canvas.getElement())||m(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map((t=>{let[i,s]=t;return e.setAttribute(i,s)}));const{top:i,left:s,fontSize:r}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(i,"; left: ").concat(s,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(r,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",onCompositionUpdate:"onCompositionEnd"}).map((t=>{let[i,s]=t;return e.addEventListener(i,this[s].bind(this))})),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e="rtl"===this.direction?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const i=()=>{this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void i();const s=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,r=this._text.length,n=s.length,o=this.selectionStart,a=this.selectionEnd,c=o!==a;let l,d,u,g,f=n-r;const m=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),v=o>m.selectionStart;c?(d=this._text.slice(o,a),f+=a-o):n<r&&(d=v?this._text.slice(a+f,a):this._text.slice(o,o-f));const _=s.slice(m.selectionEnd-f,m.selectionEnd);if(d&&d.length&&(_.length&&(l=this.getSelectionStyles(o,o+1,!1),l=_.map((()=>l[0]))),c?(u=o,g=a):v?(u=a-d.length,g=a):(u=a,g=a+d.length),this.removeStyleFromTo(u,g)),_.length){const{copyPasteData:t}=p();e&&_.join("")===t.copiedText&&!h.disableStyleCopyPaste&&(l=t.copiedTextStyle),this.insertNewStyleBlock(_,o,l)}i()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:i,selectionEnd:s}=e;this.compositionStart=i,this.compositionEnd=s,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=p();t.copiedText=this.getSelectedText(),h.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let i,s=this._getLineLeftOffset(t);return e>0&&(i=this.__charBounds[t][e-1],s+=i.left+i.width),s}getDownCursorOffset(t,e){const i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(r===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-i;const n=s.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r+1,o);return this._textLines[r].slice(n).length+a+1+this.missingNewlineOffset(r)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(0===r||t.metaKey||33===t.keyCode)return-i;const n=s.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r-1,o),h=this._textLines[r].slice(0,n),c=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+a-h.length+(1-c)}_getIndexOnLine(t,e){const i=this._textLines[t];let s,r,n=this._getLineLeftOffset(t),o=0;for(let a=0,h=i.length;a<h;a++)if(s=this.__charBounds[t][a].width,n+=s,n>e){r=!0;const t=n-s,i=n,h=Math.abs(t-e);o=Math.abs(i-e)<h?a:a-1;break}return r||(o=i.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const i=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===E);if(e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i){const t=this.text.length;this.selectionStart=Re(0,this.selectionStart,t),this.selectionEnd=Re(0,this.selectionEnd,t),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===D?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),0!==t}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t}moveCursorLeft(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorLeftOrRight("Left",t)}_move(t,e,i){let s;if(t.altKey)s=this["findWordBoundary".concat(i)](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===i?-1:1,!0;s=this["findLineBoundary".concat(i)](this[e])}return void 0!==s&&this[e]!==s&&(this[e]=s,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=D,this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===E&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection=D,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const i="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[i](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===D&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=E,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=E,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}function io(t){return t.button&&1!==t.button}class so extends eo{constructor(){super(...arguments),s(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new Qn(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),ee(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e:e}=t;this.canvas&&this.editable&&!io(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e:e}=t;this.canvas&&this.editable&&!io(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e:e,transform:i,button:s}=t;const r=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const t=this.canvas._activeObject;if(t&&t!==this)return}!this.editable||this.group&&!this.group.interactive||i&&i.actionPerformed||io(e)||r||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),i=this.selectionStart,s=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(i,s,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getPointer(t).transform(nt(this.calcTransformMatrix())).add(new z(-this._getLeftOffset(),-this._getTopOffset()));let i=0,s=0,r=0;for(let t=0;t<this._textLines.length&&i<=e.y;t++)i+=this.getHeightOfLine(t),r=t,t>0&&(s+=this._textLines[t-1].length+this.missingNewlineOffset(t-1));let n=Math.abs(this._getLineLeftOffset(r));const o=this._textLines[r].length,a=this.__charBounds[r];for(let t=0;t<o;t++){const i=n+a[t].kernedWidth;if(e.x<=i){Math.abs(e.x-i)<=Math.abs(e.x-n)&&s++;break}n=i,s++}return Math.min(this.flipX?o-s:s,this._text.length)}}const ro="moveCursorUp",no="moveCursorDown",oo="moveCursorLeft",ao="moveCursorRight",ho="exitEditing",co={selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1,keysMap:{9:ho,27:ho,33:ro,34:no,35:ao,36:oo,37:oo,38:ro,39:ao,40:no},keysMapRtl:{9:ho,27:ho,33:ro,34:no,35:oo,36:ao,37:ao,38:ro,39:oo,40:no},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}};class lo extends so{static getDefaults(){return i(i({},super.getDefaults()),lo.ownDefaults)}get type(){const t=super.type;return"itext"===t?"i-text":t}constructor(t,e){super(t,e),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof Zr&&this.canvas.textEditingManager.remove(this),e instanceof Zr&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart||0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionEnd,i=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,i)}setSelectionStyles(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionStart||0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,i)}get2DCursorLocation(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const i=super.toCanvasElement(t);return this.isEditing=e,i}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const i=this._getLeftOffset(),s=this._getTopOffset(),r=this._getCursorBoundariesOffsets(t,e);return{left:i,top:s,leftOffset:r.left,topOffset:r.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,i=0;const{charIndex:s,lineIndex:r}=this.get2DCursorLocation(t);for(let t=0;t<r;t++)e+=this.getHeightOfLine(t);const n=this._getLineLeftOffset(r),o=this.__charBounds[r][s];o&&(i=o.left),0!==this.charSpacing&&s===this._textLines[r].length&&(i-=this._getWidthOfCharSpacing());const a={top:e,left:n+(i>0?i:0)};return"rtl"===this.direction&&(this.textAlign===E||this.textAlign===Wn||this.textAlign===Gn?a.left*=-1:this.textAlign===D||this.textAlign===Vn?a.left=n-(i>0?i:0):this.textAlign!==k&&this.textAlign!==zn||(a.left=n-(i>0?i:0))),a}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,i){const s=this.get2DCursorLocation(i),r=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,o=this.getValueOfPropertyAt(r,n,"fontSize"),a=this.scaleX*this.canvas.getZoom(),h=this.cursorWidth/a,c=this.getValueOfPropertyAt(r,n,"deltaY"),l=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(r)/this.lineHeight-o*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(r,n,"fill"),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-h/2,l+e.top+c,h,o)}renderSelection(t,e){const i={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,i,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,i){const s=e.selectionStart,r=e.selectionEnd,n=this.textAlign.includes(Wn),o=this.get2DCursorLocation(s),a=this.get2DCursorLocation(r),h=o.lineIndex,c=a.lineIndex,l=o.charIndex<0?0:o.charIndex,d=a.charIndex<0?0:a.charIndex;for(let e=h;e<=c;e++){const s=this._getLineLeftOffset(e)||0;let r=this.getHeightOfLine(e),o=0,a=0,u=0;if(e===h&&(a=this.__charBounds[h][l].left),e>=h&&e<c)u=n&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===c)if(0===d)u=this.__charBounds[c][d].left;else{const t=this._getWidthOfCharSpacing();u=this.__charBounds[c][d-1].left+this.__charBounds[c][d-1].width-t}o=r,(this.lineHeight<1||e===c&&this.lineHeight>1)&&(r/=this.lineHeight);let g=i.left+s+a,f=r,p=0;const m=u-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",f=1,p=r):t.fillStyle=this.selectionColor,"rtl"===this.direction&&(this.textAlign===E||this.textAlign===Wn||this.textAlign===Gn?g=this.width-g-m:this.textAlign===D||this.textAlign===Vn?g=i.left+s-u:this.textAlign!==k&&this.textAlign!==zn||(g=i.left+s-u)),t.fillRect(g,i.top+i.topOffset+p,m,f),i.topOffset+=o}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fill")}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}s(lo,"ownDefaults",co),s(lo,"type","IText"),R.setClass(lo),R.setClass(lo,"i-text");class uo extends lo{static getDefaults(){return i(i({},super.getDefaults()),{},{controls:zi()},uo.ownDefaults)}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(Wn)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,i=0,s=0;const r={};for(let n=0;n<t.graphemeLines.length;n++)"\n"===t.graphemeText[s]&&n>0?(i=0,s++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[s])&&n>0&&(i++,s++),r[n]={line:e,offset:i},s+=t.graphemeLines[n].length,i+=t.graphemeLines[n].length;return r}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const t=this._styleMap[e];t&&(e=t.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,i=0,s=t+1,r=!1;const n=this._styleMap[t],o=this._styleMap[t+1];n&&(t=n.line,i=n.offset),o&&(s=o.line,r=s===t,e=o.offset);const a=void 0===t?this.styles:{line:this.styles[t]};for(const t in a)for(const s in a[t]){const n=parseInt(s,10);if(n>=i&&(!r||n<e))for(const e in a[t][s])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const i=this._styleMap[t];if(!i)return{};t=i.line,e=i.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,i){const s=this._styleMap[t];t=s.line,e=s.offset+e,this.styles[t][e]=i}_deleteStyleDeclaration(t,e){const i=this._styleMap[t];t=i.line,e=i.offset+e,delete this.styles[t][e]}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];this.styles[e.line]={}}_wrapText(t,e){this.isWrapping=!0;const i=this.getGraphemeDataForRender(t),s=[];for(let t=0;t<i.wordsData.length;t++)s.push(...this._wrapLine(t,e,i));return this.isWrapping=!1,s}getGraphemeDataForRender(t){const e=this.splitByGrapheme,i=e?"":" ";let s=0;return{wordsData:t.map(((t,r)=>{let n=0;const o=e?this.graphemeSplit(t):this.wordSplit(t);return 0===o.length?[{word:[],width:0}]:o.map((t=>{const o=e?[t]:this.graphemeSplit(t),a=this._measureWord(o,r,n);return s=Math.max(a,s),n+=o.length+i.length,{word:o,width:a}}))})),largestWordWidth:s}}_measureWord(t,e){let i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=0;for(let n=0,o=t.length;n<o;n++){r+=this._getGraphemeBox(t[n],e,n+s,i,true).kernedWidth,i=t[n]}return r}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,i){let{largestWordWidth:s,wordsData:r}=i,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=this._getWidthOfCharSpacing(),a=this.splitByGrapheme,h=[],c=a?"":" ";let l=0,d=[],u=0,g=0,f=!0;e-=n;const p=Math.max(e,s,this.dynamicMinWidth),m=r[t];let v;for(u=0,v=0;v<m.length;v++){const{word:e,width:i}=m[v];u+=e.length,l+=g+i-o,l>p&&!f?(h.push(d),d=[],l=i,f=!0):l+=o,f||a||d.push(c),d=d.concat(e),g=a?0:this._measureWord([c],t,u),u++,f=!1}return v&&h.push(d),s+n>this.dynamicMinWidth&&(this.dynamicMinWidth=s-o+n),h}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),i=this._wrapText(e.lines,this.width),s=new Array(i.length);for(let t=0;t<i.length;t++)s[t]=i[t].join("");return e.lines=s,e.graphemeLines=i,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const i=parseInt(e,10);if(this._textLines[i]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}s(uo,"type","Textbox"),s(uo,"textLayoutProperties",[...lo.textLayoutProperties,"width"]),s(uo,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),R.setClass(uo);class go{constructor(){s(this,"resources",{})}applyFilters(t,e,i,s,r){const n=r.getContext("2d");if(!n)return;n.drawImage(e,0,0,i,s);const o={sourceWidth:i,sourceHeight:s,imageData:n.getImageData(0,0,i,s),originalEl:e,originalImageData:n.getImageData(0,0,i,s),canvasEl:r,ctx:n,filterBackend:this};t.forEach((t=>{t.applyTo(o)}));const{imageData:a}=o;return a.width===i&&a.height===s||(r.width=a.width,r.height=a.height),n.putImageData(a,0,0),o}}class fo{constructor(){let{tileSize:t=h.textureSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),s(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e),this.chooseFastestCopyGLTo2DMethod(t,e)}chooseFastestCopyGLTo2DMethod(t,e){const i=Q(),s=new ArrayBuffer(t*e*4);if(h.forceGLPutImageData)return this.imageBuffer=s,void(this.copyGLTo2D=po);const r={imageBuffer:s},n={destinationWidth:t,destinationHeight:e,targetCanvas:i};let o;i.width=t,i.height=e,o=v().performance.now(),this.copyGLTo2D.call(r,this.gl,n);const a=v().performance.now()-o;o=v().performance.now(),po.call(r,this.gl,n);a>v().performance.now()-o&&(this.imageBuffer=s,this.copyGLTo2D=po)}createWebGLCanvas(t,e){const i=Q();i.width=t,i.height=e;const s=i.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});s&&(s.clearColor(0,0,0,0),this.canvas=i,this.gl=s)}applyFilters(t,e,i,s,r,n){const o=this.gl,a=r.getContext("2d");if(!o||!a)return;let h;n&&(h=this.getCachedTexture(n,e));const c={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:i,sourceHeight:s,destinationWidth:i,destinationHeight:s,context:o,sourceTexture:this.createTexture(o,i,s,h?void 0:e),targetTexture:this.createTexture(o,i,s),originalTexture:h||this.createTexture(o,i,s,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:r},l=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,l),t.forEach((t=>{t&&t.applyTo(c)})),function(t){const e=t.targetCanvas,i=e.width,s=e.height,r=t.destinationWidth,n=t.destinationHeight;i===r&&s===n||(e.width=r,e.height=n)}(c),this.copyGLTo2D(o,c),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(c.sourceTexture),o.deleteTexture(c.targetTexture),o.deleteFramebuffer(l),a.setTransform(1,0,0,1,0,0),c}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,i,s,r){const{NEAREST:n,TEXTURE_2D:o,RGBA:a,UNSIGNED_BYTE:h,CLAMP_TO_EDGE:c,TEXTURE_MAG_FILTER:l,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:u,TEXTURE_WRAP_T:g}=t,f=t.createTexture();return t.bindTexture(o,f),t.texParameteri(o,l,r||n),t.texParameteri(o,d,r||n),t.texParameteri(o,u,c),t.texParameteri(o,g,c),s?t.texImage2D(o,0,a,a,h,s):t.texImage2D(o,0,a,e,i,0,a,h,null),f}getCachedTexture(t,e,i){const{textureCache:s}=this;if(s[t])return s[t];{const r=this.createTexture(this.gl,e.width,e.height,e,i);return r&&(s[t]=r),r}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const i=t.canvas,s=e.targetCanvas,r=s.getContext("2d");if(!r)return;r.translate(0,s.height),r.scale(1,-1);const n=i.height-s.height;r.drawImage(i,0,n,s.width,s.height,0,0,s.width,s.height)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const i=t.getExtension("WEBGL_debug_renderer_info");if(i){const s=t.getParameter(i.UNMASKED_RENDERER_WEBGL),r=t.getParameter(i.UNMASKED_VENDOR_WEBGL);s&&(e.renderer=s.toLowerCase()),r&&(e.vendor=r.toLowerCase())}return this.gpuInfo=e,e}}function po(t,e){const i=e.targetCanvas.getContext("2d"),s=e.destinationWidth,r=e.destinationHeight,n=s*r*4;if(!i)return;const o=new Uint8Array(this.imageBuffer,0,n),a=new Uint8ClampedArray(this.imageBuffer,0,n);t.readPixels(0,0,s,r,t.RGBA,t.UNSIGNED_BYTE,o);const h=new ImageData(a,s,r);i.putImageData(h,0,0)}let mo;function vo(){const{WebGLProbe:t}=p();return t.queryWebGL(Q()),h.enableGLFiltering&&t.isSupported(h.textureSize)?new fo({tileSize:h.textureSize}):new go}function _o(){return!mo&&(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(mo=vo()),mo}const yo=["filters","resizeFilter","src","crossOrigin"],xo=["cropX","cropY"];class Co extends Ni{static getDefaults(){return i(i({},super.getDefaults()),Co.ownDefaults)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i({filters:[]},e)),s(this,"_lastScaleX",1),s(this,"_lastScaleY",1),s(this,"_filterScalingX",1),s(this,"_filterScalingY",1),this.cacheKey="texture".concat(Z()),this.setElement("string"==typeof t?(this.canvas&&Gt(this.canvas.getElement())||m()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(Co.CSS_CANVAS),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=_o(!1);e instanceof fo&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach((t=>{const e=this[t];e&&p().dispose(e),this[t]=void 0}))}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||0===this.strokeWidth)return;const e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,-i),t.lineTo(e,-i),t.lineTo(e,i),t.lineTo(-e,i),t.lineTo(-e,-i),t.closePath()}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=[];return this.filters.forEach((t=>{t&&e.push(t.toObject())})),i(i({},super.toObject([...xo,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,i=-this.width/2,s=-this.height/2;let r=[],n=[],o="",a="";if(!e)return[];if(this.hasCrop()){const t=Z();r.push('<clipPath id="imageCrop_'+t+'">\n','\t<rect x="'+i+'" y="'+s+'" width="'+this.width+'" height="'+this.height+'" />\n',"</clipPath>\n"),o=' clip-path="url(#imageCrop_'+t+')" '}if(this.imageSmoothing||(a=' image-rendering="optimizeSpeed"'),t.push("\t<image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(i-this.cropX,'" y="').concat(s-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(a).concat(o,"></image>\n")),this.stroke||this.strokeDashArray){const t=this.fill;this.fill=null,n=['\t<rect x="'.concat(i,'" y="').concat(s,'" width="').concat(this.width,'" height="').concat(this.height,'" styles="').concat(this.getSvgStyles(),'" />\n')],this.fill=t}return r="fill"!==this.paintFirst?r.concat(n,t):r.concat(t,n),r}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return vt(t,{crossOrigin:e,signal:i}).then((t=>{void 0!==e&&this.set({crossOrigin:e}),this.setElement(t)}))}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,i=this.getTotalObjectScaling(),s=i.x,r=i.y,n=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||s>e&&r>e)return this._element=n,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=s,void(this._lastScaleY=r);const o=Q(),a=n.width,h=n.height;o.width=a,o.height=h,this._element=o,this._lastScaleX=t.scaleX=s,this._lastScaleY=t.scaleY=r,_o().applyFilters([t],n,a,h,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.filters||[];if(t=t.filter((t=>t&&!t.isNeutralState())),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),0===t.length)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,i=e.naturalWidth||e.width,s=e.naturalHeight||e.height;if(this._element===this._originalElement){const t=Q();t.width=i,t.height=s,this._element=t,this._filteredEl=t}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,i,s),this._lastScaleX=1,this._lastScaleY=1);_o().applyFilters(t,this._originalElement,i,s,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const i=this._filterScalingX,s=this._filterScalingY,r=this.width,n=this.height,o=Math.max(this.cropX,0),a=Math.max(this.cropY,0),h=e.naturalWidth||e.width,c=e.naturalHeight||e.height,l=o*i,d=a*s,u=Math.min(r*i,h-l),g=Math.min(n*s,c-d),f=-r/2,p=-n/2,m=Math.min(r,h/i-o),v=Math.min(n,c/s-a);e&&t.drawImage(e,l,d,u,g,f,p,m,v)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=this.getOriginalSize();this.width=t||i.width,this.height=e||i.height}parsePreserveAspectRatioAttribute(){const t=Et(this.preserveAspectRatio||""),e=this.width,i=this.height,s={width:e,height:i};let r,n=this._element.width,o=this._element.height,a=1,h=1,c=0,l=0,d=0,u=0;return!t||t.alignX===A&&t.alignY===A?(a=e/n,h=i/o):("meet"===t.meetOrSlice&&(a=h=Qs(this._element,s),r=(e-n*a)/2,"Min"===t.alignX&&(c=-r),"Max"===t.alignX&&(c=r),r=(i-o*h)/2,"Min"===t.alignY&&(l=-r),"Max"===t.alignY&&(l=r)),"slice"===t.meetOrSlice&&(a=h=$s(this._element,s),r=n-e/a,"Mid"===t.alignX&&(d=r/2),"Max"===t.alignX&&(d=r),r=o-i/h,"Mid"===t.alignY&&(u=r/2),"Max"===t.alignY&&(u=r),n=e/a,o=i/h)),{width:n,height:o,scaleX:a,scaleY:h,offsetLeft:c,offsetTop:l,cropX:d,cropY:u}}static fromObject(t){let{filters:e,resizeFilter:s,src:n,crossOrigin:o}=t,a=r(t,yo),h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Promise.all([vt(n,i(i({},h),{},{crossOrigin:o})),e&&_t(e,h),s&&_t([s],h),yt(a,h)]).then((t=>{let[e,s=[],[r]=[],o={}]=t;return new this(e,i(i({},a),{},{src:n,filters:s,resizeFilter:r},o))}))}static fromURL(t){let{crossOrigin:e=null,signal:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;return vt(t,{crossOrigin:e,signal:i}).then((t=>new this(t,s)))}static async fromElement(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;const s=Bs(t,this.ATTRIBUTE_NAMES,i);return this.fromURL(s["xlink:href"],e,s).catch((t=>(console.log(t),null)))}}function bo(t){if(!os.test(t.nodeName))return{};const e=t.getAttribute("viewBox");let i,s,r=1,n=1,o=0,a=0;const h=t.getAttribute("width"),c=t.getAttribute("height"),l=t.getAttribute("x")||0,d=t.getAttribute("y")||0,u=!(e&&hs.test(e)),g=!h||!c||"100%"===h||"100%"===c;let f="",p=0,m=0;if(u&&(l||d)&&t.parentNode&&"#document"!==t.parentNode.nodeName&&(f=" translate("+Pt(l||"0")+" "+Pt(d||"0")+") ",i=(t.getAttribute("transform")||"")+f,t.setAttribute("transform",i),t.removeAttribute("x"),t.removeAttribute("y")),u&&g)return{width:0,height:0};const v={width:0,height:0};if(u)return v.width=Pt(h),v.height=Pt(c),v;const _=e.match(hs);o=-parseFloat(_[1]),a=-parseFloat(_[2]);const y=parseFloat(_[3]),x=parseFloat(_[4]);v.minX=o,v.minY=a,v.viewBoxWidth=y,v.viewBoxHeight=x,g?(v.width=y,v.height=x):(v.width=Pt(h),v.height=Pt(c),r=v.width/y,n=v.height/x);const C=Et(t.getAttribute("preserveAspectRatio")||"");if(C.alignX!==A&&("meet"===C.meetOrSlice&&(n=r=r>n?n:r),"slice"===C.meetOrSlice&&(n=r=r>n?r:n),p=v.width-y*r,m=v.height-x*r,"Mid"===C.alignX&&(p/=2),"Mid"===C.alignY&&(m/=2),"Min"===C.alignX&&(p=0),"Min"===C.alignY&&(m=0)),1===r&&1===n&&0===o&&0===a&&0===l&&0===d)return v;if((l||d)&&"#document"!==t.parentNode.nodeName&&(f=" translate("+Pt(l||"0")+" "+Pt(d||"0")+") "),i=f+" matrix("+r+" 0 0 "+n+" "+(o*r+p)+" "+(a*n+m)+") ","svg"===t.nodeName){for(s=t.ownerDocument.createElementNS(ts,"g");t.firstChild;)s.appendChild(t.firstChild);t.appendChild(s)}else s=t,s.removeAttribute("x"),s.removeAttribute("y"),i=s.getAttribute("transform")+i;return s.setAttribute("transform",i),v}s(Co,"type","Image"),s(Co,"cacheProperties",[...li,...xo]),s(Co,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),s(Co,"CSS_CANVAS","canvas-img"),s(Co,"ATTRIBUTE_NAMES",[...Ki,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),R.setClass(Co),R.setSVGClass(Co);const So=Ji(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function wo(t,e){if(t.getElementById)return t.getElementById(e);const i=t.getElementsByTagName("*");for(let t=0,s=i.length;t<s;t++){const s=i[t];if(e===s.getAttribute("id"))return s}return null}function To(t,e){let i,s,r,n,o=[];for(r=0,n=e.length;r<n;r++)i=e[r],s=t.getElementsByTagNameNS("http://www.w3.org/2000/svg",i),o=o.concat(Array.from(s));return o}const Oo=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],ko="xlink:href";function Do(t,e){var i;const s=wo(t,(null===(i=e.getAttribute(ko))||void 0===i?void 0:i.slice(1))||"");if(s&&s.getAttribute(ko)&&Do(t,s),s&&(Oo.forEach((t=>{const i=s.getAttribute(t);!e.hasAttribute(t)&&i&&e.setAttribute(t,i)})),!e.children.length)){const t=s.cloneNode(!0);for(;t.firstChild;)e.appendChild(t.firstChild)}e.removeAttribute(ko)}const Mo=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Po(t){const e=t.getElementsByTagName("style");let s,r;const n={};for(s=0,r=e.length;s<r;s++){const t=(e[s].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");""!==t.trim()&&t.split("}").filter((function(t){return t.trim()})).forEach((function(t){const e=t.split("{"),o={},a=e[1].trim().split(";").filter((function(t){return t.trim()}));for(s=0,r=a.length;s<r;s++){const t=a[s].split(":"),e=t[0].trim(),i=t[1].trim();o[e]=i}(t=e[0].trim()).split(",").forEach((t=>{""!==(t=t.replace(/^svg/i,"").trim())&&(n[t]=i(i({},n[t]||{}),o))}))}))}return n}const Eo=t=>R.getSVGClass(t.tagName.toLowerCase().replace("svg:",""));class Ao{constructor(t,e,i,s,r){this.elements=t,this.options=e,this.reviver=i,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=s,this.clipPaths=r,this.gradientDefs=function(t){const e=To(t,Mo),i={};let s=e.length;for(;s--;){const r=e[s];r.getAttribute("xlink:href")&&Do(t,r);const n=r.getAttribute("id");n&&(i[n]=r)}return i}(s),this.cssRules=Po(s)}parse(){return Promise.all(this.elements.map((t=>this.createObject(t))))}async createObject(t){const e=Eo(t);if(e){const i=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(i,t,"fill"),this.resolveGradient(i,t,"stroke"),i instanceof Co&&i._originalElement?Xr(i,i.parsePreserveAspectRatioAttribute()):Xr(i),await this.resolveClipPath(i,t),this.reviver&&this.reviver(t,i),i}return null}extractPropertyDefinition(t,e,i){const s=t[e],r=this.regexUrl;if(!r.test(s))return;r.lastIndex=0;const n=r.exec(s)[1];return r.lastIndex=0,i[n]}resolveGradient(t,e,s){const r=this.extractPropertyDefinition(t,s,this.gradientDefs);if(r){const n=e.getAttribute(s+"-opacity"),o=un.fromElement(r,t,i(i({},this.options),{},{opacity:n}));t.set(s,o)}}async resolveClipPath(t,e){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const s=nt(t.calcTransformMatrix()),r=i[0].parentElement;let n=e;for(;n.parentElement&&n.getAttribute("clip-path")!==t.clipPath;)n=n.parentElement;n.parentElement.appendChild(r);const o=await Promise.all(i.map((t=>Eo(t).fromElement(t,this.options,this.cssRules).then((t=>(Xr(t),t.fillRule=t.clipRule,delete t.clipRule,t)))))),a=1===o.length?o[0]:new Vs(o),h=ot(s,a.calcTransformMatrix());a.clipPath&&await this.resolveClipPath(a,n);const{scaleX:c,scaleY:l,angle:d,skewX:u,translateX:g,translateY:f}=ht(h);a.set({flipX:!1,flipY:!1}),a.set({scaleX:c,scaleY:l,angle:d,skewX:u,skewY:0}),a.setPositionByOrigin(new z(g,f),k,k),t.clipPath=a}else delete t.clipPath}}const jo=t=>ns.test(t.nodeName.replace("svg:","")),Fo=()=>({objects:[],elements:[],options:{},allElements:[]});async function Lo(t,e){let{crossOrigin:s,signal:r}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(r&&r.aborted)return console.log("`options.signal` is in `aborted` state"),Fo();const n=t.documentElement;!function(t){const e=To(t,["use","svg:use"]);let i=0;for(;e.length&&i<e.length;){const s=e[i],r=s.getAttribute("xlink:href")||s.getAttribute("href");if(null===r)return;const n=r.slice(1),o=s.getAttribute("x")||0,a=s.getAttribute("y")||0;let h=wo(t,n).cloneNode(!0),c=(h.getAttribute("transform")||"")+" translate("+o+", "+a+")";const l=e.length,d=ts;if(bo(h),/^svg$/i.test(h.nodeName)){const t=h.ownerDocument.createElementNS(d,"g");for(let e=0,i=h.attributes,s=i.length;e<s;e++){const s=i.item(e);s&&t.setAttributeNS(d,s.nodeName,s.nodeValue)}for(;h.firstChild;)t.appendChild(h.firstChild);h=t}for(let t=0,e=s.attributes,i=e.length;t<i;t++){const i=e.item(t);if(!i)continue;const{nodeName:s,nodeValue:r}=i;"x"!==s&&"y"!==s&&"xlink:href"!==s&&"href"!==s&&("transform"===s?c=r+" "+c:h.setAttribute(s,r))}h.setAttribute("transform",c),h.setAttribute("instantiated_by_use","1"),h.removeAttribute("id"),s.parentNode.replaceChild(h,s),e.length===l&&i++}}(t);const o=Array.from(n.getElementsByTagName("*")),a=i(i({},bo(n)),{},{crossOrigin:s,signal:r}),h=o.filter((t=>(bo(t),jo(t)&&!function(t){let e=t;for(;e&&(e=e.parentElement);)if(e&&e.nodeName&&So.test(e.nodeName.replace("svg:",""))&&!e.getAttribute("instantiated_by_use"))return!0;return!1}(t))));if(!h||h&&!h.length)return i(i({},Fo()),{},{options:a,allElements:o});const c={};o.filter((t=>"clipPath"===t.nodeName.replace("svg:",""))).forEach((t=>{const e=t.getAttribute("id");c[e]=Array.from(t.getElementsByTagName("*")).filter((t=>jo(t)))}));const l=new Ao(h,a,e,t,c);return{objects:await l.parse(),elements:h,options:a,allElements:o}}const Ro=t=>function(e,i,s){var r,n;const o=s.points[t].x-s.pathOffset.x,a=s.points[t].y-s.pathOffset.y;return new z(o,a).transform(ot(null!==(r=null===(n=s.canvas)||void 0===n?void 0:n.viewportTransform)&&void 0!==r?r:w,s.calcTransformMatrix()))},Bo=(t,e,i,s)=>{const r=e.target,n=e.pointIndex,o=Ce(e,k,k,i,s),a=(t=>new z(t.width,t.height))(r),h=r._getTransformedDimensions(),c=a.divide(h),l=new z(r.flipX?-1:1,r.flipY?-1:1),d=o.multiply(l).multiply(c).add(r.pathOffset);return r.points[n]=d,r.setDimensions(),!0},Io=(t,e)=>function(s,r,n,o){const a=r.target,h=new z(a.points[(t>0?t:a.points.length)-1]),c=h.subtract(a.pathOffset).transform(a.calcOwnMatrix()),l=e(s,i(i({},r),{},{pointIndex:t}),n,o),d=new z(a.flipX?-1:1,a.flipY?-1:1),u=h.subtract(a.pathOffset).divide(a._getNonTransformedDimensions()).multiply(d);return a.setPositionByOrigin(c,u.x+.5,u.y+.5),l};var Xo=Object.freeze({__proto__:null,changeWidth:mi,createObjectDefaultControls:Vi,createPolyControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s={};for(let r=0;r<("number"==typeof t?t:t.points.length);r++)s["p".concat(r)]=new yi(i({actionName:"modifyPoly",positionHandler:Ro(r),actionHandler:Io(r,Bo)},e));return s},createResizeControls:Gi,createTextboxDefaultControls:zi,dragHandler:be,getLocalPoint:Ce,renderCircleControl:vi,renderSquareControl:_i,rotationStyleHandler:xi,rotationWithSnapping:Ci,scaleCursorStyleHandler:Ti,scaleOrSkewActionName:Ii,scaleSkewCursorStyleHandler:Xi,scalingEqually:ki,scalingX:Di,scalingXOrSkewingY:Yi,scalingY:Mi,scalingYOrSkewingX:Wi,skewCursorStyleHandler:ji,skewHandlerX:Li,skewHandlerY:Ri,wrapWithFireEvent:fi,wrapWithFixedAnchor:pi});const Yo=t=>void 0!==t.webgl,Wo="precision highp float",Vo="\n ".concat(Wo,";\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }"),Go=["type"],zo=["type"];class Ho{get type(){return this.constructor.type}constructor(){let t=r(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},Go);s(this,"vertexSource","\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n void main() {\n vTexCoord = aPosition;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }"),Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Vo}createProgram(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getFragmentSource(),i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.vertexSource;const{WebGLProbe:{GLPrecision:s="highp"}}=p();"highp"!==s&&(e=e.replace(new RegExp(Wo,"g"),Wo.replace("highp",s)));const r=t.createShader(t.VERTEX_SHADER),n=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!r||!n||!o)throw new Error("Vertex, fragment shader or program creation error");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error('Shader link error for "${this.type}" '+t.getProgramInfoLog(o));const a=this.getUniformLocations(t,o)||{};return a.uStepW=t.getUniformLocation(o,"uStepW"),a.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:a}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){return{}}sendAttributeData(t,e,i){const s=e.aPosition,r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,i,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const i=t.destinationWidth,s=t.destinationHeight;t.sourceWidth===i&&t.sourceHeight===s||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,i,s)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){const e=this.mainParameter,i=this.constructor.defaults[e];if(e){const t=this[e];return Array.isArray(i)&&Array.isArray(t)?i.every(((e,i)=>e===t[i])):i===t}return!1}applyTo(t){Yo(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,i=this.retrieveShader(t);0===t.pass&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(i.program),this.sendAttributeData(e,i.attributeLocations,t.aPosition),e.uniform1f(i.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(i.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,i.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,i){t.activeTexture(i),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}getMainParameter(){return this.mainParameter?this[this.mainParameter]:void 0}setMainParameter(t){this.mainParameter&&(this[this.mainParameter]=t)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const e=Q();e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}}toObject(){const t=this.mainParameter;return i({type:this.type},t?{[t]:this[t]}:{})}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(r(t,zo))}}s(Ho,"type","BaseFilter");const Uo={multiply:"gl_FragColor.rgb *= uColor.rgb;\n",screen:"gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);\n",add:"gl_FragColor.rgb += uColor.rgb;\n",difference:"gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);\n",subtract:"gl_FragColor.rgb -= uColor.rgb;\n",lighten:"gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);\n",darken:"gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);\n",exclusion:"gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);\n",overlay:"\n if (uColor.r < 0.5) {\n gl_FragColor.r *= 2.0 * uColor.r;\n } else {\n gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);\n }\n if (uColor.g < 0.5) {\n gl_FragColor.g *= 2.0 * uColor.g;\n } else {\n gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);\n }\n if (uColor.b < 0.5) {\n gl_FragColor.b *= 2.0 * uColor.b;\n } else {\n gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);\n }\n ",tint:"\n gl_FragColor.rgb *= (1.0 - uColor.a);\n gl_FragColor.rgb += uColor.rgb;\n "};class No extends Ho{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n gl_FragColor = color;\n if (color.a > 0.0) {\n ".concat(Uo[this.mode],"\n }\n }\n ")}applyTo2d(t){let{imageData:{data:e}}=t;const i=new Dt(this.color).getSource(),s=i[0]*this.alpha,r=i[1]*this.alpha,n=i[2]*this.alpha,o=1-this.alpha;for(let t=0;t<e.length;t+=4){const i=e[t],a=e[t+1],h=e[t+2];switch(this.mode){case"multiply":e[t]=i*s/255,e[t+1]=a*r/255,e[t+2]=h*n/255;break;case"screen":e[t]=255-(255-i)*(255-s)/255,e[t+1]=255-(255-a)*(255-r)/255,e[t+2]=255-(255-h)*(255-n)/255;break;case"add":e[t]=i+s,e[t+1]=a+r,e[t+2]=h+n;break;case"difference":e[t]=Math.abs(i-s),e[t+1]=Math.abs(a-r),e[t+2]=Math.abs(h-n);break;case"subtract":e[t]=i-s,e[t+1]=a-r,e[t+2]=h-n;break;case"darken":e[t]=Math.min(i,s),e[t+1]=Math.min(a,r),e[t+2]=Math.min(h,n);break;case"lighten":e[t]=Math.max(i,s),e[t+1]=Math.max(a,r),e[t+2]=Math.max(h,n);break;case"overlay":e[t]=s<128?2*i*s/255:255-2*(255-i)*(255-s)/255,e[t+1]=r<128?2*a*r/255:255-2*(255-a)*(255-r)/255,e[t+2]=n<128?2*h*n/255:255-2*(255-h)*(255-n)/255;break;case"exclusion":e[t]=s+i-2*s*i/255,e[t+1]=r+a-2*r*a/255,e[t+2]=n+h-2*n*h/255;break;case"tint":e[t]=s+i*o,e[t+1]=r+a*o,e[t+2]=n+h*o}}}getUniformLocations(t,e){return{uColor:t.getUniformLocation(e,"uColor")}}sendUniformData(t,e){const i=new Dt(this.color).getSource();i[0]=this.alpha*i[0]/255,i[1]=this.alpha*i[1]/255,i[2]=this.alpha*i[2]/255,i[3]=this.alpha,t.uniform4fv(e.uColor,i)}toObject(){return{type:this.type,color:this.color,mode:this.mode,alpha:this.alpha}}}s(No,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),s(No,"type","BlendColor"),R.setClass(No);const qo={multiply:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.rgba *= color2.rgba;\n gl_FragColor = color;\n }\n ",mask:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.a = color2.a;\n gl_FragColor = color;\n }\n "},Ko=["type","image"];class Jo extends Ho{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return qo[this.mode]}applyToWebGL(t){const e=t.context,i=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,i,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:i}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/i,1]}applyTo2d(t){let{imageData:{data:e,width:i,height:s},filterBackend:{resources:r}}=t;const n=this.image;r.blendImage||(r.blendImage=Q());const o=r.blendImage,a=o.getContext("2d");o.width!==i||o.height!==s?(o.width=i,o.height=s):a.clearRect(0,0,i,s),a.setTransform(n.scaleX,0,0,n.scaleY,n.left,n.top),a.drawImage(n.getElement(),0,0,i,s);const h=a.getImageData(0,0,i,s).data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2],n=e[t+3],o=h[t],a=h[t+1],c=h[t+2],l=h[t+3];switch(this.mode){case"multiply":e[t]=i*o/255,e[t+1]=s*a/255,e[t+2]=r*c/255,e[t+3]=n*l/255;break;case"mask":e[t+3]=l}}}getUniformLocations(t,e){return{uTransformMatrix:t.getUniformLocation(e,"uTransformMatrix"),uImage:t.getUniformLocation(e,"uImage")}}sendUniformData(t,e){const i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)}toObject(){return{type:this.type,image:this.image&&this.image.toObject(),mode:this.mode,alpha:this.alpha}}static fromObject(t,e){let{type:s,image:n}=t,o=r(t,Ko);return Co.fromObject(n,e).then((t=>new this(i(i({},o),{},{image:t}))))}}s(Jo,"type","BlendImage"),s(Jo,"defaults",{mode:"multiply",alpha:1,vertexSource:"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n uniform mat3 uTransformMatrix;\n void main() {\n vTexCoord = aPosition;\n vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }\n "}),R.setClass(Jo);class Zo extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n const float nSamples = 15.0;\n vec3 v3offset = vec3(12.9898, 78.233, 151.7182);\n float random(vec3 scale) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n }\n void main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n float offset = random(v3offset);\n for (float t = -nSamples; t <= nSamples; t++) {\n float percent = (t + offset - 0.5) / nSamples;\n float weight = 1.0 - abs(percent);\n color += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n }\n "}applyTo(t){Yo(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:i,filterBackend:{resources:s}}=t;const{width:r,height:n}=i;s.blurLayer1||(s.blurLayer1=Q(),s.blurLayer2=Q());const o=s.blurLayer1,a=s.blurLayer2;o.width===r&&o.height===n||(a.width=o.width=r,a.height=o.height=n);const h=o.getContext("2d"),c=a.getContext("2d"),l=15,d=.06*this.blur*.5;let u,g,f,p;for(h.putImageData(i,0,0),c.clearRect(0,0,r,n),p=-15;p<=l;p++)u=(Math.random()-.5)/4,g=p/l,f=d*g*r+u,c.globalAlpha=1-Math.abs(g),c.drawImage(o,f,u),h.drawImage(a,0,0),c.globalAlpha=1,c.clearRect(0,0,a.width,a.height);for(p=-15;p<=l;p++)u=(Math.random()-.5)/4,g=p/l,f=d*g*n+u,c.globalAlpha=1-Math.abs(g),c.drawImage(o,u,f),h.drawImage(a,0,0),c.globalAlpha=1,c.clearRect(0,0,a.width,a.height);e.drawImage(o,0,0);const m=e.getImageData(0,0,o.width,o.height);return h.globalAlpha=1,h.clearRect(0,0,o.width,o.height),m}getUniformLocations(t,e){return{delta:t.getUniformLocation(e,"uDelta")}}sendUniformData(t,e){const i=this.chooseRightDelta();t.uniform2fv(e.delta,i)}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const i=t*this.blur*.12;return this.horizontal?e[0]=i:e[1]=i,e}}s(Zo,"type","Blur"),s(Zo,"defaults",{blur:0,mainParameter:"blur"}),R.setClass(Zo);class Qo extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBrightness;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += uBrightness;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.brightness)return;const i=Math.round(255*this.brightness);for(let t=0;t<e.length;t+=4)e[t]=e[t]+i,e[t+1]=e[t+1]+i,e[t+2]=e[t+2]+i}getUniformLocations(t,e){return{uBrightness:t.getUniformLocation(e,"uBrightness")}}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}s(Qo,"type","Brightness"),s(Qo,"defaults",{brightness:0,mainParameter:"brightness"}),R.setClass(Qo);const $o=["matrix"],ta={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],mainParameter:"matrix",colorsOnly:!0};class ea extends Ho{setOptions(t){let{matrix:e}=t,i=r(t,$o);e&&(this.matrix=[...e]),Object.assign(this,i)}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n uniform mat4 uColorMatrix;\n uniform vec4 uConstants;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color *= uColorMatrix;\n color += uConstants;\n gl_FragColor = color;\n }"}applyTo2d(t){const e=t.imageData.data,i=this.matrix,s=this.colorsOnly;for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2];if(s)e[t]=r*i[0]+n*i[1]+o*i[2]+255*i[4],e[t+1]=r*i[5]+n*i[6]+o*i[7]+255*i[9],e[t+2]=r*i[10]+n*i[11]+o*i[12]+255*i[14];else{const s=e[t+3];e[t]=r*i[0]+n*i[1]+o*i[2]+s*i[3]+255*i[4],e[t+1]=r*i[5]+n*i[6]+o*i[7]+s*i[8]+255*i[9],e[t+2]=r*i[10]+n*i[11]+o*i[12]+s*i[13]+255*i[14],e[t+3]=r*i[15]+n*i[16]+o*i[17]+s*i[18]+255*i[19]}}}getUniformLocations(t,e){return{uColorMatrix:t.getUniformLocation(e,"uColorMatrix"),uConstants:t.getUniformLocation(e,"uConstants")}}sendUniformData(t,e){const i=this.matrix,s=[i[0],i[1],i[2],i[3],i[5],i[6],i[7],i[8],i[10],i[11],i[12],i[13],i[15],i[16],i[17],i[18]],r=[i[4],i[9],i[14],i[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,s),t.uniform4fv(e.uConstants,r)}}function ia(t,e){var r;const n=(s(r=class extends ea{},"type",t),s(r,"defaults",i(i({},ta),{},{mainParameter:void 0,matrix:e})),r);return R.setClass(n,t),n}s(ea,"type","ColorMatrix"),s(ea,"defaults",ta),R.setClass(ea);const sa=ia("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),ra=ia("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),na=ia("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),oa=ia("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),aa=ia("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),ha=ia("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),ca=ia("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]),la=["subFilters"];class da extends Ho{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{subFilters:e=[]}=t;super(r(t,la)),this.subFilters=e}applyTo(t){Yo(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach((e=>{e.applyTo(t)}))}toObject(){return i(i({},super.toObject()),{},{subFilters:this.subFilters.map((t=>t.toObject()))})}isNeutralState(){return!this.subFilters.some((t=>!t.isNeutralState()))}static fromObject(t,e){return Promise.all((t.subFilters||[]).map((t=>R.getClass(t.type).fromObject(t,e)))).then((t=>new this({subFilters:t})))}}s(da,"type","Composed"),R.setClass(da);class ua extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uContrast;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\n color.rgb = contrastF * (color.rgb - 0.5) + 0.5;\n gl_FragColor = color;\n }"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.contrast)return;const i=Math.floor(255*this.contrast),s=259*(i+255)/(255*(259-i));for(let t=0;t<e.length;t+=4)e[t]=s*(e[t]-128)+128,e[t+1]=s*(e[t+1]-128)+128,e[t+2]=s*(e[t+2]-128)+128}getUniformLocations(t,e){return{uContrast:t.getUniformLocation(e,"uContrast")}}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}s(ua,"type","Contrast"),s(ua,"defaults",{contrast:0,mainParameter:"contrast"}),R.setClass(ua);const ga={Convolute_3_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_3_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_5_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_5_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_7_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_7_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_9_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_9_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n "};class fa extends Ho{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ga[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,i=e.data,s=this.matrix,r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=e.width,a=e.height,h=t.ctx.createImageData(o,a),c=h.data,l=this.opaque?1:0;let d,u,g,f,p,m,v,_,y,x,C,b,S;for(C=0;C<a;C++)for(x=0;x<o;x++){for(p=4*(C*o+x),d=0,u=0,g=0,f=0,S=0;S<r;S++)for(b=0;b<r;b++)v=C+S-n,m=x+b-n,v<0||v>=a||m<0||m>=o||(_=4*(v*o+m),y=s[S*r+b],d+=i[_]*y,u+=i[_+1]*y,g+=i[_+2]*y,l||(f+=i[_+3]*y));c[p]=d,c[p+1]=u,c[p+2]=g,c[p+3]=l?i[p+3]:f}t.imageData=h}getUniformLocations(t,e){return{uMatrix:t.getUniformLocation(e,"uMatrix"),uOpaque:t.getUniformLocation(e,"uOpaque"),uHalfSize:t.getUniformLocation(e,"uHalfSize"),uSize:t.getUniformLocation(e,"uSize")}}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return i(i({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}s(fa,"type","Convolute"),s(fa,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),R.setClass(fa);const pa=["gamma"];class ma extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec3 uGamma;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec3 correction = (1.0 / uGamma);\n color.r = pow(color.r, correction.r);\n color.g = pow(color.g, correction.g);\n color.b = pow(color.b, correction.b);\n gl_FragColor = color;\n gl_FragColor.rgb *= color.a;\n }\n"}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{gamma:e=[1,1,1]}=t;super(r(t,pa)),this.gamma=e}applyTo2d(t){let{imageData:{data:e}}=t;const i=this.gamma,s=1/i[0],r=1/i[1],n=1/i[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let t=0;t<256;t++)o.r[t]=255*Math.pow(t/255,s),o.g[t]=255*Math.pow(t/255,r),o.b[t]=255*Math.pow(t/255,n);for(let t=0;t<e.length;t+=4)e[t]=o.r[e[t]],e[t+1]=o.g[e[t+1]],e[t+2]=o.b[e[t+2]]}getUniformLocations(t,e){return{uGamma:t.getUniformLocation(e,"uGamma")}}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}}s(ma,"type","Gamma"),s(ma,"defaults",{mainParameter:"gamma",gamma:[1,1,1]}),R.setClass(ma);const va={average:"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float average = (color.r + color.b + color.g) / 3.0;\n gl_FragColor = vec4(average, average, average, color.a);\n }\n ",lightness:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n ",luminosity:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n "};class _a extends Ho{applyTo2d(t){let{imageData:{data:e}}=t;for(let t,i=0;i<e.length;i+=4){switch(this.mode){case"average":t=(e[i]+e[i+1]+e[i+2])/3;break;case"lightness":t=(Math.min(e[i],e[i+1],e[i+2])+Math.max(e[i],e[i+1],e[i+2]))/2;break;case"luminosity":t=.21*e[i]+.72*e[i+1]+.07*e[i+2]}e[i]=t,e[i+1]=t,e[i+2]=t}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return va[this.mode]}getUniformLocations(t,e){return{uMode:t.getUniformLocation(e,"uMode")}}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}s(_a,"type","Grayscale"),s(_a,"defaults",{mode:"average",mainParameter:"mode"}),R.setClass(_a);class ya extends ea{calculateMatrix(){const t=this.rotation*Math.PI,e=V(t),i=G(t),s=1/3,r=Math.sqrt(s)*i,n=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+n/3,this.matrix[1]=s*n-r,this.matrix[2]=s*n+r,this.matrix[5]=s*n+r,this.matrix[6]=e+s*n,this.matrix[7]=s*n-r,this.matrix[10]=s*n-r,this.matrix[11]=s*n+r,this.matrix[12]=e+s*n}isNeutralState(){return this.calculateMatrix(),super.isNeutralState()}applyTo(t){this.calculateMatrix(),super.applyTo(t)}}s(ya,"type","HueRotation"),s(ya,"defaults",{rotation:0,mainParameter:"rotation"}),R.setClass(ya);class xa extends Ho{applyTo2d(t){let{imageData:{data:e}}=t;for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uInvert;\n uniform int uAlpha;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n if (uInvert == 1) {\n if (uAlpha == 1) {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);\n } else {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n }\n } else {\n gl_FragColor = color;\n }\n }\n"}isNeutralState(){return!this.invert}getUniformLocations(t,e){return{uInvert:t.getUniformLocation(e,"uInvert"),uAlpha:t.getUniformLocation(e,"uAlpha")}}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}s(xa,"type","Invert"),s(xa,"defaults",{alpha:!1,invert:!0,mainParameter:"invert"}),R.setClass(xa);class Ca extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uStepH;\n uniform float uNoise;\n uniform float uSeed;\n varying vec2 vTexCoord;\n float rand(vec2 co, float seed, float vScale) {\n return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n }\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.noise)return;const i=this.noise;for(let t=0;t<e.length;t+=4){const s=(.5-Math.random())*i;e[t]+=s,e[t+1]+=s,e[t+2]+=s}}getUniformLocations(t,e){return{uNoise:t.getUniformLocation(e,"uNoise"),uSeed:t.getUniformLocation(e,"uSeed")}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}toObject(){return i(i({},super.toObject()),{},{noise:this.noise})}}s(Ca,"type","Noise"),s(Ca,"defaults",{mainParameter:"noise",noise:0}),R.setClass(Ca);class ba extends Ho{applyTo2d(t){let{imageData:{data:e,width:i,height:s}}=t;for(let t=0;t<s;t+=this.blocksize)for(let r=0;r<i;r+=this.blocksize){const n=4*t*i+4*r,o=e[n],a=e[n+1],h=e[n+2],c=e[n+3];for(let n=t;n<Math.min(t+this.blocksize,s);n++)for(let t=r;t<Math.min(r+this.blocksize,i);t++){const s=4*n*i+4*t;e[s]=o,e[s+1]=a,e[s+2]=h,e[s+3]=c}}}isNeutralState(){return 1===this.blocksize}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBlocksize;\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n float blockW = uBlocksize * uStepW;\n float blockH = uBlocksize * uStepW;\n int posX = int(vTexCoord.x / blockW);\n int posY = int(vTexCoord.y / blockH);\n float fposX = float(posX);\n float fposY = float(posY);\n vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\n vec4 color = texture2D(uTexture, squareCoords);\n gl_FragColor = color;\n }\n"}getUniformLocations(t,e){return{uBlocksize:t.getUniformLocation(e,"uBlocksize"),uStepW:t.getUniformLocation(e,"uStepW"),uStepH:t.getUniformLocation(e,"uStepH")}}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}s(ba,"type","Pixelate"),s(ba,"defaults",{blocksize:4,mainParameter:"blocksize"}),R.setClass(ba);class Sa extends Ho{getFragmentShader(){return"\nprecision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\n gl_FragColor.a = 0.0;\n }\n}\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=255*this.distance,s=new Dt(this.color).getSource(),r=[s[0]-i,s[1]-i,s[2]-i],n=[s[0]+i,s[1]+i,s[2]+i];for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],o=e[t+2];i>r[0]&&s>r[1]&&o>r[2]&&i<n[0]&&s<n[1]&&o<n[2]&&(e[t+3]=0)}}getUniformLocations(t,e){return{uLow:t.getUniformLocation(e,"uLow"),uHigh:t.getUniformLocation(e,"uHigh")}}sendUniformData(t,e){const i=new Dt(this.color).getSource(),s=this.distance,r=[0+i[0]/255-s,0+i[1]/255-s,0+i[2]/255-s,1],n=[i[0]/255+s,i[1]/255+s,i[2]/255+s,1];t.uniform4fv(e.uLow,r),t.uniform4fv(e.uHigh,n)}toObject(){return i(i({},super.toObject()),{},{color:this.color,distance:this.distance})}}s(Sa,"type","RemoveColor"),s(Sa,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),R.setClass(Sa);class wa extends Ho{getUniformLocations(t,e){return{uDelta:t.getUniformLocation(e,"uDelta"),uTaps:t.getUniformLocation(e,"uTaps")}}sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,i=this.getFilterWindow(),s=new Array(i);for(let r=1;r<=i;r++)s[r-1]=t(r*e);return s}generateShader(t){const e=new Array(t);for(let i=1;i<=t;i++)e[i-1]="".concat(i,".0 * uDelta");return"\n ".concat(this.fragmentSourceTOP,"\n uniform float uTaps[").concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map(((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(e,"];\n "))).join("\n"),"\n gl_FragColor = color / sum;\n }\n ")}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Yo(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return 1===this.scaleX&&1===this.scaleY}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<1.1920929e-7&&e>-1.1920929e-7)return 1;const i=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(i)/i}}applyTo2d(t){const e=t.imageData,i=this.scaleX,s=this.scaleY;this.rcpScaleX=1/i,this.rcpScaleY=1/s;const r=e.width,n=e.height,o=Math.round(r*i),a=Math.round(n*s);let h;h="sliceHack"===this.resizeType?this.sliceByTwo(t,r,n,o,a):"hermite"===this.resizeType?this.hermiteFastResize(t,r,n,o,a):"bilinear"===this.resizeType?this.bilinearFiltering(t,r,n,o,a):"lanczos"===this.resizeType?this.lanczosResize(t,r,n,o,a):new ImageData(o,a),t.imageData=h}sliceByTwo(t,e,i,s,r){const n=t.imageData,o=.5;let a=!1,h=!1,c=e*o,l=i*o;const d=t.filterBackend.resources;let u=0,g=0;const f=e;let p=0;d.sliceByTwo||(d.sliceByTwo=Q());const m=d.sliceByTwo;(m.width<1.5*e||m.height<i)&&(m.width=1.5*e,m.height=i);const v=m.getContext("2d");for(v.clearRect(0,0,1.5*e,i),v.putImageData(n,0,0),s=Math.floor(s),r=Math.floor(r);!a||!h;)e=c,i=l,s<Math.floor(c*o)?c=Math.floor(c*o):(c=s,a=!0),r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,h=!0),v.drawImage(m,u,g,e,i,f,p,c,l),u=f,g=p,p+=l;return v.getImageData(u,g,s,r)}lanczosResize(t,e,i,s,r){const n=t.imageData.data,o=t.ctx.createImageData(s,r),a=o.data,h=this.lanczosCreate(this.lanczosLobes),c=this.rcpScaleX,l=this.rcpScaleY,d=2/this.rcpScaleX,u=2/this.rcpScaleY,g=Math.ceil(c*this.lanczosLobes/2),f=Math.ceil(l*this.lanczosLobes/2),p={},m={x:0,y:0},v={x:0,y:0};return function t(_){let y,x,C,b,S,w,T,O,k,D,M;for(m.x=(_+.5)*c,v.x=Math.floor(m.x),y=0;y<r;y++){for(m.y=(y+.5)*l,v.y=Math.floor(m.y),S=0,w=0,T=0,O=0,k=0,x=v.x-g;x<=v.x+g;x++)if(!(x<0||x>=e)){D=Math.floor(1e3*Math.abs(x-m.x)),p[D]||(p[D]={});for(let t=v.y-f;t<=v.y+f;t++)t<0||t>=i||(M=Math.floor(1e3*Math.abs(t-m.y)),p[D][M]||(p[D][M]=h(Math.sqrt(Math.pow(D*d,2)+Math.pow(M*u,2))/1e3)),C=p[D][M],C>0&&(b=4*(t*e+x),S+=C,w+=C*n[b],T+=C*n[b+1],O+=C*n[b+2],k+=C*n[b+3]))}b=4*(y*s+_),a[b]=w/S,a[b+1]=T/S,a[b+2]=O/S,a[b+3]=k/S}return++_<s?t(_):o}(0)}bilinearFiltering(t,e,i,s,r){let n,o,a,h,c,l,d,u,g,f,p,m,v,_=0;const y=this.rcpScaleX,x=this.rcpScaleY,C=4*(e-1),b=t.imageData.data,S=t.ctx.createImageData(s,r),w=S.data;for(d=0;d<r;d++)for(u=0;u<s;u++)for(c=Math.floor(y*u),l=Math.floor(x*d),g=y*u-c,f=x*d-l,v=4*(l*e+c),p=0;p<4;p++)n=b[v+p],o=b[v+4+p],a=b[v+C+p],h=b[v+C+4+p],m=n*(1-g)*(1-f)+o*g*(1-f)+a*f*(1-g)+h*g*f,w[_++]=m;return S}hermiteFastResize(t,e,i,s,r){const n=this.rcpScaleX,o=this.rcpScaleY,a=Math.ceil(n/2),h=Math.ceil(o/2),c=t.imageData.data,l=t.ctx.createImageData(s,r),d=l.data;for(let t=0;t<r;t++)for(let i=0;i<s;i++){const r=4*(i+t*s);let l=0,u=0,g=0,f=0,p=0,m=0,v=0;const _=(t+.5)*o;for(let s=Math.floor(t*o);s<(t+1)*o;s++){const t=Math.abs(_-(s+.5))/h,r=(i+.5)*n,o=t*t;for(let t=Math.floor(i*n);t<(i+1)*n;t++){let i=Math.abs(r-(t+.5))/a;const n=Math.sqrt(o+i*i);n>1&&n<-1||(l=2*n*n*n-3*n*n+1,l>0&&(i=4*(t+s*e),v+=l*c[i+3],g+=l,c[i+3]<255&&(l=l*c[i+3]/250),f+=l*c[i],p+=l*c[i+1],m+=l*c[i+2],u+=l))}}d[r]=f/u,d[r+1]=p/u,d[r+2]=m/u,d[r+3]=v/g}return l}toObject(){return{type:this.type,scaleX:this.scaleX,scaleY:this.scaleY,resizeType:this.resizeType,lanczosLobes:this.lanczosLobes}}}s(wa,"type","Resize"),s(wa,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3,fragmentSourceTOP:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n "}),R.setClass(wa);class Ta extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uSaturation;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float rgMax = max(color.r, color.g);\n float rgbMax = max(rgMax, color.b);\n color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\n color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\n color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.saturation)return;const i=-this.saturation;for(let t=0;t<e.length;t+=4){const s=Math.max(e[t],e[t+1],e[t+2]);e[t]+=s!==e[t]?(s-e[t])*i:0,e[t+1]+=s!==e[t+1]?(s-e[t+1])*i:0,e[t+2]+=s!==e[t+2]?(s-e[t+2])*i:0}}getUniformLocations(t,e){return{uSaturation:t.getUniformLocation(e,"uSaturation")}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}}s(Ta,"type","Saturation"),s(Ta,"defaults",{saturation:0,mainParameter:"saturation"}),R.setClass(Ta);class Oa extends Ho{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uVibrance;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float max = max(color.r, max(color.g, color.b));\n float avg = (color.r + color.g + color.b) / 3.0;\n float amt = (abs(max - avg) * 2.0) * uVibrance;\n color.r += max != color.r ? (max - color.r) * amt : 0.00;\n color.g += max != color.g ? (max - color.g) * amt : 0.00;\n color.b += max != color.b ? (max - color.b) * amt : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.vibrance)return;const i=-this.vibrance;for(let t=0;t<e.length;t+=4){const s=Math.max(e[t],e[t+1],e[t+2]),r=(e[t]+e[t+1]+e[t+2])/3,n=2*Math.abs(s-r)/255*i;e[t]+=s!==e[t]?(s-e[t])*n:0,e[t+1]+=s!==e[t+1]?(s-e[t+1])*n:0,e[t+2]+=s!==e[t+2]?(s-e[t+2])*n:0}}getUniformLocations(t,e){return{uVibrance:t.getUniformLocation(e,"uVibrance")}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}}s(Oa,"type","Vibrance"),s(Oa,"defaults",{vibrance:0,mainParameter:"vibrance"}),R.setClass(Oa);var ka=Object.freeze({__proto__:null,BaseFilter:Ho,BlackWhite:ca,BlendColor:No,BlendImage:Jo,Blur:Zo,Brightness:Qo,Brownie:sa,ColorMatrix:ea,Composed:da,Contrast:ua,Convolute:fa,Gamma:ma,Grayscale:_a,HueRotation:ya,Invert:xa,Kodachrome:na,Noise:Ca,Pixelate:ba,Polaroid:aa,RemoveColor:Sa,Resize:wa,Saturation:Ta,Sepia:ha,Technicolor:oa,Vibrance:Oa,Vintage:ra});t.ActiveSelection=Gs,t.BaseBrush=pn,t.Canvas=Zr,t.Canvas2dFilterBackend=go,t.CanvasDOMManager=Wr,t.Circle=bn,t.CircleBrush=class extends pn{constructor(t){super(t),s(this,"width",10),this.points=[]}drawDot(t){const e=this.addPoint(t),i=this.canvas.contextTop;this._saveAndTransform(i),this.dot(i,e),i.restore()}dot(t,e){t.fillStyle=e.fill,t.beginPath(),t.arc(e.x,e.y,e.radius,0,2*Math.PI,!1),t.closePath(),t.fill()}onMouseDown(t){this.points=[],this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.drawDot(t)}_render(){const t=this.canvas.contextTop,e=this.points;this._saveAndTransform(t);for(let i=0;i<e.length;i++)this.dot(t,e[i]);t.restore()}onMouseMove(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.needsFullRender()?(this.canvas.clearContext(this.canvas.contextTop),this.addPoint(t),this._render()):this.drawDot(t))}onMouseUp(){const t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;const e=[];for(let t=0;t<this.points.length;t++){const i=this.points[t],s=new bn({radius:i.radius,left:i.x,top:i.y,originX:k,originY:k,fill:i.fill});this.shadow&&(s.shadow=new ai(this.shadow)),e.push(s)}const i=new Vs(e,{canvas:this.canvas});this.canvas.fire("before:path:created",{path:i}),this.canvas.add(i),this.canvas.fire("path:created",{path:i}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()}addPoint(t){let{x:e,y:i}=t;const s={x:e,y:i,radius:X(Math.max(0,this.width-20),this.width+20)/2,fill:new Dt(this.color).setAlpha(X(0,100)/100).toRgba()};return this.points.push(s),s}},t.Color=Dt,t.Control=yi,t.Ellipse=Mn,t.Gradient=un,t.Group=Vs,t.IText=lo,t.Image=Co,t.Intersection=ii,t.Line=On,t.Object=Ni,t.Observable=I,t.Path=_n,t.Pattern=fn,t.PatternBrush=class extends yn{constructor(t){super(t)}getPatternSrc(){const t=Q(),e=t.getContext("2d");return t.width=t.height=25,e&&(e.fillStyle=this.color,e.beginPath(),e.arc(10,10,10,0,2*Math.PI,!1),e.closePath(),e.fill()),t}getPattern(t){return t.createPattern(this.source||this.getPatternSrc(),"repeat")}_setBrushStyles(t){super._setBrushStyles(t);const e=this.getPattern(t);e&&(t.strokeStyle=e)}createPath(t){const e=super.createPath(t),i=e._getLeftTopCoords().scalarAdd(e.strokeWidth/2);return e.stroke=new fn({source:this.source||this.getPatternSrc(),offsetX:-i.x,offsetY:-i.y}),e}},t.PencilBrush=yn,t.Point=z,t.Polygon=Fn,t.Polyline=jn,t.Rect=Ys,t.Shadow=ai,t.SprayBrush=class extends pn{constructor(t){super(t),s(this,"width",10),s(this,"density",20),s(this,"dotWidth",1),s(this,"dotWidthVariance",1),s(this,"randomOpacity",!1),s(this,"optimizeOverlapping",!0),this.sprayChunks=[],this.sprayChunk=[]}onMouseDown(t){this.sprayChunks=[],this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.addSprayChunk(t),this.renderChunck(this.sprayChunk)}onMouseMove(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.addSprayChunk(t),this.renderChunck(this.sprayChunk))}onMouseUp(){const t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;const e=[];for(let t=0;t<this.sprayChunks.length;t++){const i=this.sprayChunks[t];for(let t=0;t<i.length;t++){const s=i[t],r=new Ys({width:s.width,height:s.width,left:s.x+1,top:s.y+1,originX:k,originY:k,fill:this.color});e.push(r)}}const i=new Vs(this.optimizeOverlapping?function(t){const e={},i=[];for(let s,r=0;r<t.length;r++)s="".concat(t[r].left).concat(t[r].top),e[s]||(e[s]=!0,i.push(t[r]));return i}(e):e,{objectCaching:!0,layout:"fixed",subTargetCheck:!1,interactive:!1});this.shadow&&i.set("shadow",new ai(this.shadow)),this.canvas.fire("before:path:created",{path:i}),this.canvas.add(i),this.canvas.fire("path:created",{path:i}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()}renderChunck(t){const e=this.canvas.contextTop;e.fillStyle=this.color,this._saveAndTransform(e);for(let i=0;i<t.length;i++){const s=t[i];e.globalAlpha=s.opacity,e.fillRect(s.x,s.y,s.width,s.width)}e.restore()}_render(){const t=this.canvas.contextTop;t.fillStyle=this.color,this._saveAndTransform(t);for(let t=0;t<this.sprayChunks.length;t++)this.renderChunck(this.sprayChunks[t]);t.restore()}addSprayChunk(t){this.sprayChunk=[];const e=this.width/2;for(let i=0;i<this.density;i++)this.sprayChunk.push({x:X(t.x-e,t.x+e),y:X(t.y-e,t.y+e),width:this.dotWidthVariance?X(Math.max(1,this.dotWidth-this.dotWidthVariance),this.dotWidth+this.dotWidthVariance):this.dotWidth,opacity:this.randomOpacity?X(0,100)/100:1});this.sprayChunks.push(this.sprayChunk)}},t.StaticCanvas=Zt,t.StaticCanvasDOMManager=Kt,t.Text=Zn,t.Textbox=uo,t.Triangle=kn,t.WebGLFilterBackend=fo,t.cache=_,t.classRegistry=R,t.config=h,t.controlsUtils=Xo,t.createCollectionMixin=U,t.filters=ka,t.getCSSRules=Po,t.getEnv=p,t.getFabricDocument=m,t.getFabricWindow=v,t.getFilterBackend=_o,t.iMatrix=w,t.initFilterBackend=vo,t.isWebGLPipelineState=Yo,t.loadSVGFromString=function(t,e,i){return Lo((new(v().DOMParser)).parseFromString(t.trim(),"text/xml"),e,i)},t.loadSVGFromURL=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise(((e,s)=>{Ir(t.replace(/^\n\s*/,"").trim(),{onComplete:t=>{const i=t.responseXML;i&&e(i),s()},signal:i.signal})})).then((t=>Lo(t,e,i))).catch((()=>Fo()))},t.parseAttributes=Bs,t.parseFontDeclaration=Fs,t.parsePointsAttribute=Pn,t.parseSVGDocument=Lo,t.parseStyleAttribute=Ls,t.parseTransformAttribute=As,t.runningAnimations=B,t.setEnv=t=>{f=t},t.setFilterBackend=function(t){mo=t},t.util=Yr,t.version=y}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fabric={})}(this,(function(t){"use strict";function e(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,s)}return i}function i(t){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?e(Object(r),!0).forEach((function(e){s(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(t,e,i){return(e=o(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function r(t,e){if(null==t)return{};var i,s,r=function(t,e){if(null==t)return{};var i,s,r={},n=Object.keys(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||(r[i]=t[i]);return r}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(t,i)&&(r[i]=t[i])}return r}function n(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function o(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var s=i.call(t,e||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}class a{constructor(){s(this,"browserShadowBlurConstant",1),s(this,"DPI",96),s(this,"devicePixelRatio",1),s(this,"perfLimitSizeTotal",2097152),s(this,"maxCacheSideLimit",4096),s(this,"minCacheSideLimit",256),s(this,"disableStyleCopyPaste",!1),s(this,"enableGLFiltering",!0),s(this,"textureSize",4096),s(this,"forceGLPutImageData",!1),s(this,"cachesBoundsOfCurve",!0),s(this,"fontPaths",{}),s(this,"NUM_FRACTION_DIGITS",4)}}const h=new class extends a{constructor(t){super(),this.configure(t)}configure(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(this,t)}addFonts(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.fontPaths=i(i({},this.fontPaths),t)}removeFonts(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).forEach((t=>{delete this.fontPaths[t]}))}clearFonts(){this.fontPaths={}}restoreDefaults(t){const e=new a,i=(null==t?void 0:t.reduce(((t,i)=>(t[i]=e[i],t)),{}))||e;this.configure(i)}},c=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return console[t]("fabric",...i)};class l extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class d extends l{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class u{}class g extends u{testPrecision(t,e){const i="precision ".concat(e," float;\nvoid main(){}"),s=t.createShader(t.FRAGMENT_SHADER);return!!s&&(t.shaderSource(s,i),t.compileShader(s),!!t.getShaderParameter(s,t.COMPILE_STATUS))}queryWebGL(t){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))),c("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const f={};let p,m=!1;let v;const _=()=>v||(m||(h.configure({devicePixelRatio:window.devicePixelRatio||1}),p="ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,m=!0),{document:document,window:window,isTouchSupported:p,WebGLProbe:new g,dispose(){},copyPasteData:f}),y=()=>_().document,x=()=>_().window;const C=new class{constructor(){s(this,"charWidthsCache",{}),s(this,"boundsOfCurveCache",{})}getFontCache(t){let{fontFamily:e,fontStyle:i,fontWeight:s}=t;e=e.toLowerCase(),this.charWidthsCache[e]||(this.charWidthsCache[e]={});const r=this.charWidthsCache[e],n="".concat(i.toLowerCase(),"_").concat((s+"").toLowerCase());return r[n]||(r[n]={}),r[n]}clearFontCache(t){(t=(t||"").toLowerCase())?this.charWidthsCache[t]&&delete this.charWidthsCache[t]:this.charWidthsCache={}}limitDimsByArea(t){const{perfLimitSizeTotal:e}=h,i=Math.sqrt(e*t);return[Math.floor(i),Math.floor(e/i)]}};const b="6.0.0-beta15";function S(){}const w=Math.PI/2,T=2*Math.PI,O=Math.PI/180,k=Object.freeze([1,0,0,1,0,0]),D=16,M=.4477152502,P="center",A="left",E="top",j="bottom",F="right",L="none",R=/\r?\n/,B="json",I="svg";const X=new class{constructor(){this[B]=new Map,this[I]=new Map}getClass(t){const e=this[B].get(t);if(!e)throw new l("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[I].get(t)}setSVGClass(t,e){this[I].set(null!=e?e:t.type.toLowerCase(),t)}};const Y=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 i;return e.target===t||"object"==typeof e.target&&(null===(i=e.target)||void 0===i?void 0:i.canvas)===t}));return e.forEach((t=>t.abort())),e}cancelByTarget(t){if(!t)return[];const e=this.filter((e=>e.target===t));return e.forEach((t=>t.abort())),e}};class W{constructor(){s(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),"object"==typeof t)return Object.entries(t).forEach((t=>{let[e,i]=t;this.on(e,i)})),()=>this.off(t);if(e){const i=t;return this.__eventListeners[i]||(this.__eventListeners[i]=[]),this.__eventListeners[i].push(e),()=>this.off(i,e)}return()=>!1}once(t,e){if("object"==typeof t){const e=[];return Object.entries(t).forEach((t=>{let[i,s]=t;e.push(this.once(i,s))})),()=>e.forEach((t=>t()))}if(e){const i=this.on(t,(function(){for(var t=arguments.length,s=new Array(t),r=0;r<t;r++)s[r]=arguments[r];e.call(this,...s),i()}));return i}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const i=this.__eventListeners[t],s=i.indexOf(e);s>-1&&i.splice(s,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(void 0===t)for(const t in this.__eventListeners)this._removeEventListener(t);else"object"==typeof t?Object.entries(t).forEach((t=>{let[e,i]=t;this._removeEventListener(e,i)})):this._removeEventListener(t,e)}fire(t,e){var i;if(!this.__eventListeners)return;const s=null===(i=this.__eventListeners[t])||void 0===i?void 0:i.concat();if(s)for(let t=0;t<s.length;t++)s[t].call(this,e||{})}}const V=(t,e)=>Math.floor(Math.random()*(e-t+1))+t,G=(t,e)=>isNaN(t)&&"number"==typeof e?e:t,z=(t,e)=>{const i=t.indexOf(e);return-1!==i&&t.splice(i,1),t},H=t=>{if(0===t)return 1;switch(Math.abs(t)/w){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},U=t=>{if(0===t)return 0;const e=t/w,i=Math.sign(t);switch(e){case 1:return i;case 2:return 0;case 3:return-i}return Math.sin(t)};class N{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new N(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new N(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new N(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new N(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new N(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new N(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new N(this.x/t.x,this.y/t.y)}scalarDivide(t){return new N(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new N(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}midPointFrom(t){return this.lerp(t)}min(t){return new N(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new N(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i}clone(){return new N(this.x,this.y)}rotate(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:q;const i=U(t),s=H(t),r=this.subtract(e);return new N(r.x*s-r.y*i,r.x*i+r.y*s).add(e)}transform(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new N(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const q=new N(0,0);function K(t){class e extends t{constructor(){super(...arguments),s(this,"_objects",[])}_onObjectAdded(t){}_onObjectRemoved(t){}_onStackOrderChanged(t){}add(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];const s=this._objects.push(...e);return e.forEach((t=>this._onObjectAdded(t))),s}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return this._objects.splice(t,0,...i),i.forEach((t=>this._onObjectAdded(t))),this._objects.length}remove(){const t=this._objects,e=[];for(var i=arguments.length,s=new Array(i),r=0;r<i;r++)s[r]=arguments[r];return s.forEach((i=>{const s=t.indexOf(i);-1!==s&&(t.splice(s,1),e.push(i),this._onObjectRemoved(i))})),e}forEachObject(t){this.getObjects().forEach(((e,i,s)=>t(e,i,s)))}getObjects(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];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,i){return!!this._objects.includes(t)||!!i&&this._objects.some((i=>i instanceof e&&i.contains(t,!0)))}complexity(){return this._objects.reduce(((t,e)=>t+=e.complexity?e.complexity():0),0)}sendObjectToBack(t){return!(!t||t===this._objects[0])&&(z(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),!0)}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1])&&(z(this._objects,t),this._objects.push(t),this._onStackOrderChanged(t),!0)}sendObjectBackwards(t,e){if(!t)return!1;const i=this._objects.indexOf(t);if(0!==i){const s=this.findNewLowerIndex(t,i,e);return z(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}bringObjectForward(t,e){if(!t)return!1;const i=this._objects.indexOf(t);if(i!==this._objects.length-1){const s=this.findNewUpperIndex(t,i,e);return z(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(z(this._objects,t),this._objects.splice(e,0,t),this._onStackOrderChanged(t),!0)}findNewLowerIndex(t,e,i){let s;if(i){s=e;for(let i=e-1;i>=0;--i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e-1;return s}findNewUpperIndex(t,e,i){let s;if(i){s=e;for(let i=e+1;i<this._objects.length;++i)if(t.isOverlapping(this._objects[i])){s=i;break}}else s=e+1;return s}collectObjects(t){let{left:e,top:i,width:s,height:r}=t,{includeIntersecting:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[],a=new N(e,i),h=a.add(new N(s,r));for(let t=this._objects.length-1;t>=0;t--){const e=this._objects[t];e.selectable&&e.visible&&(n&&e.intersectsWithRect(a,h,!0)||e.isContainedWithinRect(a,h,!0)||n&&e.containsPoint(a,!0)||n&&e.containsPoint(h,!0))&&o.push(e)}return o}}return e}class J extends W{_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 Z(t){return x().requestAnimationFrame(t)}function Q(t){return x().cancelAnimationFrame(t)}let $=0;const tt=()=>$++,et=()=>{const t=y().createElement("canvas");if(!t||void 0===t.getContext)throw new l("Failed to create `canvas` element");return t},it=()=>y().createElement("img"),st=(t,e,i)=>t.toDataURL("image/".concat(e),i),rt=t=>t*O,nt=t=>t/O,ot=["translateX","translateY","angle"],at=(t,e,i)=>new N(t).transform(e,i),ht=t=>{const e=1/(t[0]*t[3]-t[1]*t[2]),i=[e*t[3],-e*t[1],-e*t[2],e*t[0],0,0],{x:s,y:r}=new N(t[4],t[5]).transform(i,!0);return i[4]=-s,i[5]=-r,i},ct=(t,e,i)=>[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],i?0:t[0]*e[4]+t[2]*e[5]+t[4],i?0:t[1]*e[4]+t[3]*e[5]+t[5]],lt=(t,e)=>t.reduceRight(((t,i)=>i?ct(i,t,e):t),k),dt=t=>{const e=Math.atan2(t[1],t[0]),i=Math.pow(t[0],2)+Math.pow(t[1],2),s=Math.sqrt(i),r=(t[0]*t[3]-t[2]*t[1])/s,n=Math.atan2(t[0]*t[2]+t[1]*t[3],i);return{angle:nt(e),scaleX:s,scaleY:r,skewX:nt(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 gt(){let{angle:t=0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{x:e=0,y:i=0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=rt(t),r=H(s),n=U(s);return[r,n,-n,r,e?e-(r*e-n*i):0,i?i-(n*e+r*i):0]}const ft=function(t){return[t,0,0,arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,0,0]},pt=t=>Math.tan(rt(t)),mt=t=>[1,0,pt(t),1,0,0],vt=t=>[1,pt(t),0,1,0,0],_t=t=>{let{scaleX:e=1,scaleY:i=1,flipX:s=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=t;return lt([ft(s?-e:e,r?-i:i),n&&mt(n),o&&vt(o)],!0)},yt=t=>{let{translateX:e=0,translateY:i=0,angle:s=0}=t,n=r(t,ot);return lt([ut(e,i),s&>({angle:s}),_t(n)])},xt=function(t){let{signal:e,crossOrigin:i=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(s,r){if(e&&e.aborted)return r(new d("loadImage"));const n=it();let o;e&&(o=function(t){n.src="",r(t)},e.addEventListener("abort",o,{once:!0}));const a=function(){n.onload=n.onerror=null,o&&(null==e||e.removeEventListener("abort",o)),s(n)};t?(n.onload=a,n.onerror=function(){o&&(null==e||e.removeEventListener("abort",o)),r(new l("Error loading ".concat(n.src)))},i&&(n.crossOrigin=i),n.src=t):a()}))},Ct=function(t){let{signal:e,reviver:i=S}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((s,r)=>{const n=[];e&&e.addEventListener("abort",r,{once:!0}),Promise.all(t.map((t=>X.getClass(t.type).fromObject(t,{signal:e,reviver:i}).then((e=>(i(t,e),n.push(e),e)))))).then(s).catch((t=>{n.forEach((t=>{t.dispose&&t.dispose()})),r(t)})).finally((()=>{e&&e.removeEventListener("abort",r)}))}))},bt=function(t){let{signal:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(((i,s)=>{const r=[];e&&e.addEventListener("abort",s,{once:!0});const n=Object.values(t).map((t=>t?t.colorStops?new(X.getClass("gradient"))(t):t.type?Ct([t],{signal:e}).then((t=>{let[e]=t;return r.push(e),e})):t.source?X.getClass("pattern").fromObject(t,{signal:e}).then((t=>(r.push(t),t))):t:t)),o=Object.keys(t);Promise.all(n).then((t=>t.reduce(((t,e,i)=>(t[o[i]]=e,t)),{}))).then(i).catch((t=>{r.forEach((t=>{t.dispose&&t.dispose()})),s(t)})).finally((()=>{e&&e.removeEventListener("abort",s)}))}))},St=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce(((e,i)=>(i in t&&(e[i]=t[i]),e)),{})},wt=(t,e)=>Object.keys(t).reduce(((i,s)=>(e(t[s],s,t)&&(i[s]=t[s]),i)),{}),Tt={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"},Ot=(t,e,i)=>(i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t),kt=(t,e,i,s)=>{t/=255,e/=255,i/=255;const r=Math.max(t,e,i),n=Math.min(t,e,i);let o,a;const h=(r+n)/2;if(r===n)o=a=0;else{const s=r-n;switch(a=h>.5?s/(2-r-n):s/(r+n),r){case t:o=(e-i)/s+(e<i?6:0);break;case e:o=(i-t)/s+2;break;case i:o=(t-e)/s+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*h),s]},Dt=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"1";return parseFloat(t)/(t.endsWith("%")?100:1)},Mt=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),Pt=t=>{let[e,i,s,r=1]=t;const n=Math.round(.3*e+.59*i+.11*s);return[n,n,n,r]};class At{constructor(t){if(t)if(t instanceof At)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,i,s,r=1]=t;this.setSource([e,i,s,r])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in Tt&&(t=Tt[t]),"transparent"===t?[255,255,255,0]:At.sourceFromHex(t)||At.sourceFromRgb(t)||At.sourceFromHsl(t)||[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,i]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(i,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,i]=kt(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(i,"%)")}toHsla(){const[t,e,i,s]=kt(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(i,"%,").concat(s,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,i,s]=this.getSource();return"".concat(Mt(t)).concat(Mt(e)).concat(Mt(i)).concat(Mt(Math.round(255*s)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Pt(this.getSource())),this}toBlackWhite(t){const[e,,,i]=Pt(this.getSource()),s=e<(t||127)?0:255;return this.setSource([s,s,s,i]),this}overlayWith(t){t instanceof At||(t=new At(t));const e=this.getSource(),i=t.getSource(),[s,r,n]=e.map(((t,e)=>Math.round(.5*t+.5*i[e])));return this.setSource([s,r,n,e[3]]),this}static fromRgb(t){return At.fromRgba(t)}static fromRgba(t){return new At(At.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,i,s]=e.slice(1,4).map((t=>{const e=parseFloat(t);return t.endsWith("%")?Math.round(2.55*e):e}));return[t,i,s,Dt(e[4])]}}static fromHsl(t){return At.fromHsla(t)}static fromHsla(t){return new At(At.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{1,3})\s*[\s|,]\s*(\d{1,3}%)\s*[\s|,]\s*(\d{1,3}%)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const i=(parseFloat(e[1])%360+360)%360/360,s=parseFloat(e[2])/100,r=parseFloat(e[3])/100;let n,o,a;if(0===s)n=o=a=r;else{const t=r<=.5?r*(s+1):r+s-r*s,e=2*r-t;n=Ot(e,t,i+1/3),o=Ot(e,t,i),a=Ot(e,t,i-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*a),Dt(e[4])]}static fromHex(t){return new At(At.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 i;i=e.length<=4?e.split("").map((t=>t+t)):e.match(/.{2}/g);const[s,r,n,o=255]=i.map((t=>parseInt(t,16)));return[s,r,n,o/255]}}}const Et=(t,e)=>parseFloat(Number(t).toFixed(e)),jt=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D;const i=/\D{0,2}$/.exec(t),s=parseFloat(t),r=h.DPI;switch(null==i?void 0:i[0]){case"mm":return s*r/25.4;case"cm":return s*r/2.54;case"in":return s*r;case"pt":return s*r/72;case"pc":return s*r/72*12;case"em":return s*e;default:return s}},Ft=t=>{const[e,i]=t.trim().split(" "),[s,r]=(n=e)&&n!==L?[n.slice(1,4),n.slice(5,8)]:n===L?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:i||"meet",alignX:s,alignY:r}},Lt=t=>"matrix("+t.map((t=>Et(t,h.NUM_FRACTION_DIGITS))).join(" ")+")",Rt=function(t,e){let i,s,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(e)if(e.toLive)i="url(#SVGID_".concat(e.id,")");else{const t=new At(e),r=t.getAlpha();i=t.toRgb(),1!==r&&(s=r.toString())}else i="none";return r?"".concat(t,": ").concat(i,"; ").concat(s?"".concat(t,"-opacity: ").concat(s,"; "):""):"".concat(t,'="').concat(i,'" ').concat(s?"".concat(t,'-opacity="').concat(s,'" '):"")},Bt=function(t,e){let{left:i,top:s,width:r,height:n}=e,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:h.NUM_FRACTION_DIGITS;const a=Rt("fill",t,!1),[c,l,d,u]=[i,s,r,n].map((t=>Et(t,o)));return"<rect ".concat(a,' x="').concat(c,'" y="').concat(l,'" width="').concat(d,'" height="').concat(u,'"></rect>')},It=t=>!!t&&void 0!==t.toLive,Xt=t=>!!t&&"function"==typeof t.toObject,Yt=t=>!!t&&void 0!==t.offsetX&&void 0!==t.source,Wt=t=>!!t&&Array.isArray(t._objects),Vt=t=>!!t&&t.isType("Text","IText","Textbox"),Gt=t=>!!t&&t.isType("IText","Textbox"),zt=t=>!!t&&"function"==typeof t.onDragStart&&"function"==typeof t.shouldStartDragging;function Ht(t){const e=t&&Ut(t);let i=0,s=0;if(!t||!e)return{left:i,top:s};const r=e.documentElement,n=e.body||{scrollLeft:0,scrollTop:0};for(;t&&(t.parentNode||t.host)&&((t=t.parentNode||t.host)===e?(i=n.scrollLeft||r.scrollLeft||0,s=n.scrollTop||r.scrollTop||0):(i+=t.scrollLeft||0,s+=t.scrollTop||0),1!==t.nodeType||"fixed"!==t.style.position););return{left:i,top:s}}const Ut=t=>t.ownerDocument||null,Nt=t=>{var e;return(null===(e=t.ownerDocument)||void 0===e?void 0:e.defaultView)||null};function qt(t,e){const i=t.style;i&&("string"==typeof e?t.style.cssText+=";"+e:Object.entries(e).forEach((t=>{let[e,s]=t;return i.setProperty(e,s)})))}const Kt=function(t,e,i){let{width:s,height:r}=i,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;t.width=s,t.height=r,n>1&&(t.setAttribute("width",(s*n).toString()),t.setAttribute("height",(r*n).toString()),e.scale(n,n))};const Jt=(t,e)=>{let{width:i,height:s}=e;i&&(t.style.width="number"==typeof i?"".concat(i,"px"):i),s&&(t.style.height="number"==typeof s?"".concat(s,"px"):s)};function Zt(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect=L,t}class Qt{constructor(t){s(this,"_originalCanvasStyle",void 0),s(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(i=t)&&void 0!==i.getContext?t:t&&y().getElementById(t)||et();var i;if(e.hasAttribute("data-fabric"))throw new l("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:i}=t;const{el:s}=this.lower;s.classList.remove("lower-canvas"),s.removeAttribute("data-fabric"),s.setAttribute("width","".concat(e)),s.setAttribute("height","".concat(i)),s.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:i,ctx:s}=this.lower;Kt(i,s,t,e)}setCSSDimensions(t){Jt(this.lower.el,t)}calcOffset(){return function(t){var e;let i={left:0,top:0};const s=t&&Ut(t),r={left:0,top:0},n={borderLeftWidth:A,borderTopWidth:E,paddingLeft:A,paddingTop:E};if(!s)return r;const o=(null===(e=Nt(t))||void 0===e?void 0:e.getComputedStyle(t,null))||{};for(const t in n)r[n[t]]+=parseInt(o[t],10)||0;const a=s.documentElement;void 0!==t.getBoundingClientRect&&(i=t.getBoundingClientRect());const h=Ht(t);return{left:i.left+h.left-(a.clientLeft||0)+r.left,top:i.top+h.top-(a.clientTop||0)+r.top}}(this.lower.el)}dispose(){_().dispose(this.lower.el),delete this.lower}}const $t={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...k]};class te extends(K(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 te.ownDefaults}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new Qt(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];const r=super.insertAt(t,...i);return i.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),r}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(c("warn","Canvas is trying to add an object that belongs to a different canvas.\nResulting to default behavior: removing object from previous canvas and adding to new canvas"),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}_isRetinaScaling(){return h.devicePixelRatio>1&&this.enableRetinaScaling}getRetinaScaling(){return this._isRetinaScaling()?Math.max(1,h.devicePixelRatio):1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.setDimensions({width:t},e)}setHeight(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e){const e=i({width:this.width,height:this.height},t);this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t){let{cssOnly:e=!1,backstoreOnly:i=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._setDimensionsImpl(t,{cssOnly:e,backstoreOnly:i}),e||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){const e=this.backgroundImage,i=this.overlayImage,s=this._objects.length;this.viewportTransform=t;for(let t=0;t<s;t++){const e=this._objects[t];e.group||e.setCoords()}e&&e.setCoords(),i&&i.setCoords(),this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const i=t,s=[...this.viewportTransform],r=at(t,ht(s));s[0]=e,s[3]=e;const n=at(r,s);s[4]+=i.x-n.x,s[5]+=i.y-n.y,this.setViewportTransform(s)}setZoom(t){this.zoomToPoint(new N(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 N(-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=Z((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,i=ht(this.viewportTransform),s=at({x:0,y:0},i),r=at({x:t,y:e},i),n=s.min(r),o=s.max(r);return this.vptCoords={tl:n,tr:new N(o.x,n.y),bl:new N(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Q(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const i=this.viewportTransform,s=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(i[0],i[1],i[2],i[3],i[4],i[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.drawControls(t),s&&(s._set("canvas",this),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,s)),this._renderOverlay(t),this.controlsAboveOverlay&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const i=this.viewportTransform;t.save(),t.transform(...i),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let i=0,s=e.length;i<s;++i)e[i]&&e[i].render(t)}_renderBackgroundOrOverlay(t,e){const i=this["".concat(e,"Color")],s=this["".concat(e,"Image")],r=this.viewportTransform,n=this["".concat(e,"Vpt")];if(!i&&!s)return;const o=It(i);if(i){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?i.toLive(t):i,n&&t.transform(...r),o){t.transform(1,0,0,1,i.offsetX||0,i.offsetY||0);const e=i.gradientTransform||i.patternTransform;e&&t.transform(...e)}t.fill(),t.restore()}if(s){t.save();const{skipOffscreen:e}=this;this.skipOffscreen=n,n&&t.transform(...r),s.render(t),this.skipOffscreen=e,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new N(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new N(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new N(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 N(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new N(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return at(this.getCenterPoint(),ht(this.viewportTransform))}_centerObject(t,e){t.setXY(e,P,P),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,r=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return i(i(i({version:b},St(this,e)),{},{objects:this._objects.filter((t=>!t.excludeFromExport)).map((i=>this._toObject(i,t,e)))},this.__serializeBgOverlay(t,e)),r?{clipPath:r}:null)}_toObject(t,e,i){let s;this.includeDefaultValues||(s=t.includeDefaultValues,t.includeDefaultValues=!1);const r=t[e](i);return this.includeDefaultValues||(t.includeDefaultValues=!!s),r}__serializeBgOverlay(t,e){const i={},s=this.backgroundImage,r=this.overlayImage,n=this.backgroundColor,o=this.overlayColor;return It(n)?n.excludeFromExport||(i.background=n.toObject(e)):n&&(i.background=n),It(o)?o.excludeFromExport||(i.overlay=o.toObject(e)):o&&(i.overlay=o),s&&!s.excludeFromExport&&(i.backgroundImage=this._toObject(s,t,e)),r&&!r.excludeFromExport&&(i.overlayImage=this._toObject(r,t,e)),i}toSVG(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const i=[];return this._setSVGPreamble(i,t),this._setSVGHeader(i,t),this.clipPath&&i.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,')" >\n')),this._setSVGBgOverlayColor(i,"background"),this._setSVGBgOverlayImage(i,"backgroundImage",e),this._setSVGObjects(i,e),this.clipPath&&i.push("</g>\n"),this._setSVGBgOverlayColor(i,"overlay"),this._setSVGBgOverlayImage(i,"overlayImage",e),i.push("</svg>"),i.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",'" standalone="no" ?>\n','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ','"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')}_setSVGHeader(t,e){const i=e.width||"".concat(this.width),s=e.height||"".concat(this.height),r=h.NUM_FRACTION_DIGITS,n=e.viewBox;let o;if(n)o='viewBox="'.concat(n.x," ").concat(n.y," ").concat(n.width," ").concat(n.height,'" ');else if(this.svgViewportTransformation){const t=this.viewportTransform;o='viewBox="'.concat(Et(-t[4]/t[0],r)," ").concat(Et(-t[5]/t[3],r)," ").concat(Et(this.width/t[0],r)," ").concat(Et(this.height/t[3],r),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',i,'" ','height="',s,'" ',o,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",b,"</desc>\n","<defs>\n",this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),"</defs>\n")}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(tt()),'<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(It(e)){const i=this["".concat(t,"Vpt")],s=this.viewportTransform,r={isType:()=>!1,width:this.width/(i?s[0]:1),height:this.height/(i?s[3]:1)};return e.toSVG(r,{additionalTransform:i?Lt(s):""})}})).join("")}createSVGFontFacesMarkup(){const t=[],e={},i=h.fontPaths;this._objects.forEach((function e(i){t.push(i),Wt(i)&&i._objects.forEach(e)})),t.forEach((t=>{if(!Vt(t))return;const{styles:s,fontFamily:r}=t;!e[r]&&i[r]&&(e[r]=!0,s&&Object.values(s).forEach((t=>{Object.values(t).forEach((t=>{let{fontFamily:s=""}=t;!e[s]&&i[s]&&(e[s]=!0)}))})))}));const s=Object.keys(e).map((t=>"\t\t@font-face {\n\t\t\tfont-family: '".concat(t,"';\n\t\t\tsrc: url('").concat(i[t],"');\n\t\t}\n"))).join("");return s?'\t<style type="text/css"><![CDATA[\n'.concat(s,"]]></style>\n"):""}_setSVGObjects(t,e){this.forEachObject((i=>{i.excludeFromExport||this._setSVGObject(t,i,e)}))}_setSVGObject(t,e,i){t.push(e.toSVG(i))}_setSVGBgOverlayImage(t,e,i){const s=this[e];s&&!s.excludeFromExport&&s.toSVG&&t.push(s.toSVG(i))}_setSVGBgOverlayColor(t,e){const i=this["".concat(e,"Color")];if(i)if(It(i)){const s=i.repeat||"",r=this.width,n=this.height,o=this["".concat(e,"Vpt")]?Lt(ht(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(r/2,",").concat(n/2,')" x="').concat(i.offsetX-r/2,'" y="').concat(i.offsetY-n/2,'" width="').concat("repeat-y"!==s&&"no-repeat"!==s||!Yt(i)?r:i.source.width,'" height="').concat("repeat-x"!==s&&"no-repeat"!==s||!Yt(i)?n:i.source.height,'" fill="url(#SVGID_').concat(i.id,')"></rect>\n'))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',i,'"',"></rect>\n")}loadFromJSON(t,e){let{signal:i}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t)return Promise.reject(new l("`json` is undefined"));const s="string"==typeof t?JSON.parse(t):t,{objects:r=[],backgroundImage:n,background:o,overlayImage:a,overlay:h,clipPath:c}=s,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([Ct(r,{reviver:e,signal:i}),bt({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:h,clipPath:c},{signal:i})]).then((t=>{let[e,i]=t;return this.clear(),this.add(...e),this.set(s),this.set(i),this.renderOnAddRemove=d,this}))}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=et();return t.width=this.width,t.height=this.height,new this.constructor(t)}toDataURL(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{format:e="png",quality:i=1,multiplier:s=1,enableRetinaScaling:r=!1}=t,n=s*(r?this.getRetinaScaling():1);return st(this.toCanvasElement(n,t),e,i)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,{width:e,height:i,left:s,top:r,filter:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=(e||this.width)*t,a=(i||this.height)*t,h=this.getZoom(),c=this.width,l=this.height,d=h*t,u=this.viewportTransform,g=[d,0,0,d,(u[4]-(s||0))*t,(u[5]-(r||0))*t],f=this.enableRetinaScaling,p=et(),m=n?this._objects.filter((t=>n(t))):this._objects;return p.width=o,p.height=a,this.enableRetinaScaling=!1,this.viewportTransform=g,this.width=o,this.height=a,this.calcViewportBoundaries(),this.renderCanvas(p.getContext("2d"),m),this.viewportTransform=u,this.width=c,this.height=l,this.calcViewportBoundaries(),this.enableRetinaScaling=f,p}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Y.cancelByCanvas(this),this.disposed=!0,new Promise(((t,e)=>{const i=()=>{this.destroy(),t(!0)};i.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=i:i()}))}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject((t=>t.dispose())),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}s(te,"ownDefaults",$t);const ee=["touchstart","touchmove","touchend"];const ie=t=>{const e=Ht(t.target),i=function(t){const e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new N(i.clientX+e.left,i.clientY+e.top)},se=t=>ee.includes(t.type)||"touch"===t.pointerType,re=t=>{t.preventDefault(),t.stopPropagation()},ne=t=>{if(0===t.length)return{left:0,top:0,width:0,height:0};const{min:e,max:i}=t.reduce(((t,e)=>{let{min:i,max:s}=t;return{min:i.min(e),max:s.max(e)}}),{min:new N(t[0]),max:new N(t[0])}),s=i.subtract(e);return{left:e.x,top:e.y,width:s.x,height:s.y}},oe=["translateX","translateY","scaleX","scaleY"],ae=(t,e)=>he(t,ct(e,t.calcOwnMatrix())),he=(t,e)=>{const i=dt(e),{translateX:s,translateY:n,scaleX:o,scaleY:a}=i,h=r(i,oe),c=new N(s,n);t.flipX=!1,t.flipY=!1,Object.assign(t,h),t.set({scaleX:o,scaleY:a}),t.setPositionByOrigin(c,P,P)},ce=t=>{t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)},le=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}),de=(t,e,i)=>{const s=t/2,r=e/2,n=_t(i),o=[new N(-s,-r),new N(s,-r),new N(-s,r),new N(s,r)].map((t=>t.transform(n))),a=ne(o);return new N(a.width,a.height)},ue=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:k;return ct(ht(arguments.length>1&&void 0!==arguments[1]?arguments[1]:k),t)},ge=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:k;return t.transform(ue(e,i))},fe=(t,e,i)=>{const s=ue(e,i);return he(t,ct(s,t.calcOwnMatrix())),s},pe=(t,e)=>{var s;const{transform:{target:r}}=e;null===(s=r.canvas)||void 0===s||s.fire("object:".concat(t),i(i({},e),{},{target:r})),r.fire(t,e)},me={left:-.5,top:-.5,center:0,bottom:.5,right:.5},ve=t=>"string"==typeof t?me[t]:t-.5,_e="not-allowed";function ye(t){return t.originX===P&&t.originY===P}function xe(t){return.5-ve(t)}const Ce=(t,e)=>t[e],be=(t,e,i,s)=>({e:t,transform:e,pointer:new N(i,s)});function Se(t,e){const i=t.getTotalAngle()+nt(Math.atan2(e.y,e.x))+360;return Math.round(i%360/45)}function we(t,e,i,s,r){var n;let{target:o,corner:a}=t;const h=o.controls[a],c=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/c,d=function(t,e,i,s){const r=t.getRelativeCenterPoint(),n=void 0!==i&&void 0!==s?t.translateToGivenOrigin(r,P,P,i,s):new N(t.left,t.top);return(t.angle?e.rotate(-rt(t.angle),r):e).subtract(n)}(o,new N(s,r),e,i);return d.x>=l&&(d.x-=l),d.x<=-l&&(d.x+=l),d.y>=l&&(d.y-=l),d.y<=l&&(d.y+=l),d.x-=h.offsetX,d.y-=h.offsetY,d}const Te=(t,e,i,s)=>{const{target:r,offsetX:n,offsetY:o}=e,a=i-n,h=s-o,c=!Ce(r,"lockMovementX")&&r.left!==a,l=!Ce(r,"lockMovementY")&&r.top!==h;return c&&r.set(A,a),l&&r.set(E,h),(c||l)&&pe("moving",be(t,e,i,s)),c||l};class Oe{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",i=this.strokeWidth?this.strokeWidth:"0",s=this.strokeDashArray?this.strokeDashArray.join(" "):L,r=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",h=void 0!==this.opacity?this.opacity:"1",c=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),d=Rt("fill",this.fill);return[Rt("stroke",this.stroke),"stroke-width: ",i,"; ","stroke-dasharray: ",s,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",d,"fill-rule: ",e,"; ","opacity: ",h,";",l,c].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const i=t?this.calcTransformMatrix():this.calcOwnMatrix(),s='transform="'.concat(Lt(i));return"".concat(s).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:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[this.getSvgTransform(!0,i),this.getSvgCommons()].join(""),r=t.indexOf("COMMON_PARTS");return t[r]=s,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:i,withShadow:s,additionalTransform:r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=s?'style="'.concat(this.getSvgFilter(),'" '):"",a=this.clipPath,h=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",c=a&&a.absolutePositioned,l=this.stroke,d=this.fill,u=this.shadow,g=[],f=t.indexOf("COMMON_PARTS");let p;a&&(a.clipPathId="CLIPPATH_".concat(tt()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(i),"</clipPath>\n")),c&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),c?"":o+this.getSvgCommons()," >\n");const m=[n,h,e?"":this.addPaintOrder()," ",r?'transform="'.concat(r,'" '):""].join("");return t[f]=m,It(d)&&g.push(d.toSVG(this)),It(l)&&g.push(l.toSVG(this)),u&&g.push(u.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),c&&g.push("</g>\n"),i?i(g.join("")):g.join("")}addPaintOrder(){return"fill"!==this.paintFirst?' paint-order="'.concat(this.paintFirst,'" '):""}}const ke=(t,e,i,s)=>(t<Math.abs(e)?(t=e,s=i/4):s=0===e&&0===t?i/T*Math.asin(1):i/T*Math.asin(e/t),{a:t,c:e,p:i,s:s}),De=(t,e,i,s,r)=>t*Math.pow(2,10*(s-=1))*Math.sin((s*r-e)*T/i),Me=(t,e,i,s)=>-i*Math.cos(t/s*w)+i+e,Pe=(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,Ae=(t,e,i,s)=>i-Pe(s-t,0,i,s)+e;var Ee=Object.freeze({__proto__:null,defaultEasing:Me,easeInBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},easeInBounce:Ae,easeInCirc:(t,e,i,s)=>-i*(Math.sqrt(1-(t/=s)*t)-1)+e,easeInCubic:(t,e,i,s)=>i*(t/s)**3+e,easeInElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(1===(t/=s))return e+i;n||(n=.3*s);const{a:o,s:a,p:h}=ke(r,i,n,1.70158);return-De(o,a,h,t,s)+e},easeInExpo:(t,e,i,s)=>0===t?e:i*2**(10*(t/s-1))+e,easeInOutBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInOutBounce:(t,e,i,s)=>t<s/2?.5*Ae(2*t,0,i,s)+e:.5*Pe(2*t-s,0,i,s)+.5*i+e,easeInOutCirc:(t,e,i,s)=>(t/=s/2)<1?-i/2*(Math.sqrt(1-t**2)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e,easeInOutCubic:(t,e,i,s)=>(t/=s/2)<1?i/2*t**3+e:i/2*((t-2)**3+2)+e,easeInOutElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(2===(t/=s/2))return e+i;n||(n=s*(.3*1.5));const{a:o,s:a,p:h,c:c}=ke(r,i,n,1.70158);return t<1?-.5*De(o,a,h,t,s)+e:o*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*T/h)*.5+c+e},easeInOutExpo:(t,e,i,s)=>0===t?e:t===s?e+i:(t/=s/2)<1?i/2*2**(10*(t-1))+e:i/2*-(2**(-10*--t)+2)+e,easeInOutQuad:(t,e,i,s)=>(t/=s/2)<1?i/2*t**2+e:-i/2*(--t*(t-2)-1)+e,easeInOutQuart:(t,e,i,s)=>(t/=s/2)<1?i/2*t**4+e:-i/2*((t-=2)*t**3-2)+e,easeInOutQuint:(t,e,i,s)=>(t/=s/2)<1?i/2*t**5+e:i/2*((t-2)**5+2)+e,easeInOutSine:(t,e,i,s)=>-i/2*(Math.cos(Math.PI*t/s)-1)+e,easeInQuad:(t,e,i,s)=>i*(t/=s)*t+e,easeInQuart:(t,e,i,s)=>i*(t/=s)*t**3+e,easeInQuint:(t,e,i,s)=>i*(t/s)**5+e,easeInSine:(t,e,i,s)=>-i*Math.cos(t/s*w)+i+e,easeOutBack:function(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},easeOutBounce:Pe,easeOutCirc:(t,e,i,s)=>i*Math.sqrt(1-(t=t/s-1)*t)+e,easeOutCubic:(t,e,i,s)=>i*((t/s-1)**3+1)+e,easeOutElastic:(t,e,i,s)=>{const r=i;let n=0;if(0===t)return e;if(1===(t/=s))return e+i;n||(n=.3*s);const{a:o,s:a,p:h,c:c}=ke(r,i,n,1.70158);return o*2**(-10*t)*Math.sin((t*s-a)*T/h)+c+e},easeOutExpo:(t,e,i,s)=>t===s?e+i:i*-(2**(-10*t/s)+1)+e,easeOutQuad:(t,e,i,s)=>-i*(t/=s)*(t-2)+e,easeOutQuart:(t,e,i,s)=>-i*((t=t/s-1)*t**3-1)+e,easeOutQuint:(t,e,i,s)=>i*((t/s-1)**5+1)+e,easeOutSine:(t,e,i,s)=>i*Math.sin(t/s*w)+e});const je=()=>!1;class Fe{constructor(t){let{startValue:e,byValue:i,duration:r=500,delay:n=0,easing:o=Me,onStart:a=S,onChange:h=S,onComplete:c=S,abort:l=je,target:d}=t;s(this,"_state","pending"),s(this,"durationProgress",0),s(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=r,this.delay=n,this.easing=o,this._onStart=a,this._onChange=h,this._onComplete=c,this._abort=l,this.target=d,this.startValue=e,this.byValue=i,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return"aborted"===this._state||"completed"===this._state}start(){const t=t=>{"pending"===this._state&&(this.startTime=t||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout((()=>Z(t)),this.delay):Z(t)}tick(t){const e=(t||+new Date)-this.startTime,i=Math.min(e,this.duration);this.durationProgress=i/this.duration;const{value:s,valueProgress:r}=this.calculate(i);this.value=Object.freeze(s),this.valueProgress=r,"aborted"!==this._state&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),Z(this.tick)))}register(){Y.push(this)}unregister(){Y.remove(this)}abort(){this._state="aborted",this.unregister()}}const Le=["startValue","endValue"];class Re extends Fe{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(i(i({},r(t,Le)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const Be=["startValue","endValue"];class Ie extends Fe{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(i(i({},r(t,Be)),{},{startValue:e,byValue:s.map(((t,i)=>t-e[i]))}))}calculate(t){const e=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i)));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const Xe=(t,e,i)=>Math.max(t,Math.min(e,i)),Ye=["startValue","endValue","easing","onChange","onComplete","abort"],We=(t,e,i,s)=>e+i*(1-Math.cos(t/s*w)),Ve=t=>t&&((e,i,s)=>t(new At(e).toRgba(),i,s));class Ge extends Fe{constructor(t){let{startValue:e,endValue:s,easing:n=We,onChange:o,onComplete:a,abort:h}=t,c=r(t,Ye);const l=new At(e).getSource(),d=new At(s).getSource();super(i(i({},c),{},{startValue:l,byValue:d.map(((t,e)=>t-l[e])),easing:n,onChange:Ve(o),onComplete:Ve(a),abort:Ve(h)}))}calculate(t){const[e,i,s,r]=this.startValue.map(((e,i)=>this.easing(t,e,this.byValue[i],this.duration,i))),n=[...[e,i,s].map(Math.round),Xe(0,r,1)];return{value:n,valueProgress:n.map(((t,e)=>0!==this.byValue[e]?Math.abs((t-this.startValue[e])/this.byValue[e]):0)).find((t=>0!==t))||0}}}const ze=t=>Array.isArray(t.startValue)||Array.isArray(t.endValue);function He(t){const e=ze(t)?new Ie(t):new Re(t);return e.start(),e}function Ue(t){const e=new Ge(t);return e.start(),e}const Ne=new N(1,0),qe=new N,Ke=(t,e)=>t.rotate(e),Je=(t,e)=>new N(e).subtract(t),Ze=t=>t.distanceFrom(qe),Qe=(t,e)=>Math.atan2(ii(t,e),si(t,e)),$e=t=>Qe(Ne,t),ti=t=>t.eq(qe)?t:t.scalarDivide(Ze(t)),ei=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return ti(new N(-t.y,t.x).scalarMultiply(e?1:-1))},ii=(t,e)=>t.x*e.y-t.y*e.x,si=(t,e)=>t.x*e.x+t.y*e.y,ri=(t,e,i)=>{if(t.eq(e)||t.eq(i))return!0;const s=ii(e,i),r=ii(e,t),n=ii(i,t);return s>=0?r>=0&&n<=0:!(r<=0&&n>=0)};class ni{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),i=0;i<t;i++)e[i]=arguments[i];return this.points=this.points.concat(e.filter((t=>!this.includes(t)))),this}static isPointContained(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e.eq(i))return t.eq(e);if(e.x===i.x)return t.x===e.x&&(s||t.y>=Math.min(e.y,i.y)&&t.y<=Math.max(e.y,i.y));if(e.y===i.y)return t.y===e.y&&(s||t.x>=Math.min(e.x,i.x)&&t.x<=Math.max(e.x,i.x));{const r=Je(e,i),n=Je(e,t).divide(r);return s?Math.abs(n.x)===Math.abs(n.y):n.x===n.y&&n.x>=0&&n.x<=1}}static isPointInPolygon(t,e){const i=new N(t).setX(Math.min(t.x-1,...e.map((t=>t.x))));let s=0;for(let r=0;r<e.length;r++){const n=this.intersectSegmentSegment(e[r],e[(r+1)%e.length],t,i);if(n.includes(t))return!0;s+=Number("Intersection"===n.status)}return s%2==1}static intersectLineLine(t,e,i,s){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],n=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];const o=e.x-t.x,a=e.y-t.y,h=s.x-i.x,c=s.y-i.y,l=t.x-i.x,d=t.y-i.y,u=h*d-c*l,g=o*d-a*l,f=c*o-h*a;if(0!==f){const e=u/f,i=g/f;return(r||0<=e&&e<=1)&&(n||0<=i&&i<=1)?new ni("Intersection").append(new N(t.x+e*o,t.y+e*a)):new ni}if(0===u||0===g){const o=r||n||ni.isPointContained(t,i,s)||ni.isPointContained(e,i,s)||ni.isPointContained(i,t,e)||ni.isPointContained(s,t,e);return new ni(o?"Coincident":void 0)}return new ni("Parallel")}static intersectSegmentLine(t,e,i,s){return ni.intersectLineLine(t,e,i,s,!1,!0)}static intersectSegmentSegment(t,e,i,s){return ni.intersectLineLine(t,e,i,s,!1,!1)}static intersectLinePolygon(t,e,i){let s=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];const r=new ni,n=i.length;for(let o,a,h,c=0;c<n;c++){if(o=i[c],a=i[(c+1)%n],h=ni.intersectLineLine(t,e,o,a,s,!1),"Coincident"===h.status)return h;r.append(...h.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectSegmentPolygon(t,e,i){return ni.intersectLinePolygon(t,e,i,!1)}static intersectPolygonPolygon(t,e){const i=new ni,s=t.length,r=[];for(let n=0;n<s;n++){const o=t[n],a=t[(n+1)%s],h=ni.intersectSegmentPolygon(o,a,e);"Coincident"===h.status?(r.push(h),i.append(o,a)):i.append(...h.points)}return r.length>0&&r.length===t.length?new ni("Coincident"):(i.points.length>0&&(i.status="Intersection"),i)}static intersectPolygonRectangle(t,e,i){const s=e.min(i),r=e.max(i),n=new N(r.x,s.y),o=new N(s.x,r.y);return ni.intersectPolygonPolygon(t,[s,n,r,o])}}class oi extends J{_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=i({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let r=s,n=0;this.strokeUniform&&(r=0,n=s);const o=e.width+r,a=e.height+r;let h;return h=0===e.skewX&&0===e.skewY?new N(o*e.scaleX,a*e.scaleY):de(o,a,e),h.scalarAdd(n)}translateToGivenOrigin(t,e,i,s,r){let n=t.x,o=t.y;const a=ve(s)-ve(e),h=ve(r)-ve(i);if(a||h){const t=this._getTransformedDimensions();n+=a*t.x,o+=h*t.y}return new N(n,o)}translateToCenterPoint(t,e,i){const s=this.translateToGivenOrigin(t,e,i,P,P);return this.angle?s.rotate(rt(this.angle),t):s}translateToOriginPoint(t,e,i){const s=this.translateToGivenOrigin(t,P,P,e,i);return this.angle?s.rotate(rt(this.angle),t):s}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?at(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new N(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,i){const s=this.translateToCenterPoint(t,e,i),r=this.translateToOriginPoint(s,this.originX,this.originY);this.set({left:r.x,top:r.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),A,E)}}class ai extends oi{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?at(t,this.group.calcTransformMatrix()):t}setXY(t,e,i){this.group&&(t=at(t,ht(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,i)}getRelativeXY(){return new N(this.left,this.top)}setRelativeXY(t,e,i){this.setPositionByOrigin(t,e||this.originX,i||this.originY)}_getCoords(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?t?this.calcACoords():this.calcLineCoords():(this.aCoords||(this.aCoords=this.calcACoords()),this.lineCoords||(this.lineCoords=this.calcLineCoords()),t?this.aCoords:this.lineCoords)}getCoords(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{tl:i,tr:s,br:r,bl:n}=this._getCoords(t,e),o=[i,s,r,n];if(this.group){const t=this.group.calcTransformMatrix();return o.map((e=>at(e,t)))}return o}intersectsWithRect(t,e,i,s){const r=this.getCoords(i,s);return"Intersection"===ni.intersectPolygonRectangle(r,t,e).status}intersectsWithObject(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=ni.intersectPolygonPolygon(this.getCoords(e,i),t.getCoords(e,i));return"Intersection"===s.status||"Coincident"===s.status||t.isContainedWithinObject(this,e,i)||this.isContainedWithinObject(t,e,i)}isContainedWithinObject(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=this.getCoords(e,i);return i&&t.getCoords(e,!0),s.every((e=>t.containsPoint(e)))}isContainedWithinRect(t,e,i,s){const r=this.getBoundingRect(i,s);return r.left>=t.x&&r.left+r.width<=e.x&&r.top>=t.y&&r.top+r.height<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return ni.isPointInPolygon(t,this.getCoords(e,i))}isOnScreen(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!this.canvas)return!1;const{tl:e,br:i}=this.canvas.vptCoords;return!!this.getCoords(!0,t).some((t=>t.x<=i.x&&t.x>=e.x&&t.y<=i.y&&t.y>=e.y))||(!!this.intersectsWithRect(e,i,!0,t)||this._containsCenterOfCanvas(e,i,t))}_containsCenterOfCanvas(t,e,i){const s=t.midPointFrom(e);return this.containsPoint(s,!0,i)}isPartiallyOnScreen(t){if(!this.canvas)return!1;const{tl:e,br:i}=this.canvas.vptCoords;if(this.intersectsWithRect(e,i,!0,t))return!0;return this.getCoords(!0,t).every((t=>(t.x>=i.x||t.x<=e.x)&&(t.y>=i.y||t.y<=e.y)))&&this._containsCenterOfCanvas(e,i,t)}getBoundingRect(t,e){return ne(this.getCoords(t,e))}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set("scaleX",t),this._set("scaleY",t),this.setCoords()}scaleToWidth(t,e){const i=this.getBoundingRect(e).width/this.getScaledWidth();return this.scale(t/this.width/i)}scaleToHeight(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.getBoundingRect(e).height/this.getScaledHeight();return this.scale(t/this.height/i)}getCanvasRetinaScaling(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?dt(this.calcTransformMatrix()).angle:this.angle}calcLineCoords(){const t=this.getViewportTransform(),e=this.padding,i=rt(this.getTotalAngle()),s=H(i)*e,r=U(i)*e,n=s+r,o=s-r,{tl:a,tr:h,bl:c,br:l}=this.calcACoords(),d={tl:at(a,t),tr:at(h,t),bl:at(c,t),br:at(l,t)};return e&&(d.tl.x-=o,d.tl.y-=n,d.tr.x+=n,d.tr.y-=o,d.bl.x-=n,d.bl.y+=o,d.br.x+=o,d.br.y+=n),d}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||k.concat()}calcACoords(){const t=gt({angle:this.angle}),{x:e,y:i}=this.getRelativeCenterPoint(),s=ut(e,i),r=ct(s,t),n=this._getTransformedDimensions(),o=n.x/2,a=n.y/2;return{tl:at({x:-o,y:-a},r),tr:at({x:o,y:-a},r),bl:at({x:-o,y:a},r),br:at({x:o,y:a},r)}}setCoords(){this.aCoords=this.calcACoords(),this.lineCoords=this.group?this.aCoords:this.calcLineCoords()}transformMatrixKey(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e="_";let i="";return!t&&this.group&&(i=this.group.transformMatrixKey(t)+e),i+this.top+e+this.left+e+this.scaleX+e+this.scaleY+e+this.skewX+e+this.skewY+e+this.angle+e+this.originX+e+this.originY+e+this.width+e+this.height+e+this.strokeWidth+this.flipX+this.flipY}calcTransformMatrix(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const i=this.transformMatrixKey(t),s=this.matrixCache;return s&&s.key===i?s.value:(this.group&&(e=ct(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:i,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const i=this.getRelativeCenterPoint(),s={angle:this.angle,translateX:i.x,translateY:i.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},r=yt(s);return this.ownMatrixCache={key:t,value:r},r}_getNonTransformedDimensions(){return new N(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}}class hi extends ai{getParent(t){return((e=this.group)&&e.isType("ActiveSelection")?this.__owningGroup:this.group)||(t?void 0:this.canvas);var e}isDescendantOf(t){return this.__owningGroup===t||this.group===t||this.canvas===t||!!this.__owningGroup&&this.__owningGroup.isDescendantOf(t)||!!this.group&&this.group.isDescendantOf(t)}getAncestors(t){const e=[];let i=this;do{i=i instanceof hi?i.getParent(t):void 0,i&&e.push(i)}while(i);return e}findCommonAncestors(t,e){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors(e)]};const i=this.getAncestors(e),s=t.getAncestors(e);if(0===i.length&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let e,r=0;r<i.length;r++){if(e=i[r],e===t)return{fork:[this,...i.slice(0,r)],otherFork:[],common:i.slice(r)};for(let n=0;n<s.length;n++){if(this===s[n])return{fork:[],otherFork:[t,...s.slice(0,n)],common:[this,...i]};if(e===s[n])return{fork:[this,...i.slice(0,r)],otherFork:[t,...s.slice(0,n)],common:i.slice(r)}}}return{fork:[this,...i],otherFork:[t,...s],common:[]}}hasCommonAncestors(t,e){const i=this.findCommonAncestors(t,e);return i&&!!i.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(!e)return;if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const i=e.common[0];if(!i)return;const s=e.fork.pop(),r=e.otherFork.pop(),n=i._objects.indexOf(s),o=i._objects.indexOf(r);return n>-1&&n>o}}class ci extends hi{animate(t,e){return Object.entries(t).reduce(((t,i)=>{let[s,r]=i;return t[s]=this._animate(s,r,e),t}),{})}_animate(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=t.split("."),r=this.colorProperties.includes(s[s.length-1]),{easing:n,duration:o,abort:a,startValue:h,onChange:c,onComplete:l}=i,d={target:this,startValue:null!=h?h:s.reduce(((t,e)=>t[e]),this),endValue:e,easing:n,duration:o,abort:null==a?void 0:a.bind(this),onChange:(t,e,i)=>{s.reduce(((e,i,r)=>(r===s.length-1&&(e[i]=t),e[i])),this),c&&c(t,e,i)},onComplete:(t,e,i)=>{this.setCoords(),l&&l(t,e,i)}};return r?Ue(d):He(d)}}class li{constructor(t){const e="string"==typeof t?li.parseShadow(t):t;Object.assign(this,this.constructor.ownDefaults);for(const t in e)this[t]=e[t];this.id=tt()}static parseShadow(t){const e=t.trim(),[i,s=0,r=0,n=0]=(li.reOffsetsAndBlur.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(li.reOffsetsAndBlur,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:r,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Ke(new N(this.offsetX,this.offsetY),rt(-t.angle)),i=new At(this.color);let s=40,r=40;return t.width&&t.height&&(s=100*Et((Math.abs(e.x)+this.blur)/t.width,h.NUM_FRACTION_DIGITS)+20,r=100*Et((Math.abs(e.y)+this.blur)/t.height,h.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(r,'%" height="').concat(100+2*r,'%" x="-').concat(s,'%" width="').concat(100+2*s,'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="').concat(Et(this.blur?this.blur/2:0,h.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(Et(e.x,h.NUM_FRACTION_DIGITS),'" dy="').concat(Et(e.y,h.NUM_FRACTION_DIGITS),'" result="oBlur" ></feOffset>\n\t<feFlood flood-color="').concat(i.toRgb(),'" flood-opacity="').concat(i.getAlpha(),'"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n')}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling},e=li.ownDefaults;return this.includeDefaultValues?t:wt(t,((t,i)=>t!==e[i]))}}s(li,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),s(li,"reOffsetsAndBlur",/(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/);const di=t=>JSON.parse(JSON.stringify(t)),ui=[E,A,"scaleX","scaleY","flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible","skewX","skewY"],gi=["fill","stroke","strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],fi={originX:A,originY:E,top:0,left:0,width:0,height:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1,opacity:1,angle:0,skewX:0,skewY:0,cornerSize:13,touchCornerSize:24,transparentCorners:!0,hoverCursor:null,moveCursor:null,padding:0,borderColor:"rgb(178,204,255)",borderDashArray:null,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,centeredScaling:!1,centeredRotation:!0,fill:"rgb(0,0,0)",fillRule:"nonzero",globalCompositeOperation:"source-over",backgroundColor:"",selectionBackgroundColor:"",stroke:null,strokeWidth:1,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,shadow:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,minScaleLimit:0,selectable:!0,evented:!0,visible:!0,hasControls:!0,hasBorders:!0,perPixelTargetFind:!1,includeDefaultValues:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,excludeFromExport:!1,objectCaching:!0,noScaleCache:!0,strokeUniform:!1,dirty:!0,paintFirst:"fill",activeOn:"down",colorProperties:["fill","stroke","backgroundColor"],clipPath:void 0,inverted:!1,absolutePositioned:!1,FX_DURATION:500},pi=["extraParam"];let mi=class t extends ci{static getDefaults(){return i({},t.ownDefaults)}get type(){const t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){c("warn","Setting type has no effect",t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(),s(this,"_cacheContext",null),Object.assign(this,this.constructor.getDefaults()),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=et(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,i=t.height,s=h.maxCacheSideLimit,r=h.minCacheSideLimit;if(e<=s&&i<=s&&e*i<=h.perfLimitSizeTotal)return e<r&&(t.width=r),i<r&&(t.height=r),t;const n=e/i,[o,a]=C.limitDimsByArea(n),c=Xe(r,o,s),l=Xe(r,a,s);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),i>l&&(t.zoomY/=i/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),i=e.x*t.x/this.scaleX,s=e.y*t.y/this.scaleY;return{width:i+2,height:s+2,zoomX:t.x,zoomY:t.y,x:i,y:s}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,i=this._limitCacheSize(this._getCacheCanvasDimensions()),s=h.minCacheSideLimit,r=i.width,n=i.height,o=i.zoomX,a=i.zoomY,c=r!==this.cacheWidth||n!==this.cacheHeight,l=this.zoomX!==o||this.zoomY!==a;if(!t||!e)return!1;let d,u,g=c||l,f=0,p=0,m=!1;if(c){const t=this._cacheCanvas.width,e=this._cacheCanvas.height,o=r>t||n>e;m=o||(r<.9*t||n<.9*e)&&t>s&&e>s,o&&!i.capped&&(r>s||n>s)&&(f=.1*r,p=.1*n)}return Vt(this)&&this.path&&(g=!0,m=!0,f+=this.getHeightOfLine(0)*this.zoomX,p+=this.getHeightOfLine(0)*this.zoomY),!!g&&(m?(t.width=Math.ceil(r+f),t.height=Math.ceil(n+p)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),d=i.x/2,u=i.y/2,this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-u)+u,this.cacheWidth=r,this.cacheHeight=n,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(o,a),this.zoomX=o,this.zoomY=a,!0)}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,i=this.calcTransformMatrix(!e);t.transform(i[0],i[1],i[2],i[3],i[4],i[5])}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=h.NUM_FRACTION_DIGITS,s=this.clipPath&&!this.clipPath.excludeFromExport?i(i({},this.clipPath.toObject(t)),{},{inverted:this.clipPath.inverted,absolutePositioned:this.clipPath.absolutePositioned}):null,r=i(i({},St(this,t)),{},{type:this.constructor.type,version:b,originX:this.originX,originY:this.originY,left:Et(this.left,e),top:Et(this.top,e),width:Et(this.width,e),height:Et(this.height,e),fill:Xt(this.fill)?this.fill.toObject():this.fill,stroke:Xt(this.stroke)?this.stroke.toObject():this.stroke,strokeWidth:Et(this.strokeWidth,e),strokeDashArray:this.strokeDashArray?this.strokeDashArray.concat():this.strokeDashArray,strokeLineCap:this.strokeLineCap,strokeDashOffset:this.strokeDashOffset,strokeLineJoin:this.strokeLineJoin,strokeUniform:this.strokeUniform,strokeMiterLimit:Et(this.strokeMiterLimit,e),scaleX:Et(this.scaleX,e),scaleY:Et(this.scaleY,e),angle:Et(this.angle,e),flipX:this.flipX,flipY:this.flipY,opacity:Et(this.opacity,e),shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible,backgroundColor:this.backgroundColor,fillRule:this.fillRule,paintFirst:this.paintFirst,globalCompositeOperation:this.globalCompositeOperation,skewX:Et(this.skewX,e),skewY:Et(this.skewY,e)},s?{clipPath:s}:null);return this.includeDefaultValues?r:this._removeDefaultValues(r)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),i=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return wt(t,((t,e)=>{if(e===A||e===E||"type"===e)return!0;const s=i[e];return t!==s&&!(Array.isArray(t)&&Array.isArray(s)&&0===t.length&&0===s.length)}))}toString(){return"#<".concat(this.constructor.type,">")}getObjectScaling(){if(!this.group)return new N(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=dt(this.calcTransformMatrix());return new N(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),i=this.getCanvasRetinaScaling();return t.scalarMultiply(e*i)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:0===t?1e-4:t}_set(t,e){const i=this[t]!==e;if("scaleX"!==t&&"scaleY"!==t||(e=this._constrainScale(e)),"scaleX"===t&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof li?"dirty"===t&&this.group&&this.group.set("dirty",e):e=new li(e),this[t]=e,i){const e=this.group&&this.group.isOnACache();this.constructor.cacheProperties.includes(t)?(this.dirty=!0,e&&this.group.set("dirty",!0)):e&&this.constructor.stateProperties.includes(t)&&this.group.set("dirty",!0)}return 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),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null,this.cacheWidth=0,this.cacheHeight=0}hasStroke(){return this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth}hasFill(){return this.fill&&"transparent"!==this.fill}needsItsOwnCache(){return!("stroke"!==this.paintFirst||!this.hasFill()||!this.hasStroke()||"object"!=typeof this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.group||!this.group.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const e=ht(this.calcTransformMatrix());t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const i=this.fill,s=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=i,this.stroke=s}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}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;if(this._cacheCanvas&&this._cacheContext&&!t&&this._updateCacheCanvas())return!0;if(this.dirty||this.clipPath&&this.clipPath.absolutePositioned){if(this._cacheCanvas&&this._cacheContext&&!t){const t=this.cacheWidth/this.zoomX,e=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-t/2,-e/2,t,e)}return!0}return!1}_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 i=e.stroke;i&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,It(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?this._applyPatternForTransformedGradient(t,i):(t.strokeStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:i}=e;i&&(It(i)?(t.fillStyle=i.toLive(t),this._applyPatternGradientTransform(t,i)):t.fillStyle=i)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&0!==e.length&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,i=this.canvas,s=this.getCanvasRetinaScaling(),[r,,,n]=(null==i?void 0:i.viewportTransform)||k,o=r*s,a=n*s,c=e.nonScaling?new N(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*h.browserShadowBlurConstant*(o+a)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*a*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!It(e))return{offsetX:0,offsetY:0};const i=e.gradientTransform||e.patternTransform,s=-this.width/2+e.offsetX||0,r=-this.height/2+e.offsetY||0;return"percentage"===e.gradientUnits?t.transform(this.width,0,0,this.height,s,r):t.transform(1,0,0,1,s,r),i&&t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),{offsetX:s,offsetY:r}}_renderPaintInOrder(t){"stroke"===this.paintFirst?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),"evenodd"===this.fillRule?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&0!==this.strokeWidth){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){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 i;const s=this._limitCacheSize(this._getCacheCanvasDimensions()),r=et(),n=this.getCanvasRetinaScaling(),o=s.x/this.scaleX/n,a=s.y/this.scaleY/n;r.width=Math.ceil(o),r.height=Math.ceil(a);const h=r.getContext("2d");h&&(h.beginPath(),h.moveTo(0,0),h.lineTo(o,0),h.lineTo(o,a),h.lineTo(0,a),h.closePath(),h.translate(o/2,a/2),h.scale(s.zoomX/this.scaleX/n,s.zoomY/this.scaleY/n),this._applyPatternGradientTransform(h,e),h.fillStyle=e.toLive(t),h.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/s.zoomX,n*this.scaleY/s.zoomY),t.strokeStyle=null!==(i=h.createPattern(r,"no-repeat"))&&void 0!==i?i:"")}_findCenterFromElement(){return new N(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(X.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=le(this),i=this.group,s=this.shadow,r=Math.abs,n=t.enableRetinaScaling?Math.max(h.devicePixelRatio,1):1,o=(t.multiplier||1)*n;delete this.group,t.withoutTransform&&ce(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&fe(this,this.getViewportTransform());const a=et(),c=this.getBoundingRect(!0,!0),l=this.shadow,d=new N;if(l){const t=l.blur,e=l.nonScaling?new N(1,1):this.getObjectScaling();d.x=2*Math.round(r(l.offsetX)+t)*r(e.x),d.y=2*Math.round(r(l.offsetY)+t)*r(e.y)}const u=c.width+d.x,g=c.height+d.y;a.width=Math.ceil(u),a.height=Math.ceil(g);const f=new te(a,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1});"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new N(f.width/2,f.height/2),P,P);const p=this.canvas;f._objects=[this],this.set("canvas",f),this.setCoords();const m=f.toCanvasElement(o||1,t);return this.set("canvas",p),this.shadow=s,i&&(this.group=i),this.set(e),this.setCoords(),f._objects=[],f.destroy(),m}toDataURL(){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),i=0;i<t;i++)e[i]=arguments[i];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:i,originY:s}=this;if(e){const{x:t,y:e}=this.getRelativeCenterPoint();this.originX=P,this.originY=P,this.left=t,this.top=e}if(this.set("angle",t),e){const{x:t,y:e}=this.translateToOriginPoint(this.getRelativeCenterPoint(),i,s);this.left=t,this.top=e,this.originX=i,this.originY=s}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Y.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&_().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}static _fromObject(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:s}=e,n=r(e,pi);return bt(di(t),n).then((t=>{const e=i(i({},n),t);if(s){const{[s]:t,type:i}=e;return new this(t,r(e,[s,"type"].map(o)))}return new this(e)}))}static fromObject(t,e){return this._fromObject(t,e)}};s(mi,"stateProperties",ui),s(mi,"cacheProperties",gi),s(mi,"ownDefaults",fi),s(mi,"type","FabricObject"),X.setClass(mi),X.setClass(mi,"object");const vi=(t,e)=>(i,s,r,n)=>{const o=e(i,s,r,n);return o&&pe(t,be(i,s,r,n)),o};function _i(t){return(e,i,s,r)=>{const{target:n,originX:o,originY:a}=i,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,o,a),l=t(e,i,s,r);return n.setPositionByOrigin(c,i.originX,i.originY),l}}const yi=vi("resizing",_i(((t,e,i,s)=>{const r=we(e,e.originX,e.originY,i,s);if(e.originX===P||e.originX===F&&r.x<0||e.originX===A&&r.x>0){const{target:t}=e,i=t.strokeWidth/(t.strokeUniform?t.scaleX:1),s=ye(e)?2:1,n=t.width,o=Math.ceil(Math.abs(r.x*s/t.scaleX)-i);return t.set("width",Math.max(o,0)),n!==t.width}return!1})));function xi(t,e,i,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,h=a?"stroke":"fill",c=!a&&(s.cornerStrokeColor||r.cornerStrokeColor);let l,d=e,u=i;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,t.scale(1,o/n),u=i*n/o):o>n?(l=o,t.scale(n/o,1),d=e*o/n):l=n,t.lineWidth=1,t.beginPath(),t.arc(d,u,l/2,0,T,!1),t[h](),c&&t.stroke(),t.restore()}function Ci(t,e,i,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,h=a?"stroke":"fill",c=!a&&(s.cornerStrokeColor||r.cornerStrokeColor),l=n/2,d=o/2;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",t.lineWidth=1,t.translate(e,i);const u=r.getTotalAngle();t.rotate(rt(u)),t["".concat(h,"Rect")](-l,-d,n,o),c&&t.strokeRect(-l,-d,n,o),t.restore()}class bi{constructor(t){s(this,"visible",!0),s(this,"actionName","scale"),s(this,"angle",0),s(this,"x",0),s(this,"y",0),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"sizeX",0),s(this,"sizeY",0),s(this,"touchSizeX",0),s(this,"touchSizeY",0),s(this,"cursorStyle","crosshair"),s(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,i,s){var r;let{tl:n,tr:o,br:a,bl:h}=s;return(null===(r=e.canvas)||void 0===r?void 0:r.getActiveObject())===e&&e.isControlVisible(t)&&ni.isPointInPolygon(i,[n,o,a,h])}getActionHandler(t,e,i){return this.actionHandler}getMouseDownHandler(t,e,i){return this.mouseDownHandler}getMouseUpHandler(t,e,i){return this.mouseUpHandler}cursorStyleHandler(t,e,i){return e.cursorStyle}getActionName(t,e,i){return e.actionName}getVisibility(t,e){var i,s;return null!==(i=null===(s=t._controlsVisibility)||void 0===s?void 0:s[e])&&void 0!==i?i:this.visible}setVisibility(t,e,i){this.visible=t}positionHandler(t,e,i,s){return new N(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,i,s,r,n){const o=lt([ut(i,s),gt({angle:t}),ft((r?this.touchSizeX:this.sizeX)||e,(r?this.touchSizeY:this.sizeY)||e)]);return{tl:new N(-.5,-.5).transform(o),tr:new N(.5,-.5).transform(o),bl:new N(-.5,.5).transform(o),br:new N(.5,.5).transform(o)}}render(t,e,i,s,r){if("circle"===((s=s||{}).cornerStyle||r.cornerStyle))xi.call(this,t,e,i,s,r);else Ci.call(this,t,e,i,s,r)}}const Si=(t,e,i)=>i.lockRotation?_e:e.cursorStyle,wi=vi("rotating",_i(((t,e,i,s)=>{let{target:r,ex:n,ey:o,theta:a,originX:h,originY:c}=e;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),h,c);if(Ce(r,"lockRotation"))return!1;const d=Math.atan2(o-l.y,n-l.x),u=Math.atan2(s-l.y,i-l.x);let g=nt(u-d+a);if(r.snapAngle&&r.snapAngle>0){const t=r.snapAngle,e=r.snapThreshold||t,i=Math.ceil(g/t)*t,s=Math.floor(g/t)*t;Math.abs(g-s)<e?g=s:Math.abs(g-i)<e&&(g=i)}g<0&&(g=360+g),g%=360;const f=r.angle!==g;return r.angle=g,f})));function Ti(t,e){const i=e.canvas,s=t[i.uniScaleKey];return i.uniformScaling&&!s||!i.uniformScaling&&s}function Oi(t,e,i){const s=Ce(t,"lockScalingX"),r=Ce(t,"lockScalingY");return!(!s||!r)||(!(e||!s&&!r||!i)||(!(!s||"x"!==e)||!(!r||"y"!==e)))}const ki=["e","se","s","sw","w","nw","n","ne","e"],Di=(t,e,i)=>{const s=Ti(t,i);if(Oi(i,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",s))return _e;const r=Se(i,e);return"".concat(ki[r],"-resize")};function Mi(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=r.by,a=Ti(t,n);let h,c,l,d,u,g;if(Oi(n,o,a))return!1;if(e.gestureScale)c=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(h=we(e,e.originX,e.originY,i,s),u="y"!==o?Math.sign(h.x||e.signX||1):1,g="x"!==o?Math.sign(h.y||e.signY||1):1,e.signX||(e.signX=u),e.signY||(e.signY=g),Ce(n,"lockScalingFlip")&&(e.signX!==u||e.signY!==g))return!1;if(d=n._getTransformedDimensions(),a&&!o){const t=Math.abs(h.x)+Math.abs(h.y),{original:i}=e,s=t/(Math.abs(d.x*i.scaleX/n.scaleX)+Math.abs(d.y*i.scaleY/n.scaleY));c=i.scaleX*s,l=i.scaleY*s}else c=Math.abs(h.x*n.scaleX/d.x),l=Math.abs(h.y*n.scaleY/d.y);ye(e)&&(c*=2,l*=2),e.signX!==u&&"y"!==o&&(e.originX=xe(e.originX),c*=-1,e.signX=u),e.signY!==g&&"x"!==o&&(e.originY=xe(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set("scaleX",c),"y"===o&&n.set("scaleY",l)):(!Ce(n,"lockScalingX")&&n.set("scaleX",c),!Ce(n,"lockScalingY")&&n.set("scaleY",l)),f!==n.scaleX||p!==n.scaleY}const Pi=vi("scaling",_i(((t,e,i,s)=>Mi(t,e,i,s)))),Ai=vi("scaling",_i(((t,e,i,s)=>Mi(t,e,i,s,{by:"x"})))),Ei=vi("scaling",_i(((t,e,i,s)=>Mi(t,e,i,s,{by:"y"})))),ji=["target","ex","ey","skewingSide"],Fi={x:{counterAxis:"y",scale:"scaleX",skew:"skewX",lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:"scaleY",skew:"skewY",lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},Li=["ns","nesw","ew","nwse"],Ri=(t,e,i)=>{if(0!==e.x&&Ce(i,"lockSkewingY"))return _e;if(0!==e.y&&Ce(i,"lockSkewingX"))return _e;const s=Se(i,e)%4;return"".concat(Li[s],"-resize")};function Bi(t,e,s,n,o){const{target:a}=s,{counterAxis:h,origin:c,lockSkewing:l,skew:d,flip:u}=Fi[t];if(Ce(a,l))return!1;const{origin:g,flip:f}=Fi[h],p=ve(s[g])*(a[f]?-1:1),m=-Math.sign(p)*(a[u]?-1:1),v=.5*-((0===a[d]&&we(s,P,P,n,o)[t]>0||a[d]>0?1:-1)*m)+.5,_=vi("skewing",_i(((e,i,s,n)=>function(t,e,i){let{target:s,ex:n,ey:o,skewingSide:a}=e,h=r(e,ji);const{skew:c}=Fi[t],l=i.subtract(new N(n,o)).divide(new N(s.scaleX,s.scaleY))[t],d=s[c],u=h[c],g=Math.tan(rt(u)),f="y"===t?s._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:s._getTransformedDimensions({scaleX:1,scaleY:1}).y,p=2*l*a/Math.max(f,1)+g,m=nt(Math.atan(p));s.set(c,m);const v=d!==s[c];if(v&&"y"===t){const{skewX:t,scaleX:e}=s,i=s._getTransformedDimensions({skewY:d}),r=s._getTransformedDimensions(),n=0!==t?i.x/r.x:1;1!==n&&s.set("scaleX",n*e)}return v}(t,i,new N(s,n)))));return _(e,i(i({},s),{},{[c]:v,skewingSide:m}),n,o)}const Ii=(t,e,i,s)=>Bi("x",t,e,i,s),Xi=(t,e,i,s)=>Bi("y",t,e,i,s);function Yi(t,e){return t[e.canvas.altActionKey]}const Wi=(t,e,i)=>{const s=Yi(t,i);return 0===e.x?s?"skewX":"scaleY":0===e.y?s?"skewY":"scaleX":""},Vi=(t,e,i)=>Yi(t,i)?Ri(0,e,i):Di(t,e,i),Gi=(t,e,i,s)=>Yi(t,e.target)?Xi(t,e,i,s):Ai(t,e,i,s),zi=(t,e,i,s)=>Yi(t,e.target)?Ii(t,e,i,s):Ei(t,e,i,s),Hi=()=>({ml:new bi({x:-.5,y:0,cursorStyleHandler:Vi,actionHandler:Gi,getActionName:Wi}),mr:new bi({x:.5,y:0,cursorStyleHandler:Vi,actionHandler:Gi,getActionName:Wi}),mb:new bi({x:0,y:.5,cursorStyleHandler:Vi,actionHandler:zi,getActionName:Wi}),mt:new bi({x:0,y:-.5,cursorStyleHandler:Vi,actionHandler:zi,getActionName:Wi}),tl:new bi({x:-.5,y:-.5,cursorStyleHandler:Di,actionHandler:Pi}),tr:new bi({x:.5,y:-.5,cursorStyleHandler:Di,actionHandler:Pi}),bl:new bi({x:-.5,y:.5,cursorStyleHandler:Di,actionHandler:Pi}),br:new bi({x:.5,y:.5,cursorStyleHandler:Di,actionHandler:Pi}),mtr:new bi({x:0,y:-.5,actionHandler:wi,cursorStyleHandler:Si,offsetY:-40,withConnection:!0,actionName:"rotate"})}),Ui=()=>({mr:new bi({x:.5,y:0,actionHandler:yi,cursorStyleHandler:Vi,actionName:"resizing"}),ml:new bi({x:-.5,y:0,actionHandler:yi,cursorStyleHandler:Vi,actionName:"resizing"})}),Ni=()=>i(i({},Hi()),Ui());class qi extends mi{static getDefaults(){return i(i({},super.getDefaults()),{},{controls:Hi()},qi.ownDefaults)}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform.target,i=t._currentTransform.action;if(this===e&&i.startsWith("scale"))return!1}return super._updateCacheCanvas()}getActiveControl(){return this.__corner}_findTargetCorner(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasControls||!this.canvas)return"";this.__corner=void 0;const i=Object.entries(this.oCoords);for(let s=i.length-1;s>=0;s--){const[r,n]=i[s];if(this.controls[r].shouldActivate(r,this,t,e?n.touchCorner:n.corner))return this.__corner=r}return""}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),i=ut(e.x,e.y),s=gt({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),r=ct(i,s),n=ct(t,r),o=ct(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?dt(this.calcTransformMatrix()):void 0,h=this._calculateCurrentDimensions(a),c={};return this.forEachControl(((t,e)=>{const i=t.positionHandler(h,o,this,t);c[e]=Object.assign(i,this._calcCornerCoords(t,i))})),c}_calcCornerCoords(t,e){const i=this.getTotalAngle();return{corner:t.calcCornerCoords(i,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(i,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(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(),i=this._calculateCurrentDimensions(),s=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/s[0],1/s[3]),t.rotate(rt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-i.x/2,-i.y/2,i.x,i.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=i({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=r.borderColor,this._setLineDash(t,r.borderDashArray),this.strokeBorders(t,e),r.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{hasBorders:s,hasControls:r}=this,n=i({hasBorders:s,hasControls:r},e),o=this.getViewportTransform(),a=n.hasBorders,h=n.hasControls,c=ct(o,this.calcTransformMatrix()),l=dt(c);t.save(),t.translate(l.translateX,l.translateY),t.lineWidth=1*this.borderScaleFactor,this.group||(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),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,i){let s;if(i&&i.forActiveSelection||this.group){const t=de(this.width,this.height,e),i=(this.strokeUniform?(new N).scalarAdd(this.canvas?this.canvas.getZoom():1):new N(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);s=t.add(i).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else s=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,s,i)}drawControlsConnectingLines(t,e){let i=!1;t.beginPath(),this.forEachControl(((s,r)=>{s.withConnection&&s.getVisibility(this,r)&&(i=!0,t.moveTo(s.x*e.x,s.y*e.y),t.lineTo(s.x*e.x+s.offsetX,s.y*e.y+s.offsetY))})),i&&t.stroke()}drawControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:r,cornerDashArray:n,cornerColor:o}=this,a=i({cornerStrokeColor:r,cornerDashArray:n,cornerColor:o},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.setCoords(),this.forEachControl(((e,i)=>{if(e.getVisibility(this,i)){const s=this.oCoords[i];e.render(t,s.x,s.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,i]=t;return this.setControlVisible(e,i)}))}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const i=this.canvas.viewportTransform;e.save(),e.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this.transform(e);const s=this.width+4,r=this.height+4;return e.clearRect(-s/2,-r/2,s,r),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function Ki(t,e){return e.forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((i=>{"constructor"!==i&&Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(e.prototype,i)||Object.create(null))}))})),t}s(qi,"ownDefaults",{});class Ji extends qi{}Ki(Ji,[Oe]),X.setClass(Ji),X.setClass(Ji,"object");const Zi=(t,e,i,s)=>{const r=2*(s=Math.round(s))+1,{data:n}=t.getImageData(e-s,i-s,r,r);for(let t=3;t<n.length;t+=4){if(n[t]>0)return!1}return!0},Qi=["display","transform","fill","fill-opacity","fill-rule","opacity","stroke","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 $i(t){return new RegExp("^("+t.join("|")+")\\b","i")}var ts,es;const is=String.raw(ts||(ts=n(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),ss="http://www.w3.org/2000/svg";String.raw(es||(es=n(["(?:s+,?s*|,s*|$)"],["(?:\\s+,?\\s*|,\\s*|$)"])));const rs=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+is+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+is+"))?\\s+(.*)"),ns={cx:A,x:A,r:"radius",cy:E,y:E,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"},os="font-size",as="clip-path",hs=$i(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),cs=$i(["symbol","image","marker","pattern","view","svg"]),ls=$i(["symbol","g","a","svg","clipPath","defs"]),ds=new RegExp("^\\s*("+is+"+)\\s*,?\\s*("+is+"+)\\s*,?\\s*("+is+"+)\\s*,?\\s*("+is+"+)\\s*$");function us(t,e){const i=t.nodeName,s=t.getAttribute("class"),r=t.getAttribute("id");let n;if(n=new RegExp("^"+i,"i"),e=e.replace(n,""),r&&e.length&&(n=new RegExp("#"+r+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")),s&&e.length){const t=s.split(" ");for(let i=t.length;i--;)n=new RegExp("\\."+t[i]+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")}return 0===e.length}function gs(t,e){let i=!0;const s=us(t,e.pop());return s&&e.length&&(i=function(t,e){let i,s=!0;for(;t.parentElement&&1===t.parentElement.nodeType&&e.length;)s&&(i=e.pop()),s=us(t=t.parentElement,i);return 0===e.length}(t,e)),s&&i&&0===e.length}const fs=t=>{var e;return null!==(e=ns[t])&&void 0!==e?e:t},ps=t=>t.replace(new RegExp("(".concat(is,")"),"gi")," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var ms,vs,_s,ys,xs,Cs,bs;const Ss="(".concat(is,")"),ws=String.raw(ms||(ms=n(["(skewX)(",")"],["(skewX)\\(","\\)"])),Ss),Ts=String.raw(vs||(vs=n(["(skewY)(",")"],["(skewY)\\(","\\)"])),Ss),Os=String.raw(_s||(_s=n(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Ss,Ss,Ss),ks=String.raw(ys||(ys=n(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Ss,Ss),Ds=String.raw(xs||(xs=n(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Ss,Ss),Ms=String.raw(Cs||(Cs=n(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Ss,Ss,Ss,Ss,Ss,Ss),Ps="(?:".concat(Ms,"|").concat(Ds,"|").concat(Os,"|").concat(ks,"|").concat(ws,"|").concat(Ts,")"),As="(?:".concat(Ps,"*)"),Es=String.raw(bs||(bs=n(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),As),js=new RegExp(Es),Fs=new RegExp(Ps,"g");function Ls(t){const e=[];if(!(t=ps(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!js.test(t))return[...k];for(const i of t.matchAll(Fs)){const t=new RegExp(Ps).exec(i[0]);if(!t)continue;let s=k;const r=t.filter((t=>!!t)),[,n,...o]=r,[a,h,c,l,d,u]=o.map((t=>parseFloat(t)));switch(n){case"translate":s=ut(a,h);break;case"rotate":s=gt({angle:a},{x:h,y:c});break;case"scale":s=ft(a,h);break;case"skewX":s=mt(a);break;case"skewY":s=vt(a);break;case"matrix":s=[a,h,c,l,d,u]}e.push(s)}return lt(e)}function Rs(t,e,i,s){const r=Array.isArray(e);let n,o=e;if("fill"!==t&&"stroke"!==t||e!==L){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)o=e===L?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)o=i&&i.transformMatrix?ct(i.transformMatrix,Ls(e)):Ls(e);else if("visible"===t)o=e!==L&&"hidden"!==e,i&&!1===i.visible&&(o=!1);else if("opacity"===t)o=parseFloat(e),i&&void 0!==i.opacity&&(o*=i.opacity);else if("textAnchor"===t)o="start"===e?A:"end"===e?F:P;else if("charSpacing"===t)n=jt(e,s)/s*1e3;else if("paintFirst"===t){const t=e.indexOf("fill"),i=e.indexOf("stroke");o="fill",(t>-1&&i>-1&&i<t||-1===t&&i>-1)&&(o="stroke")}else{if("href"===t||"xlink:href"===t||"font"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=r?e.map(jt):jt(e,s)}}else o="";return!r&&isNaN(n)?o:n}function Bs(t,e){const i=t.match(rs);if(!i)return;const s=i[1],r=i[3],n=i[4],o=i[5],a=i[6];s&&(e.fontStyle=s),r&&(e.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),n&&(e.fontSize=jt(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}function Is(t){const e={},i=t.getAttribute("style");return i?("string"==typeof i?function(t,e){t.replace(/;\s*$/,"").split(";").forEach((t=>{const[i,s]=t.split(":");e[i.trim().toLowerCase()]=s.trim()}))}(i,e):function(t,e){Object.entries(t).forEach((t=>{let[i,s]=t;void 0!==s&&(e[i.toLowerCase()]=s)}))}(i,e),e):e}const Xs={stroke:"strokeOpacity",fill:"fillOpacity"};function Ys(t,e,s){if(!t)return{};let r,n={},o=D;t.parentNode&&ls.test(t.parentNode.nodeName)&&(n=Ys(t.parentElement,e,s),n.fontSize&&(r=o=jt(n.fontSize)));const a=i(i(i({},e.reduce(((e,i)=>{const s=t.getAttribute(i);return s&&(e[i]=s),e}),{})),function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s={};for(const r in e)gs(t,r.split(" "))&&(s=i(i({},s),e[r]));return s}(t,s)),Is(t));a[as]&&t.setAttribute(as,a[as]),a[os]&&(r=jt(a[os],o),a[os]="".concat(r));const h={};for(const t in a){const e=fs(t),i=Rs(e,a[t],n,r);h[e]=i}h&&h.font&&Bs(h.font,h);const c=i(i({},n),h);return ls.test(t.nodeName)?c:function(t){const e=Ji.getDefaults();return Object.entries(Xs).forEach((i=>{let[s,r]=i;if(void 0===t[r]||""===t[s])return;if(void 0===t[s]){if(!e[s])return;t[s]=e[s]}if(0===t[s].indexOf("url("))return;const n=new At(t[s]);t[s]=n.setAlpha(Et(n.getAlpha()*t[r],2)).toRgba()})),t}(c)}const Ws=["left","top","width","height","visible"],Vs=["rx","ry"];class Gs extends Ji{static getDefaults(){return i(i({},super.getDefaults()),Gs.ownDefaults)}constructor(t){super(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:i}=this,s=-e/2,r=-i/2,n=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,i/2):0,a=0!==n||0!==o;t.beginPath(),t.moveTo(s+n,r),t.lineTo(s+e-n,r),a&&t.bezierCurveTo(s+e-M*n,r,s+e,r+M*o,s+e,r+o),t.lineTo(s+e,r+i-o),a&&t.bezierCurveTo(s+e,r+i-M*o,s+e-M*n,r+i,s+e-n,r+i),t.lineTo(s+n,r+i),a&&t.bezierCurveTo(s+M*n,r+i,s,r+i-M*o,s,r+i-o),t.lineTo(s,r+o),a&&t.bezierCurveTo(s,r+M*o,s+M*n,r,s+n,r),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Vs,...t])}_toSVG(){const{width:t,height:e,rx:i,ry:s}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(i,'" ry="').concat(s,'" width="').concat(t,'" height="').concat(e,'" />\n')]}static async fromElement(t,e,s){const n=Ys(t,this.ATTRIBUTE_NAMES,s),{left:o=0,top:a=0,width:h=0,height:c=0,visible:l=!0}=n,d=r(n,Ws);return new this(i(i(i({},e),d),{},{left:o,top:a,width:h,height:c,visible:Boolean(l&&h&&c)}))}}s(Gs,"type","Rect"),s(Gs,"cacheProperties",[...gi,...Vs]),s(Gs,"ownDefaults",{rx:0,ry:0}),s(Gs,"ATTRIBUTE_NAMES",[...Qi,"x","y","rx","ry","width","height"]),X.setClass(Gs),X.setSVGClass(Gs);const zs=["objects"];class Hs extends(K(Ji)){static getDefaults(){return i(i({},super.getDefaults()),Hs.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;super(),s(this,"_activeObjects",[]),s(this,"__objectSelectionTracker",void 0),s(this,"__objectSelectionDisposer",void 0),s(this,"_firstLayoutDone",!1),this._objects=t.slice(),this.__objectMonitor=this.__objectMonitor.bind(this),this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.set(i(i({},e),{},{angle:0,skewX:0,skewY:0})),this.forEachObject((t=>{this.enterGroup(t,!1)})),this._applyLayoutStrategy({type:"initialization",options:e,objectsRelativeToGroup:r})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(c("error","Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(c("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter(((t,e,i)=>this.canEnterGroup(t)&&i.indexOf(t)===e))}add(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];const s=this._filterObjectsBeforeEnteringGroup(e),r=super.add(...s);return this._onAfterObjectsChange("added",s),r}insertAt(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];const r=this._filterObjectsBeforeEnteringGroup(i),n=super.insertAt(t,...r);return this._onAfterObjectsChange("added",r),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange("removed",t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onRelativeObjectAdded(t){this.enterGroup(t,!1),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this._applyLayoutStrategy({type:t,targets:e}),this._set("dirty",!0)}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const i=this[t];return super._set(t,e),"canvas"===t&&i!==e&&this.forEachObject((i=>{i._set(t,e)})),"layout"===t&&i!==e&&this._applyLayoutStrategy({type:"layout_change",layout:e,prevLayout:i}),"interactive"===t&&this.forEachObject((t=>this._watchObject(e,t))),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectMonitor(t){this._applyLayoutStrategy(i(i({},t),{},{type:"object_modified"})),this._set("dirty",!0)}__objectSelectionMonitor(t,e){let{target:i}=e;if(t)this._activeObjects.push(i),this._set("dirty",!0);else if(this._activeObjects.length>0){const t=this._activeObjects.indexOf(i);t>-1&&(this._activeObjects.splice(t,1),this._set("dirty",!0))}}_watchObject(t,e){const i=t?"on":"off";t&&this._watchObject(!1,e),e[i]("changed",this.__objectMonitor),e[i]("modified",this.__objectMonitor),e[i]("selected",this.__objectSelectionTracker),e[i]("deselected",this.__objectSelectionDisposer)}enterGroup(t,e){return t.group&&t.group.remove(t),this._enterGroup(t,e),!0}_enterGroup(t,e){e&&he(t,ct(ht(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this.interactive&&this._watchObject(!0,t);const i=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();i&&(i===t||t.isDescendantOf(i))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(he(t,ct(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const i=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;i>-1&&this._activeObjects.splice(i,1)}shouldCache(){const t=Ji.prototype.shouldCache.call(this);if(t)for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return this.ownCaching=!1,!1;return t}willDrawShadow(){if(Ji.prototype.willDrawShadow.call(this))return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.group&&this.group.isOnACache()}drawObject(t){this._renderBackground(t);for(let i=0;i<this._objects.length;i++){var e;null!==(e=this.canvas)&&void 0!==e&&e.preserveObjectStacking&&this._objects[i].group!==this?(t.save(),t.transform(...ht(this.calcTransformMatrix())),this._objects[i].render(t),t.restore()):this._objects[i].group===this&&this._objects[i].render(t)}this._drawClipPath(t,this.clipPath)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}triggerLayout(t){t&&t.layout&&(t.prevLayout=this.layout,this.layout=t.layout),this._applyLayoutStrategy({type:"imperative",context:t})}_adjustObjectPosition(t,e){t.set({left:t.left+e.x,top:t.top+e.y})}_applyLayoutStrategy(t){const e="initialization"===t.type;if(!e&&!this._firstLayoutDone)return;const i=e&&t.options,s=i&&{angle:i.angle||0,skewX:i.skewX||0,skewY:i.skewY||0},r=this.getRelativeCenterPoint();let n,o=this.getLayoutStrategyResult(this.layout,[...this._objects],t);if(o){const i=new N(o.centerX,o.centerY),a=r.subtract(i).add(new N(o.correctionX||0,o.correctionY||0));n=a.transform(ht(this.calcOwnMatrix()),!0),this.set({width:o.width,height:o.height}),!t.objectsRelativeToGroup&&this.forEachObject((t=>{t.group===this&&this._adjustObjectPosition(t,n)})),!e&&"clip-path"!==this.layout&&this.clipPath&&!this.clipPath.absolutePositioned&&this._adjustObjectPosition(this.clipPath,n),i.eq(r)&&!s||(this.setPositionByOrigin(i,P,P),s&&this.set(s),this.setCoords())}else{if(!e)return;o={centerX:r.x,centerY:r.y,width:this.width,height:this.height},s&&this.set(s),n=new N}this._firstLayoutDone=!0,this.onLayout(t,o),this.fire("layout",{context:t,result:o,diff:n}),this.group&&this.group._applyLayoutStrategy&&(t.path||(t.path=[]),t.path.push(this),this.group._applyLayoutStrategy(t))}getLayoutStrategyResult(t,e,i){if("fit-content-lazy"===t&&"added"===i.type&&e.length>i.targets.length){const e=i.targets.concat(this);return this.prepareBoundingBox(t,e,i)}if("fit-content"===t||"fit-content-lazy"===t||"fixed"===t&&("initialization"===i.type||"imperative"===i.type))return this.prepareBoundingBox(t,e,i);if("clip-path"===t&&this.clipPath){const s=this.clipPath,r=s._getTransformedDimensions();if(s.absolutePositioned&&("initialization"===i.type||"layout_change"===i.type)){let t=s.getCenterPoint();if(this.group){const e=ht(this.group.calcTransformMatrix());t=at(t,e)}return{centerX:t.x,centerY:t.y,width:r.x,height:r.y}}if(!s.absolutePositioned){let n;const o=s.getRelativeCenterPoint(),a=at(o,this.calcOwnMatrix(),!0);if("initialization"===i.type||"layout_change"===i.type){const r=this.prepareBoundingBox(t,e,i)||{};return n=new N(r.centerX||0,r.centerY||0),{centerX:n.x+a.x,centerY:n.y+a.y,correctionX:r.correctionX-a.x,correctionY:r.correctionY-a.y,width:s.width,height:s.height}}return n=this.getRelativeCenterPoint(),{centerX:n.x+a.x,centerY:n.y+a.y,width:r.x,height:r.y}}}}prepareBoundingBox(t,e,s){return"initialization"===s.type?this.prepareInitialBoundingBox(t,e,s):"imperative"===s.type&&s.context?i(i({},this.getObjectsBoundingBox(e)||{}),s.context):this.getObjectsBoundingBox(e)}prepareInitialBoundingBox(t,e,i){const s=i.options||{},r="number"==typeof s.left,n="number"==typeof s.top,o="number"==typeof s.width,a="number"==typeof s.height;if(r&&n&&o&&a&&i.objectsRelativeToGroup||0===e.length)return;const h=this.getObjectsBoundingBox(e)||{},{centerX:c=0,centerY:l=0,width:d=0,height:u=0}=h,g=o?this.width:d,f=a?this.height:u,p=new N(c,l),m=new N(ve(this.originX),ve(this.originY)),v=new N(g,f),_=this._getTransformedDimensions({width:0,height:0}),y=this._getTransformedDimensions({width:g,height:f,strokeWidth:0}),x=this._getTransformedDimensions({width:h.width,height:h.height,strokeWidth:0}),C=new N(0,0),b=m.scalarAdd(.5),S=y.multiply(b),w=new N(o?x.x/2:S.x,a?x.y/2:S.y),T=new N(r?this.left-(y.x+_.x)*m.x:p.x-w.x,n?this.top-(y.y+_.y)*m.y:p.y-w.y),O=new N(r?T.x-p.x+x.x*(o?.5:0):-(o?.5*(y.x-_.x):y.x*b.x),n?T.y-p.y+x.y*(a?.5:0):-(a?.5*(y.y-_.y):y.y*b.y)).add(C),k=new N(o?-y.x/2:0,a?-y.y/2:0).add(O);return{centerX:T.x,centerY:T.y,correctionX:k.x,correctionY:k.y,width:v.x,height:v.y}}getObjectsBoundingBox(t,e){if(0===t.length)return null;const i=[];t.forEach((t=>{const e=t.getRelativeCenterPoint();let s=t._getTransformedDimensions().scalarDivide(2);if(t.angle){const e=rt(t.angle),i=Math.abs(U(e)),r=Math.abs(H(e)),n=s.x*r+s.y*i,o=s.x*i+s.y*r;s=new N(n,o)}i.push(e.subtract(s),e.add(s))}));const{left:s,top:r,width:n,height:o}=ne(i),a=new N(n,o),h=(e?new N:new N(s,r)).add(a.scalarDivide(2)).transform(this.calcOwnMatrix());return{centerX:h.x,centerY:h.y,width:a.x,height:a.y}}onLayout(t,e){}__serializeObjects(t,e){const i=this.includeDefaultValues;return this._objects.filter((function(t){return!t.excludeFromExport})).map((function(s){const r=s.includeDefaultValues;s.includeDefaultValues=i;const n=s[t||"toObject"](e);return s.includeDefaultValues=r,n}))}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(["layout","subTargetCheck","interactive",...t])),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this._activeObjects=[],this.forEachObject((t=>{this._watchObject(!1,t),t.dispose()})),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=Gs.prototype._toSVG.call(this),i=e.indexOf("COMMON_PARTS");e[i]='for="group" ';const s=e.join("");return t?t(s):s}_toSVG(t){const e=["<g ","COMMON_PARTS"," >\n"],i=this._createSVGBgRect(t);i&&e.push("\t\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t\t",this._objects[i].toSVG(t));return e.push("</g>\n"),e}getSvgStyles(){const t=void 0!==this.opacity&&1!==this.opacity?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],i=this._createSVGBgRect(t);i&&e.push("\t",i);for(let i=0;i<this._objects.length;i++)e.push("\t",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t){let{objects:e=[]}=t,s=r(t,zs);return Promise.all([Ct(e),bt(s)]).then((t=>{let[e,r]=t;return new this(e,i(i({},s),r),!0)}))}}s(Hs,"stateProperties",[...Ji.stateProperties,"layout"]),s(Hs,"type","Group"),s(Hs,"ownDefaults",{layout:"fit-content",strokeWidth:0,subTargetCheck:!1,interactive:!1}),X.setClass(Hs);class Us extends Hs{constructor(){super(...arguments),s(this,"multiSelectionStacking","canvas-stacking")}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];"selection-order"===this.multiSelectionStacking?this.add(...e):e.forEach((t=>{const e=this._objects.findIndex((e=>e.isInFrontOf(t))),i=-1===e?this.size():e;this.insertAt(i,t)}))}enterGroup(t,e){if(t.group){const e=t.group;e._exitGroup(t),!(e instanceof Us)&&(t.__owningGroup=e)}return this._enterGroup(t,e),!0}exitGroup(t,e){this._exitGroup(t,e);const i=t.__owningGroup;i&&(i._enterGroup(t,!0),delete t.__owningGroup)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const i=[];e.forEach((t=>{t.group&&!i.includes(t.group)&&i.push(t.group)})),"removed"===t?i.forEach((t=>{t._onAfterObjectsChange("added",e)})):i.forEach((t=>{t._set("dirty",!0)}))}onDeselect(){return this.removeAll(),!1}_applyLayoutStrategy(t){super._applyLayoutStrategy(t),0===this._objects.length&&Object.assign(this,{left:0,top:0,angle:0,scaleX:1,scaleY:1,skewX:0,skewY:0,flipX:!1,flipY:!1})}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,super._renderControls(t,e);const r=i(i({hasControls:!1},s),{},{forActiveSelection:!0});for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,r);t.restore()}}s(Us,"type","ActiveSelection"),X.setClass(Us),X.setClass(Us,"activeSelection");class Ns{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new N(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new N(1/this.options.scaleX,1/this.options.scaleY):new N(1,1)}createSideVector(t,e){const i=Je(t,e);return this.options.strokeUniform?i.multiply(this.scale):i}projectOrthogonally(t,e,i){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,i)))}isSkewed(){return 0!==this.options.skewX||0!==this.options.skewY}applySkew(t){const e=new N(t);return e.y+=e.x*Math.tan(rt(this.options.skewY)),e.x+=e.y*Math.tan(rt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const qs=new N;class Ks extends Ns{static getOrthogonalRotationFactor(t,e){const i=e?Qe(t,e):$e(t);return Math.abs(i)<w?-1:1}constructor(t,e,i,r){super(r),s(this,"AB",void 0),s(this,"AC",void 0),s(this,"alpha",void 0),s(this,"bisector",void 0),this.A=new N(t),this.B=new N(e),this.C=new N(i),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Qe(this.AB,this.AC),this.bisector=ti(Ke(this.AB.eq(qs)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const s=this.createSideVector(t,e),r=ei(s),n=Ks.getOrthogonalRotationFactor(r,this.bisector);return this.scaleUnitVector(r,i*n)}projectBevel(){const t=[];return(this.alpha%T==0?[this.B]:[this.B,this.C]).forEach((e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))})),t}projectMiter(){const t=[],e=Math.abs(this.alpha),i=1/Math.sin(e/2),s=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*i),r=this.options.strokeUniform?Ze(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Ze(s)/this.strokeProjectionMagnitude<=r&&t.push(this.applySkew(this.A.add(s))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const i=[],s=new N(Ks.getOrthogonalRotationFactor(this.bisector),Ks.getOrthogonalRotationFactor(new N(this.bisector.y,this.bisector.x)));return[new N(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s),new N(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s)].forEach((s=>{ri(s,t,e)&&i.push(this.A.add(s))})),i}projectRoundWithSkew(t,e){const i=[],{skewX:s,skewY:r,scaleX:n,scaleY:o,strokeUniform:a}=this.options,h=new N(Math.tan(rt(s)),Math.tan(rt(r))),c=this.strokeProjectionMagnitude,l=a?c/o/Math.sqrt(1/o**2+1/n**2*h.y**2):c/Math.sqrt(1+h.y**2),d=new N(Math.sqrt(Math.max(c**2-l**2,0)),l),u=a?c/Math.sqrt(1+h.x**2*(1/o)**2/(1/n+1/n*h.x*h.y)**2):c/Math.sqrt(1+h.x**2/(1+h.x*h.y)**2),g=new N(u,Math.sqrt(Math.max(c**2-u**2,0)));return[g,g.scalarMultiply(-1),d,d.scalarMultiply(-1)].map((t=>this.applySkew(a?t.multiply(this.strokeUniformScalar):t))).forEach((s=>{ri(s,t,e)&&i.push(this.applySkew(this.A).add(s))})),i}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%T==0,i=this.applySkew(this.A),s=t[e?0:2].subtract(i),r=t[e?1:0].subtract(i),n=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=ii(s,n)>0,a=o?s:r,h=o?r:s;return this.isSkewed()?t.push(...this.projectRoundWithSkew(a,h)):t.push(...this.projectRoundNoSkew(a,h)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector})))}}class Js extends Ns{constructor(t,e,i){super(i),this.A=new N(t),this.T=new N(e)}calcOrthogonalProjection(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.strokeProjectionMagnitude;const s=this.createSideVector(t,e);return this.scaleUnitVector(ei(s),i)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new N(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new Ks(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new N(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),i=this.scaleUnitVector(ti(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),s=this.A.add(i);t.push(s.add(e),s.subtract(e))}return t.map((t=>this.applySkew(t)))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map((t=>({originPoint:this.A,projectedPoint:t})))}}const Zs=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const s=[];if(0===t.length)return s;const r=t.reduce(((t,e)=>(t[t.length-1].eq(e)||t.push(new N(e)),t)),[new N(t[0])]);if(1===r.length)i=!0;else if(!i){const t=r[0],e=((t,e)=>{for(let i=t.length-1;i>=0;i--)if(e(t[i],i,t))return i;return-1})(r,(e=>!e.eq(t)));r.splice(e+1)}return r.forEach(((t,r,n)=>{let o,a;0===r?(a=n[1],o=i?t:n[n.length-1]):r===n.length-1?(o=n[r-1],a=i?t:n[0]):(o=n[r-1],a=n[r+1]),i&&1===n.length?s.push(...new Js(t,t,e).project()):!i||0!==r&&r!==n.length-1?s.push(...new Ks(t,o,a,e).project()):s.push(...new Js(t,0===r?a:o,e).project())})),s},Qs=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||i&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},$s=(t,e)=>{const i=e.split("\n"),s=[];let r=-1,n={};t=di(t);for(let e=0;e<i.length;e++)if(t[e])for(let o=0;o<i[e].length;o++){r++;const i=t[e][o];i&&Object.keys(i).length>0&&(Qs(n,i,!0)?s.push({start:r,end:r+1,style:i}):s[s.length-1].end++),n=i||{}}else r+=i[e].length,n={};return s},tr=(t,e)=>{if(!Array.isArray(t))return di(t);const s=e.split(R),r={};let n=-1,o=0;for(let e=0;e<s.length;e++)for(let a=0;a<s[e].length;a++)n++,t[o]&&t[o].start<=n&&n<t[o].end&&(r[e]=r[e]||{},r[e][a]=i({},t[o].style),n===t[o].end-1&&o++);return r},er=(t,e)=>Math.min(e.width/t.width,e.height/t.height),ir=(t,e)=>Math.max(e.width/t.width,e.height/t.height),sr=t=>t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),rr=t=>{const e=[];for(let i,s=0;s<t.length;s++)!1!==(i=nr(t,s))&&e.push(i);return e},nr=(t,e)=>{const i=t.charCodeAt(e);if(isNaN(i))return"";if(i<55296||i>57343)return t.charAt(e);if(55296<=i&&i<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";const i=t.charCodeAt(e+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return t.charAt(e)+t.charAt(e+1)}if(0===e)throw"Low surrogate without preceding high surrogate";const s=t.charCodeAt(e-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var or,ar=Object.freeze({__proto__:null,capitalize:function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"".concat(t.charAt(0).toUpperCase()).concat(e?t.slice(1):t.slice(1).toLowerCase())},escapeXml:sr,graphemeSplit:rr});const hr="(".concat(is,")"),cr="(M) (?:".concat(hr," ").concat(hr," ?)+"),lr="(L) (?:".concat(hr," ").concat(hr," ?)+"),dr="(H) (?:".concat(hr," ?)+"),ur="(V) (?:".concat(hr," ?)+"),gr=String.raw(or||(or=n(["(Z)s*"],["(Z)\\s*"]))),fr="(C) (?:".concat(hr," ").concat(hr," ").concat(hr," ").concat(hr," ").concat(hr," ").concat(hr," ?)+"),pr="(S) (?:".concat(hr," ").concat(hr," ").concat(hr," ").concat(hr," ?)+"),mr="(Q) (?:".concat(hr," ").concat(hr," ").concat(hr," ").concat(hr," ?)+"),vr="(T) (?:".concat(hr," ").concat(hr," ?)+"),_r="(A) (?:".concat(hr," ").concat(hr," ").concat(hr," ([01]) ?([01]) ").concat(hr," ").concat(hr," ?)+"),yr="(?:(?:".concat(cr,")")+"|(?:".concat(lr,")")+"|(?:".concat(dr,")")+"|(?:".concat(ur,")")+"|(?:".concat(gr,")")+"|(?:".concat(fr,")")+"|(?:".concat(pr,")")+"|(?:".concat(mr,")")+"|(?:".concat(vr,")")+"|(?:".concat(_r,"))"),xr={m:"l",M:"L"},Cr=(t,e,i,s,r,n,o,a,h,c,l)=>{const d=H(t),u=U(t),g=H(e),f=U(e),p=i*r*g-s*n*f+o,m=s*r*g+i*n*f+a;return["C",c+h*(-i*r*u-s*n*d),l+h*(-s*r*u+i*n*d),p+h*(i*r*f+s*n*g),m+h*(s*r*f-i*n*g),p,m]},br=(t,e,i,s)=>{const r=Math.atan2(e,t),n=Math.atan2(s,i);return n>=r?n-r:2*Math.PI-(r-n)};function Sr(t,e,i,s,r,n,o,a){let c;if(h.cachesBoundsOfCurve&&(c=[...arguments].join(),C.boundsOfCurveCache[c]))return C.boundsOfCurveCache[c];const l=Math.sqrt,d=Math.abs,u=[],g=[[0,0],[0,0]];let f=6*t-12*i+6*r,p=-3*t+9*i-9*r+3*o,m=3*i-3*t;for(let t=0;t<2;++t){if(t>0&&(f=6*e-12*s+6*n,p=-3*e+9*s-9*n+3*a,m=3*s-3*e),d(p)<1e-12){if(d(f)<1e-12)continue;const t=-m/f;0<t&&t<1&&u.push(t);continue}const i=f*f-4*m*p;if(i<0)continue;const r=l(i),o=(-f+r)/(2*p);0<o&&o<1&&u.push(o);const h=(-f-r)/(2*p);0<h&&h<1&&u.push(h)}let v=u.length;const _=v,y=kr(t,e,i,s,r,n,o,a);for(;v--;){const{x:t,y:e}=y(u[v]);g[0][v]=t,g[1][v]=e}g[0][_]=t,g[1][_]=e,g[0][_+1]=o,g[1][_+1]=a;const x=[new N(Math.min(...g[0]),Math.min(...g[1])),new N(Math.max(...g[0]),Math.max(...g[1]))];return h.cachesBoundsOfCurve&&(C.boundsOfCurveCache[c]=x),x}const wr=(t,e,i)=>{let[s,r,n,o,a,h,c,l]=i;const d=((t,e,i,s,r,n,o)=>{if(0===i||0===s)return[];let a=0,h=0,c=0;const l=Math.PI,d=o*O,u=U(d),g=H(d),f=.5*(-g*t-u*e),p=.5*(-g*e+u*t),m=i**2,v=s**2,_=p**2,y=f**2,x=m*v-m*_-v*y;let C=Math.abs(i),b=Math.abs(s);if(x<0){const t=Math.sqrt(1-x/(m*v));C*=t,b*=t}else c=(r===n?-1:1)*Math.sqrt(x/(m*_+v*y));const S=c*C*p/b,w=-c*b*f/C,T=g*S-u*w+.5*t,k=u*S+g*w+.5*e;let D=br(1,0,(f-S)/C,(p-w)/b),M=br((f-S)/C,(p-w)/b,(-f-S)/C,(-p-w)/b);0===n&&M>0?M-=2*l:1===n&&M<0&&(M+=2*l);const P=Math.ceil(Math.abs(M/l*2)),A=new Array(P),E=M/P,j=8/3*Math.sin(E/4)*Math.sin(E/4)/Math.sin(E/2);let F=D+E;for(let t=0;t<P;t++)A[t]=Cr(D,F,g,u,C,b,T,k,j,a,h),a=A[t][5],h=A[t][6],D=F,F+=E;return A})(c-t,l-e,r,n,a,h,o);for(let i=0,s=d.length;i<s;i++)d[i][1]+=t,d[i][2]+=e,d[i][3]+=t,d[i][4]+=e,d[i][5]+=t,d[i][6]+=e;return d},Tr=t=>{let e=0,i=0,s=0,r=0;const n=[];let o,a=0,h=0;for(const c of t){const t=[...c];let l;switch(t[0]){case"l":t[1]+=e,t[2]+=i;case"L":e=t[1],i=t[2],l=["L",e,i];break;case"h":t[1]+=e;case"H":e=t[1],l=["L",e,i];break;case"v":t[1]+=i;case"V":i=t[1],l=["L",e,i];break;case"m":t[1]+=e,t[2]+=i;case"M":e=t[1],i=t[2],s=t[1],r=t[2],l=["M",e,i];break;case"c":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i,t[5]+=e,t[6]+=i;case"C":a=t[3],h=t[4],e=t[5],i=t[6],l=["C",t[1],t[2],a,h,e,i];break;case"s":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"S":"C"===o?(a=2*e-a,h=2*i-h):(a=e,h=i),e=t[3],i=t[4],l=["C",a,h,t[1],t[2],e,i],a=l[3],h=l[4];break;case"q":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"Q":a=t[1],h=t[2],e=t[3],i=t[4],l=["Q",a,h,e,i];break;case"t":t[1]+=e,t[2]+=i;case"T":"Q"===o?(a=2*e-a,h=2*i-h):(a=e,h=i),e=t[1],i=t[2],l=["Q",a,h,e,i];break;case"a":t[6]+=e,t[7]+=i;case"A":wr(e,i,t).forEach((t=>n.push(t))),e=t[6],i=t[7];break;case"z":case"Z":e=s,i=r,l=["Z"]}l?(n.push(l),o=l[0]):o=""}return n},Or=(t,e,i,s)=>Math.sqrt((i-t)**2+(s-e)**2),kr=(t,e,i,s,r,n,o,a)=>h=>{const c=h**3,l=(t=>3*t**2*(1-t))(h),d=(t=>3*t*(1-t)**2)(h),u=(t=>(1-t)**3)(h);return new N(o*c+r*l+i*d+t*u,a*c+n*l+s*d+e*u)},Dr=t=>t**2,Mr=t=>2*t*(1-t),Pr=t=>(1-t)**2,Ar=(t,e,i,s,r,n,o,a)=>h=>{const c=Dr(h),l=Mr(h),d=Pr(h),u=3*(d*(i-t)+l*(r-i)+c*(o-r)),g=3*(d*(s-e)+l*(n-s)+c*(a-n));return Math.atan2(g,u)},Er=(t,e,i,s,r,n)=>o=>{const a=Dr(o),h=Mr(o),c=Pr(o);return new N(r*a+i*h+t*c,n*a+s*h+e*c)},jr=(t,e,i,s,r,n)=>o=>{const a=1-o,h=2*(a*(i-t)+o*(r-i)),c=2*(a*(s-e)+o*(n-s));return Math.atan2(c,h)},Fr=(t,e,i)=>{let s=new N(e,i),r=0;for(let e=1;e<=100;e+=1){const i=t(e/100);r+=Or(s.x,s.y,i.x,i.y),s=i}return r},Lr=(t,e)=>{let s,r=0,n=0,o={x:t.x,y:t.y},a=i({},o),h=.01,c=0;const l=t.iterator,d=t.angleFinder;for(;n<e&&h>1e-4;)a=l(r),c=r,s=Or(o.x,o.y,a.x,a.y),s+n>e?(r-=h,h/=2):(o=a,r+=h,n+=s);return i(i({},a),{},{angle:d(c)})},Rr=t=>{let e,i,s=0,r=0,n=0,o=0,a=0;const h=[];for(const c of t){const t={x:r,y:n,command:c[0],length:0};switch(c[0]){case"M":i=t,i.x=o=r=c[1],i.y=a=n=c[2];break;case"L":i=t,i.length=Or(r,n,c[1],c[2]),r=c[1],n=c[2];break;case"C":e=kr(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),i=t,i.iterator=e,i.angleFinder=Ar(r,n,c[1],c[2],c[3],c[4],c[5],c[6]),i.length=Fr(e,r,n),r=c[5],n=c[6];break;case"Q":e=Er(r,n,c[1],c[2],c[3],c[4]),i=t,i.iterator=e,i.angleFinder=jr(r,n,c[1],c[2],c[3],c[4]),i.length=Fr(e,r,n),r=c[3],n=c[4];break;case"Z":i=t,i.destX=o,i.destY=a,i.length=Or(r,n,o,a),r=o,n=a}s+=i.length,h.push(i)}return h.push({length:s,x:r,y:n}),h},Br=function(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Rr(t),r=0;for(;e-s[r].length>0&&r<s.length-2;)e-=s[r].length,r++;const n=s[r],o=e/n.length,a=t[r];switch(n.command){case"M":return{x:n.x,y:n.y,angle:0};case"Z":return i(i({},new N(n.x,n.y).lerp(new N(n.destX,n.destY),o)),{},{angle:Math.atan2(n.destY-n.y,n.destX-n.x)});case"L":return i(i({},new N(n.x,n.y).lerp(new N(a[1],a[2]),o)),{},{angle:Math.atan2(a[2]-n.y,a[1]-n.x)});case"C":case"Q":return Lr(n,e)}},Ir=t=>{t=ps(t);const e=[];for(const i of t.matchAll(new RegExp(yr,"gi"))){let t=i[0];const s=[];let r;do{if(r=new RegExp(yr,"i").exec(t),!r)break;const e=r.filter((t=>t));e.shift();const i=e.map((t=>{const e=Number.parseFloat(t);return Number.isNaN(e)?t:e}));if(s.push(i),e.length<=1)break;e.shift(),t=t.replace(new RegExp("".concat(e.join(" ?")," ?$")),"")}while(r);s.reverse().forEach(((t,i)=>{const s=xr[t[0]];i>0&&("l"==s||"L"==s)&&(t[0]=s),e.push(t)}))}return e},Xr=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=new N(t[0]),s=new N(t[1]),r=1,n=0;const o=[],a=t.length,h=a>2;let c;for(h&&(r=t[2].x<s.x?-1:t[2].x===s.x?0:1,n=t[2].y<s.y?-1:t[2].y===s.y?0:1),o.push(["M",i.x-r*e,i.y-n*e]),c=1;c<a;c++){if(!i.eq(s)){const t=i.midPointFrom(s);o.push(["Q",i.x,i.y,t.x,t.y])}i=t[c],c+1<t.length&&(s=t[c+1])}return h&&(r=i.x>t[c-2].x?1:i.x===t[c-2].x?0:-1,n=i.y>t[c-2].y?1:i.y===t[c-2].y?0:-1),o.push(["L",i.x+r*e,i.y+n*e]),o},Yr=(t,e)=>t.map((t=>t.map(((t,i)=>0===i||void 0===e?t:Et(t,e))).join(" "))).join(" ");function Wr(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.onComplete||S,s=new(x().XMLHttpRequest),r=e.signal,n=function(){s.abort()},o=function(){r&&r.removeEventListener("abort",n),s.onerror=s.ontimeout=S};if(r&&r.aborted)throw new d("request");return r&&r.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){4===s.readyState&&(o(),i(s),s.onreadystatechange=S)},s.onerror=s.ontimeout=o,s.open("get",t,!0),s.send(),s}const Vr=(t,e)=>{let i=t._findCenterFromElement();t.transformMatrix&&((t=>{if(t.transformMatrix){const{scaleX:e,scaleY:i,angle:s,skewX:r}=dt(t.transformMatrix);t.flipX=!1,t.flipY=!1,t.set("scaleX",e),t.set("scaleY",i),t.angle=s,t.skewX=r,t.skewY=0}})(t),i=i.transform(t.transformMatrix)),delete t.transformMatrix,e&&(t.scaleX*=e.scaleX,t.scaleY*=e.scaleY,t.cropX=e.cropX,t.cropY=e.cropY,i.x+=e.offsetLeft,i.y+=e.offsetTop,t.width=e.width,t.height=e.height),t.setPositionByOrigin(i,P,P)};var Gr=Object.freeze({__proto__:null,addTransformToObject:ae,animate:He,animateColor:Ue,applyTransformToObject:he,calcAngleBetweenVectors:Qe,calcDimensionsMatrix:_t,calcPlaneChangeMatrix:ue,calcVectorRotation:$e,cancelAnimFrame:Q,capValue:Xe,composeMatrix:yt,copyCanvasElement:t=>{var e;const i=et();return i.width=t.width,i.height=t.height,null===(e=i.getContext("2d"))||void 0===e||e.drawImage(t,0,0),i},cos:H,createCanvasElement:et,createImage:it,createRotateMatrix:gt,createScaleMatrix:ft,createSkewXMatrix:mt,createSkewYMatrix:vt,createTranslateMatrix:ut,createVector:Je,crossProduct:ii,degreesToRadians:rt,dotProduct:si,ease:Ee,enlivenObjectEnlivables:bt,enlivenObjects:Ct,findScaleToCover:ir,findScaleToFit:er,getBoundsOfCurve:Sr,getOrthonormalVector:ei,getPathSegmentsInfo:Rr,getPointOnPath:Br,getPointer:ie,getRandomInt:V,getRegularPolygonPath:(t,e)=>{const i=2*Math.PI/t;let s=-w;t%2==0&&(s+=i/2);const r=new Array(t+1);for(let n=0;n<t;n++){const t=n*i+s,{x:o,y:a}=new N(H(t),U(t)).scalarMultiply(e);r[n]=[0===n?"M":"L",o,a]}return r[t]=["Z"],r},getSmoothPathFromPoints:Xr,getSvgAttributes:t=>{const e=["instantiated_by_use","style","id","class"];switch(t){case"linearGradient":return e.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return e.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return e.concat(["offset","stop-color","stop-opacity"])}return e},getUnitVector:ti,groupSVGElements:t=>t&&1===t.length?t[0]:new Hs(t),hasStyleChanged:Qs,invertTransform:ht,isBetweenVectors:ri,isIdentityMatrix:t=>t.every(((t,e)=>t===k[e])),isTouchEvent:se,isTransparent:Zi,joinPath:Yr,loadImage:xt,magnitude:Ze,makeBoundingBoxFromPoints:ne,makePathSimpler:Tr,matrixToSVG:Lt,mergeClipPaths:(t,e)=>{var i;let s=t,r=e;s.inverted&&!r.inverted&&(s=e,r=t),fe(r,null===(i=r.group)||void 0===i?void 0:i.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&r.inverted;return n&&(s.inverted=r.inverted=!1),new Hs([s],{clipPath:r,inverted:n})},multiplyTransformMatrices:ct,multiplyTransformMatrixArray:lt,parsePath:Ir,parsePreserveAspectRatioAttribute:Ft,parseUnit:jt,pick:St,projectStrokeOnPoints:Zs,qrDecompose:dt,radiansToDegrees:nt,removeFromArray:z,removeTransformFromObject:(t,e)=>{const i=ht(e),s=ct(i,t.calcOwnMatrix());he(t,s)},removeTransformMatrixForSvgParsing:Vr,request:Wr,requestAnimFrame:Z,resetObjectTransform:ce,rotatePoint:(t,e,i)=>t.rotate(i,e),rotateVector:Ke,saveObjectTransform:le,sendObjectToPlane:fe,sendPointToPlane:ge,setStyle:qt,sin:U,sizeAfterTransform:de,string:ar,stylesFromArray:tr,stylesToArray:$s,toDataURL:st,toFixed:Et,transformPath:(t,e,i)=>(i&&(e=ct(e,[1,0,0,1,-i.x,-i.y])),t.map((t=>{const i=[...t];for(let s=1;s<t.length-1;s+=2){const{x:r,y:n}=at({x:t[s],y:t[s+1]},e);i[s]=r,i[s+1]=n}return i}))),transformPoint:at,transformPointRelativeToCanvas:(t,e,i,s)=>{if("child"!==i&&"sibling"!==i)throw new l("received bad argument ".concat(i));if("child"!==s&&"sibling"!==s)throw new l("received bad argument ".concat(s));if(i===s)return t;const r=e.viewportTransform;return t.transform("child"===s?ht(r):r)}});class zr extends Qt{constructor(t){let{allowTouchScrolling:e=!1,containerClass:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t),s(this,"upper",void 0),s(this,"container",void 0);const{el:r}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(r,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e});const o=this.createContainerElement();o.classList.add(i),r.parentNode&&r.parentNode.replaceChild(o,r),o.append(r,n),this.container=o}createUpperCanvas(){const{el:t}=this.lower,e=et();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=y().createElement("div");return t.setAttribute("data-fabric","wrapper"),qt(t,{position:"relative"}),Zt(t),t}applyCanvasStyle(t,e){let{allowTouchScrolling:i}=e;qt(t,{position:"absolute",left:"0",top:"0"}),function(t,e){const i=e?"manipulation":L;qt(t,{"touch-action":i,"-ms-touch-action":i})}(t,i),Zt(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:i,ctx:s}=this.upper;Kt(i,s,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Jt(this.upper.el,t),Jt(this.container,t)}cleanupDOM(t){const e=this.container,{el:i}=this.lower,{el:s}=this.upper;super.cleanupDOM(t),e.removeChild(s),e.removeChild(i),e.parentNode&&e.parentNode.replaceChild(i,e)}dispose(){super.dispose(),_().dispose(this.upper.el),delete this.upper,delete this.container}}const Hr=["activeSelection"];class Ur extends te{static getDefaults(){return i(i({},super.getDefaults()),Ur.ownDefaults)}get upperCanvasEl(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.el}get contextTop(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.ctx}get wrapperEl(){return this.elements.container}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{activeSelection:i=new Us}=e;super(t,r(e,Hr)),s(this,"targets",[]),s(this,"_hoveredTargets",[]),s(this,"_objectsToRender",void 0),s(this,"_currentTransform",null),s(this,"_groupSelector",null),s(this,"contextTopDirty",!1),s(this,"_activeSelection",void 0),this._activeSelection=i,this._activeSelection.set("canvas",this),this._activeSelection.setCoords()}initElements(t){this.elements=new zr(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),i=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=i,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,i){const s=this.targetFindTolerance,r=this.pixelFindContext;this.clearContext(r),r.save(),r.translate(-e+s,-i+s),r.transform(...this.viewportTransform);const n=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(r),t.selectionBackgroundColor=n,r.restore();const o=Math.round(s*this.getRetinaScaling());return Zi(r,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((e=>!!e&&!0===t[e])):t[e])}_shouldClearSelection(t,e){const i=this.getActiveObjects(),s=this._activeObject;return!!(!e||e&&s&&i.length>1&&-1===i.indexOf(e)&&s!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&s&&s!==e)}_shouldCenterTransform(t,e,i){if(!t)return;let s;return"scale"===e||"scaleX"===e||"scaleY"===e||"resizing"===e?s=this.centeredScaling||t.centeredScaling:"rotate"===e&&(s=this.centeredRotation||t.centeredRotation),s?!i:i}_getOriginFromCorner(t,e){const i={x:t.originX,y:t.originY};return["ml","tl","bl"].includes(e)?i.x=F:["mr","tr","br"].includes(e)&&(i.x=A),["tl","mt","tr"].includes(e)?i.y=j:["bl","mb","br"].includes(e)&&(i.y=E),i}_setupCurrentTransform(t,e,s){var r;if(!e)return;const n=e.group?ge(this.getPointer(t),void 0,e.group.calcTransformMatrix()):this.getPointer(t),o=e.getActiveControl()||"",a=!!o&&e.controls[o],h=s&&a?null===(r=a.getActionHandler(t,e,a))||void 0===r?void 0:r.bind(a):Te,c=((t,e,i,s)=>{if(!e||!t)return"drag";const r=s.controls[e];return r.getActionName(i,r,s)})(s,o,t,e),l=this._getOriginFromCorner(e,o),d=t[this.centeredKey],u={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:o,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:l.x,originY:l.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:rt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:d,original:i(i({},le(e)),{},{originX:l.x,originY:l.y})};this._shouldCenterTransform(e,c,d)&&(u.originX=P,u.originY=P),this._currentTransform=u,this._beforeTransform(t)}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new N(e,i).transform(this.viewportTransform),o=new N(e+s,i+r).transform(this.viewportTransform),a=this.selectionLineWidth/2;let h=Math.min(n.x,o.x),c=Math.min(n.y,o.y),l=Math.max(n.x,o.x),d=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(h,c,l-h,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,h+=a,c+=a,l-=a,d-=a,Ji.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(h,c,l-h,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getPointer(t,!0),i=this._activeObject,s=this.getActiveObjects();if(this.targets=[],i&&s.length>=1){if(i._findTargetCorner(e,se(t)))return i;if(s.length>1&&this.searchPossibleTargets([i],e))return i;if(i===this.searchPossibleTargets([i],e)){if(this.preserveObjectStacking){const s=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==i?(this.targets=s,i):r}return i}}return this.searchPossibleTargets(this._objects,e)}_checkTarget(t,e){if(t&&t.visible&&t.evented&&t.containsPoint(this.restorePointerVpt(e),!0)){if(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing)return!0;if(!this.isTargetTransparent(t,e.x,e.y))return!0}return!1}_searchPossibleTargets(t,e){let i=t.length;for(;i--;){const s=t[i];if(this._checkTarget(s,e)){if(Wt(s)&&s.subTargetCheck){const t=this._searchPossibleTargets(s._objects,e);t&&this.targets.push(t)}return s}}}searchPossibleTargets(t,e){const i=this._searchPossibleTargets(t,e);return i&&Wt(i)&&i.interactive&&this.targets[0]?this.targets[0]:i}restorePointerVpt(t){return t.transform(ht(this.viewportTransform))}getPointer(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this._absolutePointer&&!e)return this._absolutePointer;if(this._pointer&&e)return this._pointer;const i=this.upperCanvasEl,s=i.getBoundingClientRect();let r=ie(t),n=s.width||0,o=s.height||0;n&&o||(E in s&&j in s&&(o=Math.abs(s.top-s.bottom)),F in s&&A in s&&(n=Math.abs(s.right-s.left))),this.calcOffset(),r.x=r.x-this._offset.left,r.y=r.y-this._offset.top,e||(r=this.restorePointerVpt(r));const a=this.getRetinaScaling();1!==a&&(r.x/=a,r.y/=a);const h=0===n||0===o?new N(1,1):new N(i.width/n,i.height/o);return r.multiply(h)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=et(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveSelection(){return this._activeSelection}getActiveObjects(){const t=this._activeObject;return t?t===this._activeSelection?[...t._objects]:[t]:[]}_fireSelectionEvents(t,e){let i=!1,s=!1;const r=this.getActiveObjects(),n=[],o=[];t.forEach((t=>{r.includes(t)||(i=!0,t.fire("deselected",{e:e,target:t}),o.push(t))})),r.forEach((s=>{t.includes(s)||(i=!0,s.fire("selected",{e:e,target:s}),n.push(s))})),t.length>0&&r.length>0?(s=!0,i&&this.fire("selection:updated",{e:e,selected:n,deselected:o})):r.length>0?(s=!0,this.fire("selection:created",{e:e,selected:n})):t.length>0&&(s=!0,this.fire("selection:cleared",{e:e,deselected:o})),s&&(this._objectsToRender=void 0)}setActiveObject(t,e){const i=this.getActiveObjects(),s=this._setActiveObject(t,e);return this._fireSelectionEvents(i,e),s}_setActiveObject(t,e){return this._activeObject!==t&&(!(!this._discardActiveObject(e,t)&&this._activeObject)&&(!t.onSelect({e:e})&&(this._activeObject=t,t instanceof Us&&this._activeSelection!==t&&(this._activeSelection=t,t.set("canvas",this),t.setCoords()),!0)))}_discardActiveObject(t,e){const i=this._activeObject;return!!i&&(!i.onDeselect({e:t,object:e})&&(i===this._activeSelection&&(this._activeSelection.removeAll(),ce(this._activeSelection)),this._currentTransform&&this._currentTransform.target===i&&this.endCurrentTransform(t),this._activeObject=void 0,!0))}discardActiveObject(t){const e=this.getActiveObjects(),i=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[i]});const s=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),s}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeSelection;t.removeAll(),this._activeSelection=void 0,t.dispose(),super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,i){const s=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,i);return t.set(s),r}_realizeGroupTransformOnObject(t){if(t.group&&t.group===this._activeSelection&&this._activeObject===t.group){const e=St(t,["angle","flipX","flipY",A,"scaleX","scaleY","skewX","skewY",E]);return ae(t,this._activeObject.calcOwnMatrix()),e}return{}}_setSVGObject(t,e,i){const s=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,i),e.set(s)}}s(Ur,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class Nr{constructor(t){s(this,"targets",[]),s(this,"__disposer",void 0);const e=()=>{const e=t.getActiveObject();Gt(e)&&e.hiddenTextarea&&e.hiddenTextarea.focus()},i=t.upperCanvasEl;i.addEventListener("click",e),this.__disposer=()=>i.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),z(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;(null===(e=this.target)||void 0===e?void 0:e.isEditing)&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const qr=["target","oldTarget","fireCanvas","e"],Kr={passive:!1};function Jr(t,e){return!!t.button&&t.button===e-1}const Zr=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return t.addEventListener(...i)},Qr=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];return t.removeEventListener(...i)},$r={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class tn extends Ur{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),s(this,"_isClick",void 0),s(this,"textEditingManager",new Nr(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((t=>{this[t]=this[t].bind(this)})),this.addOrRemove(Zr,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const i=this.upperCanvasEl,s=this._getEventPrefix();t(Nt(i),"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,"".concat(s,"move"),this._onMouseMove,Kr),t(i,"".concat(s,"out"),this._onMouseOut),t(i,"".concat(s,"enter"),this._onMouseEnter),t(i,"wheel",this._onMouseWheel),t(i,"contextmenu",this._onContextMenu),t(i,"dblclick",this._onDoubleClick),t(i,"dragstart",this._onDragStart),t(i,"dragend",this._onDragEnd),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,Kr)}removeListeners(){this.addOrRemove(Qr,"remove");const t=this._getEventPrefix(),e=Ut(this.upperCanvasEl);Qr(e,"".concat(t,"up"),this._onMouseUp),Qr(e,"touchend",this._onTouchEnd,Kr),Qr(e,"".concat(t,"move"),this._onMouseMove,Kr),Qr(e,"touchmove",this._onMouseMove,Kr)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s={e:t,isClick:!1,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t)};this.fire("mouse:out",i(i({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",i({},s)),this._hoveredTargets.forEach((t=>{this.fire("mouse:out",i(i({},s),{},{target:t})),t&&t.fire("mouseout",i({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",{e:t,isClick:!1,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t)}),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(zt(e)&&e.onDragStart(t)){this._dragSource=e;const i={e:t,target:e};return this.fire("dragstart",i),e.fire("dragstart",i),void Zr(this.upperCanvasEl,"drag",this._onDragProgress)}re(t)}_renderDragEffects(t,e,i){let s=!1;const r=this._dropTarget;r&&r!==e&&r!==i&&(r.clearContextTop(),s=!0),null==e||e.clearContextTop(),i!==e&&(null==i||i.clearContextTop());const n=this.contextTop;n.save(),n.transform(...this.viewportTransform),e&&(n.save(),e.transform(n),e.renderDragSourceEffect(t),n.restore(),s=!0),i&&(n.save(),i.transform(n),i.renderDropTargetEffect(t),n.restore(),s=!0),n.restore(),s&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==L,i=e?this._activeObject:void 0,s={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:i};Qr(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",s),this._dragSource&&this._dragSource.fire("dragend",s),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){this.targets=[];return{target:this._searchPossibleTargets(this._objects,this.getPointer(t,!0)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:i,targets:s}=this.findDragTargets(t),r=this._dragSource,n={e:t,target:i,subTargets:s,dragSource:r,canDrop:!1,dropTarget:void 0};let o;this.fire(e,n),this._fireEnterLeaveEvents(i,n),i&&(i.canDrop(t)&&(o=i),i.fire(e,n));for(let i=0;i<s.length;i++){const r=s[i];r.canDrop(t)&&(o=r),r.fire(e,n)}this._renderDragEffects(t,r,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:i}=this.findDragTargets(t),s={e:t,target:e,subTargets:i,dragSource:this._dragSource};this.fire("dragenter",s),this._fireEnterLeaveEvents(e,s)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:i}=this.findDragTargets(t),s=this._basicEventHandler("drop:before",{e:t,target:e,subTargets:i,dragSource:this._dragSource,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t)});s.didDrop=!1,s.dropTarget=void 0,this._basicEventHandler("drop",s),this.fire("drop:after",s)}_onContextMenu(t){const e=this.findTarget(t),i=this.targets||[],s=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:i});return this.stopContextMenu&&re(t),this._basicEventHandler("contextmenu",s),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||(!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId))}_onTouchStart(t){t.preventDefault(),null===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix(),s=Ut(e);Zr(s,"touchend",this._onTouchEnd,Kr),Zr(s,"touchmove",this._onMouseMove,Kr),Qr(e,"".concat(i,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();Qr(e,"".concat(i,"move"),this._onMouseMove,Kr);const s=Ut(e);Zr(s,"".concat(i,"up"),this._onMouseUp),Zr(s,"".concat(i,"move"),this._onMouseMove,Kr)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),this.mainTouchId=null;const e=this._getEventPrefix(),i=Ut(this.upperCanvasEl);Qr(i,"touchend",this._onTouchEnd,Kr),Qr(i,"touchmove",this._onMouseMove,Kr),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{Zr(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();if(this._isMainEvent(t)){const t=Ut(this.upperCanvasEl);Qr(t,"".concat(i,"up"),this._onMouseUp),Qr(t,"".concat(i,"move"),this._onMouseMove,Kr),Zr(e,"".concat(i,"move"),this._onMouseMove,Kr)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||zt(e)&&!e.shouldStartDragging())&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!(!!e!=!!t||e&&t&&e!==t)||(Gt(e),!1)}__onMouseUp(t){const e=this._currentTransform;this._cacheTransformEventData(t);const i=this._target,s=this._isClick;if(this._handleEvent(t,"up:before"),Jr(t,3))return void(this.fireRightClick&&this._handleEvent(t,"up",3,s));if(Jr(t,2))return this.fireMiddleClick&&this._handleEvent(t,"up",2,s),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let r,n,o=!1;if(e&&(this._finalizeCurrentTransform(t),o=e.actionPerformed),!s){const e=i===this._activeObject;this.handleSelection(t),o||(o=this._shouldRender(i)||!e&&i===this._activeObject)}if(i){if(n=i._findTargetCorner(this.getPointer(t,!0),se(t)),i.selectable&&i!==this._activeObject&&"up"===i.activeOn)this.setActiveObject(i,t),o=!0;else{const s=i.controls[n],o=s&&s.getMouseUpHandler(t,i,s);o&&(r=this.getPointer(t),o.call(s,t,e,r.x,r.y))}i.isMoving=!1}if(e&&(e.target!==i||e.corner!==n)){const i=e.target&&e.target.controls[e.corner],s=i&&i.getMouseUpHandler(t,e.target,i);r=r||this.getPointer(t),s&&s.call(i,t,e,r.x,r.y)}this._setCursorFromEvent(t,i),this._handleEvent(t,"up",1,s),this._groupSelector=null,this._currentTransform=null,i&&(i.__corner=void 0),o?this.requestRenderAll():s||Gt(this._activeObject)&&this._activeObject.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:i,subTargets:s=[]}=e;this.fire(t,e),i&&i.fire(t,e);for(let r=0;r<s.length;r++)s[r]!==i&&s[r].fire(t,e);return e}_handleEvent(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const r=this._target,n=this.targets||[],o={e:t,target:r,subTargets:n,button:i,isClick:s,pointer:this.getPointer(t,!0),absolutePointer:this.getPointer(t),transform:this._currentTransform};"up"===e&&(o.currentTarget=this.findTarget(t),o.currentSubTargets=this.targets),this.fire("mouse:".concat(e),o),r&&r.fire("mouse".concat(e),o);for(let t=0;t<n.length;t++)n[t]!==r&&n[t].fire("mouse".concat(e),o)}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,i=e.target,s={e:t,target:i,transform:e,action:e.action};i._scaling&&(i._scaling=!1),i.setCoords(),e.actionPerformed&&(this.fire("object:modified",s),i.fire("modified",s))}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getPointer(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getPointer(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getPointer(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;if(Jr(t,3))return void(this.fireRightClick&&this._handleEvent(t,"down",3));if(Jr(t,2))return void(this.fireMiddleClick&&this._handleEvent(t,"down",2));if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t))return;if(this._currentTransform)return;let i=this._shouldRender(e),s=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,s=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const e=this.getPointer(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(e){const i=e===this._activeObject;e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);const r=e._findTargetCorner(this.getPointer(t,!0),se(t));if(e===this._activeObject&&(r||!s)){this._setupCurrentTransform(t,e,i);const s=e.controls[r],n=this.getPointer(t),o=s&&s.getMouseDownHandler(t,e,s);o&&o.call(s,t,this._currentTransform,n.x,n.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getPointer(t,!0),this._absolutePointer=this.restorePointerVpt(this._pointer),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}_beforeTransform(t){const e=this._currentTransform;this.fire("before:transform",{e:t,transform:e})}__onMouseMove(t){if(this._isClick=!1,this._handleEvent(t,"move:before"),this._cacheTransformEventData(t),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const i=this.getPointer(t);e.deltaX=i.x-e.x,e.deltaY=i.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const e=this.findTarget(t);this._setCursorFromEvent(t,e),this._fireOverOutEvents(t,e)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const i=this._hoveredTarget,s=this._hoveredTargets,r=this.targets,n=Math.max(s.length,r.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:i,fireCanvas:!0});for(let e=0;e<n;e++)this.fireSyntheticInOutEvents("mouse",{e:t,target:r[e],oldTarget:s[e]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,r=this._hoveredTargets,n=this.targets,o=Math.max(r.length,n.length);this.fireSyntheticInOutEvents("drag",i(i({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let t=0;t<o;t++)this.fireSyntheticInOutEvents("drag",i(i({},e),{},{target:n[t],oldTarget:r[t]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:n,fireCanvas:o,e:a}=e,h=r(e,qr);const{targetIn:c,targetOut:l,canvasIn:d,canvasOut:u}=$r[t],g=n!==s;if(n&&g){const t=i(i({},h),{},{e:a,target:n,nextTarget:s,isClick:!1,pointer:this.getPointer(a,!0),absolutePointer:this.getPointer(a)});o&&this.fire(u,t),n.fire(l,t)}if(s&&g){const t=i(i({},h),{},{e:a,target:s,previousTarget:n,isClick:!1,pointer:this.getPointer(a,!0),absolutePointer:this.getPointer(a)});o&&this.fire(d,t),s.fire(c,t)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getPointer(t),i=this._currentTransform,s=i.target,r=s.group?ge(e,void 0,s.group.calcTransformMatrix()):e;i.reset=!1,i.shiftKey=t.shiftKey,i.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,i,r),i.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,i){const s=i.x,r=i.y,n=e.action,o=e.actionHandler;let a=!1;o&&(a=o(t,e,s,r)),"drag"===n&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let i=e.hoverCursor||this.hoverCursor;const s=this._activeObject===this._activeSelection?this._activeObject:null,r=(!s||e.group!==s)&&e._findTargetCorner(this.getPointer(t,!0));if(r){const i=e.controls[r];this.setCursor(i.cursorStyleHandler(t,i,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((t=>{i=t.hoverCursor||i})),this.setCursor(i)}handleMultiSelection(t,e){const i=this._activeObject,s=this._activeSelection,r=i===s;if(i&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(i!==e||r)&&(r||!e.isDescendantOf(i)&&!i.isDescendantOf(e))&&!e.onSelect({e:t})&&!i.getActiveControl()){if(r){const i=s.getObjects();if(e===s){const s=this.getPointer(t,!0);if(!(e=this.searchPossibleTargets(i,s)||this.searchPossibleTargets(this._objects,s))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],1===s.size()&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(i,t)}else Gt(i)&&i.exitEditing(),s.multiSelectAdd(i,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([i],t);return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new N(e,i),o=n.add(new N(s,r)),a=n.min(o),h=n.max(o).subtract(a),c=n.eq(o),l=this.collectObjects({left:a.x,top:a.y,width:h.x,height:h.y},{includeIntersecting:!this.selectionFullyContained}),d=c?l[0]?[l[0]]:[]:l.length>1?l.filter((e=>!e.onSelect({e:t}))).reverse():l;return 1===d.length?this.setActiveObject(d[0],t):d.length>1&&(this._activeSelection.add(...d),this.setActiveObject(this._activeSelection,t)),this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const en={x1:0,y1:0,x2:0,y2:0},sn=i(i({},en),{},{r1:0,r2:0}),rn=/^(\d+\.\d+)%|(\d+)%$/;function nn(t){return t&&rn.test(t)}function on(t,e){const i="number"==typeof t?t:"string"==typeof t?parseFloat(t)/(nn(t)?100:1):NaN;return Xe(0,G(i,e),1)}const an=/\s*;\s*/,hn=/\s*:\s*/;function cn(t,e){let i,s;const r=t.getAttribute("style");if(r){const t=r.split(an);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){const[r,n]=t[e].split(hn).map((t=>t.trim()));"stop-color"===r?i=n:"stop-opacity"===r&&(s=n)}}const n=new At(i||t.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:on(t.getAttribute("offset"),0),color:n.toRgb(),opacity:G(parseFloat(s||t.getAttribute("stop-opacity")||""),1)*n.getAlpha()*e}}function ln(t,e){const i=[],s=t.getElementsByTagName("stop"),r=on(e,1);for(let t=s.length;t--;)i.push(cn(s[t],r));return i}function dn(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function un(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}function gn(t,e){return t.getAttribute(e)}function fn(t,e){return function(t,e){let i,{width:s,height:r,gradientUnits:n}=e;return Object.keys(t).reduce(((e,o)=>{const a=t[o];return"Infinity"===a?i=1:"-Infinity"===a?i=0:(i="string"==typeof a?parseFloat(a):a,"string"==typeof a&&nn(a)&&(i*=.01,"pixels"===n&&("x1"!==o&&"x2"!==o&&"r2"!==o||(i*=s),"y1"!==o&&"y2"!==o||(i*=r)))),e[o]=i,e}),{})}("linear"===dn(t)?function(t){return{x1:gn(t,"x1")||0,y1:gn(t,"y1")||0,x2:gn(t,"x2")||"100%",y2:gn(t,"y2")||0}}(t):function(t){return{x1:gn(t,"fx")||gn(t,"cx")||"50%",y1:gn(t,"fy")||gn(t,"cy")||"50%",r1:0,x2:gn(t,"cx")||"50%",y2:gn(t,"cy")||"50%",r2:gn(t,"r")||"50%"}}(t),i(i({},e),{},{gradientUnits:un(t)}))}class pn{constructor(t){let{type:e="linear",gradientUnits:s="pixels",coords:r,colorStops:n=[],offsetX:o=0,offsetY:a=0,gradientTransform:h,id:c}=t;this.id=c?"".concat(c,"_").concat(tt()):tt(),this.type=e,this.gradientUnits=s,this.gradientTransform=h,this.offsetX=o,this.offsetY=a,this.coords=i(i({},"radial"===this.type?sn:en),r),this.colorStops=n.slice()}addColorStop(t){for(const e in t){const i=new At(t[e]);this.colorStops.push({offset:parseFloat(e),color:i.toRgb(),opacity:i.getAlpha()})}return this}toObject(t){return i(i({},St(this,t)),{},{type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[],r=this.gradientTransform?this.gradientTransform.concat():k.concat(),n="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map((t=>i({},t))).sort(((t,e)=>t.offset-e.offset));let a=-this.offsetX,h=-this.offsetY;var c;"objectBoundingBox"===n?(a/=t.width,h/=t.height):(a+=t.width/2,h+=t.height/2),(c=t)&&c.isType("Path")&&"percentage"!==this.gradientUnits&&(a-=t.pathOffset.x,h-=t.pathOffset.y),r[4]-=a,r[5]-=h;const l=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Lt(r),'"'),""].join(" ");if("linear"===this.type){const{x1:t,y1:e,x2:i,y2:r}=this.coords;s.push("<linearGradient ",l,' x1="',t,'" y1="',e,'" x2="',i,'" y2="',r,'">\n')}else if("radial"===this.type){const{x1:t,y1:e,x2:i,y2:r,r1:n,r2:a}=this.coords,h=n>a;s.push("<radialGradient ",l,' cx="',h?t:i,'" cy="',h?e:r,'" r="',h?n:a,'" fx="',h?i:t,'" fy="',h?r:e,'">\n'),h&&(o.reverse(),o.forEach((t=>{t.offset=1-t.offset})));const c=Math.min(n,a);if(c>0){const t=c/Math.max(n,a);o.forEach((e=>{e.offset+=t*(1-e.offset)}))}}return o.forEach((t=>{let{color:e,offset:i,opacity:r}=t;s.push("<stop ",'offset="',100*i+"%",'" style="stop-color:',e,void 0!==r?";stop-opacity: "+r:";",'"/>\n')})),s.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),s.join("")}toLive(t){const e=this.coords,i="linear"===this.type?t.createLinearGradient(e.x1,e.y1,e.x2,e.y2):t.createRadialGradient(e.x1,e.y1,e.r1,e.x2,e.y2,e.r2);return this.colorStops.forEach((t=>{let{color:e,opacity:s,offset:r}=t;i.addColorStop(r,void 0!==s?new At(e).setAlpha(s).toRgba():e)})),i}static fromElement(t,e,s){const r=un(t),n=e._findCenterFromElement();return new this(i({id:t.getAttribute("id")||void 0,type:dn(t),coords:fn(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:ln(t,s.opacity),gradientUnits:r,gradientTransform:Ls(t.getAttribute("gradientTransform")||"")},"pixels"===r?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}s(pn,"type","Gradient"),X.setClass(pn,"gradient");const mn=["source"];class vn{get type(){return"pattern"}set type(t){c("warn","Setting type has no effect",t)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"repeat","repeat"),s(this,"offsetX",0),s(this,"offsetY",0),s(this,"crossOrigin",""),s(this,"patternTransform",null),this.id=tt(),Object.assign(this,t)}isImageSource(){return!!this.source&&"string"==typeof this.source.src}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&0!==this.source.naturalWidth&&0!==this.source.naturalHeight)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return i(i({},St(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:Et(this.offsetX,h.NUM_FRACTION_DIGITS),offsetY:Et(this.offsetY,h.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:i}=t;const{source:s,repeat:r,id:n}=this,o=G(this.offsetX/e,0),a=G(this.offsetY/i,0),h="repeat-y"===r||"no-repeat"===r?1+Math.abs(o||0):G(s.width/e,0),c="repeat-x"===r||"no-repeat"===r?1+Math.abs(a||0):G(s.height/i,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(a,'" width="').concat(h,'" height="').concat(c,'">'),'<image x="0" y="0" width="'.concat(s.width,'" height="').concat(s.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join("\n")}static async fromObject(t,e){let{source:s}=t,n=r(t,mn);const o=await xt(s,i(i({},e),{},{crossOrigin:n.crossOrigin}));return new this(i(i({},n),{},{source:o}))}}s(vn,"type","Pattern"),X.setClass(vn),X.setClass(vn,"pattern");class _n{constructor(t){s(this,"color","rgb(0, 0, 0)"),s(this,"width",1),s(this,"shadow",null),s(this,"strokeLineCap","round"),s(this,"strokeLineJoin","round"),s(this,"strokeMiterLimit",10),s(this,"strokeDashArray",null),s(this,"limitedToCanvasSize",!1),this.canvas=t}_setBrushStyles(t){t.strokeStyle=this.color,t.lineWidth=this.width,t.lineCap=this.strokeLineCap,t.miterLimit=this.strokeMiterLimit,t.lineJoin=this.strokeLineJoin,t.setLineDash(this.strokeDashArray||[])}_saveAndTransform(t){const e=this.canvas.viewportTransform;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5])}needsFullRender(){return new At(this.color).getAlpha()<1||!!this.shadow}_setShadow(){if(!this.shadow||!this.canvas)return;const t=this.canvas,e=this.shadow,i=t.contextTop,s=t.getZoom()*t.getRetinaScaling();i.shadowColor=e.color,i.shadowBlur=e.blur*s,i.shadowOffsetX=e.offsetX*s,i.shadowOffsetY=e.offsetY*s}_resetShadow(){const t=this.canvas.contextTop;t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0}_isOutSideCanvas(t){return t.x<0||t.x>this.canvas.getWidth()||t.y<0||t.y>this.canvas.getHeight()}}const yn=["path","left","top"],xn=["d"];class Cn extends Ji{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{path:i,left:s,top:n}=e;super(r(e,yn)),this._setPath(t||[],!0),"number"==typeof s&&this.set(A,s),"number"==typeof n&&this.set(E,n)}_setPath(t,e){this.path=Tr(Array.isArray(t)?t:Ir(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new N(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){let e=0,i=0,s=0,r=0,n=0,o=0;const a=-this.pathOffset.x,h=-this.pathOffset.y;t.beginPath();for(const c of this.path)switch(c[0]){case"L":s=c[1],r=c[2],t.lineTo(s+a,r+h);break;case"M":s=c[1],r=c[2],e=s,i=r,t.moveTo(s+a,r+h);break;case"C":s=c[5],r=c[6],n=c[3],o=c[4],t.bezierCurveTo(c[1]+a,c[2]+h,n+a,o+h,s+a,r+h);break;case"Q":t.quadraticCurveTo(c[1]+a,c[2]+h,c[3]+a,c[4]+h),s=c[3],r=c[4],n=c[1],o=c[2];break;case"Z":s=e,r=i,t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),{},{path:di(this.path)})}toDatalessObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=Yr(this.path,h.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,'" stroke-linecap="round" />\n')]}_getOffsetTransform(){const t=h.NUM_FRACTION_DIGITS;return" translate(".concat(Et(-this.pathOffset.x,t),", ").concat(Et(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:i,pathOffset:s}=this._calcDimensions();this.set({width:e,height:i,pathOffset:s}),t&&this.setPositionByOrigin(s,P,P)}_calcBoundsFromPath(){const t=[];let e=0,i=0,s=0,r=0;for(const n of this.path)switch(n[0]){case"L":s=n[1],r=n[2],t.push(new N(e,i),new N(s,r));break;case"M":s=n[1],r=n[2],e=s,i=r;break;case"C":t.push(...Sr(s,r,n[1],n[2],n[3],n[4],n[5],n[6])),s=n[5],r=n[6];break;case"Q":t.push(...Sr(s,r,n[1],n[2],n[1],n[2],n[3],n[4])),s=n[3],r=n[4];break;case"Z":s=e,r=i}return ne(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return i(i({},t),{},{pathOffset:new N(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const n=Ys(t,this.ATTRIBUTE_NAMES,s),{d:o}=n;return new this(o,i(i(i({},r(n,xn)),e),{},{left:void 0,top:void 0}))}}s(Cn,"type","Path"),s(Cn,"cacheProperties",[...gi,"path","fillRule"]),s(Cn,"ATTRIBUTE_NAMES",[...Qi,"d"]),X.setClass(Cn),X.setSVGClass(Cn);class bn extends _n{constructor(t){super(t),s(this,"decimate",.4),s(this,"drawStraightLine",!1),s(this,"straightLineKey","shiftKey"),this._points=[],this._hasStraightLine=!1}needsFullRender(){return super.needsFullRender()||this._hasStraightLine}static drawSegment(t,e,i){const s=e.midPointFrom(i);return t.quadraticCurveTo(e.x,e.y,s.x,s.y),s}onMouseDown(t,e){let{e:i}=e;this.canvas._isMainEvent(i)&&(this.drawStraightLine=!!this.straightLineKey&&i[this.straightLineKey],this._prepareForDrawing(t),this._addPoint(t),this._render())}onMouseMove(t,e){let{e:i}=e;if(this.canvas._isMainEvent(i)&&(this.drawStraightLine=!!this.straightLineKey&&i[this.straightLineKey],(!0!==this.limitedToCanvasSize||!this._isOutSideCanvas(t))&&this._addPoint(t)&&this._points.length>1))if(this.needsFullRender())this.canvas.clearContext(this.canvas.contextTop),this._render();else{const t=this._points,e=t.length,i=this.canvas.contextTop;this._saveAndTransform(i),this.oldEnd&&(i.beginPath(),i.moveTo(this.oldEnd.x,this.oldEnd.y)),this.oldEnd=bn.drawSegment(i,t[e-2],t[e-1]),i.stroke(),i.restore()}}onMouseUp(t){let{e:e}=t;return!this.canvas._isMainEvent(e)||(this.drawStraightLine=!1,this.oldEnd=void 0,this._finalizeAndAddPath(),!1)}_prepareForDrawing(t){this._reset(),this._addPoint(t),this.canvas.contextTop.moveTo(t.x,t.y)}_addPoint(t){return!(this._points.length>1&&t.eq(this._points[this._points.length-1]))&&(this.drawStraightLine&&this._points.length>1&&(this._hasStraightLine=!0,this._points.pop()),this._points.push(t),!0)}_reset(){this._points=[],this._setBrushStyles(this.canvas.contextTop),this._setShadow(),this._hasStraightLine=!1}_render(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.contextTop,e=this._points[0],i=this._points[1];if(this._saveAndTransform(t),t.beginPath(),2===this._points.length&&e.x===i.x&&e.y===i.y){const t=this.width/1e3;e.x-=t,i.x+=t}t.moveTo(e.x,e.y);for(let s=1;s<this._points.length;s++)bn.drawSegment(t,e,i),e=this._points[s],i=this._points[s+1];t.lineTo(e.x,e.y),t.stroke(),t.restore()}convertPointsToSVGPath(t){const e=this.width/1e3;return Xr(t,e)}createPath(t){const e=new Cn(t,{fill:null,stroke:this.color,strokeWidth:this.width,strokeLineCap:this.strokeLineCap,strokeMiterLimit:this.strokeMiterLimit,strokeLineJoin:this.strokeLineJoin,strokeDashArray:this.strokeDashArray});return this.shadow&&(this.shadow.affectStroke=!0,e.shadow=new li(this.shadow)),e}decimatePoints(t,e){if(t.length<=2)return t;let i,s=t[0];const r=this.canvas.getZoom(),n=Math.pow(e/r,2),o=t.length-1,a=[s];for(let e=1;e<o-1;e++)i=Math.pow(s.x-t[e].x,2)+Math.pow(s.y-t[e].y,2),i>=n&&(s=t[e],a.push(s));return a.push(t[o]),a}_finalizeAndAddPath(){this.canvas.contextTop.closePath(),this.decimate&&(this._points=this.decimatePoints(this._points,this.decimate));const t=this.convertPointsToSVGPath(this._points);if(function(t){return"M 0 0 Q 0 0 0 0 L 0 0"===Yr(t)}(t))return void this.canvas.requestRenderAll();const e=this.createPath(t);this.canvas.clearContext(this.canvas.contextTop),this.canvas.fire("before:path:created",{path:e}),this.canvas.add(e),this.canvas.requestRenderAll(),e.setCoords(),this._resetShadow(),this.canvas.fire("path:created",{path:e})}}const Sn=["left","top","radius"],wn=["radius","startAngle","endAngle"];class Tn extends Ji{static getDefaults(){return i(i({},super.getDefaults()),Tn.ownDefaults)}_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),!1),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get("scaleX")}getRadiusY(){return this.get("radius")*this.get("scaleY")}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([...wn,...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,i=rt(this.startAngle),s=rt(this.endAngle),r=H(i)*e,n=U(i)*e,o=H(s)*e,a=U(s)*e,h=t>180?"1":"0";return['<path d="M '.concat(r," ").concat(n)," A ".concat(e," ").concat(e)," 0 ","".concat(h," 1")," ".concat(o," ").concat(a),'" ',"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,s){const n=Ys(t,this.ATTRIBUTE_NAMES,s),{left:o=0,top:a=0,radius:h=0}=n;return new this(i(i({},r(n,Sn)),{},{radius:h,left:o-h,top:a-h}))}static fromObject(t){return super._fromObject(t)}}s(Tn,"type","Circle"),s(Tn,"cacheProperties",[...gi,...wn]),s(Tn,"ownDefaults",{radius:0,startAngle:0,endAngle:360}),s(Tn,"ATTRIBUTE_NAMES",["cx","cy","r",...Qi]),X.setClass(Tn),X.setSVGClass(Tn);const On=["x1","y1","x2","y2"],kn=["x1","y1","x2","y2"],Dn=["x1","x2","y1","y2"];class Mn extends Ji{constructor(){let[t,e,s,r]=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0,0,0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i(i({},n),{},{x1:t,y1:e,x2:s,y2:r})),this._setWidthHeight();const{left:o,top:a}=n;"number"==typeof o&&this.set(A,o),"number"==typeof a&&this.set(E,a)}_setWidthHeight(){const{x1:t,y1:e,x2:i,y2:s}=this;this.width=Math.abs(i-t),this.height=Math.abs(s-e);const{left:r,top:n,width:o,height:a}=ne([{x:t,y:e},{x:i,y:s}]),h=new N(r+o/2,n+a/2);this.setPositionByOrigin(h,P,P)}_set(t,e){return super._set(t,e),Dn.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const i=t.strokeStyle;var s;It(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=null!==(s=this.stroke)&&void 0!==s?s:t.fillStyle;this.stroke&&this._renderStroke(t),t.strokeStyle=i}_findCenterFromElement(){return new N((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:i,y2:s,width:r,height:n}=this,o=t<=e?-1:1,a=i<=s?-1:1;return{x1:o*r/2,x2:o*-r/2,y1:a*n/2,y2:a*-n/2}}_toSVG(){const{x1:t,x2:e,y1:i,y2:s}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(i,'" x2="').concat(e,'" y2="').concat(s,'" />\n')]}static async fromElement(t,e,i){const s=Ys(t,this.ATTRIBUTE_NAMES,i),{x1:n=0,y1:o=0,x2:a=0,y2:h=0}=s;return new this([n,o,a,h],r(s,On))}static fromObject(t){let{x1:e,y1:s,x2:n,y2:o}=t,a=r(t,kn);return this._fromObject(i(i({},a),{},{points:[e,s,n,o]}),{extraParam:"points"})}}s(Mn,"type","Line"),s(Mn,"cacheProperties",[...gi,...Dn]),s(Mn,"ATTRIBUTE_NAMES",Qi.concat(Dn)),X.setClass(Mn),X.setSVGClass(Mn);class Pn extends Ji{static getDefaults(){return i(i({},super.getDefaults()),Pn.ownDefaults)}_render(t){const e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,i),t.lineTo(0,-i),t.lineTo(e,i),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}s(Pn,"type","Triangle"),s(Pn,"ownDefaults",{width:100,height:100}),X.setClass(Pn),X.setSVGClass(Pn);const An=["rx","ry"];class En extends Ji{static getDefaults(){return i(i({},super.getDefaults()),En.ownDefaults)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get("scaleX")}getRy(){return this.get("ry")*this.get("scaleY")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...An,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,'" />\n')]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,T,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,i){const s=Ys(t,this.ATTRIBUTE_NAMES,i);return s.left=(s.left||0)-s.rx,s.top=(s.top||0)-s.ry,new this(s)}}function jn(t){if(!t)return[];const e=t.replace(/,/g," ").trim().split(/\s+/),i=[];for(let t=0;t<e.length;t+=2)i.push({x:parseFloat(e[t]),y:parseFloat(e[t+1])});return i}s(En,"type","Ellipse"),s(En,"cacheProperties",[...gi,...An]),s(En,"ownDefaults",{rx:0,ry:0}),s(En,"ATTRIBUTE_NAMES",[...Qi,"cx","cy","rx","ry"]),X.setClass(En),X.setSVGClass(En);const Fn=["left","top"],Ln={exactBoundingBox:!1};class Rn extends Ji{static getDefaults(){return i(i({},super.getDefaults()),Rn.ownDefaults)}constructor(){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i({points:arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]},t)),s(this,"strokeDiff",void 0);const{left:e,top:r}=t;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof e&&this.set(A,e),"number"==typeof r&&this.set(E,r)}isOpen(){return!0}_projectStrokeOnPoints(t){return Zs(this.points,t,this.isOpen())}_calcDimensions(t){t=i({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map((t=>t.projectedPoint)):this.points;if(0===e.length)return{left:0,top:0,width:0,height:0,pathOffset:new N,strokeOffset:new N,strokeDiff:new N};const s=ne(e),r=_t(i(i({},t),{},{scaleX:1,scaleY:1})),n=ne(this.points.map((t=>at(t,r,!0)))),o=s.left+s.width/2,a=s.top+s.height/2,h=o-a*Math.tan(rt(this.skewX)),c=a-h*Math.tan(rt(this.skewY)),l=new N(this.scaleX,this.scaleY);return i(i({},s),{},{pathOffset:new N(h,c),strokeOffset:new N(n.left,n.top).subtract(new N(s.left,s.top)).multiply(l),strokeDiff:new N(s.width,s.height).subtract(new N(n.width,n.height)).multiply(l)})}_findCenterFromElement(){const t=ne(this.points);return new N(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:i,width:s,height:r,pathOffset:n,strokeOffset:o,strokeDiff:a}=this._calcDimensions();this.set({width:s,height:r,pathOffset:n,strokeOffset:o,strokeDiff:a}),t&&this.setPositionByOrigin(new N(e+s/2,i+r/2),P,P)}_getNonTransformedDimensions(){return this.exactBoundingBox?new N(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.exactBoundingBox){let n;if(Object.keys(t).some((t=>this.strokeUniform||this.constructor.layoutProperties.includes(t)))){var e,i;const{width:s,height:r}=this._calcDimensions(t);n=new N(null!==(e=t.width)&&void 0!==e?e:s,null!==(i=t.height)&&void 0!==i?i:r)}else{var s,r;n=new N(null!==(s=t.width)&&void 0!==s?s:this.width,null!==(r=t.height)&&void 0!==r?r:this.height)}return n.multiply(new N(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const i=this.initialized&&this[t]!==e,s=super._set(t,e);return this.exactBoundingBox&&i&&(("scaleX"===t||"scaleY"===t)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),s}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject(t)),{},{points:di(this.points)})}_toSVG(){const t=[],e=this.pathOffset.x,i=this.pathOffset.y,s=h.NUM_FRACTION_DIGITS;for(let r=0,n=this.points.length;r<n;r++)t.push(Et(this.points[r].x-e,s),",",Et(this.points[r].y-i,s)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),'" />\n')]}_render(t){const e=this.points.length,i=this.pathOffset.x,s=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-i,this.points[0].y-s);for(let r=0;r<e;r++){const e=this.points[r];t.lineTo(e.x-i,e.y-s)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(jn(t.getAttribute("points")),i(i({},r(Ys(t,this.ATTRIBUTE_NAMES,s),Fn)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}s(Rn,"ownDefaults",Ln),s(Rn,"type","Polyline"),s(Rn,"layoutProperties",["skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),s(Rn,"cacheProperties",[...gi,"points"]),s(Rn,"ATTRIBUTE_NAMES",[...Qi]),X.setClass(Rn),X.setSVGClass(Rn);class Bn extends Rn{static getDefaults(){return i(i({},super.getDefaults()),Rn.ownDefaults)}isOpen(){return!1}}s(Bn,"ownDefaults",Ln),s(Bn,"type","Polygon"),X.setClass(Bn),X.setSVGClass(Bn);const In=["fontSize","fontWeight","fontFamily","fontStyle"],Xn=["underline","overline","linethrough"],Yn=[...In,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],Wn=[...Yn,...Xn,"textBackgroundColor","direction"],Vn=[...In,...Xn,"stroke","strokeWidth","fill","deltaY","textBackgroundColor"],Gn={_reNewline:R,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:A,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:A,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},zn="justify",Hn="justify-left",Un="justify-right",Nn="justify-center";class qn extends Ji{isEmptyStyles(t){if(!this.styles)return!0;if(void 0!==t&&!this.styles[t])return!0;const e=void 0===t?this.styles:{line:this.styles[t]};for(const t in e)for(const i in e[t])for(const s in e[t][i])return!1;return!0}styleHas(t,e){if(!this.styles)return!1;if(void 0!==e&&!this.styles[e])return!1;const i=void 0===e?this.styles:{0:this.styles[e]};for(const e in i)for(const s in i[e])if(void 0!==i[e][s][t])return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let i,s,r=0,n=!0,o=0;for(const o in e){i=0;for(const a in e[o]){const h=e[o][a]||{};r++,void 0!==h[t]?(s?h[t]!==s&&(n=!1):s=h[t],h[t]===this[t]&&delete h[t]):n=!1,0!==Object.keys(h).length?i++:delete e[o][a]}0===i&&delete e[o]}for(let t=0;t<this._textLines.length;t++)o+=this._textLines[t].length;n&&r===o&&(this[t]=s,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let i,s,r;for(s in e){for(r in i=e[s],i)delete i[r][t],0===Object.keys(i[r]).length&&delete i[r];0===Object.keys(i).length&&delete e[s]}}_extendStyles(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);this._getLineStyle(i)||this._setLineStyle(i),Object.keys(this._getStyleDeclaration(i,s)).length||this._setStyleDeclaration(i,s,{}),Object.assign(this._getStyleDeclaration(i,s),e)}getSelectionStyles(t,e,i){const s=[];for(let r=t;r<(e||t);r++)s.push(this.getStyleAtPosition(r,i));return s}getStyleAtPosition(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(i,s):this._getStyleDeclaration(i,s)}setSelectionStyles(t,e,i){for(let s=e;s<(i||e);s++)this._extendStyles(s,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var i;const s=this.styles&&this.styles[t];return s&&null!==(i=s[e])&&void 0!==i?i:{}}getCompleteStyleDeclaration(t,e){return i(i({},St(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,i){this.styles[t][e]=i}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}s(qn,"_styleProperties",Vn);const Kn=/ +/g,Jn=/"/g;function Zn(t,e,i,s,r){return"\t\t".concat(Bt(t,{left:e,top:i,width:s,height:r}),"\n")}const Qn=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let $n;class to extends qn{static getDefaults(){return i(i({},super.getDefaults()),to.ownDefaults)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i(i({},e),{},{text:t,styles:(null==e?void 0:e.styles)||{}})),s(this,"__charBounds",[]),this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Rr(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(zn)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,r,n,o;for(let a=0,h=this._textLines.length;a<h;a++)if((this.textAlign===zn||a!==h-1&&!this.isEndOfWrapping(a))&&(s=0,r=this._textLines[a],e=this.getLineWidth(a),e<this.width&&(o=this.textLines[a].match(this._reSpacesAndTabs)))){i=o.length,t=(this.width-e)/i;for(let e=0;e<=r.length;e++)n=this.__charBounds[a][e],this._reSpaceAndTab.test(r[e])?(n.width+=t,n.kernedWidth+=t,n.left+=s,s+=t):n.left+=s}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const i=e?this._unwrappedTextLines:this._textLines;let s;for(s=0;s<i.length;s++){if(t<=i[s].length)return{lineIndex:s,charIndex:t};t-=i[s].length+this.missingNewlineOffset(s,e)}return{lineIndex:s-1,charIndex:i[s-1].length<t?i[s-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,i){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case P:t.textBaseline="middle";break;case"ascender":t.textBaseline=E;break;case"descender":t.textBaseline=j}t.font=this._getFontDeclaration(e,i)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,i=this._textLines.length;e<i;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,i,s,r,n){this._renderChars(t,e,i,s,r,n)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,i=this._getLeftOffset();let s=this._getTopOffset();for(let e=0,r=this._textLines.length;e<r;e++){const r=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){s+=r;continue}const n=this._textLines[e].length,o=this._getLineLeftOffset(e);let a,h,c=0,l=0,d=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let u=0;u<n;u++){const n=this.__charBounds[e][u];h=this.getValueOfPropertyAt(e,u,"textBackgroundColor"),this.path?(t.save(),t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillStyle=h,h&&t.fillRect(-n.width/2,-r/this.lineHeight*(1-this._fontSizeFraction),n.width,r/this.lineHeight),t.restore()):h!==d?(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=d,d&&t.fillRect(a,s,c,r/this.lineHeight),l=n.left,c=n.width,d=h):c+=n.kernedWidth}h&&!this.path&&(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-c),t.fillStyle=h,t.fillRect(a,s,c,r/this.lineHeight)),s+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,s){const r=C.getFontCache(e),n=this._getFontDeclaration(e),o=i+t,a=i&&n===this._getFontDeclaration(s),h=e.fontSize/this.CACHE_FONT_SIZE;let c,l,d,u;if(i&&void 0!==r[i]&&(d=r[i]),void 0!==r[t]&&(u=c=r[t]),a&&void 0!==r[o]&&(l=r[o],u=l-d),void 0===c||void 0===d||void 0===l){const s=($n||($n=et().getContext("2d")),$n);this._setTextStyles(s,e,!0),void 0===c&&(u=c=s.measureText(t).width,r[t]=c),void 0===d&&a&&i&&(d=s.measureText(i).width,r[i]=d),a&&void 0===l&&(l=s.measureText(o).width,r[o]=l,u=l-d)}return{width:c*h,kernedWidth:u*h}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,i,s=0;const r=this.pathSide===F,n=this.path,o=this._textLines[t],a=o.length,h=new Array(a);this.__charBounds[t]=h;for(let r=0;r<a;r++){const n=o[r];i=this._getGraphemeBox(n,t,r,e),h[r]=i,s+=i.kernedWidth,e=n}if(h[a]={left:i?i.left+i.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},n&&n.segmentsInfo){let t=0;const e=n.segmentsInfo[n.segmentsInfo.length-1].length;switch(this.textAlign){case A:t=r?e-s:0;break;case P:t=(e-s)/2;break;case F:t=r?0:e-s}t+=this.pathStartOffset*(r?-1:1);for(let s=r?a-1:0;r?s>=0:s<a;r?s--:s++)i=h[s],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,i),t+=i.kernedWidth}return{width:s,numOfSpaces:0}}_setGraphemeOnPath(t,e){const i=t+e.kernedWidth/2,s=this.path,r=Br(s.path,i,s.segmentsInfo);e.renderLeft=r.x-s.pathOffset.x,e.renderTop=r.y-s.pathOffset.y,e.angle=r.angle+(this.pathSide===F?Math.PI:0)}_getGraphemeBox(t,e,i,s,r){const n=this.getCompleteStyleDeclaration(e,i),o=s?this.getCompleteStyleDeclaration(e,i-1):{},a=this._measureChar(t,n,s,o);let h,c=a.kernedWidth,l=a.width;0!==this.charSpacing&&(h=this._getWidthOfCharSpacing(),l+=h,c+=h);const d={width:l,left:0,height:n.fontSize,kernedWidth:c,deltaY:n.deltaY};if(i>0&&!r){const t=this.__charBounds[e][i-1];d.left=t.left+t.width+a.kernedWidth-a.width}return d}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let i=1,s=this._textLines[t].length;i<s;i++)e=Math.max(this.getHeightOfChar(t,i),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let i=0,s=this._textLines.length;i<s;i++)t=this.getHeightOfLine(i),e+=i===s-1?t/this.lineHeight:t;return e}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let i=0;const s=this._getLeftOffset(),r=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const o=this.getHeightOfLine(n),a=o/this.lineHeight,h=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],s+h,r+i+a,n),i+=o}t.restore()}_renderTextFill(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,i,s,r,n){const o=this.getHeightOfLine(n),a=this.textAlign.includes(zn),h=this.path,c=!a&&0===this.charSpacing&&this.isEmptyStyles(n)&&!h,l="ltr"===this.direction,d="ltr"===this.direction?1:-1,u=e.direction;let g,f,p,m,v,_="",y=0;if(e.save(),u!==this.direction&&(e.canvas.setAttribute("dir",l?"ltr":"rtl"),e.direction=l?"ltr":"rtl",e.textAlign=l?A:F),r-=o*this._fontSizeFraction/this.lineHeight,c)return this._renderChar(t,e,n,0,i.join(""),s,r),void e.restore();for(let o=0,c=i.length-1;o<=c;o++)m=o===c||this.charSpacing||h,_+=i[o],p=this.__charBounds[n][o],0===y?(s+=d*(p.kernedWidth-p.width),y+=p.width):y+=p.kernedWidth,a&&!m&&this._reSpaceAndTab.test(i[o])&&(m=!0),m||(g=g||this.getCompleteStyleDeclaration(n,o),f=this.getCompleteStyleDeclaration(n,o+1),m=Qs(g,f,!1)),m&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,n,o,_,-y/2,0),e.restore()):(v=s,this._renderChar(t,e,n,o,_,v,r)),_="",g=f,s+=d*y,y=0);e.restore()}_applyPatternGradientTransformText(t){const e=et(),i=this.width+this.strokeWidth,s=this.height+this.strokeWidth,r=e.getContext("2d");return e.width=i,e.height=s,r.beginPath(),r.moveTo(0,0),r.lineTo(i,0),r.lineTo(i,s),r.lineTo(0,s),r.closePath(),r.translate(i/2,s/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(e,"no-repeat")}handleFiller(t,e,i){let s,r;return It(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?(s=-this.width/2,r=-this.height/2,t.translate(s,r),t[e]=this._applyPatternGradientTransformText(i),{offsetX:s,offsetY:r}):(t[e]=i.toLive(t),this._applyPatternGradientTransform(t,i)):(t[e]=i,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:i,strokeWidth:s}=e;return t.lineWidth=s,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",i)}_setFillStyles(t,e){let{fill:i}=e;return this.handleFiller(t,"fillStyle",i)}_renderChar(t,e,i,s,r,n,o){const a=this._getStyleDeclaration(i,s),h=this.getCompleteStyleDeclaration(i,s),c="fillText"===t&&h.fill,l="strokeText"===t&&h.stroke&&h.strokeWidth;if(l||c){if(e.save(),e.font=this._getFontDeclaration(h),a.textBackgroundColor&&this._removeShadow(e),a.deltaY&&(o+=a.deltaY),c){const t=this._setFillStyles(e,h);e.fillText(r,n-t.offsetX,o-t.offsetY)}if(l){const t=this._setStrokeStyles(e,h);e.strokeText(r,n-t.offsetX,o-t.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,i){const s=this.get2DCursorLocation(t,!0),r=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"fontSize"),n=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"deltaY"),o={fontSize:r*i.size,deltaY:n+r*i.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),i=this.width-e,s=this.textAlign,r=this.direction,n=this.isEndOfWrapping(t);let o=0;return s===zn||s===Nn&&!n||s===Un&&!n||s===Hn&&!n?0:(s===P&&(o=i/2),s===F&&(o=i),s===Nn&&(o=i/2),s===Un&&(o=i),"rtl"===r&&(s===F||s===zn||s===Un?o=0:s===A||s===Hn?o=-i:s!==P&&s!==Nn||(o=-i/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,i){var s;return null!==(s=this._getStyleDeclaration(t,e)[i])&&void 0!==s?s:this[i]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let i=this._getTopOffset();const s=this._getLeftOffset(),r=this.path,n=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let a=0,h=this._textLines.length;a<h;a++){const h=this.getHeightOfLine(a);if(!this[e]&&!this.styleHas(e,a)){i+=h;continue}const c=this._textLines[a],l=h/this.lineHeight,d=this._getLineLeftOffset(a);let u,g,f=0,p=0,m=this.getValueOfPropertyAt(a,0,e),v=this.getValueOfPropertyAt(a,0,"fill");const _=i+l*(1-this._fontSizeFraction);let y=this.getHeightOfChar(a,0),x=this.getValueOfPropertyAt(a,0,"deltaY");for(let i=0,n=c.length;i<n;i++){const n=this.__charBounds[a][i];u=this.getValueOfPropertyAt(a,i,e),g=this.getValueOfPropertyAt(a,i,"fill");const h=this.getHeightOfChar(a,i),c=this.getValueOfPropertyAt(a,i,"deltaY");if(r&&u&&g)t.save(),t.fillStyle=v,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,o*h+c,n.kernedWidth,this.fontSize/15),t.restore();else if((u!==m||g!==v||h!==y||c!==x)&&p>0){let e=s+d+f;"rtl"===this.direction&&(e=this.width-e-p),m&&v&&(t.fillStyle=v,t.fillRect(e,_+o*y+x,p,this.fontSize/15)),f=n.left,p=n.width,m=u,v=g,y=h,x=c}else p+=n.kernedWidth}let C=s+d+f;"rtl"===this.direction&&(C=this.width-C-p),t.fillStyle=g,u&&g&&t.fillRect(C,_+o*y+x,p-n,this.fontSize/15),i+=h}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:i=this.fontWeight,fontSize:s=this.fontSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;const n=t.includes("'")||t.includes('"')||t.includes(",")||to.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,i,"".concat(r?this.CACHE_FONT_SIZE:s,"px"),n].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return rr(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),i=new Array(e.length),s=["\n"];let r=[];for(let t=0;t<e.length;t++)i[t]=this.graphemeSplit(e[t]),r=r.concat(i[t],s);return r.pop(),{_unwrappedLines:i,lines:e,graphemeText:r,graphemeLines:i}}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return i(i({},super.toObject([...Wn,...t])),{},{styles:$s(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:i}=this.constructor;super.set(t,e);let s=!1,r=!1;if("object"==typeof t)for(const e in t)"path"===e&&this.setPathInfo(),s=s||i.includes(e),r=r||"path"===e;else s=i.includes(t),r="path"===t;return r&&this.setPathInfo(),s&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const n=Ys(t,to.ATTRIBUTE_NAMES,s),o=i(i({},e),n),{textAnchor:a=A,textDecoration:h="",dx:c=0,dy:l=0,top:d=0,left:u=0,fontSize:g=D,strokeWidth:f=1}=o,p=r(o,Qn),m=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),i({left:u+c,top:d+l,underline:h.includes("underline"),overline:h.includes("overline"),linethrough:h.includes("line-through"),strokeWidth:0,fontSize:g},p)),v=m.getScaledHeight()/m.height,_=((m.height+m.strokeWidth)*m.lineHeight-m.height)*v,y=m.getScaledHeight()+_;let x=0;return a===P&&(x=m.getScaledWidth()/2),a===F&&(x=m.getScaledWidth()),m.set({left:m.left-x,top:m.top-(y-m.fontSize*(.07+m._fontSizeFraction))/m.lineHeight,strokeWidth:f}),m}static fromObject(t){return this._fromObject(i(i({},t),{},{styles:tr(t.styles||{},t.text)}),{extraParam:"text"})}}s(to,"textLayoutProperties",Yn),s(to,"cacheProperties",[...gi,...Wn]),s(to,"ownDefaults",Gn),s(to,"type","Text"),s(to,"genericFonts",["sans-serif","serif","cursive","fantasy","monospace"]),s(to,"ATTRIBUTE_NAMES",Qi.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Ki(to,[class extends Oe{_toSVG(){const t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(t){let{textBgRects:e,textSpans:i}=t;const s=this.getSvgTextDecoration(this);return[e.join(""),'\t\t<text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(Jn,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"","rtl"===this.direction?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",i.join(""),"</text>\n"]}_getSVGTextAndBg(t,e){const i=[],s=[];let r,n=t;this.backgroundColor&&s.push(...Zn(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let t=0,o=this._textLines.length;t<o;t++)r=this._getLineLeftOffset(t),"rtl"===this.direction&&(r+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",t))&&this._setSVGTextLineBg(s,t,e+r,n),this._setSVGTextLineText(i,t,e+r,n),n+=this.getHeightOfLine(t);return{textSpans:i,textBgRects:s}}_createTextCharSpan(t,e,i,s){const r=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(Kn)),n=r?'style="'.concat(r,'"'):"",o=e.deltaY,a=o?' dy="'.concat(Et(o,h.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(Et(i,h.NUM_FRACTION_DIGITS),'" y="').concat(Et(s,h.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(sr(t),"</tspan>")}_setSVGTextLineText(t,e,i,s){const r=this.getHeightOfLine(e),n=this.textAlign.includes(zn),o=this._textLines[e];let a,h,c,l,d,u="",g=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let r=0,f=o.length-1;r<=f;r++)d=r===f||this.charSpacing,u+=o[r],c=this.__charBounds[e][r],0===g?(i+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(o[r])&&(d=!0),d||(a=a||this.getCompleteStyleDeclaration(e,r),h=this.getCompleteStyleDeclaration(e,r+1),d=Qs(a,h,!0)),d&&(l=this._getStyleDeclaration(e,r),t.push(this._createTextCharSpan(u,l,i,s)),u="",a=h,"rtl"===this.direction?i-=g:i+=g,g=0)}_setSVGTextLineBg(t,e,i,s){const r=this._textLines[e],n=this.getHeightOfLine(e)/this.lineHeight;let o,a=0,h=0,c=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let l=0;l<r.length;l++){const{left:r,width:d,kernedWidth:u}=this.__charBounds[e][l];o=this.getValueOfPropertyAt(e,l,"textBackgroundColor"),o!==c?(c&&t.push(...Zn(c,i+h,s,a,n)),h=r,a=d,c=o):a+=u}o&&t.push(...Zn(c,i+h,s,a,n))}_getSVGLineTopOffset(t){let e,i=0;for(e=0;e<t;e++)i+=this.getHeightOfLine(e);const s=this.getHeightOfLine(e);return{lineTop:i,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(t){return"".concat(super.getSvgStyles(t)," white-space: pre;")}getSvgSpanStyles(t,e){const{fontFamily:i,strokeWidth:s,stroke:r,fill:n,fontSize:o,fontStyle:a,fontWeight:h,deltaY:c}=t,l=this.getSvgTextDecoration(t);return[r?Rt("stroke",r):"",s?"stroke-width: ".concat(s,"; "):"",i?"font-family: ".concat(i.includes("'")||i.includes('"')?i:"'".concat(i,"'"),"; "):"",o?"font-size: ".concat(o,"px; "):"",a?"font-style: ".concat(a,"; "):"",h?"font-weight: ".concat(h,"; "):"",l?"text-decoration: ".concat(l,"; "):l,n?Rt("fill",n):"",c?"baseline-shift: ".concat(-c,"; "):"",e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter((e=>t[e.replace("-","")])).join(" ")}}]),X.setClass(to),X.setSVGClass(to);class eo{constructor(t){s(this,"target",void 0),s(this,"__mouseDownInPlace",!1),s(this,"__dragStartFired",!1),s(this,"__isDraggingOver",!1),s(this,"__dragStartSelection",void 0),s(this,"__dragImageDisposer",void 0),s(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach((t=>t())),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,i=e.getSelectionStartFromPointer(t);return e.isEditing&&i>=e.selectionStart&&i<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var i;let{selectionStart:s,selectionEnd:r}=e;const n=this.target,o=n.canvas,a=new N(n.flipX?-1:1,n.flipY?-1:1),h=n._getCursorBoundaries(s),c=new N(h.left+h.leftOffset,h.top+h.topOffset).multiply(a).transform(n.calcTransformMatrix()),l=o.getPointer(t).subtract(c),d=o._isRetinaScaling(),u=n.getCanvasRetinaScaling(),g=n.getBoundingRect(!0),f=c.subtract(new N(g.left,g.top)),p=o.viewportTransform,m=f.add(l).transform(p,!0),v=n.backgroundColor,_=di(n.styles);n.backgroundColor="";const y={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};n.setSelectionStyles(y,0,s),n.setSelectionStyles(y,r,n.text.length),n.dirty=!0;const x=n.toCanvasElement({enableRetinaScaling:d,viewportTransform:!0});n.backgroundColor=v,n.styles=_,n.dirty=!0,qt(x,{position:"fixed",left:"".concat(-x.width,"px"),border:L,width:"".concat(x.width/u,"px"),height:"".concat(x.height/u,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{x.remove()},Ut(t.target||this.target.hiddenTextarea).body.appendChild(x),null===(i=t.dataTransfer)||void 0===i||i.setDragImage(x,m.x,m.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const s=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},r=e._text.slice(s.selectionStart,s.selectionEnd).join(""),n=i({text:e.text,value:r},s);t.dataTransfer.setData("text/plain",r),t.dataTransfer.setData("application/fabric",JSON.stringify({value:r,styles:e.getSelectionStyles(s.selectionStart,s.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,n)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),i=this.__dragStartSelection;return e<i.selectionStart||e>i.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e:e}=t;const i=this.targetCanDrop(e);!this.__isDraggingOver&&i&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e:e}=t,i=this.targetCanDrop(e);!this.__isDraggingOver&&i?this.__isDraggingOver=!0:this.__isDraggingOver&&!i&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:i}=t,s=i.defaultPrevented;this.__isDraggingOver=!1,i.preventDefault();let r=null===(e=i.dataTransfer)||void 0===e?void 0:e.getData("text/plain");if(r&&!s){const e=this.target,s=e.canvas;let n=e.getSelectionStartFromPointer(i);const{styles:o}=i.dataTransfer.types.includes("application/fabric")?JSON.parse(i.dataTransfer.getData("application/fabric")):{},a=r[Math.max(0,r.length-1)],h=0;if(this.__dragStartSelection){const t=this.__dragStartSelection.selectionStart,i=this.__dragStartSelection.selectionEnd;n>t&&n<=i?n=t:n>i&&(n-=i-t),e.removeChars(t,i),delete this.__dragStartSelection}e._reNewline.test(a)&&(e._reNewline.test(e._text[n])||n===e._text.length)&&(r=r.trimEnd()),t.didDrop=!0,t.dropTarget=e,e.insertChars(r,o,n),s.setActiveObject(e),e.enterEditing(i),e.selectionStart=Math.min(n+h,e._text.length),e.selectionEnd=Math.min(e.selectionStart+r.length,e._text.length),e.hiddenTextarea.value=e.text,e._updateTextarea(),e.hiddenTextarea.focus(),e.fire("changed",{index:n+h,action:"drop"}),s.fire("text:changed",{target:e}),s.contextTopDirty=!0,s.requestRenderAll()}}dragEndHandler(t){let{e:e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var i;const t=this.target,s=this.target.canvas,{selectionStart:r,selectionEnd:n}=this.__dragStartSelection,o=(null===(i=e.dataTransfer)||void 0===i?void 0:i.dropEffect)||L;o===L?(t.selectionStart=r,t.selectionEnd=n,t._updateTextarea(),t.hiddenTextarea.focus()):(t.clearContextTop(),"move"===o&&(t.removeChars(r,n),t.selectionStart=t.selectionEnd=r,t.hiddenTextarea&&(t.hiddenTextarea.value=t.text),t._updateTextarea(),t.fire("changed",{index:r,action:"dragend"}),s.fire("text:changed",{target:t}),s.requestRenderAll()),t.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const io=/[ \n\.,;!\?\-]/;class so extends to{constructor(){super(...arguments),s(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:i,delay:s,onComplete:r}=t;return He({startValue:this._currentCursorOpacity,endValue:e,duration:i,delay:s,onComplete:r,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:t=>{this._currentCursorOpacity=t,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:1,duration:this.cursorDuration,delay:t,onComplete:this._onTickComplete})}_onTickComplete(){var t;null===(t=this._currentTickCompleteState)||void 0===t||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:100,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,i=t-1;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i--;for(;/\S/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findWordBoundaryRight(t){let e=0,i=t;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i++;for(;/\S/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}findLineBoundaryLeft(t){let e=0,i=t-1;for(;!/\n/.test(this._text[i])&&i>-1;)e++,i--;return t-e}findLineBoundaryRight(t){let e=0,i=t;for(;!/\n/.test(this._text[i])&&i<this._text.length;)e++,i++;return t+e}searchWordBoundary(t,e){const i=this._text;let s=t>0&&this._reSpace.test(i[t])&&(-1===e||!R.test(i[t-1]))?t-1:t,r=i[s];for(;s>0&&s<i.length&&!io.test(r);)s+=e,r=i[s];return-1===e&&io.test(r)&&s++,s}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),i=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ut(e).activeElement!==e&&e.focus();const i=this.getSelectionStartFromPointer(t),s=this.selectionStart,r=this.selectionEnd;(i===this.__selectionStartOnMouseDown&&s!==r||s!==i&&r!==i)&&(i>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=i):(this.selectionStart=i,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===s&&this.selectionEnd===r||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,i){const s=i.slice(0,t),r=this.graphemeSplit(s).length;if(t===e)return{selectionStart:r,selectionEnd:r};const n=i.slice(t,e);return{selectionStart:r,selectionEnd:r+this.graphemeSplit(n).length}}fromGraphemeToStringSelection(t,e,i){const s=i.slice(0,t).join("").length;if(t===e)return{selectionStart:s,selectionEnd:s};return{selectionStart:s,selectionEnd:s+i.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),i=this.get2DCursorLocation(t),s=i.lineIndex,r=i.charIndex,n=this.getValueOfPropertyAt(s,r,"fontSize")*this.lineHeight,o=e.leftOffset,a=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,c=h.width/a,l=h.height/a,d=c-n,u=l-n,g=new N(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new N(h.clientWidth/c,h.clientHeight/l));return g.x<0&&(g.x=0),g.x>d&&(g.x=d),g.y<0&&(g.y=0),g.y>u&&(g.y=u),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:i,charIndex:s}=this.get2DCursorLocation(t,!0),{lineIndex:r,charIndex:n}=this.get2DCursorLocation(e,!0);if(i!==r){if(this.styles[i])for(let t=s;t<this._unwrappedTextLines[i].length;t++)delete this.styles[i][t];if(this.styles[r])for(let t=n;t<this._unwrappedTextLines[r].length;t++){const e=this.styles[r][t];e&&(this.styles[i]||(this.styles[i]={}),this.styles[i][s+t-n]=e)}for(let t=i+1;t<=r;t++)delete this.styles[t];this.shiftLineStyles(r,i-r)}else if(this.styles[i]){const t=this.styles[i],e=n-s;for(let e=s;e<n;e++)delete t[e];for(const s in this.styles[i]){const i=parseInt(s,10);i>=n&&(t[i-e]=t[s],delete t[s])}}}shiftLineStyles(t,e){const i=Object.assign({},this.styles);for(const s in this.styles){const r=parseInt(s,10);r>t&&(this.styles[r+e]=i[r],i[r-e]||delete this.styles[r])}}insertNewlineStyleObject(t,e,s,r){const n={},o=this._unwrappedTextLines[t].length===e;let a=!1;s||(s=1),this.shiftLineStyles(t,s);const h=this.styles[t]?this.styles[t][0===e?e:e-1]:void 0;for(const i in this.styles[t]){const s=parseInt(i,10);s>=e&&(a=!0,n[s-e]=this.styles[t][i],o&&0===e||delete this.styles[t][i])}let c=!1;for(a&&!o&&(this.styles[t+s]=n,c=!0),c&&s--;s>0;)r&&r[s-1]?this.styles[t+s]={0:i({},r[s-1])}:h?this.styles[t+s]={0:i({},h)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,r){this.styles||(this.styles={});const n=this.styles[t],o=n?i({},n):{};s||(s=1);for(const t in o){const i=parseInt(t,10);i>=e&&(n[i+s]=o[i],o[i-s]||delete n[i])}if(this._forceClearCache=!0,r){for(;s--;)Object.keys(r[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=i({},r[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=i({},a)}insertNewStyleBlock(t,e,i){const s=this.get2DCursorLocation(e,!0),r=[0];let n,o=0;for(let e=0;e<t.length;e++)"\n"===t[e]?(o++,r[o]=0):r[o]++;for(r[0]>0&&(this.insertCharStyleObject(s.lineIndex,s.charIndex,r[0],i),i=i&&i.slice(r[0]+1)),o&&this.insertNewlineStyleObject(s.lineIndex,s.charIndex+r[0],o),n=1;n<o;n++)r[n]>0?this.insertCharStyleObject(s.lineIndex+n,0,r[n],i):i&&this.styles[s.lineIndex+n]&&i[0]&&(this.styles[s.lineIndex+n][0]=i[0]),i=i&&i.slice(r[n]+1);r[n]>0&&this.insertCharStyleObject(s.lineIndex+n,0,r[n],i)}removeChars(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:i;s>i&&this.removeStyleFromTo(i,s);const r=this.graphemeSplit(t);this.insertNewStyleBlock(r,i,e),this._text=[...this._text.slice(0,i),...r,...this._text.slice(s)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,i){i<=t?(e===t?this._selectionDirection=A:this._selectionDirection===F&&(this._selectionDirection=A,this.selectionEnd=t),this.selectionStart=i):i>t&&i<e?this._selectionDirection===F?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection=F:this._selectionDirection===A&&(this._selectionDirection=F,this.selectionStart=e),this.selectionEnd=i)}}class ro extends so{initHiddenTextarea(){const t=this.canvas&&Ut(this.canvas.getElement())||y(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map((t=>{let[i,s]=t;return e.setAttribute(i,s)}));const{top:i,left:s,fontSize:r}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(i,"; left: ").concat(s,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(r,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",onCompositionUpdate:"onCompositionEnd"}).map((t=>{let[i,s]=t;return e.addEventListener(i,this[s].bind(this))})),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e="rtl"===this.direction?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const i=()=>{this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void i();const s=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,r=this._text.length,n=s.length,o=this.selectionStart,a=this.selectionEnd,c=o!==a;let l,d,u,g,f=n-r;const p=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),m=o>p.selectionStart;c?(d=this._text.slice(o,a),f+=a-o):n<r&&(d=m?this._text.slice(a+f,a):this._text.slice(o,o-f));const v=s.slice(p.selectionEnd-f,p.selectionEnd);if(d&&d.length&&(v.length&&(l=this.getSelectionStyles(o,o+1,!1),l=v.map((()=>l[0]))),c?(u=o,g=a):m?(u=a-d.length,g=a):(u=a,g=a+d.length),this.removeStyleFromTo(u,g)),v.length){const{copyPasteData:t}=_();e&&v.join("")===t.copiedText&&!h.disableStyleCopyPaste&&(l=t.copiedTextStyle),this.insertNewStyleBlock(v,o,l)}i()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:i,selectionEnd:s}=e;this.compositionStart=i,this.compositionEnd=s,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=_();t.copiedText=this.getSelectedText(),h.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let i,s=this._getLineLeftOffset(t);return e>0&&(i=this.__charBounds[t][e-1],s+=i.left+i.width),s}getDownCursorOffset(t,e){const i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(r===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-i;const n=s.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r+1,o);return this._textLines[r].slice(n).length+a+1+this.missingNewlineOffset(r)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const i=this._getSelectionForOffset(t,e),s=this.get2DCursorLocation(i),r=s.lineIndex;if(0===r||t.metaKey||33===t.keyCode)return-i;const n=s.charIndex,o=this._getWidthBeforeCursor(r,n),a=this._getIndexOnLine(r-1,o),h=this._textLines[r].slice(0,n),c=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+a-h.length+(1-c)}_getIndexOnLine(t,e){const i=this._textLines[t];let s,r,n=this._getLineLeftOffset(t),o=0;for(let a=0,h=i.length;a<h;a++)if(s=this.__charBounds[t][a].width,n+=s,n>e){r=!0;const t=n-s,i=n,h=Math.abs(t-e);o=Math.abs(i-e)<h?a:a-1;break}return r||(o=i.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const i=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===F);if(e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i){const t=this.text.length;this.selectionStart=Xe(0,this.selectionStart,t),this.selectionEnd=Xe(0,this.selectionEnd,t),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===A?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),0!==t}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t}moveCursorLeft(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorLeftOrRight("Left",t)}_move(t,e,i){let s;if(t.altKey)s=this["findWordBoundary".concat(i)](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===i?-1:1,!0;s=this["findLineBoundary".concat(i)](this[e])}return void 0!==s&&this[e]!==s&&(this[e]=s,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=A,this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===F&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection=A,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const i="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[i](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===A&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=F,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=F,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}function no(t){return t.button&&1!==t.button}class oo extends ro{constructor(){super(...arguments),s(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new eo(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),re(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e:e}=t;this.canvas&&this.editable&&!no(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e:e}=t;this.canvas&&this.editable&&!no(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e:e,transform:i,button:s}=t;const r=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const t=this.canvas._activeObject;if(t&&t!==this)return}!this.editable||this.group&&!this.group.interactive||i&&i.actionPerformed||no(e)||r||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),i=this.selectionStart,s=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(i,s,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getPointer(t).transform(ht(this.calcTransformMatrix())).add(new N(-this._getLeftOffset(),-this._getTopOffset()));let i=0,s=0,r=0;for(let t=0;t<this._textLines.length&&i<=e.y;t++)i+=this.getHeightOfLine(t),r=t,t>0&&(s+=this._textLines[t-1].length+this.missingNewlineOffset(t-1));let n=Math.abs(this._getLineLeftOffset(r));const o=this._textLines[r].length,a=this.__charBounds[r];for(let t=0;t<o;t++){const i=n+a[t].kernedWidth;if(e.x<=i){Math.abs(e.x-i)<=Math.abs(e.x-n)&&s++;break}n=i,s++}return Math.min(this.flipX?o-s:s,this._text.length)}}const ao="moveCursorUp",ho="moveCursorDown",co="moveCursorLeft",lo="moveCursorRight",uo="exitEditing",go={selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1,keysMap:{9:uo,27:uo,33:ao,34:ho,35:lo,36:co,37:co,38:ao,39:lo,40:ho},keysMapRtl:{9:uo,27:uo,33:ao,34:ho,35:co,36:lo,37:lo,38:ao,39:co,40:ho},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}};class fo extends oo{static getDefaults(){return i(i({},super.getDefaults()),fo.ownDefaults)}get type(){const t=super.type;return"itext"===t?"i-text":t}constructor(t,e){super(t,e),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof tn&&this.canvas.textEditingManager.remove(this),e instanceof tn&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart||0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionEnd,i=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,i)}setSelectionStyles(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.selectionStart||0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,i)}get2DCursorLocation(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const i=super.toCanvasElement(t);return this.isEditing=e,i}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const i=this._getLeftOffset(),s=this._getTopOffset(),r=this._getCursorBoundariesOffsets(t,e);return{left:i,top:s,leftOffset:r.left,topOffset:r.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,i=0;const{charIndex:s,lineIndex:r}=this.get2DCursorLocation(t);for(let t=0;t<r;t++)e+=this.getHeightOfLine(t);const n=this._getLineLeftOffset(r),o=this.__charBounds[r][s];o&&(i=o.left),0!==this.charSpacing&&s===this._textLines[r].length&&(i-=this._getWidthOfCharSpacing());const a={top:e,left:n+(i>0?i:0)};return"rtl"===this.direction&&(this.textAlign===F||this.textAlign===zn||this.textAlign===Un?a.left*=-1:this.textAlign===A||this.textAlign===Hn?a.left=n-(i>0?i:0):this.textAlign!==P&&this.textAlign!==Nn||(a.left=n-(i>0?i:0))),a}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,i){const s=this.get2DCursorLocation(i),r=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,o=this.getValueOfPropertyAt(r,n,"fontSize"),a=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/a,c=this.getValueOfPropertyAt(r,n,"deltaY"),l=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(r)/this.lineHeight-o*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(r,n,"fill"),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-h/2,l+e.top+c,h,o)}renderSelection(t,e){const i={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,i,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,i){const s=e.selectionStart,r=e.selectionEnd,n=this.textAlign.includes(zn),o=this.get2DCursorLocation(s),a=this.get2DCursorLocation(r),h=o.lineIndex,c=a.lineIndex,l=o.charIndex<0?0:o.charIndex,d=a.charIndex<0?0:a.charIndex;for(let e=h;e<=c;e++){const s=this._getLineLeftOffset(e)||0;let r=this.getHeightOfLine(e),o=0,a=0,u=0;if(e===h&&(a=this.__charBounds[h][l].left),e>=h&&e<c)u=n&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===c)if(0===d)u=this.__charBounds[c][d].left;else{const t=this._getWidthOfCharSpacing();u=this.__charBounds[c][d-1].left+this.__charBounds[c][d-1].width-t}o=r,(this.lineHeight<1||e===c&&this.lineHeight>1)&&(r/=this.lineHeight);let g=i.left+s+a,f=r,p=0;const m=u-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",f=1,p=r):t.fillStyle=this.selectionColor,"rtl"===this.direction&&(this.textAlign===F||this.textAlign===zn||this.textAlign===Un?g=this.width-g-m:this.textAlign===A||this.textAlign===Hn?g=i.left+s-u:this.textAlign!==P&&this.textAlign!==Nn||(g=i.left+s-u)),t.fillRect(g,i.top+i.topOffset+p,m,f),i.topOffset+=o}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fill")}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}s(fo,"ownDefaults",go),s(fo,"type","IText"),X.setClass(fo),X.setClass(fo,"i-text");class po extends fo{static getDefaults(){return i(i({},super.getDefaults()),{},{controls:Ni()},po.ownDefaults)}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(zn)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,i=0,s=0;const r={};for(let n=0;n<t.graphemeLines.length;n++)"\n"===t.graphemeText[s]&&n>0?(i=0,s++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[s])&&n>0&&(i++,s++),r[n]={line:e,offset:i},s+=t.graphemeLines[n].length,i+=t.graphemeLines[n].length;return r}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const t=this._styleMap[e];t&&(e=t.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,i=0,s=t+1,r=!1;const n=this._styleMap[t],o=this._styleMap[t+1];n&&(t=n.line,i=n.offset),o&&(s=o.line,r=s===t,e=o.offset);const a=void 0===t?this.styles:{line:this.styles[t]};for(const t in a)for(const s in a[t]){const n=parseInt(s,10);if(n>=i&&(!r||n<e))for(const e in a[t][s])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const i=this._styleMap[t];if(!i)return{};t=i.line,e=i.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,i){const s=this._styleMap[t];t=s.line,e=s.offset+e,this.styles[t][e]=i}_deleteStyleDeclaration(t,e){const i=this._styleMap[t];t=i.line,e=i.offset+e,delete this.styles[t][e]}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];this.styles[e.line]={}}_wrapText(t,e){this.isWrapping=!0;const i=this.getGraphemeDataForRender(t),s=[];for(let t=0;t<i.wordsData.length;t++)s.push(...this._wrapLine(t,e,i));return this.isWrapping=!1,s}getGraphemeDataForRender(t){const e=this.splitByGrapheme,i=e?"":" ";let s=0;return{wordsData:t.map(((t,r)=>{let n=0;const o=e?this.graphemeSplit(t):this.wordSplit(t);return 0===o.length?[{word:[],width:0}]:o.map((t=>{const o=e?[t]:this.graphemeSplit(t),a=this._measureWord(o,r,n);return s=Math.max(a,s),n+=o.length+i.length,{word:o,width:a}}))})),largestWordWidth:s}}_measureWord(t,e){let i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=0;for(let n=0,o=t.length;n<o;n++){r+=this._getGraphemeBox(t[n],e,n+s,i,true).kernedWidth,i=t[n]}return r}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,i){let{largestWordWidth:s,wordsData:r}=i,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=this._getWidthOfCharSpacing(),a=this.splitByGrapheme,h=[],c=a?"":" ";let l=0,d=[],u=0,g=0,f=!0;e-=n;const p=Math.max(e,s,this.dynamicMinWidth),m=r[t];let v;for(u=0,v=0;v<m.length;v++){const{word:e,width:i}=m[v];u+=e.length,l+=g+i-o,l>p&&!f?(h.push(d),d=[],l=i,f=!0):l+=o,f||a||d.push(c),d=d.concat(e),g=a?0:this._measureWord([c],t,u),u++,f=!1}return v&&h.push(d),s+n>this.dynamicMinWidth&&(this.dynamicMinWidth=s-o+n),h}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),i=this._wrapText(e.lines,this.width),s=new Array(i.length);for(let t=0;t<i.length;t++)s[t]=i[t].join("");return e.lines=s,e.graphemeLines=i,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const i=parseInt(e,10);if(this._textLines[i]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}s(po,"type","Textbox"),s(po,"textLayoutProperties",[...fo.textLayoutProperties,"width"]),s(po,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),X.setClass(po);class mo{constructor(){s(this,"resources",{})}applyFilters(t,e,i,s,r){const n=r.getContext("2d");if(!n)return;n.drawImage(e,0,0,i,s);const o={sourceWidth:i,sourceHeight:s,imageData:n.getImageData(0,0,i,s),originalEl:e,originalImageData:n.getImageData(0,0,i,s),canvasEl:r,ctx:n,filterBackend:this};t.forEach((t=>{t.applyTo(o)}));const{imageData:a}=o;return a.width===i&&a.height===s||(r.width=a.width,r.height=a.height),n.putImageData(a,0,0),o}}class vo{constructor(){let{tileSize:t=h.textureSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),s(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e),this.chooseFastestCopyGLTo2DMethod(t,e)}chooseFastestCopyGLTo2DMethod(t,e){const i=et(),s=new ArrayBuffer(t*e*4);if(h.forceGLPutImageData)return this.imageBuffer=s,void(this.copyGLTo2D=_o);const r={imageBuffer:s},n={destinationWidth:t,destinationHeight:e,targetCanvas:i};let o;i.width=t,i.height=e,o=x().performance.now(),this.copyGLTo2D.call(r,this.gl,n);const a=x().performance.now()-o;o=x().performance.now(),_o.call(r,this.gl,n);a>x().performance.now()-o&&(this.imageBuffer=s,this.copyGLTo2D=_o)}createWebGLCanvas(t,e){const i=et();i.width=t,i.height=e;const s=i.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});s&&(s.clearColor(0,0,0,0),this.canvas=i,this.gl=s)}applyFilters(t,e,i,s,r,n){const o=this.gl,a=r.getContext("2d");if(!o||!a)return;let h;n&&(h=this.getCachedTexture(n,e));const c={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:i,sourceHeight:s,destinationWidth:i,destinationHeight:s,context:o,sourceTexture:this.createTexture(o,i,s,h?void 0:e),targetTexture:this.createTexture(o,i,s),originalTexture:h||this.createTexture(o,i,s,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:r},l=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,l),t.forEach((t=>{t&&t.applyTo(c)})),function(t){const e=t.targetCanvas,i=e.width,s=e.height,r=t.destinationWidth,n=t.destinationHeight;i===r&&s===n||(e.width=r,e.height=n)}(c),this.copyGLTo2D(o,c),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(c.sourceTexture),o.deleteTexture(c.targetTexture),o.deleteFramebuffer(l),a.setTransform(1,0,0,1,0,0),c}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,i,s,r){const{NEAREST:n,TEXTURE_2D:o,RGBA:a,UNSIGNED_BYTE:h,CLAMP_TO_EDGE:c,TEXTURE_MAG_FILTER:l,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:u,TEXTURE_WRAP_T:g}=t,f=t.createTexture();return t.bindTexture(o,f),t.texParameteri(o,l,r||n),t.texParameteri(o,d,r||n),t.texParameteri(o,u,c),t.texParameteri(o,g,c),s?t.texImage2D(o,0,a,a,h,s):t.texImage2D(o,0,a,e,i,0,a,h,null),f}getCachedTexture(t,e,i){const{textureCache:s}=this;if(s[t])return s[t];{const r=this.createTexture(this.gl,e.width,e.height,e,i);return r&&(s[t]=r),r}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const i=t.canvas,s=e.targetCanvas,r=s.getContext("2d");if(!r)return;r.translate(0,s.height),r.scale(1,-1);const n=i.height-s.height;r.drawImage(i,0,n,s.width,s.height,0,0,s.width,s.height)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const i=t.getExtension("WEBGL_debug_renderer_info");if(i){const s=t.getParameter(i.UNMASKED_RENDERER_WEBGL),r=t.getParameter(i.UNMASKED_VENDOR_WEBGL);s&&(e.renderer=s.toLowerCase()),r&&(e.vendor=r.toLowerCase())}return this.gpuInfo=e,e}}function _o(t,e){const i=e.targetCanvas.getContext("2d"),s=e.destinationWidth,r=e.destinationHeight,n=s*r*4;if(!i)return;const o=new Uint8Array(this.imageBuffer,0,n),a=new Uint8ClampedArray(this.imageBuffer,0,n);t.readPixels(0,0,s,r,t.RGBA,t.UNSIGNED_BYTE,o);const h=new ImageData(a,s,r);i.putImageData(h,0,0)}let yo;function xo(){const{WebGLProbe:t}=_();return t.queryWebGL(et()),h.enableGLFiltering&&t.isSupported(h.textureSize)?new vo({tileSize:h.textureSize}):new mo}function Co(){return!yo&&(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(yo=xo()),yo}const bo=["filters","resizeFilter","src","crossOrigin"],So=["cropX","cropY"];class wo extends Ji{static getDefaults(){return i(i({},super.getDefaults()),wo.ownDefaults)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(i({filters:[]},e)),s(this,"_lastScaleX",1),s(this,"_lastScaleY",1),s(this,"_filterScalingX",1),s(this,"_filterScalingY",1),this.cacheKey="texture".concat(tt()),this.setElement("string"==typeof t?(this.canvas&&Ut(this.canvas.getElement())||y()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(e),t.classList.add(wo.CSS_CANVAS),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Co(!1);e instanceof vo&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach((t=>{const e=this[t];e&&_().dispose(e),this[t]=void 0}))}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||0===this.strokeWidth)return;const e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,-i),t.lineTo(e,-i),t.lineTo(e,i),t.lineTo(-e,i),t.lineTo(-e,-i),t.closePath()}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=[];return this.filters.forEach((t=>{t&&e.push(t.toObject())})),i(i({},super.toObject([...So,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,i=-this.width/2,s=-this.height/2;let r=[],n=[],o="",a="";if(!e)return[];if(this.hasCrop()){const t=tt();r.push('<clipPath id="imageCrop_'+t+'">\n','\t<rect x="'+i+'" y="'+s+'" width="'+this.width+'" height="'+this.height+'" />\n',"</clipPath>\n"),o=' clip-path="url(#imageCrop_'+t+')" '}if(this.imageSmoothing||(a=' image-rendering="optimizeSpeed"'),t.push("\t<image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(i-this.cropX,'" y="').concat(s-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(a).concat(o,"></image>\n")),this.stroke||this.strokeDashArray){const t=this.fill;this.fill=null,n=['\t<rect x="'.concat(i,'" y="').concat(s,'" width="').concat(this.width,'" height="').concat(this.height,'" styles="').concat(this.getSvgStyles(),'" />\n')],this.fill=t}return r="fill"!==this.paintFirst?r.concat(n,t):r.concat(t,n),r}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return xt(t,{crossOrigin:e,signal:i}).then((t=>{void 0!==e&&this.set({crossOrigin:e}),this.setElement(t)}))}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,i=this.getTotalObjectScaling(),s=i.x,r=i.y,n=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||s>e&&r>e)return this._element=n,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=s,void(this._lastScaleY=r);const o=et(),a=n.width,h=n.height;o.width=a,o.height=h,this._element=o,this._lastScaleX=t.scaleX=s,this._lastScaleY=t.scaleY=r,Co().applyFilters([t],n,a,h,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.filters||[];if(t=t.filter((t=>t&&!t.isNeutralState())),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),0===t.length)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,i=e.naturalWidth||e.width,s=e.naturalHeight||e.height;if(this._element===this._originalElement){const t=et();t.width=i,t.height=s,this._element=t,this._filteredEl=t}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,i,s),this._lastScaleX=1,this._lastScaleY=1);Co().applyFilters(t,this._originalElement,i,s,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const i=this._filterScalingX,s=this._filterScalingY,r=this.width,n=this.height,o=Math.max(this.cropX,0),a=Math.max(this.cropY,0),h=e.naturalWidth||e.width,c=e.naturalHeight||e.height,l=o*i,d=a*s,u=Math.min(r*i,h-l),g=Math.min(n*s,c-d),f=-r/2,p=-n/2,m=Math.min(r,h/i-o),v=Math.min(n,c/s-a);e&&t.drawImage(e,l,d,u,g,f,p,m,v)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=this.getOriginalSize();this.width=t||i.width,this.height=e||i.height}parsePreserveAspectRatioAttribute(){const t=Ft(this.preserveAspectRatio||""),e=this.width,i=this.height,s={width:e,height:i};let r,n=this._element.width,o=this._element.height,a=1,h=1,c=0,l=0,d=0,u=0;return!t||t.alignX===L&&t.alignY===L?(a=e/n,h=i/o):("meet"===t.meetOrSlice&&(a=h=er(this._element,s),r=(e-n*a)/2,"Min"===t.alignX&&(c=-r),"Max"===t.alignX&&(c=r),r=(i-o*h)/2,"Min"===t.alignY&&(l=-r),"Max"===t.alignY&&(l=r)),"slice"===t.meetOrSlice&&(a=h=ir(this._element,s),r=n-e/a,"Mid"===t.alignX&&(d=r/2),"Max"===t.alignX&&(d=r),r=o-i/h,"Mid"===t.alignY&&(u=r/2),"Max"===t.alignY&&(u=r),n=e/a,o=i/h)),{width:n,height:o,scaleX:a,scaleY:h,offsetLeft:c,offsetTop:l,cropX:d,cropY:u}}static fromObject(t){let{filters:e,resizeFilter:s,src:n,crossOrigin:o}=t,a=r(t,bo),h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Promise.all([xt(n,i(i({},h),{},{crossOrigin:o})),e&&Ct(e,h),s&&Ct([s],h),bt(a,h)]).then((t=>{let[e,s=[],[r]=[],o={}]=t;return new this(e,i(i({},a),{},{src:n,filters:s,resizeFilter:r},o))}))}static fromURL(t){let{crossOrigin:e=null,signal:i}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;return xt(t,{crossOrigin:e,signal:i}).then((t=>new this(t,s)))}static async fromElement(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;const s=Ys(t,this.ATTRIBUTE_NAMES,i);return this.fromURL(s["xlink:href"],e,s).catch((t=>(c("log","Unable to parse Image",t),null)))}}function To(t){if(!cs.test(t.nodeName))return{};const e=t.getAttribute("viewBox");let i,s,r=1,n=1,o=0,a=0;const h=t.getAttribute("width"),c=t.getAttribute("height"),l=t.getAttribute("x")||0,d=t.getAttribute("y")||0,u=!(e&&ds.test(e)),g=!h||!c||"100%"===h||"100%"===c;let f="",p=0,m=0;if(u&&(l||d)&&t.parentNode&&"#document"!==t.parentNode.nodeName&&(f=" translate("+jt(l||"0")+" "+jt(d||"0")+") ",i=(t.getAttribute("transform")||"")+f,t.setAttribute("transform",i),t.removeAttribute("x"),t.removeAttribute("y")),u&&g)return{width:0,height:0};const v={width:0,height:0};if(u)return v.width=jt(h),v.height=jt(c),v;const _=e.match(ds);o=-parseFloat(_[1]),a=-parseFloat(_[2]);const y=parseFloat(_[3]),x=parseFloat(_[4]);v.minX=o,v.minY=a,v.viewBoxWidth=y,v.viewBoxHeight=x,g?(v.width=y,v.height=x):(v.width=jt(h),v.height=jt(c),r=v.width/y,n=v.height/x);const C=Ft(t.getAttribute("preserveAspectRatio")||"");if(C.alignX!==L&&("meet"===C.meetOrSlice&&(n=r=r>n?n:r),"slice"===C.meetOrSlice&&(n=r=r>n?r:n),p=v.width-y*r,m=v.height-x*r,"Mid"===C.alignX&&(p/=2),"Mid"===C.alignY&&(m/=2),"Min"===C.alignX&&(p=0),"Min"===C.alignY&&(m=0)),1===r&&1===n&&0===o&&0===a&&0===l&&0===d)return v;if((l||d)&&"#document"!==t.parentNode.nodeName&&(f=" translate("+jt(l||"0")+" "+jt(d||"0")+") "),i=f+" matrix("+r+" 0 0 "+n+" "+(o*r+p)+" "+(a*n+m)+") ","svg"===t.nodeName){for(s=t.ownerDocument.createElementNS(ss,"g");t.firstChild;)s.appendChild(t.firstChild);t.appendChild(s)}else s=t,s.removeAttribute("x"),s.removeAttribute("y"),i=s.getAttribute("transform")+i;return s.setAttribute("transform",i),v}s(wo,"type","Image"),s(wo,"cacheProperties",[...gi,...So]),s(wo,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),s(wo,"CSS_CANVAS","canvas-img"),s(wo,"ATTRIBUTE_NAMES",[...Qi,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),X.setClass(wo),X.setSVGClass(wo);const Oo=$i(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function ko(t,e){let i,s,r,n,o=[];for(r=0,n=e.length;r<n;r++)i=e[r],s=t.getElementsByTagNameNS("http://www.w3.org/2000/svg",i),o=o.concat(Array.from(s));return o}const Do=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Mo="xlink:href";function Po(t,e){var i;const s=(null===(i=e.getAttribute(Mo))||void 0===i?void 0:i.slice(1))||"",r=t.getElementById(s);if(r&&r.getAttribute(Mo)&&Po(t,r),r&&(Do.forEach((t=>{const i=r.getAttribute(t);!e.hasAttribute(t)&&i&&e.setAttribute(t,i)})),!e.children.length)){const t=r.cloneNode(!0);for(;t.firstChild;)e.appendChild(t.firstChild)}e.removeAttribute(Mo)}const Ao=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Eo(t){const e=t.getElementsByTagName("style");let s,r;const n={};for(s=0,r=e.length;s<r;s++){const t=(e[s].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");""!==t.trim()&&t.split("}").filter((function(t){return t.trim()})).forEach((function(t){const e=t.split("{"),o={},a=e[1].trim().split(";").filter((function(t){return t.trim()}));for(s=0,r=a.length;s<r;s++){const t=a[s].split(":"),e=t[0].trim(),i=t[1].trim();o[e]=i}(t=e[0].trim()).split(",").forEach((t=>{""!==(t=t.replace(/^svg/i,"").trim())&&(n[t]=i(i({},n[t]||{}),o))}))}))}return n}const jo=t=>X.getSVGClass(t.tagName.toLowerCase().replace("svg:",""));class Fo{constructor(t,e,i,s,r){this.elements=t,this.options=e,this.reviver=i,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=s,this.clipPaths=r,this.gradientDefs=function(t){const e=ko(t,Ao),i={};let s=e.length;for(;s--;){const r=e[s];r.getAttribute("xlink:href")&&Po(t,r);const n=r.getAttribute("id");n&&(i[n]=r)}return i}(s),this.cssRules=Eo(s)}parse(){return Promise.all(this.elements.map((t=>this.createObject(t))))}async createObject(t){const e=jo(t);if(e){const i=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(i,t,"fill"),this.resolveGradient(i,t,"stroke"),i instanceof wo&&i._originalElement?Vr(i,i.parsePreserveAspectRatioAttribute()):Vr(i),await this.resolveClipPath(i,t),this.reviver&&this.reviver(t,i),i}return null}extractPropertyDefinition(t,e,i){const s=t[e],r=this.regexUrl;if(!r.test(s))return;r.lastIndex=0;const n=r.exec(s)[1];return r.lastIndex=0,i[n]}resolveGradient(t,e,s){const r=this.extractPropertyDefinition(t,s,this.gradientDefs);if(r){const n=e.getAttribute(s+"-opacity"),o=pn.fromElement(r,t,i(i({},this.options),{},{opacity:n}));t.set(s,o)}}async resolveClipPath(t,e){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const s=ht(t.calcTransformMatrix()),r=i[0].parentElement;let n=e;for(;n.parentElement&&n.getAttribute("clip-path")!==t.clipPath;)n=n.parentElement;n.parentElement.appendChild(r);const o=await Promise.all(i.map((t=>jo(t).fromElement(t,this.options,this.cssRules).then((t=>(Vr(t),t.fillRule=t.clipRule,delete t.clipRule,t)))))),a=1===o.length?o[0]:new Hs(o),h=ct(s,a.calcTransformMatrix());a.clipPath&&await this.resolveClipPath(a,n);const{scaleX:c,scaleY:l,angle:d,skewX:u,translateX:g,translateY:f}=dt(h);a.set({flipX:!1,flipY:!1}),a.set({scaleX:c,scaleY:l,angle:d,skewX:u,skewY:0}),a.setPositionByOrigin(new N(g,f),P,P),t.clipPath=a}else delete t.clipPath}}const Lo=t=>hs.test(t.nodeName.replace("svg:","")),Ro=()=>({objects:[],elements:[],options:{},allElements:[]});async function Bo(t,e){let{crossOrigin:s,signal:r}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(r&&r.aborted)return c("log",new d("parseSVGDocument")),Ro();const n=t.documentElement;!function(t){const e=ko(t,["use","svg:use"]);let i=0;for(;e.length&&i<e.length;){const s=e[i],r=s.getAttribute("xlink:href")||s.getAttribute("href");if(null===r)return;const n=r.slice(1),o=s.getAttribute("x")||0,a=s.getAttribute("y")||0,h=t.getElementById(n);if(null===h)return;let c=h.cloneNode(!0),l=(c.getAttribute("transform")||"")+" translate("+o+", "+a+")";const d=e.length,u=ss;if(To(c),/^svg$/i.test(c.nodeName)){const t=c.ownerDocument.createElementNS(u,"g");for(let e=0,i=c.attributes,s=i.length;e<s;e++){const s=i.item(e);s&&t.setAttributeNS(u,s.nodeName,s.nodeValue)}for(;c.firstChild;)t.appendChild(c.firstChild);c=t}for(let t=0,e=s.attributes,i=e.length;t<i;t++){const i=e.item(t);if(!i)continue;const{nodeName:s,nodeValue:r}=i;"x"!==s&&"y"!==s&&"xlink:href"!==s&&"href"!==s&&("transform"===s?l=r+" "+l:c.setAttribute(s,r))}c.setAttribute("transform",l),c.setAttribute("instantiated_by_use","1"),c.removeAttribute("id"),s.parentNode.replaceChild(c,s),e.length===d&&i++}}(t);const o=Array.from(n.getElementsByTagName("*")),a=i(i({},To(n)),{},{crossOrigin:s,signal:r}),h=o.filter((t=>(To(t),Lo(t)&&!function(t){let e=t;for(;e&&(e=e.parentElement);)if(e&&e.nodeName&&Oo.test(e.nodeName.replace("svg:",""))&&!e.getAttribute("instantiated_by_use"))return!0;return!1}(t))));if(!h||h&&!h.length)return i(i({},Ro()),{},{options:a,allElements:o});const l={};o.filter((t=>"clipPath"===t.nodeName.replace("svg:",""))).forEach((t=>{const e=t.getAttribute("id");l[e]=Array.from(t.getElementsByTagName("*")).filter((t=>Lo(t)))}));const u=new Fo(h,a,e,t,l);return{objects:await u.parse(),elements:h,options:a,allElements:o}}const Io=t=>function(e,i,s){var r,n;const o=s.points[t].x-s.pathOffset.x,a=s.points[t].y-s.pathOffset.y;return new N(o,a).transform(ct(null!==(r=null===(n=s.canvas)||void 0===n?void 0:n.viewportTransform)&&void 0!==r?r:k,s.calcTransformMatrix()))},Xo=(t,e,i,s)=>{const r=e.target,n=e.pointIndex,o=we(e,P,P,i,s),a=(t=>new N(t.width,t.height))(r),h=r._getTransformedDimensions(),c=a.divide(h),l=new N(r.flipX?-1:1,r.flipY?-1:1),d=o.multiply(l).multiply(c).add(r.pathOffset);return r.points[n]=d,r.setDimensions(),!0},Yo=(t,e)=>function(s,r,n,o){const a=r.target,h=new N(a.points[(t>0?t:a.points.length)-1]),c=h.subtract(a.pathOffset).transform(a.calcOwnMatrix()),l=e(s,i(i({},r),{},{pointIndex:t}),n,o),d=new N(a.flipX?-1:1,a.flipY?-1:1),u=h.subtract(a.pathOffset).divide(a._getNonTransformedDimensions()).multiply(d);return a.setPositionByOrigin(c,u.x+.5,u.y+.5),l},Wo=t=>Yo(t,Xo);var Vo=Object.freeze({__proto__:null,changeWidth:yi,createObjectDefaultControls:Hi,createPolyActionHandler:Wo,createPolyControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s={};for(let r=0;r<("number"==typeof t?t:t.points.length);r++)s["p".concat(r)]=new bi(i({actionName:"modifyPoly",positionHandler:Io(r),actionHandler:Wo(r)},e));return s},createPolyPositionHandler:Io,createResizeControls:Ui,createTextboxDefaultControls:Ni,dragHandler:Te,factoryPolyActionHandler:Yo,getLocalPoint:we,polyActionHandler:Xo,renderCircleControl:xi,renderSquareControl:Ci,rotationStyleHandler:Si,rotationWithSnapping:wi,scaleCursorStyleHandler:Di,scaleOrSkewActionName:Wi,scaleSkewCursorStyleHandler:Vi,scalingEqually:Pi,scalingX:Ai,scalingXOrSkewingY:Gi,scalingY:Ei,scalingYOrSkewingX:zi,skewCursorStyleHandler:Ri,skewHandlerX:Ii,skewHandlerY:Xi,wrapWithFireEvent:vi,wrapWithFixedAnchor:_i});const Go=t=>void 0!==t.webgl,zo="precision highp float",Ho="\n ".concat(zo,";\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }"),Uo=["type"],No=["type"];class qo{get type(){return this.constructor.type}constructor(){let t=r(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},Uo);s(this,"vertexSource","\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n void main() {\n vTexCoord = aPosition;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }"),Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Ho}createProgram(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getFragmentSource(),i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.vertexSource;const{WebGLProbe:{GLPrecision:s="highp"}}=_();"highp"!==s&&(e=e.replace(new RegExp(zo,"g"),zo.replace("highp",s)));const r=t.createShader(t.VERTEX_SHADER),n=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!r||!n||!o)throw new l("Vertex, fragment shader or program creation error");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new l("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new l("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new l('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const a=this.getUniformLocations(t,o)||{};return a.uStepW=t.getUniformLocation(o,"uStepW"),a.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:a}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){return{}}sendAttributeData(t,e,i){const s=e.aPosition,r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,i,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const i=t.destinationWidth,s=t.destinationHeight;t.sourceWidth===i&&t.sourceHeight===s||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,i,s)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){const e=this.mainParameter,i=this.constructor.defaults[e];if(e){const t=this[e];return Array.isArray(i)&&Array.isArray(t)?i.every(((e,i)=>e===t[i])):i===t}return!1}applyTo(t){Go(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,i=this.retrieveShader(t);0===t.pass&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(i.program),this.sendAttributeData(e,i.attributeLocations,t.aPosition),e.uniform1f(i.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(i.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,i.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,i){t.activeTexture(i),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}getMainParameter(){return this.mainParameter?this[this.mainParameter]:void 0}setMainParameter(t){this.mainParameter&&(this[this.mainParameter]=t)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const e=et();e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}}toObject(){const t=this.mainParameter;return i({type:this.type},t?{[t]:this[t]}:{})}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(r(t,No))}}s(qo,"type","BaseFilter");const Ko={multiply:"gl_FragColor.rgb *= uColor.rgb;\n",screen:"gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);\n",add:"gl_FragColor.rgb += uColor.rgb;\n",difference:"gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);\n",subtract:"gl_FragColor.rgb -= uColor.rgb;\n",lighten:"gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);\n",darken:"gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);\n",exclusion:"gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);\n",overlay:"\n if (uColor.r < 0.5) {\n gl_FragColor.r *= 2.0 * uColor.r;\n } else {\n gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);\n }\n if (uColor.g < 0.5) {\n gl_FragColor.g *= 2.0 * uColor.g;\n } else {\n gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);\n }\n if (uColor.b < 0.5) {\n gl_FragColor.b *= 2.0 * uColor.b;\n } else {\n gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);\n }\n ",tint:"\n gl_FragColor.rgb *= (1.0 - uColor.a);\n gl_FragColor.rgb += uColor.rgb;\n "};class Jo extends qo{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n gl_FragColor = color;\n if (color.a > 0.0) {\n ".concat(Ko[this.mode],"\n }\n }\n ")}applyTo2d(t){let{imageData:{data:e}}=t;const i=new At(this.color).getSource(),s=i[0]*this.alpha,r=i[1]*this.alpha,n=i[2]*this.alpha,o=1-this.alpha;for(let t=0;t<e.length;t+=4){const i=e[t],a=e[t+1],h=e[t+2];switch(this.mode){case"multiply":e[t]=i*s/255,e[t+1]=a*r/255,e[t+2]=h*n/255;break;case"screen":e[t]=255-(255-i)*(255-s)/255,e[t+1]=255-(255-a)*(255-r)/255,e[t+2]=255-(255-h)*(255-n)/255;break;case"add":e[t]=i+s,e[t+1]=a+r,e[t+2]=h+n;break;case"difference":e[t]=Math.abs(i-s),e[t+1]=Math.abs(a-r),e[t+2]=Math.abs(h-n);break;case"subtract":e[t]=i-s,e[t+1]=a-r,e[t+2]=h-n;break;case"darken":e[t]=Math.min(i,s),e[t+1]=Math.min(a,r),e[t+2]=Math.min(h,n);break;case"lighten":e[t]=Math.max(i,s),e[t+1]=Math.max(a,r),e[t+2]=Math.max(h,n);break;case"overlay":e[t]=s<128?2*i*s/255:255-2*(255-i)*(255-s)/255,e[t+1]=r<128?2*a*r/255:255-2*(255-a)*(255-r)/255,e[t+2]=n<128?2*h*n/255:255-2*(255-h)*(255-n)/255;break;case"exclusion":e[t]=s+i-2*s*i/255,e[t+1]=r+a-2*r*a/255,e[t+2]=n+h-2*n*h/255;break;case"tint":e[t]=s+i*o,e[t+1]=r+a*o,e[t+2]=n+h*o}}}getUniformLocations(t,e){return{uColor:t.getUniformLocation(e,"uColor")}}sendUniformData(t,e){const i=new At(this.color).getSource();i[0]=this.alpha*i[0]/255,i[1]=this.alpha*i[1]/255,i[2]=this.alpha*i[2]/255,i[3]=this.alpha,t.uniform4fv(e.uColor,i)}toObject(){return{type:this.type,color:this.color,mode:this.mode,alpha:this.alpha}}}s(Jo,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),s(Jo,"type","BlendColor"),X.setClass(Jo);const Zo={multiply:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.rgba *= color2.rgba;\n gl_FragColor = color;\n }\n ",mask:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform sampler2D uImage;\n uniform vec4 uColor;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec4 color2 = texture2D(uImage, vTexCoord2);\n color.a = color2.a;\n gl_FragColor = color;\n }\n "},Qo=["type","image"];class $o extends qo{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Zo[this.mode]}applyToWebGL(t){const e=t.context,i=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,i,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:i}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/i,1]}applyTo2d(t){let{imageData:{data:e,width:i,height:s},filterBackend:{resources:r}}=t;const n=this.image;r.blendImage||(r.blendImage=et());const o=r.blendImage,a=o.getContext("2d");o.width!==i||o.height!==s?(o.width=i,o.height=s):a.clearRect(0,0,i,s),a.setTransform(n.scaleX,0,0,n.scaleY,n.left,n.top),a.drawImage(n.getElement(),0,0,i,s);const h=a.getImageData(0,0,i,s).data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2],n=e[t+3],o=h[t],a=h[t+1],c=h[t+2],l=h[t+3];switch(this.mode){case"multiply":e[t]=i*o/255,e[t+1]=s*a/255,e[t+2]=r*c/255,e[t+3]=n*l/255;break;case"mask":e[t+3]=l}}}getUniformLocations(t,e){return{uTransformMatrix:t.getUniformLocation(e,"uTransformMatrix"),uImage:t.getUniformLocation(e,"uImage")}}sendUniformData(t,e){const i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)}toObject(){return{type:this.type,image:this.image&&this.image.toObject(),mode:this.mode,alpha:this.alpha}}static fromObject(t,e){let{type:s,image:n}=t,o=r(t,Qo);return wo.fromObject(n,e).then((t=>new this(i(i({},o),{},{image:t}))))}}s($o,"type","BlendImage"),s($o,"defaults",{mode:"multiply",alpha:1,vertexSource:"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n uniform mat3 uTransformMatrix;\n void main() {\n vTexCoord = aPosition;\n vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }\n "}),X.setClass($o);class ta extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n const float nSamples = 15.0;\n vec3 v3offset = vec3(12.9898, 78.233, 151.7182);\n float random(vec3 scale) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n }\n void main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n float offset = random(v3offset);\n for (float t = -nSamples; t <= nSamples; t++) {\n float percent = (t + offset - 0.5) / nSamples;\n float weight = 1.0 - abs(percent);\n color += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n }\n "}applyTo(t){Go(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:i,filterBackend:{resources:s}}=t;const{width:r,height:n}=i;s.blurLayer1||(s.blurLayer1=et(),s.blurLayer2=et());const o=s.blurLayer1,a=s.blurLayer2;o.width===r&&o.height===n||(a.width=o.width=r,a.height=o.height=n);const h=o.getContext("2d"),c=a.getContext("2d"),l=15,d=.06*this.blur*.5;let u,g,f,p;for(h.putImageData(i,0,0),c.clearRect(0,0,r,n),p=-15;p<=l;p++)u=(Math.random()-.5)/4,g=p/l,f=d*g*r+u,c.globalAlpha=1-Math.abs(g),c.drawImage(o,f,u),h.drawImage(a,0,0),c.globalAlpha=1,c.clearRect(0,0,a.width,a.height);for(p=-15;p<=l;p++)u=(Math.random()-.5)/4,g=p/l,f=d*g*n+u,c.globalAlpha=1-Math.abs(g),c.drawImage(o,u,f),h.drawImage(a,0,0),c.globalAlpha=1,c.clearRect(0,0,a.width,a.height);e.drawImage(o,0,0);const m=e.getImageData(0,0,o.width,o.height);return h.globalAlpha=1,h.clearRect(0,0,o.width,o.height),m}getUniformLocations(t,e){return{delta:t.getUniformLocation(e,"uDelta")}}sendUniformData(t,e){const i=this.chooseRightDelta();t.uniform2fv(e.delta,i)}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const i=t*this.blur*.12;return this.horizontal?e[0]=i:e[1]=i,e}}s(ta,"type","Blur"),s(ta,"defaults",{blur:0,mainParameter:"blur"}),X.setClass(ta);class ea extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBrightness;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += uBrightness;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.brightness)return;const i=Math.round(255*this.brightness);for(let t=0;t<e.length;t+=4)e[t]=e[t]+i,e[t+1]=e[t+1]+i,e[t+2]=e[t+2]+i}getUniformLocations(t,e){return{uBrightness:t.getUniformLocation(e,"uBrightness")}}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}s(ea,"type","Brightness"),s(ea,"defaults",{brightness:0,mainParameter:"brightness"}),X.setClass(ea);const ia=["matrix"],sa={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],mainParameter:"matrix",colorsOnly:!0};class ra extends qo{setOptions(t){let{matrix:e}=t,i=r(t,ia);e&&(this.matrix=[...e]),Object.assign(this,i)}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n uniform mat4 uColorMatrix;\n uniform vec4 uConstants;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color *= uColorMatrix;\n color += uConstants;\n gl_FragColor = color;\n }"}applyTo2d(t){const e=t.imageData.data,i=this.matrix,s=this.colorsOnly;for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2];if(s)e[t]=r*i[0]+n*i[1]+o*i[2]+255*i[4],e[t+1]=r*i[5]+n*i[6]+o*i[7]+255*i[9],e[t+2]=r*i[10]+n*i[11]+o*i[12]+255*i[14];else{const s=e[t+3];e[t]=r*i[0]+n*i[1]+o*i[2]+s*i[3]+255*i[4],e[t+1]=r*i[5]+n*i[6]+o*i[7]+s*i[8]+255*i[9],e[t+2]=r*i[10]+n*i[11]+o*i[12]+s*i[13]+255*i[14],e[t+3]=r*i[15]+n*i[16]+o*i[17]+s*i[18]+255*i[19]}}}getUniformLocations(t,e){return{uColorMatrix:t.getUniformLocation(e,"uColorMatrix"),uConstants:t.getUniformLocation(e,"uConstants")}}sendUniformData(t,e){const i=this.matrix,s=[i[0],i[1],i[2],i[3],i[5],i[6],i[7],i[8],i[10],i[11],i[12],i[13],i[15],i[16],i[17],i[18]],r=[i[4],i[9],i[14],i[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,s),t.uniform4fv(e.uConstants,r)}}function na(t,e){var r;const n=(s(r=class extends ra{},"type",t),s(r,"defaults",i(i({},sa),{},{mainParameter:void 0,matrix:e})),r);return X.setClass(n,t),n}s(ra,"type","ColorMatrix"),s(ra,"defaults",sa),X.setClass(ra);const oa=na("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),aa=na("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),ha=na("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),ca=na("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),la=na("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),da=na("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),ua=na("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]),ga=["subFilters"];class fa extends qo{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{subFilters:e=[]}=t;super(r(t,ga)),this.subFilters=e}applyTo(t){Go(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach((e=>{e.applyTo(t)}))}toObject(){return i(i({},super.toObject()),{},{subFilters:this.subFilters.map((t=>t.toObject()))})}isNeutralState(){return!this.subFilters.some((t=>!t.isNeutralState()))}static fromObject(t,e){return Promise.all((t.subFilters||[]).map((t=>X.getClass(t.type).fromObject(t,e)))).then((t=>new this({subFilters:t})))}}s(fa,"type","Composed"),X.setClass(fa);class pa extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uContrast;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\n color.rgb = contrastF * (color.rgb - 0.5) + 0.5;\n gl_FragColor = color;\n }"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.contrast)return;const i=Math.floor(255*this.contrast),s=259*(i+255)/(255*(259-i));for(let t=0;t<e.length;t+=4)e[t]=s*(e[t]-128)+128,e[t+1]=s*(e[t+1]-128)+128,e[t+2]=s*(e[t+2]-128)+128}getUniformLocations(t,e){return{uContrast:t.getUniformLocation(e,"uContrast")}}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}s(pa,"type","Contrast"),s(pa,"defaults",{contrast:0,mainParameter:"contrast"}),X.setClass(pa);const ma={Convolute_3_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_3_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[9];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 3.0; h+=1.0) {\n for (float w = 0.0; w < 3.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_5_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_5_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[25];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 5.0; h+=1.0) {\n for (float w = 0.0; w < 5.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_7_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_7_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[49];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 7.0; h+=1.0) {\n for (float w = 0.0; w < 7.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n ",Convolute_9_1:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 0);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];\n }\n }\n gl_FragColor = color;\n }\n ",Convolute_9_0:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uMatrix[81];\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = vec4(0, 0, 0, 1);\n for (float h = 0.0; h < 9.0; h+=1.0) {\n for (float w = 0.0; w < 9.0; w+=1.0) {\n vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\n color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];\n }\n }\n float alpha = texture2D(uTexture, vTexCoord).a;\n gl_FragColor = color;\n gl_FragColor.a = alpha;\n }\n "};class va extends qo{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ma[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,i=e.data,s=this.matrix,r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=e.width,a=e.height,h=t.ctx.createImageData(o,a),c=h.data,l=this.opaque?1:0;let d,u,g,f,p,m,v,_,y,x,C,b,S;for(C=0;C<a;C++)for(x=0;x<o;x++){for(p=4*(C*o+x),d=0,u=0,g=0,f=0,S=0;S<r;S++)for(b=0;b<r;b++)v=C+S-n,m=x+b-n,v<0||v>=a||m<0||m>=o||(_=4*(v*o+m),y=s[S*r+b],d+=i[_]*y,u+=i[_+1]*y,g+=i[_+2]*y,l||(f+=i[_+3]*y));c[p]=d,c[p+1]=u,c[p+2]=g,c[p+3]=l?i[p+3]:f}t.imageData=h}getUniformLocations(t,e){return{uMatrix:t.getUniformLocation(e,"uMatrix"),uOpaque:t.getUniformLocation(e,"uOpaque"),uHalfSize:t.getUniformLocation(e,"uHalfSize"),uSize:t.getUniformLocation(e,"uSize")}}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return i(i({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}s(va,"type","Convolute"),s(va,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),X.setClass(va);const _a=["gamma"];class ya extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec3 uGamma;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec3 correction = (1.0 / uGamma);\n color.r = pow(color.r, correction.r);\n color.g = pow(color.g, correction.g);\n color.b = pow(color.b, correction.b);\n gl_FragColor = color;\n gl_FragColor.rgb *= color.a;\n }\n"}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{gamma:e=[1,1,1]}=t;super(r(t,_a)),this.gamma=e}applyTo2d(t){let{imageData:{data:e}}=t;const i=this.gamma,s=1/i[0],r=1/i[1],n=1/i[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let t=0;t<256;t++)o.r[t]=255*Math.pow(t/255,s),o.g[t]=255*Math.pow(t/255,r),o.b[t]=255*Math.pow(t/255,n);for(let t=0;t<e.length;t+=4)e[t]=o.r[e[t]],e[t+1]=o.g[e[t+1]],e[t+2]=o.b[e[t+2]]}getUniformLocations(t,e){return{uGamma:t.getUniformLocation(e,"uGamma")}}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}}s(ya,"type","Gamma"),s(ya,"defaults",{mainParameter:"gamma",gamma:[1,1,1]}),X.setClass(ya);const xa={average:"\n precision highp float;\n uniform sampler2D uTexture;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float average = (color.r + color.b + color.g) / 3.0;\n gl_FragColor = vec4(average, average, average, color.a);\n }\n ",lightness:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n ",luminosity:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uMode;\n varying vec2 vTexCoord;\n void main() {\n vec4 col = texture2D(uTexture, vTexCoord);\n float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;\n gl_FragColor = vec4(average, average, average, col.a);\n }\n "};class Ca extends qo{applyTo2d(t){let{imageData:{data:e}}=t;for(let t,i=0;i<e.length;i+=4){switch(this.mode){case"average":t=(e[i]+e[i+1]+e[i+2])/3;break;case"lightness":t=(Math.min(e[i],e[i+1],e[i+2])+Math.max(e[i],e[i+1],e[i+2]))/2;break;case"luminosity":t=.21*e[i]+.72*e[i+1]+.07*e[i+2]}e[i]=t,e[i+1]=t,e[i+2]=t}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return xa[this.mode]}getUniformLocations(t,e){return{uMode:t.getUniformLocation(e,"uMode")}}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}s(Ca,"type","Grayscale"),s(Ca,"defaults",{mode:"average",mainParameter:"mode"}),X.setClass(Ca);class ba extends ra{calculateMatrix(){const t=this.rotation*Math.PI,e=H(t),i=U(t),s=1/3,r=Math.sqrt(s)*i,n=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+n/3,this.matrix[1]=s*n-r,this.matrix[2]=s*n+r,this.matrix[5]=s*n+r,this.matrix[6]=e+s*n,this.matrix[7]=s*n-r,this.matrix[10]=s*n-r,this.matrix[11]=s*n+r,this.matrix[12]=e+s*n}isNeutralState(){return this.calculateMatrix(),super.isNeutralState()}applyTo(t){this.calculateMatrix(),super.applyTo(t)}}s(ba,"type","HueRotation"),s(ba,"defaults",{rotation:0,mainParameter:"rotation"}),X.setClass(ba);class Sa extends qo{applyTo2d(t){let{imageData:{data:e}}=t;for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uInvert;\n uniform int uAlpha;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n if (uInvert == 1) {\n if (uAlpha == 1) {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);\n } else {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n }\n } else {\n gl_FragColor = color;\n }\n }\n"}isNeutralState(){return!this.invert}getUniformLocations(t,e){return{uInvert:t.getUniformLocation(e,"uInvert"),uAlpha:t.getUniformLocation(e,"uAlpha")}}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}s(Sa,"type","Invert"),s(Sa,"defaults",{alpha:!1,invert:!0,mainParameter:"invert"}),X.setClass(Sa);class wa extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uStepH;\n uniform float uNoise;\n uniform float uSeed;\n varying vec2 vTexCoord;\n float rand(vec2 co, float seed, float vScale) {\n return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n }\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.noise)return;const i=this.noise;for(let t=0;t<e.length;t+=4){const s=(.5-Math.random())*i;e[t]+=s,e[t+1]+=s,e[t+2]+=s}}getUniformLocations(t,e){return{uNoise:t.getUniformLocation(e,"uNoise"),uSeed:t.getUniformLocation(e,"uSeed")}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}toObject(){return i(i({},super.toObject()),{},{noise:this.noise})}}s(wa,"type","Noise"),s(wa,"defaults",{mainParameter:"noise",noise:0}),X.setClass(wa);class Ta extends qo{applyTo2d(t){let{imageData:{data:e,width:i,height:s}}=t;for(let t=0;t<s;t+=this.blocksize)for(let r=0;r<i;r+=this.blocksize){const n=4*t*i+4*r,o=e[n],a=e[n+1],h=e[n+2],c=e[n+3];for(let n=t;n<Math.min(t+this.blocksize,s);n++)for(let t=r;t<Math.min(r+this.blocksize,i);t++){const s=4*n*i+4*t;e[s]=o,e[s+1]=a,e[s+2]=h,e[s+3]=c}}}isNeutralState(){return 1===this.blocksize}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBlocksize;\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n float blockW = uBlocksize * uStepW;\n float blockH = uBlocksize * uStepW;\n int posX = int(vTexCoord.x / blockW);\n int posY = int(vTexCoord.y / blockH);\n float fposX = float(posX);\n float fposY = float(posY);\n vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\n vec4 color = texture2D(uTexture, squareCoords);\n gl_FragColor = color;\n }\n"}getUniformLocations(t,e){return{uBlocksize:t.getUniformLocation(e,"uBlocksize"),uStepW:t.getUniformLocation(e,"uStepW"),uStepH:t.getUniformLocation(e,"uStepH")}}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}s(Ta,"type","Pixelate"),s(Ta,"defaults",{blocksize:4,mainParameter:"blocksize"}),X.setClass(Ta);class Oa extends qo{getFragmentShader(){return"\nprecision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\n gl_FragColor.a = 0.0;\n }\n}\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=255*this.distance,s=new At(this.color).getSource(),r=[s[0]-i,s[1]-i,s[2]-i],n=[s[0]+i,s[1]+i,s[2]+i];for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],o=e[t+2];i>r[0]&&s>r[1]&&o>r[2]&&i<n[0]&&s<n[1]&&o<n[2]&&(e[t+3]=0)}}getUniformLocations(t,e){return{uLow:t.getUniformLocation(e,"uLow"),uHigh:t.getUniformLocation(e,"uHigh")}}sendUniformData(t,e){const i=new At(this.color).getSource(),s=this.distance,r=[0+i[0]/255-s,0+i[1]/255-s,0+i[2]/255-s,1],n=[i[0]/255+s,i[1]/255+s,i[2]/255+s,1];t.uniform4fv(e.uLow,r),t.uniform4fv(e.uHigh,n)}toObject(){return i(i({},super.toObject()),{},{color:this.color,distance:this.distance})}}s(Oa,"type","RemoveColor"),s(Oa,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),X.setClass(Oa);class ka extends qo{getUniformLocations(t,e){return{uDelta:t.getUniformLocation(e,"uDelta"),uTaps:t.getUniformLocation(e,"uTaps")}}sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,i=this.getFilterWindow(),s=new Array(i);for(let r=1;r<=i;r++)s[r-1]=t(r*e);return s}generateShader(t){const e=new Array(t);for(let i=1;i<=t;i++)e[i-1]="".concat(i,".0 * uDelta");return"\n ".concat(this.fragmentSourceTOP,"\n uniform float uTaps[").concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map(((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(e,"];\n "))).join("\n"),"\n gl_FragColor = color / sum;\n }\n ")}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Go(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return 1===this.scaleX&&1===this.scaleY}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<1.1920929e-7&&e>-1.1920929e-7)return 1;const i=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(i)/i}}applyTo2d(t){const e=t.imageData,i=this.scaleX,s=this.scaleY;this.rcpScaleX=1/i,this.rcpScaleY=1/s;const r=e.width,n=e.height,o=Math.round(r*i),a=Math.round(n*s);let h;h="sliceHack"===this.resizeType?this.sliceByTwo(t,r,n,o,a):"hermite"===this.resizeType?this.hermiteFastResize(t,r,n,o,a):"bilinear"===this.resizeType?this.bilinearFiltering(t,r,n,o,a):"lanczos"===this.resizeType?this.lanczosResize(t,r,n,o,a):new ImageData(o,a),t.imageData=h}sliceByTwo(t,e,i,s,r){const n=t.imageData,o=.5;let a=!1,h=!1,c=e*o,l=i*o;const d=t.filterBackend.resources;let u=0,g=0;const f=e;let p=0;d.sliceByTwo||(d.sliceByTwo=et());const m=d.sliceByTwo;(m.width<1.5*e||m.height<i)&&(m.width=1.5*e,m.height=i);const v=m.getContext("2d");for(v.clearRect(0,0,1.5*e,i),v.putImageData(n,0,0),s=Math.floor(s),r=Math.floor(r);!a||!h;)e=c,i=l,s<Math.floor(c*o)?c=Math.floor(c*o):(c=s,a=!0),r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,h=!0),v.drawImage(m,u,g,e,i,f,p,c,l),u=f,g=p,p+=l;return v.getImageData(u,g,s,r)}lanczosResize(t,e,i,s,r){const n=t.imageData.data,o=t.ctx.createImageData(s,r),a=o.data,h=this.lanczosCreate(this.lanczosLobes),c=this.rcpScaleX,l=this.rcpScaleY,d=2/this.rcpScaleX,u=2/this.rcpScaleY,g=Math.ceil(c*this.lanczosLobes/2),f=Math.ceil(l*this.lanczosLobes/2),p={},m={x:0,y:0},v={x:0,y:0};return function t(_){let y,x,C,b,S,w,T,O,k,D,M;for(m.x=(_+.5)*c,v.x=Math.floor(m.x),y=0;y<r;y++){for(m.y=(y+.5)*l,v.y=Math.floor(m.y),S=0,w=0,T=0,O=0,k=0,x=v.x-g;x<=v.x+g;x++)if(!(x<0||x>=e)){D=Math.floor(1e3*Math.abs(x-m.x)),p[D]||(p[D]={});for(let t=v.y-f;t<=v.y+f;t++)t<0||t>=i||(M=Math.floor(1e3*Math.abs(t-m.y)),p[D][M]||(p[D][M]=h(Math.sqrt(Math.pow(D*d,2)+Math.pow(M*u,2))/1e3)),C=p[D][M],C>0&&(b=4*(t*e+x),S+=C,w+=C*n[b],T+=C*n[b+1],O+=C*n[b+2],k+=C*n[b+3]))}b=4*(y*s+_),a[b]=w/S,a[b+1]=T/S,a[b+2]=O/S,a[b+3]=k/S}return++_<s?t(_):o}(0)}bilinearFiltering(t,e,i,s,r){let n,o,a,h,c,l,d,u,g,f,p,m,v,_=0;const y=this.rcpScaleX,x=this.rcpScaleY,C=4*(e-1),b=t.imageData.data,S=t.ctx.createImageData(s,r),w=S.data;for(d=0;d<r;d++)for(u=0;u<s;u++)for(c=Math.floor(y*u),l=Math.floor(x*d),g=y*u-c,f=x*d-l,v=4*(l*e+c),p=0;p<4;p++)n=b[v+p],o=b[v+4+p],a=b[v+C+p],h=b[v+C+4+p],m=n*(1-g)*(1-f)+o*g*(1-f)+a*f*(1-g)+h*g*f,w[_++]=m;return S}hermiteFastResize(t,e,i,s,r){const n=this.rcpScaleX,o=this.rcpScaleY,a=Math.ceil(n/2),h=Math.ceil(o/2),c=t.imageData.data,l=t.ctx.createImageData(s,r),d=l.data;for(let t=0;t<r;t++)for(let i=0;i<s;i++){const r=4*(i+t*s);let l=0,u=0,g=0,f=0,p=0,m=0,v=0;const _=(t+.5)*o;for(let s=Math.floor(t*o);s<(t+1)*o;s++){const t=Math.abs(_-(s+.5))/h,r=(i+.5)*n,o=t*t;for(let t=Math.floor(i*n);t<(i+1)*n;t++){let i=Math.abs(r-(t+.5))/a;const n=Math.sqrt(o+i*i);n>1&&n<-1||(l=2*n*n*n-3*n*n+1,l>0&&(i=4*(t+s*e),v+=l*c[i+3],g+=l,c[i+3]<255&&(l=l*c[i+3]/250),f+=l*c[i],p+=l*c[i+1],m+=l*c[i+2],u+=l))}}d[r]=f/u,d[r+1]=p/u,d[r+2]=m/u,d[r+3]=v/g}return l}toObject(){return{type:this.type,scaleX:this.scaleX,scaleY:this.scaleY,resizeType:this.resizeType,lanczosLobes:this.lanczosLobes}}}s(ka,"type","Resize"),s(ka,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3,fragmentSourceTOP:"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n "}),X.setClass(ka);class Da extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uSaturation;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float rgMax = max(color.r, color.g);\n float rgbMax = max(rgMax, color.b);\n color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\n color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\n color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.saturation)return;const i=-this.saturation;for(let t=0;t<e.length;t+=4){const s=Math.max(e[t],e[t+1],e[t+2]);e[t]+=s!==e[t]?(s-e[t])*i:0,e[t+1]+=s!==e[t+1]?(s-e[t+1])*i:0,e[t+2]+=s!==e[t+2]?(s-e[t+2])*i:0}}getUniformLocations(t,e){return{uSaturation:t.getUniformLocation(e,"uSaturation")}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}}s(Da,"type","Saturation"),s(Da,"defaults",{saturation:0,mainParameter:"saturation"}),X.setClass(Da);class Ma extends qo{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uVibrance;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float max = max(color.r, max(color.g, color.b));\n float avg = (color.r + color.g + color.b) / 3.0;\n float amt = (abs(max - avg) * 2.0) * uVibrance;\n color.r += max != color.r ? (max - color.r) * amt : 0.00;\n color.g += max != color.g ? (max - color.g) * amt : 0.00;\n color.b += max != color.b ? (max - color.b) * amt : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;if(0===this.vibrance)return;const i=-this.vibrance;for(let t=0;t<e.length;t+=4){const s=Math.max(e[t],e[t+1],e[t+2]),r=(e[t]+e[t+1]+e[t+2])/3,n=2*Math.abs(s-r)/255*i;e[t]+=s!==e[t]?(s-e[t])*n:0,e[t+1]+=s!==e[t+1]?(s-e[t+1])*n:0,e[t+2]+=s!==e[t+2]?(s-e[t+2])*n:0}}getUniformLocations(t,e){return{uVibrance:t.getUniformLocation(e,"uVibrance")}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}}s(Ma,"type","Vibrance"),s(Ma,"defaults",{vibrance:0,mainParameter:"vibrance"}),X.setClass(Ma);var Pa=Object.freeze({__proto__:null,BaseFilter:qo,BlackWhite:ua,BlendColor:Jo,BlendImage:$o,Blur:ta,Brightness:ea,Brownie:oa,ColorMatrix:ra,Composed:fa,Contrast:pa,Convolute:va,Gamma:ya,Grayscale:Ca,HueRotation:ba,Invert:Sa,Kodachrome:ha,Noise:wa,Pixelate:Ta,Polaroid:la,RemoveColor:Oa,Resize:ka,Saturation:Da,Sepia:da,Technicolor:ca,Vibrance:Ma,Vintage:aa});t.ActiveSelection=Us,t.BaseBrush=_n,t.Canvas=tn,t.Canvas2dFilterBackend=mo,t.CanvasDOMManager=zr,t.Circle=Tn,t.CircleBrush=class extends _n{constructor(t){super(t),s(this,"width",10),this.points=[]}drawDot(t){const e=this.addPoint(t),i=this.canvas.contextTop;this._saveAndTransform(i),this.dot(i,e),i.restore()}dot(t,e){t.fillStyle=e.fill,t.beginPath(),t.arc(e.x,e.y,e.radius,0,2*Math.PI,!1),t.closePath(),t.fill()}onMouseDown(t){this.points=[],this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.drawDot(t)}_render(){const t=this.canvas.contextTop,e=this.points;this._saveAndTransform(t);for(let i=0;i<e.length;i++)this.dot(t,e[i]);t.restore()}onMouseMove(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.needsFullRender()?(this.canvas.clearContext(this.canvas.contextTop),this.addPoint(t),this._render()):this.drawDot(t))}onMouseUp(){const t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;const e=[];for(let t=0;t<this.points.length;t++){const i=this.points[t],s=new Tn({radius:i.radius,left:i.x,top:i.y,originX:P,originY:P,fill:i.fill});this.shadow&&(s.shadow=new li(this.shadow)),e.push(s)}const i=new Hs(e,{canvas:this.canvas});this.canvas.fire("before:path:created",{path:i}),this.canvas.add(i),this.canvas.fire("path:created",{path:i}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()}addPoint(t){let{x:e,y:i}=t;const s={x:e,y:i,radius:V(Math.max(0,this.width-20),this.width+20)/2,fill:new At(this.color).setAlpha(V(0,100)/100).toRgba()};return this.points.push(s),s}},t.Color=At,t.Control=bi,t.Ellipse=En,t.FabricImage=wo,t.FabricObject=Ji,t.FabricText=to,t.Gradient=pn,t.Group=Hs,t.IText=fo,t.Image=wo,t.Intersection=ni,t.Line=Mn,t.Object=Ji,t.Observable=W,t.Path=Cn,t.Pattern=vn,t.PatternBrush=class extends bn{constructor(t){super(t)}getPatternSrc(){const t=et(),e=t.getContext("2d");return t.width=t.height=25,e&&(e.fillStyle=this.color,e.beginPath(),e.arc(10,10,10,0,2*Math.PI,!1),e.closePath(),e.fill()),t}getPattern(t){return t.createPattern(this.source||this.getPatternSrc(),"repeat")}_setBrushStyles(t){super._setBrushStyles(t);const e=this.getPattern(t);e&&(t.strokeStyle=e)}createPath(t){const e=super.createPath(t),i=e._getLeftTopCoords().scalarAdd(e.strokeWidth/2);return e.stroke=new vn({source:this.source||this.getPatternSrc(),offsetX:-i.x,offsetY:-i.y}),e}},t.PencilBrush=bn,t.Point=N,t.Polygon=Bn,t.Polyline=Rn,t.Rect=Gs,t.Shadow=li,t.SprayBrush=class extends _n{constructor(t){super(t),s(this,"width",10),s(this,"density",20),s(this,"dotWidth",1),s(this,"dotWidthVariance",1),s(this,"randomOpacity",!1),s(this,"optimizeOverlapping",!0),this.sprayChunks=[],this.sprayChunk=[]}onMouseDown(t){this.sprayChunks=[],this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.addSprayChunk(t),this.renderChunck(this.sprayChunk)}onMouseMove(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.addSprayChunk(t),this.renderChunck(this.sprayChunk))}onMouseUp(){const t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;const e=[];for(let t=0;t<this.sprayChunks.length;t++){const i=this.sprayChunks[t];for(let t=0;t<i.length;t++){const s=i[t],r=new Gs({width:s.width,height:s.width,left:s.x+1,top:s.y+1,originX:P,originY:P,fill:this.color});e.push(r)}}const i=new Hs(this.optimizeOverlapping?function(t){const e={},i=[];for(let s,r=0;r<t.length;r++)s="".concat(t[r].left).concat(t[r].top),e[s]||(e[s]=!0,i.push(t[r]));return i}(e):e,{objectCaching:!0,layout:"fixed",subTargetCheck:!1,interactive:!1});this.shadow&&i.set("shadow",new li(this.shadow)),this.canvas.fire("before:path:created",{path:i}),this.canvas.add(i),this.canvas.fire("path:created",{path:i}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()}renderChunck(t){const e=this.canvas.contextTop;e.fillStyle=this.color,this._saveAndTransform(e);for(let i=0;i<t.length;i++){const s=t[i];e.globalAlpha=s.opacity,e.fillRect(s.x,s.y,s.width,s.width)}e.restore()}_render(){const t=this.canvas.contextTop;t.fillStyle=this.color,this._saveAndTransform(t);for(let t=0;t<this.sprayChunks.length;t++)this.renderChunck(this.sprayChunks[t]);t.restore()}addSprayChunk(t){this.sprayChunk=[];const e=this.width/2;for(let i=0;i<this.density;i++)this.sprayChunk.push({x:V(t.x-e,t.x+e),y:V(t.y-e,t.y+e),width:this.dotWidthVariance?V(Math.max(1,this.dotWidth-this.dotWidthVariance),this.dotWidth+this.dotWidthVariance):this.dotWidth,opacity:this.randomOpacity?V(0,100)/100:1});this.sprayChunks.push(this.sprayChunk)}},t.StaticCanvas=te,t.StaticCanvasDOMManager=Qt,t.Text=to,t.Textbox=po,t.Triangle=Pn,t.WebGLFilterBackend=vo,t.cache=C,t.classRegistry=X,t.config=h,t.controlsUtils=Vo,t.createCollectionMixin=K,t.filters=Pa,t.getCSSRules=Eo,t.getEnv=_,t.getFabricDocument=y,t.getFabricWindow=x,t.getFilterBackend=Co,t.iMatrix=k,t.initFilterBackend=xo,t.isWebGLPipelineState=Go,t.loadSVGFromString=function(t,e,i){return Bo((new(x().DOMParser)).parseFromString(t.trim(),"text/xml"),e,i)},t.loadSVGFromURL=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise(((e,s)=>{Wr(t.replace(/^\n\s*/,"").trim(),{onComplete:t=>{const i=t.responseXML;i&&e(i),s()},signal:i.signal})})).then((t=>Bo(t,e,i))).catch((()=>Ro()))},t.parseAttributes=Ys,t.parseFontDeclaration=Bs,t.parsePointsAttribute=jn,t.parseSVGDocument=Bo,t.parseStyleAttribute=Is,t.parseTransformAttribute=Ls,t.runningAnimations=Y,t.setEnv=t=>{v=t},t.setFilterBackend=function(t){yo=t},t.util=Gr,t.version=b}));
|