@inweb/markup 26.12.5 → 26.12.7
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/markup.min.js
CHANGED
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ODA=t.ODA||{},t.ODA.Markup=t.ODA.Markup||{}))}(this,function(t){"use strict";const e=Math.PI/180;const i="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},s={_global:i,version:"10.0.12",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:t=>s.angleDeg?t*e: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,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>s.DD.isDragging,isTransforming(){var t,e;return null!==(e=null===(t=s.Transformer)||void 0===t?void 0:t.isTransforming())&&void 0!==e&&e},isDragReady:()=>!!s.DD.node,releaseCanvasOnDestroy:!0,document:i.document,_injectGlobal(t){void 0!==i.Konva&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),i.Konva=t}},r=t=>{s[t.prototype.getClassName()]=t};s._injectGlobal(s);const n=()=>{if("undefined"==typeof document)throw new Error('Konva.js unsupported environment.\n\nLooks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.\n\nTo use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module.\n\nbash: npm install canvas\njs: import "konva/canvas-backend";\n\nor\n\nbash: npm install skia-canvas\njs: import "konva/skia-backend";\n')};class o{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 o(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,r=this.m[1]*e+this.m[3]*i,n=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]=r,this.m[2]=n,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,r=this.m[2]+this.m[0]*t,n=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=r,this.m[3]=n,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],r=this.m[1]*t.m[2]+this.m[3]*t.m[3],n=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]=r,this.m[4]=n,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,r=this.m[0]*t,n=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]=r,this.m[4]=n,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],r=t*s-e*i,n={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){const o=Math.sqrt(t*t+e*e);n.rotation=e>0?Math.acos(t/o):-Math.acos(t/o),n.scaleX=o,n.scaleY=r/o,n.skewX=(t*i+e*s)/r,n.skewY=0}else if(0!=i||0!=s){const o=Math.sqrt(i*i+s*s);n.rotation=Math.PI/2-(s>0?Math.acos(-i/o):-Math.acos(i/o)),n.scaleX=r/o,n.scaleY=o,n.skewX=0,n.skewY=(t*i+e*s)/r}return n.rotation=_._getRotation(n.rotation),n}}const a=Math.PI/180,h=180/Math.PI,l="#",d="Konva error: ",c={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]},g=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let f=[],u=null;const p="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},_={_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){f.push(t),1===f.length&&p(function(){const t=f;f=[],t.forEach(function(t){t()})})},createCanvasElement(){n();const t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>(n(),document.createElement("img")),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){const i=_.createImageElement();i.onload=function(){e(i)},i.src=t},_rgbToHex:(t,e,i)=>((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1),_hexToRgb(t){t=t.replace(l,"");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 l+t},isCanvasFarblingActive(){if(null!==u)return u;if("undefined"==typeof document)return u=!1,!1;const t=this.createCanvasElement();t.width=10,t.height=10;const e=t.getContext("2d",{willReadFrequently:!0});e.clearRect(0,0,10,10),e.fillStyle="#282828",e.fillRect(0,0,10,10);const i=e.getImageData(0,0,10,10).data;let s=!1;for(let t=0;t<100;t++)if(40!==i[4*t]||40!==i[4*t+1]||40!==i[4*t+2]||255!==i[4*t+3]){s=!0;break}return u=s,this.releaseCanvas(t),u},getHitColor(){const t=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(t):t},getHitColorKey(t,e,i){return this.isCanvasFarblingActive()&&(t=5*Math.round(t/5),e=5*Math.round(e/5),i=5*Math.round(i/5)),l+this._rgbToHex(t,e,i)},getSnappedHexColor(t){const e=this._hexToRgb(t);return l+this._rgbToHex(5*Math.round(e.r/5),5*Math.round(e.g/5),5*Math.round(e.b/5))},getRGB(t){let e;return t in c?(e=c[t],{r:e[0],g:e[1],b:e[2]}):t[0]===l?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=g.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:t=>(t=t||"black",_._namedColorToRBA(t)||_._hex3ColorToRGBA(t)||_._hex4ColorToRGBA(t)||_._hex6ColorToRGBA(t)||_._hex8ColorToRGBA(t)||_._rgbColorToRGBA(t)||_._rgbaColorToRGBA(t)||_._hslColorToRGBA(t)),_namedColorToRBA(t){const e=c[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),s=Number(i[0])/360,r=Number(i[1])/100,n=Number(i[2])/100;let o,a,h;if(0===r)return h=255*n,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};o=n<.5?n*(1+r):n+r-n*r;const l=2*n-o,d=[0,0,0];for(let t=0;t<3;t++)a=s+1/3*-(t-1),a<0&&a++,a>1&&a--,h=6*a<1?l+6*(o-l)*a:2*a<1?o:3*a<2?l+(o-l)*(2/3-a)*6:l,d[t]=255*h;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[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*a,radToDeg:t=>t*h,_degToRad:t=>(_.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),_.degToRad(t)),_radToDeg:t=>(_.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),_.radToDeg(t)),_getRotation:t=>s.angleDeg?_.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(d+t)},error(t){console.error(d+t)},warn(t){s.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,s,r,n){let o,a,h;const l=(t-i)*(t-i)+(e-s)*(e-s);if(0==l)o=t,a=e,h=(r-i)*(r-i)+(n-s)*(n-s);else{const d=((r-t)*(i-t)+(n-e)*(s-e))/l;d<0?(o=t,a=e,h=(t-r)*(t-r)+(e-n)*(e-n)):d>1?(o=i,a=s,h=(i-r)*(i-r)+(s-n)*(s-n)):(o=t+d*(i-t),a=e+d*(s-e),h=(o-r)*(o-r)+(a-n)*(a-n))}return[o,a,h]},_getProjectionToLine(t,e,i){const s=_.cloneObject(t);let r=Number.MAX_VALUE;return e.forEach(function(n,o){if(!i&&o===e.length-1)return;const a=e[(o+1)%e.length],h=_._getProjectionToSegment(n.x,n.y,a.x,a.y,t.x,t.y),l=h[0],d=h[1],c=h[2];c<r&&(s.x=l,s.y=d,r=c)}),s},_prepareArrayForTween(t,e,i){const s=[],r=[];if(t.length>e.length){const i=e;e=t,t=i}for(let e=0;e<t.length;e+=2)s.push({x:t[e],y:t[e+1]});for(let t=0;t<e.length;t+=2)r.push({x:e[t],y:e[t+1]});const n=[];return r.forEach(function(t){const e=_._getProjectionToLine(t,s,i);n.push(e.x),n.push(e.y)}),n},_prepareToStringify(t){let e;t.visitedByCircularReferenceRemoval=!0;for(const i in t)if(t.hasOwnProperty(i)&&t[i]&&"object"==typeof t[i])if(e=Object.getOwnPropertyDescriptor(t,i),t[i].visitedByCircularReferenceRemoval||_._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===_._prepareToStringify(t[i])){if(!e.configurable)return null;delete t[i]}return delete t.visitedByCircularReferenceRemoval,t},_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){s.releaseCanvasOnDestroy&&t.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(t,e,i,s){let r=e<0?e:0,n=i<0?i:0;e=Math.abs(e),i=Math.abs(i);let o=0,a=0,h=0,l=0;"number"==typeof s?o=a=h=l=Math.min(s,e/2,i/2):(o=Math.min(s[0]||0,e/2,i/2),a=Math.min(s[1]||0,e/2,i/2),l=Math.min(s[2]||0,e/2,i/2),h=Math.min(s[3]||0,e/2,i/2)),t.moveTo(r+o,n),t.lineTo(r+e-a,n),t.arc(r+e-a,n+a,a,3*Math.PI/2,0,!1),t.lineTo(r+e,n+i-l),t.arc(r+e-l,n+i-l,l,0,Math.PI/2,!1),t.lineTo(r+h,n+i),t.arc(r+h,n+i-h,h,Math.PI/2,Math.PI,!1),t.lineTo(r,n+o),t.arc(r+o,n+o,o,Math.PI,3*Math.PI/2,!1)},drawRoundedPolygonPath(t,e,i,s,r){s=Math.abs(s);for(let n=0;n<i;n++){const o=e[(n-1+i)%i],a=e[n],h=e[(n+1)%i],l={x:a.x-o.x,y:a.y-o.y},d={x:h.x-a.x,y:h.y-a.y},c=Math.hypot(l.x,l.y),g=Math.hypot(d.x,d.y);let f;f="number"==typeof r?r:n<r.length?r[n]:0;f=s*Math.cos(Math.PI/i)*Math.min(1,f/s*2);const u={x:l.x/c,y:l.y/c},p={x:d.x/g,y:d.y/g},_={x:a.x-u.x*f,y:a.y-u.y*f},m={x:a.x+p.x*f,y:a.y+p.y*f};0===n?t.moveTo(_.x,_.y):t.lineTo(_.x,_.y),t.arcTo(a.x,a.y,m.x,m.y,f)}}};const m=["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 y,x=null;function v(){if(null!==x)return x;try{const t=_.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(x=!1,!1)}catch(t){return x=!1,!1}}class w{constructor(t){this.canvas=t,s.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,s,r,n,o=this.traceArr,a=o.length,h="";for(i=0;i<a;i++)s=o[i],r=s.method,r?(n=s.args,h+=r,t?h+="()":_._isArray(n[0])?h+="(["+n.join(",")+"])":(e&&(n=n.map(t=>"number"==typeof t?Math.floor(t):t)),h+="("+n.join(",")+")")):(h+=s.property,t||(h+="="+s.val)),h+=";";return h}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)}_applyMiterLimit(t){const e=t.attrs.miterLimit;null!=e&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,r,n){this._context.arc(t,e,i,s,r,n)}arcTo(t,e,i,s,r){this._context.arcTo(t,e,i,s,r)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,r,n){this._context.bezierCurveTo(t,e,i,s,r,n)}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;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}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,r,n){return this._context.createRadialGradient(t,e,i,s,r,n)}drawImage(t,e,i,s,r,n,o,a,h){const l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,s,r):9===l.length&&d.drawImage(t,e,i,s,r,n,o,a,h)}ellipse(t,e,i,s,r,n,o,a){this._context.ellipse(t,e,i,s,r,n,o,a)}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,r){this._context.roundRect(t,e,i,s,r)}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,r,n){this._context.setTransform(t,e,i,s,r,n)}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,r,n){this._context.transform(t,e,i,s,r,n)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t,e,i=this,s=m.length,r=this.setAttr;const n=function(t){let s,r=i[t];i[t]=function(){return e=function(t){const e=[],i=t.length,s=_;for(let r=0;r<i;r++){let i=t[r];s._isNumber(i)?i=Math.round(1e3*i)/1e3:s._isString(i)||(i+=""),e.push(i)}return e}(Array.prototype.slice.call(arguments,0)),s=r.apply(i,arguments),i._trace({method:t,args:e}),s}};for(t=0;t<s;t++)n(m[t]);i.setAttr=function(){r.apply(i,arguments);const t=arguments[0];let e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),i._trace({property:t,val:e})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||"source-over"===e||this.setAttr("globalCompositeOperation",e)}}["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"].forEach(function(t){Object.defineProperty(w.prototype,t,{get(){return this._context[t]},set(e){this._context[t]=e}})});class S extends w{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 s=t.getFillPatternImage();if(s&&"pattern"===i)return void this._fillPattern(t);const r=t.getFillLinearGradientColorStops();if(r&&"linear-gradient"===i)return void this._fillLinearGradient(t);const n=t.getFillRadialGradientColorStops();n&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):s?this._fillPattern(t):r?this._fillLinearGradient(t):n&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),r=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let t=0;t<s.length;t+=2)r.addColorStop(s[t],s[t+1]);this.setAttr("strokeStyle",r)}}_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,s;const r=null!==(e=t.getShadowRGBA())&&void 0!==e?e:"black",n=null!==(i=t.getShadowBlur())&&void 0!==i?i:5,o=null!==(s=t.getShadowOffset())&&void 0!==s?s:{x:0,y:0},a=t.getAbsoluteScale(),h=this.canvas.getPixelRatio(),l=a.x*h,d=a.y*h;this.setAttr("shadowColor",r),this.setAttr("shadowBlur",n*Math.min(Math.abs(l),Math.abs(d))),this.setAttr("shadowOffsetX",o.x*l),this.setAttr("shadowOffsetY",o.y*d)}}class b extends w{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(),s="auto"===i?t.strokeWidth():i;this.setAttr("lineWidth",s),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}}class C{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const e=(t||{}).pixelRatio||s.pixelRatio||function(){if(y)return y;const t=_.createCanvasElement(),e=t.getContext("2d");return y=(s._global.devicePixelRatio||1)/(e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1),_.releaseCanvas(t),y}();this.pixelRatio=e,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(t){try{return this._canvas.toDataURL()}catch(t){return _.error("Unable to get data URL. "+t.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class T extends C{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new S(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}class A extends C{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new b(this),this.setSize(t.width,t.height)}}const k={get isDragging(){let t=!1;return k._dragElements.forEach(e=>{"dragging"===e.dragStatus&&(t=!0)}),t},justDragged:!1,get node(){let t;return k._dragElements.forEach(e=>{t=e.node}),t},_dragElements:new Map,_drag(t){const e=[];k._dragElements.forEach((i,s)=>{const{node:r}=i,n=r.getStage();n.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=_._getFirstPointerId(t));const o=n._changedPointerPositions.find(t=>t.id===i.pointerId);if(o){if("dragging"!==i.dragStatus){const e=r.dragDistance();if(Math.max(Math.abs(o.x-i.startPointerPos.x),Math.abs(o.y-i.startPointerPos.y))<e)return;if(r.startDrag({evt:t}),!r.isDragging())return}r._setDragPosition(t,i),e.push(r)}}),e.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)})},_endDragBefore(t){const e=[];k._dragElements.forEach(i=>{const{node:r}=i,n=r.getStage();t&&n.setPointersPositions(t);if(!n._changedPointerPositions.find(t=>t.id===i.pointerId))return;"dragging"!==i.dragStatus&&"stopped"!==i.dragStatus||(k.justDragged=!0,s._mouseListenClick=!1,s._touchListenClick=!1,s._pointerListenClick=!1,i.dragStatus="stopped");const o=i.node.getLayer()||i.node instanceof s.Stage&&i.node;o&&-1===e.indexOf(o)&&e.push(o)}),e.forEach(t=>{t.draw()})},_endDragAfter(t){k._dragElements.forEach((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&k._dragElements.delete(i)})}};function P(t){return _._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||_._isBoolean(t)?t:Object.prototype.toString.call(t)}function M(t){return t>255?255:t<0?0:Math.round(t)}function R(){if(s.isUnminified)return function(t,e){return _._isNumber(t)||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function I(t){if(s.isUnminified)return function(e,i){let s=_._isNumber(e),r=_._isArray(e)&&e.length==t;return s||r||_.warn(P(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array<number>('+t+")"),e}}function E(){if(s.isUnminified)return function(t,e){return _._isNumber(t)||"auto"===t||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function L(){if(s.isUnminified)return function(t,e){return _._isString(t)||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function G(){if(s.isUnminified)return function(t,e){const i=_._isString(t),s="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||s||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function O(){if(s.isUnminified)return function(t,e){return!0===t||!1===t||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}s.isBrowser&&(window.addEventListener("mouseup",k._endDragBefore,!0),window.addEventListener("touchend",k._endDragBefore,!0),window.addEventListener("touchcancel",k._endDragBefore,!0),window.addEventListener("mousemove",k._drag),window.addEventListener("touchmove",k._drag),window.addEventListener("mouseup",k._endDragAfter,!1),window.addEventListener("touchend",k._endDragAfter,!1),window.addEventListener("touchcancel",k._endDragAfter,!1));const D="get",F="set",W={addGetterSetter(t,e,i,s,r){W.addGetter(t,e,i),W.addSetter(t,e,s,r),W.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){const s=D+_._capitalize(e);t.prototype[s]=t.prototype[s]||function(){const t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,s){const r=F+_._capitalize(e);t.prototype[r]||W.overWriteSetter(t,e,i,s)},overWriteSetter(t,e,i,s){const r=F+_._capitalize(e);t.prototype[r]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),s&&s.call(this),this}},addComponentsGetterSetter(t,e,i,r,n){const o=i.length,a=_._capitalize,h=D+a(e),l=F+a(e);t.prototype[h]=function(){const t={};for(let s=0;s<o;s++){const r=i[s];t[r]=this.getAttr(e+a(r))}return t};const d=function(t){if(s.isUnminified)return function(e,i){return null==e||_.isObject(e)||_.warn(P(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}}(i);t.prototype[l]=function(t){const s=this.attrs[e];r&&(t=r.call(this,t,e)),d&&d.call(this,t,e);for(const i in t)t.hasOwnProperty(i)&&this._setAttr(e+a(i),t[i]);return t||i.forEach(t=>{this._setAttr(e+a(t),void 0)}),this._fireChangeEvent(e,s,t),n&&n.call(this),this},W.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){const i=_._capitalize(e),s=F+i,r=D+i;t.prototype[e]=function(){return arguments.length?(this[s](arguments[0]),this):this[r]()}},addDeprecatedGetterSetter(t,e,i,s){_.error("Adding deprecated "+e);const r=D+_._capitalize(e),n=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[r]=function(){_.error(n);const t=this.attrs[e];return void 0===t?i:t},W.addSetter(t,e,s,function(){_.error(n)}),W.addOverloadedGetterSetter(t,e)},backCompat(t,e){_.each(e,function(e,i){const s=t.prototype[i],r=D+_._capitalize(e),n=F+_._capitalize(e);function o(){s.apply(this,arguments),_.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=o,t.prototype[r]=o,t.prototype[n]=o})},afterSetFilter(){this._filterUpToDate=!1}};function B(t){const e=/(\w+)\(([^)]+)\)/g;let i;for(;null!==(i=e.exec(t));){const[,t,e]=i;switch(t){case"blur":{const t=parseFloat(e.replace("px",""));return function(e){this.blurRadius(.5*t);const i=s.Filters;i&&i.Blur&&i.Blur.call(this,e)}}case"brightness":{const t=e.includes("%")?parseFloat(e)/100:parseFloat(e);return function(e){this.brightness(t);const i=s.Filters;i&&i.Brightness&&i.Brightness.call(this,e)}}case"contrast":{const t=parseFloat(e);return function(e){const i=100*(Math.sqrt(t)-1);this.contrast(i);const r=s.Filters;r&&r.Contrast&&r.Contrast.call(this,e)}}case"grayscale":return function(t){const e=s.Filters;e&&e.Grayscale&&e.Grayscale.call(this,t)};case"sepia":return function(t){const e=s.Filters;e&&e.Sepia&&e.Sepia.call(this,t)};case"invert":return function(t){const e=s.Filters;e&&e.Invert&&e.Invert.call(this,t)};default:_.warn(`CSS filter "${t}" is not supported in fallback mode. Consider using function filters for better compatibility.`)}}return()=>{}}const N="absoluteOpacity",z="allEventListeners",H="absoluteTransform",X="absoluteScale",Y="canvas",j="listening",U="Shape",q=" ",K="stage",V="transform",Q="visible",J=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(q);let Z=1;class ${constructor(t){this._id=Z++,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!==V&&t!==H||!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===V||t===H)&&!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(q);this.on(i,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(Y)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===H&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(Y)){const{scene:t,filter:e,hit:i,buffer:s}=this._cache.get(Y);_.releaseCanvas(t,e,i,s),this._cache.delete(Y)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),r=Math.ceil(e.height||i.height),n=e.pixelRatio,o=void 0===e.x?Math.floor(i.x):e.x,a=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(!s||!r)return void _.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");s+=2*h+(Math.abs(Math.round(i.x)-o)>.5?1:0),r+=2*h+(Math.abs(Math.round(i.y)-a)>.5?1:0),o-=h,a-=h;const c=new T({pixelRatio:n,width:s,height:r}),g=new T({pixelRatio:n,width:0,height:0,willReadFrequently:!0}),f=new A({pixelRatio:d,width:s,height:r}),u=c.getContext(),p=f.getContext(),m=new T({width:c.width/c.pixelRatio+Math.abs(o),height:c.height/c.pixelRatio+Math.abs(a),pixelRatio:c.pixelRatio}),y=m.getContext();return f.isCache=!0,c.isCache=!0,this._cache.delete(Y),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,g.getContext()._context.imageSmoothingEnabled=!1),u.save(),p.save(),y.save(),u.translate(-o,-a),p.translate(-o,-a),y.translate(-o,-a),m.x=o,m.y=a,this._isUnderCache=!0,this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(X),this.drawScene(c,this,m),this.drawHit(f,this),this._isUnderCache=!1,u.restore(),p.restore(),l&&(u.save(),u.beginPath(),u.rect(0,0,s,r),u.closePath(),u.setAttr("strokeStyle","red"),u.setAttr("lineWidth",5),u.stroke(),u.restore()),this._cache.set(Y,{scene:c,filter:g,hit:f,buffer:m,x:o,y:a}),this._requestDraw(),this}isCached(){return this._cache.has(Y)}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,r=1/0,n=-1/0,o=-1/0;const a=this.getAbsoluteTransform(e);return i.forEach(function(t){const e=a.point(t);void 0===s&&(s=n=e.x,r=o=e.y),s=Math.min(s,e.x),r=Math.min(r,e.y),n=Math.max(n,e.x),o=Math.max(o,e.y)}),{x:s,y:r,width:n-s,height:o-r}}_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,e,i,s,r=this.filters(),n=this._getCanvasCache(),o=n.scene,a=n.filter,h=a.getContext();if(!r||0===r.length)return o;if(this._filterUpToDate)return a;let l=!0;for(let t=0;t<r.length;t++)if("string"==typeof r[t]&&v(),"string"!=typeof r[t]||!v()){l=!1;break}const d=o.pixelRatio;if(a.setSize(o.width/o.pixelRatio,o.height/o.pixelRatio),l){const t=r.join(" ");return h.save(),h.setAttr("filter",t),h.drawImage(o._canvas,0,0,o.getWidth()/d,o.getHeight()/d),h.restore(),this._filterUpToDate=!0,a}try{for(t=r.length,h.clear(),h.drawImage(o._canvas,0,0,o.getWidth()/d,o.getHeight()/d),e=h.getImageData(0,0,a.getWidth(),a.getHeight()),i=0;i<t;i++)s=r[i],"string"==typeof s&&(s=B(s)),s.call(this,e),h.putImageData(e,0,0)}catch(t){_.error("Unable to apply filter. "+t.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,a}on(t,e){if(this._cache&&this._cache.delete(z),3===arguments.length)return this._delegate.apply(this,arguments);const i=t.split(q);for(let t=0;t<i.length;t++){const s=i[t].split("."),r=s[0],n=s[1]||"";this.eventListeners[r]||(this.eventListeners[r]=[]),this.eventListeners[r].push({name:n,handler:e})}return this}off(t,e){let i,s,r,n,o,a,h=(t||"").split(q),l=h.length;if(this._cache&&this._cache.delete(z),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<l;i++)if(r=h[i],n=r.split("."),o=n[0],a=n[1],o)this.eventListeners[o]&&this._off(o,a,e);else for(s in this.eventListeners)this._off(s,a,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 s=this;this.on(t,function(t){const r=t.target.findAncestors(e,!0,s);for(let e=0;e<r.length;e++)(t=_.cloneObject(t)).currentTarget=r[e],i.call(r[e],t)})}remove(){return this.isDragging()&&this.stopDrag(),k._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(H),this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(X),this._clearSelfAndDescendantCache(K),this._clearSelfAndDescendantCache(Q),this._clearSelfAndDescendantCache(j)}_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)"children"!==e&&(i="set"+_._capitalize(e),_._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(j,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(Q,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const i=this.getLayer();let r=!1;k._dragElements.forEach(t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===i)&&(r=!0)});const n=!e&&!s.hitOnDragEnabled&&(r||s.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,e,i,s,r=this.getDepth(),n=this,o=0;const a=this.getStage();return"Stage"!==n.nodeType&&a&&function a(h){for(t=[],e=h.length,i=0;i<e;i++)s=h[i],o++,s.nodeType!==U&&(t=t.concat(s.getChildren().slice())),s._id===n._id&&(i=e);t.length>0&&t[0].getDepth()<=r&&a(t)}(a.getChildren()),o}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(V),this._clearSelfAndDescendantCache(H)),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(),r=new o,n=this.offset();return r.m=s.slice(),r.translate(n.x,n.y),r.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(V);const r=this._getAbsoluteTransform().copy();return r.invert(),r.translate(t.x,t.y),t={x:this.attrs.x+r.getTranslation().x,y:this.attrs.y+r.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(V),this._clearSelfAndDescendantCache(H),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(),r=this.y();return void 0!==e&&(s+=e),void 0!==i&&(r+=i),this.setPosition({x:s,y:r}),this}_eachAncestorReverse(t,e){let i,s,r=[],n=this.getParent();if(!e||e._id!==this._id){for(r.unshift(this);n&&(!e||n._id!==e._id);)r.unshift(n),n=n.parent;for(i=r.length,s=0;s<i;s++)t(r[s])}}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;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 _.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 _.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 _.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 _.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(N,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,s,r,n=this.getAttrs();const o={attrs:{},className:this.getClassName()};for(t in n)e=n[t],r=_.isObject(e)&&!_._isPlainObject(e)&&!_._isArray(e),r||(i="function"==typeof this[t]&&this[t],delete n[t],s=i?i.call(this):null,n[t]=e,s!==e&&(o.attrs[t]=e));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 r=this.parent;for(;r;){if(r===i)return s;r._isMatch(t)&&s.push(r),r=r.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("function"==typeof t)return t(this);let e,i,s=t.replace(/ /g,"").split(","),r=s.length;for(e=0;e<r;e++)if(i=s[e],_.isValidSelector(i)||(_.warn('Selector "'+i+'" 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?")),"#"===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(K,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(H,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new o,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(H)||new o,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,s=this.attrs.offsetX||0,r=this.attrs.offsetY||0;e.translate(t-s,i-r)}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(V,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(V)||new o;i.reset();const r=this.x(),n=this.y(),a=s.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,d=this.attrs.skewX||0,c=this.attrs.skewY||0,g=this.attrs.offsetX||0,f=this.attrs.offsetY||0;return 0===r&&0===n||i.translate(r,n),0!==a&&i.rotate(a),0===d&&0===c||i.skew(d,c),1===h&&1===l||i.scale(h,l),0===g&&0===f||i.translate(-1*g,-1*f),i.dirty=!1,i}clone(t){let e,i,s,r,n,o=_.cloneObject(this.attrs);for(e in t)o[e]=t[e];const a=new this.constructor(o);for(e in this.eventListeners)for(i=this.eventListeners[e],s=i.length,r=0;r<s;r++)n=i[r],n.name.indexOf("konva")<0&&(a.eventListeners[e]||(a.eventListeners[e]=[]),a.eventListeners[e].push(n));return a}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=void 0!==t.x?t.x:Math.floor(e.x),r=void 0!==t.y?t.y:Math.floor(e.y),n=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:n}),a=o.getContext(),h=new T({width:o.width/o.pixelRatio+Math.abs(s),height:o.height/o.pixelRatio+Math.abs(r),pixelRatio:o.pixelRatio});return!1===t.imageSmoothingEnabled&&(a._context.imageSmoothingEnabled=!1),a.save(),(s||r)&&a.translate(-1*s,-1*r),this.drawScene(o,void 0,h),a.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){const e=(t=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 i=null==t?void 0:t.callback;i&&delete t.callback,_._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():s.dragDistance}_off(t,e,i){let s,r,n,o=this.eventListeners[t];for(s=0;s<o.length;s++)if(r=o[s].name,n=o[s].handler,!("konva"===r&&"konva"!==e||e&&r!==e||i&&i!==n)){if(o.splice(s,1),0===o.length){delete this.eventListeners[t];break}s--}}_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"+_._capitalize(t)];return _._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(s.autoDrawEnabled){const t=this.getLayer()||this.getStage();null==t||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];(i!==e||_.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 s;void 0!==i&&(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===U&&(e.target=this);const s=["mouseenter","mouseleave","pointerenter","pointerleave","touchenter","touchleave"];if(!(-1!==s.indexOf(t)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);const r=-1!==s.indexOf(t)&&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,s;const r=null!==(e=this._cache.get(z))&&void 0!==e?e:{};let n=null==r?void 0:r[t];if(void 0===n){n=[];let e=Object.getPrototypeOf(this);for(;e;){const r=null!==(s=null===(i=e.eventListeners)||void 0===i?void 0:i[t])&&void 0!==s?s:[];n.push(...r),e=Object.getPrototypeOf(e)}r[t]=n,this._cache.set(z,r)}return n}_fire(t,e){(e=e||{}).currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let t=0;t<i.length;t++)i[t].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let t=0;t<s.length;t++)s[t].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 r=i._getPointerById(e)||i._changedPointerPositions[0]||s;k._dragElements.set(this._id,{node:this,startPointerPos:r,offset:{x:r.x-s.x,y:r.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){k._dragElements.has(this._id)||this._createDragElement(t);k._dragElements.get(this._id).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 r=this.dragBoundFunc();if(void 0!==r){const e=r.call(this,s,t);e?s=e:_.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=k._dragElements.get(this._id);e&&(e.dragStatus="stopped"),k._endDragBefore(t),k._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=k._dragElements.get(this._id);return!!t&&"dragging"===t.dragStatus}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(void 0!==t.evt.button)||s.dragButtons.indexOf(t.evt.button)>=0))return;if(this.isDragging())return;let e=!1;k._dragElements.forEach(t=>{this.isAncestorOf(t.node)&&(e=!0)}),e||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();if(!this.getStage())return;const t=k._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&k._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,r,n,o=$.prototype.getClassName.call(t),a=t.children;e&&(t.attrs.container=e),s[o]||(_.warn('Can not find a node with class name "'+o+'". Fallback to "Shape".'),o="Shape");if(i=new(0,s[o])(t.attrs),a)for(r=a.length,n=0;n<r;n++)i.add($._createNode(a[n]));return i}}$.prototype.nodeType="Node",$.prototype._attrsAffectingSize=[],$.prototype.eventListeners={},$.prototype.on.call($.prototype,J,function(){this._batchingTransformChange?this._needClearTransformCache=!0:(this._clearCache(V),this._clearSelfAndDescendantCache(H))}),$.prototype.on.call($.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(Q)}),$.prototype.on.call($.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(j)}),$.prototype.on.call($.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(N)});const tt=W.addGetterSetter;tt($,"zIndex"),tt($,"absolutePosition"),tt($,"position"),tt($,"x",0,R()),tt($,"y",0,R()),tt($,"globalCompositeOperation","source-over",L()),tt($,"opacity",1,R()),tt($,"name","",L()),tt($,"id","",L()),tt($,"rotation",0,R()),W.addComponentsGetterSetter($,"scale",["x","y"]),tt($,"scaleX",1,R()),tt($,"scaleY",1,R()),W.addComponentsGetterSetter($,"skew",["x","y"]),tt($,"skewX",0,R()),tt($,"skewY",0,R()),W.addComponentsGetterSetter($,"offset",["x","y"]),tt($,"offsetX",0,R()),tt($,"offsetY",0,R()),tt($,"dragDistance",void 0,R()),tt($,"width",0,R()),tt($,"height",0,R()),tt($,"listening",!0,O()),tt($,"preventDefault",!0,O()),tt($,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),tt($,"visible",!0,O()),tt($,"transformsEnabled","all",L()),tt($,"size"),tt($,"dragBoundFunc"),tt($,"draggable",!1,O()),W.backCompat($,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class et extends ${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(0===t.length)return this;if(t.length>1){for(let e=0;e<t.length;e++)this.add(t[e]);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 r=s._isMatch(t);return r&&i.push(s),!(!r||!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=$.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=$.prototype.clone.call(this,t);return this.getChildren().forEach(function(t){e.add(t.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()||null===(e=this.children)||void 0===e||e.forEach(function(e){e._clearSelfAndDescendantCache(t)})}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach(function(t,e){t.index=e}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas(),n=r&&r.getContext(),o=this._getCanvasCache(),a=o&&o.scene,h=r&&r.isCache;if(!this.isVisible()&&!h)return this;if(a){n.save();const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(n),n.restore()}else this._drawChildren("drawScene",r,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,r=s&&s.getContext(),n=this._getCanvasCache();if(n&&n.hit){r.save();const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(r),r.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var r;const n=e&&e.getContext(),o=this.clipWidth(),a=this.clipHeight(),h=this.clipFunc(),l="number"==typeof o&&"number"==typeof a||h,d=i===this;if(l){n.save();const t=this.getAbsoluteTransform(i);let e,s=t.getMatrix();if(n.transform(s[0],s[1],s[2],s[3],s[4],s[5]),n.beginPath(),h)e=h.call(this,n,this);else{const t=this.clipX(),e=this.clipY();n.rect(t||0,e||0,o,a)}n.clip.apply(n,e),s=t.copy().invert().getMatrix(),n.transform(s[0],s[1],s[2],s[3],s[4],s[5])}const c=!d&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;c&&(n.save(),n._applyGlobalCompositeOperation(this)),null===(r=this.children)||void 0===r||r.forEach(function(r){r[t](e,i,s)}),c&&n.restore(),l&&n.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let r,n,o,a,h={x:1/0,y:1/0,width:0,height:0};const l=this;null===(e=this.children)||void 0===e||e.forEach(function(e){if(!e.visible())return;const i=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===i.width&&0===i.height||(void 0===r?(r=i.x,n=i.y,o=i.x+i.width,a=i.y+i.height):(r=Math.min(r,i.x),n=Math.min(n,i.y),o=Math.max(o,i.x+i.width),a=Math.max(a,i.y+i.height)))});const d=this.find("Shape");let c=!1;for(let t=0;t<d.length;t++){if(d[t]._isVisible(this)){c=!0;break}}return h=c&&void 0!==r?{x:r,y:n,width:o-r,height:a-n}:{x:0,y:0,width:0,height:0},i?h:this._transformedRect(h,s)}}W.addComponentsGetterSetter(et,"clip",["x","y","width","height"]),W.addGetterSetter(et,"clipX",void 0,R()),W.addGetterSetter(et,"clipY",void 0,R()),W.addGetterSetter(et,"clipWidth",void 0,R()),W.addGetterSetter(et,"clipHeight",void 0,R()),W.addGetterSetter(et,"clipFunc");const it=new Map,st=void 0!==s._global.PointerEvent;function rt(t){return it.get(t)}function nt(t){return{evt:t,pointerId:t.pointerId}}function ot(t,e){return it.get(t)===e}function at(t,e){ht(t);e.getStage()&&(it.set(t,e),st&&e._fire("gotpointercapture",nt(new PointerEvent("gotpointercapture"))))}function ht(t,e){const i=it.get(t);if(!i)return;const s=i.getStage();s&&s.content,it.delete(t),st&&i._fire("lostpointercapture",nt(new PointerEvent("lostpointercapture")))}const lt="mouseleave",dt="mouseover",ct="mouseenter",gt="mousemove",ft="mousedown",ut="mouseup",pt="pointermove",_t="pointerdown",mt="pointerup",yt="pointercancel",xt="pointerout",vt="pointerleave",wt="pointerover",St="pointerenter",bt="contextmenu",Ct="touchstart",Tt="touchend",At="touchmove",kt="touchcancel",Pt="wheel",Mt=[[ct,"_pointerenter"],[ft,"_pointerdown"],[gt,"_pointermove"],[ut,"_pointerup"],[lt,"_pointerleave"],[Ct,"_pointerdown"],[At,"_pointermove"],[Tt,"_pointerup"],[kt,"_pointercancel"],[dt,"_pointerover"],[Pt,"_wheel"],[bt,"_contextmenu"],[_t,"_pointerdown"],[pt,"_pointermove"],[mt,"_pointerup"],[yt,"_pointercancel"],[vt,"_pointerleave"],["lostpointercapture","_lostpointercapture"]],Rt={mouse:{[xt]:"mouseout",[vt]:lt,[wt]:dt,[St]:ct,[pt]:gt,[_t]:ft,[mt]:ut,[yt]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[xt]:"touchout",[vt]:"touchleave",[wt]:"touchover",[St]:"touchenter",[pt]:At,[_t]:Ct,[mt]:Tt,[yt]:kt,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[xt]:xt,[vt]:vt,[wt]:wt,[St]:St,[pt]:pt,[_t]:_t,[mt]:mt,[yt]:yt,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},It=t=>t.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",Et=t=>{const e=It(t);return"pointer"===e?s.pointerEventsEnabled&&Rt.pointer:"touch"===e?Rt.touch:"mouse"===e?Rt.mouse:void 0};function Lt(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&_.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const Gt=[];class Ot extends et{constructor(t){super(Lt(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),Gt.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{Lt(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();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("string"==typeof t){let e;if("."===t.charAt(0)){const e=t.slice(1);t=document.getElementsByClassName(e)[0]}else e="#"!==t.charAt(0)?t: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="undefined"!=typeof document&&document.createElement("div"),et.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&_._isInDocument(t)&&this.container().removeChild(t);const e=Gt.indexOf(this);return e>-1&&Gt.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("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);"),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}).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(e){if(!e.isVisible())return;const s=e._toKonvaCanvas(t);i.drawImage(s._canvas,t.x,t.y,s.getWidth()/s.getPixelRatio(),s.getHeight()/s.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children;for(let i=e.length-1;i>=0;i--){const s=e[i].getIntersection(t);if(s)return s}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),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 t=0;t<arguments.length;t++)this.add(arguments[t]);return this}super.add(t);const i=this.children.length;return i>5&&_.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(),s.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return ot(t,this)}setPointerCapture(t){at(t,this)}releaseCapture(t){ht(t)}getLayers(){return this.children}_bindContentEvents(){s.isBrowser&&Mt.forEach(([t,e])=>{this.content.addEventListener(t,t=>{this[e](t)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=Et(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Et(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=Et(t.type),i=It(t.type);if(!e)return;this.setPointersPositions(t);const r=this._getTargetShape(i),n=!(s.isDragging()||s.isTransforming())||s.hitOnDragEnabled;r&&n?(r._fireAndBubble(e.pointerout,{evt:t}),r._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=Et(t.type),i=It(t.type);if(!e)return;this.setPointersPositions(t);let r=!1;this._changedPointerPositions.forEach(n=>{const o=this.getIntersection(n);if(k.justDragged=!1,s["_"+i+"ListenClick"]=!0,!o||!o.isListening())return void(this[i+"ClickStartShape"]=void 0);s.capturePointerEventsEnabled&&o.setPointerCapture(n.id),this[i+"ClickStartShape"]=o,o._fireAndBubble(e.pointerdown,{evt:t,pointerId:n.id}),r=!0;const a=t.type.indexOf("touch")>=0;o.preventDefault()&&t.cancelable&&a&&t.preventDefault()}),r||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=Et(t.type),i=It(t.type);if(!e)return;const r=t.type.indexOf("touch")>=0||"touch"===t.pointerType;s.isDragging()&&k.node.preventDefault()&&t.cancelable&&r&&t.preventDefault(),this.setPointersPositions(t);if(!(!(s.isDragging()||s.isTransforming())||s.hitOnDragEnabled))return;const n={};let o=!1;const a=this._getTargetShape(i);this._changedPointerPositions.forEach(s=>{const r=rt(s.id)||this.getIntersection(s),h=s.id,l={evt:t,pointerId:h},d=a!==r;if(d&&a&&(a._fireAndBubble(e.pointerout,{...l},r),a._fireAndBubble(e.pointerleave,{...l},r)),r){if(n[r._id])return;n[r._id]=!0}r&&r.isListening()?(o=!0,d&&(r._fireAndBubble(e.pointerover,{...l},a),r._fireAndBubble(e.pointerenter,{...l},a),this[i+"targetShape"]=r),r._fireAndBubble(e.pointermove,{...l})):a&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[i+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Et(t.type),i=It(t.type);if(!e)return;this.setPointersPositions(t);const r=this[i+"ClickStartShape"],n=this[i+"ClickEndShape"],o={};let a=!1;this._changedPointerPositions.forEach(h=>{const l=rt(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),o[l._id])return;o[l._id]=!0}const d=h.id,c={evt:t,pointerId:d};let g=!1;s["_"+i+"InDblClickWindow"]?(g=!0,clearTimeout(this[i+"DblTimeout"])):k.justDragged||(s["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){s["_"+i+"InDblClickWindow"]=!1},s.dblClickWindow),l&&l.isListening()?(a=!0,this[i+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...c}),s["_"+i+"ListenClick"]&&r&&r===l&&(l._fireAndBubble(e.pointerclick,{...c}),g&&n&&n===l&&l._fireAndBubble(e.pointerdblclick,{...c}))):(this[i+"ClickEndShape"]=null,a||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),a=!0),s["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),g&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))}),a||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),s["_"+i+"ListenClick"]=!1,t.cancelable&&"touch"!==i&&"pointer"!==i&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(bt,{evt:t}):this._fire(bt,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Pt,{evt:t}):this._fire(Pt,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=rt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(mt,nt(t)),ht(t.pointerId)}_lostpointercapture(t){ht(t.pointerId)}setPointersPositions(t){const e=this._getContentPosition();let i=null,s=null;void 0!==(t=t||window.event).touches?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,t=>{this._pointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,t=>{this._changedPointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.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 A({pixelRatio:1,width:this.width(),height:this.height()}),!s.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}}Ot.prototype.nodeType="Stage",r(Ot),W.addGetterSetter(Ot,"container"),s.isBrowser&&document.addEventListener("visibilitychange",()=>{Gt.forEach(t=>{t.batchDraw()})});const Dt="hasShadow",Ft="shadowRGBA",Wt="patternImage",Bt="linearGradient",Nt="radialGradient";let zt;function Ht(){return zt||(zt=_.createCanvasElement().getContext("2d"),zt)}const Xt={};class Yt extends ${constructor(t){let e;super(t);let i=0;for(;e=_.getHitColor(),!e||e in Xt;)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,Xt[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(Dt,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Wt,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=Ht().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new o;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(s.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const i=e.getMatrix(),r="undefined"==typeof DOMMatrix?{a:i[0],b:i[1],c:i[2],d:i[3],e:i[4],f:i[5]}:new DOMMatrix(i);t.setTransform(r)}return t}}_getLinearGradient(){return this._getCache(Bt,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=Ht(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),r=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}_getRadialGradient(){return this._getCache(Nt,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=Ht(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),r=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}getShadowRGBA(){return this._getCache(Ft,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=_.colorToRGBA(this.shadowColor());return t?"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")":void 0}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"auto"===t?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){const e=this.getStage();if(!e)return!1;const i=e.bufferHitCanvas;i.getContext().clear(),this.drawHit(i,void 0,!0);return i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return $.prototype.destroy.call(this),delete Xt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),s=this.hasStroke(),r=1!==this.getAbsoluteOpacity();if(i&&s&&r)return!0;const n=this.hasShadow(),o=this.shadowForStrokeEnabled();return!!(i&&s&&n&&o)}setStrokeHitEnabled(t){_.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}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,r=t.relativeTo||e&&this.getStage()||void 0,n=this.getSelfRect(),o=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,a=n.width+o,h=n.height+o,l=!t.skipShadow&&this.hasShadow(),d=l?this.shadowOffsetX():0,c=l?this.shadowOffsetY():0,g=a+Math.abs(d),f=h+Math.abs(c),u=l&&this.shadowBlur()||0,p={width:g+2*u,height:f+2*u,x:-(o/2+u)+Math.min(d,0)+n.x,y:-(o/2+u)+Math.min(c,0)+n.y};return s?p:this._transformedRect(p,r)}drawScene(t,e,i){const s=this.getLayer(),r=(t||s.getCanvas()).getContext(),n=this._getCanvasCache(),o=this.getSceneFunc(),a=this.hasShadow();let h;const l=e===this;if(!this.isVisible()&&!l)return this;if(n){r.save();const t=this.getAbsoluteTransform(e).getMatrix();return r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(r),r.restore(),this}if(!o)return this;if(r.save(),this._useBufferCanvas()){h=this.getStage();const t=i||h.bufferCanvas,s=t.getContext();s.clear(),s.save(),s._applyLineJoin(this),s._applyMiterLimit(this);const n=this.getAbsoluteTransform(e).getMatrix();s.transform(n[0],n[1],n[2],n[3],n[4],n[5]),o.call(this,s,this),s.restore();const d=t.pixelRatio;a&&r._applyShadow(this),l||(r._applyOpacity(this),r._applyGlobalCompositeOperation(this)),r.drawImage(t._canvas,t.x||0,t.y||0,t.width/d,t.height/d)}else{if(r._applyLineJoin(this),r._applyMiterLimit(this),!l){const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),r._applyOpacity(this),r._applyGlobalCompositeOperation(this)}a&&r._applyShadow(this),o.call(this,r,this)}return r.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),r=t||s.hitCanvas,n=r&&r.getContext(),o=this.hitFunc()||this.sceneFunc(),a=this._getCanvasCache(),h=a&&a.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()"),h){n.save();const t=this.getAbsoluteTransform(e).getMatrix();return n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(n),n.restore(),this}if(!o)return this;n.save(),n._applyLineJoin(this),n._applyMiterLimit(this);if(!(this===e)){const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return o.call(this,n,this),n.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,r=s.getContext(),n=s.getWidth(),o=s.getHeight();r.clear(),r.drawImage(i._canvas,0,0,n,o);try{const e=r.getImageData(0,0,n,o),i=e.data,s=i.length,a=_._hexToRgb(this.colorKey);for(let e=0;e<s;e+=4){i[e+3]>t?(i[e]=a.r,i[e+1]=a.g,i[e+2]=a.b,i[e+3]=255):i[e+3]=0}r.putImageData(e,0,0)}catch(t){_.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}hasPointerCapture(t){return ot(t,this)}setPointerCapture(t){at(t,this)}releaseCapture(t){ht(t)}}Yt.prototype._fillFunc=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},Yt.prototype._strokeFunc=function(t){t.stroke()},Yt.prototype._fillFuncHit=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},Yt.prototype._strokeFuncHit=function(t){t.stroke()},Yt.prototype._centroid=!1,Yt.prototype.nodeType="Shape",r(Yt),Yt.prototype.eventListeners={},Yt.prototype.on.call(Yt.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(Dt)}),Yt.prototype.on.call(Yt.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(Ft)}),Yt.prototype.on.call(Yt.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",function(){this._clearCache(Wt)}),Yt.prototype.on.call(Yt.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",function(){this._clearCache(Bt)}),Yt.prototype.on.call(Yt.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",function(){this._clearCache(Nt)}),W.addGetterSetter(Yt,"stroke",void 0,G()),W.addGetterSetter(Yt,"strokeWidth",2,R()),W.addGetterSetter(Yt,"fillAfterStrokeEnabled",!1),W.addGetterSetter(Yt,"hitStrokeWidth","auto",E()),W.addGetterSetter(Yt,"strokeHitEnabled",!0,O()),W.addGetterSetter(Yt,"perfectDrawEnabled",!0,O()),W.addGetterSetter(Yt,"shadowForStrokeEnabled",!0,O()),W.addGetterSetter(Yt,"lineJoin"),W.addGetterSetter(Yt,"lineCap"),W.addGetterSetter(Yt,"miterLimit"),W.addGetterSetter(Yt,"sceneFunc"),W.addGetterSetter(Yt,"hitFunc"),W.addGetterSetter(Yt,"dash"),W.addGetterSetter(Yt,"dashOffset",0,R()),W.addGetterSetter(Yt,"shadowColor",void 0,L()),W.addGetterSetter(Yt,"shadowBlur",0,R()),W.addGetterSetter(Yt,"shadowOpacity",1,R()),W.addComponentsGetterSetter(Yt,"shadowOffset",["x","y"]),W.addGetterSetter(Yt,"shadowOffsetX",0,R()),W.addGetterSetter(Yt,"shadowOffsetY",0,R()),W.addGetterSetter(Yt,"fillPatternImage"),W.addGetterSetter(Yt,"fill",void 0,G()),W.addGetterSetter(Yt,"fillPatternX",0,R()),W.addGetterSetter(Yt,"fillPatternY",0,R()),W.addGetterSetter(Yt,"fillLinearGradientColorStops"),W.addGetterSetter(Yt,"strokeLinearGradientColorStops"),W.addGetterSetter(Yt,"fillRadialGradientStartRadius",0),W.addGetterSetter(Yt,"fillRadialGradientEndRadius",0),W.addGetterSetter(Yt,"fillRadialGradientColorStops"),W.addGetterSetter(Yt,"fillPatternRepeat","repeat"),W.addGetterSetter(Yt,"fillEnabled",!0),W.addGetterSetter(Yt,"strokeEnabled",!0),W.addGetterSetter(Yt,"shadowEnabled",!0),W.addGetterSetter(Yt,"dashEnabled",!0),W.addGetterSetter(Yt,"strokeScaleEnabled",!0),W.addGetterSetter(Yt,"fillPriority","color"),W.addComponentsGetterSetter(Yt,"fillPatternOffset",["x","y"]),W.addGetterSetter(Yt,"fillPatternOffsetX",0,R()),W.addGetterSetter(Yt,"fillPatternOffsetY",0,R()),W.addComponentsGetterSetter(Yt,"fillPatternScale",["x","y"]),W.addGetterSetter(Yt,"fillPatternScaleX",1,R()),W.addGetterSetter(Yt,"fillPatternScaleY",1,R()),W.addComponentsGetterSetter(Yt,"fillLinearGradientStartPoint",["x","y"]),W.addComponentsGetterSetter(Yt,"strokeLinearGradientStartPoint",["x","y"]),W.addGetterSetter(Yt,"fillLinearGradientStartPointX",0),W.addGetterSetter(Yt,"strokeLinearGradientStartPointX",0),W.addGetterSetter(Yt,"fillLinearGradientStartPointY",0),W.addGetterSetter(Yt,"strokeLinearGradientStartPointY",0),W.addComponentsGetterSetter(Yt,"fillLinearGradientEndPoint",["x","y"]),W.addComponentsGetterSetter(Yt,"strokeLinearGradientEndPoint",["x","y"]),W.addGetterSetter(Yt,"fillLinearGradientEndPointX",0),W.addGetterSetter(Yt,"strokeLinearGradientEndPointX",0),W.addGetterSetter(Yt,"fillLinearGradientEndPointY",0),W.addGetterSetter(Yt,"strokeLinearGradientEndPointY",0),W.addComponentsGetterSetter(Yt,"fillRadialGradientStartPoint",["x","y"]),W.addGetterSetter(Yt,"fillRadialGradientStartPointX",0),W.addGetterSetter(Yt,"fillRadialGradientStartPointY",0),W.addComponentsGetterSetter(Yt,"fillRadialGradientEndPoint",["x","y"]),W.addGetterSetter(Yt,"fillRadialGradientEndPointX",0),W.addGetterSetter(Yt,"fillRadialGradientEndPointY",0),W.addGetterSetter(Yt,"fillPatternRotation",0),W.addGetterSetter(Yt,"fillRule",void 0,L()),W.backCompat(Yt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const jt=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Ut=jt.length;class qt extends et{constructor(t){super(t),this.canvas=new T,this.hitCanvas=new A({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(){$.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(!$.prototype.moveUp.call(this))return!1;const t=this.getStage();return!(!t||!t.content)&&(t.content.removeChild(this.getNativeCanvasElement()),this.index<t.children.length-1?t.content.insertBefore(this.getNativeCanvasElement(),t.children[this.index+1].getCanvas()._canvas):t.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if($.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($.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 $.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();"Group"!==e&&"Shape"!==e&&_.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return(t={...t}).width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=void 0!==t.x?t.x:this.x(),t.y=void 0!==t.y?t.y:this.y(),$.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){const t=this.visible();this.canvas._canvas.style.display=t?"block":"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<Ut;s++){const r=jt[s],n=this._getIntersection({x:t.x+r.x*e,y:t.y+r.y*e}),o=n.shape;if(o)return o;if(i=!!n.antialiased,!n.antialiased)break}if(!i)return null;e+=1}}_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(255===s){const t=_.getHitColorKey(i[0],i[1],i[2]),e=Xt[t];return e?{shape:e}:{antialiased:!0}}return s>0?{antialiased:!0}:{}}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),et.prototype.drawScene.call(this,r,e,i),this._fire("draw",{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),et.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()}}qt.prototype.nodeType="Layer",r(qt),W.addGetterSetter(qt,"imageSmoothingEnabled",!0),W.addGetterSetter(qt,"clearBeforeDraw",!0),W.addGetterSetter(qt,"hitGraphEnabled",!0,O());class Kt extends qt{constructor(t){super(t),this.listening(!1),_.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}Kt.prototype.nodeType="FastLayer",r(Kt);class Vt extends et{_validateAdd(t){const e=t.getType();"Group"!==e&&"Shape"!==e&&_.throw("You may only add groups and shapes to groups.")}}Vt.prototype.nodeType="Group",r(Vt);const Qt=i.performance&&i.performance.now?function(){return i.performance.now()}:function(){return(new Date).getTime()};class Jt{constructor(t,e){this.id=Jt.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:Qt(),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 t=Jt.animations,e=t.length;for(let i=0;i<e;i++)if(t[i].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=Qt(),Jt._addAnimation(this),this}stop(){return Jt._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 t=0;t<s;t++)if(i[t].id===e){this.animations.splice(t,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],r=s.layers,n=s.func;s._updateFrameObject(Qt());const o=r.length;let a;if(a=!n||!1!==n.call(s,s.frame),a)for(let e=0;e<o;e++){const i=r[e];void 0!==i._id&&(t[i._id]=i)}}for(const e in t)t.hasOwnProperty(e)&&t[e].batchDraw()}static _animationLoop(){const t=Jt;t.animations.length?(t._runFrames(),_.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,_.requestAnimFrame(this._animationLoop))}}Jt.animations=[],Jt.animIdCounter=0,Jt.animRunning=!1;const Zt={node:1,duration:1,easing:1,onFinish:1,yoyo:1},$t=["fill","stroke","shadowColor"];let te=0;class ee{constructor(t,e,i,s,r,n,o){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=n,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=r-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 void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,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;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class ie{constructor(t){const e=this,i=t.node,r=i._id,n=t.easing||se.Linear,o=!!t.yoyo;let a,h;a=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=i,this._id=te++;const l=i.getLayer()||(i instanceof s.Stage?i.getLayers():null);for(h in l||_.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Jt(function(){e.tween.onEnterFrame()},l),this.tween=new ee(h,function(t){e._tweenFunc(t)},n,0,1,1e3*a,o),this._addListeners(),ie.attrs[r]||(ie.attrs[r]={}),ie.attrs[r][this._id]||(ie.attrs[r][this._id]={}),ie.tweens[r]||(ie.tweens[r]={}),t)void 0===Zt[h]&&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 r,n,o,a,h;const l=ie.tweens[s][t];l&&delete ie.attrs[s][l][t];let d=i.getAttr(t);if(_._isArray(e))if(r=[],n=Math.max(e.length,d.length),"points"===t&&e.length!==d.length&&(e.length>d.length?(a=d,d=_._prepareArrayForTween(d,e,i.closed())):(o=e,e=_._prepareArrayForTween(e,d,i.closed()))),0===t.indexOf("fill"))for(let t=0;t<n;t++)if(t%2==0)r.push(e[t]-d[t]);else{const i=_.colorToRGBA(d[t]);h=_.colorToRGBA(e[t]),d[t]=i,r.push({r:h.r-i.r,g:h.g-i.g,b:h.b-i.b,a:h.a-i.a})}else for(let t=0;t<n;t++)r.push(e[t]-d[t]);else-1!==$t.indexOf(t)?(d=_.colorToRGBA(d),h=_.colorToRGBA(e),r={r:h.r-d.r,g:h.g-d.g,b:h.b-d.b,a:h.a-d.a}):r=e-d;ie.attrs[s][this._id][t]={start:d,diff:r,end:e,trueEnd:o,trueStart:a},ie.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=ie.attrs[e._id][this._id];let s,r,n,o,a,h,l,d;for(s in i){if(r=i[s],n=r.start,o=r.diff,d=r.end,_._isArray(n))if(a=[],l=Math.max(n.length,d.length),0===s.indexOf("fill"))for(h=0;h<l;h++)h%2==0?a.push((n[h]||0)+o[h]*t):a.push("rgba("+Math.round(n[h].r+o[h].r*t)+","+Math.round(n[h].g+o[h].g*t)+","+Math.round(n[h].b+o[h].b*t)+","+(n[h].a+o[h].a*t)+")");else for(h=0;h<l;h++)a.push((n[h]||0)+o[h]*t);else a=-1!==$t.indexOf(s)?"rgba("+Math.round(n.r+o.r*t)+","+Math.round(n.g+o.g*t)+","+Math.round(n.b+o.b*t)+","+(n.a+o.a*t)+")":n+o*t;e.setAttr(s,a)}}_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=ie.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=ie.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(1e3*t),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){const t=this.node._id,e=this._id,i=ie.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const e in i)delete ie.tweens[t][e];delete ie.attrs[t][e],ie.tweens[t]&&(0===Object.keys(ie.tweens[t]).length&&delete ie.tweens[t],0===Object.keys(ie.attrs[t]).length&&delete ie.attrs[t])}}ie.attrs={},ie.tweens={},$.prototype.to=function(t){const e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()};new ie(t).play()};const se={BackEaseIn(t,e,i,s){const r=1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},BackEaseOut(t,e,i,s){const r=1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},BackEaseInOut(t,e,i,s){let r=1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},ElasticEaseIn(t,e,i,s,r,n){let o=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)+e)},ElasticEaseOut(t,e,i,s,r,n){let o=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/n)+i+e)},ElasticEaseInOut(t,e,i,s,r,n){let o=0;return 0===t?e:2==(t/=s/2)?e+i:(n||(n=s*(.3*1.5)),!r||r<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*.5+i+e)},BounceEaseOut:(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,s)=>i-se.BounceEaseOut(s-t,0,i,s)+e,BounceEaseInOut:(t,e,i,s)=>t<s/2?.5*se.BounceEaseIn(2*t,0,i,s)+e:.5*se.BounceEaseOut(2*t-s,0,i,s)+.5*i+e,EaseIn:(t,e,i,s)=>i*(t/=s)*t+e,EaseOut:(t,e,i,s)=>-i*(t/=s)*(t-2)+e,EaseInOut:(t,e,i,s)=>(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e,StrongEaseIn:(t,e,i,s)=>i*(t/=s)*t*t*t*t+e,StrongEaseOut:(t,e,i,s)=>i*((t=t/s-1)*t*t*t*t+1)+e,StrongEaseInOut:(t,e,i,s)=>(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e,Linear:(t,e,i,s)=>i*t/s+e},re=_._assign(s,{Util:_,Transform:o,Node:$,Container:et,Stage:Ot,stages:Gt,Layer:qt,FastLayer:Kt,Group:Vt,DD:k,Shape:Yt,shapes:Xt,Animation:Jt,Tween:ie,Easings:se,Context:w,Canvas:C});class ne extends Yt{_sceneFunc(t){const e=s.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 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),i=this.clockwise(),r=s.getAngle(i?360-this.angle():this.angle()),n=Math.cos(Math.min(r,Math.PI)),o=Math.sin(Math.min(Math.max(Math.PI,r),3*Math.PI/2)),a=Math.sin(Math.min(r,Math.PI/2)),h=n*(n>0?t:e),l=o*(o>0?t:e),d=a*(a>0?e:t);return{x:h,y:i?-1*d:l,width:1*e-h,height:d-l}}}function oe(t,e,i,s,r,n,o){const a=Math.sqrt(Math.pow(i-t,2)+Math.pow(s-e,2)),h=Math.sqrt(Math.pow(r-i,2)+Math.pow(n-s,2)),l=o*a/(a+h),d=o*h/(a+h);return[i-l*(r-t),s-l*(n-e),i+d*(r-t),s+d*(n-e)]}function ae(t,e){const i=t.length,s=[];for(let r=2;r<i-2;r+=2){const i=oe(t[r-2],t[r-1],t[r],t[r+1],t[r+2],t[r+3],e);isNaN(i[0])||(s.push(i[0]),s.push(i[1]),s.push(t[r]),s.push(t[r+1]),s.push(i[2]),s.push(i[3]))}return s}ne.prototype._centroid=!0,ne.prototype.className="Arc",ne.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],r(ne),W.addGetterSetter(ne,"innerRadius",0,R()),W.addGetterSetter(ne,"outerRadius",0,R()),W.addGetterSetter(ne,"angle",0,R()),W.addGetterSetter(ne,"clockwise",!1,O());class he extends Yt{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(),r=this.closed(),n=this.bezier();if(!i)return;let o=0;if(t.beginPath(),t.moveTo(e[0],e[1]),0!==s&&i>4){const s=this.getTensionPoints(),n=s.length;for(o=r?0:4,r||t.quadraticCurveTo(s[0],s[1],s[2],s[3]);o<n-2;)t.bezierCurveTo(s[o++],s[o++],s[o++],s[o++],s[o++],s[o++]);r||t.quadraticCurveTo(s[n-2],s[n-1],e[i-2],e[i-1])}else if(n)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]);r?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():ae(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=oe(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),r=oe(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),n=ae(t,i);return[s[2],s[3]].concat(n).concat([r[0],r[1],t[e-2],t[e-1],r[2],r[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};t=0!==this.tension()?[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.points();let e,i,s=t[0],r=t[0],n=t[1],o=t[1];for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),o=Math.max(o,i);return{x:s,y:n,width:r-s,height:o-n}}}he.prototype.className="Line",he.prototype._attrsAffectingSize=["points","bezier","tension"],r(he),W.addGetterSetter(he,"closed",!1),W.addGetterSetter(he,"bezier",!1),W.addGetterSetter(he,"tension",0,R()),W.addGetterSetter(he,"points",[],function(){if(s.isUnminified)return function(t,e){const i=Int8Array?Object.getPrototypeOf(Int8Array):null;return i&&t instanceof i||(_._isArray(t)?t.forEach(function(t){_._isNumber(t)||_.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")}):_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),t}}());const le=[[],[],[-.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]],de=[[],[],[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]],ce=[[1],[1,1],[1,2,1],[1,3,3,1]],ge=(t,e,i)=>{let s,r;const n=i/2;s=0;for(let i=0;i<20;i++)r=n*le[20][i]+n,s+=de[20][i]*ue(t,e,r);return n*s},fe=(t,e,i)=>{void 0===i&&(i=1);const s=t[0]-2*t[1]+t[2],r=e[0]-2*e[1]+e[2],n=2*t[1]-2*t[0],o=2*e[1]-2*e[0],a=4*(s*s+r*r),h=4*(s*n+r*o),l=n*n+o*o;if(0===a)return i*Math.sqrt(Math.pow(t[2]-t[0],2)+Math.pow(e[2]-e[0],2));const d=h/(2*a),c=i+d,g=l/a-d*d,f=c*c+g>0?Math.sqrt(c*c+g):0,u=d*d+g>0?Math.sqrt(d*d+g):0,p=d+Math.sqrt(d*d+g)!==0?g*Math.log(Math.abs((c+f)/(d+u))):0;return Math.sqrt(a)/2*(c*f-d*u+p)};function ue(t,e,i){const s=pe(1,i,t),r=pe(1,i,e),n=s*s+r*r;return Math.sqrt(n)}const pe=(t,e,i)=>{const s=i.length-1;let r,n;if(0===s)return 0;if(0===t){n=0;for(let t=0;t<=s;t++)n+=ce[s][t]*Math.pow(1-e,s-t)*Math.pow(e,t)*i[t];return n}r=new Array(s);for(let t=0;t<s;t++)r[t]=s*(i[t+1]-i[t]);return pe(t-1,e,r)},_e=(t,e,i)=>{let s=1,r=t/e,n=(t-i(r))/e,o=0;for(;s>.001;){const a=i(r+n),h=Math.abs(t-a)/e;if(h<s)s=h,r+=n;else{const o=i(r-n),a=Math.abs(t-o)/e;a<s?(s=a,r-=n):n/=2}if(o++,o>500)break}return r};class me extends Yt{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=me.parsePathData(this.data()),this.pathLength=me.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const r=e[s].command,n=e[s].points;switch(r){case"L":t.lineTo(n[0],n[1]);break;case"M":t.moveTo(n[0],n[1]);break;case"C":t.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]);break;case"Q":t.quadraticCurveTo(n[0],n[1],n[2],n[3]);break;case"A":const e=n[0],s=n[1],r=n[2],o=n[3],a=n[4],h=n[5],l=n[6],d=n[7],c=r>o?r:o,g=r>o?1:r/o,f=r>o?o/r:1;t.translate(e,s),t.rotate(l),t.scale(g,f),t.arc(0,0,c,a,a+h,1-d),t.scale(1/g,1/f),t.rotate(-l),t.translate(-e,-s);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(e){if("A"===e.command){const i=e.points[4],s=e.points[5],r=e.points[4]+s;let n=Math.PI/180;if(Math.abs(i-r)<n&&(n=Math.abs(i-r)),s<0)for(let s=i-n;s>r;s-=n){const i=me.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}else for(let s=i+n;s<r;s+=n){const i=me.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}}else if("C"===e.command)for(let i=0;i<=1;i+=.01){const s=me.getPointOnCubicBezier(i,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);t.push(s.x,s.y)}else t=t.concat(e.points)});let e,i,s=t[0],r=t[0],n=t[1],o=t[1];for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],isNaN(e)||(s=Math.min(s,e),r=Math.max(r,e)),isNaN(i)||(n=Math.min(n,i),o=Math.max(o,i));return{x:s,y:n,width:r-s,height:o-n}}getLength(){return this.pathLength}getPointAtLength(t){return me.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,r=e.length;if(!r)return null;for(;s<r&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===r)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01){return"M"===e[s].command?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y}}const n=e[s],o=n.points;switch(n.command){case"L":return me.getPointOnLine(t,n.start.x,n.start.y,o[0],o[1]);case"C":return me.getPointOnCubicBezier(_e(t,me.getPathLength(e),t=>ge([n.start.x,o[0],o[2],o[4]],[n.start.y,o[1],o[3],o[5]],t)),n.start.x,n.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return me.getPointOnQuadraticBezier(_e(t,me.getPathLength(e),t=>fe([n.start.x,o[0],o[2]],[n.start.y,o[1],o[3]],t)),n.start.x,n.start.y,o[0],o[1],o[2],o[3]);case"A":const i=o[0],s=o[1],r=o[2],a=o[3],h=o[5],l=o[6];let d=o[4];return d+=h*t/n.pathLength,me.getPointOnEllipticalArc(i,s,r,a,d,l)}return null}static getPointOnLine(t,e,i,s,r,n,o){n=null!=n?n:e,o=null!=o?o:i;const a=this.getLineLength(e,i,s,r);if(a<1e-10)return{x:e,y:i};if(s===e)return{x:n,y:o+(r>i?t:-t)};const h=(r-i)/(s-e),l=Math.sqrt(t*t/(1+h*h))*(s<e?-1:1),d=h*l;if(Math.abs(o-i-h*(n-e))<1e-10)return{x:n+l,y:o+d};const c=((n-e)*(s-e)+(o-i)*(r-i))/(a*a),g=e+c*(s-e),f=i+c*(r-i),u=this.getLineLength(n,o,g,f),p=Math.sqrt(t*t-u*u),_=Math.sqrt(p*p/(1+h*h))*(s<e?-1:1);return{x:g+_,y:f+h*_}}static getPointOnCubicBezier(t,e,i,s,r,n,o,a,h){function l(t){return t*t*t}function d(t){return 3*t*t*(1-t)}function c(t){return 3*t*(1-t)*(1-t)}function g(t){return(1-t)*(1-t)*(1-t)}return{x:a*l(t)+n*d(t)+s*c(t)+e*g(t),y:h*l(t)+o*d(t)+r*c(t)+i*g(t)}}static getPointOnQuadraticBezier(t,e,i,s,r,n,o){function a(t){return t*t}function h(t){return 2*t*(1-t)}function l(t){return(1-t)*(1-t)}return{x:n*a(t)+s*h(t)+e*l(t),y:o*a(t)+r*h(t)+i*l(t)}}static getPointOnEllipticalArc(t,e,i,s,r,n){const o=Math.cos(n),a=Math.sin(n),h=i*Math.cos(r),l=s*Math.sin(r);return{x:t+(h*o-l*a),y:e+(h*a+l*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 t=0;t<i.length;t++)e=e.replace(new RegExp(i[t],"g"),"|"+i[t]);const s=e.split("|"),r=[],n=[];let o=0,a=0;const h=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let l;for(let t=1;t<s.length;t++){let e=s[t],i=e.charAt(0);for(e=e.slice(1),n.length=0;l=h.exec(e);)n.push(l[0]);let d=[],c="A"===i||"a"===i?0:-1;for(let t=0,e=n.length;t<e;t++){const e=n[t];if("00"!==e)if(c>=0){if(3===c){if(/^[01]{2}\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),d.push(parseFloat(e.slice(2))),c+=3,c>=7&&(c-=7);continue}if("11"===e||"10"===e||"01"===e){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}else if(4===c){if(/^[01]\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseFloat(e.slice(1))),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t),c+=1,c>=7&&(c-=7)}else{const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t)}else d.push(0,0),c>=0&&(c+=2,c>=7&&(c-=7))}for(;d.length>0&&!isNaN(d[0]);){let t="",e=[];const s=o,n=a;let h,l,c,g,f,u,p,_,m,y;switch(i){case"l":o+=d.shift(),a+=d.shift(),t="L",e.push(o,a);break;case"L":o=d.shift(),a=d.shift(),e.push(o,a);break;case"m":const s=d.shift(),n=d.shift();if(o+=s,a+=n,t="M",r.length>2&&"z"===r[r.length-1].command)for(let t=r.length-2;t>=0;t--)if("M"===r[t].command){o=r[t].points[0]+s,a=r[t].points[1]+n;break}e.push(o,a),i="l";break;case"M":o=d.shift(),a=d.shift(),t="M",e.push(o,a),i="L";break;case"h":o+=d.shift(),t="L",e.push(o,a);break;case"H":o=d.shift(),t="L",e.push(o,a);break;case"v":a+=d.shift(),t="L",e.push(o,a);break;case"V":a=d.shift(),t="L",e.push(o,a);break;case"C":e.push(d.shift(),d.shift(),d.shift(),d.shift()),o=d.shift(),a=d.shift(),e.push(o,a);break;case"c":e.push(o+d.shift(),a+d.shift(),o+d.shift(),a+d.shift()),o+=d.shift(),a+=d.shift(),t="C",e.push(o,a);break;case"S":l=o,c=a,h=r[r.length-1],"C"===h.command&&(l=o+(o-h.points[2]),c=a+(a-h.points[3])),e.push(l,c,d.shift(),d.shift()),o=d.shift(),a=d.shift(),t="C",e.push(o,a);break;case"s":l=o,c=a,h=r[r.length-1],"C"===h.command&&(l=o+(o-h.points[2]),c=a+(a-h.points[3])),e.push(l,c,o+d.shift(),a+d.shift()),o+=d.shift(),a+=d.shift(),t="C",e.push(o,a);break;case"Q":e.push(d.shift(),d.shift()),o=d.shift(),a=d.shift(),e.push(o,a);break;case"q":e.push(o+d.shift(),a+d.shift()),o+=d.shift(),a+=d.shift(),t="Q",e.push(o,a);break;case"T":l=o,c=a,h=r[r.length-1],"Q"===h.command&&(l=o+(o-h.points[0]),c=a+(a-h.points[1])),o=d.shift(),a=d.shift(),t="Q",e.push(l,c,o,a);break;case"t":l=o,c=a,h=r[r.length-1],"Q"===h.command&&(l=o+(o-h.points[0]),c=a+(a-h.points[1])),o+=d.shift(),a+=d.shift(),t="Q",e.push(l,c,o,a);break;case"A":g=d.shift(),f=d.shift(),u=d.shift(),p=d.shift(),_=d.shift(),m=o,y=a,o=d.shift(),a=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(m,y,o,a,p,_,g,f,u);break;case"a":g=d.shift(),f=d.shift(),u=d.shift(),p=d.shift(),_=d.shift(),m=o,y=a,o+=d.shift(),a+=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(m,y,o,a,p,_,g,f,u)}r.push({command:t||i,points:e,start:{x:s,y:n},pathLength:this.calcLength(s,n,t||i,e)})}"z"!==i&&"Z"!==i||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r}static calcLength(t,e,i,s){let r,n,o,a;const h=me;switch(i){case"L":return h.getLineLength(t,e,s[0],s[1]);case"C":return ge([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return fe([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":r=0;const i=s[4],l=s[5],d=s[4]+l;let c=Math.PI/180;if(Math.abs(i-d)<c&&(c=Math.abs(i-d)),n=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],i,0),l<0)for(a=i-c;a>d;a-=c)o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],a,0),r+=h.getLineLength(n.x,n.y,o.x,o.y),n=o;else for(a=i+c;a<d;a+=c)o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],a,0),r+=h.getLineLength(n.x,n.y,o.x,o.y),n=o;return o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),r+=h.getLineLength(n.x,n.y,o.x,o.y),r}return 0}static convertEndpointToCenterParameterization(t,e,i,s,r,n,o,a,h){const l=h*(Math.PI/180),d=Math.cos(l)*(t-i)/2+Math.sin(l)*(e-s)/2,c=-1*Math.sin(l)*(t-i)/2+Math.cos(l)*(e-s)/2,g=d*d/(o*o)+c*c/(a*a);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));let f=Math.sqrt((o*o*(a*a)-o*o*(c*c)-a*a*(d*d))/(o*o*(c*c)+a*a*(d*d)));r===n&&(f*=-1),isNaN(f)&&(f=0);const u=f*o*c/a,p=f*-a*d/o,_=(t+i)/2+Math.cos(l)*u-Math.sin(l)*p,m=(e+s)/2+Math.sin(l)*u+Math.cos(l)*p,y=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},x=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(y(t)*y(e))},v=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(x(t,e))},w=v([1,0],[(d-u)/o,(c-p)/a]),S=[(d-u)/o,(c-p)/a],b=[(-1*d-u)/o,(-1*c-p)/a];let C=v(S,b);return x(S,b)<=-1&&(C=Math.PI),x(S,b)>=1&&(C=0),0===n&&C>0&&(C-=2*Math.PI),1===n&&C<0&&(C+=2*Math.PI),[_,m,o,a,w,C,l,n]}}me.prototype.className="Path",me.prototype._attrsAffectingSize=["data"],r(me),W.addGetterSetter(me,"data");class ye extends he{_sceneFunc(t){super._sceneFunc(t);const e=2*Math.PI,i=this.points();let s=i;const r=0!==this.tension()&&i.length>4;r&&(s=this.getTensionPoints());const n=this.pointerLength(),o=i.length;let a,h;if(r){const t=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[o-2],i[o-1]],e=me.calcLength(s[s.length-4],s[s.length-3],"C",t),r=me.getPointOnQuadraticBezier(Math.min(1,1-n/e),t[0],t[1],t[2],t[3],t[4],t[5]);a=i[o-2]-r.x,h=i[o-1]-r.y}else a=i[o-2]-i[o-4],h=i[o-1]-i[o-3];const l=(Math.atan2(h,a)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[o-2],i[o-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),r?(a=(s[0]+s[2])/2-i[0],h=(s[1]+s[3])/2-i[1]):(a=i[2]-i[0],h=i[3]-i[1]),t.rotate((Math.atan2(-h,-a)+e)%e),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/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+2*e}}}ye.prototype.className="Arrow",r(ye),W.addGetterSetter(ye,"pointerLength",10,R()),W.addGetterSetter(ye,"pointerWidth",10,R()),W.addGetterSetter(ye,"pointerAtBeginning",!1),W.addGetterSetter(ye,"pointerAtEnding",!0);class xe extends Yt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,2*Math.PI,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}xe.prototype._centroid=!0,xe.prototype.className="Circle",xe.prototype._attrsAffectingSize=["radius"],r(xe),W.addGetterSetter(xe,"radius",0,R());class ve extends Yt{_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,2*Math.PI,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radiusX()}getHeight(){return 2*this.radiusY()}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}ve.prototype.className="Ellipse",ve.prototype._centroid=!0,ve.prototype._attrsAffectingSize=["radiusX","radiusY"],r(ve),W.addComponentsGetterSetter(ve,"radius",["x","y"]),W.addGetterSetter(ve,"radiusX",0,R()),W.addGetterSetter(ve,"radiusY",0,R());let we=class t extends Yt{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",t=>{this._removeImageLoad(t.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||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)||super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),r=this.attrs.image;let n;if(r){const t=this.attrs.cropWidth,s=this.attrs.cropHeight;n=t&&s?[r,this.cropX(),this.cropY(),t,s,0,0,e,i]:[r,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)),r&&(s&&t.clip(),t.drawImage.apply(t,n))}_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 null!==(i=null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width)&&void 0!==i?i:0}getHeight(){var t,e,i;return null!==(i=null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height)&&void 0!==i?i:0}static fromURL(e,i,s=null){const r=_.createImageElement();r.onload=function(){const e=new t({image:r});i(e)},r.onerror=s,r.crossOrigin="Anonymous",r.src=e}};we.prototype.className="Image",we.prototype._attrsAffectingSize=["image"],r(we),W.addGetterSetter(we,"cornerRadius",0,I(4)),W.addGetterSetter(we,"image"),W.addComponentsGetterSetter(we,"crop",["x","y","width","height"]),W.addGetterSetter(we,"cropX",0,R()),W.addGetterSetter(we,"cropY",0,R()),W.addGetterSetter(we,"cropWidth",0,R()),W.addGetterSetter(we,"cropHeight",0,R());const Se=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],be="up",Ce="right",Te="down",Ae="left",ke=Se.length;class Pe extends Vt{constructor(t){super(t),this.on("add.konva",function(t){this._addListeners(t.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){let e,i=this;const s=function(){i._sync()};for(e=0;e<ke;e++)t.on(Se[e]+"Change.konva",s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t,e,i,s,r,n,o,a=this.getText(),h=this.getTag();if(a&&h){switch(t=a.width(),e=a.height(),i=h.pointerDirection(),s=h.pointerWidth(),o=h.pointerHeight(),r=0,n=0,i){case be:r=t/2,n=-1*o;break;case Ce:r=t+s,n=e/2;break;case Te:r=t/2,n=e+o;break;case Ae:r=-1*s,n=e/2}h.setAttrs({x:-1*r,y:-1*n,width:t,height:e}),a.setAttrs({x:-1*r,y:-1*n})}}}Pe.prototype.className="Label",r(Pe);class Me extends Yt{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),r=this.pointerWidth(),n=this.pointerHeight(),o=this.cornerRadius();let a=0,h=0,l=0,d=0;"number"==typeof o?a=h=l=d=Math.min(o,e/2,i/2):(a=Math.min(o[0]||0,e/2,i/2),h=Math.min(o[1]||0,e/2,i/2),d=Math.min(o[2]||0,e/2,i/2),l=Math.min(o[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(a,0),s===be&&(t.lineTo((e-r)/2,0),t.lineTo(e/2,-1*n),t.lineTo((e+r)/2,0)),t.lineTo(e-h,0),t.arc(e-h,h,h,3*Math.PI/2,0,!1),s===Ce&&(t.lineTo(e,(i-n)/2),t.lineTo(e+r,i/2),t.lineTo(e,(i+n)/2)),t.lineTo(e,i-d),t.arc(e-d,i-d,d,0,Math.PI/2,!1),s===Te&&(t.lineTo((e+r)/2,i),t.lineTo(e/2,i+n),t.lineTo((e-r)/2,i)),t.lineTo(l,i),t.arc(l,i-l,l,Math.PI/2,Math.PI,!1),s===Ae&&(t.lineTo(0,(i+n)/2),t.lineTo(-1*r,i/2),t.lineTo(0,(i-n)/2)),t.lineTo(0,a),t.arc(a,a,a,Math.PI,3*Math.PI/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),r=this.pointerDirection(),n=this.width(),o=this.height();return r===be?(e-=s,o+=s):r===Te?o+=s:r===Ae?(t-=1.5*i,n+=i):r===Ce&&(n+=1.5*i),{x:t,y:e,width:n,height:o}}}Me.prototype.className="Tag",r(Me),W.addGetterSetter(Me,"pointerDirection","none"),W.addGetterSetter(Me,"pointerWidth",0,R()),W.addGetterSetter(Me,"pointerHeight",0,R()),W.addGetterSetter(Me,"cornerRadius",0,I(4));class Re extends Yt{_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)}}Re.prototype.className="Rect",r(Re),W.addGetterSetter(Re,"cornerRadius",0,I(4));class Ie extends Yt{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),r=this.cornerRadius();if(t.beginPath(),r)_.drawRoundedPolygonPath(t,e,s,i,r);else{t.moveTo(e[0].x,e[0].y);for(let i=1;i<e.length;i++)t.lineTo(e[i].x,e[i].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(2*s*Math.PI/t),y:-1*e*Math.cos(2*s*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].x,s=t[0].y,r=t[0].y;return t.forEach(t=>{e=Math.min(e,t.x),i=Math.max(i,t.x),s=Math.min(s,t.y),r=Math.max(r,t.y)}),{x:e,y:s,width:i-e,height:r-s}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}Ie.prototype.className="RegularPolygon",Ie.prototype._centroid=!0,Ie.prototype._attrsAffectingSize=["radius"],r(Ie),W.addGetterSetter(Ie,"radius",0,R()),W.addGetterSetter(Ie,"sides",0,R()),W.addGetterSetter(Ie,"cornerRadius",0,I(4));const Ee=2*Math.PI;class Le extends Yt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,Ee,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),Ee,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}Le.prototype.className="Ring",Le.prototype._centroid=!0,Le.prototype._attrsAffectingSize=["innerRadius","outerRadius"],r(Le),W.addGetterSetter(Le,"innerRadius",0,R()),W.addGetterSetter(Le,"outerRadius",0,R());class Ge extends Yt{constructor(t){super(t),this._updated=!0,this.anim=new Jt(()=>{const t=this._updated;return this._updated=!1,t}),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=4*i,r=this.animations()[e],n=this.frameOffsets(),o=r[s+0],a=r[s+1],h=r[s+2],l=r[s+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(n){const s=n[e],r=2*i;t.drawImage(d,o,a,h,l,s[r+0],s[r+1],h,l)}else t.drawImage(d,o,a,h,l,0,0,h,l)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,r=this.animations()[e],n=this.frameOffsets(),o=r[s+2],a=r[s+3];if(t.beginPath(),n){const s=n[e],r=2*i;t.rect(s[r+0],s[r+1],o,a)}else t.rect(0,0,o,a);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();t<this.animations()[e].length/4-1?this.frameIndex(t+1):this.frameIndex(0)}}Ge.prototype.className="Sprite",r(Ge),W.addGetterSetter(Ge,"animation"),W.addGetterSetter(Ge,"animations"),W.addGetterSetter(Ge,"frameOffsets"),W.addGetterSetter(Ge,"image"),W.addGetterSetter(Ge,"frameIndex",0,R()),W.addGetterSetter(Ge,"frameRate",17,R()),W.backCompat(Ge,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class Oe extends Yt{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let r=1;r<2*s;r++){const n=r%2==0?i:e,o=n*Math.sin(r*Math.PI/s),a=-1*n*Math.cos(r*Math.PI/s);t.lineTo(o,a)}t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}function De(t){return[...t].reduce((t,e,i,s)=>{if(/\p{Emoji}/u.test(e)){const r=s[i+1];r&&/\p{Emoji_Modifier}|\u200D/u.test(r)?(t.push(e+r),s[i+1]=""):t.push(e)}else/\p{Regional_Indicator}{2}/u.test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}Oe.prototype.className="Star",Oe.prototype._centroid=!0,Oe.prototype._attrsAffectingSize=["innerRadius","outerRadius"],r(Oe),W.addGetterSetter(Oe,"numPoints",5,R()),W.addGetterSetter(Oe,"innerRadius",0,R()),W.addGetterSetter(Oe,"outerRadius",0,R());const Fe="auto",We="inherit",Be="justify",Ne="left",ze="middle",He="normal",Xe=" ",Ye="none",je=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],Ue=je.length;let qe;function Ke(){return qe||(qe=_.createCanvasElement().getContext("2d"),qe)}class Ve extends Yt{constructor(t){super(function(t){return(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||t.fillPatternImage||(t.fill=t.fill||"black"),t}(t)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<Ue;t++)this.on(je[t]+"Change.konva",this._setTextData);this._setTextData()}_sceneFunc(t){var e,i;const r=this.textArr,n=r.length;if(!this.text())return;let o,a=this.padding(),h=this.fontSize(),l=this.lineHeight()*h,d=this.verticalAlign(),c=this.direction(),g=0,f=this.align(),u=this.getWidth(),p=this.letterSpacing(),_=this.charRenderFunc(),m=this.fill(),y=this.textDecoration(),x=-1!==y.indexOf("underline"),v=-1!==y.indexOf("line-through");c=c===We?t.direction:c;let w=l/2,S=ze;if(!s.legacyTextRendering){const t=this.measureSize("M");S="alphabetic";w=((null!==(e=t.fontBoundingBoxAscent)&&void 0!==e?e:t.actualBoundingBoxAscent)-(null!==(i=t.fontBoundingBoxDescent)&&void 0!==i?i:t.actualBoundingBoxDescent))/2+l/2}for("rtl"===c&&t.setAttr("direction",c),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",S),t.setAttr("textAlign",Ne),d===ze?g=(this.getHeight()-n*l-2*a)/2:"bottom"===d&&(g=this.getHeight()-n*l-2*a),t.translate(a,g+a),o=0;o<n;o++){let e=0,i=0;const d=r[o],g=d.text,y=d.width,S=d.lastInParagraph;if(t.save(),"right"===f?e+=u-y-2*a:"center"===f&&(e+=(u-y-2*a)/2),x){t.save(),t.beginPath();const r=e,n=w+i+(s.legacyTextRendering?Math.round(h/2):Math.round(h/4));t.moveTo(r,n);const o=f!==Be||S?y:u-2*a;t.lineTo(r+Math.round(o),n),t.lineWidth=h/15;const l=this._getLinearGradient();t.strokeStyle=l||m,t.stroke(),t.restore()}const b=e;if("rtl"===c||0===p&&f!==Be&&!_)0!==p&&t.setAttr("letterSpacing",`${p}px`),this._partialTextX=e,this._partialTextY=w+i,this._partialText=g,t.fillStrokeShape(this);else{const s=g.split(" ").length-1,n=De(g);for(let h=0;h<n.length;h++){const l=n[h];if(" "!==l||S||f!==Be||(e+=(u-2*a-y)/s),this._partialTextX=e,this._partialTextY=w+i,this._partialText=l,_){t.save();_({char:l,index:h+r.slice(0,o).reduce((t,e)=>t+De(e.text).length,0),x:e,y:w+i,lineIndex:o,column:h,isLastInLine:S,width:this.measureSize(l).width,context:t})}t.fillStrokeShape(this),_&&t.restore(),e+=this.measureSize(l).width+p}}if(v){t.save(),t.beginPath();const e=s.legacyTextRendering?0:-Math.round(h/4),r=b;t.moveTo(r,w+i+e);const n=f!==Be||S?y:u-2*a;t.lineTo(r+Math.round(n),w+i+e),t.lineWidth=h/15;const o=this._getLinearGradient();t.strokeStyle=o||m,t.stroke(),t.restore()}t.restore(),n>1&&(w+=l)}}_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:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===Fe||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===Fe||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():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,r,n,o,a,h,l,d,c;let g,f=Ke(),u=this.fontSize();f.save(),f.font=this._getContextFont(),g=f.measureText(t),f.restore();const p=u/100;return{actualBoundingBoxAscent:null!==(e=g.actualBoundingBoxAscent)&&void 0!==e?e:71.58203125*p,actualBoundingBoxDescent:null!==(i=g.actualBoundingBoxDescent)&&void 0!==i?i:0,actualBoundingBoxLeft:null!==(s=g.actualBoundingBoxLeft)&&void 0!==s?s:-7.421875*p,actualBoundingBoxRight:null!==(r=g.actualBoundingBoxRight)&&void 0!==r?r:75.732421875*p,alphabeticBaseline:null!==(n=g.alphabeticBaseline)&&void 0!==n?n:0,emHeightAscent:null!==(o=g.emHeightAscent)&&void 0!==o?o:100*p,emHeightDescent:null!==(a=g.emHeightDescent)&&void 0!==a?a:-20*p,fontBoundingBoxAscent:null!==(h=g.fontBoundingBoxAscent)&&void 0!==h?h:91*p,fontBoundingBoxDescent:null!==(l=g.fontBoundingBoxDescent)&&void 0!==l?l:21*p,hangingBaseline:null!==(d=g.hangingBaseline)&&void 0!==d?d:72.80000305175781*p,ideographicBaseline:null!==(c=g.ideographicBaseline)&&void 0!==c?c:-21*p,width:g.width,height:u}}_getContextFont(){return this.fontStyle()+Xe+this.fontVariant()+Xe+(this.fontSize()+"px ")+this.fontFamily().split(",").map(t=>{const e=(t=t.trim()).indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t}).join(", ")}_addTextLine(t){this.align()===Be&&(t=t.trim());const e=this._getTextWidth(t);return this.textArr.push({text:t,width:e,lastInParagraph:!1})}_getTextWidth(t){const e=this.letterSpacing(),i=t.length;return Ke().measureText(t).width+e*i}_setTextData(){let t=this.text().split("\n"),e=+this.fontSize(),i=0,s=this.lineHeight()*e,r=this.attrs.width,n=this.attrs.height,o=r!==Fe&&void 0!==r,a=n!==Fe&&void 0!==n,h=this.padding(),l=r-2*h,d=n-2*h,c=0,g=this.wrap(),f="char"!==g&&g!==Ye,u=this.ellipsis();this.textArr=[],Ke().font=this._getContextFont();const p=u?this._getTextWidth("…"):0;for(let e=0,r=t.length;e<r;++e){let n=t[e],h=this._getTextWidth(n);if(o&&h>l)for(;n.length>0;){let t=0,e=De(n).length,r="",o=0;for(;t<e;){const i=t+e>>>1,h=De(n).slice(0,i+1).join(""),g=this._getTextWidth(h);(u&&a&&c+s>d?g+p:g)<=l?(t=i+1,r=h,o=g):e=i}if(!r)break;if(f){const e=De(n),i=De(r),s=e[i.length];let a;if((s===Xe||"-"===s)&&o<=l)a=i.length;else{const t=i.lastIndexOf(Xe),e=i.lastIndexOf("-");a=Math.max(t,e)+1}a>0&&(t=a,r=e.slice(0,t).join(""),o=this._getTextWidth(r))}r=r.trimRight(),this._addTextLine(r),i=Math.max(i,o),c+=s;if(this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if(n=De(n).slice(t).join("").trimLeft(),n.length>0&&(h=this._getTextWidth(n),h<=l)){this._addTextLine(n),c+=s,i=Math.max(i,h);break}}else this._addTextLine(n),c+=s,i=Math.max(i,h),this._shouldHandleEllipsis(c)&&e<r-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),a&&c+s>d)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,r=s!==Fe&&void 0!==s,n=s-2*this.padding();return!(this.wrap()!==Ye)||r&&t+i>n}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==Fe&&void 0!==t,i=t-2*this.padding(),s=this.ellipsis(),r=this.textArr[this.textArr.length-1];if(r&&s){if(e){this._getTextWidth(r.text+"…")<i||(r.text=r.text.slice(0,r.text.length-3))}this.textArr.splice(this.textArr.length-1,1),this._addTextLine(r.text+"…")}}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=-1!==this.textDecoration().indexOf("underline")||-1!==this.textDecoration().indexOf("line-through"),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas()}}Ve.prototype._fillFunc=function(t){t.fillText(this._partialText,this._partialTextX,this._partialTextY)},Ve.prototype._strokeFunc=function(t){t.setAttr("miterLimit",2),t.strokeText(this._partialText,this._partialTextX,this._partialTextY)},Ve.prototype.className="Text",Ve.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],r(Ve),W.overWriteSetter(Ve,"width",E()),W.overWriteSetter(Ve,"height",E()),W.addGetterSetter(Ve,"direction",We),W.addGetterSetter(Ve,"fontFamily","Arial"),W.addGetterSetter(Ve,"fontSize",12,R()),W.addGetterSetter(Ve,"fontStyle",He),W.addGetterSetter(Ve,"fontVariant",He),W.addGetterSetter(Ve,"padding",0,R()),W.addGetterSetter(Ve,"align",Ne),W.addGetterSetter(Ve,"verticalAlign","top"),W.addGetterSetter(Ve,"lineHeight",1,R()),W.addGetterSetter(Ve,"wrap","word"),W.addGetterSetter(Ve,"ellipsis",!1,O()),W.addGetterSetter(Ve,"letterSpacing",0,R()),W.addGetterSetter(Ve,"text","",L()),W.addGetterSetter(Ve,"textDecoration",""),W.addGetterSetter(Ve,"charRenderFunc",void 0);const Qe="normal";function Je(t){t.fillText(this.partialText,0,0)}function Ze(t){t.strokeText(this.partialText,0,0)}class $e extends Yt{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 me.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;return t>this.pathLength?null:me.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=me.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(),r=this.glyphInfo,n=-1!==e.indexOf("underline"),o=-1!==e.indexOf("line-through");n&&t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),this.partialText=r[e].text,t.fillStrokeShape(this),n&&(0===e&&t.moveTo(0,s/2+1),t.lineTo(r[e].width,s/2+1)),t.restore()}if(n&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),o){t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),0===e&&t.moveTo(0,0),t.lineTo(r[e].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 Ve.prototype.setText.call(this,t)}_getContextFont(){return Ve.prototype._getContextFont.call(this)}_getTextSize(t){const e=this.dummyCanvas.getContext("2d");e.save(),e.font=this._getContextFont();const i=e.measureText(t);return e.restore(),{width:i.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const t=De(this.text()),e=[];let i=0;for(let s=0;s<t.length;s++)e.push({char:t[s],width:this._getTextSize(t[s]).width}),i+=e[s].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const r=this.letterSpacing(),n=this.align(),o=this.kerningFunc(),a=Math.max(this.textWidth+((this.attrs.text||"").length-1)*r,0);let h=0;"center"===n&&(h=Math.max(0,this.pathLength/2-a/2)),"right"===n&&(h=Math.max(0,this.pathLength-a));let l=h;for(let i=0;i<e.length;i++){const s=this._getPointAtLength(l);if(!s)return;const h=e[i].char;let d=e[i].width+r;if(" "===h&&"justify"===n){const t=this.text().split(" ").length-1;d+=(this.pathLength-a)/t}const c=this._getPointAtLength(l+d);if(!c)return;const g=me.getLineLength(s.x,s.y,c.x,c.y);let f=0;if(o)try{f=o(e[i-1].char,h)*this.fontSize()}catch(t){f=0}s.x+=f,c.x+=f,this.textWidth+=f;const u=me.getPointOnLine(f+g/2,s.x,s.y,c.x,c.y),p=Math.atan2(c.y-s.y,c.x-s.x);this.glyphInfo.push({transposeX:u.x,transposeY:u.y,text:t[i],rotation:p,p0:s,p1:c,width:g}),l+=d}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(e){t.push(e.p0.x),t.push(e.p0.y),t.push(e.p1.x),t.push(e.p1.y)});let e,i,s=t[0]||0,r=t[0]||0,n=t[1]||0,o=t[1]||0;for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),o=Math.max(o,i);const a=this.fontSize();return{x:s-a/2,y:n-a/2,width:r-s+a,height:o-n+a}}destroy(){return _.releaseCanvas(this.dummyCanvas),super.destroy()}}$e.prototype._fillFunc=Je,$e.prototype._strokeFunc=Ze,$e.prototype._fillFuncHit=Je,$e.prototype._strokeFuncHit=Ze,$e.prototype.className="TextPath",$e.prototype._attrsAffectingSize=["text","fontSize","data"],r($e),W.addGetterSetter($e,"data"),W.addGetterSetter($e,"fontFamily","Arial"),W.addGetterSetter($e,"fontSize",12,R()),W.addGetterSetter($e,"fontStyle",Qe),W.addGetterSetter($e,"align","left"),W.addGetterSetter($e,"letterSpacing",0,R()),W.addGetterSetter($e,"textBaseline","middle"),W.addGetterSetter($e,"fontVariant",Qe),W.addGetterSetter($e,"text",""),W.addGetterSetter($e,"textDecoration",""),W.addGetterSetter($e,"kerningFunc",void 0);const ti="tr-konva",ei=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(t=>t+`.${ti}`).join(" "),ii="nodesRect",si=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],ri={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},ni="ontouchstart"in s._global;const oi=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function ai(t,e,i){const s=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),r=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return{...t,rotation:t.rotation+e,x:s,y:r}}function hi(t,e){const i=function(t){return{x:t.x+t.width/2*Math.cos(t.rotation)+t.height/2*Math.sin(-t.rotation),y:t.y+t.height/2*Math.cos(t.rotation)+t.width/2*Math.sin(t.rotation)}}(t);return ai(t,e,i)}let li=0;class di extends Vt{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(ei,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 ti+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(t=>!t.isAncestorOf(this)||(_.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1));this._nodes=t=e,1===t.length&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(t=>{const e=()=>{1===this.nodes().length&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),this._transforming||this.isDragging()||this.update()};if(t._attrsAffectingSize.length){const i=t._attrsAffectingSize.map(t=>t+"Change."+this._getEventNamespace()).join(" ");t.on(i,e)}t.on(si.map(t=>t+`.${this._getEventNamespace()}`).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)}),this._resetTransformCache();return!!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(),r=s.x-e.x,n=s.y-e.y;this.nodes().forEach(e=>{if(e===t)return;if(e.isDragging())return;const s=e.getAbsolutePosition();e.setAbsolutePosition({x:s.x+r,y:s.y+n}),e.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(ii),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(ii,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),i){const r=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),n=t.getAbsoluteScale(i),o=t.getAbsolutePosition(i),a=r.x*n.x-t.offsetX()*n.x,h=r.y*n.y-t.offsetY()*n.y,l=(s.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return ai({x:o.x+a*Math.cos(l)+h*Math.sin(-l),y:o.y+h*Math.cos(l)+a*Math.sin(l),width:r.width*n.x,height:r.height*n.y,rotation:l},-s.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map(e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),s=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],r=e.getAbsoluteTransform();s.forEach(function(e){const i=r.point(e);t.push(i)})});const e=new o;e.rotate(-s.getAngle(this.rotation()));let i=1/0,r=1/0,n=-1/0,a=-1/0;t.forEach(function(t){const s=e.point(t);void 0===i&&(i=n=s.x,r=a=s.y),i=Math.min(i,s.x),r=Math.min(r,s.y),n=Math.max(n,s.x),a=Math.max(a,s.y)}),e.invert();const h=e.point({x:i,y:r});return{x:h.x,y:h.y,width:n-i,height:a-r,rotation:s.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(),oi.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new Re({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:ni?10:"auto"}),i=this;e.on("mousedown touchstart",function(t){i._handleMouseDown(t)}),e.on("dragstart",t=>{e.stopDrag(),t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),e.on("mouseenter",()=>{const i=s.getAngle(this.rotation()),r=this.rotateAnchorCursor(),n=function(t,e,i){if("rotater"===t)return i;e+=_.degToRad(ri[t]||0);const s=(_.radToDeg(e)%360+360)%360;return _._inRange(s,337.5,360)||_._inRange(s,0,22.5)?"ns-resize":_._inRange(s,22.5,67.5)?"nesw-resize":_._inRange(s,67.5,112.5)?"ew-resize":_._inRange(s,112.5,157.5)?"nwse-resize":_._inRange(s,157.5,202.5)?"ns-resize":_._inRange(s,202.5,247.5)?"nesw-resize":_._inRange(s,247.5,292.5)?"ew-resize":_._inRange(s,292.5,337.5)?"nwse-resize":(_.error("Transformer has unknown angle for cursor detection: "+s),"pointer")}(t,i,r);e.getStage().content&&(e.getStage().content.style.cursor=n),this._cursorChange=!0}),e.on("mouseout",()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(e)}_createBack(){const t=new Yt({name:"back",width:0,height:0,sceneFunc(t,e){const i=e.getParent(),s=i.padding();t.beginPath(),t.rect(-s,-s,e.width()+2*s,e.height()+2*s),t.moveTo(e.width()/2,-s),i.rotateEnabled()&&i.rotateLineVisible()&&t.lineTo(e.width()/2,-i.rotateAnchorOffset()*_._sign(e.height())-s),t.fillStrokeShape(e)},hitFunc:(t,e)=>{if(!this.shouldOverdrawWholeArea())return;const i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}});this.add(t),this._proxyDrag(t),t.on("dragstart",t=>{t.cancelBubble=!0}),t.on("dragmove",t=>{t.cancelBubble=!0}),t.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{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,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/r),this.cos=Math.abs(i/r),"undefined"!=typeof window&&(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 n=t.target.getAbsolutePosition(),o=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:o.x-n.x,y:o.y-n.y},li++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(e=>{e._fire("transformstart",{evt:t.evt,target:e})})}_handleMouseMove(t){let e,i,r;const n=this.findOne("."+this._movingAnchorName),o=n.getStage();o.setPointersPositions(t);const a=o.getPointerPosition();let h={x:a.x-this._anchorDragOffset.x,y:a.y-this._anchorDragOffset.y};const l=n.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),n.setAbsolutePosition(h);const d=n.getAbsolutePosition();if(l.x===d.x&&l.y===d.y)return;if("rotater"===this._movingAnchorName){const r=this._getNodeRect();e=n.x()-r.width/2,i=-n.y()+r.height/2;let o=Math.atan2(-i,e)+Math.PI/2;r.height<0&&(o-=Math.PI);const a=s.getAngle(this.rotation())+o,h=s.getAngle(this.rotationSnapTolerance()),l=function(t,e,i){let r=e;for(let n=0;n<t.length;n++){const o=s.getAngle(t[n]),a=Math.abs(o-e)%(2*Math.PI);Math.min(a,2*Math.PI-a)<i&&(r=o)}return r}(this.rotationSnaps(),a,h),d=hi(r,l-r.rotation);return void this._fitNodesInto(d,t)}const c=this.shiftBehavior();let g;g="inverted"===c?this.keepRatio()&&!t.shiftKey:"none"===c?this.keepRatio():this.keepRatio()||t.shiftKey;let f=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};r=Math.sqrt(Math.pow(t.x-n.x(),2)+Math.pow(t.y-n.y(),2));const s=this.findOne(".top-left").x()>t.x?-1:1,o=this.findOne(".top-left").y()>t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,this.findOne(".top-left").x(t.x-e),this.findOne(".top-left").y(t.y-i)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(n.y());else if("top-right"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};r=Math.sqrt(Math.pow(n.x()-t.x,2)+Math.pow(t.y-n.y(),2));const s=this.findOne(".top-right").x()<t.x?-1:1,o=this.findOne(".top-right").y()>t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,this.findOne(".top-right").x(t.x+e),this.findOne(".top-right").y(t.y-i)}var u=n.position();this.findOne(".top-left").y(u.y),this.findOne(".bottom-right").x(u.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(n.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(n.x());else if("bottom-left"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};r=Math.sqrt(Math.pow(t.x-n.x(),2)+Math.pow(n.y()-t.y,2));const s=t.x<n.x()?-1:1,o=n.y()<t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,n.x(t.x-e),n.y(t.y+i)}u=n.position(),this.findOne(".top-left").x(u.x),this.findOne(".bottom-right").y(u.y)}else if("bottom-center"===this._movingAnchorName)this.findOne(".bottom-right").y(n.y());else if("bottom-right"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};r=Math.sqrt(Math.pow(n.x()-t.x,2)+Math.pow(n.y()-t.y,2));const s=this.findOne(".bottom-right").x()<t.x?-1:1,o=this.findOne(".bottom-right").y()<t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,this.findOne(".bottom-right").x(t.x+e),this.findOne(".bottom-right").y(t.y+i)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(f=this.centeredScaling()||t.altKey,f){const t=this.findOne(".top-left"),e=this.findOne(".bottom-right"),i=t.x(),s=t.y(),r=this.getWidth()-e.x(),n=this.getHeight()-e.y();e.move({x:-i,y:-s}),t.move({x:r,y:n})}const p=this.findOne(".top-left").getAbsolutePosition();e=p.x,i=p.y;const _=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),m=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:i,width:_,height:m,rotation:s.getAngle(this.rotation())},t)}_handleMouseUp(t){this._removeEvents(t)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(t){var e;if(this._transforming){this._transforming=!1,"undefined"!=typeof window&&(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();li--,this._fire("transformend",{evt:t,target:i}),null===(e=this.getLayer())||void 0===e||e.batchDraw(),i&&this._nodes.forEach(e=>{var i;e._fire("transformend",{evt:t,target:e}),null===(i=e.getLayer())||void 0===i||i.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const i=this._getNodeRect();if(_._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(_._inRange(t.height,2*-this.padding()-1,1))return void this.update();const r=new o;if(r.rotate(s.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=r.point({x:2*-this.padding(),y:0});t.x+=e.x,t.y+=e.y,t.width+=2*this.padding(),this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const e=r.point({x:2*this.padding(),y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.width+=2*this.padding()}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const e=r.point({x:0,y:2*-this.padding()});t.x+=e.x,t.y+=e.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const e=r.point({x:0,y:2*this.padding()});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(i,t);e?t=e:_.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const n=1e7,a=new o;a.translate(i.x,i.y),a.rotate(i.rotation),a.scale(i.width/n,i.height/n);const h=new o,l=t.width/n,d=t.height/n;!1===this.flipEnabled()?(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(d))):(h.translate(t.x,t.y),h.rotate(t.rotation),h.scale(l,d));const c=h.multiply(a.invert());this._nodes.forEach(t=>{var e;if(!t.getStage())return;const i=t.getParent().getAbsoluteTransform(),s=t.getTransform().copy();s.translate(t.offsetX(),t.offsetY());const r=new o;r.multiply(i.copy().invert()).multiply(c).multiply(i).multiply(s);const n=r.decompose();t.setAttrs(n),null===(e=t.getLayer())||void 0===e||e.batchDraw()}),this.rotation(_._getRotation(t.rotation)),this._nodes.forEach(t=>{this._fire("transform",{evt:e,target:t}),t._fire("transform",{evt:e,target:t})}),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,r=this.enabledAnchors(),n=this.resizeEnabled(),o=this.padding(),a=this.anchorSize(),h=this.find("._anchor");h.forEach(t=>{t.setAttrs({width:a,height:a,offsetX:a/2,offsetY:a/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:a/2+o,offsetY:a/2+o,visible:n&&r.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:a/2+o,visible:n&&r.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:a/2-o,offsetY:a/2+o,visible:n&&r.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:a/2+o,visible:n&&r.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:a/2-o,visible:n&&r.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:a/2+o,offsetY:a/2-o,visible:n&&r.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:a/2-o,visible:n&&r.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:a/2-o,offsetY:a/2-o,visible:n&&r.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*_._sign(s)-o,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(t=>t.draggable()),x:0,y:0});const l=this.anchorStyleFunc();l&&h.forEach(t=>{l(t)}),null===(t=this.getLayer())||void 0===t||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=""),Vt.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return $.prototype.toObject.call(this)}clone(t){return $.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}di.isTransforming=()=>li>0,di.prototype.className="Transformer",r(di),W.addGetterSetter(di,"enabledAnchors",oi,function(t){return t instanceof Array||_.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach(function(t){-1===oi.indexOf(t)&&_.warn("Unknown anchor name: "+t+". Available names are: "+oi.join(", "))}),t||[]}),W.addGetterSetter(di,"flipEnabled",!0,O()),W.addGetterSetter(di,"resizeEnabled",!0),W.addGetterSetter(di,"anchorSize",10,R()),W.addGetterSetter(di,"rotateEnabled",!0),W.addGetterSetter(di,"rotateLineVisible",!0),W.addGetterSetter(di,"rotationSnaps",[]),W.addGetterSetter(di,"rotateAnchorOffset",50,R()),W.addGetterSetter(di,"rotateAnchorCursor","crosshair"),W.addGetterSetter(di,"rotationSnapTolerance",5,R()),W.addGetterSetter(di,"borderEnabled",!0),W.addGetterSetter(di,"anchorStroke","rgb(0, 161, 255)"),W.addGetterSetter(di,"anchorStrokeWidth",1,R()),W.addGetterSetter(di,"anchorFill","white"),W.addGetterSetter(di,"anchorCornerRadius",0,R()),W.addGetterSetter(di,"borderStroke","rgb(0, 161, 255)"),W.addGetterSetter(di,"borderStrokeWidth",1,R()),W.addGetterSetter(di,"borderDash"),W.addGetterSetter(di,"keepRatio",!0),W.addGetterSetter(di,"shiftBehavior","default"),W.addGetterSetter(di,"centeredScaling",!1),W.addGetterSetter(di,"ignoreStroke",!1),W.addGetterSetter(di,"padding",0,R()),W.addGetterSetter(di,"nodes"),W.addGetterSetter(di,"node"),W.addGetterSetter(di,"boundBoxFunc"),W.addGetterSetter(di,"anchorDragBoundFunc"),W.addGetterSetter(di,"anchorStyleFunc"),W.addGetterSetter(di,"shouldOverdrawWholeArea",!1),W.addGetterSetter(di,"useSingleNodeRotation",!0),W.backCompat(di,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class ci extends Yt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,s.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}function gi(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}ci.prototype.className="Wedge",ci.prototype._centroid=!0,ci.prototype._attrsAffectingSize=["radius"],r(ci),W.addGetterSetter(ci,"radius",0,R()),W.addGetterSetter(ci,"angle",0,R()),W.addGetterSetter(ci,"clockwise",!1),W.backCompat(ci,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});const fi=[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],ui=[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];W.addGetterSetter($,"blurRadius",0,R(),W.afterSetFilter);W.addGetterSetter($,"brightness",0,R(),W.afterSetFilter);W.addGetterSetter($,"contrast",0,R(),W.afterSetFilter);function pi(t,e,i,s,r){const n=i-e,o=r-s;if(0===n)return s+o/2;if(0===o)return s;let a=(t-e)/n;return a=o*a+s,a}W.addGetterSetter($,"embossStrength",.5,R(),W.afterSetFilter),W.addGetterSetter($,"embossWhiteLevel",.5,R(),W.afterSetFilter),W.addGetterSetter($,"embossDirection","top-left",void 0,W.afterSetFilter),W.addGetterSetter($,"embossBlend",!1,void 0,W.afterSetFilter);W.addGetterSetter($,"enhance",0,R(),W.afterSetFilter);W.addGetterSetter($,"hue",0,R(),W.afterSetFilter),W.addGetterSetter($,"saturation",0,R(),W.afterSetFilter),W.addGetterSetter($,"luminance",0,R(),W.afterSetFilter);W.addGetterSetter($,"hue",0,R(),W.afterSetFilter),W.addGetterSetter($,"saturation",0,R(),W.afterSetFilter),W.addGetterSetter($,"value",0,R(),W.afterSetFilter);function _i(t,e,i){let s=4*(i*t.width+e);const r=[];return r.push(t.data[s++],t.data[s++],t.data[s++],t.data[s++]),r}function mi(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}W.addGetterSetter($,"kaleidoscopePower",2,R(),W.afterSetFilter),W.addGetterSetter($,"kaleidoscopeAngle",0,R(),W.afterSetFilter);W.addGetterSetter($,"threshold",0,R(),W.afterSetFilter);W.addGetterSetter($,"noise",.2,R(),W.afterSetFilter);W.addGetterSetter($,"pixelSize",8,R(),W.afterSetFilter);W.addGetterSetter($,"levels",.5,R(),W.afterSetFilter);W.addGetterSetter($,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"blue",0,M,W.afterSetFilter);W.addGetterSetter($,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"blue",0,M,W.afterSetFilter),W.addGetterSetter($,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t});W.addGetterSetter($,"threshold",.5,R(),W.afterSetFilter);const yi=re.Util._assign(re,{Arc:ne,Arrow:ye,Circle:xe,Ellipse:ve,Image:we,Label:Pe,Tag:Me,Line:he,Path:me,Rect:Re,RegularPolygon:Ie,Ring:Le,Sprite:Ge,Star:Oe,Text:Ve,TextPath:$e,Transformer:di,Wedge:ci,Filters:{Blur:function(t){const e=Math.round(this.blurRadius());e>0&&function(t,e){const i=t.data,s=t.width,r=t.height;let n,o,a,h,l,d,c,g,f,u,p,_,m,y,x,v,w,S,b,C;const T=e+e+1,A=s-1,k=r-1,P=e+1,M=P*(P+1)/2,R=new gi,I=fi[e],E=ui[e];let L=null,G=R,O=null,D=null;for(let t=1;t<T;t++)G=G.next=new gi,t===P&&(L=G);G.next=R,a=o=0;for(let t=0;t<r;t++){_=m=y=x=h=l=d=c=0,g=P*(v=i[o]),f=P*(w=i[o+1]),u=P*(S=i[o+2]),p=P*(b=i[o+3]),h+=M*v,l+=M*w,d+=M*S,c+=M*b,G=R;for(let t=0;t<P;t++)G.r=v,G.g=w,G.b=S,G.a=b,G=G.next;for(let t=1;t<P;t++)n=o+((A<t?A:t)<<2),h+=(G.r=v=i[n])*(C=P-t),l+=(G.g=w=i[n+1])*C,d+=(G.b=S=i[n+2])*C,c+=(G.a=b=i[n+3])*C,_+=v,m+=w,y+=S,x+=b,G=G.next;O=R,D=L;for(let t=0;t<s;t++)i[o+3]=b=c*I>>E,0!==b?(b=255/b,i[o]=(h*I>>E)*b,i[o+1]=(l*I>>E)*b,i[o+2]=(d*I>>E)*b):i[o]=i[o+1]=i[o+2]=0,h-=g,l-=f,d-=u,c-=p,g-=O.r,f-=O.g,u-=O.b,p-=O.a,n=a+((n=t+e+1)<A?n:A)<<2,_+=O.r=i[n],m+=O.g=i[n+1],y+=O.b=i[n+2],x+=O.a=i[n+3],h+=_,l+=m,d+=y,c+=x,O=O.next,g+=v=D.r,f+=w=D.g,u+=S=D.b,p+=b=D.a,_-=v,m-=w,y-=S,x-=b,D=D.next,o+=4;a+=s}for(let t=0;t<s;t++){m=y=x=_=l=d=c=h=0,o=t<<2,g=P*(v=i[o]),f=P*(w=i[o+1]),u=P*(S=i[o+2]),p=P*(b=i[o+3]),h+=M*v,l+=M*w,d+=M*S,c+=M*b,G=R;for(let t=0;t<P;t++)G.r=v,G.g=w,G.b=S,G.a=b,G=G.next;let a=s;for(let r=1;r<=e;r++)o=a+t<<2,h+=(G.r=v=i[o])*(C=P-r),l+=(G.g=w=i[o+1])*C,d+=(G.b=S=i[o+2])*C,c+=(G.a=b=i[o+3])*C,_+=v,m+=w,y+=S,x+=b,G=G.next,r<k&&(a+=s);o=t,O=R,D=L;for(let e=0;e<r;e++)n=o<<2,i[n+3]=b=c*I>>E,b>0?(b=255/b,i[n]=(h*I>>E)*b,i[n+1]=(l*I>>E)*b,i[n+2]=(d*I>>E)*b):i[n]=i[n+1]=i[n+2]=0,h-=g,l-=f,d-=u,c-=p,g-=O.r,f-=O.g,u-=O.b,p-=O.a,n=t+((n=e+P)<k?n:k)*s<<2,h+=_+=O.r=i[n],l+=m+=O.g=i[n+1],d+=y+=O.b=i[n+2],c+=x+=O.a=i[n+3],O=O.next,g+=v=D.r,f+=w=D.g,u+=S=D.b,p+=b=D.a,_-=v,m-=w,y-=S,x-=b,D=D.next,o+=s}}(t,e)},Brightness:function(t){const e=this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]=Math.min(255,i[t]*e),i[t+1]=Math.min(255,i[t+1]*e),i[t+2]=Math.min(255,i[t+2]*e)},Brighten:function(t){const e=255*this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]+=e,i[t+1]+=e,i[t+2]+=e},Contrast:function(t){const e=Math.pow((this.contrast()+100)/100,2),i=t.data,s=i.length;let r=150,n=150,o=150;for(let t=0;t<s;t+=4)r=i[t],n=i[t+1],o=i[t+2],r/=255,r-=.5,r*=e,r+=.5,r*=255,n/=255,n-=.5,n*=e,n+=.5,n*=255,o/=255,o-=.5,o*=e,o+=.5,o*=255,r=r<0?0:r>255?255:r,n=n<0?0:n>255?255:n,o=o<0?0:o>255?255:o,i[t]=r,i[t+1]=n,i[t+2]=o},Emboss:function(t){var e,i,s,r,n,o,a,h,l;const d=t.data,c=t.width,g=t.height,f=Math.min(1,Math.max(0,null!==(i=null===(e=this.embossStrength)||void 0===e?void 0:e.call(this))&&void 0!==i?i:.5)),u=Math.min(1,Math.max(0,null!==(r=null===(s=this.embossWhiteLevel)||void 0===s?void 0:s.call(this))&&void 0!==r?r:.5)),p=null!==(a={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[null!==(o=null===(n=this.embossDirection)||void 0===n?void 0:n.call(this))&&void 0!==o?o:"top-left"])&&void 0!==a?a:315,_=!(null===(l=null===(h=this.embossBlend)||void 0===h?void 0:h.call(this))||void 0===l||!l),m=10*f,y=255*u,x=p*Math.PI/180,v=Math.cos(x),w=Math.sin(x),S=128/1020*m,b=new Uint8ClampedArray(d),C=new Float32Array(c*g);for(let t=0,e=0;e<d.length;e+=4,t++)C[t]=.2126*b[e]+.7152*b[e+1]+.0722*b[e+2];const T=[-1,0,1,-2,0,2,-1,0,1],A=[-1,-2,-1,0,0,0,1,2,1],k=[-c-1,-c,1-c,-1,0,1,c-1,c,c+1],P=t=>t<0?0:t>255?255:t;for(let t=1;t<g-1;t++)for(let e=1;e<c-1;e++){const i=t*c+e;let s=0,r=0;s+=C[i+k[0]]*T[0],r+=C[i+k[0]]*A[0],s+=C[i+k[1]]*T[1],r+=C[i+k[1]]*A[1],s+=C[i+k[2]]*T[2],r+=C[i+k[2]]*A[2],s+=C[i+k[3]]*T[3],r+=C[i+k[3]]*A[3],s+=C[i+k[5]]*T[5],r+=C[i+k[5]]*A[5],s+=C[i+k[6]]*T[6],r+=C[i+k[6]]*A[6],s+=C[i+k[7]]*T[7],r+=C[i+k[7]]*A[7],s+=C[i+k[8]]*T[8],r+=C[i+k[8]]*A[8];const n=P(y+(v*s+w*r)*S),o=4*i;if(_){const t=n-y;d[o]=P(b[o]+t),d[o+1]=P(b[o+1]+t),d[o+2]=P(b[o+2]+t),d[o+3]=b[o+3]}else d[o]=d[o+1]=d[o+2]=n,d[o+3]=b[o+3]}for(let t=0;t<c;t++){let e=4*t,i=4*((g-1)*c+t);d[e]=b[e],d[e+1]=b[e+1],d[e+2]=b[e+2],d[e+3]=b[e+3],d[i]=b[i],d[i+1]=b[i+1],d[i+2]=b[i+2],d[i+3]=b[i+3]}for(let t=1;t<g-1;t++){let e=t*c*4,i=4*(t*c+(c-1));d[e]=b[e],d[e+1]=b[e+1],d[e+2]=b[e+2],d[e+3]=b[e+3],d[i]=b[i],d[i+1]=b[i+1],d[i+2]=b[i+2],d[i+3]=b[i+3]}return t},Enhance:function(t){const e=t.data,i=e.length;let s,r,n,o=e[0],a=o,h=e[1],l=h,d=e[2],c=d;const g=this.enhance();if(0===g)return;for(let t=0;t<i;t+=4)s=e[t+0],s<o?o=s:s>a&&(a=s),r=e[t+1],r<h?h=r:r>l&&(l=r),n=e[t+2],n<d?d=n:n>c&&(c=n);let f,u,p,_,m,y;if(a===o&&(a=255,o=0),l===h&&(l=255,h=0),c===d&&(c=255,d=0),g>0)f=a+g*(255-a),u=o-g*(o-0),p=l+g*(255-l),_=h-g*(h-0),m=c+g*(255-c),y=d-g*(d-0);else{const t=.5*(a+o);f=a+g*(a-t),u=o+g*(o-t);const e=.5*(l+h);p=l+g*(l-e),_=h+g*(h-e);const i=.5*(c+d);m=c+g*(c-i),y=d+g*(d-i)}for(let t=0;t<i;t+=4)e[t+0]=pi(e[t+0],o,a,u,f),e[t+1]=pi(e[t+1],h,l,_,p),e[t+2]=pi(e[t+2],d,c,y,m)},Grayscale:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=.34*e[t]+.5*e[t+1]+.16*e[t+2];e[t]=i,e[t+1]=i,e[t+2]=i}},HSL:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.saturation()),r=Math.abs(this.hue()+360)%360,n=127*this.luminance(),o=1*s*Math.cos(r*Math.PI/180),a=1*s*Math.sin(r*Math.PI/180),h=.299+.701*o+.167*a,l=.587-.587*o+.33*a,d=.114-.114*o-.497*a,c=.299-.299*o-.328*a,g=.587+.413*o+.035*a,f=.114-.114*o+.293*a,u=.299-.3*o+1.25*a,p=.587-.586*o-1.05*a,_=.114+.886*o-.2*a;let m,y,x,v;for(let t=0;t<i;t+=4)m=e[t+0],y=e[t+1],x=e[t+2],v=e[t+3],e[t+0]=h*m+l*y+d*x+n,e[t+1]=c*m+g*y+f*x+n,e[t+2]=u*m+p*y+_*x+n,e[t+3]=v},HSV:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.value()),r=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,o=s*r*Math.cos(n*Math.PI/180),a=s*r*Math.sin(n*Math.PI/180),h=.299*s+.701*o+.167*a,l=.587*s-.587*o+.33*a,d=.114*s-.114*o-.497*a,c=.299*s-.299*o-.328*a,g=.587*s+.413*o+.035*a,f=.114*s-.114*o+.293*a,u=.299*s-.3*o+1.25*a,p=.587*s-.586*o-1.05*a,_=.114*s+.886*o-.2*a;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2],n=e[t+3];e[t+0]=h*i+l*s+d*r,e[t+1]=c*i+g*s+f*r,e[t+2]=u*i+p*s+_*r,e[t+3]=n}},Invert:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},Kaleidoscope:function(t){const e=t.width,i=t.height;let s,r,n,o,a,h,l,d,c,g,f=Math.round(this.kaleidoscopePower());const u=Math.round(this.kaleidoscopeAngle()),p=Math.floor(e*(u%360)/360);if(f<1)return;const m=_.createCanvasElement();m.width=e,m.height=i;const y=m.getContext("2d").getImageData(0,0,e,i);_.releaseCanvas(m),function(t,e,i){const s=t.data,r=e.data,n=t.width,o=t.height,a=i.polarCenterX||n/2,h=i.polarCenterY||o/2;let l=Math.sqrt(a*a+h*h),d=n-a,c=o-h;const g=Math.sqrt(d*d+c*c);l=g>l?g:l;const f=o,u=n,p=360/u*Math.PI/180;for(let t=0;t<u;t+=1){const e=Math.sin(t*p),i=Math.cos(t*p);for(let o=0;o<f;o+=1){d=Math.floor(a+l*o/f*i),c=Math.floor(h+l*o/f*e);let g=4*(c*n+d);const u=s[g+0],p=s[g+1],_=s[g+2],m=s[g+3];g=4*(t+o*n),r[g+0]=u,r[g+1]=p,r[g+2]=_,r[g+3]=m}}}(t,y,{polarCenterX:e/2,polarCenterY:i/2});let x=e/Math.pow(2,f);for(;x<=8;)x*=2,f-=1;x=Math.ceil(x);let v=x,w=0,S=v,b=1;for(p+x>e&&(w=v,S=0,b=-1),r=0;r<i;r+=1)for(s=w;s!==S;s+=b)n=Math.round(s+p)%e,c=4*(e*r+n),a=y.data[c+0],h=y.data[c+1],l=y.data[c+2],d=y.data[c+3],g=4*(e*r+s),y.data[g+0]=a,y.data[g+1]=h,y.data[g+2]=l,y.data[g+3]=d;for(r=0;r<i;r+=1)for(v=Math.floor(x),o=0;o<f;o+=1){for(s=0;s<v+1;s+=1)c=4*(e*r+s),a=y.data[c+0],h=y.data[c+1],l=y.data[c+2],d=y.data[c+3],g=4*(e*r+2*v-s-1),y.data[g+0]=a,y.data[g+1]=h,y.data[g+2]=l,y.data[g+3]=d;v*=2}!function(t,e,i){const s=t.data,r=e.data,n=t.width,o=t.height,a=i.polarCenterX||n/2,h=i.polarCenterY||o/2;let l=Math.sqrt(a*a+h*h),d=n-a,c=o-h;const g=Math.sqrt(d*d+c*c);l=g>l?g:l;const f=o,u=n;let p,_;for(d=0;d<n;d+=1)for(c=0;c<o;c+=1){const t=d-a,e=c-h,i=Math.sqrt(t*t+e*e)*f/l;let o=(180*Math.atan2(e,t)/Math.PI+360+0)%360;o=o*u/360,p=Math.floor(o),_=Math.floor(i);let g=4*(_*n+p);const m=s[g+0],y=s[g+1],x=s[g+2],v=s[g+3];g=4*(c*n+d),r[g+0]=m,r[g+1]=y,r[g+2]=x,r[g+3]=v}}(y,t,{})},Mask:function(t){let e=function(t,e){const i=_i(t,0,0),s=_i(t,t.width-1,0),r=_i(t,0,t.height-1),n=_i(t,t.width-1,t.height-1),o=e||10;if(mi(i,s)<o&&mi(s,n)<o&&mi(n,r)<o&&mi(r,i)<o){const e=function(t){const e=[0,0,0];for(let i=0;i<t.length;i++)e[0]+=t[i][0],e[1]+=t[i][1],e[2]+=t[i][2];return e[0]/=t.length,e[1]/=t.length,e[2]/=t.length,e}([s,i,n,r]),a=[];for(let i=0;i<t.width*t.height;i++){const s=mi(e,[t.data[4*i],t.data[4*i+1],t.data[4*i+2]]);a[i]=s<o?0:255}return a}}(t,this.threshold());return e&&(e=function(t,e,i){const s=[1,1,1,1,0,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<r;o++)for(let l=0;l<r;l++){const c=a+o-n,g=h+l-n;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*r+l];d+=t[c*e+g]*i}}o[l]=2040===d?255:0}return o}(e,t.width,t.height),e=function(t,e,i){const s=[1,1,1,1,1,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<r;o++)for(let l=0;l<r;l++){const c=a+o-n,g=h+l-n;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*r+l];d+=t[c*e+g]*i}}o[l]=d>=1020?255:0}return o}(e,t.width,t.height),e=function(t,e,i){const s=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<r;o++)for(let l=0;l<r;l++){const c=a+o-n,g=h+l-n;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*r+l];d+=t[c*e+g]*i}}o[l]=d}return o}(e,t.width,t.height),function(t,e){for(let i=0;i<t.width*t.height;i++)t.data[4*i+3]=e[i]}(t,e)),t},Noise:function(t){const e=255*this.noise(),i=t.data,s=i.length,r=e/2;for(let t=0;t<s;t+=4)i[t+0]+=r-2*r*Math.random(),i[t+1]+=r-2*r*Math.random(),i[t+2]+=r-2*r*Math.random()},Pixelate:function(t){let e=Math.ceil(this.pixelSize()),i=t.width,s=t.height,r=Math.ceil(i/e),n=Math.ceil(s/e),o=t.data;if(e<=0)_.error("pixelSize value can not be <= 0");else for(let t=0;t<r;t+=1)for(let r=0;r<n;r+=1){let n=0,a=0,h=0,l=0;const d=t*e,c=d+e,g=r*e,f=g+e;let u=0;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=g;e<f;e+=1){if(e>=s)continue;const r=4*(i*e+t);n+=o[r+0],a+=o[r+1],h+=o[r+2],l+=o[r+3],u+=1}n/=u,a/=u,h/=u,l/=u;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=g;e<f;e+=1){if(e>=s)continue;const r=4*(i*e+t);o[r+0]=n,o[r+1]=a,o[r+2]=h,o[r+3]=l}}},Posterize:function(t){const e=Math.round(254*this.levels())+1,i=t.data,s=i.length,r=255/e;for(let t=0;t<s;t+=1)i[t]=Math.floor(i[t]/r)*r},RGB:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue();for(let t=0;t<i;t+=4){const i=(.34*e[t]+.5*e[t+1]+.16*e[t+2])/255;e[t]=i*s,e[t+1]=i*r,e[t+2]=i*n,e[t+3]=e[t+3]}},RGBA:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue(),o=this.alpha();for(let t=0;t<i;t+=4){const i=1-o;e[t]=s*o+e[t]*i,e[t+1]=r*o+e[t+1]*i,e[t+2]=n*o+e[t+2]*i}},Sepia:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2];e[t+0]=Math.min(255,.393*i+.769*s+.189*r),e[t+1]=Math.min(255,.349*i+.686*s+.168*r),e[t+2]=Math.min(255,.272*i+.534*s+.131*r)}},Solarize:function(t){const e=t.data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2];.2126*i+.7152*s+.0722*r>=128&&(e[t]=255-i,e[t+1]=255-s,e[t+2]=255-r)}return t},Threshold:function(t){const e=255*this.threshold(),i=t.data,s=i.length;for(let t=0;t<s;t+=1)i[t]=i[t]<e?0:255}}});class xi{screenToWorld(t){return{x:t.x,y:t.y,z:0}}worldToScreen(t){return{x:t.x,y:t.y}}getScale(){return{x:1,y:1,z:1}}}class vi{constructor(t,e,i){this.setColor(t,e,i)}asHex(){return"#"+this.HEX}asRGB(){return{r:this.R,g:this.G,b:this.B}}setColor(t,e,i){this.R=t,this.G=e,this.B=i,this.HEX=this.rgbToHex(t,e,i)}rgbToHex(t,e,i){const s=t=>{const e=t.toString(16);return"0"===e?"00":e};return s(t)+s(e)+s(i)}}const wi=new Map([["solid",[]],["dot",[30,30,.001,30]],["dash",[30,30]]]);class Si{constructor(t,e=null,i=new xi){var s,r;if(this._worldTransformer=i,e){this._ref=e;let t=this._ref.getAttr("wcsPoints");if(!t){t=[];const e=this._ref.points();let i;for(let s=0;s<e.length;s+=2)i=this._worldTransformer.screenToWorld({x:e[s],y:e[s+1]}),t.push({x:i.x,y:i.y,z:i.z});this._ref.setAttr("wcsPoints",t)}return}t||(t={}),t.points||(t.points=[{x:0,y:0},{x:100,y:100}]);const n=[],o=[];t.points.forEach(t=>{n.push(t.x,t.y);const e=this._worldTransformer.screenToWorld({x:t.x,y:t.y});o.push({x:e.x,y:e.y,z:e.z})}),this._ref=new yi.Line({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.width)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:n,draggable:!0,strokeScaleEnabled:!1,dash:wi.get(t.type)||[]}),this._ref.setAttr("wcsPoints",o),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation)}),this._ref.on("transformend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.on("dragend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Line"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){return this._ref.points()}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}getLineType(){let t;switch(this._ref.dash()||[]){case wi.get("dot"):t="dot";break;case wi.get("dash"):t="dash";break;default:t="solid"}return t}setLineType(t){const e=wi.get(t);e&&this._ref.dash(e)}addPoints(t){let e=this._ref.points();const i=this._ref.getAttr("wcsPoints");t.forEach(t=>{e=e.concat([t.x,t.y]);const s=this._worldTransformer.screenToWorld(t);i.push(s)}),this._ref.points(e)}updateScreenCoordinates(){const t=this._ref.getAttr("wcsPoints"),e=[];let i=this._ref.getAbsoluteTransform().copy();i=i.invert(),t.forEach(t=>{let s=this._worldTransformer.worldToScreen(t);s=i.point({x:s.x,y:s.y}),e.push(s.x),e.push(s.y)}),this._ref.points([]),this._ref.points(e),this._ref.clearCache()}}class bi{constructor(t,e=null,i=new xi){var s,r,n;if(this.TEXT_FONT_FAMILY="Calibri",this._worldTransformer=i,e){this._ref=e;return void(this._ref.getAttr("wcsStart")||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.text||(t.text="default"),this._ref=new yi.Text({x:t.position.x,y:t.position.y,text:t.text,fontSize:null!==(s=t.fontSize)&&void 0!==s?s:34,fontFamily:this.TEXT_FONT_FAMILY,fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",align:"left",draggable:!0,rotation:null!==(n=t.rotation)&&void 0!==n?n:0}),this._ref.width(this._ref.getTextWidth()),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<Math.round(this.getFontSize())&&(n=Math.round(this.getFontSize())),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Text"}getColor(){return this._ref.fill()}setColor(t){this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getText(){return this._ref.text()}setText(t){this._ref.text(t)}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getFontSize(){return this._ref.fontSize()}setFontSize(t){this._ref.fontSize(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));let e=this._ref.getStage().getAbsoluteTransform().copy();e=e.invert();const i=e.point(t);this._ref.position({x:i.x,y:i.y})}}class Ci{constructor(t,e=null,i=new xi){var s,r,n,o;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200),this._ref=new yi.Rect({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.lineWidth)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,width:null!==(n=t.width)&&void 0!==n?n:200,height:null!==(o=t.height)&&void 0!==o?o:200,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}getWidth(){return this._ref.width()}getHeight(){return this._ref.height()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Rectangle"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}function Ti(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}class Ai{constructor(t,e=null,i=new xi){var s,r,n;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsPosition"),i=this._ref.getAttr("wcsRadiusX"),s=this._ref.getAttr("wcsRadiusY");return t||this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),i||this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:e.x()+e.radiusX(),y:e.y()})),void(s||this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()+e.radiusY()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(null!==(s=t.radius)&&void 0!==s||(t.radius={x:0,y:0}),t.radius.x=Ti(t.position,t.position2),t.position3?t.radius.y=Ti(t.position,t.position3):t.radius.x=t.radius.y):t.radius||(t.radius={x:25,y:25}),this._ref=new yi.Ellipse({stroke:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:null!==(n=t.lineWidth)&&void 0!==n?n:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,radiusX:t.radius.x,radiusY:t.radius.y,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t.radius.x,y:this._ref.y()})),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t.radius.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.radiusX();i&&(r*=e.scaleX);let n=this._ref.radiusY();s&&(n*=e.scaleY);r<25&&(r=25),n<25&&(n=25),t.evt.ctrlKey||t.evt.shiftKey?i?this._ref.radius({x:r,y:r}):this._ref.radius({x:n,y:n}):this._ref.radius({x:r,y:n}),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t,y:e}))}getRadiusX(){return this._ref.radiusX()}setRadiusX(t){this._ref.radiusX(t),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t,y:this._ref.y()}))}getRadiusY(){return this._ref.radiusY()}setRadiusY(t){this._ref.radiusY(t),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t}))}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Ellipse"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX")),i=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));let s=this._ref.getStage().getAbsoluteTransform().copy();s=s.invert();const r=s.point({x:t.x,y:t.y});this._ref.position({x:r.x,y:r.y}),this._ref.radius({x:Math.abs(s.point(e).x-r.x),y:Math.abs(s.point(i).y-r.y)})}}class ki{constructor(t,e=null,i=new xi){var s,r;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");return t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.points()[0],y:e.points()[1]})),void(i||this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:e.points()[2],y:e.points()[3]})))}t||(t={}),t.start||(t.start={x:0,y:0}),t.end||(t.end={x:100,y:100}),this._ref=new yi.Arrow({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[t.start.x,t.start.y,t.end.x,t.end.y],draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.start.x,y:t.start.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.end.x,y:t.end.y})),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.points(),s=this._ref.getAbsoluteTransform(),r=s.point({x:i[0],y:i[1]}),n=s.point({x:i[2],y:i[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(r)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(n))}),this._ref.on("dragend",t=>{const e=this._ref.points(),i=t.target.getAbsoluteTransform(),s=i.point({x:e[0],y:e[1]}),r=i.point({x:e[2],y:e[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(s)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(r))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Arrow"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t),this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){const t=this._ref.points();return[{x:t[0],y:t[1]},{x:t[2],y:t[3]}]}setPoints(t){2===t.length&&(this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t[0].x,y:t[0].y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t[1].x,y:t[1].y})),this._ref.points([t[0].x,t[0].y,t[1].x,t[1].y]))}getStartPoint(){const t=this._ref.points();return{x:t[0],y:t[1]}}setStartPoint(t,e){const i=this._ref.points();this._ref.points([t,e,i[2],i[3]]),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getEndPoint(){const t=this._ref.points();return{x:t[2],y:t[3]}}setEndPoint(t,e){const i=this._ref.points();this._ref.points([i[0],i[1],t,e]),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t,y:e}))}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getAbsoluteTransform().copy();i=i.invert();const s=i.point({x:t.x,y:t.y}),r=i.point({x:e.x,y:e.y});this._ref.points([s.x,s.y,r.x,r.y])}}class Pi{constructor(t,e=null,i=new xi){var s,r;if(this._ratio=1,this.EPSILON=1e-5,this.BASE64_HEADER_START="data:image/",this.BASE64_NOT_FOUND="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=",this._worldTransformer=i,e){e.src&&e.src.startsWith(this.BASE64_HEADER_START)||(e.src=this.BASE64_NOT_FOUND),e.height()<=this.EPSILON&&e.height(32),e.width()<=this.EPSILON&&e.width(32),this._ref=e,this._canvasImage=e.image(),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width();const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.src&&t.src.startsWith(this.BASE64_HEADER_START)||(t.src=this.BASE64_NOT_FOUND),t.position2&&(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y),this._canvasImage=new Image,this._canvasImage.onload=()=>{if(this._ref.image(this._canvasImage),this._ref.height()<=this.EPSILON&&this._ref.height(this._canvasImage.height),this._ref.width()<=this.EPSILON&&this._ref.width(this._canvasImage.width),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width(),(t.width<=this.EPSILON||t.height<=this.EPSILON)&&(t.maxWidth>=this.EPSILON||t.maxWidth>=this.EPSILON)){const e=t.maxHeight-this._canvasImage.height,i=t.maxWidth-this._canvasImage.width;(e<=this.EPSILON||i<=this.EPSILON)&&(i<=this.EPSILON&&i<e/this._ratio?(this._ref.height(t.maxWidth*this._ratio),this._ref.width(t.maxWidth)):(this._ref.width(t.maxHeight/this._ratio),this._ref.height(t.maxHeight)))}const e=this._worldTransformer.screenToWorld({x:t.position.x+this._ref.width(),y:t.position.y+this._ref.height()});this._ref.setAttr("wcsEnd",e)},this._canvasImage.onerror=()=>{this._canvasImage.onerror=function(){},this._canvasImage.src=this.BASE64_NOT_FOUND},this._canvasImage.src=t.src,this._ref=new yi.Image({x:t.position.x,y:t.position.y,image:this._canvasImage,width:null!==(s=t.width)&&void 0!==s?s:0,height:null!==(r=t.height)&&void 0!==r?r:0,draggable:!0}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),t.position2&&this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),t.evt.ctrlKey||t.evt.shiftKey?i?(this._ref.width(r),this._ref.height(r*this._ratio)):(this._ref.width(n/this._ratio),this._ref.height(n)):(i&&this._ref.width(r),s&&this._ref.height(n)),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getSrc(){return this._canvasImage.src}setSrc(t){this._canvasImage.src=t}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t),this._ref.height(t*this._ratio);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t),this._ref.width(t/this._ratio);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Image"}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}class Mi{constructor(t,e=null,i=new xi){var s,r,n,o;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200);this._ref=new yi.Shape({x:t.position.x,y:t.position.y,width:null!==(s=t.width)&&void 0!==s?s:200,height:null!==(r=t.height)&&void 0!==r?r:200,stroke:null!==(n=t.color)&&void 0!==n?n:"#ff0000",strokeWidth:null!==(o=t.lineWidth)&&void 0!==o?o:4,draggable:!0,strokeScaleEnabled:!1,globalCompositeOperation:"source-over",sceneFunc:(t,e)=>{const i=this._ref.width(),s=this._ref.height(),r=[{x:0,y:0},{x:0+i,y:0},{x:0+i,y:0+s},{x:0,y:0+s},{x:0,y:0}];function n(n,o){const a={x:(h={x:0,y:0}).x+i/2,y:h.y+s/2};var h;t.beginPath();for(let e=0;e<r.length-1;e++){let i=o;const s=r[e+1].x-r[e].x,h=r[e+1].y-r[e].y,l=Math.sqrt(s*s+h*h),d=Math.floor(l/i);i=o+d/(l%i);let c=r[e].x+s/d/2,g=r[e].y+h/d/2;const f=r[e+1].x,u=r[e+1].y,p=Math.atan((u-g)/(f-c)),_=p+Math.PI,m=c>a.x&&g>a.y;for(let e=0;e<d;e++)m?t.arc(c,g,n,p,_):t.arc(c,g,n,_,p),c+=s/d,g+=h/d}t.closePath(),t.fillStrokeShape(e)}i>=49||s>=49?n(8,15):i>=25||s>=25?n(4,7.5):(t.beginPath(),t.lineTo(r[1].x,r[1].y),t.lineTo(r[2].x,r[2].y),t.lineTo(r[3].x,r[3].y),t.lineTo(r[4].x,r[4].y),t.closePath(),t.fillStrokeShape(e))}}),this._ref.className="Cloud",this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.getSelfRect=()=>({x:-8,y:-8,width:this._ref.width()+16,height:this._ref.height()+16}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Cloud"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.position({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}const Ri={SelectMarkup:{name:"SelectMarkup",initializer:null},Line:{name:"Line",initializer:(t,e=null,...i)=>new Si(e,t,...i)},Text:{name:"Text",initializer:(t,e=null,...i)=>new bi(e,t,...i)},Rectangle:{name:"Rect",initializer:(t,e=null,...i)=>new Ci(e,t,...i)},Ellipse:{name:"Ellipse",initializer:(t,e=null,...i)=>new Ai(e,t,...i)},Arrow:{name:"Arrow",initializer:(t,e=null,...i)=>new ki(e,t,...i)},Image:{name:"Image",initializer:(t,e=null,...i)=>new Pi(e,t,...i)},Cloud:{name:"Cloud",initializer:(t,e=null,...i)=>new Mi(e,t,...i)}};t.Markup=class{constructor(){this._markupIsActive=!1,this._markupColor=new vi(255,0,0),this.lineWidth=4,this.lineType="solid",this.fontSize=34,this.changeActiveDragger=t=>{const e=t.data;this._markupContainer.className=this._container.className.split(" ").filter(t=>!t.startsWith("oda-cursor-")).filter(t=>t).concat(`oda-cursor-${e.toLowerCase()}`).join(" "),this.removeTextInput(),this.removeImageInput(),this.enableEditMode(e)},this.resizeContainer=()=>{const{offsetLeft:t,offsetTop:e,offsetWidth:i,offsetHeight:s}=this._container;i&&s&&(this._markupContainer.style.left=`${t}px`,this._markupContainer.style.top=`${e}px`,this._konvaStage.width(i),this._konvaStage.height(s),this.getObjects().forEach(t=>{t.updateScreenCoordinates()}))},this.pan=()=>{this.updateScreenCoordinatesForAll()},this.zoomAt=()=>{this.updateScreenCoordinatesForAll()},this.changeCameraMode=()=>{this.clearOverlay()},this.redirectToViewer=t=>{this._viewer&&this._viewer.emit(t)},this.getRelativePointPosition=(t,e)=>{const i=e.getAbsoluteTransform().copy();return i.invert(),i.point(t)},this.getRelativePointerPosition=t=>this.getRelativePointPosition(t.getStage().getPointerPosition(),t)}initialize(t,e,i,s){this._viewer=i,this._worldTransformer=null!=s?s:new xi,this._container=t,this._markupContainer=document.createElement("div"),this._markupContainer.id="markup-container",this._markupContainer.style.position="absolute",this._markupContainer.style.outline="0px",this._markupContainer.style.pointerEvents="none";this._container.parentElement.appendChild(this._markupContainer),this._markupColor.setColor(255,0,0),this.initializeKonva(),this._resizeObserver=new ResizeObserver(this.resizeContainer),this._resizeObserver.observe(t),this._viewer&&(this._viewer.addEventListener("changeactivedragger",this.changeActiveDragger),this._viewer.addEventListener("pan",this.pan),this._viewer.addEventListener("zoomat",this.zoomAt),this._viewer.addEventListener("changecameramode",this.changeCameraMode))}dispose(){var t,e;this._viewer&&(this._viewer.removeEventListener("changecameramode",this.changeCameraMode),this._viewer.removeEventListener("zoomat",this.zoomAt),this._viewer.removeEventListener("pan",this.pan),this._viewer.removeEventListener("changeactivedragger",this.changeActiveDragger)),null===(t=this._resizeObserver)||void 0===t||t.disconnect(),this._resizeObserver=void 0,this.destroyKonva(),null===(e=this._markupContainer)||void 0===e||e.remove(),this._markupContainer=void 0,this._container=void 0,this._viewer=void 0,this._worldTransformer=void 0,this._markupIsActive=!1}syncOverlay(){}clearOverlay(){this.removeTextInput(),this.removeImageInput(),this.clearSelected(),this.getObjects().forEach(t=>t.delete())}getMarkupColor(){return this._markupColor.asRGB()}setMarkupColor(t,e,i){this._markupColor.setColor(t,e,i),this.redirectToViewer({type:"changemarkupcolor",data:{r:t,g:e,b:i}})}colorizeAllMarkup(t,e,i){this.setMarkupColor(t,e,i);const s=new vi(t,e,i).asHex();this.getObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}colorizeSelectedMarkups(t,e,i){const s=new vi(t,e,i).asHex();this.getSelectedObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}setViewpoint(t){var e,i,s,r,n,o,a,h;this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._konvaStage.scale({x:1,y:1}),this._konvaStage.position({x:0,y:0});const l=(null===(e=t.custom_fields)||void 0===e?void 0:e.markup_color)||{r:255,g:0,b:0};this.setMarkupColor(l.r,l.g,l.b),null===(i=t.lines)||void 0===i||i.forEach(t=>{const e=[];t.points.forEach(t=>{const i=this._worldTransformer.worldToScreen(t);e.push(i.x),e.push(i.y)}),this.addLine(e,t.color,t.type,t.width,t.id)}),null===(s=t.texts)||void 0===s||s.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position);this.addText(t.text,e,t.angle,t.color,t.text_size,t.font_size,t.id)}),null===(r=t.rectangles)||void 0===r||r.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addRectangle(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(n=t.ellipses)||void 0===n||n.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null,s=t.position3?this._worldTransformer.worldToScreen(t.position3):null;this.addEllipse(e,i,s,t.radius,t.line_width,t.color,t.id)}),null===(o=t.arrows)||void 0===o||o.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.start),i=this._worldTransformer.worldToScreen(t.end);this.addArrow(e,i,t.color,t.id)}),null===(a=t.clouds)||void 0===a||a.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addCloud(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(h=t.images)||void 0===h||h.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addImage(e,i,t.src,t.width,t.height,t.id)})}getViewpoint(t){return t||(t={}),t.lines=this.getMarkupLines(),t.texts=this.getMarkupTexts(),t.arrows=this.getMarkupArrows(),t.clouds=this.getMarkupClouds(),t.ellipses=this.getMarkupEllipses(),t.images=this.getMarkupImages(),t.rectangles=this.getMarkupRectangles(),t.custom_fields={markup_color:this.getMarkupColor()},t.snapshot={data:this.combineMarkupWithDrawing()},t}enableEditMode(t){return t&&Ri[t]?(this._markupMode=t,this._markupContainer.style.pointerEvents="all",this._markupIsActive=!0):(this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._markupContainer.style.pointerEvents="none",this._markupIsActive=!1),this}createObject(t,e){const i=Ri[t];if(!i||!i.initializer)throw new Error(`Markup CreateObject - unsupported markup type ${t}`);const s=i.initializer(null,e,this._worldTransformer);return this.addObject(s),s}getObjects(){const t=[];return Object.keys(Ri).forEach(e=>{const i=Ri[e];this.konvaLayerFind(e).forEach(e=>t.push(i.initializer(e,null,this._worldTransformer)))}),t}getSelectedObjects(){return this._konvaTransformer?this._konvaTransformer.nodes().map(t=>{const e=t.className,i=Object.values(Ri).find(t=>t.name===e);return i?i.initializer(t,null,this._worldTransformer):null}).filter(t=>t):[]}selectObjects(t){if(!this._konvaTransformer)return;const e=this._konvaTransformer.nodes().concat(t.map(t=>t.ref()));this._konvaTransformer.nodes(e)}clearSelected(){this._konvaTransformer&&this._konvaTransformer.nodes([])}addObject(t){"Image"===t.type()?this._groupImages.add(t.ref()):"Text"===t.type()?this._groupTexts.add(t.ref()):this._groupGeometry.add(t.ref())}konvaLayerFind(t){if(!this._konvaLayer)return[];const e=Ri[t];return e&&e.initializer?this._konvaLayer.find(e.name).filter(t=>t.parent===this._konvaLayer||t.parent===this._groupImages||t.parent===this._groupGeometry||t.parent===this._groupTexts):[]}updateScreenCoordinatesForAll(){this.getObjects().forEach(t=>{t.updateScreenCoordinates()})}initializeKonva(){const t=new yi.Stage({container:this._markupContainer,width:this._container.clientWidth,height:this._container.clientHeight});this._konvaStage=t;const e=new yi.Layer({pixelRation:window.devicePixelRatio});t.add(e),this._groupImages=new yi.Group,e.add(this._groupImages),this._groupGeometry=new yi.Group,e.add(this._groupGeometry),this._groupTexts=new yi.Group,e.add(this._groupTexts),this._konvaLayer=e;const i=new yi.Transformer({shouldOverdrawWholeArea:!1,keepRatio:!1,flipEnabled:!1});e.add(i),this._konvaTransformer=i;let s,r,n,o=!1;t.on("mousedown touchstart",e=>{if(!this._markupIsActive||e.target!==t||"Text"===this._markupMode||"Image"===this._markupMode)return;if(e.target===t&&i.nodes().length>0)return void i.nodes([]);const n=this.getRelativePointerPosition(t);r=n,o=["Arrow","Cloud","Ellipse","Line","Rectangle"].some(t=>t===this._markupMode),"Line"===this._markupMode&&(s=this.addLine([n.x,n.y,n.x,n.y]))}),t.on("mouseup touchend",()=>{if(this._markupIsActive){if(o){const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,s=i?r.x:Math.min(r.x,e.x),n=i?r.y:Math.min(r.y,e.y),o=i?200:Math.abs(r.x-e.x),a=i?200:Math.abs(r.y-e.y);i&&("Rectangle"===this._markupMode?this.addRectangle({x:s,y:n},null,o,a):"Ellipse"===this._markupMode?this.addEllipse({x:s,y:n},null,null,{x:o/2,y:a/2}):"Arrow"===this._markupMode?this.addArrow({x:r.x,y:r.y},{x:i?r.x+200:e.x,y:i?n:e.y}):"Cloud"===this._markupMode&&this.addCloud({x:s,y:n},null,Math.max(100,o),Math.max(100,a)))}n=void 0,o=!1}}),t.on("mousemove touchmove",()=>{if(!this._markupIsActive)return;if(!o)return;const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,a=i?r.x:Math.min(r.x,e.x),h=i?r.y:Math.min(r.y,e.y),l=i?200:Math.abs(r.x-e.x),d=i?200:Math.abs(r.y-e.y);"Line"===this._markupMode?s.addPoints([{x:e.x,y:e.y}]):"Arrow"===this._markupMode?n?n.setEndPoint(e.x,e.y):n=this.addArrow({x:r.x,y:r.y},{x:e.x,y:e.y}):"Rectangle"===this._markupMode?n?(n.setPosition(a,h),n.setWidth(l),n.setHeight(d)):n=this.addRectangle({x:a,y:h},null,l,d):"Ellipse"===this._markupMode?n?(n.setPosition(a,h),n.setRadiusX(l),n.setRadiusY(d)):n=this.addEllipse({x:a,y:h},null,null,{x:l,y:d}):"Cloud"===this._markupMode&&(n?(n.setPosition(a,h),n.setWidth(Math.max(100,l)),n.setHeight(Math.max(100,d))):n=this.addCloud({x:a,y:h},null,l,d))}),t.on("click tap",e=>{if(!this._markupIsActive)return;if(e.target===t){if("Text"===this._markupMode){if(this._textInputRef&&this._textInputRef.value)this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle);else if(0===i.nodes().length){const i=this.getRelativePointerPosition(t);this.createTextInput(i,e.evt.pageX,e.evt.pageY,0,null)}}else if("Image"===this._markupMode)if(this._imageInputRef&&this._imageInputRef.value)this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,this._imageInputRef.value,0,0,this._imageInputRef.value);else if(0===i.nodes().length){const e=this.getRelativePointerPosition(t);this.createImageInput(e)}return void i.nodes([])}if("Text"===this._markupMode||"SelectMarkup"===this._markupMode){if("Text"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._textInputRef&&this._textInputRef.value?this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle):this.createTextInput({x:e.target.attrs.x,y:e.target.attrs.y},e.evt.pageX,e.evt.pageY,e.target.attrs.rotation,e.target.attrs.text));this.removeTextInput()}if("Image"===this._markupMode||"SelectMarkup"===this._markupMode){if("Image"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._imageInputRef&&this._imageInputRef.value?this.addImage(this._imageInputPos,null,this._imageInputRef.value,0,0):this.createImageInput({x:e.target.attrs.x,y:e.target.attrs.y}));this.removeImageInput()}i.nodes().filter(t=>"Cloud"===t.className||"Image"===t.className).length>0||"Cloud"===e.target.className||"Image"===e.target.className?i.rotateEnabled(!1):i.rotateEnabled(!0);const s=e.evt.shiftKey||e.evt.ctrlKey||e.evt.metaKey,r=i.nodes().indexOf(e.target)>=0;if(s||r){if(s&&r){const t=i.nodes().slice();t.splice(t.indexOf(e.target),1),i.nodes(t)}else if(s&&!r){const t=i.nodes().concat([e.target]);i.nodes(t)}}else i.nodes([e.target])});const a=t.container();a.tabIndex=1,a.focus(),a.addEventListener("keydown",t=>{if(this._markupIsActive)return"Delete"===t.code?(this.getSelectedObjects().forEach(t=>t.delete()),void this.clearSelected()):void t.preventDefault()})}destroyKonva(){var t;this.removeTextInput(),this.removeImageInput(),this.clearOverlay(),null===(t=this._konvaStage)||void 0===t||t.destroy(),this._groupImages=void 0,this._groupGeometry=void 0,this._groupTexts=void 0,this._konvaLayer=void 0,this._konvaTransformer=void 0,this._konvaStage=void 0}getMarkupLines(){const t=[];return this.konvaLayerFind("Line").forEach(e=>{const i=e.getAttr("wcsPoints");if(!i)return;const s=new Si(null,e,this._worldTransformer),r={id:s.id(),points:i,color:s.getColor()||"#ff0000",type:s.getLineType()||this.lineType,width:s.getLineWidth()||this.lineWidth};t.push(r)}),t}getMarkupTexts(){const t=[];return this.konvaLayerFind("Text").forEach(e=>{const i=this._worldTransformer.getScale(),s=e.getAttr("wcsStart"),r=this._konvaStage.getAbsoluteTransform(),n=new bi(null,e,this._worldTransformer),o={id:n.id(),position:s,text:n.getText(),text_size:.02*i.y,angle:n.getRotation(),color:n.getColor(),font_size:n.getFontSize()*r.getMatrix()[0]};t.push(o)}),t}getMarkupRectangles(){const t=[];return this.konvaLayerFind("Rectangle").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),o=new Ci(null,e,this._worldTransformer),a={id:o.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:o.getLineWidth(),color:o.getColor()};t.push(a)}),t}getMarkupEllipses(){const t=[];return this.konvaLayerFind("Ellipse").forEach(e=>{const i=e.getAttr("wcsPosition"),s=e.getAttr("wcsRadiusX"),r=e.getAttr("wcsRadiusY"),n=this._konvaStage.getAbsoluteTransform().getMatrix()[0],o=new Ai(null,e,this._worldTransformer),a={id:o.id(),position:i,position2:s,position3:r,radius:{x:e.getRadiusX()*n,y:e.getRadiusY()*n},line_width:o.getLineWidth(),color:o.getColor()};t.push(a)}),t}getMarkupArrows(){const t=[];return this.konvaLayerFind("Arrow").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=new ki(null,e,this._worldTransformer),n={id:r.id(),start:i,end:s,color:r.getColor()};t.push(n)}),t}getMarkupImages(){const t=[];return this.konvaLayerFind("Image").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._konvaStage.getAbsoluteTransform().getMatrix()[0],n=new Pi(null,e,this._worldTransformer),o={id:n.id(),position:i,position2:s,src:n.getSrc(),width:n.getWidth()*r,height:n.getHeight()*r};t.push(o)}),t}getMarkupClouds(){const t=[];return this.konvaLayerFind("Cloud").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),o=new Mi(null,e,this._worldTransformer),a={id:o.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:o.getLineWidth(),color:o.getColor()};t.push(a)}),t}combineMarkupWithDrawing(){this.clearSelected();const t=document.createElement("canvas");if(this._konvaStage){t.width=this._konvaStage.width(),t.height=this._konvaStage.height();const e=t.getContext("2d");this._container instanceof HTMLCanvasElement&&e.drawImage(this._container,0,0),e.drawImage(this._konvaStage.toCanvas({pixelRatio:window.devicePixelRatio}),0,0)}return t.toDataURL("image/jpeg",.25)}addLine(t,e,i,s,r){if(!t||0===t.length)return;const n=[];for(let e=0;e<t.length;e+=2)n.push({x:t[e],y:t[e+1]});const o=new Si({points:n,type:i||this.lineType,width:s||this.lineWidth,color:e||this._markupColor.asHex(),id:r},null,this._worldTransformer);return this.addObject(o),o}createTextInput(t,e,i,s,r){this._textInputRef?this.removeTextInput():(this._textInputPos=t,this._textInputAngle=s,this._textInputRef=document.createElement("textarea"),this._textInputRef.style.zIndex="9999",this._textInputRef.style.position="absolute",this._textInputRef.style.display="block",this._textInputRef.style.top=i+"px",this._textInputRef.style.left=e+"px",this._textInputRef.style.fontSize=`${this.fontSize}px`,this._textInputRef.style.color=`${this._markupColor.asHex()}`,this._textInputRef.style.fontFamily="Calibri",this._textInputRef.onkeydown=t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle)),"Escape"===t.key&&(t.preventDefault(),this.removeTextInput())},r&&(this._textInputRef.value=r),document.body.appendChild(this._textInputRef),setTimeout(()=>{this._textInputRef.focus()},50))}removeTextInput(){var t;null===(t=this._textInputRef)||void 0===t||t.remove(),this._textInputRef=null,this._textInputPos=null,this._textInputAngle=0}createImageInput(t){if(this._imageInputRef)this.removeImageInput();else{const e=t=>new Promise((e,i)=>{const s=new FileReader;s.readAsDataURL(t),s.onload=()=>{e(s.result)},s.onerror=t=>{i(t)}});this._imageInputPos=t,this._imageInputRef=document.createElement("input"),this._imageInputRef.style.display="none",this._imageInputRef.type="file",this._imageInputRef.accept="image/png, image/jpeg",this._imageInputRef.onchange=async t=>{const i=t.target.files[0],s=await e(i);this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,s.toString(),0,0)},this._imageInputRef.oncancel=()=>{this.removeImageInput()},document.body.appendChild(this._imageInputRef),setTimeout(()=>{this._imageInputRef.click()},50)}}removeImageInput(){var t;null===(t=this._imageInputRef)||void 0===t||t.remove(),this._imageInputRef=null,this._imageInputPos=null}addText(t,e,i,s,r,n,o){var a;if(!t)return;null===(a=this.getSelectedObjects().shift())||void 0===a||a.delete(),this.clearSelected(),this.removeTextInput();const h=1e-6;if(r&&r>h&&(!n||n<h)){const t=.02;n=r/(this._worldTransformer.getScale().y/t)/34}const l=new bi({position:{x:e.x,y:e.y},text:t,rotation:i,fontSize:n||this.fontSize,color:s||this._markupColor.asHex(),id:o},null,this._worldTransformer);return this.addObject(l),l}addRectangle(t,e,i,s,r,n,o){if(!t)return;const a=new Ci({position:t,position2:e,width:i,height:s,lineWidth:r||this.lineWidth,color:n||this._markupColor.asHex(),id:o},null,this._worldTransformer);return this.addObject(a),a}addEllipse(t,e,i,s,r,n,o){if(!t)return;const a=new Ai({position:t,position2:e,position3:i,radius:s,lineWidth:r,color:n||this._markupColor.asHex(),id:o},null,this._worldTransformer);return this.addObject(a),a}addArrow(t,e,i,s){if(!t||!e)return;const r=new ki({start:t,end:e,color:i||this._markupColor.asHex(),id:s},null,this._worldTransformer);return this.addObject(r),r}addCloud(t,e,i,s,r,n,o){if(!t||!i||!s)return;const a=new Mi({position:t,position2:e,width:i,height:s,color:n||this._markupColor.asHex(),lineWidth:r||this.lineWidth,id:o},null,this._worldTransformer);return this.addObject(a),a}addImage(t,e,i,s,r,n){var o;if(!t||!i)return;null===(o=this.getSelectedObjects().shift())||void 0===o||o.delete(),this.clearSelected(),this.removeImageInput();const a=new Pi({position:t,position2:e,src:i,width:s,height:r,maxWidth:this._konvaStage.width()-t.x,maxHeight:this._konvaStage.height()-t.y,id:n},null,this._worldTransformer);return this.addObject(a),a}}});
|
|
24
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ODA=t.ODA||{},t.ODA.Markup=t.ODA.Markup||{}))}(this,function(t){"use strict";const e=Math.PI/180;const i="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},s={_global:i,version:"10.0.12",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:t=>s.angleDeg?t*e: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,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>s.DD.isDragging,isTransforming(){var t,e;return null!==(e=null===(t=s.Transformer)||void 0===t?void 0:t.isTransforming())&&void 0!==e&&e},isDragReady:()=>!!s.DD.node,releaseCanvasOnDestroy:!0,document:i.document,_injectGlobal(t){void 0!==i.Konva&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),i.Konva=t}},r=t=>{s[t.prototype.getClassName()]=t};s._injectGlobal(s);const n=()=>{if("undefined"==typeof document)throw new Error('Konva.js unsupported environment.\n\nLooks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.\n\nTo use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module.\n\nbash: npm install canvas\njs: import "konva/canvas-backend";\n\nor\n\nbash: npm install skia-canvas\njs: import "konva/skia-backend";\n')};class o{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 o(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,r=this.m[1]*e+this.m[3]*i,n=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]=r,this.m[2]=n,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,r=this.m[2]+this.m[0]*t,n=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=r,this.m[3]=n,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],r=this.m[1]*t.m[2]+this.m[3]*t.m[3],n=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]=r,this.m[4]=n,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,r=this.m[0]*t,n=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]=r,this.m[4]=n,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],r=t*s-e*i,n={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){const o=Math.sqrt(t*t+e*e);n.rotation=e>0?Math.acos(t/o):-Math.acos(t/o),n.scaleX=o,n.scaleY=r/o,n.skewX=(t*i+e*s)/r,n.skewY=0}else if(0!=i||0!=s){const o=Math.sqrt(i*i+s*s);n.rotation=Math.PI/2-(s>0?Math.acos(-i/o):-Math.acos(i/o)),n.scaleX=r/o,n.scaleY=o,n.skewX=0,n.skewY=(t*i+e*s)/r}return n.rotation=_._getRotation(n.rotation),n}}const a=Math.PI/180,h=180/Math.PI,l="#",d="Konva error: ",c={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]},g=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let f=[],u=null;const p="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},_={_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){f.push(t),1===f.length&&p(function(){const t=f;f=[],t.forEach(function(t){t()})})},createCanvasElement(){n();const t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>(n(),document.createElement("img")),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){const i=_.createImageElement();i.onload=function(){e(i)},i.src=t},_rgbToHex:(t,e,i)=>((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1),_hexToRgb(t){t=t.replace(l,"");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 l+t},isCanvasFarblingActive(){if(null!==u)return u;if("undefined"==typeof document)return u=!1,!1;const t=this.createCanvasElement();t.width=10,t.height=10;const e=t.getContext("2d",{willReadFrequently:!0});e.clearRect(0,0,10,10),e.fillStyle="#282828",e.fillRect(0,0,10,10);const i=e.getImageData(0,0,10,10).data;let s=!1;for(let t=0;t<100;t++)if(40!==i[4*t]||40!==i[4*t+1]||40!==i[4*t+2]||255!==i[4*t+3]){s=!0;break}return u=s,this.releaseCanvas(t),u},getHitColor(){const t=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(t):t},getHitColorKey(t,e,i){return this.isCanvasFarblingActive()&&(t=5*Math.round(t/5),e=5*Math.round(e/5),i=5*Math.round(i/5)),l+this._rgbToHex(t,e,i)},getSnappedHexColor(t){const e=this._hexToRgb(t);return l+this._rgbToHex(5*Math.round(e.r/5),5*Math.round(e.g/5),5*Math.round(e.b/5))},getRGB(t){let e;return t in c?(e=c[t],{r:e[0],g:e[1],b:e[2]}):t[0]===l?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=g.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:t=>(t=t||"black",_._namedColorToRBA(t)||_._hex3ColorToRGBA(t)||_._hex4ColorToRGBA(t)||_._hex6ColorToRGBA(t)||_._hex8ColorToRGBA(t)||_._rgbColorToRGBA(t)||_._rgbaColorToRGBA(t)||_._hslColorToRGBA(t)),_namedColorToRBA(t){const e=c[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),s=Number(i[0])/360,r=Number(i[1])/100,n=Number(i[2])/100;let o,a,h;if(0===r)return h=255*n,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};o=n<.5?n*(1+r):n+r-n*r;const l=2*n-o,d=[0,0,0];for(let t=0;t<3;t++)a=s+1/3*-(t-1),a<0&&a++,a>1&&a--,h=6*a<1?l+6*(o-l)*a:2*a<1?o:3*a<2?l+(o-l)*(2/3-a)*6:l,d[t]=255*h;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[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*a,radToDeg:t=>t*h,_degToRad:t=>(_.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),_.degToRad(t)),_radToDeg:t=>(_.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),_.radToDeg(t)),_getRotation:t=>s.angleDeg?_.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(d+t)},error(t){console.error(d+t)},warn(t){s.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,s,r,n){let o,a,h;const l=(t-i)*(t-i)+(e-s)*(e-s);if(0==l)o=t,a=e,h=(r-i)*(r-i)+(n-s)*(n-s);else{const d=((r-t)*(i-t)+(n-e)*(s-e))/l;d<0?(o=t,a=e,h=(t-r)*(t-r)+(e-n)*(e-n)):d>1?(o=i,a=s,h=(i-r)*(i-r)+(s-n)*(s-n)):(o=t+d*(i-t),a=e+d*(s-e),h=(o-r)*(o-r)+(a-n)*(a-n))}return[o,a,h]},_getProjectionToLine(t,e,i){const s=_.cloneObject(t);let r=Number.MAX_VALUE;return e.forEach(function(n,o){if(!i&&o===e.length-1)return;const a=e[(o+1)%e.length],h=_._getProjectionToSegment(n.x,n.y,a.x,a.y,t.x,t.y),l=h[0],d=h[1],c=h[2];c<r&&(s.x=l,s.y=d,r=c)}),s},_prepareArrayForTween(t,e,i){const s=[],r=[];if(t.length>e.length){const i=e;e=t,t=i}for(let e=0;e<t.length;e+=2)s.push({x:t[e],y:t[e+1]});for(let t=0;t<e.length;t+=2)r.push({x:e[t],y:e[t+1]});const n=[];return r.forEach(function(t){const e=_._getProjectionToLine(t,s,i);n.push(e.x),n.push(e.y)}),n},_prepareToStringify(t){let e;t.visitedByCircularReferenceRemoval=!0;for(const i in t)if(t.hasOwnProperty(i)&&t[i]&&"object"==typeof t[i])if(e=Object.getOwnPropertyDescriptor(t,i),t[i].visitedByCircularReferenceRemoval||_._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===_._prepareToStringify(t[i])){if(!e.configurable)return null;delete t[i]}return delete t.visitedByCircularReferenceRemoval,t},_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){s.releaseCanvasOnDestroy&&t.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(t,e,i,s){let r=e<0?e:0,n=i<0?i:0;e=Math.abs(e),i=Math.abs(i);let o=0,a=0,h=0,l=0;"number"==typeof s?o=a=h=l=Math.min(s,e/2,i/2):(o=Math.min(s[0]||0,e/2,i/2),a=Math.min(s[1]||0,e/2,i/2),l=Math.min(s[2]||0,e/2,i/2),h=Math.min(s[3]||0,e/2,i/2)),t.moveTo(r+o,n),t.lineTo(r+e-a,n),t.arc(r+e-a,n+a,a,3*Math.PI/2,0,!1),t.lineTo(r+e,n+i-l),t.arc(r+e-l,n+i-l,l,0,Math.PI/2,!1),t.lineTo(r+h,n+i),t.arc(r+h,n+i-h,h,Math.PI/2,Math.PI,!1),t.lineTo(r,n+o),t.arc(r+o,n+o,o,Math.PI,3*Math.PI/2,!1)},drawRoundedPolygonPath(t,e,i,s,r){s=Math.abs(s);for(let n=0;n<i;n++){const o=e[(n-1+i)%i],a=e[n],h=e[(n+1)%i],l={x:a.x-o.x,y:a.y-o.y},d={x:h.x-a.x,y:h.y-a.y},c=Math.hypot(l.x,l.y),g=Math.hypot(d.x,d.y);let f;f="number"==typeof r?r:n<r.length?r[n]:0;f=s*Math.cos(Math.PI/i)*Math.min(1,f/s*2);const u={x:l.x/c,y:l.y/c},p={x:d.x/g,y:d.y/g},_={x:a.x-u.x*f,y:a.y-u.y*f},m={x:a.x+p.x*f,y:a.y+p.y*f};0===n?t.moveTo(_.x,_.y):t.lineTo(_.x,_.y),t.arcTo(a.x,a.y,m.x,m.y,f)}}};const m=["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 y,x=null;function v(){if(null!==x)return x;try{const t=_.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(x=!1,!1)}catch(t){return x=!1,!1}}class w{constructor(t){this.canvas=t,s.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,s,r,n,o=this.traceArr,a=o.length,h="";for(i=0;i<a;i++)s=o[i],r=s.method,r?(n=s.args,h+=r,t?h+="()":_._isArray(n[0])?h+="(["+n.join(",")+"])":(e&&(n=n.map(t=>"number"==typeof t?Math.floor(t):t)),h+="("+n.join(",")+")")):(h+=s.property,t||(h+="="+s.val)),h+=";";return h}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)}_applyMiterLimit(t){const e=t.attrs.miterLimit;null!=e&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,r,n){this._context.arc(t,e,i,s,r,n)}arcTo(t,e,i,s,r){this._context.arcTo(t,e,i,s,r)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,r,n){this._context.bezierCurveTo(t,e,i,s,r,n)}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;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}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,r,n){return this._context.createRadialGradient(t,e,i,s,r,n)}drawImage(t,e,i,s,r,n,o,a,h){const l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,s,r):9===l.length&&d.drawImage(t,e,i,s,r,n,o,a,h)}ellipse(t,e,i,s,r,n,o,a){this._context.ellipse(t,e,i,s,r,n,o,a)}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,r){this._context.roundRect(t,e,i,s,r)}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,r,n){this._context.setTransform(t,e,i,s,r,n)}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,r,n){this._context.transform(t,e,i,s,r,n)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t,e,i=this,s=m.length,r=this.setAttr;const n=function(t){let s,r=i[t];i[t]=function(){return e=function(t){const e=[],i=t.length,s=_;for(let r=0;r<i;r++){let i=t[r];s._isNumber(i)?i=Math.round(1e3*i)/1e3:s._isString(i)||(i+=""),e.push(i)}return e}(Array.prototype.slice.call(arguments,0)),s=r.apply(i,arguments),i._trace({method:t,args:e}),s}};for(t=0;t<s;t++)n(m[t]);i.setAttr=function(){r.apply(i,arguments);const t=arguments[0];let e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),i._trace({property:t,val:e})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||"source-over"===e||this.setAttr("globalCompositeOperation",e)}}["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"].forEach(function(t){Object.defineProperty(w.prototype,t,{get(){return this._context[t]},set(e){this._context[t]=e}})});class S extends w{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 s=t.getFillPatternImage();if(s&&"pattern"===i)return void this._fillPattern(t);const r=t.getFillLinearGradientColorStops();if(r&&"linear-gradient"===i)return void this._fillLinearGradient(t);const n=t.getFillRadialGradientColorStops();n&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):s?this._fillPattern(t):r?this._fillLinearGradient(t):n&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),r=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let t=0;t<s.length;t+=2)r.addColorStop(s[t],s[t+1]);this.setAttr("strokeStyle",r)}}_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,s;const r=null!==(e=t.getShadowRGBA())&&void 0!==e?e:"black",n=null!==(i=t.getShadowBlur())&&void 0!==i?i:5,o=null!==(s=t.getShadowOffset())&&void 0!==s?s:{x:0,y:0},a=t.getAbsoluteScale(),h=this.canvas.getPixelRatio(),l=a.x*h,d=a.y*h;this.setAttr("shadowColor",r),this.setAttr("shadowBlur",n*Math.min(Math.abs(l),Math.abs(d))),this.setAttr("shadowOffsetX",o.x*l),this.setAttr("shadowOffsetY",o.y*d)}}class b extends w{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(),s="auto"===i?t.strokeWidth():i;this.setAttr("lineWidth",s),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}}class C{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const e=(t||{}).pixelRatio||s.pixelRatio||function(){if(y)return y;const t=_.createCanvasElement(),e=t.getContext("2d");return y=(s._global.devicePixelRatio||1)/(e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1),_.releaseCanvas(t),y}();this.pixelRatio=e,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(t){try{return this._canvas.toDataURL()}catch(t){return _.error("Unable to get data URL. "+t.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class T extends C{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new S(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}class A extends C{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new b(this),this.setSize(t.width,t.height)}}const k={get isDragging(){let t=!1;return k._dragElements.forEach(e=>{"dragging"===e.dragStatus&&(t=!0)}),t},justDragged:!1,get node(){let t;return k._dragElements.forEach(e=>{t=e.node}),t},_dragElements:new Map,_drag(t){const e=[];k._dragElements.forEach((i,s)=>{const{node:r}=i,n=r.getStage();n.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=_._getFirstPointerId(t));const o=n._changedPointerPositions.find(t=>t.id===i.pointerId);if(o){if("dragging"!==i.dragStatus){const e=r.dragDistance();if(Math.max(Math.abs(o.x-i.startPointerPos.x),Math.abs(o.y-i.startPointerPos.y))<e)return;if(r.startDrag({evt:t}),!r.isDragging())return}r._setDragPosition(t,i),e.push(r)}}),e.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)})},_endDragBefore(t){const e=[];k._dragElements.forEach(i=>{const{node:r}=i,n=r.getStage();t&&n.setPointersPositions(t);if(!n._changedPointerPositions.find(t=>t.id===i.pointerId))return;"dragging"!==i.dragStatus&&"stopped"!==i.dragStatus||(k.justDragged=!0,s._mouseListenClick=!1,s._touchListenClick=!1,s._pointerListenClick=!1,i.dragStatus="stopped");const o=i.node.getLayer()||i.node instanceof s.Stage&&i.node;o&&-1===e.indexOf(o)&&e.push(o)}),e.forEach(t=>{t.draw()})},_endDragAfter(t){k._dragElements.forEach((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&k._dragElements.delete(i)})}};function P(t){return _._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||_._isBoolean(t)?t:Object.prototype.toString.call(t)}function M(t){return t>255?255:t<0?0:Math.round(t)}function R(){if(s.isUnminified)return function(t,e){return _._isNumber(t)||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function I(t){if(s.isUnminified)return function(e,i){let s=_._isNumber(e),r=_._isArray(e)&&e.length==t;return s||r||_.warn(P(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array<number>('+t+")"),e}}function E(){if(s.isUnminified)return function(t,e){return _._isNumber(t)||"auto"===t||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function L(){if(s.isUnminified)return function(t,e){return _._isString(t)||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function G(){if(s.isUnminified)return function(t,e){const i=_._isString(t),s="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||s||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function O(){if(s.isUnminified)return function(t,e){return!0===t||!1===t||_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}s.isBrowser&&(window.addEventListener("mouseup",k._endDragBefore,!0),window.addEventListener("touchend",k._endDragBefore,!0),window.addEventListener("touchcancel",k._endDragBefore,!0),window.addEventListener("mousemove",k._drag),window.addEventListener("touchmove",k._drag),window.addEventListener("mouseup",k._endDragAfter,!1),window.addEventListener("touchend",k._endDragAfter,!1),window.addEventListener("touchcancel",k._endDragAfter,!1));const D="get",F="set",W={addGetterSetter(t,e,i,s,r){W.addGetter(t,e,i),W.addSetter(t,e,s,r),W.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){const s=D+_._capitalize(e);t.prototype[s]=t.prototype[s]||function(){const t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,s){const r=F+_._capitalize(e);t.prototype[r]||W.overWriteSetter(t,e,i,s)},overWriteSetter(t,e,i,s){const r=F+_._capitalize(e);t.prototype[r]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),s&&s.call(this),this}},addComponentsGetterSetter(t,e,i,r,n){const o=i.length,a=_._capitalize,h=D+a(e),l=F+a(e);t.prototype[h]=function(){const t={};for(let s=0;s<o;s++){const r=i[s];t[r]=this.getAttr(e+a(r))}return t};const d=function(t){if(s.isUnminified)return function(e,i){return null==e||_.isObject(e)||_.warn(P(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}}(i);t.prototype[l]=function(t){const s=this.attrs[e];r&&(t=r.call(this,t,e)),d&&d.call(this,t,e);for(const i in t)t.hasOwnProperty(i)&&this._setAttr(e+a(i),t[i]);return t||i.forEach(t=>{this._setAttr(e+a(t),void 0)}),this._fireChangeEvent(e,s,t),n&&n.call(this),this},W.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){const i=_._capitalize(e),s=F+i,r=D+i;t.prototype[e]=function(){return arguments.length?(this[s](arguments[0]),this):this[r]()}},addDeprecatedGetterSetter(t,e,i,s){_.error("Adding deprecated "+e);const r=D+_._capitalize(e),n=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[r]=function(){_.error(n);const t=this.attrs[e];return void 0===t?i:t},W.addSetter(t,e,s,function(){_.error(n)}),W.addOverloadedGetterSetter(t,e)},backCompat(t,e){_.each(e,function(e,i){const s=t.prototype[i],r=D+_._capitalize(e),n=F+_._capitalize(e);function o(){s.apply(this,arguments),_.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=o,t.prototype[r]=o,t.prototype[n]=o})},afterSetFilter(){this._filterUpToDate=!1}};function B(t){const e=/(\w+)\(([^)]+)\)/g;let i;for(;null!==(i=e.exec(t));){const[,t,e]=i;switch(t){case"blur":{const t=parseFloat(e.replace("px",""));return function(e){this.blurRadius(.5*t);const i=s.Filters;i&&i.Blur&&i.Blur.call(this,e)}}case"brightness":{const t=e.includes("%")?parseFloat(e)/100:parseFloat(e);return function(e){this.brightness(t);const i=s.Filters;i&&i.Brightness&&i.Brightness.call(this,e)}}case"contrast":{const t=parseFloat(e);return function(e){const i=100*(Math.sqrt(t)-1);this.contrast(i);const r=s.Filters;r&&r.Contrast&&r.Contrast.call(this,e)}}case"grayscale":return function(t){const e=s.Filters;e&&e.Grayscale&&e.Grayscale.call(this,t)};case"sepia":return function(t){const e=s.Filters;e&&e.Sepia&&e.Sepia.call(this,t)};case"invert":return function(t){const e=s.Filters;e&&e.Invert&&e.Invert.call(this,t)};default:_.warn(`CSS filter "${t}" is not supported in fallback mode. Consider using function filters for better compatibility.`)}}return()=>{}}const N="absoluteOpacity",z="allEventListeners",H="absoluteTransform",X="absoluteScale",Y="canvas",j="listening",U="Shape",q=" ",K="stage",V="transform",Q="visible",J=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(q);let Z=1;class ${constructor(t){this._id=Z++,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!==V&&t!==H||!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===V||t===H)&&!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(q);this.on(i,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(Y)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===H&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(Y)){const{scene:t,filter:e,hit:i,buffer:s}=this._cache.get(Y);_.releaseCanvas(t,e,i,s),this._cache.delete(Y)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),r=Math.ceil(e.height||i.height),n=e.pixelRatio,o=void 0===e.x?Math.floor(i.x):e.x,a=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(!s||!r)return void _.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");s+=2*h+(Math.abs(Math.round(i.x)-o)>.5?1:0),r+=2*h+(Math.abs(Math.round(i.y)-a)>.5?1:0),o-=h,a-=h;const c=new T({pixelRatio:n,width:s,height:r}),g=new T({pixelRatio:n,width:0,height:0,willReadFrequently:!0}),f=new A({pixelRatio:d,width:s,height:r}),u=c.getContext(),p=f.getContext(),m=new T({width:c.width/c.pixelRatio+Math.abs(o),height:c.height/c.pixelRatio+Math.abs(a),pixelRatio:c.pixelRatio}),y=m.getContext();return f.isCache=!0,c.isCache=!0,this._cache.delete(Y),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,g.getContext()._context.imageSmoothingEnabled=!1),u.save(),p.save(),y.save(),u.translate(-o,-a),p.translate(-o,-a),y.translate(-o,-a),m.x=o,m.y=a,this._isUnderCache=!0,this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(X),this.drawScene(c,this,m),this.drawHit(f,this),this._isUnderCache=!1,u.restore(),p.restore(),l&&(u.save(),u.beginPath(),u.rect(0,0,s,r),u.closePath(),u.setAttr("strokeStyle","red"),u.setAttr("lineWidth",5),u.stroke(),u.restore()),this._cache.set(Y,{scene:c,filter:g,hit:f,buffer:m,x:o,y:a}),this._requestDraw(),this}isCached(){return this._cache.has(Y)}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,r=1/0,n=-1/0,o=-1/0;const a=this.getAbsoluteTransform(e);return i.forEach(function(t){const e=a.point(t);void 0===s&&(s=n=e.x,r=o=e.y),s=Math.min(s,e.x),r=Math.min(r,e.y),n=Math.max(n,e.x),o=Math.max(o,e.y)}),{x:s,y:r,width:n-s,height:o-r}}_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,e,i,s,r=this.filters(),n=this._getCanvasCache(),o=n.scene,a=n.filter,h=a.getContext();if(!r||0===r.length)return o;if(this._filterUpToDate)return a;let l=!0;for(let t=0;t<r.length;t++)if("string"==typeof r[t]&&v(),"string"!=typeof r[t]||!v()){l=!1;break}const d=o.pixelRatio;if(a.setSize(o.width/o.pixelRatio,o.height/o.pixelRatio),l){const t=r.join(" ");return h.save(),h.setAttr("filter",t),h.drawImage(o._canvas,0,0,o.getWidth()/d,o.getHeight()/d),h.restore(),this._filterUpToDate=!0,a}try{for(t=r.length,h.clear(),h.drawImage(o._canvas,0,0,o.getWidth()/d,o.getHeight()/d),e=h.getImageData(0,0,a.getWidth(),a.getHeight()),i=0;i<t;i++)s=r[i],"string"==typeof s&&(s=B(s)),s.call(this,e),h.putImageData(e,0,0)}catch(t){_.error("Unable to apply filter. "+t.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,a}on(t,e){if(this._cache&&this._cache.delete(z),3===arguments.length)return this._delegate.apply(this,arguments);const i=t.split(q);for(let t=0;t<i.length;t++){const s=i[t].split("."),r=s[0],n=s[1]||"";this.eventListeners[r]||(this.eventListeners[r]=[]),this.eventListeners[r].push({name:n,handler:e})}return this}off(t,e){let i,s,r,n,o,a,h=(t||"").split(q),l=h.length;if(this._cache&&this._cache.delete(z),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<l;i++)if(r=h[i],n=r.split("."),o=n[0],a=n[1],o)this.eventListeners[o]&&this._off(o,a,e);else for(s in this.eventListeners)this._off(s,a,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 s=this;this.on(t,function(t){const r=t.target.findAncestors(e,!0,s);for(let e=0;e<r.length;e++)(t=_.cloneObject(t)).currentTarget=r[e],i.call(r[e],t)})}remove(){return this.isDragging()&&this.stopDrag(),k._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(H),this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(X),this._clearSelfAndDescendantCache(K),this._clearSelfAndDescendantCache(Q),this._clearSelfAndDescendantCache(j)}_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)"children"!==e&&(i="set"+_._capitalize(e),_._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(j,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(Q,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const i=this.getLayer();let r=!1;k._dragElements.forEach(t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===i)&&(r=!0)});const n=!e&&!s.hitOnDragEnabled&&(r||s.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,e,i,s,r=this.getDepth(),n=this,o=0;const a=this.getStage();return"Stage"!==n.nodeType&&a&&function a(h){for(t=[],e=h.length,i=0;i<e;i++)s=h[i],o++,s.nodeType!==U&&(t=t.concat(s.getChildren().slice())),s._id===n._id&&(i=e);t.length>0&&t[0].getDepth()<=r&&a(t)}(a.getChildren()),o}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(V),this._clearSelfAndDescendantCache(H)),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(),r=new o,n=this.offset();return r.m=s.slice(),r.translate(n.x,n.y),r.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(V);const r=this._getAbsoluteTransform().copy();return r.invert(),r.translate(t.x,t.y),t={x:this.attrs.x+r.getTranslation().x,y:this.attrs.y+r.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(V),this._clearSelfAndDescendantCache(H),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(),r=this.y();return void 0!==e&&(s+=e),void 0!==i&&(r+=i),this.setPosition({x:s,y:r}),this}_eachAncestorReverse(t,e){let i,s,r=[],n=this.getParent();if(!e||e._id!==this._id){for(r.unshift(this);n&&(!e||n._id!==e._id);)r.unshift(n),n=n.parent;for(i=r.length,s=0;s<i;s++)t(r[s])}}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;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 _.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 _.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 _.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 _.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(N,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,s,r,n=this.getAttrs();const o={attrs:{},className:this.getClassName()};for(t in n)e=n[t],r=_.isObject(e)&&!_._isPlainObject(e)&&!_._isArray(e),r||(i="function"==typeof this[t]&&this[t],delete n[t],s=i?i.call(this):null,n[t]=e,s!==e&&(o.attrs[t]=e));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 r=this.parent;for(;r;){if(r===i)return s;r._isMatch(t)&&s.push(r),r=r.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("function"==typeof t)return t(this);let e,i,s=t.replace(/ /g,"").split(","),r=s.length;for(e=0;e<r;e++)if(i=s[e],_.isValidSelector(i)||(_.warn('Selector "'+i+'" 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?")),"#"===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(K,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(H,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new o,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(H)||new o,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,s=this.attrs.offsetX||0,r=this.attrs.offsetY||0;e.translate(t-s,i-r)}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(V,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(V)||new o;i.reset();const r=this.x(),n=this.y(),a=s.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,d=this.attrs.skewX||0,c=this.attrs.skewY||0,g=this.attrs.offsetX||0,f=this.attrs.offsetY||0;return 0===r&&0===n||i.translate(r,n),0!==a&&i.rotate(a),0===d&&0===c||i.skew(d,c),1===h&&1===l||i.scale(h,l),0===g&&0===f||i.translate(-1*g,-1*f),i.dirty=!1,i}clone(t){let e,i,s,r,n,o=_.cloneObject(this.attrs);for(e in t)o[e]=t[e];const a=new this.constructor(o);for(e in this.eventListeners)for(i=this.eventListeners[e],s=i.length,r=0;r<s;r++)n=i[r],n.name.indexOf("konva")<0&&(a.eventListeners[e]||(a.eventListeners[e]=[]),a.eventListeners[e].push(n));return a}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=void 0!==t.x?t.x:Math.floor(e.x),r=void 0!==t.y?t.y:Math.floor(e.y),n=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:n}),a=o.getContext(),h=new T({width:o.width/o.pixelRatio+Math.abs(s),height:o.height/o.pixelRatio+Math.abs(r),pixelRatio:o.pixelRatio});return!1===t.imageSmoothingEnabled&&(a._context.imageSmoothingEnabled=!1),a.save(),(s||r)&&a.translate(-1*s,-1*r),this.drawScene(o,void 0,h),a.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){const e=(t=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 i=null==t?void 0:t.callback;i&&delete t.callback,_._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():s.dragDistance}_off(t,e,i){let s,r,n,o=this.eventListeners[t];for(s=0;s<o.length;s++)if(r=o[s].name,n=o[s].handler,!("konva"===r&&"konva"!==e||e&&r!==e||i&&i!==n)){if(o.splice(s,1),0===o.length){delete this.eventListeners[t];break}s--}}_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"+_._capitalize(t)];return _._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(s.autoDrawEnabled){const t=this.getLayer()||this.getStage();null==t||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];(i!==e||_.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 s;void 0!==i&&(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===U&&(e.target=this);const s=["mouseenter","mouseleave","pointerenter","pointerleave","touchenter","touchleave"];if(!(-1!==s.indexOf(t)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);const r=-1!==s.indexOf(t)&&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,s;const r=null!==(e=this._cache.get(z))&&void 0!==e?e:{};let n=null==r?void 0:r[t];if(void 0===n){n=[];let e=Object.getPrototypeOf(this);for(;e;){const r=null!==(s=null===(i=e.eventListeners)||void 0===i?void 0:i[t])&&void 0!==s?s:[];n.push(...r),e=Object.getPrototypeOf(e)}r[t]=n,this._cache.set(z,r)}return n}_fire(t,e){(e=e||{}).currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let t=0;t<i.length;t++)i[t].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let t=0;t<s.length;t++)s[t].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 r=i._getPointerById(e)||i._changedPointerPositions[0]||s;k._dragElements.set(this._id,{node:this,startPointerPos:r,offset:{x:r.x-s.x,y:r.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){k._dragElements.has(this._id)||this._createDragElement(t);k._dragElements.get(this._id).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 r=this.dragBoundFunc();if(void 0!==r){const e=r.call(this,s,t);e?s=e:_.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=k._dragElements.get(this._id);e&&(e.dragStatus="stopped"),k._endDragBefore(t),k._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=k._dragElements.get(this._id);return!!t&&"dragging"===t.dragStatus}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(void 0!==t.evt.button)||s.dragButtons.indexOf(t.evt.button)>=0))return;if(this.isDragging())return;let e=!1;k._dragElements.forEach(t=>{this.isAncestorOf(t.node)&&(e=!0)}),e||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();if(!this.getStage())return;const t=k._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&k._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,r,n,o=$.prototype.getClassName.call(t),a=t.children;e&&(t.attrs.container=e),s[o]||(_.warn('Can not find a node with class name "'+o+'". Fallback to "Shape".'),o="Shape");if(i=new(0,s[o])(t.attrs),a)for(r=a.length,n=0;n<r;n++)i.add($._createNode(a[n]));return i}}$.prototype.nodeType="Node",$.prototype._attrsAffectingSize=[],$.prototype.eventListeners={},$.prototype.on.call($.prototype,J,function(){this._batchingTransformChange?this._needClearTransformCache=!0:(this._clearCache(V),this._clearSelfAndDescendantCache(H))}),$.prototype.on.call($.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(Q)}),$.prototype.on.call($.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(j)}),$.prototype.on.call($.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(N)});const tt=W.addGetterSetter;tt($,"zIndex"),tt($,"absolutePosition"),tt($,"position"),tt($,"x",0,R()),tt($,"y",0,R()),tt($,"globalCompositeOperation","source-over",L()),tt($,"opacity",1,R()),tt($,"name","",L()),tt($,"id","",L()),tt($,"rotation",0,R()),W.addComponentsGetterSetter($,"scale",["x","y"]),tt($,"scaleX",1,R()),tt($,"scaleY",1,R()),W.addComponentsGetterSetter($,"skew",["x","y"]),tt($,"skewX",0,R()),tt($,"skewY",0,R()),W.addComponentsGetterSetter($,"offset",["x","y"]),tt($,"offsetX",0,R()),tt($,"offsetY",0,R()),tt($,"dragDistance",void 0,R()),tt($,"width",0,R()),tt($,"height",0,R()),tt($,"listening",!0,O()),tt($,"preventDefault",!0,O()),tt($,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),tt($,"visible",!0,O()),tt($,"transformsEnabled","all",L()),tt($,"size"),tt($,"dragBoundFunc"),tt($,"draggable",!1,O()),W.backCompat($,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class et extends ${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(0===t.length)return this;if(t.length>1){for(let e=0;e<t.length;e++)this.add(t[e]);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 r=s._isMatch(t);return r&&i.push(s),!(!r||!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=$.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=$.prototype.clone.call(this,t);return this.getChildren().forEach(function(t){e.add(t.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()||null===(e=this.children)||void 0===e||e.forEach(function(e){e._clearSelfAndDescendantCache(t)})}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach(function(t,e){t.index=e}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas(),n=r&&r.getContext(),o=this._getCanvasCache(),a=o&&o.scene,h=r&&r.isCache;if(!this.isVisible()&&!h)return this;if(a){n.save();const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(n),n.restore()}else this._drawChildren("drawScene",r,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,r=s&&s.getContext(),n=this._getCanvasCache();if(n&&n.hit){r.save();const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(r),r.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var r;const n=e&&e.getContext(),o=this.clipWidth(),a=this.clipHeight(),h=this.clipFunc(),l="number"==typeof o&&"number"==typeof a||h,d=i===this;if(l){n.save();const t=this.getAbsoluteTransform(i);let e,s=t.getMatrix();if(n.transform(s[0],s[1],s[2],s[3],s[4],s[5]),n.beginPath(),h)e=h.call(this,n,this);else{const t=this.clipX(),e=this.clipY();n.rect(t||0,e||0,o,a)}n.clip.apply(n,e),s=t.copy().invert().getMatrix(),n.transform(s[0],s[1],s[2],s[3],s[4],s[5])}const c=!d&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;c&&(n.save(),n._applyGlobalCompositeOperation(this)),null===(r=this.children)||void 0===r||r.forEach(function(r){r[t](e,i,s)}),c&&n.restore(),l&&n.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let r,n,o,a,h={x:1/0,y:1/0,width:0,height:0};const l=this;null===(e=this.children)||void 0===e||e.forEach(function(e){if(!e.visible())return;const i=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===i.width&&0===i.height||(void 0===r?(r=i.x,n=i.y,o=i.x+i.width,a=i.y+i.height):(r=Math.min(r,i.x),n=Math.min(n,i.y),o=Math.max(o,i.x+i.width),a=Math.max(a,i.y+i.height)))});const d=this.find("Shape");let c=!1;for(let t=0;t<d.length;t++){if(d[t]._isVisible(this)){c=!0;break}}return h=c&&void 0!==r?{x:r,y:n,width:o-r,height:a-n}:{x:0,y:0,width:0,height:0},i?h:this._transformedRect(h,s)}}W.addComponentsGetterSetter(et,"clip",["x","y","width","height"]),W.addGetterSetter(et,"clipX",void 0,R()),W.addGetterSetter(et,"clipY",void 0,R()),W.addGetterSetter(et,"clipWidth",void 0,R()),W.addGetterSetter(et,"clipHeight",void 0,R()),W.addGetterSetter(et,"clipFunc");const it=new Map,st=void 0!==s._global.PointerEvent;function rt(t){return it.get(t)}function nt(t){return{evt:t,pointerId:t.pointerId}}function ot(t,e){return it.get(t)===e}function at(t,e){ht(t);e.getStage()&&(it.set(t,e),st&&e._fire("gotpointercapture",nt(new PointerEvent("gotpointercapture"))))}function ht(t,e){const i=it.get(t);if(!i)return;const s=i.getStage();s&&s.content,it.delete(t),st&&i._fire("lostpointercapture",nt(new PointerEvent("lostpointercapture")))}const lt="mouseleave",dt="mouseover",ct="mouseenter",gt="mousemove",ft="mousedown",ut="mouseup",pt="pointermove",_t="pointerdown",mt="pointerup",yt="pointercancel",xt="pointerout",vt="pointerleave",wt="pointerover",St="pointerenter",bt="contextmenu",Ct="touchstart",Tt="touchend",At="touchmove",kt="touchcancel",Pt="wheel",Mt=[[ct,"_pointerenter"],[ft,"_pointerdown"],[gt,"_pointermove"],[ut,"_pointerup"],[lt,"_pointerleave"],[Ct,"_pointerdown"],[At,"_pointermove"],[Tt,"_pointerup"],[kt,"_pointercancel"],[dt,"_pointerover"],[Pt,"_wheel"],[bt,"_contextmenu"],[_t,"_pointerdown"],[pt,"_pointermove"],[mt,"_pointerup"],[yt,"_pointercancel"],[vt,"_pointerleave"],["lostpointercapture","_lostpointercapture"]],Rt={mouse:{[xt]:"mouseout",[vt]:lt,[wt]:dt,[St]:ct,[pt]:gt,[_t]:ft,[mt]:ut,[yt]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[xt]:"touchout",[vt]:"touchleave",[wt]:"touchover",[St]:"touchenter",[pt]:At,[_t]:Ct,[mt]:Tt,[yt]:kt,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[xt]:xt,[vt]:vt,[wt]:wt,[St]:St,[pt]:pt,[_t]:_t,[mt]:mt,[yt]:yt,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},It=t=>t.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",Et=t=>{const e=It(t);return"pointer"===e?s.pointerEventsEnabled&&Rt.pointer:"touch"===e?Rt.touch:"mouse"===e?Rt.mouse:void 0};function Lt(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&_.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const Gt=[];class Ot extends et{constructor(t){super(Lt(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),Gt.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{Lt(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();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("string"==typeof t){let e;if("."===t.charAt(0)){const e=t.slice(1);t=document.getElementsByClassName(e)[0]}else e="#"!==t.charAt(0)?t: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="undefined"!=typeof document&&document.createElement("div"),et.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&_._isInDocument(t)&&this.container().removeChild(t);const e=Gt.indexOf(this);return e>-1&&Gt.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("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);"),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}).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(e){if(!e.isVisible())return;const s=e._toKonvaCanvas(t);i.drawImage(s._canvas,t.x,t.y,s.getWidth()/s.getPixelRatio(),s.getHeight()/s.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children;for(let i=e.length-1;i>=0;i--){const s=e[i].getIntersection(t);if(s)return s}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),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 t=0;t<arguments.length;t++)this.add(arguments[t]);return this}super.add(t);const i=this.children.length;return i>5&&_.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(),s.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return ot(t,this)}setPointerCapture(t){at(t,this)}releaseCapture(t){ht(t)}getLayers(){return this.children}_bindContentEvents(){s.isBrowser&&Mt.forEach(([t,e])=>{this.content.addEventListener(t,t=>{this[e](t)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=Et(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Et(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=Et(t.type),i=It(t.type);if(!e)return;this.setPointersPositions(t);const r=this._getTargetShape(i),n=!(s.isDragging()||s.isTransforming())||s.hitOnDragEnabled;r&&n?(r._fireAndBubble(e.pointerout,{evt:t}),r._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=Et(t.type),i=It(t.type);if(!e)return;this.setPointersPositions(t);let r=!1;this._changedPointerPositions.forEach(n=>{const o=this.getIntersection(n);if(k.justDragged=!1,s["_"+i+"ListenClick"]=!0,!o||!o.isListening())return void(this[i+"ClickStartShape"]=void 0);s.capturePointerEventsEnabled&&o.setPointerCapture(n.id),this[i+"ClickStartShape"]=o,o._fireAndBubble(e.pointerdown,{evt:t,pointerId:n.id}),r=!0;const a=t.type.indexOf("touch")>=0;o.preventDefault()&&t.cancelable&&a&&t.preventDefault()}),r||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=Et(t.type),i=It(t.type);if(!e)return;const r=t.type.indexOf("touch")>=0||"touch"===t.pointerType;s.isDragging()&&k.node.preventDefault()&&t.cancelable&&r&&t.preventDefault(),this.setPointersPositions(t);if(!(!(s.isDragging()||s.isTransforming())||s.hitOnDragEnabled))return;const n={};let o=!1;const a=this._getTargetShape(i);this._changedPointerPositions.forEach(s=>{const r=rt(s.id)||this.getIntersection(s),h=s.id,l={evt:t,pointerId:h},d=a!==r;if(d&&a&&(a._fireAndBubble(e.pointerout,{...l},r),a._fireAndBubble(e.pointerleave,{...l},r)),r){if(n[r._id])return;n[r._id]=!0}r&&r.isListening()?(o=!0,d&&(r._fireAndBubble(e.pointerover,{...l},a),r._fireAndBubble(e.pointerenter,{...l},a),this[i+"targetShape"]=r),r._fireAndBubble(e.pointermove,{...l})):a&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[i+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Et(t.type),i=It(t.type);if(!e)return;this.setPointersPositions(t);const r=this[i+"ClickStartShape"],n=this[i+"ClickEndShape"],o={};let a=!1;this._changedPointerPositions.forEach(h=>{const l=rt(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),o[l._id])return;o[l._id]=!0}const d=h.id,c={evt:t,pointerId:d};let g=!1;s["_"+i+"InDblClickWindow"]?(g=!0,clearTimeout(this[i+"DblTimeout"])):k.justDragged||(s["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){s["_"+i+"InDblClickWindow"]=!1},s.dblClickWindow),l&&l.isListening()?(a=!0,this[i+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...c}),s["_"+i+"ListenClick"]&&r&&r===l&&(l._fireAndBubble(e.pointerclick,{...c}),g&&n&&n===l&&l._fireAndBubble(e.pointerdblclick,{...c}))):(this[i+"ClickEndShape"]=null,a||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),a=!0),s["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),g&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))}),a||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),s["_"+i+"ListenClick"]=!1,t.cancelable&&"touch"!==i&&"pointer"!==i&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(bt,{evt:t}):this._fire(bt,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Pt,{evt:t}):this._fire(Pt,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=rt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(mt,nt(t)),ht(t.pointerId)}_lostpointercapture(t){ht(t.pointerId)}setPointersPositions(t){const e=this._getContentPosition();let i=null,s=null;void 0!==(t=t||window.event).touches?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,t=>{this._pointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,t=>{this._changedPointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.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 A({pixelRatio:1,width:this.width(),height:this.height()}),!s.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}}Ot.prototype.nodeType="Stage",r(Ot),W.addGetterSetter(Ot,"container"),s.isBrowser&&document.addEventListener("visibilitychange",()=>{Gt.forEach(t=>{t.batchDraw()})});const Dt="hasShadow",Ft="shadowRGBA",Wt="patternImage",Bt="linearGradient",Nt="radialGradient";let zt;function Ht(){return zt||(zt=_.createCanvasElement().getContext("2d"),zt)}const Xt={};class Yt extends ${constructor(t){let e;super(t);let i=0;for(;e=_.getHitColor(),!e||e in Xt;)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,Xt[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(Dt,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Wt,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=Ht().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new o;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(s.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const i=e.getMatrix(),r="undefined"==typeof DOMMatrix?{a:i[0],b:i[1],c:i[2],d:i[3],e:i[4],f:i[5]}:new DOMMatrix(i);t.setTransform(r)}return t}}_getLinearGradient(){return this._getCache(Bt,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=Ht(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),r=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}_getRadialGradient(){return this._getCache(Nt,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=Ht(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),r=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}getShadowRGBA(){return this._getCache(Ft,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=_.colorToRGBA(this.shadowColor());return t?"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")":void 0}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"auto"===t?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){const e=this.getStage();if(!e)return!1;const i=e.bufferHitCanvas;i.getContext().clear(),this.drawHit(i,void 0,!0);return i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return $.prototype.destroy.call(this),delete Xt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),s=this.hasStroke(),r=1!==this.getAbsoluteOpacity();if(i&&s&&r)return!0;const n=this.hasShadow(),o=this.shadowForStrokeEnabled();return!!(i&&s&&n&&o)}setStrokeHitEnabled(t){_.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}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,r=t.relativeTo||e&&this.getStage()||void 0,n=this.getSelfRect(),o=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,a=n.width+o,h=n.height+o,l=!t.skipShadow&&this.hasShadow(),d=l?this.shadowOffsetX():0,c=l?this.shadowOffsetY():0,g=a+Math.abs(d),f=h+Math.abs(c),u=l&&this.shadowBlur()||0,p={width:g+2*u,height:f+2*u,x:-(o/2+u)+Math.min(d,0)+n.x,y:-(o/2+u)+Math.min(c,0)+n.y};return s?p:this._transformedRect(p,r)}drawScene(t,e,i){const s=this.getLayer(),r=(t||s.getCanvas()).getContext(),n=this._getCanvasCache(),o=this.getSceneFunc(),a=this.hasShadow();let h;const l=e===this;if(!this.isVisible()&&!l)return this;if(n){r.save();const t=this.getAbsoluteTransform(e).getMatrix();return r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(r),r.restore(),this}if(!o)return this;if(r.save(),this._useBufferCanvas()){h=this.getStage();const t=i||h.bufferCanvas,s=t.getContext();s.clear(),s.save(),s._applyLineJoin(this),s._applyMiterLimit(this);const n=this.getAbsoluteTransform(e).getMatrix();s.transform(n[0],n[1],n[2],n[3],n[4],n[5]),o.call(this,s,this),s.restore();const d=t.pixelRatio;a&&r._applyShadow(this),l||(r._applyOpacity(this),r._applyGlobalCompositeOperation(this)),r.drawImage(t._canvas,t.x||0,t.y||0,t.width/d,t.height/d)}else{if(r._applyLineJoin(this),r._applyMiterLimit(this),!l){const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),r._applyOpacity(this),r._applyGlobalCompositeOperation(this)}a&&r._applyShadow(this),o.call(this,r,this)}return r.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),r=t||s.hitCanvas,n=r&&r.getContext(),o=this.hitFunc()||this.sceneFunc(),a=this._getCanvasCache(),h=a&&a.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()"),h){n.save();const t=this.getAbsoluteTransform(e).getMatrix();return n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(n),n.restore(),this}if(!o)return this;n.save(),n._applyLineJoin(this),n._applyMiterLimit(this);if(!(this===e)){const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return o.call(this,n,this),n.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,r=s.getContext(),n=s.getWidth(),o=s.getHeight();r.clear(),r.drawImage(i._canvas,0,0,n,o);try{const e=r.getImageData(0,0,n,o),i=e.data,s=i.length,a=_._hexToRgb(this.colorKey);for(let e=0;e<s;e+=4){i[e+3]>t?(i[e]=a.r,i[e+1]=a.g,i[e+2]=a.b,i[e+3]=255):i[e+3]=0}r.putImageData(e,0,0)}catch(t){_.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}hasPointerCapture(t){return ot(t,this)}setPointerCapture(t){at(t,this)}releaseCapture(t){ht(t)}}Yt.prototype._fillFunc=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},Yt.prototype._strokeFunc=function(t){t.stroke()},Yt.prototype._fillFuncHit=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},Yt.prototype._strokeFuncHit=function(t){t.stroke()},Yt.prototype._centroid=!1,Yt.prototype.nodeType="Shape",r(Yt),Yt.prototype.eventListeners={},Yt.prototype.on.call(Yt.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(Dt)}),Yt.prototype.on.call(Yt.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(Ft)}),Yt.prototype.on.call(Yt.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",function(){this._clearCache(Wt)}),Yt.prototype.on.call(Yt.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",function(){this._clearCache(Bt)}),Yt.prototype.on.call(Yt.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",function(){this._clearCache(Nt)}),W.addGetterSetter(Yt,"stroke",void 0,G()),W.addGetterSetter(Yt,"strokeWidth",2,R()),W.addGetterSetter(Yt,"fillAfterStrokeEnabled",!1),W.addGetterSetter(Yt,"hitStrokeWidth","auto",E()),W.addGetterSetter(Yt,"strokeHitEnabled",!0,O()),W.addGetterSetter(Yt,"perfectDrawEnabled",!0,O()),W.addGetterSetter(Yt,"shadowForStrokeEnabled",!0,O()),W.addGetterSetter(Yt,"lineJoin"),W.addGetterSetter(Yt,"lineCap"),W.addGetterSetter(Yt,"miterLimit"),W.addGetterSetter(Yt,"sceneFunc"),W.addGetterSetter(Yt,"hitFunc"),W.addGetterSetter(Yt,"dash"),W.addGetterSetter(Yt,"dashOffset",0,R()),W.addGetterSetter(Yt,"shadowColor",void 0,L()),W.addGetterSetter(Yt,"shadowBlur",0,R()),W.addGetterSetter(Yt,"shadowOpacity",1,R()),W.addComponentsGetterSetter(Yt,"shadowOffset",["x","y"]),W.addGetterSetter(Yt,"shadowOffsetX",0,R()),W.addGetterSetter(Yt,"shadowOffsetY",0,R()),W.addGetterSetter(Yt,"fillPatternImage"),W.addGetterSetter(Yt,"fill",void 0,G()),W.addGetterSetter(Yt,"fillPatternX",0,R()),W.addGetterSetter(Yt,"fillPatternY",0,R()),W.addGetterSetter(Yt,"fillLinearGradientColorStops"),W.addGetterSetter(Yt,"strokeLinearGradientColorStops"),W.addGetterSetter(Yt,"fillRadialGradientStartRadius",0),W.addGetterSetter(Yt,"fillRadialGradientEndRadius",0),W.addGetterSetter(Yt,"fillRadialGradientColorStops"),W.addGetterSetter(Yt,"fillPatternRepeat","repeat"),W.addGetterSetter(Yt,"fillEnabled",!0),W.addGetterSetter(Yt,"strokeEnabled",!0),W.addGetterSetter(Yt,"shadowEnabled",!0),W.addGetterSetter(Yt,"dashEnabled",!0),W.addGetterSetter(Yt,"strokeScaleEnabled",!0),W.addGetterSetter(Yt,"fillPriority","color"),W.addComponentsGetterSetter(Yt,"fillPatternOffset",["x","y"]),W.addGetterSetter(Yt,"fillPatternOffsetX",0,R()),W.addGetterSetter(Yt,"fillPatternOffsetY",0,R()),W.addComponentsGetterSetter(Yt,"fillPatternScale",["x","y"]),W.addGetterSetter(Yt,"fillPatternScaleX",1,R()),W.addGetterSetter(Yt,"fillPatternScaleY",1,R()),W.addComponentsGetterSetter(Yt,"fillLinearGradientStartPoint",["x","y"]),W.addComponentsGetterSetter(Yt,"strokeLinearGradientStartPoint",["x","y"]),W.addGetterSetter(Yt,"fillLinearGradientStartPointX",0),W.addGetterSetter(Yt,"strokeLinearGradientStartPointX",0),W.addGetterSetter(Yt,"fillLinearGradientStartPointY",0),W.addGetterSetter(Yt,"strokeLinearGradientStartPointY",0),W.addComponentsGetterSetter(Yt,"fillLinearGradientEndPoint",["x","y"]),W.addComponentsGetterSetter(Yt,"strokeLinearGradientEndPoint",["x","y"]),W.addGetterSetter(Yt,"fillLinearGradientEndPointX",0),W.addGetterSetter(Yt,"strokeLinearGradientEndPointX",0),W.addGetterSetter(Yt,"fillLinearGradientEndPointY",0),W.addGetterSetter(Yt,"strokeLinearGradientEndPointY",0),W.addComponentsGetterSetter(Yt,"fillRadialGradientStartPoint",["x","y"]),W.addGetterSetter(Yt,"fillRadialGradientStartPointX",0),W.addGetterSetter(Yt,"fillRadialGradientStartPointY",0),W.addComponentsGetterSetter(Yt,"fillRadialGradientEndPoint",["x","y"]),W.addGetterSetter(Yt,"fillRadialGradientEndPointX",0),W.addGetterSetter(Yt,"fillRadialGradientEndPointY",0),W.addGetterSetter(Yt,"fillPatternRotation",0),W.addGetterSetter(Yt,"fillRule",void 0,L()),W.backCompat(Yt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const jt=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Ut=jt.length;class qt extends et{constructor(t){super(t),this.canvas=new T,this.hitCanvas=new A({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(){$.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(!$.prototype.moveUp.call(this))return!1;const t=this.getStage();return!(!t||!t.content)&&(t.content.removeChild(this.getNativeCanvasElement()),this.index<t.children.length-1?t.content.insertBefore(this.getNativeCanvasElement(),t.children[this.index+1].getCanvas()._canvas):t.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if($.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($.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 $.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();"Group"!==e&&"Shape"!==e&&_.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return(t={...t}).width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=void 0!==t.x?t.x:this.x(),t.y=void 0!==t.y?t.y:this.y(),$.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){const t=this.visible();this.canvas._canvas.style.display=t?"block":"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<Ut;s++){const r=jt[s],n=this._getIntersection({x:t.x+r.x*e,y:t.y+r.y*e}),o=n.shape;if(o)return o;if(i=!!n.antialiased,!n.antialiased)break}if(!i)return null;e+=1}}_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(255===s){const t=_.getHitColorKey(i[0],i[1],i[2]),e=Xt[t];return e?{shape:e}:{antialiased:!0}}return s>0?{antialiased:!0}:{}}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),et.prototype.drawScene.call(this,r,e,i),this._fire("draw",{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),et.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()}}qt.prototype.nodeType="Layer",r(qt),W.addGetterSetter(qt,"imageSmoothingEnabled",!0),W.addGetterSetter(qt,"clearBeforeDraw",!0),W.addGetterSetter(qt,"hitGraphEnabled",!0,O());class Kt extends qt{constructor(t){super(t),this.listening(!1),_.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}Kt.prototype.nodeType="FastLayer",r(Kt);class Vt extends et{_validateAdd(t){const e=t.getType();"Group"!==e&&"Shape"!==e&&_.throw("You may only add groups and shapes to groups.")}}Vt.prototype.nodeType="Group",r(Vt);const Qt=i.performance&&i.performance.now?function(){return i.performance.now()}:function(){return(new Date).getTime()};class Jt{constructor(t,e){this.id=Jt.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:Qt(),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 t=Jt.animations,e=t.length;for(let i=0;i<e;i++)if(t[i].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=Qt(),Jt._addAnimation(this),this}stop(){return Jt._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 t=0;t<s;t++)if(i[t].id===e){this.animations.splice(t,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],r=s.layers,n=s.func;s._updateFrameObject(Qt());const o=r.length;let a;if(a=!n||!1!==n.call(s,s.frame),a)for(let e=0;e<o;e++){const i=r[e];void 0!==i._id&&(t[i._id]=i)}}for(const e in t)t.hasOwnProperty(e)&&t[e].batchDraw()}static _animationLoop(){const t=Jt;t.animations.length?(t._runFrames(),_.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,_.requestAnimFrame(this._animationLoop))}}Jt.animations=[],Jt.animIdCounter=0,Jt.animRunning=!1;const Zt={node:1,duration:1,easing:1,onFinish:1,yoyo:1},$t=["fill","stroke","shadowColor"];let te=0;class ee{constructor(t,e,i,s,r,n,o){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=n,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=r-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 void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,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;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class ie{constructor(t){const e=this,i=t.node,r=i._id,n=t.easing||se.Linear,o=!!t.yoyo;let a,h;a=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=i,this._id=te++;const l=i.getLayer()||(i instanceof s.Stage?i.getLayers():null);for(h in l||_.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Jt(function(){e.tween.onEnterFrame()},l),this.tween=new ee(h,function(t){e._tweenFunc(t)},n,0,1,1e3*a,o),this._addListeners(),ie.attrs[r]||(ie.attrs[r]={}),ie.attrs[r][this._id]||(ie.attrs[r][this._id]={}),ie.tweens[r]||(ie.tweens[r]={}),t)void 0===Zt[h]&&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 r,n,o,a,h;const l=ie.tweens[s][t];l&&delete ie.attrs[s][l][t];let d=i.getAttr(t);if(_._isArray(e))if(r=[],n=Math.max(e.length,d.length),"points"===t&&e.length!==d.length&&(e.length>d.length?(a=d,d=_._prepareArrayForTween(d,e,i.closed())):(o=e,e=_._prepareArrayForTween(e,d,i.closed()))),0===t.indexOf("fill"))for(let t=0;t<n;t++)if(t%2==0)r.push(e[t]-d[t]);else{const i=_.colorToRGBA(d[t]);h=_.colorToRGBA(e[t]),d[t]=i,r.push({r:h.r-i.r,g:h.g-i.g,b:h.b-i.b,a:h.a-i.a})}else for(let t=0;t<n;t++)r.push(e[t]-d[t]);else-1!==$t.indexOf(t)?(d=_.colorToRGBA(d),h=_.colorToRGBA(e),r={r:h.r-d.r,g:h.g-d.g,b:h.b-d.b,a:h.a-d.a}):r=e-d;ie.attrs[s][this._id][t]={start:d,diff:r,end:e,trueEnd:o,trueStart:a},ie.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=ie.attrs[e._id][this._id];let s,r,n,o,a,h,l,d;for(s in i){if(r=i[s],n=r.start,o=r.diff,d=r.end,_._isArray(n))if(a=[],l=Math.max(n.length,d.length),0===s.indexOf("fill"))for(h=0;h<l;h++)h%2==0?a.push((n[h]||0)+o[h]*t):a.push("rgba("+Math.round(n[h].r+o[h].r*t)+","+Math.round(n[h].g+o[h].g*t)+","+Math.round(n[h].b+o[h].b*t)+","+(n[h].a+o[h].a*t)+")");else for(h=0;h<l;h++)a.push((n[h]||0)+o[h]*t);else a=-1!==$t.indexOf(s)?"rgba("+Math.round(n.r+o.r*t)+","+Math.round(n.g+o.g*t)+","+Math.round(n.b+o.b*t)+","+(n.a+o.a*t)+")":n+o*t;e.setAttr(s,a)}}_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=ie.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=ie.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(1e3*t),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){const t=this.node._id,e=this._id,i=ie.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const e in i)delete ie.tweens[t][e];delete ie.attrs[t][e],ie.tweens[t]&&(0===Object.keys(ie.tweens[t]).length&&delete ie.tweens[t],0===Object.keys(ie.attrs[t]).length&&delete ie.attrs[t])}}ie.attrs={},ie.tweens={},$.prototype.to=function(t){const e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()};new ie(t).play()};const se={BackEaseIn(t,e,i,s){const r=1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},BackEaseOut(t,e,i,s){const r=1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},BackEaseInOut(t,e,i,s){let r=1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},ElasticEaseIn(t,e,i,s,r,n){let o=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)+e)},ElasticEaseOut(t,e,i,s,r,n){let o=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/n)+i+e)},ElasticEaseInOut(t,e,i,s,r,n){let o=0;return 0===t?e:2==(t/=s/2)?e+i:(n||(n=s*(.3*1.5)),!r||r<Math.abs(i)?(r=i,o=n/4):o=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/n)*.5+i+e)},BounceEaseOut:(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,s)=>i-se.BounceEaseOut(s-t,0,i,s)+e,BounceEaseInOut:(t,e,i,s)=>t<s/2?.5*se.BounceEaseIn(2*t,0,i,s)+e:.5*se.BounceEaseOut(2*t-s,0,i,s)+.5*i+e,EaseIn:(t,e,i,s)=>i*(t/=s)*t+e,EaseOut:(t,e,i,s)=>-i*(t/=s)*(t-2)+e,EaseInOut:(t,e,i,s)=>(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e,StrongEaseIn:(t,e,i,s)=>i*(t/=s)*t*t*t*t+e,StrongEaseOut:(t,e,i,s)=>i*((t=t/s-1)*t*t*t*t+1)+e,StrongEaseInOut:(t,e,i,s)=>(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e,Linear:(t,e,i,s)=>i*t/s+e},re=_._assign(s,{Util:_,Transform:o,Node:$,Container:et,Stage:Ot,stages:Gt,Layer:qt,FastLayer:Kt,Group:Vt,DD:k,Shape:Yt,shapes:Xt,Animation:Jt,Tween:ie,Easings:se,Context:w,Canvas:C});class ne extends Yt{_sceneFunc(t){const e=s.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 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),i=this.clockwise(),r=s.getAngle(i?360-this.angle():this.angle()),n=Math.cos(Math.min(r,Math.PI)),o=Math.sin(Math.min(Math.max(Math.PI,r),3*Math.PI/2)),a=Math.sin(Math.min(r,Math.PI/2)),h=n*(n>0?t:e),l=o*(o>0?t:e),d=a*(a>0?e:t);return{x:h,y:i?-1*d:l,width:1*e-h,height:d-l}}}function oe(t,e,i,s,r,n,o){const a=Math.sqrt(Math.pow(i-t,2)+Math.pow(s-e,2)),h=Math.sqrt(Math.pow(r-i,2)+Math.pow(n-s,2)),l=o*a/(a+h),d=o*h/(a+h);return[i-l*(r-t),s-l*(n-e),i+d*(r-t),s+d*(n-e)]}function ae(t,e){const i=t.length,s=[];for(let r=2;r<i-2;r+=2){const i=oe(t[r-2],t[r-1],t[r],t[r+1],t[r+2],t[r+3],e);isNaN(i[0])||(s.push(i[0]),s.push(i[1]),s.push(t[r]),s.push(t[r+1]),s.push(i[2]),s.push(i[3]))}return s}ne.prototype._centroid=!0,ne.prototype.className="Arc",ne.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],r(ne),W.addGetterSetter(ne,"innerRadius",0,R()),W.addGetterSetter(ne,"outerRadius",0,R()),W.addGetterSetter(ne,"angle",0,R()),W.addGetterSetter(ne,"clockwise",!1,O());class he extends Yt{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(),r=this.closed(),n=this.bezier();if(!i)return;let o=0;if(t.beginPath(),t.moveTo(e[0],e[1]),0!==s&&i>4){const s=this.getTensionPoints(),n=s.length;for(o=r?0:4,r||t.quadraticCurveTo(s[0],s[1],s[2],s[3]);o<n-2;)t.bezierCurveTo(s[o++],s[o++],s[o++],s[o++],s[o++],s[o++]);r||t.quadraticCurveTo(s[n-2],s[n-1],e[i-2],e[i-1])}else if(n)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]);r?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():ae(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=oe(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),r=oe(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),n=ae(t,i);return[s[2],s[3]].concat(n).concat([r[0],r[1],t[e-2],t[e-1],r[2],r[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};t=0!==this.tension()?[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.points();let e,i,s=t[0],r=t[0],n=t[1],o=t[1];for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),o=Math.max(o,i);return{x:s,y:n,width:r-s,height:o-n}}}he.prototype.className="Line",he.prototype._attrsAffectingSize=["points","bezier","tension"],r(he),W.addGetterSetter(he,"closed",!1),W.addGetterSetter(he,"bezier",!1),W.addGetterSetter(he,"tension",0,R()),W.addGetterSetter(he,"points",[],function(){if(s.isUnminified)return function(t,e){const i=Int8Array?Object.getPrototypeOf(Int8Array):null;return i&&t instanceof i||(_._isArray(t)?t.forEach(function(t){_._isNumber(t)||_.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")}):_.warn(P(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),t}}());const le=[[],[],[-.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]],de=[[],[],[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]],ce=[[1],[1,1],[1,2,1],[1,3,3,1]],ge=(t,e,i)=>{let s,r;const n=i/2;s=0;for(let i=0;i<20;i++)r=n*le[20][i]+n,s+=de[20][i]*ue(t,e,r);return n*s},fe=(t,e,i)=>{void 0===i&&(i=1);const s=t[0]-2*t[1]+t[2],r=e[0]-2*e[1]+e[2],n=2*t[1]-2*t[0],o=2*e[1]-2*e[0],a=4*(s*s+r*r),h=4*(s*n+r*o),l=n*n+o*o;if(0===a)return i*Math.sqrt(Math.pow(t[2]-t[0],2)+Math.pow(e[2]-e[0],2));const d=h/(2*a),c=i+d,g=l/a-d*d,f=c*c+g>0?Math.sqrt(c*c+g):0,u=d*d+g>0?Math.sqrt(d*d+g):0,p=d+Math.sqrt(d*d+g)!==0?g*Math.log(Math.abs((c+f)/(d+u))):0;return Math.sqrt(a)/2*(c*f-d*u+p)};function ue(t,e,i){const s=pe(1,i,t),r=pe(1,i,e),n=s*s+r*r;return Math.sqrt(n)}const pe=(t,e,i)=>{const s=i.length-1;let r,n;if(0===s)return 0;if(0===t){n=0;for(let t=0;t<=s;t++)n+=ce[s][t]*Math.pow(1-e,s-t)*Math.pow(e,t)*i[t];return n}r=new Array(s);for(let t=0;t<s;t++)r[t]=s*(i[t+1]-i[t]);return pe(t-1,e,r)},_e=(t,e,i)=>{let s=1,r=t/e,n=(t-i(r))/e,o=0;for(;s>.001;){const a=i(r+n),h=Math.abs(t-a)/e;if(h<s)s=h,r+=n;else{const o=i(r-n),a=Math.abs(t-o)/e;a<s?(s=a,r-=n):n/=2}if(o++,o>500)break}return r};class me extends Yt{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=me.parsePathData(this.data()),this.pathLength=me.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const r=e[s].command,n=e[s].points;switch(r){case"L":t.lineTo(n[0],n[1]);break;case"M":t.moveTo(n[0],n[1]);break;case"C":t.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]);break;case"Q":t.quadraticCurveTo(n[0],n[1],n[2],n[3]);break;case"A":const e=n[0],s=n[1],r=n[2],o=n[3],a=n[4],h=n[5],l=n[6],d=n[7],c=r>o?r:o,g=r>o?1:r/o,f=r>o?o/r:1;t.translate(e,s),t.rotate(l),t.scale(g,f),t.arc(0,0,c,a,a+h,1-d),t.scale(1/g,1/f),t.rotate(-l),t.translate(-e,-s);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(e){if("A"===e.command){const i=e.points[4],s=e.points[5],r=e.points[4]+s;let n=Math.PI/180;if(Math.abs(i-r)<n&&(n=Math.abs(i-r)),s<0)for(let s=i-n;s>r;s-=n){const i=me.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}else for(let s=i+n;s<r;s+=n){const i=me.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}}else if("C"===e.command)for(let i=0;i<=1;i+=.01){const s=me.getPointOnCubicBezier(i,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);t.push(s.x,s.y)}else t=t.concat(e.points)});let e,i,s=t[0],r=t[0],n=t[1],o=t[1];for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],isNaN(e)||(s=Math.min(s,e),r=Math.max(r,e)),isNaN(i)||(n=Math.min(n,i),o=Math.max(o,i));return{x:s,y:n,width:r-s,height:o-n}}getLength(){return this.pathLength}getPointAtLength(t){return me.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,r=e.length;if(!r)return null;for(;s<r&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===r)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01){return"M"===e[s].command?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y}}const n=e[s],o=n.points;switch(n.command){case"L":return me.getPointOnLine(t,n.start.x,n.start.y,o[0],o[1]);case"C":return me.getPointOnCubicBezier(_e(t,me.getPathLength(e),t=>ge([n.start.x,o[0],o[2],o[4]],[n.start.y,o[1],o[3],o[5]],t)),n.start.x,n.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return me.getPointOnQuadraticBezier(_e(t,me.getPathLength(e),t=>fe([n.start.x,o[0],o[2]],[n.start.y,o[1],o[3]],t)),n.start.x,n.start.y,o[0],o[1],o[2],o[3]);case"A":const i=o[0],s=o[1],r=o[2],a=o[3],h=o[5],l=o[6];let d=o[4];return d+=h*t/n.pathLength,me.getPointOnEllipticalArc(i,s,r,a,d,l)}return null}static getPointOnLine(t,e,i,s,r,n,o){n=null!=n?n:e,o=null!=o?o:i;const a=this.getLineLength(e,i,s,r);if(a<1e-10)return{x:e,y:i};if(s===e)return{x:n,y:o+(r>i?t:-t)};const h=(r-i)/(s-e),l=Math.sqrt(t*t/(1+h*h))*(s<e?-1:1),d=h*l;if(Math.abs(o-i-h*(n-e))<1e-10)return{x:n+l,y:o+d};const c=((n-e)*(s-e)+(o-i)*(r-i))/(a*a),g=e+c*(s-e),f=i+c*(r-i),u=this.getLineLength(n,o,g,f),p=Math.sqrt(t*t-u*u),_=Math.sqrt(p*p/(1+h*h))*(s<e?-1:1);return{x:g+_,y:f+h*_}}static getPointOnCubicBezier(t,e,i,s,r,n,o,a,h){function l(t){return t*t*t}function d(t){return 3*t*t*(1-t)}function c(t){return 3*t*(1-t)*(1-t)}function g(t){return(1-t)*(1-t)*(1-t)}return{x:a*l(t)+n*d(t)+s*c(t)+e*g(t),y:h*l(t)+o*d(t)+r*c(t)+i*g(t)}}static getPointOnQuadraticBezier(t,e,i,s,r,n,o){function a(t){return t*t}function h(t){return 2*t*(1-t)}function l(t){return(1-t)*(1-t)}return{x:n*a(t)+s*h(t)+e*l(t),y:o*a(t)+r*h(t)+i*l(t)}}static getPointOnEllipticalArc(t,e,i,s,r,n){const o=Math.cos(n),a=Math.sin(n),h=i*Math.cos(r),l=s*Math.sin(r);return{x:t+(h*o-l*a),y:e+(h*a+l*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 t=0;t<i.length;t++)e=e.replace(new RegExp(i[t],"g"),"|"+i[t]);const s=e.split("|"),r=[],n=[];let o=0,a=0;const h=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let l;for(let t=1;t<s.length;t++){let e=s[t],i=e.charAt(0);for(e=e.slice(1),n.length=0;l=h.exec(e);)n.push(l[0]);let d=[],c="A"===i||"a"===i?0:-1;for(let t=0,e=n.length;t<e;t++){const e=n[t];if("00"!==e)if(c>=0){if(3===c){if(/^[01]{2}\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),d.push(parseFloat(e.slice(2))),c+=3,c>=7&&(c-=7);continue}if("11"===e||"10"===e||"01"===e){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}else if(4===c){if(/^[01]\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseFloat(e.slice(1))),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t),c+=1,c>=7&&(c-=7)}else{const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t)}else d.push(0,0),c>=0&&(c+=2,c>=7&&(c-=7))}for(;d.length>0&&!isNaN(d[0]);){let t="",e=[];const s=o,n=a;let h,l,c,g,f,u,p,_,m,y;switch(i){case"l":o+=d.shift(),a+=d.shift(),t="L",e.push(o,a);break;case"L":o=d.shift(),a=d.shift(),e.push(o,a);break;case"m":const s=d.shift(),n=d.shift();if(o+=s,a+=n,t="M",r.length>2&&"z"===r[r.length-1].command)for(let t=r.length-2;t>=0;t--)if("M"===r[t].command){o=r[t].points[0]+s,a=r[t].points[1]+n;break}e.push(o,a),i="l";break;case"M":o=d.shift(),a=d.shift(),t="M",e.push(o,a),i="L";break;case"h":o+=d.shift(),t="L",e.push(o,a);break;case"H":o=d.shift(),t="L",e.push(o,a);break;case"v":a+=d.shift(),t="L",e.push(o,a);break;case"V":a=d.shift(),t="L",e.push(o,a);break;case"C":e.push(d.shift(),d.shift(),d.shift(),d.shift()),o=d.shift(),a=d.shift(),e.push(o,a);break;case"c":e.push(o+d.shift(),a+d.shift(),o+d.shift(),a+d.shift()),o+=d.shift(),a+=d.shift(),t="C",e.push(o,a);break;case"S":l=o,c=a,h=r[r.length-1],"C"===h.command&&(l=o+(o-h.points[2]),c=a+(a-h.points[3])),e.push(l,c,d.shift(),d.shift()),o=d.shift(),a=d.shift(),t="C",e.push(o,a);break;case"s":l=o,c=a,h=r[r.length-1],"C"===h.command&&(l=o+(o-h.points[2]),c=a+(a-h.points[3])),e.push(l,c,o+d.shift(),a+d.shift()),o+=d.shift(),a+=d.shift(),t="C",e.push(o,a);break;case"Q":e.push(d.shift(),d.shift()),o=d.shift(),a=d.shift(),e.push(o,a);break;case"q":e.push(o+d.shift(),a+d.shift()),o+=d.shift(),a+=d.shift(),t="Q",e.push(o,a);break;case"T":l=o,c=a,h=r[r.length-1],"Q"===h.command&&(l=o+(o-h.points[0]),c=a+(a-h.points[1])),o=d.shift(),a=d.shift(),t="Q",e.push(l,c,o,a);break;case"t":l=o,c=a,h=r[r.length-1],"Q"===h.command&&(l=o+(o-h.points[0]),c=a+(a-h.points[1])),o+=d.shift(),a+=d.shift(),t="Q",e.push(l,c,o,a);break;case"A":g=d.shift(),f=d.shift(),u=d.shift(),p=d.shift(),_=d.shift(),m=o,y=a,o=d.shift(),a=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(m,y,o,a,p,_,g,f,u);break;case"a":g=d.shift(),f=d.shift(),u=d.shift(),p=d.shift(),_=d.shift(),m=o,y=a,o+=d.shift(),a+=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(m,y,o,a,p,_,g,f,u)}r.push({command:t||i,points:e,start:{x:s,y:n},pathLength:this.calcLength(s,n,t||i,e)})}"z"!==i&&"Z"!==i||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r}static calcLength(t,e,i,s){let r,n,o,a;const h=me;switch(i){case"L":return h.getLineLength(t,e,s[0],s[1]);case"C":return ge([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return fe([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":r=0;const i=s[4],l=s[5],d=s[4]+l;let c=Math.PI/180;if(Math.abs(i-d)<c&&(c=Math.abs(i-d)),n=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],i,0),l<0)for(a=i-c;a>d;a-=c)o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],a,0),r+=h.getLineLength(n.x,n.y,o.x,o.y),n=o;else for(a=i+c;a<d;a+=c)o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],a,0),r+=h.getLineLength(n.x,n.y,o.x,o.y),n=o;return o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),r+=h.getLineLength(n.x,n.y,o.x,o.y),r}return 0}static convertEndpointToCenterParameterization(t,e,i,s,r,n,o,a,h){const l=h*(Math.PI/180),d=Math.cos(l)*(t-i)/2+Math.sin(l)*(e-s)/2,c=-1*Math.sin(l)*(t-i)/2+Math.cos(l)*(e-s)/2,g=d*d/(o*o)+c*c/(a*a);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));let f=Math.sqrt((o*o*(a*a)-o*o*(c*c)-a*a*(d*d))/(o*o*(c*c)+a*a*(d*d)));r===n&&(f*=-1),isNaN(f)&&(f=0);const u=f*o*c/a,p=f*-a*d/o,_=(t+i)/2+Math.cos(l)*u-Math.sin(l)*p,m=(e+s)/2+Math.sin(l)*u+Math.cos(l)*p,y=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},x=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(y(t)*y(e))},v=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(x(t,e))},w=v([1,0],[(d-u)/o,(c-p)/a]),S=[(d-u)/o,(c-p)/a],b=[(-1*d-u)/o,(-1*c-p)/a];let C=v(S,b);return x(S,b)<=-1&&(C=Math.PI),x(S,b)>=1&&(C=0),0===n&&C>0&&(C-=2*Math.PI),1===n&&C<0&&(C+=2*Math.PI),[_,m,o,a,w,C,l,n]}}me.prototype.className="Path",me.prototype._attrsAffectingSize=["data"],r(me),W.addGetterSetter(me,"data");class ye extends he{_sceneFunc(t){super._sceneFunc(t);const e=2*Math.PI,i=this.points();let s=i;const r=0!==this.tension()&&i.length>4;r&&(s=this.getTensionPoints());const n=this.pointerLength(),o=i.length;let a,h;if(r){const t=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[o-2],i[o-1]],e=me.calcLength(s[s.length-4],s[s.length-3],"C",t),r=me.getPointOnQuadraticBezier(Math.min(1,1-n/e),t[0],t[1],t[2],t[3],t[4],t[5]);a=i[o-2]-r.x,h=i[o-1]-r.y}else a=i[o-2]-i[o-4],h=i[o-1]-i[o-3];const l=(Math.atan2(h,a)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[o-2],i[o-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),r?(a=(s[0]+s[2])/2-i[0],h=(s[1]+s[3])/2-i[1]):(a=i[2]-i[0],h=i[3]-i[1]),t.rotate((Math.atan2(-h,-a)+e)%e),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/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+2*e}}}ye.prototype.className="Arrow",r(ye),W.addGetterSetter(ye,"pointerLength",10,R()),W.addGetterSetter(ye,"pointerWidth",10,R()),W.addGetterSetter(ye,"pointerAtBeginning",!1),W.addGetterSetter(ye,"pointerAtEnding",!0);class xe extends Yt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,2*Math.PI,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}xe.prototype._centroid=!0,xe.prototype.className="Circle",xe.prototype._attrsAffectingSize=["radius"],r(xe),W.addGetterSetter(xe,"radius",0,R());class ve extends Yt{_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,2*Math.PI,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radiusX()}getHeight(){return 2*this.radiusY()}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}ve.prototype.className="Ellipse",ve.prototype._centroid=!0,ve.prototype._attrsAffectingSize=["radiusX","radiusY"],r(ve),W.addComponentsGetterSetter(ve,"radius",["x","y"]),W.addGetterSetter(ve,"radiusX",0,R()),W.addGetterSetter(ve,"radiusY",0,R());let we=class t extends Yt{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",t=>{this._removeImageLoad(t.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||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)||super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),r=this.attrs.image;let n;if(r){const t=this.attrs.cropWidth,s=this.attrs.cropHeight;n=t&&s?[r,this.cropX(),this.cropY(),t,s,0,0,e,i]:[r,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)),r&&(s&&t.clip(),t.drawImage.apply(t,n))}_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 null!==(i=null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width)&&void 0!==i?i:0}getHeight(){var t,e,i;return null!==(i=null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height)&&void 0!==i?i:0}static fromURL(e,i,s=null){const r=_.createImageElement();r.onload=function(){const e=new t({image:r});i(e)},r.onerror=s,r.crossOrigin="Anonymous",r.src=e}};we.prototype.className="Image",we.prototype._attrsAffectingSize=["image"],r(we),W.addGetterSetter(we,"cornerRadius",0,I(4)),W.addGetterSetter(we,"image"),W.addComponentsGetterSetter(we,"crop",["x","y","width","height"]),W.addGetterSetter(we,"cropX",0,R()),W.addGetterSetter(we,"cropY",0,R()),W.addGetterSetter(we,"cropWidth",0,R()),W.addGetterSetter(we,"cropHeight",0,R());const Se=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],be="up",Ce="right",Te="down",Ae="left",ke=Se.length;class Pe extends Vt{constructor(t){super(t),this.on("add.konva",function(t){this._addListeners(t.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){let e,i=this;const s=function(){i._sync()};for(e=0;e<ke;e++)t.on(Se[e]+"Change.konva",s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t,e,i,s,r,n,o,a=this.getText(),h=this.getTag();if(a&&h){switch(t=a.width(),e=a.height(),i=h.pointerDirection(),s=h.pointerWidth(),o=h.pointerHeight(),r=0,n=0,i){case be:r=t/2,n=-1*o;break;case Ce:r=t+s,n=e/2;break;case Te:r=t/2,n=e+o;break;case Ae:r=-1*s,n=e/2}h.setAttrs({x:-1*r,y:-1*n,width:t,height:e}),a.setAttrs({x:-1*r,y:-1*n})}}}Pe.prototype.className="Label",r(Pe);class Me extends Yt{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),r=this.pointerWidth(),n=this.pointerHeight(),o=this.cornerRadius();let a=0,h=0,l=0,d=0;"number"==typeof o?a=h=l=d=Math.min(o,e/2,i/2):(a=Math.min(o[0]||0,e/2,i/2),h=Math.min(o[1]||0,e/2,i/2),d=Math.min(o[2]||0,e/2,i/2),l=Math.min(o[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(a,0),s===be&&(t.lineTo((e-r)/2,0),t.lineTo(e/2,-1*n),t.lineTo((e+r)/2,0)),t.lineTo(e-h,0),t.arc(e-h,h,h,3*Math.PI/2,0,!1),s===Ce&&(t.lineTo(e,(i-n)/2),t.lineTo(e+r,i/2),t.lineTo(e,(i+n)/2)),t.lineTo(e,i-d),t.arc(e-d,i-d,d,0,Math.PI/2,!1),s===Te&&(t.lineTo((e+r)/2,i),t.lineTo(e/2,i+n),t.lineTo((e-r)/2,i)),t.lineTo(l,i),t.arc(l,i-l,l,Math.PI/2,Math.PI,!1),s===Ae&&(t.lineTo(0,(i+n)/2),t.lineTo(-1*r,i/2),t.lineTo(0,(i-n)/2)),t.lineTo(0,a),t.arc(a,a,a,Math.PI,3*Math.PI/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),r=this.pointerDirection(),n=this.width(),o=this.height();return r===be?(e-=s,o+=s):r===Te?o+=s:r===Ae?(t-=1.5*i,n+=i):r===Ce&&(n+=1.5*i),{x:t,y:e,width:n,height:o}}}Me.prototype.className="Tag",r(Me),W.addGetterSetter(Me,"pointerDirection","none"),W.addGetterSetter(Me,"pointerWidth",0,R()),W.addGetterSetter(Me,"pointerHeight",0,R()),W.addGetterSetter(Me,"cornerRadius",0,I(4));class Re extends Yt{_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)}}Re.prototype.className="Rect",r(Re),W.addGetterSetter(Re,"cornerRadius",0,I(4));class Ie extends Yt{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),r=this.cornerRadius();if(t.beginPath(),r)_.drawRoundedPolygonPath(t,e,s,i,r);else{t.moveTo(e[0].x,e[0].y);for(let i=1;i<e.length;i++)t.lineTo(e[i].x,e[i].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(2*s*Math.PI/t),y:-1*e*Math.cos(2*s*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].x,s=t[0].y,r=t[0].y;return t.forEach(t=>{e=Math.min(e,t.x),i=Math.max(i,t.x),s=Math.min(s,t.y),r=Math.max(r,t.y)}),{x:e,y:s,width:i-e,height:r-s}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}Ie.prototype.className="RegularPolygon",Ie.prototype._centroid=!0,Ie.prototype._attrsAffectingSize=["radius"],r(Ie),W.addGetterSetter(Ie,"radius",0,R()),W.addGetterSetter(Ie,"sides",0,R()),W.addGetterSetter(Ie,"cornerRadius",0,I(4));const Ee=2*Math.PI;class Le extends Yt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,Ee,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),Ee,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}Le.prototype.className="Ring",Le.prototype._centroid=!0,Le.prototype._attrsAffectingSize=["innerRadius","outerRadius"],r(Le),W.addGetterSetter(Le,"innerRadius",0,R()),W.addGetterSetter(Le,"outerRadius",0,R());class Ge extends Yt{constructor(t){super(t),this._updated=!0,this.anim=new Jt(()=>{const t=this._updated;return this._updated=!1,t}),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=4*i,r=this.animations()[e],n=this.frameOffsets(),o=r[s+0],a=r[s+1],h=r[s+2],l=r[s+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(n){const s=n[e],r=2*i;t.drawImage(d,o,a,h,l,s[r+0],s[r+1],h,l)}else t.drawImage(d,o,a,h,l,0,0,h,l)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,r=this.animations()[e],n=this.frameOffsets(),o=r[s+2],a=r[s+3];if(t.beginPath(),n){const s=n[e],r=2*i;t.rect(s[r+0],s[r+1],o,a)}else t.rect(0,0,o,a);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();t<this.animations()[e].length/4-1?this.frameIndex(t+1):this.frameIndex(0)}}Ge.prototype.className="Sprite",r(Ge),W.addGetterSetter(Ge,"animation"),W.addGetterSetter(Ge,"animations"),W.addGetterSetter(Ge,"frameOffsets"),W.addGetterSetter(Ge,"image"),W.addGetterSetter(Ge,"frameIndex",0,R()),W.addGetterSetter(Ge,"frameRate",17,R()),W.backCompat(Ge,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class Oe extends Yt{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let r=1;r<2*s;r++){const n=r%2==0?i:e,o=n*Math.sin(r*Math.PI/s),a=-1*n*Math.cos(r*Math.PI/s);t.lineTo(o,a)}t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}function De(t){return[...t].reduce((t,e,i,s)=>{if(/\p{Emoji}/u.test(e)){const r=s[i+1];r&&/\p{Emoji_Modifier}|\u200D/u.test(r)?(t.push(e+r),s[i+1]=""):t.push(e)}else/\p{Regional_Indicator}{2}/u.test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}Oe.prototype.className="Star",Oe.prototype._centroid=!0,Oe.prototype._attrsAffectingSize=["innerRadius","outerRadius"],r(Oe),W.addGetterSetter(Oe,"numPoints",5,R()),W.addGetterSetter(Oe,"innerRadius",0,R()),W.addGetterSetter(Oe,"outerRadius",0,R());const Fe="auto",We="inherit",Be="justify",Ne="left",ze="middle",He="normal",Xe=" ",Ye="none",je=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],Ue=je.length;let qe;function Ke(){return qe||(qe=_.createCanvasElement().getContext("2d"),qe)}class Ve extends Yt{constructor(t){super(function(t){return(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||t.fillPatternImage||(t.fill=t.fill||"black"),t}(t)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<Ue;t++)this.on(je[t]+"Change.konva",this._setTextData);this._setTextData()}_sceneFunc(t){var e,i;const r=this.textArr,n=r.length;if(!this.text())return;let o,a=this.padding(),h=this.fontSize(),l=this.lineHeight()*h,d=this.verticalAlign(),c=this.direction(),g=0,f=this.align(),u=this.getWidth(),p=this.letterSpacing(),_=this.charRenderFunc(),m=this.fill(),y=this.textDecoration(),x=-1!==y.indexOf("underline"),v=-1!==y.indexOf("line-through");c=c===We?t.direction:c;let w=l/2,S=ze;if(!s.legacyTextRendering){const t=this.measureSize("M");S="alphabetic";w=((null!==(e=t.fontBoundingBoxAscent)&&void 0!==e?e:t.actualBoundingBoxAscent)-(null!==(i=t.fontBoundingBoxDescent)&&void 0!==i?i:t.actualBoundingBoxDescent))/2+l/2}for("rtl"===c&&t.setAttr("direction",c),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",S),t.setAttr("textAlign",Ne),d===ze?g=(this.getHeight()-n*l-2*a)/2:"bottom"===d&&(g=this.getHeight()-n*l-2*a),t.translate(a,g+a),o=0;o<n;o++){let e=0,i=0;const d=r[o],g=d.text,y=d.width,S=d.lastInParagraph;if(t.save(),"right"===f?e+=u-y-2*a:"center"===f&&(e+=(u-y-2*a)/2),x){t.save(),t.beginPath();const r=e,n=w+i+(s.legacyTextRendering?Math.round(h/2):Math.round(h/4));t.moveTo(r,n);const o=f!==Be||S?y:u-2*a;t.lineTo(r+Math.round(o),n),t.lineWidth=h/15;const l=this._getLinearGradient();t.strokeStyle=l||m,t.stroke(),t.restore()}const b=e;if("rtl"===c||0===p&&f!==Be&&!_)0!==p&&t.setAttr("letterSpacing",`${p}px`),this._partialTextX=e,this._partialTextY=w+i,this._partialText=g,t.fillStrokeShape(this);else{const s=g.split(" ").length-1,n=De(g);for(let h=0;h<n.length;h++){const l=n[h];if(" "!==l||S||f!==Be||(e+=(u-2*a-y)/s),this._partialTextX=e,this._partialTextY=w+i,this._partialText=l,_){t.save();_({char:l,index:h+r.slice(0,o).reduce((t,e)=>t+De(e.text).length,0),x:e,y:w+i,lineIndex:o,column:h,isLastInLine:S,width:this.measureSize(l).width,context:t})}t.fillStrokeShape(this),_&&t.restore(),e+=this.measureSize(l).width+p}}if(v){t.save(),t.beginPath();const e=s.legacyTextRendering?0:-Math.round(h/4),r=b;t.moveTo(r,w+i+e);const n=f!==Be||S?y:u-2*a;t.lineTo(r+Math.round(n),w+i+e),t.lineWidth=h/15;const o=this._getLinearGradient();t.strokeStyle=o||m,t.stroke(),t.restore()}t.restore(),n>1&&(w+=l)}}_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:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===Fe||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===Fe||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():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,r,n,o,a,h,l,d,c;let g,f=Ke(),u=this.fontSize();f.save(),f.font=this._getContextFont(),g=f.measureText(t),f.restore();const p=u/100;return{actualBoundingBoxAscent:null!==(e=g.actualBoundingBoxAscent)&&void 0!==e?e:71.58203125*p,actualBoundingBoxDescent:null!==(i=g.actualBoundingBoxDescent)&&void 0!==i?i:0,actualBoundingBoxLeft:null!==(s=g.actualBoundingBoxLeft)&&void 0!==s?s:-7.421875*p,actualBoundingBoxRight:null!==(r=g.actualBoundingBoxRight)&&void 0!==r?r:75.732421875*p,alphabeticBaseline:null!==(n=g.alphabeticBaseline)&&void 0!==n?n:0,emHeightAscent:null!==(o=g.emHeightAscent)&&void 0!==o?o:100*p,emHeightDescent:null!==(a=g.emHeightDescent)&&void 0!==a?a:-20*p,fontBoundingBoxAscent:null!==(h=g.fontBoundingBoxAscent)&&void 0!==h?h:91*p,fontBoundingBoxDescent:null!==(l=g.fontBoundingBoxDescent)&&void 0!==l?l:21*p,hangingBaseline:null!==(d=g.hangingBaseline)&&void 0!==d?d:72.80000305175781*p,ideographicBaseline:null!==(c=g.ideographicBaseline)&&void 0!==c?c:-21*p,width:g.width,height:u}}_getContextFont(){return this.fontStyle()+Xe+this.fontVariant()+Xe+(this.fontSize()+"px ")+this.fontFamily().split(",").map(t=>{const e=(t=t.trim()).indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t}).join(", ")}_addTextLine(t){this.align()===Be&&(t=t.trim());const e=this._getTextWidth(t);return this.textArr.push({text:t,width:e,lastInParagraph:!1})}_getTextWidth(t){const e=this.letterSpacing(),i=t.length;return Ke().measureText(t).width+e*i}_setTextData(){let t=this.text().split("\n"),e=+this.fontSize(),i=0,s=this.lineHeight()*e,r=this.attrs.width,n=this.attrs.height,o=r!==Fe&&void 0!==r,a=n!==Fe&&void 0!==n,h=this.padding(),l=r-2*h,d=n-2*h,c=0,g=this.wrap(),f="char"!==g&&g!==Ye,u=this.ellipsis();this.textArr=[],Ke().font=this._getContextFont();const p=u?this._getTextWidth("…"):0;for(let e=0,r=t.length;e<r;++e){let n=t[e],h=this._getTextWidth(n);if(o&&h>l)for(;n.length>0;){let t=0,e=De(n).length,r="",o=0;for(;t<e;){const i=t+e>>>1,h=De(n).slice(0,i+1).join(""),g=this._getTextWidth(h);(u&&a&&c+s>d?g+p:g)<=l?(t=i+1,r=h,o=g):e=i}if(!r)break;if(f){const e=De(n),i=De(r),s=e[i.length];let a;if((s===Xe||"-"===s)&&o<=l)a=i.length;else{const t=i.lastIndexOf(Xe),e=i.lastIndexOf("-");a=Math.max(t,e)+1}a>0&&(t=a,r=e.slice(0,t).join(""),o=this._getTextWidth(r))}r=r.trimRight(),this._addTextLine(r),i=Math.max(i,o),c+=s;if(this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if(n=De(n).slice(t).join("").trimLeft(),n.length>0&&(h=this._getTextWidth(n),h<=l)){this._addTextLine(n),c+=s,i=Math.max(i,h);break}}else this._addTextLine(n),c+=s,i=Math.max(i,h),this._shouldHandleEllipsis(c)&&e<r-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),a&&c+s>d)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,r=s!==Fe&&void 0!==s,n=s-2*this.padding();return!(this.wrap()!==Ye)||r&&t+i>n}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==Fe&&void 0!==t,i=t-2*this.padding(),s=this.ellipsis(),r=this.textArr[this.textArr.length-1];if(r&&s){if(e){this._getTextWidth(r.text+"…")<i||(r.text=r.text.slice(0,r.text.length-3))}this.textArr.splice(this.textArr.length-1,1),this._addTextLine(r.text+"…")}}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=-1!==this.textDecoration().indexOf("underline")||-1!==this.textDecoration().indexOf("line-through"),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas()}}Ve.prototype._fillFunc=function(t){t.fillText(this._partialText,this._partialTextX,this._partialTextY)},Ve.prototype._strokeFunc=function(t){t.setAttr("miterLimit",2),t.strokeText(this._partialText,this._partialTextX,this._partialTextY)},Ve.prototype.className="Text",Ve.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],r(Ve),W.overWriteSetter(Ve,"width",E()),W.overWriteSetter(Ve,"height",E()),W.addGetterSetter(Ve,"direction",We),W.addGetterSetter(Ve,"fontFamily","Arial"),W.addGetterSetter(Ve,"fontSize",12,R()),W.addGetterSetter(Ve,"fontStyle",He),W.addGetterSetter(Ve,"fontVariant",He),W.addGetterSetter(Ve,"padding",0,R()),W.addGetterSetter(Ve,"align",Ne),W.addGetterSetter(Ve,"verticalAlign","top"),W.addGetterSetter(Ve,"lineHeight",1,R()),W.addGetterSetter(Ve,"wrap","word"),W.addGetterSetter(Ve,"ellipsis",!1,O()),W.addGetterSetter(Ve,"letterSpacing",0,R()),W.addGetterSetter(Ve,"text","",L()),W.addGetterSetter(Ve,"textDecoration",""),W.addGetterSetter(Ve,"charRenderFunc",void 0);const Qe="normal";function Je(t){t.fillText(this.partialText,0,0)}function Ze(t){t.strokeText(this.partialText,0,0)}class $e extends Yt{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 me.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;return t>this.pathLength?null:me.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=me.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(),r=this.glyphInfo,n=-1!==e.indexOf("underline"),o=-1!==e.indexOf("line-through");n&&t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),this.partialText=r[e].text,t.fillStrokeShape(this),n&&(0===e&&t.moveTo(0,s/2+1),t.lineTo(r[e].width,s/2+1)),t.restore()}if(n&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),o){t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),0===e&&t.moveTo(0,0),t.lineTo(r[e].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 Ve.prototype.setText.call(this,t)}_getContextFont(){return Ve.prototype._getContextFont.call(this)}_getTextSize(t){const e=this.dummyCanvas.getContext("2d");e.save(),e.font=this._getContextFont();const i=e.measureText(t);return e.restore(),{width:i.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const t=De(this.text()),e=[];let i=0;for(let s=0;s<t.length;s++)e.push({char:t[s],width:this._getTextSize(t[s]).width}),i+=e[s].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const r=this.letterSpacing(),n=this.align(),o=this.kerningFunc(),a=Math.max(this.textWidth+((this.attrs.text||"").length-1)*r,0);let h=0;"center"===n&&(h=Math.max(0,this.pathLength/2-a/2)),"right"===n&&(h=Math.max(0,this.pathLength-a));let l=h;for(let i=0;i<e.length;i++){const s=this._getPointAtLength(l);if(!s)return;const h=e[i].char;let d=e[i].width+r;if(" "===h&&"justify"===n){const t=this.text().split(" ").length-1;d+=(this.pathLength-a)/t}const c=this._getPointAtLength(l+d);if(!c)return;const g=me.getLineLength(s.x,s.y,c.x,c.y);let f=0;if(o)try{f=o(e[i-1].char,h)*this.fontSize()}catch(t){f=0}s.x+=f,c.x+=f,this.textWidth+=f;const u=me.getPointOnLine(f+g/2,s.x,s.y,c.x,c.y),p=Math.atan2(c.y-s.y,c.x-s.x);this.glyphInfo.push({transposeX:u.x,transposeY:u.y,text:t[i],rotation:p,p0:s,p1:c,width:g}),l+=d}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(e){t.push(e.p0.x),t.push(e.p0.y),t.push(e.p1.x),t.push(e.p1.y)});let e,i,s=t[0]||0,r=t[0]||0,n=t[1]||0,o=t[1]||0;for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),o=Math.max(o,i);const a=this.fontSize();return{x:s-a/2,y:n-a/2,width:r-s+a,height:o-n+a}}destroy(){return _.releaseCanvas(this.dummyCanvas),super.destroy()}}$e.prototype._fillFunc=Je,$e.prototype._strokeFunc=Ze,$e.prototype._fillFuncHit=Je,$e.prototype._strokeFuncHit=Ze,$e.prototype.className="TextPath",$e.prototype._attrsAffectingSize=["text","fontSize","data"],r($e),W.addGetterSetter($e,"data"),W.addGetterSetter($e,"fontFamily","Arial"),W.addGetterSetter($e,"fontSize",12,R()),W.addGetterSetter($e,"fontStyle",Qe),W.addGetterSetter($e,"align","left"),W.addGetterSetter($e,"letterSpacing",0,R()),W.addGetterSetter($e,"textBaseline","middle"),W.addGetterSetter($e,"fontVariant",Qe),W.addGetterSetter($e,"text",""),W.addGetterSetter($e,"textDecoration",""),W.addGetterSetter($e,"kerningFunc",void 0);const ti="tr-konva",ei=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(t=>t+`.${ti}`).join(" "),ii="nodesRect",si=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],ri={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},ni="ontouchstart"in s._global;const oi=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function ai(t,e,i){const s=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),r=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return{...t,rotation:t.rotation+e,x:s,y:r}}function hi(t,e){const i=function(t){return{x:t.x+t.width/2*Math.cos(t.rotation)+t.height/2*Math.sin(-t.rotation),y:t.y+t.height/2*Math.cos(t.rotation)+t.width/2*Math.sin(t.rotation)}}(t);return ai(t,e,i)}let li=0;class di extends Vt{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(ei,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 ti+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(t=>!t.isAncestorOf(this)||(_.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1));this._nodes=t=e,1===t.length&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(t=>{const e=()=>{1===this.nodes().length&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),this._transforming||this.isDragging()||this.update()};if(t._attrsAffectingSize.length){const i=t._attrsAffectingSize.map(t=>t+"Change."+this._getEventNamespace()).join(" ");t.on(i,e)}t.on(si.map(t=>t+`.${this._getEventNamespace()}`).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)}),this._resetTransformCache();return!!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(),r=s.x-e.x,n=s.y-e.y;this.nodes().forEach(e=>{if(e===t)return;if(e.isDragging())return;const s=e.getAbsolutePosition();e.setAbsolutePosition({x:s.x+r,y:s.y+n}),e.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(ii),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(ii,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),i){const r=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),n=t.getAbsoluteScale(i),o=t.getAbsolutePosition(i),a=r.x*n.x-t.offsetX()*n.x,h=r.y*n.y-t.offsetY()*n.y,l=(s.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return ai({x:o.x+a*Math.cos(l)+h*Math.sin(-l),y:o.y+h*Math.cos(l)+a*Math.sin(l),width:r.width*n.x,height:r.height*n.y,rotation:l},-s.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map(e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),s=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],r=e.getAbsoluteTransform();s.forEach(function(e){const i=r.point(e);t.push(i)})});const e=new o;e.rotate(-s.getAngle(this.rotation()));let i=1/0,r=1/0,n=-1/0,a=-1/0;t.forEach(function(t){const s=e.point(t);void 0===i&&(i=n=s.x,r=a=s.y),i=Math.min(i,s.x),r=Math.min(r,s.y),n=Math.max(n,s.x),a=Math.max(a,s.y)}),e.invert();const h=e.point({x:i,y:r});return{x:h.x,y:h.y,width:n-i,height:a-r,rotation:s.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(),oi.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new Re({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:ni?10:"auto"}),i=this;e.on("mousedown touchstart",function(t){i._handleMouseDown(t)}),e.on("dragstart",t=>{e.stopDrag(),t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),e.on("mouseenter",()=>{const i=s.getAngle(this.rotation()),r=this.rotateAnchorCursor(),n=function(t,e,i){if("rotater"===t)return i;e+=_.degToRad(ri[t]||0);const s=(_.radToDeg(e)%360+360)%360;return _._inRange(s,337.5,360)||_._inRange(s,0,22.5)?"ns-resize":_._inRange(s,22.5,67.5)?"nesw-resize":_._inRange(s,67.5,112.5)?"ew-resize":_._inRange(s,112.5,157.5)?"nwse-resize":_._inRange(s,157.5,202.5)?"ns-resize":_._inRange(s,202.5,247.5)?"nesw-resize":_._inRange(s,247.5,292.5)?"ew-resize":_._inRange(s,292.5,337.5)?"nwse-resize":(_.error("Transformer has unknown angle for cursor detection: "+s),"pointer")}(t,i,r);e.getStage().content&&(e.getStage().content.style.cursor=n),this._cursorChange=!0}),e.on("mouseout",()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(e)}_createBack(){const t=new Yt({name:"back",width:0,height:0,sceneFunc(t,e){const i=e.getParent(),s=i.padding();t.beginPath(),t.rect(-s,-s,e.width()+2*s,e.height()+2*s),t.moveTo(e.width()/2,-s),i.rotateEnabled()&&i.rotateLineVisible()&&t.lineTo(e.width()/2,-i.rotateAnchorOffset()*_._sign(e.height())-s),t.fillStrokeShape(e)},hitFunc:(t,e)=>{if(!this.shouldOverdrawWholeArea())return;const i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}});this.add(t),this._proxyDrag(t),t.on("dragstart",t=>{t.cancelBubble=!0}),t.on("dragmove",t=>{t.cancelBubble=!0}),t.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{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,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/r),this.cos=Math.abs(i/r),"undefined"!=typeof window&&(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 n=t.target.getAbsolutePosition(),o=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:o.x-n.x,y:o.y-n.y},li++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(e=>{e._fire("transformstart",{evt:t.evt,target:e})})}_handleMouseMove(t){let e,i,r;const n=this.findOne("."+this._movingAnchorName),o=n.getStage();o.setPointersPositions(t);const a=o.getPointerPosition();let h={x:a.x-this._anchorDragOffset.x,y:a.y-this._anchorDragOffset.y};const l=n.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),n.setAbsolutePosition(h);const d=n.getAbsolutePosition();if(l.x===d.x&&l.y===d.y)return;if("rotater"===this._movingAnchorName){const r=this._getNodeRect();e=n.x()-r.width/2,i=-n.y()+r.height/2;let o=Math.atan2(-i,e)+Math.PI/2;r.height<0&&(o-=Math.PI);const a=s.getAngle(this.rotation())+o,h=s.getAngle(this.rotationSnapTolerance()),l=function(t,e,i){let r=e;for(let n=0;n<t.length;n++){const o=s.getAngle(t[n]),a=Math.abs(o-e)%(2*Math.PI);Math.min(a,2*Math.PI-a)<i&&(r=o)}return r}(this.rotationSnaps(),a,h),d=hi(r,l-r.rotation);return void this._fitNodesInto(d,t)}const c=this.shiftBehavior();let g;g="inverted"===c?this.keepRatio()&&!t.shiftKey:"none"===c?this.keepRatio():this.keepRatio()||t.shiftKey;let f=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};r=Math.sqrt(Math.pow(t.x-n.x(),2)+Math.pow(t.y-n.y(),2));const s=this.findOne(".top-left").x()>t.x?-1:1,o=this.findOne(".top-left").y()>t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,this.findOne(".top-left").x(t.x-e),this.findOne(".top-left").y(t.y-i)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(n.y());else if("top-right"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};r=Math.sqrt(Math.pow(n.x()-t.x,2)+Math.pow(t.y-n.y(),2));const s=this.findOne(".top-right").x()<t.x?-1:1,o=this.findOne(".top-right").y()>t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,this.findOne(".top-right").x(t.x+e),this.findOne(".top-right").y(t.y-i)}var u=n.position();this.findOne(".top-left").y(u.y),this.findOne(".bottom-right").x(u.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(n.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(n.x());else if("bottom-left"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};r=Math.sqrt(Math.pow(t.x-n.x(),2)+Math.pow(n.y()-t.y,2));const s=t.x<n.x()?-1:1,o=n.y()<t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,n.x(t.x-e),n.y(t.y+i)}u=n.position(),this.findOne(".top-left").x(u.x),this.findOne(".bottom-right").y(u.y)}else if("bottom-center"===this._movingAnchorName)this.findOne(".bottom-right").y(n.y());else if("bottom-right"===this._movingAnchorName){if(g){const t=f?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};r=Math.sqrt(Math.pow(n.x()-t.x,2)+Math.pow(n.y()-t.y,2));const s=this.findOne(".bottom-right").x()<t.x?-1:1,o=this.findOne(".bottom-right").y()<t.y?-1:1;e=r*this.cos*s,i=r*this.sin*o,this.findOne(".bottom-right").x(t.x+e),this.findOne(".bottom-right").y(t.y+i)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(f=this.centeredScaling()||t.altKey,f){const t=this.findOne(".top-left"),e=this.findOne(".bottom-right"),i=t.x(),s=t.y(),r=this.getWidth()-e.x(),n=this.getHeight()-e.y();e.move({x:-i,y:-s}),t.move({x:r,y:n})}const p=this.findOne(".top-left").getAbsolutePosition();e=p.x,i=p.y;const _=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),m=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:i,width:_,height:m,rotation:s.getAngle(this.rotation())},t)}_handleMouseUp(t){this._removeEvents(t)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(t){var e;if(this._transforming){this._transforming=!1,"undefined"!=typeof window&&(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();li--,this._fire("transformend",{evt:t,target:i}),null===(e=this.getLayer())||void 0===e||e.batchDraw(),i&&this._nodes.forEach(e=>{var i;e._fire("transformend",{evt:t,target:e}),null===(i=e.getLayer())||void 0===i||i.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const i=this._getNodeRect();if(_._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(_._inRange(t.height,2*-this.padding()-1,1))return void this.update();const r=new o;if(r.rotate(s.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=r.point({x:2*-this.padding(),y:0});t.x+=e.x,t.y+=e.y,t.width+=2*this.padding(),this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const e=r.point({x:2*this.padding(),y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.width+=2*this.padding()}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const e=r.point({x:0,y:2*-this.padding()});t.x+=e.x,t.y+=e.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const e=r.point({x:0,y:2*this.padding()});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(i,t);e?t=e:_.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const n=1e7,a=new o;a.translate(i.x,i.y),a.rotate(i.rotation),a.scale(i.width/n,i.height/n);const h=new o,l=t.width/n,d=t.height/n;!1===this.flipEnabled()?(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(d))):(h.translate(t.x,t.y),h.rotate(t.rotation),h.scale(l,d));const c=h.multiply(a.invert());this._nodes.forEach(t=>{var e;if(!t.getStage())return;const i=t.getParent().getAbsoluteTransform(),s=t.getTransform().copy();s.translate(t.offsetX(),t.offsetY());const r=new o;r.multiply(i.copy().invert()).multiply(c).multiply(i).multiply(s);const n=r.decompose();t.setAttrs(n),null===(e=t.getLayer())||void 0===e||e.batchDraw()}),this.rotation(_._getRotation(t.rotation)),this._nodes.forEach(t=>{this._fire("transform",{evt:e,target:t}),t._fire("transform",{evt:e,target:t})}),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,r=this.enabledAnchors(),n=this.resizeEnabled(),o=this.padding(),a=this.anchorSize(),h=this.find("._anchor");h.forEach(t=>{t.setAttrs({width:a,height:a,offsetX:a/2,offsetY:a/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:a/2+o,offsetY:a/2+o,visible:n&&r.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:a/2+o,visible:n&&r.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:a/2-o,offsetY:a/2+o,visible:n&&r.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:a/2+o,visible:n&&r.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:a/2-o,visible:n&&r.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:a/2+o,offsetY:a/2-o,visible:n&&r.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:a/2-o,visible:n&&r.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:a/2-o,offsetY:a/2-o,visible:n&&r.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*_._sign(s)-o,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(t=>t.draggable()),x:0,y:0});const l=this.anchorStyleFunc();l&&h.forEach(t=>{l(t)}),null===(t=this.getLayer())||void 0===t||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=""),Vt.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return $.prototype.toObject.call(this)}clone(t){return $.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}di.isTransforming=()=>li>0,di.prototype.className="Transformer",r(di),W.addGetterSetter(di,"enabledAnchors",oi,function(t){return t instanceof Array||_.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach(function(t){-1===oi.indexOf(t)&&_.warn("Unknown anchor name: "+t+". Available names are: "+oi.join(", "))}),t||[]}),W.addGetterSetter(di,"flipEnabled",!0,O()),W.addGetterSetter(di,"resizeEnabled",!0),W.addGetterSetter(di,"anchorSize",10,R()),W.addGetterSetter(di,"rotateEnabled",!0),W.addGetterSetter(di,"rotateLineVisible",!0),W.addGetterSetter(di,"rotationSnaps",[]),W.addGetterSetter(di,"rotateAnchorOffset",50,R()),W.addGetterSetter(di,"rotateAnchorCursor","crosshair"),W.addGetterSetter(di,"rotationSnapTolerance",5,R()),W.addGetterSetter(di,"borderEnabled",!0),W.addGetterSetter(di,"anchorStroke","rgb(0, 161, 255)"),W.addGetterSetter(di,"anchorStrokeWidth",1,R()),W.addGetterSetter(di,"anchorFill","white"),W.addGetterSetter(di,"anchorCornerRadius",0,R()),W.addGetterSetter(di,"borderStroke","rgb(0, 161, 255)"),W.addGetterSetter(di,"borderStrokeWidth",1,R()),W.addGetterSetter(di,"borderDash"),W.addGetterSetter(di,"keepRatio",!0),W.addGetterSetter(di,"shiftBehavior","default"),W.addGetterSetter(di,"centeredScaling",!1),W.addGetterSetter(di,"ignoreStroke",!1),W.addGetterSetter(di,"padding",0,R()),W.addGetterSetter(di,"nodes"),W.addGetterSetter(di,"node"),W.addGetterSetter(di,"boundBoxFunc"),W.addGetterSetter(di,"anchorDragBoundFunc"),W.addGetterSetter(di,"anchorStyleFunc"),W.addGetterSetter(di,"shouldOverdrawWholeArea",!1),W.addGetterSetter(di,"useSingleNodeRotation",!0),W.backCompat(di,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class ci extends Yt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,s.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}function gi(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}ci.prototype.className="Wedge",ci.prototype._centroid=!0,ci.prototype._attrsAffectingSize=["radius"],r(ci),W.addGetterSetter(ci,"radius",0,R()),W.addGetterSetter(ci,"angle",0,R()),W.addGetterSetter(ci,"clockwise",!1),W.backCompat(ci,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});const fi=[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],ui=[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];W.addGetterSetter($,"blurRadius",0,R(),W.afterSetFilter);W.addGetterSetter($,"brightness",0,R(),W.afterSetFilter);W.addGetterSetter($,"contrast",0,R(),W.afterSetFilter);function pi(t,e,i,s,r){const n=i-e,o=r-s;if(0===n)return s+o/2;if(0===o)return s;let a=(t-e)/n;return a=o*a+s,a}W.addGetterSetter($,"embossStrength",.5,R(),W.afterSetFilter),W.addGetterSetter($,"embossWhiteLevel",.5,R(),W.afterSetFilter),W.addGetterSetter($,"embossDirection","top-left",void 0,W.afterSetFilter),W.addGetterSetter($,"embossBlend",!1,void 0,W.afterSetFilter);W.addGetterSetter($,"enhance",0,R(),W.afterSetFilter);W.addGetterSetter($,"hue",0,R(),W.afterSetFilter),W.addGetterSetter($,"saturation",0,R(),W.afterSetFilter),W.addGetterSetter($,"luminance",0,R(),W.afterSetFilter);W.addGetterSetter($,"hue",0,R(),W.afterSetFilter),W.addGetterSetter($,"saturation",0,R(),W.afterSetFilter),W.addGetterSetter($,"value",0,R(),W.afterSetFilter);function _i(t,e,i){let s=4*(i*t.width+e);const r=[];return r.push(t.data[s++],t.data[s++],t.data[s++],t.data[s++]),r}function mi(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}W.addGetterSetter($,"kaleidoscopePower",2,R(),W.afterSetFilter),W.addGetterSetter($,"kaleidoscopeAngle",0,R(),W.afterSetFilter);W.addGetterSetter($,"threshold",0,R(),W.afterSetFilter);W.addGetterSetter($,"noise",.2,R(),W.afterSetFilter);W.addGetterSetter($,"pixelSize",8,R(),W.afterSetFilter);W.addGetterSetter($,"levels",.5,R(),W.afterSetFilter);W.addGetterSetter($,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"blue",0,M,W.afterSetFilter);W.addGetterSetter($,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),W.addGetterSetter($,"blue",0,M,W.afterSetFilter),W.addGetterSetter($,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t});W.addGetterSetter($,"threshold",.5,R(),W.afterSetFilter);const yi=re.Util._assign(re,{Arc:ne,Arrow:ye,Circle:xe,Ellipse:ve,Image:we,Label:Pe,Tag:Me,Line:he,Path:me,Rect:Re,RegularPolygon:Ie,Ring:Le,Sprite:Ge,Star:Oe,Text:Ve,TextPath:$e,Transformer:di,Wedge:ci,Filters:{Blur:function(t){const e=Math.round(this.blurRadius());e>0&&function(t,e){const i=t.data,s=t.width,r=t.height;let n,o,a,h,l,d,c,g,f,u,p,_,m,y,x,v,w,S,b,C;const T=e+e+1,A=s-1,k=r-1,P=e+1,M=P*(P+1)/2,R=new gi,I=fi[e],E=ui[e];let L=null,G=R,O=null,D=null;for(let t=1;t<T;t++)G=G.next=new gi,t===P&&(L=G);G.next=R,a=o=0;for(let t=0;t<r;t++){_=m=y=x=h=l=d=c=0,g=P*(v=i[o]),f=P*(w=i[o+1]),u=P*(S=i[o+2]),p=P*(b=i[o+3]),h+=M*v,l+=M*w,d+=M*S,c+=M*b,G=R;for(let t=0;t<P;t++)G.r=v,G.g=w,G.b=S,G.a=b,G=G.next;for(let t=1;t<P;t++)n=o+((A<t?A:t)<<2),h+=(G.r=v=i[n])*(C=P-t),l+=(G.g=w=i[n+1])*C,d+=(G.b=S=i[n+2])*C,c+=(G.a=b=i[n+3])*C,_+=v,m+=w,y+=S,x+=b,G=G.next;O=R,D=L;for(let t=0;t<s;t++)i[o+3]=b=c*I>>E,0!==b?(b=255/b,i[o]=(h*I>>E)*b,i[o+1]=(l*I>>E)*b,i[o+2]=(d*I>>E)*b):i[o]=i[o+1]=i[o+2]=0,h-=g,l-=f,d-=u,c-=p,g-=O.r,f-=O.g,u-=O.b,p-=O.a,n=a+((n=t+e+1)<A?n:A)<<2,_+=O.r=i[n],m+=O.g=i[n+1],y+=O.b=i[n+2],x+=O.a=i[n+3],h+=_,l+=m,d+=y,c+=x,O=O.next,g+=v=D.r,f+=w=D.g,u+=S=D.b,p+=b=D.a,_-=v,m-=w,y-=S,x-=b,D=D.next,o+=4;a+=s}for(let t=0;t<s;t++){m=y=x=_=l=d=c=h=0,o=t<<2,g=P*(v=i[o]),f=P*(w=i[o+1]),u=P*(S=i[o+2]),p=P*(b=i[o+3]),h+=M*v,l+=M*w,d+=M*S,c+=M*b,G=R;for(let t=0;t<P;t++)G.r=v,G.g=w,G.b=S,G.a=b,G=G.next;let a=s;for(let r=1;r<=e;r++)o=a+t<<2,h+=(G.r=v=i[o])*(C=P-r),l+=(G.g=w=i[o+1])*C,d+=(G.b=S=i[o+2])*C,c+=(G.a=b=i[o+3])*C,_+=v,m+=w,y+=S,x+=b,G=G.next,r<k&&(a+=s);o=t,O=R,D=L;for(let e=0;e<r;e++)n=o<<2,i[n+3]=b=c*I>>E,b>0?(b=255/b,i[n]=(h*I>>E)*b,i[n+1]=(l*I>>E)*b,i[n+2]=(d*I>>E)*b):i[n]=i[n+1]=i[n+2]=0,h-=g,l-=f,d-=u,c-=p,g-=O.r,f-=O.g,u-=O.b,p-=O.a,n=t+((n=e+P)<k?n:k)*s<<2,h+=_+=O.r=i[n],l+=m+=O.g=i[n+1],d+=y+=O.b=i[n+2],c+=x+=O.a=i[n+3],O=O.next,g+=v=D.r,f+=w=D.g,u+=S=D.b,p+=b=D.a,_-=v,m-=w,y-=S,x-=b,D=D.next,o+=s}}(t,e)},Brightness:function(t){const e=this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]=Math.min(255,i[t]*e),i[t+1]=Math.min(255,i[t+1]*e),i[t+2]=Math.min(255,i[t+2]*e)},Brighten:function(t){const e=255*this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]+=e,i[t+1]+=e,i[t+2]+=e},Contrast:function(t){const e=Math.pow((this.contrast()+100)/100,2),i=t.data,s=i.length;let r=150,n=150,o=150;for(let t=0;t<s;t+=4)r=i[t],n=i[t+1],o=i[t+2],r/=255,r-=.5,r*=e,r+=.5,r*=255,n/=255,n-=.5,n*=e,n+=.5,n*=255,o/=255,o-=.5,o*=e,o+=.5,o*=255,r=r<0?0:r>255?255:r,n=n<0?0:n>255?255:n,o=o<0?0:o>255?255:o,i[t]=r,i[t+1]=n,i[t+2]=o},Emboss:function(t){var e,i,s,r,n,o,a,h,l;const d=t.data,c=t.width,g=t.height,f=Math.min(1,Math.max(0,null!==(i=null===(e=this.embossStrength)||void 0===e?void 0:e.call(this))&&void 0!==i?i:.5)),u=Math.min(1,Math.max(0,null!==(r=null===(s=this.embossWhiteLevel)||void 0===s?void 0:s.call(this))&&void 0!==r?r:.5)),p=null!==(a={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[null!==(o=null===(n=this.embossDirection)||void 0===n?void 0:n.call(this))&&void 0!==o?o:"top-left"])&&void 0!==a?a:315,_=!(null===(l=null===(h=this.embossBlend)||void 0===h?void 0:h.call(this))||void 0===l||!l),m=10*f,y=255*u,x=p*Math.PI/180,v=Math.cos(x),w=Math.sin(x),S=128/1020*m,b=new Uint8ClampedArray(d),C=new Float32Array(c*g);for(let t=0,e=0;e<d.length;e+=4,t++)C[t]=.2126*b[e]+.7152*b[e+1]+.0722*b[e+2];const T=[-1,0,1,-2,0,2,-1,0,1],A=[-1,-2,-1,0,0,0,1,2,1],k=[-c-1,-c,1-c,-1,0,1,c-1,c,c+1],P=t=>t<0?0:t>255?255:t;for(let t=1;t<g-1;t++)for(let e=1;e<c-1;e++){const i=t*c+e;let s=0,r=0;s+=C[i+k[0]]*T[0],r+=C[i+k[0]]*A[0],s+=C[i+k[1]]*T[1],r+=C[i+k[1]]*A[1],s+=C[i+k[2]]*T[2],r+=C[i+k[2]]*A[2],s+=C[i+k[3]]*T[3],r+=C[i+k[3]]*A[3],s+=C[i+k[5]]*T[5],r+=C[i+k[5]]*A[5],s+=C[i+k[6]]*T[6],r+=C[i+k[6]]*A[6],s+=C[i+k[7]]*T[7],r+=C[i+k[7]]*A[7],s+=C[i+k[8]]*T[8],r+=C[i+k[8]]*A[8];const n=P(y+(v*s+w*r)*S),o=4*i;if(_){const t=n-y;d[o]=P(b[o]+t),d[o+1]=P(b[o+1]+t),d[o+2]=P(b[o+2]+t),d[o+3]=b[o+3]}else d[o]=d[o+1]=d[o+2]=n,d[o+3]=b[o+3]}for(let t=0;t<c;t++){let e=4*t,i=4*((g-1)*c+t);d[e]=b[e],d[e+1]=b[e+1],d[e+2]=b[e+2],d[e+3]=b[e+3],d[i]=b[i],d[i+1]=b[i+1],d[i+2]=b[i+2],d[i+3]=b[i+3]}for(let t=1;t<g-1;t++){let e=t*c*4,i=4*(t*c+(c-1));d[e]=b[e],d[e+1]=b[e+1],d[e+2]=b[e+2],d[e+3]=b[e+3],d[i]=b[i],d[i+1]=b[i+1],d[i+2]=b[i+2],d[i+3]=b[i+3]}return t},Enhance:function(t){const e=t.data,i=e.length;let s,r,n,o=e[0],a=o,h=e[1],l=h,d=e[2],c=d;const g=this.enhance();if(0===g)return;for(let t=0;t<i;t+=4)s=e[t+0],s<o?o=s:s>a&&(a=s),r=e[t+1],r<h?h=r:r>l&&(l=r),n=e[t+2],n<d?d=n:n>c&&(c=n);let f,u,p,_,m,y;if(a===o&&(a=255,o=0),l===h&&(l=255,h=0),c===d&&(c=255,d=0),g>0)f=a+g*(255-a),u=o-g*(o-0),p=l+g*(255-l),_=h-g*(h-0),m=c+g*(255-c),y=d-g*(d-0);else{const t=.5*(a+o);f=a+g*(a-t),u=o+g*(o-t);const e=.5*(l+h);p=l+g*(l-e),_=h+g*(h-e);const i=.5*(c+d);m=c+g*(c-i),y=d+g*(d-i)}for(let t=0;t<i;t+=4)e[t+0]=pi(e[t+0],o,a,u,f),e[t+1]=pi(e[t+1],h,l,_,p),e[t+2]=pi(e[t+2],d,c,y,m)},Grayscale:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=.34*e[t]+.5*e[t+1]+.16*e[t+2];e[t]=i,e[t+1]=i,e[t+2]=i}},HSL:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.saturation()),r=Math.abs(this.hue()+360)%360,n=127*this.luminance(),o=1*s*Math.cos(r*Math.PI/180),a=1*s*Math.sin(r*Math.PI/180),h=.299+.701*o+.167*a,l=.587-.587*o+.33*a,d=.114-.114*o-.497*a,c=.299-.299*o-.328*a,g=.587+.413*o+.035*a,f=.114-.114*o+.293*a,u=.299-.3*o+1.25*a,p=.587-.586*o-1.05*a,_=.114+.886*o-.2*a;let m,y,x,v;for(let t=0;t<i;t+=4)m=e[t+0],y=e[t+1],x=e[t+2],v=e[t+3],e[t+0]=h*m+l*y+d*x+n,e[t+1]=c*m+g*y+f*x+n,e[t+2]=u*m+p*y+_*x+n,e[t+3]=v},HSV:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.value()),r=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,o=s*r*Math.cos(n*Math.PI/180),a=s*r*Math.sin(n*Math.PI/180),h=.299*s+.701*o+.167*a,l=.587*s-.587*o+.33*a,d=.114*s-.114*o-.497*a,c=.299*s-.299*o-.328*a,g=.587*s+.413*o+.035*a,f=.114*s-.114*o+.293*a,u=.299*s-.3*o+1.25*a,p=.587*s-.586*o-1.05*a,_=.114*s+.886*o-.2*a;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2],n=e[t+3];e[t+0]=h*i+l*s+d*r,e[t+1]=c*i+g*s+f*r,e[t+2]=u*i+p*s+_*r,e[t+3]=n}},Invert:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},Kaleidoscope:function(t){const e=t.width,i=t.height;let s,r,n,o,a,h,l,d,c,g,f=Math.round(this.kaleidoscopePower());const u=Math.round(this.kaleidoscopeAngle()),p=Math.floor(e*(u%360)/360);if(f<1)return;const m=_.createCanvasElement();m.width=e,m.height=i;const y=m.getContext("2d").getImageData(0,0,e,i);_.releaseCanvas(m),function(t,e,i){const s=t.data,r=e.data,n=t.width,o=t.height,a=i.polarCenterX||n/2,h=i.polarCenterY||o/2;let l=Math.sqrt(a*a+h*h),d=n-a,c=o-h;const g=Math.sqrt(d*d+c*c);l=g>l?g:l;const f=o,u=n,p=360/u*Math.PI/180;for(let t=0;t<u;t+=1){const e=Math.sin(t*p),i=Math.cos(t*p);for(let o=0;o<f;o+=1){d=Math.floor(a+l*o/f*i),c=Math.floor(h+l*o/f*e);let g=4*(c*n+d);const u=s[g+0],p=s[g+1],_=s[g+2],m=s[g+3];g=4*(t+o*n),r[g+0]=u,r[g+1]=p,r[g+2]=_,r[g+3]=m}}}(t,y,{polarCenterX:e/2,polarCenterY:i/2});let x=e/Math.pow(2,f);for(;x<=8;)x*=2,f-=1;x=Math.ceil(x);let v=x,w=0,S=v,b=1;for(p+x>e&&(w=v,S=0,b=-1),r=0;r<i;r+=1)for(s=w;s!==S;s+=b)n=Math.round(s+p)%e,c=4*(e*r+n),a=y.data[c+0],h=y.data[c+1],l=y.data[c+2],d=y.data[c+3],g=4*(e*r+s),y.data[g+0]=a,y.data[g+1]=h,y.data[g+2]=l,y.data[g+3]=d;for(r=0;r<i;r+=1)for(v=Math.floor(x),o=0;o<f;o+=1){for(s=0;s<v+1;s+=1)c=4*(e*r+s),a=y.data[c+0],h=y.data[c+1],l=y.data[c+2],d=y.data[c+3],g=4*(e*r+2*v-s-1),y.data[g+0]=a,y.data[g+1]=h,y.data[g+2]=l,y.data[g+3]=d;v*=2}!function(t,e,i){const s=t.data,r=e.data,n=t.width,o=t.height,a=i.polarCenterX||n/2,h=i.polarCenterY||o/2;let l=Math.sqrt(a*a+h*h),d=n-a,c=o-h;const g=Math.sqrt(d*d+c*c);l=g>l?g:l;const f=o,u=n;let p,_;for(d=0;d<n;d+=1)for(c=0;c<o;c+=1){const t=d-a,e=c-h,i=Math.sqrt(t*t+e*e)*f/l;let o=(180*Math.atan2(e,t)/Math.PI+360+0)%360;o=o*u/360,p=Math.floor(o),_=Math.floor(i);let g=4*(_*n+p);const m=s[g+0],y=s[g+1],x=s[g+2],v=s[g+3];g=4*(c*n+d),r[g+0]=m,r[g+1]=y,r[g+2]=x,r[g+3]=v}}(y,t,{})},Mask:function(t){let e=function(t,e){const i=_i(t,0,0),s=_i(t,t.width-1,0),r=_i(t,0,t.height-1),n=_i(t,t.width-1,t.height-1),o=e||10;if(mi(i,s)<o&&mi(s,n)<o&&mi(n,r)<o&&mi(r,i)<o){const e=function(t){const e=[0,0,0];for(let i=0;i<t.length;i++)e[0]+=t[i][0],e[1]+=t[i][1],e[2]+=t[i][2];return e[0]/=t.length,e[1]/=t.length,e[2]/=t.length,e}([s,i,n,r]),a=[];for(let i=0;i<t.width*t.height;i++){const s=mi(e,[t.data[4*i],t.data[4*i+1],t.data[4*i+2]]);a[i]=s<o?0:255}return a}}(t,this.threshold());return e&&(e=function(t,e,i){const s=[1,1,1,1,0,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<r;o++)for(let l=0;l<r;l++){const c=a+o-n,g=h+l-n;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*r+l];d+=t[c*e+g]*i}}o[l]=2040===d?255:0}return o}(e,t.width,t.height),e=function(t,e,i){const s=[1,1,1,1,1,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<r;o++)for(let l=0;l<r;l++){const c=a+o-n,g=h+l-n;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*r+l];d+=t[c*e+g]*i}}o[l]=d>=1020?255:0}return o}(e,t.width,t.height),e=function(t,e,i){const s=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<r;o++)for(let l=0;l<r;l++){const c=a+o-n,g=h+l-n;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*r+l];d+=t[c*e+g]*i}}o[l]=d}return o}(e,t.width,t.height),function(t,e){for(let i=0;i<t.width*t.height;i++)t.data[4*i+3]=e[i]}(t,e)),t},Noise:function(t){const e=255*this.noise(),i=t.data,s=i.length,r=e/2;for(let t=0;t<s;t+=4)i[t+0]+=r-2*r*Math.random(),i[t+1]+=r-2*r*Math.random(),i[t+2]+=r-2*r*Math.random()},Pixelate:function(t){let e=Math.ceil(this.pixelSize()),i=t.width,s=t.height,r=Math.ceil(i/e),n=Math.ceil(s/e),o=t.data;if(e<=0)_.error("pixelSize value can not be <= 0");else for(let t=0;t<r;t+=1)for(let r=0;r<n;r+=1){let n=0,a=0,h=0,l=0;const d=t*e,c=d+e,g=r*e,f=g+e;let u=0;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=g;e<f;e+=1){if(e>=s)continue;const r=4*(i*e+t);n+=o[r+0],a+=o[r+1],h+=o[r+2],l+=o[r+3],u+=1}n/=u,a/=u,h/=u,l/=u;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=g;e<f;e+=1){if(e>=s)continue;const r=4*(i*e+t);o[r+0]=n,o[r+1]=a,o[r+2]=h,o[r+3]=l}}},Posterize:function(t){const e=Math.round(254*this.levels())+1,i=t.data,s=i.length,r=255/e;for(let t=0;t<s;t+=1)i[t]=Math.floor(i[t]/r)*r},RGB:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue();for(let t=0;t<i;t+=4){const i=(.34*e[t]+.5*e[t+1]+.16*e[t+2])/255;e[t]=i*s,e[t+1]=i*r,e[t+2]=i*n,e[t+3]=e[t+3]}},RGBA:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue(),o=this.alpha();for(let t=0;t<i;t+=4){const i=1-o;e[t]=s*o+e[t]*i,e[t+1]=r*o+e[t+1]*i,e[t+2]=n*o+e[t+2]*i}},Sepia:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2];e[t+0]=Math.min(255,.393*i+.769*s+.189*r),e[t+1]=Math.min(255,.349*i+.686*s+.168*r),e[t+2]=Math.min(255,.272*i+.534*s+.131*r)}},Solarize:function(t){const e=t.data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2];.2126*i+.7152*s+.0722*r>=128&&(e[t]=255-i,e[t+1]=255-s,e[t+2]=255-r)}return t},Threshold:function(t){const e=255*this.threshold(),i=t.data,s=i.length;for(let t=0;t<s;t+=1)i[t]=i[t]<e?0:255}}});class xi{screenToWorld(t){return{x:t.x,y:t.y,z:0}}worldToScreen(t){return{x:t.x,y:t.y}}getScale(){return{x:1,y:1,z:1}}}class vi{constructor(t,e,i){this.setColor(t,e,i)}asHex(){return"#"+this.HEX}asRGB(){return{r:this.R,g:this.G,b:this.B}}setColor(t,e,i){this.R=t,this.G=e,this.B=i,this.HEX=this.rgbToHex(t,e,i)}rgbToHex(t,e,i){const s=t=>{const e=t.toString(16);return"0"===e?"00":e};return s(t)+s(e)+s(i)}}const wi=new Map([["solid",[]],["dot",[30,30,.001,30]],["dash",[30,30]]]);class Si{constructor(t,e=null,i=new xi){var s,r;if(this._worldTransformer=i,e){this._ref=e;let t=this._ref.getAttr("wcsPoints");if(!t){t=[];const e=this._ref.points();let i;for(let s=0;s<e.length;s+=2)i=this._worldTransformer.screenToWorld({x:e[s],y:e[s+1]}),t.push({x:i.x,y:i.y,z:i.z});this._ref.setAttr("wcsPoints",t)}return}t||(t={}),t.points||(t.points=[{x:0,y:0},{x:100,y:100}]);const n=[],o=[];t.points.forEach(t=>{n.push(t.x,t.y);const e=this._worldTransformer.screenToWorld({x:t.x,y:t.y});o.push({x:e.x,y:e.y,z:e.z})}),this._ref=new yi.Line({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.width)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:n,draggable:!0,strokeScaleEnabled:!1,dash:wi.get(t.type)||[]}),this._ref.setAttr("wcsPoints",o),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation)}),this._ref.on("transformend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.on("dragend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Line"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){return this._ref.points()}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}getLineType(){let t;switch(this._ref.dash()||[]){case wi.get("dot"):t="dot";break;case wi.get("dash"):t="dash";break;default:t="solid"}return t}setLineType(t){const e=wi.get(t);e&&this._ref.dash(e)}addPoints(t){let e=this._ref.points();const i=this._ref.getAttr("wcsPoints");t.forEach(t=>{e=e.concat([t.x,t.y]);const s=this._worldTransformer.screenToWorld(t);i.push(s)}),this._ref.points(e)}updateScreenCoordinates(){const t=this._ref.getAttr("wcsPoints"),e=[];let i=this._ref.getAbsoluteTransform().copy();i=i.invert(),t.forEach(t=>{let s=this._worldTransformer.worldToScreen(t);s=i.point({x:s.x,y:s.y}),e.push(s.x),e.push(s.y)}),this._ref.points([]),this._ref.points(e),this._ref.clearCache()}}class bi{constructor(t,e=null,i=new xi){var s,r,n;if(this.TEXT_FONT_FAMILY="Calibri",this._worldTransformer=i,e){this._ref=e;return void(this._ref.getAttr("wcsStart")||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.text||(t.text="default"),this._ref=new yi.Text({x:t.position.x,y:t.position.y,text:t.text,fontSize:null!==(s=t.fontSize)&&void 0!==s?s:34,fontFamily:this.TEXT_FONT_FAMILY,fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",align:"left",draggable:!0,rotation:null!==(n=t.rotation)&&void 0!==n?n:0}),this._ref.width(this._ref.getTextWidth()),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<Math.round(this.getFontSize())&&(n=Math.round(this.getFontSize())),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Text"}getColor(){return this._ref.fill()}setColor(t){this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getText(){return this._ref.text()}setText(t){this._ref.text(t)}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getFontSize(){return this._ref.fontSize()}setFontSize(t){this._ref.fontSize(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));let e=this._ref.getStage().getAbsoluteTransform().copy();e=e.invert();const i=e.point(t);this._ref.position({x:i.x,y:i.y})}}class Ci{constructor(t,e=null,i=new xi){var s,r,n,o;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200),this._ref=new yi.Rect({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.lineWidth)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,width:null!==(n=t.width)&&void 0!==n?n:200,height:null!==(o=t.height)&&void 0!==o?o:200,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}getWidth(){return this._ref.width()}getHeight(){return this._ref.height()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Rectangle"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}function Ti(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}class Ai{constructor(t,e=null,i=new xi){var s,r,n;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsPosition"),i=this._ref.getAttr("wcsRadiusX"),s=this._ref.getAttr("wcsRadiusY");return t||this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),i||this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:e.x()+e.radiusX(),y:e.y()})),void(s||this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()+e.radiusY()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(null!==(s=t.radius)&&void 0!==s||(t.radius={x:0,y:0}),t.radius.x=Ti(t.position,t.position2),t.position3?t.radius.y=Ti(t.position,t.position3):t.radius.x=t.radius.y):t.radius||(t.radius={x:25,y:25}),this._ref=new yi.Ellipse({stroke:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:null!==(n=t.lineWidth)&&void 0!==n?n:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,radiusX:t.radius.x,radiusY:t.radius.y,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t.radius.x,y:this._ref.y()})),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t.radius.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.radiusX();i&&(r*=e.scaleX);let n=this._ref.radiusY();s&&(n*=e.scaleY);r<25&&(r=25),n<25&&(n=25),t.evt.ctrlKey||t.evt.shiftKey?i?this._ref.radius({x:r,y:r}):this._ref.radius({x:n,y:n}):this._ref.radius({x:r,y:n}),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t,y:e}))}getRadiusX(){return this._ref.radiusX()}setRadiusX(t){this._ref.radiusX(t),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t,y:this._ref.y()}))}getRadiusY(){return this._ref.radiusY()}setRadiusY(t){this._ref.radiusY(t),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t}))}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Ellipse"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX")),i=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));let s=this._ref.getStage().getAbsoluteTransform().copy();s=s.invert();const r=s.point({x:t.x,y:t.y});this._ref.position({x:r.x,y:r.y}),this._ref.radius({x:Math.abs(s.point(e).x-r.x),y:Math.abs(s.point(i).y-r.y)})}}class ki{constructor(t,e=null,i=new xi){var s,r;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");return t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.points()[0],y:e.points()[1]})),void(i||this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:e.points()[2],y:e.points()[3]})))}t||(t={}),t.start||(t.start={x:0,y:0}),t.end||(t.end={x:100,y:100}),this._ref=new yi.Arrow({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[t.start.x,t.start.y,t.end.x,t.end.y],draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.start.x,y:t.start.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.end.x,y:t.end.y})),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.points(),s=this._ref.getAbsoluteTransform(),r=s.point({x:i[0],y:i[1]}),n=s.point({x:i[2],y:i[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(r)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(n))}),this._ref.on("dragend",t=>{const e=this._ref.points(),i=t.target.getAbsoluteTransform(),s=i.point({x:e[0],y:e[1]}),r=i.point({x:e[2],y:e[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(s)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(r))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Arrow"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t),this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){const t=this._ref.points();return[{x:t[0],y:t[1]},{x:t[2],y:t[3]}]}setPoints(t){2===t.length&&(this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t[0].x,y:t[0].y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t[1].x,y:t[1].y})),this._ref.points([t[0].x,t[0].y,t[1].x,t[1].y]))}getStartPoint(){const t=this._ref.points();return{x:t[0],y:t[1]}}setStartPoint(t,e){const i=this._ref.points();this._ref.points([t,e,i[2],i[3]]),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getEndPoint(){const t=this._ref.points();return{x:t[2],y:t[3]}}setEndPoint(t,e){const i=this._ref.points();this._ref.points([i[0],i[1],t,e]),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t,y:e}))}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getAbsoluteTransform().copy();i=i.invert();const s=i.point({x:t.x,y:t.y}),r=i.point({x:e.x,y:e.y});this._ref.points([s.x,s.y,r.x,r.y])}}class Pi{constructor(t,e=null,i=new xi){var s,r;if(this._ratio=1,this.EPSILON=1e-5,this.BASE64_HEADER_START="data:image/",this.BASE64_NOT_FOUND="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=",this._worldTransformer=i,e){e.src&&e.src.startsWith(this.BASE64_HEADER_START)||(e.src=this.BASE64_NOT_FOUND),e.height()<=this.EPSILON&&e.height(32),e.width()<=this.EPSILON&&e.width(32),this._ref=e,this._canvasImage=e.image(),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width();const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.src&&t.src.startsWith(this.BASE64_HEADER_START)||(t.src=this.BASE64_NOT_FOUND),t.position2&&(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y),this._canvasImage=new Image,this._canvasImage.onload=()=>{if(this._ref.image(this._canvasImage),this._ref.height()<=this.EPSILON&&this._ref.height(this._canvasImage.height),this._ref.width()<=this.EPSILON&&this._ref.width(this._canvasImage.width),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width(),(t.width<=this.EPSILON||t.height<=this.EPSILON)&&(t.maxWidth>=this.EPSILON||t.maxWidth>=this.EPSILON)){const e=t.maxHeight-this._canvasImage.height,i=t.maxWidth-this._canvasImage.width;(e<=this.EPSILON||i<=this.EPSILON)&&(i<=this.EPSILON&&i<e/this._ratio?(this._ref.height(t.maxWidth*this._ratio),this._ref.width(t.maxWidth)):(this._ref.width(t.maxHeight/this._ratio),this._ref.height(t.maxHeight)))}const e=this._worldTransformer.screenToWorld({x:t.position.x+this._ref.width(),y:t.position.y+this._ref.height()});this._ref.setAttr("wcsEnd",e)},this._canvasImage.onerror=()=>{this._canvasImage.onerror=function(){},this._canvasImage.src=this.BASE64_NOT_FOUND},this._canvasImage.src=t.src,this._ref=new yi.Image({x:t.position.x,y:t.position.y,image:this._canvasImage,width:null!==(s=t.width)&&void 0!==s?s:0,height:null!==(r=t.height)&&void 0!==r?r:0,draggable:!0}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),t.position2&&this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),t.evt.ctrlKey||t.evt.shiftKey?i?(this._ref.width(r),this._ref.height(r*this._ratio)):(this._ref.width(n/this._ratio),this._ref.height(n)):(i&&this._ref.width(r),s&&this._ref.height(n)),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getSrc(){return this._canvasImage.src}setSrc(t){this._canvasImage.src=t}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t),this._ref.height(t*this._ratio);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t),this._ref.width(t/this._ratio);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Image"}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}class Mi{constructor(t,e=null,i=new xi){var s,r,n,o;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200);this._ref=new yi.Shape({x:t.position.x,y:t.position.y,width:null!==(s=t.width)&&void 0!==s?s:200,height:null!==(r=t.height)&&void 0!==r?r:200,stroke:null!==(n=t.color)&&void 0!==n?n:"#ff0000",strokeWidth:null!==(o=t.lineWidth)&&void 0!==o?o:4,draggable:!0,strokeScaleEnabled:!1,globalCompositeOperation:"source-over",sceneFunc:(t,e)=>{const i=this._ref.width(),s=this._ref.height(),r=[{x:0,y:0},{x:0+i,y:0},{x:0+i,y:0+s},{x:0,y:0+s},{x:0,y:0}];function n(n,o){const a={x:(h={x:0,y:0}).x+i/2,y:h.y+s/2};var h;t.beginPath();for(let e=0;e<r.length-1;e++){let i=o;const s=r[e+1].x-r[e].x,h=r[e+1].y-r[e].y,l=Math.sqrt(s*s+h*h),d=Math.floor(l/i);i=o+d/(l%i);let c=r[e].x+s/d/2,g=r[e].y+h/d/2;const f=r[e+1].x,u=r[e+1].y,p=Math.atan((u-g)/(f-c)),_=p+Math.PI,m=c>a.x&&g>a.y;for(let e=0;e<d;e++)m?t.arc(c,g,n,p,_):t.arc(c,g,n,_,p),c+=s/d,g+=h/d}t.closePath(),t.fillStrokeShape(e)}i>=49||s>=49?n(8,15):i>=25||s>=25?n(4,7.5):(t.beginPath(),t.lineTo(r[1].x,r[1].y),t.lineTo(r[2].x,r[2].y),t.lineTo(r[3].x,r[3].y),t.lineTo(r[4].x,r[4].y),t.closePath(),t.fillStrokeShape(e))}}),this._ref.className="Cloud",this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.getSelfRect=()=>({x:-8,y:-8,width:this._ref.width()+16,height:this._ref.height()+16}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Cloud"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.position({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}const Ri={SelectMarkup:{name:"SelectMarkup",initializer:null},Line:{name:"Line",initializer:(t,e=null,...i)=>new Si(e,t,...i)},Text:{name:"Text",initializer:(t,e=null,...i)=>new bi(e,t,...i)},Rectangle:{name:"Rect",initializer:(t,e=null,...i)=>new Ci(e,t,...i)},Ellipse:{name:"Ellipse",initializer:(t,e=null,...i)=>new Ai(e,t,...i)},Arrow:{name:"Arrow",initializer:(t,e=null,...i)=>new ki(e,t,...i)},Image:{name:"Image",initializer:(t,e=null,...i)=>new Pi(e,t,...i)},Cloud:{name:"Cloud",initializer:(t,e=null,...i)=>new Mi(e,t,...i)}};t.Markup=class{constructor(){this._markupIsActive=!1,this._markupColor=new vi(255,0,0),this.lineWidth=4,this.lineType="solid",this.fontSize=34,this.changeActiveDragger=t=>{const e=t.data;this._markupContainer.className=this._container.className.split(" ").filter(t=>!t.startsWith("oda-cursor-")).filter(t=>t).concat(`oda-cursor-${e.toLowerCase()}`).join(" "),this.removeTextInput(),this.removeImageInput(),this.enableEditMode(e)},this.resizeContainer=()=>{const{offsetLeft:t,offsetTop:e,offsetWidth:i,offsetHeight:s}=this._container;i&&s&&(this._markupContainer.style.left=`${t}px`,this._markupContainer.style.top=`${e}px`,this._konvaStage.width(i),this._konvaStage.height(s),this.getObjects().forEach(t=>{t.updateScreenCoordinates()}))},this.pan=()=>{this.updateScreenCoordinatesForAll()},this.zoomAt=()=>{this.updateScreenCoordinatesForAll()},this.changeCameraMode=()=>{this.clearOverlay()},this.redirectToViewer=t=>{this._viewer&&this._viewer.emit(t)},this.getRelativePointPosition=(t,e)=>{const i=e.getAbsoluteTransform().copy();return i.invert(),i.point(t)},this.getRelativePointerPosition=t=>this.getRelativePointPosition(t.getStage().getPointerPosition(),t)}initialize(t,e,i,s){this._viewer=i,this._worldTransformer=null!=s?s:new xi,this._container=t,this._markupContainer=document.createElement("div"),this._markupContainer.id="markup-container",this._markupContainer.style.position="absolute",this._markupContainer.style.outline="0px",this._markupContainer.style.pointerEvents="none";this._container.parentElement.appendChild(this._markupContainer),this._markupColor.setColor(255,0,0),this.initializeKonva(),this._resizeObserver=new ResizeObserver(this.resizeContainer),this._resizeObserver.observe(t),this._viewer&&(this._viewer.addEventListener("changeactivedragger",this.changeActiveDragger),this._viewer.addEventListener("pan",this.pan),this._viewer.addEventListener("zoomat",this.zoomAt),this._viewer.addEventListener("changecameramode",this.changeCameraMode))}dispose(){var t,e;this._viewer&&(this._viewer.removeEventListener("changecameramode",this.changeCameraMode),this._viewer.removeEventListener("zoomat",this.zoomAt),this._viewer.removeEventListener("pan",this.pan),this._viewer.removeEventListener("changeactivedragger",this.changeActiveDragger)),null===(t=this._resizeObserver)||void 0===t||t.disconnect(),this._resizeObserver=void 0,this.destroyKonva(),null===(e=this._markupContainer)||void 0===e||e.remove(),this._markupContainer=void 0,this._container=void 0,this._viewer=void 0,this._worldTransformer=void 0,this._markupIsActive=!1}syncOverlay(){}clearOverlay(){this.removeTextInput(),this.removeImageInput(),this.clearSelected(),this.getObjects().forEach(t=>t.delete())}getMarkupColor(){return this._markupColor.asRGB()}setMarkupColor(t,e,i){this._markupColor.setColor(t,e,i),this.redirectToViewer({type:"changemarkupcolor",data:{r:t,g:e,b:i}})}colorizeAllMarkup(t,e,i){this.setMarkupColor(t,e,i);const s=new vi(t,e,i).asHex();this.getObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}colorizeSelectedMarkups(t,e,i){const s=new vi(t,e,i).asHex();this.getSelectedObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}setViewpoint(t){var e,i,s,r,n,o,a,h;this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._konvaStage.scale({x:1,y:1}),this._konvaStage.position({x:0,y:0});const l=(null===(e=t.custom_fields)||void 0===e?void 0:e.markup_color)||{r:255,g:0,b:0};this.setMarkupColor(l.r,l.g,l.b),null===(i=t.lines)||void 0===i||i.forEach(t=>{const e=[];t.points.forEach(t=>{const i=this._worldTransformer.worldToScreen(t);e.push(i.x),e.push(i.y)}),this.addLine(e,t.color,t.type,t.width,t.id)}),null===(s=t.texts)||void 0===s||s.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position);this.addText(t.text,e,t.angle,t.color,t.text_size,t.font_size,t.id)}),null===(r=t.rectangles)||void 0===r||r.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addRectangle(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(n=t.ellipses)||void 0===n||n.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null,s=t.position3?this._worldTransformer.worldToScreen(t.position3):null;this.addEllipse(e,i,s,t.radius,t.line_width,t.color,t.id)}),null===(o=t.arrows)||void 0===o||o.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.start),i=this._worldTransformer.worldToScreen(t.end);this.addArrow(e,i,t.color,t.id)}),null===(a=t.clouds)||void 0===a||a.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addCloud(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(h=t.images)||void 0===h||h.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addImage(e,i,t.src,t.width,t.height,t.id)})}getViewpoint(t){return t||(t={custom_fields:{}}),t.lines=this.getMarkupLines(),t.texts=this.getMarkupTexts(),t.arrows=this.getMarkupArrows(),t.clouds=this.getMarkupClouds(),t.ellipses=this.getMarkupEllipses(),t.images=this.getMarkupImages(),t.rectangles=this.getMarkupRectangles(),t.snapshot={data:this.combineMarkupWithDrawing()},t.custom_fields.markup_color=this.getMarkupColor(),t}enableEditMode(t){return t&&Ri[t]?(this._markupMode=t,this._markupContainer.style.pointerEvents="all",this._markupIsActive=!0):(this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._markupContainer.style.pointerEvents="none",this._markupIsActive=!1),this}createObject(t,e){const i=Ri[t];if(!i||!i.initializer)throw new Error(`Markup CreateObject - unsupported markup type ${t}`);const s=i.initializer(null,e,this._worldTransformer);return this.addObject(s),s}getObjects(){const t=[];return Object.keys(Ri).forEach(e=>{const i=Ri[e];this.konvaLayerFind(e).forEach(e=>t.push(i.initializer(e,null,this._worldTransformer)))}),t}getSelectedObjects(){return this._konvaTransformer?this._konvaTransformer.nodes().map(t=>{const e=t.className,i=Object.values(Ri).find(t=>t.name===e);return i?i.initializer(t,null,this._worldTransformer):null}).filter(t=>t):[]}selectObjects(t){if(!this._konvaTransformer)return;const e=this._konvaTransformer.nodes().concat(t.map(t=>t.ref()));this._konvaTransformer.nodes(e)}clearSelected(){this._konvaTransformer&&this._konvaTransformer.nodes([])}addObject(t){"Image"===t.type()?this._groupImages.add(t.ref()):"Text"===t.type()?this._groupTexts.add(t.ref()):this._groupGeometry.add(t.ref())}konvaLayerFind(t){if(!this._konvaLayer)return[];const e=Ri[t];return e&&e.initializer?this._konvaLayer.find(e.name).filter(t=>t.parent===this._konvaLayer||t.parent===this._groupImages||t.parent===this._groupGeometry||t.parent===this._groupTexts):[]}updateScreenCoordinatesForAll(){this.getObjects().forEach(t=>{t.updateScreenCoordinates()})}initializeKonva(){const t=new yi.Stage({container:this._markupContainer,width:this._container.clientWidth,height:this._container.clientHeight});this._konvaStage=t;const e=new yi.Layer({pixelRation:window.devicePixelRatio});t.add(e),this._groupImages=new yi.Group,e.add(this._groupImages),this._groupGeometry=new yi.Group,e.add(this._groupGeometry),this._groupTexts=new yi.Group,e.add(this._groupTexts),this._konvaLayer=e;const i=new yi.Transformer({shouldOverdrawWholeArea:!1,keepRatio:!1,flipEnabled:!1});e.add(i),this._konvaTransformer=i;let s,r,n,o=!1;t.on("mousedown touchstart",e=>{if(!this._markupIsActive||e.target!==t||"Text"===this._markupMode||"Image"===this._markupMode)return;if(e.target===t&&i.nodes().length>0)return void i.nodes([]);const n=this.getRelativePointerPosition(t);r=n,o=["Arrow","Cloud","Ellipse","Line","Rectangle"].some(t=>t===this._markupMode),"Line"===this._markupMode&&(s=this.addLine([n.x,n.y,n.x,n.y]))}),t.on("mouseup touchend",()=>{if(this._markupIsActive){if(o){const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,s=i?r.x:Math.min(r.x,e.x),n=i?r.y:Math.min(r.y,e.y),o=i?200:Math.abs(r.x-e.x),a=i?200:Math.abs(r.y-e.y);i&&("Rectangle"===this._markupMode?this.addRectangle({x:s,y:n},null,o,a):"Ellipse"===this._markupMode?this.addEllipse({x:s,y:n},null,null,{x:o/2,y:a/2}):"Arrow"===this._markupMode?this.addArrow({x:r.x,y:r.y},{x:i?r.x+200:e.x,y:i?n:e.y}):"Cloud"===this._markupMode&&this.addCloud({x:s,y:n},null,Math.max(100,o),Math.max(100,a)))}n=void 0,o=!1}}),t.on("mousemove touchmove",()=>{if(!this._markupIsActive)return;if(!o)return;const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,a=i?r.x:Math.min(r.x,e.x),h=i?r.y:Math.min(r.y,e.y),l=i?200:Math.abs(r.x-e.x),d=i?200:Math.abs(r.y-e.y);"Line"===this._markupMode?s.addPoints([{x:e.x,y:e.y}]):"Arrow"===this._markupMode?n?n.setEndPoint(e.x,e.y):n=this.addArrow({x:r.x,y:r.y},{x:e.x,y:e.y}):"Rectangle"===this._markupMode?n?(n.setPosition(a,h),n.setWidth(l),n.setHeight(d)):n=this.addRectangle({x:a,y:h},null,l,d):"Ellipse"===this._markupMode?n?(n.setPosition(a,h),n.setRadiusX(l),n.setRadiusY(d)):n=this.addEllipse({x:a,y:h},null,null,{x:l,y:d}):"Cloud"===this._markupMode&&(n?(n.setPosition(a,h),n.setWidth(Math.max(100,l)),n.setHeight(Math.max(100,d))):n=this.addCloud({x:a,y:h},null,l,d))}),t.on("click tap",e=>{if(!this._markupIsActive)return;if(e.target===t){if("Text"===this._markupMode){if(this._textInputRef&&this._textInputRef.value)this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle);else if(0===i.nodes().length){const i=this.getRelativePointerPosition(t);this.createTextInput(i,e.evt.pageX,e.evt.pageY,0,null)}}else if("Image"===this._markupMode)if(this._imageInputRef&&this._imageInputRef.value)this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,this._imageInputRef.value,0,0,this._imageInputRef.value);else if(0===i.nodes().length){const e=this.getRelativePointerPosition(t);this.createImageInput(e)}return void i.nodes([])}if("Text"===this._markupMode||"SelectMarkup"===this._markupMode){if("Text"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._textInputRef&&this._textInputRef.value?this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle):this.createTextInput({x:e.target.attrs.x,y:e.target.attrs.y},e.evt.pageX,e.evt.pageY,e.target.attrs.rotation,e.target.attrs.text));this.removeTextInput()}if("Image"===this._markupMode||"SelectMarkup"===this._markupMode){if("Image"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._imageInputRef&&this._imageInputRef.value?this.addImage(this._imageInputPos,null,this._imageInputRef.value,0,0):this.createImageInput({x:e.target.attrs.x,y:e.target.attrs.y}));this.removeImageInput()}i.nodes().filter(t=>"Cloud"===t.className||"Image"===t.className).length>0||"Cloud"===e.target.className||"Image"===e.target.className?i.rotateEnabled(!1):i.rotateEnabled(!0);const s=e.evt.shiftKey||e.evt.ctrlKey||e.evt.metaKey,r=i.nodes().indexOf(e.target)>=0;if(s||r){if(s&&r){const t=i.nodes().slice();t.splice(t.indexOf(e.target),1),i.nodes(t)}else if(s&&!r){const t=i.nodes().concat([e.target]);i.nodes(t)}}else i.nodes([e.target])});const a=t.container();a.tabIndex=1,a.focus(),a.addEventListener("keydown",t=>{if(this._markupIsActive)return"Delete"===t.code?(this.getSelectedObjects().forEach(t=>t.delete()),void this.clearSelected()):void t.preventDefault()})}destroyKonva(){var t;this.removeTextInput(),this.removeImageInput(),this.clearOverlay(),null===(t=this._konvaStage)||void 0===t||t.destroy(),this._groupImages=void 0,this._groupGeometry=void 0,this._groupTexts=void 0,this._konvaLayer=void 0,this._konvaTransformer=void 0,this._konvaStage=void 0}getMarkupLines(){const t=[];return this.konvaLayerFind("Line").forEach(e=>{const i=e.getAttr("wcsPoints");if(!i)return;const s=new Si(null,e,this._worldTransformer),r={id:s.id(),points:i,color:s.getColor()||"#ff0000",type:s.getLineType()||this.lineType,width:s.getLineWidth()||this.lineWidth};t.push(r)}),t}getMarkupTexts(){const t=[];return this.konvaLayerFind("Text").forEach(e=>{const i=this._worldTransformer.getScale(),s=e.getAttr("wcsStart"),r=this._konvaStage.getAbsoluteTransform(),n=new bi(null,e,this._worldTransformer),o={id:n.id(),position:s,text:n.getText(),text_size:.02*i.y,angle:n.getRotation(),color:n.getColor(),font_size:n.getFontSize()*r.getMatrix()[0]};t.push(o)}),t}getMarkupRectangles(){const t=[];return this.konvaLayerFind("Rectangle").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),o=new Ci(null,e,this._worldTransformer),a={id:o.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:o.getLineWidth(),color:o.getColor()};t.push(a)}),t}getMarkupEllipses(){const t=[];return this.konvaLayerFind("Ellipse").forEach(e=>{const i=e.getAttr("wcsPosition"),s=e.getAttr("wcsRadiusX"),r=e.getAttr("wcsRadiusY"),n=this._konvaStage.getAbsoluteTransform().getMatrix()[0],o=new Ai(null,e,this._worldTransformer),a={id:o.id(),position:i,position2:s,position3:r,radius:{x:e.getRadiusX()*n,y:e.getRadiusY()*n},line_width:o.getLineWidth(),color:o.getColor()};t.push(a)}),t}getMarkupArrows(){const t=[];return this.konvaLayerFind("Arrow").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=new ki(null,e,this._worldTransformer),n={id:r.id(),start:i,end:s,color:r.getColor()};t.push(n)}),t}getMarkupImages(){const t=[];return this.konvaLayerFind("Image").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._konvaStage.getAbsoluteTransform().getMatrix()[0],n=new Pi(null,e,this._worldTransformer),o={id:n.id(),position:i,position2:s,src:n.getSrc(),width:n.getWidth()*r,height:n.getHeight()*r};t.push(o)}),t}getMarkupClouds(){const t=[];return this.konvaLayerFind("Cloud").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),o=new Mi(null,e,this._worldTransformer),a={id:o.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:o.getLineWidth(),color:o.getColor()};t.push(a)}),t}combineMarkupWithDrawing(){this.clearSelected();const t=document.createElement("canvas");if(this._konvaStage){t.width=this._konvaStage.width(),t.height=this._konvaStage.height();const e=t.getContext("2d");this._container instanceof HTMLCanvasElement&&e.drawImage(this._container,0,0),e.drawImage(this._konvaStage.toCanvas({pixelRatio:window.devicePixelRatio}),0,0)}return t.toDataURL("image/jpeg",.25)}addLine(t,e,i,s,r){if(!t||0===t.length)return;const n=[];for(let e=0;e<t.length;e+=2)n.push({x:t[e],y:t[e+1]});const o=new Si({points:n,type:i||this.lineType,width:s||this.lineWidth,color:e||this._markupColor.asHex(),id:r},null,this._worldTransformer);return this.addObject(o),o}createTextInput(t,e,i,s,r){this._textInputRef?this.removeTextInput():(this._textInputPos=t,this._textInputAngle=s,this._textInputRef=document.createElement("textarea"),this._textInputRef.style.zIndex="9999",this._textInputRef.style.position="absolute",this._textInputRef.style.display="block",this._textInputRef.style.top=i+"px",this._textInputRef.style.left=e+"px",this._textInputRef.style.fontSize=`${this.fontSize}px`,this._textInputRef.style.color=`${this._markupColor.asHex()}`,this._textInputRef.style.fontFamily="Calibri",this._textInputRef.onkeydown=t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle)),"Escape"===t.key&&(t.preventDefault(),this.removeTextInput())},r&&(this._textInputRef.value=r),document.body.appendChild(this._textInputRef),setTimeout(()=>{this._textInputRef.focus()},50))}removeTextInput(){var t;null===(t=this._textInputRef)||void 0===t||t.remove(),this._textInputRef=null,this._textInputPos=null,this._textInputAngle=0}createImageInput(t){if(this._imageInputRef)this.removeImageInput();else{const e=t=>new Promise((e,i)=>{const s=new FileReader;s.readAsDataURL(t),s.onload=()=>{e(s.result)},s.onerror=t=>{i(t)}});this._imageInputPos=t,this._imageInputRef=document.createElement("input"),this._imageInputRef.style.display="none",this._imageInputRef.type="file",this._imageInputRef.accept="image/png, image/jpeg",this._imageInputRef.onchange=async t=>{const i=t.target.files[0],s=await e(i);this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,s.toString(),0,0)},this._imageInputRef.oncancel=()=>{this.removeImageInput()},document.body.appendChild(this._imageInputRef),setTimeout(()=>{this._imageInputRef.click()},50)}}removeImageInput(){var t;null===(t=this._imageInputRef)||void 0===t||t.remove(),this._imageInputRef=null,this._imageInputPos=null}addText(t,e,i,s,r,n,o){var a;if(!t)return;null===(a=this.getSelectedObjects().shift())||void 0===a||a.delete(),this.clearSelected(),this.removeTextInput();const h=1e-6;if(r&&r>h&&(!n||n<h)){const t=.02;n=r/(this._worldTransformer.getScale().y/t)/34}const l=new bi({position:{x:e.x,y:e.y},text:t,rotation:i,fontSize:n||this.fontSize,color:s||this._markupColor.asHex(),id:o},null,this._worldTransformer);return this.addObject(l),l}addRectangle(t,e,i,s,r,n,o){if(!t)return;const a=new Ci({position:t,position2:e,width:i,height:s,lineWidth:r||this.lineWidth,color:n||this._markupColor.asHex(),id:o},null,this._worldTransformer);return this.addObject(a),a}addEllipse(t,e,i,s,r,n,o){if(!t)return;const a=new Ai({position:t,position2:e,position3:i,radius:s,lineWidth:r,color:n||this._markupColor.asHex(),id:o},null,this._worldTransformer);return this.addObject(a),a}addArrow(t,e,i,s){if(!t||!e)return;const r=new ki({start:t,end:e,color:i||this._markupColor.asHex(),id:s},null,this._worldTransformer);return this.addObject(r),r}addCloud(t,e,i,s,r,n,o){if(!t||!i||!s)return;const a=new Mi({position:t,position2:e,width:i,height:s,color:n||this._markupColor.asHex(),lineWidth:r||this.lineWidth,id:o},null,this._worldTransformer);return this.addObject(a),a}addImage(t,e,i,s,r,n){var o;if(!t||!i)return;null===(o=this.getSelectedObjects().shift())||void 0===o||o.delete(),this.clearSelected(),this.removeImageInput();const a=new Pi({position:t,position2:e,src:i,width:s,height:r,maxWidth:this._konvaStage.width()-t.x,maxHeight:this._konvaStage.height()-t.y,id:n},null,this._worldTransformer);return this.addObject(a),a}}});
|