mudlet-map-browser-script 0.1.0 → 0.2.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/README.md +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +29 -29
- package/dist/assets/index-DN84wJBG.js +0 -2
- package/dist/assets/index-DN84wJBG.js.map +0 -1
- package/dist/embedded.min.js +0 -2
- package/dist/embedded.min.js.map +0 -1
- package/dist/mobile.min.js +0 -2
- package/dist/mobile.min.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const t=Math.PI/180;const e="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},i={_global:e,version:"10.0.2",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:e=>i.angleDeg?e*t:e,enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>i.DD.isDragging,isTransforming(){var t,e;return null!==(e=null===(t=i.Transformer)||void 0===t?void 0:t.isTransforming())&&void 0!==e&&e},isDragReady:()=>!!i.DD.node,releaseCanvasOnDestroy:!0,document:e.document,_injectGlobal(t){void 0!==e.Konva&&console.error("Severa Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),e.Konva=t}},s=t=>{i[t.prototype.getClassName()]=t};i._injectGlobal(i);const n=()=>{if("undefined"==typeof document)throw new Error('Konva.js unsupported environment.\n\nLooks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.\n\nTo use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module.\n\nbash: npm install canvas\njs: import "konva/canvas-backend";\n\nor\n\nbash: npm install skia-canvas\njs: import "konva/skia-backend";\n')};class 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){const e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.m[0]*e+this.m[2]*i,n=this.m[1]*e+this.m[3]*i,r=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=s,this.m[1]=n,this.m[2]=r,this.m[3]=o,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){const i=this.m[0]+this.m[2]*e,s=this.m[1]+this.m[3]*e,n=this.m[2]+this.m[0]*t,r=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=n,this.m[3]=r,this}multiply(t){const e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],s=this.m[0]*t.m[2]+this.m[2]*t.m[3],n=this.m[1]*t.m[2]+this.m[3]*t.m[3],r=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],o=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=n,this.m[4]=r,this.m[5]=o,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,s=-this.m[2]*t,n=this.m[0]*t,r=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),o=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=n,this.m[4]=r,this.m[5]=o,this}getMatrix(){return this.m}decompose(){const t=this.m[0],e=this.m[1],i=this.m[2],s=this.m[3],n=t*s-e*i,r={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){const o=Math.sqrt(t*t+e*e);r.rotation=e>0?Math.acos(t/o):-Math.acos(t/o),r.scaleX=o,r.scaleY=n/o,r.skewX=(t*i+e*s)/n,r.skewY=0}else if(0!=i||0!=s){const o=Math.sqrt(i*i+s*s);r.rotation=Math.PI/2-(s>0?Math.acos(-i/o):-Math.acos(i/o)),r.scaleX=n/o,r.scaleY=o,r.skewX=0,r.skewY=(t*i+e*s)/n}return r.rotation=u._getRotation(r.rotation),r}}const o=Math.PI/180,a=180/Math.PI,h="Konva error: ",l={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]},d=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let c=[];const g="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},u={_isElement:t=>!(!t||1!=t.nodeType),_isFunction:t=>!!(t&&t.constructor&&t.call&&t.apply),_isPlainObject:t=>!!t&&t.constructor===Object,_isArray:t=>"[object Array]"===Object.prototype.toString.call(t),_isNumber:t=>"[object Number]"===Object.prototype.toString.call(t)&&!isNaN(t)&&isFinite(t),_isString:t=>"[object String]"===Object.prototype.toString.call(t),_isBoolean:t=>"[object Boolean]"===Object.prototype.toString.call(t),isObject:t=>t instanceof Object,isValidSelector(t){if("string"!=typeof t)return!1;const e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},_sign:t=>0===t||t>0?1:-1,requestAnimFrame(t){c.push(t),1===c.length&&g(function(){const t=c;c=[],t.forEach(function(t){t()})})},createCanvasElement(){n();const t=document.createElement("canvas");try{t.style=t.style||{}}catch(e){}return t},createImageElement:()=>(n(),document.createElement("img")),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){const i=u.createImageElement();i.onload=function(){e(i)},i.src=t},_rgbToHex:(t,e,i)=>((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1),_hexToRgb(t){t=t.replace("#","");const e=parseInt(t,16);return{r:e>>16&255,g:e>>8&255,b:255&e}},getRandomColor(){let t=(16777215*Math.random()|0).toString(16);for(;t.length<6;)t="0"+t;return"#"+t},getRGB(t){let e;return t in l?(e=l[t],{r:e[0],g:e[1],b:e[2]}):"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=d.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:t=>(t=t||"black",u._namedColorToRBA(t)||u._hex3ColorToRGBA(t)||u._hex4ColorToRGBA(t)||u._hex6ColorToRGBA(t)||u._hex8ColorToRGBA(t)||u._rgbColorToRGBA(t)||u._rgbaColorToRGBA(t)||u._hslColorToRGBA(t)),_namedColorToRBA(t){const e=l[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA(t){if(0===t.indexOf("rgb(")){const e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA(t){if(0===t.indexOf("rgba(")){const e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map((t,e)=>"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){const[e,...i]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),s=Number(i[0])/360,n=Number(i[1])/100,r=Number(i[2])/100;let o,a,h;if(0===n)return h=255*r,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};o=r<.5?r*(1+n):r+n-r*n;const l=2*r-o,d=[0,0,0];for(let t=0;t<3;t++)a=s+1/3*-(t-1),a<0&&a++,a>1&&a--,h=6*a<1?l+6*(o-l)*a:2*a<1?o:3*a<2?l+(o-l)*(2/3-a)*6:l,d[t]=255*h;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[2]),a:1}}},haveIntersection:(t,e)=>!(e.x>t.x+t.width||e.x+e.width<t.x||e.y>t.y+t.height||e.y+e.height<t.y),cloneObject(t){const e={};for(const i in t)this._isPlainObject(t[i])?e[i]=this.cloneObject(t[i]):this._isArray(t[i])?e[i]=this.cloneArray(t[i]):e[i]=t[i];return e},cloneArray:t=>t.slice(0),degToRad:t=>t*o,radToDeg:t=>t*a,_degToRad:t=>(u.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),u.degToRad(t)),_radToDeg:t=>(u.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),u.radToDeg(t)),_getRotation:t=>i.angleDeg?u.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(h+t)},error(t){console.error(h+t)},warn(t){i.showWarnings&&console.warn("Konva warning: "+t)},each(t,e){for(const i in t)e(i,t[i])},_inRange:(t,e,i)=>e<=t&&t<i,_getProjectionToSegment(t,e,i,s,n,r){let o,a,h;const l=(t-i)*(t-i)+(e-s)*(e-s);if(0==l)o=t,a=e,h=(n-i)*(n-i)+(r-s)*(r-s);else{const d=((n-t)*(i-t)+(r-e)*(s-e))/l;d<0?(o=t,a=e,h=(t-n)*(t-n)+(e-r)*(e-r)):d>1?(o=i,a=s,h=(i-n)*(i-n)+(s-r)*(s-r)):(o=t+d*(i-t),a=e+d*(s-e),h=(o-n)*(o-n)+(a-r)*(a-r))}return[o,a,h]},_getProjectionToLine(t,e,i){const s=u.cloneObject(t);let n=Number.MAX_VALUE;return e.forEach(function(r,o){if(!i&&o===e.length-1)return;const a=e[(o+1)%e.length],h=u._getProjectionToSegment(r.x,r.y,a.x,a.y,t.x,t.y),l=h[0],d=h[1],c=h[2];c<n&&(s.x=l,s.y=d,n=c)}),s},_prepareArrayForTween(t,e,i){const s=[],n=[];if(t.length>e.length){const i=e;e=t,t=i}for(let o=0;o<t.length;o+=2)s.push({x:t[o],y:t[o+1]});for(let o=0;o<e.length;o+=2)n.push({x:e[o],y:e[o+1]});const r=[];return n.forEach(function(t){const e=u._getProjectionToLine(t,s,i);r.push(e.x),r.push(e.y)}),r},_prepareToStringify(t){let e;t.visitedByCircularReferenceRemoval=!0;for(const i in t)if(t.hasOwnProperty(i)&&t[i]&&"object"==typeof t[i])if(e=Object.getOwnPropertyDescriptor(t,i),t[i].visitedByCircularReferenceRemoval||u._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===u._prepareToStringify(t[i])){if(!e.configurable)return null;delete t[i]}return delete t.visitedByCircularReferenceRemoval,t},_assign(t,e){for(const i in e)t[i]=e[i];return t},_getFirstPointerId:t=>t.touches?t.changedTouches[0].identifier:t.pointerId||999,releaseCanvas(...t){i.releaseCanvasOnDestroy&&t.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(t,e,i,s){let n=e<0?e:0,r=i<0?i:0;e=Math.abs(e),i=Math.abs(i);let o=0,a=0,h=0,l=0;"number"==typeof s?o=a=h=l=Math.min(s,e/2,i/2):(o=Math.min(s[0]||0,e/2,i/2),a=Math.min(s[1]||0,e/2,i/2),l=Math.min(s[2]||0,e/2,i/2),h=Math.min(s[3]||0,e/2,i/2)),t.moveTo(n+o,r),t.lineTo(n+e-a,r),t.arc(n+e-a,r+a,a,3*Math.PI/2,0,!1),t.lineTo(n+e,r+i-l),t.arc(n+e-l,r+i-l,l,0,Math.PI/2,!1),t.lineTo(n+h,r+i),t.arc(n+h,r+i-h,h,Math.PI/2,Math.PI,!1),t.lineTo(n,r+o),t.arc(n+o,r+o,o,Math.PI,3*Math.PI/2,!1)},drawRoundedPolygonPath(t,e,i,s,n){s=Math.abs(s);for(let r=0;r<i;r++){const o=e[(r-1+i)%i],a=e[r],h=e[(r+1)%i],l={x:a.x-o.x,y:a.y-o.y},d={x:h.x-a.x,y:h.y-a.y},c=Math.hypot(l.x,l.y),g=Math.hypot(d.x,d.y);let u;u="number"==typeof n?n:r<n.length?n[r]:0;u=s*Math.cos(Math.PI/i)*Math.min(1,u/s*2);const f={x:l.x/c,y:l.y/c},p={x:d.x/g,y:d.y/g},m={x:a.x-f.x*u,y:a.y-f.y*u},y={x:a.x+p.x*u,y:a.y+p.y*u};0===r?t.moveTo(m.x,m.y):t.lineTo(m.x,m.y),t.arcTo(a.x,a.y,y.x,y.y,u)}}};const f=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","roundRect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"];let p,m=null;function y(){if(null!==m)return m;try{const t=u.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(m=!1,!1)}catch(t){return m=!1,!1}}class x{constructor(t){this.canvas=t,i.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i,s,n,r,o=this.traceArr,a=o.length,h="";for(i=0;i<a;i++)s=o[i],n=s.method,n?(r=s.args,h+=n,t?h+="()":u._isArray(r[0])?h+="(["+r.join(",")+"])":(e&&(r=r.map(t=>"number"==typeof t?Math.floor(t):t)),h+="("+r.join(",")+")")):(h+=s.property,t||(h+="="+s.val)),h+=";";return h}clearTrace(){this.traceArr=[]}_trace(t){let e,i=this.traceArr;i.push(t),e=i.length,e>=100&&i.shift()}reset(){const t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){const e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){const e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){const e=t.attrs.miterLimit;null!=e&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,n,r){this._context.arc(t,e,i,s,n,r)}arcTo(t,e,i,s,n){this._context.arcTo(t,e,i,s,n)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,n,r){this._context.bezierCurveTo(t,e,i,s,n,r)}clearRect(t,e,i,s){this._context.clearRect(t,e,i,s)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){const i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}createLinearGradient(t,e,i,s){return this._context.createLinearGradient(t,e,i,s)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,s,n,r){return this._context.createRadialGradient(t,e,i,s,n,r)}drawImage(t,e,i,s,n,r,o,a,h){const l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,s,n):9===l.length&&d.drawImage(t,e,i,s,n,r,o,a,h)}ellipse(t,e,i,s,n,r,o,a){this._context.ellipse(t,e,i,s,n,r,o,a)}isPointInPath(t,e,i,s){return i?this._context.isPointInPath(i,t,e,s):this._context.isPointInPath(t,e,s)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,s){this._context.fillRect(t,e,i,s)}strokeRect(t,e,i,s){this._context.strokeRect(t,e,i,s)}fillText(t,e,i,s){s?this._context.fillText(t,e,i,s):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,s){return this._context.getImageData(t,e,i,s)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,s){this._context.rect(t,e,i,s)}roundRect(t,e,i,s,n){this._context.roundRect(t,e,i,s,n)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,s){this._context.quadraticCurveTo(t,e,i,s)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,s,n,r){this._context.setTransform(t,e,i,s,n,r)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,s){this._context.strokeText(t,e,i,s)}transform(t,e,i,s,n,r){this._context.transform(t,e,i,s,n,r)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t,e,i=this,s=f.length,n=this.setAttr;const r=function(t){let s,n=i[t];i[t]=function(){return e=function(t){const e=[],i=t.length,s=u;for(let n=0;n<i;n++){let i=t[n];s._isNumber(i)?i=Math.round(1e3*i)/1e3:s._isString(i)||(i+=""),e.push(i)}return e}(Array.prototype.slice.call(arguments,0)),s=n.apply(i,arguments),i._trace({method:t,args:e}),s}};for(t=0;t<s;t++)r(f[t]);i.setAttr=function(){n.apply(i,arguments);const t=arguments[0];let e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),i._trace({property:t,val:e})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||"source-over"===e||this.setAttr("globalCompositeOperation",e)}}["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"].forEach(function(t){Object.defineProperty(x.prototype,t,{get(){return this._context[t]},set(e){this._context[t]=e}})});class v extends x{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){const e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){const e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){const e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){const e=t.fill(),i=t.getFillPriority();if(e&&"color"===i)return void this._fillColor(t);const s=t.getFillPatternImage();if(s&&"pattern"===i)return void this._fillPattern(t);const n=t.getFillLinearGradientColorStops();if(n&&"linear-gradient"===i)return void this._fillLinearGradient(t);const r=t.getFillRadialGradientColorStops();r&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):s?this._fillPattern(t):n?this._fillLinearGradient(t):r&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),n=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let t=0;t<s.length;t+=2)n.addColorStop(s[t],s[t+1]);this.setAttr("strokeStyle",n)}}_stroke(t){const e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();const t=this.getCanvas().getPixelRatio();this.setTransform(t,0,0,t,0,0)}this._applyLineCap(t),e&&t.dashEnabled()&&(this.setLineDash(e),this.setAttr("lineDashOffset",t.dashOffset())),this.setAttr("lineWidth",t.strokeWidth()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)");t.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(t):this.setAttr("strokeStyle",t.stroke()),t._strokeFunc(this),i||this.restore()}}_applyShadow(t){var e,i,s;const n=null!==(e=t.getShadowRGBA())&&void 0!==e?e:"black",r=null!==(i=t.getShadowBlur())&&void 0!==i?i:5,o=null!==(s=t.getShadowOffset())&&void 0!==s?s:{x:0,y:0},a=t.getAbsoluteScale(),h=this.canvas.getPixelRatio(),l=a.x*h,d=a.y*h;this.setAttr("shadowColor",n),this.setAttr("shadowBlur",r*Math.min(Math.abs(l),Math.abs(d))),this.setAttr("shadowOffsetX",o.x*l),this.setAttr("shadowOffsetY",o.y*d)}}class b extends x{constructor(t){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:!0})}_fill(t){this.save(),this.setAttr("fillStyle",t.colorKey),t._fillFuncHit(this),this.restore()}strokeShape(t){t.hasHitStroke()&&this._stroke(t)}_stroke(t){if(t.hasHitStroke()){const e=t.getStrokeScaleEnabled();if(!e){this.save();const t=this.getCanvas().getPixelRatio();this.setTransform(t,0,0,t,0,0)}this._applyLineCap(t);const i=t.hitStrokeWidth(),s="auto"===i?t.strokeWidth():i;this.setAttr("lineWidth",s),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}}class _{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const e=(t||{}).pixelRatio||i.pixelRatio||function(){if(p)return p;const t=u.createCanvasElement(),e=t.getContext("2d");return p=(i._global.devicePixelRatio||1)/(e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1),u.releaseCanvas(t),p}();this.pixelRatio=e,this._canvas=u.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(t){const e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)}setWidth(t){this.width=this._canvas.width=t*this.pixelRatio,this._canvas.style.width=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}setHeight(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch(i){try{return this._canvas.toDataURL()}catch(s){return u.error("Unable to get data URL. "+s.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class w extends _{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new v(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}function S(){const t=u.createCanvasElement();t.width=1,t.height=1;const e=t.getContext("2d",{willReadFrequently:!0});e.clearRect(0,0,1,1),e.fillStyle="rgba(255,0,255,1)",e.fillRect(0,0,1,1);const i=e.getImageData(0,0,1,1).data;return!(255===i[0]&&0===i[1]&&255===i[2]&&255===i[3])}function C(){var t,e;return"undefined"!=typeof navigator&&(null!==(e=null===(t=navigator.brave)||void 0===t?void 0:t.isBrave())&&void 0!==e&&e)}let k=!1;class R extends _{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new b(this),this.setSize(t.width,t.height),C()&&S()&&!k&&(k=!0,u.error('Looks like you have "Brave shield" enabled in your browser. It breaks KonvaJS internals. Please disable it. You may need to ask your users to do the same.')),C()&&S()}}const E={get isDragging(){let t=!1;return E._dragElements.forEach(e=>{"dragging"===e.dragStatus&&(t=!0)}),t},justDragged:!1,get node(){let t;return E._dragElements.forEach(e=>{t=e.node}),t},_dragElements:new Map,_drag(t){const e=[];E._dragElements.forEach((i,s)=>{const{node:n}=i,r=n.getStage();r.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=u._getFirstPointerId(t));const o=r._changedPointerPositions.find(t=>t.id===i.pointerId);if(o){if("dragging"!==i.dragStatus){const e=n.dragDistance();if(Math.max(Math.abs(o.x-i.startPointerPos.x),Math.abs(o.y-i.startPointerPos.y))<e)return;if(n.startDrag({evt:t}),!n.isDragging())return}n._setDragPosition(t,i),e.push(n)}}),e.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)})},_endDragBefore(t){const e=[];E._dragElements.forEach(s=>{const{node:n}=s,r=n.getStage();t&&r.setPointersPositions(t);if(!r._changedPointerPositions.find(t=>t.id===s.pointerId))return;"dragging"!==s.dragStatus&&"stopped"!==s.dragStatus||(E.justDragged=!0,i._mouseListenClick=!1,i._touchListenClick=!1,i._pointerListenClick=!1,s.dragStatus="stopped");const o=s.node.getLayer()||s.node instanceof i.Stage&&s.node;o&&-1===e.indexOf(o)&&e.push(o)}),e.forEach(t=>{t.draw()})},_endDragAfter(t){E._dragElements.forEach((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&E._dragElements.delete(i)})}};function M(t){return u._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||u._isBoolean(t)?t:Object.prototype.toString.call(t)}function P(t){return t>255?255:t<0?0:Math.round(t)}function A(){if(i.isUnminified)return function(t,e){return u._isNumber(t)||u.warn(M(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function T(t){if(i.isUnminified)return function(e,i){let s=u._isNumber(e),n=u._isArray(e)&&e.length==t;return s||n||u.warn(M(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array<number>('+t+")"),e}}function L(){if(i.isUnminified)return function(t,e){return u._isNumber(t)||"auto"===t||u.warn(M(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function D(){if(i.isUnminified)return function(t,e){return u._isString(t)||u.warn(M(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function I(){if(i.isUnminified)return function(t,e){const i=u._isString(t),s="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||s||u.warn(M(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function G(){if(i.isUnminified)return function(t,e){return!0===t||!1===t||u.warn(M(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}i.isBrowser&&(window.addEventListener("mouseup",E._endDragBefore,!0),window.addEventListener("touchend",E._endDragBefore,!0),window.addEventListener("touchcancel",E._endDragBefore,!0),window.addEventListener("mousemove",E._drag),window.addEventListener("touchmove",E._drag),window.addEventListener("mouseup",E._endDragAfter,!1),window.addEventListener("touchend",E._endDragAfter,!1),window.addEventListener("touchcancel",E._endDragAfter,!1));const O="get",z="set",B={addGetterSetter(t,e,i,s,n){B.addGetter(t,e,i),B.addSetter(t,e,s,n),B.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){const s=O+u._capitalize(e);t.prototype[s]=t.prototype[s]||function(){const t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,s){const n=z+u._capitalize(e);t.prototype[n]||B.overWriteSetter(t,e,i,s)},overWriteSetter(t,e,i,s){const n=z+u._capitalize(e);t.prototype[n]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),s&&s.call(this),this}},addComponentsGetterSetter(t,e,s,n,r){const o=s.length,a=u._capitalize,h=O+a(e),l=z+a(e);t.prototype[h]=function(){const t={};for(let i=0;i<o;i++){const n=s[i];t[n]=this.getAttr(e+a(n))}return t};const d=function(t){if(i.isUnminified)return function(e,i){return null==e||u.isObject(e)||u.warn(M(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}}(s);t.prototype[l]=function(t){const i=this.attrs[e];n&&(t=n.call(this,t,e)),d&&d.call(this,t,e);for(const s in t)t.hasOwnProperty(s)&&this._setAttr(e+a(s),t[s]);return t||s.forEach(t=>{this._setAttr(e+a(t),void 0)}),this._fireChangeEvent(e,i,t),r&&r.call(this),this},B.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){const i=u._capitalize(e),s=z+i,n=O+i;t.prototype[e]=function(){return arguments.length?(this[s](arguments[0]),this):this[n]()}},addDeprecatedGetterSetter(t,e,i,s){u.error("Adding deprecated "+e);const n=O+u._capitalize(e),r=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[n]=function(){u.error(r);const t=this.attrs[e];return void 0===t?i:t},B.addSetter(t,e,s,function(){u.error(r)}),B.addOverloadedGetterSetter(t,e)},backCompat(t,e){u.each(e,function(e,i){const s=t.prototype[i],n=O+u._capitalize(e),r=z+u._capitalize(e);function o(){s.apply(this,arguments),u.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=o,t.prototype[n]=o,t.prototype[r]=o})},afterSetFilter(){this._filterUpToDate=!1}};function F(t){const e=/(\w+)\(([^)]+)\)/g;let s;for(;null!==(s=e.exec(t));){const[,t,e]=s;switch(t){case"blur":{const t=parseFloat(e.replace("px",""));return function(e){this.blurRadius(.5*t);const s=i.Filters;s&&s.Blur&&s.Blur.call(this,e)}}case"brightness":{const t=e.includes("%")?parseFloat(e)/100:parseFloat(e);return function(e){this.brightness(t);const s=i.Filters;s&&s.Brightness&&s.Brightness.call(this,e)}}case"contrast":{const t=parseFloat(e);return function(e){const s=100*(Math.sqrt(t)-1);this.contrast(s);const n=i.Filters;n&&n.Contrast&&n.Contrast.call(this,e)}}case"grayscale":return function(t){const e=i.Filters;e&&e.Grayscale&&e.Grayscale.call(this,t)};case"sepia":return function(t){const e=i.Filters;e&&e.Sepia&&e.Sepia.call(this,t)};case"invert":return function(t){const e=i.Filters;e&&e.Invert&&e.Invert.call(this,t)};default:u.warn(`CSS filter "${t}" is not supported in fallback mode. Consider using function filters for better compatibility.`)}}return()=>{}}const N="absoluteOpacity",W="allEventListeners",$="absoluteTransform",Y="absoluteScale",X="canvas",H="listening",j="Shape",q=" ",V="stage",U="transform",Z="visible",K=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(q);let J=1;class Q{constructor(t){this._id=J++,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!==U&&t!==$||!this._cache.get(t)?t?this._cache.delete(t):this._cache.clear():this._cache.get(t).dirty=!0}_getCache(t,e){let i=this._cache.get(t);return(void 0===i||(t===U||t===$)&&!0===i.dirty)&&(i=e.call(this),this._cache.set(t,i)),i}_calculate(t,e,i){if(!this._attachedDepsListeners.get(t)){const i=e.map(t=>t+"Change.konva").join(q);this.on(i,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(X)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===$&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(X)){const{scene:t,filter:e,hit:i,buffer:s}=this._cache.get(X);u.releaseCanvas(t,e,i,s),this._cache.delete(X)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),n=Math.ceil(e.height||i.height),r=e.pixelRatio,o=void 0===e.x?Math.floor(i.x):e.x,a=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(!s||!n)return void u.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");s+=2*h+(Math.abs(Math.round(i.x)-o)>.5?1:0),n+=2*h+(Math.abs(Math.round(i.y)-a)>.5?1:0),o-=h,a-=h;const c=new w({pixelRatio:r,width:s,height:n}),g=new w({pixelRatio:r,width:0,height:0,willReadFrequently:!0}),f=new R({pixelRatio:d,width:s,height:n}),p=c.getContext(),m=f.getContext(),y=new w({width:c.width/c.pixelRatio+Math.abs(o),height:c.height/c.pixelRatio+Math.abs(a),pixelRatio:c.pixelRatio}),x=y.getContext();return f.isCache=!0,c.isCache=!0,this._cache.delete(X),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,g.getContext()._context.imageSmoothingEnabled=!1),p.save(),m.save(),x.save(),p.translate(-o,-a),m.translate(-o,-a),x.translate(-o,-a),y.x=o,y.y=a,this._isUnderCache=!0,this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(Y),this.drawScene(c,this,y),this.drawHit(f,this),this._isUnderCache=!1,p.restore(),m.restore(),l&&(p.save(),p.beginPath(),p.rect(0,0,s,n),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.set(X,{scene:c,filter:g,hit:f,buffer:y,x:o,y:a}),this._requestDraw(),this}isCached(){return this._cache.has(X)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){const i=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let s=1/0,n=1/0,r=-1/0,o=-1/0;const a=this.getAbsoluteTransform(e);return i.forEach(function(t){const e=a.point(t);void 0===s&&(s=r=e.x,n=o=e.y),s=Math.min(s,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),o=Math.max(o,e.y)}),{x:s,y:n,width:r-s,height:o-n}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);const i=this._getCachedSceneCanvas(),s=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/s,i.height/s),t.restore()}_drawCachedHitCanvas(t){const e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t,e,i,s,n=this.filters(),r=this._getCanvasCache(),o=r.scene,a=r.filter,h=a.getContext();if(!n||0===n.length)return o;if(this._filterUpToDate)return a;let l=!0;for(let g=0;g<n.length;g++)if("string"==typeof n[g]&&y(),"string"!=typeof n[g]||!y()){l=!1;break}const d=o.pixelRatio;if(a.setSize(o.width/o.pixelRatio,o.height/o.pixelRatio),l){const t=n.join(" ");return h.save(),h.setAttr("filter",t),h.drawImage(o._canvas,0,0,o.getWidth()/d,o.getHeight()/d),h.restore(),this._filterUpToDate=!0,a}try{for(t=n.length,h.clear(),h.drawImage(o._canvas,0,0,o.getWidth()/d,o.getHeight()/d),e=h.getImageData(0,0,a.getWidth(),a.getHeight()),i=0;i<t;i++)s=n[i],"string"==typeof s&&(s=F(s)),s.call(this,e),h.putImageData(e,0,0)}catch(c){u.error("Unable to apply filter. "+c.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,a}on(t,e){if(this._cache&&this._cache.delete(W),3===arguments.length)return this._delegate.apply(this,arguments);const i=t.split(q);for(let s=0;s<i.length;s++){const t=i[s].split("."),n=t[0],r=t[1]||"";this.eventListeners[n]||(this.eventListeners[n]=[]),this.eventListeners[n].push({name:r,handler:e})}return this}off(t,e){let i,s,n,r,o,a,h=(t||"").split(q),l=h.length;if(this._cache&&this._cache.delete(W),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<l;i++)if(n=h[i],r=n.split("."),o=r[0],a=r[1],o)this.eventListeners[o]&&this._off(o,a,e);else for(s in this.eventListeners)this._off(s,a,e);return this}dispatchEvent(t){const e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(t){e.call(this,t.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){const s=this;this.on(t,function(t){const n=t.target.findAncestors(e,!0,s);for(let e=0;e<n.length;e++)(t=u.cloneObject(t)).currentTarget=n[e],i.call(n[e],t)})}remove(){return this.isDragging()&&this.stopDrag(),E._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache($),this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(Y),this._clearSelfAndDescendantCache(V),this._clearSelfAndDescendantCache(Z),this._clearSelfAndDescendantCache(H)}_remove(){this._clearCaches();const t=this.getParent();t&&t.children&&(t.children.splice(this.index,1),t._setChildrenIndices(),this.parent=null)}destroy(){return this.remove(),this.clearCache(),this}getAttr(t){const e="get"+u._capitalize(t);return u._isFunction(this[e])?this[e]():this.attrs[t]}getAncestors(){let t=this.getParent(),e=[];for(;t;)e.push(t),t=t.getParent();return e}getAttrs(){return this.attrs||{}}setAttrs(t){return this._batchTransformChanges(()=>{let e,i;if(!t)return this;for(e in t)"children"!==e&&(i="set"+u._capitalize(e),u._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(H,this._isListening)}_isListening(t){if(!this.listening())return!1;const e=this.getParent();return!e||e===t||this===t||e._isListening(t)}isVisible(){return this._getCache(Z,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const s=this.getLayer();let n=!1;E._dragElements.forEach(t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===s)&&(n=!0)});const r=!e&&!i.hitOnDragEnabled&&(n||i.isTransforming());return this.isListening()&&this.isVisible()&&!r}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t,e,i,s,n=this.getDepth(),r=this,o=0;const a=this.getStage();return"Stage"!==r.nodeType&&a&&function a(h){for(t=[],e=h.length,i=0;i<e;i++)s=h[i],o++,s.nodeType!==j&&(t=t.concat(s.getChildren().slice())),s._id===r._id&&(i=e);t.length>0&&t[0].getDepth()<=n&&a(t)}(a.getChildren()),o}getDepth(){let t=0,e=this.parent;for(;e;)t++,e=e.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(U),this._clearSelfAndDescendantCache($)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges(()=>{this.x(t.x),this.y(t.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const t=this.getStage();if(!t)return null;const e=t.getPointerPosition();if(!e)return null;const i=this.getAbsoluteTransform().copy();return i.invert(),i.point(e)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);const s=this.getAbsoluteTransform(t).getMatrix(),n=new r,o=this.offset();return n.m=s.slice(),n.translate(o.x,o.y),n.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(U);const n=this._getAbsoluteTransform().copy();return n.invert(),n.translate(t.x,t.y),t={x:this.attrs.x+n.getTranslation().x,y:this.attrs.y+n.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(U),this._clearSelfAndDescendantCache($),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){const t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}move(t){let e=t.x,i=t.y,s=this.x(),n=this.y();return void 0!==e&&(s+=e),void 0!==i&&(n+=i),this.setPosition({x:s,y:n}),this}_eachAncestorReverse(t,e){let i,s,n=[],r=this.getParent();if(!e||e._id!==this._id){for(n.unshift(this);r&&(!e||r._id!==e._id);)n.unshift(r),r=r.parent;for(i=n.length,s=0;s<i;s++)t(n[s])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return u.warn("Node has no parent. moveToTop function is ignored."),!1;const t=this.index;return t<this.parent.getChildren().length-1&&(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0)}moveUp(){if(!this.parent)return u.warn("Node has no parent. moveUp function is ignored."),!1;const t=this.index;return t<this.parent.getChildren().length-1&&(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0)}moveDown(){if(!this.parent)return u.warn("Node has no parent. moveDown function is ignored."),!1;const t=this.index;return t>0&&(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0)}moveToBottom(){if(!this.parent)return u.warn("Node has no parent. moveToBottom function is ignored."),!1;const t=this.index;return t>0&&(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)}setZIndex(t){if(!this.parent)return u.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&u.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");const e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(N,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity();const e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t,e,i,s,n,r=this.getAttrs();const o={attrs:{},className:this.getClassName()};for(t in r)e=r[t],n=u.isObject(e)&&!u._isPlainObject(e)&&!u._isArray(e),n||(i="function"==typeof this[t]&&this[t],delete r[t],s=i?i.call(this):null,r[t]=e,s!==e&&(o.attrs[t]=e));return u._prepareToStringify(o)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){const s=[];e&&this._isMatch(t)&&s.push(this);let n=this.parent;for(;n;){if(n===i)return s;n._isMatch(t)&&s.push(n),n=n.parent}return s}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if("function"==typeof t)return t(this);let e,i,s=t.replace(/ /g,"").split(","),n=s.length;for(e=0;e<n;e++)if(i=s[e],u.isValidSelector(i)||(u.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),u.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),u.warn("Konva is awesome, right?")),"#"===i.charAt(0)){if(this.id()===i.slice(1))return!0}else if("."===i.charAt(0)){if(this.hasName(i.slice(1)))return!0}else if(this.className===i||this.nodeType===i)return!0;return!1}getLayer(){const t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(V,this._getStage)}_getStage(){const t=this.getParent();return t?t.getStage():null}fire(t,e={},i){return e.target=e.target||this,i?this._fireAndBubble(t,e):this._fire(t,e),this}getAbsoluteTransform(t){return t?this._getAbsoluteTransform(t):this._getCache($,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new r,this._eachAncestorReverse(function(t){const i=t.transformsEnabled();"all"===i?e.multiply(t.getTransform()):"position"===i&&e.translate(t.x()-t.offsetX(),t.y()-t.offsetY())},t),e;{e=this._cache.get($)||new r,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();const t=this.transformsEnabled();if("all"===t)e.multiply(this.getTransform());else if("position"===t){const t=this.attrs.x||0,i=this.attrs.y||0,s=this.attrs.offsetX||0,n=this.attrs.offsetY||0;e.translate(t-s,i-n)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();const i=this.getAbsoluteTransform(t).decompose();return{x:i.scaleX,y:i.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(U,this._getTransform)}_getTransform(){var t,e;const s=this._cache.get(U)||new r;s.reset();const n=this.x(),o=this.y(),a=i.getAngle(this.rotation()),h=null!==(t=this.attrs.scaleX)&&void 0!==t?t:1,l=null!==(e=this.attrs.scaleY)&&void 0!==e?e:1,d=this.attrs.skewX||0,c=this.attrs.skewY||0,g=this.attrs.offsetX||0,u=this.attrs.offsetY||0;return 0===n&&0===o||s.translate(n,o),0!==a&&s.rotate(a),0===d&&0===c||s.skew(d,c),1===h&&1===l||s.scale(h,l),0===g&&0===u||s.translate(-1*g,-1*u),s.dirty=!1,s}clone(t){let e,i,s,n,r,o=u.cloneObject(this.attrs);for(e in t)o[e]=t[e];const a=new this.constructor(o);for(e in this.eventListeners)for(i=this.eventListeners[e],s=i.length,n=0;n<s;n++)r=i[n],r.name.indexOf("konva")<0&&(a.eventListeners[e]||(a.eventListeners[e]=[]),a.eventListeners[e].push(r));return a}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=void 0!==t.x?t.x:Math.floor(e.x),n=void 0!==t.y?t.y:Math.floor(e.y),r=t.pixelRatio||1,o=new w({width:t.width||Math.ceil(e.width)||(i?i.width():0),height:t.height||Math.ceil(e.height)||(i?i.height():0),pixelRatio:r}),a=o.getContext(),h=new w({width:o.width/o.pixelRatio+Math.abs(s),height:o.height/o.pixelRatio+Math.abs(n),pixelRatio:o.pixelRatio});return!1===t.imageSmoothingEnabled&&(a._context.imageSmoothingEnabled=!1),a.save(),(s||n)&&a.translate(-1*s,-1*n),this.drawScene(o,void 0,h),a.restore(),o}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){const e=(t=t||{}).mimeType||null,i=t.quality||null,s=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(s),s}toImage(t){return new Promise((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,u._urlToImage(this.toDataURL(t),function(t){e(t),null==i||i(t)})}catch(s){i(s)}})}toBlob(t){return new Promise((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,this.toCanvas(t).toBlob(t=>{e(t),null==i||i(t)},null==t?void 0:t.mimeType,null==t?void 0:t.quality)}catch(s){i(s)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():i.dragDistance}_off(t,e,i){let s,n,r,o=this.eventListeners[t];for(s=0;s<o.length;s++)if(n=o[s].name,r=o[s].handler,!("konva"===n&&"konva"!==e||e&&n!==e||i&&i!==r)){if(o.splice(s,1),0===o.length){delete this.eventListeners[t];break}s--}}_fireChangeEvent(t,e,i){this._fire(t+"Change",{oldVal:e,newVal:i})}addName(t){if(!this.hasName(t)){const e=this.name(),i=e?e+" "+t:t;this.name(i)}return this}hasName(t){if(!t)return!1;const e=this.name();if(!e)return!1;return-1!==(e||"").split(/\s/g).indexOf(t)}removeName(t){const e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return-1!==i&&(e.splice(i,1),this.name(e.join(" "))),this}setAttr(t,e){const i=this["set"+u._capitalize(t)];return u._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(i.autoDrawEnabled){const t=this.getLayer()||this.getStage();null==t||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];(i!==e||u.isObject(e))&&(null==e?delete this.attrs[t]:this.attrs[t]=e,this._shouldFireChangeEvents&&this._fireChangeEvent(t,i,e),this._requestDraw())}_setComponentAttr(t,e,i){let s;void 0!==i&&(s=this.attrs[t],s||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,s,i))}_fireAndBubble(t,e,i){e&&this.nodeType===j&&(e.target=this);const s=["mouseenter","mouseleave","pointerenter","pointerleave","touchenter","touchleave"];if(!(-1!==s.indexOf(t)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);const n=-1!==s.indexOf(t)&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!n&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i,s;const n=null!==(e=this._cache.get(W))&&void 0!==e?e:{};let r=null==n?void 0:n[t];if(void 0===r){r=[];let e=Object.getPrototypeOf(this);for(;e;){const n=null!==(s=null===(i=e.eventListeners)||void 0===i?void 0:i[t])&&void 0!==s?s:[];r.push(...n),e=Object.getPrototypeOf(e)}n[t]=r,this._cache.set(W,n)}return r}_fire(t,e){(e=e||{}).currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let n=0;n<i.length;n++)i[n].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let n=0;n<s.length;n++)s[n].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const e=t?t.pointerId:void 0,i=this.getStage(),s=this.getAbsolutePosition();if(!i)return;const n=i._getPointerById(e)||i._changedPointerPositions[0]||s;E._dragElements.set(this._id,{node:this,startPointerPos:n,offset:{x:n.x-s.x,y:n.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){E._dragElements.has(this._id)||this._createDragElement(t);E._dragElements.get(this._id).dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:t&&t.evt},e)}_setDragPosition(t,e){const i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let s={x:i.x-e.offset.x,y:i.y-e.offset.y};const n=this.dragBoundFunc();if(void 0!==n){const e=n.call(this,s,t);e?s=e:u.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}this._lastPos&&this._lastPos.x===s.x&&this._lastPos.y===s.y||(this.setAbsolutePosition(s),this._requestDraw()),this._lastPos=s}stopDrag(t){const e=E._dragElements.get(this._id);e&&(e.dragStatus="stopped"),E._endDragBefore(t),E._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=E._dragElements.get(this._id);return!!t&&"dragging"===t.dragStatus}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(!(void 0!==t.evt.button)||i.dragButtons.indexOf(t.evt.button)>=0))return;if(this.isDragging())return;let e=!1;E._dragElements.forEach(t=>{this.isAncestorOf(t.node)&&(e=!0)}),e||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();if(!this.getStage())return;const t=E._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&E._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const e=this.getStage();if(!e)return!1;const i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return u.haveIntersection(i,this.getClientRect())}static create(t,e){return u._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let s,n,r,o=Q.prototype.getClassName.call(t),a=t.children;e&&(t.attrs.container=e),i[o]||(u.warn('Can not find a node with class name "'+o+'". Fallback to "Shape".'),o="Shape");if(s=new(0,i[o])(t.attrs),a)for(n=a.length,r=0;r<n;r++)s.add(Q._createNode(a[r]));return s}}Q.prototype.nodeType="Node",Q.prototype._attrsAffectingSize=[],Q.prototype.eventListeners={},Q.prototype.on.call(Q.prototype,K,function(){this._batchingTransformChange?this._needClearTransformCache=!0:(this._clearCache(U),this._clearSelfAndDescendantCache($))}),Q.prototype.on.call(Q.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(Z)}),Q.prototype.on.call(Q.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(H)}),Q.prototype.on.call(Q.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(N)});const tt=B.addGetterSetter;tt(Q,"zIndex"),tt(Q,"absolutePosition"),tt(Q,"position"),tt(Q,"x",0,A()),tt(Q,"y",0,A()),tt(Q,"globalCompositeOperation","source-over",D()),tt(Q,"opacity",1,A()),tt(Q,"name","",D()),tt(Q,"id","",D()),tt(Q,"rotation",0,A()),B.addComponentsGetterSetter(Q,"scale",["x","y"]),tt(Q,"scaleX",1,A()),tt(Q,"scaleY",1,A()),B.addComponentsGetterSetter(Q,"skew",["x","y"]),tt(Q,"skewX",0,A()),tt(Q,"skewY",0,A()),B.addComponentsGetterSetter(Q,"offset",["x","y"]),tt(Q,"offsetX",0,A()),tt(Q,"offsetY",0,A()),tt(Q,"dragDistance",void 0,A()),tt(Q,"width",0,A()),tt(Q,"height",0,A()),tt(Q,"listening",!0,G()),tt(Q,"preventDefault",!0,G()),tt(Q,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),tt(Q,"visible",!0,G()),tt(Q,"transformsEnabled","all",D()),tt(Q,"size"),tt(Q,"dragBoundFunc"),tt(Q,"draggable",!1,G()),B.backCompat(Q,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class et extends Q{constructor(){super(...arguments),this.children=[]}getChildren(t){const e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(0===t.length)return this;if(t.length>1){for(let e=0;e<t.length;e++)this.add(t[e]);return this}const e=t[0];return e.getParent()?(e.moveTo(this),this):(this._validateAdd(e),e.index=this.getChildren().length,e.parent=this,e._clearCaches(),this.getChildren().push(e),this._fire("add",{child:e}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(t){return this._generalFind(t,!1)}findOne(t){const e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){const i=[];return this._descendants(s=>{const n=s._isMatch(t);return n&&i.push(s),!(!n||!e)}),i}_descendants(t){let e=!1;const i=this.getChildren();for(const s of i){if(e=t(s),e)return!0;if(s.hasChildren()&&(e=s._descendants(t),e))return!0}return!1}toObject(){const t=Q.prototype.toObject.call(this);return t.children=[],this.getChildren().forEach(e=>{t.children.push(e.toObject())}),t}isAncestorOf(t){let e=t.getParent();for(;e;){if(e._id===this._id)return!0;e=e.getParent()}return!1}clone(t){const e=Q.prototype.clone.call(this,t);return this.getChildren().forEach(function(t){e.add(t.clone())}),e}getAllIntersections(t){const e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),this.isCached()||null===(e=this.children)||void 0===e||e.forEach(function(e){e._clearSelfAndDescendantCache(t)})}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach(function(t,e){t.index=e}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),n=t||s&&s.getCanvas(),r=n&&n.getContext(),o=this._getCanvasCache(),a=o&&o.scene,h=n&&n.isCache;if(!this.isVisible()&&!h)return this;if(a){r.save();const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(r),r.restore()}else this._drawChildren("drawScene",n,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,n=s&&s.getContext(),r=this._getCanvasCache();if(r&&r.hit){n.save();const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(n),n.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var n;const r=e&&e.getContext(),o=this.clipWidth(),a=this.clipHeight(),h=this.clipFunc(),l="number"==typeof o&&"number"==typeof a||h,d=i===this;if(l){r.save();const t=this.getAbsoluteTransform(i);let e,s=t.getMatrix();if(r.transform(s[0],s[1],s[2],s[3],s[4],s[5]),r.beginPath(),h)e=h.call(this,r,this);else{const t=this.clipX(),e=this.clipY();r.rect(t||0,e||0,o,a)}r.clip.apply(r,e),s=t.copy().invert().getMatrix(),r.transform(s[0],s[1],s[2],s[3],s[4],s[5])}const c=!d&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;c&&(r.save(),r._applyGlobalCompositeOperation(this)),null===(n=this.children)||void 0===n||n.forEach(function(n){n[t](e,i,s)}),c&&r.restore(),l&&r.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let n,r,o,a,h={x:1/0,y:1/0,width:0,height:0};const l=this;null===(e=this.children)||void 0===e||e.forEach(function(e){if(!e.visible())return;const i=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===i.width&&0===i.height||(void 0===n?(n=i.x,r=i.y,o=i.x+i.width,a=i.y+i.height):(n=Math.min(n,i.x),r=Math.min(r,i.y),o=Math.max(o,i.x+i.width),a=Math.max(a,i.y+i.height)))});const d=this.find("Shape");let c=!1;for(let g=0;g<d.length;g++){if(d[g]._isVisible(this)){c=!0;break}}return h=c&&void 0!==n?{x:n,y:r,width:o-n,height:a-r}:{x:0,y:0,width:0,height:0},i?h:this._transformedRect(h,s)}}B.addComponentsGetterSetter(et,"clip",["x","y","width","height"]),B.addGetterSetter(et,"clipX",void 0,A()),B.addGetterSetter(et,"clipY",void 0,A()),B.addGetterSetter(et,"clipWidth",void 0,A()),B.addGetterSetter(et,"clipHeight",void 0,A()),B.addGetterSetter(et,"clipFunc");const it=new Map,st=void 0!==i._global.PointerEvent;function nt(t){return it.get(t)}function rt(t){return{evt:t,pointerId:t.pointerId}}function ot(t,e){return it.get(t)===e}function at(t,e){ht(t);e.getStage()&&(it.set(t,e),st&&e._fire("gotpointercapture",rt(new PointerEvent("gotpointercapture"))))}function ht(t,e){const i=it.get(t);if(!i)return;const s=i.getStage();s&&s.content,it.delete(t),st&&i._fire("lostpointercapture",rt(new PointerEvent("lostpointercapture")))}const lt="mouseleave",dt="mouseover",ct="mouseenter",gt="mousemove",ut="mousedown",ft="mouseup",pt="pointermove",mt="pointerdown",yt="pointerup",xt="pointercancel",vt="pointerout",bt="pointerleave",_t="pointerover",wt="pointerenter",St="contextmenu",Ct="touchstart",kt="touchend",Rt="touchmove",Et="touchcancel",Mt="wheel",Pt=[[ct,"_pointerenter"],[ut,"_pointerdown"],[gt,"_pointermove"],[ft,"_pointerup"],[lt,"_pointerleave"],[Ct,"_pointerdown"],[Rt,"_pointermove"],[kt,"_pointerup"],[Et,"_pointercancel"],[dt,"_pointerover"],[Mt,"_wheel"],[St,"_contextmenu"],[mt,"_pointerdown"],[pt,"_pointermove"],[yt,"_pointerup"],[xt,"_pointercancel"],[bt,"_pointerleave"],["lostpointercapture","_lostpointercapture"]],At={mouse:{[vt]:"mouseout",[bt]:lt,[_t]:dt,[wt]:ct,[pt]:gt,[mt]:ut,[yt]:ft,[xt]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[vt]:"touchout",[bt]:"touchleave",[_t]:"touchover",[wt]:"touchenter",[pt]:Rt,[mt]:Ct,[yt]:kt,[xt]:Et,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[vt]:vt,[bt]:bt,[_t]:_t,[wt]:wt,[pt]:pt,[mt]:mt,[yt]:yt,[xt]:xt,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},Tt=t=>t.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",Lt=t=>{const e=Tt(t);return"pointer"===e?i.pointerEventsEnabled&&At.pointer:"touch"===e?At.touch:"mouse"===e?At.mouse:void 0};function Dt(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&u.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const It=[];class Gt extends et{constructor(t){super(Dt(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),It.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{Dt(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();e||i||u.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const t=this.visible()?"":"none";this.content.style.display=t}setContainer(t){if("string"==typeof t){let e;if("."===t.charAt(0)){const e=t.slice(1);t=document.getElementsByClassName(e)[0]}else e="#"!==t.charAt(0)?t:t.slice(1),t=document.getElementById(e);if(!t)throw"Can not find container in document with id "+e}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){const t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].clear();return this}clone(t){return t||(t={}),t.container="undefined"!=typeof document&&document.createElement("div"),et.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&u._isInDocument(t)&&this.container().removeChild(t);const e=It.indexOf(this);return e>-1&&It.splice(e,1),u.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(u.warn("Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);"),null)}_getPointerById(t){return this._pointerPositions.find(e=>e.id===t)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(t){(t={...t}).x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();const e=new w({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,s=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),s.forEach(function(e){if(!e.isVisible())return;const s=e._toKonvaCanvas(t);i.drawImage(s._canvas,t.x,t.y,s.getWidth()/s.getPixelRatio(),s.getHeight()/s.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children;for(let i=e.length-1;i>=0;i--){const s=e[i].getIntersection(t);if(s)return s}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach(i=>{i.setSize({width:t,height:e}),i.draw()})}add(t,...e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}super.add(t);const s=this.children.length;return s>5&&u.warn("The stage has "+s+" 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(),i.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return ot(t,this)}setPointerCapture(t){at(t,this)}releaseCapture(t){ht(t)}getLayers(){return this.children}_bindContentEvents(){i.isBrowser&&Pt.forEach(([t,e])=>{this.content.addEventListener(t,t=>{this[e](t)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=Lt(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=Lt(t.type);e&&this._fire(e.pointerover,{evt:t,target:this,currentTarget:this})}_getTargetShape(t){let e=this[t+"targetShape"];return e&&!e.getStage()&&(e=null),e}_pointerleave(t){const e=Lt(t.type),s=Tt(t.type);if(!e)return;this.setPointersPositions(t);const n=this._getTargetShape(s),r=!(i.isDragging()||i.isTransforming())||i.hitOnDragEnabled;n&&r?(n._fireAndBubble(e.pointerout,{evt:t}),n._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[s+"targetShape"]=null):r&&(this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this._fire(e.pointerout,{evt:t,target:this,currentTarget:this})),this.pointerPos=null,this._pointerPositions=[]}_pointerdown(t){const e=Lt(t.type),s=Tt(t.type);if(!e)return;this.setPointersPositions(t);let n=!1;this._changedPointerPositions.forEach(r=>{const o=this.getIntersection(r);if(E.justDragged=!1,i["_"+s+"ListenClick"]=!0,!o||!o.isListening())return void(this[s+"ClickStartShape"]=void 0);i.capturePointerEventsEnabled&&o.setPointerCapture(r.id),this[s+"ClickStartShape"]=o,o._fireAndBubble(e.pointerdown,{evt:t,pointerId:r.id}),n=!0;const a=t.type.indexOf("touch")>=0;o.preventDefault()&&t.cancelable&&a&&t.preventDefault()}),n||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=Lt(t.type),s=Tt(t.type);if(!e)return;const n=t.type.indexOf("touch")>=0||"touch"===t.pointerType;i.isDragging()&&E.node.preventDefault()&&t.cancelable&&n&&t.preventDefault(),this.setPointersPositions(t);if(!(!(i.isDragging()||i.isTransforming())||i.hitOnDragEnabled))return;const r={};let o=!1;const a=this._getTargetShape(s);this._changedPointerPositions.forEach(i=>{const n=nt(i.id)||this.getIntersection(i),h=i.id,l={evt:t,pointerId:h},d=a!==n;if(d&&a&&(a._fireAndBubble(e.pointerout,{...l},n),a._fireAndBubble(e.pointerleave,{...l},n)),n){if(r[n._id])return;r[n._id]=!0}n&&n.isListening()?(o=!0,d&&(n._fireAndBubble(e.pointerover,{...l},a),n._fireAndBubble(e.pointerenter,{...l},a),this[s+"targetShape"]=n),n._fireAndBubble(e.pointermove,{...l})):a&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[s+"targetShape"]=null)}),o||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=Lt(t.type),s=Tt(t.type);if(!e)return;this.setPointersPositions(t);const n=this[s+"ClickStartShape"],r=this[s+"ClickEndShape"],o={};let a=!1;this._changedPointerPositions.forEach(h=>{const l=nt(h.id)||this.getIntersection(h);if(l){if(l.releaseCapture(h.id),o[l._id])return;o[l._id]=!0}const d=h.id,c={evt:t,pointerId:d};let g=!1;i["_"+s+"InDblClickWindow"]?(g=!0,clearTimeout(this[s+"DblTimeout"])):E.justDragged||(i["_"+s+"InDblClickWindow"]=!0,clearTimeout(this[s+"DblTimeout"])),this[s+"DblTimeout"]=setTimeout(function(){i["_"+s+"InDblClickWindow"]=!1},i.dblClickWindow),l&&l.isListening()?(a=!0,this[s+"ClickEndShape"]=l,l._fireAndBubble(e.pointerup,{...c}),i["_"+s+"ListenClick"]&&n&&n===l&&(l._fireAndBubble(e.pointerclick,{...c}),g&&r&&r===l&&l._fireAndBubble(e.pointerdblclick,{...c}))):(this[s+"ClickEndShape"]=null,a||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),a=!0),i["_"+s+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:d}),g&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:d}))}),a||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),i["_"+s+"ListenClick"]=!1,t.cancelable&&"touch"!==s&&"pointer"!==s&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(St,{evt:t}):this._fire(St,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const 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);const e=nt(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(yt,rt(t)),ht(t.pointerId)}_lostpointercapture(t){ht(t.pointerId)}setPointersPositions(t){const e=this._getContentPosition();let i=null,s=null;void 0!==(t=t||window.event).touches?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,t=>{this._pointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})}),Array.prototype.forEach.call(t.changedTouches||t.touches,t=>{this._changedPointerPositions.push({id:t.identifier,x:(t.clientX-e.left)/e.scaleX,y:(t.clientY-e.top)/e.scaleY})})):(i=(t.clientX-e.left)/e.scaleX,s=(t.clientY-e.top)/e.scaleY,this.pointerPos={x:i,y:s},this._pointerPositions=[{x:i,y:s,id:u._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:s,id:u._getFirstPointerId(t)}])}_setPointerPosition(t){u.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(t)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};const t=this.content.getBoundingClientRect();return{top:t.top,left:t.left,scaleX:t.width/this.content.clientWidth||1,scaleY:t.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new w({width:this.width(),height:this.height()}),this.bufferHitCanvas=new R({pixelRatio:1,width:this.width(),height:this.height()}),!i.isBrowser)return;const t=this.container();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.userSelect="none",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}cache(){return u.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}}Gt.prototype.nodeType="Stage",s(Gt),B.addGetterSetter(Gt,"container"),i.isBrowser&&document.addEventListener("visibilitychange",()=>{It.forEach(t=>{t.batchDraw()})});const Ot="hasShadow",zt="shadowRGBA",Bt="patternImage",Ft="linearGradient",Nt="radialGradient";let Wt;function $t(){return Wt||(Wt=u.createCanvasElement().getContext("2d"),Wt)}const Yt={};class Xt extends Q{constructor(t){let e;for(super(t);e=u.getRandomColor(),!e||e in Yt;);this.colorKey=e,Yt[e]=this}getContext(){return u.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return u.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(Ot,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Bt,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=$t().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new r;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(i.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const s=e.getMatrix(),n="undefined"==typeof DOMMatrix?{a:s[0],b:s[1],c:s[2],d:s[3],e:s[4],f:s[5]}:new DOMMatrix(s);t.setTransform(n)}return t}}_getLinearGradient(){return this._getCache(Ft,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=$t(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),n=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let r=0;r<t.length;r+=2)n.addColorStop(t[r],t[r+1]);return n}}_getRadialGradient(){return this._getCache(Nt,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=$t(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),n=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let r=0;r<t.length;r+=2)n.addColorStop(t[r],t[r+1]);return n}}getShadowRGBA(){return this._getCache(zt,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=u.colorToRGBA(this.shadowColor());return t?"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.shadowOpacity()||1)+")":void 0}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!(!this.stroke()&&!this.strokeLinearGradientColorStops()))}hasHitStroke(){const t=this.hitStrokeWidth();return"auto"===t?this.hasStroke():this.strokeEnabled()&&!!t}intersects(t){const e=this.getStage();if(!e)return!1;const i=e.bufferHitCanvas;i.getContext().clear(),this.drawHit(i,void 0,!0);return i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]>0}destroy(){return Q.prototype.destroy.call(this),delete Yt[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),s=this.hasStroke(),n=1!==this.getAbsoluteOpacity();if(i&&s&&n)return!0;const r=this.hasShadow(),o=this.shadowForStrokeEnabled();return!!(i&&s&&r&&o)}setStrokeHitEnabled(t){u.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}getSelfRect(){const t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){let e=!1,i=this.getParent();for(;i;){if(i.isCached()){e=!0;break}i=i.getParent()}const s=t.skipTransform,n=t.relativeTo||e&&this.getStage()||void 0,r=this.getSelfRect(),o=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,a=r.width+o,h=r.height+o,l=!t.skipShadow&&this.hasShadow(),d=l?this.shadowOffsetX():0,c=l?this.shadowOffsetY():0,g=a+Math.abs(d),u=h+Math.abs(c),f=l&&this.shadowBlur()||0,p={width:g+2*f,height:u+2*f,x:-(o/2+f)+Math.min(d,0)+r.x,y:-(o/2+f)+Math.min(c,0)+r.y};return s?p:this._transformedRect(p,n)}drawScene(t,e,i){const s=this.getLayer(),n=(t||s.getCanvas()).getContext(),r=this._getCanvasCache(),o=this.getSceneFunc(),a=this.hasShadow();let h;const l=e===this;if(!this.isVisible()&&!l)return this;if(r){n.save();const t=this.getAbsoluteTransform(e).getMatrix();return n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(n),n.restore(),this}if(!o)return this;if(n.save(),this._useBufferCanvas()){h=this.getStage();const t=i||h.bufferCanvas,s=t.getContext();s.clear(),s.save(),s._applyLineJoin(this),s._applyMiterLimit(this);const r=this.getAbsoluteTransform(e).getMatrix();s.transform(r[0],r[1],r[2],r[3],r[4],r[5]),o.call(this,s,this),s.restore();const l=t.pixelRatio;a&&n._applyShadow(this),n._applyOpacity(this),n._applyGlobalCompositeOperation(this),n.drawImage(t._canvas,t.x||0,t.y||0,t.width/l,t.height/l)}else{if(n._applyLineJoin(this),n._applyMiterLimit(this),!l){const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),n._applyOpacity(this),n._applyGlobalCompositeOperation(this)}a&&n._applyShadow(this),o.call(this,n,this)}return n.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),n=t||s.hitCanvas,r=n&&n.getContext(),o=this.hitFunc()||this.sceneFunc(),a=this._getCanvasCache(),h=a&&a.hit;if(this.colorKey||u.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),h){r.save();const t=this.getAbsoluteTransform(e).getMatrix();return r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(r),r.restore(),this}if(!o)return this;r.save(),r._applyLineJoin(this),r._applyMiterLimit(this);if(!(this===e)){const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return o.call(this,r,this),r.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,n=s.getContext(),r=s.getWidth(),o=s.getHeight();n.clear(),n.drawImage(i._canvas,0,0,r,o);try{const e=n.getImageData(0,0,r,o),i=e.data,s=i.length,a=u._hexToRgb(this.colorKey);for(let n=0;n<s;n+=4){i[n+3]>t?(i[n]=a.r,i[n+1]=a.g,i[n+2]=a.b,i[n+3]=255):i[n+3]=0}n.putImageData(e,0,0)}catch(a){u.error("Unable to draw hit graph from cached scene canvas. "+a.message)}return this}hasPointerCapture(t){return ot(t,this)}setPointerCapture(t){at(t,this)}releaseCapture(t){ht(t)}}Xt.prototype._fillFunc=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},Xt.prototype._strokeFunc=function(t){t.stroke()},Xt.prototype._fillFuncHit=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},Xt.prototype._strokeFuncHit=function(t){t.stroke()},Xt.prototype._centroid=!1,Xt.prototype.nodeType="Shape",s(Xt),Xt.prototype.eventListeners={},Xt.prototype.on.call(Xt.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(Ot)}),Xt.prototype.on.call(Xt.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(zt)}),Xt.prototype.on.call(Xt.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",function(){this._clearCache(Bt)}),Xt.prototype.on.call(Xt.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",function(){this._clearCache(Ft)}),Xt.prototype.on.call(Xt.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",function(){this._clearCache(Nt)}),B.addGetterSetter(Xt,"stroke",void 0,I()),B.addGetterSetter(Xt,"strokeWidth",2,A()),B.addGetterSetter(Xt,"fillAfterStrokeEnabled",!1),B.addGetterSetter(Xt,"hitStrokeWidth","auto",L()),B.addGetterSetter(Xt,"strokeHitEnabled",!0,G()),B.addGetterSetter(Xt,"perfectDrawEnabled",!0,G()),B.addGetterSetter(Xt,"shadowForStrokeEnabled",!0,G()),B.addGetterSetter(Xt,"lineJoin"),B.addGetterSetter(Xt,"lineCap"),B.addGetterSetter(Xt,"miterLimit"),B.addGetterSetter(Xt,"sceneFunc"),B.addGetterSetter(Xt,"hitFunc"),B.addGetterSetter(Xt,"dash"),B.addGetterSetter(Xt,"dashOffset",0,A()),B.addGetterSetter(Xt,"shadowColor",void 0,D()),B.addGetterSetter(Xt,"shadowBlur",0,A()),B.addGetterSetter(Xt,"shadowOpacity",1,A()),B.addComponentsGetterSetter(Xt,"shadowOffset",["x","y"]),B.addGetterSetter(Xt,"shadowOffsetX",0,A()),B.addGetterSetter(Xt,"shadowOffsetY",0,A()),B.addGetterSetter(Xt,"fillPatternImage"),B.addGetterSetter(Xt,"fill",void 0,I()),B.addGetterSetter(Xt,"fillPatternX",0,A()),B.addGetterSetter(Xt,"fillPatternY",0,A()),B.addGetterSetter(Xt,"fillLinearGradientColorStops"),B.addGetterSetter(Xt,"strokeLinearGradientColorStops"),B.addGetterSetter(Xt,"fillRadialGradientStartRadius",0),B.addGetterSetter(Xt,"fillRadialGradientEndRadius",0),B.addGetterSetter(Xt,"fillRadialGradientColorStops"),B.addGetterSetter(Xt,"fillPatternRepeat","repeat"),B.addGetterSetter(Xt,"fillEnabled",!0),B.addGetterSetter(Xt,"strokeEnabled",!0),B.addGetterSetter(Xt,"shadowEnabled",!0),B.addGetterSetter(Xt,"dashEnabled",!0),B.addGetterSetter(Xt,"strokeScaleEnabled",!0),B.addGetterSetter(Xt,"fillPriority","color"),B.addComponentsGetterSetter(Xt,"fillPatternOffset",["x","y"]),B.addGetterSetter(Xt,"fillPatternOffsetX",0,A()),B.addGetterSetter(Xt,"fillPatternOffsetY",0,A()),B.addComponentsGetterSetter(Xt,"fillPatternScale",["x","y"]),B.addGetterSetter(Xt,"fillPatternScaleX",1,A()),B.addGetterSetter(Xt,"fillPatternScaleY",1,A()),B.addComponentsGetterSetter(Xt,"fillLinearGradientStartPoint",["x","y"]),B.addComponentsGetterSetter(Xt,"strokeLinearGradientStartPoint",["x","y"]),B.addGetterSetter(Xt,"fillLinearGradientStartPointX",0),B.addGetterSetter(Xt,"strokeLinearGradientStartPointX",0),B.addGetterSetter(Xt,"fillLinearGradientStartPointY",0),B.addGetterSetter(Xt,"strokeLinearGradientStartPointY",0),B.addComponentsGetterSetter(Xt,"fillLinearGradientEndPoint",["x","y"]),B.addComponentsGetterSetter(Xt,"strokeLinearGradientEndPoint",["x","y"]),B.addGetterSetter(Xt,"fillLinearGradientEndPointX",0),B.addGetterSetter(Xt,"strokeLinearGradientEndPointX",0),B.addGetterSetter(Xt,"fillLinearGradientEndPointY",0),B.addGetterSetter(Xt,"strokeLinearGradientEndPointY",0),B.addComponentsGetterSetter(Xt,"fillRadialGradientStartPoint",["x","y"]),B.addGetterSetter(Xt,"fillRadialGradientStartPointX",0),B.addGetterSetter(Xt,"fillRadialGradientStartPointY",0),B.addComponentsGetterSetter(Xt,"fillRadialGradientEndPoint",["x","y"]),B.addGetterSetter(Xt,"fillRadialGradientEndPointX",0),B.addGetterSetter(Xt,"fillRadialGradientEndPointY",0),B.addGetterSetter(Xt,"fillPatternRotation",0),B.addGetterSetter(Xt,"fillRule",void 0,D()),B.backCompat(Xt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const Ht=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],jt=Ht.length;class qt extends et{constructor(t){super(t),this.canvas=new w,this.hitCanvas=new R({pixelRatio:1}),this._waitingForDraw=!1,this.on("visibleChange.konva",this._checkVisibility),this._checkVisibility(),this.on("imageSmoothingEnabledChange.konva",this._setSmoothEnabled),this._setSmoothEnabled()}createPNGStream(){return this.canvas._canvas.createPNGStream()}getCanvas(){return this.canvas}getNativeCanvasElement(){return this.canvas._canvas}getHitCanvas(){return this.hitCanvas}getContext(){return this.getCanvas().getContext()}clear(t){return this.getContext().clear(t),this.getHitCanvas().getContext().clear(t),this}setZIndex(t){super.setZIndex(t);const e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),t<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[t+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement())),this}moveToTop(){Q.prototype.moveToTop.call(this);const t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!Q.prototype.moveUp.call(this))return!1;const t=this.getStage();return!(!t||!t.content)&&(t.content.removeChild(this.getNativeCanvasElement()),this.index<t.children.length-1?t.content.insertBefore(this.getNativeCanvasElement(),t.children[this.index+1].getCanvas()._canvas):t.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(Q.prototype.moveDown.call(this)){const t=this.getStage();if(t){const e=t.children;t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.insertBefore(this.getNativeCanvasElement(),e[this.index+1].getCanvas()._canvas))}return!0}return!1}moveToBottom(){if(Q.prototype.moveToBottom.call(this)){const t=this.getStage();if(t){const e=t.children;t.content&&(t.content.removeChild(this.getNativeCanvasElement()),t.content.insertBefore(this.getNativeCanvasElement(),e[1].getCanvas()._canvas))}return!0}return!1}getLayer(){return this}remove(){const t=this.getNativeCanvasElement();return Q.prototype.remove.call(this),t&&t.parentNode&&u._isInDocument(t)&&t.parentNode.removeChild(t),this}getStage(){return this.parent}setSize({width:t,height:e}){return this.canvas.setSize(t,e),this.hitCanvas.setSize(t,e),this._setSmoothEnabled(),this}_validateAdd(t){const e=t.getType();"Group"!==e&&"Shape"!==e&&u.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(t){return(t={...t}).width=t.width||this.getWidth(),t.height=t.height||this.getHeight(),t.x=void 0!==t.x?t.x:this.x(),t.y=void 0!==t.y?t.y:this.y(),Q.prototype._toKonvaCanvas.call(this,t)}_checkVisibility(){const t=this.visible();this.canvas._canvas.style.display=t?"block":"none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){u.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){u.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,u.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(t){if(!this.isListening()||!this.isVisible())return null;let e=1,i=!1;for(;;){for(let s=0;s<jt;s++){const n=Ht[s],r=this._getIntersection({x:t.x+n.x*e,y:t.y+n.y*e}),o=r.shape;if(o)return o;if(i=!!r.antialiased,!r.antialiased)break}if(!i)return null;e+=1}}_getIntersection(t){const e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,s=i[3];if(255===s){const t=u._rgbToHex(i[0],i[1],i[2]),e=Yt["#"+t];return e?{shape:e}:{antialiased:!0}}return s>0?{antialiased:!0}:{}}drawScene(t,e,i){const s=this.getLayer(),n=t||s&&s.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&n.getContext().clear(),et.prototype.drawScene.call(this,n,e,i),this._fire("draw",{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),et.prototype.drawHit.call(this,s,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){u.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return u.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;const t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}destroy(){return u.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}qt.prototype.nodeType="Layer",s(qt),B.addGetterSetter(qt,"imageSmoothingEnabled",!0),B.addGetterSetter(qt,"clearBeforeDraw",!0),B.addGetterSetter(qt,"hitGraphEnabled",!0,G());class Vt extends qt{constructor(t){super(t),this.listening(!1),u.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}Vt.prototype.nodeType="FastLayer",s(Vt);class Ut extends et{_validateAdd(t){const e=t.getType();"Group"!==e&&"Shape"!==e&&u.throw("You may only add groups and shapes to groups.")}}Ut.prototype.nodeType="Group",s(Ut);const Zt=e.performance&&e.performance.now?function(){return e.performance.now()}:function(){return(new Date).getTime()};class Kt{constructor(t,e){this.id=Kt.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:Zt(),frameRate:0},this.func=t,this.setLayers(e)}setLayers(t){let e=[];return t&&(e=Array.isArray(t)?t:[t]),this.layers=e,this}getLayers(){return this.layers}addLayer(t){const e=this.layers,i=e.length;for(let s=0;s<i;s++)if(e[s]._id===t._id)return!1;return this.layers.push(t),!0}isRunning(){const t=Kt.animations,e=t.length;for(let i=0;i<e;i++)if(t[i].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=Zt(),Kt._addAnimation(this),this}stop(){return Kt._removeAnimation(this),this}_updateFrameObject(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(t){this.animations.push(t),this._handleAnimation()}static _removeAnimation(t){const e=t.id,i=this.animations,s=i.length;for(let n=0;n<s;n++)if(i[n].id===e){this.animations.splice(n,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],n=s.layers,r=s.func;s._updateFrameObject(Zt());const o=n.length;let a;if(a=!r||!1!==r.call(s,s.frame),a)for(let e=0;e<o;e++){const i=n[e];void 0!==i._id&&(t[i._id]=i)}}for(const i in t)t.hasOwnProperty(i)&&t[i].batchDraw()}static _animationLoop(){const t=Kt;t.animations.length?(t._runFrames(),u.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,u.requestAnimFrame(this._animationLoop))}}Kt.animations=[],Kt.animIdCounter=0,Kt.animRunning=!1;const Jt={node:1,duration:1,easing:1,onFinish:1,yoyo:1},Qt=["fill","stroke","shadowColor"];let te=0;class ee{constructor(t,e,i,s,n,r,o){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=r,this._change=0,this.prevPos=0,this.yoyo=o,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=n-this.begin,this.pause()}fire(t){const e=this[t];e&&e()}setTime(t){t>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class ie{constructor(t){const e=this,s=t.node,n=s._id,r=t.easing||se.Linear,o=!!t.yoyo;let a,h;a=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=s,this._id=te++;const l=s.getLayer()||(s instanceof i.Stage?s.getLayers():null);for(h in l||u.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Kt(function(){e.tween.onEnterFrame()},l),this.tween=new ee(h,function(t){e._tweenFunc(t)},r,0,1,1e3*a,o),this._addListeners(),ie.attrs[n]||(ie.attrs[n]={}),ie.attrs[n][this._id]||(ie.attrs[n][this._id]={}),ie.tweens[n]||(ie.tweens[n]={}),t)void 0===Jt[h]&&this._addAttr(h,t[h]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){const i=this.node,s=i._id;let n,r,o,a,h;const l=ie.tweens[s][t];l&&delete ie.attrs[s][l][t];let d=i.getAttr(t);if(u._isArray(e))if(n=[],r=Math.max(e.length,d.length),"points"===t&&e.length!==d.length&&(e.length>d.length?(a=d,d=u._prepareArrayForTween(d,e,i.closed())):(o=e,e=u._prepareArrayForTween(e,d,i.closed()))),0===t.indexOf("fill"))for(let c=0;c<r;c++)if(c%2==0)n.push(e[c]-d[c]);else{const t=u.colorToRGBA(d[c]);h=u.colorToRGBA(e[c]),d[c]=t,n.push({r:h.r-t.r,g:h.g-t.g,b:h.b-t.b,a:h.a-t.a})}else for(let c=0;c<r;c++)n.push(e[c]-d[c]);else-1!==Qt.indexOf(t)?(d=u.colorToRGBA(d),h=u.colorToRGBA(e),n={r:h.r-d.r,g:h.g-d.g,b:h.b-d.b,a:h.a-d.a}):n=e-d;ie.attrs[s][this._id][t]={start:d,diff:n,end:e,trueEnd:o,trueStart:a},ie.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=ie.attrs[e._id][this._id];let s,n,r,o,a,h,l,d;for(s in i){if(n=i[s],r=n.start,o=n.diff,d=n.end,u._isArray(r))if(a=[],l=Math.max(r.length,d.length),0===s.indexOf("fill"))for(h=0;h<l;h++)h%2==0?a.push((r[h]||0)+o[h]*t):a.push("rgba("+Math.round(r[h].r+o[h].r*t)+","+Math.round(r[h].g+o[h].g*t)+","+Math.round(r[h].b+o[h].b*t)+","+(r[h].a+o[h].a*t)+")");else for(h=0;h<l;h++)a.push((r[h]||0)+o[h]*t);else a=-1!==Qt.indexOf(s)?"rgba("+Math.round(r.r+o.r*t)+","+Math.round(r.g+o.g*t)+","+Math.round(r.b+o.b*t)+","+(r.a+o.a*t)+")":r+o*t;e.setAttr(s,a)}}_addListeners(){this.tween.onPlay=()=>{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{const t=this.node,e=ie.attrs[t._id][this._id];e.points&&e.points.trueEnd&&t.setAttr("points",e.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{const t=this.node,e=ie.attrs[t._id][this._id];e.points&&e.points.trueStart&&t.points(e.points.trueStart),this.onReset&&this.onReset()},this.tween.onUpdate=()=>{this.onUpdate&&this.onUpdate.call(this)}}play(){return this.tween.play(),this}reverse(){return this.tween.reverse(),this}reset(){return this.tween.reset(),this}seek(t){return this.tween.seek(1e3*t),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){const t=this.node._id,e=this._id,i=ie.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const s in i)delete ie.tweens[t][s];delete ie.attrs[t][e],ie.tweens[t]&&(0===Object.keys(ie.tweens[t]).length&&delete ie.tweens[t],0===Object.keys(ie.attrs[t]).length&&delete ie.attrs[t])}}ie.attrs={},ie.tweens={},Q.prototype.to=function(t){const e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()};new ie(t).play()};const se={BackEaseIn(t,e,i,s){const n=1.70158;return i*(t/=s)*t*((n+1)*t-n)+e},BackEaseOut(t,e,i,s){const n=1.70158;return i*((t=t/s-1)*t*((n+1)*t+n)+1)+e},BackEaseInOut(t,e,i,s){let n=1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(n*=1.525))*t-n))+e:i/2*((t-=2)*t*((1+(n*=1.525))*t+n)+2)+e},ElasticEaseIn(t,e,i,s,n,r){let o=0;return 0===t?e:1===(t/=s)?e+i:(r||(r=.3*s),!n||n<Math.abs(i)?(n=i,o=r/4):o=r/(2*Math.PI)*Math.asin(i/n),-n*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/r)+e)},ElasticEaseOut(t,e,i,s,n,r){let o=0;return 0===t?e:1===(t/=s)?e+i:(r||(r=.3*s),!n||n<Math.abs(i)?(n=i,o=r/4):o=r/(2*Math.PI)*Math.asin(i/n),n*Math.pow(2,-10*t)*Math.sin((t*s-o)*(2*Math.PI)/r)+i+e)},ElasticEaseInOut(t,e,i,s,n,r){let o=0;return 0===t?e:2==(t/=s/2)?e+i:(r||(r=s*(.3*1.5)),!n||n<Math.abs(i)?(n=i,o=r/4):o=r/(2*Math.PI)*Math.asin(i/n),t<1?n*Math.pow(2,10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/r)*-.5+e:n*Math.pow(2,-10*(t-=1))*Math.sin((t*s-o)*(2*Math.PI)/r)*.5+i+e)},BounceEaseOut:(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,s)=>i-se.BounceEaseOut(s-t,0,i,s)+e,BounceEaseInOut:(t,e,i,s)=>t<s/2?.5*se.BounceEaseIn(2*t,0,i,s)+e:.5*se.BounceEaseOut(2*t-s,0,i,s)+.5*i+e,EaseIn:(t,e,i,s)=>i*(t/=s)*t+e,EaseOut:(t,e,i,s)=>-i*(t/=s)*(t-2)+e,EaseInOut:(t,e,i,s)=>(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e,StrongEaseIn:(t,e,i,s)=>i*(t/=s)*t*t*t*t+e,StrongEaseOut:(t,e,i,s)=>i*((t=t/s-1)*t*t*t*t+1)+e,StrongEaseInOut:(t,e,i,s)=>(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e,Linear:(t,e,i,s)=>i*t/s+e},ne=u._assign(i,{Util:u,Transform:r,Node:Q,Container:et,Stage:Gt,stages:It,Layer:qt,FastLayer:Vt,Group:Ut,DD:E,Shape:Xt,shapes:Yt,Animation:Kt,Tween:ie,Easings:se,Context:x,Canvas:_});class re extends Xt{_sceneFunc(t){const e=i.getAngle(this.angle()),s=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,s),t.arc(0,0,this.innerRadius(),e,0,!s),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),s=this.clockwise(),n=i.getAngle(s?360-this.angle():this.angle()),r=Math.cos(Math.min(n,Math.PI)),o=Math.sin(Math.min(Math.max(Math.PI,n),3*Math.PI/2)),a=Math.sin(Math.min(n,Math.PI/2)),h=r*(r>0?t:e),l=o*(o>0?t:e),d=a*(a>0?e:t);return{x:h,y:s?-1*d:l,width:1*e-h,height:d-l}}}function oe(t,e,i,s,n,r,o){const a=Math.sqrt(Math.pow(i-t,2)+Math.pow(s-e,2)),h=Math.sqrt(Math.pow(n-i,2)+Math.pow(r-s,2)),l=o*a/(a+h),d=o*h/(a+h);return[i-l*(n-t),s-l*(r-e),i+d*(n-t),s+d*(r-e)]}function ae(t,e){const i=t.length,s=[];for(let n=2;n<i-2;n+=2){const i=oe(t[n-2],t[n-1],t[n],t[n+1],t[n+2],t[n+3],e);isNaN(i[0])||(s.push(i[0]),s.push(i[1]),s.push(t[n]),s.push(t[n+1]),s.push(i[2]),s.push(i[3]))}return s}re.prototype._centroid=!0,re.prototype.className="Arc",re.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],s(re),B.addGetterSetter(re,"innerRadius",0,A()),B.addGetterSetter(re,"outerRadius",0,A()),B.addGetterSetter(re,"angle",0,A()),B.addGetterSetter(re,"clockwise",!1,G());class he extends Xt{constructor(t){super(t),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(t){const e=this.points(),i=e.length,s=this.tension(),n=this.closed(),r=this.bezier();if(!i)return;let o=0;if(t.beginPath(),t.moveTo(e[0],e[1]),0!==s&&i>4){const s=this.getTensionPoints(),r=s.length;for(o=n?0:4,n||t.quadraticCurveTo(s[0],s[1],s[2],s[3]);o<r-2;)t.bezierCurveTo(s[o++],s[o++],s[o++],s[o++],s[o++],s[o++]);n||t.quadraticCurveTo(s[r-2],s[r-1],e[i-2],e[i-1])}else if(r)for(o=2;o<i;)t.bezierCurveTo(e[o++],e[o++],e[o++],e[o++],e[o++],e[o++]);else for(o=2;o<i;o+=2)t.lineTo(e[o],e[o+1]);n?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():ae(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=oe(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),n=oe(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),r=ae(t,i);return[s[2],s[3]].concat(r).concat([n[0],n[1],t[e-2],t[e-1],n[2],n[3],s[0],s[1],t[0],t[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let t=this.points();if(t.length<4)return{x:t[0]||0,y:t[1]||0,width:0,height:0};t=0!==this.tension()?[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.points();let e,i,s=t[0],n=t[0],r=t[1],o=t[1];for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],s=Math.min(s,e),n=Math.max(n,e),r=Math.min(r,i),o=Math.max(o,i);return{x:s,y:r,width:n-s,height:o-r}}}he.prototype.className="Line",he.prototype._attrsAffectingSize=["points","bezier","tension"],s(he),B.addGetterSetter(he,"closed",!1),B.addGetterSetter(he,"bezier",!1),B.addGetterSetter(he,"tension",0,A()),B.addGetterSetter(he,"points",[],function(){if(i.isUnminified)return function(t,e){const i=Int8Array?Object.getPrototypeOf(Int8Array):null;return i&&t instanceof i||(u._isArray(t)?t.forEach(function(t){u._isNumber(t)||u.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")}):u.warn(M(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),t}}());const le=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],de=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],ce=[[1],[1,1],[1,2,1],[1,3,3,1]],ge=(t,e,i)=>{let s,n;const r=i/2;s=0;for(let o=0;o<20;o++)n=r*le[20][o]+r,s+=de[20][o]*fe(t,e,n);return r*s},ue=(t,e,i)=>{void 0===i&&(i=1);const s=t[0]-2*t[1]+t[2],n=e[0]-2*e[1]+e[2],r=2*t[1]-2*t[0],o=2*e[1]-2*e[0],a=4*(s*s+n*n),h=4*(s*r+n*o),l=r*r+o*o;if(0===a)return i*Math.sqrt(Math.pow(t[2]-t[0],2)+Math.pow(e[2]-e[0],2));const d=h/(2*a),c=i+d,g=l/a-d*d,u=c*c+g>0?Math.sqrt(c*c+g):0,f=d*d+g>0?Math.sqrt(d*d+g):0,p=d+Math.sqrt(d*d+g)!==0?g*Math.log(Math.abs((c+u)/(d+f))):0;return Math.sqrt(a)/2*(c*u-d*f+p)};function fe(t,e,i){const s=pe(1,i,t),n=pe(1,i,e),r=s*s+n*n;return Math.sqrt(r)}const pe=(t,e,i)=>{const s=i.length-1;let n,r;if(0===s)return 0;if(0===t){r=0;for(let t=0;t<=s;t++)r+=ce[s][t]*Math.pow(1-e,s-t)*Math.pow(e,t)*i[t];return r}n=new Array(s);for(let o=0;o<s;o++)n[o]=s*(i[o+1]-i[o]);return pe(t-1,e,n)},me=(t,e,i)=>{let s=1,n=t/e,r=(t-i(n))/e,o=0;for(;s>.001;){const a=i(n+r),h=Math.abs(t-a)/e;if(h<s)s=h,n+=r;else{const o=i(n-r),a=Math.abs(t-o)/e;a<s?(s=a,n-=r):r/=2}if(o++,o>500)break}return n};class ye extends Xt{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=ye.parsePathData(this.data()),this.pathLength=ye.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const n=e[s].command,r=e[s].points;switch(n){case"L":t.lineTo(r[0],r[1]);break;case"M":t.moveTo(r[0],r[1]);break;case"C":t.bezierCurveTo(r[0],r[1],r[2],r[3],r[4],r[5]);break;case"Q":t.quadraticCurveTo(r[0],r[1],r[2],r[3]);break;case"A":const e=r[0],s=r[1],n=r[2],o=r[3],a=r[4],h=r[5],l=r[6],d=r[7],c=n>o?n:o,g=n>o?1:n/o,u=n>o?o/n:1;t.translate(e,s),t.rotate(l),t.scale(g,u),t.arc(0,0,c,a,a+h,1-d),t.scale(1/g,1/u),t.rotate(-l),t.translate(-e,-s);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(e){if("A"===e.command){const i=e.points[4],s=e.points[5],n=e.points[4]+s;let r=Math.PI/180;if(Math.abs(i-n)<r&&(r=Math.abs(i-n)),s<0)for(let o=i-r;o>n;o-=r){const i=ye.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],o,0);t.push(i.x,i.y)}else for(let o=i+r;o<n;o+=r){const i=ye.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],o,0);t.push(i.x,i.y)}}else if("C"===e.command)for(let i=0;i<=1;i+=.01){const s=ye.getPointOnCubicBezier(i,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);t.push(s.x,s.y)}else t=t.concat(e.points)});let e,i,s=t[0],n=t[0],r=t[1],o=t[1];for(let a=0;a<t.length/2;a++)e=t[2*a],i=t[2*a+1],isNaN(e)||(s=Math.min(s,e),n=Math.max(n,e)),isNaN(i)||(r=Math.min(r,i),o=Math.max(o,i));return{x:s,y:r,width:n-s,height:o-r}}getLength(){return this.pathLength}getPointAtLength(t){return ye.getPointAtLengthOfDataArray(t,this.dataArray)}static getLineLength(t,e,i,s){return Math.sqrt((i-t)*(i-t)+(s-e)*(s-e))}static getPathLength(t){let e=0;for(let i=0;i<t.length;++i)e+=t[i].pathLength;return e}static getPointAtLengthOfDataArray(t,e){let i,s=0,n=e.length;if(!n)return null;for(;s<n&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===n)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01){return"M"===e[s].command?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y}}const r=e[s],o=r.points;switch(r.command){case"L":return ye.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return ye.getPointOnCubicBezier(me(t,ye.getPathLength(e),t=>ge([r.start.x,o[0],o[2],o[4]],[r.start.y,o[1],o[3],o[5]],t)),r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return ye.getPointOnQuadraticBezier(me(t,ye.getPathLength(e),t=>ue([r.start.x,o[0],o[2]],[r.start.y,o[1],o[3]],t)),r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":const i=o[0],s=o[1],n=o[2],a=o[3],h=o[5],l=o[6];let d=o[4];return d+=h*t/r.pathLength,ye.getPointOnEllipticalArc(i,s,n,a,d,l)}return null}static getPointOnLine(t,e,i,s,n,r,o){r=null!=r?r:e,o=null!=o?o:i;const a=this.getLineLength(e,i,s,n);if(a<1e-10)return{x:e,y:i};if(s===e)return{x:r,y:o+(n>i?t:-t)};const h=(n-i)/(s-e),l=Math.sqrt(t*t/(1+h*h))*(s<e?-1:1),d=h*l;if(Math.abs(o-i-h*(r-e))<1e-10)return{x:r+l,y:o+d};const c=((r-e)*(s-e)+(o-i)*(n-i))/(a*a),g=e+c*(s-e),u=i+c*(n-i),f=this.getLineLength(r,o,g,u),p=Math.sqrt(t*t-f*f),m=Math.sqrt(p*p/(1+h*h))*(s<e?-1:1);return{x:g+m,y:u+h*m}}static getPointOnCubicBezier(t,e,i,s,n,r,o,a,h){function l(t){return t*t*t}function d(t){return 3*t*t*(1-t)}function c(t){return 3*t*(1-t)*(1-t)}function g(t){return(1-t)*(1-t)*(1-t)}return{x:a*l(t)+r*d(t)+s*c(t)+e*g(t),y:h*l(t)+o*d(t)+n*c(t)+i*g(t)}}static getPointOnQuadraticBezier(t,e,i,s,n,r,o){function a(t){return t*t}function h(t){return 2*t*(1-t)}function l(t){return(1-t)*(1-t)}return{x:r*a(t)+s*h(t)+e*l(t),y:o*a(t)+n*h(t)+i*l(t)}}static getPointOnEllipticalArc(t,e,i,s,n,r){const o=Math.cos(r),a=Math.sin(r),h=i*Math.cos(n),l=s*Math.sin(n);return{x:t+(h*o-l*a),y:e+(h*a+l*o)}}static parsePathData(t){if(!t)return[];let e=t;const i=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];e=e.replace(new RegExp(" ","g"),",");for(let d=0;d<i.length;d++)e=e.replace(new RegExp(i[d],"g"),"|"+i[d]);const s=e.split("|"),n=[],r=[];let o=0,a=0;const h=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let l;for(let d=1;d<s.length;d++){let t=s[d],e=t.charAt(0);for(t=t.slice(1),r.length=0;l=h.exec(t);)r.push(l[0]);let i=[],c="A"===e||"a"===e?0:-1;for(let s=0,n=r.length;s<n;s++){const t=r[s];if("00"!==t)if(c>=0){if(3===c){if(/^[01]{2}\d+(?:\.\d+)?$/.test(t)){i.push(parseInt(t[0],10)),i.push(parseInt(t[1],10)),i.push(parseFloat(t.slice(2))),c+=3,c>=7&&(c-=7);continue}if("11"===t||"10"===t||"01"===t){i.push(parseInt(t[0],10)),i.push(parseInt(t[1],10)),c+=2,c>=7&&(c-=7);continue}if("0"===t||"1"===t){i.push(parseInt(t,10)),c+=1,c>=7&&(c-=7);continue}}else if(4===c){if(/^[01]\d+(?:\.\d+)?$/.test(t)){i.push(parseInt(t[0],10)),i.push(parseFloat(t.slice(1))),c+=2,c>=7&&(c-=7);continue}if("0"===t||"1"===t){i.push(parseInt(t,10)),c+=1,c>=7&&(c-=7);continue}}const e=parseFloat(t);isNaN(e)?i.push(0):i.push(e),c+=1,c>=7&&(c-=7)}else{const e=parseFloat(t);isNaN(e)?i.push(0):i.push(e)}else i.push(0,0),c>=0&&(c+=2,c>=7&&(c-=7))}for(;i.length>0&&!isNaN(i[0]);){let t="",s=[];const r=o,h=a;let l,d,c,g,u,f,p,m,y,x;switch(e){case"l":o+=i.shift(),a+=i.shift(),t="L",s.push(o,a);break;case"L":o=i.shift(),a=i.shift(),s.push(o,a);break;case"m":const r=i.shift(),h=i.shift();if(o+=r,a+=h,t="M",n.length>2&&"z"===n[n.length-1].command)for(let t=n.length-2;t>=0;t--)if("M"===n[t].command){o=n[t].points[0]+r,a=n[t].points[1]+h;break}s.push(o,a),e="l";break;case"M":o=i.shift(),a=i.shift(),t="M",s.push(o,a),e="L";break;case"h":o+=i.shift(),t="L",s.push(o,a);break;case"H":o=i.shift(),t="L",s.push(o,a);break;case"v":a+=i.shift(),t="L",s.push(o,a);break;case"V":a=i.shift(),t="L",s.push(o,a);break;case"C":s.push(i.shift(),i.shift(),i.shift(),i.shift()),o=i.shift(),a=i.shift(),s.push(o,a);break;case"c":s.push(o+i.shift(),a+i.shift(),o+i.shift(),a+i.shift()),o+=i.shift(),a+=i.shift(),t="C",s.push(o,a);break;case"S":d=o,c=a,l=n[n.length-1],"C"===l.command&&(d=o+(o-l.points[2]),c=a+(a-l.points[3])),s.push(d,c,i.shift(),i.shift()),o=i.shift(),a=i.shift(),t="C",s.push(o,a);break;case"s":d=o,c=a,l=n[n.length-1],"C"===l.command&&(d=o+(o-l.points[2]),c=a+(a-l.points[3])),s.push(d,c,o+i.shift(),a+i.shift()),o+=i.shift(),a+=i.shift(),t="C",s.push(o,a);break;case"Q":s.push(i.shift(),i.shift()),o=i.shift(),a=i.shift(),s.push(o,a);break;case"q":s.push(o+i.shift(),a+i.shift()),o+=i.shift(),a+=i.shift(),t="Q",s.push(o,a);break;case"T":d=o,c=a,l=n[n.length-1],"Q"===l.command&&(d=o+(o-l.points[0]),c=a+(a-l.points[1])),o=i.shift(),a=i.shift(),t="Q",s.push(d,c,o,a);break;case"t":d=o,c=a,l=n[n.length-1],"Q"===l.command&&(d=o+(o-l.points[0]),c=a+(a-l.points[1])),o+=i.shift(),a+=i.shift(),t="Q",s.push(d,c,o,a);break;case"A":g=i.shift(),u=i.shift(),f=i.shift(),p=i.shift(),m=i.shift(),y=o,x=a,o=i.shift(),a=i.shift(),t="A",s=this.convertEndpointToCenterParameterization(y,x,o,a,p,m,g,u,f);break;case"a":g=i.shift(),u=i.shift(),f=i.shift(),p=i.shift(),m=i.shift(),y=o,x=a,o+=i.shift(),a+=i.shift(),t="A",s=this.convertEndpointToCenterParameterization(y,x,o,a,p,m,g,u,f)}n.push({command:t||e,points:s,start:{x:r,y:h},pathLength:this.calcLength(r,h,t||e,s)})}"z"!==e&&"Z"!==e||n.push({command:"z",points:[],start:void 0,pathLength:0})}return n}static calcLength(t,e,i,s){let n,r,o,a;const h=ye;switch(i){case"L":return h.getLineLength(t,e,s[0],s[1]);case"C":return ge([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return ue([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":n=0;const i=s[4],l=s[5],d=s[4]+l;let c=Math.PI/180;if(Math.abs(i-d)<c&&(c=Math.abs(i-d)),r=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],i,0),l<0)for(a=i-c;a>d;a-=c)o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],a,0),n+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(a=i+c;a<d;a+=c)o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],a,0),n+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return o=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),n+=h.getLineLength(r.x,r.y,o.x,o.y),n}return 0}static convertEndpointToCenterParameterization(t,e,i,s,n,r,o,a,h){const l=h*(Math.PI/180),d=Math.cos(l)*(t-i)/2+Math.sin(l)*(e-s)/2,c=-1*Math.sin(l)*(t-i)/2+Math.cos(l)*(e-s)/2,g=d*d/(o*o)+c*c/(a*a);g>1&&(o*=Math.sqrt(g),a*=Math.sqrt(g));let u=Math.sqrt((o*o*(a*a)-o*o*(c*c)-a*a*(d*d))/(o*o*(c*c)+a*a*(d*d)));n===r&&(u*=-1),isNaN(u)&&(u=0);const f=u*o*c/a,p=u*-a*d/o,m=(t+i)/2+Math.cos(l)*f-Math.sin(l)*p,y=(e+s)/2+Math.sin(l)*f+Math.cos(l)*p,x=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},v=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(x(t)*x(e))},b=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(v(t,e))},_=b([1,0],[(d-f)/o,(c-p)/a]),w=[(d-f)/o,(c-p)/a],S=[(-1*d-f)/o,(-1*c-p)/a];let C=b(w,S);return v(w,S)<=-1&&(C=Math.PI),v(w,S)>=1&&(C=0),0===r&&C>0&&(C-=2*Math.PI),1===r&&C<0&&(C+=2*Math.PI),[m,y,o,a,_,C,l,r]}}ye.prototype.className="Path",ye.prototype._attrsAffectingSize=["data"],s(ye),B.addGetterSetter(ye,"data");class xe extends he{_sceneFunc(t){super._sceneFunc(t);const e=2*Math.PI,i=this.points();let s=i;const n=0!==this.tension()&&i.length>4;n&&(s=this.getTensionPoints());const r=this.pointerLength(),o=i.length;let a,h;if(n){const t=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[o-2],i[o-1]],e=ye.calcLength(s[s.length-4],s[s.length-3],"C",t),n=ye.getPointOnQuadraticBezier(Math.min(1,1-r/e),t[0],t[1],t[2],t[3],t[4],t[5]);a=i[o-2]-n.x,h=i[o-1]-n.y}else a=i[o-2]-i[o-4],h=i[o-1]-i[o-3];const l=(Math.atan2(h,a)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[o-2],i[o-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-r,d/2),t.lineTo(-r,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),n?(a=(s[0]+s[2])/2-i[0],h=(s[1]+s[3])/2-i[1]):(a=i[2]-i[0],h=i[3]-i[1]),t.rotate((Math.atan2(-h,-a)+e)%e),t.moveTo(0,0),t.lineTo(-r,d/2),t.lineTo(-r,-d/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){const e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x,y:t.y-e,width:t.width,height:t.height+2*e}}}xe.prototype.className="Arrow",s(xe),B.addGetterSetter(xe,"pointerLength",10,A()),B.addGetterSetter(xe,"pointerWidth",10,A()),B.addGetterSetter(xe,"pointerAtBeginning",!1),B.addGetterSetter(xe,"pointerAtEnding",!0);class ve extends Xt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.attrs.radius||0,0,2*Math.PI,!1),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius()!==t/2&&this.radius(t/2)}setHeight(t){this.radius()!==t/2&&this.radius(t/2)}}ve.prototype._centroid=!0,ve.prototype.className="Circle",ve.prototype._attrsAffectingSize=["radius"],s(ve),B.addGetterSetter(ve,"radius",0,A());class be extends Xt{_sceneFunc(t){const e=this.radiusX(),i=this.radiusY();t.beginPath(),t.save(),e!==i&&t.scale(1,i/e),t.arc(0,0,e,0,2*Math.PI,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radiusX()}getHeight(){return 2*this.radiusY()}setWidth(t){this.radiusX(t/2)}setHeight(t){this.radiusY(t/2)}}be.prototype.className="Ellipse",be.prototype._centroid=!0,be.prototype._attrsAffectingSize=["radiusX","radiusY"],s(be),B.addComponentsGetterSetter(be,"radius",["x","y"]),B.addGetterSetter(be,"radiusX",0,A()),B.addGetterSetter(be,"radiusY",0,A());let _e=class t extends Xt{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",t=>{this._removeImageLoad(t.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){const t=!!this.cornerRadius(),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),n=this.attrs.image;let r;if(n){const t=this.attrs.cropWidth,s=this.attrs.cropHeight;r=t&&s?[n,this.cropX(),this.cropY(),t,s,0,0,e,i]:[n,0,0,e,i]}(this.hasFill()||this.hasStroke()||s)&&(t.beginPath(),s?u.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),n&&(s&&t.clip(),t.drawImage.apply(t,r))}_hitFunc(t){const e=this.width(),i=this.height(),s=this.cornerRadius();t.beginPath(),s?u.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e;return null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width}getHeight(){var t,e;return null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height}static fromURL(e,i,s=null){const n=u.createImageElement();n.onload=function(){const e=new t({image:n});i(e)},n.onerror=s,n.crossOrigin="Anonymous",n.src=e}};_e.prototype.className="Image",s(_e),B.addGetterSetter(_e,"cornerRadius",0,T(4)),B.addGetterSetter(_e,"image"),B.addComponentsGetterSetter(_e,"crop",["x","y","width","height"]),B.addGetterSetter(_e,"cropX",0,A()),B.addGetterSetter(_e,"cropY",0,A()),B.addGetterSetter(_e,"cropWidth",0,A()),B.addGetterSetter(_e,"cropHeight",0,A());const we=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],Se="up",Ce="right",ke="down",Re="left",Ee=we.length;class Me extends Ut{constructor(t){super(t),this.on("add.konva",function(t){this._addListeners(t.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(t){let e,i=this;const s=function(){i._sync()};for(e=0;e<Ee;e++)t.on(we[e]+"Change.konva",s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t,e,i,s,n,r,o,a=this.getText(),h=this.getTag();if(a&&h){switch(t=a.width(),e=a.height(),i=h.pointerDirection(),s=h.pointerWidth(),o=h.pointerHeight(),n=0,r=0,i){case Se:n=t/2,r=-1*o;break;case Ce:n=t+s,r=e/2;break;case ke:n=t/2,r=e+o;break;case Re:n=-1*s,r=e/2}h.setAttrs({x:-1*n,y:-1*r,width:t,height:e}),a.setAttrs({x:-1*n,y:-1*r})}}}Me.prototype.className="Label",s(Me);class Pe extends Xt{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),n=this.pointerWidth(),r=this.pointerHeight(),o=this.cornerRadius();let a=0,h=0,l=0,d=0;"number"==typeof o?a=h=l=d=Math.min(o,e/2,i/2):(a=Math.min(o[0]||0,e/2,i/2),h=Math.min(o[1]||0,e/2,i/2),d=Math.min(o[2]||0,e/2,i/2),l=Math.min(o[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(a,0),s===Se&&(t.lineTo((e-n)/2,0),t.lineTo(e/2,-1*r),t.lineTo((e+n)/2,0)),t.lineTo(e-h,0),t.arc(e-h,h,h,3*Math.PI/2,0,!1),s===Ce&&(t.lineTo(e,(i-r)/2),t.lineTo(e+n,i/2),t.lineTo(e,(i+r)/2)),t.lineTo(e,i-d),t.arc(e-d,i-d,d,0,Math.PI/2,!1),s===ke&&(t.lineTo((e+n)/2,i),t.lineTo(e/2,i+r),t.lineTo((e-n)/2,i)),t.lineTo(l,i),t.arc(l,i-l,l,Math.PI/2,Math.PI,!1),s===Re&&(t.lineTo(0,(i+r)/2),t.lineTo(-1*n,i/2),t.lineTo(0,(i-r)/2)),t.lineTo(0,a),t.arc(a,a,a,Math.PI,3*Math.PI/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),n=this.pointerDirection(),r=this.width(),o=this.height();return n===Se?(e-=s,o+=s):n===ke?o+=s:n===Re?(t-=1.5*i,r+=i):n===Ce&&(r+=1.5*i),{x:t,y:e,width:r,height:o}}}Pe.prototype.className="Tag",s(Pe),B.addGetterSetter(Pe,"pointerDirection","none"),B.addGetterSetter(Pe,"pointerWidth",0,A()),B.addGetterSetter(Pe,"pointerHeight",0,A()),B.addGetterSetter(Pe,"cornerRadius",0,T(4));class Ae extends Xt{_sceneFunc(t){const e=this.cornerRadius(),i=this.width(),s=this.height();t.beginPath(),e?u.drawRoundedRectPath(t,i,s,e):t.rect(0,0,i,s),t.closePath(),t.fillStrokeShape(this)}}Ae.prototype.className="Rect",s(Ae),B.addGetterSetter(Ae,"cornerRadius",0,T(4));class Te extends Xt{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),n=this.cornerRadius();if(t.beginPath(),n)u.drawRoundedPolygonPath(t,e,s,i,n);else{t.moveTo(e[0].x,e[0].y);for(let i=1;i<e.length;i++)t.lineTo(e[i].x,e[i].y)}t.closePath(),t.fillStrokeShape(this)}_getPoints(){const t=this.attrs.sides,e=this.attrs.radius||0,i=[];for(let s=0;s<t;s++)i.push({x:e*Math.sin(2*s*Math.PI/t),y:-1*e*Math.cos(2*s*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].y,s=t[0].x,n=t[0].y;return t.forEach(t=>{e=Math.min(e,t.x),i=Math.max(i,t.x),s=Math.min(s,t.y),n=Math.max(n,t.y)}),{x:e,y:s,width:i-e,height:n-s}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}Te.prototype.className="RegularPolygon",Te.prototype._centroid=!0,Te.prototype._attrsAffectingSize=["radius"],s(Te),B.addGetterSetter(Te,"radius",0,A()),B.addGetterSetter(Te,"sides",0,A()),B.addGetterSetter(Te,"cornerRadius",0,T(4));const Le=2*Math.PI;class De extends Xt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,Le,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),Le,0,!0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}De.prototype.className="Ring",De.prototype._centroid=!0,De.prototype._attrsAffectingSize=["innerRadius","outerRadius"],s(De),B.addGetterSetter(De,"innerRadius",0,A()),B.addGetterSetter(De,"outerRadius",0,A());class Ie extends Xt{constructor(t){super(t),this._updated=!0,this.anim=new Kt(()=>{const t=this._updated;return this._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,n=this.animations()[e],r=this.frameOffsets(),o=n[s+0],a=n[s+1],h=n[s+2],l=n[s+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(r){const s=r[e],n=2*i;t.drawImage(d,o,a,h,l,s[n+0],s[n+1],h,l)}else t.drawImage(d,o,a,h,l,0,0,h,l)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,n=this.animations()[e],r=this.frameOffsets(),o=n[s+2],a=n[s+3];if(t.beginPath(),r){const s=r[e],n=2*i;t.rect(s[n+0],s[n+1],o,a)}else t.rect(0,0,o,a);t.closePath(),t.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){const t=this;this.interval=setInterval(function(){t._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;const t=this.getLayer();this.anim.setLayers(t),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){const t=this.frameIndex(),e=this.animation();t<this.animations()[e].length/4-1?this.frameIndex(t+1):this.frameIndex(0)}}Ie.prototype.className="Sprite",s(Ie),B.addGetterSetter(Ie,"animation"),B.addGetterSetter(Ie,"animations"),B.addGetterSetter(Ie,"frameOffsets"),B.addGetterSetter(Ie,"image"),B.addGetterSetter(Ie,"frameIndex",0,A()),B.addGetterSetter(Ie,"frameRate",17,A()),B.backCompat(Ie,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class Ge extends Xt{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let n=1;n<2*s;n++){const r=n%2==0?i:e,o=r*Math.sin(n*Math.PI/s),a=-1*r*Math.cos(n*Math.PI/s);t.lineTo(o,a)}t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}}function Oe(t){return[...t].reduce((t,e,i,s)=>{if(new RegExp("\\p{Emoji}","u").test(e)){const n=s[i+1];n&&new RegExp("\\p{Emoji_Modifier}|\\u200D","u").test(n)?(t.push(e+n),s[i+1]=""):t.push(e)}else new RegExp("\\p{Regional_Indicator}{2}","u").test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&new RegExp("\\p{Mn}|\\p{Me}|\\p{Mc}","u").test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}Ge.prototype.className="Star",Ge.prototype._centroid=!0,Ge.prototype._attrsAffectingSize=["innerRadius","outerRadius"],s(Ge),B.addGetterSetter(Ge,"numPoints",5,A()),B.addGetterSetter(Ge,"innerRadius",0,A()),B.addGetterSetter(Ge,"outerRadius",0,A());const ze="auto",Be="inherit",Fe="justify",Ne="left",We="middle",$e="normal",Ye=" ",Xe="none",He=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],je=He.length;let qe;function Ve(){return qe||(qe=u.createCanvasElement().getContext("2d"),qe)}class Ue extends Xt{constructor(t){super(function(t){return(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||t.fillPatternImage||(t.fill=t.fill||"black"),t}(t)),this._partialTextX=0,this._partialTextY=0;for(let e=0;e<je;e++)this.on(He[e]+"Change.konva",this._setTextData);this._setTextData()}_sceneFunc(t){var e,s;const n=this.textArr,r=n.length;if(!this.text())return;let o,a=this.padding(),h=this.fontSize(),l=this.lineHeight()*h,d=this.verticalAlign(),c=this.direction(),g=0,u=this.align(),f=this.getWidth(),p=this.letterSpacing(),m=this.charRenderFunc(),y=this.fill(),x=this.textDecoration(),v=-1!==x.indexOf("underline"),b=-1!==x.indexOf("line-through");c=c===Be?t.direction:c;let _=l/2,w=We;if(!i.legacyTextRendering){const t=this.measureSize("M");w="alphabetic";_=((null!==(e=t.fontBoundingBoxAscent)&&void 0!==e?e:t.actualBoundingBoxAscent)-(null!==(s=t.fontBoundingBoxDescent)&&void 0!==s?s:t.actualBoundingBoxDescent))/2+l/2}for("rtl"===c&&t.setAttr("direction",c),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",w),t.setAttr("textAlign",Ne),d===We?g=(this.getHeight()-r*l-2*a)/2:"bottom"===d&&(g=this.getHeight()-r*l-2*a),t.translate(a,g+a),o=0;o<r;o++){let e=0,s=0;const d=n[o],g=d.text,x=d.width,w=d.lastInParagraph;if(t.save(),"right"===u?e+=f-x-2*a:"center"===u&&(e+=(f-x-2*a)/2),v){t.save(),t.beginPath();const n=e,r=_+s+(i.legacyTextRendering?Math.round(h/2):Math.round(h/4));t.moveTo(n,r);const o=u!==Fe||w?x:f-2*a;t.lineTo(n+Math.round(o),r),t.lineWidth=h/15;const l=this._getLinearGradient();t.strokeStyle=l||y,t.stroke(),t.restore()}if("rtl"===c||0===p&&u!==Fe&&!m)0!==p&&t.setAttr("letterSpacing",`${p}px`),this._partialTextX=e,this._partialTextY=_+s,this._partialText=g,t.fillStrokeShape(this);else{const i=g.split(" ").length-1,r=Oe(g);for(let h=0;h<r.length;h++){const l=r[h];if(" "!==l||w||u!==Fe||(e+=(f-2*a-x)/i),this._partialTextX=e,this._partialTextY=_+s,this._partialText=l,m){t.save();m({char:l,index:h+n.slice(0,o).reduce((t,e)=>t+Oe(e.text).length,0),x:e,y:_+s,lineIndex:o,column:h,isLastInLine:w,width:this.measureSize(l).width,context:t})}t.fillStrokeShape(this),m&&t.restore(),e+=this.measureSize(l).width+p}}if(b){t.save(),t.beginPath();const n=i.legacyTextRendering?0:-Math.round(h/4),r=u===Fe?0:e;t.moveTo(r,_+s+n);const o=u!==Fe||w?x:f-2*a;t.lineTo(r+Math.round(o),_+s+n),t.lineWidth=h/15;const l=this._getLinearGradient();t.strokeStyle=l||y,t.stroke(),t.restore()}t.restore(),r>1&&(_+=l)}}_hitFunc(t){const e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}setText(t){const e=u._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===ze||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===ze||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return u.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i,s,n,r,o,a,h,l,d,c;let g,u=Ve(),f=this.fontSize();u.save(),u.font=this._getContextFont(),g=u.measureText(t),u.restore();const p=f/100;return{actualBoundingBoxAscent:null!==(e=g.actualBoundingBoxAscent)&&void 0!==e?e:71.58203125*p,actualBoundingBoxDescent:null!==(i=g.actualBoundingBoxDescent)&&void 0!==i?i:0,actualBoundingBoxLeft:null!==(s=g.actualBoundingBoxLeft)&&void 0!==s?s:-7.421875*p,actualBoundingBoxRight:null!==(n=g.actualBoundingBoxRight)&&void 0!==n?n:75.732421875*p,alphabeticBaseline:null!==(r=g.alphabeticBaseline)&&void 0!==r?r:0,emHeightAscent:null!==(o=g.emHeightAscent)&&void 0!==o?o:100*p,emHeightDescent:null!==(a=g.emHeightDescent)&&void 0!==a?a:-20*p,fontBoundingBoxAscent:null!==(h=g.fontBoundingBoxAscent)&&void 0!==h?h:91*p,fontBoundingBoxDescent:null!==(l=g.fontBoundingBoxDescent)&&void 0!==l?l:21*p,hangingBaseline:null!==(d=g.hangingBaseline)&&void 0!==d?d:72.80000305175781*p,ideographicBaseline:null!==(c=g.ideographicBaseline)&&void 0!==c?c:-21*p,width:g.width,height:f}}_getContextFont(){return this.fontStyle()+Ye+this.fontVariant()+Ye+(this.fontSize()+"px ")+this.fontFamily().split(",").map(t=>{const e=(t=t.trim()).indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t=`"${t}"`),t}).join(", ")}_addTextLine(t){this.align()===Fe&&(t=t.trim());const e=this._getTextWidth(t);return this.textArr.push({text:t,width:e,lastInParagraph:!1})}_getTextWidth(t){const e=this.letterSpacing(),i=t.length;return Ve().measureText(t).width+e*i}_setTextData(){let t=this.text().split("\n"),e=+this.fontSize(),i=0,s=this.lineHeight()*e,n=this.attrs.width,r=this.attrs.height,o=n!==ze&&void 0!==n,a=r!==ze&&void 0!==r,h=this.padding(),l=n-2*h,d=r-2*h,c=0,g=this.wrap(),u="char"!==g&&g!==Xe,f=this.ellipsis();this.textArr=[],Ve().font=this._getContextFont();const p=f?this._getTextWidth("…"):0;for(let m=0,y=t.length;m<y;++m){let e=t[m],n=this._getTextWidth(e);if(o&&n>l)for(;e.length>0;){let t=0,r=Oe(e).length,o="",h=0;for(;t<r;){const i=t+r>>>1,n=Oe(e).slice(0,i+1).join(""),g=this._getTextWidth(n);(f&&a&&c+s>d?g+p:g)<=l?(t=i+1,o=n,h=g):r=i}if(!o)break;if(u){const i=Oe(e),s=Oe(o),n=i[s.length];let r;if((n===Ye||"-"===n)&&h<=l)r=s.length;else{const t=s.lastIndexOf(Ye),e=s.lastIndexOf("-");r=Math.max(t,e)+1}r>0&&(t=r,o=i.slice(0,t).join(""),h=this._getTextWidth(o))}o=o.trimRight(),this._addTextLine(o),i=Math.max(i,h),c+=s;if(this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if(e=Oe(e).slice(t).join("").trimLeft(),e.length>0&&(n=this._getTextWidth(e),n<=l)){this._addTextLine(e),c+=s,i=Math.max(i,n);break}}else this._addTextLine(e),c+=s,i=Math.max(i,n),this._shouldHandleEllipsis(c)&&m<y-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),a&&c+s>d)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,n=s!==ze&&void 0!==s,r=s-2*this.padding();return!(this.wrap()!==Xe)||n&&t+i>r}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==ze&&void 0!==t,i=t-2*this.padding(),s=this.ellipsis(),n=this.textArr[this.textArr.length-1];if(n&&s){if(e){this._getTextWidth(n.text+"…")<i||(n.text=n.text.slice(0,n.text.length-3))}this.textArr.splice(this.textArr.length-1,1),this._addTextLine(n.text+"…")}}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=-1!==this.textDecoration().indexOf("underline")||-1!==this.textDecoration().indexOf("line-through"),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas()}}Ue.prototype._fillFunc=function(t){t.fillText(this._partialText,this._partialTextX,this._partialTextY)},Ue.prototype._strokeFunc=function(t){t.setAttr("miterLimit",2),t.strokeText(this._partialText,this._partialTextX,this._partialTextY)},Ue.prototype.className="Text",Ue.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],s(Ue),B.overWriteSetter(Ue,"width",L()),B.overWriteSetter(Ue,"height",L()),B.addGetterSetter(Ue,"direction",Be),B.addGetterSetter(Ue,"fontFamily","Arial"),B.addGetterSetter(Ue,"fontSize",12,A()),B.addGetterSetter(Ue,"fontStyle",$e),B.addGetterSetter(Ue,"fontVariant",$e),B.addGetterSetter(Ue,"padding",0,A()),B.addGetterSetter(Ue,"align",Ne),B.addGetterSetter(Ue,"verticalAlign","top"),B.addGetterSetter(Ue,"lineHeight",1,A()),B.addGetterSetter(Ue,"wrap","word"),B.addGetterSetter(Ue,"ellipsis",!1,G()),B.addGetterSetter(Ue,"letterSpacing",0,A()),B.addGetterSetter(Ue,"text","",D()),B.addGetterSetter(Ue,"textDecoration",""),B.addGetterSetter(Ue,"charRenderFunc",void 0);const Ze="normal";function Ke(t){t.fillText(this.partialText,0,0)}function Je(t){t.strokeText(this.partialText,0,0)}class Qe extends Xt{constructor(t){super(t),this.dummyCanvas=u.createCanvasElement(),this.dataArray=[],this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute(),this._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva",this._setTextData),this._setTextData()}_getTextPathLength(){return ye.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;return t>this.pathLength?null:ye.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=ye.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.textBaseline()),t.setAttr("textAlign","left"),t.save();const e=this.textDecoration(),i=this.fill(),s=this.fontSize(),n=this.glyphInfo;"underline"===e&&t.beginPath();for(let r=0;r<n.length;r++){t.save();const i=n[r].p0;t.translate(i.x,i.y),t.rotate(n[r].rotation),this.partialText=n[r].text,t.fillStrokeShape(this),"underline"===e&&(0===r&&t.moveTo(0,s/2+1),t.lineTo(s,s/2+1)),t.restore()}"underline"===e&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),t.restore()}_hitFunc(t){t.beginPath();const e=this.glyphInfo;if(e.length>=1){const i=e[0].p0;t.moveTo(i.x,i.y)}for(let i=0;i<e.length;i++){const s=e[i].p1;t.lineTo(s.x,s.y)}t.setAttr("lineWidth",this.fontSize()),t.setAttr("strokeStyle",this.colorKey),t.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return u.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(t){return Ue.prototype.setText.call(this,t)}_getContextFont(){return Ue.prototype._getContextFont.call(this)}_getTextSize(t){const e=this.dummyCanvas.getContext("2d");e.save(),e.font=this._getContextFont();const i=e.measureText(t);return e.restore(),{width:i.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const t=Oe(this.text()),e=[];let i=0;for(let c=0;c<t.length;c++)e.push({char:t[c],width:this._getTextSize(t[c]).width}),i+=e[c].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const n=this.letterSpacing(),r=this.align(),o=this.kerningFunc(),a=Math.max(this.textWidth+((this.attrs.text||"").length-1)*n,0);let h=0;"center"===r&&(h=Math.max(0,this.pathLength/2-a/2)),"right"===r&&(h=Math.max(0,this.pathLength-a));let l=h;for(let c=0;c<e.length;c++){const i=this._getPointAtLength(l);if(!i)return;const s=e[c].char;let h=e[c].width+n;if(" "===s&&"justify"===r){const t=this.text().split(" ").length-1;h+=(this.pathLength-a)/t}const g=this._getPointAtLength(l+h);if(!g)return;const u=ye.getLineLength(i.x,i.y,g.x,g.y);let f=0;if(o)try{f=o(e[c-1].char,s)*this.fontSize()}catch(d){f=0}i.x+=f,g.x+=f,this.textWidth+=f;const p=ye.getPointOnLine(f+u/2,i.x,i.y,g.x,g.y),m=Math.atan2(g.y-i.y,g.x-i.x);this.glyphInfo.push({transposeX:p.x,transposeY:p.y,text:t[c],rotation:m,p0:i,p1:g}),l+=h}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(e){t.push(e.p0.x),t.push(e.p0.y),t.push(e.p1.x),t.push(e.p1.y)});let e,i,s=t[0]||0,n=t[0]||0,r=t[1]||0,o=t[1]||0;for(let h=0;h<t.length/2;h++)e=t[2*h],i=t[2*h+1],s=Math.min(s,e),n=Math.max(n,e),r=Math.min(r,i),o=Math.max(o,i);const a=this.fontSize();return{x:s-a/2,y:r-a/2,width:n-s+a,height:o-r+a}}destroy(){return u.releaseCanvas(this.dummyCanvas),super.destroy()}}Qe.prototype._fillFunc=Ke,Qe.prototype._strokeFunc=Je,Qe.prototype._fillFuncHit=Ke,Qe.prototype._strokeFuncHit=Je,Qe.prototype.className="TextPath",Qe.prototype._attrsAffectingSize=["text","fontSize","data"],s(Qe),B.addGetterSetter(Qe,"data"),B.addGetterSetter(Qe,"fontFamily","Arial"),B.addGetterSetter(Qe,"fontSize",12,A()),B.addGetterSetter(Qe,"fontStyle",Ze),B.addGetterSetter(Qe,"align","left"),B.addGetterSetter(Qe,"letterSpacing",0,A()),B.addGetterSetter(Qe,"textBaseline","middle"),B.addGetterSetter(Qe,"fontVariant",Ze),B.addGetterSetter(Qe,"text",""),B.addGetterSetter(Qe,"textDecoration",""),B.addGetterSetter(Qe,"kerningFunc",void 0);const ti="tr-konva",ei=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(t=>t+`.${ti}`).join(" "),ii="nodesRect",si=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],ni={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},ri="ontouchstart"in i._global;const oi=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function ai(t,e,i){const s=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),n=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return{...t,rotation:t.rotation+e,x:s,y:n}}function hi(t,e){const i=function(t){return{x:t.x+t.width/2*Math.cos(t.rotation)+t.height/2*Math.sin(-t.rotation),y:t.y+t.height/2*Math.cos(t.rotation)+t.width/2*Math.sin(t.rotation)}}(t);return ai(t,e,i)}let li=0;class di extends Ut{constructor(t){super(t),this._movingAnchorName=null,this._transforming=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(ei,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return u.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([t])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return ti+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(t=>!t.isAncestorOf(this)||(u.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1));this._nodes=t=e,1===t.length&&this.useSingleNodeRotation()?this.rotation(t[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(t=>{const e=()=>{1===this.nodes().length&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),this._transforming||this.isDragging()||this.update()};if(t._attrsAffectingSize.length){const i=t._attrsAffectingSize.map(t=>t+"Change."+this._getEventNamespace()).join(" ");t.on(i,e)}t.on(si.map(t=>t+`.${this._getEventNamespace()}`).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)}),this._resetTransformCache();return!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,i=>{e=t.getAbsolutePosition(),this.isDragging()||t===this.findOne(".back")||this.startDrag(i,!1)}),t.on(`dragmove.${this._getEventNamespace()}`,i=>{if(!e)return;const s=t.getAbsolutePosition(),n=s.x-e.x,r=s.y-e.y;this.nodes().forEach(e=>{if(e===t)return;if(e.isDragging())return;const s=e.getAbsolutePosition();e.setAbsolutePosition({x:s.x+n,y:s.y+r}),e.startDrag(i)}),e=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(t=>{t.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(ii),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(ii,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),s){const n=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),r=t.getAbsoluteScale(s),o=t.getAbsolutePosition(s),a=n.x*r.x-t.offsetX()*r.x,h=n.y*r.y-t.offsetY()*r.y,l=(i.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return ai({x:o.x+a*Math.cos(l)+h*Math.sin(-l),y:o.y+h*Math.cos(l)+a*Math.sin(l),width:n.width*r.x,height:n.height*r.y,rotation:l},-i.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map(e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),s=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],n=e.getAbsoluteTransform();s.forEach(function(e){const i=n.point(e);t.push(i)})});const e=new r;e.rotate(-i.getAngle(this.rotation()));let s=1/0,n=1/0,o=-1/0,a=-1/0;t.forEach(function(t){const i=e.point(t);void 0===s&&(s=o=i.x,n=a=i.y),s=Math.min(s,i.x),n=Math.min(n,i.y),o=Math.max(o,i.x),a=Math.max(a,i.y)}),e.invert();const h=e.point({x:s,y:n});return{x:h.x,y:h.y,width:o-s,height:a-n,rotation:i.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),oi.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new Ae({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:ri?10:"auto"}),s=this;e.on("mousedown touchstart",function(t){s._handleMouseDown(t)}),e.on("dragstart",t=>{e.stopDrag(),t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),e.on("mouseenter",()=>{const s=i.getAngle(this.rotation()),n=this.rotateAnchorCursor(),r=function(t,e,i){if("rotater"===t)return i;e+=u.degToRad(ni[t]||0);const s=(u.radToDeg(e)%360+360)%360;return u._inRange(s,337.5,360)||u._inRange(s,0,22.5)?"ns-resize":u._inRange(s,22.5,67.5)?"nesw-resize":u._inRange(s,67.5,112.5)?"ew-resize":u._inRange(s,112.5,157.5)?"nwse-resize":u._inRange(s,157.5,202.5)?"ns-resize":u._inRange(s,202.5,247.5)?"nesw-resize":u._inRange(s,247.5,292.5)?"ew-resize":u._inRange(s,292.5,337.5)?"nwse-resize":(u.error("Transformer has unknown angle for cursor detection: "+s),"pointer")}(t,s,n);e.getStage().content&&(e.getStage().content.style.cursor=r),this._cursorChange=!0}),e.on("mouseout",()=>{e.getStage().content&&(e.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(e)}_createBack(){const t=new Xt({name:"back",width:0,height:0,sceneFunc(t,e){const i=e.getParent(),s=i.padding();t.beginPath(),t.rect(-s,-s,e.width()+2*s,e.height()+2*s),t.moveTo(e.width()/2,-s),i.rotateEnabled()&&i.rotateLineVisible()&&t.lineTo(e.width()/2,-i.rotateAnchorOffset()*u._sign(e.height())-s),t.fillStrokeShape(e)},hitFunc:(t,e)=>{if(!this.shouldOverdrawWholeArea())return;const i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}});this.add(t),this._proxyDrag(t),t.on("dragstart",t=>{t.cancelBubble=!0}),t.on("dragmove",t=>{t.cancelBubble=!0}),t.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{this.update()})}_handleMouseDown(t){if(this._transforming)return;this._movingAnchorName=t.target.name().split(" ")[0];const e=this._getNodeRect(),i=e.width,s=e.height,n=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/n),this.cos=Math.abs(i/n),"undefined"!=typeof window&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const r=t.target.getAbsolutePosition(),o=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:o.x-r.x,y:o.y-r.y},li++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(e=>{e._fire("transformstart",{evt:t.evt,target:e})})}_handleMouseMove(t){let e,s,n;const r=this.findOne("."+this._movingAnchorName),o=r.getStage();o.setPointersPositions(t);const a=o.getPointerPosition();let h={x:a.x-this._anchorDragOffset.x,y:a.y-this._anchorDragOffset.y};const l=r.getAbsolutePosition();this.anchorDragBoundFunc()&&(h=this.anchorDragBoundFunc()(l,h,t)),r.setAbsolutePosition(h);const d=r.getAbsolutePosition();if(l.x===d.x&&l.y===d.y)return;if("rotater"===this._movingAnchorName){const n=this._getNodeRect();e=r.x()-n.width/2,s=-r.y()+n.height/2;let o=Math.atan2(-s,e)+Math.PI/2;n.height<0&&(o-=Math.PI);const a=i.getAngle(this.rotation())+o,h=i.getAngle(this.rotationSnapTolerance()),l=function(t,e,s){let n=e;for(let r=0;r<t.length;r++){const o=i.getAngle(t[r]),a=Math.abs(o-e)%(2*Math.PI);Math.min(a,2*Math.PI-a)<s&&(n=o)}return n}(this.rotationSnaps(),a,h),d=hi(n,l-n.rotation);return void this._fitNodesInto(d,t)}const c=this.shiftBehavior();let g;g="inverted"===c?this.keepRatio()&&!t.shiftKey:"none"===c?this.keepRatio():this.keepRatio()||t.shiftKey;let u=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(g){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};n=Math.sqrt(Math.pow(t.x-r.x(),2)+Math.pow(t.y-r.y(),2));const i=this.findOne(".top-left").x()>t.x?-1:1,o=this.findOne(".top-left").y()>t.y?-1:1;e=n*this.cos*i,s=n*this.sin*o,this.findOne(".top-left").x(t.x-e),this.findOne(".top-left").y(t.y-s)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(r.y());else if("top-right"===this._movingAnchorName){if(g){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};n=Math.sqrt(Math.pow(r.x()-t.x,2)+Math.pow(t.y-r.y(),2));const i=this.findOne(".top-right").x()<t.x?-1:1,o=this.findOne(".top-right").y()>t.y?-1:1;e=n*this.cos*i,s=n*this.sin*o,this.findOne(".top-right").x(t.x+e),this.findOne(".top-right").y(t.y-s)}var f=r.position();this.findOne(".top-left").y(f.y),this.findOne(".bottom-right").x(f.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(r.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(r.x());else if("bottom-left"===this._movingAnchorName){if(g){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};n=Math.sqrt(Math.pow(t.x-r.x(),2)+Math.pow(r.y()-t.y,2));const i=t.x<r.x()?-1:1,o=r.y()<t.y?-1:1;e=n*this.cos*i,s=n*this.sin*o,r.x(t.x-e),r.y(t.y+s)}f=r.position(),this.findOne(".top-left").x(f.x),this.findOne(".bottom-right").y(f.y)}else if("bottom-center"===this._movingAnchorName)this.findOne(".bottom-right").y(r.y());else if("bottom-right"===this._movingAnchorName){if(g){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};n=Math.sqrt(Math.pow(r.x()-t.x,2)+Math.pow(r.y()-t.y,2));const i=this.findOne(".bottom-right").x()<t.x?-1:1,o=this.findOne(".bottom-right").y()<t.y?-1:1;e=n*this.cos*i,s=n*this.sin*o,this.findOne(".bottom-right").x(t.x+e),this.findOne(".bottom-right").y(t.y+s)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(u=this.centeredScaling()||t.altKey,u){const t=this.findOne(".top-left"),e=this.findOne(".bottom-right"),i=t.x(),s=t.y(),n=this.getWidth()-e.x(),r=this.getHeight()-e.y();e.move({x:-i,y:-s}),t.move({x:n,y:r})}const p=this.findOne(".top-left").getAbsolutePosition();e=p.x,s=p.y;const m=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),y=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:s,width:m,height:y,rotation:i.getAngle(this.rotation())},t)}_handleMouseUp(t){this._removeEvents(t)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(t){var e;if(this._transforming){this._transforming=!1,"undefined"!=typeof window&&(window.removeEventListener("mousemove",this._handleMouseMove),window.removeEventListener("touchmove",this._handleMouseMove),window.removeEventListener("mouseup",this._handleMouseUp,!0),window.removeEventListener("touchend",this._handleMouseUp,!0));const i=this.getNode();li--,this._fire("transformend",{evt:t,target:i}),null===(e=this.getLayer())||void 0===e||e.batchDraw(),i&&this._nodes.forEach(e=>{var i;e._fire("transformend",{evt:t,target:e}),null===(i=e.getLayer())||void 0===i||i.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const s=this._getNodeRect();if(u._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(u._inRange(t.height,2*-this.padding()-1,1))return void this.update();const n=new r;if(n.rotate(i.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=n.point({x:2*-this.padding(),y:0});t.x+=e.x,t.y+=e.y,t.width+=2*this.padding(),this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y}else if(this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("right")>=0){const e=n.point({x:2*this.padding(),y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.width+=2*this.padding()}if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("top")>=0){const e=n.point({x:0,y:2*-this.padding()});t.x+=e.x,t.y+=e.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}else if(this._movingAnchorName&&t.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const e=n.point({x:0,y:2*this.padding()});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(s,t);e?t=e:u.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const o=1e7,a=new r;a.translate(s.x,s.y),a.rotate(s.rotation),a.scale(s.width/o,s.height/o);const h=new r,l=t.width/o,d=t.height/o;!1===this.flipEnabled()?(h.translate(t.x,t.y),h.rotate(t.rotation),h.translate(t.width<0?t.width:0,t.height<0?t.height:0),h.scale(Math.abs(l),Math.abs(d))):(h.translate(t.x,t.y),h.rotate(t.rotation),h.scale(l,d));const c=h.multiply(a.invert());this._nodes.forEach(t=>{var e;if(!t.getStage())return;const i=t.getParent().getAbsoluteTransform(),s=t.getTransform().copy();s.translate(t.offsetX(),t.offsetY());const n=new r;n.multiply(i.copy().invert()).multiply(c).multiply(i).multiply(s);const o=n.decompose();t.setAttrs(o),null===(e=t.getLayer())||void 0===e||e.batchDraw()}),this.rotation(u._getRotation(t.rotation)),this._nodes.forEach(t=>{this._fire("transform",{evt:e,target:t}),t._fire("transform",{evt:e,target:t})}),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(t,e){this.findOne(t).setAttrs(e)}update(){var t;const e=this._getNodeRect();this.rotation(u._getRotation(e.rotation));const i=e.width,s=e.height,n=this.enabledAnchors(),r=this.resizeEnabled(),o=this.padding(),a=this.anchorSize(),h=this.find("._anchor");h.forEach(t=>{t.setAttrs({width:a,height:a,offsetX:a/2,offsetY:a/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:a/2+o,offsetY:a/2+o,visible:r&&n.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:a/2+o,visible:r&&n.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:a/2-o,offsetY:a/2+o,visible:r&&n.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:a/2+o,visible:r&&n.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:a/2-o,visible:r&&n.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:a/2+o,offsetY:a/2-o,visible:r&&n.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:a/2-o,visible:r&&n.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:a/2-o,offsetY:a/2-o,visible:r&&n.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*u._sign(s)-o,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:i,height:s,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),draggable:this.nodes().some(t=>t.draggable()),x:0,y:0});const l=this.anchorStyleFunc();l&&h.forEach(t=>{l(t)}),null===(t=this.getLayer())||void 0===t||t.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();const t=this.findOne("."+this._movingAnchorName);t&&t.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),Ut.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return Q.prototype.toObject.call(this)}clone(t){return Q.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}di.isTransforming=()=>li>0,di.prototype.className="Transformer",s(di),B.addGetterSetter(di,"enabledAnchors",oi,function(t){return t instanceof Array||u.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach(function(t){-1===oi.indexOf(t)&&u.warn("Unknown anchor name: "+t+". Available names are: "+oi.join(", "))}),t||[]}),B.addGetterSetter(di,"flipEnabled",!0,G()),B.addGetterSetter(di,"resizeEnabled",!0),B.addGetterSetter(di,"anchorSize",10,A()),B.addGetterSetter(di,"rotateEnabled",!0),B.addGetterSetter(di,"rotateLineVisible",!0),B.addGetterSetter(di,"rotationSnaps",[]),B.addGetterSetter(di,"rotateAnchorOffset",50,A()),B.addGetterSetter(di,"rotateAnchorCursor","crosshair"),B.addGetterSetter(di,"rotationSnapTolerance",5,A()),B.addGetterSetter(di,"borderEnabled",!0),B.addGetterSetter(di,"anchorStroke","rgb(0, 161, 255)"),B.addGetterSetter(di,"anchorStrokeWidth",1,A()),B.addGetterSetter(di,"anchorFill","white"),B.addGetterSetter(di,"anchorCornerRadius",0,A()),B.addGetterSetter(di,"borderStroke","rgb(0, 161, 255)"),B.addGetterSetter(di,"borderStrokeWidth",1,A()),B.addGetterSetter(di,"borderDash"),B.addGetterSetter(di,"keepRatio",!0),B.addGetterSetter(di,"shiftBehavior","default"),B.addGetterSetter(di,"centeredScaling",!1),B.addGetterSetter(di,"ignoreStroke",!1),B.addGetterSetter(di,"padding",0,A()),B.addGetterSetter(di,"nodes"),B.addGetterSetter(di,"node"),B.addGetterSetter(di,"boundBoxFunc"),B.addGetterSetter(di,"anchorDragBoundFunc"),B.addGetterSetter(di,"anchorStyleFunc"),B.addGetterSetter(di,"shouldOverdrawWholeArea",!1),B.addGetterSetter(di,"useSingleNodeRotation",!0),B.backCompat(di,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class ci extends Xt{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,i.getAngle(this.angle()),this.clockwise()),t.lineTo(0,0),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}function gi(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}ci.prototype.className="Wedge",ci.prototype._centroid=!0,ci.prototype._attrsAffectingSize=["radius"],s(ci),B.addGetterSetter(ci,"radius",0,A()),B.addGetterSetter(ci,"angle",0,A()),B.addGetterSetter(ci,"clockwise",!1),B.backCompat(ci,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});const ui=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],fi=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];B.addGetterSetter(Q,"blurRadius",0,A(),B.afterSetFilter);B.addGetterSetter(Q,"brightness",0,A(),B.afterSetFilter);B.addGetterSetter(Q,"contrast",0,A(),B.afterSetFilter);function pi(t,e,i,s,n){const r=i-e,o=n-s;if(0===r)return s+o/2;if(0===o)return s;let a=(t-e)/r;return a=o*a+s,a}B.addGetterSetter(Q,"embossStrength",.5,A(),B.afterSetFilter),B.addGetterSetter(Q,"embossWhiteLevel",.5,A(),B.afterSetFilter),B.addGetterSetter(Q,"embossDirection","top-left",void 0,B.afterSetFilter),B.addGetterSetter(Q,"embossBlend",!1,void 0,B.afterSetFilter);B.addGetterSetter(Q,"enhance",0,A(),B.afterSetFilter);B.addGetterSetter(Q,"hue",0,A(),B.afterSetFilter),B.addGetterSetter(Q,"saturation",0,A(),B.afterSetFilter),B.addGetterSetter(Q,"luminance",0,A(),B.afterSetFilter);B.addGetterSetter(Q,"hue",0,A(),B.afterSetFilter),B.addGetterSetter(Q,"saturation",0,A(),B.afterSetFilter),B.addGetterSetter(Q,"value",0,A(),B.afterSetFilter);function mi(t,e,i){let s=4*(i*t.width+e);const n=[];return n.push(t.data[s++],t.data[s++],t.data[s++],t.data[s++]),n}function yi(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}B.addGetterSetter(Q,"kaleidoscopePower",2,A(),B.afterSetFilter),B.addGetterSetter(Q,"kaleidoscopeAngle",0,A(),B.afterSetFilter);B.addGetterSetter(Q,"threshold",0,A(),B.afterSetFilter);B.addGetterSetter(Q,"noise",.2,A(),B.afterSetFilter);B.addGetterSetter(Q,"pixelSize",8,A(),B.afterSetFilter);B.addGetterSetter(Q,"levels",.5,A(),B.afterSetFilter);B.addGetterSetter(Q,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),B.addGetterSetter(Q,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),B.addGetterSetter(Q,"blue",0,P,B.afterSetFilter);B.addGetterSetter(Q,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),B.addGetterSetter(Q,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),B.addGetterSetter(Q,"blue",0,P,B.afterSetFilter),B.addGetterSetter(Q,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t});B.addGetterSetter(Q,"threshold",.5,A(),B.afterSetFilter);const xi=ne.Util._assign(ne,{Arc:re,Arrow:xe,Circle:ve,Ellipse:be,Image:_e,Label:Me,Tag:Pe,Line:he,Path:ye,Rect:Ae,RegularPolygon:Te,Ring:De,Sprite:Ie,Star:Ge,Text:Ue,TextPath:Qe,Transformer:di,Wedge:ci,Filters:{Blur:function(t){const e=Math.round(this.blurRadius());e>0&&function(t,e){const i=t.data,s=t.width,n=t.height;let r,o,a,h,l,d,c,g,u,f,p,m,y,x,v,b,_,w,S,C;const k=e+e+1,R=s-1,E=n-1,M=e+1,P=M*(M+1)/2,A=new gi,T=ui[e],L=fi[e];let D=null,I=A,G=null,O=null;for(let z=1;z<k;z++)I=I.next=new gi,z===M&&(D=I);I.next=A,a=o=0;for(let z=0;z<n;z++){m=y=x=v=h=l=d=c=0,g=M*(b=i[o]),u=M*(_=i[o+1]),f=M*(w=i[o+2]),p=M*(S=i[o+3]),h+=P*b,l+=P*_,d+=P*w,c+=P*S,I=A;for(let t=0;t<M;t++)I.r=b,I.g=_,I.b=w,I.a=S,I=I.next;for(let t=1;t<M;t++)r=o+((R<t?R:t)<<2),h+=(I.r=b=i[r])*(C=M-t),l+=(I.g=_=i[r+1])*C,d+=(I.b=w=i[r+2])*C,c+=(I.a=S=i[r+3])*C,m+=b,y+=_,x+=w,v+=S,I=I.next;G=A,O=D;for(let t=0;t<s;t++)i[o+3]=S=c*T>>L,0!==S?(S=255/S,i[o]=(h*T>>L)*S,i[o+1]=(l*T>>L)*S,i[o+2]=(d*T>>L)*S):i[o]=i[o+1]=i[o+2]=0,h-=g,l-=u,d-=f,c-=p,g-=G.r,u-=G.g,f-=G.b,p-=G.a,r=a+((r=t+e+1)<R?r:R)<<2,m+=G.r=i[r],y+=G.g=i[r+1],x+=G.b=i[r+2],v+=G.a=i[r+3],h+=m,l+=y,d+=x,c+=v,G=G.next,g+=b=O.r,u+=_=O.g,f+=w=O.b,p+=S=O.a,m-=b,y-=_,x-=w,v-=S,O=O.next,o+=4;a+=s}for(let z=0;z<s;z++){y=x=v=m=l=d=c=h=0,o=z<<2,g=M*(b=i[o]),u=M*(_=i[o+1]),f=M*(w=i[o+2]),p=M*(S=i[o+3]),h+=P*b,l+=P*_,d+=P*w,c+=P*S,I=A;for(let e=0;e<M;e++)I.r=b,I.g=_,I.b=w,I.a=S,I=I.next;let t=s;for(let n=1;n<=e;n++)o=t+z<<2,h+=(I.r=b=i[o])*(C=M-n),l+=(I.g=_=i[o+1])*C,d+=(I.b=w=i[o+2])*C,c+=(I.a=S=i[o+3])*C,m+=b,y+=_,x+=w,v+=S,I=I.next,n<E&&(t+=s);o=z,G=A,O=D;for(let e=0;e<n;e++)r=o<<2,i[r+3]=S=c*T>>L,S>0?(S=255/S,i[r]=(h*T>>L)*S,i[r+1]=(l*T>>L)*S,i[r+2]=(d*T>>L)*S):i[r]=i[r+1]=i[r+2]=0,h-=g,l-=u,d-=f,c-=p,g-=G.r,u-=G.g,f-=G.b,p-=G.a,r=z+((r=e+M)<E?r:E)*s<<2,h+=m+=G.r=i[r],l+=y+=G.g=i[r+1],d+=x+=G.b=i[r+2],c+=v+=G.a=i[r+3],G=G.next,g+=b=O.r,u+=_=O.g,f+=w=O.b,p+=S=O.a,m-=b,y-=_,x-=w,v-=S,O=O.next,o+=s}}(t,e)},Brightness:function(t){const e=this.brightness(),i=t.data,s=i.length;for(let n=0;n<s;n+=4)i[n]=Math.min(255,i[n]*e),i[n+1]=Math.min(255,i[n+1]*e),i[n+2]=Math.min(255,i[n+2]*e)},Brighten:function(t){const e=255*this.brightness(),i=t.data,s=i.length;for(let n=0;n<s;n+=4)i[n]+=e,i[n+1]+=e,i[n+2]+=e},Contrast:function(t){const e=Math.pow((this.contrast()+100)/100,2),i=t.data,s=i.length;let n=150,r=150,o=150;for(let a=0;a<s;a+=4)n=i[a],r=i[a+1],o=i[a+2],n/=255,n-=.5,n*=e,n+=.5,n*=255,r/=255,r-=.5,r*=e,r+=.5,r*=255,o/=255,o-=.5,o*=e,o+=.5,o*=255,n=n<0?0:n>255?255:n,r=r<0?0:r>255?255:r,o=o<0?0:o>255?255:o,i[a]=n,i[a+1]=r,i[a+2]=o},Emboss:function(t){var e,i,s,n,r,o,a,h,l;const d=t.data,c=t.width,g=t.height,u=Math.min(1,Math.max(0,null!==(i=null===(e=this.embossStrength)||void 0===e?void 0:e.call(this))&&void 0!==i?i:.5)),f=Math.min(1,Math.max(0,null!==(n=null===(s=this.embossWhiteLevel)||void 0===s?void 0:s.call(this))&&void 0!==n?n:.5)),p=null!==(a={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[null!==(o=null===(r=this.embossDirection)||void 0===r?void 0:r.call(this))&&void 0!==o?o:"top-left"])&&void 0!==a?a:315,m=!(null===(l=null===(h=this.embossBlend)||void 0===h?void 0:h.call(this))||void 0===l||!l),y=10*u,x=255*f,v=p*Math.PI/180,b=Math.cos(v),_=Math.sin(v),w=128/1020*y,S=new Uint8ClampedArray(d),C=new Float32Array(c*g);for(let P=0,A=0;A<d.length;A+=4,P++)C[P]=.2126*S[A]+.7152*S[A+1]+.0722*S[A+2];const k=[-1,0,1,-2,0,2,-1,0,1],R=[-1,-2,-1,0,0,0,1,2,1],E=[-c-1,-c,1-c,-1,0,1,c-1,c,c+1],M=t=>t<0?0:t>255?255:t;for(let P=1;P<g-1;P++)for(let t=1;t<c-1;t++){const e=P*c+t;let i=0,s=0;i+=C[e+E[0]]*k[0],s+=C[e+E[0]]*R[0],i+=C[e+E[1]]*k[1],s+=C[e+E[1]]*R[1],i+=C[e+E[2]]*k[2],s+=C[e+E[2]]*R[2],i+=C[e+E[3]]*k[3],s+=C[e+E[3]]*R[3],i+=C[e+E[5]]*k[5],s+=C[e+E[5]]*R[5],i+=C[e+E[6]]*k[6],s+=C[e+E[6]]*R[6],i+=C[e+E[7]]*k[7],s+=C[e+E[7]]*R[7],i+=C[e+E[8]]*k[8],s+=C[e+E[8]]*R[8];const n=M(x+(b*i+_*s)*w),r=4*e;if(m){const t=n-x;d[r]=M(S[r]+t),d[r+1]=M(S[r+1]+t),d[r+2]=M(S[r+2]+t),d[r+3]=S[r+3]}else d[r]=d[r+1]=d[r+2]=n,d[r+3]=S[r+3]}for(let P=0;P<c;P++){let t=4*P,e=4*((g-1)*c+P);d[t]=S[t],d[t+1]=S[t+1],d[t+2]=S[t+2],d[t+3]=S[t+3],d[e]=S[e],d[e+1]=S[e+1],d[e+2]=S[e+2],d[e+3]=S[e+3]}for(let P=1;P<g-1;P++){let t=P*c*4,e=4*(P*c+(c-1));d[t]=S[t],d[t+1]=S[t+1],d[t+2]=S[t+2],d[t+3]=S[t+3],d[e]=S[e],d[e+1]=S[e+1],d[e+2]=S[e+2],d[e+3]=S[e+3]}return t},Enhance:function(t){const e=t.data,i=e.length;let s,n,r,o=e[0],a=o,h=e[1],l=h,d=e[2],c=d;const g=this.enhance();if(0===g)return;for(let v=0;v<i;v+=4)s=e[v+0],s<o?o=s:s>a&&(a=s),n=e[v+1],n<h?h=n:n>l&&(l=n),r=e[v+2],r<d?d=r:r>c&&(c=r);let u,f,p,m,y,x;if(a===o&&(a=255,o=0),l===h&&(l=255,h=0),c===d&&(c=255,d=0),g>0)u=a+g*(255-a),f=o-g*(o-0),p=l+g*(255-l),m=h-g*(h-0),y=c+g*(255-c),x=d-g*(d-0);else{const t=.5*(a+o);u=a+g*(a-t),f=o+g*(o-t);const e=.5*(l+h);p=l+g*(l-e),m=h+g*(h-e);const i=.5*(c+d);y=c+g*(c-i),x=d+g*(d-i)}for(let v=0;v<i;v+=4)e[v+0]=pi(e[v+0],o,a,f,u),e[v+1]=pi(e[v+1],h,l,m,p),e[v+2]=pi(e[v+2],d,c,x,y)},Grayscale:function(t){const e=t.data,i=e.length;for(let s=0;s<i;s+=4){const t=.34*e[s]+.5*e[s+1]+.16*e[s+2];e[s]=t,e[s+1]=t,e[s+2]=t}},HSL:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,r=127*this.luminance(),o=1*s*Math.cos(n*Math.PI/180),a=1*s*Math.sin(n*Math.PI/180),h=.299+.701*o+.167*a,l=.587-.587*o+.33*a,d=.114-.114*o-.497*a,c=.299-.299*o-.328*a,g=.587+.413*o+.035*a,u=.114-.114*o+.293*a,f=.299-.3*o+1.25*a,p=.587-.586*o-1.05*a,m=.114+.886*o-.2*a;let y,x,v,b;for(let _=0;_<i;_+=4)y=e[_+0],x=e[_+1],v=e[_+2],b=e[_+3],e[_+0]=h*y+l*x+d*v+r,e[_+1]=c*y+g*x+u*v+r,e[_+2]=f*y+p*x+m*v+r,e[_+3]=b},HSV:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.value()),n=Math.pow(2,this.saturation()),r=Math.abs(this.hue()+360)%360,o=s*n*Math.cos(r*Math.PI/180),a=s*n*Math.sin(r*Math.PI/180),h=.299*s+.701*o+.167*a,l=.587*s-.587*o+.33*a,d=.114*s-.114*o-.497*a,c=.299*s-.299*o-.328*a,g=.587*s+.413*o+.035*a,u=.114*s-.114*o+.293*a,f=.299*s-.3*o+1.25*a,p=.587*s-.586*o-1.05*a,m=.114*s+.886*o-.2*a;for(let y=0;y<i;y+=4){const t=e[y+0],i=e[y+1],s=e[y+2],n=e[y+3];e[y+0]=h*t+l*i+d*s,e[y+1]=c*t+g*i+u*s,e[y+2]=f*t+p*i+m*s,e[y+3]=n}},Invert:function(t){const e=t.data,i=e.length;for(let s=0;s<i;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2]},Kaleidoscope:function(t){const e=t.width,i=t.height;let s,n,r,o,a,h,l,d,c,g,f=Math.round(this.kaleidoscopePower());const p=Math.round(this.kaleidoscopeAngle()),m=Math.floor(e*(p%360)/360);if(f<1)return;const y=u.createCanvasElement();y.width=e,y.height=i;const x=y.getContext("2d").getImageData(0,0,e,i);u.releaseCanvas(y),function(t,e,i){const s=t.data,n=e.data,r=t.width,o=t.height,a=i.polarCenterX||r/2,h=i.polarCenterY||o/2;let l=Math.sqrt(a*a+h*h),d=r-a,c=o-h;const g=Math.sqrt(d*d+c*c);l=g>l?g:l;const u=o,f=r,p=360/f*Math.PI/180;for(let m=0;m<f;m+=1){const t=Math.sin(m*p),e=Math.cos(m*p);for(let i=0;i<u;i+=1){d=Math.floor(a+l*i/u*e),c=Math.floor(h+l*i/u*t);let o=4*(c*r+d);const g=s[o+0],f=s[o+1],p=s[o+2],y=s[o+3];o=4*(m+i*r),n[o+0]=g,n[o+1]=f,n[o+2]=p,n[o+3]=y}}}(t,x,{polarCenterX:e/2,polarCenterY:i/2});let v=e/Math.pow(2,f);for(;v<=8;)v*=2,f-=1;v=Math.ceil(v);let b=v,_=0,w=b,S=1;for(m+v>e&&(_=b,w=0,S=-1),n=0;n<i;n+=1)for(s=_;s!==w;s+=S)r=Math.round(s+m)%e,c=4*(e*n+r),a=x.data[c+0],h=x.data[c+1],l=x.data[c+2],d=x.data[c+3],g=4*(e*n+s),x.data[g+0]=a,x.data[g+1]=h,x.data[g+2]=l,x.data[g+3]=d;for(n=0;n<i;n+=1)for(b=Math.floor(v),o=0;o<f;o+=1){for(s=0;s<b+1;s+=1)c=4*(e*n+s),a=x.data[c+0],h=x.data[c+1],l=x.data[c+2],d=x.data[c+3],g=4*(e*n+2*b-s-1),x.data[g+0]=a,x.data[g+1]=h,x.data[g+2]=l,x.data[g+3]=d;b*=2}!function(t,e,i){const s=t.data,n=e.data,r=t.width,o=t.height,a=i.polarCenterX||r/2,h=i.polarCenterY||o/2;let l=Math.sqrt(a*a+h*h),d=r-a,c=o-h;const g=Math.sqrt(d*d+c*c);l=g>l?g:l;const u=o,f=r;let p,m;for(d=0;d<r;d+=1)for(c=0;c<o;c+=1){const t=d-a,e=c-h,i=Math.sqrt(t*t+e*e)*u/l;let o=(180*Math.atan2(e,t)/Math.PI+360+0)%360;o=o*f/360,p=Math.floor(o),m=Math.floor(i);let g=4*(m*r+p);const y=s[g+0],x=s[g+1],v=s[g+2],b=s[g+3];g=4*(c*r+d),n[g+0]=y,n[g+1]=x,n[g+2]=v,n[g+3]=b}}(x,t,{})},Mask:function(t){let e=function(t,e){const i=mi(t,0,0),s=mi(t,t.width-1,0),n=mi(t,0,t.height-1),r=mi(t,t.width-1,t.height-1),o=e||10;if(yi(i,s)<o&&yi(s,r)<o&&yi(r,n)<o&&yi(n,i)<o){const e=function(t){const e=[0,0,0];for(let i=0;i<t.length;i++)e[0]+=t[i][0],e[1]+=t[i][1],e[2]+=t[i][2];return e[0]/=t.length,e[1]/=t.length,e[2]/=t.length,e}([s,i,r,n]),a=[];for(let i=0;i<t.width*t.height;i++){const s=yi(e,[t.data[4*i],t.data[4*i+1],t.data[4*i+2]]);a[i]=s<o?0:255}return a}}(t,this.threshold());return e&&(e=function(t,e,i){const s=[1,1,1,1,0,1,1,1,1],n=Math.round(Math.sqrt(s.length)),r=Math.floor(n/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<n;o++)for(let l=0;l<n;l++){const c=a+o-r,g=h+l-r;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*n+l];d+=t[c*e+g]*i}}o[l]=2040===d?255:0}return o}(e,t.width,t.height),e=function(t,e,i){const s=[1,1,1,1,1,1,1,1,1],n=Math.round(Math.sqrt(s.length)),r=Math.floor(n/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<n;o++)for(let l=0;l<n;l++){const c=a+o-r,g=h+l-r;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*n+l];d+=t[c*e+g]*i}}o[l]=d>=1020?255:0}return o}(e,t.width,t.height),e=function(t,e,i){const s=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],n=Math.round(Math.sqrt(s.length)),r=Math.floor(n/2),o=[];for(let a=0;a<i;a++)for(let h=0;h<e;h++){const l=a*e+h;let d=0;for(let o=0;o<n;o++)for(let l=0;l<n;l++){const c=a+o-r,g=h+l-r;if(c>=0&&c<i&&g>=0&&g<e){const i=s[o*n+l];d+=t[c*e+g]*i}}o[l]=d}return o}(e,t.width,t.height),function(t,e){for(let i=0;i<t.width*t.height;i++)t.data[4*i+3]=e[i]}(t,e)),t},Noise:function(t){const e=255*this.noise(),i=t.data,s=i.length,n=e/2;for(let r=0;r<s;r+=4)i[r+0]+=n-2*n*Math.random(),i[r+1]+=n-2*n*Math.random(),i[r+2]+=n-2*n*Math.random()},Pixelate:function(t){let e=Math.ceil(this.pixelSize()),i=t.width,s=t.height,n=Math.ceil(i/e),r=Math.ceil(s/e),o=t.data;if(e<=0)u.error("pixelSize value can not be <= 0");else for(let a=0;a<n;a+=1)for(let t=0;t<r;t+=1){let n=0,r=0,h=0,l=0;const d=a*e,c=d+e,g=t*e,u=g+e;let f=0;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=g;e<u;e+=1){if(e>=s)continue;const a=4*(i*e+t);n+=o[a+0],r+=o[a+1],h+=o[a+2],l+=o[a+3],f+=1}n/=f,r/=f,h/=f,l/=f;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=g;e<u;e+=1){if(e>=s)continue;const a=4*(i*e+t);o[a+0]=n,o[a+1]=r,o[a+2]=h,o[a+3]=l}}},Posterize:function(t){const e=Math.round(254*this.levels())+1,i=t.data,s=i.length,n=255/e;for(let r=0;r<s;r+=1)i[r]=Math.floor(i[r]/n)*n},RGB:function(t){const e=t.data,i=e.length,s=this.red(),n=this.green(),r=this.blue();for(let o=0;o<i;o+=4){const t=(.34*e[o]+.5*e[o+1]+.16*e[o+2])/255;e[o]=t*s,e[o+1]=t*n,e[o+2]=t*r,e[o+3]=e[o+3]}},RGBA:function(t){const e=t.data,i=e.length,s=this.red(),n=this.green(),r=this.blue(),o=this.alpha();for(let a=0;a<i;a+=4){const t=1-o;e[a]=s*o+e[a]*t,e[a+1]=n*o+e[a+1]*t,e[a+2]=r*o+e[a+2]*t}},Sepia:function(t){const e=t.data,i=e.length;for(let s=0;s<i;s+=4){const t=e[s+0],i=e[s+1],n=e[s+2];e[s+0]=Math.min(255,.393*t+.769*i+.189*n),e[s+1]=Math.min(255,.349*t+.686*i+.168*n),e[s+2]=Math.min(255,.272*t+.534*i+.131*n)}},Solarize:function(t){const e=t.data;for(let i=0;i<e.length;i+=4){const t=e[i],s=e[i+1],n=e[i+2];.2126*t+.7152*s+.0722*n>=128&&(e[i]=255-t,e[i+1]=255-s,e[i+2]=255-n)}return t},Threshold:function(t){const e=255*this.threshold(),i=t.data,s=i.length;for(let n=0;n<s;n+=1)i[n]=i[n]<e?0:255}}}),vi=["north","south","east","west","northeast","northwest","southeast","southwest"],bi={n:"north",s:"south",e:"east",w:"west",ne:"northeast",nw:"northwest",se:"southeast",sw:"southwest"},_i={north:"n",south:"s",east:"e",west:"w",northeast:"ne",northwest:"nw",southeast:"se",southwest:"sw",up:"u",down:"d",in:"i",out:"o"},wi={north:{x:0,y:-1},south:{x:0,y:1},east:{x:1,y:0},west:{x:-1,y:0},northeast:{x:1,y:-1},northwest:{x:-1,y:-1},southeast:{x:1,y:1},southwest:{x:-1,y:1}},Si=["north","south","east","west","northeast","northwest","southeast","southwest"],Ci={north:"south",south:"north",east:"west",west:"east",northeast:"southwest",northwest:"southeast",southeast:"northwest",southwest:"northeast"};function ki(t){return!!t&&Object.prototype.hasOwnProperty.call(wi,t)}function Ri(t,e,i,s=1){if(!ki(i))return{x:t,y:e};const n=wi[i];return{x:t+n.x*s,y:e+n.y*s}}function Ei(t,e,i,s=1,n=0){if(!ki(i))return{x:t,y:e};const r=wi[i];if(0===r.x||0===r.y||n<=0)return Ri(t,e,i,s);const o=s-n+n/Math.SQRT2;return{x:t+r.x*o,y:e+r.y*o}}function Mi(t,e,i,s=1){if(!ki(i))return{x:t,y:e};const n=wi[i],r=Math.atan2(n.y,n.x);return{x:t+Math.cos(r)*s,y:e+Math.sin(r)*s}}const Pi="rgb(10, 155, 10)",Ai="rgb(226, 205, 59)",Ti="rgb(155, 10, 10)",Li="rgb(155, 10, 10)",Di={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"},Ii=["up","down","in","out"];function Gi(t){switch(t){case 1:return Pi;case 2:return Ai;default:return Ti}}class Oi{constructor(t,e,i){this.mapReader=t,this.mapRenderer=e,this.settings=i}getRoomEdgePoint(t,e,i,s){return"circle"===this.settings.roomShape?Mi(t,e,i,s):"roundedRectangle"===this.settings.roomShape?Ei(t,e,i,s,.2*this.settings.roomSize):Ri(t,e,i,s)}renderData(t,e){return this.renderDataWithColor(t,this.settings.lineColor,e)}renderDataWithColor(t,e,i){const s=t.aDir&&vi.includes(t.aDir),n=t.bDir&&vi.includes(t.bDir);if(s&&n)return this.renderTwoWayExitData(t,e,i);if(s||n){const i=s?"a":"b";return this.renderOneWayExitData(t,e,i)}}renderTwoWayExitData(t,e,i){const s=this.mapReader.getRoom(t.a),n=this.mapReader.getRoom(t.b);if(!s||!n||!t.aDir||!t.bDir||s.customLines[_i[t.aDir]]&&n.customLines[_i[t.bDir]]||s.z!==n.z&&(i!==n.z&&s.customLines[_i[t.aDir]]||i!==s.z&&n.customLines[_i[t.bDir]]))return;const r=this.getRoomEdgePoint(s.x,s.y,t.aDir,this.settings.roomSize/2),o=this.getRoomEdgePoint(n.x,n.y,t.bDir,this.settings.roomSize/2),a=[r.x,r.y,o.x,o.y],h=[{points:a,stroke:e,strokeWidth:this.settings.lineWidth}],l=[],d=s.doors[_i[t.aDir]]??n.doors[_i[t.bDir]];if(d){const t=a[0]+(a[2]-a[0])/2,e=a[1]+(a[3]-a[1])/2;l.push({x:t-this.settings.roomSize/4,y:e-this.settings.roomSize/4,width:this.settings.roomSize/2,height:this.settings.roomSize/2,stroke:Gi(d),strokeWidth:this.settings.lineWidth})}const c=Math.min(a[0],a[2]),g=Math.max(a[0],a[2]),u=Math.min(a[1],a[3]);return{lines:h,arrows:[],doors:l,bounds:{x:c,y:u,width:g-c,height:Math.max(a[1],a[3])-u},targetRoomId:s.z!==n.z?s.z===i?n.id:s.id:void 0}}renderOneWayExitData(t,e,i){const s="a"===i||!i&&t.aDir,n=s?this.mapReader.getRoom(t.a):this.mapReader.getRoom(t.b),r=s?this.mapReader.getRoom(t.b):this.mapReader.getRoom(t.a),o=s?t.aDir:t.bDir;if(!o||!n||!r||!vi.includes(o)||n.customLines[_i[o]||o])return;if(n.area!=r.area&&o){const t=this.mapReader.getColorValue(r.env),e=this.getRoomEdgePoint(n.x,n.y,o,this.settings.roomSize/2),i=Ri(n.x,n.y,o,1.5*this.settings.roomSize),s=t;return{lines:[],arrows:[{points:[e.x,e.y,i.x,i.y],pointerLength:.3,pointerWidth:.3,strokeWidth:1.4*this.settings.lineWidth,stroke:s,fill:s}],doors:[],bounds:{x:Math.min(e.x,i.x),y:Math.min(e.y,i.y),width:Math.abs(i.x-e.x),height:Math.abs(i.y-e.y)},targetRoomId:r.id}}const a=r.area!==n.area||r.z!==n.z;let h={x:r.x,y:r.y};a&&(h=Ri(n.x,n.y,o,this.settings.roomSize/2));const l=Ri(n.x,n.y,o,.3),d=l.x-(l.x-h.x)/2,c=l.y-(l.y-h.y)/2,g=this.getRoomEdgePoint(n.x,n.y,o,this.settings.roomSize/2),u=[g.x,g.y,h.x,h.y],f=[g.x,h.x,d],p=[g.y,h.y,c],m=Math.min(...f),y=Math.max(...f),x=Math.min(...p),v=Math.max(...p);return{lines:[{points:u,stroke:e,strokeWidth:this.settings.lineWidth,dash:[.1,.05]}],arrows:[{points:[u[0],u[1],d,c],pointerLength:.5,pointerWidth:.35,strokeWidth:1.4*this.settings.lineWidth,stroke:e,fill:Li,dash:[.1,.05]}],doors:[],bounds:{x:m,y:x,width:y-m,height:v-x},...a?{targetRoomId:r.id}:{}}}render(t,e){return this.renderWithColor(t,this.settings.lineColor,e)}renderWithColor(t,e,i){const s=t.aDir&&vi.includes(t.aDir),n=t.bDir&&vi.includes(t.bDir);if(s&&n)return this.renderTwoWayExit(t,e,i);if(s||n){const i=s?"a":"b";return this.renderOneWayExit(t,e,i)}}renderTwoWayExit(t,e,i){const s=this.mapReader.getRoom(t.a),n=this.mapReader.getRoom(t.b);if(!s||!n||!t.aDir||!t.bDir||s.customLines[_i[t.aDir]]&&n.customLines[_i[t.bDir]]||s.z!==n.z&&(i!==n.z&&s.customLines[_i[t.aDir]]||i!==s.z&&n.customLines[_i[t.bDir]]))return;const r=new xi.Group({listening:!1}),o=[];if(o.push(...Object.values(this.getRoomEdgePoint(s.x,s.y,t.aDir,this.settings.roomSize/2))),o.push(...Object.values(this.getRoomEdgePoint(n.x,n.y,t.bDir,this.settings.roomSize/2))),s.doors[_i[t.aDir]]||n.doors[_i[t.bDir]]){const e=this.renderDoor(o,s.doors[_i[t.aDir]]??n.doors[_i[t.bDir]]);r.add(e)}const a=new xi.Line({points:o,stroke:e,strokeWidth:this.settings.lineWidth,perfectDrawEnabled:!1,listening:!1});return r.add(a),r}renderOneWayExit(t,e,i){const s="a"===i||!i&&t.aDir,n=s?this.mapReader.getRoom(t.a):this.mapReader.getRoom(t.b),r=s?this.mapReader.getRoom(t.b):this.mapReader.getRoom(t.a),o=s?t.aDir:t.bDir;if(!o||!n||!r||!vi.includes(o)||n.customLines[_i[o]||o])return;if(n.area!=r.area&&o){const t=this.mapReader.getColorValue(r.env);return this.renderAreaExit(n,o,t)}let a={x:r.x,y:r.y};(r.area!==n.area||r.z!==n.z)&&(a=Ri(n.x,n.y,o,this.settings.roomSize/2));const h=Ri(n.x,n.y,o,.3),l=h.x-(h.x-a.x)/2,d=h.y-(h.y-a.y)/2,c=new xi.Group({listening:!1}),g=[];g.push(...Object.values(this.getRoomEdgePoint(n.x,n.y,o,this.settings.roomSize/2))),g.push(a.x,a.y);const u=new xi.Line({points:g,stroke:e,strokeWidth:this.settings.lineWidth,dashEnabled:!0,dash:[.1,.05],perfectDrawEnabled:!1,listening:!1});c.add(u);const f=new xi.Arrow({points:[g[0],g[1],l,d],pointerLength:.5,pointerWidth:.35,strokeWidth:1.4*this.settings.lineWidth,stroke:e,fill:Li,dashEnabled:!0,dash:[.1,.05],perfectDrawEnabled:!1,listening:!1});return c.add(f),c}renderAreaExit(t,e,i){const s=this.getRoomEdgePoint(t.x,t.y,e,this.settings.roomSize/2),n=Ri(t.x,t.y,e,1.5*this.settings.roomSize),r=i??this.mapReader.getColorValue(t.env);return new xi.Arrow({points:[s.x,s.y,n.x,n.y],pointerLength:.3,pointerWidth:.3,strokeWidth:1.4*this.settings.lineWidth,stroke:r,fill:r,perfectDrawEnabled:!1,listening:!1})}renderSpecialExits(t,e){return Object.entries(t.customLines).flatMap(([i,s])=>{const n=[t.x,t.y];s.points.reduce((t,e)=>(t.push(e.x,-e.y),t),n);const r=s.attributes.arrow?xi.Arrow:xi.Line,o=e??`rgb(${s.attributes.color.r}, ${s.attributes.color.g}, ${s.attributes.color.b})`,a=new r({points:n,strokeWidth:this.settings.lineWidth,stroke:o,fill:e??`rgb(${s.attributes.color.r}, ${s.attributes.color.g} , ${s.attributes.color.b})`,pointerLength:.3,pointerWidth:.2,perfectDrawEnabled:!1,listening:!1});let h=s.attributes.style;"dot line"===h?(a.dash([.05,.05]),a.dashOffset(.1)):"dash line"===h?a.dash([.4,.2]):"solid line"===h||void 0!==h&&console.log("Brak opisu stylu: "+h);const l=[a],d=t.doors[i];return d&&n.length>=4&&l.push(this.renderDoor(n,d)),l})}getSpecialExitAreaTargets(t){const e=[];for(const[i,s]of Object.entries(t.customLines)){let n=t.specialExits[i];if(void 0===n){const e=bi[i];e&&(n=t.exits[e]??t.specialExits[e])}if(void 0===n)continue;const r=this.mapReader.getRoom(n);if(!r||r.area===t.area&&r.z===t.z)continue;const o=[t.x,t.y];s.points.reduce((t,e)=>(t.push(e.x,-e.y),t),o);let a=1/0,h=1/0,l=-1/0,d=-1/0;for(let t=0;t<o.length;t+=2)a=Math.min(a,o[t]),l=Math.max(l,o[t]),h=Math.min(h,o[t+1]),d=Math.max(d,o[t+1]);e.push({bounds:{x:a,y:h,width:l-a,height:d-h},targetRoomId:n})}return e}renderStubs(t,e=this.settings.lineColor){return t.stubs.map(i=>{const s=Di[i],n=this.getRoomEdgePoint(t.x,t.y,s,this.settings.roomSize/2),r=Ri(t.x,t.y,s,this.settings.roomSize/2+.5),o=[n.x,n.y,r.x,r.y];return new xi.Line({points:o,stroke:e,strokeWidth:this.settings.lineWidth,perfectDrawEnabled:!1,listening:!1})})}getSymbolColor(t,e){return this.settings.frameMode?this.mapReader.getColorValue(t):this.mapReader.getSymbolColor(t,e)}renderInnerExits(t){return Ii.map(e=>{if(t.exits[e]){const i=new xi.Group({listening:!1}),s=new xi.RegularPolygon({x:t.x,y:t.y,sides:3,fill:this.getSymbolColor(t.env,.6),stroke:this.getSymbolColor(t.env),strokeWidth:this.settings.lineWidth,radius:this.settings.roomSize/5,scaleX:1.4,scaleY:.8,perfectDrawEnabled:!1,listening:!1});i.add(s);let n=t.doors[e];if(void 0!==n)switch(n){case 1:s.stroke(Pi);break;case 2:s.stroke(Ai);break;default:s.stroke(Ti)}const r=s.stroke();switch(e){case"up":s.position(Ri(t.x,t.y,"south",this.settings.roomSize/4));break;case"down":s.rotation(180),s.position(Ri(t.x,t.y,"north",this.settings.roomSize/4));break;case"in":{s.rotation(90),s.position(Ri(t.x,t.y,"west",this.settings.roomSize/4));const e=Ri(t.x,t.y,"east",this.settings.roomSize/4);i.add(new xi.RegularPolygon({x:e.x,y:e.y,sides:3,fill:s.fill(),stroke:r,strokeWidth:this.settings.lineWidth,radius:this.settings.roomSize/5,scaleX:1.4,scaleY:.8,rotation:-90,perfectDrawEnabled:!1,listening:!1}));break}case"out":{s.rotation(-90),s.position(Ri(t.x,t.y,"west",this.settings.roomSize/4));const e=Ri(t.x,t.y,"east",this.settings.roomSize/4);i.add(new xi.RegularPolygon({x:e.x,y:e.y,sides:3,fill:s.fill(),stroke:r,strokeWidth:this.settings.lineWidth,radius:this.settings.roomSize/5,scaleX:1.4,scaleY:.8,rotation:90,perfectDrawEnabled:!1,listening:!1}));break}}return i}}).filter(t=>void 0!==t)}renderDoor(t,e){const i=t[0]+(t[2]-t[0])/2,s=t[1]+(t[3]-t[1])/2;return new xi.Rect({x:i-this.settings.roomSize/4,y:s-this.settings.roomSize/4,width:this.settings.roomSize/2,height:this.settings.roomSize/2,stroke:Gi(e),strokeWidth:this.settings.lineWidth,perfectDrawEnabled:!1,listening:!1})}}class zi{constructor(t,e){this.rooms=[],this.labels=[],this.rooms=t,this.labels=e,this.bounds=this.createBounds()}getRooms(){return this.rooms}getLabels(){return this.labels}getBounds(){return this.bounds}createBounds(){const t=this.rooms.reduce((t,e)=>({minX:Math.min(t.minX,e.x),maxX:Math.max(t.maxX,e.x),minY:Math.min(t.minY,e.y),maxY:Math.max(t.maxY,e.y)}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY});for(const e of this.labels){const i=e.X,s=-e.Y;t.minX=Math.min(t.minX,i),t.maxX=Math.max(t.maxX,i+e.Width),t.minY=Math.min(t.minY,s),t.maxY=Math.max(t.maxY,s+e.Height)}return t}}const Bi=class t{constructor(t){this.planes={},this.exits=new Map,this.version=0,this.area=t,this.planes=this.createPlanes(),this.createExits()}getAreaName(){return this.area.areaName}getAreaId(){return parseInt(this.area.areaId)}getVersion(){return this.version}markDirty(){this.version++}getPlane(t){return this.planes[t]}getPlanes(){return Object.values(this.planes)}getZLevels(){return Object.keys(this.planes).map(Number).sort((t,e)=>t-e)}getRooms(){return this.area.rooms}getFullBounds(){return this.getPlanes().reduce((t,e)=>{const i=e.getBounds();return{minX:Math.min(t.minX,i.minX),maxX:Math.max(t.maxX,i.maxX),minY:Math.min(t.minY,i.minY),maxY:Math.max(t.maxY,i.maxY)}},{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}getLinkExits(t){return Array.from(this.exits.values()).filter(e=>e.zIndex.includes(t))}createPlanes(){const t=this.area.rooms.reduce((t,e)=>(t[e.z]||(t[e.z]=[]),t[e.z].push(e),t),{});return Object.entries(t).reduce((t,[e,i])=>(t[+e]=new zi(i,this.area.labels.filter(t=>t.Z===+e)),t),{})}createExits(){const e=new Map;this.area.rooms.forEach(t=>{Object.entries(t.exits).forEach(([i,s])=>{if(t.id===s)return;const n=`${Math.min(t.id,s)}-${Math.max(t.id,s)}`;e.has(n)||e.set(n,[]),e.get(n).push({origin:t.id,target:s,z:t.z,dir:i})})});for(const[i,s]of e){const[e,n]=i.split("-"),r=parseInt(e),o=parseInt(n),a=s.filter(t=>t.origin===r),h=s.filter(t=>t.origin===o),l=new Set;for(const s of a){let e=-1;for(let i=0;i<h.length;i++)if(!l.has(i)){if(h[i].dir===t.oppositeDir[s.dir]){e=i;break}-1===e&&(e=i)}if(-1!==e){l.add(e);const t=h[e];this.exits.set(`${i}-${s.dir}`,{a:r,b:o,aDir:s.dir,bDir:t.dir,zIndex:[s.z,t.z]})}else this.exits.set(`${i}-a:${s.dir}`,{a:r,b:o,aDir:s.dir,zIndex:[s.z]})}for(let t=0;t<h.length;t++)if(!l.has(t)){const e=h[t];this.exits.set(`${i}-b:${e.dir}`,{a:r,b:o,bDir:e.dir,zIndex:[e.z]})}}}};Bi.oppositeDir={north:"south",south:"north",east:"west",west:"east",northeast:"southwest",southwest:"northeast",northwest:"southeast",southeast:"northwest",up:"down",down:"up",in:"out",out:"in"};let Fi=Bi;class Ni extends zi{constructor(t,e){super(t.getRooms(),t.getLabels()),this.basePlane=t,this.visitedRooms=e}getRooms(){return this.basePlane.getRooms().filter(t=>this.visitedRooms.has(t.id))}getLabels(){return this.basePlane.getLabels()}getBounds(){const t=this.getRooms();return t.length?t.reduce((t,e)=>({minX:Math.min(t.minX,e.x),maxX:Math.max(t.maxX,e.x),minY:Math.min(t.minY,e.y),maxY:Math.max(t.maxY,e.y)}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}):this.basePlane.getBounds()}}class Wi extends Fi{constructor(t,e){super(t),this.planeCache=new WeakMap,this.visitedRooms=e instanceof Set?e:new Set(e??[]),this.areaRoomIds=new Set(t.rooms.map(t=>t.id))}getPlane(t){const e=super.getPlane(t);if(!e)return e;let i=this.planeCache.get(e);return i||(i=new Ni(e,this.visitedRooms),this.planeCache.set(e,i)),i}getPlanes(){return super.getPlanes().map(t=>{let e=this.planeCache.get(t);return e||(e=new Ni(t,this.visitedRooms),this.planeCache.set(t,e)),e})}getLinkExits(t){return super.getLinkExits(t).filter(t=>this.visitedRooms.has(t.a)||this.visitedRooms.has(t.b))}getVisitedRoomCount(){return super.getRooms().reduce((t,e)=>t+(this.visitedRooms.has(e.id)?1:0),0)}getTotalRoomCount(){return this.areaRoomIds.size}hasVisitedRoom(t){return this.areaRoomIds.has(t)&&this.visitedRooms.has(t)}getVisitedRoomIds(){return super.getRooms().filter(t=>this.visitedRooms.has(t.id)).map(t=>t.id)}addVisitedRoom(t){const e=this.visitedRooms.has(t);this.visitedRooms.add(t);const i=!e&&this.areaRoomIds.has(t);return i&&this.markDirty(),i}addVisitedRooms(t){let e=0;for(const i of t){const t=this.visitedRooms.has(i);this.visitedRooms.add(i),!t&&this.areaRoomIds.has(i)&&e++}return e>0&&this.markDirty(),e}}const $i=["up","down","in","out"];function Yi(t,e,i,s,n){return"circle"===t.roomShape?Mi(e,i,s,n):"roundedRectangle"===t.roomShape?Ei(e,i,s,n,.2*t.roomSize):Ri(e,i,s,n)}function Xi(t,e,i){for(const[s,n]of Object.entries(e.exits))if(n===i.id){const t=s;if($i.includes(t)){const s=_i[t];return{type:"inner",fromDir:t,customLineKey:e.customLines[s]?s:e.customLines[t]?t:void 0,fromRoom:e,toRoom:i}}const n=_i[t];if(e.customLines[n])return{type:"special",fromDir:t,customLineKey:n,fromRoom:e,toRoom:i};if(e.customLines[t])return{type:"special",fromDir:t,customLineKey:t,fromRoom:e,toRoom:i};return{type:"regular",fromDir:t,toDir:Hi(i,e.id),fromRoom:e,toRoom:i}}for(const[s,n]of Object.entries(e.specialExits))if(n===i.id)return e.customLines[s]?{type:"special",customLineKey:s,fromRoom:e,toRoom:i}:{type:"inner",fromRoom:e,toRoom:i};for(const[s,n]of Object.entries(i.exits))if(n===e.id){const t=s;if($i.includes(t)){const s=_i[t];return{type:"inner",toDir:t,customLineKey:i.customLines[s]?s:i.customLines[t]?t:void 0,fromRoom:e,toRoom:i}}const n=_i[t];return i.customLines[n]?{type:"special",toDir:t,customLineKey:n,fromRoom:e,toRoom:i}:i.customLines[t]?{type:"special",toDir:t,customLineKey:t,fromRoom:e,toRoom:i}:{type:"regular",toDir:t,fromRoom:e,toRoom:i}}for(const[s,n]of Object.entries(i.specialExits))if(n===e.id)return i.customLines[s]?{type:"special",customLineKey:s,fromRoom:e,toRoom:i}:{type:"inner",fromRoom:e,toRoom:i};return{type:"none",fromRoom:e,toRoom:i}}function Hi(t,e){for(const[i,s]of Object.entries(t.exits))if(s===e)return i}function ji(t,e,i){return!!t&&(t.area===e&&t.z===i)}function qi(t,e){for(const[i,s]of Object.entries(t.exits))if(s===e.id)return{direction:i};for(const[i,s]of Object.entries(t.specialExits))if(s===e.id)return}function Vi(t,e){for(const i of Si)if(t.exits[i]===e.id)return i;for(const i of Si)if(e.exits[i]===t.id)return Ci[i]}function Ui(t,e,i){const{fromRoom:s,toRoom:n,fromDir:r,toDir:o}=e;if(0===i.length&&i.push(s.x,s.y),r&&vi.includes(r)){const e=Yi(t,s.x,s.y,r,t.roomSize/2);i.push(e.x,e.y)}if(o&&vi.includes(o)){const e=Yi(t,n.x,n.y,o,t.roomSize/2);i.push(e.x,e.y)}i.push(n.x,n.y)}function Zi(t,e){const{fromRoom:i,toRoom:s,customLineKey:n}=t;let r,o=i;n&&(r=i.customLines[n],r||(r=s.customLines[n],o=s)),0===e.length&&e.push(o.x,o.y),r&&r.points.forEach(t=>{e.push(t.x,-t.y)}),e.push(s.x,s.y)}function Ki(t,e,i,s,n){const r=[],o=[],a=[],h=i.map(e=>t.getRoom(e)).filter(t=>void 0!==t);let l=[];const d=()=>{l.length>=4&&r.push({points:[...l]}),l=[]},c=t=>{const{fromRoom:e,toRoom:i,fromDir:s,toDir:n,customLineKey:r}=t;if(r){let t=e,s=e.customLines[r];if(s||(s=i.customLines[r],t=i),s){const e=[t.x,t.y];s.points.forEach(t=>{e.push(t.x,-t.y)}),a.push({points:e})}}s&&$i.includes(s)&&o.push({room:e,direction:s}),n&&$i.includes(n)&&o.push({room:i,direction:n})};for(let g=0;g<h.length-1;g++){const t=h[g],i=h[g+1],r=ji(t,s,n),a=ji(i,s,n);if(r||a)if(r&&a){const s=Xi(0,t,i);switch(s.type){case"regular":Ui(e,s,l);break;case"special":Zi(s,l);break;case"inner":d(),c(s);break;case"none":0===l.length&&l.push(t.x,t.y),l.push(i.x,i.y)}}else{const s=r?t:i,n=r?i:t,a=qi(s,n);if(a){if($i.includes(a.direction))d(),o.push({room:s,direction:a.direction});else if(vi.includes(a.direction)){0===l.length&&l.push(s.x,s.y);const t=Yi(e,s.x,s.y,a.direction,e.roomSize/2),i=Ri(s.x,s.y,a.direction,e.roomSize);l.push(t.x,t.y,i.x,i.y),d()}}else{const t=Vi(s,n);if(t){0===l.length&&l.push(s.x,s.y);const i=Yi(e,s.x,s.y,t,e.roomSize/2),n=Ri(s.x,s.y,t,e.roomSize);l.push(i.x,i.y,n.x,n.y),d()}}}else d()}return d(),{segments:r,innerMarkers:o,customLines:a}}class Ji{constructor(t,e,i){this.paths=[],this.mapReader=t,this.overlayLayer=e,this.settings=i}createStrokedLine(t,e){const i=new xi.Group;return i.opacity(.8),i.add(new xi.Line({points:t,stroke:"black",strokeWidth:8*this.settings.lineWidth,lineCap:"round",lineJoin:"round"})),i.add(new xi.Line({points:t,stroke:e,strokeWidth:4*this.settings.lineWidth,lineCap:"round",lineJoin:"round"})),i}renderInnerExitMarker(t,e,i){const s=new xi.Group;s.opacity(.8);const n=new xi.RegularPolygon({x:t.x,y:t.y,sides:3,fill:i,stroke:"black",strokeWidth:2*this.settings.lineWidth,radius:this.settings.roomSize/5,scaleX:1.4,scaleY:.8});switch(e){case"up":n.position(Ri(t.x,t.y,"south",this.settings.roomSize/4));break;case"down":n.rotation(180),n.position(Ri(t.x,t.y,"north",this.settings.roomSize/4));break;case"in":{const e=n.clone();e.rotation(-90),e.position(Ri(t.x,t.y,"east",this.settings.roomSize/4)),s.add(e),n.rotation(90),n.position(Ri(t.x,t.y,"west",this.settings.roomSize/4));break}case"out":{const e=n.clone();e.rotation(90),e.position(Ri(t.x,t.y,"east",this.settings.roomSize/4)),s.add(e),n.rotation(-90),n.position(Ri(t.x,t.y,"west",this.settings.roomSize/4));break}}return s.add(n),s}renderPath(t,e,i,s="#66E64D"){if(void 0===e||void 0===i)return;const n=Ki(this.mapReader,this.settings,t,e,i);for(const r of n.segments){const t=this.createStrokedLine(r.points,s);this.overlayLayer.add(t),this.paths.push(t)}for(const r of n.customLines){const t=this.createStrokedLine(r.points,s);this.overlayLayer.add(t),this.paths.push(t)}for(const r of n.innerMarkers){const t=this.renderInnerExitMarker(r.room,r.direction,s);this.overlayLayer.add(t),this.paths.push(t)}return this.paths[0]}clearPaths(){this.paths.forEach(t=>{t.destroy()}),this.paths=[]}}const Qi={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"},ts=["up","down","in","out"],es="rgb(10, 155, 10)",is="rgb(226, 205, 59)",ss="rgb(155, 10, 10)";function ns(t){switch(t){case 1:return es;case 2:return is;default:return ss}}function rs(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}class os{constructor(t,e){this.mapReader=t,this.settings=e,this.exitRenderer=new Oi(t,null,e)}getSymbolColor(t,e){return this.settings.frameMode?this.mapReader.getColorValue(t):this.mapReader.getSymbolColor(t,e)}export(t,e,i){const s=this.mapReader.getArea(t);if(!s)throw new Error(`Area ${t} not found`);const n=s.getPlane(e);if(!n)throw new Error(`Plane z=${e} not found in area ${t}`);const r=i?.padding??3,o=this.computeBounds(s,n,i?.roomId,r),a=[];a.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${o.x} ${o.y} ${o.w} ${o.h}">`),a.push(`<rect x="${o.x}" y="${o.y}" width="${o.w}" height="${o.h}" fill="${rs(this.settings.backgroundColor)}"/>`),this.settings.gridEnabled&&this.renderGrid(a,o),this.renderLabels(a,n.getLabels()),this.renderLinkExits(a,s,e);const h=n.getRooms();this.renderSpecialExits(a,h),this.renderStubs(a,h),this.renderRooms(a,h),this.renderInnerExits(a,h);const l=i?.overlays;if(l){if(l.paths)for(const i of l.paths)this.renderPathOverlay(a,i.locations,i.color,t,e);if(l.highlights)for(const t of l.highlights)this.renderHighlightOverlay(a,t.roomId,t.color);l.position&&this.renderPositionMarker(a,l.position.roomId)}if(this.settings.areaName){const t=s.getAreaName();if(t){const e=this.getEffectiveBounds(s,n);a.push(`<text x="${e.minX-3.5}" y="${e.minY-2}" font-size="2.5" font-family="${rs(this.settings.fontFamily)}" fill="white">${rs(t)}</text>`)}}return a.push("</svg>"),a.join("\n")}computeBounds(t,e,i,s){if(void 0!==i){const t=this.mapReader.getRoom(i);if(!t)throw new Error(`Room ${i} not found`);return{x:t.x-s,y:t.y-s,w:2*s,h:2*s}}const n=this.getEffectiveBounds(t,e),r=this.settings.areaName?t.getAreaName():void 0,o=r?7:0,a=r?3.5:0,h=n.minX-a,l=n.minY-o,d=r?n.minX-3.5+2.5*r.length*.6:-1/0;return{x:h-s,y:l-s,w:Math.max(n.maxX,d)-h+2*s,h:n.maxY-l+2*s}}getEffectiveBounds(t,e){return this.settings.uniformLevelSize?t.getFullBounds():e.getBounds()}getRoomEdgePoint(t,e,i,s){return"circle"===this.settings.roomShape?Mi(t,e,i,s):"roundedRectangle"===this.settings.roomShape?Ei(t,e,i,s,.2*this.settings.roomSize):Ri(t,e,i,s)}renderGrid(t,e){const i=this.settings.gridSize,s=Math.floor(e.x/i)*i,n=Math.ceil((e.x+e.w)/i)*i,r=Math.floor(e.y/i)*i,o=Math.ceil((e.y+e.h)/i)*i,a=rs(this.settings.gridColor),h=this.settings.gridLineWidth;for(let l=s;l<=n;l+=i)t.push(`<line x1="${l}" y1="${r}" x2="${l}" y2="${o}" stroke="${a}" stroke-width="${h}"/>`);for(let l=r;l<=o;l+=i)t.push(`<line x1="${s}" y1="${l}" x2="${n}" y2="${l}" stroke="${a}" stroke-width="${h}"/>`)}renderLabels(t,e){for(const i of e){const e=i.X,s=-i.Y;if("image"===this.settings.labelRenderMode&&i.pixMap)t.push(`<image x="${e}" y="${s}" width="${i.Width}" height="${i.Height}" href="data:image/png;base64,${i.pixMap}"/>`);else{if((i.BgColor?.alpha??0)>0&&!this.settings.transparentLabels){const n=this.labelColor(i.BgColor);t.push(`<rect x="${e}" y="${s}" width="${i.Width}" height="${i.Height}" fill="${n}"/>`)}if(i.Text){const n=this.labelColor(i.FgColor),r=Math.min(.75,i.Width/Math.max(i.Text.length/2,1)),o=Math.max(.1,Math.min(r,Math.max(.9*i.Height,.1)));t.push(`<text x="${e+i.Width/2}" y="${s+i.Height/2}" font-size="${o}" font-family="${rs(this.settings.fontFamily)}" fill="${n}" text-anchor="middle" dominant-baseline="central">${rs(i.Text)}</text>`)}}}}labelColor(t){const e=(t?.alpha??255)/255,i=t=>Math.min(255,Math.max(0,t??0));return`rgba(${i(t?.r)}, ${i(t?.g)}, ${i(t?.b)}, ${e})`}renderLinkExits(t,e,i){const s=e.getLinkExits(i);for(const n of s){const e=this.exitRenderer.renderData(n,i);e&&this.renderExitData(t,e)}}renderExitData(t,e){for(const i of e.lines)this.renderSvgLine(t,i);for(const i of e.arrows)this.renderSvgArrow(t,i);for(const i of e.doors)this.renderSvgDoor(t,i)}renderSvgLine(t,e){if(e.points.length<4)return;const i=e.points.map(t=>t.toString()).join(" "),s=e.dash?` stroke-dasharray="${e.dash.join(" ")}"`:"";t.push(`<polyline points="${i}" stroke="${rs(e.stroke)}" stroke-width="${e.strokeWidth}" fill="none"${s}/>`)}renderSvgArrow(t,e){if(e.points.length<4)return;const i=e.points.map(t=>t.toString()).join(" "),s=e.dash?` stroke-dasharray="${e.dash.join(" ")}"`:"";t.push(`<polyline points="${i}" stroke="${rs(e.stroke)}" stroke-width="${e.strokeWidth}" fill="none"${s}/>`);const n=e.points.length-2,r=e.points[n],o=e.points[n+1],a=e.points[n-2],h=e.points[n-1],l=Math.atan2(o-h,r-a),d=e.pointerLength,c=e.pointerWidth/2,g=r-d*Math.cos(l-Math.atan2(c,d)),u=o-d*Math.sin(l-Math.atan2(c,d)),f=r-d*Math.cos(l+Math.atan2(c,d)),p=o-d*Math.sin(l+Math.atan2(c,d));t.push(`<polygon points="${r},${o} ${g},${u} ${f},${p}" fill="${rs(e.fill)}" stroke="${rs(e.stroke)}" stroke-width="${e.strokeWidth}"/>`)}renderSvgDoor(t,e){t.push(`<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" stroke="${rs(e.stroke)}" stroke-width="${e.strokeWidth}" fill="none"/>`)}renderStubs(t,e){const i=this.settings.lineColor;for(const s of e)for(const e of s.stubs){const n=Qi[e];if(!n)continue;const r=this.getRoomEdgePoint(s.x,s.y,n,this.settings.roomSize/2),o=Ri(s.x,s.y,n,this.settings.roomSize/2+.5);t.push(`<line x1="${r.x}" y1="${r.y}" x2="${o.x}" y2="${o.y}" stroke="${rs(i)}" stroke-width="${this.settings.lineWidth}"/>`)}}renderSpecialExits(t,e){for(const i of e)for(const[e,s]of Object.entries(i.customLines)){const n=[i.x,i.y];for(const t of s.points)n.push(t.x,-t.y);const r=`rgb(${s.attributes.color.r}, ${s.attributes.color.g}, ${s.attributes.color.b})`;let o="";"dot line"===s.attributes.style?o=' stroke-dasharray="0.05 0.05"':"dash line"===s.attributes.style&&(o=' stroke-dasharray="0.4 0.2"');const a=n.map(t=>t.toString()).join(" ");if(s.attributes.arrow&&n.length>=4){t.push(`<polyline points="${a}" stroke="${rs(r)}" stroke-width="${this.settings.lineWidth}" fill="none"${o}/>`);const e=n.length-2,i=n[e],s=n[e+1],h=n[e-2],l=n[e-1],d=Math.atan2(s-l,i-h),c=.3,g=.1,u=i-c*Math.cos(d-Math.atan2(g,c)),f=s-c*Math.sin(d-Math.atan2(g,c)),p=i-c*Math.cos(d+Math.atan2(g,c)),m=s-c*Math.sin(d+Math.atan2(g,c));t.push(`<polygon points="${i},${s} ${u},${f} ${p},${m}" fill="${rs(r)}" stroke="${rs(r)}" stroke-width="${this.settings.lineWidth}"/>`)}else t.push(`<polyline points="${a}" stroke="${rs(r)}" stroke-width="${this.settings.lineWidth}" fill="none"${o}/>`);const h=i.doors[e];if(h&&n.length>=4){const e=n[0]+(n[2]-n[0])/2,i=n[1]+(n[3]-n[1])/2,s=this.settings.roomSize/2;t.push(`<rect x="${e-s/2}" y="${i-s/2}" width="${s}" height="${s}" stroke="${ns(h)}" stroke-width="${this.settings.lineWidth}" fill="none"/>`)}}}renderRooms(t,e){const i=this.settings.roomSize,s=i/2;for(const n of e){const e=this.mapReader.getColorValue(n.env),r=this.settings.frameMode?this.settings.backgroundColor:e,o=this.settings.frameMode?e:this.settings.lineColor;if("circle"===this.settings.roomShape)t.push(`<circle cx="${n.x}" cy="${n.y}" r="${s}" fill="${rs(r)}" stroke="${rs(o)}" stroke-width="${this.settings.lineWidth}"/>`);else{const e=n.x-s,a=n.y-s,h="roundedRectangle"===this.settings.roomShape?.2*i:0,l=h>0?` rx="${h}" ry="${h}"`:"";if(t.push(`<rect x="${e}" y="${a}" width="${i}" height="${i}" fill="${rs(r)}" stroke="${rs(o)}" stroke-width="${this.settings.lineWidth}"${l}/>`),this.settings.emboss){const s=ls(this.settings.lineColor)>.41,n=s?"#000000":"#ffffff",r=s?`${e},${a} ${e+i},${a} ${e+i},${a+i}`:`${e},${a} ${e},${a+i} ${e+i},${a+i}`;t.push(`<polyline points="${r}" stroke="${n}" stroke-width="${this.settings.lineWidth}" fill="none"/>`)}}if(n.roomChar){const e=this.getSymbolColor(n.env),s=.75*i;t.push(`<text x="${n.x}" y="${n.y}" dy="0.35em" font-size="${s}" font-weight="bold" font-family="${rs(this.settings.fontFamily)}" fill="${rs(e)}" text-anchor="middle">${rs(n.roomChar)}</text>`)}}}renderInnerExits(t,e){const i=this.settings.roomSize,s=i/5;for(const n of e)for(const e of ts){if(!n.exits[e])continue;const r=this.getSymbolColor(n.env),o=this.getSymbolColor(n.env,.6);let a;const h=n.doors[e];void 0!==h&&(a=ns(h));const l=a??r;switch(e){case"up":{const e=Ri(n.x,n.y,"south",i/4);t.push(this.svgTriangle(e.x,e.y,s,0,o,l));break}case"down":{const e=Ri(n.x,n.y,"north",i/4);t.push(this.svgTriangle(e.x,e.y,s,180,o,l));break}case"in":{const e=Ri(n.x,n.y,"west",i/4),r=Ri(n.x,n.y,"east",i/4);t.push(this.svgTriangle(e.x,e.y,s,90,o,l)),t.push(this.svgTriangle(r.x,r.y,s,-90,o,l));break}case"out":{const e=Ri(n.x,n.y,"west",i/4),r=Ri(n.x,n.y,"east",i/4);t.push(this.svgTriangle(e.x,e.y,s,-90,o,l)),t.push(this.svgTriangle(r.x,r.y,s,90,o,l));break}}}}svgTriangle(t,e,i,s,n,r){const o=s*Math.PI/180,a=[];for(let h=0;h<3;h++){const s=2*Math.PI*h/3-Math.PI/2;let n=Math.cos(s)*i*1.4,r=Math.sin(s)*i*.8;const l=n*Math.cos(o)-r*Math.sin(o),d=n*Math.sin(o)+r*Math.cos(o);a.push(`${t+l},${e+d}`)}return`<polygon points="${a.join(" ")}" fill="${rs(n)}" stroke="${rs(r)}" stroke-width="${this.settings.lineWidth}"/>`}renderPathOverlay(t,e,i,s,n){const r=Ki(this.mapReader,this.settings,e,s,n),o=this.settings.lineWidth;for(const h of r.segments){const e=h.points.map(t=>t.toString()).join(" ");t.push(`<polyline points="${e}" stroke="black" stroke-width="${8*o}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.8"/>`),t.push(`<polyline points="${e}" stroke="${rs(i)}" stroke-width="${4*o}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.8"/>`)}for(const h of r.customLines){const e=h.points.map(t=>t.toString()).join(" ");t.push(`<polyline points="${e}" stroke="black" stroke-width="${8*o}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.8"/>`),t.push(`<polyline points="${e}" stroke="${rs(i)}" stroke-width="${4*o}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.8"/>`)}const a=this.settings.roomSize/5;for(const h of r.innerMarkers)t.push(this.svgTriangle(h.room.x,h.room.y,a,this.innerExitRotation(h.direction),i,"black"))}innerExitRotation(t){switch(t){case"up":default:return 0;case"down":return 180;case"in":return 90;case"out":return-90}}renderHighlightOverlay(t,e,i){const s=this.mapReader.getRoom(e);if(!s)return;const n=this.settings.roomSize,r="0.05 0.05";if("circle"===this.settings.roomShape)t.push(`<circle cx="${s.x}" cy="${s.y}" r="${n/2*1.5}" stroke="${rs(i)}" stroke-width="0.1" stroke-dasharray="${r}" fill="none"/>`);else{const e=1.5*n;t.push(`<rect x="${s.x-e/2}" y="${s.y-e/2}" width="${e}" height="${e}" stroke="${rs(i)}" stroke-width="0.1" stroke-dasharray="${r}" fill="none"/>`)}}renderPositionMarker(t,e){const i=this.mapReader.getRoom(e);if(!i)return;const s=this.settings.playerMarker,n=this.settings.roomSize*s.sizeFactor,r=s.dashEnabled&&s.dash?` stroke-dasharray="${s.dash.join(" ")}"`:"",o=s.fillAlpha>0?` fill="${s.fillColor}" fill-opacity="${s.fillAlpha}"`:' fill="none"';t.push(`<circle cx="${i.x}" cy="${i.y}" r="${n/2}" stroke="${s.strokeColor}" stroke-width="${s.strokeWidth}" stroke-opacity="${s.strokeAlpha}"${r}${o}/>`)}}const as=75,hs="rgb(120, 72, 0)";function ls(t){let e,i,s;const n=t.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);if(n)e=parseInt(n[1])/255,i=parseInt(n[2])/255,s=parseInt(n[3])/255;else{if(!(t.startsWith("#")&&t.length>=7))return.5;e=parseInt(t.slice(1,3),16)/255,i=parseInt(t.slice(3,5),16)/255,s=parseInt(t.slice(5,7),16)/255}return(Math.max(e,i,s)+Math.min(e,i,s))/2}class ds{constructor(t=60){this.samples=[],this.lastCullingTime=0,this.callback=null,this.windowSize=t}setCallback(t){t!==this.callback&&(this.callback=t,this.samples=[])}record(t){this.callback&&(this.samples.push(t),this.samples.length>=this.windowSize&&this.flush())}computeFps(){const t=performance.now(),e=t-this.lastCullingTime;return this.lastCullingTime=t,e>0?1e3/e:0}flush(){const t=this.samples.length;if(0===t)return;const e={cullingMs:0,gridMs:0,visibleRooms:0,totalRooms:0,visibleExits:0,fps:0};for(const i of this.samples)e.cullingMs+=i.cullingMs,e.gridMs+=i.gridMs,e.visibleRooms+=i.visibleRooms,e.totalRooms+=i.totalRooms,e.visibleExits+=i.visibleExits,e.fps+=i.fps;e.cullingMs/=t,e.gridMs/=t,e.visibleRooms=Math.round(e.visibleRooms/t),e.totalRooms=Math.round(e.totalRooms/t),e.visibleExits=Math.round(e.visibleExits/t),e.fps=Math.round(e.fps),this.callback(e),this.samples=[]}}function cs(t,e){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${e})`}function gs(){return{roomSize:.6,lineWidth:.025,lineColor:"rgb(225, 255, 225)",backgroundColor:"#000000",instantMapMove:!1,highlightCurrentRoom:!0,cullingEnabled:!0,cullingMode:"indexed",cullingBounds:null,labelRenderMode:"image",transparentLabels:!1,roomShape:"rectangle",playerMarker:{strokeColor:"#00e5b2",strokeAlpha:1,fillColor:"#00e5b2",fillAlpha:0,strokeWidth:.1,sizeFactor:1.7,dash:[.05,.05],dashEnabled:!0},gridEnabled:!1,gridSize:1,gridColor:"rgba(200, 200, 200, 0.15)",gridLineWidth:.03,perfCallback:null,borders:!0,frameMode:!1,emboss:!1,areaName:!0,fontFamily:"sans-serif",uniformLevelSize:!1}}class us{constructor(t,e,i){this.highlights=new Map,this.currentZoom=1,this.currentRoomOverlay=[],this.roomNodes=new Map,this.centerOnResize=!0,this.minZoom=.05,this.standaloneExitNodes=[],this.spatialBucketSize=5,this.roomSpatialIndex=new Map,this.exitSpatialIndex=new Map,this.visibleRooms=new Set,this.visibleStandaloneExitNodes=new Set,this.bufferRoomSet=new Set,this.bufferExitSet=new Set,this.bufferRoomCandidates=new Set,this.bufferExitCandidates=new Set,this.cullingScheduled=!1,this.perfMonitor=new ds,this.areaExitHitZones=[],this.visibleExitDrawData=[],this.cachedGridBounds=null,this.settings=i??{roomSize:.6,lineWidth:.025,lineColor:"rgb(225, 255, 225)",backgroundColor:"#000000",instantMapMove:!1,highlightCurrentRoom:!0,cullingEnabled:!0,cullingMode:"indexed",cullingBounds:null,labelRenderMode:"image",transparentLabels:!1,roomShape:"rectangle",playerMarker:{strokeColor:"#00e5b2",strokeAlpha:1,fillColor:"#00e5b2",fillAlpha:0,strokeWidth:.1,sizeFactor:1.7,dash:[.05,.05],dashEnabled:!0},gridEnabled:!1,gridSize:1,gridColor:"rgba(200, 200, 200, 0.15)",gridLineWidth:.03,perfCallback:null,borders:!0,frameMode:!1,emboss:!1,areaName:!0,fontFamily:"sans-serif",uniformLevelSize:!1},this.stage=new xi.Stage({container:t,width:t.clientWidth,height:t.clientHeight,draggable:!0}),t.style.backgroundColor=this.settings.backgroundColor,window.addEventListener("resize",()=>{this.onResize(t)}),t.addEventListener("resize",()=>{this.onResize(t)}),this.gridLayer=new xi.Layer({listening:!1,hitGraphEnabled:!1}),this.stage.add(this.gridLayer),this.linkLayer=new xi.Layer({listening:!1,hitGraphEnabled:!1}),this.stage.add(this.linkLayer),this.roomLayer=new xi.Layer({hitGraphEnabled:!1}),this.stage.add(this.roomLayer),this.positionLayer=new xi.Layer({listening:!1,hitGraphEnabled:!1}),this.stage.add(this.positionLayer),this.overlayLayer=new xi.Layer({listening:!1,hitGraphEnabled:!1}),this.stage.add(this.overlayLayer),this.mapReader=e,this.exitRenderer=new Oi(e,this,this.settings),this.pathRenderer=new Ji(e,this.overlayLayer,this.settings),this.initScaling(1.1),this.stage.on("dragmove",()=>{this.scheduleRoomCulling(),this.emitPanEvent()}),this.stage.on("dragend",()=>{this.scheduleRoomCulling(),this.emitPanEvent()}),this.initRoomHitDetection()}clientToMapPoint(t,e){const i=this.stage.container().getBoundingClientRect(),s=t-i.left,n=e-i.top,r=this.stage.scaleX();if(!r)return null;const o=this.stage.position();return{x:(s-o.x)/r,y:(n-o.y)/r}}findRoomAtClientPoint(t,e){const i=this.clientToMapPoint(t,e);if(!i)return null;const s=this.settings.roomSize/2,n=this.getBucketKey(Math.floor(i.x/this.spatialBucketSize),Math.floor(i.y/this.spatialBucketSize)),r=this.roomSpatialIndex.get(n);if(!r)return null;for(const o of r){const t=i.x-o.room.x,e=i.y-o.room.y;if(t>=-s&&t<=s&&e>=-s&&e<=s)return o.room}return null}initRoomHitDetection(){const t=this.stage.container();let e=null;t.addEventListener("mousemove",i=>{const s=this.findRoomAtClientPoint(i.clientX,i.clientY);if(s!==e&&(e=s,s))t.style.cursor="pointer";else if(!e){const e=null!==this.findAreaExitAtClientPoint(i.clientX,i.clientY);t.style.cursor=e?"pointer":"auto"}}),t.addEventListener("mouseleave",()=>{e=null,t.style.cursor="auto"});let i,s,n,r=null;t.addEventListener("mousedown",t=>{0===t.button&&(r={x:t.clientX,y:t.clientY})}),t.addEventListener("mouseup",t=>{if(0!==t.button||!r)return;const e=t.clientX-r.x,i=t.clientY-r.y;if(r=null,e*e+i*i>25)return;const s=this.findRoomAtClientPoint(t.clientX,t.clientY);if(s)return void this.emitRoomClickEvent(s.id,t.clientX,t.clientY);const n=this.findAreaExitAtClientPoint(t.clientX,t.clientY);n?this.emitAreaExitClickEvent(n.targetRoomId,t.clientX,t.clientY):this.emitMapClickEvent()}),t.addEventListener("contextmenu",t=>{const e=this.findRoomAtClientPoint(t.clientX,t.clientY);e&&(t.preventDefault(),this.emitRoomContextEvent(e.id,t.clientX,t.clientY))});const o=()=>{void 0!==n&&(this.stage.draggable(n),n=void 0)},a=()=>{void 0!==i&&(window.clearTimeout(i),i=void 0),s=void 0,o()};t.addEventListener("touchstart",t=>{if(a(),t.touches.length>1)return;const e=t.touches[0];!e||!this.findRoomAtClientPoint(e.clientX,e.clientY)||(s={clientX:e.clientX,clientY:e.clientY},n=this.stage.draggable(),this.stage.draggable(!1),i=window.setTimeout(()=>{if(s){const t=this.findRoomAtClientPoint(s.clientX,s.clientY);t&&this.emitRoomContextEvent(t.id,s.clientX,s.clientY)}a()},500))},{passive:!0}),t.addEventListener("touchend",()=>a(),{passive:!0}),t.addEventListener("touchcancel",()=>a(),{passive:!0}),t.addEventListener("touchmove",t=>{if(!s)return;const e=t.touches[0];if(!e)return void a();const i=e.clientX-s.clientX,r=e.clientY-s.clientY;if(i*i+r*r>100){const t=n;a(),t&&this.stage.startDrag()}},{passive:!0})}onResize(t){this.stage.width(t.clientWidth),this.stage.height(t.clientHeight),this.centerOnResize&&this.currentRoomId&&this.centerOnRoom(this.mapReader.getRoom(this.currentRoomId),!1),this.stage.batchDraw(),this.scheduleRoomCulling()}initScaling(t){let e,i=!1,s=!1;this.stage.on("touchstart",t=>{const e=t.evt.touches;e&&e.length>1?(s=!0,this.stage.isDragging()&&(this.stage.stopDrag(),i=!0),this.stage.draggable(!1)):(s=!1,this.stage.draggable(!0))}),this.stage.on("touchend touchcancel",t=>{e=void 0;const i=t.evt.touches;(!i||i.length<=1)&&(s=!1,this.stage.draggable(!0))}),this.stage.on("wheel",e=>{e.evt.preventDefault();const i=this.stage.scaleX(),s=this.stage.getPointerPosition();if(!s)return;const n=(s.x-this.stage.x())/i,r=(s.y-this.stage.y())/i;let o=e.evt.deltaY>0?-1:1;e.evt.ctrlKey&&(o=-o);const a=o>0?this.currentZoom*t:this.currentZoom/t;if(this.setZoom(a)){const t=this.stage.scaleX(),e={x:s.x-n*t,y:s.y-r*t};this.stage.position(e),this.scheduleRoomCulling(),this.emitZoomChangeEvent()}}),this.stage.on("touchmove",t=>{const n=t.evt.touches,r=n?.[0],o=n?.[1];if(o||s&&(s=!1,this.stage.draggable(!0)),r&&!o&&i&&!this.stage.isDragging()&&(this.stage.startDrag(),i=!1),!r||!o)return void(e=void 0);t.evt.preventDefault(),this.stage.isDragging()&&(this.stage.stopDrag(),i=!0),s||(s=!0,this.stage.draggable(!1));const a=this.stage.container().getBoundingClientRect(),h=r.clientX-a.left,l=r.clientY-a.top,d=o.clientX-a.left,c=o.clientY-a.top,g=Math.hypot(h-d,l-c);if(void 0===e)return void(e=g);if(0===e||0===g)return void(e=g);const u=this.stage.scaleX(),f=this.stage.x(),p=this.stage.y(),m=this.stage.width()/2,y=this.stage.height()/2,x=(m-f)/u,v=(y-p)/u,b=this.currentZoom*(g/e);if(this.setZoom(b)){const t=this.stage.scaleX(),e={x:m-x*t,y:y-v*t};this.stage.position(e),this.stage.batchDraw(),this.scheduleRoomCulling(),this.emitZoomChangeEvent()}e=g})}drawArea(t,e){const i=this.mapReader.getArea(t);if(!i)return;const s=i.getPlane(e);s&&(this.currentArea=t,this.currentAreaInstance=i,this.currentZIndex=e,this.currentAreaVersion=i.getVersion(),this.clearCurrentRoomOverlay(),this.positionRender&&(this.positionRender.destroy(),this.positionRender=void 0),this.positionLayer.destroyChildren(),this.gridLayer.destroyChildren(),this.invalidateGridCache(),this.roomLayer.destroyChildren(),this.linkLayer.destroyChildren(),this.roomNodes.clear(),this.standaloneExitNodes=[],this.areaExitHitZones=[],this.standaloneExitBoundsRoomSize=void 0,this.roomSpatialIndex.clear(),this.exitSpatialIndex.clear(),this.visibleRooms.clear(),this.visibleStandaloneExitNodes.clear(),this.visibleExitDrawData.length=0,this.exitBatchShape=void 0,this.spatialBucketSize=this.computeSpatialBucketSize(),this.stage.scale({x:as*this.currentZoom,y:as*this.currentZoom}),this.renderGrid(),this.renderLabels(s.getLabels()),this.renderExits(i.getLinkExits(e)),this.renderRooms(s.getRooms()??[]),this.renderAreaName(i,s),this.refreshHighlights(),this.updateRoomCulling(),this.stage.batchDraw())}exportSvg(t){return void 0===this.currentArea||void 0===this.currentZIndex?void 0:new os(this.mapReader,this.settings).export(this.currentArea,this.currentZIndex,t)}exportPng(t){if(void 0===this.currentArea||void 0===this.currentZIndex)return;const e=t?.pixelRatio??1,i=this.stage.toCanvas({pixelRatio:e}),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=s.getContext("2d");return n.fillStyle=this.settings.backgroundColor,n.fillRect(0,0,s.width,s.height),n.drawImage(i,0,0),s.toDataURL("image/png")}exportPngBlob(t){if(void 0===this.currentArea||void 0===this.currentZIndex)return;const e=t?.pixelRatio??1,i=this.stage.toCanvas({pixelRatio:e}),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=s.getContext("2d");return n.fillStyle=this.settings.backgroundColor,n.fillRect(0,0,s.width,s.height),n.drawImage(i,0,0),new Promise(t=>{s.toBlob(e=>{e&&t(e)},"image/png")})}computeSpatialBucketSize(){return Math.max(10*this.settings.roomSize,5)}getBucketKey(t,e){return 1000003*t+e}forEachBucket(t,e,i,s,n){const r=this.spatialBucketSize,o=Math.min(t,i),a=Math.max(t,i),h=Math.min(e,s),l=Math.max(e,s),d=Math.floor(o/r),c=Math.floor(a/r),g=Math.floor(h/r),u=Math.floor(l/r);for(let f=d;f<=c;f++)for(let t=g;t<=u;t++)n(this.getBucketKey(f,t))}addRoomToSpatialIndex(t){const e=this.settings.roomSize/2,i=t.room.x-e,s=t.room.x+e,n=t.room.y-e,r=t.room.y+e;this.forEachBucket(i,n,s,r,e=>{let i=this.roomSpatialIndex.get(e);i||(i=new Set,this.roomSpatialIndex.set(e,i)),i.add(t)})}addStandaloneExitToSpatialIndex(t){const{bounds:e}=t,i=e.x,s=e.x+e.width,n=e.y,r=e.y+e.height;this.forEachBucket(i,n,s,r,e=>{let i=this.exitSpatialIndex.get(e);i||(i=new Set,this.exitSpatialIndex.set(e,i)),i.add(t)})}collectRoomCandidates(t,e,i,s){const n=this.bufferRoomCandidates;return n.clear(),this.forEachBucket(t,e,i,s,t=>{this.roomSpatialIndex.get(t)?.forEach(t=>n.add(t))}),n}collectStandaloneExitCandidates(t,e,i,s){const n=this.bufferExitCandidates;return n.clear(),this.forEachBucket(t,e,i,s,t=>{this.exitSpatialIndex.get(t)?.forEach(t=>n.add(t))}),n}refreshStandaloneExitBoundsIfNeeded(){this.standaloneExitBoundsRoomSize!==this.settings.roomSize&&(this.exitSpatialIndex.clear(),this.standaloneExitNodes.forEach(t=>{this.addStandaloneExitToSpatialIndex(t)}),this.standaloneExitBoundsRoomSize=this.settings.roomSize)}emitRoomContextEvent(t,e,i){const s=this.stage.container(),n=s.getBoundingClientRect(),r={roomId:t,position:{x:e-n.left,y:i-n.top}},o=new CustomEvent("roomcontextmenu",{detail:r});s.dispatchEvent(o)}emitRoomClickEvent(t,e,i){const s=this.stage.container(),n=s.getBoundingClientRect(),r={roomId:t,position:{x:e-n.left,y:i-n.top}},o=new CustomEvent("roomclick",{detail:r});s.dispatchEvent(o)}findAreaExitAtClientPoint(t,e){const i=this.clientToMapPoint(t,e);if(!i)return null;for(const s of this.areaExitHitZones){const t=s.bounds,e=.5*this.settings.roomSize;if(i.x>=t.x-e&&i.x<=t.x+t.width+e&&i.y>=t.y-e&&i.y<=t.y+t.height+e)return s}return null}emitAreaExitClickEvent(t,e,i){const s=this.stage.container(),n=s.getBoundingClientRect(),r={targetRoomId:t,position:{x:e-n.left,y:i-n.top}},o=new CustomEvent("areaexitclick",{detail:r});s.dispatchEvent(o)}emitZoomChangeEvent(){const t=new CustomEvent("zoom",{detail:{zoom:this.currentZoom}});this.stage.container().dispatchEvent(t)}emitPanEvent(){const t=new CustomEvent("pan",{detail:this.getViewportBounds()});this.stage.container().dispatchEvent(t)}emitMapClickEvent(){const t=new CustomEvent("mapclick");this.stage.container().dispatchEvent(t)}setZoom(t){const e=Math.max(this.minZoom,Math.min(5,t));return this.currentZoom!==e&&(this.currentZoom=e,this.stage.scale({x:as*this.currentZoom,y:as*this.currentZoom}),this.scheduleRoomCulling(),this.emitPanEvent(),!0)}zoomToCenter(t){const e=Math.max(this.minZoom,Math.min(5,t));if(this.currentZoom===e)return!1;const i=this.stage.scaleX(),s=this.stage.width()/2,n=this.stage.height()/2,r=(s-this.stage.x())/i,o=(n-this.stage.y())/i;this.currentZoom=e;const a=as*e;this.stage.scale({x:a,y:a});const h={x:s-r*a,y:n-o*a};return this.stage.position(h),this.stage.batchDraw(),this.scheduleRoomCulling(),!0}getZoom(){return this.currentZoom}getViewportBounds(){const t=this.stage.scaleX(),e=this.stage.position();return{minX:(0-e.x)/t,maxX:(this.stage.width()-e.x)/t,minY:(0-e.y)/t,maxY:(this.stage.height()-e.y)/t}}getAreaBounds(){if(!this.currentAreaInstance||void 0===this.currentZIndex)return null;const t=this.currentAreaInstance.getPlane(this.currentZIndex);if(!t)return null;const e=this.getEffectiveBounds(this.currentAreaInstance,t),i=this.settings.areaName&&this.currentAreaInstance.getAreaName();return{minX:i?e.minX-4:e.minX,maxX:e.maxX,minY:i?e.minY-7:e.minY,maxY:e.maxY}}fitArea(){if(void 0===this.currentArea||void 0===this.currentZIndex||!this.currentAreaInstance)return;const t=this.currentAreaInstance.getPlane(this.currentZIndex);if(!t)return;const e=this.getEffectiveBounds(this.currentAreaInstance,t),i=this.settings.areaName&&this.currentAreaInstance.getAreaName(),s=i?e.minY-7:e.minY,n=i?e.minX-4:e.minX,r=e.maxX-n,o=e.maxY-s;if(r<=0||o<=0)return;const a=this.stage.width(),h=this.stage.height(),l=a/((r+4)*as),d=h/((o+4)*as),c=Math.min(l,d);this.currentZoom=Math.max(.05,Math.min(5,c)),this.minZoom=this.currentZoom;const g=as*this.currentZoom;this.stage.scale({x:g,y:g});const u=(n+e.maxX)/2,f=(s+e.maxY)/2;this.stage.position({x:a/2-u*g,y:h/2-f*g}),this.stage.batchDraw(),this.scheduleRoomCulling()}setCullingMode(t){this.settings.cullingMode=t,this.settings.cullingEnabled="none"!==t,this.scheduleRoomCulling()}getCullingMode(){return this.settings.cullingMode}getCurrentArea(){return this.currentArea?this.mapReader.getArea(this.currentArea):void 0}refreshCurrentRoomOverlay(){if(void 0!==this.currentRoomId){const t=this.mapReader.getRoom(this.currentRoomId);t&&this.updateCurrentRoomOverlay(t)}}updateBackground(){this.stage.container().style.backgroundColor=this.settings.backgroundColor}refresh(){this.updateBackground(),void 0!==this.currentArea&&void 0!==this.currentZIndex&&(this.drawArea(this.currentArea,this.currentZIndex),void 0!==this.currentRoomId&&this.setPosition(this.currentRoomId))}updatePositionMarker(t){const e=this.mapReader.getRoom(t);if(!e)return;if(e.area!==this.currentArea||e.z!==this.currentZIndex)return void(this.positionRender&&(this.positionRender.hide(),this.positionLayer.batchDraw()));this.currentRoomId=t,this.updateCurrentRoomOverlay(e);const i=cs(this.settings.playerMarker.strokeColor,this.settings.playerMarker.strokeAlpha),s=cs(this.settings.playerMarker.fillColor,this.settings.playerMarker.fillAlpha),n=this.settings.roomSize/2*this.settings.playerMarker.sizeFactor;this.positionRender?(this.positionRender.position({x:e.x,y:e.y}),this.positionRender.radius(n),this.positionRender.stroke(i),this.positionRender.fill(s),this.positionRender.strokeWidth(this.settings.playerMarker.strokeWidth),this.positionRender.dash(this.settings.playerMarker.dash??[]),this.positionRender.dashEnabled(this.settings.playerMarker.dashEnabled),this.positionRender.show()):(this.positionRender=new xi.Circle({x:e.x,y:e.y,radius:n,stroke:i,fill:s,strokeWidth:this.settings.playerMarker.strokeWidth,dash:this.settings.playerMarker.dash,dashEnabled:this.settings.playerMarker.dashEnabled}),this.positionLayer.add(this.positionRender)),this.positionLayer.batchDraw()}setPosition(t,e=!0){const i=this.mapReader.getRoom(t);if(!i)return;const s=this.mapReader.getArea(i.area),n=s?.getVersion();let r=this.currentArea!==i.area||this.currentZIndex!==i.z;(this.currentArea!==i.area||this.currentZIndex!==i.z||void 0!==n&&this.currentAreaVersion!==n||void 0!==s&&this.currentAreaInstance!==s)&&this.drawArea(i.area,i.z),e?this.centerOnRoom(i,r):this.currentRoomId=t,this.updateCurrentRoomOverlay(i);const o=cs(this.settings.playerMarker.strokeColor,this.settings.playerMarker.strokeAlpha),a=cs(this.settings.playerMarker.fillColor,this.settings.playerMarker.fillAlpha),h=this.settings.roomSize/2*this.settings.playerMarker.sizeFactor;this.positionRender?(this.positionRender.radius(h),this.positionRender.stroke(o),this.positionRender.fill(a),this.positionRender.strokeWidth(this.settings.playerMarker.strokeWidth),this.positionRender.dash(this.settings.playerMarker.dash??[]),this.positionRender.dashEnabled(this.settings.playerMarker.dashEnabled)):(this.positionRender=new xi.Circle({x:i.x,y:i.y,radius:h,stroke:o,fill:a,strokeWidth:this.settings.playerMarker.strokeWidth,dash:this.settings.playerMarker.dash,dashEnabled:this.settings.playerMarker.dashEnabled}),this.positionLayer.add(this.positionRender))}clearPosition(){this.currentRoomId=void 0,this.positionRender&&(this.positionRender.destroy(),this.positionRender=void 0),this.positionLayer.batchDraw(),this.currentRoomOverlay.forEach(t=>t.destroy()),this.currentRoomOverlay=[],this.overlayLayer.batchDraw()}centerOn(t,e){const i=this.mapReader.getRoom(t);if(!i)return;const s=this.mapReader.getArea(i.area),n=s?.getVersion(),r=this.currentArea!==i.area||this.currentZIndex!==i.z;(r||void 0!==n&&this.currentAreaVersion!==n||void 0!==s&&this.currentAreaInstance!==s)&&this.drawArea(i.area,i.z),this.centerOnRoomView(i,e??r)}renderPath(t,e){return this.pathRenderer.renderPath(t,this.currentArea,this.currentZIndex,e)}clearPaths(){this.pathRenderer.clearPaths()}renderHighlight(t,e){const i=this.mapReader.getRoom(t);if(!i)return;const s=this.highlights.get(t);s?.shape&&(s.shape.destroy(),delete s.shape);const n={color:e,area:i.area,z:i.z};if(this.highlights.set(t,n),i.area===this.currentArea&&i.z===this.currentZIndex){const t=this.createHighlightShape(i,e);return this.overlayLayer.add(t),n.shape=t,this.overlayLayer.batchDraw(),t}return n.shape}removeHighlight(t){const e=this.highlights.get(t);e&&(e.shape?.destroy(),this.highlights.delete(t),this.overlayLayer.batchDraw())}hasHighlight(t){return this.highlights.has(t)}clearHighlights(){this.highlights.forEach(({shape:t})=>t?.destroy()),this.highlights.clear(),this.overlayLayer.batchDraw()}refreshHighlights(){this.highlights.forEach((t,e)=>{if(t.shape?.destroy(),delete t.shape,t.area!==this.currentArea||t.z!==this.currentZIndex)return;const i=this.mapReader.getRoom(e);if(!i)return;const s=this.createHighlightShape(i,t.color);this.overlayLayer.add(s),t.shape=s}),this.overlayLayer.batchDraw()}createHighlightShape(t,e){return"circle"===this.settings.roomShape?new xi.Circle({x:t.x,y:t.y,radius:this.settings.roomSize/2*1.5,stroke:e,strokeWidth:.1,dash:[.05,.05],dashEnabled:!0,listening:!1}):new xi.Rect({x:t.x-this.settings.roomSize/2*1.5,y:t.y-this.settings.roomSize/2*1.5,width:1.5*this.settings.roomSize,height:1.5*this.settings.roomSize,stroke:e,strokeWidth:.1,dash:[.05,.05],dashEnabled:!0,cornerRadius:"roundedRectangle"===this.settings.roomShape?1.5*this.settings.roomSize*.2:0,listening:!1})}centerOnRoom(t,e=!1){this.currentRoomId=t.id;const i={x:t.x,y:t.y};this.positionRender?.position(t);const s=this.stage.getAbsoluteTransform().point(i),n=this.stage.width()/2,r=this.stage.height()/2,o=n-s.x,a=r-s.y;this.currentTransition&&(this.currentTransition.pause(),this.currentTransition.destroy(),delete this.currentTransition),e||this.settings.instantMapMove?(this.stage.position({x:this.stage.x()+o,y:this.stage.y()+a}),this.scheduleRoomCulling()):(this.currentTransition=new xi.Tween({node:this.stage,x:this.stage.x()+o,y:this.stage.y()+a,duration:.2,easing:xi.Easings.EaseInOut,onUpdate:()=>this.scheduleRoomCulling(),onFinish:()=>this.scheduleRoomCulling()}),this.currentTransition.play())}centerOnRoomView(t,e=!1){const i={x:t.x,y:t.y},s=this.stage.getAbsoluteTransform().point(i),n=this.stage.width()/2,r=this.stage.height()/2,o=n-s.x,a=r-s.y;this.currentTransition&&(this.currentTransition.pause(),this.currentTransition.destroy(),delete this.currentTransition),e||this.settings.instantMapMove?(this.stage.position({x:this.stage.x()+o,y:this.stage.y()+a}),this.scheduleRoomCulling(),this.emitPanEvent()):(this.currentTransition=new xi.Tween({node:this.stage,x:this.stage.x()+o,y:this.stage.y()+a,duration:.2,easing:xi.Easings.EaseInOut,onUpdate:()=>this.scheduleRoomCulling(),onFinish:()=>{this.scheduleRoomCulling(),this.emitPanEvent()}}),this.currentTransition.play())}getEffectiveBounds(t,e){return this.settings.uniformLevelSize?t.getFullBounds():e.getBounds()}renderAreaName(t,e){if(!this.settings.areaName)return;const i=t.getAreaName();if(!i)return;const s=this.getEffectiveBounds(t,e);this.roomLayer.add(new xi.Text({x:s.minX-3.5,y:s.minY-4.5,text:i,fontSize:2.5,fontFamily:this.settings.fontFamily,fill:"white",listening:!1,perfectDrawEnabled:!1}))}renderRooms(t){t.forEach(t=>{const e=new xi.Group({x:t.x-this.settings.roomSize/2,y:t.y-this.settings.roomSize/2,listening:!1}),i=this.mapReader.getColorValue(t.env),s=this.settings.frameMode?this.settings.backgroundColor:i,n=this.settings.frameMode?i:this.settings.lineColor,r=this.settings.borders?this.settings.lineWidth:0,o="circle"===this.settings.roomShape?new xi.Circle({x:this.settings.roomSize/2,y:this.settings.roomSize/2,radius:this.settings.roomSize/2,fill:s,strokeWidth:r,stroke:n,perfectDrawEnabled:!1,listening:!1}):new xi.Rect({x:0,y:0,width:this.settings.roomSize,height:this.settings.roomSize,fill:s,strokeWidth:r,stroke:n,cornerRadius:"roundedRectangle"===this.settings.roomShape?.2*this.settings.roomSize:0,perfectDrawEnabled:!1,listening:!1});if(e.add(o),this.settings.emboss&&"circle"!==this.settings.roomShape){const t=this.settings.roomSize,i=ls(this.settings.lineColor)>.41;e.add(new xi.Line({points:i?[0,0,t,0,t,t]:[0,0,0,t,t,t],stroke:i?"#000000":"#ffffff",strokeWidth:this.settings.lineWidth,perfectDrawEnabled:!1,listening:!1}))}this.renderSymbol(t,e),this.roomLayer.add(e),this.exitRenderer.renderSpecialExits(t).forEach(t=>{this.linkLayer.add(t)}),this.exitRenderer.getSpecialExitAreaTargets(t).forEach(t=>{this.areaExitHitZones.push(t)});const a=t.x-this.settings.roomSize/2,h=t.y-this.settings.roomSize/2;this.exitRenderer.renderStubs(t).forEach(t=>{const i=t.points();for(let e=0;e<i.length;e+=2)i[e]-=a,i[e+1]-=h;t.points(i),e.add(t)}),this.exitRenderer.renderInnerExits(t).forEach(t=>{t.position({x:-a,y:-h}),e.add(t)});const l={room:t,group:e};this.roomNodes.set(t.id,l),this.addRoomToSpatialIndex(l)})}scheduleRoomCulling(){this.cullingScheduled||(this.cullingScheduled=!0,window.requestAnimationFrame(()=>{this.cullingScheduled=!1,this.updateRoomCulling()}))}updateRoomCulling(){if(0===this.roomNodes.size&&0===this.standaloneExitNodes.length)return;const t=this.stage.scaleX();if(!t)return;this.syncPerfMonitor();const e=this.settings.perfCallback?performance.now():0,i=this.stage.position(),s=this.settings.roomSize/2,n=this.settings.cullingBounds,r=n?n.x:0,o=n?n.x+n.width:this.stage.width(),a=n?n.y:0,h=n?n.y+n.height:this.stage.height(),l=Math.min(r,o),d=Math.max(r,o),c=Math.min(a,h),g=Math.max(a,h),u=(l-i.x)/t,f=(d-i.x)/t,p=(c-i.y)/t,m=(g-i.y)/t;let y=!1,x=!1;const v=this.settings.cullingEnabled?this.settings.cullingMode??"indexed":"none",b=u-s,_=f+s,w=p-s,S=m+s;if(this.refreshStandaloneExitBoundsIfNeeded(),"none"===v){if(this.roomNodes.forEach(t=>{t.group.visible()||(t.group.visible(!0),y=!0)}),this.visibleExitDrawData.length!==this.standaloneExitNodes.length){this.visibleExitDrawData.length=0;for(const t of this.standaloneExitNodes)this.visibleExitDrawData.push(t.data);x=!0}return y&&this.roomLayer.batchDraw(),x&&this.linkLayer.batchDraw(),this.visibleRooms.clear(),this.roomNodes.forEach(t=>this.visibleRooms.add(t)),this.visibleStandaloneExitNodes.clear(),void this.standaloneExitNodes.forEach(t=>this.visibleStandaloneExitNodes.add(t))}if("basic"===v){const t=this.bufferRoomSet;t.clear(),this.roomNodes.forEach(e=>{const i=e.room.x-s,n=e.room.x+s,r=e.room.y-s,o=e.room.y+s,a=n>=u&&i<=f&&o>=p&&r<=m;e.group.visible()!==a&&(e.group.visible(a),y=!0),a&&t.add(e)});const e=this.bufferExitSet;e.clear();let i=!1;return this.standaloneExitNodes.forEach(t=>{const{bounds:s}=t,n=s.x,r=s.x+s.width,o=s.y,a=s.y+s.height;r>=u&&n<=f&&a>=p&&o<=m&&(e.add(t),this.visibleStandaloneExitNodes.has(t)||(i=!0))}),!i&&e.size!==this.visibleStandaloneExitNodes.size&&(i=!0),this.bufferRoomSet=this.visibleRooms,this.visibleRooms=t,this.bufferExitSet=this.visibleStandaloneExitNodes,this.visibleStandaloneExitNodes=e,i&&(this.visibleExitDrawData.length=0,this.visibleStandaloneExitNodes.forEach(t=>this.visibleExitDrawData.push(t.data)),x=!0),y&&this.roomLayer.batchDraw(),void(x&&this.linkLayer.batchDraw())}const C=this.collectRoomCandidates(b,w,_,S),k=this.bufferRoomSet;k.clear(),C.forEach(t=>{const e=t.room.x-s,i=t.room.x+s,n=t.room.y-s,r=t.room.y+s,o=i>=u&&e<=f&&r>=p&&n<=m;t.group.visible()!==o&&(t.group.visible(o),y=!0),o&&k.add(t)}),this.visibleRooms.forEach(t=>{C.has(t)||t.group.visible()&&(t.group.visible(!1),y=!0)}),this.bufferRoomSet=this.visibleRooms,this.visibleRooms=k;const R=this.collectStandaloneExitCandidates(b,w,_,S),E=this.bufferExitSet;E.clear();let M=!1;R.forEach(t=>{const{bounds:e}=t,i=e.x,s=e.x+e.width,n=e.y,r=e.y+e.height;s>=u&&i<=f&&r>=p&&n<=m&&(E.add(t),this.visibleStandaloneExitNodes.has(t)||(M=!0))}),!M&&E.size!==this.visibleStandaloneExitNodes.size&&(M=!0),this.bufferExitSet=this.visibleStandaloneExitNodes,this.visibleStandaloneExitNodes=E,M&&(this.visibleExitDrawData.length=0,this.visibleStandaloneExitNodes.forEach(t=>this.visibleExitDrawData.push(t.data)),x=!0),y&&this.roomLayer.batchDraw(),x&&this.linkLayer.batchDraw();const P=this.settings.perfCallback?performance.now():0;if(this.renderGrid(),this.settings.perfCallback){const t=performance.now()-P,i=performance.now()-e;this.perfMonitor.record({cullingMs:i,gridMs:t,visibleRooms:this.visibleRooms.size,totalRooms:this.roomNodes.size,visibleExits:this.visibleStandaloneExitNodes.size,fps:this.perfMonitor.computeFps()})}}syncPerfMonitor(){this.perfMonitor.setCallback(this.settings.perfCallback)}invalidateGridCache(){this.cachedGridBounds=null}renderGrid(){if(!this.settings.gridEnabled)return void(null!==this.cachedGridBounds&&(this.gridLayer.destroyChildren(),this.gridLayer.batchDraw(),this.cachedGridBounds=null));const t=this.stage.scaleX();if(!t)return;const e=this.stage.position(),i=this.stage.width(),s=this.stage.height(),n=(0-e.x)/t,r=(i-e.x)/t,o=(0-e.y)/t,a=(s-e.y)/t,h=2*this.settings.gridSize,l=Math.floor((Math.min(n,r)-h)/this.settings.gridSize)*this.settings.gridSize,d=Math.ceil((Math.max(n,r)+h)/this.settings.gridSize)*this.settings.gridSize,c=Math.floor((Math.min(o,a)-h)/this.settings.gridSize)*this.settings.gridSize,g=Math.ceil((Math.max(o,a)+h)/this.settings.gridSize)*this.settings.gridSize,u=this.cachedGridBounds;if(!u||u.left!==l||u.right!==d||u.top!==c||u.bottom!==g){this.gridLayer.destroyChildren();for(let t=l;t<=d;t+=this.settings.gridSize)this.gridLayer.add(new xi.Line({points:[t,c,t,g],stroke:this.settings.gridColor,strokeWidth:this.settings.gridLineWidth,listening:!1,perfectDrawEnabled:!1}));for(let t=c;t<=g;t+=this.settings.gridSize)this.gridLayer.add(new xi.Line({points:[l,t,d,t],stroke:this.settings.gridColor,strokeWidth:this.settings.gridLineWidth,listening:!1,perfectDrawEnabled:!1}));this.cachedGridBounds={left:l,right:d,top:c,bottom:g},this.gridLayer.batchDraw()}}clearCurrentRoomOverlay(){this.currentRoomOverlay.forEach(t=>t.destroy()),this.currentRoomOverlay=[],this.positionLayer.batchDraw()}updateCurrentRoomOverlay(t){if(this.clearCurrentRoomOverlay(),t.area!==this.currentArea||t.z!==this.currentZIndex)return void this.positionLayer.batchDraw();const e=new Map;e.set(t.id,t);const i=[],s=this.currentAreaInstance instanceof Wi?this.currentAreaInstance:void 0;this.currentAreaInstance&&void 0!==this.currentZIndex&&this.currentAreaInstance.getLinkExits(this.currentZIndex).filter(e=>e.a===t.id||e.b===t.id).forEach(t=>{const e=this.settings.highlightCurrentRoom?this.exitRenderer.renderWithColor(t,hs,this.currentZIndex):this.exitRenderer.render(t,this.currentZIndex);e&&i.push(e)});const n=this.settings.highlightCurrentRoom?hs:void 0;this.exitRenderer.renderSpecialExits(t,n).forEach(t=>{i.push(t)}),(this.settings.highlightCurrentRoom?this.exitRenderer.renderStubs(t,hs):this.exitRenderer.renderStubs(t)).forEach(t=>{i.push(t)}),[...Object.values(t.exits),...Object.values(t.specialExits)].forEach(t=>{const i=this.mapReader.getRoom(t),n=!s||s.hasVisitedRoom(t);i&&i.area===this.currentArea&&i.z===this.currentZIndex&&n&&e.set(t,i)}),i.forEach(t=>{this.positionLayer.add(t),this.currentRoomOverlay.push(t)}),e.forEach((e,i)=>{const s=i===t.id,n=this.createOverlayRoomGroup(e,{stroke:s&&this.settings.highlightCurrentRoom?hs:this.settings.lineColor});this.positionLayer.add(n),this.currentRoomOverlay.push(n),this.exitRenderer.renderInnerExits(e).forEach(t=>{this.positionLayer.add(t),this.currentRoomOverlay.push(t)})}),this.positionRender&&this.positionRender.moveToTop(),this.positionLayer.batchDraw()}createOverlayRoomGroup(t,e){const i=new xi.Group({x:t.x-this.settings.roomSize/2,y:t.y-this.settings.roomSize/2,listening:!1}),s=this.mapReader.getColorValue(t.env),n=this.settings.frameMode?this.settings.backgroundColor:s,r=this.settings.frameMode?s:e.stroke,o=this.settings.borders?this.settings.lineWidth:0,a="circle"===this.settings.roomShape?new xi.Circle({x:this.settings.roomSize/2,y:this.settings.roomSize/2,radius:this.settings.roomSize/2,fill:n,stroke:r,strokeWidth:o}):new xi.Rect({x:0,y:0,width:this.settings.roomSize,height:this.settings.roomSize,fill:n,stroke:r,strokeWidth:o,cornerRadius:"roundedRectangle"===this.settings.roomShape?.2*this.settings.roomSize:0});if(i.add(a),this.settings.emboss&&"circle"!==this.settings.roomShape){const t=this.settings.roomSize,e=ls(this.settings.lineColor)>.41;i.add(new xi.Line({points:e?[0,0,t,0,t,t]:[0,0,0,t,t,t],stroke:e?"#000000":"#ffffff",strokeWidth:this.settings.lineWidth,perfectDrawEnabled:!1,listening:!1}))}return this.renderSymbol(t,i),i}getSymbolColor(t,e){return this.settings.frameMode?this.mapReader.getColorValue(t):this.mapReader.getSymbolColor(t,e)}renderSymbol(t,e){if(void 0!==t.roomChar){const i=.75*this.settings.roomSize,s=new xi.Text({x:0,y:0,text:t.roomChar,fontSize:i,fontStyle:"bold",fill:this.getSymbolColor(t.env),align:"center",verticalAlign:"middle",width:this.settings.roomSize,height:this.settings.roomSize,perfectDrawEnabled:!1,listening:!1});e.add(s)}}renderExits(t){t.forEach(t=>{const e=this.exitRenderer.renderData(t,this.currentZIndex);if(!e)return;const i={data:e,bounds:e.bounds,targetRoomId:e.targetRoomId};this.standaloneExitNodes.push(i),this.addStandaloneExitToSpatialIndex(i),void 0!==e.targetRoomId&&this.areaExitHitZones.push({bounds:e.bounds,targetRoomId:e.targetRoomId})}),this.standaloneExitBoundsRoomSize=this.settings.roomSize,this.exitBatchShape=new xi.Shape({listening:!1,perfectDrawEnabled:!1,sceneFunc:t=>{const e=t._context;for(const i of this.visibleExitDrawData)this.drawExitData(e,i)}}),this.linkLayer.add(this.exitBatchShape)}drawExitData(t,e){for(const i of e.lines){t.beginPath(),t.moveTo(i.points[0],i.points[1]);for(let e=2;e<i.points.length;e+=2)t.lineTo(i.points[e],i.points[e+1]);t.strokeStyle=i.stroke,t.lineWidth=i.strokeWidth,i.dash?t.setLineDash(i.dash):t.setLineDash([]),t.stroke()}for(const i of e.arrows){t.beginPath(),t.moveTo(i.points[0],i.points[1]);for(let d=2;d<i.points.length;d+=2)t.lineTo(i.points[d],i.points[d+1]);t.strokeStyle=i.stroke,t.lineWidth=i.strokeWidth,i.dash?t.setLineDash(i.dash):t.setLineDash([]),t.stroke();const e=i.points.length-2,s=i.points[e],n=i.points[e+1],r=i.points[e-2],o=i.points[e-1],a=Math.atan2(n-o,s-r),h=i.pointerLength,l=i.pointerWidth/2;t.beginPath(),t.setLineDash([]),t.moveTo(s,n),t.lineTo(s-h*Math.cos(a-Math.atan2(l,h)),n-h*Math.sin(a-Math.atan2(l,h))),t.lineTo(s-h*Math.cos(a+Math.atan2(l,h)),n-h*Math.sin(a+Math.atan2(l,h))),t.closePath(),t.fillStyle=i.fill,t.fill(),t.strokeStyle=i.stroke,t.lineWidth=i.strokeWidth,t.stroke()}for(const i of e.doors)t.beginPath(),t.rect(i.x,i.y,i.width,i.height),t.strokeStyle=i.stroke,t.lineWidth=i.strokeWidth,t.setLineDash([]),t.stroke()}renderLabels(t){"none"!==this.settings.labelRenderMode&&t.forEach(t=>{if("image"===this.settings.labelRenderMode){if(!t.pixMap)return;const e=new Image;e.src=`data:image/png;base64,${t.pixMap}`;const i=new xi.Image({x:t.X,y:-t.Y,width:t.Width,height:t.Height,image:e,listening:!1});return void this.linkLayer.add(i)}this.renderLabelAsData(t)})}renderLabelAsData(t){const e=new xi.Group({listening:!1}),i=new xi.Rect({x:t.X,y:-t.Y,width:t.Width,height:t.Height,listening:!1});(t.BgColor?.alpha??0)>0&&!this.settings.transparentLabels?i.fill(this.getLabelColor(t.BgColor)):i.fillEnabled(!1),e.add(i);const s=Math.min(.75,t.Width/Math.max(t.Text.length/2,1)),n=Math.max(.1,Math.min(s,Math.max(.9*t.Height,.1))),r=new xi.Text({x:t.X,y:-t.Y,width:t.Width,height:t.Height,text:t.Text,fontSize:n,fillEnabled:!0,fill:this.getLabelColor(t.FgColor),align:"center",verticalAlign:"middle",listening:!1});e.add(r),this.linkLayer.add(e)}getLabelColor(t){const e=(t?.alpha??255)/255,i=t=>Math.min(255,Math.max(0,t??0));return`rgba(${i(t?.r)}, ${i(t?.g)}, ${i(t?.b)}, ${e})`}}const fs={rgbValue:"rgb(114, 1, 0)",symbolColor:[225,225,225]};function ps(t){const e=t[0]/255,i=t[1]/255,s=t[2]/255;return(Math.max(e,i,s)+Math.min(e,i,s))/2}class ms{constructor(t,e){this.rooms={},this.areas={},this.areaSources={},this.explorationEnabled=!1,this.colors={},t.forEach(t=>{t.rooms.forEach(t=>{t.y=-t.y,this.rooms[t.id]=t});const e=parseInt(t.areaId);this.areas[e]=new Fi(t),this.areaSources[e]=t}),this.colors=e.reduce((t,e)=>({...t,[e.envId]:{rgb:e.colors,rgbValue:`rgb(${e.colors.join(",")})`,symbolColor:ps(e.colors)>.41?[25,25,25]:[225,255,255],symbolColorValue:ps(e.colors)>.41?"rgb(25,25,25)":"rgb(225,255,255)"}}),{})}getArea(t){return this.areas[t]}getExplorationArea(t){const e=this.areas[t];if(e instanceof Wi)return e}getAreas(){return Object.values(this.areas)}getRooms(){return Object.values(this.rooms)}getRoom(t){return this.rooms[t]}ensureVisitedRooms(){return this.visitedRooms||(this.visitedRooms=new Set),this.visitedRooms}applyExplorationDecoration(){this.visitedRooms&&Object.entries(this.areaSources).forEach(([t,e])=>{const i=parseInt(t,10);this.areas[i]=new Wi(e,this.visitedRooms)})}decorateWithExploration(t){return void 0!==t?this.setVisitedRooms(t):this.ensureVisitedRooms(),this.applyExplorationDecoration(),this.explorationEnabled=!0,this.visitedRooms}getVisitedRooms(){return this.visitedRooms}clearExplorationDecoration(){Object.entries(this.areaSources).forEach(([t,e])=>{const i=parseInt(t,10);this.areas[i]=new Fi(e)}),this.explorationEnabled=!1}isExplorationEnabled(){return this.explorationEnabled}setVisitedRooms(t){return this.visitedRooms=t instanceof Set?t:new Set(t),this.explorationEnabled&&this.applyExplorationDecoration(),this.visitedRooms}addVisitedRoom(t){if(this.explorationEnabled){const e=this.getRoom(t);if(e){const i=this.getExplorationArea(e.area);if(i)return i.addVisitedRoom(t)}}const e=this.ensureVisitedRooms(),i=e.has(t);return e.add(t),!i}addVisitedRooms(t){const e=this.ensureVisitedRooms();let i=0;for(const s of t){if(this.explorationEnabled){const t=this.getRoom(s);if(t){const e=this.getExplorationArea(t.area);if(e){e.addVisitedRoom(s)&&i++;continue}}}const t=e.has(s);e.add(s),t||i++}return i}hasVisitedRoom(t){return this.visitedRooms?.has(t)??!1}getColorValue(t){return this.colors[t]?.rgbValue??fs.rgbValue}getSymbolColor(t,e){const i=this.colors[t]?.symbolColor??fs.symbolColor,s=Math.min(Math.max(e??1,0),1),n=i.join(",");return 1!=s?`rgba(${n}, ${s})`:`rgba(${n})`}}function ys(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var xs,vs,bs,_s,ws,Ss,Cs,ks,Rs,Es;function Ms(){if(Ss)return ws;return Ss=1,ws=function t(e){const i=new Map;return Object.keys(e).forEach(s=>{const n=e[s];if(null!==n&&"object"==typeof n&&!Array.isArray(n))return i.set(s,t(n));if(!function(t){const e=Number(t);return!(isNaN(e)||e<=0)}(n))throw new Error(`Could not add node at key "${s}", make sure it's a valid node`,n);return i.set(s,Number(n))}),i},ws}const Ps=ys(function(){if(Es)return Rs;Es=1;const t=vs?xs:(vs=1,xs=class{constructor(){this.keys=new Set,this.queue=[]}sort(){this.queue.sort((t,e)=>t.priority-e.priority)}set(t,e){const i=Number(e);if(isNaN(i))throw new TypeError('"priority" must be a number');return this.keys.has(t)?this.queue.map(e=>(e.key===t&&Object.assign(e,{priority:i}),e)):(this.keys.add(t),this.queue.push({key:t,priority:i})),this.sort(),this.queue.length}next(){const t=this.queue.shift();return this.keys.delete(t.key),t}isEmpty(){return 0===this.queue.length}has(t){return this.keys.has(t)}get(t){return this.queue.find(e=>e.key===t)}}),e=(_s||(_s=1,bs=function t(e,i){const s=new Map;for(const[n,r]of e)n!==i&&r instanceof Map?s.set(n,t(r,i)):n!==i&&s.set(n,r);return s}),bs),i=Ms(),s=(ks||(ks=1,Cs=function t(e){if(!(e instanceof Map))throw new Error("Invalid graph: Expected Map instead found "+typeof e);e.forEach((e,i)=>{if("object"==typeof e&&e instanceof Map)t(e);else if("number"!=typeof e||e<=0)throw new Error(`Values must be numbers greater than 0. Found value ${e} at ${i}`)})}),Cs);return Rs=class{constructor(t){t instanceof Map?(s(t),this.graph=t):this.graph=t?i(t):new Map}addNode(t,e){let n;return e instanceof Map?(s(e),n=e):n=i(e),this.graph.set(t,n),this}addVertex(t,e){return this.addNode(t,e)}removeNode(t){return this.graph=e(this.graph,t),this}path(e,i,s={}){if(!this.graph.size)return s.cost?{path:null,cost:0}:null;const n=new Set,r=new t,o=new Map;let a=[],h=0,l=[];if(s.avoid&&(l=[].concat(s.avoid)),l.includes(e))throw new Error(`Starting node (${e}) cannot be avoided`);if(l.includes(i))throw new Error(`Ending node (${i}) cannot be avoided`);for(r.set(e,0);!r.isEmpty();){const t=r.next();if(t.key===i){h=t.priority;let e=t.key;for(;o.has(e);)a.push(e),e=o.get(e);break}n.add(t.key),(this.graph.get(t.key)||new Map).forEach((e,i)=>{if(n.has(i)||l.includes(i))return null;if(!r.has(i))return o.set(i,t.key),r.set(i,t.priority+e);const s=r.get(i).priority,a=t.priority+e;return a<s?(o.set(i,t.key),r.set(i,a)):null})}return a.length?(s.trim?a.shift():a=a.concat([e]),s.reverse||(a=a.reverse()),s.cost?{path:a,cost:h}:a):s.cost?{path:null,cost:0}:null}shortestPath(...t){return this.path(...t)}}}()),As={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"},Ts={north:"n",northeast:"ne",northwest:"nw",east:"e",west:"w",south:"s",southeast:"se",southwest:"sw",up:"up",down:"down",in:"in",out:"out"};function Ls(t,e){t.push(e);let i=t.length-1;for(;i>0;){const e=i-1>>1;if(t[e].priority<=t[i].priority)break;[t[e],t[i]]=[t[i],t[e]],i=e}}function Ds(t){if(0===t.length)return;const e=t[0],i=t.pop();if(t.length>0){t[0]=i;let e=0;const s=t.length;for(;;){let i=e;const n=2*e+1,r=2*e+2;if(n<s&&t[n].priority<t[i].priority&&(i=n),r<s&&t[r].priority<t[i].priority&&(i=r),i===e)break;[t[e],t[i]]=[t[i],t[e]],e=i}}return e}function Is(t,e,i){const s=[i];let n=i;for(;n!==e;)n=t.get(n),s.push(n);return s.reverse(),s}class Gs{constructor(t,e="dijkstra"){this.cache=new Map,this.mapReader=t,this._algorithm=e;const{adj:i,maxEdgeDistance:s,minEdgeWeight:n,graphDefinition:r}=this.buildGraph();this.adj=i,this.graph=new Ps(r),this.maxEdgeDistance=s,this.minEdgeWeight=n}get algorithm(){return this._algorithm}setAlgorithm(t){t!==this._algorithm&&(this._algorithm=t,this.cache.clear())}findPath(t,e){const i=`${t}->${e}`;if(this.cache.has(i))return this.cache.get(i);if(t===e){const e=this.mapReader.getRoom(t)?[t]:null;return this.cache.set(i,e),e}if(!this.mapReader.getRoom(t)||!this.mapReader.getRoom(e))return this.cache.set(i,null),null;let s;switch(this._algorithm){case"dijkstra":s=function(t,e,i){const s=t.path(e.toString(),i.toString()),n=Array.isArray(s)?s:s?.path;return n?n.map(t=>Number(t)):null}(this.graph,t,e);break;case"astar":s=function(t,e,i,s,n,r){const o=s.getRoom(i);if(!o)return null;const a=o.x,h=o.y,l=o.z,d=t=>{const e=s.getRoom(t);if(!e)return 0;const i=e.x-a,o=e.y-h,d=e.z-l;return Math.sqrt(i*i+o*o+d*d)/n*r},c=new Map,g=new Map,u=[];for(c.set(e,0),Ls(u,{id:e,priority:d(e)});u.length>0;){const{id:s}=Ds(u);if(s===i)return Is(g,e,i);const n=c.get(s)??1/0,r=t.get(s);if(r)for(const t of r){const e=n+t.weight;e<(c.get(t.id)??1/0)&&(c.set(t.id,e),g.set(t.id,s),Ls(u,{id:t.id,priority:e+d(t.id)}))}}return null}(this.adj,t,e,this.mapReader,this.maxEdgeDistance,this.minEdgeWeight)}return this.cache.set(i,s),s}resolveEdgeWeight(t,e,i){const s=t.exitWeights?.[e];return void 0!==s&&s>0?s:Math.max(i.weight,1)}buildGraph(){const t=new Map,e={};let i=1,s=1/0;return this.mapReader.getRooms().forEach(n=>{const r=[],o={},a=new Set((n.exitLocks??[]).map(t=>As[t]).filter(t=>!!t)),h=new Set(n.mSpecialExitLocks??[]);Object.entries(n.exits??{}).forEach(([t,e])=>{if(a.has(t))return;const h=this.mapReader.getRoom(e);if(h){const a=Ts[t]??t,l=this.resolveEdgeWeight(n,a,h);r.push({id:e,weight:l}),o[e.toString()]=l,l<s&&(s=l);const d=h.x-n.x,c=h.y-n.y,g=h.z-n.z,u=Math.sqrt(d*d+c*c+g*g);u>i&&(i=u)}}),Object.entries(n.specialExits??{}).forEach(([t,e])=>{if(h.has(e))return;const a=this.mapReader.getRoom(e);if(a){const h=this.resolveEdgeWeight(n,t,a);r.push({id:e,weight:h}),o[e.toString()]=h,h<s&&(s=h);const l=a.x-n.x,d=a.y-n.y,c=a.z-n.z,g=Math.sqrt(l*l+d*d+c*c);g>i&&(i=g)}}),t.set(n.id,r),e[n.id.toString()]=o}),isFinite(s)||(s=1),{adj:t,maxEdgeDistance:i,minEdgeWeight:s,graphDefinition:e}}}export{us as f,ms as m,Gs as p,gs as z};
|
|
2
|
-
//# sourceMappingURL=index-DN84wJBG.js.map
|