@component-hook/pdf-canvas 1.3.2-alpha.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  (function(J,W){typeof exports=="object"&&typeof module<"u"?W(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],W):(J=typeof globalThis<"u"?globalThis:J||self,W(J["pdf-canvas"]={},J.Vue))})(this,(function(J,W){"use strict";var Hl=J=>{throw TypeError(J)};var ko=(J,W,dt)=>W.has(J)||Hl("Cannot "+dt);var pe=(J,W,dt)=>(ko(J,W,"read from private field"),dt?dt.call(J):W.get(J)),Xs=(J,W,dt)=>W.has(J)?Hl("Cannot add the same private member more than once"):W instanceof WeakSet?W.add(J):W.set(J,dt),Si=(J,W,dt,ys)=>(ko(J,W,"write to private field"),ys?ys.call(J,dt):W.set(J,dt),dt),Xn=(J,W,dt)=>(ko(J,W,"access private method"),dt);var zl=(J,W,dt,ys)=>({set _($n){Si(J,W,$n,dt)},get _(){return pe(J,W,ys)}});var Vn,bs,vs,zs,Un,Gs,Yn;var dt=typeof document<"u"?document.currentScript:null;const ys="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e",$n={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},Gl={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},Vl={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},Xl={stroke:"#000",hoverStroke:"#B7EC5D",src:ys},Wl=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];function x(a,t,e){return(t=(function(s){var i=(function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)})(s,"string");return typeof i=="symbol"?i:i+""})(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function Mo(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter((function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable}))),e.push.apply(e,s)}return e}function w(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Mo(Object(e),!0).forEach((function(s){x(a,s,e[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Mo(Object(e)).forEach((function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))}))}return a}function it(a,t){if(a==null)return{};var e,s,i=(function(r,o){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(o.indexOf(l)>=0)continue;h[l]=r[l]}return h})(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function me(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Po{constructor(){x(this,"browserShadowBlurConstant",1),x(this,"DPI",96),x(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),x(this,"perfLimitSizeTotal",2097152),x(this,"maxCacheSideLimit",4096),x(this,"minCacheSideLimit",256),x(this,"disableStyleCopyPaste",!1),x(this,"enableGLFiltering",!0),x(this,"textureSize",4096),x(this,"forceGLPutImageData",!1),x(this,"cachesBoundsOfCurve",!1),x(this,"fontPaths",{}),x(this,"NUM_FRACTION_DIGITS",4)}}const K=new class extends Po{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=w(w({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach((a=>{delete this.fontPaths[a]}))}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new Po,e=a?.reduce(((s,i)=>(s[i]=t[i],s)),{})||t;this.configure(e)}},Me=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[a]("fabric",...e)};class be extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class qn extends be{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Ul{}class Yl extends Ul{testPrecision(t,e){const s="precision ".concat(e,` float;
2
- void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find((s=>this.testPrecision(e,s))),e.getExtension("WEBGL_lose_context").loseContext(),Me("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const $l={};let Oo;const ve=()=>Oo||(Oo={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Yl,dispose(){},copyPasteData:$l}),_s=()=>ve().document,Ws=()=>ve().window,Do=()=>{var a;return Math.max((a=K.devicePixelRatio)!==null&&a!==void 0?a:Ws().devicePixelRatio,1)},Us=new class{constructor(){x(this,"boundsOfCurveCache",{}),this.charWidthsCache=new Map}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase();const i=this.charWidthsCache;i.has(t)||i.set(t,new Map);const n=i.get(t),r="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return n.has(r)||n.set(r,new Map),n.get(r)}clearFontCache(a){a?this.charWidthsCache.delete((a||"").toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(a){const{perfLimitSizeTotal:t}=K,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},Kn="6.9.0";function Ze(){}const ze=Math.PI/2,Pe=2*Math.PI,Jn=Math.PI/180,Rt=Object.freeze([1,0,0,1,0,0]),Zn=16,Ge=.4477152502,X="center",Z="left",Xt="top",Qn="bottom",ft="right",Lt="none",tr=/\r?\n/,Ro="moving",Ci="scaling",Lo="rotating",er="rotate",Fo="skewing",Ys="resizing",ql="modifyPoly",Kl="modifyPath",Ai="changed",Ti="scale",Ft="scaleX",qt="scaleY",ws="skewX",xs="skewY",bt="fill",It="stroke",Ei="modified",Ss="json",sr="svg",F=new class{constructor(){this[Ss]=new Map,this[sr]=new Map}has(a){return this[Ss].has(a)}getClass(a){const t=this[Ss].get(a);if(!t)throw new be("No class registered for ".concat(a));return t}setClass(a,t){t?this[Ss].set(t,a):(this[Ss].set(a.type,a),this[Ss].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[sr].get(a)}setSVGClass(a,t){this[sr].set(t??a.type.toLowerCase(),a)}},ki=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach((t=>t.abort())),a}cancelByCanvas(a){if(!a)return[];const t=this.filter((e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a}));return t.forEach((e=>e.abort())),t}cancelByTarget(a){if(!a)return[];const t=this.filter((e=>e.target===a));return t.forEach((e=>e.abort())),t}};class Jl{constructor(){x(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach((s=>{let[i,n]=s;this.on(i,n)})),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach((i=>{let[n,r]=i;s.push(this.once(n,r))})),()=>s.forEach((i=>i()))}if(e){const s=this.on(t,(function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()}));return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach((s=>{let[i,n]=s;this._removeEventListener(i,n)})):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Qe=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},re=a=>{if(a===0)return 1;switch(Math.abs(a)/ze){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},oe=a=>{if(a===0)return 0;const t=a/ze,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class C{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new C(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new C(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new C(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new C(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new C(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new C(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new C(this.x/t.x,this.y/t.y)}scalarDivide(t){return new C(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&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new C(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new C(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new C(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new C(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ir;const s=oe(t),i=re(t),n=this.subtract(e);return new C(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new C(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 ir=new C(0,0),Mi=a=>!!a&&Array.isArray(a._objects);function Io(a){class t extends a{constructor(){super(...arguments),x(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach((o=>this._onObjectAdded(o))),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach((o=>this._onObjectAdded(o))),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach((h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))})),i}forEachObject(s){this.getObjects().forEach(((i,n,r)=>s(i,n,r)))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter((r=>r.isType(...i)))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some((n=>n instanceof t&&n.contains(s,!0)))}complexity(){return this._objects.reduce(((s,i)=>s+=i.complexity?i.complexity():0),0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Qe(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Qe(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return Qe(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return Qe(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Qe(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],c=new C(i,n),u=c.add(new C(r,o));for(let d=this._objects.length-1;d>=0;d--){const f=this._objects[d];f.selectable&&f.visible&&(h&&f.intersectsWithRect(c,u)||f.isContainedWithinRect(c,u)||h&&f.containsPoint(c)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class No extends Jl{_setOptions(){let t=arguments.length>0&&arguments[0]!==void 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 typeof t=="object"?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){const e=this.get(t);return typeof e=="boolean"&&this.set(t,!e),this}get(t){return this[t]}}function $s(a){return Ws().requestAnimationFrame(a)}function jo(a){return Ws().cancelAnimationFrame(a)}let Zl=0;const Ve=()=>Zl++,ye=()=>{const a=_s().createElement("canvas");if(!a||a.getContext===void 0)throw new be("Failed to create `canvas` element");return a},Bo=()=>_s().createElement("img"),Kt=a=>{const t=ye();return t.width=a.width,t.height=a.height,t},nr=(a,t,e)=>a.toDataURL("image/".concat(t),e),rr=(a,t,e)=>new Promise(((s,i)=>{a.toBlob(s,"image/".concat(t),e)})),lt=a=>a*Jn,_e=a=>a/Jn,Ho=a=>a.every(((t,e)=>t===Rt[e])),Tt=(a,t,e)=>new C(a).transform(t,e),Wt=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new C(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},gt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Pi=(a,t)=>a.reduceRight(((e,s)=>s&&e?gt(s,e,t):s||e),void 0)||Rt.concat(),zo=a=>{let[t,e]=a;return Math.atan2(e,t)},ts=a=>{const t=zo(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:_e(t),scaleX:s,scaleY:i,skewX:_e(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Cs=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function es(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=lt(a),i=re(s),n=oe(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Oi=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},Go=a=>Math.tan(lt(a)),or=a=>[1,0,Go(a),1,0,0],ar=a=>[1,Go(a),0,1,0,0],qs=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Oi(s?-t:t,i?-e:e);return n&&(o=gt(o,or(n),!0)),r&&(o=gt(o,ar(r),!0)),o},Vo=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Cs(t,e);s&&(i=gt(i,es({angle:s})));const n=qs(a);return Ho(n)||(i=gt(i,n)),i},Ks=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((function(s,i){if(t&&t.aborted)return i(new qn("loadImage"));const n=Bo();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&t?.removeEventListener("abort",r),s(n)};a?(n.onload=o,n.onerror=function(){r&&t?.removeEventListener("abort",r),i(new be("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()}))},As=function(a){let{signal:t,reviver:e=Ze}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map((r=>F.getClass(r.type).fromObject(r,{signal:t}).then((o=>(e(r,o),n.push(o),o)))))).then(s).catch((r=>{n.forEach((o=>{o.dispose&&o.dispose()})),i(r)})).finally((()=>{t&&t.removeEventListener("abort",i)}))}))},Js=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map((o=>o&&o.type&&F.has(o.type)?As([o],{signal:t}).then((h=>{let[l]=h;return i.push(l),l})):o)),r=Object.keys(a);Promise.all(n).then((o=>o.reduce(((h,l,c)=>(h[r[c]]=l,h)),{}))).then(e).catch((o=>{i.forEach((h=>{h.dispose&&h.dispose()})),s(o)})).finally((()=>{t&&t.removeEventListener("abort",s)}))}))},ss=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce(((t,e)=>(e in a&&(t[e]=a[e]),t)),{})},hr=(a,t)=>Object.keys(a).reduce(((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e)),{}),et=(a,t)=>parseFloat(Number(a).toFixed(t)),Ts=a=>"matrix("+a.map((t=>et(t,K.NUM_FRACTION_DIGITS))).join(" ")+")",ee=a=>!!a&&a.toLive!==void 0,Xo=a=>!!a&&typeof a.toObject=="function",Wo=a=>!!a&&a.offsetX!==void 0&&"source"in a,is=a=>!!a&&"multiSelectionStacking"in a;function Uo(a){const t=a&&ae(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const ae=a=>a.ownerDocument||null,Yo=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},$o=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},lr=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function qo(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Lt,a}class Ko{constructor(t){x(this,"_originalCanvasStyle",void 0),x(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&_s().getElementById(t)||ye();var s;if(e.hasAttribute("data-fabric"))throw new be("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;$o(s,i,t,e)}setCSSDimensions(t){lr(this.lower.el,t)}calcOffset(){return(function(t){var e;const s=t&&ae(t),i={left:0,top:0};if(!s)return i;const n=((e=Yo(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=Uo(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}})(this.lower.el)}dispose(){ve().dispose(this.lower.el),delete this.lower}}const Ql={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Rt]},tc=["objects"];class Zs extends Io(No){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return Zs.ownDefaults}constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?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 Ko(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(Me("warn",`Canvas is trying to add an object that belongs to a different canvas.
2
+ void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find((s=>this.testPrecision(e,s))),e.getExtension("WEBGL_lose_context").loseContext(),Me("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const $l={};let Oo;const ve=()=>Oo||(Oo={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Yl,dispose(){},copyPasteData:$l}),_s=()=>ve().document,Ws=()=>ve().window,Do=()=>{var a;return Math.max((a=K.devicePixelRatio)!==null&&a!==void 0?a:Ws().devicePixelRatio,1)},Us=new class{constructor(){x(this,"boundsOfCurveCache",{}),this.charWidthsCache=new Map}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase();const i=this.charWidthsCache;i.has(t)||i.set(t,new Map);const n=i.get(t),r="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return n.has(r)||n.set(r,new Map),n.get(r)}clearFontCache(a){a?this.charWidthsCache.delete((a||"").toLowerCase()):this.charWidthsCache=new Map}limitDimsByArea(a){const{perfLimitSizeTotal:t}=K,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},Kn="6.9.1";function Ze(){}const ze=Math.PI/2,Pe=2*Math.PI,Jn=Math.PI/180,Rt=Object.freeze([1,0,0,1,0,0]),Zn=16,Ge=.4477152502,X="center",Z="left",Xt="top",Qn="bottom",ft="right",Lt="none",tr=/\r?\n/,Ro="moving",Ci="scaling",Lo="rotating",er="rotate",Fo="skewing",Ys="resizing",ql="modifyPoly",Kl="modifyPath",Ai="changed",Ti="scale",Ft="scaleX",qt="scaleY",ws="skewX",xs="skewY",bt="fill",It="stroke",Ei="modified",Ss="json",sr="svg",F=new class{constructor(){this[Ss]=new Map,this[sr]=new Map}has(a){return this[Ss].has(a)}getClass(a){const t=this[Ss].get(a);if(!t)throw new be("No class registered for ".concat(a));return t}setClass(a,t){t?this[Ss].set(t,a):(this[Ss].set(a.type,a),this[Ss].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[sr].get(a)}setSVGClass(a,t){this[sr].set(t??a.type.toLowerCase(),a)}},ki=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach((t=>t.abort())),a}cancelByCanvas(a){if(!a)return[];const t=this.filter((e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a}));return t.forEach((e=>e.abort())),t}cancelByTarget(a){if(!a)return[];const t=this.filter((e=>e.target===a));return t.forEach((e=>e.abort())),t}};class Jl{constructor(){x(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach((s=>{let[i,n]=s;this.on(i,n)})),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach((i=>{let[n,r]=i;s.push(this.once(n,r))})),()=>s.forEach((i=>i()))}if(e){const s=this.on(t,(function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()}));return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach((s=>{let[i,n]=s;this._removeEventListener(i,n)})):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Qe=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},re=a=>{if(a===0)return 1;switch(Math.abs(a)/ze){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},oe=a=>{if(a===0)return 0;const t=a/ze,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class C{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new C(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new C(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new C(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new C(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new C(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new C(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new C(this.x/t.x,this.y/t.y)}scalarDivide(t){return new C(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&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new C(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new C(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new C(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new C(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ir;const s=oe(t),i=re(t),n=this.subtract(e);return new C(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new C(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 ir=new C(0,0),Mi=a=>!!a&&Array.isArray(a._objects);function Io(a){class t extends a{constructor(){super(...arguments),x(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach((o=>this._onObjectAdded(o))),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach((o=>this._onObjectAdded(o))),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach((h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))})),i}forEachObject(s){this.getObjects().forEach(((i,n,r)=>s(i,n,r)))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter((r=>r.isType(...i)))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some((n=>n instanceof t&&n.contains(s,!0)))}complexity(){return this._objects.reduce(((s,i)=>s+=i.complexity?i.complexity():0),0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Qe(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Qe(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return Qe(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return Qe(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Qe(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],c=new C(i,n),u=c.add(new C(r,o));for(let d=this._objects.length-1;d>=0;d--){const f=this._objects[d];f.selectable&&f.visible&&(h&&f.intersectsWithRect(c,u)||f.isContainedWithinRect(c,u)||h&&f.containsPoint(c)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class No extends Jl{_setOptions(){let t=arguments.length>0&&arguments[0]!==void 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 typeof t=="object"?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){const e=this.get(t);return typeof e=="boolean"&&this.set(t,!e),this}get(t){return this[t]}}function $s(a){return Ws().requestAnimationFrame(a)}function jo(a){return Ws().cancelAnimationFrame(a)}let Zl=0;const Ve=()=>Zl++,ye=()=>{const a=_s().createElement("canvas");if(!a||a.getContext===void 0)throw new be("Failed to create `canvas` element");return a},Bo=()=>_s().createElement("img"),Kt=a=>{const t=ye();return t.width=a.width,t.height=a.height,t},nr=(a,t,e)=>a.toDataURL("image/".concat(t),e),rr=(a,t,e)=>new Promise(((s,i)=>{a.toBlob(s,"image/".concat(t),e)})),lt=a=>a*Jn,_e=a=>a/Jn,Ho=a=>a.every(((t,e)=>t===Rt[e])),Tt=(a,t,e)=>new C(a).transform(t,e),Wt=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new C(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},gt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Pi=(a,t)=>a.reduceRight(((e,s)=>s&&e?gt(s,e,t):s||e),void 0)||Rt.concat(),zo=a=>{let[t,e]=a;return Math.atan2(e,t)},ts=a=>{const t=zo(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:_e(t),scaleX:s,scaleY:i,skewX:_e(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Cs=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function es(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=lt(a),i=re(s),n=oe(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Oi=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},Go=a=>Math.tan(lt(a)),or=a=>[1,0,Go(a),1,0,0],ar=a=>[1,Go(a),0,1,0,0],qs=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Oi(s?-t:t,i?-e:e);return n&&(o=gt(o,or(n),!0)),r&&(o=gt(o,ar(r),!0)),o},Vo=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Cs(t,e);s&&(i=gt(i,es({angle:s})));const n=qs(a);return Ho(n)||(i=gt(i,n)),i},Ks=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((function(s,i){if(t&&t.aborted)return i(new qn("loadImage"));const n=Bo();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&t?.removeEventListener("abort",r),s(n)};a?(n.onload=o,n.onerror=function(){r&&t?.removeEventListener("abort",r),i(new be("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()}))},As=function(a){let{signal:t,reviver:e=Ze}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map((r=>F.getClass(r.type).fromObject(r,{signal:t}).then((o=>(e(r,o),n.push(o),o)))))).then(s).catch((r=>{n.forEach((o=>{o.dispose&&o.dispose()})),i(r)})).finally((()=>{t&&t.removeEventListener("abort",i)}))}))},Js=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map((o=>o&&o.type&&F.has(o.type)?As([o],{signal:t}).then((h=>{let[l]=h;return i.push(l),l})):o)),r=Object.keys(a);Promise.all(n).then((o=>o.reduce(((h,l,c)=>(h[r[c]]=l,h)),{}))).then(e).catch((o=>{i.forEach((h=>{h.dispose&&h.dispose()})),s(o)})).finally((()=>{t&&t.removeEventListener("abort",s)}))}))},ss=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce(((t,e)=>(e in a&&(t[e]=a[e]),t)),{})},hr=(a,t)=>Object.keys(a).reduce(((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e)),{}),et=(a,t)=>parseFloat(Number(a).toFixed(t)),Ts=a=>"matrix("+a.map((t=>et(t,K.NUM_FRACTION_DIGITS))).join(" ")+")",ee=a=>!!a&&a.toLive!==void 0,Xo=a=>!!a&&typeof a.toObject=="function",Wo=a=>!!a&&a.offsetX!==void 0&&"source"in a,is=a=>!!a&&"multiSelectionStacking"in a;function Uo(a){const t=a&&ae(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const ae=a=>a.ownerDocument||null,Yo=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},$o=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},lr=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function qo(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=Lt,a}class Ko{constructor(t){x(this,"_originalCanvasStyle",void 0),x(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&_s().getElementById(t)||ye();var s;if(e.hasAttribute("data-fabric"))throw new be("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;$o(s,i,t,e)}setCSSDimensions(t){lr(this.lower.el,t)}calcOffset(){return(function(t){var e;const s=t&&ae(t),i={left:0,top:0};if(!s)return i;const n=((e=Yo(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=Uo(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}})(this.lower.el)}dispose(){ve().dispose(this.lower.el),delete this.lower}}const Ql={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Rt]},tc=["objects"];class Zs extends Io(No){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return Zs.ownDefaults}constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?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 Ko(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(Me("warn",`Canvas is trying to add an object that belongs to a different canvas.
3
3
  Resulting 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?Do():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e){const i=w({width:this.width,height:this.height},t);this.elements.setDimensions(i,this.getRetinaScaling()),this.hasLostContext=!0,this.width=i.width,this.height=i.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const s=t,i=[...this.viewportTransform],n=Tt(t,Wt(i));i[0]=e,i[3]=e;const r=Tt(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new C(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 C(-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=$s((()=>this.renderAndReset())))}calcViewportBoundaries(){const t=this.width,e=this.height,s=Wt(this.viewportTransform),i=Tt({x:0,y:0},s),n=Tt({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new C(o.x,r.y),bl:new C(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(jo(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const o=ee(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?s.toLive(t):s,r&&t.transform(...n),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=r,r&&t.transform(...n),i.render(t),this.skipOffscreen=h,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 C(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new C(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new C(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 C(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new C(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return Tt(this.getCenterPoint(),Wt(this.viewportTransform))}_centerObject(t,e){t.setXY(e,X,X),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return w(w(w({version:Kn},ss(this,e)),{},{objects:this._objects.filter((n=>!n.excludeFromExport)).map((n=>this._toObject(n,t,e)))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),n}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,n=this.overlayImage,r=this.backgroundColor,o=this.overlayColor;return ee(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),ee(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
4
4
  `)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
5
5
  `),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
@@ -38,7 +38,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
38
38
  `),s=[];let i=-1,n={};a=Mr(a);for(let r=0;r<e.length;r++){const o=Ui(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const l=a[r][h];l&&Object.keys(l).length>0&&(Yi(n,l,!0)?s.push({start:i,end:i+1,style:l}):s[s.length-1].end++),n=l||{}}else i+=o.length,n={}}return s},Xa=(a,t)=>{if(!Array.isArray(a))return Mr(a);const e=t.split(tr),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=Ui(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=w({},a[n].style),i===a[n].end-1&&n++)}return s},Xe=["display","transform",bt,"fill-opacity","fill-rule","opacity",It,"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 Wa(a,t){const e=a.nodeName,s=a.getAttribute("class"),i=a.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)r=new RegExp("\\."+o[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function Xc(a,t){let e=!0;const s=Wa(a,t.pop());return s&&t.length&&(e=(function(i,n){let r,o=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)o&&(r=n.pop()),o=Wa(i=i.parentElement,r);return n.length===0})(a,t)),s&&e&&t.length===0}const Wc=a=>{var t;return(t=hc[a])!==null&&t!==void 0?t:a},Uc=new RegExp("(".concat(le,")"),"gi"),Yc=a=>Fi(a.replace(Uc," $1 ").replace(/,/gi," "));var Ua,Ya,$a,qa,Ka,Ja,Za;const jt="(".concat(le,")"),$c=String.raw(Ua||(Ua=me(["(skewX)(",")"],["(skewX)\\(","\\)"])),jt),qc=String.raw(Ya||(Ya=me(["(skewY)(",")"],["(skewY)\\(","\\)"])),jt),Kc=String.raw($a||($a=me(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),jt,jt,jt),Jc=String.raw(qa||(qa=me(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),jt,jt),Zc=String.raw(Ka||(Ka=me(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),jt,jt),Qc=String.raw(Ja||(Ja=me(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),jt,jt,jt,jt,jt,jt),Pr="(?:".concat(Qc,"|").concat(Zc,"|").concat(Kc,"|").concat(Jc,"|").concat($c,"|").concat(qc,")"),tu="(?:".concat(Pr,"*)"),eu=String.raw(Za||(Za=me(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),tu),su=new RegExp(eu),iu=new RegExp(Pr),nu=new RegExp(Pr,"g");function $i(a){const t=[];if(!(a=Yc(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!su.test(a))return[...Rt];for(const e of a.matchAll(nu)){const s=iu.exec(e[0]);if(!s)continue;let i=Rt;const n=s.filter((g=>!!g)),[,r,...o]=n,[h,l,c,u,d,f]=o.map((g=>parseFloat(g)));switch(r){case"translate":i=Cs(h,l);break;case er:i=es({angle:h},{x:l,y:c});break;case Ti:i=Oi(h,l);break;case ws:i=or(h);break;case xs:i=ar(h);break;case"matrix":i=[h,l,c,u,d,f]}t.push(i)}return Pi(t)}function ru(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==bt&&a!==It||t!==Lt){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===Lt?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?gt(e.transformMatrix,$i(t)):$i(t);else if(a==="visible")r=t!==Lt&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(a==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(a==="textAnchor")r=t==="start"?Z:t==="end"?ft:X;else if(a==="charSpacing"||a===rs)n=Nt(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(bt),h=t.indexOf(It);r=bt,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=It)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(Nt):Nt(t,s)}}else r="";return!i&&isNaN(n)?r:n}function ou(a,t){const e=a.match(ac);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],o=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=Nt(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Or(a,t){a.replace(/;\s*$/,"").split(";").forEach((e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()}))}function au(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Or(e,t):(function(s,i){Object.entries(s).forEach((n=>{let[r,o]=n;o!==void 0&&(i[r.toLowerCase()]=o)}))})(e,t)),t}const hu={stroke:"strokeOpacity",fill:"fillOpacity"};function Le(a,t,e){if(!a)return{};let s,i={},n=Zn;a.parentNode&&ya.test(a.parentNode.nodeName)&&(i=Le(a.parentElement,t,e),i.fontSize&&(s=n=Nt(i.fontSize)));const r=w(w(w({},t.reduce(((l,c)=>{const u=a.getAttribute(c);return u&&(l[c]=u),l}),{})),(function(l){let c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u={};for(const d in c)Xc(l,d.split(" "))&&(u=w(w({},u),c[d]));return u})(a,e)),au(a));r[vr]&&a.setAttribute(vr,r[vr]),r[br]&&(s=Nt(r[br],n),r[br]="".concat(s));const o={};for(const l in r){const c=Wc(l),u=ru(c,r[l],i,s);o[c]=u}o&&o.font&&ou(o.font,o);const h=w(w({},i),o);return ya.test(a.nodeName)?h:(function(l){const c=Et.getDefaults();return Object.entries(hu).forEach((u=>{let[d,f]=u;if(l[f]===void 0||l[d]==="")return;if(l[d]===void 0){if(!c[d])return;l[d]=c[d]}if(l[d].indexOf("url(")===0)return;const g=new tt(l[d]);l[d]=g.setAlpha(et(g.getAlpha()*l[f],2)).toRgba()})),l})(h)}const lu=["left","top","width","height","visible"],Qa=["rx","ry"];class Se extends Et{static getDefaults(){return w(w({},super.getDefaults()),Se.ownDefaults)}constructor(t){super(),Object.assign(this,Se.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,n=-s/2,r=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,h=r!==0||o!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Ge*r,n,i+e,n+Ge*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-Ge*o,i+e-Ge*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Ge*r,n+s,i,n+s-Ge*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+Ge*o,i+Ge*r,n,i+r,n),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Qa,...t])}_toSVG(){const{width:t,height:e,rx:s,ry:i}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(s,'" ry="').concat(i,'" width="').concat(t,'" height="').concat(e,`" />
39
39
  `)]}static async fromElement(t,e,s){const i=Le(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:l=!0}=i,c=it(i,lu);return new this(w(w(w({},e),c),{},{left:n,top:r,width:o,height:h,visible:!!(l&&o&&h)}))}}x(Se,"type","Rect"),x(Se,"cacheProperties",[...De,...Qa]),x(Se,"ownDefaults",{rx:0,ry:0}),x(Se,"ATTRIBUTE_NAMES",[...Xe,"x","y","rx","ry","width","height"]),F.setClass(Se),F.setSVGClass(Se);const Fe="initialization",qi="added",Dr="removed",Ki="imperative",th=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Qs(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),c=e&&l?ea(new C(s,s),void 0,a.calcTransformMatrix()):ir,u=!e&&l?s:0,d=Ri(i+u,n+u,Pi([o,t.calcOwnMatrix()],!0)).add(c).scalarDivide(2);return[h.subtract(d),h.add(d)]};class Ji{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===Fe||e===Ki||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Fe&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Ki&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=we(t.map((u=>th(i,u))).reduce(((u,d)=>u.concat(d)),[])),l=new C(o,h),c=new C(n,r).add(l.scalarDivide(2));if(s===Fe){const u=this.getInitialSize(e,{size:l,center:c});return{center:c,relativeCorrection:new C(0,0),size:u}}return{center:c.transform(i.calcOwnMatrix()),size:l}}}x(Ji,"type","strategy");class Rr extends Ji{shouldPerformLayout(t){return!0}}x(Rr,"type","fit-content"),F.setClass(Rr);const cu=["strategy"],uu=["target","strategy","bubbles","prevStrategy"],eh="layoutManager";class oi{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Rr;x(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=w(w({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Ei,Ro,Ys,Lo,Ci,Fo,Ai,ql,Kl].map((i=>t.on(i,(n=>this.performLayout(i===Ei?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach((s=>s())),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach((e=>this.unsubscribe(e,t)))}subscribeTargets(t){t.targets.forEach((e=>this.subscribe(e,t)))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===Fe||s===qi?this.subscribeTargets(t):s===Dr&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Ki&&t.deep){const n=it(t,cu);e.forEachObject((r=>r.layoutManager&&r.layoutManager.performLayout(w(w({},n),{},{bubbles:!1,target:r}))))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===Fe?new C:e.getRelativeCenterPoint(),{center:o,correction:h=new C,relativeCorrection:l=new C}=n,c=r.subtract(o).add(h).transform(i===Fe?Rt:Wt(e.calcOwnMatrix()),!0).add(l);return{result:n,prevCenter:r,nextCenter:o,offset:c}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===Fe?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*vt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*vt(s.originY)}):(s.setPositionByOrigin(n,X,X),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject((i=>{i.group===s&&this.layoutObject(t,e,i)})),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=it(t,uu),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const l=s.parent;n&&l!=null&&l.layoutManager&&((o.path||(o.path=[])).push(s),l.layoutManager.performLayout(w(w({},o),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach((e=>e.forEach((s=>s())))),t.clear()}toObject(){return{type:eh,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}F.setClass(oi,eh);const du=["type","objects","layoutManager"];class fu extends oi{performLayout(){}}class Jt extends Io(Et){static getDefaults(){return w(w({},super.getDefaults()),Jt.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),x(this,"_activeObjects",[]),x(this,"__objectSelectionTracker",void 0),x(this,"__objectSelectionDisposer",void 0),Object.assign(this,Jt.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject((i=>{this.enterGroup(i,!1)})),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new oi,this.layoutManager.performLayout({type:Fe,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Me("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Me("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter(((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s))}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(qi,i),n}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(qi,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Dr,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==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:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,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&&Es(t,gt(Wt(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Es(t,gt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=Et.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...Wt(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject((t=>t.setCoords()))}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(w({target:this,type:Ki},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter((function(i){return!i.excludeFromExport})).map((function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r}))}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return w(w(w({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||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=Se.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
40
40
  `],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toSVG(t));return e.push(`</g>
41
- `),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=it(t,du);return Promise.all([As(i,e),Js(r,e)]).then((o=>{let[h,l]=o;const c=new this(h,w(w(w({},r),l),{},{layoutManager:new fu}));if(n){const u=F.getClass(n.type),d=F.getClass(n.strategy);c.layoutManager=new u(new d)}else c.layoutManager=new oi;return c.layoutManager.subscribeTargets({type:Fe,target:c,targets:c.getObjects()}),c.setCoords(),c}))}}x(Jt,"type","Group"),x(Jt,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),F.setClass(Jt);const sh=(a,t)=>Math.min(t.width/a.width,t.height/a.height),ih=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Lr="\\s*,?\\s*",ai="".concat(Lr,"(").concat(le,")"),gu="".concat(ai).concat(ai).concat(ai).concat(Lr,"([01])").concat(Lr,"([01])").concat(ai).concat(ai),pu={m:"l",M:"L"},mu=(a,t,e,s,i,n,r,o,h,l,c)=>{const u=re(a),d=oe(a),f=re(t),g=oe(t),p=e*i*f-s*n*g+r,b=s*i*f+e*n*g+o;return["C",l+h*(-e*i*d-s*n*u),c+h*(-s*i*d+e*n*u),p+h*(e*i*g+s*n*f),b+h*(s*i*g-e*n*f),p,b]},nh=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Fr(a,t,e,s,i,n,r,o){let h;if(K.cachesBoundsOfCurve&&(h=[...arguments].join(),Us.boundsOfCurveCache[h]))return Us.boundsOfCurveCache[h];const l=Math.sqrt,c=Math.abs,u=[],d=[[0,0],[0,0]];let f=6*a-12*e+6*i,g=-3*a+9*e-9*i+3*r,p=3*e-3*a;for(let _=0;_<2;++_){if(_>0&&(f=6*t-12*s+6*n,g=-3*t+9*s-9*n+3*o,p=3*s-3*t),c(g)<1e-12){if(c(f)<1e-12)continue;const P=-p/f;0<P&&P<1&&u.push(P);continue}const S=f*f-4*p*g;if(S<0)continue;const A=l(S),T=(-f+A)/(2*g);0<T&&T<1&&u.push(T);const E=(-f-A)/(2*g);0<E&&E<1&&u.push(E)}let b=u.length;const m=b,v=oh(a,t,e,s,i,n,r,o);for(;b--;){const{x:_,y:S}=v(u[b]);d[0][b]=_,d[1][b]=S}d[0][m]=a,d[1][m]=t,d[0][m+1]=r,d[1][m+1]=o;const y=[new C(Math.min(...d[0]),Math.min(...d[1])),new C(Math.max(...d[0]),Math.max(...d[1]))];return K.cachesBoundsOfCurve&&(Us.boundsOfCurveCache[h]=y),y}const bu=(a,t,e)=>{let[s,i,n,r,o,h,l,c]=e;const u=((d,f,g,p,b,m,v)=>{if(g===0||p===0)return[];let y=0,_=0,S=0;const A=Math.PI,T=v*Jn,E=oe(T),P=re(T),N=.5*(-P*d-E*f),D=.5*(-P*f+E*d),L=g**2,k=p**2,O=D**2,j=N**2,M=L*k-L*O-k*j;let R=Math.abs(g),G=Math.abs(p);if(M<0){const ke=Math.sqrt(1-M/(L*k));R*=ke,G*=ke}else S=(b===m?-1:1)*Math.sqrt(M/(L*O+k*j));const at=S*R*D/G,ct=-S*G*N/R,At=P*at-E*ct+.5*d,wt=E*at+P*ct+.5*f;let nt=nh(1,0,(N-at)/R,(D-ct)/G),Vt=nh((N-at)/R,(D-ct)/G,(-N-at)/R,(-D-ct)/G);m===0&&Vt>0?Vt-=2*A:m===1&&Vt<0&&(Vt+=2*A);const Ee=Math.ceil(Math.abs(Vt/A*2)),ut=[],Q=Vt/Ee,Je=8/3*Math.sin(Q/4)*Math.sin(Q/4)/Math.sin(Q/2);let Vs=nt+Q;for(let ke=0;ke<Ee;ke++)ut[ke]=mu(nt,Vs,P,E,R,G,At,wt,Je,y,_),y=ut[ke][5],_=ut[ke][6],nt=Vs,Vs+=Q;return ut})(l-a,c-t,i,n,o,h,r);for(let d=0,f=u.length;d<f;d++)u[d][1]+=a,u[d][2]+=t,u[d][3]+=a,u[d][4]+=t,u[d][5]+=a,u[d][6]+=t;return u},rh=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){const c=[...l];let u;switch(c[0]){case"l":c[1]+=t,c[2]+=e;case"L":t=c[1],e=c[2],u=["L",t,e];break;case"h":c[1]+=t;case"H":t=c[1],u=["L",t,e];break;case"v":c[1]+=e;case"V":e=c[1],u=["L",t,e];break;case"m":c[1]+=t,c[2]+=e;case"M":t=c[1],e=c[2],s=c[1],i=c[2],u=["M",t,e];break;case"c":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e,c[5]+=t,c[6]+=e;case"C":o=c[3],h=c[4],t=c[5],e=c[6],u=["C",c[1],c[2],o,h,t,e];break;case"s":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[3],e=c[4],u=["C",o,h,c[1],c[2],t,e],o=u[3],h=u[4];break;case"q":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"Q":o=c[1],h=c[2],t=c[3],e=c[4],u=["Q",o,h,t,e];break;case"t":c[1]+=t,c[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[1],e=c[2],u=["Q",o,h,t,e];break;case"a":c[6]+=t,c[7]+=e;case"A":bu(t,e,c).forEach((d=>n.push(d))),t=c[6],e=c[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),r=u[0]):r=""}return n},Zi=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),oh=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,c=(f=>3*f**2*(1-f))(h),u=(f=>3*f*(1-f)**2)(h),d=(f=>(1-f)**3)(h);return new C(r*l+i*c+e*u+a*d,o*l+n*c+s*u+t*d)},ah=a=>a**2,hh=a=>2*a*(1-a),lh=a=>(1-a)**2,vu=(a,t,e,s,i,n,r,o)=>h=>{const l=ah(h),c=hh(h),u=lh(h),d=3*(u*(e-a)+c*(i-e)+l*(r-i)),f=3*(u*(s-t)+c*(n-s)+l*(o-n));return Math.atan2(f,d)},yu=(a,t,e,s,i,n)=>r=>{const o=ah(r),h=hh(r),l=lh(r);return new C(i*o+e*h+a*l,n*o+s*h+t*l)},_u=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},ch=(a,t,e)=>{let s=new C(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=Zi(s.x,s.y,r.x,r.y),s=r}return i},wu=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=w({},n),o=.01,h=0;const l=a.iterator,c=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=Zi(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return w(w({},r),{},{angle:c(h)})},Ir=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){const c={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=c,e.x=r=i=l[1],e.y=o=n=l[2];break;case"L":e=c,e.length=Zi(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=oh(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=c,e.iterator=t,e.angleFinder=vu(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=ch(t,i,n),i=l[5],n=l[6];break;case"Q":t=yu(i,n,l[1],l[2],l[3],l[4]),e=c,e.iterator=t,e.angleFinder=_u(i,n,l[1],l[2],l[3],l[4]),e.length=ch(t,i,n),i=l[3],n=l[4];break;case"Z":e=c,e.destX=r,e.destY=o,e.length=Zi(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},uh=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ir(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return w(w({},new C(i.x,i.y).lerp(new C(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return w(w({},new C(i.x,i.y).lerp(new C(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return wu(i,t)}},xu=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),dh=new RegExp(gu,"g"),Su=new RegExp(le,"gi"),Cu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},fh=a=>{var t;const e=[],s=(t=a.match(xu))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Cu[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){dh.lastIndex=0;for(let h=null;h=dh.exec(i);)o.push(...h.slice(1))}else o=i.match(Su)||[];for(let h=0;h<o.length;h+=r){const l=new Array(r),c=pu[n];l[0]=h>0&&c?c:n;for(let u=0;u<r;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},Au=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new C(a[0]),s=new C(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let l;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),l=1;l<o;l++){if(!e.eq(s)){const c=e.midPointFrom(s);r.push(["Q",e.x,e.y,c.x,c.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},gh=(a,t)=>a.map((e=>e.map(((s,i)=>i===0||t===void 0?s:et(s,t))).join(" "))).join(" ");function Qi(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach((s=>{let[i,n]=s;return e.setProperty(i,n)})))}const Tu=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function ph(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Ze,s=new(Ws()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Ze};if(i&&i.aborted)throw new qn("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Ze)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const tn=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=ts(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Ft,i),s.set(qt,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,X,X)};var Eu=Object.freeze({__proto__:null,addTransformToObject:Qo,animate:Tr,animateColor:Ma,applyTransformToObject:Es,calcAngleBetweenVectors:zi,calcDimensionsMatrix:qs,calcPlaneChangeMatrix:Qs,calcVectorRotation:xa,cancelAnimFrame:jo,capValue:os,composeMatrix:Vo,copyCanvasElement:a=>{var t;const e=Kt(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:re,createCanvasElement:ye,createImage:Bo,createRotateMatrix:es,createScaleMatrix:Oi,createSkewXMatrix:or,createSkewYMatrix:ar,createTranslateMatrix:Cs,createVector:Bi,crossProduct:ks,degreesToRadians:lt,dotProduct:Sa,ease:gc,enlivenObjectEnlivables:Js,enlivenObjects:As,findScaleToCover:ih,findScaleToFit:sh,getBoundsOfCurve:Fr,getOrthonormalVector:_r,getPathSegmentsInfo:Ir,getPointOnPath:uh,getPointer:Jo,getRandomInt:Tu,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-ze;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new C(re(r),oe(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:Au,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:Gi,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new Jt(a,t),hasStyleChanged:Yi,invertTransform:Wt,isBetweenVectors:wr,isIdentityMatrix:Ho,isTouchEvent:Di,isTransparent:ja,joinPath:gh,loadImage:Ks,magnitude:Hi,makeBoundingBoxFromPoints:we,makePathSimpler:rh,matrixToSVG:Ts,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),ur(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new Jt([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:gt,multiplyTransformMatrixArray:Pi,parsePath:fh,parsePreserveAspectRatioAttribute:gr,parseUnit:Nt,pick:ss,projectStrokeOnPoints:za,qrDecompose:ts,radiansToDegrees:_e,removeFromArray:Qe,removeTransformFromObject:(a,t)=>{const e=Wt(t),s=gt(e,a.calcOwnMatrix());Es(a,s)},removeTransformMatrixForSvgParsing:tn,request:ph,requestAnimFrame:$s,resetObjectTransform:ta,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:yr,saveObjectTransform:cr,sendObjectToPlane:ur,sendPointToPlane:ns,sendVectorToPlane:ea,setStyle:Qi,sin:oe,sizeAfterTransform:Ri,string:Vc,stylesFromArray:Xa,stylesToArray:Va,toBlob:rr,toDataURL:nr,toFixed:et,transformPath:(a,t,e)=>(e&&(t=gt(t,[1,0,0,1,-e.x,-e.y])),a.map((s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=Tt({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i}))),transformPoint:Tt});class ku extends Ko{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),x(this,"upper",void 0),x(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=ye();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=_s().createElement("div");return t.setAttribute("data-fabric","wrapper"),Qi(t,{position:"relative"}),qo(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Qi(t,w(w({},s),{},{"touch-action":i?"manipulation":Lt})),qo(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;$o(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),lr(this.upper.el,t),lr(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),ve().dispose(this.upper.el),delete this.upper,delete this.container}}class en extends Zs{constructor(){super(...arguments),x(this,"targets",[]),x(this,"_hoveredTargets",[]),x(this,"_currentTransform",null),x(this,"_groupSelector",null),x(this,"contextTopDirty",!1)}static getDefaults(){return w(w({},super.getDefaults()),en.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new ku(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return ja(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((s=>!!s&&t[s]===!0)):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===Ti||e===Ft||e===qt||e===Ys?i=this.centeredScaling||t.centeredScaling:e===er&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=ft:["mr","tr","br"].includes(e)&&(s.x=Z),["tl","mt","tr"].includes(e)?s.y=Qn:["bl","mb","br"].includes(e)&&(s.y=Xt)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?ns(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):nc,l=((f,g,p,b)=>{if(!g||!f)return"drag";const m=b.controls[g];return m.getActionName(p,m,b)})(s,r,t,e),c=t[this.centeredKey],u=this._shouldCenterTransform(e,l,c)?{x:X,y:X}:this._getOriginFromCorner(e,r),d={target:e,action:l,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:lt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:c,original:w(w({},cr(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s).transform(this.viewportTransform),o=new C(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,o.x),c=Math.min(r.y,o.y),u=Math.max(r.x,o.x),d=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,c,u-l,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,c+=h,u-=h,d-=h,Et.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,c,u-l,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Di(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,l]=s,c=Math.atan2(o.y-r.y,o.x-r.x),u=re(c)*n,d=oe(c)*n,f=u+d,g=u-d;s=[new C(r.x-g,r.y-f),new C(o.x+f,o.y-g),new C(h.x+g,h.y+f),new C(l.x-f,l.y+g)]}return ht.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,ns(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Mi(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Mi(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Mi(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=Jo(t),r=i.width||0,o=i.height||0;r&&o||(Xt in i&&Qn in i&&(o=Math.abs(i.top-i.bottom)),ft in i&&Z in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=ns(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new C(1,1):new C(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ye(),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 is(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach((h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))})),n.forEach((h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))})),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,is(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),is(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Ei,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;is(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&is(e)&&this._activeObject===e){const s=ss(t,["angle","flipX","flipY",Z,Ft,qt,ws,xs,Xt]);return Qo(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}x(en,"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 Mu{constructor(t){x(this,"targets",[]),x(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.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),Qe(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||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 Pu=["target","oldTarget","fireCanvas","e"],Zt={passive:!1},Rs=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},We=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},se=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},Ou={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 Nr extends en{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),x(this,"_isClick",void 0),x(this,"textEditingManager",new Mu(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((e=>{this[e]=this[e].bind(this)})),this.addOrRemove(We,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Yo(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Zt),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel,{passive:!1}),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Zt)}removeListeners(){this.addOrRemove(se,"remove");const t=this._getEventPrefix(),e=ae(this.upperCanvasEl);se(e,"".concat(t,"up"),this._onMouseUp),se(e,"touchend",this._onTouchEnd,Zt),se(e,"".concat(t,"move"),this._onMouseMove,Zt),se(e,"touchmove",this._onMouseMove,Zt),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=w({e:t},Rs(this,t));this.fire("mouse:out",w(w({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",w({},s)),this._hoveredTargets.forEach((i=>{this.fire("mouse:out",w(w({},s),{},{target:i})),i&&i.fire("mouseout",w({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",w({e:t},Rs(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void We(this.upperCanvasEl,"drag",this._onDragProgress)}Zo(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e?.clearContextTop(),s!==e&&s?.clearContextTop();const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==Lt,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};se(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const l=i[h];l.canDrop(t)&&(o=l),l.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",w({e:t,target:e,subTargets:s,dragSource:this._dragSource},Rs(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&Zo(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&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 t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=ae(i);We(r,"touchend",this._onTouchEnd,Zt),e&&We(r,"touchmove",this._onMouseMove,Zt),se(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();se(e,"".concat(s,"move"),this._onMouseMove,Zt);const i=ae(e);We(i,"".concat(s,"up"),this._onMouseUp),We(i,"".concat(s,"move"),this._onMouseMove,Zt)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=ae(this.upperCanvasEl);se(s,"touchend",this._onTouchEnd,Zt),se(s,"touchmove",this._onMouseMove,Zt),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{We(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=ae(this.upperCanvasEl);se(i,"".concat(s,"up"),this._onMouseUp),se(i,"".concat(s,"move"),this._onMouseMove,Zt),We(e,"".concat(s,"move"),this._onMouseMove,Zt)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const c=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!c&&n===this._activeObject)}if(n){const c=n.findControl(this.getViewportPoint(t),Di(t)),{key:u,control:d}=c||{};if(h=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(d){const f=d.getMouseUpHandler(t,n,d);f&&(o=this.getScenePoint(t),f.call(d,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const c=s.target&&s.target.controls[s.corner],u=c&&c.getMouseUpHandler(t,s.target,c);o=o||this.getScenePoint(t),u&&u.call(c,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],r=w(w(w({e:t,target:i,subTargets:n},Rs(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Di(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);const h=o?o.control:void 0,l=this.getScenePoint(t),c=h&&h.getMouseDownHandler(t,e,h);c&&c.call(h,t,this._currentTransform,l.x,l.y)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=ns(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)n[o]===e||i[o]&&i[o]===s||this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=it(e,Pu);const{targetIn:h,targetOut:l,canvasIn:c,canvasOut:u}=Ou[t],d=i!==s;if(i&&d){const f=w(w({},o),{},{e:r,target:i,nextTarget:s},Rs(this,r));n&&this.fire(u,f),i.fire(l,f)}if(s&&d){const f=w(w({},o),{},{e:r,target:s,previousTarget:i},Rs(this,r));n&&this.fire(c,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?ns(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=is(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((r=>{s=r.hoverCursor||s})),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=is(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(F.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s),o=r.add(new C(i,n)),h=r.min(o),l=r.max(o).subtract(h),c=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=r.eq(o)?c[0]?[c[0]]:[]:c.length>1?c.filter((d=>!d.onSelect({e:t}))).reverse():c;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=F.getClass("ActiveSelection");this.setActiveObject(new d(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const mh={x1:0,y1:0,x2:0,y2:0},Du=w(w({},mh),{},{r1:0,r2:0}),Ls=(a,t)=>isNaN(a)&&typeof t=="number"?t:a;function bh(a){return a&&/%$/.test(a)&&Number.isFinite(parseFloat(a))}function vh(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(bh(a)?100:1):NaN;return os(0,Ls(e,t),1)}const Ru=/\s*;\s*/,Lu=/\s*:\s*/;function Fu(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(Ru);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(Lu).map((c=>c.trim()));h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new tt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:vh(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Ls(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function Iu(a,t){const e=[],s=a.getElementsByTagName("stop"),i=vh(t,1);for(let n=s.length;n--;)e.push(Fu(s[n],i));return e}function yh(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function _h(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function ue(a,t){return a.getAttribute(t)}function Nu(a,t){return(function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.entries(e).reduce(((h,l)=>{let[c,u]=l;if(u==="Infinity")i=1;else if(u==="-Infinity")i=0;else{const d=typeof u=="string";i=d?parseFloat(u):u,d&&bh(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))}return h[c]=i,h}),{})})(yh(a)==="linear"?(function(e){return{x1:ue(e,"x1")||0,y1:ue(e,"y1")||0,x2:ue(e,"x2")||"100%",y2:ue(e,"y2")||0}})(a):(function(e){return{x1:ue(e,"fx")||ue(e,"cx")||"50%",y1:ue(e,"fy")||ue(e,"cy")||"50%",r1:0,x2:ue(e,"cx")||"50%",y2:ue(e,"cy")||"50%",r2:ue(e,"r")||"50%"}})(a),w(w({},t),{},{gradientUnits:_h(a)}))}class hi{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:w(w({},e==="radial"?Du:mh),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(Ve()):Ve()})}addColorStop(t){for(const e in t){const s=new tt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return w(w({},ss(this,t)),{},{type:this.type,coords:w({},this.coords),colorStops:this.colorStops.map((e=>w({},e))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Rt.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map((u=>w({},u))).sort(((u,d)=>u.offset-d.offset));let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const c=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Ts(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:f,y2:g}=this.coords;s.push("<linearGradient ",c,' x1="',u,'" y1="',d,'" x2="',f,'" y2="',g,`">
41
+ `),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=it(t,du);return Promise.all([As(i,e),Js(r,e)]).then((o=>{let[h,l]=o;const c=new this(h,w(w(w({},r),l),{},{layoutManager:new fu}));if(n){const u=F.getClass(n.type),d=F.getClass(n.strategy);c.layoutManager=new u(new d)}else c.layoutManager=new oi;return c.layoutManager.subscribeTargets({type:Fe,target:c,targets:c.getObjects()}),c.setCoords(),c}))}}x(Jt,"type","Group"),x(Jt,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),F.setClass(Jt);const sh=(a,t)=>Math.min(t.width/a.width,t.height/a.height),ih=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Lr="\\s*,?\\s*",ai="".concat(Lr,"(").concat(le,")"),gu="".concat(ai).concat(ai).concat(ai).concat(Lr,"([01])").concat(Lr,"([01])").concat(ai).concat(ai),pu={m:"l",M:"L"},mu=(a,t,e,s,i,n,r,o,h,l,c)=>{const u=re(a),d=oe(a),f=re(t),g=oe(t),p=e*i*f-s*n*g+r,b=s*i*f+e*n*g+o;return["C",l+h*(-e*i*d-s*n*u),c+h*(-s*i*d+e*n*u),p+h*(e*i*g+s*n*f),b+h*(s*i*g-e*n*f),p,b]},nh=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Fr(a,t,e,s,i,n,r,o){let h;if(K.cachesBoundsOfCurve&&(h=[...arguments].join(),Us.boundsOfCurveCache[h]))return Us.boundsOfCurveCache[h];const l=Math.sqrt,c=Math.abs,u=[],d=[[0,0],[0,0]];let f=6*a-12*e+6*i,g=-3*a+9*e-9*i+3*r,p=3*e-3*a;for(let _=0;_<2;++_){if(_>0&&(f=6*t-12*s+6*n,g=-3*t+9*s-9*n+3*o,p=3*s-3*t),c(g)<1e-12){if(c(f)<1e-12)continue;const P=-p/f;0<P&&P<1&&u.push(P);continue}const S=f*f-4*p*g;if(S<0)continue;const A=l(S),T=(-f+A)/(2*g);0<T&&T<1&&u.push(T);const E=(-f-A)/(2*g);0<E&&E<1&&u.push(E)}let b=u.length;const m=b,v=oh(a,t,e,s,i,n,r,o);for(;b--;){const{x:_,y:S}=v(u[b]);d[0][b]=_,d[1][b]=S}d[0][m]=a,d[1][m]=t,d[0][m+1]=r,d[1][m+1]=o;const y=[new C(Math.min(...d[0]),Math.min(...d[1])),new C(Math.max(...d[0]),Math.max(...d[1]))];return K.cachesBoundsOfCurve&&(Us.boundsOfCurveCache[h]=y),y}const bu=(a,t,e)=>{let[s,i,n,r,o,h,l,c]=e;const u=((d,f,g,p,b,m,v)=>{if(g===0||p===0)return[];let y=0,_=0,S=0;const A=Math.PI,T=v*Jn,E=oe(T),P=re(T),N=.5*(-P*d-E*f),D=.5*(-P*f+E*d),L=g**2,k=p**2,O=D**2,j=N**2,M=L*k-L*O-k*j;let R=Math.abs(g),G=Math.abs(p);if(M<0){const ke=Math.sqrt(1-M/(L*k));R*=ke,G*=ke}else S=(b===m?-1:1)*Math.sqrt(M/(L*O+k*j));const at=S*R*D/G,ct=-S*G*N/R,At=P*at-E*ct+.5*d,wt=E*at+P*ct+.5*f;let nt=nh(1,0,(N-at)/R,(D-ct)/G),Vt=nh((N-at)/R,(D-ct)/G,(-N-at)/R,(-D-ct)/G);m===0&&Vt>0?Vt-=2*A:m===1&&Vt<0&&(Vt+=2*A);const Ee=Math.ceil(Math.abs(Vt/A*2)),ut=[],Q=Vt/Ee,Je=8/3*Math.sin(Q/4)*Math.sin(Q/4)/Math.sin(Q/2);let Vs=nt+Q;for(let ke=0;ke<Ee;ke++)ut[ke]=mu(nt,Vs,P,E,R,G,At,wt,Je,y,_),y=ut[ke][5],_=ut[ke][6],nt=Vs,Vs+=Q;return ut})(l-a,c-t,i,n,o,h,r);for(let d=0,f=u.length;d<f;d++)u[d][1]+=a,u[d][2]+=t,u[d][3]+=a,u[d][4]+=t,u[d][5]+=a,u[d][6]+=t;return u},rh=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const l of a){const c=[...l];let u;switch(c[0]){case"l":c[1]+=t,c[2]+=e;case"L":t=c[1],e=c[2],u=["L",t,e];break;case"h":c[1]+=t;case"H":t=c[1],u=["L",t,e];break;case"v":c[1]+=e;case"V":e=c[1],u=["L",t,e];break;case"m":c[1]+=t,c[2]+=e;case"M":t=c[1],e=c[2],s=c[1],i=c[2],u=["M",t,e];break;case"c":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e,c[5]+=t,c[6]+=e;case"C":o=c[3],h=c[4],t=c[5],e=c[6],u=["C",c[1],c[2],o,h,t,e];break;case"s":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[3],e=c[4],u=["C",o,h,c[1],c[2],t,e],o=u[3],h=u[4];break;case"q":c[1]+=t,c[2]+=e,c[3]+=t,c[4]+=e;case"Q":o=c[1],h=c[2],t=c[3],e=c[4],u=["Q",o,h,t,e];break;case"t":c[1]+=t,c[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=c[1],e=c[2],u=["Q",o,h,t,e];break;case"a":c[6]+=t,c[7]+=e;case"A":bu(t,e,c).forEach((d=>n.push(d))),t=c[6],e=c[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),r=u[0]):r=""}return n},Zi=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),oh=(a,t,e,s,i,n,r,o)=>h=>{const l=h**3,c=(f=>3*f**2*(1-f))(h),u=(f=>3*f*(1-f)**2)(h),d=(f=>(1-f)**3)(h);return new C(r*l+i*c+e*u+a*d,o*l+n*c+s*u+t*d)},ah=a=>a**2,hh=a=>2*a*(1-a),lh=a=>(1-a)**2,vu=(a,t,e,s,i,n,r,o)=>h=>{const l=ah(h),c=hh(h),u=lh(h),d=3*(u*(e-a)+c*(i-e)+l*(r-i)),f=3*(u*(s-t)+c*(n-s)+l*(o-n));return Math.atan2(f,d)},yu=(a,t,e,s,i,n)=>r=>{const o=ah(r),h=hh(r),l=lh(r);return new C(i*o+e*h+a*l,n*o+s*h+t*l)},_u=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),l=2*(o*(s-t)+r*(n-s));return Math.atan2(l,h)},ch=(a,t,e)=>{let s=new C(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=Zi(s.x,s.y,r.x,r.y),s=r}return i},wu=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=w({},n),o=.01,h=0;const l=a.iterator,c=a.angleFinder;for(;i<t&&o>1e-4;)r=l(s),h=s,e=Zi(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return w(w({},r),{},{angle:c(h)})},Ir=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const l of a){const c={x:i,y:n,command:l[0],length:0};switch(l[0]){case"M":e=c,e.x=r=i=l[1],e.y=o=n=l[2];break;case"L":e=c,e.length=Zi(i,n,l[1],l[2]),i=l[1],n=l[2];break;case"C":t=oh(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e=c,e.iterator=t,e.angleFinder=vu(i,n,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=ch(t,i,n),i=l[5],n=l[6];break;case"Q":t=yu(i,n,l[1],l[2],l[3],l[4]),e=c,e.iterator=t,e.angleFinder=_u(i,n,l[1],l[2],l[3],l[4]),e.length=ch(t,i,n),i=l[3],n=l[4];break;case"Z":e=c,e.destX=r,e.destY=o,e.length=Zi(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},uh=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ir(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return w(w({},new C(i.x,i.y).lerp(new C(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return w(w({},new C(i.x,i.y).lerp(new C(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return wu(i,t)}},xu=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),dh=new RegExp(gu,"g"),Su=new RegExp(le,"gi"),Cu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},fh=a=>{var t;const e=[],s=(t=a.match(xu))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Cu[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){dh.lastIndex=0;for(let h=null;h=dh.exec(i);)o.push(...h.slice(1))}else o=i.match(Su)||[];for(let h=0;h<o.length;h+=r){const l=new Array(r),c=pu[n];l[0]=h>0&&c?c:n;for(let u=0;u<r;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},Au=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new C(a[0]),s=new C(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let l;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),l=1;l<o;l++){if(!e.eq(s)){const c=e.midPointFrom(s);r.push(["Q",e.x,e.y,c.x,c.y])}e=a[l],l+1<a.length&&(s=a[l+1])}return h&&(i=e.x>a[l-2].x?1:e.x===a[l-2].x?0:-1,n=e.y>a[l-2].y?1:e.y===a[l-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},gh=(a,t)=>a.map((e=>e.map(((s,i)=>i===0||t===void 0?s:et(s,t))).join(" "))).join(" ");function Qi(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach((s=>{let[i,n]=s;return e.setProperty(i,n)})))}const Tu=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function ph(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Ze,s=new(Ws()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Ze};if(i&&i.aborted)throw new qn("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=Ze)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const tn=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=ts(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Ft,i),s.set(qt,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,X,X)};var Eu=Object.freeze({__proto__:null,addTransformToObject:Qo,animate:Tr,animateColor:Ma,applyTransformToObject:Es,calcAngleBetweenVectors:zi,calcDimensionsMatrix:qs,calcPlaneChangeMatrix:Qs,calcVectorRotation:xa,cancelAnimFrame:jo,capValue:os,composeMatrix:Vo,copyCanvasElement:a=>{var t;const e=Kt(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:re,createCanvasElement:ye,createImage:Bo,createRotateMatrix:es,createScaleMatrix:Oi,createSkewXMatrix:or,createSkewYMatrix:ar,createTranslateMatrix:Cs,createVector:Bi,crossProduct:ks,degreesToRadians:lt,dotProduct:Sa,ease:gc,enlivenObjectEnlivables:Js,enlivenObjects:As,findScaleToCover:ih,findScaleToFit:sh,getBoundsOfCurve:Fr,getOrthonormalVector:_r,getPathSegmentsInfo:Ir,getPointOnPath:uh,getPointer:Jo,getRandomInt:Tu,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-ze;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new C(re(r),oe(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:Au,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:Gi,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new Jt(a,t),hasStyleChanged:Yi,invertTransform:Wt,isBetweenVectors:wr,isIdentityMatrix:Ho,isTouchEvent:Di,isTransparent:ja,joinPath:gh,loadImage:Ks,magnitude:Hi,makeBoundingBoxFromPoints:we,makePathSimpler:rh,matrixToSVG:Ts,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),ur(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new Jt([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:gt,multiplyTransformMatrixArray:Pi,parsePath:fh,parsePreserveAspectRatioAttribute:gr,parseUnit:Nt,pick:ss,projectStrokeOnPoints:za,qrDecompose:ts,radiansToDegrees:_e,removeFromArray:Qe,removeTransformFromObject:(a,t)=>{const e=Wt(t),s=gt(e,a.calcOwnMatrix());Es(a,s)},removeTransformMatrixForSvgParsing:tn,request:ph,requestAnimFrame:$s,resetObjectTransform:ta,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:yr,saveObjectTransform:cr,sendObjectToPlane:ur,sendPointToPlane:ns,sendVectorToPlane:ea,setStyle:Qi,sin:oe,sizeAfterTransform:Ri,string:Vc,stylesFromArray:Xa,stylesToArray:Va,toBlob:rr,toDataURL:nr,toFixed:et,transformPath:(a,t,e)=>(e&&(t=gt(t,[1,0,0,1,-e.x,-e.y])),a.map((s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=Tt({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i}))),transformPoint:Tt});class ku extends Ko{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),x(this,"upper",void 0),x(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=ye();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=_s().createElement("div");return t.setAttribute("data-fabric","wrapper"),Qi(t,{position:"relative"}),qo(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Qi(t,w(w({},s),{},{"touch-action":i?"manipulation":Lt})),qo(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;$o(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),lr(this.upper.el,t),lr(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),ve().dispose(this.upper.el),delete this.upper,delete this.container}}class en extends Zs{constructor(){super(...arguments),x(this,"targets",[]),x(this,"_hoveredTargets",[]),x(this,"_currentTransform",null),x(this,"_groupSelector",null),x(this,"contextTopDirty",!1)}static getDefaults(){return w(w({},super.getDefaults()),en.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new ku(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter((e=>!e.group&&e!==t)).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return ja(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find((s=>!!s&&t[s]===!0)):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===Ti||e===Ft||e===qt||e===Ys?i=this.centeredScaling||t.centeredScaling:e===er&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=ft:["mr","tr","br"].includes(e)&&(s.x=Z),["tl","mt","tr"].includes(e)?s.y=Qn:["bl","mb","br"].includes(e)&&(s.y=Xt)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?ns(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):nc,l=((f,g,p,b)=>{if(!g||!f)return"drag";const m=b.controls[g];return m.getActionName(p,m,b)})(s,r,t,e),c=t[this.centeredKey],u=this._shouldCenterTransform(e,l,c)?{x:X,y:X}:this._getOriginFromCorner(e,r),d={target:e,action:l,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:lt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:c,original:w(w({},cr(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s).transform(this.viewportTransform),o=new C(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(r.x,o.x),c=Math.min(r.y,o.y),u=Math.max(r.x,o.x),d=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,c,u-l,d-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,c+=h,u-=h,d-=h,Et.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,c,u-l,d-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Di(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,l]=s,c=Math.atan2(o.y-r.y,o.x-r.x),u=re(c)*n,d=oe(c)*n,f=u+d,g=u-d;s=[new C(r.x-g,r.y-f),new C(o.x+f,o.y-g),new C(h.x+g,h.y+f),new C(l.x-f,l.y+g)]}return ht.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,ns(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Mi(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Mi(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Mi(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=Jo(t),r=i.width||0,o=i.height||0;r&&o||(Xt in i&&Qn in i&&(o=Math.abs(i.top-i.bottom)),ft in i&&Z in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=ns(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const l=r===0||o===0?new C(1,1):new C(s.width/r,s.height/o);return n.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ye(),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 is(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach((h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))})),n.forEach((h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))})),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,is(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),is(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Ei,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;is(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&is(e)&&this._activeObject===e){const s=ss(t,["angle","flipX","flipY",Z,Ft,qt,ws,xs,Xt]);return Qo(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}x(en,"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 Mu{constructor(t){x(this,"targets",[]),x(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.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),Qe(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||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 Pu=["target","oldTarget","fireCanvas","e"],Zt={passive:!1},Rs=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},We=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},se=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},Ou={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 Nr extends en{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),x(this,"_isClick",void 0),x(this,"textEditingManager",new Mu(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach((e=>{this[e]=this[e].bind(this)})),this.addOrRemove(We,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Yo(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Zt),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel,{passive:!1}),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Zt)}removeListeners(){this.addOrRemove(se,"remove");const t=this._getEventPrefix(),e=ae(this.upperCanvasEl);se(e,"".concat(t,"up"),this._onMouseUp),se(e,"touchend",this._onTouchEnd,Zt),se(e,"".concat(t,"move"),this._onMouseMove,Zt),se(e,"touchmove",this._onMouseMove,Zt),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=w({e:t},Rs(this,t));this.fire("mouse:out",w(w({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",w({},s)),this._hoveredTargets.forEach((i=>{this.fire("mouse:out",w(w({},s),{},{target:i})),i&&i.fire("mouseout",w({},s))})),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",w({e:t},Rs(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void We(this.upperCanvasEl,"drag",this._onDragProgress)}Zo(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e?.clearContextTop(),s!==e&&s?.clearContextTop();const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==Lt,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};se(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const l=i[h];l.canDrop(t)&&(o=l),l.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",w({e:t,target:e,subTargets:s,dragSource:this._dragSource},Rs(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&Zo(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&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 t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=ae(i);We(r,"touchend",this._onTouchEnd,Zt),e&&We(r,"touchmove",this._onMouseMove,Zt),se(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();se(e,"".concat(s,"move"),this._onMouseMove,Zt);const i=ae(e);We(i,"".concat(s,"up"),this._onMouseUp),We(i,"".concat(s,"move"),this._onMouseMove,Zt)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=ae(this.upperCanvasEl);se(s,"touchend",this._onTouchEnd,Zt),se(s,"touchmove",this._onMouseMove,Zt),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((()=>{We(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0}),400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=ae(this.upperCanvasEl);se(i,"".concat(s,"up"),this._onMouseUp),se(i,"".concat(s,"move"),this._onMouseMove,Zt),We(e,"".concat(s,"move"),this._onMouseMove,Zt)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,l=!1;if(s&&(this._finalizeCurrentTransform(t),l=s.actionPerformed),!i){const c=n===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(n)||!c&&n===this._activeObject)}if(n){const c=n.findControl(this.getViewportPoint(t),Di(t)),{key:u,control:d}=c||{};if(h=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),l=!0;else if(d){const f=d.getMouseUpHandler(t,n,d);f&&(o=this.getScenePoint(t),f.call(d,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const c=s.target&&s.target.controls[s.corner],u=c&&c.getMouseUpHandler(t,s.target,c);o=o||this.getScenePoint(t),u&&u.call(c,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),l?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e,s){const i=this._target,n=this.targets||[],r=w(w(w({e:t,target:i,subTargets:n},Rs(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Di(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);const h=o?o.control:void 0,l=this.getScenePoint(t),c=h&&h.getMouseDownHandler(t,e,h);c&&c.call(h,t,this._currentTransform,l.x,l.y)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=ns(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)n[o]===e||i[o]&&i[o]===s||this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",w(w({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=it(e,Pu);const{targetIn:h,targetOut:l,canvasIn:c,canvasOut:u}=Ou[t],d=i!==s;if(i&&d){const f=w(w({},o),{},{e:r,target:i,nextTarget:s},Rs(this,r));n&&this.fire(u,f),i.fire(l,f)}if(s&&d){const f=w(w({},o),{},{e:r,target:s,previousTarget:i},Rs(this,r));n&&this.fire(c,f),s.fire(h,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?ns(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=is(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map((r=>{s=r.hoverCursor||s})),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=is(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(F.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new C(e,s),o=r.add(new C(i,n)),h=r.min(o),l=r.max(o).subtract(h),c=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=r.eq(o)?c[0]?[c[0]]:[]:c.length>1?c.filter((d=>!d.onSelect({e:t}))).reverse():c;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=F.getClass("ActiveSelection");this.setActiveObject(new d(u,{canvas:this}),t)}return this._groupSelector=null,!0}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,e=arguments.length>1?arguments[1]:void 0;const{upper:s}=this.elements;s.ctx=void 0;const i=super.toCanvasElement(t,e);return s.ctx=s.el.getContext("2d"),i}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const mh={x1:0,y1:0,x2:0,y2:0},Du=w(w({},mh),{},{r1:0,r2:0}),Ls=(a,t)=>isNaN(a)&&typeof t=="number"?t:a;function bh(a){return a&&/%$/.test(a)&&Number.isFinite(parseFloat(a))}function vh(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(bh(a)?100:1):NaN;return os(0,Ls(e,t),1)}const Ru=/\s*;\s*/,Lu=/\s*:\s*/;function Fu(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(Ru);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,l]=r[o].split(Lu).map((c=>c.trim()));h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const n=new tt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:vh(a.getAttribute("offset"),0),color:n.toRgb(),opacity:Ls(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function Iu(a,t){const e=[],s=a.getElementsByTagName("stop"),i=vh(t,1);for(let n=s.length;n--;)e.push(Fu(s[n],i));return e}function yh(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function _h(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function ue(a,t){return a.getAttribute(t)}function Nu(a,t){return(function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.entries(e).reduce(((h,l)=>{let[c,u]=l;if(u==="Infinity")i=1;else if(u==="-Infinity")i=0;else{const d=typeof u=="string";i=d?parseFloat(u):u,d&&bh(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))}return h[c]=i,h}),{})})(yh(a)==="linear"?(function(e){return{x1:ue(e,"x1")||0,y1:ue(e,"y1")||0,x2:ue(e,"x2")||"100%",y2:ue(e,"y2")||0}})(a):(function(e){return{x1:ue(e,"fx")||ue(e,"cx")||"50%",y1:ue(e,"fy")||ue(e,"cy")||"50%",r1:0,x2:ue(e,"cx")||"50%",y2:ue(e,"cy")||"50%",r2:ue(e,"r")||"50%"}})(a),w(w({},t),{},{gradientUnits:_h(a)}))}class hi{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:w(w({},e==="radial"?Du:mh),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(Ve()):Ve()})}addColorStop(t){for(const e in t){const s=new tt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return w(w({},ss(this,t)),{},{type:this.type,coords:w({},this.coords),colorStops:this.colorStops.map((e=>w({},e))),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Rt.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map((u=>w({},u))).sort(((u,d)=>u.offset-d.offset));let o=-this.offsetX,h=-this.offsetY;var l;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(l=t)&&typeof l._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const c=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Ts(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:f,y2:g}=this.coords;s.push("<linearGradient ",c,' x1="',u,'" y1="',d,'" x2="',f,'" y2="',g,`">
42
42
  `)}else if(this.type==="radial"){const{x1:u,y1:d,x2:f,y2:g,r1:p,r2:b}=this.coords,m=p>b;s.push("<radialGradient ",c,' cx="',m?u:f,'" cy="',m?d:g,'" r="',m?p:b,'" fx="',m?f:u,'" fy="',m?g:d,`">
43
43
  `),m&&(r.reverse(),r.forEach((y=>{y.offset=1-y.offset})));const v=Math.min(p,b);if(v>0){const y=v/Math.max(p,b);r.forEach((_=>{_.offset+=y*(1-_.offset)}))}}return r.forEach((u=>{let{color:d,offset:f,opacity:g}=u;s.push("<stop ",'offset="',100*f+"%",'" style="stop-color:',d,g!==void 0?";stop-opacity: "+g:";",`"/>
44
44
  `)})),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
@@ -50,7 +50,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
50
50
  `)]}static async fromElement(t,e,s){const i=Le(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],it(i,Gu))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=it(t,Vu);return this._fromObject(w(w({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}x(hs,"type","Line"),x(hs,"cacheProperties",[...De,...Br]),x(hs,"ATTRIBUTE_NAMES",Xe.concat(Br)),F.setClass(hs),F.setSVGClass(hs);class ls extends Et{static getDefaults(){return w(w({},super.getDefaults()),ls.ownDefaults)}constructor(t){super(),Object.assign(this,ls.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}x(ls,"type","Triangle"),x(ls,"ownDefaults",{width:100,height:100}),F.setClass(ls),F.setSVGClass(ls);const xh=["rx","ry"];class Ne extends Et{static getDefaults(){return w(w({},super.getDefaults()),Ne.ownDefaults)}constructor(t){super(),Object.assign(this,Ne.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(Ft)}getRy(){return this.get("ry")*this.get(qt)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...xh,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
51
51
  `)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Pe,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Le(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function Xu(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}x(Ne,"type","Ellipse"),x(Ne,"cacheProperties",[...De,...xh]),x(Ne,"ownDefaults",{rx:0,ry:0}),x(Ne,"ATTRIBUTE_NAMES",[...Xe,"cx","cy","rx","ry"]),F.setClass(Ne),F.setSVGClass(Ne);const Wu=["left","top"],Sh={exactBoundingBox:!1};class de extends Et{static getDefaults(){return w(w({},super.getDefaults()),de.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),x(this,"strokeDiff",void 0),Object.assign(this,de.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(Z,s),typeof i=="number"&&this.set(Xt,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return za(this.points,t,this.isOpen())}_calcDimensions(t){t=w({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((l=>l.projectedPoint)):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new C,strokeOffset:new C,strokeDiff:new C};const s=we(e),i=qs(w(w({},t),{},{scaleX:1,scaleY:1})),n=we(this.points.map((l=>Tt(l,i,!0)))),r=new C(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(lt(this.skewX)),h-=o*Math.tan(lt(this.skewY))),w(w({},s),{},{pathOffset:new C(o,h),strokeOffset:new C(n.left,n.top).subtract(new C(s.left,s.top)).multiply(r),strokeDiff:new C(s.width,s.height).subtract(new C(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=we(this.points);return new C(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new C(e+i/2,s+n/2),X,X)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new C(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some((o=>this.strokeUniform||this.constructor.layoutProperties.includes(o)))){var e,s;const{width:o,height:h}=this._calcDimensions(t);r=new C((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new C((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new C(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===Ft||t===qt)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return w(w({},super.toObject(t)),{},{points:this.points.map((e=>{let{x:s,y:i}=e;return{x:s,y:i}}))})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=K.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(et(this.points[n].x-e,i),",",et(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
52
52
  `)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(Xu(t.getAttribute("points")),w(w({},it(Le(t,this.ATTRIBUTE_NAMES,s),Wu)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}x(de,"ownDefaults",Sh),x(de,"type","Polyline"),x(de,"layoutProperties",[ws,xs,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),x(de,"cacheProperties",[...De,"points"]),x(de,"ATTRIBUTE_NAMES",[...Xe]),F.setClass(de),F.setSVGClass(de);class sn extends de{isOpen(){return!1}}x(sn,"ownDefaults",Sh),x(sn,"type","Polygon"),F.setClass(sn),F.setSVGClass(sn);class Ch extends Et{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const l in e[h]){const c=e[h][l]||{};n++,c[t]!==void 0?(i?c[t]!==i&&(r=!1):i=c[t],c[t]===this[t]&&delete c[t]):r=!1,Object.keys(c).length!==0?s++:delete e[h][l]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=hr(w(w({},this._getStyleDeclaration(s,i)),e),(r=>r!==void 0));this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return w(w({},ss(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}x(Ch,"_styleProperties",rc);const Uu=/ +/g,Yu=/"/g;function Hr(a,t,e,s,i){return" ".concat((function(n,r){let{left:o,top:h,width:l,height:c}=r,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:K.NUM_FRACTION_DIGITS;const d=ti(bt,n,!1),[f,g,p,b]=[o,h,l,c].map((m=>et(m,u)));return"<rect ".concat(d,' x="').concat(f,'" y="').concat(g,'" width="').concat(p,'" height="').concat(b,'"></rect>')})(a,{left:t,top:e,width:s,height:i}),`
53
- `)}const $u=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let zr;class kt extends Ch{static getDefaults(){return w(w({},super.getDefaults()),kt.ownDefaults)}constructor(t,e){super(),x(this,"__charBounds",[]),Object.assign(this,kt.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=Ir(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(xe)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===xe||h!==l-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let c=0;c<=n.length;c++)r=this.__charBounds[h][c],this._reSpaceAndTab.test(n[c])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===It?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case X:t.textBaseline="middle";break;case"ascender":t.textBaseline=Xt;break;case"descender":t.textBaseline=Qn}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,l=this._getLineLeftOffset(n);let c,u,d=0,f=0,g=this.getValueOfPropertyAt(n,0,"textBackgroundColor");const p=this.getHeightOfLineImpl(n);for(let b=0;b<h;b++){const m=this.__charBounds[n][b];u=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),t.fillStyle=u,u&&t.fillRect(-m.width/2,-p*(1-this._fontSizeFraction),m.width,p),t.restore()):u!==g?(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=g,g&&t.fillRect(c,i,d,p),f=m.left,d=m.width,g=u):d+=m.kernedWidth}u&&!this.path&&(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=u,t.fillRect(c,i,d,p)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Us.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let c,u,d,f;if(s&&n.has(s)&&(d=n.get(s)),n.has(t)&&(f=c=n.get(t)),h&&n.has(o)&&(u=n.get(o),f=u-d),c===void 0||d===void 0||u===void 0){const g=(function(){return zr||(zr=Kt({width:0,height:0}).getContext("2d")),zr})();this._setTextStyles(g,e,!0),c===void 0&&(f=c=g.measureText(t).width,n.set(t,c)),d===void 0&&h&&s&&(d=g.measureText(s).width,n.set(s,d)),h&&u===void 0&&(u=g.measureText(o).width,n.set(o,u),f=u-d)}return{width:c*l,kernedWidth:f*l}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===ft,r=this.path,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let c=0;c<h;c++){const u=o[c];s=this._getGraphemeBox(u,t,c,e),l[c]=s,i+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let c=0;const u=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case Z:c=n?u-i:0;break;case X:c=(u-i)/2;break;case ft:c=n?0:u-i}c+=this.pathStartOffset*(n?-1:1);for(let d=n?h-1:0;n?d>=0:d<h;n?d--:d++)s=l[d],c>u?c%=u:c<0&&(c+=u),this._setGraphemeOnPath(c,s),c+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=uh(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===ft?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let l,c=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,c+=l);const d={width:u,left:0,height:r.fontSize,kernedWidth:c,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];d.left=f.left+f.width+h.kernedWidth-h.width}return d}getHeightOfLineImpl(t){const e=this.__lineHeights;if(e[t])return e[t];let s=this.getHeightOfChar(t,0);for(let i=1,n=this._textLines[t].length;i<n;i++)s=Math.max(this.getHeightOfChar(t,i),s);return e[t]=s*this._fontSizeMult}getHeightOfLine(t){return this.getHeightOfLineImpl(t)*this.lineHeight}calcTextHeight(){let t=0;for(let e=0,s=this._textLines.length;e<s;e++)t+=e===s-1?this.getHeightOfLineImpl(e):this.getHeightOfLine(e);return t}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++)this._renderTextLine(e,t,this._textLines[r],i+this._getLineLeftOffset(r),n+s+this.getHeightOfLineImpl(r),r),s+=this.getHeightOfLine(r);t.restore()}_renderTextFill(t){(this.fill||this.styleHas(bt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.textAlign.includes(xe),h=this.path,l=!o&&this.charSpacing===0&&this.isEmptyStyles(r)&&!h,c=this.direction==="ltr",u=this.direction==="ltr"?1:-1,d=e.direction;let f,g,p,b,m,v="",y=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",c?"ltr":"rtl"),e.direction=c?"ltr":"rtl",e.textAlign=c?Z:ft),n-=this.getHeightOfLineImpl(r)*this._fontSizeFraction,l)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let _=0,S=s.length-1;_<=S;_++)b=_===S||this.charSpacing||h,v+=s[_],p=this.__charBounds[r][_],y===0?(i+=u*(p.kernedWidth-p.width),y+=p.width):y+=p.kernedWidth,o&&!b&&this._reSpaceAndTab.test(s[_])&&(b=!0),b||(f=f||this.getCompleteStyleDeclaration(r,_),g=this.getCompleteStyleDeclaration(r,_+1),b=Yi(f,g,!1)),b&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,r,_,v,-y/2,0),e.restore()):(m=i,this._renderChar(t,e,r,_,v,m,n)),v="",f=g,i+=u*y,y=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Kt({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return ee(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),l=this.getCompleteStyleDeclaration(s,i),c=t==="fillText"&&l.fill,u=t==="strokeText"&&l.stroke&&l.strokeWidth;if(u||c){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),c){const d=this._setFillStyles(e,l);e.fillText(n,r-d.offsetX,o-d.offsetY)}if(u){const d=this._setStrokeStyles(e,l);e.strokeText(n,r-d.offsetX,o-d.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===xe||i===si&&!r||i===ei&&!r||i===ji&&!r?0:(i===X&&(o=s/2),i===ft&&(o=s),i===si&&(o=s/2),i===ei&&(o=s),n==="rtl"&&(i===ft||i===xe||i===ei?o=0:i===Z||i===ji?o=-s:i!==X&&i!==si||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=e==="linethrough"?.5:e==="overline"?1:0,h=this.offsets[e];for(let l=0,c=this._textLines.length;l<c;l++){const u=this.getHeightOfLine(l);if(!this[e]&&!this.styleHas(e,l)){s+=u;continue}const d=this._textLines[l],f=u/this.lineHeight,g=this._getLineLeftOffset(l);let p=0,b=0,m=this.getValueOfPropertyAt(l,0,e),v=this.getValueOfPropertyAt(l,0,bt),y=this.getValueOfPropertyAt(l,0,rs),_=m,S=v,A=y;const T=s+f*(1-this._fontSizeFraction);let E=this.getHeightOfChar(l,0),P=this.getValueOfPropertyAt(l,0,"deltaY");for(let L=0,k=d.length;L<k;L++){const O=this.__charBounds[l][L];_=this.getValueOfPropertyAt(l,L,e),S=this.getValueOfPropertyAt(l,L,bt),A=this.getValueOfPropertyAt(l,L,rs);const j=this.getHeightOfChar(l,L),M=this.getValueOfPropertyAt(l,L,"deltaY");if(n&&_&&S){const R=this.fontSize*A/1e3;t.save(),t.fillStyle=v,t.translate(O.renderLeft,O.renderTop),t.rotate(O.angle),t.fillRect(-O.kernedWidth/2,h*j+M-o*R,O.kernedWidth,R),t.restore()}else if((_!==m||S!==v||j!==E||A!==y||M!==P)&&b>0){const R=this.fontSize*y/1e3;let G=i+g+p;this.direction==="rtl"&&(G=this.width-G-b),m&&v&&y&&(t.fillStyle=v,t.fillRect(G,T+h*E+P-o*R,b,R)),p=O.left,b=O.width,m=_,y=A,v=S,E=j,P=M}else b+=O.kernedWidth}let N=i+g+p;this.direction==="rtl"&&(N=this.width-N-b),t.fillStyle=S;const D=this.fontSize*A/1e3;_&&S&&A&&t.fillRect(N,T+h*E+P-o*D,b-r,D),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||kt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return Ui(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
53
+ `)}const $u=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let zr;class kt extends Ch{static getDefaults(){return w(w({},super.getDefaults()),kt.ownDefaults)}constructor(t,e){super(),x(this,"__charBounds",[]),Object.assign(this,kt.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=Ir(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(xe)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===xe||h!==l-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let c=0;c<=n.length;c++)r=this.__charBounds[h][c],this._reSpaceAndTab.test(n[c])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===It?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case X:t.textBaseline="middle";break;case"ascender":t.textBaseline=Xt;break;case"descender":t.textBaseline=Qn}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,l=this._getLineLeftOffset(n);let c,u,d=0,f=0,g=this.getValueOfPropertyAt(n,0,"textBackgroundColor");const p=this.getHeightOfLineImpl(n);for(let b=0;b<h;b++){const m=this.__charBounds[n][b];u=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),t.fillStyle=u,u&&t.fillRect(-m.width/2,-p*(1-this._fontSizeFraction),m.width,p),t.restore()):u!==g?(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=g,g&&t.fillRect(c,i,d,p),f=m.left,d=m.width,g=u):d+=m.kernedWidth}u&&!this.path&&(c=s+l+f,this.direction==="rtl"&&(c=this.width-c-d),t.fillStyle=u,t.fillRect(c,i,d,p)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Us.getFontCache(e),r=this._getFontDeclaration(e),o=s?s+t:t,h=s&&r===this._getFontDeclaration(i),l=e.fontSize/this.CACHE_FONT_SIZE;let c,u,d,f;if(s&&n.has(s)&&(d=n.get(s)),n.has(t)&&(f=c=n.get(t)),h&&n.has(o)&&(u=n.get(o),f=u-d),c===void 0||d===void 0||u===void 0){const g=(function(){return zr||(zr=Kt({width:0,height:0}).getContext("2d")),zr})();this._setTextStyles(g,e,!0),c===void 0&&(f=c=g.measureText(t).width,n.set(t,c)),d===void 0&&h&&s&&(d=g.measureText(s).width,n.set(s,d)),h&&u===void 0&&(u=g.measureText(o).width,n.set(o,u),f=u-d)}return{width:c*l,kernedWidth:f*l}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===ft,r=this.path,o=this._textLines[t],h=o.length,l=new Array(h);this.__charBounds[t]=l;for(let c=0;c<h;c++){const u=o[c];s=this._getGraphemeBox(u,t,c,e),l[c]=s,i+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let c=0;const u=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case Z:c=n?u-i:0;break;case X:c=(u-i)/2;break;case ft:c=n?0:u-i}c+=this.pathStartOffset*(n?-1:1);for(let d=n?h-1:0;n?d>=0:d<h;n?d--:d++)s=l[d],c>u?c%=u:c<0&&(c+=u),this._setGraphemeOnPath(c,s),c+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=uh(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===ft?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let l,c=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,c+=l);const d={width:u,left:0,height:r.fontSize,kernedWidth:c,deltaY:r.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];d.left=f.left+f.width+h.kernedWidth-h.width}return d}getHeightOfLineImpl(t){const e=this.__lineHeights;if(e[t])return e[t];let s=this.getHeightOfChar(t,0);for(let i=1,n=this._textLines[t].length;i<n;i++)s=Math.max(this.getHeightOfChar(t,i),s);return e[t]=s*this._fontSizeMult}getHeightOfLine(t){return this.getHeightOfLineImpl(t)*this.lineHeight}calcTextHeight(){let t=0;for(let e=0,s=this._textLines.length;e<s;e++)t+=e===s-1?this.getHeightOfLineImpl(e):this.getHeightOfLine(e);return t}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++)this._renderTextLine(e,t,this._textLines[r],i+this._getLineLeftOffset(r),n+s+this.getHeightOfLineImpl(r),r),s+=this.getHeightOfLine(r);t.restore()}_renderTextFill(t){(this.fill||this.styleHas(bt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.textAlign.includes(xe),h=this.path,l=!o&&this.charSpacing===0&&this.isEmptyStyles(r)&&!h,c=this.direction==="ltr",u=this.direction==="ltr"?1:-1,d=e.direction;let f,g,p,b,m,v="",y=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",c?"ltr":"rtl"),e.direction=c?"ltr":"rtl",e.textAlign=c?Z:ft),n-=this.getHeightOfLineImpl(r)*this._fontSizeFraction,l)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let _=0,S=s.length-1;_<=S;_++)b=_===S||this.charSpacing||h,v+=s[_],p=this.__charBounds[r][_],y===0?(i+=u*(p.kernedWidth-p.width),y+=p.width):y+=p.kernedWidth,o&&!b&&this._reSpaceAndTab.test(s[_])&&(b=!0),b||(f=f||this.getCompleteStyleDeclaration(r,_),g=this.getCompleteStyleDeclaration(r,_+1),b=Yi(f,g,!1)),b&&(h?(e.save(),e.translate(p.renderLeft,p.renderTop),e.rotate(p.angle),this._renderChar(t,e,r,_,v,-y/2,0),e.restore()):(m=i,this._renderChar(t,e,r,_,v,m,n)),v="",f=g,i+=u*y,y=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Kt({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return ee(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),l=this.getCompleteStyleDeclaration(s,i),c=t==="fillText"&&l.fill,u=t==="strokeText"&&l.stroke&&l.strokeWidth;if(u||c){if(e.save(),e.font=this._getFontDeclaration(l),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),c){const d=this._setFillStyles(e,l);e.fillText(n,r-d.offsetX,o-d.offsetY)}if(u){const d=this._setStrokeStyles(e,l);e.strokeText(n,r-d.offsetX,o-d.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===xe||i===si&&!r||i===ei&&!r||i===ji&&!r?0:(i===X&&(o=s/2),i===ft&&(o=s),i===si&&(o=s/2),i===ei&&(o=s),n==="rtl"&&(i===ft||i===xe||i===ei?o=0:i===Z||i===ji?o=-s:i!==X&&i!==si||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=e==="linethrough"?.5:e==="overline"?1:0,h=this.offsets[e];for(let l=0,c=this._textLines.length;l<c;l++){const u=this.getHeightOfLine(l);if(!this[e]&&!this.styleHas(e,l)){s+=u;continue}const d=this._textLines[l],f=u/this.lineHeight,g=this._getLineLeftOffset(l);let p=0,b=0,m=this.getValueOfPropertyAt(l,0,e),v=this.getValueOfPropertyAt(l,0,bt),y=this.getValueOfPropertyAt(l,0,rs),_=m,S=v,A=y;const T=s+f*(1-this._fontSizeFraction);let E=this.getHeightOfChar(l,0),P=this.getValueOfPropertyAt(l,0,"deltaY");for(let L=0,k=d.length;L<k;L++){const O=this.__charBounds[l][L];_=this.getValueOfPropertyAt(l,L,e),S=this.getValueOfPropertyAt(l,L,bt),A=this.getValueOfPropertyAt(l,L,rs);const j=this.getHeightOfChar(l,L),M=this.getValueOfPropertyAt(l,L,"deltaY");if(n&&_&&S){const R=this.fontSize*A/1e3;t.save(),t.fillStyle=v,t.translate(O.renderLeft,O.renderTop),t.rotate(O.angle),t.fillRect(-O.kernedWidth/2,h*j+M-o*R,O.kernedWidth,R),t.restore()}else if((_!==m||S!==v||j!==E||A!==y||M!==P)&&b>0){const R=this.fontSize*y/1e3;let G=i+g+p;this.direction==="rtl"&&(G=this.width-G-b),m&&v&&y&&(t.fillStyle=v,t.fillRect(G,T+h*E+P-o*R,b,R)),p=O.left,b=O.width,m=_,y=A,v=S,E=j,P=M}else b+=O.kernedWidth}let N=i+g+p;this.direction==="rtl"&&(N=this.width-N-b),t.fillStyle=S;const D=this.fontSize*A/1e3;_&&S&&A&&t.fillRect(N,T+h*E+P-o*D,b-r,D),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||kt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return Ui(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
54
54
  `];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return w(w({},super.toObject([...pa,...t])),{},{styles:Va(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,n=!1;if(typeof t=="object")for(const r in t)r==="path"&&this.setPathInfo(),i=i||s.includes(r),n=n||r==="path";else i=s.includes(t),n=t==="path";return n&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Le(t,kt.ATTRIBUTE_NAMES,s),n=w(w({},e),i),{textAnchor:r=Z,textDecoration:o="",dx:h=0,dy:l=0,top:c=0,left:u=0,fontSize:d=Zn,strokeWidth:f=1}=n,g=it(n,$u),p=new this(Fi(t.textContent||"").trim(),w({left:u+h,top:c+l,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:d},g)),b=p.getScaledHeight()/p.height,m=((p.height+p.strokeWidth)*p.lineHeight-p.height)*b,v=p.getScaledHeight()+m;let y=0;return r===X&&(y=p.getScaledWidth()/2),r===ft&&(y=p.getScaledWidth()),p.set({left:p.left-y,top:p.top-(v-p.fontSize*(.07+p._fontSizeFraction))/p.lineHeight,strokeWidth:f}),p}static fromObject(t){return this._fromObject(w(w({},t),{},{styles:Xa(t.styles||{},t.text)}),{extraParam:"text"})}}x(kt,"textLayoutProperties",ga),x(kt,"cacheProperties",[...De,...pa]),x(kt,"ownDefaults",oc),x(kt,"type","Text"),x(kt,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),x(kt,"ATTRIBUTE_NAMES",Xe.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),Na(kt,[class extends ua{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:a,withShadow:!0,additionalTransform:Ts(this.calcOwnMatrix())}):t}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ','font-family="'.concat(this.fontFamily.replace(Yu,"'"),'" '),'font-size="'.concat(this.fontSize,'" '),this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
55
55
  `]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...Hr(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s,i){const n=K.NUM_FRACTION_DIGITS,r=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Uu)),o=r?'style="'.concat(r,'"'):"",h=t.deltaY,l=h?' dy="'.concat(et(h,n),'" '):"",{angle:c,renderLeft:u,renderTop:d,width:f}=i;let g="";if(u!==void 0){const p=f/2;c&&(g=' rotate="'.concat(et(_e(c),n),'"'));const b=es({angle:_e(c)});b[4]=u,b[5]=d;const m=new C(-p,0).transform(b);e=m.x,s=m.y}return'<tspan x="'.concat(et(e,n),'" y="').concat(et(s,n),'" ').concat(l).concat(g).concat(o,">").concat(Ga(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(xe),r=this._textLines[t];let o,h,l,c,u,d="",f=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let g=0,p=r.length-1;g<=p;g++)u=g===p||this.charSpacing||this.path,d+=r[g],l=this.__charBounds[t][g],f===0?(e+=l.kernedWidth-l.width,f+=l.width):f+=l.kernedWidth,n&&!u&&this._reSpaceAndTab.test(r[g])&&(u=!0),u||(o=o||this.getCompleteStyleDeclaration(t,g),h=this.getCompleteStyleDeclaration(t,g+1),u=Yi(o,h,!0)),u&&(c=this._getStyleDeclaration(t,g),a.push(this._createTextCharSpan(d,c,e,s,l)),d="",o=h,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let c=0;c<i.length;c++){const{left:u,width:d,kernedWidth:f}=this.__charBounds[t][c];r=this.getValueOfPropertyAt(t,c,"textBackgroundColor"),r!==l?(l&&a.push(...Hr(l,e+h,s,o,n)),h=u,o=d,l=r):o+=f}r&&a.push(...Hr(l,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," text-decoration-thickness: ").concat(et(this.textDecorationThickness*this.getObjectScaling().y/10,K.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:l,textDecorationThickness:c,linethrough:u,overline:d,underline:f}=a,g=this.getSvgTextDecoration({underline:f??this.underline,overline:d??this.overline,linethrough:u??this.linethrough}),p=c||this.textDecorationThickness;return[i?ti(It,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",g?"text-decoration: ".concat(g,"; text-decoration-thickness: ").concat(et(p*this.getObjectScaling().y/10,K.NUM_FRACTION_DIGITS),"%; "):"",n?ti(bt,n):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter((t=>a[t.replace("-","")])).join(" ")}}]),F.setClass(kt),F.setSVGClass(kt);class qu{constructor(t){x(this,"target",void 0),x(this,"__mouseDownInPlace",!1),x(this,"__dragStartFired",!1),x(this,"__isDraggingOver",!1),x(this,"__dragStartSelection",void 0),x(this,"__dragImageDisposer",void 0),x(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((s=>s())),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new C(r.flipX?-1:1,r.flipY?-1:1),l=r._getCursorBoundaries(i),c=new C(l.left+l.leftOffset,l.top+l.topOffset).multiply(h).transform(r.calcTransformMatrix()),u=o.getScenePoint(t).subtract(c),d=r.getCanvasRetinaScaling(),f=r.getBoundingRect(),g=c.subtract(new C(f.left,f.top)),p=o.viewportTransform,b=g.add(u).transform(p,!0),m=r.backgroundColor,v=Mr(r.styles);r.backgroundColor="";const y={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(y,0,i),r.setSelectionStyles(y,n,r.text.length),r.dirty=!0;const _=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=m,r.styles=v,r.dirty=!0,Qi(_,{position:"fixed",left:"".concat(-_.width,"px"),border:Lt,width:"".concat(_.width/d,"px"),height:"".concat(_.height/d,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{_.remove()},ae(t.target||this.target.hiddenTextarea).body.appendChild(_),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(_,b.x,b.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=w({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:l}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},c=n[Math.max(0,n.length-1)],u=0;if(this.__dragStartSelection){const d=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;h>d&&h<=f?h=d:h>f&&(h-=f-d),r.removeChars(d,f),delete this.__dragStartSelection}r._reNewline.test(c)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,l,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+u,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(Ai,{index:h+u,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||Lt;h===Lt?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(Ai,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const Ah=/[ \n\.,;!\?\-]/;class Ku extends kt{constructor(){super(...arguments),x(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Tr({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,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;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach((e=>{e&&!e.isDone()&&(t=!0,e.abort())})),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some((t=>!t||t.isDone()))&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!tr.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!Ah.test(n);)i+=e,n=s[i];return e===-1&&Ah.test(n)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea()}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;ae(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),l=this.canvas.upperCanvasEl,c=l.width/h,u=l.height/h,d=c-r,f=u-r,g=new C(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new C(l.clientWidth/c,l.clientHeight/u));return g.x<0&&(g.x=0),g.x>d&&(g.x=d),g.y<0&&(g.y=0),g.y>f&&(g.y=f),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_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(Ei),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let l=i;l<r;l++)delete o[l];for(const l in this.styles[s]){const c=parseInt(l,10);c>=r&&(o[c-h]=o[l],delete o[l])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const l=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const u in this.styles[t]){const d=parseInt(u,10);d>=e&&(h=!0,n[d-e]=this.styles[t][u],o&&e===0||delete this.styles[t][u])}let c=!1;for(h&&!o&&(this.styles[t+s]=n,c=!0),(c||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:w({},i[s-1])}:l?this.styles[t+s]={0:w({},l)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?w({},n):{};s||(s=1);for(const h in r){const l=parseInt(h,10);l>=e&&(n[l+s]=r[l],r[l-s]||delete n[l])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=w({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=w({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
56
56
  `?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=Z:this._selectionDirection===ft&&(this._selectionDirection=Z,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===ft?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=ft:this._selectionDirection===Z&&(this._selectionDirection=ft,this.selectionStart=e),this.selectionEnd=s)}}class Ju extends Ku{initHiddenTextarea(){const t=this.canvas&&ae(this.canvas.getElement())||_s(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off",name:"fabricTextarea"}).map((r=>{let[o,h]=r;return e.setAttribute(o,h)}));const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(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((r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))})),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste,{value:s,selectionStart:i,selectionEnd:n}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const r=()=>{this.updateFromTextArea(),this.fire(Ai),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void r();const o=this._splitTextIntoLines(s).graphemeText,h=this._text.length,l=o.length,c=this.selectionStart,u=this.selectionEnd,d=c!==u;let f,g,p,b,m=l-h;const v=this.fromStringToGraphemeSelection(i,n,s),y=c>v.selectionStart;d?(g=this._text.slice(c,u),m+=u-c):l<h&&(g=y?this._text.slice(u+m,u):this._text.slice(c,c-m));const _=o.slice(v.selectionEnd-m,v.selectionEnd);if(g&&g.length&&(_.length&&(f=this.getSelectionStyles(c,c+1,!1),f=_.map((()=>f[0]))),d?(p=c,b=u):y?(p=u-g.length,b=u):(p=u,b=u+g.length),this.removeStyleFromTo(p,b)),_.length){const{copyPasteData:S}=ve();e&&_.join("")===S.copiedText&&!K.disableStyleCopyPaste&&(f=S.copiedTextStyle),this.insertNewStyleBlock(_,c,f)}r()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=ve();t.copiedText=this.getSelectedText(),K.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),l=this._textLines[n].slice(0,r),c=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-l.length+(1-c)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,l=s.length;h<l;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const c=r-i,u=r,d=Math.abs(c-e);o=Math.abs(u-e)<d?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===ft);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=os(0,this.selectionStart,i),this.selectionEnd=os(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===Z?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=Z,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===ft&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=Z,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===Z&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=ft,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=ft,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Th=a=>!!a.button;class Zu extends Ju{constructor(){super(...arguments),x(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 qu(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,alreadySelected:s}=t;this.canvas&&this.editable&&!Th(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Th(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Wt(this.calcTransformMatrix())).add(new C(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),n=l,l>0&&(i+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let l=0;l<o;l++){const c=r+h[l].kernedWidth;if(e.x<=c){Math.abs(e.x-c)<=Math.abs(e.x-r)&&i++;break}r=c,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const nn="moveCursorUp",rn="moveCursorDown",on="moveCursorLeft",an="moveCursorRight",hn="exitEditing",Eh=(a,t)=>{const e=t.getRetinaScaling();a.setTransform(e,0,0,e,0,0);const s=t.viewportTransform;a.transform(s[0],s[1],s[2],s[3],s[4],s[5])},Qu=w({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:hn,27:hn,33:nn,34:rn,35:an,36:on,37:on,38:nn,39:an,40:rn},keysMapRtl:{9:hn,27:hn,33:nn,34:rn,35:on,36:an,37:an,38:nn,39:on,40:rn},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class je extends Zu{static getDefaults(){return w(w({},super.getDefaults()),je.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,w(w({},je.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof Nr&&this.canvas.textEditingManager.remove(this),e instanceof Nr&&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&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let n,r=t;if(i){n=Kt(t.canvas),r=n.getContext("2d"),Eh(r,this.canvas);const o=this.calcTransformMatrix();r.transform(o[0],o[1],o[2],o[3],o[4],o[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(r,e):this.renderCursor(r,e),i)for(const o of s){const h=o.clipPath,l=Kt(t.canvas),c=l.getContext("2d");if(Eh(c,this.canvas),!h.absolutePositioned){const u=o.calcTransformMatrix();c.transform(u[0],u[1],u[2],u[3],u[4],u[5])}h.transform(c),h.drawObject(c,!0,{}),this.drawClipPathOnCache(r,h,l)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(n,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&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let l=0;l<n;l++)e+=this.getHeightOfLine(l);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===ft||this.textAlign===xe||this.textAlign===ei?h.left*=-1:this.textAlign===Z||this.textAlign===ji?h.left=r-(s>0?s:0):this.textAlign!==X&&this.textAlign!==si||(h.left=r-(s>0?s:0))),h}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&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,l=this.getValueOfPropertyAt(i,n,"deltaY"),c=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:c+e.top+l,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:l}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,l)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(xe),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),l=o.lineIndex,c=h.lineIndex,u=o.charIndex<0?0:o.charIndex,d=h.charIndex<0?0:h.charIndex;for(let f=l;f<=c;f++){const g=this._getLineLeftOffset(f)||0;let p=this.getHeightOfLine(f),b=0,m=0,v=0;if(f===l&&(m=this.__charBounds[l][u].left),f>=l&&f<c)v=r&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===c)if(d===0)v=this.__charBounds[c][d].left;else{const T=this._getWidthOfCharSpacing();v=this.__charBounds[c][d-1].left+this.__charBounds[c][d-1].width-T}b=p,(this.lineHeight<1||f===c&&this.lineHeight>1)&&(p/=this.lineHeight);let y=s.left+g+m,_=p,S=0;const A=v-m;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",_=1,S=p):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===ft||this.textAlign===xe||this.textAlign===ei?y=this.width-y-A:this.textAlign===Z||this.textAlign===ji?y=s.left+g-v:this.textAlign!==X&&this.textAlign!==si||(y=s.left+g-v)),t.fillRect(y,s.top+s.topOffset+S,A,_),s.topOffset+=b}}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,bt)}_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()}}x(je,"ownDefaults",Qu),x(je,"type","IText"),F.setClass(je),F.setClass(je,"i-text");class cs extends je{static getDefaults(){return w(w({},super.getDefaults()),cs.ownDefaults)}constructor(t,e){super(t,w(w({},cs.ownDefaults),e))}static createControls(){return{controls:Bc()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(xe)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`