@scratch-compiler/client 1.2.0 → 1.3.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 +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var we=Math.PI/180;function
|
|
1
|
+
var we=Math.PI/180;function xe(){return typeof window<"u"&&({}.toString.call(window)==="[object Window]"||{}.toString.call(window)==="[object global]")}var ot=typeof global<"u"?global:typeof window<"u"?window:typeof WorkerGlobalScope<"u"?self:{},p={_global:ot,version:"10.2.3",isBrowser:xe(),isUnminified:/param/.test(function(r){}.toString()),dblClickWindow:400,getAngle(r){return p.angleDeg?r*we: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:ot.document,_injectGlobal(r){typeof ot.Konva<"u"&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),ot.Konva=r}},O=r=>{p[r.prototype.getClassName()]=r};p._injectGlobal(p);var Ee=`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
|
-
`,Ut=()=>{if(typeof document>"u")throw new Error(xe)},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 l=Math.sqrt(t*t+e*e);h.rotation=e>0?Math.acos(t/l):-Math.acos(t/l),h.scaleX=l,h.scaleY=o/l,h.skewX=(t*i+e*n)/o,h.skewY=0}else if(i!=0||n!=0){let l=Math.sqrt(i*i+n*n);h.rotation=Math.PI/2-(n>0?Math.acos(-i/l):-Math.acos(i/l)),h.scaleX=o/l,h.scaleY=l,h.skewX=0,h.skewY=(t*i+e*n)/o}return h.rotation=c._getRotation(h.rotation),h}},Ee="[object Array]",ke="[object Number]",Pe="[object String]",Te="[object Boolean]",Re=Math.PI/180,Ae=180/Math.PI,q="#",De="",Le="0",Ge="Konva warning: ",Xt="Konva error: ",Ie="rgb(",Tt={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]},Oe=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,ot=[],j=null,Me=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(r){setTimeout(r,16)},c={_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)===Ee},_isNumber(r){return Object.prototype.toString.call(r)===ke&&!isNaN(r)&&isFinite(r)},_isString(r){return Object.prototype.toString.call(r)===Pe},_isBoolean(r){return Object.prototype.toString.call(r)===Te},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&&Me(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=c.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(q,De);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 q+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),q+this._rgbToHex(r,t,e)},getSnappedHexColor(r){let t=this._hexToRgb(r);return q+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 Tt?(t=Tt[r],{r:t[0],g:t[1],b:t[2]}):r[0]===q?this._hexToRgb(r.substring(1)):r.substr(0,4)===Ie?(t=Oe.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",c._namedColorToRBA(r)||c._hex3ColorToRGBA(r)||c._hex4ColorToRGBA(r)||c._hex6ColorToRGBA(r)||c._hex8ColorToRGBA(r)||c._rgbColorToRGBA(r)||c._rgbaColorToRGBA(r)||c._hslColorToRGBA(r)},_namedColorToRBA(r){let t=Tt[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 l=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=l+(a-l)*6*o:2*o<1?h=a:3*o<2?h=l+(a-l)*(2/3-o)*6:h=l,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*Re},radToDeg(r){return r*Ae},_degToRad(r){return c.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),c.degToRad(r)},_radToDeg(r){return c.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),c.radToDeg(r)},_getRotation(r){return p.angleDeg?c.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(Ge+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,l=(r-e)*(r-e)+(t-i)*(t-i);if(l==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))/l;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=c.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=c._getProjectionToSegment(s.x,s.y,o.x,o.y,r.x,r.y),l=h[0],d=h[1],g=h[2];g<n&&(i.x=l,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=c._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||c._isElement(r[e]))if(t.configurable)delete r[e];else return null;else if(c._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,l=0;typeof i=="number"?a=o=h=l=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),l=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-l),r.arc(n+t-l,s+e-l,l,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],l={x:o.x-a.x,y:o.y-a.y},d={x:h.x-o.x,y:h.y-o.y},g=Math.hypot(l.x,l.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:l.x/g,y:l.y/g},S={x:d.x/m,y:d.y/m},E={x:o.x-x.x*_,y:o.y-x.y*_},k={x:o.x+S.x*_,y:o.y+S.y*_};s===0?r.moveTo(E.x,E.y):r.lineTo(E.x,E.y),r.arcTo(o.x,o.y,k.x,k.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=c._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 c._isString(r)?'"'+r+'"':Object.prototype.toString.call(r)==="[object Number]"||c._isBoolean(r)?r:Object.prototype.toString.call(r)}function C(){if(p.isUnminified)return function(r,t){return c._isNumber(r)||c.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=c._isNumber(t),n=c._isArray(t)&&t.length==r;return!i&&!n&&c.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or Array<number>('+r+")"),t}}function Kt(){if(p.isUnminified)return function(r,t){return c._isNumber(r)||r==="auto"||c.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 c._isString(r)||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),r}}function Rt(){if(p.isUnminified)return function(r,t){let e=c._isString(r),i=Object.prototype.toString.call(r)==="[object CanvasGradient]"||r&&r.addColorStop;return e||i||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),r}}function A(){if(p.isUnminified)return function(r,t){return r===!0||r===!1||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),r}}function qt(r){if(p.isUnminified)return function(t,e){return t==null||c.isObject(t)||c.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+r),t}}var z="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=z+c._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=$+c._capitalize(t);r.prototype[n]||u.overWriteSetter(r,t,e,i)},overWriteSetter(r,t,e,i){let n=$+c._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=c._capitalize,o=z+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 l=qt(e);r.prototype[h]=function(d){let g=this.attrs[t];i&&(d=i.call(this,d,t)),l&&l.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=c._capitalize(t),i=$+e,n=z+e;r.prototype[t]=function(){return arguments.length?(this[i](arguments[0]),this):this[n]()}},addDeprecatedGetterSetter(r,t,e,i){c.error("Adding deprecated "+t);let n=z+c._capitalize(t),s=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";r.prototype[n]=function(){c.error(s);let a=this.attrs[t];return a===void 0?e:a},u.addSetter(r,t,i,function(){c.error(s)}),u.addOverloadedGetterSetter(r,t)},backCompat(r,t){c.each(t,function(e,i){let n=r.prototype[i],s=z+c._capitalize(e),a=$+c._capitalize(e);function o(){n.apply(this,arguments),c.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 Ne(r){let t=[],e=r.length,i=c;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 jt=",",He="(",Fe=")",Be="([",Ye="])",We=";",Ue="()",Xe="=",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"],Ve=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],Ke=100,ht=null;function At(){if(ht!==null)return ht;try{let t=c.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,l;for(a=0;a<n;a++)o=i[a],h=o.method,h?(l=o.args,s+=h,t?s+=Ue:c._isArray(l[0])?s+=Be+l.join(jt)+Ye:(e&&(l=l.map(d=>typeof d=="number"?Math.floor(d):d)),s+=He+l.join(jt)+Fe)):(s+=o.property,t||(s+=Xe+o.val)),s+=We;return s}clearTrace(){this.traceArr=[]}_trace(t){let e=this.traceArr,i;e.push(t),i=e.length,i>=Ke&&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,l){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,l)}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],l;t[o]=function(){return s=Ne(Array.prototype.slice.call(arguments,0)),l=h.apply(t,arguments),t._trace({method:o,args:s}),l}};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)}};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(),l=this.canvas.getPixelRatio(),d=h.x*l,g=h.y*l;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 qe(){if(dt)return dt;let r=c.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})(),c.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||qe();this.pixelRatio=i,this._canvas=c.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 c.error("Unable to get data URL. "+n.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},R=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 je(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:c.warn(`CSS filter "${i}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var ft="absoluteOpacity",$t="allEventListeners",G="absoluteTransform",Jt="absoluteScale",B="canvas",ze="Change",$e="children",Je="konva",Dt="listening",Ze="mouseenter",Qe="mouseleave",ti="pointerenter",ei="pointerleave",ii="touchenter",ni="touchleave";var Zt="set",Qt="Shape",gt=" ",te="stage",H="transform",ri="Stage",Lt="visible",si=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(gt),ai=1,y=class r{constructor(t){this._id=ai++,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===G)&&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===G)&&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===G&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(B)){let{scene:t,filter:e,hit:i}=this._cache.get(B);c.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,l=e.offset||0,d=e.drawBorder||!1,g=e.hitCanvasPixelRatio||1;if(!n||!s){c.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+=l*2+m,s+=l*2+_,o-=l,h-=l;let v=new R({pixelRatio:a,width:n,height:s}),x=new R({pixelRatio:a,width:0,height:0,willReadFrequently:!0}),S=new N({pixelRatio:g,width:n,height:s}),E=v.getContext(),k=S.getContext(),I=new R({width:v.width/v.pixelRatio+Math.abs(o),height:v.height/v.pixelRatio+Math.abs(h),pixelRatio:v.pixelRatio}),Wt=I.getContext();return S.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),E.save(),k.save(),Wt.save(),E.translate(-o,-h),k.translate(-o,-h),Wt.translate(-o,-h),I.x=o,I.y=h,this._isUnderCache=!0,this._clearSelfAndDescendantCache(ft),this._clearSelfAndDescendantCache(Jt),this.drawScene(v,this,I),this.drawHit(S,this),this._isUnderCache=!1,E.restore(),k.restore(),d&&(E.save(),E.beginPath(),E.rect(0,0,n,s),E.closePath(),E.setAttr("strokeStyle","red"),E.setAttr("lineWidth",5),E.stroke(),E.restore()),c.releaseCanvas(I._canvas),this._cache.set(B,{scene:v,filter:x,hit:S,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(l){let d=h.point(l);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,l;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"&&!At();if(typeof t[m]!="string"||!At()){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++)l=t[h],typeof l=="string"&&(l=je(l)),l.call(this,o),s.putImageData(o,0,0)}catch(m){c.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($t),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("."),l=h[0],d=h[1]||"";this.eventListeners[l]||(this.eventListeners[l]=[]),this.eventListeners[l].push({name:d,handler:i})}return this}off(t,e){let i=(t||"").split(gt),n=i.length,s,a,o,h,l,d;if(this._cache&&this._cache.delete($t),!t)for(a in this.eventListeners)this._off(a);for(s=0;s<n;s++)if(o=i[s],h=o.split("."),l=h[0],d=h[1],l)this.eventListeners[l]&&this._off(l,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=c.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(G),this._clearSelfAndDescendantCache(ft),this._clearSelfAndDescendantCache(Jt),this._clearSelfAndDescendantCache(te),this._clearSelfAndDescendantCache(Lt),this._clearSelfAndDescendantCache(Dt)}_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"+c._capitalize(t);return c._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!==$e&&(i=Zt+c._capitalize(e),c._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(Dt,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!==Qt&&(n=n.concat(o.getChildren().slice())),o._id===e._id&&(a=s);n.length>0&&n[0].getDepth()<=t&&h(n)}let l=this.getStage();return e.nodeType!==ri&&l&&h(l.getChildren()),i}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(H),this._clearSelfAndDescendantCache(G)),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(G),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 c.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 c.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 c.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 c.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 c.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&c.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=c.isObject(i)&&!c._isPlainObject(i)&&!c._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 c._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],c.isValidSelector(s)||(c.warn('Selector "'+s+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),c.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),c.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(te,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(G,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(G)||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,l=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),(l!==0||d!==0)&&i.skew(l,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=c.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(Je)<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 R({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(),l=new R({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,l),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,c._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[Zt+c._capitalize(t)];return c._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&&!c.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===Qt&&(e.target=this);let n=[Ze,Qe,ti,ei,ii,ni];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:c.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 c.haveIntersection(i,this.getClientRect())}static create(t,e){return c._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]||(c.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(si,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(H),this._clearSelfAndDescendantCache(G)});y.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(Lt)});y.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(Dt)});y.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache(ft)});var w=u.addGetterSetter;w(y,"zIndex");w(y,"absolutePosition");w(y,"position");w(y,"x",0,C());w(y,"y",0,C());w(y,"globalCompositeOperation","source-over",M());w(y,"opacity",1,C());w(y,"name","",M());w(y,"id","",M());w(y,"rotation",0,C());u.addComponentsGetterSetter(y,"scale",["x","y"]);w(y,"scaleX",1,C());w(y,"scaleY",1,C());u.addComponentsGetterSetter(y,"skew",["x","y"]);w(y,"skewX",0,C());w(y,"skewY",0,C());u.addComponentsGetterSetter(y,"offset",["x","y"]);w(y,"offsetX",0,C());w(y,"offsetY",0,C());w(y,"dragDistance",void 0,C());w(y,"width",0,C());w(y,"height",0,C());w(y,"listening",!0,A());w(y,"preventDefault",!0,A());w(y,"filters",void 0,function(r){return this._filterUpToDate=!1,r});w(y,"visible",!0,A());w(y,"transformsEnabled","all",M());w(y,"size");w(y,"dragBoundFunc");w(y,"draggable",!1,A());u.backCompat(y,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var T=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,l=s&&s.isCache;if(!this.isVisible()&&!l)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(),l=this.clipFunc(),d=typeof o=="number"&&typeof h=="number"||l,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(l)x=l.call(this,a,this);else{let S=this.clipX(),E=this.clipY();a.rect(S||0,E||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,l={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?l={x:s,y:a,width:o-s,height:h-a}:l={x:0,y:0,width:0,height:0},i?l:this._transformedRect(l,n)}};u.addComponentsGetterSetter(T,"clip",["x","y","width","height"]);u.addGetterSetter(T,"clipX",void 0,C());u.addGetterSetter(T,"clipY",void 0,C());u.addGetterSetter(T,"clipWidth",void 0,C());u.addGetterSetter(T,"clipHeight",void 0,C());u.addGetterSetter(T,"clipFunc");var Z=new Map,ee=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),ee&&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),ee&&e._fire("lostpointercapture",mt(new PointerEvent("lostpointercapture")))}var oi="Stage",hi="string",ne="px",li="mouseout",se="mouseleave",ae="mouseover",oe="mouseenter",he="mousemove",le="mousedown",ce="mouseup",Q="pointermove",tt="pointerdown",X="pointerup",et="pointercancel",ci="lostpointercapture",yt="pointerout",it="pointerleave",Ct="pointerover",bt="pointerenter",It="contextmenu",de="touchstart",ue="touchend",fe="touchmove",ge="touchcancel",Ot="wheel",di=5,ui=[[oe,"_pointerenter"],[le,"_pointerdown"],[he,"_pointermove"],[ce,"_pointerup"],[se,"_pointerleave"],[de,"_pointerdown"],[fe,"_pointermove"],[ue,"_pointerup"],[ge,"_pointercancel"],[ae,"_pointerover"],[Ot,"_wheel"],[It,"_contextmenu"],[tt,"_pointerdown"],[Q,"_pointermove"],[X,"_pointerup"],[et,"_pointercancel"],[it,"_pointerleave"],[ci,"_lostpointercapture"]],Gt={mouse:{[yt]:li,[it]:se,[Ct]:ae,[bt]:oe,[Q]:he,[tt]:le,[X]:ce,[et]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[yt]:"touchout",[it]:"touchleave",[Ct]:"touchover",[bt]:"touchenter",[Q]:fe,[tt]:de,[X]:ue,[et]:ge,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[yt]:yt,[it]:it,[Ct]:Ct,[bt]:bt,[Q]:Q,[tt]:tt,[X]:X,[et]:et,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},nt=r=>r.indexOf("pointer")>=0?"pointer":r.indexOf("touch")>=0?"touch":"mouse",U=r=>{let t=nt(r);if(t==="pointer")return p.pointerEventsEnabled&&Gt.pointer;if(t==="touch")return Gt.touch;if(t==="mouse")return Gt.mouse};function re(r={}){return(r.clipFunc||r.clipWidth||r.clipHeight)&&c.warn("Stage does not support clipping. Please use clip for Layers or Groups."),r}var fi="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=[],W=class extends T{constructor(t){super(re(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",()=>{re(this.attrs)}),this._checkVisibility()}_validateAdd(t){let e=t.getType()==="Layer",i=t.getType()==="FastLayer";e||i||c.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===hi){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"),T.prototype.clone.call(this,t)}destroy(){super.destroy();let t=this.content;t&&c._isInDocument(t)&&this.container().removeChild(t);let e=wt.indexOf(this);return e>-1&&wt.splice(e,1),c.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}:(c.warn(fi),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 R({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+ne,this.content.style.height=e+ne),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>di&&c.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&&ui.forEach(([t,e])=>{this.content.addEventListener(t,i=>{this[e](i)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);let e=U(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);let e=U(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=U(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=U(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=U(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(l=>{let d=pt(l.id)||this.getIntersection(l),g=l.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=U(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 l=pt(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),a[l._id])return;a[l._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),l&&l.isListening()?(o=!0,this[i+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...g}),p["_"+i+"ListenClick"]&&n&&n===l&&(l._fireAndBubble(e.pointerclick,{...g}),m&&s&&s===l&&l._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(It,{evt:t}):this._fire(It,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);let e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ot,{evt:t}):this._fire(Ot,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);let e=pt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(X,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:c._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:n,id:c._getFirstPointerId(t)}])}_setPointerPosition(t){c.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 R({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 c.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}};W.prototype.nodeType=oi;O(W);u.addGetterSetter(W,"container");p.isBrowser&&document.addEventListener("visibilitychange",()=>{wt.forEach(r=>{r.batchDraw()})});var pe="hasShadow",me="shadowRGBA",_e="patternImage",ve="linearGradient",ye="radialGradient",St;function Mt(){return St||(St=c.createCanvasElement().getContext("2d"),St)}var rt={};function gi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function pi(r){r.stroke()}function mi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function _i(r){r.stroke()}function vi(){this._clearCache(pe)}function yi(){this._clearCache(me)}function Ci(){this._clearCache(_e)}function bi(){this._clearCache(ve)}function wi(){this._clearCache(ye)}var f=class extends y{constructor(t){super(t);let e,i=0;for(;e=c.getHitColor(),!(e&&!(e in rt));)if(i++,i>=1e4){c.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=c.getRandomColor();break}this.colorKey=e,rt[e]=this}getContext(){return c.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return c.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(pe,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(_e,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){let e=Mt().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(ve,this.__getLinearGradient)}__getLinearGradient(){let t=this.fillLinearGradientColorStops();if(t){let e=Mt(),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(ye,this.__getRadialGradient)}__getRadialGradient(){let t=this.fillRadialGradientColorStops();if(t){let e=Mt(),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(me,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;let t=c.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){c.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,l=a.width+h,d=a.height+h,g=!t.skipShadow&&this.hasShadow(),m=g?this.shadowOffsetX():0,_=g?this.shadowOffsetY():0,v=l+Math.abs(m),x=d+Math.abs(_),S=g&&this.shadowBlur()||0,E=v+S*2,k=x+S*2,I={width:E,height:k,x:-(h/2+S)+Math.min(m,0)+a.x,y:-(h/2+S)+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(),l=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 S=_.pixelRatio;l&&a._applyShadow(this),m||(a._applyOpacity(this),a._applyGlobalCompositeOperation(this)),a.drawImage(_._canvas,_.x||0,_.y||0,_.width/S,_.height/S)}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)}l&&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(),l=h&&h.hit;if(this.colorKey||c.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){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),l=h.data,d=l.length,g=c._hexToRgb(this.colorKey);for(let m=0;m<d;m+=4)l[m+3]>t?(l[m]=g.r,l[m+1]=g.g,l[m+2]=g.b,l[m+3]=255):l[m+3]=0;s.putImageData(h,0,0)}catch(h){c.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=gi;f.prototype._strokeFunc=pi;f.prototype._fillFuncHit=mi;f.prototype._strokeFuncHit=_i;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",vi);f.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",yi);f.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",Ci);f.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",bi);f.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",wi);u.addGetterSetter(f,"stroke",void 0,Rt());u.addGetterSetter(f,"strokeWidth",2,C());u.addGetterSetter(f,"fillAfterStrokeEnabled",!1);u.addGetterSetter(f,"hitStrokeWidth","auto",Kt());u.addGetterSetter(f,"strokeHitEnabled",!0,A());u.addGetterSetter(f,"perfectDrawEnabled",!0,A());u.addGetterSetter(f,"shadowForStrokeEnabled",!0,A());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,Rt());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",xi="draw",Ce=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Ei=Ce.length,D=class extends T{constructor(t){super(t),this.canvas=new R,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&&c._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"&&c.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(){c.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){c.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,c.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<Ei;n++){let s=Ce[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=c.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(),T.prototype.drawScene.call(this,s,e,i),this._fire(xi,{node:this}),this}drawHit(t,e){let i=this.getLayer(),n=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),T.prototype.drawHit.call(this,n,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){c.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return c.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 c.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};D.prototype.nodeType="Layer";O(D);u.addGetterSetter(D,"imageSmoothingEnabled",!0);u.addGetterSetter(D,"clearBeforeDraw",!0);u.addGetterSetter(D,"hitGraphEnabled",!0,A());var P=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?c.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?c.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=c.createImageElement();n.onload=function(){let s=new r({image:n});e(s)},n.onerror=i,n.crossOrigin="Anonymous",n.src=t}};P.prototype.className="Image";P.prototype._attrsAffectingSize=["image"];O(P);u.addGetterSetter(P,"cornerRadius",0,Vt(4));u.addGetterSetter(P,"image");u.addComponentsGetterSetter(P,"crop",["x","y","width","height"]);u.addGetterSetter(P,"cropX",0,C());u.addGetterSetter(P,"cropY",0,C());u.addGetterSetter(P,"cropWidth",0,C());u.addGetterSetter(P,"cropHeight",0,C());function Nt(r,t){r.konvaNode.on("click",()=>{t()})}function st(r,t){r?t():window.addEventListener("scratch-engine-ready",t,{once:!0})}function ki(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 Ht(r,t){let e=r.trim().toLowerCase(),i=ki(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 Pi(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=Pi(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
|
+
`,Xt=()=>{if(typeof document>"u")throw new Error(Ee)},D=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 l=Math.sqrt(t*t+e*e);h.rotation=e>0?Math.acos(t/l):-Math.acos(t/l),h.scaleX=l,h.scaleY=o/l,h.skewX=(t*i+e*n)/o,h.skewY=0}else if(i!=0||n!=0){let l=Math.sqrt(i*i+n*n);h.rotation=Math.PI/2-(n>0?Math.acos(-i/l):-Math.acos(i/l)),h.scaleX=o/l,h.scaleY=l,h.skewX=0,h.skewY=(t*i+e*n)/o}return h.rotation=c._getRotation(h.rotation),h}},ke="[object Array]",Pe="[object Number]",Te="[object String]",Re="[object Boolean]",Ae=Math.PI/180,Le=180/Math.PI,j="#",De="",Ge="0",Ie="Konva warning: ",Vt="Konva error: ",Oe="rgb(",Rt={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]},Me=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,ht=[],z=null,Ne=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(r){setTimeout(r,16)},c={_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)===ke},_isNumber(r){return Object.prototype.toString.call(r)===Pe&&!isNaN(r)&&isFinite(r)},_isString(r){return Object.prototype.toString.call(r)===Te},_isBoolean(r){return Object.prototype.toString.call(r)===Re},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){ht.push(r),ht.length===1&&Ne(function(){let t=ht;ht=[],t.forEach(function(e){e()})})},createCanvasElement(){Xt();let r=document.createElement("canvas");try{r.style=r.style||{}}catch{}return r},createImageElement(){return Xt(),document.createElement("img")},_isInDocument(r){for(;r=r.parentNode;)if(r==document)return!0;return!1},_urlToImage(r,t){let e=c.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(j,De);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=Ge+r;return j+r},isCanvasFarblingActive(){if(z!==null)return z;if(typeof document>"u")return z=!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 z=i,this.releaseCanvas(r),z},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),j+this._rgbToHex(r,t,e)},getSnappedHexColor(r){let t=this._hexToRgb(r);return j+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 Rt?(t=Rt[r],{r:t[0],g:t[1],b:t[2]}):r[0]===j?this._hexToRgb(r.substring(1)):r.substr(0,4)===Oe?(t=Me.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",c._namedColorToRBA(r)||c._hex3ColorToRGBA(r)||c._hex4ColorToRGBA(r)||c._hex6ColorToRGBA(r)||c._hex8ColorToRGBA(r)||c._rgbColorToRGBA(r)||c._rgbaColorToRGBA(r)||c._hslColorToRGBA(r)},_namedColorToRBA(r){let t=Rt[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 l=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=l+(a-l)*6*o:2*o<1?h=a:3*o<2?h=l+(a-l)*(2/3-o)*6:h=l,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*Ae},radToDeg(r){return r*Le},_degToRad(r){return c.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),c.degToRad(r)},_radToDeg(r){return c.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),c.radToDeg(r)},_getRotation(r){return p.angleDeg?c.radToDeg(r):r},_capitalize(r){return r.charAt(0).toUpperCase()+r.slice(1)},throw(r){throw new Error(Vt+r)},error(r){console.error(Vt+r)},warn(r){p.showWarnings&&console.warn(Ie+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,l=(r-e)*(r-e)+(t-i)*(t-i);if(l==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))/l;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=c.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=c._getProjectionToSegment(s.x,s.y,o.x,o.y,r.x,r.y),l=h[0],d=h[1],g=h[2];g<n&&(i.x=l,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=c._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||c._isElement(r[e]))if(t.configurable)delete r[e];else return null;else if(c._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,l=0;typeof i=="number"?a=o=h=l=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),l=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-l),r.arc(n+t-l,s+e-l,l,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],l={x:o.x-a.x,y:o.y-a.y},d={x:h.x-o.x,y:h.y-o.y},g=Math.hypot(l.x,l.y),m=Math.hypot(d.x,d.y),v;typeof n=="number"?v=n:v=s<n.length?n[s]:0,v=i*Math.cos(Math.PI/e)*Math.min(1,v/i*2);let x={x:l.x/g,y:l.y/g},w={x:d.x/m,y:d.y/m},E={x:o.x-x.x*v,y:o.y-x.y*v},k={x:o.x+w.x*v,y:o.y+w.y*v};s===0?r.moveTo(E.x,E.y):r.lineTo(E.x,E.y),r.arcTo(o.x,o.y,k.x,k.y,v)}}};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=c._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 c._isString(r)?'"'+r+'"':Object.prototype.toString.call(r)==="[object Number]"||c._isBoolean(r)?r:Object.prototype.toString.call(r)}function C(){if(p.isUnminified)return function(r,t){return c._isNumber(r)||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),r}}function Kt(r){if(p.isUnminified)return function(t,e){let i=c._isNumber(t),n=c._isArray(t)&&t.length==r;return!i&&!n&&c.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or Array<number>('+r+")"),t}}function qt(){if(p.isUnminified)return function(r,t){return c._isNumber(r)||r==="auto"||c.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 c._isString(r)||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),r}}function At(){if(p.isUnminified)return function(r,t){let e=c._isString(r),i=Object.prototype.toString.call(r)==="[object CanvasGradient]"||r&&r.addColorStop;return e||i||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),r}}function A(){if(p.isUnminified)return function(r,t){return r===!0||r===!1||c.warn(F(r)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),r}}function jt(r){if(p.isUnminified)return function(t,e){return t==null||c.isObject(t)||c.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+r),t}}var $="get",J="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=$+c._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=J+c._capitalize(t);r.prototype[n]||u.overWriteSetter(r,t,e,i)},overWriteSetter(r,t,e,i){let n=J+c._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=c._capitalize,o=$+a(t),h=J+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 l=jt(e);r.prototype[h]=function(d){let g=this.attrs[t];i&&(d=i.call(this,d,t)),l&&l.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=c._capitalize(t),i=J+e,n=$+e;r.prototype[t]=function(){return arguments.length?(this[i](arguments[0]),this):this[n]()}},addDeprecatedGetterSetter(r,t,e,i){c.error("Adding deprecated "+t);let n=$+c._capitalize(t),s=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";r.prototype[n]=function(){c.error(s);let a=this.attrs[t];return a===void 0?e:a},u.addSetter(r,t,i,function(){c.error(s)}),u.addOverloadedGetterSetter(r,t)},backCompat(r,t){c.each(t,function(e,i){let n=r.prototype[i],s=$+c._capitalize(e),a=J+c._capitalize(e);function o(){n.apply(this,arguments),c.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 He(r){let t=[],e=r.length,i=c;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=",",Fe="(",Be=")",Ue="([",Ye="])",We=";",Xe="()",Ve="=",$t=["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"],Ke=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],qe=100,lt=null;function Lt(){if(lt!==null)return lt;try{let t=c.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(lt=!1,!1)}catch{return lt=!1,!1}}var Z=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,l;for(a=0;a<n;a++)o=i[a],h=o.method,h?(l=o.args,s+=h,t?s+=Xe:c._isArray(l[0])?s+=Ue+l.join(zt)+Ye:(e&&(l=l.map(d=>typeof d=="number"?Math.floor(d):d)),s+=Fe+l.join(zt)+Be)):(s+=o.property,t||(s+=Ve+o.val)),s+=We;return s}clearTrace(){this.traceArr=[]}_trace(t){let e=this.traceArr,i;e.push(t),i=e.length,i>=qe&&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,l){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,l)}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=$t.length,i=this.setAttr,n,s,a=function(o){let h=t[o],l;t[o]=function(){return s=He(Array.prototype.slice.call(arguments,0)),l=h.apply(t,arguments),t._trace({method:o,args:s}),l}};for(n=0;n<e;n++)a($t[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)}};Ke.forEach(function(r){Object.defineProperty(Z.prototype,r,{get(){return this._context[r]},set(t){this._context[r]=t}})});var ct=class extends Z{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(),l=this.canvas.getPixelRatio(),d=h.x*l,g=h.y*l;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)}},dt=class extends Z{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 ut;function je(){if(ut)return ut;let r=c.createCanvasElement(),t=r.getContext("2d");return ut=(function(){let e=p._global.devicePixelRatio||1,i=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return e/i})(),c.releaseCanvas(r),ut}var ft=class{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;let i=(t||{}).pixelRatio||p.pixelRatio||je();this.pixelRatio=i,this._canvas=c.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 c.error("Unable to get data URL. "+n.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},R=class extends ft{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new ct(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}},N=class extends ft{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new dt(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:c.warn(`CSS filter "${i}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var gt="absoluteOpacity",Jt="allEventListeners",G="absoluteTransform",Zt="absoluteScale",B="canvas",$e="Change",Je="children",Ze="konva",Dt="listening",Qe="mouseenter",ti="mouseleave",ei="pointerenter",ii="pointerleave",ni="touchenter",ri="touchleave";var Qt="set",te="Shape",pt=" ",ee="stage",H="transform",si="Stage",Gt="visible",ai=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(pt),oi=1,y=class r{constructor(t){this._id=oi++,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===G)&&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===G)&&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(pt);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===G&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(B)){let{scene:t,filter:e,hit:i}=this._cache.get(B);c.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,l=e.offset||0,d=e.drawBorder||!1,g=e.hitCanvasPixelRatio||1;if(!n||!s){c.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,v=Math.abs(Math.round(i.y)-h)>.5?1:0;n+=l*2+m,s+=l*2+v,o-=l,h-=l;let _=new R({pixelRatio:a,width:n,height:s}),x=new R({pixelRatio:a,width:0,height:0,willReadFrequently:!0}),w=new N({pixelRatio:g,width:n,height:s}),E=_.getContext(),k=w.getContext(),I=new R({width:_.width/_.pixelRatio+Math.abs(o),height:_.height/_.pixelRatio+Math.abs(h),pixelRatio:_.pixelRatio}),Wt=I.getContext();return w.isCache=!0,_.isCache=!0,this._cache.delete(B),this._filterUpToDate=!1,e.imageSmoothingEnabled===!1&&(_.getContext()._context.imageSmoothingEnabled=!1,x.getContext()._context.imageSmoothingEnabled=!1),E.save(),k.save(),Wt.save(),E.translate(-o,-h),k.translate(-o,-h),Wt.translate(-o,-h),I.x=o,I.y=h,this._isUnderCache=!0,this._clearSelfAndDescendantCache(gt),this._clearSelfAndDescendantCache(Zt),this.drawScene(_,this,I),this.drawHit(w,this),this._isUnderCache=!1,E.restore(),k.restore(),d&&(E.save(),E.beginPath(),E.rect(0,0,n,s),E.closePath(),E.setAttr("strokeStyle","red"),E.setAttr("lineWidth",5),E.stroke(),E.restore()),c.releaseCanvas(I._canvas),this._cache.set(B,{scene:_,filter:x,hit:w,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(l){let d=h.point(l);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,l;if(!t||t.length===0)return i;if(this._filterUpToDate)return n;let d=!0;for(let m=0;m<t.length;m++){let v=typeof t[m]=="string"&&!Lt();if(typeof t[m]!="string"||!Lt()){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++)l=t[h],typeof l=="string"&&(l=ze(l)),l.call(this,o),s.putImageData(o,0,0)}catch(m){c.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(pt);for(let a=0;a<s.length;a++){let h=s[a].split("."),l=h[0],d=h[1]||"";this.eventListeners[l]||(this.eventListeners[l]=[]),this.eventListeners[l].push({name:d,handler:i})}return this}off(t,e){let i=(t||"").split(pt),n=i.length,s,a,o,h,l,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("."),l=h[0],d=h[1],l)this.eventListeners[l]&&this._off(l,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=c.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(G),this._clearSelfAndDescendantCache(gt),this._clearSelfAndDescendantCache(Zt),this._clearSelfAndDescendantCache(ee),this._clearSelfAndDescendantCache(Gt),this._clearSelfAndDescendantCache(Dt)}_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"+c._capitalize(t);return c._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=Qt+c._capitalize(e),c._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(Dt,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(Gt,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!==te&&(n=n.concat(o.getChildren().slice())),o._id===e._id&&(a=s);n.length>0&&n[0].getDepth()<=t&&h(n)}let l=this.getStage();return e.nodeType!==si&&l&&h(l.getChildren()),i}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(H),this._clearSelfAndDescendantCache(G)),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 D,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(G),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 c.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 c.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 c.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 c.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 c.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&c.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(gt,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=c.isObject(i)&&!c._isPlainObject(i)&&!c._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 c._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],c.isValidSelector(s)||(c.warn('Selector "'+s+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),c.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),c.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(ee,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(G,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new D,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(G)||new D,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 D;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,l=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),(l!==0||d!==0)&&i.skew(l,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=c.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(Ze)<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 R({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(),l=new R({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,l),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,c._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+$e,{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[Qt+c._capitalize(t)];return c._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&&!c.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===te&&(e.target=this);let n=[Qe,ti,ei,ii,ni,ri];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:c.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 c.haveIntersection(i,this.getClientRect())}static create(t,e){return c._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]||(c.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(ai,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(H),this._clearSelfAndDescendantCache(G)});y.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(Gt)});y.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(Dt)});y.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache(gt)});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,A());S(y,"preventDefault",!0,A());S(y,"filters",void 0,function(r){return this._filterUpToDate=!1,r});S(y,"visible",!0,A());S(y,"transformsEnabled","all",M());S(y,"size");S(y,"dragBoundFunc");S(y,"draggable",!1,A());u.backCompat(y,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var T=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,l=s&&s.isCache;if(!this.isVisible()&&!l)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(),l=this.clipFunc(),d=typeof o=="number"&&typeof h=="number"||l,g=i===this;if(d){a.save();let v=this.getAbsoluteTransform(i),_=v.getMatrix();a.transform(_[0],_[1],_[2],_[3],_[4],_[5]),a.beginPath();let x;if(l)x=l.call(this,a,this);else{let w=this.clipX(),E=this.clipY();a.rect(w||0,E||0,o,h)}a.clip.apply(a,x),_=v.copy().invert().getMatrix(),a.transform(_[0],_[1],_[2],_[3],_[4],_[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(v){v[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,l={x:1/0,y:1/0,width:0,height:0},d=this;(e=this.children)===null||e===void 0||e.forEach(function(v){if(!v.visible())return;let _=v.getClientRect({relativeTo:d,skipShadow:t.skipShadow,skipStroke:t.skipStroke});_.width===0&&_.height===0||(s===void 0?(s=_.x,a=_.y,o=_.x+_.width,h=_.y+_.height):(s=Math.min(s,_.x),a=Math.min(a,_.y),o=Math.max(o,_.x+_.width),h=Math.max(h,_.y+_.height)))});let g=this.find("Shape"),m=!1;for(let v=0;v<g.length;v++)if(g[v]._isVisible(this)){m=!0;break}return m&&s!==void 0?l={x:s,y:a,width:o-s,height:h-a}:l={x:0,y:0,width:0,height:0},i?l:this._transformedRect(l,n)}};u.addComponentsGetterSetter(T,"clip",["x","y","width","height"]);u.addGetterSetter(T,"clipX",void 0,C());u.addGetterSetter(T,"clipY",void 0,C());u.addGetterSetter(T,"clipWidth",void 0,C());u.addGetterSetter(T,"clipHeight",void 0,C());u.addGetterSetter(T,"clipFunc");var Q=new Map,ie=p._global.PointerEvent!==void 0;function mt(r){return Q.get(r)}function vt(r){return{evt:r,pointerId:r.pointerId}}function _t(r,t){return Q.get(r)===t}function yt(r,t){U(r),t.getStage()&&(Q.set(r,t),ie&&t._fire("gotpointercapture",vt(new PointerEvent("gotpointercapture"))))}function U(r,t){let e=Q.get(r);if(!e)return;let i=e.getStage();i&&i.content,Q.delete(r),ie&&e._fire("lostpointercapture",vt(new PointerEvent("lostpointercapture")))}var hi="Stage",li="string",re="px",ci="mouseout",ae="mouseleave",oe="mouseover",he="mouseenter",le="mousemove",ce="mousedown",de="mouseup",tt="pointermove",et="pointerdown",X="pointerup",it="pointercancel",di="lostpointercapture",Ct="pointerout",nt="pointerleave",bt="pointerover",St="pointerenter",Ot="contextmenu",ue="touchstart",fe="touchend",ge="touchmove",pe="touchcancel",Mt="wheel",ui=5,fi=[[he,"_pointerenter"],[ce,"_pointerdown"],[le,"_pointermove"],[de,"_pointerup"],[ae,"_pointerleave"],[ue,"_pointerdown"],[ge,"_pointermove"],[fe,"_pointerup"],[pe,"_pointercancel"],[oe,"_pointerover"],[Mt,"_wheel"],[Ot,"_contextmenu"],[et,"_pointerdown"],[tt,"_pointermove"],[X,"_pointerup"],[it,"_pointercancel"],[nt,"_pointerleave"],[di,"_lostpointercapture"]],It={mouse:{[Ct]:ci,[nt]:ae,[bt]:oe,[St]:he,[tt]:le,[et]:ce,[X]:de,[it]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[Ct]:"touchout",[nt]:"touchleave",[bt]:"touchover",[St]:"touchenter",[tt]:ge,[et]:ue,[X]:fe,[it]:pe,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[Ct]:Ct,[nt]:nt,[bt]:bt,[St]:St,[tt]:tt,[et]:et,[X]:X,[it]:it,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},rt=r=>r.indexOf("pointer")>=0?"pointer":r.indexOf("touch")>=0?"touch":"mouse",W=r=>{let t=rt(r);if(t==="pointer")return p.pointerEventsEnabled&&It.pointer;if(t==="touch")return It.touch;if(t==="mouse")return It.mouse};function se(r={}){return(r.clipFunc||r.clipWidth||r.clipHeight)&&c.warn("Stage does not support clipping. Please use clip for Layers or Groups."),r}var gi="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=[],Y=class extends T{constructor(t){super(se(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",()=>{se(this.attrs)}),this._checkVisibility()}_validateAdd(t){let e=t.getType()==="Layer",i=t.getType()==="FastLayer";e||i||c.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===li){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"),T.prototype.clone.call(this,t)}destroy(){super.destroy();let t=this.content;t&&c._isInDocument(t)&&this.container().removeChild(t);let e=wt.indexOf(this);return e>-1&&wt.splice(e,1),c.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}:(c.warn(gi),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 R({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+re,this.content.style.height=e+re),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>ui&&c.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){U(t,this)}getLayers(){return this.children}_bindContentEvents(){p.isBrowser&&fi.forEach(([t,e])=>{this.content.addEventListener(t,i=>{this[e](i)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);let e=W(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);let e=W(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=W(t.type),i=rt(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=W(t.type),i=rt(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=W(t.type),i=rt(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(l=>{let d=mt(l.id)||this.getIntersection(l),g=l.id,m={evt:t,pointerId:g},v=h!==d;if(v&&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,v&&(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=W(t.type),i=rt(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 l=mt(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),a[l._id])return;a[l._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),l&&l.isListening()?(o=!0,this[i+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...g}),p["_"+i+"ListenClick"]&&n&&n===l&&(l._fireAndBubble(e.pointerclick,{...g}),m&&s&&s===l&&l._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(Ot,{evt:t}):this._fire(Ot,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);let e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Mt,{evt:t}):this._fire(Mt,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);let e=mt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(X,vt(t)),U(t.pointerId)}_lostpointercapture(t){U(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:c._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:n,id:c._getFirstPointerId(t)}])}_setPointerPosition(t){c.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 R({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 c.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}};Y.prototype.nodeType=hi;O(Y);u.addGetterSetter(Y,"container");p.isBrowser&&document.addEventListener("visibilitychange",()=>{wt.forEach(r=>{r.batchDraw()})});var me="hasShadow",ve="shadowRGBA",_e="patternImage",ye="linearGradient",Ce="radialGradient",xt;function Nt(){return xt||(xt=c.createCanvasElement().getContext("2d"),xt)}var st={};function pi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function mi(r){r.stroke()}function vi(r){let t=this.attrs.fillRule;t?r.fill(t):r.fill()}function _i(r){r.stroke()}function yi(){this._clearCache(me)}function Ci(){this._clearCache(ve)}function bi(){this._clearCache(_e)}function Si(){this._clearCache(ye)}function wi(){this._clearCache(Ce)}var f=class extends y{constructor(t){super(t);let e,i=0;for(;e=c.getHitColor(),!(e&&!(e in st));)if(i++,i>=1e4){c.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=c.getRandomColor();break}this.colorKey=e,st[e]=this}getContext(){return c.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return c.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(me,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(_e,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){let e=Nt().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){let i=new D;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(ye,this.__getLinearGradient)}__getLinearGradient(){let t=this.fillLinearGradientColorStops();if(t){let e=Nt(),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(Ce,this.__getRadialGradient)}__getRadialGradient(){let t=this.fillRadialGradientColorStops();if(t){let e=Nt(),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(ve,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;let t=c.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 st[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){c.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,l=a.width+h,d=a.height+h,g=!t.skipShadow&&this.hasShadow(),m=g?this.shadowOffsetX():0,v=g?this.shadowOffsetY():0,_=l+Math.abs(m),x=d+Math.abs(v),w=g&&this.shadowBlur()||0,E=_+w*2,k=x+w*2,I={width:E,height:k,x:-(h/2+w)+Math.min(m,0)+a.x,y:-(h/2+w)+Math.min(v,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(),l=this.hasShadow(),d,g=!1,m=e===this;if(!this.isVisible()&&!m)return this;if(o){a.save();let v=this.getAbsoluteTransform(e).getMatrix();return a.transform(v[0],v[1],v[2],v[3],v[4],v[5]),this._drawCachedSceneCanvas(a),a.restore(),this}if(!h)return this;if(a.save(),this._useBufferCanvas()&&!g){d=this.getStage();let v=i||d.bufferCanvas,_=v.getContext();i?(_.save(),_.setTransform(1,0,0,1,0,0),_.clearRect(0,0,v.width,v.height),_.restore()):_.clear(),_.save(),_._applyLineJoin(this),_._applyMiterLimit(this);let x=this.getAbsoluteTransform(e).getMatrix();_.transform(x[0],x[1],x[2],x[3],x[4],x[5]),h.call(this,_,this),_.restore();let w=v.pixelRatio;l&&a._applyShadow(this),m||(a._applyOpacity(this),a._applyGlobalCompositeOperation(this)),a.drawImage(v._canvas,v.x||0,v.y||0,v.width/w,v.height/w)}else{if(a._applyLineJoin(this),a._applyMiterLimit(this),!m){let v=this.getAbsoluteTransform(e).getMatrix();a.transform(v[0],v[1],v[2],v[3],v[4],v[5]),a._applyOpacity(this),a._applyGlobalCompositeOperation(this)}l&&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(),l=h&&h.hit;if(this.colorKey||c.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){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),l=h.data,d=l.length,g=c._hexToRgb(this.colorKey);for(let m=0;m<d;m+=4)l[m+3]>t?(l[m]=g.r,l[m+1]=g.g,l[m+2]=g.b,l[m+3]=255):l[m+3]=0;s.putImageData(h,0,0)}catch(h){c.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){U(t,this)}};f.prototype._fillFunc=pi;f.prototype._strokeFunc=mi;f.prototype._fillFuncHit=vi;f.prototype._strokeFuncHit=_i;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",yi);f.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",Ci);f.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",bi);f.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",Si);f.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",wi);u.addGetterSetter(f,"stroke",void 0,At());u.addGetterSetter(f,"strokeWidth",2,C());u.addGetterSetter(f,"fillAfterStrokeEnabled",!1);u.addGetterSetter(f,"hitStrokeWidth","auto",qt());u.addGetterSetter(f,"strokeHitEnabled",!0,A());u.addGetterSetter(f,"perfectDrawEnabled",!0,A());u.addGetterSetter(f,"shadowForStrokeEnabled",!0,A());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,At());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 xi="beforeDraw",Ei="draw",be=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],ki=be.length,L=class extends T{constructor(t){super(t),this.canvas=new R,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&&c._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"&&c.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(){c.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){c.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,c.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<ki;n++){let s=be[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=c.getHitColorKey(i[0],i[1],i[2]),a=st[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(xi,{node:this}),this.clearBeforeDraw()&&s.getContext().clear(),T.prototype.drawScene.call(this,s,e,i),this._fire(Ei,{node:this}),this}drawHit(t,e){let i=this.getLayer(),n=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),T.prototype.drawHit.call(this,n,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){c.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return c.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 c.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};L.prototype.nodeType="Layer";O(L);u.addGetterSetter(L,"imageSmoothingEnabled",!0);u.addGetterSetter(L,"clearBeforeDraw",!0);u.addGetterSetter(L,"hitGraphEnabled",!0,A());var P=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?c.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?c.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=c.createImageElement();n.onload=function(){let s=new r({image:n});e(s)},n.onerror=i,n.crossOrigin="Anonymous",n.src=t}};P.prototype.className="Image";P.prototype._attrsAffectingSize=["image"];O(P);u.addGetterSetter(P,"cornerRadius",0,Kt(4));u.addGetterSetter(P,"image");u.addComponentsGetterSetter(P,"crop",["x","y","width","height"]);u.addGetterSetter(P,"cropX",0,C());u.addGetterSetter(P,"cropY",0,C());u.addGetterSetter(P,"cropWidth",0,C());u.addGetterSetter(P,"cropHeight",0,C());function Ht(r,t){r.konvaNode.on("click",()=>{t()})}function at(r,t){r?t():window.addEventListener("scratch-engine-ready",t,{once:!0})}function Pi(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 Ft(r,t){let e=r.trim().toLowerCase(),i=Pi(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 Ti(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 Et=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=Ti(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 Ft=new Map;function Ti(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 Ri(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=Ft.get(e);if(i)return i;let n=r.dataFormat==="svg"?Ri(t):Ti(t);return Ft.set(e,n),n.catch(()=>Ft.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 Pt=class{constructor(t){this.queue=Promise.resolve();this.answer="";this.resolveCurrent=null;this.root=document.createElement("div"),Object.assign(this.root.style,{position:"absolute",inset:"0",zIndex:"10000",display:"none",alignItems:"flex-end",justifyContent:"center",padding:"12px",boxSizing:"border-box",pointerEvents:"none",fontFamily:"Arial, sans-serif"});let e=document.createElement("form");Object.assign(e.style,{display:"flex",alignItems:"center",gap:"8px",width:"100%",maxWidth:"440px",padding:"10px",borderRadius:"8px",background:"#ffffff",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.25)",pointerEvents:"auto"}),this.question=document.createElement("div"),Object.assign(this.question.style,{flex:"0 1 auto",overflowWrap:"anywhere",fontSize:"14px",color:"#222"}),this.input=document.createElement("input"),this.input.type="text",this.input.setAttribute("aria-label","Your answer"),Object.assign(this.input.style,{flex:"1 1 auto",minWidth:"0",padding:"7px 9px",border:"1px solid #aaa",borderRadius:"5px",font:"inherit"});let i=document.createElement("button");i.type="submit",i.textContent="OK",Object.assign(i.style,{padding:"7px 12px",border:"0",borderRadius:"5px",background:"#4c97ff",color:"#fff",font:"inherit",cursor:"pointer"}),e.append(this.question,this.input,i),this.root.appendChild(e),t.appendChild(this.root),e.addEventListener("submit",n=>{n.preventDefault(),this.answer=this.input.value,this.root.style.display="none",this.resolveCurrent?.(this.answer),this.resolveCurrent=null})}askAndWait(t){return new Promise(e=>{this.queue=this.queue.then(()=>new Promise(i=>{this.question.textContent=t,this.input.value="",this.resolveCurrent=n=>{e(n),i()},this.root.style.display="flex",this.input.focus()}))})}};var Bt=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 W({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.askAndWaitComponent=new Pt(i),this.backdropLayer=new D,this.spriteLayer=new D,this.konvaStage.add(this.backdropLayer),this.konvaStage.add(this.spriteLayer),this.backdropImage=new P({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)}askAndWait(t){return this.askAndWaitComponent.askAndWait(t)}get answer(){return this.askAndWaitComponent.answer}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,l=i/2,d=h-a,g=l-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)}};function Ai(r){if(!CSS.supports("color",r))return null;let t=document.createElement("canvas");t.width=1,t.height=1;let e=t.getContext("2d",{willReadFrequently:!0});if(!e)return null;e.fillStyle=r,e.fillRect(0,0,1,1);let[i,n,s]=e.getImageData(0,0,1,1).data;return[i,n,s]}var Yt=class{constructor(t){this.images=[];this.isReady=!1;this.data=t,this.konvaNode=new P({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"?Nt(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"?Ht(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,l=n.bitmapResolution??1,d=480/2+s,g=360/2-a,m=(n.rotationCenterX??i.width/2)/l,_=(n.rotationCenterY??i.height/2)/l,v=i.width/l,x=i.height/l;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)}isTouchingColor(t){if(!this.stage||!this.data.visible||!this.isReady)return!1;let e=Ai(t);if(!e)return!1;let i=this.stage.logicalWidth,n=this.stage.logicalHeight,s=this.konvaNode.getClientRect(),a=Math.max(0,Math.floor(s.x)),o=Math.max(0,Math.floor(s.y)),h=Math.min(i,Math.ceil(s.x+s.width)),l=Math.min(n,Math.ceil(s.y+s.height));if(h<=a||l<=o)return!1;let d={x:a,y:o,width:h-a,height:l-o,pixelRatio:1},g=this.konvaNode.visible(),m;this.konvaNode.visible(!1);try{m=this.stage.konvaStage.toCanvas(d)}finally{this.konvaNode.visible(g)}let _=this.konvaNode.toCanvas(d),v=m.getContext("2d",{willReadFrequently:!0}),x=_.getContext("2d",{willReadFrequently:!0});if(!v||!x)return!1;let S=v.getImageData(0,0,d.width,d.height).data,E=x.getImageData(0,0,d.width,d.height).data;for(let k=0;k<S.length;k+=4)if(E[k+3]>0&&S[k+3]>0&&S[k]===e[0]&&S[k+1]===e[1]&&S[k+2]===e[2])return!0;return!1}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{Yt as Sprite,Bt as Stage};
|
|
16
|
+
`)}`:i.textContent=`${t}: ${String(e)}`,this.layout()}};var Bt=new Map;function Ri(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 Ai(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 kt(r){let t="./assets/"+r.md5ext,e=`${r.assetId}:${r.dataFormat}`,i=Bt.get(e);if(i)return i;let n=r.dataFormat==="svg"?Ai(t):Ri(t);return Bt.set(e,n),n.catch(()=>Bt.delete(e)),n}var Pt=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 Tt=class{constructor(t){this.queue=Promise.resolve();this.answer="";this.resolveCurrent=null;this.root=document.createElement("div"),Object.assign(this.root.style,{position:"absolute",inset:"0",zIndex:"10000",display:"none",alignItems:"flex-end",justifyContent:"center",padding:"12px",boxSizing:"border-box",pointerEvents:"none",fontFamily:"Arial, sans-serif"});let e=document.createElement("form");Object.assign(e.style,{display:"flex",alignItems:"center",gap:"8px",width:"100%",maxWidth:"440px",padding:"10px",borderRadius:"8px",background:"#ffffff",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.25)",pointerEvents:"auto"}),this.question=document.createElement("div"),Object.assign(this.question.style,{flex:"0 1 auto",overflowWrap:"anywhere",fontSize:"14px",color:"#222"}),this.input=document.createElement("input"),this.input.type="text",this.input.setAttribute("aria-label","Your answer"),Object.assign(this.input.style,{flex:"1 1 auto",minWidth:"0",padding:"7px 9px",border:"1px solid #aaa",borderRadius:"5px",font:"inherit"});let i=document.createElement("button");i.type="submit",i.textContent="OK",Object.assign(i.style,{padding:"7px 12px",border:"0",borderRadius:"5px",background:"#4c97ff",color:"#fff",font:"inherit",cursor:"pointer"}),e.append(this.question,this.input,i),this.root.appendChild(e),t.appendChild(this.root),e.addEventListener("submit",n=>{n.preventDefault(),this.answer=this.input.value,this.root.style.display="none",this.resolveCurrent?.(this.answer),this.resolveCurrent=null})}askAndWait(t){return new Promise(e=>{this.queue=this.queue.then(()=>new Promise(i=>{this.question.textContent=t,this.input.value="",this.resolveCurrent=n=>{e(n),i()},this.root.style.display="flex",this.input.focus()}))})}};var V=class{constructor(t){this.data=t;this.active=new Map;this.volume=typeof t.volume=="number"?Math.max(0,Math.min(100,t.volume)):100}setVolume(t){if(Number.isFinite(t)){this.volume=Math.max(0,Math.min(100,t)),this.data.volume=this.volume;for(let{audio:e}of this.active.values())e.volume=this.volume/100}}play(t){let e=this.data.sounds?.find(s=>s.name===t||s.assetId===t);if(!e)return console.warn(`[Sound] Sound "${t}" does not exist`),Promise.resolve();let i=this.active.get(e);i&&(i.audio.pause(),i.finish());let n=new Audio(`./assets/${e.md5ext}`);return n.volume=this.volume/100,new Promise(s=>{let a=()=>{this.active.get(e)?.audio===n&&(this.active.delete(e),n.removeEventListener("ended",a),n.removeEventListener("error",a),s())};this.active.set(e,{audio:n,finish:a}),n.addEventListener("ended",a),n.addEventListener("error",a),n.play().catch(o=>{this.active.get(e)?.audio===n&&(console.warn("[Sound] Unable to play sound",o),a())})})}};var Ut=class{constructor(t,e){this.sprites=[];this.eventBus=new Pt;if(!t.isStage)throw new Error("Please pass a stage not sprite");this.stage=t,this.soundPlayer=new V(t),this.currentCostume=t.costumes[t.currentCostume??0],this.logicalWidth=480,this.logicalHeight=360,this.konvaStage=new Y({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 Et(i),this.askAndWaitComponent=new Tt(i),this.backdropLayer=new L,this.spriteLayer=new L,this.konvaStage.add(this.backdropLayer),this.konvaStage.add(this.spriteLayer),this.backdropImage=new P({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)}askAndWait(t){return this.askAndWaitComponent.askAndWait(t)}get answer(){return this.askAndWaitComponent.answer}draw(){this.currentCostume&&kt(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,l=i/2,d=h-a,g=l-o,m=t.width/s,v=t.height/s;this.backdropImage.setAttrs({image:t,x:d,y:g,width:m,height:v}),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()}setVolume(t){this.soundPlayer.setVolume(t)}playSound(t){return this.soundPlayer.play(t)}playSoundUntilDone(t){return this.soundPlayer.play(t)}on(t,...e){switch(t){case"flag":typeof e[0]=="function"?at(!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)}};function Li(r){if(!CSS.supports("color",r))return null;let t=document.createElement("canvas");t.width=1,t.height=1;let e=t.getContext("2d",{willReadFrequently:!0});if(!e)return null;e.fillStyle=r,e.fillRect(0,0,1,1);let[i,n,s]=e.getImageData(0,0,1,1).data;return[i,n,s]}var Yt=class{constructor(t){this.images=[];this.isReady=!1;this.data=t,this.soundPlayer=new V(t),this.konvaNode=new P({name:t.name,image:new Image});let e=this.data.costumes.map((i,n)=>kt(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"?Ht(this,e):console.warn("[Sprite] Callback must be provided for 'click' event");break;case"flag":typeof e=="function"?at(!0,e):console.warn("[Sprite] Callback must be provided for 'flag' event");break;case"keypress":typeof e=="string"&&typeof i=="function"?Ft(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,l=n.bitmapResolution??1,d=480/2+s,g=360/2-a,m=(n.rotationCenterX??i.width/2)/l,v=(n.rotationCenterY??i.height/2)/l,_=i.width/l,x=i.height/l;this.konvaNode.setAttrs({image:i,x:d,y:g,width:_,height:x,rotation:o-90,scaleX:h/100,scaleY:h/100,offsetX:m,offsetY:v,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)}isTouchingColor(t){if(!this.stage||!this.data.visible||!this.isReady)return!1;let e=Li(t);if(!e)return!1;let i=this.stage.logicalWidth,n=this.stage.logicalHeight,s=this.konvaNode.getClientRect(),a=Math.max(0,Math.floor(s.x)),o=Math.max(0,Math.floor(s.y)),h=Math.min(i,Math.ceil(s.x+s.width)),l=Math.min(n,Math.ceil(s.y+s.height));if(h<=a||l<=o)return!1;let d={x:a,y:o,width:h-a,height:l-o,pixelRatio:1},g=this.konvaNode.visible(),m;this.konvaNode.visible(!1);try{m=this.stage.konvaStage.toCanvas(d)}finally{this.konvaNode.visible(g)}let v=this.konvaNode.toCanvas(d),_=m.getContext("2d",{willReadFrequently:!0}),x=v.getContext("2d",{willReadFrequently:!0});if(!_||!x)return!1;let w=_.getImageData(0,0,d.width,d.height).data,E=x.getImageData(0,0,d.width,d.height).data;for(let k=0;k<w.length;k+=4)if(E[k+3]>0&&w[k+3]>0&&w[k]===e[0]&&w[k+1]===e[1]&&w[k+2]===e[2])return!0;return!1}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)}setVolume(t){this.soundPlayer.setVolume(t)}playSound(t){return this.soundPlayer.play(t)}playSoundUntilDone(t){return this.soundPlayer.play(t)}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{Yt as Sprite,Ut as Stage};
|
|
17
17
|
//# sourceMappingURL=index.js.map
|