@cliquify.me/timeline 3.1.11 → 3.1.13
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/events/canvas/internal.d.ts +4 -3
- package/dist/index.es.js +4425 -4279
- package/dist/index.umd.js +68 -68
- package/dist/mixins/track-items.d.ts +1 -1
- package/dist/mixins/transitions.d.ts +1 -1
- package/dist/objects/composition.d.ts +34 -0
- package/dist/utils/group-by-transition.d.ts +1 -1
- package/dist/utils/load-object.d.ts +8 -1
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find(s=>this.testPrecision(e,s)),e.getExtension("WEBGL_lose_context").loseContext(),me("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const zl={};let bo;const Gt=()=>bo||(bo={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Xl,dispose(){},copyPasteData:zl}),Ke=()=>Gt().document,ui=()=>Gt().window,_o=()=>{var r;return Math.max((r=A.devicePixelRatio)!==null&&r!==void 0?r:ui().devicePixelRatio,1)},Fs=new class{constructor(){v(this,"charWidthsCache",{}),v(this,"boundsOfCurveCache",{})}getFontCache(r){let{fontFamily:t,fontStyle:e,fontWeight:s}=r;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(r){(r=(r||"").toLowerCase())?this.charWidthsCache[r]&&delete this.charWidthsCache[r]:this.charWidthsCache={}}limitDimsByArea(r){const{perfLimitSizeTotal:t}=A,e=Math.sqrt(t*r);return[Math.floor(e),Math.floor(t/e)]}},Er="6.4.2";function Ee(){}const ve=Math.PI/2,Jt=2*Math.PI,jr=Math.PI/180,ut=Object.freeze([1,0,0,1,0,0]),Pr=16,ye=.4477152502,j="center",L="left",mt="top",Ar="bottom",Q="right",vt="none",Lr=/\r?\n/,To="moving",di="scaling",So="rotating",Fr="rotate",xo="skewing",Rs="resizing",wo="modifyPoly",Hl="modifyPath",gi="changed",fi="scale",dt="scaleX",Tt="scaleY",Je="skewX",Ze="skewY",st="fill",yt="stroke",pi="modified",Qe="json",Rr="svg",w=new class{constructor(){this[Qe]=new Map,this[Rr]=new Map}has(r){return this[Qe].has(r)}getClass(r){const t=this[Qe].get(r);if(!t)throw new Yt("No class registered for ".concat(r));return t}setClass(r,t){t?this[Qe].set(t,r):(this[Qe].set(r.type,r),this[Qe].set(r.type.toLowerCase(),r))}getSVGClass(r){return this[Rr].get(r)}setSVGClass(r,t){this[Rr].set(t??r.type.toLowerCase(),r)}},mi=new class extends Array{remove(r){const t=this.indexOf(r);t>-1&&this.splice(t,1)}cancelAll(){const r=this.splice(0);return r.forEach(t=>t.abort()),r}cancelByCanvas(r){if(!r)return[];const t=this.filter(e=>{var s;return e.target===r||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===r});return t.forEach(e=>e.abort()),t}cancelByTarget(r){if(!r)return[];const t=this.filter(e=>e.target===r);return t.forEach(e=>e.abort()),t}};class Yl{constructor(){v(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,o]=i;s.push(this.once(n,o))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const je=(r,t)=>{const e=r.indexOf(t);return e!==-1&&r.splice(e,1),r},It=r=>{if(r===0)return 1;switch(Math.abs(r)/ve){case 1:case 3:return 0;case 2:return-1}return Math.cos(r)},Et=r=>{if(r===0)return 0;const t=r/ve,e=Math.sign(r);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(r)};class _{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 _(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new _(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new _(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new _(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new _(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new _(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new _(this.x/t.x,this.y/t.y)}scalarDivide(t){return new _(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 _(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 _(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new _(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 _(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Br;const s=Et(t),i=It(t),n=this.subtract(e);return new _(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new _(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 Br=new _(0,0),vi=r=>!!r&&Array.isArray(r._objects);function Co(r){class t extends r{constructor(){super(...arguments),v(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const o=this._objects.push(...i);return i.forEach(a=>this._onObjectAdded(a)),o}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),o=1;o<i;o++)n[o-1]=arguments[o];return this._objects.splice(s,0,...n),n.forEach(a=>this._onObjectAdded(a)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,o=new Array(n),a=0;a<n;a++)o[a]=arguments[a];return o.forEach(c=>{const h=s.indexOf(c);h!==-1&&(s.splice(h,1),i.push(c),this._onObjectRemoved(c))}),i}forEachObject(s){this.getObjects().forEach((i,n,o)=>s(i,n,o))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(o=>o.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(je(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(je(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const o=this.findNewLowerIndex(s,n,i);return je(this._objects,s),this._objects.splice(o,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const o=this.findNewUpperIndex(s,n,i);return je(this._objects,s),this._objects.splice(o,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(je(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let o;if(n){o=i;for(let a=i-1;a>=0;--a)if(s.isOverlapping(this._objects[a])){o=a;break}}else o=i-1;return o}findNewUpperIndex(s,i,n){let o;if(n){o=i;for(let a=i+1;a<this._objects.length;++a)if(s.isOverlapping(this._objects[a])){o=a;break}}else o=i+1;return o}collectObjects(s){let{left:i,top:n,width:o,height:a}=s,{includeIntersecting:c=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const h=[],l=new _(i,n),u=l.add(new _(o,a));for(let d=this._objects.length-1;d>=0;d--){const g=this._objects[d];g.selectable&&g.visible&&(c&&g.intersectsWithRect(l,u)||g.isContainedWithinRect(l,u)||c&&g.containsPoint(l)||c&&g.containsPoint(u))&&h.push(g)}return h}}return t}class Oo extends Yl{_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 Bs(r){return ui().requestAnimationFrame(r)}function ko(r){return ui().cancelAnimationFrame(r)}let Gl=0;const be=()=>Gl++,tt=()=>{const r=Ke().createElement("canvas");if(!r||r.getContext===void 0)throw new Yt("Failed to create `canvas` element");return r},Mo=()=>Ke().createElement("img"),Wr=(r,t,e)=>r.toDataURL("image/".concat(t),e),$=r=>r*jr,_e=r=>r/jr,Do=r=>r.every((t,e)=>t===ut[e]),ht=(r,t,e)=>new _(r).transform(t,e),St=r=>{const t=1/(r[0]*r[3]-r[1]*r[2]),e=[t*r[3],-t*r[1],-t*r[2],t*r[0],0,0],{x:s,y:i}=new _(r[4],r[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},q=(r,t,e)=>[r[0]*t[0]+r[2]*t[1],r[1]*t[0]+r[3]*t[1],r[0]*t[2]+r[2]*t[3],r[1]*t[2]+r[3]*t[3],e?0:r[0]*t[4]+r[2]*t[5]+r[4],e?0:r[1]*t[4]+r[3]*t[5]+r[5]],yi=(r,t)=>r.reduceRight((e,s)=>s&&e?q(s,e,t):s||e,void 0)||ut.concat(),Io=r=>{let[t,e]=r;return Math.atan2(e,t)},ts=r=>{const t=Io(r),e=Math.pow(r[0],2)+Math.pow(r[1],2),s=Math.sqrt(e),i=(r[0]*r[3]-r[2]*r[1])/s,n=Math.atan2(r[0]*r[2]+r[1]*r[3],e);return{angle:_e(t),scaleX:s,scaleY:i,skewX:_e(n),skewY:0,translateX:r[4]||0,translateY:r[5]||0}},es=function(r){return[1,0,0,1,r,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function ss(){let{angle:r=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=$(r),i=It(s),n=Et(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const bi=function(r){return[r,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:r,0,0]},Eo=r=>Math.tan($(r)),Xr=r=>[1,0,Eo(r),1,0,0],zr=r=>[1,Eo(r),0,1,0,0],Ws=r=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:o=0}=r,a=bi(s?-t:t,i?-e:e);return n&&(a=q(a,Xr(n),!0)),o&&(a=q(a,zr(o),!0)),a},jo=r=>{const{translateX:t=0,translateY:e=0,angle:s=0}=r;let i=es(t,e);s&&(i=q(i,ss({angle:s})));const n=Ws(r);return Do(n)||(i=q(i,n)),i},Xs=function(r){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(s,i){if(t&&t.aborted)return i(new yo("loadImage"));const n=Mo();let o;t&&(o=function(c){n.src="",i(c)},t.addEventListener("abort",o,{once:!0}));const a=function(){n.onload=n.onerror=null,o&&(t==null||t.removeEventListener("abort",o)),s(n)};r?(n.onload=a,n.onerror=function(){o&&(t==null||t.removeEventListener("abort",o)),i(new Yt("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=r):a()})},is=function(r){let{signal:t,reviver:e=Ee}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(r.map(o=>w.getClass(o.type).fromObject(o,{signal:t}).then(a=>(e(o,a),n.push(a),a)))).then(s).catch(o=>{n.forEach(a=>{a.dispose&&a.dispose()}),i(o)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},zs=function(r){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(r).map(a=>a&&a.type&&w.has(a.type)?is([a],{signal:t}).then(c=>{let[h]=c;return i.push(h),h}):a),o=Object.keys(r);Promise.all(n).then(a=>a.reduce((c,h,l)=>(c[o[l]]=h,c),{})).then(e).catch(a=>{i.forEach(c=>{c.dispose&&c.dispose()}),s(a)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},Pe=function(r){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in r&&(t[e]=r[e]),t),{})},Hr=(r,t)=>Object.keys(r).reduce((e,s)=>(t(r[s],s,r)&&(e[s]=r[s]),e),{}),Po={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"},Yr=(r,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?r+6*(t-r)*e:e<.5?t:e<2/3?r+(t-r)*(2/3-e)*6:r),Ao=(r,t,e,s)=>{r/=255,t/=255,e/=255;const i=Math.max(r,t,e),n=Math.min(r,t,e);let o,a;const c=(i+n)/2;if(i===n)o=a=0;else{const h=i-n;switch(a=c>.5?h/(2-i-n):h/(i+n),i){case r:o=(t-e)/h+(t<e?6:0);break;case t:o=(e-r)/h+2;break;case e:o=(r-t)/h+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*c),s]},Lo=function(){let r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(r)/(r.endsWith("%")?100:1)},_i=r=>Math.min(Math.round(r),255).toString(16).toUpperCase().padStart(2,"0"),Fo=r=>{let[t,e,s,i=1]=r;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class R{constructor(t){if(v(this,"isUnrecognised",!1),t)if(t instanceof R)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in Po&&(t=Po[t]),t==="transparent"?[255,255,255,0]:R.sourceFromHex(t)||R.sourceFromRgb(t)||R.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]=Ao(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Ao(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,i]=this.getSource();return"".concat(_i(t)).concat(_i(e)).concat(_i(s)).concat(_i(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Fo(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Fo(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof R||(t=new R(t));const e=this.getSource(),s=t.getSource(),[i,n,o]=e.map((a,c)=>Math.round(.5*a+.5*s[c]));return this.setSource([i,n,o,e[3]]),this}static fromRgb(t){return R.fromRgba(t)}static fromRgba(t){return new R(R.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,i,n]=e.slice(1,4).map(o=>{const a=parseFloat(o);return o.endsWith("%")?Math.round(2.55*a):a});return[s,i,n,Lo(e[4])]}}static fromHsl(t){return R.fromHsla(t)}static fromHsla(t){return new R(R.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=(R.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let o,a,c;if(i===0)o=a=c=n;else{const h=n<=.5?n*(i+1):n+i-n*i,l=2*n-h;o=Yr(l,h,s+1/3),a=Yr(l,h,s),c=Yr(l,h,s-1/3)}return[Math.round(255*o),Math.round(255*a),Math.round(255*c),Lo(e[4])]}static fromHex(t){return new R(R.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(c=>c+c):e.match(/.{2}/g);const[i,n,o,a=255]=s.map(c=>parseInt(c,16));return[i,n,o,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?_e(s):e.includes("turn")?360*s:s}}const G=(r,t)=>parseFloat(Number(r).toFixed(t)),Ae=function(r){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Pr;const e=/\D{0,2}$/.exec(r),s=parseFloat(r),i=A.DPI;switch(e==null?void 0:e[0]){case"mm":return s*i/25.4;case"cm":return s*i/2.54;case"in":return s*i;case"pt":return s*i/72;case"pc":return s*i/72*12;case"em":return s*t;default:return s}},Ro=r=>{const[t,e]=r.trim().split(" "),[s,i]=(n=t)&&n!==vt?[n.slice(1,4),n.slice(5,8)]:n===vt?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Hs=r=>"matrix("+r.map(t=>G(t,A.NUM_FRACTION_DIGITS)).join(" ")+")",Ys=function(r,t){let e,s,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const n=new R(t),o=n.getAlpha();e=n.toRgb(),o!==1&&(s=o.toString())}else e="none";return i?"".concat(r,": ").concat(e,"; ").concat(s?"".concat(r,"-opacity: ").concat(s,"; "):""):"".concat(r,'="').concat(e,'" ').concat(s?"".concat(r,'-opacity="').concat(s,'" '):"")},Ct=r=>!!r&&r.toLive!==void 0,Bo=r=>!!r&&typeof r.toObject=="function",Wo=r=>!!r&&r.offsetX!==void 0&&"source"in r,Xo=r=>!!r&&typeof r._renderText=="function",Le=r=>!!r&&"multiSelectionStacking"in r;function zo(r){const t=r&&jt(r);let e=0,s=0;if(!r||!t)return{left:e,top:s};let i=r;const n=t.documentElement,o=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=o.scrollLeft||n.scrollLeft||0,s=o.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const jt=r=>r.ownerDocument||null,Ho=r=>{var t;return((t=r.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},Yo=function(r,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;r.width=s,r.height=i,n>1&&(r.setAttribute("width",(s*n).toString()),r.setAttribute("height",(i*n).toString()),t.scale(n,n))},Gr=(r,t)=>{let{width:e,height:s}=t;e&&(r.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(r.style.height=typeof s=="number"?"".concat(s,"px"):s)};function Go(r){return r.onselectstart!==void 0&&(r.onselectstart=()=>!1),r.style.userSelect=vt,r}class Vo{constructor(t){v(this,"_originalCanvasStyle",void 0),v(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&&Ke().getElementById(t)||tt();var s;if(e.hasAttribute("data-fabric"))throw new Yt("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;Yo(s,i,t,e)}setCSSDimensions(t){Gr(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&jt(t),i={left:0,top:0};if(!s)return i;const n=((e=Ho(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let o={left:0,top:0};const a=s.documentElement;t.getBoundingClientRect!==void 0&&(o=t.getBoundingClientRect());const c=zo(t);return{left:o.left+c.left-(a.clientLeft||0)+i.left,top:o.top+c.top-(a.clientTop||0)+i.top}}(this.lower.el)}dispose(){Gt().dispose(this.lower.el),delete this.lower}}const Vl={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...ut]};class Gs extends Co(Oo){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 Gs.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 Vo(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(me("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
3
|
-
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?
|
|
1
|
+
(function(M,J){typeof exports=="object"&&typeof module<"u"?J(exports,require("@designcombo/events")):typeof define=="function"&&define.amd?define(["exports","@designcombo/events"],J):(M=typeof globalThis<"u"?globalThis:M||self,J(M.timeline={},M.events))})(this,function(M,J){"use strict";var R0=Object.defineProperty;var B0=(M,J,v)=>J in M?R0(M,J,{enumerable:!0,configurable:!0,writable:!0,value:v}):M[J]=v;var S=(M,J,v)=>B0(M,typeof J!="symbol"?J+"":J,v);function v(i,t,e){return(t=function(s){var r=function(n,o){if(typeof n!="object"||!n)return n;var a=n[Symbol.toPrimitive];if(a!==void 0){var c=a.call(n,o);if(typeof c!="object")return c;throw new TypeError("@@toPrimitive must return a primitive value.")}return(o==="string"?String:Number)(n)}(s,"string");return typeof r=="symbol"?r:r+""}(t))in i?Object.defineProperty(i,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):i[t]=e,i}function lo(i,t){var e=Object.keys(i);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(i);t&&(s=s.filter(function(r){return Object.getOwnPropertyDescriptor(i,r).enumerable})),e.push.apply(e,s)}return e}function y(i){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?lo(Object(e),!0).forEach(function(s){v(i,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(e)):lo(Object(e)).forEach(function(s){Object.defineProperty(i,s,Object.getOwnPropertyDescriptor(e,s))})}return i}function U(i,t){if(i==null)return{};var e,s,r=function(o,a){if(o==null)return{};var c={};for(var h in o)if({}.hasOwnProperty.call(o,h)){if(a.indexOf(h)>=0)continue;c[h]=o[h]}return c}(i,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(i);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(i,e)&&(r[e]=i[e])}return r}function Ht(i,t){return t||(t=i.slice(0)),Object.freeze(Object.defineProperties(i,{raw:{value:Object.freeze(t)}}))}class uo{constructor(){v(this,"browserShadowBlurConstant",1),v(this,"DPI",96),v(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),v(this,"perfLimitSizeTotal",2097152),v(this,"maxCacheSideLimit",4096),v(this,"minCacheSideLimit",256),v(this,"disableStyleCopyPaste",!1),v(this,"enableGLFiltering",!0),v(this,"textureSize",4096),v(this,"forceGLPutImageData",!1),v(this,"cachesBoundsOfCurve",!0),v(this,"fontPaths",{}),v(this,"NUM_FRACTION_DIGITS",4)}}const L=new class extends uo{constructor(i){super(),this.configure(i)}configure(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,i)}addFonts(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=y(y({},this.fontPaths),i)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(i=>{delete this.fontPaths[i]})}clearFonts(){this.fontPaths={}}restoreDefaults(i){const t=new uo,e=(i==null?void 0:i.reduce((s,r)=>(s[r]=t[r],s),{}))||t;this.configure(e)}},pe=function(i){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[i]("fabric",...e)};class Yt extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class fo extends Yt{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Al{}class Ll extends Al{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(),pe("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Fl={};let go;const Vt=()=>go||(go={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Ll,dispose(){},copyPasteData:Fl}),Ke=()=>Vt().document,gr=()=>Vt().window,po=()=>{var i;return Math.max((i=L.devicePixelRatio)!==null&&i!==void 0?i:gr().devicePixelRatio,1)},Bs=new class{constructor(){v(this,"charWidthsCache",{}),v(this,"boundsOfCurveCache",{})}getFontCache(i){let{fontFamily:t,fontStyle:e,fontWeight:s}=i;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const r=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return r[n]||(r[n]={}),r[n]}clearFontCache(i){(i=(i||"").toLowerCase())?this.charWidthsCache[i]&&delete this.charWidthsCache[i]:this.charWidthsCache={}}limitDimsByArea(i){const{perfLimitSizeTotal:t}=L,e=Math.sqrt(t*i);return[Math.floor(e),Math.floor(t/e)]}},Ii="6.3.0";function De(){}const me=Math.PI/2,te=2*Math.PI,ji=Math.PI/180,ut=Object.freeze([1,0,0,1,0,0]),Ei=16,ve=.4477152502,E="center",R="left",mt="top",Pi="bottom",Q="right",vt="none",Ai=/\r?\n/,mo="moving",pr="scaling",vo="rotating",Li="rotate",yo="skewing",Ws="resizing",bo="modifyPoly",Rl="modifyPath",mr="changed",vr="scale",dt="scaleX",_t="scaleY",Ze="skewX",Je="skewY",st="fill",yt="stroke",yr="modified",Qe="json",Fi="svg",C=new class{constructor(){this[Qe]=new Map,this[Fi]=new Map}has(i){return this[Qe].has(i)}getClass(i){const t=this[Qe].get(i);if(!t)throw new Yt("No class registered for ".concat(i));return t}setClass(i,t){t?this[Qe].set(t,i):(this[Qe].set(i.type,i),this[Qe].set(i.type.toLowerCase(),i))}getSVGClass(i){return this[Fi].get(i)}setSVGClass(i,t){this[Fi].set(t??i.type.toLowerCase(),i)}},br=new class extends Array{remove(i){const t=this.indexOf(i);t>-1&&this.splice(t,1)}cancelAll(){const i=this.splice(0);return i.forEach(t=>t.abort()),i}cancelByCanvas(i){if(!i)return[];const t=this.filter(e=>{var s;return e.target===i||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===i});return t.forEach(e=>e.abort()),t}cancelByTarget(i){if(!i)return[];const t=this.filter(e=>e.target===i);return t.forEach(e=>e.abort()),t}};class Bl{constructor(){v(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[r,n]=s;this.on(r,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(r=>{let[n,o]=r;s.push(this.once(n,o))}),()=>s.forEach(r=>r())}if(e){const s=this.on(t,function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];e.call(this,...n),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,n]=s;this._removeEventListener(r,n)}):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 n=0;n<r.length;n++)r[n].call(this,e||{})}}const Ie=(i,t)=>{const e=i.indexOf(t);return e!==-1&&i.splice(e,1),i},It=i=>{if(i===0)return 1;switch(Math.abs(i)/me){case 1:case 3:return 0;case 2:return-1}return Math.cos(i)},jt=i=>{if(i===0)return 0;const t=i/me,e=Math.sign(i);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(i)};class _{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 _(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new _(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new _(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new _(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new _(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new _(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new _(this.x/t.x,this.y/t.y)}scalarDivide(t){return new _(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 _(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 _(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new _(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 _(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ri;const s=jt(t),r=It(t),n=this.subtract(e);return new _(n.x*r-n.y*s,n.x*s+n.y*r).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new _(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 Ri=new _(0,0),_r=i=>!!i&&Array.isArray(i._objects);function _o(i){class t extends i{constructor(){super(...arguments),v(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,r=new Array(s),n=0;n<s;n++)r[n]=arguments[n];const o=this._objects.push(...r);return r.forEach(a=>this._onObjectAdded(a)),o}insertAt(s){for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return this._objects.splice(s,0,...n),n.forEach(a=>this._onObjectAdded(a)),this._objects.length}remove(){const s=this._objects,r=[];for(var n=arguments.length,o=new Array(n),a=0;a<n;a++)o[a]=arguments[a];return o.forEach(c=>{const h=s.indexOf(c);h!==-1&&(s.splice(h,1),r.push(c),this._onObjectRemoved(c))}),r}forEachObject(s){this.getObjects().forEach((r,n,o)=>s(r,n,o))}getObjects(){for(var s=arguments.length,r=new Array(s),n=0;n<s;n++)r[n]=arguments[n];return r.length===0?[...this._objects]:this._objects.filter(o=>o.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(n=>n instanceof t&&n.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])&&(Ie(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Ie(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,r){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const o=this.findNewLowerIndex(s,n,r);return Ie(this._objects,s),this._objects.splice(o,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,r){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const o=this.findNewUpperIndex(s,n,r);return Ie(this._objects,s),this._objects.splice(o,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,r){return s!==this._objects[r]&&(Ie(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,r,n){let o;if(n){o=r;for(let a=r-1;a>=0;--a)if(s.isOverlapping(this._objects[a])){o=a;break}}else o=r-1;return o}findNewUpperIndex(s,r,n){let o;if(n){o=r;for(let a=r+1;a<this._objects.length;++a)if(s.isOverlapping(this._objects[a])){o=a;break}}else o=r+1;return o}collectObjects(s){let{left:r,top:n,width:o,height:a}=s,{includeIntersecting:c=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const h=[],l=new _(r,n),u=l.add(new _(o,a));for(let d=this._objects.length-1;d>=0;d--){const f=this._objects[d];f.selectable&&f.visible&&(c&&f.intersectsWithRect(l,u)||f.isContainedWithinRect(l,u)||c&&f.containsPoint(l)||c&&f.containsPoint(u))&&h.push(f)}return h}}return t}class To extends Bl{_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 Xs(i){return gr().requestAnimationFrame(i)}function So(i){return gr().cancelAnimationFrame(i)}let Wl=0;const ye=()=>Wl++,tt=()=>{const i=Ke().createElement("canvas");if(!i||i.getContext===void 0)throw new Yt("Failed to create `canvas` element");return i},xo=()=>Ke().createElement("img"),Bi=(i,t,e)=>i.toDataURL("image/".concat(t),e),K=i=>i*ji,be=i=>i/ji,wo=i=>i.every((t,e)=>t===ut[e]),ht=(i,t,e)=>new _(i).transform(t,e),Tt=i=>{const t=1/(i[0]*i[3]-i[1]*i[2]),e=[t*i[3],-t*i[1],-t*i[2],t*i[0],0,0],{x:s,y:r}=new _(i[4],i[5]).transform(e,!0);return e[4]=-s,e[5]=-r,e},Z=(i,t,e)=>[i[0]*t[0]+i[2]*t[1],i[1]*t[0]+i[3]*t[1],i[0]*t[2]+i[2]*t[3],i[1]*t[2]+i[3]*t[3],e?0:i[0]*t[4]+i[2]*t[5]+i[4],e?0:i[1]*t[4]+i[3]*t[5]+i[5]],Tr=(i,t)=>i.reduceRight((e,s)=>s&&e?Z(s,e,t):s||e,void 0)||ut.concat(),Co=i=>{let[t,e]=i;return Math.atan2(e,t)},ts=i=>{const t=Co(i),e=Math.pow(i[0],2)+Math.pow(i[1],2),s=Math.sqrt(e),r=(i[0]*i[3]-i[2]*i[1])/s,n=Math.atan2(i[0]*i[2]+i[1]*i[3],e);return{angle:be(t),scaleX:s,scaleY:r,skewX:be(n),skewY:0,translateX:i[4]||0,translateY:i[5]||0}},es=function(i){return[1,0,0,1,i,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function ss(){let{angle:i=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=K(i),r=It(s),n=jt(s);return[r,n,-n,r,t?t-(r*t-n*e):0,e?e-(n*t+r*e):0]}const Sr=function(i){return[i,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:i,0,0]},Oo=i=>Math.tan(K(i)),Wi=i=>[1,0,Oo(i),1,0,0],Xi=i=>[1,Oo(i),0,1,0,0],zs=i=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:r=!1,skewX:n=0,skewY:o=0}=i,a=Sr(s?-t:t,r?-e:e);return n&&(a=Z(a,Wi(n),!0)),o&&(a=Z(a,Xi(o),!0)),a},ko=i=>{const{translateX:t=0,translateY:e=0,angle:s=0}=i;let r=es(t,e);s&&(r=Z(r,ss({angle:s})));const n=zs(i);return wo(n)||(r=Z(r,n)),r},Hs=function(i){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 fo("loadImage"));const n=xo();let o;t&&(o=function(c){n.src="",r(c)},t.addEventListener("abort",o,{once:!0}));const a=function(){n.onload=n.onerror=null,o&&(t==null||t.removeEventListener("abort",o)),s(n)};i?(n.onload=a,n.onerror=function(){o&&(t==null||t.removeEventListener("abort",o)),r(new Yt("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=i):a()})},rs=function(i){let{signal:t,reviver:e=De}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,r)=>{const n=[];t&&t.addEventListener("abort",r,{once:!0}),Promise.all(i.map(o=>C.getClass(o.type).fromObject(o,{signal:t}).then(a=>(e(o,a),n.push(a),a)))).then(s).catch(o=>{n.forEach(a=>{a.dispose&&a.dispose()}),r(o)}).finally(()=>{t&&t.removeEventListener("abort",r)})})},Ys=function(i){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 n=Object.values(i).map(a=>a&&a.type&&C.has(a.type)?rs([a],{signal:t}).then(c=>{let[h]=c;return r.push(h),h}):a),o=Object.keys(i);Promise.all(n).then(a=>a.reduce((c,h,l)=>(c[o[l]]=h,c),{})).then(e).catch(a=>{r.forEach(c=>{c.dispose&&c.dispose()}),s(a)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},je=function(i){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in i&&(t[e]=i[e]),t),{})},zi=(i,t)=>Object.keys(i).reduce((e,s)=>(t(i[s],s,i)&&(e[s]=i[s]),e),{}),Mo={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"},Hi=(i,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?i+6*(t-i)*e:e<.5?t:e<2/3?i+(t-i)*(2/3-e)*6:i),Do=(i,t,e,s)=>{i/=255,t/=255,e/=255;const r=Math.max(i,t,e),n=Math.min(i,t,e);let o,a;const c=(r+n)/2;if(r===n)o=a=0;else{const h=r-n;switch(a=c>.5?h/(2-r-n):h/(r+n),r){case i:o=(t-e)/h+(t<e?6:0);break;case t:o=(e-i)/h+2;break;case e:o=(i-t)/h+4}o/=6}return[Math.round(360*o),Math.round(100*a),Math.round(100*c),s]},Io=function(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(i)/(i.endsWith("%")?100:1)},xr=i=>Math.min(Math.round(i),255).toString(16).toUpperCase().padStart(2,"0"),jo=i=>{let[t,e,s,r=1]=i;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,r]};class B{constructor(t){if(v(this,"isUnrecognised",!1),t)if(t instanceof B)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,r,n=1]=t;this.setSource([e,s,r,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in Mo&&(t=Mo[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]=Do(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,r]=Do(...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(xr(t)).concat(xr(e)).concat(xr(s)).concat(xr(Math.round(255*r)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(jo(this.getSource())),this}toBlackWhite(t){const[e,,,s]=jo(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,n,o]=e.map((a,c)=>Math.round(.5*a+.5*s[c]));return this.setSource([r,n,o,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,n]=e.slice(1,4).map(o=>{const a=parseFloat(o);return o.endsWith("%")?Math.round(2.55*a):a});return[s,r,n,Io(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,n=parseFloat(e[3])/100;let o,a,c;if(r===0)o=a=c=n;else{const h=n<=.5?n*(r+1):n+r-n*r,l=2*n-h;o=Hi(l,h,s+1/3),a=Hi(l,h,s),c=Hi(l,h,s-1/3)}return[Math.round(255*o),Math.round(255*a),Math.round(255*c),Io(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(c=>c+c):e.match(/.{2}/g);const[r,n,o,a=255]=s.map(c=>parseInt(c,16));return[r,n,o,a/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?be(s):e.includes("turn")?360*s:s}}const P=(i,t)=>parseFloat(Number(i).toFixed(t)),Ee=function(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ei;const e=/\D{0,2}$/.exec(i),s=parseFloat(i),r=L.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}},Eo=i=>{const[t,e]=i.trim().split(" "),[s,r]=(n=t)&&n!==vt?[n.slice(1,4),n.slice(5,8)]:n===vt?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:r}},Vs=i=>"matrix("+i.map(t=>P(t,L.NUM_FRACTION_DIGITS)).join(" ")+")",Gs=function(i,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 n=new B(t),o=n.getAlpha();e=n.toRgb(),o!==1&&(s=o.toString())}else e="none";return r?"".concat(i,": ").concat(e,"; ").concat(s?"".concat(i,"-opacity: ").concat(s,"; "):""):"".concat(i,'="').concat(e,'" ').concat(s?"".concat(i,'-opacity="').concat(s,'" '):"")},xt=i=>!!i&&i.toLive!==void 0,Po=i=>!!i&&typeof i.toObject=="function",Ao=i=>!!i&&i.offsetX!==void 0&&"source"in i,Lo=i=>!!i&&typeof i._renderText=="function",Pe=i=>!!i&&"multiSelectionStacking"in i;function Fo(i){const t=i&&Et(i);let e=0,s=0;if(!i||!t)return{left:e,top:s};let r=i;const n=t.documentElement,o=t.body||{scrollLeft:0,scrollTop:0};for(;r&&(r.parentNode||r.host)&&(r=r.parentNode||r.host,r===t?(e=o.scrollLeft||n.scrollLeft||0,s=o.scrollTop||n.scrollTop||0):(e+=r.scrollLeft||0,s+=r.scrollTop||0),r.nodeType!==1||r.style.position!=="fixed"););return{left:e,top:s}}const Et=i=>i.ownerDocument||null,Ro=i=>{var t;return((t=i.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null};function Ns(i,t){const e=i.style;e&&(typeof t=="string"?i.style.cssText+=";"+t:Object.entries(t).forEach(s=>{let[r,n]=s;return e.setProperty(r,n)}))}const Bo=function(i,t,e){let{width:s,height:r}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;i.width=s,i.height=r,n>1&&(i.setAttribute("width",(s*n).toString()),i.setAttribute("height",(r*n).toString()),t.scale(n,n))},Yi=(i,t)=>{let{width:e,height:s}=t;e&&(i.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(i.style.height=typeof s=="number"?"".concat(s,"px"):s)};function Wo(i){return i.onselectstart!==void 0&&(i.onselectstart=()=>!1),i.style.userSelect=vt,i}class Xo{constructor(t){v(this,"_originalCanvasStyle",void 0),v(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&&Ke().getElementById(t)||tt();var s;if(e.hasAttribute("data-fabric"))throw new Yt("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;Bo(s,r,t,e)}setCSSDimensions(t){Yi(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Et(t),r={left:0,top:0};if(!s)return r;const n=((e=Ro(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};r.left+=parseInt(n.borderLeftWidth,10)||0,r.top+=parseInt(n.borderTopWidth,10)||0,r.left+=parseInt(n.paddingLeft,10)||0,r.top+=parseInt(n.paddingTop,10)||0;let o={left:0,top:0};const a=s.documentElement;t.getBoundingClientRect!==void 0&&(o=t.getBoundingClientRect());const c=Fo(t);return{left:o.left+c.left-(a.clientLeft||0)+r.left,top:o.top+c.top-(a.clientTop||0)+r.top}}(this.lower.el)}dispose(){Vt().dispose(this.lower.el),delete this.lower}}const Xl={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...ut]};class Us extends _o(To){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 Us.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 Xo(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 n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(pe("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?po():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=y({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],n=ht(t,Tt(r));r[0]=e,r[3]=e;const o=ht(n,r);r[4]+=s.x-o.x,r[5]+=s.y-o.y,this.setViewportTransform(r)}setZoom(t){this.zoomToPoint(new _(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 _(-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=Xs(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=Tt(this.viewportTransform),r=ht({x:0,y:0},s),n=ht({x:t,y:e},s),o=r.min(n),a=r.max(n);return this.vptCoords={tl:o,tr:new _(a.x,o.y),bl:new _(o.x,a.y),br:a}}cancelRequestedRender(){this.nextRenderHandle&&(So(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")],n=this.viewportTransform,o=this["".concat(e,"Vpt")];if(!s&&!r)return;const a=xt(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=a?s.toLive(t):s,o&&t.transform(...n),a){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const c=s.gradientTransform||s.patternTransform;c&&t.transform(...c)}t.fill(),t.restore()}if(r){t.save();const{skipOffscreen:c}=this;this.skipOffscreen=o,o&&t.transform(...n),r.render(t),this.skipOffscreen=c,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 _(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new _(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new _(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 _(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new _(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ht(this.getCenterPoint(),Tt(this.viewportTransform))}_centerObject(t,e){t.setXY(e,E,E),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,r=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return y(y(y({version:Ii},je(this,e)),{},{objects:this._objects.filter(n=>!n.excludeFromExport).map(n=>this._toObject(n,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 n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!r),n}__serializeBgOverlay(t,e){const s={},r=this.backgroundImage,n=this.overlayImage,o=this.backgroundColor,a=this.overlayColor;return xt(o)?o.excludeFromExport||(s.background=o.toObject(e)):o&&(s.background=o),xt(a)?a.excludeFromExport||(s.overlay=a.toObject(e)):a&&(s.overlay=a),r&&!r.excludeFromExport&&(s.backgroundImage=this._toObject(r,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
|
|
4
4
|
`)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
|
|
5
5
|
`),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
|
|
6
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),
|
|
8
|
-
`,"<desc>Created with Fabric.js ",
|
|
7
|
+
`)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),r=e.height||"".concat(this.height),n=L.NUM_FRACTION_DIGITS,o=e.viewBox;let a;if(o)a='viewBox="'.concat(o.x," ").concat(o.y," ").concat(o.width," ").concat(o.height,'" ');else if(this.svgViewportTransformation){const c=this.viewportTransform;a='viewBox="'.concat(P(-c[4]/c[0],n)," ").concat(P(-c[5]/c[3],n)," ").concat(P(this.width/c[0],n)," ").concat(P(this.height/c[3],n),'" ')}else a='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',r,'" ',a,`xml:space="preserve">
|
|
8
|
+
`,"<desc>Created with Fabric.js ",Ii,`</desc>
|
|
9
9
|
`,`<defs>
|
|
10
10
|
`,this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),`</defs>
|
|
11
|
-
`)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(
|
|
11
|
+
`)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(ye()),'<clipPath id="'.concat(e.clipPathId,`" >
|
|
12
12
|
`).concat(e.toClipPathSVG(t.reviver),`</clipPath>
|
|
13
|
-
`)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(
|
|
13
|
+
`)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(xt(e)){const s=this["".concat(t,"Vpt")],r=this.viewportTransform,n={isType:()=>!1,width:this.width/(s?r[0]:1),height:this.height/(s?r[3]:1)};return e.toSVG(n,{additionalTransform:s?Vs(r):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=L.fontPaths;this._objects.forEach(function n(o){t.push(o),_r(o)&&o._objects.forEach(n)}),t.forEach(n=>{if(!Lo(n))return;const{styles:o,fontFamily:a}=n;!e[a]&&s[a]&&(e[a]=!0,o&&Object.values(o).forEach(c=>{Object.values(c).forEach(h=>{let{fontFamily:l=""}=h;!e[l]&&s[l]&&(e[l]=!0)})}))});const r=Object.keys(e).map(n=>` @font-face {
|
|
14
14
|
font-family: '`.concat(n,`';
|
|
15
15
|
src: url('`).concat(s[n],`');
|
|
16
16
|
}
|
|
17
|
-
`)).join("");return
|
|
18
|
-
`.concat(
|
|
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
|
|
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(xt(s)){const r=s.repeat||"",n=this.width,o=this.height,a=this["".concat(e,"Vpt")]?Vs(Tt(this.viewportTransform)):"";t.push('<rect transform="'.concat(a," translate(").concat(n/2,",").concat(o/2,')" x="').concat(s.offsetX-n/2,'" y="').concat(s.offsetY-o/2,'" width="').concat(r!=="repeat-y"&&r!=="no-repeat"||!Ao(s)?n:s.source.width,'" height="').concat(r!=="repeat-x"&&r!=="no-repeat"||!Ao(s)?o:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
|
|
20
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 Yt("`json` is undefined"));const
|
|
21
|
+
`)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new Yt("`json` is undefined"));const r=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:o,background:a,overlayImage:c,overlay:h,clipPath:l}=r,u=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([rs(n,{reviver:e,signal:s}),Ys({backgroundImage:o,backgroundColor:a,overlayImage:c,overlayColor:h,clipPath:l},{signal:s})]).then(d=>{let[f,g]=d;return this.clear(),this.add(...f),this.set(r),this.set(g),this.renderOnAddRemove=u,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=tt();return t.width=this.width,t.height=this.height,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:n=!1}=t,o=r*(n?this.getRetinaScaling():1);return Bi(this.toCanvasElement(o,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:r,top:n,filter:o}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const a=(e||this.width)*t,c=(s||this.height)*t,h=this.getZoom(),l=this.width,u=this.height,d=this.skipControlsDrawing,f=h*t,g=this.viewportTransform,p=[f,0,0,f,(g[4]-(r||0))*t,(g[5]-(n||0))*t],m=this.enableRetinaScaling,b=tt(),T=o?this._objects.filter(w=>o(w)):this._objects;return b.width=a,b.height=c,this.enableRetinaScaling=!1,this.viewportTransform=p,this.width=a,this.height=c,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(b.getContext("2d"),T),this.viewportTransform=g,this.width=l,this.height=u,this.calcViewportBoundaries(),this.enableRetinaScaling=m,this.skipControlsDrawing=d,b}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),br.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," }>")}}v(Us,"ownDefaults",Xl);const zl=["touchstart","touchmove","touchend"],zo=i=>{const t=Fo(i.target),e=function(s){const r=s.changedTouches;return r&&r[0]?r[0]:s}(i);return new _(e.clientX+t.left,e.clientY+t.top)},wr=i=>zl.includes(i.type)||i.pointerType==="touch",Vi=i=>{i.preventDefault(),i.stopPropagation()},Gt=i=>{if(i.length===0)return{left:0,top:0,width:0,height:0};const{min:t,max:e}=i.reduce((r,n)=>{let{min:o,max:a}=r;return{min:o.min(n),max:a.max(n)}},{min:new _(i[0]),max:new _(i[0])}),s=e.subtract(t);return{left:t.x,top:t.y,width:s.x,height:s.y}},Hl=["translateX","translateY","scaleX","scaleY"],Ho=(i,t)=>is(i,Z(t,i.calcOwnMatrix())),is=(i,t)=>{const e=ts(t),{translateX:s,translateY:r,scaleX:n,scaleY:o}=e,a=U(e,Hl),c=new _(s,r);i.flipX=!1,i.flipY=!1,Object.assign(i,a),i.set({scaleX:n,scaleY:o}),i.setPositionByOrigin(c,E,E)},Yo=i=>{i.scaleX=1,i.scaleY=1,i.skewX=0,i.skewY=0,i.flipX=!1,i.flipY=!1,i.rotate(0)},Gi=i=>({scaleX:i.scaleX,scaleY:i.scaleY,skewX:i.skewX,skewY:i.skewY,angle:i.angle,left:i.left,flipX:i.flipX,flipY:i.flipY,top:i.top}),Cr=(i,t,e)=>{const s=i/2,r=t/2,n=[new _(-s,-r),new _(s,-r),new _(-s,r),new _(s,r)].map(a=>a.transform(e)),o=Gt(n);return new _(o.width,o.height)},$s=function(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:ut;return Z(Tt(arguments.length>1&&arguments[1]!==void 0?arguments[1]:ut),i)},ee=function(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ut,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ut;return i.transform($s(t,e))},Vo=function(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ut,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ut;return i.transform($s(t,e),!0)},Ni=(i,t,e)=>{const s=$s(t,e);return is(i,Z(s,i.calcOwnMatrix())),s},Ui=(i,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(i),y(y({},t),{},{target:s})),s.fire(i,t)},Yl={left:-.5,top:-.5,center:0,bottom:.5,right:.5},rt=i=>typeof i=="string"?Yl[i]:i-.5,Or="not-allowed";function Go(i){return rt(i.originX)===rt(E)&&rt(i.originY)===rt(E)}function No(i){return .5-rt(i)}const Pt=(i,t)=>i[t],$i=(i,t,e,s)=>({e:i,transform:t,pointer:new _(e,s)});function Uo(i,t){const e=i.getTotalAngle()+be(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function kr(i,t,e,s,r){var n;let{target:o,corner:a}=i;const c=o.controls[a],h=((n=o.canvas)===null||n===void 0?void 0:n.getZoom())||1,l=o.padding/h,u=function(d,f,g,p){const m=d.getRelativeCenterPoint(),b=g!==void 0&&p!==void 0?d.translateToGivenOrigin(m,E,E,g,p):new _(d.left,d.top);return(d.angle?f.rotate(-K(d.angle),m):f).subtract(b)}(o,new _(s,r),t,e);return u.x>=l&&(u.x-=l),u.x<=-l&&(u.x+=l),u.y>=l&&(u.y-=l),u.y<=l&&(u.y+=l),u.x-=c.offsetX,u.y-=c.offsetY,u}const $o=(i,t,e,s)=>{const{target:r,offsetX:n,offsetY:o}=t,a=e-n,c=s-o,h=!Pt(r,"lockMovementX")&&r.left!==a,l=!Pt(r,"lockMovementY")&&r.top!==c;return h&&r.set(R,a),l&&r.set(mt,c),(h||l)&&Ui(mo,$i(i,t,e,s)),h||l};class qo{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",r=this.strokeDashArray?this.strokeDashArray.join(" "):vt,n=this.strokeDashOffset?this.strokeDashOffset:"0",o=this.strokeLineCap?this.strokeLineCap:"butt",a=this.strokeLineJoin?this.strokeLineJoin:"miter",c=this.strokeMiterLimit?this.strokeMiterLimit:"4",h=this.opacity!==void 0?this.opacity:"1",l=this.visible?"":" visibility: hidden;",u=t?"":this.getSvgFilter(),d=Gs(st,this.fill);return[Gs(yt,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",r,"; ","stroke-linecap: ",o,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",a,"; ","stroke-miterlimit: ",c,"; ",d,"fill-rule: ",e,"; ","opacity: ",h,";",u,l].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(Vs(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(""),n=t.indexOf("COMMON_PARTS");return t[n]=r,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:r,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=e?"":'style="'.concat(this.getSvgStyles(),'" '),a=r?'style="'.concat(this.getSvgFilter(),'" '):"",c=this.clipPath,h=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",l=c&&c.absolutePositioned,u=this.stroke,d=this.fill,f=this.shadow,g=[],p=t.indexOf("COMMON_PARTS");let m;c&&(c.clipPathId="CLIPPATH_".concat(ye()),m='<clipPath id="'.concat(c.clipPathId,`" >
|
|
22
22
|
`).concat(c.toClipPathSVG(s),`</clipPath>
|
|
23
|
-
`)),l&&
|
|
24
|
-
`),
|
|
25
|
-
`);const b=[o,h,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[p]=b,
|
|
26
|
-
`),l&&
|
|
27
|
-
`),s?s(f.join("")):f.join("")}addPaintOrder(){return this.paintFirst!==st?' paint-order="'.concat(this.paintFirst,'" '):""}}function Ci(r){return new RegExp("^("+r.join("|")+")\\b","i")}var ea;const Fe=String.raw(ea||(ea=pe(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),ql=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Fe+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Fe+"))?\\s+(.*)"),Kl={cx:L,x:L,r:"radius",cy:mt,y:mt,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"},Kr="font-size",Jr="clip-path";Ci(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Ci(["symbol","image","marker","pattern","view","svg"]);const sa=Ci(["symbol","g","a","svg","clipPath","defs"]),Jl=new _(1,0),ia=new _,Zr=(r,t)=>r.rotate(t),Oi=(r,t)=>new _(t).subtract(r),ki=r=>r.distanceFrom(ia),Mi=(r,t)=>Math.atan2(ns(r,t),na(r,t)),ra=r=>Mi(Jl,r),Di=r=>r.eq(ia)?r:r.scalarDivide(ki(r)),Qr=function(r){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Di(new _(-r.y,r.x).scalarMultiply(t?1:-1))},ns=(r,t)=>r.x*t.y-r.y*t.x,na=(r,t)=>r.x*t.x+r.y*t.y,tn=(r,t,e)=>{if(r.eq(t)||r.eq(e))return!0;const s=ns(t,e),i=ns(t,r),n=ns(e,r);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},oa="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",aa=new RegExp("(?:\\s|^)"+oa+oa+"("+Fe+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Qt{constructor(t){const e=typeof t=="string"?Qt.parseShadow(t):t;Object.assign(this,Qt.ownDefaults,e),this.id=be()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(aa.exec(e)||[]).map(o=>parseFloat(o)||0);return{color:(e.replace(aa,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:i,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Zr(new _(this.offsetX,this.offsetY),$(-t.angle)),s=new R(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*G((Math.abs(e.x)+this.blur)/t.width,A.NUM_FRACTION_DIGITS)+20,n=100*G((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(n,'%" height="').concat(100+2*n,'%" x="-').concat(i,'%" width="').concat(100+2*i,`%" >
|
|
28
|
-
<feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(
|
|
29
|
-
<feOffset dx="`).concat(
|
|
23
|
+
`)),l&&g.push("<g ",a,this.getSvgCommons(),` >
|
|
24
|
+
`),g.push("<g ",this.getSvgTransform(!1),l?"":a+this.getSvgCommons(),` >
|
|
25
|
+
`);const b=[o,h,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[p]=b,xt(d)&&g.push(d.toSVG(this)),xt(u)&&g.push(u.toSVG(this)),f&&g.push(f.toSVG(this)),c&&g.push(m),g.push(t.join("")),g.push(`</g>
|
|
26
|
+
`),l&&g.push(`</g>
|
|
27
|
+
`),s?s(g.join("")):g.join("")}addPaintOrder(){return this.paintFirst!==st?' paint-order="'.concat(this.paintFirst,'" '):""}}const qi=(i,t,e,s)=>(i<Math.abs(t)?(i=t,s=e/4):s=t===0&&i===0?e/te*Math.asin(1):e/te*Math.asin(t/i),{a:i,c:t,p:e,s}),Ko=(i,t,e,s,r)=>i*Math.pow(2,10*(s-=1))*Math.sin((s*r-t)*te/e),Zo=(i,t,e,s)=>-e*Math.cos(i/s*me)+e+t,Ki=(i,t,e,s)=>(i/=s)<1/2.75?e*(7.5625*i*i)+t:i<2/2.75?e*(7.5625*(i-=1.5/2.75)*i+.75)+t:i<2.5/2.75?e*(7.5625*(i-=2.25/2.75)*i+.9375)+t:e*(7.5625*(i-=2.625/2.75)*i+.984375)+t,Jo=(i,t,e,s)=>e-Ki(s-i,0,e,s)+t;var Vl=Object.freeze({__proto__:null,defaultEasing:Zo,easeInBack:function(i,t,e,s){let r=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(i/=s)*i*((r+1)*i-r)+t},easeInBounce:Jo,easeInCirc:(i,t,e,s)=>-e*(Math.sqrt(1-(i/=s)*i)-1)+t,easeInCubic:(i,t,e,s)=>e*(i/s)**3+t,easeInElastic:(i,t,e,s)=>{const r=e;let n=0;if(i===0)return t;if((i/=s)===1)return t+e;n||(n=.3*s);const{a:o,s:a,p:c}=qi(r,e,n,1.70158);return-Ko(o,a,c,i,s)+t},easeInExpo:(i,t,e,s)=>i===0?t:e*2**(10*(i/s-1))+t,easeInOutBack:function(i,t,e,s){let r=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(i/=s/2)<1?e/2*(i*i*((1+(r*=1.525))*i-r))+t:e/2*((i-=2)*i*((1+(r*=1.525))*i+r)+2)+t},easeInOutBounce:(i,t,e,s)=>i<s/2?.5*Jo(2*i,0,e,s)+t:.5*Ki(2*i-s,0,e,s)+.5*e+t,easeInOutCirc:(i,t,e,s)=>(i/=s/2)<1?-e/2*(Math.sqrt(1-i**2)-1)+t:e/2*(Math.sqrt(1-(i-=2)*i)+1)+t,easeInOutCubic:(i,t,e,s)=>(i/=s/2)<1?e/2*i**3+t:e/2*((i-2)**3+2)+t,easeInOutElastic:(i,t,e,s)=>{const r=e;let n=0;if(i===0)return t;if((i/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:o,s:a,p:c,c:h}=qi(r,e,n,1.70158);return i<1?-.5*Ko(o,a,c,i,s)+t:o*Math.pow(2,-10*(i-=1))*Math.sin((i*s-a)*te/c)*.5+h+t},easeInOutExpo:(i,t,e,s)=>i===0?t:i===s?t+e:(i/=s/2)<1?e/2*2**(10*(i-1))+t:e/2*-(2**(-10*--i)+2)+t,easeInOutQuad:(i,t,e,s)=>(i/=s/2)<1?e/2*i**2+t:-e/2*(--i*(i-2)-1)+t,easeInOutQuart:(i,t,e,s)=>(i/=s/2)<1?e/2*i**4+t:-e/2*((i-=2)*i**3-2)+t,easeInOutQuint:(i,t,e,s)=>(i/=s/2)<1?e/2*i**5+t:e/2*((i-2)**5+2)+t,easeInOutSine:(i,t,e,s)=>-e/2*(Math.cos(Math.PI*i/s)-1)+t,easeInQuad:(i,t,e,s)=>e*(i/=s)*i+t,easeInQuart:(i,t,e,s)=>e*(i/=s)*i**3+t,easeInQuint:(i,t,e,s)=>e*(i/s)**5+t,easeInSine:(i,t,e,s)=>-e*Math.cos(i/s*me)+e+t,easeOutBack:function(i,t,e,s){let r=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((i=i/s-1)*i*((r+1)*i+r)+1)+t},easeOutBounce:Ki,easeOutCirc:(i,t,e,s)=>e*Math.sqrt(1-(i=i/s-1)*i)+t,easeOutCubic:(i,t,e,s)=>e*((i/s-1)**3+1)+t,easeOutElastic:(i,t,e,s)=>{const r=e;let n=0;if(i===0)return t;if((i/=s)===1)return t+e;n||(n=.3*s);const{a:o,s:a,p:c,c:h}=qi(r,e,n,1.70158);return o*2**(-10*i)*Math.sin((i*s-a)*te/c)+h+t},easeOutExpo:(i,t,e,s)=>i===s?t+e:e*-(2**(-10*i/s)+1)+t,easeOutQuad:(i,t,e,s)=>-e*(i/=s)*(i-2)+t,easeOutQuart:(i,t,e,s)=>-e*((i=i/s-1)*i**3-1)+t,easeOutQuint:(i,t,e,s)=>e*((i/s-1)**5+1)+t,easeOutSine:(i,t,e,s)=>e*Math.sin(i/s*me)+t});const Gl=()=>!1;class Zi{constructor(t){let{startValue:e,byValue:s,duration:r=500,delay:n=0,easing:o=Zo,onStart:a=De,onChange:c=De,onComplete:h=De,abort:l=Gl,target:u}=t;v(this,"_state","pending"),v(this,"durationProgress",0),v(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=r,this.delay=n,this.easing=o,this._onStart=a,this._onChange=c,this._onComplete=h,this._abort=l,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(()=>Xs(t),this.delay):Xs(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:n}=this.calculate(s);this.value=Object.freeze(r),this.valueProgress=n,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),Xs(this.tick)))}register(){br.push(this)}unregister(){br.remove(this)}abort(){this._state="aborted",this.unregister()}}const Nl=["startValue","endValue"];class Ul extends Zi{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(y(y({},U(t,Nl)),{},{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 $l=["startValue","endValue"];class ql extends Zi{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(y(y({},U(t,$l)),{},{startValue:e,byValue:s.map((r,n)=>r-e[n])}))}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 Ae=(i,t,e)=>Math.max(i,Math.min(t,e)),Kl=["startValue","endValue","easing","onChange","onComplete","abort"],Zl=(i,t,e,s)=>t+e*(1-Math.cos(i/s*me)),Ji=i=>i&&((t,e,s)=>i(new B(t).toRgba(),e,s));class Jl extends Zi{constructor(t){let{startValue:e,endValue:s,easing:r=Zl,onChange:n,onComplete:o,abort:a}=t,c=U(t,Kl);const h=new B(e).getSource(),l=new B(s).getSource();super(y(y({},c),{},{startValue:h,byValue:l.map((u,d)=>u-h[d]),easing:r,onChange:Ji(n),onComplete:Ji(o),abort:Ji(a)}))}calculate(t){const[e,s,r,n]=this.startValue.map((a,c)=>this.easing(t,a,this.byValue[c],this.duration,c)),o=[...[e,s,r].map(Math.round),Ae(0,n,1)];return{value:o,valueProgress:o.map((a,c)=>this.byValue[c]!==0?Math.abs((a-this.startValue[c])/this.byValue[c]):0).find(a=>a!==0)||0}}}function Qi(i){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(i)?new ql(i):new Ul(i);return t.start(),t}function Qo(i){const t=new Jl(i);return t.start(),t}const Ql=new _(1,0),ta=new _,tn=(i,t)=>i.rotate(t),Mr=(i,t)=>new _(t).subtract(i),Dr=i=>i.distanceFrom(ta),Ir=(i,t)=>Math.atan2(ns(i,t),sa(i,t)),ea=i=>Ir(Ql,i),jr=i=>i.eq(ta)?i:i.scalarDivide(Dr(i)),en=function(i){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return jr(new _(-i.y,i.x).scalarMultiply(t?1:-1))},ns=(i,t)=>i.x*t.y-i.y*t.x,sa=(i,t)=>i.x*t.x+i.y*t.y,sn=(i,t,e)=>{if(i.eq(t)||i.eq(e))return!0;const s=ns(t,e),r=ns(t,i),n=ns(e,i);return s>=0?r>=0&&n<=0:!(r<=0&&n>=0)};class q{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 n=Mr(e,s),o=Mr(e,t).divide(n);return r?Math.abs(o.x)===Math.abs(o.y):o.x===o.y&&o.x>=0&&o.x<=1}}static isPointInPolygon(t,e){const s=new _(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let r=0;for(let n=0;n<e.length;n++){const o=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(o.includes(t))return!0;r+=+(o.status==="Intersection")}return r%2==1}static intersectLineLine(t,e,s,r){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],o=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const a=e.x-t.x,c=e.y-t.y,h=r.x-s.x,l=r.y-s.y,u=t.x-s.x,d=t.y-s.y,f=h*d-l*u,g=a*d-c*u,p=l*a-h*c;if(p!==0){const m=f/p,b=g/p;return(n||0<=m&&m<=1)&&(o||0<=b&&b<=1)?new q("Intersection").append(new _(t.x+m*a,t.y+m*c)):new q}if(f===0||g===0){const m=n||o||q.isPointContained(t,s,r)||q.isPointContained(e,s,r)||q.isPointContained(s,t,e)||q.isPointContained(r,t,e);return new q(m?"Coincident":void 0)}return new q("Parallel")}static intersectSegmentLine(t,e,s,r){return q.intersectLineLine(t,e,s,r,!1,!0)}static intersectSegmentSegment(t,e,s,r){return q.intersectLineLine(t,e,s,r,!1,!1)}static intersectLinePolygon(t,e,s){let r=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new q,o=s.length;for(let a,c,h,l=0;l<o;l++){if(a=s[l],c=s[(l+1)%o],h=q.intersectLineLine(t,e,a,c,r,!1),h.status==="Coincident")return h;n.append(...h.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return q.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new q,r=t.length,n=[];for(let o=0;o<r;o++){const a=t[o],c=t[(o+1)%r],h=q.intersectSegmentPolygon(a,c,e);h.status==="Coincident"?(n.push(h),s.append(a,c)):s.append(...h.points)}return n.length>0&&n.length===t.length?new q("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const r=e.min(s),n=e.max(s),o=new _(n.x,r.y),a=new _(r.x,n.y);return q.intersectPolygonPolygon(t,[r,o,n,a])}}class tu extends To{_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=y({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let r=s,n=0;this.strokeUniform&&(r=0,n=s);const o=e.width+r,a=e.height+r;let c;return c=e.skewX===0&&e.skewY===0?new _(o*e.scaleX,a*e.scaleY):Cr(o,a,zs(e)),c.scalarAdd(n)}translateToGivenOrigin(t,e,s,r,n){let o=t.x,a=t.y;const c=rt(r)-rt(e),h=rt(n)-rt(s);if(c||h){const l=this._getTransformedDimensions();o+=c*l.x,a+=h*l.y}return new _(o,a)}translateToCenterPoint(t,e,s){const r=this.translateToGivenOrigin(t,e,s,E,E);return this.angle?r.rotate(K(this.angle),t):r}translateToOriginPoint(t,e,s){const r=this.translateToGivenOrigin(t,E,E,e,s);return this.angle?r.rotate(K(this.angle),t):r}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ht(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new _(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),n=this.translateToOriginPoint(r,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),R,mt)}}class eu extends tu{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?ht(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=ht(t,Tt(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new _(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()),n=[t,e,s,r];if(this.group){const o=this.group.calcTransformMatrix();return n.map(a=>ht(a,o))}return n}intersectsWithRect(t,e){return q.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=q.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:n,height:o}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&r>=t.y&&r+o<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return q.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 Gt(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(dt,t),this._set(_t,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?be(Co(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||ut.concat()}calcACoords(){const t=ss({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),r=es(e,s),n=Z(r,t),o=this._getTransformedDimensions(),a=o.x/2,c=o.y/2;return{tl:ht({x:-a,y:-c},n),tr:ht({x:a,y:-c},n),bl:ht({x:-a,y:c},n),br:ht({x:a,y:c},n)}}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,rt(this.originX),rt(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((n,o)=>n===s[o])?r.value:(this.group&&(e=Z(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},n=ko(r);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new _(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}}class rn extends eu{isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||this.canvas===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e instanceof rn?e.parent:void 0,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,n=0;n<e.length;n++){if(r=e[n],r===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let o=0;o<s.length;o++){if(this===s[o])return{fork:[],otherFork:[t,...s.slice(0,o)],common:[this,...e]};if(r===s[o])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,o)],common:e.slice(n)}}}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(),n=e.otherFork.pop(),o=s._objects.indexOf(r),a=s._objects.indexOf(n);return o>-1&&o>a}}class ra extends rn{animate(t,e){return Object.entries(t).reduce((s,r)=>{let[n,o]=r;return s[n]=this._animate(n,o,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const r=t.split("."),n=this.constructor.colorProperties.includes(r[r.length-1]),{abort:o,startValue:a,onChange:c,onComplete:h}=s,l=y(y({},s),{},{target:this,startValue:a??r.reduce((u,d)=>u[d],this),endValue:e,abort:o==null?void 0:o.bind(this),onChange:(u,d,f)=>{r.reduce((g,p,m)=>(m===r.length-1&&(g[p]=u),g[p]),this),c&&c(u,d,f)},onComplete:(u,d,f)=>{this.setCoords(),h&&h(u,d,f)}});return n?Qo(l):Qi(l)}}function Er(i){return new RegExp("^("+i.join("|")+")\\b","i")}var ia,na;v(ra,"colorProperties",[st,yt,"backgroundColor"]);const os=String.raw(ia||(ia=Ht(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"])));String.raw(na||(na=Ht(["(?:s+,?s*|,s*|$)"],["(?:\\s+,?\\s*|,\\s*|$)"])));const su=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+os+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+os+"))?\\s+(.*)"),ru={cx:R,x:R,r:"radius",cy:mt,y:mt,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"},nn="font-size",on="clip-path";Er(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),Er(["symbol","image","marker","pattern","view","svg"]);const oa=Er(["symbol","g","a","svg","clipPath","defs"]),aa="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",ca=new RegExp("(?:\\s|^)"+aa+aa+"("+os+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class se{constructor(t){const e=typeof t=="string"?se.parseShadow(t):t;Object.assign(this,se.ownDefaults,e),this.id=ye()}static parseShadow(t){const e=t.trim(),[,s=0,r=0,n=0]=(ca.exec(e)||[]).map(o=>parseFloat(o)||0);return{color:(e.replace(ca,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:r,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=tn(new _(this.offsetX,this.offsetY),K(-t.angle)),s=new B(this.color);let r=40,n=40;return t.width&&t.height&&(r=100*P((Math.abs(e.x)+this.blur)/t.width,L.NUM_FRACTION_DIGITS)+20,n=100*P((Math.abs(e.y)+this.blur)/t.height,L.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(n,'%" height="').concat(100+2*n,'%" x="-').concat(r,'%" width="').concat(100+2*r,`%" >
|
|
28
|
+
<feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(P(this.blur?this.blur/2:0,L.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
|
|
29
|
+
<feOffset dx="`).concat(P(e.x,L.NUM_FRACTION_DIGITS),'" dy="').concat(P(e.y,L.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
|
|
30
30
|
<feFlood flood-color="`).concat(s.toRgb(),'" flood-opacity="').concat(s.getAlpha(),`"/>
|
|
31
31
|
<feComposite in2="oBlur" operator="in" />
|
|
32
32
|
<feMerge>
|
|
@@ -34,44 +34,44 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
34
34
|
<feMergeNode in="SourceGraphic"></feMergeNode>
|
|
35
35
|
</feMerge>
|
|
36
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=Qt.ownDefaults;return this.includeDefaultValues?t:Hr(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}v(Qt,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),v(Qt,"type","shadow"),w.setClass(Qt,"shadow");const Re=(r,t,e)=>Math.max(r,Math.min(t,e)),Zl=[mt,L,dt,Tt,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Je,Ze],te=[st,yt,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Ql={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:mt,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:st,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},en=(r,t,e,s)=>(r<Math.abs(t)?(r=t,s=e/4):s=t===0&&r===0?e/Jt*Math.asin(1):e/Jt*Math.asin(t/r),{a:r,c:t,p:e,s}),ca=(r,t,e,s,i)=>r*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Jt/e),ha=(r,t,e,s)=>-e*Math.cos(r/s*ve)+e+t,sn=(r,t,e,s)=>(r/=s)<1/2.75?e*(7.5625*r*r)+t:r<2/2.75?e*(7.5625*(r-=1.5/2.75)*r+.75)+t:r<2.5/2.75?e*(7.5625*(r-=2.25/2.75)*r+.9375)+t:e*(7.5625*(r-=2.625/2.75)*r+.984375)+t,la=(r,t,e,s)=>e-sn(s-r,0,e,s)+t;var tu=Object.freeze({__proto__:null,defaultEasing:ha,easeInBack:function(r,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(r/=s)*r*((i+1)*r-i)+t},easeInBounce:la,easeInCirc:(r,t,e,s)=>-e*(Math.sqrt(1-(r/=s)*r)-1)+t,easeInCubic:(r,t,e,s)=>e*(r/s)**3+t,easeInElastic:(r,t,e,s)=>{const i=e;let n=0;if(r===0)return t;if((r/=s)===1)return t+e;n||(n=.3*s);const{a:o,s:a,p:c}=en(i,e,n,1.70158);return-ca(o,a,c,r,s)+t},easeInExpo:(r,t,e,s)=>r===0?t:e*2**(10*(r/s-1))+t,easeInOutBack:function(r,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(r/=s/2)<1?e/2*(r*r*((1+(i*=1.525))*r-i))+t:e/2*((r-=2)*r*((1+(i*=1.525))*r+i)+2)+t},easeInOutBounce:(r,t,e,s)=>r<s/2?.5*la(2*r,0,e,s)+t:.5*sn(2*r-s,0,e,s)+.5*e+t,easeInOutCirc:(r,t,e,s)=>(r/=s/2)<1?-e/2*(Math.sqrt(1-r**2)-1)+t:e/2*(Math.sqrt(1-(r-=2)*r)+1)+t,easeInOutCubic:(r,t,e,s)=>(r/=s/2)<1?e/2*r**3+t:e/2*((r-2)**3+2)+t,easeInOutElastic:(r,t,e,s)=>{const i=e;let n=0;if(r===0)return t;if((r/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:o,s:a,p:c,c:h}=en(i,e,n,1.70158);return r<1?-.5*ca(o,a,c,r,s)+t:o*Math.pow(2,-10*(r-=1))*Math.sin((r*s-a)*Jt/c)*.5+h+t},easeInOutExpo:(r,t,e,s)=>r===0?t:r===s?t+e:(r/=s/2)<1?e/2*2**(10*(r-1))+t:e/2*-(2**(-10*--r)+2)+t,easeInOutQuad:(r,t,e,s)=>(r/=s/2)<1?e/2*r**2+t:-e/2*(--r*(r-2)-1)+t,easeInOutQuart:(r,t,e,s)=>(r/=s/2)<1?e/2*r**4+t:-e/2*((r-=2)*r**3-2)+t,easeInOutQuint:(r,t,e,s)=>(r/=s/2)<1?e/2*r**5+t:e/2*((r-2)**5+2)+t,easeInOutSine:(r,t,e,s)=>-e/2*(Math.cos(Math.PI*r/s)-1)+t,easeInQuad:(r,t,e,s)=>e*(r/=s)*r+t,easeInQuart:(r,t,e,s)=>e*(r/=s)*r**3+t,easeInQuint:(r,t,e,s)=>e*(r/s)**5+t,easeInSine:(r,t,e,s)=>-e*Math.cos(r/s*ve)+e+t,easeOutBack:function(r,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((r=r/s-1)*r*((i+1)*r+i)+1)+t},easeOutBounce:sn,easeOutCirc:(r,t,e,s)=>e*Math.sqrt(1-(r=r/s-1)*r)+t,easeOutCubic:(r,t,e,s)=>e*((r/s-1)**3+1)+t,easeOutElastic:(r,t,e,s)=>{const i=e;let n=0;if(r===0)return t;if((r/=s)===1)return t+e;n||(n=.3*s);const{a:o,s:a,p:c,c:h}=en(i,e,n,1.70158);return o*2**(-10*r)*Math.sin((r*s-a)*Jt/c)+h+t},easeOutExpo:(r,t,e,s)=>r===s?t+e:e*-(2**(-10*r/s)+1)+t,easeOutQuad:(r,t,e,s)=>-e*(r/=s)*(r-2)+t,easeOutQuart:(r,t,e,s)=>-e*((r=r/s-1)*r**3-1)+t,easeOutQuint:(r,t,e,s)=>e*((r/s-1)**5+1)+t,easeOutSine:(r,t,e,s)=>e*Math.sin(r/s*ve)+t});const eu=()=>!1;class rn{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:o=ha,onStart:a=Ee,onChange:c=Ee,onComplete:h=Ee,abort:l=eu,target:u}=t;v(this,"_state","pending"),v(this,"durationProgress",0),v(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=o,this._onStart=a,this._onChange=c,this._onComplete=h,this._abort=l,this.target=u,this.startValue=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(()=>Bs(t),this.delay):Bs(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:i,valueProgress:n}=this.calculate(s);this.value=Object.freeze(i),this.valueProgress=n,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),Bs(this.tick)))}register(){mi.push(this)}unregister(){mi.remove(this)}abort(){this._state="aborted",this.unregister()}}const su=["startValue","endValue"];class iu extends rn{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(y(y({},Y(t,su)),{},{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 ru=["startValue","endValue"];class nu extends rn{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(y(y({},Y(t,ru)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const ou=["startValue","endValue","easing","onChange","onComplete","abort"],au=(r,t,e,s)=>t+e*(1-Math.cos(r/s*ve)),nn=r=>r&&((t,e,s)=>r(new R(t).toRgba(),e,s));class cu extends rn{constructor(t){let{startValue:e,endValue:s,easing:i=au,onChange:n,onComplete:o,abort:a}=t,c=Y(t,ou);const h=new R(e).getSource(),l=new R(s).getSource();super(y(y({},c),{},{startValue:h,byValue:l.map((u,d)=>u-h[d]),easing:i,onChange:nn(n),onComplete:nn(o),abort:nn(a)}))}calculate(t){const[e,s,i,n]=this.startValue.map((a,c)=>this.easing(t,a,this.byValue[c],this.duration,c)),o=[...[e,s,i].map(Math.round),Re(0,n,1)];return{value:o,valueProgress:o.map((a,c)=>this.byValue[c]!==0?Math.abs((a-this.startValue[c])/this.byValue[c]):0).find(a=>a!==0)||0}}}function on(r){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(r)?new nu(r):new iu(r);return t.start(),t}function ua(r){const t=new cu(r);return t.start(),t}class U{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(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=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&&(i||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&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=Oi(e,s),o=Oi(e,t).divide(n);return i?Math.abs(o.x)===Math.abs(o.y):o.x===o.y&&o.x>=0&&o.x<=1}}static isPointInPolygon(t,e){const s=new _(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const o=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(o.includes(t))return!0;i+=+(o.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],o=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const a=e.x-t.x,c=e.y-t.y,h=i.x-s.x,l=i.y-s.y,u=t.x-s.x,d=t.y-s.y,g=h*d-l*u,f=a*d-c*u,p=l*a-h*c;if(p!==0){const m=g/p,b=f/p;return(n||0<=m&&m<=1)&&(o||0<=b&&b<=1)?new U("Intersection").append(new _(t.x+m*a,t.y+m*c)):new U}if(g===0||f===0){const m=n||o||U.isPointContained(t,s,i)||U.isPointContained(e,s,i)||U.isPointContained(s,t,e)||U.isPointContained(i,t,e);return new U(m?"Coincident":void 0)}return new U("Parallel")}static intersectSegmentLine(t,e,s,i){return U.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return U.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new U,o=s.length;for(let a,c,h,l=0;l<o;l++){if(a=s[l],c=s[(l+1)%o],h=U.intersectLineLine(t,e,a,c,i,!1),h.status==="Coincident")return h;n.append(...h.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return U.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new U,i=t.length,n=[];for(let o=0;o<i;o++){const a=t[o],c=t[(o+1)%i],h=U.intersectSegmentPolygon(a,c,e);h.status==="Coincident"?(n.push(h),s.append(a,c)):s.append(...h.points)}return n.length>0&&n.length===t.length?new U("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),o=new _(n.x,i.y),a=new _(i.x,n.y);return U.intersectPolygonPolygon(t,[i,o,n,a])}}class hu extends Oo{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?ht(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=ht(t,St(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new _(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:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const o=this.group.calcTransformMatrix();return n.map(a=>ht(a,o))}return n}intersectsWithRect(t,e){return U.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=U.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:i,width:n,height:o}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&i>=t.y&&i+o<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return U.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 Vt(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(dt,t),this._set(Tt,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?_e(Io(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||ut.concat()}calcACoords(){const t=ss({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=es(e,s),n=q(i,t),o=this._getTransformedDimensions(),a=o.x/2,c=o.y/2;return{tl:ht({x:-a,y:-c},n),tr:ht({x:a,y:-c},n),bl:ht({x:-a,y:c},n),br:ht({x:a,y:c},n)}}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,it(this.originX),it(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),i=this.matrixCache;return i&&i.key.every((n,o)=>n===s[o])?i.value:(this.group&&(e=q(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(),i={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},n=jo(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new _(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=y({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 i=s,n=0;this.strokeUniform&&(i=0,n=s);const o=e.width+i,a=e.height+i;let c;return c=e.skewX===0&&e.skewY===0?new _(o*e.scaleX,a*e.scaleY):Si(o,a,Ws(e)),c.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let o=t.x,a=t.y;const c=it(i)-it(e),h=it(n)-it(s);if(c||h){const l=this._getTransformedDimensions();o+=c*l.x,a+=h*l.y}return new _(o,a)}translateToCenterPoint(t,e,s){if(e===j&&s===j)return t;const i=this.translateToGivenOrigin(t,e,s,j,j);return this.angle?i.rotate($(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,j,j,e,s);return this.angle?i.rotate($(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ht(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new _(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),L,mt)}}const lu=["type"],uu=["extraParam"];let ee=class Ir extends hu{static getDefaults(){return Ir.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){me("warn","Setting type has no effect",t)}constructor(t){super(),v(this,"_cacheContext",null),Object.assign(this,Ir.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=tt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=A.maxCacheSideLimit,n=A.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=A.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const o=e/s,[a,c]=Fs.limitDimsByArea(o),h=Re(n,a,i),l=Re(n,c,i);return e>h&&(t.zoomX/=e/h,t.width=h,t.capped=!0),s>l&&(t.zoomY/=s/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:s+2,height:i+2,zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),i=A.minCacheSideLimit,n=s.width,o=s.height,a=s.zoomX,c=s.zoomY,h=n!==t.width||o!==t.height,l=this.zoomX!==a||this.zoomY!==c;if(!t||!e)return!1;let u,d,g=h||l,f=0,p=0,m=!1;if(h){const b=this._cacheCanvas.width,T=this._cacheCanvas.height,S=n>b||o>T;m=S||(n<.9*b||o<.9*T)&&b>i&&T>i,S&&!s.capped&&(n>i||o>i)&&(f=.1*n,p=.1*o)}return Xo(this)&&this.path&&(g=!0,m=!0,f+=this.getHeightOfLine(0)*this.zoomX,p+=this.getHeightOfLine(0)*this.zoomY),!!g&&(m?(t.width=Math.ceil(n+f),t.height=Math.ceil(o+p)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),u=s.x/2,d=s.y/2,this.cacheTranslationX=Math.round(t.width/2-u)+u,this.cacheTranslationY=Math.round(t.height/2-d)+d,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(a,c),this.zoomX=a,this.zoomY=c,!0)}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 _(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=ts(this.calcTransformMatrix());return new _(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!==dt&&t!==Tt||(e=this._constrainScale(e)),t===dt&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Qt||(e=new Qt(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),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===yt&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const s=St(this.calcTransformMatrix());t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const s=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),this.fill=s,this.stroke=i}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&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,Ct(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&&(Ct(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&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,o]=(s==null?void 0:s.viewportTransform)||ut,a=n*i,c=o*i,h=e.nonScaling?new _(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*A.browserShadowBlurConstant*(a+c)*(h.x+h.y)/4,t.shadowOffsetX=e.offsetX*a*h.x,t.shadowOffsetY=e.offsetY*c*h.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!Ct(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===yt?(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 i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=tt(),o=this.getCanvasRetinaScaling(),a=i.x/this.scaleX/o,c=i.y/this.scaleY/o;n.width=Math.ceil(a),n.height=Math.ceil(c);const h=n.getContext("2d");h&&(h.beginPath(),h.moveTo(0,0),h.lineTo(a,0),h.lineTo(a,c),h.lineTo(0,c),h.closePath(),h.translate(a/2,c/2),h.scale(i.zoomX/this.scaleX/o,i.zoomY/this.scaleY/o),this._applyPatternGradientTransform(h,e),h.fillStyle=e.toLive(t),h.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(o*this.scaleX/i.zoomX,o*this.scaleY/i.zoomY),t.strokeStyle=(s=h.createPattern(n,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new _(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(w.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Nr(this),s=this.group,i=this.shadow,n=Math.abs,o=t.enableRetinaScaling?_o():1,a=(t.multiplier||1)*o,c=t.canvasProvider||(T=>new Gs(T,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&$o(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Ur(this,this.getViewportTransform()),this.setCoords();const h=tt(),l=this.getBoundingRect(),u=this.shadow,d=new _;if(u){const T=u.blur,S=u.nonScaling?new _(1,1):this.getObjectScaling();d.x=2*Math.round(n(u.offsetX)+T)*n(S.x),d.y=2*Math.round(n(u.offsetY)+T)*n(S.y)}const g=l.width+d.x,f=l.height+d.y;h.width=Math.ceil(g),h.height=Math.ceil(f);const p=c(h);t.format==="jpeg"&&(p.backgroundColor="#fff"),this.setPositionByOrigin(new _(p.width/2,p.height/2),j,j);const m=this.canvas;p._objects=[this],this.set("canvas",p),this.setCoords();const b=p.toCanvasElement(a||1,t);return this.set("canvas",m),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),p._objects=[],p.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Wr(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:i}=this;if(e){const{x:n,y:o}=this.getRelativeCenterPoint();this.originX=j,this.originY=j,this.left=n,this.top=o}if(this.set("angle",t),e){const{x:n,y:o}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=o,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){mi.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&Gt().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,o]=i;return s[n]=this._animate(n,o,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:o,startValue:a,onChange:c,onComplete:h}=s,l=y(y({},s),{},{target:this,startValue:a??i.reduce((u,d)=>u[d],this),endValue:e,abort:o==null?void 0:o.bind(this),onChange:(u,d,g)=>{i.reduce((f,p,m)=>(m===i.length-1&&(f[p]=u),f[p]),this),c&&c(u,d,g)},onComplete:(u,d,g)=>{this.setCoords(),h&&h(u,d,g)}});return n?ua(l):on(l)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(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 i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let o=0;o<s.length;o++){if(this===s[o])return{fork:[],otherFork:[t,...s.slice(0,o)],common:[this,...e]};if(i===s[o])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,o)],common:e.slice(n)}}}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 i=e.fork.pop(),n=e.otherFork.pop(),o=s._objects.indexOf(i),a=s._objects.indexOf(n);return o>-1&&o>a}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Ir.customProperties,this.constructor.customProperties||[]);let e;const s=A.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:o,shadow:a,strokeDashArray:c,left:h,top:l,originX:u,originY:d,width:g,height:f,strokeWidth:p,strokeLineCap:m,strokeDashOffset:b,strokeLineJoin:T,strokeUniform:S,strokeMiterLimit:C,scaleX:O,scaleY:M,angle:I,flipX:D,flipY:F,opacity:N,visible:at,backgroundColor:et,fillRule:B,paintFirst:K,globalCompositeOperation:wt,skewX:_t,skewY:Ht}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const J=fe=>G(fe,s),Kt=y(y({},Pe(this,t)),{},{type:this.constructor.type,version:Er,originX:u,originY:d,left:J(h),top:J(l),width:J(g),height:J(f),fill:Bo(n)?n.toObject():n,stroke:Bo(o)?o.toObject():o,strokeWidth:J(p),strokeDashArray:c&&c.concat(),strokeLineCap:m,strokeDashOffset:b,strokeLineJoin:T,strokeUniform:S,strokeMiterLimit:J(C),scaleX:J(O),scaleY:J(M),angle:J(I),flipX:D,flipY:F,opacity:J(N),shadow:a&&a.toObject(),visible:at,backgroundColor:et,fillRule:B,paintFirst:K,globalCompositeOperation:wt,skewX:J(_t),skewY:J(Ht)},e?{clipPath:e}:null);return this.includeDefaultValues?Kt:this._removeDefaultValues(Kt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return Hr(t,(i,n)=>{if(n===L||n===mt||n==="type")return!0;const o=s[n];return i!==o&&!(Array.isArray(i)&&Array.isArray(o)&&i.length===0&&o.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Y(t,lu),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Y(s,uu);return zs(e,n).then(o=>i?(delete o[i],new this(e[i],o)):new this(o))}static fromObject(t,e){return this._fromObject(t,e)}};v(ee,"stateProperties",Zl),v(ee,"cacheProperties",te),v(ee,"ownDefaults",Ql),v(ee,"type","FabricObject"),v(ee,"colorProperties",[st,yt,"backgroundColor"]),v(ee,"customProperties",[]),w.setClass(ee),w.setClass(ee,"object");const Te=(r,t,e)=>(s,i,n,o)=>{const a=t(s,i,n,o);return a&&$r(r,y(y({},qr(s,i,n,o)),e)),a};function Be(r){return(t,e,s,i)=>{const{target:n,originX:o,originY:a}=e,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=r(t,e,s,i);return n.setPositionByOrigin(h,e.originX,e.originY),l}}const an=Te(Rs,Be((r,t,e,s)=>{const i=wi(t,t.originX,t.originY,e,s);if(it(t.originX)===it(j)||it(t.originX)===it(Q)&&i.x<0||it(t.originX)===it(L)&&i.x>0){const{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=Ko(t)?2:1,c=n.width,h=Math.ceil(Math.abs(i.x*a/n.scaleX)-o);return n.set("width",Math.max(h,0)),c!==n.width}return!1}));function da(r,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,o=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,c=a?yt:st,h=!a&&(s.cornerStrokeColor||i.cornerStrokeColor);let l,u=t,d=e;r.save(),r.fillStyle=s.cornerColor||i.cornerColor||"",r.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>o?(l=n,r.scale(1,o/n),d=e*n/o):o>n?(l=o,r.scale(n/o,1),u=t*o/n):l=n,r.lineWidth=1,r.beginPath(),r.arc(u,d,l/2,0,Jt,!1),r[c](),h&&r.stroke(),r.restore()}function ga(r,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,o=this.sizeY||s.cornerSize||i.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,c=a?yt:st,h=!a&&(s.cornerStrokeColor||i.cornerStrokeColor),l=n/2,u=o/2;r.save(),r.fillStyle=s.cornerColor||i.cornerColor||"",r.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",r.lineWidth=1,r.translate(t,e);const d=i.getTotalAngle();r.rotate($(d)),r["".concat(c,"Rect")](-l,-u,n,o),h&&r.strokeRect(-l,-u,n,o),r.restore()}class V{constructor(t){v(this,"visible",!0),v(this,"actionName",fi),v(this,"angle",0),v(this,"x",0),v(this,"y",0),v(this,"offsetX",0),v(this,"offsetY",0),v(this,"sizeX",0),v(this,"sizeY",0),v(this,"touchSizeX",0),v(this,"touchSizeY",0),v(this,"cursorStyle","crosshair"),v(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:o,tr:a,br:c,bl:h}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&U.isPointInPolygon(s,[o,a,c,h])}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,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new _(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,o){const a=yi([es(s,i),ss({angle:t}),bi((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new _(-.5,-.5).transform(a),tr:new _(.5,-.5).transform(a),br:new _(.5,.5).transform(a),bl:new _(-.5,.5).transform(a)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?da.call(this,t,e,s,i,n):ga.call(this,t,e,s,i,n)}}const fa=(r,t,e)=>e.lockRotation?xi:t.cursorStyle,pa=Te(So,Be((r,t,e,s)=>{let{target:i,ex:n,ey:o,theta:a,originX:c,originY:h}=t;const l=i.translateToOriginPoint(i.getRelativeCenterPoint(),c,h);if(Pt(i,"lockRotation"))return!1;const u=Math.atan2(o-l.y,n-l.x),d=Math.atan2(s-l.y,e-l.x);let g=_e(d-u+a);if(i.snapAngle&&i.snapAngle>0){const p=i.snapAngle,m=i.snapThreshold||p,b=Math.ceil(g/p)*p,T=Math.floor(g/p)*p;Math.abs(g-T)<m?g=T:Math.abs(g-b)<m&&(g=b)}g<0&&(g=360+g),g%=360;const f=i.angle!==g;return i.angle=g,f}));function ma(r,t){const e=t.canvas,s=r[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function va(r,t,e){const s=Pt(r,"lockScalingX"),i=Pt(r,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:o,strokeWidth:a}=r;return n===0&&a===0&&t!=="y"||o===0&&a===0&&t!=="x"}const du=["e","se","s","sw","w","nw","n","ne","e"],os=(r,t,e)=>{const s=ma(r,e);if(va(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return xi;const i=Zo(e,t);return"".concat(du[i],"-resize")};function cn(r,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,o=i.by,a=ma(r,n);let c,h,l,u,d,g;if(va(n,o,a))return!1;if(t.gestureScale)h=t.scaleX*t.gestureScale,l=t.scaleY*t.gestureScale;else{if(c=wi(t,t.originX,t.originY,e,s),d=o!=="y"?Math.sign(c.x||t.signX||1):1,g=o!=="x"?Math.sign(c.y||t.signY||1):1,t.signX||(t.signX=d),t.signY||(t.signY=g),Pt(n,"lockScalingFlip")&&(t.signX!==d||t.signY!==g))return!1;if(u=n._getTransformedDimensions(),a&&!o){const m=Math.abs(c.x)+Math.abs(c.y),{original:b}=t,T=m/(Math.abs(u.x*b.scaleX/n.scaleX)+Math.abs(u.y*b.scaleY/n.scaleY));h=b.scaleX*T,l=b.scaleY*T}else h=Math.abs(c.x*n.scaleX/u.x),l=Math.abs(c.y*n.scaleY/u.y);Ko(t)&&(h*=2,l*=2),t.signX!==d&&o!=="y"&&(t.originX=Jo(t.originX),h*=-1,t.signX=d),t.signY!==g&&o!=="x"&&(t.originY=Jo(t.originY),l*=-1,t.signY=g)}const f=n.scaleX,p=n.scaleY;return o?(o==="x"&&n.set(dt,h),o==="y"&&n.set(Tt,l)):(!Pt(n,"lockScalingX")&&n.set(dt,h),!Pt(n,"lockScalingY")&&n.set(Tt,l)),f!==n.scaleX||p!==n.scaleY}const Ns=Te(di,Be((r,t,e,s)=>cn(r,t,e,s))),ya=Te(di,Be((r,t,e,s)=>cn(r,t,e,s,{by:"x"}))),ba=Te(di,Be((r,t,e,s)=>cn(r,t,e,s,{by:"y"}))),gu=["target","ex","ey","skewingSide"],hn={x:{counterAxis:"y",scale:dt,skew:Je,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Tt,skew:Ze,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},fu=["ns","nesw","ew","nwse"],_a=(r,t,e)=>{if(t.x!==0&&Pt(e,"lockSkewingY")||t.y!==0&&Pt(e,"lockSkewingX"))return xi;const s=Zo(e,t)%4;return"".concat(fu[s],"-resize")};function Ta(r,t,e,s,i){const{target:n}=e,{counterAxis:o,origin:a,lockSkewing:c,skew:h,flip:l}=hn[r];if(Pt(n,c))return!1;const{origin:u,flip:d}=hn[o],g=it(e[u])*(n[d]?-1:1),f=-Math.sign(g)*(n[l]?-1:1),p=.5*-((n[h]===0&&wi(e,j,j,s,i)[r]>0||n[h]>0?1:-1)*f)+.5;return Te(xo,Be((b,T,S,C)=>function(O,M,I){let{target:D,ex:F,ey:N,skewingSide:at}=M,et=Y(M,gu);const{skew:B}=hn[O],K=I.subtract(new _(F,N)).divide(new _(D.scaleX,D.scaleY))[O],wt=D[B],_t=et[B],Ht=Math.tan($(_t)),J=O==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,Kt=2*K*at/Math.max(J,1)+Ht,fe=_e(Math.atan(Kt));D.set(B,fe);const Mr=wt!==D[B];if(Mr&&O==="y"){const{skewX:fo,scaleX:hi}=D,De=D._getTransformedDimensions({skewY:wt}),Dr=D._getTransformedDimensions(),qe=fo!==0?De.x/Dr.x:1;qe!==1&&D.set(dt,qe*hi)}return Mr}(r,T,new _(S,C))))(t,y(y({},e),{},{[a]:p,skewingSide:f}),s,i)}const Sa=(r,t,e,s)=>Ta("x",r,t,e,s),xa=(r,t,e,s)=>Ta("y",r,t,e,s);function Ii(r,t){return r[t.canvas.altActionKey]}const Us=(r,t,e)=>{const s=Ii(r,e);return t.x===0?s?Je:Tt:t.y===0?s?Ze:dt:""},We=(r,t,e)=>Ii(r,e)?_a(0,t,e):os(r,t,e),ln=(r,t,e,s)=>Ii(r,t.target)?xa(r,t,e,s):ya(r,t,e,s),un=(r,t,e,s)=>Ii(r,t.target)?Sa(r,t,e,s):ba(r,t,e,s),dn=()=>({ml:new V({x:-.5,y:0,cursorStyleHandler:We,actionHandler:ln,getActionName:Us}),mr:new V({x:.5,y:0,cursorStyleHandler:We,actionHandler:ln,getActionName:Us}),mb:new V({x:0,y:.5,cursorStyleHandler:We,actionHandler:un,getActionName:Us}),mt:new V({x:0,y:-.5,cursorStyleHandler:We,actionHandler:un,getActionName:Us}),tl:new V({x:-.5,y:-.5,cursorStyleHandler:os,actionHandler:Ns}),tr:new V({x:.5,y:-.5,cursorStyleHandler:os,actionHandler:Ns}),bl:new V({x:-.5,y:.5,cursorStyleHandler:os,actionHandler:Ns}),br:new V({x:.5,y:.5,cursorStyleHandler:os,actionHandler:Ns}),mtr:new V({x:0,y:-.5,actionHandler:pa,cursorStyleHandler:fa,offsetY:-40,withConnection:!0,actionName:Fr})}),wa=()=>({mr:new V({x:.5,y:0,actionHandler:an,cursorStyleHandler:We,actionName:Rs}),ml:new V({x:-.5,y:0,actionHandler:an,cursorStyleHandler:We,actionName:Rs})}),Ca=()=>y(y({},dn()),wa());class $s extends ee{static getDefaults(){return y(y({},super.getDefaults()),$s.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),$s.ownDefaults),this.setOptions(t)}static createControls(){return{controls:dn()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(fi))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 i=s.length-1;i>=0;i--){const[n,o]=s[i],a=this.controls[n];if(a.shouldActivate(n,this,t,e?o.touchCorner:o.corner))return this.__corner=n,{key:n,control:a,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=es(e.x,e.y),i=ss({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=q(s,i),o=q(t,n),a=q(o,[1/t[0],0,0,1/t[3],0,0]),c=this.group?ts(this.calcTransformMatrix()):void 0;c&&(c.scaleX=Math.abs(c.scaleX),c.scaleY=Math.abs(c.scaleY));const h=this._calculateCurrentDimensions(c),l={};return this.forEachControl((u,d)=>{const g=u.positionHandler(h,a,this,u);l[d]=Object.assign(g,this._calcCornerCoords(u,g))}),l}_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(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate($(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 i=y({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=y({hasBorders:s,hasControls:i},e),o=this.getViewportTransform(),a=n.hasBorders,c=n.hasControls,h=q(o,this.calcTransformMatrix()),l=ts(h);t.save(),t.translate(l.translateX,l.translateY),t.lineWidth=1*this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(l.angle-=180),t.rotate($(this.group?l.angle:this.angle)),a&&this.drawBorders(t,l,e),c&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Si(this.width,this.height,Ws(e)),o=this.isStrokeAccountedForInDimensions()?Br:(this.strokeUniform?new _().scalarAdd(this.canvas?this.canvas.getZoom():1):new _(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(o).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:o}=this,a=y({cornerStrokeColor:i,cornerDashArray:n,cornerColor:o},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((c,h)=>{if(c.getVisibility(this,h)){const l=this.oCoords[h];c.render(t,l.x,l.y,a,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}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 i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),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 Oa(r,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(r.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),r}v($s,"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 ct extends $s{}Oa(ct,[ta]),w.setClass(ct),w.setClass(ct,"object");const ka=(r,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=r.getImageData(t-s,e-s,i,i);for(let o=3;o<n.length;o+=4)if(n[o]>0)return!1;return!0};class Ma{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new _(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new _(1/this.options.scaleX,1/this.options.scaleY):new _(1,1)}createSideVector(t,e){const s=Oi(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 _(t);return e.y+=e.x*Math.tan($(this.options.skewY)),e.x+=e.y*Math.tan($(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const pu=new _;class as extends Ma{static getOrthogonalRotationFactor(t,e){const s=e?Mi(t,e):ra(t);return Math.abs(s)<ve?-1:1}constructor(t,e,s,i){super(i),v(this,"AB",void 0),v(this,"AC",void 0),v(this,"alpha",void 0),v(this,"bisector",void 0),this.A=new _(t),this.B=new _(e),this.C=new _(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Mi(this.AB,this.AC),this.bisector=Di(Zr(this.AB.eq(pu)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),n=Qr(i),o=as.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*o)}projectBevel(){const t=[];return(this.alpha%Jt==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),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?ki(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return ki(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new _(as.getOrthogonalRotationFactor(this.bisector),as.getOrthogonalRotationFactor(new _(this.bisector.y,this.bisector.x)));return[new _(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new _(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{tn(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:o,scaleY:a,strokeUniform:c}=this.options,h=new _(Math.tan($(i)),Math.tan($(n))),l=this.strokeProjectionMagnitude,u=c?l/a/Math.sqrt(1/a**2+1/o**2*h.y**2):l/Math.sqrt(1+h.y**2),d=new _(Math.sqrt(Math.max(l**2-u**2,0)),u),g=c?l/Math.sqrt(1+h.x**2*(1/a)**2/(1/o+1/o*h.x*h.y)**2):l/Math.sqrt(1+h.x**2/(1+h.x*h.y)**2),f=new _(g,Math.sqrt(Math.max(l**2-g**2,0)));return[f,f.scalarMultiply(-1),d,d.scalarMultiply(-1)].map(p=>this.applySkew(c?p.multiply(this.strokeUniformScalar):p)).forEach(p=>{tn(p,t,e)&&s.push(this.applySkew(this.A).add(p))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Jt==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),o=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),a=ns(i,o)>0,c=a?i:n,h=a?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(c,h)):t.push(...this.projectRoundNoSkew(c,h)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Da extends Ma{constructor(t,e,s){super(s),this.A=new _(t),this.T=new _(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(Qr(i),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 _(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 as(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new _(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(Di(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.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 Ia=function(r,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(r.length===0)return s;const i=r.reduce((n,o)=>(n[n.length-1].eq(o)||n.push(new _(o)),n),[new _(r[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],o=((a,c)=>{for(let h=a.length-1;h>=0;h--)if(c(a[h],h,a))return h;return-1})(i,a=>!a.eq(n));i.splice(o+1)}return i.forEach((n,o,a)=>{let c,h;o===0?(h=a[1],c=e?n:a[a.length-1]):o===a.length-1?(c=a[o-1],h=e?n:a[0]):(c=a[o-1],h=a[o+1]),e&&a.length===1?s.push(...new Da(n,n,t).project()):!e||o!==0&&o!==a.length-1?s.push(...new as(n,c,h,t).project()):s.push(...new Da(n,o===0?h:c,t).project())}),s},gn=r=>{const t={};return Object.keys(r).forEach(e=>{t[e]={},Object.keys(r[e]).forEach(s=>{t[e][s]=y({},r[e][s])})}),t},Ea=r=>r.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Ei=r=>{const t=[];for(let e,s=0;s<r.length;s++)(e=mu(r,s))!==!1&&t.push(e);return t},mu=(r,t)=>{const e=r.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return r.charAt(t);if(55296<=e&&e<=56319){if(r.length<=t+1)throw"High surrogate without following low surrogate";const i=r.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return r.charAt(t)+r.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=r.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var vu=Object.freeze({__proto__:null,capitalize:function(r){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(r.charAt(0).toUpperCase()).concat(t?r.slice(1):r.slice(1).toLowerCase())},escapeXml:Ea,graphemeSplit:Ei});const ji=function(r,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return r.fill!==t.fill||r.stroke!==t.stroke||r.strokeWidth!==t.strokeWidth||r.fontSize!==t.fontSize||r.fontFamily!==t.fontFamily||r.fontWeight!==t.fontWeight||r.fontStyle!==t.fontStyle||r.textBackgroundColor!==t.textBackgroundColor||r.deltaY!==t.deltaY||e&&(r.overline!==t.overline||r.underline!==t.underline||r.linethrough!==t.linethrough)},ja=(r,t)=>{const e=t.split(`
|
|
38
|
-
`),s=[];let
|
|
39
|
-
`)]}static async fromElement(t,e,s){const i=se(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:o=0,width:a=0,height:c=0,visible:h=!0}=i,l=Y(i,Bu);return new this(y(y(y({},e),l),{},{left:n,top:o,width:a,height:c,visible:!!(h&&a&&c)}))}}v(z,"type","Rect"),v(z,"cacheProperties",[...te,...Ha]),v(z,"ownDefaults",{rx:0,ry:0}),v(z,"ATTRIBUTE_NAMES",[...Se,"x","y","rx","ry","width","height"]),w.setClass(z),w.setSVGClass(z);const ie="initialization",Pi="added",mn="removed",Ai="imperative",Ya=(r,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:o}=t,a=o&&o!==r?Vs(o.calcTransformMatrix(),r.calcTransformMatrix()):null,c=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),h=!t.isStrokeAccountedForInDimensions(),l=e&&h?qo(new _(s,s),void 0,r.calcTransformMatrix()):Br,u=!e&&h?s:0,d=Si(i+u,n+u,yi([a,t.calcOwnMatrix()],!0)).add(l).scalarDivide(2);return[c.subtract(d),c.add(d)]};class Li{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===ie||e===Ai||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ie&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===Ai&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:o,width:a,height:c}=Vt(t.map(u=>Ya(i,u)).reduce((u,d)=>u.concat(d),[])),h=new _(a,c),l=new _(n,o).add(h.scalarDivide(2));if(s===ie){const u=this.getInitialSize(e,{size:h,center:l});return{center:l,relativeCorrection:new _(0,0),size:u}}return{center:l.transform(i.calcOwnMatrix()),size:h}}}v(Li,"type","strategy");class vn extends Li{shouldPerformLayout(t){return!0}}v(vn,"type","fit-content"),w.setClass(vn);const Wu=["strategy"],Xu=["target","strategy","bubbles","prevStrategy"],Ga="layoutManager";class qs{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new vn;v(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=y(y({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[pi,To,Rs,So,di,xo,gi,wo,Hl].map(i=>t.on(i,n=>this.performLayout(i===pi?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===ie||s===Pi?this.subscribeTargets(t):s===mn&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===Ai&&t.deep){const n=Y(t,Wu);e.forEachObject(o=>o.layoutManager&&o.layoutManager.performLayout(y(y({},n),{},{bubbles:!1,target:o})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const o=i===ie?new _:e.getRelativeCenterPoint(),{center:a,correction:c=new _,relativeCorrection:h=new _}=n,l=o.subtract(a).add(c).transform(i===ie?ut:St(e.calcOwnMatrix()),!0).add(h);return{result:n,prevCenter:o,nextCenter:a,offset:l}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var o,a;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===ie?s.set({left:(o=t.x)!==null&&o!==void 0?o:n.x+i.x*it(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+i.y*it(s.originY)}):(s.setPositionByOrigin(n,j,j),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:o}=t,a=Y(t,Xu),{canvas:c}=s;s.fire("layout:after",{context:t,result:e}),c&&c.fire("object:layout:after",{context:t,result:e,target:s});const h=s.parent;n&&h!=null&&h.layoutManager&&((a.path||(a.path=[])).push(s),h.layoutManager.performLayout(y(y({},a),{},{target:h}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:Ga,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}w.setClass(qs,Ga);const zu=["type","objects","layoutManager"];class Hu extends qs{performLayout(){}}class Nt extends Co(ct){static getDefaults(){return y(y({},super.getDefaults()),Nt.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),v(this,"_activeObjects",[]),v(this,"__objectSelectionTracker",void 0),v(this,"__objectSelectionDisposer",void 0),Object.assign(this,Nt.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject(i=>{this.enterGroup(i,!1)}),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new qs,this.layoutManager.performLayout({type:ie,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(me("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(me("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(Pi,i),n}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=this._filterObjectsBeforeEnteringGroup(s),o=super.insertAt(t,...n);return this._onAfterObjectsChange(Pi,n),o}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(mn,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&rs(t,q(St(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||(rs(t,q(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=ct.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){this._renderBackground(t);for(let s=0;s<this._objects.length;s++){var e;(e=this.canvas)!==null&&e!==void 0&&e.preserveObjectStacking&&this._objects[s].group!==this?(t.save(),t.transform(...St(this.calcTransformMatrix())),this._objects[s].render(t),t.restore()):this._objects[s].group===this&&this._objects[s].render(t)}this._drawClipPath(t,this.clipPath)}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(y({target:this,type:Ai},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const o=i[t||"toObject"](e);return i.includeDefaultValues=n,o})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return y(y(y({},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=z.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
|
|
40
|
-
`],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let
|
|
41
|
-
`),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,o=Y(t,zu);return Promise.all([is(i,e),zs(o,e)]).then(a=>{let[c,h]=a;const l=new this(c,y(y(y({},o),h),{},{layoutManager:new Hu}));if(n){const u=w.getClass(n.type),d=w.getClass(n.strategy);l.layoutManager=new u(new d)}else l.layoutManager=new qs;return l.layoutManager.subscribeTargets({type:ie,target:l,targets:l.getObjects()}),l.setCoords(),l})}}v(Nt,"type","Group"),v(Nt,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),w.setClass(Nt);const Va=(r,t)=>Math.min(t.width/r.width,t.height/r.height),Na=(r,t)=>Math.max(t.width/r.width,t.height/r.height),yn="\\s*,?\\s*",Ks="".concat(yn,"(").concat(Fe,")"),Yu="".concat(Ks).concat(Ks).concat(Ks).concat(yn,"([01])").concat(yn,"([01])").concat(Ks).concat(Ks),Gu={m:"l",M:"L"},Vu=(r,t,e,s,i,n,o,a,c,h,l)=>{const u=It(r),d=Et(r),g=It(t),f=Et(t),p=e*i*g-s*n*f+o,m=s*i*g+e*n*f+a;return["C",h+c*(-e*i*d-s*n*u),l+c*(-s*i*d+e*n*u),p+c*(e*i*f+s*n*g),m+c*(s*i*f-e*n*g),p,m]},Ua=(r,t,e,s)=>{const i=Math.atan2(t,r),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function bn(r,t,e,s,i,n,o,a){let c;if(A.cachesBoundsOfCurve&&(c=[...arguments].join(),Fs.boundsOfCurveCache[c]))return Fs.boundsOfCurveCache[c];const h=Math.sqrt,l=Math.abs,u=[],d=[[0,0],[0,0]];let g=6*r-12*e+6*i,f=-3*r+9*e-9*i+3*o,p=3*e-3*r;for(let C=0;C<2;++C){if(C>0&&(g=6*t-12*s+6*n,f=-3*t+9*s-9*n+3*a,p=3*s-3*t),l(f)<1e-12){if(l(g)<1e-12)continue;const F=-p/g;0<F&&F<1&&u.push(F);continue}const O=g*g-4*p*f;if(O<0)continue;const M=h(O),I=(-g+M)/(2*f);0<I&&I<1&&u.push(I);const D=(-g-M)/(2*f);0<D&&D<1&&u.push(D)}let m=u.length;const b=m,T=qa(r,t,e,s,i,n,o,a);for(;m--;){const{x:C,y:O}=T(u[m]);d[0][m]=C,d[1][m]=O}d[0][b]=r,d[1][b]=t,d[0][b+1]=o,d[1][b+1]=a;const S=[new _(Math.min(...d[0]),Math.min(...d[1])),new _(Math.max(...d[0]),Math.max(...d[1]))];return A.cachesBoundsOfCurve&&(Fs.boundsOfCurveCache[c]=S),S}const Nu=(r,t,e)=>{let[s,i,n,o,a,c,h,l]=e;const u=((d,g,f,p,m,b,T)=>{if(f===0||p===0)return[];let S=0,C=0,O=0;const M=Math.PI,I=T*jr,D=Et(I),F=It(I),N=.5*(-F*d-D*g),at=.5*(-F*g+D*d),et=f**2,B=p**2,K=at**2,wt=N**2,_t=et*B-et*K-B*wt;let Ht=Math.abs(f),J=Math.abs(p);if(_t<0){const Ie=Math.sqrt(1-_t/(et*B));Ht*=Ie,J*=Ie}else O=(m===b?-1:1)*Math.sqrt(_t/(et*K+B*wt));const Kt=O*Ht*at/J,fe=-O*J*N/Ht,Mr=F*Kt-D*fe+.5*d,fo=D*Kt+F*fe+.5*g;let hi=Ua(1,0,(N-Kt)/Ht,(at-fe)/J),De=Ua((N-Kt)/Ht,(at-fe)/J,(-N-Kt)/Ht,(-at-fe)/J);b===0&&De>0?De-=2*M:b===1&&De<0&&(De+=2*M);const Dr=Math.ceil(Math.abs(De/M*2)),qe=[],li=De/Dr,Ry=8/3*Math.sin(li/4)*Math.sin(li/4)/Math.sin(li/2);let po=hi+li;for(let Ie=0;Ie<Dr;Ie++)qe[Ie]=Vu(hi,po,F,D,Ht,J,Mr,fo,Ry,S,C),S=qe[Ie][5],C=qe[Ie][6],hi=po,po+=li;return qe})(h-r,l-t,i,n,a,c,o);for(let d=0,g=u.length;d<g;d++)u[d][1]+=r,u[d][2]+=t,u[d][3]+=r,u[d][4]+=t,u[d][5]+=r,u[d][6]+=t;return u},$a=r=>{let t=0,e=0,s=0,i=0;const n=[];let o,a=0,c=0;for(const h of r){const l=[...h];let u;switch(l[0]){case"l":l[1]+=t,l[2]+=e;case"L":t=l[1],e=l[2],u=["L",t,e];break;case"h":l[1]+=t;case"H":t=l[1],u=["L",t,e];break;case"v":l[1]+=e;case"V":e=l[1],u=["L",t,e];break;case"m":l[1]+=t,l[2]+=e;case"M":t=l[1],e=l[2],s=l[1],i=l[2],u=["M",t,e];break;case"c":l[1]+=t,l[2]+=e,l[3]+=t,l[4]+=e,l[5]+=t,l[6]+=e;case"C":a=l[3],c=l[4],t=l[5],e=l[6],u=["C",l[1],l[2],a,c,t,e];break;case"s":l[1]+=t,l[2]+=e,l[3]+=t,l[4]+=e;case"S":o==="C"?(a=2*t-a,c=2*e-c):(a=t,c=e),t=l[3],e=l[4],u=["C",a,c,l[1],l[2],t,e],a=u[3],c=u[4];break;case"q":l[1]+=t,l[2]+=e,l[3]+=t,l[4]+=e;case"Q":a=l[1],c=l[2],t=l[3],e=l[4],u=["Q",a,c,t,e];break;case"t":l[1]+=t,l[2]+=e;case"T":o==="Q"?(a=2*t-a,c=2*e-c):(a=t,c=e),t=l[1],e=l[2],u=["Q",a,c,t,e];break;case"a":l[6]+=t,l[7]+=e;case"A":Nu(t,e,l).forEach(d=>n.push(d)),t=l[6],e=l[7];break;case"z":case"Z":t=s,e=i,u=["Z"]}u?(n.push(u),o=u[0]):o=""}return n},Fi=(r,t,e,s)=>Math.sqrt((e-r)**2+(s-t)**2),qa=(r,t,e,s,i,n,o,a)=>c=>{const h=c**3,l=(g=>3*g**2*(1-g))(c),u=(g=>3*g*(1-g)**2)(c),d=(g=>(1-g)**3)(c);return new _(o*h+i*l+e*u+r*d,a*h+n*l+s*u+t*d)},Ka=r=>r**2,Ja=r=>2*r*(1-r),Za=r=>(1-r)**2,Uu=(r,t,e,s,i,n,o,a)=>c=>{const h=Ka(c),l=Ja(c),u=Za(c),d=3*(u*(e-r)+l*(i-e)+h*(o-i)),g=3*(u*(s-t)+l*(n-s)+h*(a-n));return Math.atan2(g,d)},$u=(r,t,e,s,i,n)=>o=>{const a=Ka(o),c=Ja(o),h=Za(o);return new _(i*a+e*c+r*h,n*a+s*c+t*h)},qu=(r,t,e,s,i,n)=>o=>{const a=1-o,c=2*(a*(e-r)+o*(i-e)),h=2*(a*(s-t)+o*(n-s));return Math.atan2(h,c)},Qa=(r,t,e)=>{let s=new _(t,e),i=0;for(let n=1;n<=100;n+=1){const o=r(n/100);i+=Fi(s.x,s.y,o.x,o.y),s=o}return i},Ku=(r,t)=>{let e,s=0,i=0,n={x:r.x,y:r.y},o=y({},n),a=.01,c=0;const h=r.iterator,l=r.angleFinder;for(;i<t&&a>1e-4;)o=h(s),c=s,e=Fi(n.x,n.y,o.x,o.y),e+i>t?(s-=a,a/=2):(n=o,s+=a,i+=e);return y(y({},o),{},{angle:l(c)})},_n=r=>{let t,e,s=0,i=0,n=0,o=0,a=0;const c=[];for(const h of r){const l={x:i,y:n,command:h[0],length:0};switch(h[0]){case"M":e=l,e.x=o=i=h[1],e.y=a=n=h[2];break;case"L":e=l,e.length=Fi(i,n,h[1],h[2]),i=h[1],n=h[2];break;case"C":t=qa(i,n,h[1],h[2],h[3],h[4],h[5],h[6]),e=l,e.iterator=t,e.angleFinder=Uu(i,n,h[1],h[2],h[3],h[4],h[5],h[6]),e.length=Qa(t,i,n),i=h[5],n=h[6];break;case"Q":t=$u(i,n,h[1],h[2],h[3],h[4]),e=l,e.iterator=t,e.angleFinder=qu(i,n,h[1],h[2],h[3],h[4]),e.length=Qa(t,i,n),i=h[3],n=h[4];break;case"Z":e=l,e.destX=o,e.destY=a,e.length=Fi(i,n,o,a),i=o,n=a}s+=e.length,c.push(e)}return c.push({length:s,x:i,y:n}),c},tc=function(r,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:_n(r),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,o=r[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return y(y({},new _(i.x,i.y).lerp(new _(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return y(y({},new _(i.x,i.y).lerp(new _(o[1],o[2]),n)),{},{angle:Math.atan2(o[2]-i.y,o[1]-i.x)});case"C":case"Q":return Ku(i,t)}},Ju=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),ec=new RegExp(Yu,"g"),Zu=new RegExp(Fe,"gi"),Qu={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},sc=r=>{var t;const e=[],s=(t=r.match(Ju))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const o=Qu[n.toLowerCase()];let a=[];if(n==="a"||n==="A"){ec.lastIndex=0;for(let c=null;c=ec.exec(i);)a.push(...c.slice(1))}else a=i.match(Zu)||[];for(let c=0;c<a.length;c+=o){const h=new Array(o),l=Gu[n];h[0]=c>0&&l?l:n;for(let u=0;u<o;u++)h[u+1]=parseFloat(a[c+u]);e.push(h)}}return e},td=function(r){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new _(r[0]),s=new _(r[1]),i=1,n=0;const o=[],a=r.length,c=a>2;let h;for(c&&(i=r[2].x<s.x?-1:r[2].x===s.x?0:1,n=r[2].y<s.y?-1:r[2].y===s.y?0:1),o.push(["M",e.x-i*t,e.y-n*t]),h=1;h<a;h++){if(!e.eq(s)){const l=e.midPointFrom(s);o.push(["Q",e.x,e.y,l.x,l.y])}e=r[h],h+1<r.length&&(s=r[h+1])}return c&&(i=e.x>r[h-2].x?1:e.x===r[h-2].x?0:-1,n=e.y>r[h-2].y?1:e.y===r[h-2].y?0:-1),o.push(["L",e.x+i*t,e.y+n*t]),o},ic=(r,t)=>r.map(e=>e.map((s,i)=>i===0||t===void 0?s:G(s,t)).join(" ")).join(" ");function Ri(r,t){const e=r.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const ed=(r,t)=>Math.floor(Math.random()*(t-r+1))+r;function sd(r){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||Ee,s=new(ui()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},o=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=Ee};if(i&&i.aborted)throw new yo("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(o(),e(s),s.onreadystatechange=Ee)},s.onerror=s.ontimeout=o,s.open("get",r,!0),s.send(),s}var rc=Object.freeze({__proto__:null,addTransformToObject:Uo,animate:on,animateColor:ua,applyTransformToObject:rs,calcAngleBetweenVectors:Mi,calcDimensionsMatrix:Ws,calcPlaneChangeMatrix:Vs,calcVectorRotation:ra,cancelAnimFrame:ko,capValue:Re,composeMatrix:jo,copyCanvasElement:r=>{var t;const e=tt();return e.width=r.width,e.height=r.height,(t=e.getContext("2d"))===null||t===void 0||t.drawImage(r,0,0),e},cos:It,createCanvasElement:tt,createImage:Mo,createRotateMatrix:ss,createScaleMatrix:bi,createSkewXMatrix:Xr,createSkewYMatrix:zr,createTranslateMatrix:es,createVector:Oi,crossProduct:ns,degreesToRadians:$,dotProduct:na,ease:tu,enlivenObjectEnlivables:zs,enlivenObjects:is,findScaleToCover:Na,findScaleToFit:Va,getBoundsOfCurve:bn,getOrthonormalVector:Qr,getPathSegmentsInfo:_n,getPointOnPath:tc,getPointer:No,getRandomInt:ed,getRegularPolygonPath:(r,t)=>{const e=2*Math.PI/r;let s=-ve;r%2==0&&(s+=e/2);const i=new Array(r+1);for(let n=0;n<r;n++){const o=n*e+s,{x:a,y:c}=new _(It(o),Et(o)).scalarMultiply(t);i[n]=[n===0?"M":"L",a,c]}return i[r]=["Z"],i},getSmoothPathFromPoints:td,getSvgAttributes:r=>{const t=["instantiated_by_use","style","id","class"];switch(r){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:Di,groupSVGElements:(r,t)=>r&&r.length===1?r[0]:new Nt(r,t),hasStyleChanged:ji,invertTransform:St,isBetweenVectors:tn,isIdentityMatrix:Do,isTouchEvent:Ti,isTransparent:ka,joinPath:ic,loadImage:Xs,magnitude:ki,makeBoundingBoxFromPoints:Vt,makePathSimpler:$a,matrixToSVG:Hs,mergeClipPaths:(r,t)=>{var e;let s=r,i=t;s.inverted&&!i.inverted&&(s=t,i=r),Ur(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new Nt([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:q,multiplyTransformMatrixArray:yi,parsePath:sc,parsePreserveAspectRatioAttribute:Ro,parseUnit:Ae,pick:Pe,projectStrokeOnPoints:Ia,qrDecompose:ts,radiansToDegrees:_e,removeFromArray:je,removeTransformFromObject:(r,t)=>{const e=St(t),s=q(e,r.calcOwnMatrix());rs(r,s)},removeTransformMatrixForSvgParsing:(r,t)=>{let e=r._findCenterFromElement();r.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:o,skewX:a}=ts(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(dt,i),s.set(Tt,n),s.angle=o,s.skewX=a,s.skewY=0}})(r),e=e.transform(r.transformMatrix)),delete r.transformMatrix,t&&(r.scaleX*=t.scaleX,r.scaleY*=t.scaleY,r.cropX=t.cropX,r.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,r.width=t.width,r.height=t.height),r.setPositionByOrigin(e,j,j)},request:sd,requestAnimFrame:Bs,resetObjectTransform:$o,rotatePoint:(r,t,e)=>r.rotate(e,t),rotateVector:Zr,saveObjectTransform:Nr,sendObjectToPlane:Ur,sendPointToPlane:Zt,sendVectorToPlane:qo,setStyle:Ri,sin:Et,sizeAfterTransform:Si,string:vu,stylesFromArray:Pa,stylesToArray:ja,toDataURL:Wr,toFixed:G,transformPath:(r,t,e)=>(e&&(t=q(t,[1,0,0,1,-e.x,-e.y])),r.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:o,y:a}=ht({x:s[n],y:s[n+1]},t);i[n]=o,i[n+1]=a}return i})),transformPoint:ht});class id extends Vo{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),v(this,"upper",void 0),v(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const o=this.createContainerElement();o.classList.add(s),i.parentNode&&i.parentNode.replaceChild(o,i),o.append(i,n),this.container=o}createUpperCanvas(){const{el:t}=this.lower,e=tt();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=Ke().createElement("div");return t.setAttribute("data-fabric","wrapper"),Ri(t,{position:"relative"}),Go(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;Ri(t,y(y({},s),{},{"touch-action":i?"manipulation":vt})),Go(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;Yo(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Gr(this.upper.el,t),Gr(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),Gt().dispose(this.upper.el),delete this.upper,delete this.container}}class Bi extends Gs{constructor(){super(...arguments),v(this,"targets",[]),v(this,"_hoveredTargets",[]),v(this,"_objectsToRender",void 0),v(this,"_currentTransform",null),v(this,"_groupSelector",null),v(this,"contextTopDirty",!1)}static getDefaults(){return y(y({},super.getDefaults()),Bi.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 id(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter(e=>!e.group&&e!==t).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const o=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=o,n.restore();const a=Math.round(i*this.getRetinaScaling());return ka(n,a,a,a)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===fi||e===dt||e===Tt||e===Rs?i=this.centeredScaling||t.centeredScaling:e===Fr&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=Q:["mr","tr","br"].includes(e)&&(s.x=L),["tl","mt","tr"].includes(e)?s.y=Ar:["bl","mb","br"].includes(e)&&(s.y=mt)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?Zt(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:o="",control:a}=e.getActiveControl()||{},c=s&&a?(i=a.getActionHandler(t,e,a))===null||i===void 0?void 0:i.bind(a):Qo,h=((g,f,p,m)=>{if(!f||!g)return"drag";const b=m.controls[f];return b.getActionName(p,b,m)})(s,o,t,e),l=t[this.centeredKey],u=this._shouldCenterTransform(e,h,l)?{x:j,y:j}:this._getOriginFromCorner(e,o),d={target:e,action:h,actionHandler:c,actionPerformed:!1,corner:o,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:$(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:l,original:y(y({},Nr(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,o=new _(e,s).transform(this.viewportTransform),a=new _(e+i,s+n).transform(this.viewportTransform),c=this.selectionLineWidth/2;let h=Math.min(o.x,a.x),l=Math.min(o.y,a.y),u=Math.max(o.x,a.x),d=Math.max(o.y,a.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(h,l,u-h,d-l)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,h+=c,l+=c,u-=c,d-=c,ct.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(h,l,u-h,d-l))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,Ti(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const o=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&o&&o!==s?(this.targets=n,s):o}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[o,a,c,h]=s,l=Math.atan2(a.y-o.y,a.x-o.x),u=It(l)*n,d=Et(l)*n,g=u+d,f=u-d;s=[new _(o.x-f,o.y-g),new _(a.x+g,a.y-f),new _(c.x+f,c.y+g),new _(h.x-g,h.y+f)]}return U.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,Zt(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(vi(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&vi(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const o=i[n];if(!vi(o)||!o.interactive)return o}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=No(t),o=i.width||0,a=i.height||0;o&&a||(mt in i&&Ar in i&&(a=Math.abs(i.top-i.bottom)),Q in i&&L in i&&(o=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=Zt(n,void 0,this.viewportTransform));const c=this.getRetinaScaling();c!==1&&(n.x/=c,n.y/=c);const h=o===0||a===0?new _(1,1):new _(s.width/o,s.height/a);return n.multiply(h)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=tt(),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 Le(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),o=[],a=[];t.forEach(c=>{n.includes(c)||(s=!0,c.fire("deselected",{e,target:c}),a.push(c))}),n.forEach(c=>{t.includes(c)||(s=!0,c.fire("selected",{e,target:c}),o.push(c))}),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:o,deselected:a})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:o})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:a})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,Le(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),Le(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(pi,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Le(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&Le(e)&&this._activeObject===e){const s=Pe(t,["angle","flipX","flipY",L,dt,Tt,Je,Ze,mt]);return Uo(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}v(Bi,"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 rd{constructor(t){v(this,"targets",[]),v(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),je(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 nd=["target","oldTarget","fireCanvas","e"],xt={passive:!1},cs=(r,t)=>{const e=r.getViewportPoint(t),s=r.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},xe=function(r){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return r.addEventListener(...e)},Ot=function(r){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return r.removeEventListener(...e)},od={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Tn extends Bi{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),v(this,"_isClick",void 0),v(this,"textEditingManager",new rd(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(xe,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(Ho(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,xt),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),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,xt)}removeListeners(){this.addOrRemove(Ot,"remove");const t=this._getEventPrefix(),e=jt(this.upperCanvasEl);Ot(e,"".concat(t,"up"),this._onMouseUp),Ot(e,"touchend",this._onTouchEnd,xt),Ot(e,"".concat(t,"move"),this._onMouseMove,xt),Ot(e,"touchmove",this._onMouseMove,xt)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=y({e:t},cs(this,t));this.fire("mouse:out",y(y({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",y({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",y(y({},s),{},{target:i})),i&&i.fire("mouseout",y({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",y({e:t},cs(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 xe(this.upperCanvasEl,"drag",this._onDragProgress)}Vr(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const o=this.contextTop;o.save(),o.transform(...this.viewportTransform),e&&(o.save(),e.transform(o),e.renderDragSourceEffect(t),o.restore(),i=!0),s&&(o.save(),s.transform(o),s.renderDropTargetEffect(t),o.restore(),i=!0),o.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==vt,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};Ot(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,o={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let a;this.fire(e,o),this._fireEnterLeaveEvents(s,o),s&&(s.canDrop(t)&&(a=s),s.fire(e,o));for(let c=0;c<i.length;c++){const h=i[c];h.canDrop(t)&&(a=h),h.fire(e,o)}this._renderDragEffects(t,n,a),this._dropTarget=a}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",y({e:t,target:e,subTargets:s,dragSource:this._dragSource},cs(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&Vr(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){t.preventDefault(),this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix(),i=jt(e);xe(i,"touchend",this._onTouchEnd,xt),xe(i,"touchmove",this._onMouseMove,xt),Ot(e,"".concat(s,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();Ot(e,"".concat(s,"move"),this._onMouseMove,xt);const i=jt(e);xe(i,"".concat(s,"up"),this._onMouseUp),xe(i,"".concat(s,"move"),this._onMouseMove,xt)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=jt(this.upperCanvasEl);Ot(s,"touchend",this._onTouchEnd,xt),Ot(s,"touchmove",this._onMouseMove,xt),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{xe(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=jt(this.upperCanvasEl);Ot(i,"".concat(s,"up"),this._onMouseUp),Ot(i,"".concat(s,"move"),this._onMouseMove,xt),xe(e,"".concat(s,"move"),this._onMouseMove,xt)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:o}=t;if(o)return(this.fireMiddleClick&&o===1||this.fireRightClick&&o===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let a,c,h=!1;if(s&&(this._finalizeCurrentTransform(t),h=s.actionPerformed),!i){const l=n===this._activeObject;this.handleSelection(t),h||(h=this._shouldRender(n)||!l&&n===this._activeObject)}if(n){const l=n.findControl(this.getViewportPoint(t),Ti(t)),{key:u,control:d}=l||{};if(c=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),h=!0;else if(d){const g=d.getMouseUpHandler(t,n,d);g&&(a=this.getScenePoint(t),g.call(d,t,s,a.x,a.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==c)){const l=s.target&&s.target.controls[s.corner],u=l&&l.getMouseUpHandler(t,s.target,l);a=a||this.getScenePoint(t),u&&u.call(l,t,s,a.x,a.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),h?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=y(y({e:t,target:s,subTargets:i},cs(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let o=0;o<i.length;o++)i[o]!==s&&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")}_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;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),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(e){const o=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const a=e.findControl(this.getViewportPoint(t),Ti(t));if(e===this._activeObject&&(a||!n)){this._setupCurrentTransform(t,e,o);const c=a?a.control:void 0,h=this.getScenePoint(t),l=c&&c.getMouseDownHandler(t,e,c);l&&l.call(c,t,this._currentTransform,h.x,h.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=Zt(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,o=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let a=0;a<o;a++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[a],oldTarget:i[a]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,o=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",y(y({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let a=0;a<o;a++)this.fireSyntheticInOutEvents("drag",y(y({},e),{},{target:n[a],oldTarget:i[a]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:o}=e,a=Y(e,nd);const{targetIn:c,targetOut:h,canvasIn:l,canvasOut:u}=od[t],d=i!==s;if(i&&d){const g=y(y({},a),{},{e:o,target:i,nextTarget:s},cs(this,o));n&&this.fire(u,g),i.fire(h,g)}if(s&&d){const g=y(y({},a),{},{e:o,target:s,previousTarget:i},cs(this,o));n&&this.fire(l,g),s.fire(c,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?Zt(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:o}=e,a=!!n&&n(t,e,s.x,s.y);a&&o.setCoords(),i==="drag"&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=Le(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const o=n.control;this.setCursor(o.cursorStyleHandler(t,o,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(o=>{s=o.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=Le(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const o=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,o)||this.searchPossibleTargets(this._objects,o))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.exitEditing&&s.exitEditing();const n=new(w.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,o=new _(e,s),a=o.add(new _(i,n)),c=o.min(a),h=o.max(a).subtract(c),l=this.collectObjects({left:c.x,top:c.y,width:h.x,height:h.y},{includeIntersecting:!this.selectionFullyContained}),u=o.eq(a)?l[0]?[l[0]]:[]:l.length>1?l.filter(d=>!d.onSelect({e:t})).reverse():l;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=w.getClass("ActiveSelection");this.setActiveObject(new d(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const nc={x1:0,y1:0,x2:0,y2:0},ad=y(y({},nc),{},{r1:0,r2:0}),hs=(r,t)=>isNaN(r)&&typeof t=="number"?t:r,cd=/^(\d+\.\d+)%|(\d+)%$/;function oc(r){return r&&cd.test(r)}function ac(r,t){const e=typeof r=="number"?r:typeof r=="string"?parseFloat(r)/(oc(r)?100:1):NaN;return Re(0,hs(e,t),1)}const hd=/\s*;\s*/,ld=/\s*:\s*/;function ud(r,t){let e,s;const i=r.getAttribute("style");if(i){const o=i.split(hd);o[o.length-1]===""&&o.pop();for(let a=o.length;a--;){const[c,h]=o[a].split(ld).map(l=>l.trim());c==="stop-color"?e=h:c==="stop-opacity"&&(s=h)}}const n=new R(e||r.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:ac(r.getAttribute("offset"),0),color:n.toRgb(),opacity:hs(parseFloat(s||r.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function dd(r,t){const e=[],s=r.getElementsByTagName("stop"),i=ac(t,1);for(let n=s.length;n--;)e.push(ud(s[n],i));return e}function cc(r){return r.nodeName==="linearGradient"||r.nodeName==="LINEARGRADIENT"?"linear":"radial"}function hc(r){return r.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function At(r,t){return r.getAttribute(t)}function gd(r,t){return function(e,s){let i,{width:n,height:o,gradientUnits:a}=s;return Object.keys(e).reduce((c,h)=>{const l=e[h];return l==="Infinity"?i=1:l==="-Infinity"?i=0:(i=typeof l=="string"?parseFloat(l):l,typeof l=="string"&&oc(l)&&(i*=.01,a==="pixels"&&(h!=="x1"&&h!=="x2"&&h!=="r2"||(i*=n),h!=="y1"&&h!=="y2"||(i*=o)))),c[h]=i,c},{})}(cc(r)==="linear"?function(e){return{x1:At(e,"x1")||0,y1:At(e,"y1")||0,x2:At(e,"x2")||"100%",y2:At(e,"y2")||0}}(r):function(e){return{x1:At(e,"fx")||At(e,"cx")||"50%",y1:At(e,"fy")||At(e,"cy")||"50%",r1:0,x2:At(e,"cx")||"50%",y2:At(e,"cy")||"50%",r2:At(e,"r")||"50%"}}(r),y(y({},t),{},{gradientUnits:hc(r)}))}class Wi{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:o=0,offsetY:a=0,gradientTransform:c,id:h}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:y(y({},e==="radial"?ad:nc),i),colorStops:n,offsetX:o,offsetY:a,gradientTransform:c,id:h?"".concat(h,"_").concat(be()):be()})}addColorStop(t){for(const e in t){const s=new R(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return y(y({},Pe(this,t)),{},{type:this.type,coords:y({},this.coords),colorStops:this.colorStops.map(e=>y({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():ut.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map(u=>y({},u)).sort((u,d)=>u.offset-d.offset);let a=-this.offsetX,c=-this.offsetY;var h;n==="objectBoundingBox"?(a/=t.width,c/=t.height):(a+=t.width/2,c+=t.height/2),(h=t)&&typeof h._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(a-=t.pathOffset.x,c-=t.pathOffset.y),i[4]-=a,i[5]-=c;const l=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Hs(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:g,y2:f}=this.coords;s.push("<linearGradient ",l,' x1="',u,'" y1="',d,'" x2="',g,'" y2="',f,`">
|
|
42
|
-
`)}else if(this.type==="radial"){const{x1:u,y1:d,x2:
|
|
43
|
-
`),b&&(o.reverse(),o.forEach(
|
|
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=se.ownDefaults;return this.includeDefaultValues?t:zi(t,(s,r)=>s!==e[r])}static async fromObject(t){return new this(t)}}v(se,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),v(se,"type","shadow"),C.setClass(se,"shadow");const iu=[mt,R,dt,_t,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Ze,Je],re=[st,yt,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],nu={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:R,originY:mt,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:st,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},ou=["type"],au=["extraParam"];let Le=class ho extends ra{static getDefaults(){return ho.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){pe("warn","Setting type has no effect",t)}constructor(t){super(),v(this,"_cacheContext",null),Object.assign(this,ho.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=tt(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,r=L.maxCacheSideLimit,n=L.minCacheSideLimit;if(e<=r&&s<=r&&e*s<=L.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const o=e/s,[a,c]=Bs.limitDimsByArea(o),h=Ae(n,a,r),l=Ae(n,c,r);return e>h&&(t.zoomX/=e/h,t.width=h,t.capped=!0),s>l&&(t.zoomY/=s/l,t.height=l,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,r=e.y*t.y/this.scaleY;return{width:s+2,height:r+2,zoomX:t.x,zoomY:t.y,x:s,y:r}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,s=this._limitCacheSize(this._getCacheCanvasDimensions()),r=L.minCacheSideLimit,n=s.width,o=s.height,a=s.zoomX,c=s.zoomY,h=n!==t.width||o!==t.height,l=this.zoomX!==a||this.zoomY!==c;if(!t||!e)return!1;let u,d,f=h||l,g=0,p=0,m=!1;if(h){const b=this._cacheCanvas.width,T=this._cacheCanvas.height,w=n>b||o>T;m=w||(n<.9*b||o<.9*T)&&b>r&&T>r,w&&!s.capped&&(n>r||o>r)&&(g=.1*n,p=.1*o)}return Lo(this)&&this.path&&(f=!0,m=!0,g+=this.getHeightOfLine(0)*this.zoomX,p+=this.getHeightOfLine(0)*this.zoomY),!!f&&(m?(t.width=Math.ceil(n+g),t.height=Math.ceil(o+p)):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height)),u=s.x/2,d=s.y/2,this.cacheTranslationX=Math.round(t.width/2-u)+u,this.cacheTranslationY=Math.round(t.height/2-d)+d,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(a,c),this.zoomX=a,this.zoomY=c,!0)}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])}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=L.NUM_FRACTION_DIGITS,s=this.clipPath&&!this.clipPath.excludeFromExport?y(y({},this.clipPath.toObject(t)),{},{inverted:this.clipPath.inverted,absolutePositioned:this.clipPath.absolutePositioned}):null,r=y(y({},je(this,t)),{},{type:this.constructor.type,version:Ii,originX:this.originX,originY:this.originY,left:P(this.left,e),top:P(this.top,e),width:P(this.width,e),height:P(this.height,e),fill:Po(this.fill)?this.fill.toObject():this.fill,stroke:Po(this.stroke)?this.stroke.toObject():this.stroke,strokeWidth:P(this.strokeWidth,e),strokeDashArray:this.strokeDashArray?this.strokeDashArray.concat():this.strokeDashArray,strokeLineCap:this.strokeLineCap,strokeDashOffset:this.strokeDashOffset,strokeLineJoin:this.strokeLineJoin,strokeUniform:this.strokeUniform,strokeMiterLimit:P(this.strokeMiterLimit,e),scaleX:P(this.scaleX,e),scaleY:P(this.scaleY,e),angle:P(this.angle,e),flipX:this.flipX,flipY:this.flipY,opacity:P(this.opacity,e),shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible,backgroundColor:this.backgroundColor,fillRule:this.fillRule,paintFirst:this.paintFirst,globalCompositeOperation:this.globalCompositeOperation,skewX:P(this.skewX,e),skewY:P(this.skewY,e)},s?{clipPath:s}:null);return this.includeDefaultValues?r:this._removeDefaultValues(r)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return zi(t,(r,n)=>{if(n===R||n===mt||n==="type")return!0;const o=s[n];return r!==o&&!(Array.isArray(r)&&Array.isArray(o)&&r.length===0&&o.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}getObjectScaling(){if(!this.group)return new _(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=ts(this.calcTransformMatrix());return new _(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!==dt&&t!==_t||(e=this._constrainScale(e)),t===dt&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof se||(e=new se(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),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext&&(this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===yt&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.parent||!this.parent.isOnACache()),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e){if(t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",e.absolutePositioned){const s=Tt(this.calcTransformMatrix());t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}drawObject(t,e){const s=this.fill,r=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath),this.fill=s,this.stroke=r}_drawClipPath(t,e){e&&(e._set("canvas",this.canvas),e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t,e))}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&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,xt(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&&(xt(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&&(1&e.length&&e.push(...e),t.setLineDash(e))}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,r=this.getCanvasRetinaScaling(),[n,,,o]=(s==null?void 0:s.viewportTransform)||ut,a=n*r,c=o*r,h=e.nonScaling?new _(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*L.browserShadowBlurConstant*(a+c)*(h.x+h.y)/4,t.shadowOffsetX=e.offsetX*a*h.x,t.shadowOffsetY=e.offsetY*c*h.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!xt(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,r=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,r,n):t.transform(1,0,0,1,r,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:r,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===yt?(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()),n=tt(),o=this.getCanvasRetinaScaling(),a=r.x/this.scaleX/o,c=r.y/this.scaleY/o;n.width=Math.ceil(a),n.height=Math.ceil(c);const h=n.getContext("2d");h&&(h.beginPath(),h.moveTo(0,0),h.lineTo(a,0),h.lineTo(a,c),h.lineTo(0,c),h.closePath(),h.translate(a/2,c/2),h.scale(r.zoomX/this.scaleX/o,r.zoomY/this.scaleY/o),this._applyPatternGradientTransform(h,e),h.fillStyle=e.toLive(t),h.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(o*this.scaleX/r.zoomX,o*this.scaleY/r.zoomY),t.strokeStyle=(s=h.createPattern(n,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new _(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(C.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=Gi(this),s=this.group,r=this.shadow,n=Math.abs,o=t.enableRetinaScaling?po():1,a=(t.multiplier||1)*o,c=t.canvasProvider||(T=>new Us(T,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&Yo(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&Ni(this,this.getViewportTransform()),this.setCoords();const h=tt(),l=this.getBoundingRect(),u=this.shadow,d=new _;if(u){const T=u.blur,w=u.nonScaling?new _(1,1):this.getObjectScaling();d.x=2*Math.round(n(u.offsetX)+T)*n(w.x),d.y=2*Math.round(n(u.offsetY)+T)*n(w.y)}const f=l.width+d.x,g=l.height+d.y;h.width=Math.ceil(f),h.height=Math.ceil(g);const p=c(h);t.format==="jpeg"&&(p.backgroundColor="#fff"),this.setPositionByOrigin(new _(p.width/2,p.height/2),E,E);const m=this.canvas;p._objects=[this],this.set("canvas",p),this.setCoords();const b=p.toCanvasElement(a||1,t);return this.set("canvas",m),this.shadow=r,s&&(this.group=s),this.set(e),this.setCoords(),p._objects=[],p.destroy(),b}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Bi(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:n,y:o}=this.getRelativeCenterPoint();this.originX=E,this.originY=E,this.left=n,this.top=o}if(this.set("angle",t),e){const{x:n,y:o}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,r);this.left=n,this.top=o,this.originX=s,this.originY=r}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){br.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&Vt().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}static _fromObject(t){let e=U(t,ou),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:r}=s,n=U(s,au);return Ys(e,n).then(o=>r?(delete o[r],new this(e[r],o)):new this(o))}static fromObject(t,e){return this._fromObject(t,e)}};v(Le,"stateProperties",iu),v(Le,"cacheProperties",re),v(Le,"ownDefaults",nu),v(Le,"type","FabricObject"),C.setClass(Le),C.setClass(Le,"object");const _e=(i,t,e)=>(s,r,n,o)=>{const a=t(s,r,n,o);return a&&Ui(i,y(y({},$i(s,r,n,o)),e)),a};function Fe(i){return(t,e,s,r)=>{const{target:n,originX:o,originY:a}=e,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=i(t,e,s,r);return n.setPositionByOrigin(h,e.originX,e.originY),l}}const an=_e(Ws,Fe((i,t,e,s)=>{const r=kr(t,t.originX,t.originY,e,s);if(rt(t.originX)===rt(E)||rt(t.originX)===rt(Q)&&r.x<0||rt(t.originX)===rt(R)&&r.x>0){const{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=Go(t)?2:1,c=n.width,h=Math.ceil(Math.abs(r.x*a/n.scaleX)-o);return n.set("width",Math.max(h,0)),c!==n.width}return!1}));function ha(i,t,e,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:r.transparentCorners,c=a?yt:st,h=!a&&(s.cornerStrokeColor||r.cornerStrokeColor);let l,u=t,d=e;i.save(),i.fillStyle=s.cornerColor||r.cornerColor||"",i.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",n>o?(l=n,i.scale(1,o/n),d=e*n/o):o>n?(l=o,i.scale(n/o,1),u=t*o/n):l=n,i.lineWidth=1,i.beginPath(),i.arc(u,d,l/2,0,te,!1),i[c](),h&&i.stroke(),i.restore()}function la(i,t,e,s,r){s=s||{};const n=this.sizeX||s.cornerSize||r.cornerSize,o=this.sizeY||s.cornerSize||r.cornerSize,a=s.transparentCorners!==void 0?s.transparentCorners:r.transparentCorners,c=a?yt:st,h=!a&&(s.cornerStrokeColor||r.cornerStrokeColor),l=n/2,u=o/2;i.save(),i.fillStyle=s.cornerColor||r.cornerColor||"",i.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor||"",i.lineWidth=1,i.translate(t,e);const d=r.getTotalAngle();i.rotate(K(d)),i["".concat(c,"Rect")](-l,-u,n,o),h&&i.strokeRect(-l,-u,n,o),i.restore()}class ${constructor(t){v(this,"visible",!0),v(this,"actionName",vr),v(this,"angle",0),v(this,"x",0),v(this,"y",0),v(this,"offsetX",0),v(this,"offsetY",0),v(this,"sizeX",0),v(this,"sizeY",0),v(this,"touchSizeX",0),v(this,"touchSizeY",0),v(this,"cursorStyle","crosshair"),v(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,r){var n;let{tl:o,tr:a,br:c,bl:h}=r;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&q.isPointInPolygon(s,[o,a,c,h])}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 _(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,r,n,o){const a=Tr([es(s,r),ss({angle:t}),Sr((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new _(-.5,-.5).transform(a),tr:new _(.5,-.5).transform(a),br:new _(.5,.5).transform(a),bl:new _(-.5,.5).transform(a)}}render(t,e,s,r,n){((r=r||{}).cornerStyle||n.cornerStyle)==="circle"?ha.call(this,t,e,s,r,n):la.call(this,t,e,s,r,n)}}const ua=(i,t,e)=>e.lockRotation?Or:t.cursorStyle,da=_e(vo,Fe((i,t,e,s)=>{let{target:r,ex:n,ey:o,theta:a,originX:c,originY:h}=t;const l=r.translateToOriginPoint(r.getRelativeCenterPoint(),c,h);if(Pt(r,"lockRotation"))return!1;const u=Math.atan2(o-l.y,n-l.x),d=Math.atan2(s-l.y,e-l.x);let f=be(d-u+a);if(r.snapAngle&&r.snapAngle>0){const p=r.snapAngle,m=r.snapThreshold||p,b=Math.ceil(f/p)*p,T=Math.floor(f/p)*p;Math.abs(f-T)<m?f=T:Math.abs(f-b)<m&&(f=b)}f<0&&(f=360+f),f%=360;const g=r.angle!==f;return r.angle=f,g}));function fa(i,t){const e=t.canvas,s=i[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function ga(i,t,e){const s=Pt(i,"lockScalingX"),r=Pt(i,"lockScalingY");if(s&&r||!t&&(s||r)&&e||s&&t==="x"||r&&t==="y")return!0;const{width:n,height:o,strokeWidth:a}=i;return n===0&&a===0&&t!=="y"||o===0&&a===0&&t!=="x"}const cu=["e","se","s","sw","w","nw","n","ne","e"],as=(i,t,e)=>{const s=fa(i,e);if(ga(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Or;const r=Uo(e,t);return"".concat(cu[r],"-resize")};function cn(i,t,e,s){let r=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,o=r.by,a=fa(i,n);let c,h,l,u,d,f;if(ga(n,o,a))return!1;if(t.gestureScale)h=t.scaleX*t.gestureScale,l=t.scaleY*t.gestureScale;else{if(c=kr(t,t.originX,t.originY,e,s),d=o!=="y"?Math.sign(c.x||t.signX||1):1,f=o!=="x"?Math.sign(c.y||t.signY||1):1,t.signX||(t.signX=d),t.signY||(t.signY=f),Pt(n,"lockScalingFlip")&&(t.signX!==d||t.signY!==f))return!1;if(u=n._getTransformedDimensions(),a&&!o){const m=Math.abs(c.x)+Math.abs(c.y),{original:b}=t,T=m/(Math.abs(u.x*b.scaleX/n.scaleX)+Math.abs(u.y*b.scaleY/n.scaleY));h=b.scaleX*T,l=b.scaleY*T}else h=Math.abs(c.x*n.scaleX/u.x),l=Math.abs(c.y*n.scaleY/u.y);Go(t)&&(h*=2,l*=2),t.signX!==d&&o!=="y"&&(t.originX=No(t.originX),h*=-1,t.signX=d),t.signY!==f&&o!=="x"&&(t.originY=No(t.originY),l*=-1,t.signY=f)}const g=n.scaleX,p=n.scaleY;return o?(o==="x"&&n.set(dt,h),o==="y"&&n.set(_t,l)):(!Pt(n,"lockScalingX")&&n.set(dt,h),!Pt(n,"lockScalingY")&&n.set(_t,l)),g!==n.scaleX||p!==n.scaleY}const qs=_e(pr,Fe((i,t,e,s)=>cn(i,t,e,s))),pa=_e(pr,Fe((i,t,e,s)=>cn(i,t,e,s,{by:"x"}))),ma=_e(pr,Fe((i,t,e,s)=>cn(i,t,e,s,{by:"y"}))),hu=["target","ex","ey","skewingSide"],hn={x:{counterAxis:"y",scale:dt,skew:Ze,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:_t,skew:Je,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},lu=["ns","nesw","ew","nwse"],va=(i,t,e)=>{if(t.x!==0&&Pt(e,"lockSkewingY")||t.y!==0&&Pt(e,"lockSkewingX"))return Or;const s=Uo(e,t)%4;return"".concat(lu[s],"-resize")};function ya(i,t,e,s,r){const{target:n}=e,{counterAxis:o,origin:a,lockSkewing:c,skew:h,flip:l}=hn[i];if(Pt(n,c))return!1;const{origin:u,flip:d}=hn[o],f=rt(e[u])*(n[d]?-1:1),g=-Math.sign(f)*(n[l]?-1:1),p=.5*-((n[h]===0&&kr(e,E,E,s,r)[i]>0||n[h]>0?1:-1)*g)+.5;return _e(yo,Fe((b,T,w,k)=>function(O,x,I){let{target:D,ex:F,ey:X,skewingSide:ct}=x,W=U(x,hu);const{skew:H}=hn[O],nt=I.subtract(new _(F,X)).divide(new _(D.scaleX,D.scaleY))[O],zt=D[H],Dt=W[H],fe=Math.tan(K(Dt)),ge=O==="y"?D._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:D._getTransformedDimensions({scaleX:1,scaleY:1}).y,Ue=2*nt*ct/Math.max(ge,1)+fe,$e=be(Math.atan(Ue));D.set(H,$e);const Mi=zt!==D[H];if(Mi&&O==="y"){const{skewX:ao,scaleX:dr}=D,ke=D._getTransformedDimensions({skewY:zt}),Di=D._getTransformedDimensions(),qe=ao!==0?ke.x/Di.x:1;qe!==1&&D.set(dt,qe*dr)}return Mi}(i,T,new _(w,k))))(t,y(y({},e),{},{[a]:p,skewingSide:g}),s,r)}const ba=(i,t,e,s)=>ya("x",i,t,e,s),_a=(i,t,e,s)=>ya("y",i,t,e,s);function Pr(i,t){return i[t.canvas.altActionKey]}const Ks=(i,t,e)=>{const s=Pr(i,e);return t.x===0?s?Ze:_t:t.y===0?s?Je:dt:""},Re=(i,t,e)=>Pr(i,e)?va(0,t,e):as(i,t,e),ln=(i,t,e,s)=>Pr(i,t.target)?_a(i,t,e,s):pa(i,t,e,s),un=(i,t,e,s)=>Pr(i,t.target)?ba(i,t,e,s):ma(i,t,e,s),dn=()=>({ml:new $({x:-.5,y:0,cursorStyleHandler:Re,actionHandler:ln,getActionName:Ks}),mr:new $({x:.5,y:0,cursorStyleHandler:Re,actionHandler:ln,getActionName:Ks}),mb:new $({x:0,y:.5,cursorStyleHandler:Re,actionHandler:un,getActionName:Ks}),mt:new $({x:0,y:-.5,cursorStyleHandler:Re,actionHandler:un,getActionName:Ks}),tl:new $({x:-.5,y:-.5,cursorStyleHandler:as,actionHandler:qs}),tr:new $({x:.5,y:-.5,cursorStyleHandler:as,actionHandler:qs}),bl:new $({x:-.5,y:.5,cursorStyleHandler:as,actionHandler:qs}),br:new $({x:.5,y:.5,cursorStyleHandler:as,actionHandler:qs}),mtr:new $({x:0,y:-.5,actionHandler:da,cursorStyleHandler:ua,offsetY:-40,withConnection:!0,actionName:Li})}),Ta=()=>({mr:new $({x:.5,y:0,actionHandler:an,cursorStyleHandler:Re,actionName:Ws}),ml:new $({x:-.5,y:0,actionHandler:an,cursorStyleHandler:Re,actionName:Ws})}),Sa=()=>y(y({},dn()),Ta());class Zs extends Le{static getDefaults(){return y(y({},super.getDefaults()),Zs.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Zs.ownDefaults),this.setOptions(t)}static createControls(){return{controls:dn()}}_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(vr))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[n,o]=s[r],a=this.controls[n];if(a.shouldActivate(n,this,t,e?o.touchCorner:o.corner))return this.__corner=n,{key:n,control:a,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=es(e.x,e.y),r=ss({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Z(s,r),o=Z(t,n),a=Z(o,[1/t[0],0,0,1/t[3],0,0]),c=this.group?ts(this.calcTransformMatrix()):void 0;c&&(c.scaleX=Math.abs(c.scaleX),c.scaleY=Math.abs(c.scaleY));const h=this._calculateCurrentDimensions(c),l={};return this.forEachControl((u,d)=>{const f=u.positionHandler(h,a,this,u);l[d]=Object.assign(f,this._calcCornerCoords(u,f))}),l}_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(K(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=y({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,n=y({hasBorders:s,hasControls:r},e),o=this.getViewportTransform(),a=n.hasBorders,c=n.hasControls,h=Z(o,this.calcTransformMatrix()),l=ts(h);t.save(),t.translate(l.translateX,l.translateY),t.lineWidth=1*this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(l.angle-=180),t.rotate(K(this.group?l.angle:this.angle)),a&&this.drawBorders(t,l,e),c&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let r;if(s&&s.forActiveSelection||this.group){const n=Cr(this.width,this.height,zs(e)),o=this.isStrokeAccountedForInDimensions()?Ri:(this.strokeUniform?new _().scalarAdd(this.canvas?this.canvas.getZoom():1):new _(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);r=n.add(o).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,n)=>{r.withConnection&&r.getVisibility(this,n)&&(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:n,cornerColor:o}=this,a=y({cornerStrokeColor:r,cornerDashArray:n,cornerColor:o},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=a.cornerColor,this.transparentCorners||(t.strokeStyle=a.cornerStrokeColor),this._setLineDash(t,a.cornerDashArray),this.forEachControl((c,h)=>{if(c.getVisibility(this,h)){const l=this.oCoords[h];c.render(t,l.x,l.y,a,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&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,n=this.height+4;return e.clearRect(-r/2,-n/2,r,n),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 xa(i,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(i.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),i}v(Zs,"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 at extends Zs{}xa(at,[qo]),C.setClass(at),C.setClass(at,"object");const wa=(i,t,e,s)=>{const r=2*(s=Math.round(s))+1,{data:n}=i.getImageData(t-s,e-s,r,r);for(let o=3;o<n.length;o+=4)if(n[o]>0)return!1;return!0};class Ca{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new _(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new _(1/this.options.scaleX,1/this.options.scaleY):new _(1,1)}createSideVector(t,e){const s=Mr(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 _(t);return e.y+=e.x*Math.tan(K(this.options.skewY)),e.x+=e.y*Math.tan(K(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const uu=new _;class cs extends Ca{static getOrthogonalRotationFactor(t,e){const s=e?Ir(t,e):ea(t);return Math.abs(s)<me?-1:1}constructor(t,e,s,r){super(r),v(this,"AB",void 0),v(this,"AC",void 0),v(this,"alpha",void 0),v(this,"bisector",void 0),this.A=new _(t),this.B=new _(e),this.C=new _(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=Ir(this.AB,this.AC),this.bisector=jr(tn(this.AB.eq(uu)?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),n=en(r),o=cs.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*o)}projectBevel(){const t=[];return(this.alpha%te==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),n=this.options.strokeUniform?Dr(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return Dr(r)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(r))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],r=new _(cs.getOrthogonalRotationFactor(this.bisector),cs.getOrthogonalRotationFactor(new _(this.bisector.y,this.bisector.x)));return[new _(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(r),new _(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(r)].forEach(n=>{sn(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:r,skewY:n,scaleX:o,scaleY:a,strokeUniform:c}=this.options,h=new _(Math.tan(K(r)),Math.tan(K(n))),l=this.strokeProjectionMagnitude,u=c?l/a/Math.sqrt(1/a**2+1/o**2*h.y**2):l/Math.sqrt(1+h.y**2),d=new _(Math.sqrt(Math.max(l**2-u**2,0)),u),f=c?l/Math.sqrt(1+h.x**2*(1/a)**2/(1/o+1/o*h.x*h.y)**2):l/Math.sqrt(1+h.x**2/(1+h.x*h.y)**2),g=new _(f,Math.sqrt(Math.max(l**2-f**2,0)));return[g,g.scalarMultiply(-1),d,d.scalarMultiply(-1)].map(p=>this.applySkew(c?p.multiply(this.strokeUniformScalar):p)).forEach(p=>{sn(p,t,e)&&s.push(this.applySkew(this.A).add(p))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%te==0,s=this.applySkew(this.A),r=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),o=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),a=ns(r,o)>0,c=a?r:n,h=a?n:r;return this.isSkewed()?t.push(...this.projectRoundWithSkew(c,h)):t.push(...this.projectRoundNoSkew(c,h)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Oa extends Ca{constructor(t,e,s){super(s),this.A=new _(t),this.T=new _(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(en(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 _(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 cs(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new _(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(jr(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 ka=function(i,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(i.length===0)return s;const r=i.reduce((n,o)=>(n[n.length-1].eq(o)||n.push(new _(o)),n),[new _(i[0])]);if(r.length===1)e=!0;else if(!e){const n=r[0],o=((a,c)=>{for(let h=a.length-1;h>=0;h--)if(c(a[h],h,a))return h;return-1})(r,a=>!a.eq(n));r.splice(o+1)}return r.forEach((n,o,a)=>{let c,h;o===0?(h=a[1],c=e?n:a[a.length-1]):o===a.length-1?(c=a[o-1],h=e?n:a[0]):(c=a[o-1],h=a[o+1]),e&&a.length===1?s.push(...new Oa(n,n,t).project()):!e||o!==0&&o!==a.length-1?s.push(...new cs(n,c,h,t).project()):s.push(...new Oa(n,o===0?h:c,t).project())}),s},fn=i=>{const t={};return Object.keys(i).forEach(e=>{t[e]={},Object.keys(i[e]).forEach(s=>{t[e][s]=y({},i[e][s])})}),t},Ma=i=>i.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),Ar=i=>{const t=[];for(let e,s=0;s<i.length;s++)(e=du(i,s))!==!1&&t.push(e);return t},du=(i,t)=>{const e=i.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return i.charAt(t);if(55296<=e&&e<=56319){if(i.length<=t+1)throw"High surrogate without following low surrogate";const r=i.charCodeAt(t+1);if(56320>r||r>57343)throw"High surrogate without following low surrogate";return i.charAt(t)+i.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=i.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var fu=Object.freeze({__proto__:null,capitalize:function(i){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(i.charAt(0).toUpperCase()).concat(t?i.slice(1):i.slice(1).toLowerCase())},escapeXml:Ma,graphemeSplit:Ar});const Lr=function(i,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return i.fill!==t.fill||i.stroke!==t.stroke||i.strokeWidth!==t.strokeWidth||i.fontSize!==t.fontSize||i.fontFamily!==t.fontFamily||i.fontWeight!==t.fontWeight||i.fontStyle!==t.fontStyle||i.textBackgroundColor!==t.textBackgroundColor||i.deltaY!==t.deltaY||e&&(i.overline!==t.overline||i.underline!==t.underline||i.linethrough!==t.linethrough)},Da=(i,t)=>{const e=t.split(`
|
|
38
|
+
`),s=[];let r=-1,n={};i=fn(i);for(let o=0;o<e.length;o++){const a=Ar(e[o]);if(i[o])for(let c=0;c<a.length;c++){r++;const h=i[o][c];h&&Object.keys(h).length>0&&(Lr(n,h,!0)?s.push({start:r,end:r+1,style:h}):s[s.length-1].end++),n=h||{}}else r+=a.length,n={}}return s},Ia=(i,t)=>{if(!Array.isArray(i))return fn(i);const e=t.split(Ai),s={};let r=-1,n=0;for(let o=0;o<e.length;o++){const a=Ar(e[o]);for(let c=0;c<a.length;c++)r++,i[n]&&i[n].start<=r&&r<i[n].end&&(s[o]=s[o]||{},s[o][c]=y({},i[n].style),r===i[n].end-1&&n++)}return s},Te=["display","transform",st,"fill-opacity","fill-rule","opacity",yt,"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 ja(i,t){const e=i.nodeName,s=i.getAttribute("class"),r=i.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let o;if(o=new RegExp("^"+e,"i"),t=t.replace(o,""),r&&t.length&&(o=new RegExp("#"+r+n,"i"),t=t.replace(o,"")),s&&t.length){const a=s.split(" ");for(let c=a.length;c--;)o=new RegExp("\\."+a[c]+n,"i"),t=t.replace(o,"")}return t.length===0}function gu(i,t){let e=!0;const s=ja(i,t.pop());return s&&t.length&&(e=function(r,n){let o,a=!0;for(;r.parentElement&&r.parentElement.nodeType===1&&n.length;)a&&(o=n.pop()),a=ja(r=r.parentElement,o);return n.length===0}(i,t)),s&&e&&t.length===0}const pu=i=>{var t;return(t=ru[i])!==null&&t!==void 0?t:i},mu=new RegExp("(".concat(os,")"),"gi"),Ea=i=>i.replace(mu," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var Pa,Aa,La,Fa,Ra,Ba,Wa;const ft="(".concat(os,")"),vu=String.raw(Pa||(Pa=Ht(["(skewX)(",")"],["(skewX)\\(","\\)"])),ft),yu=String.raw(Aa||(Aa=Ht(["(skewY)(",")"],["(skewY)\\(","\\)"])),ft),bu=String.raw(La||(La=Ht(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),ft,ft,ft),_u=String.raw(Fa||(Fa=Ht(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),ft,ft),Tu=String.raw(Ra||(Ra=Ht(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),ft,ft),Su=String.raw(Ba||(Ba=Ht(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),ft,ft,ft,ft,ft,ft),gn="(?:".concat(Su,"|").concat(Tu,"|").concat(bu,"|").concat(_u,"|").concat(vu,"|").concat(yu,")"),xu="(?:".concat(gn,"*)"),wu=String.raw(Wa||(Wa=Ht(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),xu),Cu=new RegExp(wu),Ou=new RegExp(gn),ku=new RegExp(gn,"g");function pn(i){const t=[];if(!(i=Ea(i).replace(/\s*([()])\s*/gi,"$1"))||i&&!Cu.test(i))return[...ut];for(const e of i.matchAll(ku)){const s=Ou.exec(e[0]);if(!s)continue;let r=ut;const n=s.filter(g=>!!g),[,o,...a]=n,[c,h,l,u,d,f]=a.map(g=>parseFloat(g));switch(o){case"translate":r=es(c,h);break;case Li:r=ss({angle:c},{x:h,y:l});break;case vr:r=Sr(c,h);break;case Ze:r=Wi(c);break;case Je:r=Xi(c);break;case"matrix":r=[c,h,l,u,d,f]}t.push(r)}return Tr(t)}function Mu(i,t,e,s){const r=Array.isArray(t);let n,o=t;if(i!==st&&i!==yt||t!==vt){if(i==="strokeUniform")return t==="non-scaling-stroke";if(i==="strokeDashArray")o=t===vt?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(i==="transformMatrix")o=e&&e.transformMatrix?Z(e.transformMatrix,pn(t)):pn(t);else if(i==="visible")o=t!==vt&&t!=="hidden",e&&e.visible===!1&&(o=!1);else if(i==="opacity")o=parseFloat(t),e&&e.opacity!==void 0&&(o*=e.opacity);else if(i==="textAnchor")o=t==="start"?R:t==="end"?Q:E;else if(i==="charSpacing")n=Ee(t,s)/s*1e3;else if(i==="paintFirst"){const a=t.indexOf(st),c=t.indexOf(yt);o=st,(a>-1&&c>-1&&c<a||a===-1&&c>-1)&&(o=yt)}else{if(i==="href"||i==="xlink:href"||i==="font")return t;if(i==="imageSmoothing")return t==="optimizeQuality";n=r?t.map(Ee):Ee(t,s)}}else o="";return!r&&isNaN(n)?o:n}function Du(i,t){const e=i.match(su);if(!e)return;const s=e[1],r=e[3],n=e[4],o=e[5],a=e[6];s&&(t.fontStyle=s),r&&(t.fontWeight=isNaN(parseFloat(r))?r:parseFloat(r)),n&&(t.fontSize=Ee(n)),a&&(t.fontFamily=a),o&&(t.lineHeight=o==="normal"?1:o)}function Iu(i,t){i.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,r]=e.split(":");t[s.trim().toLowerCase()]=r.trim()})}function ju(i){const t={},e=i.getAttribute("style");return e&&(typeof e=="string"?Iu(e,t):function(s,r){Object.entries(s).forEach(n=>{let[o,a]=n;a!==void 0&&(r[o.toLowerCase()]=a)})}(e,t)),t}const Eu={stroke:"strokeOpacity",fill:"fillOpacity"};function ie(i,t,e){if(!i)return{};let s,r={},n=Ei;i.parentNode&&oa.test(i.parentNode.nodeName)&&(r=ie(i.parentElement,t,e),r.fontSize&&(s=n=Ee(r.fontSize)));const o=y(y(y({},t.reduce((h,l)=>{const u=i.getAttribute(l);return u&&(h[l]=u),h},{})),function(h){let l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u={};for(const d in l)gu(h,d.split(" "))&&(u=y(y({},u),l[d]));return u}(i,e)),ju(i));o[on]&&i.setAttribute(on,o[on]),o[nn]&&(s=Ee(o[nn],n),o[nn]="".concat(s));const a={};for(const h in o){const l=pu(h),u=Mu(l,o[h],r,s);a[l]=u}a&&a.font&&Du(a.font,a);const c=y(y({},r),a);return oa.test(i.nodeName)?c:function(h){const l=at.getDefaults();return Object.entries(Eu).forEach(u=>{let[d,f]=u;if(h[f]===void 0||h[d]==="")return;if(h[d]===void 0){if(!l[d])return;h[d]=l[d]}if(h[d].indexOf("url(")===0)return;const g=new B(h[d]);h[d]=g.setAlpha(P(g.getAlpha()*h[f],2)).toRgba()}),h}(c)}const Pu=["left","top","width","height","visible"],Xa=["rx","ry"];class Y extends at{static getDefaults(){return y(y({},super.getDefaults()),Y.ownDefaults)}constructor(t){super(),Object.assign(this,Y.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,n=-s/2,o=this.rx?Math.min(this.rx,e/2):0,a=this.ry?Math.min(this.ry,s/2):0,c=o!==0||a!==0;t.beginPath(),t.moveTo(r+o,n),t.lineTo(r+e-o,n),c&&t.bezierCurveTo(r+e-ve*o,n,r+e,n+ve*a,r+e,n+a),t.lineTo(r+e,n+s-a),c&&t.bezierCurveTo(r+e,n+s-ve*a,r+e-ve*o,n+s,r+e-o,n+s),t.lineTo(r+o,n+s),c&&t.bezierCurveTo(r+ve*o,n+s,r,n+s-ve*a,r,n+s-a),t.lineTo(r,n+a),c&&t.bezierCurveTo(r,n+ve*a,r+ve*o,n,r+o,n),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...Xa,...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=ie(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:o=0,width:a=0,height:c=0,visible:h=!0}=r,l=U(r,Pu);return new this(y(y(y({},e),l),{},{left:n,top:o,width:a,height:c,visible:!!(h&&a&&c)}))}}v(Y,"type","Rect"),v(Y,"cacheProperties",[...re,...Xa]),v(Y,"ownDefaults",{rx:0,ry:0}),v(Y,"ATTRIBUTE_NAMES",[...Te,"x","y","rx","ry","width","height"]),C.setClass(Y),C.setSVGClass(Y);const ne="initialization",Fr="added",mn="removed",Rr="imperative",za=(i,t)=>{const{strokeUniform:e,strokeWidth:s,width:r,height:n,group:o}=t,a=o&&o!==i?$s(o.calcTransformMatrix(),i.calcTransformMatrix()):null,c=a?t.getRelativeCenterPoint().transform(a):t.getRelativeCenterPoint(),h=!t.isStrokeAccountedForInDimensions(),l=e&&h?Vo(new _(s,s),void 0,i.calcTransformMatrix()):Ri,u=!e&&h?s:0,d=Cr(r+u,n+u,Tr([a,t.calcOwnMatrix()],!0)).add(l).scalarDivide(2);return[c.subtract(d),c.add(d)]};class Br{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:r}=t;return e===ne||e===Rr||!!s&&r!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ne&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:r}=e;if(s===Rr&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:o,width:a,height:c}=Gt(t.map(u=>za(r,u)).reduce((u,d)=>u.concat(d),[])),h=new _(a,c),l=new _(n,o).add(h.scalarDivide(2));if(s===ne){const u=this.getInitialSize(e,{size:h,center:l});return{center:l,relativeCorrection:new _(0,0),size:u}}return{center:l.transform(r.calcOwnMatrix()),size:h}}}v(Br,"type","strategy");class vn extends Br{shouldPerformLayout(t){return!0}}v(vn,"type","fit-content"),C.setClass(vn);const Au=["strategy"],Lu=["target","strategy","bubbles","prevStrategy"],Ha="layoutManager";class Js{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new vn;v(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=y(y({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[yr,mo,Ws,vo,pr,yo,mr,bo,Rl].map(r=>t.on(r,n=>this.performLayout(r===yr?{type:"object_modified",trigger:r,e:n,target:s}:{type:"object_modifying",trigger:r,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:r}=e;if(s===ne||s===Fr?this.subscribeTargets(t):s===mn&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),r&&r.fire("object:layout:before",{target:e,context:t}),s===Rr&&t.deep){const n=U(t,Au);e.forEachObject(o=>o.layoutManager&&o.layoutManager.performLayout(y(y({},n),{},{bubbles:!1,target:o})))}}getLayoutResult(t){const{target:e,strategy:s,type:r}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const o=r===ne?new _:e.getRelativeCenterPoint(),{center:a,correction:c=new _,relativeCorrection:h=new _}=n,l=o.subtract(a).add(c).transform(r===ne?ut:Tt(e.calcOwnMatrix()),!0).add(h);return{result:n,prevCenter:o,nextCenter:a,offset:l}}commitLayout(t,e){const{target:s}=t,{result:{size:r},nextCenter:n}=e;var o,a;s.set({width:r.x,height:r.y}),this.layoutObjects(t,e),t.type===ne?s.set({left:(o=t.x)!==null&&o!==void 0?o:n.x+r.x*rt(s.originX),top:(a=t.y)!==null&&a!==void 0?a:n.y+r.y*rt(s.originY)}):(s.setPositionByOrigin(n,E,E),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:n,prevStrategy:o}=t,a=U(t,Lu),{canvas:c}=s;s.fire("layout:after",{context:t,result:e}),c&&c.fire("object:layout:after",{context:t,result:e,target:s});const h=s.parent;n&&h!=null&&h.layoutManager&&((a.path||(a.path=[])).push(s),h.layoutManager.performLayout(y(y({},a),{},{target:h}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:Ha,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}C.setClass(Js,Ha);const Fu=["type","objects","layoutManager"];class Ru extends Js{performLayout(){}}class Nt extends _o(at){static getDefaults(){return y(y({},super.getDefaults()),Nt.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),v(this,"_activeObjects",[]),v(this,"__objectSelectionTracker",void 0),v(this,"__objectSelectionDisposer",void 0),Object.assign(this,Nt.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 Js,this.layoutManager.performLayout({type:ne,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(pe("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(pe("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),n=super.add(...r);return this._onAfterObjectsChange(Fr,r),n}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 n=this._filterObjectsBeforeEnteringGroup(s),o=super.insertAt(t,...n);return this._onAfterObjectsChange(Fr,n),o}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(mn,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 n=r.indexOf(s);n>-1&&(r.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&is(t,Z(Tt(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||(is(t,Z(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=at.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){this._renderBackground(t);for(let s=0;s<this._objects.length;s++){var e;(e=this.canvas)!==null&&e!==void 0&&e.preserveObjectStacking&&this._objects[s].group!==this?(t.save(),t.transform(...Tt(this.calcTransformMatrix())),this._objects[s].render(t),t.restore()):this._objects[s].group===this&&this._objects[s].render(t)}this._drawClipPath(t,this.clipPath)}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(y({target:this,type:Rr},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 n=r.includeDefaultValues;r.includeDefaultValues=s;const o=r[t||"toObject"](e);return r.includeDefaultValues=n,o})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return y(y(y({},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=Y.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:n}=t,o=U(t,Fu);return Promise.all([rs(r,e),Ys(o,e)]).then(a=>{let[c,h]=a;const l=new this(c,y(y(y({},o),h),{},{layoutManager:new Ru}));if(n){const u=C.getClass(n.type),d=C.getClass(n.strategy);l.layoutManager=new u(new d)}else l.layoutManager=new Js;return l.layoutManager.subscribeTargets({type:ne,target:l,targets:l.getObjects()}),l.setCoords(),l})}}v(Nt,"type","Group"),v(Nt,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),C.setClass(Nt);const Ya=(i,t)=>Math.min(t.width/i.width,t.height/i.height),Va=(i,t)=>Math.max(t.width/i.width,t.height/i.height);var Ga;const z="(".concat(os,")"),Bu="(M) (?:".concat(z," ").concat(z," ?)+"),Wu="(L) (?:".concat(z," ").concat(z," ?)+"),Xu="(H) (?:".concat(z," ?)+"),zu="(V) (?:".concat(z," ?)+"),Hu=String.raw(Ga||(Ga=Ht(["(Z)s*"],["(Z)\\s*"]))),Yu="(C) (?:".concat(z," ").concat(z," ").concat(z," ").concat(z," ").concat(z," ").concat(z," ?)+"),Vu="(S) (?:".concat(z," ").concat(z," ").concat(z," ").concat(z," ?)+"),Gu="(Q) (?:".concat(z," ").concat(z," ").concat(z," ").concat(z," ?)+"),Nu="(T) (?:".concat(z," ").concat(z," ?)+"),Uu="(A) (?:".concat(z," ").concat(z," ").concat(z," ([01]) ?([01]) ").concat(z," ").concat(z," ?)+"),Na="(?:(?:".concat(Bu,")")+"|(?:".concat(Wu,")")+"|(?:".concat(Xu,")")+"|(?:".concat(zu,")")+"|(?:".concat(Hu,")")+"|(?:".concat(Yu,")")+"|(?:".concat(Vu,")")+"|(?:".concat(Gu,")")+"|(?:".concat(Nu,")")+"|(?:".concat(Uu,"))"),$u={m:"l",M:"L"},qu=(i,t,e,s,r,n,o,a,c,h,l)=>{const u=It(i),d=jt(i),f=It(t),g=jt(t),p=e*r*f-s*n*g+o,m=s*r*f+e*n*g+a;return["C",h+c*(-e*r*d-s*n*u),l+c*(-s*r*d+e*n*u),p+c*(e*r*g+s*n*f),m+c*(s*r*g-e*n*f),p,m]},Ua=(i,t,e,s)=>{const r=Math.atan2(t,i),n=Math.atan2(s,e);return n>=r?n-r:2*Math.PI-(r-n)};function yn(i,t,e,s,r,n,o,a){let c;if(L.cachesBoundsOfCurve&&(c=[...arguments].join(),Bs.boundsOfCurveCache[c]))return Bs.boundsOfCurveCache[c];const h=Math.sqrt,l=Math.abs,u=[],d=[[0,0],[0,0]];let f=6*i-12*e+6*r,g=-3*i+9*e-9*r+3*o,p=3*e-3*i;for(let k=0;k<2;++k){if(k>0&&(f=6*t-12*s+6*n,g=-3*t+9*s-9*n+3*a,p=3*s-3*t),l(g)<1e-12){if(l(f)<1e-12)continue;const F=-p/f;0<F&&F<1&&u.push(F);continue}const O=f*f-4*p*g;if(O<0)continue;const x=h(O),I=(-f+x)/(2*g);0<I&&I<1&&u.push(I);const D=(-f-x)/(2*g);0<D&&D<1&&u.push(D)}let m=u.length;const b=m,T=qa(i,t,e,s,r,n,o,a);for(;m--;){const{x:k,y:O}=T(u[m]);d[0][m]=k,d[1][m]=O}d[0][b]=i,d[1][b]=t,d[0][b+1]=o,d[1][b+1]=a;const w=[new _(Math.min(...d[0]),Math.min(...d[1])),new _(Math.max(...d[0]),Math.max(...d[1]))];return L.cachesBoundsOfCurve&&(Bs.boundsOfCurveCache[c]=w),w}const Ku=(i,t,e)=>{let[s,r,n,o,a,c,h,l]=e;const u=((d,f,g,p,m,b,T)=>{if(g===0||p===0)return[];let w=0,k=0,O=0;const x=Math.PI,I=T*ji,D=jt(I),F=It(I),X=.5*(-F*d-D*f),ct=.5*(-F*f+D*d),W=g**2,H=p**2,nt=ct**2,zt=X**2,Dt=W*H-W*nt-H*zt;let fe=Math.abs(g),ge=Math.abs(p);if(Dt<0){const Me=Math.sqrt(1-Dt/(W*H));fe*=Me,ge*=Me}else O=(m===b?-1:1)*Math.sqrt(Dt/(W*nt+H*zt));const Ue=O*fe*ct/ge,$e=-O*ge*X/fe,Mi=F*Ue-D*$e+.5*d,ao=D*Ue+F*$e+.5*f;let dr=Ua(1,0,(X-Ue)/fe,(ct-$e)/ge),ke=Ua((X-Ue)/fe,(ct-$e)/ge,(-X-Ue)/fe,(-ct-$e)/ge);b===0&&ke>0?ke-=2*x:b===1&&ke<0&&(ke+=2*x);const Di=Math.ceil(Math.abs(ke/x*2)),qe=[],fr=ke/Di,F0=8/3*Math.sin(fr/4)*Math.sin(fr/4)/Math.sin(fr/2);let co=dr+fr;for(let Me=0;Me<Di;Me++)qe[Me]=qu(dr,co,F,D,fe,ge,Mi,ao,F0,w,k),w=qe[Me][5],k=qe[Me][6],dr=co,co+=fr;return qe})(h-i,l-t,r,n,a,c,o);for(let d=0,f=u.length;d<f;d++)u[d][1]+=i,u[d][2]+=t,u[d][3]+=i,u[d][4]+=t,u[d][5]+=i,u[d][6]+=t;return u},$a=i=>{let t=0,e=0,s=0,r=0;const n=[];let o,a=0,c=0;for(const h of i){const l=[...h];let u;switch(l[0]){case"l":l[1]+=t,l[2]+=e;case"L":t=l[1],e=l[2],u=["L",t,e];break;case"h":l[1]+=t;case"H":t=l[1],u=["L",t,e];break;case"v":l[1]+=e;case"V":e=l[1],u=["L",t,e];break;case"m":l[1]+=t,l[2]+=e;case"M":t=l[1],e=l[2],s=l[1],r=l[2],u=["M",t,e];break;case"c":l[1]+=t,l[2]+=e,l[3]+=t,l[4]+=e,l[5]+=t,l[6]+=e;case"C":a=l[3],c=l[4],t=l[5],e=l[6],u=["C",l[1],l[2],a,c,t,e];break;case"s":l[1]+=t,l[2]+=e,l[3]+=t,l[4]+=e;case"S":o==="C"?(a=2*t-a,c=2*e-c):(a=t,c=e),t=l[3],e=l[4],u=["C",a,c,l[1],l[2],t,e],a=u[3],c=u[4];break;case"q":l[1]+=t,l[2]+=e,l[3]+=t,l[4]+=e;case"Q":a=l[1],c=l[2],t=l[3],e=l[4],u=["Q",a,c,t,e];break;case"t":l[1]+=t,l[2]+=e;case"T":o==="Q"?(a=2*t-a,c=2*e-c):(a=t,c=e),t=l[1],e=l[2],u=["Q",a,c,t,e];break;case"a":l[6]+=t,l[7]+=e;case"A":Ku(t,e,l).forEach(d=>n.push(d)),t=l[6],e=l[7];break;case"z":case"Z":t=s,e=r,u=["Z"]}u?(n.push(u),o=u[0]):o=""}return n},Wr=(i,t,e,s)=>Math.sqrt((e-i)**2+(s-t)**2),qa=(i,t,e,s,r,n,o,a)=>c=>{const h=c**3,l=(f=>3*f**2*(1-f))(c),u=(f=>3*f*(1-f)**2)(c),d=(f=>(1-f)**3)(c);return new _(o*h+r*l+e*u+i*d,a*h+n*l+s*u+t*d)},Ka=i=>i**2,Za=i=>2*i*(1-i),Ja=i=>(1-i)**2,Zu=(i,t,e,s,r,n,o,a)=>c=>{const h=Ka(c),l=Za(c),u=Ja(c),d=3*(u*(e-i)+l*(r-e)+h*(o-r)),f=3*(u*(s-t)+l*(n-s)+h*(a-n));return Math.atan2(f,d)},Ju=(i,t,e,s,r,n)=>o=>{const a=Ka(o),c=Za(o),h=Ja(o);return new _(r*a+e*c+i*h,n*a+s*c+t*h)},Qu=(i,t,e,s,r,n)=>o=>{const a=1-o,c=2*(a*(e-i)+o*(r-e)),h=2*(a*(s-t)+o*(n-s));return Math.atan2(h,c)},Qa=(i,t,e)=>{let s=new _(t,e),r=0;for(let n=1;n<=100;n+=1){const o=i(n/100);r+=Wr(s.x,s.y,o.x,o.y),s=o}return r},td=(i,t)=>{let e,s=0,r=0,n={x:i.x,y:i.y},o=y({},n),a=.01,c=0;const h=i.iterator,l=i.angleFinder;for(;r<t&&a>1e-4;)o=h(s),c=s,e=Wr(n.x,n.y,o.x,o.y),e+r>t?(s-=a,a/=2):(n=o,s+=a,r+=e);return y(y({},o),{},{angle:l(c)})},bn=i=>{let t,e,s=0,r=0,n=0,o=0,a=0;const c=[];for(const h of i){const l={x:r,y:n,command:h[0],length:0};switch(h[0]){case"M":e=l,e.x=o=r=h[1],e.y=a=n=h[2];break;case"L":e=l,e.length=Wr(r,n,h[1],h[2]),r=h[1],n=h[2];break;case"C":t=qa(r,n,h[1],h[2],h[3],h[4],h[5],h[6]),e=l,e.iterator=t,e.angleFinder=Zu(r,n,h[1],h[2],h[3],h[4],h[5],h[6]),e.length=Qa(t,r,n),r=h[5],n=h[6];break;case"Q":t=Ju(r,n,h[1],h[2],h[3],h[4]),e=l,e.iterator=t,e.angleFinder=Qu(r,n,h[1],h[2],h[3],h[4]),e.length=Qa(t,r,n),r=h[3],n=h[4];break;case"Z":e=l,e.destX=o,e.destY=a,e.length=Wr(r,n,o,a),r=o,n=a}s+=e.length,c.push(e)}return c.push({length:s,x:r,y:n}),c},tc=function(i,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:bn(i),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const r=e[s],n=t/r.length,o=i[s];switch(r.command){case"M":return{x:r.x,y:r.y,angle:0};case"Z":return y(y({},new _(r.x,r.y).lerp(new _(r.destX,r.destY),n)),{},{angle:Math.atan2(r.destY-r.y,r.destX-r.x)});case"L":return y(y({},new _(r.x,r.y).lerp(new _(o[1],o[2]),n)),{},{angle:Math.atan2(o[2]-r.y,o[1]-r.x)});case"C":case"Q":return td(r,t)}},ed=new RegExp(Na,"gi"),sd=new RegExp(Na,"i"),ec=i=>{i=Ea(i);const t=[];for(let[e]of i.matchAll(ed)){const s=[];let r;do{if(r=sd.exec(e),!r)break;const n=r.filter(a=>a);n.shift();const o=n.map(a=>{const c=Number.parseFloat(a);return Number.isNaN(c)?a:c});if(s.push(o),n.length<=1)break;n.shift(),e=e.replace(new RegExp("".concat(n.join(" ?")," ?$")),"")}while(r);s.reverse().forEach((n,o)=>{const a=$u[n[0]];o>0&&(a=="l"||a=="L")&&(n[0]=a),t.push(n)})}return t},rd=function(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new _(i[0]),s=new _(i[1]),r=1,n=0;const o=[],a=i.length,c=a>2;let h;for(c&&(r=i[2].x<s.x?-1:i[2].x===s.x?0:1,n=i[2].y<s.y?-1:i[2].y===s.y?0:1),o.push(["M",e.x-r*t,e.y-n*t]),h=1;h<a;h++){if(!e.eq(s)){const l=e.midPointFrom(s);o.push(["Q",e.x,e.y,l.x,l.y])}e=i[h],h+1<i.length&&(s=i[h+1])}return c&&(r=e.x>i[h-2].x?1:e.x===i[h-2].x?0:-1,n=e.y>i[h-2].y?1:e.y===i[h-2].y?0:-1),o.push(["L",e.x+r*t,e.y+n*t]),o},sc=(i,t)=>i.map(e=>e.map((s,r)=>r===0||t===void 0?s:P(s,t)).join(" ")).join(" "),id=(i,t)=>Math.floor(Math.random()*(t-i+1))+i;function nd(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||De,s=new(gr()).XMLHttpRequest,r=t.signal,n=function(){s.abort()},o=function(){r&&r.removeEventListener("abort",n),s.onerror=s.ontimeout=De};if(r&&r.aborted)throw new fo("request");return r&&r.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(o(),e(s),s.onreadystatechange=De)},s.onerror=s.ontimeout=o,s.open("get",i,!0),s.send(),s}var rc=Object.freeze({__proto__:null,addTransformToObject:Ho,animate:Qi,animateColor:Qo,applyTransformToObject:is,calcAngleBetweenVectors:Ir,calcDimensionsMatrix:zs,calcPlaneChangeMatrix:$s,calcVectorRotation:ea,cancelAnimFrame:So,capValue:Ae,composeMatrix:ko,copyCanvasElement:i=>{var t;const e=tt();return e.width=i.width,e.height=i.height,(t=e.getContext("2d"))===null||t===void 0||t.drawImage(i,0,0),e},cos:It,createCanvasElement:tt,createImage:xo,createRotateMatrix:ss,createScaleMatrix:Sr,createSkewXMatrix:Wi,createSkewYMatrix:Xi,createTranslateMatrix:es,createVector:Mr,crossProduct:ns,degreesToRadians:K,dotProduct:sa,ease:Vl,enlivenObjectEnlivables:Ys,enlivenObjects:rs,findScaleToCover:Va,findScaleToFit:Ya,getBoundsOfCurve:yn,getOrthonormalVector:en,getPathSegmentsInfo:bn,getPointOnPath:tc,getPointer:zo,getRandomInt:id,getRegularPolygonPath:(i,t)=>{const e=2*Math.PI/i;let s=-me;i%2==0&&(s+=e/2);const r=new Array(i+1);for(let n=0;n<i;n++){const o=n*e+s,{x:a,y:c}=new _(It(o),jt(o)).scalarMultiply(t);r[n]=[n===0?"M":"L",a,c]}return r[i]=["Z"],r},getSmoothPathFromPoints:rd,getSvgAttributes:i=>{const t=["instantiated_by_use","style","id","class"];switch(i){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:jr,groupSVGElements:(i,t)=>i&&i.length===1?i[0]:new Nt(i,t),hasStyleChanged:Lr,invertTransform:Tt,isBetweenVectors:sn,isIdentityMatrix:wo,isTouchEvent:wr,isTransparent:wa,joinPath:sc,loadImage:Hs,magnitude:Dr,makeBoundingBoxFromPoints:Gt,makePathSimpler:$a,matrixToSVG:Vs,mergeClipPaths:(i,t)=>{var e;let s=i,r=t;s.inverted&&!r.inverted&&(s=t,r=i),Ni(r,(e=r.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&r.inverted;return n&&(s.inverted=r.inverted=!1),new Nt([s],{clipPath:r,inverted:n})},multiplyTransformMatrices:Z,multiplyTransformMatrixArray:Tr,parsePath:ec,parsePreserveAspectRatioAttribute:Eo,parseUnit:Ee,pick:je,projectStrokeOnPoints:ka,qrDecompose:ts,radiansToDegrees:be,removeFromArray:Ie,removeTransformFromObject:(i,t)=>{const e=Tt(t),s=Z(e,i.calcOwnMatrix());is(i,s)},removeTransformMatrixForSvgParsing:(i,t)=>{let e=i._findCenterFromElement();i.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:r,scaleY:n,angle:o,skewX:a}=ts(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(dt,r),s.set(_t,n),s.angle=o,s.skewX=a,s.skewY=0}})(i),e=e.transform(i.transformMatrix)),delete i.transformMatrix,t&&(i.scaleX*=t.scaleX,i.scaleY*=t.scaleY,i.cropX=t.cropX,i.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,i.width=t.width,i.height=t.height),i.setPositionByOrigin(e,E,E)},request:nd,requestAnimFrame:Xs,resetObjectTransform:Yo,rotatePoint:(i,t,e)=>i.rotate(e,t),rotateVector:tn,saveObjectTransform:Gi,sendObjectToPlane:Ni,sendPointToPlane:ee,sendVectorToPlane:Vo,setStyle:Ns,sin:jt,sizeAfterTransform:Cr,string:fu,stylesFromArray:Ia,stylesToArray:Da,toDataURL:Bi,toFixed:P,transformPath:(i,t,e)=>(e&&(t=Z(t,[1,0,0,1,-e.x,-e.y])),i.map(s=>{const r=[...s];for(let n=1;n<s.length-1;n+=2){const{x:o,y:a}=ht({x:s[n],y:s[n+1]},t);r[n]=o,r[n+1]=a}return r})),transformPoint:ht});class od extends Xo{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),v(this,"upper",void 0),v(this,"container",void 0);const{el:r}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(r,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e});const o=this.createContainerElement();o.classList.add(s),r.parentNode&&r.parentNode.replaceChild(o,r),o.append(r,n),this.container=o}createUpperCanvas(){const{el:t}=this.lower,e=tt();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=Ke().createElement("div");return t.setAttribute("data-fabric","wrapper"),Ns(t,{position:"relative"}),Wo(t),t}applyCanvasStyle(t,e){let{allowTouchScrolling:s}=e;Ns(t,{position:"absolute",left:"0",top:"0"}),function(r,n){const o=n?"manipulation":vt;Ns(r,{"touch-action":o,"-ms-touch-action":o})}(t,s),Wo(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:r}=this.upper;Bo(s,r,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),Yi(this.upper.el,t),Yi(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(),Vt().dispose(this.upper.el),delete this.upper,delete this.container}}class Xr extends Us{constructor(){super(...arguments),v(this,"targets",[]),v(this,"_hoveredTargets",[]),v(this,"_objectsToRender",void 0),v(this,"_currentTransform",null),v(this,"_groupSelector",null),v(this,"contextTopDirty",!1)}static getDefaults(){return y(y({},super.getDefaults()),Xr.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 od(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,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+r,-s+r),n.transform(...this.viewportTransform);const o=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=o,n.restore();const a=Math.round(r*this.getRetinaScaling());return wa(n,a,a,a)}_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===vr||e===dt||e===_t||e===Ws?r=this.centeredScaling||t.centeredScaling:e===Li&&(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=Q:["mr","tr","br"].includes(e)&&(s.x=R),["tl","mt","tr"].includes(e)?s.y=Pi:["bl","mb","br"].includes(e)&&(s.y=mt)),s}_setupCurrentTransform(t,e,s){var r;const n=e.group?ee(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:o="",control:a}=e.getActiveControl()||{},c=s&&a?(r=a.getActionHandler(t,e,a))===null||r===void 0?void 0:r.bind(a):$o,h=((f,g,p,m)=>{if(!g||!f)return"drag";const b=m.controls[g];return b.getActionName(p,b,m)})(s,o,t,e),l=t[this.centeredKey],u=this._shouldCenterTransform(e,h,l)?{x:E,y:E}:this._getOriginFromCorner(e,o),d={target:e,action:h,actionHandler:c,actionPerformed:!1,corner:o,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:u.x,originY:u.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:K(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:l,original:y(y({},Gi(e)),{},{originX:u.x,originY:u.y})};this._currentTransform=d,this.fire("before:transform",{e:t,transform:d})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:r,deltaY:n}=this._groupSelector,o=new _(e,s).transform(this.viewportTransform),a=new _(e+r,s+n).transform(this.viewportTransform),c=this.selectionLineWidth/2;let h=Math.min(o.x,a.x),l=Math.min(o.y,a.y),u=Math.max(o.x,a.x),d=Math.max(o.y,a.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(h,l,u-h,d-l)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,h+=c,l+=c,u-=c,d-=c,at.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(h,l,u-h,d-l))}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,wr(t))||r.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const o=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&o&&o!==s?(this.targets=n,s):o}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const r=this.getZoom(),n=t.padding/r;if(n){const[o,a,c,h]=s,l=Math.atan2(a.y-o.y,a.x-o.x),u=It(l)*n,d=jt(l)*n,f=u+d,g=u-d;s=[new _(o.x-g,o.y-f),new _(a.x+f,a.y-g),new _(c.x+g,c.y+f),new _(h.x-f,h.y+g)]}return q.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,ee(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(_r(r)&&r.subTargetCheck){const n=this._searchPossibleTargets(r._objects,e);n&&this.targets.push(n)}return r}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&_r(s)&&s.interactive&&this.targets[0]){const r=this.targets;for(let n=r.length-1;n>0;n--){const o=r[n];if(!_r(o)||!o.interactive)return o}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 n=zo(t),o=r.width||0,a=r.height||0;o&&a||(mt in r&&Pi in r&&(a=Math.abs(r.top-r.bottom)),Q in r&&R in r&&(o=Math.abs(r.right-r.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=ee(n,void 0,this.viewportTransform));const c=this.getRetinaScaling();c!==1&&(n.x/=c,n.y/=c);const h=o===0||a===0?new _(1,1):new _(s.width/o,s.height/a);return n.multiply(h)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=tt(),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 Pe(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,r=!1;const n=this.getActiveObjects(),o=[],a=[];t.forEach(c=>{n.includes(c)||(s=!0,c.fire("deselected",{e,target:c}),a.push(c))}),n.forEach(c=>{t.includes(c)||(s=!0,c.fire("selected",{e,target:c}),o.push(c))}),t.length>0&&n.length>0?(r=!0,s&&this.fire("selection:updated",{e,selected:o,deselected:a})):n.length>0?(r=!0,this.fire("selection:created",{e,selected:o})):t.length>0&&(r=!0,this.fire("selection:cleared",{e,deselected:a})),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,Pe(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),Pe(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(yr,r))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;Pe(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),n=super._toObject(t,e,s);return t.set(r),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&Pe(e)&&this._activeObject===e){const s=je(t,["angle","flipX","flipY",R,dt,_t,Ze,Je,mt]);return Ho(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const r=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(r)}}v(Xr,"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 ad{constructor(t){v(this,"targets",[]),v(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),Ie(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 cd=["target","oldTarget","fireCanvas","e"],St={passive:!1},hs=(i,t)=>{const e=i.getViewportPoint(t),s=i.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Se=function(i){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return i.addEventListener(...e)},wt=function(i){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return i.removeEventListener(...e)},hd={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 _n extends Xr{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),v(this,"_isClick",void 0),v(this,"textEditingManager",new ad(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Se,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,r=this._getEventPrefix();t(Ro(s),"resize",this._onResize),t(s,r+"down",this._onMouseDown),t(s,"".concat(r,"move"),this._onMouseMove,St),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,"dblclick",this._onDoubleClick),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,St)}removeListeners(){this.addOrRemove(wt,"remove");const t=this._getEventPrefix(),e=Et(this.upperCanvasEl);wt(e,"".concat(t,"up"),this._onMouseUp),wt(e,"touchend",this._onTouchEnd,St),wt(e,"".concat(t,"move"),this._onMouseMove,St),wt(e,"touchmove",this._onMouseMove,St)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=y({e:t},hs(this,t));this.fire("mouse:out",y(y({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",y({},s)),this._hoveredTargets.forEach(r=>{this.fire("mouse:out",y(y({},s),{},{target:r})),r&&r.fire("mouseout",y({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",y({e:t},hs(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 Se(this.upperCanvasEl,"drag",this._onDragProgress)}Vi(t)}_renderDragEffects(t,e,s){let r=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),r=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const o=this.contextTop;o.save(),o.transform(...this.viewportTransform),e&&(o.save(),e.transform(o),e.renderDragSourceEffect(t),o.restore(),r=!0),s&&(o.save(),s.transform(o),s.renderDropTargetEffect(t),o.restore(),r=!0),o.restore(),r&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==vt,s=e?this._activeObject:void 0,r={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};wt(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),n=this._dragSource,o={e:t,target:s,subTargets:r,dragSource:n,canDrop:!1,dropTarget:void 0};let a;this.fire(e,o),this._fireEnterLeaveEvents(s,o),s&&(s.canDrop(t)&&(a=s),s.fire(e,o));for(let c=0;c<r.length;c++){const h=r[c];h.canDrop(t)&&(a=h),h.fire(e,o)}this._renderDragEffects(t,n,a),this._dropTarget=a}_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",y({e:t,target:e,subTargets:s,dragSource:this._dragSource},hs(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&&Vi(t),this._basicEventHandler("contextmenu",r),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){t.preventDefault(),this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix(),r=Et(e);Se(r,"touchend",this._onTouchEnd,St),Se(r,"touchmove",this._onMouseMove,St),wt(e,"".concat(s,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();wt(e,"".concat(s,"move"),this._onMouseMove,St);const r=Et(e);Se(r,"".concat(s,"up"),this._onMouseUp),Se(r,"".concat(s,"move"),this._onMouseMove,St)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Et(this.upperCanvasEl);wt(s,"touchend",this._onTouchEnd,St),wt(s,"touchmove",this._onMouseMove,St),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Se(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=Et(this.upperCanvasEl);wt(r,"".concat(s,"up"),this._onMouseUp),wt(r,"".concat(s,"move"),this._onMouseMove,St),Se(e,"".concat(s,"move"),this._onMouseMove,St)}}_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,n=this._target,{button:o}=t;if(o)return(this.fireMiddleClick&&o===1||this.fireRightClick&&o===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let a,c,h=!1;if(s&&(this._finalizeCurrentTransform(t),h=s.actionPerformed),!r){const l=n===this._activeObject;this.handleSelection(t),h||(h=this._shouldRender(n)||!l&&n===this._activeObject)}if(n){const l=n.findControl(this.getViewportPoint(t),wr(t)),{key:u,control:d}=l||{};if(c=u,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),h=!0;else if(d){const f=d.getMouseUpHandler(t,n,d);f&&(a=this.getScenePoint(t),f.call(d,t,s,a.x,a.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==c)){const l=s.target&&s.target.controls[s.corner],u=l&&l.getMouseUpHandler(t,s.target,l);a=a||this.getScenePoint(t),u&&u.call(l,t,s,a.x,a.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),h?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 n=0;n<r.length;n++)r[n]!==s&&r[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,r=this.targets||[],n=y(y({e:t,target:s,subTargets:r},hs(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let o=0;o<r.length;o++)r[o]!==s&&r[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")}_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;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let r=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,r=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(e){const o=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const a=e.findControl(this.getViewportPoint(t),wr(t));if(e===this._activeObject&&(a||!n)){this._setupCurrentTransform(t,e,o);const c=a?a.control:void 0,h=this.getScenePoint(t),l=c&&c.getMouseDownHandler(t,e,c);l&&l.call(c,t,this._currentTransform,h.x,h.y)}}r&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),r&&this.requestRenderAll()}_resetTransformEventData(){this._target=void 0,this._pointer=void 0,this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=ee(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,n=this.targets,o=Math.max(r.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let a=0;a<o;a++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[a],oldTarget:r[a]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,r=this._hoveredTargets,n=this.targets,o=Math.max(r.length,n.length);this.fireSyntheticInOutEvents("drag",y(y({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let a=0;a<o;a++)this.fireSyntheticInOutEvents("drag",y(y({},e),{},{target:n[a],oldTarget:r[a]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:r,fireCanvas:n,e:o}=e,a=U(e,cd);const{targetIn:c,targetOut:h,canvasIn:l,canvasOut:u}=hd[t],d=r!==s;if(r&&d){const f=y(y({},a),{},{e:o,target:r,nextTarget:s},hs(this,o));n&&this.fire(u,f),r.fire(h,f)}if(s&&d){const f=y(y({},a),{},{e:o,target:s,previousTarget:r},hs(this,o));n&&this.fire(l,f),s.fire(c,f)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,r=s.target,n=r.group?ee(e,void 0,r.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:r,actionHandler:n,target:o}=e,a=!!n&&n(t,e,s.x,s.y);a&&o.setCoords(),r==="drag"&&a&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||a}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const r=Pe(this._activeObject)?this._activeObject:null,n=(!r||e.group!==r)&&e.findControl(this.getViewportPoint(t));if(n){const o=n.control;this.setCursor(o.cursorStyleHandler(t,o,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(o=>{s=o.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,r=Pe(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 n=s.getObjects();if(e===s){const o=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,o)||this.searchPossibleTargets(this._objects,o))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.exitEditing&&s.exitEditing();const n=new(C.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:r,deltaY:n}=this._groupSelector,o=new _(e,s),a=o.add(new _(r,n)),c=o.min(a),h=o.max(a).subtract(c),l=this.collectObjects({left:c.x,top:c.y,width:h.x,height:h.y},{includeIntersecting:!this.selectionFullyContained}),u=o.eq(a)?l[0]?[l[0]]:[]:l.length>1?l.filter(d=>!d.onSelect({e:t})).reverse():l;if(u.length===1)this.setActiveObject(u[0],t);else if(u.length>1){const d=C.getClass("ActiveSelection");this.setActiveObject(new d(u,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const ic={x1:0,y1:0,x2:0,y2:0},ld=y(y({},ic),{},{r1:0,r2:0}),ls=(i,t)=>isNaN(i)&&typeof t=="number"?t:i,ud=/^(\d+\.\d+)%|(\d+)%$/;function nc(i){return i&&ud.test(i)}function oc(i,t){const e=typeof i=="number"?i:typeof i=="string"?parseFloat(i)/(nc(i)?100:1):NaN;return Ae(0,ls(e,t),1)}const dd=/\s*;\s*/,fd=/\s*:\s*/;function gd(i,t){let e,s;const r=i.getAttribute("style");if(r){const o=r.split(dd);o[o.length-1]===""&&o.pop();for(let a=o.length;a--;){const[c,h]=o[a].split(fd).map(l=>l.trim());c==="stop-color"?e=h:c==="stop-opacity"&&(s=h)}}const n=new B(e||i.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:oc(i.getAttribute("offset"),0),color:n.toRgb(),opacity:ls(parseFloat(s||i.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function pd(i,t){const e=[],s=i.getElementsByTagName("stop"),r=oc(t,1);for(let n=s.length;n--;)e.push(gd(s[n],r));return e}function ac(i){return i.nodeName==="linearGradient"||i.nodeName==="LINEARGRADIENT"?"linear":"radial"}function cc(i){return i.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function At(i,t){return i.getAttribute(t)}function md(i,t){return function(e,s){let r,{width:n,height:o,gradientUnits:a}=s;return Object.keys(e).reduce((c,h)=>{const l=e[h];return l==="Infinity"?r=1:l==="-Infinity"?r=0:(r=typeof l=="string"?parseFloat(l):l,typeof l=="string"&&nc(l)&&(r*=.01,a==="pixels"&&(h!=="x1"&&h!=="x2"&&h!=="r2"||(r*=n),h!=="y1"&&h!=="y2"||(r*=o)))),c[h]=r,c},{})}(ac(i)==="linear"?function(e){return{x1:At(e,"x1")||0,y1:At(e,"y1")||0,x2:At(e,"x2")||"100%",y2:At(e,"y2")||0}}(i):function(e){return{x1:At(e,"fx")||At(e,"cx")||"50%",y1:At(e,"fy")||At(e,"cy")||"50%",r1:0,x2:At(e,"cx")||"50%",y2:At(e,"cy")||"50%",r2:At(e,"r")||"50%"}}(i),y(y({},t),{},{gradientUnits:cc(i)}))}class zr{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:r={},colorStops:n=[],offsetX:o=0,offsetY:a=0,gradientTransform:c,id:h}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:y(y({},e==="radial"?ld:ic),r),colorStops:n,offsetX:o,offsetY:a,gradientTransform:c,id:h?"".concat(h,"_").concat(ye()):ye()})}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 y(y({},je(this,t)),{},{type:this.type,coords:y({},this.coords),colorStops:this.colorStops.map(e=>y({},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():ut.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",o=this.colorStops.map(u=>y({},u)).sort((u,d)=>u.offset-d.offset);let a=-this.offsetX,c=-this.offsetY;var h;n==="objectBoundingBox"?(a/=t.width,c/=t.height):(a+=t.width/2,c+=t.height/2),(h=t)&&typeof h._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(a-=t.pathOffset.x,c-=t.pathOffset.y),r[4]-=a,r[5]-=c;const l=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(Vs(r),'"'),""].join(" ");if(this.type==="linear"){const{x1:u,y1:d,x2:f,y2:g}=this.coords;s.push("<linearGradient ",l,' x1="',u,'" y1="',d,'" x2="',f,'" y2="',g,`">
|
|
42
|
+
`)}else if(this.type==="radial"){const{x1:u,y1:d,x2:f,y2:g,r1:p,r2:m}=this.coords,b=p>m;s.push("<radialGradient ",l,' cx="',b?u:f,'" cy="',b?d:g,'" r="',b?p:m,'" fx="',b?f:u,'" fy="',b?g:d,`">
|
|
43
|
+
`),b&&(o.reverse(),o.forEach(w=>{w.offset=1-w.offset}));const T=Math.min(p,m);if(T>0){const w=T/Math.max(p,m);o.forEach(k=>{k.offset+=w*(1-k.offset)})}}return o.forEach(u=>{let{color:d,offset:f,opacity:g}=u;s.push("<stop ",'offset="',100*f+"%",'" style="stop-color:',d,g!==void 0?";stop-opacity: "+g:";",`"/>
|
|
44
44
|
`)}),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
|
|
45
|
-
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:
|
|
46
|
-
`)}static async fromObject(t,e){let{type:s,source:
|
|
47
|
-
`)]}_getOffsetTransform(){const t=
|
|
48
|
-
`];{const{radius:e}=this,s
|
|
49
|
-
`]}}static async fromElement(t,e,s){const
|
|
50
|
-
`)]}static async fromElement(t,e,s){const
|
|
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,
|
|
52
|
-
`)]}_render(t){const e=this.points.length,s=this.pathOffset.x,
|
|
53
|
-
`)}const Od=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let wn;class ft extends vc{static getDefaults(){return y(y({},super.getDefaults()),ft.ownDefaults)}constructor(t,e){super(),v(this,"__charBounds",[]),Object.assign(this,ft.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=_n(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(Ut)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,o,a;for(let c=0,h=this._textLines.length;c<h;c++)if((this.textAlign===Ut||c!==h-1&&!this.isEndOfWrapping(c))&&(i=0,n=this._textLines[c],e=this.getLineWidth(c),e<this.width&&(a=this.textLines[c].match(this._reSpacesAndTabs)))){s=a.length,t=(this.width-e)/s;for(let l=0;l<=n.length;l++)o=this.__charBounds[c][l],this._reSpaceAndTab.test(n[l])?(o.width+=t,o.kernedWidth+=t,o.left+=i,i+=t):o.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===yt?(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 j:t.textBaseline="middle";break;case"ascender":t.textBaseline=mt;break;case"descender":t.textBaseline=Ar}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,o){this._renderChars(t,e,s,i,n,o)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const a=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=a;continue}const c=this._textLines[n].length,h=this._getLineLeftOffset(n);let l,u,d=0,g=0,f=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let p=0;p<c;p++){const m=this.__charBounds[n][p];u=this.getValueOfPropertyAt(n,p,"textBackgroundColor"),this.path?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),t.fillStyle=u,u&&t.fillRect(-m.width/2,-a/this.lineHeight*(1-this._fontSizeFraction),m.width,a/this.lineHeight),t.restore()):u!==f?(l=s+h+g,this.direction==="rtl"&&(l=this.width-l-d),t.fillStyle=f,f&&t.fillRect(l,i,d,a/this.lineHeight),g=m.left,d=m.width,f=u):d+=m.kernedWidth}u&&!this.path&&(l=s+h+g,this.direction==="rtl"&&(l=this.width-l-d),t.fillStyle=u,t.fillRect(l,i,d,a/this.lineHeight)),i+=a}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=Fs.getFontCache(e),o=this._getFontDeclaration(e),a=s+t,c=s&&o===this._getFontDeclaration(i),h=e.fontSize/this.CACHE_FONT_SIZE;let l,u,d,g;if(s&&n[s]!==void 0&&(d=n[s]),n[t]!==void 0&&(g=l=n[t]),c&&n[a]!==void 0&&(u=n[a],g=u-d),l===void 0||d===void 0||u===void 0){const f=function(){if(!wn){const p=tt();p.width=p.height=0,wn=p.getContext("2d")}return wn}();this._setTextStyles(f,e,!0),l===void 0&&(g=l=f.measureText(t).width,n[t]=l),d===void 0&&c&&s&&(d=f.measureText(s).width,n[s]=d),c&&u===void 0&&(u=f.measureText(a).width,n[a]=u,g=u-d)}return{width:l*h,kernedWidth:g*h}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===Q,o=this.path,a=this._textLines[t],c=a.length,h=new Array(c);this.__charBounds[t]=h;for(let l=0;l<c;l++){const u=a[l];s=this._getGraphemeBox(u,t,l,e),h[l]=s,i+=s.kernedWidth,e=u}if(h[c]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},o&&o.segmentsInfo){let l=0;const u=o.segmentsInfo[o.segmentsInfo.length-1].length;switch(this.textAlign){case L:l=n?u-i:0;break;case j:l=(u-i)/2;break;case Q:l=n?0:u-i}l+=this.pathStartOffset*(n?-1:1);for(let d=n?c-1:0;n?d>=0:d<c;n?d--:d++)s=h[d],l>u?l%=u:l<0&&(l+=u),this._setGraphemeOnPath(l,s),l+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=tc(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===Q?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const o=this.getCompleteStyleDeclaration(e,s),a=i?this.getCompleteStyleDeclaration(e,s-1):{},c=this._measureChar(t,o,i,a);let h,l=c.kernedWidth,u=c.width;this.charSpacing!==0&&(h=this._getWidthOfCharSpacing(),u+=h,l+=h);const d={width:u,left:0,height:o.fontSize,kernedWidth:l,deltaY:o.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];d.left=g.left+g.width+c.kernedWidth-c.width}return d}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;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,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-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 i=this._getLeftOffset(),n=this._getTopOffset();for(let o=0,a=this._textLines.length;o<a;o++){const c=this.getHeightOfLine(o),h=c/this.lineHeight,l=this._getLineLeftOffset(o);this._renderTextLine(e,t,this._textLines[o],i+l,n+s+h,o),s+=c}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(st))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,o){const a=this.getHeightOfLine(o),c=this.textAlign.includes(Ut),h=this.path,l=!c&&this.charSpacing===0&&this.isEmptyStyles(o)&&!h,u=this.direction==="ltr",d=this.direction==="ltr"?1:-1,g=e.direction;let f,p,m,b,T,S="",C=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",u?"ltr":"rtl"),e.direction=u?"ltr":"rtl",e.textAlign=u?L:Q),n-=a*this._fontSizeFraction/this.lineHeight,l)return this._renderChar(t,e,o,0,s.join(""),i,n),void e.restore();for(let O=0,M=s.length-1;O<=M;O++)b=O===M||this.charSpacing||h,S+=s[O],m=this.__charBounds[o][O],C===0?(i+=d*(m.kernedWidth-m.width),C+=m.width):C+=m.kernedWidth,c&&!b&&this._reSpaceAndTab.test(s[O])&&(b=!0),b||(f=f||this.getCompleteStyleDeclaration(o,O),p=this.getCompleteStyleDeclaration(o,O+1),b=ji(f,p,!1)),b&&(h?(e.save(),e.translate(m.renderLeft,m.renderTop),e.rotate(m.angle),this._renderChar(t,e,o,O,S,-C/2,0),e.restore()):(T=i,this._renderChar(t,e,o,O,S,T,n)),S="",f=p,i+=d*C,C=0);e.restore()}_applyPatternGradientTransformText(t){const e=tt(),s=this.width+this.strokeWidth,i=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=s,e.height=i,n.beginPath(),n.moveTo(0,0),n.lineTo(s,0),n.lineTo(s,i),n.lineTo(0,i),n.closePath(),n.translate(s/2,i/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,s){let i,n;return Ct(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,o,a){const c=this._getStyleDeclaration(s,i),h=this.getCompleteStyleDeclaration(s,i),l=t==="fillText"&&h.fill,u=t==="strokeText"&&h.stroke&&h.strokeWidth;if(u||l){if(e.save(),e.font=this._getFontDeclaration(h),c.textBackgroundColor&&this._removeShadow(e),c.deltaY&&(a+=c.deltaY),l){const d=this._setFillStyles(e,h);e.fillText(n,o-d.offsetX,a-d.offsetY)}if(u){const d=this._setStrokeStyles(e,h);e.strokeText(n,o-d.offsetX,a-d.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),o=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),a={fontSize:n*s.size,deltaY:o+n*s.baseline};this.setSelectionStyles(a,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,o=this.isEndOfWrapping(t);let a=0;return i===Ut||i===Zs&&!o||i===Js&&!o||i===Hi&&!o?0:(i===j&&(a=s/2),i===Q&&(a=s),i===Zs&&(a=s/2),i===Js&&(a=s),n==="rtl"&&(i===Q||i===Ut||i===Js?a=0:i===L||i===Hi?a=-s:i!==j&&i!==Zs||(a=-s/2)),a)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,o=this._getWidthOfCharSpacing(),a=this.offsets[e];for(let c=0,h=this._textLines.length;c<h;c++){const l=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){s+=l;continue}const u=this._textLines[c],d=l/this.lineHeight,g=this._getLineLeftOffset(c);let f,p,m=0,b=0,T=this.getValueOfPropertyAt(c,0,e),S=this.getValueOfPropertyAt(c,0,st);const C=s+d*(1-this._fontSizeFraction);let O=this.getHeightOfChar(c,0),M=this.getValueOfPropertyAt(c,0,"deltaY");for(let D=0,F=u.length;D<F;D++){const N=this.__charBounds[c][D];f=this.getValueOfPropertyAt(c,D,e),p=this.getValueOfPropertyAt(c,D,st);const at=this.getHeightOfChar(c,D),et=this.getValueOfPropertyAt(c,D,"deltaY");if(n&&f&&p)t.save(),t.fillStyle=S,t.translate(N.renderLeft,N.renderTop),t.rotate(N.angle),t.fillRect(-N.kernedWidth/2,a*at+et,N.kernedWidth,this.fontSize/15),t.restore();else if((f!==T||p!==S||at!==O||et!==M)&&b>0){let B=i+g+m;this.direction==="rtl"&&(B=this.width-B-b),T&&S&&(t.fillStyle=S,t.fillRect(B,C+a*O+M,b,this.fontSize/15)),m=N.left,b=N.width,T=f,S=p,O=at,M=et}else b+=N.kernedWidth}let I=i+g+m;this.direction==="rtl"&&(I=this.width-I-b),t.fillStyle=p,f&&p&&t.fillRect(I,C+a*O+M,b-o,this.fontSize/15),s+=l}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const o=t.includes("'")||t.includes('"')||t.includes(",")||ft.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),o].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return Ei(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
|
|
54
|
-
`];let n=[];for(let o=0;o<e.length;o++)s[o]=this.graphemeSplit(e[o]),n=n.concat(s[o],
|
|
55
|
-
`]}_getSVGTextAndBg(r,t){const e=[],s=[];let i,n=r;this.backgroundColor&&s.push(...xn(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let o=0,a=this._textLines.length;o<a;o++)i=this._getLineLeftOffset(o),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",o))&&this._setSVGTextLineBg(s,o,t+i,n),this._setSVGTextLineText(e,o,t+i,n),n+=this.getHeightOfLine(o);return{textSpans:e,textBgRects:s}}_createTextCharSpan(r,t,e,s){const i=this.getSvgSpanStyles(t,r!==r.trim()||!!r.match(wd)),n=i?'style="'.concat(i,'"'):"",o=t.deltaY,a=o?' dy="'.concat(G(o,A.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(G(e,A.NUM_FRACTION_DIGITS),'" y="').concat(G(s,A.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(Ea(r),"</tspan>")}_setSVGTextLineText(r,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(Ut),o=this._textLines[t];let a,c,h,l,u,d="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let f=0,p=o.length-1;f<=p;f++)u=f===p||this.charSpacing,d+=o[f],h=this.__charBounds[t][f],g===0?(e+=h.kernedWidth-h.width,g+=h.width):g+=h.kernedWidth,n&&!u&&this._reSpaceAndTab.test(o[f])&&(u=!0),u||(a=a||this.getCompleteStyleDeclaration(t,f),c=this.getCompleteStyleDeclaration(t,f+1),u=ji(a,c,!0)),u&&(l=this._getStyleDeclaration(t,f),r.push(this._createTextCharSpan(d,l,e,s)),d="",a=c,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(r,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let o,a=0,c=0,h=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let l=0;l<i.length;l++){const{left:u,width:d,kernedWidth:g}=this.__charBounds[t][l];o=this.getValueOfPropertyAt(t,l,"textBackgroundColor"),o!==h?(h&&r.push(...xn(h,e+c,s,a,n)),c=u,a=d,h=o):a+=g}o&&r.push(...xn(h,e+c,s,a,n))}_getSVGLineTopOffset(r){let t,e=0;for(t=0;t<r;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(r){return"".concat(super.getSvgStyles(r)," white-space: pre;")}getSvgSpanStyles(r,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:o,fontStyle:a,fontWeight:c,deltaY:h}=r,l=this.getSvgTextDecoration(r);return[i?Ys(yt,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",o?"font-size: ".concat(o,"px; "):"",a?"font-style: ".concat(a,"; "):"",c?"font-weight: ".concat(c,"; "):"",l&&"text-decoration: ".concat(l,"; "),n?Ys(st,n):"",h?"baseline-shift: ".concat(-h,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(r){return["overline","underline","line-through"].filter(t=>r[t.replace("-","")]).join(" ")}}]),w.setClass(ft),w.setSVGClass(ft);class kd{constructor(t){v(this,"target",void 0),v(this,"__mouseDownInPlace",!1),v(this,"__dragStartFired",!1),v(this,"__isDraggingOver",!1),v(this,"__dragStartSelection",void 0),v(this,"__dragImageDisposer",void 0),v(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const o=this.target,a=o.canvas,c=new _(o.flipX?-1:1,o.flipY?-1:1),h=o._getCursorBoundaries(i),l=new _(h.left+h.leftOffset,h.top+h.topOffset).multiply(c).transform(o.calcTransformMatrix()),u=a.getScenePoint(t).subtract(l),d=o.getCanvasRetinaScaling(),g=o.getBoundingRect(),f=l.subtract(new _(g.left,g.top)),p=a.viewportTransform,m=f.add(u).transform(p,!0),b=o.backgroundColor,T=gn(o.styles);o.backgroundColor="";const S={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};o.setSelectionStyles(S,0,i),o.setSelectionStyles(S,n,o.text.length),o.dirty=!0;const C=o.toCanvasElement({enableRetinaScaling:a.enableRetinaScaling,viewportTransform:!0});o.backgroundColor=b,o.styles=T,o.dirty=!0,Ri(C,{position:"fixed",left:"".concat(-C.width,"px"),border:vt,width:"".concat(C.width/d,"px"),height:"".concat(C.height/d,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{C.remove()},jt(t.target||this.target.hiddenTextarea).body.appendChild(C),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(C,m.x,m.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),o=y({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,o)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const o=this.target,a=o.canvas;let c=o.getSelectionStartFromPointer(s);const{styles:h}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},l=n[Math.max(0,n.length-1)],u=0;if(this.__dragStartSelection){const d=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;c>d&&c<=g?c=d:c>g&&(c-=g-d),o.removeChars(d,g),delete this.__dragStartSelection}o._reNewline.test(l)&&(o._reNewline.test(o._text[c])||c===o._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=o,o.insertChars(n,h,c),a.setActiveObject(o),o.enterEditing(s),o.selectionStart=Math.min(c+u,o._text.length),o.selectionEnd=Math.min(o.selectionStart+n.length,o._text.length),o.hiddenTextarea.value=o.text,o._updateTextarea(),o.hiddenTextarea.focus(),o.fire(gi,{index:c+u,action:"drop"}),a.fire("text:changed",{target:o}),a.contextTopDirty=!0,a.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:o,selectionEnd:a}=this.__dragStartSelection,c=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||vt;c===vt?(i.selectionStart=o,i.selectionEnd=a,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),c==="move"&&(i.removeChars(o,a),i.selectionStart=i.selectionEnd=o,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(gi,{index:o,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const yc=/[ \n\.,;!\?\-]/;class Md extends ft{constructor(){super(...arguments),v(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return on({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:o=>{this._currentCursorOpacity=o,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}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!Lr.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!yc.test(n);)i+=e,n=s[i];return e===-1&&yc.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;jt(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const o=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(o).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,o=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,a=e.leftOffset,c=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,l=h.width/c,u=h.height/c,d=l-o,g=u-o,f=new _(e.left+a,e.top+e.topOffset+o).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new _(h.clientWidth/l,h.clientHeight/u));return f.x<0&&(f.x=0),f.x>d&&(f.x=d),f.y<0&&(f.y=0),f.y>g&&(f.y=g),f.x+=this.canvas._offset.left,f.y+=this.canvas._offset.top,{left:"".concat(f.x,"px"),top:"".concat(f.y,"px"),fontSize:"".concat(o,"px"),charHeight:o}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire(pi),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:o}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let a=i;a<this._unwrappedTextLines[s].length;a++)delete this.styles[s][a];if(this.styles[n])for(let a=o;a<this._unwrappedTextLines[n].length;a++){const c=this.styles[n][a];c&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+a-o]=c)}for(let a=s+1;a<=n;a++)delete this.styles[a];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const a=this.styles[s],c=o-i;for(let h=i;h<o;h++)delete a[h];for(const h in this.styles[s]){const l=parseInt(h,10);l>=o&&(a[l-c]=a[h],delete a[h])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},o=this._unwrappedTextLines[t].length,a=o===e;let c=!1;s||(s=1),this.shiftLineStyles(t,s);const h=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const u in this.styles[t]){const d=parseInt(u,10);d>=e&&(c=!0,n[d-e]=this.styles[t][u],a&&e===0||delete this.styles[t][u])}let l=!1;for(c&&!a&&(this.styles[t+s]=n,l=!0),(l||o>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:y({},i[s-1])}:h?this.styles[t+s]={0:y({},h)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],o=n?y({},n):{};s||(s=1);for(const c in o){const h=parseInt(c,10);h>=e&&(n[h+s]=o[h],o[h-s]||delete n[h])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=y({},i[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=y({},a)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let o,a=0;for(let c=0;c<t.length;c++)t[c]===`
|
|
56
|
-
`?(a++,n[a]=0):n[a]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),a&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],a),o=1;o<a;o++)n[o]>0?this.insertCharStyleObject(i.lineIndex+o,0,n[o],s):s&&this.styles[i.lineIndex+o]&&s[0]&&(this.styles[i.lineIndex+o][0]=s[0]),s=s&&s.slice(n[o]+1);n[o]>0&&this.insertCharStyleObject(i.lineIndex+o,0,n[o],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=L:this._selectionDirection===Q&&(this._selectionDirection=L,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Q?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Q:this._selectionDirection===L&&(this._selectionDirection=Q,this.selectionStart=e),this.selectionEnd=s)}}class Dd extends Md{initHiddenTextarea(){const t=this.canvas&&jt(this.canvas.getElement())||Ke(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(o=>{let[a,c]=o;return e.setAttribute(a,c)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(o=>{let[a,c]=o;return e.addEventListener(a,this[c].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;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(gi),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,o=i.length,a=this.selectionStart,c=this.selectionEnd,h=a!==c;let l,u,d,g,f=o-n;const p=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),m=a>p.selectionStart;h?(u=this._text.slice(a,c),f+=c-a):o<n&&(u=m?this._text.slice(c+f,c):this._text.slice(a,a-f));const b=i.slice(p.selectionEnd-f,p.selectionEnd);if(u&&u.length&&(b.length&&(l=this.getSelectionStyles(a,a+1,!1),l=b.map(()=>l[0])),h?(d=a,g=c):m?(d=c-u.length,g=c):(d=c,g=c+u.length),this.removeStyleFromTo(d,g)),b.length){const{copyPasteData:T}=Gt();e&&b.join("")===T.copiedText&&!A.disableStyleCopyPaste&&(l=T.copiedTextStyle),this.insertNewStyleBlock(b,a,l)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=Gt();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,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const o=i.charIndex,a=this._getWidthBeforeCursor(n,o),c=this._getIndexOnLine(n+1,a);return this._textLines[n].slice(o).length+c+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const o=i.charIndex,a=this._getWidthBeforeCursor(n,o),c=this._getIndexOnLine(n-1,a),h=this._textLines[n].slice(0,o),l=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+c-h.length+(1-l)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,o=this._getLineLeftOffset(t),a=0;for(let c=0,h=s.length;c<h;c++)if(i=this.__charBounds[t][c].width,o+=i,o>e){n=!0;const l=o-i,u=o,d=Math.abs(l-e);a=Math.abs(u-e)<d?c:c-1;break}return n||(a=s.length-1),a}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===Q);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=Re(0,this.selectionStart,i),this.selectionEnd=Re(0,this.selectionEnd,i),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 i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=L,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Q&&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=Q,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Q,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Cn=r=>!!r.button;class Id extends Dd{constructor(){super(...arguments),v(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new kd(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),Vr(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!Cn(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!Cn(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Cn(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(St(this.calcTransformMatrix())).add(new _(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let h=0;h<this._textLines.length&&s<=e.y;h++)s+=this.getHeightOfLine(h),n=h,h>0&&(i+=this._textLines[h-1].length+this.missingNewlineOffset(h-1));let o=Math.abs(this._getLineLeftOffset(n));const a=this._textLines[n].length,c=this.__charBounds[n];for(let h=0;h<a;h++){const l=o+c[h].kernedWidth;if(e.x<=l){Math.abs(e.x-l)<=Math.abs(e.x-o)&&i++;break}o=l,i++}return Math.min(this.flipX?a-i:i,this._text.length)}}const Yi="moveCursorUp",Gi="moveCursorDown",Vi="moveCursorLeft",Ni="moveCursorRight",Ui="exitEditing",Ed=y({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:Ui,27:Ui,33:Yi,34:Gi,35:Ni,36:Vi,37:Vi,38:Yi,39:Ni,40:Gi},keysMapRtl:{9:Ui,27:Ui,33:Yi,34:Gi,35:Vi,36:Ni,37:Ni,38:Yi,39:Vi,40:Gi},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class oe extends Id{static getDefaults(){return y(y({},super.getDefaults()),oe.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,y(y({},oe.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 Tn&&this.canvas.textEditingManager.remove(this),e instanceof Tn&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&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)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let h=0;h<n;h++)e+=this.getHeightOfLine(h);const o=this._getLineLeftOffset(n),a=this.__charBounds[n][i];a&&(s=a.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const c={top:e,left:o+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===Q||this.textAlign===Ut||this.textAlign===Js?c.left*=-1:this.textAlign===L||this.textAlign===Hi?c.left=o-(s>0?s:0):this.textAlign!==j&&this.textAlign!==Zs||(c.left=o-(s>0?s:0))),c}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,s){const i=this.get2DCursorLocation(s),n=i.lineIndex,o=i.charIndex>0?i.charIndex-1:0,a=this.getValueOfPropertyAt(n,o,"fontSize"),c=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/c,l=this.getValueOfPropertyAt(n,o,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(n)/this.lineHeight-a*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(n,o,st),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-h/2,u+e.top+l,h,a)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,o=this.textAlign.includes(Ut),a=this.get2DCursorLocation(i),c=this.get2DCursorLocation(n),h=a.lineIndex,l=c.lineIndex,u=a.charIndex<0?0:a.charIndex,d=c.charIndex<0?0:c.charIndex;for(let g=h;g<=l;g++){const f=this._getLineLeftOffset(g)||0;let p=this.getHeightOfLine(g),m=0,b=0,T=0;if(g===h&&(b=this.__charBounds[h][u].left),g>=h&&g<l)T=o&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===l)if(d===0)T=this.__charBounds[l][d].left;else{const I=this._getWidthOfCharSpacing();T=this.__charBounds[l][d-1].left+this.__charBounds[l][d-1].width-I}m=p,(this.lineHeight<1||g===l&&this.lineHeight>1)&&(p/=this.lineHeight);let S=s.left+f+b,C=p,O=0;const M=T-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",C=1,O=p):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Q||this.textAlign===Ut||this.textAlign===Js?S=this.width-S-M:this.textAlign===L||this.textAlign===Hi?S=s.left+f-T:this.textAlign!==j&&this.textAlign!==Zs||(S=s.left+f-T)),t.fillRect(S,s.top+s.topOffset+O,M,C),s.topOffset+=m}}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,st)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}v(oe,"ownDefaults",Ed),v(oe,"type","IText"),w.setClass(oe),w.setClass(oe,"i-text");class He extends oe{static getDefaults(){return y(y({},super.getDefaults()),He.ownDefaults)}constructor(t,e){super(t,y(y({},He.ownDefaults),e))}static createControls(){return{controls:Ca()}}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(Ut)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let o=0;o<t.graphemeLines.length;o++)t.graphemeText[i]===`
|
|
57
|
-
`&&o>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&o>0&&(s++,i++),n[o]={line:e,offset:s},i+=t.graphemeLines[o].length,s+=t.graphemeLines[o].length;return n}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,i=t+1,n=!1;const o=this._styleMap[t],a=this._styleMap[t+1];o&&(t=o.line,s=o.offset),a&&(i=a.line,n=i===t,e=a.offset);const c=t===void 0?this.styles:{line:this.styles[t]};for(const h in c)for(const l in c[h]){const u=parseInt(l,10);if(u>=s&&(!n||u<e))for(const d in c[h][l])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 i=this._styleMap[t];super._setStyleDeclaration(i.line,i.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),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,o)=>{let a=0;const c=e?this.graphemeSplit(n):this.wordSplit(n);return c.length===0?[{word:[],width:0}]:c.map(h=>{const l=e?[h]:this.graphemeSplit(h),u=this._measureWord(l,o,a);return i=Math.max(u,i),a+=l.length+s.length,{word:l,width:u}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let o=0,a=t.length;o<a;o++)n+=this._getGraphemeBox(t[o],e,o+i,s,!0).kernedWidth,s=t[o];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const a=this._getWidthOfCharSpacing(),c=this.splitByGrapheme,h=[],l=c?"":" ";let u=0,d=[],g=0,f=0,p=!0;e-=o;const m=Math.max(e,i,this.dynamicMinWidth),b=n[t];let T;for(g=0,T=0;T<b.length;T++){const{word:S,width:C}=b[T];g+=S.length,u+=f+C-a,u>m&&!p?(h.push(d),d=[],u=C,p=!0):u+=a,p||c||d.push(l),d=d.concat(S),f=c?0:this._measureWord([l],t,g),g++,p=!1}return T&&h.push(d),i+o>this.dynamicMinWidth&&(this.dynamicMinWidth=i-a+o),h}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,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 i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}v(He,"type","Textbox"),v(He,"textLayoutProperties",[...oe.textLayoutProperties,"width"]),v(He,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),w.setClass(He);class bc extends Li{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:o,height:a}=Vt(Ya(s,i)),c=new _(o,a);if(i.absolutePositioned)return{center:Zt(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:c};{const h=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:l=new _,correction:u=new _}=this.calcBoundingBox(e,t)||{};return{center:l.add(h),correction:u.subtract(h),size:c}}return{center:s.getRelativeCenterPoint().add(h),size:c}}}}v(bc,"type","clip-path"),w.setClass(bc);class _c extends Li{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new _(s.width||i.x,s.height||i.y)}}v(_c,"type","fixed"),w.setClass(_c);class jd extends qs{subscribeTargets(t){const e=t.target;t.targets.reduce((s,i)=>(i.parent&&s.add(i.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((i,n)=>(n.parent&&i.add(n.parent),i),new Set).forEach(i=>{!s.some(n=>n.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class kt extends Nt{static getDefaults(){return y(y({},super.getDefaults()),kt.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,kt.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new jd})}_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(i=>{const n=this._objects.findIndex(a=>a.isInFrontOf(i)),o=n===-1?this.size():n;this.insertAt(o,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(me("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(i=>{const{parent:n}=i;n&&s.add(n)}),t===mn?s.forEach(i=>{i._onAfterObjectsChange(Pi,e)}):s.forEach(i=>{i._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 i=y(y({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}v(kt,"type","ActiveSelection"),v(kt,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),w.setClass(kt),w.setClass(kt,"activeSelection");class Pd{constructor(){v(this,"resources",{})}applyFilters(t,e,s,i,n){const o=n.getContext("2d");if(!o)return;o.drawImage(e,0,0,s,i);const a={sourceWidth:s,sourceHeight:i,imageData:o.getImageData(0,0,s,i),originalEl:e,originalImageData:o.getImageData(0,0,s,i),canvasEl:n,ctx:o,filterBackend:this};t.forEach(h=>{h.applyTo(a)});const{imageData:c}=a;return c.width===s&&c.height===i||(n.width=c.width,n.height=c.height),o.putImageData(c,0,0),a}}class Tc{constructor(){let{tileSize:t=A.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};v(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),v(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=tt();s.width=t,s.height=e;const i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,o){const a=this.gl,c=n.getContext("2d");if(!a||!c)return;let h;o&&(h=this.getCachedTexture(o,e));const l={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:a,sourceTexture:this.createTexture(a,s,i,h?void 0:e),targetTexture:this.createTexture(a,s,i),originalTexture:h||this.createTexture(a,s,i,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},u=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,u),t.forEach(d=>{d&&d.applyTo(l)}),function(d){const g=d.targetCanvas,f=g.width,p=g.height,m=d.destinationWidth,b=d.destinationHeight;f===m&&p===b||(g.width=m,g.height=b)}(l),this.copyGLTo2D(a,l),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(l.sourceTexture),a.deleteTexture(l.targetTexture),a.deleteFramebuffer(u),c.setTransform(1,0,0,1,0,0),l}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:o,TEXTURE_2D:a,RGBA:c,UNSIGNED_BYTE:h,CLAMP_TO_EDGE:l,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:f}=t,p=t.createTexture();return t.bindTexture(a,p),t.texParameteri(a,u,n||o),t.texParameteri(a,d,n||o),t.texParameteri(a,g,l),t.texParameteri(a,f,l),i?t.texImage2D(a,0,c,c,h,i):t.texImage2D(a,0,c,e,s,0,c,h,null),p}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const o=s.height-i.height;n.drawImage(s,0,o,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,o=i*n*4;if(!s)return;const a=new Uint8Array(this.imageBuffer,0,o),c=new Uint8ClampedArray(this.imageBuffer,0,o);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,a);const h=new ImageData(c,i,n);s.putImageData(h,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 i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let On;function Ad(){const{WebGLProbe:r}=Gt();return r.queryWebGL(tt()),A.enableGLFiltering&&r.isSupported(A.textureSize)?new Tc({tileSize:A.textureSize}):new Pd}function kn(){return!On&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(On=Ad()),On}const Ld=["filters","resizeFilter","src","crossOrigin","type"],Sc=["cropX","cropY"];class Mt extends ct{static getDefaults(){return y(y({},super.getDefaults()),Mt.ownDefaults)}constructor(t,e){super(),v(this,"_lastScaleX",1),v(this,"_lastScaleY",1),v(this,"_filterScalingX",1),v(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Mt.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(be()),this.setElement(typeof t=="string"?(this.canvas&&jt(this.canvas.getElement())||Ke()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=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(e),t.classList.add(Mt.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=kn(!1);e instanceof Tc&&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&&Gt().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())}),y(y({},super.toObject([...Sc,...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,i=-this.height/2;let n=[],o=[],a="",c="";if(!e)return[];if(this.hasCrop()){const h=be();n.push('<clipPath id="imageCrop_'+h+`">
|
|
58
|
-
`,' <rect x="'+s+'" y="'+
|
|
45
|
+
`),s.join("")}toLive(t){const{x1:e,y1:s,x2:r,y2:n,r1:o,r2:a}=this.coords,c=this.type==="linear"?t.createLinearGradient(e,s,r,n):t.createRadialGradient(e,s,o,r,n,a);return this.colorStops.forEach(h=>{let{color:l,opacity:u,offset:d}=h;c.addColorStop(d,u!==void 0?new B(l).setAlpha(u).toRgba():l)}),c}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(y(y({},t),{},{colorStops:e?e.map(r=>y({},r)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const r=cc(t),n=e._findCenterFromElement();return new this(y({id:t.getAttribute("id")||void 0,type:ac(t),coords:md(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:pd(t,s.opacity),gradientUnits:r,gradientTransform:pn(t.getAttribute("gradientTransform")||"")},r==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}v(zr,"type","Gradient"),C.setClass(zr,"gradient"),C.setClass(zr,"linear"),C.setClass(zr,"radial");const vd=["type","source","patternTransform"];class Hr{get type(){return"pattern"}set type(t){pe("warn","Setting type has no effect",t)}constructor(t){v(this,"repeat","repeat"),v(this,"offsetX",0),v(this,"offsetY",0),v(this,"crossOrigin",""),this.id=ye(),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 y(y({},je(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:P(this.offsetX,L.NUM_FRACTION_DIGITS),offsetY:P(this.offsetY,L.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:r,repeat:n,id:o}=this,a=ls(this.offsetX/e,0),c=ls(this.offsetY/s,0),h=n==="repeat-y"||n==="no-repeat"?1+Math.abs(a||0):ls(r.width/e,0),l=n==="repeat-x"||n==="no-repeat"?1+Math.abs(c||0):ls(r.height/s,0);return['<pattern id="SVGID_'.concat(o,'" x="').concat(a,'" y="').concat(c,'" width="').concat(h,'" height="').concat(l,'">'),'<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:n}=t,o=U(t,vd);const a=await Hs(r,y(y({},e),{},{crossOrigin:o.crossOrigin}));return new this(y(y({},o),{},{patternTransform:n&&n.slice(0),source:a}))}}v(Hr,"type","Pattern"),C.setClass(Hr),C.setClass(Hr,"pattern");const yd=["path","left","top"],bd=["d"];class Be extends at{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:r,top:n}=e,o=U(e,yd);super(),Object.assign(this,Be.ownDefaults),this.setOptions(o),this._setPath(t||[],!0),typeof r=="number"&&this.set(R,r),typeof n=="number"&&this.set(mt,n)}_setPath(t,e){this.path=$a(Array.isArray(t)?t:ec(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new _(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 y(y({},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=sc(this.path,L.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
|
|
47
|
+
`)]}_getOffsetTransform(){const t=L.NUM_FRACTION_DIGITS;return" translate(".concat(P(-this.pathOffset.x,t),", ").concat(P(-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,E,E)}_calcBoundsFromPath(){const t=[];let e=0,s=0,r=0,n=0;for(const o of this.path)switch(o[0]){case"L":r=o[1],n=o[2],t.push(new _(e,s),new _(r,n));break;case"M":r=o[1],n=o[2],e=r,s=n;break;case"C":t.push(...yn(r,n,o[1],o[2],o[3],o[4],o[5],o[6])),r=o[5],n=o[6];break;case"Q":t.push(...yn(r,n,o[1],o[2],o[1],o[2],o[3],o[4])),r=o[3],n=o[4];break;case"Z":r=e,n=s}return Gt(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return y(y({},t),{},{pathOffset:new _(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=ie(t,this.ATTRIBUTE_NAMES,s),{d:n}=r;return new this(n,y(y(y({},U(r,bd)),e),{},{left:void 0,top:void 0}))}}v(Be,"type","Path"),v(Be,"cacheProperties",[...re,"path","fillRule"]),v(Be,"ATTRIBUTE_NAMES",[...Te,"d"]),C.setClass(Be),C.setSVGClass(Be);const _d=["left","top","radius"],hc=["radius","startAngle","endAngle","counterClockwise"];class oe extends at{static getDefaults(){return y(y({},super.getDefaults()),oe.ownDefaults)}constructor(t){super(),Object.assign(this,oe.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,K(this.startAngle),K(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(dt)}getRadiusY(){return this.get("radius")*this.get(_t)}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([...hc,...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=K(this.startAngle),r=K(this.endAngle),n=It(s)*e,o=jt(s)*e,a=It(r)*e,c=jt(r)*e,h=t>180?1:0,l=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(o," A ").concat(e," ").concat(e," 0 ").concat(h," ").concat(l," ").concat(a," ").concat(c,'" '),"COMMON_PARTS",` />
|
|
49
|
+
`]}}static async fromElement(t,e,s){const r=ie(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:o=0,radius:a=0}=r;return new this(y(y({},U(r,_d)),{},{radius:a,left:n-a,top:o-a}))}static fromObject(t){return super._fromObject(t)}}v(oe,"type","Circle"),v(oe,"cacheProperties",[...re,...hc]),v(oe,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),v(oe,"ATTRIBUTE_NAMES",["cx","cy","r",...Te]),C.setClass(oe),C.setSVGClass(oe);const Td=["x1","y1","x2","y2"],Sd=["x1","y1","x2","y2"],Tn=["x1","x2","y1","y2"];class xe extends at{constructor(){let[t,e,s,r]=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[0,0,0,0],n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,xe.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=r,this._setWidthHeight();const{left:o,top:a}=n;typeof o=="number"&&this.set(R,o),typeof a=="number"&&this.set(mt,a)}_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:n,top:o,width:a,height:c}=Gt([{x:t,y:e},{x:s,y:r}]),h=new _(n+a/2,o+c/2);this.setPositionByOrigin(h,E,E)}_set(t,e){return super._set(t,e),Tn.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var r;xt(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 _((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return y(y({},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:n,height:o}=this,a=t<=e?-1:1,c=s<=r?-1:1;return{x1:a*n/2,x2:a*-n/2,y1:c*o/2,y2:c*-o/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=ie(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:o=0,x2:a=0,y2:c=0}=r;return new this([n,o,a,c],U(r,Td))}static fromObject(t){let{x1:e,y1:s,x2:r,y2:n}=t,o=U(t,Sd);return this._fromObject(y(y({},o),{},{points:[e,s,r,n]}),{extraParam:"points"})}}v(xe,"type","Line"),v(xe,"cacheProperties",[...re,...Tn]),v(xe,"ATTRIBUTE_NAMES",Te.concat(Tn)),C.setClass(xe),C.setSVGClass(xe);class We extends at{static getDefaults(){return y(y({},super.getDefaults()),We.ownDefaults)}constructor(t){super(),Object.assign(this,We.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),'" />']}}v(We,"type","Triangle"),v(We,"ownDefaults",{width:100,height:100}),C.setClass(We),C.setSVGClass(We);const lc=["rx","ry"];class ae extends at{static getDefaults(){return y(y({},super.getDefaults()),ae.ownDefaults)}constructor(t){super(),Object.assign(this,ae.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(dt)}getRy(){return this.get("ry")*this.get(_t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...lc,...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,te,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const r=ie(t,this.ATTRIBUTE_NAMES,s);return r.left=(r.left||0)-r.rx,r.top=(r.top||0)-r.ry,new this(r)}}function xd(i){if(!i)return[];const t=i.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}v(ae,"type","Ellipse"),v(ae,"cacheProperties",[...re,...lc]),v(ae,"ownDefaults",{rx:0,ry:0}),v(ae,"ATTRIBUTE_NAMES",[...Te,"cx","cy","rx","ry"]),C.setClass(ae),C.setSVGClass(ae);const wd=["left","top"],uc={exactBoundingBox:!1};class Lt extends at{static getDefaults(){return y(y({},super.getDefaults()),Lt.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),v(this,"strokeDiff",void 0),Object.assign(this,Lt.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:r}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(R,s),typeof r=="number"&&this.set(mt,r)}isOpen(){return!0}_projectStrokeOnPoints(t){return ka(this.points,t,this.isOpen())}_calcDimensions(t){t=y({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(h=>h.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new _,strokeOffset:new _,strokeDiff:new _};const s=Gt(e),r=zs(y(y({},t),{},{scaleX:1,scaleY:1})),n=Gt(this.points.map(h=>ht(h,r,!0))),o=new _(this.scaleX,this.scaleY);let a=s.left+s.width/2,c=s.top+s.height/2;return this.exactBoundingBox&&(a-=c*Math.tan(K(this.skewX)),c-=a*Math.tan(K(this.skewY))),y(y({},s),{},{pathOffset:new _(a,c),strokeOffset:new _(n.left,n.top).subtract(new _(s.left,s.top)).multiply(o),strokeDiff:new _(s.width,s.height).subtract(new _(n.width,n.height)).multiply(o)})}_findCenterFromElement(){const t=Gt(this.points);return new _(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:r,height:n,pathOffset:o,strokeOffset:a,strokeDiff:c}=this._calcDimensions();this.set({width:r,height:n,pathOffset:o,strokeOffset:a,strokeDiff:c}),t&&this.setPositionByOrigin(new _(e+r/2,s+n/2),E,E)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new _(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let o;if(Object.keys(t).some(a=>this.strokeUniform||this.constructor.layoutProperties.includes(a))){var e,s;const{width:a,height:c}=this._calcDimensions(t);o=new _((e=t.width)!==null&&e!==void 0?e:a,(s=t.height)!==null&&s!==void 0?s:c)}else{var r,n;o=new _((r=t.width)!==null&&r!==void 0?r:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return o.multiply(new _(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===dt||t===_t)&&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 y(y({},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=L.NUM_FRACTION_DIGITS;for(let n=0,o=this.points.length;n<o;n++)t.push(P(this.points[n].x-e,r),",",P(this.points[n].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 n=0;n<e;n++){const o=this.points[n];t.lineTo(o.x-s,o.y-r)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(xd(t.getAttribute("points")),y(y({},U(ie(t,this.ATTRIBUTE_NAMES,s),wd)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}v(Lt,"ownDefaults",uc),v(Lt,"type","Polyline"),v(Lt,"layoutProperties",[Ze,Je,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),v(Lt,"cacheProperties",[...re,"points"]),v(Lt,"ATTRIBUTE_NAMES",[...Te]),C.setClass(Lt),C.setSVGClass(Lt);class Yr extends Lt{isOpen(){return!1}}v(Yr,"ownDefaults",uc),v(Yr,"type","Polygon"),C.setClass(Yr),C.setSVGClass(Yr);const dc=["fontSize","fontWeight","fontFamily","fontStyle"],fc=["underline","overline","linethrough"],gc=[...dc,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],pc=[...gc,...fc,"textBackgroundColor","direction"],Cd=[...dc,...fc,yt,"strokeWidth",st,"deltaY","textBackgroundColor"],Od={_reNewline:Ai,_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:R,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:R,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},Ut="justify",Vr="justify-left",Qs="justify-right",tr="justify-center";class mc extends at{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 n 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 n in s[r])if(s[r][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,r,n=0,o=!0,a=0;for(const c in e){s=0;for(const h in e[c]){const l=e[c][h]||{};n++,l[t]!==void 0?(r?l[t]!==r&&(o=!1):r=l[t],l[t]===this[t]&&delete l[t]):o=!1,Object.keys(l).length!==0?s++:delete e[c][h]}s===0&&delete e[c]}for(let c=0;c<this._textLines.length;c++)a+=this._textLines[c].length;o&&n===a&&(this[t]=r,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,r,n;for(r in e){for(n in s=e[r],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];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 n=zi(y(y({},this._getStyleDeclaration(s,r)),e),o=>o!==void 0);this._setStyleDeclaration(s,r,n)}getSelectionStyles(t,e,s){const r=[];for(let n=t;n<(e||t);n++)r.push(this.getStyleAtPosition(n,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 y(y({},je(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]}}v(mc,"_styleProperties",Cd);const kd=/ +/g,Md=/"/g;function Sn(i,t,e,s,r){return" ".concat(function(n,o){let{left:a,top:c,width:h,height:l}=o,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:L.NUM_FRACTION_DIGITS;const d=Gs(st,n,!1),[f,g,p,m]=[a,c,h,l].map(b=>P(b,u));return"<rect ".concat(d,' x="').concat(f,'" y="').concat(g,'" width="').concat(p,'" height="').concat(m,'"></rect>')}(i,{left:t,top:e,width:s,height:r}),`
|
|
53
|
+
`)}const Dd=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let xn;class gt extends mc{static getDefaults(){return y(y({},super.getDefaults()),gt.ownDefaults)}constructor(t,e){super(),v(this,"__charBounds",[]),Object.assign(this,gt.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=bn(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(Ut)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,r,n,o,a;for(let c=0,h=this._textLines.length;c<h;c++)if((this.textAlign===Ut||c!==h-1&&!this.isEndOfWrapping(c))&&(r=0,n=this._textLines[c],e=this.getLineWidth(c),e<this.width&&(a=this.textLines[c].match(this._reSpacesAndTabs)))){s=a.length,t=(this.width-e)/s;for(let l=0;l<=n.length;l++)o=this.__charBounds[c][l],this._reSpaceAndTab.test(n[l])?(o.width+=t,o.kernedWidth+=t,o.left+=r,r+=t):o.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===yt?(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 E:t.textBaseline="middle";break;case"ascender":t.textBaseline=mt;break;case"descender":t.textBaseline=Pi}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,n,o){this._renderChars(t,e,s,r,n,o)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let r=this._getTopOffset();for(let n=0,o=this._textLines.length;n<o;n++){const a=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){r+=a;continue}const c=this._textLines[n].length,h=this._getLineLeftOffset(n);let l,u,d=0,f=0,g=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let p=0;p<c;p++){const m=this.__charBounds[n][p];u=this.getValueOfPropertyAt(n,p,"textBackgroundColor"),this.path?(t.save(),t.translate(m.renderLeft,m.renderTop),t.rotate(m.angle),t.fillStyle=u,u&&t.fillRect(-m.width/2,-a/this.lineHeight*(1-this._fontSizeFraction),m.width,a/this.lineHeight),t.restore()):u!==g?(l=s+h+f,this.direction==="rtl"&&(l=this.width-l-d),t.fillStyle=g,g&&t.fillRect(l,r,d,a/this.lineHeight),f=m.left,d=m.width,g=u):d+=m.kernedWidth}u&&!this.path&&(l=s+h+f,this.direction==="rtl"&&(l=this.width-l-d),t.fillStyle=u,t.fillRect(l,r,d,a/this.lineHeight)),r+=a}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,r){const n=Bs.getFontCache(e),o=this._getFontDeclaration(e),a=s+t,c=s&&o===this._getFontDeclaration(r),h=e.fontSize/this.CACHE_FONT_SIZE;let l,u,d,f;if(s&&n[s]!==void 0&&(d=n[s]),n[t]!==void 0&&(f=l=n[t]),c&&n[a]!==void 0&&(u=n[a],f=u-d),l===void 0||d===void 0||u===void 0){const g=function(){if(!xn){const p=tt();p.width=p.height=0,xn=p.getContext("2d")}return xn}();this._setTextStyles(g,e,!0),l===void 0&&(f=l=g.measureText(t).width,n[t]=l),d===void 0&&c&&s&&(d=g.measureText(s).width,n[s]=d),c&&u===void 0&&(u=g.measureText(a).width,n[a]=u,f=u-d)}return{width:l*h,kernedWidth:f*h}}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 n=this.pathSide===Q,o=this.path,a=this._textLines[t],c=a.length,h=new Array(c);this.__charBounds[t]=h;for(let l=0;l<c;l++){const u=a[l];s=this._getGraphemeBox(u,t,l,e),h[l]=s,r+=s.kernedWidth,e=u}if(h[c]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},o&&o.segmentsInfo){let l=0;const u=o.segmentsInfo[o.segmentsInfo.length-1].length;switch(this.textAlign){case R:l=n?u-r:0;break;case E:l=(u-r)/2;break;case Q:l=n?0:u-r}l+=this.pathStartOffset*(n?-1:1);for(let d=n?c-1:0;n?d>=0:d<c;n?d--:d++)s=h[d],l>u?l%=u:l<0&&(l+=u),this._setGraphemeOnPath(l,s),l+=s.kernedWidth}return{width:r,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,r=this.path,n=tc(r.path,s,r.segmentsInfo);e.renderLeft=n.x-r.pathOffset.x,e.renderTop=n.y-r.pathOffset.y,e.angle=n.angle+(this.pathSide===Q?Math.PI:0)}_getGraphemeBox(t,e,s,r,n){const o=this.getCompleteStyleDeclaration(e,s),a=r?this.getCompleteStyleDeclaration(e,s-1):{},c=this._measureChar(t,o,r,a);let h,l=c.kernedWidth,u=c.width;this.charSpacing!==0&&(h=this._getWidthOfCharSpacing(),u+=h,l+=h);const d={width:u,left:0,height:o.fontSize,kernedWidth:l,deltaY:o.deltaY};if(s>0&&!n){const f=this.__charBounds[e][s-1];d.left=f.left+f.width+c.kernedWidth-c.width}return d}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(),n=this._getTopOffset();for(let o=0,a=this._textLines.length;o<a;o++){const c=this.getHeightOfLine(o),h=c/this.lineHeight,l=this._getLineLeftOffset(o);this._renderTextLine(e,t,this._textLines[o],r+l,n+s+h,o),s+=c}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(st))&&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,n,o){const a=this.getHeightOfLine(o),c=this.textAlign.includes(Ut),h=this.path,l=!c&&this.charSpacing===0&&this.isEmptyStyles(o)&&!h,u=this.direction==="ltr",d=this.direction==="ltr"?1:-1,f=e.direction;let g,p,m,b,T,w="",k=0;if(e.save(),f!==this.direction&&(e.canvas.setAttribute("dir",u?"ltr":"rtl"),e.direction=u?"ltr":"rtl",e.textAlign=u?R:Q),n-=a*this._fontSizeFraction/this.lineHeight,l)return this._renderChar(t,e,o,0,s.join(""),r,n),void e.restore();for(let O=0,x=s.length-1;O<=x;O++)b=O===x||this.charSpacing||h,w+=s[O],m=this.__charBounds[o][O],k===0?(r+=d*(m.kernedWidth-m.width),k+=m.width):k+=m.kernedWidth,c&&!b&&this._reSpaceAndTab.test(s[O])&&(b=!0),b||(g=g||this.getCompleteStyleDeclaration(o,O),p=this.getCompleteStyleDeclaration(o,O+1),b=Lr(g,p,!1)),b&&(h?(e.save(),e.translate(m.renderLeft,m.renderTop),e.rotate(m.angle),this._renderChar(t,e,o,O,w,-k/2,0),e.restore()):(T=r,this._renderChar(t,e,o,O,w,T,n)),w="",g=p,r+=d*k,k=0);e.restore()}_applyPatternGradientTransformText(t){const e=tt(),s=this.width+this.strokeWidth,r=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=s,e.height=r,n.beginPath(),n.moveTo(0,0),n.lineTo(s,0),n.lineTo(s,r),n.lineTo(0,r),n.closePath(),n.translate(s/2,r/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,s){let r,n;return xt(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(r=-this.width/2,n=-this.height/2,t.translate(r,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:r,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth: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,n,o,a){const c=this._getStyleDeclaration(s,r),h=this.getCompleteStyleDeclaration(s,r),l=t==="fillText"&&h.fill,u=t==="strokeText"&&h.stroke&&h.strokeWidth;if(u||l){if(e.save(),e.font=this._getFontDeclaration(h),c.textBackgroundColor&&this._removeShadow(e),c.deltaY&&(a+=c.deltaY),l){const d=this._setFillStyles(e,h);e.fillText(n,o-d.offsetX,a-d.offsetY)}if(u){const d=this._setStrokeStyles(e,h);e.strokeText(n,o-d.offsetX,a-d.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const r=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,"fontSize"),o=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,"deltaY"),a={fontSize:n*s.size,deltaY:o+n*s.baseline};this.setSelectionStyles(a,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,r=this.textAlign,n=this.direction,o=this.isEndOfWrapping(t);let a=0;return r===Ut||r===tr&&!o||r===Qs&&!o||r===Vr&&!o?0:(r===E&&(a=s/2),r===Q&&(a=s),r===tr&&(a=s/2),r===Qs&&(a=s),n==="rtl"&&(r===Q||r===Ut||r===Qs?a=0:r===R||r===Vr?a=-s:r!==E&&r!==tr||(a=-s/2)),a)}_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(),n=this.path,o=this._getWidthOfCharSpacing(),a=this.offsets[e];for(let c=0,h=this._textLines.length;c<h;c++){const l=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){s+=l;continue}const u=this._textLines[c],d=l/this.lineHeight,f=this._getLineLeftOffset(c);let g,p,m=0,b=0,T=this.getValueOfPropertyAt(c,0,e),w=this.getValueOfPropertyAt(c,0,st);const k=s+d*(1-this._fontSizeFraction);let O=this.getHeightOfChar(c,0),x=this.getValueOfPropertyAt(c,0,"deltaY");for(let D=0,F=u.length;D<F;D++){const X=this.__charBounds[c][D];g=this.getValueOfPropertyAt(c,D,e),p=this.getValueOfPropertyAt(c,D,st);const ct=this.getHeightOfChar(c,D),W=this.getValueOfPropertyAt(c,D,"deltaY");if(n&&g&&p)t.save(),t.fillStyle=w,t.translate(X.renderLeft,X.renderTop),t.rotate(X.angle),t.fillRect(-X.kernedWidth/2,a*ct+W,X.kernedWidth,this.fontSize/15),t.restore();else if((g!==T||p!==w||ct!==O||W!==x)&&b>0){let H=r+f+m;this.direction==="rtl"&&(H=this.width-H-b),T&&w&&(t.fillStyle=w,t.fillRect(H,k+a*O+x,b,this.fontSize/15)),m=X.left,b=X.width,T=g,w=p,O=ct,x=W}else b+=X.kernedWidth}let I=r+f+m;this.direction==="rtl"&&(I=this.width-I-b),t.fillStyle=p,g&&p&&t.fillRect(I,k+a*O+x,b-o,this.fontSize/15),s+=l}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]:{},n=arguments.length>1?arguments[1]:void 0;const o=t.includes("'")||t.includes('"')||t.includes(",")||gt.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:r,"px"),o].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return Ar(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),r=[`
|
|
54
|
+
`];let n=[];for(let o=0;o<e.length;o++)s[o]=this.graphemeSplit(e[o]),n=n.concat(s[o],r);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return y(y({},super.toObject([...pc,...t])),{},{styles:Da(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,n=!1;if(typeof t=="object")for(const o in t)o==="path"&&this.setPathInfo(),r=r||s.includes(o),n=n||o==="path";else r=s.includes(t),n=t==="path";return n&&this.setPathInfo(),r&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const r=ie(t,gt.ATTRIBUTE_NAMES,s),n=y(y({},e),r),{textAnchor:o=R,textDecoration:a="",dx:c=0,dy:h=0,top:l=0,left:u=0,fontSize:d=Ei,strokeWidth:f=1}=n,g=U(n,Dd),p=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),y({left:u+c,top:l+h,underline:a.includes("underline"),overline:a.includes("overline"),linethrough:a.includes("line-through"),strokeWidth:0,fontSize:d},g)),m=p.getScaledHeight()/p.height,b=((p.height+p.strokeWidth)*p.lineHeight-p.height)*m,T=p.getScaledHeight()+b;let w=0;return o===E&&(w=p.getScaledWidth()/2),o===Q&&(w=p.getScaledWidth()),p.set({left:p.left-w,top:p.top-(T-p.fontSize*(.07+p._fontSizeFraction))/p.lineHeight,strokeWidth:f}),p}static fromObject(t){return this._fromObject(y(y({},t),{},{styles:Ia(t.styles||{},t.text)}),{extraParam:"text"})}}v(gt,"textLayoutProperties",gc),v(gt,"cacheProperties",[...re,...pc]),v(gt,"ownDefaults",Od),v(gt,"type","Text"),v(gt,"genericFonts",["sans-serif","serif","cursive","fantasy","monospace"]),v(gt,"ATTRIBUTE_NAMES",Te.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),xa(gt,[class extends qo{_toSVG(){const i=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(i.textTop,i.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(i){return this._createBaseSVGMarkup(this._toSVG(),{reviver:i,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(i){let{textBgRects:t,textSpans:e}=i;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(Md,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
|
|
55
|
+
`]}_getSVGTextAndBg(i,t){const e=[],s=[];let r,n=i;this.backgroundColor&&s.push(...Sn(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let o=0,a=this._textLines.length;o<a;o++)r=this._getLineLeftOffset(o),this.direction==="rtl"&&(r+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",o))&&this._setSVGTextLineBg(s,o,t+r,n),this._setSVGTextLineText(e,o,t+r,n),n+=this.getHeightOfLine(o);return{textSpans:e,textBgRects:s}}_createTextCharSpan(i,t,e,s){const r=this.getSvgSpanStyles(t,i!==i.trim()||!!i.match(kd)),n=r?'style="'.concat(r,'"'):"",o=t.deltaY,a=o?' dy="'.concat(P(o,L.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(P(e,L.NUM_FRACTION_DIGITS),'" y="').concat(P(s,L.NUM_FRACTION_DIGITS),'" ').concat(a).concat(n,">").concat(Ma(i),"</tspan>")}_setSVGTextLineText(i,t,e,s){const r=this.getHeightOfLine(t),n=this.textAlign.includes(Ut),o=this._textLines[t];let a,c,h,l,u,d="",f=0;s+=r*(1-this._fontSizeFraction)/this.lineHeight;for(let g=0,p=o.length-1;g<=p;g++)u=g===p||this.charSpacing,d+=o[g],h=this.__charBounds[t][g],f===0?(e+=h.kernedWidth-h.width,f+=h.width):f+=h.kernedWidth,n&&!u&&this._reSpaceAndTab.test(o[g])&&(u=!0),u||(a=a||this.getCompleteStyleDeclaration(t,g),c=this.getCompleteStyleDeclaration(t,g+1),u=Lr(a,c,!0)),u&&(l=this._getStyleDeclaration(t,g),i.push(this._createTextCharSpan(d,l,e,s)),d="",a=c,this.direction==="rtl"?e-=f:e+=f,f=0)}_setSVGTextLineBg(i,t,e,s){const r=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let o,a=0,c=0,h=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let l=0;l<r.length;l++){const{left:u,width:d,kernedWidth:f}=this.__charBounds[t][l];o=this.getValueOfPropertyAt(t,l,"textBackgroundColor"),o!==h?(h&&i.push(...Sn(h,e+c,s,a,n)),c=u,a=d,h=o):a+=f}o&&i.push(...Sn(h,e+c,s,a,n))}_getSVGLineTopOffset(i){let t,e=0;for(t=0;t<i;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(i){return"".concat(super.getSvgStyles(i)," white-space: pre;")}getSvgSpanStyles(i,t){const{fontFamily:e,strokeWidth:s,stroke:r,fill:n,fontSize:o,fontStyle:a,fontWeight:c,deltaY:h}=i,l=this.getSvgTextDecoration(i);return[r?Gs(yt,r):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",o?"font-size: ".concat(o,"px; "):"",a?"font-style: ".concat(a,"; "):"",c?"font-weight: ".concat(c,"; "):"",l&&"text-decoration: ".concat(l,"; "),n?Gs(st,n):"",h?"baseline-shift: ".concat(-h,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(i){return["overline","underline","line-through"].filter(t=>i[t.replace("-","")]).join(" ")}}]),C.setClass(gt),C.setSVGClass(gt);class Id{constructor(t){v(this,"target",void 0),v(this,"__mouseDownInPlace",!1),v(this,"__dragStartFired",!1),v(this,"__isDraggingOver",!1),v(this,"__dragStartSelection",void 0),v(this,"__dragImageDisposer",void 0),v(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:n}=e;const o=this.target,a=o.canvas,c=new _(o.flipX?-1:1,o.flipY?-1:1),h=o._getCursorBoundaries(r),l=new _(h.left+h.leftOffset,h.top+h.topOffset).multiply(c).transform(o.calcTransformMatrix()),u=a.getScenePoint(t).subtract(l),d=o.getCanvasRetinaScaling(),f=o.getBoundingRect(),g=l.subtract(new _(f.left,f.top)),p=a.viewportTransform,m=g.add(u).transform(p,!0),b=o.backgroundColor,T=fn(o.styles);o.backgroundColor="";const w={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};o.setSelectionStyles(w,0,r),o.setSelectionStyles(w,n,o.text.length),o.dirty=!0;const k=o.toCanvasElement({enableRetinaScaling:a.enableRetinaScaling,viewportTransform:!0});o.backgroundColor=b,o.styles=T,o.dirty=!0,Ns(k,{position:"fixed",left:"".concat(-k.width,"px"),border:vt,width:"".concat(k.width/d,"px"),height:"".concat(k.height/d,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{k.remove()},Et(t.target||this.target.hiddenTextarea).body.appendChild(k),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(k,m.x,m.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},n=e._text.slice(r.selectionStart,r.selectionEnd).join(""),o=y({text:e.text,value:n},r);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(r.selectionStart,r.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,o)}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 n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!r){const o=this.target,a=o.canvas;let c=o.getSelectionStartFromPointer(s);const{styles:h}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},l=n[Math.max(0,n.length-1)],u=0;if(this.__dragStartSelection){const d=this.__dragStartSelection.selectionStart,f=this.__dragStartSelection.selectionEnd;c>d&&c<=f?c=d:c>f&&(c-=f-d),o.removeChars(d,f),delete this.__dragStartSelection}o._reNewline.test(l)&&(o._reNewline.test(o._text[c])||c===o._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=o,o.insertChars(n,h,c),a.setActiveObject(o),o.enterEditing(s),o.selectionStart=Math.min(c+u,o._text.length),o.selectionEnd=Math.min(o.selectionStart+n.length,o._text.length),o.hiddenTextarea.value=o.text,o._updateTextarea(),o.hiddenTextarea.focus(),o.fire(mr,{index:c+u,action:"drop"}),a.fire("text:changed",{target:o}),a.contextTopDirty=!0,a.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const r=this.target,n=this.target.canvas,{selectionStart:o,selectionEnd:a}=this.__dragStartSelection,c=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||vt;c===vt?(r.selectionStart=o,r.selectionEnd=a,r._updateTextarea(),r.hiddenTextarea.focus()):(r.clearContextTop(),c==="move"&&(r.removeChars(o,a),r.selectionStart=r.selectionEnd=o,r.hiddenTextarea&&(r.hiddenTextarea.value=r.text),r._updateTextarea(),r.fire(mr,{index:o,action:"dragend"}),n.fire("text:changed",{target:r}),n.requestRenderAll()),r.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const vc=/[ \n\.,;!\?\-]/;class jd extends gt{constructor(){super(...arguments),v(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:n}=t;return Qi({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:r,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:o=>{this._currentCursorOpacity=o,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}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||!Ai.test(s[t-1]))?t-1:t,n=s[r];for(;r>0&&r<s.length&&!vc.test(n);)r+=e,n=s[r];return e===-1&&vc.test(n)&&r++,r}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Et(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),r=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&r!==n||r!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===r&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const r=s.slice(0,t),n=this.graphemeSplit(r).length;if(t===e)return{selectionStart:n,selectionEnd:n};const o=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(o).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,n=s.charIndex,o=this.getValueOfPropertyAt(r,n,"fontSize")*this.lineHeight,a=e.leftOffset,c=this.getCanvasRetinaScaling(),h=this.canvas.upperCanvasEl,l=h.width/c,u=h.height/c,d=l-o,f=u-o,g=new _(e.left+a,e.top+e.topOffset+o).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new _(h.clientWidth/l,h.clientHeight/u));return g.x<0&&(g.x=0),g.x>d&&(g.x=d),g.y<0&&(g.y=0),g.y>f&&(g.y=f),g.x+=this.canvas._offset.left,g.y+=this.canvas._offset.top,{left:"".concat(g.x,"px"),top:"".concat(g.y,"px"),fontSize:"".concat(o,"px"),charHeight:o}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditing(){const t=this._textBeforeEdit!==this.text;return this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire(yr),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:n,charIndex:o}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let a=r;a<this._unwrappedTextLines[s].length;a++)delete this.styles[s][a];if(this.styles[n])for(let a=o;a<this._unwrappedTextLines[n].length;a++){const c=this.styles[n][a];c&&(this.styles[s]||(this.styles[s]={}),this.styles[s][r+a-o]=c)}for(let a=s+1;a<=n;a++)delete this.styles[a];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const a=this.styles[s],c=o-r;for(let h=r;h<o;h++)delete a[h];for(const h in this.styles[s]){const l=parseInt(h,10);l>=o&&(a[l-c]=a[h],delete a[h])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const r in this.styles){const n=parseInt(r,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,r){const n={},o=this._unwrappedTextLines[t].length,a=o===e;let c=!1;s||(s=1),this.shiftLineStyles(t,s);const h=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const u in this.styles[t]){const d=parseInt(u,10);d>=e&&(c=!0,n[d-e]=this.styles[t][u],a&&e===0||delete this.styles[t][u])}let l=!1;for(c&&!a&&(this.styles[t+s]=n,l=!0),(l||o>e)&&s--;s>0;)r&&r[s-1]?this.styles[t+s]={0:y({},r[s-1])}:h?this.styles[t+s]={0:y({},h)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,r){this.styles||(this.styles={});const n=this.styles[t],o=n?y({},n):{};s||(s=1);for(const c in o){const h=parseInt(c,10);h>=e&&(n[h+s]=o[h],o[h-s]||delete n[h])}if(this._forceClearCache=!0,r){for(;s--;)Object.keys(r[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=y({},r[s]));return}if(!n)return;const a=n[e?e-1:1];for(;a&&s--;)this.styles[t][e+s]=y({},a)}insertNewStyleBlock(t,e,s){const r=this.get2DCursorLocation(e,!0),n=[0];let o,a=0;for(let c=0;c<t.length;c++)t[c]===`
|
|
56
|
+
`?(a++,n[a]=0):n[a]++;for(n[0]>0&&(this.insertCharStyleObject(r.lineIndex,r.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),a&&this.insertNewlineStyleObject(r.lineIndex,r.charIndex+n[0],a),o=1;o<a;o++)n[o]>0?this.insertCharStyleObject(r.lineIndex+o,0,n[o],s):s&&this.styles[r.lineIndex+o]&&s[0]&&(this.styles[r.lineIndex+o][0]=s[0]),s=s&&s.slice(n[o]+1);n[o]>0&&this.insertCharStyleObject(r.lineIndex+o,0,n[o],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 n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...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=R:this._selectionDirection===Q&&(this._selectionDirection=R,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Q?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Q:this._selectionDirection===R&&(this._selectionDirection=Q,this.selectionStart=e),this.selectionEnd=s)}}class Ed extends jd{initHiddenTextarea(){const t=this.canvas&&Et(this.canvas.getElement())||Ke(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(o=>{let[a,c]=o;return e.setAttribute(a,c)});const{top:s,left:r,fontSize:n}=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(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(o=>{let[a,c]=o;return e.addEventListener(a,this[c].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;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(mr),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const r=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,o=r.length,a=this.selectionStart,c=this.selectionEnd,h=a!==c;let l,u,d,f,g=o-n;const p=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),m=a>p.selectionStart;h?(u=this._text.slice(a,c),g+=c-a):o<n&&(u=m?this._text.slice(c+g,c):this._text.slice(a,a-g));const b=r.slice(p.selectionEnd-g,p.selectionEnd);if(u&&u.length&&(b.length&&(l=this.getSelectionStyles(a,a+1,!1),l=b.map(()=>l[0])),h?(d=a,f=c):m?(d=c-u.length,f=c):(d=c,f=c+u.length),this.removeStyleFromTo(d,f)),b.length){const{copyPasteData:T}=Vt();e&&b.join("")===T.copiedText&&!L.disableStyleCopyPaste&&(l=T.copiedTextStyle),this.insertNewStyleBlock(b,a,l)}s()}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}=Vt();t.copiedText=this.getSelectedText(),L.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),n=r.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const o=r.charIndex,a=this._getWidthBeforeCursor(n,o),c=this._getIndexOnLine(n+1,a);return this._textLines[n].slice(o).length+c+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),r=this.get2DCursorLocation(s),n=r.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const o=r.charIndex,a=this._getWidthBeforeCursor(n,o),c=this._getIndexOnLine(n-1,a),h=this._textLines[n].slice(0,o),l=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+c-h.length+(1-l)}_getIndexOnLine(t,e){const s=this._textLines[t];let r,n,o=this._getLineLeftOffset(t),a=0;for(let c=0,h=s.length;c<h;c++)if(r=this.__charBounds[t][c].width,o+=r,o>e){n=!0;const l=o-r,u=o,d=Math.abs(l-e);a=Math.abs(u-e)<d?c:c-1;break}return n||(a=s.length-1),a}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===Q);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const r=this.text.length;this.selectionStart=Ae(0,this.selectionStart,r),this.selectionEnd=Ae(0,this.selectionEnd,r),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===R?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=R,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===Q&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=R,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===R&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=Q,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Q,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const wn=i=>!!i.button;class Pd extends Ed{constructor(){super(...arguments),v(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new Id(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),Vi(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!wn(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!wn(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const r=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||wn(e)||r||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),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(Tt(this.calcTransformMatrix())).add(new _(-this._getLeftOffset(),-this._getTopOffset()));let s=0,r=0,n=0;for(let h=0;h<this._textLines.length&&s<=e.y;h++)s+=this.getHeightOfLine(h),n=h,h>0&&(r+=this._textLines[h-1].length+this.missingNewlineOffset(h-1));let o=Math.abs(this._getLineLeftOffset(n));const a=this._textLines[n].length,c=this.__charBounds[n];for(let h=0;h<a;h++){const l=o+c[h].kernedWidth;if(e.x<=l){Math.abs(e.x-l)<=Math.abs(e.x-o)&&r++;break}o=l,r++}return Math.min(this.flipX?a-r:r,this._text.length)}}const Gr="moveCursorUp",Nr="moveCursorDown",Ur="moveCursorLeft",$r="moveCursorRight",qr="exitEditing",Ad=y({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:qr,27:qr,33:Gr,34:Nr,35:$r,36:Ur,37:Ur,38:Gr,39:$r,40:Nr},keysMapRtl:{9:qr,27:qr,33:Gr,34:Nr,35:Ur,36:$r,37:$r,38:Gr,39:Ur,40:Nr},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class ce extends Pd{static getDefaults(){return y(y({},super.getDefaults()),ce.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,y(y({},ce.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 _n&&this.canvas.textEditingManager.remove(this),e instanceof _n&&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)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),r=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:r,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:r,lineIndex:n}=this.get2DCursorLocation(t);for(let h=0;h<n;h++)e+=this.getHeightOfLine(h);const o=this._getLineLeftOffset(n),a=this.__charBounds[n][r];a&&(s=a.left),this.charSpacing!==0&&r===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const c={top:e,left:o+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===Q||this.textAlign===Ut||this.textAlign===Qs?c.left*=-1:this.textAlign===R||this.textAlign===Vr?c.left=o-(s>0?s:0):this.textAlign!==E&&this.textAlign!==tr||(c.left=o-(s>0?s:0))),c}renderCursorAt(t){const e=this._getCursorBoundaries(t,!0);this._renderCursor(this.canvas.contextTop,e,t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}_renderCursor(t,e,s){const r=this.get2DCursorLocation(s),n=r.lineIndex,o=r.charIndex>0?r.charIndex-1:0,a=this.getValueOfPropertyAt(n,o,"fontSize"),c=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/c,l=this.getValueOfPropertyAt(n,o,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(n)/this.lineHeight-a*(1-this._fontSizeFraction);this.inCompositionMode&&this.renderSelection(t,e),t.fillStyle=this.cursorColor||this.getValueOfPropertyAt(n,o,st),t.globalAlpha=this._currentCursorOpacity,t.fillRect(e.left+e.leftOffset-h/2,u+e.top+l,h,a)}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,n=e.selectionEnd,o=this.textAlign.includes(Ut),a=this.get2DCursorLocation(r),c=this.get2DCursorLocation(n),h=a.lineIndex,l=c.lineIndex,u=a.charIndex<0?0:a.charIndex,d=c.charIndex<0?0:c.charIndex;for(let f=h;f<=l;f++){const g=this._getLineLeftOffset(f)||0;let p=this.getHeightOfLine(f),m=0,b=0,T=0;if(f===h&&(b=this.__charBounds[h][u].left),f>=h&&f<l)T=o&&!this.isEndOfWrapping(f)?this.width:this.getLineWidth(f)||5;else if(f===l)if(d===0)T=this.__charBounds[l][d].left;else{const I=this._getWidthOfCharSpacing();T=this.__charBounds[l][d-1].left+this.__charBounds[l][d-1].width-I}m=p,(this.lineHeight<1||f===l&&this.lineHeight>1)&&(p/=this.lineHeight);let w=s.left+g+b,k=p,O=0;const x=T-b;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",k=1,O=p):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Q||this.textAlign===Ut||this.textAlign===Qs?w=this.width-w-x:this.textAlign===R||this.textAlign===Vr?w=s.left+g-T:this.textAlign!==E&&this.textAlign!==tr||(w=s.left+g-T)),t.fillRect(w,s.top+s.topOffset+O,x,k),s.topOffset+=m}}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,st)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this._exitEditing(),this.draggableTextDelegate.dispose(),super.dispose()}}v(ce,"ownDefaults",Ad),v(ce,"type","IText"),C.setClass(ce),C.setClass(ce,"i-text");class Xe extends ce{static getDefaults(){return y(y({},super.getDefaults()),Xe.ownDefaults)}constructor(t,e){super(t,y(y({},Xe.ownDefaults),e))}static createControls(){return{controls:Sa()}}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(Ut)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,r=0;const n={};for(let o=0;o<t.graphemeLines.length;o++)t.graphemeText[r]===`
|
|
57
|
+
`&&o>0?(s=0,r++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[r])&&o>0&&(s++,r++),n[o]={line:e,offset:s},r+=t.graphemeLines[o].length,s+=t.graphemeLines[o].length;return n}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,n=!1;const o=this._styleMap[t],a=this._styleMap[t+1];o&&(t=o.line,s=o.offset),a&&(r=a.line,n=r===t,e=a.offset);const c=t===void 0?this.styles:{line:this.styles[t]};for(const h in c)for(const l in c[h]){const u=parseInt(l,10);if(u>=s&&(!n||u<e))for(const d in c[h][l])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 n=0;n<s.wordsData.length;n++)r.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,r}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let r=0;return{wordsData:t.map((n,o)=>{let a=0;const c=e?this.graphemeSplit(n):this.wordSplit(n);return c.length===0?[{word:[],width:0}]:c.map(h=>{const l=e?[h]:this.graphemeSplit(h),u=this._measureWord(l,o,a);return r=Math.max(u,r),a+=l.length+s.length,{word:l,width:u}})}),largestWordWidth:r}}_measureWord(t,e){let s,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let o=0,a=t.length;o<a;o++)n+=this._getGraphemeBox(t[o],e,o+r,s,!0).kernedWidth,s=t[o];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:r,wordsData:n}=s,o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const a=this._getWidthOfCharSpacing(),c=this.splitByGrapheme,h=[],l=c?"":" ";let u=0,d=[],f=0,g=0,p=!0;e-=o;const m=Math.max(e,r,this.dynamicMinWidth),b=n[t];let T;for(f=0,T=0;T<b.length;T++){const{word:w,width:k}=b[T];f+=w.length,u+=g+k-a,u>m&&!p?(h.push(d),d=[],u=k,p=!0):u+=a,p||c||d.push(l),d=d.concat(w),g=c?0:this._measureWord([l],t,f),f++,p=!1}return T&&h.push(d),r+o>this.dynamicMinWidth&&(this.dynamicMinWidth=r-a+o),h}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),r=new Array(s.length);for(let n=0;n<s.length;n++)r[n]=s[n].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])}}v(Xe,"type","Textbox"),v(Xe,"textLayoutProperties",[...ce.textLayoutProperties,"width"]),v(Xe,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),C.setClass(Xe);class yc extends Br{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:r,group:n}=s;if(!r||!this.shouldPerformLayout(t))return;const{width:o,height:a}=Gt(za(s,r)),c=new _(o,a);if(r.absolutePositioned)return{center:ee(r.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:c};{const h=r.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:l=new _,correction:u=new _}=this.calcBoundingBox(e,t)||{};return{center:l.add(h),correction:u.subtract(h),size:c}}return{center:s.getRelativeCenterPoint().add(h),size:c}}}}v(yc,"type","clip-path"),C.setClass(yc);class bc extends Br{getInitialSize(t,e){let{target:s}=t,{size:r}=e;return new _(s.width||r.x,s.height||r.y)}}v(bc,"type","fixed"),C.setClass(bc);class Ld extends Js{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,n)=>(n.parent&&r.add(n.parent),r),new Set).forEach(r=>{!s.some(n=>n.parent===r)&&r.layoutManager.unsubscribeTargets({target:r,targets:[e]})})}}class Ct extends Nt{static getDefaults(){return y(y({},super.getDefaults()),Ct.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,Ct.ownDefaults),this.setOptions(e);const{left:s,top:r,layoutManager:n}=e;this.groupInit(t,{left:s,top:r,layoutManager:n??new Ld})}_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 n=this._objects.findIndex(a=>a.isInFrontOf(r)),o=n===-1?this.size():n;this.insertAt(o,r)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(pe("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:n}=r;n&&s.add(n)}),t===mn?s.forEach(r=>{r._onAfterObjectsChange(Fr,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=y(y({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,r);super._renderControls(t,e),t.restore()}}v(Ct,"type","ActiveSelection"),v(Ct,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),C.setClass(Ct),C.setClass(Ct,"activeSelection");class Fd{constructor(){v(this,"resources",{})}applyFilters(t,e,s,r,n){const o=n.getContext("2d");if(!o)return;o.drawImage(e,0,0,s,r);const a={sourceWidth:s,sourceHeight:r,imageData:o.getImageData(0,0,s,r),originalEl:e,originalImageData:o.getImageData(0,0,s,r),canvasEl:n,ctx:o,filterBackend:this};t.forEach(h=>{h.applyTo(a)});const{imageData:c}=a;return c.width===s&&c.height===r||(n.width=c.width,n.height=c.height),o.putImageData(c,0,0),a}}class _c{constructor(){let{tileSize:t=L.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};v(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),v(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=tt();s.width=t,s.height=e;const 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,n,o){const a=this.gl,c=n.getContext("2d");if(!a||!c)return;let h;o&&(h=this.getCachedTexture(o,e));const l={originalWidth:e.width||e.originalWidth||0,originalHeight:e.height||e.originalHeight||0,sourceWidth:s,sourceHeight:r,destinationWidth:s,destinationHeight:r,context:a,sourceTexture:this.createTexture(a,s,r,h?void 0:e),targetTexture:this.createTexture(a,s,r),originalTexture:h||this.createTexture(a,s,r,h?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},u=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,u),t.forEach(d=>{d&&d.applyTo(l)}),function(d){const f=d.targetCanvas,g=f.width,p=f.height,m=d.destinationWidth,b=d.destinationHeight;g===m&&p===b||(f.width=m,f.height=b)}(l),this.copyGLTo2D(a,l),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(l.sourceTexture),a.deleteTexture(l.targetTexture),a.deleteFramebuffer(u),c.setTransform(1,0,0,1,0,0),l}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,r,n){const{NEAREST:o,TEXTURE_2D:a,RGBA:c,UNSIGNED_BYTE:h,CLAMP_TO_EDGE:l,TEXTURE_MAG_FILTER:u,TEXTURE_MIN_FILTER:d,TEXTURE_WRAP_S:f,TEXTURE_WRAP_T:g}=t,p=t.createTexture();return t.bindTexture(a,p),t.texParameteri(a,u,n||o),t.texParameteri(a,d,n||o),t.texParameteri(a,f,l),t.texParameteri(a,g,l),r?t.texImage2D(a,0,c,c,h,r):t.texImage2D(a,0,c,e,s,0,c,h,null),p}getCachedTexture(t,e,s){const{textureCache:r}=this;if(r[t])return r[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(r[t]=n),n}}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,n=r.getContext("2d");if(!n)return;n.translate(0,r.height),n.scale(1,-1);const o=s.height-r.height;n.drawImage(s,0,o,r.width,r.height,0,0,r.width,r.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),r=e.destinationWidth,n=e.destinationHeight,o=r*n*4;if(!s)return;const a=new Uint8Array(this.imageBuffer,0,o),c=new Uint8ClampedArray(this.imageBuffer,0,o);t.readPixels(0,0,r,n,t.RGBA,t.UNSIGNED_BYTE,a);const h=new ImageData(c,r,n);s.putImageData(h,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),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);r&&(e.renderer=r.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Cn;function Rd(){const{WebGLProbe:i}=Vt();return i.queryWebGL(tt()),L.enableGLFiltering&&i.isSupported(L.textureSize)?new _c({tileSize:L.textureSize}):new Fd}function On(){return!Cn&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Cn=Rd()),Cn}const Bd=["filters","resizeFilter","src","crossOrigin","type"],Tc=["cropX","cropY"];class Ot extends at{static getDefaults(){return y(y({},super.getDefaults()),Ot.ownDefaults)}constructor(t,e){super(),v(this,"_lastScaleX",1),v(this,"_lastScaleY",1),v(this,"_filterScalingX",1),v(this,"_filterScalingY",1),this.filters=[],Object.assign(this,Ot.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(ye()),this.setElement(typeof t=="string"?(this.canvas&&Et(this.canvas.getElement())||Ke()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){let e=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(e),t.classList.add(Ot.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=On(!1);e instanceof _c&&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&&Vt().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())}),y(y({},super.toObject([...Tc,...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 n=[],o=[],a="",c="";if(!e)return[];if(this.hasCrop()){const h=ye();n.push('<clipPath id="imageCrop_'+h+`">
|
|
58
|
+
`,' <rect x="'+s+'" y="'+r+'" width="'+this.width+'" height="'+this.height+`" />
|
|
59
59
|
`,`</clipPath>
|
|
60
|
-
`),a=' clip-path="url(#imageCrop_'+h+')" '}if(this.imageSmoothing||(c=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(
|
|
61
|
-
`)),this.stroke||this.strokeDashArray){const h=this.fill;this.fill=null,o=[' <rect x="'.concat(s,'" y="').concat(
|
|
62
|
-
`)],this.fill=h}return n=this.paintFirst!==st?n.concat(o,t):n.concat(t,o),n}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
|
|
63
|
-
`.concat(
|
|
60
|
+
`),a=' clip-path="url(#imageCrop_'+h+')" '}if(this.imageSmoothing||(c=' 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(c).concat(a,`></image>
|
|
61
|
+
`)),this.stroke||this.strokeDashArray){const h=this.fill;this.fill=null,o=[' <rect x="'.concat(s,'" y="').concat(r,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
|
|
62
|
+
`)],this.fill=h}return n=this.paintFirst!==st?n.concat(o,t):n.concat(t,o),n}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 Hs(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,n=s.y,o=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||r>e&&n>e)return this._element=o,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=r,void(this._lastScaleY=n);const a=tt(),c=o.width,h=o.height;a.width=c,a.height=h,this._element=a,this._lastScaleX=t.scaleX=r,this._lastScaleY=t.scaleY=n,On().applyFilters([t],o,c,h,this._element),this._filterScalingX=a.width/this._originalElement.width,this._filterScalingY=a.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.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 n=tt();n.width=s,n.height=r,this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,r),this._lastScaleX=1,this._lastScaleY=1);On().applyFilters(t,this._originalElement,s,r,this._element),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,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,n=this.width,o=this.height,a=Math.max(this.cropX,0),c=Math.max(this.cropY,0),h=e.naturalWidth||e.width,l=e.naturalHeight||e.height,u=a*s,d=c*r,f=Math.min(n*s,h-u),g=Math.min(o*r,l-d),p=-n/2,m=-o/2,b=Math.min(n,h/s-a),T=Math.min(o,l/r-c);e&&t.drawImage(e,u,d,f,g,p,m,b,T)}_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=Eo(this.preserveAspectRatio||""),e=this.width,s=this.height,r={width:e,height:s};let n,o=this._element.width,a=this._element.height,c=1,h=1,l=0,u=0,d=0,f=0;return!t||t.alignX===vt&&t.alignY===vt?(c=e/o,h=s/a):(t.meetOrSlice==="meet"&&(c=h=Ya(this._element,r),n=(e-o*c)/2,t.alignX==="Min"&&(l=-n),t.alignX==="Max"&&(l=n),n=(s-a*h)/2,t.alignY==="Min"&&(u=-n),t.alignY==="Max"&&(u=n)),t.meetOrSlice==="slice"&&(c=h=Va(this._element,r),n=o-e/c,t.alignX==="Mid"&&(d=n/2),t.alignX==="Max"&&(d=n),n=a-s/h,t.alignY==="Mid"&&(f=n/2),t.alignY==="Max"&&(f=n),o=e/c,a=s/h)),{width:o,height:a,scaleX:c,scaleY:h,offsetLeft:l,offsetTop:u,cropX:d,cropY:f}}static fromObject(t,e){let{filters:s,resizeFilter:r,src:n,crossOrigin:o,type:a}=t,c=U(t,Bd);return Promise.all([Hs(n,y(y({},e),{},{crossOrigin:o})),s&&rs(s,e),r&&rs([r],e),Ys(c,e)]).then(h=>{let[l,u=[],[d]=[],f={}]=h;return new this(l,y(y({},c),{},{src:n,filters:u,resizeFilter:d},f))})}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 Hs(t,{crossOrigin:e,signal:s}).then(n=>new this(n,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=ie(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(r["xlink:href"],e,r).catch(n=>(pe("log","Unable to parse Image",n),null))}}v(Ot,"type","Image"),v(Ot,"cacheProperties",[...re,...Tc]),v(Ot,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),v(Ot,"CSS_CANVAS","canvas-img"),v(Ot,"ATTRIBUTE_NAMES",[...Te,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),C.setClass(Ot),C.setSVGClass(Ot),Er(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);const Sc=bo,xc=i=>function(t,e,s){const{points:r,pathOffset:n}=s;return new _(r[i]).subtract(n).transform(Z(s.getViewportTransform(),s.calcTransformMatrix()))},wc=(i,t,e,s)=>{const{target:r,pointIndex:n}=t,o=r,a=ee(new _(e,s),void 0,o.calcOwnMatrix());return o.points[n]=a.add(o.pathOffset),o.setDimensions(),!0},Cc=(i,t)=>function(e,s,r,n){const o=s.target,a=new _(o.points[(i>0?i:o.points.length)-1]),c=a.subtract(o.pathOffset).transform(o.calcOwnMatrix()),h=t(e,y(y({},s),{},{pointIndex:i}),r,n),l=a.subtract(o.pathOffset).transform(o.calcOwnMatrix()).subtract(c);return o.left-=l.x,o.top-=l.y,h},Oc=i=>_e(Sc,Cc(i,wc)),kn=(i,t,e)=>{const{path:s,pathOffset:r}=i,n=s[t];return new _(n[e]-r.x,n[e+1]-r.y).transform(Z(i.getViewportTransform(),i.calcTransformMatrix()))};function Wd(i,t,e){const{commandIndex:s,pointIndex:r}=this;return kn(e,s,r)}function Xd(i,t,e,s){const{target:r}=t,{commandIndex:n,pointIndex:o}=this,a=((c,h,l,u,d)=>{const{path:f,pathOffset:g}=c,p=f[(u>0?u:f.length)-1],m=new _(p[d],p[d+1]),b=m.subtract(g).transform(c.calcOwnMatrix()),T=ee(new _(h,l),void 0,c.calcOwnMatrix());f[u][d]=T.x+g.x,f[u][d+1]=T.y+g.y,c.setDimensions();const w=m.subtract(c.pathOffset).transform(c.calcOwnMatrix()).subtract(b);return c.left-=w.x,c.top-=w.y,c.set("dirty",!0),!0})(r,e,s,n,o);return Ui(this.actionName,y(y({},$i(i,t,e,s)),{},{commandIndex:n,pointIndex:o})),a}class kc extends ${constructor(t){super(t)}render(t,e,s,r,n){const o=y(y({},r),{},{cornerColor:this.controlFill,cornerStrokeColor:this.controlStroke,transparentCorners:!this.controlFill});super.render(t,e,s,o,n)}}class zd extends kc{constructor(t){super(t)}render(t,e,s,r,n){const{path:o}=n,{commandIndex:a,pointIndex:c,connectToCommandIndex:h,connectToPointIndex:l}=this;t.save(),t.strokeStyle=this.controlStroke,this.connectionDashArray&&t.setLineDash(this.connectionDashArray);const[u]=o[a],d=kn(n,h,l);if(u==="Q"){const f=kn(n,a,c+2);t.moveTo(f.x,f.y),t.lineTo(e,s)}else t.moveTo(e,s);t.lineTo(d.x,d.y),t.stroke(),t.restore(),super.render(t,e,s,r,n)}}const Kr=(i,t,e,s,r,n)=>new(e?zd:kc)(y(y({commandIndex:i,pointIndex:t,actionName:"modifyPath",positionHandler:Wd,actionHandler:Xd,connectToCommandIndex:r,connectToPointIndex:n},s),e?s.controlPointStyle:s.pointStyle));var ze=Object.freeze({__proto__:null,changeWidth:an,createObjectDefaultControls:dn,createPathControls:function(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e={};let s="M";return i.path.forEach((r,n)=>{const o=r[0];switch(o!=="Z"&&(e["c_".concat(n,"_").concat(o)]=Kr(n,r.length-2,!1,t)),o){case"C":e["c_".concat(n,"_C_CP_1")]=Kr(n,1,!0,t,n-1,(a=>a==="C"?5:a==="Q"?3:1)(s)),e["c_".concat(n,"_C_CP_2")]=Kr(n,3,!0,t,n,5);break;case"Q":e["c_".concat(n,"_Q_CP_1")]=Kr(n,1,!0,t,n,3)}s=o}),e},createPolyActionHandler:Oc,createPolyControls:function(i){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e={};for(let s=0;s<(typeof i=="number"?i:i.points.length);s++)e["p".concat(s)]=new $(y({actionName:Sc,positionHandler:xc(s),actionHandler:Oc(s)},t));return e},createPolyPositionHandler:xc,createResizeControls:Ta,createTextboxDefaultControls:Sa,dragHandler:$o,factoryPolyActionHandler:Cc,getLocalPoint:kr,polyActionHandler:wc,renderCircleControl:ha,renderSquareControl:la,rotationStyleHandler:ua,rotationWithSnapping:da,scaleCursorStyleHandler:as,scaleOrSkewActionName:Ks,scaleSkewCursorStyleHandler:Re,scalingEqually:qs,scalingX:pa,scalingXOrSkewingY:ln,scalingY:ma,scalingYOrSkewingX:un,skewCursorStyleHandler:va,skewHandlerX:ba,skewHandlerY:_a,wrapWithFireEvent:_e,wrapWithFixedAnchor:Fe});const Zr=i=>i.webgl!==void 0,Mn="precision highp float",Hd=`
|
|
63
|
+
`.concat(Mn,`;
|
|
64
64
|
varying vec2 vTexCoord;
|
|
65
65
|
uniform sampler2D uTexture;
|
|
66
66
|
void main() {
|
|
67
67
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
68
|
-
}`),
|
|
68
|
+
}`),Yd=["type"],Vd=["type"],Gd=new RegExp(Mn,"g");class ot{get type(){return this.constructor.type}constructor(){let t=U(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Yd);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Hd}getVertexSource(){return`
|
|
69
69
|
attribute vec2 aPosition;
|
|
70
70
|
varying vec2 vTexCoord;
|
|
71
71
|
void main() {
|
|
72
72
|
vTexCoord = aPosition;
|
|
73
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:
|
|
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"}}=Vt();r!=="highp"&&(e=e.replace(Gd,Mn.replace("highp",r)));const n=t.createShader(t.VERTEX_SHADER),o=t.createShader(t.FRAGMENT_SHADER),a=t.createProgram();if(!n||!o||!a)throw new Yt("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Yt("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.shaderSource(o,e),t.compileShader(o),!t.getShaderParameter(o,t.COMPILE_STATUS))throw new Yt("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(o)));if(t.attachShader(a,n),t.attachShader(a,o),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw new Yt('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(a)));const c=this.getUniformLocations(t,a)||{};return c.uStepW=t.getUniformLocation(a,"uStepW"),c.uStepH=t.getUniformLocation(a,"uStepH"),{program:a,attributeLocations:this.getAttributeLocations(t,a),uniformLocations:c}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,r={};for(let n=0;n<s.length;n++)r[s[n]]=t.getUniformLocation(e,s[n]);return r}sendAttributeData(t,e,s){const r=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),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){Zr(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 e=tt();e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}}toObject(){const t=Object.keys(this.constructor.defaults);return y({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(U(t,Vd))}}v(ot,"type","BaseFilter"),v(ot,"uniformLocations",[]);const Nd={multiply:`gl_FragColor.rgb *= uColor.rgb;
|
|
75
75
|
`,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
|
|
76
76
|
`,add:`gl_FragColor.rgb += uColor.rgb;
|
|
77
77
|
`,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
|
|
@@ -98,7 +98,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
98
98
|
`,tint:`
|
|
99
99
|
gl_FragColor.rgb *= (1.0 - uColor.a);
|
|
100
100
|
gl_FragColor.rgb += uColor.rgb;
|
|
101
|
-
`};class
|
|
101
|
+
`};class Jr extends ot{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
|
|
102
102
|
precision highp float;
|
|
103
103
|
uniform sampler2D uTexture;
|
|
104
104
|
uniform vec4 uColor;
|
|
@@ -107,10 +107,10 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
107
107
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
108
108
|
gl_FragColor = color;
|
|
109
109
|
if (color.a > 0.0) {
|
|
110
|
-
`.concat(
|
|
110
|
+
`.concat(Nd[this.mode],`
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new
|
|
113
|
+
`)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new B(this.color).getSource(),r=s[0]*this.alpha,n=s[1]*this.alpha,o=s[2]*this.alpha,a=1-this.alpha;for(let c=0;c<e.length;c+=4){const h=e[c],l=e[c+1],u=e[c+2];switch(this.mode){case"multiply":e[c]=h*r/255,e[c+1]=l*n/255,e[c+2]=u*o/255;break;case"screen":e[c]=255-(255-h)*(255-r)/255,e[c+1]=255-(255-l)*(255-n)/255,e[c+2]=255-(255-u)*(255-o)/255;break;case"add":e[c]=h+r,e[c+1]=l+n,e[c+2]=u+o;break;case"difference":e[c]=Math.abs(h-r),e[c+1]=Math.abs(l-n),e[c+2]=Math.abs(u-o);break;case"subtract":e[c]=h-r,e[c+1]=l-n,e[c+2]=u-o;break;case"darken":e[c]=Math.min(h,r),e[c+1]=Math.min(l,n),e[c+2]=Math.min(u,o);break;case"lighten":e[c]=Math.max(h,r),e[c+1]=Math.max(l,n),e[c+2]=Math.max(u,o);break;case"overlay":e[c]=r<128?2*h*r/255:255-2*(255-h)*(255-r)/255,e[c+1]=n<128?2*l*n/255:255-2*(255-l)*(255-n)/255,e[c+2]=o<128?2*u*o/255:255-2*(255-u)*(255-o)/255;break;case"exclusion":e[c]=r+h-2*r*h/255,e[c+1]=n+l-2*n*l/255,e[c+2]=o+u-2*o*u/255;break;case"tint":e[c]=r+h*a,e[c+1]=n+l*a,e[c+2]=o+u*a}}}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)}}v(Jr,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),v(Jr,"type","BlendColor"),v(Jr,"uniformLocations",["uColor"]),C.setClass(Jr);const Ud={multiply:`
|
|
114
114
|
precision highp float;
|
|
115
115
|
uniform sampler2D uTexture;
|
|
116
116
|
uniform sampler2D uImage;
|
|
@@ -136,7 +136,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
136
136
|
color.a = color2.a;
|
|
137
137
|
gl_FragColor = color;
|
|
138
138
|
}
|
|
139
|
-
`}
|
|
139
|
+
`},$d=["type","image"];class Qr extends ot{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ud[this.mode]}getVertexSource(){return`
|
|
140
140
|
attribute vec2 aPosition;
|
|
141
141
|
varying vec2 vTexCoord;
|
|
142
142
|
varying vec2 vTexCoord2;
|
|
@@ -146,7 +146,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
146
146
|
vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
|
|
147
147
|
gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
|
|
148
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:
|
|
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:n}}=t;const o=this.image;n.blendImage||(n.blendImage=tt());const a=n.blendImage,c=a.getContext("2d");a.width!==s||a.height!==r?(a.width=s,a.height=r):c.clearRect(0,0,s,r),c.setTransform(o.scaleX,0,0,o.scaleY,o.left,o.top),c.drawImage(o.getElement(),0,0,s,r);const h=c.getImageData(0,0,s,r).data;for(let l=0;l<e.length;l+=4){const u=e[l],d=e[l+1],f=e[l+2],g=e[l+3],p=h[l],m=h[l+1],b=h[l+2],T=h[l+3];switch(this.mode){case"multiply":e[l]=u*p/255,e[l+1]=d*m/255,e[l+2]=f*b/255,e[l+3]=g*T/255;break;case"mask":e[l+3]=T}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return y(y({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:r}=t,n=U(t,$d);return Ot.fromObject(r,e).then(o=>new this(y(y({},n),{},{image:o})))}}v(Qr,"type","BlendImage"),v(Qr,"defaults",{mode:"multiply",alpha:1}),v(Qr,"uniformLocations",["uTransformMatrix","uImage"]),C.setClass(Qr);class ti extends ot{getFragmentSource(){return`
|
|
150
150
|
precision highp float;
|
|
151
151
|
uniform sampler2D uTexture;
|
|
152
152
|
uniform vec2 uDelta;
|
|
@@ -169,7 +169,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
169
169
|
}
|
|
170
170
|
gl_FragColor = color / total;
|
|
171
171
|
}
|
|
172
|
-
`}applyTo(t){
|
|
172
|
+
`}applyTo(t){Zr(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:s,filterBackend:{resources:r}}=t;const{width:n,height:o}=s;r.blurLayer1||(r.blurLayer1=tt(),r.blurLayer2=tt());const a=r.blurLayer1,c=r.blurLayer2;a.width===n&&a.height===o||(c.width=a.width=n,c.height=a.height=o);const h=a.getContext("2d"),l=c.getContext("2d"),u=15,d=.06*this.blur*.5;let f,g,p,m;for(h.putImageData(s,0,0),l.clearRect(0,0,n,o),m=-15;m<=u;m++)f=(Math.random()-.5)/4,g=m/u,p=d*g*n+f,l.globalAlpha=1-Math.abs(g),l.drawImage(a,p,f),h.drawImage(c,0,0),l.globalAlpha=1,l.clearRect(0,0,c.width,c.height);for(m=-15;m<=u;m++)f=(Math.random()-.5)/4,g=m/u,p=d*g*o+f,l.globalAlpha=1-Math.abs(g),l.drawImage(a,f,p),h.drawImage(c,0,0),l.globalAlpha=1,l.clearRect(0,0,c.width,c.height);e.drawImage(a,0,0);const b=e.getImageData(0,0,a.width,a.height);return h.globalAlpha=1,h.clearRect(0,0,a.width,a.height),b}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}v(ti,"type","Blur"),v(ti,"defaults",{blur:0}),v(ti,"uniformLocations",["uDelta"]),C.setClass(ti);class ei extends ot{getFragmentSource(){return`
|
|
173
173
|
precision highp float;
|
|
174
174
|
uniform sampler2D uTexture;
|
|
175
175
|
uniform float uBrightness;
|
|
@@ -179,7 +179,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
179
179
|
color.rgb += uBrightness;
|
|
180
180
|
gl_FragColor = color;
|
|
181
181
|
}
|
|
182
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let
|
|
182
|
+
`}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]=e[r]+s,e[r+1]=e[r+1]+s,e[r+2]=e[r+2]+s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}v(ei,"type","Brightness"),v(ei,"defaults",{brightness:0}),v(ei,"uniformLocations",["uBrightness"]),C.setClass(ei);class us extends ot{getFragmentSource(){return`
|
|
183
183
|
precision highp float;
|
|
184
184
|
uniform sampler2D uTexture;
|
|
185
185
|
varying vec2 vTexCoord;
|
|
@@ -190,7 +190,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
190
190
|
color *= uColorMatrix;
|
|
191
191
|
color += uConstants;
|
|
192
192
|
gl_FragColor = color;
|
|
193
|
-
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,
|
|
193
|
+
}`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,r=this.colorsOnly;for(let n=0;n<e.length;n+=4){const o=e[n],a=e[n+1],c=e[n+2];if(r)e[n]=o*s[0]+a*s[1]+c*s[2]+255*s[4],e[n+1]=o*s[5]+a*s[6]+c*s[7]+255*s[9],e[n+2]=o*s[10]+a*s[11]+c*s[12]+255*s[14];else{const h=e[n+3];e[n]=o*s[0]+a*s[1]+c*s[2]+h*s[3]+255*s[4],e[n+1]=o*s[5]+a*s[6]+c*s[7]+h*s[8]+255*s[9],e[n+2]=o*s[10]+a*s[11]+c*s[12]+h*s[13]+255*s[14],e[n+3]=o*s[15]+a*s[16]+c*s[17]+h*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]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,r),t.uniform4fv(e.uConstants,n)}toObject(){return y(y({},super.toObject()),{},{matrix:[...this.matrix]})}}function He(i,t){var e;const s=(v(e=class extends us{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",i),v(e,"defaults",{colorsOnly:!1,matrix:t}),e);return C.setClass(s,i),s}v(us,"type","ColorMatrix"),v(us,"defaults",{matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0}),v(us,"uniformLocations",["uColorMatrix","uConstants"]),C.setClass(us),He("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),He("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),He("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),He("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),He("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),He("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),He("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 Mc extends ot{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Zr(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=>C.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}v(Mc,"type","Composed"),C.setClass(Mc);class si extends ot{getFragmentSource(){return`
|
|
194
194
|
precision highp float;
|
|
195
195
|
uniform sampler2D uTexture;
|
|
196
196
|
uniform float uContrast;
|
|
@@ -200,7 +200,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
200
200
|
float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
|
|
201
201
|
color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
|
|
202
202
|
gl_FragColor = color;
|
|
203
|
-
}`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),
|
|
203
|
+
}`}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 n=0;n<e.length;n+=4)e[n]=r*(e[n]-128)+128,e[n+1]=r*(e[n+1]-128)+128,e[n+2]=r*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}v(si,"type","Contrast"),v(si,"defaults",{contrast:0}),v(si,"uniformLocations",["uContrast"]),C.setClass(si);const qd={Convolute_3_1:`
|
|
204
204
|
precision highp float;
|
|
205
205
|
uniform sampler2D uTexture;
|
|
206
206
|
uniform float uMatrix[9];
|
|
@@ -344,7 +344,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
344
344
|
gl_FragColor = color;
|
|
345
345
|
gl_FragColor.a = alpha;
|
|
346
346
|
}
|
|
347
|
-
`};class
|
|
347
|
+
`};class ri extends ot{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return qd[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,r=this.matrix,n=Math.round(Math.sqrt(r.length)),o=Math.floor(n/2),a=e.width,c=e.height,h=t.ctx.createImageData(a,c),l=h.data,u=this.opaque?1:0;let d,f,g,p,m,b,T,w,k,O,x,I,D;for(x=0;x<c;x++)for(O=0;O<a;O++){for(m=4*(x*a+O),d=0,f=0,g=0,p=0,D=0;D<n;D++)for(I=0;I<n;I++)T=x+D-o,b=O+I-o,T<0||T>=c||b<0||b>=a||(w=4*(T*a+b),k=r[D*n+I],d+=s[w]*k,f+=s[w+1]*k,g+=s[w+2]*k,u||(p+=s[w+3]*k));l[m]=d,l[m+1]=f,l[m+2]=g,l[m+3]=u?s[m+3]:p}t.imageData=h}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return y(y({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}v(ri,"type","Convolute"),v(ri,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),v(ri,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),C.setClass(ri);const Dc="Gamma";class ii extends ot{getFragmentSource(){return`
|
|
348
348
|
precision highp float;
|
|
349
349
|
uniform sampler2D uTexture;
|
|
350
350
|
uniform vec3 uGamma;
|
|
@@ -358,7 +358,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
358
358
|
gl_FragColor = color;
|
|
359
359
|
gl_FragColor.rgb *= color.a;
|
|
360
360
|
}
|
|
361
|
-
`}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,
|
|
361
|
+
`}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],n=1/s[1],o=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const a=this.rgbValues;for(let c=0;c<256;c++)a.r[c]=255*Math.pow(c/255,r),a.g[c]=255*Math.pow(c/255,n),a.b[c]=255*Math.pow(c/255,o);for(let c=0;c<e.length;c+=4)e[c]=a.r[e[c]],e[c+1]=a.g[e[c+1]],e[c+2]=a.b[e[c+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:Dc,gamma:this.gamma.concat()}}}v(ii,"type",Dc),v(ii,"defaults",{gamma:[1,1,1]}),v(ii,"uniformLocations",["uGamma"]),C.setClass(ii);const Kd={average:`
|
|
362
362
|
precision highp float;
|
|
363
363
|
uniform sampler2D uTexture;
|
|
364
364
|
varying vec2 vTexCoord;
|
|
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
387
387
|
float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
|
|
388
388
|
gl_FragColor = vec4(average, average, average, col.a);
|
|
389
389
|
}
|
|
390
|
-
`};class
|
|
390
|
+
`};class ni extends ot{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,r=0;r<e.length;r+=4){switch(this.mode){case"average":s=(e[r]+e[r+1]+e[r+2])/3;break;case"lightness":s=(Math.min(e[r],e[r+1],e[r+2])+Math.max(e[r],e[r+1],e[r+2]))/2;break;case"luminosity":s=.21*e[r]+.72*e[r+1]+.07*e[r+2]}e[r]=s,e[r+1]=s,e[r+2]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Kd[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}v(ni,"type","Grayscale"),v(ni,"defaults",{mode:"average"}),v(ni,"uniformLocations",["uMode"]),C.setClass(ni);class Dn extends us{calculateMatrix(){const t=this.rotation*Math.PI,e=It(t),s=jt(t),r=1/3,n=Math.sqrt(r)*s,o=1-e;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=e+o/3,this.matrix[1]=r*o-n,this.matrix[2]=r*o+n,this.matrix[5]=r*o+n,this.matrix[6]=e+r*o,this.matrix[7]=r*o-n,this.matrix[10]=r*o-n,this.matrix[11]=r*o+n,this.matrix[12]=e+r*o}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}v(Dn,"type","HueRotation"),v(Dn,"defaults",{rotation:0}),C.setClass(Dn);class oi extends ot{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`
|
|
391
391
|
precision highp float;
|
|
392
392
|
uniform sampler2D uTexture;
|
|
393
393
|
uniform int uInvert;
|
|
@@ -405,7 +405,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
405
405
|
gl_FragColor = color;
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}v(
|
|
408
|
+
`}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}v(oi,"type","Invert"),v(oi,"defaults",{alpha:!1,invert:!0}),v(oi,"uniformLocations",["uInvert","uAlpha"]),C.setClass(oi);class ai extends ot{getFragmentSource(){return`
|
|
409
409
|
precision highp float;
|
|
410
410
|
uniform sampler2D uTexture;
|
|
411
411
|
uniform float uStepH;
|
|
@@ -420,7 +420,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
420
420
|
color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
|
|
421
421
|
gl_FragColor = color;
|
|
422
422
|
}
|
|
423
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let
|
|
423
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let r=0;r<e.length;r+=4){const n=(.5-Math.random())*s;e[r]+=n,e[r+1]+=n,e[r+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}v(ai,"type","Noise"),v(ai,"defaults",{noise:0}),v(ai,"uniformLocations",["uNoise","uSeed"]),C.setClass(ai);class ci extends ot{applyTo2d(t){let{imageData:{data:e,width:s,height:r}}=t;for(let n=0;n<r;n+=this.blocksize)for(let o=0;o<s;o+=this.blocksize){const a=4*n*s+4*o,c=e[a],h=e[a+1],l=e[a+2],u=e[a+3];for(let d=n;d<Math.min(n+this.blocksize,r);d++)for(let f=o;f<Math.min(o+this.blocksize,s);f++){const g=4*d*s+4*f;e[g]=c,e[g+1]=h,e[g+2]=l,e[g+3]=u}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
|
|
424
424
|
precision highp float;
|
|
425
425
|
uniform sampler2D uTexture;
|
|
426
426
|
uniform float uBlocksize;
|
|
@@ -429,7 +429,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
429
429
|
varying vec2 vTexCoord;
|
|
430
430
|
void main() {
|
|
431
431
|
float blockW = uBlocksize * uStepW;
|
|
432
|
-
float blockH = uBlocksize *
|
|
432
|
+
float blockH = uBlocksize * uStepW;
|
|
433
433
|
int posX = int(vTexCoord.x / blockW);
|
|
434
434
|
int posY = int(vTexCoord.y / blockH);
|
|
435
435
|
float fposX = float(posX);
|
|
@@ -438,7 +438,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
|
|
|
438
438
|
vec4 color = texture2D(uTexture, squareCoords);
|
|
439
439
|
gl_FragColor = color;
|
|
440
440
|
}
|
|
441
|
-
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}v(
|
|
441
|
+
`}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}v(ci,"type","Pixelate"),v(ci,"defaults",{blocksize:4}),v(ci,"uniformLocations",["uBlocksize"]),C.setClass(ci);class hi extends ot{getFragmentSource(){return`
|
|
442
442
|
precision highp float;
|
|
443
443
|
uniform sampler2D uTexture;
|
|
444
444
|
uniform vec4 uLow;
|
|
@@ -450,7 +450,7 @@ void main() {
|
|
|
450
450
|
gl_FragColor.a = 0.0;
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,
|
|
453
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,r=new B(this.color).getSource(),n=[r[0]-s,r[1]-s,r[2]-s],o=[r[0]+s,r[1]+s,r[2]+s];for(let a=0;a<e.length;a+=4){const c=e[a],h=e[a+1],l=e[a+2];c>n[0]&&h>n[1]&&l>n[2]&&c<o[0]&&h<o[1]&&l<o[2]&&(e[a+3]=0)}}sendUniformData(t,e){const s=new B(this.color).getSource(),r=this.distance,n=[0+s[0]/255-r,0+s[1]/255-r,0+s[2]/255-r,1],o=[s[0]/255+r,s[1]/255+r,s[2]/255+r,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,o)}}v(hi,"type","RemoveColor"),v(hi,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),v(hi,"uniformLocations",["uLow","uHigh"]),C.setClass(hi);class li extends ot{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 n=1;n<=s;n++)r[n-1]=t(n*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`
|
|
454
454
|
precision highp float;
|
|
455
455
|
uniform sampler2D uTexture;
|
|
456
456
|
uniform vec2 uDelta;
|
|
@@ -459,14 +459,14 @@ void main() {
|
|
|
459
459
|
void main() {
|
|
460
460
|
vec4 color = texture2D(uTexture, vTexCoord);
|
|
461
461
|
float sum = 1.0;
|
|
462
|
-
`).concat(e.map((s,
|
|
463
|
-
color += texture2D(uTexture, vTexCoord + `.concat(s,") * uTaps[").concat(
|
|
464
|
-
sum += 2.0 * uTaps[`).concat(
|
|
462
|
+
`).concat(e.map((s,r)=>`
|
|
463
|
+
color += texture2D(uTexture, vTexCoord + `.concat(s,") * uTaps[").concat(r,"] + texture2D(uTexture, vTexCoord - ").concat(s,") * uTaps[").concat(r,`];
|
|
464
|
+
sum += 2.0 * uTaps[`).concat(r,`];
|
|
465
465
|
`)).join(`
|
|
466
466
|
`),`
|
|
467
467
|
gl_FragColor = color / sum;
|
|
468
468
|
}
|
|
469
|
-
`)}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){
|
|
469
|
+
`)}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){Zr(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 n=e.width,o=e.height,a=Math.round(n*s),c=Math.round(o*r);let h;h=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,o,a,c):this.resizeType==="hermite"?this.hermiteFastResize(t,n,o,a,c):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,o,a,c):this.resizeType==="lanczos"?this.lanczosResize(t,n,o,a,c):new ImageData(a,c),t.imageData=h}sliceByTwo(t,e,s,r,n){const o=t.imageData,a=.5;let c=!1,h=!1,l=e*a,u=s*a;const d=t.filterBackend.resources;let f=0,g=0;const p=e;let m=0;d.sliceByTwo||(d.sliceByTwo=tt());const b=d.sliceByTwo;(b.width<1.5*e||b.height<s)&&(b.width=1.5*e,b.height=s);const T=b.getContext("2d");for(T.clearRect(0,0,1.5*e,s),T.putImageData(o,0,0),r=Math.floor(r),n=Math.floor(n);!c||!h;)e=l,s=u,r<Math.floor(l*a)?l=Math.floor(l*a):(l=r,c=!0),n<Math.floor(u*a)?u=Math.floor(u*a):(u=n,h=!0),T.drawImage(b,f,g,e,s,p,m,l,u),f=p,g=m,m+=u;return T.getImageData(f,g,r,n)}lanczosResize(t,e,s,r,n){const o=t.imageData.data,a=t.ctx.createImageData(r,n),c=a.data,h=this.lanczosCreate(this.lanczosLobes),l=this.rcpScaleX,u=this.rcpScaleY,d=2/this.rcpScaleX,f=2/this.rcpScaleY,g=Math.ceil(l*this.lanczosLobes/2),p=Math.ceil(u*this.lanczosLobes/2),m={},b={x:0,y:0},T={x:0,y:0};return function w(k){let O,x,I,D,F,X,ct,W,H,nt,zt;for(b.x=(k+.5)*l,T.x=Math.floor(b.x),O=0;O<n;O++){for(b.y=(O+.5)*u,T.y=Math.floor(b.y),F=0,X=0,ct=0,W=0,H=0,x=T.x-g;x<=T.x+g;x++)if(!(x<0||x>=e)){nt=Math.floor(1e3*Math.abs(x-b.x)),m[nt]||(m[nt]={});for(let Dt=T.y-p;Dt<=T.y+p;Dt++)Dt<0||Dt>=s||(zt=Math.floor(1e3*Math.abs(Dt-b.y)),m[nt][zt]||(m[nt][zt]=h(Math.sqrt(Math.pow(nt*d,2)+Math.pow(zt*f,2))/1e3)),I=m[nt][zt],I>0&&(D=4*(Dt*e+x),F+=I,X+=I*o[D],ct+=I*o[D+1],W+=I*o[D+2],H+=I*o[D+3]))}D=4*(O*r+k),c[D]=X/F,c[D+1]=ct/F,c[D+2]=W/F,c[D+3]=H/F}return++k<r?w(k):a}(0)}bilinearFiltering(t,e,s,r,n){let o,a,c,h,l,u,d,f,g,p,m,b,T,w=0;const k=this.rcpScaleX,O=this.rcpScaleY,x=4*(e-1),I=t.imageData.data,D=t.ctx.createImageData(r,n),F=D.data;for(d=0;d<n;d++)for(f=0;f<r;f++)for(l=Math.floor(k*f),u=Math.floor(O*d),g=k*f-l,p=O*d-u,T=4*(u*e+l),m=0;m<4;m++)o=I[T+m],a=I[T+4+m],c=I[T+x+m],h=I[T+x+4+m],b=o*(1-g)*(1-p)+a*g*(1-p)+c*p*(1-g)+h*g*p,F[w++]=b;return D}hermiteFastResize(t,e,s,r,n){const o=this.rcpScaleX,a=this.rcpScaleY,c=Math.ceil(o/2),h=Math.ceil(a/2),l=t.imageData.data,u=t.ctx.createImageData(r,n),d=u.data;for(let f=0;f<n;f++)for(let g=0;g<r;g++){const p=4*(g+f*r);let m=0,b=0,T=0,w=0,k=0,O=0,x=0;const I=(f+.5)*a;for(let D=Math.floor(f*a);D<(f+1)*a;D++){const F=Math.abs(I-(D+.5))/h,X=(g+.5)*o,ct=F*F;for(let W=Math.floor(g*o);W<(g+1)*o;W++){let H=Math.abs(X-(W+.5))/c;const nt=Math.sqrt(ct+H*H);nt>1&&nt<-1||(m=2*nt*nt*nt-3*nt*nt+1,m>0&&(H=4*(W+D*e),x+=m*l[H+3],T+=m,l[H+3]<255&&(m=m*l[H+3]/250),w+=m*l[H],k+=m*l[H+1],O+=m*l[H+2],b+=m))}}d[p]=w/b,d[p+1]=k/b,d[p+2]=O/b,d[p+3]=x/T}return u}}v(li,"type","Resize"),v(li,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),v(li,"uniformLocations",["uDelta","uTaps"]),C.setClass(li);class ui extends ot{getFragmentSource(){return`
|
|
470
470
|
precision highp float;
|
|
471
471
|
uniform sampler2D uTexture;
|
|
472
472
|
uniform float uSaturation;
|
|
@@ -480,7 +480,7 @@ void main() {
|
|
|
480
480
|
color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
|
|
481
481
|
gl_FragColor = color;
|
|
482
482
|
}
|
|
483
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let
|
|
483
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let r=0;r<e.length;r+=4){const n=Math.max(e[r],e[r+1],e[r+2]);e[r]+=n!==e[r]?(n-e[r])*s:0,e[r+1]+=n!==e[r+1]?(n-e[r+1])*s:0,e[r+2]+=n!==e[r+2]?(n-e[r+2])*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}v(ui,"type","Saturation"),v(ui,"defaults",{saturation:0}),v(ui,"uniformLocations",["uSaturation"]),C.setClass(ui);class di extends ot{getFragmentSource(){return`
|
|
484
484
|
precision highp float;
|
|
485
485
|
uniform sampler2D uTexture;
|
|
486
486
|
uniform float uVibrance;
|
|
@@ -495,4 +495,4 @@ void main() {
|
|
|
495
495
|
color.b += max != color.b ? (max - color.b) * amt : 0.00;
|
|
496
496
|
gl_FragColor = color;
|
|
497
497
|
}
|
|
498
|
-
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=Math.max(e[i],e[i+1],e[i+2]),o=(e[i]+e[i+1]+e[i+2])/3,a=2*Math.abs(n-o)/255*s;e[i]+=n!==e[i]?(n-e[i])*a:0,e[i+1]+=n!==e[i+1]?(n-e[i+1])*a:0,e[i+2]+=n!==e[i+2]?(n-e[i+2])*a:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}v(lr,"type","Vibrance"),v(lr,"defaults",{vibrance:0}),v(lr,"uniformLocations",["uVibrance"]),w.setClass(lr);function Ft(r,t,e,s,i){r.save(),r.translate(t,e),r.rotate(rc.degreesToRadians(90+i.angle)),r.lineWidth=6,r.lineCap="round",r.strokeStyle="white",r.beginPath(),r.moveTo(-6,0),r.lineTo(6,0),r.stroke(),r.lineWidth=4,r.strokeStyle="black",r.beginPath(),r.moveTo(-6,0),r.lineTo(6,0),r.stroke(),r.restore()}const ae=1,Rt="rgba(255, 255, 255,1.0)",Ec=["Image","Text","Video","Audio","Caption","Template"],$d={left:-.5,top:-.5,center:0,bottom:.5,right:.5},P=r=>typeof r=="string"?$d[r]:r-.5,Ce="center",us="left",qd="top",Kd="bottom",ds="right",Jd="none";function gs(r){return P(r.originX)===P(Ce)&&P(r.originY)===P(Ce)}function Qs(r){return(t,e,s,i)=>{const{target:n,originX:o,originY:a}=e,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=r(t,e,s,i);return n.setPositionByOrigin(h,e.originX,e.originY),l}}const jc=188,Zd=1e3/60;function E(r,t=1,e=1){const s=jc*t;return r*(60/1e3)*s/e}function W(r,t=1,e=1){const s=jc*t;return r/s*Zd*e}function Qd(r,t=1){return E(r,t)}const En=r=>Object.keys(r).reduce((t,e)=>{const{display:s,playbackRate:i}=r[e];return Math.max(t,s.to/(i||1))},0),{wrapWithFireEvent:tg,getLocalPoint:eg}=Ye,jn=tg("resizing",Qs((r,t,e,s)=>{const i=eg(t,t.originX,t.originY,e,s);if(P(t.originX)===P(Ce)||P(t.originX)===P(ds)&&i.x<0||P(t.originX)===P(us)&&i.x>0){let{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(i.x*a/n.scaleX)-o);if(t.corner==="mr"){const u=n.trim.to,d=h-c,g=W(d,n.tScale,n.playbackRate),f=u+g;if(f>n.duration)return!1;n.set("width",Math.max(h,0)),n.trim.to=f}else{if(n.left<0)return!1;const u=c-h;if(n.left+u<0){const b=E(n.duration,n.tScale,n.playbackRate),T=n.width+n.left;if(T<=b){n.set("width",T);const S=W(b-T,n.tScale,n.playbackRate);return n.trim.from=S,!0}return!1}const g=h-c,f=n.trim.from,p=W(g,n.tScale,n.playbackRate),m=f-p;if(m<0)return!1;n.set("width",Math.max(h,0)),n.trim.from=m,n.onResize&&n.onResize()}return c!==n.width}return!1})),{wrapWithFireEvent:sg,getLocalPoint:ig,wrapWithFixedAnchor:rg}=Ye,ur=sg("resizing",rg((r,t,e,s)=>{const i=ig(t,t.originX,t.originY,e,s);if(P(t.originX)===P(Ce)||P(t.originX)===P(ds)&&i.x<0||P(t.originX)===P(us)&&i.x>0){const{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(i.x*a/n.scaleX)-o),l=t.corner==="ml";if(n.left<0)return!1;if(l){const u=c-h;if(n.left+u<0)return n.set("width",n.width+n.left),!0}return n.set("width",Math.max(h,0)),c!==n.width}return!1})),{wrapWithFireEvent:ng,getLocalPoint:og}=Ye,Pn=ng("resizing",Qs((r,t,e,s)=>{const i=og(t,t.originX,t.originY,e,s);if(P(t.originX)===P(Ce)||P(t.originX)===P(ds)&&i.x<0||P(t.originX)===P(us)&&i.x>0){const{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(i.x*a/n.scaleX)-o),l=W(h,n.tScale,n.playbackRate);return l>=1500||l<500?!1:(n.set("width",Math.max(h,0)),n.set("duration",l),c!==n.width)}return!1})),{wrapWithFireEvent:ag,getLocalPoint:cg}=Ye,Pc=ag("resizing",Qs((r,t,e,s)=>{const i=cg(t,t.originX,t.originY,e,s);if(P(t.originX)===P(Ce)||P(t.originX)===P(ds)&&i.x<0||P(t.originX)===P(us)&&i.x>0){let{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(i.x*a/n.scaleX)-o);if(t.corner==="mr"){const u=n.trim.to,d=h-c,g=W(d,n.tScale,n.playbackRate),f=u+g;if(f>n.duration)return!1;n.set("width",Math.max(h,0)),n.trim.to=f}else{if(n.left<0)return!1;const u=c-h;if(n.left+u<0)return!1;const g=h-c,f=n.trim.from,p=W(g,n.tScale,n.playbackRate),m=f-p;if(m<0)return!1;n.set("width",Math.max(h,0)),n.trim.from=m}return c!==n.width}return!1})),{scaleSkewCursorStyleHandler:$t}=Ye,dr=()=>({mr:new V({x:.5,y:0,actionHandler:ur,cursorStyleHandler:$t,actionName:"resizing",render:Ft}),ml:new V({x:-.5,y:0,actionHandler:ur,cursorStyleHandler:$t,actionName:"resizing",render:Ft})}),Ac=()=>({mr:new V({x:.5,y:0,render:Ft,actionHandler:Pc,cursorStyleHandler:$t,actionName:"resizing"}),ml:new V({x:-.5,y:0,render:Ft,actionHandler:Pc,cursorStyleHandler:$t,actionName:"resizing"})}),Lc=()=>({mr:new V({x:.5,y:0,render:Ft,actionHandler:jn,cursorStyleHandler:$t,actionName:"resizing"}),ml:new V({x:-.5,y:0,render:Ft,actionHandler:jn,cursorStyleHandler:$t,actionName:"resizing"})}),Fc=()=>({mr:new V({x:.5,y:0,render:Ft,actionHandler:Ln,cursorStyleHandler:$t,actionName:"resizing"}),ml:new V({x:-.5,y:0,render:Ft,actionHandler:Ln,cursorStyleHandler:$t,actionName:"resizing"})}),An=()=>({mr:new V({x:.5,y:0,actionHandler:Pn,cursorStyleHandler:$t,actionName:"resizing",render:Ft}),ml:new V({x:-.5,y:0,actionHandler:Pn,cursorStyleHandler:$t,actionName:"resizing",render:Ft})}),hg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ti=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r));for(;r--;)t+=hg[e[r]&63];return t};function fs(r=16){const t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",e=t.charAt(Math.floor(Math.random()*t.length));let s=ti(r-1);return s=s.replace(/[^a-zA-Z0-9]/g,"").slice(0,r-1),e+s}const{wrapWithFireEvent:lg,getLocalPoint:ug}=Ye,Ln=lg("resizing",Qs((r,t,e,s)=>{const i=ug(t,t.originX,t.originY,e,s);if(P(t.originX)===P(Ce)||P(t.originX)===P(ds)&&i.x<0||P(t.originX)===P(us)&&i.x>0){let{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(i.x*a/n.scaleX)-o);if(t.corner==="mr"){const u=n.trim.to,d=h-c,g=W(d,n.tScale,n.playbackRate),f=u+g;if(f>n.duration)return!1;n.set("width",Math.max(h,0)),n.trim.to=f}else{if(n.left<0)return!1;const u=c-h;if(n.left+u<0){const b=E(n.duration,n.tScale,n.playbackRate),T=n.width+n.left;if(T<=b){n.set("width",T);const S=W(b-T,n.tScale,n.playbackRate);return n.trim.from=S,!0}return!1}const g=h-c,f=n.trim.from,p=W(g,n.tScale,n.playbackRate),m=f-p;if(m<0)return!1;n.set("width",Math.max(h,0)),n.trim.from=m,n.onResize&&n.onResize()}return c!==n.width}return!1})),Cs=class Cs extends z{constructor(e){super(e);x(this,"itemType","image");x(this,"src");x(this,"isSelected",!1);Object.assign(this,Cs.ownDefaults),this.id=e.id,this.src=e.src,this.display=e.display,this.tScale=e.tScale}static createControls(){return{controls:dr()}}static getDefaults(){return{...super.getDefaults(),...Cs.ownDefaults}}_render(e){super._render(e),this.updateSelected(e)}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}setSrc(e){this.src=e}};x(Cs,"type","Image"),x(Cs,"ownDefaults",{rx:8,ry:8,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,borderOpacityWhenMoving:1,hoverCursor:"default",fill:"#27272a"});let ps=Cs;w.setClass(ps,"Image");class bt extends z{constructor(e){super(e);x(this,"id");x(this,"resourceId","");x(this,"tScale");x(this,"isSelected",!1);x(this,"display");x(this,"trim");x(this,"duration");x(this,"src");this.id=e.id,this.tScale=e.tScale,this.objectCaching=!1,this.rx=8,this.ry=8,this.display=e.display,this.trim=e.trim,this.duration=e.duration,this.fill="#27272a"}static createControls(){return{controls:Fc()}}_render(e){super._render(e),this.updateSelected(e)}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}onResizeSnap(){}setSrc(e){this.src=e}}x(bt,"type","Video"),w.setClass(bt,"Video");const Os=class Os extends z{constructor(e){super(e);x(this,"itemType","audio");x(this,"isSelected",!1);x(this,"trim");x(this,"src");x(this,"duration");Object.assign(this,Os.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.trim=e.trim,this.src=e.src,this.duration=e.duration}static getDefaults(){return{...super.getDefaults(),...Os.ownDefaults}}static createControls(){return{controls:Lc()}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}setSrc(e){this.src=e}};x(Os,"type","Audio"),x(Os,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let pt=Os;w.setClass(pt,"Audio");const ks=class ks extends z{constructor(e){super(e);x(this,"isSelected",!1);x(this,"text");Object.assign(this,ks.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.text=e.text}static createControls(){return{controls:dr()}}static getDefaults(){return{...super.getDefaults(),...ks.ownDefaults}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}};x(ks,"type","Text"),x(ks,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let ms=ks;w.setClass(ms,"Text");const dg={selectable:!1,evented:!1,strokeWidth:0,stroke:"transparent"},Ms=class Ms extends z{constructor(e){super(e);x(this,"id");x(this,"accepts",["audio","video","image","text","caption","template"]);x(this,"metadata");x(this,"items",[]);x(this,"magnetic");x(this,"static");Object.assign(this,Ms.ownDefaults),this.id=e.id,this.accepts=e.accepts||[],this.items=e.items||[],this.magnetic=e.magnetic,this.static=e.static,this.metadata=e.metadata,this.fill="rgba(34, 34, 37, 0.8)"}static getDefaults(){return{...super.getDefaults(),...Ms.ownDefaults}}updateCoords(e){this.width=e}};x(Ms,"ownDefaults",dg),x(Ms,"type","Track");let Oe=Ms;w.setClass(Oe,"Track");const gg={top:{top:35,guide:2,bottom:3},center:{top:3,guide:2,bottom:3},bottom:{top:3,guide:2,bottom:35}},fg=(r,t)=>{const e=gg[r];return r==="top"?{top:t-(e.guide+e.bottom),guide:e.guide,bottom:e.bottom}:r==="center"?{top:e.top,guide:e.guide,bottom:e.bottom}:{top:e==null?void 0:e.top,guide:e==null?void 0:e.guide,bottom:t-((e==null?void 0:e.guide)+(e==null?void 0:e.top))}},Ds=class Ds extends Nt{constructor(e){const s=fg(e.kind,e.height),i=new z({top:0,left:0,strokeWidth:0,fill:"transparent",selectable:!0,height:s.top,width:e.width}),n=new z({top:s.top,left:0,strokeWidth:0,fill:"transparent",selectable:!0,height:s.guide,width:e.width}),o=new z({top:s.top+s.guide,left:0,strokeWidth:0,fill:"transparent",selectable:!0,height:s.bottom,width:e.width});super([i,n,o],e);x(this,"guide");x(this,"topGuide");x(this,"bottomGuide");x(this,"metadata");x(this,"accepts",[]);x(this,"kind");x(this,"activeGuideFill");Object.assign(this,Ds.ownDefaults),this.guide=n,this.topGuide=i,this.bottomGuide=o,this.id=e.id,this.metadata=e.metadata,this.tScale=e.tScale,this.kind=e.kind,this.activeGuideFill=e.activeGuideFill||Rt}static getDefaults(){return{...super.getDefaults(),...Ds.ownDefaults}}updateCoords(e){this.scaleToWidth(e),this.set("scaleY",1)}setSelected(e){e?this.guide.set("fill",this.activeGuideFill):this.guide.set("fill","transparent")}};x(Ds,"type","Helper"),x(Ds,"ownDefaults",{selectable:!1,evented:!1});let Ve=Ds;w.setClass(Ve,"Helper");const Is=class Is extends z{constructor(e){super(e);x(this,"guideItemId");x(this,"distXToActCenter");x(this,"trackItemType");x(this,"defaultPos");x(this,"draggedObject");Object.assign(this,Is.ownDefaults),this.id=e.id}static getDefaults(){return{...super.getDefaults(),...Is.ownDefaults}}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=ae,e.setLineDash(this.strokeDashArray),e.strokeStyle=Rt,e.stroke(),e.restore()}};x(Is,"type","Placeholder"),x(Is,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",strokeWidth:0,fill:"rgba(255, 211, 42,0.1)",stroke:"rgba(255, 211, 42,1.0)",selectable:!1,borderOpacityWhenMoving:1,hoverCursor:"default",strokeDashArray:[5,1],evented:!1});let vs=Is;w.setClass(vs,"Placeholder");const Es=class Es extends z{constructor(e){super(e);x(this,"duration");x(this,"fromId");x(this,"toId");x(this,"kind","none");x(this,"isSelected",!1);Object.assign(this,Es.ownDefaults),this.id=e.id,this.centeredScaling=!0,this.strokeWidth=0,this.tScale=e.tScale,this.duration=e.duration,this.fromId=e.fromId,this.toId=e.toId,this.kind=e.kind,this.strokeDashArray=e.strokeDashArray||[]}static createControls(){return{controls:An()}}static getDefaults(){return{...super.getDefaults(),...Es.ownDefaults}}updateCoords(){}_render(e){super._render(e),this.updateSelected(e)}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){const s=this.isSelected?Rt:"rgba(255, 255, 255,0.15)";e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=ae,e.setLineDash(this.strokeDashArray),e.strokeStyle=s,e.stroke(),e.restore()}};x(Es,"type","Transition"),x(Es,"ownDefaults",{objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:1.5,fill:"rgba(0,0,0, 0.5)",borderOpacityWhenMoving:1,hoverCursor:"default",lockMovementX:!0,lockMovementY:!0,duration:1500,rx:8,ry:8});let ce=Es;w.setClass(ce,"Transition");const js=class js extends z{constructor(e){super(e);x(this,"isSelected",!1);x(this,"text");Object.assign(this,js.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.text=e.text}static createControls(){return{controls:dr()}}static getDefaults(){return{...super.getDefaults(),...js.ownDefaults}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}};x(js,"type","Caption"),x(js,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let ys=js;w.setClass(ys,"Caption");const Ps=class Ps extends z{constructor(e){super(e);x(this,"itemType","template");x(this,"isSelected",!1);x(this,"trim");Object.assign(this,Ps.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.trim=e.trim}static getDefaults(){return{...super.getDefaults(),...Ps.ownDefaults}}static createControls(){return{controls:Ac()}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}};x(Ps,"type","Template"),x(Ps,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let Bt=Ps;w.setClass(Bt,"Template");function pg(r){const t=Math.floor(r/1e3),e=Math.floor(t/60),s=t%60,i=String(e).padStart(2,"0"),n=String(s).padStart(2,"0");return`${i}:${n}`}const As=class As extends z{constructor(e){super(e);x(this,"duration");x(this,"fromId");x(this,"toId");x(this,"isSelected",!1);x(this,"name");x(this,"durationString");x(this,"itemType");Object.assign(this,As.ownDefaults),this.id=e.id,this.fill="#27272a",this.name=e.type.toUpperCase(),this.durationString=pg(e.duration),this.itemType=e.type}static getDefaults(){return{...super.getDefaults(),...As.ownDefaults}}_render(e){e.save(),super._render(e),e.beginPath(),e.rect(-this.width/2,-this.height/2,this.width,this.height),e.clip(),this.drawTextIdentity(e),e.restore()}drawTextIdentity(e){e.font="600 12px 'Geist variable'",e.textAlign="left";const s=e.measureText(this.name).width,i=e.measureText(this.durationString).width,n=8,o=4,a=4-this.height/2,c=20,h=4,l=4-this.width/2,u=s+n*2;this.drawRoundedRect(e,l,a,u,c,h),e.fillStyle="#f4f4f5",e.fillText(this.name,l+n,a+14);const d=l+u+o,g=i+n*2;this.drawRoundedRect(e,d,a,g,c,h),e.fillStyle="#f4f4f5",e.fillText(this.durationString,d+n,a+14)}drawRoundedRect(e,s,i,n,o,a){e.fillStyle="rgba(0, 0, 0, 0.5)",e.roundRect?(e.beginPath(),e.roundRect(s,i,n,o,a),e.fill()):e.fillRect(s,i,n,o)}};x(As,"type","PreviewTrackItem"),x(As,"ownDefaults",{objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,borderOpacityWhenMoving:1,hoverCursor:"default",rx:4,ry:4});let he=As;w.setClass(he,"PreviewTrackItem");class mg{constructor(){x(this,"___eventListeners",{});x(this,"___activeObjects",[])}resize(t,{force:e}={force:!1}){var s;this.lowerCanvasEl&&(this.setDimensions(t),e&&this.renderTracks(),(s=this.onResizeCanvas)==null||s.call(this,{width:this.width,height:this.height}))}pauseEventListeners(){this.___eventListeners=this.__eventListeners,this.__eventListeners={};const t=this.getActiveObjects();this.discardActiveObject(),this.___activeObjects=t}resumeEventListeners(){this.__eventListeners=this.___eventListeners,this.___eventListeners={};const t=this.___activeObjects;if(!t.length)return this.requestRenderAll(),!1;if(t.length===1)this.setActiveObject(t[0]);else{const e=new kt(t);this.setActiveObject(e)}this.requestRenderAll()}updateCachingActiveObjects(t){const e=this.___activeObjects;this.___activeObjects=e.map(s=>{const i=t.find(n=>n.id===s.id);return i||s})}}function ei(r,t){return r.map(e=>({...e,items:e.items.filter(s=>!t.includes(s))}))}const vg=(r,t)=>{var a;const e=E(r.display.from,t.tScale),s=E(r.duration,t.tScale,r.playbackRate),i=t.sizesMap.video,n=w.getClass("Video")||bt;return new n({width:s,height:i,id:r.id,tScale:t.tScale,fill:"#333333",resourceId:(a=r.metadata)==null?void 0:a.resourceId,duration:r.duration,top:10,left:e,display:r.display,trim:r.trim,src:r.details.src,metadata:r.metadata})},yg=(r,t)=>{const e=r.display,s=E(e.from,t.tScale),i=E(e.to-e.from,t.tScale),n=t.sizesMap.text,o=w.getClass("Text")||ms;return new o({width:i,height:n,id:r.id,display:e,top:10,left:s,text:r.details.text,tScale:t.tScale})},bg=(r,t)=>{const e=r.display,s=E(e.from,t.tScale),i=E(e.to-e.from,t.tScale),n=t.sizesMap.caption,o=w.getClass("Caption")||ys;return new o({width:i,height:n,id:r.id,display:e,top:10,left:s,text:r.details.text,tScale:t.tScale})},_g=(r,t)=>{const e=E(r.display.from,t.tScale),s=E(r.display.to-(r.display.from||5e3),t.tScale),i=t.sizesMap.image,n=w.getClass("Image")||ps;return new n({width:s,height:i,id:r.id,src:r.details.src,tScale:t.tScale,top:10,left:e,display:r.display})},Tg=(r,t)=>{const e=r.display,s=E(e.from,t.tScale),i=E(e.to-e.from,t.tScale,r.playbackRate),n=t.sizesMap.audio,o=w.getClass("Audio")||pt;return new o({width:i,height:n,top:10,left:s,id:r.id,display:e,trim:r.trim||{from:0,to:r.duration},duration:r.duration,src:r.details.src,tScale:t.tScale})},Sg=(r,t)=>{const e=r.display,s=E(e.from,t.tScale),i=E(e.to-e.from,t.tScale),n=42,o=w.getClass("Template")||Bt;return new o({width:i,height:n,top:10,left:s,id:r.id,display:e,duration:e.to-e.from,tScale:t.tScale,trim:r.trim||r.display})},xg=(r,t)=>{if(r.type==="caption")return bg(r,t);if(r.type==="text")return yg(r,t);if(r.type==="image")return _g(r,t);if(r.type==="video")return vg(r,t);if(r.type==="audio")return Tg(r,t);if(r.type==="template")return Sg(r,t)};var Rc=typeof global=="object"&&global&&global.Object===Object&&global,wg=typeof self=="object"&&self&&self.Object===Object&&self,Wt=Rc||wg||Function("return this")(),Dt=Wt.Symbol,Bc=Object.prototype,Cg=Bc.hasOwnProperty,Og=Bc.toString,si=Dt?Dt.toStringTag:void 0;function kg(r){var t=Cg.call(r,si),e=r[si];try{r[si]=void 0;var s=!0}catch{}var i=Og.call(r);return s&&(t?r[si]=e:delete r[si]),i}var Mg=Object.prototype,Dg=Mg.toString;function Ig(r){return Dg.call(r)}var Eg="[object Null]",jg="[object Undefined]",Wc=Dt?Dt.toStringTag:void 0;function bs(r){return r==null?r===void 0?jg:Eg:Wc&&Wc in Object(r)?kg(r):Ig(r)}function ke(r){return r!=null&&typeof r=="object"}var Pg="[object Symbol]";function gr(r){return typeof r=="symbol"||ke(r)&&bs(r)==Pg}function Ag(r,t){for(var e=-1,s=r==null?0:r.length,i=Array(s);++e<s;)i[e]=t(r[e],e,r);return i}var qt=Array.isArray,Lg=1/0,Xc=Dt?Dt.prototype:void 0,zc=Xc?Xc.toString:void 0;function Hc(r){if(typeof r=="string")return r;if(qt(r))return Ag(r,Hc)+"";if(gr(r))return zc?zc.call(r):"";var t=r+"";return t=="0"&&1/r==-Lg?"-0":t}var Fg=/\s/;function Rg(r){for(var t=r.length;t--&&Fg.test(r.charAt(t)););return t}var Bg=/^\s+/;function Wg(r){return r&&r.slice(0,Rg(r)+1).replace(Bg,"")}function Xt(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}var Yc=NaN,Xg=/^[-+]0x[0-9a-f]+$/i,zg=/^0b[01]+$/i,Hg=/^0o[0-7]+$/i,Yg=parseInt;function Gc(r){if(typeof r=="number")return r;if(gr(r))return Yc;if(Xt(r)){var t=typeof r.valueOf=="function"?r.valueOf():r;r=Xt(t)?t+"":t}if(typeof r!="string")return r===0?r:+r;r=Wg(r);var e=zg.test(r);return e||Hg.test(r)?Yg(r.slice(2),e?2:8):Xg.test(r)?Yc:+r}function Gg(r){return r}var Vg="[object AsyncFunction]",Ng="[object Function]",Ug="[object GeneratorFunction]",$g="[object Proxy]";function Vc(r){if(!Xt(r))return!1;var t=bs(r);return t==Ng||t==Ug||t==Vg||t==$g}var Fn=Wt["__core-js_shared__"],Nc=function(){var r=/[^.]+$/.exec(Fn&&Fn.keys&&Fn.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""}();function qg(r){return!!Nc&&Nc in r}var Kg=Function.prototype,Jg=Kg.toString;function Ne(r){if(r!=null){try{return Jg.call(r)}catch{}try{return r+""}catch{}}return""}var Zg=/[\\^$.*+?()[\]{}|]/g,Qg=/^\[object .+?Constructor\]$/,tf=Function.prototype,ef=Object.prototype,sf=tf.toString,rf=ef.hasOwnProperty,nf=RegExp("^"+sf.call(rf).replace(Zg,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function of(r){if(!Xt(r)||qg(r))return!1;var t=Vc(r)?nf:Qg;return t.test(Ne(r))}function af(r,t){return r==null?void 0:r[t]}function Ue(r,t){var e=af(r,t);return of(e)?e:void 0}var Rn=Ue(Wt,"WeakMap"),Uc=Object.create,cf=function(){function r(){}return function(t){if(!Xt(t))return{};if(Uc)return Uc(t);r.prototype=t;var e=new r;return r.prototype=void 0,e}}();function hf(r,t,e){switch(e.length){case 0:return r.call(t);case 1:return r.call(t,e[0]);case 2:return r.call(t,e[0],e[1]);case 3:return r.call(t,e[0],e[1],e[2])}return r.apply(t,e)}function lf(r,t){var e=-1,s=r.length;for(t||(t=Array(s));++e<s;)t[e]=r[e];return t}var uf=800,df=16,gf=Date.now;function ff(r){var t=0,e=0;return function(){var s=gf(),i=df-(s-e);if(e=s,i>0){if(++t>=uf)return arguments[0]}else t=0;return r.apply(void 0,arguments)}}function pf(r){return function(){return r}}var fr=function(){try{var r=Ue(Object,"defineProperty");return r({},"",{}),r}catch{}}(),mf=fr?function(r,t){return fr(r,"toString",{configurable:!0,enumerable:!1,value:pf(t),writable:!0})}:Gg,vf=ff(mf);function yf(r,t){for(var e=-1,s=r==null?0:r.length;++e<s&&t(r[e],e,r)!==!1;);return r}var bf=9007199254740991,_f=/^(?:0|[1-9]\d*)$/;function Bn(r,t){var e=typeof r;return t=t??bf,!!t&&(e=="number"||e!="symbol"&&_f.test(r))&&r>-1&&r%1==0&&r<t}function $c(r,t,e){t=="__proto__"&&fr?fr(r,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):r[t]=e}function Wn(r,t){return r===t||r!==r&&t!==t}var Tf=Object.prototype,Sf=Tf.hasOwnProperty;function Xn(r,t,e){var s=r[t];(!(Sf.call(r,t)&&Wn(s,e))||e===void 0&&!(t in r))&&$c(r,t,e)}function pr(r,t,e,s){var i=!e;e||(e={});for(var n=-1,o=t.length;++n<o;){var a=t[n],c=void 0;c===void 0&&(c=r[a]),i?$c(e,a,c):Xn(e,a,c)}return e}var qc=Math.max;function xf(r,t,e){return t=qc(t===void 0?r.length-1:t,0),function(){for(var s=arguments,i=-1,n=qc(s.length-t,0),o=Array(n);++i<n;)o[i]=s[t+i];i=-1;for(var a=Array(t+1);++i<t;)a[i]=s[i];return a[t]=e(o),hf(r,this,a)}}var wf=9007199254740991;function zn(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=wf}function Kc(r){return r!=null&&zn(r.length)&&!Vc(r)}var Cf=Object.prototype;function Hn(r){var t=r&&r.constructor,e=typeof t=="function"&&t.prototype||Cf;return r===e}function Of(r,t){for(var e=-1,s=Array(r);++e<r;)s[e]=t(e);return s}var kf="[object Arguments]";function Jc(r){return ke(r)&&bs(r)==kf}var Zc=Object.prototype,Mf=Zc.hasOwnProperty,Df=Zc.propertyIsEnumerable,Yn=Jc(function(){return arguments}())?Jc:function(r){return ke(r)&&Mf.call(r,"callee")&&!Df.call(r,"callee")};function If(){return!1}var Qc=typeof k=="object"&&k&&!k.nodeType&&k,th=Qc&&typeof module=="object"&&module&&!module.nodeType&&module,Ef=th&&th.exports===Qc,eh=Ef?Wt.Buffer:void 0,jf=eh?eh.isBuffer:void 0,mr=jf||If,Pf="[object Arguments]",Af="[object Array]",Lf="[object Boolean]",Ff="[object Date]",Rf="[object Error]",Bf="[object Function]",Wf="[object Map]",Xf="[object Number]",zf="[object Object]",Hf="[object RegExp]",Yf="[object Set]",Gf="[object String]",Vf="[object WeakMap]",Nf="[object ArrayBuffer]",Uf="[object DataView]",$f="[object Float32Array]",qf="[object Float64Array]",Kf="[object Int8Array]",Jf="[object Int16Array]",Zf="[object Int32Array]",Qf="[object Uint8Array]",tp="[object Uint8ClampedArray]",ep="[object Uint16Array]",sp="[object Uint32Array]",H={};H[$f]=H[qf]=H[Kf]=H[Jf]=H[Zf]=H[Qf]=H[tp]=H[ep]=H[sp]=!0,H[Pf]=H[Af]=H[Nf]=H[Lf]=H[Uf]=H[Ff]=H[Rf]=H[Bf]=H[Wf]=H[Xf]=H[zf]=H[Hf]=H[Yf]=H[Gf]=H[Vf]=!1;function ip(r){return ke(r)&&zn(r.length)&&!!H[bs(r)]}function Gn(r){return function(t){return r(t)}}var sh=typeof k=="object"&&k&&!k.nodeType&&k,ii=sh&&typeof module=="object"&&module&&!module.nodeType&&module,rp=ii&&ii.exports===sh,Vn=rp&&Rc.process,_s=function(){try{var r=ii&&ii.require&&ii.require("util").types;return r||Vn&&Vn.binding&&Vn.binding("util")}catch{}}(),ih=_s&&_s.isTypedArray,rh=ih?Gn(ih):ip,np=Object.prototype,op=np.hasOwnProperty;function nh(r,t){var e=qt(r),s=!e&&Yn(r),i=!e&&!s&&mr(r),n=!e&&!s&&!i&&rh(r),o=e||s||i||n,a=o?Of(r.length,String):[],c=a.length;for(var h in r)(t||op.call(r,h))&&!(o&&(h=="length"||i&&(h=="offset"||h=="parent")||n&&(h=="buffer"||h=="byteLength"||h=="byteOffset")||Bn(h,c)))&&a.push(h);return a}function oh(r,t){return function(e){return r(t(e))}}var ap=oh(Object.keys,Object),cp=Object.prototype,hp=cp.hasOwnProperty;function lp(r){if(!Hn(r))return ap(r);var t=[];for(var e in Object(r))hp.call(r,e)&&e!="constructor"&&t.push(e);return t}function Nn(r){return Kc(r)?nh(r):lp(r)}function up(r){var t=[];if(r!=null)for(var e in Object(r))t.push(e);return t}var dp=Object.prototype,gp=dp.hasOwnProperty;function fp(r){if(!Xt(r))return up(r);var t=Hn(r),e=[];for(var s in r)s=="constructor"&&(t||!gp.call(r,s))||e.push(s);return e}function Un(r){return Kc(r)?nh(r,!0):fp(r)}var pp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,mp=/^\w*$/;function vp(r,t){if(qt(r))return!1;var e=typeof r;return e=="number"||e=="symbol"||e=="boolean"||r==null||gr(r)?!0:mp.test(r)||!pp.test(r)||t!=null&&r in Object(t)}var ri=Ue(Object,"create");function yp(){this.__data__=ri?ri(null):{},this.size=0}function bp(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}var _p="__lodash_hash_undefined__",Tp=Object.prototype,Sp=Tp.hasOwnProperty;function xp(r){var t=this.__data__;if(ri){var e=t[r];return e===_p?void 0:e}return Sp.call(t,r)?t[r]:void 0}var wp=Object.prototype,Cp=wp.hasOwnProperty;function Op(r){var t=this.__data__;return ri?t[r]!==void 0:Cp.call(t,r)}var kp="__lodash_hash_undefined__";function Mp(r,t){var e=this.__data__;return this.size+=this.has(r)?0:1,e[r]=ri&&t===void 0?kp:t,this}function $e(r){var t=-1,e=r==null?0:r.length;for(this.clear();++t<e;){var s=r[t];this.set(s[0],s[1])}}$e.prototype.clear=yp,$e.prototype.delete=bp,$e.prototype.get=xp,$e.prototype.has=Op,$e.prototype.set=Mp;function Dp(){this.__data__=[],this.size=0}function vr(r,t){for(var e=r.length;e--;)if(Wn(r[e][0],t))return e;return-1}var Ip=Array.prototype,Ep=Ip.splice;function jp(r){var t=this.__data__,e=vr(t,r);if(e<0)return!1;var s=t.length-1;return e==s?t.pop():Ep.call(t,e,1),--this.size,!0}function Pp(r){var t=this.__data__,e=vr(t,r);return e<0?void 0:t[e][1]}function Ap(r){return vr(this.__data__,r)>-1}function Lp(r,t){var e=this.__data__,s=vr(e,r);return s<0?(++this.size,e.push([r,t])):e[s][1]=t,this}function le(r){var t=-1,e=r==null?0:r.length;for(this.clear();++t<e;){var s=r[t];this.set(s[0],s[1])}}le.prototype.clear=Dp,le.prototype.delete=jp,le.prototype.get=Pp,le.prototype.has=Ap,le.prototype.set=Lp;var ni=Ue(Wt,"Map");function Fp(){this.size=0,this.__data__={hash:new $e,map:new(ni||le),string:new $e}}function Rp(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}function yr(r,t){var e=r.__data__;return Rp(t)?e[typeof t=="string"?"string":"hash"]:e.map}function Bp(r){var t=yr(this,r).delete(r);return this.size-=t?1:0,t}function Wp(r){return yr(this,r).get(r)}function Xp(r){return yr(this,r).has(r)}function zp(r,t){var e=yr(this,r),s=e.size;return e.set(r,t),this.size+=e.size==s?0:1,this}function ue(r){var t=-1,e=r==null?0:r.length;for(this.clear();++t<e;){var s=r[t];this.set(s[0],s[1])}}ue.prototype.clear=Fp,ue.prototype.delete=Bp,ue.prototype.get=Wp,ue.prototype.has=Xp,ue.prototype.set=zp;var Hp="Expected a function";function $n(r,t){if(typeof r!="function"||t!=null&&typeof t!="function")throw new TypeError(Hp);var e=function(){var s=arguments,i=t?t.apply(this,s):s[0],n=e.cache;if(n.has(i))return n.get(i);var o=r.apply(this,s);return e.cache=n.set(i,o)||n,o};return e.cache=new($n.Cache||ue),e}$n.Cache=ue;var Yp=500;function Gp(r){var t=$n(r,function(s){return e.size===Yp&&e.clear(),s}),e=t.cache;return t}var Vp=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Np=/\\(\\)?/g,Up=Gp(function(r){var t=[];return r.charCodeAt(0)===46&&t.push(""),r.replace(Vp,function(e,s,i,n){t.push(i?n.replace(Np,"$1"):s||e)}),t});function $p(r){return r==null?"":Hc(r)}function br(r,t){return qt(r)?r:vp(r,t)?[r]:Up($p(r))}var qp=1/0;function qn(r){if(typeof r=="string"||gr(r))return r;var t=r+"";return t=="0"&&1/r==-qp?"-0":t}function Kp(r,t){t=br(t,r);for(var e=0,s=t.length;r!=null&&e<s;)r=r[qn(t[e++])];return e&&e==s?r:void 0}function Kn(r,t){for(var e=-1,s=t.length,i=r.length;++e<s;)r[i+e]=t[e];return r}var ah=Dt?Dt.isConcatSpreadable:void 0;function Jp(r){return qt(r)||Yn(r)||!!(ah&&r&&r[ah])}function Zp(r,t,e,s,i){var n=-1,o=r.length;for(e||(e=Jp),i||(i=[]);++n<o;){var a=r[n];e(a)?Kn(i,a):i[i.length]=a}return i}function Jn(r){var t=r==null?0:r.length;return t?Zp(r):[]}function Qp(r){return vf(xf(r,void 0,Jn),r+"")}var ch=oh(Object.getPrototypeOf,Object);function tm(){this.__data__=new le,this.size=0}function em(r){var t=this.__data__,e=t.delete(r);return this.size=t.size,e}function sm(r){return this.__data__.get(r)}function im(r){return this.__data__.has(r)}var rm=200;function nm(r,t){var e=this.__data__;if(e instanceof le){var s=e.__data__;if(!ni||s.length<rm-1)return s.push([r,t]),this.size=++e.size,this;e=this.__data__=new ue(s)}return e.set(r,t),this.size=e.size,this}function de(r){var t=this.__data__=new le(r);this.size=t.size}de.prototype.clear=tm,de.prototype.delete=em,de.prototype.get=sm,de.prototype.has=im,de.prototype.set=nm;function om(r,t){return r&&pr(t,Nn(t),r)}function am(r,t){return r&&pr(t,Un(t),r)}var hh=typeof k=="object"&&k&&!k.nodeType&&k,lh=hh&&typeof module=="object"&&module&&!module.nodeType&&module,cm=lh&&lh.exports===hh,uh=cm?Wt.Buffer:void 0,dh=uh?uh.allocUnsafe:void 0;function hm(r,t){if(t)return r.slice();var e=r.length,s=dh?dh(e):new r.constructor(e);return r.copy(s),s}function lm(r,t){for(var e=-1,s=r==null?0:r.length,i=0,n=[];++e<s;){var o=r[e];t(o,e,r)&&(n[i++]=o)}return n}function gh(){return[]}var um=Object.prototype,dm=um.propertyIsEnumerable,fh=Object.getOwnPropertySymbols,Zn=fh?function(r){return r==null?[]:(r=Object(r),lm(fh(r),function(t){return dm.call(r,t)}))}:gh;function gm(r,t){return pr(r,Zn(r),t)}var fm=Object.getOwnPropertySymbols,ph=fm?function(r){for(var t=[];r;)Kn(t,Zn(r)),r=ch(r);return t}:gh;function pm(r,t){return pr(r,ph(r),t)}function mh(r,t,e){var s=t(r);return qt(r)?s:Kn(s,e(r))}function Qn(r){return mh(r,Nn,Zn)}function mm(r){return mh(r,Un,ph)}var to=Ue(Wt,"DataView"),eo=Ue(Wt,"Promise"),so=Ue(Wt,"Set"),vh="[object Map]",vm="[object Object]",yh="[object Promise]",bh="[object Set]",_h="[object WeakMap]",Th="[object DataView]",ym=Ne(to),bm=Ne(ni),_m=Ne(eo),Tm=Ne(so),Sm=Ne(Rn),zt=bs;(to&&zt(new to(new ArrayBuffer(1)))!=Th||ni&&zt(new ni)!=vh||eo&&zt(eo.resolve())!=yh||so&&zt(new so)!=bh||Rn&&zt(new Rn)!=_h)&&(zt=function(r){var t=bs(r),e=t==vm?r.constructor:void 0,s=e?Ne(e):"";if(s)switch(s){case ym:return Th;case bm:return vh;case _m:return yh;case Tm:return bh;case Sm:return _h}return t});var xm=Object.prototype,wm=xm.hasOwnProperty;function Cm(r){var t=r.length,e=new r.constructor(t);return t&&typeof r[0]=="string"&&wm.call(r,"index")&&(e.index=r.index,e.input=r.input),e}var _r=Wt.Uint8Array;function io(r){var t=new r.constructor(r.byteLength);return new _r(t).set(new _r(r)),t}function Om(r,t){var e=t?io(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.byteLength)}var km=/\w*$/;function Mm(r){var t=new r.constructor(r.source,km.exec(r));return t.lastIndex=r.lastIndex,t}var Sh=Dt?Dt.prototype:void 0,xh=Sh?Sh.valueOf:void 0;function Dm(r){return xh?Object(xh.call(r)):{}}function Im(r,t){var e=t?io(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.length)}var Em="[object Boolean]",jm="[object Date]",Pm="[object Map]",Am="[object Number]",Lm="[object RegExp]",Fm="[object Set]",Rm="[object String]",Bm="[object Symbol]",Wm="[object ArrayBuffer]",Xm="[object DataView]",zm="[object Float32Array]",Hm="[object Float64Array]",Ym="[object Int8Array]",Gm="[object Int16Array]",Vm="[object Int32Array]",Nm="[object Uint8Array]",Um="[object Uint8ClampedArray]",$m="[object Uint16Array]",qm="[object Uint32Array]";function Km(r,t,e){var s=r.constructor;switch(t){case Wm:return io(r);case Em:case jm:return new s(+r);case Xm:return Om(r,e);case zm:case Hm:case Ym:case Gm:case Vm:case Nm:case Um:case $m:case qm:return Im(r,e);case Pm:return new s;case Am:case Rm:return new s(r);case Lm:return Mm(r);case Fm:return new s;case Bm:return Dm(r)}}function Jm(r){return typeof r.constructor=="function"&&!Hn(r)?cf(ch(r)):{}}var Zm="[object Map]";function Qm(r){return ke(r)&&zt(r)==Zm}var wh=_s&&_s.isMap,t0=wh?Gn(wh):Qm,e0="[object Set]";function s0(r){return ke(r)&&zt(r)==e0}var Ch=_s&&_s.isSet,i0=Ch?Gn(Ch):s0,r0=1,n0=2,o0=4,Oh="[object Arguments]",a0="[object Array]",c0="[object Boolean]",h0="[object Date]",l0="[object Error]",kh="[object Function]",u0="[object GeneratorFunction]",d0="[object Map]",g0="[object Number]",Mh="[object Object]",f0="[object RegExp]",p0="[object Set]",m0="[object String]",v0="[object Symbol]",y0="[object WeakMap]",b0="[object ArrayBuffer]",_0="[object DataView]",T0="[object Float32Array]",S0="[object Float64Array]",x0="[object Int8Array]",w0="[object Int16Array]",C0="[object Int32Array]",O0="[object Uint8Array]",k0="[object Uint8ClampedArray]",M0="[object Uint16Array]",D0="[object Uint32Array]",X={};X[Oh]=X[a0]=X[b0]=X[_0]=X[c0]=X[h0]=X[T0]=X[S0]=X[x0]=X[w0]=X[C0]=X[d0]=X[g0]=X[Mh]=X[f0]=X[p0]=X[m0]=X[v0]=X[O0]=X[k0]=X[M0]=X[D0]=!0,X[l0]=X[kh]=X[y0]=!1;function Tr(r,t,e,s,i,n){var o,a=t&r0,c=t&n0,h=t&o0;if(o!==void 0)return o;if(!Xt(r))return r;var l=qt(r);if(l){if(o=Cm(r),!a)return lf(r,o)}else{var u=zt(r),d=u==kh||u==u0;if(mr(r))return hm(r,a);if(u==Mh||u==Oh||d&&!i){if(o=c||d?{}:Jm(r),!a)return c?pm(r,am(o,r)):gm(r,om(o,r))}else{if(!X[u])return i?r:{};o=Km(r,u,a)}}n||(n=new de);var g=n.get(r);if(g)return g;n.set(r,o),i0(r)?r.forEach(function(m){o.add(Tr(m,t,e,m,r,n))}):t0(r)&&r.forEach(function(m,b){o.set(b,Tr(m,t,e,b,r,n))});var f=h?c?mm:Qn:c?Un:Nn,p=l?void 0:f(r);return yf(p||r,function(m,b){p&&(b=m,m=r[b]),Xn(o,b,Tr(m,t,e,b,r,n))}),o}var I0=1,E0=4;function Sr(r){return Tr(r,I0|E0)}var j0="__lodash_hash_undefined__";function P0(r){return this.__data__.set(r,j0),this}function A0(r){return this.__data__.has(r)}function xr(r){var t=-1,e=r==null?0:r.length;for(this.__data__=new ue;++t<e;)this.add(r[t])}xr.prototype.add=xr.prototype.push=P0,xr.prototype.has=A0;function L0(r,t){for(var e=-1,s=r==null?0:r.length;++e<s;)if(t(r[e],e,r))return!0;return!1}function F0(r,t){return r.has(t)}var R0=1,B0=2;function Dh(r,t,e,s,i,n){var o=e&R0,a=r.length,c=t.length;if(a!=c&&!(o&&c>a))return!1;var h=n.get(r),l=n.get(t);if(h&&l)return h==t&&l==r;var u=-1,d=!0,g=e&B0?new xr:void 0;for(n.set(r,t),n.set(t,r);++u<a;){var f=r[u],p=t[u];if(s)var m=o?s(p,f,u,t,r,n):s(f,p,u,r,t,n);if(m!==void 0){if(m)continue;d=!1;break}if(g){if(!L0(t,function(b,T){if(!F0(g,T)&&(f===b||i(f,b,e,s,n)))return g.push(T)})){d=!1;break}}else if(!(f===p||i(f,p,e,s,n))){d=!1;break}}return n.delete(r),n.delete(t),d}function W0(r){var t=-1,e=Array(r.size);return r.forEach(function(s,i){e[++t]=[i,s]}),e}function X0(r){var t=-1,e=Array(r.size);return r.forEach(function(s){e[++t]=s}),e}var z0=1,H0=2,Y0="[object Boolean]",G0="[object Date]",V0="[object Error]",N0="[object Map]",U0="[object Number]",$0="[object RegExp]",q0="[object Set]",K0="[object String]",J0="[object Symbol]",Z0="[object ArrayBuffer]",Q0="[object DataView]",Ih=Dt?Dt.prototype:void 0,ro=Ih?Ih.valueOf:void 0;function tv(r,t,e,s,i,n,o){switch(e){case Q0:if(r.byteLength!=t.byteLength||r.byteOffset!=t.byteOffset)return!1;r=r.buffer,t=t.buffer;case Z0:return!(r.byteLength!=t.byteLength||!n(new _r(r),new _r(t)));case Y0:case G0:case U0:return Wn(+r,+t);case V0:return r.name==t.name&&r.message==t.message;case $0:case K0:return r==t+"";case N0:var a=W0;case q0:var c=s&z0;if(a||(a=X0),r.size!=t.size&&!c)return!1;var h=o.get(r);if(h)return h==t;s|=H0,o.set(r,t);var l=Dh(a(r),a(t),s,i,n,o);return o.delete(r),l;case J0:if(ro)return ro.call(r)==ro.call(t)}return!1}var ev=1,sv=Object.prototype,iv=sv.hasOwnProperty;function rv(r,t,e,s,i,n){var o=e&ev,a=Qn(r),c=a.length,h=Qn(t),l=h.length;if(c!=l&&!o)return!1;for(var u=c;u--;){var d=a[u];if(!(o?d in t:iv.call(t,d)))return!1}var g=n.get(r),f=n.get(t);if(g&&f)return g==t&&f==r;var p=!0;n.set(r,t),n.set(t,r);for(var m=o;++u<c;){d=a[u];var b=r[d],T=t[d];if(s)var S=o?s(T,b,d,t,r,n):s(b,T,d,r,t,n);if(!(S===void 0?b===T||i(b,T,e,s,n):S)){p=!1;break}m||(m=d=="constructor")}if(p&&!m){var C=r.constructor,O=t.constructor;C!=O&&"constructor"in r&&"constructor"in t&&!(typeof C=="function"&&C instanceof C&&typeof O=="function"&&O instanceof O)&&(p=!1)}return n.delete(r),n.delete(t),p}var nv=1,Eh="[object Arguments]",jh="[object Array]",wr="[object Object]",ov=Object.prototype,Ph=ov.hasOwnProperty;function av(r,t,e,s,i,n){var o=qt(r),a=qt(t),c=o?jh:zt(r),h=a?jh:zt(t);c=c==Eh?wr:c,h=h==Eh?wr:h;var l=c==wr,u=h==wr,d=c==h;if(d&&mr(r)){if(!mr(t))return!1;o=!0,l=!1}if(d&&!l)return n||(n=new de),o||rh(r)?Dh(r,t,e,s,i,n):tv(r,t,c,e,s,i,n);if(!(e&nv)){var g=l&&Ph.call(r,"__wrapped__"),f=u&&Ph.call(t,"__wrapped__");if(g||f){var p=g?r.value():r,m=f?t.value():t;return n||(n=new de),i(p,m,e,s,n)}}return d?(n||(n=new de),rv(r,t,e,s,i,n)):!1}function Ah(r,t,e,s,i){return r===t?!0:r==null||t==null||!ke(r)&&!ke(t)?r!==r&&t!==t:av(r,t,e,s,Ah,i)}function cv(r,t){return r!=null&&t in Object(r)}function hv(r,t,e){t=br(t,r);for(var s=-1,i=t.length,n=!1;++s<i;){var o=qn(t[s]);if(!(n=r!=null&&e(r,o)))break;r=r[o]}return n||++s!=i?n:(i=r==null?0:r.length,!!i&&zn(i)&&Bn(o,i)&&(qt(r)||Yn(r)))}function lv(r,t){return r!=null&&hv(r,t,cv)}var no=function(){return Wt.Date.now()},uv="Expected a function",dv=Math.max,gv=Math.min;function fv(r,t,e){var s,i,n,o,a,c,h=0,l=!1,u=!1,d=!0;if(typeof r!="function")throw new TypeError(uv);t=Gc(t)||0,Xt(e)&&(l=!!e.leading,u="maxWait"in e,n=u?dv(Gc(e.maxWait)||0,t):n,d="trailing"in e?!!e.trailing:d);function g(M){var I=s,D=i;return s=i=void 0,h=M,o=r.apply(D,I),o}function f(M){return h=M,a=setTimeout(b,t),l?g(M):o}function p(M){var I=M-c,D=M-h,F=t-I;return u?gv(F,n-D):F}function m(M){var I=M-c,D=M-h;return c===void 0||I>=t||I<0||u&&D>=n}function b(){var M=no();if(m(M))return T(M);a=setTimeout(b,p(M))}function T(M){return a=void 0,d&&s?g(M):(s=i=void 0,o)}function S(){a!==void 0&&clearTimeout(a),h=0,s=c=i=a=void 0}function C(){return a===void 0?o:T(no())}function O(){var M=no(),I=m(M);if(s=arguments,i=this,c=M,I){if(a===void 0)return f(c);if(u)return clearTimeout(a),a=setTimeout(b,t),g(c)}return a===void 0&&(a=setTimeout(b,t)),o}return O.cancel=S,O.flush=C,O}function pv(r,t){return Ah(r,t)}function mv(r,t,e,s){if(!Xt(r))return r;t=br(t,r);for(var i=-1,n=t.length,o=n-1,a=r;a!=null&&++i<n;){var c=qn(t[i]),h=e;if(c==="__proto__"||c==="constructor"||c==="prototype")return r;if(i!=o){var l=a[c];h=void 0,h===void 0&&(h=Xt(l)?l:Bn(t[i+1])?[]:{})}Xn(a,c,h),a=a[c]}return r}function vv(r,t,e){for(var s=-1,i=t.length,n={};++s<i;){var o=t[s],a=Kp(r,o);e(a,o)&&mv(n,br(o,r),a)}return n}function yv(r,t){return vv(r,t,function(e,s){return lv(r,s)})}var bv=Qp(function(r,t){return r==null?{}:yv(r,t)}),_v="Expected a function";function Tv(r,t,e){var s=!0,i=!0;if(typeof r!="function")throw new TypeError(_v);return Xt(e)&&(s="leading"in e?!!e.leading:s,i="trailing"in e?!!e.trailing:i),fv(r,t,{leading:s,maxWait:t,trailing:i})}const Sv=(r,t)=>{if(r.length!==t.length)return!1;const e=new Set(r.map(i=>i.id)),s=new Set(t.map(i=>i.id));if(e.size!==s.size)return!1;for(const i of e)if(!s.has(i))return!1;return!0},Ts=r=>{const{trackItemIds:t,transitionsMap:e,trackItemsMap:s}=r,i=new Map;Object.values(e).forEach(c=>{var u,d;if(c.kind==="none")return;const{fromId:h,toId:l}=c;i.has(h)||i.set(h,[]),i.has(l)||i.set(l,[]),(u=i.get(h))==null||u.push(c),(d=i.get(l))==null||d.push(c)});const n=[],o=new Set,a=c=>{const h=[];let l=c;for(;l&&!o.has(l);){o.add(l);const u=s[l];h.push(u);const d=Object.values(e).find(g=>g.fromId===l&&g.kind!=="none");if(!d)break;h.push(d),l=d.toId}return h};for(const c of t)if(!o.has(c)&&(!i.has(c)||!Object.values(e).some(h=>h.toId===c&&h.kind!=="none"))){const h=a(c);h.length>0&&n.push(h)}return n.forEach(c=>{c.sort((h,l)=>"display"in h&&"display"in l?h.display.from-l.display.from:0)}),n};function xv(r,t,e,s){const i=Object.keys(s),n={},o=[];return r.forEach(a=>{const c=t.filter(h=>a.items.includes(h.id)).sort((h,l)=>h.left-l.left);for(let h=0;h<c.length-1;h++){const l=c[h];let u=l.left;const d=c[h+1];let g=d.left;if(i.includes(l.id)&&(u=s[l.id].left),i.includes(d.id)&&(g=s[d.id].left),Math.abs(u+l.width-g)<=1){const f=`${l.id}-${d.id}`;if(e.hasOwnProperty(f)){const m=e[f];n[f]=m}else{const m={id:f,duration:1500,fromId:l.id,toId:d.id,kind:"none",trackId:a.id,type:"transition"};n[f]=m}o.push(f)}}}),{newTransitionIds:o,newTransitionsMap:n}}const Me=(r,t)=>{const e=t.findIndex(l=>l.id===r),s=t[e-1],i=t[e+1],n=t.filter(l=>l.type==="transition"),o=n.indexOf(s),c=n.slice(0,o).reduce((l,u)=>l+(u.duration||0),0);let h=0;return s&&!i?h=(s.duration||0)/2:i&&!s?h=(i.duration||0)/2:s&&i&&(h=(i.duration||0)/2+(s.duration||0)/2),{durationDiff:h,offsetTransitions:c}},wv=r=>{const{trackItemIds:t,transitionsMap:e,trackItemsMap:s}=r,i=new Map;Object.values(e).forEach(h=>{var g,f;const{fromId:l,toId:u,kind:d}=h;d!=="none"&&(i.has(l)||i.set(l,[]),i.has(u)||i.set(u,[]),(g=i.get(l))==null||g.push(h),(f=i.get(u))==null||f.push(h))});const n=[],o=new Set,a=h=>{const l=[];let u=h;for(;u&&!o.has(u);){o.add(u);const d=s[u];l.push(d);const g=Object.values(e).find(f=>f.fromId===u&&f.kind!=="none");if(!g)break;l.push(g),u=g.toId}return l},c=Object.values(e).filter(h=>h.kind!=="none");for(const h of t)if(!o.has(h)&&(!i.has(h)||!c.some(l=>l.toId===h))){const l=a(h);l.length>0&&n.push(l)}return n.forEach(h=>{h.sort((l,u)=>"display"in l&&"display"in u?l.display.from-u.display.from:0)}),n};class Cv{addTrackItem(t){const e=xg(t,{tScale:this.tScale,sizesMap:this.sizesMap});this.add(e)}alignItemsToTrack(){this.pauseEventListeners();const t=new Map(this.getObjects("Track").map(i=>[i.id,i])),e=this.getTrackItems(),s=this.getObjects("Transition");this.trackItemIds.forEach(i=>{const n=this.tracks.find(c=>c.items.includes(i));if(!n)return;const o=t.get(n.id),a=this.getTrackItems().find(c=>c.id===i);a&&o&&(a.isMain=o.magnetic,this.trackItemsMap[i].isMain=o.magnetic,a.set({top:o.top}),a.setCoords())}),t.forEach(i=>{i.items=e.filter(n=>n.top===i.top).map(n=>n.id)}),s.forEach(i=>{const n=i.fromId,o=e.find(a=>a.id===n);o&&(i.set({top:o.top}),i.setCoords())}),this.resumeEventListeners()}updateTrackItemsToHistory(){this.pauseEventListeners(),this.trackItemIds.forEach(t=>{const e=this.tracks.find(c=>c.items.includes(t)),s=this.getObjects().find(c=>c.id===(e==null?void 0:e.id)).top,i=this.trackItemsMap[t],n=this.getObjects().find(c=>c.id===t),o=E(i.display.from,this.tScale),a=E(i.display.to-i.display.from,this.tScale,i.playbackRate);if(n.set({left:o,width:a,top:s}),n instanceof bt||n instanceof pt){const c=n.display.to-n.display.from;n.setDuration?n.setDuration(c):n.set({duration:c}),i.trim=n.trim,i.display=n.display}n.setCoords()}),this.requestRenderAll(),this.resumeEventListeners()}deleteTrackItemToHistory(t){this.getObjects().filter(e=>t.includes(e.id)).map(e=>this.remove(e)),this.alignItemsToTrack(),this.requestRenderAll()}uodateTrackItemIdsOrdering(){const t=this.getTrackItems();t.sort((e,s)=>e.top-s.top),this.trackItemIds=t.map(e=>e.id).reverse()}selectTrackItemByIds(t){const e=this.getActiveObjects().map(n=>n.id);if(pv(e,t))return;const i=this.getObjects(...Ec,"Transition").filter(n=>t.includes(n.id));if(!i.length)this.discardActiveObject();else if(i.length===1)this.setActiveObject(i[0]);else{const n=new kt(i);this.setActiveObject(n)}this.requestRenderAll()}synchronizeTrackItemsState(){this.pauseEventListeners();const t=this.getTrackItems(),e={},s=wv({trackItemIds:this.trackItemIds,transitionsMap:this.transitionsMap,trackItemsMap:this.trackItemsMap});t.forEach(i=>{const{id:n,left:o,width:a}=i,c=this.trackItemsMap[n],h=this.transitionGroups.find(l=>l.find(u=>u.id===n))||[];if(h.length===1){const l=W(o,this.tScale),u=W(a,this.tScale,i.playbackRate),d={from:l,to:l+u},g={display:d};(i instanceof bt||i instanceof pt||i instanceof Bt)&&(g.trim=i.trim,g.duration=d.to-d.from),i.display=d,e[n]={...c,...g}}else{const l=h.findIndex(g=>g.id===n),u=h[l-1],d=h[l+1];if(u&&!d){const g=Me(n,h),f=W(o,this.tScale)+u.duration/2+g.offsetTransitions,p=W(a,this.tScale,i.playbackRate)+(u.duration||0)/2,m={from:f,to:f+p},b={display:m};(i instanceof bt||i instanceof pt||i instanceof Bt)&&(b.trim=i.trim),i.display=m,e[n]={...c,...b}}else if(d&&!u){const g=W(o,this.tScale),f=W(a,this.tScale,i.playbackRate),p={from:g,to:g+f+(d.duration||0)/2},m={display:p};(i instanceof bt||i instanceof pt||i instanceof Bt)&&(m.trim=i.trim),i.display=p,e[n]={...c,...m}}else if(u&&d){const g=W(o,this.tScale),f=s.find(O=>O.find(M=>M.id===i.id)),b=(f==null?void 0:f.filter(O=>O.type==="transition").map(O=>this.getObjects().find(M=>M.id===O.id))).filter(O=>O.top===i.top).filter(O=>O.left+O.width<=i.left).reduce((O,M)=>O+(M.duration||0),0),T=W(a,this.tScale,i.playbackRate),S={from:g+b+(u.duration||0)/2,to:g+b+T+(d.duration||0)/2+(u.duration||0)},C={display:S};(i instanceof bt||i instanceof pt||i instanceof Bt)&&(C.trim=i.trim),i.display=S,e[n]={...c,...C}}}}),this.trackItemsMap={...this.trackItemsMap,...e},this.resumeEventListeners()}deleteTrackItemById(t){const e=t,s=this.getObjects().filter(a=>t.includes(a.id)),i=ei(this.tracks,e),n={};Object.keys(this.trackItemsMap).forEach(a=>{e.includes(a)||(n[a]=this.trackItemsMap[a])});const o=this.trackItemIds.filter(a=>!e.includes(a));this.tracks=i,this.trackItemsMap=n,this.trackItemIds=o,this.discardActiveObject(),this.remove(...s),this.renderTracks(),this.alignItemsToTrack()}deleteActiveTrackItem(){const t=this.getActiveObjects();if(!t.length)return!1;const e=t.map(o=>o.id),s=ei(this.tracks,e),i={};Object.keys(this.trackItemsMap).forEach(o=>{e.includes(o)||(i[o]=this.trackItemsMap[o])});const n=this.trackItemIds.filter(o=>!e.includes(o));this.tracks=s,this.trackItemsMap=i,this.trackItemIds=n,this.discardActiveObject(),this.remove(...t),this.setActiveIds([]),this.renderTracks(),this.alignItemsToTrack(),this.updateState({updateHistory:!0,kind:"remove"})}updateTrackItemCoords(){this.trackItemIds.forEach(t=>{const e=this.transitionGroups.find(o=>o.find(a=>a.id===t))||[];if((e==null?void 0:e.length)===1){const o=this.getObjects().find(l=>l.id===t),a=this.trackItemsMap[t],c=E(a.display.from,this.tScale),h=E(a.display.to-a.display.from,this.tScale,a.playbackRate);o.set({left:c,width:h}),o.setCoords();return}const s=e.findIndex(o=>o.id===t),i=e[s-1],n=e[s+1];if(i&&!n){const o=this.getObjects().find(u=>u.id===t),a=this.trackItemsMap[t],c=Me(t,e),h=E(a.display.from-(i.duration||0)/2-c.offsetTransitions,this.tScale),l=E(a.display.to-a.display.from-(i.duration||0)/2,this.tScale,a.playbackRate);o.set({left:h,width:l}),o.setCoords();return}if(n&&!i){const o=this.getObjects().find(l=>l.id===t),a=this.trackItemsMap[t],c=E(a.display.from,this.tScale),h=E(a.display.to-a.display.from-(n.duration||0)/2,this.tScale,a.playbackRate);o.set({left:c,width:h}),o.setCoords();return}if(i&&n){const o=this.getObjects().find(u=>u.id===t),a=this.trackItemsMap[t],c=Me(t,e),h=E(a.display.from-(i.duration||0)/2-c.offsetTransitions,this.tScale),l=E(a.display.to-a.display.from-(n.duration||0)/2-(i.duration||0)/2,this.tScale,a.playbackRate);o.set({left:h,width:l}),o.setCoords();return}})}refreshTrackItemsForTransitions(){const t=this.getActiveObjects().map(h=>h.id);this.pauseEventListeners();const e=this.getObjects("Track"),s=this.getObjects("Video","Image"),i=this.getObjects("Transition"),n=s.concat(i),o=Object.keys(this.positionAfterTransform);e.forEach(h=>{o.forEach(l=>{if(h.items.includes(l)){const u=this.getObjects().find(d=>d.id===l);t.includes(l)||(this.positionAfterTransform[l].left=u.left)}})});const{newTransitionsMap:a}=xv(e,s,this.transitionsMap,this.positionAfterTransform),c=Ts({trackItemIds:this.trackItemIds,transitionsMap:a,trackItemsMap:this.trackItemsMap});s.forEach(h=>{const l=h.id,u=c.find(m=>m.find(b=>b.id===l))||[],d=this.transitionGroups.find(m=>m.find(b=>b.id===l))||[];if(Sv(d,u))return;const g=u.findIndex(m=>m.id===l),f=u[g-1],p=u[g+1];if(f&&!p){const m=Me(l,d),b=Me(l,u),T=E(m.durationDiff-b.durationDiff,this.tScale);h.set({width:h.width+T})}else if(p&&!f){const m=Me(l,d),b=Me(l,u);if(m.durationDiff>0){const T=E(m.durationDiff-b.durationDiff,this.tScale);h.set({width:h.width+T}),u.forEach(S=>{if(S.id!==h.id){const C=n.find(O=>O.id===S.id);C==null||C.set({left:C.left+T}),C==null||C.setCoords()}})}}else if(f&&p)console.warn("invalid spot");else{const m=Me(l,d),b=E(m.durationDiff,this.tScale);h.set({width:h.width+b})}}),this.resumeEventListeners()}getTrackItems(){return this.getObjects(...Ec)}setTrackItemCoords(){this.getTrackItems().forEach(t=>{t.setCoords()})}setActiveTrackItemCoords(){this.getActiveObjects().forEach(e=>e.setCoords())}}const Ss={text:32,image:40,video:40,audio:32,helper:8,main:40,caption:32,template:32},Lh=r=>{switch(r){case"text":return Ss.text;case"image":return Ss.image;case"video":return Ss.video;case"audio":return Ss.audio;case"helperTop":return 1e3;case"helperBottom":return 1e3;case"helperCenter":return 8;case"main":return Ss.main;default:return Ss.text}};class Ov{findOrCreateTrack(t,{trackId:e,trackIndex:s}){if(e){const n=this.tracks.find(o=>o.id===e);if(n)return n.items.push(t.id),e}const i={id:ti(),items:[t.id],type:t.type,accepts:this.acceptsMap[t.type],magnetic:!1,static:!1};return s!==void 0?this.tracks.splice(s,0,i):this.tracks.push(i),this.renderTracks(),i.id}removeTracks(){this.getObjects("Track","Helper").forEach(e=>this.remove(e))}renderTracks(){this.filterEmptyTracks(),this.removeTracks();const t=this.width,e=this.tracks.flatMap(a=>[a,{id:`helper-${a.id}`,type:"helper",items:[],accepts:[]}]).slice(0,-1);let s=-970;const i=w.getClass("Helper")||Ve,n=new i({top:s,selectable:!1,evented:!1,tScale:this.tScale,id:"helper-line-top",width:t,kind:"top",height:1e3,metadata:{}});s+=Lh("helperTop"),this.insertAt(0,n),e.forEach((a,c)=>{if(a.type==="helper"){const h=Lh("helperCenter"),l=new i({id:a.id,top:s,tScale:this.tScale,width:t,height:h,metadata:{order:(c+1)/2},kind:"center"});s+=h,this.insertAt(0,l)}else{const h=this.sizesMap[a.type],l=w.getClass("Track")||Oe,u=new l({id:a.id,top:s,left:0,height:h,width:t,tScale:this.tScale,accepts:this.acceptsMap[a.type]||[],items:a.items,magnetic:a.magnetic,static:a.static});s+=h,this.insertAt(0,u)}});const o=new i({id:"helper-line-bottom",top:s,selectable:!1,evented:!1,tScale:this.tScale,width:t,kind:"bottom",height:1e3,metadata:{}});this.insertAt(0,o)}filterEmptyTracks(){const t=new Set;this.tracks=this.tracks.filter(e=>(e.items.length||e.static)&&!t.has(e.id)?(t.add(e.id),!0):!1)}refreshTrackLayout(){const t=this.bounding.width+this.spacing.right;this.getObjects("Track","Helper").forEach(e=>{e.updateCoords(t),e.setCoords()})}adjustMagneticTrack(){this.pauseEventListeners();const t=this.tracks.filter(e=>e.magnetic);t.length>0&&t.forEach(e=>{const s=e.accepts||[],i=this.getObjects(...s).filter(o=>e.items.includes(o.id)).sort((o,a)=>o.left-a.left);let n=0;i.forEach(o=>{o.left=n,n+=o.width})}),this.resumeEventListeners()}}function Fh(r){const t=this,e=r.target,s=r.transform;if(s.action==="resizing"){const i=t.getObjects().filter(l=>l!==e&&!["Track","Helper","Transition","Placeholder"].includes(l.type)),n=10,o=e.left,a=e.width*e.scaleX,c=o+a;let h=!1;i.forEach(l=>{if(h)return;const u=l.getBoundingRect(),d=u.left,g=u.left+u.width;if(s.corner==="mr"){const f=Math.abs(c-g),p=Math.abs(c-d);if(f<n)if(e instanceof bt||e instanceof pt){const m=g-e.left,b=m-a,T=W(b,e.tScale,e.playbackRate),S=e.trim.to+T;S<=e.duration&&(e.set({width:m,scaleX:1}),e.trim.to=S,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({width:g-e.left,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0;else if(p<n)if(e instanceof bt||e instanceof pt){const m=d-e.left,b=m-a,T=W(b,e.tScale,e.playbackRate),S=e.trim.to+T;S<=e.duration&&(e.set({width:m,scaleX:1}),e.trim.to=S,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({width:d-e.left,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0}else if(s.corner==="ml"){const f=Math.abs(o-d),p=Math.abs(o-g);if(f<n)if(e instanceof bt||e instanceof pt||e instanceof Bt){const m=c-d,b=m-a,T=W(b,e.tScale,e.playbackRate),S=e.trim.from-T;S>=0&&(e.set({left:d,width:m,scaleX:1}),e.trim.from=S,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({left:d,width:c-d,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0;else if(p<n)if(e instanceof bt||e instanceof pt||e instanceof Bt){const m=c-g,b=m-a,T=W(b,e.tScale,e.playbackRate),S=e.trim.from-T;S>=0&&(e.set({left:g,width:m,scaleX:1}),e.trim.from=S,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({left:g,width:c-g,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0}}),h&&(e.setCoords(),t.requestRenderAll())}}function kv(r){r.on("object:resizing",Fh.bind(r))}function Mv(r){r.off("object:resizing",Fh.bind(r))}const oi=100,oo=0,Cr=5,Rh=3,Dv=25,xs={scrollInterval:null};function Bh(r){const t=Dv-Rh,e=(oi-r)/oi;return Rh+t*e}function Iv(r,t){xs.scrollInterval&&clearInterval(xs.scrollInterval);const e=t.target,s=e.getBoundingRect();xs.scrollInterval=setInterval(()=>{const i=r.viewportTransform,n=r.getViewportPoint(t.e);if(n.x>r.width-oi&&e.left+s.width<r.bounding.width){const o=Bh(r.width-n.x);e.set("left",e.left+o),r.setViewportPos(i[4]-o,i[5])}if(n.x<oi&&e.left>0&&i[4]<oi){const o=Bh(n.x);e.set("left",e.left-o),r.setViewportPos(i[4]+o,i[5])}n.y>r.height-oo&&e.top+s.height<r.bounding.height+80&&(e.set("top",e.top+Cr),r.setViewportPos(i[4],i[5]-Cr)),n.y<oo&&e.top>-80&&-i[5]>oo&&(e.set("top",e.top-Cr),r.setViewportPos(i[4],i[5]+Cr)),e.setCoords(),r.requestRenderAll()},16)}function Ev(){xs.scrollInterval&&(clearInterval(xs.scrollInterval),xs.scrollInterval=null)}function Wh(){Ev()}function Xh(r){Iv(this,r)}function jv(r){r.on("mouse:up",Wh),r.on("object:moving",Xh.bind(r))}function Pv(r){r.off("mouse:up",Wh),r.off("object:moving",Xh.bind(r))}function zh(r){const t=r.target,e=r.target.canvas;if(r.action==="resizing"&&t instanceof ce&&e){const s=t.id,i=e.getObjects("Transition").find(n=>n.id===s);if(i&&i instanceof ce){const n=Sr(this.transitionsMap),o={...n,[s]:{...n[s],width:i.width,duration:i.duration}};this.transitionsMap=o,this.updateState()}}}function Av(r){r.on("object:modified",zh)}function Lv(r){r.off("object:modified",zh)}const Hh={canvas:null,enableGuideRedraw:!0,isPointerOverHelperTrack:!1,draggingOverTrack:null,placeholderMovingObjects:[],primaryMovingObjects:[],secondaryMovingObjects:[],objectInitialPositions:{},originTrack:{},trackToItemsMap:{},activeTrackToItemsMap:{},trackTopToIdMap:{},trackTops:[],activeObjects:[],primaryTracks:{},secondaryTracks:{},isDragOver:!1,initialMagneticTrackPoints:[]},ot=()=>Hh,lt=r=>{Object.assign(Hh,r)},Yh=10,Or=(r,t)=>{t.forEach(e=>e.isAlignmentAuxiliary&&r.remove(e))},Gh=(r,t)=>{const e=[],s=[];return t.getObjects().filter(i=>i.visible).forEach(i=>{if(r.find(o=>o.id===i.id)||i.isAlignmentAuxiliary)return;const n=i.getBoundingRect();e.push(qh(n.left,n.width,n.top,n.height)),s.push(qh(n.top,n.height,n.left,n.width))}),{vertical:e.flat(),horizontal:[]}},Vh=(r,t)=>{const e=[],s=[];r.vertical.forEach(a=>{t.vertical.forEach(c=>{const h=Math.abs(a.val-c.guide);h<Yh&&e.push({lineGuide:a.val,diff:h,orientation:"V",snap:c.snap,offset:c.offset,targetDim:{start:a.start,end:a.end}})})}),r.horizontal.forEach(a=>{t.horizontal.forEach(c=>{const h=Math.abs(a.val-c.guide);h<Yh&&s.push({lineGuide:a.val,diff:h,orientation:"H",snap:c.snap,offset:c.offset,targetDim:{start:a.start,end:a.end}})})});const i=[],n=e.sort((a,c)=>a.diff-c.diff)[0],o=s.sort((a,c)=>a.diff-c.diff)[0];return n&&i.push({lineGuide:n.lineGuide,offset:n.offset,orientation:"V",snap:n.snap,targetDim:n.targetDim}),o&&i.push({lineGuide:o.lineGuide,offset:o.offset,orientation:"H",snap:o.snap,targetDim:o.targetDim}),i},Nh=(r,t,e)=>{r.forEach(s=>{const i=Fv(e.getZoom());s.orientation==="H"?e.add(Uh([0,s.lineGuide-i.strokeWidth/2,2e3,s.lineGuide-i.strokeWidth/2],{...i,stroke:e.guideLineColor})):s.orientation==="V"&&e.add(Uh([s.lineGuide-i.strokeWidth/2,0,s.lineGuide-i.strokeWidth/2,2e3],{...i,stroke:e.guideLineColor}))})},Fv=r=>({strokeWidth:2/r}),Uh=(r,t)=>new we(r,{...t,strokeLineCap:"square",excludeFromExport:!0,isAlignmentAuxiliary:!0,selectable:!1,objectCaching:!1}),$h=r=>{const t=r.getBoundingRect();return{vertical:[{guide:Math.round(t.left),offset:Math.round(r.left-t.left),snap:"start"},{guide:Math.round(t.left+t.width),offset:Math.round(r.left-t.left-t.width),snap:"end"}],horizontal:[{guide:Math.round(t.top),offset:Math.round(r.top-t.top),snap:"start"},{guide:Math.round(t.top+t.height),offset:Math.round(r.top-t.top-t.height),snap:"end"}]}},qh=(r,t,e,s)=>[r,r+t].map(n=>({val:n,start:e,end:e+s})),Kh=(r,t)=>{r.remove(...t),t=[]},Jh=r=>{r.forEach(t=>t.setSelected(!1))},Zh=r=>r instanceof Ve,Rv=r=>Object.assign({},{left:16,right:80},r),Bv=["touchstart","touchmove","touchend"],Wv=r=>Bv.includes(r.type)||r.pointerType==="touch";function Qh(r){const t=this;if(!t)return;const s=ot().enableGuideRedraw,i=t.getScenePoint(r.e),n=t.getObjects("Helper","Track"),o=n.find(f=>{const p=f.getBoundingRect();return i.x>=p.left&&i.x<=p.left+p.width&&i.y>=p.top&&i.y<=p.top+p.height});lt({draggingOverTrack:o}),n.forEach(f=>{Zh(f)&&(f===o?f.setSelected(!0):f.setSelected(!1))}),Zh(o)?lt({isPointerOverHelperTrack:!0}):lt({isPointerOverHelperTrack:!1});const a=t.getObjects(),c=r.target,h=c.getBoundingRect();c.setCoords();const l=[c,...t.getActiveObjects(),...t.getObjects("Track","Helper","Transition","Placeholder")],u=Gh(l,t),d=$h(c),g=Vh(u,d);s&&(Or(t,a),g.length&&Nh(g,h,t),lt({enableGuideRedraw:!1}),setTimeout(()=>lt({enableGuideRedraw:!0}),50)),g.forEach(f=>{f.orientation==="V"?c.left=f.lineGuide+f.offset:c.top=f.lineGuide+f.offset})}function tl(r){const t=r.target.canvas;t&&(Or(t,t.getObjects()),Jh(t.getObjects("Helper")),lt({draggingOverTrack:null,isPointerOverHelperTrack:!1}))}function el(r){var a;const t=this,e=t.getObjects(),s=r.target,i=r.transform,n=(a=t._currentTransform)==null?void 0:a.corner,o=s.getBoundingRect();if(i.action==="resizing"){const c=[s,...t.getActiveObjects(),...t.getObjects("Track","Helper","Transition","Placeholder")],h=Gh(c,t),l=h.vertical.filter(g=>{const f=g.val;if(n==="ml")return f<=o.left;if(n==="mr")return f>=o.left+o.width});h.vertical=l;const u=$h(s),d=Vh(h,u);Or(t,e),d.length&&Nh(d,o,t)}}function Xv(r){r.on("object:moving",Qh.bind(r)),r.on("object:modified",tl.bind(r)),r.on("object:resizing",el.bind(r))}function zv(r){r.off("object:moving",Qh.bind(r)),r.off("object:modified",tl.bind(r)),r.off("object:resizing",el.bind(r))}function ao(r,t,e){const s=r.indexOf(t),i=r.indexOf(e);return s===-1||i===-1?null:i-s}function sl(r,t){const e=t.sort((i,n)=>i.tempIndex-n.tempIndex),s=[];for(const i of e)i.tempIndex<0&&s.push(i);s.push(r);for(const i of e)i.tempIndex>=0&&s.push(i);return s}function il(r){const t=ot(),e=t.canvas;lt({activeTrackToItemsMap:{},primaryTracks:{},secondaryTracks:{},trackTops:[],trackToItemsMap:{},activeObjects:[],trackTopToIdMap:{},isDragOver:!1,initialMagneticTrackPoints:[]}),e.trackIdAfterTransform="",e.positionAfterTransform={};const s=e.getActiveObject(),i=s instanceof kt?s.getObjects():[s];lt({activeObjects:i});const n=e.getScenePoint(r.e),o=e.getObjects("Track"),a=e.getActiveObjects().map(u=>u.id);let h=o.filter(u=>{const d=u.items;return a.some(g=>d.includes(g))}).find(u=>{const d=u.getBoundingRect();return n.x>=d.left&&n.x<=d.left+d.width&&n.y>=d.top&&n.y<=d.top+d.height});lt({originTrack:h});const l=e.getObjects("Video","Image","Audio","Text","Element","Template");o.forEach(u=>{const d=l.filter(g=>u.items.includes(g.id));t.trackToItemsMap[u.id]=d,t.trackTopToIdMap[u.top]=u.id,t.trackTops.push(u.top)}),t.trackTops.sort((u,d)=>u-d),i.forEach(u=>{const d=o.find(f=>f.items.includes(u.id));if(!d)return;const g=d.id;t.activeTrackToItemsMap[g]?t.activeTrackToItemsMap[g].push(u):t.activeTrackToItemsMap[g]=[u]}),t.primaryMovingObjects=i.filter(u=>{const d=u.getBoundingRect();return n.y>=d.top&&n.y<=d.top+d.height&&!(u instanceof ce)}),t.primaryMovingObjects.length!==0&&(t.primaryMovingObjects.forEach(u=>{const d=u.getBoundingRect().top,g=t.trackTopToIdMap[d];if(t.primaryTracks[g])t.primaryTracks[g].objects.push(u);else{const f=ao(t.trackTops,h==null?void 0:h.top,d);t.primaryTracks[g]={objects:[u],index:f}}}),t.primaryMovingObjects=t.primaryMovingObjects.sort((u,d)=>u.left-d.left),t.secondaryMovingObjects=i.filter(u=>!t.primaryMovingObjects.includes(u)),t.secondaryMovingObjects.forEach(u=>{const d=u.getBoundingRect().top,g=t.trackTopToIdMap[u.getBoundingRect().top];if(t.secondaryTracks[g])t.secondaryTracks[g].objects.push(u);else{const f=ao(t.trackTops,h.top,d);t.secondaryTracks[g]={objects:[u],index:f}}}),h&&(e.trackOriginBeforeTransform=h.id),s&&(e.positionBeforeTransform={top:s.top,left:s.left}),r.transform.action==="drag"&&(t.placeholderMovingObjects=t.primaryMovingObjects.map(u=>{const d=u.getBoundingRect();t.objectInitialPositions[u.id]={top:d.top,left:d.left};const g=new vs({id:`${u.id}-placeholder`,left:d.left,top:d.top,width:d.width,height:d.height});return g.draggedObject=u,g}),e.add(...t.placeholderMovingObjects)))}function Hv(r){r.on("before:transform",il.bind(r))}function Yv(r){r.off("before:transform",il.bind(r))}const Ls=class Ls extends z{constructor(e){super(e);x(this,"duration");x(this,"fromId");x(this,"toId");x(this,"itemType","none");x(this,"isSelected",!1);Object.assign(this,Ls.ownDefaults),this.id=e.id}static createControls(){return{controls:An()}}static getDefaults(){return{...super.getDefaults(),...Ls.ownDefaults}}updateCoords(){const e=this.canvas;if(!e)return;const s=e.getObjects().find(o=>o.id===this.fromId);if(!s)return;const i=E(this.duration,this.tScale),n=s.left+s.width-i/2;this.set({width:i,left:n})}_render(e){super._render(e),this.drawTextIdentity(e),this.updateSelected(e)}drawTextIdentity(e){const s=new Path2D("M3 5.30359C3 3.93159 4.659 3.24359 5.629 4.21359L11.997 10.5826L10.583 11.9966L5 6.41359V17.5856L10.586 11.9996L10.583 11.9966L11.997 10.5826L12 10.5856L18.371 4.21459C19.341 3.24459 21 3.93159 21 5.30359V18.6956C21 20.0676 19.341 20.7556 18.371 19.7856L12 13.5L13.414 11.9996L19 17.5866V6.41359L13.414 11.9996L13.421 12.0056L12.006 13.4206L12 13.4136L5.629 19.7846C4.659 20.7546 3 20.0676 3 18.6956V5.30359Z");e.save(),e.translate(-12,-12),e.fillStyle="#ffffff",e.fill(s),e.restore()}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=ae,e.strokeStyle=Rt,e.stroke(),e.restore())}};x(Ls,"type","TransitionGuide"),x(Ls,"ownDefaults",{objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:1.5,fill:"rgba(0,0,0, 0.85)",borderOpacityWhenMoving:1,hoverCursor:"default",lockMovementX:!0,lockMovementY:!0,duration:1500,rx:8,ry:8});let ai=Ls;function rl(){const r=ot();Kh(this,r.placeholderMovingObjects)}let ge=!1;function Gv(r){const t=r.target.left;r.target.left=Math.max(t,0)}function nl(r,t){return r.find(s=>{const i=s.getBoundingRect();return t.left<i.left+i.width&&t.left+t.width>i.left&&t.top<i.top+i.height&&t.top+t.height>i.top})}function Vv(r,t){const e=r.left+r.width/2,s=t.left+t.width/2;return e<s?t.left-r.width:(e>s,t.left+t.width)}const Nv=(r,t,e)=>!(e<0||nl(r,{...t.getBoundingRect(),left:e})),ol=r=>{const e=ot().draggingOverTrack;return r instanceof he?e&&e.accepts.includes(r.itemType):e&&e.accepts.includes(r.type)};function Uv(r){ot().isPointerOverHelperTrack?r.opacity=0:r.opacity=1}function $v(r){const t=ot();return{top:t.objectInitialPositions[r.id].top,left:t.objectInitialPositions[r.id].left}}function qv(r){const t=r.getBoundingRect();return{top:ot().draggingOverTrack.top,left:t.left}}function Kv(r,t,e){const s=Vv(r,t),i=Nv(e,r,s),n=ot();return!i||n.activeObjects.length!==1?{left:n.objectInitialPositions[r.id].left,top:n.objectInitialPositions[r.id].top}:{left:s,top:t.top}}const Jv=(r,t)=>{r.forEach((e,s)=>{e.set({left:t[s]})})},al=Tv(r=>{const t=r.target.canvas;Gv(r);const e=ot(),s=e.draggingOverTrack;if(!s){e.placeholderMovingObjects.forEach(a=>{a.visible=!1});return}const i=e.placeholderMovingObjects.map(a=>a.draggedObject),n=(e.trackToItemsMap[s.id]||[]).filter(a=>!i.includes(a)),o=ol(e.primaryMovingObjects[0]);if(s.magnetic&&o){if(ge===!1?(ge=s.id,e.initialMagneticTrackPoints=[]):typeof ge=="string"&&ge!==s.id&&(ge=s.id,e.initialMagneticTrackPoints=[]),e.initialMagneticTrackPoints.length===0){ge=s.id;const c=[];s.items.forEach(p=>{const m=t.getObjects().find(b=>b.id===p);m&&c.push(m)});const h=e.activeObjects.map(p=>p.id),u=c.filter(p=>!h.includes(p.id)).sort((p,m)=>p.left-m.left);let d=0;const g=[];u.forEach(p=>{p.set({left:d}),d+=p.width,g.push(p.left)});const f=u[u.length-1];g.push(((f==null?void 0:f.left)||0)+((f==null?void 0:f.width)||0)),e.initialMagneticTrackPoints=g}let a=0;for(const[c,h]of e.initialMagneticTrackPoints.entries()){const l=h,u=e.initialMagneticTrackPoints[c+1],d=e.initialMagneticTrackPoints[c-1],g=u-l,f=l-d;if(!u)a=l;else if(l<=r.pointer.x&&l+g/2>=r.pointer.x){a=l;break}else if(l-f/2<=r.pointer.x&&r.pointer.x<=l){a=l;break}}e.placeholderMovingObjects.forEach(c=>{c.opacity=1,c.left=a,c.top=s.top,a+=c.width}),e.placeholderMovingObjects.forEach(c=>{const h=c.draggedObject;t.positionAfterTransform[h.id]={top:c.top,left:c.left}}),t.trackIdAfterTransform=e.trackTopToIdMap[s.top]}else{if(typeof ge=="string"&&e.initialMagneticTrackPoints.length>0){const c=[];t.getObjects().find(g=>g.id===ge).items.forEach(g=>{const f=t.getObjects().find(p=>p.id===g);f&&c.push(f)});const l=e.activeObjects.map(g=>g.id),d=c.filter(g=>!l.includes(g.id)).sort((g,f)=>g.left-f.left);e.initialMagneticTrackPoints.length>d.length&&Jv(d,e.initialMagneticTrackPoints),ge=!1}const a=n.find(c=>nl(i,c.getBoundingRect()));e.placeholderMovingObjects.forEach(c=>{const h=c.draggedObject;if(h instanceof ai){c.visible=!1;return}h.setCoords(),Uv(c);let l=Qv(h,n,a,e.placeholderMovingObjects.length>1);if(h instanceof he&&l.isInvalidDrop&&e.draggingOverTrack instanceof Oe){c.opacity=0;const u=r.pointer,d=[...t.viewportTransform],g=u.y-d[5];Zv(t,g)}else t.trackIdAfterTransform=e.trackTopToIdMap[l.top],t.positionAfterTransform[h.id]={top:l.top,left:l.left},c.left=l.left,c.top=l.top})}});function Zv(r,t){r.getObjects("Helper").reduce((i,n)=>Math.abs(n.top-t)<Math.abs(i.top-t)?n:i).setSelected(!0)}const Qv=(r,t,e,s)=>{const i=ol(r);return!i&&r instanceof he?{top:0,left:0,isInvalidDrop:!0}:!i||s&&e?$v(r):e?r instanceof he?{top:0,left:0,isInvalidDrop:!0}:Kv(r,e,t):qv(r)};function ty(r){r.on("mouse:up",rl.bind(r)),r.on("object:moving",al)}function ey(r){r.off("mouse:up",rl.bind(r)),r.off("object:moving",al)}const sy=r=>{ot().canvas.fire("track:create",r)},iy=r=>{ot().canvas.fire("track-items:moved",r)},cl=r=>{var a,c,h;const t=(a=r.target)==null?void 0:a.canvas;if(!t)return;const e=ot(),s=t.getActiveObject();if(!s||!t.positionBeforeTransform)return;const i=t.getScenePoint(r.e),o=t.getObjects("Track","Helper").find(l=>{const u=l.getBoundingRect();return i.x>=u.left&&i.x<=u.left+u.width&&i.y>=u.top&&i.y<=u.top+u.height});if(r.action==="resizing"){const l=(e.trackToItemsMap[(c=e.originTrack)==null?void 0:c.id]||[]).filter(d=>d!==s);s.setCoords();const u=hl(l,s.getBoundingRect());return t.fire("track-items:resized",{trackId:(h=e.originTrack)==null?void 0:h.id,trackItemIds:[s.id],isOverlapped:!!u}),!1}if(!o)return s==null||s.set(t.positionBeforeTransform),s==null||s.setCoords(),!1;if(o instanceof Ve){let l;switch(o.kind){case"top":l=0;break;case"center":l=o.metadata.order||0;break;case"bottom":l=-1;break;default:return}const u={isSecondaryOverlapped:!1,secondaryTracks:e.secondaryTracks,primaryTracks:e.primaryTracks,primaryPositions:{trackIndex:l,trackId:t.trackIdAfterTransform,positions:t.positionAfterTransform}};sy(u)}else if(o instanceof Oe){const u={isSecondaryOverlapped:ny(),secondaryTracks:e.secondaryTracks,primaryTracks:e.primaryTracks,primaryPositions:{trackId:t.trackIdAfterTransform,positions:t.positionAfterTransform}};iy(u)}};function ry(){const r=ot(),t=r.canvas,[e]=r.primaryMovingObjects,s=e.id,i=t.positionAfterTransform[s],n=e.getBoundingRect().top,o=i.top-n,a={};return r.secondaryMovingObjects.forEach(c=>{const h=c.getBoundingRect().top+o,l=r.trackTopToIdMap[h],u=ao(r.trackTops,r.originTrack.top,h);a[l]?a[l].objects.push(c):a[l]={objects:[c],index:u}}),a}function ny(){const r=ry(),t=ot();return Object.keys(r).some(e=>{const s=t.trackToItemsMap[e],i=r[e].objects;return!s||!s.length?!0:s.filter(n=>!i.includes(n)).some(n=>hl(i,n.getBoundingRect()))})}function hl(r,t){return r.find(s=>{const i=s.getBoundingRect();return t.left<i.left+i.width&&t.left+t.width>i.left&&t.top<i.top+i.height&&t.top+t.height>i.top})}const oy=r=>{r.on("object:modified",cl)},ay=r=>{r.off("object:modified",cl)},co="drag",ll=`${co}:start`,ho=`${co}:end`,lo="timeline",ul=`${lo}:boundingChanged`,dl=`${lo}:seek`,cy="add:audio",hy="add:video",ly="add:image",uy="add:text",dy=["transition","image","video","audio","caption","text"];let rt,ci,ws=[];function gy(r,t){let e=1/0,s=null;const i=new _(r.x,r.y);return t.forEach(n=>{const o=Math.sqrt(Math.pow(n.left-i.x,2)+Math.pow(n.top-i.y,2));o<e&&(e=o,s=n)}),s}const fy=({width:r,height:t,id:e,left:s,top:i,type:n,duration:o})=>{if(n==="transition")return new ai({top:0,left:0,height:48,width:48,id:"TransitionGuide"});const a=w.getClass("PreviewTrackItem")||he;return new a({top:i,left:s,height:t,width:r,id:e,type:n,duration:o})};function gl(r){var g;const t=(g=r.e.dataTransfer)==null?void 0:g.types[0];if(!t)return;const e=JSON.parse(t),s=e.type;if(!dy.includes(s))return;const i=e.duration||5e3,n=this;n.discardActiveObject();const o=E(i,this.tScale),a=this.sizesMap[s];rt=fy({width:o,height:a,id:"TransitionGuide",left:0,top:0,type:s,duration:i}),rt.visible=!1,s==="transition"&&(ws=n.getObjects("Transition"),ws.forEach(f=>{f.visible=!0}));const c=ot();n.trackIdAfterTransform="",n.positionAfterTransform={};const h=rt,l=[rt];lt({activeTrackToItemsMap:{},primaryTracks:{},secondaryTracks:{},trackTops:[],trackToItemsMap:{},activeObjects:[],trackTopToIdMap:{},isDragOver:!1}),lt({activeObjects:l});const u=n.getObjects("Track"),d=n.getTrackItems();u.forEach(f=>{const p=d.filter(m=>f.items.includes(m.id));c.trackToItemsMap[f.id]=p,c.trackTopToIdMap[f.top]=f.id,c.trackTops.push(f.top)}),c.trackTops.sort((f,p)=>f-p),c.primaryMovingObjects=l,c.primaryMovingObjects=c.primaryMovingObjects.sort((f,p)=>f.left-p.left),h&&(n.positionBeforeTransform={top:h.top,left:h.left}),c.placeholderMovingObjects=c.primaryMovingObjects.map(f=>{const p=f.getBoundingRect();c.objectInitialPositions[f.id]={top:p.top,left:p.left};const m=new vs({id:`${f.id}-placeholder`,left:p.left,top:p.top,width:p.width,height:p.height});return m.visible=!1,m.draggedObject=f,m}),n.add(...c.placeholderMovingObjects),n.add(rt),Z.dispatch(ll)}const fl=r=>{const t=ot();Kh(r,t.placeholderMovingObjects),r&&(Or(r,r.getObjects()),Jh(r.getObjects("Helper")))};function pl(){if(fl(this),lt({draggingOverTrack:null,isPointerOverHelperTrack:!1}),!rt)return;Z.dispatch(ho);const r=this;ws.forEach(t=>{t.strokeDashArray=[],t.setSelected(!1),t.kind==="none"&&(t.visible=!1)}),r.getObjects("Helper","Track").forEach(t=>{t.setSelected&&t.setSelected(!1)}),r.remove(rt)}function ml(r){const t=ot(),e=t.placeholderMovingObjects[0];if(e.visible||(rt.visible=!0,e.visible=!0),t.activeObjects[0]instanceof ai&&(e.visible=!1),!rt)return!1;r.e.preventDefault();const s=this,i=s.getViewportPoint(r.e),n=[...this.viewportTransform];rt.set({left:i.x-16-n[4],top:i.y-n[5]-rt.height/2});const o=gy(i,ws);o&&(ci=o,o.strokeDashArray=[5,1],o.setSelected(!0)),ws.forEach(c=>{c!==o&&c.setSelected(!1)}),lt({isDragOver:!0}),rt.setCoords();const a={target:rt,action:"drag",originX:"center",originY:"center",offsetX:i.x-rt.left,offsetY:i.y-rt.top,scaleX:rt.scaleX,scaleY:rt.scaleY};s.fire("object:moving",{target:rt,e:r.e,pointer:i,transform:a}),s.requestRenderAll()}function vl(r){var o;const t=this;fl(t);const e=ot(),s=e.draggingOverTrack;lt({draggingOverTrack:null,isPointerOverHelperTrack:!1});const i=(o=r.e.dataTransfer)==null?void 0:o.types[0],n=JSON.parse(r.e.dataTransfer.getData(i));if(n.type!=="transition"){const a=e.activeObjects[0],c=W(a.left,t.tScale);if(s instanceof Oe)if(e.placeholderMovingObjects[0].opacity!==0){const l=uo(s,this.getObjects("Track"));if(s.magnetic){const u=e.initialMagneticTrackPoints[e.initialMagneticTrackPoints.length-1],d=W(u,t.tScale);kr(n,l,d)}else kr(n,l,c)}else{const l=r.viewportPoint,u=[...t.viewportTransform],d=l.y-u[5],f=t.getObjects("Helper").reduce((m,b)=>Math.abs(b.top-d)<Math.abs(m.top-d)?b:m),p=uo(f,this.getObjects("Track"));kr(n,p,c,!0)}else{const h=uo(s,this.getObjects("Track"));kr(n,h,c,!0)}this.remove(a),this.requestRenderAll();return}if(rt){if(ci){const a=ci.id,c=bv(n,["kind","direction"]);Object.keys(c).forEach(T=>{T==="kind"?ci.kind=c[T]:ci[T]=c[T]});const h=Sr(this.trackItemIds),l=Sr(this.transitionsMap),u=Sr(this.trackItemsMap);l[a]={...l[a],...c};const d=Ts({trackItemIds:h,transitionsMap:l,trackItemsMap:u}),f=l[a].fromId,p=d.find(T=>T.find(S=>S.id===f))||[],m=py(p),b=my(this.trackItemsMap,m);this.trackItemsMap=b,this.transitionsMap[a]={...this.transitionsMap[a],...c},this.transitionGroups=Ts({trackItemIds:this.trackItemIds,transitionsMap:this.transitionsMap,trackItemsMap:this.trackItemsMap}),this.updateTrackItemCoords(),this.adjustMagneticTrack(),this.calcBounding(),this.updateTransitions(),this.refreshTrackLayout(),this.updateState({kind:"add:transition",updateHistory:!0})}ws.forEach(a=>{a.strokeDashArray=[],a.setSelected(!1),a.kind==="none"&&(a.visible=!1)}),t.remove(rt),t.requestRenderAll(),Z.dispatch(ho)}}const py=r=>{const[t]=r,e=r.filter(i=>i.type!=="transition");let s=t.display.from;return e.map(i=>{const n=i.display.to-i.display.from,o={from:s,to:s+n};return s=o.to,{...i,display:o}})},my=(r,t)=>{let e=r;return t.forEach(s=>{e[s.id]=s}),e},uo=(r,t)=>{const e=t.sort((o,a)=>o.top-a.top);if(e.length===0)return 0;const s=e[e.length-1];if(s.top+s.height<=r.top)return e.length;const i=r.top;return e.reduce((o,a,c)=>{const h=Math.abs(a.top-i),l=Math.abs(e[o].top-i);return h<l?c:o},0)},kr=(r,t,e,s)=>{r.type==="image"?Z.dispatch(ly,{payload:{...r,id:fs(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}}):r.type==="video"?Z.dispatch(hy,{payload:{...r,id:fs(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}}):r.type==="audio"?Z.dispatch(cy,{payload:{...r,id:fs(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}}):r.type==="text"&&Z.dispatch(uy,{payload:{...r,id:fs(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}})};function vy(r){r.on("dragover",ml),r.on("dragenter",gl),r.on("dragleave",pl),r.on("drop",vl)}function yy(r){r.off("dragover",ml),r.off("dragenter",gl),r.off("dragleave",pl),r.off("drop",vl)}function yl(r){const t=this.height<this.bounding.height;if(!(this.width<this.bounding.width)&&!t)return;const s=this.viewportTransform;let i=s[4],n=s[5];const o=2;r.e.shiftKey?i=i-r.e.deltaY*o:(t&&(n=n-r.e.deltaY*o),i=i-r.e.deltaX*o),this.setViewportPos(i,n)}function bl(){const r=this,t=r.getActiveObject(),s=r.getActiveObjects().map(i=>i.id);t instanceof kt?(t.borderColor="rgba(0, 216, 214,0.75)",t.hasControls=!1,t.hoverCursor="default",t.borderScaleFactor=1,t.padding=0,t.getObjects().forEach(i=>{i.setSelected(!0)})):t==null||t.setSelected(!0),this.setActiveIds(s)}function _l(r){const t=this,e=t.getActiveObject();e instanceof kt&&(e.borderColor="transparent",e.hasControls=!1,e.hoverCursor="default"),r.selected.forEach(n=>{n.setSelected(!0)}),r.deselected.forEach(n=>{n.setSelected(!1)});const i=t.getActiveObjects().map(n=>n.id);this.setActiveIds(i)}function Tl(r){r.deselected.forEach(t=>{t.setSelected(!1)})}const by=r=>{r.on("selection:created",bl),r.on("selection:updated",_l),r.on("selection:cleared",Tl),r.on("mouse:wheel",yl)},_y=r=>{r.off("mouse:wheel",yl),r.off("selection:created",bl),r.off("selection:updated",_l),r.off("selection:cleared",Tl)},Sl=()=>{var g;const r=ot(),t=r.draggingOverTrack;if(!t)return;const e=r.isPointerOverHelperTrack,s=new Set(r.activeObjects.map(f=>f.id)),i=t.magnetic,n=i?t.id:"main",o=r.trackToItemsMap[n];if(!o)return;const a=o.sort((f,p)=>f.left-p.left),c=r.placeholderMovingObjects,h=((g=c[0])==null?void 0:g.top)||0,l=c.reduce((f,p)=>f+p.width,0),u=Math.min(...c.map(f=>f.left));let d=0;if(a.forEach(f=>{s.has(f.id)||f.top===h&&(i&&u===d&&(d+=l),f.left=d,d+=f.width)}),!i){const f=r.trackToItemsMap.main;if(f&&f.length===0)return;const p=f.sort((b,T)=>b.left-T.left);let m=0;p.forEach(b=>{s.has(b.id)||(h===b.top&&u===m&&!e&&(m+=l),b.left=m,m+=b.width)})}};function Ty(r){r.on("object:moving",Sl)}function Sy(r){r.off("object:moving",Sl)}const xy=r=>{lt({canvas:r}),jv(r),kv(r),Av(r),Xv(r),Hv(r),ty(r),oy(r),vy(r),by(r),Ty(r)},wy=r=>{lt({canvas:null}),Pv(r),Mv(r),Lv(r),zv(r),Yv(r),ey(r),ay(r),yy(r),_y(r),Sy(r)};class Cy{removeTransitions(){const t=this.getObjects("Transition");this.remove(...t)}renderTransitions(){this.removeTransitions(),this.transitionIds.forEach(t=>{const e=this.transitionsMap[t],s=e.fromId,i=e.toId,n=this.getObjects(),o=n.find(d=>d.id===s),a=n.find(d=>d.id===i);if(!o||!a)return;const c=E(e.duration,this.tScale),h=o.left+o.width-c/2,l=o.height,u=new ce({id:e.id,left:h,top:o.top,height:l,width:c,tScale:this.tScale,duration:e.duration,fromId:o.id,toId:a.id,kind:e.kind});e.kind==="none"&&(u.visible=!1),u&&this.add(u)})}updateTrackTransitionsItemCoords(){this.pauseEventListeners(),this.getObjects("Transition").forEach(e=>{e.tScale=this.tScale,e.updateCoords(),e.setCoords()}),this.resumeEventListeners()}alignTransitionsToTrack(){this.transitionIds.forEach(t=>{const e=this.getObjects("Transition").find(s=>s.id===t);if(e instanceof ce){const s=this.getObjects().find(o=>o.id===e.fromId);if(!s)return;const i=E(e.duration,this.tScale),n=s.left+s.width-i/2;e.set({left:n,top:s.top}),e.setCoords()}})}updateTransitions(t=!0){t&&this.pauseEventListeners();const e=this.getObjects("Track"),s=this.getObjects("Video","Image");this.removeTransitions();const i={},n=[];e.forEach(a=>{const c=s.filter(h=>a.items.includes(h.id)).sort((h,l)=>h.left-l.left);for(let h=0;h<c.length-1;h++){const l=c[h],u=c[h+1];if(Math.abs(l.left+l.width-u.left)<=1){const d=`${l.id}-${u.id}`;if(this.transitionIds.includes(d)){const f=this.transitionsMap[d];i[d]=f}else{const f={id:d,duration:1500,fromId:l.id,toId:u.id,kind:"none",trackId:a.id,type:"transition"};i[d]=f}n.push(d)}}}),this.transitionIds=n,this.transitionsMap=i,this.renderTransitions();const o=this.getObjects("Transition");this.updateCachingActiveObjects(o),this.transitionGroups=Ts({trackItemIds:this.trackItemIds,transitionsMap:this.transitionsMap,trackItemsMap:this.trackItemsMap}),t&&this.resumeEventListeners()}}function xl(r){const{secondaryTracks:t,primaryTracks:e,primaryPositions:s}=r,{positions:i,trackIndex:n}=s,o=n===-1?this.tracks.length:n,[a]=Object.keys(e),c=this.tracks.find(p=>p.id===a),h=e[a],l={id:fs(),items:h.objects.map(p=>p.id),type:c.type,accepts:c.accepts},u=Jn(Object.keys(t).map(p=>t[p].objects.map(m=>m.id)));let d=ei(this.tracks,[...Object.keys(i),...u]);const g=[];Object.keys(t).forEach(p=>{const{objects:m,index:b}=t[p],T=this.tracks.find(O=>O.id===p),S=m.map(O=>O.id).filter(O=>!this.transitionIds.includes(O)),C={id:ti(),items:S,type:T.type,accepts:T.accepts,tempIndex:b};g.push(C)});const f=sl(l,g);f.length&&d.splice(o,0,...f),this.tracks=d,this.renderTracks(),this.refreshTrackLayout(),this.alignItemsToTrack(),this.uodateTrackItemIdsOrdering(),this.refreshTrackItemsForTransitions(),this.adjustMagneticTrack(),this.updateTransitions(!0),this.updateState({updateHistory:!0,kind:"update"})}function wl(r){const{isSecondaryOverlapped:t,secondaryTracks:e,primaryTracks:s,primaryPositions:i}=r,{trackId:n,positions:o}=i,a=this.tracks.find(f=>f.id===n),c=this.tracks.findIndex(f=>f.id===n),h=Jn(Object.keys(e).map(f=>e[f].objects.map(p=>p.id)));let l=ei(this.tracks,[...Object.keys(o),...h]);Object.keys(s).forEach(f=>{this.pauseEventListeners();const{objects:p}=s[f];p.forEach(T=>{if(T.isMain&&(a!=null&&a.magnetic))return;const S=o[T.id];T.left=S==null?void 0:S.left}),this.resumeEventListeners();const m=i.trackId,b=l.find(T=>T.id===m);b==null||b.items.push(...Object.keys(o)),this.tracks=l});const u=this.tracks[c],d=[];Object.keys(e).forEach(f=>{const{objects:p,index:m}=e[f],b=p.filter(C=>C.type!=="transition").map(C=>C.id),[T]=b,S=this.trackItemsMap[T];if(t&&S){const C={id:ti(),items:b,type:S.type,accepts:this.acceptsMap[S.type],tempIndex:m};d.push(C)}else{const C=l[c+m];C==null||C.items.push(...b),this.tracks=l}});const g=sl(u,d);g.length&&l.splice(c,1,...g),this.tracks=l,this.renderTracks(),this.alignItemsToTrack(),this.uodateTrackItemIdsOrdering(),this.refreshTrackItemsForTransitions(),this.adjustMagneticTrack(),this.updateTransitions(!0),this.updateState({updateHistory:!0,kind:"update"})}function Cl({trackItemIds:r,isOverlapped:t}){const[e]=r;if(!e)return;if(!this.getObjects("Transition").find(i=>i.id===e)){const i=this.tracks.find(n=>n.items.includes(e));if(t){const n=ei(this.tracks,r),o={id:ti(),items:[e],type:i.type,accepts:i.accepts},a=this.tracks.findIndex(c=>c.id===i.id);n.splice(a,0,o),this.tracks=n}}this.renderTracks(),this.alignItemsToTrack(),this.refreshTrackItemsForTransitions(),this.adjustMagneticTrack(),this.updateTransitions(!0),this.uodateTrackItemIdsOrdering(),this.updateState({updateHistory:!0,kind:"update"})}let go={x:0,y:0};function Oy(r){go=r.scenePoint}function Ol(r){const t=r.scenePoint;if((go.x===t.x||go.y===t.y)&&!r.target){const s=this.getElement().getBoundingClientRect(),i=this.viewportTransform,n=r.e.clientX-s.left-i[4],o=W(n,this.scale.zoom);Z.dispatch(dl,{payload:{time:o}})}}const ky=r=>{r.on("track:create",xl.bind(r)),r.on("track-items:resized",Cl.bind(r)),r.on("track-items:moved",wl.bind(r)),r.on("mouse:up",Ol.bind(r)),r.on("mouse:down",Oy.bind(r))};function My(r){r.off("track:create",xl.bind(r)),r.off("track-items:resized",Cl.bind(r)),r.off("track-items:moved",wl.bind(r)),r.off("mouse:up",Ol.bind(r))}function Dy(r,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(r.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),r}const kl={video:["*"],image:["*"],audio:["*"],text:["*"],caption:["*"],template:["*"]},Ml={video:42,image:42,audio:42,text:42,caption:42,template:42},Iy=["video","image","audio","text","caption","template"],Ey=(r={})=>{const t=Object.assign({},kl,r),e={};return Object.keys(t).forEach(s=>{const i=t[s];e[s]=i.includes("*")?Iy:i}),e},jy=(r={})=>{const t=Object.assign({},Ml,r),e={};return r?(Object.keys(t).forEach(s=>{const i=t[s];e[s]=i}),e):t};let Dl,Il,El,jl,Pl,Al,Ll,Fl;const Py=r=>{Dl=r.state.subscribeToActiveIds(({activeIds:t})=>{const e=r.activeIds;if(t.length===1&&e.length===1){const s=t[0],i=e[0],o=r.state.getState().structure;let a="";if(o.forEach(c=>{c.id===i&&c.items.includes(s)&&(a=c.id)}),a!=="")return;r.selectTrackItemByIds([s])}else r.selectTrackItemByIds(t)}),Fl=r.state.subscribeToTracks(({tracks:t,changedTracks:e})=>{e.length&&(r.tracks=t,r.renderTracks(),r.refreshTrackLayout())}),Ll=r.state.subscribeToUpdateAnimations(({trackItemsMap:t,changedAnimationIds:e})=>{if(e!=null&&e.length){const s=r.getTrackItems();r.trackItemsMap=t,s.forEach(i=>{if(e.includes(i.id)){const n=t[i.id].animations;n&&i.set({animations:n})}})}}),Al=r.state.subscribeToUpdateTrackItemTiming(({trackItemsMap:t,changedTrimIds:e,changedDisplayIds:s})=>{if(e&&r.getTrackItems().forEach(n=>{if(e.includes(n.id)){const o=t[n.id].trim;o&&n.set({trim:{from:o.from,to:o.to}})}}),s){const i=r.getTrackItems();r.pauseEventListeners(),i.forEach(n=>{if(s.includes(n.id)){const o=t[n.id].display;o&&n.set({display:o})}}),r.resumeEventListeners()}r.requestRenderAll()}),Pl=r.state.subscribeToScale(t=>{r.setScale(t.scale)}),jl=r.state.subscribeToUpdateItemDetails(t=>{const e=r.getTrackItems();if(e.length===0)return;const s=r.state.getState(),i=t.trackItemDetailsMap,n=s.trackItemsMap;e.forEach(o=>{const a=i[o.id];if(a)if(o instanceof bt||o instanceof ps||o instanceof pt){if(a.type==="video"||a.type==="image"||a.type==="audio"){const c=n[o.id];if(o.src!==a.details.src&&o.setSrc&&o.setSrc(a.details.src),a.type==="video"||a.type==="audio"){const l=c.display.to-c.display.from,u=E(l,r.scale.zoom,c.playbackRate);o.set({duration:c.duration,display:c.display,trim:c.trim,width:u}),o.setCoords()}}}else(o instanceof ms||o instanceof ys)&&(a.type==="text"||a.type==="caption")&&o.set({text:a.details.text})}),r.requestRenderAll()}),El=r.state.subscribeToHistory(t=>{r.tracks=t.tracks,r.trackItemsMap=t.trackItemsMap,r.trackItemIds=t.trackItemIds,r.trackItemDetailsMap=t.trackItemDetailsMap,r.transitionIds=t.transitionIds,r.transitionsMap=t.transitionsMap,r.transitionGroups=Ts({trackItemIds:r.trackItemIds,transitionsMap:r.transitionsMap,trackItemsMap:r.trackItemsMap}),r.renderTracks(),r.refreshTrackLayout(),r.updateTrackItemCoords(),r.alignItemsToTrack(),r.alignTransitionsToTrack(),r.adjustMagneticTrack(),r.updateTransitions(),r.calcBounding(),r.duration=En(r.trackItemsMap)}),Il=r.state.subscribeToAddOrRemoveItems(()=>{const t=r.getTrackItems().map(n=>n.id),e=r.state.getState(),s=e.trackItemIds,i=[];t.forEach(n=>{s.includes(n)||i.push(n)}),r.deleteTrackItemById(i),r.tracks=e.tracks,r.trackItemsMap=e.trackItemsMap,r.trackItemDetailsMap=e.trackItemDetailsMap,r.transitionIds=e.transitionIds,r.transitionsMap=e.transitionsMap,s.forEach(n=>{if(!t.includes(n)){const a={...e.trackItemsMap[n],details:{...e.trackItemDetailsMap[n].details}};r.addTrackItem(a)}}),r.trackItemIds=e.trackItemIds,r.activeIds=e.activeIds,r.transitionGroups=Ts({trackItemIds:r.trackItemIds,transitionsMap:r.transitionsMap,trackItemsMap:r.trackItemsMap}),r.renderTracks(),r.alignItemsToTrack(),r.updateTrackItemCoords(),r.calcBounding(),r.updateTransitions(),r.refreshTrackLayout(),r.selectTrackItemByIds(e.activeIds)})},Ay=r=>{Dl.unsubscribe(),Il.unsubscribe(),El.unsubscribe(),jl.unsubscribe(),Pl.unsubscribe(),Al.unsubscribe(),Ll.unsubscribe(),Fl.unsubscribe()},Rl=(r,t)=>{let e=!1;const s=[];return t.forEach(i=>{i.containsPoint(r)&&(s.push(i),e=!0)}),{isOverObject:e,overObjects:s}};function Ly(r){return JSON.parse(JSON.stringify(r))}class Bl extends Tn{constructor(e,s){var i;super(e,s);x(this,"acceptsMap");x(this,"sizesMap",{});x(this,"tracks",[]);x(this,"trackItemsMap",{});x(this,"trackItemIds",[]);x(this,"transitionIds",[]);x(this,"transitionsMap",{});x(this,"trackItemDetailsMap",{});x(this,"scale");x(this,"duration");x(this,"bounding");x(this,"onScroll");x(this,"onResizeCanvas");x(this,"tScale");x(this,"state");x(this,"activeIds",[]);x(this,"spacing");x(this,"guideLineColor");x(this,"transitionGroups",[]);this.bounding=s.bounding||{width:s.width||0,height:s.height||0},this.tScale=((i=s.scale)==null?void 0:i.zoom)||1,this.state=s.state,this.onScroll=s.onScroll,this.onResizeCanvas=s.onResizeCanvas,this.acceptsMap=Ey(s.acceptsMap),this.sizesMap=jy(s.sizesMap),this.spacing=Rv(s.spacing),this.positionAfterTransform={},this.initializeCanvasDefaults(),this.scale=s.scale,this.duration=s.duration,this.guideLineColor=s.guideLineColor||Rt,this.initEventListeners()}static registerItems(e){Object.keys(e).forEach(s=>{w.setClass(e[s],s)})}initializeCanvasDefaults(){const e=this.viewportTransform;e[4]=this.spacing.left,Object.assign(ct.ownDefaults,{borderColor:"transparent",cornerColor:"white",cornerStrokeColor:"transparent",strokeWidth:0,borderOpacityWhenMoving:1,borderScaleFactor:1,cornerSize:8,cornerStyle:"rect",centeredScaling:!1,centeredRotation:!0,transparentCorners:!1})}__onMouseDown(e){const s=this.getScenePoint(e),i=this._activeObject,n=this.getActiveObjects();if(n.length===0){super.__onMouseDown(e);return}const{isOverObject:o}=Rl(s,n);if(i&&(i==null?void 0:i.findControl(this.getViewportPoint(e),Wv(e)))){super.__onMouseDown(e);return}const{isOverObject:a,overObjects:c}=Rl(s,this.getTrackItems());a?o?super.__onMouseDown(e):(this.setActiveIds([c[0].id]),super.__onMouseDown(e)):(this.discardActiveObject(),this.requestRenderAll(),this.setActiveIds([]),this._groupSelector={x:s.x,y:s.y,deltaY:0,deltaX:0},super.__onMouseDown(e))}initEventListeners(){ky(this),xy(this),Py(this)}setActiveIds(e){this.activeIds=e,this.state.updateState({activeIds:Ly(this.activeIds)},{kind:"layer:selection",updateHistory:!1})}updateState(e={updateHistory:!1}){this.filterEmptyTracks(),this.synchronizeTrackItemsState(),this.requestRenderAll(),this.duration=this.getDurationBasedOnTrackItemsPosition(),this.calcBounding(),this.refreshTrackLayout(),this.setTrackItemCoords();const s=this.getUpdatedState();this.state.updateState(s,e)}getUpdatedState(){const e=this.getDurationBasedOnTrackItemsPosition();return{tracks:this.tracks,trackItemIds:this.trackItemIds,trackItemsMap:this.trackItemsMap,transitionIds:this.transitionIds,transitionsMap:this.transitionsMap,scale:this.scale,duration:e}}getDurationBasedOnTrackItemsPosition(){const e=this.getTrackItems().map(n=>n.getBoundingRect()),s=e.reduce((n,o)=>n.left+n.width<o.left+o.width?o:n,e[0]),i=s.left+s.width;return W(i,this.tScale)}notify(e={updateHistory:!1}){const s=this.getUpdatedState();this.state.updateState(s,e)}getState(){const e=En(this.trackItemsMap);return{tracks:this.tracks,trackItemIds:this.trackItemIds,trackItemsMap:this.trackItemsMap,transitionIds:this.transitionIds,transitionsMap:this.transitionsMap,trackItemDetailsMap:this.trackItemDetailsMap,scale:this.scale,duration:e}}purge(){wy(this),My(this),Ay(),this.dispose()}scrollTo({scrollLeft:e,scrollTop:s}){var o;const i=[...this.viewportTransform];let n=!1;typeof e=="number"&&(i[4]=-e+this.spacing.left,n=!0),typeof s=="number"&&(i[5]=-s,n=!0),n&&(this.viewportTransform=i,(o=this.getActiveObject())==null||o.setCoords(),this.requestRenderAll())}setBounding(e){this.bounding=e}calcBounding(){const e=this.getObjects("Track").filter(c=>c.static),s=[...this.getTrackItems(),...e].reduce((c,h)=>{const{top:l,height:u}=h.getBoundingRect();return{top:Math.min(c.top,l),height:Math.max(c.height,l+u)}},{top:1/0,height:0}),i=[...this.getTrackItems()].reduce((c,h)=>{const{left:l,width:u}=h.getBoundingRect();return{left:Math.min(c.left,l),width:Math.max(c.width,l+u)}},{left:1/0,width:this.width}),n=this.bounding.width,o=i.width,a=o-n;if(a<0){const c=this.getTrackItems(),h=this.getElement().clientWidth,l=c.reduce((u,d)=>d.left+d.width>u.left+u.width?d:u,c[0]);Math.abs(a)>h?this.setViewportPos(-(o-h)-this.spacing.right,this.viewportTransform[5]):l.left+l.width<=h?this.setViewportPos(16,this.viewportTransform[5]):this.setViewportPos(this.viewportTransform[4]-a,this.viewportTransform[5])}this.bounding={...s,...i},Z.dispatch(ul,{payload:{bounding:{...s,...i}}})}setViewportPos(e,s){var o;const i=this.getViewportPos(e,s),n=this.viewportTransform;n[4]=i.x,n[5]=i.y,this.requestRenderAll(),this.setActiveTrackItemCoords(),(o=this.onScroll)==null||o.call(this,{scrollTop:i.y,scrollLeft:i.x-this.spacing.left})}getViewportPos(e,s){const i=this,n=this.bounding.width-100>=i.width?this.spacing.right:0,o=i.width-this.bounding.width-n,a=this.spacing.left,c=Math.max(o,Math.min(e,a));if(this.bounding.height<this.height)return{x:c,y:0};const h=i.height-this.bounding.height-40,u=Math.max(h,Math.min(s,0));return{x:c,y:u}}setScale(e){this.pauseEventListeners(),this.tScale=e.zoom,this.scale=e,this.getObjects("Video","Image","Text","Audio","Caption","Template").forEach(i=>{const n=this.transitionGroups.find(o=>o.find(a=>a.id===i.id))||[];if((n==null?void 0:n.length)===1){const o=E(i.display.from,this.tScale),a=E(i.display.to-i.display.from,this.tScale,i.playbackRate);i.set({left:o,width:a,tScale:e.zoom})}else{const o=n.findIndex(u=>u.id===i.id),a=n[o-1],c=n[o+1],h=n.filter(u=>u.type==="transition"),l=this.trackItemsMap[i.id];if(a&&!c){const u=h.indexOf(a),g=h.slice(0,u).reduce((m,b)=>m+(b.duration||0),0),f=E(l.display.from-(a.duration||0)/2-g,this.tScale),p=E(l.display.to-l.display.from-(a.duration||0)/2,this.tScale,l.playbackRate);i.set({left:f,width:p,tScale:e.zoom})}else if(c&&!a){const u=E(l.display.from,this.tScale),d=E(l.display.to-l.display.from-(c.duration||0)/2,this.tScale,l.playbackRate);i.set({left:u,width:d,tScale:e.zoom})}else if(a&&c){const u=E(l.display.from-(a.duration||0)/2,this.tScale),d=E(l.display.to-l.display.from-(c.duration||0)/2-(a.duration||0)/2,this.tScale,i.playbackRate);i.set({left:u,width:d,tScale:e.zoom})}}i.onScale&&i.onScale(),i.setCoords()}),this.requestRenderAll(),this.calcBounding(),this.refreshTrackLayout(),this.updateTransitions(!1),this.resumeEventListeners()}}Dy(Bl,[mg,Ov,Cv,Cy]);const Fy={audio:jn,media:Ln,common:ur,transition:Pn};k.ACCEPTS_MAP=kl,k.Audio=pt,k.BOTTOM=Kd,k.CENTER=Ce,k.Caption=ys,k.Control=V,k.DRAG_END=ho,k.DRAG_PREFIX=co,k.DRAG_START=ll,k.FabricObject=ct,k.Helper=Ve,k.Image=ps,k.LEFT=us,k.NONE=Jd,k.Pattern=Xi,k.Placeholder=vs,k.PreviewTrackItem=he,k.RIGHT=ds,k.Rect=z,k.SIZES_MAP=Ml,k.TIMELINE_BOUNDING_CHANGED=ul,k.TIMELINE_PREFIX=lo,k.TIMELINE_SEEK=dl,k.TOP=qd,k.Template=Bt,k.Text=ms,k.Track=Oe,k.Transition=ce,k.Video=bt,k.calculateTimelineWidth=Qd,k.changeWidth=ur,k.classRegistry=w,k.controlsUtils=Ye,k.createAudioControls=Lc,k.createMediaControls=Fc,k.createResizeControls=dr,k.createTemplateControls=Ac,k.createTransitionControls=An,k.default=Bl,k.drawVerticalLine=Ft,k.generateId=fs,k.getDuration=En,k.isTransformCentered=gs,k.resize=Fy,k.resolveOrigin=P,k.timeMsToUnits=E,k.unitsToTimeMs=W,k.util=rc,k.wrapWithFixedAnchor=Qs,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
498
|
+
`}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let r=0;r<e.length;r+=4){const n=Math.max(e[r],e[r+1],e[r+2]),o=(e[r]+e[r+1]+e[r+2])/3,a=2*Math.abs(n-o)/255*s;e[r]+=n!==e[r]?(n-e[r])*a:0,e[r+1]+=n!==e[r+1]?(n-e[r+1])*a:0,e[r+2]+=n!==e[r+2]?(n-e[r+2])*a:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}v(di,"type","Vibrance"),v(di,"defaults",{vibrance:0}),v(di,"uniformLocations",["uVibrance"]),C.setClass(di);function Ft(i,t,e,s,r){i.save(),i.translate(t,e),i.rotate(rc.degreesToRadians(90+r.angle)),i.lineWidth=6,i.lineCap="round",i.strokeStyle="white",i.beginPath(),i.moveTo(-6,0),i.lineTo(6,0),i.stroke(),i.lineWidth=4,i.strokeStyle="black",i.beginPath(),i.moveTo(-6,0),i.lineTo(6,0),i.stroke(),i.restore()}const $t=1,kt="rgba(255, 255, 255,1.0)",Ic=["Image","Text","Video","Audio","Caption","Template","Composition"],Zd={left:-.5,top:-.5,center:0,bottom:.5,right:.5},A=i=>typeof i=="string"?Zd[i]:i-.5,we="center",ds="left",Jd="top",Qd="bottom",fs="right",tf="none";function gs(i){return A(i.originX)===A(we)&&A(i.originY)===A(we)}function er(i){return(t,e,s,r)=>{const{target:n,originX:o,originY:a}=e,c=n.getRelativeCenterPoint(),h=n.translateToOriginPoint(c,o,a),l=i(t,e,s,r);return n.setPositionByOrigin(h,e.originX,e.originY),l}}const jc=188,ef=1e3/60;function j(i,t=1,e=1){const s=jc*t;return i*(60/1e3)*s/e}function V(i,t=1,e=1){const s=jc*t;return i/s*ef*e}function sf(i,t=1){return j(i,t)}const In=i=>Object.keys(i).reduce((t,e)=>{const{display:s,playbackRate:r}=i[e];return Math.max(t,s.to/(r||1))},0),{wrapWithFireEvent:rf,getLocalPoint:nf}=ze,jn=rf("resizing",er((i,t,e,s)=>{const r=nf(t,t.originX,t.originY,e,s);if(A(t.originX)===A(we)||A(t.originX)===A(fs)&&r.x<0||A(t.originX)===A(ds)&&r.x>0){let{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(r.x*a/n.scaleX)-o);if(t.corner==="mr"){const u=n.trim.to,d=h-c,f=V(d,n.tScale,n.playbackRate),g=u+f;if(g>n.duration)return!1;n.set("width",Math.max(h,0)),n.trim.to=g}else{if(n.left<0)return!1;const u=c-h;if(n.left+u<0){const b=j(n.duration,n.tScale,n.playbackRate),T=n.width+n.left;if(T<=b){n.set("width",T);const w=V(b-T,n.tScale,n.playbackRate);return n.trim.from=w,!0}return!1}const f=h-c,g=n.trim.from,p=V(f,n.tScale,n.playbackRate),m=g-p;if(m<0)return!1;n.set("width",Math.max(h,0)),n.trim.from=m,n.onResize&&n.onResize()}return c!==n.width}return!1})),{wrapWithFireEvent:of,getLocalPoint:af,wrapWithFixedAnchor:cf}=ze,fi=of("resizing",cf((i,t,e,s)=>{const r=af(t,t.originX,t.originY,e,s);if(A(t.originX)===A(we)||A(t.originX)===A(fs)&&r.x<0||A(t.originX)===A(ds)&&r.x>0){const{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(r.x*a/n.scaleX)-o),l=t.corner==="ml";if(n.left<0)return!1;if(l){const u=c-h;if(n.left+u<0)return n.set("width",n.width+n.left),!0}return n.set("width",Math.max(h,0)),c!==n.width}return!1})),{wrapWithFireEvent:hf,getLocalPoint:lf}=ze,En=hf("resizing",er((i,t,e,s)=>{const r=lf(t,t.originX,t.originY,e,s);if(A(t.originX)===A(we)||A(t.originX)===A(fs)&&r.x<0||A(t.originX)===A(ds)&&r.x>0){const{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(r.x*a/n.scaleX)-o),l=V(h,n.tScale,n.playbackRate);return l>=1500||l<500?!1:(n.set("width",Math.max(h,0)),n.set("duration",l),c!==n.width)}return!1})),{wrapWithFireEvent:uf,getLocalPoint:df}=ze,Ec=uf("resizing",er((i,t,e,s)=>{const r=df(t,t.originX,t.originY,e,s);if(A(t.originX)===A(we)||A(t.originX)===A(fs)&&r.x<0||A(t.originX)===A(ds)&&r.x>0){let{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(r.x*a/n.scaleX)-o);if(t.corner==="mr"){const u=n.trim.to,d=h-c,f=V(d,n.tScale,n.playbackRate),g=u+f;if(g>n.duration)return!1;n.set("width",Math.max(h,0)),n.trim.to=g}else{if(n.left<0)return!1;const u=c-h;if(n.left+u<0)return!1;const f=h-c,g=n.trim.from,p=V(f,n.tScale,n.playbackRate),m=g-p;if(m<0)return!1;n.set("width",Math.max(h,0)),n.trim.from=m}return c!==n.width}return!1})),{scaleSkewCursorStyleHandler:qt}=ze,sr=()=>({mr:new $({x:.5,y:0,actionHandler:fi,cursorStyleHandler:qt,actionName:"resizing",render:Ft}),ml:new $({x:-.5,y:0,actionHandler:fi,cursorStyleHandler:qt,actionName:"resizing",render:Ft})}),Pc=()=>({mr:new $({x:.5,y:0,render:Ft,actionHandler:Ec,cursorStyleHandler:qt,actionName:"resizing"}),ml:new $({x:-.5,y:0,render:Ft,actionHandler:Ec,cursorStyleHandler:qt,actionName:"resizing"})}),Ac=()=>({mr:new $({x:.5,y:0,render:Ft,actionHandler:jn,cursorStyleHandler:qt,actionName:"resizing"}),ml:new $({x:-.5,y:0,render:Ft,actionHandler:jn,cursorStyleHandler:qt,actionName:"resizing"})}),Lc=()=>({mr:new $({x:.5,y:0,render:Ft,actionHandler:An,cursorStyleHandler:qt,actionName:"resizing"}),ml:new $({x:-.5,y:0,render:Ft,actionHandler:An,cursorStyleHandler:qt,actionName:"resizing"})}),Pn=()=>({mr:new $({x:.5,y:0,actionHandler:En,cursorStyleHandler:qt,actionName:"resizing",render:Ft}),ml:new $({x:-.5,y:0,actionHandler:En,cursorStyleHandler:qt,actionName:"resizing",render:Ft})}),ff="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let rr=(i=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(i|=0));for(;i--;)t+=ff[e[i]&63];return t};function ps(i=16){const t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",e=t.charAt(Math.floor(Math.random()*t.length));let s=rr(i-1);return s=s.replace(/[^a-zA-Z0-9]/g,"").slice(0,i-1),e+s}const{wrapWithFireEvent:gf,getLocalPoint:pf}=ze,An=gf("resizing",er((i,t,e,s)=>{const r=pf(t,t.originX,t.originY,e,s);if(A(t.originX)===A(we)||A(t.originX)===A(fs)&&r.x<0||A(t.originX)===A(ds)&&r.x>0){let{target:n}=t,o=n.strokeWidth/(n.strokeUniform?n.scaleX:1),a=gs(t)?2:1,c=n.width,h=Math.ceil(Math.abs(r.x*a/n.scaleX)-o);if(t.corner==="mr"){const u=n.trim.to,d=h-c,f=V(d,n.tScale,n.playbackRate),g=u+f;if(g>n.duration)return!1;n.set("width",Math.max(h,0)),n.trim.to=g}else{if(n.left<0)return!1;const u=c-h;if(n.left+u<0){const b=j(n.duration,n.tScale,n.playbackRate),T=n.width+n.left;if(T<=b){n.set("width",T);const w=V(b-T,n.tScale,n.playbackRate);return n.trim.from=w,!0}return!1}const f=h-c,g=n.trim.from,p=V(f,n.tScale,n.playbackRate),m=g-p;if(m<0)return!1;n.set("width",Math.max(h,0)),n.trim.from=m,n.onResize&&n.onResize()}return c!==n.width}return!1})),Os=class Os extends Y{constructor(e){super(e);S(this,"itemType","image");S(this,"src");S(this,"isSelected",!1);Object.assign(this,Os.ownDefaults),this.id=e.id,this.src=e.src,this.display=e.display,this.tScale=e.tScale}static createControls(){return{controls:sr()}}static getDefaults(){return{...super.getDefaults(),...Os.ownDefaults}}_render(e){super._render(e),this.updateSelected(e)}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}setSrc(e){this.src=e}};S(Os,"type","Image"),S(Os,"ownDefaults",{rx:8,ry:8,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,borderOpacityWhenMoving:1,hoverCursor:"default",fill:"#27272a"});let ms=Os;C.setClass(ms,"Image");class bt extends Y{constructor(e){super(e);S(this,"id");S(this,"resourceId","");S(this,"tScale");S(this,"isSelected",!1);S(this,"display");S(this,"trim");S(this,"duration");S(this,"src");this.id=e.id,this.tScale=e.tScale,this.objectCaching=!1,this.rx=8,this.ry=8,this.display=e.display,this.trim=e.trim,this.duration=e.duration,this.fill="#27272a"}static createControls(){return{controls:Lc()}}_render(e){super._render(e),this.updateSelected(e)}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}onResizeSnap(){}setSrc(e){this.src=e}}S(bt,"type","Video"),C.setClass(bt,"Video");const ks=class ks extends Y{constructor(e){super(e);S(this,"itemType","audio");S(this,"isSelected",!1);S(this,"trim");S(this,"src");S(this,"duration");Object.assign(this,ks.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.trim=e.trim,this.src=e.src,this.duration=e.duration}static getDefaults(){return{...super.getDefaults(),...ks.ownDefaults}}static createControls(){return{controls:Ac()}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}setSrc(e){this.src=e}};S(ks,"type","Audio"),S(ks,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let pt=ks;C.setClass(pt,"Audio");const Ms=class Ms extends Y{constructor(e){super(e);S(this,"isSelected",!1);S(this,"text");Object.assign(this,Ms.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.text=e.text}static createControls(){return{controls:sr()}}static getDefaults(){return{...super.getDefaults(),...Ms.ownDefaults}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}};S(Ms,"type","Text"),S(Ms,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let vs=Ms;C.setClass(vs,"Text");const mf={selectable:!1,evented:!1,strokeWidth:0,stroke:"transparent"},Ds=class Ds extends Y{constructor(e){super(e);S(this,"id");S(this,"accepts",["audio","video","image","text","caption","template"]);S(this,"metadata");S(this,"items",[]);S(this,"magnetic");S(this,"static");Object.assign(this,Ds.ownDefaults),this.id=e.id,this.accepts=e.accepts||[],this.items=e.items||[],this.magnetic=e.magnetic,this.static=e.static,this.metadata=e.metadata,this.fill="rgba(34, 34, 37, 0.8)"}static getDefaults(){return{...super.getDefaults(),...Ds.ownDefaults}}updateCoords(e){this.width=e}};S(Ds,"ownDefaults",mf),S(Ds,"type","Track");let Kt=Ds;C.setClass(Kt,"Track");const vf={top:{top:35,guide:2,bottom:3},center:{top:3,guide:2,bottom:3},bottom:{top:3,guide:2,bottom:35}},yf=(i,t)=>{const e=vf[i];return i==="top"?{top:t-(e.guide+e.bottom),guide:e.guide,bottom:e.bottom}:i==="center"?{top:e.top,guide:e.guide,bottom:e.bottom}:{top:e==null?void 0:e.top,guide:e==null?void 0:e.guide,bottom:t-((e==null?void 0:e.guide)+(e==null?void 0:e.top))}},Is=class Is extends Nt{constructor(e){const s=yf(e.kind,e.height),r=new Y({top:0,left:0,strokeWidth:0,fill:"transparent",selectable:!0,height:s.top,width:e.width}),n=new Y({top:s.top,left:0,strokeWidth:0,fill:"transparent",selectable:!0,height:s.guide,width:e.width}),o=new Y({top:s.top+s.guide,left:0,strokeWidth:0,fill:"transparent",selectable:!0,height:s.bottom,width:e.width});super([r,n,o],e);S(this,"guide");S(this,"topGuide");S(this,"bottomGuide");S(this,"metadata");S(this,"accepts",[]);S(this,"kind");S(this,"activeGuideFill");Object.assign(this,Is.ownDefaults),this.guide=n,this.topGuide=r,this.bottomGuide=o,this.id=e.id,this.metadata=e.metadata,this.tScale=e.tScale,this.kind=e.kind,this.activeGuideFill=e.activeGuideFill||kt}static getDefaults(){return{...super.getDefaults(),...Is.ownDefaults}}updateCoords(e){this.scaleToWidth(e),this.set("scaleY",1)}setSelected(e){e?this.guide.set("fill",this.activeGuideFill):this.guide.set("fill","transparent")}};S(Is,"type","Helper"),S(Is,"ownDefaults",{selectable:!1,evented:!1});let Ye=Is;C.setClass(Ye,"Helper");const js=class js extends Y{constructor(e){super(e);S(this,"guideItemId");S(this,"distXToActCenter");S(this,"trackItemType");S(this,"defaultPos");S(this,"draggedObject");Object.assign(this,js.ownDefaults),this.id=e.id}static getDefaults(){return{...super.getDefaults(),...js.ownDefaults}}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=$t,e.setLineDash(this.strokeDashArray),e.strokeStyle=kt,e.stroke(),e.restore()}};S(js,"type","Placeholder"),S(js,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",strokeWidth:0,fill:"rgba(255, 211, 42,0.1)",stroke:"rgba(255, 211, 42,1.0)",selectable:!1,borderOpacityWhenMoving:1,hoverCursor:"default",strokeDashArray:[5,1],evented:!1});let ys=js;C.setClass(ys,"Placeholder");const Es=class Es extends Y{constructor(e){super(e);S(this,"duration");S(this,"fromId");S(this,"toId");S(this,"kind","none");S(this,"isSelected",!1);Object.assign(this,Es.ownDefaults),this.id=e.id,this.centeredScaling=!0,this.strokeWidth=0,this.tScale=e.tScale,this.duration=e.duration,this.fromId=e.fromId,this.toId=e.toId,this.kind=e.kind,this.strokeDashArray=e.strokeDashArray||[]}static createControls(){return{controls:Pn()}}static getDefaults(){return{...super.getDefaults(),...Es.ownDefaults}}updateCoords(){}_render(e){super._render(e),this.updateSelected(e)}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){const s=this.isSelected?kt:"rgba(255, 255, 255,0.15)";e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=$t,e.setLineDash(this.strokeDashArray),e.strokeStyle=s,e.stroke(),e.restore()}};S(Es,"type","Transition"),S(Es,"ownDefaults",{objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:1.5,fill:"rgba(0,0,0, 0.5)",borderOpacityWhenMoving:1,hoverCursor:"default",lockMovementX:!0,lockMovementY:!0,duration:1500,rx:8,ry:8});let Rt=Es;C.setClass(Rt,"Transition");const Ps=class Ps extends Y{constructor(e){super(e);S(this,"isSelected",!1);S(this,"text");Object.assign(this,Ps.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.text=e.text}static createControls(){return{controls:sr()}}static getDefaults(){return{...super.getDefaults(),...Ps.ownDefaults}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}};S(Ps,"type","Caption"),S(Ps,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let bs=Ps;C.setClass(bs,"Caption");const As=class As extends Y{constructor(e){super(e);S(this,"itemType","template");S(this,"isSelected",!1);S(this,"trim");Object.assign(this,As.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display,this.trim=e.trim}static getDefaults(){return{...super.getDefaults(),...As.ownDefaults}}static createControls(){return{controls:Pc()}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}};S(As,"type","Template"),S(As,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let Bt=As;C.setClass(Bt,"Template");function bf(i){const t=Math.floor(i/1e3),e=Math.floor(t/60),s=t%60,r=String(e).padStart(2,"0"),n=String(s).padStart(2,"0");return`${r}:${n}`}const Ls=class Ls extends Y{constructor(e){super(e);S(this,"duration");S(this,"fromId");S(this,"toId");S(this,"isSelected",!1);S(this,"name");S(this,"durationString");S(this,"itemType");Object.assign(this,Ls.ownDefaults),this.id=e.id,this.fill="#27272a",this.name=e.type.toUpperCase(),this.durationString=bf(e.duration),this.itemType=e.type}static getDefaults(){return{...super.getDefaults(),...Ls.ownDefaults}}_render(e){e.save(),super._render(e),e.beginPath(),e.rect(-this.width/2,-this.height/2,this.width,this.height),e.clip(),this.drawTextIdentity(e),e.restore()}drawTextIdentity(e){e.font="600 12px 'Geist variable'",e.textAlign="left";const s=e.measureText(this.name).width,r=e.measureText(this.durationString).width,n=8,o=4,a=4-this.height/2,c=20,h=4,l=4-this.width/2,u=s+n*2;this.drawRoundedRect(e,l,a,u,c,h),e.fillStyle="#f4f4f5",e.fillText(this.name,l+n,a+14);const d=l+u+o,f=r+n*2;this.drawRoundedRect(e,d,a,f,c,h),e.fillStyle="#f4f4f5",e.fillText(this.durationString,d+n,a+14)}drawRoundedRect(e,s,r,n,o,a){e.fillStyle="rgba(0, 0, 0, 0.5)",e.roundRect?(e.beginPath(),e.roundRect(s,r,n,o,a),e.fill()):e.fillRect(s,r,n,o)}};S(Ls,"type","PreviewTrackItem"),S(Ls,"ownDefaults",{objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,borderOpacityWhenMoving:1,hoverCursor:"default",rx:4,ry:4});let he=Ls;C.setClass(he,"PreviewTrackItem");class _f{constructor(){S(this,"___eventListeners",{});S(this,"___activeObjects",[])}resize(t,{force:e}={force:!1}){var s;this.lowerCanvasEl&&(this.setDimensions(t),e&&this.renderTracks(),(s=this.onResizeCanvas)==null||s.call(this,{width:this.width,height:this.height}))}pauseEventListeners(){this.___eventListeners=this.__eventListeners,this.__eventListeners={};const t=this.getActiveObjects();this.discardActiveObject(),this.___activeObjects=t}resumeEventListeners(){this.__eventListeners=this.___eventListeners,this.___eventListeners={};const t=this.___activeObjects;if(!t.length)return this.requestRenderAll(),!1;if(t.length===1)this.setActiveObject(t[0]);else{const e=new Ct(t);this.setActiveObject(e)}this.requestRenderAll()}updateCachingActiveObjects(t){const e=this.___activeObjects;this.___activeObjects=e.map(s=>{const r=t.find(n=>n.id===s.id);return r||s})}}function ir(i,t){return i.map(e=>({...e,items:e.items.filter(s=>!t.includes(s))}))}const Fs=class Fs extends Y{constructor(e){super(e);S(this,"itemType","composition");S(this,"isSelected",!1);Object.assign(this,Fs.ownDefaults),this.id=e.id,this.borderColor="transparent",this.stroke="transparent",this.strokeWidth=0,this.tScale=e.tScale,this.display=e.display}static getDefaults(){return{...super.getDefaults(),...Fs.ownDefaults}}static createControls(){return{controls:sr()}}setSelected(e){this.isSelected=e,this.set({dirty:!0})}_render(e){super._render(e),this.updateSelected(e)}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,6),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}};S(Fs,"type","Composition"),S(Fs,"ownDefaults",{rx:6,ry:6,objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:0,fill:"#27272a",borderOpacityWhenMoving:1,hoverCursor:"default"});let gi=Fs;C.setClass(gi,"Composition");const Tf=(i,t)=>{var a;const e=j(i.display.from,t.tScale),s=j(i.duration,t.tScale,i.playbackRate),r=t.sizesMap.video,n=C.getClass("Video")||bt;return new n({width:s,height:r,id:i.id,tScale:t.tScale,fill:"#333333",resourceId:(a=i.metadata)==null?void 0:a.resourceId,duration:i.duration,top:10,left:e,display:i.display,trim:i.trim,src:i.details.src,metadata:i.metadata})},Sf=(i,t)=>{const e=i.display,s=j(e.from,t.tScale),r=j(e.to-e.from,t.tScale),n=t.sizesMap.text,o=C.getClass("Text")||vs;return new o({width:r,height:n,id:i.id,display:e,top:10,left:s,text:i.details.text,tScale:t.tScale})},xf=(i,t)=>{const e=i.display,s=j(e.from,t.tScale),r=j(e.to-e.from,t.tScale),n=t.sizesMap.caption,o=C.getClass("Caption")||bs;return new o({width:r,height:n,id:i.id,display:e,top:10,left:s,text:i.details.text,tScale:t.tScale})},wf=(i,t)=>{const e=j(i.display.from,t.tScale),s=j(i.display.to-(i.display.from||5e3),t.tScale),r=t.sizesMap.image,n=C.getClass("Image")||ms;return new n({width:s,height:r,id:i.id,src:i.details.src,tScale:t.tScale,top:10,left:e,display:i.display})},Cf=(i,t)=>{const e=i.display,s=j(e.from,t.tScale),r=j(e.to-e.from,t.tScale,i.playbackRate),n=t.sizesMap.audio,o=C.getClass("Audio")||pt;return new o({width:r,height:n,top:10,left:s,id:i.id,display:e,trim:i.trim||{from:0,to:i.duration},duration:i.duration,src:i.details.src,tScale:t.tScale})},Of=(i,t)=>{const e=i.display,s=j(e.from,t.tScale),r=j(e.to-e.from,t.tScale),n=42,o=C.getClass("Template")||Bt;return new o({width:r,height:n,top:10,left:s,id:i.id,display:e,duration:e.to-e.from,tScale:t.tScale,trim:i.trim||i.display})},kf=(i,t)=>{const e=i.display,s=j(e.from,t.tScale),r=j(e.to-e.from,t.tScale),n=32,o=C.getClass("Composition")||gi;return new o({width:r,height:n,id:i.id,display:e,top:10,left:s,duration:e.to-e.from,tScale:t.tScale})},Mf=(i,t)=>{if(i.type==="caption")return xf(i,t);if(i.type==="text")return Sf(i,t);if(i.type==="image")return wf(i,t);if(i.type==="video")return Tf(i,t);if(i.type==="audio")return Cf(i,t);if(i.type==="template")return Of(i,t);if(i.type==="composition")return kf(i,t)};var Fc=typeof global=="object"&&global&&global.Object===Object&&global,Df=typeof self=="object"&&self&&self.Object===Object&&self,Wt=Fc||Df||Function("return this")(),Mt=Wt.Symbol,Rc=Object.prototype,If=Rc.hasOwnProperty,jf=Rc.toString,nr=Mt?Mt.toStringTag:void 0;function Ef(i){var t=If.call(i,nr),e=i[nr];try{i[nr]=void 0;var s=!0}catch{}var r=jf.call(i);return s&&(t?i[nr]=e:delete i[nr]),r}var Pf=Object.prototype,Af=Pf.toString;function Lf(i){return Af.call(i)}var Ff="[object Null]",Rf="[object Undefined]",Bc=Mt?Mt.toStringTag:void 0;function _s(i){return i==null?i===void 0?Rf:Ff:Bc&&Bc in Object(i)?Ef(i):Lf(i)}function Ce(i){return i!=null&&typeof i=="object"}var Bf="[object Symbol]";function pi(i){return typeof i=="symbol"||Ce(i)&&_s(i)==Bf}function Wf(i,t){for(var e=-1,s=i==null?0:i.length,r=Array(s);++e<s;)r[e]=t(i[e],e,i);return r}var Zt=Array.isArray,Wc=Mt?Mt.prototype:void 0,Xc=Wc?Wc.toString:void 0;function zc(i){if(typeof i=="string")return i;if(Zt(i))return Wf(i,zc)+"";if(pi(i))return Xc?Xc.call(i):"";var t=i+"";return t=="0"&&1/i==-1/0?"-0":t}var Xf=/\s/;function zf(i){for(var t=i.length;t--&&Xf.test(i.charAt(t)););return t}var Hf=/^\s+/;function Yf(i){return i&&i.slice(0,zf(i)+1).replace(Hf,"")}function Jt(i){var t=typeof i;return i!=null&&(t=="object"||t=="function")}var Hc=NaN,Vf=/^[-+]0x[0-9a-f]+$/i,Gf=/^0b[01]+$/i,Nf=/^0o[0-7]+$/i,Uf=parseInt;function Yc(i){if(typeof i=="number")return i;if(pi(i))return Hc;if(Jt(i)){var t=typeof i.valueOf=="function"?i.valueOf():i;i=Jt(t)?t+"":t}if(typeof i!="string")return i===0?i:+i;i=Yf(i);var e=Gf.test(i);return e||Nf.test(i)?Uf(i.slice(2),e?2:8):Vf.test(i)?Hc:+i}function $f(i){return i}var qf="[object AsyncFunction]",Kf="[object Function]",Zf="[object GeneratorFunction]",Jf="[object Proxy]";function Vc(i){if(!Jt(i))return!1;var t=_s(i);return t==Kf||t==Zf||t==qf||t==Jf}var Ln=Wt["__core-js_shared__"],Gc=function(){var i=/[^.]+$/.exec(Ln&&Ln.keys&&Ln.keys.IE_PROTO||"");return i?"Symbol(src)_1."+i:""}();function Qf(i){return!!Gc&&Gc in i}var tg=Function.prototype,eg=tg.toString;function Ve(i){if(i!=null){try{return eg.call(i)}catch{}try{return i+""}catch{}}return""}var sg=/[\\^$.*+?()[\]{}|]/g,rg=/^\[object .+?Constructor\]$/,ig=Function.prototype,ng=Object.prototype,og=ig.toString,ag=ng.hasOwnProperty,cg=RegExp("^"+og.call(ag).replace(sg,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function hg(i){if(!Jt(i)||Qf(i))return!1;var t=Vc(i)?cg:rg;return t.test(Ve(i))}function lg(i,t){return i==null?void 0:i[t]}function Ge(i,t){var e=lg(i,t);return hg(e)?e:void 0}var Fn=Ge(Wt,"WeakMap"),Nc=Object.create,ug=function(){function i(){}return function(t){if(!Jt(t))return{};if(Nc)return Nc(t);i.prototype=t;var e=new i;return i.prototype=void 0,e}}();function dg(i,t,e){switch(e.length){case 0:return i.call(t);case 1:return i.call(t,e[0]);case 2:return i.call(t,e[0],e[1]);case 3:return i.call(t,e[0],e[1],e[2])}return i.apply(t,e)}var fg=800,gg=16,pg=Date.now;function mg(i){var t=0,e=0;return function(){var s=pg(),r=gg-(s-e);if(e=s,r>0){if(++t>=fg)return arguments[0]}else t=0;return i.apply(void 0,arguments)}}function vg(i){return function(){return i}}var mi=function(){try{var i=Ge(Object,"defineProperty");return i({},"",{}),i}catch{}}(),yg=mi?function(i,t){return mi(i,"toString",{configurable:!0,enumerable:!1,value:vg(t),writable:!0})}:$f,bg=mg(yg);function _g(i,t){for(var e=-1,s=i==null?0:i.length;++e<s&&t(i[e],e,i)!==!1;);return i}var Tg=9007199254740991,Sg=/^(?:0|[1-9]\d*)$/;function Rn(i,t){var e=typeof i;return t=t??Tg,!!t&&(e=="number"||e!="symbol"&&Sg.test(i))&&i>-1&&i%1==0&&i<t}function xg(i,t,e){t=="__proto__"&&mi?mi(i,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):i[t]=e}function Bn(i,t){return i===t||i!==i&&t!==t}var wg=Object.prototype,Cg=wg.hasOwnProperty;function Uc(i,t,e){var s=i[t];(!(Cg.call(i,t)&&Bn(s,e))||e===void 0&&!(t in i))&&xg(i,t,e)}var $c=Math.max;function Og(i,t,e){return t=$c(t===void 0?i.length-1:t,0),function(){for(var s=arguments,r=-1,n=$c(s.length-t,0),o=Array(n);++r<n;)o[r]=s[t+r];r=-1;for(var a=Array(t+1);++r<t;)a[r]=s[r];return a[t]=e(o),dg(i,this,a)}}var kg=9007199254740991;function Wn(i){return typeof i=="number"&&i>-1&&i%1==0&&i<=kg}function Mg(i){return i!=null&&Wn(i.length)&&!Vc(i)}var Dg=Object.prototype;function qc(i){var t=i&&i.constructor,e=typeof t=="function"&&t.prototype||Dg;return i===e}function Ig(i,t){for(var e=-1,s=Array(i);++e<i;)s[e]=t(e);return s}var jg="[object Arguments]";function Kc(i){return Ce(i)&&_s(i)==jg}var Zc=Object.prototype,Eg=Zc.hasOwnProperty,Pg=Zc.propertyIsEnumerable,Xn=Kc(function(){return arguments}())?Kc:function(i){return Ce(i)&&Eg.call(i,"callee")&&!Pg.call(i,"callee")};function Ag(){return!1}var Jc=typeof M=="object"&&M&&!M.nodeType&&M,Qc=Jc&&typeof module=="object"&&module&&!module.nodeType&&module,Lg=Qc&&Qc.exports===Jc,th=Lg?Wt.Buffer:void 0,Fg=th?th.isBuffer:void 0,vi=Fg||Ag,Rg="[object Arguments]",Bg="[object Array]",Wg="[object Boolean]",Xg="[object Date]",zg="[object Error]",Hg="[object Function]",Yg="[object Map]",Vg="[object Number]",Gg="[object Object]",Ng="[object RegExp]",Ug="[object Set]",$g="[object String]",qg="[object WeakMap]",Kg="[object ArrayBuffer]",Zg="[object DataView]",Jg="[object Float32Array]",Qg="[object Float64Array]",tp="[object Int8Array]",ep="[object Int16Array]",sp="[object Int32Array]",rp="[object Uint8Array]",ip="[object Uint8ClampedArray]",np="[object Uint16Array]",op="[object Uint32Array]",N={};N[Jg]=N[Qg]=N[tp]=N[ep]=N[sp]=N[rp]=N[ip]=N[np]=N[op]=!0,N[Rg]=N[Bg]=N[Kg]=N[Wg]=N[Zg]=N[Xg]=N[zg]=N[Hg]=N[Yg]=N[Vg]=N[Gg]=N[Ng]=N[Ug]=N[$g]=N[qg]=!1;function ap(i){return Ce(i)&&Wn(i.length)&&!!N[_s(i)]}function zn(i){return function(t){return i(t)}}var eh=typeof M=="object"&&M&&!M.nodeType&&M,or=eh&&typeof module=="object"&&module&&!module.nodeType&&module,cp=or&&or.exports===eh,Hn=cp&&Fc.process,Ts=function(){try{var i=or&&or.require&&or.require("util").types;return i||Hn&&Hn.binding&&Hn.binding("util")}catch{}}(),sh=Ts&&Ts.isTypedArray,rh=sh?zn(sh):ap,hp=Object.prototype,lp=hp.hasOwnProperty;function up(i,t){var e=Zt(i),s=!e&&Xn(i),r=!e&&!s&&vi(i),n=!e&&!s&&!r&&rh(i),o=e||s||r||n,a=o?Ig(i.length,String):[],c=a.length;for(var h in i)lp.call(i,h)&&!(o&&(h=="length"||r&&(h=="offset"||h=="parent")||n&&(h=="buffer"||h=="byteLength"||h=="byteOffset")||Rn(h,c)))&&a.push(h);return a}function ih(i,t){return function(e){return i(t(e))}}var dp=ih(Object.keys,Object),fp=Object.prototype,gp=fp.hasOwnProperty;function pp(i){if(!qc(i))return dp(i);var t=[];for(var e in Object(i))gp.call(i,e)&&e!="constructor"&&t.push(e);return t}function mp(i){return Mg(i)?up(i):pp(i)}var vp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,yp=/^\w*$/;function bp(i,t){if(Zt(i))return!1;var e=typeof i;return e=="number"||e=="symbol"||e=="boolean"||i==null||pi(i)?!0:yp.test(i)||!vp.test(i)||t!=null&&i in Object(t)}var ar=Ge(Object,"create");function _p(){this.__data__=ar?ar(null):{},this.size=0}function Tp(i){var t=this.has(i)&&delete this.__data__[i];return this.size-=t?1:0,t}var Sp="__lodash_hash_undefined__",xp=Object.prototype,wp=xp.hasOwnProperty;function Cp(i){var t=this.__data__;if(ar){var e=t[i];return e===Sp?void 0:e}return wp.call(t,i)?t[i]:void 0}var Op=Object.prototype,kp=Op.hasOwnProperty;function Mp(i){var t=this.__data__;return ar?t[i]!==void 0:kp.call(t,i)}var Dp="__lodash_hash_undefined__";function Ip(i,t){var e=this.__data__;return this.size+=this.has(i)?0:1,e[i]=ar&&t===void 0?Dp:t,this}function Ne(i){var t=-1,e=i==null?0:i.length;for(this.clear();++t<e;){var s=i[t];this.set(s[0],s[1])}}Ne.prototype.clear=_p,Ne.prototype.delete=Tp,Ne.prototype.get=Cp,Ne.prototype.has=Mp,Ne.prototype.set=Ip;function jp(){this.__data__=[],this.size=0}function yi(i,t){for(var e=i.length;e--;)if(Bn(i[e][0],t))return e;return-1}var Ep=Array.prototype,Pp=Ep.splice;function Ap(i){var t=this.__data__,e=yi(t,i);if(e<0)return!1;var s=t.length-1;return e==s?t.pop():Pp.call(t,e,1),--this.size,!0}function Lp(i){var t=this.__data__,e=yi(t,i);return e<0?void 0:t[e][1]}function Fp(i){return yi(this.__data__,i)>-1}function Rp(i,t){var e=this.__data__,s=yi(e,i);return s<0?(++this.size,e.push([i,t])):e[s][1]=t,this}function le(i){var t=-1,e=i==null?0:i.length;for(this.clear();++t<e;){var s=i[t];this.set(s[0],s[1])}}le.prototype.clear=jp,le.prototype.delete=Ap,le.prototype.get=Lp,le.prototype.has=Fp,le.prototype.set=Rp;var cr=Ge(Wt,"Map");function Bp(){this.size=0,this.__data__={hash:new Ne,map:new(cr||le),string:new Ne}}function Wp(i){var t=typeof i;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?i!=="__proto__":i===null}function bi(i,t){var e=i.__data__;return Wp(t)?e[typeof t=="string"?"string":"hash"]:e.map}function Xp(i){var t=bi(this,i).delete(i);return this.size-=t?1:0,t}function zp(i){return bi(this,i).get(i)}function Hp(i){return bi(this,i).has(i)}function Yp(i,t){var e=bi(this,i),s=e.size;return e.set(i,t),this.size+=e.size==s?0:1,this}function ue(i){var t=-1,e=i==null?0:i.length;for(this.clear();++t<e;){var s=i[t];this.set(s[0],s[1])}}ue.prototype.clear=Bp,ue.prototype.delete=Xp,ue.prototype.get=zp,ue.prototype.has=Hp,ue.prototype.set=Yp;var Vp="Expected a function";function Yn(i,t){if(typeof i!="function"||t!=null&&typeof t!="function")throw new TypeError(Vp);var e=function(){var s=arguments,r=t?t.apply(this,s):s[0],n=e.cache;if(n.has(r))return n.get(r);var o=i.apply(this,s);return e.cache=n.set(r,o)||n,o};return e.cache=new(Yn.Cache||ue),e}Yn.Cache=ue;var Gp=500;function Np(i){var t=Yn(i,function(s){return e.size===Gp&&e.clear(),s}),e=t.cache;return t}var Up=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,$p=/\\(\\)?/g,qp=Np(function(i){var t=[];return i.charCodeAt(0)===46&&t.push(""),i.replace(Up,function(e,s,r,n){t.push(r?n.replace($p,"$1"):s||e)}),t});function Kp(i){return i==null?"":zc(i)}function _i(i,t){return Zt(i)?i:bp(i,t)?[i]:qp(Kp(i))}function Vn(i){if(typeof i=="string"||pi(i))return i;var t=i+"";return t=="0"&&1/i==-1/0?"-0":t}function Zp(i,t){t=_i(t,i);for(var e=0,s=t.length;i!=null&&e<s;)i=i[Vn(t[e++])];return e&&e==s?i:void 0}function nh(i,t){for(var e=-1,s=t.length,r=i.length;++e<s;)i[r+e]=t[e];return i}var oh=Mt?Mt.isConcatSpreadable:void 0;function Jp(i){return Zt(i)||Xn(i)||!!(oh&&i&&i[oh])}function Qp(i,t,e,s,r){var n=-1,o=i.length;for(e||(e=Jp),r||(r=[]);++n<o;){var a=i[n];e(a)?nh(r,a):r[r.length]=a}return r}function Gn(i){var t=i==null?0:i.length;return t?Qp(i):[]}function tm(i){return bg(Og(i,void 0,Gn),i+"")}var em=ih(Object.getPrototypeOf,Object);function sm(){this.__data__=new le,this.size=0}function rm(i){var t=this.__data__,e=t.delete(i);return this.size=t.size,e}function im(i){return this.__data__.get(i)}function nm(i){return this.__data__.has(i)}var om=200;function am(i,t){var e=this.__data__;if(e instanceof le){var s=e.__data__;if(!cr||s.length<om-1)return s.push([i,t]),this.size=++e.size,this;e=this.__data__=new ue(s)}return e.set(i,t),this.size=e.size,this}function de(i){var t=this.__data__=new le(i);this.size=t.size}de.prototype.clear=sm,de.prototype.delete=rm,de.prototype.get=im,de.prototype.has=nm,de.prototype.set=am;var ah=typeof M=="object"&&M&&!M.nodeType&&M,ch=ah&&typeof module=="object"&&module&&!module.nodeType&&module,cm=ch&&ch.exports===ah,hh=cm?Wt.Buffer:void 0;hh&&hh.allocUnsafe;function hm(i,t){return i.slice()}function lm(i,t){for(var e=-1,s=i==null?0:i.length,r=0,n=[];++e<s;){var o=i[e];t(o,e,i)&&(n[r++]=o)}return n}function um(){return[]}var dm=Object.prototype,fm=dm.propertyIsEnumerable,lh=Object.getOwnPropertySymbols,gm=lh?function(i){return i==null?[]:(i=Object(i),lm(lh(i),function(t){return fm.call(i,t)}))}:um;function pm(i,t,e){var s=t(i);return Zt(i)?s:nh(s,e(i))}function Nn(i){return pm(i,mp,gm)}var Un=Ge(Wt,"DataView"),$n=Ge(Wt,"Promise"),qn=Ge(Wt,"Set"),uh="[object Map]",mm="[object Object]",dh="[object Promise]",fh="[object Set]",gh="[object WeakMap]",ph="[object DataView]",vm=Ve(Un),ym=Ve(cr),bm=Ve($n),_m=Ve(qn),Tm=Ve(Fn),Xt=_s;(Un&&Xt(new Un(new ArrayBuffer(1)))!=ph||cr&&Xt(new cr)!=uh||$n&&Xt($n.resolve())!=dh||qn&&Xt(new qn)!=fh||Fn&&Xt(new Fn)!=gh)&&(Xt=function(i){var t=_s(i),e=t==mm?i.constructor:void 0,s=e?Ve(e):"";if(s)switch(s){case vm:return ph;case ym:return uh;case bm:return dh;case _m:return fh;case Tm:return gh}return t});var Sm=Object.prototype,xm=Sm.hasOwnProperty;function wm(i){var t=i.length,e=new i.constructor(t);return t&&typeof i[0]=="string"&&xm.call(i,"index")&&(e.index=i.index,e.input=i.input),e}var Ti=Wt.Uint8Array;function Kn(i){var t=new i.constructor(i.byteLength);return new Ti(t).set(new Ti(i)),t}function Cm(i,t){var e=Kn(i.buffer);return new i.constructor(e,i.byteOffset,i.byteLength)}var Om=/\w*$/;function km(i){var t=new i.constructor(i.source,Om.exec(i));return t.lastIndex=i.lastIndex,t}var mh=Mt?Mt.prototype:void 0,vh=mh?mh.valueOf:void 0;function Mm(i){return vh?Object(vh.call(i)):{}}function Dm(i,t){var e=Kn(i.buffer);return new i.constructor(e,i.byteOffset,i.length)}var Im="[object Boolean]",jm="[object Date]",Em="[object Map]",Pm="[object Number]",Am="[object RegExp]",Lm="[object Set]",Fm="[object String]",Rm="[object Symbol]",Bm="[object ArrayBuffer]",Wm="[object DataView]",Xm="[object Float32Array]",zm="[object Float64Array]",Hm="[object Int8Array]",Ym="[object Int16Array]",Vm="[object Int32Array]",Gm="[object Uint8Array]",Nm="[object Uint8ClampedArray]",Um="[object Uint16Array]",$m="[object Uint32Array]";function qm(i,t,e){var s=i.constructor;switch(t){case Bm:return Kn(i);case Im:case jm:return new s(+i);case Wm:return Cm(i);case Xm:case zm:case Hm:case Ym:case Vm:case Gm:case Nm:case Um:case $m:return Dm(i);case Em:return new s;case Pm:case Fm:return new s(i);case Am:return km(i);case Lm:return new s;case Rm:return Mm(i)}}function Km(i){return typeof i.constructor=="function"&&!qc(i)?ug(em(i)):{}}var Zm="[object Map]";function Jm(i){return Ce(i)&&Xt(i)==Zm}var yh=Ts&&Ts.isMap,Qm=yh?zn(yh):Jm,tv="[object Set]";function ev(i){return Ce(i)&&Xt(i)==tv}var bh=Ts&&Ts.isSet,sv=bh?zn(bh):ev,_h="[object Arguments]",rv="[object Array]",iv="[object Boolean]",nv="[object Date]",ov="[object Error]",Th="[object Function]",av="[object GeneratorFunction]",cv="[object Map]",hv="[object Number]",Sh="[object Object]",lv="[object RegExp]",uv="[object Set]",dv="[object String]",fv="[object Symbol]",gv="[object WeakMap]",pv="[object ArrayBuffer]",mv="[object DataView]",vv="[object Float32Array]",yv="[object Float64Array]",bv="[object Int8Array]",_v="[object Int16Array]",Tv="[object Int32Array]",Sv="[object Uint8Array]",xv="[object Uint8ClampedArray]",wv="[object Uint16Array]",Cv="[object Uint32Array]",G={};G[_h]=G[rv]=G[pv]=G[mv]=G[iv]=G[nv]=G[vv]=G[yv]=G[bv]=G[_v]=G[Tv]=G[cv]=G[hv]=G[Sh]=G[lv]=G[uv]=G[dv]=G[fv]=G[Sv]=G[xv]=G[wv]=G[Cv]=!0,G[ov]=G[Th]=G[gv]=!1;function Si(i,t,e,s,r,n){var o;if(o!==void 0)return o;if(!Jt(i))return i;var a=Zt(i);if(a)o=wm(i);else{var c=Xt(i),h=c==Th||c==av;if(vi(i))return hm(i);if(c==Sh||c==_h||h&&!r)o=h?{}:Km(i);else{if(!G[c])return r?i:{};o=qm(i,c)}}n||(n=new de);var l=n.get(i);if(l)return l;n.set(i,o),sv(i)?i.forEach(function(f){o.add(Si(f,t,e,f,i,n))}):Qm(i)&&i.forEach(function(f,g){o.set(g,Si(f,t,e,g,i,n))});var u=Nn,d=a?void 0:u(i);return _g(d||i,function(f,g){d&&(g=f,f=i[g]),Uc(o,g,Si(f,t,e,g,i,n))}),o}var Ov=1,kv=4;function Qt(i){return Si(i,Ov|kv)}var Mv="__lodash_hash_undefined__";function Dv(i){return this.__data__.set(i,Mv),this}function Iv(i){return this.__data__.has(i)}function xi(i){var t=-1,e=i==null?0:i.length;for(this.__data__=new ue;++t<e;)this.add(i[t])}xi.prototype.add=xi.prototype.push=Dv,xi.prototype.has=Iv;function jv(i,t){for(var e=-1,s=i==null?0:i.length;++e<s;)if(t(i[e],e,i))return!0;return!1}function Ev(i,t){return i.has(t)}var Pv=1,Av=2;function xh(i,t,e,s,r,n){var o=e&Pv,a=i.length,c=t.length;if(a!=c&&!(o&&c>a))return!1;var h=n.get(i),l=n.get(t);if(h&&l)return h==t&&l==i;var u=-1,d=!0,f=e&Av?new xi:void 0;for(n.set(i,t),n.set(t,i);++u<a;){var g=i[u],p=t[u];if(s)var m=o?s(p,g,u,t,i,n):s(g,p,u,i,t,n);if(m!==void 0){if(m)continue;d=!1;break}if(f){if(!jv(t,function(b,T){if(!Ev(f,T)&&(g===b||r(g,b,e,s,n)))return f.push(T)})){d=!1;break}}else if(!(g===p||r(g,p,e,s,n))){d=!1;break}}return n.delete(i),n.delete(t),d}function Lv(i){var t=-1,e=Array(i.size);return i.forEach(function(s,r){e[++t]=[r,s]}),e}function Fv(i){var t=-1,e=Array(i.size);return i.forEach(function(s){e[++t]=s}),e}var Rv=1,Bv=2,Wv="[object Boolean]",Xv="[object Date]",zv="[object Error]",Hv="[object Map]",Yv="[object Number]",Vv="[object RegExp]",Gv="[object Set]",Nv="[object String]",Uv="[object Symbol]",$v="[object ArrayBuffer]",qv="[object DataView]",wh=Mt?Mt.prototype:void 0,Zn=wh?wh.valueOf:void 0;function Kv(i,t,e,s,r,n,o){switch(e){case qv:if(i.byteLength!=t.byteLength||i.byteOffset!=t.byteOffset)return!1;i=i.buffer,t=t.buffer;case $v:return!(i.byteLength!=t.byteLength||!n(new Ti(i),new Ti(t)));case Wv:case Xv:case Yv:return Bn(+i,+t);case zv:return i.name==t.name&&i.message==t.message;case Vv:case Nv:return i==t+"";case Hv:var a=Lv;case Gv:var c=s&Rv;if(a||(a=Fv),i.size!=t.size&&!c)return!1;var h=o.get(i);if(h)return h==t;s|=Bv,o.set(i,t);var l=xh(a(i),a(t),s,r,n,o);return o.delete(i),l;case Uv:if(Zn)return Zn.call(i)==Zn.call(t)}return!1}var Zv=1,Jv=Object.prototype,Qv=Jv.hasOwnProperty;function ty(i,t,e,s,r,n){var o=e&Zv,a=Nn(i),c=a.length,h=Nn(t),l=h.length;if(c!=l&&!o)return!1;for(var u=c;u--;){var d=a[u];if(!(o?d in t:Qv.call(t,d)))return!1}var f=n.get(i),g=n.get(t);if(f&&g)return f==t&&g==i;var p=!0;n.set(i,t),n.set(t,i);for(var m=o;++u<c;){d=a[u];var b=i[d],T=t[d];if(s)var w=o?s(T,b,d,t,i,n):s(b,T,d,i,t,n);if(!(w===void 0?b===T||r(b,T,e,s,n):w)){p=!1;break}m||(m=d=="constructor")}if(p&&!m){var k=i.constructor,O=t.constructor;k!=O&&"constructor"in i&&"constructor"in t&&!(typeof k=="function"&&k instanceof k&&typeof O=="function"&&O instanceof O)&&(p=!1)}return n.delete(i),n.delete(t),p}var ey=1,Ch="[object Arguments]",Oh="[object Array]",wi="[object Object]",sy=Object.prototype,kh=sy.hasOwnProperty;function ry(i,t,e,s,r,n){var o=Zt(i),a=Zt(t),c=o?Oh:Xt(i),h=a?Oh:Xt(t);c=c==Ch?wi:c,h=h==Ch?wi:h;var l=c==wi,u=h==wi,d=c==h;if(d&&vi(i)){if(!vi(t))return!1;o=!0,l=!1}if(d&&!l)return n||(n=new de),o||rh(i)?xh(i,t,e,s,r,n):Kv(i,t,c,e,s,r,n);if(!(e&ey)){var f=l&&kh.call(i,"__wrapped__"),g=u&&kh.call(t,"__wrapped__");if(f||g){var p=f?i.value():i,m=g?t.value():t;return n||(n=new de),r(p,m,e,s,n)}}return d?(n||(n=new de),ty(i,t,e,s,r,n)):!1}function Mh(i,t,e,s,r){return i===t?!0:i==null||t==null||!Ce(i)&&!Ce(t)?i!==i&&t!==t:ry(i,t,e,s,Mh,r)}function iy(i,t){return i!=null&&t in Object(i)}function ny(i,t,e){t=_i(t,i);for(var s=-1,r=t.length,n=!1;++s<r;){var o=Vn(t[s]);if(!(n=i!=null&&e(i,o)))break;i=i[o]}return n||++s!=r?n:(r=i==null?0:i.length,!!r&&Wn(r)&&Rn(o,r)&&(Zt(i)||Xn(i)))}function oy(i,t){return i!=null&&ny(i,t,iy)}var Jn=function(){return Wt.Date.now()},ay="Expected a function",cy=Math.max,hy=Math.min;function ly(i,t,e){var s,r,n,o,a,c,h=0,l=!1,u=!1,d=!0;if(typeof i!="function")throw new TypeError(ay);t=Yc(t)||0,Jt(e)&&(l=!!e.leading,u="maxWait"in e,n=u?cy(Yc(e.maxWait)||0,t):n,d="trailing"in e?!!e.trailing:d);function f(x){var I=s,D=r;return s=r=void 0,h=x,o=i.apply(D,I),o}function g(x){return h=x,a=setTimeout(b,t),l?f(x):o}function p(x){var I=x-c,D=x-h,F=t-I;return u?hy(F,n-D):F}function m(x){var I=x-c,D=x-h;return c===void 0||I>=t||I<0||u&&D>=n}function b(){var x=Jn();if(m(x))return T(x);a=setTimeout(b,p(x))}function T(x){return a=void 0,d&&s?f(x):(s=r=void 0,o)}function w(){a!==void 0&&clearTimeout(a),h=0,s=c=r=a=void 0}function k(){return a===void 0?o:T(Jn())}function O(){var x=Jn(),I=m(x);if(s=arguments,r=this,c=x,I){if(a===void 0)return g(c);if(u)return clearTimeout(a),a=setTimeout(b,t),f(c)}return a===void 0&&(a=setTimeout(b,t)),o}return O.cancel=w,O.flush=k,O}function uy(i,t){return Mh(i,t)}function dy(i,t,e,s){if(!Jt(i))return i;t=_i(t,i);for(var r=-1,n=t.length,o=n-1,a=i;a!=null&&++r<n;){var c=Vn(t[r]),h=e;if(c==="__proto__"||c==="constructor"||c==="prototype")return i;if(r!=o){var l=a[c];h=void 0,h===void 0&&(h=Jt(l)?l:Rn(t[r+1])?[]:{})}Uc(a,c,h),a=a[c]}return i}function fy(i,t,e){for(var s=-1,r=t.length,n={};++s<r;){var o=t[s],a=Zp(i,o);e(a,o)&&dy(n,_i(o,i),a)}return n}function gy(i,t){return fy(i,t,function(e,s){return oy(i,s)})}var py=tm(function(i,t){return i==null?{}:gy(i,t)}),my="Expected a function";function vy(i,t,e){var s=!0,r=!0;if(typeof i!="function")throw new TypeError(my);return Jt(e)&&(s="leading"in e?!!e.leading:s,r="trailing"in e?!!e.trailing:r),ly(i,t,{leading:s,maxWait:t,trailing:r})}const yy=(i,t)=>{if(i.length!==t.length)return!1;const e=new Set(i.map(r=>r.id)),s=new Set(t.map(r=>r.id));if(e.size!==s.size)return!1;for(const r of e)if(!s.has(r))return!1;return!0},Ss=i=>{const{trackItemIds:t,transitionsMap:e,trackItemsMap:s}=i,r=new Map;Object.values(e).forEach(c=>{var u,d;if(c.kind==="none")return;const{fromId:h,toId:l}=c;r.has(h)||r.set(h,[]),r.has(l)||r.set(l,[]),(u=r.get(h))==null||u.push(c),(d=r.get(l))==null||d.push(c)});const n=[],o=new Set,a=c=>{const h=[];let l=c;for(;l&&!o.has(l);){o.add(l);const u=s[l];h.push(u);const d=Object.values(e).find(f=>f.fromId===l&&f.kind!=="none");if(!d)break;h.push(d),l=d.toId}return h};for(const c of t)if(!o.has(c)&&(!r.has(c)||!Object.values(e).some(h=>h.toId===c&&h.kind!=="none"))){const h=a(c);h.length>0&&n.push(h)}return n.forEach(c=>{c.sort((h,l)=>"display"in h&&"display"in l?h.display.from-l.display.from:0)}),n};function by(i,t,e,s,r){const n=i[0].canvas,o=Object.keys(s),a={},c=[];return i.forEach(h=>{const l=t.filter(u=>h.items.includes(u.id)).map(u=>{if(r.includes(u.id)){const d=n.getObjects().find(f=>f.id===`${u.id}-placeholder`);return(d==null?void 0:d.opacity)===1&&(u.left=(d==null?void 0:d.left)||u.left),u}else return u}).sort((u,d)=>u.left-d.left);for(let u=0;u<l.length-1;u++){const d=l[u];let f=d.left;const g=l[u+1];let p=g.left;if(o.includes(d.id)&&(f=s[d.id].left),o.includes(g.id)&&(p=s[g.id].left),Math.abs(f+d.width-p)<=1){const m=`${d.id}-${g.id}`;if(e.hasOwnProperty(m)){const T=e[m];a[m]=T}else{const T={id:m,duration:1500,fromId:d.id,toId:g.id,kind:"none",trackId:h.id,type:"transition"};a[m]=T}c.push(m)}}}),{newTransitionIds:c,newTransitionsMap:a}}const Oe=(i,t)=>{const e=t.findIndex(l=>l.id===i),s=t[e-1],r=t[e+1],n=t.filter(l=>l.type==="transition"),o=n.indexOf(s),c=n.slice(0,o).reduce((l,u)=>l+(u.duration||0),0);let h=0;return s&&!r?h=(s.duration||0)/2:r&&!s?h=(r.duration||0)/2:s&&r&&(h=(r.duration||0)/2+(s.duration||0)/2),{durationDiff:h,offsetTransitions:c}},Qn=i=>{const{trackItemIds:t,transitionsMap:e,trackItemsMap:s}=i,r=new Map;Object.values(e).forEach(h=>{var f,g;const{fromId:l,toId:u,kind:d}=h;d!=="none"&&(r.has(l)||r.set(l,[]),r.has(u)||r.set(u,[]),(f=r.get(l))==null||f.push(h),(g=r.get(u))==null||g.push(h))});const n=[],o=new Set,a=h=>{const l=[];let u=h;for(;u&&!o.has(u);){o.add(u);const d=s[u];l.push(d);const f=Object.values(e).find(g=>g.fromId===u&&g.kind!=="none");if(!f)break;l.push(f),u=f.toId}return l},c=Object.values(e).filter(h=>h.kind!=="none");for(const h of t)if(!o.has(h)&&(!r.has(h)||!c.some(l=>l.toId===h))){const l=a(h);l.length>0&&n.push(l)}return n.forEach(h=>{h.sort((l,u)=>"display"in l&&"display"in u?l.display.from-u.display.from:0)}),n};class _y{addTrackItem(t){const e=Mf(t,{tScale:this.tScale,sizesMap:this.sizesMap});this.add(e)}alignItemsToTrack(){this.pauseEventListeners();const t=new Map(this.getObjects("Track").map(r=>[r.id,r])),e=this.getTrackItems(),s=this.getObjects("Transition");this.trackItemIds.forEach(r=>{const n=this.tracks.find(c=>c.items.includes(r));if(!n)return;const o=t.get(n.id),a=this.getTrackItems().find(c=>c.id===r);a&&o&&(a.isMain=o.magnetic,this.trackItemsMap[r].isMain=o.magnetic,a.set({top:o.top}),a.setCoords())}),t.forEach(r=>{r.items=e.filter(n=>n.top===r.top).map(n=>n.id)}),s.forEach(r=>{const n=r.fromId,o=e.find(a=>a.id===n);o&&(r.set({top:o.top}),r.setCoords())}),this.resumeEventListeners()}updateTrackItemsToHistory(){this.pauseEventListeners(),this.trackItemIds.forEach(t=>{const e=this.tracks.find(c=>c.items.includes(t)),s=this.getObjects().find(c=>c.id===(e==null?void 0:e.id)).top,r=this.trackItemsMap[t],n=this.getObjects().find(c=>c.id===t),o=j(r.display.from,this.tScale),a=j(r.display.to-r.display.from,this.tScale,r.playbackRate);if(n.set({left:o,width:a,top:s}),n instanceof bt||n instanceof pt){const c=n.display.to-n.display.from;n.setDuration?n.setDuration(c):n.set({duration:c}),r.trim=n.trim,r.display=n.display}n.setCoords()}),this.requestRenderAll(),this.resumeEventListeners()}deleteTrackItemToHistory(t){this.getObjects().filter(e=>t.includes(e.id)).map(e=>this.remove(e)),this.alignItemsToTrack(),this.requestRenderAll()}uodateTrackItemIdsOrdering(){const t=this.getTrackItems();t.sort((e,s)=>e.top-s.top),this.trackItemIds=t.map(e=>e.id).reverse()}selectTrackItemByIds(t){const e=this.getActiveObjects().map(n=>n.id);if(uy(e,t))return;const r=this.getObjects(...Ic,"Transition").filter(n=>t.includes(n.id));if(!r.length)this.discardActiveObject();else if(r.length===1)this.setActiveObject(r[0]);else{const n=new Ct(r);this.setActiveObject(n)}this.requestRenderAll()}synchronizeTrackItemsState(){this.pauseEventListeners();const t=this.getTrackItems(),e={},s=Qn({trackItemIds:this.trackItemIds,transitionsMap:this.transitionsMap,trackItemsMap:this.trackItemsMap});t.forEach(r=>{const{id:n,left:o,width:a}=r,c=this.trackItemsMap[n],h=this.transitionGroups.find(l=>l.find(u=>u.id===n))||[];if(h.length===1){const l=V(o,this.tScale),u=V(a,this.tScale,r.playbackRate),d={from:l,to:l+u},f={display:d};(r instanceof bt||r instanceof pt||r instanceof Bt)&&(f.trim=r.trim,f.duration=d.to-d.from),r.display=d,e[n]={...c,...f}}else{const l=h.findIndex(f=>f.id===n),u=h[l-1],d=h[l+1];if(u&&!d){const f=Oe(n,h),g=V(o,this.tScale)+u.duration/2+f.offsetTransitions,p=V(a,this.tScale,r.playbackRate)+(u.duration||0)/2,m={from:g,to:g+p},b={display:m};(r instanceof bt||r instanceof pt||r instanceof Bt)&&(b.trim=r.trim),r.display=m,e[n]={...c,...b}}else if(d&&!u){const f=V(o,this.tScale),g=V(a,this.tScale,r.playbackRate),p={from:f,to:f+g+(d.duration||0)/2},m={display:p};(r instanceof bt||r instanceof pt||r instanceof Bt)&&(m.trim=r.trim),r.display=p,e[n]={...c,...m}}else if(u&&d){const f=V(o,this.tScale),g=s.find(O=>O.find(x=>x.id===r.id)),b=(g==null?void 0:g.filter(O=>O.type==="transition").map(O=>this.getObjects().find(x=>x.id===O.id))).filter(O=>O.top===r.top).filter(O=>O.left+O.width<=r.left).reduce((O,x)=>O+(x.duration||0),0),T=V(a,this.tScale,r.playbackRate),w={from:f+b+(u.duration||0)/2,to:f+b+T+(d.duration||0)/2+(u.duration||0)},k={display:w};(r instanceof bt||r instanceof pt||r instanceof Bt)&&(k.trim=r.trim),r.display=w,e[n]={...c,...k}}}}),this.trackItemsMap={...this.trackItemsMap,...e},this.resumeEventListeners()}deleteTrackItemById(t){const e=t,s=this.getObjects().filter(a=>t.includes(a.id)),r=ir(this.tracks,e),n={};Object.keys(this.trackItemsMap).forEach(a=>{e.includes(a)||(n[a]=this.trackItemsMap[a])});const o=this.trackItemIds.filter(a=>!e.includes(a));this.tracks=r,this.trackItemsMap=n,this.trackItemIds=o,this.discardActiveObject(),this.remove(...s),this.renderTracks(),this.alignItemsToTrack()}deleteActiveTrackItem(){const t=this.getActiveObjects();if(!t.length)return!1;const e=t.map(o=>o.id),s=ir(this.tracks,e),r={};Object.keys(this.trackItemsMap).forEach(o=>{e.includes(o)||(r[o]=this.trackItemsMap[o])});const n=this.trackItemIds.filter(o=>!e.includes(o));this.tracks=s,this.trackItemsMap=r,this.trackItemIds=n,this.discardActiveObject(),this.remove(...t),this.setActiveIds([]),this.renderTracks(),this.alignItemsToTrack(),this.updateState({updateHistory:!0,kind:"remove"})}updateTrackItemCoords(t){const e=t?this.getActiveObjects().map(s=>s.id):[];this.trackItemIds.forEach(s=>{if(e.includes(s))return;const r=this.transitionGroups.find(c=>c.find(h=>h.id===s))||[];if((r==null?void 0:r.length)===1){const c=this.getObjects().find(d=>d.id===s),h=this.trackItemsMap[s],l=j(h.display.from,this.tScale),u=j(h.display.to-h.display.from,this.tScale,h.playbackRate);c.set({left:l,width:u}),c.setCoords();return}const n=r.findIndex(c=>c.id===s),o=r[n-1],a=r[n+1];if(o&&!a){const c=this.getObjects().find(f=>f.id===s),h=this.trackItemsMap[s],l=Oe(s,r),u=j(h.display.from-(o.duration||0)/2-l.offsetTransitions,this.tScale),d=j(h.display.to-h.display.from-(o.duration||0)/2,this.tScale,h.playbackRate);c.set({left:u,width:d}),c.setCoords();return}if(a&&!o){const c=this.getObjects().find(d=>d.id===s),h=this.trackItemsMap[s],l=j(h.display.from,this.tScale),u=j(h.display.to-h.display.from-(a.duration||0)/2,this.tScale,h.playbackRate);c.set({left:l,width:u}),c.setCoords();return}if(o&&a){const c=this.getObjects().find(f=>f.id===s),h=this.trackItemsMap[s],l=Oe(s,r),u=j(h.display.from-(o.duration||0)/2-l.offsetTransitions,this.tScale),d=j(h.display.to-h.display.from-(a.duration||0)/2-(o.duration||0)/2,this.tScale,h.playbackRate);c.set({left:u,width:d}),c.setCoords();return}})}refreshTrackItemsForTransitions(){const t=this.getActiveObjects().map(h=>h.id);this.pauseEventListeners();const e=this.getObjects("Track"),s=this.getObjects("Video","Image"),r=this.getObjects("Transition"),n=s.concat(r),o=Object.keys(this.positionAfterTransform);e.forEach(h=>{o.forEach(l=>{if(h.items.includes(l)){const u=this.getObjects().find(d=>d.id===l);t.includes(l)||(this.positionAfterTransform[l].left=u.left)}})});const{newTransitionsMap:a}=by(e,s,this.transitionsMap,this.positionAfterTransform,t),c=Ss({trackItemIds:this.trackItemIds,transitionsMap:a,trackItemsMap:this.trackItemsMap});s.forEach(h=>{const l=h.id,u=c.find(m=>m.find(b=>b.id===l))||[],d=this.transitionGroups.find(m=>m.find(b=>b.id===l))||[];if(yy(d,u))return;const f=u.findIndex(m=>m.id===l),g=u[f-1],p=u[f+1];if(g&&!p){const m=Oe(l,d),b=Oe(l,u),T=j(m.durationDiff-b.durationDiff,this.tScale);h.set({width:h.width+T})}else if(p&&!g){const m=Oe(l,d),b=Oe(l,u);if(m.durationDiff>0){const T=j(m.durationDiff-b.durationDiff,this.tScale);h.set({width:h.width+T}),u.forEach(w=>{if(w.id!==h.id){const k=n.find(O=>O.id===w.id);k==null||k.set({left:k.left+T}),k==null||k.setCoords()}})}}else if(g&&p)console.warn("invalid spot");else{const m=Oe(l,d),b=j(m.durationDiff,this.tScale);h.set({width:h.width+b})}}),this.resumeEventListeners()}getTrackItems(){return this.getObjects(...Ic)}setTrackItemCoords(){this.getTrackItems().forEach(t=>{t.setCoords()})}setActiveTrackItemCoords(){this.getActiveObjects().forEach(e=>e.setCoords())}}const xs={text:32,image:40,video:40,audio:32,main:40},Dh=i=>{switch(i){case"text":return xs.text;case"image":return xs.image;case"video":return xs.video;case"audio":return xs.audio;case"helperTop":return 1e3;case"helperBottom":return 1e3;case"helperCenter":return 8;case"main":return xs.main;default:return xs.text}};class Ty{findOrCreateTrack(t,{trackId:e,trackIndex:s}){if(e){const n=this.tracks.find(o=>o.id===e);if(n)return n.items.push(t.id),e}const r={id:rr(),items:[t.id],type:t.type,accepts:this.acceptsMap[t.type],magnetic:!1,static:!1};return s!==void 0?this.tracks.splice(s,0,r):this.tracks.push(r),this.renderTracks(),r.id}removeTracks(){this.getObjects("Track","Helper").forEach(e=>this.remove(e))}renderTracks(){this.filterEmptyTracks(),this.removeTracks();const t=this.width,e=this.tracks.flatMap(a=>[a,{id:`helper-${a.id}`,type:"helper",items:[],accepts:[]}]).slice(0,-1);let s=-970;const r=C.getClass("Helper")||Ye,n=new r({top:s,selectable:!1,evented:!1,tScale:this.tScale,id:"helper-line-top",width:t,kind:"top",height:1e3,metadata:{}});s+=Dh("helperTop"),this.insertAt(0,n),e.forEach((a,c)=>{if(a.type==="helper"){const h=Dh("helperCenter"),l=new r({id:a.id,top:s,tScale:this.tScale,width:t,height:h,metadata:{order:(c+1)/2},kind:"center"});s+=h,this.insertAt(0,l)}else{const h=this.sizesMap[a.type],l=C.getClass("Track")||Kt,u=new l({id:a.id,top:s,left:0,height:h,width:t,tScale:this.tScale,accepts:this.acceptsMap[a.type]||[],items:a.items,magnetic:a.magnetic,static:a.static});s+=h,this.insertAt(0,u)}});const o=new r({id:"helper-line-bottom",top:s,selectable:!1,evented:!1,tScale:this.tScale,width:t,kind:"bottom",height:1e3,metadata:{}});this.insertAt(0,o)}filterEmptyTracks(){const t=new Set;this.tracks=this.tracks.filter(e=>(e.items.length||e.static)&&!t.has(e.id)?(t.add(e.id),!0):!1)}refreshTrackLayout(){const t=this.bounding.width+this.spacing.right;this.getObjects("Track","Helper").forEach(e=>{e.updateCoords(t),e.setCoords()})}adjustMagneticTrack(){this.pauseEventListeners();const t=this.tracks.filter(e=>e.magnetic);t.length>0&&t.forEach(e=>{const s=e.accepts||[],r=this.getObjects(...s).filter(o=>e.items.includes(o.id)).sort((o,a)=>o.left-a.left);let n=0;r.forEach(o=>{o.left=n,n+=o.width})}),this.resumeEventListeners()}}function Ih(i){const t=this,e=i.target,s=i.transform;if(s.action==="resizing"){const r=t.getObjects().filter(l=>l!==e&&!["Track","Helper","Transition","Placeholder"].includes(l.type)),n=10,o=e.left,a=e.width*e.scaleX,c=o+a;let h=!1;r.forEach(l=>{if(h)return;const u=l.getBoundingRect(),d=u.left,f=u.left+u.width;if(s.corner==="mr"){const g=Math.abs(c-f),p=Math.abs(c-d);if(g<n)if(e instanceof bt||e instanceof pt){const m=f-e.left,b=m-a,T=V(b,e.tScale,e.playbackRate),w=e.trim.to+T;w<=e.duration&&(e.set({width:m,scaleX:1}),e.trim.to=w,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({width:f-e.left,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0;else if(p<n)if(e instanceof bt||e instanceof pt){const m=d-e.left,b=m-a,T=V(b,e.tScale,e.playbackRate),w=e.trim.to+T;w<=e.duration&&(e.set({width:m,scaleX:1}),e.trim.to=w,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({width:d-e.left,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0}else if(s.corner==="ml"){const g=Math.abs(o-d),p=Math.abs(o-f);if(g<n)if(e instanceof bt||e instanceof pt||e instanceof Bt){const m=c-d,b=m-a,T=V(b,e.tScale,e.playbackRate),w=e.trim.from-T;w>=0&&(e.set({left:d,width:m,scaleX:1}),e.trim.from=w,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({left:d,width:c-d,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0;else if(p<n)if(e instanceof bt||e instanceof pt||e instanceof Bt){const m=c-f,b=m-a,T=V(b,e.tScale,e.playbackRate),w=e.trim.from-T;w>=0&&(e.set({left:f,width:m,scaleX:1}),e.trim.from=w,e.onResizeSnap&&e.onResizeSnap(),h=!0)}else e.set({left:f,width:c-f,scaleX:1}),e.onResizeSnap&&e.onResizeSnap(),h=!0}}),h&&(e.setCoords(),t.requestRenderAll())}}function Sy(i){i.on("object:resizing",Ih.bind(i))}function xy(i){i.off("object:resizing",Ih.bind(i))}const hr=100,to=0,Ci=5,jh=3,wy=25,ws={scrollInterval:null};function Eh(i){const t=wy-jh,e=(hr-i)/hr;return jh+t*e}function Cy(i,t){ws.scrollInterval&&clearInterval(ws.scrollInterval);const e=t.target,s=e.getBoundingRect();ws.scrollInterval=setInterval(()=>{const r=i.viewportTransform,n=i.getViewportPoint(t.e);if(n.x>i.width-hr&&e.left+s.width<i.bounding.width){const o=Eh(i.width-n.x);e.set("left",e.left+o),i.setViewportPos(r[4]-o,r[5])}if(n.x<hr&&e.left>0&&r[4]<hr){const o=Eh(n.x);e.set("left",e.left-o),i.setViewportPos(r[4]+o,r[5])}n.y>i.height-to&&e.top+s.height<i.bounding.height+80&&(e.set("top",e.top+Ci),i.setViewportPos(r[4],r[5]-Ci)),n.y<to&&e.top>-80&&-r[5]>to&&(e.set("top",e.top-Ci),i.setViewportPos(r[4],r[5]+Ci)),e.setCoords(),i.requestRenderAll()},16)}function Oy(){ws.scrollInterval&&(clearInterval(ws.scrollInterval),ws.scrollInterval=null)}function Ph(){Oy()}function Ah(i){Cy(this,i)}function ky(i){i.on("mouse:up",Ph),i.on("object:moving",Ah.bind(i))}function My(i){i.off("mouse:up",Ph),i.off("object:moving",Ah.bind(i))}function Lh(i){const t=i.target,e=i.target.canvas;if(i.action==="resizing"&&t instanceof Rt&&e){const s=t.id,r=e.getObjects("Transition").find(n=>n.id===s);if(r&&r instanceof Rt){const n=Qt(this.transitionsMap),o={...n,[s]:{...n[s],width:r.width,duration:r.duration}};this.transitionsMap=o,this.updateState()}}}function Dy(i){i.on("object:modified",Lh)}function Iy(i){i.off("object:modified",Lh)}const Fh={canvas:null,enableGuideRedraw:!0,isPointerOverHelperTrack:!1,draggingOverTrack:null,placeholderMovingObjects:[],primaryMovingObjects:[],secondaryMovingObjects:[],objectInitialPositions:{},originTrack:{},trackToItemsMap:{},activeTrackToItemsMap:{},trackTopToIdMap:{},trackTops:[],activeObjects:[],primaryTracks:{},secondaryTracks:{},isDragOver:!1,initialTrackPoints:[],updateItemsInTrack:null,orderNormalTrack:!1},et=()=>Fh,lt=i=>{Object.assign(Fh,i)},Rh=10,Oi=(i,t)=>{t.forEach(e=>e.isAlignmentAuxiliary&&i.remove(e))},Bh=(i,t)=>{const e=[],s=[];return t.getObjects().filter(r=>r.visible).forEach(r=>{if(i.find(o=>o.id===r.id)||r.isAlignmentAuxiliary)return;const n=r.getBoundingRect();e.push(Yh(n.left,n.width,n.top,n.height)),s.push(Yh(n.top,n.height,n.left,n.width))}),{vertical:e.flat(),horizontal:[]}},Wh=(i,t)=>{const e=[],s=[];i.vertical.forEach(a=>{t.vertical.forEach(c=>{const h=Math.abs(a.val-c.guide);h<Rh&&e.push({lineGuide:a.val,diff:h,orientation:"V",snap:c.snap,offset:c.offset,targetDim:{start:a.start,end:a.end}})})}),i.horizontal.forEach(a=>{t.horizontal.forEach(c=>{const h=Math.abs(a.val-c.guide);h<Rh&&s.push({lineGuide:a.val,diff:h,orientation:"H",snap:c.snap,offset:c.offset,targetDim:{start:a.start,end:a.end}})})});const r=[],n=e.sort((a,c)=>a.diff-c.diff)[0],o=s.sort((a,c)=>a.diff-c.diff)[0];return n&&r.push({lineGuide:n.lineGuide,offset:n.offset,orientation:"V",snap:n.snap,targetDim:n.targetDim}),o&&r.push({lineGuide:o.lineGuide,offset:o.offset,orientation:"H",snap:o.snap,targetDim:o.targetDim}),r},Xh=(i,t,e)=>{i.forEach(s=>{const r=jy(e.getZoom());s.orientation==="H"?e.add(zh([0,s.lineGuide-r.strokeWidth/2,2e3,s.lineGuide-r.strokeWidth/2],{...r,stroke:e.guideLineColor})):s.orientation==="V"&&e.add(zh([s.lineGuide-r.strokeWidth/2,0,s.lineGuide-r.strokeWidth/2,2e3],{...r,stroke:e.guideLineColor}))})},jy=i=>({strokeWidth:2/i}),zh=(i,t)=>new xe(i,{...t,strokeLineCap:"square",excludeFromExport:!0,isAlignmentAuxiliary:!0,selectable:!1,objectCaching:!1}),Hh=i=>{const t=i.getBoundingRect();return{vertical:[{guide:Math.round(t.left),offset:Math.round(i.left-t.left),snap:"start"},{guide:Math.round(t.left+t.width),offset:Math.round(i.left-t.left-t.width),snap:"end"}],horizontal:[{guide:Math.round(t.top),offset:Math.round(i.top-t.top),snap:"start"},{guide:Math.round(t.top+t.height),offset:Math.round(i.top-t.top-t.height),snap:"end"}]}},Yh=(i,t,e,s)=>[i,i+t].map(n=>({val:n,start:e,end:e+s})),Vh=(i,t)=>{i.remove(...t),t=[]},Gh=i=>{i.forEach(t=>t.setSelected(!1))},Nh=i=>i instanceof Ye,Ey=i=>Object.assign({},{left:16,right:80},i),Py=["touchstart","touchmove","touchend"],Ay=i=>Py.includes(i.type)||i.pointerType==="touch";function Uh(i){const t=this;if(!t)return;const s=et().enableGuideRedraw,r=t.getScenePoint(i.e),n=t.getObjects("Helper","Track"),o=n.find(g=>{const p=g.getBoundingRect();return r.x>=p.left&&r.x<=p.left+p.width&&r.y>=p.top&&r.y<=p.top+p.height});lt({draggingOverTrack:o}),n.forEach(g=>{Nh(g)&&(g===o?g.setSelected(!0):g.setSelected(!1))}),Nh(o)?lt({isPointerOverHelperTrack:!0}):lt({isPointerOverHelperTrack:!1});const a=t.getObjects(),c=i.target,h=c.getBoundingRect();c.setCoords();const l=[c,...t.getActiveObjects(),...t.getObjects("Track","Helper","Transition","Placeholder")],u=Bh(l,t),d=Hh(c),f=Wh(u,d);s&&(Oi(t,a),f.length&&Xh(f,h,t),lt({enableGuideRedraw:!1}),setTimeout(()=>lt({enableGuideRedraw:!0}),50)),f.forEach(g=>{g.orientation==="V"?c.left=g.lineGuide+g.offset:c.top=g.lineGuide+g.offset})}function $h(i){const t=i.target.canvas;t&&(Oi(t,t.getObjects()),Gh(t.getObjects("Helper")),lt({draggingOverTrack:null,isPointerOverHelperTrack:!1}))}function qh(i){var a;const t=this,e=t.getObjects(),s=i.target,r=i.transform,n=(a=t._currentTransform)==null?void 0:a.corner,o=s.getBoundingRect();if(r.action==="resizing"){const c=[s,...t.getActiveObjects(),...t.getObjects("Track","Helper","Transition","Placeholder")],h=Bh(c,t),l=h.vertical.filter(f=>{const g=f.val;if(n==="ml")return g<=o.left;if(n==="mr")return g>=o.left+o.width});h.vertical=l;const u=Hh(s),d=Wh(h,u);Oi(t,e),d.length&&Xh(d,o,t)}}function Ly(i){i.on("object:moving",Uh.bind(i)),i.on("object:modified",$h.bind(i)),i.on("object:resizing",qh.bind(i))}function Fy(i){i.off("object:moving",Uh.bind(i)),i.off("object:modified",$h.bind(i)),i.off("object:resizing",qh.bind(i))}function eo(i,t,e){const s=i.indexOf(t),r=i.indexOf(e);return s===-1||r===-1?null:r-s}function Kh(i,t){const e=t.sort((r,n)=>r.tempIndex-n.tempIndex),s=[];for(const r of e)r.tempIndex<0&&s.push(r);s.push(i);for(const r of e)r.tempIndex>=0&&s.push(r);return s}function Zh(i){const t=et(),e=t.canvas;lt({activeTrackToItemsMap:{},primaryTracks:{},secondaryTracks:{},trackTops:[],trackToItemsMap:{},activeObjects:[],trackTopToIdMap:{},isDragOver:!1,initialTrackPoints:[],updateItemsInTrack:null}),e.trackIdAfterTransform="",e.positionAfterTransform={};const s=e.getActiveObject(),r=s instanceof Ct?s.getObjects():[s];lt({activeObjects:r});const n=e.getScenePoint(i.e),o=e.getObjects("Track"),a=e.getActiveObjects().map(u=>u.id);let h=o.filter(u=>{const d=u.items;return a.some(f=>d.includes(f))}).find(u=>{const d=u.getBoundingRect();return n.x>=d.left&&n.x<=d.left+d.width&&n.y>=d.top&&n.y<=d.top+d.height});lt({originTrack:h});const l=e.getObjects("Video","Image","Audio","Text","Element","Template");o.forEach(u=>{const d=l.filter(f=>u.items.includes(f.id));t.trackToItemsMap[u.id]=d,t.trackTopToIdMap[u.top]=u.id,t.trackTops.push(u.top)}),t.trackTops.sort((u,d)=>u-d),r.forEach(u=>{const d=o.find(g=>g.items.includes(u.id));if(!d)return;const f=d.id;t.activeTrackToItemsMap[f]?t.activeTrackToItemsMap[f].push(u):t.activeTrackToItemsMap[f]=[u]}),t.primaryMovingObjects=r.filter(u=>{const d=u.getBoundingRect();return n.y>=d.top&&n.y<=d.top+d.height&&!(u instanceof Rt)}),t.primaryMovingObjects.length!==0&&(t.primaryMovingObjects.forEach(u=>{const d=u.getBoundingRect().top,f=t.trackTopToIdMap[d];if(t.primaryTracks[f])t.primaryTracks[f].objects.push(u);else{const g=eo(t.trackTops,h==null?void 0:h.top,d);t.primaryTracks[f]={objects:[u],index:g}}}),t.primaryMovingObjects=t.primaryMovingObjects.sort((u,d)=>u.left-d.left),t.secondaryMovingObjects=r.filter(u=>!t.primaryMovingObjects.includes(u)),t.secondaryMovingObjects.forEach(u=>{const d=u.getBoundingRect().top,f=t.trackTopToIdMap[u.getBoundingRect().top];if(t.secondaryTracks[f])t.secondaryTracks[f].objects.push(u);else{const g=eo(t.trackTops,h.top,d);t.secondaryTracks[f]={objects:[u],index:g}}}),h&&(e.trackOriginBeforeTransform=h.id),s&&(e.positionBeforeTransform={top:s.top,left:s.left}),i.transform.action==="drag"&&(t.placeholderMovingObjects=t.primaryMovingObjects.map(u=>{const d=u.getBoundingRect();t.objectInitialPositions[u.id]={top:d.top,left:d.left};const f=new ys({id:`${u.id}-placeholder`,left:d.left,top:d.top,width:d.width,height:d.height});return f.draggedObject=u,f}),e.add(...t.placeholderMovingObjects)))}function Ry(i){i.on("before:transform",Zh.bind(i))}function By(i){i.off("before:transform",Zh.bind(i))}const Rs=class Rs extends Y{constructor(e){super(e);S(this,"duration");S(this,"fromId");S(this,"toId");S(this,"itemType","none");S(this,"isSelected",!1);Object.assign(this,Rs.ownDefaults),this.id=e.id}static createControls(){return{controls:Pn()}}static getDefaults(){return{...super.getDefaults(),...Rs.ownDefaults}}updateCoords(){const e=this.canvas;if(!e)return;const s=e.getObjects().find(o=>o.id===this.fromId);if(!s)return;const r=j(this.duration,this.tScale),n=s.left+s.width-r/2;this.set({width:r,left:n})}_render(e){super._render(e),this.drawTextIdentity(e),this.updateSelected(e)}drawTextIdentity(e){const s=new Path2D("M3 5.30359C3 3.93159 4.659 3.24359 5.629 4.21359L11.997 10.5826L10.583 11.9966L5 6.41359V17.5856L10.586 11.9996L10.583 11.9966L11.997 10.5826L12 10.5856L18.371 4.21459C19.341 3.24459 21 3.93159 21 5.30359V18.6956C21 20.0676 19.341 20.7556 18.371 19.7856L12 13.5L13.414 11.9996L19 17.5866V6.41359L13.414 11.9996L13.421 12.0056L12.006 13.4206L12 13.4136L5.629 19.7846C4.659 20.7546 3 20.0676 3 18.6956V5.30359Z");e.save(),e.translate(-12,-12),e.fillStyle="#ffffff",e.fill(s),e.restore()}setSelected(e){this.isSelected=e,this.set({dirty:!0})}updateSelected(e){this.isSelected&&(e.save(),e.beginPath(),e.roundRect(-this.width/2,-this.height/2,this.width,this.height,this.rx),e.lineWidth=$t,e.strokeStyle=kt,e.stroke(),e.restore())}};S(Rs,"type","TransitionGuide"),S(Rs,"ownDefaults",{objectCaching:!1,borderColor:"transparent",stroke:"transparent",strokeWidth:1.5,fill:"rgba(0,0,0, 0.85)",borderOpacityWhenMoving:1,hoverCursor:"default",lockMovementX:!0,lockMovementY:!0,duration:1500,rx:8,ry:8});let lr=Rs;const Wy=["text","image","video","audio","caption","template"];function Jh(){const i=et();Vh(this,i.placeholderMovingObjects)}function Xy(i){const t=i.target.left;i.target.left=Math.max(t,0)}function Qh(i,t){return i.find(s=>{const r=s.getBoundingRect();return t.left<r.left+r.width&&t.left+t.width-1>r.left&&t.top<r.top+r.height&&t.top+t.height>r.top})}function zy(i,t){const s=i.canvas.getActiveObject(),r=s.left+s.width/2,n=t.left+t.width/2;return r<n?t.left-s.width:(r>n,t.left+t.width)}const Hy=(i,t,e)=>!(e<0||Qh(i,{...t.getBoundingRect(),left:e})),tl=i=>{const e=et().draggingOverTrack;return i instanceof he?e&&e.accepts.includes(i.itemType):e&&e.accepts.includes(i.type)};function Yy(i){et().isPointerOverHelperTrack?i.opacity=0:i.opacity=1}function Vy(){const i=et(),t=i.primaryMovingObjects[0];return{top:i.objectInitialPositions[t.id].top,left:i.objectInitialPositions[t.id].left}}function Gy(i){const t=i.getBoundingRect(),e=et(),s=e.draggingOverTrack;if(e.primaryMovingObjects.map(n=>n.id).includes(i.id)){const o=e.primaryMovingObjects[0].getBoundingRect();return{top:s.top,left:o.left}}return{top:s.top,left:t.left}}function Ny(i,t,e,s){const n=i.canvas.getActiveObjects().map(l=>l.id),o=zy(i,t),a=e.filter(l=>!n.includes(l.id)),c=Hy(a,i,o),h=et();if(h.orderNormalTrack=!0,!c||s.x-20<0){const l=h.draggingOverTrack;return{left:h.initialTrackPoints.reduce((d,f)=>Math.abs(f-s.x)<Math.abs(d-s.x)?f:d),top:l.top}}return{left:o,top:t.top}}const Uy=(i,t)=>{i.forEach((e,s)=>{e.set({left:t[s]})})},el=vy(i=>{const t=i.target.canvas;Xy(i);const e=et(),s=e.draggingOverTrack;if(s){const a=e.primaryMovingObjects[0];Wy.includes(a.type)&&e.placeholderMovingObjects.forEach(c=>{c.visible=!0})}else{e.placeholderMovingObjects.forEach(a=>{a.visible=!1});return}const r=e.placeholderMovingObjects.map(a=>a.draggedObject),n=(e.trackToItemsMap[s.id]||[]).filter(a=>!r.includes(a)),o=tl(e.primaryMovingObjects[0]);if(s.magnetic&&o){e.updateItemsInTrack?e.updateItemsInTrack!==s.id&&(e.updateItemsInTrack=s.id,e.initialTrackPoints=[]):(e.updateItemsInTrack=s.id,e.initialTrackPoints=[]),e.initialTrackPoints.length===0&&(e.updateItemsInTrack=s.id,e.initialTrackPoints=sl(e,s));let a=0;for(const[c,h]of e.initialTrackPoints.entries()){const l=h,u=e.initialTrackPoints[c+1],d=e.initialTrackPoints[c-1],f=u-l,g=l-d;if(!u)a=l;else if(l<=i.pointer.x&&l+f/2>=i.pointer.x){a=l;break}else if(l-g/2<=i.pointer.x&&i.pointer.x<=l){a=l;break}}e.placeholderMovingObjects.forEach(c=>{c.opacity=1,c.left=a,c.top=s.top,a+=c.width}),e.placeholderMovingObjects.forEach(c=>{const h=c.draggedObject;t.positionAfterTransform[h.id]={top:c.top,left:c.left}}),t.trackIdAfterTransform=e.trackTopToIdMap[s.top]}else{e.orderNormalTrack=!1,e.updateItemsInTrack&&e.updateItemsInTrack!==s.id&&(t.getObjects().find(f=>f.id===e.updateItemsInTrack).magnetic?$y(t,e):t.updateTrackItemCoords(!0),e.updateItemsInTrack=null,e.initialTrackPoints=[]),e.initialTrackPoints.length===0&&s instanceof Kt&&(e.updateItemsInTrack=s.id,e.initialTrackPoints=sl(e,s));const a=n.find(d=>Qh(r,d.getBoundingRect())),c=[],l=e.primaryMovingObjects.sort((d,f)=>d.left-f.left),u=l[0];l.forEach((d,f)=>{if(!l[f-1])return;const g=d.left-u.left;c.push(g)}),e.placeholderMovingObjects.forEach((d,f)=>{const g=d.draggedObject;if(g instanceof lr){d.visible=!1;return}g.setCoords(),Yy(d);let p=Jy(g,n,i.pointer,a);if(g instanceof he&&p.isInvalidDrop&&e.draggingOverTrack instanceof Kt){d.opacity=0;const m=i.pointer,b=[...t.viewportTransform],T=m.y-b[5];Zy(t,T)}else e.primaryMovingObjects.length>1?(t.trackIdAfterTransform=e.trackTopToIdMap[p.top],t.positionAfterTransform[g.id]={top:p.top,left:p.left+(c[f-1]||0)},d.left=p.left+(c[f-1]||0),d.top=p.top):(t.trackIdAfterTransform=e.trackTopToIdMap[p.top],t.positionAfterTransform[g.id]={top:p.top,left:p.left},d.left=p.left,d.top=p.top)})}}),sl=(i,t)=>{const e=i.canvas,s=[];t.items.forEach(h=>{const l=e.getObjects().find(u=>u.id===h);l&&s.push(l)});const r=i.activeObjects.map(h=>h.id),o=s.filter(h=>!r.includes(h.id)).sort((h,l)=>h.left-l.left);let a=0;const c=[];return t.magnetic?qy(o,a,c):Ky(t,c,e),c};function $y(i,t){const e=[];i.getObjects().find(a=>a.id===t.updateItemsInTrack).items.forEach(a=>{const c=i.getObjects().find(h=>h.id===a);c&&e.push(c)});const r=t.activeObjects.map(a=>a.id),o=e.filter(a=>!r.includes(a.id)).sort((a,c)=>a.left-c.left);t.initialTrackPoints.length>o.length&&Uy(o,t.initialTrackPoints)}function qy(i,t,e){var h;const s=et(),r=(h=i[0])==null?void 0:h.canvas,n=s.draggingOverTrack,o=s.primaryMovingObjects.map(l=>l.id);if(!r)return;const a=r.transitionIds.filter(l=>r.transitionsMap[l].kind!=="none");i.forEach(l=>{l.set({left:t}),t+=l.width,a.find(d=>r.transitionsMap[d].toId===l.id)||e.push(l.left)});const c=i[i.length-1];if(e.push(((c==null?void 0:c.left)||0)+((c==null?void 0:c.width)||0)),n!=null&&n.items.includes(o[0])){const l=r.getActiveObject(),u=[...e];if(l){const d=u.findIndex(f=>f>(l==null?void 0:l.left));d!==-1&&e.splice(d,0,l.left)}}}function Ky(i,t,e){const s=i.items,r={},n={},o=e.getActiveObjects().map(h=>h.id);Object.values(e.trackItemsMap).forEach(h=>{s.includes(h.id)&&(r[h.id]=h)});const a=e.getObjects("Transition").filter(h=>h.top===i.top).map(h=>h.id);Object.values(e.transitionsMap).forEach(h=>{a.includes(h.id)&&(n[h.id]=h)});const c=Qn({trackItemIds:Qt(s),transitionsMap:Qt(n),trackItemsMap:Qt(r)});t.push(0),c.forEach(h=>{if(h.length===1){const l=e.getObjects().find(u=>u.id===h[0].id);o.includes(l.id)||t.push(l.left+l.width)}else{const l=h[h.length-1],u=e.getObjects().find(d=>d.id===l.id);t.push(u.width+u.left)}})}function Zy(i,t){i.getObjects("Helper").reduce((r,n)=>Math.abs(n.top-t)<Math.abs(r.top-t)?n:r).setSelected(!0)}const Jy=(i,t,e,s)=>{const r=tl(i);return!r&&i instanceof he?{top:0,left:0,isInvalidDrop:!0}:r?s?i instanceof he?{top:0,left:0,isInvalidDrop:!0}:Ny(i,s,t,e):Gy(i):Vy()};function Qy(i){i.on("mouse:up",Jh.bind(i)),i.on("object:moving",el)}function t0(i){i.off("mouse:up",Jh.bind(i)),i.off("object:moving",el)}const e0=i=>{et().canvas.fire("track:create",i)},s0=i=>{et().canvas.fire("track-items:moved",i)},rl=i=>{var a,c,h;const t=(a=i.target)==null?void 0:a.canvas;if(!t)return;const e=et(),s=t.getActiveObject();if(!s||!t.positionBeforeTransform)return;const r=t.getScenePoint(i.e),o=t.getObjects("Track","Helper").find(l=>{const u=l.getBoundingRect();return r.x>=u.left&&r.x<=u.left+u.width&&r.y>=u.top&&r.y<=u.top+u.height});if(i.action==="resizing"){const l=(e.trackToItemsMap[(c=e.originTrack)==null?void 0:c.id]||[]).filter(d=>d!==s);s.setCoords();const u=il(l,s.getBoundingRect());return t.fire("track-items:resized",{trackId:(h=e.originTrack)==null?void 0:h.id,trackItemIds:[s.id],isOverlapped:!!u}),!1}if(!o)return s==null||s.set(t.positionBeforeTransform),s==null||s.setCoords(),!1;if(o instanceof Ye){let l;switch(o.kind){case"top":l=0;break;case"center":l=o.metadata.order||0;break;case"bottom":l=-1;break;default:return}const u={isSecondaryOverlapped:!1,secondaryTracks:e.secondaryTracks,primaryTracks:e.primaryTracks,primaryPositions:{trackIndex:l,trackId:t.trackIdAfterTransform,positions:t.positionAfterTransform}};e0(u)}else if(o instanceof Kt){const u={isSecondaryOverlapped:i0(),secondaryTracks:e.secondaryTracks,primaryTracks:e.primaryTracks,primaryPositions:{trackId:t.trackIdAfterTransform,positions:t.positionAfterTransform}};s0(u)}};function r0(){const i=et(),t=i.canvas,[e]=i.primaryMovingObjects,s=e.id,r=t.positionAfterTransform[s],n=e.getBoundingRect().top,o=r.top-n,a={};return i.secondaryMovingObjects.forEach(c=>{const h=c.getBoundingRect().top+o,l=i.trackTopToIdMap[h],u=eo(i.trackTops,i.originTrack.top,h);a[l]?a[l].objects.push(c):a[l]={objects:[c],index:u}}),a}function i0(){const i=r0(),t=et();return Object.keys(i).some(e=>{const s=t.trackToItemsMap[e],r=i[e].objects;return!s||!s.length?!0:s.filter(n=>!r.includes(n)).some(n=>il(r,n.getBoundingRect()))})}function il(i,t){return i.find(s=>{const r=s.getBoundingRect();return t.left<r.left+r.width&&t.left+t.width>r.left&&t.top<r.top+r.height&&t.top+t.height>r.top})}const n0=i=>{i.on("object:modified",rl)},o0=i=>{i.off("object:modified",rl)},so="drag",nl=`${so}:start`,ro=`${so}:end`,io="timeline",ol=`${io}:boundingChanged`,al=`${io}:seek`,a0="add:audio",c0="add:video",h0="add:image",l0="add:text",u0=["transition","image","video","audio","caption","text"];let it,ur,Cs=[];function d0(i,t){let e=1/0,s=null;const r=new _(i.x,i.y);return t.forEach(n=>{const o=Math.sqrt(Math.pow(n.left-r.x,2)+Math.pow(n.top-r.y,2));o<e&&(e=o,s=n)}),s}const f0=({width:i,height:t,id:e,left:s,top:r,type:n,duration:o})=>{if(n==="transition")return new lr({top:0,left:0,height:48,width:48,id:"TransitionGuide"});const a=C.getClass("PreviewTrackItem")||he;return new a({top:r,left:s,height:t,width:i,id:e,type:n,duration:o})};function cl(i){var f;const t=(f=i.e.dataTransfer)==null?void 0:f.types[0];if(!t)return;const e=JSON.parse(t),s=e.type;if(!u0.includes(s))return;const r=e.duration||5e3,n=this;n.discardActiveObject(),n.setActiveIds([]);const o=j(r,this.tScale),a=this.sizesMap[s];it=f0({width:o,height:a,id:"TransitionGuide",left:0,top:0,type:s,duration:r}),it.visible=!1,s==="transition"&&(Cs=n.getObjects("Transition"),Cs.forEach(g=>{g.visible=!0}));const c=et();n.trackIdAfterTransform="",n.positionAfterTransform={};const h=it,l=[it];lt({activeTrackToItemsMap:{},primaryTracks:{},secondaryTracks:{},trackTops:[],trackToItemsMap:{},activeObjects:[],trackTopToIdMap:{},isDragOver:!1}),lt({activeObjects:l});const u=n.getObjects("Track"),d=n.getTrackItems();u.forEach(g=>{const p=d.filter(m=>g.items.includes(m.id));c.trackToItemsMap[g.id]=p,c.trackTopToIdMap[g.top]=g.id,c.trackTops.push(g.top)}),c.trackTops.sort((g,p)=>g-p),c.primaryMovingObjects=l,c.primaryMovingObjects=c.primaryMovingObjects.sort((g,p)=>g.left-p.left),h&&(n.positionBeforeTransform={top:h.top,left:h.left}),c.placeholderMovingObjects=c.primaryMovingObjects.map(g=>{const p=g.getBoundingRect();c.objectInitialPositions[g.id]={top:p.top,left:p.left};const m=new ys({id:`${g.id}-placeholder`,left:p.left,top:p.top,width:p.width,height:p.height});return m.visible=!1,m.draggedObject=g,m}),n.add(...c.placeholderMovingObjects),n.add(it),J.dispatch(nl)}const hl=i=>{const t=et();Vh(i,t.placeholderMovingObjects),i&&(Oi(i,i.getObjects()),Gh(i.getObjects("Helper")))};function ll(){if(hl(this),lt({draggingOverTrack:null,isPointerOverHelperTrack:!1}),!it)return;J.dispatch(ro);const i=this;Cs.forEach(t=>{t.strokeDashArray=[],t.setSelected(!1),t.kind==="none"&&(t.visible=!1)}),i.getObjects("Helper","Track").forEach(t=>{t.setSelected&&t.setSelected(!1)}),i.remove(it)}function ul(i){const t=et(),e=t.placeholderMovingObjects[0];if(e.visible||(it.visible=!0,e.visible=!0),t.activeObjects[0]instanceof lr&&(e.visible=!1),!it)return!1;i.e.preventDefault();const s=this,r=s.getViewportPoint(i.e),n=[...this.viewportTransform];it.set({left:r.x-16-n[4],top:r.y-n[5]-it.height/2});const o=d0(r,Cs);o&&(ur=o,o.strokeDashArray=[5,1],o.setSelected(!0)),Cs.forEach(c=>{c!==o&&c.setSelected(!1)}),lt({isDragOver:!0}),it.setCoords();const a={target:it,action:"drag",originX:"center",originY:"center",offsetX:r.x-it.left,offsetY:r.y-it.top,scaleX:it.scaleX,scaleY:it.scaleY};s.fire("object:moving",{target:it,e:i.e,pointer:r,transform:a}),s.requestRenderAll()}function dl(i){var o;const t=this;hl(t);const e=et(),s=e.draggingOverTrack;lt({draggingOverTrack:null,isPointerOverHelperTrack:!1});const r=(o=i.e.dataTransfer)==null?void 0:o.types[0],n=JSON.parse(i.e.dataTransfer.getData(r));if(n.type!=="transition"){const a=e.activeObjects[0],c=V(a.left,t.tScale);if(s instanceof Kt)if(e.placeholderMovingObjects[0].opacity!==0){const l=no(s,this.getObjects("Track"));if(s.magnetic){const u=e.initialTrackPoints[e.initialTrackPoints.length-1],d=V(u,t.tScale);ki(n,l,d)}else ki(n,l,c)}else{const l=i.viewportPoint,u=[...t.viewportTransform],d=l.y-u[5],g=t.getObjects("Helper").reduce((m,b)=>Math.abs(b.top-d)<Math.abs(m.top-d)?b:m),p=no(g,this.getObjects("Track"));ki(n,p,c,!0)}else{const h=no(s,this.getObjects("Track"));ki(n,h,c,!0)}this.remove(a),this.requestRenderAll();return}if(it){if(ur){const a=ur.id,c=py(n,["kind","direction"]);Object.keys(c).forEach(T=>{T==="kind"?ur.kind=c[T]:ur[T]=c[T]});const h=Qt(this.trackItemIds),l=Qt(this.transitionsMap),u=Qt(this.trackItemsMap);l[a]={...l[a],...c};const d=Ss({trackItemIds:h,transitionsMap:l,trackItemsMap:u}),g=l[a].fromId,p=d.find(T=>T.find(w=>w.id===g))||[],m=g0(p),b=p0(this.trackItemsMap,m);this.trackItemsMap=b,this.transitionsMap[a]={...this.transitionsMap[a],...c},this.transitionGroups=Ss({trackItemIds:this.trackItemIds,transitionsMap:this.transitionsMap,trackItemsMap:this.trackItemsMap}),this.updateTrackItemCoords(),this.adjustMagneticTrack(),this.calcBounding(),this.updateTransitions(),this.refreshTrackLayout(),this.updateState({kind:"add:transition",updateHistory:!0})}Cs.forEach(a=>{a.strokeDashArray=[],a.setSelected(!1),a.kind==="none"&&(a.visible=!1)}),t.remove(it),t.requestRenderAll(),J.dispatch(ro)}}const g0=i=>{const[t]=i,e=i.filter(r=>r.type!=="transition");let s=t.display.from;return e.map(r=>{const n=r.display.to-r.display.from,o={from:s,to:s+n};return s=o.to,{...r,display:o}})},p0=(i,t)=>{let e=i;return t.forEach(s=>{e[s.id]=s}),e},no=(i,t)=>{const e=t.sort((o,a)=>o.top-a.top);if(e.length===0)return 0;const s=e[e.length-1];if(s.top+s.height<=i.top)return e.length;const r=i.top;return e.reduce((o,a,c)=>{const h=Math.abs(a.top-r),l=Math.abs(e[o].top-r);return h<l?c:o},0)},ki=(i,t,e,s)=>{i.type==="image"?J.dispatch(h0,{payload:{...i,id:ps(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}}):i.type==="video"?J.dispatch(c0,{payload:{...i,id:ps(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}}):i.type==="audio"?J.dispatch(a0,{payload:{...i,id:ps(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}}):i.type==="text"&&J.dispatch(l0,{payload:{...i,id:ps(),display:{from:e}},options:{trackIndex:t,isNewTrack:s}})};function m0(i){i.on("dragover",ul),i.on("dragenter",cl),i.on("dragleave",ll),i.on("drop",dl)}function v0(i){i.off("dragover",ul),i.off("dragenter",cl),i.off("dragleave",ll),i.off("drop",dl)}function fl(i){const t=this.height<this.bounding.height;if(!(this.width<this.bounding.width)&&!t)return;const s=this.viewportTransform;let r=s[4],n=s[5];const o=2;i.e.shiftKey?r=r-i.e.deltaY*o:(t&&(n=n-i.e.deltaY*o),r=r-i.e.deltaX*o),this.setViewportPos(r,n)}function gl(){const i=this,t=i.getActiveObject(),e=i.getActiveObjects(),s=e.map(n=>n.id),r=e.filter(n=>{if(e.length===1)return!0;if(n.id&&!(n instanceof Rt))return!0;if(n instanceof Rt&&s.includes(n.fromId)&&s.includes(n.toId))return!0}).map(n=>n.id);t instanceof Ct?(t.borderColor="rgba(0, 216, 214,0.75)",t.hasControls=!1,t.hoverCursor="default",t.borderScaleFactor=1,t.padding=0,t.getObjects().forEach(n=>{n.setSelected(!0)})):t==null||t.setSelected(!0),this.setActiveIds(r)}function pl(i){const t=this,e=t.getActiveObject();e instanceof Ct&&(e.borderColor="transparent",e.hasControls=!1,e.hoverCursor="default"),i.selected.forEach(n=>{n.setSelected(!0)}),i.deselected.forEach(n=>{n.setSelected(!1)});const r=t.getActiveObjects().map(n=>n.id);this.setActiveIds(r)}function ml(i){i.deselected.forEach(t=>{t.setSelected(!1)})}const y0=i=>{i.on("selection:created",gl),i.on("selection:updated",pl),i.on("selection:cleared",ml),i.on("mouse:wheel",fl)},b0=i=>{i.off("mouse:wheel",fl),i.off("selection:created",gl),i.off("selection:updated",pl),i.off("selection:cleared",ml)},vl=()=>{var n,o;const i=et(),t=i.canvas,e=i.draggingOverTrack;t.updateTrackItemCoords(!0);const s=e==null?void 0:e.magnetic,r=new Set(i.activeObjects.map(a=>a.id));if(s){const a=e.id,h=i.trackToItemsMap[a].sort((p,m)=>p.left-m.left),l=i.placeholderMovingObjects,u=((n=l[0])==null?void 0:n.top)||0,d=l.reduce((p,m)=>p+m.width,0),f=Math.min(...l.map(p=>p.left));let g=0;h.forEach(p=>{r.has(p.id)||p.top===u&&(Math.abs(f-g)<1&&(g+=d),p.left=g,g+=p.width)})}else if(e instanceof Kt&&i.orderNormalTrack){const a=e.items,c=t.getTrackItems().filter(x=>!r.has(x.id)&&a.includes(x.id)),h=c.sort((x,I)=>x.left-I.left),l=i.placeholderMovingObjects[0],u=i.placeholderMovingObjects[i.placeholderMovingObjects.length-1],d=l.left,f=u.left-l.left+u.width,g=h.find((x,I)=>{if(x.left>=d-1)return h[I]}),p=j(((o=g==null?void 0:g.display)==null?void 0:o.from)||0,t.tScale),m=c.map(x=>x.id),b={},T={};Object.values(t.trackItemsMap).forEach(x=>{m.includes(x.id)&&(b[x.id]=x)});const w=t.getObjects("Transition").filter(x=>x.top===c[0].top).map(x=>x.id);Object.values(t.transitionsMap).forEach(x=>{w.includes(x.id)&&(T[x.id]=x)});const k=Qn({trackItemIds:Qt(c.map(x=>x.id)),transitionsMap:Qt(T),trackItemsMap:Qt(b)});c.filter(x=>x.left>=d-1).forEach(x=>{const I=j(x.display.from,t.tScale),D=Object.values(t.transitionsMap).find(X=>X.kind!=="none"&&X.toId===x.id);let F=0;k.forEach(X=>{if(X.map(W=>W==null?void 0:W.id).includes(x.id)){for(const W of X)if(W.type==="transition")if((D==null?void 0:D.id)===W.id){F=F+j(W.duration,t.tScale)/2;break}else F=F+j(W.duration,t.tScale);else if(W.id===x.id)break}}),p<=d+f&&(x.left=I+f-F+d-p)})}t.alignTransitionsToTrack(!1)};function _0(i){i.on("object:moving",vl)}function T0(i){i.off("object:moving",vl)}const S0=i=>{lt({canvas:i}),ky(i),Sy(i),Dy(i),Ly(i),Ry(i),Qy(i),n0(i),m0(i),y0(i),_0(i)},x0=i=>{lt({canvas:null}),My(i),xy(i),Iy(i),Fy(i),By(i),t0(i),o0(i),v0(i),b0(i),T0(i)};class w0{removeTransitions(){const t=this.getObjects("Transition");this.remove(...t)}renderTransitions(){this.removeTransitions(),this.transitionIds.forEach(t=>{const e=this.transitionsMap[t],s=e.fromId,r=e.toId,n=this.getObjects(),o=n.find(d=>d.id===s),a=n.find(d=>d.id===r);if(!o||!a)return;const c=j(e.duration,this.tScale),h=o.left+o.width-c/2,l=o.height,u=new Rt({id:e.id,left:h,top:o.top,height:l,width:c,tScale:this.tScale,duration:e.duration,fromId:o.id,toId:a.id,kind:e.kind});e.kind==="none"&&(u.visible=!1),u&&this.add(u)})}updateTrackTransitionsItemCoords(){this.pauseEventListeners(),this.getObjects("Transition").forEach(e=>{e.tScale=this.tScale,e.updateCoords(),e.setCoords()}),this.resumeEventListeners()}alignTransitionsToTrack(t=!0){const e=t?[]:this.getActiveObjects().map(s=>s.id);this.transitionIds.forEach(s=>{const r=this.getObjects("Transition").find(n=>n.id===s);if(r instanceof Rt){const n=this.getObjects().find(c=>c.id===r.fromId&&!e.includes(c.id));if(!n)return;const o=j(r.duration,this.tScale),a=n.left+n.width-o/2;r.set({left:a,top:n.top}),r.setCoords()}})}updateTransitions(t=!0){t&&this.pauseEventListeners();const e=this.getObjects("Track"),s=this.getObjects("Video","Image");this.removeTransitions();const r={},n=[];e.forEach(a=>{const c=s.filter(h=>a.items.includes(h.id)).sort((h,l)=>h.left-l.left);for(let h=0;h<c.length-1;h++){const l=c[h],u=c[h+1];if(Math.abs(l.left+l.width-u.left)<=1){const d=`${l.id}-${u.id}`;if(this.transitionIds.includes(d)){const g=this.transitionsMap[d];r[d]=g}else{const g={id:d,duration:1500,fromId:l.id,toId:u.id,kind:"none",trackId:a.id,type:"transition"};r[d]=g}n.push(d)}}}),this.transitionIds=n,this.transitionsMap=r,this.renderTransitions();const o=this.getObjects("Transition");this.updateCachingActiveObjects(o),this.transitionGroups=Ss({trackItemIds:this.trackItemIds,transitionsMap:this.transitionsMap,trackItemsMap:this.trackItemsMap}),t&&this.resumeEventListeners()}}function yl(i){const{secondaryTracks:t,primaryTracks:e,primaryPositions:s}=i,{positions:r,trackIndex:n}=s,o=n===-1?this.tracks.length:n,[a]=Object.keys(e),c=this.tracks.find(p=>p.id===a),h=e[a],l={id:ps(),items:h.objects.map(p=>p.id),type:c.type,accepts:c.accepts},u=Gn(Object.keys(t).map(p=>t[p].objects.map(m=>m.id)));let d=ir(this.tracks,[...Object.keys(r),...u]);const f=[];Object.keys(t).forEach(p=>{const{objects:m,index:b}=t[p],T=this.tracks.find(O=>O.id===p),w=m.map(O=>O.id).filter(O=>!this.transitionIds.includes(O)),k={id:rr(),items:w,type:T.type,accepts:T.accepts,tempIndex:b};f.push(k)});const g=Kh(l,f);g.length&&d.splice(o,0,...g),this.tracks=d,this.renderTracks(),this.refreshTrackLayout(),this.alignItemsToTrack(),this.uodateTrackItemIdsOrdering(),this.refreshTrackItemsForTransitions(),this.adjustMagneticTrack(),this.updateTransitions(!0),this.updateState({updateHistory:!0,kind:"update"})}function bl(i){const{isSecondaryOverlapped:t,secondaryTracks:e,primaryTracks:s,primaryPositions:r}=i,{trackId:n,positions:o}=r,a=this.tracks.find(b=>b.id===n),l=et().primaryMovingObjects.sort((b,T)=>b.left-T.left);l.forEach((b,T)=>{l[T-1]&&b.left-l[T-1].left});const u=this.tracks.findIndex(b=>b.id===n),d=Gn(Object.keys(e).map(b=>e[b].objects.map(T=>T.id)));let f=ir(this.tracks,[...Object.keys(o),...d]);Object.keys(s).forEach(b=>{this.pauseEventListeners();const{objects:T}=s[b];T.forEach(O=>{if(O.isMain&&(a!=null&&a.magnetic))return;const x=o[O.id];O.left=x==null?void 0:x.left}),this.resumeEventListeners();const w=r.trackId,k=f.find(O=>O.id===w);k==null||k.items.push(...Object.keys(o)),this.tracks=f});const g=this.tracks[u],p=[];Object.keys(e).forEach(b=>{const{objects:T,index:w}=e[b],k=T.filter(I=>I.type!=="transition").map(I=>I.id),[O]=k,x=this.trackItemsMap[O];if(t&&x){const I={id:rr(),items:k,type:x.type,accepts:this.acceptsMap[x.type],tempIndex:w};p.push(I)}else{const I=f[u+w];I==null||I.items.push(...k),this.tracks=f}});const m=Kh(g,p);m.length&&f.splice(u,1,...m),this.tracks=f,this.renderTracks(),this.alignItemsToTrack(),this.uodateTrackItemIdsOrdering(),this.refreshTrackItemsForTransitions(),this.adjustMagneticTrack(),this.updateTransitions(!0),this.updateState({updateHistory:!0,kind:"update"})}function _l({trackItemIds:i,isOverlapped:t}){const[e]=i;if(!e)return;if(!this.getObjects("Transition").find(r=>r.id===e)){const r=this.tracks.find(n=>n.items.includes(e));if(t){const n=ir(this.tracks,i),o={id:rr(),items:[e],type:r.type,accepts:r.accepts},a=this.tracks.findIndex(c=>c.id===r.id);n.splice(a,0,o),this.tracks=n}}this.renderTracks(),this.alignItemsToTrack(),this.refreshTrackItemsForTransitions(),this.adjustMagneticTrack(),this.updateTransitions(!0),this.uodateTrackItemIdsOrdering(),this.updateState({updateHistory:!0,kind:"update"})}let oo={x:0,y:0};function C0(i){oo=i.scenePoint}function Tl(i){const t=i.scenePoint;if((oo.x===t.x||oo.y===t.y)&&!i.target){const s=this.getElement().getBoundingClientRect(),r=this.viewportTransform,n=i.e.clientX-s.left-r[4],o=V(n,this.scale.zoom);J.dispatch(al,{payload:{time:o}})}}const O0=i=>{i.on("track:create",yl.bind(i)),i.on("track-items:resized",_l.bind(i)),i.on("track-items:moved",bl.bind(i)),i.on("mouse:up",Tl.bind(i)),i.on("mouse:down",C0.bind(i))};function k0(i){i.off("track:create",yl.bind(i)),i.off("track-items:resized",_l.bind(i)),i.off("track-items:moved",bl.bind(i)),i.off("mouse:up",Tl.bind(i))}function M0(i,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(i.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),i}const Sl={video:["*"],image:["*"],audio:["*"],text:["*"],caption:["*"],template:["*"]},xl={video:42,image:42,audio:42,text:42,caption:42,template:42},D0=["video","image","audio","text","caption","template"],I0=(i={})=>{const t=Object.assign({},Sl,i),e={};return Object.keys(t).forEach(s=>{const r=t[s];e[s]=r.includes("*")?D0:r}),e},j0=(i={})=>{const t=Object.assign({},xl,i),e={};return i?(Object.keys(t).forEach(s=>{const r=t[s];e[s]=r}),e):t};let wl,Cl,Ol,kl,Ml,Dl,Il,jl;const E0=i=>{wl=i.state.subscribeToActiveIds(({activeIds:t})=>{const e=i.activeIds;if(t.length===1&&e.length===1){const s=t[0],r=e[0],o=i.state.getState().structure;let a="";if(o.forEach(c=>{c.id===r&&c.items.includes(s)&&(a=c.id)}),a!=="")return;i.selectTrackItemByIds([s])}else i.selectTrackItemByIds(t)}),jl=i.state.subscribeToTracks(({tracks:t,changedTracks:e})=>{e.length&&(i.tracks=t,i.renderTracks(),i.refreshTrackLayout())}),Il=i.state.subscribeToUpdateAnimations(({trackItemsMap:t,changedAnimationIds:e})=>{if(e!=null&&e.length){const s=i.getTrackItems();i.trackItemsMap=t,s.forEach(r=>{if(e.includes(r.id)){const n=t[r.id].animations;n&&r.set({animations:n})}})}}),Dl=i.state.subscribeToUpdateTrackItemTiming(({trackItemsMap:t,changedTrimIds:e,changedDisplayIds:s})=>{if(e&&i.getTrackItems().forEach(n=>{if(e.includes(n.id)){const o=t[n.id].trim;o&&n.set({trim:{from:o.from,to:o.to}})}}),s){const r=i.getTrackItems();i.pauseEventListeners(),r.forEach(n=>{if(s.includes(n.id)){const o=t[n.id].display;o&&n.set({display:o})}}),i.resumeEventListeners()}i.requestRenderAll()}),Ml=i.state.subscribeToScale(t=>{i.setScale(t.scale)}),kl=i.state.subscribeToUpdateItemDetails(t=>{const e=i.getTrackItems();if(e.length===0)return;const s=i.state.getState(),r=t.trackItemDetailsMap,n=s.trackItemsMap;e.forEach(o=>{const a=r[o.id];if(a)if(o instanceof bt||o instanceof ms||o instanceof pt){if(a.type==="video"||a.type==="image"||a.type==="audio"){const c=n[o.id];if(o.src!==a.details.src&&o.setSrc&&o.setSrc(a.details.src),a.type==="video"||a.type==="audio"){const l=c.display.to-c.display.from,u=j(l,i.scale.zoom,c.playbackRate);o.set({duration:c.duration,display:c.display,trim:c.trim,width:u}),o.setCoords()}}}else(o instanceof vs||o instanceof bs)&&(a.type==="text"||a.type==="caption")&&o.set({text:a.details.text})}),i.requestRenderAll()}),Ol=i.state.subscribeToHistory(t=>{i.tracks=t.tracks,i.trackItemsMap=t.trackItemsMap,i.trackItemIds=t.trackItemIds,i.trackItemDetailsMap=t.trackItemDetailsMap,i.transitionIds=t.transitionIds,i.transitionsMap=t.transitionsMap,i.transitionGroups=Ss({trackItemIds:i.trackItemIds,transitionsMap:i.transitionsMap,trackItemsMap:i.trackItemsMap}),i.renderTracks(),i.refreshTrackLayout(),i.updateTrackItemCoords(),i.alignItemsToTrack(),i.alignTransitionsToTrack(),i.adjustMagneticTrack(),i.updateTransitions(),i.calcBounding(),i.duration=In(i.trackItemsMap)}),Cl=i.state.subscribeToAddOrRemoveItems(()=>{const t=i.getTrackItems().map(n=>n.id),e=i.state.getState(),s=e.trackItemIds,r=[];t.forEach(n=>{s.includes(n)||r.push(n)}),i.deleteTrackItemById(r),i.tracks=e.tracks,i.trackItemsMap=e.trackItemsMap,i.trackItemDetailsMap=e.trackItemDetailsMap,i.transitionIds=e.transitionIds,i.transitionsMap=e.transitionsMap,s.forEach(n=>{if(!t.includes(n)){const a={...e.trackItemsMap[n],details:{...e.trackItemDetailsMap[n].details}};i.addTrackItem(a)}}),i.trackItemIds=e.trackItemIds,i.activeIds=e.activeIds,i.transitionGroups=Ss({trackItemIds:i.trackItemIds,transitionsMap:i.transitionsMap,trackItemsMap:i.trackItemsMap}),i.renderTracks(),i.alignItemsToTrack(),i.updateTrackItemCoords(),i.calcBounding(),i.updateTransitions(),i.refreshTrackLayout(),i.selectTrackItemByIds(e.activeIds)})},P0=i=>{wl.unsubscribe(),Cl.unsubscribe(),Ol.unsubscribe(),kl.unsubscribe(),Ml.unsubscribe(),Dl.unsubscribe(),Il.unsubscribe(),jl.unsubscribe()},El=(i,t)=>{let e=!1;const s=[];return t.forEach(r=>{r.containsPoint(i)&&(s.push(r),e=!0)}),{isOverObject:e,overObjects:s}};function A0(i){return JSON.parse(JSON.stringify(i))}class Pl extends _n{constructor(e,s){var r;super(e,s);S(this,"acceptsMap");S(this,"sizesMap",{});S(this,"tracks",[]);S(this,"trackItemsMap",{});S(this,"trackItemIds",[]);S(this,"transitionIds",[]);S(this,"transitionsMap",{});S(this,"trackItemDetailsMap",{});S(this,"scale");S(this,"duration");S(this,"bounding");S(this,"onScroll");S(this,"onResizeCanvas");S(this,"tScale");S(this,"state");S(this,"activeIds",[]);S(this,"spacing");S(this,"guideLineColor");S(this,"transitionGroups",[]);this.bounding=s.bounding||{width:s.width||0,height:s.height||0},this.tScale=((r=s.scale)==null?void 0:r.zoom)||1,this.state=s.state,this.onScroll=s.onScroll,this.onResizeCanvas=s.onResizeCanvas,this.acceptsMap=I0(s.acceptsMap),this.sizesMap=j0(s.sizesMap),this.spacing=Ey(s.spacing),this.positionAfterTransform={},this.initializeCanvasDefaults(),this.scale=s.scale,this.duration=s.duration,this.guideLineColor=s.guideLineColor||kt,this.initEventListeners()}static registerItems(e){Object.keys(e).forEach(s=>{C.setClass(e[s],s)})}initializeCanvasDefaults(){const e=this.viewportTransform;e[4]=this.spacing.left,Object.assign(at.ownDefaults,{borderColor:"transparent",cornerColor:"white",cornerStrokeColor:"transparent",strokeWidth:0,borderOpacityWhenMoving:1,borderScaleFactor:1,cornerSize:8,cornerStyle:"rect",centeredScaling:!1,centeredRotation:!0,transparentCorners:!1})}__onMouseDown(e){const s=this.getScenePoint(e),r=this._activeObject,n=this.getActiveObjects();if(n.length===0){super.__onMouseDown(e);return}const{isOverObject:o}=El(s,n);if(r&&(r==null?void 0:r.findControl(this.getViewportPoint(e),Ay(e)))){super.__onMouseDown(e);return}const a=this.getTrackItems(),c=this.getObjects("Transition"),{isOverObject:h,overObjects:l}=El(s,[...c,...a]);h?o?super.__onMouseDown(e):(this.setActiveIds([l[0].id]),super.__onMouseDown(e)):(this.discardActiveObject(),this.requestRenderAll(),this.setActiveIds([]),this._groupSelector={x:s.x,y:s.y,deltaY:0,deltaX:0},super.__onMouseDown(e))}initEventListeners(){O0(this),S0(this),E0(this)}setActiveIds(e){this.activeIds=e,this.state.updateState({activeIds:A0(this.activeIds)},{kind:"layer:selection",updateHistory:!1})}updateState(e={updateHistory:!1}){this.filterEmptyTracks(),this.synchronizeTrackItemsState(),this.requestRenderAll(),this.duration=this.getDurationBasedOnTrackItemsPosition(),this.calcBounding(),this.refreshTrackLayout(),this.setTrackItemCoords();const s=this.getUpdatedState();this.state.updateState(s,e)}getUpdatedState(){const e=this.getDurationBasedOnTrackItemsPosition();return{tracks:this.tracks,trackItemIds:this.trackItemIds,trackItemsMap:this.trackItemsMap,transitionIds:this.transitionIds,transitionsMap:this.transitionsMap,scale:this.scale,duration:e}}getDurationBasedOnTrackItemsPosition(){const e=this.getTrackItems().map(n=>n.getBoundingRect()),s=e.reduce((n,o)=>n.left+n.width<o.left+o.width?o:n,e[0]),r=s.left+s.width;return V(r,this.tScale)}notify(e={updateHistory:!1}){const s=this.getUpdatedState();this.state.updateState(s,e)}getState(){const e=In(this.trackItemsMap);return{tracks:this.tracks,trackItemIds:this.trackItemIds,trackItemsMap:this.trackItemsMap,transitionIds:this.transitionIds,transitionsMap:this.transitionsMap,trackItemDetailsMap:this.trackItemDetailsMap,scale:this.scale,duration:e}}purge(){x0(this),k0(this),P0(),this.dispose()}scrollTo({scrollLeft:e,scrollTop:s}){var o;const r=[...this.viewportTransform];let n=!1;typeof e=="number"&&(r[4]=-e+this.spacing.left,n=!0),typeof s=="number"&&(r[5]=-s,n=!0),n&&(this.viewportTransform=r,(o=this.getActiveObject())==null||o.setCoords(),this.requestRenderAll())}setBounding(e){this.bounding=e}calcBounding(){const e=this.getObjects("Track").filter(c=>c.static),s=[...this.getTrackItems(),...e].reduce((c,h)=>{const{top:l,height:u}=h.getBoundingRect();return{top:Math.min(c.top,l),height:Math.max(c.height,l+u)}},{top:1/0,height:0}),r=[...this.getTrackItems()].reduce((c,h)=>{const{left:l,width:u}=h.getBoundingRect();return{left:Math.min(c.left,l),width:Math.max(c.width,l+u)}},{left:1/0,width:this.width}),n=this.bounding.width,o=r.width,a=o-n;if(a<0){const c=this.getTrackItems(),h=this.getElement().clientWidth,l=c.reduce((u,d)=>d.left+d.width>u.left+u.width?d:u,c[0]);Math.abs(a)>h?this.setViewportPos(-(o-h)-this.spacing.right,this.viewportTransform[5]):l.left+l.width<=h?this.setViewportPos(16,this.viewportTransform[5]):this.setViewportPos(this.viewportTransform[4]-a,this.viewportTransform[5])}this.bounding={...s,...r},J.dispatch(ol,{payload:{bounding:{...s,...r}}})}setViewportPos(e,s){var o;const r=this.getViewportPos(e,s),n=this.viewportTransform;n[4]=r.x,n[5]=r.y,this.requestRenderAll(),this.setActiveTrackItemCoords(),(o=this.onScroll)==null||o.call(this,{scrollTop:r.y,scrollLeft:r.x-this.spacing.left})}getViewportPos(e,s){const r=this,n=this.bounding.width-100>=r.width?this.spacing.right:0,o=r.width-this.bounding.width-n,a=this.spacing.left,c=Math.max(o,Math.min(e,a));if(this.bounding.height<this.height)return{x:c,y:0};const h=r.height-this.bounding.height-40,u=Math.max(h,Math.min(s,0));return{x:c,y:u}}setScale(e){this.pauseEventListeners(),this.tScale=e.zoom,this.scale=e,this.getObjects("Video","Image","Text","Audio","Caption","Template").forEach(r=>{const n=this.transitionGroups.find(o=>o.find(a=>a.id===r.id))||[];if((n==null?void 0:n.length)===1){const o=j(r.display.from,this.tScale),a=j(r.display.to-r.display.from,this.tScale,r.playbackRate);r.set({left:o,width:a,tScale:e.zoom})}else{const o=n.findIndex(u=>u.id===r.id),a=n[o-1],c=n[o+1],h=n.filter(u=>u.type==="transition"),l=this.trackItemsMap[r.id];if(a&&!c){const u=h.indexOf(a),f=h.slice(0,u).reduce((m,b)=>m+(b.duration||0),0),g=j(l.display.from-(a.duration||0)/2-f,this.tScale),p=j(l.display.to-l.display.from-(a.duration||0)/2,this.tScale,l.playbackRate);r.set({left:g,width:p,tScale:e.zoom})}else if(c&&!a){const u=j(l.display.from,this.tScale),d=j(l.display.to-l.display.from-(c.duration||0)/2,this.tScale,l.playbackRate);r.set({left:u,width:d,tScale:e.zoom})}else if(a&&c){const u=j(l.display.from-(a.duration||0)/2,this.tScale),d=j(l.display.to-l.display.from-(c.duration||0)/2-(a.duration||0)/2,this.tScale,r.playbackRate);r.set({left:u,width:d,tScale:e.zoom})}}r.onScale&&r.onScale(),r.setCoords()}),this.requestRenderAll(),this.calcBounding(),this.refreshTrackLayout(),this.updateTransitions(!1),this.resumeEventListeners()}}M0(Pl,[_f,Ty,_y,w0]);const L0={audio:jn,media:An,common:fi,transition:En};M.ACCEPTS_MAP=Sl,M.Audio=pt,M.BOTTOM=Qd,M.CENTER=we,M.Caption=bs,M.Control=$,M.DRAG_END=ro,M.DRAG_PREFIX=so,M.DRAG_START=nl,M.FabricObject=at,M.Helper=Ye,M.Image=ms,M.LEFT=ds,M.NONE=tf,M.Pattern=Hr,M.Placeholder=ys,M.PreviewTrackItem=he,M.RIGHT=fs,M.Rect=Y,M.SIZES_MAP=xl,M.TIMELINE_BOUNDING_CHANGED=ol,M.TIMELINE_PREFIX=io,M.TIMELINE_SEEK=al,M.TOP=Jd,M.Template=Bt,M.Text=vs,M.Track=Kt,M.Transition=Rt,M.Video=bt,M.calculateTimelineWidth=sf,M.changeWidth=fi,M.classRegistry=C,M.controlsUtils=ze,M.createAudioControls=Ac,M.createMediaControls=Lc,M.createResizeControls=sr,M.createTemplateControls=Pc,M.createTransitionControls=Pn,M.default=Pl,M.drawVerticalLine=Ft,M.generateId=ps,M.getDuration=In,M.isTransformCentered=gs,M.resize=L0,M.resolveOrigin=A,M.timeMsToUnits=j,M.unitsToTimeMs=V,M.util=rc,M.wrapWithFixedAnchor=er,Object.defineProperties(M,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|