@zonetrix/viewer 1.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,504 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ct=require("react/jsx-runtime"),Q=require("react");function p(a,t,e){return(t=function(s){var r=function(i,n){if(typeof i!="object"||!i)return i;var o=i[Symbol.toPrimitive];if(o!==void 0){var h=o.call(i,n);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(i)}(s,"string");return typeof r=="symbol"?r:r+""}(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function Fr(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(r){return Object.getOwnPropertyDescriptor(a,r).enumerable})),e.push.apply(e,s)}return e}function m(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Fr(Object(e),!0).forEach(function(s){p(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Fr(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function Y(a,t){if(a==null)return{};var e,s,r=function(n,o){if(n==null)return{};var h={};for(var l in n)if({}.hasOwnProperty.call(n,l)){if(o.indexOf(l)>=0)continue;h[l]=n[l]}return h}(a,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(a);for(s=0;s<i.length;s++)e=i[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(r[e]=a[e])}return r}function kt(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Lr{constructor(){p(this,"browserShadowBlurConstant",1),p(this,"DPI",96),p(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),p(this,"perfLimitSizeTotal",2097152),p(this,"maxCacheSideLimit",4096),p(this,"minCacheSideLimit",256),p(this,"disableStyleCopyPaste",!1),p(this,"enableGLFiltering",!0),p(this,"textureSize",4096),p(this,"forceGLPutImageData",!1),p(this,"cachesBoundsOfCurve",!1),p(this,"fontPaths",{}),p(this,"NUM_FRACTION_DIGITS",4)}}const A=new class extends Lr{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=m(m({},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 Lr,e=(a==null?void 0:a.reduce((s,r)=>(s[r]=t[r],s),{}))||t;this.configure(e)}},qt=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 Ot extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class kn extends Ot{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Mn{}class En extends Mn{testPrecision(t,e){const s="precision ".concat(e,` float;
2
+ void main(){}`),r=t.createShader(t.FRAGMENT_SHADER);return!!r&&(t.shaderSource(r,s),t.compileShader(r),!!t.getShaderParameter(r,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find(s=>this.testPrecision(e,s)),e.getExtension("WEBGL_lose_context").loseContext(),qt("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Pn={};let Rr;const Dt=()=>Rr||(Rr={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new En,dispose(){},copyPasteData:Pn}),pe=()=>Dt().document,Ms=()=>Dt().window,Ci=()=>{var a;return Math.max((a=A.devicePixelRatio)!==null&&a!==void 0?a:Ms().devicePixelRatio,1)},De=new class{constructor(){p(this,"charWidthsCache",{}),p(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const r=this.charWidthsCache[t],i="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return r[i]||(r[i]={}),r[i]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=A,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},sr="6.7.1";function ds(){}const Be=Math.PI/2,ys=2*Math.PI,pr=Math.PI/180,st=Object.freeze([1,0,0,1,0,0]),mr=16,Gt=.4477152502,P="center",L="left",it="top",rr="bottom",z="right",nt="none",vr=/\r?\n/,bi="moving",Es="scaling",Si="rotating",yr="rotate",wi="skewing",Pe="resizing",jn="modifyPoly",An="modifyPath",_s="changed",Ps="scale",at="scaleX",ft="scaleY",me="skewX",ve="skewY",N="fill",ot="stroke",xs="modified",ne="json",Vs="svg",O=new class{constructor(){this[ne]=new Map,this[Vs]=new Map}has(a){return this[ne].has(a)}getClass(a){const t=this[ne].get(a);if(!t)throw new Ot("No class registered for ".concat(a));return t}setClass(a,t){t?this[ne].set(t,a):(this[ne].set(a.type,a),this[ne].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[Vs].get(a)}setSVGClass(a,t){this[Vs].set(t??a.type.toLowerCase(),a)}},Cs=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 Fn{constructor(){p(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[r,i]=s;this.on(r,i)}),()=>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(r=>{let[i,n]=r;s.push(this.once(i,n))}),()=>s.forEach(r=>r())}if(e){const s=this.on(t,function(){for(var r=arguments.length,i=new Array(r),n=0;n<r;n++)i[n]=arguments[n];e.call(this,...i),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],r=s.indexOf(e);r>-1&&s.splice(r,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[r,i]=s;this._removeEventListener(r,i)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const r=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(r)for(let i=0;i<r.length;i++)r[i].call(this,e||{})}}const ae=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Rt=a=>{if(a===0)return 1;switch(Math.abs(a)/Be){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Bt=a=>{if(a===0)return 0;const t=a/Be,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class y{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 y(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new y(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new y(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new y(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new y(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new y(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new y(this.x/t.x,this.y/t.y)}scalarDivide(t){return new y(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 y(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 y(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new y(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 y(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:_r;const s=Bt(t),r=Rt(t),i=this.subtract(e);return new y(i.x*r-i.y*s,i.x*s+i.y*r).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new y(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 _r=new y(0,0),fs=a=>!!a&&Array.isArray(a._objects);function Ti(a){class t extends a{constructor(){super(...arguments),p(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,r=new Array(s),i=0;i<s;i++)r[i]=arguments[i];const n=this._objects.push(...r);return r.forEach(o=>this._onObjectAdded(o)),n}insertAt(s){for(var r=arguments.length,i=new Array(r>1?r-1:0),n=1;n<r;n++)i[n-1]=arguments[n];return this._objects.splice(s,0,...i),i.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,r=[];for(var i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return n.forEach(h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),r.push(h),this._onObjectRemoved(h))}),r}forEachObject(s){this.getObjects().forEach((r,i,n)=>s(r,i,n))}getObjects(){for(var s=arguments.length,r=new Array(s),i=0;i<s;i++)r[i]=arguments[i];return r.length===0?[...this._objects]:this._objects.filter(n=>n.isType(...r))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,r){return!!this._objects.includes(s)||!!r&&this._objects.some(i=>i instanceof t&&i.contains(s,!0))}complexity(){return this._objects.reduce((s,r)=>s+=r.complexity?r.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(ae(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(ae(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,r){if(!s)return!1;const i=this._objects.indexOf(s);if(i!==0){const n=this.findNewLowerIndex(s,i,r);return ae(this._objects,s),this._objects.splice(n,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,r){if(!s)return!1;const i=this._objects.indexOf(s);if(i!==this._objects.length-1){const n=this.findNewUpperIndex(s,i,r);return ae(this._objects,s),this._objects.splice(n,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,r){return s!==this._objects[r]&&(ae(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,r,i){let n;if(i){n=r;for(let o=r-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){n=o;break}}else n=r-1;return n}findNewUpperIndex(s,r,i){let n;if(i){n=r;for(let o=r+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){n=o;break}}else n=r+1;return n}collectObjects(s){let{left:r,top:i,width:n,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],c=new y(r,i),u=c.add(new y(n,o));for(let g=this._objects.length-1;g>=0;g--){const d=this._objects[g];d.selectable&&d.visible&&(h&&d.intersectsWithRect(c,u)||d.isContainedWithinRect(c,u)||h&&d.containsPoint(c)||h&&d.containsPoint(u))&&l.push(d)}return l}}return t}class Oi extends Fn{_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 ps(a){return Ms().requestAnimationFrame(a)}function Ln(a){return Ms().cancelAnimationFrame(a)}let Rn=0;const Kt=()=>Rn++,It=()=>{const a=pe().createElement("canvas");if(!a||a.getContext===void 0)throw new Ot("Failed to create `canvas` element");return a},Bn=()=>pe().createElement("img"),pt=a=>{const t=It();return t.width=a.width,t.height=a.height,t},Di=(a,t,e)=>a.toDataURL("image/".concat(t),e),ki=(a,t,e)=>new Promise((s,r)=>{a.toBlob(s,"image/".concat(t),e)}),G=a=>a*pr,Xt=a=>a/pr,In=a=>a.every((t,e)=>t===st[e]),rt=(a,t,e)=>new y(a).transform(t,e),xt=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:r}=new y(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-r,e},$=(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]],xr=(a,t)=>a.reduceRight((e,s)=>s&&e?$(s,e,t):s||e,void 0)||st.concat(),Mi=a=>{let[t,e]=a;return Math.atan2(e,t)},bs=a=>{const t=Mi(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),r=(a[0]*a[3]-a[2]*a[1])/s,i=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:Xt(t),scaleX:s,scaleY:r,skewX:Xt(i),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Ie=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function ye(){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=G(a),r=Rt(s),i=Bt(s);return[r,i,-i,r,t?t-(r*t-i*e):0,e?e-(i*t+r*e):0]}const Cr=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},Ei=a=>Math.tan(G(a)),Pi=a=>[1,0,Ei(a),1,0,0],ji=a=>[1,Ei(a),0,1,0,0],js=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:r=!1,skewX:i=0,skewY:n=0}=a,o=Cr(s?-t:t,r?-e:e);return i&&(o=$(o,Pi(i),!0)),n&&(o=$(o,ji(n),!0)),o},Xn=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let r=Ie(t,e);s&&(r=$(r,ye({angle:s})));const i=js(a);return In(i)||(r=$(r,i)),r},ms=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(s,r){if(t&&t.aborted)return r(new kn("loadImage"));const i=Bn();let n;t&&(n=function(h){i.src="",r(h)},t.addEventListener("abort",n,{once:!0}));const o=function(){i.onload=i.onerror=null,n&&(t==null||t.removeEventListener("abort",n)),s(i)};a?(i.onload=o,i.onerror=function(){n&&(t==null||t.removeEventListener("abort",n)),r(new Ot("Error loading ".concat(i.src)))},e&&(i.crossOrigin=e),i.src=a):o()})},je=function(a){let{signal:t,reviver:e=ds}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,r)=>{const i=[];t&&t.addEventListener("abort",r,{once:!0}),Promise.all(a.map(n=>O.getClass(n.type).fromObject(n,{signal:t}).then(o=>(e(n,o),i.push(o),o)))).then(s).catch(n=>{i.forEach(o=>{o.dispose&&o.dispose()}),r(n)}).finally(()=>{t&&t.removeEventListener("abort",r)})})},As=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const r=[];t&&t.addEventListener("abort",s,{once:!0});const i=Object.values(a).map(o=>o&&o.type&&O.has(o.type)?je([o],{signal:t}).then(h=>{let[l]=h;return r.push(l),l}):o),n=Object.keys(a);Promise.all(i).then(o=>o.reduce((h,l,c)=>(h[n[c]]=l,h),{})).then(e).catch(o=>{r.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},_e=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},br=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),X=(a,t)=>parseFloat(Number(a).toFixed(t)),Ae=a=>"matrix("+a.map(t=>X(t,A.NUM_FRACTION_DIGITS)).join(" ")+")",dt=a=>!!a&&a.toLive!==void 0,Br=a=>!!a&&typeof a.toObject=="function",Ir=a=>!!a&&a.offsetX!==void 0&&"source"in a,Zt=a=>!!a&&"multiSelectionStacking"in a;function Ai(a){const t=a&&_t(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let r=a;const i=t.documentElement,n=t.body||{scrollLeft:0,scrollTop:0};for(;r&&(r.parentNode||r.host)&&(r=r.parentNode||r.host,r===t?(e=n.scrollLeft||i.scrollLeft||0,s=n.scrollTop||i.scrollTop||0):(e+=r.scrollLeft||0,s+=r.scrollTop||0),r.nodeType!==1||r.style.position!=="fixed"););return{left:e,top:s}}const _t=a=>a.ownerDocument||null,Fi=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Li=function(a,t,e){let{width:s,height:r}=e,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=r,i>1&&(a.setAttribute("width",(s*i).toString()),a.setAttribute("height",(r*i).toString()),t.scale(i,i))},ir=(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 Xr(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=nt,a}class Ri{constructor(t){p(this,"_originalCanvasStyle",void 0),p(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&pe().getElementById(t)||It();var s;if(e.hasAttribute("data-fabric"))throw new Ot("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:r}=this.lower;r.classList.remove("lower-canvas"),r.removeAttribute("data-fabric"),r.setAttribute("width","".concat(e)),r.setAttribute("height","".concat(s)),r.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:r}=this.lower;Li(s,r,t,e)}setCSSDimensions(t){ir(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&_t(t),r={left:0,top:0};if(!s)return r;const i=((e=Fi(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};r.left+=parseInt(i.borderLeftWidth,10)||0,r.top+=parseInt(i.borderTopWidth,10)||0,r.left+=parseInt(i.paddingLeft,10)||0,r.top+=parseInt(i.paddingTop,10)||0;let n={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(n=t.getBoundingClientRect());const h=Ai(t);return{left:n.left+h.left-(o.clientLeft||0)+r.left,top:n.top+h.top-(o.clientTop||0)+r.top}}(this.lower.el)}dispose(){Dt().dispose(this.lower.el),delete this.lower}}const Wn={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...st]};class Xe extends Ti(Oi){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 Xe.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 Ri(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),r=1;r<e;r++)s[r-1]=arguments[r];const i=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),i}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(qt("warn",`Canvas is trying to add an object that belongs to a different canvas.
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?Ci():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 r=m({width:this.width,height:this.height},t);this.elements.setDimensions(r,this.getRetinaScaling()),this.hasLostContext=!0,this.width=r.width,this.height=r.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,r=[...this.viewportTransform],i=rt(t,xt(r));r[0]=e,r[3]=e;const n=rt(i,r);r[4]+=s.x-n.x,r[5]+=s.y-n.y,this.setViewportTransform(r)}setZoom(t){this.zoomToPoint(new y(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 y(-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=ps(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=xt(this.viewportTransform),r=rt({x:0,y:0},s),i=rt({x:t,y:e},s),n=r.min(i),o=r.max(i);return this.vptCoords={tl:n,tr:new y(o.x,n.y),bl:new y(n.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Ln(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,r=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),r&&(r._set("canvas",this),r.shouldCache(),r._transformDone=!0,r.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,r)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,r=e.length;s<r;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],r=this["".concat(e,"Image")],i=this.viewportTransform,n=this["".concat(e,"Vpt")];if(!s&&!r)return;const o=dt(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?s.toLive(t):s,n&&t.transform(...i),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(r){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=n,n&&t.transform(...i),r.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 y(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new y(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new y(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 y(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new y(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return rt(this.getCenterPoint(),xt(this.viewportTransform))}_centerObject(t,e){t.setXY(e,P,P),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,r=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return m(m(m({version:sr},_e(this,e)),{},{objects:this._objects.filter(i=>!i.excludeFromExport).map(i=>this._toObject(i,t,e))},this.__serializeBgOverlay(t,e)),r?{clipPath:r}:null)}_toObject(t,e,s){let r;this.includeDefaultValues||(r=t.includeDefaultValues,t.includeDefaultValues=!1);const i=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!r),i}__serializeBgOverlay(t,e){const s={},r=this.backgroundImage,i=this.overlayImage,n=this.backgroundColor,o=this.overlayColor;return dt(n)?n.excludeFromExport||(s.background=n.toObject(e)):n&&(s.background=n),dt(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),r&&!r.excludeFromExport&&(s.backgroundImage=this._toObject(r,t,e)),i&&!i.excludeFromExport&&(s.overlayImage=this._toObject(i,t,e)),s}toSVG(){let t=arguments.length>0&&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
+ `)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
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" ?>
6
+ `,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
7
+ `)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),r=e.height||"".concat(this.height),i=A.NUM_FRACTION_DIGITS,n=e.viewBox;let o;if(n)o='viewBox="'.concat(n.x," ").concat(n.y," ").concat(n.width," ").concat(n.height,'" ');else if(this.svgViewportTransformation){const h=this.viewportTransform;o='viewBox="'.concat(X(-h[4]/h[0],i)," ").concat(X(-h[5]/h[3],i)," ").concat(X(this.width/h[0],i)," ").concat(X(this.height/h[3],i),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',r,'" ',o,`xml:space="preserve">
8
+ `,"<desc>Created with Fabric.js ",sr,`</desc>
9
+ `,`<defs>
10
+ `,this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),`</defs>
11
+ `)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(Kt()),'<clipPath id="'.concat(e.clipPathId,`" >
12
+ `).concat(e.toClipPathSVG(t.reviver),`</clipPath>
13
+ `)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(dt(e)){const s=this["".concat(t,"Vpt")],r=this.viewportTransform,i={isType:()=>!1,width:this.width/(s?r[0]:1),height:this.height/(s?r[3]:1)};return e.toSVG(i,{additionalTransform:s?Ae(r):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=A.fontPaths;this._objects.forEach(function i(n){t.push(n),fs(n)&&n._objects.forEach(i)}),t.forEach(i=>{if(!(n=i)||typeof n._renderText!="function")return;var n;const{styles:o,fontFamily:h}=i;!e[h]&&s[h]&&(e[h]=!0,o&&Object.values(o).forEach(l=>{Object.values(l).forEach(c=>{let{fontFamily:u=""}=c;!e[u]&&s[u]&&(e[u]=!0)})}))});const r=Object.keys(e).map(i=>` @font-face {
14
+ font-family: '`.concat(i,`';
15
+ src: url('`).concat(s[i],`');
16
+ }
17
+ `)).join("");return r?` <style type="text/css"><![CDATA[
18
+ `.concat(r,`]]></style>
19
+ `):""}_setSVGObjects(t,e){this.forEachObject(s=>{s.excludeFromExport||this._setSVGObject(t,s,e)})}_setSVGObject(t,e,s){t.push(e.toSVG(s))}_setSVGBgOverlayImage(t,e,s){const r=this[e];r&&!r.excludeFromExport&&r.toSVG&&t.push(r.toSVG(s))}_setSVGBgOverlayColor(t,e){const s=this["".concat(e,"Color")];if(s)if(dt(s)){const r=s.repeat||"",i=this.width,n=this.height,o=this["".concat(e,"Vpt")]?Ae(xt(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(i/2,",").concat(n/2,')" x="').concat(s.offsetX-i/2,'" y="').concat(s.offsetY-n/2,'" width="').concat(r!=="repeat-y"&&r!=="no-repeat"||!Ir(s)?i:s.source.width,'" height="').concat(r!=="repeat-x"&&r!=="no-repeat"||!Ir(s)?n:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
20
+ `))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',s,'"',`></rect>
21
+ `)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new Ot("`json` is undefined"));const r=typeof t=="string"?JSON.parse(t):t,{objects:i=[],backgroundImage:n,background:o,overlayImage:h,overlay:l,clipPath:c}=r,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([je(i,{reviver:e,signal:s}),As({backgroundImage:n,backgroundColor:o,overlayImage:h,overlayColor:l,clipPath:c},{signal:s})]).then(g=>{let[d,f]=g;return this.clear(),this.add(...d),this.set(r),this.set(f),this.renderOnAddRemove=u,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=pt(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:r=1,enableRetinaScaling:i=!1}=t,n=r*(i?this.getRetinaScaling():1);return Di(this.toCanvasElement(n,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:r=1,enableRetinaScaling:i=!1}=t,n=r*(i?this.getRetinaScaling():1);return ki(this.toCanvasElement(n,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:r,top:i,filter:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,l=this.getZoom(),c=this.width,u=this.height,g=this.skipControlsDrawing,d=l*t,f=this.viewportTransform,v=[d,0,0,d,(f[4]-(r||0))*t,(f[5]-(i||0))*t],_=this.enableRetinaScaling,x=pt({width:o,height:h}),b=n?this._objects.filter(T=>n(T)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=v,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(x.getContext("2d"),b),this.viewportTransform=f,this.width=c,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=_,this.skipControlsDrawing=g,x}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Cs.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}p(Xe,"ownDefaults",Wn);const Yn=["touchstart","touchmove","touchend"],Vn=a=>{const t=Ai(a.target),e=function(s){const r=s.changedTouches;return r&&r[0]?r[0]:s}(a);return new y(e.clientX+t.left,e.clientY+t.top)},nr=a=>Yn.includes(a.type)||a.pointerType==="touch",Wr=a=>{a.preventDefault(),a.stopPropagation()},Ft=a=>{let t=0,e=0,s=0,r=0;for(let i=0,n=a.length;i<n;i++){const{x:o,y:h}=a[i];(o>s||!i)&&(s=o),(o<t||!i)&&(t=o),(h>r||!i)&&(r=h),(h<e||!i)&&(e=h)}return{left:t,top:e,width:s-t,height:r-e}},zn=["translateX","translateY","scaleX","scaleY"],Gn=(a,t)=>Ss(a,$(t,a.calcOwnMatrix())),Ss=(a,t)=>{const e=bs(t),{translateX:s,translateY:r,scaleX:i,scaleY:n}=e,o=Y(e,zn),h=new y(s,r);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:i,scaleY:n}),a.setPositionByOrigin(h,P,P)},Hn=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},Bi=a=>({scaleX:a.scaleX,scaleY:a.scaleY,skewX:a.skewX,skewY:a.skewY,angle:a.angle,left:a.left,flipX:a.flipX,flipY:a.flipY,top:a.top}),Sr=(a,t,e)=>{const s=a/2,r=t/2,i=[new y(-s,-r),new y(s,-r),new y(-s,r),new y(s,r)].map(o=>o.transform(e)),n=Ft(i);return new y(n.width,n.height)},Fs=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:st;return $(xt(arguments.length>1&&arguments[1]!==void 0?arguments[1]:st),a)},ue=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:st,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:st;return a.transform(Fs(t,e))},Nn=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:st,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:st;return a.transform(Fs(t,e),!0)},Un=(a,t,e)=>{const s=Fs(t,e);return Ss(a,$(s,a.calcOwnMatrix())),s},Ii=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),m(m({},t),{},{target:s})),s.fire(a,t)},qn={left:-.5,top:-.5,center:0,bottom:.5,right:.5},H=a=>typeof a=="string"?qn[a]:a-.5,ws="not-allowed";function Xi(a){return H(a.originX)===H(P)&&H(a.originY)===H(P)}function Yr(a){return .5-H(a)}const bt=(a,t)=>a[t],Wi=(a,t,e,s)=>({e:a,transform:t,pointer:new y(e,s)});function Yi(a,t){const e=a.getTotalAngle()+Xt(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function wr(a,t,e,s,r){var i;let{target:n,corner:o}=a;const h=n.controls[o],l=((i=n.canvas)===null||i===void 0?void 0:i.getZoom())||1,c=n.padding/l,u=function(g,d,f,v){const _=g.getRelativeCenterPoint(),x=f!==void 0&&v!==void 0?g.translateToGivenOrigin(_,P,P,f,v):new y(g.left,g.top);return(g.angle?d.rotate(-G(g.angle),_):d).subtract(x)}(n,new y(s,r),t,e);return u.x>=c&&(u.x-=c),u.x<=-c&&(u.x+=c),u.y>=c&&(u.y-=c),u.y<=c&&(u.y+=c),u.x-=h.offsetX,u.y-=h.offsetY,u}const Kn=(a,t,e,s)=>{const{target:r,offsetX:i,offsetY:n}=t,o=e-i,h=s-n,l=!bt(r,"lockMovementX")&&r.left!==o,c=!bt(r,"lockMovementY")&&r.top!==h;return l&&r.set(L,o),c&&r.set(it,h),(l||c)&&Ii(bi,Wi(a,t,e,s)),l||c},Vr={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},zs=(a,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+6*(t-a)*e:e<.5?t:e<2/3?a+(t-a)*(2/3-e)*6:a),zr=(a,t,e,s)=>{a/=255,t/=255,e/=255;const r=Math.max(a,t,e),i=Math.min(a,t,e);let n,o;const h=(r+i)/2;if(r===i)n=o=0;else{const l=r-i;switch(o=h>.5?l/(2-r-i):l/(r+i),r){case a:n=(t-e)/l+(t<e?6:0);break;case t:n=(e-a)/l+2;break;case e:n=(a-t)/l+4}n/=6}return[Math.round(360*n),Math.round(100*o),Math.round(100*h),s]},Gr=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},Ve=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),Hr=a=>{let[t,e,s,r=1]=a;const i=Math.round(.3*t+.59*e+.11*s);return[i,i,i,r]};class B{constructor(t){if(p(this,"isUnrecognised",!1),t)if(t instanceof B)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,r,i=1]=t;this.setSource([e,s,r,i])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in Vr&&(t=Vr[t]),t==="transparent"?[255,255,255,0]:B.sourceFromHex(t)||B.sourceFromRgb(t)||B.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=zr(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,r]=zr(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(r,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,r]=this.getSource();return"".concat(Ve(t)).concat(Ve(e)).concat(Ve(s)).concat(Ve(Math.round(255*r)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Hr(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Hr(this.getSource()),r=e<(t||127)?0:255;return this.setSource([r,r,r,s]),this}overlayWith(t){t instanceof B||(t=new B(t));const e=this.getSource(),s=t.getSource(),[r,i,n]=e.map((o,h)=>Math.round(.5*o+.5*s[h]));return this.setSource([r,i,n,e[3]]),this}static fromRgb(t){return B.fromRgba(t)}static fromRgba(t){return new B(B.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(/^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i);if(e){const[s,r,i]=e.slice(1,4).map(n=>{const o=parseFloat(n);return n.endsWith("%")?Math.round(2.55*o):o});return[s,r,i,Gr(e[4])]}}static fromHsl(t){return B.fromHsla(t)}static fromHsla(t){return new B(B.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const s=(B.parseAngletoDegrees(e[1])%360+360)%360/360,r=parseFloat(e[2])/100,i=parseFloat(e[3])/100;let n,o,h;if(r===0)n=o=h=i;else{const l=i<=.5?i*(r+1):i+r-i*r,c=2*i-l;n=zs(c,l,s+1/3),o=zs(c,l,s),h=zs(c,l,s-1/3)}return[Math.round(255*n),Math.round(255*o),Math.round(255*h),Gr(e[4])]}static fromHex(t){return new B(B.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(h=>h+h):e.match(/.{2}/g);const[r,i,n,o=255]=s.map(h=>parseInt(h,16));return[r,i,n,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?Xt(s):e.includes("turn")?360*s:s}}const ge=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:mr;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),r=A.DPI;switch(e==null?void 0:e[0]){case"mm":return s*r/25.4;case"cm":return s*r/2.54;case"in":return s*r;case"pt":return s*r/72;case"pc":return s*r/72*12;case"em":return s*t;default:return s}},Jn=a=>{const[t,e]=a.trim().split(" "),[s,r]=(i=t)&&i!==nt?[i.slice(1,4),i.slice(5,8)]:i===nt?[i,i]:["Mid","Mid"];var i;return{meetOrSlice:e||"meet",alignX:s,alignY:r}},Fe=function(a,t){let e,s,r=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const i=new B(t),n=i.getAlpha();e=i.toRgb(),n!==1&&(s=n.toString())}else e="none";return r?"".concat(a,": ").concat(e,"; ").concat(s?"".concat(a,"-opacity: ").concat(s,"; "):""):"".concat(a,'="').concat(e,'" ').concat(s?"".concat(a,'-opacity="').concat(s,'" '):"")};class Vi{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",r=this.strokeDashArray?this.strokeDashArray.join(" "):nt,i=this.strokeDashOffset?this.strokeDashOffset:"0",n=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",l=this.opacity!==void 0?this.opacity:"1",c=this.visible?"":" visibility: hidden;",u=t?"":this.getSvgFilter(),g=Fe(N,this.fill);return[Fe(ot,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",r,"; ","stroke-linecap: ",n,"; ","stroke-dashoffset: ",i,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",g,"fill-rule: ",e,"; ","opacity: ",l,";",u,c].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),r='transform="'.concat(Ae(s));return"".concat(r).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),i=t.indexOf("COMMON_PARTS");return t[i]=r,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:r,additionalTransform:i}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const n=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=r?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,l=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",c=h&&h.absolutePositioned,u=this.stroke,g=this.fill,d=this.shadow,f=[],v=t.indexOf("COMMON_PARTS");let _;h&&(h.clipPathId="CLIPPATH_".concat(Kt()),_='<clipPath id="'.concat(h.clipPathId,`" >
22
+ `).concat(h.toClipPathSVG(s),`</clipPath>
23
+ `)),c&&f.push("<g ",o,this.getSvgCommons(),` >
24
+ `),f.push("<g ",this.getSvgTransform(!1),c?"":o+this.getSvgCommons(),` >
25
+ `);const x=[n,l,e?"":this.addPaintOrder()," ",i?'transform="'.concat(i,'" '):""].join("");return t[v]=x,dt(g)&&f.push(g.toSVG(this)),dt(u)&&f.push(u.toSVG(this)),d&&f.push(d.toSVG(this)),h&&f.push(_),f.push(t.join("")),f.push(`</g>
26
+ `),c&&f.push(`</g>
27
+ `),s?s(f.join("")):f.join("")}addPaintOrder(){return this.paintFirst!==N?' paint-order="'.concat(this.paintFirst,'" '):""}}function Ls(a){return new RegExp("^("+a.join("|")+")\\b","i")}const re="textDecorationThickness",zi=["fontSize","fontWeight","fontFamily","fontStyle"],Gi=["underline","overline","linethrough"],Hi=[...zi,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],Ni=[...Hi,...Gi,"textBackgroundColor","direction",re],$n=[...zi,...Gi,ot,"strokeWidth",N,"deltaY","textBackgroundColor",re],Zn={_reNewline:vr,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:L,fontStyle:"normal",lineHeight:1.16,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:L,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[re]:66.667},Tt="justify",Ts="justify-left",ke="justify-right",Me="justify-center";var Nr,Ur,qr;const Ct=String.raw(Nr||(Nr=kt(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),Gs=String.raw(Ur||(Ur=kt(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),Qn=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Ct+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Ct+"))?\\s+(.*)"),to={cx:L,x:L,r:"radius",cy:it,y:it,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":re},Hs="font-size",Ns="clip-path";Ls(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]);Ls(["symbol","image","marker","pattern","view","svg"]);const Kr=Ls(["symbol","g","a","svg","clipPath","defs"]);new RegExp(String.raw(qr||(qr=kt(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Ct,Gs,Ct,Gs,Ct,Gs,Ct));const eo=new y(1,0),Ui=new y,qi=(a,t)=>a.rotate(t),or=(a,t)=>new y(t).subtract(a),ar=a=>a.distanceFrom(Ui),hr=(a,t)=>Math.atan2(Ee(a,t),ro(a,t)),so=a=>hr(eo,a),Tr=a=>a.eq(Ui)?a:a.scalarDivide(ar(a)),Ki=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Tr(new y(-a.y,a.x).scalarMultiply(t?1:-1))},Ee=(a,t)=>a.x*t.y-a.y*t.x,ro=(a,t)=>a.x*t.x+a.y*t.y,Jr=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=Ee(t,e),r=Ee(t,a),i=Ee(e,a);return s>=0?r>=0&&i<=0:!(r<=0&&i>=0)},$r="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Zr=new RegExp("(?:\\s|^)"+$r+$r+"("+Ct+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Lt{constructor(t){const e=typeof t=="string"?Lt.parseShadow(t):t;Object.assign(this,Lt.ownDefaults,e),this.id=Kt()}static parseShadow(t){const e=t.trim(),[,s=0,r=0,i=0]=(Zr.exec(e)||[]).map(n=>parseFloat(n)||0);return{color:(e.replace(Zr,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:r,blur:i}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=qi(new y(this.offsetX,this.offsetY),G(-t.angle)),s=new B(this.color);let r=40,i=40;return t.width&&t.height&&(r=100*X((Math.abs(e.x)+this.blur)/t.width,A.NUM_FRACTION_DIGITS)+20,i=100*X((Math.abs(e.y)+this.blur)/t.height,A.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(i,'%" height="').concat(100+2*i,'%" x="-').concat(r,'%" width="').concat(100+2*r,`%" >
28
+ <feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(X(this.blur?this.blur/2:0,A.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
29
+ <feOffset dx="`).concat(X(e.x,A.NUM_FRACTION_DIGITS),'" dy="').concat(X(e.y,A.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
30
+ <feFlood flood-color="`).concat(s.toRgb(),'" flood-opacity="').concat(s.getAlpha(),`"/>
31
+ <feComposite in2="oBlur" operator="in" />
32
+ <feMerge>
33
+ <feMergeNode></feMergeNode>
34
+ <feMergeNode in="SourceGraphic"></feMergeNode>
35
+ </feMerge>
36
+ </filter>
37
+ `)}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=Lt.ownDefaults;return this.includeDefaultValues?t:br(t,(s,r)=>s!==e[r])}static async fromObject(t){return new this(t)}}p(Lt,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),p(Lt,"type","shadow"),O.setClass(Lt,"shadow");const fe=(a,t,e)=>Math.max(a,Math.min(t,e)),io=[it,L,at,ft,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",me,ve],Wt=[N,ot,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],no={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:L,originY:it,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:N,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},oo=(a,t,e,s)=>-e*Math.cos(a/s*Be)+e+t,ao=()=>!1;class Or{constructor(t){let{startValue:e,byValue:s,duration:r=500,delay:i=0,easing:n=oo,onStart:o=ds,onChange:h=ds,onComplete:l=ds,abort:c=ao,target:u}=t;p(this,"_state","pending"),p(this,"durationProgress",0),p(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=r,this.delay=i,this.easing=n,this._onStart=o,this._onChange=h,this._onComplete=l,this._abort=c,this.target=u,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>ps(t),this.delay):ps(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:r,valueProgress:i}=this.calculate(s);this.value=Object.freeze(r),this.valueProgress=i,this._state!=="aborted"&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),ps(this.tick)))}register(){Cs.push(this)}unregister(){Cs.remove(this)}abort(){this._state="aborted",this.unregister()}}const ho=["startValue","endValue"];class lo extends Or{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(m(m({},Y(t,ho)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const co=["startValue","endValue"];class uo extends Or{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(m(m({},Y(t,co)),{},{startValue:e,byValue:s.map((r,i)=>r-e[i])}))}calculate(t){const e=this.startValue.map((s,r)=>this.easing(t,s,this.byValue[r],this.duration,r));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const go=["startValue","endValue","easing","onChange","onComplete","abort"],fo=(a,t,e,s)=>t+e*(1-Math.cos(a/s*Be)),Us=a=>a&&((t,e,s)=>a(new B(t).toRgba(),e,s));class po extends Or{constructor(t){let{startValue:e,endValue:s,easing:r=fo,onChange:i,onComplete:n,abort:o}=t,h=Y(t,go);const l=new B(e).getSource(),c=new B(s).getSource();super(m(m({},h),{},{startValue:l,byValue:c.map((u,g)=>u-l[g]),easing:r,onChange:Us(i),onComplete:Us(n),abort:Us(o)}))}calculate(t){const[e,s,r,i]=this.startValue.map((o,h)=>this.easing(t,o,this.byValue[h],this.duration,h)),n=[...[e,s,r].map(Math.round),fe(0,i,1)];return{value:n,valueProgress:n.map((o,h)=>this.byValue[h]!==0?Math.abs((o-this.startValue[h])/this.byValue[h]):0).find(o=>o!==0)||0}}}function Ji(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new uo(a):new lo(a);return t.start(),t}function mo(a){const t=new po(a);return t.start(),t}class V{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(r=>!this.includes(r))),this}static isPointContained(t,e,s){let r=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(r||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(r||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const i=or(e,s),n=or(e,t).divide(i);return r?Math.abs(n.x)===Math.abs(n.y):n.x===n.y&&n.x>=0&&n.x<=1}}static isPointInPolygon(t,e){const s=new y(t).setX(Math.min(t.x-1,...e.map(i=>i.x)));let r=0;for(let i=0;i<e.length;i++){const n=this.intersectSegmentSegment(e[i],e[(i+1)%e.length],t,s);if(n.includes(t))return!0;r+=+(n.status==="Intersection")}return r%2==1}static intersectLineLine(t,e,s,r){let i=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],n=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,l=r.x-s.x,c=r.y-s.y,u=t.x-s.x,g=t.y-s.y,d=l*g-c*u,f=o*g-h*u,v=c*o-l*h;if(v!==0){const _=d/v,x=f/v;return(i||0<=_&&_<=1)&&(n||0<=x&&x<=1)?new V("Intersection").append(new y(t.x+_*o,t.y+_*h)):new V}if(d===0||f===0){const _=i||n||V.isPointContained(t,s,r)||V.isPointContained(e,s,r)||V.isPointContained(s,t,e)||V.isPointContained(r,t,e);return new V(_?"Coincident":void 0)}return new V("Parallel")}static intersectSegmentLine(t,e,s,r){return V.intersectLineLine(t,e,s,r,!1,!0)}static intersectSegmentSegment(t,e,s,r){return V.intersectLineLine(t,e,s,r,!1,!1)}static intersectLinePolygon(t,e,s){let r=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const i=new V,n=s.length;for(let o,h,l,c=0;c<n;c++){if(o=s[c],h=s[(c+1)%n],l=V.intersectLineLine(t,e,o,h,r,!1),l.status==="Coincident")return l;i.append(...l.points)}return i.points.length>0&&(i.status="Intersection"),i}static intersectSegmentPolygon(t,e,s){return V.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new V,r=t.length,i=[];for(let n=0;n<r;n++){const o=t[n],h=t[(n+1)%r],l=V.intersectSegmentPolygon(o,h,e);l.status==="Coincident"?(i.push(l),s.append(o,h)):s.append(...l.points)}return i.length>0&&i.length===t.length?new V("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const r=e.min(s),i=e.max(s),n=new y(i.x,r.y),o=new y(r.x,i.y);return V.intersectPolygonPolygon(t,[r,n,i,o])}}class vo extends Oi{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?rt(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=rt(t,xt(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new y(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:r}=this.aCoords||(this.aCoords=this.calcACoords()),i=[t,e,s,r];if(this.group){const n=this.group.calcTransformMatrix();return i.map(o=>rt(o,n))}return i}intersectsWithRect(t,e){return V.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=V.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:s,top:r,width:i,height:n}=this.getBoundingRect();return s>=t.x&&s+i<=e.x&&r>=t.y&&r+n<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return V.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return Ft(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(at,t),this._set(ft,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?Xt(Mi(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||st.concat()}calcACoords(){const t=ye({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),r=Ie(e,s),i=$(r,t),n=this._getTransformedDimensions(),o=n.x/2,h=n.y/2;return{tl:rt({x:-o,y:-h},i),tr:rt({x:o,y:-h},i),bl:rt({x:-o,y:h},i),br:rt({x:o,y:h},i)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,H(this.originX),H(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),r=this.matrixCache;return r&&r.key.every((i,n)=>i===s[n])?r.value:(this.group&&(e=$(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),r={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},i=Xn(r);return this.ownMatrixCache={key:t,value:i},i}_getNonTransformedDimensions(){return new y(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=m({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let r=s,i=0;this.strokeUniform&&(r=0,i=s);const n=e.width+r,o=e.height+r;let h;return h=e.skewX===0&&e.skewY===0?new y(n*e.scaleX,o*e.scaleY):Sr(n,o,js(e)),h.scalarAdd(i)}translateToGivenOrigin(t,e,s,r,i){let n=t.x,o=t.y;const h=H(r)-H(e),l=H(i)-H(s);if(h||l){const c=this._getTransformedDimensions();n+=h*c.x,o+=l*c.y}return new y(n,o)}translateToCenterPoint(t,e,s){if(e===P&&s===P)return t;const r=this.translateToGivenOrigin(t,e,s,P,P);return this.angle?r.rotate(G(this.angle),t):r}translateToOriginPoint(t,e,s){const r=this.translateToGivenOrigin(t,P,P,e,s);return this.angle?r.rotate(G(this.angle),t):r}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?rt(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new y(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const r=this.translateToCenterPoint(t,e,s),i=this.translateToOriginPoint(r,this.originX,this.originY);this.set({left:i.x,top:i.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),L,it)}}const yo=["type"],_o=["extraParam"];let Et=class vs extends vo{static getDefaults(){return vs.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){qt("warn","Setting type has no effect",t)}constructor(t){super(),p(this,"_cacheContext",null),Object.assign(this,vs.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=It(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,r=A.maxCacheSideLimit,i=A.minCacheSideLimit;if(e<=r&&s<=r&&e*s<=A.perfLimitSizeTotal)return e<i&&(t.width=i),s<i&&(t.height=i),t;const n=e/s,[o,h]=De.limitDimsByArea(n),l=fe(i,o,r),c=fe(i,h,r);return e>l&&(t.zoomX/=e/l,t.width=l,t.capped=!0),s>c&&(t.zoomY/=s/c,t.height=c,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,r=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(r+2),zoomX:t.x,zoomY:t.y,x:s,y:r}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:r,zoomX:i,zoomY:n,x:o,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),l=s!==t.width||r!==t.height,c=this.zoomX!==i||this.zoomY!==n;if(!t||!e)return!1;if(l||c){s!==t.width||r!==t.height?(t.width=s,t.height=r):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const u=o/2,g=h/2;return this.cacheTranslationX=Math.round(t.width/2-u)+u,this.cacheTranslationY=Math.round(t.height/2-g)+g,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(i,n),this.zoomX=i,this.zoomY=n,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new y(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=bs(this.calcTransformMatrix());return new y(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==at&&t!==ft||(e=this._constrainScale(e)),t===at&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Lt||(e=new Lt(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:r,cacheTranslationY:i}=this,{width:n,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:r,cacheTranslationY:i,width:n,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===ot&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const r=this.fill,i=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=r,this.stroke=i}createClipPathLayer(t,e){const s=pt(e),r=s.getContext("2d");if(r.translate(e.cacheTranslationX,e.cacheTranslationY),r.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(i=>{i.transform(r)}),e.parentClipPaths.push(t),t.absolutePositioned){const i=xt(this.calcTransformMatrix());r.transform(i[0],i[1],i[2],i[3],i[4],i[5])}return t.transform(r),t.drawObject(r,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const r=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,r)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,dt(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(dt(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,r=this.getCanvasRetinaScaling(),[i,,,n]=(s==null?void 0:s.viewportTransform)||st,o=i*r,h=n*r,l=e.nonScaling?new y(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*A.browserShadowBlurConstant*(o+h)*(l.x+l.y)/4,t.shadowOffsetX=e.offsetX*o*l.x,t.shadowOffsetY=e.offsetY*h*l.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!dt(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,r=-this.width/2+e.offsetX||0,i=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,r,i):t.transform(1,0,0,1,r,i),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:r,offsetY:i}}_renderPaintInOrder(t){this.paintFirst===ot?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const r=this._limitCacheSize(this._getCacheCanvasDimensions()),i=this.getCanvasRetinaScaling(),n=r.x/this.scaleX/i,o=r.y/this.scaleY/i,h=pt({width:Math.ceil(n),height:Math.ceil(o)}),l=h.getContext("2d");l&&(l.beginPath(),l.moveTo(0,0),l.lineTo(n,0),l.lineTo(n,o),l.lineTo(0,o),l.closePath(),l.translate(n/2,o/2),l.scale(r.zoomX/this.scaleX/i,r.zoomY/this.scaleY/i),this._applyPatternGradientTransform(l,e),l.fillStyle=e.toLive(t),l.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(i*this.scaleX/r.zoomX,i*this.scaleY/r.zoomY),t.strokeStyle=(s=l.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new y(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(O.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Bi(this),s=this.group,r=this.shadow,i=Math.abs,n=t.enableRetinaScaling?Ci():1,o=(t.multiplier||1)*n,h=t.canvasProvider||(b=>new Xe(b,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Hn(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Un(this,this.getViewportTransform()),this.setCoords();const l=It(),c=this.getBoundingRect(),u=this.shadow,g=new y;if(u){const b=u.blur,T=u.nonScaling?new y(1,1):this.getObjectScaling();g.x=2*Math.round(i(u.offsetX)+b)*i(T.x),g.y=2*Math.round(i(u.offsetY)+b)*i(T.y)}const d=c.width+g.x,f=c.height+g.y;l.width=Math.ceil(d),l.height=Math.ceil(f);const v=h(l);t.format==="jpeg"&&(v.backgroundColor="#fff"),this.setPositionByOrigin(new y(v.width/2,v.height/2),P,P);const _=this.canvas;v._objects=[this],this.set("canvas",v),this.setCoords();const x=v.toCanvasElement(o||1,t);return this.set("canvas",_),this.shadow=r,s&&(this.group=s),this.set(e),this.setCoords(),v._objects=[],v.destroy(),x}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Di(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ki(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:r}=this;if(e){const{x:i,y:n}=this.getRelativeCenterPoint();this.originX=P,this.originY=P,this.left=i,this.top=n}if(this.set("angle",t),e){const{x:i,y:n}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,r);this.left=i,this.top=n,this.originX=s,this.originY=r}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Cs.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&Dt().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,r)=>{let[i,n]=r;return s[i]=this._animate(i,n,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const r=t.split("."),i=this.constructor.colorProperties.includes(r[r.length-1]),{abort:n,startValue:o,onChange:h,onComplete:l}=s,c=m(m({},s),{},{target:this,startValue:o??r.reduce((u,g)=>u[g],this),endValue:e,abort:n==null?void 0:n.bind(this),onChange:(u,g,d)=>{r.reduce((f,v,_)=>(_===r.length-1&&(f[v]=u),f[v]),this),h&&h(u,g,d)},onComplete:(u,g,d)=>{this.setCoords(),l&&l(u,g,d)}});return i?mo(c):Ji(c)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let r,i=0;i<e.length;i++){if(r=e[i],r===t)return{fork:[this,...e.slice(0,i)],otherFork:[],common:e.slice(i)};for(let n=0;n<s.length;n++){if(this===s[n])return{fork:[],otherFork:[t,...s.slice(0,n)],common:[this,...e]};if(r===s[n])return{fork:[this,...e.slice(0,i)],otherFork:[t,...s.slice(0,n)],common:e.slice(i)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const r=e.fork.pop(),i=e.otherFork.pop(),n=s._objects.indexOf(r),o=s._objects.indexOf(i);return n>-1&&n>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(vs.customProperties,this.constructor.customProperties||[]);let e;const s=A.NUM_FRACTION_DIGITS,{clipPath:r,fill:i,stroke:n,shadow:o,strokeDashArray:h,left:l,top:c,originX:u,originY:g,width:d,height:f,strokeWidth:v,strokeLineCap:_,strokeDashOffset:x,strokeLineJoin:b,strokeUniform:T,strokeMiterLimit:w,scaleX:C,scaleY:D,angle:k,flipX:S,flipY:M,opacity:E,visible:W,backgroundColor:j,fillRule:R,paintFirst:F,globalCompositeOperation:K,skewX:q,skewY:J}=this;r&&!r.excludeFromExport&&(e=r.toObject(t.concat("inverted","absolutePositioned")));const I=Mt=>X(Mt,s),St=m(m({},_e(this,t)),{},{type:this.constructor.type,version:sr,originX:u,originY:g,left:I(l),top:I(c),width:I(d),height:I(f),fill:Br(i)?i.toObject():i,stroke:Br(n)?n.toObject():n,strokeWidth:I(v),strokeDashArray:h&&h.concat(),strokeLineCap:_,strokeDashOffset:x,strokeLineJoin:b,strokeUniform:T,strokeMiterLimit:I(w),scaleX:I(C),scaleY:I(D),angle:I(k),flipX:S,flipY:M,opacity:I(E),shadow:o&&o.toObject(),visible:W,backgroundColor:j,fillRule:R,paintFirst:F,globalCompositeOperation:K,skewX:I(q),skewY:I(J)},e?{clipPath:e}:null);return this.includeDefaultValues?St:this._removeDefaultValues(St)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return br(t,(r,i)=>{if(i===L||i===it||i==="type")return!0;const n=s[i];return r!==n&&!(Array.isArray(r)&&Array.isArray(n)&&r.length===0&&n.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Y(t,yo),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:r}=s,i=Y(s,_o);return As(e,i).then(n=>r?(delete n[r],new this(e[r],n)):new this(n))}static fromObject(t,e){return this._fromObject(t,e)}};p(Et,"stateProperties",io),p(Et,"cacheProperties",Wt),p(Et,"ownDefaults",no),p(Et,"type","FabricObject"),p(Et,"colorProperties",[N,ot,"backgroundColor"]),p(Et,"customProperties",[]),O.setClass(Et),O.setClass(Et,"object");const xe=(a,t,e)=>(s,r,i,n)=>{const o=t(s,r,i,n);return o&&Ii(a,m(m({},Wi(s,r,i,n)),e)),o};function Ce(a){return(t,e,s,r)=>{const{target:i,originX:n,originY:o}=e,h=i.getRelativeCenterPoint(),l=i.translateToOriginPoint(h,n,o),c=a(t,e,s,r);return i.setPositionByOrigin(l,e.originX,e.originY),c}}const Qr=xe(Pe,Ce((a,t,e,s)=>{const r=wr(t,t.originX,t.originY,e,s);if(H(t.originX)===H(P)||H(t.originX)===H(z)&&r.x<0||H(t.originX)===H(L)&&r.x>0){const{target:i}=t,n=i.strokeWidth/(i.strokeUniform?i.scaleX:1),o=Xi(t)?2:1,h=i.width,l=Math.abs(r.x*o/i.scaleX)-n;return i.set("width",Math.max(l,1)),h!==i.width}return!1}));function xo(a,t,e,s,r){s=s||{};const i=this.sizeX||s.cornerSize||r.cornerSize,n=this.sizeY||s.cornerSize||r.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:r.transparentCorners,h=o?ot:N,l=!o&&(s.cornerStrokeColor||r.cornerStrokeColor);let c,u=t,g=e;a.save(),a.fillStyle=s.cornerColor||r.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",i>n?(c=i,a.scale(1,n/i),g=e*i/n):n>i?(c=n,a.scale(i/n,1),u=t*n/i):c=i,a.beginPath(),a.arc(u,g,c/2,0,ys,!1),a[h](),l&&a.stroke(),a.restore()}function Co(a,t,e,s,r){s=s||{};const i=this.sizeX||s.cornerSize||r.cornerSize,n=this.sizeY||s.cornerSize||r.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:r.transparentCorners,h=o?ot:N,l=!o&&(s.cornerStrokeColor||r.cornerStrokeColor),c=i/2,u=n/2;a.save(),a.fillStyle=s.cornerColor||r.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",a.translate(t,e);const g=r.getTotalAngle();a.rotate(G(g)),a["".concat(h,"Rect")](-c,-u,i,n),l&&a.strokeRect(-c,-u,i,n),a.restore()}class vt{constructor(t){p(this,"visible",!0),p(this,"actionName",Ps),p(this,"angle",0),p(this,"x",0),p(this,"y",0),p(this,"offsetX",0),p(this,"offsetY",0),p(this,"sizeX",0),p(this,"sizeY",0),p(this,"touchSizeX",0),p(this,"touchSizeY",0),p(this,"cursorStyle","crosshair"),p(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,r){var i;let{tl:n,tr:o,br:h,bl:l}=r;return((i=e.canvas)===null||i===void 0?void 0:i.getActiveObject())===e&&e.isControlVisible(t)&&V.isPointInPolygon(s,[n,o,h,l])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,r;return(s=(r=t._controlsVisibility)===null||r===void 0?void 0:r[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,r){return new y(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,r,i,n){const o=xr([Ie(s,r),ye({angle:t}),Cr((i?this.touchSizeX:this.sizeX)||e,(i?this.touchSizeY:this.sizeY)||e)]);return{tl:new y(-.5,-.5).transform(o),tr:new y(.5,-.5).transform(o),br:new y(.5,.5).transform(o),bl:new y(-.5,.5).transform(o)}}render(t,e,s,r,i){((r=r||{}).cornerStyle||i.cornerStyle)==="circle"?xo.call(this,t,e,s,r,i):Co.call(this,t,e,s,r,i)}}const bo=(a,t,e)=>e.lockRotation?ws:t.cursorStyle,So=xe(Si,Ce((a,t,e,s)=>{let{target:r,ex:i,ey:n,theta:o,originX:h,originY:l}=t;const c=r.translateToOriginPoint(r.getRelativeCenterPoint(),h,l);if(bt(r,"lockRotation"))return!1;const u=Math.atan2(n-c.y,i-c.x),g=Math.atan2(s-c.y,e-c.x);let d=Xt(g-u+o);if(r.snapAngle&&r.snapAngle>0){const v=r.snapAngle,_=r.snapThreshold||v,x=Math.ceil(d/v)*v,b=Math.floor(d/v)*v;Math.abs(d-b)<_?d=b:Math.abs(d-x)<_&&(d=x)}d<0&&(d=360+d),d%=360;const f=r.angle!==d;return r.angle=d,f}));function $i(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Zi(a,t,e){const s=bt(a,"lockScalingX"),r=bt(a,"lockScalingY");if(s&&r||!t&&(s||r)&&e||s&&t==="x"||r&&t==="y")return!0;const{width:i,height:n,strokeWidth:o}=a;return i===0&&o===0&&t!=="y"||n===0&&o===0&&t!=="x"}const wo=["e","se","s","sw","w","nw","n","ne","e"],Oe=(a,t,e)=>{const s=$i(a,e);if(Zi(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return ws;const r=Yi(e,t);return"".concat(wo[r],"-resize")};function Dr(a,t,e,s){let r=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const i=t.target,n=r.by,o=$i(a,i);let h,l,c,u,g,d;if(Zi(i,n,o))return!1;if(t.gestureScale)l=t.scaleX*t.gestureScale,c=t.scaleY*t.gestureScale;else{if(h=wr(t,t.originX,t.originY,e,s),g=n!=="y"?Math.sign(h.x||t.signX||1):1,d=n!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=g),t.signY||(t.signY=d),bt(i,"lockScalingFlip")&&(t.signX!==g||t.signY!==d))return!1;if(u=i._getTransformedDimensions(),o&&!n){const _=Math.abs(h.x)+Math.abs(h.y),{original:x}=t,b=_/(Math.abs(u.x*x.scaleX/i.scaleX)+Math.abs(u.y*x.scaleY/i.scaleY));l=x.scaleX*b,c=x.scaleY*b}else l=Math.abs(h.x*i.scaleX/u.x),c=Math.abs(h.y*i.scaleY/u.y);Xi(t)&&(l*=2,c*=2),t.signX!==g&&n!=="y"&&(t.originX=Yr(t.originX),l*=-1,t.signX=g),t.signY!==d&&n!=="x"&&(t.originY=Yr(t.originY),c*=-1,t.signY=d)}const f=i.scaleX,v=i.scaleY;return n?(n==="x"&&i.set(at,l),n==="y"&&i.set(ft,c)):(!bt(i,"lockScalingX")&&i.set(at,l),!bt(i,"lockScalingY")&&i.set(ft,c)),f!==i.scaleX||v!==i.scaleY}const ze=xe(Es,Ce((a,t,e,s)=>Dr(a,t,e,s))),To=xe(Es,Ce((a,t,e,s)=>Dr(a,t,e,s,{by:"x"}))),Oo=xe(Es,Ce((a,t,e,s)=>Dr(a,t,e,s,{by:"y"}))),Do=["target","ex","ey","skewingSide"],qs={x:{counterAxis:"y",scale:at,skew:me,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:ft,skew:ve,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},ko=["ns","nesw","ew","nwse"],Mo=(a,t,e)=>{if(t.x!==0&&bt(e,"lockSkewingY")||t.y!==0&&bt(e,"lockSkewingX"))return ws;const s=Yi(e,t)%4;return"".concat(ko[s],"-resize")};function Qi(a,t,e,s,r){const{target:i}=e,{counterAxis:n,origin:o,lockSkewing:h,skew:l,flip:c}=qs[a];if(bt(i,h))return!1;const{origin:u,flip:g}=qs[n],d=H(e[u])*(i[g]?-1:1),f=-Math.sign(d)*(i[c]?-1:1),v=.5*-((i[l]===0&&wr(e,P,P,s,r)[a]>0||i[l]>0?1:-1)*f)+.5;return xe(wi,Ce((x,b,T,w)=>function(C,D,k){let{target:S,ex:M,ey:E,skewingSide:W}=D,j=Y(D,Do);const{skew:R}=qs[C],F=k.subtract(new y(M,E)).divide(new y(S.scaleX,S.scaleY))[C],K=S[R],q=j[R],J=Math.tan(G(q)),I=C==="y"?S._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:S._getTransformedDimensions({scaleX:1,scaleY:1}).y,St=2*F*W/Math.max(I,1)+J,Mt=Xt(Math.atan(St));S.set(R,Mt);const We=K!==S[R];if(We&&C==="y"){const{skewX:Ws,scaleX:be}=S,Vt=S._getTransformedDimensions({skewY:K}),Ye=S._getTransformedDimensions(),$t=Ws!==0?Vt.x/Ye.x:1;$t!==1&&S.set(at,$t*be)}return We}(a,b,new y(T,w))))(t,m(m({},e),{},{[o]:v,skewingSide:f}),s,r)}const Eo=(a,t,e,s)=>Qi("x",a,t,e,s),Po=(a,t,e,s)=>Qi("y",a,t,e,s);function Rs(a,t){return a[t.canvas.altActionKey]}const Ge=(a,t,e)=>{const s=Rs(a,e);return t.x===0?s?me:ft:t.y===0?s?ve:at:""},he=(a,t,e)=>Rs(a,e)?Mo(0,t,e):Oe(a,t,e),ti=(a,t,e,s)=>Rs(a,t.target)?Po(a,t,e,s):To(a,t,e,s),ei=(a,t,e,s)=>Rs(a,t.target)?Eo(a,t,e,s):Oo(a,t,e,s),tn=()=>({ml:new vt({x:-.5,y:0,cursorStyleHandler:he,actionHandler:ti,getActionName:Ge}),mr:new vt({x:.5,y:0,cursorStyleHandler:he,actionHandler:ti,getActionName:Ge}),mb:new vt({x:0,y:.5,cursorStyleHandler:he,actionHandler:ei,getActionName:Ge}),mt:new vt({x:0,y:-.5,cursorStyleHandler:he,actionHandler:ei,getActionName:Ge}),tl:new vt({x:-.5,y:-.5,cursorStyleHandler:Oe,actionHandler:ze}),tr:new vt({x:.5,y:-.5,cursorStyleHandler:Oe,actionHandler:ze}),bl:new vt({x:-.5,y:.5,cursorStyleHandler:Oe,actionHandler:ze}),br:new vt({x:.5,y:.5,cursorStyleHandler:Oe,actionHandler:ze}),mtr:new vt({x:0,y:-.5,actionHandler:So,cursorStyleHandler:bo,offsetY:-40,withConnection:!0,actionName:yr})}),jo=()=>({mr:new vt({x:.5,y:0,actionHandler:Qr,cursorStyleHandler:he,actionName:Pe}),ml:new vt({x:-.5,y:0,actionHandler:Qr,cursorStyleHandler:he,actionName:Pe})}),Ao=()=>m(m({},tn()),jo());class Le extends Et{static getDefaults(){return m(m({},super.getDefaults()),Le.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Le.ownDefaults),this.setOptions(t)}static createControls(){return{controls:tn()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,r=e.action;if(this===s&&r&&r.startsWith(Ps))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let r=s.length-1;r>=0;r--){const[i,n]=s[r],o=this.controls[i];if(o.shouldActivate(i,this,t,e?n.touchCorner:n.corner))return this.__corner=i,{key:i,control:o,coord:this.oCoords[i]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Ie(e.x,e.y),r=ye({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),i=$(s,r),n=$(t,i),o=$(n,[1/t[0],0,0,1/t[3],0,0]),h=this.group?bs(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const l=this._calculateCurrentDimensions(h),c={};return this.forEachControl((u,g)=>{const d=u.positionHandler(l,o,this,u);c[g]=Object.assign(d,this._calcCornerCoords(u,d))}),c}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),r=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/r[0],1/r[3]),t.rotate(G(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const r=m({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=r.borderColor,this._setLineDash(t,r.borderDashArray),this.strokeBorders(t,e),r.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:r}=this,i=m({hasBorders:s,hasControls:r},e),n=this.getViewportTransform(),o=i.hasBorders,h=i.hasControls,l=$(n,this.calcTransformMatrix()),c=bs(l);t.save(),t.translate(c.translateX,c.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(c.angle-=180),t.rotate(G(this.group?c.angle:this.angle)),o&&this.drawBorders(t,c,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let r;if(s&&s.forActiveSelection||this.group){const i=Sr(this.width,this.height,js(e)),n=this.isStrokeAccountedForInDimensions()?_r:(this.strokeUniform?new y().scalarAdd(this.canvas?this.canvas.getZoom():1):new y(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);r=i.add(n).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else r=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,r,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((r,i)=>{r.withConnection&&r.getVisibility(this,i)&&(s=!0,t.moveTo(r.x*e.x,r.y*e.y),t.lineTo(r.x*e.x+r.offsetX,r.y*e.y+r.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:r,cornerDashArray:i,cornerColor:n}=this,o=m({cornerStrokeColor:r,cornerDashArray:i,cornerColor:n},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,l)=>{if(h.getVisibility(this,l)){const c=this.oCoords[l];h.render(t,c.x,c.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,r]=e;return this.setControlVisible(s,r)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const r=this.width+4,i=this.height+4;return e.clearRect(-r/2,-i/2,r,i),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function en(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}p(Le,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class Z extends Le{}en(Z,[Vi]),O.setClass(Z),O.setClass(Z,"object");const Fo=(a,t,e,s)=>{const r=2*(s=Math.round(s))+1,{data:i}=a.getImageData(t-s,e-s,r,r);for(let n=3;n<i.length;n+=4)if(i[n]>0)return!1;return!0};class sn{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new y(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new y(1/this.options.scaleX,1/this.options.scaleY):new y(1,1)}createSideVector(t,e){const s=or(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new y(t);return e.y+=e.x*Math.tan(G(this.options.skewY)),e.x+=e.y*Math.tan(G(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const Lo=new y;class de extends sn{static getOrthogonalRotationFactor(t,e){const s=e?hr(t,e):so(t);return Math.abs(s)<Be?-1:1}constructor(t,e,s,r){super(r),p(this,"AB",void 0),p(this,"AC",void 0),p(this,"alpha",void 0),p(this,"bisector",void 0),this.A=new y(t),this.B=new y(e),this.C=new y(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=hr(this.AB,this.AC),this.bisector=Tr(qi(this.AB.eq(Lo)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const r=this.createSideVector(t,e),i=Ki(r),n=de.getOrthogonalRotationFactor(i,this.bisector);return this.scaleUnitVector(i,s*n)}projectBevel(){const t=[];return(this.alpha%ys==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),r=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),i=this.options.strokeUniform?ar(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return ar(r)/this.strokeProjectionMagnitude<=i&&t.push(this.applySkew(this.A.add(r))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],r=new y(de.getOrthogonalRotationFactor(this.bisector),de.getOrthogonalRotationFactor(new y(this.bisector.y,this.bisector.x)));return[new y(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(r),new y(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(r)].forEach(i=>{Jr(i,t,e)&&s.push(this.A.add(i))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:r,skewY:i,scaleX:n,scaleY:o,strokeUniform:h}=this.options,l=new y(Math.tan(G(r)),Math.tan(G(i))),c=this.strokeProjectionMagnitude,u=h?c/o/Math.sqrt(1/o**2+1/n**2*l.y**2):c/Math.sqrt(1+l.y**2),g=new y(Math.sqrt(Math.max(c**2-u**2,0)),u),d=h?c/Math.sqrt(1+l.x**2*(1/o)**2/(1/n+1/n*l.x*l.y)**2):c/Math.sqrt(1+l.x**2/(1+l.x*l.y)**2),f=new y(d,Math.sqrt(Math.max(c**2-d**2,0)));return[f,f.scalarMultiply(-1),g,g.scalarMultiply(-1)].map(v=>this.applySkew(h?v.multiply(this.strokeUniformScalar):v)).forEach(v=>{Jr(v,t,e)&&s.push(this.applySkew(this.A).add(v))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%ys==0,s=this.applySkew(this.A),r=t[e?0:2].subtract(s),i=t[e?1:0].subtract(s),n=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=Ee(r,n)>0,h=o?r:i,l=o?i:r;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,l)):t.push(...this.projectRoundNoSkew(h,l)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class si extends sn{constructor(t,e,s){super(s),this.A=new y(t),this.T=new y(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const r=this.createSideVector(t,e);return this.scaleUnitVector(Ki(r),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new y(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new de(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new y(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(Tr(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),r=this.A.add(s);t.push(r.add(e),r.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Ro=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const r=a.reduce((i,n)=>(i[i.length-1].eq(n)||i.push(new y(n)),i),[new y(a[0])]);if(r.length===1)e=!0;else if(!e){const i=r[0],n=((o,h)=>{for(let l=o.length-1;l>=0;l--)if(h(o[l],l,o))return l;return-1})(r,o=>!o.eq(i));r.splice(n+1)}return r.forEach((i,n,o)=>{let h,l;n===0?(l=o[1],h=e?i:o[o.length-1]):n===o.length-1?(h=o[n-1],l=e?i:o[0]):(h=o[n-1],l=o[n+1]),e&&o.length===1?s.push(...new si(i,i,t).project()):!e||n!==0&&n!==o.length-1?s.push(...new de(i,h,l,t).project()):s.push(...new si(i,n===0?l:h,t).project())}),s},kr=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=m({},a[e][s])})}),t},Bo=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;");let we;const Mr=a=>{if(we||we||(we="Intl"in Ms()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),we){const t=we.segment(a);return Array.from(t).map(e=>{let{segment:s}=e;return s})}return Io(a)},Io=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=Xo(a,s))!==!1&&t.push(e);return t},Xo=(a,t)=>{const e=a.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return a.charAt(t);if(55296<=e&&e<=56319){if(a.length<=t+1)throw"High surrogate without following low surrogate";const r=a.charCodeAt(t+1);if(56320>r||r>57343)throw"High surrogate without following low surrogate";return a.charAt(t)+a.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=a.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1},Er=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textDecorationThickness!==t.textDecorationThickness||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},Wo=(a,t)=>{const e=t.split(`
38
+ `),s=[];let r=-1,i={};a=kr(a);for(let n=0;n<e.length;n++){const o=Mr(e[n]);if(a[n])for(let h=0;h<o.length;h++){r++;const l=a[n][h];l&&Object.keys(l).length>0&&(Er(i,l,!0)?s.push({start:r,end:r+1,style:l}):s[s.length-1].end++),i=l||{}}else r+=o.length,i={}}return s},Yo=(a,t)=>{if(!Array.isArray(a))return kr(a);const e=t.split(vr),s={};let r=-1,i=0;for(let n=0;n<e.length;n++){const o=Mr(e[n]);for(let h=0;h<o.length;h++)r++,a[i]&&a[i].start<=r&&r<a[i].end&&(s[n]=s[n]||{},s[n][h]=m({},a[i].style),r===a[i].end-1&&i++)}return s},Jt=["display","transform",N,"fill-opacity","fill-rule","opacity",ot,"stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"];function ri(a,t){const e=a.nodeName,s=a.getAttribute("class"),r=a.getAttribute("id"),i="(?![a-zA-Z\\-]+)";let n;if(n=new RegExp("^"+e,"i"),t=t.replace(n,""),r&&t.length&&(n=new RegExp("#"+r+i,"i"),t=t.replace(n,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)n=new RegExp("\\."+o[h]+i,"i"),t=t.replace(n,"")}return t.length===0}function Vo(a,t){let e=!0;const s=ri(a,t.pop());return s&&t.length&&(e=function(r,i){let n,o=!0;for(;r.parentElement&&r.parentElement.nodeType===1&&i.length;)o&&(n=i.pop()),o=ri(r=r.parentElement,n);return i.length===0}(a,t)),s&&e&&t.length===0}const zo=a=>{var t;return(t=to[a])!==null&&t!==void 0?t:a},Go=new RegExp("(".concat(Ct,")"),"gi"),Ho=a=>a.replace(Go," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var ii,ni,oi,ai,hi,li,ci;const et="(".concat(Ct,")"),No=String.raw(ii||(ii=kt(["(skewX)(",")"],["(skewX)\\(","\\)"])),et),Uo=String.raw(ni||(ni=kt(["(skewY)(",")"],["(skewY)\\(","\\)"])),et),qo=String.raw(oi||(oi=kt(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),et,et,et),Ko=String.raw(ai||(ai=kt(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),et,et),Jo=String.raw(hi||(hi=kt(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),et,et),$o=String.raw(li||(li=kt(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),et,et,et,et,et,et),Pr="(?:".concat($o,"|").concat(Jo,"|").concat(qo,"|").concat(Ko,"|").concat(No,"|").concat(Uo,")"),Zo="(?:".concat(Pr,"*)"),Qo=String.raw(ci||(ci=kt(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),Zo),ta=new RegExp(Qo),ea=new RegExp(Pr),sa=new RegExp(Pr,"g");function lr(a){const t=[];if(!(a=Ho(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!ta.test(a))return[...st];for(const e of a.matchAll(sa)){const s=ea.exec(e[0]);if(!s)continue;let r=st;const i=s.filter(f=>!!f),[,n,...o]=i,[h,l,c,u,g,d]=o.map(f=>parseFloat(f));switch(n){case"translate":r=Ie(h,l);break;case yr:r=ye({angle:h},{x:l,y:c});break;case Ps:r=Cr(h,l);break;case me:r=Pi(h);break;case ve:r=ji(h);break;case"matrix":r=[h,l,c,u,g,d]}t.push(r)}return xr(t)}function ra(a,t,e,s){const r=Array.isArray(t);let i,n=t;if(a!==N&&a!==ot||t!==nt){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")n=t===nt?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")n=e&&e.transformMatrix?$(e.transformMatrix,lr(t)):lr(t);else if(a==="visible")n=t!==nt&&t!=="hidden",e&&e.visible===!1&&(n=!1);else if(a==="opacity")n=parseFloat(t),e&&e.opacity!==void 0&&(n*=e.opacity);else if(a==="textAnchor")n=t==="start"?L:t==="end"?z:P;else if(a==="charSpacing"||a===re)i=ge(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(N),h=t.indexOf(ot);n=N,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(n=ot)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";i=r?t.map(ge):ge(t,s)}}else n="";return!r&&isNaN(i)?n:i}function ia(a,t){const e=a.match(Qn);if(!e)return;const s=e[1],r=e[3],i=e[4],n=e[5],o=e[6];s&&(t.fontStyle=s),r&&(t.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),i&&(t.fontSize=ge(i)),o&&(t.fontFamily=o),n&&(t.lineHeight=n==="normal"?1:n)}function na(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,r]=e.split(":");t[s.trim().toLowerCase()]=r.trim()})}function oa(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?na(e,t):function(s,r){Object.entries(s).forEach(i=>{let[n,o]=i;o!==void 0&&(r[n.toLowerCase()]=o)})}(e,t)),t}const aa={stroke:"strokeOpacity",fill:"fillOpacity"};function Yt(a,t,e){if(!a)return{};let s,r={},i=mr;a.parentNode&&Kr.test(a.parentNode.nodeName)&&(r=Yt(a.parentElement,t,e),r.fontSize&&(s=i=ge(r.fontSize)));const n=m(m(m({},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 g in c)Vo(l,g.split(" "))&&(u=m(m({},u),c[g]));return u}(a,e)),oa(a));n[Ns]&&a.setAttribute(Ns,n[Ns]),n[Hs]&&(s=ge(n[Hs],i),n[Hs]="".concat(s));const o={};for(const l in n){const c=zo(l),u=ra(c,n[l],r,s);o[c]=u}o&&o.font&&ia(o.font,o);const h=m(m({},r),o);return Kr.test(a.nodeName)?h:function(l){const c=Z.getDefaults();return Object.entries(aa).forEach(u=>{let[g,d]=u;if(l[d]===void 0||l[g]==="")return;if(l[g]===void 0){if(!c[g])return;l[g]=c[g]}if(l[g].indexOf("url(")===0)return;const f=new B(l[g]);l[g]=f.setAlpha(X(f.getAlpha()*l[d],2)).toRgba()}),l}(h)}const ha=["left","top","width","height","visible"],rn=["rx","ry"];class lt extends Z{static getDefaults(){return m(m({},super.getDefaults()),lt.ownDefaults)}constructor(t){super(),Object.assign(this,lt.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,r=-e/2,i=-s/2,n=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,h=n!==0||o!==0;t.beginPath(),t.moveTo(r+n,i),t.lineTo(r+e-n,i),h&&t.bezierCurveTo(r+e-Gt*n,i,r+e,i+Gt*o,r+e,i+o),t.lineTo(r+e,i+s-o),h&&t.bezierCurveTo(r+e,i+s-Gt*o,r+e-Gt*n,i+s,r+e-n,i+s),t.lineTo(r+n,i+s),h&&t.bezierCurveTo(r+Gt*n,i+s,r,i+s-Gt*o,r,i+s-o),t.lineTo(r,i+o),h&&t.bezierCurveTo(r,i+Gt*o,r+Gt*n,i,r+n,i),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...rn,...t])}_toSVG(){const{width:t,height:e,rx:s,ry:r}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(s,'" ry="').concat(r,'" width="').concat(t,'" height="').concat(e,`" />
39
+ `)]}static async fromElement(t,e,s){const r=Yt(t,this.ATTRIBUTE_NAMES,s),{left:i=0,top:n=0,width:o=0,height:h=0,visible:l=!0}=r,c=Y(r,ha);return new this(m(m(m({},e),c),{},{left:i,top:n,width:o,height:h,visible:!!(l&&o&&h)}))}}p(lt,"type","Rect"),p(lt,"cacheProperties",[...Wt,...rn]),p(lt,"ownDefaults",{rx:0,ry:0}),p(lt,"ATTRIBUTE_NAMES",[...Jt,"x","y","rx","ry","width","height"]),O.setClass(lt),O.setSVGClass(lt);const jt="initialization",Os="added",jr="removed",Ds="imperative",nn=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:r,height:i,group:n}=t,o=n&&n!==a?Fs(n.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),l=!t.isStrokeAccountedForInDimensions(),c=e&&l?Nn(new y(s,s),void 0,a.calcTransformMatrix()):_r,u=!e&&l?s:0,g=Sr(r+u,i+u,xr([o,t.calcOwnMatrix()],!0)).add(c).scalarDivide(2);return[h.subtract(g),h.add(g)]};class Bs{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:r}=t;return e===jt||e===Ds||!!s&&r!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==jt&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:r}=e;if(s===Ds&&e.overrides)return e.overrides;if(t.length===0)return;const{left:i,top:n,width:o,height:h}=Ft(t.map(u=>nn(r,u)).reduce((u,g)=>u.concat(g),[])),l=new y(o,h),c=new y(i,n).add(l.scalarDivide(2));if(s===jt){const u=this.getInitialSize(e,{size:l,center:c});return{center:c,relativeCorrection:new y(0,0),size:u}}return{center:c.transform(r.calcOwnMatrix()),size:l}}}p(Bs,"type","strategy");class cr extends Bs{shouldPerformLayout(t){return!0}}p(cr,"type","fit-content"),O.setClass(cr);const la=["strategy"],ca=["target","strategy","bubbles","prevStrategy"],on="layoutManager";class Re{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new cr;p(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=m(m({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[xs,bi,Pe,Si,Es,wi,_s,jn,An].map(r=>t.on(r,i=>this.performLayout(r===xs?{type:"object_modified",trigger:r,e:i,target:s}:{type:"object_modifying",trigger:r,e:i,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:r}=e;if(s===jt||s===Os?this.subscribeTargets(t):s===jr&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),r&&r.fire("object:layout:before",{target:e,context:t}),s===Ds&&t.deep){const i=Y(t,la);e.forEachObject(n=>n.layoutManager&&n.layoutManager.performLayout(m(m({},i),{},{bubbles:!1,target:n})))}}getLayoutResult(t){const{target:e,strategy:s,type:r}=t,i=s.calcLayoutResult(t,e.getObjects());if(!i)return;const n=r===jt?new y:e.getRelativeCenterPoint(),{center:o,correction:h=new y,relativeCorrection:l=new y}=i,c=n.subtract(o).add(h).transform(r===jt?st:xt(e.calcOwnMatrix()),!0).add(l);return{result:i,prevCenter:n,nextCenter:o,offset:c}}commitLayout(t,e){const{target:s}=t,{result:{size:r},nextCenter:i}=e;var n,o;s.set({width:r.x,height:r.y}),this.layoutObjects(t,e),t.type===jt?s.set({left:(n=t.x)!==null&&n!==void 0?n:i.x+r.x*H(s.originX),top:(o=t.y)!==null&&o!==void 0?o:i.y+r.y*H(s.originY)}):(s.setPositionByOrigin(i,P,P),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(r=>{r.group===s&&this.layoutObject(t,e,r)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:r}=e;s.set({left:s.left+r.x,top:s.top+r.y})}onAfterLayout(t,e){const{target:s,strategy:r,bubbles:i,prevStrategy:n}=t,o=Y(t,ca),{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;i&&l!=null&&l.layoutManager&&((o.path||(o.path=[])).push(s),l.layoutManager.performLayout(m(m({},o),{},{target:l}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:on,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}O.setClass(Re,on);const ua=["type","objects","layoutManager"];class ga extends Re{performLayout(){}}class Ut extends Ti(Z){static getDefaults(){return m(m({},super.getDefaults()),Ut.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),p(this,"_activeObjects",[]),p(this,"__objectSelectionTracker",void 0),p(this,"__objectSelectionDisposer",void 0),Object.assign(this,Ut.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(r=>{this.enterGroup(r,!1)}),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new Re,this.layoutManager.performLayout({type:jt,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(qt("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(qt("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,r)=>this.canEnterGroup(e)&&r.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const r=this._filterObjectsBeforeEnteringGroup(e),i=super.add(...r);return this._onAfterObjectsChange(Os,r),i}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),r=1;r<e;r++)s[r-1]=arguments[r];const i=this._filterObjectsBeforeEnteringGroup(s),n=super.insertAt(t,...i);return this._onAfterObjectsChange(Os,i),n}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(jr,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(r=>{r._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const r=this._activeObjects;if(t)r.push(s),this._set("dirty",!0);else if(r.length>0){const i=r.indexOf(s);i>-1&&(r.splice(i,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&&Ss(t,$(xt(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||(Ss(t,$(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=Z.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 i=0;i<this._objects.length;i++){var r;const n=this._objects[i];(r=this.canvas)!==null&&r!==void 0&&r.preserveObjectStacking&&n.group!==this?(t.save(),t.transform(...xt(this.calcTransformMatrix())),n.render(t),t.restore()):n.group===this&&n.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(m({target:this,type:Ds},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(r){return!r.excludeFromExport}).map(function(r){const i=r.includeDefaultValues;r.includeDefaultValues=s;const n=r[t||"toObject"](e);return r.includeDefaultValues=i,n})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return m(m(m({},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=lt.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const r=e.join("");return t?t(r):r}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
40
+ `],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let r=0;r<this._objects.length;r++)e.push(" ",this._objects[r].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 r=0;r<this._objects.length;r++)e.push(" ",this._objects[r].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:r=[],layoutManager:i}=t,n=Y(t,ua);return Promise.all([je(r,e),As(n,e)]).then(o=>{let[h,l]=o;const c=new this(h,m(m(m({},n),l),{},{layoutManager:new ga}));if(i){const u=O.getClass(i.type),g=O.getClass(i.strategy);c.layoutManager=new u(new g)}else c.layoutManager=new Re;return c.layoutManager.subscribeTargets({type:jt,target:c,targets:c.getObjects()}),c.setCoords(),c})}}p(Ut,"type","Group"),p(Ut,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),O.setClass(Ut);const da=(a,t)=>Math.min(t.width/a.width,t.height/a.height),fa=(a,t)=>Math.max(t.width/a.width,t.height/a.height),ur="\\s*,?\\s*",Te="".concat(ur,"(").concat(Ct,")"),pa="".concat(Te).concat(Te).concat(Te).concat(ur,"([01])").concat(ur,"([01])").concat(Te).concat(Te),ma={m:"l",M:"L"},va=(a,t,e,s,r,i,n,o,h,l,c)=>{const u=Rt(a),g=Bt(a),d=Rt(t),f=Bt(t),v=e*r*d-s*i*f+n,_=s*r*d+e*i*f+o;return["C",l+h*(-e*r*g-s*i*u),c+h*(-s*r*g+e*i*u),v+h*(e*r*f+s*i*d),_+h*(s*r*f-e*i*d),v,_]},ui=(a,t,e,s)=>{const r=Math.atan2(t,a),i=Math.atan2(s,e);return i>=r?i-r:2*Math.PI-(r-i)};function gi(a,t,e,s,r,i,n,o){let h;if(A.cachesBoundsOfCurve&&(h=[...arguments].join(),De.boundsOfCurveCache[h]))return De.boundsOfCurveCache[h];const l=Math.sqrt,c=Math.abs,u=[],g=[[0,0],[0,0]];let d=6*a-12*e+6*r,f=-3*a+9*e-9*r+3*n,v=3*e-3*a;for(let w=0;w<2;++w){if(w>0&&(d=6*t-12*s+6*i,f=-3*t+9*s-9*i+3*o,v=3*s-3*t),c(f)<1e-12){if(c(d)<1e-12)continue;const M=-v/d;0<M&&M<1&&u.push(M);continue}const C=d*d-4*v*f;if(C<0)continue;const D=l(C),k=(-d+D)/(2*f);0<k&&k<1&&u.push(k);const S=(-d-D)/(2*f);0<S&&S<1&&u.push(S)}let _=u.length;const x=_,b=an(a,t,e,s,r,i,n,o);for(;_--;){const{x:w,y:C}=b(u[_]);g[0][_]=w,g[1][_]=C}g[0][x]=a,g[1][x]=t,g[0][x+1]=n,g[1][x+1]=o;const T=[new y(Math.min(...g[0]),Math.min(...g[1])),new y(Math.max(...g[0]),Math.max(...g[1]))];return A.cachesBoundsOfCurve&&(De.boundsOfCurveCache[h]=T),T}const ya=(a,t,e)=>{let[s,r,i,n,o,h,l,c]=e;const u=((g,d,f,v,_,x,b)=>{if(f===0||v===0)return[];let T=0,w=0,C=0;const D=Math.PI,k=b*pr,S=Bt(k),M=Rt(k),E=.5*(-M*g-S*d),W=.5*(-M*d+S*g),j=f**2,R=v**2,F=W**2,K=E**2,q=j*R-j*F-R*K;let J=Math.abs(f),I=Math.abs(v);if(q<0){const zt=Math.sqrt(1-q/(j*R));J*=zt,I*=zt}else C=(_===x?-1:1)*Math.sqrt(q/(j*F+R*K));const St=C*J*W/I,Mt=-C*I*E/J,We=M*St-S*Mt+.5*g,Ws=S*St+M*Mt+.5*d;let be=ui(1,0,(E-St)/J,(W-Mt)/I),Vt=ui((E-St)/J,(W-Mt)/I,(-E-St)/J,(-W-Mt)/I);x===0&&Vt>0?Vt-=2*D:x===1&&Vt<0&&(Vt+=2*D);const Ye=Math.ceil(Math.abs(Vt/D*2)),$t=[],Se=Vt/Ye,Dn=8/3*Math.sin(Se/4)*Math.sin(Se/4)/Math.sin(Se/2);let Ys=be+Se;for(let zt=0;zt<Ye;zt++)$t[zt]=va(be,Ys,M,S,J,I,We,Ws,Dn,T,w),T=$t[zt][5],w=$t[zt][6],be=Ys,Ys+=Se;return $t})(l-a,c-t,r,i,o,h,n);for(let g=0,d=u.length;g<d;g++)u[g][1]+=a,u[g][2]+=t,u[g][3]+=a,u[g][4]+=t,u[g][5]+=a,u[g][6]+=t;return u},_a=a=>{let t=0,e=0,s=0,r=0;const i=[];let n,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],r=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":n==="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":n==="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":ya(t,e,c).forEach(g=>i.push(g)),t=c[6],e=c[7];break;case"z":case"Z":t=s,e=r,u=["Z"]}u?(i.push(u),n=u[0]):n=""}return i},ks=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),an=(a,t,e,s,r,i,n,o)=>h=>{const l=h**3,c=(d=>3*d**2*(1-d))(h),u=(d=>3*d*(1-d)**2)(h),g=(d=>(1-d)**3)(h);return new y(n*l+r*c+e*u+a*g,o*l+i*c+s*u+t*g)},hn=a=>a**2,ln=a=>2*a*(1-a),cn=a=>(1-a)**2,xa=(a,t,e,s,r,i,n,o)=>h=>{const l=hn(h),c=ln(h),u=cn(h),g=3*(u*(e-a)+c*(r-e)+l*(n-r)),d=3*(u*(s-t)+c*(i-s)+l*(o-i));return Math.atan2(d,g)},Ca=(a,t,e,s,r,i)=>n=>{const o=hn(n),h=ln(n),l=cn(n);return new y(r*o+e*h+a*l,i*o+s*h+t*l)},ba=(a,t,e,s,r,i)=>n=>{const o=1-n,h=2*(o*(e-a)+n*(r-e)),l=2*(o*(s-t)+n*(i-s));return Math.atan2(l,h)},di=(a,t,e)=>{let s=new y(t,e),r=0;for(let i=1;i<=100;i+=1){const n=a(i/100);r+=ks(s.x,s.y,n.x,n.y),s=n}return r},Sa=(a,t)=>{let e,s=0,r=0,i={x:a.x,y:a.y},n=m({},i),o=.01,h=0;const l=a.iterator,c=a.angleFinder;for(;r<t&&o>1e-4;)n=l(s),h=s,e=ks(i.x,i.y,n.x,n.y),e+r>t?(s-=o,o/=2):(i=n,s+=o,r+=e);return m(m({},n),{},{angle:c(h)})},un=a=>{let t,e,s=0,r=0,i=0,n=0,o=0;const h=[];for(const l of a){const c={x:r,y:i,command:l[0],length:0};switch(l[0]){case"M":e=c,e.x=n=r=l[1],e.y=o=i=l[2];break;case"L":e=c,e.length=ks(r,i,l[1],l[2]),r=l[1],i=l[2];break;case"C":t=an(r,i,l[1],l[2],l[3],l[4],l[5],l[6]),e=c,e.iterator=t,e.angleFinder=xa(r,i,l[1],l[2],l[3],l[4],l[5],l[6]),e.length=di(t,r,i),r=l[5],i=l[6];break;case"Q":t=Ca(r,i,l[1],l[2],l[3],l[4]),e=c,e.iterator=t,e.angleFinder=ba(r,i,l[1],l[2],l[3],l[4]),e.length=di(t,r,i),r=l[3],i=l[4];break;case"Z":e=c,e.destX=n,e.destY=o,e.length=ks(r,i,n,o),r=n,i=o}s+=e.length,h.push(e)}return h.push({length:s,x:r,y:i}),h},wa=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:un(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const r=e[s],i=t/r.length,n=a[s];switch(r.command){case"M":return{x:r.x,y:r.y,angle:0};case"Z":return m(m({},new y(r.x,r.y).lerp(new y(r.destX,r.destY),i)),{},{angle:Math.atan2(r.destY-r.y,r.destX-r.x)});case"L":return m(m({},new y(r.x,r.y).lerp(new y(n[1],n[2]),i)),{},{angle:Math.atan2(n[2]-r.y,n[1]-r.x)});case"C":case"Q":return Sa(r,t)}},Ta=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),fi=new RegExp(pa,"g"),Oa=new RegExp(Ct,"gi"),Da={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},ka=a=>{var t;const e=[],s=(t=a.match(Ta))!==null&&t!==void 0?t:[];for(const r of s){const i=r[0];if(i==="z"||i==="Z"){e.push([i]);continue}const n=Da[i.toLowerCase()];let o=[];if(i==="a"||i==="A"){fi.lastIndex=0;for(let h=null;h=fi.exec(r);)o.push(...h.slice(1))}else o=r.match(Oa)||[];for(let h=0;h<o.length;h+=n){const l=new Array(n),c=ma[i];l[0]=h>0&&c?c:i;for(let u=0;u<n;u++)l[u+1]=parseFloat(o[h+u]);e.push(l)}}return e},Ma=(a,t)=>a.map(e=>e.map((s,r)=>r===0||t===void 0?s:X(s,t)).join(" ")).join(" ");function gr(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[r,i]=s;return e.setProperty(r,i)}))}class Ea extends Ri{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),p(this,"upper",void 0),p(this,"container",void 0);const{el:r}=this.lower,i=this.createUpperCanvas();this.upper={el:i,ctx:i.getContext("2d")},this.applyCanvasStyle(r,{allowTouchScrolling:e}),this.applyCanvasStyle(i,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const n=this.createContainerElement();n.classList.add(s),r.parentNode&&r.parentNode.replaceChild(n,r),n.append(r,i),this.container=n}createUpperCanvas(){const{el:t}=this.lower,e=It();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=pe().createElement("div");return t.setAttribute("data-fabric","wrapper"),gr(t,{position:"relative"}),Xr(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:r}=e;gr(t,m(m({},s),{},{"touch-action":r?"manipulation":nt})),Xr(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:r}=this.upper;Li(s,r,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),ir(this.upper.el,t),ir(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:r}=this.upper;super.cleanupDOM(t),e.removeChild(r),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),Dt().dispose(this.upper.el),delete this.upper,delete this.container}}class Is extends Xe{constructor(){super(...arguments),p(this,"targets",[]),p(this,"_hoveredTargets",[]),p(this,"_objectsToRender",void 0),p(this,"_currentTransform",null),p(this,"_groupSelector",null),p(this,"contextTopDirty",!1)}static getDefaults(){return m(m({},super.getDefaults()),Is.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 Ea(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 r=this.targetFindTolerance,i=this.pixelFindContext;this.clearContext(i),i.save(),i.translate(-e+r,-s+r),i.transform(...this.viewportTransform);const n=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(i),t.selectionBackgroundColor=n,i.restore();const o=Math.round(r*this.getRetinaScaling());return Fo(i,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(),r=this._activeObject;return!!(!e||e&&r&&s.length>1&&s.indexOf(e)===-1&&r!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&r&&r!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let r;return e===Ps||e===at||e===ft||e===Pe?r=this.centeredScaling||t.centeredScaling:e===yr&&(r=this.centeredRotation||t.centeredRotation),r?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=z:["mr","tr","br"].includes(e)&&(s.x=L),["tl","mt","tr"].includes(e)?s.y=rr:["bl","mb","br"].includes(e)&&(s.y=it)),s}_setupCurrentTransform(t,e,s){var r;const i=e.group?ue(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:n="",control:o}=e.getActiveControl()||{},h=s&&o?(r=o.getActionHandler(t,e,o))===null||r===void 0?void 0:r.bind(o):Kn,l=((d,f,v,_)=>{if(!f||!d)return"drag";const x=_.controls[f];return x.getActionName(v,x,_)})(s,n,t,e),c=t[this.centeredKey],u=this._shouldCenterTransform(e,l,c)?{x:P,y:P}:this._getOriginFromCorner(e,n),g={target:e,action:l,actionHandler:h,actionPerformed:!1,corner:n,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:i.x-e.left,offsetY:i.y-e.top,originX:u.x,originY:u.y,ex:i.x,ey:i.y,lastX:i.x,lastY:i.y,theta:G(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:c,original:m(m({},Bi(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=g,this.fire("before:transform",{e:t,transform:g})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:r,deltaY:i}=this._groupSelector,n=new y(e,s).transform(this.viewportTransform),o=new y(e+r,s+i).transform(this.viewportTransform),h=this.selectionLineWidth/2;let l=Math.min(n.x,o.x),c=Math.min(n.y,o.y),u=Math.max(n.x,o.x),g=Math.max(n.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(l,c,u-l,g-c)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,l+=h,c+=h,u-=h,g-=h,Z.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(l,c,u-l,g-c))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,r=this.getActiveObjects();if(this.targets=[],s&&r.length>=1){if(s.findControl(e,nr(t))||r.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const i=this.targets;this.targets=[];const n=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&n&&n!==s?(this.targets=i,s):n}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const r=this.getZoom(),i=t.padding/r;if(i){const[n,o,h,l]=s,c=Math.atan2(o.y-n.y,o.x-n.x),u=Rt(c)*i,g=Bt(c)*i,d=u+g,f=u-g;s=[new y(n.x-f,n.y-d),new y(o.x+d,o.y-f),new y(h.x+f,h.y+d),new y(l.x-d,l.y+f)]}return V.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,ue(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 r=t[s];if(this._checkTarget(r,e)){if(fs(r)&&r.subTargetCheck){const i=this._searchPossibleTargets(r._objects,e);i&&this.targets.push(i)}return r}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&fs(s)&&s.interactive&&this.targets[0]){const r=this.targets;for(let i=r.length-1;i>0;i--){const n=r[i];if(!fs(n)||!n.interactive)return n}return r[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,r=s.getBoundingClientRect();let i=Vn(t),n=r.width||0,o=r.height||0;n&&o||(it in r&&rr in r&&(o=Math.abs(r.top-r.bottom)),z in r&&L in r&&(n=Math.abs(r.right-r.left))),this.calcOffset(),i.x=i.x-this._offset.left,i.y=i.y-this._offset.top,e||(i=ue(i,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(i.x/=h,i.y/=h);const l=n===0||o===0?new y(1,1):new y(s.width/n,s.height/o);return i.multiply(l)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=It(),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 Zt(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,r=!1;const i=this.getActiveObjects(),n=[],o=[];t.forEach(h=>{i.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))}),i.forEach(h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),n.push(h))}),t.length>0&&i.length>0?(r=!0,s&&this.fire("selection:updated",{e,selected:n,deselected:o})):i.length>0?(r=!0,this.fire("selection:created",{e,selected:n})):t.length>0&&(r=!0,this.fire("selection:cleared",{e,deselected:o})),r&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),r=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),r}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,Zt(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),Zt(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 r=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),r}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,r={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",r),s.fire(xs,r))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Zt(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 r=this._realizeGroupTransformOnObject(t),i=super._toObject(t,e,s);return t.set(r),i}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&Zt(e)&&this._activeObject===e){const s=_e(t,["angle","flipX","flipY",L,at,ft,me,ve,it]);return Gn(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const r=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(r)}}p(Is,"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 Pa{constructor(t){p(this,"targets",[]),p(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:r}=t.getActiveObject()||{};r&&r.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),ae(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 ja=["target","oldTarget","fireCanvas","e"],ht={passive:!1},oe=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Ht=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)},ut=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)},Aa={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 dr extends Is{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),p(this,"_isClick",void 0),p(this,"textEditingManager",new Pa(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(Ht,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,r=this._getEventPrefix();t(Fi(s),"resize",this._onResize),t(s,r+"down",this._onMouseDown),t(s,"".concat(r,"move"),this._onMouseMove,ht),t(s,"".concat(r,"out"),this._onMouseOut),t(s,"".concat(r,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"click",this._onClick),t(s,"dblclick",this._onClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,ht)}removeListeners(){this.addOrRemove(ut,"remove");const t=this._getEventPrefix(),e=_t(this.upperCanvasEl);ut(e,"".concat(t,"up"),this._onMouseUp),ut(e,"touchend",this._onTouchEnd,ht),ut(e,"".concat(t,"move"),this._onMouseMove,ht),ut(e,"touchmove",this._onMouseMove,ht),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=m({e:t},oe(this,t));this.fire("mouse:out",m(m({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",m({},s)),this._hoveredTargets.forEach(r=>{this.fire("mouse:out",m(m({},s),{},{target:r})),r&&r.fire("mouseout",m({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",m({e:t},oe(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 Ht(this.upperCanvasEl,"drag",this._onDragProgress)}Wr(t)}_renderDragEffects(t,e,s){let r=!1;const i=this._dropTarget;i&&i!==e&&i!==s&&(i.clearContextTop(),r=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const n=this.contextTop;n.save(),n.transform(...this.viewportTransform),e&&(n.save(),e.transform(n),e.renderDragSourceEffect(t),n.restore(),r=!0),s&&(n.save(),s.transform(n),s.renderDropTargetEffect(t),n.restore(),r=!0),n.restore(),r&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==nt,s=e?this._activeObject:void 0,r={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};ut(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",r),this._dragSource&&this._dragSource.fire("dragend",r),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:r}=this.findDragTargets(t),i=this._dragSource,n={e:t,target:s,subTargets:r,dragSource:i,canDrop:!1,dropTarget:void 0};let o;this.fire(e,n),this._fireEnterLeaveEvents(s,n),s&&(s.canDrop(t)&&(o=s),s.fire(e,n));for(let h=0;h<r.length;h++){const l=r[h];l.canDrop(t)&&(o=l),l.fire(e,n)}this._renderDragEffects(t,i,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),r={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",r),this._fireEnterLeaveEvents(e,r)}_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),r=this._basicEventHandler("drop:before",m({e:t,target:e,subTargets:s,dragSource:this._dragSource},oe(this,t)));r.didDrop=!1,r.dropTarget=void 0,this._basicEventHandler("drop",r),this.fire("drop:after",r)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],r=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&Wr(t),this._basicEventHandler("contextmenu",r),!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 r=this.upperCanvasEl,i=this._getEventPrefix(),n=_t(r);Ht(n,"touchend",this._onTouchEnd,ht),e&&Ht(n,"touchmove",this._onMouseMove,ht),ut(r,"".concat(i,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ut(e,"".concat(s,"move"),this._onMouseMove,ht);const r=_t(e);Ht(r,"".concat(s,"up"),this._onMouseUp),Ht(r,"".concat(s,"move"),this._onMouseMove,ht)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=_t(this.upperCanvasEl);ut(s,"touchend",this._onTouchEnd,ht),ut(s,"touchmove",this._onMouseMove,ht),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Ht(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 r=_t(this.upperCanvasEl);ut(r,"".concat(s,"up"),this._onMouseUp),ut(r,"".concat(s,"move"),this._onMouseMove,ht),Ht(e,"".concat(s,"move"),this._onMouseMove,ht)}}_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,r=this._isClick,i=this._target,{button:n}=t;if(n)return(this.fireMiddleClick&&n===1||this.fireRightClick&&n===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),!r){const c=i===this._activeObject;this.handleSelection(t),l||(l=this._shouldRender(i)||!c&&i===this._activeObject)}if(i){const c=i.findControl(this.getViewportPoint(t),nr(t)),{key:u,control:g}=c||{};if(h=u,i.selectable&&i!==this._activeObject&&i.activeOn==="up")this.setActiveObject(i,t),l=!0;else if(g){const d=g.getMouseUpHandler(t,i,g);d&&(o=this.getScenePoint(t),d.call(g,t,s,o.x,o.y))}i.isMoving=!1}if(s&&(s.target!==i||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,i),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,i&&(i.__corner=void 0),l?this.requestRenderAll():r||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:r=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let i=0;i<r.length;i++)r[i]!==s&&r[i].fire(t,e);return e}_handleEvent(t,e,s){const r=this._target,i=this.targets||[],n=m(m(m({e:t,target:r,subTargets:i},oe(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),n),r&&r.fire("mouse".concat(e),n);for(let o=0;o<i.length;o++)i[o]!==r&&i[o].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down",{alreadySelected:!1})}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target,s=!!e&&e===this._activeObject;const{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===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 i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!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),nr(t));if(e===this._activeObject&&(o||!n)){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)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=ue(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,r=this._hoveredTargets,i=this.targets,n=Math.max(r.length,i.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<n;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:i[o],oldTarget:r[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,r=this._hoveredTargets,i=this.targets,n=Math.max(r.length,i.length);this.fireSyntheticInOutEvents("drag",m(m({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<n;o++)this.fireSyntheticInOutEvents("drag",m(m({},e),{},{target:i[o],oldTarget:r[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:r,fireCanvas:i,e:n}=e,o=Y(e,ja);const{targetIn:h,targetOut:l,canvasIn:c,canvasOut:u}=Aa[t],g=r!==s;if(r&&g){const d=m(m({},o),{},{e:n,target:r,nextTarget:s},oe(this,n));i&&this.fire(u,d),r.fire(l,d)}if(s&&g){const d=m(m({},o),{},{e:n,target:s,previousTarget:r},oe(this,n));i&&this.fire(c,d),s.fire(h,d)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,r=s.target,i=r.group?ue(e,void 0,r.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,i),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:r,actionHandler:i,target:n}=e,o=!!i&&i(t,e,s.x,s.y);o&&n.setCoords(),r==="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 r=Zt(this._activeObject)?this._activeObject:null,i=(!r||e.group!==r)&&e.findControl(this.getViewportPoint(t));if(i){const n=i.control;this.setCursor(n.cursorStyleHandler(t,n,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(n=>{s=n.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,r=Zt(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||r)&&(r||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(r){const i=s.getObjects();if(e===s){const n=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(i,n)||this.searchPossibleTargets(this._objects,n))||!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(i,t)}else{s.isEditing&&s.exitEditing();const i=new(O.getClass("ActiveSelection"))([],{canvas:this});i.multiSelectAdd(s,e),this._hoveredTarget=i,this._setActiveObject(i,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:r,deltaY:i}=this._groupSelector,n=new y(e,s),o=n.add(new y(r,i)),h=n.min(o),l=n.max(o).subtract(h),c=this.collectObjects({left:h.x,top:h.y,width:l.x,height:l.y},{includeIntersecting:!this.selectionFullyContained}),u=n.eq(o)?c[0]?[c[0]]:[]:c.length>1?c.filter(g=>!g.onSelect({e:t})).reverse():c;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const g=O.getClass("ActiveSelection");this.setActiveObject(new g(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const gn={x1:0,y1:0,x2:0,y2:0},Fa=m(m({},gn),{},{r1:0,r2:0}),le=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,La=/^(\d+\.\d+)%|(\d+)%$/;function dn(a){return a&&La.test(a)}function fn(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(dn(a)?100:1):NaN;return fe(0,le(e,t),1)}const Ra=/\s*;\s*/,Ba=/\s*:\s*/;function Ia(a,t){let e,s;const r=a.getAttribute("style");if(r){const n=r.split(Ra);n[n.length-1]===""&&n.pop();for(let o=n.length;o--;){const[h,l]=n[o].split(Ba).map(c=>c.trim());h==="stop-color"?e=l:h==="stop-opacity"&&(s=l)}}const i=new B(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:fn(a.getAttribute("offset"),0),color:i.toRgb(),opacity:le(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*i.getAlpha()*t}}function Xa(a,t){const e=[],s=a.getElementsByTagName("stop"),r=fn(t,1);for(let i=s.length;i--;)e.push(Ia(s[i],r));return e}function pn(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function mn(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function mt(a,t){return a.getAttribute(t)}function Wa(a,t){return function(e,s){let r,{width:i,height:n,gradientUnits:o}=s;return Object.keys(e).reduce((h,l)=>{const c=e[l];return c==="Infinity"?r=1:c==="-Infinity"?r=0:(r=typeof c=="string"?parseFloat(c):c,typeof c=="string"&&dn(c)&&(r*=.01,o==="pixels"&&(l!=="x1"&&l!=="x2"&&l!=="r2"||(r*=i),l!=="y1"&&l!=="y2"||(r*=n)))),h[l]=r,h},{})}(pn(a)==="linear"?function(e){return{x1:mt(e,"x1")||0,y1:mt(e,"y1")||0,x2:mt(e,"x2")||"100%",y2:mt(e,"y2")||0}}(a):function(e){return{x1:mt(e,"fx")||mt(e,"cx")||"50%",y1:mt(e,"fy")||mt(e,"cy")||"50%",r1:0,x2:mt(e,"cx")||"50%",y2:mt(e,"cy")||"50%",r2:mt(e,"r")||"50%"}}(a),m(m({},t),{},{gradientUnits:mn(a)}))}class He{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:r={},colorStops:i=[],offsetX:n=0,offsetY:o=0,gradientTransform:h,id:l}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:m(m({},e==="radial"?Fa:gn),r),colorStops:i,offsetX:n,offsetY:o,gradientTransform:h,id:l?"".concat(l,"_").concat(Kt()):Kt()})}addColorStop(t){for(const e in t){const s=new B(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return m(m({},_e(this,t)),{},{type:this.type,coords:m({},this.coords),colorStops:this.colorStops.map(e=>m({},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=[],r=this.gradientTransform?this.gradientTransform.concat():st.concat(),i=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",n=this.colorStops.map(u=>m({},u)).sort((u,g)=>u.offset-g.offset);let o=-this.offsetX,h=-this.offsetY;var l;i==="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),r[4]-=o,r[5]-=h;const c=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(i,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Ae(r),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:g,x2:d,y2:f}=this.coords;s.push("<linearGradient ",c,' x1="',u,'" y1="',g,'" x2="',d,'" y2="',f,`">
42
+ `)}else if(this.type==="radial"){const{x1:u,y1:g,x2:d,y2:f,r1:v,r2:_}=this.coords,x=v>_;s.push("<radialGradient ",c,' cx="',x?u:d,'" cy="',x?g:f,'" r="',x?v:_,'" fx="',x?d:u,'" fy="',x?f:g,`">
43
+ `),x&&(n.reverse(),n.forEach(T=>{T.offset=1-T.offset}));const b=Math.min(v,_);if(b>0){const T=b/Math.max(v,_);n.forEach(w=>{w.offset+=T*(1-w.offset)})}}return n.forEach(u=>{let{color:g,offset:d,opacity:f}=u;s.push("<stop ",'offset="',100*d+"%",'" style="stop-color:',g,f!==void 0?";stop-opacity: "+f:";",`"/>
44
+ `)}),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
45
+ `),s.join("")}toLive(t){const{x1:e,y1:s,x2:r,y2:i,r1:n,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,r,i):t.createRadialGradient(e,s,n,r,i,o);return this.colorStops.forEach(l=>{let{color:c,opacity:u,offset:g}=l;h.addColorStop(g,u!==void 0?new B(c).setAlpha(u).toRgba():c)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(m(m({},t),{},{colorStops:e?e.map(r=>m({},r)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const r=mn(t),i=e._findCenterFromElement();return new this(m({id:t.getAttribute("id")||void 0,type:pn(t),coords:Wa(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:Xa(t,s.opacity),gradientUnits:r,gradientTransform:lr(t.getAttribute("gradientTransform")||"")},r==="pixels"?{offsetX:e.width/2-i.x,offsetY:e.height/2-i.y}:{offsetX:0,offsetY:0}))}}p(He,"type","Gradient"),O.setClass(He,"gradient"),O.setClass(He,"linear"),O.setClass(He,"radial");const Ya=["type","source","patternTransform"];class Ks{get type(){return"pattern"}set type(t){qt("warn","Setting type has no effect",t)}constructor(t){p(this,"repeat","repeat"),p(this,"offsetX",0),p(this,"offsetY",0),p(this,"crossOrigin",""),this.id=Kt(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return m(m({},_e(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:X(this.offsetX,A.NUM_FRACTION_DIGITS),offsetY:X(this.offsetY,A.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:r,repeat:i,id:n}=this,o=le(this.offsetX/e,0),h=le(this.offsetY/s,0),l=i==="repeat-y"||i==="no-repeat"?1+Math.abs(o||0):le(r.width/e,0),c=i==="repeat-x"||i==="no-repeat"?1+Math.abs(h||0):le(r.height/s,0);return['<pattern id="SVGID_'.concat(n,'" x="').concat(o,'" y="').concat(h,'" width="').concat(l,'" height="').concat(c,'">'),'<image x="0" y="0" width="'.concat(r.width,'" height="').concat(r.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
46
+ `)}static async fromObject(t,e){let{type:s,source:r,patternTransform:i}=t,n=Y(t,Ya);const o=await ms(r,m(m({},e),{},{crossOrigin:n.crossOrigin}));return new this(m(m({},n),{},{patternTransform:i&&i.slice(0),source:o}))}}p(Ks,"type","Pattern"),O.setClass(Ks),O.setClass(Ks,"pattern");const Va=["path","left","top"],za=["d"];class Qt extends Z{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:r,top:i}=e,n=Y(e,Va);super(),Object.assign(this,Qt.ownDefaults),this.setOptions(n),this._setPath(t||[],!0),typeof r=="number"&&this.set(L,r),typeof i=="number"&&this.set(it,i)}_setPath(t,e){this.path=_a(Array.isArray(t)?t:ka(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new y(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const r of this.path)switch(r[0]){case"L":t.lineTo(r[1]+e,r[2]+s);break;case"M":t.moveTo(r[1]+e,r[2]+s);break;case"C":t.bezierCurveTo(r[1]+e,r[2]+s,r[3]+e,r[4]+s,r[5]+e,r[6]+s);break;case"Q":t.quadraticCurveTo(r[1]+e,r[2]+s,r[3]+e,r[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return m(m({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=Ma(this.path,A.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
47
+ `)]}_getOffsetTransform(){const t=A.NUM_FRACTION_DIGITS;return" translate(".concat(X(-this.pathOffset.x,t),", ").concat(X(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:r}=this._calcDimensions();this.set({width:e,height:s,pathOffset:r}),t&&this.setPositionByOrigin(r,P,P)}_calcBoundsFromPath(){const t=[];let e=0,s=0,r=0,i=0;for(const n of this.path)switch(n[0]){case"L":r=n[1],i=n[2],t.push({x:e,y:s},{x:r,y:i});break;case"M":r=n[1],i=n[2],e=r,s=i;break;case"C":t.push(...gi(r,i,n[1],n[2],n[3],n[4],n[5],n[6])),r=n[5],i=n[6];break;case"Q":t.push(...gi(r,i,n[1],n[2],n[1],n[2],n[3],n[4])),r=n[3],i=n[4];break;case"Z":r=e,i=s}return Ft(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return m(m({},t),{},{pathOffset:new y(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const r=Yt(t,this.ATTRIBUTE_NAMES,s),{d:i}=r;return new this(i,m(m(m({},Y(r,za)),e),{},{left:void 0,top:void 0}))}}p(Qt,"type","Path"),p(Qt,"cacheProperties",[...Wt,"path","fillRule"]),p(Qt,"ATTRIBUTE_NAMES",[...Jt,"d"]),O.setClass(Qt),O.setSVGClass(Qt);const Ga=["left","top","radius"],vn=["radius","startAngle","endAngle","counterClockwise"];class wt extends Z{static getDefaults(){return m(m({},super.getDefaults()),wt.ownDefaults)}constructor(t){super(),Object.assign(this,wt.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),t==="radius"&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,G(this.startAngle),G(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(at)}getRadiusY(){return this.get("radius")*this.get(ft)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...vn,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
48
+ `];{const{radius:e}=this,s=G(this.startAngle),r=G(this.endAngle),i=Rt(s)*e,n=Bt(s)*e,o=Rt(r)*e,h=Bt(r)*e,l=t>180?1:0,c=this.counterClockwise?0:1;return['<path d="M '.concat(i," ").concat(n," A ").concat(e," ").concat(e," 0 ").concat(l," ").concat(c," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
49
+ `]}}static async fromElement(t,e,s){const r=Yt(t,this.ATTRIBUTE_NAMES,s),{left:i=0,top:n=0,radius:o=0}=r;return new this(m(m({},Y(r,Ga)),{},{radius:o,left:i-o,top:n-o}))}static fromObject(t){return super._fromObject(t)}}p(wt,"type","Circle"),p(wt,"cacheProperties",[...Wt,...vn]),p(wt,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),p(wt,"ATTRIBUTE_NAMES",["cx","cy","r",...Jt]),O.setClass(wt),O.setSVGClass(wt);const Ha=["x1","y1","x2","y2"],Na=["x1","y1","x2","y2"],fr=["x1","x2","y1","y2"];class te extends Z{constructor(){let[t,e,s,r]=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[0,0,0,0],i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,te.ownDefaults),this.setOptions(i),this.x1=t,this.x2=s,this.y1=e,this.y2=r,this._setWidthHeight();const{left:n,top:o}=i;typeof n=="number"&&this.set(L,n),typeof o=="number"&&this.set(it,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:r}=this;this.width=Math.abs(s-t),this.height=Math.abs(r-e);const{left:i,top:n,width:o,height:h}=Ft([{x:t,y:e},{x:s,y:r}]),l=new y(i+o/2,n+h/2);this.setPositionByOrigin(l,P,P)}_set(t,e){return super._set(t,e),fr.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var r;dt(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(r=this.stroke)!==null&&r!==void 0?r:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new y((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return m(m({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:r,width:i,height:n}=this,o=t<=e?-1:1,h=s<=r?-1:1;return{x1:o*i/2,x2:o*-i/2,y1:h*n/2,y2:h*-n/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:r}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(r,`" />
50
+ `)]}static async fromElement(t,e,s){const r=Yt(t,this.ATTRIBUTE_NAMES,s),{x1:i=0,y1:n=0,x2:o=0,y2:h=0}=r;return new this([i,n,o,h],Y(r,Ha))}static fromObject(t){let{x1:e,y1:s,x2:r,y2:i}=t,n=Y(t,Na);return this._fromObject(m(m({},n),{},{points:[e,s,r,i]}),{extraParam:"points"})}}p(te,"type","Line"),p(te,"cacheProperties",[...Wt,...fr]),p(te,"ATTRIBUTE_NAMES",Jt.concat(fr)),O.setClass(te),O.setSVGClass(te);class ee extends Z{static getDefaults(){return m(m({},super.getDefaults()),ee.ownDefaults)}constructor(t){super(),Object.assign(this,ee.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),'" />']}}p(ee,"type","Triangle"),p(ee,"ownDefaults",{width:100,height:100}),O.setClass(ee),O.setSVGClass(ee);const yn=["rx","ry"];class Pt extends Z{static getDefaults(){return m(m({},super.getDefaults()),Pt.ownDefaults)}constructor(t){super(),Object.assign(this,Pt.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(at)}getRy(){return this.get("ry")*this.get(ft)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...yn,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
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,ys,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const r=Yt(t,this.ATTRIBUTE_NAMES,s);return r.left=(r.left||0)-r.rx,r.top=(r.top||0)-r.ry,new this(r)}}function Ua(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}p(Pt,"type","Ellipse"),p(Pt,"cacheProperties",[...Wt,...yn]),p(Pt,"ownDefaults",{rx:0,ry:0}),p(Pt,"ATTRIBUTE_NAMES",[...Jt,"cx","cy","rx","ry"]),O.setClass(Pt),O.setSVGClass(Pt);const qa=["left","top"],_n={exactBoundingBox:!1};class yt extends Z{static getDefaults(){return m(m({},super.getDefaults()),yt.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),p(this,"strokeDiff",void 0),Object.assign(this,yt.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:r}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(L,s),typeof r=="number"&&this.set(it,r)}isOpen(){return!0}_projectStrokeOnPoints(t){return Ro(this.points,t,this.isOpen())}_calcDimensions(t){t=m({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 y,strokeOffset:new y,strokeDiff:new y};const s=Ft(e),r=js(m(m({},t),{},{scaleX:1,scaleY:1})),i=Ft(this.points.map(l=>rt(l,r,!0))),n=new y(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(G(this.skewX)),h-=o*Math.tan(G(this.skewY))),m(m({},s),{},{pathOffset:new y(o,h),strokeOffset:new y(i.left,i.top).subtract(new y(s.left,s.top)).multiply(n),strokeDiff:new y(s.width,s.height).subtract(new y(i.width,i.height)).multiply(n)})}_findCenterFromElement(){const t=Ft(this.points);return new y(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:r,height:i,pathOffset:n,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:r,height:i,pathOffset:n,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new y(e+r/2,s+i/2),P,P)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new y(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let n;if(Object.keys(t).some(o=>this.strokeUniform||this.constructor.layoutProperties.includes(o))){var e,s;const{width:o,height:h}=this._calcDimensions(t);n=new y((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var r,i;n=new y((r=t.width)!==null&&r!==void 0?r:this.width,(i=t.height)!==null&&i!==void 0?i:this.height)}return n.multiply(new y(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,r=super._set(t,e);return this.exactBoundingBox&&s&&((t===at||t===ft)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),r}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return m(m({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:s,y:r}=e;return{x:s,y:r}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,r=A.NUM_FRACTION_DIGITS;for(let i=0,n=this.points.length;i<n;i++)t.push(X(this.points[i].x-e,r),",",X(this.points[i].y-s,r)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
52
+ `)]}_render(t){const e=this.points.length,s=this.pathOffset.x,r=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-r);for(let i=0;i<e;i++){const n=this.points[i];t.lineTo(n.x-s,n.y-r)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(Ua(t.getAttribute("points")),m(m({},Y(Yt(t,this.ATTRIBUTE_NAMES,s),qa)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}p(yt,"ownDefaults",_n),p(yt,"type","Polyline"),p(yt,"layoutProperties",[me,ve,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),p(yt,"cacheProperties",[...Wt,"points"]),p(yt,"ATTRIBUTE_NAMES",[...Jt]),O.setClass(yt),O.setSVGClass(yt);class Ne extends yt{isOpen(){return!1}}p(Ne,"ownDefaults",_n),p(Ne,"type","Polygon"),O.setClass(Ne),O.setSVGClass(Ne);class xn extends Z{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 r in e[s])for(const i in e[s][r])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 r in s)for(const i in s[r])if(s[r][i][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,r,i=0,n=!0,o=0;for(const h in e){s=0;for(const l in e[h]){const c=e[h][l]||{};i++,c[t]!==void 0?(r?c[t]!==r&&(n=!1):r=c[t],c[t]===this[t]&&delete c[t]):n=!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;n&&i===o&&(this[t]=r,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,r,i;for(r in e){for(i in s=e[r],s)delete s[i][t],Object.keys(s[i]).length===0&&delete s[i];Object.keys(s).length===0&&delete e[r]}}_extendStyles(t,e){const{lineIndex:s,charIndex:r}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const i=br(m(m({},this._getStyleDeclaration(s,r)),e),n=>n!==void 0);this._setStyleDeclaration(s,r,i)}getSelectionStyles(t,e,s){const r=[];for(let i=t;i<(e||t);i++)r.push(this.getStyleAtPosition(i,s));return r}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:r}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,r):this._getStyleDeclaration(s,r)}setSelectionStyles(t,e,s){for(let r=e;r<(s||e);r++)this._extendStyles(r,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const r=this.styles&&this.styles[t];return r&&(s=r[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return m(m({},_e(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]}}p(xn,"_styleProperties",$n);const Ka=/ +/g,Ja=/"/g;function Js(a,t,e,s,r){return" ".concat(function(i,n){let{left:o,top:h,width:l,height:c}=n,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:A.NUM_FRACTION_DIGITS;const g=Fe(N,i,!1),[d,f,v,_]=[o,h,l,c].map(x=>X(x,u));return"<rect ".concat(g,' x="').concat(d,'" y="').concat(f,'" width="').concat(v,'" height="').concat(_,'"></rect>')}(a,{left:t,top:e,width:s,height:r}),`
53
+ `)}const $a=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let $s;class tt extends xn{static getDefaults(){return m(m({},super.getDefaults()),tt.ownDefaults)}constructor(t,e){super(),p(this,"__charBounds",[]),Object.assign(this,tt.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=un(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(Tt)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,r,i,n,o;for(let h=0,l=this._textLines.length;h<l;h++)if((this.textAlign===Tt||h!==l-1&&!this.isEndOfWrapping(h))&&(r=0,i=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<=i.length;c++)n=this.__charBounds[h][c],this._reSpaceAndTab.test(i[c])?(n.width+=t,n.kernedWidth+=t,n.left+=r,r+=t):n.left+=r}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let r;for(r=0;r<s.length;r++){if(t<=s[r].length)return{lineIndex:r,charIndex:t};t-=s[r].length+this.missingNewlineOffset(r,e)}return{lineIndex:r-1,charIndex:s[r-1].length<t?s[r-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===ot?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case P:t.textBaseline="middle";break;case"ascender":t.textBaseline=it;break;case"descender":t.textBaseline=rr}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const r=this.getLineWidth(e);r>t&&(t=r)}return t}_renderTextLine(t,e,s,r,i,n){this._renderChars(t,e,s,r,i,n)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let r=this._getTopOffset();for(let i=0,n=this._textLines.length;i<n;i++){const o=this.getHeightOfLine(i);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",i)){r+=o;continue}const h=this._textLines[i].length,l=this._getLineLeftOffset(i);let c,u,g=0,d=0,f=this.getValueOfPropertyAt(i,0,"textBackgroundColor");for(let v=0;v<h;v++){const _=this.__charBounds[i][v];u=this.getValueOfPropertyAt(i,v,"textBackgroundColor"),this.path?(t.save(),t.translate(_.renderLeft,_.renderTop),t.rotate(_.angle),t.fillStyle=u,u&&t.fillRect(-_.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),_.width,o/this.lineHeight),t.restore()):u!==f?(c=s+l+d,this.direction==="rtl"&&(c=this.width-c-g),t.fillStyle=f,f&&t.fillRect(c,r,g,o/this.lineHeight),d=_.left,g=_.width,f=u):g+=_.kernedWidth}u&&!this.path&&(c=s+l+d,this.direction==="rtl"&&(c=this.width-c-g),t.fillStyle=u,t.fillRect(c,r,g,o/this.lineHeight)),r+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,r){const i=De.getFontCache(e),n=this._getFontDeclaration(e),o=s+t,h=s&&n===this._getFontDeclaration(r),l=e.fontSize/this.CACHE_FONT_SIZE;let c,u,g,d;if(s&&i[s]!==void 0&&(g=i[s]),i[t]!==void 0&&(d=c=i[t]),h&&i[o]!==void 0&&(u=i[o],d=u-g),c===void 0||g===void 0||u===void 0){const f=function(){return $s||($s=pt({width:0,height:0}).getContext("2d")),$s}();this._setTextStyles(f,e,!0),c===void 0&&(d=c=f.measureText(t).width,i[t]=c),g===void 0&&h&&s&&(g=f.measureText(s).width,i[s]=g),h&&u===void 0&&(u=f.measureText(o).width,i[o]=u,d=u-g)}return{width:c*l,kernedWidth:d*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,r=0;const i=this.pathSide===z,n=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,r+=s.kernedWidth,e=u}if(l[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},n&&n.segmentsInfo){let c=0;const u=n.segmentsInfo[n.segmentsInfo.length-1].length;switch(this.textAlign){case L:c=i?u-r:0;break;case P:c=(u-r)/2;break;case z:c=i?0:u-r}c+=this.pathStartOffset*(i?-1:1);for(let g=i?h-1:0;i?g>=0:g<h;i?g--:g++)s=l[g],c>u?c%=u:c<0&&(c+=u),this._setGraphemeOnPath(c,s),c+=s.kernedWidth}return{width:r,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,r=this.path,i=wa(r.path,s,r.segmentsInfo);e.renderLeft=i.x-r.pathOffset.x,e.renderTop=i.y-r.pathOffset.y,e.angle=i.angle+(this.pathSide===z?Math.PI:0)}_getGraphemeBox(t,e,s,r,i){const n=this.getCompleteStyleDeclaration(e,s),o=r?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,n,r,o);let l,c=h.kernedWidth,u=h.width;this.charSpacing!==0&&(l=this._getWidthOfCharSpacing(),u+=l,c+=l);const g={width:u,left:0,height:n.fontSize,kernedWidth:c,deltaY:n.deltaY};if(s>0&&!i){const d=this.__charBounds[e][s-1];g.left=d.left+d.width+h.kernedWidth-h.width}return g}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,r=this._textLines[t].length;s<r;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,r=this._textLines.length;s<r;s++)t=this.getHeightOfLine(s),e+=s===r-1?t/this.lineHeight:t;return e}_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 r=this._getLeftOffset(),i=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const h=this.getHeightOfLine(n),l=h/this.lineHeight,c=this._getLineLeftOffset(n);this._renderTextLine(e,t,this._textLines[n],r+c,i+s+l,n),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(N))&&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,r,i,n){const o=this.getHeightOfLine(n),h=this.textAlign.includes(Tt),l=this.path,c=!h&&this.charSpacing===0&&this.isEmptyStyles(n)&&!l,u=this.direction==="ltr",g=this.direction==="ltr"?1:-1,d=e.direction;let f,v,_,x,b,T="",w=0;if(e.save(),d!==this.direction&&(e.canvas.setAttribute("dir",u?"ltr":"rtl"),e.direction=u?"ltr":"rtl",e.textAlign=u?L:z),i-=o*this._fontSizeFraction/this.lineHeight,c)return this._renderChar(t,e,n,0,s.join(""),r,i),void e.restore();for(let C=0,D=s.length-1;C<=D;C++)x=C===D||this.charSpacing||l,T+=s[C],_=this.__charBounds[n][C],w===0?(r+=g*(_.kernedWidth-_.width),w+=_.width):w+=_.kernedWidth,h&&!x&&this._reSpaceAndTab.test(s[C])&&(x=!0),x||(f=f||this.getCompleteStyleDeclaration(n,C),v=this.getCompleteStyleDeclaration(n,C+1),x=Er(f,v,!1)),x&&(l?(e.save(),e.translate(_.renderLeft,_.renderTop),e.rotate(_.angle),this._renderChar(t,e,n,C,T,-w/2,0),e.restore()):(b=r,this._renderChar(t,e,n,C,T,b,i)),T="",f=v,r+=g*w,w=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,r=pt({width:e,height:s}),i=r.getContext("2d");return r.width=e,r.height=s,i.beginPath(),i.moveTo(0,0),i.lineTo(e,0),i.lineTo(e,s),i.lineTo(0,s),i.closePath(),i.translate(e/2,s/2),i.fillStyle=t.toLive(i),this._applyPatternGradientTransform(i,t),i.fill(),i.createPattern(r,"no-repeat")}handleFiller(t,e,s){let r,i;return dt(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(r=-this.width/2,i=-this.height/2,t.translate(r,i),t[e]=this._applyPatternGradientTransformText(s),{offsetX:r,offsetY:i}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:r}=e;return t.lineWidth=r,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,r,i,n,o){const h=this._getStyleDeclaration(s,r),l=this.getCompleteStyleDeclaration(s,r),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 g=this._setFillStyles(e,l);e.fillText(i,n-g.offsetX,o-g.offsetY)}if(u){const g=this._setStrokeStyles(e,l);e.strokeText(i,n-g.offsetX,o-g.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 r=this.get2DCursorLocation(t,!0),i=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,"fontSize"),n=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,"deltaY"),o={fontSize:i*s.size,deltaY:n+i*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,r=this.textAlign,i=this.direction,n=this.isEndOfWrapping(t);let o=0;return r===Tt||r===Me&&!n||r===ke&&!n||r===Ts&&!n?0:(r===P&&(o=s/2),r===z&&(o=s),r===Me&&(o=s/2),r===ke&&(o=s),i==="rtl"&&(r===z||r===Tt||r===ke?o=0:r===L||r===Ts?o=-s:r!==P&&r!==Me||(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 r;return(r=this._getStyleDeclaration(t,e)[s])!==null&&r!==void 0?r:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const r=this._getLeftOffset(),i=this.path,n=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 g=this._textLines[l],d=u/this.lineHeight,f=this._getLineLeftOffset(l);let v=0,_=0,x=this.getValueOfPropertyAt(l,0,e),b=this.getValueOfPropertyAt(l,0,N),T=this.getValueOfPropertyAt(l,0,re),w=x,C=b,D=T;const k=s+d*(1-this._fontSizeFraction);let S=this.getHeightOfChar(l,0),M=this.getValueOfPropertyAt(l,0,"deltaY");for(let j=0,R=g.length;j<R;j++){const F=this.__charBounds[l][j];w=this.getValueOfPropertyAt(l,j,e),C=this.getValueOfPropertyAt(l,j,N),D=this.getValueOfPropertyAt(l,j,re);const K=this.getHeightOfChar(l,j),q=this.getValueOfPropertyAt(l,j,"deltaY");if(i&&w&&C){const J=this.fontSize*D/1e3;t.save(),t.fillStyle=b,t.translate(F.renderLeft,F.renderTop),t.rotate(F.angle),t.fillRect(-F.kernedWidth/2,h*K+q-o*J,F.kernedWidth,J),t.restore()}else if((w!==x||C!==b||K!==S||D!==T||q!==M)&&_>0){const J=this.fontSize*T/1e3;let I=r+f+v;this.direction==="rtl"&&(I=this.width-I-_),x&&b&&T&&(t.fillStyle=b,t.fillRect(I,k+h*S+M-o*J,_,J)),v=F.left,_=F.width,x=w,T=D,b=C,S=K,M=q}else _+=F.kernedWidth}let E=r+f+v;this.direction==="rtl"&&(E=this.width-E-_),t.fillStyle=C;const W=this.fontSize*D/1e3;w&&C&&D&&t.fillRect(E,k+h*S+M-o*W,_-n,W),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:r=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},i=arguments.length>1?arguments[1]:void 0;const n=t.includes("'")||t.includes('"')||t.includes(",")||tt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(i?this.CACHE_FONT_SIZE:r,"px"),n].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return Mr(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),r=[`
54
+ `];let i=[];for(let n=0;n<e.length;n++)s[n]=this.graphemeSplit(e[n]),i=i.concat(s[n],r);return i.pop(),{_unwrappedLines:s,lines:e,graphemeText:i,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return m(m({},super.toObject([...Ni,...t])),{},{styles:Wo(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let r=!1,i=!1;if(typeof t=="object")for(const n in t)n==="path"&&this.setPathInfo(),r=r||s.includes(n),i=i||n==="path";else r=s.includes(t),i=t==="path";return i&&this.setPathInfo(),r&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const r=Yt(t,tt.ATTRIBUTE_NAMES,s),i=m(m({},e),r),{textAnchor:n=L,textDecoration:o="",dx:h=0,dy:l=0,top:c=0,left:u=0,fontSize:g=mr,strokeWidth:d=1}=i,f=Y(i,$a),v=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),m({left:u+h,top:c+l,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:g},f)),_=v.getScaledHeight()/v.height,x=((v.height+v.strokeWidth)*v.lineHeight-v.height)*_,b=v.getScaledHeight()+x;let T=0;return n===P&&(T=v.getScaledWidth()/2),n===z&&(T=v.getScaledWidth()),v.set({left:v.left-T,top:v.top-(b-v.fontSize*(.07+v._fontSizeFraction))/v.lineHeight,strokeWidth:d}),v}static fromObject(t){return this._fromObject(m(m({},t),{},{styles:Yo(t.styles||{},t.text)}),{extraParam:"text"})}}p(tt,"textLayoutProperties",Hi),p(tt,"cacheProperties",[...Wt,...Ni]),p(tt,"ownDefaults",Zn),p(tt,"type","Text"),p(tt,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),p(tt,"ATTRIBUTE_NAMES",Jt.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),en(tt,[class extends Vi{_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:Ae(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(Ja,"'"),'" '),'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
+ `]}_getSVGTextAndBg(a,t){const e=[],s=[];let r,i=a;this.backgroundColor&&s.push(...Js(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let n=0,o=this._textLines.length;n<o;n++)r=this._getLineLeftOffset(n),this.direction==="rtl"&&(r+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",n))&&this._setSVGTextLineBg(s,n,t+r,i),this._setSVGTextLineText(e,n,t+r,i),i+=this.getHeightOfLine(n);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s,r){const i=A.NUM_FRACTION_DIGITS,n=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Ka)),o=n?'style="'.concat(n,'"'):"",h=t.deltaY,l=h?' dy="'.concat(X(h,i),'" '):"",{angle:c,renderLeft:u,renderTop:g,width:d}=r;let f="";if(u!==void 0){const v=d/2;c&&(f=' rotate="'.concat(X(Xt(c),i),'"'));const _=ye({angle:Xt(c)});_[4]=u,_[5]=g;const x=new y(-v,0).transform(_);e=x.x,s=x.y}return'<tspan x="'.concat(X(e,i),'" y="').concat(X(s,i),'" ').concat(l).concat(f).concat(o,">").concat(Bo(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const r=this.getHeightOfLine(t),i=this.textAlign.includes(Tt),n=this._textLines[t];let o,h,l,c,u,g="",d=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let f=0,v=n.length-1;f<=v;f++)u=f===v||this.charSpacing||this.path,g+=n[f],l=this.__charBounds[t][f],d===0?(e+=l.kernedWidth-l.width,d+=l.width):d+=l.kernedWidth,i&&!u&&this._reSpaceAndTab.test(n[f])&&(u=!0),u||(o=o||this.getCompleteStyleDeclaration(t,f),h=this.getCompleteStyleDeclaration(t,f+1),u=Er(o,h,!0)),u&&(c=this._getStyleDeclaration(t,f),a.push(this._createTextCharSpan(g,c,e,s,l)),g="",o=h,this.direction==="rtl"?e-=d:e+=d,d=0)}_setSVGTextLineBg(a,t,e,s){const r=this._textLines[t],i=this.getHeightOfLine(t)/this.lineHeight;let n,o=0,h=0,l=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let c=0;c<r.length;c++){const{left:u,width:g,kernedWidth:d}=this.__charBounds[t][c];n=this.getValueOfPropertyAt(t,c,"textBackgroundColor"),n!==l?(l&&a.push(...Js(l,e+h,s,o,i)),h=u,o=g,l=n):o+=d}n&&a.push(...Js(l,e+h,s,o,i))}_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(X(this.textDecorationThickness*this.getObjectScaling().y/10,A.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:r,fill:i,fontSize:n,fontStyle:o,fontWeight:h,deltaY:l,textDecorationThickness:c,linethrough:u,overline:g,underline:d}=a,f=this.getSvgTextDecoration({underline:d??this.underline,overline:g??this.overline,linethrough:u??this.linethrough}),v=c||this.textDecorationThickness;return[r?Fe(ot,r):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",n?"font-size: ".concat(n,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",f?"text-decoration: ".concat(f,"; text-decoration-thickness: ").concat(X(v*this.getObjectScaling().y/10,A.NUM_FRACTION_DIGITS),"%; "):"",i?Fe(N,i):"",l?"baseline-shift: ".concat(-l,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),O.setClass(tt),O.setSVGClass(tt);class Za{constructor(t){p(this,"target",void 0),p(this,"__mouseDownInPlace",!1),p(this,"__dragStartFired",!1),p(this,"__isDraggingOver",!1),p(this,"__dragStartSelection",void 0),p(this,"__dragImageDisposer",void 0),p(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(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:r,selectionEnd:i}=e;const n=this.target,o=n.canvas,h=new y(n.flipX?-1:1,n.flipY?-1:1),l=n._getCursorBoundaries(r),c=new y(l.left+l.leftOffset,l.top+l.topOffset).multiply(h).transform(n.calcTransformMatrix()),u=o.getScenePoint(t).subtract(c),g=n.getCanvasRetinaScaling(),d=n.getBoundingRect(),f=c.subtract(new y(d.left,d.top)),v=o.viewportTransform,_=f.add(u).transform(v,!0),x=n.backgroundColor,b=kr(n.styles);n.backgroundColor="";const T={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};n.setSelectionStyles(T,0,r),n.setSelectionStyles(T,i,n.text.length),n.dirty=!0;const w=n.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});n.backgroundColor=x,n.styles=b,n.dirty=!0,gr(w,{position:"fixed",left:"".concat(-w.width,"px"),border:nt,width:"".concat(w.width/g,"px"),height:"".concat(w.height/g,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{w.remove()},_t(t.target||this.target.hiddenTextarea).body.appendChild(w),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(w,_.x,_.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const r=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},i=e._text.slice(r.selectionStart,r.selectionEnd).join(""),n=m({text:e.text,value:i},r);t.dataTransfer.setData("text/plain",i),t.dataTransfer.setData("application/fabric",JSON.stringify({value:i,styles:e.getSelectionStyles(r.selectionStart,r.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,n)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=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,r=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let i=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(i&&!r){const n=this.target,o=n.canvas;let h=n.getSelectionStartFromPointer(s);const{styles:l}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},c=i[Math.max(0,i.length-1)],u=0;if(this.__dragStartSelection){const g=this.__dragStartSelection.selectionStart,d=this.__dragStartSelection.selectionEnd;h>g&&h<=d?h=g:h>d&&(h-=d-g),n.removeChars(g,d),delete this.__dragStartSelection}n._reNewline.test(c)&&(n._reNewline.test(n._text[h])||h===n._text.length)&&(i=i.trimEnd()),t.didDrop=!0,t.dropTarget=n,n.insertChars(i,l,h),o.setActiveObject(n),n.enterEditing(s),n.selectionStart=Math.min(h+u,n._text.length),n.selectionEnd=Math.min(n.selectionStart+i.length,n._text.length),n.hiddenTextarea.value=n.text,n._updateTextarea(),n.hiddenTextarea.focus(),n.fire(_s,{index:h+u,action:"drop"}),o.fire("text:changed",{target:n}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const r=this.target,i=this.target.canvas,{selectionStart:n,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||nt;h===nt?(r.selectionStart=n,r.selectionEnd=o,r._updateTextarea(),r.hiddenTextarea.focus()):(r.clearContextTop(),h==="move"&&(r.removeChars(n,o),r.selectionStart=r.selectionEnd=n,r.hiddenTextarea&&(r.hiddenTextarea.value=r.text),r._updateTextarea(),r.fire(_s,{index:n,action:"dragend"}),i.fire("text:changed",{target:r}),i.requestRenderAll()),r.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const pi=/[ \n\.,;!\?\-]/;class Qa extends tt{constructor(){super(...arguments),p(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:r,onComplete:i}=t;return Ji({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:r,onComplete:i,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:n=>{this._currentCursorOpacity=n,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 r=t>0&&this._reSpace.test(s[t])&&(e===-1||!vr.test(s[t-1]))?t-1:t,i=s[r];for(;r>0&&r<s.length&&!pi.test(i);)r+=e,i=s[r];return e===-1&&pi.test(i)&&r++,r}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),r=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=r,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),r=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=r,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;_t(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),r=this.selectionStart,i=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&r!==i||r!==s&&i!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===r&&this.selectionEnd===i||(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 r=s.slice(0,t),i=this.graphemeSplit(r).length;if(t===e)return{selectionStart:i,selectionEnd:i};const n=s.slice(t,e);return{selectionStart:i,selectionEnd:i+this.graphemeSplit(n).length}}fromGraphemeToStringSelection(t,e,s){const r=s.slice(0,t).join("").length;return t===e?{selectionStart:r,selectionEnd:r}:{selectionStart:r,selectionEnd:r+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),r=s.lineIndex,i=s.charIndex,n=this.getValueOfPropertyAt(r,i,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),l=this.canvas.upperCanvasEl,c=l.width/h,u=l.height/h,g=c-n,d=u-n,f=new y(e.left+o,e.top+e.topOffset+n).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new y(l.clientWidth/c,l.clientHeight/u));return f.x<0&&(f.x=0),f.x>g&&(f.x=g),f.y<0&&(f.y=0),f.y>d&&(f.y=d),f.x+=this.canvas._offset.left,f.y+=this.canvas._offset.top,{left:"".concat(f.x,"px"),top:"".concat(f.y,"px"),fontSize:"".concat(n,"px"),charHeight:n}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(xs),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:r}=this.get2DCursorLocation(t,!0),{lineIndex:i,charIndex:n}=this.get2DCursorLocation(e,!0);if(s!==i){if(this.styles[s])for(let o=r;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[i])for(let o=n;o<this._unwrappedTextLines[i].length;o++){const h=this.styles[i][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][r+o-n]=h)}for(let o=s+1;o<=i;o++)delete this.styles[o];this.shiftLineStyles(i,s-i)}else if(this.styles[s]){const o=this.styles[s],h=n-r;for(let l=r;l<n;l++)delete o[l];for(const l in this.styles[s]){const c=parseInt(l,10);c>=n&&(o[c-h]=o[l],delete o[l])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const r in this.styles){const i=parseInt(r,10);i>t&&(this.styles[i+e]=s[i],s[i-e]||delete this.styles[i])}}insertNewlineStyleObject(t,e,s,r){const i={},n=this._unwrappedTextLines[t].length,o=n===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 g=parseInt(u,10);g>=e&&(h=!0,i[g-e]=this.styles[t][u],o&&e===0||delete this.styles[t][u])}let c=!1;for(h&&!o&&(this.styles[t+s]=i,c=!0),(c||n>e)&&s--;s>0;)r&&r[s-1]?this.styles[t+s]={0:m({},r[s-1])}:l?this.styles[t+s]={0:m({},l)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,r){this.styles||(this.styles={});const i=this.styles[t],n=i?m({},i):{};s||(s=1);for(const h in n){const l=parseInt(h,10);l>=e&&(i[l+s]=n[l],n[l-s]||delete i[l])}if(this._forceClearCache=!0,r){for(;s--;)Object.keys(r[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=m({},r[s]));return}if(!i)return;const o=i[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=m({},o)}insertNewStyleBlock(t,e,s){const r=this.get2DCursorLocation(e,!0),i=[0];let n,o=0;for(let h=0;h<t.length;h++)t[h]===`
56
+ `?(o++,i[o]=0):i[o]++;for(i[0]>0&&(this.insertCharStyleObject(r.lineIndex,r.charIndex,i[0],s),s=s&&s.slice(i[0]+1)),o&&this.insertNewlineStyleObject(r.lineIndex,r.charIndex+i[0],o),n=1;n<o;n++)i[n]>0?this.insertCharStyleObject(r.lineIndex+n,0,i[n],s):s&&this.styles[r.lineIndex+n]&&s[0]&&(this.styles[r.lineIndex+n][0]=s[0]),s=s&&s.slice(i[n]+1);i[n]>0&&this.insertCharStyleObject(r.lineIndex+n,0,i[n],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 r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;r>s&&this.removeStyleFromTo(s,r);const i=this.graphemeSplit(t);this.insertNewStyleBlock(i,s,e),this._text=[...this._text.slice(0,s),...i,...this._text.slice(r)],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=L:this._selectionDirection===z&&(this._selectionDirection=L,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===z?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=z:this._selectionDirection===L&&(this._selectionDirection=z,this.selectionStart=e),this.selectionEnd=s)}}class th extends Qa{initHiddenTextarea(){const t=this.canvas&&_t(this.canvas.getElement())||pe(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(n=>{let[o,h]=n;return e.setAttribute(o,h)});const{top:s,left:r,fontSize:i}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(r,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(i,";"),(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(n=>{let[o,h]=n;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:r,selectionEnd:i}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const n=()=>{this.updateFromTextArea(),this.fire(_s),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void n();const o=this._splitTextIntoLines(s).graphemeText,h=this._text.length,l=o.length,c=this.selectionStart,u=this.selectionEnd,g=c!==u;let d,f,v,_,x=l-h;const b=this.fromStringToGraphemeSelection(r,i,s),T=c>b.selectionStart;g?(f=this._text.slice(c,u),x+=u-c):l<h&&(f=T?this._text.slice(u+x,u):this._text.slice(c,c-x));const w=o.slice(b.selectionEnd-x,b.selectionEnd);if(f&&f.length&&(w.length&&(d=this.getSelectionStyles(c,c+1,!1),d=w.map(()=>d[0])),g?(v=c,_=u):T?(v=u-f.length,_=u):(v=u,_=u+f.length),this.removeStyleFromTo(v,_)),w.length){const{copyPasteData:C}=Dt();e&&w.join("")===C.copiedText&&!A.disableStyleCopyPaste&&(d=C.copiedTextStyle),this.insertNewStyleBlock(w,c,d)}n()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:r}=e;this.compositionStart=s,this.compositionEnd=r,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=Dt();t.copiedText=this.getSelectedText(),A.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,r=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],r+=s.left+s.width),r}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),r=this.get2DCursorLocation(s),i=r.lineIndex;if(i===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const n=r.charIndex,o=this._getWidthBeforeCursor(i,n),h=this._getIndexOnLine(i+1,o);return this._textLines[i].slice(n).length+h+1+this.missingNewlineOffset(i)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),r=this.get2DCursorLocation(s),i=r.lineIndex;if(i===0||t.metaKey||t.keyCode===33)return-s;const n=r.charIndex,o=this._getWidthBeforeCursor(i,n),h=this._getIndexOnLine(i-1,o),l=this._textLines[i].slice(0,n),c=this.missingNewlineOffset(i-1);return-this._textLines[i-1].length+h-l.length+(1-c)}_getIndexOnLine(t,e){const s=this._textLines[t];let r,i,n=this._getLineLeftOffset(t),o=0;for(let h=0,l=s.length;h<l;h++)if(r=this.__charBounds[t][h].width,n+=r,n>e){i=!0;const c=n-r,u=n,g=Math.abs(c-e);o=Math.abs(u-e)<g?h:h-1;break}return i||(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===z);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const r=this.text.length;this.selectionStart=fe(0,this.selectionStart,r),this.selectionEnd=fe(0,this.selectionEnd,r),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===L?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 r;if(t.altKey)r=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;r=this["findLineBoundary".concat(s)](this[e])}return r!==void 0&&this[e]!==r&&(this[e]=r,!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=L,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===z&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=L,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===L&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=z,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=z,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const mi=a=>!!a.button;class eh extends th{constructor(){super(...arguments),p(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new Za(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&&!mi(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 r=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const i=this.canvas._activeObject;if(i&&i!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||mi(e)||r||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,r=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,r,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(xt(this.calcTransformMatrix())).add(new y(-this._getLeftOffset(),-this._getTopOffset()));let s=0,r=0,i=0;for(let l=0;l<this._textLines.length&&s<=e.y;l++)s+=this.getHeightOfLine(l),i=l,l>0&&(r+=this._textLines[l-1].length+this.missingNewlineOffset(l-1));let n=Math.abs(this._getLineLeftOffset(i));const o=this._textLines[i].length,h=this.__charBounds[i];for(let l=0;l<o;l++){const c=n+h[l].kernedWidth;if(e.x<=c){Math.abs(e.x-c)<=Math.abs(e.x-n)&&r++;break}n=c,r++}return Math.min(this.flipX?o-r:r,this._text.length)}}const Ue="moveCursorUp",qe="moveCursorDown",Ke="moveCursorLeft",Je="moveCursorRight",$e="exitEditing",vi=(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])},sh=m({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:$e,27:$e,33:Ue,34:qe,35:Je,36:Ke,37:Ke,38:Ue,39:Je,40:qe},keysMapRtl:{9:$e,27:$e,33:Ue,34:qe,35:Ke,36:Je,37:Je,38:Ue,39:Ke,40:qe},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class At extends eh{static getDefaults(){return m(m({},super.getDefaults()),At.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,m(m({},At.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 dr&&this.canvas.textEditingManager.remove(this),e instanceof dr&&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(),r=s.length>0;let i,n=t;if(r){i=pt(t.canvas),n=i.getContext("2d"),vi(n,this.canvas);const o=this.calcTransformMatrix();n.transform(o[0],o[1],o[2],o[3],o[4],o[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(n,e):this.renderCursor(n,e),r)for(const o of s){const h=o.clipPath,l=pt(t.canvas),c=l.getContext("2d");if(vi(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(n,h,l)}r&&(t.setTransform(1,0,0,1,0,0),t.drawImage(i,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(),r=this._getTopOffset(),i=this._getCursorBoundariesOffsets(t,e);return{left:s,top:r,leftOffset:i.left,topOffset:i.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:r,lineIndex:i}=this.get2DCursorLocation(t);for(let l=0;l<i;l++)e+=this.getHeightOfLine(l);const n=this._getLineLeftOffset(i),o=this.__charBounds[i][r];o&&(s=o.left),this.charSpacing!==0&&r===this._textLines[i].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:n+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===z||this.textAlign===Tt||this.textAlign===ke?h.left*=-1:this.textAlign===L||this.textAlign===Ts?h.left=n-(s>0?s:0):this.textAlign!==P&&this.textAlign!==Me||(h.left=n-(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),r=s.lineIndex,i=s.charIndex>0?s.charIndex-1:0,n=this.getValueOfPropertyAt(r,i,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,l=this.getValueOfPropertyAt(r,i,"deltaY"),c=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(r)/this.lineHeight-n*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(r,i,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:c+e.top+l,width:h,height:n}}_renderCursor(t,e,s){const{color:r,opacity:i,left:n,top:o,width:h,height:l}=this.getCursorRenderingData(s,e);t.fillStyle=r,t.globalAlpha=i,t.fillRect(n,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 r=e.selectionStart,i=e.selectionEnd,n=this.textAlign.includes(Tt),o=this.get2DCursorLocation(r),h=this.get2DCursorLocation(i),l=o.lineIndex,c=h.lineIndex,u=o.charIndex<0?0:o.charIndex,g=h.charIndex<0?0:h.charIndex;for(let d=l;d<=c;d++){const f=this._getLineLeftOffset(d)||0;let v=this.getHeightOfLine(d),_=0,x=0,b=0;if(d===l&&(x=this.__charBounds[l][u].left),d>=l&&d<c)b=n&&!this.isEndOfWrapping(d)?this.width:this.getLineWidth(d)||5;else if(d===c)if(g===0)b=this.__charBounds[c][g].left;else{const k=this._getWidthOfCharSpacing();b=this.__charBounds[c][g-1].left+this.__charBounds[c][g-1].width-k}_=v,(this.lineHeight<1||d===c&&this.lineHeight>1)&&(v/=this.lineHeight);let T=s.left+f+x,w=v,C=0;const D=b-x;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",w=1,C=v):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===z||this.textAlign===Tt||this.textAlign===ke?T=this.width-T-D:this.textAlign===L||this.textAlign===Ts?T=s.left+f-b:this.textAlign!==P&&this.textAlign!==Me||(T=s.left+f-b)),t.fillRect(T,s.top+s.topOffset+C,D,w),s.topOffset+=_}}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,N)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}p(At,"ownDefaults",sh),p(At,"type","IText"),O.setClass(At),O.setClass(At,"i-text");class Nt extends At{static getDefaults(){return m(m({},super.getDefaults()),Nt.ownDefaults)}constructor(t,e){super(t,m(m({},Nt.ownDefaults),e))}static createControls(){return{controls:Ao()}}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(Tt)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,r=0;const i={};for(let n=0;n<t.graphemeLines.length;n++)t.graphemeText[r]===`
57
+ `&&n>0?(s=0,r++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[r])&&n>0&&(s++,r++),i[n]={line:e,offset:s},r+=t.graphemeLines[n].length,s+=t.graphemeLines[n].length;return i}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,r=t+1,i=!1;const n=this._styleMap[t],o=this._styleMap[t+1];n&&(t=n.line,s=n.offset),o&&(r=o.line,i=r===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const l in h)for(const c in h[l]){const u=parseInt(c,10);if(u>=s&&(!i||u<e))for(const g in h[l][c])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const r=this._styleMap[t];super._setStyleDeclaration(r.line,r.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),r=[];for(let i=0;i<s.wordsData.length;i++)r.push(...this._wrapLine(i,e,s));return this.isWrapping=!1,r}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let r=0;return{wordsData:t.map((i,n)=>{let o=0;const h=e?this.graphemeSplit(i):this.wordSplit(i);return h.length===0?[{word:[],width:0}]:h.map(l=>{const c=e?[l]:this.graphemeSplit(l),u=this._measureWord(c,n,o);return r=Math.max(u,r),o+=c.length+s.length,{word:c,width:u}})}),largestWordWidth:r}}_measureWord(t,e){let s,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,i=0;for(let n=0,o=t.length;n<o;n++)i+=this._getGraphemeBox(t[n],e,n+r,s,!0).kernedWidth,s=t[n];return i}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:r,wordsData:i}=s,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,l=[],c=h?"":" ";let u=0,g=[],d=0,f=0,v=!0;e-=n;const _=Math.max(e,r,this.dynamicMinWidth),x=i[t];let b;for(d=0,b=0;b<x.length;b++){const{word:T,width:w}=x[b];d+=T.length,u+=f+w-o,u>_&&!v?(l.push(g),g=[],u=w,v=!0):u+=o,v||h||g.push(c),g=g.concat(T),f=h?0:this._measureWord([c],t,d),d++,v=!1}return b&&l.push(g),r+n>this.dynamicMinWidth&&(this.dynamicMinWidth=r-o+n),l}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),r=new Array(s.length);for(let i=0;i<s.length;i++)r[i]=s[i].join("");return e.lines=r,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const r=this._styleMap[e].line;t.set("".concat(r),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}p(Nt,"type","Textbox"),p(Nt,"textLayoutProperties",[...At.textLayoutProperties,"width"]),p(Nt,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),O.setClass(Nt);class yi extends Bs{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:r,group:i}=s;if(!r||!this.shouldPerformLayout(t))return;const{width:n,height:o}=Ft(nn(s,r)),h=new y(n,o);if(r.absolutePositioned)return{center:ue(r.getRelativeCenterPoint(),void 0,i?i.calcTransformMatrix():void 0),size:h};{const l=r.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:c=new y,correction:u=new y}=this.calcBoundingBox(e,t)||{};return{center:c.add(l),correction:u.subtract(l),size:h}}return{center:s.getRelativeCenterPoint().add(l),size:h}}}}p(yi,"type","clip-path"),O.setClass(yi);class _i extends Bs{getInitialSize(t,e){let{target:s}=t,{size:r}=e;return new y(s.width||r.x,s.height||r.y)}}p(_i,"type","fixed"),O.setClass(_i);class rh extends Re{subscribeTargets(t){const e=t.target;t.targets.reduce((s,r)=>(r.parent&&s.add(r.parent),s),new Set).forEach(s=>{s.layoutManager.subscribeTargets({target:s,targets:[e]})})}unsubscribeTargets(t){const e=t.target,s=e.getObjects();t.targets.reduce((r,i)=>(i.parent&&r.add(i.parent),r),new Set).forEach(r=>{!s.some(i=>i.parent===r)&&r.layoutManager.unsubscribeTargets({target:r,targets:[e]})})}}class se extends Ut{static getDefaults(){return m(m({},super.getDefaults()),se.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,se.ownDefaults),this.setOptions(e);const{left:s,top:r,layoutManager:i}=e;this.groupInit(t,{left:s,top:r,layoutManager:i??new rh})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(r=>{const i=this._objects.findIndex(o=>o.isInFrontOf(r)),n=i===-1?this.size():i;this.insertAt(n,r)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(qt("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const s=new Set;e.forEach(r=>{const{parent:i}=r;i&&s.add(i)}),t===jr?s.forEach(r=>{r._onAfterObjectsChange(Os,e)}):s.forEach(r=>{r._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const r=m(m({hasControls:!1},s),{},{forActiveSelection:!0});for(let i=0;i<this._objects.length;i++)this._objects[i]._renderControls(t,r);super._renderControls(t,e),t.restore()}}p(se,"type","ActiveSelection"),p(se,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),O.setClass(se),O.setClass(se,"activeSelection");class ih{constructor(){p(this,"resources",{})}applyFilters(t,e,s,r,i){const n=i.getContext("2d");if(!n)return;n.drawImage(e,0,0,s,r);const o={sourceWidth:s,sourceHeight:r,imageData:n.getImageData(0,0,s,r),originalEl:e,originalImageData:n.getImageData(0,0,s,r),canvasEl:i,ctx:n,filterBackend:this};t.forEach(l=>{l.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===r||(i.width=h.width,i.height=h.height),n.putImageData(h,0,0),o}}class Cn{constructor(){let{tileSize:t=A.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};p(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),p(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=pt({width:t,height:e}),r=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});r&&(r.clearColor(0,0,0,0),this.canvas=s,this.gl=r)}applyFilters(t,e,s,r,i,n){const o=this.gl,h=i.getContext("2d");if(!o||!h)return;let l;n&&(l=this.getCachedTexture(n,e));const c={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:r,destinationWidth:s,destinationHeight:r,context:o,sourceTexture:this.createTexture(o,s,r,l?void 0:e),targetTexture:this.createTexture(o,s,r),originalTexture:l||this.createTexture(o,s,r,l?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:i},u=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,u),t.forEach(g=>{g&&g.applyTo(c)}),function(g){const d=g.targetCanvas,f=d.width,v=d.height,_=g.destinationWidth,x=g.destinationHeight;f===_&&v===x||(d.width=_,d.height=x)}(c),this.copyGLTo2D(o,c),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(c.sourceTexture),o.deleteTexture(c.targetTexture),o.deleteFramebuffer(u),h.setTransform(1,0,0,1,0,0),c}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,r,i){const{NEAREST:n,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:l,CLAMP_TO_EDGE:c,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:g,TEXTURE_WRAP_S:d,TEXTURE_WRAP_T:f}=t,v=t.createTexture();return t.bindTexture(o,v),t.texParameteri(o,u,i||n),t.texParameteri(o,g,i||n),t.texParameteri(o,d,c),t.texParameteri(o,f,c),r?t.texImage2D(o,0,h,h,l,r):t.texImage2D(o,0,h,e,s,0,h,l,null),v}getCachedTexture(t,e,s){const{textureCache:r}=this;if(r[t])return r[t];{const i=this.createTexture(this.gl,e.width,e.height,e,s);return i&&(r[t]=i),i}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,r=e.targetCanvas,i=r.getContext("2d");if(!i)return;i.translate(0,r.height),i.scale(1,-1);const n=s.height-r.height;i.drawImage(s,0,n,r.width,r.height,0,0,r.width,r.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),r=e.destinationWidth,i=e.destinationHeight,n=r*i*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,n),h=new Uint8ClampedArray(this.imageBuffer,0,n);t.readPixels(0,0,r,i,t.RGBA,t.UNSIGNED_BYTE,o);const l=new ImageData(h,r,i);s.putImageData(l,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const r=t.getParameter(s.UNMASKED_RENDERER_WEBGL),i=t.getParameter(s.UNMASKED_VENDOR_WEBGL);r&&(e.renderer=r.toLowerCase()),i&&(e.vendor=i.toLowerCase())}return this.gpuInfo=e,e}}let Zs;function nh(){const{WebGLProbe:a}=Dt();return a.queryWebGL(It()),A.enableGLFiltering&&a.isSupported(A.textureSize)?new Cn({tileSize:A.textureSize}):new ih}function Qs(){return!Zs&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Zs=nh()),Zs}const oh=["filters","resizeFilter","src","crossOrigin","type"],bn=["cropX","cropY"];class gt extends Z{static getDefaults(){return m(m({},super.getDefaults()),gt.ownDefaults)}constructor(t,e){super(),p(this,"_lastScaleX",1),p(this,"_lastScaleY",1),p(this,"_filterScalingX",1),p(this,"_filterScalingY",1),this.filters=[],Object.assign(this,gt.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(Kt()),this.setElement(typeof t=="string"?(this.canvas&&_t(this.canvas.getElement())||pe()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(gt.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Qs(!1);e instanceof Cn&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&Dt().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),m(m({},super.toObject([...bn,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,r=-this.height/2;let i=[],n=[],o="",h="";if(!e)return[];if(this.hasCrop()){const l=Kt();i.push('<clipPath id="imageCrop_'+l+`">
58
+ `,' <rect x="'+s+'" y="'+r+'" width="'+this.width+'" height="'+this.height+`" />
59
+ `,`</clipPath>
60
+ `),o=' clip-path="url(#imageCrop_'+l+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(r-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(o,`></image>
61
+ `)),this.stroke||this.strokeDashArray){const l=this.fill;this.fill=null,n=[' <rect x="'.concat(s,'" y="').concat(r,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
62
+ `)],this.fill=l}return i=this.paintFirst!==N?i.concat(n,t):i.concat(t,n),i}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return ms(t,{crossOrigin:e,signal:s}).then(r=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(r)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),r=s.x,i=s.y,n=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||r>e&&i>e)return this._element=n,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=r,void(this._lastScaleY=i);const o=pt(n),{width:h,height:l}=n;this._element=o,this._lastScaleX=t.scaleX=r,this._lastScaleY=t.scaleY=i,Qs().applyFilters([t],n,h,l,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(i=>i&&!i.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,r=e.naturalHeight||e.height;if(this._element===this._originalElement){const i=pt({width:s,height:r});this._element=i,this._filteredEl=i}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,r),this._lastScaleX=1,this._lastScaleY=1);Qs().applyFilters(t,this._originalElement,s,r,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,r=this._filterScalingY,i=this.width,n=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),l=e.naturalWidth||e.width,c=e.naturalHeight||e.height,u=o*s,g=h*r,d=Math.min(i*s,l-u),f=Math.min(n*r,c-g),v=-i/2,_=-n/2,x=Math.min(i,l/s-o),b=Math.min(n,c/r-h);e&&t.drawImage(e,u,g,d,f,v,_,x,b)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=Jn(this.preserveAspectRatio||""),e=this.width,s=this.height,r={width:e,height:s};let i,n=this._element.width,o=this._element.height,h=1,l=1,c=0,u=0,g=0,d=0;return!t||t.alignX===nt&&t.alignY===nt?(h=e/n,l=s/o):(t.meetOrSlice==="meet"&&(h=l=da(this._element,r),i=(e-n*h)/2,t.alignX==="Min"&&(c=-i),t.alignX==="Max"&&(c=i),i=(s-o*l)/2,t.alignY==="Min"&&(u=-i),t.alignY==="Max"&&(u=i)),t.meetOrSlice==="slice"&&(h=l=fa(this._element,r),i=n-e/h,t.alignX==="Mid"&&(g=i/2),t.alignX==="Max"&&(g=i),i=o-s/l,t.alignY==="Mid"&&(d=i/2),t.alignY==="Max"&&(d=i),n=e/h,o=s/l)),{width:n,height:o,scaleX:h,scaleY:l,offsetLeft:c,offsetTop:u,cropX:g,cropY:d}}static fromObject(t,e){let{filters:s,resizeFilter:r,src:i,crossOrigin:n,type:o}=t,h=Y(t,oh);return Promise.all([ms(i,m(m({},e),{},{crossOrigin:n})),s&&je(s,e),r&&je([r],e),As(h,e)]).then(l=>{let[c,u=[],[g]=[],d={}]=l;return new this(c,m(m({},h),{},{src:i,filters:u,resizeFilter:g},d))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;return ms(t,{crossOrigin:e,signal:s}).then(i=>new this(i,r))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const r=Yt(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(r["xlink:href"]||r.href,e,r).catch(i=>(qt("log","Unable to parse Image",i),null))}}p(gt,"type","Image"),p(gt,"cacheProperties",[...Wt,...bn]),p(gt,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),p(gt,"CSS_CANVAS","canvas-img"),p(gt,"ATTRIBUTE_NAMES",[...Jt,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),O.setClass(gt),O.setSVGClass(gt);Ls(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const Xs=a=>a.webgl!==void 0,Ar="precision highp float",ah=`
63
+ `.concat(Ar,`;
64
+ varying vec2 vTexCoord;
65
+ uniform sampler2D uTexture;
66
+ void main() {
67
+ gl_FragColor = texture2D(uTexture, vTexCoord);
68
+ }`),hh=["type"],lh=["type"],ch=new RegExp(Ar,"g");class U{get type(){return this.constructor.type}constructor(){let t=Y(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},hh);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return ah}getVertexSource(){return`
69
+ attribute vec2 aPosition;
70
+ varying vec2 vTexCoord;
71
+ void main() {
72
+ vTexCoord = aPosition;
73
+ gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
74
+ }`}createProgram(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.getFragmentSource(),s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:r="highp"}}=Dt();r!=="highp"&&(e=e.replace(ch,Ar.replace("highp",r)));const i=t.createShader(t.VERTEX_SHADER),n=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!i||!n||!o)throw new Ot("Vertex, fragment shader or program creation error");if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Ot("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(i)));if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Ot("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.attachShader(o,i),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Ot('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const h=this.getUniformLocations(t,o)||{};return h.uStepW=t.getUniformLocation(o,"uStepW"),h.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:h}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,r={};for(let i=0;i<s.length;i++)r[s[i]]=t.getUniformLocation(e,s[i]);return r}sendAttributeData(t,e,s){const r=e.aPosition,i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,r=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===r||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,r)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){Xs(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:s}=t,r=pt({width:e,height:s});t.helpLayer=r}}toObject(){const t=Object.keys(this.constructor.defaults||{});return m({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Y(t,lh))}}p(U,"type","BaseFilter"),p(U,"uniformLocations",[]);const uh={multiply:`gl_FragColor.rgb *= uColor.rgb;
75
+ `,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
76
+ `,add:`gl_FragColor.rgb += uColor.rgb;
77
+ `,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
78
+ `,subtract:`gl_FragColor.rgb -= uColor.rgb;
79
+ `,lighten:`gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);
80
+ `,darken:`gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);
81
+ `,exclusion:`gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);
82
+ `,overlay:`
83
+ if (uColor.r < 0.5) {
84
+ gl_FragColor.r *= 2.0 * uColor.r;
85
+ } else {
86
+ gl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);
87
+ }
88
+ if (uColor.g < 0.5) {
89
+ gl_FragColor.g *= 2.0 * uColor.g;
90
+ } else {
91
+ gl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);
92
+ }
93
+ if (uColor.b < 0.5) {
94
+ gl_FragColor.b *= 2.0 * uColor.b;
95
+ } else {
96
+ gl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);
97
+ }
98
+ `,tint:`
99
+ gl_FragColor.rgb *= (1.0 - uColor.a);
100
+ gl_FragColor.rgb += uColor.rgb;
101
+ `};class Ze extends U{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
102
+ precision highp float;
103
+ uniform sampler2D uTexture;
104
+ uniform vec4 uColor;
105
+ varying vec2 vTexCoord;
106
+ void main() {
107
+ vec4 color = texture2D(uTexture, vTexCoord);
108
+ gl_FragColor = color;
109
+ if (color.a > 0.0) {
110
+ `.concat(uh[this.mode],`
111
+ }
112
+ }
113
+ `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new B(this.color).getSource(),r=this.alpha,i=s[0]*r,n=s[1]*r,o=s[2]*r,h=1-r;for(let l=0;l<e.length;l+=4){const c=e[l],u=e[l+1],g=e[l+2];let d,f,v;switch(this.mode){case"multiply":d=c*i/255,f=u*n/255,v=g*o/255;break;case"screen":d=255-(255-c)*(255-i)/255,f=255-(255-u)*(255-n)/255,v=255-(255-g)*(255-o)/255;break;case"add":d=c+i,f=u+n,v=g+o;break;case"difference":d=Math.abs(c-i),f=Math.abs(u-n),v=Math.abs(g-o);break;case"subtract":d=c-i,f=u-n,v=g-o;break;case"darken":d=Math.min(c,i),f=Math.min(u,n),v=Math.min(g,o);break;case"lighten":d=Math.max(c,i),f=Math.max(u,n),v=Math.max(g,o);break;case"overlay":d=i<128?2*c*i/255:255-2*(255-c)*(255-i)/255,f=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,v=o<128?2*g*o/255:255-2*(255-g)*(255-o)/255;break;case"exclusion":d=i+c-2*i*c/255,f=n+u-2*n*u/255,v=o+g-2*o*g/255;break;case"tint":d=i+c*h,f=n+u*h,v=o+g*h}e[l]=d,e[l+1]=f,e[l+2]=v}}sendUniformData(t,e){const s=new B(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}p(Ze,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),p(Ze,"type","BlendColor"),p(Ze,"uniformLocations",["uColor"]),O.setClass(Ze);const gh={multiply:`
114
+ precision highp float;
115
+ uniform sampler2D uTexture;
116
+ uniform sampler2D uImage;
117
+ uniform vec4 uColor;
118
+ varying vec2 vTexCoord;
119
+ varying vec2 vTexCoord2;
120
+ void main() {
121
+ vec4 color = texture2D(uTexture, vTexCoord);
122
+ vec4 color2 = texture2D(uImage, vTexCoord2);
123
+ color.rgba *= color2.rgba;
124
+ gl_FragColor = color;
125
+ }
126
+ `,mask:`
127
+ precision highp float;
128
+ uniform sampler2D uTexture;
129
+ uniform sampler2D uImage;
130
+ uniform vec4 uColor;
131
+ varying vec2 vTexCoord;
132
+ varying vec2 vTexCoord2;
133
+ void main() {
134
+ vec4 color = texture2D(uTexture, vTexCoord);
135
+ vec4 color2 = texture2D(uImage, vTexCoord2);
136
+ color.a = color2.a;
137
+ gl_FragColor = color;
138
+ }
139
+ `},dh=["type","image"];class Qe extends U{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return gh[this.mode]}getVertexSource(){return`
140
+ attribute vec2 aPosition;
141
+ varying vec2 vTexCoord;
142
+ varying vec2 vTexCoord2;
143
+ uniform mat3 uTransformMatrix;
144
+ void main() {
145
+ vTexCoord = aPosition;
146
+ vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
147
+ gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
148
+ }
149
+ `}applyToWebGL(t){const e=t.context,s=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,s,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:s}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/s,1]}applyTo2d(t){let{imageData:{data:e,width:s,height:r},filterBackend:{resources:i}}=t;const n=this.image;i.blendImage||(i.blendImage=It());const o=i.blendImage,h=o.getContext("2d");o.width!==s||o.height!==r?(o.width=s,o.height=r):h.clearRect(0,0,s,r),h.setTransform(n.scaleX,0,0,n.scaleY,n.left,n.top),h.drawImage(n.getElement(),0,0,s,r);const l=h.getImageData(0,0,s,r).data;for(let c=0;c<e.length;c+=4){const u=e[c],g=e[c+1],d=e[c+2],f=e[c+3],v=l[c],_=l[c+1],x=l[c+2],b=l[c+3];switch(this.mode){case"multiply":e[c]=u*v/255,e[c+1]=g*_/255,e[c+2]=d*x/255,e[c+3]=f*b/255;break;case"mask":e[c+3]=b}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return m(m({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:r}=t,i=Y(t,dh);return gt.fromObject(r,e).then(n=>new this(m(m({},i),{},{image:n})))}}p(Qe,"type","BlendImage"),p(Qe,"defaults",{mode:"multiply",alpha:1}),p(Qe,"uniformLocations",["uTransformMatrix","uImage"]),O.setClass(Qe);class ts extends U{getFragmentSource(){return`
150
+ precision highp float;
151
+ uniform sampler2D uTexture;
152
+ uniform vec2 uDelta;
153
+ varying vec2 vTexCoord;
154
+ const float nSamples = 15.0;
155
+ vec3 v3offset = vec3(12.9898, 78.233, 151.7182);
156
+ float random(vec3 scale) {
157
+ /* use the fragment position for a different seed per-pixel */
158
+ return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);
159
+ }
160
+ void main() {
161
+ vec4 color = vec4(0.0);
162
+ float totalC = 0.0;
163
+ float totalA = 0.0;
164
+ float offset = random(v3offset);
165
+ for (float t = -nSamples; t <= nSamples; t++) {
166
+ float percent = (t + offset - 0.5) / nSamples;
167
+ vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);
168
+ float weight = 1.0 - abs(percent);
169
+ float alpha = weight * sample.a;
170
+ color.rgb += sample.rgb * alpha;
171
+ color.a += alpha;
172
+ totalA += weight;
173
+ totalC += alpha;
174
+ }
175
+ gl_FragColor.rgb = color.rgb / totalC;
176
+ gl_FragColor.a = color.a / totalA;
177
+ }
178
+ `}applyTo(t){Xs(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){let{imageData:{data:e,width:s,height:r}}=t;this.aspectRatio=s/r,this.horizontal=!0;let i=this.getBlurValue()*s;const n=new Uint8ClampedArray(e),o=15,h=4*s;for(let l=0;l<e.length;l+=4){let c=0,u=0,g=0,d=0,f=0;const v=l-l%h,_=v+h;for(let x=-14;x<o;x++){const b=x/o,T=4*Math.floor(i*b),w=1-Math.abs(b);let C=l+T;C<v?C=v:C>_&&(C=_);const D=e[C+3]*w;c+=e[C]*D,u+=e[C+1]*D,g+=e[C+2]*D,d+=D,f+=w}n[l]=c/d,n[l+1]=u/d,n[l+2]=g/d,n[l+3]=d/f}this.horizontal=!1,i=this.getBlurValue()*r;for(let l=0;l<n.length;l+=4){let c=0,u=0,g=0,d=0,f=0;const v=l%h,_=n.length-h+v;for(let x=-14;x<o;x++){const b=x/o,T=Math.floor(i*b)*h,w=1-Math.abs(b);let C=l+T;C<v?C=v:C>_&&(C=_);const D=n[C+3]*w;c+=n[C]*D,u+=n[C+1]*D,g+=n[C+2]*D,d+=D,f+=w}e[l]=c/d,e[l+1]=u/d,e[l+2]=g/d,e[l+3]=d/f}}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:s}=this;return e?s>1&&(t=1/s):s<1&&(t=s),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}p(ts,"type","Blur"),p(ts,"defaults",{blur:0}),p(ts,"uniformLocations",["uDelta"]),O.setClass(ts);class es extends U{getFragmentSource(){return`
179
+ precision highp float;
180
+ uniform sampler2D uTexture;
181
+ uniform float uBrightness;
182
+ varying vec2 vTexCoord;
183
+ void main() {
184
+ vec4 color = texture2D(uTexture, vTexCoord);
185
+ color.rgb += uBrightness;
186
+ gl_FragColor = color;
187
+ }
188
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let r=0;r<e.length;r+=4)e[r]+=s,e[r+1]+=s,e[r+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}p(es,"type","Brightness"),p(es,"defaults",{brightness:0}),p(es,"uniformLocations",["uBrightness"]),O.setClass(es);const Sn={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class ce extends U{getFragmentSource(){return`
189
+ precision highp float;
190
+ uniform sampler2D uTexture;
191
+ varying vec2 vTexCoord;
192
+ uniform mat4 uColorMatrix;
193
+ uniform vec4 uConstants;
194
+ void main() {
195
+ vec4 color = texture2D(uTexture, vTexCoord);
196
+ color *= uColorMatrix;
197
+ color += uConstants;
198
+ gl_FragColor = color;
199
+ }`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,r=this.colorsOnly;for(let i=0;i<e.length;i+=4){const n=e[i],o=e[i+1],h=e[i+2];if(e[i]=n*s[0]+o*s[1]+h*s[2]+255*s[4],e[i+1]=n*s[5]+o*s[6]+h*s[7]+255*s[9],e[i+2]=n*s[10]+o*s[11]+h*s[12]+255*s[14],!r){const l=e[i+3];e[i]+=l*s[3],e[i+1]+=l*s[8],e[i+2]+=l*s[13],e[i+3]=n*s[15]+o*s[16]+h*s[17]+l*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,r=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],i=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,r),t.uniform4fv(e.uConstants,i)}toObject(){return m(m({},super.toObject()),{},{matrix:[...this.matrix]})}}function ie(a,t){var e;const s=(p(e=class extends ce{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),p(e,"defaults",{colorsOnly:!1,matrix:t}),e);return O.setClass(s,a),s}p(ce,"type","ColorMatrix"),p(ce,"defaults",Sn),p(ce,"uniformLocations",["uColorMatrix","uConstants"]),O.setClass(ce);ie("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]);ie("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]);ie("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]);ie("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]);ie("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]);ie("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]);ie("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class xi extends U{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Xs(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>O.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}p(xi,"type","Composed"),O.setClass(xi);class ss extends U{getFragmentSource(){return`
200
+ precision highp float;
201
+ uniform sampler2D uTexture;
202
+ uniform float uContrast;
203
+ varying vec2 vTexCoord;
204
+ void main() {
205
+ vec4 color = texture2D(uTexture, vTexCoord);
206
+ float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
207
+ color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
208
+ gl_FragColor = color;
209
+ }`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),r=259*(s+255)/(255*(259-s));for(let i=0;i<e.length;i+=4)e[i]=r*(e[i]-128)+128,e[i+1]=r*(e[i+1]-128)+128,e[i+2]=r*(e[i+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}p(ss,"type","Contrast"),p(ss,"defaults",{contrast:0}),p(ss,"uniformLocations",["uContrast"]),O.setClass(ss);const fh={Convolute_3_1:`
210
+ precision highp float;
211
+ uniform sampler2D uTexture;
212
+ uniform float uMatrix[9];
213
+ uniform float uStepW;
214
+ uniform float uStepH;
215
+ varying vec2 vTexCoord;
216
+ void main() {
217
+ vec4 color = vec4(0, 0, 0, 0);
218
+ for (float h = 0.0; h < 3.0; h+=1.0) {
219
+ for (float w = 0.0; w < 3.0; w+=1.0) {
220
+ vec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));
221
+ color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];
222
+ }
223
+ }
224
+ gl_FragColor = color;
225
+ }
226
+ `,Convolute_3_0:`
227
+ precision highp float;
228
+ uniform sampler2D uTexture;
229
+ uniform float uMatrix[9];
230
+ uniform float uStepW;
231
+ uniform float uStepH;
232
+ varying vec2 vTexCoord;
233
+ void main() {
234
+ vec4 color = vec4(0, 0, 0, 1);
235
+ for (float h = 0.0; h < 3.0; h+=1.0) {
236
+ for (float w = 0.0; w < 3.0; w+=1.0) {
237
+ vec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));
238
+ color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];
239
+ }
240
+ }
241
+ float alpha = texture2D(uTexture, vTexCoord).a;
242
+ gl_FragColor = color;
243
+ gl_FragColor.a = alpha;
244
+ }
245
+ `,Convolute_5_1:`
246
+ precision highp float;
247
+ uniform sampler2D uTexture;
248
+ uniform float uMatrix[25];
249
+ uniform float uStepW;
250
+ uniform float uStepH;
251
+ varying vec2 vTexCoord;
252
+ void main() {
253
+ vec4 color = vec4(0, 0, 0, 0);
254
+ for (float h = 0.0; h < 5.0; h+=1.0) {
255
+ for (float w = 0.0; w < 5.0; w+=1.0) {
256
+ vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));
257
+ color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];
258
+ }
259
+ }
260
+ gl_FragColor = color;
261
+ }
262
+ `,Convolute_5_0:`
263
+ precision highp float;
264
+ uniform sampler2D uTexture;
265
+ uniform float uMatrix[25];
266
+ uniform float uStepW;
267
+ uniform float uStepH;
268
+ varying vec2 vTexCoord;
269
+ void main() {
270
+ vec4 color = vec4(0, 0, 0, 1);
271
+ for (float h = 0.0; h < 5.0; h+=1.0) {
272
+ for (float w = 0.0; w < 5.0; w+=1.0) {
273
+ vec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));
274
+ color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];
275
+ }
276
+ }
277
+ float alpha = texture2D(uTexture, vTexCoord).a;
278
+ gl_FragColor = color;
279
+ gl_FragColor.a = alpha;
280
+ }
281
+ `,Convolute_7_1:`
282
+ precision highp float;
283
+ uniform sampler2D uTexture;
284
+ uniform float uMatrix[49];
285
+ uniform float uStepW;
286
+ uniform float uStepH;
287
+ varying vec2 vTexCoord;
288
+ void main() {
289
+ vec4 color = vec4(0, 0, 0, 0);
290
+ for (float h = 0.0; h < 7.0; h+=1.0) {
291
+ for (float w = 0.0; w < 7.0; w+=1.0) {
292
+ vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));
293
+ color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];
294
+ }
295
+ }
296
+ gl_FragColor = color;
297
+ }
298
+ `,Convolute_7_0:`
299
+ precision highp float;
300
+ uniform sampler2D uTexture;
301
+ uniform float uMatrix[49];
302
+ uniform float uStepW;
303
+ uniform float uStepH;
304
+ varying vec2 vTexCoord;
305
+ void main() {
306
+ vec4 color = vec4(0, 0, 0, 1);
307
+ for (float h = 0.0; h < 7.0; h+=1.0) {
308
+ for (float w = 0.0; w < 7.0; w+=1.0) {
309
+ vec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));
310
+ color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];
311
+ }
312
+ }
313
+ float alpha = texture2D(uTexture, vTexCoord).a;
314
+ gl_FragColor = color;
315
+ gl_FragColor.a = alpha;
316
+ }
317
+ `,Convolute_9_1:`
318
+ precision highp float;
319
+ uniform sampler2D uTexture;
320
+ uniform float uMatrix[81];
321
+ uniform float uStepW;
322
+ uniform float uStepH;
323
+ varying vec2 vTexCoord;
324
+ void main() {
325
+ vec4 color = vec4(0, 0, 0, 0);
326
+ for (float h = 0.0; h < 9.0; h+=1.0) {
327
+ for (float w = 0.0; w < 9.0; w+=1.0) {
328
+ vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));
329
+ color += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];
330
+ }
331
+ }
332
+ gl_FragColor = color;
333
+ }
334
+ `,Convolute_9_0:`
335
+ precision highp float;
336
+ uniform sampler2D uTexture;
337
+ uniform float uMatrix[81];
338
+ uniform float uStepW;
339
+ uniform float uStepH;
340
+ varying vec2 vTexCoord;
341
+ void main() {
342
+ vec4 color = vec4(0, 0, 0, 1);
343
+ for (float h = 0.0; h < 9.0; h+=1.0) {
344
+ for (float w = 0.0; w < 9.0; w+=1.0) {
345
+ vec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));
346
+ color.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];
347
+ }
348
+ }
349
+ float alpha = texture2D(uTexture, vTexCoord).a;
350
+ gl_FragColor = color;
351
+ gl_FragColor.a = alpha;
352
+ }
353
+ `};class rs extends U{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return fh[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,r=this.matrix,i=Math.round(Math.sqrt(r.length)),n=Math.floor(i/2),o=e.width,h=e.height,l=t.ctx.createImageData(o,h),c=l.data,u=this.opaque?1:0;let g,d,f,v,_,x,b,T,w,C,D,k,S;for(D=0;D<h;D++)for(C=0;C<o;C++){for(_=4*(D*o+C),g=0,d=0,f=0,v=0,S=0;S<i;S++)for(k=0;k<i;k++)b=D+S-n,x=C+k-n,b<0||b>=h||x<0||x>=o||(T=4*(b*o+x),w=r[S*i+k],g+=s[T]*w,d+=s[T+1]*w,f+=s[T+2]*w,u||(v+=s[T+3]*w));c[_]=g,c[_+1]=d,c[_+2]=f,c[_+3]=u?s[_+3]:v}t.imageData=l}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return m(m({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}p(rs,"type","Convolute"),p(rs,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),p(rs,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),O.setClass(rs);const wn="Gamma";class is extends U{getFragmentSource(){return`
354
+ precision highp float;
355
+ uniform sampler2D uTexture;
356
+ uniform vec3 uGamma;
357
+ varying vec2 vTexCoord;
358
+ void main() {
359
+ vec4 color = texture2D(uTexture, vTexCoord);
360
+ vec3 correction = (1.0 / uGamma);
361
+ color.r = pow(color.r, correction.r);
362
+ color.g = pow(color.g, correction.g);
363
+ color.b = pow(color.b, correction.b);
364
+ gl_FragColor = color;
365
+ gl_FragColor.rgb *= color.a;
366
+ }
367
+ `}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,r=1/s[0],i=1/s[1],n=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,r),o.g[h]=255*Math.pow(h/255,i),o.b[h]=255*Math.pow(h/255,n);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:wn,gamma:this.gamma.concat()}}}p(is,"type",wn),p(is,"defaults",{gamma:[1,1,1]}),p(is,"uniformLocations",["uGamma"]),O.setClass(is);const ph={average:`
368
+ precision highp float;
369
+ uniform sampler2D uTexture;
370
+ varying vec2 vTexCoord;
371
+ void main() {
372
+ vec4 color = texture2D(uTexture, vTexCoord);
373
+ float average = (color.r + color.b + color.g) / 3.0;
374
+ gl_FragColor = vec4(average, average, average, color.a);
375
+ }
376
+ `,lightness:`
377
+ precision highp float;
378
+ uniform sampler2D uTexture;
379
+ uniform int uMode;
380
+ varying vec2 vTexCoord;
381
+ void main() {
382
+ vec4 col = texture2D(uTexture, vTexCoord);
383
+ float average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;
384
+ gl_FragColor = vec4(average, average, average, col.a);
385
+ }
386
+ `,luminosity:`
387
+ precision highp float;
388
+ uniform sampler2D uTexture;
389
+ uniform int uMode;
390
+ varying vec2 vTexCoord;
391
+ void main() {
392
+ vec4 col = texture2D(uTexture, vTexCoord);
393
+ float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
394
+ gl_FragColor = vec4(average, average, average, col.a);
395
+ }
396
+ `};class ns extends U{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,r=0;r<e.length;r+=4){const i=e[r],n=e[r+1],o=e[r+2];switch(this.mode){case"average":s=(i+n+o)/3;break;case"lightness":s=(Math.min(i,n,o)+Math.max(i,n,o))/2;break;case"luminosity":s=.21*i+.72*n+.07*o}e[r+2]=e[r+1]=e[r]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return ph[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}p(ns,"type","Grayscale"),p(ns,"defaults",{mode:"average"}),p(ns,"uniformLocations",["uMode"]),O.setClass(ns);const mh=m(m({},Sn),{},{rotation:0});class tr extends ce{calculateMatrix(){const t=this.rotation*Math.PI,e=Rt(t),s=Bt(t),r=1/3,i=Math.sqrt(r)*s,n=1-e;this.matrix=[e+n/3,r*n-i,r*n+i,0,0,r*n+i,e+r*n,r*n-i,0,0,r*n-i,r*n+i,e+r*n,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}p(tr,"type","HueRotation"),p(tr,"defaults",mh),O.setClass(tr);class os extends U{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
397
+ precision highp float;
398
+ uniform sampler2D uTexture;
399
+ uniform int uInvert;
400
+ uniform int uAlpha;
401
+ varying vec2 vTexCoord;
402
+ void main() {
403
+ vec4 color = texture2D(uTexture, vTexCoord);
404
+ if (uInvert == 1) {
405
+ if (uAlpha == 1) {
406
+ gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,1.0 -color.a);
407
+ } else {
408
+ gl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);
409
+ }
410
+ } else {
411
+ gl_FragColor = color;
412
+ }
413
+ }
414
+ `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}p(os,"type","Invert"),p(os,"defaults",{alpha:!1,invert:!0}),p(os,"uniformLocations",["uInvert","uAlpha"]),O.setClass(os);class as extends U{getFragmentSource(){return`
415
+ precision highp float;
416
+ uniform sampler2D uTexture;
417
+ uniform float uStepH;
418
+ uniform float uNoise;
419
+ uniform float uSeed;
420
+ varying vec2 vTexCoord;
421
+ float rand(vec2 co, float seed, float vScale) {
422
+ return fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);
423
+ }
424
+ void main() {
425
+ vec4 color = texture2D(uTexture, vTexCoord);
426
+ color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
427
+ gl_FragColor = color;
428
+ }
429
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let r=0;r<e.length;r+=4){const i=(.5-Math.random())*s;e[r]+=i,e[r+1]+=i,e[r+2]+=i}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}p(as,"type","Noise"),p(as,"defaults",{noise:0}),p(as,"uniformLocations",["uNoise","uSeed"]),O.setClass(as);class hs extends U{applyTo2d(t){let{imageData:{data:e,width:s,height:r}}=t;for(let i=0;i<r;i+=this.blocksize)for(let n=0;n<s;n+=this.blocksize){const o=4*i*s+4*n,h=e[o],l=e[o+1],c=e[o+2],u=e[o+3];for(let g=i;g<Math.min(i+this.blocksize,r);g++)for(let d=n;d<Math.min(n+this.blocksize,s);d++){const f=4*g*s+4*d;e[f]=h,e[f+1]=l,e[f+2]=c,e[f+3]=u}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
430
+ precision highp float;
431
+ uniform sampler2D uTexture;
432
+ uniform float uBlocksize;
433
+ uniform float uStepW;
434
+ uniform float uStepH;
435
+ varying vec2 vTexCoord;
436
+ void main() {
437
+ float blockW = uBlocksize * uStepW;
438
+ float blockH = uBlocksize * uStepH;
439
+ int posX = int(vTexCoord.x / blockW);
440
+ int posY = int(vTexCoord.y / blockH);
441
+ float fposX = float(posX);
442
+ float fposY = float(posY);
443
+ vec2 squareCoords = vec2(fposX * blockW, fposY * blockH);
444
+ vec4 color = texture2D(uTexture, squareCoords);
445
+ gl_FragColor = color;
446
+ }
447
+ `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}p(hs,"type","Pixelate"),p(hs,"defaults",{blocksize:4}),p(hs,"uniformLocations",["uBlocksize"]),O.setClass(hs);class ls extends U{getFragmentSource(){return`
448
+ precision highp float;
449
+ uniform sampler2D uTexture;
450
+ uniform vec4 uLow;
451
+ uniform vec4 uHigh;
452
+ varying vec2 vTexCoord;
453
+ void main() {
454
+ gl_FragColor = texture2D(uTexture, vTexCoord);
455
+ if(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {
456
+ gl_FragColor.a = 0.0;
457
+ }
458
+ }
459
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,r=new B(this.color).getSource(),i=[r[0]-s,r[1]-s,r[2]-s],n=[r[0]+s,r[1]+s,r[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],l=e[o+1],c=e[o+2];h>i[0]&&l>i[1]&&c>i[2]&&h<n[0]&&l<n[1]&&c<n[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new B(this.color).getSource(),r=this.distance,i=[0+s[0]/255-r,0+s[1]/255-r,0+s[2]/255-r,1],n=[s[0]/255+r,s[1]/255+r,s[2]/255+r,1];t.uniform4fv(e.uLow,i),t.uniform4fv(e.uHigh,n)}}p(ls,"type","RemoveColor"),p(ls,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),p(ls,"uniformLocations",["uLow","uHigh"]),O.setClass(ls);class cs extends U{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),r=new Array(s);for(let i=1;i<=s;i++)r[i-1]=t(i*e);return r}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
460
+ precision highp float;
461
+ uniform sampler2D uTexture;
462
+ uniform vec2 uDelta;
463
+ varying vec2 vTexCoord;
464
+ uniform float uTaps[`.concat(t,`];
465
+ void main() {
466
+ vec4 color = texture2D(uTexture, vTexCoord);
467
+ float sum = 1.0;
468
+ `).concat(e.map((s,r)=>`
469
+ color += texture2D(uTexture, vTexCoord + `.concat(s,") * uTaps[").concat(r,"] + texture2D(uTexture, vTexCoord - ").concat(s,") * uTaps[").concat(r,`];
470
+ sum += 2.0 * uTaps[`).concat(r,`];
471
+ `)).join(`
472
+ `),`
473
+ gl_FragColor = color / sum;
474
+ }
475
+ `)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Xs(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,r=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/r;const i=e.width,n=e.height,o=Math.round(i*s),h=Math.round(n*r);let l;l=this.resizeType==="sliceHack"?this.sliceByTwo(t,i,n,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,i,n,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,i,n,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,i,n,o,h):new ImageData(o,h),t.imageData=l}sliceByTwo(t,e,s,r,i){const n=t.imageData,o=.5;let h=!1,l=!1,c=e*o,u=s*o;const g=t.filterBackend.resources;let d=0,f=0;const v=e;let _=0;g.sliceByTwo||(g.sliceByTwo=It());const x=g.sliceByTwo;(x.width<1.5*e||x.height<s)&&(x.width=1.5*e,x.height=s);const b=x.getContext("2d");for(b.clearRect(0,0,1.5*e,s),b.putImageData(n,0,0),r=Math.floor(r),i=Math.floor(i);!h||!l;)e=c,s=u,r<Math.floor(c*o)?c=Math.floor(c*o):(c=r,h=!0),i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,l=!0),b.drawImage(x,d,f,e,s,v,_,c,u),d=v,f=_,_+=u;return b.getImageData(d,f,r,i)}lanczosResize(t,e,s,r,i){const n=t.imageData.data,o=t.ctx.createImageData(r,i),h=o.data,l=this.lanczosCreate(this.lanczosLobes),c=this.rcpScaleX,u=this.rcpScaleY,g=2/this.rcpScaleX,d=2/this.rcpScaleY,f=Math.ceil(c*this.lanczosLobes/2),v=Math.ceil(u*this.lanczosLobes/2),_={},x={x:0,y:0},b={x:0,y:0};return function T(w){let C,D,k,S,M,E,W,j,R,F,K;for(x.x=(w+.5)*c,b.x=Math.floor(x.x),C=0;C<i;C++){for(x.y=(C+.5)*u,b.y=Math.floor(x.y),M=0,E=0,W=0,j=0,R=0,D=b.x-f;D<=b.x+f;D++)if(!(D<0||D>=e)){F=Math.floor(1e3*Math.abs(D-x.x)),_[F]||(_[F]={});for(let q=b.y-v;q<=b.y+v;q++)q<0||q>=s||(K=Math.floor(1e3*Math.abs(q-x.y)),_[F][K]||(_[F][K]=l(Math.sqrt(Math.pow(F*g,2)+Math.pow(K*d,2))/1e3)),k=_[F][K],k>0&&(S=4*(q*e+D),M+=k,E+=k*n[S],W+=k*n[S+1],j+=k*n[S+2],R+=k*n[S+3]))}S=4*(C*r+w),h[S]=E/M,h[S+1]=W/M,h[S+2]=j/M,h[S+3]=R/M}return++w<r?T(w):o}(0)}bilinearFiltering(t,e,s,r,i){let n,o,h,l,c,u,g,d,f,v,_,x,b,T=0;const w=this.rcpScaleX,C=this.rcpScaleY,D=4*(e-1),k=t.imageData.data,S=t.ctx.createImageData(r,i),M=S.data;for(g=0;g<i;g++)for(d=0;d<r;d++)for(c=Math.floor(w*d),u=Math.floor(C*g),f=w*d-c,v=C*g-u,b=4*(u*e+c),_=0;_<4;_++)n=k[b+_],o=k[b+4+_],h=k[b+D+_],l=k[b+D+4+_],x=n*(1-f)*(1-v)+o*f*(1-v)+h*v*(1-f)+l*f*v,M[T++]=x;return S}hermiteFastResize(t,e,s,r,i){const n=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(n/2),l=Math.ceil(o/2),c=t.imageData.data,u=t.ctx.createImageData(r,i),g=u.data;for(let d=0;d<i;d++)for(let f=0;f<r;f++){const v=4*(f+d*r);let _=0,x=0,b=0,T=0,w=0,C=0,D=0;const k=(d+.5)*o;for(let S=Math.floor(d*o);S<(d+1)*o;S++){const M=Math.abs(k-(S+.5))/l,E=(f+.5)*n,W=M*M;for(let j=Math.floor(f*n);j<(f+1)*n;j++){let R=Math.abs(E-(j+.5))/h;const F=Math.sqrt(W+R*R);F>1&&F<-1||(_=2*F*F*F-3*F*F+1,_>0&&(R=4*(j+S*e),D+=_*c[R+3],b+=_,c[R+3]<255&&(_=_*c[R+3]/250),T+=_*c[R],w+=_*c[R+1],C+=_*c[R+2],x+=_))}}g[v]=T/x,g[v+1]=w/x,g[v+2]=C/x,g[v+3]=D/b}return u}}p(cs,"type","Resize"),p(cs,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),p(cs,"uniformLocations",["uDelta","uTaps"]),O.setClass(cs);class us extends U{getFragmentSource(){return`
476
+ precision highp float;
477
+ uniform sampler2D uTexture;
478
+ uniform float uSaturation;
479
+ varying vec2 vTexCoord;
480
+ void main() {
481
+ vec4 color = texture2D(uTexture, vTexCoord);
482
+ float rgMax = max(color.r, color.g);
483
+ float rgbMax = max(rgMax, color.b);
484
+ color.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;
485
+ color.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;
486
+ color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
487
+ gl_FragColor = color;
488
+ }
489
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let r=0;r<e.length;r+=4){const i=e[r],n=e[r+1],o=e[r+2],h=Math.max(i,n,o);e[r]+=h!==i?(h-i)*s:0,e[r+1]+=h!==n?(h-n)*s:0,e[r+2]+=h!==o?(h-o)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}p(us,"type","Saturation"),p(us,"defaults",{saturation:0}),p(us,"uniformLocations",["uSaturation"]),O.setClass(us);class gs extends U{getFragmentSource(){return`
490
+ precision highp float;
491
+ uniform sampler2D uTexture;
492
+ uniform float uVibrance;
493
+ varying vec2 vTexCoord;
494
+ void main() {
495
+ vec4 color = texture2D(uTexture, vTexCoord);
496
+ float max = max(color.r, max(color.g, color.b));
497
+ float avg = (color.r + color.g + color.b) / 3.0;
498
+ float amt = (abs(max - avg) * 2.0) * uVibrance;
499
+ color.r += max != color.r ? (max - color.r) * amt : 0.00;
500
+ color.g += max != color.g ? (max - color.g) * amt : 0.00;
501
+ color.b += max != color.b ? (max - color.b) * amt : 0.00;
502
+ gl_FragColor = color;
503
+ }
504
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let r=0;r<e.length;r+=4){const i=e[r],n=e[r+1],o=e[r+2],h=Math.max(i,n,o),l=(i+n+o)/3,c=2*Math.abs(h-l)/255*s;e[r]+=h!==i?(h-i)*c:0,e[r+1]+=h!==n?(h-n)*c:0,e[r+2]+=h!==o?(h-o)*c:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}p(gs,"type","Vibrance"),p(gs,"defaults",{vibrance:0}),p(gs,"uniformLocations",["uVibrance"]),O.setClass(gs);function Tn(a){const[t,e]=Q.useState(null),[s,r]=Q.useState(!1),[i,n]=Q.useState(null),o=async()=>{if(a){r(!0),n(null);try{const h=await fetch(a);if(!h.ok)throw new Error(`Failed to fetch config: ${h.statusText}`);const l=await h.json();e(l)}catch(h){const l=h instanceof Error?h:new Error("Unknown error occurred");n(l),console.error("Failed to fetch seat map config:",l)}finally{r(!1)}}};return Q.useEffect(()=>{o()},[a]),{config:t,loading:s,error:i,refetch:o}}const On={canvasBackground:"#1a1a1a",stageColor:"#808080",seatAvailable:"#2C2B30",seatReserved:"#FCEA00",seatSelected:"#3A7DE5",seatUnavailable:"#6b7280",gridLines:"#404040",currency:"KD"},vh=({config:a,configUrl:t,reservedSeats:e=[],unavailableSeats:s=[],onSeatSelect:r,onSeatDeselect:i,onSelectionChange:n,colorOverrides:o,showTooltip:h=!0,zoomEnabled:l=!0,className:c="",onConfigLoad:u,onError:g})=>{const d=Q.useRef(null),[f,v]=Q.useState(null),[_,x]=Q.useState([]),{config:b,loading:T,error:w}=Tn(t),C=a||b,D=C?{...C.colors,...o}:{...On,...o};return Q.useEffect(()=>{C&&u&&u(C)},[C,u]),Q.useEffect(()=>{w&&g&&g(w)},[w,g]),Q.useEffect(()=>{if(!d.current||!C)return;const k=new dr(d.current,{width:C.canvas.width,height:C.canvas.height,backgroundColor:C.canvas.backgroundColor,selection:!1});return v(k),()=>{k.dispose()}},[C]),Q.useEffect(()=>{var k;!f||!C||(f.clear(),f.backgroundColor=C.canvas.backgroundColor,(k=C.stages)==null||k.forEach(S=>{const M=new lt({left:S.position.x,top:S.position.y,width:S.config.width,height:S.config.height,fill:D.stageColor+"80",stroke:"#ffffff",strokeWidth:2,rx:10,ry:10,selectable:!1,evented:!1}),E=new Nt(S.config.label,{left:S.position.x+S.config.width/2,top:S.position.y+S.config.height/2,fontSize:24,fontWeight:"bold",fill:"#ffffff",textAlign:"center",originX:"center",originY:"center",selectable:!1,evented:!1}),W=new Ut([M,E],{left:S.position.x,top:S.position.y,selectable:!1,evented:!1});f.add(W)}),C.seats.forEach(S=>{const M=yh(S,D);M.seatData=S,M.seatId=S.id,f.add(M)}),f.renderAll())},[f,C,D]),Q.useEffect(()=>{if(!f||!C)return;f.getObjects().forEach(S=>{const M=S.seatData;if(!M)return;const E=M.id,W=M.seatNumber;let j=null;s.includes(E)||s.includes(W||"")?j="unavailable":(e.includes(E)||e.includes(W||""))&&(j="reserved"),j&&M.state!==j&&(M.state=j,er(S,j,D))}),f.renderAll()},[f,C,e,s,D]),Q.useEffect(()=>{if(!f)return;const k=S=>{const M=S.target;if(!M||!M.seatData)return;const E=M.seatData;(E.state==="available"||E.state==="selected")&&(E.state==="selected"?(E.state="available",er(M,"available",D),x(j=>j.filter(R=>R.seatNumber!==E.seatNumber)),i&&i(E)):(E.state="selected",er(M,"selected",D),x(j=>[...j,E]),r?r(E):console.log("Seat selected:",E)),f.renderAll())};return f.on("mouse:down",k),()=>{f.off("mouse:down",k)}},[f,D,r,i]),Q.useEffect(()=>{n&&n(_)},[_,n]),Q.useEffect(()=>{if(!f||!l)return;const k=S=>{const M=S.e.deltaY;let E=f.getZoom();E*=.999**M,E>5&&(E=5),E<.5&&(E=.5),f.zoomToPoint(new y(S.e.offsetX,S.e.offsetY),E),S.e.preventDefault(),S.e.stopPropagation()};return f.on("mouse:wheel",k),()=>{f.off("mouse:wheel",k)}},[f,l]),T?ct.jsx("div",{className:`flex items-center justify-center h-full ${c}`,children:ct.jsx("p",{children:"Loading seat map..."})}):w?ct.jsx("div",{className:`flex items-center justify-center h-full ${c}`,children:ct.jsxs("p",{className:"text-red-500",children:["Error loading seat map: ",w.message]})}):C?ct.jsxs("div",{className:`relative ${c}`,children:[ct.jsx("canvas",{ref:d}),_.length>0&&ct.jsxs("div",{className:"absolute top-4 right-4 bg-white dark:bg-gray-800 p-4 rounded shadow-lg",children:[ct.jsxs("h3",{className:"font-semibold mb-2",children:["Selected Seats (",_.length,")"]}),ct.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:_.map(k=>ct.jsxs("div",{className:"text-sm",children:[k.seatNumber,k.price&&` - ${D.currency} ${k.price.toFixed(2)}`]},k.seatNumber))})]})]}):ct.jsx("div",{className:`flex items-center justify-center h-full ${c}`,children:ct.jsx("p",{children:"No configuration provided"})})};function yh(a,t){const s={available:t.seatAvailable,reserved:t.seatReserved,selected:t.seatSelected,unavailable:t.seatUnavailable};let r;return a.shape==="circle"?r=new wt({left:a.position.x,top:a.position.y,radius:12,fill:s[a.state],stroke:"#ffffff",strokeWidth:1,originX:"center",originY:"center",selectable:!1,hoverCursor:"pointer"}):a.shape==="square"?r=new lt({left:a.position.x,top:a.position.y,width:12*2,height:12*2,fill:s[a.state],stroke:"#ffffff",strokeWidth:1,originX:"center",originY:"center",rx:0,ry:0,selectable:!1,hoverCursor:"pointer"}):r=new lt({left:a.position.x,top:a.position.y,width:12*2,height:12*2,fill:s[a.state],stroke:"#ffffff",strokeWidth:1,originX:"center",originY:"center",rx:4,ry:4,selectable:!1,hoverCursor:"pointer"}),r}function er(a,t,e){const s={available:e.seatAvailable,reserved:e.seatReserved,selected:e.seatSelected,unavailable:e.seatUnavailable};a.set({fill:s[t]})}exports.DEFAULT_COLORS=On;exports.SeatMapViewer=vh;exports.useConfigFetcher=Tn;