@linker-design-plus/timeline-track 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +3 -3
- package/dist/index.es.js +1348 -1387
- package/dist/{components → src/components}/Clip.d.ts +0 -13
- package/dist/{components → src/components}/Timeline.d.ts +2 -0
- package/dist/{core → src/core}/constants.d.ts +1 -0
- package/dist/{core → src/core}/timelineManager.d.ts +11 -0
- package/dist/{core → src/core}/types.d.ts +1 -0
- package/package.json +1 -1
- /package/dist/{components → src/components}/Playhead.d.ts +0 -0
- /package/dist/{components → src/components}/VideoTrack.d.ts +0 -0
- /package/dist/{core → src/core}/history.d.ts +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{utils → src/utils}/KonvaUtils.d.ts +0 -0
- /package/dist/{utils → src/utils}/Logger.d.ts +0 -0
- /package/dist/{utils → src/utils}/timeUtils.d.ts +0 -0
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Ji=Object.defineProperty;var Qi=(a,t,e)=>t in a?Ji(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var A=(a,t,e)=>Qi(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe={background:"#000000",border:"#333333",timeTick:"#666666",timeText:"#aaaaaa",trackBackground:"#000000",trackBorder:"#444444",clipBackground:"#1D2129",clipBorder:"#000000",clipName:"#ffffff",clipDuration:"#cccccc",clipHandle:"#ffffff",clipSelectedBackground:"#b5baff",clipSelectedBorder:"#50e3c2",clipSelectedName:"#ffffff",clipSelectedDuration:"#ffffff",clipSelectedHandle:"#ffffff",clipSelectedCoverBackground:"#444444",clipCoverBackground:"#333333",playhead:"#ffffff",grid:"#333333"};class X{static msToSeconds(t){return t/1e3}static secondsToMs(t){return t*1e3}static timeToPixels(t,e){return this.msToSeconds(t)*e}static pixelsToTime(t,e){return this.secondsToMs(t/e)}static formatTime(t){const e=t/1e3,i=Math.floor(e/60),s=Math.floor(e%60),n=Math.floor(t%1e3/10);return`${i.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}.${n.toString().padStart(2,"0")}`}static diffTime(t,e){return Math.abs(t-e)}static isTimeInRange(t,e,i){return t>=e&&t<=i}static clampTime(t,e,i){return Math.max(e,Math.min(i,t))}static calculateEndTime(t,e){return t+e}static getTickConfig(t){let e,i;return t>=1e3?(e=1,i=.1):t>=500?(e=1,i=.5):t>=100?(e=1,i=1):t>=50?(e=5,i=1):t>=10?(e=10,i=2):t>=5?(e=60,i=10):(e=300,i=60),{majorStep:e,minorStep:i}}static generateTimeTicks(t,e=1){const i=[],s=this.msToSeconds(t);for(let n=0;n<=s;n+=e)i.push(this.secondsToMs(n));return i}static generateVisibleTicks(t,e,i,s){const n=[],r=Math.max(0,t);let o=Math.floor(r/i)*i,h=0;const l=100;for(let p=o;p<=e&&(n.push({time:this.secondsToMs(p),type:this.TICK_TYPE_MAJOR}),h++,!(h>=l));p+=i);let c=0;const u=400;let d=Math.floor(r/s)*s;for(let p=d;p<=e&&!(Math.abs(p-Math.round(p/i)*i)>.001&&(n.push({time:this.secondsToMs(p),type:this.TICK_TYPE_MINOR}),c++,c>=u));p+=s);return n.sort((p,f)=>p.time-f.time)}static getVideoDuration(t){return new Promise(e=>{const i=document.createElement("video");i.preload="metadata",i.onloadedmetadata=()=>{i.onloadedmetadata=null,i.onerror=null,e(i.duration*1e3)},i.onerror=()=>{i.onloadedmetadata=null,i.onerror=null,e(0)},i.src=t})}}A(X,"TICK_TYPE_MAJOR","major"),A(X,"TICK_TYPE_MINOR","minor");const ts=Math.PI/180;function es(){return typeof window<"u"&&({}.toString.call(window)==="[object Window]"||{}.toString.call(window)==="[object global]")}const xt=typeof global<"u"?global:typeof window<"u"?window:typeof WorkerGlobalScope<"u"?self:{},E={_global:xt,version:"10.2.0",isBrowser:es(),isUnminified:/param/.test((function(a){}).toString()),dblClickWindow:400,getAngle(a){return E.angleDeg?a*ts:a},enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:typeof window<"u"&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging(){return E.DD.isDragging},isTransforming(){var a,t;return(t=(a=E.Transformer)===null||a===void 0?void 0:a.isTransforming())!==null&&t!==void 0?t:!1},isDragReady(){return!!E.DD.node},releaseCanvasOnDestroy:!0,document:xt.document,_injectGlobal(a){typeof xt.Konva<"u"&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),xt.Konva=a}},J=a=>{E[a.prototype.getClassName()]=a};E._injectGlobal(E);const is=`Konva.js unsupported environment.
|
|
2
2
|
|
|
3
3
|
Looks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.
|
|
4
4
|
|
|
@@ -11,5 +11,5 @@ or
|
|
|
11
11
|
|
|
12
12
|
bash: npm install skia-canvas
|
|
13
13
|
js: import "konva/skia-backend";
|
|
14
|
-
`,We=()=>{if(typeof document>"u")throw new Error(es)};class rt{constructor(t=[1,0,0,1,0,0]){this.dirty=!1,this.m=t&&t.slice()||[1,0,0,1,0,0]}reset(){this.m[0]=1,this.m[1]=0,this.m[2]=0,this.m[3]=1,this.m[4]=0,this.m[5]=0}copy(){return new rt(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){const e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.m[0]*e+this.m[2]*i,n=this.m[1]*e+this.m[3]*i,r=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=s,this.m[1]=n,this.m[2]=r,this.m[3]=o,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){const i=this.m[0]+this.m[2]*e,s=this.m[1]+this.m[3]*e,n=this.m[2]+this.m[0]*t,r=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=n,this.m[3]=r,this}multiply(t){const e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],s=this.m[0]*t.m[2]+this.m[2]*t.m[3],n=this.m[1]*t.m[2]+this.m[3]*t.m[3],r=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],o=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=n,this.m[4]=r,this.m[5]=o,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,s=-this.m[2]*t,n=this.m[0]*t,r=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),o=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=n,this.m[4]=r,this.m[5]=o,this}getMatrix(){return this.m}decompose(){const t=this.m[0],e=this.m[1],i=this.m[2],s=this.m[3],n=this.m[4],r=this.m[5],o=t*s-e*i,h={x:n,y:r,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(t!=0||e!=0){const l=Math.sqrt(t*t+e*e);h.rotation=e>0?Math.acos(t/l):-Math.acos(t/l),h.scaleX=l,h.scaleY=o/l,h.skewX=(t*i+e*s)/o,h.skewY=0}else if(i!=0||s!=0){const l=Math.sqrt(i*i+s*s);h.rotation=Math.PI/2-(s>0?Math.acos(-i/l):-Math.acos(i/l)),h.scaleX=o/l,h.scaleY=l,h.skewX=0,h.skewY=(t*i+e*s)/o}return h.rotation=_._getRotation(h.rotation),h}}const is="[object Array]",ss="[object Number]",ns="[object String]",rs="[object Boolean]",as=Math.PI/180,os=180/Math.PI,Ot="#",hs="",ls="0",cs="Konva warning: ",Ue="Konva error: ",ds="rgb(",ye={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],transparent:[255,255,255,0],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]},us=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let Qt=[],Ft=null;const fs=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(a){setTimeout(a,16)},_={_isElement(a){return!!(a&&a.nodeType==1)},_isFunction(a){return!!(a&&a.constructor&&a.call&&a.apply)},_isPlainObject(a){return!!a&&a.constructor===Object},_isArray(a){return Object.prototype.toString.call(a)===is},_isNumber(a){return Object.prototype.toString.call(a)===ss&&!isNaN(a)&&isFinite(a)},_isString(a){return Object.prototype.toString.call(a)===ns},_isBoolean(a){return Object.prototype.toString.call(a)===rs},isObject(a){return a instanceof Object},isValidSelector(a){if(typeof a!="string")return!1;const t=a[0];return t==="#"||t==="."||t===t.toUpperCase()},_sign(a){return a===0||a>0?1:-1},requestAnimFrame(a){Qt.push(a),Qt.length===1&&fs(function(){const t=Qt;Qt=[],t.forEach(function(e){e()})})},createCanvasElement(){We();const a=document.createElement("canvas");try{a.style=a.style||{}}catch{}return a},createImageElement(){return We(),document.createElement("img")},_isInDocument(a){for(;a=a.parentNode;)if(a==document)return!0;return!1},_urlToImage(a,t){const e=_.createImageElement();e.onload=function(){t(e)},e.src=a},_rgbToHex(a,t,e){return((1<<24)+(a<<16)+(t<<8)+e).toString(16).slice(1)},_hexToRgb(a){a=a.replace(Ot,hs);const t=parseInt(a,16);return{r:t>>16&255,g:t>>8&255,b:t&255}},getRandomColor(){let a=(Math.random()*16777215<<0).toString(16);for(;a.length<6;)a=ls+a;return Ot+a},isCanvasFarblingActive(){if(Ft!==null)return Ft;if(typeof document>"u")return Ft=!1,!1;const a=this.createCanvasElement();a.width=10,a.height=10;const t=a.getContext("2d",{willReadFrequently:!0});t.clearRect(0,0,10,10),t.fillStyle="#282828",t.fillRect(0,0,10,10);const e=t.getImageData(0,0,10,10).data;let i=!1;for(let s=0;s<100;s++)if(e[s*4]!==40||e[s*4+1]!==40||e[s*4+2]!==40||e[s*4+3]!==255){i=!0;break}return Ft=i,this.releaseCanvas(a),Ft},getHitColor(){const a=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(a):a},getHitColorKey(a,t,e){return this.isCanvasFarblingActive()&&(a=Math.round(a/5)*5,t=Math.round(t/5)*5,e=Math.round(e/5)*5),Ot+this._rgbToHex(a,t,e)},getSnappedHexColor(a){const t=this._hexToRgb(a);return Ot+this._rgbToHex(Math.round(t.r/5)*5,Math.round(t.g/5)*5,Math.round(t.b/5)*5)},getRGB(a){let t;return a in ye?(t=ye[a],{r:t[0],g:t[1],b:t[2]}):a[0]===Ot?this._hexToRgb(a.substring(1)):a.substr(0,4)===ds?(t=us.exec(a.replace(/ /g,"")),{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}):{r:0,g:0,b:0}},colorToRGBA(a){return a=a||"black",_._namedColorToRBA(a)||_._hex3ColorToRGBA(a)||_._hex4ColorToRGBA(a)||_._hex6ColorToRGBA(a)||_._hex8ColorToRGBA(a)||_._rgbColorToRGBA(a)||_._rgbaColorToRGBA(a)||_._hslColorToRGBA(a)},_namedColorToRBA(a){const t=ye[a.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(a){if(a.indexOf("rgb(")===0){a=a.match(/rgb\(([^)]+)\)/)[1];const t=a.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(a){if(a.indexOf("rgba(")===0){a=a.match(/rgba\(([^)]+)\)/)[1];const t=a.split(/ *, */).map((e,i)=>e.slice(-1)==="%"?i===3?parseInt(e)/100:parseInt(e)/100*255:Number(e));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(a){if(a[0]==="#"&&a.length===9)return{r:parseInt(a.slice(1,3),16),g:parseInt(a.slice(3,5),16),b:parseInt(a.slice(5,7),16),a:parseInt(a.slice(7,9),16)/255}},_hex6ColorToRGBA(a){if(a[0]==="#"&&a.length===7)return{r:parseInt(a.slice(1,3),16),g:parseInt(a.slice(3,5),16),b:parseInt(a.slice(5,7),16),a:1}},_hex4ColorToRGBA(a){if(a[0]==="#"&&a.length===5)return{r:parseInt(a[1]+a[1],16),g:parseInt(a[2]+a[2],16),b:parseInt(a[3]+a[3],16),a:parseInt(a[4]+a[4],16)/255}},_hex3ColorToRGBA(a){if(a[0]==="#"&&a.length===4)return{r:parseInt(a[1]+a[1],16),g:parseInt(a[2]+a[2],16),b:parseInt(a[3]+a[3],16),a:1}},_hslColorToRGBA(a){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(a)){const[t,...e]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(a),i=Number(e[0])/360,s=Number(e[1])/100,n=Number(e[2])/100;let r,o,h;if(s===0)return h=n*255,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};n<.5?r=n*(1+s):r=n+s-n*s;const l=2*n-r,c=[0,0,0];for(let u=0;u<3;u++)o=i+1/3*-(u-1),o<0&&o++,o>1&&o--,6*o<1?h=l+(r-l)*6*o:2*o<1?h=r:3*o<2?h=l+(r-l)*(2/3-o)*6:h=l,c[u]=h*255;return{r:Math.round(c[0]),g:Math.round(c[1]),b:Math.round(c[2]),a:1}}},haveIntersection(a,t){return!(t.x>a.x+a.width||t.x+t.width<a.x||t.y>a.y+a.height||t.y+t.height<a.y)},cloneObject(a){const t={};for(const e in a)this._isPlainObject(a[e])?t[e]=this.cloneObject(a[e]):this._isArray(a[e])?t[e]=this.cloneArray(a[e]):t[e]=a[e];return t},cloneArray(a){return a.slice(0)},degToRad(a){return a*as},radToDeg(a){return a*os},_degToRad(a){return _.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),_.degToRad(a)},_radToDeg(a){return _.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),_.radToDeg(a)},_getRotation(a){return E.angleDeg?_.radToDeg(a):a},_capitalize(a){return a.charAt(0).toUpperCase()+a.slice(1)},throw(a){throw new Error(Ue+a)},error(a){console.error(Ue+a)},warn(a){E.showWarnings&&console.warn(cs+a)},each(a,t){for(const e in a)t(e,a[e])},_inRange(a,t,e){return t<=a&&a<e},_getProjectionToSegment(a,t,e,i,s,n){let r,o,h;const l=(a-e)*(a-e)+(t-i)*(t-i);if(l==0)r=a,o=t,h=(s-e)*(s-e)+(n-i)*(n-i);else{const c=((s-a)*(e-a)+(n-t)*(i-t))/l;c<0?(r=a,o=t,h=(a-s)*(a-s)+(t-n)*(t-n)):c>1?(r=e,o=i,h=(e-s)*(e-s)+(i-n)*(i-n)):(r=a+c*(e-a),o=t+c*(i-t),h=(r-s)*(r-s)+(o-n)*(o-n))}return[r,o,h]},_getProjectionToLine(a,t,e){const i=_.cloneObject(a);let s=Number.MAX_VALUE;return t.forEach(function(n,r){if(!e&&r===t.length-1)return;const o=t[(r+1)%t.length],h=_._getProjectionToSegment(n.x,n.y,o.x,o.y,a.x,a.y),l=h[0],c=h[1],u=h[2];u<s&&(i.x=l,i.y=c,s=u)}),i},_prepareArrayForTween(a,t,e){const i=[],s=[];if(a.length>t.length){const r=t;t=a,a=r}for(let r=0;r<a.length;r+=2)i.push({x:a[r],y:a[r+1]});for(let r=0;r<t.length;r+=2)s.push({x:t[r],y:t[r+1]});const n=[];return s.forEach(function(r){const o=_._getProjectionToLine(r,i,e);n.push(o.x),n.push(o.y)}),n},_prepareToStringify(a){let t;a.visitedByCircularReferenceRemoval=!0;for(const e in a)if(a.hasOwnProperty(e)&&a[e]&&typeof a[e]=="object"){if(t=Object.getOwnPropertyDescriptor(a,e),a[e].visitedByCircularReferenceRemoval||_._isElement(a[e]))if(t.configurable)delete a[e];else return null;else if(_._prepareToStringify(a[e])===null)if(t.configurable)delete a[e];else return null}return delete a.visitedByCircularReferenceRemoval,a},_assign(a,t){for(const e in t)a[e]=t[e];return a},_getFirstPointerId(a){return a.touches?a.changedTouches[0].identifier:a.pointerId||999},releaseCanvas(...a){E.releaseCanvasOnDestroy&&a.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(a,t,e,i){let s=t<0?t:0,n=e<0?e:0;t=Math.abs(t),e=Math.abs(e);let r=0,o=0,h=0,l=0;typeof i=="number"?r=o=h=l=Math.min(i,t/2,e/2):(r=Math.min(i[0]||0,t/2,e/2),o=Math.min(i[1]||0,t/2,e/2),l=Math.min(i[2]||0,t/2,e/2),h=Math.min(i[3]||0,t/2,e/2)),a.moveTo(s+r,n),a.lineTo(s+t-o,n),a.arc(s+t-o,n+o,o,Math.PI*3/2,0,!1),a.lineTo(s+t,n+e-l),a.arc(s+t-l,n+e-l,l,0,Math.PI/2,!1),a.lineTo(s+h,n+e),a.arc(s+h,n+e-h,h,Math.PI/2,Math.PI,!1),a.lineTo(s,n+r),a.arc(s+r,n+r,r,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(a,t,e,i,s){i=Math.abs(i);for(let n=0;n<e;n++){const r=t[(n-1+e)%e],o=t[n],h=t[(n+1)%e],l={x:o.x-r.x,y:o.y-r.y},c={x:h.x-o.x,y:h.y-o.y},u=Math.hypot(l.x,l.y),d=Math.hypot(c.x,c.y);let p;typeof s=="number"?p=s:p=n<s.length?s[n]:0,p=i*Math.cos(Math.PI/e)*Math.min(1,p/i*2);const m={x:l.x/u,y:l.y/u},y={x:c.x/d,y:c.y/d},C={x:o.x-m.x*p,y:o.y-m.y*p},S={x:o.x+y.x*p,y:o.y+y.y*p};n===0?a.moveTo(C.x,C.y):a.lineTo(C.x,C.y),a.arcTo(o.x,o.y,S.x,S.y,p)}}};function gs(a){const t=[],e=a.length,i=_;for(let s=0;s<e;s++){let n=a[s];i._isNumber(n)?n=Math.round(n*1e3)/1e3:i._isString(n)||(n=n+""),t.push(n)}return t}const Xe=",",ps="(",ms=")",ys="([",_s="])",Cs=";",Ss="()",bs="=",Ye=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","roundRect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"],vs=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],Ts=100;let te=null;function Ve(){if(te!==null)return te;try{const t=_.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(te=!1,!1)}catch{return te=!1,!1}}class ge{constructor(t){this.canvas=t,E.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i=this.traceArr,s=i.length,n="",r,o,h,l;for(r=0;r<s;r++)o=i[r],h=o.method,h?(l=o.args,n+=h,t?n+=Ss:_._isArray(l[0])?n+=ys+l.join(Xe)+_s:(e&&(l=l.map(c=>typeof c=="number"?Math.floor(c):c)),n+=ps+l.join(Xe)+ms)):(n+=o.property,t||(n+=bs+o.val)),n+=Cs;return n}clearTrace(){this.traceArr=[]}_trace(t){let e=this.traceArr,i;e.push(t),i=e.length,i>=Ts&&e.shift()}reset(){const t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){const e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){const e=t.getAbsoluteOpacity();e!==1&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){const e=t.attrs.miterLimit;e!=null&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,n,r){this._context.arc(t,e,i,s,n,r)}arcTo(t,e,i,s,n){this._context.arcTo(t,e,i,s,n)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,n,r){this._context.bezierCurveTo(t,e,i,s,n,r)}clearRect(t,e,i,s){this._context.clearRect(t,e,i,s)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){const i=arguments;if(i.length===2)return this._context.createImageData(t,e);if(i.length===1)return this._context.createImageData(t)}createLinearGradient(t,e,i,s){return this._context.createLinearGradient(t,e,i,s)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,s,n,r){return this._context.createRadialGradient(t,e,i,s,n,r)}drawImage(t,e,i,s,n,r,o,h,l){const c=arguments,u=this._context;c.length===3?u.drawImage(t,e,i):c.length===5?u.drawImage(t,e,i,s,n):c.length===9&&u.drawImage(t,e,i,s,n,r,o,h,l)}ellipse(t,e,i,s,n,r,o,h){this._context.ellipse(t,e,i,s,n,r,o,h)}isPointInPath(t,e,i,s){return i?this._context.isPointInPath(i,t,e,s):this._context.isPointInPath(t,e,s)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,s){this._context.fillRect(t,e,i,s)}strokeRect(t,e,i,s){this._context.strokeRect(t,e,i,s)}fillText(t,e,i,s){s?this._context.fillText(t,e,i,s):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,s){return this._context.getImageData(t,e,i,s)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,s){this._context.rect(t,e,i,s)}roundRect(t,e,i,s,n){this._context.roundRect(t,e,i,s,n)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,s){this._context.quadraticCurveTo(t,e,i,s)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,s,n,r){this._context.setTransform(t,e,i,s,n,r)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,s){this._context.strokeText(t,e,i,s)}transform(t,e,i,s,n,r){this._context.transform(t,e,i,s,n,r)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t=this,e=Ye.length,i=this.setAttr,s,n;const r=function(o){let h=t[o],l;t[o]=function(){return n=gs(Array.prototype.slice.call(arguments,0)),l=h.apply(t,arguments),t._trace({method:o,args:n}),l}};for(s=0;s<e;s++)r(Ye[s]);t.setAttr=function(){i.apply(t,arguments);const o=arguments[0];let h=arguments[1];(o==="shadowOffsetX"||o==="shadowOffsetY"||o==="shadowBlur")&&(h=h/this.canvas.getPixelRatio()),t._trace({property:o,val:h})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||e==="source-over"||this.setAttr("globalCompositeOperation",e)}}vs.forEach(function(a){Object.defineProperty(ge.prototype,a,{get(){return this._context[a]},set(t){this._context[a]=t}})});class xs extends ge{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){const e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){const e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){const e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){const e=t.fill(),i=t.getFillPriority();if(e&&i==="color"){this._fillColor(t);return}const s=t.getFillPatternImage();if(s&&i==="pattern"){this._fillPattern(t);return}const n=t.getFillLinearGradientColorStops();if(n&&i==="linear-gradient"){this._fillLinearGradient(t);return}const r=t.getFillRadialGradientColorStops();if(r&&i==="radial-gradient"){this._fillRadialGradient(t);return}e?this._fillColor(t):s?this._fillPattern(t):n?this._fillLinearGradient(t):r&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),n=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let r=0;r<s.length;r+=2)n.addColorStop(s[r],s[r+1]);this.setAttr("strokeStyle",n)}}_stroke(t){const e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();const n=this.getCanvas().getPixelRatio();this.setTransform(n,0,0,n,0,0)}this._applyLineCap(t),e&&t.dashEnabled()&&(this.setLineDash(e),this.setAttr("lineDashOffset",t.dashOffset())),this.setAttr("lineWidth",t.strokeWidth()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),t.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(t):this.setAttr("strokeStyle",t.stroke()),t._strokeFunc(this),i||this.restore()}}_applyShadow(t){var e,i,s;const n=(e=t.getShadowRGBA())!==null&&e!==void 0?e:"black",r=(i=t.getShadowBlur())!==null&&i!==void 0?i:5,o=(s=t.getShadowOffset())!==null&&s!==void 0?s:{x:0,y:0},h=t.getAbsoluteScale(),l=this.canvas.getPixelRatio(),c=h.x*l,u=h.y*l;this.setAttr("shadowColor",n),this.setAttr("shadowBlur",r*Math.min(Math.abs(c),Math.abs(u))),this.setAttr("shadowOffsetX",o.x*c),this.setAttr("shadowOffsetY",o.y*u)}}class ws extends ge{constructor(t){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:!0})}_fill(t){this.save(),this.setAttr("fillStyle",t.colorKey),t._fillFuncHit(this),this.restore()}strokeShape(t){t.hasHitStroke()&&this._stroke(t)}_stroke(t){if(t.hasHitStroke()){const e=t.getStrokeScaleEnabled();if(!e){this.save();const n=this.getCanvas().getPixelRatio();this.setTransform(n,0,0,n,0,0)}this._applyLineCap(t);const i=t.hitStrokeWidth(),s=i==="auto"?t.strokeWidth():i;this.setAttr("lineWidth",s),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}}let ee;function ks(){if(ee)return ee;const a=_.createCanvasElement(),t=a.getContext("2d");return ee=function(){const e=E._global.devicePixelRatio||1,i=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/i}(),_.releaseCanvas(a),ee}class Oe{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const i=(t||{}).pixelRatio||E.pixelRatio||ks();this.pixelRatio=i,this._canvas=_.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(t){const e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)}setWidth(t){this.width=this._canvas.width=t*this.pixelRatio,this._canvas.style.width=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}setHeight(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch{try{return this._canvas.toDataURL()}catch(s){return _.error("Unable to get data URL. "+s.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class _t extends Oe{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new xs(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}class Fe extends Oe{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new ws(this),this.setSize(t.width,t.height)}}const X={get isDragging(){let a=!1;return X._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(a=!0)}),a},justDragged:!1,get node(){let a;return X._dragElements.forEach(t=>{a=t.node}),a},_dragElements:new Map,_drag(a){const t=[];X._dragElements.forEach((e,i)=>{const{node:s}=e,n=s.getStage();n.setPointersPositions(a),e.pointerId===void 0&&(e.pointerId=_._getFirstPointerId(a));const r=n._changedPointerPositions.find(o=>o.id===e.pointerId);if(r){if(e.dragStatus!=="dragging"){const o=s.dragDistance();if(Math.max(Math.abs(r.x-e.startPointerPos.x),Math.abs(r.y-e.startPointerPos.y))<o||(s.startDrag({evt:a}),!s.isDragging()))return}s._setDragPosition(a,e),t.push(s)}}),t.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:a},!0)})},_endDragBefore(a){const t=[];X._dragElements.forEach(e=>{const{node:i}=e,s=i.getStage();if(a&&s.setPointersPositions(a),!s._changedPointerPositions.find(o=>o.id===e.pointerId))return;(e.dragStatus==="dragging"||e.dragStatus==="stopped")&&(X.justDragged=!0,E._mouseListenClick=!1,E._touchListenClick=!1,E._pointerListenClick=!1,e.dragStatus="stopped");const r=e.node.getLayer()||e.node instanceof E.Stage&&e.node;r&&t.indexOf(r)===-1&&t.push(r)}),t.forEach(e=>{e.draw()})},_endDragAfter(a){X._dragElements.forEach((t,e)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:a},!0),t.dragStatus!=="dragging"&&X._dragElements.delete(e)})}};E.isBrowser&&(window.addEventListener("mouseup",X._endDragBefore,!0),window.addEventListener("touchend",X._endDragBefore,!0),window.addEventListener("touchcancel",X._endDragBefore,!0),window.addEventListener("mousemove",X._drag),window.addEventListener("touchmove",X._drag),window.addEventListener("mouseup",X._endDragAfter,!1),window.addEventListener("touchend",X._endDragAfter,!1),window.addEventListener("touchcancel",X._endDragAfter,!1));function Ct(a){return _._isString(a)?'"'+a+'"':Object.prototype.toString.call(a)==="[object Number]"||_._isBoolean(a)?a:Object.prototype.toString.call(a)}function pi(a){return a>255?255:a<0?0:Math.round(a)}function k(){if(E.isUnminified)return function(a,t){return _._isNumber(a)||_.warn(Ct(a)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),a}}function pe(a){if(E.isUnminified)return function(t,e){let i=_._isNumber(t),s=_._isArray(t)&&t.length==a;return!i&&!s&&_.warn(Ct(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or Array<number>('+a+")"),t}}function Be(){if(E.isUnminified)return function(a,t){return _._isNumber(a)||a==="auto"||_.warn(Ct(a)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),a}}function kt(){if(E.isUnminified)return function(a,t){return _._isString(a)||_.warn(Ct(a)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),a}}function mi(){if(E.isUnminified)return function(a,t){const e=_._isString(a),i=Object.prototype.toString.call(a)==="[object CanvasGradient]"||a&&a.addColorStop;return e||i||_.warn(Ct(a)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),a}}function As(){if(E.isUnminified)return function(a,t){const e=Int8Array?Object.getPrototypeOf(Int8Array):null;return e&&a instanceof e||(_._isArray(a)?a.forEach(function(i){_._isNumber(i)||_.warn('"'+t+'" attribute has non numeric element '+i+". Make sure that all elements are numbers.")}):_.warn(Ct(a)+' is a not valid value for "'+t+'" attribute. The value should be a array of numbers.')),a}}function ht(){if(E.isUnminified)return function(a,t){return a===!0||a===!1||_.warn(Ct(a)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),a}}function Es(a){if(E.isUnminified)return function(t,e){return t==null||_.isObject(t)||_.warn(Ct(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+a),t}}const Bt="get",Nt="set",g={addGetterSetter(a,t,e,i,s){g.addGetter(a,t,e),g.addSetter(a,t,i,s),g.addOverloadedGetterSetter(a,t)},addGetter(a,t,e){const i=Bt+_._capitalize(t);a.prototype[i]=a.prototype[i]||function(){const s=this.attrs[t];return s===void 0?e:s}},addSetter(a,t,e,i){const s=Nt+_._capitalize(t);a.prototype[s]||g.overWriteSetter(a,t,e,i)},overWriteSetter(a,t,e,i){const s=Nt+_._capitalize(t);a.prototype[s]=function(n){return e&&n!==void 0&&n!==null&&(n=e.call(this,n,t)),this._setAttr(t,n),i&&i.call(this),this}},addComponentsGetterSetter(a,t,e,i,s){const n=e.length,r=_._capitalize,o=Bt+r(t),h=Nt+r(t);a.prototype[o]=function(){const c={};for(let u=0;u<n;u++){const d=e[u];c[d]=this.getAttr(t+r(d))}return c};const l=Es(e);a.prototype[h]=function(c){const u=this.attrs[t];i&&(c=i.call(this,c,t)),l&&l.call(this,c,t);for(const d in c)c.hasOwnProperty(d)&&this._setAttr(t+r(d),c[d]);return c||e.forEach(d=>{this._setAttr(t+r(d),void 0)}),this._fireChangeEvent(t,u,c),s&&s.call(this),this},g.addOverloadedGetterSetter(a,t)},addOverloadedGetterSetter(a,t){const e=_._capitalize(t),i=Nt+e,s=Bt+e;a.prototype[t]=function(){return arguments.length?(this[i](arguments[0]),this):this[s]()}},addDeprecatedGetterSetter(a,t,e,i){_.error("Adding deprecated "+t);const s=Bt+_._capitalize(t),n=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";a.prototype[s]=function(){_.error(n);const r=this.attrs[t];return r===void 0?e:r},g.addSetter(a,t,i,function(){_.error(n)}),g.addOverloadedGetterSetter(a,t)},backCompat(a,t){_.each(t,function(e,i){const s=a.prototype[i],n=Bt+_._capitalize(e),r=Nt+_._capitalize(e);function o(){s.apply(this,arguments),_.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}a.prototype[e]=o,a.prototype[n]=o,a.prototype[r]=o})},afterSetFilter(){this._filterUpToDate=!1}};function Ps(a){const t=/(\w+)\(([^)]+)\)/g;let e;for(;(e=t.exec(a))!==null;){const[,i,s]=e;switch(i){case"blur":{const n=parseFloat(s.replace("px",""));return function(r){this.blurRadius(n*.5);const o=E.Filters;o&&o.Blur&&o.Blur.call(this,r)}}case"brightness":{const n=s.includes("%")?parseFloat(s)/100:parseFloat(s);return function(r){this.brightness(n);const o=E.Filters;o&&o.Brightness&&o.Brightness.call(this,r)}}case"contrast":{const n=parseFloat(s);return function(r){const o=100*(Math.sqrt(n)-1);this.contrast(o);const h=E.Filters;h&&h.Contrast&&h.Contrast.call(this,r)}}case"grayscale":return function(n){const r=E.Filters;r&&r.Grayscale&&r.Grayscale.call(this,n)};case"sepia":return function(n){const r=E.Filters;r&&r.Sepia&&r.Sepia.call(this,n)};case"invert":return function(n){const r=E.Filters;r&&r.Invert&&r.Invert.call(this,n)};default:_.warn(`CSS filter "${i}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}const le="absoluteOpacity",je="allEventListeners",dt="absoluteTransform",qe="absoluteScale",Tt="canvas",Rs="Change",Ms="children",Ls="konva",we="listening",Ds="mouseenter",Gs="mouseleave",Is="pointerenter",Os="pointerleave",Fs="touchenter",Bs="touchleave",$e="set",Ke="Shape",ce=" ",Ze="stage",mt="transform",Ns="Stage",ke="visible",Hs=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(ce);let zs=1;class x{constructor(t){this._id=zs++,this.eventListeners={},this.attrs={},this.index=0,this._allEventListeners=null,this.parent=null,this._cache=new Map,this._attachedDepsListeners=new Map,this._lastPos=null,this._batchingTransformChange=!1,this._needClearTransformCache=!1,this._filterUpToDate=!1,this._isUnderCache=!1,this._dragEventId=null,this._shouldFireChangeEvents=!1,this.setAttrs(t),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(t){(t===mt||t===dt)&&this._cache.get(t)?this._cache.get(t).dirty=!0:t?this._cache.delete(t):this._cache.clear()}_getCache(t,e){let i=this._cache.get(t);return(i===void 0||(t===mt||t===dt)&&i.dirty===!0)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){const s=e.map(n=>n+"Change.konva").join(ce);this.on(s,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(Tt)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===dt&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(Tt)){const{scene:t,filter:e,hit:i}=this._cache.get(Tt);_.releaseCanvas(t._canvas,e._canvas,i._canvas),this._cache.delete(Tt)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};(e.x===void 0||e.y===void 0||e.width===void 0||e.height===void 0)&&(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),n=Math.ceil(e.height||i.height),r=e.pixelRatio,o=e.x===void 0?Math.floor(i.x):e.x,h=e.y===void 0?Math.floor(i.y):e.y,l=e.offset||0,c=e.drawBorder||!1,u=e.hitCanvasPixelRatio||1;if(!s||!n){_.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}const d=Math.abs(Math.round(i.x)-o)>.5?1:0,p=Math.abs(Math.round(i.y)-h)>.5?1:0;s+=l*2+d,n+=l*2+p,o-=l,h-=l;const f=new _t({pixelRatio:r,width:s,height:n}),m=new _t({pixelRatio:r,width:0,height:0,willReadFrequently:!0}),y=new Fe({pixelRatio:u,width:s,height:n}),C=f.getContext(),S=y.getContext(),b=new _t({width:f.width/f.pixelRatio+Math.abs(o),height:f.height/f.pixelRatio+Math.abs(h),pixelRatio:f.pixelRatio}),v=b.getContext();return y.isCache=!0,f.isCache=!0,this._cache.delete(Tt),this._filterUpToDate=!1,e.imageSmoothingEnabled===!1&&(f.getContext()._context.imageSmoothingEnabled=!1,m.getContext()._context.imageSmoothingEnabled=!1),C.save(),S.save(),v.save(),C.translate(-o,-h),S.translate(-o,-h),v.translate(-o,-h),b.x=o,b.y=h,this._isUnderCache=!0,this._clearSelfAndDescendantCache(le),this._clearSelfAndDescendantCache(qe),this.drawScene(f,this,b),this.drawHit(y,this),this._isUnderCache=!1,C.restore(),S.restore(),c&&(C.save(),C.beginPath(),C.rect(0,0,s,n),C.closePath(),C.setAttr("strokeStyle","red"),C.setAttr("lineWidth",5),C.stroke(),C.restore()),_.releaseCanvas(b._canvas),this._cache.set(Tt,{scene:f,filter:m,hit:y,x:o,y:h}),this._requestDraw(),this}isCached(){return this._cache.has(Tt)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){const i=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let s=1/0,n=1/0,r=-1/0,o=-1/0;const h=this.getAbsoluteTransform(e);return i.forEach(function(l){const c=h.point(l);s===void 0&&(s=r=c.x,n=o=c.y),s=Math.min(s,c.x),n=Math.min(n,c.y),r=Math.max(r,c.x),o=Math.max(o,c.y)}),{x:s,y:n,width:r-s,height:o-n}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);const i=this._getCachedSceneCanvas(),s=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/s,i.height/s),t.restore()}_drawCachedHitCanvas(t){const e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t=this.filters(),e=this._getCanvasCache(),i=e.scene,s=e.filter,n=s.getContext(),r,o,h,l;if(!t||t.length===0)return i;if(this._filterUpToDate)return s;let c=!0;for(let d=0;d<t.length;d++)if(typeof t[d]=="string"&&Ve(),typeof t[d]!="string"||!Ve()){c=!1;break}const u=i.pixelRatio;if(s.setSize(i.width/i.pixelRatio,i.height/i.pixelRatio),c){const d=t.join(" ");return n.save(),n.setAttr("filter",d),n.drawImage(i._canvas,0,0,i.getWidth()/u,i.getHeight()/u),n.restore(),this._filterUpToDate=!0,s}try{for(r=t.length,n.clear(),n.drawImage(i._canvas,0,0,i.getWidth()/u,i.getHeight()/u),o=n.getImageData(0,0,s.getWidth(),s.getHeight()),h=0;h<r;h++)l=t[h],typeof l=="string"&&(l=Ps(l)),l.call(this,o),n.putImageData(o,0,0)}catch(d){_.error("Unable to apply filter. "+d.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,s}on(t,e){if(this._cache&&this._cache.delete(je),arguments.length===3)return this._delegate.apply(this,arguments);const i=t.split(ce);for(let s=0;s<i.length;s++){const r=i[s].split("."),o=r[0],h=r[1]||"";this.eventListeners[o]||(this.eventListeners[o]=[]),this.eventListeners[o].push({name:h,handler:e})}return this}off(t,e){let i=(t||"").split(ce),s=i.length,n,r,o,h,l,c;if(this._cache&&this._cache.delete(je),!t)for(r in this.eventListeners)this._off(r);for(n=0;n<s;n++)if(o=i[n],h=o.split("."),l=h[0],c=h[1],l)this.eventListeners[l]&&this._off(l,c,e);else for(r in this.eventListeners)this._off(r,c,e);return this}dispatchEvent(t){const e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(i){e.call(this,i.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){const s=this;this.on(t,function(n){const r=n.target.findAncestors(e,!0,s);for(let o=0;o<r.length;o++)n=_.cloneObject(n),n.currentTarget=r[o],i.call(r[o],n)})}remove(){return this.isDragging()&&this.stopDrag(),X._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(dt),this._clearSelfAndDescendantCache(le),this._clearSelfAndDescendantCache(qe),this._clearSelfAndDescendantCache(Ze),this._clearSelfAndDescendantCache(ke),this._clearSelfAndDescendantCache(we)}_remove(){this._clearCaches();const t=this.getParent();t&&t.children&&(t.children.splice(this.index,1),t._setChildrenIndices(),this.parent=null)}destroy(){return this.remove(),this.clearCache(),this}getAttr(t){const e="get"+_._capitalize(t);return _._isFunction(this[e])?this[e]():this.attrs[t]}getAncestors(){let t=this.getParent(),e=[];for(;t;)e.push(t),t=t.getParent();return e}getAttrs(){return this.attrs||{}}setAttrs(t){return this._batchTransformChanges(()=>{let e,i;if(!t)return this;for(e in t)e!==Ms&&(i=$e+_._capitalize(e),_._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(we,this._isListening)}_isListening(t){if(!this.listening())return!1;const i=this.getParent();return i&&i!==t&&this!==t?i._isListening(t):!0}isVisible(){return this._getCache(ke,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const i=this.getParent();return i&&i!==t&&this!==t?i._isVisible(t):!0}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const i=this.getLayer();let s=!1;X._dragElements.forEach(r=>{r.dragStatus==="dragging"&&(r.node.nodeType==="Stage"||r.node.getLayer()===i)&&(s=!0)});const n=!e&&!E.hitOnDragEnabled&&(s||E.isTransforming());return this.isListening()&&this.isVisible()&&!n}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t=this.getDepth(),e=this,i=0,s,n,r,o;function h(c){for(s=[],n=c.length,r=0;r<n;r++)o=c[r],i++,o.nodeType!==Ke&&(s=s.concat(o.getChildren().slice())),o._id===e._id&&(r=n);s.length>0&&s[0].getDepth()<=t&&h(s)}const l=this.getStage();return e.nodeType!==Ns&&l&&h(l.getChildren()),i}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(mt),this._clearSelfAndDescendantCache(dt)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges(()=>{this.x(t.x),this.y(t.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const t=this.getStage();if(!t)return null;const e=t.getPointerPosition();if(!e)return null;const i=this.getAbsoluteTransform().copy();return i.invert(),i.point(e)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);const s=this.getAbsoluteTransform(t).getMatrix(),n=new rt,r=this.offset();return n.m=s.slice(),n.translate(r.x,r.y),n.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(mt);const n=this._getAbsoluteTransform().copy();return n.invert(),n.translate(t.x,t.y),t={x:this.attrs.x+n.getTranslation().x,y:this.attrs.y+n.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(mt),this._clearSelfAndDescendantCache(dt),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){const t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}move(t){let e=t.x,i=t.y,s=this.x(),n=this.y();return e!==void 0&&(s+=e),i!==void 0&&(n+=i),this.setPosition({x:s,y:n}),this}_eachAncestorReverse(t,e){let i=[],s=this.getParent(),n,r;if(!(e&&e._id===this._id)){for(i.unshift(this);s&&(!e||s._id!==e._id);)i.unshift(s),s=s.parent;for(n=i.length,r=0;r<n;r++)t(i[r])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return _.warn("Node has no parent. moveToTop function is ignored."),!1;const t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0):!1}moveUp(){if(!this.parent)return _.warn("Node has no parent. moveUp function is ignored."),!1;const t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0):!1}moveDown(){if(!this.parent)return _.warn("Node has no parent. moveDown function is ignored."),!1;const t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return _.warn("Node has no parent. moveToBottom function is ignored."),!1;const t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(t){if(!this.parent)return _.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&_.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");const e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(le,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity();const e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t=this.getAttrs(),e,i,s,n,r;const o={attrs:{},className:this.getClassName()};for(e in t)i=t[e],r=_.isObject(i)&&!_._isPlainObject(i)&&!_._isArray(i),!r&&(s=typeof this[e]=="function"&&this[e],delete t[e],n=s?s.call(this):null,t[e]=i,n!==i&&(o.attrs[e]=i));return _._prepareToStringify(o)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){const s=[];e&&this._isMatch(t)&&s.push(this);let n=this.parent;for(;n;){if(n===i)return s;n._isMatch(t)&&s.push(n),n=n.parent}return s}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if(typeof t=="function")return t(this);let e=t.replace(/ /g,"").split(","),i=e.length,s,n;for(s=0;s<i;s++)if(n=e[s],_.isValidSelector(n)||(_.warn('Selector "'+n+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),_.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),_.warn("Konva is awesome, right?")),n.charAt(0)==="#"){if(this.id()===n.slice(1))return!0}else if(n.charAt(0)==="."){if(this.hasName(n.slice(1)))return!0}else if(this.className===n||this.nodeType===n)return!0;return!1}getLayer(){const t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(Ze,this._getStage)}_getStage(){const t=this.getParent();return t?t.getStage():null}fire(t,e={},i){return e.target=e.target||this,i?this._fireAndBubble(t,e):this._fire(t,e),this}getAbsoluteTransform(t){return t?this._getAbsoluteTransform(t):this._getCache(dt,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new rt,this._eachAncestorReverse(function(i){const s=i.transformsEnabled();s==="all"?e.multiply(i.getTransform()):s==="position"&&e.translate(i.x()-i.offsetX(),i.y()-i.offsetY())},t),e;{e=this._cache.get(dt)||new rt,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();const i=this.transformsEnabled();if(i==="all")e.multiply(this.getTransform());else if(i==="position"){const s=this.attrs.x||0,n=this.attrs.y||0,r=this.attrs.offsetX||0,o=this.attrs.offsetY||0;e.translate(s-r,n-o)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();const s=this.getAbsoluteTransform(t).decompose();return{x:s.scaleX,y:s.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(mt,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(mt)||new rt;i.reset();const s=this.x(),n=this.y(),r=E.getAngle(this.rotation()),o=(t=this.attrs.scaleX)!==null&&t!==void 0?t:1,h=(e=this.attrs.scaleY)!==null&&e!==void 0?e:1,l=this.attrs.skewX||0,c=this.attrs.skewY||0,u=this.attrs.offsetX||0,d=this.attrs.offsetY||0;return(s!==0||n!==0)&&i.translate(s,n),r!==0&&i.rotate(r),(l!==0||c!==0)&&i.skew(l,c),(o!==1||h!==1)&&i.scale(o,h),(u!==0||d!==0)&&i.translate(-1*u,-1*d),i.dirty=!1,i}clone(t){let e=_.cloneObject(this.attrs),i,s,n,r,o;for(i in t)e[i]=t[i];const h=new this.constructor(e);for(i in this.eventListeners)for(s=this.eventListeners[i],n=s.length,r=0;r<n;r++)o=s[r],o.name.indexOf(Ls)<0&&(h.eventListeners[i]||(h.eventListeners[i]=[]),h.eventListeners[i].push(o));return h}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=t.x!==void 0?t.x:Math.floor(e.x),n=t.y!==void 0?t.y:Math.floor(e.y),r=t.pixelRatio||1,o=new _t({width:t.width||Math.ceil(e.width)||(i?i.width():0),height:t.height||Math.ceil(e.height)||(i?i.height():0),pixelRatio:r}),h=o.getContext(),l=new _t({width:o.width/o.pixelRatio+Math.abs(s),height:o.height/o.pixelRatio+Math.abs(n),pixelRatio:o.pixelRatio});return t.imageSmoothingEnabled===!1&&(h._context.imageSmoothingEnabled=!1),h.save(),(s||n)&&h.translate(-1*s,-1*n),this.drawScene(o,void 0,l),h.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){t=t||{};const e=t.mimeType||null,i=t.quality||null,s=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(s),s}toImage(t){return new Promise((e,i)=>{try{const s=t==null?void 0:t.callback;s&&delete t.callback,_._urlToImage(this.toDataURL(t),function(n){e(n),s==null||s(n)})}catch(s){i(s)}})}toBlob(t){return new Promise((e,i)=>{try{const s=t==null?void 0:t.callback;s&&delete t.callback,this.toCanvas(t).toBlob(n=>{e(n),s==null||s(n)},t==null?void 0:t.mimeType,t==null?void 0:t.quality)}catch(s){i(s)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance!==void 0?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():E.dragDistance}_off(t,e,i){let s=this.eventListeners[t],n,r,o;for(n=0;n<s.length;n++)if(r=s[n].name,o=s[n].handler,(r!=="konva"||e==="konva")&&(!e||r===e)&&(!i||i===o)){if(s.splice(n,1),s.length===0){delete this.eventListeners[t];break}n--}}_fireChangeEvent(t,e,i){this._fire(t+Rs,{oldVal:e,newVal:i})}addName(t){if(!this.hasName(t)){const e=this.name(),i=e?e+" "+t:t;this.name(i)}return this}hasName(t){if(!t)return!1;const e=this.name();return e?(e||"").split(/\s/g).indexOf(t)!==-1:!1}removeName(t){const e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return i!==-1&&(e.splice(i,1),this.name(e.join(" "))),this}setAttr(t,e){const i=this[$e+_._capitalize(t)];return _._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(E.autoDrawEnabled){const t=this.getLayer()||this.getStage();t==null||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];i===e&&!_.isObject(e)||(e==null?delete this.attrs[t]:this.attrs[t]=e,this._shouldFireChangeEvents&&this._fireChangeEvent(t,i,e),this._requestDraw())}_setComponentAttr(t,e,i){let s;i!==void 0&&(s=this.attrs[t],s||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,s,i))}_fireAndBubble(t,e,i){e&&this.nodeType===Ke&&(e.target=this);const s=[Ds,Gs,Is,Os,Fs,Bs];if(!(s.indexOf(t)!==-1&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||this.nodeType==="Stage"&&!i))){this._fire(t,e);const r=s.indexOf(t)!==-1&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!r&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i;const{nodeType:s}=this,n=x.protoListenerMap.get(s)||{};let r=n==null?void 0:n[t];if(r===void 0){r=[];let o=Object.getPrototypeOf(this);for(;o;){const h=(i=(e=o.eventListeners)===null||e===void 0?void 0:e[t])!==null&&i!==void 0?i:[];r.push(...h),o=Object.getPrototypeOf(o)}n[t]=r,x.protoListenerMap.set(s,n)}return r}_fire(t,e){e=e||{},e.currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let n=0;n<i.length;n++)i[n].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let n=0;n<s.length;n++)s[n].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const e=t?t.pointerId:void 0,i=this.getStage(),s=this.getAbsolutePosition();if(!i)return;const n=i._getPointerById(e)||i._changedPointerPositions[0]||s;X._dragElements.set(this._id,{node:this,startPointerPos:n,offset:{x:n.x-s.x,y:n.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){X._dragElements.has(this._id)||this._createDragElement(t);const i=X._dragElements.get(this._id);i.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:t&&t.evt},e)}_setDragPosition(t,e){const i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let s={x:i.x-e.offset.x,y:i.y-e.offset.y};const n=this.dragBoundFunc();if(n!==void 0){const r=n.call(this,s,t);r?s=r:_.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==s.x||this._lastPos.y!==s.y)&&(this.setAbsolutePosition(s),this._requestDraw()),this._lastPos=s}stopDrag(t){const e=X._dragElements.get(this._id);e&&(e.dragStatus="stopped"),X._endDragBefore(t),X._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=X._dragElements.get(this._id);return t?t.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(t.evt.button!==void 0)||E.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let s=!1;X._dragElements.forEach(n=>{this.isAncestorOf(n.node)&&(s=!0)}),s||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const e=X._dragElements.get(this._id),i=e&&e.dragStatus==="dragging",s=e&&e.dragStatus==="ready";i?this.stopDrag():s&&X._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const e=this.getStage();if(!e)return!1;const i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return _.haveIntersection(i,this.getClientRect())}static create(t,e){return _._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let i=x.prototype.getClassName.call(t),s=t.children,n,r,o;e&&(t.attrs.container=e),E[i]||(_.warn('Can not find a node with class name "'+i+'". Fallback to "Shape".'),i="Shape");const h=E[i];if(n=new h(t.attrs),s)for(r=s.length,o=0;o<r;o++)n.add(x._createNode(s[o]));return n}}x.protoListenerMap=new Map;x.prototype.nodeType="Node";x.prototype._attrsAffectingSize=[];x.prototype.eventListeners={};x.prototype.on.call(x.prototype,Hs,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(mt),this._clearSelfAndDescendantCache(dt)});x.prototype.on.call(x.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(ke)});x.prototype.on.call(x.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(we)});x.prototype.on.call(x.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(le)});const q=g.addGetterSetter;q(x,"zIndex");q(x,"absolutePosition");q(x,"position");q(x,"x",0,k());q(x,"y",0,k());q(x,"globalCompositeOperation","source-over",kt());q(x,"opacity",1,k());q(x,"name","",kt());q(x,"id","",kt());q(x,"rotation",0,k());g.addComponentsGetterSetter(x,"scale",["x","y"]);q(x,"scaleX",1,k());q(x,"scaleY",1,k());g.addComponentsGetterSetter(x,"skew",["x","y"]);q(x,"skewX",0,k());q(x,"skewY",0,k());g.addComponentsGetterSetter(x,"offset",["x","y"]);q(x,"offsetX",0,k());q(x,"offsetY",0,k());q(x,"dragDistance",void 0,k());q(x,"width",0,k());q(x,"height",0,k());q(x,"listening",!0,ht());q(x,"preventDefault",!0,ht());q(x,"filters",void 0,function(a){return this._filterUpToDate=!1,a});q(x,"visible",!0,ht());q(x,"transformsEnabled","all",kt());q(x,"size");q(x,"dragBoundFunc");q(x,"draggable",!1,ht());g.backCompat(x,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class at extends x{constructor(){super(...arguments),this.children=[]}getChildren(t){const e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(t.length===0)return this;if(t.length>1){for(let i=0;i<t.length;i++)this.add(t[i]);return this}const e=t[0];return e.getParent()?(e.moveTo(this),this):(this._validateAdd(e),e.index=this.getChildren().length,e.parent=this,e._clearCaches(),this.getChildren().push(e),this._fire("add",{child:e}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(t){return this._generalFind(t,!1)}findOne(t){const e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){const i=[];return this._descendants(s=>{const n=s._isMatch(t);return n&&i.push(s),!!(n&&e)}),i}_descendants(t){let e=!1;const i=this.getChildren();for(const s of i){if(e=t(s),e)return!0;if(s.hasChildren()&&(e=s._descendants(t),e))return!0}return!1}toObject(){const t=x.prototype.toObject.call(this);return t.children=[],this.getChildren().forEach(e=>{t.children.push(e.toObject())}),t}isAncestorOf(t){let e=t.getParent();for(;e;){if(e._id===this._id)return!0;e=e.getParent()}return!1}clone(t){const e=x.prototype.clone.call(this,t);return this.getChildren().forEach(function(i){e.add(i.clone())}),e}getAllIntersections(t){const e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),!this.isCached()&&((e=this.children)===null||e===void 0||e.forEach(function(i){i._clearSelfAndDescendantCache(t)}))}_setChildrenIndices(){var t;(t=this.children)===null||t===void 0||t.forEach(function(e,i){e.index=i}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),n=t||s&&s.getCanvas(),r=n&&n.getContext(),o=this._getCanvasCache(),h=o&&o.scene,l=n&&n.isCache;if(!this.isVisible()&&!l)return this;if(h){r.save();const c=this.getAbsoluteTransform(e).getMatrix();r.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedSceneCanvas(r),r.restore()}else this._drawChildren("drawScene",n,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,n=s&&s.getContext(),r=this._getCanvasCache();if(r&&r.hit){n.save();const h=this.getAbsoluteTransform(e).getMatrix();n.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedHitCanvas(n),n.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var n;const r=e&&e.getContext(),o=this.clipWidth(),h=this.clipHeight(),l=this.clipFunc(),c=typeof o=="number"&&typeof h=="number"||l,u=i===this;if(c){r.save();const p=this.getAbsoluteTransform(i);let f=p.getMatrix();r.transform(f[0],f[1],f[2],f[3],f[4],f[5]),r.beginPath();let m;if(l)m=l.call(this,r,this);else{const y=this.clipX(),C=this.clipY();r.rect(y||0,C||0,o,h)}r.clip.apply(r,m),f=p.copy().invert().getMatrix(),r.transform(f[0],f[1],f[2],f[3],f[4],f[5])}const d=!u&&this.globalCompositeOperation()!=="source-over"&&t==="drawScene";d&&(r.save(),r._applyGlobalCompositeOperation(this)),(n=this.children)===null||n===void 0||n.forEach(function(p){p[t](e,i,s)}),d&&r.restore(),c&&r.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let n,r,o,h,l={x:1/0,y:1/0,width:0,height:0};const c=this;(e=this.children)===null||e===void 0||e.forEach(function(p){if(!p.visible())return;const f=p.getClientRect({relativeTo:c,skipShadow:t.skipShadow,skipStroke:t.skipStroke});f.width===0&&f.height===0||(n===void 0?(n=f.x,r=f.y,o=f.x+f.width,h=f.y+f.height):(n=Math.min(n,f.x),r=Math.min(r,f.y),o=Math.max(o,f.x+f.width),h=Math.max(h,f.y+f.height)))});const u=this.find("Shape");let d=!1;for(let p=0;p<u.length;p++)if(u[p]._isVisible(this)){d=!0;break}return d&&n!==void 0?l={x:n,y:r,width:o-n,height:h-r}:l={x:0,y:0,width:0,height:0},i?l:this._transformedRect(l,s)}}g.addComponentsGetterSetter(at,"clip",["x","y","width","height"]);g.addGetterSetter(at,"clipX",void 0,k());g.addGetterSetter(at,"clipY",void 0,k());g.addGetterSetter(at,"clipWidth",void 0,k());g.addGetterSetter(at,"clipHeight",void 0,k());g.addGetterSetter(at,"clipFunc");const Zt=new Map,yi=E._global.PointerEvent!==void 0;function _e(a){return Zt.get(a)}function Ne(a){return{evt:a,pointerId:a.pointerId}}function _i(a,t){return Zt.get(a)===t}function Ci(a,t){jt(a),t.getStage()&&(Zt.set(a,t),yi&&t._fire("gotpointercapture",Ne(new PointerEvent("gotpointercapture"))))}function jt(a,t){const e=Zt.get(a);if(!e)return;const i=e.getStage();i&&i.content,Zt.delete(a),yi&&e._fire("lostpointercapture",Ne(new PointerEvent("lostpointercapture")))}const Ws="Stage",Us="string",Je="px",Xs="mouseout",Si="mouseleave",bi="mouseover",vi="mouseenter",Ti="mousemove",xi="mousedown",wi="mouseup",Wt="pointermove",Ut="pointerdown",Dt="pointerup",Xt="pointercancel",Ys="lostpointercapture",ie="pointerout",Yt="pointerleave",se="pointerover",ne="pointerenter",Ae="contextmenu",ki="touchstart",Ai="touchend",Ei="touchmove",Pi="touchcancel",Ee="wheel",Vs=5,js=[[vi,"_pointerenter"],[xi,"_pointerdown"],[Ti,"_pointermove"],[wi,"_pointerup"],[Si,"_pointerleave"],[ki,"_pointerdown"],[Ei,"_pointermove"],[Ai,"_pointerup"],[Pi,"_pointercancel"],[bi,"_pointerover"],[Ee,"_wheel"],[Ae,"_contextmenu"],[Ut,"_pointerdown"],[Wt,"_pointermove"],[Dt,"_pointerup"],[Xt,"_pointercancel"],[Yt,"_pointerleave"],[Ys,"_lostpointercapture"]],Ce={mouse:{[ie]:Xs,[Yt]:Si,[se]:bi,[ne]:vi,[Wt]:Ti,[Ut]:xi,[Dt]:wi,[Xt]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[ie]:"touchout",[Yt]:"touchleave",[se]:"touchover",[ne]:"touchenter",[Wt]:Ei,[Ut]:ki,[Dt]:Ai,[Xt]:Pi,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[ie]:ie,[Yt]:Yt,[se]:se,[ne]:ne,[Wt]:Wt,[Ut]:Ut,[Dt]:Dt,[Xt]:Xt,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},Vt=a=>a.indexOf("pointer")>=0?"pointer":a.indexOf("touch")>=0?"touch":"mouse",Mt=a=>{const t=Vt(a);if(t==="pointer")return E.pointerEventsEnabled&&Ce.pointer;if(t==="touch")return Ce.touch;if(t==="mouse")return Ce.mouse};function Qe(a={}){return(a.clipFunc||a.clipWidth||a.clipHeight)&&_.warn("Stage does not support clipping. Please use clip for Layers or Groups."),a}const qs="Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);",qt=[];class me extends at{constructor(t){super(Qe(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),qt.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{Qe(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e=t.getType()==="Layer",i=t.getType()==="FastLayer";e||i||_.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if(typeof t===Us){let e;if(t.charAt(0)==="."){const i=t.slice(1);t=document.getElementsByClassName(i)[0]}else t.charAt(0)!=="#"?e=t:e=t.slice(1),t=document.getElementById(e);if(!t)throw"Can not find container in document with id "+e}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){const t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].clear();return this}clone(t){return t||(t={}),t.container=typeof document<"u"&&document.createElement("div"),at.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&_._isInDocument(t)&&this.container().removeChild(t);const e=qt.indexOf(this);return e>-1&&qt.splice(e,1),_.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(_.warn(qs),null)}_getPointerById(t){return this._pointerPositions.find(e=>e.id===t)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){t={...t},t.x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();const e=new _t({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,s=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),s.forEach(function(n){if(!n.isVisible())return;const r=n._toKonvaCanvas(t);i.drawImage(r._canvas,t.x,t.y,r.getWidth()/r.getPixelRatio(),r.getHeight()/r.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children,i=e.length,s=i-1;for(let n=s;n>=0;n--){const r=e[n].getIntersection(t);if(r)return r}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+Je,this.content.style.height=e+Je),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach(i=>{i.setSize({width:t,height:e}),i.draw()})}add(t,...e){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.add(arguments[s]);return this}super.add(t);const i=this.children.length;return i>Vs&&_.warn("The stage has "+i+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),t.setSize({width:this.width(),height:this.height()}),t.draw(),E.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return _i(t,this)}setPointerCapture(t){Ci(t,this)}releaseCapture(t){jt(t)}getLayers(){return this.children}_bindContentEvents(){E.isBrowser&&js.forEach(([t,e])=>{this.content.addEventListener(t,i=>{this[e](i)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=Mt(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Mt(t.type);e&&this._fire(e.pointerover,{evt:t,target:this,currentTarget:this})}_getTargetShape(t){let e=this[t+"targetShape"];return e&&!e.getStage()&&(e=null),e}_pointerleave(t){const e=Mt(t.type),i=Vt(t.type);if(!e)return;this.setPointersPositions(t);const s=this._getTargetShape(i),n=!(E.isDragging()||E.isTransforming())||E.hitOnDragEnabled;s&&n?(s._fireAndBubble(e.pointerout,{evt:t}),s._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"targetShape"]=null):n&&(this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this._fire(e.pointerout,{evt:t,target:this,currentTarget:this})),this.pointerPos=null,this._pointerPositions=[]}_pointerdown(t){const e=Mt(t.type),i=Vt(t.type);if(!e)return;this.setPointersPositions(t);let s=!1;this._changedPointerPositions.forEach(n=>{const r=this.getIntersection(n);if(X.justDragged=!1,E["_"+i+"ListenClick"]=!0,!r||!r.isListening()){this[i+"ClickStartShape"]=void 0;return}E.capturePointerEventsEnabled&&r.setPointerCapture(n.id),this[i+"ClickStartShape"]=r,r._fireAndBubble(e.pointerdown,{evt:t,pointerId:n.id}),s=!0;const o=t.type.indexOf("touch")>=0;r.preventDefault()&&t.cancelable&&o&&t.preventDefault()}),s||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=Mt(t.type),i=Vt(t.type);if(!e)return;const s=t.type.indexOf("touch")>=0||t.pointerType==="touch";if(E.isDragging()&&X.node.preventDefault()&&t.cancelable&&s&&t.preventDefault(),this.setPointersPositions(t),!(!(E.isDragging()||E.isTransforming())||E.hitOnDragEnabled))return;const r={};let o=!1;const h=this._getTargetShape(i);this._changedPointerPositions.forEach(l=>{const c=_e(l.id)||this.getIntersection(l),u=l.id,d={evt:t,pointerId:u},p=h!==c;if(p&&h&&(h._fireAndBubble(e.pointerout,{...d},c),h._fireAndBubble(e.pointerleave,{...d},c)),c){if(r[c._id])return;r[c._id]=!0}c&&c.isListening()?(o=!0,p&&(c._fireAndBubble(e.pointerover,{...d},h),c._fireAndBubble(e.pointerenter,{...d},h),this[i+"targetShape"]=c),c._fireAndBubble(e.pointermove,{...d})):h&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:u}),this[i+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Mt(t.type),i=Vt(t.type);if(!e)return;this.setPointersPositions(t);const s=this[i+"ClickStartShape"],n=this[i+"ClickEndShape"],r={};let o=!1;this._changedPointerPositions.forEach(h=>{const l=_e(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),r[l._id])return;r[l._id]=!0}const c=h.id,u={evt:t,pointerId:c};let d=!1;E["_"+i+"InDblClickWindow"]?(d=!0,clearTimeout(this[i+"DblTimeout"])):X.justDragged||(E["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){E["_"+i+"InDblClickWindow"]=!1},E.dblClickWindow),l&&l.isListening()?(o=!0,this[i+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...u}),E["_"+i+"ListenClick"]&&s&&s===l&&(l._fireAndBubble(e.pointerclick,{...u}),d&&n&&n===l&&l._fireAndBubble(e.pointerdblclick,{...u}))):(this[i+"ClickEndShape"]=null,o||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),o=!0),E["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:c}),d&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:c}))}),o||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),E["_"+i+"ListenClick"]=!1,t.cancelable&&i!=="touch"&&i!=="pointer"&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ae,{evt:t}):this._fire(Ae,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ee,{evt:t}):this._fire(Ee,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=_e(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(Dt,Ne(t)),jt(t.pointerId)}_lostpointercapture(t){jt(t.pointerId)}setPointersPositions(t){const e=this._getContentPosition();let i=null,s=null;t=t||window.event,t.touches!==void 0?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,n=>{this._pointerPositions.push({id:n.identifier,x:(n.clientX-e.left)/e.scaleX,y:(n.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,n=>{this._changedPointerPositions.push({id:n.identifier,x:(n.clientX-e.left)/e.scaleX,y:(n.clientY-e.top)/e.scaleY})})):(i=(t.clientX-e.left)/e.scaleX,s=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:s},this._pointerPositions=[{x:i,y:s,id:_._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:s,id:_._getFirstPointerId(t)}])}_setPointerPosition(t){_.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(t)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};const t=this.content.getBoundingClientRect();return{top:t.top,left:t.left,scaleX:t.width/this.content.clientWidth||1,scaleY:t.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new _t({width:this.width(),height:this.height()}),this.bufferHitCanvas=new Fe({pixelRatio:1,width:this.width(),height:this.height()}),!E.isBrowser)return;const t=this.container();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.userSelect="none",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}cache(){return _.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes."),this}clearCache(){return this}batchDraw(){return this.getChildren().forEach(function(t){t.batchDraw()}),this}}me.prototype.nodeType=Ws;tt(me);g.addGetterSetter(me,"container");E.isBrowser&&document.addEventListener("visibilitychange",()=>{qt.forEach(a=>{a.batchDraw()})});const Ri="hasShadow",Mi="shadowRGBA",Li="patternImage",Di="linearGradient",Gi="radialGradient";let re;function Se(){return re||(re=_.createCanvasElement().getContext("2d"),re)}const $t={};function $s(a){const t=this.attrs.fillRule;t?a.fill(t):a.fill()}function Ks(a){a.stroke()}function Zs(a){const t=this.attrs.fillRule;t?a.fill(t):a.fill()}function Js(a){a.stroke()}function Qs(){this._clearCache(Ri)}function tn(){this._clearCache(Mi)}function en(){this._clearCache(Li)}function sn(){this._clearCache(Di)}function nn(){this._clearCache(Gi)}class T extends x{constructor(t){super(t);let e,i=0;for(;e=_.getHitColor(),!(e&&!(e in $t));)if(i++,i>=1e4){_.warn("Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it."),e=_.getRandomColor();break}this.colorKey=e,$t[e]=this}getContext(){return _.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return _.warn("shape.getCanvas() method is deprecated. Please do not use it."),this.getLayer().getCanvas()}getSceneFunc(){return this.attrs.sceneFunc||this._sceneFunc}getHitFunc(){return this.attrs.hitFunc||this._hitFunc}hasShadow(){return this._getCache(Ri,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Li,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const e=Se().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){const i=new rt;i.translate(this.fillPatternX(),this.fillPatternY()),i.rotate(E.getAngle(this.fillPatternRotation())),i.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),i.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const s=i.getMatrix(),n=typeof DOMMatrix>"u"?{a:s[0],b:s[1],c:s[2],d:s[3],e:s[4],f:s[5]}:new DOMMatrix(s);e.setTransform(n)}return e}}_getLinearGradient(){return this._getCache(Di,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=Se(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),n=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let r=0;r<t.length;r+=2)n.addColorStop(t[r],t[r+1]);return n}}_getRadialGradient(){return this._getCache(Gi,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=Se(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),n=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let r=0;r<t.length;r+=2)n.addColorStop(t[r],t[r+1]);return n}}getShadowRGBA(){return this._getCache(Mi,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=_.colorToRGBA(this.shadowColor());if(t)return"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")"}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){const t=this.hitStrokeWidth();return t==="auto"?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){const e=this.getStage();if(!e)return!1;const i=e.bufferHitCanvas;return i.getContext().clear(),this.drawHit(i,void 0,!0),i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return x.prototype.destroy.call(this),delete $t[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!((e=this.attrs.perfectDrawEnabled)!==null&&e!==void 0?e:!0))return!1;const s=t||this.hasFill(),n=this.hasStroke(),r=this.getAbsoluteOpacity()!==1;if(s&&n&&r)return!0;const o=this.hasShadow(),h=this.shadowForStrokeEnabled();return!!(s&&n&&o&&h)}setStrokeHitEnabled(t){_.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){const t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){let e=!1,i=this.getParent();for(;i;){if(i.isCached()){e=!0;break}i=i.getParent()}const s=t.skipTransform,n=t.relativeTo||e&&this.getStage()||void 0,r=this.getSelfRect(),h=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,l=r.width+h,c=r.height+h,u=!t.skipShadow&&this.hasShadow(),d=u?this.shadowOffsetX():0,p=u?this.shadowOffsetY():0,f=l+Math.abs(d),m=c+Math.abs(p),y=u&&this.shadowBlur()||0,C=f+y*2,S=m+y*2,b={width:C,height:S,x:-(h/2+y)+Math.min(d,0)+r.x,y:-(h/2+y)+Math.min(p,0)+r.y};return s?b:this._transformedRect(b,n)}drawScene(t,e,i){const s=this.getLayer(),n=t||s.getCanvas(),r=n.getContext(),o=this._getCanvasCache(),h=this.getSceneFunc(),l=this.hasShadow();let c;const u=e===this;if(!this.isVisible()&&!u)return this;if(o){r.save();const d=this.getAbsoluteTransform(e).getMatrix();return r.transform(d[0],d[1],d[2],d[3],d[4],d[5]),this._drawCachedSceneCanvas(r),r.restore(),this}if(!h)return this;if(r.save(),this._useBufferCanvas()){c=this.getStage();const d=i||c.bufferCanvas,p=d.getContext();i?(p.save(),p.setTransform(1,0,0,1,0,0),p.clearRect(0,0,d.width,d.height),p.restore()):p.clear(),p.save(),p._applyLineJoin(this),p._applyMiterLimit(this);const f=this.getAbsoluteTransform(e).getMatrix();p.transform(f[0],f[1],f[2],f[3],f[4],f[5]),h.call(this,p,this),p.restore();const m=d.pixelRatio;l&&r._applyShadow(this),u||(r._applyOpacity(this),r._applyGlobalCompositeOperation(this)),r.drawImage(d._canvas,d.x||0,d.y||0,d.width/m,d.height/m)}else{if(r._applyLineJoin(this),r._applyMiterLimit(this),!u){const d=this.getAbsoluteTransform(e).getMatrix();r.transform(d[0],d[1],d[2],d[3],d[4],d[5]),r._applyOpacity(this),r._applyGlobalCompositeOperation(this)}l&&r._applyShadow(this),h.call(this,r,this)}return r.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),n=t||s.hitCanvas,r=n&&n.getContext(),o=this.hitFunc()||this.sceneFunc(),h=this._getCanvasCache(),l=h&&h.hit;if(this.colorKey||_.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){r.save();const u=this.getAbsoluteTransform(e).getMatrix();return r.transform(u[0],u[1],u[2],u[3],u[4],u[5]),this._drawCachedHitCanvas(r),r.restore(),this}if(!o)return this;if(r.save(),r._applyLineJoin(this),r._applyMiterLimit(this),!(this===e)){const u=this.getAbsoluteTransform(e).getMatrix();r.transform(u[0],u[1],u[2],u[3],u[4],u[5])}return o.call(this,r,this),r.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,n=s.getContext(),r=s.getWidth(),o=s.getHeight();n.clear(),n.drawImage(i._canvas,0,0,r,o);try{const h=n.getImageData(0,0,r,o),l=h.data,c=l.length,u=_._hexToRgb(this.colorKey);for(let d=0;d<c;d+=4)l[d+3]>t?(l[d]=u.r,l[d+1]=u.g,l[d+2]=u.b,l[d+3]=255):l[d+3]=0;n.putImageData(h,0,0)}catch(h){_.error("Unable to draw hit graph from cached scene canvas. "+h.message)}return this}hasPointerCapture(t){return _i(t,this)}setPointerCapture(t){Ci(t,this)}releaseCapture(t){jt(t)}}T.prototype._fillFunc=$s;T.prototype._strokeFunc=Ks;T.prototype._fillFuncHit=Zs;T.prototype._strokeFuncHit=Js;T.prototype._centroid=!1;T.prototype.nodeType="Shape";tt(T);T.prototype.eventListeners={};T.prototype.on.call(T.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",Qs);T.prototype.on.call(T.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",tn);T.prototype.on.call(T.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",en);T.prototype.on.call(T.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",sn);T.prototype.on.call(T.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",nn);g.addGetterSetter(T,"stroke",void 0,mi());g.addGetterSetter(T,"strokeWidth",2,k());g.addGetterSetter(T,"fillAfterStrokeEnabled",!1);g.addGetterSetter(T,"hitStrokeWidth","auto",Be());g.addGetterSetter(T,"strokeHitEnabled",!0,ht());g.addGetterSetter(T,"perfectDrawEnabled",!0,ht());g.addGetterSetter(T,"shadowForStrokeEnabled",!0,ht());g.addGetterSetter(T,"lineJoin");g.addGetterSetter(T,"lineCap");g.addGetterSetter(T,"miterLimit");g.addGetterSetter(T,"sceneFunc");g.addGetterSetter(T,"hitFunc");g.addGetterSetter(T,"dash");g.addGetterSetter(T,"dashOffset",0,k());g.addGetterSetter(T,"shadowColor",void 0,kt());g.addGetterSetter(T,"shadowBlur",0,k());g.addGetterSetter(T,"shadowOpacity",1,k());g.addComponentsGetterSetter(T,"shadowOffset",["x","y"]);g.addGetterSetter(T,"shadowOffsetX",0,k());g.addGetterSetter(T,"shadowOffsetY",0,k());g.addGetterSetter(T,"fillPatternImage");g.addGetterSetter(T,"fill",void 0,mi());g.addGetterSetter(T,"fillPatternX",0,k());g.addGetterSetter(T,"fillPatternY",0,k());g.addGetterSetter(T,"fillLinearGradientColorStops");g.addGetterSetter(T,"strokeLinearGradientColorStops");g.addGetterSetter(T,"fillRadialGradientStartRadius",0);g.addGetterSetter(T,"fillRadialGradientEndRadius",0);g.addGetterSetter(T,"fillRadialGradientColorStops");g.addGetterSetter(T,"fillPatternRepeat","repeat");g.addGetterSetter(T,"fillEnabled",!0);g.addGetterSetter(T,"strokeEnabled",!0);g.addGetterSetter(T,"shadowEnabled",!0);g.addGetterSetter(T,"dashEnabled",!0);g.addGetterSetter(T,"strokeScaleEnabled",!0);g.addGetterSetter(T,"fillPriority","color");g.addComponentsGetterSetter(T,"fillPatternOffset",["x","y"]);g.addGetterSetter(T,"fillPatternOffsetX",0,k());g.addGetterSetter(T,"fillPatternOffsetY",0,k());g.addComponentsGetterSetter(T,"fillPatternScale",["x","y"]);g.addGetterSetter(T,"fillPatternScaleX",1,k());g.addGetterSetter(T,"fillPatternScaleY",1,k());g.addComponentsGetterSetter(T,"fillLinearGradientStartPoint",["x","y"]);g.addComponentsGetterSetter(T,"strokeLinearGradientStartPoint",["x","y"]);g.addGetterSetter(T,"fillLinearGradientStartPointX",0);g.addGetterSetter(T,"strokeLinearGradientStartPointX",0);g.addGetterSetter(T,"fillLinearGradientStartPointY",0);g.addGetterSetter(T,"strokeLinearGradientStartPointY",0);g.addComponentsGetterSetter(T,"fillLinearGradientEndPoint",["x","y"]);g.addComponentsGetterSetter(T,"strokeLinearGradientEndPoint",["x","y"]);g.addGetterSetter(T,"fillLinearGradientEndPointX",0);g.addGetterSetter(T,"strokeLinearGradientEndPointX",0);g.addGetterSetter(T,"fillLinearGradientEndPointY",0);g.addGetterSetter(T,"strokeLinearGradientEndPointY",0);g.addComponentsGetterSetter(T,"fillRadialGradientStartPoint",["x","y"]);g.addGetterSetter(T,"fillRadialGradientStartPointX",0);g.addGetterSetter(T,"fillRadialGradientStartPointY",0);g.addComponentsGetterSetter(T,"fillRadialGradientEndPoint",["x","y"]);g.addGetterSetter(T,"fillRadialGradientEndPointX",0);g.addGetterSetter(T,"fillRadialGradientEndPointY",0);g.addGetterSetter(T,"fillPatternRotation",0);g.addGetterSetter(T,"fillRule",void 0,kt());g.backCompat(T,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const rn="beforeDraw",an="draw",Ii=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],on=Ii.length;class At extends at{constructor(t){super(t),this.canvas=new _t,this.hitCanvas=new Fe({pixelRatio:1}),this._waitingForDraw=!1,this.on("visibleChange.konva",this._checkVisibility),this._checkVisibility(),this.on("imageSmoothingEnabledChange.konva",this._setSmoothEnabled),this._setSmoothEnabled()}createPNGStream(){return this.canvas._canvas.createPNGStream()}getCanvas(){return this.canvas}getNativeCanvasElement(){return this.canvas._canvas}getHitCanvas(){return this.hitCanvas}getContext(){return this.getCanvas().getContext()}clear(t){return this.getContext().clear(t),this.getHitCanvas().getContext().clear(t),this}setZIndex(t){super.setZIndex(t);const e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),t<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[t+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement())),this}moveToTop(){x.prototype.moveToTop.call(this);const t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!x.prototype.moveUp.call(this))return!1;const e=this.getStage();return!e||!e.content?!1:(e.content.removeChild(this.getNativeCanvasElement()),this.index<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[this.index+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(x.prototype.moveDown.call(this)){const t=this.getStage();if(t){const e=t.children;t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.insertBefore(this.getNativeCanvasElement(),e[this.index+1].getCanvas()._canvas))}return!0}return!1}moveToBottom(){if(x.prototype.moveToBottom.call(this)){const t=this.getStage();if(t){const e=t.children;t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.insertBefore(this.getNativeCanvasElement(),e[1].getCanvas()._canvas))}return!0}return!1}getLayer(){return this}remove(){const t=this.getNativeCanvasElement();return x.prototype.remove.call(this),t&&t.parentNode&&_._isInDocument(t)&&t.parentNode.removeChild(t),this}getStage(){return this.parent}setSize({width:t,height:e}){return this.canvas.setSize(t,e),this.hitCanvas.setSize(t,e),this._setSmoothEnabled(),this}_validateAdd(t){const e=t.getType();e!=="Group"&&e!=="Shape"&&_.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return t={...t},t.width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=t.x!==void 0?t.x:this.x(),t.y=t.y!==void 0?t.y:this.y(),x.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){this.visible()?this.canvas._canvas.style.display="block":this.canvas._canvas.style.display="none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){_.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){_.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,_.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;let e=1,i=!1;for(;;){for(let s=0;s<on;s++){const n=Ii[s],r=this._getIntersection({x:t.x+n.x*e,y:t.y+n.y*e}),o=r.shape;if(o)return o;if(i=!!r.antialiased,!r.antialiased)break}if(i)e+=1;else return null}}_getIntersection(t){const e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,s=i[3];if(s===255){const n=_.getHitColorKey(i[0],i[1],i[2]),r=$t[n];return r?{shape:r}:{antialiased:!0}}else if(s>0)return{antialiased:!0};return{}}drawScene(t,e,i){const s=this.getLayer(),n=t||s&&s.getCanvas();return this._fire(rn,{node:this}),this.clearBeforeDraw()&&n.getContext().clear(),at.prototype.drawScene.call(this,n,e,i),this._fire(an,{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),at.prototype.drawHit.call(this,s,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){_.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return _.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;const t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}destroy(){return _.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}At.prototype.nodeType="Layer";tt(At);g.addGetterSetter(At,"imageSmoothingEnabled",!0);g.addGetterSetter(At,"clearBeforeDraw",!0);g.addGetterSetter(At,"hitGraphEnabled",!0,ht());class He extends At{constructor(t){super(t),this.listening(!1),_.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}He.prototype.nodeType="FastLayer";tt(He);class Gt extends at{_validateAdd(t){const e=t.getType();e!=="Group"&&e!=="Shape"&&_.throw("You may only add groups and shapes to groups.")}}Gt.prototype.nodeType="Group";tt(Gt);const be=function(){return xt.performance&&xt.performance.now?function(){return xt.performance.now()}:function(){return new Date().getTime()}}();class ot{constructor(t,e){this.id=ot.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:be(),frameRate:0},this.func=t,this.setLayers(e)}setLayers(t){let e=[];return t&&(e=Array.isArray(t)?t:[t]),this.layers=e,this}getLayers(){return this.layers}addLayer(t){const e=this.layers,i=e.length;for(let s=0;s<i;s++)if(e[s]._id===t._id)return!1;return this.layers.push(t),!0}isRunning(){const e=ot.animations,i=e.length;for(let s=0;s<i;s++)if(e[s].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=be(),ot._addAnimation(this),this}stop(){return ot._removeAnimation(this),this}_updateFrameObject(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(t){this.animations.push(t),this._handleAnimation()}static _removeAnimation(t){const e=t.id,i=this.animations,s=i.length;for(let n=0;n<s;n++)if(i[n].id===e){this.animations.splice(n,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],n=s.layers,r=s.func;s._updateFrameObject(be());const o=n.length;let h;if(r?h=r.call(s,s.frame)!==!1:h=!0,!!h)for(let l=0;l<o;l++){const c=n[l];c._id!==void 0&&(t[c._id]=c)}}for(const i in t)t.hasOwnProperty(i)&&t[i].batchDraw()}static _animationLoop(){const t=ot;t.animations.length?(t._runFrames(),_.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,_.requestAnimFrame(this._animationLoop))}}ot.animations=[];ot.animIdCounter=0;ot.animRunning=!1;const hn={node:1,duration:1,easing:1,onFinish:1,yoyo:1},ln=1,ti=2,ei=3,ii=["fill","stroke","shadowColor"];let cn=0;class dn{constructor(t,e,i,s,n,r,o){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=r,this._change=0,this.prevPos=0,this.yoyo=o,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=n-this.begin,this.pause()}fire(t){const e=this[t];e&&e()}setTime(t){t>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return t===void 0&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=ti,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=ei,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const t=this.getTimer()-this._startTime;this.state===ti?this.setTime(t):this.state===ei&&this.setTime(this.duration-t)}pause(){this.state=ln,this.fire("onPause")}getTimer(){return new Date().getTime()}}class K{constructor(t){const e=this,i=t.node,s=i._id,n=t.easing||Kt.Linear,r=!!t.yoyo;let o,h;typeof t.duration>"u"?o=.3:t.duration===0?o=.001:o=t.duration,this.node=i,this._id=cn++;const l=i.getLayer()||(i instanceof E.Stage?i.getLayers():null);l||_.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new ot(function(){e.tween.onEnterFrame()},l),this.tween=new dn(h,function(c){e._tweenFunc(c)},n,0,1,o*1e3,r),this._addListeners(),K.attrs[s]||(K.attrs[s]={}),K.attrs[s][this._id]||(K.attrs[s][this._id]={}),K.tweens[s]||(K.tweens[s]={});for(h in t)hn[h]===void 0&&this._addAttr(h,t[h]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){const i=this.node,s=i._id;let n,r,o,h,l;const c=K.tweens[s][t];c&&delete K.attrs[s][c][t];let u=i.getAttr(t);if(_._isArray(e))if(n=[],r=Math.max(e.length,u.length),t==="points"&&e.length!==u.length&&(e.length>u.length?(h=u,u=_._prepareArrayForTween(u,e,i.closed())):(o=e,e=_._prepareArrayForTween(e,u,i.closed()))),t.indexOf("fill")===0)for(let d=0;d<r;d++)if(d%2===0)n.push(e[d]-u[d]);else{const p=_.colorToRGBA(u[d]);l=_.colorToRGBA(e[d]),u[d]=p,n.push({r:l.r-p.r,g:l.g-p.g,b:l.b-p.b,a:l.a-p.a})}else for(let d=0;d<r;d++)n.push(e[d]-u[d]);else ii.indexOf(t)!==-1?(u=_.colorToRGBA(u),l=_.colorToRGBA(e),n={r:l.r-u.r,g:l.g-u.g,b:l.b-u.b,a:l.a-u.a}):n=e-u;K.attrs[s][this._id][t]={start:u,diff:n,end:e,trueEnd:o,trueStart:h},K.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=K.attrs[e._id][this._id];let s,n,r,o,h,l,c,u;for(s in i){if(n=i[s],r=n.start,o=n.diff,u=n.end,_._isArray(r))if(h=[],c=Math.max(r.length,u.length),s.indexOf("fill")===0)for(l=0;l<c;l++)l%2===0?h.push((r[l]||0)+o[l]*t):h.push("rgba("+Math.round(r[l].r+o[l].r*t)+","+Math.round(r[l].g+o[l].g*t)+","+Math.round(r[l].b+o[l].b*t)+","+(r[l].a+o[l].a*t)+")");else for(l=0;l<c;l++)h.push((r[l]||0)+o[l]*t);else ii.indexOf(s)!==-1?h="rgba("+Math.round(r.r+o.r*t)+","+Math.round(r.g+o.g*t)+","+Math.round(r.b+o.b*t)+","+(r.a+o.a*t)+")":h=r+o*t;e.setAttr(s,h)}}_addListeners(){this.tween.onPlay=()=>{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{const t=this.node,e=K.attrs[t._id][this._id];e.points&&e.points.trueEnd&&t.setAttr("points",e.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{const t=this.node,e=K.attrs[t._id][this._id];e.points&&e.points.trueStart&&t.points(e.points.trueStart),this.onReset&&this.onReset()},this.tween.onUpdate=()=>{this.onUpdate&&this.onUpdate.call(this)}}play(){return this.tween.play(),this}reverse(){return this.tween.reverse(),this}reset(){return this.tween.reset(),this}seek(t){return this.tween.seek(t*1e3),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){const t=this.node._id,e=this._id,i=K.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const s in i)delete K.tweens[t][s];delete K.attrs[t][e],K.tweens[t]&&(Object.keys(K.tweens[t]).length===0&&delete K.tweens[t],Object.keys(K.attrs[t]).length===0&&delete K.attrs[t])}}K.attrs={};K.tweens={};x.prototype.to=function(a){const t=a.onFinish;a.node=this,a.onFinish=function(){this.destroy(),t&&t()},new K(a).play()};const Kt={BackEaseIn(a,t,e,i){return e*(a/=i)*a*((1.70158+1)*a-1.70158)+t},BackEaseOut(a,t,e,i){return e*((a=a/i-1)*a*((1.70158+1)*a+1.70158)+1)+t},BackEaseInOut(a,t,e,i){let s=1.70158;return(a/=i/2)<1?e/2*(a*a*(((s*=1.525)+1)*a-s))+t:e/2*((a-=2)*a*(((s*=1.525)+1)*a+s)+2)+t},ElasticEaseIn(a,t,e,i,s,n){let r=0;return a===0?t:(a/=i)===1?t+e:(n||(n=i*.3),!s||s<Math.abs(e)?(s=e,r=n/4):r=n/(2*Math.PI)*Math.asin(e/s),-(s*Math.pow(2,10*(a-=1))*Math.sin((a*i-r)*(2*Math.PI)/n))+t)},ElasticEaseOut(a,t,e,i,s,n){let r=0;return a===0?t:(a/=i)===1?t+e:(n||(n=i*.3),!s||s<Math.abs(e)?(s=e,r=n/4):r=n/(2*Math.PI)*Math.asin(e/s),s*Math.pow(2,-10*a)*Math.sin((a*i-r)*(2*Math.PI)/n)+e+t)},ElasticEaseInOut(a,t,e,i,s,n){let r=0;return a===0?t:(a/=i/2)===2?t+e:(n||(n=i*(.3*1.5)),!s||s<Math.abs(e)?(s=e,r=n/4):r=n/(2*Math.PI)*Math.asin(e/s),a<1?-.5*(s*Math.pow(2,10*(a-=1))*Math.sin((a*i-r)*(2*Math.PI)/n))+t:s*Math.pow(2,-10*(a-=1))*Math.sin((a*i-r)*(2*Math.PI)/n)*.5+e+t)},BounceEaseOut(a,t,e,i){return(a/=i)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t},BounceEaseIn(a,t,e,i){return e-Kt.BounceEaseOut(i-a,0,e,i)+t},BounceEaseInOut(a,t,e,i){return a<i/2?Kt.BounceEaseIn(a*2,0,e,i)*.5+t:Kt.BounceEaseOut(a*2-i,0,e,i)*.5+e*.5+t},EaseIn(a,t,e,i){return e*(a/=i)*a+t},EaseOut(a,t,e,i){return-e*(a/=i)*(a-2)+t},EaseInOut(a,t,e,i){return(a/=i/2)<1?e/2*a*a+t:-e/2*(--a*(a-2)-1)+t},StrongEaseIn(a,t,e,i){return e*(a/=i)*a*a*a*a+t},StrongEaseOut(a,t,e,i){return e*((a=a/i-1)*a*a*a*a+1)+t},StrongEaseInOut(a,t,e,i){return(a/=i/2)<1?e/2*a*a*a*a*a+t:e/2*((a-=2)*a*a*a*a+2)+t},Linear(a,t,e,i){return e*a/i+t}},si=_._assign(E,{Util:_,Transform:rt,Node:x,Container:at,Stage:me,stages:qt,Layer:At,FastLayer:He,Group:Gt,DD:X,Shape:T,shapes:$t,Animation:ot,Tween:K,Easings:Kt,Context:ge,Canvas:Oe});class ft extends T{_sceneFunc(t){const e=E.getAngle(this.angle()),i=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,i),t.arc(0,0,this.innerRadius(),e,0,!i),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),i=this.clockwise(),s=E.getAngle(i?360-this.angle():this.angle()),n=Math.cos(Math.min(s,Math.PI)),r=1,o=Math.sin(Math.min(Math.max(Math.PI,s),3*Math.PI/2)),h=Math.sin(Math.min(s,Math.PI/2)),l=n*(n>0?t:e),c=r*e,u=o*(o>0?t:e),d=h*(h>0?e:t);return{x:l,y:i?-1*d:u,width:c-l,height:d-u}}}ft.prototype._centroid=!0;ft.prototype.className="Arc";ft.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"];tt(ft);g.addGetterSetter(ft,"innerRadius",0,k());g.addGetterSetter(ft,"outerRadius",0,k());g.addGetterSetter(ft,"angle",0,k());g.addGetterSetter(ft,"clockwise",!1,ht());function Pe(a,t,e,i,s,n,r){const o=Math.sqrt(Math.pow(e-a,2)+Math.pow(i-t,2)),h=Math.sqrt(Math.pow(s-e,2)+Math.pow(n-i,2)),l=r*o/(o+h),c=r*h/(o+h),u=e-l*(s-a),d=i-l*(n-t),p=e+c*(s-a),f=i+c*(n-t);return[u,d,p,f]}function ni(a,t){const e=a.length,i=[];for(let s=2;s<e-2;s+=2){const n=Pe(a[s-2],a[s-1],a[s],a[s+1],a[s+2],a[s+3],t);isNaN(n[0])||(i.push(n[0]),i.push(n[1]),i.push(a[s]),i.push(a[s+1]),i.push(n[2]),i.push(n[3]))}return i}function un(a){const t=[[a[0],a[2],a[4],a[6]],[a[1],a[3],a[5],a[7]]],e=[];for(const i of t){const s=-3*i[0]+9*i[1]-9*i[2]+3*i[3];if(s!==0){const n=6*i[0]-12*i[1]+6*i[2],r=-3*i[0]+3*i[1],o=n*n-4*s*r;if(o>=0){const h=Math.sqrt(o);e.push((-n+h)/(2*s)),e.push((-n-h)/(2*s))}}}return e.filter(i=>i>0&&i<1).flatMap(i=>t.map(s=>{const n=1-i;return n*n*n*s[0]+3*n*n*i*s[1]+3*n*i*i*s[2]+i*i*i*s[3]}))}class gt extends T{constructor(t){super(t),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(t){const e=this.points(),i=e.length,s=this.tension(),n=this.closed(),r=this.bezier();if(!i)return;let o=0;if(t.beginPath(),t.moveTo(e[0],e[1]),s!==0&&i>4){const h=this.getTensionPoints(),l=h.length;for(o=n?0:4,n||t.quadraticCurveTo(h[0],h[1],h[2],h[3]);o<l-2;)t.bezierCurveTo(h[o++],h[o++],h[o++],h[o++],h[o++],h[o++]);n||t.quadraticCurveTo(h[l-2],h[l-1],e[i-2],e[i-1])}else if(r)for(o=2;o<i;)t.bezierCurveTo(e[o++],e[o++],e[o++],e[o++],e[o++],e[o++]);else for(o=2;o<i;o+=2)t.lineTo(e[o],e[o+1]);n?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():ni(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=Pe(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),n=Pe(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),r=ni(t,i);return[s[2],s[3]].concat(r).concat([n[0],n[1],t[e-2],t[e-1],n[2],n[3],s[0],s[1],t[0],t[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let t=this.points();if(t.length<4)return{x:t[0]||0,y:t[1]||0,width:0,height:0};this.tension()!==0?t=[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.bezier()?t=[t[0],t[1],...un(this.points()),t[t.length-2],t[t.length-1]]:t=this.points();let e=t[0],i=t[0],s=t[1],n=t[1],r,o;for(let h=0;h<t.length/2;h++)r=t[h*2],o=t[h*2+1],e=Math.min(e,r),i=Math.max(i,r),s=Math.min(s,o),n=Math.max(n,o);return{x:e,y:s,width:i-e,height:n-s}}}gt.prototype.className="Line";gt.prototype._attrsAffectingSize=["points","bezier","tension"];tt(gt);g.addGetterSetter(gt,"closed",!1);g.addGetterSetter(gt,"bezier",!1);g.addGetterSetter(gt,"tension",0,k());g.addGetterSetter(gt,"points",[],As());const fn=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],gn=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],pn=[[1],[1,1],[1,2,1],[1,3,3,1]],ri=(a,t,e)=>{let i,s;const r=e/2;i=0;for(let o=0;o<20;o++)s=r*fn[20][o]+r,i+=gn[20][o]*mn(a,t,s);return r*i},ai=(a,t,e)=>{e===void 0&&(e=1);const i=a[0]-2*a[1]+a[2],s=t[0]-2*t[1]+t[2],n=2*a[1]-2*a[0],r=2*t[1]-2*t[0],o=4*(i*i+s*s),h=4*(i*n+s*r),l=n*n+r*r;if(o===0)return e*Math.sqrt(Math.pow(a[2]-a[0],2)+Math.pow(t[2]-t[0],2));const c=h/(2*o),u=l/o,d=e+c,p=u-c*c,f=d*d+p>0?Math.sqrt(d*d+p):0,m=c*c+p>0?Math.sqrt(c*c+p):0,y=c+Math.sqrt(c*c+p)!==0?p*Math.log(Math.abs((d+f)/(c+m))):0;return Math.sqrt(o)/2*(d*f-c*m+y)};function mn(a,t,e){const i=Re(1,e,a),s=Re(1,e,t),n=i*i+s*s;return Math.sqrt(n)}const Re=(a,t,e)=>{const i=e.length-1;let s,n;if(i===0)return 0;if(a===0){n=0;for(let r=0;r<=i;r++)n+=pn[i][r]*Math.pow(1-t,i-r)*Math.pow(t,r)*e[r];return n}else{s=new Array(i);for(let r=0;r<i;r++)s[r]=i*(e[r+1]-e[r]);return Re(a-1,t,s)}},oi=(a,t,e)=>{let i=1,s=a/t,n=(a-e(s))/t,r=0;for(;i>.001;){const o=e(s+n),h=Math.abs(a-o)/t;if(h<i)i=h,s+=n;else{const l=e(s-n),c=Math.abs(a-l)/t;c<i?(i=c,s-=n):n/=2}if(r++,r>500)break}return s};class Z extends T{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=Z.parsePathData(this.data()),this.pathLength=Z.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const n=e[s].command,r=e[s].points;switch(n){case"L":t.lineTo(r[0],r[1]);break;case"M":t.moveTo(r[0],r[1]);break;case"C":t.bezierCurveTo(r[0],r[1],r[2],r[3],r[4],r[5]);break;case"Q":t.quadraticCurveTo(r[0],r[1],r[2],r[3]);break;case"A":const o=r[0],h=r[1],l=r[2],c=r[3],u=r[4],d=r[5],p=r[6],f=r[7],m=l>c?l:c,y=l>c?1:l/c,C=l>c?c/l:1;t.translate(o,h),t.rotate(p),t.scale(y,C),t.arc(0,0,m,u,u+d,1-f),t.scale(1/y,1/C),t.rotate(-p),t.translate(-o,-h);break;case"z":i=!0,t.closePath();break}}!i&&!this.hasFill()?t.strokeShape(this):t.fillStrokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(h){if(h.command==="A"){const l=h.points[4],c=h.points[5],u=h.points[4]+c;let d=Math.PI/180;if(Math.abs(l-u)<d&&(d=Math.abs(l-u)),c<0)for(let p=l-d;p>u;p-=d){const f=Z.getPointOnEllipticalArc(h.points[0],h.points[1],h.points[2],h.points[3],p,0);t.push(f.x,f.y)}else for(let p=l+d;p<u;p+=d){const f=Z.getPointOnEllipticalArc(h.points[0],h.points[1],h.points[2],h.points[3],p,0);t.push(f.x,f.y)}}else if(h.command==="C")for(let l=0;l<=1;l+=.01){const c=Z.getPointOnCubicBezier(l,h.start.x,h.start.y,h.points[0],h.points[1],h.points[2],h.points[3],h.points[4],h.points[5]);t.push(c.x,c.y)}else t=t.concat(h.points)});let e=t[0],i=t[0],s=t[1],n=t[1],r,o;for(let h=0;h<t.length/2;h++)r=t[h*2],o=t[h*2+1],isNaN(r)||(e=Math.min(e,r),i=Math.max(i,r)),isNaN(o)||(s=Math.min(s,o),n=Math.max(n,o));return{x:e,y:s,width:i-e,height:n-s}}getLength(){return this.pathLength}getPointAtLength(t){return Z.getPointAtLengthOfDataArray(t,this.dataArray)}static getLineLength(t,e,i,s){return Math.sqrt((i-t)*(i-t)+(s-e)*(s-e))}static getPathLength(t){let e=0;for(let i=0;i<t.length;++i)e+=t[i].pathLength;return e}static getPointAtLengthOfDataArray(t,e){let i,s=0,n=e.length;if(!n)return null;for(;s<n&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===n)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01)return e[s].command==="M"?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y};const r=e[s],o=r.points;switch(r.command){case"L":return Z.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return Z.getPointOnCubicBezier(oi(t,Z.getPathLength(e),m=>ri([r.start.x,o[0],o[2],o[4]],[r.start.y,o[1],o[3],o[5]],m)),r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return Z.getPointOnQuadraticBezier(oi(t,Z.getPathLength(e),m=>ai([r.start.x,o[0],o[2]],[r.start.y,o[1],o[3]],m)),r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":const h=o[0],l=o[1],c=o[2],u=o[3],d=o[5],p=o[6];let f=o[4];return f+=d*t/r.pathLength,Z.getPointOnEllipticalArc(h,l,c,u,f,p)}return null}static getPointOnLine(t,e,i,s,n,r,o){r=r??e,o=o??i;const h=this.getLineLength(e,i,s,n);if(h<1e-10)return{x:e,y:i};if(s===e)return{x:r,y:o+(n>i?t:-t)};const l=(n-i)/(s-e),c=Math.sqrt(t*t/(1+l*l))*(s<e?-1:1),u=l*c;if(Math.abs(o-i-l*(r-e))<1e-10)return{x:r+c,y:o+u};const d=((r-e)*(s-e)+(o-i)*(n-i))/(h*h),p=e+d*(s-e),f=i+d*(n-i),m=this.getLineLength(r,o,p,f),y=Math.sqrt(t*t-m*m),C=Math.sqrt(y*y/(1+l*l))*(s<e?-1:1),S=l*C;return{x:p+C,y:f+S}}static getPointOnCubicBezier(t,e,i,s,n,r,o,h,l){function c(y){return y*y*y}function u(y){return 3*y*y*(1-y)}function d(y){return 3*y*(1-y)*(1-y)}function p(y){return(1-y)*(1-y)*(1-y)}const f=h*c(t)+r*u(t)+s*d(t)+e*p(t),m=l*c(t)+o*u(t)+n*d(t)+i*p(t);return{x:f,y:m}}static getPointOnQuadraticBezier(t,e,i,s,n,r,o){function h(p){return p*p}function l(p){return 2*p*(1-p)}function c(p){return(1-p)*(1-p)}const u=r*h(t)+s*l(t)+e*c(t),d=o*h(t)+n*l(t)+i*c(t);return{x:u,y:d}}static getPointOnEllipticalArc(t,e,i,s,n,r){const o=Math.cos(r),h=Math.sin(r),l={x:i*Math.cos(n),y:s*Math.sin(n)};return{x:t+(l.x*o-l.y*h),y:e+(l.x*h+l.y*o)}}static parsePathData(t){if(!t)return[];let e=t;const i=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];e=e.replace(new RegExp(" ","g"),",");for(let u=0;u<i.length;u++)e=e.replace(new RegExp(i[u],"g"),"|"+i[u]);const s=e.split("|"),n=[],r=[];let o=0,h=0;const l=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let c;for(let u=1;u<s.length;u++){let d=s[u],p=d.charAt(0);for(d=d.slice(1),r.length=0;c=l.exec(d);)r.push(c[0]);let f=[],m=p==="A"||p==="a"?0:-1;for(let y=0,C=r.length;y<C;y++){const S=r[y];if(S==="00"){f.push(0,0),m>=0&&(m+=2,m>=7&&(m-=7));continue}if(m>=0){if(m===3){if(/^[01]{2}\d+(?:\.\d+)?$/.test(S)){f.push(parseInt(S[0],10)),f.push(parseInt(S[1],10)),f.push(parseFloat(S.slice(2))),m+=3,m>=7&&(m-=7);continue}if(S==="11"||S==="10"||S==="01"){f.push(parseInt(S[0],10)),f.push(parseInt(S[1],10)),m+=2,m>=7&&(m-=7);continue}if(S==="0"||S==="1"){f.push(parseInt(S,10)),m+=1,m>=7&&(m-=7);continue}}else if(m===4){if(/^[01]\d+(?:\.\d+)?$/.test(S)){f.push(parseInt(S[0],10)),f.push(parseFloat(S.slice(1))),m+=2,m>=7&&(m-=7);continue}if(S==="0"||S==="1"){f.push(parseInt(S,10)),m+=1,m>=7&&(m-=7);continue}}const b=parseFloat(S);isNaN(b)?f.push(0):f.push(b),m+=1,m>=7&&(m-=7)}else{const b=parseFloat(S);isNaN(b)?f.push(0):f.push(b)}}for(;f.length>0&&!isNaN(f[0]);){let y="",C=[];const S=o,b=h;let v,P,w,D,M,G,I,W,F,U;switch(p){case"l":o+=f.shift(),h+=f.shift(),y="L",C.push(o,h);break;case"L":o=f.shift(),h=f.shift(),C.push(o,h);break;case"m":const N=f.shift(),B=f.shift();if(o+=N,h+=B,y="M",n.length>2&&n[n.length-1].command==="z"){for(let L=n.length-2;L>=0;L--)if(n[L].command==="M"){o=n[L].points[0]+N,h=n[L].points[1]+B;break}}C.push(o,h),p="l";break;case"M":o=f.shift(),h=f.shift(),y="M",C.push(o,h),p="L";break;case"h":o+=f.shift(),y="L",C.push(o,h);break;case"H":o=f.shift(),y="L",C.push(o,h);break;case"v":h+=f.shift(),y="L",C.push(o,h);break;case"V":h=f.shift(),y="L",C.push(o,h);break;case"C":C.push(f.shift(),f.shift(),f.shift(),f.shift()),o=f.shift(),h=f.shift(),C.push(o,h);break;case"c":C.push(o+f.shift(),h+f.shift(),o+f.shift(),h+f.shift()),o+=f.shift(),h+=f.shift(),y="C",C.push(o,h);break;case"S":P=o,w=h,v=n[n.length-1],v.command==="C"&&(P=o+(o-v.points[2]),w=h+(h-v.points[3])),C.push(P,w,f.shift(),f.shift()),o=f.shift(),h=f.shift(),y="C",C.push(o,h);break;case"s":P=o,w=h,v=n[n.length-1],v.command==="C"&&(P=o+(o-v.points[2]),w=h+(h-v.points[3])),C.push(P,w,o+f.shift(),h+f.shift()),o+=f.shift(),h+=f.shift(),y="C",C.push(o,h);break;case"Q":C.push(f.shift(),f.shift()),o=f.shift(),h=f.shift(),C.push(o,h);break;case"q":C.push(o+f.shift(),h+f.shift()),o+=f.shift(),h+=f.shift(),y="Q",C.push(o,h);break;case"T":P=o,w=h,v=n[n.length-1],v.command==="Q"&&(P=o+(o-v.points[0]),w=h+(h-v.points[1])),o=f.shift(),h=f.shift(),y="Q",C.push(P,w,o,h);break;case"t":P=o,w=h,v=n[n.length-1],v.command==="Q"&&(P=o+(o-v.points[0]),w=h+(h-v.points[1])),o+=f.shift(),h+=f.shift(),y="Q",C.push(P,w,o,h);break;case"A":D=f.shift(),M=f.shift(),G=f.shift(),I=f.shift(),W=f.shift(),F=o,U=h,o=f.shift(),h=f.shift(),y="A",C=this.convertEndpointToCenterParameterization(F,U,o,h,I,W,D,M,G);break;case"a":D=f.shift(),M=f.shift(),G=f.shift(),I=f.shift(),W=f.shift(),F=o,U=h,o+=f.shift(),h+=f.shift(),y="A",C=this.convertEndpointToCenterParameterization(F,U,o,h,I,W,D,M,G);break}n.push({command:y||p,points:C,start:{x:S,y:b},pathLength:this.calcLength(S,b,y||p,C)})}(p==="z"||p==="Z")&&n.push({command:"z",points:[],start:void 0,pathLength:0})}return n}static calcLength(t,e,i,s){let n,r,o,h;const l=Z;switch(i){case"L":return l.getLineLength(t,e,s[0],s[1]);case"C":return ri([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return ai([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":n=0;const c=s[4],u=s[5],d=s[4]+u;let p=Math.PI/180;if(Math.abs(c-d)<p&&(p=Math.abs(c-d)),r=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],c,0),u<0)for(h=c-p;h>d;h-=p)o=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],h,0),n+=l.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(h=c+p;h<d;h+=p)o=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],h,0),n+=l.getLineLength(r.x,r.y,o.x,o.y),r=o;return o=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),n+=l.getLineLength(r.x,r.y,o.x,o.y),n}return 0}static convertEndpointToCenterParameterization(t,e,i,s,n,r,o,h,l){const c=l*(Math.PI/180),u=Math.cos(c)*(t-i)/2+Math.sin(c)*(e-s)/2,d=-1*Math.sin(c)*(t-i)/2+Math.cos(c)*(e-s)/2,p=u*u/(o*o)+d*d/(h*h);p>1&&(o*=Math.sqrt(p),h*=Math.sqrt(p));let f=Math.sqrt((o*o*(h*h)-o*o*(d*d)-h*h*(u*u))/(o*o*(d*d)+h*h*(u*u)));n===r&&(f*=-1),isNaN(f)&&(f=0);const m=f*o*d/h,y=f*-h*u/o,C=(t+i)/2+Math.cos(c)*m-Math.sin(c)*y,S=(e+s)/2+Math.sin(c)*m+Math.cos(c)*y,b=function(I){return Math.sqrt(I[0]*I[0]+I[1]*I[1])},v=function(I,W){return(I[0]*W[0]+I[1]*W[1])/(b(I)*b(W))},P=function(I,W){return(I[0]*W[1]<I[1]*W[0]?-1:1)*Math.acos(v(I,W))},w=P([1,0],[(u-m)/o,(d-y)/h]),D=[(u-m)/o,(d-y)/h],M=[(-1*u-m)/o,(-1*d-y)/h];let G=P(D,M);return v(D,M)<=-1&&(G=Math.PI),v(D,M)>=1&&(G=0),r===0&&G>0&&(G=G-2*Math.PI),r===1&&G<0&&(G=G+2*Math.PI),[C,S,o,h,w,G,c,r]}}Z.prototype.className="Path";Z.prototype._attrsAffectingSize=["data"];tt(Z);g.addGetterSetter(Z,"data");class Et extends gt{_sceneFunc(t){super._sceneFunc(t);const e=Math.PI*2,i=this.points();let s=i;const n=this.tension()!==0&&i.length>4;n&&(s=this.getTensionPoints());const r=this.pointerLength(),o=i.length;let h,l;if(n){const d=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[o-2],i[o-1]],p=Z.calcLength(s[s.length-4],s[s.length-3],"C",d),f=Z.getPointOnQuadraticBezier(Math.min(1,1-r/p),d[0],d[1],d[2],d[3],d[4],d[5]);h=i[o-2]-f.x,l=i[o-1]-f.y}else h=i[o-2]-i[o-4],l=i[o-1]-i[o-3];const c=(Math.atan2(l,h)+e)%e,u=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[o-2],i[o-1]),t.rotate(c),t.moveTo(0,0),t.lineTo(-r,u/2),t.lineTo(-r,-u/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),n?(h=(s[0]+s[2])/2-i[0],l=(s[1]+s[3])/2-i[1]):(h=i[2]-i[0],l=i[3]-i[1]),t.rotate((Math.atan2(-l,-h)+e)%e),t.moveTo(0,0),t.lineTo(-r,u/2),t.lineTo(-r,-u/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){const e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x,y:t.y-e,width:t.width,height:t.height+e*2}}}Et.prototype.className="Arrow";tt(Et);g.addGetterSetter(Et,"pointerLength",10,k());g.addGetterSetter(Et,"pointerWidth",10,k());g.addGetterSetter(Et,"pointerAtBeginning",!1);g.addGetterSetter(Et,"pointerAtEnding",!0);class It extends T{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,Math.PI*2,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}It.prototype._centroid=!0;It.prototype.className="Circle";It.prototype._attrsAffectingSize=["radius"];tt(It);g.addGetterSetter(It,"radius",0,k());class St extends T{_sceneFunc(t){const e=this.radiusX(),i=this.radiusY();t.beginPath(),t.save(),e!==i&&t.scale(1,i/e),t.arc(0,0,e,0,Math.PI*2,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.radiusX()*2}getHeight(){return this.radiusY()*2}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}St.prototype.className="Ellipse";St.prototype._centroid=!0;St.prototype._attrsAffectingSize=["radiusX","radiusY"];tt(St);g.addComponentsGetterSetter(St,"radius",["x","y"]);g.addGetterSetter(St,"radiusX",0,k());g.addGetterSetter(St,"radiusY",0,k());let lt=class Oi extends T{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",e=>{this._removeImageLoad(e.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&t.readyState===4||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){const t=!!this.cornerRadius(),e=this.hasShadow();return t&&e?!0:super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),n=this.attrs.image;let r;if(n){const o=this.attrs.cropWidth,h=this.attrs.cropHeight;o&&h?r=[n,this.cropX(),this.cropY(),o,h,0,0,e,i]:r=[n,0,0,e,i]}(this.hasFill()||this.hasStroke()||s)&&(t.beginPath(),s?_.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),n&&(s&&t.clip(),t.drawImage.apply(t,r))}_hitFunc(t){const e=this.width(),i=this.height(),s=this.cornerRadius();t.beginPath(),s?_.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e,i;return(i=(t=this.attrs.width)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.width)!==null&&i!==void 0?i:0}getHeight(){var t,e,i;return(i=(t=this.attrs.height)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.height)!==null&&i!==void 0?i:0}static fromURL(t,e,i=null){const s=_.createImageElement();s.onload=function(){const n=new Oi({image:s});e(n)},s.onerror=i,s.crossOrigin="Anonymous",s.src=t}};lt.prototype.className="Image";lt.prototype._attrsAffectingSize=["image"];tt(lt);g.addGetterSetter(lt,"cornerRadius",0,pe(4));g.addGetterSetter(lt,"image");g.addComponentsGetterSetter(lt,"crop",["x","y","width","height"]);g.addGetterSetter(lt,"cropX",0,k());g.addGetterSetter(lt,"cropY",0,k());g.addGetterSetter(lt,"cropWidth",0,k());g.addGetterSetter(lt,"cropHeight",0,k());const Fi=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],yn="Change.konva",_n="none",Me="up",Le="right",De="down",Ge="left",Cn=Fi.length;class ze extends Gt{constructor(t){super(t),this.on("add.konva",function(e){this._addListeners(e.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){let e=this,i;const s=function(){e._sync()};for(i=0;i<Cn;i++)t.on(Fi[i]+yn,s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t=this.getText(),e=this.getTag(),i,s,n,r,o,h,l;if(t&&e){switch(i=t.width(),s=t.height(),n=e.pointerDirection(),r=e.pointerWidth(),l=e.pointerHeight(),o=0,h=0,n){case Me:o=i/2,h=-1*l;break;case Le:o=i+r,h=s/2;break;case De:o=i/2,h=s+l;break;case Ge:o=-1*r,h=s/2;break}e.setAttrs({x:-1*o,y:-1*h,width:i,height:s}),t.setAttrs({x:-1*o,y:-1*h})}}}ze.prototype.className="Label";tt(ze);class Pt extends T{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),n=this.pointerWidth(),r=this.pointerHeight(),o=this.cornerRadius();let h=0,l=0,c=0,u=0;typeof o=="number"?h=l=c=u=Math.min(o,e/2,i/2):(h=Math.min(o[0]||0,e/2,i/2),l=Math.min(o[1]||0,e/2,i/2),u=Math.min(o[2]||0,e/2,i/2),c=Math.min(o[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(h,0),s===Me&&(t.lineTo((e-n)/2,0),t.lineTo(e/2,-1*r),t.lineTo((e+n)/2,0)),t.lineTo(e-l,0),t.arc(e-l,l,l,Math.PI*3/2,0,!1),s===Le&&(t.lineTo(e,(i-r)/2),t.lineTo(e+n,i/2),t.lineTo(e,(i+r)/2)),t.lineTo(e,i-u),t.arc(e-u,i-u,u,0,Math.PI/2,!1),s===De&&(t.lineTo((e+n)/2,i),t.lineTo(e/2,i+r),t.lineTo((e-n)/2,i)),t.lineTo(c,i),t.arc(c,i-c,c,Math.PI/2,Math.PI,!1),s===Ge&&(t.lineTo(0,(i+r)/2),t.lineTo(-1*n,i/2),t.lineTo(0,(i-r)/2)),t.lineTo(0,h),t.arc(h,h,h,Math.PI,Math.PI*3/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),n=this.pointerDirection(),r=this.width(),o=this.height();return n===Me?(e-=s,o+=s):n===De?o+=s:n===Ge?(t-=i*1.5,r+=i):n===Le&&(r+=i*1.5),{x:t,y:e,width:r,height:o}}}Pt.prototype.className="Tag";tt(Pt);g.addGetterSetter(Pt,"pointerDirection",_n);g.addGetterSetter(Pt,"pointerWidth",0,k());g.addGetterSetter(Pt,"pointerHeight",0,k());g.addGetterSetter(Pt,"cornerRadius",0,pe(4));class Jt extends T{_sceneFunc(t){const e=this.cornerRadius(),i=this.width(),s=this.height();t.beginPath(),e?_.drawRoundedRectPath(t,i,s,e):t.rect(0,0,i,s),t.closePath(),t.fillStrokeShape(this)}}Jt.prototype.className="Rect";tt(Jt);g.addGetterSetter(Jt,"cornerRadius",0,pe(4));class bt extends T{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),n=this.cornerRadius();if(t.beginPath(),n)_.drawRoundedPolygonPath(t,e,s,i,n);else{t.moveTo(e[0].x,e[0].y);for(let r=1;r<e.length;r++)t.lineTo(e[r].x,e[r].y)}t.closePath(),t.fillStrokeShape(this)}_getPoints(){const t=this.attrs.sides,e=this.attrs.radius||0,i=[];for(let s=0;s<t;s++)i.push({x:e*Math.sin(s*2*Math.PI/t),y:-1*e*Math.cos(s*2*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].x,s=t[0].y,n=t[0].y;return t.forEach(r=>{e=Math.min(e,r.x),i=Math.max(i,r.x),s=Math.min(s,r.y),n=Math.max(n,r.y)}),{x:e,y:s,width:i-e,height:n-s}}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}bt.prototype.className="RegularPolygon";bt.prototype._centroid=!0;bt.prototype._attrsAffectingSize=["radius"];tt(bt);g.addGetterSetter(bt,"radius",0,k());g.addGetterSetter(bt,"sides",0,k());g.addGetterSetter(bt,"cornerRadius",0,pe(4));const hi=Math.PI*2;class Rt extends T{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,hi,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),hi,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}Rt.prototype.className="Ring";Rt.prototype._centroid=!0;Rt.prototype._attrsAffectingSize=["innerRadius","outerRadius"];tt(Rt);g.addGetterSetter(Rt,"innerRadius",0,k());g.addGetterSetter(Rt,"outerRadius",0,k());class ct extends T{constructor(t){super(t),this._updated=!0,this.anim=new ot(()=>{const e=this._updated;return this._updated=!1,e}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(t){const e=this.animation(),i=this.frameIndex(),s=i*4,n=this.animations()[e],r=this.frameOffsets(),o=n[s+0],h=n[s+1],l=n[s+2],c=n[s+3],u=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,l,c),t.closePath(),t.fillStrokeShape(this)),u)if(r){const d=r[e],p=i*2;t.drawImage(u,o,h,l,c,d[p+0],d[p+1],l,c)}else t.drawImage(u,o,h,l,c,0,0,l,c)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=i*4,n=this.animations()[e],r=this.frameOffsets(),o=n[s+2],h=n[s+3];if(t.beginPath(),r){const l=r[e],c=i*2;t.rect(l[c+0],l[c+1],o,h)}else t.rect(0,0,o,h);t.closePath(),t.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){const t=this;this.interval=setInterval(function(){t._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;const t=this.getLayer();this.anim.setLayers(t),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){const t=this.frameIndex(),e=this.animation(),i=this.animations(),s=i[e],n=s.length/4;t<n-1?this.frameIndex(t+1):this.frameIndex(0)}}ct.prototype.className="Sprite";tt(ct);g.addGetterSetter(ct,"animation");g.addGetterSetter(ct,"animations");g.addGetterSetter(ct,"frameOffsets");g.addGetterSetter(ct,"image");g.addGetterSetter(ct,"frameIndex",0,k());g.addGetterSetter(ct,"frameRate",17,k());g.backCompat(ct,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class vt extends T{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let n=1;n<s*2;n++){const r=n%2===0?i:e,o=r*Math.sin(n*Math.PI/s),h=-1*r*Math.cos(n*Math.PI/s);t.lineTo(o,h)}t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}vt.prototype.className="Star";vt.prototype._centroid=!0;vt.prototype._attrsAffectingSize=["innerRadius","outerRadius"];tt(vt);g.addGetterSetter(vt,"numPoints",5,k());g.addGetterSetter(vt,"innerRadius",0,k());g.addGetterSetter(vt,"outerRadius",0,k());function yt(a){return[...a].reduce((t,e,i,s)=>{if(new RegExp("\\p{Emoji}","u").test(e)){const n=s[i+1];n&&new RegExp("\\p{Emoji_Modifier}|\\u200D","u").test(n)?(t.push(e+n),s[i+1]=""):t.push(e)}else new RegExp("\\p{Regional_Indicator}{2}","u").test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&new RegExp("\\p{Mn}|\\p{Me}|\\p{Mc}","u").test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}const Lt="auto",Sn="center",Bi="inherit",Ht="justify",bn="Change.konva",vn="2d",li="-",Ni="left",Tn="text",xn="Text",wn="top",kn="bottom",ci="middle",Hi="normal",An="px ",ae=" ",En="right",di="rtl",Pn="word",Rn="char",ui="none",ve="…",zi=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],Mn=zi.length;function Ln(a){return a.split(",").map(t=>{t=t.trim();const e=t.indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t}).join(", ")}let oe;function Te(){return oe||(oe=_.createCanvasElement().getContext(vn),oe)}function Dn(a){a.fillText(this._partialText,this._partialTextX,this._partialTextY)}function Gn(a){a.setAttr("miterLimit",2),a.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function In(a){return a=a||{},!a.fillLinearGradientColorStops&&!a.fillRadialGradientColorStops&&!a.fillPatternImage&&(a.fill=a.fill||"black"),a}class J extends T{constructor(t){super(In(t)),this._partialTextX=0,this._partialTextY=0;for(let e=0;e<Mn;e++)this.on(zi[e]+bn,this._setTextData);this._setTextData()}_sceneFunc(t){var e,i;const s=this.textArr,n=s.length;if(!this.text())return;let r=this.padding(),o=this.fontSize(),h=this.lineHeight()*o,l=this.verticalAlign(),c=this.direction(),u=0,d=this.align(),p=this.getWidth(),f=this.letterSpacing(),m=this.charRenderFunc(),y=this.fill(),C=this.textDecoration(),S=this.underlineOffset(),b=C.indexOf("underline")!==-1,v=C.indexOf("line-through")!==-1,P;c=c===Bi?t.direction:c;let w=h/2,D=ci;if(!E.legacyTextRendering){const M=this.measureSize("M");D="alphabetic";const G=(e=M.fontBoundingBoxAscent)!==null&&e!==void 0?e:M.actualBoundingBoxAscent,I=(i=M.fontBoundingBoxDescent)!==null&&i!==void 0?i:M.actualBoundingBoxDescent;w=(G-I)/2+h/2}for(c===di&&t.setAttr("direction",c),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",D),t.setAttr("textAlign",Ni),l===ci?u=(this.getHeight()-n*h-r*2)/2:l===kn&&(u=this.getHeight()-n*h-r*2),t.translate(r,u+r),P=0;P<n;P++){let M=0,G=0;const I=s[P],W=I.text,F=I.width,U=I.lastInParagraph;if(t.save(),d===En?M+=p-F-r*2:d===Sn&&(M+=(p-F-r*2)/2),b){t.save(),t.beginPath();const B=S??(E.legacyTextRendering?Math.round(o/2):Math.round(o/4)),L=M,$=w+G+B;t.moveTo(L,$);const O=d===Ht&&!U?p-r*2:F;t.lineTo(L+Math.round(O),$),t.lineWidth=o/15;const j=this._getLinearGradient();t.strokeStyle=j||y,t.stroke(),t.restore()}const N=M;if(c!==di&&(f!==0||d===Ht||m)){const B=W.split(" ").length-1,L=yt(W);for(let $=0;$<L.length;$++){const O=L[$];if(O===" "&&!U&&d===Ht&&(M+=(p-r*2-F)/B),this._partialTextX=M,this._partialTextY=w+G,this._partialText=O,m){t.save();const it=s.slice(0,P).reduce((et,nt)=>et+yt(nt.text).length,0),Y=$+it;m({char:O,index:Y,x:M,y:w+G,lineIndex:P,column:$,isLastInLine:U,width:this.measureSize(O).width,context:t})}t.fillStrokeShape(this),m&&t.restore(),M+=this.measureSize(O).width+f}}else f!==0&&t.setAttr("letterSpacing",`${f}px`),this._partialTextX=M,this._partialTextY=w+G,this._partialText=W,t.fillStrokeShape(this);if(v){t.save(),t.beginPath();const B=E.legacyTextRendering?0:-Math.round(o/4),L=N;t.moveTo(L,w+G+B);const $=d===Ht&&!U?p-r*2:F;t.lineTo(L+Math.round($),w+G+B),t.lineWidth=o/15;const O=this._getLinearGradient();t.strokeStyle=O||y,t.stroke(),t.restore()}t.restore(),n>1&&(w+=h)}}_hitFunc(t){const e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}setText(t){const e=_._isString(t)?t:t==null?"":t+"";return this._setAttr(Tn,e),this}getWidth(){return this.attrs.width===Lt||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===Lt||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return _.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i,s,n,r,o,h,l,c,u,d;let p=Te(),f=this.fontSize(),m;p.save(),p.font=this._getContextFont(),m=p.measureText(t),p.restore();const y=f/100;return{actualBoundingBoxAscent:(e=m.actualBoundingBoxAscent)!==null&&e!==void 0?e:71.58203125*y,actualBoundingBoxDescent:(i=m.actualBoundingBoxDescent)!==null&&i!==void 0?i:0,actualBoundingBoxLeft:(s=m.actualBoundingBoxLeft)!==null&&s!==void 0?s:-7.421875*y,actualBoundingBoxRight:(n=m.actualBoundingBoxRight)!==null&&n!==void 0?n:75.732421875*y,alphabeticBaseline:(r=m.alphabeticBaseline)!==null&&r!==void 0?r:0,emHeightAscent:(o=m.emHeightAscent)!==null&&o!==void 0?o:100*y,emHeightDescent:(h=m.emHeightDescent)!==null&&h!==void 0?h:-20*y,fontBoundingBoxAscent:(l=m.fontBoundingBoxAscent)!==null&&l!==void 0?l:91*y,fontBoundingBoxDescent:(c=m.fontBoundingBoxDescent)!==null&&c!==void 0?c:21*y,hangingBaseline:(u=m.hangingBaseline)!==null&&u!==void 0?u:72.80000305175781*y,ideographicBaseline:(d=m.ideographicBaseline)!==null&&d!==void 0?d:-21*y,width:m.width,height:f}}_getContextFont(){return this.fontStyle()+ae+this.fontVariant()+ae+(this.fontSize()+An)+Ln(this.fontFamily())}_addTextLine(t){this.align()===Ht&&(t=t.trim());const i=this._getTextWidth(t);return this.textArr.push({text:t,width:i,lastInParagraph:!1})}_getTextWidth(t){const e=this.letterSpacing(),i=t.length;return Te().measureText(t).width+e*i}_setTextData(){let t=this.text().split(`
|
|
15
|
-
`),e=+this.fontSize(),i=0,s=this.lineHeight()*e,n=this.attrs.width,r=this.attrs.height,o=n!==Lt&&n!==void 0,h=r!==Lt&&r!==void 0,l=this.padding(),c=n-l*2,u=r-l*2,d=0,p=this.wrap(),f=p!==ui,m=p!==Rn&&f,y=this.ellipsis();this.textArr=[],Te().font=this._getContextFont();const C=y?this._getTextWidth(ve):0;for(let S=0,b=t.length;S<b;++S){let v=t[S],P=this._getTextWidth(v);if(o&&P>c)for(;v.length>0;){let w=0,D=yt(v).length,M="",G=0;for(;w<D;){const I=w+D>>>1,W=yt(v),F=W.slice(0,I+1).join(""),U=this._getTextWidth(F);(y&&h&&d+s>u?U+C:U)<=c?(w=I+1,M=F,G=U):D=I}if(M){if(m){const F=yt(v),U=yt(M),N=F[U.length],B=N===ae||N===li;let L;if(B&&G<=c)L=U.length;else{const $=U.lastIndexOf(ae),O=U.lastIndexOf(li);L=Math.max($,O)+1}L>0&&(w=L,M=F.slice(0,w).join(""),G=this._getTextWidth(M))}if(M=M.trimRight(),this._addTextLine(M),i=Math.max(i,G),d+=s,this._shouldHandleEllipsis(d)){this._tryToAddEllipsisToLastLine();break}if(v=yt(v).slice(w).join("").trimLeft(),v.length>0&&(P=this._getTextWidth(v),P<=c)){this._addTextLine(v),d+=s,i=Math.max(i,P);break}}else break}else this._addTextLine(v),d+=s,i=Math.max(i,P),this._shouldHandleEllipsis(d)&&S<b-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),h&&d+s>u)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,n=s!==Lt&&s!==void 0,r=this.padding(),o=s-r*2;return!(this.wrap()!==ui)||n&&t+i>o}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==Lt&&t!==void 0,i=this.padding(),s=t-i*2,n=this.ellipsis(),r=this.textArr[this.textArr.length-1];!r||!n||(e&&(this._getTextWidth(r.text+ve)<s||(r.text=r.text.slice(0,r.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(r.text+ve))}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=this.textDecoration().indexOf("underline")!==-1||this.textDecoration().indexOf("line-through")!==-1,e=this.hasShadow();return t&&e?!0:super._useBufferCanvas()}}J.prototype._fillFunc=Dn;J.prototype._strokeFunc=Gn;J.prototype.className=xn;J.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"];tt(J);g.overWriteSetter(J,"width",Be());g.overWriteSetter(J,"height",Be());g.addGetterSetter(J,"direction",Bi);g.addGetterSetter(J,"fontFamily","Arial");g.addGetterSetter(J,"fontSize",12,k());g.addGetterSetter(J,"fontStyle",Hi);g.addGetterSetter(J,"fontVariant",Hi);g.addGetterSetter(J,"padding",0,k());g.addGetterSetter(J,"align",Ni);g.addGetterSetter(J,"verticalAlign",wn);g.addGetterSetter(J,"lineHeight",1,k());g.addGetterSetter(J,"wrap",Pn);g.addGetterSetter(J,"ellipsis",!1,ht());g.addGetterSetter(J,"letterSpacing",0,k());g.addGetterSetter(J,"text","",kt());g.addGetterSetter(J,"textDecoration","");g.addGetterSetter(J,"underlineOffset",void 0,k());g.addGetterSetter(J,"charRenderFunc",void 0);const On="",Wi="normal";function Ui(a){a.fillText(this.partialText,0,0)}function Xi(a){a.strokeText(this.partialText,0,0)}class st extends T{constructor(t){super(t),this.dummyCanvas=_.createCanvasElement(),this.dataArray=[],this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute(),this._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva",this._setTextData),this._setTextData()}_getTextPathLength(){return Z.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;const e=this.pathLength;return t>e?null:Z.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=Z.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.textBaseline()),t.setAttr("textAlign","left"),t.save();const e=this.textDecoration(),i=this.fill(),s=this.fontSize(),n=this.glyphInfo,r=e.indexOf("underline")!==-1,o=e.indexOf("line-through")!==-1;r&&t.beginPath();for(let h=0;h<n.length;h++){t.save();const l=n[h].p0;t.translate(l.x,l.y),t.rotate(n[h].rotation),this.partialText=n[h].text,t.fillStrokeShape(this),r&&(h===0&&t.moveTo(0,s/2+1),t.lineTo(n[h].width,s/2+1)),t.restore()}if(r&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),o){t.beginPath();for(let h=0;h<n.length;h++){t.save();const l=n[h].p0;t.translate(l.x,l.y),t.rotate(n[h].rotation),h===0&&t.moveTo(0,0),t.lineTo(n[h].width,0),t.restore()}t.strokeStyle=i,t.lineWidth=s/20,t.stroke()}t.restore()}_hitFunc(t){t.beginPath();const e=this.glyphInfo;if(e.length>=1){const i=e[0].p0;t.moveTo(i.x,i.y)}for(let i=0;i<e.length;i++){const s=e[i].p1;t.lineTo(s.x,s.y)}t.setAttr("lineWidth",this.fontSize()),t.setAttr("strokeStyle",this.colorKey),t.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return _.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(t){return J.prototype.setText.call(this,t)}_getContextFont(){return J.prototype._getContextFont.call(this)}_getTextSize(t){const i=this.dummyCanvas.getContext("2d");i.save(),i.font=this._getContextFont();const s=i.measureText(t);return i.restore(),{width:s.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const t=yt(this.text()),e=[];let i=0;for(let u=0;u<t.length;u++)e.push({char:t[u],width:this._getTextSize(t[u]).width}),i+=e[u].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const n=this.letterSpacing(),r=this.align(),o=this.kerningFunc(),h=Math.max(this.textWidth+((this.attrs.text||"").length-1)*n,0);let l=0;r==="center"&&(l=Math.max(0,this.pathLength/2-h/2)),r==="right"&&(l=Math.max(0,this.pathLength-h));let c=l;for(let u=0;u<e.length;u++){const d=this._getPointAtLength(c);if(!d)return;const p=e[u].char;let f=e[u].width+n;if(p===" "&&r==="justify"){const v=this.text().split(" ").length-1;f+=(this.pathLength-h)/v}const m=this._getPointAtLength(c+f);if(!m)return;const y=Z.getLineLength(d.x,d.y,m.x,m.y);let C=0;if(o)try{C=o(e[u-1].char,p)*this.fontSize()}catch{C=0}d.x+=C,m.x+=C,this.textWidth+=C;const S=Z.getPointOnLine(C+y/2,d.x,d.y,m.x,m.y),b=Math.atan2(m.y-d.y,m.x-d.x);this.glyphInfo.push({transposeX:S.x,transposeY:S.y,text:t[u],rotation:b,p0:d,p1:m,width:y}),c+=f}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(l){t.push(l.p0.x),t.push(l.p0.y),t.push(l.p1.x),t.push(l.p1.y)});let e=t[0]||0,i=t[0]||0,s=t[1]||0,n=t[1]||0,r,o;for(let l=0;l<t.length/2;l++)r=t[l*2],o=t[l*2+1],e=Math.min(e,r),i=Math.max(i,r),s=Math.min(s,o),n=Math.max(n,o);const h=this.fontSize();return{x:e-h/2,y:s-h/2,width:i-e+h,height:n-s+h}}destroy(){return _.releaseCanvas(this.dummyCanvas),super.destroy()}}st.prototype._fillFunc=Ui;st.prototype._strokeFunc=Xi;st.prototype._fillFuncHit=Ui;st.prototype._strokeFuncHit=Xi;st.prototype.className="TextPath";st.prototype._attrsAffectingSize=["text","fontSize","data"];tt(st);g.addGetterSetter(st,"data");g.addGetterSetter(st,"fontFamily","Arial");g.addGetterSetter(st,"fontSize",12,k());g.addGetterSetter(st,"fontStyle",Wi);g.addGetterSetter(st,"align","left");g.addGetterSetter(st,"letterSpacing",0,k());g.addGetterSetter(st,"textBaseline","middle");g.addGetterSetter(st,"fontVariant",Wi);g.addGetterSetter(st,"text",On);g.addGetterSetter(st,"textDecoration","");g.addGetterSetter(st,"kerningFunc",void 0);const Yi="tr-konva",Fn=["resizeEnabledChange","rotateAnchorOffsetChange","rotateAnchorAngleChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(a=>a+`.${Yi}`).join(" "),fi="nodesRect",Bn=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],Nn={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},Hn="ontouchstart"in E._global;function zn(a,t,e){if(a==="rotater")return e;t+=_.degToRad(Nn[a]||0);const i=(_.radToDeg(t)%360+360)%360;return _._inRange(i,315+22.5,360)||_._inRange(i,0,22.5)?"ns-resize":_._inRange(i,45-22.5,45+22.5)?"nesw-resize":_._inRange(i,90-22.5,90+22.5)?"ew-resize":_._inRange(i,135-22.5,135+22.5)?"nwse-resize":_._inRange(i,180-22.5,180+22.5)?"ns-resize":_._inRange(i,225-22.5,225+22.5)?"nesw-resize":_._inRange(i,270-22.5,270+22.5)?"ew-resize":_._inRange(i,315-22.5,315+22.5)?"nwse-resize":(_.error("Transformer has unknown angle for cursor detection: "+i),"pointer")}const fe=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function Wn(a){return{x:a.x+a.width/2*Math.cos(a.rotation)+a.height/2*Math.sin(-a.rotation),y:a.y+a.height/2*Math.cos(a.rotation)+a.width/2*Math.sin(a.rotation)}}function Vi(a,t,e){const i=e.x+(a.x-e.x)*Math.cos(t)-(a.y-e.y)*Math.sin(t),s=e.y+(a.x-e.x)*Math.sin(t)+(a.y-e.y)*Math.cos(t);return{...a,rotation:a.rotation+t,x:i,y:s}}function Un(a,t){const e=Wn(a);return Vi(a,t,e)}function Xn(a,t,e){let i=t;for(let s=0;s<a.length;s++){const n=E.getAngle(a[s]),r=Math.abs(n-t)%(Math.PI*2);Math.min(r,Math.PI*2-r)<e&&(i=n)}return i}let Ie=0;class H extends Gt{constructor(t){super(t),this._movingAnchorName=null,this._transforming=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(Fn,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return _.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([t])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return Yi+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(s=>s.isAncestorOf(this)?(_.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1):!0);return this._nodes=t=e,t.length===1&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(s=>{const n=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()};if(s._attrsAffectingSize.length){const r=s._attrsAffectingSize.map(o=>o+"Change."+this._getEventNamespace()).join(" ");s.on(r,n)}s.on(Bn.map(r=>r+`.${this._getEventNamespace()}`).join(" "),n),s.on(`absoluteTransformChange.${this._getEventNamespace()}`,n),this._proxyDrag(s)}),this._resetTransformCache(),!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,i=>{e=t.getAbsolutePosition(),!this.isDragging()&&t!==this.findOne(".back")&&this.startDrag(i,!1)}),t.on(`dragmove.${this._getEventNamespace()}`,i=>{if(!e)return;const s=t.getAbsolutePosition(),n=s.x-e.x,r=s.y-e.y;this.nodes().forEach(o=>{if(o===t||o.isDragging())return;const h=o.getAbsolutePosition();o.setAbsolutePosition({x:h.x+n,y:h.y+r}),o.startDrag(i)}),e=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(t=>{t.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(fi),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(fi,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),i){const s=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),n=t.getAbsoluteScale(i),r=t.getAbsolutePosition(i),o=s.x*n.x-t.offsetX()*n.x,h=s.y*n.y-t.offsetY()*n.y,l=(E.getAngle(t.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2),c={x:r.x+o*Math.cos(l)+h*Math.sin(-l),y:r.y+h*Math.cos(l)+o*Math.sin(l),width:s.width*n.x,height:s.height*n.y,rotation:l};return Vi(c,-E.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const e=[];this.nodes().map(l=>{const c=l.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),u=[{x:c.x,y:c.y},{x:c.x+c.width,y:c.y},{x:c.x+c.width,y:c.y+c.height},{x:c.x,y:c.y+c.height}],d=l.getAbsoluteTransform();u.forEach(function(p){const f=d.point(p);e.push(f)})});const i=new rt;i.rotate(-E.getAngle(this.rotation()));let s=1/0,n=1/0,r=-1/0,o=-1/0;e.forEach(function(l){const c=i.point(l);s===void 0&&(s=r=c.x,n=o=c.y),s=Math.min(s,c.x),n=Math.min(n,c.y),r=Math.max(r,c.x),o=Math.max(o,c.y)}),i.invert();const h=i.point({x:s,y:n});return{x:h.x,y:h.y,width:r-s,height:o-n,rotation:E.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),fe.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new Jt({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:Hn?10:"auto"}),i=this;e.on("mousedown touchstart",function(s){i._handleMouseDown(s)}),e.on("dragstart",s=>{e.stopDrag(),s.cancelBubble=!0}),e.on("dragend",s=>{s.cancelBubble=!0}),e.on("mouseenter",()=>{const s=E.getAngle(this.rotation()),n=this.rotateAnchorCursor(),r=zn(t,s,n);e.getStage().content&&(e.getStage().content.style.cursor=r),this._cursorChange=!0}),e.on("mouseout",()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(e)}_createBack(){const t=new T({name:"back",width:0,height:0,sceneFunc(e,i){const s=i.getParent(),n=s.padding(),r=i.width(),o=i.height();if(e.beginPath(),e.rect(-n,-n,r+n*2,o+n*2),s.rotateEnabled()&&s.rotateLineVisible()){const h=s.rotateAnchorAngle(),l=s.rotateAnchorOffset(),c=_.degToRad(h),u=Math.sin(c),d=-Math.cos(c),p=r/2,f=o/2;let m=1/0;d<0?m=Math.min(m,-f/d):d>0&&(m=Math.min(m,(o-f)/d)),u<0?m=Math.min(m,-p/u):u>0&&(m=Math.min(m,(r-p)/u));const y=p+u*m,C=f+d*m,S=_._sign(o),b=y+u*l*S,v=C+d*l*S;e.moveTo(y,C),e.lineTo(b,v)}e.fillStrokeShape(i)},hitFunc:(e,i)=>{if(!this.shouldOverdrawWholeArea())return;const s=this.padding();e.beginPath(),e.rect(-s,-s,i.width()+s*2,i.height()+s*2),e.fillStrokeShape(i)}});this.add(t),this._proxyDrag(t),t.on("dragstart",e=>{e.cancelBubble=!0}),t.on("dragmove",e=>{e.cancelBubble=!0}),t.on("dragend",e=>{e.cancelBubble=!0}),this.on("dragmove",e=>{this.update()})}_handleMouseDown(t){if(this._transforming)return;this._movingAnchorName=t.target.name().split(" ")[0];const e=this._getNodeRect(),i=e.width,s=e.height,n=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/n),this.cos=Math.abs(i/n),typeof window<"u"&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const r=t.target.getAbsolutePosition(),o=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:o.x-r.x,y:o.y-r.y},Ie++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(h=>{h._fire("transformstart",{evt:t.evt,target:h})})}_handleMouseMove(t){let e,i,s;const n=this.findOne("."+this._movingAnchorName),r=n.getStage();r.setPointersPositions(t);const o=r.getPointerPosition();let h={x:o.x-this._anchorDragOffset.x,y:o.y-this._anchorDragOffset.y};const l=n.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),n.setAbsolutePosition(h);const c=n.getAbsolutePosition();if(l.x===c.x&&l.y===c.y)return;if(this._movingAnchorName==="rotater"){const S=this._getNodeRect();e=n.x()-S.width/2,i=-n.y()+S.height/2;const b=E.getAngle(this.rotateAnchorAngle());let v=Math.atan2(-i,e)+Math.PI/2-b;S.height<0&&(v-=Math.PI);const w=E.getAngle(this.rotation())+v,D=E.getAngle(this.rotationSnapTolerance()),G=Xn(this.rotationSnaps(),w,D)-S.rotation,I=Un(S,G);this._fitNodesInto(I,t);return}const u=this.shiftBehavior();let d;u==="inverted"?d=this.keepRatio()&&!t.shiftKey:u==="none"?d=this.keepRatio():d=this.keepRatio()||t.shiftKey;let p=this.centeredScaling()||t.altKey;if(this._movingAnchorName==="top-left"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};s=Math.sqrt(Math.pow(S.x-n.x(),2)+Math.pow(S.y-n.y(),2));const b=this.findOne(".top-left").x()>S.x?-1:1,v=this.findOne(".top-left").y()>S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,this.findOne(".top-left").x(S.x-e),this.findOne(".top-left").y(S.y-i)}}else if(this._movingAnchorName==="top-center")this.findOne(".top-left").y(n.y());else if(this._movingAnchorName==="top-right"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};s=Math.sqrt(Math.pow(n.x()-S.x,2)+Math.pow(S.y-n.y(),2));const b=this.findOne(".top-right").x()<S.x?-1:1,v=this.findOne(".top-right").y()>S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,this.findOne(".top-right").x(S.x+e),this.findOne(".top-right").y(S.y-i)}var f=n.position();this.findOne(".top-left").y(f.y),this.findOne(".bottom-right").x(f.x)}else if(this._movingAnchorName==="middle-left")this.findOne(".top-left").x(n.x());else if(this._movingAnchorName==="middle-right")this.findOne(".bottom-right").x(n.x());else if(this._movingAnchorName==="bottom-left"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};s=Math.sqrt(Math.pow(S.x-n.x(),2)+Math.pow(n.y()-S.y,2));const b=S.x<n.x()?-1:1,v=n.y()<S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,n.x(S.x-e),n.y(S.y+i)}f=n.position(),this.findOne(".top-left").x(f.x),this.findOne(".bottom-right").y(f.y)}else if(this._movingAnchorName==="bottom-center")this.findOne(".bottom-right").y(n.y());else if(this._movingAnchorName==="bottom-right"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};s=Math.sqrt(Math.pow(n.x()-S.x,2)+Math.pow(n.y()-S.y,2));const b=this.findOne(".bottom-right").x()<S.x?-1:1,v=this.findOne(".bottom-right").y()<S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,this.findOne(".bottom-right").x(S.x+e),this.findOne(".bottom-right").y(S.y+i)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(p=this.centeredScaling()||t.altKey,p){const S=this.findOne(".top-left"),b=this.findOne(".bottom-right"),v=S.x(),P=S.y(),w=this.getWidth()-b.x(),D=this.getHeight()-b.y();b.move({x:-v,y:-P}),S.move({x:w,y:D})}const m=this.findOne(".top-left").getAbsolutePosition();e=m.x,i=m.y;const y=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),C=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:i,width:y,height:C,rotation:E.getAngle(this.rotation())},t)}_handleMouseUp(t){this._removeEvents(t)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(t){var e;if(this._transforming){this._transforming=!1,typeof window<"u"&&(window.removeEventListener("mousemove",this._handleMouseMove),window.removeEventListener("touchmove",this._handleMouseMove),window.removeEventListener("mouseup",this._handleMouseUp,!0),window.removeEventListener("touchend",this._handleMouseUp,!0));const i=this.getNode();Ie--,this._fire("transformend",{evt:t,target:i}),(e=this.getLayer())===null||e===void 0||e.batchDraw(),i&&this._nodes.forEach(s=>{var n;s._fire("transformend",{evt:t,target:s}),(n=s.getLayer())===null||n===void 0||n.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const i=this._getNodeRect(),s=1;if(_._inRange(t.width,-this.padding()*2-s,s)){this.update();return}if(_._inRange(t.height,-this.padding()*2-s,s)){this.update();return}const n=new rt;if(n.rotate(E.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const d=n.point({x:-this.padding()*2,y:0});t.x+=d.x,t.y+=d.y,t.width+=this.padding()*2,this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const d=n.point({x:this.padding()*2,y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,t.width+=this.padding()*2}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const d=n.point({x:0,y:-this.padding()*2});t.x+=d.x,t.y+=d.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,t.height+=this.padding()*2}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const d=n.point({x:0,y:this.padding()*2});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,t.height+=this.padding()*2}if(this.boundBoxFunc()){const d=this.boundBoxFunc()(i,t);d?t=d:_.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const r=1e7,o=new rt;o.translate(i.x,i.y),o.rotate(i.rotation),o.scale(i.width/r,i.height/r);const h=new rt,l=t.width/r,c=t.height/r;this.flipEnabled()===!1?(h.translate(t.x,t.y),h.rotate(t.rotation),h.translate(t.width<0?t.width:0,t.height<0?t.height:0),h.scale(Math.abs(l),Math.abs(c))):(h.translate(t.x,t.y),h.rotate(t.rotation),h.scale(l,c));const u=h.multiply(o.invert());this._nodes.forEach(d=>{var p;if(!d.getStage())return;const f=d.getParent().getAbsoluteTransform(),m=d.getTransform().copy();m.translate(d.offsetX(),d.offsetY());const y=new rt;y.multiply(f.copy().invert()).multiply(u).multiply(f).multiply(m);const C=y.decompose();d.setAttrs(C),(p=d.getLayer())===null||p===void 0||p.batchDraw()}),this.rotation(_._getRotation(t.rotation)),this._nodes.forEach(d=>{this._fire("transform",{evt:e,target:d}),d._fire("transform",{evt:e,target:d})}),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(t,e){this.findOne(t).setAttrs(e)}update(){var t;const e=this._getNodeRect();this.rotation(_._getRotation(e.rotation));const i=e.width,s=e.height,n=this.enabledAnchors(),r=this.resizeEnabled(),o=this.padding(),h=this.anchorSize(),l=this.find("._anchor");l.forEach(w=>{w.setAttrs({width:h,height:h,offsetX:h/2,offsetY:h/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:h/2+o,offsetY:h/2+o,visible:r&&n.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:h/2+o,visible:r&&n.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:h/2-o,offsetY:h/2+o,visible:r&&n.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:h/2+o,visible:r&&n.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:h/2-o,visible:r&&n.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:h/2+o,offsetY:h/2-o,visible:r&&n.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:h/2-o,visible:r&&n.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:h/2-o,offsetY:h/2-o,visible:r&&n.indexOf("bottom-right")>=0});const c=this.rotateAnchorAngle(),u=this.rotateAnchorOffset(),d=_.degToRad(c),p=Math.sin(d),f=-Math.cos(d),m=i/2,y=s/2;let C=1/0;f<0?C=Math.min(C,-y/f):f>0&&(C=Math.min(C,(s-y)/f)),p<0?C=Math.min(C,-m/p):p>0&&(C=Math.min(C,(i-m)/p));const S=m+p*C,b=y+f*C,v=_._sign(s);this._batchChangeChild(".rotater",{x:S+p*u*v,y:b+f*u*v-o*f,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:i,height:s,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),draggable:this.nodes().some(w=>w.draggable()),x:0,y:0});const P=this.anchorStyleFunc();P&&l.forEach(w=>{P(w)}),(t=this.getLayer())===null||t===void 0||t.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();const t=this.findOne("."+this._movingAnchorName);t&&t.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),Gt.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return x.prototype.toObject.call(this)}clone(t){return x.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}H.isTransforming=()=>Ie>0;function Yn(a){return a instanceof Array||_.warn("enabledAnchors value should be an array"),a instanceof Array&&a.forEach(function(t){fe.indexOf(t)===-1&&_.warn("Unknown anchor name: "+t+". Available names are: "+fe.join(", "))}),a||[]}H.prototype.className="Transformer";tt(H);g.addGetterSetter(H,"enabledAnchors",fe,Yn);g.addGetterSetter(H,"flipEnabled",!0,ht());g.addGetterSetter(H,"resizeEnabled",!0);g.addGetterSetter(H,"anchorSize",10,k());g.addGetterSetter(H,"rotateEnabled",!0);g.addGetterSetter(H,"rotateLineVisible",!0);g.addGetterSetter(H,"rotationSnaps",[]);g.addGetterSetter(H,"rotateAnchorOffset",50,k());g.addGetterSetter(H,"rotateAnchorAngle",0,k());g.addGetterSetter(H,"rotateAnchorCursor","crosshair");g.addGetterSetter(H,"rotationSnapTolerance",5,k());g.addGetterSetter(H,"borderEnabled",!0);g.addGetterSetter(H,"anchorStroke","rgb(0, 161, 255)");g.addGetterSetter(H,"anchorStrokeWidth",1,k());g.addGetterSetter(H,"anchorFill","white");g.addGetterSetter(H,"anchorCornerRadius",0,k());g.addGetterSetter(H,"borderStroke","rgb(0, 161, 255)");g.addGetterSetter(H,"borderStrokeWidth",1,k());g.addGetterSetter(H,"borderDash");g.addGetterSetter(H,"keepRatio",!0);g.addGetterSetter(H,"shiftBehavior","default");g.addGetterSetter(H,"centeredScaling",!1);g.addGetterSetter(H,"ignoreStroke",!1);g.addGetterSetter(H,"padding",0,k());g.addGetterSetter(H,"nodes");g.addGetterSetter(H,"node");g.addGetterSetter(H,"boundBoxFunc");g.addGetterSetter(H,"anchorDragBoundFunc");g.addGetterSetter(H,"anchorStyleFunc");g.addGetterSetter(H,"shouldOverdrawWholeArea",!1);g.addGetterSetter(H,"useSingleNodeRotation",!0);g.backCompat(H,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class pt extends T{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,E.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}pt.prototype.className="Wedge";pt.prototype._centroid=!0;pt.prototype._attrsAffectingSize=["radius"];tt(pt);g.addGetterSetter(pt,"radius",0,k());g.addGetterSetter(pt,"angle",0,k());g.addGetterSetter(pt,"clockwise",!1);g.backCompat(pt,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});function gi(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}const Vn=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],jn=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function qn(a,t){const e=a.data,i=a.width,s=a.height;let n,r,o,h,l,c,u,d,p,f,m,y,C,S,b,v,P,w,D,M;const G=t+t+1,I=i-1,W=s-1,F=t+1,U=F*(F+1)/2,N=new gi,B=Vn[t],L=jn[t];let $=null,O=N,j=null,it=null;for(let Y=1;Y<G;Y++)O=O.next=new gi,Y===F&&($=O);O.next=N,o=r=0;for(let Y=0;Y<s;Y++){y=C=S=b=h=l=c=u=0,d=F*(v=e[r]),p=F*(P=e[r+1]),f=F*(w=e[r+2]),m=F*(D=e[r+3]),h+=U*v,l+=U*P,c+=U*w,u+=U*D,O=N;for(let et=0;et<F;et++)O.r=v,O.g=P,O.b=w,O.a=D,O=O.next;for(let et=1;et<F;et++)n=r+((I<et?I:et)<<2),h+=(O.r=v=e[n])*(M=F-et),l+=(O.g=P=e[n+1])*M,c+=(O.b=w=e[n+2])*M,u+=(O.a=D=e[n+3])*M,y+=v,C+=P,S+=w,b+=D,O=O.next;j=N,it=$;for(let et=0;et<i;et++)e[r+3]=D=u*B>>L,D!==0?(D=255/D,e[r]=(h*B>>L)*D,e[r+1]=(l*B>>L)*D,e[r+2]=(c*B>>L)*D):e[r]=e[r+1]=e[r+2]=0,h-=d,l-=p,c-=f,u-=m,d-=j.r,p-=j.g,f-=j.b,m-=j.a,n=o+((n=et+t+1)<I?n:I)<<2,y+=j.r=e[n],C+=j.g=e[n+1],S+=j.b=e[n+2],b+=j.a=e[n+3],h+=y,l+=C,c+=S,u+=b,j=j.next,d+=v=it.r,p+=P=it.g,f+=w=it.b,m+=D=it.a,y-=v,C-=P,S-=w,b-=D,it=it.next,r+=4;o+=i}for(let Y=0;Y<i;Y++){C=S=b=y=l=c=u=h=0,r=Y<<2,d=F*(v=e[r]),p=F*(P=e[r+1]),f=F*(w=e[r+2]),m=F*(D=e[r+3]),h+=U*v,l+=U*P,c+=U*w,u+=U*D,O=N;for(let nt=0;nt<F;nt++)O.r=v,O.g=P,O.b=w,O.a=D,O=O.next;let et=i;for(let nt=1;nt<=t;nt++)r=et+Y<<2,h+=(O.r=v=e[r])*(M=F-nt),l+=(O.g=P=e[r+1])*M,c+=(O.b=w=e[r+2])*M,u+=(O.a=D=e[r+3])*M,y+=v,C+=P,S+=w,b+=D,O=O.next,nt<W&&(et+=i);r=Y,j=N,it=$;for(let nt=0;nt<s;nt++)n=r<<2,e[n+3]=D=u*B>>L,D>0?(D=255/D,e[n]=(h*B>>L)*D,e[n+1]=(l*B>>L)*D,e[n+2]=(c*B>>L)*D):e[n]=e[n+1]=e[n+2]=0,h-=d,l-=p,c-=f,u-=m,d-=j.r,p-=j.g,f-=j.b,m-=j.a,n=Y+((n=nt+F)<W?n:W)*i<<2,h+=y+=j.r=e[n],l+=C+=j.g=e[n+1],c+=S+=j.b=e[n+2],u+=b+=j.a=e[n+3],j=j.next,d+=v=it.r,p+=P=it.g,f+=w=it.b,m+=D=it.a,y-=v,C-=P,S-=w,b-=D,it=it.next,r+=i}}const $n=function(t){const e=Math.round(this.blurRadius());e>0&&qn(t,e)};g.addGetterSetter(x,"blurRadius",0,k(),g.afterSetFilter);const Kn=function(a){const t=this.brightness()*255,e=a.data,i=e.length;for(let s=0;s<i;s+=4)e[s]+=t,e[s+1]+=t,e[s+2]+=t};g.addGetterSetter(x,"brightness",0,k(),g.afterSetFilter);const Zn=function(a){const t=this.brightness(),e=a.data,i=e.length;for(let s=0;s<i;s+=4)e[s]=Math.min(255,e[s]*t),e[s+1]=Math.min(255,e[s+1]*t),e[s+2]=Math.min(255,e[s+2]*t)},Jn=function(a){const t=Math.pow((this.contrast()+100)/100,2),e=a.data,i=e.length;let s=150,n=150,r=150;for(let o=0;o<i;o+=4)s=e[o],n=e[o+1],r=e[o+2],s/=255,s-=.5,s*=t,s+=.5,s*=255,n/=255,n-=.5,n*=t,n+=.5,n*=255,r/=255,r-=.5,r*=t,r+=.5,r*=255,s=s<0?0:s>255?255:s,n=n<0?0:n>255?255:n,r=r<0?0:r>255?255:r,e[o]=s,e[o+1]=n,e[o+2]=r};g.addGetterSetter(x,"contrast",0,k(),g.afterSetFilter);const Qn=function(a){var t,e,i,s,n,r,o,h,l;const c=a.data,u=a.width,d=a.height,p=Math.min(1,Math.max(0,(e=(t=this.embossStrength)===null||t===void 0?void 0:t.call(this))!==null&&e!==void 0?e:.5)),f=Math.min(1,Math.max(0,(s=(i=this.embossWhiteLevel)===null||i===void 0?void 0:i.call(this))!==null&&s!==void 0?s:.5)),y=(o={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[(r=(n=this.embossDirection)===null||n===void 0?void 0:n.call(this))!==null&&r!==void 0?r:"top-left"])!==null&&o!==void 0?o:315,C=!!((l=(h=this.embossBlend)===null||h===void 0?void 0:h.call(this))!==null&&l!==void 0&&l),S=p*10,b=f*255,v=y*Math.PI/180,P=Math.cos(v),w=Math.sin(v),D=128/1020*S,M=new Uint8ClampedArray(c),G=new Float32Array(u*d);for(let N=0,B=0;B<c.length;B+=4,N++)G[N]=.2126*M[B]+.7152*M[B+1]+.0722*M[B+2];const I=[-1,0,1,-2,0,2,-1,0,1],W=[-1,-2,-1,0,0,0,1,2,1],F=[-u-1,-u,-u+1,-1,0,1,u-1,u,u+1],U=N=>N<0?0:N>255?255:N;for(let N=1;N<d-1;N++)for(let B=1;B<u-1;B++){const L=N*u+B;let $=0,O=0;$+=G[L+F[0]]*I[0],O+=G[L+F[0]]*W[0],$+=G[L+F[1]]*I[1],O+=G[L+F[1]]*W[1],$+=G[L+F[2]]*I[2],O+=G[L+F[2]]*W[2],$+=G[L+F[3]]*I[3],O+=G[L+F[3]]*W[3],$+=G[L+F[5]]*I[5],O+=G[L+F[5]]*W[5],$+=G[L+F[6]]*I[6],O+=G[L+F[6]]*W[6],$+=G[L+F[7]]*I[7],O+=G[L+F[7]]*W[7],$+=G[L+F[8]]*I[8],O+=G[L+F[8]]*W[8];const j=P*$+w*O,it=U(b+j*D),Y=L*4;if(C){const et=it-b;c[Y]=U(M[Y]+et),c[Y+1]=U(M[Y+1]+et),c[Y+2]=U(M[Y+2]+et),c[Y+3]=M[Y+3]}else c[Y]=c[Y+1]=c[Y+2]=it,c[Y+3]=M[Y+3]}for(let N=0;N<u;N++){let B=N*4,L=((d-1)*u+N)*4;c[B]=M[B],c[B+1]=M[B+1],c[B+2]=M[B+2],c[B+3]=M[B+3],c[L]=M[L],c[L+1]=M[L+1],c[L+2]=M[L+2],c[L+3]=M[L+3]}for(let N=1;N<d-1;N++){let B=N*u*4,L=(N*u+(u-1))*4;c[B]=M[B],c[B+1]=M[B+1],c[B+2]=M[B+2],c[B+3]=M[B+3],c[L]=M[L],c[L+1]=M[L+1],c[L+2]=M[L+2],c[L+3]=M[L+3]}return a};g.addGetterSetter(x,"embossStrength",.5,k(),g.afterSetFilter);g.addGetterSetter(x,"embossWhiteLevel",.5,k(),g.afterSetFilter);g.addGetterSetter(x,"embossDirection","top-left",void 0,g.afterSetFilter);g.addGetterSetter(x,"embossBlend",!1,void 0,g.afterSetFilter);function xe(a,t,e,i,s){const n=e-t,r=s-i;if(n===0)return i+r/2;if(r===0)return i;let o=(a-t)/n;return o=r*o+i,o}const tr=function(a){const t=a.data,e=t.length;let i=t[0],s=i,n,r=t[1],o=r,h,l=t[2],c=l,u;const d=this.enhance();if(d===0)return;for(let b=0;b<e;b+=4)n=t[b+0],n<i?i=n:n>s&&(s=n),h=t[b+1],h<r?r=h:h>o&&(o=h),u=t[b+2],u<l?l=u:u>c&&(c=u);s===i&&(s=255,i=0),o===r&&(o=255,r=0),c===l&&(c=255,l=0);let p,f,m,y,C,S;if(d>0)p=s+d*(255-s),f=i-d*(i-0),m=o+d*(255-o),y=r-d*(r-0),C=c+d*(255-c),S=l-d*(l-0);else{const b=(s+i)*.5;p=s+d*(s-b),f=i+d*(i-b);const v=(o+r)*.5;m=o+d*(o-v),y=r+d*(r-v);const P=(c+l)*.5;C=c+d*(c-P),S=l+d*(l-P)}for(let b=0;b<e;b+=4)t[b+0]=xe(t[b+0],i,s,f,p),t[b+1]=xe(t[b+1],r,o,y,m),t[b+2]=xe(t[b+2],l,c,S,C)};g.addGetterSetter(x,"enhance",0,k(),g.afterSetFilter);const er=function(a){const t=a.data,e=t.length;for(let i=0;i<e;i+=4){const s=.34*t[i]+.5*t[i+1]+.16*t[i+2];t[i]=s,t[i+1]=s,t[i+2]=s}};g.addGetterSetter(x,"hue",0,k(),g.afterSetFilter);g.addGetterSetter(x,"saturation",0,k(),g.afterSetFilter);g.addGetterSetter(x,"luminance",0,k(),g.afterSetFilter);const ir=function(a){const t=a.data,e=t.length,i=1,s=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,r=this.luminance()*127,o=i*s*Math.cos(n*Math.PI/180),h=i*s*Math.sin(n*Math.PI/180),l=.299*i+.701*o+.167*h,c=.587*i-.587*o+.33*h,u=.114*i-.114*o-.497*h,d=.299*i-.299*o-.328*h,p=.587*i+.413*o+.035*h,f=.114*i-.114*o+.293*h,m=.299*i-.3*o+1.25*h,y=.587*i-.586*o-1.05*h,C=.114*i+.886*o-.2*h;let S,b,v,P;for(let w=0;w<e;w+=4)S=t[w+0],b=t[w+1],v=t[w+2],P=t[w+3],t[w+0]=l*S+c*b+u*v+r,t[w+1]=d*S+p*b+f*v+r,t[w+2]=m*S+y*b+C*v+r,t[w+3]=P},sr=function(a){const t=a.data,e=t.length,i=Math.pow(2,this.value()),s=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,r=i*s*Math.cos(n*Math.PI/180),o=i*s*Math.sin(n*Math.PI/180),h=.299*i+.701*r+.167*o,l=.587*i-.587*r+.33*o,c=.114*i-.114*r-.497*o,u=.299*i-.299*r-.328*o,d=.587*i+.413*r+.035*o,p=.114*i-.114*r+.293*o,f=.299*i-.3*r+1.25*o,m=.587*i-.586*r-1.05*o,y=.114*i+.886*r-.2*o;for(let C=0;C<e;C+=4){const S=t[C+0],b=t[C+1],v=t[C+2],P=t[C+3];t[C+0]=h*S+l*b+c*v,t[C+1]=u*S+d*b+p*v,t[C+2]=f*S+m*b+y*v,t[C+3]=P}};g.addGetterSetter(x,"hue",0,k(),g.afterSetFilter);g.addGetterSetter(x,"saturation",0,k(),g.afterSetFilter);g.addGetterSetter(x,"value",0,k(),g.afterSetFilter);const nr=function(a){const t=a.data,e=t.length;for(let i=0;i<e;i+=4)t[i]=255-t[i],t[i+1]=255-t[i+1],t[i+2]=255-t[i+2]},rr=function(a,t,e){const i=a.data,s=t.data,n=a.width,r=a.height,o=e.polarCenterX||n/2,h=e.polarCenterY||r/2;let l=Math.sqrt(o*o+h*h),c=n-o,u=r-h;const d=Math.sqrt(c*c+u*u);l=d>l?d:l;const p=r,f=n,m=360/f*Math.PI/180;for(let y=0;y<f;y+=1){const C=Math.sin(y*m),S=Math.cos(y*m);for(let b=0;b<p;b+=1){c=Math.floor(o+l*b/p*S),u=Math.floor(h+l*b/p*C);let v=(u*n+c)*4;const P=i[v+0],w=i[v+1],D=i[v+2],M=i[v+3];v=(y+b*n)*4,s[v+0]=P,s[v+1]=w,s[v+2]=D,s[v+3]=M}}},ar=function(a,t,e){const i=a.data,s=t.data,n=a.width,r=a.height,o=e.polarCenterX||n/2,h=e.polarCenterY||r/2;let l=Math.sqrt(o*o+h*h),c=n-o,u=r-h;const d=Math.sqrt(c*c+u*u);l=d>l?d:l;const p=r,f=n,m=0;let y,C;for(c=0;c<n;c+=1)for(u=0;u<r;u+=1){const S=c-o,b=u-h,v=Math.sqrt(S*S+b*b)*p/l;let P=(Math.atan2(b,S)*180/Math.PI+360+m)%360;P=P*f/360,y=Math.floor(P),C=Math.floor(v);let w=(C*n+y)*4;const D=i[w+0],M=i[w+1],G=i[w+2],I=i[w+3];w=(u*n+c)*4,s[w+0]=D,s[w+1]=M,s[w+2]=G,s[w+3]=I}},or=function(a){const t=a.width,e=a.height;let i,s,n,r,o,h,l,c,u,d,p=Math.round(this.kaleidoscopePower());const f=Math.round(this.kaleidoscopeAngle()),m=Math.floor(t*(f%360)/360);if(p<1)return;const y=_.createCanvasElement();y.width=t,y.height=e;const C=y.getContext("2d").getImageData(0,0,t,e);_.releaseCanvas(y),rr(a,C,{polarCenterX:t/2,polarCenterY:e/2});let S=t/Math.pow(2,p);for(;S<=8;)S=S*2,p-=1;S=Math.ceil(S);let b=S,v=0,P=b,w=1;for(m+S>t&&(v=b,P=0,w=-1),s=0;s<e;s+=1)for(i=v;i!==P;i+=w)n=Math.round(i+m)%t,u=(t*s+n)*4,o=C.data[u+0],h=C.data[u+1],l=C.data[u+2],c=C.data[u+3],d=(t*s+i)*4,C.data[d+0]=o,C.data[d+1]=h,C.data[d+2]=l,C.data[d+3]=c;for(s=0;s<e;s+=1)for(b=Math.floor(S),r=0;r<p;r+=1){for(i=0;i<b+1;i+=1)u=(t*s+i)*4,o=C.data[u+0],h=C.data[u+1],l=C.data[u+2],c=C.data[u+3],d=(t*s+b*2-i-1)*4,C.data[d+0]=o,C.data[d+1]=h,C.data[d+2]=l,C.data[d+3]=c;b*=2}ar(C,a,{})};g.addGetterSetter(x,"kaleidoscopePower",2,k(),g.afterSetFilter);g.addGetterSetter(x,"kaleidoscopeAngle",0,k(),g.afterSetFilter);function he(a,t,e){let i=(e*a.width+t)*4;const s=[];return s.push(a.data[i++],a.data[i++],a.data[i++],a.data[i++]),s}function zt(a,t){return Math.sqrt(Math.pow(a[0]-t[0],2)+Math.pow(a[1]-t[1],2)+Math.pow(a[2]-t[2],2))}function hr(a){const t=[0,0,0];for(let e=0;e<a.length;e++)t[0]+=a[e][0],t[1]+=a[e][1],t[2]+=a[e][2];return t[0]/=a.length,t[1]/=a.length,t[2]/=a.length,t}function lr(a,t){const e=he(a,0,0),i=he(a,a.width-1,0),s=he(a,0,a.height-1),n=he(a,a.width-1,a.height-1),r=t||10;if(zt(e,i)<r&&zt(i,n)<r&&zt(n,s)<r&&zt(s,e)<r){const o=hr([i,e,n,s]),h=[];for(let l=0;l<a.width*a.height;l++){const c=zt(o,[a.data[l*4],a.data[l*4+1],a.data[l*4+2]]);h[l]=c<r?0:255}return h}}function cr(a,t){for(let e=0;e<a.width*a.height;e++)a.data[4*e+3]=t[e]}function dr(a,t,e){const i=[1,1,1,1,0,1,1,1,1],s=Math.round(Math.sqrt(i.length)),n=Math.floor(s/2),r=[];for(let o=0;o<e;o++)for(let h=0;h<t;h++){const l=o*t+h;let c=0;for(let u=0;u<s;u++)for(let d=0;d<s;d++){const p=o+u-n,f=h+d-n;if(p>=0&&p<e&&f>=0&&f<t){const m=p*t+f,y=i[u*s+d];c+=a[m]*y}}r[l]=c===255*8?255:0}return r}function ur(a,t,e){const i=[1,1,1,1,1,1,1,1,1],s=Math.round(Math.sqrt(i.length)),n=Math.floor(s/2),r=[];for(let o=0;o<e;o++)for(let h=0;h<t;h++){const l=o*t+h;let c=0;for(let u=0;u<s;u++)for(let d=0;d<s;d++){const p=o+u-n,f=h+d-n;if(p>=0&&p<e&&f>=0&&f<t){const m=p*t+f,y=i[u*s+d];c+=a[m]*y}}r[l]=c>=255*4?255:0}return r}function fr(a,t,e){const i=[.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111],s=Math.round(Math.sqrt(i.length)),n=Math.floor(s/2),r=[];for(let o=0;o<e;o++)for(let h=0;h<t;h++){const l=o*t+h;let c=0;for(let u=0;u<s;u++)for(let d=0;d<s;d++){const p=o+u-n,f=h+d-n;if(p>=0&&p<e&&f>=0&&f<t){const m=p*t+f,y=i[u*s+d];c+=a[m]*y}}r[l]=c}return r}const gr=function(a){const t=this.threshold();let e=lr(a,t);return e&&(e=dr(e,a.width,a.height),e=ur(e,a.width,a.height),e=fr(e,a.width,a.height),cr(a,e)),a};g.addGetterSetter(x,"threshold",0,k(),g.afterSetFilter);const pr=function(a){const t=this.noise()*255,e=a.data,i=e.length,s=t/2;for(let n=0;n<i;n+=4)e[n+0]+=s-2*s*Math.random(),e[n+1]+=s-2*s*Math.random(),e[n+2]+=s-2*s*Math.random()};g.addGetterSetter(x,"noise",.2,k(),g.afterSetFilter);const mr=function(a){let t=Math.ceil(this.pixelSize()),e=a.width,i=a.height,s=Math.ceil(e/t),n=Math.ceil(i/t),r=a.data;if(t<=0){_.error("pixelSize value can not be <= 0");return}for(let o=0;o<s;o+=1)for(let h=0;h<n;h+=1){let l=0,c=0,u=0,d=0;const p=o*t,f=p+t,m=h*t,y=m+t;let C=0;for(let S=p;S<f;S+=1)if(!(S>=e))for(let b=m;b<y;b+=1){if(b>=i)continue;const v=(e*b+S)*4;l+=r[v+0],c+=r[v+1],u+=r[v+2],d+=r[v+3],C+=1}l=l/C,c=c/C,u=u/C,d=d/C;for(let S=p;S<f;S+=1)if(!(S>=e))for(let b=m;b<y;b+=1){if(b>=i)continue;const v=(e*b+S)*4;r[v+0]=l,r[v+1]=c,r[v+2]=u,r[v+3]=d}}};g.addGetterSetter(x,"pixelSize",8,k(),g.afterSetFilter);const yr=function(a){const t=Math.round(this.levels()*254)+1,e=a.data,i=e.length,s=255/t;for(let n=0;n<i;n+=1)e[n]=Math.floor(e[n]/s)*s};g.addGetterSetter(x,"levels",.5,k(),g.afterSetFilter);const _r=function(a){const t=a.data,e=t.length,i=this.red(),s=this.green(),n=this.blue();for(let r=0;r<e;r+=4){const o=(.34*t[r]+.5*t[r+1]+.16*t[r+2])/255;t[r]=o*i,t[r+1]=o*s,t[r+2]=o*n,t[r+3]=t[r+3]}};g.addGetterSetter(x,"red",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(x,"green",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(x,"blue",0,pi,g.afterSetFilter);const Cr=function(a){const t=a.data,e=t.length,i=this.red(),s=this.green(),n=this.blue(),r=this.alpha();for(let o=0;o<e;o+=4){const h=1-r;t[o]=i*r+t[o]*h,t[o+1]=s*r+t[o+1]*h,t[o+2]=n*r+t[o+2]*h}};g.addGetterSetter(x,"red",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(x,"green",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(x,"blue",0,pi,g.afterSetFilter);g.addGetterSetter(x,"alpha",1,function(a){return this._filterUpToDate=!1,a>1?1:a<0?0:a});const Sr=function(a){const t=a.data,e=t.length;for(let i=0;i<e;i+=4){const s=t[i+0],n=t[i+1],r=t[i+2];t[i+0]=Math.min(255,s*.393+n*.769+r*.189),t[i+1]=Math.min(255,s*.349+n*.686+r*.168),t[i+2]=Math.min(255,s*.272+n*.534+r*.131)}},br=function(a){const e=a.data;for(let i=0;i<e.length;i+=4){const s=e[i],n=e[i+1],r=e[i+2];.2126*s+.7152*n+.0722*r>=128&&(e[i]=255-s,e[i+1]=255-n,e[i+2]=255-r)}return a},vr=function(a){const t=this.threshold()*255,e=a.data,i=e.length;for(let s=0;s<i;s+=1)e[s]=e[s]<t?0:255};g.addGetterSetter(x,"threshold",.5,k(),g.afterSetFilter);const V=si.Util._assign(si,{Arc:ft,Arrow:Et,Circle:It,Ellipse:St,Image:lt,Label:ze,Tag:Pt,Line:gt,Path:Z,Rect:Jt,RegularPolygon:bt,Ring:Rt,Sprite:ct,Star:vt,Text:J,TextPath:st,Transformer:H,Wedge:pt,Filters:{Blur:$n,Brightness:Zn,Brighten:Kn,Contrast:Jn,Emboss:Qn,Enhance:tr,Grayscale:er,HSL:ir,HSV:sr,Invert:nr,Kaleidoscope:or,Mask:gr,Noise:pr,Pixelate:mr,Posterize:yr,RGB:_r,RGBA:Cr,Sepia:Sr,Solarize:br,Threshold:vr}});class R{static setDebugEnabled(t){this.debugEnabled=t}static setModuleDebugEnabled(t,e){this.moduleDebugEnabled.set(t,e)}static isModuleDebugEnabled(t){return this.moduleDebugEnabled.get(t)??this.debugEnabled}static debug(t,e,i){this.isModuleDebugEnabled(t)&&console.log(`[DEBUG] [${t}] ${e}`,i)}static info(t,e,i){console.log(`[INFO] [${t}] ${e}`,i)}static warn(t,e,i){console.warn(`[WARN] [${t}] ${e}`,i)}static error(t,e,i){console.error(`[ERROR] [${t}] ${e}`,i)}}A(R,"debugEnabled",!1),A(R,"moduleDebugEnabled",new Map);const ut=class ut{static createStage(t,e,i){return new V.Stage({container:t,width:e,height:i})}static createLayer(t){const e=new V.Layer;return e.name(t),e}static createRect(t,e,i,s,n="#ffffff",r="#000000",o=1){return new V.Rect({x:t,y:e,width:i,height:s,fill:n,stroke:r,strokeWidth:o})}static createText(t,e,i,s=12,n="Arial",r="#000000",o="left",h="top"){return new V.Text({text:t,x:e,y:i,fontSize:s,fontFamily:n,fill:r,align:o,verticalAlign:h})}static createLine(t,e="#000000",i=1){return new V.Line({points:t,stroke:e,strokeWidth:i,lineCap:"round",lineJoin:"round"})}static createGroup(t=0,e=0){return new V.Group({x:t,y:e})}static createPlayhead(t,e,i){const s=new V.Group({x:t,y:e}),n=this.createLine([0,0,0,i],"#FF0000",2),r=new V.RegularPolygon({x:0,y:-10,sides:3,radius:5,fill:"#FF0000",rotation:180});return s.add(n),s.add(r),s}static drawTimeTick(t,e,i,s,n,r,o,h){const l=h||s;let c;o==="major"?c=l*.6:c=l*.3;const u=this.createLine([e,i,e,i+c],r.timeTick,o==="major"?1:.5);if(u.name("time-tick-line"),t.add(u),o==="major"){const d=i+c+5,p=this.formatTime(n),f=this.createText(p,e,d,10,"Arial",r.timeText,"center");f.name("time-tick-text"),t.add(f)}}static drawGrid(t,e,i,s,n,r){const o=this.createGroup(e,i);for(let h=0;h<=s;h+=r){const l=this.createLine([h,0,h,n],"#E0E0E0",.5);o.add(l)}for(let h=0;h<=n;h+=r){const l=this.createLine([0,h,s,h],"#E0E0E0",.5);o.add(l)}t.add(o)}static formatTime(t){const e=t/1e3,i=Math.floor(e/60),s=Math.floor(e%60),n=Math.floor(t%1e3/10);return`${i.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}.${n.toString().padStart(2,"0")}`}static formatDuration(t){const e=Math.floor(t/1e3),i=Math.floor(t%1e3/10);return`${e}.${i.toString().padStart(2,"0")}s`}static getKeyframeDimensions(t,e){return this.keyframeDimensionsCache[t]?Promise.resolve(this.keyframeDimensionsCache[t]):new Promise(i=>{const s=this.getCachedImage(e);if(s.complete&&s.width>0){const n={width:s.width,height:s.height};this.keyframeDimensionsCache[t]=n,i(n);return}s.onload=()=>{const n={width:s.width,height:s.height};this.keyframeDimensionsCache[t]=n,i(n)},s.onerror=()=>{console.warn(`Failed to load keyframe: ${e}, using default dimensions`),i({width:160,height:90})},s.src||(s.src=e)})}static getCachedImage(t){if(this.imageCache[t])return this.imageCache[t];const e=new Image;return this.imageCache[t]=e,this.checkAndTrimCache(),e}static checkAndTrimCache(){const t=Object.keys(this.imageCache);if(t.length>this.MAX_CACHE_SIZE){const e=t.length-this.MAX_CACHE_SIZE;for(let i=0;i<e;i++){const s=t[i];delete this.imageCache[s]}}}static clearImageCache(){this.imageCache={}}static createClipGroup(t,e,i,s,n,r,o,h=!1,l,c){const u=this.createGroup(t,e),d=4,p=15,f=s-p-4,m=i-this.RESIZE_AREA_WIDTH*2,y={...o,background:h&&o.clipSelectedBackground||o.clipBackground,name:h&&o.clipSelectedName||o.clipName,duration:h&&o.clipSelectedDuration||o.clipDuration,handle:h&&o.clipSelectedHandle||o.clipHandle,coverBackground:h?o.clipSelectedCoverBackground||o.clipCoverBackground||"#FFF2A0":o.clipCoverBackground||"#FFF2A0"},C=this.createRect(0,0,i,s,y.background,y.clipBorder||"transparent",0);C.cornerRadius(d),C.name("clip-background"),u.add(C);const S=new V.Rect({x:0,y:0,width:this.RESIZE_AREA_WIDTH,height:s,name:"clip-resize-left"});u.add(S);const b=new V.Rect({x:i-this.RESIZE_AREA_WIDTH,y:0,width:this.RESIZE_AREA_WIDTH,height:s,name:"clip-resize-right"});u.add(b);const v=this.createGroup(this.RESIZE_AREA_WIDTH,2);v.name("clip-cover-container"),v.clip({x:0,y:0,width:m,height:f}),u.add(v);const P=this.createRect(0,0,m,f,y.coverBackground,"transparent",0);P.cornerRadius(2),P.name("clip-cover-background"),v.add(P);const w=l??[],D=this.createGroup(0,0);D.name("clip-covers-group"),v.add(D),this.renderClipCovers(D,w,m,f,c);const M=this.formatDuration(r),G=`${n} ${M}`,I=this.createText(G,this.RESIZE_AREA_WIDTH,s-p,10,"Arial",y.name,"left","middle");return I.ellipsis(!0),I.width(m),I.height(p),I.name("clip-label"),u.add(I),u}static updateClipGroup(t,e,i,s,n,r,o=!1,h,l){const u=i-15-4,d=e-this.RESIZE_AREA_WIDTH*2,p=t.findOne(".clip-background");if(p&&(p.width(e),p.height(i),r)){const b=o&&r.clipSelectedBackground||r.clipBackground;new V.Tween({node:p,duration:.2,fill:b,easing:V.Easings.EaseInOut}).play()}const f=t.findOne(".clip-resize-right");f&&(f.x(e-this.RESIZE_AREA_WIDTH),f.height(i));let m=t.findOne(".clip-cover-container");if(m){m.x(this.RESIZE_AREA_WIDTH),m.y(2),m.clip({x:0,y:0,width:d,height:u});const b=m.findOne(".clip-cover-background");if(b&&(b.width(d),b.height(u),r)){const v=o?r.clipSelectedCoverBackground||r.clipCoverBackground||"#FFF2A0":r.clipCoverBackground||"#FFF2A0";new V.Tween({node:b,duration:.2,fill:v,easing:V.Easings.EaseInOut}).play()}}else{m=this.createGroup(this.RESIZE_AREA_WIDTH,2),m.name("clip-cover-container"),m.clip({x:0,y:0,width:d,height:u}),t.add(m);const b=o?(r==null?void 0:r.clipSelectedCoverBackground)||(r==null?void 0:r.clipCoverBackground)||"#FFF2A0":(r==null?void 0:r.clipCoverBackground)||"#FFF2A0",v=this.createRect(0,0,d,u,b,"transparent",0);v.cornerRadius(2),v.name("clip-cover-background"),m.add(v)}const y=h&&h.length>0?h:void 0;let C=m.findOne(".clip-covers-group");C||(C=this.createGroup(0,0),C.name("clip-covers-group"),m.add(C)),y&&this.renderClipCovers(C,y,d,u,l);const S=t.findOne(".clip-label");if(S){const b=this.formatDuration(n),v=`${s} ${b}`;if(S.text(v),S.y(i-15),S.width(d),r){const P=o&&r.clipSelectedName||r.clipName;S.fill(P)}}}static createSelectionEffect(t,e,i,s){return new V.Rect({x:t,y:e,width:i,height:s,stroke:"#50E3C2",strokeWidth:2,dash:[5,5],fillEnabled:!1})}static timeToPixels(t,e){return t/1e3*e}static async renderClipCovers(t,e,i,s,n){var o;R.debug("KonvaUtils","renderClipCovers",{videoSrc:n,coverSource:e,coverWidth:i,coverHeight:s});const r=t.find(".cover-image");if(e&&e.length>0){const h=new Set(e),l=new Map;let c=null;const u=n||(e.length>0?e[0]:""),d=await ut.getKeyframeDimensions(u,e[0]);if(d){const f=d.width/d.height;c=s*f}let p=0;for(let f=0;f<r.length;f++){const m=r[f],y=(o=m.attrs.image)==null?void 0:o.src;y&&h.has(y)?l.set(y,m):m.remove()}for(let f=0;f<e.length;f++){const m=e[f];let y=l.get(m);if(!y){const C=ut.getCachedImage(m);y=new V.Image({image:C,cornerRadius:2,name:"cover-image"}),t.add(y),C.src||(C.src=m)}if(c&&y)y.width(c),y.height(s),y.x(f*c+f*p),y.y(0);else if(y){const C=n||m;ut.getKeyframeDimensions(C,m).then(S=>{if(!y)return;const b=S.width/S.height,v=s,P=v*b;y.width(P),y.height(v),y.x(f*P+f*p),y.y(0)}).catch(S=>{if(!y)return;console.warn(`Failed to get keyframe dimensions: ${S}, using default dimensions`);const b=s,v=b*(16/9);y.width(v),y.height(b),y.x(f*v+f*p),y.y(0)})}}}else e&&e.length===0&&t&&t.destroyChildren()}static pixelsToTime(t,e){return t/e*1e3}};A(ut,"RESIZE_AREA_WIDTH",8),A(ut,"keyframeDimensionsCache",{}),A(ut,"imageCache",{}),A(ut,"MAX_CACHE_SIZE",100);let Q=ut;const wt={MIN:1,MEDIUM:50,MAX:100},Tr={DURATION:300};class ji{constructor(t,e,i,s,n,r){A(this,"stage");A(this,"gridLayer");A(this,"config");A(this,"theme");A(this,"isDragging",!1);A(this,"startDragX",0);A(this,"scrollLeft",0);A(this,"timeScaleHeight",40);A(this,"onTimeChange");A(this,"onZoomChange");A(this,"onScrollChange");A(this,"animationFrameId",null);A(this,"isZooming",!1);this.stage=t,this.gridLayer=e,this.onTimeChange=s,this.onZoomChange=n,this.onScrollChange=r,this.config={duration:i.duration||36e5,zoom:i.zoom||wt.MEDIUM,currentTime:i.currentTime||0,playState:i.playState||"paused",container:i.container,theme:i.theme,timeScaleHeight:i.timeScaleHeight},this.theme=this.config.theme||ue,i.timeScaleHeight&&(this.timeScaleHeight=i.timeScaleHeight),this.initEventListeners(),this.render()}initEventListeners(){this.stage.on("wheel",t=>{t.evt.preventDefault(),this.handleZoom(t)}),this.stage.on("click",t=>{t.target.getLayer()===this.gridLayer&&this.handleClick(t.evt.offsetX)}),this.stage.on("mousedown",t=>{t.target.getLayer()===this.gridLayer&&(this.isDragging=!0,this.startDragX=t.evt.clientX)}),this.stage.on("mousemove",t=>{if(this.isDragging){const e=t.evt.clientX-this.startDragX,i=this.scrollLeft;this.scrollLeft-=e,this.scrollLeft=Math.max(0,this.scrollLeft),this.startDragX=t.evt.clientX,this.render(),this.scrollLeft!==i&&this.onScrollChange(this.scrollLeft)}}),this.stage.on("mouseup",()=>{this.isDragging=!1}),this.stage.on("mouseleave",()=>{this.isDragging=!1})}handleZoom(t){if(this.isZooming)return;const i=t.evt.deltaY>0?.5:1.5,s=Math.max(wt.MIN,Math.min(wt.MAX,this.config.zoom*i));if(s!==this.config.zoom){const n=t.evt.offsetX;this.animateZoom(s,n)}}animateZoom(t,e){this.isZooming=!0;const i=this.config.zoom,s=Tr.DURATION,n=Date.now(),r=this.pixelToTime(e),o=()=>{const h=Date.now()-n,l=Math.min(h/s,1),c=this.easeOutCubic(l),u=i+(t-i)*c,d=z.timeToPixels(r,u),p=Math.max(0,d-e);if(this.scrollLeft=p,this.config.zoom=u,this.onZoomChange(u),this.onScrollChange(p),this.render(),l<1)this.animationFrameId=requestAnimationFrame(o);else{const f=z.timeToPixels(r,t),m=Math.max(0,f-e);this.config.zoom=t,this.scrollLeft=m,this.onZoomChange(t),this.onScrollChange(m),this.render(),this.isZooming=!1}};this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),o()}easeOutCubic(t){return 1-Math.pow(1-t,3)}handleClick(t){const e=this.pixelToTime(t);this.setCurrentTime(e)}pixelToTime(t){return z.pixelsToTime(t+this.scrollLeft,this.config.zoom)}timeToPixel(t){return z.timeToPixels(t,this.config.zoom)-this.scrollLeft}setCurrentTime(t){this.config.currentTime=Math.max(0,t),this.onTimeChange(this.config.currentTime)}setZoom(t){this.config.zoom=t,this.render()}setDuration(t){this.config.duration=t,this.render()}setPlayState(t){this.config.playState=t,this.render()}update(){this.render()}render(){const t=this.stage.width(),e=this.stage.height(),i=this.gridLayer.findOne(".timeline-background");if(i)i.width(t),i.height(e),i.fill(this.theme.background),i.stroke(this.theme.border);else{const s=Q.createRect(0,0,t,e,this.theme.background,this.theme.border,1);s.name("timeline-background"),this.gridLayer.add(s)}this.gridLayer.find(".grid-line").forEach(s=>s.remove()),this.gridLayer.find(".time-tick-line").forEach(s=>s.remove()),this.gridLayer.find(".time-tick-text").forEach(s=>s.remove()),this.renderTimeTicks(),this.gridLayer.batchDraw()}renderTimeTicks(){const t=this.stage.width(),e=this.scrollLeft,i=this.scrollLeft+t,s=z.pixelsToTime(e,this.config.zoom),n=z.pixelsToTime(i,this.config.zoom),r=z.msToSeconds(s),o=z.msToSeconds(n),h=10,l=r-h,c=o+h,{majorStep:u,minorStep:d}=z.getTickConfig(this.config.zoom),p=z.generateVisibleTicks(l,c,u,d);let f=0;const m=20;for(const y of p){const C=this.timeToPixel(y.time);C>=-m&&C<=t+m&&(Q.drawTimeTick(this.gridLayer,C,0,this.timeScaleHeight,y.time,{timeTick:this.theme.timeTick,timeText:this.theme.timeText},y.type,this.timeScaleHeight),f++)}R.debug("Timeline",`📌 Timeline - scrollLeft: ${this.scrollLeft}px, zoom: ${this.config.zoom}px/s, visible time: ${Math.round(r)}s to ${Math.round(o)}s, ticks: ${p.length} generated, ${f} drawn`)}getConfig(){return{...this.config}}getScrollLeft(){return this.scrollLeft}setScrollLeft(t){this.scrollLeft=t,this.render()}scrollToTime(t){const e=z.timeToPixels(t,this.config.zoom),i=this.stage.width(),s=Math.max(0,e-i/2);this.setScrollLeft(s),this.onScrollChange(s)}scrollToClip(t){const e=z.timeToPixels(t.startTime,this.config.zoom),s=z.timeToPixels(t.startTime+t.duration,this.config.zoom)-e,n=this.stage.width();let r;s<=n?r=Math.max(0,e-(n-s)/2):r=Math.max(0,e),this.setScrollLeft(r),this.onScrollChange(r)}getStage(){return this.stage}getGridLayer(){return this.gridLayer}resize(t,e){this.render()}}class de{constructor(t,e,i){A(this,"clip");A(this,"onUpdate");A(this,"onSplit");A(this,"isMoving",!1);A(this,"dragStartPos",{x:0,y:0});A(this,"originalStart",0);A(this,"originalDuration",0);A(this,"originalStartTimeAtSource",0);A(this,"originalEndTimeAtSource",0);A(this,"originalOpacity",1);this.clip={...t,endTime:z.calculateEndTime(t.startTime,t.duration),isDragging:!1,isResizingLeft:!1,isResizingRight:!1,isSelected:!1,isResizing:!1,zIndex:1,opacity:1},this.onUpdate=e,this.onSplit=i}checkCollision(t,e,i){const s=t+e;return i.find(r=>{if(r.id===this.clip.id)return!1;const o=r.startTime+r.duration;return t<o&&r.startTime<s})}checkBoundary(t,e,i,s){return!(s<0||i<1e3||t<0||e>this.clip.sourceDuration)}getCenterTime(){return this.clip.startTime+this.clip.duration/2}getClip(){return{...this.clip}}setSelected(t){this.clip={...this.clip,isSelected:t},this.onUpdate(this.clip)}isPointInClip(t,e,i,s,n,r){const o=z.timeToPixels(this.clip.startTime,i)-r,h=z.timeToPixels(this.clip.duration,i);return t>=o&&t<=o+h&&e>=s&&e<=s+n}isPointInResizeHandle(t,e,i,s,n,r){const o=z.timeToPixels(this.clip.startTime,i)-r,h=z.timeToPixels(this.clip.duration,i),l=8;return e<s||e>s+n?(this.clip={...this.clip,isResizingLeft:!1,isResizingRight:!1},R.debug("Clip","Not in clip area",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,trackY:s,trackHeight:n}),!1):t>=o&&t<=o+l?(this.clip={...this.clip,isResizingLeft:!0,isResizingRight:!1},R.debug("Clip","Left resize handle detected",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,handleSize:l}),!0):t>=o+h-l&&t<=o+h?(this.clip={...this.clip,isResizingLeft:!1,isResizingRight:!0},R.debug("Clip","Right resize handle detected",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,handleSize:l}),!0):(this.clip={...this.clip,isResizingLeft:!1,isResizingRight:!1},R.debug("Clip","Not in resize handle",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,handleSize:l}),!1)}startDrag(t){this.dragStartPos=t,this.originalStart=this.clip.startTime,this.originalDuration=this.clip.duration,this.originalStartTimeAtSource=this.clip.startTimeAtSource,this.originalEndTimeAtSource=this.clip.endTimeAtSource,this.isMoving=!0,this.originalOpacity=this.clip.opacity,this.clip={...this.clip,isDragging:!0,isResizingLeft:!1,isResizingRight:!1,opacity:.5,zIndex:1e3},this.onUpdate(this.clip),R.debug("Clip","startDrag",{pos:t,clip:this.clip,isMoving:this.isMoving,originalOpacity:this.originalOpacity})}startResize(t){this.dragStartPos=t,this.originalStart=this.clip.startTime,this.originalDuration=this.clip.duration,this.originalStartTimeAtSource=this.clip.startTimeAtSource,this.originalEndTimeAtSource=this.clip.endTimeAtSource,this.clip={...this.clip,isDragging:!0,zIndex:1e3},this.onUpdate(this.clip),R.debug("Clip","startResize",{pos:t,clip:this.clip})}drag(t,e,i=[],s=!1){if(!this.clip.isDragging)return!1;R.debug("Clip","拖拽");const n=t.x-this.dragStartPos.x,r=z.pixelsToTime(n,e);R.debug("Clip","deltaX",n),R.debug("Clip","deltaTime",r);let o=this.originalStart,h=this.originalDuration,l=this.originalStartTimeAtSource,c=this.originalEndTimeAtSource,u="move";if(this.clip.isResizingLeft){const C=Math.max(0,this.originalStart+r)-this.originalStart,b=Math.max(0,this.originalStartTimeAtSource+r)-this.originalStartTimeAtSource,v=Math.abs(C),P=Math.abs(b),w=v<P?C:b;o=this.originalStart+w,h=this.originalDuration-w;const D=z.calculateEndTime(this.originalStart,this.originalDuration);h<1e3?(h=1e3,o=D-h,l=this.originalEndTimeAtSource-h):l=this.originalStartTimeAtSource+w,c=this.originalEndTimeAtSource,u="resize-left",R.debug("Clip","Resize left",{operation:u,clipId:this.clip.id,originalStartTimeAtSource:this.originalStartTimeAtSource,newStartTimeAtSource:l,deltaTime:r,actualDeltaTime:w,timelineDeltaTime:C,sourceDeltaTime:b,newDuration:h,newEndTimeAtSource:c})}else this.clip.isResizingRight?(h=Math.max(1e3,this.originalDuration+r),l=this.originalStartTimeAtSource,c=Math.min(this.clip.sourceDuration,l+h),h=c-l,u="resize-right",R.debug("Clip","Resize right",{operation:u,clipId:this.clip.id,originalStartTimeAtSource:this.originalStartTimeAtSource,newStartTimeAtSource:l,deltaTime:r,newDuration:h,newEndTimeAtSource:c})):(o=Math.max(0,this.originalStart+r),u="move");let d=z.calculateEndTime(o,h),p=!0,f;if(s&&!this.isMoving){if(p=this.checkBoundary(l,c,h,o),!p)return R.debug("Clip",`Boundary check failed - ${u}`,{clipId:this.clip.id,operation:u,newStart:o,newDuration:h,newStartTimeAtSource:l,newEndTimeAtSource:c,deltaX:n,deltaTime:r}),!1;if(f=this.checkCollision(o,h,i),f){const y=f.startTime+f.duration;let C=!1;if(this.clip.isResizingLeft||this.clip.isResizingRight){if(this.clip.isResizingLeft){if(R.debug("Clip","Resizing left with collision",{clipId:this.clip.id,collisionClip:f,newStart:o,collisionEndTime:y}),o<=y){const S=y,b=d-S;if(b>=1e3){const v=S-o;o=S,h=b,l+=v,d=z.calculateEndTime(o,h),C=!0,R.debug("Clip","Resizing left adjusted to avoid collision",{clipId:this.clip.id,newStart:o,newDuration:h,newStartTimeAtSource:l})}}}else if(this.clip.isResizingRight&&(R.debug("Clip","Resizing right with collision",{clipId:this.clip.id,collisionClip:f,newEndTime:d,collisionStart:f.startTime}),d>=f.startTime)){const S=f.startTime-o;S>=1e3&&(h=S,c=l+h,d=z.calculateEndTime(o,h),C=!0,R.debug("Clip","Resizing right adjusted to avoid collision",{clipId:this.clip.id,newDuration:h,newEndTimeAtSource:c}))}}if(!C)return R.debug("Clip","Collision check failed",{clipId:this.clip.id,collisionClip:f,otherClips:i,operation:u,newStart:o,newDuration:h,newStartTimeAtSource:l,newEndTimeAtSource:c,deltaX:n,deltaTime:r}),!1}}return this.clip={...this.clip,startTime:o,duration:h,endTime:d,startTimeAtSource:l,endTimeAtSource:c},R.debug("Clip","Successful update",{clipId:this.clip.id,operation:u,deltaX:n,deltaTime:r,newStart:o,newDuration:h,newEndTime:d,boundaryCheckPassed:p,collisionCheckPassed:f}),!0}endDrag(){R.debug("Clip","Drag operation ended",{clipId:this.clip.id,finalStart:this.clip.startTime,finalDuration:this.clip.duration,finalEndTime:this.clip.endTime}),this.clip={...this.clip,isDragging:!1,isResizingLeft:!1,isResizingRight:!1,opacity:this.isMoving?this.originalOpacity:this.clip.opacity,zIndex:1},this.isMoving=!1}split(t){t>this.clip.startTime+1&&t<this.clip.endTime-1&&this.onSplit(this.clip,t)}createKonvaGroup(t,e,i,s){const n=z.timeToPixels(this.clip.startTime,t)-e,r=z.timeToPixels(this.clip.duration,t),o=2,h=s-4,l=new V.Group({x:n,y:o,opacity:this.clip.opacity,zIndex:this.clip.zIndex}),c=this.clip.isSelected?"#50E3C2":"#4A90E2",u=new V.Rect({width:r,height:h,fill:c,stroke:"#2C5AA0",strokeWidth:1});l.add(u);const d=new V.Rect({x:5,y:5,width:30,height:h-10,fill:"#2C5AA0",stroke:"#1A365D",strokeWidth:1});l.add(d);const p=new V.Text({text:this.clip.name,x:40,y:5,fontSize:12,fontFamily:"Arial",fill:"#ffffff"});l.add(p);const f=Q.formatDuration(this.clip.duration),m=new V.Text({text:f,x:10,y:h-20,fontSize:10,fontFamily:"Arial",fill:"#ffffff"});return l.add(m),this.renderResizeHandles(l,r,h),l}renderResizeHandles(t,e,i){const n=(i-8)/2,r=new V.Rect({x:-8/2,y:n,width:8,height:8,fill:"#ffffff",stroke:"#2C5AA0",strokeWidth:1});r.name("leftHandle"),t.add(r);const o=new V.Rect({x:e-8/2,y:n,width:8,height:8,fill:"#ffffff",stroke:"#2C5AA0",strokeWidth:1});o.name("rightHandle"),t.add(o)}updateKonvaGroup(t,e,i,s){const n=z.timeToPixels(this.clip.startTime,e)-i,r=z.timeToPixels(this.clip.duration,e),o=s-4;t.x(n),t.opacity(this.clip.opacity);const h=t.getChildren()[0];h.width(r),h.height(o),t.getChildren()[1].height(o-10),t.getChildren()[2].text(this.clip.name);const u=t.getChildren()[3];u.text(Q.formatDuration(this.clip.duration)),u.y(o-20),t.find(".rightHandle")[0].x(r-4)}}class qi{constructor(t,e,i,s,n,r,o,h,l,c,u){A(this,"layer");A(this,"trackGroup");A(this,"config");A(this,"theme");A(this,"clips",[]);A(this,"clipGroups",new Map);A(this,"zoom",100);A(this,"scrollLeft",0);A(this,"trackY",0);A(this,"trackHeight",64);A(this,"selectedClip",null);A(this,"originalClipsState",[]);A(this,"nonDraggedClips",[]);A(this,"isVisualUpdate",!1);A(this,"onClipUpdate");A(this,"onClipAdd");A(this,"onClipRemove");A(this,"onClipSplit");A(this,"onClipSelect");this.layer=t,this.config=e,this.theme=r,this.zoom=i,this.trackY=s,this.trackHeight=n,this.onClipUpdate=o,this.onClipAdd=h,this.onClipRemove=l,this.onClipSplit=c,this.onClipSelect=u,this.trackGroup=Q.createGroup(0,s),this.layer.add(this.trackGroup),this.initClips(),this.initEventListeners(),this.render()}initClips(){this.clips=this.config.clips.map(t=>{const e=new de(t,this.handleClipUpdate.bind(this),this.handleClipSplit.bind(this));return this.createClipGroup(t),e})}initEventListeners(){const t=this.layer.getStage();t&&(t.on("mousemove",e=>{this.handleStageMouseMove(e.evt)}),t.on("mouseup",()=>{this.handleClipMouseUp()}))}createClipGroup(t){const e=Q.timeToPixels(t.startTime,this.zoom)-this.scrollLeft,i=Q.timeToPixels(t.duration,this.zoom),s=2,n=this.trackHeight-4,r=Q.createClipGroup(e,s,i,n,t.name,t.duration,this.theme,!1,t.thumbnails,t.src);r.name(`clip-${t.id}`),r.on("click",()=>{this.handleClipClick(t.id)}),r.on("mousedown",o=>{this.handleClipMouseDown(t.id,o.evt)}),r.on("mousemove",()=>{this.handleClipMouseMove()}),r.on("mouseleave",()=>{this.handleClipMouseLeave()}),this.trackGroup.add(r),this.clipGroups.set(t.id,r)}handleClipClick(t){const e=this.clips.find(i=>i.getClip().id===t);e&&(this.clips.forEach(i=>{i.setSelected(!1),this.updateClipVisualState(i.getClip().id,!1)}),e.setSelected(!0),this.selectedClip=e,this.updateClipVisualState(e.getClip().id,!0),this.onClipSelect(e.getClip()),this.render())}handleClipMouseDown(t,e){var s;R.debug("VideoTrack","Mouse down on clip",{clipId:t,evt:e}),this.clips.sort((n,r)=>n.getClip().startTime-r.getClip().startTime),R.debug("VideoTrack","Clips sorted by start time",{clipCount:this.clips.length}),this.originalClipsState=this.clips.map(n=>({...n.getClip()})),R.debug("VideoTrack","Recorded original clips state",{clipCount:this.originalClipsState.length}),this.nonDraggedClips=this.clips.filter(n=>n.getClip().id!==t).map(n=>({...n.getClip()})),R.debug("VideoTrack","Recorded non-dragged clips",{clipCount:this.nonDraggedClips.length});const i=this.clips.find(n=>n.getClip().id===t);if(i){this.clips.forEach(c=>{c.setSelected(!1),this.updateClipVisualState(c.getClip().id,!1)}),i.setSelected(!0),this.selectedClip=i,R.debug("VideoTrack","Clip selected",{clipId:t,selectedClipId:(s=this.selectedClip)==null?void 0:s.getClip().id});const n=this.layer.getStage();if(!n){R.debug("VideoTrack","Stage not found",{clipId:t});return}const r=n.container();if(!r){R.debug("VideoTrack","Container not found",{clipId:t});return}const o=r.getBoundingClientRect(),h=e.clientX-o.left,l=e.clientY-o.top;R.debug("VideoTrack","Calculated mouse position",{clipId:t,x:h,y:l,clientX:e.clientX,clientY:e.clientY,rect:o}),i.isPointInResizeHandle(h,l,this.zoom,this.trackY,this.trackHeight,this.scrollLeft)?(i.startResize({x:h,y:l}),R.debug("VideoTrack","Started resize operation",{clipId:t,x:h,y:l})):(i.startDrag({x:h,y:l}),R.debug("VideoTrack","Started drag operation",{clipId:t,x:h,y:l})),this.updateClipVisualState(i.getClip().id,!0),this.render()}else R.debug("VideoTrack","Clip not found",{clipId:t})}handleClipMouseMove(){}handleClipMouseUp(){var t;if(R.debug("VideoTrack","Mouse up detected",{hasSelectedClip:!!this.selectedClip,selectedClipId:(t=this.selectedClip)==null?void 0:t.getClip().id}),this.selectedClip){const e=this.selectedClip.getClip();R.debug("VideoTrack","Processing release for clip",{clipId:e.id}),this.selectedClip.endDrag(),this.handleClipMoveEnd(e),this.selectedClip=null,R.debug("VideoTrack","Clip drag ended successfully"),this.layer.batchDraw()}else R.debug("VideoTrack","No selected clip to process")}handleClipMoveEnd(t){R.debug("VideoTrack","handleClipMoveEnd-拖拽结束",{startTime:t.startTime,clipId:t.id});const e=[...this.nonDraggedClips];R.debug("VideoTrack","Initial processed clips",{clipCount:e.length});let i=e.findIndex(s=>s.startTime>=t.startTime);i===-1&&(i=e.length),R.debug("VideoTrack","Calculated insert index",{insertIndex:i,draggedStartTime:t.startTime}),e.splice(i,0,{...t,opacity:1}),R.debug("VideoTrack","Drag clip inserted",{insertIndex:i,clipId:t.id,insertedStartTime:t.startTime}),this.adjustClipsForOverlap(e,i),this.updateAllClips(e),this.buildAndSendUpdates(t,e)}adjustClipsForOverlap(t,e){R.debug("VideoTrack","adjustClipsForOverlap-开始调整重叠",{startIndex:e,totalClips:t.length});for(let i=e;i<t.length;i++){if(i===0)continue;const s=t[i],n=t[i-1],r=n.startTime+n.duration;if(s.startTime<r&&(s.startTime=r,s.endTime=s.startTime+s.duration,R.debug("VideoTrack","adjustClipsForOverlap-调整片段位置",{clipId:s.id,oldStartTime:s.startTime-r+s.startTime,newStartTime:s.startTime})),i+1<t.length){const o=t[i+1],h=s.startTime+s.duration;if(h+s.duration<o.startTime){R.debug("VideoTrack","adjustClipsForOverlap-检测到无重叠区域,终止计算",{currentEndTime:h,nextClipStartTime:o.startTime});break}}}}updateAllClips(t){R.debug("VideoTrack","updateAllClips-开始批量更新",{clipCount:t.length}),this.isVisualUpdate=!0,t.forEach(e=>{this.clips.find(s=>s.getClip().id===e.id)&&this.handleClipUpdate(e)}),this.isVisualUpdate=!1,this.clips.sort((e,i)=>e.getClip().startTime-i.getClip().startTime),R.debug("VideoTrack","updateAllClips-更新完成并重新排序",{finalClipCount:this.clips.length})}buildAndSendUpdates(t,e){R.debug("VideoTrack","buildAndSendUpdates-开始构建更新数据",{draggedClipId:t.id});const i=this.originalClipsState.map(s=>{const n=e.find(r=>r.id===s.id);return n&&(s.startTime!==n.startTime||s.duration!==n.duration||s.opacity!==n.opacity)?{clipId:s.id,previousState:s,newState:n}:null}).filter(s=>s!==null);R.debug("VideoTrack","buildAndSendUpdates-构建完成",{updateCount:i.length}),i.length>0&&this.onClipUpdate(t,this.originalClipsState.find(s=>s.id===t.id),i)}handleStageMouseMove(t){const e=this.layer.getStage();if(!e)return;const i=e.container();if(!i)return;const s=i.getBoundingClientRect(),n=t.clientX-s.left,r=t.clientY-s.top;if(this.selectedClip){const o=this.clips.map(l=>l.getClip()).filter(l=>{var c;return l.id!==((c=this.selectedClip)==null?void 0:c.getClip().id)});if(this.selectedClip.drag({x:n,y:r},this.zoom,o,!0)){const l=this.selectedClip.getClip();this.updateClipGroup(l),this.layer.batchDraw()}}else{let o=!1;for(const h of this.clips){const l=h.getClip(),c=Q.timeToPixels(l.startTime,this.zoom)-this.scrollLeft,u=Q.timeToPixels(l.duration,this.zoom);if(n>=c&&n<=c+Q.RESIZE_AREA_WIDTH&&r>=this.trackY&&r<=this.trackY+this.trackHeight){i.style.cursor="ew-resize",o=!0;break}if(n>=c+u-Q.RESIZE_AREA_WIDTH&&n<=c+u&&r>=this.trackY&&r<=this.trackY+this.trackHeight){i.style.cursor="ew-resize",o=!0;break}if(n>c+Q.RESIZE_AREA_WIDTH&&n<c+u-Q.RESIZE_AREA_WIDTH&&r>=this.trackY&&r<=this.trackY+this.trackHeight){i.style.cursor="pointer",o=!0;break}}o||(i.style.cursor="default")}}handleClipMouseLeave(){if(!this.selectedClip){const t=this.layer.getStage();t&&t.container()&&(t.container().style.cursor="default")}}updateClipVisualState(t,e){const i=this.clips.find(s=>s.getClip().id===t);if(i){const s=i.getClip();this.isVisualUpdate=!0,this.handleClipUpdate({...s,isDragging:e,isResizing:e,zIndex:e?2:1,opacity:e?.7:1}),this.isVisualUpdate=!1}}updateClipGroup(t){var i;const e=this.clipGroups.get(t.id);if(e){const s=Q.timeToPixels(t.startTime,this.zoom)-this.scrollLeft,n=Q.timeToPixels(t.duration,this.zoom);e.x(s);const r=((i=this.selectedClip)==null?void 0:i.getClip().id)===t.id;(t.isDragging||r)&&e.moveToTop(),Q.updateClipGroup(e,n,this.trackHeight-4,t.name,t.duration,this.theme,r,t.thumbnails,t.src)}}handleClipUpdate(t){const e=this.clips.findIndex(i=>i.getClip().id===t.id);if(R.debug("VideoTrack","更新片段",{clipId:t.id,isDragging:t.isDragging,zIndex:t.zIndex}),e!==-1){const i=this.clips[e].getClip();this.clips[e]=new de(t,this.handleClipUpdate.bind(this),this.handleClipSplit.bind(this)),this.updateClipGroup(t);const s=this.clipGroups.get(t.id);s&&s.opacity(t.opacity),this.isVisualUpdate||this.onClipUpdate(t,i),this.layer.batchDraw()}}handleClipSplit(t,e){const i=e-t.startTime,s=t.duration-i,n=t.startTimeAtSource+i,r={...t,duration:i,endTime:e,endTimeAtSource:n},o={...t,id:`${t.id}_split_${Date.now()}`,startTime:e,duration:s,endTime:z.calculateEndTime(e,s),startTimeAtSource:n,endTimeAtSource:t.endTimeAtSource};this.removeClip(t.id),this.addClip(r),this.addClip(o),this.onClipSplit(r,o),this.layer.batchDraw()}addClip(t){const e=new de(t,this.handleClipUpdate.bind(this),this.handleClipSplit.bind(this));this.clips.push(e),this.createClipGroup(t),this.onClipAdd(t),this.layer.batchDraw()}removeClip(t){const e=this.clips.findIndex(i=>i.getClip().id===t);if(e!==-1){this.clips.splice(e,1);const i=this.clipGroups.get(t);i&&(i.remove(),this.clipGroups.delete(t)),this.onClipRemove(t),this.layer.batchDraw()}}updateClip(t,e){const i=this.clips.find(s=>s.getClip().id===t);if(i){const s={...i.getClip(),...e};this.handleClipUpdate(s)}}setZoom(t){this.zoom=t,this.clips.forEach(e=>{this.updateClipGroup(e.getClip())}),this.layer.batchDraw()}setCurrentTime(t){this.layer.batchDraw()}setScrollLeft(t){this.scrollLeft=t,this.clips.forEach(e=>{const i=e.getClip();this.updateClipGroup(i),this.updateClipVisibility(i)}),this.layer.batchDraw()}updateClipVisibility(t){const e=this.clipGroups.get(t.id);if(e){const i=Q.timeToPixels(t.startTime,this.zoom)-this.scrollLeft,s=Q.timeToPixels(t.duration,this.zoom),n=i+s>0&&i<this.layer.width();e.visible(n)}}setTrackY(t){this.trackY=t,this.trackGroup.y(t),this.layer.batchDraw()}render(){if(this.trackGroup.children.length===0){const t=Q.createRect(0,0,this.layer.width(),this.trackHeight,this.theme.trackBackground,this.theme.trackBorder,1);t.name("track-background"),this.trackGroup.add(t);const e=Q.createText(`Track ${this.config.id}`,10,20,14,"Arial",this.theme.timeText);e.name("track-name"),this.trackGroup.add(e)}else{const t=this.trackGroup.findOne(".track-background");t&&(t.width(this.layer.width()),t.fill(this.theme.trackBackground),t.stroke(this.theme.trackBorder));const e=this.trackGroup.findOne(".track-name");e&&e.fill(this.theme.timeText)}this.layer.batchDraw()}getClips(){return this.clips.map(t=>t.getClip())}getSelectedClip(){return this.selectedClip?this.selectedClip.getClip():null}selectClip(t){const e=this.clips.find(i=>i.getClip().id===t);e&&(this.clips.forEach(i=>{i.setSelected(!1),this.updateClipVisualState(i.getClip().id,!1)}),e.setSelected(!0),this.selectedClip=e,this.clips.forEach(i=>{this.updateClipGroup(i.getClip())}),this.onClipSelect(e.getClip()),this.layer.batchDraw())}splitSelectedClip(t){const e=this.clips.find(i=>{const s=i.getClip();return t>=s.startTime&&t<s.endTime});e&&e.split(t)}removeClipGaps(){R.debug("VideoTrack","Removing clip gaps");const t=this.clips.map(i=>i.getClip()).sort((i,s)=>i.startTime-s.startTime);if(t.length<=1)return;let e=t[0].startTime+t[0].duration;for(let i=1;i<t.length;i++){const s=t[i];if(e-s.startTime<0){const r=e,o=r+s.duration;this.handleClipUpdate({...s,startTime:r,endTime:o}),e=o}else e=s.startTime+s.duration}}getTrackGroup(){return this.trackGroup}getId(){return this.config.id||"default"}}class $i{constructor(t,e,i,s,n,r){A(this,"layer");A(this,"playheadGroup");A(this,"playheadLine");A(this,"playheadTriangle");A(this,"theme");A(this,"currentTime",0);A(this,"zoom",100);A(this,"scrollLeft",0);A(this,"onTimeChange");A(this,"isDragging",!1);this.layer=t,this.currentTime=e,this.zoom=i,this.theme=n,this.onTimeChange=r,this.playheadGroup=Q.createGroup(),this.layer.add(this.playheadGroup),this.playheadLine=Q.createLine([0,0,0,s],this.theme.playhead,1),this.playheadGroup.add(this.playheadLine),this.playheadTriangle=new V.RegularPolygon({x:0,y:5,sides:3,radius:10,fill:this.theme.playhead,rotation:180}),this.playheadGroup.add(this.playheadTriangle),this.initEventListeners(),this.render()}initEventListeners(){var t,e,i;this.playheadGroup.on("mousedown",()=>{this.isDragging=!0}),(t=this.layer.getStage())==null||t.on("mousemove",s=>{this.isDragging&&this.handleMouseMove(s.evt)}),(e=this.layer.getStage())==null||e.on("mouseup",()=>{this.isDragging=!1}),(i=this.layer.getStage())==null||i.on("mouseleave",()=>{this.isDragging=!1})}handleMouseMove(t){if(!this.isDragging)return;const e=this.layer.getStage();if(!e)return;const i=e.container();if(!i)return;const s=i.getBoundingClientRect(),n=t.clientX-s.left,r=z.pixelsToTime(n+this.scrollLeft,this.zoom);this.setTime(r)}setTime(t){this.currentTime=t,this.onTimeChange(t),this.render()}setZoom(t){this.zoom=t,this.render()}setScrollLeft(t){this.scrollLeft=t,this.render()}setHeight(t){this.playheadLine.points([0,0,0,t]),this.render()}render(){const t=z.timeToPixels(this.currentTime,this.zoom)-this.scrollLeft;this.playheadGroup.x(t),this.playheadGroup.visible(t>=0&&t<=this.layer.width()),this.layer.batchDraw()}getTime(){return this.currentTime}getPlayheadGroup(){return this.playheadGroup}}class Ki{constructor(t,e,i,s=100){A(this,"state");A(this,"maxHistorySize",100);A(this,"onActionUndo");A(this,"onActionRedo");A(this,"onHistoryChange");this.state={past:[],future:[]},this.maxHistorySize=s,this.onActionUndo=t,this.onActionRedo=e,this.onHistoryChange=i}addAction(t){this.state.past.length>=this.maxHistorySize&&this.state.past.shift(),this.state.past.push({...t,timestamp:Date.now()}),this.state.future=[],this.onHistoryChange&&this.onHistoryChange()}undo(){if(this.state.past.length===0)return!1;const t=this.state.past.pop();return this.state.future.push(t),this.onActionUndo(t),this.onHistoryChange&&this.onHistoryChange(),!0}redo(){if(this.state.future.length===0)return!1;const t=this.state.future.pop();return this.state.past.push(t),this.onActionRedo(t),this.onHistoryChange&&this.onHistoryChange(),!0}clear(){this.state.past=[],this.state.future=[],this.onHistoryChange&&this.onHistoryChange()}canUndo(){return this.state.past.length>0}canRedo(){return this.state.future.length>0}getState(){return{...this.state}}createAddClipAction(t){return{type:"add_clip",data:t,timestamp:Date.now()}}createRemoveClipAction(t){return{type:"remove_clip",data:t,timestamp:Date.now()}}createUpdateClipAction(t,e,i){return{type:"update_clip",data:{clipId:t,updates:e,previousState:i},timestamp:Date.now()}}createSplitClipAction(t,e,i){return{type:"split_clip",data:{originalClip:t,clip1:e,clip2:i},timestamp:Date.now()}}createMoveClipAction(t,e,i){return{type:"move_clip",data:{clipId:t,newStartTime:e,previousStartTime:i},timestamp:Date.now()}}createResizeClipAction(t,e,i,s,n){return{type:"resize_clip",data:{clipId:t,newDuration:e,newStartTime:i,previousDuration:s,previousStartTime:n},timestamp:Date.now()}}createSetTimeAction(t,e){return{type:"set_time",data:{newTime:t,previousTime:e},timestamp:Date.now()}}createRemoveGapsAction(t){return{type:"remove_gaps",data:{clipsBefore:t},timestamp:Date.now()}}createMultiClipUpdateAction(t){return{type:"multi_clip_update",data:{clipUpdates:t},timestamp:Date.now()}}}class xr{constructor(t={}){A(this,"timeline",null);A(this,"tracks",[]);A(this,"playhead",null);A(this,"history");A(this,"config");A(this,"eventListeners",new Map);A(this,"animationFrameId",null);A(this,"lastUpdateTime",0);A(this,"isInitialized",!1);A(this,"stage",null);A(this,"gridLayer",null);A(this,"trackLayer",null);A(this,"playheadLayer",null);A(this,"selectionLayer",null);A(this,"videoPreview",null);A(this,"isExecutingHistoryAction",!1);A(this,"lastTrackDuration",0);A(this,"thumbnailProvider",null);this.config={duration:t.duration||36e5,zoom:t.zoom||wt.MEDIUM,currentTime:t.currentTime||0,playState:t.playState||"paused",container:t.container,theme:t.theme,timeScaleHeight:t.timeScaleHeight,debug:t.debug,speed:t.speed||1,thumbnailProvider:t.thumbnailProvider},R.setDebugEnabled(!!this.config.debug),this.thumbnailProvider=t.thumbnailProvider||null,this.history=new Ki(this.handleActionUndo.bind(this),this.handleActionRedo.bind(this),()=>{this.emitEvent("history_change",{canUndo:this.history.canUndo(),canRedo:this.history.canRedo()})}),this.config.container&&this.init(this.config.container)}init(t){if(this.isInitialized){R.warn("TimelineManager","TimelineManager has already been initialized");return}this.stage=new V.Stage({container:t,width:t.clientWidth,height:t.clientHeight}),this.gridLayer=new V.Layer({name:"gridLayer"}),this.trackLayer=new V.Layer({name:"trackLayer"}),this.playheadLayer=new V.Layer({name:"playheadLayer"}),this.selectionLayer=new V.Layer({name:"selectionLayer"}),this.stage.add(this.gridLayer),this.stage.add(this.trackLayer),this.stage.add(this.playheadLayer),this.stage.add(this.selectionLayer),this.timeline=new ji(this.stage,this.gridLayer,this.config,this.handleTimeChange.bind(this),this.handleZoomChange.bind(this),this.handleScrollChange.bind(this)),this.playhead=new $i(this.playheadLayer,this.config.currentTime,this.config.zoom,t.clientHeight,this.config.theme||ue,this.handleTimeChange.bind(this));const e=this.config.timeScaleHeight||40,i=new qi(this.trackLayer,{id:"1",clips:[]},this.config.zoom,e,60,this.config.theme||ue,(s,n,r)=>this.handleClipUpdate(s,n,r),this.handleClipAdd.bind(this),this.handleClipRemove.bind(this),this.handleClipSplit.bind(this),this.handleClipSelect.bind(this));this.tracks.push(i),this.isInitialized=!0,this.stage&&this.stage.batchDraw()}play(){this.config.playState!=="playing"&&(this.config.playState="playing",this.lastUpdateTime=Date.now(),this.animate(),this.emitEvent("play_state_change",{playState:this.config.playState}))}pause(){this.config.playState!=="paused"&&(this.config.playState="paused",this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.emitEvent("play_state_change",{playState:this.config.playState}))}togglePlay(){this.config.playState==="playing"?this.pause():this.play()}animate(){if(this.config.playState==="paused")return;const t=Date.now(),e=t-this.lastUpdateTime;this.lastUpdateTime=t;const i=this.config.currentTime+e*this.config.speed;this.setCurrentTime(i),this.animationFrameId=requestAnimationFrame(this.animate.bind(this))}setCurrentTime(t){const e=Math.max(0,t);e!==this.config.currentTime&&(this.config.currentTime=e,this.timeline&&this.timeline.setCurrentTime(e),this.playhead&&this.playhead.setTime(e),this.tracks.forEach(i=>i.setCurrentTime(e)),this.emitEvent("time_change",{time:e}))}getCurrentTime(){return this.config.currentTime}setZoom(t){const e=Math.max(wt.MIN,Math.min(wt.MAX,t));e!==this.config.zoom&&(this.config.zoom=e,this.timeline&&this.timeline.setZoom(e),this.playhead&&this.playhead.setZoom(e),this.tracks.forEach(i=>i.setZoom(e)),this.emitEvent("zoom_change",{zoom:e}))}getZoom(){return this.config.zoom}setSpeed(t){const e=Math.max(.1,Math.min(10,t));e!==this.config.speed&&(this.config.speed=e,this.emitEvent("speed_change",{speed:e}))}getSpeed(){return this.config.speed||1}setThumbnailProvider(t){this.thumbnailProvider=t,this.config.thumbnailProvider=t,this.getClips().forEach(i=>{if(!i.thumbnails)try{const s=t.getThumbnails(i);Array.isArray(s)?this.updateClip(i.id,{thumbnails:s}):s instanceof Promise&&s.then(n=>{Array.isArray(n)&&this.updateClip(i.id,{thumbnails:n})}).catch(n=>{R.warn("TimelineManager","Failed to get thumbnail for existing clip:",{error:n,clipId:i.id})})}catch(s){R.warn("TimelineManager","Error getting thumbnail for existing clip:",{error:s,clipId:i.id})}})}async addClip(t){let e=t.startTime;if(e===void 0){const c=this.getClips();c.length>0?e=Math.max(...c.map(u=>u.endTime)):e=0}const i=t.startTimeAtSource||0,s=t.duration,n=t.endTimeAtSource||i+s;let r=t.sourceDuration;if(!r)try{r=await z.getVideoDuration(t.src),r<=0&&(r=n)}catch(c){R.error("TimelineManager","Failed to get video duration:",{error:c}),r=n}let o=t.thumbnails;const h=t.id||`clip_${t.name}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;if(!o&&this.thumbnailProvider){const c={id:h,externalId:t.externalId,src:t.src,name:t.name,startTime:e,duration:s,startTimeAtSource:i,endTimeAtSource:n,sourceDuration:r,endTime:e+s,isDragging:!1,isResizing:!1,isResizingLeft:!1,isResizingRight:!1,isSelected:!1,zIndex:1,opacity:1,thumbnails:void 0,style:t.style};try{const u=this.thumbnailProvider.getThumbnails(c);Array.isArray(u)?o=u:u instanceof Promise&&u.then(d=>{Array.isArray(d)&&(o=d,this.updateClip(h,{thumbnails:o}))}).catch(d=>{R.warn("TimelineManager","Failed to get thumbnail:",{error:d})})}catch(u){R.warn("TimelineManager","Error getting thumbnail:",{error:u})}}const l={id:h,externalId:t.externalId,src:t.src,name:t.name,startTime:e,duration:s,startTimeAtSource:i,endTimeAtSource:n,sourceDuration:r,endTime:e+s,isDragging:!1,isResizing:!1,isResizingLeft:!1,isResizingRight:!1,isSelected:!1,zIndex:1,opacity:1,thumbnails:o,style:t.style};if(R.debug("TimelineManager","添加的片段:",{clip:l}),this.tracks.length>0){if(this.tracks[0].addClip(l),!this.isExecutingHistoryAction){const c=this.history.createAddClipAction(l);this.history.addAction(c)}this.checkTrackDurationChange()}return l.id}removeClip(t){if(!this.isExecutingHistoryAction){const e=this.getClips().find(i=>i.id===t);if(e){const i=this.history.createRemoveClipAction(e);this.history.addAction(i)}}this.tracks.forEach(e=>e.removeClip(t)),this.checkTrackDurationChange()}updateClip(t,e){this.tracks.forEach(i=>i.updateClip(t,e)),this.checkTrackDurationChange()}splitClip(t,e){const i=this.tracks.find(s=>s.getClips().some(n=>n.id===t));i&&(i.splitSelectedClip(e),this.checkTrackDurationChange())}splitCurrentClip(){const t=this.getCurrentTime(),e=this.tracks.find(i=>i.getClips().some(n=>t>=n.startTime&&t<n.endTime));e&&e.getClips().find(n=>t>=n.startTime&&t<n.endTime)&&(e.splitSelectedClip(t),this.checkTrackDurationChange())}getClips(){return this.tracks.flatMap(t=>t.getClips())}exportTimeline(){const t=this.tracks.map(e=>({id:e.getId(),clips:e.getClips().map(i=>({id:i.id,externalId:i.externalId,src:i.src,name:i.name,startTime:Math.round(i.startTime),duration:Math.round(i.duration),endTime:Math.round(i.endTime),startTimeAtSource:Math.round(i.startTimeAtSource),endTimeAtSource:Math.round(i.endTimeAtSource),sourceDuration:Math.round(i.sourceDuration),thumbnails:i.thumbnails})).sort((i,s)=>i.startTime-s.startTime)}));return{version:"1.0.0",exportTime:Date.now(),tracks:t}}getClipsData(){return this.getClips()}undo(){return this.history.undo()}redo(){return this.history.redo()}getHistoryState(){return this.history.getState()}fitZoom(){var o;const t=this.getClips();if(t.length===0)return;const e=Math.min(...t.map(h=>h.startTime)),s=(Math.max(...t.map(h=>h.endTime))-e)/1e3,n=((o=this.stage)==null?void 0:o.width())||0;R.debug("TimelineManager","适合缩放:",{duration:s,containerWidth:n});const r=Math.min(n/s,wt.MAX);this.setZoom(r)}removeClipGaps(){const t=this.getClips().map(e=>({...e}));if(this.tracks.forEach(e=>e.removeClipGaps()),t.length>0){const e=this.history.createRemoveGapsAction(t);this.history.addAction(e)}this.checkTrackDurationChange()}handleTimeChange(t){this.setCurrentTime(t)}handleZoomChange(t){this.setZoom(t)}handleScrollChange(t){this.playhead&&this.playhead.setScrollLeft(t),this.tracks.forEach(e=>e.setScrollLeft(t))}handleClipUpdate(t,e,i){if(!this.isExecutingHistoryAction){if(i&&i.length>0){const s=this.history.createMultiClipUpdateAction(i);this.history.addAction(s)}else if(e){const s=e.startTime!==t.startTime&&e.duration===t.duration,n=e.duration!==t.duration;if(s){const r=this.history.createMoveClipAction(t.id,t.startTime,e.startTime);this.history.addAction(r)}else if(n){const r=this.history.createResizeClipAction(t.id,t.duration,t.startTime,e.duration,e.startTime);this.history.addAction(r)}}}this.emitEvent("clip_updated",{clip:t}),this.checkTrackDurationChange()}handleClipAdd(t){this.emitEvent("clip_added",{clip:t})}handleClipRemove(t){this.emitEvent("clip_removed",{clipId:t})}handleClipSplit(t,e){const i={...t,id:t.id.replace("_split_",""),duration:t.duration+e.duration,endTime:e.endTime,endTimeAtSource:e.endTimeAtSource},s=this.history.createSplitClipAction(i,t,e);this.history.addAction(s),this.emitEvent("clip_updated",{clip:t}),this.emitEvent("clip_added",{clip:e})}handleClipSelect(t){this.emitEvent("clip_selected",{clip:t})}handleActionUndo(t){switch(R.debug("TimelineManager","Undo action:",{action:t}),this.isExecutingHistoryAction=!0,t.type){case"add_clip":this.removeClip(t.data.id);break;case"remove_clip":this.tracks[0].addClip(t.data);break;case"update_clip":this.updateClip(t.data.clipId,t.data.previousState);break;case"split_clip":this.removeClip(t.data.clip1.id),this.removeClip(t.data.clip2.id),this.tracks[0].addClip(t.data.originalClip);break;case"move_clip":this.updateClip(t.data.clipId,{startTime:t.data.previousStartTime});break;case"resize_clip":this.updateClip(t.data.clipId,{duration:t.data.previousDuration,startTime:t.data.previousStartTime});break;case"remove_gaps":this.getClips().forEach(e=>this.removeClip(e.id)),t.data.clipsBefore.forEach(e=>{this.tracks[0].addClip(e)});break;case"multi_clip_update":t.data.clipUpdates.forEach(e=>{this.updateClip(e.clipId,e.previousState)});break;default:R.warn("TimelineManager","Unknown action type for undo:",{type:t.type})}this.isExecutingHistoryAction=!1,this.checkTrackDurationChange()}handleActionRedo(t){switch(R.debug("TimelineManager","Redo action:",{action:t}),this.isExecutingHistoryAction=!0,t.type){case"add_clip":this.tracks[0].addClip(t.data);break;case"remove_clip":this.removeClip(t.data.id);break;case"update_clip":this.updateClip(t.data.clipId,t.data.updates);break;case"split_clip":this.removeClip(t.data.originalClip.id),this.tracks[0].addClip(t.data.clip1),this.tracks[0].addClip(t.data.clip2);break;case"move_clip":this.updateClip(t.data.clipId,{startTime:t.data.newStartTime});break;case"resize_clip":this.updateClip(t.data.clipId,{duration:t.data.newDuration,startTime:t.data.newStartTime});break;case"remove_gaps":this.removeClipGaps();break;case"multi_clip_update":t.data.clipUpdates.forEach(e=>{this.updateClip(e.clipId,e.newState)});break;default:R.warn("TimelineManager","Unknown action type for redo:",{type:t.type})}this.isExecutingHistoryAction=!1,this.checkTrackDurationChange()}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}off(t,e){if(this.eventListeners.has(t)){const i=this.eventListeners.get(t).filter(s=>s!==e);this.eventListeners.set(t,i)}}emitEvent(t,e){this.eventListeners.has(t)&&this.eventListeners.get(t).forEach(i=>{try{i(t,e)}catch(s){R.error("TimelineManager",`Error in event listener for ${t}:`,{error:s})}})}getPlayState(){return this.config.playState}setDuration(t){this.config.duration=t,this.timeline&&this.timeline.setDuration(t)}getDuration(){return this.config.duration}scrollToTime(t,e=!1){this.timeline&&(this.timeline.scrollToTime(t),e&&this.setCurrentTime(t))}selectClip(t){const e=this.tracks.find(i=>i.getClips().some(s=>s.id===t));e&&e.selectClip(t)}scrollToClip(t,e={}){const{selectClip:i=!1,setCurrentTime:s=!1}=e,n=this.getClips().find(r=>r.id===t);!n||!this.timeline||(this.timeline.scrollToClip(n),s&&this.setCurrentTime(n.startTime),i&&this.selectClip(t))}getSelectedClip(){for(const t of this.tracks){const e=t.getSelectedClip();if(e)return e}return null}getCurrentClip(){return this.findClipAtTime(this.config.currentTime)}removeSelectedClip(){const t=this.getSelectedClip();return t?(this.removeClip(t.id),!0):!1}getTrackTotalDuration(){const t=this.getClips();if(t.length===0)return 0;const e=t.reduce((i,s)=>{const n=s.startTime+s.duration,r=i.startTime+i.duration;return n>r?s:i});return e.startTime+e.duration}destroy(){this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),this.videoPreview&&this.disconnectVideo(),this.eventListeners.clear()}connectTo(t){let e;t instanceof HTMLVideoElement?e={videoElement:t,autoPlay:!1,volume:1}:e=t,this.videoPreview&&this.disconnectVideo(),this.videoPreview={videoElement:e.videoElement,currentClip:null,isPlaying:!1,lastUpdateTime:Date.now()},e.volume!==void 0&&(this.videoPreview.videoElement.volume=Math.max(0,Math.min(1,e.volume))),e.autoPlay&&this.videoPreview.videoElement.play().catch(i=>{R.warn("TimelineManager","Auto-play was prevented:",{err:i})}),this.on("time_change",this.handleVideoTimeUpdate.bind(this)),this.on("play_state_change",this.handlePlayStateChange.bind(this)),this.on("clip_added",this.handleClipChange.bind(this)),this.on("clip_removed",this.handleClipChange.bind(this)),R.debug("TimelineManager","TimelineManager connected to video element")}disconnectVideo(){this.videoPreview&&(this.off("time_change",this.handleVideoTimeUpdate.bind(this)),this.off("play_state_change",this.handlePlayStateChange.bind(this)),this.off("clip_added",this.handleClipChange.bind(this)),this.off("clip_removed",this.handleClipChange.bind(this)),this.videoPreview=null,R.debug("TimelineManager","TimelineManager disconnected from video element"))}clearHistory(){this.history.clear()}handleVideoTimeUpdate(t,e){if(!this.videoPreview)return;const i=this.videoPreview.videoElement,s=e.time;i.playbackRate=this.config.speed||1;const n=this.findClipAtTime(s);if(!this.videoPreview.currentClip||this.videoPreview.currentClip.id!==(n==null?void 0:n.id)?n?this.loadClipToVideo(n):(i.paused||i.pause(),i.src&&(i.src=""),this.videoPreview.currentClip=null):n&&this.config.playState==="playing"&&i.paused&&i.play().catch(r=>{R.warn("TimelineManager","Video play was prevented:",{err:r})}),n){const r=s-n.startTime,o=n.startTimeAtSource+r,h=this.config.speed||1,l=Math.max(100,h*150);Math.abs(i.currentTime*1e3-o)>l&&(i.currentTime=o/1e3,this.config.playState==="playing"&&i.paused&&setTimeout(()=>{this.config.playState==="playing"&&i.paused&&i.play().catch(c=>{R.warn("TimelineManager","Video play was prevented:",{err:c})})},50))}}handlePlayStateChange(t,e){if(!this.videoPreview)return;const i=this.videoPreview.videoElement;e.playState==="playing"?i.paused&&i.play().catch(s=>{R.warn("TimelineManager","Video play was prevented:",{err:s})}):i.paused||i.pause()}handleClipChange(){if(this.videoPreview&&this.videoPreview.currentClip){const t=this.findClipAtTime(this.config.currentTime);(!t||t.id!==this.videoPreview.currentClip.id)&&(this.videoPreview.currentClip=null)}}findClipAtTime(t){return this.getClips().find(i=>t>=i.startTime&&t<i.startTime+i.duration)||null}loadClipToVideo(t){if(!this.videoPreview)return;const e=this.videoPreview.videoElement;if(e.src===t.src){e.currentTime=t.startTimeAtSource/1e3,this.videoPreview.currentClip=t,this.config.playState==="playing"&&e.paused&&e.play().catch(s=>{R.warn("TimelineManager","Video play was prevented:",{err:s})});return}const i=this.config.playState==="playing";e.pause(),e.src=t.src,e.load(),e.currentTime=t.startTimeAtSource/1e3,this.videoPreview.currentClip=t,i&&e.play().catch(s=>{R.warn("TimelineManager","Video play was prevented:",{err:s})}),R.debug("TimelineManager",`Loaded clip: ${t.name}, src: ${t.src}, start: ${t.startTimeAtSource}ms`)}checkTrackDurationChange(){const t=this.getTrackTotalDuration();t!==this.lastTrackDuration&&(this.lastTrackDuration=t,this.emitEvent("track_duration_change",{duration:t}),R.debug("TimelineManager",`Track duration changed: ${t}ms`))}}exports.Clip=de;exports.HistoryManager=Ki;exports.Playhead=$i;exports.TimeUtils=z;exports.Timeline=ji;exports.TimelineManager=xr;exports.VideoTrack=qi;exports.defaultDarkTheme=ue;
|
|
14
|
+
`,Ue=()=>{if(typeof document>"u")throw new Error(is)};class rt{constructor(t=[1,0,0,1,0,0]){this.dirty=!1,this.m=t&&t.slice()||[1,0,0,1,0,0]}reset(){this.m[0]=1,this.m[1]=0,this.m[2]=0,this.m[3]=1,this.m[4]=0,this.m[5]=0}copy(){return new rt(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){const e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.m[0]*e+this.m[2]*i,n=this.m[1]*e+this.m[3]*i,r=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=s,this.m[1]=n,this.m[2]=r,this.m[3]=o,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){const i=this.m[0]+this.m[2]*e,s=this.m[1]+this.m[3]*e,n=this.m[2]+this.m[0]*t,r=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=n,this.m[3]=r,this}multiply(t){const e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],s=this.m[0]*t.m[2]+this.m[2]*t.m[3],n=this.m[1]*t.m[2]+this.m[3]*t.m[3],r=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],o=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=n,this.m[4]=r,this.m[5]=o,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,s=-this.m[2]*t,n=this.m[0]*t,r=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),o=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=n,this.m[4]=r,this.m[5]=o,this}getMatrix(){return this.m}decompose(){const t=this.m[0],e=this.m[1],i=this.m[2],s=this.m[3],n=this.m[4],r=this.m[5],o=t*s-e*i,h={x:n,y:r,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(t!=0||e!=0){const l=Math.sqrt(t*t+e*e);h.rotation=e>0?Math.acos(t/l):-Math.acos(t/l),h.scaleX=l,h.scaleY=o/l,h.skewX=(t*i+e*s)/o,h.skewY=0}else if(i!=0||s!=0){const l=Math.sqrt(i*i+s*s);h.rotation=Math.PI/2-(s>0?Math.acos(-i/l):-Math.acos(i/l)),h.scaleX=o/l,h.scaleY=l,h.skewX=0,h.skewY=(t*i+e*s)/o}return h.rotation=y._getRotation(h.rotation),h}}const ss="[object Array]",ns="[object Number]",rs="[object String]",as="[object Boolean]",os=Math.PI/180,hs=180/Math.PI,Ft="#",ls="",cs="0",ds="Konva warning: ",Xe="Konva error: ",us="rgb(",ye={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],transparent:[255,255,255,0],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]},fs=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let te=[],Bt=null;const gs=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(a){setTimeout(a,16)},y={_isElement(a){return!!(a&&a.nodeType==1)},_isFunction(a){return!!(a&&a.constructor&&a.call&&a.apply)},_isPlainObject(a){return!!a&&a.constructor===Object},_isArray(a){return Object.prototype.toString.call(a)===ss},_isNumber(a){return Object.prototype.toString.call(a)===ns&&!isNaN(a)&&isFinite(a)},_isString(a){return Object.prototype.toString.call(a)===rs},_isBoolean(a){return Object.prototype.toString.call(a)===as},isObject(a){return a instanceof Object},isValidSelector(a){if(typeof a!="string")return!1;const t=a[0];return t==="#"||t==="."||t===t.toUpperCase()},_sign(a){return a===0||a>0?1:-1},requestAnimFrame(a){te.push(a),te.length===1&&gs(function(){const t=te;te=[],t.forEach(function(e){e()})})},createCanvasElement(){Ue();const a=document.createElement("canvas");try{a.style=a.style||{}}catch{}return a},createImageElement(){return Ue(),document.createElement("img")},_isInDocument(a){for(;a=a.parentNode;)if(a==document)return!0;return!1},_urlToImage(a,t){const e=y.createImageElement();e.onload=function(){t(e)},e.src=a},_rgbToHex(a,t,e){return((1<<24)+(a<<16)+(t<<8)+e).toString(16).slice(1)},_hexToRgb(a){a=a.replace(Ft,ls);const t=parseInt(a,16);return{r:t>>16&255,g:t>>8&255,b:t&255}},getRandomColor(){let a=(Math.random()*16777215<<0).toString(16);for(;a.length<6;)a=cs+a;return Ft+a},isCanvasFarblingActive(){if(Bt!==null)return Bt;if(typeof document>"u")return Bt=!1,!1;const a=this.createCanvasElement();a.width=10,a.height=10;const t=a.getContext("2d",{willReadFrequently:!0});t.clearRect(0,0,10,10),t.fillStyle="#282828",t.fillRect(0,0,10,10);const e=t.getImageData(0,0,10,10).data;let i=!1;for(let s=0;s<100;s++)if(e[s*4]!==40||e[s*4+1]!==40||e[s*4+2]!==40||e[s*4+3]!==255){i=!0;break}return Bt=i,this.releaseCanvas(a),Bt},getHitColor(){const a=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(a):a},getHitColorKey(a,t,e){return this.isCanvasFarblingActive()&&(a=Math.round(a/5)*5,t=Math.round(t/5)*5,e=Math.round(e/5)*5),Ft+this._rgbToHex(a,t,e)},getSnappedHexColor(a){const t=this._hexToRgb(a);return Ft+this._rgbToHex(Math.round(t.r/5)*5,Math.round(t.g/5)*5,Math.round(t.b/5)*5)},getRGB(a){let t;return a in ye?(t=ye[a],{r:t[0],g:t[1],b:t[2]}):a[0]===Ft?this._hexToRgb(a.substring(1)):a.substr(0,4)===us?(t=fs.exec(a.replace(/ /g,"")),{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}):{r:0,g:0,b:0}},colorToRGBA(a){return a=a||"black",y._namedColorToRBA(a)||y._hex3ColorToRGBA(a)||y._hex4ColorToRGBA(a)||y._hex6ColorToRGBA(a)||y._hex8ColorToRGBA(a)||y._rgbColorToRGBA(a)||y._rgbaColorToRGBA(a)||y._hslColorToRGBA(a)},_namedColorToRBA(a){const t=ye[a.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(a){if(a.indexOf("rgb(")===0){a=a.match(/rgb\(([^)]+)\)/)[1];const t=a.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(a){if(a.indexOf("rgba(")===0){a=a.match(/rgba\(([^)]+)\)/)[1];const t=a.split(/ *, */).map((e,i)=>e.slice(-1)==="%"?i===3?parseInt(e)/100:parseInt(e)/100*255:Number(e));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(a){if(a[0]==="#"&&a.length===9)return{r:parseInt(a.slice(1,3),16),g:parseInt(a.slice(3,5),16),b:parseInt(a.slice(5,7),16),a:parseInt(a.slice(7,9),16)/255}},_hex6ColorToRGBA(a){if(a[0]==="#"&&a.length===7)return{r:parseInt(a.slice(1,3),16),g:parseInt(a.slice(3,5),16),b:parseInt(a.slice(5,7),16),a:1}},_hex4ColorToRGBA(a){if(a[0]==="#"&&a.length===5)return{r:parseInt(a[1]+a[1],16),g:parseInt(a[2]+a[2],16),b:parseInt(a[3]+a[3],16),a:parseInt(a[4]+a[4],16)/255}},_hex3ColorToRGBA(a){if(a[0]==="#"&&a.length===4)return{r:parseInt(a[1]+a[1],16),g:parseInt(a[2]+a[2],16),b:parseInt(a[3]+a[3],16),a:1}},_hslColorToRGBA(a){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(a)){const[t,...e]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(a),i=Number(e[0])/360,s=Number(e[1])/100,n=Number(e[2])/100;let r,o,h;if(s===0)return h=n*255,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};n<.5?r=n*(1+s):r=n+s-n*s;const l=2*n-r,c=[0,0,0];for(let u=0;u<3;u++)o=i+1/3*-(u-1),o<0&&o++,o>1&&o--,6*o<1?h=l+(r-l)*6*o:2*o<1?h=r:3*o<2?h=l+(r-l)*(2/3-o)*6:h=l,c[u]=h*255;return{r:Math.round(c[0]),g:Math.round(c[1]),b:Math.round(c[2]),a:1}}},haveIntersection(a,t){return!(t.x>a.x+a.width||t.x+t.width<a.x||t.y>a.y+a.height||t.y+t.height<a.y)},cloneObject(a){const t={};for(const e in a)this._isPlainObject(a[e])?t[e]=this.cloneObject(a[e]):this._isArray(a[e])?t[e]=this.cloneArray(a[e]):t[e]=a[e];return t},cloneArray(a){return a.slice(0)},degToRad(a){return a*os},radToDeg(a){return a*hs},_degToRad(a){return y.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),y.degToRad(a)},_radToDeg(a){return y.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),y.radToDeg(a)},_getRotation(a){return E.angleDeg?y.radToDeg(a):a},_capitalize(a){return a.charAt(0).toUpperCase()+a.slice(1)},throw(a){throw new Error(Xe+a)},error(a){console.error(Xe+a)},warn(a){E.showWarnings&&console.warn(ds+a)},each(a,t){for(const e in a)t(e,a[e])},_inRange(a,t,e){return t<=a&&a<e},_getProjectionToSegment(a,t,e,i,s,n){let r,o,h;const l=(a-e)*(a-e)+(t-i)*(t-i);if(l==0)r=a,o=t,h=(s-e)*(s-e)+(n-i)*(n-i);else{const c=((s-a)*(e-a)+(n-t)*(i-t))/l;c<0?(r=a,o=t,h=(a-s)*(a-s)+(t-n)*(t-n)):c>1?(r=e,o=i,h=(e-s)*(e-s)+(i-n)*(i-n)):(r=a+c*(e-a),o=t+c*(i-t),h=(r-s)*(r-s)+(o-n)*(o-n))}return[r,o,h]},_getProjectionToLine(a,t,e){const i=y.cloneObject(a);let s=Number.MAX_VALUE;return t.forEach(function(n,r){if(!e&&r===t.length-1)return;const o=t[(r+1)%t.length],h=y._getProjectionToSegment(n.x,n.y,o.x,o.y,a.x,a.y),l=h[0],c=h[1],u=h[2];u<s&&(i.x=l,i.y=c,s=u)}),i},_prepareArrayForTween(a,t,e){const i=[],s=[];if(a.length>t.length){const r=t;t=a,a=r}for(let r=0;r<a.length;r+=2)i.push({x:a[r],y:a[r+1]});for(let r=0;r<t.length;r+=2)s.push({x:t[r],y:t[r+1]});const n=[];return s.forEach(function(r){const o=y._getProjectionToLine(r,i,e);n.push(o.x),n.push(o.y)}),n},_prepareToStringify(a){let t;a.visitedByCircularReferenceRemoval=!0;for(const e in a)if(a.hasOwnProperty(e)&&a[e]&&typeof a[e]=="object"){if(t=Object.getOwnPropertyDescriptor(a,e),a[e].visitedByCircularReferenceRemoval||y._isElement(a[e]))if(t.configurable)delete a[e];else return null;else if(y._prepareToStringify(a[e])===null)if(t.configurable)delete a[e];else return null}return delete a.visitedByCircularReferenceRemoval,a},_assign(a,t){for(const e in t)a[e]=t[e];return a},_getFirstPointerId(a){return a.touches?a.changedTouches[0].identifier:a.pointerId||999},releaseCanvas(...a){E.releaseCanvasOnDestroy&&a.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(a,t,e,i){let s=t<0?t:0,n=e<0?e:0;t=Math.abs(t),e=Math.abs(e);let r=0,o=0,h=0,l=0;typeof i=="number"?r=o=h=l=Math.min(i,t/2,e/2):(r=Math.min(i[0]||0,t/2,e/2),o=Math.min(i[1]||0,t/2,e/2),l=Math.min(i[2]||0,t/2,e/2),h=Math.min(i[3]||0,t/2,e/2)),a.moveTo(s+r,n),a.lineTo(s+t-o,n),a.arc(s+t-o,n+o,o,Math.PI*3/2,0,!1),a.lineTo(s+t,n+e-l),a.arc(s+t-l,n+e-l,l,0,Math.PI/2,!1),a.lineTo(s+h,n+e),a.arc(s+h,n+e-h,h,Math.PI/2,Math.PI,!1),a.lineTo(s,n+r),a.arc(s+r,n+r,r,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(a,t,e,i,s){i=Math.abs(i);for(let n=0;n<e;n++){const r=t[(n-1+e)%e],o=t[n],h=t[(n+1)%e],l={x:o.x-r.x,y:o.y-r.y},c={x:h.x-o.x,y:h.y-o.y},u=Math.hypot(l.x,l.y),d=Math.hypot(c.x,c.y);let p;typeof s=="number"?p=s:p=n<s.length?s[n]:0,p=i*Math.cos(Math.PI/e)*Math.min(1,p/i*2);const m={x:l.x/u,y:l.y/u},_={x:c.x/d,y:c.y/d},C={x:o.x-m.x*p,y:o.y-m.y*p},S={x:o.x+_.x*p,y:o.y+_.y*p};n===0?a.moveTo(C.x,C.y):a.lineTo(C.x,C.y),a.arcTo(o.x,o.y,S.x,S.y,p)}}};function ps(a){const t=[],e=a.length,i=y;for(let s=0;s<e;s++){let n=a[s];i._isNumber(n)?n=Math.round(n*1e3)/1e3:i._isString(n)||(n=n+""),t.push(n)}return t}const Ye=",",ms="(",_s=")",ys="([",Cs="])",Ss=";",bs="()",vs="=",Ve=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","roundRect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"],Ts=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],ws=100;let ee=null;function je(){if(ee!==null)return ee;try{const t=y.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(ee=!1,!1)}catch{return ee=!1,!1}}class pe{constructor(t){this.canvas=t,E.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i=this.traceArr,s=i.length,n="",r,o,h,l;for(r=0;r<s;r++)o=i[r],h=o.method,h?(l=o.args,n+=h,t?n+=bs:y._isArray(l[0])?n+=ys+l.join(Ye)+Cs:(e&&(l=l.map(c=>typeof c=="number"?Math.floor(c):c)),n+=ms+l.join(Ye)+_s)):(n+=o.property,t||(n+=vs+o.val)),n+=Ss;return n}clearTrace(){this.traceArr=[]}_trace(t){let e=this.traceArr,i;e.push(t),i=e.length,i>=ws&&e.shift()}reset(){const t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){const e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){const e=t.getAbsoluteOpacity();e!==1&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){const e=t.attrs.miterLimit;e!=null&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,n,r){this._context.arc(t,e,i,s,n,r)}arcTo(t,e,i,s,n){this._context.arcTo(t,e,i,s,n)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,n,r){this._context.bezierCurveTo(t,e,i,s,n,r)}clearRect(t,e,i,s){this._context.clearRect(t,e,i,s)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){const i=arguments;if(i.length===2)return this._context.createImageData(t,e);if(i.length===1)return this._context.createImageData(t)}createLinearGradient(t,e,i,s){return this._context.createLinearGradient(t,e,i,s)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,s,n,r){return this._context.createRadialGradient(t,e,i,s,n,r)}drawImage(t,e,i,s,n,r,o,h,l){const c=arguments,u=this._context;c.length===3?u.drawImage(t,e,i):c.length===5?u.drawImage(t,e,i,s,n):c.length===9&&u.drawImage(t,e,i,s,n,r,o,h,l)}ellipse(t,e,i,s,n,r,o,h){this._context.ellipse(t,e,i,s,n,r,o,h)}isPointInPath(t,e,i,s){return i?this._context.isPointInPath(i,t,e,s):this._context.isPointInPath(t,e,s)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,s){this._context.fillRect(t,e,i,s)}strokeRect(t,e,i,s){this._context.strokeRect(t,e,i,s)}fillText(t,e,i,s){s?this._context.fillText(t,e,i,s):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,s){return this._context.getImageData(t,e,i,s)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,s){this._context.rect(t,e,i,s)}roundRect(t,e,i,s,n){this._context.roundRect(t,e,i,s,n)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,s){this._context.quadraticCurveTo(t,e,i,s)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,s,n,r){this._context.setTransform(t,e,i,s,n,r)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,s){this._context.strokeText(t,e,i,s)}transform(t,e,i,s,n,r){this._context.transform(t,e,i,s,n,r)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t=this,e=Ve.length,i=this.setAttr,s,n;const r=function(o){let h=t[o],l;t[o]=function(){return n=ps(Array.prototype.slice.call(arguments,0)),l=h.apply(t,arguments),t._trace({method:o,args:n}),l}};for(s=0;s<e;s++)r(Ve[s]);t.setAttr=function(){i.apply(t,arguments);const o=arguments[0];let h=arguments[1];(o==="shadowOffsetX"||o==="shadowOffsetY"||o==="shadowBlur")&&(h=h/this.canvas.getPixelRatio()),t._trace({property:o,val:h})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||e==="source-over"||this.setAttr("globalCompositeOperation",e)}}Ts.forEach(function(a){Object.defineProperty(pe.prototype,a,{get(){return this._context[a]},set(t){this._context[a]=t}})});class xs extends pe{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){const e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){const e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){const e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){const e=t.fill(),i=t.getFillPriority();if(e&&i==="color"){this._fillColor(t);return}const s=t.getFillPatternImage();if(s&&i==="pattern"){this._fillPattern(t);return}const n=t.getFillLinearGradientColorStops();if(n&&i==="linear-gradient"){this._fillLinearGradient(t);return}const r=t.getFillRadialGradientColorStops();if(r&&i==="radial-gradient"){this._fillRadialGradient(t);return}e?this._fillColor(t):s?this._fillPattern(t):n?this._fillLinearGradient(t):r&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),n=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let r=0;r<s.length;r+=2)n.addColorStop(s[r],s[r+1]);this.setAttr("strokeStyle",n)}}_stroke(t){const e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();const n=this.getCanvas().getPixelRatio();this.setTransform(n,0,0,n,0,0)}this._applyLineCap(t),e&&t.dashEnabled()&&(this.setLineDash(e),this.setAttr("lineDashOffset",t.dashOffset())),this.setAttr("lineWidth",t.strokeWidth()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),t.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(t):this.setAttr("strokeStyle",t.stroke()),t._strokeFunc(this),i||this.restore()}}_applyShadow(t){var e,i,s;const n=(e=t.getShadowRGBA())!==null&&e!==void 0?e:"black",r=(i=t.getShadowBlur())!==null&&i!==void 0?i:5,o=(s=t.getShadowOffset())!==null&&s!==void 0?s:{x:0,y:0},h=t.getAbsoluteScale(),l=this.canvas.getPixelRatio(),c=h.x*l,u=h.y*l;this.setAttr("shadowColor",n),this.setAttr("shadowBlur",r*Math.min(Math.abs(c),Math.abs(u))),this.setAttr("shadowOffsetX",o.x*c),this.setAttr("shadowOffsetY",o.y*u)}}class ks extends pe{constructor(t){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:!0})}_fill(t){this.save(),this.setAttr("fillStyle",t.colorKey),t._fillFuncHit(this),this.restore()}strokeShape(t){t.hasHitStroke()&&this._stroke(t)}_stroke(t){if(t.hasHitStroke()){const e=t.getStrokeScaleEnabled();if(!e){this.save();const n=this.getCanvas().getPixelRatio();this.setTransform(n,0,0,n,0,0)}this._applyLineCap(t);const i=t.hitStrokeWidth(),s=i==="auto"?t.strokeWidth():i;this.setAttr("lineWidth",s),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}}let ie;function As(){if(ie)return ie;const a=y.createCanvasElement(),t=a.getContext("2d");return ie=function(){const e=E._global.devicePixelRatio||1,i=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/i}(),y.releaseCanvas(a),ie}class Fe{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const i=(t||{}).pixelRatio||E.pixelRatio||As();this.pixelRatio=i,this._canvas=y.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(t){const e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)}setWidth(t){this.width=this._canvas.width=t*this.pixelRatio,this._canvas.style.width=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}setHeight(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch{try{return this._canvas.toDataURL()}catch(s){return y.error("Unable to get data URL. "+s.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class Ct extends Fe{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new xs(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}class Be extends Fe{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new ks(this),this.setSize(t.width,t.height)}}const U={get isDragging(){let a=!1;return U._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(a=!0)}),a},justDragged:!1,get node(){let a;return U._dragElements.forEach(t=>{a=t.node}),a},_dragElements:new Map,_drag(a){const t=[];U._dragElements.forEach((e,i)=>{const{node:s}=e,n=s.getStage();n.setPointersPositions(a),e.pointerId===void 0&&(e.pointerId=y._getFirstPointerId(a));const r=n._changedPointerPositions.find(o=>o.id===e.pointerId);if(r){if(e.dragStatus!=="dragging"){const o=s.dragDistance();if(Math.max(Math.abs(r.x-e.startPointerPos.x),Math.abs(r.y-e.startPointerPos.y))<o||(s.startDrag({evt:a}),!s.isDragging()))return}s._setDragPosition(a,e),t.push(s)}}),t.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:a},!0)})},_endDragBefore(a){const t=[];U._dragElements.forEach(e=>{const{node:i}=e,s=i.getStage();if(a&&s.setPointersPositions(a),!s._changedPointerPositions.find(o=>o.id===e.pointerId))return;(e.dragStatus==="dragging"||e.dragStatus==="stopped")&&(U.justDragged=!0,E._mouseListenClick=!1,E._touchListenClick=!1,E._pointerListenClick=!1,e.dragStatus="stopped");const r=e.node.getLayer()||e.node instanceof E.Stage&&e.node;r&&t.indexOf(r)===-1&&t.push(r)}),t.forEach(e=>{e.draw()})},_endDragAfter(a){U._dragElements.forEach((t,e)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:a},!0),t.dragStatus!=="dragging"&&U._dragElements.delete(e)})}};E.isBrowser&&(window.addEventListener("mouseup",U._endDragBefore,!0),window.addEventListener("touchend",U._endDragBefore,!0),window.addEventListener("touchcancel",U._endDragBefore,!0),window.addEventListener("mousemove",U._drag),window.addEventListener("touchmove",U._drag),window.addEventListener("mouseup",U._endDragAfter,!1),window.addEventListener("touchend",U._endDragAfter,!1),window.addEventListener("touchcancel",U._endDragAfter,!1));function St(a){return y._isString(a)?'"'+a+'"':Object.prototype.toString.call(a)==="[object Number]"||y._isBoolean(a)?a:Object.prototype.toString.call(a)}function mi(a){return a>255?255:a<0?0:Math.round(a)}function k(){if(E.isUnminified)return function(a,t){return y._isNumber(a)||y.warn(St(a)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),a}}function me(a){if(E.isUnminified)return function(t,e){let i=y._isNumber(t),s=y._isArray(t)&&t.length==a;return!i&&!s&&y.warn(St(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or Array<number>('+a+")"),t}}function Ne(){if(E.isUnminified)return function(a,t){return y._isNumber(a)||a==="auto"||y.warn(St(a)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),a}}function At(){if(E.isUnminified)return function(a,t){return y._isString(a)||y.warn(St(a)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),a}}function _i(){if(E.isUnminified)return function(a,t){const e=y._isString(a),i=Object.prototype.toString.call(a)==="[object CanvasGradient]"||a&&a.addColorStop;return e||i||y.warn(St(a)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),a}}function Es(){if(E.isUnminified)return function(a,t){const e=Int8Array?Object.getPrototypeOf(Int8Array):null;return e&&a instanceof e||(y._isArray(a)?a.forEach(function(i){y._isNumber(i)||y.warn('"'+t+'" attribute has non numeric element '+i+". Make sure that all elements are numbers.")}):y.warn(St(a)+' is a not valid value for "'+t+'" attribute. The value should be a array of numbers.')),a}}function ht(){if(E.isUnminified)return function(a,t){return a===!0||a===!1||y.warn(St(a)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),a}}function Ps(a){if(E.isUnminified)return function(t,e){return t==null||y.isObject(t)||y.warn(St(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+a),t}}const Nt="get",zt="set",g={addGetterSetter(a,t,e,i,s){g.addGetter(a,t,e),g.addSetter(a,t,i,s),g.addOverloadedGetterSetter(a,t)},addGetter(a,t,e){const i=Nt+y._capitalize(t);a.prototype[i]=a.prototype[i]||function(){const s=this.attrs[t];return s===void 0?e:s}},addSetter(a,t,e,i){const s=zt+y._capitalize(t);a.prototype[s]||g.overWriteSetter(a,t,e,i)},overWriteSetter(a,t,e,i){const s=zt+y._capitalize(t);a.prototype[s]=function(n){return e&&n!==void 0&&n!==null&&(n=e.call(this,n,t)),this._setAttr(t,n),i&&i.call(this),this}},addComponentsGetterSetter(a,t,e,i,s){const n=e.length,r=y._capitalize,o=Nt+r(t),h=zt+r(t);a.prototype[o]=function(){const c={};for(let u=0;u<n;u++){const d=e[u];c[d]=this.getAttr(t+r(d))}return c};const l=Ps(e);a.prototype[h]=function(c){const u=this.attrs[t];i&&(c=i.call(this,c,t)),l&&l.call(this,c,t);for(const d in c)c.hasOwnProperty(d)&&this._setAttr(t+r(d),c[d]);return c||e.forEach(d=>{this._setAttr(t+r(d),void 0)}),this._fireChangeEvent(t,u,c),s&&s.call(this),this},g.addOverloadedGetterSetter(a,t)},addOverloadedGetterSetter(a,t){const e=y._capitalize(t),i=zt+e,s=Nt+e;a.prototype[t]=function(){return arguments.length?(this[i](arguments[0]),this):this[s]()}},addDeprecatedGetterSetter(a,t,e,i){y.error("Adding deprecated "+t);const s=Nt+y._capitalize(t),n=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";a.prototype[s]=function(){y.error(n);const r=this.attrs[t];return r===void 0?e:r},g.addSetter(a,t,i,function(){y.error(n)}),g.addOverloadedGetterSetter(a,t)},backCompat(a,t){y.each(t,function(e,i){const s=a.prototype[i],n=Nt+y._capitalize(e),r=zt+y._capitalize(e);function o(){s.apply(this,arguments),y.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}a.prototype[e]=o,a.prototype[n]=o,a.prototype[r]=o})},afterSetFilter(){this._filterUpToDate=!1}};function Ms(a){const t=/(\w+)\(([^)]+)\)/g;let e;for(;(e=t.exec(a))!==null;){const[,i,s]=e;switch(i){case"blur":{const n=parseFloat(s.replace("px",""));return function(r){this.blurRadius(n*.5);const o=E.Filters;o&&o.Blur&&o.Blur.call(this,r)}}case"brightness":{const n=s.includes("%")?parseFloat(s)/100:parseFloat(s);return function(r){this.brightness(n);const o=E.Filters;o&&o.Brightness&&o.Brightness.call(this,r)}}case"contrast":{const n=parseFloat(s);return function(r){const o=100*(Math.sqrt(n)-1);this.contrast(o);const h=E.Filters;h&&h.Contrast&&h.Contrast.call(this,r)}}case"grayscale":return function(n){const r=E.Filters;r&&r.Grayscale&&r.Grayscale.call(this,n)};case"sepia":return function(n){const r=E.Filters;r&&r.Sepia&&r.Sepia.call(this,n)};case"invert":return function(n){const r=E.Filters;r&&r.Invert&&r.Invert.call(this,n)};default:y.warn(`CSS filter "${i}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}const ce="absoluteOpacity",qe="allEventListeners",ut="absoluteTransform",$e="absoluteScale",wt="canvas",Rs="Change",Ls="children",Ds="konva",ke="listening",Gs="mouseenter",Is="mouseleave",Os="pointerenter",Fs="pointerleave",Bs="touchenter",Ns="touchleave",Ke="set",Ze="Shape",de=" ",Je="stage",_t="transform",zs="Stage",Ae="visible",Hs=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(de);let Ws=1;class w{constructor(t){this._id=Ws++,this.eventListeners={},this.attrs={},this.index=0,this._allEventListeners=null,this.parent=null,this._cache=new Map,this._attachedDepsListeners=new Map,this._lastPos=null,this._batchingTransformChange=!1,this._needClearTransformCache=!1,this._filterUpToDate=!1,this._isUnderCache=!1,this._dragEventId=null,this._shouldFireChangeEvents=!1,this.setAttrs(t),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(t){(t===_t||t===ut)&&this._cache.get(t)?this._cache.get(t).dirty=!0:t?this._cache.delete(t):this._cache.clear()}_getCache(t,e){let i=this._cache.get(t);return(i===void 0||(t===_t||t===ut)&&i.dirty===!0)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){const s=e.map(n=>n+"Change.konva").join(de);this.on(s,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(wt)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===ut&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(wt)){const{scene:t,filter:e,hit:i}=this._cache.get(wt);y.releaseCanvas(t._canvas,e._canvas,i._canvas),this._cache.delete(wt)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};(e.x===void 0||e.y===void 0||e.width===void 0||e.height===void 0)&&(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),n=Math.ceil(e.height||i.height),r=e.pixelRatio,o=e.x===void 0?Math.floor(i.x):e.x,h=e.y===void 0?Math.floor(i.y):e.y,l=e.offset||0,c=e.drawBorder||!1,u=e.hitCanvasPixelRatio||1;if(!s||!n){y.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}const d=Math.abs(Math.round(i.x)-o)>.5?1:0,p=Math.abs(Math.round(i.y)-h)>.5?1:0;s+=l*2+d,n+=l*2+p,o-=l,h-=l;const f=new Ct({pixelRatio:r,width:s,height:n}),m=new Ct({pixelRatio:r,width:0,height:0,willReadFrequently:!0}),_=new Be({pixelRatio:u,width:s,height:n}),C=f.getContext(),S=_.getContext(),b=new Ct({width:f.width/f.pixelRatio+Math.abs(o),height:f.height/f.pixelRatio+Math.abs(h),pixelRatio:f.pixelRatio}),v=b.getContext();return _.isCache=!0,f.isCache=!0,this._cache.delete(wt),this._filterUpToDate=!1,e.imageSmoothingEnabled===!1&&(f.getContext()._context.imageSmoothingEnabled=!1,m.getContext()._context.imageSmoothingEnabled=!1),C.save(),S.save(),v.save(),C.translate(-o,-h),S.translate(-o,-h),v.translate(-o,-h),b.x=o,b.y=h,this._isUnderCache=!0,this._clearSelfAndDescendantCache(ce),this._clearSelfAndDescendantCache($e),this.drawScene(f,this,b),this.drawHit(_,this),this._isUnderCache=!1,C.restore(),S.restore(),c&&(C.save(),C.beginPath(),C.rect(0,0,s,n),C.closePath(),C.setAttr("strokeStyle","red"),C.setAttr("lineWidth",5),C.stroke(),C.restore()),y.releaseCanvas(b._canvas),this._cache.set(wt,{scene:f,filter:m,hit:_,x:o,y:h}),this._requestDraw(),this}isCached(){return this._cache.has(wt)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){const i=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let s=1/0,n=1/0,r=-1/0,o=-1/0;const h=this.getAbsoluteTransform(e);return i.forEach(function(l){const c=h.point(l);s===void 0&&(s=r=c.x,n=o=c.y),s=Math.min(s,c.x),n=Math.min(n,c.y),r=Math.max(r,c.x),o=Math.max(o,c.y)}),{x:s,y:n,width:r-s,height:o-n}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);const i=this._getCachedSceneCanvas(),s=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/s,i.height/s),t.restore()}_drawCachedHitCanvas(t){const e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t=this.filters(),e=this._getCanvasCache(),i=e.scene,s=e.filter,n=s.getContext(),r,o,h,l;if(!t||t.length===0)return i;if(this._filterUpToDate)return s;let c=!0;for(let d=0;d<t.length;d++)if(typeof t[d]=="string"&&je(),typeof t[d]!="string"||!je()){c=!1;break}const u=i.pixelRatio;if(s.setSize(i.width/i.pixelRatio,i.height/i.pixelRatio),c){const d=t.join(" ");return n.save(),n.setAttr("filter",d),n.drawImage(i._canvas,0,0,i.getWidth()/u,i.getHeight()/u),n.restore(),this._filterUpToDate=!0,s}try{for(r=t.length,n.clear(),n.drawImage(i._canvas,0,0,i.getWidth()/u,i.getHeight()/u),o=n.getImageData(0,0,s.getWidth(),s.getHeight()),h=0;h<r;h++)l=t[h],typeof l=="string"&&(l=Ms(l)),l.call(this,o),n.putImageData(o,0,0)}catch(d){y.error("Unable to apply filter. "+d.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,s}on(t,e){if(this._cache&&this._cache.delete(qe),arguments.length===3)return this._delegate.apply(this,arguments);const i=t.split(de);for(let s=0;s<i.length;s++){const r=i[s].split("."),o=r[0],h=r[1]||"";this.eventListeners[o]||(this.eventListeners[o]=[]),this.eventListeners[o].push({name:h,handler:e})}return this}off(t,e){let i=(t||"").split(de),s=i.length,n,r,o,h,l,c;if(this._cache&&this._cache.delete(qe),!t)for(r in this.eventListeners)this._off(r);for(n=0;n<s;n++)if(o=i[n],h=o.split("."),l=h[0],c=h[1],l)this.eventListeners[l]&&this._off(l,c,e);else for(r in this.eventListeners)this._off(r,c,e);return this}dispatchEvent(t){const e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(i){e.call(this,i.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){const s=this;this.on(t,function(n){const r=n.target.findAncestors(e,!0,s);for(let o=0;o<r.length;o++)n=y.cloneObject(n),n.currentTarget=r[o],i.call(r[o],n)})}remove(){return this.isDragging()&&this.stopDrag(),U._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(ut),this._clearSelfAndDescendantCache(ce),this._clearSelfAndDescendantCache($e),this._clearSelfAndDescendantCache(Je),this._clearSelfAndDescendantCache(Ae),this._clearSelfAndDescendantCache(ke)}_remove(){this._clearCaches();const t=this.getParent();t&&t.children&&(t.children.splice(this.index,1),t._setChildrenIndices(),this.parent=null)}destroy(){return this.remove(),this.clearCache(),this}getAttr(t){const e="get"+y._capitalize(t);return y._isFunction(this[e])?this[e]():this.attrs[t]}getAncestors(){let t=this.getParent(),e=[];for(;t;)e.push(t),t=t.getParent();return e}getAttrs(){return this.attrs||{}}setAttrs(t){return this._batchTransformChanges(()=>{let e,i;if(!t)return this;for(e in t)e!==Ls&&(i=Ke+y._capitalize(e),y._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(ke,this._isListening)}_isListening(t){if(!this.listening())return!1;const i=this.getParent();return i&&i!==t&&this!==t?i._isListening(t):!0}isVisible(){return this._getCache(Ae,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const i=this.getParent();return i&&i!==t&&this!==t?i._isVisible(t):!0}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const i=this.getLayer();let s=!1;U._dragElements.forEach(r=>{r.dragStatus==="dragging"&&(r.node.nodeType==="Stage"||r.node.getLayer()===i)&&(s=!0)});const n=!e&&!E.hitOnDragEnabled&&(s||E.isTransforming());return this.isListening()&&this.isVisible()&&!n}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t=this.getDepth(),e=this,i=0,s,n,r,o;function h(c){for(s=[],n=c.length,r=0;r<n;r++)o=c[r],i++,o.nodeType!==Ze&&(s=s.concat(o.getChildren().slice())),o._id===e._id&&(r=n);s.length>0&&s[0].getDepth()<=t&&h(s)}const l=this.getStage();return e.nodeType!==zs&&l&&h(l.getChildren()),i}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(_t),this._clearSelfAndDescendantCache(ut)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges(()=>{this.x(t.x),this.y(t.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const t=this.getStage();if(!t)return null;const e=t.getPointerPosition();if(!e)return null;const i=this.getAbsoluteTransform().copy();return i.invert(),i.point(e)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);const s=this.getAbsoluteTransform(t).getMatrix(),n=new rt,r=this.offset();return n.m=s.slice(),n.translate(r.x,r.y),n.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(_t);const n=this._getAbsoluteTransform().copy();return n.invert(),n.translate(t.x,t.y),t={x:this.attrs.x+n.getTranslation().x,y:this.attrs.y+n.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(_t),this._clearSelfAndDescendantCache(ut),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){const t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}move(t){let e=t.x,i=t.y,s=this.x(),n=this.y();return e!==void 0&&(s+=e),i!==void 0&&(n+=i),this.setPosition({x:s,y:n}),this}_eachAncestorReverse(t,e){let i=[],s=this.getParent(),n,r;if(!(e&&e._id===this._id)){for(i.unshift(this);s&&(!e||s._id!==e._id);)i.unshift(s),s=s.parent;for(n=i.length,r=0;r<n;r++)t(i[r])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return y.warn("Node has no parent. moveToTop function is ignored."),!1;const t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0):!1}moveUp(){if(!this.parent)return y.warn("Node has no parent. moveUp function is ignored."),!1;const t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0):!1}moveDown(){if(!this.parent)return y.warn("Node has no parent. moveDown function is ignored."),!1;const t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return y.warn("Node has no parent. moveToBottom function is ignored."),!1;const t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(t){if(!this.parent)return y.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&y.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");const e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(ce,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity();const e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t=this.getAttrs(),e,i,s,n,r;const o={attrs:{},className:this.getClassName()};for(e in t)i=t[e],r=y.isObject(i)&&!y._isPlainObject(i)&&!y._isArray(i),!r&&(s=typeof this[e]=="function"&&this[e],delete t[e],n=s?s.call(this):null,t[e]=i,n!==i&&(o.attrs[e]=i));return y._prepareToStringify(o)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){const s=[];e&&this._isMatch(t)&&s.push(this);let n=this.parent;for(;n;){if(n===i)return s;n._isMatch(t)&&s.push(n),n=n.parent}return s}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if(typeof t=="function")return t(this);let e=t.replace(/ /g,"").split(","),i=e.length,s,n;for(s=0;s<i;s++)if(n=e[s],y.isValidSelector(n)||(y.warn('Selector "'+n+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),y.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),y.warn("Konva is awesome, right?")),n.charAt(0)==="#"){if(this.id()===n.slice(1))return!0}else if(n.charAt(0)==="."){if(this.hasName(n.slice(1)))return!0}else if(this.className===n||this.nodeType===n)return!0;return!1}getLayer(){const t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(Je,this._getStage)}_getStage(){const t=this.getParent();return t?t.getStage():null}fire(t,e={},i){return e.target=e.target||this,i?this._fireAndBubble(t,e):this._fire(t,e),this}getAbsoluteTransform(t){return t?this._getAbsoluteTransform(t):this._getCache(ut,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new rt,this._eachAncestorReverse(function(i){const s=i.transformsEnabled();s==="all"?e.multiply(i.getTransform()):s==="position"&&e.translate(i.x()-i.offsetX(),i.y()-i.offsetY())},t),e;{e=this._cache.get(ut)||new rt,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();const i=this.transformsEnabled();if(i==="all")e.multiply(this.getTransform());else if(i==="position"){const s=this.attrs.x||0,n=this.attrs.y||0,r=this.attrs.offsetX||0,o=this.attrs.offsetY||0;e.translate(s-r,n-o)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();const s=this.getAbsoluteTransform(t).decompose();return{x:s.scaleX,y:s.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(_t,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(_t)||new rt;i.reset();const s=this.x(),n=this.y(),r=E.getAngle(this.rotation()),o=(t=this.attrs.scaleX)!==null&&t!==void 0?t:1,h=(e=this.attrs.scaleY)!==null&&e!==void 0?e:1,l=this.attrs.skewX||0,c=this.attrs.skewY||0,u=this.attrs.offsetX||0,d=this.attrs.offsetY||0;return(s!==0||n!==0)&&i.translate(s,n),r!==0&&i.rotate(r),(l!==0||c!==0)&&i.skew(l,c),(o!==1||h!==1)&&i.scale(o,h),(u!==0||d!==0)&&i.translate(-1*u,-1*d),i.dirty=!1,i}clone(t){let e=y.cloneObject(this.attrs),i,s,n,r,o;for(i in t)e[i]=t[i];const h=new this.constructor(e);for(i in this.eventListeners)for(s=this.eventListeners[i],n=s.length,r=0;r<n;r++)o=s[r],o.name.indexOf(Ds)<0&&(h.eventListeners[i]||(h.eventListeners[i]=[]),h.eventListeners[i].push(o));return h}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=t.x!==void 0?t.x:Math.floor(e.x),n=t.y!==void 0?t.y:Math.floor(e.y),r=t.pixelRatio||1,o=new Ct({width:t.width||Math.ceil(e.width)||(i?i.width():0),height:t.height||Math.ceil(e.height)||(i?i.height():0),pixelRatio:r}),h=o.getContext(),l=new Ct({width:o.width/o.pixelRatio+Math.abs(s),height:o.height/o.pixelRatio+Math.abs(n),pixelRatio:o.pixelRatio});return t.imageSmoothingEnabled===!1&&(h._context.imageSmoothingEnabled=!1),h.save(),(s||n)&&h.translate(-1*s,-1*n),this.drawScene(o,void 0,l),h.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){t=t||{};const e=t.mimeType||null,i=t.quality||null,s=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(s),s}toImage(t){return new Promise((e,i)=>{try{const s=t==null?void 0:t.callback;s&&delete t.callback,y._urlToImage(this.toDataURL(t),function(n){e(n),s==null||s(n)})}catch(s){i(s)}})}toBlob(t){return new Promise((e,i)=>{try{const s=t==null?void 0:t.callback;s&&delete t.callback,this.toCanvas(t).toBlob(n=>{e(n),s==null||s(n)},t==null?void 0:t.mimeType,t==null?void 0:t.quality)}catch(s){i(s)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance!==void 0?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():E.dragDistance}_off(t,e,i){let s=this.eventListeners[t],n,r,o;for(n=0;n<s.length;n++)if(r=s[n].name,o=s[n].handler,(r!=="konva"||e==="konva")&&(!e||r===e)&&(!i||i===o)){if(s.splice(n,1),s.length===0){delete this.eventListeners[t];break}n--}}_fireChangeEvent(t,e,i){this._fire(t+Rs,{oldVal:e,newVal:i})}addName(t){if(!this.hasName(t)){const e=this.name(),i=e?e+" "+t:t;this.name(i)}return this}hasName(t){if(!t)return!1;const e=this.name();return e?(e||"").split(/\s/g).indexOf(t)!==-1:!1}removeName(t){const e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return i!==-1&&(e.splice(i,1),this.name(e.join(" "))),this}setAttr(t,e){const i=this[Ke+y._capitalize(t)];return y._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(E.autoDrawEnabled){const t=this.getLayer()||this.getStage();t==null||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];i===e&&!y.isObject(e)||(e==null?delete this.attrs[t]:this.attrs[t]=e,this._shouldFireChangeEvents&&this._fireChangeEvent(t,i,e),this._requestDraw())}_setComponentAttr(t,e,i){let s;i!==void 0&&(s=this.attrs[t],s||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,s,i))}_fireAndBubble(t,e,i){e&&this.nodeType===Ze&&(e.target=this);const s=[Gs,Is,Os,Fs,Bs,Ns];if(!(s.indexOf(t)!==-1&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||this.nodeType==="Stage"&&!i))){this._fire(t,e);const r=s.indexOf(t)!==-1&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!r&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i;const{nodeType:s}=this,n=w.protoListenerMap.get(s)||{};let r=n==null?void 0:n[t];if(r===void 0){r=[];let o=Object.getPrototypeOf(this);for(;o;){const h=(i=(e=o.eventListeners)===null||e===void 0?void 0:e[t])!==null&&i!==void 0?i:[];r.push(...h),o=Object.getPrototypeOf(o)}n[t]=r,w.protoListenerMap.set(s,n)}return r}_fire(t,e){e=e||{},e.currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let n=0;n<i.length;n++)i[n].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let n=0;n<s.length;n++)s[n].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const e=t?t.pointerId:void 0,i=this.getStage(),s=this.getAbsolutePosition();if(!i)return;const n=i._getPointerById(e)||i._changedPointerPositions[0]||s;U._dragElements.set(this._id,{node:this,startPointerPos:n,offset:{x:n.x-s.x,y:n.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){U._dragElements.has(this._id)||this._createDragElement(t);const i=U._dragElements.get(this._id);i.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:t&&t.evt},e)}_setDragPosition(t,e){const i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let s={x:i.x-e.offset.x,y:i.y-e.offset.y};const n=this.dragBoundFunc();if(n!==void 0){const r=n.call(this,s,t);r?s=r:y.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==s.x||this._lastPos.y!==s.y)&&(this.setAbsolutePosition(s),this._requestDraw()),this._lastPos=s}stopDrag(t){const e=U._dragElements.get(this._id);e&&(e.dragStatus="stopped"),U._endDragBefore(t),U._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=U._dragElements.get(this._id);return t?t.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(t.evt.button!==void 0)||E.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let s=!1;U._dragElements.forEach(n=>{this.isAncestorOf(n.node)&&(s=!0)}),s||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const e=U._dragElements.get(this._id),i=e&&e.dragStatus==="dragging",s=e&&e.dragStatus==="ready";i?this.stopDrag():s&&U._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const e=this.getStage();if(!e)return!1;const i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return y.haveIntersection(i,this.getClientRect())}static create(t,e){return y._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let i=w.prototype.getClassName.call(t),s=t.children,n,r,o;e&&(t.attrs.container=e),E[i]||(y.warn('Can not find a node with class name "'+i+'". Fallback to "Shape".'),i="Shape");const h=E[i];if(n=new h(t.attrs),s)for(r=s.length,o=0;o<r;o++)n.add(w._createNode(s[o]));return n}}w.protoListenerMap=new Map;w.prototype.nodeType="Node";w.prototype._attrsAffectingSize=[];w.prototype.eventListeners={};w.prototype.on.call(w.prototype,Hs,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(_t),this._clearSelfAndDescendantCache(ut)});w.prototype.on.call(w.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(Ae)});w.prototype.on.call(w.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(ke)});w.prototype.on.call(w.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(ce)});const j=g.addGetterSetter;j(w,"zIndex");j(w,"absolutePosition");j(w,"position");j(w,"x",0,k());j(w,"y",0,k());j(w,"globalCompositeOperation","source-over",At());j(w,"opacity",1,k());j(w,"name","",At());j(w,"id","",At());j(w,"rotation",0,k());g.addComponentsGetterSetter(w,"scale",["x","y"]);j(w,"scaleX",1,k());j(w,"scaleY",1,k());g.addComponentsGetterSetter(w,"skew",["x","y"]);j(w,"skewX",0,k());j(w,"skewY",0,k());g.addComponentsGetterSetter(w,"offset",["x","y"]);j(w,"offsetX",0,k());j(w,"offsetY",0,k());j(w,"dragDistance",void 0,k());j(w,"width",0,k());j(w,"height",0,k());j(w,"listening",!0,ht());j(w,"preventDefault",!0,ht());j(w,"filters",void 0,function(a){return this._filterUpToDate=!1,a});j(w,"visible",!0,ht());j(w,"transformsEnabled","all",At());j(w,"size");j(w,"dragBoundFunc");j(w,"draggable",!1,ht());g.backCompat(w,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class at extends w{constructor(){super(...arguments),this.children=[]}getChildren(t){const e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(t.length===0)return this;if(t.length>1){for(let i=0;i<t.length;i++)this.add(t[i]);return this}const e=t[0];return e.getParent()?(e.moveTo(this),this):(this._validateAdd(e),e.index=this.getChildren().length,e.parent=this,e._clearCaches(),this.getChildren().push(e),this._fire("add",{child:e}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(t){return this._generalFind(t,!1)}findOne(t){const e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){const i=[];return this._descendants(s=>{const n=s._isMatch(t);return n&&i.push(s),!!(n&&e)}),i}_descendants(t){let e=!1;const i=this.getChildren();for(const s of i){if(e=t(s),e)return!0;if(s.hasChildren()&&(e=s._descendants(t),e))return!0}return!1}toObject(){const t=w.prototype.toObject.call(this);return t.children=[],this.getChildren().forEach(e=>{t.children.push(e.toObject())}),t}isAncestorOf(t){let e=t.getParent();for(;e;){if(e._id===this._id)return!0;e=e.getParent()}return!1}clone(t){const e=w.prototype.clone.call(this,t);return this.getChildren().forEach(function(i){e.add(i.clone())}),e}getAllIntersections(t){const e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),!this.isCached()&&((e=this.children)===null||e===void 0||e.forEach(function(i){i._clearSelfAndDescendantCache(t)}))}_setChildrenIndices(){var t;(t=this.children)===null||t===void 0||t.forEach(function(e,i){e.index=i}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),n=t||s&&s.getCanvas(),r=n&&n.getContext(),o=this._getCanvasCache(),h=o&&o.scene,l=n&&n.isCache;if(!this.isVisible()&&!l)return this;if(h){r.save();const c=this.getAbsoluteTransform(e).getMatrix();r.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedSceneCanvas(r),r.restore()}else this._drawChildren("drawScene",n,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,n=s&&s.getContext(),r=this._getCanvasCache();if(r&&r.hit){n.save();const h=this.getAbsoluteTransform(e).getMatrix();n.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedHitCanvas(n),n.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var n;const r=e&&e.getContext(),o=this.clipWidth(),h=this.clipHeight(),l=this.clipFunc(),c=typeof o=="number"&&typeof h=="number"||l,u=i===this;if(c){r.save();const p=this.getAbsoluteTransform(i);let f=p.getMatrix();r.transform(f[0],f[1],f[2],f[3],f[4],f[5]),r.beginPath();let m;if(l)m=l.call(this,r,this);else{const _=this.clipX(),C=this.clipY();r.rect(_||0,C||0,o,h)}r.clip.apply(r,m),f=p.copy().invert().getMatrix(),r.transform(f[0],f[1],f[2],f[3],f[4],f[5])}const d=!u&&this.globalCompositeOperation()!=="source-over"&&t==="drawScene";d&&(r.save(),r._applyGlobalCompositeOperation(this)),(n=this.children)===null||n===void 0||n.forEach(function(p){p[t](e,i,s)}),d&&r.restore(),c&&r.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let n,r,o,h,l={x:1/0,y:1/0,width:0,height:0};const c=this;(e=this.children)===null||e===void 0||e.forEach(function(p){if(!p.visible())return;const f=p.getClientRect({relativeTo:c,skipShadow:t.skipShadow,skipStroke:t.skipStroke});f.width===0&&f.height===0||(n===void 0?(n=f.x,r=f.y,o=f.x+f.width,h=f.y+f.height):(n=Math.min(n,f.x),r=Math.min(r,f.y),o=Math.max(o,f.x+f.width),h=Math.max(h,f.y+f.height)))});const u=this.find("Shape");let d=!1;for(let p=0;p<u.length;p++)if(u[p]._isVisible(this)){d=!0;break}return d&&n!==void 0?l={x:n,y:r,width:o-n,height:h-r}:l={x:0,y:0,width:0,height:0},i?l:this._transformedRect(l,s)}}g.addComponentsGetterSetter(at,"clip",["x","y","width","height"]);g.addGetterSetter(at,"clipX",void 0,k());g.addGetterSetter(at,"clipY",void 0,k());g.addGetterSetter(at,"clipWidth",void 0,k());g.addGetterSetter(at,"clipHeight",void 0,k());g.addGetterSetter(at,"clipFunc");const Jt=new Map,yi=E._global.PointerEvent!==void 0;function Ce(a){return Jt.get(a)}function ze(a){return{evt:a,pointerId:a.pointerId}}function Ci(a,t){return Jt.get(a)===t}function Si(a,t){qt(a),t.getStage()&&(Jt.set(a,t),yi&&t._fire("gotpointercapture",ze(new PointerEvent("gotpointercapture"))))}function qt(a,t){const e=Jt.get(a);if(!e)return;const i=e.getStage();i&&i.content,Jt.delete(a),yi&&e._fire("lostpointercapture",ze(new PointerEvent("lostpointercapture")))}const Us="Stage",Xs="string",Qe="px",Ys="mouseout",bi="mouseleave",vi="mouseover",Ti="mouseenter",wi="mousemove",xi="mousedown",ki="mouseup",Ut="pointermove",Xt="pointerdown",Gt="pointerup",Yt="pointercancel",Vs="lostpointercapture",se="pointerout",Vt="pointerleave",ne="pointerover",re="pointerenter",Ee="contextmenu",Ai="touchstart",Ei="touchend",Pi="touchmove",Mi="touchcancel",Pe="wheel",js=5,qs=[[Ti,"_pointerenter"],[xi,"_pointerdown"],[wi,"_pointermove"],[ki,"_pointerup"],[bi,"_pointerleave"],[Ai,"_pointerdown"],[Pi,"_pointermove"],[Ei,"_pointerup"],[Mi,"_pointercancel"],[vi,"_pointerover"],[Pe,"_wheel"],[Ee,"_contextmenu"],[Xt,"_pointerdown"],[Ut,"_pointermove"],[Gt,"_pointerup"],[Yt,"_pointercancel"],[Vt,"_pointerleave"],[Vs,"_lostpointercapture"]],Se={mouse:{[se]:Ys,[Vt]:bi,[ne]:vi,[re]:Ti,[Ut]:wi,[Xt]:xi,[Gt]:ki,[Yt]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[se]:"touchout",[Vt]:"touchleave",[ne]:"touchover",[re]:"touchenter",[Ut]:Pi,[Xt]:Ai,[Gt]:Ei,[Yt]:Mi,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[se]:se,[Vt]:Vt,[ne]:ne,[re]:re,[Ut]:Ut,[Xt]:Xt,[Gt]:Gt,[Yt]:Yt,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},jt=a=>a.indexOf("pointer")>=0?"pointer":a.indexOf("touch")>=0?"touch":"mouse",Lt=a=>{const t=jt(a);if(t==="pointer")return E.pointerEventsEnabled&&Se.pointer;if(t==="touch")return Se.touch;if(t==="mouse")return Se.mouse};function ti(a={}){return(a.clipFunc||a.clipWidth||a.clipHeight)&&y.warn("Stage does not support clipping. Please use clip for Layers or Groups."),a}const $s="Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);",$t=[];class _e extends at{constructor(t){super(ti(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),$t.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{ti(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e=t.getType()==="Layer",i=t.getType()==="FastLayer";e||i||y.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if(typeof t===Xs){let e;if(t.charAt(0)==="."){const i=t.slice(1);t=document.getElementsByClassName(i)[0]}else t.charAt(0)!=="#"?e=t:e=t.slice(1),t=document.getElementById(e);if(!t)throw"Can not find container in document with id "+e}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){const t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].clear();return this}clone(t){return t||(t={}),t.container=typeof document<"u"&&document.createElement("div"),at.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&y._isInDocument(t)&&this.container().removeChild(t);const e=$t.indexOf(this);return e>-1&&$t.splice(e,1),y.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(y.warn($s),null)}_getPointerById(t){return this._pointerPositions.find(e=>e.id===t)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){t={...t},t.x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();const e=new Ct({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,s=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),s.forEach(function(n){if(!n.isVisible())return;const r=n._toKonvaCanvas(t);i.drawImage(r._canvas,t.x,t.y,r.getWidth()/r.getPixelRatio(),r.getHeight()/r.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children,i=e.length,s=i-1;for(let n=s;n>=0;n--){const r=e[n].getIntersection(t);if(r)return r}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+Qe,this.content.style.height=e+Qe),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach(i=>{i.setSize({width:t,height:e}),i.draw()})}add(t,...e){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.add(arguments[s]);return this}super.add(t);const i=this.children.length;return i>js&&y.warn("The stage has "+i+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),t.setSize({width:this.width(),height:this.height()}),t.draw(),E.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return Ci(t,this)}setPointerCapture(t){Si(t,this)}releaseCapture(t){qt(t)}getLayers(){return this.children}_bindContentEvents(){E.isBrowser&&qs.forEach(([t,e])=>{this.content.addEventListener(t,i=>{this[e](i)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=Lt(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Lt(t.type);e&&this._fire(e.pointerover,{evt:t,target:this,currentTarget:this})}_getTargetShape(t){let e=this[t+"targetShape"];return e&&!e.getStage()&&(e=null),e}_pointerleave(t){const e=Lt(t.type),i=jt(t.type);if(!e)return;this.setPointersPositions(t);const s=this._getTargetShape(i),n=!(E.isDragging()||E.isTransforming())||E.hitOnDragEnabled;s&&n?(s._fireAndBubble(e.pointerout,{evt:t}),s._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"targetShape"]=null):n&&(this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this._fire(e.pointerout,{evt:t,target:this,currentTarget:this})),this.pointerPos=null,this._pointerPositions=[]}_pointerdown(t){const e=Lt(t.type),i=jt(t.type);if(!e)return;this.setPointersPositions(t);let s=!1;this._changedPointerPositions.forEach(n=>{const r=this.getIntersection(n);if(U.justDragged=!1,E["_"+i+"ListenClick"]=!0,!r||!r.isListening()){this[i+"ClickStartShape"]=void 0;return}E.capturePointerEventsEnabled&&r.setPointerCapture(n.id),this[i+"ClickStartShape"]=r,r._fireAndBubble(e.pointerdown,{evt:t,pointerId:n.id}),s=!0;const o=t.type.indexOf("touch")>=0;r.preventDefault()&&t.cancelable&&o&&t.preventDefault()}),s||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=Lt(t.type),i=jt(t.type);if(!e)return;const s=t.type.indexOf("touch")>=0||t.pointerType==="touch";if(E.isDragging()&&U.node.preventDefault()&&t.cancelable&&s&&t.preventDefault(),this.setPointersPositions(t),!(!(E.isDragging()||E.isTransforming())||E.hitOnDragEnabled))return;const r={};let o=!1;const h=this._getTargetShape(i);this._changedPointerPositions.forEach(l=>{const c=Ce(l.id)||this.getIntersection(l),u=l.id,d={evt:t,pointerId:u},p=h!==c;if(p&&h&&(h._fireAndBubble(e.pointerout,{...d},c),h._fireAndBubble(e.pointerleave,{...d},c)),c){if(r[c._id])return;r[c._id]=!0}c&&c.isListening()?(o=!0,p&&(c._fireAndBubble(e.pointerover,{...d},h),c._fireAndBubble(e.pointerenter,{...d},h),this[i+"targetShape"]=c),c._fireAndBubble(e.pointermove,{...d})):h&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:u}),this[i+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Lt(t.type),i=jt(t.type);if(!e)return;this.setPointersPositions(t);const s=this[i+"ClickStartShape"],n=this[i+"ClickEndShape"],r={};let o=!1;this._changedPointerPositions.forEach(h=>{const l=Ce(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),r[l._id])return;r[l._id]=!0}const c=h.id,u={evt:t,pointerId:c};let d=!1;E["_"+i+"InDblClickWindow"]?(d=!0,clearTimeout(this[i+"DblTimeout"])):U.justDragged||(E["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){E["_"+i+"InDblClickWindow"]=!1},E.dblClickWindow),l&&l.isListening()?(o=!0,this[i+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...u}),E["_"+i+"ListenClick"]&&s&&s===l&&(l._fireAndBubble(e.pointerclick,{...u}),d&&n&&n===l&&l._fireAndBubble(e.pointerdblclick,{...u}))):(this[i+"ClickEndShape"]=null,o||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),o=!0),E["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:c}),d&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:c}))}),o||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),E["_"+i+"ListenClick"]=!1,t.cancelable&&i!=="touch"&&i!=="pointer"&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ee,{evt:t}):this._fire(Ee,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Pe,{evt:t}):this._fire(Pe,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=Ce(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(Gt,ze(t)),qt(t.pointerId)}_lostpointercapture(t){qt(t.pointerId)}setPointersPositions(t){const e=this._getContentPosition();let i=null,s=null;t=t||window.event,t.touches!==void 0?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,n=>{this._pointerPositions.push({id:n.identifier,x:(n.clientX-e.left)/e.scaleX,y:(n.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,n=>{this._changedPointerPositions.push({id:n.identifier,x:(n.clientX-e.left)/e.scaleX,y:(n.clientY-e.top)/e.scaleY})})):(i=(t.clientX-e.left)/e.scaleX,s=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:s},this._pointerPositions=[{x:i,y:s,id:y._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:s,id:y._getFirstPointerId(t)}])}_setPointerPosition(t){y.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(t)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};const t=this.content.getBoundingClientRect();return{top:t.top,left:t.left,scaleX:t.width/this.content.clientWidth||1,scaleY:t.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new Ct({width:this.width(),height:this.height()}),this.bufferHitCanvas=new Be({pixelRatio:1,width:this.width(),height:this.height()}),!E.isBrowser)return;const t=this.container();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.userSelect="none",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}cache(){return y.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes."),this}clearCache(){return this}batchDraw(){return this.getChildren().forEach(function(t){t.batchDraw()}),this}}_e.prototype.nodeType=Us;J(_e);g.addGetterSetter(_e,"container");E.isBrowser&&document.addEventListener("visibilitychange",()=>{$t.forEach(a=>{a.batchDraw()})});const Ri="hasShadow",Li="shadowRGBA",Di="patternImage",Gi="linearGradient",Ii="radialGradient";let ae;function be(){return ae||(ae=y.createCanvasElement().getContext("2d"),ae)}const Kt={};function Ks(a){const t=this.attrs.fillRule;t?a.fill(t):a.fill()}function Zs(a){a.stroke()}function Js(a){const t=this.attrs.fillRule;t?a.fill(t):a.fill()}function Qs(a){a.stroke()}function tn(){this._clearCache(Ri)}function en(){this._clearCache(Li)}function sn(){this._clearCache(Di)}function nn(){this._clearCache(Gi)}function rn(){this._clearCache(Ii)}class T extends w{constructor(t){super(t);let e,i=0;for(;e=y.getHitColor(),!(e&&!(e in Kt));)if(i++,i>=1e4){y.warn("Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it."),e=y.getRandomColor();break}this.colorKey=e,Kt[e]=this}getContext(){return y.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return y.warn("shape.getCanvas() method is deprecated. Please do not use it."),this.getLayer().getCanvas()}getSceneFunc(){return this.attrs.sceneFunc||this._sceneFunc}getHitFunc(){return this.attrs.hitFunc||this._hitFunc}hasShadow(){return this._getCache(Ri,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Di,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const e=be().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){const i=new rt;i.translate(this.fillPatternX(),this.fillPatternY()),i.rotate(E.getAngle(this.fillPatternRotation())),i.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),i.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const s=i.getMatrix(),n=typeof DOMMatrix>"u"?{a:s[0],b:s[1],c:s[2],d:s[3],e:s[4],f:s[5]}:new DOMMatrix(s);e.setTransform(n)}return e}}_getLinearGradient(){return this._getCache(Gi,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=be(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),n=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let r=0;r<t.length;r+=2)n.addColorStop(t[r],t[r+1]);return n}}_getRadialGradient(){return this._getCache(Ii,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=be(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),n=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let r=0;r<t.length;r+=2)n.addColorStop(t[r],t[r+1]);return n}}getShadowRGBA(){return this._getCache(Li,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=y.colorToRGBA(this.shadowColor());if(t)return"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")"}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){const t=this.hitStrokeWidth();return t==="auto"?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){const e=this.getStage();if(!e)return!1;const i=e.bufferHitCanvas;return i.getContext().clear(),this.drawHit(i,void 0,!0),i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return w.prototype.destroy.call(this),delete Kt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!((e=this.attrs.perfectDrawEnabled)!==null&&e!==void 0?e:!0))return!1;const s=t||this.hasFill(),n=this.hasStroke(),r=this.getAbsoluteOpacity()!==1;if(s&&n&&r)return!0;const o=this.hasShadow(),h=this.shadowForStrokeEnabled();return!!(s&&n&&o&&h)}setStrokeHitEnabled(t){y.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){const t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){let e=!1,i=this.getParent();for(;i;){if(i.isCached()){e=!0;break}i=i.getParent()}const s=t.skipTransform,n=t.relativeTo||e&&this.getStage()||void 0,r=this.getSelfRect(),h=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,l=r.width+h,c=r.height+h,u=!t.skipShadow&&this.hasShadow(),d=u?this.shadowOffsetX():0,p=u?this.shadowOffsetY():0,f=l+Math.abs(d),m=c+Math.abs(p),_=u&&this.shadowBlur()||0,C=f+_*2,S=m+_*2,b={width:C,height:S,x:-(h/2+_)+Math.min(d,0)+r.x,y:-(h/2+_)+Math.min(p,0)+r.y};return s?b:this._transformedRect(b,n)}drawScene(t,e,i){const s=this.getLayer(),n=t||s.getCanvas(),r=n.getContext(),o=this._getCanvasCache(),h=this.getSceneFunc(),l=this.hasShadow();let c;const u=e===this;if(!this.isVisible()&&!u)return this;if(o){r.save();const d=this.getAbsoluteTransform(e).getMatrix();return r.transform(d[0],d[1],d[2],d[3],d[4],d[5]),this._drawCachedSceneCanvas(r),r.restore(),this}if(!h)return this;if(r.save(),this._useBufferCanvas()){c=this.getStage();const d=i||c.bufferCanvas,p=d.getContext();i?(p.save(),p.setTransform(1,0,0,1,0,0),p.clearRect(0,0,d.width,d.height),p.restore()):p.clear(),p.save(),p._applyLineJoin(this),p._applyMiterLimit(this);const f=this.getAbsoluteTransform(e).getMatrix();p.transform(f[0],f[1],f[2],f[3],f[4],f[5]),h.call(this,p,this),p.restore();const m=d.pixelRatio;l&&r._applyShadow(this),u||(r._applyOpacity(this),r._applyGlobalCompositeOperation(this)),r.drawImage(d._canvas,d.x||0,d.y||0,d.width/m,d.height/m)}else{if(r._applyLineJoin(this),r._applyMiterLimit(this),!u){const d=this.getAbsoluteTransform(e).getMatrix();r.transform(d[0],d[1],d[2],d[3],d[4],d[5]),r._applyOpacity(this),r._applyGlobalCompositeOperation(this)}l&&r._applyShadow(this),h.call(this,r,this)}return r.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),n=t||s.hitCanvas,r=n&&n.getContext(),o=this.hitFunc()||this.sceneFunc(),h=this._getCanvasCache(),l=h&&h.hit;if(this.colorKey||y.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){r.save();const u=this.getAbsoluteTransform(e).getMatrix();return r.transform(u[0],u[1],u[2],u[3],u[4],u[5]),this._drawCachedHitCanvas(r),r.restore(),this}if(!o)return this;if(r.save(),r._applyLineJoin(this),r._applyMiterLimit(this),!(this===e)){const u=this.getAbsoluteTransform(e).getMatrix();r.transform(u[0],u[1],u[2],u[3],u[4],u[5])}return o.call(this,r,this),r.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,n=s.getContext(),r=s.getWidth(),o=s.getHeight();n.clear(),n.drawImage(i._canvas,0,0,r,o);try{const h=n.getImageData(0,0,r,o),l=h.data,c=l.length,u=y._hexToRgb(this.colorKey);for(let d=0;d<c;d+=4)l[d+3]>t?(l[d]=u.r,l[d+1]=u.g,l[d+2]=u.b,l[d+3]=255):l[d+3]=0;n.putImageData(h,0,0)}catch(h){y.error("Unable to draw hit graph from cached scene canvas. "+h.message)}return this}hasPointerCapture(t){return Ci(t,this)}setPointerCapture(t){Si(t,this)}releaseCapture(t){qt(t)}}T.prototype._fillFunc=Ks;T.prototype._strokeFunc=Zs;T.prototype._fillFuncHit=Js;T.prototype._strokeFuncHit=Qs;T.prototype._centroid=!1;T.prototype.nodeType="Shape";J(T);T.prototype.eventListeners={};T.prototype.on.call(T.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",tn);T.prototype.on.call(T.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",en);T.prototype.on.call(T.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",sn);T.prototype.on.call(T.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",nn);T.prototype.on.call(T.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",rn);g.addGetterSetter(T,"stroke",void 0,_i());g.addGetterSetter(T,"strokeWidth",2,k());g.addGetterSetter(T,"fillAfterStrokeEnabled",!1);g.addGetterSetter(T,"hitStrokeWidth","auto",Ne());g.addGetterSetter(T,"strokeHitEnabled",!0,ht());g.addGetterSetter(T,"perfectDrawEnabled",!0,ht());g.addGetterSetter(T,"shadowForStrokeEnabled",!0,ht());g.addGetterSetter(T,"lineJoin");g.addGetterSetter(T,"lineCap");g.addGetterSetter(T,"miterLimit");g.addGetterSetter(T,"sceneFunc");g.addGetterSetter(T,"hitFunc");g.addGetterSetter(T,"dash");g.addGetterSetter(T,"dashOffset",0,k());g.addGetterSetter(T,"shadowColor",void 0,At());g.addGetterSetter(T,"shadowBlur",0,k());g.addGetterSetter(T,"shadowOpacity",1,k());g.addComponentsGetterSetter(T,"shadowOffset",["x","y"]);g.addGetterSetter(T,"shadowOffsetX",0,k());g.addGetterSetter(T,"shadowOffsetY",0,k());g.addGetterSetter(T,"fillPatternImage");g.addGetterSetter(T,"fill",void 0,_i());g.addGetterSetter(T,"fillPatternX",0,k());g.addGetterSetter(T,"fillPatternY",0,k());g.addGetterSetter(T,"fillLinearGradientColorStops");g.addGetterSetter(T,"strokeLinearGradientColorStops");g.addGetterSetter(T,"fillRadialGradientStartRadius",0);g.addGetterSetter(T,"fillRadialGradientEndRadius",0);g.addGetterSetter(T,"fillRadialGradientColorStops");g.addGetterSetter(T,"fillPatternRepeat","repeat");g.addGetterSetter(T,"fillEnabled",!0);g.addGetterSetter(T,"strokeEnabled",!0);g.addGetterSetter(T,"shadowEnabled",!0);g.addGetterSetter(T,"dashEnabled",!0);g.addGetterSetter(T,"strokeScaleEnabled",!0);g.addGetterSetter(T,"fillPriority","color");g.addComponentsGetterSetter(T,"fillPatternOffset",["x","y"]);g.addGetterSetter(T,"fillPatternOffsetX",0,k());g.addGetterSetter(T,"fillPatternOffsetY",0,k());g.addComponentsGetterSetter(T,"fillPatternScale",["x","y"]);g.addGetterSetter(T,"fillPatternScaleX",1,k());g.addGetterSetter(T,"fillPatternScaleY",1,k());g.addComponentsGetterSetter(T,"fillLinearGradientStartPoint",["x","y"]);g.addComponentsGetterSetter(T,"strokeLinearGradientStartPoint",["x","y"]);g.addGetterSetter(T,"fillLinearGradientStartPointX",0);g.addGetterSetter(T,"strokeLinearGradientStartPointX",0);g.addGetterSetter(T,"fillLinearGradientStartPointY",0);g.addGetterSetter(T,"strokeLinearGradientStartPointY",0);g.addComponentsGetterSetter(T,"fillLinearGradientEndPoint",["x","y"]);g.addComponentsGetterSetter(T,"strokeLinearGradientEndPoint",["x","y"]);g.addGetterSetter(T,"fillLinearGradientEndPointX",0);g.addGetterSetter(T,"strokeLinearGradientEndPointX",0);g.addGetterSetter(T,"fillLinearGradientEndPointY",0);g.addGetterSetter(T,"strokeLinearGradientEndPointY",0);g.addComponentsGetterSetter(T,"fillRadialGradientStartPoint",["x","y"]);g.addGetterSetter(T,"fillRadialGradientStartPointX",0);g.addGetterSetter(T,"fillRadialGradientStartPointY",0);g.addComponentsGetterSetter(T,"fillRadialGradientEndPoint",["x","y"]);g.addGetterSetter(T,"fillRadialGradientEndPointX",0);g.addGetterSetter(T,"fillRadialGradientEndPointY",0);g.addGetterSetter(T,"fillPatternRotation",0);g.addGetterSetter(T,"fillRule",void 0,At());g.backCompat(T,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const an="beforeDraw",on="draw",Oi=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],hn=Oi.length;class Et extends at{constructor(t){super(t),this.canvas=new Ct,this.hitCanvas=new Be({pixelRatio:1}),this._waitingForDraw=!1,this.on("visibleChange.konva",this._checkVisibility),this._checkVisibility(),this.on("imageSmoothingEnabledChange.konva",this._setSmoothEnabled),this._setSmoothEnabled()}createPNGStream(){return this.canvas._canvas.createPNGStream()}getCanvas(){return this.canvas}getNativeCanvasElement(){return this.canvas._canvas}getHitCanvas(){return this.hitCanvas}getContext(){return this.getCanvas().getContext()}clear(t){return this.getContext().clear(t),this.getHitCanvas().getContext().clear(t),this}setZIndex(t){super.setZIndex(t);const e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),t<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[t+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement())),this}moveToTop(){w.prototype.moveToTop.call(this);const t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!w.prototype.moveUp.call(this))return!1;const e=this.getStage();return!e||!e.content?!1:(e.content.removeChild(this.getNativeCanvasElement()),this.index<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[this.index+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(w.prototype.moveDown.call(this)){const t=this.getStage();if(t){const e=t.children;t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.insertBefore(this.getNativeCanvasElement(),e[this.index+1].getCanvas()._canvas))}return!0}return!1}moveToBottom(){if(w.prototype.moveToBottom.call(this)){const t=this.getStage();if(t){const e=t.children;t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.insertBefore(this.getNativeCanvasElement(),e[1].getCanvas()._canvas))}return!0}return!1}getLayer(){return this}remove(){const t=this.getNativeCanvasElement();return w.prototype.remove.call(this),t&&t.parentNode&&y._isInDocument(t)&&t.parentNode.removeChild(t),this}getStage(){return this.parent}setSize({width:t,height:e}){return this.canvas.setSize(t,e),this.hitCanvas.setSize(t,e),this._setSmoothEnabled(),this}_validateAdd(t){const e=t.getType();e!=="Group"&&e!=="Shape"&&y.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return t={...t},t.width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=t.x!==void 0?t.x:this.x(),t.y=t.y!==void 0?t.y:this.y(),w.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){this.visible()?this.canvas._canvas.style.display="block":this.canvas._canvas.style.display="none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){y.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){y.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,y.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;let e=1,i=!1;for(;;){for(let s=0;s<hn;s++){const n=Oi[s],r=this._getIntersection({x:t.x+n.x*e,y:t.y+n.y*e}),o=r.shape;if(o)return o;if(i=!!r.antialiased,!r.antialiased)break}if(i)e+=1;else return null}}_getIntersection(t){const e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,s=i[3];if(s===255){const n=y.getHitColorKey(i[0],i[1],i[2]),r=Kt[n];return r?{shape:r}:{antialiased:!0}}else if(s>0)return{antialiased:!0};return{}}drawScene(t,e,i){const s=this.getLayer(),n=t||s&&s.getCanvas();return this._fire(an,{node:this}),this.clearBeforeDraw()&&n.getContext().clear(),at.prototype.drawScene.call(this,n,e,i),this._fire(on,{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),at.prototype.drawHit.call(this,s,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){y.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return y.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;const t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}destroy(){return y.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}Et.prototype.nodeType="Layer";J(Et);g.addGetterSetter(Et,"imageSmoothingEnabled",!0);g.addGetterSetter(Et,"clearBeforeDraw",!0);g.addGetterSetter(Et,"hitGraphEnabled",!0,ht());class He extends Et{constructor(t){super(t),this.listening(!1),y.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}He.prototype.nodeType="FastLayer";J(He);class It extends at{_validateAdd(t){const e=t.getType();e!=="Group"&&e!=="Shape"&&y.throw("You may only add groups and shapes to groups.")}}It.prototype.nodeType="Group";J(It);const ve=function(){return xt.performance&&xt.performance.now?function(){return xt.performance.now()}:function(){return new Date().getTime()}}();class ot{constructor(t,e){this.id=ot.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:ve(),frameRate:0},this.func=t,this.setLayers(e)}setLayers(t){let e=[];return t&&(e=Array.isArray(t)?t:[t]),this.layers=e,this}getLayers(){return this.layers}addLayer(t){const e=this.layers,i=e.length;for(let s=0;s<i;s++)if(e[s]._id===t._id)return!1;return this.layers.push(t),!0}isRunning(){const e=ot.animations,i=e.length;for(let s=0;s<i;s++)if(e[s].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=ve(),ot._addAnimation(this),this}stop(){return ot._removeAnimation(this),this}_updateFrameObject(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(t){this.animations.push(t),this._handleAnimation()}static _removeAnimation(t){const e=t.id,i=this.animations,s=i.length;for(let n=0;n<s;n++)if(i[n].id===e){this.animations.splice(n,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],n=s.layers,r=s.func;s._updateFrameObject(ve());const o=n.length;let h;if(r?h=r.call(s,s.frame)!==!1:h=!0,!!h)for(let l=0;l<o;l++){const c=n[l];c._id!==void 0&&(t[c._id]=c)}}for(const i in t)t.hasOwnProperty(i)&&t[i].batchDraw()}static _animationLoop(){const t=ot;t.animations.length?(t._runFrames(),y.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,y.requestAnimFrame(this._animationLoop))}}ot.animations=[];ot.animIdCounter=0;ot.animRunning=!1;const ln={node:1,duration:1,easing:1,onFinish:1,yoyo:1},cn=1,ei=2,ii=3,si=["fill","stroke","shadowColor"];let dn=0;class un{constructor(t,e,i,s,n,r,o){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=r,this._change=0,this.prevPos=0,this.yoyo=o,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=n-this.begin,this.pause()}fire(t){const e=this[t];e&&e()}setTime(t){t>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return t===void 0&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=ei,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=ii,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const t=this.getTimer()-this._startTime;this.state===ei?this.setTime(t):this.state===ii&&this.setTime(this.duration-t)}pause(){this.state=cn,this.fire("onPause")}getTimer(){return new Date().getTime()}}class ${constructor(t){const e=this,i=t.node,s=i._id,n=t.easing||Zt.Linear,r=!!t.yoyo;let o,h;typeof t.duration>"u"?o=.3:t.duration===0?o=.001:o=t.duration,this.node=i,this._id=dn++;const l=i.getLayer()||(i instanceof E.Stage?i.getLayers():null);l||y.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new ot(function(){e.tween.onEnterFrame()},l),this.tween=new un(h,function(c){e._tweenFunc(c)},n,0,1,o*1e3,r),this._addListeners(),$.attrs[s]||($.attrs[s]={}),$.attrs[s][this._id]||($.attrs[s][this._id]={}),$.tweens[s]||($.tweens[s]={});for(h in t)ln[h]===void 0&&this._addAttr(h,t[h]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){const i=this.node,s=i._id;let n,r,o,h,l;const c=$.tweens[s][t];c&&delete $.attrs[s][c][t];let u=i.getAttr(t);if(y._isArray(e))if(n=[],r=Math.max(e.length,u.length),t==="points"&&e.length!==u.length&&(e.length>u.length?(h=u,u=y._prepareArrayForTween(u,e,i.closed())):(o=e,e=y._prepareArrayForTween(e,u,i.closed()))),t.indexOf("fill")===0)for(let d=0;d<r;d++)if(d%2===0)n.push(e[d]-u[d]);else{const p=y.colorToRGBA(u[d]);l=y.colorToRGBA(e[d]),u[d]=p,n.push({r:l.r-p.r,g:l.g-p.g,b:l.b-p.b,a:l.a-p.a})}else for(let d=0;d<r;d++)n.push(e[d]-u[d]);else si.indexOf(t)!==-1?(u=y.colorToRGBA(u),l=y.colorToRGBA(e),n={r:l.r-u.r,g:l.g-u.g,b:l.b-u.b,a:l.a-u.a}):n=e-u;$.attrs[s][this._id][t]={start:u,diff:n,end:e,trueEnd:o,trueStart:h},$.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=$.attrs[e._id][this._id];let s,n,r,o,h,l,c,u;for(s in i){if(n=i[s],r=n.start,o=n.diff,u=n.end,y._isArray(r))if(h=[],c=Math.max(r.length,u.length),s.indexOf("fill")===0)for(l=0;l<c;l++)l%2===0?h.push((r[l]||0)+o[l]*t):h.push("rgba("+Math.round(r[l].r+o[l].r*t)+","+Math.round(r[l].g+o[l].g*t)+","+Math.round(r[l].b+o[l].b*t)+","+(r[l].a+o[l].a*t)+")");else for(l=0;l<c;l++)h.push((r[l]||0)+o[l]*t);else si.indexOf(s)!==-1?h="rgba("+Math.round(r.r+o.r*t)+","+Math.round(r.g+o.g*t)+","+Math.round(r.b+o.b*t)+","+(r.a+o.a*t)+")":h=r+o*t;e.setAttr(s,h)}}_addListeners(){this.tween.onPlay=()=>{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{const t=this.node,e=$.attrs[t._id][this._id];e.points&&e.points.trueEnd&&t.setAttr("points",e.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{const t=this.node,e=$.attrs[t._id][this._id];e.points&&e.points.trueStart&&t.points(e.points.trueStart),this.onReset&&this.onReset()},this.tween.onUpdate=()=>{this.onUpdate&&this.onUpdate.call(this)}}play(){return this.tween.play(),this}reverse(){return this.tween.reverse(),this}reset(){return this.tween.reset(),this}seek(t){return this.tween.seek(t*1e3),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){const t=this.node._id,e=this._id,i=$.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const s in i)delete $.tweens[t][s];delete $.attrs[t][e],$.tweens[t]&&(Object.keys($.tweens[t]).length===0&&delete $.tweens[t],Object.keys($.attrs[t]).length===0&&delete $.attrs[t])}}$.attrs={};$.tweens={};w.prototype.to=function(a){const t=a.onFinish;a.node=this,a.onFinish=function(){this.destroy(),t&&t()},new $(a).play()};const Zt={BackEaseIn(a,t,e,i){return e*(a/=i)*a*((1.70158+1)*a-1.70158)+t},BackEaseOut(a,t,e,i){return e*((a=a/i-1)*a*((1.70158+1)*a+1.70158)+1)+t},BackEaseInOut(a,t,e,i){let s=1.70158;return(a/=i/2)<1?e/2*(a*a*(((s*=1.525)+1)*a-s))+t:e/2*((a-=2)*a*(((s*=1.525)+1)*a+s)+2)+t},ElasticEaseIn(a,t,e,i,s,n){let r=0;return a===0?t:(a/=i)===1?t+e:(n||(n=i*.3),!s||s<Math.abs(e)?(s=e,r=n/4):r=n/(2*Math.PI)*Math.asin(e/s),-(s*Math.pow(2,10*(a-=1))*Math.sin((a*i-r)*(2*Math.PI)/n))+t)},ElasticEaseOut(a,t,e,i,s,n){let r=0;return a===0?t:(a/=i)===1?t+e:(n||(n=i*.3),!s||s<Math.abs(e)?(s=e,r=n/4):r=n/(2*Math.PI)*Math.asin(e/s),s*Math.pow(2,-10*a)*Math.sin((a*i-r)*(2*Math.PI)/n)+e+t)},ElasticEaseInOut(a,t,e,i,s,n){let r=0;return a===0?t:(a/=i/2)===2?t+e:(n||(n=i*(.3*1.5)),!s||s<Math.abs(e)?(s=e,r=n/4):r=n/(2*Math.PI)*Math.asin(e/s),a<1?-.5*(s*Math.pow(2,10*(a-=1))*Math.sin((a*i-r)*(2*Math.PI)/n))+t:s*Math.pow(2,-10*(a-=1))*Math.sin((a*i-r)*(2*Math.PI)/n)*.5+e+t)},BounceEaseOut(a,t,e,i){return(a/=i)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t},BounceEaseIn(a,t,e,i){return e-Zt.BounceEaseOut(i-a,0,e,i)+t},BounceEaseInOut(a,t,e,i){return a<i/2?Zt.BounceEaseIn(a*2,0,e,i)*.5+t:Zt.BounceEaseOut(a*2-i,0,e,i)*.5+e*.5+t},EaseIn(a,t,e,i){return e*(a/=i)*a+t},EaseOut(a,t,e,i){return-e*(a/=i)*(a-2)+t},EaseInOut(a,t,e,i){return(a/=i/2)<1?e/2*a*a+t:-e/2*(--a*(a-2)-1)+t},StrongEaseIn(a,t,e,i){return e*(a/=i)*a*a*a*a+t},StrongEaseOut(a,t,e,i){return e*((a=a/i-1)*a*a*a*a+1)+t},StrongEaseInOut(a,t,e,i){return(a/=i/2)<1?e/2*a*a*a*a*a+t:e/2*((a-=2)*a*a*a*a+2)+t},Linear(a,t,e,i){return e*a/i+t}},ni=y._assign(E,{Util:y,Transform:rt,Node:w,Container:at,Stage:_e,stages:$t,Layer:Et,FastLayer:He,Group:It,DD:U,Shape:T,shapes:Kt,Animation:ot,Tween:$,Easings:Zt,Context:pe,Canvas:Fe});class gt extends T{_sceneFunc(t){const e=E.getAngle(this.angle()),i=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,i),t.arc(0,0,this.innerRadius(),e,0,!i),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),i=this.clockwise(),s=E.getAngle(i?360-this.angle():this.angle()),n=Math.cos(Math.min(s,Math.PI)),r=1,o=Math.sin(Math.min(Math.max(Math.PI,s),3*Math.PI/2)),h=Math.sin(Math.min(s,Math.PI/2)),l=n*(n>0?t:e),c=r*e,u=o*(o>0?t:e),d=h*(h>0?e:t);return{x:l,y:i?-1*d:u,width:c-l,height:d-u}}}gt.prototype._centroid=!0;gt.prototype.className="Arc";gt.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"];J(gt);g.addGetterSetter(gt,"innerRadius",0,k());g.addGetterSetter(gt,"outerRadius",0,k());g.addGetterSetter(gt,"angle",0,k());g.addGetterSetter(gt,"clockwise",!1,ht());function Me(a,t,e,i,s,n,r){const o=Math.sqrt(Math.pow(e-a,2)+Math.pow(i-t,2)),h=Math.sqrt(Math.pow(s-e,2)+Math.pow(n-i,2)),l=r*o/(o+h),c=r*h/(o+h),u=e-l*(s-a),d=i-l*(n-t),p=e+c*(s-a),f=i+c*(n-t);return[u,d,p,f]}function ri(a,t){const e=a.length,i=[];for(let s=2;s<e-2;s+=2){const n=Me(a[s-2],a[s-1],a[s],a[s+1],a[s+2],a[s+3],t);isNaN(n[0])||(i.push(n[0]),i.push(n[1]),i.push(a[s]),i.push(a[s+1]),i.push(n[2]),i.push(n[3]))}return i}function fn(a){const t=[[a[0],a[2],a[4],a[6]],[a[1],a[3],a[5],a[7]]],e=[];for(const i of t){const s=-3*i[0]+9*i[1]-9*i[2]+3*i[3];if(s!==0){const n=6*i[0]-12*i[1]+6*i[2],r=-3*i[0]+3*i[1],o=n*n-4*s*r;if(o>=0){const h=Math.sqrt(o);e.push((-n+h)/(2*s)),e.push((-n-h)/(2*s))}}}return e.filter(i=>i>0&&i<1).flatMap(i=>t.map(s=>{const n=1-i;return n*n*n*s[0]+3*n*n*i*s[1]+3*n*i*i*s[2]+i*i*i*s[3]}))}class pt extends T{constructor(t){super(t),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(t){const e=this.points(),i=e.length,s=this.tension(),n=this.closed(),r=this.bezier();if(!i)return;let o=0;if(t.beginPath(),t.moveTo(e[0],e[1]),s!==0&&i>4){const h=this.getTensionPoints(),l=h.length;for(o=n?0:4,n||t.quadraticCurveTo(h[0],h[1],h[2],h[3]);o<l-2;)t.bezierCurveTo(h[o++],h[o++],h[o++],h[o++],h[o++],h[o++]);n||t.quadraticCurveTo(h[l-2],h[l-1],e[i-2],e[i-1])}else if(r)for(o=2;o<i;)t.bezierCurveTo(e[o++],e[o++],e[o++],e[o++],e[o++],e[o++]);else for(o=2;o<i;o+=2)t.lineTo(e[o],e[o+1]);n?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():ri(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=Me(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),n=Me(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),r=ri(t,i);return[s[2],s[3]].concat(r).concat([n[0],n[1],t[e-2],t[e-1],n[2],n[3],s[0],s[1],t[0],t[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let t=this.points();if(t.length<4)return{x:t[0]||0,y:t[1]||0,width:0,height:0};this.tension()!==0?t=[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.bezier()?t=[t[0],t[1],...fn(this.points()),t[t.length-2],t[t.length-1]]:t=this.points();let e=t[0],i=t[0],s=t[1],n=t[1],r,o;for(let h=0;h<t.length/2;h++)r=t[h*2],o=t[h*2+1],e=Math.min(e,r),i=Math.max(i,r),s=Math.min(s,o),n=Math.max(n,o);return{x:e,y:s,width:i-e,height:n-s}}}pt.prototype.className="Line";pt.prototype._attrsAffectingSize=["points","bezier","tension"];J(pt);g.addGetterSetter(pt,"closed",!1);g.addGetterSetter(pt,"bezier",!1);g.addGetterSetter(pt,"tension",0,k());g.addGetterSetter(pt,"points",[],Es());const gn=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],pn=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],mn=[[1],[1,1],[1,2,1],[1,3,3,1]],ai=(a,t,e)=>{let i,s;const r=e/2;i=0;for(let o=0;o<20;o++)s=r*gn[20][o]+r,i+=pn[20][o]*_n(a,t,s);return r*i},oi=(a,t,e)=>{e===void 0&&(e=1);const i=a[0]-2*a[1]+a[2],s=t[0]-2*t[1]+t[2],n=2*a[1]-2*a[0],r=2*t[1]-2*t[0],o=4*(i*i+s*s),h=4*(i*n+s*r),l=n*n+r*r;if(o===0)return e*Math.sqrt(Math.pow(a[2]-a[0],2)+Math.pow(t[2]-t[0],2));const c=h/(2*o),u=l/o,d=e+c,p=u-c*c,f=d*d+p>0?Math.sqrt(d*d+p):0,m=c*c+p>0?Math.sqrt(c*c+p):0,_=c+Math.sqrt(c*c+p)!==0?p*Math.log(Math.abs((d+f)/(c+m))):0;return Math.sqrt(o)/2*(d*f-c*m+_)};function _n(a,t,e){const i=Re(1,e,a),s=Re(1,e,t),n=i*i+s*s;return Math.sqrt(n)}const Re=(a,t,e)=>{const i=e.length-1;let s,n;if(i===0)return 0;if(a===0){n=0;for(let r=0;r<=i;r++)n+=mn[i][r]*Math.pow(1-t,i-r)*Math.pow(t,r)*e[r];return n}else{s=new Array(i);for(let r=0;r<i;r++)s[r]=i*(e[r+1]-e[r]);return Re(a-1,t,s)}},hi=(a,t,e)=>{let i=1,s=a/t,n=(a-e(s))/t,r=0;for(;i>.001;){const o=e(s+n),h=Math.abs(a-o)/t;if(h<i)i=h,s+=n;else{const l=e(s-n),c=Math.abs(a-l)/t;c<i?(i=c,s-=n):n/=2}if(r++,r>500)break}return s};class K extends T{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=K.parsePathData(this.data()),this.pathLength=K.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const n=e[s].command,r=e[s].points;switch(n){case"L":t.lineTo(r[0],r[1]);break;case"M":t.moveTo(r[0],r[1]);break;case"C":t.bezierCurveTo(r[0],r[1],r[2],r[3],r[4],r[5]);break;case"Q":t.quadraticCurveTo(r[0],r[1],r[2],r[3]);break;case"A":const o=r[0],h=r[1],l=r[2],c=r[3],u=r[4],d=r[5],p=r[6],f=r[7],m=l>c?l:c,_=l>c?1:l/c,C=l>c?c/l:1;t.translate(o,h),t.rotate(p),t.scale(_,C),t.arc(0,0,m,u,u+d,1-f),t.scale(1/_,1/C),t.rotate(-p),t.translate(-o,-h);break;case"z":i=!0,t.closePath();break}}!i&&!this.hasFill()?t.strokeShape(this):t.fillStrokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(h){if(h.command==="A"){const l=h.points[4],c=h.points[5],u=h.points[4]+c;let d=Math.PI/180;if(Math.abs(l-u)<d&&(d=Math.abs(l-u)),c<0)for(let p=l-d;p>u;p-=d){const f=K.getPointOnEllipticalArc(h.points[0],h.points[1],h.points[2],h.points[3],p,0);t.push(f.x,f.y)}else for(let p=l+d;p<u;p+=d){const f=K.getPointOnEllipticalArc(h.points[0],h.points[1],h.points[2],h.points[3],p,0);t.push(f.x,f.y)}}else if(h.command==="C")for(let l=0;l<=1;l+=.01){const c=K.getPointOnCubicBezier(l,h.start.x,h.start.y,h.points[0],h.points[1],h.points[2],h.points[3],h.points[4],h.points[5]);t.push(c.x,c.y)}else t=t.concat(h.points)});let e=t[0],i=t[0],s=t[1],n=t[1],r,o;for(let h=0;h<t.length/2;h++)r=t[h*2],o=t[h*2+1],isNaN(r)||(e=Math.min(e,r),i=Math.max(i,r)),isNaN(o)||(s=Math.min(s,o),n=Math.max(n,o));return{x:e,y:s,width:i-e,height:n-s}}getLength(){return this.pathLength}getPointAtLength(t){return K.getPointAtLengthOfDataArray(t,this.dataArray)}static getLineLength(t,e,i,s){return Math.sqrt((i-t)*(i-t)+(s-e)*(s-e))}static getPathLength(t){let e=0;for(let i=0;i<t.length;++i)e+=t[i].pathLength;return e}static getPointAtLengthOfDataArray(t,e){let i,s=0,n=e.length;if(!n)return null;for(;s<n&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===n)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01)return e[s].command==="M"?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y};const r=e[s],o=r.points;switch(r.command){case"L":return K.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return K.getPointOnCubicBezier(hi(t,K.getPathLength(e),m=>ai([r.start.x,o[0],o[2],o[4]],[r.start.y,o[1],o[3],o[5]],m)),r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return K.getPointOnQuadraticBezier(hi(t,K.getPathLength(e),m=>oi([r.start.x,o[0],o[2]],[r.start.y,o[1],o[3]],m)),r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":const h=o[0],l=o[1],c=o[2],u=o[3],d=o[5],p=o[6];let f=o[4];return f+=d*t/r.pathLength,K.getPointOnEllipticalArc(h,l,c,u,f,p)}return null}static getPointOnLine(t,e,i,s,n,r,o){r=r??e,o=o??i;const h=this.getLineLength(e,i,s,n);if(h<1e-10)return{x:e,y:i};if(s===e)return{x:r,y:o+(n>i?t:-t)};const l=(n-i)/(s-e),c=Math.sqrt(t*t/(1+l*l))*(s<e?-1:1),u=l*c;if(Math.abs(o-i-l*(r-e))<1e-10)return{x:r+c,y:o+u};const d=((r-e)*(s-e)+(o-i)*(n-i))/(h*h),p=e+d*(s-e),f=i+d*(n-i),m=this.getLineLength(r,o,p,f),_=Math.sqrt(t*t-m*m),C=Math.sqrt(_*_/(1+l*l))*(s<e?-1:1),S=l*C;return{x:p+C,y:f+S}}static getPointOnCubicBezier(t,e,i,s,n,r,o,h,l){function c(_){return _*_*_}function u(_){return 3*_*_*(1-_)}function d(_){return 3*_*(1-_)*(1-_)}function p(_){return(1-_)*(1-_)*(1-_)}const f=h*c(t)+r*u(t)+s*d(t)+e*p(t),m=l*c(t)+o*u(t)+n*d(t)+i*p(t);return{x:f,y:m}}static getPointOnQuadraticBezier(t,e,i,s,n,r,o){function h(p){return p*p}function l(p){return 2*p*(1-p)}function c(p){return(1-p)*(1-p)}const u=r*h(t)+s*l(t)+e*c(t),d=o*h(t)+n*l(t)+i*c(t);return{x:u,y:d}}static getPointOnEllipticalArc(t,e,i,s,n,r){const o=Math.cos(r),h=Math.sin(r),l={x:i*Math.cos(n),y:s*Math.sin(n)};return{x:t+(l.x*o-l.y*h),y:e+(l.x*h+l.y*o)}}static parsePathData(t){if(!t)return[];let e=t;const i=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];e=e.replace(new RegExp(" ","g"),",");for(let u=0;u<i.length;u++)e=e.replace(new RegExp(i[u],"g"),"|"+i[u]);const s=e.split("|"),n=[],r=[];let o=0,h=0;const l=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let c;for(let u=1;u<s.length;u++){let d=s[u],p=d.charAt(0);for(d=d.slice(1),r.length=0;c=l.exec(d);)r.push(c[0]);let f=[],m=p==="A"||p==="a"?0:-1;for(let _=0,C=r.length;_<C;_++){const S=r[_];if(S==="00"){f.push(0,0),m>=0&&(m+=2,m>=7&&(m-=7));continue}if(m>=0){if(m===3){if(/^[01]{2}\d+(?:\.\d+)?$/.test(S)){f.push(parseInt(S[0],10)),f.push(parseInt(S[1],10)),f.push(parseFloat(S.slice(2))),m+=3,m>=7&&(m-=7);continue}if(S==="11"||S==="10"||S==="01"){f.push(parseInt(S[0],10)),f.push(parseInt(S[1],10)),m+=2,m>=7&&(m-=7);continue}if(S==="0"||S==="1"){f.push(parseInt(S,10)),m+=1,m>=7&&(m-=7);continue}}else if(m===4){if(/^[01]\d+(?:\.\d+)?$/.test(S)){f.push(parseInt(S[0],10)),f.push(parseFloat(S.slice(1))),m+=2,m>=7&&(m-=7);continue}if(S==="0"||S==="1"){f.push(parseInt(S,10)),m+=1,m>=7&&(m-=7);continue}}const b=parseFloat(S);isNaN(b)?f.push(0):f.push(b),m+=1,m>=7&&(m-=7)}else{const b=parseFloat(S);isNaN(b)?f.push(0):f.push(b)}}for(;f.length>0&&!isNaN(f[0]);){let _="",C=[];const S=o,b=h;let v,P,x,D,R,G,I,H,F,W;switch(p){case"l":o+=f.shift(),h+=f.shift(),_="L",C.push(o,h);break;case"L":o=f.shift(),h=f.shift(),C.push(o,h);break;case"m":const N=f.shift(),B=f.shift();if(o+=N,h+=B,_="M",n.length>2&&n[n.length-1].command==="z"){for(let L=n.length-2;L>=0;L--)if(n[L].command==="M"){o=n[L].points[0]+N,h=n[L].points[1]+B;break}}C.push(o,h),p="l";break;case"M":o=f.shift(),h=f.shift(),_="M",C.push(o,h),p="L";break;case"h":o+=f.shift(),_="L",C.push(o,h);break;case"H":o=f.shift(),_="L",C.push(o,h);break;case"v":h+=f.shift(),_="L",C.push(o,h);break;case"V":h=f.shift(),_="L",C.push(o,h);break;case"C":C.push(f.shift(),f.shift(),f.shift(),f.shift()),o=f.shift(),h=f.shift(),C.push(o,h);break;case"c":C.push(o+f.shift(),h+f.shift(),o+f.shift(),h+f.shift()),o+=f.shift(),h+=f.shift(),_="C",C.push(o,h);break;case"S":P=o,x=h,v=n[n.length-1],v.command==="C"&&(P=o+(o-v.points[2]),x=h+(h-v.points[3])),C.push(P,x,f.shift(),f.shift()),o=f.shift(),h=f.shift(),_="C",C.push(o,h);break;case"s":P=o,x=h,v=n[n.length-1],v.command==="C"&&(P=o+(o-v.points[2]),x=h+(h-v.points[3])),C.push(P,x,o+f.shift(),h+f.shift()),o+=f.shift(),h+=f.shift(),_="C",C.push(o,h);break;case"Q":C.push(f.shift(),f.shift()),o=f.shift(),h=f.shift(),C.push(o,h);break;case"q":C.push(o+f.shift(),h+f.shift()),o+=f.shift(),h+=f.shift(),_="Q",C.push(o,h);break;case"T":P=o,x=h,v=n[n.length-1],v.command==="Q"&&(P=o+(o-v.points[0]),x=h+(h-v.points[1])),o=f.shift(),h=f.shift(),_="Q",C.push(P,x,o,h);break;case"t":P=o,x=h,v=n[n.length-1],v.command==="Q"&&(P=o+(o-v.points[0]),x=h+(h-v.points[1])),o+=f.shift(),h+=f.shift(),_="Q",C.push(P,x,o,h);break;case"A":D=f.shift(),R=f.shift(),G=f.shift(),I=f.shift(),H=f.shift(),F=o,W=h,o=f.shift(),h=f.shift(),_="A",C=this.convertEndpointToCenterParameterization(F,W,o,h,I,H,D,R,G);break;case"a":D=f.shift(),R=f.shift(),G=f.shift(),I=f.shift(),H=f.shift(),F=o,W=h,o+=f.shift(),h+=f.shift(),_="A",C=this.convertEndpointToCenterParameterization(F,W,o,h,I,H,D,R,G);break}n.push({command:_||p,points:C,start:{x:S,y:b},pathLength:this.calcLength(S,b,_||p,C)})}(p==="z"||p==="Z")&&n.push({command:"z",points:[],start:void 0,pathLength:0})}return n}static calcLength(t,e,i,s){let n,r,o,h;const l=K;switch(i){case"L":return l.getLineLength(t,e,s[0],s[1]);case"C":return ai([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return oi([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":n=0;const c=s[4],u=s[5],d=s[4]+u;let p=Math.PI/180;if(Math.abs(c-d)<p&&(p=Math.abs(c-d)),r=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],c,0),u<0)for(h=c-p;h>d;h-=p)o=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],h,0),n+=l.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(h=c+p;h<d;h+=p)o=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],h,0),n+=l.getLineLength(r.x,r.y,o.x,o.y),r=o;return o=l.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),n+=l.getLineLength(r.x,r.y,o.x,o.y),n}return 0}static convertEndpointToCenterParameterization(t,e,i,s,n,r,o,h,l){const c=l*(Math.PI/180),u=Math.cos(c)*(t-i)/2+Math.sin(c)*(e-s)/2,d=-1*Math.sin(c)*(t-i)/2+Math.cos(c)*(e-s)/2,p=u*u/(o*o)+d*d/(h*h);p>1&&(o*=Math.sqrt(p),h*=Math.sqrt(p));let f=Math.sqrt((o*o*(h*h)-o*o*(d*d)-h*h*(u*u))/(o*o*(d*d)+h*h*(u*u)));n===r&&(f*=-1),isNaN(f)&&(f=0);const m=f*o*d/h,_=f*-h*u/o,C=(t+i)/2+Math.cos(c)*m-Math.sin(c)*_,S=(e+s)/2+Math.sin(c)*m+Math.cos(c)*_,b=function(I){return Math.sqrt(I[0]*I[0]+I[1]*I[1])},v=function(I,H){return(I[0]*H[0]+I[1]*H[1])/(b(I)*b(H))},P=function(I,H){return(I[0]*H[1]<I[1]*H[0]?-1:1)*Math.acos(v(I,H))},x=P([1,0],[(u-m)/o,(d-_)/h]),D=[(u-m)/o,(d-_)/h],R=[(-1*u-m)/o,(-1*d-_)/h];let G=P(D,R);return v(D,R)<=-1&&(G=Math.PI),v(D,R)>=1&&(G=0),r===0&&G>0&&(G=G-2*Math.PI),r===1&&G<0&&(G=G+2*Math.PI),[C,S,o,h,x,G,c,r]}}K.prototype.className="Path";K.prototype._attrsAffectingSize=["data"];J(K);g.addGetterSetter(K,"data");class Pt extends pt{_sceneFunc(t){super._sceneFunc(t);const e=Math.PI*2,i=this.points();let s=i;const n=this.tension()!==0&&i.length>4;n&&(s=this.getTensionPoints());const r=this.pointerLength(),o=i.length;let h,l;if(n){const d=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[o-2],i[o-1]],p=K.calcLength(s[s.length-4],s[s.length-3],"C",d),f=K.getPointOnQuadraticBezier(Math.min(1,1-r/p),d[0],d[1],d[2],d[3],d[4],d[5]);h=i[o-2]-f.x,l=i[o-1]-f.y}else h=i[o-2]-i[o-4],l=i[o-1]-i[o-3];const c=(Math.atan2(l,h)+e)%e,u=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[o-2],i[o-1]),t.rotate(c),t.moveTo(0,0),t.lineTo(-r,u/2),t.lineTo(-r,-u/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),n?(h=(s[0]+s[2])/2-i[0],l=(s[1]+s[3])/2-i[1]):(h=i[2]-i[0],l=i[3]-i[1]),t.rotate((Math.atan2(-l,-h)+e)%e),t.moveTo(0,0),t.lineTo(-r,u/2),t.lineTo(-r,-u/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){const e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x,y:t.y-e,width:t.width,height:t.height+e*2}}}Pt.prototype.className="Arrow";J(Pt);g.addGetterSetter(Pt,"pointerLength",10,k());g.addGetterSetter(Pt,"pointerWidth",10,k());g.addGetterSetter(Pt,"pointerAtBeginning",!1);g.addGetterSetter(Pt,"pointerAtEnding",!0);class Ot extends T{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,Math.PI*2,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}Ot.prototype._centroid=!0;Ot.prototype.className="Circle";Ot.prototype._attrsAffectingSize=["radius"];J(Ot);g.addGetterSetter(Ot,"radius",0,k());class bt extends T{_sceneFunc(t){const e=this.radiusX(),i=this.radiusY();t.beginPath(),t.save(),e!==i&&t.scale(1,i/e),t.arc(0,0,e,0,Math.PI*2,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.radiusX()*2}getHeight(){return this.radiusY()*2}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}bt.prototype.className="Ellipse";bt.prototype._centroid=!0;bt.prototype._attrsAffectingSize=["radiusX","radiusY"];J(bt);g.addComponentsGetterSetter(bt,"radius",["x","y"]);g.addGetterSetter(bt,"radiusX",0,k());g.addGetterSetter(bt,"radiusY",0,k());let lt=class Fi extends T{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",e=>{this._removeImageLoad(e.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&t.readyState===4||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){const t=!!this.cornerRadius(),e=this.hasShadow();return t&&e?!0:super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),n=this.attrs.image;let r;if(n){const o=this.attrs.cropWidth,h=this.attrs.cropHeight;o&&h?r=[n,this.cropX(),this.cropY(),o,h,0,0,e,i]:r=[n,0,0,e,i]}(this.hasFill()||this.hasStroke()||s)&&(t.beginPath(),s?y.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),n&&(s&&t.clip(),t.drawImage.apply(t,r))}_hitFunc(t){const e=this.width(),i=this.height(),s=this.cornerRadius();t.beginPath(),s?y.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e,i;return(i=(t=this.attrs.width)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.width)!==null&&i!==void 0?i:0}getHeight(){var t,e,i;return(i=(t=this.attrs.height)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.height)!==null&&i!==void 0?i:0}static fromURL(t,e,i=null){const s=y.createImageElement();s.onload=function(){const n=new Fi({image:s});e(n)},s.onerror=i,s.crossOrigin="Anonymous",s.src=t}};lt.prototype.className="Image";lt.prototype._attrsAffectingSize=["image"];J(lt);g.addGetterSetter(lt,"cornerRadius",0,me(4));g.addGetterSetter(lt,"image");g.addComponentsGetterSetter(lt,"crop",["x","y","width","height"]);g.addGetterSetter(lt,"cropX",0,k());g.addGetterSetter(lt,"cropY",0,k());g.addGetterSetter(lt,"cropWidth",0,k());g.addGetterSetter(lt,"cropHeight",0,k());const Bi=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],yn="Change.konva",Cn="none",Le="up",De="right",Ge="down",Ie="left",Sn=Bi.length;class We extends It{constructor(t){super(t),this.on("add.konva",function(e){this._addListeners(e.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){let e=this,i;const s=function(){e._sync()};for(i=0;i<Sn;i++)t.on(Bi[i]+yn,s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t=this.getText(),e=this.getTag(),i,s,n,r,o,h,l;if(t&&e){switch(i=t.width(),s=t.height(),n=e.pointerDirection(),r=e.pointerWidth(),l=e.pointerHeight(),o=0,h=0,n){case Le:o=i/2,h=-1*l;break;case De:o=i+r,h=s/2;break;case Ge:o=i/2,h=s+l;break;case Ie:o=-1*r,h=s/2;break}e.setAttrs({x:-1*o,y:-1*h,width:i,height:s}),t.setAttrs({x:-1*o,y:-1*h})}}}We.prototype.className="Label";J(We);class Mt extends T{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),n=this.pointerWidth(),r=this.pointerHeight(),o=this.cornerRadius();let h=0,l=0,c=0,u=0;typeof o=="number"?h=l=c=u=Math.min(o,e/2,i/2):(h=Math.min(o[0]||0,e/2,i/2),l=Math.min(o[1]||0,e/2,i/2),u=Math.min(o[2]||0,e/2,i/2),c=Math.min(o[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(h,0),s===Le&&(t.lineTo((e-n)/2,0),t.lineTo(e/2,-1*r),t.lineTo((e+n)/2,0)),t.lineTo(e-l,0),t.arc(e-l,l,l,Math.PI*3/2,0,!1),s===De&&(t.lineTo(e,(i-r)/2),t.lineTo(e+n,i/2),t.lineTo(e,(i+r)/2)),t.lineTo(e,i-u),t.arc(e-u,i-u,u,0,Math.PI/2,!1),s===Ge&&(t.lineTo((e+n)/2,i),t.lineTo(e/2,i+r),t.lineTo((e-n)/2,i)),t.lineTo(c,i),t.arc(c,i-c,c,Math.PI/2,Math.PI,!1),s===Ie&&(t.lineTo(0,(i+r)/2),t.lineTo(-1*n,i/2),t.lineTo(0,(i-r)/2)),t.lineTo(0,h),t.arc(h,h,h,Math.PI,Math.PI*3/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),n=this.pointerDirection(),r=this.width(),o=this.height();return n===Le?(e-=s,o+=s):n===Ge?o+=s:n===Ie?(t-=i*1.5,r+=i):n===De&&(r+=i*1.5),{x:t,y:e,width:r,height:o}}}Mt.prototype.className="Tag";J(Mt);g.addGetterSetter(Mt,"pointerDirection",Cn);g.addGetterSetter(Mt,"pointerWidth",0,k());g.addGetterSetter(Mt,"pointerHeight",0,k());g.addGetterSetter(Mt,"cornerRadius",0,me(4));class Qt extends T{_sceneFunc(t){const e=this.cornerRadius(),i=this.width(),s=this.height();t.beginPath(),e?y.drawRoundedRectPath(t,i,s,e):t.rect(0,0,i,s),t.closePath(),t.fillStrokeShape(this)}}Qt.prototype.className="Rect";J(Qt);g.addGetterSetter(Qt,"cornerRadius",0,me(4));class vt extends T{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),n=this.cornerRadius();if(t.beginPath(),n)y.drawRoundedPolygonPath(t,e,s,i,n);else{t.moveTo(e[0].x,e[0].y);for(let r=1;r<e.length;r++)t.lineTo(e[r].x,e[r].y)}t.closePath(),t.fillStrokeShape(this)}_getPoints(){const t=this.attrs.sides,e=this.attrs.radius||0,i=[];for(let s=0;s<t;s++)i.push({x:e*Math.sin(s*2*Math.PI/t),y:-1*e*Math.cos(s*2*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].x,s=t[0].y,n=t[0].y;return t.forEach(r=>{e=Math.min(e,r.x),i=Math.max(i,r.x),s=Math.min(s,r.y),n=Math.max(n,r.y)}),{x:e,y:s,width:i-e,height:n-s}}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}vt.prototype.className="RegularPolygon";vt.prototype._centroid=!0;vt.prototype._attrsAffectingSize=["radius"];J(vt);g.addGetterSetter(vt,"radius",0,k());g.addGetterSetter(vt,"sides",0,k());g.addGetterSetter(vt,"cornerRadius",0,me(4));const li=Math.PI*2;class Rt extends T{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,li,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),li,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}Rt.prototype.className="Ring";Rt.prototype._centroid=!0;Rt.prototype._attrsAffectingSize=["innerRadius","outerRadius"];J(Rt);g.addGetterSetter(Rt,"innerRadius",0,k());g.addGetterSetter(Rt,"outerRadius",0,k());class dt extends T{constructor(t){super(t),this._updated=!0,this.anim=new ot(()=>{const e=this._updated;return this._updated=!1,e}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(t){const e=this.animation(),i=this.frameIndex(),s=i*4,n=this.animations()[e],r=this.frameOffsets(),o=n[s+0],h=n[s+1],l=n[s+2],c=n[s+3],u=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,l,c),t.closePath(),t.fillStrokeShape(this)),u)if(r){const d=r[e],p=i*2;t.drawImage(u,o,h,l,c,d[p+0],d[p+1],l,c)}else t.drawImage(u,o,h,l,c,0,0,l,c)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=i*4,n=this.animations()[e],r=this.frameOffsets(),o=n[s+2],h=n[s+3];if(t.beginPath(),r){const l=r[e],c=i*2;t.rect(l[c+0],l[c+1],o,h)}else t.rect(0,0,o,h);t.closePath(),t.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){const t=this;this.interval=setInterval(function(){t._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;const t=this.getLayer();this.anim.setLayers(t),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){const t=this.frameIndex(),e=this.animation(),i=this.animations(),s=i[e],n=s.length/4;t<n-1?this.frameIndex(t+1):this.frameIndex(0)}}dt.prototype.className="Sprite";J(dt);g.addGetterSetter(dt,"animation");g.addGetterSetter(dt,"animations");g.addGetterSetter(dt,"frameOffsets");g.addGetterSetter(dt,"image");g.addGetterSetter(dt,"frameIndex",0,k());g.addGetterSetter(dt,"frameRate",17,k());g.backCompat(dt,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class Tt extends T{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let n=1;n<s*2;n++){const r=n%2===0?i:e,o=r*Math.sin(n*Math.PI/s),h=-1*r*Math.cos(n*Math.PI/s);t.lineTo(o,h)}t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}Tt.prototype.className="Star";Tt.prototype._centroid=!0;Tt.prototype._attrsAffectingSize=["innerRadius","outerRadius"];J(Tt);g.addGetterSetter(Tt,"numPoints",5,k());g.addGetterSetter(Tt,"innerRadius",0,k());g.addGetterSetter(Tt,"outerRadius",0,k());function yt(a){return[...a].reduce((t,e,i,s)=>{if(new RegExp("\\p{Emoji}","u").test(e)){const n=s[i+1];n&&new RegExp("\\p{Emoji_Modifier}|\\u200D","u").test(n)?(t.push(e+n),s[i+1]=""):t.push(e)}else new RegExp("\\p{Regional_Indicator}{2}","u").test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&new RegExp("\\p{Mn}|\\p{Me}|\\p{Mc}","u").test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}const Dt="auto",bn="center",Ni="inherit",Ht="justify",vn="Change.konva",Tn="2d",ci="-",zi="left",wn="text",xn="Text",kn="top",An="bottom",di="middle",Hi="normal",En="px ",oe=" ",Pn="right",ui="rtl",Mn="word",Rn="char",fi="none",Te="…",Wi=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],Ln=Wi.length;function Dn(a){return a.split(",").map(t=>{t=t.trim();const e=t.indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t}).join(", ")}let he;function we(){return he||(he=y.createCanvasElement().getContext(Tn),he)}function Gn(a){a.fillText(this._partialText,this._partialTextX,this._partialTextY)}function In(a){a.setAttr("miterLimit",2),a.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function On(a){return a=a||{},!a.fillLinearGradientColorStops&&!a.fillRadialGradientColorStops&&!a.fillPatternImage&&(a.fill=a.fill||"black"),a}class Z extends T{constructor(t){super(On(t)),this._partialTextX=0,this._partialTextY=0;for(let e=0;e<Ln;e++)this.on(Wi[e]+vn,this._setTextData);this._setTextData()}_sceneFunc(t){var e,i;const s=this.textArr,n=s.length;if(!this.text())return;let r=this.padding(),o=this.fontSize(),h=this.lineHeight()*o,l=this.verticalAlign(),c=this.direction(),u=0,d=this.align(),p=this.getWidth(),f=this.letterSpacing(),m=this.charRenderFunc(),_=this.fill(),C=this.textDecoration(),S=this.underlineOffset(),b=C.indexOf("underline")!==-1,v=C.indexOf("line-through")!==-1,P;c=c===Ni?t.direction:c;let x=h/2,D=di;if(!E.legacyTextRendering){const R=this.measureSize("M");D="alphabetic";const G=(e=R.fontBoundingBoxAscent)!==null&&e!==void 0?e:R.actualBoundingBoxAscent,I=(i=R.fontBoundingBoxDescent)!==null&&i!==void 0?i:R.actualBoundingBoxDescent;x=(G-I)/2+h/2}for(c===ui&&t.setAttr("direction",c),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",D),t.setAttr("textAlign",zi),l===di?u=(this.getHeight()-n*h-r*2)/2:l===An&&(u=this.getHeight()-n*h-r*2),t.translate(r,u+r),P=0;P<n;P++){let R=0,G=0;const I=s[P],H=I.text,F=I.width,W=I.lastInParagraph;if(t.save(),d===Pn?R+=p-F-r*2:d===bn&&(R+=(p-F-r*2)/2),b){t.save(),t.beginPath();const B=S??(E.legacyTextRendering?Math.round(o/2):Math.round(o/4)),L=R,q=x+G+B;t.moveTo(L,q);const O=d===Ht&&!W?p-r*2:F;t.lineTo(L+Math.round(O),q),t.lineWidth=o/15;const V=this._getLinearGradient();t.strokeStyle=V||_,t.stroke(),t.restore()}const N=R;if(c!==ui&&(f!==0||d===Ht||m)){const B=H.split(" ").length-1,L=yt(H);for(let q=0;q<L.length;q++){const O=L[q];if(O===" "&&!W&&d===Ht&&(R+=(p-r*2-F)/B),this._partialTextX=R,this._partialTextY=x+G,this._partialText=O,m){t.save();const it=s.slice(0,P).reduce((et,nt)=>et+yt(nt.text).length,0),Y=q+it;m({char:O,index:Y,x:R,y:x+G,lineIndex:P,column:q,isLastInLine:W,width:this.measureSize(O).width,context:t})}t.fillStrokeShape(this),m&&t.restore(),R+=this.measureSize(O).width+f}}else f!==0&&t.setAttr("letterSpacing",`${f}px`),this._partialTextX=R,this._partialTextY=x+G,this._partialText=H,t.fillStrokeShape(this);if(v){t.save(),t.beginPath();const B=E.legacyTextRendering?0:-Math.round(o/4),L=N;t.moveTo(L,x+G+B);const q=d===Ht&&!W?p-r*2:F;t.lineTo(L+Math.round(q),x+G+B),t.lineWidth=o/15;const O=this._getLinearGradient();t.strokeStyle=O||_,t.stroke(),t.restore()}t.restore(),n>1&&(x+=h)}}_hitFunc(t){const e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}setText(t){const e=y._isString(t)?t:t==null?"":t+"";return this._setAttr(wn,e),this}getWidth(){return this.attrs.width===Dt||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===Dt||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return y.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i,s,n,r,o,h,l,c,u,d;let p=we(),f=this.fontSize(),m;p.save(),p.font=this._getContextFont(),m=p.measureText(t),p.restore();const _=f/100;return{actualBoundingBoxAscent:(e=m.actualBoundingBoxAscent)!==null&&e!==void 0?e:71.58203125*_,actualBoundingBoxDescent:(i=m.actualBoundingBoxDescent)!==null&&i!==void 0?i:0,actualBoundingBoxLeft:(s=m.actualBoundingBoxLeft)!==null&&s!==void 0?s:-7.421875*_,actualBoundingBoxRight:(n=m.actualBoundingBoxRight)!==null&&n!==void 0?n:75.732421875*_,alphabeticBaseline:(r=m.alphabeticBaseline)!==null&&r!==void 0?r:0,emHeightAscent:(o=m.emHeightAscent)!==null&&o!==void 0?o:100*_,emHeightDescent:(h=m.emHeightDescent)!==null&&h!==void 0?h:-20*_,fontBoundingBoxAscent:(l=m.fontBoundingBoxAscent)!==null&&l!==void 0?l:91*_,fontBoundingBoxDescent:(c=m.fontBoundingBoxDescent)!==null&&c!==void 0?c:21*_,hangingBaseline:(u=m.hangingBaseline)!==null&&u!==void 0?u:72.80000305175781*_,ideographicBaseline:(d=m.ideographicBaseline)!==null&&d!==void 0?d:-21*_,width:m.width,height:f}}_getContextFont(){return this.fontStyle()+oe+this.fontVariant()+oe+(this.fontSize()+En)+Dn(this.fontFamily())}_addTextLine(t){this.align()===Ht&&(t=t.trim());const i=this._getTextWidth(t);return this.textArr.push({text:t,width:i,lastInParagraph:!1})}_getTextWidth(t){const e=this.letterSpacing(),i=t.length;return we().measureText(t).width+e*i}_setTextData(){let t=this.text().split(`
|
|
15
|
+
`),e=+this.fontSize(),i=0,s=this.lineHeight()*e,n=this.attrs.width,r=this.attrs.height,o=n!==Dt&&n!==void 0,h=r!==Dt&&r!==void 0,l=this.padding(),c=n-l*2,u=r-l*2,d=0,p=this.wrap(),f=p!==fi,m=p!==Rn&&f,_=this.ellipsis();this.textArr=[],we().font=this._getContextFont();const C=_?this._getTextWidth(Te):0;for(let S=0,b=t.length;S<b;++S){let v=t[S],P=this._getTextWidth(v);if(o&&P>c)for(;v.length>0;){let x=0,D=yt(v).length,R="",G=0;for(;x<D;){const I=x+D>>>1,H=yt(v),F=H.slice(0,I+1).join(""),W=this._getTextWidth(F);(_&&h&&d+s>u?W+C:W)<=c?(x=I+1,R=F,G=W):D=I}if(R){if(m){const F=yt(v),W=yt(R),N=F[W.length],B=N===oe||N===ci;let L;if(B&&G<=c)L=W.length;else{const q=W.lastIndexOf(oe),O=W.lastIndexOf(ci);L=Math.max(q,O)+1}L>0&&(x=L,R=F.slice(0,x).join(""),G=this._getTextWidth(R))}if(R=R.trimRight(),this._addTextLine(R),i=Math.max(i,G),d+=s,this._shouldHandleEllipsis(d)){this._tryToAddEllipsisToLastLine();break}if(v=yt(v).slice(x).join("").trimLeft(),v.length>0&&(P=this._getTextWidth(v),P<=c)){this._addTextLine(v),d+=s,i=Math.max(i,P);break}}else break}else this._addTextLine(v),d+=s,i=Math.max(i,P),this._shouldHandleEllipsis(d)&&S<b-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),h&&d+s>u)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,n=s!==Dt&&s!==void 0,r=this.padding(),o=s-r*2;return!(this.wrap()!==fi)||n&&t+i>o}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==Dt&&t!==void 0,i=this.padding(),s=t-i*2,n=this.ellipsis(),r=this.textArr[this.textArr.length-1];!r||!n||(e&&(this._getTextWidth(r.text+Te)<s||(r.text=r.text.slice(0,r.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(r.text+Te))}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=this.textDecoration().indexOf("underline")!==-1||this.textDecoration().indexOf("line-through")!==-1,e=this.hasShadow();return t&&e?!0:super._useBufferCanvas()}}Z.prototype._fillFunc=Gn;Z.prototype._strokeFunc=In;Z.prototype.className=xn;Z.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"];J(Z);g.overWriteSetter(Z,"width",Ne());g.overWriteSetter(Z,"height",Ne());g.addGetterSetter(Z,"direction",Ni);g.addGetterSetter(Z,"fontFamily","Arial");g.addGetterSetter(Z,"fontSize",12,k());g.addGetterSetter(Z,"fontStyle",Hi);g.addGetterSetter(Z,"fontVariant",Hi);g.addGetterSetter(Z,"padding",0,k());g.addGetterSetter(Z,"align",zi);g.addGetterSetter(Z,"verticalAlign",kn);g.addGetterSetter(Z,"lineHeight",1,k());g.addGetterSetter(Z,"wrap",Mn);g.addGetterSetter(Z,"ellipsis",!1,ht());g.addGetterSetter(Z,"letterSpacing",0,k());g.addGetterSetter(Z,"text","",At());g.addGetterSetter(Z,"textDecoration","");g.addGetterSetter(Z,"underlineOffset",void 0,k());g.addGetterSetter(Z,"charRenderFunc",void 0);const Fn="",Ui="normal";function Xi(a){a.fillText(this.partialText,0,0)}function Yi(a){a.strokeText(this.partialText,0,0)}class st extends T{constructor(t){super(t),this.dummyCanvas=y.createCanvasElement(),this.dataArray=[],this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute(),this._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva",this._setTextData),this._setTextData()}_getTextPathLength(){return K.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;const e=this.pathLength;return t>e?null:K.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=K.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.textBaseline()),t.setAttr("textAlign","left"),t.save();const e=this.textDecoration(),i=this.fill(),s=this.fontSize(),n=this.glyphInfo,r=e.indexOf("underline")!==-1,o=e.indexOf("line-through")!==-1;r&&t.beginPath();for(let h=0;h<n.length;h++){t.save();const l=n[h].p0;t.translate(l.x,l.y),t.rotate(n[h].rotation),this.partialText=n[h].text,t.fillStrokeShape(this),r&&(h===0&&t.moveTo(0,s/2+1),t.lineTo(n[h].width,s/2+1)),t.restore()}if(r&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),o){t.beginPath();for(let h=0;h<n.length;h++){t.save();const l=n[h].p0;t.translate(l.x,l.y),t.rotate(n[h].rotation),h===0&&t.moveTo(0,0),t.lineTo(n[h].width,0),t.restore()}t.strokeStyle=i,t.lineWidth=s/20,t.stroke()}t.restore()}_hitFunc(t){t.beginPath();const e=this.glyphInfo;if(e.length>=1){const i=e[0].p0;t.moveTo(i.x,i.y)}for(let i=0;i<e.length;i++){const s=e[i].p1;t.lineTo(s.x,s.y)}t.setAttr("lineWidth",this.fontSize()),t.setAttr("strokeStyle",this.colorKey),t.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return y.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(t){return Z.prototype.setText.call(this,t)}_getContextFont(){return Z.prototype._getContextFont.call(this)}_getTextSize(t){const i=this.dummyCanvas.getContext("2d");i.save(),i.font=this._getContextFont();const s=i.measureText(t);return i.restore(),{width:s.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const t=yt(this.text()),e=[];let i=0;for(let u=0;u<t.length;u++)e.push({char:t[u],width:this._getTextSize(t[u]).width}),i+=e[u].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const n=this.letterSpacing(),r=this.align(),o=this.kerningFunc(),h=Math.max(this.textWidth+((this.attrs.text||"").length-1)*n,0);let l=0;r==="center"&&(l=Math.max(0,this.pathLength/2-h/2)),r==="right"&&(l=Math.max(0,this.pathLength-h));let c=l;for(let u=0;u<e.length;u++){const d=this._getPointAtLength(c);if(!d)return;const p=e[u].char;let f=e[u].width+n;if(p===" "&&r==="justify"){const v=this.text().split(" ").length-1;f+=(this.pathLength-h)/v}const m=this._getPointAtLength(c+f);if(!m)return;const _=K.getLineLength(d.x,d.y,m.x,m.y);let C=0;if(o)try{C=o(e[u-1].char,p)*this.fontSize()}catch{C=0}d.x+=C,m.x+=C,this.textWidth+=C;const S=K.getPointOnLine(C+_/2,d.x,d.y,m.x,m.y),b=Math.atan2(m.y-d.y,m.x-d.x);this.glyphInfo.push({transposeX:S.x,transposeY:S.y,text:t[u],rotation:b,p0:d,p1:m,width:_}),c+=f}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(l){t.push(l.p0.x),t.push(l.p0.y),t.push(l.p1.x),t.push(l.p1.y)});let e=t[0]||0,i=t[0]||0,s=t[1]||0,n=t[1]||0,r,o;for(let l=0;l<t.length/2;l++)r=t[l*2],o=t[l*2+1],e=Math.min(e,r),i=Math.max(i,r),s=Math.min(s,o),n=Math.max(n,o);const h=this.fontSize();return{x:e-h/2,y:s-h/2,width:i-e+h,height:n-s+h}}destroy(){return y.releaseCanvas(this.dummyCanvas),super.destroy()}}st.prototype._fillFunc=Xi;st.prototype._strokeFunc=Yi;st.prototype._fillFuncHit=Xi;st.prototype._strokeFuncHit=Yi;st.prototype.className="TextPath";st.prototype._attrsAffectingSize=["text","fontSize","data"];J(st);g.addGetterSetter(st,"data");g.addGetterSetter(st,"fontFamily","Arial");g.addGetterSetter(st,"fontSize",12,k());g.addGetterSetter(st,"fontStyle",Ui);g.addGetterSetter(st,"align","left");g.addGetterSetter(st,"letterSpacing",0,k());g.addGetterSetter(st,"textBaseline","middle");g.addGetterSetter(st,"fontVariant",Ui);g.addGetterSetter(st,"text",Fn);g.addGetterSetter(st,"textDecoration","");g.addGetterSetter(st,"kerningFunc",void 0);const Vi="tr-konva",Bn=["resizeEnabledChange","rotateAnchorOffsetChange","rotateAnchorAngleChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(a=>a+`.${Vi}`).join(" "),gi="nodesRect",Nn=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],zn={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},Hn="ontouchstart"in E._global;function Wn(a,t,e){if(a==="rotater")return e;t+=y.degToRad(zn[a]||0);const i=(y.radToDeg(t)%360+360)%360;return y._inRange(i,315+22.5,360)||y._inRange(i,0,22.5)?"ns-resize":y._inRange(i,45-22.5,45+22.5)?"nesw-resize":y._inRange(i,90-22.5,90+22.5)?"ew-resize":y._inRange(i,135-22.5,135+22.5)?"nwse-resize":y._inRange(i,180-22.5,180+22.5)?"ns-resize":y._inRange(i,225-22.5,225+22.5)?"nesw-resize":y._inRange(i,270-22.5,270+22.5)?"ew-resize":y._inRange(i,315-22.5,315+22.5)?"nwse-resize":(y.error("Transformer has unknown angle for cursor detection: "+i),"pointer")}const ge=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function Un(a){return{x:a.x+a.width/2*Math.cos(a.rotation)+a.height/2*Math.sin(-a.rotation),y:a.y+a.height/2*Math.cos(a.rotation)+a.width/2*Math.sin(a.rotation)}}function ji(a,t,e){const i=e.x+(a.x-e.x)*Math.cos(t)-(a.y-e.y)*Math.sin(t),s=e.y+(a.x-e.x)*Math.sin(t)+(a.y-e.y)*Math.cos(t);return{...a,rotation:a.rotation+t,x:i,y:s}}function Xn(a,t){const e=Un(a);return ji(a,t,e)}function Yn(a,t,e){let i=t;for(let s=0;s<a.length;s++){const n=E.getAngle(a[s]),r=Math.abs(n-t)%(Math.PI*2);Math.min(r,Math.PI*2-r)<e&&(i=n)}return i}let Oe=0;class z extends It{constructor(t){super(t),this._movingAnchorName=null,this._transforming=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(Bn,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return y.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([t])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return Vi+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(s=>s.isAncestorOf(this)?(y.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1):!0);return this._nodes=t=e,t.length===1&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(s=>{const n=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()};if(s._attrsAffectingSize.length){const r=s._attrsAffectingSize.map(o=>o+"Change."+this._getEventNamespace()).join(" ");s.on(r,n)}s.on(Nn.map(r=>r+`.${this._getEventNamespace()}`).join(" "),n),s.on(`absoluteTransformChange.${this._getEventNamespace()}`,n),this._proxyDrag(s)}),this._resetTransformCache(),!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,i=>{e=t.getAbsolutePosition(),!this.isDragging()&&t!==this.findOne(".back")&&this.startDrag(i,!1)}),t.on(`dragmove.${this._getEventNamespace()}`,i=>{if(!e)return;const s=t.getAbsolutePosition(),n=s.x-e.x,r=s.y-e.y;this.nodes().forEach(o=>{if(o===t||o.isDragging())return;const h=o.getAbsolutePosition();o.setAbsolutePosition({x:h.x+n,y:h.y+r}),o.startDrag(i)}),e=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(t=>{t.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(gi),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(gi,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),i){const s=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),n=t.getAbsoluteScale(i),r=t.getAbsolutePosition(i),o=s.x*n.x-t.offsetX()*n.x,h=s.y*n.y-t.offsetY()*n.y,l=(E.getAngle(t.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2),c={x:r.x+o*Math.cos(l)+h*Math.sin(-l),y:r.y+h*Math.cos(l)+o*Math.sin(l),width:s.width*n.x,height:s.height*n.y,rotation:l};return ji(c,-E.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const e=[];this.nodes().map(l=>{const c=l.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),u=[{x:c.x,y:c.y},{x:c.x+c.width,y:c.y},{x:c.x+c.width,y:c.y+c.height},{x:c.x,y:c.y+c.height}],d=l.getAbsoluteTransform();u.forEach(function(p){const f=d.point(p);e.push(f)})});const i=new rt;i.rotate(-E.getAngle(this.rotation()));let s=1/0,n=1/0,r=-1/0,o=-1/0;e.forEach(function(l){const c=i.point(l);s===void 0&&(s=r=c.x,n=o=c.y),s=Math.min(s,c.x),n=Math.min(n,c.y),r=Math.max(r,c.x),o=Math.max(o,c.y)}),i.invert();const h=i.point({x:s,y:n});return{x:h.x,y:h.y,width:r-s,height:o-n,rotation:E.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),ge.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new Qt({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:Hn?10:"auto"}),i=this;e.on("mousedown touchstart",function(s){i._handleMouseDown(s)}),e.on("dragstart",s=>{e.stopDrag(),s.cancelBubble=!0}),e.on("dragend",s=>{s.cancelBubble=!0}),e.on("mouseenter",()=>{const s=E.getAngle(this.rotation()),n=this.rotateAnchorCursor(),r=Wn(t,s,n);e.getStage().content&&(e.getStage().content.style.cursor=r),this._cursorChange=!0}),e.on("mouseout",()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(e)}_createBack(){const t=new T({name:"back",width:0,height:0,sceneFunc(e,i){const s=i.getParent(),n=s.padding(),r=i.width(),o=i.height();if(e.beginPath(),e.rect(-n,-n,r+n*2,o+n*2),s.rotateEnabled()&&s.rotateLineVisible()){const h=s.rotateAnchorAngle(),l=s.rotateAnchorOffset(),c=y.degToRad(h),u=Math.sin(c),d=-Math.cos(c),p=r/2,f=o/2;let m=1/0;d<0?m=Math.min(m,-f/d):d>0&&(m=Math.min(m,(o-f)/d)),u<0?m=Math.min(m,-p/u):u>0&&(m=Math.min(m,(r-p)/u));const _=p+u*m,C=f+d*m,S=y._sign(o),b=_+u*l*S,v=C+d*l*S;e.moveTo(_,C),e.lineTo(b,v)}e.fillStrokeShape(i)},hitFunc:(e,i)=>{if(!this.shouldOverdrawWholeArea())return;const s=this.padding();e.beginPath(),e.rect(-s,-s,i.width()+s*2,i.height()+s*2),e.fillStrokeShape(i)}});this.add(t),this._proxyDrag(t),t.on("dragstart",e=>{e.cancelBubble=!0}),t.on("dragmove",e=>{e.cancelBubble=!0}),t.on("dragend",e=>{e.cancelBubble=!0}),this.on("dragmove",e=>{this.update()})}_handleMouseDown(t){if(this._transforming)return;this._movingAnchorName=t.target.name().split(" ")[0];const e=this._getNodeRect(),i=e.width,s=e.height,n=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/n),this.cos=Math.abs(i/n),typeof window<"u"&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const r=t.target.getAbsolutePosition(),o=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:o.x-r.x,y:o.y-r.y},Oe++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(h=>{h._fire("transformstart",{evt:t.evt,target:h})})}_handleMouseMove(t){let e,i,s;const n=this.findOne("."+this._movingAnchorName),r=n.getStage();r.setPointersPositions(t);const o=r.getPointerPosition();let h={x:o.x-this._anchorDragOffset.x,y:o.y-this._anchorDragOffset.y};const l=n.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),n.setAbsolutePosition(h);const c=n.getAbsolutePosition();if(l.x===c.x&&l.y===c.y)return;if(this._movingAnchorName==="rotater"){const S=this._getNodeRect();e=n.x()-S.width/2,i=-n.y()+S.height/2;const b=E.getAngle(this.rotateAnchorAngle());let v=Math.atan2(-i,e)+Math.PI/2-b;S.height<0&&(v-=Math.PI);const x=E.getAngle(this.rotation())+v,D=E.getAngle(this.rotationSnapTolerance()),G=Yn(this.rotationSnaps(),x,D)-S.rotation,I=Xn(S,G);this._fitNodesInto(I,t);return}const u=this.shiftBehavior();let d;u==="inverted"?d=this.keepRatio()&&!t.shiftKey:u==="none"?d=this.keepRatio():d=this.keepRatio()||t.shiftKey;let p=this.centeredScaling()||t.altKey;if(this._movingAnchorName==="top-left"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};s=Math.sqrt(Math.pow(S.x-n.x(),2)+Math.pow(S.y-n.y(),2));const b=this.findOne(".top-left").x()>S.x?-1:1,v=this.findOne(".top-left").y()>S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,this.findOne(".top-left").x(S.x-e),this.findOne(".top-left").y(S.y-i)}}else if(this._movingAnchorName==="top-center")this.findOne(".top-left").y(n.y());else if(this._movingAnchorName==="top-right"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};s=Math.sqrt(Math.pow(n.x()-S.x,2)+Math.pow(S.y-n.y(),2));const b=this.findOne(".top-right").x()<S.x?-1:1,v=this.findOne(".top-right").y()>S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,this.findOne(".top-right").x(S.x+e),this.findOne(".top-right").y(S.y-i)}var f=n.position();this.findOne(".top-left").y(f.y),this.findOne(".bottom-right").x(f.x)}else if(this._movingAnchorName==="middle-left")this.findOne(".top-left").x(n.x());else if(this._movingAnchorName==="middle-right")this.findOne(".bottom-right").x(n.x());else if(this._movingAnchorName==="bottom-left"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};s=Math.sqrt(Math.pow(S.x-n.x(),2)+Math.pow(n.y()-S.y,2));const b=S.x<n.x()?-1:1,v=n.y()<S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,n.x(S.x-e),n.y(S.y+i)}f=n.position(),this.findOne(".top-left").x(f.x),this.findOne(".bottom-right").y(f.y)}else if(this._movingAnchorName==="bottom-center")this.findOne(".bottom-right").y(n.y());else if(this._movingAnchorName==="bottom-right"){if(d){const S=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};s=Math.sqrt(Math.pow(n.x()-S.x,2)+Math.pow(n.y()-S.y,2));const b=this.findOne(".bottom-right").x()<S.x?-1:1,v=this.findOne(".bottom-right").y()<S.y?-1:1;e=s*this.cos*b,i=s*this.sin*v,this.findOne(".bottom-right").x(S.x+e),this.findOne(".bottom-right").y(S.y+i)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(p=this.centeredScaling()||t.altKey,p){const S=this.findOne(".top-left"),b=this.findOne(".bottom-right"),v=S.x(),P=S.y(),x=this.getWidth()-b.x(),D=this.getHeight()-b.y();b.move({x:-v,y:-P}),S.move({x,y:D})}const m=this.findOne(".top-left").getAbsolutePosition();e=m.x,i=m.y;const _=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),C=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:i,width:_,height:C,rotation:E.getAngle(this.rotation())},t)}_handleMouseUp(t){this._removeEvents(t)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(t){var e;if(this._transforming){this._transforming=!1,typeof window<"u"&&(window.removeEventListener("mousemove",this._handleMouseMove),window.removeEventListener("touchmove",this._handleMouseMove),window.removeEventListener("mouseup",this._handleMouseUp,!0),window.removeEventListener("touchend",this._handleMouseUp,!0));const i=this.getNode();Oe--,this._fire("transformend",{evt:t,target:i}),(e=this.getLayer())===null||e===void 0||e.batchDraw(),i&&this._nodes.forEach(s=>{var n;s._fire("transformend",{evt:t,target:s}),(n=s.getLayer())===null||n===void 0||n.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const i=this._getNodeRect(),s=1;if(y._inRange(t.width,-this.padding()*2-s,s)){this.update();return}if(y._inRange(t.height,-this.padding()*2-s,s)){this.update();return}const n=new rt;if(n.rotate(E.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const d=n.point({x:-this.padding()*2,y:0});t.x+=d.x,t.y+=d.y,t.width+=this.padding()*2,this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const d=n.point({x:this.padding()*2,y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,t.width+=this.padding()*2}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const d=n.point({x:0,y:-this.padding()*2});t.x+=d.x,t.y+=d.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,t.height+=this.padding()*2}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const d=n.point({x:0,y:this.padding()*2});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,t.height+=this.padding()*2}if(this.boundBoxFunc()){const d=this.boundBoxFunc()(i,t);d?t=d:y.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const r=1e7,o=new rt;o.translate(i.x,i.y),o.rotate(i.rotation),o.scale(i.width/r,i.height/r);const h=new rt,l=t.width/r,c=t.height/r;this.flipEnabled()===!1?(h.translate(t.x,t.y),h.rotate(t.rotation),h.translate(t.width<0?t.width:0,t.height<0?t.height:0),h.scale(Math.abs(l),Math.abs(c))):(h.translate(t.x,t.y),h.rotate(t.rotation),h.scale(l,c));const u=h.multiply(o.invert());this._nodes.forEach(d=>{var p;if(!d.getStage())return;const f=d.getParent().getAbsoluteTransform(),m=d.getTransform().copy();m.translate(d.offsetX(),d.offsetY());const _=new rt;_.multiply(f.copy().invert()).multiply(u).multiply(f).multiply(m);const C=_.decompose();d.setAttrs(C),(p=d.getLayer())===null||p===void 0||p.batchDraw()}),this.rotation(y._getRotation(t.rotation)),this._nodes.forEach(d=>{this._fire("transform",{evt:e,target:d}),d._fire("transform",{evt:e,target:d})}),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(t,e){this.findOne(t).setAttrs(e)}update(){var t;const e=this._getNodeRect();this.rotation(y._getRotation(e.rotation));const i=e.width,s=e.height,n=this.enabledAnchors(),r=this.resizeEnabled(),o=this.padding(),h=this.anchorSize(),l=this.find("._anchor");l.forEach(x=>{x.setAttrs({width:h,height:h,offsetX:h/2,offsetY:h/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:h/2+o,offsetY:h/2+o,visible:r&&n.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:h/2+o,visible:r&&n.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:h/2-o,offsetY:h/2+o,visible:r&&n.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:h/2+o,visible:r&&n.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:h/2-o,visible:r&&n.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:h/2+o,offsetY:h/2-o,visible:r&&n.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:h/2-o,visible:r&&n.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:h/2-o,offsetY:h/2-o,visible:r&&n.indexOf("bottom-right")>=0});const c=this.rotateAnchorAngle(),u=this.rotateAnchorOffset(),d=y.degToRad(c),p=Math.sin(d),f=-Math.cos(d),m=i/2,_=s/2;let C=1/0;f<0?C=Math.min(C,-_/f):f>0&&(C=Math.min(C,(s-_)/f)),p<0?C=Math.min(C,-m/p):p>0&&(C=Math.min(C,(i-m)/p));const S=m+p*C,b=_+f*C,v=y._sign(s);this._batchChangeChild(".rotater",{x:S+p*u*v,y:b+f*u*v-o*f,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:i,height:s,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),draggable:this.nodes().some(x=>x.draggable()),x:0,y:0});const P=this.anchorStyleFunc();P&&l.forEach(x=>{P(x)}),(t=this.getLayer())===null||t===void 0||t.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();const t=this.findOne("."+this._movingAnchorName);t&&t.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),It.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return w.prototype.toObject.call(this)}clone(t){return w.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}z.isTransforming=()=>Oe>0;function Vn(a){return a instanceof Array||y.warn("enabledAnchors value should be an array"),a instanceof Array&&a.forEach(function(t){ge.indexOf(t)===-1&&y.warn("Unknown anchor name: "+t+". Available names are: "+ge.join(", "))}),a||[]}z.prototype.className="Transformer";J(z);g.addGetterSetter(z,"enabledAnchors",ge,Vn);g.addGetterSetter(z,"flipEnabled",!0,ht());g.addGetterSetter(z,"resizeEnabled",!0);g.addGetterSetter(z,"anchorSize",10,k());g.addGetterSetter(z,"rotateEnabled",!0);g.addGetterSetter(z,"rotateLineVisible",!0);g.addGetterSetter(z,"rotationSnaps",[]);g.addGetterSetter(z,"rotateAnchorOffset",50,k());g.addGetterSetter(z,"rotateAnchorAngle",0,k());g.addGetterSetter(z,"rotateAnchorCursor","crosshair");g.addGetterSetter(z,"rotationSnapTolerance",5,k());g.addGetterSetter(z,"borderEnabled",!0);g.addGetterSetter(z,"anchorStroke","rgb(0, 161, 255)");g.addGetterSetter(z,"anchorStrokeWidth",1,k());g.addGetterSetter(z,"anchorFill","white");g.addGetterSetter(z,"anchorCornerRadius",0,k());g.addGetterSetter(z,"borderStroke","rgb(0, 161, 255)");g.addGetterSetter(z,"borderStrokeWidth",1,k());g.addGetterSetter(z,"borderDash");g.addGetterSetter(z,"keepRatio",!0);g.addGetterSetter(z,"shiftBehavior","default");g.addGetterSetter(z,"centeredScaling",!1);g.addGetterSetter(z,"ignoreStroke",!1);g.addGetterSetter(z,"padding",0,k());g.addGetterSetter(z,"nodes");g.addGetterSetter(z,"node");g.addGetterSetter(z,"boundBoxFunc");g.addGetterSetter(z,"anchorDragBoundFunc");g.addGetterSetter(z,"anchorStyleFunc");g.addGetterSetter(z,"shouldOverdrawWholeArea",!1);g.addGetterSetter(z,"useSingleNodeRotation",!0);g.backCompat(z,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class mt extends T{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,E.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}mt.prototype.className="Wedge";mt.prototype._centroid=!0;mt.prototype._attrsAffectingSize=["radius"];J(mt);g.addGetterSetter(mt,"radius",0,k());g.addGetterSetter(mt,"angle",0,k());g.addGetterSetter(mt,"clockwise",!1);g.backCompat(mt,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});function pi(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}const jn=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],qn=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function $n(a,t){const e=a.data,i=a.width,s=a.height;let n,r,o,h,l,c,u,d,p,f,m,_,C,S,b,v,P,x,D,R;const G=t+t+1,I=i-1,H=s-1,F=t+1,W=F*(F+1)/2,N=new pi,B=jn[t],L=qn[t];let q=null,O=N,V=null,it=null;for(let Y=1;Y<G;Y++)O=O.next=new pi,Y===F&&(q=O);O.next=N,o=r=0;for(let Y=0;Y<s;Y++){_=C=S=b=h=l=c=u=0,d=F*(v=e[r]),p=F*(P=e[r+1]),f=F*(x=e[r+2]),m=F*(D=e[r+3]),h+=W*v,l+=W*P,c+=W*x,u+=W*D,O=N;for(let et=0;et<F;et++)O.r=v,O.g=P,O.b=x,O.a=D,O=O.next;for(let et=1;et<F;et++)n=r+((I<et?I:et)<<2),h+=(O.r=v=e[n])*(R=F-et),l+=(O.g=P=e[n+1])*R,c+=(O.b=x=e[n+2])*R,u+=(O.a=D=e[n+3])*R,_+=v,C+=P,S+=x,b+=D,O=O.next;V=N,it=q;for(let et=0;et<i;et++)e[r+3]=D=u*B>>L,D!==0?(D=255/D,e[r]=(h*B>>L)*D,e[r+1]=(l*B>>L)*D,e[r+2]=(c*B>>L)*D):e[r]=e[r+1]=e[r+2]=0,h-=d,l-=p,c-=f,u-=m,d-=V.r,p-=V.g,f-=V.b,m-=V.a,n=o+((n=et+t+1)<I?n:I)<<2,_+=V.r=e[n],C+=V.g=e[n+1],S+=V.b=e[n+2],b+=V.a=e[n+3],h+=_,l+=C,c+=S,u+=b,V=V.next,d+=v=it.r,p+=P=it.g,f+=x=it.b,m+=D=it.a,_-=v,C-=P,S-=x,b-=D,it=it.next,r+=4;o+=i}for(let Y=0;Y<i;Y++){C=S=b=_=l=c=u=h=0,r=Y<<2,d=F*(v=e[r]),p=F*(P=e[r+1]),f=F*(x=e[r+2]),m=F*(D=e[r+3]),h+=W*v,l+=W*P,c+=W*x,u+=W*D,O=N;for(let nt=0;nt<F;nt++)O.r=v,O.g=P,O.b=x,O.a=D,O=O.next;let et=i;for(let nt=1;nt<=t;nt++)r=et+Y<<2,h+=(O.r=v=e[r])*(R=F-nt),l+=(O.g=P=e[r+1])*R,c+=(O.b=x=e[r+2])*R,u+=(O.a=D=e[r+3])*R,_+=v,C+=P,S+=x,b+=D,O=O.next,nt<H&&(et+=i);r=Y,V=N,it=q;for(let nt=0;nt<s;nt++)n=r<<2,e[n+3]=D=u*B>>L,D>0?(D=255/D,e[n]=(h*B>>L)*D,e[n+1]=(l*B>>L)*D,e[n+2]=(c*B>>L)*D):e[n]=e[n+1]=e[n+2]=0,h-=d,l-=p,c-=f,u-=m,d-=V.r,p-=V.g,f-=V.b,m-=V.a,n=Y+((n=nt+F)<H?n:H)*i<<2,h+=_+=V.r=e[n],l+=C+=V.g=e[n+1],c+=S+=V.b=e[n+2],u+=b+=V.a=e[n+3],V=V.next,d+=v=it.r,p+=P=it.g,f+=x=it.b,m+=D=it.a,_-=v,C-=P,S-=x,b-=D,it=it.next,r+=i}}const Kn=function(t){const e=Math.round(this.blurRadius());e>0&&$n(t,e)};g.addGetterSetter(w,"blurRadius",0,k(),g.afterSetFilter);const Zn=function(a){const t=this.brightness()*255,e=a.data,i=e.length;for(let s=0;s<i;s+=4)e[s]+=t,e[s+1]+=t,e[s+2]+=t};g.addGetterSetter(w,"brightness",0,k(),g.afterSetFilter);const Jn=function(a){const t=this.brightness(),e=a.data,i=e.length;for(let s=0;s<i;s+=4)e[s]=Math.min(255,e[s]*t),e[s+1]=Math.min(255,e[s+1]*t),e[s+2]=Math.min(255,e[s+2]*t)},Qn=function(a){const t=Math.pow((this.contrast()+100)/100,2),e=a.data,i=e.length;let s=150,n=150,r=150;for(let o=0;o<i;o+=4)s=e[o],n=e[o+1],r=e[o+2],s/=255,s-=.5,s*=t,s+=.5,s*=255,n/=255,n-=.5,n*=t,n+=.5,n*=255,r/=255,r-=.5,r*=t,r+=.5,r*=255,s=s<0?0:s>255?255:s,n=n<0?0:n>255?255:n,r=r<0?0:r>255?255:r,e[o]=s,e[o+1]=n,e[o+2]=r};g.addGetterSetter(w,"contrast",0,k(),g.afterSetFilter);const tr=function(a){var t,e,i,s,n,r,o,h,l;const c=a.data,u=a.width,d=a.height,p=Math.min(1,Math.max(0,(e=(t=this.embossStrength)===null||t===void 0?void 0:t.call(this))!==null&&e!==void 0?e:.5)),f=Math.min(1,Math.max(0,(s=(i=this.embossWhiteLevel)===null||i===void 0?void 0:i.call(this))!==null&&s!==void 0?s:.5)),_=(o={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[(r=(n=this.embossDirection)===null||n===void 0?void 0:n.call(this))!==null&&r!==void 0?r:"top-left"])!==null&&o!==void 0?o:315,C=!!((l=(h=this.embossBlend)===null||h===void 0?void 0:h.call(this))!==null&&l!==void 0&&l),S=p*10,b=f*255,v=_*Math.PI/180,P=Math.cos(v),x=Math.sin(v),D=128/1020*S,R=new Uint8ClampedArray(c),G=new Float32Array(u*d);for(let N=0,B=0;B<c.length;B+=4,N++)G[N]=.2126*R[B]+.7152*R[B+1]+.0722*R[B+2];const I=[-1,0,1,-2,0,2,-1,0,1],H=[-1,-2,-1,0,0,0,1,2,1],F=[-u-1,-u,-u+1,-1,0,1,u-1,u,u+1],W=N=>N<0?0:N>255?255:N;for(let N=1;N<d-1;N++)for(let B=1;B<u-1;B++){const L=N*u+B;let q=0,O=0;q+=G[L+F[0]]*I[0],O+=G[L+F[0]]*H[0],q+=G[L+F[1]]*I[1],O+=G[L+F[1]]*H[1],q+=G[L+F[2]]*I[2],O+=G[L+F[2]]*H[2],q+=G[L+F[3]]*I[3],O+=G[L+F[3]]*H[3],q+=G[L+F[5]]*I[5],O+=G[L+F[5]]*H[5],q+=G[L+F[6]]*I[6],O+=G[L+F[6]]*H[6],q+=G[L+F[7]]*I[7],O+=G[L+F[7]]*H[7],q+=G[L+F[8]]*I[8],O+=G[L+F[8]]*H[8];const V=P*q+x*O,it=W(b+V*D),Y=L*4;if(C){const et=it-b;c[Y]=W(R[Y]+et),c[Y+1]=W(R[Y+1]+et),c[Y+2]=W(R[Y+2]+et),c[Y+3]=R[Y+3]}else c[Y]=c[Y+1]=c[Y+2]=it,c[Y+3]=R[Y+3]}for(let N=0;N<u;N++){let B=N*4,L=((d-1)*u+N)*4;c[B]=R[B],c[B+1]=R[B+1],c[B+2]=R[B+2],c[B+3]=R[B+3],c[L]=R[L],c[L+1]=R[L+1],c[L+2]=R[L+2],c[L+3]=R[L+3]}for(let N=1;N<d-1;N++){let B=N*u*4,L=(N*u+(u-1))*4;c[B]=R[B],c[B+1]=R[B+1],c[B+2]=R[B+2],c[B+3]=R[B+3],c[L]=R[L],c[L+1]=R[L+1],c[L+2]=R[L+2],c[L+3]=R[L+3]}return a};g.addGetterSetter(w,"embossStrength",.5,k(),g.afterSetFilter);g.addGetterSetter(w,"embossWhiteLevel",.5,k(),g.afterSetFilter);g.addGetterSetter(w,"embossDirection","top-left",void 0,g.afterSetFilter);g.addGetterSetter(w,"embossBlend",!1,void 0,g.afterSetFilter);function xe(a,t,e,i,s){const n=e-t,r=s-i;if(n===0)return i+r/2;if(r===0)return i;let o=(a-t)/n;return o=r*o+i,o}const er=function(a){const t=a.data,e=t.length;let i=t[0],s=i,n,r=t[1],o=r,h,l=t[2],c=l,u;const d=this.enhance();if(d===0)return;for(let b=0;b<e;b+=4)n=t[b+0],n<i?i=n:n>s&&(s=n),h=t[b+1],h<r?r=h:h>o&&(o=h),u=t[b+2],u<l?l=u:u>c&&(c=u);s===i&&(s=255,i=0),o===r&&(o=255,r=0),c===l&&(c=255,l=0);let p,f,m,_,C,S;if(d>0)p=s+d*(255-s),f=i-d*(i-0),m=o+d*(255-o),_=r-d*(r-0),C=c+d*(255-c),S=l-d*(l-0);else{const b=(s+i)*.5;p=s+d*(s-b),f=i+d*(i-b);const v=(o+r)*.5;m=o+d*(o-v),_=r+d*(r-v);const P=(c+l)*.5;C=c+d*(c-P),S=l+d*(l-P)}for(let b=0;b<e;b+=4)t[b+0]=xe(t[b+0],i,s,f,p),t[b+1]=xe(t[b+1],r,o,_,m),t[b+2]=xe(t[b+2],l,c,S,C)};g.addGetterSetter(w,"enhance",0,k(),g.afterSetFilter);const ir=function(a){const t=a.data,e=t.length;for(let i=0;i<e;i+=4){const s=.34*t[i]+.5*t[i+1]+.16*t[i+2];t[i]=s,t[i+1]=s,t[i+2]=s}};g.addGetterSetter(w,"hue",0,k(),g.afterSetFilter);g.addGetterSetter(w,"saturation",0,k(),g.afterSetFilter);g.addGetterSetter(w,"luminance",0,k(),g.afterSetFilter);const sr=function(a){const t=a.data,e=t.length,i=1,s=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,r=this.luminance()*127,o=i*s*Math.cos(n*Math.PI/180),h=i*s*Math.sin(n*Math.PI/180),l=.299*i+.701*o+.167*h,c=.587*i-.587*o+.33*h,u=.114*i-.114*o-.497*h,d=.299*i-.299*o-.328*h,p=.587*i+.413*o+.035*h,f=.114*i-.114*o+.293*h,m=.299*i-.3*o+1.25*h,_=.587*i-.586*o-1.05*h,C=.114*i+.886*o-.2*h;let S,b,v,P;for(let x=0;x<e;x+=4)S=t[x+0],b=t[x+1],v=t[x+2],P=t[x+3],t[x+0]=l*S+c*b+u*v+r,t[x+1]=d*S+p*b+f*v+r,t[x+2]=m*S+_*b+C*v+r,t[x+3]=P},nr=function(a){const t=a.data,e=t.length,i=Math.pow(2,this.value()),s=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,r=i*s*Math.cos(n*Math.PI/180),o=i*s*Math.sin(n*Math.PI/180),h=.299*i+.701*r+.167*o,l=.587*i-.587*r+.33*o,c=.114*i-.114*r-.497*o,u=.299*i-.299*r-.328*o,d=.587*i+.413*r+.035*o,p=.114*i-.114*r+.293*o,f=.299*i-.3*r+1.25*o,m=.587*i-.586*r-1.05*o,_=.114*i+.886*r-.2*o;for(let C=0;C<e;C+=4){const S=t[C+0],b=t[C+1],v=t[C+2],P=t[C+3];t[C+0]=h*S+l*b+c*v,t[C+1]=u*S+d*b+p*v,t[C+2]=f*S+m*b+_*v,t[C+3]=P}};g.addGetterSetter(w,"hue",0,k(),g.afterSetFilter);g.addGetterSetter(w,"saturation",0,k(),g.afterSetFilter);g.addGetterSetter(w,"value",0,k(),g.afterSetFilter);const rr=function(a){const t=a.data,e=t.length;for(let i=0;i<e;i+=4)t[i]=255-t[i],t[i+1]=255-t[i+1],t[i+2]=255-t[i+2]},ar=function(a,t,e){const i=a.data,s=t.data,n=a.width,r=a.height,o=e.polarCenterX||n/2,h=e.polarCenterY||r/2;let l=Math.sqrt(o*o+h*h),c=n-o,u=r-h;const d=Math.sqrt(c*c+u*u);l=d>l?d:l;const p=r,f=n,m=360/f*Math.PI/180;for(let _=0;_<f;_+=1){const C=Math.sin(_*m),S=Math.cos(_*m);for(let b=0;b<p;b+=1){c=Math.floor(o+l*b/p*S),u=Math.floor(h+l*b/p*C);let v=(u*n+c)*4;const P=i[v+0],x=i[v+1],D=i[v+2],R=i[v+3];v=(_+b*n)*4,s[v+0]=P,s[v+1]=x,s[v+2]=D,s[v+3]=R}}},or=function(a,t,e){const i=a.data,s=t.data,n=a.width,r=a.height,o=e.polarCenterX||n/2,h=e.polarCenterY||r/2;let l=Math.sqrt(o*o+h*h),c=n-o,u=r-h;const d=Math.sqrt(c*c+u*u);l=d>l?d:l;const p=r,f=n,m=0;let _,C;for(c=0;c<n;c+=1)for(u=0;u<r;u+=1){const S=c-o,b=u-h,v=Math.sqrt(S*S+b*b)*p/l;let P=(Math.atan2(b,S)*180/Math.PI+360+m)%360;P=P*f/360,_=Math.floor(P),C=Math.floor(v);let x=(C*n+_)*4;const D=i[x+0],R=i[x+1],G=i[x+2],I=i[x+3];x=(u*n+c)*4,s[x+0]=D,s[x+1]=R,s[x+2]=G,s[x+3]=I}},hr=function(a){const t=a.width,e=a.height;let i,s,n,r,o,h,l,c,u,d,p=Math.round(this.kaleidoscopePower());const f=Math.round(this.kaleidoscopeAngle()),m=Math.floor(t*(f%360)/360);if(p<1)return;const _=y.createCanvasElement();_.width=t,_.height=e;const C=_.getContext("2d").getImageData(0,0,t,e);y.releaseCanvas(_),ar(a,C,{polarCenterX:t/2,polarCenterY:e/2});let S=t/Math.pow(2,p);for(;S<=8;)S=S*2,p-=1;S=Math.ceil(S);let b=S,v=0,P=b,x=1;for(m+S>t&&(v=b,P=0,x=-1),s=0;s<e;s+=1)for(i=v;i!==P;i+=x)n=Math.round(i+m)%t,u=(t*s+n)*4,o=C.data[u+0],h=C.data[u+1],l=C.data[u+2],c=C.data[u+3],d=(t*s+i)*4,C.data[d+0]=o,C.data[d+1]=h,C.data[d+2]=l,C.data[d+3]=c;for(s=0;s<e;s+=1)for(b=Math.floor(S),r=0;r<p;r+=1){for(i=0;i<b+1;i+=1)u=(t*s+i)*4,o=C.data[u+0],h=C.data[u+1],l=C.data[u+2],c=C.data[u+3],d=(t*s+b*2-i-1)*4,C.data[d+0]=o,C.data[d+1]=h,C.data[d+2]=l,C.data[d+3]=c;b*=2}or(C,a,{})};g.addGetterSetter(w,"kaleidoscopePower",2,k(),g.afterSetFilter);g.addGetterSetter(w,"kaleidoscopeAngle",0,k(),g.afterSetFilter);function le(a,t,e){let i=(e*a.width+t)*4;const s=[];return s.push(a.data[i++],a.data[i++],a.data[i++],a.data[i++]),s}function Wt(a,t){return Math.sqrt(Math.pow(a[0]-t[0],2)+Math.pow(a[1]-t[1],2)+Math.pow(a[2]-t[2],2))}function lr(a){const t=[0,0,0];for(let e=0;e<a.length;e++)t[0]+=a[e][0],t[1]+=a[e][1],t[2]+=a[e][2];return t[0]/=a.length,t[1]/=a.length,t[2]/=a.length,t}function cr(a,t){const e=le(a,0,0),i=le(a,a.width-1,0),s=le(a,0,a.height-1),n=le(a,a.width-1,a.height-1),r=t||10;if(Wt(e,i)<r&&Wt(i,n)<r&&Wt(n,s)<r&&Wt(s,e)<r){const o=lr([i,e,n,s]),h=[];for(let l=0;l<a.width*a.height;l++){const c=Wt(o,[a.data[l*4],a.data[l*4+1],a.data[l*4+2]]);h[l]=c<r?0:255}return h}}function dr(a,t){for(let e=0;e<a.width*a.height;e++)a.data[4*e+3]=t[e]}function ur(a,t,e){const i=[1,1,1,1,0,1,1,1,1],s=Math.round(Math.sqrt(i.length)),n=Math.floor(s/2),r=[];for(let o=0;o<e;o++)for(let h=0;h<t;h++){const l=o*t+h;let c=0;for(let u=0;u<s;u++)for(let d=0;d<s;d++){const p=o+u-n,f=h+d-n;if(p>=0&&p<e&&f>=0&&f<t){const m=p*t+f,_=i[u*s+d];c+=a[m]*_}}r[l]=c===255*8?255:0}return r}function fr(a,t,e){const i=[1,1,1,1,1,1,1,1,1],s=Math.round(Math.sqrt(i.length)),n=Math.floor(s/2),r=[];for(let o=0;o<e;o++)for(let h=0;h<t;h++){const l=o*t+h;let c=0;for(let u=0;u<s;u++)for(let d=0;d<s;d++){const p=o+u-n,f=h+d-n;if(p>=0&&p<e&&f>=0&&f<t){const m=p*t+f,_=i[u*s+d];c+=a[m]*_}}r[l]=c>=255*4?255:0}return r}function gr(a,t,e){const i=[.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111],s=Math.round(Math.sqrt(i.length)),n=Math.floor(s/2),r=[];for(let o=0;o<e;o++)for(let h=0;h<t;h++){const l=o*t+h;let c=0;for(let u=0;u<s;u++)for(let d=0;d<s;d++){const p=o+u-n,f=h+d-n;if(p>=0&&p<e&&f>=0&&f<t){const m=p*t+f,_=i[u*s+d];c+=a[m]*_}}r[l]=c}return r}const pr=function(a){const t=this.threshold();let e=cr(a,t);return e&&(e=ur(e,a.width,a.height),e=fr(e,a.width,a.height),e=gr(e,a.width,a.height),dr(a,e)),a};g.addGetterSetter(w,"threshold",0,k(),g.afterSetFilter);const mr=function(a){const t=this.noise()*255,e=a.data,i=e.length,s=t/2;for(let n=0;n<i;n+=4)e[n+0]+=s-2*s*Math.random(),e[n+1]+=s-2*s*Math.random(),e[n+2]+=s-2*s*Math.random()};g.addGetterSetter(w,"noise",.2,k(),g.afterSetFilter);const _r=function(a){let t=Math.ceil(this.pixelSize()),e=a.width,i=a.height,s=Math.ceil(e/t),n=Math.ceil(i/t),r=a.data;if(t<=0){y.error("pixelSize value can not be <= 0");return}for(let o=0;o<s;o+=1)for(let h=0;h<n;h+=1){let l=0,c=0,u=0,d=0;const p=o*t,f=p+t,m=h*t,_=m+t;let C=0;for(let S=p;S<f;S+=1)if(!(S>=e))for(let b=m;b<_;b+=1){if(b>=i)continue;const v=(e*b+S)*4;l+=r[v+0],c+=r[v+1],u+=r[v+2],d+=r[v+3],C+=1}l=l/C,c=c/C,u=u/C,d=d/C;for(let S=p;S<f;S+=1)if(!(S>=e))for(let b=m;b<_;b+=1){if(b>=i)continue;const v=(e*b+S)*4;r[v+0]=l,r[v+1]=c,r[v+2]=u,r[v+3]=d}}};g.addGetterSetter(w,"pixelSize",8,k(),g.afterSetFilter);const yr=function(a){const t=Math.round(this.levels()*254)+1,e=a.data,i=e.length,s=255/t;for(let n=0;n<i;n+=1)e[n]=Math.floor(e[n]/s)*s};g.addGetterSetter(w,"levels",.5,k(),g.afterSetFilter);const Cr=function(a){const t=a.data,e=t.length,i=this.red(),s=this.green(),n=this.blue();for(let r=0;r<e;r+=4){const o=(.34*t[r]+.5*t[r+1]+.16*t[r+2])/255;t[r]=o*i,t[r+1]=o*s,t[r+2]=o*n,t[r+3]=t[r+3]}};g.addGetterSetter(w,"red",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(w,"green",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(w,"blue",0,mi,g.afterSetFilter);const Sr=function(a){const t=a.data,e=t.length,i=this.red(),s=this.green(),n=this.blue(),r=this.alpha();for(let o=0;o<e;o+=4){const h=1-r;t[o]=i*r+t[o]*h,t[o+1]=s*r+t[o+1]*h,t[o+2]=n*r+t[o+2]*h}};g.addGetterSetter(w,"red",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(w,"green",0,function(a){return this._filterUpToDate=!1,a>255?255:a<0?0:Math.round(a)});g.addGetterSetter(w,"blue",0,mi,g.afterSetFilter);g.addGetterSetter(w,"alpha",1,function(a){return this._filterUpToDate=!1,a>1?1:a<0?0:a});const br=function(a){const t=a.data,e=t.length;for(let i=0;i<e;i+=4){const s=t[i+0],n=t[i+1],r=t[i+2];t[i+0]=Math.min(255,s*.393+n*.769+r*.189),t[i+1]=Math.min(255,s*.349+n*.686+r*.168),t[i+2]=Math.min(255,s*.272+n*.534+r*.131)}},vr=function(a){const e=a.data;for(let i=0;i<e.length;i+=4){const s=e[i],n=e[i+1],r=e[i+2];.2126*s+.7152*n+.0722*r>=128&&(e[i]=255-s,e[i+1]=255-n,e[i+2]=255-r)}return a},Tr=function(a){const t=this.threshold()*255,e=a.data,i=e.length;for(let s=0;s<i;s+=1)e[s]=e[s]<t?0:255};g.addGetterSetter(w,"threshold",.5,k(),g.afterSetFilter);const Q=ni.Util._assign(ni,{Arc:gt,Arrow:Pt,Circle:Ot,Ellipse:bt,Image:lt,Label:We,Tag:Mt,Line:pt,Path:K,Rect:Qt,RegularPolygon:vt,Ring:Rt,Sprite:dt,Star:Tt,Text:Z,TextPath:st,Transformer:z,Wedge:mt,Filters:{Blur:Kn,Brightness:Jn,Brighten:Zn,Contrast:Qn,Emboss:tr,Enhance:er,Grayscale:ir,HSL:sr,HSV:nr,Invert:rr,Kaleidoscope:hr,Mask:pr,Noise:mr,Pixelate:_r,Posterize:yr,RGB:Cr,RGBA:Sr,Sepia:br,Solarize:vr,Threshold:Tr}});class M{static setDebugEnabled(t){this.debugEnabled=t}static setModuleDebugEnabled(t,e){this.moduleDebugEnabled.set(t,e)}static isModuleDebugEnabled(t){return this.moduleDebugEnabled.get(t)??this.debugEnabled}static debug(t,e,i){this.isModuleDebugEnabled(t)&&console.log(`[DEBUG] [${t}] ${e}`,i)}static info(t,e,i){console.log(`[INFO] [${t}] ${e}`,i)}static warn(t,e,i){console.warn(`[WARN] [${t}] ${e}`,i)}static error(t,e,i){console.error(`[ERROR] [${t}] ${e}`,i)}}A(M,"debugEnabled",!1),A(M,"moduleDebugEnabled",new Map);const ft=class ft{static createStage(t,e,i){return new Q.Stage({container:t,width:e,height:i})}static createLayer(t){const e=new Q.Layer;return e.name(t),e}static createRect(t,e,i,s,n="#ffffff",r="#000000",o=1){return new Q.Rect({x:t,y:e,width:i,height:s,fill:n,stroke:r,strokeWidth:o})}static createText(t,e,i,s=12,n="Arial",r="#000000",o="left",h="top"){return new Q.Text({text:t,x:e,y:i,fontSize:s,fontFamily:n,fill:r,align:o,verticalAlign:h})}static createLine(t,e="#000000",i=1){return new Q.Line({points:t,stroke:e,strokeWidth:i,lineCap:"round",lineJoin:"round"})}static createGroup(t=0,e=0){return new Q.Group({x:t,y:e})}static createPlayhead(t,e,i){const s=new Q.Group({x:t,y:e}),n=this.createLine([0,0,0,i],"#FF0000",2),r=new Q.RegularPolygon({x:0,y:-10,sides:3,radius:5,fill:"#FF0000",rotation:180});return s.add(n),s.add(r),s}static drawTimeTick(t,e,i,s,n,r,o,h){const l=h||s;let c;o==="major"?c=l*.6:c=l*.3;const u=this.createLine([e,i,e,i+c],r.timeTick,o==="major"?1:.5);if(u.name("time-tick-line"),t.add(u),o==="major"){const d=i+c+5,p=this.formatTime(n),f=this.createText(p,e,d,10,"Arial",r.timeText,"center");f.name("time-tick-text"),t.add(f)}}static drawGrid(t,e,i,s,n,r){const o=this.createGroup(e,i);for(let h=0;h<=s;h+=r){const l=this.createLine([h,0,h,n],"#E0E0E0",.5);o.add(l)}for(let h=0;h<=n;h+=r){const l=this.createLine([0,h,s,h],"#E0E0E0",.5);o.add(l)}t.add(o)}static formatTime(t){const e=t/1e3,i=Math.floor(e/60),s=Math.floor(e%60),n=Math.floor(t%1e3/10);return`${i.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}.${n.toString().padStart(2,"0")}`}static formatDuration(t){const e=Math.floor(t/1e3),i=Math.floor(t%1e3/10);return`${e}.${i.toString().padStart(2,"0")}s`}static getKeyframeDimensions(t,e){return this.keyframeDimensionsCache[t]?Promise.resolve(this.keyframeDimensionsCache[t]):new Promise(i=>{const s=this.getCachedImage(e);if(s.complete&&s.width>0){const n={width:s.width,height:s.height};this.keyframeDimensionsCache[t]=n,i(n);return}s.onload=()=>{const n={width:s.width,height:s.height};this.keyframeDimensionsCache[t]=n,i(n)},s.onerror=()=>{console.warn(`Failed to load keyframe: ${e}, using default dimensions`),i({width:160,height:90})},s.src||(s.src=e)})}static getCachedImage(t){if(this.imageCache[t])return this.imageCache[t];const e=new Image;return this.imageCache[t]=e,this.checkAndTrimCache(),e}static checkAndTrimCache(){const t=Object.keys(this.imageCache);if(t.length>this.MAX_CACHE_SIZE){const e=t.length-this.MAX_CACHE_SIZE;for(let i=0;i<e;i++){const s=t[i];delete this.imageCache[s]}}}static clearImageCache(){this.imageCache={}}static createClipGroup(t,e,i,s,n,r,o,h=!1,l,c){const u=this.createGroup(t,e),d=4,p=15,f=s-p-4,m=i-this.RESIZE_AREA_WIDTH*2,_={...o,background:h&&o.clipSelectedBackground||o.clipBackground,name:h&&o.clipSelectedName||o.clipName,duration:h&&o.clipSelectedDuration||o.clipDuration,handle:h&&o.clipSelectedHandle||o.clipHandle,coverBackground:h?o.clipSelectedCoverBackground||o.clipCoverBackground||"#FFF2A0":o.clipCoverBackground||"#FFF2A0"},C=this.createRect(0,0,i,s,_.background,_.clipBorder||"transparent",0);C.cornerRadius(d),C.name("clip-background"),u.add(C);const S=new Q.Rect({x:0,y:0,width:this.RESIZE_AREA_WIDTH,height:s,name:"clip-resize-left"});u.add(S);const b=new Q.Rect({x:i-this.RESIZE_AREA_WIDTH,y:0,width:this.RESIZE_AREA_WIDTH,height:s,name:"clip-resize-right"});u.add(b);const v=this.createGroup(this.RESIZE_AREA_WIDTH,2);v.name("clip-cover-container"),v.clip({x:0,y:0,width:m,height:f}),u.add(v);const P=this.createRect(0,0,m,f,_.coverBackground,"transparent",0);P.cornerRadius(2),P.name("clip-cover-background"),v.add(P);const x=l??[],D=this.createGroup(0,0);D.name("clip-covers-group"),v.add(D),this.renderClipCovers(D,x,m,f,c);const R=this.formatDuration(r),G=`${n} ${R}`,I=this.createText(G,this.RESIZE_AREA_WIDTH,s-p,10,"Arial",_.name,"left","middle");return I.ellipsis(!0),I.width(m),I.height(p),I.name("clip-label"),u.add(I),u}static updateClipGroup(t,e,i,s,n,r,o=!1,h,l){const u=i-15-4,d=e-this.RESIZE_AREA_WIDTH*2,p=t.findOne(".clip-background");if(p&&(p.width(e),p.height(i),r)){const b=o&&r.clipSelectedBackground||r.clipBackground;new Q.Tween({node:p,duration:.2,fill:b,easing:Q.Easings.EaseInOut}).play()}const f=t.findOne(".clip-resize-right");f&&(f.x(e-this.RESIZE_AREA_WIDTH),f.height(i));let m=t.findOne(".clip-cover-container");if(m){m.x(this.RESIZE_AREA_WIDTH),m.y(2),m.clip({x:0,y:0,width:d,height:u});const b=m.findOne(".clip-cover-background");if(b&&(b.width(d),b.height(u),r)){const v=o?r.clipSelectedCoverBackground||r.clipCoverBackground||"#FFF2A0":r.clipCoverBackground||"#FFF2A0";new Q.Tween({node:b,duration:.2,fill:v,easing:Q.Easings.EaseInOut}).play()}}else{m=this.createGroup(this.RESIZE_AREA_WIDTH,2),m.name("clip-cover-container"),m.clip({x:0,y:0,width:d,height:u}),t.add(m);const b=o?(r==null?void 0:r.clipSelectedCoverBackground)||(r==null?void 0:r.clipCoverBackground)||"#FFF2A0":(r==null?void 0:r.clipCoverBackground)||"#FFF2A0",v=this.createRect(0,0,d,u,b,"transparent",0);v.cornerRadius(2),v.name("clip-cover-background"),m.add(v)}const _=h&&h.length>0?h:void 0;let C=m.findOne(".clip-covers-group");C||(C=this.createGroup(0,0),C.name("clip-covers-group"),m.add(C)),_&&this.renderClipCovers(C,_,d,u,l);const S=t.findOne(".clip-label");if(S){const b=this.formatDuration(n),v=`${s} ${b}`;if(S.text(v),S.y(i-15),S.width(d),r){const P=o&&r.clipSelectedName||r.clipName;S.fill(P)}}}static createSelectionEffect(t,e,i,s){return new Q.Rect({x:t,y:e,width:i,height:s,stroke:"#50E3C2",strokeWidth:2,dash:[5,5],fillEnabled:!1})}static timeToPixels(t,e){return t/1e3*e}static async renderClipCovers(t,e,i,s,n){var o;M.debug("KonvaUtils","renderClipCovers",{videoSrc:n,coverSource:e,coverWidth:i,coverHeight:s});const r=t.find(".cover-image");if(e&&e.length>0){const h=new Set(e),l=new Map;let c=null;const u=n||(e.length>0?e[0]:""),d=await ft.getKeyframeDimensions(u,e[0]);if(d){const f=d.width/d.height;c=s*f}let p=0;for(let f=0;f<r.length;f++){const m=r[f],_=(o=m.attrs.image)==null?void 0:o.src;_&&h.has(_)?l.set(_,m):m.remove()}for(let f=0;f<e.length;f++){const m=e[f];let _=l.get(m);if(!_){const C=ft.getCachedImage(m);_=new Q.Image({image:C,cornerRadius:2,name:"cover-image"}),t.add(_),C.src||(C.src=m)}if(c&&_)_.width(c),_.height(s),_.x(f*c+f*p),_.y(0);else if(_){const C=n||m;ft.getKeyframeDimensions(C,m).then(S=>{if(!_)return;const b=S.width/S.height,v=s,P=v*b;_.width(P),_.height(v),_.x(f*P+f*p),_.y(0)}).catch(S=>{if(!_)return;console.warn(`Failed to get keyframe dimensions: ${S}, using default dimensions`);const b=s,v=b*(16/9);_.width(v),_.height(b),_.x(f*v+f*p),_.y(0)})}}}else e&&e.length===0&&t&&t.destroyChildren()}static pixelsToTime(t,e){return t/e*1e3}};A(ft,"RESIZE_AREA_WIDTH",8),A(ft,"keyframeDimensionsCache",{}),A(ft,"imageCache",{}),A(ft,"MAX_CACHE_SIZE",100);let tt=ft;const kt={MIN:1,MEDIUM:50,MAX:100},wr={DURATION:300},ct=15;class qi{constructor(t,e,i,s,n,r){A(this,"stage");A(this,"gridLayer");A(this,"config");A(this,"theme");A(this,"isDragging",!1);A(this,"startDragX",0);A(this,"scrollLeft",0);A(this,"timeScaleHeight",40);A(this,"onTimeChange");A(this,"onZoomChange");A(this,"onScrollChange");A(this,"animationFrameId",null);A(this,"isZooming",!1);A(this,"leftPadding",ct);this.stage=t,this.gridLayer=e,this.onTimeChange=s,this.onZoomChange=n,this.onScrollChange=r,this.config={duration:i.duration||36e5,zoom:i.zoom||kt.MEDIUM,currentTime:i.currentTime||0,playState:i.playState||"paused",container:i.container,theme:i.theme,timeScaleHeight:i.timeScaleHeight},this.theme=this.config.theme||fe,i.timeScaleHeight&&(this.timeScaleHeight=i.timeScaleHeight),this.initEventListeners(),this.render()}initEventListeners(){this.stage.on("wheel",t=>{if(t.evt.preventDefault(),t.evt.shiftKey){console.log("Shift+wheel event:",{deltaX:t.evt.deltaX,deltaY:t.evt.deltaY,shiftKey:t.evt.shiftKey});const i=(t.evt.deltaX||t.evt.deltaY)*1.5,s=Math.max(0,this.scrollLeft+i);s!==this.scrollLeft&&(console.log("Updating horizontal scroll"),this.animateHorizontalScroll(s))}else this.handleZoom(t)}),this.stage.on("click",t=>{t.target.getLayer()===this.gridLayer&&this.handleClick(t.evt.offsetX)}),this.stage.on("mousedown",t=>{t.target.getLayer()===this.gridLayer&&(this.isDragging=!0,this.startDragX=t.evt.clientX)}),this.stage.on("mousemove",t=>{if(this.isDragging){const e=t.evt.clientX-this.startDragX,i=this.scrollLeft;this.scrollLeft-=e,this.scrollLeft=Math.max(0,this.scrollLeft),this.startDragX=t.evt.clientX,this.render(),this.scrollLeft!==i&&this.onScrollChange(this.scrollLeft)}}),this.stage.on("mouseup",()=>{this.isDragging=!1}),this.stage.on("mouseleave",()=>{this.isDragging=!1})}handleZoom(t){if(this.isZooming)return;const i=t.evt.deltaY>0?.5:1.5,s=Math.max(kt.MIN,Math.min(kt.MAX,this.config.zoom*i));if(s!==this.config.zoom){const n=t.evt.offsetX;this.animateZoom(s,n)}}animateZoom(t,e){this.isZooming=!0;const i=this.config.zoom,s=wr.DURATION,n=Date.now(),r=this.pixelToTime(e),o=()=>{const h=Date.now()-n,l=Math.min(h/s,1),c=this.easeOutCubic(l),u=i+(t-i)*c,d=X.timeToPixels(r,u),p=Math.max(0,d-(e-this.leftPadding));if(this.scrollLeft=p,this.config.zoom=u,this.onZoomChange(u),this.onScrollChange(p),this.render(),l<1)this.animationFrameId=requestAnimationFrame(o);else{const f=X.timeToPixels(r,t),m=Math.max(0,f-(e-this.leftPadding));this.config.zoom=t,this.scrollLeft=m,this.onZoomChange(t),this.onScrollChange(m),this.render(),this.isZooming=!1}};this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),o()}animateHorizontalScroll(t){const e=this.scrollLeft,i=300,s=Date.now();this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null);const n=()=>{const r=Date.now()-s,o=Math.min(r/i,1),h=this.easeOutCubic(o),l=e+(t-e)*h;this.scrollLeft=Math.max(0,l),this.onScrollChange(this.scrollLeft),this.render(),o<1?this.animationFrameId=requestAnimationFrame(n):(this.scrollLeft=Math.max(0,t),this.onScrollChange(this.scrollLeft),this.render())};n()}easeOutCubic(t){return 1-Math.pow(1-t,3)}handleClick(t){const e=this.pixelToTime(t);this.setCurrentTime(e)}pixelToTime(t){return X.pixelsToTime(t-this.leftPadding+this.scrollLeft,this.config.zoom)}timeToPixel(t){return X.timeToPixels(t,this.config.zoom)-this.scrollLeft+this.leftPadding}setCurrentTime(t){this.config.currentTime=Math.max(0,t),this.onTimeChange(this.config.currentTime)}setZoom(t){this.config.zoom=t,this.render()}setDuration(t){this.config.duration=t,this.render()}setPlayState(t){this.config.playState=t,this.render()}update(){this.render()}render(){const t=this.stage.width(),e=this.stage.height(),i=this.gridLayer.findOne(".timeline-background");if(i)i.width(t),i.height(e),i.fill(this.theme.background),i.stroke(this.theme.border);else{const s=tt.createRect(0,0,t,e,this.theme.background,this.theme.border,1);s.name("timeline-background"),this.gridLayer.add(s)}this.gridLayer.find(".grid-line").forEach(s=>s.remove()),this.gridLayer.find(".time-tick-line").forEach(s=>s.remove()),this.gridLayer.find(".time-tick-text").forEach(s=>s.remove()),this.renderTimeTicks(),this.gridLayer.batchDraw()}renderTimeTicks(){const t=this.stage.width(),e=this.scrollLeft,i=this.scrollLeft+t,s=X.pixelsToTime(e,this.config.zoom),n=X.pixelsToTime(i,this.config.zoom),r=X.msToSeconds(s),o=X.msToSeconds(n),h=10,l=r-h,c=o+h,{majorStep:u,minorStep:d}=X.getTickConfig(this.config.zoom),p=X.generateVisibleTicks(l,c,u,d);let f=0;const m=20;for(const _ of p){const C=this.timeToPixel(_.time);C>=-m&&C<=t+m&&(tt.drawTimeTick(this.gridLayer,C,0,this.timeScaleHeight,_.time,{timeTick:this.theme.timeTick,timeText:this.theme.timeText},_.type,this.timeScaleHeight),f++)}M.debug("Timeline",`📌 Timeline - scrollLeft: ${this.scrollLeft}px, zoom: ${this.config.zoom}px/s, visible time: ${Math.round(r)}s to ${Math.round(o)}s, ticks: ${p.length} generated, ${f} drawn`)}getConfig(){return{...this.config}}getScrollLeft(){return this.scrollLeft}setScrollLeft(t){this.scrollLeft=t,this.render()}scrollToTime(t){const e=X.timeToPixels(t,this.config.zoom),i=this.stage.width(),s=Math.max(0,e-i/2);this.setScrollLeft(s),this.onScrollChange(s)}scrollToClip(t){const e=X.timeToPixels(t.startTime,this.config.zoom),s=X.timeToPixels(t.startTime+t.duration,this.config.zoom)-e,n=this.stage.width();let r;s<=n?r=Math.max(0,e-(n-s)/2):r=Math.max(0,e),this.setScrollLeft(r),this.onScrollChange(r)}getStage(){return this.stage}getGridLayer(){return this.gridLayer}resize(t,e){this.render()}}class ue{constructor(t,e,i){A(this,"clip");A(this,"onUpdate");A(this,"onSplit");A(this,"isMoving",!1);A(this,"dragStartPos",{x:0,y:0});A(this,"originalStart",0);A(this,"originalDuration",0);A(this,"originalStartTimeAtSource",0);A(this,"originalEndTimeAtSource",0);A(this,"originalOpacity",1);this.clip={...t,endTime:X.calculateEndTime(t.startTime,t.duration),isDragging:!1,isResizingLeft:!1,isResizingRight:!1,isSelected:!1,isResizing:!1,zIndex:1,opacity:1},this.onUpdate=e,this.onSplit=i}checkCollision(t,e,i){const s=t+e;return i.find(r=>{if(r.id===this.clip.id)return!1;const o=r.startTime+r.duration;return t<o&&r.startTime<s})}checkBoundary(t,e,i,s){return!(s<0||i<1e3||t<0||e>this.clip.sourceDuration)}getCenterTime(){return this.clip.startTime+this.clip.duration/2}getClip(){return{...this.clip}}setSelected(t){this.clip={...this.clip,isSelected:t},this.onUpdate(this.clip)}isPointInClip(t,e,i,s,n,r){const o=X.timeToPixels(this.clip.startTime,i)-r+ct,h=X.timeToPixels(this.clip.duration,i);return t>=o&&t<=o+h&&e>=s&&e<=s+n}isPointInResizeHandle(t,e,i,s,n,r){const o=X.timeToPixels(this.clip.startTime,i)-r+ct,h=X.timeToPixels(this.clip.duration,i),l=8;return e<s||e>s+n?(this.clip={...this.clip,isResizingLeft:!1,isResizingRight:!1},M.debug("Clip","Not in clip area",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,trackY:s,trackHeight:n}),!1):t>=o&&t<=o+l?(this.clip={...this.clip,isResizingLeft:!0,isResizingRight:!1},M.debug("Clip","Left resize handle detected",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,handleSize:l}),!0):t>=o+h-l&&t<=o+h?(this.clip={...this.clip,isResizingLeft:!1,isResizingRight:!0},M.debug("Clip","Right resize handle detected",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,handleSize:l}),!0):(this.clip={...this.clip,isResizingLeft:!1,isResizingRight:!1},M.debug("Clip","Not in resize handle",{clipId:this.clip.id,x:t,y:e,clipX:o,clipWidth:h,handleSize:l}),!1)}startDrag(t){this.dragStartPos=t,this.originalStart=this.clip.startTime,this.originalDuration=this.clip.duration,this.originalStartTimeAtSource=this.clip.startTimeAtSource,this.originalEndTimeAtSource=this.clip.endTimeAtSource,this.isMoving=!0,this.originalOpacity=this.clip.opacity,this.clip={...this.clip,isDragging:!0,isResizingLeft:!1,isResizingRight:!1,opacity:.5,zIndex:1e3},this.onUpdate(this.clip),M.debug("Clip","startDrag",{pos:t,clip:this.clip,isMoving:this.isMoving,originalOpacity:this.originalOpacity})}startResize(t){this.dragStartPos=t,this.originalStart=this.clip.startTime,this.originalDuration=this.clip.duration,this.originalStartTimeAtSource=this.clip.startTimeAtSource,this.originalEndTimeAtSource=this.clip.endTimeAtSource,this.clip={...this.clip,isDragging:!0,zIndex:1e3},this.onUpdate(this.clip),M.debug("Clip","startResize",{pos:t,clip:this.clip})}drag(t,e,i=[],s=!1){if(!this.clip.isDragging)return!1;M.debug("Clip","拖拽");const n=t.x-this.dragStartPos.x,r=X.pixelsToTime(n,e);M.debug("Clip","deltaX",n),M.debug("Clip","deltaTime",r);let o=this.originalStart,h=this.originalDuration,l=this.originalStartTimeAtSource,c=this.originalEndTimeAtSource,u="move";if(this.clip.isResizingLeft){const C=Math.max(0,this.originalStart+r)-this.originalStart,b=Math.max(0,this.originalStartTimeAtSource+r)-this.originalStartTimeAtSource,v=Math.abs(C),P=Math.abs(b),x=v<P?C:b;o=this.originalStart+x,h=this.originalDuration-x;const D=X.calculateEndTime(this.originalStart,this.originalDuration);h<1e3?(h=1e3,o=D-h,l=this.originalEndTimeAtSource-h):l=this.originalStartTimeAtSource+x,c=this.originalEndTimeAtSource,u="resize-left",M.debug("Clip","Resize left",{operation:u,clipId:this.clip.id,originalStartTimeAtSource:this.originalStartTimeAtSource,newStartTimeAtSource:l,deltaTime:r,actualDeltaTime:x,timelineDeltaTime:C,sourceDeltaTime:b,newDuration:h,newEndTimeAtSource:c})}else this.clip.isResizingRight?(h=Math.max(1e3,this.originalDuration+r),l=this.originalStartTimeAtSource,c=Math.min(this.clip.sourceDuration,l+h),h=c-l,u="resize-right",M.debug("Clip","Resize right",{operation:u,clipId:this.clip.id,originalStartTimeAtSource:this.originalStartTimeAtSource,newStartTimeAtSource:l,deltaTime:r,newDuration:h,newEndTimeAtSource:c})):(o=Math.max(0,this.originalStart+r),u="move");let d=X.calculateEndTime(o,h),p=!0,f;if(s&&!this.isMoving){if(p=this.checkBoundary(l,c,h,o),!p)return M.debug("Clip",`Boundary check failed - ${u}`,{clipId:this.clip.id,operation:u,newStart:o,newDuration:h,newStartTimeAtSource:l,newEndTimeAtSource:c,deltaX:n,deltaTime:r}),!1;if(f=this.checkCollision(o,h,i),f){const _=f.startTime+f.duration;let C=!1;if(this.clip.isResizingLeft||this.clip.isResizingRight){if(this.clip.isResizingLeft){if(M.debug("Clip","Resizing left with collision",{clipId:this.clip.id,collisionClip:f,newStart:o,collisionEndTime:_}),o<=_){const S=_,b=d-S;if(b>=1e3){const v=S-o;o=S,h=b,l+=v,d=X.calculateEndTime(o,h),C=!0,M.debug("Clip","Resizing left adjusted to avoid collision",{clipId:this.clip.id,newStart:o,newDuration:h,newStartTimeAtSource:l})}}}else if(this.clip.isResizingRight&&(M.debug("Clip","Resizing right with collision",{clipId:this.clip.id,collisionClip:f,newEndTime:d,collisionStart:f.startTime}),d>=f.startTime)){const S=f.startTime-o;S>=1e3&&(h=S,c=l+h,d=X.calculateEndTime(o,h),C=!0,M.debug("Clip","Resizing right adjusted to avoid collision",{clipId:this.clip.id,newDuration:h,newEndTimeAtSource:c}))}}if(!C)return M.debug("Clip","Collision check failed",{clipId:this.clip.id,collisionClip:f,otherClips:i,operation:u,newStart:o,newDuration:h,newStartTimeAtSource:l,newEndTimeAtSource:c,deltaX:n,deltaTime:r}),!1}}return this.clip={...this.clip,startTime:o,duration:h,endTime:d,startTimeAtSource:l,endTimeAtSource:c},M.debug("Clip","Successful update",{clipId:this.clip.id,operation:u,deltaX:n,deltaTime:r,newStart:o,newDuration:h,newEndTime:d,boundaryCheckPassed:p,collisionCheckPassed:f}),!0}endDrag(){M.debug("Clip","Drag operation ended",{clipId:this.clip.id,finalStart:this.clip.startTime,finalDuration:this.clip.duration,finalEndTime:this.clip.endTime}),this.clip={...this.clip,isDragging:!1,isResizingLeft:!1,isResizingRight:!1,opacity:this.isMoving?this.originalOpacity:this.clip.opacity,zIndex:1},this.isMoving=!1}split(t){t>this.clip.startTime+1&&t<this.clip.endTime-1&&this.onSplit(this.clip,t)}}class $i{constructor(t,e,i,s,n,r,o,h,l,c,u){A(this,"layer");A(this,"trackGroup");A(this,"config");A(this,"theme");A(this,"clips",[]);A(this,"clipGroups",new Map);A(this,"zoom",100);A(this,"scrollLeft",0);A(this,"trackY",0);A(this,"trackHeight",64);A(this,"selectedClip",null);A(this,"originalClipsState",[]);A(this,"nonDraggedClips",[]);A(this,"isVisualUpdate",!1);A(this,"onClipUpdate");A(this,"onClipAdd");A(this,"onClipRemove");A(this,"onClipSplit");A(this,"onClipSelect");this.layer=t,this.config=e,this.theme=r,this.zoom=i,this.trackY=s,this.trackHeight=n,this.onClipUpdate=o,this.onClipAdd=h,this.onClipRemove=l,this.onClipSplit=c,this.onClipSelect=u,this.trackGroup=tt.createGroup(0,s),this.layer.add(this.trackGroup),this.initClips(),this.initEventListeners(),this.render()}initClips(){this.clips=this.config.clips.map(t=>{const e=new ue(t,this.handleClipUpdate.bind(this),this.handleClipSplit.bind(this));return this.createClipGroup(t),e})}initEventListeners(){const t=this.layer.getStage();t&&(t.on("mousemove",e=>{this.handleStageMouseMove(e.evt)}),t.on("mouseup",()=>{this.handleClipMouseUp()}))}createClipGroup(t){const e=tt.timeToPixels(t.startTime,this.zoom)-this.scrollLeft+ct,i=tt.timeToPixels(t.duration,this.zoom),s=2,n=this.trackHeight-4,r=tt.createClipGroup(e,s,i,n,t.name,t.duration,this.theme,!1,t.thumbnails,t.src);r.name(`clip-${t.id}`),r.on("click",()=>{this.handleClipClick(t.id)}),r.on("mousedown",o=>{this.handleClipMouseDown(t.id,o.evt)}),r.on("mousemove",()=>{this.handleClipMouseMove()}),r.on("mouseleave",()=>{this.handleClipMouseLeave()}),this.trackGroup.add(r),this.clipGroups.set(t.id,r)}handleClipClick(t){const e=this.clips.find(i=>i.getClip().id===t);e&&(this.clips.forEach(i=>{i.setSelected(!1),this.updateClipVisualState(i.getClip().id,!1)}),e.setSelected(!0),this.selectedClip=e,this.updateClipVisualState(e.getClip().id,!0),this.onClipSelect(e.getClip()),this.render())}handleClipMouseDown(t,e){var s;M.debug("VideoTrack","Mouse down on clip",{clipId:t,evt:e}),this.clips.sort((n,r)=>n.getClip().startTime-r.getClip().startTime),M.debug("VideoTrack","Clips sorted by start time",{clipCount:this.clips.length}),this.originalClipsState=this.clips.map(n=>({...n.getClip()})),M.debug("VideoTrack","Recorded original clips state",{clipCount:this.originalClipsState.length}),this.nonDraggedClips=this.clips.filter(n=>n.getClip().id!==t).map(n=>({...n.getClip()})),M.debug("VideoTrack","Recorded non-dragged clips",{clipCount:this.nonDraggedClips.length});const i=this.clips.find(n=>n.getClip().id===t);if(i){this.clips.forEach(c=>{c.setSelected(!1),this.updateClipVisualState(c.getClip().id,!1)}),i.setSelected(!0),this.selectedClip=i,M.debug("VideoTrack","Clip selected",{clipId:t,selectedClipId:(s=this.selectedClip)==null?void 0:s.getClip().id});const n=this.layer.getStage();if(!n){M.debug("VideoTrack","Stage not found",{clipId:t});return}const r=n.container();if(!r){M.debug("VideoTrack","Container not found",{clipId:t});return}const o=r.getBoundingClientRect(),h=e.clientX-o.left,l=e.clientY-o.top;M.debug("VideoTrack","Calculated mouse position",{clipId:t,x:h,y:l,clientX:e.clientX,clientY:e.clientY,rect:o}),i.isPointInResizeHandle(h,l,this.zoom,this.trackY,this.trackHeight,this.scrollLeft)?(i.startResize({x:h,y:l}),M.debug("VideoTrack","Started resize operation",{clipId:t,x:h,y:l})):(i.startDrag({x:h,y:l}),M.debug("VideoTrack","Started drag operation",{clipId:t,x:h,y:l})),this.updateClipVisualState(i.getClip().id,!0),this.render()}else M.debug("VideoTrack","Clip not found",{clipId:t})}handleClipMouseMove(){}handleClipMouseUp(){if(M.debug("VideoTrack","Mouse up detected",{selectedClip:this.selectedClip}),this.selectedClip){const t=this.selectedClip.getClip();M.debug("VideoTrack","Processing release for clip",{clipId:t.id}),this.selectedClip.endDrag(),this.handleClipMoveEnd(t),this.selectedClip=null,M.debug("VideoTrack","Clip drag ended successfully"),this.layer.batchDraw()}else M.debug("VideoTrack","No selected clip to process")}handleClipMoveEnd(t){M.debug("VideoTrack","handleClipMoveEnd-拖拽结束",{startTime:t.startTime,clipId:t.id});const e=[...this.nonDraggedClips];M.debug("VideoTrack","Initial processed clips",{clipCount:e.length});let i=e.findIndex(s=>s.startTime>=t.startTime);i===-1&&(i=e.length),M.debug("VideoTrack","Calculated insert index",{insertIndex:i,draggedStartTime:t.startTime}),e.splice(i,0,{...t,opacity:1}),M.debug("VideoTrack","Drag clip inserted",{insertIndex:i,clipId:t.id,insertedStartTime:t.startTime}),this.adjustClipsForOverlap(e,i),this.updateAllClips(e),this.buildAndSendUpdates(t,e)}adjustClipsForOverlap(t,e){M.debug("VideoTrack","adjustClipsForOverlap-开始调整重叠",{startIndex:e,totalClips:t.length});for(let i=e;i<t.length;i++){if(i===0)continue;const s=t[i],n=t[i-1],r=n.startTime+n.duration;if(s.startTime<r&&(s.startTime=r,s.endTime=s.startTime+s.duration,M.debug("VideoTrack","adjustClipsForOverlap-调整片段位置",{clipId:s.id,oldStartTime:s.startTime-r+s.startTime,newStartTime:s.startTime})),i+1<t.length){const o=t[i+1],h=s.startTime+s.duration;if(h+s.duration<o.startTime){M.debug("VideoTrack","adjustClipsForOverlap-检测到无重叠区域,终止计算",{currentEndTime:h,nextClipStartTime:o.startTime});break}}}}updateAllClips(t){M.debug("VideoTrack","updateAllClips-开始批量更新",{clipCount:t.length}),this.isVisualUpdate=!0,t.forEach(e=>{this.clips.find(s=>s.getClip().id===e.id)&&this.handleClipUpdate(e)}),this.isVisualUpdate=!1,this.clips.sort((e,i)=>e.getClip().startTime-i.getClip().startTime),M.debug("VideoTrack","updateAllClips-更新完成并重新排序",{finalClipCount:this.clips.length})}buildAndSendUpdates(t,e){M.debug("VideoTrack","buildAndSendUpdates-开始构建更新数据",{draggedClipId:t.id});const i=this.originalClipsState.map(s=>{const n=e.find(r=>r.id===s.id);return n&&(s.startTime!==n.startTime||s.duration!==n.duration||s.opacity!==n.opacity)?{clipId:s.id,previousState:s,newState:n}:null}).filter(s=>s!==null);M.debug("VideoTrack","buildAndSendUpdates-构建完成",{updateCount:i.length}),i.length>0&&this.onClipUpdate(t,this.originalClipsState.find(s=>s.id===t.id),i)}handleStageMouseMove(t){const e=this.layer.getStage();if(!e)return;const i=e.container();if(!i)return;const s=i.getBoundingClientRect(),n=t.clientX-s.left,r=t.clientY-s.top;if(this.selectedClip){const o=this.clips.map(l=>l.getClip()).filter(l=>{var c;return l.id!==((c=this.selectedClip)==null?void 0:c.getClip().id)});if(this.selectedClip.drag({x:n,y:r},this.zoom,o,!0)){const l=this.selectedClip.getClip();this.updateClipGroup(l),this.layer.batchDraw()}}else{let o=!1;for(const h of this.clips){const l=h.getClip(),c=tt.timeToPixels(l.startTime,this.zoom)-this.scrollLeft+ct,u=tt.timeToPixels(l.duration,this.zoom);if(n>=c&&n<=c+tt.RESIZE_AREA_WIDTH&&r>=this.trackY&&r<=this.trackY+this.trackHeight){i.style.cursor="ew-resize",o=!0;break}if(n>=c+u-tt.RESIZE_AREA_WIDTH&&n<=c+u&&r>=this.trackY&&r<=this.trackY+this.trackHeight){i.style.cursor="ew-resize",o=!0;break}if(n>c+tt.RESIZE_AREA_WIDTH&&n<c+u-tt.RESIZE_AREA_WIDTH&&r>=this.trackY&&r<=this.trackY+this.trackHeight){i.style.cursor="pointer",o=!0;break}}o||(i.style.cursor="default")}}handleClipMouseLeave(){if(!this.selectedClip){const t=this.layer.getStage();t&&t.container()&&(t.container().style.cursor="default")}}updateClipVisualState(t,e){const i=this.clips.find(s=>s.getClip().id===t);if(i){const s=i.getClip();this.isVisualUpdate=!0,this.handleClipUpdate({...s,isDragging:e,isResizing:e,zIndex:e?2:1,opacity:e?.7:1}),this.isVisualUpdate=!1}}updateClipGroup(t){var i;const e=this.clipGroups.get(t.id);if(e){const s=tt.timeToPixels(t.startTime,this.zoom)-this.scrollLeft+ct,n=tt.timeToPixels(t.duration,this.zoom);e.x(s);const r=((i=this.selectedClip)==null?void 0:i.getClip().id)===t.id;(t.isDragging||r)&&e.moveToTop(),tt.updateClipGroup(e,n,this.trackHeight-4,t.name,t.duration,this.theme,r,t.thumbnails,t.src)}}handleClipUpdate(t){const e=this.clips.findIndex(i=>i.getClip().id===t.id);if(M.debug("VideoTrack","更新片段",{clipId:t.id,isDragging:t.isDragging,zIndex:t.zIndex}),e!==-1){const i=this.clips[e].getClip();this.clips[e]=new ue(t,this.handleClipUpdate.bind(this),this.handleClipSplit.bind(this)),this.updateClipGroup(t);const s=this.clipGroups.get(t.id);s&&s.opacity(t.opacity),this.isVisualUpdate||this.onClipUpdate(t,i),this.layer.batchDraw()}}handleClipSplit(t,e){const i=e-t.startTime,s=t.duration-i,n=t.startTimeAtSource+i,r={...t,duration:i,endTime:e,endTimeAtSource:n},o={...t,id:`${t.id}_split_${Date.now()}`,startTime:e,duration:s,endTime:X.calculateEndTime(e,s),startTimeAtSource:n,endTimeAtSource:t.endTimeAtSource};this.removeClip(t.id),this.addClip(r),this.addClip(o),this.onClipSplit(r,o),this.layer.batchDraw()}addClip(t){const e=new ue(t,this.handleClipUpdate.bind(this),this.handleClipSplit.bind(this));this.clips.push(e),this.createClipGroup(t),this.onClipAdd(t),this.layer.batchDraw()}removeClip(t){const e=this.clips.findIndex(i=>i.getClip().id===t);if(e!==-1){this.clips.splice(e,1);const i=this.clipGroups.get(t);i&&(i.remove(),this.clipGroups.delete(t)),this.onClipRemove(t),this.layer.batchDraw()}}updateClip(t,e){const i=this.clips.find(s=>s.getClip().id===t);if(i){const s={...i.getClip(),...e};this.handleClipUpdate(s)}}setZoom(t){this.zoom=t,this.clips.forEach(e=>{this.updateClipGroup(e.getClip())}),this.layer.batchDraw()}setCurrentTime(t){this.layer.batchDraw()}setScrollLeft(t){this.scrollLeft=t,this.clips.forEach(e=>{const i=e.getClip();this.updateClipGroup(i),this.updateClipVisibility(i)}),this.layer.batchDraw()}updateClipVisibility(t){const e=this.clipGroups.get(t.id);if(e){const i=tt.timeToPixels(t.startTime,this.zoom)-this.scrollLeft+ct,s=tt.timeToPixels(t.duration,this.zoom),n=i+s>0&&i<this.layer.width();e.visible(n)}}setTrackY(t){this.trackY=t,this.trackGroup.y(t),this.layer.batchDraw()}render(){if(this.trackGroup.children.length===0){const t=tt.createRect(0,0,this.layer.width(),this.trackHeight,this.theme.trackBackground,this.theme.trackBorder,1);t.name("track-background"),this.trackGroup.add(t)}else{const t=this.trackGroup.findOne(".track-background");t&&(t.width(this.layer.width()),t.fill(this.theme.trackBackground),t.stroke(this.theme.trackBorder))}this.layer.batchDraw()}getClips(){return this.clips.map(t=>t.getClip())}getSelectedClip(){return this.selectedClip?this.selectedClip.getClip():null}selectClip(t){const e=this.clips.find(i=>i.getClip().id===t);e&&(this.clips.forEach(i=>{i.setSelected(!1),this.updateClipVisualState(i.getClip().id,!1)}),e.setSelected(!0),this.selectedClip=e,this.clips.forEach(i=>{this.updateClipGroup(i.getClip())}),this.onClipSelect(e.getClip()),this.layer.batchDraw())}splitSelectedClip(t){const e=this.clips.find(i=>{const s=i.getClip();return t>=s.startTime&&t<s.endTime});e&&e.split(t)}removeClipGaps(){M.debug("VideoTrack","Removing clip gaps");const t=this.clips.map(i=>i.getClip()).sort((i,s)=>i.startTime-s.startTime);if(t.length<=1)return;let e=t[0].startTime+t[0].duration;for(let i=1;i<t.length;i++){const s=t[i];if(e-s.startTime<0){const r=e,o=r+s.duration;this.handleClipUpdate({...s,startTime:r,endTime:o}),e=o}else e=s.startTime+s.duration}}getTrackGroup(){return this.trackGroup}getId(){return this.config.id||"default"}}class Ki{constructor(t,e,i,s,n,r){A(this,"layer");A(this,"playheadGroup");A(this,"playheadLine");A(this,"playheadTriangle");A(this,"theme");A(this,"currentTime",0);A(this,"zoom",100);A(this,"scrollLeft",0);A(this,"onTimeChange");A(this,"isDragging",!1);this.layer=t,this.currentTime=e,this.zoom=i,this.theme=n,this.onTimeChange=r,this.playheadGroup=tt.createGroup(),this.layer.add(this.playheadGroup),this.playheadLine=tt.createLine([0,0,0,s],this.theme.playhead,1),this.playheadGroup.add(this.playheadLine),this.playheadTriangle=new Q.RegularPolygon({x:0,y:5,sides:3,radius:10,fill:this.theme.playhead,rotation:180}),this.playheadGroup.add(this.playheadTriangle),this.initEventListeners(),this.render()}initEventListeners(){var t,e,i;this.playheadGroup.on("mousedown",()=>{this.isDragging=!0}),(t=this.layer.getStage())==null||t.on("mousemove",s=>{this.isDragging&&this.handleMouseMove(s.evt)}),(e=this.layer.getStage())==null||e.on("mouseup",()=>{this.isDragging=!1}),(i=this.layer.getStage())==null||i.on("mouseleave",()=>{this.isDragging=!1})}handleMouseMove(t){if(!this.isDragging)return;const e=this.layer.getStage();if(!e)return;const i=e.container();if(!i)return;const s=i.getBoundingClientRect(),n=t.clientX-s.left,r=X.pixelsToTime(n-ct+this.scrollLeft,this.zoom);this.setTime(r)}setTime(t){this.currentTime=Math.max(0,t),this.onTimeChange(this.currentTime),this.render()}setZoom(t){this.zoom=t,this.render()}setScrollLeft(t){this.scrollLeft=t,this.render()}setHeight(t){this.playheadLine.points([0,0,0,t]),this.render()}render(){const t=X.timeToPixels(this.currentTime,this.zoom)-this.scrollLeft+ct;this.playheadGroup.x(t),this.playheadGroup.visible(t>=0&&t<=this.layer.width()),this.layer.batchDraw()}getTime(){return this.currentTime}getPlayheadGroup(){return this.playheadGroup}}class Zi{constructor(t,e,i,s=100){A(this,"state");A(this,"maxHistorySize",100);A(this,"onActionUndo");A(this,"onActionRedo");A(this,"onHistoryChange");this.state={past:[],future:[]},this.maxHistorySize=s,this.onActionUndo=t,this.onActionRedo=e,this.onHistoryChange=i}addAction(t){this.state.past.length>=this.maxHistorySize&&this.state.past.shift(),this.state.past.push({...t,timestamp:Date.now()}),this.state.future=[],this.onHistoryChange&&this.onHistoryChange()}undo(){if(this.state.past.length===0)return!1;const t=this.state.past.pop();return this.state.future.push(t),this.onActionUndo(t),this.onHistoryChange&&this.onHistoryChange(),!0}redo(){if(this.state.future.length===0)return!1;const t=this.state.future.pop();return this.state.past.push(t),this.onActionRedo(t),this.onHistoryChange&&this.onHistoryChange(),!0}clear(){this.state.past=[],this.state.future=[],this.onHistoryChange&&this.onHistoryChange()}canUndo(){return this.state.past.length>0}canRedo(){return this.state.future.length>0}getState(){return{...this.state}}createAddClipAction(t){return{type:"add_clip",data:t,timestamp:Date.now()}}createRemoveClipAction(t){return{type:"remove_clip",data:t,timestamp:Date.now()}}createUpdateClipAction(t,e,i){return{type:"update_clip",data:{clipId:t,updates:e,previousState:i},timestamp:Date.now()}}createSplitClipAction(t,e,i){return{type:"split_clip",data:{originalClip:t,clip1:e,clip2:i},timestamp:Date.now()}}createMoveClipAction(t,e,i){return{type:"move_clip",data:{clipId:t,newStartTime:e,previousStartTime:i},timestamp:Date.now()}}createResizeClipAction(t,e,i,s,n){return{type:"resize_clip",data:{clipId:t,newDuration:e,newStartTime:i,previousDuration:s,previousStartTime:n},timestamp:Date.now()}}createSetTimeAction(t,e){return{type:"set_time",data:{newTime:t,previousTime:e},timestamp:Date.now()}}createRemoveGapsAction(t){return{type:"remove_gaps",data:{clipsBefore:t},timestamp:Date.now()}}createMultiClipUpdateAction(t){return{type:"multi_clip_update",data:{clipUpdates:t},timestamp:Date.now()}}}const xr="1.0.4",kr={version:xr};class Ar{constructor(t={}){A(this,"timeline",null);A(this,"tracks",[]);A(this,"playhead",null);A(this,"history");A(this,"config");A(this,"eventListeners",new Map);A(this,"animationFrameId",null);A(this,"lastUpdateTime",0);A(this,"isInitialized",!1);A(this,"stage",null);A(this,"gridLayer",null);A(this,"trackLayer",null);A(this,"playheadLayer",null);A(this,"selectionLayer",null);A(this,"resizeObserver",null);A(this,"videoPreview",null);A(this,"isExecutingHistoryAction",!1);A(this,"lastTrackDuration",0);A(this,"thumbnailProvider",null);this.config={duration:t.duration||36e5,zoom:t.zoom||kt.MEDIUM,currentTime:t.currentTime||0,playState:t.playState||"paused",container:t.container,theme:t.theme,timeScaleHeight:t.timeScaleHeight,debug:t.debug,speed:t.speed||1,thumbnailProvider:t.thumbnailProvider},M.setDebugEnabled(!!this.config.debug),this.thumbnailProvider=t.thumbnailProvider||null,this.history=new Zi(this.handleActionUndo.bind(this),this.handleActionRedo.bind(this),()=>{this.emitEvent("history_change",{canUndo:this.history.canUndo(),canRedo:this.history.canRedo()})}),this.config.container&&this.init(this.config.container)}init(t){if(this.isInitialized){M.warn("TimelineManager","TimelineManager has already been initialized");return}this.stage=new Q.Stage({container:t,width:t.clientWidth,height:t.clientHeight}),this.resizeObserver=new ResizeObserver(s=>{for(const n of s){const{width:r,height:o}=n.contentRect;this.resize(Math.floor(r),Math.floor(o))}}),this.resizeObserver.observe(t),this.gridLayer=new Q.Layer({name:"gridLayer"}),this.trackLayer=new Q.Layer({name:"trackLayer"}),this.playheadLayer=new Q.Layer({name:"playheadLayer"}),this.selectionLayer=new Q.Layer({name:"selectionLayer"}),this.stage.add(this.gridLayer),this.stage.add(this.trackLayer),this.stage.add(this.playheadLayer),this.stage.add(this.selectionLayer),this.timeline=new qi(this.stage,this.gridLayer,this.config,this.handleTimeChange.bind(this),this.handleZoomChange.bind(this),this.handleScrollChange.bind(this)),this.playhead=new Ki(this.playheadLayer,this.config.currentTime,this.config.zoom,t.clientHeight,this.config.theme||fe,this.handleTimeChange.bind(this));const e=this.config.timeScaleHeight||40,i=new $i(this.trackLayer,{id:"1",clips:[]},this.config.zoom,e,60,this.config.theme||fe,(s,n,r)=>this.handleClipUpdate(s,n,r),this.handleClipAdd.bind(this),this.handleClipRemove.bind(this),this.handleClipSplit.bind(this),this.handleClipSelect.bind(this));this.tracks.push(i),this.isInitialized=!0,this.stage&&this.stage.batchDraw()}play(){this.config.playState!=="playing"&&(this.config.playState="playing",this.lastUpdateTime=Date.now(),this.animate(),this.emitEvent("play_state_change",{playState:this.config.playState}))}pause(){this.config.playState!=="paused"&&(this.config.playState="paused",this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.emitEvent("play_state_change",{playState:this.config.playState}))}togglePlay(){this.config.playState==="playing"?this.pause():this.play()}animate(){if(this.config.playState==="paused")return;const t=Date.now(),e=t-this.lastUpdateTime;this.lastUpdateTime=t;const i=this.config.currentTime+e*this.config.speed;this.setCurrentTime(i),this.animationFrameId=requestAnimationFrame(this.animate.bind(this))}setCurrentTime(t){const e=Math.max(0,t);e!==this.config.currentTime&&(this.config.currentTime=e,this.timeline&&this.timeline.setCurrentTime(e),this.playhead&&this.playhead.setTime(e),this.tracks.forEach(i=>i.setCurrentTime(e)),this.emitEvent("time_change",{time:e}))}getCurrentTime(){return this.config.currentTime}setZoom(t){const e=Math.max(kt.MIN,Math.min(kt.MAX,t));e!==this.config.zoom&&(this.config.zoom=e,this.timeline&&this.timeline.setZoom(e),this.playhead&&this.playhead.setZoom(e),this.tracks.forEach(i=>i.setZoom(e)),this.emitEvent("zoom_change",{zoom:e}))}getZoom(){return this.config.zoom}setSpeed(t){const e=Math.max(.1,Math.min(10,t));e!==this.config.speed&&(this.config.speed=e,this.emitEvent("speed_change",{speed:e}))}getSpeed(){return this.config.speed||1}setThumbnailProvider(t){this.thumbnailProvider=t,this.config.thumbnailProvider=t,this.getClips().forEach(i=>{if(!i.thumbnails)try{const s=t.getThumbnails(i);Array.isArray(s)?this.updateClip(i.id,{thumbnails:s}):s instanceof Promise&&s.then(n=>{Array.isArray(n)&&this.updateClip(i.id,{thumbnails:n})}).catch(n=>{M.warn("TimelineManager","Failed to get thumbnail for existing clip:",{error:n,clipId:i.id})})}catch(s){M.warn("TimelineManager","Error getting thumbnail for existing clip:",{error:s,clipId:i.id})}})}async addClip(t){let e=t.startTime;if(e===void 0){const c=this.getClips();c.length>0?e=Math.max(...c.map(u=>u.endTime)):e=0}const i=t.startTimeAtSource||0,s=t.duration,n=t.endTimeAtSource||i+s;let r=t.sourceDuration;if(!r)try{r=await X.getVideoDuration(t.src),r<=0&&(r=n)}catch(c){M.error("TimelineManager","Failed to get video duration:",{error:c}),r=n}let o=t.thumbnails;const h=t.id||`clip_${t.name}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;if(!o&&this.thumbnailProvider){const c={id:h,externalId:t.externalId,src:t.src,name:t.name,startTime:e,duration:s,startTimeAtSource:i,endTimeAtSource:n,sourceDuration:r,endTime:e+s,isDragging:!1,isResizing:!1,isResizingLeft:!1,isResizingRight:!1,isSelected:!1,zIndex:1,opacity:1,thumbnails:void 0,style:t.style};try{const u=this.thumbnailProvider.getThumbnails(c);Array.isArray(u)?o=u:u instanceof Promise&&u.then(d=>{Array.isArray(d)&&(o=d,this.updateClip(h,{thumbnails:o}))}).catch(d=>{M.warn("TimelineManager","Failed to get thumbnail:",{error:d})})}catch(u){M.warn("TimelineManager","Error getting thumbnail:",{error:u})}}const l={id:h,externalId:t.externalId,src:t.src,name:t.name,startTime:e,duration:s,startTimeAtSource:i,endTimeAtSource:n,sourceDuration:r,endTime:e+s,isDragging:!1,isResizing:!1,isResizingLeft:!1,isResizingRight:!1,isSelected:!1,zIndex:1,opacity:1,thumbnails:o,style:t.style};if(M.debug("TimelineManager","添加的片段:",{clip:l}),this.tracks.length>0){if(this.tracks[0].addClip(l),!this.isExecutingHistoryAction){const c=this.history.createAddClipAction(l);this.history.addAction(c)}this.checkTrackDurationChange()}return l.id}removeClip(t){if(!this.isExecutingHistoryAction){const e=this.getClips().find(i=>i.id===t);if(e){const i=this.history.createRemoveClipAction(e);this.history.addAction(i)}}this.tracks.forEach(e=>e.removeClip(t)),this.checkTrackDurationChange()}updateClip(t,e){this.tracks.forEach(i=>i.updateClip(t,e)),this.checkTrackDurationChange()}splitClip(t,e){const i=this.tracks.find(s=>s.getClips().some(n=>n.id===t));i&&(i.splitSelectedClip(e),this.checkTrackDurationChange())}splitCurrentClip(){const t=this.getCurrentTime(),e=this.tracks.find(i=>i.getClips().some(n=>t>=n.startTime&&t<n.endTime));e&&e.getClips().find(n=>t>=n.startTime&&t<n.endTime)&&(e.splitSelectedClip(t),this.checkTrackDurationChange())}getClips(){return this.tracks.flatMap(t=>t.getClips())}exportTimeline(){var i;const t=this.tracks.map(s=>({id:s.getId(),clips:s.getClips().map(n=>({id:n.id,externalId:n.externalId,src:n.src,name:n.name,startTime:Math.round(n.startTime),duration:Math.round(n.duration),endTime:Math.round(n.endTime),startTimeAtSource:Math.round(n.startTimeAtSource),endTimeAtSource:Math.round(n.endTimeAtSource),sourceDuration:Math.round(n.sourceDuration),thumbnails:n.thumbnails})).sort((n,r)=>n.startTime-r.startTime)})),e=((i=t[0].clips[0].thumbnails)==null?void 0:i[0])||"";return{version:this.getVersion(),exportTime:Date.now(),coverUrl:e,tracks:t}}getClipsData(){return this.getClips()}getVersion(){return kr.version}undo(){return this.history.undo()}redo(){return this.history.redo()}getHistoryState(){return this.history.getState()}fitZoom(){var h;const t=this.getClips();if(t.length===0)return;const e=Math.min(...t.map(l=>l.startTime)),s=(Math.max(...t.map(l=>l.endTime))-e)/1e3,n=((h=this.stage)==null?void 0:h.width())||0,r=n-ct*2;M.debug("TimelineManager","适合缩放:",{duration:s,containerWidth:n,availableWidth:r});const o=Math.min(r/s,kt.MAX);if(this.setZoom(o),this.timeline){const l=t.reduce((c,u)=>u.startTime<c.startTime?u:c);this.scrollToClip(l.id,{selectClip:!0})}}removeClipGaps(){const t=this.getClips().map(e=>({...e}));if(this.tracks.forEach(e=>e.removeClipGaps()),t.length>0){const e=this.history.createRemoveGapsAction(t);this.history.addAction(e)}this.checkTrackDurationChange()}handleTimeChange(t){this.setCurrentTime(t)}handleZoomChange(t){this.setZoom(t)}handleScrollChange(t){this.playhead&&this.playhead.setScrollLeft(t),this.tracks.forEach(e=>e.setScrollLeft(t))}handleClipUpdate(t,e,i){if(!this.isExecutingHistoryAction){if(i&&i.length>0){const s=this.history.createMultiClipUpdateAction(i);this.history.addAction(s)}else if(e){const s=e.startTime!==t.startTime&&e.duration===t.duration,n=e.duration!==t.duration;if(s){const r=this.history.createMoveClipAction(t.id,t.startTime,e.startTime);this.history.addAction(r)}else if(n){const r=this.history.createResizeClipAction(t.id,t.duration,t.startTime,e.duration,e.startTime);this.history.addAction(r)}}}this.emitEvent("clip_updated",{clip:t}),this.checkTrackDurationChange()}handleClipAdd(t){this.emitEvent("clip_added",{clip:t})}handleClipRemove(t){this.emitEvent("clip_removed",{clipId:t})}handleClipSplit(t,e){const i={...t,id:t.id.replace("_split_",""),duration:t.duration+e.duration,endTime:e.endTime,endTimeAtSource:e.endTimeAtSource},s=this.history.createSplitClipAction(i,t,e);this.history.addAction(s),this.emitEvent("clip_updated",{clip:t}),this.emitEvent("clip_added",{clip:e})}handleClipSelect(t){this.emitEvent("clip_selected",{clip:t})}handleActionUndo(t){switch(M.debug("TimelineManager","Undo action:",{action:t}),this.isExecutingHistoryAction=!0,t.type){case"add_clip":this.removeClip(t.data.id);break;case"remove_clip":this.tracks[0].addClip(t.data);break;case"update_clip":this.updateClip(t.data.clipId,t.data.previousState);break;case"split_clip":this.removeClip(t.data.clip1.id),this.removeClip(t.data.clip2.id),this.tracks[0].addClip(t.data.originalClip);break;case"move_clip":this.updateClip(t.data.clipId,{startTime:t.data.previousStartTime});break;case"resize_clip":this.updateClip(t.data.clipId,{duration:t.data.previousDuration,startTime:t.data.previousStartTime});break;case"remove_gaps":this.getClips().forEach(e=>this.removeClip(e.id)),t.data.clipsBefore.forEach(e=>{this.tracks[0].addClip(e)});break;case"multi_clip_update":t.data.clipUpdates.forEach(e=>{this.updateClip(e.clipId,e.previousState)});break;default:M.warn("TimelineManager","Unknown action type for undo:",{type:t.type})}this.isExecutingHistoryAction=!1,this.checkTrackDurationChange()}handleActionRedo(t){switch(M.debug("TimelineManager","Redo action:",{action:t}),this.isExecutingHistoryAction=!0,t.type){case"add_clip":this.tracks[0].addClip(t.data);break;case"remove_clip":this.removeClip(t.data.id);break;case"update_clip":this.updateClip(t.data.clipId,t.data.updates);break;case"split_clip":this.removeClip(t.data.originalClip.id),this.tracks[0].addClip(t.data.clip1),this.tracks[0].addClip(t.data.clip2);break;case"move_clip":this.updateClip(t.data.clipId,{startTime:t.data.newStartTime});break;case"resize_clip":this.updateClip(t.data.clipId,{duration:t.data.newDuration,startTime:t.data.newStartTime});break;case"remove_gaps":this.removeClipGaps();break;case"multi_clip_update":t.data.clipUpdates.forEach(e=>{this.updateClip(e.clipId,e.newState)});break;default:M.warn("TimelineManager","Unknown action type for redo:",{type:t.type})}this.isExecutingHistoryAction=!1,this.checkTrackDurationChange()}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}off(t,e){if(this.eventListeners.has(t)){const i=this.eventListeners.get(t).filter(s=>s!==e);this.eventListeners.set(t,i)}}emitEvent(t,e){this.eventListeners.has(t)&&this.eventListeners.get(t).forEach(i=>{try{i(t,e)}catch(s){M.error("TimelineManager",`Error in event listener for ${t}:`,{error:s})}})}getPlayState(){return this.config.playState}setDuration(t){this.config.duration=t,this.timeline&&this.timeline.setDuration(t)}getDuration(){return this.config.duration}resize(t,e){this.stage&&(this.stage.width(t),this.stage.height(e),this.timeline&&this.timeline.resize(t,e),this.playhead&&this.playhead.setHeight(e),this.tracks.forEach(()=>{}),this.stage.batchDraw())}scrollToTime(t,e=!1){this.timeline&&(this.timeline.scrollToTime(t),e&&this.setCurrentTime(t))}selectClip(t){const e=this.tracks.find(i=>i.getClips().some(s=>s.id===t));e&&e.selectClip(t)}scrollToClip(t,e={}){const{selectClip:i=!1,setCurrentTime:s=!1}=e,n=this.getClips().find(r=>r.id===t);!n||!this.timeline||(this.timeline.scrollToClip(n),s&&this.setCurrentTime(n.startTime),i&&this.selectClip(t))}getSelectedClip(){for(const t of this.tracks){const e=t.getSelectedClip();if(e)return e}return null}getCurrentClip(){return this.findClipAtTime(this.config.currentTime)}removeSelectedClip(){const t=this.getSelectedClip();return t?(this.removeClip(t.id),!0):!1}getTrackTotalDuration(){const t=this.getClips();if(t.length===0)return 0;const e=t.reduce((i,s)=>{const n=s.startTime+s.duration,r=i.startTime+i.duration;return n>r?s:i});return e.startTime+e.duration}destroy(){this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),this.videoPreview&&this.disconnectVideo(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.eventListeners.clear()}connectTo(t){let e;t instanceof HTMLVideoElement?e={videoElement:t,autoPlay:!1,volume:1}:e=t,this.videoPreview&&this.disconnectVideo(),this.videoPreview={videoElement:e.videoElement,currentClip:null,isPlaying:!1,lastUpdateTime:Date.now()},e.volume!==void 0&&(this.videoPreview.videoElement.volume=Math.max(0,Math.min(1,e.volume))),e.autoPlay&&this.videoPreview.videoElement.play().catch(i=>{M.warn("TimelineManager","Auto-play was prevented:",{err:i})}),this.on("time_change",this.handleVideoTimeUpdate.bind(this)),this.on("play_state_change",this.handlePlayStateChange.bind(this)),this.on("clip_added",this.handleClipChange.bind(this)),this.on("clip_removed",this.handleClipChange.bind(this)),M.debug("TimelineManager","TimelineManager connected to video element")}disconnectVideo(){this.videoPreview&&(this.off("time_change",this.handleVideoTimeUpdate.bind(this)),this.off("play_state_change",this.handlePlayStateChange.bind(this)),this.off("clip_added",this.handleClipChange.bind(this)),this.off("clip_removed",this.handleClipChange.bind(this)),this.videoPreview=null,M.debug("TimelineManager","TimelineManager disconnected from video element"))}clearHistory(){this.history.clear()}handleVideoTimeUpdate(t,e){if(!this.videoPreview)return;const i=this.videoPreview.videoElement,s=e.time;i.playbackRate=this.config.speed||1;const n=this.findClipAtTime(s);if(!this.videoPreview.currentClip||this.videoPreview.currentClip.id!==(n==null?void 0:n.id)?n?this.loadClipToVideo(n):(i.paused||i.pause(),i.src&&(i.src=""),this.videoPreview.currentClip=null):n&&this.config.playState==="playing"&&i.paused&&i.play().catch(r=>{M.warn("TimelineManager","Video play was prevented:",{err:r})}),n){const r=s-n.startTime,o=n.startTimeAtSource+r,h=this.config.speed||1,l=Math.max(100,h*150);Math.abs(i.currentTime*1e3-o)>l&&(i.currentTime=o/1e3,this.config.playState==="playing"&&i.paused&&setTimeout(()=>{this.config.playState==="playing"&&i.paused&&i.play().catch(c=>{M.warn("TimelineManager","Video play was prevented:",{err:c})})},50))}}handlePlayStateChange(t,e){if(!this.videoPreview)return;const i=this.videoPreview.videoElement;e.playState==="playing"?i.paused&&i.play().catch(s=>{M.warn("TimelineManager","Video play was prevented:",{err:s})}):i.paused||i.pause()}handleClipChange(){if(this.videoPreview&&this.videoPreview.currentClip){const t=this.findClipAtTime(this.config.currentTime);(!t||t.id!==this.videoPreview.currentClip.id)&&(this.videoPreview.currentClip=null)}}findClipAtTime(t){return this.getClips().find(i=>t>=i.startTime&&t<i.startTime+i.duration)||null}loadClipToVideo(t){if(!this.videoPreview)return;const e=this.videoPreview.videoElement;if(e.src===t.src){e.currentTime=t.startTimeAtSource/1e3,this.videoPreview.currentClip=t,this.config.playState==="playing"&&e.paused&&e.play().catch(s=>{M.warn("TimelineManager","Video play was prevented:",{err:s})});return}const i=this.config.playState==="playing";e.pause(),e.src=t.src,e.load(),e.currentTime=t.startTimeAtSource/1e3,this.videoPreview.currentClip=t,i&&e.play().catch(s=>{M.warn("TimelineManager","Video play was prevented:",{err:s})}),M.debug("TimelineManager",`Loaded clip: ${t.name}, src: ${t.src}, start: ${t.startTimeAtSource}ms`)}checkTrackDurationChange(){const t=this.getTrackTotalDuration();t!==this.lastTrackDuration&&(this.lastTrackDuration=t,this.emitEvent("track_duration_change",{duration:t}),M.debug("TimelineManager",`Track duration changed: ${t}ms`))}}exports.Clip=ue;exports.HistoryManager=Zi;exports.Playhead=Ki;exports.TimeUtils=X;exports.Timeline=qi;exports.TimelineManager=Ar;exports.VideoTrack=$i;exports.defaultDarkTheme=fe;
|