@scratch-compiler/client 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/index.js.map +4 -4
- package/package.json +18 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var be=Math.PI/180;function Se(){return typeof window<"u"&&({}.toString.call(window)==="[object Window]"||{}.toString.call(window)==="[object global]")}var at=typeof global<"u"?global:typeof window<"u"?window:typeof WorkerGlobalScope<"u"?self:{},p={_global:at,version:"10.2.3",isBrowser:Se(),isUnminified:/param/.test(function(r){}.toString()),dblClickWindow:400,getAngle(r){return p.angleDeg?r*be:r},enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:typeof window<"u"&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging(){return p.DD.isDragging},isTransforming(){var r,t;return(t=(r=p.Transformer)===null||r===void 0?void 0:r.isTransforming())!==null&&t!==void 0?t:!1},isDragReady(){return!!p.DD.node},releaseCanvasOnDestroy:!0,document:at.document,_injectGlobal(r){typeof at.Konva<"u"&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),at.Konva=r}},O=r=>{p[r.prototype.getClassName()]=r};p._injectGlobal(p);var we=`Konva.js unsupported environment.
|
|
2
2
|
|
|
3
3
|
Looks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ or
|
|
|
11
11
|
|
|
12
12
|
bash: npm install skia-canvas
|
|
13
13
|
js: import "konva/skia-backend";
|
|
14
|
-
`,Yt=()=>{if(typeof document>"u")throw new Error(we)},L=class r{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 r(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){let 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){let e=Math.cos(t),i=Math.sin(t),n=this.m[0]*e+this.m[2]*i,s=this.m[1]*e+this.m[3]*i,a=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=n,this.m[1]=s,this.m[2]=a,this.m[3]=o,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){let i=this.m[0]+this.m[2]*e,n=this.m[1]+this.m[3]*e,s=this.m[2]+this.m[0]*t,a=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=n,this.m[2]=s,this.m[3]=a,this}multiply(t){let 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],n=this.m[0]*t.m[2]+this.m[2]*t.m[3],s=this.m[1]*t.m[2]+this.m[3]*t.m[3],a=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]=n,this.m[3]=s,this.m[4]=a,this.m[5]=o,this}invert(){let t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,n=-this.m[2]*t,s=this.m[0]*t,a=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]=n,this.m[3]=s,this.m[4]=a,this.m[5]=o,this}getMatrix(){return this.m}decompose(){let t=this.m[0],e=this.m[1],i=this.m[2],n=this.m[3],s=this.m[4],a=this.m[5],o=t*n-e*i,h={x:s,y:a,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(t!=0||e!=0){let c=Math.sqrt(t*t+e*e);h.rotation=e>0?Math.acos(t/c):-Math.acos(t/c),h.scaleX=c,h.scaleY=o/c,h.skewX=(t*i+e*n)/o,h.skewY=0}else if(i!=0||n!=0){let c=Math.sqrt(i*i+n*n);h.rotation=Math.PI/2-(n>0?Math.acos(-i/c):-Math.acos(i/c)),h.scaleX=o/c,h.scaleY=c,h.skewX=0,h.skewY=(t*i+e*n)/o}return h.rotation=l._getRotation(h.rotation),h}},Se="[object Array]",xe="[object Number]",ke="[object String]",Ee="[object Boolean]",Pe=Math.PI/180,Te=180/Math.PI,z="#",Re="",Ae="0",Le="Konva warning: ",Ut="Konva error: ",De="rgb(",Et={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]},Ge=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,ot=[],j=null,Oe=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(r){setTimeout(r,16)},l={_isElement(r){return!!(r&&r.nodeType==1)},_isFunction(r){return!!(r&&r.constructor&&r.call&&r.apply)},_isPlainObject(r){return!!r&&r.constructor===Object},_isArray(r){return Object.prototype.toString.call(r)===Se},_isNumber(r){return Object.prototype.toString.call(r)===xe&&!isNaN(r)&&isFinite(r)},_isString(r){return Object.prototype.toString.call(r)===ke},_isBoolean(r){return Object.prototype.toString.call(r)===Ee},isObject(r){return r instanceof Object},isValidSelector(r){if(typeof r!="string")return!1;let t=r[0];return t==="#"||t==="."||t===t.toUpperCase()},_sign(r){return r===0||r>0?1:-1},requestAnimFrame(r){ot.push(r),ot.length===1&&Oe(function(){let t=ot;ot=[],t.forEach(function(e){e()})})},createCanvasElement(){Yt();let r=document.createElement("canvas");try{r.style=r.style||{}}catch{}return r},createImageElement(){return Yt(),document.createElement("img")},_isInDocument(r){for(;r=r.parentNode;)if(r==document)return!0;return!1},_urlToImage(r,t){let e=l.createImageElement();e.onload=function(){t(e)},e.src=r},_rgbToHex(r,t,e){return((1<<24)+(r<<16)+(t<<8)+e).toString(16).slice(1)},_hexToRgb(r){r=r.replace(z,Re);let t=parseInt(r,16);return{r:t>>16&255,g:t>>8&255,b:t&255}},getRandomColor(){let r=(Math.random()*16777215<<0).toString(16);for(;r.length<6;)r=Ae+r;return z+r},isCanvasFarblingActive(){if(j!==null)return j;if(typeof document>"u")return j=!1,!1;let r=this.createCanvasElement();r.width=10,r.height=10;let t=r.getContext("2d",{willReadFrequently:!0});t.clearRect(0,0,10,10),t.fillStyle="#282828",t.fillRect(0,0,10,10);let e=t.getImageData(0,0,10,10).data,i=!1;for(let n=0;n<100;n++)if(e[n*4]!==40||e[n*4+1]!==40||e[n*4+2]!==40||e[n*4+3]!==255){i=!0;break}return j=i,this.releaseCanvas(r),j},getHitColor(){let r=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(r):r},getHitColorKey(r,t,e){return this.isCanvasFarblingActive()&&(r=Math.round(r/5)*5,t=Math.round(t/5)*5,e=Math.round(e/5)*5),z+this._rgbToHex(r,t,e)},getSnappedHexColor(r){let t=this._hexToRgb(r);return z+this._rgbToHex(Math.round(t.r/5)*5,Math.round(t.g/5)*5,Math.round(t.b/5)*5)},getRGB(r){let t;return r in Et?(t=Et[r],{r:t[0],g:t[1],b:t[2]}):r[0]===z?this._hexToRgb(r.substring(1)):r.substr(0,4)===De?(t=Ge.exec(r.replace(/ /g,"")),{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}):{r:0,g:0,b:0}},colorToRGBA(r){return r=r||"black",l._namedColorToRBA(r)||l._hex3ColorToRGBA(r)||l._hex4ColorToRGBA(r)||l._hex6ColorToRGBA(r)||l._hex8ColorToRGBA(r)||l._rgbColorToRGBA(r)||l._rgbaColorToRGBA(r)||l._hslColorToRGBA(r)},_namedColorToRBA(r){let t=Et[r.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(r){if(r.indexOf("rgb(")===0){r=r.match(/rgb\(([^)]+)\)/)[1];let t=r.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(r){if(r.indexOf("rgba(")===0){r=r.match(/rgba\(([^)]+)\)/)[1];let t=r.split(/ *, */).map((e,i)=>e.slice(-1)==="%"?i===3?parseInt(e)/100:parseInt(e)/100*255:Number(e));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(r){if(r[0]==="#"&&r.length===9)return{r:parseInt(r.slice(1,3),16),g:parseInt(r.slice(3,5),16),b:parseInt(r.slice(5,7),16),a:parseInt(r.slice(7,9),16)/255}},_hex6ColorToRGBA(r){if(r[0]==="#"&&r.length===7)return{r:parseInt(r.slice(1,3),16),g:parseInt(r.slice(3,5),16),b:parseInt(r.slice(5,7),16),a:1}},_hex4ColorToRGBA(r){if(r[0]==="#"&&r.length===5)return{r:parseInt(r[1]+r[1],16),g:parseInt(r[2]+r[2],16),b:parseInt(r[3]+r[3],16),a:parseInt(r[4]+r[4],16)/255}},_hex3ColorToRGBA(r){if(r[0]==="#"&&r.length===4)return{r:parseInt(r[1]+r[1],16),g:parseInt(r[2]+r[2],16),b:parseInt(r[3]+r[3],16),a:1}},_hslColorToRGBA(r){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(r)){let[t,...e]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(r),i=Number(e[0])/360,n=Number(e[1])/100,s=Number(e[2])/100,a,o,h;if(n===0)return h=s*255,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};s<.5?a=s*(1+n):a=s+n-s*n;let c=2*s-a,d=[0,0,0];for(let g=0;g<3;g++)o=i+1/3*-(g-1),o<0&&o++,o>1&&o--,6*o<1?h=c+(a-c)*6*o:2*o<1?h=a:3*o<2?h=c+(a-c)*(2/3-o)*6:h=c,d[g]=h*255;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[2]),a:1}}},haveIntersection(r,t){return!(t.x>r.x+r.width||t.x+t.width<r.x||t.y>r.y+r.height||t.y+t.height<r.y)},cloneObject(r){let t={};for(let e in r)this._isPlainObject(r[e])?t[e]=this.cloneObject(r[e]):this._isArray(r[e])?t[e]=this.cloneArray(r[e]):t[e]=r[e];return t},cloneArray(r){return r.slice(0)},degToRad(r){return r*Pe},radToDeg(r){return r*Te},_degToRad(r){return l.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),l.degToRad(r)},_radToDeg(r){return l.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),l.radToDeg(r)},_getRotation(r){return p.angleDeg?l.radToDeg(r):r},_capitalize(r){return r.charAt(0).toUpperCase()+r.slice(1)},throw(r){throw new Error(Ut+r)},error(r){console.error(Ut+r)},warn(r){p.showWarnings&&console.warn(Le+r)},each(r,t){for(let e in r)t(e,r[e])},_inRange(r,t,e){return t<=r&&r<e},_getProjectionToSegment(r,t,e,i,n,s){let a,o,h,c=(r-e)*(r-e)+(t-i)*(t-i);if(c==0)a=r,o=t,h=(n-e)*(n-e)+(s-i)*(s-i);else{let d=((n-r)*(e-r)+(s-t)*(i-t))/c;d<0?(a=r,o=t,h=(r-n)*(r-n)+(t-s)*(t-s)):d>1?(a=e,o=i,h=(e-n)*(e-n)+(i-s)*(i-s)):(a=r+d*(e-r),o=t+d*(i-t),h=(a-n)*(a-n)+(o-s)*(o-s))}return[a,o,h]},_getProjectionToLine(r,t,e){let i=l.cloneObject(r),n=Number.MAX_VALUE;return t.forEach(function(s,a){if(!e&&a===t.length-1)return;let o=t[(a+1)%t.length],h=l._getProjectionToSegment(s.x,s.y,o.x,o.y,r.x,r.y),c=h[0],d=h[1],g=h[2];g<n&&(i.x=c,i.y=d,n=g)}),i},_prepareArrayForTween(r,t,e){let i=[],n=[];if(r.length>t.length){let a=t;t=r,r=a}for(let a=0;a<r.length;a+=2)i.push({x:r[a],y:r[a+1]});for(let a=0;a<t.length;a+=2)n.push({x:t[a],y:t[a+1]});let s=[];return n.forEach(function(a){let o=l._getProjectionToLine(a,i,e);s.push(o.x),s.push(o.y)}),s},_prepareToStringify(r){let t;r.visitedByCircularReferenceRemoval=!0;for(let e in r)if(r.hasOwnProperty(e)&&r[e]&&typeof r[e]=="object"){if(t=Object.getOwnPropertyDescriptor(r,e),r[e].visitedByCircularReferenceRemoval||l._isElement(r[e]))if(t.configurable)delete r[e];else return null;else if(l._prepareToStringify(r[e])===null)if(t.configurable)delete r[e];else return null}return delete r.visitedByCircularReferenceRemoval,r},_assign(r,t){for(let e in t)r[e]=t[e];return r},_getFirstPointerId(r){return r.touches?r.changedTouches[0].identifier:r.pointerId||999},releaseCanvas(...r){p.releaseCanvasOnDestroy&&r.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(r,t,e,i){let n=t<0?t:0,s=e<0?e:0;t=Math.abs(t),e=Math.abs(e);let a=0,o=0,h=0,c=0;typeof i=="number"?a=o=h=c=Math.min(i,t/2,e/2):(a=Math.min(i[0]||0,t/2,e/2),o=Math.min(i[1]||0,t/2,e/2),c=Math.min(i[2]||0,t/2,e/2),h=Math.min(i[3]||0,t/2,e/2)),r.moveTo(n+a,s),r.lineTo(n+t-o,s),r.arc(n+t-o,s+o,o,Math.PI*3/2,0,!1),r.lineTo(n+t,s+e-c),r.arc(n+t-c,s+e-c,c,0,Math.PI/2,!1),r.lineTo(n+h,s+e),r.arc(n+h,s+e-h,h,Math.PI/2,Math.PI,!1),r.lineTo(n,s+a),r.arc(n+a,s+a,a,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(r,t,e,i,n){i=Math.abs(i);for(let s=0;s<e;s++){let a=t[(s-1+e)%e],o=t[s],h=t[(s+1)%e],c={x:o.x-a.x,y:o.y-a.y},d={x:h.x-o.x,y:h.y-o.y},g=Math.hypot(c.x,c.y),m=Math.hypot(d.x,d.y),_;typeof n=="number"?_=n:_=s<n.length?n[s]:0,_=i*Math.cos(Math.PI/e)*Math.min(1,_/i*2);let x={x:c.x/g,y:c.y/g},k={x:d.x/m,y:d.y/m},S={x:o.x-x.x*_,y:o.y-x.y*_},G={x:o.x+k.x*_,y:o.y+k.y*_};s===0?r.moveTo(S.x,S.y):r.lineTo(S.x,S.y),r.arcTo(o.x,o.y,G.x,G.y,_)}}};var b={get isDragging(){let r=!1;return b._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(r=!0)}),r},justDragged:!1,get node(){let r;return b._dragElements.forEach(t=>{r=t.node}),r},_dragElements:new Map,_drag(r){let t=[];b._dragElements.forEach((e,i)=>{let{node:n}=e,s=n.getStage();s.setPointersPositions(r),e.pointerId===void 0&&(e.pointerId=l._getFirstPointerId(r));let a=s._changedPointerPositions.find(o=>o.id===e.pointerId);if(a){if(e.dragStatus!=="dragging"){let o=n.dragDistance();if(Math.max(Math.abs(a.x-e.startPointerPos.x),Math.abs(a.y-e.startPointerPos.y))<o||(n.startDrag({evt:r}),!n.isDragging()))return}n._setDragPosition(r,e),t.push(n)}}),t.forEach(e=>{e.getStage()&&e.fire("dragmove",{type:"dragmove",target:e,evt:r},!0)})},_endDragBefore(r){let t=[];b._dragElements.forEach(e=>{let{node:i}=e,n=i.getStage();if(r&&n.setPointersPositions(r),!n._changedPointerPositions.find(o=>o.id===e.pointerId))return;(e.dragStatus==="dragging"||e.dragStatus==="stopped")&&(b.justDragged=!0,p._mouseListenClick=!1,p._touchListenClick=!1,p._pointerListenClick=!1,e.dragStatus="stopped");let a=e.node.getLayer()||e.node instanceof p.Stage&&e.node;a&&t.indexOf(a)===-1&&t.push(a)}),t.forEach(e=>{e.draw()})},_endDragAfter(r){b._dragElements.forEach((t,e)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:r},!0),t.dragStatus!=="dragging"&&b._dragElements.delete(e)})}};p.isBrowser&&(window.addEventListener("mouseup",b._endDragBefore,!0),window.addEventListener("touchend",b._endDragBefore,!0),window.addEventListener("touchcancel",b._endDragBefore,!0),window.addEventListener("mousemove",b._drag),window.addEventListener("touchmove",b._drag),window.addEventListener("mouseup",b._endDragAfter,!1),window.addEventListener("touchend",b._endDragAfter,!1),window.addEventListener("touchcancel",b._endDragAfter,!1));p.DD=b;function B(r){return l._isString(r)?'"'+r+'"':Object.prototype.toString.call(r)==="[object Number]"||l._isBoolean(r)?r:Object.prototype.toString.call(r)}function C(){if(p.isUnminified)return function(r,t){return l._isNumber(r)||l.warn(B(r)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),r}}function Xt(r){if(p.isUnminified)return function(t,e){let i=l._isNumber(t),n=l._isArray(t)&&t.length==r;return!i&&!n&&l.warn(B(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or Array<number>('+r+")"),t}}function Vt(){if(p.isUnminified)return function(r,t){return l._isNumber(r)||r==="auto"||l.warn(B(r)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),r}}function M(){if(p.isUnminified)return function(r,t){return l._isString(r)||l.warn(B(r)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),r}}function Pt(){if(p.isUnminified)return function(r,t){let e=l._isString(r),i=Object.prototype.toString.call(r)==="[object CanvasGradient]"||r&&r.addColorStop;return e||i||l.warn(B(r)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),r}}function R(){if(p.isUnminified)return function(r,t){return r===!0||r===!1||l.warn(B(r)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),r}}function Wt(r){if(p.isUnminified)return function(t,e){return t==null||l.isObject(t)||l.warn(B(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+r),t}}var q="get",$="set",u={addGetterSetter(r,t,e,i,n){u.addGetter(r,t,e),u.addSetter(r,t,i,n),u.addOverloadedGetterSetter(r,t)},addGetter(r,t,e){let i=q+l._capitalize(t);r.prototype[i]=r.prototype[i]||function(){let n=this.attrs[t];return n===void 0?e:n}},addSetter(r,t,e,i){let n=$+l._capitalize(t);r.prototype[n]||u.overWriteSetter(r,t,e,i)},overWriteSetter(r,t,e,i){let n=$+l._capitalize(t);r.prototype[n]=function(s){return e&&s!==void 0&&s!==null&&(s=e.call(this,s,t)),this._setAttr(t,s),i&&i.call(this),this}},addComponentsGetterSetter(r,t,e,i,n){let s=e.length,a=l._capitalize,o=q+a(t),h=$+a(t);r.prototype[o]=function(){let d={};for(let g=0;g<s;g++){let m=e[g];d[m]=this.getAttr(t+a(m))}return d};let c=Wt(e);r.prototype[h]=function(d){let g=this.attrs[t];i&&(d=i.call(this,d,t)),c&&c.call(this,d,t);for(let m in d)d.hasOwnProperty(m)&&this._setAttr(t+a(m),d[m]);return d||e.forEach(m=>{this._setAttr(t+a(m),void 0)}),this._fireChangeEvent(t,g,d),n&&n.call(this),this},u.addOverloadedGetterSetter(r,t)},addOverloadedGetterSetter(r,t){let e=l._capitalize(t),i=$+e,n=q+e;r.prototype[t]=function(){return arguments.length?(this[i](arguments[0]),this):this[n]()}},addDeprecatedGetterSetter(r,t,e,i){l.error("Adding deprecated "+t);let n=q+l._capitalize(t),s=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";r.prototype[n]=function(){l.error(s);let a=this.attrs[t];return a===void 0?e:a},u.addSetter(r,t,i,function(){l.error(s)}),u.addOverloadedGetterSetter(r,t)},backCompat(r,t){l.each(t,function(e,i){let n=r.prototype[i],s=q+l._capitalize(e),a=$+l._capitalize(e);function o(){n.apply(this,arguments),l.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}r.prototype[e]=o,r.prototype[s]=o,r.prototype[a]=o})},afterSetFilter(){this._filterUpToDate=!1}};function Ie(r){let t=[],e=r.length,i=l;for(let n=0;n<e;n++){let s=r[n];i._isNumber(s)?s=Math.round(s*1e3)/1e3:i._isString(s)||(s=s+""),t.push(s)}return t}var Kt=",",Me="(",Ne=")",Fe="([",Be="])",He=";",Ye="()",Ue="=",zt=["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"],Xe=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],Ve=100,ht=null;function Tt(){if(ht!==null)return ht;try{let t=l.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(ht=!1,!1)}catch{return ht=!1,!1}}var J=class{constructor(t){this.canvas=t,p.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i=this.traceArr,n=i.length,s="",a,o,h,c;for(a=0;a<n;a++)o=i[a],h=o.method,h?(c=o.args,s+=h,t?s+=Ye:l._isArray(c[0])?s+=Fe+c.join(Kt)+Be:(e&&(c=c.map(d=>typeof d=="number"?Math.floor(d):d)),s+=Me+c.join(Kt)+Ne)):(s+=o.property,t||(s+=Ue+o.val)),s+=He;return s}clearTrace(){this.traceArr=[]}_trace(t){let e=this.traceArr,i;e.push(t),i=e.length,i>=Ve&&e.shift()}reset(){let t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){let 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){let e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){let e=t.getAbsoluteOpacity();e!==1&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){let e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){let e=t.attrs.miterLimit;e!=null&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,n,s,a){this._context.arc(t,e,i,n,s,a)}arcTo(t,e,i,n,s){this._context.arcTo(t,e,i,n,s)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,n,s,a){this._context.bezierCurveTo(t,e,i,n,s,a)}clearRect(t,e,i,n){this._context.clearRect(t,e,i,n)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){let i=arguments;if(i.length===2)return this._context.createImageData(t,e);if(i.length===1)return this._context.createImageData(t)}createLinearGradient(t,e,i,n){return this._context.createLinearGradient(t,e,i,n)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,n,s,a){return this._context.createRadialGradient(t,e,i,n,s,a)}drawImage(t,e,i,n,s,a,o,h,c){let d=arguments,g=this._context;d.length===3?g.drawImage(t,e,i):d.length===5?g.drawImage(t,e,i,n,s):d.length===9&&g.drawImage(t,e,i,n,s,a,o,h,c)}ellipse(t,e,i,n,s,a,o,h){this._context.ellipse(t,e,i,n,s,a,o,h)}isPointInPath(t,e,i,n){return i?this._context.isPointInPath(i,t,e,n):this._context.isPointInPath(t,e,n)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,n){this._context.fillRect(t,e,i,n)}strokeRect(t,e,i,n){this._context.strokeRect(t,e,i,n)}fillText(t,e,i,n){n?this._context.fillText(t,e,i,n):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,n){return this._context.getImageData(t,e,i,n)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,n){this._context.rect(t,e,i,n)}roundRect(t,e,i,n,s){this._context.roundRect(t,e,i,n,s)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,n){this._context.quadraticCurveTo(t,e,i,n)}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,n,s,a){this._context.setTransform(t,e,i,n,s,a)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,n){this._context.strokeText(t,e,i,n)}transform(t,e,i,n,s,a){this._context.transform(t,e,i,n,s,a)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t=this,e=zt.length,i=this.setAttr,n,s,a=function(o){let h=t[o],c;t[o]=function(){return s=Ie(Array.prototype.slice.call(arguments,0)),c=h.apply(t,arguments),t._trace({method:o,args:s}),c}};for(n=0;n<e;n++)a(zt[n]);t.setAttr=function(){i.apply(t,arguments);let o=arguments[0],h=arguments[1];(o==="shadowOffsetX"||o==="shadowOffsetY"||o==="shadowBlur")&&(h=h/this.canvas.getPixelRatio()),t._trace({property:o,val:h})}}_applyGlobalCompositeOperation(t){let e=t.attrs.globalCompositeOperation;!e||e==="source-over"||this.setAttr("globalCompositeOperation",e)}};Xe.forEach(function(r){Object.defineProperty(J.prototype,r,{get(){return this._context[r]},set(t){this._context[r]=t}})});var lt=class extends J{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){let e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){let e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){let e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){let e=t.fill(),i=t.getFillPriority();if(e&&i==="color"){this._fillColor(t);return}let n=t.getFillPatternImage();if(n&&i==="pattern"){this._fillPattern(t);return}let s=t.getFillLinearGradientColorStops();if(s&&i==="linear-gradient"){this._fillLinearGradient(t);return}let a=t.getFillRadialGradientColorStops();if(a&&i==="radial-gradient"){this._fillRadialGradient(t);return}e?this._fillColor(t):n?this._fillPattern(t):s?this._fillLinearGradient(t):a&&this._fillRadialGradient(t)}_strokeLinearGradient(t){let e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),n=t.getStrokeLinearGradientColorStops(),s=this.createLinearGradient(e.x,e.y,i.x,i.y);if(n){for(let a=0;a<n.length;a+=2)s.addColorStop(n[a],n[a+1]);this.setAttr("strokeStyle",s)}}_stroke(t){let e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();let s=this.getCanvas().getPixelRatio();this.setTransform(s,0,0,s,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,n;let s=(e=t.getShadowRGBA())!==null&&e!==void 0?e:"black",a=(i=t.getShadowBlur())!==null&&i!==void 0?i:5,o=(n=t.getShadowOffset())!==null&&n!==void 0?n:{x:0,y:0},h=t.getAbsoluteScale(),c=this.canvas.getPixelRatio(),d=h.x*c,g=h.y*c;this.setAttr("shadowColor",s),this.setAttr("shadowBlur",a*Math.min(Math.abs(d),Math.abs(g))),this.setAttr("shadowOffsetX",o.x*d),this.setAttr("shadowOffsetY",o.y*g)}},ct=class extends J{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()){let e=t.getStrokeScaleEnabled();if(!e){this.save();let s=this.getCanvas().getPixelRatio();this.setTransform(s,0,0,s,0,0)}this._applyLineCap(t);let i=t.hitStrokeWidth(),n=i==="auto"?t.strokeWidth():i;this.setAttr("lineWidth",n),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}};var dt;function We(){if(dt)return dt;let r=l.createCanvasElement(),t=r.getContext("2d");return dt=(function(){let e=p._global.devicePixelRatio||1,i=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/i})(),l.releaseCanvas(r),dt}var ut=class{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;let i=(t||{}).pixelRatio||p.pixelRatio||We();this.pixelRatio=i,this._canvas=l.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){let 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";let 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";let e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch{try{return this._canvas.toDataURL()}catch(n){return l.error("Unable to get data URL. "+n.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},T=class extends ut{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new lt(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}},N=class extends ut{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new ct(this),this.setSize(t.width,t.height)}};function Ke(r){let t=/(\w+)\(([^)]+)\)/g,e;for(;(e=t.exec(r))!==null;){let[,i,n]=e;switch(i){case"blur":{let s=parseFloat(n.replace("px",""));return function(a){this.blurRadius(s*.5);let o=p.Filters;o&&o.Blur&&o.Blur.call(this,a)}}case"brightness":{let s=n.includes("%")?parseFloat(n)/100:parseFloat(n);return function(a){this.brightness(s);let o=p.Filters;o&&o.Brightness&&o.Brightness.call(this,a)}}case"contrast":{let s=parseFloat(n);return function(a){let o=100*(Math.sqrt(s)-1);this.contrast(o);let h=p.Filters;h&&h.Contrast&&h.Contrast.call(this,a)}}case"grayscale":return function(s){let a=p.Filters;a&&a.Grayscale&&a.Grayscale.call(this,s)};case"sepia":return function(s){let a=p.Filters;a&&a.Sepia&&a.Sepia.call(this,s)};case"invert":return function(s){let a=p.Filters;a&&a.Invert&&a.Invert.call(this,s)};default:l.warn(`CSS filter "${i}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var ft="absoluteOpacity",jt="allEventListeners",D="absoluteTransform",qt="absoluteScale",H="canvas",ze="Change",je="children",qe="konva",Rt="listening",$e="mouseenter",Je="mouseleave",Ze="pointerenter",Qe="pointerleave",ti="touchenter",ei="touchleave";var $t="set",Jt="Shape",gt=" ",Zt="stage",F="transform",ii="Stage",At="visible",ni=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(gt),ri=1,v=class r{constructor(t){this._id=ri++,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===F||t===D)&&this._cache.get(t)?this._cache.get(t).dirty=!0:t?this._cache.delete(t):this._cache.clear()}_getCache(t,e){let i=this._cache.get(t);return(i===void 0||(t===F||t===D)&&i.dirty===!0)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){let n=e.map(s=>s+"Change.konva").join(gt);this.on(n,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(H)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===D&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(H)){let{scene:t,filter:e,hit:i}=this._cache.get(H);l.releaseCanvas(t._canvas,e._canvas,i._canvas),this._cache.delete(H)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){let e=t||{},i={};(e.x===void 0||e.y===void 0||e.width===void 0||e.height===void 0)&&(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let n=Math.ceil(e.width||i.width),s=Math.ceil(e.height||i.height),a=e.pixelRatio,o=e.x===void 0?Math.floor(i.x):e.x,h=e.y===void 0?Math.floor(i.y):e.y,c=e.offset||0,d=e.drawBorder||!1,g=e.hitCanvasPixelRatio||1;if(!n||!s){l.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}let m=Math.abs(Math.round(i.x)-o)>.5?1:0,_=Math.abs(Math.round(i.y)-h)>.5?1:0;n+=c*2+m,s+=c*2+_,o-=c,h-=c;let y=new T({pixelRatio:a,width:n,height:s}),x=new T({pixelRatio:a,width:0,height:0,willReadFrequently:!0}),k=new N({pixelRatio:g,width:n,height:s}),S=y.getContext(),G=k.getContext(),O=new T({width:y.width/y.pixelRatio+Math.abs(o),height:y.height/y.pixelRatio+Math.abs(h),pixelRatio:y.pixelRatio}),Ht=O.getContext();return k.isCache=!0,y.isCache=!0,this._cache.delete(H),this._filterUpToDate=!1,e.imageSmoothingEnabled===!1&&(y.getContext()._context.imageSmoothingEnabled=!1,x.getContext()._context.imageSmoothingEnabled=!1),S.save(),G.save(),Ht.save(),S.translate(-o,-h),G.translate(-o,-h),Ht.translate(-o,-h),O.x=o,O.y=h,this._isUnderCache=!0,this._clearSelfAndDescendantCache(ft),this._clearSelfAndDescendantCache(qt),this.drawScene(y,this,O),this.drawHit(k,this),this._isUnderCache=!1,S.restore(),G.restore(),d&&(S.save(),S.beginPath(),S.rect(0,0,n,s),S.closePath(),S.setAttr("strokeStyle","red"),S.setAttr("lineWidth",5),S.stroke(),S.restore()),l.releaseCanvas(O._canvas),this._cache.set(H,{scene:y,filter:x,hit:k,x:o,y:h}),this._requestDraw(),this}isCached(){return this._cache.has(H)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){let 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}],n=1/0,s=1/0,a=-1/0,o=-1/0,h=this.getAbsoluteTransform(e);return i.forEach(function(c){let d=h.point(c);n===void 0&&(n=a=d.x,s=o=d.y),n=Math.min(n,d.x),s=Math.min(s,d.y),a=Math.max(a,d.x),o=Math.max(o,d.y)}),{x:n,y:s,width:a-n,height:o-s}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);let e=this._getCanvasCache();t.translate(e.x,e.y);let i=this._getCachedSceneCanvas(),n=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/n,i.height/n),t.restore()}_drawCachedHitCanvas(t){let e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t=this.filters(),e=this._getCanvasCache(),i=e.scene,n=e.filter,s=n.getContext(),a,o,h,c;if(!t||t.length===0)return i;if(this._filterUpToDate)return n;let d=!0;for(let m=0;m<t.length;m++){let _=typeof t[m]=="string"&&!Tt();if(typeof t[m]!="string"||!Tt()){d=!1;break}}let g=i.pixelRatio;if(n.setSize(i.width/i.pixelRatio,i.height/i.pixelRatio),d){let m=t.join(" ");return s.save(),s.setAttr("filter",m),s.drawImage(i._canvas,0,0,i.getWidth()/g,i.getHeight()/g),s.restore(),this._filterUpToDate=!0,n}try{for(a=t.length,s.clear(),s.drawImage(i._canvas,0,0,i.getWidth()/g,i.getHeight()/g),o=s.getImageData(0,0,n.getWidth(),n.getHeight()),h=0;h<a;h++)c=t[h],typeof c=="string"&&(c=Ke(c)),c.call(this,o),s.putImageData(o,0,0)}catch(m){l.error("Unable to apply filter. "+m.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,n}on(...t){let e=t[0],i=t[1],n=t[2];if(this._cache&&this._cache.delete(jt),t.length===3)return this._delegate.apply(this,t);let s=e.split(gt);for(let a=0;a<s.length;a++){let h=s[a].split("."),c=h[0],d=h[1]||"";this.eventListeners[c]||(this.eventListeners[c]=[]),this.eventListeners[c].push({name:d,handler:i})}return this}off(t,e){let i=(t||"").split(gt),n=i.length,s,a,o,h,c,d;if(this._cache&&this._cache.delete(jt),!t)for(a in this.eventListeners)this._off(a);for(s=0;s<n;s++)if(o=i[s],h=o.split("."),c=h[0],d=h[1],c)this.eventListeners[c]&&this._off(c,d,e);else for(a in this.eventListeners)this._off(a,d,e);return this}dispatchEvent(t){let e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(i){e.call(this,i.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){let n=this;return this.on(t,function(s){let a=s.target.findAncestors(e,!0,n);for(let o=0;o<a.length;o++)s=l.cloneObject(s),s.currentTarget=a[o],i.call(a[o],s)}),this}remove(){return this.isDragging()&&this.stopDrag(),b._dragElements.delete(this._id),b._dragElements.forEach((t,e)=>{this.isAncestorOf(t.node)&&b._dragElements.delete(e)}),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(D),this._clearSelfAndDescendantCache(ft),this._clearSelfAndDescendantCache(qt),this._clearSelfAndDescendantCache(Zt),this._clearSelfAndDescendantCache(At),this._clearSelfAndDescendantCache(Rt)}_remove(){this._clearCaches();let 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){let e="get"+l._capitalize(t);return l._isFunction(this[e])?this[e]():this.attrs[t]}getAncestors(){let t=this.getParent(),e=[];for(;t;)e.push(t),t=t.getParent();return e}getAttrs(){return this.attrs||{}}setAttrs(t){return this._batchTransformChanges(()=>{let e,i;if(!t)return this;for(e in t)e!==je&&(i=$t+l._capitalize(e),l._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(Rt,this._isListening)}_isListening(t){if(!this.listening())return!1;let i=this.getParent();return i&&i!==t&&this!==t?i._isListening(t):!0}isVisible(){return this._getCache(At,this._isVisible)}_isVisible(t){if(!this.visible())return!1;let i=this.getParent();return i&&i!==t&&this!==t?i._isVisible(t):!0}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);let i=this.getLayer(),n=!1;b._dragElements.forEach(a=>{a.dragStatus==="dragging"&&(a.node.nodeType==="Stage"||a.node.getLayer()===i)&&(n=!0)});let s=!e&&!p.hitOnDragEnabled&&(n||p.isTransforming());return this.isListening()&&this.isVisible()&&!s}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t=this.getDepth(),e=this,i=0,n,s,a,o;function h(d){for(n=[],s=d.length,a=0;a<s;a++)o=d[a],i++,o.nodeType!==Jt&&(n=n.concat(o.getChildren().slice())),o._id===e._id&&(a=s);n.length>0&&n[0].getDepth()<=t&&h(n)}let c=this.getStage();return e.nodeType!==ii&&c&&h(c.getChildren()),i}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(F),this._clearSelfAndDescendantCache(D)),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(){let t=this.getStage();if(!t)return null;let e=t.getPointerPosition();if(!e)return null;let 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);let n=this.getAbsoluteTransform(t).getMatrix(),s=new L,a=this.offset();return s.m=n.slice(),s.translate(a.x,a.y),s.getTranslation()}setAbsolutePosition(t){let{x:e,y:i,...n}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(F);let s=this._getAbsoluteTransform().copy();return s.invert(),s.translate(t.x,t.y),t={x:this.attrs.x+s.getTranslation().x,y:this.attrs.y+s.getTranslation().y},this._setTransform(n),this.setPosition({x:t.x,y:t.y}),this._clearCache(F),this._clearSelfAndDescendantCache(D),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){let 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,n=this.x(),s=this.y();return e!==void 0&&(n+=e),i!==void 0&&(s+=i),this.setPosition({x:n,y:s}),this}_eachAncestorReverse(t,e){let i=[],n=this.getParent(),s,a;if(!(e&&e._id===this._id)){for(i.unshift(this);n&&(!e||n._id!==e._id);)i.unshift(n),n=n.parent;for(s=i.length,a=0;a<s;a++)t(i[a])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return l.warn("Node has no parent. moveToTop function is ignored."),!1;let t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0):!1}moveUp(){if(!this.parent)return l.warn("Node has no parent. moveUp function is ignored."),!1;let t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0):!1}moveDown(){if(!this.parent)return l.warn("Node has no parent. moveDown function is ignored."),!1;let t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return l.warn("Node has no parent. moveToBottom function is ignored."),!1;let t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(t){if(!this.parent)return l.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&l.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)+".");let 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(ft,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t=this.getAttrs(),e,i,n,s,a,o={attrs:{},className:this.getClassName()};for(e in t)i=t[e],a=l.isObject(i)&&!l._isPlainObject(i)&&!l._isArray(i),!a&&(n=typeof this[e]=="function"&&this[e],delete t[e],s=n?n.call(this):null,t[e]=i,s!==i&&(o.attrs[e]=i));return l._prepareToStringify(o)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){let n=[];e&&this._isMatch(t)&&n.push(this);let s=this.parent;for(;s;){if(s===i)return n;s._isMatch(t)&&n.push(s),s=s.parent}return n}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if(typeof t=="function")return t(this);let e=t.replace(/ /g,"").split(","),i=e.length,n,s;for(n=0;n<i;n++)if(s=e[n],l.isValidSelector(s)||(l.warn('Selector "'+s+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),l.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),l.warn("Konva is awesome, right?")),s.charAt(0)==="#"){if(this.id()===s.slice(1))return!0}else if(s.charAt(0)==="."){if(this.hasName(s.slice(1)))return!0}else if(this.className===s||this.nodeType===s)return!0;return!1}getLayer(){let t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(Zt,this._getStage)}_getStage(){let 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(D,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new L,this._eachAncestorReverse(function(i){let n=i.transformsEnabled();n==="all"?e.multiply(i.getTransform()):n==="position"&&e.translate(i.x()-i.offsetX(),i.y()-i.offsetY())},t),e;{e=this._cache.get(D)||new L,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();let i=this.transformsEnabled();if(i==="all")e.multiply(this.getTransform());else if(i==="position"){let n=this.attrs.x||0,s=this.attrs.y||0,a=this.attrs.offsetX||0,o=this.attrs.offsetY||0;e.translate(n-a,s-o)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();let n=this.getAbsoluteTransform(t).decompose();return{x:n.scaleX,y:n.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(F,this._getTransform)}_getTransform(){var t,e;let i=this._cache.get(F)||new L;i.reset();let n=this.x(),s=this.y(),a=p.getAngle(this.rotation()),o=(t=this.attrs.scaleX)!==null&&t!==void 0?t:1,h=(e=this.attrs.scaleY)!==null&&e!==void 0?e:1,c=this.attrs.skewX||0,d=this.attrs.skewY||0,g=this.attrs.offsetX||0,m=this.attrs.offsetY||0;return(n!==0||s!==0)&&i.translate(n,s),a!==0&&i.rotate(a),(c!==0||d!==0)&&i.skew(c,d),(o!==1||h!==1)&&i.scale(o,h),(g!==0||m!==0)&&i.translate(-1*g,-1*m),i.dirty=!1,i}clone(t){let e=l.cloneObject(this.attrs),i,n,s,a,o;for(i in t)e[i]=t[i];let h=new this.constructor(e);for(i in this.eventListeners)for(n=this.eventListeners[i],s=n.length,a=0;a<s;a++)o=n[a],o.name.indexOf(qe)<0&&(h.eventListeners[i]||(h.eventListeners[i]=[]),h.eventListeners[i].push(o));return h}_toKonvaCanvas(t){t=t||{};let e=this.getClientRect(),i=this.getStage(),n=t.x!==void 0?t.x:Math.floor(e.x),s=t.y!==void 0?t.y:Math.floor(e.y),a=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:a}),h=o.getContext(),c=new T({width:o.width/o.pixelRatio+Math.abs(n),height:o.height/o.pixelRatio+Math.abs(s),pixelRatio:o.pixelRatio});return t.imageSmoothingEnabled===!1&&(h._context.imageSmoothingEnabled=!1),h.save(),(n||s)&&h.translate(-1*n,-1*s),this.drawScene(o,void 0,c),h.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){t=t||{};let e=t.mimeType||null,i=t.quality||null,n=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(n),n}toImage(t){return new Promise((e,i)=>{try{let n=t?.callback;n&&delete t.callback,l._urlToImage(this.toDataURL(t),function(s){e(s),n?.(s)})}catch(n){i(n)}})}toBlob(t){return new Promise((e,i)=>{try{let n=t?.callback;n&&delete t.callback,this.toCanvas(t).toBlob(s=>{e(s),n?.(s)},t?.mimeType,t?.quality)}catch(n){i(n)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance!==void 0?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():p.dragDistance}_off(t,e,i){let n=this.eventListeners[t],s,a,o;for(s=0;s<n.length;s++)if(a=n[s].name,o=n[s].handler,(a!=="konva"||e==="konva")&&(!e||a===e)&&(!i||i===o)){if(n.splice(s,1),n.length===0){delete this.eventListeners[t];break}s--}}_fireChangeEvent(t,e,i){this._fire(t+ze,{oldVal:e,newVal:i})}addName(t){if(!this.hasName(t)){let e=this.name(),i=e?e+" "+t:t;this.name(i)}return this}hasName(t){if(!t)return!1;let e=this.name();return e?(e||"").split(/\s/g).indexOf(t)!==-1:!1}removeName(t){let e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return i!==-1&&(e.splice(i,1),this.name(e.join(" "))),this}setAttr(t,e){let i=this[$t+l._capitalize(t)];return l._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(p.autoDrawEnabled){let t=this.getLayer()||this.getStage();t?.batchDraw()}}_setAttr(t,e){let i=this.attrs[t];i===e&&!l.isObject(e)||(e==null?delete this.attrs[t]:this.attrs[t]=e,this._shouldFireChangeEvents&&this._fireChangeEvent(t,i,e),this._requestDraw())}_setComponentAttr(t,e,i){let n;i!==void 0&&(n=this.attrs[t],n||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,n,i))}_fireAndBubble(t,e,i){e&&this.nodeType===Jt&&(e.target=this);let n=[$e,Je,Ze,Qe,ti,ei];if(!(n.indexOf(t)!==-1&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||this.nodeType==="Stage"&&!i))){this._fire(t,e);let a=n.indexOf(t)!==-1&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!a&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i;let{nodeType:n}=this,s=r.protoListenerMap.get(n)||{},a=s?.[t];if(a===void 0){a=[];let o=Object.getPrototypeOf(this);for(;o;){let h=(i=(e=o.eventListeners)===null||e===void 0?void 0:e[t])!==null&&i!==void 0?i:[];a.push(...h),o=Object.getPrototypeOf(o)}s[t]=a,r.protoListenerMap.set(n,s)}return a}_fire(t,e){e=e||{},e.currentTarget=this,e.type=t;let i=this._getProtoListeners(t);if(i)for(let s=0;s<i.length;s++)i[s].handler.call(this,e);let n=this.eventListeners[t];if(n)for(let s=0;s<n.length;s++)n[s].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){let e=t?t.pointerId:void 0,i=this.getStage(),n=this.getAbsolutePosition();if(!i)return;let s=i._getPointerById(e)||i._changedPointerPositions[0]||n;b._dragElements.set(this._id,{node:this,startPointerPos:s,offset:{x:s.x-n.x,y:s.y-n.y},dragStatus:"ready",pointerId:e,startEvent:t})}startDrag(t,e=!0){b._dragElements.has(this._id)||this._createDragElement(t);let i=b._dragElements.get(this._id);i.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:i.startEvent&&i.startEvent.evt||t&&t.evt},e)}_setDragPosition(t,e){let i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let n={x:i.x-e.offset.x,y:i.y-e.offset.y},s=this.dragBoundFunc();if(s!==void 0){let a=s.call(this,n,t);a?n=a:l.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==n.x||this._lastPos.y!==n.y)&&(this.setAbsolutePosition(n),this._requestDraw()),this._lastPos=n}stopDrag(t){let e=b._dragElements.get(this._id);e&&(e.dragStatus="stopped"),b._endDragBefore(t),b._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){let t=b._dragElements.get(this._id);return t?t.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(t.evt.button!==void 0)||p.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let n=!1;b._dragElements.forEach(s=>{this.isAncestorOf(s.node)&&(n=!0)}),n||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;let e=b._dragElements.get(this._id),i=e&&e.dragStatus==="dragging",n=e&&e.dragStatus==="ready";i?this.stopDrag():n&&b._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){let e=this.getStage();if(!e)return!1;let i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return l.haveIntersection(i,this.getClientRect())}static create(t,e){return l._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let i=r.prototype.getClassName.call(t),n=t.children,s,a,o;e&&(t.attrs.container=e),p[i]||(l.warn('Can not find a node with class name "'+i+'". Fallback to "Shape".'),i="Shape");let h=p[i];if(s=new h(t.attrs),n)for(a=n.length,o=0;o<a;o++)s.add(r._createNode(n[o]));return s}};v.protoListenerMap=new Map;v.prototype.nodeType="Node";v.prototype._attrsAffectingSize=[];v.prototype.eventListeners={};v.prototype.on(ni,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(F),this._clearSelfAndDescendantCache(D)});v.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(At)});v.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(Rt)});v.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache(ft)});var w=u.addGetterSetter;w(v,"zIndex");w(v,"absolutePosition");w(v,"position");w(v,"x",0,C());w(v,"y",0,C());w(v,"globalCompositeOperation","source-over",M());w(v,"opacity",1,C());w(v,"name","",M());w(v,"id","",M());w(v,"rotation",0,C());u.addComponentsGetterSetter(v,"scale",["x","y"]);w(v,"scaleX",1,C());w(v,"scaleY",1,C());u.addComponentsGetterSetter(v,"skew",["x","y"]);w(v,"skewX",0,C());w(v,"skewY",0,C());u.addComponentsGetterSetter(v,"offset",["x","y"]);w(v,"offsetX",0,C());w(v,"offsetY",0,C());w(v,"dragDistance",void 0,C());w(v,"width",0,C());w(v,"height",0,C());w(v,"listening",!0,R());w(v,"preventDefault",!0,R());w(v,"filters",void 0,function(r){return this._filterUpToDate=!1,r});w(v,"visible",!0,R());w(v,"transformsEnabled","all",M());w(v,"size");w(v,"dragBoundFunc");w(v,"draggable",!1,R());u.backCompat(v,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var P=class extends v{constructor(){super(...arguments),this.children=[]}getChildren(t){let e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(t.length===0)return this;if(t.length>1){for(let i=0;i<t.length;i++)this.add(t[i]);return this}let 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){let e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){let i=[];return this._descendants(n=>{let s=n._isMatch(t);return s&&i.push(n),!!(s&&e)}),i}_descendants(t){let e=!1,i=this.getChildren();for(let n of i){if(e=t(n),e)return!0;if(n.hasChildren()&&(e=n._descendants(t),e))return!0}return!1}toObject(){let t=v.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){let e=v.prototype.clone.call(this,t);return this.getChildren().forEach(function(i){e.add(i.clone())}),e}getAllIntersections(t){let e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),!this.isCached()&&((e=this.children)===null||e===void 0||e.forEach(function(i){i._clearSelfAndDescendantCache(t)}))}_setChildrenIndices(){var t;(t=this.children)===null||t===void 0||t.forEach(function(e,i){e.index=i}),this._requestDraw()}drawScene(t,e,i){let n=this.getLayer(),s=t||n&&n.getCanvas(),a=s&&s.getContext(),o=this._getCanvasCache(),h=o&&o.scene,c=s&&s.isCache;if(!this.isVisible()&&!c)return this;if(h){a.save();let d=this.getAbsoluteTransform(e).getMatrix();a.transform(d[0],d[1],d[2],d[3],d[4],d[5]),this._drawCachedSceneCanvas(a),a.restore()}else this._drawChildren("drawScene",s,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;let i=this.getLayer(),n=t||i&&i.hitCanvas,s=n&&n.getContext(),a=this._getCanvasCache();if(a&&a.hit){s.save();let h=this.getAbsoluteTransform(e).getMatrix();s.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedHitCanvas(s),s.restore()}else this._drawChildren("drawHit",n,e);return this}_drawChildren(t,e,i,n){var s;let a=e&&e.getContext(),o=this.clipWidth(),h=this.clipHeight(),c=this.clipFunc(),d=typeof o=="number"&&typeof h=="number"||c,g=i===this;if(d){a.save();let _=this.getAbsoluteTransform(i),y=_.getMatrix();a.transform(y[0],y[1],y[2],y[3],y[4],y[5]),a.beginPath();let x;if(c)x=c.call(this,a,this);else{let k=this.clipX(),S=this.clipY();a.rect(k||0,S||0,o,h)}a.clip.apply(a,x),y=_.copy().invert().getMatrix(),a.transform(y[0],y[1],y[2],y[3],y[4],y[5])}let m=!g&&this.globalCompositeOperation()!=="source-over"&&t==="drawScene";m&&(a.save(),a._applyGlobalCompositeOperation(this)),(s=this.children)===null||s===void 0||s.forEach(function(_){_[t](e,i,n)}),m&&a.restore(),d&&a.restore()}getClientRect(t={}){var e;let i=t.skipTransform,n=t.relativeTo,s,a,o,h,c={x:1/0,y:1/0,width:0,height:0},d=this;(e=this.children)===null||e===void 0||e.forEach(function(_){if(!_.visible())return;let y=_.getClientRect({relativeTo:d,skipShadow:t.skipShadow,skipStroke:t.skipStroke});y.width===0&&y.height===0||(s===void 0?(s=y.x,a=y.y,o=y.x+y.width,h=y.y+y.height):(s=Math.min(s,y.x),a=Math.min(a,y.y),o=Math.max(o,y.x+y.width),h=Math.max(h,y.y+y.height)))});let g=this.find("Shape"),m=!1;for(let _=0;_<g.length;_++)if(g[_]._isVisible(this)){m=!0;break}return m&&s!==void 0?c={x:s,y:a,width:o-s,height:h-a}:c={x:0,y:0,width:0,height:0},i?c:this._transformedRect(c,n)}};u.addComponentsGetterSetter(P,"clip",["x","y","width","height"]);u.addGetterSetter(P,"clipX",void 0,C());u.addGetterSetter(P,"clipY",void 0,C());u.addGetterSetter(P,"clipWidth",void 0,C());u.addGetterSetter(P,"clipHeight",void 0,C());u.addGetterSetter(P,"clipFunc");var Z=new Map,Qt=p._global.PointerEvent!==void 0;function pt(r){return Z.get(r)}function mt(r){return{evt:r,pointerId:r.pointerId}}function _t(r,t){return Z.get(r)===t}function yt(r,t){Y(r),t.getStage()&&(Z.set(r,t),Qt&&t._fire("gotpointercapture",mt(new PointerEvent("gotpointercapture"))))}function Y(r,t){let e=Z.get(r);if(!e)return;let i=e.getStage();i&&i.content,Z.delete(r),Qt&&e._fire("lostpointercapture",mt(new PointerEvent("lostpointercapture")))}var si="Stage",ai="string",ee="px",oi="mouseout",ne="mouseleave",re="mouseover",se="mouseenter",ae="mousemove",oe="mousedown",he="mouseup",Q="pointermove",tt="pointerdown",V="pointerup",et="pointercancel",hi="lostpointercapture",vt="pointerout",it="pointerleave",Ct="pointerover",bt="pointerenter",Dt="contextmenu",le="touchstart",ce="touchend",de="touchmove",ue="touchcancel",Gt="wheel",li=5,ci=[[se,"_pointerenter"],[oe,"_pointerdown"],[ae,"_pointermove"],[he,"_pointerup"],[ne,"_pointerleave"],[le,"_pointerdown"],[de,"_pointermove"],[ce,"_pointerup"],[ue,"_pointercancel"],[re,"_pointerover"],[Gt,"_wheel"],[Dt,"_contextmenu"],[tt,"_pointerdown"],[Q,"_pointermove"],[V,"_pointerup"],[et,"_pointercancel"],[it,"_pointerleave"],[hi,"_lostpointercapture"]],Lt={mouse:{[vt]:oi,[it]:ne,[Ct]:re,[bt]:se,[Q]:ae,[tt]:oe,[V]:he,[et]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[vt]:"touchout",[it]:"touchleave",[Ct]:"touchover",[bt]:"touchenter",[Q]:de,[tt]:le,[V]:ce,[et]:ue,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[vt]:vt,[it]:it,[Ct]:Ct,[bt]:bt,[Q]:Q,[tt]:tt,[V]:V,[et]:et,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},nt=r=>r.indexOf("pointer")>=0?"pointer":r.indexOf("touch")>=0?"touch":"mouse",X=r=>{let t=nt(r);if(t==="pointer")return p.pointerEventsEnabled&&Lt.pointer;if(t==="touch")return Lt.touch;if(t==="mouse")return Lt.mouse};function ie(r={}){return(r.clipFunc||r.clipWidth||r.clipHeight)&&l.warn("Stage does not support clipping. Please use clip for Layers or Groups."),r}var di="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);",wt=[],U=class extends P{constructor(t){super(ie(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),wt.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{ie(this.attrs)}),this._checkVisibility()}_validateAdd(t){let e=t.getType()==="Layer",i=t.getType()==="FastLayer";e||i||l.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;let t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if(typeof t===ai){let e;if(t.charAt(0)==="."){let i=t.slice(1);t=document.getElementsByClassName(i)[0]}else t.charAt(0)!=="#"?e=t:e=t.slice(1),t=document.getElementById(e);if(!t)throw"Can not find container in document with id "+e}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){let t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].clear();return this}clone(t){return t||(t={}),t.container=typeof document<"u"&&document.createElement("div"),P.prototype.clone.call(this,t)}destroy(){super.destroy();let t=this.content;t&&l._isInDocument(t)&&this.container().removeChild(t);let e=wt.indexOf(this);return e>-1&&wt.splice(e,1),l.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){let t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(l.warn(di),null)}_getPointerById(t){return this._pointerPositions.find(e=>e.id===t)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){t={...t},t.x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();let e=new T({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,n=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),n.forEach(function(s){if(!s.isVisible())return;let a=s._toKonvaCanvas(t);i.drawImage(a._canvas,t.x,t.y,a.getWidth()/a.getPixelRatio(),a.getHeight()/a.getPixelRatio())}),e}getIntersection(t){if(!t)return null;let e=this.children,i=e.length,n=i-1;for(let s=n;s>=0;s--){let a=e[s].getIntersection(t);if(a)return a}return null}_resizeDOM(){let t=this.width(),e=this.height();this.content&&(this.content.style.width=t+ee,this.content.style.height=e+ee),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 n=0;n<arguments.length;n++)this.add(arguments[n]);return this}super.add(t);let i=this.children.length;return i>li&&l.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(),p.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return _t(t,this)}setPointerCapture(t){yt(t,this)}releaseCapture(t){Y(t,this)}getLayers(){return this.children}_bindContentEvents(){p.isBrowser&&ci.forEach(([t,e])=>{this.content.addEventListener(t,i=>{this[e](i)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);let e=X(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);let e=X(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){let e=X(t.type),i=nt(t.type);if(!e)return;this.setPointersPositions(t);let n=this._getTargetShape(i),s=!(p.isDragging()||p.isTransforming())||p.hitOnDragEnabled;n&&s?(n._fireAndBubble(e.pointerout,{evt:t}),n._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"targetShape"]=null):s&&(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){let e=X(t.type),i=nt(t.type);if(!e)return;this.setPointersPositions(t);let n=!1;this._changedPointerPositions.forEach(s=>{let a=this.getIntersection(s);if(b.justDragged=!1,p["_"+i+"ListenClick"]=!0,!a||!a.isListening()){this[i+"ClickStartShape"]=void 0;return}p.capturePointerEventsEnabled&&a.setPointerCapture(s.id),this[i+"ClickStartShape"]=a,a._fireAndBubble(e.pointerdown,{evt:t,pointerId:s.id}),n=!0;let o=t.type.indexOf("touch")>=0;a.preventDefault()&&t.cancelable&&o&&t.preventDefault()}),n||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){let e=X(t.type),i=nt(t.type);if(!e)return;let n=t.type.indexOf("touch")>=0||t.pointerType==="touch";if(p.isDragging()&&b.node.preventDefault()&&t.cancelable&&n&&t.preventDefault(),this.setPointersPositions(t),!(!(p.isDragging()||p.isTransforming())||p.hitOnDragEnabled))return;let a={},o=!1,h=this._getTargetShape(i);this._changedPointerPositions.forEach(c=>{let d=pt(c.id)||this.getIntersection(c),g=c.id,m={evt:t,pointerId:g},_=h!==d;if(_&&h&&(h._fireAndBubble(e.pointerout,{...m},d),h._fireAndBubble(e.pointerleave,{...m},d)),d){if(a[d._id])return;a[d._id]=!0}d&&d.isListening()?(o=!0,_&&(d._fireAndBubble(e.pointerover,{...m},h),d._fireAndBubble(e.pointerenter,{...m},h),this[i+"targetShape"]=d),d._fireAndBubble(e.pointermove,{...m})):h&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:g}),this[i+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){let e=X(t.type),i=nt(t.type);if(!e)return;this.setPointersPositions(t);let n=this[i+"ClickStartShape"],s=this[i+"ClickEndShape"],a={},o=!1;this._changedPointerPositions.forEach(h=>{let c=pt(h.id)||this.getIntersection(h);if(c){if(c.releaseCapture(h.id),a[c._id])return;a[c._id]=!0}let d=h.id,g={evt:t,pointerId:d},m=!1;p["_"+i+"InDblClickWindow"]?(m=!0,clearTimeout(this[i+"DblTimeout"])):b.justDragged||(p["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){p["_"+i+"InDblClickWindow"]=!1},p.dblClickWindow),c&&c.isListening()?(o=!0,this[i+"ClickEndShape"]=c,c._fireAndBubble(e.pointerup,{...g}),p["_"+i+"ListenClick"]&&n&&n===c&&(c._fireAndBubble(e.pointerclick,{...g}),m&&s&&s===c&&c._fireAndBubble(e.pointerdblclick,{...g}))):(this[i+"ClickEndShape"]=null,o||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),o=!0),p["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),m&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))}),o||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),p["_"+i+"ListenClick"]=!1,t.cancelable&&i!=="touch"&&i!=="pointer"&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);let e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Dt,{evt:t}):this._fire(Dt,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);let e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Gt,{evt:t}):this._fire(Gt,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);let e=pt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(V,mt(t)),Y(t.pointerId)}_lostpointercapture(t){Y(t.pointerId)}setPointersPositions(t){let e=this._getContentPosition(),i=null,n=null;t=t||window.event,t.touches!==void 0?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,s=>{this._pointerPositions.push({id:s.identifier,x:(s.clientX-e.left)/e.scaleX,y:(s.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,s=>{this._changedPointerPositions.push({id:s.identifier,x:(s.clientX-e.left)/e.scaleX,y:(s.clientY-e.top)/e.scaleY})})):(i=(t.clientX-e.left)/e.scaleX,n=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:n},this._pointerPositions=[{x:i,y:n,id:l._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:n,id:l._getFirstPointerId(t)}])}_setPointerPosition(t){l.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};let 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 N({pixelRatio:1,width:this.width(),height:this.height()}),!p.isBrowser)return;let 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 l.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}};U.prototype.nodeType=si;I(U);u.addGetterSetter(U,"container");p.isBrowser&&document.addEventListener("visibilitychange",()=>{wt.forEach(r=>{r.batchDraw()})});var fe="hasShadow",ge="shadowRGBA",pe="patternImage",me="linearGradient",_e="radialGradient",St;function Ot(){return St||(St=l.createCanvasElement().getContext("2d"),St)}var rt={};function ui(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function fi(r){r.stroke()}function gi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function pi(r){r.stroke()}function mi(){this._clearCache(fe)}function _i(){this._clearCache(ge)}function yi(){this._clearCache(pe)}function vi(){this._clearCache(me)}function Ci(){this._clearCache(_e)}var f=class extends v{constructor(t){super(t);let e,i=0;for(;e=l.getHitColor(),!(e&&!(e in rt));)if(i++,i>=1e4){l.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=l.getRandomColor();break}this.colorKey=e,rt[e]=this}getContext(){return l.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return l.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(fe,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(pe,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){let e=Ot().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){let i=new L;i.translate(this.fillPatternX(),this.fillPatternY()),i.rotate(p.getAngle(this.fillPatternRotation())),i.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),i.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());let n=i.getMatrix(),s=typeof DOMMatrix>"u"?{a:n[0],b:n[1],c:n[2],d:n[3],e:n[4],f:n[5]}:new DOMMatrix(n);e.setTransform(s)}return e}}_getLinearGradient(){return this._getCache(me,this.__getLinearGradient)}__getLinearGradient(){let t=this.fillLinearGradientColorStops();if(t){let e=Ot(),i=this.fillLinearGradientStartPoint(),n=this.fillLinearGradientEndPoint(),s=e.createLinearGradient(i.x,i.y,n.x,n.y);for(let a=0;a<t.length;a+=2)s.addColorStop(t[a],t[a+1]);return s}}_getRadialGradient(){return this._getCache(_e,this.__getRadialGradient)}__getRadialGradient(){let t=this.fillRadialGradientColorStops();if(t){let e=Ot(),i=this.fillRadialGradientStartPoint(),n=this.fillRadialGradientEndPoint(),s=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),n.x,n.y,this.fillRadialGradientEndRadius());for(let a=0;a<t.length;a+=2)s.addColorStop(t[a],t[a+1]);return s}}getShadowRGBA(){return this._getCache(ge,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;let t=l.colorToRGBA(this.shadowColor());if(t)return"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")"}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){let t=this.hitStrokeWidth();return t==="auto"?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){let e=this.getStage();if(!e)return!1;let i=e.bufferHitCanvas;return i.getContext().clear(),this.drawHit(i,void 0,!0),i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return v.prototype.destroy.call(this),delete rt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!((e=this.attrs.perfectDrawEnabled)!==null&&e!==void 0?e:!0))return!1;let n=t||this.hasFill(),s=this.hasStroke(),a=this.getAbsoluteOpacity()!==1;if(n&&s&&a)return!0;let o=this.hasShadow(),h=this.shadowForStrokeEnabled();return!!(n&&s&&o&&h)}setStrokeHitEnabled(t){l.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){let 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()}let n=t.skipTransform,s=t.relativeTo||e&&this.getStage()||void 0,a=this.getSelfRect(),h=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,c=a.width+h,d=a.height+h,g=!t.skipShadow&&this.hasShadow(),m=g?this.shadowOffsetX():0,_=g?this.shadowOffsetY():0,y=c+Math.abs(m),x=d+Math.abs(_),k=g&&this.shadowBlur()||0,S=y+k*2,G=x+k*2,O={width:S,height:G,x:-(h/2+k)+Math.min(m,0)+a.x,y:-(h/2+k)+Math.min(_,0)+a.y};return n?O:this._transformedRect(O,s)}drawScene(t,e,i){let n=this.getLayer(),s=t||n.getCanvas(),a=s.getContext(),o=this._getCanvasCache(),h=this.getSceneFunc(),c=this.hasShadow(),d,g=!1,m=e===this;if(!this.isVisible()&&!m)return this;if(o){a.save();let _=this.getAbsoluteTransform(e).getMatrix();return a.transform(_[0],_[1],_[2],_[3],_[4],_[5]),this._drawCachedSceneCanvas(a),a.restore(),this}if(!h)return this;if(a.save(),this._useBufferCanvas()&&!g){d=this.getStage();let _=i||d.bufferCanvas,y=_.getContext();i?(y.save(),y.setTransform(1,0,0,1,0,0),y.clearRect(0,0,_.width,_.height),y.restore()):y.clear(),y.save(),y._applyLineJoin(this),y._applyMiterLimit(this);let x=this.getAbsoluteTransform(e).getMatrix();y.transform(x[0],x[1],x[2],x[3],x[4],x[5]),h.call(this,y,this),y.restore();let k=_.pixelRatio;c&&a._applyShadow(this),m||(a._applyOpacity(this),a._applyGlobalCompositeOperation(this)),a.drawImage(_._canvas,_.x||0,_.y||0,_.width/k,_.height/k)}else{if(a._applyLineJoin(this),a._applyMiterLimit(this),!m){let _=this.getAbsoluteTransform(e).getMatrix();a.transform(_[0],_[1],_[2],_[3],_[4],_[5]),a._applyOpacity(this),a._applyGlobalCompositeOperation(this)}c&&a._applyShadow(this),h.call(this,a,this)}return a.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;let n=this.getLayer(),s=t||n.hitCanvas,a=s&&s.getContext(),o=this.hitFunc()||this.sceneFunc(),h=this._getCanvasCache(),c=h&&h.hit;if(this.colorKey||l.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()"),c){a.save();let g=this.getAbsoluteTransform(e).getMatrix();return a.transform(g[0],g[1],g[2],g[3],g[4],g[5]),this._drawCachedHitCanvas(a),a.restore(),this}if(!o)return this;if(a.save(),a._applyLineJoin(this),a._applyMiterLimit(this),!(this===e)){let g=this.getAbsoluteTransform(e).getMatrix();a.transform(g[0],g[1],g[2],g[3],g[4],g[5])}return o.call(this,a,this),a.restore(),this}drawHitFromCache(t=0){let e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),n=e.hit,s=n.getContext(),a=n.getWidth(),o=n.getHeight();s.clear(),s.drawImage(i._canvas,0,0,a,o);try{let h=s.getImageData(0,0,a,o),c=h.data,d=c.length,g=l._hexToRgb(this.colorKey);for(let m=0;m<d;m+=4)c[m+3]>t?(c[m]=g.r,c[m+1]=g.g,c[m+2]=g.b,c[m+3]=255):c[m+3]=0;s.putImageData(h,0,0)}catch(h){l.error("Unable to draw hit graph from cached scene canvas. "+h.message)}return this}hasPointerCapture(t){return _t(t,this)}setPointerCapture(t){yt(t,this)}releaseCapture(t){Y(t,this)}};f.prototype._fillFunc=ui;f.prototype._strokeFunc=fi;f.prototype._fillFuncHit=gi;f.prototype._strokeFuncHit=pi;f.prototype._centroid=!1;f.prototype.nodeType="Shape";I(f);f.prototype.eventListeners={};f.prototype.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",mi);f.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",_i);f.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",yi);f.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",vi);f.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",Ci);u.addGetterSetter(f,"stroke",void 0,Pt());u.addGetterSetter(f,"strokeWidth",2,C());u.addGetterSetter(f,"fillAfterStrokeEnabled",!1);u.addGetterSetter(f,"hitStrokeWidth","auto",Vt());u.addGetterSetter(f,"strokeHitEnabled",!0,R());u.addGetterSetter(f,"perfectDrawEnabled",!0,R());u.addGetterSetter(f,"shadowForStrokeEnabled",!0,R());u.addGetterSetter(f,"lineJoin");u.addGetterSetter(f,"lineCap");u.addGetterSetter(f,"miterLimit");u.addGetterSetter(f,"sceneFunc");u.addGetterSetter(f,"hitFunc");u.addGetterSetter(f,"dash");u.addGetterSetter(f,"dashOffset",0,C());u.addGetterSetter(f,"shadowColor",void 0,M());u.addGetterSetter(f,"shadowBlur",0,C());u.addGetterSetter(f,"shadowOpacity",1,C());u.addComponentsGetterSetter(f,"shadowOffset",["x","y"]);u.addGetterSetter(f,"shadowOffsetX",0,C());u.addGetterSetter(f,"shadowOffsetY",0,C());u.addGetterSetter(f,"fillPatternImage");u.addGetterSetter(f,"fill",void 0,Pt());u.addGetterSetter(f,"fillPatternX",0,C());u.addGetterSetter(f,"fillPatternY",0,C());u.addGetterSetter(f,"fillLinearGradientColorStops");u.addGetterSetter(f,"strokeLinearGradientColorStops");u.addGetterSetter(f,"fillRadialGradientStartRadius",0);u.addGetterSetter(f,"fillRadialGradientEndRadius",0);u.addGetterSetter(f,"fillRadialGradientColorStops");u.addGetterSetter(f,"fillPatternRepeat","repeat");u.addGetterSetter(f,"fillEnabled",!0);u.addGetterSetter(f,"strokeEnabled",!0);u.addGetterSetter(f,"shadowEnabled",!0);u.addGetterSetter(f,"dashEnabled",!0);u.addGetterSetter(f,"strokeScaleEnabled",!0);u.addGetterSetter(f,"fillPriority","color");u.addComponentsGetterSetter(f,"fillPatternOffset",["x","y"]);u.addGetterSetter(f,"fillPatternOffsetX",0,C());u.addGetterSetter(f,"fillPatternOffsetY",0,C());u.addComponentsGetterSetter(f,"fillPatternScale",["x","y"]);u.addGetterSetter(f,"fillPatternScaleX",1,C());u.addGetterSetter(f,"fillPatternScaleY",1,C());u.addComponentsGetterSetter(f,"fillLinearGradientStartPoint",["x","y"]);u.addComponentsGetterSetter(f,"strokeLinearGradientStartPoint",["x","y"]);u.addGetterSetter(f,"fillLinearGradientStartPointX",0);u.addGetterSetter(f,"strokeLinearGradientStartPointX",0);u.addGetterSetter(f,"fillLinearGradientStartPointY",0);u.addGetterSetter(f,"strokeLinearGradientStartPointY",0);u.addComponentsGetterSetter(f,"fillLinearGradientEndPoint",["x","y"]);u.addComponentsGetterSetter(f,"strokeLinearGradientEndPoint",["x","y"]);u.addGetterSetter(f,"fillLinearGradientEndPointX",0);u.addGetterSetter(f,"strokeLinearGradientEndPointX",0);u.addGetterSetter(f,"fillLinearGradientEndPointY",0);u.addGetterSetter(f,"strokeLinearGradientEndPointY",0);u.addComponentsGetterSetter(f,"fillRadialGradientStartPoint",["x","y"]);u.addGetterSetter(f,"fillRadialGradientStartPointX",0);u.addGetterSetter(f,"fillRadialGradientStartPointY",0);u.addComponentsGetterSetter(f,"fillRadialGradientEndPoint",["x","y"]);u.addGetterSetter(f,"fillRadialGradientEndPointX",0);u.addGetterSetter(f,"fillRadialGradientEndPointY",0);u.addGetterSetter(f,"fillPatternRotation",0);u.addGetterSetter(f,"fillRule",void 0,M());u.backCompat(f,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var bi="beforeDraw",wi="draw",ye=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Si=ye.length,A=class extends P{constructor(t){super(t),this.canvas=new T,this.hitCanvas=new N({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);let 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(){v.prototype.moveToTop.call(this);let t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!v.prototype.moveUp.call(this))return!1;let e=this.getStage();return!e||!e.content?!1:(e.content.removeChild(this.getNativeCanvasElement()),this.index<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[this.index+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(v.prototype.moveDown.call(this)){let t=this.getStage();if(t){let 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(v.prototype.moveToBottom.call(this)){let t=this.getStage();if(t){let 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(){let t=this.getNativeCanvasElement();return v.prototype.remove.call(this),t&&t.parentNode&&l._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){let e=t.getType();e!=="Group"&&e!=="Shape"&&l.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return t={...t},t.width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=t.x!==void 0?t.x:this.x(),t.y=t.y!==void 0?t.y:this.y(),v.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){this.visible()?this.canvas._canvas.style.display="block":this.canvas._canvas.style.display="none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){l.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){l.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,l.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;let e=1,i=!1;for(;;){for(let n=0;n<Si;n++){let s=ye[n],a=this._getIntersection({x:t.x+s.x*e,y:t.y+s.y*e}),o=a.shape;if(o)return o;if(i=!!a.antialiased,!a.antialiased)break}if(i)e+=1;else return null}}_getIntersection(t){let e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,n=i[3];if(n===255){let s=l.getHitColorKey(i[0],i[1],i[2]),a=rt[s];return a?{shape:a}:{antialiased:!0}}else if(n>0)return{antialiased:!0};return{}}drawScene(t,e,i){let n=this.getLayer(),s=t||n&&n.getCanvas();return this._fire(bi,{node:this}),this.clearBeforeDraw()&&s.getContext().clear(),P.prototype.drawScene.call(this,s,e,i),this._fire(wi,{node:this}),this}drawHit(t,e){let i=this.getLayer(),n=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),P.prototype.drawHit.call(this,n,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){l.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return l.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;let t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}destroy(){return l.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};A.prototype.nodeType="Layer";I(A);u.addGetterSetter(A,"imageSmoothingEnabled",!0);u.addGetterSetter(A,"clearBeforeDraw",!0);u.addGetterSetter(A,"hitGraphEnabled",!0,R());var E=class r extends f{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",e=>{this._removeImageLoad(e.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){let t=this.image();t&&t.complete||t&&t.readyState===4||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){let t=!!this.cornerRadius(),e=this.hasShadow();return t&&e?!0:super._useBufferCanvas(!0)}_sceneFunc(t){let e=this.getWidth(),i=this.getHeight(),n=this.cornerRadius(),s=this.attrs.image,a;if(s){let o=this.attrs.cropWidth,h=this.attrs.cropHeight;o&&h?a=[s,this.cropX(),this.cropY(),o,h,0,0,e,i]:a=[s,0,0,e,i]}(this.hasFill()||this.hasStroke()||n)&&(t.beginPath(),n?l.drawRoundedRectPath(t,e,i,n):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),s&&(n&&t.clip(),t.drawImage.apply(t,a))}_hitFunc(t){let e=this.width(),i=this.height(),n=this.cornerRadius();t.beginPath(),n?l.drawRoundedRectPath(t,e,i,n):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e,i;return(i=(t=this.attrs.width)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.width)!==null&&i!==void 0?i:0}getHeight(){var t,e,i;return(i=(t=this.attrs.height)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.height)!==null&&i!==void 0?i:0}static fromURL(t,e,i=null){let n=l.createImageElement();n.onload=function(){let s=new r({image:n});e(s)},n.onerror=i,n.crossOrigin="Anonymous",n.src=t}};E.prototype.className="Image";E.prototype._attrsAffectingSize=["image"];I(E);u.addGetterSetter(E,"cornerRadius",0,Xt(4));u.addGetterSetter(E,"image");u.addComponentsGetterSetter(E,"crop",["x","y","width","height"]);u.addGetterSetter(E,"cropX",0,C());u.addGetterSetter(E,"cropY",0,C());u.addGetterSetter(E,"cropWidth",0,C());u.addGetterSetter(E,"cropHeight",0,C());function It(r,t){r.konvaNode.on("click",()=>{t()})}function st(r,t){r?t():window.addEventListener("scratch-engine-ready",t,{once:!0})}function xi(r){let t={space:" ","left arrow":"ArrowLeft","right arrow":"ArrowRight","up arrow":"ArrowUp","down arrow":"ArrowDown",any:"any"},e=r.trim().toLowerCase();return t[e]??e}function Mt(r,t){let e=r.trim().toLowerCase(),i=xi(e);window.addEventListener("keydown",n=>{if(i==="any"){t();return}(typeof i=="string"&&n.key.toLowerCase()===i.toLowerCase()||i?.length===1&&n.key.length===1&&n.key.toLowerCase()===i.toLowerCase())&&t()})}function ki(r){let t=document.createElement("div");return t.style.position="absolute",t.style.padding="4px 6px",t.style.background="rgba(255,255,255,0.85)",t.style.border="1px solid rgba(0,0,0,0.15)",t.style.borderRadius="6px",t.style.whiteSpace="pre",t.style.display="none",r==="list"&&(t.style.maxWidth="220px"),t}var xt=class{constructor(t){this.variableMonitors=new Map;this.listMonitors=new Map;this.monitorOrder=[];t.style.position=t.style.position||"relative",this.root=document.createElement("div"),this.root.style.position="absolute",this.root.style.left="0",this.root.style.top="0",this.root.style.width="100%",this.root.style.height="100%",this.root.style.zIndex="9999",this.root.style.pointerEvents="none",this.root.style.fontFamily="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",this.root.style.fontSize="12px",this.root.style.color="#111",t.appendChild(this.root)}layout(){let t=6;for(let e of this.monitorOrder){let i=this.variableMonitors.get(e)??this.listMonitors.get(e);!i||i.style.display==="none"||(i.style.left="6px",i.style.top=`${t}px`,t+=i.getBoundingClientRect().height+6)}}ensure(t,e){let i=t==="variable"?this.variableMonitors:this.listMonitors,n=i.get(e);if(n)return n;let s=ki(t);return this.root.appendChild(s),i.set(e,s),this.monitorOrder.push(e),s}showVariable(t){let e=this.ensure("variable",t);e.style.display="block",this.layout()}hideVariable(t){let e=this.variableMonitors.get(t);e&&(e.style.display="none",this.layout())}renderVariable(t,e){let i=this.ensure("variable",t);i.style.display="block",i.textContent=`${t}: ${String(e)}`,this.layout()}showList(t){let e=this.ensure("list",t);e.style.display="block",this.layout()}hideList(t){let e=this.listMonitors.get(t);e&&(e.style.display="none",this.layout())}renderList(t,e){let i=this.ensure("list",t);i.style.display="block",Array.isArray(e)?i.textContent=`${t}:
|
|
14
|
+
`,Ut=()=>{if(typeof document>"u")throw new Error(we)},L=class r{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 r(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){let 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){let e=Math.cos(t),i=Math.sin(t),n=this.m[0]*e+this.m[2]*i,s=this.m[1]*e+this.m[3]*i,a=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=n,this.m[1]=s,this.m[2]=a,this.m[3]=o,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){let i=this.m[0]+this.m[2]*e,n=this.m[1]+this.m[3]*e,s=this.m[2]+this.m[0]*t,a=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=n,this.m[2]=s,this.m[3]=a,this}multiply(t){let 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],n=this.m[0]*t.m[2]+this.m[2]*t.m[3],s=this.m[1]*t.m[2]+this.m[3]*t.m[3],a=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]=n,this.m[3]=s,this.m[4]=a,this.m[5]=o,this}invert(){let t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,n=-this.m[2]*t,s=this.m[0]*t,a=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]=n,this.m[3]=s,this.m[4]=a,this.m[5]=o,this}getMatrix(){return this.m}decompose(){let t=this.m[0],e=this.m[1],i=this.m[2],n=this.m[3],s=this.m[4],a=this.m[5],o=t*n-e*i,h={x:s,y:a,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(t!=0||e!=0){let c=Math.sqrt(t*t+e*e);h.rotation=e>0?Math.acos(t/c):-Math.acos(t/c),h.scaleX=c,h.scaleY=o/c,h.skewX=(t*i+e*n)/o,h.skewY=0}else if(i!=0||n!=0){let c=Math.sqrt(i*i+n*n);h.rotation=Math.PI/2-(n>0?Math.acos(-i/c):-Math.acos(i/c)),h.scaleX=o/c,h.scaleY=c,h.skewX=0,h.skewY=(t*i+e*n)/o}return h.rotation=l._getRotation(h.rotation),h}},xe="[object Array]",Ee="[object Number]",ke="[object String]",Pe="[object Boolean]",Te=Math.PI/180,Re=180/Math.PI,z="#",Ae="",Le="0",De="Konva warning: ",Xt="Konva error: ",Ge="rgb(",Pt={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]},Ie=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,ot=[],j=null,Oe=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(r){setTimeout(r,16)},l={_isElement(r){return!!(r&&r.nodeType==1)},_isFunction(r){return!!(r&&r.constructor&&r.call&&r.apply)},_isPlainObject(r){return!!r&&r.constructor===Object},_isArray(r){return Object.prototype.toString.call(r)===xe},_isNumber(r){return Object.prototype.toString.call(r)===Ee&&!isNaN(r)&&isFinite(r)},_isString(r){return Object.prototype.toString.call(r)===ke},_isBoolean(r){return Object.prototype.toString.call(r)===Pe},isObject(r){return r instanceof Object},isValidSelector(r){if(typeof r!="string")return!1;let t=r[0];return t==="#"||t==="."||t===t.toUpperCase()},_sign(r){return r===0||r>0?1:-1},requestAnimFrame(r){ot.push(r),ot.length===1&&Oe(function(){let t=ot;ot=[],t.forEach(function(e){e()})})},createCanvasElement(){Ut();let r=document.createElement("canvas");try{r.style=r.style||{}}catch{}return r},createImageElement(){return Ut(),document.createElement("img")},_isInDocument(r){for(;r=r.parentNode;)if(r==document)return!0;return!1},_urlToImage(r,t){let e=l.createImageElement();e.onload=function(){t(e)},e.src=r},_rgbToHex(r,t,e){return((1<<24)+(r<<16)+(t<<8)+e).toString(16).slice(1)},_hexToRgb(r){r=r.replace(z,Ae);let t=parseInt(r,16);return{r:t>>16&255,g:t>>8&255,b:t&255}},getRandomColor(){let r=(Math.random()*16777215<<0).toString(16);for(;r.length<6;)r=Le+r;return z+r},isCanvasFarblingActive(){if(j!==null)return j;if(typeof document>"u")return j=!1,!1;let r=this.createCanvasElement();r.width=10,r.height=10;let t=r.getContext("2d",{willReadFrequently:!0});t.clearRect(0,0,10,10),t.fillStyle="#282828",t.fillRect(0,0,10,10);let e=t.getImageData(0,0,10,10).data,i=!1;for(let n=0;n<100;n++)if(e[n*4]!==40||e[n*4+1]!==40||e[n*4+2]!==40||e[n*4+3]!==255){i=!0;break}return j=i,this.releaseCanvas(r),j},getHitColor(){let r=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(r):r},getHitColorKey(r,t,e){return this.isCanvasFarblingActive()&&(r=Math.round(r/5)*5,t=Math.round(t/5)*5,e=Math.round(e/5)*5),z+this._rgbToHex(r,t,e)},getSnappedHexColor(r){let t=this._hexToRgb(r);return z+this._rgbToHex(Math.round(t.r/5)*5,Math.round(t.g/5)*5,Math.round(t.b/5)*5)},getRGB(r){let t;return r in Pt?(t=Pt[r],{r:t[0],g:t[1],b:t[2]}):r[0]===z?this._hexToRgb(r.substring(1)):r.substr(0,4)===Ge?(t=Ie.exec(r.replace(/ /g,"")),{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}):{r:0,g:0,b:0}},colorToRGBA(r){return r=r||"black",l._namedColorToRBA(r)||l._hex3ColorToRGBA(r)||l._hex4ColorToRGBA(r)||l._hex6ColorToRGBA(r)||l._hex8ColorToRGBA(r)||l._rgbColorToRGBA(r)||l._rgbaColorToRGBA(r)||l._hslColorToRGBA(r)},_namedColorToRBA(r){let t=Pt[r.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(r){if(r.indexOf("rgb(")===0){r=r.match(/rgb\(([^)]+)\)/)[1];let t=r.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(r){if(r.indexOf("rgba(")===0){r=r.match(/rgba\(([^)]+)\)/)[1];let t=r.split(/ *, */).map((e,i)=>e.slice(-1)==="%"?i===3?parseInt(e)/100:parseInt(e)/100*255:Number(e));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(r){if(r[0]==="#"&&r.length===9)return{r:parseInt(r.slice(1,3),16),g:parseInt(r.slice(3,5),16),b:parseInt(r.slice(5,7),16),a:parseInt(r.slice(7,9),16)/255}},_hex6ColorToRGBA(r){if(r[0]==="#"&&r.length===7)return{r:parseInt(r.slice(1,3),16),g:parseInt(r.slice(3,5),16),b:parseInt(r.slice(5,7),16),a:1}},_hex4ColorToRGBA(r){if(r[0]==="#"&&r.length===5)return{r:parseInt(r[1]+r[1],16),g:parseInt(r[2]+r[2],16),b:parseInt(r[3]+r[3],16),a:parseInt(r[4]+r[4],16)/255}},_hex3ColorToRGBA(r){if(r[0]==="#"&&r.length===4)return{r:parseInt(r[1]+r[1],16),g:parseInt(r[2]+r[2],16),b:parseInt(r[3]+r[3],16),a:1}},_hslColorToRGBA(r){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(r)){let[t,...e]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(r),i=Number(e[0])/360,n=Number(e[1])/100,s=Number(e[2])/100,a,o,h;if(n===0)return h=s*255,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};s<.5?a=s*(1+n):a=s+n-s*n;let c=2*s-a,d=[0,0,0];for(let g=0;g<3;g++)o=i+1/3*-(g-1),o<0&&o++,o>1&&o--,6*o<1?h=c+(a-c)*6*o:2*o<1?h=a:3*o<2?h=c+(a-c)*(2/3-o)*6:h=c,d[g]=h*255;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[2]),a:1}}},haveIntersection(r,t){return!(t.x>r.x+r.width||t.x+t.width<r.x||t.y>r.y+r.height||t.y+t.height<r.y)},cloneObject(r){let t={};for(let e in r)this._isPlainObject(r[e])?t[e]=this.cloneObject(r[e]):this._isArray(r[e])?t[e]=this.cloneArray(r[e]):t[e]=r[e];return t},cloneArray(r){return r.slice(0)},degToRad(r){return r*Te},radToDeg(r){return r*Re},_degToRad(r){return l.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),l.degToRad(r)},_radToDeg(r){return l.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),l.radToDeg(r)},_getRotation(r){return p.angleDeg?l.radToDeg(r):r},_capitalize(r){return r.charAt(0).toUpperCase()+r.slice(1)},throw(r){throw new Error(Xt+r)},error(r){console.error(Xt+r)},warn(r){p.showWarnings&&console.warn(De+r)},each(r,t){for(let e in r)t(e,r[e])},_inRange(r,t,e){return t<=r&&r<e},_getProjectionToSegment(r,t,e,i,n,s){let a,o,h,c=(r-e)*(r-e)+(t-i)*(t-i);if(c==0)a=r,o=t,h=(n-e)*(n-e)+(s-i)*(s-i);else{let d=((n-r)*(e-r)+(s-t)*(i-t))/c;d<0?(a=r,o=t,h=(r-n)*(r-n)+(t-s)*(t-s)):d>1?(a=e,o=i,h=(e-n)*(e-n)+(i-s)*(i-s)):(a=r+d*(e-r),o=t+d*(i-t),h=(a-n)*(a-n)+(o-s)*(o-s))}return[a,o,h]},_getProjectionToLine(r,t,e){let i=l.cloneObject(r),n=Number.MAX_VALUE;return t.forEach(function(s,a){if(!e&&a===t.length-1)return;let o=t[(a+1)%t.length],h=l._getProjectionToSegment(s.x,s.y,o.x,o.y,r.x,r.y),c=h[0],d=h[1],g=h[2];g<n&&(i.x=c,i.y=d,n=g)}),i},_prepareArrayForTween(r,t,e){let i=[],n=[];if(r.length>t.length){let a=t;t=r,r=a}for(let a=0;a<r.length;a+=2)i.push({x:r[a],y:r[a+1]});for(let a=0;a<t.length;a+=2)n.push({x:t[a],y:t[a+1]});let s=[];return n.forEach(function(a){let o=l._getProjectionToLine(a,i,e);s.push(o.x),s.push(o.y)}),s},_prepareToStringify(r){let t;r.visitedByCircularReferenceRemoval=!0;for(let e in r)if(r.hasOwnProperty(e)&&r[e]&&typeof r[e]=="object"){if(t=Object.getOwnPropertyDescriptor(r,e),r[e].visitedByCircularReferenceRemoval||l._isElement(r[e]))if(t.configurable)delete r[e];else return null;else if(l._prepareToStringify(r[e])===null)if(t.configurable)delete r[e];else return null}return delete r.visitedByCircularReferenceRemoval,r},_assign(r,t){for(let e in t)r[e]=t[e];return r},_getFirstPointerId(r){return r.touches?r.changedTouches[0].identifier:r.pointerId||999},releaseCanvas(...r){p.releaseCanvasOnDestroy&&r.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(r,t,e,i){let n=t<0?t:0,s=e<0?e:0;t=Math.abs(t),e=Math.abs(e);let a=0,o=0,h=0,c=0;typeof i=="number"?a=o=h=c=Math.min(i,t/2,e/2):(a=Math.min(i[0]||0,t/2,e/2),o=Math.min(i[1]||0,t/2,e/2),c=Math.min(i[2]||0,t/2,e/2),h=Math.min(i[3]||0,t/2,e/2)),r.moveTo(n+a,s),r.lineTo(n+t-o,s),r.arc(n+t-o,s+o,o,Math.PI*3/2,0,!1),r.lineTo(n+t,s+e-c),r.arc(n+t-c,s+e-c,c,0,Math.PI/2,!1),r.lineTo(n+h,s+e),r.arc(n+h,s+e-h,h,Math.PI/2,Math.PI,!1),r.lineTo(n,s+a),r.arc(n+a,s+a,a,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(r,t,e,i,n){i=Math.abs(i);for(let s=0;s<e;s++){let a=t[(s-1+e)%e],o=t[s],h=t[(s+1)%e],c={x:o.x-a.x,y:o.y-a.y},d={x:h.x-o.x,y:h.y-o.y},g=Math.hypot(c.x,c.y),m=Math.hypot(d.x,d.y),_;typeof n=="number"?_=n:_=s<n.length?n[s]:0,_=i*Math.cos(Math.PI/e)*Math.min(1,_/i*2);let x={x:c.x/g,y:c.y/g},E={x:d.x/m,y:d.y/m},w={x:o.x-x.x*_,y:o.y-x.y*_},G={x:o.x+E.x*_,y:o.y+E.y*_};s===0?r.moveTo(w.x,w.y):r.lineTo(w.x,w.y),r.arcTo(o.x,o.y,G.x,G.y,_)}}};var b={get isDragging(){let r=!1;return b._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(r=!0)}),r},justDragged:!1,get node(){let r;return b._dragElements.forEach(t=>{r=t.node}),r},_dragElements:new Map,_drag(r){let t=[];b._dragElements.forEach((e,i)=>{let{node:n}=e,s=n.getStage();s.setPointersPositions(r),e.pointerId===void 0&&(e.pointerId=l._getFirstPointerId(r));let a=s._changedPointerPositions.find(o=>o.id===e.pointerId);if(a){if(e.dragStatus!=="dragging"){let o=n.dragDistance();if(Math.max(Math.abs(a.x-e.startPointerPos.x),Math.abs(a.y-e.startPointerPos.y))<o||(n.startDrag({evt:r}),!n.isDragging()))return}n._setDragPosition(r,e),t.push(n)}}),t.forEach(e=>{e.getStage()&&e.fire("dragmove",{type:"dragmove",target:e,evt:r},!0)})},_endDragBefore(r){let t=[];b._dragElements.forEach(e=>{let{node:i}=e,n=i.getStage();if(r&&n.setPointersPositions(r),!n._changedPointerPositions.find(o=>o.id===e.pointerId))return;(e.dragStatus==="dragging"||e.dragStatus==="stopped")&&(b.justDragged=!0,p._mouseListenClick=!1,p._touchListenClick=!1,p._pointerListenClick=!1,e.dragStatus="stopped");let a=e.node.getLayer()||e.node instanceof p.Stage&&e.node;a&&t.indexOf(a)===-1&&t.push(a)}),t.forEach(e=>{e.draw()})},_endDragAfter(r){b._dragElements.forEach((t,e)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:r},!0),t.dragStatus!=="dragging"&&b._dragElements.delete(e)})}};p.isBrowser&&(window.addEventListener("mouseup",b._endDragBefore,!0),window.addEventListener("touchend",b._endDragBefore,!0),window.addEventListener("touchcancel",b._endDragBefore,!0),window.addEventListener("mousemove",b._drag),window.addEventListener("touchmove",b._drag),window.addEventListener("mouseup",b._endDragAfter,!1),window.addEventListener("touchend",b._endDragAfter,!1),window.addEventListener("touchcancel",b._endDragAfter,!1));p.DD=b;function F(r){return l._isString(r)?'"'+r+'"':Object.prototype.toString.call(r)==="[object Number]"||l._isBoolean(r)?r:Object.prototype.toString.call(r)}function C(){if(p.isUnminified)return function(r,t){return l._isNumber(r)||l.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),r}}function Vt(r){if(p.isUnminified)return function(t,e){let i=l._isNumber(t),n=l._isArray(t)&&t.length==r;return!i&&!n&&l.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or Array<number>('+r+")"),t}}function Wt(){if(p.isUnminified)return function(r,t){return l._isNumber(r)||r==="auto"||l.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),r}}function M(){if(p.isUnminified)return function(r,t){return l._isString(r)||l.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),r}}function Tt(){if(p.isUnminified)return function(r,t){let e=l._isString(r),i=Object.prototype.toString.call(r)==="[object CanvasGradient]"||r&&r.addColorStop;return e||i||l.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),r}}function R(){if(p.isUnminified)return function(r,t){return r===!0||r===!1||l.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),r}}function Kt(r){if(p.isUnminified)return function(t,e){return t==null||l.isObject(t)||l.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+r),t}}var q="get",$="set",u={addGetterSetter(r,t,e,i,n){u.addGetter(r,t,e),u.addSetter(r,t,i,n),u.addOverloadedGetterSetter(r,t)},addGetter(r,t,e){let i=q+l._capitalize(t);r.prototype[i]=r.prototype[i]||function(){let n=this.attrs[t];return n===void 0?e:n}},addSetter(r,t,e,i){let n=$+l._capitalize(t);r.prototype[n]||u.overWriteSetter(r,t,e,i)},overWriteSetter(r,t,e,i){let n=$+l._capitalize(t);r.prototype[n]=function(s){return e&&s!==void 0&&s!==null&&(s=e.call(this,s,t)),this._setAttr(t,s),i&&i.call(this),this}},addComponentsGetterSetter(r,t,e,i,n){let s=e.length,a=l._capitalize,o=q+a(t),h=$+a(t);r.prototype[o]=function(){let d={};for(let g=0;g<s;g++){let m=e[g];d[m]=this.getAttr(t+a(m))}return d};let c=Kt(e);r.prototype[h]=function(d){let g=this.attrs[t];i&&(d=i.call(this,d,t)),c&&c.call(this,d,t);for(let m in d)d.hasOwnProperty(m)&&this._setAttr(t+a(m),d[m]);return d||e.forEach(m=>{this._setAttr(t+a(m),void 0)}),this._fireChangeEvent(t,g,d),n&&n.call(this),this},u.addOverloadedGetterSetter(r,t)},addOverloadedGetterSetter(r,t){let e=l._capitalize(t),i=$+e,n=q+e;r.prototype[t]=function(){return arguments.length?(this[i](arguments[0]),this):this[n]()}},addDeprecatedGetterSetter(r,t,e,i){l.error("Adding deprecated "+t);let n=q+l._capitalize(t),s=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";r.prototype[n]=function(){l.error(s);let a=this.attrs[t];return a===void 0?e:a},u.addSetter(r,t,i,function(){l.error(s)}),u.addOverloadedGetterSetter(r,t)},backCompat(r,t){l.each(t,function(e,i){let n=r.prototype[i],s=q+l._capitalize(e),a=$+l._capitalize(e);function o(){n.apply(this,arguments),l.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}r.prototype[e]=o,r.prototype[s]=o,r.prototype[a]=o})},afterSetFilter(){this._filterUpToDate=!1}};function Me(r){let t=[],e=r.length,i=l;for(let n=0;n<e;n++){let s=r[n];i._isNumber(s)?s=Math.round(s*1e3)/1e3:i._isString(s)||(s=s+""),t.push(s)}return t}var zt=",",Ne="(",He=")",Fe="([",Be="])",Ye=";",Ue="()",Xe="=",jt=["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"],Ve=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],We=100,ht=null;function Rt(){if(ht!==null)return ht;try{let t=l.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(ht=!1,!1)}catch{return ht=!1,!1}}var J=class{constructor(t){this.canvas=t,p.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i=this.traceArr,n=i.length,s="",a,o,h,c;for(a=0;a<n;a++)o=i[a],h=o.method,h?(c=o.args,s+=h,t?s+=Ue:l._isArray(c[0])?s+=Fe+c.join(zt)+Be:(e&&(c=c.map(d=>typeof d=="number"?Math.floor(d):d)),s+=Ne+c.join(zt)+He)):(s+=o.property,t||(s+=Xe+o.val)),s+=Ye;return s}clearTrace(){this.traceArr=[]}_trace(t){let e=this.traceArr,i;e.push(t),i=e.length,i>=We&&e.shift()}reset(){let t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){let 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){let e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){let e=t.getAbsoluteOpacity();e!==1&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){let e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){let e=t.attrs.miterLimit;e!=null&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,n,s,a){this._context.arc(t,e,i,n,s,a)}arcTo(t,e,i,n,s){this._context.arcTo(t,e,i,n,s)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,n,s,a){this._context.bezierCurveTo(t,e,i,n,s,a)}clearRect(t,e,i,n){this._context.clearRect(t,e,i,n)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){let i=arguments;if(i.length===2)return this._context.createImageData(t,e);if(i.length===1)return this._context.createImageData(t)}createLinearGradient(t,e,i,n){return this._context.createLinearGradient(t,e,i,n)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,n,s,a){return this._context.createRadialGradient(t,e,i,n,s,a)}drawImage(t,e,i,n,s,a,o,h,c){let d=arguments,g=this._context;d.length===3?g.drawImage(t,e,i):d.length===5?g.drawImage(t,e,i,n,s):d.length===9&&g.drawImage(t,e,i,n,s,a,o,h,c)}ellipse(t,e,i,n,s,a,o,h){this._context.ellipse(t,e,i,n,s,a,o,h)}isPointInPath(t,e,i,n){return i?this._context.isPointInPath(i,t,e,n):this._context.isPointInPath(t,e,n)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,n){this._context.fillRect(t,e,i,n)}strokeRect(t,e,i,n){this._context.strokeRect(t,e,i,n)}fillText(t,e,i,n){n?this._context.fillText(t,e,i,n):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,n){return this._context.getImageData(t,e,i,n)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,n){this._context.rect(t,e,i,n)}roundRect(t,e,i,n,s){this._context.roundRect(t,e,i,n,s)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,n){this._context.quadraticCurveTo(t,e,i,n)}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,n,s,a){this._context.setTransform(t,e,i,n,s,a)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,n){this._context.strokeText(t,e,i,n)}transform(t,e,i,n,s,a){this._context.transform(t,e,i,n,s,a)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t=this,e=jt.length,i=this.setAttr,n,s,a=function(o){let h=t[o],c;t[o]=function(){return s=Me(Array.prototype.slice.call(arguments,0)),c=h.apply(t,arguments),t._trace({method:o,args:s}),c}};for(n=0;n<e;n++)a(jt[n]);t.setAttr=function(){i.apply(t,arguments);let o=arguments[0],h=arguments[1];(o==="shadowOffsetX"||o==="shadowOffsetY"||o==="shadowBlur")&&(h=h/this.canvas.getPixelRatio()),t._trace({property:o,val:h})}}_applyGlobalCompositeOperation(t){let e=t.attrs.globalCompositeOperation;!e||e==="source-over"||this.setAttr("globalCompositeOperation",e)}};Ve.forEach(function(r){Object.defineProperty(J.prototype,r,{get(){return this._context[r]},set(t){this._context[r]=t}})});var lt=class extends J{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){let e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){let e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){let e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){let e=t.fill(),i=t.getFillPriority();if(e&&i==="color"){this._fillColor(t);return}let n=t.getFillPatternImage();if(n&&i==="pattern"){this._fillPattern(t);return}let s=t.getFillLinearGradientColorStops();if(s&&i==="linear-gradient"){this._fillLinearGradient(t);return}let a=t.getFillRadialGradientColorStops();if(a&&i==="radial-gradient"){this._fillRadialGradient(t);return}e?this._fillColor(t):n?this._fillPattern(t):s?this._fillLinearGradient(t):a&&this._fillRadialGradient(t)}_strokeLinearGradient(t){let e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),n=t.getStrokeLinearGradientColorStops(),s=this.createLinearGradient(e.x,e.y,i.x,i.y);if(n){for(let a=0;a<n.length;a+=2)s.addColorStop(n[a],n[a+1]);this.setAttr("strokeStyle",s)}}_stroke(t){let e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();let s=this.getCanvas().getPixelRatio();this.setTransform(s,0,0,s,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,n;let s=(e=t.getShadowRGBA())!==null&&e!==void 0?e:"black",a=(i=t.getShadowBlur())!==null&&i!==void 0?i:5,o=(n=t.getShadowOffset())!==null&&n!==void 0?n:{x:0,y:0},h=t.getAbsoluteScale(),c=this.canvas.getPixelRatio(),d=h.x*c,g=h.y*c;this.setAttr("shadowColor",s),this.setAttr("shadowBlur",a*Math.min(Math.abs(d),Math.abs(g))),this.setAttr("shadowOffsetX",o.x*d),this.setAttr("shadowOffsetY",o.y*g)}},ct=class extends J{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()){let e=t.getStrokeScaleEnabled();if(!e){this.save();let s=this.getCanvas().getPixelRatio();this.setTransform(s,0,0,s,0,0)}this._applyLineCap(t);let i=t.hitStrokeWidth(),n=i==="auto"?t.strokeWidth():i;this.setAttr("lineWidth",n),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}};var dt;function Ke(){if(dt)return dt;let r=l.createCanvasElement(),t=r.getContext("2d");return dt=(function(){let e=p._global.devicePixelRatio||1,i=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/i})(),l.releaseCanvas(r),dt}var ut=class{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;let i=(t||{}).pixelRatio||p.pixelRatio||Ke();this.pixelRatio=i,this._canvas=l.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){let 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";let 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";let e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch{try{return this._canvas.toDataURL()}catch(n){return l.error("Unable to get data URL. "+n.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},T=class extends ut{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new lt(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}},N=class extends ut{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new ct(this),this.setSize(t.width,t.height)}};function ze(r){let t=/(\w+)\(([^)]+)\)/g,e;for(;(e=t.exec(r))!==null;){let[,i,n]=e;switch(i){case"blur":{let s=parseFloat(n.replace("px",""));return function(a){this.blurRadius(s*.5);let o=p.Filters;o&&o.Blur&&o.Blur.call(this,a)}}case"brightness":{let s=n.includes("%")?parseFloat(n)/100:parseFloat(n);return function(a){this.brightness(s);let o=p.Filters;o&&o.Brightness&&o.Brightness.call(this,a)}}case"contrast":{let s=parseFloat(n);return function(a){let o=100*(Math.sqrt(s)-1);this.contrast(o);let h=p.Filters;h&&h.Contrast&&h.Contrast.call(this,a)}}case"grayscale":return function(s){let a=p.Filters;a&&a.Grayscale&&a.Grayscale.call(this,s)};case"sepia":return function(s){let a=p.Filters;a&&a.Sepia&&a.Sepia.call(this,s)};case"invert":return function(s){let a=p.Filters;a&&a.Invert&&a.Invert.call(this,s)};default:l.warn(`CSS filter "${i}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var ft="absoluteOpacity",qt="allEventListeners",D="absoluteTransform",$t="absoluteScale",B="canvas",je="Change",qe="children",$e="konva",At="listening",Je="mouseenter",Ze="mouseleave",Qe="pointerenter",ti="pointerleave",ei="touchenter",ii="touchleave";var Jt="set",Zt="Shape",gt=" ",Qt="stage",H="transform",ni="Stage",Lt="visible",ri=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(gt),si=1,y=class r{constructor(t){this._id=si++,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===H||t===D)&&this._cache.get(t)?this._cache.get(t).dirty=!0:t?this._cache.delete(t):this._cache.clear()}_getCache(t,e){let i=this._cache.get(t);return(i===void 0||(t===H||t===D)&&i.dirty===!0)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){let n=e.map(s=>s+"Change.konva").join(gt);this.on(n,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(B)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===D&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(B)){let{scene:t,filter:e,hit:i}=this._cache.get(B);l.releaseCanvas(t._canvas,e._canvas,i._canvas),this._cache.delete(B)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){let e=t||{},i={};(e.x===void 0||e.y===void 0||e.width===void 0||e.height===void 0)&&(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let n=Math.ceil(e.width||i.width),s=Math.ceil(e.height||i.height),a=e.pixelRatio,o=e.x===void 0?Math.floor(i.x):e.x,h=e.y===void 0?Math.floor(i.y):e.y,c=e.offset||0,d=e.drawBorder||!1,g=e.hitCanvasPixelRatio||1;if(!n||!s){l.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}let m=Math.abs(Math.round(i.x)-o)>.5?1:0,_=Math.abs(Math.round(i.y)-h)>.5?1:0;n+=c*2+m,s+=c*2+_,o-=c,h-=c;let v=new T({pixelRatio:a,width:n,height:s}),x=new T({pixelRatio:a,width:0,height:0,willReadFrequently:!0}),E=new N({pixelRatio:g,width:n,height:s}),w=v.getContext(),G=E.getContext(),I=new T({width:v.width/v.pixelRatio+Math.abs(o),height:v.height/v.pixelRatio+Math.abs(h),pixelRatio:v.pixelRatio}),Yt=I.getContext();return E.isCache=!0,v.isCache=!0,this._cache.delete(B),this._filterUpToDate=!1,e.imageSmoothingEnabled===!1&&(v.getContext()._context.imageSmoothingEnabled=!1,x.getContext()._context.imageSmoothingEnabled=!1),w.save(),G.save(),Yt.save(),w.translate(-o,-h),G.translate(-o,-h),Yt.translate(-o,-h),I.x=o,I.y=h,this._isUnderCache=!0,this._clearSelfAndDescendantCache(ft),this._clearSelfAndDescendantCache($t),this.drawScene(v,this,I),this.drawHit(E,this),this._isUnderCache=!1,w.restore(),G.restore(),d&&(w.save(),w.beginPath(),w.rect(0,0,n,s),w.closePath(),w.setAttr("strokeStyle","red"),w.setAttr("lineWidth",5),w.stroke(),w.restore()),l.releaseCanvas(I._canvas),this._cache.set(B,{scene:v,filter:x,hit:E,x:o,y:h}),this._requestDraw(),this}isCached(){return this._cache.has(B)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){let 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}],n=1/0,s=1/0,a=-1/0,o=-1/0,h=this.getAbsoluteTransform(e);return i.forEach(function(c){let d=h.point(c);n===void 0&&(n=a=d.x,s=o=d.y),n=Math.min(n,d.x),s=Math.min(s,d.y),a=Math.max(a,d.x),o=Math.max(o,d.y)}),{x:n,y:s,width:a-n,height:o-s}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);let e=this._getCanvasCache();t.translate(e.x,e.y);let i=this._getCachedSceneCanvas(),n=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/n,i.height/n),t.restore()}_drawCachedHitCanvas(t){let e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t=this.filters(),e=this._getCanvasCache(),i=e.scene,n=e.filter,s=n.getContext(),a,o,h,c;if(!t||t.length===0)return i;if(this._filterUpToDate)return n;let d=!0;for(let m=0;m<t.length;m++){let _=typeof t[m]=="string"&&!Rt();if(typeof t[m]!="string"||!Rt()){d=!1;break}}let g=i.pixelRatio;if(n.setSize(i.width/i.pixelRatio,i.height/i.pixelRatio),d){let m=t.join(" ");return s.save(),s.setAttr("filter",m),s.drawImage(i._canvas,0,0,i.getWidth()/g,i.getHeight()/g),s.restore(),this._filterUpToDate=!0,n}try{for(a=t.length,s.clear(),s.drawImage(i._canvas,0,0,i.getWidth()/g,i.getHeight()/g),o=s.getImageData(0,0,n.getWidth(),n.getHeight()),h=0;h<a;h++)c=t[h],typeof c=="string"&&(c=ze(c)),c.call(this,o),s.putImageData(o,0,0)}catch(m){l.error("Unable to apply filter. "+m.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,n}on(...t){let e=t[0],i=t[1],n=t[2];if(this._cache&&this._cache.delete(qt),t.length===3)return this._delegate.apply(this,t);let s=e.split(gt);for(let a=0;a<s.length;a++){let h=s[a].split("."),c=h[0],d=h[1]||"";this.eventListeners[c]||(this.eventListeners[c]=[]),this.eventListeners[c].push({name:d,handler:i})}return this}off(t,e){let i=(t||"").split(gt),n=i.length,s,a,o,h,c,d;if(this._cache&&this._cache.delete(qt),!t)for(a in this.eventListeners)this._off(a);for(s=0;s<n;s++)if(o=i[s],h=o.split("."),c=h[0],d=h[1],c)this.eventListeners[c]&&this._off(c,d,e);else for(a in this.eventListeners)this._off(a,d,e);return this}dispatchEvent(t){let e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(i){e.call(this,i.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){let n=this;return this.on(t,function(s){let a=s.target.findAncestors(e,!0,n);for(let o=0;o<a.length;o++)s=l.cloneObject(s),s.currentTarget=a[o],i.call(a[o],s)}),this}remove(){return this.isDragging()&&this.stopDrag(),b._dragElements.delete(this._id),b._dragElements.forEach((t,e)=>{this.isAncestorOf(t.node)&&b._dragElements.delete(e)}),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(D),this._clearSelfAndDescendantCache(ft),this._clearSelfAndDescendantCache($t),this._clearSelfAndDescendantCache(Qt),this._clearSelfAndDescendantCache(Lt),this._clearSelfAndDescendantCache(At)}_remove(){this._clearCaches();let 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){let e="get"+l._capitalize(t);return l._isFunction(this[e])?this[e]():this.attrs[t]}getAncestors(){let t=this.getParent(),e=[];for(;t;)e.push(t),t=t.getParent();return e}getAttrs(){return this.attrs||{}}setAttrs(t){return this._batchTransformChanges(()=>{let e,i;if(!t)return this;for(e in t)e!==qe&&(i=Jt+l._capitalize(e),l._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(At,this._isListening)}_isListening(t){if(!this.listening())return!1;let i=this.getParent();return i&&i!==t&&this!==t?i._isListening(t):!0}isVisible(){return this._getCache(Lt,this._isVisible)}_isVisible(t){if(!this.visible())return!1;let i=this.getParent();return i&&i!==t&&this!==t?i._isVisible(t):!0}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);let i=this.getLayer(),n=!1;b._dragElements.forEach(a=>{a.dragStatus==="dragging"&&(a.node.nodeType==="Stage"||a.node.getLayer()===i)&&(n=!0)});let s=!e&&!p.hitOnDragEnabled&&(n||p.isTransforming());return this.isListening()&&this.isVisible()&&!s}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t=this.getDepth(),e=this,i=0,n,s,a,o;function h(d){for(n=[],s=d.length,a=0;a<s;a++)o=d[a],i++,o.nodeType!==Zt&&(n=n.concat(o.getChildren().slice())),o._id===e._id&&(a=s);n.length>0&&n[0].getDepth()<=t&&h(n)}let c=this.getStage();return e.nodeType!==ni&&c&&h(c.getChildren()),i}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(H),this._clearSelfAndDescendantCache(D)),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(){let t=this.getStage();if(!t)return null;let e=t.getPointerPosition();if(!e)return null;let 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);let n=this.getAbsoluteTransform(t).getMatrix(),s=new L,a=this.offset();return s.m=n.slice(),s.translate(a.x,a.y),s.getTranslation()}setAbsolutePosition(t){let{x:e,y:i,...n}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(H);let s=this._getAbsoluteTransform().copy();return s.invert(),s.translate(t.x,t.y),t={x:this.attrs.x+s.getTranslation().x,y:this.attrs.y+s.getTranslation().y},this._setTransform(n),this.setPosition({x:t.x,y:t.y}),this._clearCache(H),this._clearSelfAndDescendantCache(D),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){let 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,n=this.x(),s=this.y();return e!==void 0&&(n+=e),i!==void 0&&(s+=i),this.setPosition({x:n,y:s}),this}_eachAncestorReverse(t,e){let i=[],n=this.getParent(),s,a;if(!(e&&e._id===this._id)){for(i.unshift(this);n&&(!e||n._id!==e._id);)i.unshift(n),n=n.parent;for(s=i.length,a=0;a<s;a++)t(i[a])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return l.warn("Node has no parent. moveToTop function is ignored."),!1;let t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0):!1}moveUp(){if(!this.parent)return l.warn("Node has no parent. moveUp function is ignored."),!1;let t=this.index,e=this.parent.getChildren().length;return t<e-1?(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0):!1}moveDown(){if(!this.parent)return l.warn("Node has no parent. moveDown function is ignored."),!1;let t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return l.warn("Node has no parent. moveToBottom function is ignored."),!1;let t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(t){if(!this.parent)return l.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&l.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)+".");let 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(ft,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t=this.getAttrs(),e,i,n,s,a,o={attrs:{},className:this.getClassName()};for(e in t)i=t[e],a=l.isObject(i)&&!l._isPlainObject(i)&&!l._isArray(i),!a&&(n=typeof this[e]=="function"&&this[e],delete t[e],s=n?n.call(this):null,t[e]=i,s!==i&&(o.attrs[e]=i));return l._prepareToStringify(o)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){let n=[];e&&this._isMatch(t)&&n.push(this);let s=this.parent;for(;s;){if(s===i)return n;s._isMatch(t)&&n.push(s),s=s.parent}return n}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if(typeof t=="function")return t(this);let e=t.replace(/ /g,"").split(","),i=e.length,n,s;for(n=0;n<i;n++)if(s=e[n],l.isValidSelector(s)||(l.warn('Selector "'+s+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),l.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),l.warn("Konva is awesome, right?")),s.charAt(0)==="#"){if(this.id()===s.slice(1))return!0}else if(s.charAt(0)==="."){if(this.hasName(s.slice(1)))return!0}else if(this.className===s||this.nodeType===s)return!0;return!1}getLayer(){let t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(Qt,this._getStage)}_getStage(){let 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(D,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new L,this._eachAncestorReverse(function(i){let n=i.transformsEnabled();n==="all"?e.multiply(i.getTransform()):n==="position"&&e.translate(i.x()-i.offsetX(),i.y()-i.offsetY())},t),e;{e=this._cache.get(D)||new L,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();let i=this.transformsEnabled();if(i==="all")e.multiply(this.getTransform());else if(i==="position"){let n=this.attrs.x||0,s=this.attrs.y||0,a=this.attrs.offsetX||0,o=this.attrs.offsetY||0;e.translate(n-a,s-o)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();let n=this.getAbsoluteTransform(t).decompose();return{x:n.scaleX,y:n.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(H,this._getTransform)}_getTransform(){var t,e;let i=this._cache.get(H)||new L;i.reset();let n=this.x(),s=this.y(),a=p.getAngle(this.rotation()),o=(t=this.attrs.scaleX)!==null&&t!==void 0?t:1,h=(e=this.attrs.scaleY)!==null&&e!==void 0?e:1,c=this.attrs.skewX||0,d=this.attrs.skewY||0,g=this.attrs.offsetX||0,m=this.attrs.offsetY||0;return(n!==0||s!==0)&&i.translate(n,s),a!==0&&i.rotate(a),(c!==0||d!==0)&&i.skew(c,d),(o!==1||h!==1)&&i.scale(o,h),(g!==0||m!==0)&&i.translate(-1*g,-1*m),i.dirty=!1,i}clone(t){let e=l.cloneObject(this.attrs),i,n,s,a,o;for(i in t)e[i]=t[i];let h=new this.constructor(e);for(i in this.eventListeners)for(n=this.eventListeners[i],s=n.length,a=0;a<s;a++)o=n[a],o.name.indexOf($e)<0&&(h.eventListeners[i]||(h.eventListeners[i]=[]),h.eventListeners[i].push(o));return h}_toKonvaCanvas(t){t=t||{};let e=this.getClientRect(),i=this.getStage(),n=t.x!==void 0?t.x:Math.floor(e.x),s=t.y!==void 0?t.y:Math.floor(e.y),a=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:a}),h=o.getContext(),c=new T({width:o.width/o.pixelRatio+Math.abs(n),height:o.height/o.pixelRatio+Math.abs(s),pixelRatio:o.pixelRatio});return t.imageSmoothingEnabled===!1&&(h._context.imageSmoothingEnabled=!1),h.save(),(n||s)&&h.translate(-1*n,-1*s),this.drawScene(o,void 0,c),h.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){t=t||{};let e=t.mimeType||null,i=t.quality||null,n=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(n),n}toImage(t){return new Promise((e,i)=>{try{let n=t?.callback;n&&delete t.callback,l._urlToImage(this.toDataURL(t),function(s){e(s),n?.(s)})}catch(n){i(n)}})}toBlob(t){return new Promise((e,i)=>{try{let n=t?.callback;n&&delete t.callback,this.toCanvas(t).toBlob(s=>{e(s),n?.(s)},t?.mimeType,t?.quality)}catch(n){i(n)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance!==void 0?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():p.dragDistance}_off(t,e,i){let n=this.eventListeners[t],s,a,o;for(s=0;s<n.length;s++)if(a=n[s].name,o=n[s].handler,(a!=="konva"||e==="konva")&&(!e||a===e)&&(!i||i===o)){if(n.splice(s,1),n.length===0){delete this.eventListeners[t];break}s--}}_fireChangeEvent(t,e,i){this._fire(t+je,{oldVal:e,newVal:i})}addName(t){if(!this.hasName(t)){let e=this.name(),i=e?e+" "+t:t;this.name(i)}return this}hasName(t){if(!t)return!1;let e=this.name();return e?(e||"").split(/\s/g).indexOf(t)!==-1:!1}removeName(t){let e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return i!==-1&&(e.splice(i,1),this.name(e.join(" "))),this}setAttr(t,e){let i=this[Jt+l._capitalize(t)];return l._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(p.autoDrawEnabled){let t=this.getLayer()||this.getStage();t?.batchDraw()}}_setAttr(t,e){let i=this.attrs[t];i===e&&!l.isObject(e)||(e==null?delete this.attrs[t]:this.attrs[t]=e,this._shouldFireChangeEvents&&this._fireChangeEvent(t,i,e),this._requestDraw())}_setComponentAttr(t,e,i){let n;i!==void 0&&(n=this.attrs[t],n||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,n,i))}_fireAndBubble(t,e,i){e&&this.nodeType===Zt&&(e.target=this);let n=[Je,Ze,Qe,ti,ei,ii];if(!(n.indexOf(t)!==-1&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||this.nodeType==="Stage"&&!i))){this._fire(t,e);let a=n.indexOf(t)!==-1&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!a&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i;let{nodeType:n}=this,s=r.protoListenerMap.get(n)||{},a=s?.[t];if(a===void 0){a=[];let o=Object.getPrototypeOf(this);for(;o;){let h=(i=(e=o.eventListeners)===null||e===void 0?void 0:e[t])!==null&&i!==void 0?i:[];a.push(...h),o=Object.getPrototypeOf(o)}s[t]=a,r.protoListenerMap.set(n,s)}return a}_fire(t,e){e=e||{},e.currentTarget=this,e.type=t;let i=this._getProtoListeners(t);if(i)for(let s=0;s<i.length;s++)i[s].handler.call(this,e);let n=this.eventListeners[t];if(n)for(let s=0;s<n.length;s++)n[s].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){let e=t?t.pointerId:void 0,i=this.getStage(),n=this.getAbsolutePosition();if(!i)return;let s=i._getPointerById(e)||i._changedPointerPositions[0]||n;b._dragElements.set(this._id,{node:this,startPointerPos:s,offset:{x:s.x-n.x,y:s.y-n.y},dragStatus:"ready",pointerId:e,startEvent:t})}startDrag(t,e=!0){b._dragElements.has(this._id)||this._createDragElement(t);let i=b._dragElements.get(this._id);i.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:i.startEvent&&i.startEvent.evt||t&&t.evt},e)}_setDragPosition(t,e){let i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let n={x:i.x-e.offset.x,y:i.y-e.offset.y},s=this.dragBoundFunc();if(s!==void 0){let a=s.call(this,n,t);a?n=a:l.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==n.x||this._lastPos.y!==n.y)&&(this.setAbsolutePosition(n),this._requestDraw()),this._lastPos=n}stopDrag(t){let e=b._dragElements.get(this._id);e&&(e.dragStatus="stopped"),b._endDragBefore(t),b._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){let t=b._dragElements.get(this._id);return t?t.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(t.evt.button!==void 0)||p.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let n=!1;b._dragElements.forEach(s=>{this.isAncestorOf(s.node)&&(n=!0)}),n||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;let e=b._dragElements.get(this._id),i=e&&e.dragStatus==="dragging",n=e&&e.dragStatus==="ready";i?this.stopDrag():n&&b._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){let e=this.getStage();if(!e)return!1;let i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return l.haveIntersection(i,this.getClientRect())}static create(t,e){return l._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let i=r.prototype.getClassName.call(t),n=t.children,s,a,o;e&&(t.attrs.container=e),p[i]||(l.warn('Can not find a node with class name "'+i+'". Fallback to "Shape".'),i="Shape");let h=p[i];if(s=new h(t.attrs),n)for(a=n.length,o=0;o<a;o++)s.add(r._createNode(n[o]));return s}};y.protoListenerMap=new Map;y.prototype.nodeType="Node";y.prototype._attrsAffectingSize=[];y.prototype.eventListeners={};y.prototype.on(ri,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(H),this._clearSelfAndDescendantCache(D)});y.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(Lt)});y.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(At)});y.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache(ft)});var S=u.addGetterSetter;S(y,"zIndex");S(y,"absolutePosition");S(y,"position");S(y,"x",0,C());S(y,"y",0,C());S(y,"globalCompositeOperation","source-over",M());S(y,"opacity",1,C());S(y,"name","",M());S(y,"id","",M());S(y,"rotation",0,C());u.addComponentsGetterSetter(y,"scale",["x","y"]);S(y,"scaleX",1,C());S(y,"scaleY",1,C());u.addComponentsGetterSetter(y,"skew",["x","y"]);S(y,"skewX",0,C());S(y,"skewY",0,C());u.addComponentsGetterSetter(y,"offset",["x","y"]);S(y,"offsetX",0,C());S(y,"offsetY",0,C());S(y,"dragDistance",void 0,C());S(y,"width",0,C());S(y,"height",0,C());S(y,"listening",!0,R());S(y,"preventDefault",!0,R());S(y,"filters",void 0,function(r){return this._filterUpToDate=!1,r});S(y,"visible",!0,R());S(y,"transformsEnabled","all",M());S(y,"size");S(y,"dragBoundFunc");S(y,"draggable",!1,R());u.backCompat(y,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var P=class extends y{constructor(){super(...arguments),this.children=[]}getChildren(t){let e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(t.length===0)return this;if(t.length>1){for(let i=0;i<t.length;i++)this.add(t[i]);return this}let 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){let e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){let i=[];return this._descendants(n=>{let s=n._isMatch(t);return s&&i.push(n),!!(s&&e)}),i}_descendants(t){let e=!1,i=this.getChildren();for(let n of i){if(e=t(n),e)return!0;if(n.hasChildren()&&(e=n._descendants(t),e))return!0}return!1}toObject(){let t=y.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){let e=y.prototype.clone.call(this,t);return this.getChildren().forEach(function(i){e.add(i.clone())}),e}getAllIntersections(t){let e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),!this.isCached()&&((e=this.children)===null||e===void 0||e.forEach(function(i){i._clearSelfAndDescendantCache(t)}))}_setChildrenIndices(){var t;(t=this.children)===null||t===void 0||t.forEach(function(e,i){e.index=i}),this._requestDraw()}drawScene(t,e,i){let n=this.getLayer(),s=t||n&&n.getCanvas(),a=s&&s.getContext(),o=this._getCanvasCache(),h=o&&o.scene,c=s&&s.isCache;if(!this.isVisible()&&!c)return this;if(h){a.save();let d=this.getAbsoluteTransform(e).getMatrix();a.transform(d[0],d[1],d[2],d[3],d[4],d[5]),this._drawCachedSceneCanvas(a),a.restore()}else this._drawChildren("drawScene",s,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;let i=this.getLayer(),n=t||i&&i.hitCanvas,s=n&&n.getContext(),a=this._getCanvasCache();if(a&&a.hit){s.save();let h=this.getAbsoluteTransform(e).getMatrix();s.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedHitCanvas(s),s.restore()}else this._drawChildren("drawHit",n,e);return this}_drawChildren(t,e,i,n){var s;let a=e&&e.getContext(),o=this.clipWidth(),h=this.clipHeight(),c=this.clipFunc(),d=typeof o=="number"&&typeof h=="number"||c,g=i===this;if(d){a.save();let _=this.getAbsoluteTransform(i),v=_.getMatrix();a.transform(v[0],v[1],v[2],v[3],v[4],v[5]),a.beginPath();let x;if(c)x=c.call(this,a,this);else{let E=this.clipX(),w=this.clipY();a.rect(E||0,w||0,o,h)}a.clip.apply(a,x),v=_.copy().invert().getMatrix(),a.transform(v[0],v[1],v[2],v[3],v[4],v[5])}let m=!g&&this.globalCompositeOperation()!=="source-over"&&t==="drawScene";m&&(a.save(),a._applyGlobalCompositeOperation(this)),(s=this.children)===null||s===void 0||s.forEach(function(_){_[t](e,i,n)}),m&&a.restore(),d&&a.restore()}getClientRect(t={}){var e;let i=t.skipTransform,n=t.relativeTo,s,a,o,h,c={x:1/0,y:1/0,width:0,height:0},d=this;(e=this.children)===null||e===void 0||e.forEach(function(_){if(!_.visible())return;let v=_.getClientRect({relativeTo:d,skipShadow:t.skipShadow,skipStroke:t.skipStroke});v.width===0&&v.height===0||(s===void 0?(s=v.x,a=v.y,o=v.x+v.width,h=v.y+v.height):(s=Math.min(s,v.x),a=Math.min(a,v.y),o=Math.max(o,v.x+v.width),h=Math.max(h,v.y+v.height)))});let g=this.find("Shape"),m=!1;for(let _=0;_<g.length;_++)if(g[_]._isVisible(this)){m=!0;break}return m&&s!==void 0?c={x:s,y:a,width:o-s,height:h-a}:c={x:0,y:0,width:0,height:0},i?c:this._transformedRect(c,n)}};u.addComponentsGetterSetter(P,"clip",["x","y","width","height"]);u.addGetterSetter(P,"clipX",void 0,C());u.addGetterSetter(P,"clipY",void 0,C());u.addGetterSetter(P,"clipWidth",void 0,C());u.addGetterSetter(P,"clipHeight",void 0,C());u.addGetterSetter(P,"clipFunc");var Z=new Map,te=p._global.PointerEvent!==void 0;function pt(r){return Z.get(r)}function mt(r){return{evt:r,pointerId:r.pointerId}}function _t(r,t){return Z.get(r)===t}function vt(r,t){Y(r),t.getStage()&&(Z.set(r,t),te&&t._fire("gotpointercapture",mt(new PointerEvent("gotpointercapture"))))}function Y(r,t){let e=Z.get(r);if(!e)return;let i=e.getStage();i&&i.content,Z.delete(r),te&&e._fire("lostpointercapture",mt(new PointerEvent("lostpointercapture")))}var ai="Stage",oi="string",ie="px",hi="mouseout",re="mouseleave",se="mouseover",ae="mouseenter",oe="mousemove",he="mousedown",le="mouseup",Q="pointermove",tt="pointerdown",V="pointerup",et="pointercancel",li="lostpointercapture",yt="pointerout",it="pointerleave",Ct="pointerover",bt="pointerenter",Gt="contextmenu",ce="touchstart",de="touchend",ue="touchmove",fe="touchcancel",It="wheel",ci=5,di=[[ae,"_pointerenter"],[he,"_pointerdown"],[oe,"_pointermove"],[le,"_pointerup"],[re,"_pointerleave"],[ce,"_pointerdown"],[ue,"_pointermove"],[de,"_pointerup"],[fe,"_pointercancel"],[se,"_pointerover"],[It,"_wheel"],[Gt,"_contextmenu"],[tt,"_pointerdown"],[Q,"_pointermove"],[V,"_pointerup"],[et,"_pointercancel"],[it,"_pointerleave"],[li,"_lostpointercapture"]],Dt={mouse:{[yt]:hi,[it]:re,[Ct]:se,[bt]:ae,[Q]:oe,[tt]:he,[V]:le,[et]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[yt]:"touchout",[it]:"touchleave",[Ct]:"touchover",[bt]:"touchenter",[Q]:ue,[tt]:ce,[V]:de,[et]:fe,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[yt]:yt,[it]:it,[Ct]:Ct,[bt]:bt,[Q]:Q,[tt]:tt,[V]:V,[et]:et,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},nt=r=>r.indexOf("pointer")>=0?"pointer":r.indexOf("touch")>=0?"touch":"mouse",X=r=>{let t=nt(r);if(t==="pointer")return p.pointerEventsEnabled&&Dt.pointer;if(t==="touch")return Dt.touch;if(t==="mouse")return Dt.mouse};function ne(r={}){return(r.clipFunc||r.clipWidth||r.clipHeight)&&l.warn("Stage does not support clipping. Please use clip for Layers or Groups."),r}var ui="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);",St=[],U=class extends P{constructor(t){super(ne(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),St.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{ne(this.attrs)}),this._checkVisibility()}_validateAdd(t){let e=t.getType()==="Layer",i=t.getType()==="FastLayer";e||i||l.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;let t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if(typeof t===oi){let e;if(t.charAt(0)==="."){let i=t.slice(1);t=document.getElementsByClassName(i)[0]}else t.charAt(0)!=="#"?e=t:e=t.slice(1),t=document.getElementById(e);if(!t)throw"Can not find container in document with id "+e}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){let t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].clear();return this}clone(t){return t||(t={}),t.container=typeof document<"u"&&document.createElement("div"),P.prototype.clone.call(this,t)}destroy(){super.destroy();let t=this.content;t&&l._isInDocument(t)&&this.container().removeChild(t);let e=St.indexOf(this);return e>-1&&St.splice(e,1),l.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){let t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(l.warn(ui),null)}_getPointerById(t){return this._pointerPositions.find(e=>e.id===t)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){t={...t},t.x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();let e=new T({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,n=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),n.forEach(function(s){if(!s.isVisible())return;let a=s._toKonvaCanvas(t);i.drawImage(a._canvas,t.x,t.y,a.getWidth()/a.getPixelRatio(),a.getHeight()/a.getPixelRatio())}),e}getIntersection(t){if(!t)return null;let e=this.children,i=e.length,n=i-1;for(let s=n;s>=0;s--){let a=e[s].getIntersection(t);if(a)return a}return null}_resizeDOM(){let t=this.width(),e=this.height();this.content&&(this.content.style.width=t+ie,this.content.style.height=e+ie),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 n=0;n<arguments.length;n++)this.add(arguments[n]);return this}super.add(t);let i=this.children.length;return i>ci&&l.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(),p.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return _t(t,this)}setPointerCapture(t){vt(t,this)}releaseCapture(t){Y(t,this)}getLayers(){return this.children}_bindContentEvents(){p.isBrowser&&di.forEach(([t,e])=>{this.content.addEventListener(t,i=>{this[e](i)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);let e=X(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);let e=X(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){let e=X(t.type),i=nt(t.type);if(!e)return;this.setPointersPositions(t);let n=this._getTargetShape(i),s=!(p.isDragging()||p.isTransforming())||p.hitOnDragEnabled;n&&s?(n._fireAndBubble(e.pointerout,{evt:t}),n._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"targetShape"]=null):s&&(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){let e=X(t.type),i=nt(t.type);if(!e)return;this.setPointersPositions(t);let n=!1;this._changedPointerPositions.forEach(s=>{let a=this.getIntersection(s);if(b.justDragged=!1,p["_"+i+"ListenClick"]=!0,!a||!a.isListening()){this[i+"ClickStartShape"]=void 0;return}p.capturePointerEventsEnabled&&a.setPointerCapture(s.id),this[i+"ClickStartShape"]=a,a._fireAndBubble(e.pointerdown,{evt:t,pointerId:s.id}),n=!0;let o=t.type.indexOf("touch")>=0;a.preventDefault()&&t.cancelable&&o&&t.preventDefault()}),n||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){let e=X(t.type),i=nt(t.type);if(!e)return;let n=t.type.indexOf("touch")>=0||t.pointerType==="touch";if(p.isDragging()&&b.node.preventDefault()&&t.cancelable&&n&&t.preventDefault(),this.setPointersPositions(t),!(!(p.isDragging()||p.isTransforming())||p.hitOnDragEnabled))return;let a={},o=!1,h=this._getTargetShape(i);this._changedPointerPositions.forEach(c=>{let d=pt(c.id)||this.getIntersection(c),g=c.id,m={evt:t,pointerId:g},_=h!==d;if(_&&h&&(h._fireAndBubble(e.pointerout,{...m},d),h._fireAndBubble(e.pointerleave,{...m},d)),d){if(a[d._id])return;a[d._id]=!0}d&&d.isListening()?(o=!0,_&&(d._fireAndBubble(e.pointerover,{...m},h),d._fireAndBubble(e.pointerenter,{...m},h),this[i+"targetShape"]=d),d._fireAndBubble(e.pointermove,{...m})):h&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:g}),this[i+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){let e=X(t.type),i=nt(t.type);if(!e)return;this.setPointersPositions(t);let n=this[i+"ClickStartShape"],s=this[i+"ClickEndShape"],a={},o=!1;this._changedPointerPositions.forEach(h=>{let c=pt(h.id)||this.getIntersection(h);if(c){if(c.releaseCapture(h.id),a[c._id])return;a[c._id]=!0}let d=h.id,g={evt:t,pointerId:d},m=!1;p["_"+i+"InDblClickWindow"]?(m=!0,clearTimeout(this[i+"DblTimeout"])):b.justDragged||(p["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){p["_"+i+"InDblClickWindow"]=!1},p.dblClickWindow),c&&c.isListening()?(o=!0,this[i+"ClickEndShape"]=c,c._fireAndBubble(e.pointerup,{...g}),p["_"+i+"ListenClick"]&&n&&n===c&&(c._fireAndBubble(e.pointerclick,{...g}),m&&s&&s===c&&c._fireAndBubble(e.pointerdblclick,{...g}))):(this[i+"ClickEndShape"]=null,o||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),o=!0),p["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),m&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))}),o||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),p["_"+i+"ListenClick"]=!1,t.cancelable&&i!=="touch"&&i!=="pointer"&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);let e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Gt,{evt:t}):this._fire(Gt,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);let e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(It,{evt:t}):this._fire(It,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);let e=pt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(V,mt(t)),Y(t.pointerId)}_lostpointercapture(t){Y(t.pointerId)}setPointersPositions(t){let e=this._getContentPosition(),i=null,n=null;t=t||window.event,t.touches!==void 0?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,s=>{this._pointerPositions.push({id:s.identifier,x:(s.clientX-e.left)/e.scaleX,y:(s.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,s=>{this._changedPointerPositions.push({id:s.identifier,x:(s.clientX-e.left)/e.scaleX,y:(s.clientY-e.top)/e.scaleY})})):(i=(t.clientX-e.left)/e.scaleX,n=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:n},this._pointerPositions=[{x:i,y:n,id:l._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:n,id:l._getFirstPointerId(t)}])}_setPointerPosition(t){l.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};let 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 N({pixelRatio:1,width:this.width(),height:this.height()}),!p.isBrowser)return;let 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 l.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}};U.prototype.nodeType=ai;O(U);u.addGetterSetter(U,"container");p.isBrowser&&document.addEventListener("visibilitychange",()=>{St.forEach(r=>{r.batchDraw()})});var ge="hasShadow",pe="shadowRGBA",me="patternImage",_e="linearGradient",ve="radialGradient",wt;function Ot(){return wt||(wt=l.createCanvasElement().getContext("2d"),wt)}var rt={};function fi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function gi(r){r.stroke()}function pi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function mi(r){r.stroke()}function _i(){this._clearCache(ge)}function vi(){this._clearCache(pe)}function yi(){this._clearCache(me)}function Ci(){this._clearCache(_e)}function bi(){this._clearCache(ve)}var f=class extends y{constructor(t){super(t);let e,i=0;for(;e=l.getHitColor(),!(e&&!(e in rt));)if(i++,i>=1e4){l.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=l.getRandomColor();break}this.colorKey=e,rt[e]=this}getContext(){return l.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return l.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(ge,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(me,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){let e=Ot().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){let i=new L;i.translate(this.fillPatternX(),this.fillPatternY()),i.rotate(p.getAngle(this.fillPatternRotation())),i.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),i.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());let n=i.getMatrix(),s=typeof DOMMatrix>"u"?{a:n[0],b:n[1],c:n[2],d:n[3],e:n[4],f:n[5]}:new DOMMatrix(n);e.setTransform(s)}return e}}_getLinearGradient(){return this._getCache(_e,this.__getLinearGradient)}__getLinearGradient(){let t=this.fillLinearGradientColorStops();if(t){let e=Ot(),i=this.fillLinearGradientStartPoint(),n=this.fillLinearGradientEndPoint(),s=e.createLinearGradient(i.x,i.y,n.x,n.y);for(let a=0;a<t.length;a+=2)s.addColorStop(t[a],t[a+1]);return s}}_getRadialGradient(){return this._getCache(ve,this.__getRadialGradient)}__getRadialGradient(){let t=this.fillRadialGradientColorStops();if(t){let e=Ot(),i=this.fillRadialGradientStartPoint(),n=this.fillRadialGradientEndPoint(),s=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),n.x,n.y,this.fillRadialGradientEndRadius());for(let a=0;a<t.length;a+=2)s.addColorStop(t[a],t[a+1]);return s}}getShadowRGBA(){return this._getCache(pe,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;let t=l.colorToRGBA(this.shadowColor());if(t)return"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")"}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){let t=this.hitStrokeWidth();return t==="auto"?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){let e=this.getStage();if(!e)return!1;let i=e.bufferHitCanvas;return i.getContext().clear(),this.drawHit(i,void 0,!0),i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return y.prototype.destroy.call(this),delete rt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!((e=this.attrs.perfectDrawEnabled)!==null&&e!==void 0?e:!0))return!1;let n=t||this.hasFill(),s=this.hasStroke(),a=this.getAbsoluteOpacity()!==1;if(n&&s&&a)return!0;let o=this.hasShadow(),h=this.shadowForStrokeEnabled();return!!(n&&s&&o&&h)}setStrokeHitEnabled(t){l.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){let 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()}let n=t.skipTransform,s=t.relativeTo||e&&this.getStage()||void 0,a=this.getSelfRect(),h=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,c=a.width+h,d=a.height+h,g=!t.skipShadow&&this.hasShadow(),m=g?this.shadowOffsetX():0,_=g?this.shadowOffsetY():0,v=c+Math.abs(m),x=d+Math.abs(_),E=g&&this.shadowBlur()||0,w=v+E*2,G=x+E*2,I={width:w,height:G,x:-(h/2+E)+Math.min(m,0)+a.x,y:-(h/2+E)+Math.min(_,0)+a.y};return n?I:this._transformedRect(I,s)}drawScene(t,e,i){let n=this.getLayer(),s=t||n.getCanvas(),a=s.getContext(),o=this._getCanvasCache(),h=this.getSceneFunc(),c=this.hasShadow(),d,g=!1,m=e===this;if(!this.isVisible()&&!m)return this;if(o){a.save();let _=this.getAbsoluteTransform(e).getMatrix();return a.transform(_[0],_[1],_[2],_[3],_[4],_[5]),this._drawCachedSceneCanvas(a),a.restore(),this}if(!h)return this;if(a.save(),this._useBufferCanvas()&&!g){d=this.getStage();let _=i||d.bufferCanvas,v=_.getContext();i?(v.save(),v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,_.width,_.height),v.restore()):v.clear(),v.save(),v._applyLineJoin(this),v._applyMiterLimit(this);let x=this.getAbsoluteTransform(e).getMatrix();v.transform(x[0],x[1],x[2],x[3],x[4],x[5]),h.call(this,v,this),v.restore();let E=_.pixelRatio;c&&a._applyShadow(this),m||(a._applyOpacity(this),a._applyGlobalCompositeOperation(this)),a.drawImage(_._canvas,_.x||0,_.y||0,_.width/E,_.height/E)}else{if(a._applyLineJoin(this),a._applyMiterLimit(this),!m){let _=this.getAbsoluteTransform(e).getMatrix();a.transform(_[0],_[1],_[2],_[3],_[4],_[5]),a._applyOpacity(this),a._applyGlobalCompositeOperation(this)}c&&a._applyShadow(this),h.call(this,a,this)}return a.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;let n=this.getLayer(),s=t||n.hitCanvas,a=s&&s.getContext(),o=this.hitFunc()||this.sceneFunc(),h=this._getCanvasCache(),c=h&&h.hit;if(this.colorKey||l.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()"),c){a.save();let g=this.getAbsoluteTransform(e).getMatrix();return a.transform(g[0],g[1],g[2],g[3],g[4],g[5]),this._drawCachedHitCanvas(a),a.restore(),this}if(!o)return this;if(a.save(),a._applyLineJoin(this),a._applyMiterLimit(this),!(this===e)){let g=this.getAbsoluteTransform(e).getMatrix();a.transform(g[0],g[1],g[2],g[3],g[4],g[5])}return o.call(this,a,this),a.restore(),this}drawHitFromCache(t=0){let e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),n=e.hit,s=n.getContext(),a=n.getWidth(),o=n.getHeight();s.clear(),s.drawImage(i._canvas,0,0,a,o);try{let h=s.getImageData(0,0,a,o),c=h.data,d=c.length,g=l._hexToRgb(this.colorKey);for(let m=0;m<d;m+=4)c[m+3]>t?(c[m]=g.r,c[m+1]=g.g,c[m+2]=g.b,c[m+3]=255):c[m+3]=0;s.putImageData(h,0,0)}catch(h){l.error("Unable to draw hit graph from cached scene canvas. "+h.message)}return this}hasPointerCapture(t){return _t(t,this)}setPointerCapture(t){vt(t,this)}releaseCapture(t){Y(t,this)}};f.prototype._fillFunc=fi;f.prototype._strokeFunc=gi;f.prototype._fillFuncHit=pi;f.prototype._strokeFuncHit=mi;f.prototype._centroid=!1;f.prototype.nodeType="Shape";O(f);f.prototype.eventListeners={};f.prototype.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",_i);f.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",vi);f.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",yi);f.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",Ci);f.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",bi);u.addGetterSetter(f,"stroke",void 0,Tt());u.addGetterSetter(f,"strokeWidth",2,C());u.addGetterSetter(f,"fillAfterStrokeEnabled",!1);u.addGetterSetter(f,"hitStrokeWidth","auto",Wt());u.addGetterSetter(f,"strokeHitEnabled",!0,R());u.addGetterSetter(f,"perfectDrawEnabled",!0,R());u.addGetterSetter(f,"shadowForStrokeEnabled",!0,R());u.addGetterSetter(f,"lineJoin");u.addGetterSetter(f,"lineCap");u.addGetterSetter(f,"miterLimit");u.addGetterSetter(f,"sceneFunc");u.addGetterSetter(f,"hitFunc");u.addGetterSetter(f,"dash");u.addGetterSetter(f,"dashOffset",0,C());u.addGetterSetter(f,"shadowColor",void 0,M());u.addGetterSetter(f,"shadowBlur",0,C());u.addGetterSetter(f,"shadowOpacity",1,C());u.addComponentsGetterSetter(f,"shadowOffset",["x","y"]);u.addGetterSetter(f,"shadowOffsetX",0,C());u.addGetterSetter(f,"shadowOffsetY",0,C());u.addGetterSetter(f,"fillPatternImage");u.addGetterSetter(f,"fill",void 0,Tt());u.addGetterSetter(f,"fillPatternX",0,C());u.addGetterSetter(f,"fillPatternY",0,C());u.addGetterSetter(f,"fillLinearGradientColorStops");u.addGetterSetter(f,"strokeLinearGradientColorStops");u.addGetterSetter(f,"fillRadialGradientStartRadius",0);u.addGetterSetter(f,"fillRadialGradientEndRadius",0);u.addGetterSetter(f,"fillRadialGradientColorStops");u.addGetterSetter(f,"fillPatternRepeat","repeat");u.addGetterSetter(f,"fillEnabled",!0);u.addGetterSetter(f,"strokeEnabled",!0);u.addGetterSetter(f,"shadowEnabled",!0);u.addGetterSetter(f,"dashEnabled",!0);u.addGetterSetter(f,"strokeScaleEnabled",!0);u.addGetterSetter(f,"fillPriority","color");u.addComponentsGetterSetter(f,"fillPatternOffset",["x","y"]);u.addGetterSetter(f,"fillPatternOffsetX",0,C());u.addGetterSetter(f,"fillPatternOffsetY",0,C());u.addComponentsGetterSetter(f,"fillPatternScale",["x","y"]);u.addGetterSetter(f,"fillPatternScaleX",1,C());u.addGetterSetter(f,"fillPatternScaleY",1,C());u.addComponentsGetterSetter(f,"fillLinearGradientStartPoint",["x","y"]);u.addComponentsGetterSetter(f,"strokeLinearGradientStartPoint",["x","y"]);u.addGetterSetter(f,"fillLinearGradientStartPointX",0);u.addGetterSetter(f,"strokeLinearGradientStartPointX",0);u.addGetterSetter(f,"fillLinearGradientStartPointY",0);u.addGetterSetter(f,"strokeLinearGradientStartPointY",0);u.addComponentsGetterSetter(f,"fillLinearGradientEndPoint",["x","y"]);u.addComponentsGetterSetter(f,"strokeLinearGradientEndPoint",["x","y"]);u.addGetterSetter(f,"fillLinearGradientEndPointX",0);u.addGetterSetter(f,"strokeLinearGradientEndPointX",0);u.addGetterSetter(f,"fillLinearGradientEndPointY",0);u.addGetterSetter(f,"strokeLinearGradientEndPointY",0);u.addComponentsGetterSetter(f,"fillRadialGradientStartPoint",["x","y"]);u.addGetterSetter(f,"fillRadialGradientStartPointX",0);u.addGetterSetter(f,"fillRadialGradientStartPointY",0);u.addComponentsGetterSetter(f,"fillRadialGradientEndPoint",["x","y"]);u.addGetterSetter(f,"fillRadialGradientEndPointX",0);u.addGetterSetter(f,"fillRadialGradientEndPointY",0);u.addGetterSetter(f,"fillPatternRotation",0);u.addGetterSetter(f,"fillRule",void 0,M());u.backCompat(f,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var Si="beforeDraw",wi="draw",ye=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],xi=ye.length,A=class extends P{constructor(t){super(t),this.canvas=new T,this.hitCanvas=new N({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);let 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(){y.prototype.moveToTop.call(this);let t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!y.prototype.moveUp.call(this))return!1;let e=this.getStage();return!e||!e.content?!1:(e.content.removeChild(this.getNativeCanvasElement()),this.index<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[this.index+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(y.prototype.moveDown.call(this)){let t=this.getStage();if(t){let 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(y.prototype.moveToBottom.call(this)){let t=this.getStage();if(t){let 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(){let t=this.getNativeCanvasElement();return y.prototype.remove.call(this),t&&t.parentNode&&l._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){let e=t.getType();e!=="Group"&&e!=="Shape"&&l.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return t={...t},t.width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=t.x!==void 0?t.x:this.x(),t.y=t.y!==void 0?t.y:this.y(),y.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){this.visible()?this.canvas._canvas.style.display="block":this.canvas._canvas.style.display="none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){l.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){l.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,l.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;let e=1,i=!1;for(;;){for(let n=0;n<xi;n++){let s=ye[n],a=this._getIntersection({x:t.x+s.x*e,y:t.y+s.y*e}),o=a.shape;if(o)return o;if(i=!!a.antialiased,!a.antialiased)break}if(i)e+=1;else return null}}_getIntersection(t){let e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,n=i[3];if(n===255){let s=l.getHitColorKey(i[0],i[1],i[2]),a=rt[s];return a?{shape:a}:{antialiased:!0}}else if(n>0)return{antialiased:!0};return{}}drawScene(t,e,i){let n=this.getLayer(),s=t||n&&n.getCanvas();return this._fire(Si,{node:this}),this.clearBeforeDraw()&&s.getContext().clear(),P.prototype.drawScene.call(this,s,e,i),this._fire(wi,{node:this}),this}drawHit(t,e){let i=this.getLayer(),n=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),P.prototype.drawHit.call(this,n,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){l.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return l.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;let t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}destroy(){return l.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};A.prototype.nodeType="Layer";O(A);u.addGetterSetter(A,"imageSmoothingEnabled",!0);u.addGetterSetter(A,"clearBeforeDraw",!0);u.addGetterSetter(A,"hitGraphEnabled",!0,R());var k=class r extends f{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",e=>{this._removeImageLoad(e.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){let t=this.image();t&&t.complete||t&&t.readyState===4||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){let t=!!this.cornerRadius(),e=this.hasShadow();return t&&e?!0:super._useBufferCanvas(!0)}_sceneFunc(t){let e=this.getWidth(),i=this.getHeight(),n=this.cornerRadius(),s=this.attrs.image,a;if(s){let o=this.attrs.cropWidth,h=this.attrs.cropHeight;o&&h?a=[s,this.cropX(),this.cropY(),o,h,0,0,e,i]:a=[s,0,0,e,i]}(this.hasFill()||this.hasStroke()||n)&&(t.beginPath(),n?l.drawRoundedRectPath(t,e,i,n):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),s&&(n&&t.clip(),t.drawImage.apply(t,a))}_hitFunc(t){let e=this.width(),i=this.height(),n=this.cornerRadius();t.beginPath(),n?l.drawRoundedRectPath(t,e,i,n):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e,i;return(i=(t=this.attrs.width)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.width)!==null&&i!==void 0?i:0}getHeight(){var t,e,i;return(i=(t=this.attrs.height)!==null&&t!==void 0?t:(e=this.image())===null||e===void 0?void 0:e.height)!==null&&i!==void 0?i:0}static fromURL(t,e,i=null){let n=l.createImageElement();n.onload=function(){let s=new r({image:n});e(s)},n.onerror=i,n.crossOrigin="Anonymous",n.src=t}};k.prototype.className="Image";k.prototype._attrsAffectingSize=["image"];O(k);u.addGetterSetter(k,"cornerRadius",0,Vt(4));u.addGetterSetter(k,"image");u.addComponentsGetterSetter(k,"crop",["x","y","width","height"]);u.addGetterSetter(k,"cropX",0,C());u.addGetterSetter(k,"cropY",0,C());u.addGetterSetter(k,"cropWidth",0,C());u.addGetterSetter(k,"cropHeight",0,C());function Mt(r,t){r.konvaNode.on("click",()=>{t()})}function st(r,t){r?t():window.addEventListener("scratch-engine-ready",t,{once:!0})}function Ei(r){let t={space:" ","left arrow":"ArrowLeft","right arrow":"ArrowRight","up arrow":"ArrowUp","down arrow":"ArrowDown",any:"any"},e=r.trim().toLowerCase();return t[e]??e}function Nt(r,t){let e=r.trim().toLowerCase(),i=Ei(e);window.addEventListener("keydown",n=>{if(i==="any"){t();return}(typeof i=="string"&&n.key.toLowerCase()===i.toLowerCase()||i?.length===1&&n.key.length===1&&n.key.toLowerCase()===i.toLowerCase())&&t()})}function ki(r){let t=document.createElement("div");return t.style.position="absolute",t.style.padding="4px 6px",t.style.background="rgba(255,255,255,0.85)",t.style.border="1px solid rgba(0,0,0,0.15)",t.style.borderRadius="6px",t.style.whiteSpace="pre",t.style.display="none",r==="list"&&(t.style.maxWidth="220px"),t}var xt=class{constructor(t){this.variableMonitors=new Map;this.listMonitors=new Map;this.monitorOrder=[];t.style.position=t.style.position||"relative",this.root=document.createElement("div"),this.root.style.position="absolute",this.root.style.left="0",this.root.style.top="0",this.root.style.width="100%",this.root.style.height="100%",this.root.style.zIndex="9999",this.root.style.pointerEvents="none",this.root.style.fontFamily="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",this.root.style.fontSize="12px",this.root.style.color="#111",t.appendChild(this.root)}layout(){let t=6;for(let e of this.monitorOrder){let i=this.variableMonitors.get(e)??this.listMonitors.get(e);!i||i.style.display==="none"||(i.style.left="6px",i.style.top=`${t}px`,t+=i.getBoundingClientRect().height+6)}}ensure(t,e){let i=t==="variable"?this.variableMonitors:this.listMonitors,n=i.get(e);if(n)return n;let s=ki(t);return this.root.appendChild(s),i.set(e,s),this.monitorOrder.push(e),s}showVariable(t){let e=this.ensure("variable",t);e.style.display="block",this.layout()}hideVariable(t){let e=this.variableMonitors.get(t);e&&(e.style.display="none",this.layout())}renderVariable(t,e){let i=this.ensure("variable",t);i.style.display="block",i.textContent=`${t}: ${String(e)}`,this.layout()}showList(t){let e=this.ensure("list",t);e.style.display="block",this.layout()}hideList(t){let e=this.listMonitors.get(t);e&&(e.style.display="none",this.layout())}renderList(t,e){let i=this.ensure("list",t);i.style.display="block",Array.isArray(e)?i.textContent=`${t}:
|
|
15
15
|
${e.map(n=>String(n)).join(`
|
|
16
|
-
`)}`:i.textContent=`${t}: ${String(e)}`,this.layout()}};var
|
|
16
|
+
`)}`:i.textContent=`${t}: ${String(e)}`,this.layout()}};var Ht=new Map;function Pi(r){return new Promise((t,e)=>{let i=new Image;i.onload=()=>t(i),i.onerror=()=>e(new Error(`Failed to load image: ${r}`)),i.src=r})}async function Ti(r){let e=await(await fetch(r)).text(),i=btoa(unescape(encodeURIComponent(e))),n=new Image;return n.src=`data:image/svg+xml;base64,${i}`,await new Promise((s,a)=>{n.onload=()=>s(),n.onerror=()=>a(new Error(`Failed to load svg: ${r}`))}),n}function Et(r){let t="./assets/"+r.md5ext,e=`${r.assetId}:${r.dataFormat}`,i=Ht.get(e);if(i)return i;let n=r.dataFormat==="svg"?Ti(t):Pi(t);return Ht.set(e,n),n.catch(()=>Ht.delete(e)),n}var kt=class{constructor(){this.broadcastHandlers=new Map}onBroadcast(t,e){let i=String(t),n=this.broadcastHandlers.get(i)??new Set;return n.add(e),this.broadcastHandlers.set(i,n),()=>{let s=this.broadcastHandlers.get(i);s&&(s.delete(e),s.size===0&&this.broadcastHandlers.delete(i))}}broadcast(t){this.broadcastAndWait(t)}async broadcastAndWait(t){let e=String(t),i=Array.from(this.broadcastHandlers.get(e)??[]);i.length!==0&&await Promise.all(i.map(async n=>{try{await n()}catch(s){console.error(`[ScratchEventBus] Broadcast handler failed (${e})`,s)}}))}};var Ft=class{constructor(t,e){this.sprites=[];this.eventBus=new kt;if(!t.isStage)throw new Error("Please pass a stage not sprite");this.stage=t,this.currentCostume=t.costumes[t.currentCostume??0],this.logicalWidth=480,this.logicalHeight=360,this.konvaStage=new U({container:e,width:480,height:360});let i=typeof e=="string"?document.getElementById(e):e;if(!i)throw new Error(`Container not found: ${String(e)}`);this.monitors=new xt(i),this.backdropLayer=new A,this.spriteLayer=new A,this.konvaStage.add(this.backdropLayer),this.konvaStage.add(this.spriteLayer),this.backdropImage=new k({name:"backdrop",image:new Image}),this.backdropLayer.add(this.backdropImage)}addSprite(t){this.sprites.includes(t)||this.sprites.push(t)}broadcast(t){this.eventBus.broadcast(t)}broadcastAndWait(t){return this.eventBus.broadcastAndWait(t)}draw(){this.currentCostume&&Et(this.currentCostume).then(t=>{let e=this.logicalWidth,i=this.logicalHeight,n=this.currentCostume,s=n.bitmapResolution??1,a=(n.rotationCenterX??t.width/2)/s,o=(n.rotationCenterY??t.height/2)/s,h=e/2,c=i/2,d=h-a,g=c-o,m=t.width/s,_=t.height/s;this.backdropImage.setAttrs({image:t,x:d,y:g,width:m,height:_}),this.backdropLayer.batchDraw()}).catch(console.warn)}change(t){let e=this.stage.costumes.find(i=>i.name===t||i.assetId===t);if(!e)throw new Error("This costume doesn't exist");this.currentCostume=e,this.draw()}on(t,...e){switch(t){case"flag":typeof e[0]=="function"?st(!0,e[0]):console.warn("[Stage] Callback must be provided for 'flag' event");break;case"broadcast":{let i=e[0],n=e[1];typeof i=="string"&&typeof n=="function"?this.eventBus.onBroadcast(i,n):console.warn("[Stage] For 'broadcast', provide a message and a callback: on('broadcast', message, callback)");break}default:console.warn(`[Stage] Unknown event type: ${t}`)}}onFlag(t){this.on("flag",t)}onBroadcast(t,e){this.on("broadcast",t,e)}showVariable(t){this.monitors.showVariable(t)}hideVariable(t){this.monitors.hideVariable(t)}renderVariable(t,e){this.monitors.renderVariable(t,e)}showList(t){this.monitors.showList(t)}hideList(t){this.monitors.hideList(t)}renderList(t,e){this.monitors.renderList(t,e)}};var Bt=class{constructor(t){this.images=[];this.isReady=!1;this.data=t,this.konvaNode=new k({name:t.name,image:new Image});let e=this.data.costumes.map((i,n)=>Et(i).then(s=>{this.images[n]=s}));this.ready=Promise.all(e).then(()=>{this.isReady=!0})}on(t,e,i){switch(t){case"click":typeof e=="function"?Mt(this,e):console.warn("[Sprite] Callback must be provided for 'click' event");break;case"flag":typeof e=="function"?st(!0,e):console.warn("[Sprite] Callback must be provided for 'flag' event");break;case"keypress":typeof e=="string"&&typeof i=="function"?Nt(e,i):console.warn("[Sprite] For 'keypress', provide a key and a callback: on('keypress', key, callback)");break;case"broadcast":if(typeof e=="string"&&typeof i=="function"){if(!this.stage){console.warn("[Sprite] Cannot register broadcast handler before draw(stage) attaches sprite to a stage");break}this.stage.on("broadcast",e,i)}else console.warn("[Sprite] For 'broadcast', provide a message and a callback: on('broadcast', message, callback)");break;default:console.warn(`[Sprite] Unknown event type: ${t}`)}}onClick(t){this.on("click",t)}onFlag(t){this.on("flag",t)}onKeyPress(t,e){this.on("keypress",t,e)}onBroadcast(t,e){this.on("broadcast",t,e)}broadcast(t){if(!this.stage){console.warn("[Sprite] Cannot broadcast before draw(stage) attaches sprite to a stage");return}this.stage.broadcast(t)}broadcastAndWait(t){return this.stage?this.stage.broadcastAndWait(t):(console.warn("[Sprite] Cannot broadcastAndWait before draw(stage) attaches sprite to a stage"),Promise.resolve())}attachToStage(t){t.addSprite(this),this.stage!==t&&(this.konvaNode.remove(),t.spriteLayer.add(this.konvaNode),this.stage=t)}draw(t){this.attachToStage(t),this.isReady?this.performDraw(t):this.ready.then(()=>{this.performDraw(t)}).catch(console.error)}performDraw(t){if(!this.data.visible){this.konvaNode.visible(!1),t.spriteLayer.batchDraw();return}let e=this.data.currentCostume??0,i=this.images[e];if(!i)return;let n=this.data.costumes[e],s=this.data.x??0,a=this.data.y??0,o=this.data.direction??90,h=this.data.size??100,c=n.bitmapResolution??1,d=480/2+s,g=360/2-a,m=(n.rotationCenterX??i.width/2)/c,_=(n.rotationCenterY??i.height/2)/c,v=i.width/c,x=i.height/c;this.konvaNode.setAttrs({image:i,x:d,y:g,width:v,height:x,rotation:o-90,scaleX:h/100,scaleY:h/100,offsetX:m,offsetY:_,visible:!0}),t.spriteLayer.batchDraw()}nextCostume(){if(!Array.isArray(this.data.costumes)||this.data.costumes.length===0)return;let e=((this.data.currentCostume??0)+1)%this.data.costumes.length;this.data.currentCostume=e,this.stage&&this.draw(this.stage)}switchCostumeTo(t){if(!Array.isArray(this.data.costumes)||this.data.costumes.length===0)return;let e=-1;typeof t=="number"?Number.isInteger(t)&&t>=0&&t<this.data.costumes.length&&(e=t):typeof t=="string"&&(e=this.data.costumes.findIndex(i=>i.name===t)),e>=0&&e<this.data.costumes.length&&(this.data.currentCostume=e,this.stage&&this.draw(this.stage))}turnRight(t){this.turnBy(t)}turnLeft(t){this.turnBy(-t)}move(t){if(!Number.isFinite(t)){console.warn(`[Sprite] move expected a finite number, received ${t}`);return}let i=((this.data.direction??90)-90)*(Math.PI/180);this.data.x=(this.data.x??0)+t*Math.cos(i),this.data.y=(this.data.y??0)+t*Math.sin(i),this.stage&&this.draw(this.stage)}gotoXY(t,e){if(!Number.isFinite(t)||!Number.isFinite(e)){console.warn(`[Sprite] gotoXY expected finite numbers, received x: ${t}, y: ${e}`);return}this.data.x=t,this.data.y=e,this.stage&&this.draw(this.stage)}isTouching(t){if(!this.stage)return!1;if(t==="_edge_"){let s=this.konvaNode.getClientRect();return s.x<0||s.y<0||s.x+s.width>480||s.y+s.height>360}if(t==="_mouse_"){let s=this.stage.konvaStage.getPointerPosition();return s?this.stage.konvaStage.getIntersection(s)===this.konvaNode:!1}let e=this.stage.sprites.find(s=>s.data.name===t&&s!==this);if(!e)return!1;let i=this.konvaNode.getClientRect(),n=e.konvaNode.getClientRect();return!(n.x>i.x+i.width||n.x+n.width<i.x||n.y>i.y+i.height||n.y+n.height<i.y)}ifOnEdgeBounce(){if(!this.stage)return;this.performDraw(this.stage);let t=this.konvaNode.getClientRect(),e=480,i=360,n=!1,s=this.data.direction??90,a=this.data.x??0,o=this.data.y??0;t.x<0?(a+=-t.x,s=-s,n=!0):t.x+t.width>e&&(a-=t.x+t.width-e,s=-s,n=!0),t.y<0?(o-=-t.y,s=180-s,n=!0):t.y+t.height>i&&(o+=t.y+t.height-i,s=180-s,n=!0),n&&(s=s%360,s<=-180&&(s+=360),s>180&&(s-=360),this.data.direction=s,this.data.x=a,this.data.y=o,this.draw(this.stage))}hide(){this.data.visible=!1,this.stage&&this.draw(this.stage)}show(){this.data.visible=!0,this.stage&&this.draw(this.stage)}turnBy(t){if(!Number.isFinite(t)){console.warn(`[Sprite] turnBy expected a finite number, received ${t}`);return}this.data.direction=(this.data.direction??90)+t,this.stage&&this.draw(this.stage)}};export{Bt as Sprite,Ft as Stage};
|
|
17
17
|
//# sourceMappingURL=index.js.map
|