pikaso
Version:
Seamless, Fully-typed and Fully-tested HTML5 Canvas Library
1 lines • 275 kB
JavaScript
"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var i=function t(){var i=!1;try{i=this instanceof t}catch{}return i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,r.get?r:{enumerable:!0,get:function(){return t[e]}})}),i}var r,n={exports:{}},o={},s={},a={};function h(){return r||(r=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._registerNode=e.Konva=e.glob=void 0;const i=Math.PI/180;e.glob=void 0!==t?t:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},e.Konva={_global:e.glob,version:"9.3.22",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:t=>e.Konva.angleDeg?t*i:t,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,_fixTextRendering:!1,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>e.Konva.DD.isDragging,isTransforming(){var t;return null===(t=e.Konva.Transformer)||void 0===t?void 0:t.isTransforming()},isDragReady:()=>!!e.Konva.DD.node,releaseCanvasOnDestroy:!0,document:e.glob.document,_injectGlobal(t){e.glob.Konva=t}};e._registerNode=t=>{e.Konva[t.prototype.getClassName()]=t},e.Konva._injectGlobal(e.Konva)}(a)),a}var l,c={};function d(){return l||(l=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.Util=t.Transform=void 0;const e=h();class i{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 i(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),r=this.m[0]*e+this.m[2]*i,n=this.m[1]*e+this.m[3]*i,o=this.m[0]*-i+this.m[2]*e,s=this.m[1]*-i+this.m[3]*e;return this.m[0]=r,this.m[1]=n,this.m[2]=o,this.m[3]=s,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){const i=this.m[0]+this.m[2]*e,r=this.m[1]+this.m[3]*e,n=this.m[2]+this.m[0]*t,o=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=r,this.m[2]=n,this.m[3]=o,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],r=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],o=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],s=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]=r,this.m[3]=n,this.m[4]=o,this.m[5]=s,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,r=-this.m[2]*t,n=this.m[0]*t,o=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),s=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]=r,this.m[3]=n,this.m[4]=o,this.m[5]=s,this}getMatrix(){return this.m}decompose(){const e=this.m[0],i=this.m[1],r=this.m[2],n=this.m[3],o=e*n-i*r,s={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=e||0!=i){const t=Math.sqrt(e*e+i*i);s.rotation=i>0?Math.acos(e/t):-Math.acos(e/t),s.scaleX=t,s.scaleY=o/t,s.skewX=(e*r+i*n)/o,s.skewY=0}else if(0!=r||0!=n){const t=Math.sqrt(r*r+n*n);s.rotation=Math.PI/2-(n>0?Math.acos(-r/t):-Math.acos(r/t)),s.scaleX=o/t,s.scaleY=t,s.skewX=0,s.skewY=(e*r+i*n)/o}return s.rotation=t.Util._getRotation(s.rotation),s}}t.Transform=i;const r=Math.PI/180,n=180/Math.PI,o="Konva error: ",s={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]},a=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let l=[];const c="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)};t.Util={_isElement:t=>!(!t||1!=t.nodeType),_isFunction:t=>!!(t&&t.constructor&&t.call&&t.apply),_isPlainObject:t=>!!t&&t.constructor===Object,_isArray:t=>"[object Array]"===Object.prototype.toString.call(t),_isNumber:t=>"[object Number]"===Object.prototype.toString.call(t)&&!isNaN(t)&&isFinite(t),_isString:t=>"[object String]"===Object.prototype.toString.call(t),_isBoolean:t=>"[object Boolean]"===Object.prototype.toString.call(t),isObject:t=>t instanceof Object,isValidSelector(t){if("string"!=typeof t)return!1;const e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},_sign:t=>0===t||t>0?1:-1,requestAnimFrame(t){l.push(t),1===l.length&&c(function(){const t=l;l=[],t.forEach(function(t){t()})})},createCanvasElement(){const t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>document.createElement("img"),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(e,i){const r=t.Util.createImageElement();r.onload=function(){i(r)},r.src=e},_rgbToHex:(t,e,i)=>((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1),_hexToRgb(t){t=t.replace("#","");const e=parseInt(t,16);return{r:e>>16&255,g:e>>8&255,b:255&e}},getRandomColor(){let t=(16777215*Math.random()|0).toString(16);for(;t.length<6;)t="0"+t;return"#"+t},getRGB(t){let e;return t in s?(e=s[t],{r:e[0],g:e[1],b:e[2]}):"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=a.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:e=>(e=e||"black",t.Util._namedColorToRBA(e)||t.Util._hex3ColorToRGBA(e)||t.Util._hex4ColorToRGBA(e)||t.Util._hex6ColorToRGBA(e)||t.Util._hex8ColorToRGBA(e)||t.Util._rgbColorToRGBA(e)||t.Util._rgbaColorToRGBA(e)||t.Util._hslColorToRGBA(e)),_namedColorToRBA(t){const e=s[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA(t){if(0===t.indexOf("rgb(")){const e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA(t){if(0===t.indexOf("rgba(")){const e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map((t,e)=>"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){const[e,...i]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),r=Number(i[0])/360,n=Number(i[1])/100,o=Number(i[2])/100;let s,a,h;if(0===n)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};s=o<.5?o*(1+n):o+n-o*n;const l=2*o-s,c=[0,0,0];for(let t=0;t<3;t++)a=r+1/3*-(t-1),a<0&&a++,a>1&&a--,h=6*a<1?l+6*(s-l)*a:2*a<1?s:3*a<2?l+(s-l)*(2/3-a)*6:l,c[t]=255*h;return{r:Math.round(c[0]),g:Math.round(c[1]),b:Math.round(c[2]),a:1}}},haveIntersection:(t,e)=>!(e.x>t.x+t.width||e.x+e.width<t.x||e.y>t.y+t.height||e.y+e.height<t.y),cloneObject(t){const e={};for(const i in t)this._isPlainObject(t[i])?e[i]=this.cloneObject(t[i]):this._isArray(t[i])?e[i]=this.cloneArray(t[i]):e[i]=t[i];return e},cloneArray:t=>t.slice(0),degToRad:t=>t*r,radToDeg:t=>t*n,_degToRad:e=>(t.Util.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),t.Util.degToRad(e)),_radToDeg:e=>(t.Util.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),t.Util.radToDeg(e)),_getRotation:i=>e.Konva.angleDeg?t.Util.radToDeg(i):i,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(o+t)},error(t){console.error(o+t)},warn(t){e.Konva.showWarnings&&console.warn("Konva warning: "+t)},each(t,e){for(const i in t)e(i,t[i])},_inRange:(t,e,i)=>e<=t&&t<i,_getProjectionToSegment(t,e,i,r,n,o){let s,a,h;const l=(t-i)*(t-i)+(e-r)*(e-r);if(0==l)s=t,a=e,h=(n-i)*(n-i)+(o-r)*(o-r);else{const c=((n-t)*(i-t)+(o-e)*(r-e))/l;c<0?(s=t,a=e,h=(t-n)*(t-n)+(e-o)*(e-o)):c>1?(s=i,a=r,h=(i-n)*(i-n)+(r-o)*(r-o)):(s=t+c*(i-t),a=e+c*(r-e),h=(s-n)*(s-n)+(a-o)*(a-o))}return[s,a,h]},_getProjectionToLine(e,i,r){const n=t.Util.cloneObject(e);let o=Number.MAX_VALUE;return i.forEach(function(s,a){if(!r&&a===i.length-1)return;const h=i[(a+1)%i.length],l=t.Util._getProjectionToSegment(s.x,s.y,h.x,h.y,e.x,e.y),c=l[0],d=l[1],u=l[2];u<o&&(n.x=c,n.y=d,o=u)}),n},_prepareArrayForTween(e,i,r){const n=[],o=[];if(e.length>i.length){const t=i;i=e,e=t}for(let t=0;t<e.length;t+=2)n.push({x:e[t],y:e[t+1]});for(let t=0;t<i.length;t+=2)o.push({x:i[t],y:i[t+1]});const s=[];return o.forEach(function(e){const i=t.Util._getProjectionToLine(e,n,r);s.push(i.x),s.push(i.y)}),s},_prepareToStringify(e){let i;e.visitedByCircularReferenceRemoval=!0;for(const r in e)if(e.hasOwnProperty(r)&&e[r]&&"object"==typeof e[r])if(i=Object.getOwnPropertyDescriptor(e,r),e[r].visitedByCircularReferenceRemoval||t.Util._isElement(e[r])){if(!i.configurable)return null;delete e[r]}else if(null===t.Util._prepareToStringify(e[r])){if(!i.configurable)return null;delete e[r]}return delete e.visitedByCircularReferenceRemoval,e},_assign(t,e){for(const i in e)t[i]=e[i];return t},_getFirstPointerId:t=>t.touches?t.changedTouches[0].identifier:t.pointerId||999,releaseCanvas(...t){e.Konva.releaseCanvasOnDestroy&&t.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(t,e,i,r){let n=0,o=0,s=0,a=0;"number"==typeof r?n=o=s=a=Math.min(r,e/2,i/2):(n=Math.min(r[0]||0,e/2,i/2),o=Math.min(r[1]||0,e/2,i/2),a=Math.min(r[2]||0,e/2,i/2),s=Math.min(r[3]||0,e/2,i/2)),t.moveTo(n,0),t.lineTo(e-o,0),t.arc(e-o,o,o,3*Math.PI/2,0,!1),t.lineTo(e,i-a),t.arc(e-a,i-a,a,0,Math.PI/2,!1),t.lineTo(s,i),t.arc(s,i-s,s,Math.PI/2,Math.PI,!1),t.lineTo(0,n),t.arc(n,n,n,Math.PI,3*Math.PI/2,!1)}}}(c)),c}var u,g,p={},f={},y={};function v(){if(u)return y;u=1,Object.defineProperty(y,"__esModule",{value:!0}),y.HitContext=y.SceneContext=y.Context=void 0;const t=d(),e=h();const i=["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"];let r=class{constructor(t){this.canvas=t,e.Konva.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(e,i){let r,n,o,s,a=this.traceArr,h=a.length,l="";for(r=0;r<h;r++)n=a[r],o=n.method,o?(s=n.args,l+=o,e?l+="()":t.Util._isArray(s[0])?l+="(["+s.join(",")+"])":(i&&(s=s.map(t=>"number"==typeof t?Math.floor(t):t)),l+="("+s.join(",")+")")):(l+=n.property,e||(l+="="+n.val)),l+=";";return l}clearTrace(){this.traceArr=[]}_trace(t){let e,i=this.traceArr;i.push(t),e=i.length,e>=100&&i.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();1!==e&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,r,n,o){this._context.arc(t,e,i,r,n,o)}arcTo(t,e,i,r,n){this._context.arcTo(t,e,i,r,n)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,r,n,o){this._context.bezierCurveTo(t,e,i,r,n,o)}clearRect(t,e,i,r){this._context.clearRect(t,e,i,r)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){const i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}createLinearGradient(t,e,i,r){return this._context.createLinearGradient(t,e,i,r)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,r,n,o){return this._context.createRadialGradient(t,e,i,r,n,o)}drawImage(t,e,i,r,n,o,s,a,h){const l=arguments,c=this._context;3===l.length?c.drawImage(t,e,i):5===l.length?c.drawImage(t,e,i,r,n):9===l.length&&c.drawImage(t,e,i,r,n,o,s,a,h)}ellipse(t,e,i,r,n,o,s,a){this._context.ellipse(t,e,i,r,n,o,s,a)}isPointInPath(t,e,i,r){return i?this._context.isPointInPath(i,t,e,r):this._context.isPointInPath(t,e,r)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,r){this._context.fillRect(t,e,i,r)}strokeRect(t,e,i,r){this._context.strokeRect(t,e,i,r)}fillText(t,e,i,r){r?this._context.fillText(t,e,i,r):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,r){return this._context.getImageData(t,e,i,r)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,r){this._context.rect(t,e,i,r)}roundRect(t,e,i,r,n){this._context.roundRect(t,e,i,r,n)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,r){this._context.quadraticCurveTo(t,e,i,r)}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,r,n,o){this._context.setTransform(t,e,i,r,n,o)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,r){this._context.strokeText(t,e,i,r)}transform(t,e,i,r,n,o){this._context.transform(t,e,i,r,n,o)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let e,r,n=this,o=i.length,s=this.setAttr;const a=function(e){let i,o=n[e];n[e]=function(){return r=function(e){const i=[],r=e.length,n=t.Util;for(let t=0;t<r;t++){let r=e[t];n._isNumber(r)?r=Math.round(1e3*r)/1e3:n._isString(r)||(r+=""),i.push(r)}return i}(Array.prototype.slice.call(arguments,0)),i=o.apply(n,arguments),n._trace({method:e,args:r}),i}};for(e=0;e<o;e++)a(i[e]);n.setAttr=function(){s.apply(n,arguments);const t=arguments[0];let e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),n._trace({property:t,val:e})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||"source-over"===e||this.setAttr("globalCompositeOperation",e)}};y.Context=r,["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled"].forEach(function(t){Object.defineProperty(r.prototype,t,{get(){return this._context[t]},set(e){this._context[t]=e}})});y.SceneContext=class extends r{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&&"color"===i)return void this._fillColor(t);const r=t.getFillPatternImage();if(r&&"pattern"===i)return void this._fillPattern(t);const n=t.getFillLinearGradientColorStops();if(n&&"linear-gradient"===i)return void this._fillLinearGradient(t);const o=t.getFillRadialGradientColorStops();o&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):r?this._fillPattern(t):n?this._fillLinearGradient(t):o&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),r=t.getStrokeLinearGradientColorStops(),n=this.createLinearGradient(e.x,e.y,i.x,i.y);if(r){for(let t=0;t<r.length;t+=2)n.addColorStop(r[t],r[t+1]);this.setAttr("strokeStyle",n)}}_stroke(t){const e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();const t=this.getCanvas().getPixelRatio();this.setTransform(t,0,0,t,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,r;const n=null!==(e=t.getShadowRGBA())&&void 0!==e?e:"black",o=null!==(i=t.getShadowBlur())&&void 0!==i?i:5,s=null!==(r=t.getShadowOffset())&&void 0!==r?r:{x:0,y:0},a=t.getAbsoluteScale(),h=this.canvas.getPixelRatio(),l=a.x*h,c=a.y*h;this.setAttr("shadowColor",n),this.setAttr("shadowBlur",o*Math.min(Math.abs(l),Math.abs(c))),this.setAttr("shadowOffsetX",s.x*l),this.setAttr("shadowOffsetY",s.y*c)}};return y.HitContext=class extends r{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 t=this.getCanvas().getPixelRatio();this.setTransform(t,0,0,t,0,0)}this._applyLineCap(t);const i=t.hitStrokeWidth(),r="auto"===i?t.strokeWidth():i;this.setAttr("lineWidth",r),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}},y}function m(){if(g)return f;g=1,Object.defineProperty(f,"__esModule",{value:!0}),f.HitCanvas=f.SceneCanvas=f.Canvas=void 0;const t=d(),e=v(),i=h();let r;let n=class{constructor(e){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const n=(e||{}).pixelRatio||i.Konva.pixelRatio||function(){if(r)return r;const e=t.Util.createCanvasElement(),n=e.getContext("2d");return r=(i.Konva._global.devicePixelRatio||1)/(n.webkitBackingStorePixelRatio||n.mozBackingStorePixelRatio||n.msBackingStorePixelRatio||n.oBackingStorePixelRatio||n.backingStorePixelRatio||1),t.Util.releaseCanvas(e),r}();this.pixelRatio=n,this._canvas=t.Util.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(e,i){try{return this._canvas.toDataURL(e,i)}catch(e){try{return this._canvas.toDataURL()}catch(e){return t.Util.error("Unable to get data URL. "+e.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}};f.Canvas=n;f.SceneCanvas=class extends n{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new e.SceneContext(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}};return f.HitCanvas=class extends n{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new e.HitContext(this),this.setSize(t.width,t.height)}},f}var b,_={};function x(){return b||(b=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.DD=void 0;const e=h(),i=d();t.DD={get isDragging(){let e=!1;return t.DD._dragElements.forEach(t=>{"dragging"===t.dragStatus&&(e=!0)}),e},justDragged:!1,get node(){let e;return t.DD._dragElements.forEach(t=>{e=t.node}),e},_dragElements:new Map,_drag(e){const r=[];t.DD._dragElements.forEach((t,n)=>{const{node:o}=t,s=o.getStage();s.setPointersPositions(e),void 0===t.pointerId&&(t.pointerId=i.Util._getFirstPointerId(e));const a=s._changedPointerPositions.find(e=>e.id===t.pointerId);if(a){if("dragging"!==t.dragStatus){const i=o.dragDistance();if(Math.max(Math.abs(a.x-t.startPointerPos.x),Math.abs(a.y-t.startPointerPos.y))<i)return;if(o.startDrag({evt:e}),!o.isDragging())return}o._setDragPosition(e,t),r.push(o)}}),r.forEach(t=>{t.fire("dragmove",{type:"dragmove",target:t,evt:e},!0)})},_endDragBefore(i){const r=[];t.DD._dragElements.forEach(n=>{const{node:o}=n,s=o.getStage();i&&s.setPointersPositions(i);if(!s._changedPointerPositions.find(t=>t.id===n.pointerId))return;"dragging"!==n.dragStatus&&"stopped"!==n.dragStatus||(t.DD.justDragged=!0,e.Konva._mouseListenClick=!1,e.Konva._touchListenClick=!1,e.Konva._pointerListenClick=!1,n.dragStatus="stopped");const a=n.node.getLayer()||n.node instanceof e.Konva.Stage&&n.node;a&&-1===r.indexOf(a)&&r.push(a)}),r.forEach(t=>{t.draw()})},_endDragAfter(e){t.DD._dragElements.forEach((i,r)=>{"stopped"===i.dragStatus&&i.node.fire("dragend",{type:"dragend",target:i.node,evt:e},!0),"dragging"!==i.dragStatus&&t.DD._dragElements.delete(r)})}},e.Konva.isBrowser&&(window.addEventListener("mouseup",t.DD._endDragBefore,!0),window.addEventListener("touchend",t.DD._endDragBefore,!0),window.addEventListener("touchcancel",t.DD._endDragBefore,!0),window.addEventListener("mousemove",t.DD._drag),window.addEventListener("touchmove",t.DD._drag),window.addEventListener("mouseup",t.DD._endDragAfter,!1),window.addEventListener("touchend",t.DD._endDragAfter,!1),window.addEventListener("touchcancel",t.DD._endDragAfter,!1))}(_)),_}var w,S,C,P={},A={};function k(){if(w)return A;w=1,Object.defineProperty(A,"__esModule",{value:!0}),A.RGBComponent=function(t){if(t>255)return 255;if(t<0)return 0;return Math.round(t)},A.alphaComponent=function(t){if(t>1)return 1;if(t<1e-4)return 1e-4;return t},A.getNumberValidator=function(){if(t.Konva.isUnminified)return function(t,r){return e.Util._isNumber(t)||e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a number.'),t}},A.getNumberOrArrayOfNumbersValidator=function(r){if(t.Konva.isUnminified)return function(t,n){let o=e.Util._isNumber(t),s=e.Util._isArray(t)&&t.length==r;return o||s||e.Util.warn(i(t)+' is a not valid value for "'+n+'" attribute. The value should be a number or Array<number>('+r+")"),t}},A.getNumberOrAutoValidator=function(){if(t.Konva.isUnminified)return function(t,r){return e.Util._isNumber(t)||"auto"===t||e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a number or "auto".'),t}},A.getStringValidator=function(){if(t.Konva.isUnminified)return function(t,r){return e.Util._isString(t)||e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a string.'),t}},A.getStringOrGradientValidator=function(){if(t.Konva.isUnminified)return function(t,r){const n=e.Util._isString(t),o="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return n||o||e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a string or a native gradient.'),t}},A.getFunctionValidator=function(){if(t.Konva.isUnminified)return function(t,r){return e.Util._isFunction(t)||e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a function.'),t}},A.getNumberArrayValidator=function(){if(t.Konva.isUnminified)return function(t,r){const n=Int8Array?Object.getPrototypeOf(Int8Array):null;return n&&t instanceof n||(e.Util._isArray(t)?t.forEach(function(t){e.Util._isNumber(t)||e.Util.warn('"'+r+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")}):e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a array of numbers.')),t}},A.getBooleanValidator=function(){if(t.Konva.isUnminified)return function(t,r){return!0===t||!1===t||e.Util.warn(i(t)+' is a not valid value for "'+r+'" attribute. The value should be a boolean.'),t}},A.getComponentValidator=function(r){if(t.Konva.isUnminified)return function(t,n){return null==t||e.Util.isObject(t)||e.Util.warn(i(t)+' is a not valid value for "'+n+'" attribute. The value should be an object with properties '+r),t}};const t=h(),e=d();function i(t){return e.Util._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||e.Util._isBoolean(t)?t:Object.prototype.toString.call(t)}return A}function T(){return S||(S=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.Factory=void 0;const e=d(),i=k(),r="get",n="set";t.Factory={addGetterSetter(e,i,r,n,o){t.Factory.addGetter(e,i,r),t.Factory.addSetter(e,i,n,o),t.Factory.addOverloadedGetterSetter(e,i)},addGetter(t,i,n){const o=r+e.Util._capitalize(i);t.prototype[o]=t.prototype[o]||function(){const t=this.attrs[i];return void 0===t?n:t}},addSetter(i,r,o,s){const a=n+e.Util._capitalize(r);i.prototype[a]||t.Factory.overWriteSetter(i,r,o,s)},overWriteSetter(t,i,r,o){const s=n+e.Util._capitalize(i);t.prototype[s]=function(t){return r&&null!=t&&(t=r.call(this,t,i)),this._setAttr(i,t),o&&o.call(this),this}},addComponentsGetterSetter(o,s,a,h,l){const c=a.length,d=e.Util._capitalize,u=r+d(s),g=n+d(s);o.prototype[u]=function(){const t={};for(let e=0;e<c;e++){const i=a[e];t[i]=this.getAttr(s+d(i))}return t};const p=(0,i.getComponentValidator)(a);o.prototype[g]=function(t){const e=this.attrs[s];h&&(t=h.call(this,t,s)),p&&p.call(this,t,s);for(const e in t)t.hasOwnProperty(e)&&this._setAttr(s+d(e),t[e]);return t||a.forEach(t=>{this._setAttr(s+d(t),void 0)}),this._fireChangeEvent(s,e,t),l&&l.call(this),this},t.Factory.addOverloadedGetterSetter(o,s)},addOverloadedGetterSetter(t,i){const o=e.Util._capitalize(i),s=n+o,a=r+o;t.prototype[i]=function(){return arguments.length?(this[s](arguments[0]),this):this[a]()}},addDeprecatedGetterSetter(i,n,o,s){e.Util.error("Adding deprecated "+n);const a=r+e.Util._capitalize(n),h=n+" property is deprecated and will be removed soon. Look at Konva change log for more information.";i.prototype[a]=function(){e.Util.error(h);const t=this.attrs[n];return void 0===t?o:t},t.Factory.addSetter(i,n,s,function(){e.Util.error(h)}),t.Factory.addOverloadedGetterSetter(i,n)},backCompat(t,i){e.Util.each(i,function(i,o){const s=t.prototype[o],a=r+e.Util._capitalize(i),h=n+e.Util._capitalize(i);function l(){s.apply(this,arguments),e.Util.error('"'+i+'" method is deprecated and will be removed soon. Use ""'+o+'" instead.')}t.prototype[i]=l,t.prototype[a]=l,t.prototype[h]=l})},afterSetFilter(){this._filterUpToDate=!1}}}(P)),P}function D(){if(C)return p;C=1,Object.defineProperty(p,"__esModule",{value:!0}),p.Node=void 0;const t=m(),e=x(),i=T(),r=h(),n=d(),o=k(),s="absoluteOpacity",a="allEventListeners",l="absoluteTransform",c="absoluteScale",u="canvas",g="listening",f="Shape",y=" ",v="stage",b="transform",_="visible",w=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(y);let S=1,P=class i{constructor(t){this._id=S++,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!==b&&t!==l||!this._cache.get(t)?t?this._cache.delete(t):this._cache.clear():this._cache.get(t).dirty=!0}_getCache(t,e){let i=this._cache.get(t);return(void 0===i||(t===b||t===l)&&!0===i.dirty)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){const i=e.map(t=>t+"Change.konva").join(y);this.on(i,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(u)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===l&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(u)){const{scene:t,filter:e,hit:i,buffer:r}=this._cache.get(u);n.Util.releaseCanvas(t,e,i,r),this._cache.delete(u)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(e){const i=e||{};let r={};void 0!==i.x&&void 0!==i.y&&void 0!==i.width&&void 0!==i.height||(r=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let o=Math.ceil(i.width||r.width),a=Math.ceil(i.height||r.height),h=i.pixelRatio,l=void 0===i.x?Math.floor(r.x):i.x,d=void 0===i.y?Math.floor(r.y):i.y,g=i.offset||0,p=i.drawBorder||!1,f=i.hitCanvasPixelRatio||1;if(!o||!a)return void n.Util.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");o+=2*g+(Math.abs(Math.round(r.x)-l)>.5?1:0),a+=2*g+(Math.abs(Math.round(r.y)-d)>.5?1:0),l-=g,d-=g;const y=new t.SceneCanvas({pixelRatio:h,width:o,height:a}),v=new t.SceneCanvas({pixelRatio:h,width:0,height:0,willReadFrequently:!0}),m=new t.HitCanvas({pixelRatio:f,width:o,height:a}),b=y.getContext(),_=m.getContext(),x=new t.SceneCanvas({width:y.width/y.pixelRatio+Math.abs(l),height:y.height/y.pixelRatio+Math.abs(d),pixelRatio:y.pixelRatio}),w=x.getContext();return m.isCache=!0,y.isCache=!0,this._cache.delete(u),this._filterUpToDate=!1,!1===i.imageSmoothingEnabled&&(y.getContext()._context.imageSmoothingEnabled=!1,v.getContext()._context.imageSmoothingEnabled=!1),b.save(),_.save(),w.save(),b.translate(-l,-d),_.translate(-l,-d),w.translate(-l,-d),x.x=l,x.y=d,this._isUnderCache=!0,this._clearSelfAndDescendantCache(s),this._clearSelfAndDescendantCache(c),this.drawScene(y,this,x),this.drawHit(m,this),this._isUnderCache=!1,b.restore(),_.restore(),p&&(b.save(),b.beginPath(),b.rect(0,0,o,a),b.closePath(),b.setAttr("strokeStyle","red"),b.setAttr("lineWidth",5),b.stroke(),b.restore()),this._cache.set(u,{scene:y,filter:v,hit:m,buffer:x,x:l,y:d}),this._requestDraw(),this}isCached(){return this._cache.has(u)}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 r=1/0,n=1/0,o=-1/0,s=-1/0;const a=this.getAbsoluteTransform(e);return i.forEach(function(t){const e=a.point(t);void 0===r&&(r=o=e.x,n=s=e.y),r=Math.min(r,e.x),n=Math.min(n,e.y),o=Math.max(o,e.x),s=Math.max(s,e.y)}),{x:r,y:n,width:o-r,height:s-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(),r=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/r,i.height/r),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,e,i,r,o=this.filters(),s=this._getCanvasCache(),a=s.scene,h=s.filter,l=h.getContext();if(o){if(!this._filterUpToDate){const s=a.pixelRatio;h.setSize(a.width/a.pixelRatio,a.height/a.pixelRatio);try{for(t=o.length,l.clear(),l.drawImage(a._canvas,0,0,a.getWidth()/s,a.getHeight()/s),e=l.getImageData(0,0,h.getWidth(),h.getHeight()),i=0;i<t;i++)r=o[i],"function"==typeof r?(r.call(this,e),l.putImageData(e,0,0)):n.Util.error("Filter should be type of function, but got "+typeof r+" instead. Please check correct filters")}catch(t){n.Util.error("Unable to apply filter. "+t.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}this._filterUpToDate=!0}return h}return a}on(t,e){if(this._cache&&this._cache.delete(a),3===arguments.length)return this._delegate.apply(this,arguments);const i=t.split(y);for(let t=0;t<i.length;t++){const r=i[t].split("."),n=r[0],o=r[1]||"";this.eventListeners[n]||(this.eventListeners[n]=[]),this.eventListeners[n].push({name:o,handler:e})}return this}off(t,e){let i,r,n,o,s,h,l=(t||"").split(y),c=l.length;if(this._cache&&this._cache.delete(a),!t)for(r in this.eventListeners)this._off(r);for(i=0;i<c;i++)if(n=l[i],o=n.split("."),s=o[0],h=o[1],s)this.eventListeners[s]&&this._off(s,h,e);else for(r in this.eventListeners)this._off(r,h,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(t){e.call(this,t.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){const r=this;this.on(t,function(t){const o=t.target.findAncestors(e,!0,r);for(let e=0;e<o.length;e++)(t=n.Util.cloneObject(t)).currentTarget=o[e],i.call(o[e],t)})}remove(){return this.isDragging()&&this.stopDrag(),e.DD._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(l),this._clearSelfAndDescendantCache(s),this._clearSelfAndDescendantCache(c),this._clearSelfAndDescendantCache(v),this._clearSelfAndDescendantCache(_),this._clearSelfAndDescendantCache(g)}_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"+n.Util._capitalize(t);return n.Util._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)"children"!==e&&(i="set"+n.Util._capitalize(e),n.Util._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(g,this._isListening)}_isListening(t){if(!this.listening())return!1;const e=this.getParent();return!e||e===t||this===t||e._isListening(t)}isVisible(){return this._getCache(_,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,i=!1){if(t)return this._isVisible(t)&&this._isListening(t);const n=this.getLayer();let o=!1;e.DD._dragElements.forEach(t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===n)&&(o=!0)});const s=!i&&!r.Konva.hitOnDragEnabled&&(o||r.Konva.isTransforming());return this.isListening()&&this.isVisible()&&!s}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t,e,i,r,n=this.getDepth(),o=this,s=0;const a=this.getStage();return"Stage"!==o.nodeType&&a&&function a(h){for(t=[],e=h.length,i=0;i<e;i++)r=h[i],s++,r.nodeType!==f&&(t=t.concat(r.getChildren().slice())),r._id===o._id&&(i=e);t.length>0&&t[0].getDepth()<=n&&a(t)}(a.getChildren()),s}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(b),this._clearSelfAndDescendantCache(l)),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 r=this.getAbsoluteTransform(t).getMatrix(),o=new n.Transform,s=this.offset();return o.m=r.slice(),o.translate(s.x,s.y),o.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...r}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(b);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(r),this.setPosition({x:t.x,y:t.y}),this._clearCache(b),this._clearSelfAndDescendantCache(l),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,r=this.x(),n=this.y();return void 0!==e&&(r+=e),void 0!==i&&(n+=i),this.setPosition({x:r,y:n}),this}_eachAncestorReverse(t,e){let i,r,n=[],o=this.getParent();if(!e||e._id!==this._id){for(n.unshift(this);o&&(!e||o._id!==e._id);)n.unshift(o),o=o.parent;for(i=n.length,r=0;r<i;r++)t(n[r])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return n.Util.warn("Node has no parent. moveToTop function is ignored."),!1;const t=this.index;return t<this.parent.getChildren().length-1&&(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0)}moveUp(){if(!this.parent)return n.Util.warn("Node has no parent. moveUp function is ignored."),!1;const t=this.index;return t<this.parent.getChildren().length-1&&(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0)}moveDown(){if(!this.parent)return n.Util.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)}moveToBottom(){if(!this.parent)return n.Util.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)}setZIndex(t){if(!this.parent)return n.Util.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&n.Util.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(s,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,e,i,r,o,s=this.getAttrs();const a={attrs:{},className:this.getClassName()};for(t in s)e=s[t],o=n.Util.isObject(e)&&!n.Util._isPlainObject(e)&&!n.Util._isArray(e),o||(i="function"==typeof this[t]&&this[t],delete s[t],r=i?i.call(this):null,s[t]=e,r!==e&&(a.attrs[t]=e));return n.Util._prepareToStringify(a)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){const r=[];e&&this._isMatch(t)&&r.push(this);let n=this.parent;for(;n;){if(n===i)return r;n._isMatch(t)&&r.push(n),n=n.parent}return r}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if("function"==typeof t)return t(this);let e,i,r=t.replace(/ /g,"").split(","),o=r.length;for(e=0;e<o;e++)if(i=r[e],n.Util.isValidSelector(i)||(n.Util.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),n.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),n.Util.warn("Konva is awesome, right?")),"#"===i.charAt(0)){if(this.id()===i.slice(1))return!0}else if("."===i.charAt(0)){if(this.hasName(i.slice(1)))return!0}else if(this.className===i||this.nodeType===i)return!0;return!1}getLayer(){const t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(v,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(l,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new n.Transform,this._eachAncestorReverse(function(t){const i=t.transformsEnabled();"all"===i?e.multiply(t.getTransform()):"position"===i&&e.translate(t.x()-t.offsetX(),t.y()-t.offsetY())},t),e;{e=this._cache.get(l)||new n.Transform,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();const t=this.transformsEnabled();if("all"===t)e.multiply(this.getTransform());else if("position"===t){const t=this.attrs.x||0,i=this.attrs.y||0,r=this.attrs.offsetX||0,n=this.attrs.offsetY||0;e.translate(t-r,i-n)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();const i=this.getAbsoluteTransform(t).decompose();return{x:i.scaleX,y:i.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(b,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(b)||new n.Transform;i.reset();const o=this.x(),s=this.y(),a=r.Konva.getAngle(this.rotation()),h=null!==(t=this.attrs.scaleX)&&void 0!==t?t:1,l=null!==(e=this.attrs.scaleY)&&void 0!==e?e:1,c=this.attrs.skewX||0,d=this.attrs.skewY||0,u=this.attrs.offsetX||0,g=this.attrs.offsetY||0;return 0===o&&0===s||i.translate(o,s),0!==a&&i.rotate(a),0===c&&0===d||i.skew(c,d),1===h&&1===l||i.scale(h,l),0===u&&0===g||i.translate(-1*u,-1*g),i.dirty=!1,i}clone(t){let e,i,r,o,s,a=n.Util.cloneObject(this.attrs);for(e in t)a[e]=t[e];const h=new this.constructor(a);for(e in this.eventListeners)for(i=this.eventListeners[e],r=i.length,o=0;o<r;o++)s=i[o],s.name.indexOf("konva")<0&&(h.eventListeners[e]||(h.eventListeners[e]=[]),h.eventListeners[e].push(s));return h}_toKonvaCanvas(e){e=e||{};const i=this.getClientRect(),r=this.getStage(),n=void 0!==e.x?e.x:Math.floor(i.x),o=void 0!==e.y?e.y:Math.floor(i.y),s=e.pixelRatio||1,a=new t.SceneCanvas({width:e.width||Math.ceil(i.width)||(r?r.width():0),height:e.height||Math.ceil(i.height)||(r?r.height():0),pixelRatio:s}),h=a.getContext(),l=new t.SceneCanvas({width:a.width/a.pixelRatio+Math.abs(n),height:a.height/a.pixelRatio+Math.abs(o),pixelRatio:a.pixelRatio});return!1===e.imageSmoothingEnabled&&(h._context.imageSmoothingEnabled=!1),h.save(),(n||o)&&h.translate(-1*n,-1*o),this.drawScene(a,void 0,l),h.restore(),a}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){const e=(t=t||{}).mimeType||null,i=t.quality||null,r=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(r),r}toImage(t){return new Promise((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,n.Util._urlToImage(this.toDataURL(t),function(t){e(t),null==i||i(t)})}catch(t){i(t)}})}toBlob(t){return new Promise((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,this.toCanvas(t).toBlob(t=>{e(t),null==i||i(t)},null==t?void 0:t.mimeType,null==t?void 0:t.quality)}catch(t){i(t)}})}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 void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():r.Konva.dragDistance}_off(t,e,i){let r,n,o,s=this.eventListeners[t];for(r=0;r<s.length;r++)if(n=s[r].name,o=s[r].handler,!("konva"===n&&"konva"!==e||e&&n!==e||i&&i!==o)){if(s.splice(r,1),0===s.length){delete this.eventListeners[t];break}r--}}_fireChangeEvent(t,e,i){this._fire(t+"Change",{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();if(!e)return!1;return-1!==(e||"").split(/\s/g).indexOf(t)}removeName(t){const e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return-1!==i&&(e.splice(i,1),this.name(e.join(" "))),this}setAttr(t,e){const i=this["set"+n.Util._capitalize(t)];return n.Util._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(r.Konva.autoDrawEnabled){const t=this.getLayer()||this.getStage();null==t||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];(i!==e||n.Util.isObject(e))&&(null==e?delete this.attrs[t]:this.attrs[t]=e,this._shouldFireChangeEvents&&this._fireChangeEvent(t,i,e),this._requestDraw())}_setComponentAttr(t,e,i){let r;void 0!==i&&(r=this.attrs[t],r||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,r,i))}_fireAndBubble(t,e,i){e&&this.nodeType===f&&(e.target=this);const r=["mouseenter","mouseleave","pointerenter","pointerleave","touchenter","touchleave"];if(!(-1!==r.indexOf(t)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);const n=-1!==r.indexOf(t)&&i&