@lifesg/web-frontend-engine 2.0.0-alpha.18 → 2.0.0-alpha.19
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/chunks/{file-upload-manager.6f91498f.js → file-upload-manager.6091aa9e.js} +2 -2
- package/chunks/file-upload-manager.6091aa9e.js.map +1 -0
- package/chunks/{index.01911ac9.js → index.cb4c93a5.js} +6 -6
- package/{cjs/chunks/index.33c9bcbb.js.map → chunks/index.cb4c93a5.js.map} +1 -1
- package/chunks/{index.c8228568.js → index.dcdbe23e.js} +2 -2
- package/chunks/{index.c8228568.js.map → index.dcdbe23e.js.map} +1 -1
- package/chunks/{index.94a6f552.js → index.df1ee6f5.js} +2 -2
- package/chunks/{index.94a6f552.js.map → index.df1ee6f5.js.map} +1 -1
- package/chunks/{location-modal.96339252.js → location-modal.b47d92b7.js} +2 -2
- package/chunks/{location-modal.96339252.js.map → location-modal.b47d92b7.js.map} +1 -1
- package/cjs/chunks/{file-upload-manager.2465d276.js → file-upload-manager.858f342f.js} +2 -2
- package/cjs/chunks/file-upload-manager.858f342f.js.map +1 -0
- package/cjs/chunks/{index.c8a96a82.js → index.3cfca5cf.js} +2 -2
- package/cjs/chunks/{index.c8a96a82.js.map → index.3cfca5cf.js.map} +1 -1
- package/cjs/chunks/{index.33c9bcbb.js → index.7db1a25b.js} +6 -6
- package/cjs/chunks/index.7db1a25b.js.map +1 -0
- package/cjs/chunks/{index.dbac2c71.js → index.ade37699.js} +2 -2
- package/cjs/chunks/{index.dbac2c71.js.map → index.ade37699.js.map} +1 -1
- package/cjs/chunks/{location-modal.07158be4.js → location-modal.ff0cd21c.js} +2 -2
- package/cjs/chunks/{location-modal.07158be4.js.map → location-modal.ff0cd21c.js.map} +1 -1
- package/cjs/index.js +1 -1
- package/components/shared/error-messages.d.ts +1 -0
- package/context-providers/yup/types.d.ts +8 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/chunks/file-upload-manager.6f91498f.js.map +0 -1
- package/chunks/index.01911ac9.js.map +0 -1
- package/cjs/chunks/file-upload-manager.2465d276.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsx as t}from"react/jsx-runtime";import e,{forwardRef as i,useRef as s,useImperativeHandle as r,useEffect as n}from"react";import{m as o,d as a,T as c}from"./index.01911ac9.js";import h from"styled-components";import"@lifesg/react-design-system/theme";import"@lifesg/react-design-system/typography";import"@lifesg/react-design-system/button";import"@lifesg/react-design-system/modal";import"@lifesg/react-design-system/markup";import"react-dom/server";import"@lifesg/react-design-system/alert";import"@lifesg/react-design-system/layout";import"@lifesg/react-design-system/box-container";import"@lifesg/react-design-system/divider";import"@lifesg/react-design-system/v2_media";import"@lifesg/react-design-system/text-list";import"@lifesg/react-design-system/popover-v2";import"@lifesg/react-icons";import"@lifesg/react-design-system/tab";import"@lifesg/react-icons/plus-circle-fill";import"@lifesg/react-design-system/button-with-icon";import"@lifesg/react-design-system/error-display";import"@lifesg/react-design-system/filter";import"@lifesg/react-design-system/uneditable-section";import"@lifesg/react-design-system/timeline";import"@lifesg/react-design-system/form";import"@lifesg/react-design-system/checkbox";import"@lifesg/react-design-system/toggle";import"@lifesg/react-design-system/file-upload";import"@lifesg/react-icons/cross";import"@lifesg/react-design-system/icon-button";import"@lifesg/react-icons/bin";import"@lifesg/react-icons/eraser";import"@lifesg/react-icons/pencil";import"@lifesg/react-icons/pencil-stroke";import"@lifesg/react-icons/plus";import"@lifesg/react-icons/exclamation-triangle";import"@lifesg/react-icons/pin-fill";import"@lifesg/react-design-system/image-button";import"@lifesg/react-design-system/radio-button";import"@lifesg/react-design-system/v2_layout";function l(t,e,i){return e=S(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return T(t)}(t,u()?Reflect.construct(e,i||[],S(t).constructor):e.apply(t,i))}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function d(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 g(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?d(Object(i),!0).forEach((function(e){b(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):d(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function f(){f=function(){return e};var t,e={},i=Object.prototype,s=i.hasOwnProperty,r=Object.defineProperty||function(t,e,i){t[e]=i.value},n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";function h(t,e,i){return Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch(t){h=function(t,e,i){return t[e]=i}}function l(t,e,i,s){var n=e&&e.prototype instanceof y?e:y,o=Object.create(n.prototype),a=new P(s||[]);return r(o,"_invoke",{value:k(t,i,a)}),o}function u(t,e,i){try{return{type:"normal",arg:t.call(e,i)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var d="suspendedStart",g="suspendedYield",p="executing",m="completed",v={};function y(){}function _(){}function x(){}var b={};h(b,o,(function(){return this}));var w=Object.getPrototypeOf,S=w&&w(w(j([])));S&&S!==i&&s.call(S,o)&&(b=S);var C=x.prototype=y.prototype=Object.create(b);function T(t){["next","throw","return"].forEach((function(e){h(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(r,n,o,a){var c=u(t[r],t,n);if("throw"!==c.type){var h=c.arg,l=h.value;return l&&"object"==typeof l&&s.call(l,"__await")?e.resolve(l.__await).then((function(t){i("next",t,o,a)}),(function(t){i("throw",t,o,a)})):e.resolve(l).then((function(t){h.value=t,o(h)}),(function(t){return i("throw",t,o,a)}))}a(c.arg)}var n;r(this,"_invoke",{value:function(t,s){function r(){return new e((function(e,r){i(t,s,e,r)}))}return n=n?n.then(r,r):r()}})}function k(e,i,s){var r=d;return function(n,o){if(r===p)throw new Error("Generator is already running");if(r===m){if("throw"===n)throw o;return{value:t,done:!0}}for(s.method=n,s.arg=o;;){var a=s.delegate;if(a){var c=D(a,s);if(c){if(c===v)continue;return c}}if("next"===s.method)s.sent=s._sent=s.arg;else if("throw"===s.method){if(r===d)throw r=m,s.arg;s.dispatchException(s.arg)}else"return"===s.method&&s.abrupt("return",s.arg);r=p;var h=u(e,i,s);if("normal"===h.type){if(r=s.done?m:g,h.arg===v)continue;return{value:h.arg,done:s.done}}"throw"===h.type&&(r=m,s.method="throw",s.arg=h.arg)}}}function D(e,i){var s=i.method,r=e.iterator[s];if(r===t)return i.delegate=null,"throw"===s&&e.iterator.return&&(i.method="return",i.arg=t,D(e,i),"throw"===i.method)||"return"!==s&&(i.method="throw",i.arg=new TypeError("The iterator does not provide a '"+s+"' method")),v;var n=u(r,e.iterator,i.arg);if("throw"===n.type)return i.method="throw",i.arg=n.arg,i.delegate=null,v;var o=n.arg;return o?o.done?(i[e.resultName]=o.value,i.next=e.nextLoc,"return"!==i.method&&(i.method="next",i.arg=t),i.delegate=null,v):o:(i.method="throw",i.arg=new TypeError("iterator result is not an object"),i.delegate=null,v)}function M(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(M,this),this.reset(!0)}function j(e){if(e||""===e){var i=e[o];if(i)return i.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function i(){for(;++r<e.length;)if(s.call(e,r))return i.value=e[r],i.done=!1,i;return i.value=t,i.done=!0,i};return n.next=n}}throw new TypeError(typeof e+" is not iterable")}return _.prototype=x,r(C,"constructor",{value:x,configurable:!0}),r(x,"constructor",{value:_,configurable:!0}),_.displayName=h(x,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,h(t,c,"GeneratorFunction")),t.prototype=Object.create(C),t},e.awrap=function(t){return{__await:t}},T(O.prototype),h(O.prototype,a,(function(){return this})),e.AsyncIterator=O,e.async=function(t,i,s,r,n){void 0===n&&(n=Promise);var o=new O(l(t,i,s,r),n);return e.isGeneratorFunction(i)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},T(C),h(C,c,"Generator"),h(C,o,(function(){return this})),h(C,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),i=[];for(var s in e)i.push(s);return i.reverse(),function t(){for(;i.length;){var s=i.pop();if(s in e)return t.value=s,t.done=!1,t}return t.done=!0,t}},e.values=j,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(E),!e)for(var i in this)"t"===i.charAt(0)&&s.call(this,i)&&!isNaN(+i.slice(1))&&(this[i]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var i=this;function r(s,r){return a.type="throw",a.arg=e,i.next=s,r&&(i.method="next",i.arg=t),!!r}for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),h=s.call(o,"finallyLoc");if(c&&h){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!h)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var i=this.tryEntries.length-1;i>=0;--i){var r=this.tryEntries[i];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var n=r;break}}n&&("break"===t||"continue"===t)&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var o=n?n.completion:{};return o.type=t,o.arg=e,n?(this.method="next",this.next=n.finallyLoc,v):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.finallyLoc===t)return this.complete(i.completion,i.afterLoc),E(i),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.tryLoc===t){var s=i.completion;if("throw"===s.type){var r=s.arg;E(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,i,s){return this.delegate={iterator:j(e),resultName:i,nextLoc:s},"next"===this.method&&(this.arg=t),v}},e}function p(t){var e=function(t,e){if("object"!=typeof t||!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)}function m(t,e,i,s,r,n,o){try{var a=t[n](o),c=a.value}catch(t){return void i(t)}a.done?e(c):Promise.resolve(c).then(s,r)}function v(t){return function(){var e=this,i=arguments;return new Promise((function(s,r){var n=t.apply(e,i);function o(t){m(n,s,r,o,a,"next",t)}function a(t){m(n,s,r,o,a,"throw",t)}o(void 0)}))}}function y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,p(s.key),s)}}function x(t,e,i){return e&&_(t.prototype,e),i&&_(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function b(t,e,i){return(e=p(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function w(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&C(t,e)}function S(t){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},S(t)}function C(t,e){return C=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},C(t,e)}function T(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function O(){return O="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var s=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=S(t)););return t}(t,e);if(s){var r=Object.getOwnPropertyDescriptor(s,e);return r.get?r.get.call(arguments.length<3?t:i):r.value}},O.apply(this,arguments)}function k(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var i=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=i){var s,r,n,o,a=[],c=!0,h=!1;try{if(n=(i=i.call(t)).next,0===e){if(Object(i)!==i)return;c=!1}else for(;!(c=(s=n.call(i)).done)&&(a.push(s.value),a.length!==e);c=!0);}catch(t){h=!0,r=t}finally{try{if(!c&&null!=i.return&&(o=i.return(),Object(o)!==o))return}finally{if(h)throw r}}return a}}(t,e)||M(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(t){return function(t){if(Array.isArray(t))return E(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||M(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(t,e){if(t){if("string"==typeof t)return E(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?E(t,e):void 0}}function E(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,s=new Array(e);i<e;i++)s[i]=t[i];return s}function P(t,e,i){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function j(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 A(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?j(Object(i),!0).forEach((function(e){P(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):j(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function F(t,e){if(null==t)return{};var i,s,r=function(t,e){if(null==t)return{};var i={};for(var s in t)if({}.hasOwnProperty.call(t,s)){if(e.indexOf(s)>=0)continue;i[s]=t[s]}return i}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||{}.propertyIsEnumerable.call(t,i)&&(r[i]=t[i])}return r}function L(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}class I{constructor(){P(this,"browserShadowBlurConstant",1),P(this,"DPI",96),P(this,"devicePixelRatio","undefined"!=typeof window?window.devicePixelRatio:1),P(this,"perfLimitSizeTotal",2097152),P(this,"maxCacheSideLimit",4096),P(this,"minCacheSideLimit",256),P(this,"disableStyleCopyPaste",!1),P(this,"enableGLFiltering",!0),P(this,"textureSize",4096),P(this,"forceGLPutImageData",!1),P(this,"cachesBoundsOfCurve",!1),P(this,"fontPaths",{}),P(this,"NUM_FRACTION_DIGITS",4)}}const R=new class extends I{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=A(A({},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 I,i=(null==t?void 0:t.reduce(((t,i)=>(t[i]=e[i],t)),{}))||e;this.configure(i)}},B=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 X extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class V extends X{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Y{}class W extends Y{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))),e.getExtension("WEBGL_lose_context").loseContext(),B("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const H={};let z;const G=()=>z||(z={document:document,window:window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new W,dispose(){},copyPasteData:H}),N=()=>G().document,U=()=>G().window,q=()=>{var t;return Math.max(null!==(t=R.devicePixelRatio)&&void 0!==t?t:U().devicePixelRatio,1)},K=new class{constructor(){P(this,"charWidthsCache",{}),P(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}=R,i=Math.sqrt(e*t);return[Math.floor(i),Math.floor(e/i)]}},J="6.7.1";function Q(){}const Z=Math.PI/2,$=2*Math.PI,tt=Math.PI/180,et=Object.freeze([1,0,0,1,0,0]),it=16,st=.4477152502,rt="center",nt="left",ot="top",at="bottom",ct="right",ht="none",lt=/\r?\n/,ut="moving",dt="scaling",gt="rotating",ft="rotate",pt="skewing",mt="resizing",vt="modifyPoly",yt="modifyPath",_t="changed",xt="scale",bt="scaleX",wt="scaleY",St="skewX",Ct="skewY",Tt="fill",Ot="stroke",kt="modified",Dt="json",Mt="svg",Et=new class{constructor(){this[Dt]=new Map,this[Mt]=new Map}has(t){return this[Dt].has(t)}getClass(t){const e=this[Dt].get(t);if(!e)throw new X("No class registered for ".concat(t));return e}setClass(t,e){e?this[Dt].set(e,t):(this[Dt].set(t.type,t),this[Dt].set(t.type.toLowerCase(),t))}getSVGClass(t){return this[Mt].get(t)}setSVGClass(t,e){this[Mt].set(null!=e?e:t.type.toLowerCase(),t)}},Pt=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 jt{constructor(){P(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 At=(t,e)=>{const i=t.indexOf(e);return-1!==i&&t.splice(i,1),t},Ft=t=>{if(0===t)return 1;switch(Math.abs(t)/Z){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},Lt=t=>{if(0===t)return 0;const e=t/Z,i=Math.sign(t);switch(e){case 1:return i;case 2:return 0;case 3:return-i}return Math.sin(t)};class It{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 It(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new It(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new It(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new It(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new It(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new It(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new It(this.x/t.x,this.y/t.y)}scalarDivide(t){return new It(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 It(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 It(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new It(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 It(this.x,this.y)}rotate(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Rt;const i=Lt(t),s=Ft(t),r=this.subtract(e);return new It(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 It(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 Rt=new It(0,0),Bt=t=>!!t&&Array.isArray(t._objects);function Xt(t){class e extends t{constructor(){super(...arguments),P(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]||(At(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),0))}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1]||(At(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 At(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 At(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(At(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 It(e,i),c=a.add(new It(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,c)||e.isContainedWithinRect(a,c)||n&&e.containsPoint(a)||n&&e.containsPoint(c))&&o.push(e)}return o}}return e}class Vt extends jt{_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 Yt(t){return U().requestAnimationFrame(t)}function Wt(t){return U().cancelAnimationFrame(t)}let Ht=0;const zt=()=>Ht++,Gt=()=>{const t=N().createElement("canvas");if(!t||void 0===t.getContext)throw new X("Failed to create `canvas` element");return t},Nt=()=>N().createElement("img"),Ut=t=>{const e=Gt();return e.width=t.width,e.height=t.height,e},qt=(t,e,i)=>t.toDataURL("image/".concat(e),i),Kt=(t,e,i)=>new Promise(((s,r)=>{t.toBlob(s,"image/".concat(e),i)})),Jt=t=>t*tt,Qt=t=>t/tt,Zt=t=>t.every(((t,e)=>t===et[e])),$t=(t,e,i)=>new It(t).transform(e,i),te=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 It(t[4],t[5]).transform(i,!0);return i[4]=-s,i[5]=-r,i},ee=(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]],ie=(t,e)=>t.reduceRight(((t,i)=>i&&t?ee(i,t,e):i||t),void 0)||et.concat(),se=t=>{let[e,i]=t;return Math.atan2(i,e)},re=t=>{const e=se(t),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:Qt(e),scaleX:s,scaleY:r,skewX:Qt(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},ne=function(t){return[1,0,0,1,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0]};function oe(){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=Jt(t),r=Ft(s),n=Lt(s);return[r,n,-n,r,e?e-(r*e-n*i):0,i?i-(n*e+r*i):0]}const ae=function(t){return[t,0,0,arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,0,0]},ce=t=>Math.tan(Jt(t)),he=t=>[1,0,ce(t),1,0,0],le=t=>[1,ce(t),0,1,0,0],ue=t=>{let{scaleX:e=1,scaleY:i=1,flipX:s=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=t,a=ae(s?-e:e,r?-i:i);return n&&(a=ee(a,he(n),!0)),o&&(a=ee(a,le(o),!0)),a},de=t=>{const{translateX:e=0,translateY:i=0,angle:s=0}=t;let r=ne(e,i);s&&(r=ee(r,oe({angle:s})));const n=ue(t);return Zt(n)||(r=ee(r,n)),r},ge=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 V("loadImage"));const n=Nt();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 X("Error loading ".concat(n.src)))},i&&(n.crossOrigin=i),n.src=t):a()}))},fe=function(t){let{signal:e,reviver:i=Q}=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=>Et.getClass(t.type).fromObject(t,{signal:e}).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)}))}))},pe=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.type&&Et.has(t.type)?fe([t],{signal:e}).then((t=>{let[e]=t;return r.push(e),e})):t)),o=Object.keys(t);Promise.all(n).then((t=>t.reduce(((t,e,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)}))}))},me=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce(((e,i)=>(i in t&&(e[i]=t[i]),e)),{})},ve=(t,e)=>Object.keys(t).reduce(((i,s)=>(e(t[s],s,t)&&(i[s]=t[s]),i)),{}),ye=(t,e)=>parseFloat(Number(t).toFixed(e)),_e=t=>"matrix("+t.map((t=>ye(t,R.NUM_FRACTION_DIGITS))).join(" ")+")",xe=t=>!!t&&void 0!==t.toLive,be=t=>!!t&&"function"==typeof t.toObject,we=t=>!!t&&void 0!==t.offsetX&&"source"in t,Se=t=>!!t&&"multiSelectionStacking"in t;function Ce(t){const e=t&&Te(t);let i=0,s=0;if(!t||!e)return{left:i,top:s};let r=t;const n=e.documentElement,o=e.body||{scrollLeft:0,scrollTop:0};for(;r&&(r.parentNode||r.host)&&(r=r.parentNode||r.host,r===e?(i=o.scrollLeft||n.scrollLeft||0,s=o.scrollTop||n.scrollTop||0):(i+=r.scrollLeft||0,s+=r.scrollTop||0),1!==r.nodeType||"fixed"!==r.style.position););return{left:i,top:s}}const Te=t=>t.ownerDocument||null,Oe=t=>{var e;return(null===(e=t.ownerDocument)||void 0===e?void 0:e.defaultView)||null},ke=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))},De=(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 Me(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect=ht,t}class Ee{constructor(t){P(this,"_originalCanvasStyle",void 0),P(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&&N().getElementById(t)||Gt();var i;if(e.hasAttribute("data-fabric"))throw new X("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;ke(i,s,t,e)}setCSSDimensions(t){De(this.lower.el,t)}calcOffset(){return function(t){var e;const i=t&&Te(t),s={left:0,top:0};if(!i)return s;const r=(null===(e=Oe(t))||void 0===e?void 0:e.getComputedStyle(t,null))||{};s.left+=parseInt(r.borderLeftWidth,10)||0,s.top+=parseInt(r.borderTopWidth,10)||0,s.left+=parseInt(r.paddingLeft,10)||0,s.top+=parseInt(r.paddingTop,10)||0;let n={left:0,top:0};const o=i.documentElement;void 0!==t.getBoundingClientRect&&(n=t.getBoundingClientRect());const a=Ce(t);return{left:n.left+a.left-(o.clientLeft||0)+s.left,top:n.top+a.top-(o.clientTop||0)+s.top}}(this.lower.el)}dispose(){G().dispose(this.lower.el),delete this.lower}}const Pe={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...et]};class je extends(Xt(Vt)){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 je.ownDefaults}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new Ee(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&&(B("warn","Canvas is trying to add an object that belongs to a different canvas.\nResulting to default behavior: removing object from previous canvas and adding to new canvas"),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}getRetinaScaling(){return this.enableRetinaScaling?q():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:i=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e){const e=A({width:this.width,height:this.height},t);this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}i||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const i=t,s=[...this.viewportTransform],r=$t(t,te(s));s[0]=e,s[3]=e;const n=$t(r,s);s[4]+=i.x-n.x,s[5]+=i.y-n.y,this.setViewportTransform(s)}setZoom(t){this.zoomToPoint(new It(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 It(-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=Yt((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,i=te(this.viewportTransform),s=$t({x:0,y:0},i),r=$t({x:t,y:e},i),n=s.min(r),o=s.max(r);return this.vptCoords={tl:n,tr:new It(o.x,n.y),bl:new It(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Wt(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.skipControlsDrawing||this.drawControls(t),s&&(s._set("canvas",this),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,s)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){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=xe(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 It(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new It(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new It(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 It(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new It(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return $t(this.getCenterPoint(),te(this.viewportTransform))}_centerObject(t,e){t.setXY(e,rt,rt),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 i=this.clipPath,s=i&&!i.excludeFromExport?this._toObject(i,t,e):null;return A(A(A({version:J},me(this,e)),{},{objects:this._objects.filter((t=>!t.excludeFromExport)).map((i=>this._toObject(i,t,e)))},this.__serializeBgOverlay(t,e)),s?{clipPath:s}:null)}_toObject(t,e,i){let s;this.includeDefaultValues||(s=t.includeDefaultValues,t.includeDefaultValues=!1);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 xe(n)?n.excludeFromExport||(i.background=n.toObject(e)):n&&(i.background=n),xe(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=R.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(ye(-t[4]/t[0],r)," ").concat(ye(-t[5]/t[3],r)," ").concat(ye(this.width/t[0],r)," ").concat(ye(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 ",J,"</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(zt()),'<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(xe(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?_e(s):""})}})).join("")}createSVGFontFacesMarkup(){const t=[],e={},i=R.fontPaths;this._objects.forEach((function e(i){t.push(i),Bt(i)&&i._objects.forEach(e)})),t.forEach((t=>{if(!(s=t)||"function"!=typeof s._renderText)return;var s;const{styles:r,fontFamily:n}=t;!e[n]&&i[n]&&(e[n]=!0,r&&Object.values(r).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(xe(i)){const s=i.repeat||"",r=this.width,n=this.height,o=this["".concat(e,"Vpt")]?_e(te(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||!we(i)?r:i.source.width,'" height="').concat("repeat-x"!==s&&"no-repeat"!==s||!we(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 X("`json` is undefined"));const s="string"==typeof t?JSON.parse(t):t,{objects:r=[],backgroundImage:n,background:o,overlayImage:a,overlay:c,clipPath:h}=s,l=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([fe(r,{reviver:e,signal:i}),pe({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:c,clipPath:h},{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=Ut(this);return 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 qt(this.toCanvasElement(n,t),e,i)}toBlob(){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 Kt(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,c=this.getZoom(),h=this.width,l=this.height,u=this.skipControlsDrawing,d=c*t,g=this.viewportTransform,f=[d,0,0,d,(g[4]-(s||0))*t,(g[5]-(r||0))*t],p=this.enableRetinaScaling,m=Ut({width:o,height:a}),v=n?this._objects.filter((t=>n(t))):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=f,this.width=o,this.height=a,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(m.getContext("2d"),v),this.viewportTransform=g,this.width=h,this.height=l,this.calcViewportBoundaries(),this.enableRetinaScaling=p,this.skipControlsDrawing=u,m}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Pt.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," }>")}}P(je,"ownDefaults",Pe);const Ae=["touchstart","touchmove","touchend"],Fe=t=>{const e=Ce(t.target),i=function(t){const e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new It(i.clientX+e.left,i.clientY+e.top)},Le=t=>Ae.includes(t.type)||"touch"===t.pointerType,Ie=t=>{t.preventDefault(),t.stopPropagation()},Re=t=>{let e=0,i=0,s=0,r=0;for(let n=0,o=t.length;n<o;n++){const{x:o,y:a}=t[n];(o>s||!n)&&(s=o),(o<e||!n)&&(e=o),(a>r||!n)&&(r=a),(a<i||!n)&&(i=a)}return{left:e,top:i,width:s-e,height:r-i}},Be=["translateX","translateY","scaleX","scaleY"],Xe=(t,e)=>Ve(t,ee(e,t.calcOwnMatrix())),Ve=(t,e)=>{const i=re(e),{translateX:s,translateY:r,scaleX:n,scaleY:o}=i,a=F(i,Be),c=new It(s,r);t.flipX=!1,t.flipY=!1,Object.assign(t,a),t.set({scaleX:n,scaleY:o}),t.setPositionByOrigin(c,rt,rt)},Ye=t=>{t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)},We=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=[new It(-s,-r),new It(s,-r),new It(-s,r),new It(s,r)].map((t=>t.transform(i))),o=Re(n);return new It(o.width,o.height)},ze=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:et;return ee(te(arguments.length>1&&void 0!==arguments[1]?arguments[1]:et),t)},Ge=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:et,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:et;return t.transform(ze(e,i))},Ne=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:et,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:et;return t.transform(ze(e,i),!0)},Ue=(t,e,i)=>{const s=ze(e,i);return Ve(t,ee(s,t.calcOwnMatrix())),s},qe=(t,e)=>{var i;const{transform:{target:s}}=e;null===(i=s.canvas)||void 0===i||i.fire("object:".concat(t),A(A({},e),{},{target:s})),s.fire(t,e)},Ke={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Je=t=>"string"==typeof t?Ke[t]:t-.5,Qe="not-allowed";function Ze(t){return Je(t.originX)===Je(rt)&&Je(t.originY)===Je(rt)}function $e(t){return.5-Je(t)}const ti=(t,e)=>t[e],ei=(t,e,i,s)=>({e:t,transform:e,pointer:new It(i,s)});function ii(t,e){const i=t.getTotalAngle()+Qt(Math.atan2(e.y,e.x))+360;return Math.round(i%360/45)}function si(t,e,i,s,r){var n;let{target:o,corner:a}=t;const c=o.controls[a],h=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/h,u=function(t,e,i,s){const r=t.getRelativeCenterPoint(),n=void 0!==i&&void 0!==s?t.translateToGivenOrigin(r,rt,rt,i,s):new It(t.left,t.top);return(t.angle?e.rotate(-Jt(t.angle),r):e).subtract(n)}(o,new It(s,r),e,i);return u.x>=l&&(u.x-=l),u.x<=-l&&(u.x+=l),u.y>=l&&(u.y-=l),u.y<=l&&(u.y+=l),u.x-=c.offsetX,u.y-=c.offsetY,u}const ri=(t,e,i,s)=>{const{target:r,offsetX:n,offsetY:o}=e,a=i-n,c=s-o,h=!ti(r,"lockMovementX")&&r.left!==a,l=!ti(r,"lockMovementY")&&r.top!==c;return h&&r.set(nt,a),l&&r.set(ot,c),(h||l)&&qe(ut,ei(t,e,i,s)),h||l},ni={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"},oi=(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),ai=(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 c=(r+n)/2;if(r===n)o=a=0;else{const s=r-n;switch(a=c>.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*c),s]},ci=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"1";return parseFloat(t)/(t.endsWith("%")?100:1)},hi=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),li=t=>{let[e,i,s,r=1]=t;const n=Math.round(.3*e+.59*i+.11*s);return[n,n,n,r]};class ui{constructor(t){if(P(this,"isUnrecognised",!1),t)if(t instanceof ui)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=t.toLowerCase())in ni&&(t=ni[t]),"transparent"===t?[255,255,255,0]:ui.sourceFromHex(t)||ui.sourceFromRgb(t)||ui.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[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]=ai(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(i,"%)")}toHsla(){const[t,e,i,s]=ai(...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(hi(t)).concat(hi(e)).concat(hi(i)).concat(hi(Math.round(255*s)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(li(this.getSource())),this}toBlackWhite(t){const[e,,,i]=li(this.getSource()),s=e<(t||127)?0:255;return this.setSource([s,s,s,i]),this}overlayWith(t){t instanceof ui||(t=new ui(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 ui.fromRgba(t)}static fromRgba(t){return new ui(ui.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,ci(e[4])]}}static fromHsl(t){return ui.fromHsla(t)}static fromHsla(t){return new ui(ui.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const i=(ui.parseAngletoDegrees(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=oi(e,t,i+1/3),o=oi(e,t,i),a=oi(e,t,i-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*a),ci(e[4])]}static fromHex(t){return new ui(ui.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]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),i=parseFloat(e);return e.includes("rad")?Qt(i):e.includes("turn")?360*i:i}}const di=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:it;const i=/\D{0,2}$/.exec(t),s=parseFloat(t),r=R.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}},gi=t=>{const[e,i]=t.trim().split(" "),[s,r]=(n=e)&&n!==ht?[n.slice(1,4),n.slice(5,8)]:n===ht?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:i||"meet",alignX:s,alignY:r}},fi=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 ui(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,'" '):"")};class pi{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",i=this.strokeWidth?this.strokeWidth:"0",s=this.strokeDashArray?this.strokeDashArray.join(" "):ht,r=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=void 0!==this.opacity?this.opacity:"1",h=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),u=fi(Tt,this.fill);return[fi(Ot,this.stroke),"stroke-width: ",i,"; ","stroke-dasharray: ",s,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",u,"fill-rule: ",e,"; ","opacity: ",c,";",l,h].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const i=t?this.calcTransformMatrix():this.calcOwnMatrix(),s='transform="'.concat(_e(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,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",h=a&&a.absolutePositioned,l=this.stroke,u=this.fill,d=this.shadow,g=[],f=t.indexOf("COMMON_PARTS");let p;a&&(a.clipPathId="CLIPPATH_".concat(zt()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(i),"</clipPath>\n")),h&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),h?"":o+this.getSvgCommons()," >\n");const m=[n,c,e?"":this.addPaintOrder()," ",r?'transform="'.concat(r,'" '):""].join("");return t[f]=m,xe(u)&&g.push(u.toSVG(this)),xe(l)&&g.push(l.toSVG(this)),d&&g.push(d.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),h&&g.push("</g>\n"),i?i(g.join("")):g.join("")}addPaintOrder(){return this.paintFirst!==Tt?' paint-order="'.concat(this.paintFirst,'" '):""}}function mi(t){return new RegExp("^("+t.join("|")+")\\b","i")}const vi="textDecorationThickness",yi=["fontSize","fontWeight","fontFamily","fontStyle"],_i=["underline","overline","linethrough"],xi=[...yi,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],bi=[...xi,..._i,"textBackgroundColor","direction",vi],wi=[...yi,..._i,Ot,"strokeWidth",Tt,"deltaY","textBackgroundColor",vi],Si={_reNewline:lt,_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:nt,fontStyle:"normal",lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:nt,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[vi]:66.667},Ci="justify",Ti="justify-left",Oi="justify-right",ki="justify-center";var Di,Mi,Ei;const Pi=String.raw(Di||(Di=L(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),ji=String.raw(Mi||(Mi=L(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),Ai=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Pi+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Pi+"))?\\s+(.*)"),Fi={cx:nt,x:nt,r:"radius",cy:ot,y:ot,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":vi},Li="font-size",Ii="clip-path";mi(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),mi(["symbol","image","marker","pattern","view","svg"]);const Ri=mi(["symbol","g","a","svg","clipPath","defs"]);new RegExp(String.raw(Ei||(Ei=L(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Pi,ji,Pi,ji,Pi,ji,Pi));const Bi=new It(1,0),Xi=new It,Vi=(t,e)=>t.rotate(e),Yi=(t,e)=>new It(e).subtract(t),Wi=t=>t.distanceFrom(Xi),Hi=(t,e)=>Math.atan2(Ui(t,e),qi(t,e)),zi=t=>Hi(Bi,t),Gi=t=>t.eq(Xi)?t:t.scalarDivide(Wi(t)),Ni=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return Gi(new It(-t.y,t.x).scalarMultiply(e?1:-1))},Ui=(t,e)=>t.x*e.y-t.y*e.x,qi=(t,e)=>t.x*e.x+t.y*e.y,Ki=(t,e,i)=>{if(t.eq(e)||t.eq(i))return!0;const s=Ui(e,i),r=Ui(e,t),n=Ui(i,t);return s>=0?r>=0&&n<=0:!(r<=0&&n>=0)},Ji="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Qi=new RegExp("(?:\\s|^)"+Ji+Ji+"("+Pi+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Zi{constructor(t){const e="string"==typeof t?Zi.parseShadow(t):t;Object.assign(this,Zi.ownDefaults,e),this.id=zt()}static parseShadow(t){const e=t.trim(),[,i=0,s=0,r=0]=(Qi.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(Qi,"")||"rgb(0,0,0)").trim(),offsetX:i,offsetY:s,blur:r}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Vi(new It(this.offsetX,this.offsetY),Jt(-t.angle)),i=new ui(this.color);let s=40,r=40;return t.width&&t.height&&(s=100*ye((Math.abs(e.x)+this.blur)/t.width,R.NUM_FRACTION_DIGITS)+20,r=100*ye((Math.abs(e.y)+this.blur)/t.height,R.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(ye(this.blur?this.blur/2:0,R.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(ye(e.x,R.NUM_FRACTION_DIGITS),'" dy="').concat(ye(e.y,R.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,type:this.constructor.type},e=Zi.ownDefaults;return this.includeDefaultValues?t:ve(t,((t,i)=>t!==e[i]))}static async fromObject(t){return new this(t)}}P(Zi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),P(Zi,"type","shadow"),Et.setClass(Zi,"shadow");const $i=(t,e,i)=>Math.max(t,Math.min(e,i)),ts=[ot,nt,bt,wt,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",St,Ct],es=[Tt,Ot,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],is={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:nt,originY:ot,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Tt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},ss=(t,e,i,s)=>(t<Math.abs(e)?(t=e,s=i/4):s=0===e&&0===t?i/$*Math.asin(1):i/$*Math.asin(e/t),{a:t,c:e,p:i,s:s}),rs=(t,e,i,s,r)=>t*Math.pow(2,10*(s-=1))*Math.sin((s*r-e)*$/i),ns=(t,e,i,s)=>-i*Math.cos(t/s*Z)+i+e,os=(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,as=(t,e,i,s)=>i-os(s-t,0,i,s)+e;var cs=Object.freeze({__proto__:null,defaultEasing:ns,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:as,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:c}=ss(r,i,n,1.70158);return-rs(o,a,c,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*as(2*t,0,i,s)+e:.5*os(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:c,c:h}=ss(r,i,n,1.70158);return t<1?-.5*rs(o,a,c,t,s)+e:o*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*$/c)*.5+h+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*Z)+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:os,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:c,c:h}=ss(r,i,n,1.70158);return o*2**(-10*t)*Math.sin((t*s-a)*$/c)+h+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*Z)+e});const hs=()=>!1;class ls{constructor(t){let{startValue:e,byValue:i,duration:s=500,delay:r=0,easing:n=ns,onStart:o=Q,onChange:a=Q,onComplete:c=Q,abort:h=hs,target:l}=t;P(this,"_state","pending"),P(this,"durationProgress",0),P(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=s,this.delay=r,this.easing=n,this._onStart=o,this._onChange=a,this._onComplete=c,this._abort=h,this.target=l,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((()=>Yt(t)),this.delay):Yt(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),Yt(this.tick)))}register(){Pt.push(this)}unregister(){Pt.remove(this)}abort(){this._state="aborted",this.unregister()}}const us=["startValue","endValue"];class ds extends ls{constructor(t){let{startValue:e=0,endValue:i=100}=t;super(A(A({},F(t,us)),{},{startValue:e,byValue:i-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const gs=["startValue","endValue"];class fs extends ls{constructor(t){let{startValue:e=[0],endValue:i=[100]}=t;super(A(A({},F(t,gs)),{},{startValue:e,byValue:i.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 ps=["startValue","endValue","easing","onChange","onComplete","abort"],ms=(t,e,i,s)=>e+i*(1-Math.cos(t/s*Z)),vs=t=>t&&((e,i,s)=>t(new ui(e).toRgba(),i,s));class ys extends ls{constructor(t){let{startValue:e,endValue:i,easing:s=ms,onChange:r,onComplete:n,abort:o}=t,a=F(t,ps);const c=new ui(e).getSource(),h=new ui(i).getSource();super(A(A({},a),{},{startValue:c,byValue:h.map(((t,e)=>t-c[e])),easing:s,onChange:vs(r),onComplete:vs(n),abort:vs(o)}))}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),$i(0,r,1)];return{value:n,valueProgress:n.map(((t,e)=>0!==this.byValue[e]?Math.abs((t-this.startValue[e])/this.byValue[e]):0)).find((t=>0!==t))||0}}}function _s(t){const e=(t=>Array.isArray(t.startValue)||Array.isArray(t.endValue))(t)?new fs(t):new ds(t);return e.start(),e}function xs(t){const e=new ys(t);return e.start(),e}class bs{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=Yi(e,i),n=Yi(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 It(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,c=s.x-i.x,h=s.y-i.y,l=t.x-i.x,u=t.y-i.y,d=c*u-h*l,g=o*u-a*l,f=h*o-c*a;if(0!==f){const e=d/f,i=g/f;return(r||0<=e&&e<=1)&&(n||0<=i&&i<=1)?new bs("Intersection").append(new It(t.x+e*o,t.y+e*a)):new bs}if(0===d||0===g){const o=r||n||bs.isPointContained(t,i,s)||bs.isPointContained(e,i,s)||bs.isPointContained(i,t,e)||bs.isPointContained(s,t,e);return new bs(o?"Coincident":void 0)}return new bs("Parallel")}static intersectSegmentLine(t,e,i,s){return bs.intersectLineLine(t,e,i,s,!1,!0)}static intersectSegmentSegment(t,e,i,s){return bs.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 bs,n=i.length;for(let o,a,c,h=0;h<n;h++){if(o=i[h],a=i[(h+1)%n],c=bs.intersectLineLine(t,e,o,a,s,!1),"Coincident"===c.status)return c;r.append(...c.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectSegmentPolygon(t,e,i){return bs.intersectLinePolygon(t,e,i,!1)}static intersectPolygonPolygon(t,e){const i=new bs,s=t.length,r=[];for(let n=0;n<s;n++){const o=t[n],a=t[(n+1)%s],c=bs.intersectSegmentPolygon(o,a,e);"Coincident"===c.status?(r.push(c),i.append(o,a)):i.append(...c.points)}return r.length>0&&r.length===t.length?new bs("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 It(r.x,s.y),o=new It(s.x,r.y);return bs.intersectPolygonPolygon(t,[s,n,r,o])}}class ws extends Vt{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?$t(t,this.group.calcTransformMatrix()):t}setXY(t,e,i){this.group&&(t=$t(t,te(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,i)}getRelativeXY(){return new It(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.originX,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.originY;this.setPositionByOrigin(t,e,i)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:i,bl:s}=this.aCoords||(this.aCoords=this.calcACoords()),r=[t,e,i,s];if(this.group){const t=this.group.calcTransformMatrix();return r.map((e=>$t(e,t)))}return r}intersectsWithRect(t,e){return"Intersection"===bs.intersectPolygonRectangle(this.getCoords(),t,e).status}intersectsWithObject(t){const e=bs.intersectPolygonPolygon(this.getCoords(),t.getCoords());return"Intersection"===e.status||"Coincident"===e.status||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every((e=>t.containsPoint(e)))}isContainedWithinRect(t,e){const{left:i,top:s,width:r,height:n}=this.getBoundingRect();return i>=t.x&&i+r<=e.x&&s>=t.y&&s+n<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return bs.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some((i=>i.x<=e.x&&i.x>=t.x&&i.y<=e.y&&i.y>=t.y))||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.intersectsWithRect(t,e)||this.getCoords().every((i=>(i.x>=e.x||i.x<=t.x)&&(i.y>=e.y||i.y<=t.y)))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return Re(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(bt,t),this._set(wt,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?Qt(se(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||et.concat()}calcACoords(){const t=oe({angle:this.angle}),{x:e,y:i}=this.getRelativeCenterPoint(),s=ne(e,i),r=ee(s,t),n=this._getTransformedDimensions(),o=n.x/2,a=n.y/2;return{tl:$t({x:-o,y:-a},r),tr:$t({x:o,y:-a},r),bl:$t({x:-o,y:a},r),br:$t({x:o,y:a},r)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Je(this.originX),Je(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const i=this.transformMatrixKey(t),s=this.matrixCache;return s&&s.key.every(((t,e)=>t===i[e]))?s.value:(this.group&&(e=ee(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=de(s);return this.ownMatrixCache={key:t,value:r},r}_getNonTransformedDimensions(){return new It(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=A({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),i=e.strokeWidth;let s=i,r=0;this.strokeUniform&&(s=0,r=i);const n=e.width+s,o=e.height+s;let a;return a=0===e.skewX&&0===e.skewY?new It(n*e.scaleX,o*e.scaleY):He(n,o,ue(e)),a.scalarAdd(r)}translateToGivenOrigin(t,e,i,s,r){let n=t.x,o=t.y;const a=Je(s)-Je(e),c=Je(r)-Je(i);if(a||c){const t=this._getTransformedDimensions();n+=a*t.x,o+=c*t.y}return new It(n,o)}translateToCenterPoint(t,e,i){if(e===rt&&i===rt)return t;const s=this.translateToGivenOrigin(t,e,i,rt,rt);return this.angle?s.rotate(Jt(this.angle),t):s}translateToOriginPoint(t,e,i){const s=this.translateToGivenOrigin(t,rt,rt,e,i);return this.angle?s.rotate(Jt(this.angle),t):s}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?$t(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new It(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(),nt,ot)}}const Ss=["type"],Cs=["extraParam"];let Ts=class t extends ws{static getDefaults(){return t.ownDefaults}get type(){const t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){B("warn","Setting type has no effect",t)}constructor(e){super(),P(this,"_cacheContext",null),Object.assign(this,t.ownDefaults),this.setOptions(e)}_createCacheCanvas(){this._cacheCanvas=Gt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,i=t.height,s=R.maxCacheSideLimit,r=R.minCacheSideLimit;if(e<=s&&i<=s&&e*i<=R.perfLimitSizeTotal)return e<r&&(t.width=r),i<r&&(t.height=r),t;const n=e/i,[o,a]=K.limitDimsByArea(n),c=$i(r,o,s),h=$i(r,a,s);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),i>h&&(t.zoomY/=i/h,t.height=h,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:Math.ceil(i+2),height:Math.ceil(s+2),zoomX:t.x,zoomY:t.y,x:i,y:s}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:i,height:s,zoomX:r,zoomY:n,x:o,y:a}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=i!==t.width||s!==t.height,h=this.zoomX!==r||this.zoomY!==n;if(!t||!e)return!1;if(c||h){i!==t.width||s!==t.height?(t.width=i,t.height=s):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const c=o/2,h=a/2;return this.cacheTranslationX=Math.round(t.width/2-c)+c,this.cacheTranslationY=Math.round(t.height/2-h)+h,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(r,n),this.zoomX=r,this.zoomY=n,!0}return!1}setOptions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,i=this.calcTransformMatrix(!e);t.transform(i[0],i[1],i[2],i[3],i[4],i[5])}getObjectScaling(){if(!this.group)return new It(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=re(this.calcTransformMatrix());return new It(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){t!==bt&&t!==wt||(e=this._constrainScale(e)),t===bt&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof Zi||(e=new Zi(e));const i=this[t]!==e;return this[t]=e,i&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||i&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return 0===this.opacity||!this.width&&!this.height&&0===this.strokeWidth||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:i,cacheTranslationX:s,cacheTranslationY:r}=this,{width:n,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:i,cacheTranslationX:s,cacheTranslationY:r,width:n,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth}hasFill(){return this.fill&&"transparent"!==this.fill}needsItsOwnCache(){return!!(this.paintFirst===Ot&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)}drawClipPathOnCache(t,e,i){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(i,0,0),t.restore()}drawObject(t,e,i){const s=this.fill,r=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,i),this.fill=s,this.stroke=r}createClipPathLayer(t,e){const i=Ut(e),s=i.getContext("2d");if(s.translate(e.cacheTranslationX,e.cacheTranslationY),s.scale(e.zoomX,e.zoomY),t._cacheCanvas=i,e.parentClipPaths.forEach((t=>{t.transform(s)})),e.parentClipPaths.push(t),t.absolutePositioned){const t=te(this.calcTransformMatrix());s.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return t.transform(s),t.drawObject(s,!0,e),i}_drawClipPath(t,e,i){if(!e)return;e._transformDone=!0;const s=this.createClipPathLayer(e,i);this.drawClipPathOnCache(t,e,s)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,i=this._cacheContext;return!(!e||!i||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&i&&!t&&(i.save(),i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,e.width,e.height),i.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;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,xe(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&&(xe(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&&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)||et,o=r*s,a=n*s,c=e.nonScaling?new It(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*R.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(!xe(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){this.paintFirst===Ot?(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=this.getCanvasRetinaScaling(),n=s.x/this.scaleX/r,o=s.y/this.scaleY/r,a=Ut({width:Math.ceil(n),height:Math.ceil(o)}),c=a.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(n,0),c.lineTo(n,o),c.lineTo(0,o),c.closePath(),c.translate(n/2,o/2),c.scale(s.zoomX/this.scaleX/r,s.zoomY/this.scaleY/r),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/s.zoomX,r*this.scaleY/s.zoomY),t.strokeStyle=null!==(i=c.createPattern(a,"no-repeat"))&&void 0!==i?i:"")}_findCenterFromElement(){return new It(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(Et.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=We(this),i=this.group,s=this.shadow,r=Math.abs,n=t.enableRetinaScaling?q():1,o=(t.multiplier||1)*n,a=t.canvasProvider||(t=>new je(t,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Ye(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Ue(this,this.getViewportTransform()),this.setCoords();const c=Gt(),h=this.getBoundingRect(),l=this.shadow,u=new It;if(l){const t=l.blur,e=l.nonScaling?new It(1,1):this.getObjectScaling();u.x=2*Math.round(r(l.offsetX)+t)*r(e.x),u.y=2*Math.round(r(l.offsetY)+t)*r(e.y)}const d=h.width+u.x,g=h.height+u.y;c.width=Math.ceil(d),c.height=Math.ceil(g);const f=a(c);"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new It(f.width/2,f.height/2),rt,rt);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 qt(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Kt(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=rt,this.originY=rt,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(){Pt.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&G().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce(((t,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.constructor.colorProperties.includes(s[s.length-1]),{abort:n,startValue:o,onChange:a,onComplete:c}=i,h=A(A({},i),{},{target:this,startValue:null!=o?o:s.reduce(((t,e)=>t[e]),this),endValue:e,abort:null==n?void 0:n.bind(this),onChange:(t,e,i)=>{s.reduce(((e,i,r)=>(r===s.length-1&&(e[i]=t),e[i])),this),a&&a(t,e,i)},onComplete:(t,e,i)=>{this.setCoords(),c&&c(t,e,i)}});return r?xs(h):_s(h)}isDescendantOf(t){const{parent:e,group:i}=this;return e===t||i===t||!!e&&e.isDescendantOf(t)||!!i&&i!==e&&i.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do{e=e.parent,e&&t.push(e)}while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),i=t.getAncestors();if(0===e.length&&i.length>0&&this===i[i.length-1])return{fork:[],otherFork:[t,...i.slice(0,i.length-1)],common:[this]};for(let s,r=0;r<e.length;r++){if(s=e[r],s===t)return{fork:[this,...e.slice(0,r)],otherFork:[],common:e.slice(r)};for(let n=0;n<i.length;n++){if(this===i[n])return{fork:[],otherFork:[t,...i.slice(0,n)],common:[this,...e]};if(s===i[n])return{fork:[this,...e.slice(0,r)],otherFork:[t,...i.slice(0,n)],common:e.slice(r)}}}return{fork:[this,...e],otherFork:[t,...i],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const i=e.common[0]||this.canvas;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}toObject(){const e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).concat(t.customProperties,this.constructor.customProperties||[]);let i;const s=R.NUM_FRACTION_DIGITS,{clipPath:r,fill:n,stroke:o,shadow:a,strokeDashArray:c,left:h,top:l,originX:u,originY:d,width:g,height:f,strokeWidth:p,strokeLineCap:m,strokeDashOffset:v,strokeLineJoin:y,strokeUniform:_,strokeMiterLimit:x,scaleX:b,scaleY:w,angle:S,flipX:C,flipY:T,opacity:O,visible:k,backgroundColor:D,fillRule:M,paintFirst:E,globalCompositeOperation:P,skewX:j,skewY:F}=this;r&&!r.excludeFromExport&&(i=r.toObject(e.concat("inverted","absolutePositioned")));const L=t=>ye(t,s),I=A(A({},me(this,e)),{},{type:this.constructor.type,version:J,originX:u,originY:d,left:L(h),top:L(l),width:L(g),height:L(f),fill:be(n)?n.toObject():n,stroke:be(o)?o.toObject():o,strokeWidth:L(p),strokeDashArray:c?c.concat():c,strokeLineCap:m,strokeDashOffset:v,strokeLineJoin:y,strokeUniform:_,strokeMiterLimit:L(x),scaleX:L(b),scaleY:L(w),angle:L(S),flipX:C,flipY:T,opacity:L(O),shadow:a?a.toObject():a,visible:k,backgroundColor:D,fillRule:M,paintFirst:E,globalCompositeOperation:P,skewX:L(j),skewY:L(F)},i?{clipPath:i}:null);return this.includeDefaultValues?I:this._removeDefaultValues(I)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),i=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return ve(t,((t,e)=>{if(e===nt||e===ot||"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,">")}static _fromObject(t){let e=F(t,Ss),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:s}=i,r=F(i,Cs);return pe(e,r).then((t=>s?(delete t[s],new this(e[s],t)):new this(t)))}static fromObject(t,e){return this._fromObject(t,e)}};P(Ts,"stateProperties",ts),P(Ts,"cacheProperties",es),P(Ts,"ownDefaults",is),P(Ts,"type","FabricObject"),P(Ts,"colorProperties",[Tt,Ot,"backgroundColor"]),P(Ts,"customProperties",[]),Et.setClass(Ts),Et.setClass(Ts,"object");const Os=(t,e,i)=>(s,r,n,o)=>{const a=e(s,r,n,o);return a&&qe(t,A(A({},ei(s,r,n,o)),i)),a};function ks(t){return(e,i,s,r)=>{const{target:n,originX:o,originY:a}=i,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=t(e,i,s,r);return n.setPositionByOrigin(h,i.originX,i.originY),l}}const Ds=Os(mt,ks(((t,e,i,s)=>{const r=si(e,e.originX,e.originY,i,s);if(Je(e.originX)===Je(rt)||Je(e.originX)===Je(ct)&&r.x<0||Je(e.originX)===Je(nt)&&r.x>0){const{target:t}=e,i=t.strokeWidth/(t.strokeUniform?t.scaleX:1),s=Ze(e)?2:1,n=t.width,o=Math.abs(r.x*s/t.scaleX)-i;return t.set("width",Math.max(o,1)),n!==t.width}return!1})));function Ms(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,c=a?Ot:Tt,h=!a&&(s.cornerStrokeColor||r.cornerStrokeColor);let l,u=e,d=i;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,t.scale(1,o/n),d=i*n/o):o>n?(l=o,t.scale(n/o,1),u=e*o/n):l=n,t.beginPath(),t.arc(u,d,l/2,0,$,!1),t[c](),h&&t.stroke(),t.restore()}function Es(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,c=a?Ot:Tt,h=!a&&(s.cornerStrokeColor||r.cornerStrokeColor),l=n/2,u=o/2;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",t.translate(e,i);const d=r.getTotalAngle();t.rotate(Jt(d)),t["".concat(c,"Rect")](-l,-u,n,o),h&&t.strokeRect(-l,-u,n,o),t.restore()}class Ps{constructor(t){P(this,"visible",!0),P(this,"actionName",xt),P(this,"angle",0),P(this,"x",0),P(this,"y",0),P(this,"offsetX",0),P(this,"offsetY",0),P(this,"sizeX",0),P(this,"sizeY",0),P(this,"touchSizeX",0),P(this,"touchSizeY",0),P(this,"cursorStyle","crosshair"),P(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,i,s){var r;let{tl:n,tr:o,br:a,bl:c}=s;return(null===(r=e.canvas)||void 0===r?void 0:r.getActiveObject())===e&&e.isControlVisible(t)&&bs.isPointInPolygon(i,[n,o,a,c])}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 It(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,i,s,r,n){const o=ie([ne(i,s),oe({angle:t}),ae((r?this.touchSizeX:this.sizeX)||e,(r?this.touchSizeY:this.sizeY)||e)]);return{tl:new It(-.5,-.5).transform(o),tr:new It(.5,-.5).transform(o),br:new It(.5,.5).transform(o),bl:new It(-.5,.5).transform(o)}}render(t,e,i,s,r){"circle"===((s=s||{}).cornerStyle||r.cornerStyle)?Ms.call(this,t,e,i,s,r):Es.call(this,t,e,i,s,r)}}const js=(t,e,i)=>i.lockRotation?Qe:e.cursorStyle,As=Os(gt,ks(((t,e,i,s)=>{let{target:r,ex:n,ey:o,theta:a,originX:c,originY:h}=e;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),c,h);if(ti(r,"lockRotation"))return!1;const u=Math.atan2(o-l.y,n-l.x),d=Math.atan2(s-l.y,i-l.x);let g=Qt(d-u+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 Fs(t,e){const i=e.canvas,s=t[i.uniScaleKey];return i.uniformScaling&&!s||!i.uniformScaling&&s}function Ls(t,e,i){const s=ti(t,"lockScalingX"),r=ti(t,"lockScalingY");if(s&&r)return!0;if(!e&&(s||r)&&i)return!0;if(s&&"x"===e)return!0;if(r&&"y"===e)return!0;const{width:n,height:o,strokeWidth:a}=t;return 0===n&&0===a&&"y"!==e||0===o&&0===a&&"x"!==e}const Is=["e","se","s","sw","w","nw","n","ne","e"],Rs=(t,e,i)=>{const s=Fs(t,i);if(Ls(i,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",s))return Qe;const r=ii(i,e);return"".concat(Is[r],"-resize")};function Bs(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=r.by,a=Fs(t,n);let c,h,l,u,d,g;if(Ls(n,o,a))return!1;if(e.gestureScale)h=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(c=si(e,e.originX,e.originY,i,s),d="y"!==o?Math.sign(c.x||e.signX||1):1,g="x"!==o?Math.sign(c.y||e.signY||1):1,e.signX||(e.signX=d),e.signY||(e.signY=g),ti(n,"lockScalingFlip")&&(e.signX!==d||e.signY!==g))return!1;if(u=n._getTransformedDimensions(),a&&!o){const t=Math.abs(c.x)+Math.abs(c.y),{original:i}=e,s=t/(Math.abs(u.x*i.scaleX/n.scaleX)+Math.abs(u.y*i.scaleY/n.scaleY));h=i.scaleX*s,l=i.scaleY*s}else h=Math.abs(c.x*n.scaleX/u.x),l=Math.abs(c.y*n.scaleY/u.y);Ze(e)&&(h*=2,l*=2),e.signX!==d&&"y"!==o&&(e.originX=$e(e.originX),h*=-1,e.signX=d),e.signY!==g&&"x"!==o&&(e.originY=$e(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set(bt,h),"y"===o&&n.set(wt,l)):(!ti(n,"lockScalingX")&&n.set(bt,h),!ti(n,"lockScalingY")&&n.set(wt,l)),f!==n.scaleX||p!==n.scaleY}const Xs=Os(dt,ks(((t,e,i,s)=>Bs(t,e,i,s)))),Vs=Os(dt,ks(((t,e,i,s)=>Bs(t,e,i,s,{by:"x"})))),Ys=Os(dt,ks(((t,e,i,s)=>Bs(t,e,i,s,{by:"y"})))),Ws=["target","ex","ey","skewingSide"],Hs={x:{counterAxis:"y",scale:bt,skew:St,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:wt,skew:Ct,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},zs=["ns","nesw","ew","nwse"],Gs=(t,e,i)=>{if(0!==e.x&&ti(i,"lockSkewingY"))return Qe;if(0!==e.y&&ti(i,"lockSkewingX"))return Qe;const s=ii(i,e)%4;return"".concat(zs[s],"-resize")};function Ns(t,e,i,s,r){const{target:n}=i,{counterAxis:o,origin:a,lockSkewing:c,skew:h,flip:l}=Hs[t];if(ti(n,c))return!1;const{origin:u,flip:d}=Hs[o],g=Je(i[u])*(n[d]?-1:1),f=-Math.sign(g)*(n[l]?-1:1),p=-(0===n[h]&&si(i,rt,rt,s,r)[t]>0||n[h]>0?1:-1)*f*.5+.5,m=Os(pt,ks(((e,i,s,r)=>function(t,e,i){let{target:s,ex:r,ey:n,skewingSide:o}=e,a=F(e,Ws);const{skew:c}=Hs[t],h=i.subtract(new It(r,n)).divide(new It(s.scaleX,s.scaleY))[t],l=s[c],u=a[c],d=Math.tan(Jt(u)),g="y"===t?s._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:s._getTransformedDimensions({scaleX:1,scaleY:1}).y,f=2*h*o/Math.max(g,1)+d,p=Qt(Math.atan(f));s.set(c,p);const m=l!==s[c];if(m&&"y"===t){const{skewX:t,scaleX:e}=s,i=s._getTransformedDimensions({skewY:l}),r=s._getTransformedDimensions(),n=0!==t?i.x/r.x:1;1!==n&&s.set(bt,n*e)}return m}(t,i,new It(s,r)))));return m(e,A(A({},i),{},{[a]:p,skewingSide:f}),s,r)}const Us=(t,e,i,s)=>Ns("x",t,e,i,s),qs=(t,e,i,s)=>Ns("y",t,e,i,s);function Ks(t,e){return t[e.canvas.altActionKey]}const Js=(t,e,i)=>{const s=Ks(t,i);return 0===e.x?s?St:wt:0===e.y?s?Ct:bt:""},Qs=(t,e,i)=>Ks(t,i)?Gs(0,e,i):Rs(t,e,i),Zs=(t,e,i,s)=>Ks(t,e.target)?qs(t,e,i,s):Vs(t,e,i,s),$s=(t,e,i,s)=>Ks(t,e.target)?Us(t,e,i,s):Ys(t,e,i,s),tr=()=>({ml:new Ps({x:-.5,y:0,cursorStyleHandler:Qs,actionHandler:Zs,getActionName:Js}),mr:new Ps({x:.5,y:0,cursorStyleHandler:Qs,actionHandler:Zs,getActionName:Js}),mb:new Ps({x:0,y:.5,cursorStyleHandler:Qs,actionHandler:$s,getActionName:Js}),mt:new Ps({x:0,y:-.5,cursorStyleHandler:Qs,actionHandler:$s,getActionName:Js}),tl:new Ps({x:-.5,y:-.5,cursorStyleHandler:Rs,actionHandler:Xs}),tr:new Ps({x:.5,y:-.5,cursorStyleHandler:Rs,actionHandler:Xs}),bl:new Ps({x:-.5,y:.5,cursorStyleHandler:Rs,actionHandler:Xs}),br:new Ps({x:.5,y:.5,cursorStyleHandler:Rs,actionHandler:Xs}),mtr:new Ps({x:0,y:-.5,actionHandler:As,cursorStyleHandler:js,offsetY:-40,withConnection:!0,actionName:ft})}),er=()=>({mr:new Ps({x:.5,y:0,actionHandler:Ds,cursorStyleHandler:Qs,actionName:mt}),ml:new Ps({x:-.5,y:0,actionHandler:Ds,cursorStyleHandler:Qs,actionName:mt})}),ir=()=>A(A({},tr()),er());class sr extends Ts{static getDefaults(){return A(A({},super.getDefaults()),sr.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),sr.ownDefaults),this.setOptions(t)}static createControls(){return{controls:tr()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,i=e.target,s=e.action;if(this===i&&s&&s.startsWith(xt))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const i=Object.entries(this.oCoords);for(let s=i.length-1;s>=0;s--){const[r,n]=i[s],o=this.controls[r];if(o.shouldActivate(r,this,t,e?n.touchCorner:n.corner))return this.__corner=r,{key:r,control:o,coord:this.oCoords[r]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),i=ne(e.x,e.y),s=oe({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),r=ee(i,s),n=ee(t,r),o=ee(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?re(this.calcTransformMatrix()):void 0;a&&(a.scaleX=Math.abs(a.scaleX),a.scaleY=Math.abs(a.scaleY));const c=this._calculateCurrentDimensions(a),h={};return this.forEachControl(((t,e)=>{const i=t.positionHandler(c,o,this,t);h[e]=Object.assign(i,this._calcCornerCoords(t,i))})),h}_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(Jt(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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=A({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},i);t.save(),t.strokeStyle=s.borderColor,this._setLineDash(t,s.borderDashArray),this.strokeBorders(t,e),s.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{hasBorders:i,hasControls:s}=this,r=A({hasBorders:i,hasControls:s},e),n=this.getViewportTransform(),o=r.hasBorders,a=r.hasControls,c=ee(n,this.calcTransformMatrix()),h=re(c);t.save(),t.translate(h.translateX,h.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(h.angle-=180),t.rotate(Jt(this.group?h.angle:this.angle)),o&&this.drawBorders(t,h,e),a&&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,ue(e)),i=this.isStrokeAccountedForInDimensions()?Rt:(this.strokeUniform?(new It).scalarAdd(this.canvas?this.canvas.getZoom():1):new It(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 i=this.getCanvasRetinaScaling(),{cornerStrokeColor:s,cornerDashArray:r,cornerColor:n}=this,o=A({cornerStrokeColor:s,cornerDashArray:r,cornerColor:n},e);t.setTransform(i,0,0,i,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl(((e,i)=>{if(e.getVisibility(this,i)){const s=this.oCoords[i];e.render(t,s.x,s.y,o,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}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function rr(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}P(sr,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class nr extends sr{}rr(nr,[pi]),Et.setClass(nr),Et.setClass(nr,"object");const or=(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};class ar{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new It(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new It(1/this.options.scaleX,1/this.options.scaleY):new It(1,1)}createSideVector(t,e){const i=Yi(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 It(t);return e.y+=e.x*Math.tan(Jt(this.options.skewY)),e.x+=e.y*Math.tan(Jt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const cr=new It;class hr extends ar{static getOrthogonalRotationFactor(t,e){const i=e?Hi(t,e):zi(t);return Math.abs(i)<Z?-1:1}constructor(t,e,i,s){super(s),P(this,"AB",void 0),P(this,"AC",void 0),P(this,"alpha",void 0),P(this,"bisector",void 0),this.A=new It(t),this.B=new It(e),this.C=new It(i),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Hi(this.AB,this.AC),this.bisector=Gi(Vi(this.AB.eq(cr)?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=Ni(s),n=hr.getOrthogonalRotationFactor(r,this.bisector);return this.scaleUnitVector(r,i*n)}projectBevel(){const t=[];return(this.alpha%$==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?Wi(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Wi(s)/this.strokeProjectionMagnitude<=r&&t.push(this.applySkew(this.A.add(s))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const i=[],s=new It(hr.getOrthogonalRotationFactor(this.bisector),hr.getOrthogonalRotationFactor(new It(this.bisector.y,this.bisector.x)));return[new It(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s),new It(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s)].forEach((s=>{Ki(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,c=new It(Math.tan(Jt(s)),Math.tan(Jt(r))),h=this.strokeProjectionMagnitude,l=a?h/o/Math.sqrt(1/o**2+1/n**2*c.y**2):h/Math.sqrt(1+c.y**2),u=new It(Math.sqrt(Math.max(h**2-l**2,0)),l),d=a?h/Math.sqrt(1+c.x**2*(1/o)**2/(1/n+1/n*c.x*c.y)**2):h/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),g=new It(d,Math.sqrt(Math.max(h**2-d**2,0)));return[g,g.scalarMultiply(-1),u,u.scalarMultiply(-1)].map((t=>this.applySkew(a?t.multiply(this.strokeUniformScalar):t))).forEach((s=>{Ki(s,t,e)&&i.push(this.applySkew(this.A).add(s))})),i}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%$==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=Ui(s,n)>0,a=o?s:r,c=o?r:s;return this.isSkewed()?t.push(...this.projectRoundWithSkew(a,c)):t.push(...this.projectRoundNoSkew(a,c)),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 lr extends ar{constructor(t,e,i){super(i),this.A=new It(t),this.T=new It(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(Ni(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 It(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 hr(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new It(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(Gi(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 ur=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 It(e)),t)),[new It(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]))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 lr(t,t,e).project()):!i||0!==r&&r!==n.length-1?s.push(...new hr(t,o,a,e).project()):s.push(...new lr(t,0===r?a:o,e).project())})),s},dr=t=>{const e={};return Object.keys(t).forEach((i=>{e[i]={},Object.keys(t[i]).forEach((s=>{e[i][s]=A({},t[i][s])}))})),e},gr=t=>t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">");let fr;const pr=t=>{if(fr||fr||(fr="Intl"in U()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),fr){const e=fr.segment(t);return Array.from(e).map((t=>{let{segment:e}=t;return e}))}return mr(t)},mr=t=>{const e=[];for(let i,s=0;s<t.length;s++)!1!==(i=vr(t,s))&&e.push(i);return e},vr=(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 yr=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:gr,graphemeSplit:pr});const _r=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.textDecorationThickness!==e.textDecorationThickness||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||i&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},xr=(t,e)=>{const i=e.split("\n"),s=[];let r=-1,n={};t=dr(t);for(let e=0;e<i.length;e++){const o=pr(i[e]);if(t[e])for(let i=0;i<o.length;i++){r++;const o=t[e][i];o&&Object.keys(o).length>0&&(_r(n,o,!0)?s.push({start:r,end:r+1,style:o}):s[s.length-1].end++),n=o||{}}else r+=o.length,n={}}return s},br=(t,e)=>{if(!Array.isArray(t))return dr(t);const i=e.split(lt),s={};let r=-1,n=0;for(let e=0;e<i.length;e++){const o=pr(i[e]);for(let i=0;i<o.length;i++)r++,t[n]&&t[n].start<=r&&r<t[n].end&&(s[e]=s[e]||{},s[e][i]=A({},t[n].style),r===t[n].end-1&&n++)}return s},wr=["display","transform",Tt,"fill-opacity","fill-rule","opacity",Ot,"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 Sr(t,e){const i=t.nodeName,s=t.getAttribute("class"),r=t.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let o;if(o=new RegExp("^"+i,"i"),e=e.replace(o,""),r&&e.length&&(o=new RegExp("#"+r+n,"i"),e=e.replace(o,"")),s&&e.length){const t=s.split(" ");for(let i=t.length;i--;)o=new RegExp("\\."+t[i]+n,"i"),e=e.replace(o,"")}return 0===e.length}function Cr(t,e){let i=!0;const s=Sr(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=Sr(t=t.parentElement,i);return 0===e.length}(t,e)),s&&i&&0===e.length}const Tr=t=>{var e;return null!==(e=Fi[t])&&void 0!==e?e:t},Or=new RegExp("(".concat(Pi,")"),"gi");var kr,Dr,Mr,Er,Pr,jr,Ar;const Fr="(".concat(Pi,")"),Lr=String.raw(kr||(kr=L(["(skewX)(",")"],["(skewX)\\(","\\)"])),Fr),Ir=String.raw(Dr||(Dr=L(["(skewY)(",")"],["(skewY)\\(","\\)"])),Fr),Rr=String.raw(Mr||(Mr=L(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Fr,Fr,Fr),Br=String.raw(Er||(Er=L(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Fr,Fr),Xr=String.raw(Pr||(Pr=L(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Fr,Fr),Vr=String.raw(jr||(jr=L(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Fr,Fr,Fr,Fr,Fr,Fr),Yr="(?:".concat(Vr,"|").concat(Xr,"|").concat(Rr,"|").concat(Br,"|").concat(Lr,"|").concat(Ir,")"),Wr="(?:".concat(Yr,"*)"),Hr=String.raw(Ar||(Ar=L(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Wr),zr=new RegExp(Hr),Gr=new RegExp(Yr),Nr=new RegExp(Yr,"g");function Ur(t){const e=[];if(!(t=(t=>t.replace(Or," $1 ").replace(/,/gi," ").replace(/\s+/gi," "))(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!zr.test(t))return[...et];for(const i of t.matchAll(Nr)){const t=Gr.exec(i[0]);if(!t)continue;let s=et;const r=t.filter((t=>!!t)),[,n,...o]=r,[a,c,h,l,u,d]=o.map((t=>parseFloat(t)));switch(n){case"translate":s=ne(a,c);break;case ft:s=oe({angle:a},{x:c,y:h});break;case xt:s=ae(a,c);break;case St:s=he(a);break;case Ct:s=le(a);break;case"matrix":s=[a,c,h,l,u,d]}e.push(s)}return ie(e)}function qr(t,e,i,s){const r=Array.isArray(e);let n,o=e;if(t!==Tt&&t!==Ot||e!==ht){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)o=e===ht?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)o=i&&i.transformMatrix?ee(i.transformMatrix,Ur(e)):Ur(e);else if("visible"===t)o=e!==ht&&"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?nt:"end"===e?ct:rt;else if("charSpacing"===t||t===vi)n=di(e,s)/s*1e3;else if("paintFirst"===t){const t=e.indexOf(Tt),i=e.indexOf(Ot);o=Tt,(t>-1&&i>-1&&i<t||-1===t&&i>-1)&&(o=Ot)}else{if("href"===t||"xlink:href"===t||"font"===t||"id"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=r?e.map(di):di(e,s)}}else o="";return!r&&isNaN(n)?o:n}const Kr={stroke:"strokeOpacity",fill:"fillOpacity"};function Jr(t,e,i){if(!t)return{};let s,r={},n=it;t.parentNode&&Ri.test(t.parentNode.nodeName)&&(r=Jr(t.parentElement,e,i),r.fontSize&&(s=n=di(r.fontSize)));const o=A(A(A({},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]:{},i={};for(const s in e)Cr(t,s.split(" "))&&(i=A(A({},i),e[s]));return i}(t,i)),function(t){const e={},i=t.getAttribute("style");return i?("string"==typeof i?function(t,e){t.replace(/;\s*$/,"").split(";").forEach((t=>{if(!t)return;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}(t));o[Ii]&&t.setAttribute(Ii,o[Ii]),o[Li]&&(s=di(o[Li],n),o[Li]="".concat(s));const a={};for(const t in o){const e=Tr(t),i=qr(e,o[t],r,s);a[e]=i}a&&a.font&&function(t,e){const i=t.match(Ai);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=di(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}(a.font,a);const c=A(A({},r),a);return Ri.test(t.nodeName)?c:function(t){const e=nr.getDefaults();return Object.entries(Kr).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 ui(t[s]);t[s]=n.setAlpha(ye(n.getAlpha()*t[r],2)).toRgba()})),t}(c)}const Qr=["left","top","width","height","visible"],Zr=["rx","ry"];class $r extends nr{static getDefaults(){return A(A({},super.getDefaults()),$r.ownDefaults)}constructor(t){super(),Object.assign(this,$r.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height: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-st*n,r,s+e,r+st*o,s+e,r+o),t.lineTo(s+e,r+i-o),a&&t.bezierCurveTo(s+e,r+i-st*o,s+e-st*n,r+i,s+e-n,r+i),t.lineTo(s+n,r+i),a&&t.bezierCurveTo(s+st*n,r+i,s,r+i-st*o,s,r+i-o),t.lineTo(s,r+o),a&&t.bezierCurveTo(s,r+st*o,s+st*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([...Zr,...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,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i),{left:r=0,top:n=0,width:o=0,height:a=0,visible:c=!0}=s,h=F(s,Qr);return new this(A(A(A({},e),h),{},{left:r,top:n,width:o,height:a,visible:Boolean(c&&o&&a)}))}}P($r,"type","Rect"),P($r,"cacheProperties",[...es,...Zr]),P($r,"ownDefaults",{rx:0,ry:0}),P($r,"ATTRIBUTE_NAMES",[...wr,"x","y","rx","ry","width","height"]),Et.setClass($r),Et.setSVGClass($r);const tn="initialization",en="added",sn="removed",rn="imperative",nn=(t,e)=>{const{strokeUniform:i,strokeWidth:s,width:r,height:n,group:o}=e,a=o&&o!==t?ze(o.calcTransformMatrix(),t.calcTransformMatrix()):null,c=a?e.getRelativeCenterPoint().transform(a):e.getRelativeCenterPoint(),h=!e.isStrokeAccountedForInDimensions(),l=i&&h?Ne(new It(s,s),void 0,t.calcTransformMatrix()):Rt,u=!i&&h?s:0,d=He(r+u,n+u,ie([a,e.calcOwnMatrix()],!0)).add(l).scalarDivide(2);return[c.subtract(d),c.add(d)]};class on{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:i,strategy:s}=t;return e===tn||e===rn||!!i&&s!==i}shouldLayoutClipPath(t){let{type:e,target:{clipPath:i}}=t;return e!==tn&&i&&!i.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:i,target:s}=e;if(i===rn&&e.overrides)return e.overrides;if(0===t.length)return;const{left:r,top:n,width:o,height:a}=Re(t.map((t=>nn(s,t))).reduce(((t,e)=>t.concat(e)),[])),c=new It(o,a),h=new It(r,n).add(c.scalarDivide(2));if(i===tn){const t=this.getInitialSize(e,{size:c,center:h});return{center:h,relativeCorrection:new It(0,0),size:t}}return{center:h.transform(s.calcOwnMatrix()),size:c}}}P(on,"type","strategy");class an extends on{shouldPerformLayout(t){return!0}}P(an,"type","fit-content"),Et.setClass(an);const cn=["strategy"],hn=["target","strategy","bubbles","prevStrategy"],ln="layoutManager";class un{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new an;P(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=A(A({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const i=this.getLayoutResult(e);i&&this.commitLayout(e,i),this.onAfterLayout(e,i),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:i}=e;return[kt,ut,mt,gt,dt,pt,_t,vt,yt].map((e=>t.on(e,(t=>this.performLayout(e===kt?{type:"object_modified",trigger:e,e:t,target:i}:{type:"object_modifying",trigger:e,e:t,target:i})))))}subscribe(t,e){this.unsubscribe(t,e);const i=this.attachHandlers(t,e);this._subscriptions.set(t,i)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach((t=>t())),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach((e=>this.unsubscribe(e,t)))}subscribeTargets(t){t.targets.forEach((e=>this.subscribe(e,t)))}onBeforeLayout(t){const{target:e,type:i}=t,{canvas:s}=e;if(i===tn||i===en?this.subscribeTargets(t):i===sn&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),s&&s.fire("object:layout:before",{target:e,context:t}),i===rn&&t.deep){const i=F(t,cn);e.forEachObject((t=>t.layoutManager&&t.layoutManager.performLayout(A(A({},i),{},{bubbles:!1,target:t}))))}}getLayoutResult(t){const{target:e,strategy:i,type:s}=t,r=i.calcLayoutResult(t,e.getObjects());if(!r)return;const n=s===tn?new It:e.getRelativeCenterPoint(),{center:o,correction:a=new It,relativeCorrection:c=new It}=r,h=n.subtract(o).add(a).transform(s===tn?et:te(e.calcOwnMatrix()),!0).add(c);return{result:r,prevCenter:n,nextCenter:o,offset:h}}commitLayout(t,e){const{target:i}=t,{result:{size:s},nextCenter:r}=e;var n,o;i.set({width:s.x,height:s.y}),this.layoutObjects(t,e),t.type===tn?i.set({left:null!==(n=t.x)&&void 0!==n?n:r.x+s.x*Je(i.originX),top:null!==(o=t.y)&&void 0!==o?o:r.y+s.y*Je(i.originY)}):(i.setPositionByOrigin(r,rt,rt),i.setCoords(),i.set("dirty",!0))}layoutObjects(t,e){const{target:i}=t;i.forEachObject((s=>{s.group===i&&this.layoutObject(t,e,s)})),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,i.clipPath)}layoutObject(t,e,i){let{offset:s}=e;i.set({left:i.left+s.x,top:i.top+s.y})}onAfterLayout(t,e){const{target:i,strategy:s,bubbles:r,prevStrategy:n}=t,o=F(t,hn),{canvas:a}=i;i.fire("layout:after",{context:t,result:e}),a&&a.fire("object:layout:after",{context:t,result:e,target:i});const c=i.parent;r&&null!=c&&c.layoutManager&&((o.path||(o.path=[])).push(i),c.layoutManager.performLayout(A(A({},o),{},{target:c}))),i.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach((t=>t.forEach((t=>t())))),t.clear()}toObject(){return{type:ln,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}Et.setClass(un,ln);const dn=["type","objects","layoutManager"];class gn extends un{performLayout(){}}class fn extends(Xt(nr)){static getDefaults(){return A(A({},super.getDefaults()),fn.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),P(this,"_activeObjects",[]),P(this,"__objectSelectionTracker",void 0),P(this,"__objectSelectionDisposer",void 0),Object.assign(this,fn.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var i;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject((t=>{this.enterGroup(t,!1)})),this.layoutManager=null!==(i=e.layoutManager)&&void 0!==i?i:new un,this.layoutManager.performLayout({type:tn,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(B("error","Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(B("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(en,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(en,r),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(sn,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const i=this[t];return super._set(t,e),"canvas"===t&&i!==e&&(this._objects||[]).forEach((i=>{i._set(t,e)})),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:i}=e;const s=this._activeObjects;if(t)s.push(i),this._set("dirty",!0);else if(s.length>0){const t=s.indexOf(i);t>-1&&(s.splice(t,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Ve(t,ee(te(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),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("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Ve(t,ee(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=nr.prototype.shouldCache.call(this);if(t)for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return this.ownCaching=!1,!1;return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,i){this._renderBackground(t);for(let e=0;e<this._objects.length;e++){var s;const i=this._objects[e];null!==(s=this.canvas)&&void 0!==s&&s.preserveObjectStacking&&i.group!==this?(t.save(),t.transform(...te(this.calcTransformMatrix())),i.render(t),t.restore()):i.group===this&&i.render(t)}this._drawClipPath(t,this.clipPath,i)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}triggerLayout(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.layoutManager.performLayout(A({target:this,type:rn},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__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]:[];const e=this.layoutManager.toObject();return A(A(A({},super.toObject(["subTargetCheck","interactive",...t])),"fit-content"!==e.strategy||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject((t=>{this._watchObject(!1,t),t.dispose()})),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=$r.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,e){let{type:i,objects:s=[],layoutManager:r}=t,n=F(t,dn);return Promise.all([fe(s,e),pe(n,e)]).then((t=>{let[e,i]=t;const s=new this(e,A(A(A({},n),i),{},{layoutManager:new gn}));if(r){const t=Et.getClass(r.type),e=Et.getClass(r.strategy);s.layoutManager=new t(new e)}else s.layoutManager=new un;return s.layoutManager.subscribeTargets({type:tn,target:s,targets:s.getObjects()}),s.setCoords(),s}))}}P(fn,"type","Group"),P(fn,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),Et.setClass(fn);const pn=(t,e)=>Math.min(e.width/t.width,e.height/t.height),mn=(t,e)=>Math.max(e.width/t.width,e.height/t.height),vn="\\s*,?\\s*",yn="".concat(vn,"(").concat(Pi,")"),_n="".concat(yn).concat(yn).concat(yn).concat(vn,"([01])").concat(vn,"([01])").concat(yn).concat(yn),xn={m:"l",M:"L"},bn=(t,e,i,s,r,n,o,a,c,h,l)=>{const u=Ft(t),d=Lt(t),g=Ft(e),f=Lt(e),p=i*r*g-s*n*f+o,m=s*r*g+i*n*f+a;return["C",h+c*(-i*r*d-s*n*u),l+c*(-s*r*d+i*n*u),p+c*(i*r*f+s*n*g),m+c*(s*r*f-i*n*g),p,m]},wn=(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 Sn(t,e,i,s,r,n,o,a){let c;if(R.cachesBoundsOfCurve&&(c=[...arguments].join(),K.boundsOfCurveCache[c]))return K.boundsOfCurveCache[c];const h=Math.sqrt,l=Math.abs,u=[],d=[[0,0],[0,0]];let g=6*t-12*i+6*r,f=-3*t+9*i-9*r+3*o,p=3*i-3*t;for(let t=0;t<2;++t){if(t>0&&(g=6*e-12*s+6*n,f=-3*e+9*s-9*n+3*a,p=3*s-3*e),l(f)<1e-12){if(l(g)<1e-12)continue;const t=-p/g;0<t&&t<1&&u.push(t);continue}const i=g*g-4*p*f;if(i<0)continue;const r=h(i),o=(-g+r)/(2*f);0<o&&o<1&&u.push(o);const c=(-g-r)/(2*f);0<c&&c<1&&u.push(c)}let m=u.length;const v=m,y=kn(t,e,i,s,r,n,o,a);for(;m--;){const{x:t,y:e}=y(u[m]);d[0][m]=t,d[1][m]=e}d[0][v]=t,d[1][v]=e,d[0][v+1]=o,d[1][v+1]=a;const _=[new It(Math.min(...d[0]),Math.min(...d[1])),new It(Math.max(...d[0]),Math.max(...d[1]))];return R.cachesBoundsOfCurve&&(K.boundsOfCurveCache[c]=_),_}const Cn=(t,e,i)=>{let[s,r,n,o,a,c,h,l]=i;const u=((t,e,i,s,r,n,o)=>{if(0===i||0===s)return[];let a=0,c=0,h=0;const l=Math.PI,u=o*tt,d=Lt(u),g=Ft(u),f=.5*(-g*t-d*e),p=.5*(-g*e+d*t),m=i**2,v=s**2,y=p**2,_=f**2,x=m*v-m*y-v*_;let b=Math.abs(i),w=Math.abs(s);if(x<0){const t=Math.sqrt(1-x/(m*v));b*=t,w*=t}else h=(r===n?-1:1)*Math.sqrt(x/(m*y+v*_));const S=h*b*p/w,C=-h*w*f/b,T=g*S-d*C+.5*t,O=d*S+g*C+.5*e;let k=wn(1,0,(f-S)/b,(p-C)/w),D=wn((f-S)/b,(p-C)/w,(-f-S)/b,(-p-C)/w);0===n&&D>0?D-=2*l:1===n&&D<0&&(D+=2*l);const M=Math.ceil(Math.abs(D/l*2)),E=[],P=D/M,j=8/3*Math.sin(P/4)*Math.sin(P/4)/Math.sin(P/2);let A=k+P;for(let t=0;t<M;t++)E[t]=bn(k,A,g,d,b,w,T,O,j,a,c),a=E[t][5],c=E[t][6],k=A,A+=P;return E})(h-t,l-e,r,n,a,c,o);for(let i=0,s=u.length;i<s;i++)u[i][1]+=t,u[i][2]+=e,u[i][3]+=t,u[i][4]+=e,u[i][5]+=t,u[i][6]+=e;return u},Tn=t=>{let e=0,i=0,s=0,r=0;const n=[];let o,a=0,c=0;for(const h of t){const t=[...h];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],c=t[4],e=t[5],i=t[6],l=["C",t[1],t[2],a,c,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,c=2*i-c):(a=e,c=i),e=t[3],i=t[4],l=["C",a,c,t[1],t[2],e,i],a=l[3],c=l[4];break;case"q":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"Q":a=t[1],c=t[2],e=t[3],i=t[4],l=["Q",a,c,e,i];break;case"t":t[1]+=e,t[2]+=i;case"T":"Q"===o?(a=2*e-a,c=2*i-c):(a=e,c=i),e=t[1],i=t[2],l=["Q",a,c,e,i];break;case"a":t[6]+=e,t[7]+=i;case"A":Cn(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},On=(t,e,i,s)=>Math.sqrt((i-t)**2+(s-e)**2),kn=(t,e,i,s,r,n,o,a)=>c=>{const h=c**3,l=(t=>3*t**2*(1-t))(c),u=(t=>3*t*(1-t)**2)(c),d=(t=>(1-t)**3)(c);return new It(o*h+r*l+i*u+t*d,a*h+n*l+s*u+e*d)},Dn=t=>t**2,Mn=t=>2*t*(1-t),En=t=>(1-t)**2,Pn=(t,e,i,s,r,n,o,a)=>c=>{const h=Dn(c),l=Mn(c),u=En(c),d=3*(u*(i-t)+l*(r-i)+h*(o-r)),g=3*(u*(s-e)+l*(n-s)+h*(a-n));return Math.atan2(g,d)},jn=(t,e,i,s,r,n)=>o=>{const a=Dn(o),c=Mn(o),h=En(o);return new It(r*a+i*c+t*h,n*a+s*c+e*h)},An=(t,e,i,s,r,n)=>o=>{const a=1-o,c=2*(a*(i-t)+o*(r-i)),h=2*(a*(s-e)+o*(n-s));return Math.atan2(h,c)},Fn=(t,e,i)=>{let s=new It(e,i),r=0;for(let e=1;e<=100;e+=1){const i=t(e/100);r+=On(s.x,s.y,i.x,i.y),s=i}return r},Ln=t=>{let e,i,s=0,r=0,n=0,o=0,a=0;const c=[];for(const h of t){const t={x:r,y:n,command:h[0],length:0};switch(h[0]){case"M":i=t,i.x=o=r=h[1],i.y=a=n=h[2];break;case"L":i=t,i.length=On(r,n,h[1],h[2]),r=h[1],n=h[2];break;case"C":e=kn(r,n,h[1],h[2],h[3],h[4],h[5],h[6]),i=t,i.iterator=e,i.angleFinder=Pn(r,n,h[1],h[2],h[3],h[4],h[5],h[6]),i.length=Fn(e,r,n),r=h[5],n=h[6];break;case"Q":e=jn(r,n,h[1],h[2],h[3],h[4]),i=t,i.iterator=e,i.angleFinder=An(r,n,h[1],h[2],h[3],h[4]),i.length=Fn(e,r,n),r=h[3],n=h[4];break;case"Z":i=t,i.destX=o,i.destY=a,i.length=On(r,n,o,a),r=o,n=a}s+=i.length,c.push(i)}return c.push({length:s,x:r,y:n}),c},In=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ln(t),s=0;for(;e-i[s].length>0&&s<i.length-2;)e-=i[s].length,s++;const r=i[s],n=e/r.length,o=t[s];switch(r.command){case"M":return{x:r.x,y:r.y,angle:0};case"Z":return A(A({},new It(r.x,r.y).lerp(new It(r.destX,r.destY),n)),{},{angle:Math.atan2(r.destY-r.y,r.destX-r.x)});case"L":return A(A({},new It(r.x,r.y).lerp(new It(o[1],o[2]),n)),{},{angle:Math.atan2(o[2]-r.y,o[1]-r.x)});case"C":case"Q":return((t,e)=>{let i,s=0,r=0,n={x:t.x,y:t.y},o=A({},n),a=.01,c=0;const h=t.iterator,l=t.angleFinder;for(;r<e&&a>1e-4;)o=h(s),c=s,i=On(n.x,n.y,o.x,o.y),i+r>e?(s-=a,a/=2):(n=o,s+=a,r+=i);return A(A({},o),{},{angle:l(c)})})(r,e)}},Rn=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Bn=new RegExp(_n,"g"),Xn=new RegExp(Pi,"gi"),Vn={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Yn=t=>{var e;const i=[],s=null!==(e=t.match(Rn))&&void 0!==e?e:[];for(const t of s){const e=t[0];if("z"===e||"Z"===e){i.push([e]);continue}const s=Vn[e.toLowerCase()];let r=[];if("a"===e||"A"===e){Bn.lastIndex=0;for(let e=null;e=Bn.exec(t);)r.push(...e.slice(1))}else r=t.match(Xn)||[];for(let t=0;t<r.length;t+=s){const n=new Array(s),o=xn[e];n[0]=t>0&&o?o:e;for(let e=0;e<s;e++)n[e+1]=parseFloat(r[t+e]);i.push(n)}}return i},Wn=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=new It(t[0]),s=new It(t[1]),r=1,n=0;const o=[],a=t.length,c=a>2;let h;for(c&&(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]),h=1;h<a;h++){if(!i.eq(s)){const t=i.midPointFrom(s);o.push(["Q",i.x,i.y,t.x,t.y])}i=t[h],h+1<t.length&&(s=t[h+1])}return c&&(r=i.x>t[h-2].x?1:i.x===t[h-2].x?0:-1,n=i.y>t[h-2].y?1:i.y===t[h-2].y?0:-1),o.push(["L",i.x+r*e,i.y+n*e]),o},Hn=(t,e)=>t.map((t=>t.map(((t,i)=>0===i||void 0===e?t:ye(t,e))).join(" "))).join(" ");function zn(t,e){const i=t.style;i&&e&&("string"==typeof e?i.cssText+=";"+e:Object.entries(e).forEach((t=>{let[e,s]=t;return i.setProperty(e,s)})))}var Gn=Object.freeze({__proto__:null,addTransformToObject:Xe,animate:_s,animateColor:xs,applyTransformToObject:Ve,calcAngleBetweenVectors:Hi,calcDimensionsMatrix:ue,calcPlaneChangeMatrix:ze,calcVectorRotation:zi,cancelAnimFrame:Wt,capValue:$i,composeMatrix:de,copyCanvasElement:t=>{var e;const i=Ut(t);return null===(e=i.getContext("2d"))||void 0===e||e.drawImage(t,0,0),i},cos:Ft,createCanvasElement:Gt,createImage:Nt,createRotateMatrix:oe,createScaleMatrix:ae,createSkewXMatrix:he,createSkewYMatrix:le,createTranslateMatrix:ne,createVector:Yi,crossProduct:Ui,degreesToRadians:Jt,dotProduct:qi,ease:cs,enlivenObjectEnlivables:pe,enlivenObjects:fe,findScaleToCover:mn,findScaleToFit:pn,getBoundsOfCurve:Sn,getOrthonormalVector:Ni,getPathSegmentsInfo:Ln,getPointOnPath:In,getPointer:Fe,getRandomInt:(t,e)=>Math.floor(Math.random()*(e-t+1))+t,getRegularPolygonPath:(t,e)=>{const i=2*Math.PI/t;let s=-Z;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 It(Ft(t),Lt(t)).scalarMultiply(e);r[n]=[0===n?"M":"L",o,a]}return r[t]=["Z"],r},getSmoothPathFromPoints:Wn,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:Gi,groupSVGElements:(t,e)=>t&&1===t.length?t[0]:new fn(t,e),hasStyleChanged:_r,invertTransform:te,isBetweenVectors:Ki,isIdentityMatrix:Zt,isTouchEvent:Le,isTransparent:or,joinPath:Hn,loadImage:ge,magnitude:Wi,makeBoundingBoxFromPoints:Re,makePathSimpler:Tn,matrixToSVG:_e,mergeClipPaths:(t,e)=>{var i;let s=t,r=e;s.inverted&&!r.inverted&&(s=e,r=t),Ue(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 fn([s],{clipPath:r,inverted:n})},multiplyTransformMatrices:ee,multiplyTransformMatrixArray:ie,parsePath:Yn,parsePreserveAspectRatioAttribute:gi,parseUnit:di,pick:me,projectStrokeOnPoints:ur,qrDecompose:re,radiansToDegrees:Qt,removeFromArray:At,removeTransformFromObject:(t,e)=>{const i=te(e),s=ee(i,t.calcOwnMatrix());Ve(t,s)},removeTransformMatrixForSvgParsing:(t,e)=>{let i=t._findCenterFromElement();t.transformMatrix&&((t=>{if(t.transformMatrix){const{scaleX:e,scaleY:i,angle:s,skewX:r}=re(t.transformMatrix);t.flipX=!1,t.flipY=!1,t.set(bt,e),t.set(wt,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,rt,rt)},request:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.onComplete||Q,s=new(U().XMLHttpRequest),r=e.signal,n=function(){s.abort()},o=function(){r&&r.removeEventListener("abort",n),s.onerror=s.ontimeout=Q};if(r&&r.aborted)throw new V("request");return r&&r.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){4===s.readyState&&(o(),i(s),s.onreadystatechange=Q)},s.onerror=s.ontimeout=o,s.open("get",t,!0),s.send(),s},requestAnimFrame:Yt,resetObjectTransform:Ye,rotatePoint:(t,e,i)=>t.rotate(i,e),rotateVector:Vi,saveObjectTransform:We,sendObjectToPlane:Ue,sendPointToPlane:Ge,sendVectorToPlane:Ne,setStyle:zn,sin:Lt,sizeAfterTransform:He,string:yr,stylesFromArray:br,stylesToArray:xr,toBlob:Kt,toDataURL:qt,toFixed:ye,transformPath:(t,e,i)=>(i&&(e=ee(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}=$t({x:t[s],y:t[s+1]},e);i[s]=r,i[s+1]=n}return i}))),transformPoint:$t});class Nn extends Ee{constructor(t){let{allowTouchScrolling:e=!1,containerClass:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t),P(this,"upper",void 0),P(this,"container",void 0);const{el:s}=this.lower,r=this.createUpperCanvas();this.upper={el:r,ctx:r.getContext("2d")},this.applyCanvasStyle(s,{allowTouchScrolling:e}),this.applyCanvasStyle(r,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const n=this.createContainerElement();n.classList.add(i),s.parentNode&&s.parentNode.replaceChild(n,s),n.append(s,r),this.container=n}createUpperCanvas(){const{el:t}=this.lower,e=Gt();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=N().createElement("div");return t.setAttribute("data-fabric","wrapper"),zn(t,{position:"relative"}),Me(t),t}applyCanvasStyle(t,e){const{styles:i,allowTouchScrolling:s}=e;zn(t,A(A({},i),{},{"touch-action":s?"manipulation":ht})),Me(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:i,ctx:s}=this.upper;ke(i,s,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),De(this.upper.el,t),De(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(),G().dispose(this.upper.el),delete this.upper,delete this.container}}class Un extends je{constructor(){super(...arguments),P(this,"targets",[]),P(this,"_hoveredTargets",[]),P(this,"_objectsToRender",void 0),P(this,"_currentTransform",null),P(this,"_groupSelector",null),P(this,"contextTopDirty",!1)}static getDefaults(){return A(A({},super.getDefaults()),Un.ownDefaults)}get upperCanvasEl(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.el}get contextTop(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Nn(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 or(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 e===xt||e===bt||e===wt||e===mt?s=this.centeredScaling||t.centeredScaling:e===ft&&(s=this.centeredRotation||t.centeredRotation),s?!i:i}_getOriginFromCorner(t,e){const i={x:t.originX,y:t.originY};return e?(["ml","tl","bl"].includes(e)?i.x=ct:["mr","tr","br"].includes(e)&&(i.x=nt),["tl","mt","tr"].includes(e)?i.y=at:["bl","mb","br"].includes(e)&&(i.y=ot),i):i}_setupCurrentTransform(t,e,i){var s;const r=e.group?Ge(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:n="",control:o}=e.getActiveControl()||{},a=i&&o?null===(s=o.getActionHandler(t,e,o))||void 0===s?void 0:s.bind(o):ri,c=((t,e,i,s)=>{if(!e||!t)return"drag";const r=s.controls[e];return r.getActionName(i,r,s)})(i,n,t,e),h=t[this.centeredKey],l=this._shouldCenterTransform(e,c,h)?{x:rt,y:rt}:this._getOriginFromCorner(e,n),u={target:e,action:c,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:l.x,originY:l.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:Jt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:h,original:A(A({},We(e)),{},{originX:l.x,originY:l.y})};this._currentTransform=u,this.fire("before:transform",{e:t,transform:u})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new It(e,i).transform(this.viewportTransform),o=new It(e+s,i+r).transform(this.viewportTransform),a=this.selectionLineWidth/2;let c=Math.min(n.x,o.x),h=Math.min(n.y,o.y),l=Math.max(n.x,o.x),u=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,h,l-c,u-h)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=a,h+=a,l-=a,u-=a,nr.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,h,l-c,u-h))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),i=this._activeObject,s=this.getActiveObjects();if(this.targets=[],i&&s.length>=1){if(i.findControl(e,Le(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)}_pointIsInObjectSelectionArea(t,e){let i=t.getCoords();const s=this.getZoom(),r=t.padding/s;if(r){const[t,e,s,n]=i,o=Math.atan2(e.y-t.y,e.x-t.x),a=Ft(o)*r,c=Lt(o)*r,h=a+c,l=a-c;i=[new It(t.x-l,t.y-h),new It(e.x+h,e.y-l),new It(s.x+l,s.y+h),new It(n.x-h,n.y+l)]}return bs.isPointInPolygon(e,i)}_checkTarget(t,e){if(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Ge(e,void 0,this.viewportTransform))){if(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing)return!0;if(!this.isTargetTransparent(t,e.x,e.y))return!0}return!1}_searchPossibleTargets(t,e){let i=t.length;for(;i--;){const s=t[i];if(this._checkTarget(s,e)){if(Bt(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);if(i&&Bt(i)&&i.interactive&&this.targets[0]){const t=this.targets;for(let e=t.length-1;e>0;e--){const i=t[e];if(!Bt(i)||!i.interactive)return i}return t[0]}return i}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.upperCanvasEl,s=i.getBoundingClientRect();let r=Fe(t),n=s.width||0,o=s.height||0;n&&o||(ot in s&&at in s&&(o=Math.abs(s.top-s.bottom)),ct in s&&nt 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=Ge(r,void 0,this.viewportTransform));const a=this.getRetinaScaling();1!==a&&(r.x/=a,r.y/=a);const c=0===n||0===o?new It(1,1):new It(i.width/n,i.height/o);return r.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Gt(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return Se(t)?t.getObjects():t?[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){const i=this._activeObject;return!(i===t||!this._discardActiveObject(e,t)&&this._activeObject||t.onSelect({e:e})||(this._activeObject=t,Se(t)&&i!==t&&t.set("canvas",this),t.setCoords(),0))}_discardActiveObject(t,e){const i=this._activeObject;return!!i&&!i.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===i&&this.endCurrentTransform(t),Se(i)&&i===this._hoveredTarget&&(this._hoveredTarget=void 0),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}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(kt,s))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Se(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,i){const s=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,i);return t.set(s),r}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&Se(e)&&this._activeObject===e){const i=me(t,["angle","flipX","flipY",nt,bt,wt,St,Ct,ot]);return Xe(t,e.calcOwnMatrix()),i}return{}}_setSVGObject(t,e,i){const s=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,i),e.set(s)}}P(Un,"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 qn{constructor(t){P(this,"targets",[]),P(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:e}=t.getActiveObject()||{};e&&e.focus()},i=t.upperCanvasEl;i.addEventListener("click",e),this.__disposer=()=>i.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),At(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 Kn=["target","oldTarget","fireCanvas","e"],Jn={passive:!1},Qn=(t,e)=>{const i=t.getViewportPoint(e),s=t.getScenePoint(e);return{viewportPoint:i,scenePoint:s,pointer:i,absolutePointer:s}},Zn=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)},$n=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)},to={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 eo extends Un{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),P(this,"_isClick",void 0),P(this,"textEditingManager",new qn(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((t=>{this[t]=this[t].bind(this)})),this.addOrRemove(Zn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const i=this.upperCanvasEl,s=this._getEventPrefix();t(Oe(i),"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,"".concat(s,"move"),this._onMouseMove,Jn),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,"click",this._onClick),t(i,"dblclick",this._onClick),t(i,"dragstart",this._onDragStart),t(i,"dragend",this._onDragEnd),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,Jn)}removeListeners(){this.addOrRemove($n,"remove");const t=this._getEventPrefix(),e=Te(this.upperCanvasEl);$n(e,"".concat(t,"up"),this._onMouseUp),$n(e,"touchend",this._onTouchEnd,Jn),$n(e,"".concat(t,"move"),this._onMouseMove,Jn),$n(e,"touchmove",this._onMouseMove,Jn),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,i=A({e:t},Qn(this,t));this.fire("mouse:out",A(A({},i),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",A({},i)),this._hoveredTargets.forEach((t=>{this.fire("mouse:out",A(A({},i),{},{target:t})),t&&t.fire("mouseout",A({},i))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",A({e:t},Qn(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const i={e:t,target:e};return this.fire("dragstart",i),e.fire("dragstart",i),void Zn(this.upperCanvasEl,"drag",this._onDragProgress)}Ie(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!==ht,i=e?this._activeObject:void 0,s={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:i};$n(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){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),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",A({e:t,target:e,subTargets:i,dragSource:this._dragSource},Qn(this,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&&Ie(t),this._basicEventHandler("contextmenu",s),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),2==e&&"dblclick"===t.type&&this._handleEvent(t,"dblclick"),3==e&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const i=this._activeObject;void 0===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||i&&this._target===i)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const s=this.upperCanvasEl,r=this._getEventPrefix(),n=Te(s);Zn(n,"touchend",this._onTouchEnd,Jn),e&&Zn(n,"touchmove",this._onMouseMove,Jn),$n(s,"".concat(r,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();$n(e,"".concat(i,"move"),this._onMouseMove,Jn);const s=Te(e);Zn(s,"".concat(i,"up"),this._onMouseUp),Zn(s,"".concat(i,"move"),this._onMouseMove,Jn)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),i=Te(this.upperCanvasEl);$n(i,"touchend",this._onTouchEnd,Jn),$n(i,"touchmove",this._onMouseMove,Jn),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{Zn(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=Te(this.upperCanvasEl);$n(t,"".concat(i,"up"),this._onMouseUp),$n(t,"".concat(i,"move"),this._onMouseMove,Jn),Zn(e,"".concat(i,"move"),this._onMouseMove,Jn)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const i=this._currentTransform,s=this._isClick,r=this._target,{button:n}=t;if(n)return(this.fireMiddleClick&&1===n||this.fireRightClick&&2===n)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,a,c=!1;if(i&&(this._finalizeCurrentTransform(t),c=i.actionPerformed),!s){const e=r===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(r)||!e&&r===this._activeObject)}if(r){const e=r.findControl(this.getViewportPoint(t),Le(t)),{key:s,control:n}=e||{};if(a=s,r.selectable&&r!==this._activeObject&&"up"===r.activeOn)this.setActiveObject(r,t),c=!0;else if(n){const e=n.getMouseUpHandler(t,r,n);e&&(o=this.getScenePoint(t),e.call(n,t,i,o.x,o.y))}r.isMoving=!1}if(i&&(i.target!==r||i.corner!==a)){const e=i.target&&i.target.controls[i.corner],s=e&&e.getMouseUpHandler(t,i.target,e);o=o||this.getScenePoint(t),s&&s.call(e,t,i,o.x,o.y)}this._setCursorFromEvent(t,r),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,r&&(r.__corner=void 0),c?this.requestRenderAll():s||null!==(e=this._activeObject)&&void 0!==e&&e.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,i){const s=this._target,r=this.targets||[],n=A(A(A({e:t,target:s,subTargets:r},Qn(this,t)),{},{transform:this._currentTransform},"up:before"===e||"up"===e?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),"down:before"===e||"down"===e?i:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let t=0;t<r.length;t++)r[t]!==s&&r[t].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,i=!!e&&e===this._activeObject;const{button:s}=t;if(s)return(this.fireMiddleClick&&1===s||this.fireRightClick&&2===s)&&this._handleEvent(t,"down",{alreadySelected:i}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t))return;if(this._currentTransform)return;let r=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,r=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const e=this.getScenePoint(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(i=!!e&&e===this._activeObject,e){e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);const s=e.findControl(this.getViewportPoint(t),Le(t));if(e===this._activeObject&&(s||!n)){this._setupCurrentTransform(t,e,i);const r=s?s.control:void 0,n=this.getScenePoint(t),o=r&&r.getMouseDownHandler(t,e,r);o&&o.call(r,t,this._currentTransform,n.x,n.y)}}r&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:i}),r&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Ge(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const i=this.getScenePoint(t);e.deltaX=i.x-e.x,e.deltaY=i.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{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 i=this._draggedoverTarget,s=this._hoveredTargets,r=this.targets,n=Math.max(s.length,r.length);this.fireSyntheticInOutEvents("drag",A(A({},e),{},{target:t,oldTarget:i,fireCanvas:!0}));for(let t=0;t<n;t++)this.fireSyntheticInOutEvents("drag",A(A({},e),{},{target:r[t],oldTarget:s[t]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:i,oldTarget:s,fireCanvas:r,e:n}=e,o=F(e,Kn);const{targetIn:a,targetOut:c,canvasIn:h,canvasOut:l}=to[t],u=s!==i;if(s&&u){const t=A(A({},o),{},{e:n,target:s,nextTarget:i},Qn(this,n));r&&this.fire(l,t),s.fire(c,t)}if(i&&u){const t=A(A({},o),{},{e:n,target:i,previousTarget:s},Qn(this,n));r&&this.fire(h,t),i.fire(a,t)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),i=this._currentTransform,s=i.target,r=s.group?Ge(e,void 0,s.group.calcTransformMatrix()):e;i.shiftKey=t.shiftKey,i.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,i,r),i.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,i){const{action:s,actionHandler:r,target:n}=e,o=!!r&&r(t,e,i.x,i.y);o&&n.setCoords(),"drag"===s&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let i=e.hoverCursor||this.hoverCursor;const s=Se(this._activeObject)?this._activeObject:null,r=(!s||e.group!==s)&&e.findControl(this.getViewportPoint(t));if(r){const i=r.control;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=Se(i);if(i&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(i!==e||s)&&(s||!e.isDescendantOf(i)&&!i.isDescendantOf(e))&&!e.onSelect({e:t})&&!i.getActiveControl()){if(s){const s=i.getObjects();if(e===i){const i=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(s,i)||this.searchPossibleTargets(this._objects,i))||!e.selectable)return!1}e.group===i?(i.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],1===i.size()&&this._setActiveObject(i.item(0),t)):(i.multiSelectAdd(e),this._hoveredTarget=i,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(s,t)}else{i.isEditing&&i.exitEditing();const s=new(Et.getClass("ActiveSelection"))([],{canvas:this});s.multiSelectAdd(i,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([i],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new It(e,i),o=n.add(new It(s,r)),a=n.min(o),c=n.max(o).subtract(a),h=this.collectObjects({left:a.x,top:a.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),l=n.eq(o)?h[0]?[h[0]]:[]:h.length>1?h.filter((e=>!e.onSelect({e:t}))).reverse():h;if(1===l.length)this.setActiveObject(l[0],t);else if(l.length>1){const e=Et.getClass("ActiveSelection");this.setActiveObject(new e(l,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const io={x1:0,y1:0,x2:0,y2:0},so=A(A({},io),{},{r1:0,r2:0}),ro=(t,e)=>isNaN(t)&&"number"==typeof e?e:t,no=/^(\d+\.\d+)%|(\d+)%$/;function oo(t){return t&&no.test(t)}function ao(t,e){const i="number"==typeof t?t:"string"==typeof t?parseFloat(t)/(oo(t)?100:1):NaN;return $i(0,ro(i,e),1)}const co=/\s*;\s*/,ho=/\s*:\s*/;function lo(t,e){let i,s;const r=t.getAttribute("style");if(r){const t=r.split(co);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){const[r,n]=t[e].split(ho).map((t=>t.trim()));"stop-color"===r?i=n:"stop-opacity"===r&&(s=n)}}const n=new ui(i||t.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:ao(t.getAttribute("offset"),0),color:n.toRgb(),opacity:ro(parseFloat(s||t.getAttribute("stop-opacity")||""),1)*n.getAlpha()*e}}function uo(t,e){const i=[],s=t.getElementsByTagName("stop"),r=ao(e,1);for(let t=s.length;t--;)i.push(lo(s[t],r));return i}function go(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function fo(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}function po(t,e){return t.getAttribute(e)}function mo(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&&oo(a)&&(i*=.01,"pixels"===n&&("x1"!==o&&"x2"!==o&&"r2"!==o||(i*=s),"y1"!==o&&"y2"!==o||(i*=r)))),e[o]=i,e}),{})}("linear"===go(t)?function(t){return{x1:po(t,"x1")||0,y1:po(t,"y1")||0,x2:po(t,"x2")||"100%",y2:po(t,"y2")||0}}(t):function(t){return{x1:po(t,"fx")||po(t,"cx")||"50%",y1:po(t,"fy")||po(t,"cy")||"50%",r1:0,x2:po(t,"cx")||"50%",y2:po(t,"cy")||"50%",r2:po(t,"r")||"50%"}}(t),A(A({},e),{},{gradientUnits:fo(t)}))}class vo{constructor(t){const{type:e="linear",gradientUnits:i="pixels",coords:s={},colorStops:r=[],offsetX:n=0,offsetY:o=0,gradientTransform:a,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:i,coords:A(A({},"radial"===e?so:io),s),colorStops:r,offsetX:n,offsetY:o,gradientTransform:a,id:c?"".concat(c,"_").concat(zt()):zt()})}addColorStop(t){for(const e in t){const i=new ui(t[e]);this.colorStops.push({offset:parseFloat(e),color:i.toRgb(),opacity:i.getAlpha()})}return this}toObject(t){return A(A({},me(this,t)),{},{type:this.type,coords:A({},this.coords),colorStops:this.colorStops.map((t=>A({},t))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=[],s=this.gradientTransform?this.gradientTransform.concat():et.concat(),r="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",n=this.colorStops.map((t=>A({},t))).sort(((t,e)=>t.offset-e.offset));let o=-this.offsetX,a=-this.offsetY;var c;"objectBoundingBox"===r?(o/=t.width,a/=t.height):(o+=t.width/2,a+=t.height/2),(c=t)&&"function"==typeof c._renderPathCommands&&"percentage"!==this.gradientUnits&&(o-=t.pathOffset.x,a-=t.pathOffset.y),s[4]-=o,s[5]-=a;const h=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(r,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(_e(s),'"'),""].join(" ");if("linear"===this.type){const{x1:t,y1:e,x2:s,y2:r}=this.coords;i.push("<linearGradient ",h,' x1="',t,'" y1="',e,'" x2="',s,'" y2="',r,'">\n')}else if("radial"===this.type){const{x1:t,y1:e,x2:s,y2:r,r1:o,r2:a}=this.coords,c=o>a;i.push("<radialGradient ",h,' cx="',c?t:s,'" cy="',c?e:r,'" r="',c?o:a,'" fx="',c?s:t,'" fy="',c?r:e,'">\n'),c&&(n.reverse(),n.forEach((t=>{t.offset=1-t.offset})));const l=Math.min(o,a);if(l>0){const t=l/Math.max(o,a);n.forEach((e=>{e.offset+=t*(1-e.offset)}))}}return n.forEach((t=>{let{color:e,offset:s,opacity:r}=t;i.push("<stop ",'offset="',100*s+"%",'" style="stop-color:',e,void 0!==r?";stop-opacity: "+r:";",'"/>\n')})),i.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),i.join("")}toLive(t){const{x1:e,y1:i,x2:s,y2:r,r1:n,r2:o}=this.coords,a="linear"===this.type?t.createLinearGradient(e,i,s,r):t.createRadialGradient(e,i,n,s,r,o);return this.colorStops.forEach((t=>{let{color:e,opacity:i,offset:s}=t;a.addColorStop(s,void 0!==i?new ui(e).setAlpha(i).toRgba():e)})),a}static async fromObject(t){const{colorStops:e,gradientTransform:i}=t;return new this(A(A({},t),{},{colorStops:e?e.map((t=>A({},t))):void 0,gradientTransform:i?[...i]:void 0}))}static fromElement(t,e,i){const s=fo(t),r=e._findCenterFromElement();return new this(A({id:t.getAttribute("id")||void 0,type:go(t),coords:mo(t,{width:i.viewBoxWidth||i.width,height:i.viewBoxHeight||i.height}),colorStops:uo(t,i.opacity),gradientUnits:s,gradientTransform:Ur(t.getAttribute("gradientTransform")||"")},"pixels"===s?{offsetX:e.width/2-r.x,offsetY:e.height/2-r.y}:{offsetX:0,offsetY:0}))}}P(vo,"type","Gradient"),Et.setClass(vo,"gradient"),Et.setClass(vo,"linear"),Et.setClass(vo,"radial");const yo=["type","source","patternTransform"];class _o{get type(){return"pattern"}set type(t){B("warn","Setting type has no effect",t)}constructor(t){P(this,"repeat","repeat"),P(this,"offsetX",0),P(this,"offsetY",0),P(this,"crossOrigin",""),this.id=zt(),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:i}=this;return A(A({},me(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:i,offsetX:ye(this.offsetX,R.NUM_FRACTION_DIGITS),offsetY:ye(this.offsetY,R.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=ro(this.offsetX/e,0),a=ro(this.offsetY/i,0),c="repeat-y"===r||"no-repeat"===r?1+Math.abs(o||0):ro(s.width/e,0),h="repeat-x"===r||"no-repeat"===r?1+Math.abs(a||0):ro(s.height/i,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(a,'" width="').concat(c,'" height="').concat(h,'">'),'<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{type:i,source:s,patternTransform:r}=t,n=F(t,yo);const o=await ge(s,A(A({},e),{},{crossOrigin:n.crossOrigin}));return new this(A(A({},n),{},{patternTransform:r&&r.slice(0),source:o}))}}P(_o,"type","Pattern"),Et.setClass(_o),Et.setClass(_o,"pattern");class xo{constructor(t){P(this,"color","rgb(0, 0, 0)"),P(this,"width",1),P(this,"shadow",null),P(this,"strokeLineCap","round"),P(this,"strokeLineJoin","round"),P(this,"strokeMiterLimit",10),P(this,"strokeDashArray",null),P(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 ui(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 bo=["path","left","top"],wo=["d"];class So extends nr{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{path:i,left:s,top:r}=e,n=F(e,bo);super(),Object.assign(this,So.ownDefaults),this.setOptions(n),this._setPath(t||[],!0),"number"==typeof s&&this.set(nt,s),"number"==typeof r&&this.set(ot,r)}_setPath(t,e){this.path=Tn(Array.isArray(t)?t:Yn(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new It(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,i=-this.pathOffset.y;t.beginPath();for(const s of this.path)switch(s[0]){case"L":t.lineTo(s[1]+e,s[2]+i);break;case"M":t.moveTo(s[1]+e,s[2]+i);break;case"C":t.bezierCurveTo(s[1]+e,s[2]+i,s[3]+e,s[4]+i,s[5]+e,s[6]+i);break;case"Q":t.quadraticCurveTo(s[1]+e,s[2]+i,s[3]+e,s[4]+i);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return A(A({},super.toObject(t)),{},{path:this.path.map((t=>t.slice()))})}toDatalessObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=Hn(this.path,R.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,'" stroke-linecap="round" />\n')]}_getOffsetTransform(){const t=R.NUM_FRACTION_DIGITS;return" translate(".concat(ye(-this.pathOffset.x,t),", ").concat(ye(-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,rt,rt)}_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({x:e,y:i},{x:s,y:r});break;case"M":s=n[1],r=n[2],e=s,i=r;break;case"C":t.push(...Sn(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(...Sn(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 Re(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return A(A({},t),{},{pathOffset:new It(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i),{d:r}=s;return new this(r,A(A(A({},F(s,wo)),e),{},{left:void 0,top:void 0}))}}P(So,"type","Path"),P(So,"cacheProperties",[...es,"path","fillRule"]),P(So,"ATTRIBUTE_NAMES",[...wr,"d"]),Et.setClass(So),Et.setSVGClass(So);class Co extends xo{constructor(t){super(t),P(this,"decimate",.4),P(this,"drawStraightLine",!1),P(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=Co.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++)Co.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 Wn(t,e)}createPath(t){const e=new So(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 Zi(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"===Hn(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 To=["left","top","radius"],Oo=["radius","startAngle","endAngle","counterClockwise"];class ko extends nr{static getDefaults(){return A(A({},super.getDefaults()),ko.ownDefaults)}constructor(t){super(),Object.assign(this,ko.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),"radius"===t&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,Jt(this.startAngle),Jt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(bt)}getRadiusY(){return this.get("radius")*this.get(wt)}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([...Oo,...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=Jt(this.startAngle),s=Jt(this.endAngle),r=Ft(i)*e,n=Lt(i)*e,o=Ft(s)*e,a=Lt(s)*e,c=t>180?1:0,h=this.counterClockwise?0:1;return['<path d="M '.concat(r," ").concat(n," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(h," ").concat(o," ").concat(a,'" '),"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i),{left:r=0,top:n=0,radius:o=0}=s;return new this(A(A({},F(s,To)),{},{radius:o,left:r-o,top:n-o}))}static fromObject(t){return super._fromObject(t)}}P(ko,"type","Circle"),P(ko,"cacheProperties",[...es,...Oo]),P(ko,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),P(ko,"ATTRIBUTE_NAMES",["cx","cy","r",...wr]),Et.setClass(ko),Et.setSVGClass(ko);const Do=["x1","y1","x2","y2"],Mo=["x1","y1","x2","y2"],Eo=["x1","x2","y1","y2"];class Po extends nr{constructor(){let[t,e,i,s]=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0,0,0],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,Po.ownDefaults),this.setOptions(r),this.x1=t,this.x2=i,this.y1=e,this.y2=s,this._setWidthHeight();const{left:n,top:o}=r;"number"==typeof n&&this.set(nt,n),"number"==typeof o&&this.set(ot,o)}_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}=Re([{x:t,y:e},{x:i,y:s}]),c=new It(r+o/2,n+a/2);this.setPositionByOrigin(c,rt,rt)}_set(t,e){return super._set(t,e),Eo.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;xe(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 It((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return A(A({},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=Jr(t,this.ATTRIBUTE_NAMES,i),{x1:r=0,y1:n=0,x2:o=0,y2:a=0}=s;return new this([r,n,o,a],F(s,Do))}static fromObject(t){let{x1:e,y1:i,x2:s,y2:r}=t,n=F(t,Mo);return this._fromObject(A(A({},n),{},{points:[e,i,s,r]}),{extraParam:"points"})}}P(Po,"type","Line"),P(Po,"cacheProperties",[...es,...Eo]),P(Po,"ATTRIBUTE_NAMES",wr.concat(Eo)),Et.setClass(Po),Et.setSVGClass(Po);class jo extends nr{static getDefaults(){return A(A({},super.getDefaults()),jo.ownDefaults)}constructor(t){super(),Object.assign(this,jo.ownDefaults),this.setOptions(t)}_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),'" />']}}P(jo,"type","Triangle"),P(jo,"ownDefaults",{width:100,height:100}),Et.setClass(jo),Et.setSVGClass(jo);const Ao=["rx","ry"];class Fo extends nr{static getDefaults(){return A(A({},super.getDefaults()),Fo.ownDefaults)}constructor(t){super(),Object.assign(this,Fo.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(bt)}getRy(){return this.get("ry")*this.get(wt)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Ao,...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,$,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i);return s.left=(s.left||0)-s.rx,s.top=(s.top||0)-s.ry,new this(s)}}P(Fo,"type","Ellipse"),P(Fo,"cacheProperties",[...es,...Ao]),P(Fo,"ownDefaults",{rx:0,ry:0}),P(Fo,"ATTRIBUTE_NAMES",[...wr,"cx","cy","rx","ry"]),Et.setClass(Fo),Et.setSVGClass(Fo);const Lo=["left","top"],Io={exactBoundingBox:!1};class Ro extends nr{static getDefaults(){return A(A({},super.getDefaults()),Ro.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),P(this,"strokeDiff",void 0),Object.assign(this,Ro.ownDefaults),this.setOptions(e),this.points=t;const{left:i,top:s}=e;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof i&&this.set(nt,i),"number"==typeof s&&this.set(ot,s)}isOpen(){return!0}_projectStrokeOnPoints(t){return ur(this.points,t,this.isOpen())}_calcDimensions(t){t=A({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 It,strokeOffset:new It,strokeDiff:new It};const i=Re(e),s=ue(A(A({},t),{},{scaleX:1,scaleY:1})),r=Re(this.points.map((t=>$t(t,s,!0)))),n=new It(this.scaleX,this.scaleY);let o=i.left+i.width/2,a=i.top+i.height/2;return this.exactBoundingBox&&(o-=a*Math.tan(Jt(this.skewX)),a-=o*Math.tan(Jt(this.skewY))),A(A({},i),{},{pathOffset:new It(o,a),strokeOffset:new It(r.left,r.top).subtract(new It(i.left,i.top)).multiply(n),strokeDiff:new It(i.width,i.height).subtract(new It(r.width,r.height)).multiply(n)})}_findCenterFromElement(){const t=Re(this.points);return new It(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 It(e+s/2,i+r/2),rt,rt)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new It(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 It(null!==(e=t.width)&&void 0!==e?e:s,null!==(i=t.height)&&void 0!==i?i:r)}else{var s,r;n=new It(null!==(s=t.width)&&void 0!==s?s:this.width,null!==(r=t.height)&&void 0!==r?r:this.height)}return n.multiply(new It(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&&((t===bt||t===wt)&&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 A(A({},super.toObject(t)),{},{points:this.points.map((t=>{let{x:e,y:i}=t;return{x:e,y:i}}))})}_toSVG(){const t=[],e=this.pathOffset.x,i=this.pathOffset.y,s=R.NUM_FRACTION_DIGITS;for(let r=0,n=this.points.length;r<n;r++)t.push(ye(this.points[r].x-e,s),",",ye(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,i){return new this(function(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}(t.getAttribute("points")),A(A({},F(Jr(t,this.ATTRIBUTE_NAMES,i),Lo)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}P(Ro,"ownDefaults",Io),P(Ro,"type","Polyline"),P(Ro,"layoutProperties",[St,Ct,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),P(Ro,"cacheProperties",[...es,"points"]),P(Ro,"ATTRIBUTE_NAMES",[...wr]),Et.setClass(Ro),Et.setSVGClass(Ro);class Bo extends Ro{isOpen(){return!1}}P(Bo,"ownDefaults",Io),P(Bo,"type","Polygon"),Et.setClass(Bo),Et.setSVGClass(Bo);class Xo extends nr{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 c=e[o][a]||{};r++,void 0!==c[t]?(s?c[t]!==s&&(n=!1):s=c[t],c[t]===this[t]&&delete c[t]):n=!1,0!==Object.keys(c).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);const r=ve(A(A({},this._getStyleDeclaration(i,s)),e),(t=>void 0!==t));this._setStyleDeclaration(i,s,r)}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 A(A({},me(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]}}P(Xo,"_styleProperties",wi);const Vo=/ +/g,Yo=/"/g;function Wo(t,e,i,s,r){return"\t\t".concat(function(t,e){let{left:i,top:s,width:r,height:n}=e,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:R.NUM_FRACTION_DIGITS;const a=fi(Tt,t,!1),[c,h,l,u]=[i,s,r,n].map((t=>ye(t,o)));return"<rect ".concat(a,' x="').concat(c,'" y="').concat(h,'" width="').concat(l,'" height="').concat(u,'"></rect>')}(t,{left:e,top:i,width:s,height:r}),"\n")}const Ho=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let zo;class Go extends Xo{static getDefaults(){return A(A({},super.getDefaults()),Go.ownDefaults)}constructor(t,e){super(),P(this,"__charBounds",[]),Object.assign(this,Go.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Ln(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(Ci)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,r,n,o;for(let a=0,c=this._textLines.length;a<c;a++)if((this.textAlign===Ci||a!==c-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){this.paintFirst===Ot?(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 rt:t.textBaseline="middle";break;case"ascender":t.textBaseline=ot;break;case"descender":t.textBaseline=at}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,c,h=0,l=0,u=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let d=0;d<n;d++){const n=this.__charBounds[e][d];c=this.getValueOfPropertyAt(e,d,"textBackgroundColor"),this.path?(t.save(),t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillStyle=c,c&&t.fillRect(-n.width/2,-r/this.lineHeight*(1-this._fontSizeFraction),n.width,r/this.lineHeight),t.restore()):c!==u?(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-h),t.fillStyle=u,u&&t.fillRect(a,s,h,r/this.lineHeight),l=n.left,h=n.width,u=c):h+=n.kernedWidth}c&&!this.path&&(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-h),t.fillStyle=c,t.fillRect(a,s,h,r/this.lineHeight)),s+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,s){const r=K.getFontCache(e),n=this._getFontDeclaration(e),o=i+t,a=i&&n===this._getFontDeclaration(s),c=e.fontSize/this.CACHE_FONT_SIZE;let h,l,u,d;if(i&&void 0!==r[i]&&(u=r[i]),void 0!==r[t]&&(d=h=r[t]),a&&void 0!==r[o]&&(l=r[o],d=l-u),void 0===h||void 0===u||void 0===l){const s=function(){if(!zo){const t=Ut({width:0,height:0});zo=t.getContext("2d")}return zo}();this._setTextStyles(s,e,!0),void 0===h&&(d=h=s.measureText(t).width,r[t]=h),void 0===u&&a&&i&&(u=s.measureText(i).width,r[i]=u),a&&void 0===l&&(l=s.measureText(o).width,r[o]=l,d=l-u)}return{width:h*c,kernedWidth:d*c}}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===ct,n=this.path,o=this._textLines[t],a=o.length,c=new Array(a);this.__charBounds[t]=c;for(let r=0;r<a;r++){const n=o[r];i=this._getGraphemeBox(n,t,r,e),c[r]=i,s+=i.kernedWidth,e=n}if(c[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 nt:t=r?e-s:0;break;case rt:t=(e-s)/2;break;case ct: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=c[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=In(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===ct?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 c,h=a.kernedWidth,l=a.width;0!==this.charSpacing&&(c=this._getWidthOfCharSpacing(),l+=c,h+=c);const u={width:l,left:0,height:n.fontSize,kernedWidth:h,deltaY:n.deltaY};if(i>0&&!r){const t=this.__charBounds[e][i-1];u.left=t.left+t.width+a.kernedWidth-a.width}return u}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let 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,c=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],s+c,r+i+a,n),i+=o}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(Tt))&&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(Ci),c=this.path,h=!a&&0===this.charSpacing&&this.isEmptyStyles(n)&&!c,l="ltr"===this.direction,u="ltr"===this.direction?1:-1,d=e.direction;let g,f,p,m,v,y="",_=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",l?"ltr":"rtl"),e.direction=l?"ltr":"rtl",e.textAlign=l?nt:ct),r-=o*this._fontSizeFraction/this.lineHeight,h)return this._renderChar(t,e,n,0,i.join(""),s,r),void e.restore();for(let o=0,h=i.length-1;o<=h;o++)m=o===h||this.charSpacing||c,y+=i[o],p=this.__charBounds[n][o],0===_?(s+=u*(p.kernedWidth-p.width),_+=p.width):_+=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=_r(g,f,!1)),m&&(c?(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,y,v,r)),y="",g=f,s+=u*_,_=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,i=this.height+this.strokeWidth,s=Ut({width:e,height:i}),r=s.getContext("2d");return s.width=e,s.height=i,r.beginPath(),r.moveTo(0,0),r.lineTo(e,0),r.lineTo(e,i),r.lineTo(0,i),r.closePath(),r.translate(e/2,i/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(s,"no-repeat")}handleFiller(t,e,i){let s,r;return xe(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),c=this.getCompleteStyleDeclaration(i,s),h="fillText"===t&&c.fill,l="strokeText"===t&&c.stroke&&c.strokeWidth;if(l||h){if(e.save(),e.font=this._getFontDeclaration(c),a.textBackgroundColor&&this._removeShadow(e),a.deltaY&&(o+=a.deltaY),h){const t=this._setFillStyles(e,c);e.fillText(r,n-t.offsetX,o-t.offsetY)}if(l){const t=this._setStrokeStyles(e,c);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===Ci||s===ki&&!n||s===Oi&&!n||s===Ti&&!n?0:(s===rt&&(o=i/2),s===ct&&(o=i),s===ki&&(o=i/2),s===Oi&&(o=i),"rtl"===r&&(s===ct||s===Ci||s===Oi?o=0:s===nt||s===Ti?o=-i:s!==rt&&s!==ki||(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="linethrough"===e?.5:"overline"===e?1:0,a=this.offsets[e];for(let c=0,h=this._textLines.length;c<h;c++){const h=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){i+=h;continue}const l=this._textLines[c],u=h/this.lineHeight,d=this._getLineLeftOffset(c);let g=0,f=0,p=this.getValueOfPropertyAt(c,0,e),m=this.getValueOfPropertyAt(c,0,Tt),v=this.getValueOfPropertyAt(c,0,vi),y=p,_=m,x=v;const b=i+u*(1-this._fontSizeFraction);let w=this.getHeightOfChar(c,0),S=this.getValueOfPropertyAt(c,0,"deltaY");for(let i=0,n=l.length;i<n;i++){const n=this.__charBounds[c][i];y=this.getValueOfPropertyAt(c,i,e),_=this.getValueOfPropertyAt(c,i,Tt),x=this.getValueOfPropertyAt(c,i,vi);const h=this.getHeightOfChar(c,i),l=this.getValueOfPropertyAt(c,i,"deltaY");if(r&&y&&_){const e=this.fontSize*x/1e3;t.save(),t.fillStyle=m,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,a*h+l-o*e,n.kernedWidth,e),t.restore()}else if((y!==p||_!==m||h!==w||x!==v||l!==S)&&f>0){const e=this.fontSize*v/1e3;let i=s+d+g;"rtl"===this.direction&&(i=this.width-i-f),p&&m&&v&&(t.fillStyle=m,t.fillRect(i,b+a*w+S-o*e,f,e)),g=n.left,f=n.width,p=y,v=x,m=_,w=h,S=l}else f+=n.kernedWidth}let C=s+d+g;"rtl"===this.direction&&(C=this.width-C-f),t.fillStyle=_;const T=this.fontSize*x/1e3;y&&_&&x&&t.fillRect(C,b+a*w+S-o*T,f-n,T),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(",")||Go.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 pr(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 A(A({},super.toObject([...bi,...t])),{},{styles:xr(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,i){const s=Jr(t,Go.ATTRIBUTE_NAMES,i),r=A(A({},e),s),{textAnchor:n=nt,textDecoration:o="",dx:a=0,dy:c=0,top:h=0,left:l=0,fontSize:u=it,strokeWidth:d=1}=r,g=F(r,Ho),f=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),A({left:l+a,top:h+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:u},g)),p=f.getScaledHeight()/f.height,m=((f.height+f.strokeWidth)*f.lineHeight-f.height)*p,v=f.getScaledHeight()+m;let y=0;return n===rt&&(y=f.getScaledWidth()/2),n===ct&&(y=f.getScaledWidth()),f.set({left:f.left-y,top:f.top-(v-f.fontSize*(.07+f._fontSizeFraction))/f.lineHeight,strokeWidth:d}),f}static fromObject(t){return this._fromObject(A(A({},t),{},{styles:br(t.styles||{},t.text)}),{extraParam:"text"})}}P(Go,"textLayoutProperties",xi),P(Go,"cacheProperties",[...es,...bi]),P(Go,"ownDefaults",Si),P(Go,"type","Text"),P(Go,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),P(Go,"ATTRIBUTE_NAMES",wr.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),rr(Go,[class extends pi{_toSVG(){const t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){const e=this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0}),i=this.path;return i?e+i._createBaseSVGMarkup(i._toSVG(),{reviver:t,withShadow:!0,additionalTransform:_e(this.calcOwnMatrix())}):e}_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" ','font-family="'.concat(this.fontFamily.replace(Yo,"'"),'" '),'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(...Wo(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,r){const n=R.NUM_FRACTION_DIGITS,o=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(Vo)),a=o?'style="'.concat(o,'"'):"",c=e.deltaY,h=c?' dy="'.concat(ye(c,n),'" '):"",{angle:l,renderLeft:u,renderTop:d,width:g}=r;let f="";if(void 0!==u){const t=g/2;l&&(f=' rotate="'.concat(ye(Qt(l),n),'"'));const e=oe({angle:Qt(l)});e[4]=u,e[5]=d;const r=new It(-t,0).transform(e);i=r.x,s=r.y}return'<tspan x="'.concat(ye(i,n),'" y="').concat(ye(s,n),'" ').concat(h).concat(f).concat(a,">").concat(gr(t),"</tspan>")}_setSVGTextLineText(t,e,i,s){const r=this.getHeightOfLine(e),n=this.textAlign.includes(Ci),o=this._textLines[e];let a,c,h,l,u,d="",g=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let r=0,f=o.length-1;r<=f;r++)u=r===f||this.charSpacing||this.path,d+=o[r],h=this.__charBounds[e][r],0===g?(i+=h.kernedWidth-h.width,g+=h.width):g+=h.kernedWidth,n&&!u&&this._reSpaceAndTab.test(o[r])&&(u=!0),u||(a=a||this.getCompleteStyleDeclaration(e,r),c=this.getCompleteStyleDeclaration(e,r+1),u=_r(a,c,!0)),u&&(l=this._getStyleDeclaration(e,r),t.push(this._createTextCharSpan(d,l,i,s,h)),d="",a=c,"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,c=0,h=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let l=0;l<r.length;l++){const{left:r,width:u,kernedWidth:d}=this.__charBounds[e][l];o=this.getValueOfPropertyAt(e,l,"textBackgroundColor"),o!==h?(h&&t.push(...Wo(h,i+c,s,a,n)),c=r,a=u,h=o):a+=d}o&&t.push(...Wo(h,i+c,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)," text-decoration-thickness: ").concat(ye(this.textDecorationThickness*this.getObjectScaling().y/10,R.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(t,e){const{fontFamily:i,strokeWidth:s,stroke:r,fill:n,fontSize:o,fontStyle:a,fontWeight:c,deltaY:h,textDecorationThickness:l,linethrough:u,overline:d,underline:g}=t,f=this.getSvgTextDecoration({underline:null!=g?g:this.underline,overline:null!=d?d:this.overline,linethrough:null!=u?u:this.linethrough}),p=l||this.textDecorationThickness;return[r?fi(Ot,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,"; "):"",c?"font-weight: ".concat(c,"; "):"",f?"text-decoration: ".concat(f,"; text-decoration-thickness: ").concat(ye(p*this.getObjectScaling().y/10,R.NUM_FRACTION_DIGITS),"%; "):"",n?fi(Tt,n):"",h?"baseline-shift: ".concat(-h,"; "):"",e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter((e=>t[e.replace("-","")])).join(" ")}}]),Et.setClass(Go),Et.setSVGClass(Go);class No{constructor(t){P(this,"target",void 0),P(this,"__mouseDownInPlace",!1),P(this,"__dragStartFired",!1),P(this,"__isDraggingOver",!1),P(this,"__dragStartSelection",void 0),P(this,"__dragImageDisposer",void 0),P(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 It(n.flipX?-1:1,n.flipY?-1:1),c=n._getCursorBoundaries(s),h=new It(c.left+c.leftOffset,c.top+c.topOffset).multiply(a).transform(n.calcTransformMatrix()),l=o.getScenePoint(t).subtract(h),u=n.getCanvasRetinaScaling(),d=n.getBoundingRect(),g=h.subtract(new It(d.left,d.top)),f=o.viewportTransform,p=g.add(l).transform(f,!0),m=n.backgroundColor,v=dr(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 _=n.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});n.backgroundColor=m,n.styles=v,n.dirty=!0,zn(_,{position:"fixed",left:"".concat(-_.width,"px"),border:ht,width:"".concat(_.width/u,"px"),height:"".concat(_.height/u,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{_.remove()},Te(t.target||this.target.hiddenTextarea).body.appendChild(_),null===(i=t.dataTransfer)||void 0===i||i.setDragImage(_,p.x,p.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,i=this.isActive();if(i&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},s=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=A({text:e.text,value:s},i);t.dataTransfer.setData("text/plain",s),t.dataTransfer.setData("application/fabric",JSON.stringify({value:s,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),i}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){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)],c=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+c,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(_t,{index:n+c,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)||ht;o===ht?(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(_t,{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 Uo=/[ \n\.,;!\?\-]/;class qo extends Go{constructor(){super(...arguments),P(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 _s({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:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;null===(t=this._currentTickCompleteState)||void 0===t||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,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||!lt.test(i[t-1]))?t-1:t,r=i[s];for(;s>0&&s<i.length&&!Uo.test(r);)s+=e,r=i[s];return-1===e&&Uo.test(r)&&s++,s}selectWord(t){var e;t=null!==(e=t)&&void 0!==e?e:this.selectionStart;const i=this.searchWordBoundary(t,-1),s=Math.max(i,this.searchWordBoundary(t,1));this.selectionStart=i,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=null!==(e=t)&&void 0!==e?e:this.selectionStart;const i=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);this.selectionStart=i,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Te(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;return t===e?{selectionStart:s,selectionEnd:s}:{selectionStart:s,selectionEnd:s+i.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){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(),c=this.canvas.upperCanvasEl,h=c.width/a,l=c.height/a,u=h-n,d=l-n,g=new It(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new It(c.clientWidth/h,c.clientHeight/l));return g.x<0&&(g.x=0),g.x>u&&(g.x=u),g.y<0&&(g.y=0),g.y>d&&(g.y=d),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(kt),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,i,s){const r={},n=this._unwrappedTextLines[t].length,o=n===e;let a=!1;i||(i=1),this.shiftLineStyles(t,i);const c=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,r[s-e]=this.styles[t][i],o&&0===e||delete this.styles[t][i])}let h=!1;for(a&&!o&&(this.styles[t+i]=r,h=!0),(h||n>e)&&i--;i>0;)s&&s[i-1]?this.styles[t+i]={0:A({},s[i-1])}:c?this.styles[t+i]={0:A({},c)}:delete this.styles[t+i],i--;this._forceClearCache=!0}insertCharStyleObject(t,e,i,s){this.styles||(this.styles={});const r=this.styles[t],n=r?A({},r):{};i||(i=1);for(const t in n){const s=parseInt(t,10);s>=e&&(r[s+i]=n[s],n[s-i]||delete r[s])}if(this._forceClearCache=!0,s){for(;i--;)Object.keys(s[i]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+i]=A({},s[i]));return}if(!r)return;const o=r[e?e-1:1];for(;o&&i--;)this.styles[t][e+i]=A({},o)}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=nt:this._selectionDirection===ct&&(this._selectionDirection=nt,this.selectionEnd=t),this.selectionStart=i):i>t&&i<e?this._selectionDirection===ct?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection=ct:this._selectionDirection===nt&&(this._selectionDirection=ct,this.selectionStart=e),this.selectionEnd=i)}}class Ko extends qo{initHiddenTextarea(){const t=this.canvas&&Te(this.canvas.getElement())||N(),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",compositionend:"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,{value:i,selectionStart:s,selectionEnd:r}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const n=()=>{this.updateFromTextArea(),this.fire(_t),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void n();const o=this._splitTextIntoLines(i).graphemeText,a=this._text.length,c=o.length,h=this.selectionStart,l=this.selectionEnd,u=h!==l;let d,g,f,p,m=c-a;const v=this.fromStringToGraphemeSelection(s,r,i),y=h>v.selectionStart;u?(g=this._text.slice(h,l),m+=l-h):c<a&&(g=y?this._text.slice(l+m,l):this._text.slice(h,h-m));const _=o.slice(v.selectionEnd-m,v.selectionEnd);if(g&&g.length&&(_.length&&(d=this.getSelectionStyles(h,h+1,!1),d=_.map((()=>d[0]))),u?(f=h,p=l):y?(f=l-g.length,p=l):(f=l,p=l+g.length),this.removeStyleFromTo(f,p)),_.length){const{copyPasteData:t}=G();e&&_.join("")===t.copiedText&&!R.disableStyleCopyPaste&&(d=t.copiedTextStyle),this.insertNewStyleBlock(_,h,d)}n()}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}=G();t.copiedText=this.getSelectedText(),R.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),c=this._textLines[r].slice(0,n),h=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+a-c.length+(1-h)}_getIndexOnLine(t,e){const i=this._textLines[t];let s,r,n=this._getLineLeftOffset(t),o=0;for(let a=0,c=i.length;a<c;a++)if(s=this.__charBounds[t][a].width,n+=s,n>e){r=!0;const t=n-s,i=n,c=Math.abs(t-e);o=Math.abs(i-e)<c?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===ct);if(e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i){const t=this.text.length;this.selectionStart=$i(0,this.selectionStart,t),this.selectionEnd=$i(0,this.selectionEnd,t),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===nt?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=nt,this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===ct&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection=nt,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===nt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=ct,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=ct,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Jo=t=>!!t.button;class Qo extends Ko{constructor(){super(...arguments),P(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new No(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e:e,alreadySelected:i}=t;this.canvas&&this.editable&&!Jo(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),i&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=i||this.isEditing)))}mouseUpHandler(t){let{e:e,transform:i}=t;const s=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||Jo(e)||s||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}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.getScenePoint(t).transform(te(this.calcTransformMatrix())).add(new It(-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 Zo="moveCursorUp",$o="moveCursorDown",ta="moveCursorLeft",ea="moveCursorRight",ia="exitEditing",sa=(t,e)=>{const i=e.getRetinaScaling();t.setTransform(i,0,0,i,0,0);const s=e.viewportTransform;t.transform(s[0],s[1],s[2],s[3],s[4],s[5])},ra=A({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:ia,27:ia,33:Zo,34:$o,35:ea,36:ta,37:ta,38:Zo,39:ea,40:$o},keysMapRtl:{9:ia,27:ia,33:Zo,34:$o,35:ta,36:ea,37:ea,38:Zo,39:ta,40:$o},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class na extends Qo{static getDefaults(){return A(A({},super.getDefaults()),na.ownDefaults)}get type(){const t=super.type;return"itext"===t?"i-text":t}constructor(t,e){super(t,A(A({},na.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof eo&&this.canvas.textEditingManager.remove(this),e instanceof eo&&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||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),i=this.findAncestorsWithClipPath(),s=i.length>0;let r,n=t;if(s){r=Ut(t.canvas),n=r.getContext("2d"),sa(n,this.canvas);const e=this.calcTransformMatrix();n.transform(e[0],e[1],e[2],e[3],e[4],e[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(n,e):this.renderCursor(n,e),s)for(const e of i){const i=e.clipPath,s=Ut(t.canvas),r=s.getContext("2d");if(sa(r,this.canvas),!i.absolutePositioned){const t=e.calcTransformMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5])}i.transform(r),i.drawObject(r,!0,{}),this.drawClipPathOnCache(n,i,s)}s&&(t.setTransform(1,0,0,1,0,0),t.drawImage(r,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const 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===ct||this.textAlign===Ci||this.textAlign===Oi?a.left*=-1:this.textAlign===nt||this.textAlign===Ti?a.left=n-(i>0?i:0):this.textAlign!==rt&&this.textAlign!==ki||(a.left=n-(i>0?i:0))),a}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._getCursorBoundaries(t);const i=this.get2DCursorLocation(t),s=i.lineIndex,r=i.charIndex>0?i.charIndex-1:0,n=this.getValueOfPropertyAt(s,r,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),a=this.cursorWidth/o,c=this.getValueOfPropertyAt(s,r,"deltaY"),h=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(s)/this.lineHeight-n*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(s,r,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-a/2,top:h+e.top+c,width:a,height:n}}_renderCursor(t,e,i){const{color:s,opacity:r,left:n,top:o,width:a,height:c}=this.getCursorRenderingData(i,e);t.fillStyle=s,t.globalAlpha=r,t.fillRect(n,o,a,c)}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(Ci),o=this.get2DCursorLocation(s),a=this.get2DCursorLocation(r),c=o.lineIndex,h=a.lineIndex,l=o.charIndex<0?0:o.charIndex,u=a.charIndex<0?0:a.charIndex;for(let e=c;e<=h;e++){const s=this._getLineLeftOffset(e)||0;let r=this.getHeightOfLine(e),o=0,a=0,d=0;if(e===c&&(a=this.__charBounds[c][l].left),e>=c&&e<h)d=n&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===h)if(0===u)d=this.__charBounds[h][u].left;else{const t=this._getWidthOfCharSpacing();d=this.__charBounds[h][u-1].left+this.__charBounds[h][u-1].width-t}o=r,(this.lineHeight<1||e===h&&this.lineHeight>1)&&(r/=this.lineHeight);let g=i.left+s+a,f=r,p=0;const m=d-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",f=1,p=r):t.fillStyle=this.selectionColor,"rtl"===this.direction&&(this.textAlign===ct||this.textAlign===Ci||this.textAlign===Oi?g=this.width-g-m:this.textAlign===nt||this.textAlign===Ti?g=i.left+s-d:this.textAlign!==rt&&this.textAlign!==ki||(g=i.left+s-d)),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,Tt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}P(na,"ownDefaults",ra),P(na,"type","IText"),Et.setClass(na),Et.setClass(na,"i-text");class oa extends na{static getDefaults(){return A(A({},super.getDefaults()),oa.ownDefaults)}constructor(t,e){super(t,A(A({},oa.ownDefaults),e))}static createControls(){return{controls:ir()}}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(Ci)&&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];super._setStyleDeclaration(s.line,s.offset+e,i)}_deleteStyleDeclaration(t,e){const i=this._styleMap[t];super._deleteStyleDeclaration(i.line,i.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const 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,!0).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,c=[],h=a?"":" ";let l=0,u=[],d=0,g=0,f=!0;e-=n;const p=Math.max(e,s,this.dynamicMinWidth),m=r[t];let v;for(d=0,v=0;v<m.length;v++){const{word:e,width:i}=m[v];d+=e.length,l+=g+i-o,l>p&&!f?(c.push(u),u=[],l=i,f=!0):l+=o,f||a||u.push(h),u=u.concat(e),g=a?0:this._measureWord([h],t,d),d++,f=!1}return v&&c.push(u),s+n>this.dynamicMinWidth&&(this.dynamicMinWidth=s-o+n),c}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])}}P(oa,"type","Textbox"),P(oa,"textLayoutProperties",[...na.textLayoutProperties,"width"]),P(oa,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),Et.setClass(oa);class aa extends on{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:i}=t,{clipPath:s,group:r}=i;if(!s||!this.shouldPerformLayout(t))return;const{width:n,height:o}=Re(nn(i,s)),a=new It(n,o);if(s.absolutePositioned)return{center:Ge(s.getRelativeCenterPoint(),void 0,r?r.calcTransformMatrix():void 0),size:a};{const r=s.getRelativeCenterPoint().transform(i.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:i=new It,correction:s=new It}=this.calcBoundingBox(e,t)||{};return{center:i.add(r),correction:s.subtract(r),size:a}}return{center:i.getRelativeCenterPoint().add(r),size:a}}}}P(aa,"type","clip-path"),Et.setClass(aa);class ca extends on{getInitialSize(t,e){let{target:i}=t,{size:s}=e;return new It(i.width||s.x,i.height||s.y)}}P(ca,"type","fixed"),Et.setClass(ca);class ha extends un{subscribeTargets(t){const e=t.target;t.targets.reduce(((t,e)=>(e.parent&&t.add(e.parent),t)),new Set).forEach((t=>{t.layoutManager.subscribeTargets({target:t,targets:[e]})}))}unsubscribeTargets(t){const e=t.target,i=e.getObjects();t.targets.reduce(((t,e)=>(e.parent&&t.add(e.parent),t)),new Set).forEach((t=>{!i.some((e=>e.parent===t))&&t.layoutManager.unsubscribeTargets({target:t,targets:[e]})}))}}class la extends fn{static getDefaults(){return A(A({},super.getDefaults()),la.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,la.ownDefaults),this.setOptions(e);const{left:i,top:s,layoutManager:r}=e;this.groupInit(t,{left:i,top:s,layoutManager:null!=r?r:new ha})}_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)}))}canEnterGroup(t){return this.getObjects().some((e=>e.isDescendantOf(t)||t.isDescendantOf(e)))?(B("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const i=new Set;e.forEach((t=>{const{parent:e}=t;e&&i.add(e)})),t===sn?i.forEach((t=>{t._onAfterObjectsChange(en,e)})):i.forEach((t=>{t._set("dirty",!0)}))}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,i){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const s=A(A({hasControls:!1},i),{},{forActiveSelection:!0});for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,s);super._renderControls(t,e),t.restore()}}P(la,"type","ActiveSelection"),P(la,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),Et.setClass(la),Et.setClass(la,"activeSelection");class ua{constructor(){P(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 da{constructor(){let{tileSize:t=R.textureSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};P(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),P(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const i=Ut({width:t,height:e}),s=i.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});s&&(s.clearColor(0,0,0,0),this.canvas=i,this.gl=s)}applyFilters(t,e,i,s,r,n){const o=this.gl,a=r.getContext("2d");if(!o||!a)return;let c;n&&(c=this.getCachedTexture(n,e));const h={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:i,sourceHeight:s,destinationWidth:i,destinationHeight:s,context:o,sourceTexture:this.createTexture(o,i,s,c?void 0:e),targetTexture:this.createTexture(o,i,s),originalTexture:c||this.createTexture(o,i,s,c?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(h)})),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)}(h),this.copyGLTo2D(o,h),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(h.sourceTexture),o.deleteTexture(h.targetTexture),o.deleteFramebuffer(l),a.setTransform(1,0,0,1,0,0),h}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:c,CLAMP_TO_EDGE:h,TEXTURE_MAG_FILTER:l,TEXTURE_MIN_FILTER:u,TEXTURE_WRAP_S:d,TEXTURE_WRAP_T:g}=t,f=t.createTexture();return t.bindTexture(o,f),t.texParameteri(o,l,r||n),t.texParameteri(o,u,r||n),t.texParameteri(o,d,h),t.texParameteri(o,g,h),s?t.texImage2D(o,0,a,a,c,s):t.texImage2D(o,0,a,e,i,0,a,c,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)}copyGLTo2DPutImageData(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 c=new ImageData(a,s,r);i.putImageData(c,0,0)}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}}let ga;function fa(){return!ga&&(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(ga=function(){const{WebGLProbe:t}=G();return t.queryWebGL(Gt()),R.enableGLFiltering&&t.isSupported(R.textureSize)?new da({tileSize:R.textureSize}):new ua}()),ga}const pa=["filters","resizeFilter","src","crossOrigin","type"],ma=["cropX","cropY"];class va extends nr{static getDefaults(){return A(A({},super.getDefaults()),va.ownDefaults)}constructor(t,e){super(),P(this,"_lastScaleX",1),P(this,"_lastScaleY",1),P(this,"_filterScalingX",1),P(this,"_filterScalingY",1),this.filters=[],Object.assign(this,va.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(zt()),this.setElement("string"==typeof t?(this.canvas&&Te(this.canvas.getElement())||N()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let i=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(i),null===(e=t.classList)||void 0===e||e.add(va.CSS_CANVAS),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=fa(!1);e instanceof da&&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&&G().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())})),A(A({},super.toObject([...ma,...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=zt();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,'" style="').concat(this.getSvgStyles(),'" />\n')],this.fill=t}return r=this.paintFirst!==Tt?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 ge(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=Ut(n),{width:a,height:c}=n;this._element=o,this._lastScaleX=t.scaleX=s,this._lastScaleY=t.scaleY=r,fa().applyFilters([t],n,a,c,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=Ut({width:i,height:s});this._element=t,this._filteredEl=t}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,i,s),this._lastScaleX=1,this._lastScaleY=1);fa().applyFilters(t,this._originalElement,i,s,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){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),c=e.naturalWidth||e.width,h=e.naturalHeight||e.height,l=o*i,u=a*s,d=Math.min(r*i,c-l),g=Math.min(n*s,h-u),f=-r/2,p=-n/2,m=Math.min(r,c/i-o),v=Math.min(n,h/s-a);e&&t.drawImage(e,l,u,d,g,f,p,m,v)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=this.getOriginalSize();this.width=t||i.width,this.height=e||i.height}parsePreserveAspectRatioAttribute(){const t=gi(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,c=1,h=0,l=0,u=0,d=0;return!t||t.alignX===ht&&t.alignY===ht?(a=e/n,c=i/o):("meet"===t.meetOrSlice&&(a=c=pn(this._element,s),r=(e-n*a)/2,"Min"===t.alignX&&(h=-r),"Max"===t.alignX&&(h=r),r=(i-o*c)/2,"Min"===t.alignY&&(l=-r),"Max"===t.alignY&&(l=r)),"slice"===t.meetOrSlice&&(a=c=mn(this._element,s),r=n-e/a,"Mid"===t.alignX&&(u=r/2),"Max"===t.alignX&&(u=r),r=o-i/c,"Mid"===t.alignY&&(d=r/2),"Max"===t.alignY&&(d=r),n=e/a,o=i/c)),{width:n,height:o,scaleX:a,scaleY:c,offsetLeft:h,offsetTop:l,cropX:u,cropY:d}}static fromObject(t,e){let{filters:i,resizeFilter:s,src:r,crossOrigin:n,type:o}=t,a=F(t,pa);return Promise.all([ge(r,A(A({},e),{},{crossOrigin:n})),i&&fe(i,e),s&&fe([s],e),pe(a,e)]).then((t=>{let[e,i=[],[s]=[],n={}]=t;return new this(e,A(A({},a),{},{src:r,filters:i,resizeFilter:s},n))}))}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 ge(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=Jr(t,this.ATTRIBUTE_NAMES,i);return this.fromURL(s["xlink:href"]||s.href,e,s).catch((t=>(B("log","Unable to parse Image",t),null)))}}P(va,"type","Image"),P(va,"cacheProperties",[...es,...ma]),P(va,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),P(va,"CSS_CANVAS","canvas-img"),P(va,"ATTRIBUTE_NAMES",[...wr,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),Et.setClass(va),Et.setSVGClass(va),mi(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const ya=vt,_a=t=>function(e,i,s){const{points:r,pathOffset:n}=s;return new It(r[t]).subtract(n).transform(ee(s.getViewportTransform(),s.calcTransformMatrix()))},xa=(t,e,i,s)=>{const{target:r,pointIndex:n}=e,o=r,a=Ge(new It(i,s),void 0,o.calcOwnMatrix());return o.points[n]=a.add(o.pathOffset),o.setDimensions(),o.set("dirty",!0),!0},ba=(t,e)=>function(i,s,r,n){const o=s.target,a=new It(o.points[(t>0?t:o.points.length)-1]),c=a.subtract(o.pathOffset).transform(o.calcOwnMatrix()),h=e(i,A(A({},s),{},{pointIndex:t}),r,n),l=a.subtract(o.pathOffset).transform(o.calcOwnMatrix()).subtract(c);return o.left-=l.x,o.top-=l.y,h},wa=t=>Os(ya,ba(t,xa)),Sa=(t,e,i)=>{const{path:s,pathOffset:r}=t,n=s[e];return new It(n[i]-r.x,n[i+1]-r.y).transform(ee(t.getViewportTransform(),t.calcTransformMatrix()))};function Ca(t,e,i){const{commandIndex:s,pointIndex:r}=this;return Sa(i,s,r)}function Ta(t,e,i,s){const{target:r}=e,{commandIndex:n,pointIndex:o}=this,a=((t,e,i,s,r)=>{const{path:n,pathOffset:o}=t,a=n[(s>0?s:n.length)-1],c=new It(a[r],a[r+1]),h=c.subtract(o).transform(t.calcOwnMatrix()),l=Ge(new It(e,i),void 0,t.calcOwnMatrix());n[s][r]=l.x+o.x,n[s][r+1]=l.y+o.y,t.setDimensions();const u=c.subtract(t.pathOffset).transform(t.calcOwnMatrix()).subtract(h);return t.left-=u.x,t.top-=u.y,t.set("dirty",!0),!0})(r,i,s,n,o);return qe(this.actionName,A(A({},ei(t,e,i,s)),{},{commandIndex:n,pointIndex:o})),a}class Oa extends Ps{constructor(t){super(t)}render(t,e,i,s,r){const n=A(A({},s),{},{cornerColor:this.controlFill,cornerStrokeColor:this.controlStroke,transparentCorners:!this.controlFill});super.render(t,e,i,n,r)}}class ka extends Oa{constructor(t){super(t)}render(t,e,i,s,r){const{path:n}=r,{commandIndex:o,pointIndex:a,connectToCommandIndex:c,connectToPointIndex:h}=this;t.save(),t.strokeStyle=this.controlStroke,this.connectionDashArray&&t.setLineDash(this.connectionDashArray);const[l]=n[o],u=Sa(r,c,h);if("Q"===l){const s=Sa(r,o,a+2);t.moveTo(s.x,s.y),t.lineTo(e,i)}else t.moveTo(e,i);t.lineTo(u.x,u.y),t.stroke(),t.restore(),super.render(t,e,i,s,r)}}const Da=(t,e,i,s,r,n)=>new(i?ka:Oa)(A(A({commandIndex:t,pointIndex:e,actionName:"modifyPath",positionHandler:Ca,actionHandler:Ta,connectToCommandIndex:r,connectToPointIndex:n},s),i?s.controlPointStyle:s.pointStyle));Object.freeze({__proto__:null,changeWidth:Ds,createObjectDefaultControls:tr,createPathControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i={};let s="M";return t.path.forEach(((t,r)=>{const n=t[0];switch("Z"!==n&&(i["c_".concat(r,"_").concat(n)]=Da(r,t.length-2,!1,e)),n){case"C":i["c_".concat(r,"_C_CP_1")]=Da(r,1,!0,e,r-1,(t=>"C"===t?5:"Q"===t?3:1)(s)),i["c_".concat(r,"_C_CP_2")]=Da(r,3,!0,e,r,5);break;case"Q":i["c_".concat(r,"_Q_CP_1")]=Da(r,1,!0,e,r,3)}s=n})),i},createPolyActionHandler:wa,createPolyControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i={};for(let s=0;s<("number"==typeof t?t:t.points.length);s++)i["p".concat(s)]=new Ps(A({actionName:ya,positionHandler:_a(s),actionHandler:wa(s)},e));return i},createPolyPositionHandler:_a,createResizeControls:er,createTextboxDefaultControls:ir,dragHandler:ri,factoryPolyActionHandler:ba,getLocalPoint:si,polyActionHandler:xa,renderCircleControl:Ms,renderSquareControl:Es,rotationStyleHandler:js,rotationWithSnapping:As,scaleCursorStyleHandler:Rs,scaleOrSkewActionName:Js,scaleSkewCursorStyleHandler:Qs,scalingEqually:Xs,scalingX:Vs,scalingXOrSkewingY:Zs,scalingY:Ys,scalingYOrSkewingX:$s,skewCursorStyleHandler:Gs,skewHandlerX:Us,skewHandlerY:qs,wrapWithFireEvent:Os,wrapWithFixedAnchor:ks});const Ma=t=>void 0!==t.webgl,Ea="precision highp float",Pa="\n ".concat(Ea,";\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }"),ja=["type"],Aa=["type"],Fa=new RegExp(Ea,"g");class La{get type(){return this.constructor.type}constructor(){let t=F(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},ja);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Pa}getVertexSource(){return"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n void main() {\n vTexCoord = aPosition;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }"}createProgram(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getFragmentSource(),i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:s="highp"}}=G();"highp"!==s&&(e=e.replace(Fa,Ea.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 X("Vertex, fragment shader or program creation error");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new X("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 X("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 X('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const a=this.getUniformLocations(t,o)||{};return a.uStepW=t.getUniformLocation(o,"uStepW"),a.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:a}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const i=this.constructor.uniformLocations,s={};for(let r=0;r<i.length;r++)s[i[r]]=t.getUniformLocation(e,i[r]);return s}sendAttributeData(t,e,i){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){return!1}applyTo(t){Ma(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)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:i}=t,s=Ut({width:e,height:i});t.helpLayer=s}}toObject(){const t=Object.keys(this.constructor.defaults||{});return A({type:this.type},t.reduce(((t,e)=>(t[e]=this[e],t)),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(F(t,Aa))}}P(La,"type","BaseFilter"),P(La,"uniformLocations",[]);const Ia={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 Ra extends La{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(Ia[this.mode],"\n }\n }\n ")}applyTo2d(t){let{imageData:{data:e}}=t;const i=new ui(this.color).getSource(),s=this.alpha,r=i[0]*s,n=i[1]*s,o=i[2]*s,a=1-s;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],c=e[t+2];let h,l,u;switch(this.mode){case"multiply":h=i*r/255,l=s*n/255,u=c*o/255;break;case"screen":h=255-(255-i)*(255-r)/255,l=255-(255-s)*(255-n)/255,u=255-(255-c)*(255-o)/255;break;case"add":h=i+r,l=s+n,u=c+o;break;case"difference":h=Math.abs(i-r),l=Math.abs(s-n),u=Math.abs(c-o);break;case"subtract":h=i-r,l=s-n,u=c-o;break;case"darken":h=Math.min(i,r),l=Math.min(s,n),u=Math.min(c,o);break;case"lighten":h=Math.max(i,r),l=Math.max(s,n),u=Math.max(c,o);break;case"overlay":h=r<128?2*i*r/255:255-2*(255-i)*(255-r)/255,l=n<128?2*s*n/255:255-2*(255-s)*(255-n)/255,u=o<128?2*c*o/255:255-2*(255-c)*(255-o)/255;break;case"exclusion":h=r+i-2*r*i/255,l=n+s-2*n*s/255,u=o+c-2*o*c/255;break;case"tint":h=r+i*a,l=n+s*a,u=o+c*a}e[t]=h,e[t+1]=l,e[t+2]=u}}sendUniformData(t,e){const i=new ui(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)}}P(Ra,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),P(Ra,"type","BlendColor"),P(Ra,"uniformLocations",["uColor"]),Et.setClass(Ra);const Ba={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 "},Xa=["type","image"];class Va extends La{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ba[this.mode]}getVertexSource(){return"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n uniform mat3 uTransformMatrix;\n void main() {\n vTexCoord = aPosition;\n vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }\n "}applyToWebGL(t){const e=t.context,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=Gt());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 c=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=c[t],a=c[t+1],h=c[t+2],l=c[t+3];switch(this.mode){case"multiply":e[t]=i*o/255,e[t+1]=s*a/255,e[t+2]=r*h/255,e[t+3]=n*l/255;break;case"mask":e[t+3]=l}}}sendUniformData(t,e){const i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)}toObject(){return A(A({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:i,image:s}=t,r=F(t,Xa);return va.fromObject(s,e).then((t=>new this(A(A({},r),{},{image:t}))))}}P(Va,"type","BlendImage"),P(Va,"defaults",{mode:"multiply",alpha:1}),P(Va,"uniformLocations",["uTransformMatrix","uImage"]),Et.setClass(Va);class Ya extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n const float nSamples = 15.0;\n vec3 v3offset = vec3(12.9898, 78.233, 151.7182);\n float random(vec3 scale) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n }\n void main() {\n vec4 color = vec4(0.0);\n float totalC = 0.0;\n float totalA = 0.0;\n float offset = random(v3offset);\n for (float t = -nSamples; t <= nSamples; t++) {\n float percent = (t + offset - 0.5) / nSamples;\n vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);\n float weight = 1.0 - abs(percent);\n float alpha = weight * sample.a;\n color.rgb += sample.rgb * alpha;\n color.a += alpha;\n totalA += weight;\n totalC += alpha;\n }\n gl_FragColor.rgb = color.rgb / totalC;\n gl_FragColor.a = color.a / totalA;\n }\n "}applyTo(t){Ma(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){let{imageData:{data:e,width:i,height:s}}=t;this.aspectRatio=i/s,this.horizontal=!0;let r=this.getBlurValue()*i;const n=new Uint8ClampedArray(e),o=4*i;for(let t=0;t<e.length;t+=4){let i=0,s=0,a=0,c=0,h=0;const l=t-t%o,u=l+o;for(let n=-14;n<15;n++){const o=n/15,d=4*Math.floor(r*o),g=1-Math.abs(o);let f=t+d;f<l?f=l:f>u&&(f=u);const p=e[f+3]*g;i+=e[f]*p,s+=e[f+1]*p,a+=e[f+2]*p,c+=p,h+=g}n[t]=i/c,n[t+1]=s/c,n[t+2]=a/c,n[t+3]=c/h}this.horizontal=!1,r=this.getBlurValue()*s;for(let t=0;t<n.length;t+=4){let i=0,s=0,a=0,c=0,h=0;const l=t%o,u=n.length-o+l;for(let e=-14;e<15;e++){const d=e/15,g=Math.floor(r*d)*o,f=1-Math.abs(d);let p=t+g;p<l?p=l:p>u&&(p=u);const m=n[p+3]*f;i+=n[p]*m,s+=n[p+1]*m,a+=n[p+2]*m,c+=m,h+=f}e[t]=i/c,e[t+1]=s/c,e[t+2]=a/c,e[t+3]=c/h}}sendUniformData(t,e){const i=this.chooseRightDelta();t.uniform2fv(e.uDelta,i)}isNeutralState(){return 0===this.blur}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:i}=this;return e?i>1&&(t=1/i):i<1&&(t=i),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}P(Ya,"type","Blur"),P(Ya,"defaults",{blur:0}),P(Ya,"uniformLocations",["uDelta"]),Et.setClass(Ya);class Wa extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBrightness;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += uBrightness;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=Math.round(255*this.brightness);for(let t=0;t<e.length;t+=4)e[t]+=i,e[t+1]+=i,e[t+2]+=i}isNeutralState(){return 0===this.brightness}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}P(Wa,"type","Brightness"),P(Wa,"defaults",{brightness:0}),P(Wa,"uniformLocations",["uBrightness"]),Et.setClass(Wa);const Ha={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class za extends La{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(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],!s){const s=e[t+3];e[t]+=s*i[3],e[t+1]+=s*i[8],e[t+2]+=s*i[13],e[t+3]=r*i[15]+n*i[16]+o*i[17]+s*i[18]+255*i[19]}}}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)}toObject(){return A(A({},super.toObject()),{},{matrix:[...this.matrix]})}}function Ga(t,e){var i;const s=(P(i=class extends za{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",t),P(i,"defaults",{colorsOnly:!1,matrix:e}),i);return Et.setClass(s,t),s}P(za,"type","ColorMatrix"),P(za,"defaults",Ha),P(za,"uniformLocations",["uColorMatrix","uConstants"]),Et.setClass(za);const Na=Ga("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Ua=Ga("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),qa=Ga("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Ka=Ga("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Ja=Ga("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Qa=Ga("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Za=Ga("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class $a extends La{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Ma(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach((e=>{e.applyTo(t)}))}toObject(){return{type:this.type,subFilters:this.subFilters.map((t=>t.toObject()))}}isNeutralState(){return!this.subFilters.some((t=>!t.isNeutralState()))}static fromObject(t,e){return Promise.all((t.subFilters||[]).map((t=>Et.getClass(t.type).fromObject(t,e)))).then((t=>new this({subFilters:t})))}}P($a,"type","Composed"),Et.setClass($a);class tc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uContrast;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\n color.rgb = contrastF * (color.rgb - 0.5) + 0.5;\n gl_FragColor = color;\n }"}isNeutralState(){return 0===this.contrast}applyTo2d(t){let{imageData:{data:e}}=t;const 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}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}P(tc,"type","Contrast"),P(tc,"defaults",{contrast:0}),P(tc,"uniformLocations",["uContrast"]),Et.setClass(tc);const ec={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 ic extends La{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ec[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,c=t.ctx.createImageData(o,a),h=c.data,l=this.opaque?1:0;let u,d,g,f,p,m,v,y,_,x,b,w,S;for(b=0;b<a;b++)for(x=0;x<o;x++){for(p=4*(b*o+x),u=0,d=0,g=0,f=0,S=0;S<r;S++)for(w=0;w<r;w++)v=b+S-n,m=x+w-n,v<0||v>=a||m<0||m>=o||(y=4*(v*o+m),_=s[S*r+w],u+=i[y]*_,d+=i[y+1]*_,g+=i[y+2]*_,l||(f+=i[y+3]*_));h[p]=u,h[p+1]=d,h[p+2]=g,h[p+3]=l?i[p+3]:f}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return A(A({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}P(ic,"type","Convolute"),P(ic,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),P(ic,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),Et.setClass(ic);const sc="Gamma";class rc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec3 uGamma;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec3 correction = (1.0 / uGamma);\n color.r = pow(color.r, correction.r);\n color.g = pow(color.g, correction.g);\n color.b = pow(color.b, correction.b);\n gl_FragColor = color;\n gl_FragColor.rgb *= color.a;\n }\n"}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const 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]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return 1===t[0]&&1===t[1]&&1===t[2]}toObject(){return{type:sc,gamma:this.gamma.concat()}}}P(rc,"type",sc),P(rc,"defaults",{gamma:[1,1,1]}),P(rc,"uniformLocations",["uGamma"]),Et.setClass(rc);const nc={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 oc extends La{applyTo2d(t){let{imageData:{data:e}}=t;for(let t,i=0;i<e.length;i+=4){const s=e[i],r=e[i+1],n=e[i+2];switch(this.mode){case"average":t=(s+r+n)/3;break;case"lightness":t=(Math.min(s,r,n)+Math.max(s,r,n))/2;break;case"luminosity":t=.21*s+.72*r+.07*n}e[i+2]=e[i+1]=e[i]=t}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return nc[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}P(oc,"type","Grayscale"),P(oc,"defaults",{mode:"average"}),P(oc,"uniformLocations",["uMode"]),Et.setClass(oc);const ac=A(A({},Ha),{},{rotation:0});class cc extends za{calculateMatrix(){const t=this.rotation*Math.PI,e=Ft(t),i=Lt(t),s=1/3,r=Math.sqrt(s)*i,n=1-e;this.matrix=[e+n/3,s*n-r,s*n+r,0,0,s*n+r,e+s*n,s*n-r,0,0,s*n-r,s*n+r,e+s*n,0,0,0,0,0,1,0]}isNeutralState(){return 0===this.rotation}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}P(cc,"type","HueRotation"),P(cc,"defaults",ac),Et.setClass(cc);class hc extends La{applyTo2d(t){let{imageData:{data:e}}=t;for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uInvert;\n uniform int uAlpha;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n if (uInvert == 1) {\n if (uAlpha == 1) {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);\n } else {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n }\n } else {\n gl_FragColor = color;\n }\n }\n"}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}P(hc,"type","Invert"),P(hc,"defaults",{alpha:!1,invert:!0}),P(hc,"uniformLocations",["uInvert","uAlpha"]),Et.setClass(hc);class lc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uStepH;\n uniform float uNoise;\n uniform float uSeed;\n varying vec2 vTexCoord;\n float rand(vec2 co, float seed, float vScale) {\n return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n }\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const 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}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return 0===this.noise}}P(lc,"type","Noise"),P(lc,"defaults",{noise:0}),P(lc,"uniformLocations",["uNoise","uSeed"]),Et.setClass(lc);class uc extends La{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],c=e[n+2],h=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]=c,e[s+3]=h}}}isNeutralState(){return 1===this.blocksize}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBlocksize;\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n float blockW = uBlocksize * uStepW;\n float blockH = uBlocksize * uStepH;\n int posX = int(vTexCoord.x / blockW);\n int posY = int(vTexCoord.y / blockH);\n float fposX = float(posX);\n float fposY = float(posY);\n vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\n vec4 color = texture2D(uTexture, squareCoords);\n gl_FragColor = color;\n }\n"}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}P(uc,"type","Pixelate"),P(uc,"defaults",{blocksize:4}),P(uc,"uniformLocations",["uBlocksize"]),Et.setClass(uc);class dc extends La{getFragmentSource(){return"\nprecision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\n gl_FragColor.a = 0.0;\n }\n}\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=255*this.distance,s=new ui(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)}}sendUniformData(t,e){const i=new ui(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)}}P(dc,"type","RemoveColor"),P(dc,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),P(dc,"uniformLocations",["uLow","uHigh"]),Et.setClass(dc);class gc extends La{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 precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[".concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map(((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(e,"];\n "))).join("\n"),"\n gl_FragColor = color / sum;\n }\n ")}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Ma(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 c;c="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=c}sliceByTwo(t,e,i,s,r){const n=t.imageData,o=.5;let a=!1,c=!1,h=e*o,l=i*o;const u=t.filterBackend.resources;let d=0,g=0;const f=e;let p=0;u.sliceByTwo||(u.sliceByTwo=Gt());const m=u.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||!c;)e=h,i=l,s<Math.floor(h*o)?h=Math.floor(h*o):(h=s,a=!0),r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,c=!0),v.drawImage(m,d,g,e,i,f,p,h,l),d=f,g=p,p+=l;return v.getImageData(d,g,s,r)}lanczosResize(t,e,i,s,r){const n=t.imageData.data,o=t.ctx.createImageData(s,r),a=o.data,c=this.lanczosCreate(this.lanczosLobes),h=this.rcpScaleX,l=this.rcpScaleY,u=2/this.rcpScaleX,d=2/this.rcpScaleY,g=Math.ceil(h*this.lanczosLobes/2),f=Math.ceil(l*this.lanczosLobes/2),p={},m={x:0,y:0},v={x:0,y:0};return function t(y){let _,x,b,w,S,C,T,O,k,D,M;for(m.x=(y+.5)*h,v.x=Math.floor(m.x),_=0;_<r;_++){for(m.y=(_+.5)*l,v.y=Math.floor(m.y),S=0,C=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]=c(Math.sqrt(Math.pow(D*u,2)+Math.pow(M*d,2))/1e3)),b=p[D][M],b>0&&(w=4*(t*e+x),S+=b,C+=b*n[w],T+=b*n[w+1],O+=b*n[w+2],k+=b*n[w+3]))}w=4*(_*s+y),a[w]=C/S,a[w+1]=T/S,a[w+2]=O/S,a[w+3]=k/S}return++y<s?t(y):o}(0)}bilinearFiltering(t,e,i,s,r){let n,o,a,c,h,l,u,d,g,f,p,m,v,y=0;const _=this.rcpScaleX,x=this.rcpScaleY,b=4*(e-1),w=t.imageData.data,S=t.ctx.createImageData(s,r),C=S.data;for(u=0;u<r;u++)for(d=0;d<s;d++)for(h=Math.floor(_*d),l=Math.floor(x*u),g=_*d-h,f=x*u-l,v=4*(l*e+h),p=0;p<4;p++)n=w[v+p],o=w[v+4+p],a=w[v+b+p],c=w[v+b+4+p],m=n*(1-g)*(1-f)+o*g*(1-f)+a*f*(1-g)+c*g*f,C[y++]=m;return S}hermiteFastResize(t,e,i,s,r){const n=this.rcpScaleX,o=this.rcpScaleY,a=Math.ceil(n/2),c=Math.ceil(o/2),h=t.imageData.data,l=t.ctx.createImageData(s,r),u=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,d=0,g=0,f=0,p=0,m=0,v=0;const y=(t+.5)*o;for(let s=Math.floor(t*o);s<(t+1)*o;s++){const t=Math.abs(y-(s+.5))/c,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*h[i+3],g+=l,h[i+3]<255&&(l=l*h[i+3]/250),f+=l*h[i],p+=l*h[i+1],m+=l*h[i+2],d+=l))}}u[r]=f/d,u[r+1]=p/d,u[r+2]=m/d,u[r+3]=v/g}return l}}P(gc,"type","Resize"),P(gc,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),P(gc,"uniformLocations",["uDelta","uTaps"]),Et.setClass(gc);class fc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uSaturation;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float rgMax = max(color.r, color.g);\n float rgbMax = max(rgMax, color.b);\n color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\n color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\n color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=-this.saturation;for(let t=0;t<e.length;t+=4){const s=e[t],r=e[t+1],n=e[t+2],o=Math.max(s,r,n);e[t]+=o!==s?(o-s)*i:0,e[t+1]+=o!==r?(o-r)*i:0,e[t+2]+=o!==n?(o-n)*i:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return 0===this.saturation}}P(fc,"type","Saturation"),P(fc,"defaults",{saturation:0}),P(fc,"uniformLocations",["uSaturation"]),Et.setClass(fc);class pc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uVibrance;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float max = max(color.r, max(color.g, color.b));\n float avg = (color.r + color.g + color.b) / 3.0;\n float amt = (abs(max - avg) * 2.0) * uVibrance;\n color.r += max != color.r ? (max - color.r) * amt : 0.00;\n color.g += max != color.g ? (max - color.g) * amt : 0.00;\n color.b += max != color.b ? (max - color.b) * amt : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=-this.vibrance;for(let t=0;t<e.length;t+=4){const s=e[t],r=e[t+1],n=e[t+2],o=Math.max(s,r,n),a=(s+r+n)/3,c=2*Math.abs(o-a)/255*i;e[t]+=o!==s?(o-s)*c:0,e[t+1]+=o!==r?(o-r)*c:0,e[t+2]+=o!==n?(o-n)*c:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return 0===this.vibrance}}P(pc,"type","Vibrance"),P(pc,"defaults",{vibrance:0}),P(pc,"uniformLocations",["uVibrance"]),Et.setClass(pc),Object.freeze({__proto__:null,BaseFilter:La,BlackWhite:Za,BlendColor:Ra,BlendImage:Va,Blur:Ya,Brightness:Wa,Brownie:Na,ColorMatrix:za,Composed:$a,Contrast:tc,Convolute:ic,Gamma:rc,Grayscale:oc,HueRotation:cc,Invert:hc,Kodachrome:qa,Noise:lc,Pixelate:uc,Polaroid:Ja,RemoveColor:dc,Resize:gc,Saturation:fc,Sepia:Qa,Technicolor:Ka,Vibrance:pc,Vintage:Ua});var mc=function(){function t(e,i){var s;return y(this,t),b(T(s=l(this,t,[e,g({originX:"center",originY:"center",left:0,top:0,layoutManager:new un(new ca)},i)])),"blockErasing",!1),s}return w(t,fn),x(t,[{key:"drawObject",value:function(t){var e=[],i=[];this._objects.forEach((function(t){return(t instanceof So?e:i).push(t)})),t.save(),t.fillStyle="black",t.fillRect(-this.width/2,-this.height/2,this.width,this.height),t.restore(),!this.blockErasing&&e.forEach((function(e){e.render(t)})),i.forEach((function(e){e.globalCompositeOperation=e.inverted?"destination-out":"source-in",e.render(t)}))}}]),t}();b(mc,"type","clipping"),Et.setClass(mc);var vc=function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"source-over";t.save(),t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high",t.globalCompositeOperation=i,t.resetTransform(),t.drawImage(e.canvas,0,0),t.restore()};function yc(t){return t.flatMap((function(t){return!t.erasable||t.isNotVisible()?[]:t instanceof fn&&"deep"===t.erasable?yc(t.getObjects()):[t]}))}function _c(t,e,i){var s=e.inverted,r=e.opacity,n=i.canvas,o=i.objects,a=void 0===o?n._objectsToRender||n._objects:o,c=i.background,h=void 0===c?n.backgroundImage:c,l=i.overlay,u=void 0===l?n.overlayImage:l,d=1-r,g=yc([].concat(D(a),D([h,u].filter((function(t){return!!t}))))).map((function(t){if(!s){var e,i=t.opacity;return t.opacity*=d,null===(e=t.parent)||void 0===e||e.set("dirty",!0),{object:t,opacity:i}}if(t.clipPath instanceof mc)return t.clipPath.blockErasing=!0,t.clipPath.set("dirty",!0),t.set("dirty",!0),{object:t,clipPath:t.clipPath}}));!function(t,e,i){e.clearContext(t),t.imageSmoothingEnabled=e.imageSmoothingEnabled,t.imageSmoothingQuality="high",t.patternQuality="best",e._renderBackground(t),t.save(),t.transform.apply(t,D(e.viewportTransform)),i.forEach((function(e){return e.render(t)})),t.restore();var s=e.clipPath;s&&(s._set("canvas",e),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),e.drawClipPathOnCanvas(t,s)),e._renderOverlay(t)}(t,n,a),g.forEach((function(t){var e;t&&(t.opacity?(t.object.opacity=t.opacity,null===(e=t.object.parent)||void 0===e||e.set("dirty",!0)):t.clipPath&&(t.clipPath.blockErasing=!1,t.clipPath.set("dirty",!0),t.object.set("dirty",!0)))}))}function xc(t,e){return t.flatMap((function(t){return t.erasable&&t.intersectsWithObject(e)?t instanceof fn&&"deep"===t.erasable?xc(t.getObjects(),e):[t]:[]}))}function bc(t,e){var i=function(t){var e=t.clipPath;if(e instanceof mc)return e;var i=t.strokeWidth,s=new It(i,i),r=t.strokeUniform?s.divide(t.getObjectScaling()):s,n=new mc([],{width:t.width+r.x,height:t.height+r.y});if(e){var o=e.translateToOriginPoint(new It,e.originX,e.originY),a=o.x,c=o.y;e.originX=e.originY="center",Gn.sendObjectToPlane(e,void 0,Gn.createTranslateMatrix(a,c)),n.add(e)}return t.clipPath=n}(t);i.add(e),i.set("dirty",!0),t.set("dirty",!0)}function wc(t,e){return Sc.apply(this,arguments)}function Sc(){return(Sc=v(f().mark((function t(e,i){var s;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i.clone();case 2:return s=t.sent,Gn.sendObjectToPlane(s,void 0,e.calcTransformMatrix()),bc(e,s),t.abrupt("return",s);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Cc(t,e,i){return Tc.apply(this,arguments)}function Tc(){return Tc=v(f().mark((function t(e,i,s){var r,n;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.clone();case 2:return r=t.sent,n=i&&e.translateToOriginPoint(new It,e.originX,e.originY),Gn.sendObjectToPlane(r,void 0,n?Gn.multiplyTransformMatrixArray([[1,0,0,1,n.x,n.y],i,[1,0,0,1,-n.x,-n.y],e.calcTransformMatrix()]):e.calcTransformMatrix()),bc(e,r),t.abrupt("return",r);case 7:case"end":return t.stop()}}),t)}))),Tc.apply(this,arguments)}var Oc=function(){function t(e){var i;y(this,t),b(T(i=l(this,t,[e])),"inverted",!1),b(T(i),"active",!1);var s=document.createElement("canvas"),r=s.getContext("2d");if(!r)throw new Error("Failed to get context");return function(t,e,i){var s=i.width,r=i.height,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))}(s,r,e,i.canvas.getRetinaScaling()),i.effectContext=r,i.eventEmitter=new EventTarget,i}var e;return w(t,Co),x(t,[{key:"on",value:function(t,e,i){var s=this;return this.eventEmitter.addEventListener(t,e,i),function(){return s.eventEmitter.removeEventListener(t,e,i)}}},{key:"drawEffect",value:function(){_c(this.effectContext,{opacity:new ui(this.color).getAlpha(),inverted:this.inverted},{canvas:this.canvas})}},{key:"_setBrushStyles",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.contextTop;O(S(t.prototype),"_setBrushStyles",this).call(this,e),e.strokeStyle="black"}},{key:"needsFullRender",value:function(){return!0}},{key:"_render",value:function(){var e,i,s,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.getTopContext();O(S(t.prototype),"_render",this).call(this,r),e=this.canvas.getContext(),i=r,s=this.effectContext,vc(e,i,"destination-out"),s?vc(i,s,"source-in"):(i.save(),i.resetTransform(),i.clearRect(0,0,i.canvas.width,i.canvas.height),i.restore())}},{key:"onMouseDown",value:function(e,i){var s=this;this.eventEmitter.dispatchEvent(new CustomEvent("start",{detail:i,cancelable:!0}))&&(this.active=!0,this.eventEmitter.dispatchEvent(new CustomEvent("redraw",{detail:{type:"start"},cancelable:!0}))&&this.drawEffect(),this._disposer=this.canvas.on("after:render",(function(t){t.ctx===s.canvas.getContext()&&(s.eventEmitter.dispatchEvent(new CustomEvent("redraw",{detail:{type:"render"},cancelable:!0}))&&s.drawEffect(),s._render())})),O(S(t.prototype),"onMouseDown",this).call(this,e,i))}},{key:"onMouseMove",value:function(e,i){this.active&&this.eventEmitter.dispatchEvent(new CustomEvent("move",{detail:i,cancelable:!0}))&&O(S(t.prototype),"onMouseMove",this).call(this,e,i)}},{key:"onMouseUp",value:function(e){var i;return this.active&&O(S(t.prototype),"onMouseUp",this).call(this,e),this.active=!1,null===(i=this._disposer)||void 0===i||i.call(this),delete this._disposer,!1}},{key:"convertPointsToSVGPath",value:function(e){return O(S(t.prototype),"convertPointsToSVGPath",this).call(this,this.decimate?this.decimatePoints(e,this.decimate):e)}},{key:"createPath",value:function(e){var i=O(S(t.prototype),"createPath",this).call(this,e);return i.set(this.inverted?{globalCompositeOperation:"source-over",stroke:"white"}:{globalCompositeOperation:"destination-out",stroke:"black",opacity:new ui(this.color).getAlpha()}),i}},{key:"commit",value:(e=v(f().mark((function t(e){var i,s;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=e.path,s=e.targets,t.t0=Map,t.next=4,Promise.all([].concat(D(s.map(function(){var t=v(f().mark((function t(e){return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=e,t.next=3,wc(e,i);case 3:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),D([[this.canvas.backgroundImage,this.canvas.backgroundVpt?void 0:this.canvas.viewportTransform],[this.canvas.overlayImage,this.canvas.overlayVpt?void 0:this.canvas.viewportTransform]].filter((function(t){var e=k(t,1)[0];return!(null==e||!e.erasable)})).map(function(){var t=v(f().mark((function t(e){var s,r,n;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s=k(e,2),r=s[0],n=s[1],t.t0=r,t.next=4,Cc(r,n,i);case 4:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()))));case 4:return t.t1=t.sent,t.abrupt("return",new t.t0(t.t1));case 6:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"_finalizeAndAddPath",value:function(){var t=this._points;if(t.length<2)this.eventEmitter.dispatchEvent(new CustomEvent("cancel",{cancelable:!1}));else{var e=this.createPath(this.convertPointsToSVGPath(t)),i=xc(this.canvas.getObjects(),e);this.eventEmitter.dispatchEvent(new CustomEvent("end",{detail:{path:e,targets:i},cancelable:!0}))&&this.commit({path:e,targets:i}),this.canvas.clearContext(this.canvas.contextTop),this.canvas.requestRenderAll(),this._resetShadow()}}},{key:"dispose",value:function(){var t=this.effectContext.canvas;t.width=t.height=0}}]),t}();const kc={toVector:(t,e)=>(void 0===t&&(t=e),Array.isArray(t)?t:[t,t]),add:(t,e)=>[t[0]+e[0],t[1]+e[1]],sub:(t,e)=>[t[0]-e[0],t[1]-e[1]],addTo(t,e){t[0]+=e[0],t[1]+=e[1]},subTo(t,e){t[0]-=e[0],t[1]-=e[1]}};function Dc(t,e,i){return 0===e||Math.abs(e)===1/0?Math.pow(t,5*i):t*e*i/(e+i*t)}function Mc(t,e,i,s=.15){return 0===s?function(t,e,i){return Math.max(e,Math.min(t,i))}(t,e,i):t<e?-Dc(e-t,i-e,s)+e:t>i?+Dc(t-i,i-e,s)+i:t}function Ec(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)}function Pc(t,e,i){return(e=Ec(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function jc(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 Ac(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?jc(Object(i),!0).forEach((function(e){Pc(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):jc(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}const Fc={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function Lc(t){return t?t[0].toUpperCase()+t.slice(1):""}const Ic=["enter","leave"];function Rc(t,e="",i=!1){const s=Fc[t],r=s&&s[e]||e;return"on"+Lc(t)+Lc(r)+(function(t=!1,e){return t&&!Ic.includes(e)}(i,r)?"Capture":"")}const Bc=["gotpointercapture","lostpointercapture"];function Xc(t){let e=t.substring(2).toLowerCase();const i=!!~e.indexOf("passive");i&&(e=e.replace("passive",""));const s=Bc.includes(e)?"capturecapture":"capture",r=!!~e.indexOf(s);return r&&(e=e.replace("capture","")),{device:e,capture:r,passive:i}}function Vc(t){return"touches"in t}function Yc(t){return Vc(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function Wc(t){return Vc(t)?function(t){return"touchend"===t.type||"touchcancel"===t.type?t.changedTouches:t.targetTouches}(t)[0]:t}function Hc(t,e){try{const i=e.clientX-t.clientX,s=e.clientY-t.clientY,r=(e.clientX+t.clientX)/2,n=(e.clientY+t.clientY)/2,o=Math.hypot(i,s),a=-180*Math.atan2(i,s)/Math.PI;return{angle:a,distance:o,origin:[r,n]}}catch(t){}return null}function zc(t){return function(t){return Array.from(t.touches).filter((e=>{var i,s;return e.target===t.currentTarget||(null===(i=t.currentTarget)||void 0===i||null===(s=i.contains)||void 0===s?void 0:s.call(i,e.target))}))}(t).map((t=>t.identifier))}function Gc(t,e){const[i,s]=Array.from(t.touches).filter((t=>e.includes(t.identifier)));return Hc(i,s)}function Nc(t){const e=Wc(t);return Vc(t)?e.identifier:e.pointerId}function Uc(t){const e=Wc(t);return[e.clientX,e.clientY]}function qc(t){let{deltaX:e,deltaY:i,deltaMode:s}=t;return 1===s?(e*=40,i*=40):2===s&&(e*=800,i*=800),[e,i]}function Kc(t,...e){return"function"==typeof t?t(...e):t}function Jc(){}function Qc(...t){return 0===t.length?Jc:1===t.length?t[0]:function(){let e;for(const i of t)e=i.apply(this,arguments)||e;return e}}function Zc(t,e){return Object.assign({},e,t||{})}class $c{constructor(t,e,i){this.ctrl=t,this.args=e,this.key=i,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(t){this.ctrl.state[this.key]=t}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:t,shared:e,ingKey:i,args:s}=this;e[i]=t._active=t.active=t._blocked=t._force=!1,t._step=[!1,!1],t.intentional=!1,t._movement=[0,0],t._distance=[0,0],t._direction=[0,0],t._delta=[0,0],t._bounds=[[-1/0,1/0],[-1/0,1/0]],t.args=s,t.axis=void 0,t.memo=void 0,t.elapsedTime=t.timeDelta=0,t.direction=[0,0],t.distance=[0,0],t.overflow=[0,0],t._movementBound=[!1,!1],t.velocity=[0,0],t.movement=[0,0],t.delta=[0,0],t.timeStamp=0}start(t){const e=this.state,i=this.config;e._active||(this.reset(),this.computeInitial(),e._active=!0,e.target=t.target,e.currentTarget=t.currentTarget,e.lastOffset=i.from?Kc(i.from,e):e.offset,e.offset=e.lastOffset,e.startTime=e.timeStamp=t.timeStamp)}computeValues(t){const e=this.state;e._values=t,e.values=this.config.transform(t)}computeInitial(){const t=this.state;t._initial=t._values,t.initial=t.values}compute(t){const{state:e,config:i,shared:s}=this;e.args=this.args;let r=0;if(t&&(e.event=t,i.preventDefault&&t.cancelable&&e.event.preventDefault(),e.type=t.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,function(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:i,altKey:s,metaKey:r,ctrlKey:n}=t;Object.assign(e,{shiftKey:i,altKey:s,metaKey:r,ctrlKey:n})}return e}(t)),s.down=s.pressed=s.buttons%2==1||s.touches>0,r=t.timeStamp-e.timeStamp,e.timeStamp=t.timeStamp,e.elapsedTime=e.timeStamp-e.startTime),e._active){const t=e._delta.map(Math.abs);kc.addTo(e._distance,t)}this.axisIntent&&this.axisIntent(t);const[n,o]=e._movement,[a,c]=i.threshold,{_step:h,values:l}=e;if(i.hasCustomTransform?(!1===h[0]&&(h[0]=Math.abs(n)>=a&&l[0]),!1===h[1]&&(h[1]=Math.abs(o)>=c&&l[1])):(!1===h[0]&&(h[0]=Math.abs(n)>=a&&Math.sign(n)*a),!1===h[1]&&(h[1]=Math.abs(o)>=c&&Math.sign(o)*c)),e.intentional=!1!==h[0]||!1!==h[1],!e.intentional)return;const u=[0,0];if(i.hasCustomTransform){const[t,e]=l;u[0]=!1!==h[0]?t-h[0]:0,u[1]=!1!==h[1]?e-h[1]:0}else u[0]=!1!==h[0]?n-h[0]:0,u[1]=!1!==h[1]?o-h[1]:0;this.restrictToAxis&&!e._blocked&&this.restrictToAxis(u);const d=e.offset,g=e._active&&!e._blocked||e.active;g&&(e.first=e._active&&!e.active,e.last=!e._active&&e.active,e.active=s[this.ingKey]=e._active,t&&(e.first&&("bounds"in i&&(e._bounds=Kc(i.bounds,e)),this.setup&&this.setup()),e.movement=u,this.computeOffset()));const[f,p]=e.offset,[[m,v],[y,_]]=e._bounds;e.overflow=[f<m?-1:f>v?1:0,p<y?-1:p>_?1:0],e._movementBound[0]=!!e.overflow[0]&&(!1===e._movementBound[0]?e._movement[0]:e._movementBound[0]),e._movementBound[1]=!!e.overflow[1]&&(!1===e._movementBound[1]?e._movement[1]:e._movementBound[1]);const x=e._active&&i.rubberband||[0,0];if(e.offset=function(t,[e,i],[s,r]){const[[n,o],[a,c]]=t;return[Mc(e,n,o,s),Mc(i,a,c,r)]}(e._bounds,e.offset,x),e.delta=kc.sub(e.offset,d),this.computeMovement(),g&&(!e.last||r>32)){e.delta=kc.sub(e.offset,d);const t=e.delta.map(Math.abs);kc.addTo(e.distance,t),e.direction=e.delta.map(Math.sign),e._direction=e._delta.map(Math.sign),!e.first&&r>0&&(e.velocity=[t[0]/r,t[1]/r],e.timeDelta=r)}}emit(){const t=this.state,e=this.shared,i=this.config;if(t._active||this.clean(),(t._blocked||!t.intentional)&&!t._force&&!i.triggerAllEvents)return;const s=this.handler(Ac(Ac(Ac({},e),t),{},{[this.aliasKey]:t.values}));void 0!==s&&(t.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}class th extends $c{constructor(...t){super(...t),Pc(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=kc.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=kc.sub(this.state.offset,this.state.lastOffset)}axisIntent(t){const e=this.state,i=this.config;if(!e.axis&&t){const s="object"==typeof i.axisThreshold?i.axisThreshold[Yc(t)]:i.axisThreshold;e.axis=function([t,e],i){const s=Math.abs(t),r=Math.abs(e);return s>r&&s>i?"x":r>s&&r>i?"y":void 0}(e._movement,s)}e._blocked=(i.lockDirection||!!i.axis)&&!e.axis||!!i.axis&&i.axis!==e.axis}restrictToAxis(t){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":t[1]=0;break;case"y":t[0]=0}}}const eh=t=>t,ih={enabled:(t=!0)=>t,eventOptions:(t,e,i)=>Ac(Ac({},i.shared.eventOptions),t),preventDefault:(t=!1)=>t,triggerAllEvents:(t=!1)=>t,rubberband(t=0){switch(t){case!0:return[.15,.15];case!1:return[0,0];default:return kc.toVector(t)}},from:t=>"function"==typeof t?t:null!=t?kc.toVector(t):void 0,transform(t,e,i){const s=t||i.shared.transform;if(this.hasCustomTransform=!!s,"development"===process.env.NODE_ENV){const t=s||eh;return e=>{const i=t(e);return isFinite(i[0])&&isFinite(i[1])||console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${i[0]},${[1]}]`),i}}return s||eh},threshold:t=>kc.toVector(t,0)};"development"===process.env.NODE_ENV&&Object.assign(ih,{domTarget(t){if(void 0!==t)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(t){if(void 0!==t)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(t){if(void 0!==t)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const sh=Ac(Ac({},ih),{},{axis(t,e,{axis:i}){if(this.lockDirection="lock"===i,!this.lockDirection)return i},axisThreshold:(t=0)=>t,bounds(t={}){if("function"==typeof t)return e=>sh.bounds(t(e));if("current"in t)return()=>t.current;if("function"==typeof HTMLElement&&t instanceof HTMLElement)return t;const{left:e=-1/0,right:i=1/0,top:s=-1/0,bottom:r=1/0}=t;return[[e,i],[s,r]]}}),rh={ArrowRight:(t,e=1)=>[t*e,0],ArrowLeft:(t,e=1)=>[-1*t*e,0],ArrowUp:(t,e=1)=>[0,-1*t*e],ArrowDown:(t,e=1)=>[0,t*e]};const nh="undefined"!=typeof window&&window.document&&window.document.createElement;function oh(){return nh&&"ontouchstart"in window}const ah={isBrowser:nh,gesture:function(){try{return"constructor"in GestureEvent}catch(t){return!1}}(),touch:oh(),touchscreen:oh()||nh&&window.navigator.maxTouchPoints>1,pointer:nh&&"onpointerdown"in window,pointerLock:nh&&"exitPointerLock"in window.document},ch={mouse:0,touch:0,pen:8},hh=Ac(Ac({},sh),{},{device(t,e,{pointer:{touch:i=!1,lock:s=!1,mouse:r=!1}={}}){return this.pointerLock=s&&ah.pointerLock,ah.touch&&i?"touch":this.pointerLock?"mouse":ah.pointer&&!r?"pointer":ah.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:i}){if(this.preventScrollDelay="number"==typeof i?i:i||void 0===i&&t?250:void 0,ah.touchscreen&&!1!==i)return t||(void 0!==i?"y":void 0)},pointerCapture(t,e,{pointer:{capture:i=!0,buttons:s=1,keys:r=!0}={}}){return this.pointerButtons=s,this.keys=r,!this.pointerLock&&"pointer"===this.device&&i},threshold(t,e,{filterTaps:i=!1,tapsThreshold:s=3,axis:r}){const n=kc.toVector(t,i?s:r?1:0);return this.filterTaps=i,this.tapsThreshold=s,n},swipe({velocity:t=.5,distance:e=50,duration:i=250}={}){return{velocity:this.transform(kc.toVector(t)),distance:this.transform(kc.toVector(e)),duration:i}},delay(t=0){switch(t){case!0:return 180;case!1:return 0;default:return t}},axisThreshold:t=>t?Ac(Ac({},ch),t):ch,keyboardDisplacement:(t=10)=>t});"development"===process.env.NODE_ENV&&Object.assign(hh,{useTouch(t){if(void 0!==t)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(t){if(void 0!==t)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(t){if(void 0!==t)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(t){if(void 0!==t)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(t){if(void 0!==t)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}});const lh=Ac(Ac({},ih),{},{device(t,e,{shared:i,pointer:{touch:s=!1}={}}){if(i.target&&!ah.touch&&ah.gesture)return"gesture";if(ah.touch&&s)return"touch";if(ah.touchscreen){if(ah.pointer)return"pointer";if(ah.touch)return"touch"}},bounds(t,e,{scaleBounds:i={},angleBounds:s={}}){const r=t=>{const e=Zc(Kc(i,t),{min:-1/0,max:1/0});return[e.min,e.max]},n=t=>{const e=Zc(Kc(s,t),{min:-1/0,max:1/0});return[e.min,e.max]};return"function"!=typeof i&&"function"!=typeof s?[r(),n()]:t=>[r(t),n(t)]},threshold(t,e,i){this.lockDirection="lock"===i.axis;return kc.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey:t=>void 0===t?"ctrlKey":t,pinchOnWheel:(t=!0)=>t});Ac(Ac({},sh),{},{mouseOnly:(t=!0)=>t}),Ac(Ac({},sh),{},{mouseOnly:(t=!0)=>t});const uh=new Map,dh=new Map;function gh(t){uh.set(t.key,t.engine),dh.set(t.key,t.resolver)}const fh={key:"drag",engine:class extends th{constructor(...t){super(...t),Pc(this,"ingKey","dragging")}reset(){super.reset();const t=this.state;t._pointerId=void 0,t._pointerActive=!1,t._keyboardActive=!1,t._preventScroll=!1,t._delayed=!1,t.swipe=[0,0],t.tap=!1,t.canceled=!1,t.cancel=this.cancel.bind(this)}setup(){const t=this.state;if(t._bounds instanceof HTMLElement){const e=t._bounds.getBoundingClientRect(),i=t.currentTarget.getBoundingClientRect(),s={left:e.left-i.left+t.offset[0],right:e.right-i.right+t.offset[0],top:e.top-i.top+t.offset[1],bottom:e.bottom-i.bottom+t.offset[1]};t._bounds=sh.bounds(s)}}cancel(){const t=this.state;t.canceled||(t.canceled=!0,t._active=!1,setTimeout((()=>{this.compute(),this.emit()}),0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(t){const e=this.config,i=this.state;if(null!=t.buttons&&(Array.isArray(e.pointerButtons)?!e.pointerButtons.includes(t.buttons):-1!==e.pointerButtons&&e.pointerButtons!==t.buttons))return;const s=this.ctrl.setEventIds(t);e.pointerCapture&&t.target.setPointerCapture(t.pointerId),s&&s.size>1&&i._pointerActive||(this.start(t),this.setupPointer(t),i._pointerId=Nc(t),i._pointerActive=!0,this.computeValues(Uc(t)),this.computeInitial(),e.preventScrollAxis&&"mouse"!==Yc(t)?(i._active=!1,this.setupScrollPrevention(t)):e.delay>0?(this.setupDelayTrigger(t),e.triggerAllEvents&&(this.compute(t),this.emit())):this.startPointerDrag(t))}startPointerDrag(t){const e=this.state;e._active=!0,e._preventScroll=!0,e._delayed=!1,this.compute(t),this.emit()}pointerMove(t){const e=this.state,i=this.config;if(!e._pointerActive)return;const s=Nc(t);if(void 0!==e._pointerId&&s!==e._pointerId)return;const r=Uc(t);return document.pointerLockElement===t.target?e._delta=[t.movementX,t.movementY]:(e._delta=kc.sub(r,e._values),this.computeValues(r)),kc.addTo(e._movement,e._delta),this.compute(t),e._delayed&&e.intentional?(this.timeoutStore.remove("dragDelay"),e.active=!1,void this.startPointerDrag(t)):i.preventScrollAxis&&!e._preventScroll?e.axis?e.axis===i.preventScrollAxis||"xy"===i.preventScrollAxis?(e._active=!1,void this.clean()):(this.timeoutStore.remove("startPointerDrag"),void this.startPointerDrag(t)):void 0:void this.emit()}pointerUp(t){this.ctrl.setEventIds(t);try{this.config.pointerCapture&&t.target.hasPointerCapture(t.pointerId)&&t.target.releasePointerCapture(t.pointerId)}catch(t){"development"===process.env.NODE_ENV&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const e=this.state,i=this.config;if(!e._active||!e._pointerActive)return;const s=Nc(t);if(void 0!==e._pointerId&&s!==e._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(t);const[r,n]=e._distance;if(e.tap=r<=i.tapsThreshold&&n<=i.tapsThreshold,e.tap&&i.filterTaps)e._force=!0;else{const[t,s]=e._delta,[r,n]=e._movement,[o,a]=i.swipe.velocity,[c,h]=i.swipe.distance,l=i.swipe.duration;if(e.elapsedTime<l){const i=Math.abs(t/e.timeDelta),l=Math.abs(s/e.timeDelta);i>o&&Math.abs(r)>c&&(e.swipe[0]=Math.sign(t)),l>a&&Math.abs(n)>h&&(e.swipe[1]=Math.sign(s))}}this.emit()}pointerClick(t){!this.state.tap&&t.detail>0&&(t.preventDefault(),t.stopPropagation())}setupPointer(t){const e=this.config,i=e.device;if("development"===process.env.NODE_ENV)try{if("pointer"===i&&void 0===e.preventScrollDelay){const e="uv"in t?t.sourceEvent.currentTarget:t.currentTarget;"auto"===window.getComputedStyle(e).touchAction&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",e)}}catch(t){}e.pointerLock&&t.currentTarget.requestPointerLock(),e.pointerCapture||(this.eventStore.add(this.sharedConfig.window,i,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,i,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,i,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(t){this.state._preventScroll&&t.cancelable&&t.preventDefault()}setupScrollPrevention(t){this.state._preventScroll=!1,function(t){"persist"in t&&"function"==typeof t.persist&&t.persist()}(t);const e=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",e),this.eventStore.add(this.sharedConfig.window,"touch","cancel",e),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,t)}setupDelayTrigger(t){this.state._delayed=!0,this.timeoutStore.add("dragDelay",(()=>{this.state._step=[0,0],this.startPointerDrag(t)}),this.config.delay)}keyDown(t){const e=rh[t.key];if(e){const i=this.state,s=t.shiftKey?10:t.altKey?.1:1;this.start(t),i._delta=e(this.config.keyboardDisplacement,s),i._keyboardActive=!0,kc.addTo(i._movement,i._delta),this.compute(t),this.emit()}}keyUp(t){t.key in rh&&(this.state._keyboardActive=!1,this.setActive(),this.compute(t),this.emit())}bind(t){const e=this.config.device;t(e,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(t(e,"change",this.pointerMove.bind(this)),t(e,"end",this.pointerUp.bind(this)),t(e,"cancel",this.pointerUp.bind(this)),t("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(t("key","down",this.keyDown.bind(this)),t("key","up",this.keyUp.bind(this))),this.config.filterTaps&&t("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}},resolver:hh},ph={key:"pinch",engine:class extends $c{constructor(...t){super(...t),Pc(this,"ingKey","pinching"),Pc(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const t=this.state;t._touchIds=[],t.canceled=!1,t.cancel=this.cancel.bind(this),t.turns=0}computeOffset(){const{type:t,movement:e,lastOffset:i}=this.state;this.state.offset="wheel"===t?kc.add(e,i):[(1+e[0])*i[0],e[1]+i[1]]}computeMovement(){const{offset:t,lastOffset:e}=this.state;this.state.movement=[t[0]/e[0],t[1]-e[1]]}axisIntent(){const t=this.state,[e,i]=t._movement;if(!t.axis){const s=30*Math.abs(e)-Math.abs(i);s<0?t.axis="angle":s>0&&(t.axis="scale")}}restrictToAxis(t){this.config.lockDirection&&("scale"===this.state.axis?t[1]=0:"angle"===this.state.axis&&(t[0]=0))}cancel(){const t=this.state;t.canceled||setTimeout((()=>{t.canceled=!0,t._active=!1,this.compute(),this.emit()}),0)}touchStart(t){this.ctrl.setEventIds(t);const e=this.state,i=this.ctrl.touchIds;if(e._active&&e._touchIds.every((t=>i.has(t))))return;if(i.size<2)return;this.start(t),e._touchIds=Array.from(i).slice(0,2);const s=Gc(t,e._touchIds);s&&this.pinchStart(t,s)}pointerStart(t){if(null!=t.buttons&&t.buttons%2!=1)return;this.ctrl.setEventIds(t),t.target.setPointerCapture(t.pointerId);const e=this.state,i=e._pointerEvents,s=this.ctrl.pointerIds;if(e._active&&Array.from(i.keys()).every((t=>s.has(t))))return;if(i.size<2&&i.set(t.pointerId,t),e._pointerEvents.size<2)return;this.start(t);const r=Hc(...Array.from(i.values()));r&&this.pinchStart(t,r)}pinchStart(t,e){this.state.origin=e.origin,this.computeValues([e.distance,e.angle]),this.computeInitial(),this.compute(t),this.emit()}touchMove(t){if(!this.state._active)return;const e=Gc(t,this.state._touchIds);e&&this.pinchMove(t,e)}pointerMove(t){const e=this.state._pointerEvents;if(e.has(t.pointerId)&&e.set(t.pointerId,t),!this.state._active)return;const i=Hc(...Array.from(e.values()));i&&this.pinchMove(t,i)}pinchMove(t,e){const i=this.state,s=i._values[1],r=e.angle-s;let n=0;Math.abs(r)>270&&(n+=Math.sign(r)),this.computeValues([e.distance,e.angle-360*n]),i.origin=e.origin,i.turns=n,i._movement=[i._values[0]/i._initial[0]-1,i._values[1]-i._initial[1]],this.compute(t),this.emit()}touchEnd(t){this.ctrl.setEventIds(t),this.state._active&&this.state._touchIds.some((t=>!this.ctrl.touchIds.has(t)))&&(this.state._active=!1,this.compute(t),this.emit())}pointerEnd(t){const e=this.state;this.ctrl.setEventIds(t);try{t.target.releasePointerCapture(t.pointerId)}catch(t){}e._pointerEvents.has(t.pointerId)&&e._pointerEvents.delete(t.pointerId),e._active&&e._pointerEvents.size<2&&(e._active=!1,this.compute(t),this.emit())}gestureStart(t){t.cancelable&&t.preventDefault();const e=this.state;e._active||(this.start(t),this.computeValues([t.scale,t.rotation]),e.origin=[t.clientX,t.clientY],this.compute(t),this.emit())}gestureMove(t){if(t.cancelable&&t.preventDefault(),!this.state._active)return;const e=this.state;this.computeValues([t.scale,t.rotation]),e.origin=[t.clientX,t.clientY];const i=e._movement;e._movement=[t.scale-1,t.rotation],e._delta=kc.sub(e._movement,i),this.compute(t),this.emit()}gestureEnd(t){this.state._active&&(this.state._active=!1,this.compute(t),this.emit())}wheel(t){const e=this.config.modifierKey;e&&!(Array.isArray(e)?e.find((e=>t[e])):t[e])||(this.state._active?this.wheelChange(t):this.wheelStart(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(t){this.start(t),this.wheelChange(t)}wheelChange(t){"uv"in t||(t.cancelable&&t.preventDefault(),"development"!==process.env.NODE_ENV||t.defaultPrevented||console.warn("[@use-gesture]: To properly support zoom on trackpads, try using the `target` option.\n\nThis message will only appear in development mode."));const e=this.state;e._delta=[-qc(t)[1]/100*e.offset[0],0],kc.addTo(e._movement,e._delta),function(t){const[e,i]=t.overflow,[s,r]=t._delta,[n,o]=t._direction;(e<0&&s>0&&n<0||e>0&&s<0&&n>0)&&(t._movement[0]=t._movementBound[0]),(i<0&&r>0&&o<0||i>0&&r<0&&o>0)&&(t._movement[1]=t._movementBound[1])}(e),this.state.origin=[t.clientX,t.clientY],this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){const e=this.config.device;e&&(t(e,"start",this[e+"Start"].bind(this)),t(e,"change",this[e+"Move"].bind(this)),t(e,"end",this[e+"End"].bind(this)),t(e,"cancel",this[e+"End"].bind(this)),t("lostPointerCapture","",this[e+"End"].bind(this))),this.config.pinchOnWheel&&t("wheel","",this.wheel.bind(this),{passive:!1})}},resolver:lh};function mh(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}const vh={target(t){if(t)return()=>"current"in t?t.current:t},enabled:(t=!0)=>t,window:(t=(ah.isBrowser?window:void 0))=>t,eventOptions:({passive:t=!0,capture:e=!1}={})=>({passive:t,capture:e}),transform:t=>t},yh=["target","eventOptions","window","enabled","transform"];function _h(t={},e){const i={};for(const[s,r]of Object.entries(e))switch(typeof r){case"function":if("development"===process.env.NODE_ENV){const e=r.call(i,t[s],s,t);Number.isNaN(e)||(i[s]=e)}else i[s]=r.call(i,t[s],s,t);break;case"object":i[s]=_h(t[s],r);break;case"boolean":r&&(i[s]=t[s])}return i}class xh{constructor(t,e){Pc(this,"_listeners",new Set),this._ctrl=t,this._gestureKey=e}add(t,e,i,s,r){const n=this._listeners,o=function(t,e=""){const i=Fc[t];return t+(i&&i[e]||e)}(e,i),a=Ac(Ac({},this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{}),r);t.addEventListener(o,s,a);const c=()=>{t.removeEventListener(o,s,a),n.delete(c)};return n.add(c),c}clean(){this._listeners.forEach((t=>t())),this._listeners.clear()}}class bh{constructor(){Pc(this,"_timeouts",new Map)}add(t,e,i=140,...s){this.remove(t),this._timeouts.set(t,window.setTimeout(e,i,...s))}remove(t){const e=this._timeouts.get(t);e&&window.clearTimeout(e)}clean(){this._timeouts.forEach((t=>{window.clearTimeout(t)})),this._timeouts.clear()}}class wh{constructor(t){Pc(this,"gestures",new Set),Pc(this,"_targetEventStore",new xh(this)),Pc(this,"gestureEventStores",{}),Pc(this,"gestureTimeoutStores",{}),Pc(this,"handlers",{}),Pc(this,"config",{}),Pc(this,"pointerIds",new Set),Pc(this,"touchIds",new Set),Pc(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),function(t,e){e.drag&&Sh(t,"drag");e.wheel&&Sh(t,"wheel");e.scroll&&Sh(t,"scroll");e.move&&Sh(t,"move");e.pinch&&Sh(t,"pinch");e.hover&&Sh(t,"hover")}(this,t)}setEventIds(t){return Vc(t)?(this.touchIds=new Set(zc(t)),this.touchIds):"pointerId"in t?("pointerup"===t.type||"pointercancel"===t.type?this.pointerIds.delete(t.pointerId):"pointerdown"===t.type&&this.pointerIds.add(t.pointerId),this.pointerIds):void 0}applyHandlers(t,e){this.handlers=t,this.nativeHandlers=e}applyConfig(t,e){this.config=function(t,e,i={}){const s=t,{target:r,eventOptions:n,window:o,enabled:a,transform:c}=s,h=mh(s,yh);if(i.shared=_h({target:r,eventOptions:n,window:o,enabled:a,transform:c},vh),e){const t=dh.get(e);i[e]=_h(Ac({shared:i.shared},h),t)}else for(const t in h){const e=dh.get(t);if(e)i[t]=_h(Ac({shared:i.shared},h[t]),e);else if("development"===process.env.NODE_ENV&&!["drag","pinch","scroll","wheel","move","hover"].includes(t)){if("domTarget"===t)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${t}\` was used. Please read the documentation for further information.`)}}return i}(t,e,this.config)}clean(){this._targetEventStore.clean();for(const t of this.gestures)this.gestureEventStores[t].clean(),this.gestureTimeoutStores[t].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...t){const e=this.config.shared,i={};let s;if(!e.target||(s=e.target(),s)){if(e.enabled){for(const e of this.gestures){const r=this.config[e],n=Ch(i,r.eventOptions,!!s);if(r.enabled){new(uh.get(e))(this,t,e).bind(n)}}const r=Ch(i,e.eventOptions,!!s);for(const e in this.nativeHandlers)r(e,"",(i=>this.nativeHandlers[e](Ac(Ac({},this.state.shared),{},{event:i,args:t}))),void 0,!0)}for(const t in i)i[t]=Qc(...i[t]);if(!s)return i;for(const t in i){const{device:e,capture:r,passive:n}=Xc(t);this._targetEventStore.add(s,e,"",i[t],{capture:r,passive:n})}}}}function Sh(t,e){t.gestures.add(e),t.gestureEventStores[e]=new xh(t,e),t.gestureTimeoutStores[e]=new bh}const Ch=(t,e,i)=>(s,r,n,o={},a=!1)=>{var c,h;const l=null!==(c=o.capture)&&void 0!==c?c:e.capture,u=null!==(h=o.passive)&&void 0!==h?h:e.passive;let d=a?s:Rc(s,r,l);i&&u&&(d+="Passive"),t[d]=t[d]||[],t[d].push(n)};function Th(t,i={},s,r){const n=e.useMemo((()=>new wh(t)),[]);if(n.applyHandlers(t,r),n.applyConfig(i,s),e.useEffect(n.effect.bind(n)),e.useEffect((()=>n.clean.bind(n)),[]),void 0===i.target)return n.bind.bind(n)}const Oh=h.div`
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import e,{forwardRef as i,useRef as s,useImperativeHandle as r,useEffect as n}from"react";import{m as o,d as a,T as c}from"./index.cb4c93a5.js";import h from"styled-components";import"@lifesg/react-design-system/theme";import"@lifesg/react-design-system/typography";import"@lifesg/react-design-system/button";import"@lifesg/react-design-system/modal";import"@lifesg/react-design-system/markup";import"react-dom/server";import"@lifesg/react-design-system/alert";import"@lifesg/react-design-system/layout";import"@lifesg/react-design-system/box-container";import"@lifesg/react-design-system/divider";import"@lifesg/react-design-system/v2_media";import"@lifesg/react-design-system/text-list";import"@lifesg/react-design-system/popover-v2";import"@lifesg/react-icons";import"@lifesg/react-design-system/tab";import"@lifesg/react-icons/plus-circle-fill";import"@lifesg/react-design-system/button-with-icon";import"@lifesg/react-design-system/error-display";import"@lifesg/react-design-system/filter";import"@lifesg/react-design-system/uneditable-section";import"@lifesg/react-design-system/timeline";import"@lifesg/react-design-system/form";import"@lifesg/react-design-system/checkbox";import"@lifesg/react-design-system/toggle";import"@lifesg/react-design-system/file-upload";import"@lifesg/react-icons/cross";import"@lifesg/react-design-system/icon-button";import"@lifesg/react-icons/bin";import"@lifesg/react-icons/eraser";import"@lifesg/react-icons/pencil";import"@lifesg/react-icons/pencil-stroke";import"@lifesg/react-icons/plus";import"@lifesg/react-icons/exclamation-triangle";import"@lifesg/react-icons/pin-fill";import"@lifesg/react-design-system/image-button";import"@lifesg/react-design-system/radio-button";import"@lifesg/react-design-system/v2_layout";function l(t,e,i){return e=S(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return T(t)}(t,u()?Reflect.construct(e,i||[],S(t).constructor):e.apply(t,i))}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function d(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 g(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?d(Object(i),!0).forEach((function(e){b(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):d(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function f(){f=function(){return e};var t,e={},i=Object.prototype,s=i.hasOwnProperty,r=Object.defineProperty||function(t,e,i){t[e]=i.value},n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";function h(t,e,i){return Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch(t){h=function(t,e,i){return t[e]=i}}function l(t,e,i,s){var n=e&&e.prototype instanceof y?e:y,o=Object.create(n.prototype),a=new P(s||[]);return r(o,"_invoke",{value:k(t,i,a)}),o}function u(t,e,i){try{return{type:"normal",arg:t.call(e,i)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var d="suspendedStart",g="suspendedYield",p="executing",m="completed",v={};function y(){}function _(){}function x(){}var b={};h(b,o,(function(){return this}));var w=Object.getPrototypeOf,S=w&&w(w(j([])));S&&S!==i&&s.call(S,o)&&(b=S);var C=x.prototype=y.prototype=Object.create(b);function T(t){["next","throw","return"].forEach((function(e){h(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(r,n,o,a){var c=u(t[r],t,n);if("throw"!==c.type){var h=c.arg,l=h.value;return l&&"object"==typeof l&&s.call(l,"__await")?e.resolve(l.__await).then((function(t){i("next",t,o,a)}),(function(t){i("throw",t,o,a)})):e.resolve(l).then((function(t){h.value=t,o(h)}),(function(t){return i("throw",t,o,a)}))}a(c.arg)}var n;r(this,"_invoke",{value:function(t,s){function r(){return new e((function(e,r){i(t,s,e,r)}))}return n=n?n.then(r,r):r()}})}function k(e,i,s){var r=d;return function(n,o){if(r===p)throw new Error("Generator is already running");if(r===m){if("throw"===n)throw o;return{value:t,done:!0}}for(s.method=n,s.arg=o;;){var a=s.delegate;if(a){var c=D(a,s);if(c){if(c===v)continue;return c}}if("next"===s.method)s.sent=s._sent=s.arg;else if("throw"===s.method){if(r===d)throw r=m,s.arg;s.dispatchException(s.arg)}else"return"===s.method&&s.abrupt("return",s.arg);r=p;var h=u(e,i,s);if("normal"===h.type){if(r=s.done?m:g,h.arg===v)continue;return{value:h.arg,done:s.done}}"throw"===h.type&&(r=m,s.method="throw",s.arg=h.arg)}}}function D(e,i){var s=i.method,r=e.iterator[s];if(r===t)return i.delegate=null,"throw"===s&&e.iterator.return&&(i.method="return",i.arg=t,D(e,i),"throw"===i.method)||"return"!==s&&(i.method="throw",i.arg=new TypeError("The iterator does not provide a '"+s+"' method")),v;var n=u(r,e.iterator,i.arg);if("throw"===n.type)return i.method="throw",i.arg=n.arg,i.delegate=null,v;var o=n.arg;return o?o.done?(i[e.resultName]=o.value,i.next=e.nextLoc,"return"!==i.method&&(i.method="next",i.arg=t),i.delegate=null,v):o:(i.method="throw",i.arg=new TypeError("iterator result is not an object"),i.delegate=null,v)}function M(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(M,this),this.reset(!0)}function j(e){if(e||""===e){var i=e[o];if(i)return i.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function i(){for(;++r<e.length;)if(s.call(e,r))return i.value=e[r],i.done=!1,i;return i.value=t,i.done=!0,i};return n.next=n}}throw new TypeError(typeof e+" is not iterable")}return _.prototype=x,r(C,"constructor",{value:x,configurable:!0}),r(x,"constructor",{value:_,configurable:!0}),_.displayName=h(x,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,h(t,c,"GeneratorFunction")),t.prototype=Object.create(C),t},e.awrap=function(t){return{__await:t}},T(O.prototype),h(O.prototype,a,(function(){return this})),e.AsyncIterator=O,e.async=function(t,i,s,r,n){void 0===n&&(n=Promise);var o=new O(l(t,i,s,r),n);return e.isGeneratorFunction(i)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},T(C),h(C,c,"Generator"),h(C,o,(function(){return this})),h(C,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),i=[];for(var s in e)i.push(s);return i.reverse(),function t(){for(;i.length;){var s=i.pop();if(s in e)return t.value=s,t.done=!1,t}return t.done=!0,t}},e.values=j,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(E),!e)for(var i in this)"t"===i.charAt(0)&&s.call(this,i)&&!isNaN(+i.slice(1))&&(this[i]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var i=this;function r(s,r){return a.type="throw",a.arg=e,i.next=s,r&&(i.method="next",i.arg=t),!!r}for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),h=s.call(o,"finallyLoc");if(c&&h){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!h)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var i=this.tryEntries.length-1;i>=0;--i){var r=this.tryEntries[i];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var n=r;break}}n&&("break"===t||"continue"===t)&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var o=n?n.completion:{};return o.type=t,o.arg=e,n?(this.method="next",this.next=n.finallyLoc,v):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.finallyLoc===t)return this.complete(i.completion,i.afterLoc),E(i),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.tryLoc===t){var s=i.completion;if("throw"===s.type){var r=s.arg;E(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,i,s){return this.delegate={iterator:j(e),resultName:i,nextLoc:s},"next"===this.method&&(this.arg=t),v}},e}function p(t){var e=function(t,e){if("object"!=typeof t||!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)}function m(t,e,i,s,r,n,o){try{var a=t[n](o),c=a.value}catch(t){return void i(t)}a.done?e(c):Promise.resolve(c).then(s,r)}function v(t){return function(){var e=this,i=arguments;return new Promise((function(s,r){var n=t.apply(e,i);function o(t){m(n,s,r,o,a,"next",t)}function a(t){m(n,s,r,o,a,"throw",t)}o(void 0)}))}}function y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,p(s.key),s)}}function x(t,e,i){return e&&_(t.prototype,e),i&&_(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function b(t,e,i){return(e=p(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function w(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&C(t,e)}function S(t){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},S(t)}function C(t,e){return C=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},C(t,e)}function T(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function O(){return O="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var s=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=S(t)););return t}(t,e);if(s){var r=Object.getOwnPropertyDescriptor(s,e);return r.get?r.get.call(arguments.length<3?t:i):r.value}},O.apply(this,arguments)}function k(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var i=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=i){var s,r,n,o,a=[],c=!0,h=!1;try{if(n=(i=i.call(t)).next,0===e){if(Object(i)!==i)return;c=!1}else for(;!(c=(s=n.call(i)).done)&&(a.push(s.value),a.length!==e);c=!0);}catch(t){h=!0,r=t}finally{try{if(!c&&null!=i.return&&(o=i.return(),Object(o)!==o))return}finally{if(h)throw r}}return a}}(t,e)||M(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(t){return function(t){if(Array.isArray(t))return E(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||M(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(t,e){if(t){if("string"==typeof t)return E(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?E(t,e):void 0}}function E(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,s=new Array(e);i<e;i++)s[i]=t[i];return s}function P(t,e,i){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function j(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 A(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?j(Object(i),!0).forEach((function(e){P(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):j(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function F(t,e){if(null==t)return{};var i,s,r=function(t,e){if(null==t)return{};var i={};for(var s in t)if({}.hasOwnProperty.call(t,s)){if(e.indexOf(s)>=0)continue;i[s]=t[s]}return i}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(s=0;s<n.length;s++)i=n[s],e.indexOf(i)>=0||{}.propertyIsEnumerable.call(t,i)&&(r[i]=t[i])}return r}function L(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}class I{constructor(){P(this,"browserShadowBlurConstant",1),P(this,"DPI",96),P(this,"devicePixelRatio","undefined"!=typeof window?window.devicePixelRatio:1),P(this,"perfLimitSizeTotal",2097152),P(this,"maxCacheSideLimit",4096),P(this,"minCacheSideLimit",256),P(this,"disableStyleCopyPaste",!1),P(this,"enableGLFiltering",!0),P(this,"textureSize",4096),P(this,"forceGLPutImageData",!1),P(this,"cachesBoundsOfCurve",!1),P(this,"fontPaths",{}),P(this,"NUM_FRACTION_DIGITS",4)}}const R=new class extends I{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=A(A({},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 I,i=(null==t?void 0:t.reduce(((t,i)=>(t[i]=e[i],t)),{}))||e;this.configure(i)}},B=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 X extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class V extends X{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Y{}class W extends Y{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))),e.getExtension("WEBGL_lose_context").loseContext(),B("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const H={};let z;const G=()=>z||(z={document:document,window:window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new W,dispose(){},copyPasteData:H}),N=()=>G().document,U=()=>G().window,q=()=>{var t;return Math.max(null!==(t=R.devicePixelRatio)&&void 0!==t?t:U().devicePixelRatio,1)},K=new class{constructor(){P(this,"charWidthsCache",{}),P(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}=R,i=Math.sqrt(e*t);return[Math.floor(i),Math.floor(e/i)]}},J="6.7.1";function Q(){}const Z=Math.PI/2,$=2*Math.PI,tt=Math.PI/180,et=Object.freeze([1,0,0,1,0,0]),it=16,st=.4477152502,rt="center",nt="left",ot="top",at="bottom",ct="right",ht="none",lt=/\r?\n/,ut="moving",dt="scaling",gt="rotating",ft="rotate",pt="skewing",mt="resizing",vt="modifyPoly",yt="modifyPath",_t="changed",xt="scale",bt="scaleX",wt="scaleY",St="skewX",Ct="skewY",Tt="fill",Ot="stroke",kt="modified",Dt="json",Mt="svg",Et=new class{constructor(){this[Dt]=new Map,this[Mt]=new Map}has(t){return this[Dt].has(t)}getClass(t){const e=this[Dt].get(t);if(!e)throw new X("No class registered for ".concat(t));return e}setClass(t,e){e?this[Dt].set(e,t):(this[Dt].set(t.type,t),this[Dt].set(t.type.toLowerCase(),t))}getSVGClass(t){return this[Mt].get(t)}setSVGClass(t,e){this[Mt].set(null!=e?e:t.type.toLowerCase(),t)}},Pt=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 jt{constructor(){P(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 At=(t,e)=>{const i=t.indexOf(e);return-1!==i&&t.splice(i,1),t},Ft=t=>{if(0===t)return 1;switch(Math.abs(t)/Z){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},Lt=t=>{if(0===t)return 0;const e=t/Z,i=Math.sign(t);switch(e){case 1:return i;case 2:return 0;case 3:return-i}return Math.sin(t)};class It{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 It(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new It(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new It(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new It(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new It(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new It(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new It(this.x/t.x,this.y/t.y)}scalarDivide(t){return new It(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 It(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 It(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new It(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 It(this.x,this.y)}rotate(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Rt;const i=Lt(t),s=Ft(t),r=this.subtract(e);return new It(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 It(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 Rt=new It(0,0),Bt=t=>!!t&&Array.isArray(t._objects);function Xt(t){class e extends t{constructor(){super(...arguments),P(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]||(At(this._objects,t),this._objects.unshift(t),this._onStackOrderChanged(t),0))}bringObjectToFront(t){return!(!t||t===this._objects[this._objects.length-1]||(At(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 At(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 At(this._objects,t),this._objects.splice(s,0,t),this._onStackOrderChanged(t),!0}return!1}moveObjectTo(t,e){return t!==this._objects[e]&&(At(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 It(e,i),c=a.add(new It(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,c)||e.isContainedWithinRect(a,c)||n&&e.containsPoint(a)||n&&e.containsPoint(c))&&o.push(e)}return o}}return e}class Vt extends jt{_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 Yt(t){return U().requestAnimationFrame(t)}function Wt(t){return U().cancelAnimationFrame(t)}let Ht=0;const zt=()=>Ht++,Gt=()=>{const t=N().createElement("canvas");if(!t||void 0===t.getContext)throw new X("Failed to create `canvas` element");return t},Nt=()=>N().createElement("img"),Ut=t=>{const e=Gt();return e.width=t.width,e.height=t.height,e},qt=(t,e,i)=>t.toDataURL("image/".concat(e),i),Kt=(t,e,i)=>new Promise(((s,r)=>{t.toBlob(s,"image/".concat(e),i)})),Jt=t=>t*tt,Qt=t=>t/tt,Zt=t=>t.every(((t,e)=>t===et[e])),$t=(t,e,i)=>new It(t).transform(e,i),te=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 It(t[4],t[5]).transform(i,!0);return i[4]=-s,i[5]=-r,i},ee=(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]],ie=(t,e)=>t.reduceRight(((t,i)=>i&&t?ee(i,t,e):i||t),void 0)||et.concat(),se=t=>{let[e,i]=t;return Math.atan2(i,e)},re=t=>{const e=se(t),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:Qt(e),scaleX:s,scaleY:r,skewX:Qt(n),skewY:0,translateX:t[4]||0,translateY:t[5]||0}},ne=function(t){return[1,0,0,1,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0]};function oe(){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=Jt(t),r=Ft(s),n=Lt(s);return[r,n,-n,r,e?e-(r*e-n*i):0,i?i-(n*e+r*i):0]}const ae=function(t){return[t,0,0,arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,0,0]},ce=t=>Math.tan(Jt(t)),he=t=>[1,0,ce(t),1,0,0],le=t=>[1,ce(t),0,1,0,0],ue=t=>{let{scaleX:e=1,scaleY:i=1,flipX:s=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=t,a=ae(s?-e:e,r?-i:i);return n&&(a=ee(a,he(n),!0)),o&&(a=ee(a,le(o),!0)),a},de=t=>{const{translateX:e=0,translateY:i=0,angle:s=0}=t;let r=ne(e,i);s&&(r=ee(r,oe({angle:s})));const n=ue(t);return Zt(n)||(r=ee(r,n)),r},ge=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 V("loadImage"));const n=Nt();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 X("Error loading ".concat(n.src)))},i&&(n.crossOrigin=i),n.src=t):a()}))},fe=function(t){let{signal:e,reviver:i=Q}=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=>Et.getClass(t.type).fromObject(t,{signal:e}).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)}))}))},pe=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.type&&Et.has(t.type)?fe([t],{signal:e}).then((t=>{let[e]=t;return r.push(e),e})):t)),o=Object.keys(t);Promise.all(n).then((t=>t.reduce(((t,e,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)}))}))},me=function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[]).reduce(((e,i)=>(i in t&&(e[i]=t[i]),e)),{})},ve=(t,e)=>Object.keys(t).reduce(((i,s)=>(e(t[s],s,t)&&(i[s]=t[s]),i)),{}),ye=(t,e)=>parseFloat(Number(t).toFixed(e)),_e=t=>"matrix("+t.map((t=>ye(t,R.NUM_FRACTION_DIGITS))).join(" ")+")",xe=t=>!!t&&void 0!==t.toLive,be=t=>!!t&&"function"==typeof t.toObject,we=t=>!!t&&void 0!==t.offsetX&&"source"in t,Se=t=>!!t&&"multiSelectionStacking"in t;function Ce(t){const e=t&&Te(t);let i=0,s=0;if(!t||!e)return{left:i,top:s};let r=t;const n=e.documentElement,o=e.body||{scrollLeft:0,scrollTop:0};for(;r&&(r.parentNode||r.host)&&(r=r.parentNode||r.host,r===e?(i=o.scrollLeft||n.scrollLeft||0,s=o.scrollTop||n.scrollTop||0):(i+=r.scrollLeft||0,s+=r.scrollTop||0),1!==r.nodeType||"fixed"!==r.style.position););return{left:i,top:s}}const Te=t=>t.ownerDocument||null,Oe=t=>{var e;return(null===(e=t.ownerDocument)||void 0===e?void 0:e.defaultView)||null},ke=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))},De=(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 Me(t){return void 0!==t.onselectstart&&(t.onselectstart=()=>!1),t.style.userSelect=ht,t}class Ee{constructor(t){P(this,"_originalCanvasStyle",void 0),P(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&&N().getElementById(t)||Gt();var i;if(e.hasAttribute("data-fabric"))throw new X("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;ke(i,s,t,e)}setCSSDimensions(t){De(this.lower.el,t)}calcOffset(){return function(t){var e;const i=t&&Te(t),s={left:0,top:0};if(!i)return s;const r=(null===(e=Oe(t))||void 0===e?void 0:e.getComputedStyle(t,null))||{};s.left+=parseInt(r.borderLeftWidth,10)||0,s.top+=parseInt(r.borderTopWidth,10)||0,s.left+=parseInt(r.paddingLeft,10)||0,s.top+=parseInt(r.paddingTop,10)||0;let n={left:0,top:0};const o=i.documentElement;void 0!==t.getBoundingClientRect&&(n=t.getBoundingClientRect());const a=Ce(t);return{left:n.left+a.left-(o.clientLeft||0)+s.left,top:n.top+a.top-(o.clientTop||0)+s.top}}(this.lower.el)}dispose(){G().dispose(this.lower.el),delete this.lower}}const Pe={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...et]};class je extends(Xt(Vt)){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 je.ownDefaults}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new Ee(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&&(B("warn","Canvas is trying to add an object that belongs to a different canvas.\nResulting to default behavior: removing object from previous canvas and adding to new canvas"),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}getRetinaScaling(){return this.enableRetinaScaling?q():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:i=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e){const e=A({width:this.width,height:this.height},t);this.elements.setDimensions(e,this.getRetinaScaling()),this.hasLostContext=!0,this.width=e.width,this.height=e.height}i||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const i=t,s=[...this.viewportTransform],r=$t(t,te(s));s[0]=e,s[3]=e;const n=$t(r,s);s[4]+=i.x-n.x,s[5]+=i.y-n.y,this.setViewportTransform(s)}setZoom(t){this.zoomToPoint(new It(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 It(-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=Yt((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,i=te(this.viewportTransform),s=$t({x:0,y:0},i),r=$t({x:t,y:e},i),n=s.min(r),o=s.max(r);return this.vptCoords={tl:n,tr:new It(o.x,n.y),bl:new It(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Wt(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.skipControlsDrawing||this.drawControls(t),s&&(s._set("canvas",this),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,s)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){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=xe(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 It(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new It(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new It(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 It(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new It(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return $t(this.getCenterPoint(),te(this.viewportTransform))}_centerObject(t,e){t.setXY(e,rt,rt),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 i=this.clipPath,s=i&&!i.excludeFromExport?this._toObject(i,t,e):null;return A(A(A({version:J},me(this,e)),{},{objects:this._objects.filter((t=>!t.excludeFromExport)).map((i=>this._toObject(i,t,e)))},this.__serializeBgOverlay(t,e)),s?{clipPath:s}:null)}_toObject(t,e,i){let s;this.includeDefaultValues||(s=t.includeDefaultValues,t.includeDefaultValues=!1);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 xe(n)?n.excludeFromExport||(i.background=n.toObject(e)):n&&(i.background=n),xe(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=R.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(ye(-t[4]/t[0],r)," ").concat(ye(-t[5]/t[3],r)," ").concat(ye(this.width/t[0],r)," ").concat(ye(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 ",J,"</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(zt()),'<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(xe(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?_e(s):""})}})).join("")}createSVGFontFacesMarkup(){const t=[],e={},i=R.fontPaths;this._objects.forEach((function e(i){t.push(i),Bt(i)&&i._objects.forEach(e)})),t.forEach((t=>{if(!(s=t)||"function"!=typeof s._renderText)return;var s;const{styles:r,fontFamily:n}=t;!e[n]&&i[n]&&(e[n]=!0,r&&Object.values(r).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(xe(i)){const s=i.repeat||"",r=this.width,n=this.height,o=this["".concat(e,"Vpt")]?_e(te(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||!we(i)?r:i.source.width,'" height="').concat("repeat-x"!==s&&"no-repeat"!==s||!we(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 X("`json` is undefined"));const s="string"==typeof t?JSON.parse(t):t,{objects:r=[],backgroundImage:n,background:o,overlayImage:a,overlay:c,clipPath:h}=s,l=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([fe(r,{reviver:e,signal:i}),pe({backgroundImage:n,backgroundColor:o,overlayImage:a,overlayColor:c,clipPath:h},{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=Ut(this);return 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 qt(this.toCanvasElement(n,t),e,i)}toBlob(){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 Kt(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,c=this.getZoom(),h=this.width,l=this.height,u=this.skipControlsDrawing,d=c*t,g=this.viewportTransform,f=[d,0,0,d,(g[4]-(s||0))*t,(g[5]-(r||0))*t],p=this.enableRetinaScaling,m=Ut({width:o,height:a}),v=n?this._objects.filter((t=>n(t))):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=f,this.width=o,this.height=a,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(m.getContext("2d"),v),this.viewportTransform=g,this.width=h,this.height=l,this.calcViewportBoundaries(),this.enableRetinaScaling=p,this.skipControlsDrawing=u,m}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Pt.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," }>")}}P(je,"ownDefaults",Pe);const Ae=["touchstart","touchmove","touchend"],Fe=t=>{const e=Ce(t.target),i=function(t){const e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return new It(i.clientX+e.left,i.clientY+e.top)},Le=t=>Ae.includes(t.type)||"touch"===t.pointerType,Ie=t=>{t.preventDefault(),t.stopPropagation()},Re=t=>{let e=0,i=0,s=0,r=0;for(let n=0,o=t.length;n<o;n++){const{x:o,y:a}=t[n];(o>s||!n)&&(s=o),(o<e||!n)&&(e=o),(a>r||!n)&&(r=a),(a<i||!n)&&(i=a)}return{left:e,top:i,width:s-e,height:r-i}},Be=["translateX","translateY","scaleX","scaleY"],Xe=(t,e)=>Ve(t,ee(e,t.calcOwnMatrix())),Ve=(t,e)=>{const i=re(e),{translateX:s,translateY:r,scaleX:n,scaleY:o}=i,a=F(i,Be),c=new It(s,r);t.flipX=!1,t.flipY=!1,Object.assign(t,a),t.set({scaleX:n,scaleY:o}),t.setPositionByOrigin(c,rt,rt)},Ye=t=>{t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)},We=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=[new It(-s,-r),new It(s,-r),new It(-s,r),new It(s,r)].map((t=>t.transform(i))),o=Re(n);return new It(o.width,o.height)},ze=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:et;return ee(te(arguments.length>1&&void 0!==arguments[1]?arguments[1]:et),t)},Ge=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:et,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:et;return t.transform(ze(e,i))},Ne=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:et,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:et;return t.transform(ze(e,i),!0)},Ue=(t,e,i)=>{const s=ze(e,i);return Ve(t,ee(s,t.calcOwnMatrix())),s},qe=(t,e)=>{var i;const{transform:{target:s}}=e;null===(i=s.canvas)||void 0===i||i.fire("object:".concat(t),A(A({},e),{},{target:s})),s.fire(t,e)},Ke={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Je=t=>"string"==typeof t?Ke[t]:t-.5,Qe="not-allowed";function Ze(t){return Je(t.originX)===Je(rt)&&Je(t.originY)===Je(rt)}function $e(t){return.5-Je(t)}const ti=(t,e)=>t[e],ei=(t,e,i,s)=>({e:t,transform:e,pointer:new It(i,s)});function ii(t,e){const i=t.getTotalAngle()+Qt(Math.atan2(e.y,e.x))+360;return Math.round(i%360/45)}function si(t,e,i,s,r){var n;let{target:o,corner:a}=t;const c=o.controls[a],h=(null===(n=o.canvas)||void 0===n?void 0:n.getZoom())||1,l=o.padding/h,u=function(t,e,i,s){const r=t.getRelativeCenterPoint(),n=void 0!==i&&void 0!==s?t.translateToGivenOrigin(r,rt,rt,i,s):new It(t.left,t.top);return(t.angle?e.rotate(-Jt(t.angle),r):e).subtract(n)}(o,new It(s,r),e,i);return u.x>=l&&(u.x-=l),u.x<=-l&&(u.x+=l),u.y>=l&&(u.y-=l),u.y<=l&&(u.y+=l),u.x-=c.offsetX,u.y-=c.offsetY,u}const ri=(t,e,i,s)=>{const{target:r,offsetX:n,offsetY:o}=e,a=i-n,c=s-o,h=!ti(r,"lockMovementX")&&r.left!==a,l=!ti(r,"lockMovementY")&&r.top!==c;return h&&r.set(nt,a),l&&r.set(ot,c),(h||l)&&qe(ut,ei(t,e,i,s)),h||l},ni={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"},oi=(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),ai=(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 c=(r+n)/2;if(r===n)o=a=0;else{const s=r-n;switch(a=c>.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*c),s]},ci=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"1";return parseFloat(t)/(t.endsWith("%")?100:1)},hi=t=>Math.min(Math.round(t),255).toString(16).toUpperCase().padStart(2,"0"),li=t=>{let[e,i,s,r=1]=t;const n=Math.round(.3*e+.59*i+.11*s);return[n,n,n,r]};class ui{constructor(t){if(P(this,"isUnrecognised",!1),t)if(t instanceof ui)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=t.toLowerCase())in ni&&(t=ni[t]),"transparent"===t?[255,255,255,0]:ui.sourceFromHex(t)||ui.sourceFromRgb(t)||ui.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[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]=ai(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(i,"%)")}toHsla(){const[t,e,i,s]=ai(...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(hi(t)).concat(hi(e)).concat(hi(i)).concat(hi(Math.round(255*s)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(li(this.getSource())),this}toBlackWhite(t){const[e,,,i]=li(this.getSource()),s=e<(t||127)?0:255;return this.setSource([s,s,s,i]),this}overlayWith(t){t instanceof ui||(t=new ui(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 ui.fromRgba(t)}static fromRgba(t){return new ui(ui.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,ci(e[4])]}}static fromHsl(t){return ui.fromHsla(t)}static fromHsla(t){return new ui(ui.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const i=(ui.parseAngletoDegrees(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=oi(e,t,i+1/3),o=oi(e,t,i),a=oi(e,t,i-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*a),ci(e[4])]}static fromHex(t){return new ui(ui.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]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),i=parseFloat(e);return e.includes("rad")?Qt(i):e.includes("turn")?360*i:i}}const di=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:it;const i=/\D{0,2}$/.exec(t),s=parseFloat(t),r=R.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}},gi=t=>{const[e,i]=t.trim().split(" "),[s,r]=(n=e)&&n!==ht?[n.slice(1,4),n.slice(5,8)]:n===ht?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:i||"meet",alignX:s,alignY:r}},fi=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 ui(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,'" '):"")};class pi{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",i=this.strokeWidth?this.strokeWidth:"0",s=this.strokeDashArray?this.strokeDashArray.join(" "):ht,r=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",a=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=void 0!==this.opacity?this.opacity:"1",h=this.visible?"":" visibility: hidden;",l=t?"":this.getSvgFilter(),u=fi(Tt,this.fill);return[fi(Ot,this.stroke),"stroke-width: ",i,"; ","stroke-dasharray: ",s,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",a,"; ",u,"fill-rule: ",e,"; ","opacity: ",c,";",l,h].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const i=t?this.calcTransformMatrix():this.calcOwnMatrix(),s='transform="'.concat(_e(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,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",h=a&&a.absolutePositioned,l=this.stroke,u=this.fill,d=this.shadow,g=[],f=t.indexOf("COMMON_PARTS");let p;a&&(a.clipPathId="CLIPPATH_".concat(zt()),p='<clipPath id="'.concat(a.clipPathId,'" >\n').concat(a.toClipPathSVG(i),"</clipPath>\n")),h&&g.push("<g ",o,this.getSvgCommons()," >\n"),g.push("<g ",this.getSvgTransform(!1),h?"":o+this.getSvgCommons()," >\n");const m=[n,c,e?"":this.addPaintOrder()," ",r?'transform="'.concat(r,'" '):""].join("");return t[f]=m,xe(u)&&g.push(u.toSVG(this)),xe(l)&&g.push(l.toSVG(this)),d&&g.push(d.toSVG(this)),a&&g.push(p),g.push(t.join("")),g.push("</g>\n"),h&&g.push("</g>\n"),i?i(g.join("")):g.join("")}addPaintOrder(){return this.paintFirst!==Tt?' paint-order="'.concat(this.paintFirst,'" '):""}}function mi(t){return new RegExp("^("+t.join("|")+")\\b","i")}const vi="textDecorationThickness",yi=["fontSize","fontWeight","fontFamily","fontStyle"],_i=["underline","overline","linethrough"],xi=[...yi,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],bi=[...xi,..._i,"textBackgroundColor","direction",vi],wi=[...yi,..._i,Ot,"strokeWidth",Tt,"deltaY","textBackgroundColor",vi],Si={_reNewline:lt,_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:nt,fontStyle:"normal",lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:nt,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[vi]:66.667},Ci="justify",Ti="justify-left",Oi="justify-right",ki="justify-center";var Di,Mi,Ei;const Pi=String.raw(Di||(Di=L(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),ji=String.raw(Mi||(Mi=L(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),Ai=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Pi+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Pi+"))?\\s+(.*)"),Fi={cx:nt,x:nt,r:"radius",cy:ot,y:ot,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":vi},Li="font-size",Ii="clip-path";mi(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),mi(["symbol","image","marker","pattern","view","svg"]);const Ri=mi(["symbol","g","a","svg","clipPath","defs"]);new RegExp(String.raw(Ei||(Ei=L(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Pi,ji,Pi,ji,Pi,ji,Pi));const Bi=new It(1,0),Xi=new It,Vi=(t,e)=>t.rotate(e),Yi=(t,e)=>new It(e).subtract(t),Wi=t=>t.distanceFrom(Xi),Hi=(t,e)=>Math.atan2(Ui(t,e),qi(t,e)),zi=t=>Hi(Bi,t),Gi=t=>t.eq(Xi)?t:t.scalarDivide(Wi(t)),Ni=function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return Gi(new It(-t.y,t.x).scalarMultiply(e?1:-1))},Ui=(t,e)=>t.x*e.y-t.y*e.x,qi=(t,e)=>t.x*e.x+t.y*e.y,Ki=(t,e,i)=>{if(t.eq(e)||t.eq(i))return!0;const s=Ui(e,i),r=Ui(e,t),n=Ui(i,t);return s>=0?r>=0&&n<=0:!(r<=0&&n>=0)},Ji="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Qi=new RegExp("(?:\\s|^)"+Ji+Ji+"("+Pi+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Zi{constructor(t){const e="string"==typeof t?Zi.parseShadow(t):t;Object.assign(this,Zi.ownDefaults,e),this.id=zt()}static parseShadow(t){const e=t.trim(),[,i=0,s=0,r=0]=(Qi.exec(e)||[]).map((t=>parseFloat(t)||0));return{color:(e.replace(Qi,"")||"rgb(0,0,0)").trim(),offsetX:i,offsetY:s,blur:r}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Vi(new It(this.offsetX,this.offsetY),Jt(-t.angle)),i=new ui(this.color);let s=40,r=40;return t.width&&t.height&&(s=100*ye((Math.abs(e.x)+this.blur)/t.width,R.NUM_FRACTION_DIGITS)+20,r=100*ye((Math.abs(e.y)+this.blur)/t.height,R.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(ye(this.blur?this.blur/2:0,R.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(ye(e.x,R.NUM_FRACTION_DIGITS),'" dy="').concat(ye(e.y,R.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,type:this.constructor.type},e=Zi.ownDefaults;return this.includeDefaultValues?t:ve(t,((t,i)=>t!==e[i]))}static async fromObject(t){return new this(t)}}P(Zi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),P(Zi,"type","shadow"),Et.setClass(Zi,"shadow");const $i=(t,e,i)=>Math.max(t,Math.min(e,i)),ts=[ot,nt,bt,wt,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",St,Ct],es=[Tt,Ot,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],is={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:nt,originY:ot,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:Tt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},ss=(t,e,i,s)=>(t<Math.abs(e)?(t=e,s=i/4):s=0===e&&0===t?i/$*Math.asin(1):i/$*Math.asin(e/t),{a:t,c:e,p:i,s:s}),rs=(t,e,i,s,r)=>t*Math.pow(2,10*(s-=1))*Math.sin((s*r-e)*$/i),ns=(t,e,i,s)=>-i*Math.cos(t/s*Z)+i+e,os=(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,as=(t,e,i,s)=>i-os(s-t,0,i,s)+e;var cs=Object.freeze({__proto__:null,defaultEasing:ns,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:as,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:c}=ss(r,i,n,1.70158);return-rs(o,a,c,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*as(2*t,0,i,s)+e:.5*os(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:c,c:h}=ss(r,i,n,1.70158);return t<1?-.5*rs(o,a,c,t,s)+e:o*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*$/c)*.5+h+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*Z)+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:os,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:c,c:h}=ss(r,i,n,1.70158);return o*2**(-10*t)*Math.sin((t*s-a)*$/c)+h+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*Z)+e});const hs=()=>!1;class ls{constructor(t){let{startValue:e,byValue:i,duration:s=500,delay:r=0,easing:n=ns,onStart:o=Q,onChange:a=Q,onComplete:c=Q,abort:h=hs,target:l}=t;P(this,"_state","pending"),P(this,"durationProgress",0),P(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=s,this.delay=r,this.easing=n,this._onStart=o,this._onChange=a,this._onComplete=c,this._abort=h,this.target=l,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((()=>Yt(t)),this.delay):Yt(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),Yt(this.tick)))}register(){Pt.push(this)}unregister(){Pt.remove(this)}abort(){this._state="aborted",this.unregister()}}const us=["startValue","endValue"];class ds extends ls{constructor(t){let{startValue:e=0,endValue:i=100}=t;super(A(A({},F(t,us)),{},{startValue:e,byValue:i-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const gs=["startValue","endValue"];class fs extends ls{constructor(t){let{startValue:e=[0],endValue:i=[100]}=t;super(A(A({},F(t,gs)),{},{startValue:e,byValue:i.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 ps=["startValue","endValue","easing","onChange","onComplete","abort"],ms=(t,e,i,s)=>e+i*(1-Math.cos(t/s*Z)),vs=t=>t&&((e,i,s)=>t(new ui(e).toRgba(),i,s));class ys extends ls{constructor(t){let{startValue:e,endValue:i,easing:s=ms,onChange:r,onComplete:n,abort:o}=t,a=F(t,ps);const c=new ui(e).getSource(),h=new ui(i).getSource();super(A(A({},a),{},{startValue:c,byValue:h.map(((t,e)=>t-c[e])),easing:s,onChange:vs(r),onComplete:vs(n),abort:vs(o)}))}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),$i(0,r,1)];return{value:n,valueProgress:n.map(((t,e)=>0!==this.byValue[e]?Math.abs((t-this.startValue[e])/this.byValue[e]):0)).find((t=>0!==t))||0}}}function _s(t){const e=(t=>Array.isArray(t.startValue)||Array.isArray(t.endValue))(t)?new fs(t):new ds(t);return e.start(),e}function xs(t){const e=new ys(t);return e.start(),e}class bs{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=Yi(e,i),n=Yi(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 It(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,c=s.x-i.x,h=s.y-i.y,l=t.x-i.x,u=t.y-i.y,d=c*u-h*l,g=o*u-a*l,f=h*o-c*a;if(0!==f){const e=d/f,i=g/f;return(r||0<=e&&e<=1)&&(n||0<=i&&i<=1)?new bs("Intersection").append(new It(t.x+e*o,t.y+e*a)):new bs}if(0===d||0===g){const o=r||n||bs.isPointContained(t,i,s)||bs.isPointContained(e,i,s)||bs.isPointContained(i,t,e)||bs.isPointContained(s,t,e);return new bs(o?"Coincident":void 0)}return new bs("Parallel")}static intersectSegmentLine(t,e,i,s){return bs.intersectLineLine(t,e,i,s,!1,!0)}static intersectSegmentSegment(t,e,i,s){return bs.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 bs,n=i.length;for(let o,a,c,h=0;h<n;h++){if(o=i[h],a=i[(h+1)%n],c=bs.intersectLineLine(t,e,o,a,s,!1),"Coincident"===c.status)return c;r.append(...c.points)}return r.points.length>0&&(r.status="Intersection"),r}static intersectSegmentPolygon(t,e,i){return bs.intersectLinePolygon(t,e,i,!1)}static intersectPolygonPolygon(t,e){const i=new bs,s=t.length,r=[];for(let n=0;n<s;n++){const o=t[n],a=t[(n+1)%s],c=bs.intersectSegmentPolygon(o,a,e);"Coincident"===c.status?(r.push(c),i.append(o,a)):i.append(...c.points)}return r.length>0&&r.length===t.length?new bs("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 It(r.x,s.y),o=new It(s.x,r.y);return bs.intersectPolygonPolygon(t,[s,n,r,o])}}class ws extends Vt{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?$t(t,this.group.calcTransformMatrix()):t}setXY(t,e,i){this.group&&(t=$t(t,te(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,i)}getRelativeXY(){return new It(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.originX,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.originY;this.setPositionByOrigin(t,e,i)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:i,bl:s}=this.aCoords||(this.aCoords=this.calcACoords()),r=[t,e,i,s];if(this.group){const t=this.group.calcTransformMatrix();return r.map((e=>$t(e,t)))}return r}intersectsWithRect(t,e){return"Intersection"===bs.intersectPolygonRectangle(this.getCoords(),t,e).status}intersectsWithObject(t){const e=bs.intersectPolygonPolygon(this.getCoords(),t.getCoords());return"Intersection"===e.status||"Coincident"===e.status||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every((e=>t.containsPoint(e)))}isContainedWithinRect(t,e){const{left:i,top:s,width:r,height:n}=this.getBoundingRect();return i>=t.x&&i+r<=e.x&&s>=t.y&&s+n<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return bs.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some((i=>i.x<=e.x&&i.x>=t.x&&i.y<=e.y&&i.y>=t.y))||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.intersectsWithRect(t,e)||this.getCoords().every((i=>(i.x>=e.x||i.x<=t.x)&&(i.y>=e.y||i.y<=t.y)))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return Re(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(bt,t),this._set(wt,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?Qt(se(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return(null===(t=this.canvas)||void 0===t?void 0:t.viewportTransform)||et.concat()}calcACoords(){const t=oe({angle:this.angle}),{x:e,y:i}=this.getRelativeCenterPoint(),s=ne(e,i),r=ee(s,t),n=this._getTransformedDimensions(),o=n.x/2,a=n.y/2;return{tl:$t({x:-o,y:-a},r),tr:$t({x:o,y:-a},r),bl:$t({x:-o,y:a},r),br:$t({x:o,y:a},r)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Je(this.originX),Je(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const i=this.transformMatrixKey(t),s=this.matrixCache;return s&&s.key.every(((t,e)=>t===i[e]))?s.value:(this.group&&(e=ee(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=de(s);return this.ownMatrixCache={key:t,value:r},r}_getNonTransformedDimensions(){return new It(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=A({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),i=e.strokeWidth;let s=i,r=0;this.strokeUniform&&(s=0,r=i);const n=e.width+s,o=e.height+s;let a;return a=0===e.skewX&&0===e.skewY?new It(n*e.scaleX,o*e.scaleY):He(n,o,ue(e)),a.scalarAdd(r)}translateToGivenOrigin(t,e,i,s,r){let n=t.x,o=t.y;const a=Je(s)-Je(e),c=Je(r)-Je(i);if(a||c){const t=this._getTransformedDimensions();n+=a*t.x,o+=c*t.y}return new It(n,o)}translateToCenterPoint(t,e,i){if(e===rt&&i===rt)return t;const s=this.translateToGivenOrigin(t,e,i,rt,rt);return this.angle?s.rotate(Jt(this.angle),t):s}translateToOriginPoint(t,e,i){const s=this.translateToGivenOrigin(t,rt,rt,e,i);return this.angle?s.rotate(Jt(this.angle),t):s}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?$t(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new It(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(),nt,ot)}}const Ss=["type"],Cs=["extraParam"];let Ts=class t extends ws{static getDefaults(){return t.ownDefaults}get type(){const t=this.constructor.type;return"FabricObject"===t?"object":t.toLowerCase()}set type(t){B("warn","Setting type has no effect",t)}constructor(e){super(),P(this,"_cacheContext",null),Object.assign(this,t.ownDefaults),this.setOptions(e)}_createCacheCanvas(){this._cacheCanvas=Gt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,i=t.height,s=R.maxCacheSideLimit,r=R.minCacheSideLimit;if(e<=s&&i<=s&&e*i<=R.perfLimitSizeTotal)return e<r&&(t.width=r),i<r&&(t.height=r),t;const n=e/i,[o,a]=K.limitDimsByArea(n),c=$i(r,o,s),h=$i(r,a,s);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),i>h&&(t.zoomY/=i/h,t.height=h,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:Math.ceil(i+2),height:Math.ceil(s+2),zoomX:t.x,zoomY:t.y,x:i,y:s}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:i,height:s,zoomX:r,zoomY:n,x:o,y:a}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=i!==t.width||s!==t.height,h=this.zoomX!==r||this.zoomY!==n;if(!t||!e)return!1;if(c||h){i!==t.width||s!==t.height?(t.width=i,t.height=s):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const c=o/2,h=a/2;return this.cacheTranslationX=Math.round(t.width/2-c)+c,this.cacheTranslationY=Math.round(t.height/2-h)+h,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(r,n),this.zoomX=r,this.zoomY=n,!0}return!1}setOptions(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,i=this.calcTransformMatrix(!e);t.transform(i[0],i[1],i[2],i[3],i[4],i[5])}getObjectScaling(){if(!this.group)return new It(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=re(this.calcTransformMatrix());return new It(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){t!==bt&&t!==wt||(e=this._constrainScale(e)),t===bt&&e<0?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&e<0?(this.flipY=!this.flipY,e*=-1):"shadow"!==t||!e||e instanceof Zi||(e=new Zi(e));const i=this[t]!==e;return this[t]=e,i&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||i&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return 0===this.opacity||!this.width&&!this.height&&0===this.strokeWidth||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:i,cacheTranslationX:s,cacheTranslationY:r}=this,{width:n,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:i,cacheTranslationX:s,cacheTranslationY:r,width:n,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth}hasFill(){return this.fill&&"transparent"!==this.fill}needsItsOwnCache(){return!!(this.paintFirst===Ot&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)}drawClipPathOnCache(t,e,i){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(i,0,0),t.restore()}drawObject(t,e,i){const s=this.fill,r=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,i),this.fill=s,this.stroke=r}createClipPathLayer(t,e){const i=Ut(e),s=i.getContext("2d");if(s.translate(e.cacheTranslationX,e.cacheTranslationY),s.scale(e.zoomX,e.zoomY),t._cacheCanvas=i,e.parentClipPaths.forEach((t=>{t.transform(s)})),e.parentClipPaths.push(t),t.absolutePositioned){const t=te(this.calcTransformMatrix());s.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return t.transform(s),t.drawObject(s,!0,e),i}_drawClipPath(t,e,i){if(!e)return;e._transformDone=!0;const s=this.createClipPathLayer(e,i);this.drawClipPathOnCache(t,e,s)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,i=this._cacheContext;return!(!e||!i||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&i&&!t&&(i.save(),i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,e.width,e.height),i.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;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,xe(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&&(xe(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&&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)||et,o=r*s,a=n*s,c=e.nonScaling?new It(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*R.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(!xe(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){this.paintFirst===Ot?(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=this.getCanvasRetinaScaling(),n=s.x/this.scaleX/r,o=s.y/this.scaleY/r,a=Ut({width:Math.ceil(n),height:Math.ceil(o)}),c=a.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(n,0),c.lineTo(n,o),c.lineTo(0,o),c.closePath(),c.translate(n/2,o/2),c.scale(s.zoomX/this.scaleX/r,s.zoomY/this.scaleY/r),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(r*this.scaleX/s.zoomX,r*this.scaleY/s.zoomY),t.strokeStyle=null!==(i=c.createPattern(a,"no-repeat"))&&void 0!==i?i:"")}_findCenterFromElement(){return new It(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(Et.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=We(this),i=this.group,s=this.shadow,r=Math.abs,n=t.enableRetinaScaling?q():1,o=(t.multiplier||1)*n,a=t.canvasProvider||(t=>new je(t,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Ye(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Ue(this,this.getViewportTransform()),this.setCoords();const c=Gt(),h=this.getBoundingRect(),l=this.shadow,u=new It;if(l){const t=l.blur,e=l.nonScaling?new It(1,1):this.getObjectScaling();u.x=2*Math.round(r(l.offsetX)+t)*r(e.x),u.y=2*Math.round(r(l.offsetY)+t)*r(e.y)}const d=h.width+u.x,g=h.height+u.y;c.width=Math.ceil(d),c.height=Math.ceil(g);const f=a(c);"jpeg"===t.format&&(f.backgroundColor="#fff"),this.setPositionByOrigin(new It(f.width/2,f.height/2),rt,rt);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 qt(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Kt(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=rt,this.originY=rt,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(){Pt.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&G().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce(((t,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.constructor.colorProperties.includes(s[s.length-1]),{abort:n,startValue:o,onChange:a,onComplete:c}=i,h=A(A({},i),{},{target:this,startValue:null!=o?o:s.reduce(((t,e)=>t[e]),this),endValue:e,abort:null==n?void 0:n.bind(this),onChange:(t,e,i)=>{s.reduce(((e,i,r)=>(r===s.length-1&&(e[i]=t),e[i])),this),a&&a(t,e,i)},onComplete:(t,e,i)=>{this.setCoords(),c&&c(t,e,i)}});return r?xs(h):_s(h)}isDescendantOf(t){const{parent:e,group:i}=this;return e===t||i===t||!!e&&e.isDescendantOf(t)||!!i&&i!==e&&i.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do{e=e.parent,e&&t.push(e)}while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),i=t.getAncestors();if(0===e.length&&i.length>0&&this===i[i.length-1])return{fork:[],otherFork:[t,...i.slice(0,i.length-1)],common:[this]};for(let s,r=0;r<e.length;r++){if(s=e[r],s===t)return{fork:[this,...e.slice(0,r)],otherFork:[],common:e.slice(r)};for(let n=0;n<i.length;n++){if(this===i[n])return{fork:[],otherFork:[t,...i.slice(0,n)],common:[this,...e]};if(s===i[n])return{fork:[this,...e.slice(0,r)],otherFork:[t,...i.slice(0,n)],common:e.slice(r)}}}return{fork:[this,...e],otherFork:[t,...i],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const i=e.common[0]||this.canvas;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}toObject(){const e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).concat(t.customProperties,this.constructor.customProperties||[]);let i;const s=R.NUM_FRACTION_DIGITS,{clipPath:r,fill:n,stroke:o,shadow:a,strokeDashArray:c,left:h,top:l,originX:u,originY:d,width:g,height:f,strokeWidth:p,strokeLineCap:m,strokeDashOffset:v,strokeLineJoin:y,strokeUniform:_,strokeMiterLimit:x,scaleX:b,scaleY:w,angle:S,flipX:C,flipY:T,opacity:O,visible:k,backgroundColor:D,fillRule:M,paintFirst:E,globalCompositeOperation:P,skewX:j,skewY:F}=this;r&&!r.excludeFromExport&&(i=r.toObject(e.concat("inverted","absolutePositioned")));const L=t=>ye(t,s),I=A(A({},me(this,e)),{},{type:this.constructor.type,version:J,originX:u,originY:d,left:L(h),top:L(l),width:L(g),height:L(f),fill:be(n)?n.toObject():n,stroke:be(o)?o.toObject():o,strokeWidth:L(p),strokeDashArray:c?c.concat():c,strokeLineCap:m,strokeDashOffset:v,strokeLineJoin:y,strokeUniform:_,strokeMiterLimit:L(x),scaleX:L(b),scaleY:L(w),angle:L(S),flipX:C,flipY:T,opacity:L(O),shadow:a?a.toObject():a,visible:k,backgroundColor:D,fillRule:M,paintFirst:E,globalCompositeOperation:P,skewX:L(j),skewY:L(F)},i?{clipPath:i}:null);return this.includeDefaultValues?I:this._removeDefaultValues(I)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),i=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return ve(t,((t,e)=>{if(e===nt||e===ot||"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,">")}static _fromObject(t){let e=F(t,Ss),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{extraParam:s}=i,r=F(i,Cs);return pe(e,r).then((t=>s?(delete t[s],new this(e[s],t)):new this(t)))}static fromObject(t,e){return this._fromObject(t,e)}};P(Ts,"stateProperties",ts),P(Ts,"cacheProperties",es),P(Ts,"ownDefaults",is),P(Ts,"type","FabricObject"),P(Ts,"colorProperties",[Tt,Ot,"backgroundColor"]),P(Ts,"customProperties",[]),Et.setClass(Ts),Et.setClass(Ts,"object");const Os=(t,e,i)=>(s,r,n,o)=>{const a=e(s,r,n,o);return a&&qe(t,A(A({},ei(s,r,n,o)),i)),a};function ks(t){return(e,i,s,r)=>{const{target:n,originX:o,originY:a}=i,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=t(e,i,s,r);return n.setPositionByOrigin(h,i.originX,i.originY),l}}const Ds=Os(mt,ks(((t,e,i,s)=>{const r=si(e,e.originX,e.originY,i,s);if(Je(e.originX)===Je(rt)||Je(e.originX)===Je(ct)&&r.x<0||Je(e.originX)===Je(nt)&&r.x>0){const{target:t}=e,i=t.strokeWidth/(t.strokeUniform?t.scaleX:1),s=Ze(e)?2:1,n=t.width,o=Math.abs(r.x*s/t.scaleX)-i;return t.set("width",Math.max(o,1)),n!==t.width}return!1})));function Ms(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,c=a?Ot:Tt,h=!a&&(s.cornerStrokeColor||r.cornerStrokeColor);let l,u=e,d=i;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,t.scale(1,o/n),d=i*n/o):o>n?(l=o,t.scale(n/o,1),u=e*o/n):l=n,t.beginPath(),t.arc(u,d,l/2,0,$,!1),t[c](),h&&t.stroke(),t.restore()}function Es(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,c=a?Ot:Tt,h=!a&&(s.cornerStrokeColor||r.cornerStrokeColor),l=n/2,u=o/2;t.save(),t.fillStyle=s.cornerColor||r.cornerColor||"",t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",t.translate(e,i);const d=r.getTotalAngle();t.rotate(Jt(d)),t["".concat(c,"Rect")](-l,-u,n,o),h&&t.strokeRect(-l,-u,n,o),t.restore()}class Ps{constructor(t){P(this,"visible",!0),P(this,"actionName",xt),P(this,"angle",0),P(this,"x",0),P(this,"y",0),P(this,"offsetX",0),P(this,"offsetY",0),P(this,"sizeX",0),P(this,"sizeY",0),P(this,"touchSizeX",0),P(this,"touchSizeY",0),P(this,"cursorStyle","crosshair"),P(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,i,s){var r;let{tl:n,tr:o,br:a,bl:c}=s;return(null===(r=e.canvas)||void 0===r?void 0:r.getActiveObject())===e&&e.isControlVisible(t)&&bs.isPointInPolygon(i,[n,o,a,c])}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 It(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,i,s,r,n){const o=ie([ne(i,s),oe({angle:t}),ae((r?this.touchSizeX:this.sizeX)||e,(r?this.touchSizeY:this.sizeY)||e)]);return{tl:new It(-.5,-.5).transform(o),tr:new It(.5,-.5).transform(o),br:new It(.5,.5).transform(o),bl:new It(-.5,.5).transform(o)}}render(t,e,i,s,r){"circle"===((s=s||{}).cornerStyle||r.cornerStyle)?Ms.call(this,t,e,i,s,r):Es.call(this,t,e,i,s,r)}}const js=(t,e,i)=>i.lockRotation?Qe:e.cursorStyle,As=Os(gt,ks(((t,e,i,s)=>{let{target:r,ex:n,ey:o,theta:a,originX:c,originY:h}=e;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),c,h);if(ti(r,"lockRotation"))return!1;const u=Math.atan2(o-l.y,n-l.x),d=Math.atan2(s-l.y,i-l.x);let g=Qt(d-u+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 Fs(t,e){const i=e.canvas,s=t[i.uniScaleKey];return i.uniformScaling&&!s||!i.uniformScaling&&s}function Ls(t,e,i){const s=ti(t,"lockScalingX"),r=ti(t,"lockScalingY");if(s&&r)return!0;if(!e&&(s||r)&&i)return!0;if(s&&"x"===e)return!0;if(r&&"y"===e)return!0;const{width:n,height:o,strokeWidth:a}=t;return 0===n&&0===a&&"y"!==e||0===o&&0===a&&"x"!==e}const Is=["e","se","s","sw","w","nw","n","ne","e"],Rs=(t,e,i)=>{const s=Fs(t,i);if(Ls(i,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",s))return Qe;const r=ii(i,e);return"".concat(Is[r],"-resize")};function Bs(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const n=e.target,o=r.by,a=Fs(t,n);let c,h,l,u,d,g;if(Ls(n,o,a))return!1;if(e.gestureScale)h=e.scaleX*e.gestureScale,l=e.scaleY*e.gestureScale;else{if(c=si(e,e.originX,e.originY,i,s),d="y"!==o?Math.sign(c.x||e.signX||1):1,g="x"!==o?Math.sign(c.y||e.signY||1):1,e.signX||(e.signX=d),e.signY||(e.signY=g),ti(n,"lockScalingFlip")&&(e.signX!==d||e.signY!==g))return!1;if(u=n._getTransformedDimensions(),a&&!o){const t=Math.abs(c.x)+Math.abs(c.y),{original:i}=e,s=t/(Math.abs(u.x*i.scaleX/n.scaleX)+Math.abs(u.y*i.scaleY/n.scaleY));h=i.scaleX*s,l=i.scaleY*s}else h=Math.abs(c.x*n.scaleX/u.x),l=Math.abs(c.y*n.scaleY/u.y);Ze(e)&&(h*=2,l*=2),e.signX!==d&&"y"!==o&&(e.originX=$e(e.originX),h*=-1,e.signX=d),e.signY!==g&&"x"!==o&&(e.originY=$e(e.originY),l*=-1,e.signY=g)}const f=n.scaleX,p=n.scaleY;return o?("x"===o&&n.set(bt,h),"y"===o&&n.set(wt,l)):(!ti(n,"lockScalingX")&&n.set(bt,h),!ti(n,"lockScalingY")&&n.set(wt,l)),f!==n.scaleX||p!==n.scaleY}const Xs=Os(dt,ks(((t,e,i,s)=>Bs(t,e,i,s)))),Vs=Os(dt,ks(((t,e,i,s)=>Bs(t,e,i,s,{by:"x"})))),Ys=Os(dt,ks(((t,e,i,s)=>Bs(t,e,i,s,{by:"y"})))),Ws=["target","ex","ey","skewingSide"],Hs={x:{counterAxis:"y",scale:bt,skew:St,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:wt,skew:Ct,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},zs=["ns","nesw","ew","nwse"],Gs=(t,e,i)=>{if(0!==e.x&&ti(i,"lockSkewingY"))return Qe;if(0!==e.y&&ti(i,"lockSkewingX"))return Qe;const s=ii(i,e)%4;return"".concat(zs[s],"-resize")};function Ns(t,e,i,s,r){const{target:n}=i,{counterAxis:o,origin:a,lockSkewing:c,skew:h,flip:l}=Hs[t];if(ti(n,c))return!1;const{origin:u,flip:d}=Hs[o],g=Je(i[u])*(n[d]?-1:1),f=-Math.sign(g)*(n[l]?-1:1),p=-(0===n[h]&&si(i,rt,rt,s,r)[t]>0||n[h]>0?1:-1)*f*.5+.5,m=Os(pt,ks(((e,i,s,r)=>function(t,e,i){let{target:s,ex:r,ey:n,skewingSide:o}=e,a=F(e,Ws);const{skew:c}=Hs[t],h=i.subtract(new It(r,n)).divide(new It(s.scaleX,s.scaleY))[t],l=s[c],u=a[c],d=Math.tan(Jt(u)),g="y"===t?s._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:s._getTransformedDimensions({scaleX:1,scaleY:1}).y,f=2*h*o/Math.max(g,1)+d,p=Qt(Math.atan(f));s.set(c,p);const m=l!==s[c];if(m&&"y"===t){const{skewX:t,scaleX:e}=s,i=s._getTransformedDimensions({skewY:l}),r=s._getTransformedDimensions(),n=0!==t?i.x/r.x:1;1!==n&&s.set(bt,n*e)}return m}(t,i,new It(s,r)))));return m(e,A(A({},i),{},{[a]:p,skewingSide:f}),s,r)}const Us=(t,e,i,s)=>Ns("x",t,e,i,s),qs=(t,e,i,s)=>Ns("y",t,e,i,s);function Ks(t,e){return t[e.canvas.altActionKey]}const Js=(t,e,i)=>{const s=Ks(t,i);return 0===e.x?s?St:wt:0===e.y?s?Ct:bt:""},Qs=(t,e,i)=>Ks(t,i)?Gs(0,e,i):Rs(t,e,i),Zs=(t,e,i,s)=>Ks(t,e.target)?qs(t,e,i,s):Vs(t,e,i,s),$s=(t,e,i,s)=>Ks(t,e.target)?Us(t,e,i,s):Ys(t,e,i,s),tr=()=>({ml:new Ps({x:-.5,y:0,cursorStyleHandler:Qs,actionHandler:Zs,getActionName:Js}),mr:new Ps({x:.5,y:0,cursorStyleHandler:Qs,actionHandler:Zs,getActionName:Js}),mb:new Ps({x:0,y:.5,cursorStyleHandler:Qs,actionHandler:$s,getActionName:Js}),mt:new Ps({x:0,y:-.5,cursorStyleHandler:Qs,actionHandler:$s,getActionName:Js}),tl:new Ps({x:-.5,y:-.5,cursorStyleHandler:Rs,actionHandler:Xs}),tr:new Ps({x:.5,y:-.5,cursorStyleHandler:Rs,actionHandler:Xs}),bl:new Ps({x:-.5,y:.5,cursorStyleHandler:Rs,actionHandler:Xs}),br:new Ps({x:.5,y:.5,cursorStyleHandler:Rs,actionHandler:Xs}),mtr:new Ps({x:0,y:-.5,actionHandler:As,cursorStyleHandler:js,offsetY:-40,withConnection:!0,actionName:ft})}),er=()=>({mr:new Ps({x:.5,y:0,actionHandler:Ds,cursorStyleHandler:Qs,actionName:mt}),ml:new Ps({x:-.5,y:0,actionHandler:Ds,cursorStyleHandler:Qs,actionName:mt})}),ir=()=>A(A({},tr()),er());class sr extends Ts{static getDefaults(){return A(A({},super.getDefaults()),sr.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),sr.ownDefaults),this.setOptions(t)}static createControls(){return{controls:tr()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,i=e.target,s=e.action;if(this===i&&s&&s.startsWith(xt))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const i=Object.entries(this.oCoords);for(let s=i.length-1;s>=0;s--){const[r,n]=i[s],o=this.controls[r];if(o.shouldActivate(r,this,t,e?n.touchCorner:n.corner))return this.__corner=r,{key:r,control:o,coord:this.oCoords[r]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),i=ne(e.x,e.y),s=oe({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),r=ee(i,s),n=ee(t,r),o=ee(n,[1/t[0],0,0,1/t[3],0,0]),a=this.group?re(this.calcTransformMatrix()):void 0;a&&(a.scaleX=Math.abs(a.scaleX),a.scaleY=Math.abs(a.scaleY));const c=this._calculateCurrentDimensions(a),h={};return this.forEachControl(((t,e)=>{const i=t.positionHandler(c,o,this,t);h[e]=Object.assign(i,this._calcCornerCoords(t,i))})),h}_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(Jt(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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=A({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},i);t.save(),t.strokeStyle=s.borderColor,this._setLineDash(t,s.borderDashArray),this.strokeBorders(t,e),s.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{hasBorders:i,hasControls:s}=this,r=A({hasBorders:i,hasControls:s},e),n=this.getViewportTransform(),o=r.hasBorders,a=r.hasControls,c=ee(n,this.calcTransformMatrix()),h=re(c);t.save(),t.translate(h.translateX,h.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(h.angle-=180),t.rotate(Jt(this.group?h.angle:this.angle)),o&&this.drawBorders(t,h,e),a&&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,ue(e)),i=this.isStrokeAccountedForInDimensions()?Rt:(this.strokeUniform?(new It).scalarAdd(this.canvas?this.canvas.getZoom():1):new It(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 i=this.getCanvasRetinaScaling(),{cornerStrokeColor:s,cornerDashArray:r,cornerColor:n}=this,o=A({cornerStrokeColor:s,cornerDashArray:r,cornerColor:n},e);t.setTransform(i,0,0,i,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl(((e,i)=>{if(e.getVisibility(this,i)){const s=this.oCoords[i];e.render(t,s.x,s.y,o,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}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function rr(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}P(sr,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class nr extends sr{}rr(nr,[pi]),Et.setClass(nr),Et.setClass(nr,"object");const or=(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};class ar{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new It(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new It(1/this.options.scaleX,1/this.options.scaleY):new It(1,1)}createSideVector(t,e){const i=Yi(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 It(t);return e.y+=e.x*Math.tan(Jt(this.options.skewY)),e.x+=e.y*Math.tan(Jt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const cr=new It;class hr extends ar{static getOrthogonalRotationFactor(t,e){const i=e?Hi(t,e):zi(t);return Math.abs(i)<Z?-1:1}constructor(t,e,i,s){super(s),P(this,"AB",void 0),P(this,"AC",void 0),P(this,"alpha",void 0),P(this,"bisector",void 0),this.A=new It(t),this.B=new It(e),this.C=new It(i),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Hi(this.AB,this.AC),this.bisector=Gi(Vi(this.AB.eq(cr)?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=Ni(s),n=hr.getOrthogonalRotationFactor(r,this.bisector);return this.scaleUnitVector(r,i*n)}projectBevel(){const t=[];return(this.alpha%$==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?Wi(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Wi(s)/this.strokeProjectionMagnitude<=r&&t.push(this.applySkew(this.A.add(s))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const i=[],s=new It(hr.getOrthogonalRotationFactor(this.bisector),hr.getOrthogonalRotationFactor(new It(this.bisector.y,this.bisector.x)));return[new It(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s),new It(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(s)].forEach((s=>{Ki(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,c=new It(Math.tan(Jt(s)),Math.tan(Jt(r))),h=this.strokeProjectionMagnitude,l=a?h/o/Math.sqrt(1/o**2+1/n**2*c.y**2):h/Math.sqrt(1+c.y**2),u=new It(Math.sqrt(Math.max(h**2-l**2,0)),l),d=a?h/Math.sqrt(1+c.x**2*(1/o)**2/(1/n+1/n*c.x*c.y)**2):h/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),g=new It(d,Math.sqrt(Math.max(h**2-d**2,0)));return[g,g.scalarMultiply(-1),u,u.scalarMultiply(-1)].map((t=>this.applySkew(a?t.multiply(this.strokeUniformScalar):t))).forEach((s=>{Ki(s,t,e)&&i.push(this.applySkew(this.A).add(s))})),i}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%$==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=Ui(s,n)>0,a=o?s:r,c=o?r:s;return this.isSkewed()?t.push(...this.projectRoundWithSkew(a,c)):t.push(...this.projectRoundNoSkew(a,c)),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 lr extends ar{constructor(t,e,i){super(i),this.A=new It(t),this.T=new It(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(Ni(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 It(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 hr(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new It(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(Gi(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 ur=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 It(e)),t)),[new It(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]))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 lr(t,t,e).project()):!i||0!==r&&r!==n.length-1?s.push(...new hr(t,o,a,e).project()):s.push(...new lr(t,0===r?a:o,e).project())})),s},dr=t=>{const e={};return Object.keys(t).forEach((i=>{e[i]={},Object.keys(t[i]).forEach((s=>{e[i][s]=A({},t[i][s])}))})),e},gr=t=>t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">");let fr;const pr=t=>{if(fr||fr||(fr="Intl"in U()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),fr){const e=fr.segment(t);return Array.from(e).map((t=>{let{segment:e}=t;return e}))}return mr(t)},mr=t=>{const e=[];for(let i,s=0;s<t.length;s++)!1!==(i=vr(t,s))&&e.push(i);return e},vr=(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 yr=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:gr,graphemeSplit:pr});const _r=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.textDecorationThickness!==e.textDecorationThickness||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||i&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},xr=(t,e)=>{const i=e.split("\n"),s=[];let r=-1,n={};t=dr(t);for(let e=0;e<i.length;e++){const o=pr(i[e]);if(t[e])for(let i=0;i<o.length;i++){r++;const o=t[e][i];o&&Object.keys(o).length>0&&(_r(n,o,!0)?s.push({start:r,end:r+1,style:o}):s[s.length-1].end++),n=o||{}}else r+=o.length,n={}}return s},br=(t,e)=>{if(!Array.isArray(t))return dr(t);const i=e.split(lt),s={};let r=-1,n=0;for(let e=0;e<i.length;e++){const o=pr(i[e]);for(let i=0;i<o.length;i++)r++,t[n]&&t[n].start<=r&&r<t[n].end&&(s[e]=s[e]||{},s[e][i]=A({},t[n].style),r===t[n].end-1&&n++)}return s},wr=["display","transform",Tt,"fill-opacity","fill-rule","opacity",Ot,"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 Sr(t,e){const i=t.nodeName,s=t.getAttribute("class"),r=t.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let o;if(o=new RegExp("^"+i,"i"),e=e.replace(o,""),r&&e.length&&(o=new RegExp("#"+r+n,"i"),e=e.replace(o,"")),s&&e.length){const t=s.split(" ");for(let i=t.length;i--;)o=new RegExp("\\."+t[i]+n,"i"),e=e.replace(o,"")}return 0===e.length}function Cr(t,e){let i=!0;const s=Sr(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=Sr(t=t.parentElement,i);return 0===e.length}(t,e)),s&&i&&0===e.length}const Tr=t=>{var e;return null!==(e=Fi[t])&&void 0!==e?e:t},Or=new RegExp("(".concat(Pi,")"),"gi");var kr,Dr,Mr,Er,Pr,jr,Ar;const Fr="(".concat(Pi,")"),Lr=String.raw(kr||(kr=L(["(skewX)(",")"],["(skewX)\\(","\\)"])),Fr),Ir=String.raw(Dr||(Dr=L(["(skewY)(",")"],["(skewY)\\(","\\)"])),Fr),Rr=String.raw(Mr||(Mr=L(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Fr,Fr,Fr),Br=String.raw(Er||(Er=L(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Fr,Fr),Xr=String.raw(Pr||(Pr=L(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Fr,Fr),Vr=String.raw(jr||(jr=L(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Fr,Fr,Fr,Fr,Fr,Fr),Yr="(?:".concat(Vr,"|").concat(Xr,"|").concat(Rr,"|").concat(Br,"|").concat(Lr,"|").concat(Ir,")"),Wr="(?:".concat(Yr,"*)"),Hr=String.raw(Ar||(Ar=L(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Wr),zr=new RegExp(Hr),Gr=new RegExp(Yr),Nr=new RegExp(Yr,"g");function Ur(t){const e=[];if(!(t=(t=>t.replace(Or," $1 ").replace(/,/gi," ").replace(/\s+/gi," "))(t).replace(/\s*([()])\s*/gi,"$1"))||t&&!zr.test(t))return[...et];for(const i of t.matchAll(Nr)){const t=Gr.exec(i[0]);if(!t)continue;let s=et;const r=t.filter((t=>!!t)),[,n,...o]=r,[a,c,h,l,u,d]=o.map((t=>parseFloat(t)));switch(n){case"translate":s=ne(a,c);break;case ft:s=oe({angle:a},{x:c,y:h});break;case xt:s=ae(a,c);break;case St:s=he(a);break;case Ct:s=le(a);break;case"matrix":s=[a,c,h,l,u,d]}e.push(s)}return ie(e)}function qr(t,e,i,s){const r=Array.isArray(e);let n,o=e;if(t!==Tt&&t!==Ot||e!==ht){if("strokeUniform"===t)return"non-scaling-stroke"===e;if("strokeDashArray"===t)o=e===ht?null:e.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)o=i&&i.transformMatrix?ee(i.transformMatrix,Ur(e)):Ur(e);else if("visible"===t)o=e!==ht&&"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?nt:"end"===e?ct:rt;else if("charSpacing"===t||t===vi)n=di(e,s)/s*1e3;else if("paintFirst"===t){const t=e.indexOf(Tt),i=e.indexOf(Ot);o=Tt,(t>-1&&i>-1&&i<t||-1===t&&i>-1)&&(o=Ot)}else{if("href"===t||"xlink:href"===t||"font"===t||"id"===t)return e;if("imageSmoothing"===t)return"optimizeQuality"===e;n=r?e.map(di):di(e,s)}}else o="";return!r&&isNaN(n)?o:n}const Kr={stroke:"strokeOpacity",fill:"fillOpacity"};function Jr(t,e,i){if(!t)return{};let s,r={},n=it;t.parentNode&&Ri.test(t.parentNode.nodeName)&&(r=Jr(t.parentElement,e,i),r.fontSize&&(s=n=di(r.fontSize)));const o=A(A(A({},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]:{},i={};for(const s in e)Cr(t,s.split(" "))&&(i=A(A({},i),e[s]));return i}(t,i)),function(t){const e={},i=t.getAttribute("style");return i?("string"==typeof i?function(t,e){t.replace(/;\s*$/,"").split(";").forEach((t=>{if(!t)return;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}(t));o[Ii]&&t.setAttribute(Ii,o[Ii]),o[Li]&&(s=di(o[Li],n),o[Li]="".concat(s));const a={};for(const t in o){const e=Tr(t),i=qr(e,o[t],r,s);a[e]=i}a&&a.font&&function(t,e){const i=t.match(Ai);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=di(n)),a&&(e.fontFamily=a),o&&(e.lineHeight="normal"===o?1:o)}(a.font,a);const c=A(A({},r),a);return Ri.test(t.nodeName)?c:function(t){const e=nr.getDefaults();return Object.entries(Kr).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 ui(t[s]);t[s]=n.setAlpha(ye(n.getAlpha()*t[r],2)).toRgba()})),t}(c)}const Qr=["left","top","width","height","visible"],Zr=["rx","ry"];class $r extends nr{static getDefaults(){return A(A({},super.getDefaults()),$r.ownDefaults)}constructor(t){super(),Object.assign(this,$r.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height: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-st*n,r,s+e,r+st*o,s+e,r+o),t.lineTo(s+e,r+i-o),a&&t.bezierCurveTo(s+e,r+i-st*o,s+e-st*n,r+i,s+e-n,r+i),t.lineTo(s+n,r+i),a&&t.bezierCurveTo(s+st*n,r+i,s,r+i-st*o,s,r+i-o),t.lineTo(s,r+o),a&&t.bezierCurveTo(s,r+st*o,s+st*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([...Zr,...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,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i),{left:r=0,top:n=0,width:o=0,height:a=0,visible:c=!0}=s,h=F(s,Qr);return new this(A(A(A({},e),h),{},{left:r,top:n,width:o,height:a,visible:Boolean(c&&o&&a)}))}}P($r,"type","Rect"),P($r,"cacheProperties",[...es,...Zr]),P($r,"ownDefaults",{rx:0,ry:0}),P($r,"ATTRIBUTE_NAMES",[...wr,"x","y","rx","ry","width","height"]),Et.setClass($r),Et.setSVGClass($r);const tn="initialization",en="added",sn="removed",rn="imperative",nn=(t,e)=>{const{strokeUniform:i,strokeWidth:s,width:r,height:n,group:o}=e,a=o&&o!==t?ze(o.calcTransformMatrix(),t.calcTransformMatrix()):null,c=a?e.getRelativeCenterPoint().transform(a):e.getRelativeCenterPoint(),h=!e.isStrokeAccountedForInDimensions(),l=i&&h?Ne(new It(s,s),void 0,t.calcTransformMatrix()):Rt,u=!i&&h?s:0,d=He(r+u,n+u,ie([a,e.calcOwnMatrix()],!0)).add(l).scalarDivide(2);return[c.subtract(d),c.add(d)]};class on{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:i,strategy:s}=t;return e===tn||e===rn||!!i&&s!==i}shouldLayoutClipPath(t){let{type:e,target:{clipPath:i}}=t;return e!==tn&&i&&!i.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:i,target:s}=e;if(i===rn&&e.overrides)return e.overrides;if(0===t.length)return;const{left:r,top:n,width:o,height:a}=Re(t.map((t=>nn(s,t))).reduce(((t,e)=>t.concat(e)),[])),c=new It(o,a),h=new It(r,n).add(c.scalarDivide(2));if(i===tn){const t=this.getInitialSize(e,{size:c,center:h});return{center:h,relativeCorrection:new It(0,0),size:t}}return{center:h.transform(s.calcOwnMatrix()),size:c}}}P(on,"type","strategy");class an extends on{shouldPerformLayout(t){return!0}}P(an,"type","fit-content"),Et.setClass(an);const cn=["strategy"],hn=["target","strategy","bubbles","prevStrategy"],ln="layoutManager";class un{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new an;P(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=A(A({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const i=this.getLayoutResult(e);i&&this.commitLayout(e,i),this.onAfterLayout(e,i),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:i}=e;return[kt,ut,mt,gt,dt,pt,_t,vt,yt].map((e=>t.on(e,(t=>this.performLayout(e===kt?{type:"object_modified",trigger:e,e:t,target:i}:{type:"object_modifying",trigger:e,e:t,target:i})))))}subscribe(t,e){this.unsubscribe(t,e);const i=this.attachHandlers(t,e);this._subscriptions.set(t,i)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach((t=>t())),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach((e=>this.unsubscribe(e,t)))}subscribeTargets(t){t.targets.forEach((e=>this.subscribe(e,t)))}onBeforeLayout(t){const{target:e,type:i}=t,{canvas:s}=e;if(i===tn||i===en?this.subscribeTargets(t):i===sn&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),s&&s.fire("object:layout:before",{target:e,context:t}),i===rn&&t.deep){const i=F(t,cn);e.forEachObject((t=>t.layoutManager&&t.layoutManager.performLayout(A(A({},i),{},{bubbles:!1,target:t}))))}}getLayoutResult(t){const{target:e,strategy:i,type:s}=t,r=i.calcLayoutResult(t,e.getObjects());if(!r)return;const n=s===tn?new It:e.getRelativeCenterPoint(),{center:o,correction:a=new It,relativeCorrection:c=new It}=r,h=n.subtract(o).add(a).transform(s===tn?et:te(e.calcOwnMatrix()),!0).add(c);return{result:r,prevCenter:n,nextCenter:o,offset:h}}commitLayout(t,e){const{target:i}=t,{result:{size:s},nextCenter:r}=e;var n,o;i.set({width:s.x,height:s.y}),this.layoutObjects(t,e),t.type===tn?i.set({left:null!==(n=t.x)&&void 0!==n?n:r.x+s.x*Je(i.originX),top:null!==(o=t.y)&&void 0!==o?o:r.y+s.y*Je(i.originY)}):(i.setPositionByOrigin(r,rt,rt),i.setCoords(),i.set("dirty",!0))}layoutObjects(t,e){const{target:i}=t;i.forEachObject((s=>{s.group===i&&this.layoutObject(t,e,s)})),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,i.clipPath)}layoutObject(t,e,i){let{offset:s}=e;i.set({left:i.left+s.x,top:i.top+s.y})}onAfterLayout(t,e){const{target:i,strategy:s,bubbles:r,prevStrategy:n}=t,o=F(t,hn),{canvas:a}=i;i.fire("layout:after",{context:t,result:e}),a&&a.fire("object:layout:after",{context:t,result:e,target:i});const c=i.parent;r&&null!=c&&c.layoutManager&&((o.path||(o.path=[])).push(i),c.layoutManager.performLayout(A(A({},o),{},{target:c}))),i.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach((t=>t.forEach((t=>t())))),t.clear()}toObject(){return{type:ln,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}Et.setClass(un,ln);const dn=["type","objects","layoutManager"];class gn extends un{performLayout(){}}class fn extends(Xt(nr)){static getDefaults(){return A(A({},super.getDefaults()),fn.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),P(this,"_activeObjects",[]),P(this,"__objectSelectionTracker",void 0),P(this,"__objectSelectionDisposer",void 0),Object.assign(this,fn.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var i;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject((t=>{this.enterGroup(t,!1)})),this.layoutManager=null!==(i=e.layoutManager)&&void 0!==i?i:new un,this.layoutManager.performLayout({type:tn,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(B("error","Group: circular object trees are not supported, this call has no effect"),!1):-1===this._objects.indexOf(t)||(B("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(en,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(en,r),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(sn,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const i=this[t];return super._set(t,e),"canvas"===t&&i!==e&&(this._objects||[]).forEach((i=>{i._set(t,e)})),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:i}=e;const s=this._activeObjects;if(t)s.push(i),this._set("dirty",!0);else if(s.length>0){const t=s.indexOf(i);t>-1&&(s.splice(t,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Ve(t,ee(te(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),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("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Ve(t,ee(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=nr.prototype.shouldCache.call(this);if(t)for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return this.ownCaching=!1,!1;return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,i){this._renderBackground(t);for(let e=0;e<this._objects.length;e++){var s;const i=this._objects[e];null!==(s=this.canvas)&&void 0!==s&&s.preserveObjectStacking&&i.group!==this?(t.save(),t.transform(...te(this.calcTransformMatrix())),i.render(t),t.restore()):i.group===this&&i.render(t)}this._drawClipPath(t,this.clipPath,i)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}triggerLayout(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.layoutManager.performLayout(A({target:this,type:rn},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__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]:[];const e=this.layoutManager.toObject();return A(A(A({},super.toObject(["subTargetCheck","interactive",...t])),"fit-content"!==e.strategy||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject((t=>{this._watchObject(!1,t),t.dispose()})),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=$r.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,e){let{type:i,objects:s=[],layoutManager:r}=t,n=F(t,dn);return Promise.all([fe(s,e),pe(n,e)]).then((t=>{let[e,i]=t;const s=new this(e,A(A(A({},n),i),{},{layoutManager:new gn}));if(r){const t=Et.getClass(r.type),e=Et.getClass(r.strategy);s.layoutManager=new t(new e)}else s.layoutManager=new un;return s.layoutManager.subscribeTargets({type:tn,target:s,targets:s.getObjects()}),s.setCoords(),s}))}}P(fn,"type","Group"),P(fn,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),Et.setClass(fn);const pn=(t,e)=>Math.min(e.width/t.width,e.height/t.height),mn=(t,e)=>Math.max(e.width/t.width,e.height/t.height),vn="\\s*,?\\s*",yn="".concat(vn,"(").concat(Pi,")"),_n="".concat(yn).concat(yn).concat(yn).concat(vn,"([01])").concat(vn,"([01])").concat(yn).concat(yn),xn={m:"l",M:"L"},bn=(t,e,i,s,r,n,o,a,c,h,l)=>{const u=Ft(t),d=Lt(t),g=Ft(e),f=Lt(e),p=i*r*g-s*n*f+o,m=s*r*g+i*n*f+a;return["C",h+c*(-i*r*d-s*n*u),l+c*(-s*r*d+i*n*u),p+c*(i*r*f+s*n*g),m+c*(s*r*f-i*n*g),p,m]},wn=(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 Sn(t,e,i,s,r,n,o,a){let c;if(R.cachesBoundsOfCurve&&(c=[...arguments].join(),K.boundsOfCurveCache[c]))return K.boundsOfCurveCache[c];const h=Math.sqrt,l=Math.abs,u=[],d=[[0,0],[0,0]];let g=6*t-12*i+6*r,f=-3*t+9*i-9*r+3*o,p=3*i-3*t;for(let t=0;t<2;++t){if(t>0&&(g=6*e-12*s+6*n,f=-3*e+9*s-9*n+3*a,p=3*s-3*e),l(f)<1e-12){if(l(g)<1e-12)continue;const t=-p/g;0<t&&t<1&&u.push(t);continue}const i=g*g-4*p*f;if(i<0)continue;const r=h(i),o=(-g+r)/(2*f);0<o&&o<1&&u.push(o);const c=(-g-r)/(2*f);0<c&&c<1&&u.push(c)}let m=u.length;const v=m,y=kn(t,e,i,s,r,n,o,a);for(;m--;){const{x:t,y:e}=y(u[m]);d[0][m]=t,d[1][m]=e}d[0][v]=t,d[1][v]=e,d[0][v+1]=o,d[1][v+1]=a;const _=[new It(Math.min(...d[0]),Math.min(...d[1])),new It(Math.max(...d[0]),Math.max(...d[1]))];return R.cachesBoundsOfCurve&&(K.boundsOfCurveCache[c]=_),_}const Cn=(t,e,i)=>{let[s,r,n,o,a,c,h,l]=i;const u=((t,e,i,s,r,n,o)=>{if(0===i||0===s)return[];let a=0,c=0,h=0;const l=Math.PI,u=o*tt,d=Lt(u),g=Ft(u),f=.5*(-g*t-d*e),p=.5*(-g*e+d*t),m=i**2,v=s**2,y=p**2,_=f**2,x=m*v-m*y-v*_;let b=Math.abs(i),w=Math.abs(s);if(x<0){const t=Math.sqrt(1-x/(m*v));b*=t,w*=t}else h=(r===n?-1:1)*Math.sqrt(x/(m*y+v*_));const S=h*b*p/w,C=-h*w*f/b,T=g*S-d*C+.5*t,O=d*S+g*C+.5*e;let k=wn(1,0,(f-S)/b,(p-C)/w),D=wn((f-S)/b,(p-C)/w,(-f-S)/b,(-p-C)/w);0===n&&D>0?D-=2*l:1===n&&D<0&&(D+=2*l);const M=Math.ceil(Math.abs(D/l*2)),E=[],P=D/M,j=8/3*Math.sin(P/4)*Math.sin(P/4)/Math.sin(P/2);let A=k+P;for(let t=0;t<M;t++)E[t]=bn(k,A,g,d,b,w,T,O,j,a,c),a=E[t][5],c=E[t][6],k=A,A+=P;return E})(h-t,l-e,r,n,a,c,o);for(let i=0,s=u.length;i<s;i++)u[i][1]+=t,u[i][2]+=e,u[i][3]+=t,u[i][4]+=e,u[i][5]+=t,u[i][6]+=e;return u},Tn=t=>{let e=0,i=0,s=0,r=0;const n=[];let o,a=0,c=0;for(const h of t){const t=[...h];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],c=t[4],e=t[5],i=t[6],l=["C",t[1],t[2],a,c,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,c=2*i-c):(a=e,c=i),e=t[3],i=t[4],l=["C",a,c,t[1],t[2],e,i],a=l[3],c=l[4];break;case"q":t[1]+=e,t[2]+=i,t[3]+=e,t[4]+=i;case"Q":a=t[1],c=t[2],e=t[3],i=t[4],l=["Q",a,c,e,i];break;case"t":t[1]+=e,t[2]+=i;case"T":"Q"===o?(a=2*e-a,c=2*i-c):(a=e,c=i),e=t[1],i=t[2],l=["Q",a,c,e,i];break;case"a":t[6]+=e,t[7]+=i;case"A":Cn(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},On=(t,e,i,s)=>Math.sqrt((i-t)**2+(s-e)**2),kn=(t,e,i,s,r,n,o,a)=>c=>{const h=c**3,l=(t=>3*t**2*(1-t))(c),u=(t=>3*t*(1-t)**2)(c),d=(t=>(1-t)**3)(c);return new It(o*h+r*l+i*u+t*d,a*h+n*l+s*u+e*d)},Dn=t=>t**2,Mn=t=>2*t*(1-t),En=t=>(1-t)**2,Pn=(t,e,i,s,r,n,o,a)=>c=>{const h=Dn(c),l=Mn(c),u=En(c),d=3*(u*(i-t)+l*(r-i)+h*(o-r)),g=3*(u*(s-e)+l*(n-s)+h*(a-n));return Math.atan2(g,d)},jn=(t,e,i,s,r,n)=>o=>{const a=Dn(o),c=Mn(o),h=En(o);return new It(r*a+i*c+t*h,n*a+s*c+e*h)},An=(t,e,i,s,r,n)=>o=>{const a=1-o,c=2*(a*(i-t)+o*(r-i)),h=2*(a*(s-e)+o*(n-s));return Math.atan2(h,c)},Fn=(t,e,i)=>{let s=new It(e,i),r=0;for(let e=1;e<=100;e+=1){const i=t(e/100);r+=On(s.x,s.y,i.x,i.y),s=i}return r},Ln=t=>{let e,i,s=0,r=0,n=0,o=0,a=0;const c=[];for(const h of t){const t={x:r,y:n,command:h[0],length:0};switch(h[0]){case"M":i=t,i.x=o=r=h[1],i.y=a=n=h[2];break;case"L":i=t,i.length=On(r,n,h[1],h[2]),r=h[1],n=h[2];break;case"C":e=kn(r,n,h[1],h[2],h[3],h[4],h[5],h[6]),i=t,i.iterator=e,i.angleFinder=Pn(r,n,h[1],h[2],h[3],h[4],h[5],h[6]),i.length=Fn(e,r,n),r=h[5],n=h[6];break;case"Q":e=jn(r,n,h[1],h[2],h[3],h[4]),i=t,i.iterator=e,i.angleFinder=An(r,n,h[1],h[2],h[3],h[4]),i.length=Fn(e,r,n),r=h[3],n=h[4];break;case"Z":i=t,i.destX=o,i.destY=a,i.length=On(r,n,o,a),r=o,n=a}s+=i.length,c.push(i)}return c.push({length:s,x:r,y:n}),c},In=function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ln(t),s=0;for(;e-i[s].length>0&&s<i.length-2;)e-=i[s].length,s++;const r=i[s],n=e/r.length,o=t[s];switch(r.command){case"M":return{x:r.x,y:r.y,angle:0};case"Z":return A(A({},new It(r.x,r.y).lerp(new It(r.destX,r.destY),n)),{},{angle:Math.atan2(r.destY-r.y,r.destX-r.x)});case"L":return A(A({},new It(r.x,r.y).lerp(new It(o[1],o[2]),n)),{},{angle:Math.atan2(o[2]-r.y,o[1]-r.x)});case"C":case"Q":return((t,e)=>{let i,s=0,r=0,n={x:t.x,y:t.y},o=A({},n),a=.01,c=0;const h=t.iterator,l=t.angleFinder;for(;r<e&&a>1e-4;)o=h(s),c=s,i=On(n.x,n.y,o.x,o.y),i+r>e?(s-=a,a/=2):(n=o,s+=a,r+=i);return A(A({},o),{},{angle:l(c)})})(r,e)}},Rn=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),Bn=new RegExp(_n,"g"),Xn=new RegExp(Pi,"gi"),Vn={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Yn=t=>{var e;const i=[],s=null!==(e=t.match(Rn))&&void 0!==e?e:[];for(const t of s){const e=t[0];if("z"===e||"Z"===e){i.push([e]);continue}const s=Vn[e.toLowerCase()];let r=[];if("a"===e||"A"===e){Bn.lastIndex=0;for(let e=null;e=Bn.exec(t);)r.push(...e.slice(1))}else r=t.match(Xn)||[];for(let t=0;t<r.length;t+=s){const n=new Array(s),o=xn[e];n[0]=t>0&&o?o:e;for(let e=0;e<s;e++)n[e+1]=parseFloat(r[t+e]);i.push(n)}}return i},Wn=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=new It(t[0]),s=new It(t[1]),r=1,n=0;const o=[],a=t.length,c=a>2;let h;for(c&&(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]),h=1;h<a;h++){if(!i.eq(s)){const t=i.midPointFrom(s);o.push(["Q",i.x,i.y,t.x,t.y])}i=t[h],h+1<t.length&&(s=t[h+1])}return c&&(r=i.x>t[h-2].x?1:i.x===t[h-2].x?0:-1,n=i.y>t[h-2].y?1:i.y===t[h-2].y?0:-1),o.push(["L",i.x+r*e,i.y+n*e]),o},Hn=(t,e)=>t.map((t=>t.map(((t,i)=>0===i||void 0===e?t:ye(t,e))).join(" "))).join(" ");function zn(t,e){const i=t.style;i&&e&&("string"==typeof e?i.cssText+=";"+e:Object.entries(e).forEach((t=>{let[e,s]=t;return i.setProperty(e,s)})))}var Gn=Object.freeze({__proto__:null,addTransformToObject:Xe,animate:_s,animateColor:xs,applyTransformToObject:Ve,calcAngleBetweenVectors:Hi,calcDimensionsMatrix:ue,calcPlaneChangeMatrix:ze,calcVectorRotation:zi,cancelAnimFrame:Wt,capValue:$i,composeMatrix:de,copyCanvasElement:t=>{var e;const i=Ut(t);return null===(e=i.getContext("2d"))||void 0===e||e.drawImage(t,0,0),i},cos:Ft,createCanvasElement:Gt,createImage:Nt,createRotateMatrix:oe,createScaleMatrix:ae,createSkewXMatrix:he,createSkewYMatrix:le,createTranslateMatrix:ne,createVector:Yi,crossProduct:Ui,degreesToRadians:Jt,dotProduct:qi,ease:cs,enlivenObjectEnlivables:pe,enlivenObjects:fe,findScaleToCover:mn,findScaleToFit:pn,getBoundsOfCurve:Sn,getOrthonormalVector:Ni,getPathSegmentsInfo:Ln,getPointOnPath:In,getPointer:Fe,getRandomInt:(t,e)=>Math.floor(Math.random()*(e-t+1))+t,getRegularPolygonPath:(t,e)=>{const i=2*Math.PI/t;let s=-Z;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 It(Ft(t),Lt(t)).scalarMultiply(e);r[n]=[0===n?"M":"L",o,a]}return r[t]=["Z"],r},getSmoothPathFromPoints:Wn,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:Gi,groupSVGElements:(t,e)=>t&&1===t.length?t[0]:new fn(t,e),hasStyleChanged:_r,invertTransform:te,isBetweenVectors:Ki,isIdentityMatrix:Zt,isTouchEvent:Le,isTransparent:or,joinPath:Hn,loadImage:ge,magnitude:Wi,makeBoundingBoxFromPoints:Re,makePathSimpler:Tn,matrixToSVG:_e,mergeClipPaths:(t,e)=>{var i;let s=t,r=e;s.inverted&&!r.inverted&&(s=e,r=t),Ue(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 fn([s],{clipPath:r,inverted:n})},multiplyTransformMatrices:ee,multiplyTransformMatrixArray:ie,parsePath:Yn,parsePreserveAspectRatioAttribute:gi,parseUnit:di,pick:me,projectStrokeOnPoints:ur,qrDecompose:re,radiansToDegrees:Qt,removeFromArray:At,removeTransformFromObject:(t,e)=>{const i=te(e),s=ee(i,t.calcOwnMatrix());Ve(t,s)},removeTransformMatrixForSvgParsing:(t,e)=>{let i=t._findCenterFromElement();t.transformMatrix&&((t=>{if(t.transformMatrix){const{scaleX:e,scaleY:i,angle:s,skewX:r}=re(t.transformMatrix);t.flipX=!1,t.flipY=!1,t.set(bt,e),t.set(wt,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,rt,rt)},request:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.onComplete||Q,s=new(U().XMLHttpRequest),r=e.signal,n=function(){s.abort()},o=function(){r&&r.removeEventListener("abort",n),s.onerror=s.ontimeout=Q};if(r&&r.aborted)throw new V("request");return r&&r.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){4===s.readyState&&(o(),i(s),s.onreadystatechange=Q)},s.onerror=s.ontimeout=o,s.open("get",t,!0),s.send(),s},requestAnimFrame:Yt,resetObjectTransform:Ye,rotatePoint:(t,e,i)=>t.rotate(i,e),rotateVector:Vi,saveObjectTransform:We,sendObjectToPlane:Ue,sendPointToPlane:Ge,sendVectorToPlane:Ne,setStyle:zn,sin:Lt,sizeAfterTransform:He,string:yr,stylesFromArray:br,stylesToArray:xr,toBlob:Kt,toDataURL:qt,toFixed:ye,transformPath:(t,e,i)=>(i&&(e=ee(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}=$t({x:t[s],y:t[s+1]},e);i[s]=r,i[s+1]=n}return i}))),transformPoint:$t});class Nn extends Ee{constructor(t){let{allowTouchScrolling:e=!1,containerClass:i=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t),P(this,"upper",void 0),P(this,"container",void 0);const{el:s}=this.lower,r=this.createUpperCanvas();this.upper={el:r,ctx:r.getContext("2d")},this.applyCanvasStyle(s,{allowTouchScrolling:e}),this.applyCanvasStyle(r,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const n=this.createContainerElement();n.classList.add(i),s.parentNode&&s.parentNode.replaceChild(n,s),n.append(s,r),this.container=n}createUpperCanvas(){const{el:t}=this.lower,e=Gt();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=N().createElement("div");return t.setAttribute("data-fabric","wrapper"),zn(t,{position:"relative"}),Me(t),t}applyCanvasStyle(t,e){const{styles:i,allowTouchScrolling:s}=e;zn(t,A(A({},i),{},{"touch-action":s?"manipulation":ht})),Me(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:i,ctx:s}=this.upper;ke(i,s,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),De(this.upper.el,t),De(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(),G().dispose(this.upper.el),delete this.upper,delete this.container}}class Un extends je{constructor(){super(...arguments),P(this,"targets",[]),P(this,"_hoveredTargets",[]),P(this,"_objectsToRender",void 0),P(this,"_currentTransform",null),P(this,"_groupSelector",null),P(this,"contextTopDirty",!1)}static getDefaults(){return A(A({},super.getDefaults()),Un.ownDefaults)}get upperCanvasEl(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.el}get contextTop(){var t;return null===(t=this.elements.upper)||void 0===t?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Nn(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 or(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 e===xt||e===bt||e===wt||e===mt?s=this.centeredScaling||t.centeredScaling:e===ft&&(s=this.centeredRotation||t.centeredRotation),s?!i:i}_getOriginFromCorner(t,e){const i={x:t.originX,y:t.originY};return e?(["ml","tl","bl"].includes(e)?i.x=ct:["mr","tr","br"].includes(e)&&(i.x=nt),["tl","mt","tr"].includes(e)?i.y=at:["bl","mb","br"].includes(e)&&(i.y=ot),i):i}_setupCurrentTransform(t,e,i){var s;const r=e.group?Ge(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:n="",control:o}=e.getActiveControl()||{},a=i&&o?null===(s=o.getActionHandler(t,e,o))||void 0===s?void 0:s.bind(o):ri,c=((t,e,i,s)=>{if(!e||!t)return"drag";const r=s.controls[e];return r.getActionName(i,r,s)})(i,n,t,e),h=t[this.centeredKey],l=this._shouldCenterTransform(e,c,h)?{x:rt,y:rt}:this._getOriginFromCorner(e,n),u={target:e,action:c,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:l.x,originY:l.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:Jt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:h,original:A(A({},We(e)),{},{originX:l.x,originY:l.y})};this._currentTransform=u,this.fire("before:transform",{e:t,transform:u})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new It(e,i).transform(this.viewportTransform),o=new It(e+s,i+r).transform(this.viewportTransform),a=this.selectionLineWidth/2;let c=Math.min(n.x,o.x),h=Math.min(n.y,o.y),l=Math.max(n.x,o.x),u=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,h,l-c,u-h)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=a,h+=a,l-=a,u-=a,nr.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,h,l-c,u-h))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),i=this._activeObject,s=this.getActiveObjects();if(this.targets=[],i&&s.length>=1){if(i.findControl(e,Le(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)}_pointIsInObjectSelectionArea(t,e){let i=t.getCoords();const s=this.getZoom(),r=t.padding/s;if(r){const[t,e,s,n]=i,o=Math.atan2(e.y-t.y,e.x-t.x),a=Ft(o)*r,c=Lt(o)*r,h=a+c,l=a-c;i=[new It(t.x-l,t.y-h),new It(e.x+h,e.y-l),new It(s.x+l,s.y+h),new It(n.x-h,n.y+l)]}return bs.isPointInPolygon(e,i)}_checkTarget(t,e){if(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Ge(e,void 0,this.viewportTransform))){if(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing)return!0;if(!this.isTargetTransparent(t,e.x,e.y))return!0}return!1}_searchPossibleTargets(t,e){let i=t.length;for(;i--;){const s=t[i];if(this._checkTarget(s,e)){if(Bt(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);if(i&&Bt(i)&&i.interactive&&this.targets[0]){const t=this.targets;for(let e=t.length-1;e>0;e--){const i=t[e];if(!Bt(i)||!i.interactive)return i}return t[0]}return i}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.upperCanvasEl,s=i.getBoundingClientRect();let r=Fe(t),n=s.width||0,o=s.height||0;n&&o||(ot in s&&at in s&&(o=Math.abs(s.top-s.bottom)),ct in s&&nt 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=Ge(r,void 0,this.viewportTransform));const a=this.getRetinaScaling();1!==a&&(r.x/=a,r.y/=a);const c=0===n||0===o?new It(1,1):new It(i.width/n,i.height/o);return r.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=Gt(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return Se(t)?t.getObjects():t?[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){const i=this._activeObject;return!(i===t||!this._discardActiveObject(e,t)&&this._activeObject||t.onSelect({e:e})||(this._activeObject=t,Se(t)&&i!==t&&t.set("canvas",this),t.setCoords(),0))}_discardActiveObject(t,e){const i=this._activeObject;return!!i&&!i.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===i&&this.endCurrentTransform(t),Se(i)&&i===this._hoveredTarget&&(this._hoveredTarget=void 0),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}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(kt,s))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Se(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,i){const s=this._realizeGroupTransformOnObject(t),r=super._toObject(t,e,i);return t.set(s),r}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&Se(e)&&this._activeObject===e){const i=me(t,["angle","flipX","flipY",nt,bt,wt,St,Ct,ot]);return Xe(t,e.calcOwnMatrix()),i}return{}}_setSVGObject(t,e,i){const s=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,i),e.set(s)}}P(Un,"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 qn{constructor(t){P(this,"targets",[]),P(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:e}=t.getActiveObject()||{};e&&e.focus()},i=t.upperCanvasEl;i.addEventListener("click",e),this.__disposer=()=>i.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach((t=>{t.isEditing&&t.exitEditing()}))}add(t){this.targets.push(t)}remove(t){this.unregister(t),At(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 Kn=["target","oldTarget","fireCanvas","e"],Jn={passive:!1},Qn=(t,e)=>{const i=t.getViewportPoint(e),s=t.getScenePoint(e);return{viewportPoint:i,scenePoint:s,pointer:i,absolutePointer:s}},Zn=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)},$n=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)},to={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 eo extends Un{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),P(this,"_isClick",void 0),P(this,"textEditingManager",new qn(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((t=>{this[t]=this[t].bind(this)})),this.addOrRemove(Zn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const i=this.upperCanvasEl,s=this._getEventPrefix();t(Oe(i),"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,"".concat(s,"move"),this._onMouseMove,Jn),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,"click",this._onClick),t(i,"dblclick",this._onClick),t(i,"dragstart",this._onDragStart),t(i,"dragend",this._onDragEnd),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,Jn)}removeListeners(){this.addOrRemove($n,"remove");const t=this._getEventPrefix(),e=Te(this.upperCanvasEl);$n(e,"".concat(t,"up"),this._onMouseUp),$n(e,"touchend",this._onTouchEnd,Jn),$n(e,"".concat(t,"move"),this._onMouseMove,Jn),$n(e,"touchmove",this._onMouseMove,Jn),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,i=A({e:t},Qn(this,t));this.fire("mouse:out",A(A({},i),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",A({},i)),this._hoveredTargets.forEach((t=>{this.fire("mouse:out",A(A({},i),{},{target:t})),t&&t.fire("mouseout",A({},i))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",A({e:t},Qn(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const i={e:t,target:e};return this.fire("dragstart",i),e.fire("dragstart",i),void Zn(this.upperCanvasEl,"drag",this._onDragProgress)}Ie(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!==ht,i=e?this._activeObject:void 0,s={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:i};$n(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){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),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",A({e:t,target:e,subTargets:i,dragSource:this._dragSource},Qn(this,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&&Ie(t),this._basicEventHandler("contextmenu",s),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),2==e&&"dblclick"===t.type&&this._handleEvent(t,"dblclick"),3==e&&this._handleEvent(t,"tripleclick"),this._resetTransformEventData())}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const i=this._activeObject;void 0===this.mainTouchId&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||i&&this._target===i)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const s=this.upperCanvasEl,r=this._getEventPrefix(),n=Te(s);Zn(n,"touchend",this._onTouchEnd,Jn),e&&Zn(n,"touchmove",this._onMouseMove,Jn),$n(s,"".concat(r,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,i=this._getEventPrefix();$n(e,"".concat(i,"move"),this._onMouseMove,Jn);const s=Te(e);Zn(s,"".concat(i,"up"),this._onMouseUp),Zn(s,"".concat(i,"move"),this._onMouseMove,Jn)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),i=Te(this.upperCanvasEl);$n(i,"touchend",this._onTouchEnd,Jn),$n(i,"touchmove",this._onMouseMove,Jn),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{Zn(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=Te(this.upperCanvasEl);$n(t,"".concat(i,"up"),this._onMouseUp),$n(t,"".concat(i,"move"),this._onMouseMove,Jn),Zn(e,"".concat(i,"move"),this._onMouseMove,Jn)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const i=this._currentTransform,s=this._isClick,r=this._target,{button:n}=t;if(n)return(this.fireMiddleClick&&1===n||this.fireRightClick&&2===n)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,a,c=!1;if(i&&(this._finalizeCurrentTransform(t),c=i.actionPerformed),!s){const e=r===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(r)||!e&&r===this._activeObject)}if(r){const e=r.findControl(this.getViewportPoint(t),Le(t)),{key:s,control:n}=e||{};if(a=s,r.selectable&&r!==this._activeObject&&"up"===r.activeOn)this.setActiveObject(r,t),c=!0;else if(n){const e=n.getMouseUpHandler(t,r,n);e&&(o=this.getScenePoint(t),e.call(n,t,i,o.x,o.y))}r.isMoving=!1}if(i&&(i.target!==r||i.corner!==a)){const e=i.target&&i.target.controls[i.corner],s=e&&e.getMouseUpHandler(t,i.target,e);o=o||this.getScenePoint(t),s&&s.call(e,t,i,o.x,o.y)}this._setCursorFromEvent(t,r),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,r&&(r.__corner=void 0),c?this.requestRenderAll():s||null!==(e=this._activeObject)&&void 0!==e&&e.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,i){const s=this._target,r=this.targets||[],n=A(A(A({e:t,target:s,subTargets:r},Qn(this,t)),{},{transform:this._currentTransform},"up:before"===e||"up"===e?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),"down:before"===e||"down"===e?i:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let t=0;t<r.length;t++)r[t]!==s&&r[t].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,i=!!e&&e===this._activeObject;const{button:s}=t;if(s)return(this.fireMiddleClick&&1===s||this.fireRightClick&&2===s)&&this._handleEvent(t,"down",{alreadySelected:i}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t))return;if(this._currentTransform)return;let r=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,r=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const e=this.getScenePoint(t);this._groupSelector={x:e.x,y:e.y,deltaY:0,deltaX:0}}if(i=!!e&&e===this._activeObject,e){e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);const s=e.findControl(this.getViewportPoint(t),Le(t));if(e===this._activeObject&&(s||!n)){this._setupCurrentTransform(t,e,i);const r=s?s.control:void 0,n=this.getScenePoint(t),o=r&&r.getMouseDownHandler(t,e,r);o&&o.call(r,t,this._currentTransform,n.x,n.y)}}r&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:i}),r&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Ge(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const i=this.getScenePoint(t);e.deltaX=i.x-e.x,e.deltaY=i.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{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 i=this._draggedoverTarget,s=this._hoveredTargets,r=this.targets,n=Math.max(s.length,r.length);this.fireSyntheticInOutEvents("drag",A(A({},e),{},{target:t,oldTarget:i,fireCanvas:!0}));for(let t=0;t<n;t++)this.fireSyntheticInOutEvents("drag",A(A({},e),{},{target:r[t],oldTarget:s[t]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:i,oldTarget:s,fireCanvas:r,e:n}=e,o=F(e,Kn);const{targetIn:a,targetOut:c,canvasIn:h,canvasOut:l}=to[t],u=s!==i;if(s&&u){const t=A(A({},o),{},{e:n,target:s,nextTarget:i},Qn(this,n));r&&this.fire(l,t),s.fire(c,t)}if(i&&u){const t=A(A({},o),{},{e:n,target:i,previousTarget:s},Qn(this,n));r&&this.fire(h,t),i.fire(a,t)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),i=this._currentTransform,s=i.target,r=s.group?Ge(e,void 0,s.group.calcTransformMatrix()):e;i.shiftKey=t.shiftKey,i.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,i,r),i.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,i){const{action:s,actionHandler:r,target:n}=e,o=!!r&&r(t,e,i.x,i.y);o&&n.setCoords(),"drag"===s&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let i=e.hoverCursor||this.hoverCursor;const s=Se(this._activeObject)?this._activeObject:null,r=(!s||e.group!==s)&&e.findControl(this.getViewportPoint(t));if(r){const i=r.control;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=Se(i);if(i&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(i!==e||s)&&(s||!e.isDescendantOf(i)&&!i.isDescendantOf(e))&&!e.onSelect({e:t})&&!i.getActiveControl()){if(s){const s=i.getObjects();if(e===i){const i=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(s,i)||this.searchPossibleTargets(this._objects,i))||!e.selectable)return!1}e.group===i?(i.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],1===i.size()&&this._setActiveObject(i.item(0),t)):(i.multiSelectAdd(e),this._hoveredTarget=i,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(s,t)}else{i.isEditing&&i.exitEditing();const s=new(Et.getClass("ActiveSelection"))([],{canvas:this});s.multiSelectAdd(i,e),this._hoveredTarget=s,this._setActiveObject(s,t),this._fireSelectionEvents([i],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:i,deltaX:s,deltaY:r}=this._groupSelector,n=new It(e,i),o=n.add(new It(s,r)),a=n.min(o),c=n.max(o).subtract(a),h=this.collectObjects({left:a.x,top:a.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),l=n.eq(o)?h[0]?[h[0]]:[]:h.length>1?h.filter((e=>!e.onSelect({e:t}))).reverse():h;if(1===l.length)this.setActiveObject(l[0],t);else if(l.length>1){const e=Et.getClass("ActiveSelection");this.setActiveObject(new e(l,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const io={x1:0,y1:0,x2:0,y2:0},so=A(A({},io),{},{r1:0,r2:0}),ro=(t,e)=>isNaN(t)&&"number"==typeof e?e:t,no=/^(\d+\.\d+)%|(\d+)%$/;function oo(t){return t&&no.test(t)}function ao(t,e){const i="number"==typeof t?t:"string"==typeof t?parseFloat(t)/(oo(t)?100:1):NaN;return $i(0,ro(i,e),1)}const co=/\s*;\s*/,ho=/\s*:\s*/;function lo(t,e){let i,s;const r=t.getAttribute("style");if(r){const t=r.split(co);""===t[t.length-1]&&t.pop();for(let e=t.length;e--;){const[r,n]=t[e].split(ho).map((t=>t.trim()));"stop-color"===r?i=n:"stop-opacity"===r&&(s=n)}}const n=new ui(i||t.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:ao(t.getAttribute("offset"),0),color:n.toRgb(),opacity:ro(parseFloat(s||t.getAttribute("stop-opacity")||""),1)*n.getAlpha()*e}}function uo(t,e){const i=[],s=t.getElementsByTagName("stop"),r=ao(e,1);for(let t=s.length;t--;)i.push(lo(s[t],r));return i}function go(t){return"linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?"linear":"radial"}function fo(t){return"userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage"}function po(t,e){return t.getAttribute(e)}function mo(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&&oo(a)&&(i*=.01,"pixels"===n&&("x1"!==o&&"x2"!==o&&"r2"!==o||(i*=s),"y1"!==o&&"y2"!==o||(i*=r)))),e[o]=i,e}),{})}("linear"===go(t)?function(t){return{x1:po(t,"x1")||0,y1:po(t,"y1")||0,x2:po(t,"x2")||"100%",y2:po(t,"y2")||0}}(t):function(t){return{x1:po(t,"fx")||po(t,"cx")||"50%",y1:po(t,"fy")||po(t,"cy")||"50%",r1:0,x2:po(t,"cx")||"50%",y2:po(t,"cy")||"50%",r2:po(t,"r")||"50%"}}(t),A(A({},e),{},{gradientUnits:fo(t)}))}class vo{constructor(t){const{type:e="linear",gradientUnits:i="pixels",coords:s={},colorStops:r=[],offsetX:n=0,offsetY:o=0,gradientTransform:a,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:i,coords:A(A({},"radial"===e?so:io),s),colorStops:r,offsetX:n,offsetY:o,gradientTransform:a,id:c?"".concat(c,"_").concat(zt()):zt()})}addColorStop(t){for(const e in t){const i=new ui(t[e]);this.colorStops.push({offset:parseFloat(e),color:i.toRgb(),opacity:i.getAlpha()})}return this}toObject(t){return A(A({},me(this,t)),{},{type:this.type,coords:A({},this.coords),colorStops:this.colorStops.map((t=>A({},t))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=[],s=this.gradientTransform?this.gradientTransform.concat():et.concat(),r="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox",n=this.colorStops.map((t=>A({},t))).sort(((t,e)=>t.offset-e.offset));let o=-this.offsetX,a=-this.offsetY;var c;"objectBoundingBox"===r?(o/=t.width,a/=t.height):(o+=t.width/2,a+=t.height/2),(c=t)&&"function"==typeof c._renderPathCommands&&"percentage"!==this.gradientUnits&&(o-=t.pathOffset.x,a-=t.pathOffset.y),s[4]-=o,s[5]-=a;const h=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(r,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(_e(s),'"'),""].join(" ");if("linear"===this.type){const{x1:t,y1:e,x2:s,y2:r}=this.coords;i.push("<linearGradient ",h,' x1="',t,'" y1="',e,'" x2="',s,'" y2="',r,'">\n')}else if("radial"===this.type){const{x1:t,y1:e,x2:s,y2:r,r1:o,r2:a}=this.coords,c=o>a;i.push("<radialGradient ",h,' cx="',c?t:s,'" cy="',c?e:r,'" r="',c?o:a,'" fx="',c?s:t,'" fy="',c?r:e,'">\n'),c&&(n.reverse(),n.forEach((t=>{t.offset=1-t.offset})));const l=Math.min(o,a);if(l>0){const t=l/Math.max(o,a);n.forEach((e=>{e.offset+=t*(1-e.offset)}))}}return n.forEach((t=>{let{color:e,offset:s,opacity:r}=t;i.push("<stop ",'offset="',100*s+"%",'" style="stop-color:',e,void 0!==r?";stop-opacity: "+r:";",'"/>\n')})),i.push("linear"===this.type?"</linearGradient>":"</radialGradient>","\n"),i.join("")}toLive(t){const{x1:e,y1:i,x2:s,y2:r,r1:n,r2:o}=this.coords,a="linear"===this.type?t.createLinearGradient(e,i,s,r):t.createRadialGradient(e,i,n,s,r,o);return this.colorStops.forEach((t=>{let{color:e,opacity:i,offset:s}=t;a.addColorStop(s,void 0!==i?new ui(e).setAlpha(i).toRgba():e)})),a}static async fromObject(t){const{colorStops:e,gradientTransform:i}=t;return new this(A(A({},t),{},{colorStops:e?e.map((t=>A({},t))):void 0,gradientTransform:i?[...i]:void 0}))}static fromElement(t,e,i){const s=fo(t),r=e._findCenterFromElement();return new this(A({id:t.getAttribute("id")||void 0,type:go(t),coords:mo(t,{width:i.viewBoxWidth||i.width,height:i.viewBoxHeight||i.height}),colorStops:uo(t,i.opacity),gradientUnits:s,gradientTransform:Ur(t.getAttribute("gradientTransform")||"")},"pixels"===s?{offsetX:e.width/2-r.x,offsetY:e.height/2-r.y}:{offsetX:0,offsetY:0}))}}P(vo,"type","Gradient"),Et.setClass(vo,"gradient"),Et.setClass(vo,"linear"),Et.setClass(vo,"radial");const yo=["type","source","patternTransform"];class _o{get type(){return"pattern"}set type(t){B("warn","Setting type has no effect",t)}constructor(t){P(this,"repeat","repeat"),P(this,"offsetX",0),P(this,"offsetY",0),P(this,"crossOrigin",""),this.id=zt(),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:i}=this;return A(A({},me(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:i,offsetX:ye(this.offsetX,R.NUM_FRACTION_DIGITS),offsetY:ye(this.offsetY,R.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=ro(this.offsetX/e,0),a=ro(this.offsetY/i,0),c="repeat-y"===r||"no-repeat"===r?1+Math.abs(o||0):ro(s.width/e,0),h="repeat-x"===r||"no-repeat"===r?1+Math.abs(a||0):ro(s.height/i,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(a,'" width="').concat(c,'" height="').concat(h,'">'),'<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{type:i,source:s,patternTransform:r}=t,n=F(t,yo);const o=await ge(s,A(A({},e),{},{crossOrigin:n.crossOrigin}));return new this(A(A({},n),{},{patternTransform:r&&r.slice(0),source:o}))}}P(_o,"type","Pattern"),Et.setClass(_o),Et.setClass(_o,"pattern");class xo{constructor(t){P(this,"color","rgb(0, 0, 0)"),P(this,"width",1),P(this,"shadow",null),P(this,"strokeLineCap","round"),P(this,"strokeLineJoin","round"),P(this,"strokeMiterLimit",10),P(this,"strokeDashArray",null),P(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 ui(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 bo=["path","left","top"],wo=["d"];class So extends nr{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{path:i,left:s,top:r}=e,n=F(e,bo);super(),Object.assign(this,So.ownDefaults),this.setOptions(n),this._setPath(t||[],!0),"number"==typeof s&&this.set(nt,s),"number"==typeof r&&this.set(ot,r)}_setPath(t,e){this.path=Tn(Array.isArray(t)?t:Yn(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new It(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,i=-this.pathOffset.y;t.beginPath();for(const s of this.path)switch(s[0]){case"L":t.lineTo(s[1]+e,s[2]+i);break;case"M":t.moveTo(s[1]+e,s[2]+i);break;case"C":t.bezierCurveTo(s[1]+e,s[2]+i,s[3]+e,s[4]+i,s[5]+e,s[6]+i);break;case"Q":t.quadraticCurveTo(s[1]+e,s[2]+i,s[3]+e,s[4]+i);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return A(A({},super.toObject(t)),{},{path:this.path.map((t=>t.slice()))})}toDatalessObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=Hn(this.path,R.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,'" stroke-linecap="round" />\n')]}_getOffsetTransform(){const t=R.NUM_FRACTION_DIGITS;return" translate(".concat(ye(-this.pathOffset.x,t),", ").concat(ye(-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,rt,rt)}_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({x:e,y:i},{x:s,y:r});break;case"M":s=n[1],r=n[2],e=s,i=r;break;case"C":t.push(...Sn(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(...Sn(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 Re(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return A(A({},t),{},{pathOffset:new It(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i),{d:r}=s;return new this(r,A(A(A({},F(s,wo)),e),{},{left:void 0,top:void 0}))}}P(So,"type","Path"),P(So,"cacheProperties",[...es,"path","fillRule"]),P(So,"ATTRIBUTE_NAMES",[...wr,"d"]),Et.setClass(So),Et.setSVGClass(So);class Co extends xo{constructor(t){super(t),P(this,"decimate",.4),P(this,"drawStraightLine",!1),P(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=Co.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++)Co.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 Wn(t,e)}createPath(t){const e=new So(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 Zi(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"===Hn(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 To=["left","top","radius"],Oo=["radius","startAngle","endAngle","counterClockwise"];class ko extends nr{static getDefaults(){return A(A({},super.getDefaults()),ko.ownDefaults)}constructor(t){super(),Object.assign(this,ko.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),"radius"===t&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,Jt(this.startAngle),Jt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(bt)}getRadiusY(){return this.get("radius")*this.get(wt)}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([...Oo,...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=Jt(this.startAngle),s=Jt(this.endAngle),r=Ft(i)*e,n=Lt(i)*e,o=Ft(s)*e,a=Lt(s)*e,c=t>180?1:0,h=this.counterClockwise?0:1;return['<path d="M '.concat(r," ").concat(n," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(h," ").concat(o," ").concat(a,'" '),"COMMON_PARTS"," />\n"]}}static async fromElement(t,e,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i),{left:r=0,top:n=0,radius:o=0}=s;return new this(A(A({},F(s,To)),{},{radius:o,left:r-o,top:n-o}))}static fromObject(t){return super._fromObject(t)}}P(ko,"type","Circle"),P(ko,"cacheProperties",[...es,...Oo]),P(ko,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),P(ko,"ATTRIBUTE_NAMES",["cx","cy","r",...wr]),Et.setClass(ko),Et.setSVGClass(ko);const Do=["x1","y1","x2","y2"],Mo=["x1","y1","x2","y2"],Eo=["x1","x2","y1","y2"];class Po extends nr{constructor(){let[t,e,i,s]=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0,0,0],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,Po.ownDefaults),this.setOptions(r),this.x1=t,this.x2=i,this.y1=e,this.y2=s,this._setWidthHeight();const{left:n,top:o}=r;"number"==typeof n&&this.set(nt,n),"number"==typeof o&&this.set(ot,o)}_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}=Re([{x:t,y:e},{x:i,y:s}]),c=new It(r+o/2,n+a/2);this.setPositionByOrigin(c,rt,rt)}_set(t,e){return super._set(t,e),Eo.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;xe(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 It((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return A(A({},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=Jr(t,this.ATTRIBUTE_NAMES,i),{x1:r=0,y1:n=0,x2:o=0,y2:a=0}=s;return new this([r,n,o,a],F(s,Do))}static fromObject(t){let{x1:e,y1:i,x2:s,y2:r}=t,n=F(t,Mo);return this._fromObject(A(A({},n),{},{points:[e,i,s,r]}),{extraParam:"points"})}}P(Po,"type","Line"),P(Po,"cacheProperties",[...es,...Eo]),P(Po,"ATTRIBUTE_NAMES",wr.concat(Eo)),Et.setClass(Po),Et.setSVGClass(Po);class jo extends nr{static getDefaults(){return A(A({},super.getDefaults()),jo.ownDefaults)}constructor(t){super(),Object.assign(this,jo.ownDefaults),this.setOptions(t)}_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),'" />']}}P(jo,"type","Triangle"),P(jo,"ownDefaults",{width:100,height:100}),Et.setClass(jo),Et.setSVGClass(jo);const Ao=["rx","ry"];class Fo extends nr{static getDefaults(){return A(A({},super.getDefaults()),Fo.ownDefaults)}constructor(t){super(),Object.assign(this,Fo.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(bt)}getRy(){return this.get("ry")*this.get(wt)}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...Ao,...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,$,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,i){const s=Jr(t,this.ATTRIBUTE_NAMES,i);return s.left=(s.left||0)-s.rx,s.top=(s.top||0)-s.ry,new this(s)}}P(Fo,"type","Ellipse"),P(Fo,"cacheProperties",[...es,...Ao]),P(Fo,"ownDefaults",{rx:0,ry:0}),P(Fo,"ATTRIBUTE_NAMES",[...wr,"cx","cy","rx","ry"]),Et.setClass(Fo),Et.setSVGClass(Fo);const Lo=["left","top"],Io={exactBoundingBox:!1};class Ro extends nr{static getDefaults(){return A(A({},super.getDefaults()),Ro.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),P(this,"strokeDiff",void 0),Object.assign(this,Ro.ownDefaults),this.setOptions(e),this.points=t;const{left:i,top:s}=e;this.initialized=!0,this.setBoundingBox(!0),"number"==typeof i&&this.set(nt,i),"number"==typeof s&&this.set(ot,s)}isOpen(){return!0}_projectStrokeOnPoints(t){return ur(this.points,t,this.isOpen())}_calcDimensions(t){t=A({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 It,strokeOffset:new It,strokeDiff:new It};const i=Re(e),s=ue(A(A({},t),{},{scaleX:1,scaleY:1})),r=Re(this.points.map((t=>$t(t,s,!0)))),n=new It(this.scaleX,this.scaleY);let o=i.left+i.width/2,a=i.top+i.height/2;return this.exactBoundingBox&&(o-=a*Math.tan(Jt(this.skewX)),a-=o*Math.tan(Jt(this.skewY))),A(A({},i),{},{pathOffset:new It(o,a),strokeOffset:new It(r.left,r.top).subtract(new It(i.left,i.top)).multiply(n),strokeDiff:new It(i.width,i.height).subtract(new It(r.width,r.height)).multiply(n)})}_findCenterFromElement(){const t=Re(this.points);return new It(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 It(e+s/2,i+r/2),rt,rt)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new It(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 It(null!==(e=t.width)&&void 0!==e?e:s,null!==(i=t.height)&&void 0!==i?i:r)}else{var s,r;n=new It(null!==(s=t.width)&&void 0!==s?s:this.width,null!==(r=t.height)&&void 0!==r?r:this.height)}return n.multiply(new It(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&&((t===bt||t===wt)&&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 A(A({},super.toObject(t)),{},{points:this.points.map((t=>{let{x:e,y:i}=t;return{x:e,y:i}}))})}_toSVG(){const t=[],e=this.pathOffset.x,i=this.pathOffset.y,s=R.NUM_FRACTION_DIGITS;for(let r=0,n=this.points.length;r<n;r++)t.push(ye(this.points[r].x-e,s),",",ye(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,i){return new this(function(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}(t.getAttribute("points")),A(A({},F(Jr(t,this.ATTRIBUTE_NAMES,i),Lo)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}P(Ro,"ownDefaults",Io),P(Ro,"type","Polyline"),P(Ro,"layoutProperties",[St,Ct,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),P(Ro,"cacheProperties",[...es,"points"]),P(Ro,"ATTRIBUTE_NAMES",[...wr]),Et.setClass(Ro),Et.setSVGClass(Ro);class Bo extends Ro{isOpen(){return!1}}P(Bo,"ownDefaults",Io),P(Bo,"type","Polygon"),Et.setClass(Bo),Et.setSVGClass(Bo);class Xo extends nr{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 c=e[o][a]||{};r++,void 0!==c[t]?(s?c[t]!==s&&(n=!1):s=c[t],c[t]===this[t]&&delete c[t]):n=!1,0!==Object.keys(c).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);const r=ve(A(A({},this._getStyleDeclaration(i,s)),e),(t=>void 0!==t));this._setStyleDeclaration(i,s,r)}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 A(A({},me(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]}}P(Xo,"_styleProperties",wi);const Vo=/ +/g,Yo=/"/g;function Wo(t,e,i,s,r){return"\t\t".concat(function(t,e){let{left:i,top:s,width:r,height:n}=e,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:R.NUM_FRACTION_DIGITS;const a=fi(Tt,t,!1),[c,h,l,u]=[i,s,r,n].map((t=>ye(t,o)));return"<rect ".concat(a,' x="').concat(c,'" y="').concat(h,'" width="').concat(l,'" height="').concat(u,'"></rect>')}(t,{left:e,top:i,width:s,height:r}),"\n")}const Ho=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let zo;class Go extends Xo{static getDefaults(){return A(A({},super.getDefaults()),Go.ownDefaults)}constructor(t,e){super(),P(this,"__charBounds",[]),Object.assign(this,Go.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Ln(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(Ci)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,r,n,o;for(let a=0,c=this._textLines.length;a<c;a++)if((this.textAlign===Ci||a!==c-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){this.paintFirst===Ot?(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 rt:t.textBaseline="middle";break;case"ascender":t.textBaseline=ot;break;case"descender":t.textBaseline=at}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,c,h=0,l=0,u=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let d=0;d<n;d++){const n=this.__charBounds[e][d];c=this.getValueOfPropertyAt(e,d,"textBackgroundColor"),this.path?(t.save(),t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillStyle=c,c&&t.fillRect(-n.width/2,-r/this.lineHeight*(1-this._fontSizeFraction),n.width,r/this.lineHeight),t.restore()):c!==u?(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-h),t.fillStyle=u,u&&t.fillRect(a,s,h,r/this.lineHeight),l=n.left,h=n.width,u=c):h+=n.kernedWidth}c&&!this.path&&(a=i+o+l,"rtl"===this.direction&&(a=this.width-a-h),t.fillStyle=c,t.fillRect(a,s,h,r/this.lineHeight)),s+=r}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,s){const r=K.getFontCache(e),n=this._getFontDeclaration(e),o=i+t,a=i&&n===this._getFontDeclaration(s),c=e.fontSize/this.CACHE_FONT_SIZE;let h,l,u,d;if(i&&void 0!==r[i]&&(u=r[i]),void 0!==r[t]&&(d=h=r[t]),a&&void 0!==r[o]&&(l=r[o],d=l-u),void 0===h||void 0===u||void 0===l){const s=function(){if(!zo){const t=Ut({width:0,height:0});zo=t.getContext("2d")}return zo}();this._setTextStyles(s,e,!0),void 0===h&&(d=h=s.measureText(t).width,r[t]=h),void 0===u&&a&&i&&(u=s.measureText(i).width,r[i]=u),a&&void 0===l&&(l=s.measureText(o).width,r[o]=l,d=l-u)}return{width:h*c,kernedWidth:d*c}}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===ct,n=this.path,o=this._textLines[t],a=o.length,c=new Array(a);this.__charBounds[t]=c;for(let r=0;r<a;r++){const n=o[r];i=this._getGraphemeBox(n,t,r,e),c[r]=i,s+=i.kernedWidth,e=n}if(c[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 nt:t=r?e-s:0;break;case rt:t=(e-s)/2;break;case ct: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=c[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=In(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===ct?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 c,h=a.kernedWidth,l=a.width;0!==this.charSpacing&&(c=this._getWidthOfCharSpacing(),l+=c,h+=c);const u={width:l,left:0,height:n.fontSize,kernedWidth:h,deltaY:n.deltaY};if(i>0&&!r){const t=this.__charBounds[e][i-1];u.left=t.left+t.width+a.kernedWidth-a.width}return u}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let 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,c=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],s+c,r+i+a,n),i+=o}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(Tt))&&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(Ci),c=this.path,h=!a&&0===this.charSpacing&&this.isEmptyStyles(n)&&!c,l="ltr"===this.direction,u="ltr"===this.direction?1:-1,d=e.direction;let g,f,p,m,v,y="",_=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",l?"ltr":"rtl"),e.direction=l?"ltr":"rtl",e.textAlign=l?nt:ct),r-=o*this._fontSizeFraction/this.lineHeight,h)return this._renderChar(t,e,n,0,i.join(""),s,r),void e.restore();for(let o=0,h=i.length-1;o<=h;o++)m=o===h||this.charSpacing||c,y+=i[o],p=this.__charBounds[n][o],0===_?(s+=u*(p.kernedWidth-p.width),_+=p.width):_+=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=_r(g,f,!1)),m&&(c?(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,y,v,r)),y="",g=f,s+=u*_,_=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,i=this.height+this.strokeWidth,s=Ut({width:e,height:i}),r=s.getContext("2d");return s.width=e,s.height=i,r.beginPath(),r.moveTo(0,0),r.lineTo(e,0),r.lineTo(e,i),r.lineTo(0,i),r.closePath(),r.translate(e/2,i/2),r.fillStyle=t.toLive(r),this._applyPatternGradientTransform(r,t),r.fill(),r.createPattern(s,"no-repeat")}handleFiller(t,e,i){let s,r;return xe(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),c=this.getCompleteStyleDeclaration(i,s),h="fillText"===t&&c.fill,l="strokeText"===t&&c.stroke&&c.strokeWidth;if(l||h){if(e.save(),e.font=this._getFontDeclaration(c),a.textBackgroundColor&&this._removeShadow(e),a.deltaY&&(o+=a.deltaY),h){const t=this._setFillStyles(e,c);e.fillText(r,n-t.offsetX,o-t.offsetY)}if(l){const t=this._setStrokeStyles(e,c);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===Ci||s===ki&&!n||s===Oi&&!n||s===Ti&&!n?0:(s===rt&&(o=i/2),s===ct&&(o=i),s===ki&&(o=i/2),s===Oi&&(o=i),"rtl"===r&&(s===ct||s===Ci||s===Oi?o=0:s===nt||s===Ti?o=-i:s!==rt&&s!==ki||(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="linethrough"===e?.5:"overline"===e?1:0,a=this.offsets[e];for(let c=0,h=this._textLines.length;c<h;c++){const h=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){i+=h;continue}const l=this._textLines[c],u=h/this.lineHeight,d=this._getLineLeftOffset(c);let g=0,f=0,p=this.getValueOfPropertyAt(c,0,e),m=this.getValueOfPropertyAt(c,0,Tt),v=this.getValueOfPropertyAt(c,0,vi),y=p,_=m,x=v;const b=i+u*(1-this._fontSizeFraction);let w=this.getHeightOfChar(c,0),S=this.getValueOfPropertyAt(c,0,"deltaY");for(let i=0,n=l.length;i<n;i++){const n=this.__charBounds[c][i];y=this.getValueOfPropertyAt(c,i,e),_=this.getValueOfPropertyAt(c,i,Tt),x=this.getValueOfPropertyAt(c,i,vi);const h=this.getHeightOfChar(c,i),l=this.getValueOfPropertyAt(c,i,"deltaY");if(r&&y&&_){const e=this.fontSize*x/1e3;t.save(),t.fillStyle=m,t.translate(n.renderLeft,n.renderTop),t.rotate(n.angle),t.fillRect(-n.kernedWidth/2,a*h+l-o*e,n.kernedWidth,e),t.restore()}else if((y!==p||_!==m||h!==w||x!==v||l!==S)&&f>0){const e=this.fontSize*v/1e3;let i=s+d+g;"rtl"===this.direction&&(i=this.width-i-f),p&&m&&v&&(t.fillStyle=m,t.fillRect(i,b+a*w+S-o*e,f,e)),g=n.left,f=n.width,p=y,v=x,m=_,w=h,S=l}else f+=n.kernedWidth}let C=s+d+g;"rtl"===this.direction&&(C=this.width-C-f),t.fillStyle=_;const T=this.fontSize*x/1e3;y&&_&&x&&t.fillRect(C,b+a*w+S-o*T,f-n,T),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(",")||Go.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 pr(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 A(A({},super.toObject([...bi,...t])),{},{styles:xr(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,i){const s=Jr(t,Go.ATTRIBUTE_NAMES,i),r=A(A({},e),s),{textAnchor:n=nt,textDecoration:o="",dx:a=0,dy:c=0,top:h=0,left:l=0,fontSize:u=it,strokeWidth:d=1}=r,g=F(r,Ho),f=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),A({left:l+a,top:h+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:u},g)),p=f.getScaledHeight()/f.height,m=((f.height+f.strokeWidth)*f.lineHeight-f.height)*p,v=f.getScaledHeight()+m;let y=0;return n===rt&&(y=f.getScaledWidth()/2),n===ct&&(y=f.getScaledWidth()),f.set({left:f.left-y,top:f.top-(v-f.fontSize*(.07+f._fontSizeFraction))/f.lineHeight,strokeWidth:d}),f}static fromObject(t){return this._fromObject(A(A({},t),{},{styles:br(t.styles||{},t.text)}),{extraParam:"text"})}}P(Go,"textLayoutProperties",xi),P(Go,"cacheProperties",[...es,...bi]),P(Go,"ownDefaults",Si),P(Go,"type","Text"),P(Go,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),P(Go,"ATTRIBUTE_NAMES",wr.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),rr(Go,[class extends pi{_toSVG(){const t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)}toSVG(t){const e=this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0}),i=this.path;return i?e+i._createBaseSVGMarkup(i._toSVG(),{reviver:t,withShadow:!0,additionalTransform:_e(this.calcOwnMatrix())}):e}_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" ','font-family="'.concat(this.fontFamily.replace(Yo,"'"),'" '),'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(...Wo(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,r){const n=R.NUM_FRACTION_DIGITS,o=this.getSvgSpanStyles(e,t!==t.trim()||!!t.match(Vo)),a=o?'style="'.concat(o,'"'):"",c=e.deltaY,h=c?' dy="'.concat(ye(c,n),'" '):"",{angle:l,renderLeft:u,renderTop:d,width:g}=r;let f="";if(void 0!==u){const t=g/2;l&&(f=' rotate="'.concat(ye(Qt(l),n),'"'));const e=oe({angle:Qt(l)});e[4]=u,e[5]=d;const r=new It(-t,0).transform(e);i=r.x,s=r.y}return'<tspan x="'.concat(ye(i,n),'" y="').concat(ye(s,n),'" ').concat(h).concat(f).concat(a,">").concat(gr(t),"</tspan>")}_setSVGTextLineText(t,e,i,s){const r=this.getHeightOfLine(e),n=this.textAlign.includes(Ci),o=this._textLines[e];let a,c,h,l,u,d="",g=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let r=0,f=o.length-1;r<=f;r++)u=r===f||this.charSpacing||this.path,d+=o[r],h=this.__charBounds[e][r],0===g?(i+=h.kernedWidth-h.width,g+=h.width):g+=h.kernedWidth,n&&!u&&this._reSpaceAndTab.test(o[r])&&(u=!0),u||(a=a||this.getCompleteStyleDeclaration(e,r),c=this.getCompleteStyleDeclaration(e,r+1),u=_r(a,c,!0)),u&&(l=this._getStyleDeclaration(e,r),t.push(this._createTextCharSpan(d,l,i,s,h)),d="",a=c,"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,c=0,h=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let l=0;l<r.length;l++){const{left:r,width:u,kernedWidth:d}=this.__charBounds[e][l];o=this.getValueOfPropertyAt(e,l,"textBackgroundColor"),o!==h?(h&&t.push(...Wo(h,i+c,s,a,n)),c=r,a=u,h=o):a+=d}o&&t.push(...Wo(h,i+c,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)," text-decoration-thickness: ").concat(ye(this.textDecorationThickness*this.getObjectScaling().y/10,R.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(t,e){const{fontFamily:i,strokeWidth:s,stroke:r,fill:n,fontSize:o,fontStyle:a,fontWeight:c,deltaY:h,textDecorationThickness:l,linethrough:u,overline:d,underline:g}=t,f=this.getSvgTextDecoration({underline:null!=g?g:this.underline,overline:null!=d?d:this.overline,linethrough:null!=u?u:this.linethrough}),p=l||this.textDecorationThickness;return[r?fi(Ot,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,"; "):"",c?"font-weight: ".concat(c,"; "):"",f?"text-decoration: ".concat(f,"; text-decoration-thickness: ").concat(ye(p*this.getObjectScaling().y/10,R.NUM_FRACTION_DIGITS),"%; "):"",n?fi(Tt,n):"",h?"baseline-shift: ".concat(-h,"; "):"",e?"white-space: pre; ":""].join("")}getSvgTextDecoration(t){return["overline","underline","line-through"].filter((e=>t[e.replace("-","")])).join(" ")}}]),Et.setClass(Go),Et.setSVGClass(Go);class No{constructor(t){P(this,"target",void 0),P(this,"__mouseDownInPlace",!1),P(this,"__dragStartFired",!1),P(this,"__isDraggingOver",!1),P(this,"__dragStartSelection",void 0),P(this,"__dragImageDisposer",void 0),P(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 It(n.flipX?-1:1,n.flipY?-1:1),c=n._getCursorBoundaries(s),h=new It(c.left+c.leftOffset,c.top+c.topOffset).multiply(a).transform(n.calcTransformMatrix()),l=o.getScenePoint(t).subtract(h),u=n.getCanvasRetinaScaling(),d=n.getBoundingRect(),g=h.subtract(new It(d.left,d.top)),f=o.viewportTransform,p=g.add(l).transform(f,!0),m=n.backgroundColor,v=dr(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 _=n.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});n.backgroundColor=m,n.styles=v,n.dirty=!0,zn(_,{position:"fixed",left:"".concat(-_.width,"px"),border:ht,width:"".concat(_.width/u,"px"),height:"".concat(_.height/u,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{_.remove()},Te(t.target||this.target.hiddenTextarea).body.appendChild(_),null===(i=t.dataTransfer)||void 0===i||i.setDragImage(_,p.x,p.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,i=this.isActive();if(i&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},s=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=A({text:e.text,value:s},i);t.dataTransfer.setData("text/plain",s),t.dataTransfer.setData("application/fabric",JSON.stringify({value:s,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),i}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){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)],c=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+c,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(_t,{index:n+c,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)||ht;o===ht?(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(_t,{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 Uo=/[ \n\.,;!\?\-]/;class qo extends Go{constructor(){super(...arguments),P(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 _s({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:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;null===(t=this._currentTickCompleteState)||void 0===t||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,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||!lt.test(i[t-1]))?t-1:t,r=i[s];for(;s>0&&s<i.length&&!Uo.test(r);)s+=e,r=i[s];return-1===e&&Uo.test(r)&&s++,s}selectWord(t){var e;t=null!==(e=t)&&void 0!==e?e:this.selectionStart;const i=this.searchWordBoundary(t,-1),s=Math.max(i,this.searchWordBoundary(t,1));this.selectionStart=i,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=null!==(e=t)&&void 0!==e?e:this.selectionStart;const i=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);this.selectionStart=i,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Te(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;return t===e?{selectionStart:s,selectionEnd:s}:{selectionStart:s,selectionEnd:s+i.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){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(),c=this.canvas.upperCanvasEl,h=c.width/a,l=c.height/a,u=h-n,d=l-n,g=new It(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new It(c.clientWidth/h,c.clientHeight/l));return g.x<0&&(g.x=0),g.x>u&&(g.x=u),g.y<0&&(g.y=0),g.y>d&&(g.y=d),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(kt),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,i,s){const r={},n=this._unwrappedTextLines[t].length,o=n===e;let a=!1;i||(i=1),this.shiftLineStyles(t,i);const c=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,r[s-e]=this.styles[t][i],o&&0===e||delete this.styles[t][i])}let h=!1;for(a&&!o&&(this.styles[t+i]=r,h=!0),(h||n>e)&&i--;i>0;)s&&s[i-1]?this.styles[t+i]={0:A({},s[i-1])}:c?this.styles[t+i]={0:A({},c)}:delete this.styles[t+i],i--;this._forceClearCache=!0}insertCharStyleObject(t,e,i,s){this.styles||(this.styles={});const r=this.styles[t],n=r?A({},r):{};i||(i=1);for(const t in n){const s=parseInt(t,10);s>=e&&(r[s+i]=n[s],n[s-i]||delete r[s])}if(this._forceClearCache=!0,s){for(;i--;)Object.keys(s[i]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+i]=A({},s[i]));return}if(!r)return;const o=r[e?e-1:1];for(;o&&i--;)this.styles[t][e+i]=A({},o)}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=nt:this._selectionDirection===ct&&(this._selectionDirection=nt,this.selectionEnd=t),this.selectionStart=i):i>t&&i<e?this._selectionDirection===ct?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection=ct:this._selectionDirection===nt&&(this._selectionDirection=ct,this.selectionStart=e),this.selectionEnd=i)}}class Ko extends qo{initHiddenTextarea(){const t=this.canvas&&Te(this.canvas.getElement())||N(),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",compositionend:"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,{value:i,selectionStart:s,selectionEnd:r}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const n=()=>{this.updateFromTextArea(),this.fire(_t),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(""===this.hiddenTextarea.value)return this.styles={},void n();const o=this._splitTextIntoLines(i).graphemeText,a=this._text.length,c=o.length,h=this.selectionStart,l=this.selectionEnd,u=h!==l;let d,g,f,p,m=c-a;const v=this.fromStringToGraphemeSelection(s,r,i),y=h>v.selectionStart;u?(g=this._text.slice(h,l),m+=l-h):c<a&&(g=y?this._text.slice(l+m,l):this._text.slice(h,h-m));const _=o.slice(v.selectionEnd-m,v.selectionEnd);if(g&&g.length&&(_.length&&(d=this.getSelectionStyles(h,h+1,!1),d=_.map((()=>d[0]))),u?(f=h,p=l):y?(f=l-g.length,p=l):(f=l,p=l+g.length),this.removeStyleFromTo(f,p)),_.length){const{copyPasteData:t}=G();e&&_.join("")===t.copiedText&&!R.disableStyleCopyPaste&&(d=t.copiedTextStyle),this.insertNewStyleBlock(_,h,d)}n()}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}=G();t.copiedText=this.getSelectedText(),R.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),c=this._textLines[r].slice(0,n),h=this.missingNewlineOffset(r-1);return-this._textLines[r-1].length+a-c.length+(1-h)}_getIndexOnLine(t,e){const i=this._textLines[t];let s,r,n=this._getLineLeftOffset(t),o=0;for(let a=0,c=i.length;a<c;a++)if(s=this.__charBounds[t][a].width,n+=s,n>e){r=!0;const t=n-s,i=n,c=Math.abs(t-e);o=Math.abs(i-e)<c?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===ct);if(e.shiftKey?this.moveCursorWithShift(i):this.moveCursorWithoutShift(i),0!==i){const t=this.text.length;this.selectionStart=$i(0,this.selectionStart,t),this.selectionEnd=$i(0,this.selectionEnd,t),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===nt?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=nt,this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===ct&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection=nt,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===nt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=ct,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=ct,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Jo=t=>!!t.button;class Qo extends Ko{constructor(){super(...arguments),P(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new No(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e:e,alreadySelected:i}=t;this.canvas&&this.editable&&!Jo(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),i&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=i||this.isEditing)))}mouseUpHandler(t){let{e:e,transform:i}=t;const s=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||Jo(e)||s||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}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.getScenePoint(t).transform(te(this.calcTransformMatrix())).add(new It(-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 Zo="moveCursorUp",$o="moveCursorDown",ta="moveCursorLeft",ea="moveCursorRight",ia="exitEditing",sa=(t,e)=>{const i=e.getRetinaScaling();t.setTransform(i,0,0,i,0,0);const s=e.viewportTransform;t.transform(s[0],s[1],s[2],s[3],s[4],s[5])},ra=A({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:ia,27:ia,33:Zo,34:$o,35:ea,36:ta,37:ta,38:Zo,39:ea,40:$o},keysMapRtl:{9:ia,27:ia,33:Zo,34:$o,35:ta,36:ea,37:ea,38:Zo,39:ta,40:$o},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class na extends Qo{static getDefaults(){return A(A({},super.getDefaults()),na.ownDefaults)}get type(){const t=super.type;return"itext"===t?"i-text":t}constructor(t,e){super(t,A(A({},na.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):("canvas"===t&&(this.canvas instanceof eo&&this.canvas.textEditingManager.remove(this),e instanceof eo&&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||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),i=this.findAncestorsWithClipPath(),s=i.length>0;let r,n=t;if(s){r=Ut(t.canvas),n=r.getContext("2d"),sa(n,this.canvas);const e=this.calcTransformMatrix();n.transform(e[0],e[1],e[2],e[3],e[4],e[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(n,e):this.renderCursor(n,e),s)for(const e of i){const i=e.clipPath,s=Ut(t.canvas),r=s.getContext("2d");if(sa(r,this.canvas),!i.absolutePositioned){const t=e.calcTransformMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5])}i.transform(r),i.drawObject(r,!0,{}),this.drawClipPathOnCache(n,i,s)}s&&(t.setTransform(1,0,0,1,0,0),t.drawImage(r,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_getCursorBoundaries(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const 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===ct||this.textAlign===Ci||this.textAlign===Oi?a.left*=-1:this.textAlign===nt||this.textAlign===Ti?a.left=n-(i>0?i:0):this.textAlign!==rt&&this.textAlign!==ki||(a.left=n-(i>0?i:0))),a}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.selectionStart,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._getCursorBoundaries(t);const i=this.get2DCursorLocation(t),s=i.lineIndex,r=i.charIndex>0?i.charIndex-1:0,n=this.getValueOfPropertyAt(s,r,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),a=this.cursorWidth/o,c=this.getValueOfPropertyAt(s,r,"deltaY"),h=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(s)/this.lineHeight-n*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(s,r,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-a/2,top:h+e.top+c,width:a,height:n}}_renderCursor(t,e,i){const{color:s,opacity:r,left:n,top:o,width:a,height:c}=this.getCursorRenderingData(i,e);t.fillStyle=s,t.globalAlpha=r,t.fillRect(n,o,a,c)}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(Ci),o=this.get2DCursorLocation(s),a=this.get2DCursorLocation(r),c=o.lineIndex,h=a.lineIndex,l=o.charIndex<0?0:o.charIndex,u=a.charIndex<0?0:a.charIndex;for(let e=c;e<=h;e++){const s=this._getLineLeftOffset(e)||0;let r=this.getHeightOfLine(e),o=0,a=0,d=0;if(e===c&&(a=this.__charBounds[c][l].left),e>=c&&e<h)d=n&&!this.isEndOfWrapping(e)?this.width:this.getLineWidth(e)||5;else if(e===h)if(0===u)d=this.__charBounds[h][u].left;else{const t=this._getWidthOfCharSpacing();d=this.__charBounds[h][u-1].left+this.__charBounds[h][u-1].width-t}o=r,(this.lineHeight<1||e===h&&this.lineHeight>1)&&(r/=this.lineHeight);let g=i.left+s+a,f=r,p=0;const m=d-a;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",f=1,p=r):t.fillStyle=this.selectionColor,"rtl"===this.direction&&(this.textAlign===ct||this.textAlign===Ci||this.textAlign===Oi?g=this.width-g-m:this.textAlign===nt||this.textAlign===Ti?g=i.left+s-d:this.textAlign!==rt&&this.textAlign!==ki||(g=i.left+s-d)),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,Tt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}P(na,"ownDefaults",ra),P(na,"type","IText"),Et.setClass(na),Et.setClass(na,"i-text");class oa extends na{static getDefaults(){return A(A({},super.getDefaults()),oa.ownDefaults)}constructor(t,e){super(t,A(A({},oa.ownDefaults),e))}static createControls(){return{controls:ir()}}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(Ci)&&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];super._setStyleDeclaration(s.line,s.offset+e,i)}_deleteStyleDeclaration(t,e){const i=this._styleMap[t];super._deleteStyleDeclaration(i.line,i.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const 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,!0).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,c=[],h=a?"":" ";let l=0,u=[],d=0,g=0,f=!0;e-=n;const p=Math.max(e,s,this.dynamicMinWidth),m=r[t];let v;for(d=0,v=0;v<m.length;v++){const{word:e,width:i}=m[v];d+=e.length,l+=g+i-o,l>p&&!f?(c.push(u),u=[],l=i,f=!0):l+=o,f||a||u.push(h),u=u.concat(e),g=a?0:this._measureWord([h],t,d),d++,f=!1}return v&&c.push(u),s+n>this.dynamicMinWidth&&(this.dynamicMinWidth=s-o+n),c}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])}}P(oa,"type","Textbox"),P(oa,"textLayoutProperties",[...na.textLayoutProperties,"width"]),P(oa,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),Et.setClass(oa);class aa extends on{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:i}=t,{clipPath:s,group:r}=i;if(!s||!this.shouldPerformLayout(t))return;const{width:n,height:o}=Re(nn(i,s)),a=new It(n,o);if(s.absolutePositioned)return{center:Ge(s.getRelativeCenterPoint(),void 0,r?r.calcTransformMatrix():void 0),size:a};{const r=s.getRelativeCenterPoint().transform(i.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:i=new It,correction:s=new It}=this.calcBoundingBox(e,t)||{};return{center:i.add(r),correction:s.subtract(r),size:a}}return{center:i.getRelativeCenterPoint().add(r),size:a}}}}P(aa,"type","clip-path"),Et.setClass(aa);class ca extends on{getInitialSize(t,e){let{target:i}=t,{size:s}=e;return new It(i.width||s.x,i.height||s.y)}}P(ca,"type","fixed"),Et.setClass(ca);class ha extends un{subscribeTargets(t){const e=t.target;t.targets.reduce(((t,e)=>(e.parent&&t.add(e.parent),t)),new Set).forEach((t=>{t.layoutManager.subscribeTargets({target:t,targets:[e]})}))}unsubscribeTargets(t){const e=t.target,i=e.getObjects();t.targets.reduce(((t,e)=>(e.parent&&t.add(e.parent),t)),new Set).forEach((t=>{!i.some((e=>e.parent===t))&&t.layoutManager.unsubscribeTargets({target:t,targets:[e]})}))}}class la extends fn{static getDefaults(){return A(A({},super.getDefaults()),la.ownDefaults)}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),Object.assign(this,la.ownDefaults),this.setOptions(e);const{left:i,top:s,layoutManager:r}=e;this.groupInit(t,{left:i,top:s,layoutManager:null!=r?r:new ha})}_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)}))}canEnterGroup(t){return this.getObjects().some((e=>e.isDescendantOf(t)||t.isDescendantOf(e)))?(B("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const i=new Set;e.forEach((t=>{const{parent:e}=t;e&&i.add(e)})),t===sn?i.forEach((t=>{t._onAfterObjectsChange(en,e)})):i.forEach((t=>{t._set("dirty",!0)}))}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,i){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const s=A(A({hasControls:!1},i),{},{forActiveSelection:!0});for(let e=0;e<this._objects.length;e++)this._objects[e]._renderControls(t,s);super._renderControls(t,e),t.restore()}}P(la,"type","ActiveSelection"),P(la,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),Et.setClass(la),Et.setClass(la,"activeSelection");class ua{constructor(){P(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 da{constructor(){let{tileSize:t=R.textureSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};P(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),P(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const i=Ut({width:t,height:e}),s=i.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});s&&(s.clearColor(0,0,0,0),this.canvas=i,this.gl=s)}applyFilters(t,e,i,s,r,n){const o=this.gl,a=r.getContext("2d");if(!o||!a)return;let c;n&&(c=this.getCachedTexture(n,e));const h={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:i,sourceHeight:s,destinationWidth:i,destinationHeight:s,context:o,sourceTexture:this.createTexture(o,i,s,c?void 0:e),targetTexture:this.createTexture(o,i,s),originalTexture:c||this.createTexture(o,i,s,c?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(h)})),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)}(h),this.copyGLTo2D(o,h),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(h.sourceTexture),o.deleteTexture(h.targetTexture),o.deleteFramebuffer(l),a.setTransform(1,0,0,1,0,0),h}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:c,CLAMP_TO_EDGE:h,TEXTURE_MAG_FILTER:l,TEXTURE_MIN_FILTER:u,TEXTURE_WRAP_S:d,TEXTURE_WRAP_T:g}=t,f=t.createTexture();return t.bindTexture(o,f),t.texParameteri(o,l,r||n),t.texParameteri(o,u,r||n),t.texParameteri(o,d,h),t.texParameteri(o,g,h),s?t.texImage2D(o,0,a,a,c,s):t.texImage2D(o,0,a,e,i,0,a,c,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)}copyGLTo2DPutImageData(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 c=new ImageData(a,s,r);i.putImageData(c,0,0)}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}}let ga;function fa(){return!ga&&(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(ga=function(){const{WebGLProbe:t}=G();return t.queryWebGL(Gt()),R.enableGLFiltering&&t.isSupported(R.textureSize)?new da({tileSize:R.textureSize}):new ua}()),ga}const pa=["filters","resizeFilter","src","crossOrigin","type"],ma=["cropX","cropY"];class va extends nr{static getDefaults(){return A(A({},super.getDefaults()),va.ownDefaults)}constructor(t,e){super(),P(this,"_lastScaleX",1),P(this,"_lastScaleY",1),P(this,"_filterScalingX",1),P(this,"_filterScalingY",1),this.filters=[],Object.assign(this,va.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(zt()),this.setElement("string"==typeof t?(this.canvas&&Te(this.canvas.getElement())||N()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let i=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(i),null===(e=t.classList)||void 0===e||e.add(va.CSS_CANVAS),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=fa(!1);e instanceof da&&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&&G().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())})),A(A({},super.toObject([...ma,...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=zt();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,'" style="').concat(this.getSvgStyles(),'" />\n')],this.fill=t}return r=this.paintFirst!==Tt?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 ge(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=Ut(n),{width:a,height:c}=n;this._element=o,this._lastScaleX=t.scaleX=s,this._lastScaleY=t.scaleY=r,fa().applyFilters([t],n,a,c,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=Ut({width:i,height:s});this._element=t,this._filteredEl=t}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,i,s),this._lastScaleX=1,this._lastScaleY=1);fa().applyFilters(t,this._originalElement,i,s,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){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),c=e.naturalWidth||e.width,h=e.naturalHeight||e.height,l=o*i,u=a*s,d=Math.min(r*i,c-l),g=Math.min(n*s,h-u),f=-r/2,p=-n/2,m=Math.min(r,c/i-o),v=Math.min(n,h/s-a);e&&t.drawImage(e,l,u,d,g,f,p,m,v)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const i=this.getOriginalSize();this.width=t||i.width,this.height=e||i.height}parsePreserveAspectRatioAttribute(){const t=gi(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,c=1,h=0,l=0,u=0,d=0;return!t||t.alignX===ht&&t.alignY===ht?(a=e/n,c=i/o):("meet"===t.meetOrSlice&&(a=c=pn(this._element,s),r=(e-n*a)/2,"Min"===t.alignX&&(h=-r),"Max"===t.alignX&&(h=r),r=(i-o*c)/2,"Min"===t.alignY&&(l=-r),"Max"===t.alignY&&(l=r)),"slice"===t.meetOrSlice&&(a=c=mn(this._element,s),r=n-e/a,"Mid"===t.alignX&&(u=r/2),"Max"===t.alignX&&(u=r),r=o-i/c,"Mid"===t.alignY&&(d=r/2),"Max"===t.alignY&&(d=r),n=e/a,o=i/c)),{width:n,height:o,scaleX:a,scaleY:c,offsetLeft:h,offsetTop:l,cropX:u,cropY:d}}static fromObject(t,e){let{filters:i,resizeFilter:s,src:r,crossOrigin:n,type:o}=t,a=F(t,pa);return Promise.all([ge(r,A(A({},e),{},{crossOrigin:n})),i&&fe(i,e),s&&fe([s],e),pe(a,e)]).then((t=>{let[e,i=[],[s]=[],n={}]=t;return new this(e,A(A({},a),{},{src:r,filters:i,resizeFilter:s},n))}))}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 ge(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=Jr(t,this.ATTRIBUTE_NAMES,i);return this.fromURL(s["xlink:href"]||s.href,e,s).catch((t=>(B("log","Unable to parse Image",t),null)))}}P(va,"type","Image"),P(va,"cacheProperties",[...es,...ma]),P(va,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),P(va,"CSS_CANVAS","canvas-img"),P(va,"ATTRIBUTE_NAMES",[...wr,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),Et.setClass(va),Et.setSVGClass(va),mi(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const ya=vt,_a=t=>function(e,i,s){const{points:r,pathOffset:n}=s;return new It(r[t]).subtract(n).transform(ee(s.getViewportTransform(),s.calcTransformMatrix()))},xa=(t,e,i,s)=>{const{target:r,pointIndex:n}=e,o=r,a=Ge(new It(i,s),void 0,o.calcOwnMatrix());return o.points[n]=a.add(o.pathOffset),o.setDimensions(),o.set("dirty",!0),!0},ba=(t,e)=>function(i,s,r,n){const o=s.target,a=new It(o.points[(t>0?t:o.points.length)-1]),c=a.subtract(o.pathOffset).transform(o.calcOwnMatrix()),h=e(i,A(A({},s),{},{pointIndex:t}),r,n),l=a.subtract(o.pathOffset).transform(o.calcOwnMatrix()).subtract(c);return o.left-=l.x,o.top-=l.y,h},wa=t=>Os(ya,ba(t,xa)),Sa=(t,e,i)=>{const{path:s,pathOffset:r}=t,n=s[e];return new It(n[i]-r.x,n[i+1]-r.y).transform(ee(t.getViewportTransform(),t.calcTransformMatrix()))};function Ca(t,e,i){const{commandIndex:s,pointIndex:r}=this;return Sa(i,s,r)}function Ta(t,e,i,s){const{target:r}=e,{commandIndex:n,pointIndex:o}=this,a=((t,e,i,s,r)=>{const{path:n,pathOffset:o}=t,a=n[(s>0?s:n.length)-1],c=new It(a[r],a[r+1]),h=c.subtract(o).transform(t.calcOwnMatrix()),l=Ge(new It(e,i),void 0,t.calcOwnMatrix());n[s][r]=l.x+o.x,n[s][r+1]=l.y+o.y,t.setDimensions();const u=c.subtract(t.pathOffset).transform(t.calcOwnMatrix()).subtract(h);return t.left-=u.x,t.top-=u.y,t.set("dirty",!0),!0})(r,i,s,n,o);return qe(this.actionName,A(A({},ei(t,e,i,s)),{},{commandIndex:n,pointIndex:o})),a}class Oa extends Ps{constructor(t){super(t)}render(t,e,i,s,r){const n=A(A({},s),{},{cornerColor:this.controlFill,cornerStrokeColor:this.controlStroke,transparentCorners:!this.controlFill});super.render(t,e,i,n,r)}}class ka extends Oa{constructor(t){super(t)}render(t,e,i,s,r){const{path:n}=r,{commandIndex:o,pointIndex:a,connectToCommandIndex:c,connectToPointIndex:h}=this;t.save(),t.strokeStyle=this.controlStroke,this.connectionDashArray&&t.setLineDash(this.connectionDashArray);const[l]=n[o],u=Sa(r,c,h);if("Q"===l){const s=Sa(r,o,a+2);t.moveTo(s.x,s.y),t.lineTo(e,i)}else t.moveTo(e,i);t.lineTo(u.x,u.y),t.stroke(),t.restore(),super.render(t,e,i,s,r)}}const Da=(t,e,i,s,r,n)=>new(i?ka:Oa)(A(A({commandIndex:t,pointIndex:e,actionName:"modifyPath",positionHandler:Ca,actionHandler:Ta,connectToCommandIndex:r,connectToPointIndex:n},s),i?s.controlPointStyle:s.pointStyle));Object.freeze({__proto__:null,changeWidth:Ds,createObjectDefaultControls:tr,createPathControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i={};let s="M";return t.path.forEach(((t,r)=>{const n=t[0];switch("Z"!==n&&(i["c_".concat(r,"_").concat(n)]=Da(r,t.length-2,!1,e)),n){case"C":i["c_".concat(r,"_C_CP_1")]=Da(r,1,!0,e,r-1,(t=>"C"===t?5:"Q"===t?3:1)(s)),i["c_".concat(r,"_C_CP_2")]=Da(r,3,!0,e,r,5);break;case"Q":i["c_".concat(r,"_Q_CP_1")]=Da(r,1,!0,e,r,3)}s=n})),i},createPolyActionHandler:wa,createPolyControls:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i={};for(let s=0;s<("number"==typeof t?t:t.points.length);s++)i["p".concat(s)]=new Ps(A({actionName:ya,positionHandler:_a(s),actionHandler:wa(s)},e));return i},createPolyPositionHandler:_a,createResizeControls:er,createTextboxDefaultControls:ir,dragHandler:ri,factoryPolyActionHandler:ba,getLocalPoint:si,polyActionHandler:xa,renderCircleControl:Ms,renderSquareControl:Es,rotationStyleHandler:js,rotationWithSnapping:As,scaleCursorStyleHandler:Rs,scaleOrSkewActionName:Js,scaleSkewCursorStyleHandler:Qs,scalingEqually:Xs,scalingX:Vs,scalingXOrSkewingY:Zs,scalingY:Ys,scalingYOrSkewingX:$s,skewCursorStyleHandler:Gs,skewHandlerX:Us,skewHandlerY:qs,wrapWithFireEvent:Os,wrapWithFixedAnchor:ks});const Ma=t=>void 0!==t.webgl,Ea="precision highp float",Pa="\n ".concat(Ea,";\n varying vec2 vTexCoord;\n uniform sampler2D uTexture;\n void main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n }"),ja=["type"],Aa=["type"],Fa=new RegExp(Ea,"g");class La{get type(){return this.constructor.type}constructor(){let t=F(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},ja);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Pa}getVertexSource(){return"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n void main() {\n vTexCoord = aPosition;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }"}createProgram(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getFragmentSource(),i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:s="highp"}}=G();"highp"!==s&&(e=e.replace(Fa,Ea.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 X("Vertex, fragment shader or program creation error");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new X("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 X("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 X('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const a=this.getUniformLocations(t,o)||{};return a.uStepW=t.getUniformLocation(o,"uStepW"),a.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:a}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const i=this.constructor.uniformLocations,s={};for(let r=0;r<i.length;r++)s[i[r]]=t.getUniformLocation(e,i[r]);return s}sendAttributeData(t,e,i){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){return!1}applyTo(t){Ma(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)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:i}=t,s=Ut({width:e,height:i});t.helpLayer=s}}toObject(){const t=Object.keys(this.constructor.defaults||{});return A({type:this.type},t.reduce(((t,e)=>(t[e]=this[e],t)),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(F(t,Aa))}}P(La,"type","BaseFilter"),P(La,"uniformLocations",[]);const Ia={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 Ra extends La{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(Ia[this.mode],"\n }\n }\n ")}applyTo2d(t){let{imageData:{data:e}}=t;const i=new ui(this.color).getSource(),s=this.alpha,r=i[0]*s,n=i[1]*s,o=i[2]*s,a=1-s;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],c=e[t+2];let h,l,u;switch(this.mode){case"multiply":h=i*r/255,l=s*n/255,u=c*o/255;break;case"screen":h=255-(255-i)*(255-r)/255,l=255-(255-s)*(255-n)/255,u=255-(255-c)*(255-o)/255;break;case"add":h=i+r,l=s+n,u=c+o;break;case"difference":h=Math.abs(i-r),l=Math.abs(s-n),u=Math.abs(c-o);break;case"subtract":h=i-r,l=s-n,u=c-o;break;case"darken":h=Math.min(i,r),l=Math.min(s,n),u=Math.min(c,o);break;case"lighten":h=Math.max(i,r),l=Math.max(s,n),u=Math.max(c,o);break;case"overlay":h=r<128?2*i*r/255:255-2*(255-i)*(255-r)/255,l=n<128?2*s*n/255:255-2*(255-s)*(255-n)/255,u=o<128?2*c*o/255:255-2*(255-c)*(255-o)/255;break;case"exclusion":h=r+i-2*r*i/255,l=n+s-2*n*s/255,u=o+c-2*o*c/255;break;case"tint":h=r+i*a,l=n+s*a,u=o+c*a}e[t]=h,e[t+1]=l,e[t+2]=u}}sendUniformData(t,e){const i=new ui(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)}}P(Ra,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),P(Ra,"type","BlendColor"),P(Ra,"uniformLocations",["uColor"]),Et.setClass(Ra);const Ba={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 "},Xa=["type","image"];class Va extends La{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ba[this.mode]}getVertexSource(){return"\n attribute vec2 aPosition;\n varying vec2 vTexCoord;\n varying vec2 vTexCoord2;\n uniform mat3 uTransformMatrix;\n void main() {\n vTexCoord = aPosition;\n vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\n gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n }\n "}applyToWebGL(t){const e=t.context,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=Gt());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 c=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=c[t],a=c[t+1],h=c[t+2],l=c[t+3];switch(this.mode){case"multiply":e[t]=i*o/255,e[t+1]=s*a/255,e[t+2]=r*h/255,e[t+3]=n*l/255;break;case"mask":e[t+3]=l}}}sendUniformData(t,e){const i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)}toObject(){return A(A({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:i,image:s}=t,r=F(t,Xa);return va.fromObject(s,e).then((t=>new this(A(A({},r),{},{image:t}))))}}P(Va,"type","BlendImage"),P(Va,"defaults",{mode:"multiply",alpha:1}),P(Va,"uniformLocations",["uTransformMatrix","uImage"]),Et.setClass(Va);class Ya extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n const float nSamples = 15.0;\n vec3 v3offset = vec3(12.9898, 78.233, 151.7182);\n float random(vec3 scale) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n }\n void main() {\n vec4 color = vec4(0.0);\n float totalC = 0.0;\n float totalA = 0.0;\n float offset = random(v3offset);\n for (float t = -nSamples; t <= nSamples; t++) {\n float percent = (t + offset - 0.5) / nSamples;\n vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);\n float weight = 1.0 - abs(percent);\n float alpha = weight * sample.a;\n color.rgb += sample.rgb * alpha;\n color.a += alpha;\n totalA += weight;\n totalC += alpha;\n }\n gl_FragColor.rgb = color.rgb / totalC;\n gl_FragColor.a = color.a / totalA;\n }\n "}applyTo(t){Ma(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){let{imageData:{data:e,width:i,height:s}}=t;this.aspectRatio=i/s,this.horizontal=!0;let r=this.getBlurValue()*i;const n=new Uint8ClampedArray(e),o=4*i;for(let t=0;t<e.length;t+=4){let i=0,s=0,a=0,c=0,h=0;const l=t-t%o,u=l+o;for(let n=-14;n<15;n++){const o=n/15,d=4*Math.floor(r*o),g=1-Math.abs(o);let f=t+d;f<l?f=l:f>u&&(f=u);const p=e[f+3]*g;i+=e[f]*p,s+=e[f+1]*p,a+=e[f+2]*p,c+=p,h+=g}n[t]=i/c,n[t+1]=s/c,n[t+2]=a/c,n[t+3]=c/h}this.horizontal=!1,r=this.getBlurValue()*s;for(let t=0;t<n.length;t+=4){let i=0,s=0,a=0,c=0,h=0;const l=t%o,u=n.length-o+l;for(let e=-14;e<15;e++){const d=e/15,g=Math.floor(r*d)*o,f=1-Math.abs(d);let p=t+g;p<l?p=l:p>u&&(p=u);const m=n[p+3]*f;i+=n[p]*m,s+=n[p+1]*m,a+=n[p+2]*m,c+=m,h+=f}e[t]=i/c,e[t+1]=s/c,e[t+2]=a/c,e[t+3]=c/h}}sendUniformData(t,e){const i=this.chooseRightDelta();t.uniform2fv(e.uDelta,i)}isNeutralState(){return 0===this.blur}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:i}=this;return e?i>1&&(t=1/i):i<1&&(t=i),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}P(Ya,"type","Blur"),P(Ya,"defaults",{blur:0}),P(Ya,"uniformLocations",["uDelta"]),Et.setClass(Ya);class Wa extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBrightness;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += uBrightness;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=Math.round(255*this.brightness);for(let t=0;t<e.length;t+=4)e[t]+=i,e[t+1]+=i,e[t+2]+=i}isNeutralState(){return 0===this.brightness}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}P(Wa,"type","Brightness"),P(Wa,"defaults",{brightness:0}),P(Wa,"uniformLocations",["uBrightness"]),Et.setClass(Wa);const Ha={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class za extends La{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(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],!s){const s=e[t+3];e[t]+=s*i[3],e[t+1]+=s*i[8],e[t+2]+=s*i[13],e[t+3]=r*i[15]+n*i[16]+o*i[17]+s*i[18]+255*i[19]}}}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)}toObject(){return A(A({},super.toObject()),{},{matrix:[...this.matrix]})}}function Ga(t,e){var i;const s=(P(i=class extends za{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",t),P(i,"defaults",{colorsOnly:!1,matrix:e}),i);return Et.setClass(s,t),s}P(za,"type","ColorMatrix"),P(za,"defaults",Ha),P(za,"uniformLocations",["uColorMatrix","uConstants"]),Et.setClass(za);const Na=Ga("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Ua=Ga("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),qa=Ga("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Ka=Ga("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Ja=Ga("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Qa=Ga("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Za=Ga("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class $a extends La{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Ma(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach((e=>{e.applyTo(t)}))}toObject(){return{type:this.type,subFilters:this.subFilters.map((t=>t.toObject()))}}isNeutralState(){return!this.subFilters.some((t=>!t.isNeutralState()))}static fromObject(t,e){return Promise.all((t.subFilters||[]).map((t=>Et.getClass(t.type).fromObject(t,e)))).then((t=>new this({subFilters:t})))}}P($a,"type","Composed"),Et.setClass($a);class tc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uContrast;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\n color.rgb = contrastF * (color.rgb - 0.5) + 0.5;\n gl_FragColor = color;\n }"}isNeutralState(){return 0===this.contrast}applyTo2d(t){let{imageData:{data:e}}=t;const 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}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}P(tc,"type","Contrast"),P(tc,"defaults",{contrast:0}),P(tc,"uniformLocations",["uContrast"]),Et.setClass(tc);const ec={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 ic extends La{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ec[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,c=t.ctx.createImageData(o,a),h=c.data,l=this.opaque?1:0;let u,d,g,f,p,m,v,y,_,x,b,w,S;for(b=0;b<a;b++)for(x=0;x<o;x++){for(p=4*(b*o+x),u=0,d=0,g=0,f=0,S=0;S<r;S++)for(w=0;w<r;w++)v=b+S-n,m=x+w-n,v<0||v>=a||m<0||m>=o||(y=4*(v*o+m),_=s[S*r+w],u+=i[y]*_,d+=i[y+1]*_,g+=i[y+2]*_,l||(f+=i[y+3]*_));h[p]=u,h[p+1]=d,h[p+2]=g,h[p+3]=l?i[p+3]:f}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return A(A({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}P(ic,"type","Convolute"),P(ic,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),P(ic,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),Et.setClass(ic);const sc="Gamma";class rc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform vec3 uGamma;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n vec3 correction = (1.0 / uGamma);\n color.r = pow(color.r, correction.r);\n color.g = pow(color.g, correction.g);\n color.b = pow(color.b, correction.b);\n gl_FragColor = color;\n gl_FragColor.rgb *= color.a;\n }\n"}constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const 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]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return 1===t[0]&&1===t[1]&&1===t[2]}toObject(){return{type:sc,gamma:this.gamma.concat()}}}P(rc,"type",sc),P(rc,"defaults",{gamma:[1,1,1]}),P(rc,"uniformLocations",["uGamma"]),Et.setClass(rc);const nc={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 oc extends La{applyTo2d(t){let{imageData:{data:e}}=t;for(let t,i=0;i<e.length;i+=4){const s=e[i],r=e[i+1],n=e[i+2];switch(this.mode){case"average":t=(s+r+n)/3;break;case"lightness":t=(Math.min(s,r,n)+Math.max(s,r,n))/2;break;case"luminosity":t=.21*s+.72*r+.07*n}e[i+2]=e[i+1]=e[i]=t}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return nc[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}P(oc,"type","Grayscale"),P(oc,"defaults",{mode:"average"}),P(oc,"uniformLocations",["uMode"]),Et.setClass(oc);const ac=A(A({},Ha),{},{rotation:0});class cc extends za{calculateMatrix(){const t=this.rotation*Math.PI,e=Ft(t),i=Lt(t),s=1/3,r=Math.sqrt(s)*i,n=1-e;this.matrix=[e+n/3,s*n-r,s*n+r,0,0,s*n+r,e+s*n,s*n-r,0,0,s*n-r,s*n+r,e+s*n,0,0,0,0,0,1,0]}isNeutralState(){return 0===this.rotation}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}P(cc,"type","HueRotation"),P(cc,"defaults",ac),Et.setClass(cc);class hc extends La{applyTo2d(t){let{imageData:{data:e}}=t;for(let t=0;t<e.length;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2],this.alpha&&(e[t+3]=255-e[t+3])}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform int uInvert;\n uniform int uAlpha;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n if (uInvert == 1) {\n if (uAlpha == 1) {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);\n } else {\n gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n }\n } else {\n gl_FragColor = color;\n }\n }\n"}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}P(hc,"type","Invert"),P(hc,"defaults",{alpha:!1,invert:!0}),P(hc,"uniformLocations",["uInvert","uAlpha"]),Et.setClass(hc);class lc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uStepH;\n uniform float uNoise;\n uniform float uSeed;\n varying vec2 vTexCoord;\n float rand(vec2 co, float seed, float vScale) {\n return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n }\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const 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}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return 0===this.noise}}P(lc,"type","Noise"),P(lc,"defaults",{noise:0}),P(lc,"uniformLocations",["uNoise","uSeed"]),Et.setClass(lc);class uc extends La{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],c=e[n+2],h=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]=c,e[s+3]=h}}}isNeutralState(){return 1===this.blocksize}getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uBlocksize;\n uniform float uStepW;\n uniform float uStepH;\n varying vec2 vTexCoord;\n void main() {\n float blockW = uBlocksize * uStepW;\n float blockH = uBlocksize * uStepH;\n int posX = int(vTexCoord.x / blockW);\n int posY = int(vTexCoord.y / blockH);\n float fposX = float(posX);\n float fposY = float(posY);\n vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\n vec4 color = texture2D(uTexture, squareCoords);\n gl_FragColor = color;\n }\n"}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}P(uc,"type","Pixelate"),P(uc,"defaults",{blocksize:4}),P(uc,"uniformLocations",["uBlocksize"]),Et.setClass(uc);class dc extends La{getFragmentSource(){return"\nprecision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTexCoord);\n if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\n gl_FragColor.a = 0.0;\n }\n}\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=255*this.distance,s=new ui(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)}}sendUniformData(t,e){const i=new ui(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)}}P(dc,"type","RemoveColor"),P(dc,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),P(dc,"uniformLocations",["uLow","uHigh"]),Et.setClass(dc);class gc extends La{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 precision highp float;\n uniform sampler2D uTexture;\n uniform vec2 uDelta;\n varying vec2 vTexCoord;\n uniform float uTaps[".concat(t,"];\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float sum = 1.0;\n ").concat(e.map(((t,e)=>"\n color += texture2D(uTexture, vTexCoord + ".concat(t,") * uTaps[").concat(e,"] + texture2D(uTexture, vTexCoord - ").concat(t,") * uTaps[").concat(e,"];\n sum += 2.0 * uTaps[").concat(e,"];\n "))).join("\n"),"\n gl_FragColor = color / sum;\n }\n ")}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Ma(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 c;c="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=c}sliceByTwo(t,e,i,s,r){const n=t.imageData,o=.5;let a=!1,c=!1,h=e*o,l=i*o;const u=t.filterBackend.resources;let d=0,g=0;const f=e;let p=0;u.sliceByTwo||(u.sliceByTwo=Gt());const m=u.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||!c;)e=h,i=l,s<Math.floor(h*o)?h=Math.floor(h*o):(h=s,a=!0),r<Math.floor(l*o)?l=Math.floor(l*o):(l=r,c=!0),v.drawImage(m,d,g,e,i,f,p,h,l),d=f,g=p,p+=l;return v.getImageData(d,g,s,r)}lanczosResize(t,e,i,s,r){const n=t.imageData.data,o=t.ctx.createImageData(s,r),a=o.data,c=this.lanczosCreate(this.lanczosLobes),h=this.rcpScaleX,l=this.rcpScaleY,u=2/this.rcpScaleX,d=2/this.rcpScaleY,g=Math.ceil(h*this.lanczosLobes/2),f=Math.ceil(l*this.lanczosLobes/2),p={},m={x:0,y:0},v={x:0,y:0};return function t(y){let _,x,b,w,S,C,T,O,k,D,M;for(m.x=(y+.5)*h,v.x=Math.floor(m.x),_=0;_<r;_++){for(m.y=(_+.5)*l,v.y=Math.floor(m.y),S=0,C=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]=c(Math.sqrt(Math.pow(D*u,2)+Math.pow(M*d,2))/1e3)),b=p[D][M],b>0&&(w=4*(t*e+x),S+=b,C+=b*n[w],T+=b*n[w+1],O+=b*n[w+2],k+=b*n[w+3]))}w=4*(_*s+y),a[w]=C/S,a[w+1]=T/S,a[w+2]=O/S,a[w+3]=k/S}return++y<s?t(y):o}(0)}bilinearFiltering(t,e,i,s,r){let n,o,a,c,h,l,u,d,g,f,p,m,v,y=0;const _=this.rcpScaleX,x=this.rcpScaleY,b=4*(e-1),w=t.imageData.data,S=t.ctx.createImageData(s,r),C=S.data;for(u=0;u<r;u++)for(d=0;d<s;d++)for(h=Math.floor(_*d),l=Math.floor(x*u),g=_*d-h,f=x*u-l,v=4*(l*e+h),p=0;p<4;p++)n=w[v+p],o=w[v+4+p],a=w[v+b+p],c=w[v+b+4+p],m=n*(1-g)*(1-f)+o*g*(1-f)+a*f*(1-g)+c*g*f,C[y++]=m;return S}hermiteFastResize(t,e,i,s,r){const n=this.rcpScaleX,o=this.rcpScaleY,a=Math.ceil(n/2),c=Math.ceil(o/2),h=t.imageData.data,l=t.ctx.createImageData(s,r),u=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,d=0,g=0,f=0,p=0,m=0,v=0;const y=(t+.5)*o;for(let s=Math.floor(t*o);s<(t+1)*o;s++){const t=Math.abs(y-(s+.5))/c,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*h[i+3],g+=l,h[i+3]<255&&(l=l*h[i+3]/250),f+=l*h[i],p+=l*h[i+1],m+=l*h[i+2],d+=l))}}u[r]=f/d,u[r+1]=p/d,u[r+2]=m/d,u[r+3]=v/g}return l}}P(gc,"type","Resize"),P(gc,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),P(gc,"uniformLocations",["uDelta","uTaps"]),Et.setClass(gc);class fc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uSaturation;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float rgMax = max(color.r, color.g);\n float rgbMax = max(rgMax, color.b);\n color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\n color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\n color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=-this.saturation;for(let t=0;t<e.length;t+=4){const s=e[t],r=e[t+1],n=e[t+2],o=Math.max(s,r,n);e[t]+=o!==s?(o-s)*i:0,e[t+1]+=o!==r?(o-r)*i:0,e[t+2]+=o!==n?(o-n)*i:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return 0===this.saturation}}P(fc,"type","Saturation"),P(fc,"defaults",{saturation:0}),P(fc,"uniformLocations",["uSaturation"]),Et.setClass(fc);class pc extends La{getFragmentSource(){return"\n precision highp float;\n uniform sampler2D uTexture;\n uniform float uVibrance;\n varying vec2 vTexCoord;\n void main() {\n vec4 color = texture2D(uTexture, vTexCoord);\n float max = max(color.r, max(color.g, color.b));\n float avg = (color.r + color.g + color.b) / 3.0;\n float amt = (abs(max - avg) * 2.0) * uVibrance;\n color.r += max != color.r ? (max - color.r) * amt : 0.00;\n color.g += max != color.g ? (max - color.g) * amt : 0.00;\n color.b += max != color.b ? (max - color.b) * amt : 0.00;\n gl_FragColor = color;\n }\n"}applyTo2d(t){let{imageData:{data:e}}=t;const i=-this.vibrance;for(let t=0;t<e.length;t+=4){const s=e[t],r=e[t+1],n=e[t+2],o=Math.max(s,r,n),a=(s+r+n)/3,c=2*Math.abs(o-a)/255*i;e[t]+=o!==s?(o-s)*c:0,e[t+1]+=o!==r?(o-r)*c:0,e[t+2]+=o!==n?(o-n)*c:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return 0===this.vibrance}}P(pc,"type","Vibrance"),P(pc,"defaults",{vibrance:0}),P(pc,"uniformLocations",["uVibrance"]),Et.setClass(pc),Object.freeze({__proto__:null,BaseFilter:La,BlackWhite:Za,BlendColor:Ra,BlendImage:Va,Blur:Ya,Brightness:Wa,Brownie:Na,ColorMatrix:za,Composed:$a,Contrast:tc,Convolute:ic,Gamma:rc,Grayscale:oc,HueRotation:cc,Invert:hc,Kodachrome:qa,Noise:lc,Pixelate:uc,Polaroid:Ja,RemoveColor:dc,Resize:gc,Saturation:fc,Sepia:Qa,Technicolor:Ka,Vibrance:pc,Vintage:Ua});var mc=function(){function t(e,i){var s;return y(this,t),b(T(s=l(this,t,[e,g({originX:"center",originY:"center",left:0,top:0,layoutManager:new un(new ca)},i)])),"blockErasing",!1),s}return w(t,fn),x(t,[{key:"drawObject",value:function(t){var e=[],i=[];this._objects.forEach((function(t){return(t instanceof So?e:i).push(t)})),t.save(),t.fillStyle="black",t.fillRect(-this.width/2,-this.height/2,this.width,this.height),t.restore(),!this.blockErasing&&e.forEach((function(e){e.render(t)})),i.forEach((function(e){e.globalCompositeOperation=e.inverted?"destination-out":"source-in",e.render(t)}))}}]),t}();b(mc,"type","clipping"),Et.setClass(mc);var vc=function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"source-over";t.save(),t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high",t.globalCompositeOperation=i,t.resetTransform(),t.drawImage(e.canvas,0,0),t.restore()};function yc(t){return t.flatMap((function(t){return!t.erasable||t.isNotVisible()?[]:t instanceof fn&&"deep"===t.erasable?yc(t.getObjects()):[t]}))}function _c(t,e,i){var s=e.inverted,r=e.opacity,n=i.canvas,o=i.objects,a=void 0===o?n._objectsToRender||n._objects:o,c=i.background,h=void 0===c?n.backgroundImage:c,l=i.overlay,u=void 0===l?n.overlayImage:l,d=1-r,g=yc([].concat(D(a),D([h,u].filter((function(t){return!!t}))))).map((function(t){if(!s){var e,i=t.opacity;return t.opacity*=d,null===(e=t.parent)||void 0===e||e.set("dirty",!0),{object:t,opacity:i}}if(t.clipPath instanceof mc)return t.clipPath.blockErasing=!0,t.clipPath.set("dirty",!0),t.set("dirty",!0),{object:t,clipPath:t.clipPath}}));!function(t,e,i){e.clearContext(t),t.imageSmoothingEnabled=e.imageSmoothingEnabled,t.imageSmoothingQuality="high",t.patternQuality="best",e._renderBackground(t),t.save(),t.transform.apply(t,D(e.viewportTransform)),i.forEach((function(e){return e.render(t)})),t.restore();var s=e.clipPath;s&&(s._set("canvas",e),s.shouldCache(),s._transformDone=!0,s.renderCache({forClipping:!0}),e.drawClipPathOnCanvas(t,s)),e._renderOverlay(t)}(t,n,a),g.forEach((function(t){var e;t&&(t.opacity?(t.object.opacity=t.opacity,null===(e=t.object.parent)||void 0===e||e.set("dirty",!0)):t.clipPath&&(t.clipPath.blockErasing=!1,t.clipPath.set("dirty",!0),t.object.set("dirty",!0)))}))}function xc(t,e){return t.flatMap((function(t){return t.erasable&&t.intersectsWithObject(e)?t instanceof fn&&"deep"===t.erasable?xc(t.getObjects(),e):[t]:[]}))}function bc(t,e){var i=function(t){var e=t.clipPath;if(e instanceof mc)return e;var i=t.strokeWidth,s=new It(i,i),r=t.strokeUniform?s.divide(t.getObjectScaling()):s,n=new mc([],{width:t.width+r.x,height:t.height+r.y});if(e){var o=e.translateToOriginPoint(new It,e.originX,e.originY),a=o.x,c=o.y;e.originX=e.originY="center",Gn.sendObjectToPlane(e,void 0,Gn.createTranslateMatrix(a,c)),n.add(e)}return t.clipPath=n}(t);i.add(e),i.set("dirty",!0),t.set("dirty",!0)}function wc(t,e){return Sc.apply(this,arguments)}function Sc(){return(Sc=v(f().mark((function t(e,i){var s;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i.clone();case 2:return s=t.sent,Gn.sendObjectToPlane(s,void 0,e.calcTransformMatrix()),bc(e,s),t.abrupt("return",s);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Cc(t,e,i){return Tc.apply(this,arguments)}function Tc(){return Tc=v(f().mark((function t(e,i,s){var r,n;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.clone();case 2:return r=t.sent,n=i&&e.translateToOriginPoint(new It,e.originX,e.originY),Gn.sendObjectToPlane(r,void 0,n?Gn.multiplyTransformMatrixArray([[1,0,0,1,n.x,n.y],i,[1,0,0,1,-n.x,-n.y],e.calcTransformMatrix()]):e.calcTransformMatrix()),bc(e,r),t.abrupt("return",r);case 7:case"end":return t.stop()}}),t)}))),Tc.apply(this,arguments)}var Oc=function(){function t(e){var i;y(this,t),b(T(i=l(this,t,[e])),"inverted",!1),b(T(i),"active",!1);var s=document.createElement("canvas"),r=s.getContext("2d");if(!r)throw new Error("Failed to get context");return function(t,e,i){var s=i.width,r=i.height,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))}(s,r,e,i.canvas.getRetinaScaling()),i.effectContext=r,i.eventEmitter=new EventTarget,i}var e;return w(t,Co),x(t,[{key:"on",value:function(t,e,i){var s=this;return this.eventEmitter.addEventListener(t,e,i),function(){return s.eventEmitter.removeEventListener(t,e,i)}}},{key:"drawEffect",value:function(){_c(this.effectContext,{opacity:new ui(this.color).getAlpha(),inverted:this.inverted},{canvas:this.canvas})}},{key:"_setBrushStyles",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.contextTop;O(S(t.prototype),"_setBrushStyles",this).call(this,e),e.strokeStyle="black"}},{key:"needsFullRender",value:function(){return!0}},{key:"_render",value:function(){var e,i,s,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.canvas.getTopContext();O(S(t.prototype),"_render",this).call(this,r),e=this.canvas.getContext(),i=r,s=this.effectContext,vc(e,i,"destination-out"),s?vc(i,s,"source-in"):(i.save(),i.resetTransform(),i.clearRect(0,0,i.canvas.width,i.canvas.height),i.restore())}},{key:"onMouseDown",value:function(e,i){var s=this;this.eventEmitter.dispatchEvent(new CustomEvent("start",{detail:i,cancelable:!0}))&&(this.active=!0,this.eventEmitter.dispatchEvent(new CustomEvent("redraw",{detail:{type:"start"},cancelable:!0}))&&this.drawEffect(),this._disposer=this.canvas.on("after:render",(function(t){t.ctx===s.canvas.getContext()&&(s.eventEmitter.dispatchEvent(new CustomEvent("redraw",{detail:{type:"render"},cancelable:!0}))&&s.drawEffect(),s._render())})),O(S(t.prototype),"onMouseDown",this).call(this,e,i))}},{key:"onMouseMove",value:function(e,i){this.active&&this.eventEmitter.dispatchEvent(new CustomEvent("move",{detail:i,cancelable:!0}))&&O(S(t.prototype),"onMouseMove",this).call(this,e,i)}},{key:"onMouseUp",value:function(e){var i;return this.active&&O(S(t.prototype),"onMouseUp",this).call(this,e),this.active=!1,null===(i=this._disposer)||void 0===i||i.call(this),delete this._disposer,!1}},{key:"convertPointsToSVGPath",value:function(e){return O(S(t.prototype),"convertPointsToSVGPath",this).call(this,this.decimate?this.decimatePoints(e,this.decimate):e)}},{key:"createPath",value:function(e){var i=O(S(t.prototype),"createPath",this).call(this,e);return i.set(this.inverted?{globalCompositeOperation:"source-over",stroke:"white"}:{globalCompositeOperation:"destination-out",stroke:"black",opacity:new ui(this.color).getAlpha()}),i}},{key:"commit",value:(e=v(f().mark((function t(e){var i,s;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=e.path,s=e.targets,t.t0=Map,t.next=4,Promise.all([].concat(D(s.map(function(){var t=v(f().mark((function t(e){return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=e,t.next=3,wc(e,i);case 3:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),D([[this.canvas.backgroundImage,this.canvas.backgroundVpt?void 0:this.canvas.viewportTransform],[this.canvas.overlayImage,this.canvas.overlayVpt?void 0:this.canvas.viewportTransform]].filter((function(t){var e=k(t,1)[0];return!(null==e||!e.erasable)})).map(function(){var t=v(f().mark((function t(e){var s,r,n;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s=k(e,2),r=s[0],n=s[1],t.t0=r,t.next=4,Cc(r,n,i);case 4:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()))));case 4:return t.t1=t.sent,t.abrupt("return",new t.t0(t.t1));case 6:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"_finalizeAndAddPath",value:function(){var t=this._points;if(t.length<2)this.eventEmitter.dispatchEvent(new CustomEvent("cancel",{cancelable:!1}));else{var e=this.createPath(this.convertPointsToSVGPath(t)),i=xc(this.canvas.getObjects(),e);this.eventEmitter.dispatchEvent(new CustomEvent("end",{detail:{path:e,targets:i},cancelable:!0}))&&this.commit({path:e,targets:i}),this.canvas.clearContext(this.canvas.contextTop),this.canvas.requestRenderAll(),this._resetShadow()}}},{key:"dispose",value:function(){var t=this.effectContext.canvas;t.width=t.height=0}}]),t}();const kc={toVector:(t,e)=>(void 0===t&&(t=e),Array.isArray(t)?t:[t,t]),add:(t,e)=>[t[0]+e[0],t[1]+e[1]],sub:(t,e)=>[t[0]-e[0],t[1]-e[1]],addTo(t,e){t[0]+=e[0],t[1]+=e[1]},subTo(t,e){t[0]-=e[0],t[1]-=e[1]}};function Dc(t,e,i){return 0===e||Math.abs(e)===1/0?Math.pow(t,5*i):t*e*i/(e+i*t)}function Mc(t,e,i,s=.15){return 0===s?function(t,e,i){return Math.max(e,Math.min(t,i))}(t,e,i):t<e?-Dc(e-t,i-e,s)+e:t>i?+Dc(t-i,i-e,s)+i:t}function Ec(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)}function Pc(t,e,i){return(e=Ec(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function jc(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 Ac(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?jc(Object(i),!0).forEach((function(e){Pc(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):jc(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}const Fc={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function Lc(t){return t?t[0].toUpperCase()+t.slice(1):""}const Ic=["enter","leave"];function Rc(t,e="",i=!1){const s=Fc[t],r=s&&s[e]||e;return"on"+Lc(t)+Lc(r)+(function(t=!1,e){return t&&!Ic.includes(e)}(i,r)?"Capture":"")}const Bc=["gotpointercapture","lostpointercapture"];function Xc(t){let e=t.substring(2).toLowerCase();const i=!!~e.indexOf("passive");i&&(e=e.replace("passive",""));const s=Bc.includes(e)?"capturecapture":"capture",r=!!~e.indexOf(s);return r&&(e=e.replace("capture","")),{device:e,capture:r,passive:i}}function Vc(t){return"touches"in t}function Yc(t){return Vc(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function Wc(t){return Vc(t)?function(t){return"touchend"===t.type||"touchcancel"===t.type?t.changedTouches:t.targetTouches}(t)[0]:t}function Hc(t,e){try{const i=e.clientX-t.clientX,s=e.clientY-t.clientY,r=(e.clientX+t.clientX)/2,n=(e.clientY+t.clientY)/2,o=Math.hypot(i,s),a=-180*Math.atan2(i,s)/Math.PI;return{angle:a,distance:o,origin:[r,n]}}catch(t){}return null}function zc(t){return function(t){return Array.from(t.touches).filter((e=>{var i,s;return e.target===t.currentTarget||(null===(i=t.currentTarget)||void 0===i||null===(s=i.contains)||void 0===s?void 0:s.call(i,e.target))}))}(t).map((t=>t.identifier))}function Gc(t,e){const[i,s]=Array.from(t.touches).filter((t=>e.includes(t.identifier)));return Hc(i,s)}function Nc(t){const e=Wc(t);return Vc(t)?e.identifier:e.pointerId}function Uc(t){const e=Wc(t);return[e.clientX,e.clientY]}function qc(t){let{deltaX:e,deltaY:i,deltaMode:s}=t;return 1===s?(e*=40,i*=40):2===s&&(e*=800,i*=800),[e,i]}function Kc(t,...e){return"function"==typeof t?t(...e):t}function Jc(){}function Qc(...t){return 0===t.length?Jc:1===t.length?t[0]:function(){let e;for(const i of t)e=i.apply(this,arguments)||e;return e}}function Zc(t,e){return Object.assign({},e,t||{})}class $c{constructor(t,e,i){this.ctrl=t,this.args=e,this.key=i,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(t){this.ctrl.state[this.key]=t}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:t,shared:e,ingKey:i,args:s}=this;e[i]=t._active=t.active=t._blocked=t._force=!1,t._step=[!1,!1],t.intentional=!1,t._movement=[0,0],t._distance=[0,0],t._direction=[0,0],t._delta=[0,0],t._bounds=[[-1/0,1/0],[-1/0,1/0]],t.args=s,t.axis=void 0,t.memo=void 0,t.elapsedTime=t.timeDelta=0,t.direction=[0,0],t.distance=[0,0],t.overflow=[0,0],t._movementBound=[!1,!1],t.velocity=[0,0],t.movement=[0,0],t.delta=[0,0],t.timeStamp=0}start(t){const e=this.state,i=this.config;e._active||(this.reset(),this.computeInitial(),e._active=!0,e.target=t.target,e.currentTarget=t.currentTarget,e.lastOffset=i.from?Kc(i.from,e):e.offset,e.offset=e.lastOffset,e.startTime=e.timeStamp=t.timeStamp)}computeValues(t){const e=this.state;e._values=t,e.values=this.config.transform(t)}computeInitial(){const t=this.state;t._initial=t._values,t.initial=t.values}compute(t){const{state:e,config:i,shared:s}=this;e.args=this.args;let r=0;if(t&&(e.event=t,i.preventDefault&&t.cancelable&&e.event.preventDefault(),e.type=t.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,function(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:i,altKey:s,metaKey:r,ctrlKey:n}=t;Object.assign(e,{shiftKey:i,altKey:s,metaKey:r,ctrlKey:n})}return e}(t)),s.down=s.pressed=s.buttons%2==1||s.touches>0,r=t.timeStamp-e.timeStamp,e.timeStamp=t.timeStamp,e.elapsedTime=e.timeStamp-e.startTime),e._active){const t=e._delta.map(Math.abs);kc.addTo(e._distance,t)}this.axisIntent&&this.axisIntent(t);const[n,o]=e._movement,[a,c]=i.threshold,{_step:h,values:l}=e;if(i.hasCustomTransform?(!1===h[0]&&(h[0]=Math.abs(n)>=a&&l[0]),!1===h[1]&&(h[1]=Math.abs(o)>=c&&l[1])):(!1===h[0]&&(h[0]=Math.abs(n)>=a&&Math.sign(n)*a),!1===h[1]&&(h[1]=Math.abs(o)>=c&&Math.sign(o)*c)),e.intentional=!1!==h[0]||!1!==h[1],!e.intentional)return;const u=[0,0];if(i.hasCustomTransform){const[t,e]=l;u[0]=!1!==h[0]?t-h[0]:0,u[1]=!1!==h[1]?e-h[1]:0}else u[0]=!1!==h[0]?n-h[0]:0,u[1]=!1!==h[1]?o-h[1]:0;this.restrictToAxis&&!e._blocked&&this.restrictToAxis(u);const d=e.offset,g=e._active&&!e._blocked||e.active;g&&(e.first=e._active&&!e.active,e.last=!e._active&&e.active,e.active=s[this.ingKey]=e._active,t&&(e.first&&("bounds"in i&&(e._bounds=Kc(i.bounds,e)),this.setup&&this.setup()),e.movement=u,this.computeOffset()));const[f,p]=e.offset,[[m,v],[y,_]]=e._bounds;e.overflow=[f<m?-1:f>v?1:0,p<y?-1:p>_?1:0],e._movementBound[0]=!!e.overflow[0]&&(!1===e._movementBound[0]?e._movement[0]:e._movementBound[0]),e._movementBound[1]=!!e.overflow[1]&&(!1===e._movementBound[1]?e._movement[1]:e._movementBound[1]);const x=e._active&&i.rubberband||[0,0];if(e.offset=function(t,[e,i],[s,r]){const[[n,o],[a,c]]=t;return[Mc(e,n,o,s),Mc(i,a,c,r)]}(e._bounds,e.offset,x),e.delta=kc.sub(e.offset,d),this.computeMovement(),g&&(!e.last||r>32)){e.delta=kc.sub(e.offset,d);const t=e.delta.map(Math.abs);kc.addTo(e.distance,t),e.direction=e.delta.map(Math.sign),e._direction=e._delta.map(Math.sign),!e.first&&r>0&&(e.velocity=[t[0]/r,t[1]/r],e.timeDelta=r)}}emit(){const t=this.state,e=this.shared,i=this.config;if(t._active||this.clean(),(t._blocked||!t.intentional)&&!t._force&&!i.triggerAllEvents)return;const s=this.handler(Ac(Ac(Ac({},e),t),{},{[this.aliasKey]:t.values}));void 0!==s&&(t.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}class th extends $c{constructor(...t){super(...t),Pc(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=kc.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=kc.sub(this.state.offset,this.state.lastOffset)}axisIntent(t){const e=this.state,i=this.config;if(!e.axis&&t){const s="object"==typeof i.axisThreshold?i.axisThreshold[Yc(t)]:i.axisThreshold;e.axis=function([t,e],i){const s=Math.abs(t),r=Math.abs(e);return s>r&&s>i?"x":r>s&&r>i?"y":void 0}(e._movement,s)}e._blocked=(i.lockDirection||!!i.axis)&&!e.axis||!!i.axis&&i.axis!==e.axis}restrictToAxis(t){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":t[1]=0;break;case"y":t[0]=0}}}const eh=t=>t,ih={enabled:(t=!0)=>t,eventOptions:(t,e,i)=>Ac(Ac({},i.shared.eventOptions),t),preventDefault:(t=!1)=>t,triggerAllEvents:(t=!1)=>t,rubberband(t=0){switch(t){case!0:return[.15,.15];case!1:return[0,0];default:return kc.toVector(t)}},from:t=>"function"==typeof t?t:null!=t?kc.toVector(t):void 0,transform(t,e,i){const s=t||i.shared.transform;if(this.hasCustomTransform=!!s,"development"===process.env.NODE_ENV){const t=s||eh;return e=>{const i=t(e);return isFinite(i[0])&&isFinite(i[1])||console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${i[0]},${[1]}]`),i}}return s||eh},threshold:t=>kc.toVector(t,0)};"development"===process.env.NODE_ENV&&Object.assign(ih,{domTarget(t){if(void 0!==t)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");return NaN},lockDirection(t){if(void 0!==t)throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");return NaN},initial(t){if(void 0!==t)throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");return NaN}});const sh=Ac(Ac({},ih),{},{axis(t,e,{axis:i}){if(this.lockDirection="lock"===i,!this.lockDirection)return i},axisThreshold:(t=0)=>t,bounds(t={}){if("function"==typeof t)return e=>sh.bounds(t(e));if("current"in t)return()=>t.current;if("function"==typeof HTMLElement&&t instanceof HTMLElement)return t;const{left:e=-1/0,right:i=1/0,top:s=-1/0,bottom:r=1/0}=t;return[[e,i],[s,r]]}}),rh={ArrowRight:(t,e=1)=>[t*e,0],ArrowLeft:(t,e=1)=>[-1*t*e,0],ArrowUp:(t,e=1)=>[0,-1*t*e],ArrowDown:(t,e=1)=>[0,t*e]};const nh="undefined"!=typeof window&&window.document&&window.document.createElement;function oh(){return nh&&"ontouchstart"in window}const ah={isBrowser:nh,gesture:function(){try{return"constructor"in GestureEvent}catch(t){return!1}}(),touch:oh(),touchscreen:oh()||nh&&window.navigator.maxTouchPoints>1,pointer:nh&&"onpointerdown"in window,pointerLock:nh&&"exitPointerLock"in window.document},ch={mouse:0,touch:0,pen:8},hh=Ac(Ac({},sh),{},{device(t,e,{pointer:{touch:i=!1,lock:s=!1,mouse:r=!1}={}}){return this.pointerLock=s&&ah.pointerLock,ah.touch&&i?"touch":this.pointerLock?"mouse":ah.pointer&&!r?"pointer":ah.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:i}){if(this.preventScrollDelay="number"==typeof i?i:i||void 0===i&&t?250:void 0,ah.touchscreen&&!1!==i)return t||(void 0!==i?"y":void 0)},pointerCapture(t,e,{pointer:{capture:i=!0,buttons:s=1,keys:r=!0}={}}){return this.pointerButtons=s,this.keys=r,!this.pointerLock&&"pointer"===this.device&&i},threshold(t,e,{filterTaps:i=!1,tapsThreshold:s=3,axis:r}){const n=kc.toVector(t,i?s:r?1:0);return this.filterTaps=i,this.tapsThreshold=s,n},swipe({velocity:t=.5,distance:e=50,duration:i=250}={}){return{velocity:this.transform(kc.toVector(t)),distance:this.transform(kc.toVector(e)),duration:i}},delay(t=0){switch(t){case!0:return 180;case!1:return 0;default:return t}},axisThreshold:t=>t?Ac(Ac({},ch),t):ch,keyboardDisplacement:(t=10)=>t});"development"===process.env.NODE_ENV&&Object.assign(hh,{useTouch(t){if(void 0!==t)throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");return NaN},experimental_preventWindowScrollY(t){if(void 0!==t)throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");return NaN},swipeVelocity(t){if(void 0!==t)throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");return NaN},swipeDistance(t){if(void 0!==t)throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");return NaN},swipeDuration(t){if(void 0!==t)throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");return NaN}});const lh=Ac(Ac({},ih),{},{device(t,e,{shared:i,pointer:{touch:s=!1}={}}){if(i.target&&!ah.touch&&ah.gesture)return"gesture";if(ah.touch&&s)return"touch";if(ah.touchscreen){if(ah.pointer)return"pointer";if(ah.touch)return"touch"}},bounds(t,e,{scaleBounds:i={},angleBounds:s={}}){const r=t=>{const e=Zc(Kc(i,t),{min:-1/0,max:1/0});return[e.min,e.max]},n=t=>{const e=Zc(Kc(s,t),{min:-1/0,max:1/0});return[e.min,e.max]};return"function"!=typeof i&&"function"!=typeof s?[r(),n()]:t=>[r(t),n(t)]},threshold(t,e,i){this.lockDirection="lock"===i.axis;return kc.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey:t=>void 0===t?"ctrlKey":t,pinchOnWheel:(t=!0)=>t});Ac(Ac({},sh),{},{mouseOnly:(t=!0)=>t}),Ac(Ac({},sh),{},{mouseOnly:(t=!0)=>t});const uh=new Map,dh=new Map;function gh(t){uh.set(t.key,t.engine),dh.set(t.key,t.resolver)}const fh={key:"drag",engine:class extends th{constructor(...t){super(...t),Pc(this,"ingKey","dragging")}reset(){super.reset();const t=this.state;t._pointerId=void 0,t._pointerActive=!1,t._keyboardActive=!1,t._preventScroll=!1,t._delayed=!1,t.swipe=[0,0],t.tap=!1,t.canceled=!1,t.cancel=this.cancel.bind(this)}setup(){const t=this.state;if(t._bounds instanceof HTMLElement){const e=t._bounds.getBoundingClientRect(),i=t.currentTarget.getBoundingClientRect(),s={left:e.left-i.left+t.offset[0],right:e.right-i.right+t.offset[0],top:e.top-i.top+t.offset[1],bottom:e.bottom-i.bottom+t.offset[1]};t._bounds=sh.bounds(s)}}cancel(){const t=this.state;t.canceled||(t.canceled=!0,t._active=!1,setTimeout((()=>{this.compute(),this.emit()}),0))}setActive(){this.state._active=this.state._pointerActive||this.state._keyboardActive}clean(){this.pointerClean(),this.state._pointerActive=!1,this.state._keyboardActive=!1,super.clean()}pointerDown(t){const e=this.config,i=this.state;if(null!=t.buttons&&(Array.isArray(e.pointerButtons)?!e.pointerButtons.includes(t.buttons):-1!==e.pointerButtons&&e.pointerButtons!==t.buttons))return;const s=this.ctrl.setEventIds(t);e.pointerCapture&&t.target.setPointerCapture(t.pointerId),s&&s.size>1&&i._pointerActive||(this.start(t),this.setupPointer(t),i._pointerId=Nc(t),i._pointerActive=!0,this.computeValues(Uc(t)),this.computeInitial(),e.preventScrollAxis&&"mouse"!==Yc(t)?(i._active=!1,this.setupScrollPrevention(t)):e.delay>0?(this.setupDelayTrigger(t),e.triggerAllEvents&&(this.compute(t),this.emit())):this.startPointerDrag(t))}startPointerDrag(t){const e=this.state;e._active=!0,e._preventScroll=!0,e._delayed=!1,this.compute(t),this.emit()}pointerMove(t){const e=this.state,i=this.config;if(!e._pointerActive)return;const s=Nc(t);if(void 0!==e._pointerId&&s!==e._pointerId)return;const r=Uc(t);return document.pointerLockElement===t.target?e._delta=[t.movementX,t.movementY]:(e._delta=kc.sub(r,e._values),this.computeValues(r)),kc.addTo(e._movement,e._delta),this.compute(t),e._delayed&&e.intentional?(this.timeoutStore.remove("dragDelay"),e.active=!1,void this.startPointerDrag(t)):i.preventScrollAxis&&!e._preventScroll?e.axis?e.axis===i.preventScrollAxis||"xy"===i.preventScrollAxis?(e._active=!1,void this.clean()):(this.timeoutStore.remove("startPointerDrag"),void this.startPointerDrag(t)):void 0:void this.emit()}pointerUp(t){this.ctrl.setEventIds(t);try{this.config.pointerCapture&&t.target.hasPointerCapture(t.pointerId)&&t.target.releasePointerCapture(t.pointerId)}catch(t){"development"===process.env.NODE_ENV&&console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.")}const e=this.state,i=this.config;if(!e._active||!e._pointerActive)return;const s=Nc(t);if(void 0!==e._pointerId&&s!==e._pointerId)return;this.state._pointerActive=!1,this.setActive(),this.compute(t);const[r,n]=e._distance;if(e.tap=r<=i.tapsThreshold&&n<=i.tapsThreshold,e.tap&&i.filterTaps)e._force=!0;else{const[t,s]=e._delta,[r,n]=e._movement,[o,a]=i.swipe.velocity,[c,h]=i.swipe.distance,l=i.swipe.duration;if(e.elapsedTime<l){const i=Math.abs(t/e.timeDelta),l=Math.abs(s/e.timeDelta);i>o&&Math.abs(r)>c&&(e.swipe[0]=Math.sign(t)),l>a&&Math.abs(n)>h&&(e.swipe[1]=Math.sign(s))}}this.emit()}pointerClick(t){!this.state.tap&&t.detail>0&&(t.preventDefault(),t.stopPropagation())}setupPointer(t){const e=this.config,i=e.device;if("development"===process.env.NODE_ENV)try{if("pointer"===i&&void 0===e.preventScrollDelay){const e="uv"in t?t.sourceEvent.currentTarget:t.currentTarget;"auto"===window.getComputedStyle(e).touchAction&&console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.",e)}}catch(t){}e.pointerLock&&t.currentTarget.requestPointerLock(),e.pointerCapture||(this.eventStore.add(this.sharedConfig.window,i,"change",this.pointerMove.bind(this)),this.eventStore.add(this.sharedConfig.window,i,"end",this.pointerUp.bind(this)),this.eventStore.add(this.sharedConfig.window,i,"cancel",this.pointerUp.bind(this)))}pointerClean(){this.config.pointerLock&&document.pointerLockElement===this.state.currentTarget&&document.exitPointerLock()}preventScroll(t){this.state._preventScroll&&t.cancelable&&t.preventDefault()}setupScrollPrevention(t){this.state._preventScroll=!1,function(t){"persist"in t&&"function"==typeof t.persist&&t.persist()}(t);const e=this.eventStore.add(this.sharedConfig.window,"touch","change",this.preventScroll.bind(this),{passive:!1});this.eventStore.add(this.sharedConfig.window,"touch","end",e),this.eventStore.add(this.sharedConfig.window,"touch","cancel",e),this.timeoutStore.add("startPointerDrag",this.startPointerDrag.bind(this),this.config.preventScrollDelay,t)}setupDelayTrigger(t){this.state._delayed=!0,this.timeoutStore.add("dragDelay",(()=>{this.state._step=[0,0],this.startPointerDrag(t)}),this.config.delay)}keyDown(t){const e=rh[t.key];if(e){const i=this.state,s=t.shiftKey?10:t.altKey?.1:1;this.start(t),i._delta=e(this.config.keyboardDisplacement,s),i._keyboardActive=!0,kc.addTo(i._movement,i._delta),this.compute(t),this.emit()}}keyUp(t){t.key in rh&&(this.state._keyboardActive=!1,this.setActive(),this.compute(t),this.emit())}bind(t){const e=this.config.device;t(e,"start",this.pointerDown.bind(this)),this.config.pointerCapture&&(t(e,"change",this.pointerMove.bind(this)),t(e,"end",this.pointerUp.bind(this)),t(e,"cancel",this.pointerUp.bind(this)),t("lostPointerCapture","",this.pointerUp.bind(this))),this.config.keys&&(t("key","down",this.keyDown.bind(this)),t("key","up",this.keyUp.bind(this))),this.config.filterTaps&&t("click","",this.pointerClick.bind(this),{capture:!0,passive:!1})}},resolver:hh},ph={key:"pinch",engine:class extends $c{constructor(...t){super(...t),Pc(this,"ingKey","pinching"),Pc(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const t=this.state;t._touchIds=[],t.canceled=!1,t.cancel=this.cancel.bind(this),t.turns=0}computeOffset(){const{type:t,movement:e,lastOffset:i}=this.state;this.state.offset="wheel"===t?kc.add(e,i):[(1+e[0])*i[0],e[1]+i[1]]}computeMovement(){const{offset:t,lastOffset:e}=this.state;this.state.movement=[t[0]/e[0],t[1]-e[1]]}axisIntent(){const t=this.state,[e,i]=t._movement;if(!t.axis){const s=30*Math.abs(e)-Math.abs(i);s<0?t.axis="angle":s>0&&(t.axis="scale")}}restrictToAxis(t){this.config.lockDirection&&("scale"===this.state.axis?t[1]=0:"angle"===this.state.axis&&(t[0]=0))}cancel(){const t=this.state;t.canceled||setTimeout((()=>{t.canceled=!0,t._active=!1,this.compute(),this.emit()}),0)}touchStart(t){this.ctrl.setEventIds(t);const e=this.state,i=this.ctrl.touchIds;if(e._active&&e._touchIds.every((t=>i.has(t))))return;if(i.size<2)return;this.start(t),e._touchIds=Array.from(i).slice(0,2);const s=Gc(t,e._touchIds);s&&this.pinchStart(t,s)}pointerStart(t){if(null!=t.buttons&&t.buttons%2!=1)return;this.ctrl.setEventIds(t),t.target.setPointerCapture(t.pointerId);const e=this.state,i=e._pointerEvents,s=this.ctrl.pointerIds;if(e._active&&Array.from(i.keys()).every((t=>s.has(t))))return;if(i.size<2&&i.set(t.pointerId,t),e._pointerEvents.size<2)return;this.start(t);const r=Hc(...Array.from(i.values()));r&&this.pinchStart(t,r)}pinchStart(t,e){this.state.origin=e.origin,this.computeValues([e.distance,e.angle]),this.computeInitial(),this.compute(t),this.emit()}touchMove(t){if(!this.state._active)return;const e=Gc(t,this.state._touchIds);e&&this.pinchMove(t,e)}pointerMove(t){const e=this.state._pointerEvents;if(e.has(t.pointerId)&&e.set(t.pointerId,t),!this.state._active)return;const i=Hc(...Array.from(e.values()));i&&this.pinchMove(t,i)}pinchMove(t,e){const i=this.state,s=i._values[1],r=e.angle-s;let n=0;Math.abs(r)>270&&(n+=Math.sign(r)),this.computeValues([e.distance,e.angle-360*n]),i.origin=e.origin,i.turns=n,i._movement=[i._values[0]/i._initial[0]-1,i._values[1]-i._initial[1]],this.compute(t),this.emit()}touchEnd(t){this.ctrl.setEventIds(t),this.state._active&&this.state._touchIds.some((t=>!this.ctrl.touchIds.has(t)))&&(this.state._active=!1,this.compute(t),this.emit())}pointerEnd(t){const e=this.state;this.ctrl.setEventIds(t);try{t.target.releasePointerCapture(t.pointerId)}catch(t){}e._pointerEvents.has(t.pointerId)&&e._pointerEvents.delete(t.pointerId),e._active&&e._pointerEvents.size<2&&(e._active=!1,this.compute(t),this.emit())}gestureStart(t){t.cancelable&&t.preventDefault();const e=this.state;e._active||(this.start(t),this.computeValues([t.scale,t.rotation]),e.origin=[t.clientX,t.clientY],this.compute(t),this.emit())}gestureMove(t){if(t.cancelable&&t.preventDefault(),!this.state._active)return;const e=this.state;this.computeValues([t.scale,t.rotation]),e.origin=[t.clientX,t.clientY];const i=e._movement;e._movement=[t.scale-1,t.rotation],e._delta=kc.sub(e._movement,i),this.compute(t),this.emit()}gestureEnd(t){this.state._active&&(this.state._active=!1,this.compute(t),this.emit())}wheel(t){const e=this.config.modifierKey;e&&!(Array.isArray(e)?e.find((e=>t[e])):t[e])||(this.state._active?this.wheelChange(t):this.wheelStart(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(t){this.start(t),this.wheelChange(t)}wheelChange(t){"uv"in t||(t.cancelable&&t.preventDefault(),"development"!==process.env.NODE_ENV||t.defaultPrevented||console.warn("[@use-gesture]: To properly support zoom on trackpads, try using the `target` option.\n\nThis message will only appear in development mode."));const e=this.state;e._delta=[-qc(t)[1]/100*e.offset[0],0],kc.addTo(e._movement,e._delta),function(t){const[e,i]=t.overflow,[s,r]=t._delta,[n,o]=t._direction;(e<0&&s>0&&n<0||e>0&&s<0&&n>0)&&(t._movement[0]=t._movementBound[0]),(i<0&&r>0&&o<0||i>0&&r<0&&o>0)&&(t._movement[1]=t._movementBound[1])}(e),this.state.origin=[t.clientX,t.clientY],this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){const e=this.config.device;e&&(t(e,"start",this[e+"Start"].bind(this)),t(e,"change",this[e+"Move"].bind(this)),t(e,"end",this[e+"End"].bind(this)),t(e,"cancel",this[e+"End"].bind(this)),t("lostPointerCapture","",this[e+"End"].bind(this))),this.config.pinchOnWheel&&t("wheel","",this.wheel.bind(this),{passive:!1})}},resolver:lh};function mh(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}const vh={target(t){if(t)return()=>"current"in t?t.current:t},enabled:(t=!0)=>t,window:(t=(ah.isBrowser?window:void 0))=>t,eventOptions:({passive:t=!0,capture:e=!1}={})=>({passive:t,capture:e}),transform:t=>t},yh=["target","eventOptions","window","enabled","transform"];function _h(t={},e){const i={};for(const[s,r]of Object.entries(e))switch(typeof r){case"function":if("development"===process.env.NODE_ENV){const e=r.call(i,t[s],s,t);Number.isNaN(e)||(i[s]=e)}else i[s]=r.call(i,t[s],s,t);break;case"object":i[s]=_h(t[s],r);break;case"boolean":r&&(i[s]=t[s])}return i}class xh{constructor(t,e){Pc(this,"_listeners",new Set),this._ctrl=t,this._gestureKey=e}add(t,e,i,s,r){const n=this._listeners,o=function(t,e=""){const i=Fc[t];return t+(i&&i[e]||e)}(e,i),a=Ac(Ac({},this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{}),r);t.addEventListener(o,s,a);const c=()=>{t.removeEventListener(o,s,a),n.delete(c)};return n.add(c),c}clean(){this._listeners.forEach((t=>t())),this._listeners.clear()}}class bh{constructor(){Pc(this,"_timeouts",new Map)}add(t,e,i=140,...s){this.remove(t),this._timeouts.set(t,window.setTimeout(e,i,...s))}remove(t){const e=this._timeouts.get(t);e&&window.clearTimeout(e)}clean(){this._timeouts.forEach((t=>{window.clearTimeout(t)})),this._timeouts.clear()}}class wh{constructor(t){Pc(this,"gestures",new Set),Pc(this,"_targetEventStore",new xh(this)),Pc(this,"gestureEventStores",{}),Pc(this,"gestureTimeoutStores",{}),Pc(this,"handlers",{}),Pc(this,"config",{}),Pc(this,"pointerIds",new Set),Pc(this,"touchIds",new Set),Pc(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),function(t,e){e.drag&&Sh(t,"drag");e.wheel&&Sh(t,"wheel");e.scroll&&Sh(t,"scroll");e.move&&Sh(t,"move");e.pinch&&Sh(t,"pinch");e.hover&&Sh(t,"hover")}(this,t)}setEventIds(t){return Vc(t)?(this.touchIds=new Set(zc(t)),this.touchIds):"pointerId"in t?("pointerup"===t.type||"pointercancel"===t.type?this.pointerIds.delete(t.pointerId):"pointerdown"===t.type&&this.pointerIds.add(t.pointerId),this.pointerIds):void 0}applyHandlers(t,e){this.handlers=t,this.nativeHandlers=e}applyConfig(t,e){this.config=function(t,e,i={}){const s=t,{target:r,eventOptions:n,window:o,enabled:a,transform:c}=s,h=mh(s,yh);if(i.shared=_h({target:r,eventOptions:n,window:o,enabled:a,transform:c},vh),e){const t=dh.get(e);i[e]=_h(Ac({shared:i.shared},h),t)}else for(const t in h){const e=dh.get(t);if(e)i[t]=_h(Ac({shared:i.shared},h[t]),e);else if("development"===process.env.NODE_ENV&&!["drag","pinch","scroll","wheel","move","hover"].includes(t)){if("domTarget"===t)throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");console.warn(`[@use-gesture]: Unknown config key \`${t}\` was used. Please read the documentation for further information.`)}}return i}(t,e,this.config)}clean(){this._targetEventStore.clean();for(const t of this.gestures)this.gestureEventStores[t].clean(),this.gestureTimeoutStores[t].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...t){const e=this.config.shared,i={};let s;if(!e.target||(s=e.target(),s)){if(e.enabled){for(const e of this.gestures){const r=this.config[e],n=Ch(i,r.eventOptions,!!s);if(r.enabled){new(uh.get(e))(this,t,e).bind(n)}}const r=Ch(i,e.eventOptions,!!s);for(const e in this.nativeHandlers)r(e,"",(i=>this.nativeHandlers[e](Ac(Ac({},this.state.shared),{},{event:i,args:t}))),void 0,!0)}for(const t in i)i[t]=Qc(...i[t]);if(!s)return i;for(const t in i){const{device:e,capture:r,passive:n}=Xc(t);this._targetEventStore.add(s,e,"",i[t],{capture:r,passive:n})}}}}function Sh(t,e){t.gestures.add(e),t.gestureEventStores[e]=new xh(t,e),t.gestureTimeoutStores[e]=new bh}const Ch=(t,e,i)=>(s,r,n,o={},a=!1)=>{var c,h;const l=null!==(c=o.capture)&&void 0!==c?c:e.capture,u=null!==(h=o.passive)&&void 0!==h?h:e.passive;let d=a?s:Rc(s,r,l);i&&u&&(d+="Passive"),t[d]=t[d]||[],t[d].push(n)};function Th(t,i={},s,r){const n=e.useMemo((()=>new wh(t)),[]);if(n.applyHandlers(t,r),n.applyConfig(i,s),e.useEffect(n.effect.bind(n)),e.useEffect((()=>n.clean.bind(n)),[]),void 0===i.target)return n.bind.bind(n)}const Oh=h.div`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
overflow: hidden;
|
|
@@ -6,4 +6,4 @@ import{jsx as t}from"react/jsx-runtime";import e,{forwardRef as i,useRef as s,us
|
|
|
6
6
|
`,kh=h.canvas`
|
|
7
7
|
${({canDraw:t})=>t&&"cursor: crosshair;"};
|
|
8
8
|
`,Dh=i(((e,i)=>{const{maxSizeInKb:h,baseImageDataURL:l,drawing:u,color:d,erase:g}=e,f=s(null),p=s(null),m=s(),v=s(),y=s(),_=s(),x=s({pinchStartAmount:0}),b=o();r(i,(()=>({clearDrawing:C,export:()=>m.current?(S(),{drawing:m.current.getObjects().map((t=>"image"!==t.type?t:void 0)).filter((t=>t)),dataURL:w()}):{drawing:[],dataURL:""}})));const w=(t=h,e=1)=>{if(v.current){const i=m.current?.toDataURL({format:"jpeg",multiplier:(v.current.width||0)/v.current.getScaledWidth(),quality:e,top:v.current.top,left:v.current.left,height:v.current.getScaledHeight(),width:v.current.getScaledWidth()})||"",s=e-.05;if(s<0)return i;const r=a.getFilesizeFromBase64(i),n=1024*t;return n&&r>n?w(t,s):i}return""};n((()=>{let t;return f.current&&p.current&&(p.current.width=f.current?.clientWidth,p.current.height=f.current?.clientHeight,t=new eo(c.generateId("imageEditor")),m.current=t,m.current.selection=!1,y.current=new Co(m.current),_.current=new Oc(m.current),m.current.freeDrawingBrush=y.current),()=>{t&&t.dispose()}}),[]),n((()=>{const t=async()=>{if(f.current&&p.current&&m.current&&v.current){await new Promise((t=>setTimeout(t))),S();const t=f.current.clientWidth,e=f.current.clientHeight,i=v.current.left||0,s=v.current.top||0;m.current.setWidth(t),m.current.setHeight(e);const r=Math.min(t/v.current.getScaledWidth(),e/v.current.getScaledHeight());T();m.current.getObjects().forEach((t=>{t.cacheKey||(t.scaleX=(t.scaleX||1)*r,t.scaleY=(t.scaleY||1)*r,t.left=(v.current?.left||0)+((t.left||0)-i)*r,t.top=(v.current?.top||0)+((t.top||0)-s)*r),t.setCoords()}))}};return window.addEventListener("resize",t),screen.orientation?.addEventListener("change",t),()=>{window.removeEventListener("resize",t),screen.orientation?.removeEventListener("change",t)}}),[]);const S=()=>{if(m.current){m.current.setZoom(1);const t=m.current.viewportTransform||[0,0,0,0,0,0];t[4]=0,t[5]=0,m.current.requestRenderAll()}},C=()=>{m.current&&m.current.getObjects().forEach((t=>{t.isType("image")||m.current?.remove(t)}))},T=()=>{if(m.current&&v.current){const t=v.current,e=m.current.getWidth()/m.current.getHeight();if((t.width||1)/(t.height||1)<=e?(t.scaleToHeight(m.current?.getHeight()||1),t.left=(m.current.getWidth()-t.getScaledWidth())/2,t.top=0):(t.scaleToWidth(m.current?.getWidth()||1),t.top=(m.current.getHeight()-t.getScaledHeight())/2,t.left=0),b()&&e>1){const e=Math.min((m.current.width||0)/t.getScaledWidth()+.1,5);m.current.zoomToPoint(new It((m.current.width||0)/2,(m.current.height||0)/2),e)}m.current.clipPath=new $r({left:t.left,top:t.top,width:t.getScaledWidth(),height:t.getScaledHeight()}),y.current&&_.current&&(y.current.width=10*(t.scaleX||1),_.current.width=10*(t.scaleX||1)*2),t.setCoords(),m.current.requestRenderAll()}};n((()=>{(async()=>{if(l){const t=await va.fromURL(l);m.current&&(v.current&&m.current.remove(v.current),t.selectable=!1,t.hoverCursor="default",t.erasable=!1,m.current.insertAt(0,t),v.current=t,S(),T())}})()}),[l]),n((()=>{m.current&&(m.current.getObjects().forEach((t=>{"image"!==t.type&&m.current.remove(t)})),u?.forEach((t=>{m.current.add(t)})),m.current.requestRenderAll())}),[u]),n((()=>{m.current&&(d||g?m.current.isDrawingMode=!0:m.current.isDrawingMode&&(m.current.isDrawingMode=!1,S()))}),[d,g]),n((()=>{y.current&&d&&(y.current.color=d)}),[d]),n((()=>{m.current&&(g?m.current.freeDrawingBrush=_.current:y.current&&(m.current.freeDrawingBrush=y.current))}),[g]);const O=t=>{if("undefined"!=typeof TouchEvent&&t.e instanceof TouchEvent&&2===t.e.touches.length&&"undefined"!=typeof TouchEvent&&m.current&&m.current.isDrawingMode){m.current.isDrawingMode=!1;try{m.current.freeDrawingBrush.onMouseUp({e:{}})}catch(t){}const e=m.current.getObjects();e.length>1&&m.current.remove(e[e.length-1])}},k=t=>{"undefined"!=typeof TouchEvent&&t.e instanceof TouchEvent&&0===t.e.touches.length&&(x.current.pinchStartAmount=0,m.current&&(d||g)&&(m.current.isDrawingMode=!0)),m.current?.getObjects().forEach((t=>{t.selectable=!1,t.hoverCursor="default"}))},D=t=>{t.path.erasable=!0};var M,E;return n((()=>(m.current&&(m.current.on("mouse:down",O),m.current.on("mouse:up",k),m.current.on("path:created",D)),()=>{m.current&&(m.current.off("mouse:down",O),m.current.off("mouse:up",k),m.current.on("path:created",D))})),[m.current,d,g]),M=({offset:t,origin:e,touches:i})=>{if((d||g)&&m.current&&2===i)if(0===x.current.pinchStartAmount)x.current.pinchStartAmount=m.current.getZoom();else{const i=t[0];let s=x.current.pinchStartAmount*i;s<1?s=1:s>5&&(s=5);const[r,n]=e;m.current.zoomToPoint(new It(r,n),s)}},E={target:f,pointer:{touch:!0}},gh(ph),Th({pinch:M},E||{},"pinch"),function(t,e){gh(fh),Th({drag:t},e||{},"drag")}((({delta:[t,e],touches:i})=>{if((d||g)&&m.current&&2===i){m.current.relativePan(new It(t,e));const i=m.current.viewportTransform||[],s=m.current.getZoom();i[4]>=0?i[4]=0:i[4]<-m.current.getWidth()*(s-1)&&(i[4]=-m.current.getWidth()*(s-1)),i[5]>=0?i[5]=0:i[5]<-m.current.getHeight()*(s-1)&&(i[5]=-m.current.getHeight()*(s-1))}}),{target:f,pointer:{touch:!0}}),t(Oh,{ref:f,children:t(kh,{id:c.generateId("imageEditor"),ref:p,canDraw:!(!d&&!g)})})}));export{Dh as default};
|
|
9
|
-
//# sourceMappingURL=index.
|
|
9
|
+
//# sourceMappingURL=index.df1ee6f5.js.map
|