@inweb/viewer-visualize 26.12.4 → 26.12.6

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.
@@ -21,4 +21,4 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ODA=t.ODA||{},t.ODA.Visualize=t.ODA.Visualize||{}))}(this,function(t){"use strict";class e{constructor(){this._commands=new Map}registerCommand(t,e,i,s){this._commands.set(t,{id:t,handler:e,thisArg:s,description:i})}registerCommandAlias(t,e){this.registerCommand(e,(e,...i)=>this.executeCommand(t,e,...i))}getCommand(t){return this._commands.get(t)}getCommands(){const t=new Map;return this._commands.forEach((e,i)=>t.set(i,e)),t}executeCommand(t,e,...i){const s=this._commands.get(t);if(!s){if(e){if(e.draggers.includes(t))return e.setActiveDragger(t)}return void console.warn(`Command '${t}' not found`)}const{handler:r,thisArg:n}=s,a=r.apply(n,[e,...i]);return null==e||e.emit({type:"command",data:t,args:i}),a}}const i=new Map;function s(t=""){let s=i.get(t);return s||(s=new e,i.set(t,s)),s}class r{constructor(){this._providers=new Map}registerDragger(t,e){this._providers.set(t,e)}registerDraggerAlias(t,e){const i=this._providers.get(t);i&&this.registerDragger(e,t=>i(t))}getDraggers(){const t=new Map;return this._providers.forEach((e,i)=>t.set(i,e)),t}createDragger(t,e){const i=this._providers.get(t);if(!i)return null;const s=i(e);return s.name=t,s}}const n=new Map;function a(t=""){let e=n.get(t);return e||(e=new r,n.set(t,e)),e}class o{constructor(){this._providers=new Map}registerComponent(t,e){this._providers.set(t,e)}registerComponentAlias(t,e){const i=this._providers.get(t);i&&this.registerComponent(e,t=>i(t))}getComponents(){const t=new Map;return this._providers.forEach((e,i)=>t.set(i,e)),t}createComponent(t,e){const i=this._providers.get(t);if(!i)return null;const s=i(e);return s.name=t,s}}const h=new Map;function l(t=""){let e=h.get(t);return e||(e=new o,h.set(t,e)),e}class d{constructor(){this.name="",this.abortController=new AbortController}dispose(){this.abortController.abort(),this.abortController=void 0}isSupport(t,e){return!1}load(t,e,i){return Promise.resolve(this)}cancel(){this.abortController.abort()}extractFileName(t){const e=/[^/\\?#:]+(?=\?|#|$)/;return"string"==typeof t?(t.match(e)||[])[0]:t instanceof globalThis.File?(t.name.match(e)||[])[0]:void 0}}class c{constructor(){this._providers=new Map}registerLoader(t,e){this._providers.set(t,e)}getLoader(t){return this._providers.get(t)}getLoaders(){const t=new Map;return this._providers.forEach((e,i)=>t.set(i,e)),t}createLoader(t,e,i){let s=null;return this._providers.forEach((r,n)=>{const a=r(t);a.isSupport(e,i)&&(s=a,s.name=n)}),s}}const u=new Map;function g(t=""){let e=u.get(t);return e||(e=new c,u.set(t,e)),e}function p(){return{showWCS:!0,cameraAnimation:!0,antialiasing:!0,groundShadow:!1,shadows:!1,cameraAxisXSpeed:4,cameraAxisYSpeed:1,ambientOcclusion:!1,enableStreamingMode:!0,enablePartialMode:!1,memoryLimit:3294967296,cuttingPlaneFillColor:{red:255,green:152,blue:0},edgesColor:{r:255,g:152,b:0},facesColor:{r:255,g:152,b:0},edgesVisibility:!0,edgesOverlap:!0,facesOverlap:!1,facesTransparancy:200,enableCustomHighlight:!0,sceneGraph:!1,edgeModel:!0,reverseZoomWheel:!1,enableZoomWheel:!0,enableGestures:!0,geometryType:"vsfx",rulerUnit:"Default",rulerPrecision:2,cameraMode:"perspective"}}class m{constructor(t){this._emitter=t,this._data={showWCS:!0,cameraAnimation:!0,antialiasing:!0,groundShadow:!1,shadows:!1,cameraAxisXSpeed:4,cameraAxisYSpeed:1,ambientOcclusion:!1,enableStreamingMode:!0,enablePartialMode:!1,memoryLimit:3294967296,cuttingPlaneFillColor:{red:255,green:152,blue:0},edgesColor:{r:255,g:152,b:0},facesColor:{r:255,g:152,b:0},edgesVisibility:!0,edgesOverlap:!0,facesOverlap:!1,facesTransparancy:200,enableCustomHighlight:!0,sceneGraph:!1,edgeModel:!0,reverseZoomWheel:!1,enableZoomWheel:!0,enableGestures:!0,geometryType:"vsfx",rulerUnit:"Default",rulerPrecision:2,cameraMode:"perspective"},this.loadFromStorage()}static defaults(){return{showWCS:!0,cameraAnimation:!0,antialiasing:!0,groundShadow:!1,shadows:!1,cameraAxisXSpeed:4,cameraAxisYSpeed:1,ambientOcclusion:!1,enableStreamingMode:!0,enablePartialMode:!1,memoryLimit:3294967296,cuttingPlaneFillColor:{red:255,green:152,blue:0},edgesColor:{r:255,g:152,b:0},facesColor:{r:255,g:152,b:0},edgesVisibility:!0,edgesOverlap:!0,facesOverlap:!1,facesTransparancy:200,enableCustomHighlight:!0,sceneGraph:!1,edgeModel:!0,reverseZoomWheel:!1,enableZoomWheel:!0,enableGestures:!0,geometryType:"vsfx",rulerUnit:"Default",rulerPrecision:2,cameraMode:"perspective"}}notifierChangeEvent(){console.warn("Options.notifierChangeEvent() has been deprecated since 25.3 and will be removed in a future release, use Options.change() instead."),this.change()}change(){void 0!==this._emitter&&(this.saveToStorage(),this._emitter.emit({type:"optionschange",data:this}))}saveToStorage(){if("undefined"!=typeof window)try{localStorage.setItem("od-client-settings",JSON.stringify(this.data))}catch(t){console.error("Cannot save client settings.",t)}}loadFromStorage(){if("undefined"!=typeof window)try{const t=localStorage.getItem("od-client-settings");if(t){const e=JSON.parse(t);this.data={...e}}}catch(t){console.error("Cannot load client settings.",t)}}resetToDefaults(t){if(void 0!==t){const e=m.defaults(),i=t.reduce((t,i)=>(t[i]=e[i],t),{});this.data={...this.data,...i}}else this.data={...this.data,...m.defaults()}}get data(){return this._data}set data(t){const e=!!t.enableStreamingMode&&t.enablePartialMode,i=!e&&t.sceneGraph;this._data={...m.defaults(),...this._data,...t,enablePartialMode:e,sceneGraph:i},this.change()}get showWCS(){return this._data.showWCS}set showWCS(t){this._data.showWCS=t,this.change()}get cameraAnimation(){return this._data.cameraAnimation}set cameraAnimation(t){this._data.cameraAnimation=t,this.change()}get antialiasing(){return this._data.antialiasing}set antialiasing(t){this._data.antialiasing=t,this.change()}get groundShadow(){return this._data.groundShadow}set groundShadow(t){this._data.groundShadow=t,this.change()}get shadows(){return this._data.shadows}set shadows(t){this._data.shadows=t,this.change()}get cameraAxisXSpeed(){return this._data.cameraAxisXSpeed}set cameraAxisXSpeed(t){this._data.cameraAxisXSpeed=t,this.change()}get cameraAxisYSpeed(){return this._data.cameraAxisYSpeed}set cameraAxisYSpeed(t){this.cameraAxisYSpeed=t,this.change()}get ambientOcclusion(){return this._data.ambientOcclusion}set ambientOcclusion(t){this._data.ambientOcclusion=t,this.change()}get enableStreamingMode(){return this._data.enableStreamingMode}set enableStreamingMode(t){this._data.enableStreamingMode=t,t||(this._data.enablePartialMode=!1),this.change()}get enablePartialMode(){return this._data.enablePartialMode}set enablePartialMode(t){this._data.enablePartialMode=t,t&&(this._data.enableStreamingMode=!0,this._data.sceneGraph=!1),this.change()}get memoryLimit(){return this._data.memoryLimit}set memoryLimit(t){this._data.memoryLimit=t,this.change()}get cuttingPlaneFillColor(){return this._data.cuttingPlaneFillColor}set cuttingPlaneFillColor(t){this._data.cuttingPlaneFillColor=t,this.change()}get edgesColor(){return this._data.edgesColor}set edgesColor(t){this._data.edgesColor=t,this.change()}get facesColor(){return this._data.facesColor}set facesColor(t){this._data.facesColor=t,this.change()}get edgesVisibility(){return this._data.edgesVisibility}set edgesVisibility(t){this._data.edgesVisibility=t,this.change()}get edgesOverlap(){return this._data.edgesOverlap}set edgesOverlap(t){this._data.edgesOverlap=t,this.change()}get facesOverlap(){return this._data.facesOverlap}set facesOverlap(t){this._data.facesOverlap=t,this.change()}get facesTransparancy(){return this._data.facesTransparancy}set facesTransparancy(t){this._data.facesTransparancy=t,this.change()}get enableCustomHighlight(){return this._data.enableCustomHighlight}set enableCustomHighlight(t){this._data.enableCustomHighlight=t,this.change()}get sceneGraph(){return this._data.sceneGraph}set sceneGraph(t){this._data.sceneGraph=t,t&&(this._data.enablePartialMode=!1),this.change()}get edgeModel(){return Boolean(this._data.edgeModel)}set edgeModel(t){this._data.edgeModel=Boolean(t),this.change()}get reverseZoomWheel(){return this._data.reverseZoomWheel}set reverseZoomWheel(t){this._data.reverseZoomWheel=!!t,this.change()}get enableZoomWheel(){return this._data.enableZoomWheel}set enableZoomWheel(t){this._data.enableZoomWheel=!!t,this.change()}get enableGestures(){return this._data.enableGestures}set enableGestures(t){this._data.enableGestures=!!t,this.change()}get geometryType(){return this._data.geometryType}set geometryType(t){this._data.geometryType=t,this.change()}get rulerUnit(){return this._data.rulerUnit}set rulerUnit(t){this._data.rulerUnit=t,this.change()}get rulerPrecision(){return this._data.rulerPrecision}set rulerPrecision(t){this._data.rulerPrecision=t,this.change()}get cameraMode(){return this._data.cameraMode||"perspective"}set cameraMode(t){this._data.cameraMode=t,this.change()}}const f=["click","contextmenu","dblclick","mousedown","mouseleave","mousemove","mouseup","pointercancel","pointerdown","pointerleave","pointermove","pointerup","touchcancel","touchend","touchmove","touchstart","wheel"],_=f;class v{constructor(){this.performance={fps:0,frameTime:0,timeToFirstRender:0,loadTime:0},this.render={viewport:{width:0,height:0},antialiasing:"",drawCalls:0,triangles:0,points:0,lines:0},this.scene={objects:0,triangles:0,points:0,lines:0,edges:0},this.optimizedScene={objects:0,triangles:0,points:0,lines:0,edges:0},this.memory={geometries:0,geometryBytes:0,textures:0,textureBytes:0,materials:0,totalEstimatedGpuBytes:0,usedJSHeapSize:0},this.system={webglRenderer:"",webglVendor:""}}}class y{constructor(t){this.setViewParams=t=>{var e;const i=this.m_module.getViewer().getActiveTvExtendedView();i.setView(t.position,t.target,t.upVector,t.viewFieldWidth,t.viewFieldHeight,t.perspective),null===(e=i.delete)||void 0===e||e.call(i)},this.getViewParams=()=>{var t;const e=this.m_module.getViewer().activeView,i={position:e.viewPosition,target:e.viewTarget,upVector:e.upVector,viewFieldWidth:e.viewFieldWidth,viewFieldHeight:e.viewFieldHeight,perspective:e.perspective};return null===(t=e.delete)||void 0===t||t.call(e),i},this.m_module=t}getViewer(){return this.m_module.getViewer()}getModel(){return this.getViewer().getMarkupModel()}copyPoint(t){const e=new this.m_module.Point3d;return e.set(t.x,t.y,t.z),e}createVector3d(){return new this.m_module.Vector3d}createPoint3d(){return new this.m_module.Point3d}createMatrix3d(){return new this.m_module.Matrix3d}createPlane(){return new this.m_module.OdTvPlane}toVector(t){return this.m_module.Vector3d.createFromArray(t)}toGeVector(t){return[t.x,t.y,t.z]}toGePoint(t){return[t.x,t.y,t.z]}toPoint(t){return this.m_module.Point3d.createFromArray(t)}screenToWorld(t,e){return this.toPoint(this.m_module.getViewer().screenToWorld(t,e))}toDoubleArray(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x),e.push(t[i].y),e.push(t[i].z);return e}correctCameraTarget(){const t=this.getViewParams(),e=this.m_module.getViewer().getActiveExtents(),{min:i,max:s}=e,r=this.toPoint(t.target);r.x>=i.x&&r.y>=i.y&&r.z>=i.z&&r.x<=s.x&&r.y<=s.y&&r.z<=s.z||(t.target=e.center(),this.setViewParams(t))}}class w extends y{constructor(t){super(t.visualizeJs),this.beginInteractivity=()=>{const t=this.getViewer().activeView;t.beginInteractivity&&(t.beginInteractivity(24),this.subject.update()),t.delete()},this.endInteractivity=()=>{const t=this.getViewer().activeView;if(t.endInteractivity){t.endInteractivity();const e=this.getViewer().getActiveDevice(),i=this.m_module.canvas;e.invalidate([0,0,i.width,i.height]),e.delete(),this.subject.update()}t.delete()},this.subject=t,this.needInputText=!1,this.mouseDownPosition={x:0,y:0},this.autoSelect=!1,this.onmessage=t=>this.subject.emitEvent(t),this.canvasEvents=_}initialize(){this.canvasEvents=this.canvasEvents.filter(t=>"function"==typeof this[t]),this.canvasEvents.forEach(t=>this[t]=this[t].bind(this)),this.canvasEvents.forEach(t=>this.subject.on(t,this[t])),this.getViewer().setEnableAutoSelect(!!this.autoSelect)}dispose(){this.canvasEvents.forEach(t=>this.subject.off(t,this[t]))}relativeCoords(t){return{x:t.offsetX*window.devicePixelRatio,y:t.offsetY*window.devicePixelRatio}}pointerdown(t){if(!t.isPrimary||w.isGestureActive)return;t.target.setPointerCapture(t.pointerId);const e=this.relativeCoords(t);this.isDragging=!0,this.mouseDownPosition={x:e.x,y:e.y},this.start(e.x,e.y,t.clientX,t.clientY),this.subject.update()}pointerup(t){if(w.needSkipPointerUp)return;if(!t.isPrimary)return;t.target.releasePointerCapture(t.pointerId);const e=this.relativeCoords(t);this.end(e.x,e.y,t.clientX,t.clientY),this.isDragging=!1,this.subject.update()}pointercancel(t){t.isPrimary&&this.m_module.canvas.dispatchEvent(new PointerEvent("pointerup",t))}pointermove(t){if(!t.isPrimary||w.isGestureActive)return;const e=this.relativeCoords(t);this.drag(e.x,e.y,t.clientX,t.clientY),this.isDragging&&this.subject.update()}click(t){const e=this.getViewer(),i=this.relativeCoords(t),s=i.x,r=i.y,n=Math.abs(s-this.mouseDownPosition.x)<5&&Math.abs(r-this.mouseDownPosition.y)<5;if(e&&e.getEnableAutoSelect()&&n){e.unselect(),e.select(s,r,s,r),this.subject.update();const t=e.getSelected();this.onmessage({type:"select",data:t,handles:this.subject.getSelected()}),this.onmessage({type:"select2",data:t,handles:this.subject.getSelected2()})}}dblclick(t){const e=this.getViewer(),i=this.relativeCoords(t),s=i.x,r=i.y,n=e.getActiveDevice(),a=n.viewAt([s,r]);if(a&&!a.active)e.activeView=a,a.delete(),this.subject.update();else if(e&&e.getEnableAutoSelect()){const t=e.getSelected();if(!t.isNull()&&0!==t.numItems()){const i=t.getIterator(),s=i.getEntity();e.zoomToEntity(s),this.onmessage({type:"zoomtoentity",data:s}),this.subject.update(),this.deleteAll([i,s])}}n.delete()}start(t,e,i=0,s=0){}drag(t,e,i=0,s=0){}end(t,e,i=0,s=0){}getActiveMarkupEntity(t){return this.subject.addMarkupEntity(t)}syncOverlayView(){return this.subject.syncOverlay()}deleteAll(t){var e;for(const i of t)null===(e=null==i?void 0:i.delete)||void 0===e||e.call(i)}updatePreview(){}static set isGestureActive(t){w._isGestureActive!==t&&(w._isGestureActive=t,w._isGestureActive&&(w.needSkipPointerUp=!0))}static get isGestureActive(){return w._isGestureActive}static get needSkipPointerUp(){return!!w._needSkipPointerUp&&(w.needSkipPointerUp=!1,!0)}static set needSkipPointerUp(t){w._needSkipPointerUp=t}}function x(t,e,i){return t||((t=document.createElement("div")).setAttribute("data-testid",i),e.appendChild(t)),t}function b(t,e){return t&&e.removeChild(t),null}function S(t,e,i){const s=e.Point3d.createFromArray(t),r=i.activeView,n=r.worldToDeviceMatrix,a=s.transformBy(n),o={x:a.x/window.devicePixelRatio,y:a.y/window.devicePixelRatio};return n.delete(),s.delete(),a.delete(),r.delete(),o}function C(t){return t<0?Math.ceil(t):Math.floor(t)}w._isGestureActive=!1,w._needSkipPointerUp=!1;function A(t,e,i,s,r){const n=((t,e,i,s)=>{const r=e.x-t.x,n=e.y-t.y,a=s.x-i.x,o=s.y-i.y,h=(-n*(t.x-i.x)+r*(t.y-i.y))/(-a*n+r*o),l=(+a*(t.y-i.y)-o*(t.x-i.x))/(-a*n+r*o);return h>=0&&h<=1&&l>=0&&l<=1&&{x:C(t.x+l*r),y:C(t.y+l*n)}})(t,e,i,s);n&&r.push(n)}function T(t,e,i){return t.x<=e&&t.x>=0&&t.y<=i&&t.y>=0}function P(t,e){t&&(t.onclick=e?()=>e():()=>{})}function k(t,e){t.style.pointerEvents=e?"auto":"none"}class E{constructor(t,e,i){this.htmlElemStartPoint=null,this.htmlElemEndPoint=null,this.htmlElemLine=null,this.htmlElemTitle=null,this.startPoint=null,this.endPoint=null,this.scale=1,this.unit="",this.precision=2,this.size=10,this.lineThickness=2,this.style={border:"2px solid #FFFFFF",background:"#009bff",color:"white",boxShadow:"0 0 10px rgba(0,0,0,0.5)"},this.htmlElemStartPoint=x(this.htmlElemStartPoint,t,"ruler-start"),this.htmlElemEndPoint=x(this.htmlElemEndPoint,t,"ruler-end"),this.htmlElemLine=x(this.htmlElemLine,t,"ruler-line"),this.htmlElemTitle=x(this.htmlElemTitle,t,"ruler-value"),this.viewer=e,this.moduleInstance=i,this.targetElement=t,this.isFinishDraw=!1}drawMeasureLine(){const t=this.size,e=this.moduleInstance.canvas.getBoundingClientRect();if(this.startPoint){this.htmlElemStartPoint=x(this.htmlElemStartPoint,this.targetElement,"ruler-start");const i=S(this.startPoint,this.moduleInstance,this.viewer);T(i,e.width,e.height)?(this.htmlElemStartPoint.style.display="block",this.htmlElemStartPoint.style.cursor="pointer",this.htmlElemStartPoint.style.position="absolute",this.htmlElemStartPoint.style.top=i.y-t/2+"px",this.htmlElemStartPoint.style.left=i.x-t/2+"px",this.htmlElemStartPoint.style.borderRadius=`${t}px`,this.htmlElemStartPoint.style.border=this.style.border,this.htmlElemStartPoint.style.background=this.style.background,this.htmlElemStartPoint.style.zIndex="2",this.htmlElemStartPoint.style.width=`${t}px`,this.htmlElemStartPoint.style.height=`${t}px`,this.htmlElemStartPoint.style.boxShadow=this.style.boxShadow):this.htmlElemStartPoint.style.display="none"}if(this.endPoint&&this.isFinishDraw){this.htmlElemEndPoint=x(this.htmlElemEndPoint,this.targetElement,"ruler-end");const i=S(this.endPoint,this.moduleInstance,this.viewer);T(i,e.width,e.height)?(this.htmlElemEndPoint.style.display="block",this.htmlElemEndPoint.style.cursor="pointer",this.htmlElemEndPoint.style.position="absolute",this.htmlElemEndPoint.style.top=i.y-t/2+"px",this.htmlElemEndPoint.style.left=i.x-t/2+"px",this.htmlElemEndPoint.style.borderRadius=`${t}px`,this.htmlElemEndPoint.style.border=this.style.border,this.htmlElemEndPoint.style.background=this.style.background,this.htmlElemEndPoint.style.zIndex="2",this.htmlElemEndPoint.style.width=`${t}px`,this.htmlElemEndPoint.style.height=`${t}px`,this.htmlElemEndPoint.style.boxShadow=this.style.boxShadow):this.htmlElemEndPoint.style.display="none"}if(this.endPoint&&this.startPoint){const t=S(this.startPoint,this.moduleInstance,this.viewer),i=S(this.endPoint,this.moduleInstance,this.viewer),{p1:s,p2:r,angle:n,width:a}=function(t,e,i,s){const r={x:0,y:0},n={x:i,y:0},a={x:0,y:s},o={x:i,y:s},h=[];A(t,e,r,n,h),A(t,e,r,a,h),A(t,e,a,o,h),A(t,e,o,n,h);let l=null,d=null;0===h.length?(l=t,d=e):1===h.length?T(t,i,s)?(l=t,d=h[0]):(l=h[0],d=e):(l=h[0],d=h[1]);const c=d.x-l.x,u=d.y-l.y;let g=180*Math.atan(u/c)/Math.PI;return c<0&&(g-=180),{angle:g,width:Math.sqrt(Math.pow(c,2)+Math.pow(u,2)),p1:l,p2:d}}(t,i,e.width,e.height),o=r.x-s.x,h=r.y-s.y,l=this.lineThickness;if(T(s,e.width,e.height)&&T(r,e.width,e.height)){this.htmlElemLine=x(this.htmlElemLine,this.targetElement,"ruler-line"),this.htmlElemLine.style.display="block",this.htmlElemLine.style.cursor="pointer",this.htmlElemLine.style.position="absolute",this.htmlElemLine.style.top=`${s.y}px`,this.htmlElemLine.style.left=`${s.x}px`,this.htmlElemLine.style.width=`${a}px`,this.htmlElemLine.style.transform=`rotate(${n}deg)`,this.htmlElemLine.style.transformOrigin=`0px ${l/2}px`,this.htmlElemLine.style.boxShadow=this.style.boxShadow,this.htmlElemLine.style.border="none",this.htmlElemLine.style.background=this.style.background,this.htmlElemLine.style.zIndex="1",this.htmlElemLine.style.height=`${l}px`;const t=this.getDistance(),e=s.x+o/2,i=s.y+h/2;this.htmlElemTitle=x(this.htmlElemTitle,this.targetElement,"ruler-value"),this.htmlElemTitle.style.display="block",this.htmlElemTitle.style.cursor="pointer",this.htmlElemTitle.style.font="10px",this.htmlElemTitle.style.color="white",this.htmlElemTitle.style.position="Absolute",this.htmlElemTitle.style.top=`${i}px`,this.htmlElemTitle.style.left=`${e}px`,this.htmlElemTitle.style.transform="translate(-50%, -50%)",this.htmlElemTitle.style.borderRadius="5px",this.htmlElemTitle.style.boxShadow=this.style.boxShadow,this.htmlElemTitle.style.border="none",this.htmlElemTitle.style.background=this.style.background,this.htmlElemTitle.style.zIndex="3",this.htmlElemTitle.style.padding="2px",this.htmlElemTitle.style.textAlign="center",this.htmlElemTitle.innerHTML=this.formatDistance(t)}else this.htmlElemLine.style.display="none",this.htmlElemTitle.style.display="none"}}getDistance(){let t=function(t,e,i){const s=i.Point3d.createFromArray(t),r=i.Point3d.createFromArray(e),n=s.distanceTo(r).toFixed(2);return s.delete(),r.delete(),n}(this.startPoint,this.endPoint,this.moduleInstance);return Math.abs(this.scale)>1e-10&&(t/=this.scale),t}calculatePrecision(t){const e=Math.abs(t);return e>=1e3?0:e>=10?1:e>=.1?2:e>=.001?3:e>0?Math.floor(-Math.log10(e))+1:2}formatDistance(t){let e;e="Auto"===this.precision?this.calculatePrecision(t):Number.isFinite(this.precision)?this.precision:parseFloat(this.precision),Number.isFinite(e)?e<0?e=0:e>10&&(e=10):e=2;let i=t.toFixed(e);return"Auto"===this.precision&&(i=i.replace(/\.0+$/,"").replace(/\.$/,"")),+i!==t&&(i="~ "+i),`${i} ${this.unit}`}setStartPoint(t){this.startPoint=t,this.drawMeasureLine()}setEndPoint(t,e){this.isFinishDraw=void 0===e||e,this.endPoint=t,this.drawMeasureLine()}update(){this.drawMeasureLine()}setSize(t){this.size=t,this.drawMeasureLine()}clear(){this.endPoint=null,this.startPoint=null,this.htmlElemStartPoint=b(this.htmlElemStartPoint,this.targetElement),this.htmlElemEndPoint=b(this.htmlElemEndPoint,this.targetElement),this.htmlElemLine=b(this.htmlElemLine,this.targetElement),this.htmlElemTitle=b(this.htmlElemTitle,this.targetElement)}setUnit(t){this.unit=t,this.drawMeasureLine()}setConversionFactor(t){this.scale=t,this.drawMeasureLine()}setPrecision(t){this.precision=t,this.drawMeasureLine()}setStyle(t){this.style=t,this.drawMeasureLine()}setSelectionReactor(t){P(this.htmlElemStartPoint,t?t.onStartPoint:null),P(this.htmlElemEndPoint,t?t.onEndPoint:null),P(this.htmlElemTitle,t?t.onTitle:null)}setSelectability(t){k(this.htmlElemStartPoint,t),k(this.htmlElemEndPoint,t),k(this.htmlElemLine,t),k(this.htmlElemTitle,t)}}function M(t,e){return t[e]||e}class I extends w{constructor(t){var e,i;super(t),this.lineThickness=2,this.press=!1,this.gripingRadius=5,this.firstPoint=null,this.secondPoint=null,this.rulerUnitTable={Millimeters:"mm",Centimeters:"cm",Meters:"m",Feet:"ft",Inches:"in",Yards:"yd",Kilometers:"km",Miles:"mi",Micrometers:"µm",Mils:"mil",MicroInches:"µin",Default:"unit"},this.rulerUnit=null!==(e=t.options.rulerUnit)&&void 0!==e?e:"Default",this.rulerPrecision=null!==(i=t.options.rulerPrecision)&&void 0!==i?i:"Default",this.items=[],this.canvasEvents.push("resize","optionsChange")}initialize(){super.initialize(),this.m_overlayElement=document.createElement("div"),this.m_overlayElement.style.background="rgba(0,0,0,0)",this.m_overlayElement.style.position="fixed",this.m_overlayElement.style.zIndex="1",this.m_overlayElement.style.pointerEvents="none",document.body.appendChild(this.m_overlayElement),this.subject.addEventListener("optionschange",this.optionsChange),this.resize()}dispose(){super.dispose(),this.m_overlayElement.remove(),this.subject.removeEventListener("optionschange",this.optionsChange)}updatePreview(){this.items.forEach(t=>t.update())}resize(){const t=this.m_module.canvas.getBoundingClientRect();this.m_overlayElement.style.top=`${t.top}px`,this.m_overlayElement.style.left=`${t.left}px`,this.m_overlayElement.style.width=`${t.width}px`,this.m_overlayElement.style.height=`${t.height}px`}getSnapPointRadius(){const t=this.getViewer().activeView.viewDcCorners(),e=t.lowerLeft,i=t.upperRight;return i[0]-=e[0],i[1]-=e[1],Math.min(i[0],i[1])/120}start(t,e){this.createNewMeasureIfNeed();const i=this.getViewer().getSnapPoint(t,e,this.gripingRadius);i&&(this.firstPoint=i,this.previewMeasureLine.setStartPoint(this.firstPoint))}drag(t,e){this.createNewMeasureIfNeed();const i=this.getViewer().getSnapPoint(t,e,this.gripingRadius);this.isDragging?i?this.firstPoint?(this.secondPoint=i,this.previewMeasureLine.setStartPoint(this.firstPoint),this.previewMeasureLine.setEndPoint(this.secondPoint,!0)):(this.firstPoint=i,this.previewMeasureLine.setStartPoint(this.firstPoint)):(this.secondPoint=null,this.previewMeasureLine.clear(),this.previewMeasureLine.setStartPoint(this.firstPoint),this.previewMeasureLine.setEndPoint(this.getViewer().screenToWorld(t,e),!1)):i?this.previewMeasureLine.setStartPoint(i):this.previewMeasureLine.clear()}end(){if(this.firstPoint&&this.secondPoint){const t=this.createMeasureLine();t.setStartPoint(this.firstPoint),t.setEndPoint(this.secondPoint,!0)}this.firstPoint=null,this.secondPoint=null,this.previewMeasureLine.clear()}createNewMeasureIfNeed(){this.previewMeasureLine||(this.previewMeasureLine=this.createMeasureLine())}createMeasureLine(){const t=this.m_module.getViewer(),e=new E(this.m_overlayElement,t,this.m_module);e.lineThickness=this.lineThickness||e.lineThickness;const i="Default"===this.rulerUnit,s="Default"===this.rulerPrecision;if(e.setUnit(M(this.rulerUnitTable,i?t.getUnit():this.rulerUnit)),i)e.setConversionFactor(1);else{const i=this.getKUnitByName(t.getUnit()),s=this.getKUnitByName(this.subject.options.rulerUnit),r=t.getUnitsConversionCoef(i,s);this.conversionFactor=1/r,e.setConversionFactor(this.conversionFactor)}return s?e.setPrecision(2):e.setPrecision(this.rulerPrecision),this.items.push(e),e}optionsChange(t){var e,i;const s=t.data,r=null!==(e=s.rulerUnit)&&void 0!==e?e:"Default",n=null!==(i=s.rulerPrecision)&&void 0!==i?i:"Default",a=this.rulerUnit!==r,o=this.rulerPrecision!==n;if(!a&&!o)return;this.rulerUnit=r,this.rulerPrecision=n;const h=this.m_module.getViewer().getUnit(),l=this.getKUnitByName(r),d=this.getKUnitByName(h);this.items.forEach(t=>{if(a)if("Default"===r)t.setUnit(M(this.rulerUnitTable,h)),t.setConversionFactor(1);else{t.setUnit(M(this.rulerUnitTable,r));const e=this.m_module.getViewer().getUnitsConversionCoef(d,l);this.conversionFactor=1/e,t.setConversionFactor(this.conversionFactor)}o&&("Default"===n?t.setPrecision(2):t.setPrecision(n))})}getKUnitByName(t){let e=this.m_module.Units.kUserDefined;switch(t){case"Millimeters":e=this.m_module.Units.kMillimeters;break;case"Centimeters":e=this.m_module.Units.kCentimeters;break;case"Meters":e=this.m_module.Units.kMeters;break;case"Feet":e=this.m_module.Units.kFeet;break;case"Inches":e=this.m_module.Units.kInches;break;case"Yards":e=this.m_module.Units.kYards;break;case"Kilometers":e=this.m_module.Units.kKilometers;break;case"Miles":e=this.m_module.Units.kMiles;break;case"Micrometers":e=this.m_module.Units.kMicrometers;break;case"Mils":e=this.m_module.Units.kMils;break;case"MicroInches":e=this.m_module.Units.kMicroInches}return e}}class R{constructor(t,e,i,s){this.hasEventListeners=!1;const r="#35436E";this.container=e,this.container.style.touchAction="none",this.canvas=document.createElement("canvas"),this.canvas.id="odJoyStickCanvas",this.canvas.width=200,this.canvas.height=200,this.container.appendChild(this.canvas);const n=this.canvas.getContext("2d");let a=0;const o=2*Math.PI,h=(this.canvas.width-(this.canvas.width/2+10))/2,l=h+5,d=h+30,c=this.canvas.width/2,u=this.canvas.height/2;let g=c,p=u;this.onMouseDown=()=>{event.preventDefault(),a=1},this.onMouseMove=e=>{e.preventDefault(),1===a&&(g=e.pageX,p=e.pageY,this.canvas.offsetParent&&"BODY"===this.canvas.offsetParent.tagName.toUpperCase()?(g-=this.canvas.offsetLeft,p-=this.canvas.offsetTop):this.canvas.offsetParent&&(g-=this.canvas.offsetParent.offsetLeft,p-=this.canvas.offsetParent.offsetTop),n.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawExternal(),this.drawInternal(),i({x:(g-c)/l*100,y:(p-u)/l*100*-1,global:t}))},this.onMouseUp=()=>{event.preventDefault(),a=0,g=c,p=u,n.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawExternal(),this.drawInternal(),i({x:(g-c)/l*100,y:(p-u)/l*100*-1,global:t})},this.drawExternal=()=>{n.beginPath(),n.arc(c,u,d,0,o,!1),n.lineWidth=2,n.strokeStyle=r,n.globalAlpha=.5,n.stroke()},this.drawInternal=()=>{n.beginPath(),g<h&&(g=l),g+h>this.canvas.width&&(g=this.canvas.width-l),p<h&&(p=l),p+h>this.canvas.height&&(p=this.canvas.height-l),n.arc(g,p,h,0,o,!1),n.fillStyle=r,n.lineWidth=2,n.strokeStyle="#003300",n.globalAlpha=.5,n.fill(),n.stroke()};const m=()=>{this.hasEventListeners||(this.canvas.addEventListener("pointerdown",this.onMouseDown,!1),document.addEventListener("pointermove",this.onMouseMove,!1),document.addEventListener("pointerup",this.onMouseUp,!1),this.hasEventListeners=!0)},f=()=>{this.hasEventListeners&&(this.canvas.removeEventListener("pointerdown",this.onMouseDown,!1),document.removeEventListener("pointermove",this.onMouseMove,!1),document.removeEventListener("pointerup",this.onMouseUp,!1),this.hasEventListeners=!1)},_=()=>{if(s){const t=s.getBoundingClientRect();this.container.style.top=t.height-200+"px",this.container.style.left=`${t.left}px`,this.container.style.width="200px",this.container.style.height="200px"}},v=()=>{const t=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),e=window.innerWidth<1024;t||e?(this.container.style.display="block",m()):(this.container.style.display="none",f())};this.onResize=()=>{v(),setTimeout(_,500)},v(),_(),window.addEventListener("resize",this.onResize,!1),this.drawExternal(),this.drawInternal()}cleanup(){window.removeEventListener("resize",this.onResize,!1),this.hasEventListeners&&(this.canvas.removeEventListener("pointerdown",this.onMouseDown,!1),document.removeEventListener("pointermove",this.onMouseMove,!1),document.removeEventListener("pointerup",this.onMouseUp,!1),this.hasEventListeners=!1),this.canvas.remove()}}class D extends w{constructor(t){super(t),this.viewer=void 0,this.multiplier=5,this.baseSpeed=1,this.keyPressMap=new Set,this.keydown=this.keydown.bind(this),this.keyup=this.keyup.bind(this),this.lastFrameTS=0,this.lastFrameJoyStickTS=0,this.animationId=void 0,this.processMovement=this.processMovement.bind(this),this.processJoyStickMovement=this.processJoyStickMovement.bind(this),this.deltaAngle=Math.PI/3600,this.autoSelect=!0,this.isJoyStickMoving=!1,this.addJoyStickDragger()}initialize(){super.initialize(),this.viewer=this.getViewer(),window.addEventListener("keydown",this.keydown,!1),window.addEventListener("keyup",this.keyup,!1),this.oldWCSEnableValue=this.viewer.getEnableWCS(),this.viewer.setEnableWCS(!1);const t=this.viewer.activeView,e=this.getMaxDimension(t);this.baseSpeed=e/3e4,this.subject.emitEvent({type:"walkstart"}),this.viewParams=this.getViewParams(),this.setViewParams(this.viewParams);const i=this.viewer.getActiveModel();this.cameraId=i.appendCamera("Camera0"),this.setupCamera(t),i.delete(),this.cameraWalker=new this.m_module.OdTvCameraWalker,this.cameraWalker.setCamera(this.cameraId),this.subject.update(),this.enableZoomWheelPreviousValue=this.subject.options.enableZoomWheel,this.subject.options.enableZoomWheel=!1}dispose(){var t;if(this.oldWCSEnableValue=void 0!==this.oldWCSEnableValue?this.oldWCSEnableValue:this.subject.options.showWCS,this.viewer.setEnableWCS(this.oldWCSEnableValue),super.dispose(),this.keyPressMap.clear(),window.removeEventListener("keydown",this.keydown),window.removeEventListener("keyup",this.keyup),this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0),this.cameraId){const e=this.viewer.getActiveModel();e.removeEntity(this.cameraId),e.delete(),null===(t=this.cameraWalker)||void 0===t||t.delete()}if(this.viewParams){this.setViewParams(this.viewParams);this.viewer.activeView.delete()}this.subject.update(!0),this.subject.options.enableZoomWheel=this.enableZoomWheelPreviousValue,this.joyStickOverlayElement.remove(),this.joyStickDragger.cleanup()}keydown(t){switch(t.code){case"NumpadSubtract":case"Minus":this.multiplier>1&&(this.multiplier=this.multiplier-1,this.subject.emitEvent({type:"walkspeedchange",data:this.multiplier}));break;case"NumpadAdd":case"Equal":this.multiplier<10&&(this.multiplier=this.multiplier+1,this.subject.emitEvent({type:"walkspeedchange",data:this.multiplier}));break;case"KeyW":case"KeyA":case"KeyS":case"KeyD":case"KeyQ":case"KeyE":this.keyPressMap.add(t.code),this.animationId||this.processMovement(0)}}keyup(t){this.keyPressMap.delete(t.code),this.keyPressMap.size<1&&this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameTS=0)}processMovement(t){if(this.animationId=requestAnimationFrame(this.processMovement),0!==this.lastFrameTS){const e=t-this.lastFrameTS;if(e>0){const t=this.multiplier*e*this.baseSpeed;Array.from(this.keyPressMap).forEach(e=>{switch(e){case"KeyW":this.moveForward(t);break;case"KeyS":this.moveBackward(t);break;case"KeyA":this.cameraWalker.moveLeft(t);break;case"KeyD":this.cameraWalker.moveRight(t);break;case"KeyQ":this.cameraWalker.moveUp(t);break;case"KeyE":this.cameraWalker.moveDown(t)}}),this.proceedChangeCamera()}}this.lastFrameTS=t}start(t,e){this.dragPosition={x:t,y:e}}drag(t,e){if(this.cameraId&&this.isDragging){const i=t-this.dragPosition.x,s=e-this.dragPosition.y;this.dragPosition={x:t,y:e},0!==i&&this.turnLeft(-i*this.deltaAngle),0!==s&&this.cameraWalker.turnDown(s*this.deltaAngle),this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}moveForward(t){const{Vector3d:e}=this.m_module,i=this.cameraWalker.camera().openObjectAsCamera(),s=e.createFromArray(i.target()),r=e.createFromArray(i.direction()),n=e.createFromArray(i.upVector()),a=e.createFromArray(i.position());let o=e.createFromArray([r.x,r.y,0]);Math.abs(r.x)>.001&&Math.abs(r.y)>.001?o.setToProduct(o.normalize(),t):o=e.createFromArray([0,t,0]);const h=a.add(o),l=s.add(o);i.setupCamera(h.toArray(),l.toArray(),n.toArray())}moveBackward(t){this.moveForward(-t)}turnLeft(t){const e=this.cameraWalker.camera().openObjectAsCamera(),i=this.toVector(e.direction()),s=this.toVector(e.upVector()),r=e.position(),n=this.createMatrix3d();n.setToRotation(t,[0,0,1],r),i.transformBy(n),s.transformBy(n),e.setupCameraByDirection(r,i.toArray(),s.toArray()),e.delete()}setupCamera(t){const e=this.cameraId.openObjectAsCamera(),i=t.viewTarget;e.setDisplayGlyph(!1),e.setDisplayTarget(!1),e.setAutoAdjust(!0),e.setupCamera(t.viewPosition,i,t.upVector),e.setNearClip(!1,1),e.setFarClip(!1,0),e.setViewParameters(t.viewFieldWidth,t.viewFieldHeight,!0);const s=(r=t.lensLength,n=t.viewFieldWidth,a=t.viewFieldHeight,r/42*Math.sqrt(n*n+a*a));var r,n,a;const o=this.toPoint(t.viewTarget),h=this.toPoint(t.viewPosition),l=h.sub(o),d=l.asVector(),c=d.normalize(),u=this.toGeVector(c),g=[u[0]*s,u[1]*s,u[2]*s],p=this.toPoint(t.viewTarget),m=this.toPoint(g),f=p.add(m);e.setupCamera(this.toGePoint(f),t.viewTarget,t.upVector),this.deleteAll([o,h,l,d,c,p,m,f]),e.assignView(t),e.delete()}getMaxDimension(t){const[e,i,s]=t.sceneExtents.max(),[r,n,a]=t.sceneExtents.min(),o=[e-r,i-n,s-a];return Math.max(...o)}addJoyStickDragger(){this.joyStickOverlayElement=document.createElement("div"),this.joyStickOverlayElement.id="joyStickDiv",this.joyStickOverlayElement.style.background="rgba(0,0,0,0)",this.joyStickOverlayElement.style.position="fixed",this.joyStickOverlayElement.style.zIndex="0",document.body.appendChild(this.joyStickOverlayElement),this.joyStickDragger=new R(this,this.joyStickOverlayElement,t=>{Math.sqrt(t.x*t.x+t.y*t.y)>20?(this.lastJoyStickCoord={x:t.x,y:t.y},this.animationId||this.isJoyStickMoving||(this.isJoyStickMoving=!0,this.processJoyStickMovement(0))):(this.isJoyStickMoving=!1,window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameJoyStickTS=0)},this.m_module.canvas)}processJoyStickMovement(t){if(this.isJoyStickMoving){if(this.animationId=requestAnimationFrame(this.processJoyStickMovement),0!==this.lastFrameJoyStickTS){const e=t-this.lastFrameJoyStickTS;if(e>0){const t=100,i=this.lastJoyStickCoord.y/t,s=this.lastJoyStickCoord.x/t,r=this.multiplier*e*this.baseSpeed;this.moveTotal(r,i,s)}}this.lastFrameJoyStickTS=t}}moveTotal(t,e,i){0!==e&&this.moveForward(t*e),0!==i&&this.cameraWalker.moveRight(t*i),this.proceedChangeCamera()}proceedChangeCamera(){this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}class L extends w{constructor(t){super(t),this.viewer=void 0,this.multiplier=5,this.speed=1,this.keyPressMap=new Set,this.keydown=this.keydown.bind(this),this.keyup=this.keyup.bind(this),this.lastFrameTS=0,this.lastFrameJoyStickTS=0,this.animationId=void 0,this.processMovement=this.processMovement.bind(this),this.processJoyMovement=this.processJoyMovement.bind(this),this.deltaAngle=Math.PI/3600,this.autoSelect=!0,this.moving=!1,this.joyStickOverlayElement=document.createElement("div"),this.joyStickOverlayElement.id="joyStickDiv",this.joyStickOverlayElement.style.background="rgba(0,0,0,0)",this.joyStickOverlayElement.style.position="fixed",this.joyStickOverlayElement.style.zIndex="0",document.body.appendChild(this.joyStickOverlayElement),this.joyStickDragger=new R(this,this.joyStickOverlayElement,t=>{Math.sqrt(t.x*t.x+t.y*t.y)>20?(this.lastJoyStickCoord={x:t.x,y:t.y},this.animationId||this.moving||(this.moving=!0,this.processJoyMovement(0))):(this.moving=!1,window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameJoyStickTS=0)},this.m_module.canvas)}initialize(){super.initialize(),this.viewer=this.getViewer(),window.addEventListener("keydown",this.keydown,!1),window.addEventListener("keyup",this.keyup,!1),this.oldWCSEnableValue=this.viewer.getEnableWCS(),this.viewer.setEnableWCS(!1);const t=this.viewer.activeView,e=this.getMaxDimension(t);this.speed=e/3e4,this.subject.emitEvent({type:"flystart"}),this.viewParams=this.getViewParams(),this.setViewParams(this.viewParams);const i=this.viewer.getActiveModel();this.cameraId=i.appendCamera("Camera0"),this.setupCamera(t),i.delete(),this.cameraFlyer=new this.m_module.OdTvCameraWalker,this.cameraFlyer.setCamera(this.cameraId),this.subject.update(),this.enableZoomWheelPreviousValue=this.subject.options.enableZoomWheel,this.subject.options.enableZoomWheel=!1}dispose(){var t;if(this.oldWCSEnableValue=void 0!==this.oldWCSEnableValue?this.oldWCSEnableValue:this.subject.options.showWCS,this.viewer.setEnableWCS(this.oldWCSEnableValue),super.dispose(),this.keyPressMap.clear(),window.removeEventListener("keydown",this.keydown),window.removeEventListener("keyup",this.keyup),this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0),this.cameraId){const e=this.viewer.getActiveModel();e.removeEntity(this.cameraId),e.delete(),null===(t=this.cameraFlyer)||void 0===t||t.delete()}if(this.viewParams){this.setViewParams(this.viewParams);this.viewer.activeView.delete()}this.subject.update(!0),this.subject.options.enableZoomWheel=this.enableZoomWheelPreviousValue,this.joyStickOverlayElement.remove(),this.joyStickDragger.cleanup()}keydown(t){switch(t.code){case"NumpadSubtract":case"Minus":this.multiplier>1&&(this.multiplier=this.multiplier-1,this.subject.emitEvent({type:"flyspeedchange",data:this.multiplier}));break;case"NumpadAdd":case"Equal":this.multiplier<10&&(this.multiplier=this.multiplier+1,this.subject.emitEvent({type:"flyspeedchange",data:this.multiplier}));break;case"KeyW":case"KeyA":case"KeyS":case"KeyD":case"KeyQ":case"KeyE":this.keyPressMap.add(t.code),this.animationId||this.processMovement(0)}}keyup(t){this.keyPressMap.delete(t.code),this.keyPressMap.size<1&&this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameTS=0)}processMovement(t){if(this.animationId=requestAnimationFrame(this.processMovement),0!==this.lastFrameTS){const e=t-this.lastFrameTS,i=this.multiplier*e*this.speed;for(const t of this.keyPressMap)switch(t){case"KeyW":this.cameraFlyer.moveForward(i);break;case"KeyS":this.cameraFlyer.moveBackward(i);break;case"KeyA":this.cameraFlyer.moveLeft(i);break;case"KeyD":this.cameraFlyer.moveRight(i);break;case"KeyQ":this.cameraFlyer.moveUp(i);break;case"KeyE":this.cameraFlyer.moveDown(i)}this.subject.update(),this.subject.emitEvent({type:"changecamera"})}this.lastFrameTS=t}start(t,e){this.dragPosition={x:t,y:e}}drag(t,e){if(this.cameraId&&this.isDragging){const i=t-this.dragPosition.x,s=e-this.dragPosition.y;this.dragPosition={x:t,y:e},0!==i&&this.turnLeft(-i*this.deltaAngle),0!==s&&this.cameraFlyer.turnDown(s*this.deltaAngle),this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}turnLeft(t){const e=this.cameraFlyer.camera().openObjectAsCamera(),i=this.toVector(e.direction()),s=this.toVector(e.upVector()),r=e.position(),n=this.createMatrix3d();n.setToRotation(t,[0,0,1],r),i.transformBy(n),s.transformBy(n),e.setupCameraByDirection(r,i.toArray(),s.toArray()),e.delete()}setupCamera(t){const e=this.cameraId.openObjectAsCamera(),i=t.viewTarget;e.setDisplayGlyph(!1),e.setDisplayTarget(!1),e.setAutoAdjust(!0),e.setupCamera(t.viewPosition,i,t.upVector),e.setNearClip(!1,1),e.setFarClip(!1,0),e.setViewParameters(t.viewFieldWidth,t.viewFieldHeight,!0);const s=(r=t.lensLength,n=t.viewFieldWidth,a=t.viewFieldHeight,r/42*Math.sqrt(n*n+a*a));var r,n,a;const o=this.toPoint(t.viewTarget),h=this.toPoint(t.viewPosition),l=h.sub(o),d=l.asVector(),c=d.normalize(),u=this.toGeVector(c),g=[u[0]*s,u[1]*s,u[2]*s],p=this.toPoint(t.viewTarget),m=this.toPoint(g),f=p.add(m);e.setupCamera(this.toGePoint(f),t.viewTarget,t.upVector),this.deleteAll([o,h,l,d,c,p,m,f]),e.assignView(t),e.delete()}getMaxDimension(t){const[e,i,s]=t.sceneExtents.max(),[r,n,a]=t.sceneExtents.min(),o=[e-r,i-n,s-a];return Math.max(...o)}processJoyMovement(t){if(this.moving){if(this.animationId=requestAnimationFrame(this.processJoyMovement),0!==this.lastFrameJoyStickTS){const e=t-this.lastFrameJoyStickTS;if(e>0){const t=100,i=this.lastJoyStickCoord.y/t,s=this.lastJoyStickCoord.x/t,r=this.multiplier*e*this.speed;this.moveTotal(r,i,s)}}this.lastFrameJoyStickTS=t}}moveTotal(t,e,i){0!==e&&(e>0?this.cameraFlyer.moveForward(t*e):this.cameraFlyer.moveBackward(t*Math.abs(e))),0!==i&&this.cameraFlyer.moveRight(t*i),this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}class O extends w{constructor(t){super(t),this.press=!1;const e=this.getViewer().getActiveExtents(),i=e.min(),s=e.max();this.m_size_x=Math.abs(s[0]-i[0])/2,this.m_size_y=Math.abs(s[1]-i[1])/2,this.m_size_z=Math.abs(s[2]-i[2])/2,this.m_center=this.toPoint(e.center()),this.m_normal=this.createNormal();const r=this.getViewer().activeView,n=this.createPlane();n.set(this.toGePoint(this.m_center),this.m_normal),r.addCuttingPlane(n),this.index=r.numCuttingPlanes()-1;const{red:a,green:o,blue:h}=this.subject.options.cuttingPlaneFillColor;r.setEnableCuttingPlaneFill(!0,a,o,h),r.setCuttingPlaneFillPatternEnabled(!0,this.m_module.CuttingPlaneFillStyle.kHorizontalBars,0,0,0),this.m_model=this.getModel(),this.createPreview(),this.deleteAll([e,r,n])}dispose(){super.dispose(),this.m_entity&&(this.m_model.removeEntity(this.m_entity),this.deleteAll([this.m_model,this.m_entity,this.planePreview,this.m_center]),this.m_entity=null,this.planePreview=null,this.subject.update())}createNormal(){return[0,0,0]}handleDelta(t){return t}getPlanePreviewCoordinate(){return[]}start(t,e){this.press=!0,this.m_last=this.screenToWorld(t,e),this.m_click={x:t,y:e}}drag(t,e){if(this.press){const i=this.screenToWorld(t,e),s=this.handleDelta(i.sub(this.m_last)),r=this.m_center;this.m_center=r.add(s);const n=this.m_last;this.m_last=i;const a=this.getViewer().activeView,o=this.createPlane(),h=o.set(this.toGePoint(this.m_center),this.m_normal),l=a.updateCuttingPlane(this.index,o);this.drawPreview(),this.deleteAll([a,o,r,s,n,h,l]);const d=this.getViewer().getActiveDevice();d.invalidate(d.getSize())}}end(t,e){if(this.press=!1,t===this.m_click.x&&e===this.m_click.y){this.m_normal=[-1*this.m_normal[0],-1*this.m_normal[1],-1*this.m_normal[2]];const t=this.getViewer().activeView,e=this.createPlane();e.set(this.toGePoint(this.m_center),this.m_normal),t.updateCuttingPlane(this.index,e),this.deleteAll([t,e,this.m_last]);const i=this.getViewer().getActiveDevice();i.invalidate(i.getSize())}}createPreview(){this.m_entity=this.m_model.appendEntity("&CuttingPlanePreview");const t=this.m_module.GeometryTypes,e=new this.m_module.OdTvTransparencyDef,i=new this.m_module.OdTvColorDef(112,112,112);e.setValue(.9);const s=this.m_entity.openObject();s.setColor(i,t.kFaces.value),i.setColor(112,112,112),s.setColor(i,t.kEdges.value),s.setLineWeight(5),s.setTransparency(e,t.kFaces),e.setValue(1),s.setTransparency(e,t.kEdges),this.planePreview=s.appendPolygon(this.getPlanePreviewCoordinate());const r=this.planePreview.openAsPolygon();r.setFilled(!0),this.deleteAll([e,i,s,r,t]),this.subject.syncOverlay()}drawPreview(){const t=this.planePreview.openAsPolygon();t.setPoints(this.getPlanePreviewCoordinate()),this.deleteAll([t]),this.subject.syncOverlay()}}class z extends O{createNormal(){return[1,0,0]}handleDelta(t){return t.y=0,t.z=0,t}getPlanePreviewCoordinate(){return[this.m_center.x,this.m_center.y-this.m_size_y,this.m_center.z-this.m_size_z,this.m_center.x,this.m_center.y+this.m_size_y,this.m_center.z-this.m_size_z,this.m_center.x,this.m_center.y+this.m_size_y,this.m_center.z+this.m_size_z,this.m_center.x,this.m_center.y-this.m_size_y,this.m_center.z+this.m_size_z]}}class F extends O{createNormal(){return[0,1,0]}handleDelta(t){return t.x=0,t.z=0,t}getPlanePreviewCoordinate(){return[this.m_center.x-this.m_size_x,this.m_center.y,this.m_center.z-this.m_size_z,this.m_center.x+this.m_size_x,this.m_center.y,this.m_center.z-this.m_size_z,this.m_center.x+this.m_size_x,this.m_center.y,this.m_center.z+this.m_size_z,this.m_center.x-this.m_size_x,this.m_center.y,this.m_center.z+this.m_size_z]}}class G extends O{createNormal(){return[0,0,1]}handleDelta(t){return t.x=0,t.y=0,t}getPlanePreviewCoordinate(){return[this.m_center.x-this.m_size_x,this.m_center.y-this.m_size_y,this.m_center.z,this.m_center.x+this.m_size_x,this.m_center.y-this.m_size_y,this.m_center.z,this.m_center.x+this.m_size_x,this.m_center.y+this.m_size_y,this.m_center.z,this.m_center.x-this.m_size_x,this.m_center.y+this.m_size_y,this.m_center.z]}}class V{constructor(t,e,i,s){this._m_module=t,this._subject=e,this._beginInteractivity=i,this._endInteractivity=s}beginAction(t,e){this.m_viewCenter=this.getCenter(),this.m_startPoint={x:t,y:e};this.getViewer().activeView.delete(),this._beginInteractivity()}action(t,e){var i,s;const r=this.getViewer().activeView,n=r.vportRect,a=Math.max(Math.abs(n[2]-n[0]),Math.abs(n[3]-n[1])),o=(this.m_startPoint.x-t)*Math.PI/a,h=(this.m_startPoint.y-e)*Math.PI/a;this.m_startPoint.x=t,this.m_startPoint.y=e;const l=h,d=o,c={position:r.viewPosition,target:r.viewTarget,upVector:r.upVector,viewFieldWidth:r.viewFieldWidth,viewFieldHeight:r.viewFieldHeight,perspective:r.perspective};r.delete();const u=this.getSideVector(c);0!==l&&this.calculateXOrbit(c,-l,u),0!==d&&this.calculateYOrbit(c,d,u),u.delete();const g=this.getViewer().getActiveTvExtendedView();g.setView(c.position,c.target,c.upVector,c.viewFieldWidth,c.viewFieldHeight,c.perspective),g.delete(),null===(s=null===(i=this._subject.activeDragger())||void 0===i?void 0:i.updatePreview)||void 0===s||s.call(i),this._subject.emitEvent({type:"orbit"}),this._subject.emitEvent({type:"changecamera"})}endAction(){this._endInteractivity()}getSideVector(t){const e=this.toVector(t.upVector),i=this.toPoint(t.target),s=this.toPoint(t.position),r=i.sub(s),n=r.asVector();if(n.length()<1e-10){const t=this.toVector(this._m_module.Vector3d.kXAxis);return this.deleteAll([r,e,i,s,n]),t}const a=e.crossProduct(n);if(a.length()<1e-10){const t=this.toVector(this._m_module.Vector3d.kXAxis);return this.deleteAll([r,e,i,s,n,a]),t}const o=a.normalize();return this.deleteAll([r,e,i,s,n,a]),o}calculateXOrbit(t,e,i){{const s=this.toPoint(t.position),r=this.toPoint(this.m_viewCenter),n=s.rotateByBasePoint(e,i,r);t.position=n.toArray(),this.deleteAll([s,r,n])}{const s=this.toPoint(t.target),r=this.toPoint(this.m_viewCenter),n=s.rotateByBasePoint(e,i,r);t.target=n.toArray(),this.deleteAll([s,r,n])}{const e=this.toPoint(t.position),s=this.toPoint(t.target),r=s.sub(e),n=r.asVector();if(n.length()<1e-10)return void this.deleteAll([e,s,r,n]);const a=n.crossProduct(i);if(a.length()<1e-10)return void this.deleteAll([e,s,r,n,a]);const o=a.normalize();t.upVector=o.toArray(),this.deleteAll([e,s,r,n,a,o])}}calculateYOrbit(t,e,i){{const i=this.toPoint(t.position),s=this.toPoint(this.m_viewCenter),r=this.toVector(this._m_module.Vector3d.kZAxis),n=i.rotateByBasePoint(e,r,s);t.position=n.toArray(),this.deleteAll([r,i,s,n])}{const i=this.toPoint(t.target),s=this.toPoint(this.m_viewCenter),r=this.toVector(this._m_module.Vector3d.kZAxis),n=i.rotateByBasePoint(e,r,s);t.target=n.toArray(),this.deleteAll([r,i,s,n])}{const s=this.toVector(this._m_module.Vector3d.kZAxis),r=this.toPoint(t.target),n=this.toPoint(t.position),a=i.rotateBy(e,s),o=r.sub(n),h=o.asVector();if(h.length()<1e-10)return void this.deleteAll([s,r,n,a,o,h]);const l=h.crossProduct(a);if(l.length()<1e-10)return void this.deleteAll([s,r,n,a,o,h,l]);const d=l.normalize();t.upVector=d.toArray(),this.deleteAll([s,r,n,a,o,h,l,d])}}getCenter(){const t=this.getViewer();let e;const i=t.getSelected();if(i.isNull()||0===i.numItems())e=t.getActiveExtents().center();else{const t=i.getIterator();let s,r,n;for(;!t.done();t.step())r=t.getEntity(),s=r.getWCSExtents(),n?n.addExt(s):n=s;e=n.center(),n.delete(),t.delete()}return e}getViewer(){return this._m_module.getViewer()}toVector(t){return this._m_module.Vector3d.createFromArray(t)}toPoint(t){return this._m_module.Point3d.createFromArray(t)}deleteAll(t){var e;for(const i of t)null===(e=null==i?void 0:i.delete)||void 0===e||e.call(i)}}class W extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this._orbitAction=new V(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity)}start(t,e){this.press=!0,this._orbitAction.beginAction(t,e)}setDefaultViewParams(){const t=this.getViewer().getActiveTvExtendedView();t.setView(this.startCameraParams.position,this.startCameraParams.target,this.startCameraParams.upVector,this.startCameraParams.viewFieldWidth,this.startCameraParams.viewFieldHeight,this.startCameraParams.perspective),t.delete()}drag(t,e){this.press&&this._orbitAction.action(t,e)}end(){this.press=!1,this._orbitAction.endAction()}}class B{constructor(t,e,i,s,r,n){this._m_module=t,this._subject=e,this._beginInteractivity=i,this._endInteractivity=s,this._getViewParams=r,this._setViewParams=n}beginAction(t,e,i,s){this._m_start=this.screenToWorld(t,e),this._deltaScreenPosition={x:i,y:s},this._beginInteractivity()}action(t,e,i,s){var r,n;const{Vector3d:a}=this._m_module,o=this._getViewParams(),h=this.screenToWorld(t,e),l=this._m_start.sub(h).asVector(),d=a.createFromArray(o.target),c=d.add(l);o.target=c.toArray();const u=a.createFromArray(o.position),g=u.add(l);o.position=g.toArray(),this._setViewParams(o),d.delete(),c.delete(),u.delete(),g.delete(),null===(n=null===(r=this._subject.activeDragger())||void 0===r?void 0:r.updatePreview)||void 0===n||n.call(r),this._subject.emitEvent({type:"pan",x:i,y:s,dX:i-this._deltaScreenPosition.x,dY:s-this._deltaScreenPosition.y}),this._subject.emitEvent({type:"changecamera"}),this._deltaScreenPosition={x:i,y:s}}endAction(){this._endInteractivity()}screenToWorld(t,e){return this._m_module.Point3d.createFromArray(this._m_module.getViewer().screenToWorld(t,e))}}class N extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this._panAction=new B(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity,this.getViewParams,this.setViewParams)}start(t,e,i,s){this.press=!0,this._panAction.beginAction(t,e,i,s)}drag(t,e,i,s){this.press&&this._panAction.action(t,e,i,s)}end(t,e){this.press=!1,this._panAction.endAction()}}class j{constructor(t,e){this._m_module=t,this._subject=e}action(t,e,i,s,r){var n,a;this._m_module.getViewer().zoomAt(i,t,e),this._subject.deviceAutoRegeneration(),null===(a=null===(n=this._subject.activeDragger())||void 0===n?void 0:n.updatePreview)||void 0===a||a.call(n),this._subject.emitEvent({type:"zoomat",data:i,x:s,y:r}),this._subject.emitEvent({type:"changecamera"})}}class H extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this._zoomAction=new j(this.m_module,this.subject)}start(t,e,i=0,s=0){this.press=!0,this.pressX=t,this.pressY=e,this.absoluteX=i,this.absoluteY=s,this.prevY=e,this.beginInteractivity()}drag(t,e){const i=e-this.prevY;if(this.prevY=e,this.press&&Math.abs(i)>=1e-5){const t=.975,e=i>0?1/t:t;this._zoomAction.action(this.pressX,this.pressY,e,this.absoluteX,this.absoluteY)}}end(){this.press=!1,this.endInteractivity()}}class U extends w{constructor(t){super(t),this.canvasEvents=["wheel"],this._zoomAction=new j(this.m_module,this.subject),this._endInteractivityTimeOutId=void 0,this._isEnableInteractivityMode=!1}wheel(t){if(!this.subject.options.enableZoomWheel)return;(t=t||window.event).preventDefault();const e=this.subject.options.reverseZoomWheel?.925:1/.925,i=this.subject.options.reverseZoomWheel?1/.925:.925;if(this.getViewer()){const s=t.deltaY>0?e:i;this._zoomAction.action(t.offsetX*window.devicePixelRatio,t.offsetY*window.devicePixelRatio,s,t.offsetX,t.offsetY),this._isEnableInteractivityMode||(this._isEnableInteractivityMode=!0,this.beginInteractivity()),this._endInteractivityTimeOutId&&clearTimeout(this._endInteractivityTimeOutId),this._isEnableInteractivityMode||(this._isEnableInteractivityMode=!0,this.beginInteractivity()),this._endInteractivityTimeOutId&&clearTimeout(this._endInteractivityTimeOutId),this.subject.update(!0),this._endInteractivityTimeOutId=setTimeout(()=>{this._endInteractivityTimeOutId=void 0,this.endInteractivity(),this._isEnableInteractivityMode=!1},100)}}dispose(){this._endInteractivityTimeOutId&&(clearTimeout(this._endInteractivityTimeOutId),this.endInteractivity(),this._isEnableInteractivityMode=!1)}}class X{constructor(){this.m_start=[0,0,0],this.m_end=[0,0,0],this.m_model=null}createPoint3d(){return new this.m_module.Point3d}init(t,e){this.m_module=t,this.m_model=e}getViewer(){return this.m_module.getViewer()}setValue(t){this.m_end=t,this.draw()}setStartPoint(t){this.m_start=t,this.m_end=t,this.draw()}toDoubleArray(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x),e.push(t[i].y),e.push(t[i].z);return e}draw(){const t=this.getViewer().activeView,e=t.viewingMatrix,i=[];i.push(this.m_start),i.push(this.createPoint3d()),i.push(this.m_end),i.push(this.createPoint3d());const s=this.createPoint3d();s.set(this.m_start[0],this.m_start[1],this.m_start[2]);const r=this.createPoint3d();r.set(this.m_end[0],this.m_end[1],this.m_end[2]),s.transformBy(e),r.transformBy(e),i[1].x=s.x,i[3].x=r.x,i[1].y=r.y,i[3].y=s.y,i[1].z=i[3].z=r.z;const n=t.eyeToWorldMatrix;if(i[1].transformBy(n),i[3].transformBy(n),this.m_entity)this.m_frame.openAsPolygon().setPoints(this.toDoubleArray(i));else{this.m_entity=this.m_model.appendEntity("");const t=this.m_entity.openObject();t.setColor(112,112,112),t.setLineWeight(2),this.m_frame=t.appendPolygon(this.toDoubleArray(i)),t.delete()}}clear(){this.m_entity&&(this.m_model.removeEntity(this.m_entity),this.m_entity=null)}}class Y extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this.needInputText=!1,this.m_frame=new X,this.m_frame.init(this.m_module,this.getModel())}start(t,e){this.press=!0,this.m_minX=t,this.m_minY=e;const i=this.screenToWorld(t,e);this.m_frame.setStartPoint(i)}drag(t,e){if(this.press){this.m_maxX=t,this.m_maxY=e;const i=this.screenToWorld(t,e);this.m_frame.setValue(i)}}end(t,e){this.press=!1,this.m_maxX=t,this.m_maxY=e,this.m_minX!==this.m_maxX&&this.m_minY!==this.m_maxY&&(this.m_frame.clear(),this.getViewer().zoomWindow(this.m_minX,this.m_minY,this.m_maxX,this.m_maxY))}}class J extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this.maxPolarAngle=Math.PI/2,this.minPolarAngle=0}start(t,e){this.press=!0,this.m_viewCenter=this.getCenter(),this.m_startPoint={x:t,y:e};const i=this.getViewer().activeView;this.startCameraParams=this.getViewParams();const s=i.vportRect;this.m_delta=Math.max(s[1]-s[0],s[2]-s[3]),this.beginInteractivity()}setDefaultViewParams(){this.setViewParams(this.startCameraParams)}drag(t,e){if(this.press){let i=t-this.m_startPoint.x,s=e-this.m_startPoint.y;i*=Math.PI/this.m_delta,s*=Math.PI/this.m_delta,this.setDefaultViewParams();const{Vector3d:r,Matrix3d:n}=this.m_module,a=r.createFromArray(this.startCameraParams.target),o=r.createFromArray(this.startCameraParams.position).sub(a),h=o.normalize(),l=new n;l.setToIdentity();const d=new n;d.setToIdentity();const c=r.createFromArray([h.x,h.y,h.z]),u=r.createFromArray(this.startCameraParams.upVector),g=c.crossProduct(u);let p=r.createFromArray([c.x,c.y,0]);p.length()<=1e-5?p.set(-g.y,g.x,0):p=p.normalize();i-=Math.sign(p.dotProduct(r.createFromArray([-1,0,0])))*p.angleTo(r.createFromArray([0,1,0]));let m=r.createFromArray([h.x,h.y,0]),f=0;m.length()<=1e-5?f=-h.z*Math.PI/2:(m=m.normalize(),f=-m.angleTo(h)),s-=f,l.setToRotation(-i,[0,0,1],[0,0,0]);const _=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,s));d.setToRotation(_,[1,0,0],[0,0,0]);const v=l.postMultBy(d);let y=r.createFromArray([0,1,0]).transformBy(v);const w=r.createFromArray([0,0,1]).transformBy(v);y.setLength(o.length()),y=a.add(y);const x=this.getViewParams();x.position=y.toArray(),x.upVector=w.toArray(),this.setViewParams(x)}}end(){this.press=!1,this.endInteractivity()}getCenter(){const t=this.getViewer();let e=t.getActiveExtents();const i=t.getSelected();if(!i.isNull()&&0!==i.numItems()){const t=i.getIterator(),s=t.getEntity();if(1===s.getType()){const t=s.openObject();e.delete(),e=t.getExtents(),t.delete()}else if(2===s.getType()){const t=s.openObjectAsInsert(),i=t.getExtents();e.delete(),e=i.ext,i.delete(),t.delete()}t.delete()}const s=e.center();return e.delete(),s}}const q=a("visualizejs");q.registerDragger("Pan",t=>new N(t)),q.registerDragger("Orbit",t=>new W(t)),q.registerDragger("Zoom",t=>new H(t)),q.registerDragger("ZoomWindow",t=>new Y(t)),q.registerDragger("ZoomWheel",t=>new U(t)),q.registerDragger("OrbitAroundBuilding",t=>new J(t)),q.registerDragger("MeasureLine",t=>new I(t)),q.registerDragger("CuttingPlaneXAxis",t=>new z(t)),q.registerDragger("CuttingPlaneYAxis",t=>new F(t)),q.registerDragger("CuttingPlaneZAxis",t=>new G(t)),q.registerDragger("Walk",t=>new D(t)),q.registerDragger("Fly",t=>new L(t));const K=(t,e,i)=>{const{translate:s,scale:r,rotation:n}=t,a=new i.Matrix3d;a.setTranslation([s.x,s.y,s.z]);const o=new i.Matrix3d;o.setToRotation(n.angle,[n.x,n.y,n.z],e);const h=new i.Matrix3d;return h.setToScaling(r,e),o.postMultBy(a).postMultBy(h)};function Z(t,e=0){if(!t.visualizeJs)return;t.visViewer().explode(e),t.update(),t.emitEvent({type:"explode",data:e})}function $(t,e=""){if(!t.visualizeJs)return;const i=t.visLib(),s=t.visViewer(),r=i.DefaultViewPosition;s.setDefaultViewPositionWithAnimation(r[e]),t.update(),t.emit({type:"viewposition",data:e})}function Q(t){return"$"===t.getName()[0]}const tt=s("visualizejs");tt.registerCommand("applyModelTransform",function(t,e){var i;if(!t.visualizeJs)return;if(!e.getModelTransformMatrix)return;const s=t.visLib(),r=t.visViewer(),n=r.getModelIterator();for(;!n.done();n.step()){const t=n.getModel(),i=e.getModelTransformMatrix(t.getDatabaseHandle());if(i){const e=t.getExtents();e.transformBy(t.getUnitsMatrix());const r=K(i,e.center(),s);t.setModelingMatrix(r,!0)}}n.delete(),null===(i=r.clearViewExtentsCache)||void 0===i||i.call(r),t.update()}),tt.registerCommand("clearMarkup",function(t){t.clearOverlay()}),tt.registerCommand("clearSelected",function(t){if(!t.visualizeJs)return;t.visViewer().unselect(),t.update(),t.emitEvent({type:"select",handles:[]}),t.emitEvent({type:"select2",handles:[]})}),tt.registerCommand("clearSlices",function(t){t.clearSlices()}),tt.registerCommand("createPreview",function(t,e="image/jpeg",i=.25){var s;return t.visualizeJs&&(null===(s=t.canvas)||void 0===s?void 0:s.toDataURL(e,i))||""}),tt.registerCommand("explode",Z),tt.registerCommand("collect",function(t){Z(t,0)}),tt.registerCommand("getDefaultViewPositions",function(t){if(!t.visualizeJs)return[];const e=t.visLib().DefaultViewPosition;return Object.keys(e).filter(t=>"values"!==t)}),tt.registerCommand("getModels",function(t){if(!t.visualizeJs)return[];const e=[],i=t.visViewer().getModelIterator();for(;!i.done();i.step()){const t=i.getModel();"$"!==t.getName()[0]&&e.push(t.getDatabaseHandle())}return i.delete(),e}),tt.registerCommand("getSelected",function(t){if(!t.visualizeJs)return[];const e=[],i=t.visViewer().getSelected();if(!i.isNull()&&0!==i.numItems()){const t=i.getIterator();for(;!t.done();t.step()){const i=t.getEntity(),s=1===i.getType()?i.openObject():2===i.getType()?i.openObjectAsInsert():null;if(s){const t=s.getNativeDatabaseHandle();"-1"!==t&&e.push(t),s.delete()}}t.delete()}return e}),tt.registerCommand("getSelected2",function(t){const e=t.executeCommand("getSelected"),i=t.models[0];return e.map(t=>`${i.id}:${t}`)}),tt.registerCommand("hideSelected",function(t){if(!t.visualizeJs)return;t.visViewer().hideSelectedObjects(!1),t.update(),t.emitEvent({type:"hide"}),t.emitEvent({type:"select",handles:[]}),t.emitEvent({type:"select2",handles:[]})}),tt.registerCommand("isolateSelected",function(t){if(!t.visualizeJs)return;t.visViewer().isolateSelectedObjects(!1),t.update(),t.emitEvent({type:"isolate"})}),tt.registerCommand("regenerateAll",function(t){if(!t.visualizeJs)return;t.visViewer().regenAll(),t.update(),t.emit({type:"regenerateall"})}),tt.registerCommand("resetView",function(t){if(!t.visualizeJs)return;const e=t.getComponent("ResetComponent");t.executeCommand("setActiveDragger"),t.executeCommand("clearSlices"),t.executeCommand("clearOverlay"),t.executeCommand("setMarkupColor"),t.executeCommand("clearSelected"),t.executeCommand("showAll"),t.executeCommand("explode",0),t.executeCommand("zoomToExtents",!0),e.resetCameraPosition(),t.emit({type:"resetview"})}),tt.registerCommand("selectModel",function(t,e){if(!t.visualizeJs)return;const i=t.visViewer(),s=i.activeView,r=i.getModelIterator();for(;!r.done();r.step()){const n=r.getModel();if(n.getDatabaseHandle()===e){const e=s.selectCrossing([0,9999,9999,0],n);i.setSelected(e),t.update(),t.emitEvent({type:"select",handles:t.getSelected()}),t.emitEvent({type:"select2",handles:t.getSelected2()}),e.delete();break}}r.delete()}),tt.registerCommand("setActiveDragger",function(t,e=""){t.setActiveDragger(e)}),tt.registerCommand("setDefaultViewPosition",$),tt.registerCommand("setMarkupColor",function(t,e=255,i=0,s=0){t.markup.setMarkupColor(e,i,s)}),tt.registerCommand("setSelected",function(t,e=[]){if(!t.visualizeJs)return;const i=e.map(t=>t.slice(t.indexOf(":")+1)),s=t.visLib(),r=t.visViewer(),n=new s.OdTvSelectionSet;i.forEach(t=>{const e=r.getEntityByOriginalHandle(t+"");e.isNull()||n.appendEntity(e)}),r.setSelected(n),t.update(),t.emitEvent({type:"select",data:n,handles:i}),t.emitEvent({type:"select2",data:n,handles:e}),n.delete()}),tt.registerCommand("setSelected2",function(t,e=[]){const i=[];return e.forEach(e=>{e.includes(":")?t.models.forEach(t=>{e.split(":",1)[0]===t.id+""&&i.push(e)}):i.push(e)}),t.executeCommand("setSelected",i)}),tt.registerCommand("showAll",function(t){if(!t.visualizeJs)return;t.visViewer().unisolateSelectedObjects(!1),t.update(),t.emitEvent({type:"showall"})}),tt.registerCommand("zoomToExtents",function(t,e=!1,i=t.options.cameraAnimation){if(!t.visualizeJs)return;const s=t.visViewer(),r=s.getEnableAnimation();s.setEnableAnimation(i),s.zoomExtents(e),s.update(),s.setEnableAnimation(r),t.deviceAutoRegeneration(),t.update(),t.emitEvent({type:"zoom"})}),tt.registerCommand("zoomToObjects",function(t,e=[]){var i;if(!t.visualizeJs)return;const s=t.visLib(),r=t.visViewer(),n=new s.OdTvSelectionSet;e.forEach(t=>{const e=r.getEntityByOriginalHandle(t+"");e.isNull()||n.appendEntity(e)}),null===(i=r.zoomToObjects)||void 0===i||i.call(r,n),t.deviceAutoRegeneration(),t.update(),t.emitEvent({type:"zoom"}),n.delete()}),tt.registerCommand("zoomToSelected",function(t){var e;if(!t.visualizeJs)return;const i=t.visViewer(),s=i.getSelected();null===(e=i.zoomToObjects)||void 0===e||e.call(i,s),t.deviceAutoRegeneration(),t.update(),t.emitEvent({type:"zoom"})}),tt.registerCommand("autoTransformAllModelsToCentralPoint",async function(t,e){var i;if(!t.visualizeJs)return;if(!e.getModelTransformMatrix)return;const s=t.visLib(),r=t.visViewer(),n=r.getActiveExtents().center(),a=r.getModelIterator();for(;!a.done();a.step()){const t=a.getModel();if(!Q(t)){const i=t.getExtents(),r=t.getUnitsMatrix();i.transformBy(t.getUnitsMatrix());const a=t.getUnitsMatrix().invert(),o=i.center(),h=1,l=new s.Matrix3d,d=new s.Matrix3d;d.setTranslation([n[0]-o[0],n[1]-o[1],n[2]-o[2]]),l.setToScaling(h,n);const c=a.postMultBy(l).postMultBy(d).postMultBy(r),u=c.scale(),g={translate:{x:c.get(0,3)-(1-u)*o[0],y:c.get(1,3)-(1-u)*o[1],z:c.get(2,3)-(1-u)*o[2]},rotation:{x:0,y:0,z:1,angle:0},scale:u},p=K(g,o,s);t.setModelingMatrix(p,!0),n[0]+=Math.abs(i.max()[0]-i.min()[0])*u,await e.setModelTransformMatrix(t.getDatabaseHandle(),g)}t.delete()}a.delete(),null===(i=r.clearViewExtentsCache)||void 0===i||i.call(r),t.update()}),tt.registerCommand("k3DViewTop",t=>$(t,"k3DViewTop")),tt.registerCommand("k3DViewBottom",t=>$(t,"k3DViewBottom")),tt.registerCommand("k3DViewLeft",t=>$(t,"k3DViewLeft")),tt.registerCommand("k3DViewRight",t=>$(t,"k3DViewRight")),tt.registerCommand("k3DViewFront",t=>$(t,"k3DViewFront")),tt.registerCommand("k3DViewBack",t=>$(t,"k3DViewBack")),tt.registerCommand("k3DViewSE",t=>$(t,"k3DViewSE")),tt.registerCommand("k3DViewSW",t=>$(t,"k3DViewSW")),tt.registerCommand("k3DViewNE",t=>$(t,"k3DViewNE")),tt.registerCommand("k3DViewNW",t=>$(t,"k3DViewNW")),tt.registerCommandAlias("clearMarkup","clearOverlay"),tt.registerCommandAlias("clearSelected","unselect"),tt.registerCommandAlias("zoomToExtents","zoomExtents");class et{constructor(t){this.optionsChange=()=>{this.switchCameraMode(this.viewer.options.cameraMode)},this.geometryEnd=()=>{const t=this.viewer.visViewer().activeView,e=this.getCameraMode(t);this.viewer.options.cameraMode=e,this.viewer.emitEvent({type:"changecameramode",mode:e}),t.delete()},this.viewer=t,this.viewer.addEventListener("databasechunk",this.geometryEnd),this.viewer.addEventListener("clear",this.geometryEnd),this.viewer.addEventListener("optionschange",this.optionsChange),this.viewer.addEventListener("initialize",this.optionsChange)}dispose(){this.viewer.removeEventListener("databasechunk",this.geometryEnd),this.viewer.removeEventListener("clear",this.geometryEnd),this.viewer.removeEventListener("optionschange",this.optionsChange),this.viewer.removeEventListener("initialize",this.optionsChange)}getCameraMode(t){return t.perspective?"perspective":"orthographic"}switchCameraMode(t){if(!t)return;const e=this.viewer.visViewer().activeView;t!==this.getCameraMode(e)&&(e.perspective=!e.perspective,this.viewer.update(),this.viewer.emitEvent({type:"changecameramode",mode:t})),e.delete()}}class it{constructor(t){this.animate=(t=0)=>{this.requestId=requestAnimationFrame(this.animate),this.viewer.render(t),this.viewer.emitEvent({type:"animate",time:t})},this.viewer=t,this.animate()}dispose(){cancelAnimationFrame(this.requestId)}}class st{constructor(t){this.resizeViewer=t=>{const{width:e,height:i}=t[0].contentRect;e&&i&&this.viewer.setSize(e,i)},this.viewer=t,this.resizeObserver=new ResizeObserver(this.resizeViewer),this.resizeObserver.observe(t.canvas.parentElement)}dispose(){this.resizeObserver.disconnect()}}class rt{constructor(t){this.viewer=t,this.zoomWheelDragger=new U(t),this.zoomWheelDragger.name="ZoomWheel",this.zoomWheelDragger.initialize()}dispose(){this.zoomWheelDragger.dispose(),this.zoomWheelDragger=void 0}}var nt;!function(t){t[t.None=0]="None",t[t.Orbit=1]="Orbit",t[t.Pan=2]="Pan",t[t.Zoom=3]="Zoom"}(nt||(nt={}));class at extends w{get isSingleTouchEnabled(){return this._isSingleTouchEnabled}set isSingleTouchEnabled(t){this._isSingleTouchEnabled=t}constructor(t){super(t),this._previousEvents=new Map,this._currentEvents=new Map,this._lastGestureAction=nt.None,this._maxInitialDistanceDifference=30*window.devicePixelRatio,this._isSingleTouchEnabled=!1,this._orbitAction=new V(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity),this._panAction=new B(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity,this.getViewParams,this.setViewParams),this._zoomAction=new j(this.m_module,this.subject)}getMiddlePoint(t){if(2!==t.size)return;const e=this.getKeys(t),i=this.relativeCoords(t.get(e[0])),s=this.relativeCoords(t.get(e[1]));return{x:Math.floor((i.x+s.x)/2),y:Math.floor((i.y+s.y)/2)}}getFirstPoint(t){if(t.size<1)return;const e=this.getKeys(t);return this.relativeCoords(t.get(e[0]))}getDistance(t){if(2!==t.size)return-1;const e=this.getKeys(t),i=this.relativeCoords(t.get(e[0])),s=this.relativeCoords(t.get(e[1]));return Math.hypot(i.x-s.x,i.y-s.y)}updateEvent(t){const e=!this._currentEvents.get(t.pointerId);if(e&&2===this._currentEvents.size)return;const i=this._currentEvents.get(t.pointerId);i&&this._previousEvents.set(i.pointerId,i),this._currentEvents.set(t.pointerId,t),e&&(this._initialDistance=this.getDistance(this._currentEvents))}removeEvent(t){this._currentEvents.delete(t.pointerId),this._previousEvents.delete(t.pointerId),this._currentEvents.size<2&&(this._initialDistance=-1)}getKeys(t){return Array.from(t.keys())}analyzeGesture(){if(2===this._currentEvents.size){const t=this.getDistance(this._currentEvents),e=this.getDistance(this._previousEvents);Math.abs(this._initialDistance-t)<=this._maxInitialDistanceDifference?this.executePanAction(this.getMiddlePoint(this._currentEvents)):-1!==e&&t!==e&&this.executeZoomAction(t,e)}else 1===this._currentEvents.size&&this.isSingleTouchEnabled&&this.executeOrbitAction(this.getFirstPoint(this._currentEvents))}executeZoomAction(t,e){this._lastGestureAction!==nt.Zoom&&(this.executeEndAction(this._lastGestureAction),this._lastGestureAction=nt.Zoom,w.isGestureActive=!0);const i=1+(t-e)/700,s=this.getMiddlePoint(this._currentEvents);this._zoomAction.action(s.x,s.y,i,s.x,s.y),this.subject.update()}executePanAction(t){this._lastGestureAction!==nt.Pan&&(this.executeEndAction(this._lastGestureAction),this._lastGestureAction=nt.Pan,w.isGestureActive=!0,this._panAction.beginAction(t.x,t.y,t.x,t.y)),this._panAction.action(t.x,t.y,t.x,t.y),this.subject.update()}executeOrbitAction(t){this._lastGestureAction!==nt.Orbit&&(this.executeEndAction(this._lastGestureAction),this._lastGestureAction=nt.Orbit,w.isGestureActive=!0,this._orbitAction.beginAction(t.x,t.y)),this._orbitAction.action(t.x,t.y),this.subject.update()}executeEndAction(t){t===nt.Orbit&&this._orbitAction.endAction(),t===nt.Pan&&this._panAction.endAction(),w.isGestureActive=!1}needIgnoreEvent(t){return!this.subject.options.enableZoomWheel||!this.subject.options.enableGestures||!this.eventIsTouchEvent(t)}eventIsTouchEvent(t){return"touch"===t.pointerType||""===t.pointerType}pointerdown(t){this.needIgnoreEvent(t)||this.updateEvent(t)}pointermove(t){this.needIgnoreEvent(t)||(this.updateEvent(t),this.analyzeGesture())}pointerup(t){this.needIgnoreEvent(t)||(this.removeEvent(t),this._currentEvents.size<2&&(this.executeEndAction(this._lastGestureAction),w.isGestureActive=!1),this._lastGestureAction=nt.None)}pointercancel(t){this.needIgnoreEvent(t)||this.pointerup(t)}pointerleave(t){this.needIgnoreEvent(t)||this.pointerup(t)}}class ot{constructor(t){this.viewer=t,this.gestureManager=new at(t),this.gestureManager.initialize()}dispose(){this.gestureManager.dispose(),this.gestureManager=void 0}}class ht{constructor(t){this.savedCameraSettings=null,this.onDatabaseChunk=()=>{this.viewer.visualizeJs&&(this.savedCameraSettings=this.getOrthogonalCameraSettings())},this.viewer=t,this.viewer.addEventListener("databasechunk",this.onDatabaseChunk)}dispose(){this.viewer.removeEventListener("databasechunk",this.onDatabaseChunk)}resetCameraPosition(){this.savedCameraSettings&&this.viewer.visualizeJs&&this.setOrthogonalCameraSettings(this.savedCameraSettings)}getOrthogonalCameraSettings(){const t=this.viewer.visViewer().activeView;return{view_point:this.getPoint3dFromArray(t.viewPosition),direction:this.getPoint3dFromArray(t.viewTarget),up_vector:this.getPoint3dFromArray(t.upVector),field_width:t.viewFieldWidth,field_height:t.viewFieldHeight,view_to_world_scale:1}}setOrthogonalCameraSettings(t){const e=this.viewer.visViewer().activeView;t&&e.setView(this.getLogicalPoint3dAsArray(t.view_point),this.getLogicalPoint3dAsArray(t.direction),this.getLogicalPoint3dAsArray(t.up_vector),t.field_width,t.field_height,!0)}getPoint3dFromArray(t){return{x:t[0],y:t[1],z:t[2]}}getLogicalPoint3dAsArray(t){return[t.x,t.y,t.z]}}const lt=l("visualizejs");lt.registerComponent("CameraComponent",t=>new et(t)),lt.registerComponent("ResizeCanvasComponent",t=>new st(t)),lt.registerComponent("RenderLoopComponent",t=>new it(t)),lt.registerComponent("ZoomWheelComponent",t=>new rt(t)),lt.registerComponent("GestureManagerComponent",t=>new ot(t)),lt.registerComponent("ResetComponent",t=>new ht(t));class dt{dispose(){}}class ct{constructor(){this.requestHeader={},this.withCredentials=!1,this.abortSignal=void 0}setRequestHeader(t){this.requestHeader=t}setWithCredentials(t){this.withCredentials=t}setAbortSignal(t){this.abortSignal=t}load(t,e){if("string"==typeof t){const i=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:this.abortSignal});return fetch(i).then(t=>{if(!t.ok)throw new Error(`Failed to fetch "${t.url}", status ${t.status}`);const i=t.headers.get("X-File-Size")||t.headers.get("Content-Length"),s=parseInt(i||"",10)||0,r=s>0,n=new ReadableStream({async start(i){const n=t.body.getReader();let a=0;try{for(;;){const{done:t,value:o}=await n.read();if(t)break;e&&(a+=o.byteLength,e(new ProgressEvent("progress",{lengthComputable:r,loaded:a,total:s}))),i.enqueue(o)}i.close()}catch(t){i.error(t)}}});return new Response(n)}).then(t=>t.arrayBuffer())}if(t instanceof globalThis.File)return new Promise((i,s)=>{const r=new FileReader;r.onload=()=>i(r.result),r.onerror=()=>s(r.error),r.onprogress=e,r.readAsArrayBuffer(new Blob([t]))});if(e){const i=t.byteLength;e(new ProgressEvent("progress",{lengthComputable:i>0,loaded:i,total:i}))}return Promise.resolve(t)}}class ut extends d{constructor(t){super(),this.viewer=t}isSupport(t,e){return("string"==typeof t||t instanceof globalThis.File||t instanceof ArrayBuffer)&&/vsf$/i.test(e)}async load(t,e,i={}){if(!this.viewer.visualizeJs)return this;const s=this.viewer.visViewer(),r=new ct;r.setRequestHeader(i.requestHeader),r.setWithCredentials(i.withCredentials),r.setAbortSignal(this.abortController.signal);const n=await r.load(t,e=>{const{lengthComputable:i,loaded:s,total:r}=e,n=i?s/r:1;this.viewer.emitEvent({type:"geometryprogress",data:n,file:t})}),a=new Uint8Array(n);if(!this.viewer.visualizeJs)return this;try{s.parseFile(a)}catch(t){throw console.error("VSF parse error.",t),t}const o=new dt;return o.id=i.modelId||this.extractFileName(t),this.viewer.models.push(o),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:a,file:t}),this}}class gt extends d{constructor(t){super(),this.viewer=t}isSupport(t,e){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&/.data$/i.test(t.database)}async load(t,e){if(!this.viewer.visualizeJs)return this;const i=this.viewer.visViewer(),s=[t.database,...t.geometry];console.time("File load time");for(let e=0;e<s.length;e++){const r=s[e],n=i=>{const r=(e+i)/s.length;this.viewer.emitEvent({type:"geometryprogress",data:r,file:t.file,model:t})},a=await t.downloadResource(r,n,this.abortController.signal),o=new Uint8Array(a);if(!this.viewer.visualizeJs)return this;try{i.parseStream(o)}catch(t){throw console.error("VSF parse error.",t),t}if(0===e){const e=new dt;e.id=t.file.id,this.viewer.models.push(e),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:o,file:t.file,model:t})}else this.viewer.update(),this.viewer.emitEvent({type:"geometrychunk",data:o,file:t.file,model:t})}return console.timeEnd("File load time"),this}}class pt extends d{constructor(t){super(),this.viewer=t}isSupport(t,e){return("string"==typeof t||t instanceof globalThis.File||t instanceof ArrayBuffer)&&/vsfx$/i.test(e)}async load(t,e,i={}){if(!this.viewer.visualizeJs)return this;const s=this.viewer.visViewer(),r=new ct;r.setRequestHeader(i.requestHeader),r.setWithCredentials(i.withCredentials),r.setAbortSignal(this.abortController.signal);const n=await r.load(t,e=>{const{lengthComputable:i,loaded:s,total:r}=e,n=i?s/r:1;this.viewer.emitEvent({type:"geometryprogress",data:n,file:t})}),a=new Uint8Array(n);if(!this.viewer.visualizeJs)return this;try{s.parseVsfx(a)}catch(t){throw console.error("VSFX parse error.",t),t}const o=new dt;return o.id=i.modelId||this.extractFileName(t),this.viewer.models.push(o),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:a,file:t}),this}}class mt extends d{constructor(t){super(),this.viewer=t}isSupport(t){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&/.vsfx$/i.test(t.database)&&!1===this.viewer.options.enableStreamingMode}async load(t){if(!this.viewer.visualizeJs)return Promise.resolve(this);const e=this.viewer.visViewer();console.time("File load time");const i=await t.downloadResource(t.database,e=>{this.viewer.emitEvent({type:"geometryprogress",data:e,file:t.file,model:t})},this.abortController.signal),s=new Uint8Array(i);if(!this.viewer.visualizeJs)return this;try{e.parseVsfx(s)}catch(t){throw console.error("VSFX parse error.",t),t}const r=new dt;return r.id=t.file.id,this.viewer.models.push(r),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:s,file:t.file,model:t}),console.timeEnd("File load time"),this}}var ft;!function(t){t[t.kDelay=0]="kDelay",t[t.kNormal=1]="kNormal",t[t.kForce=2]="kForce"}(ft||(ft={}));class _t{constructor(){this.lastUpdate=0,this.delayUpdateTime=1e3}initialize(t){this.viewer=t,this.lastUpdate=performance.now()}update(t){const e=t!==ft.kDelay||performance.now()-this.lastUpdate>=this.delayUpdateTime,i=t===ft.kForce;e&&(this.viewer.update(i),this.lastUpdate=performance.now(),this.delayUpdateTime*=2)}}class vt extends d{constructor(t){super(),this.viewer=t}isSupport(t){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&/.vsfx$/i.test(t.database)&&!0===this.viewer.options.enableStreamingMode&&!1===this.viewer.options.enablePartialMode&&!/.rcs$/i.test(t.name)}async load(t){if(!this.viewer.visualizeJs)return this;const e=this.viewer.visLib(),i=this.viewer.visViewer(),s=new _t;s.initialize(this.viewer);let r=!1;return console.time("File load time"),await t.downloadResource(t.database,(n,a)=>{if(!this.viewer.visualizeJs)return;let o;try{o=i.parseVsfx(a)}catch(t){throw console.error("VSFX parse error.",t),t}this.viewer.emitEvent({type:"geometryprogress",data:n,file:t.file,model:t});let h=!1;if((o===e.DatabaseStreamStatus.ReadyServiceData||o===e.DatabaseStreamStatus.Complete&&!r)&&(r=!0,h=!0),h){const e=new dt;e.id=t.file.id,this.viewer.models.push(e),this.viewer.syncOptions(),this.viewer.syncOverlay(),s.update(ft.kForce),this.viewer.emitEvent({type:"databasechunk",data:a,file:t.file,model:t})}else s.update(ft.kDelay),this.viewer.emitEvent({type:"geometrychunk",data:a,file:t.file,model:t})},this.abortController.signal),s.update(ft.kNormal),console.timeEnd("File load time"),Promise.resolve(this)}}class yt extends d{constructor(t){super(),this.viewer=t,this.abortControllerForRequestMap=new Map}isSupport(t){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&"function"==typeof t.downloadResourceRange&&/.vsfx$/i.test(t.database)&&(!0===this.viewer.options.enablePartialMode||/.rcs$/i.test(t.name))}async load(t){if(!this.viewer.visualizeJs)return this;const e=this.viewer.visViewer();let i=!1;const s=new Map;let r=0;const n=()=>clearTimeout(r),a=new AbortController;this.abortControllerForRequestMap.set(0,a);const o=new _t;o.initialize(this.viewer),e.memoryLimit=this.viewer.options.memoryLimit;const h=(i,s,r=0)=>{if(!this.viewer.visualizeJs)return;let n;try{n=e.parseVsfxInPartialMode(r,s)}catch(t){throw console.error("VSFX parse error.",t),t}if(this.viewer.emitEvent({type:"geometryprogress",data:i,file:t.file,model:t}),n){const e=new dt;e.id=t.file.id,this.viewer.models.push(e),this.viewer.syncOptions(),this.viewer.syncOverlay(),o.update(ft.kForce),this.viewer.emitEvent({type:"databasechunk",data:s,file:t.file,model:t})}else o.update(ft.kDelay),this.viewer.emitEvent({type:"geometrychunk",data:s,file:t.file,model:t})},l=async(i,s,r)=>{const n=new AbortController;this.abortControllerForRequestMap.set(s,n);try{await t.downloadResourceRange(i,s,r,h,n.signal)}catch(e){this.viewer.emitEvent({type:"geometryerror",data:e,file:t.file,model:t})}finally{r.forEach(t=>e.onRequestResponseComplete(t.requestId)),this.abortControllerForRequestMap.delete(s),o.update(ft.kNormal)}},d=(t,e)=>{const i=[];for(let s=0;s<e.size();s++){const r=e.get(s);i.push({requestId:t,begin:Number(r.begin),end:Number(r.end)-1}),r.delete()}return i},c={onServicePartReceived:t=>{t&&(i=!0,this.abortController.abort())},onRequest:(e,i)=>{const s=d(e,i);l(t.database,e,s)},onFullLoaded:()=>{o.update(ft.kNormal)},onRequestResponseParsed:t=>{this.abortControllerForRequestMap.delete(t),o.update(ft.kNormal)},onRequestAborted:t=>{const e=this.abortControllerForRequestMap.get(t);e&&e.abort()},onRequestResourceFile:(e,i,o)=>{const h=`${t.fileId}${t.file.type}`,c=d(e,o);let u=[],g=0;const p=s.get(h);return p&&(u=p.ranges,g=p.number),g<=5?(s.set(h,{ranges:[],number:g+1}),void l(h,e,c)):(u=u.concat(c),u.length>=50?(r&&(window.clearTimeout(r),r=0),s.set(h,{ranges:[],number:g+1}),void l(h,e,u)):(s.set(h,{ranges:u,number:g+1}),void(0===r&&(r=window.setTimeout(()=>{a.signal.removeEventListener("abort",n),r=0,s.forEach((t,i)=>{t.ranges.length>0&&(s.set(i,{ranges:[],number:t.number+1}),l(i,e,t.ranges))})},250),a.signal.addEventListener("abort",n,{once:!0})))))}};e.attachPartialResolver(c);try{await t.downloadResource(t.database,h,this.abortController.signal)}catch(t){if(window.clearTimeout(r),!i)throw t}return this}cancel(){super.cancel(),this.abortControllerForRequestMap.forEach(t=>t.abort())}}const wt=g("visualizejs");wt.registerLoader("vsf-file",t=>new ut(t)),wt.registerLoader("vsf-cloud",t=>new gt(t)),wt.registerLoader("vsfx-file",t=>new pt(t)),wt.registerLoader("vsfx-cloud",t=>new mt(t)),wt.registerLoader("vsfx-cloud-streaming",t=>new vt(t)),wt.registerLoader("vsfx-cloud-partial",t=>new yt(t));class xt{constructor(){this._listeners={}}addEventListener(t,e){return void 0===this._listeners[t]&&(this._listeners[t]=[]),this._listeners[t].push(e),this}removeEventListener(t,e){if(void 0===this._listeners[t])return this;const i=this._listeners[t].filter(t=>t!==e);return 0!==i.length?this._listeners[t]=i:delete this._listeners[t],this}removeAllListeners(t){return t?delete this._listeners[t]:this._listeners={},this}emitEvent(t){if(void 0===this._listeners[t.type])return!1;return this._listeners[t.type].slice().forEach(e=>e.call(this,t)),!0}on(t,e){return this.addEventListener(t,e)}off(t,e){return this.removeEventListener(t,e)}emit(t,...e){return"string"==typeof t?this.emitEvent({type:t,args:e}):"object"==typeof t&&this.emitEvent(t)}}function bt(t,e){if(window.getVisualizeLibInst){const e=window.getVisualizeLibInst.script;if(e){if(e.src===t)return Promise.resolve(e);e.remove()}delete window.getVisualizeLibInst}return function(t,e={}){return new Promise((i,s)=>{const r=document.createElement("script");r.src=t,r.async=!0,r.crossOrigin=e.crossOrigin,r.onload=()=>i(r),r.onerror=()=>{r.remove(),s(new Error(`GET ${t} failed to load script`))},document.body.appendChild(r)})}(t,e)}const St=Math.PI/180;const Ct="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},At={_global:Ct,version:"10.0.12",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:t=>At.angleDeg?t*St:t,enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>At.DD.isDragging,isTransforming(){var t,e;return null!==(e=null===(t=At.Transformer)||void 0===t?void 0:t.isTransforming())&&void 0!==e&&e},isDragReady:()=>!!At.DD.node,releaseCanvasOnDestroy:!0,document:Ct.document,_injectGlobal(t){void 0!==Ct.Konva&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),Ct.Konva=t}},Tt=t=>{At[t.prototype.getClassName()]=t};At._injectGlobal(At);const Pt=()=>{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 kt{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 kt(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){const e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.m[0]*e+this.m[2]*i,r=this.m[1]*e+this.m[3]*i,n=this.m[0]*-i+this.m[2]*e,a=this.m[1]*-i+this.m[3]*e;return this.m[0]=s,this.m[1]=r,this.m[2]=n,this.m[3]=a,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){const i=this.m[0]+this.m[2]*e,s=this.m[1]+this.m[3]*e,r=this.m[2]+this.m[0]*t,n=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=r,this.m[3]=n,this}multiply(t){const e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],s=this.m[0]*t.m[2]+this.m[2]*t.m[3],r=this.m[1]*t.m[2]+this.m[3]*t.m[3],n=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],a=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=r,this.m[4]=n,this.m[5]=a,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,s=-this.m[2]*t,r=this.m[0]*t,n=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),a=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=r,this.m[4]=n,this.m[5]=a,this}getMatrix(){return this.m}decompose(){const t=this.m[0],e=this.m[1],i=this.m[2],s=this.m[3],r=t*s-e*i,n={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){const a=Math.sqrt(t*t+e*e);n.rotation=e>0?Math.acos(t/a):-Math.acos(t/a),n.scaleX=a,n.scaleY=r/a,n.skewX=(t*i+e*s)/r,n.skewY=0}else if(0!=i||0!=s){const a=Math.sqrt(i*i+s*s);n.rotation=Math.PI/2-(s>0?Math.acos(-i/a):-Math.acos(i/a)),n.scaleX=r/a,n.scaleY=a,n.skewX=0,n.skewY=(t*i+e*s)/r}return n.rotation=Gt._getRotation(n.rotation),n}}const Et=Math.PI/180,Mt=180/Math.PI,It="#",Rt="Konva error: ",Dt={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]},Lt=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let Ot=[],zt=null;const Ft="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},Gt={_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){Ot.push(t),1===Ot.length&&Ft(function(){const t=Ot;Ot=[],t.forEach(function(t){t()})})},createCanvasElement(){Pt();const t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>(Pt(),document.createElement("img")),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){const i=Gt.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(It,"");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 It+t},isCanvasFarblingActive(){if(null!==zt)return zt;if("undefined"==typeof document)return zt=!1,!1;const t=this.createCanvasElement();t.width=10,t.height=10;const e=t.getContext("2d",{willReadFrequently:!0});e.clearRect(0,0,10,10),e.fillStyle="#282828",e.fillRect(0,0,10,10);const i=e.getImageData(0,0,10,10).data;let s=!1;for(let t=0;t<100;t++)if(40!==i[4*t]||40!==i[4*t+1]||40!==i[4*t+2]||255!==i[4*t+3]){s=!0;break}return zt=s,this.releaseCanvas(t),zt},getHitColor(){const t=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(t):t},getHitColorKey(t,e,i){return this.isCanvasFarblingActive()&&(t=5*Math.round(t/5),e=5*Math.round(e/5),i=5*Math.round(i/5)),It+this._rgbToHex(t,e,i)},getSnappedHexColor(t){const e=this._hexToRgb(t);return It+this._rgbToHex(5*Math.round(e.r/5),5*Math.round(e.g/5),5*Math.round(e.b/5))},getRGB(t){let e;return t in Dt?(e=Dt[t],{r:e[0],g:e[1],b:e[2]}):t[0]===It?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=Lt.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",Gt._namedColorToRBA(t)||Gt._hex3ColorToRGBA(t)||Gt._hex4ColorToRGBA(t)||Gt._hex6ColorToRGBA(t)||Gt._hex8ColorToRGBA(t)||Gt._rgbColorToRGBA(t)||Gt._rgbaColorToRGBA(t)||Gt._hslColorToRGBA(t)),_namedColorToRBA(t){const e=Dt[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA(t){if(0===t.indexOf("rgb(")){const e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA(t){if(0===t.indexOf("rgba(")){const e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map((t,e)=>"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){const[e,...i]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),s=Number(i[0])/360,r=Number(i[1])/100,n=Number(i[2])/100;let a,o,h;if(0===r)return h=255*n,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};a=n<.5?n*(1+r):n+r-n*r;const l=2*n-a,d=[0,0,0];for(let t=0;t<3;t++)o=s+1/3*-(t-1),o<0&&o++,o>1&&o--,h=6*o<1?l+6*(a-l)*o:2*o<1?a:3*o<2?l+(a-l)*(2/3-o)*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*Et,radToDeg:t=>t*Mt,_degToRad:t=>(Gt.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),Gt.degToRad(t)),_radToDeg:t=>(Gt.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),Gt.radToDeg(t)),_getRotation:t=>At.angleDeg?Gt.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(Rt+t)},error(t){console.error(Rt+t)},warn(t){At.showWarnings&&console.warn("Konva warning: "+t)},each(t,e){for(const i in t)e(i,t[i])},_inRange:(t,e,i)=>e<=t&&t<i,_getProjectionToSegment(t,e,i,s,r,n){let a,o,h;const l=(t-i)*(t-i)+(e-s)*(e-s);if(0==l)a=t,o=e,h=(r-i)*(r-i)+(n-s)*(n-s);else{const d=((r-t)*(i-t)+(n-e)*(s-e))/l;d<0?(a=t,o=e,h=(t-r)*(t-r)+(e-n)*(e-n)):d>1?(a=i,o=s,h=(i-r)*(i-r)+(s-n)*(s-n)):(a=t+d*(i-t),o=e+d*(s-e),h=(a-r)*(a-r)+(o-n)*(o-n))}return[a,o,h]},_getProjectionToLine(t,e,i){const s=Gt.cloneObject(t);let r=Number.MAX_VALUE;return e.forEach(function(n,a){if(!i&&a===e.length-1)return;const o=e[(a+1)%e.length],h=Gt._getProjectionToSegment(n.x,n.y,o.x,o.y,t.x,t.y),l=h[0],d=h[1],c=h[2];c<r&&(s.x=l,s.y=d,r=c)}),s},_prepareArrayForTween(t,e,i){const s=[],r=[];if(t.length>e.length){const i=e;e=t,t=i}for(let e=0;e<t.length;e+=2)s.push({x:t[e],y:t[e+1]});for(let t=0;t<e.length;t+=2)r.push({x:e[t],y:e[t+1]});const n=[];return r.forEach(function(t){const e=Gt._getProjectionToLine(t,s,i);n.push(e.x),n.push(e.y)}),n},_prepareToStringify(t){let e;t.visitedByCircularReferenceRemoval=!0;for(const i in t)if(t.hasOwnProperty(i)&&t[i]&&"object"==typeof t[i])if(e=Object.getOwnPropertyDescriptor(t,i),t[i].visitedByCircularReferenceRemoval||Gt._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===Gt._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){At.releaseCanvasOnDestroy&&t.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(t,e,i,s){let r=e<0?e:0,n=i<0?i:0;e=Math.abs(e),i=Math.abs(i);let a=0,o=0,h=0,l=0;"number"==typeof s?a=o=h=l=Math.min(s,e/2,i/2):(a=Math.min(s[0]||0,e/2,i/2),o=Math.min(s[1]||0,e/2,i/2),l=Math.min(s[2]||0,e/2,i/2),h=Math.min(s[3]||0,e/2,i/2)),t.moveTo(r+a,n),t.lineTo(r+e-o,n),t.arc(r+e-o,n+o,o,3*Math.PI/2,0,!1),t.lineTo(r+e,n+i-l),t.arc(r+e-l,n+i-l,l,0,Math.PI/2,!1),t.lineTo(r+h,n+i),t.arc(r+h,n+i-h,h,Math.PI/2,Math.PI,!1),t.lineTo(r,n+a),t.arc(r+a,n+a,a,Math.PI,3*Math.PI/2,!1)},drawRoundedPolygonPath(t,e,i,s,r){s=Math.abs(s);for(let n=0;n<i;n++){const a=e[(n-1+i)%i],o=e[n],h=e[(n+1)%i],l={x:o.x-a.x,y:o.y-a.y},d={x:h.x-o.x,y:h.y-o.y},c=Math.hypot(l.x,l.y),u=Math.hypot(d.x,d.y);let g;g="number"==typeof r?r:n<r.length?r[n]:0;g=s*Math.cos(Math.PI/i)*Math.min(1,g/s*2);const p={x:l.x/c,y:l.y/c},m={x:d.x/u,y:d.y/u},f={x:o.x-p.x*g,y:o.y-p.y*g},_={x:o.x+m.x*g,y:o.y+m.y*g};0===n?t.moveTo(f.x,f.y):t.lineTo(f.x,f.y),t.arcTo(o.x,o.y,_.x,_.y,g)}}};const Vt=["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 Wt,Bt=null;function Nt(){if(null!==Bt)return Bt;try{const t=Gt.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(Bt=!1,!1)}catch(t){return Bt=!1,!1}}class jt{constructor(t){this.canvas=t,At.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i,s,r,n,a=this.traceArr,o=a.length,h="";for(i=0;i<o;i++)s=a[i],r=s.method,r?(n=s.args,h+=r,t?h+="()":Gt._isArray(n[0])?h+="(["+n.join(",")+"])":(e&&(n=n.map(t=>"number"==typeof t?Math.floor(t):t)),h+="("+n.join(",")+")")):(h+=s.property,t||(h+="="+s.val)),h+=";";return h}clearTrace(){this.traceArr=[]}_trace(t){let e,i=this.traceArr;i.push(t),e=i.length,e>=100&&i.shift()}reset(){const t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){const e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){const e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){const e=t.attrs.miterLimit;null!=e&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,r,n){this._context.arc(t,e,i,s,r,n)}arcTo(t,e,i,s,r){this._context.arcTo(t,e,i,s,r)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,r,n){this._context.bezierCurveTo(t,e,i,s,r,n)}clearRect(t,e,i,s){this._context.clearRect(t,e,i,s)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){const i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}createLinearGradient(t,e,i,s){return this._context.createLinearGradient(t,e,i,s)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,s,r,n){return this._context.createRadialGradient(t,e,i,s,r,n)}drawImage(t,e,i,s,r,n,a,o,h){const l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,s,r):9===l.length&&d.drawImage(t,e,i,s,r,n,a,o,h)}ellipse(t,e,i,s,r,n,a,o){this._context.ellipse(t,e,i,s,r,n,a,o)}isPointInPath(t,e,i,s){return i?this._context.isPointInPath(i,t,e,s):this._context.isPointInPath(t,e,s)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,s){this._context.fillRect(t,e,i,s)}strokeRect(t,e,i,s){this._context.strokeRect(t,e,i,s)}fillText(t,e,i,s){s?this._context.fillText(t,e,i,s):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,s){return this._context.getImageData(t,e,i,s)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,s){this._context.rect(t,e,i,s)}roundRect(t,e,i,s,r){this._context.roundRect(t,e,i,s,r)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,s){this._context.quadraticCurveTo(t,e,i,s)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,s,r,n){this._context.setTransform(t,e,i,s,r,n)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,s){this._context.strokeText(t,e,i,s)}transform(t,e,i,s,r,n){this._context.transform(t,e,i,s,r,n)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t,e,i=this,s=Vt.length,r=this.setAttr;const n=function(t){let s,r=i[t];i[t]=function(){return e=function(t){const e=[],i=t.length,s=Gt;for(let r=0;r<i;r++){let i=t[r];s._isNumber(i)?i=Math.round(1e3*i)/1e3:s._isString(i)||(i+=""),e.push(i)}return e}(Array.prototype.slice.call(arguments,0)),s=r.apply(i,arguments),i._trace({method:t,args:e}),s}};for(t=0;t<s;t++)n(Vt[t]);i.setAttr=function(){r.apply(i,arguments);const t=arguments[0];let e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),i._trace({property:t,val:e})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||"source-over"===e||this.setAttr("globalCompositeOperation",e)}}["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"].forEach(function(t){Object.defineProperty(jt.prototype,t,{get(){return this._context[t]},set(e){this._context[t]=e}})});class Ht extends jt{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){const e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){const e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){const e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){const e=t.fill(),i=t.getFillPriority();if(e&&"color"===i)return void this._fillColor(t);const s=t.getFillPatternImage();if(s&&"pattern"===i)return void this._fillPattern(t);const r=t.getFillLinearGradientColorStops();if(r&&"linear-gradient"===i)return void this._fillLinearGradient(t);const n=t.getFillRadialGradientColorStops();n&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):s?this._fillPattern(t):r?this._fillLinearGradient(t):n&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),r=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let t=0;t<s.length;t+=2)r.addColorStop(s[t],s[t+1]);this.setAttr("strokeStyle",r)}}_stroke(t){const e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();const t=this.getCanvas().getPixelRatio();this.setTransform(t,0,0,t,0,0)}this._applyLineCap(t),e&&t.dashEnabled()&&(this.setLineDash(e),this.setAttr("lineDashOffset",t.dashOffset())),this.setAttr("lineWidth",t.strokeWidth()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)");t.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(t):this.setAttr("strokeStyle",t.stroke()),t._strokeFunc(this),i||this.restore()}}_applyShadow(t){var e,i,s;const r=null!==(e=t.getShadowRGBA())&&void 0!==e?e:"black",n=null!==(i=t.getShadowBlur())&&void 0!==i?i:5,a=null!==(s=t.getShadowOffset())&&void 0!==s?s:{x:0,y:0},o=t.getAbsoluteScale(),h=this.canvas.getPixelRatio(),l=o.x*h,d=o.y*h;this.setAttr("shadowColor",r),this.setAttr("shadowBlur",n*Math.min(Math.abs(l),Math.abs(d))),this.setAttr("shadowOffsetX",a.x*l),this.setAttr("shadowOffsetY",a.y*d)}}class Ut extends jt{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 Xt{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const e=(t||{}).pixelRatio||At.pixelRatio||function(){if(Wt)return Wt;const t=Gt.createCanvasElement(),e=t.getContext("2d");return Wt=(At._global.devicePixelRatio||1)/(e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1),Gt.releaseCanvas(t),Wt}();this.pixelRatio=e,this._canvas=Gt.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(t){const e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)}setWidth(t){this.width=this._canvas.width=t*this.pixelRatio,this._canvas.style.width=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}setHeight(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch(t){try{return this._canvas.toDataURL()}catch(t){return Gt.error("Unable to get data URL. "+t.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class Yt extends Xt{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new Ht(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}class Jt extends Xt{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new Ut(this),this.setSize(t.width,t.height)}}const qt={get isDragging(){let t=!1;return qt._dragElements.forEach(e=>{"dragging"===e.dragStatus&&(t=!0)}),t},justDragged:!1,get node(){let t;return qt._dragElements.forEach(e=>{t=e.node}),t},_dragElements:new Map,_drag(t){const e=[];qt._dragElements.forEach((i,s)=>{const{node:r}=i,n=r.getStage();n.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=Gt._getFirstPointerId(t));const a=n._changedPointerPositions.find(t=>t.id===i.pointerId);if(a){if("dragging"!==i.dragStatus){const e=r.dragDistance();if(Math.max(Math.abs(a.x-i.startPointerPos.x),Math.abs(a.y-i.startPointerPos.y))<e)return;if(r.startDrag({evt:t}),!r.isDragging())return}r._setDragPosition(t,i),e.push(r)}}),e.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)})},_endDragBefore(t){const e=[];qt._dragElements.forEach(i=>{const{node:s}=i,r=s.getStage();t&&r.setPointersPositions(t);if(!r._changedPointerPositions.find(t=>t.id===i.pointerId))return;"dragging"!==i.dragStatus&&"stopped"!==i.dragStatus||(qt.justDragged=!0,At._mouseListenClick=!1,At._touchListenClick=!1,At._pointerListenClick=!1,i.dragStatus="stopped");const n=i.node.getLayer()||i.node instanceof At.Stage&&i.node;n&&-1===e.indexOf(n)&&e.push(n)}),e.forEach(t=>{t.draw()})},_endDragAfter(t){qt._dragElements.forEach((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&qt._dragElements.delete(i)})}};function Kt(t){return Gt._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||Gt._isBoolean(t)?t:Object.prototype.toString.call(t)}function Zt(t){return t>255?255:t<0?0:Math.round(t)}function $t(){if(At.isUnminified)return function(t,e){return Gt._isNumber(t)||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function Qt(t){if(At.isUnminified)return function(e,i){let s=Gt._isNumber(e),r=Gt._isArray(e)&&e.length==t;return s||r||Gt.warn(Kt(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array<number>('+t+")"),e}}function te(){if(At.isUnminified)return function(t,e){return Gt._isNumber(t)||"auto"===t||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function ee(){if(At.isUnminified)return function(t,e){return Gt._isString(t)||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function ie(){if(At.isUnminified)return function(t,e){const i=Gt._isString(t),s="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||s||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function se(){if(At.isUnminified)return function(t,e){return!0===t||!1===t||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}At.isBrowser&&(window.addEventListener("mouseup",qt._endDragBefore,!0),window.addEventListener("touchend",qt._endDragBefore,!0),window.addEventListener("touchcancel",qt._endDragBefore,!0),window.addEventListener("mousemove",qt._drag),window.addEventListener("touchmove",qt._drag),window.addEventListener("mouseup",qt._endDragAfter,!1),window.addEventListener("touchend",qt._endDragAfter,!1),window.addEventListener("touchcancel",qt._endDragAfter,!1));const re="get",ne="set",ae={addGetterSetter(t,e,i,s,r){ae.addGetter(t,e,i),ae.addSetter(t,e,s,r),ae.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){const s=re+Gt._capitalize(e);t.prototype[s]=t.prototype[s]||function(){const t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,s){const r=ne+Gt._capitalize(e);t.prototype[r]||ae.overWriteSetter(t,e,i,s)},overWriteSetter(t,e,i,s){const r=ne+Gt._capitalize(e);t.prototype[r]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),s&&s.call(this),this}},addComponentsGetterSetter(t,e,i,s,r){const n=i.length,a=Gt._capitalize,o=re+a(e),h=ne+a(e);t.prototype[o]=function(){const t={};for(let s=0;s<n;s++){const r=i[s];t[r]=this.getAttr(e+a(r))}return t};const l=function(t){if(At.isUnminified)return function(e,i){return null==e||Gt.isObject(e)||Gt.warn(Kt(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}}(i);t.prototype[h]=function(t){const n=this.attrs[e];s&&(t=s.call(this,t,e)),l&&l.call(this,t,e);for(const i in t)t.hasOwnProperty(i)&&this._setAttr(e+a(i),t[i]);return t||i.forEach(t=>{this._setAttr(e+a(t),void 0)}),this._fireChangeEvent(e,n,t),r&&r.call(this),this},ae.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){const i=Gt._capitalize(e),s=ne+i,r=re+i;t.prototype[e]=function(){return arguments.length?(this[s](arguments[0]),this):this[r]()}},addDeprecatedGetterSetter(t,e,i,s){Gt.error("Adding deprecated "+e);const r=re+Gt._capitalize(e),n=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[r]=function(){Gt.error(n);const t=this.attrs[e];return void 0===t?i:t},ae.addSetter(t,e,s,function(){Gt.error(n)}),ae.addOverloadedGetterSetter(t,e)},backCompat(t,e){Gt.each(e,function(e,i){const s=t.prototype[i],r=re+Gt._capitalize(e),n=ne+Gt._capitalize(e);function a(){s.apply(this,arguments),Gt.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=a,t.prototype[r]=a,t.prototype[n]=a})},afterSetFilter(){this._filterUpToDate=!1}};function oe(t){const e=/(\w+)\(([^)]+)\)/g;let i;for(;null!==(i=e.exec(t));){const[,t,e]=i;switch(t){case"blur":{const t=parseFloat(e.replace("px",""));return function(e){this.blurRadius(.5*t);const i=At.Filters;i&&i.Blur&&i.Blur.call(this,e)}}case"brightness":{const t=e.includes("%")?parseFloat(e)/100:parseFloat(e);return function(e){this.brightness(t);const i=At.Filters;i&&i.Brightness&&i.Brightness.call(this,e)}}case"contrast":{const t=parseFloat(e);return function(e){const i=100*(Math.sqrt(t)-1);this.contrast(i);const s=At.Filters;s&&s.Contrast&&s.Contrast.call(this,e)}}case"grayscale":return function(t){const e=At.Filters;e&&e.Grayscale&&e.Grayscale.call(this,t)};case"sepia":return function(t){const e=At.Filters;e&&e.Sepia&&e.Sepia.call(this,t)};case"invert":return function(t){const e=At.Filters;e&&e.Invert&&e.Invert.call(this,t)};default:Gt.warn(`CSS filter "${t}" is not supported in fallback mode. Consider using function filters for better compatibility.`)}}return()=>{}}const he="absoluteOpacity",le="allEventListeners",de="absoluteTransform",ce="absoluteScale",ue="canvas",ge="listening",pe="Shape",me=" ",fe="stage",_e="transform",ve="visible",ye=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(me);let we=1;class xe{constructor(t){this._id=we++,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!==_e&&t!==de||!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===_e||t===de)&&!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(me);this.on(i,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(ue)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===de&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(ue)){const{scene:t,filter:e,hit:i,buffer:s}=this._cache.get(ue);Gt.releaseCanvas(t,e,i,s),this._cache.delete(ue)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),r=Math.ceil(e.height||i.height),n=e.pixelRatio,a=void 0===e.x?Math.floor(i.x):e.x,o=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(!s||!r)return void Gt.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)-a)>.5?1:0),r+=2*h+(Math.abs(Math.round(i.y)-o)>.5?1:0),a-=h,o-=h;const c=new Yt({pixelRatio:n,width:s,height:r}),u=new Yt({pixelRatio:n,width:0,height:0,willReadFrequently:!0}),g=new Jt({pixelRatio:d,width:s,height:r}),p=c.getContext(),m=g.getContext(),f=new Yt({width:c.width/c.pixelRatio+Math.abs(a),height:c.height/c.pixelRatio+Math.abs(o),pixelRatio:c.pixelRatio}),_=f.getContext();return g.isCache=!0,c.isCache=!0,this._cache.delete(ue),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,u.getContext()._context.imageSmoothingEnabled=!1),p.save(),m.save(),_.save(),p.translate(-a,-o),m.translate(-a,-o),_.translate(-a,-o),f.x=a,f.y=o,this._isUnderCache=!0,this._clearSelfAndDescendantCache(he),this._clearSelfAndDescendantCache(ce),this.drawScene(c,this,f),this.drawHit(g,this),this._isUnderCache=!1,p.restore(),m.restore(),l&&(p.save(),p.beginPath(),p.rect(0,0,s,r),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.set(ue,{scene:c,filter:u,hit:g,buffer:f,x:a,y:o}),this._requestDraw(),this}isCached(){return this._cache.has(ue)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){const i=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let s=1/0,r=1/0,n=-1/0,a=-1/0;const o=this.getAbsoluteTransform(e);return i.forEach(function(t){const e=o.point(t);void 0===s&&(s=n=e.x,r=a=e.y),s=Math.min(s,e.x),r=Math.min(r,e.y),n=Math.max(n,e.x),a=Math.max(a,e.y)}),{x:s,y:r,width:n-s,height:a-r}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);const i=this._getCachedSceneCanvas(),s=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/s,i.height/s),t.restore()}_drawCachedHitCanvas(t){const e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t,e,i,s,r=this.filters(),n=this._getCanvasCache(),a=n.scene,o=n.filter,h=o.getContext();if(!r||0===r.length)return a;if(this._filterUpToDate)return o;let l=!0;for(let t=0;t<r.length;t++)if("string"==typeof r[t]&&Nt(),"string"!=typeof r[t]||!Nt()){l=!1;break}const d=a.pixelRatio;if(o.setSize(a.width/a.pixelRatio,a.height/a.pixelRatio),l){const t=r.join(" ");return h.save(),h.setAttr("filter",t),h.drawImage(a._canvas,0,0,a.getWidth()/d,a.getHeight()/d),h.restore(),this._filterUpToDate=!0,o}try{for(t=r.length,h.clear(),h.drawImage(a._canvas,0,0,a.getWidth()/d,a.getHeight()/d),e=h.getImageData(0,0,o.getWidth(),o.getHeight()),i=0;i<t;i++)s=r[i],"string"==typeof s&&(s=oe(s)),s.call(this,e),h.putImageData(e,0,0)}catch(t){Gt.error("Unable to apply filter. "+t.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,o}on(t,e){if(this._cache&&this._cache.delete(le),3===arguments.length)return this._delegate.apply(this,arguments);const i=t.split(me);for(let t=0;t<i.length;t++){const s=i[t].split("."),r=s[0],n=s[1]||"";this.eventListeners[r]||(this.eventListeners[r]=[]),this.eventListeners[r].push({name:n,handler:e})}return this}off(t,e){let i,s,r,n,a,o,h=(t||"").split(me),l=h.length;if(this._cache&&this._cache.delete(le),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<l;i++)if(r=h[i],n=r.split("."),a=n[0],o=n[1],a)this.eventListeners[a]&&this._off(a,o,e);else for(s in this.eventListeners)this._off(s,o,e);return this}dispatchEvent(t){const e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(t){e.call(this,t.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){const s=this;this.on(t,function(t){const r=t.target.findAncestors(e,!0,s);for(let e=0;e<r.length;e++)(t=Gt.cloneObject(t)).currentTarget=r[e],i.call(r[e],t)})}remove(){return this.isDragging()&&this.stopDrag(),qt._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(de),this._clearSelfAndDescendantCache(he),this._clearSelfAndDescendantCache(ce),this._clearSelfAndDescendantCache(fe),this._clearSelfAndDescendantCache(ve),this._clearSelfAndDescendantCache(ge)}_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"+Gt._capitalize(t);return Gt._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"+Gt._capitalize(e),Gt._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(ge,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(ve,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const i=this.getLayer();let s=!1;qt._dragElements.forEach(t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===i)&&(s=!0)});const r=!e&&!At.hitOnDragEnabled&&(s||At.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,r=this.getDepth(),n=this,a=0;const o=this.getStage();return"Stage"!==n.nodeType&&o&&function o(h){for(t=[],e=h.length,i=0;i<e;i++)s=h[i],a++,s.nodeType!==pe&&(t=t.concat(s.getChildren().slice())),s._id===n._id&&(i=e);t.length>0&&t[0].getDepth()<=r&&o(t)}(o.getChildren()),a}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(_e),this._clearSelfAndDescendantCache(de)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges(()=>{this.x(t.x),this.y(t.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const t=this.getStage();if(!t)return null;const e=t.getPointerPosition();if(!e)return null;const i=this.getAbsoluteTransform().copy();return i.invert(),i.point(e)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);const s=this.getAbsoluteTransform(t).getMatrix(),r=new kt,n=this.offset();return r.m=s.slice(),r.translate(n.x,n.y),r.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(_e);const r=this._getAbsoluteTransform().copy();return r.invert(),r.translate(t.x,t.y),t={x:this.attrs.x+r.getTranslation().x,y:this.attrs.y+r.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(_e),this._clearSelfAndDescendantCache(de),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){const t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}move(t){let e=t.x,i=t.y,s=this.x(),r=this.y();return void 0!==e&&(s+=e),void 0!==i&&(r+=i),this.setPosition({x:s,y:r}),this}_eachAncestorReverse(t,e){let i,s,r=[],n=this.getParent();if(!e||e._id!==this._id){for(r.unshift(this);n&&(!e||n._id!==e._id);)r.unshift(n),n=n.parent;for(i=r.length,s=0;s<i;s++)t(r[s])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return Gt.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 Gt.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 Gt.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 Gt.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 Gt.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&Gt.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(he,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity();const e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t,e,i,s,r,n=this.getAttrs();const a={attrs:{},className:this.getClassName()};for(t in n)e=n[t],r=Gt.isObject(e)&&!Gt._isPlainObject(e)&&!Gt._isArray(e),r||(i="function"==typeof this[t]&&this[t],delete n[t],s=i?i.call(this):null,n[t]=e,s!==e&&(a.attrs[t]=e));return Gt._prepareToStringify(a)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){const s=[];e&&this._isMatch(t)&&s.push(this);let r=this.parent;for(;r;){if(r===i)return s;r._isMatch(t)&&s.push(r),r=r.parent}return s}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if("function"==typeof t)return t(this);let e,i,s=t.replace(/ /g,"").split(","),r=s.length;for(e=0;e<r;e++)if(i=s[e],Gt.isValidSelector(i)||(Gt.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),Gt.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),Gt.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(fe,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(de,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new kt,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(de)||new kt,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();const t=this.transformsEnabled();if("all"===t)e.multiply(this.getTransform());else if("position"===t){const t=this.attrs.x||0,i=this.attrs.y||0,s=this.attrs.offsetX||0,r=this.attrs.offsetY||0;e.translate(t-s,i-r)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();const i=this.getAbsoluteTransform(t).decompose();return{x:i.scaleX,y:i.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(_e,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(_e)||new kt;i.reset();const s=this.x(),r=this.y(),n=At.getAngle(this.rotation()),a=null!==(t=this.attrs.scaleX)&&void 0!==t?t:1,o=null!==(e=this.attrs.scaleY)&&void 0!==e?e:1,h=this.attrs.skewX||0,l=this.attrs.skewY||0,d=this.attrs.offsetX||0,c=this.attrs.offsetY||0;return 0===s&&0===r||i.translate(s,r),0!==n&&i.rotate(n),0===h&&0===l||i.skew(h,l),1===a&&1===o||i.scale(a,o),0===d&&0===c||i.translate(-1*d,-1*c),i.dirty=!1,i}clone(t){let e,i,s,r,n,a=Gt.cloneObject(this.attrs);for(e in t)a[e]=t[e];const o=new this.constructor(a);for(e in this.eventListeners)for(i=this.eventListeners[e],s=i.length,r=0;r<s;r++)n=i[r],n.name.indexOf("konva")<0&&(o.eventListeners[e]||(o.eventListeners[e]=[]),o.eventListeners[e].push(n));return o}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=void 0!==t.x?t.x:Math.floor(e.x),r=void 0!==t.y?t.y:Math.floor(e.y),n=t.pixelRatio||1,a=new Yt({width:t.width||Math.ceil(e.width)||(i?i.width():0),height:t.height||Math.ceil(e.height)||(i?i.height():0),pixelRatio:n}),o=a.getContext(),h=new Yt({width:a.width/a.pixelRatio+Math.abs(s),height:a.height/a.pixelRatio+Math.abs(r),pixelRatio:a.pixelRatio});return!1===t.imageSmoothingEnabled&&(o._context.imageSmoothingEnabled=!1),o.save(),(s||r)&&o.translate(-1*s,-1*r),this.drawScene(a,void 0,h),o.restore(),a}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,Gt._urlToImage(this.toDataURL(t),function(t){e(t),null==i||i(t)})}catch(t){i(t)}})}toBlob(t){return new Promise((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,this.toCanvas(t).toBlob(t=>{e(t),null==i||i(t)},null==t?void 0:t.mimeType,null==t?void 0:t.quality)}catch(t){i(t)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():At.dragDistance}_off(t,e,i){let s,r,n,a=this.eventListeners[t];for(s=0;s<a.length;s++)if(r=a[s].name,n=a[s].handler,!("konva"===r&&"konva"!==e||e&&r!==e||i&&i!==n)){if(a.splice(s,1),0===a.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"+Gt._capitalize(t)];return Gt._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(At.autoDrawEnabled){const t=this.getLayer()||this.getStage();null==t||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];(i!==e||Gt.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===pe&&(e.target=this);const s=["mouseenter","mouseleave","pointerenter","pointerleave","touchenter","touchleave"];if(!(-1!==s.indexOf(t)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);const r=-1!==s.indexOf(t)&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!r&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i,s;const r=null!==(e=this._cache.get(le))&&void 0!==e?e:{};let n=null==r?void 0:r[t];if(void 0===n){n=[];let e=Object.getPrototypeOf(this);for(;e;){const r=null!==(s=null===(i=e.eventListeners)||void 0===i?void 0:i[t])&&void 0!==s?s:[];n.push(...r),e=Object.getPrototypeOf(e)}r[t]=n,this._cache.set(le,r)}return n}_fire(t,e){(e=e||{}).currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let t=0;t<i.length;t++)i[t].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let t=0;t<s.length;t++)s[t].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const e=t?t.pointerId:void 0,i=this.getStage(),s=this.getAbsolutePosition();if(!i)return;const r=i._getPointerById(e)||i._changedPointerPositions[0]||s;qt._dragElements.set(this._id,{node:this,startPointerPos:r,offset:{x:r.x-s.x,y:r.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){qt._dragElements.has(this._id)||this._createDragElement(t);qt._dragElements.get(this._id).dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:t&&t.evt},e)}_setDragPosition(t,e){const i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let s={x:i.x-e.offset.x,y:i.y-e.offset.y};const r=this.dragBoundFunc();if(void 0!==r){const e=r.call(this,s,t);e?s=e:Gt.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=qt._dragElements.get(this._id);e&&(e.dragStatus="stopped"),qt._endDragBefore(t),qt._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=qt._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)||At.dragButtons.indexOf(t.evt.button)>=0))return;if(this.isDragging())return;let e=!1;qt._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=qt._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&qt._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 Gt.haveIntersection(i,this.getClientRect())}static create(t,e){return Gt._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let i,s,r,n=xe.prototype.getClassName.call(t),a=t.children;e&&(t.attrs.container=e),At[n]||(Gt.warn('Can not find a node with class name "'+n+'". Fallback to "Shape".'),n="Shape");if(i=new(0,At[n])(t.attrs),a)for(s=a.length,r=0;r<s;r++)i.add(xe._createNode(a[r]));return i}}xe.prototype.nodeType="Node",xe.prototype._attrsAffectingSize=[],xe.prototype.eventListeners={},xe.prototype.on.call(xe.prototype,ye,function(){this._batchingTransformChange?this._needClearTransformCache=!0:(this._clearCache(_e),this._clearSelfAndDescendantCache(de))}),xe.prototype.on.call(xe.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(ve)}),xe.prototype.on.call(xe.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(ge)}),xe.prototype.on.call(xe.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(he)});const be=ae.addGetterSetter;be(xe,"zIndex"),be(xe,"absolutePosition"),be(xe,"position"),be(xe,"x",0,$t()),be(xe,"y",0,$t()),be(xe,"globalCompositeOperation","source-over",ee()),be(xe,"opacity",1,$t()),be(xe,"name","",ee()),be(xe,"id","",ee()),be(xe,"rotation",0,$t()),ae.addComponentsGetterSetter(xe,"scale",["x","y"]),be(xe,"scaleX",1,$t()),be(xe,"scaleY",1,$t()),ae.addComponentsGetterSetter(xe,"skew",["x","y"]),be(xe,"skewX",0,$t()),be(xe,"skewY",0,$t()),ae.addComponentsGetterSetter(xe,"offset",["x","y"]),be(xe,"offsetX",0,$t()),be(xe,"offsetY",0,$t()),be(xe,"dragDistance",void 0,$t()),be(xe,"width",0,$t()),be(xe,"height",0,$t()),be(xe,"listening",!0,se()),be(xe,"preventDefault",!0,se()),be(xe,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),be(xe,"visible",!0,se()),be(xe,"transformsEnabled","all",ee()),be(xe,"size"),be(xe,"dragBoundFunc"),be(xe,"draggable",!1,se()),ae.backCompat(xe,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class Se extends xe{constructor(){super(...arguments),this.children=[]}getChildren(t){const e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(0===t.length)return this;if(t.length>1){for(let e=0;e<t.length;e++)this.add(t[e]);return this}const e=t[0];return e.getParent()?(e.moveTo(this),this):(this._validateAdd(e),e.index=this.getChildren().length,e.parent=this,e._clearCaches(),this.getChildren().push(e),this._fire("add",{child:e}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(t){return this._generalFind(t,!1)}findOne(t){const e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){const i=[];return this._descendants(s=>{const r=s._isMatch(t);return r&&i.push(s),!(!r||!e)}),i}_descendants(t){let e=!1;const i=this.getChildren();for(const s of i){if(e=t(s),e)return!0;if(s.hasChildren()&&(e=s._descendants(t),e))return!0}return!1}toObject(){const t=xe.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=xe.prototype.clone.call(this,t);return this.getChildren().forEach(function(t){e.add(t.clone())}),e}getAllIntersections(t){const e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),this.isCached()||null===(e=this.children)||void 0===e||e.forEach(function(e){e._clearSelfAndDescendantCache(t)})}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach(function(t,e){t.index=e}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas(),n=r&&r.getContext(),a=this._getCanvasCache(),o=a&&a.scene,h=r&&r.isCache;if(!this.isVisible()&&!h)return this;if(o){n.save();const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(n),n.restore()}else this._drawChildren("drawScene",r,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,r=s&&s.getContext(),n=this._getCanvasCache();if(n&&n.hit){r.save();const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(r),r.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var r;const n=e&&e.getContext(),a=this.clipWidth(),o=this.clipHeight(),h=this.clipFunc(),l="number"==typeof a&&"number"==typeof o||h,d=i===this;if(l){n.save();const t=this.getAbsoluteTransform(i);let e,s=t.getMatrix();if(n.transform(s[0],s[1],s[2],s[3],s[4],s[5]),n.beginPath(),h)e=h.call(this,n,this);else{const t=this.clipX(),e=this.clipY();n.rect(t||0,e||0,a,o)}n.clip.apply(n,e),s=t.copy().invert().getMatrix(),n.transform(s[0],s[1],s[2],s[3],s[4],s[5])}const c=!d&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;c&&(n.save(),n._applyGlobalCompositeOperation(this)),null===(r=this.children)||void 0===r||r.forEach(function(r){r[t](e,i,s)}),c&&n.restore(),l&&n.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let r,n,a,o,h={x:1/0,y:1/0,width:0,height:0};const l=this;null===(e=this.children)||void 0===e||e.forEach(function(e){if(!e.visible())return;const i=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===i.width&&0===i.height||(void 0===r?(r=i.x,n=i.y,a=i.x+i.width,o=i.y+i.height):(r=Math.min(r,i.x),n=Math.min(n,i.y),a=Math.max(a,i.x+i.width),o=Math.max(o,i.y+i.height)))});const d=this.find("Shape");let c=!1;for(let t=0;t<d.length;t++){if(d[t]._isVisible(this)){c=!0;break}}return h=c&&void 0!==r?{x:r,y:n,width:a-r,height:o-n}:{x:0,y:0,width:0,height:0},i?h:this._transformedRect(h,s)}}ae.addComponentsGetterSetter(Se,"clip",["x","y","width","height"]),ae.addGetterSetter(Se,"clipX",void 0,$t()),ae.addGetterSetter(Se,"clipY",void 0,$t()),ae.addGetterSetter(Se,"clipWidth",void 0,$t()),ae.addGetterSetter(Se,"clipHeight",void 0,$t()),ae.addGetterSetter(Se,"clipFunc");const Ce=new Map,Ae=void 0!==At._global.PointerEvent;function Te(t){return Ce.get(t)}function Pe(t){return{evt:t,pointerId:t.pointerId}}function ke(t,e){return Ce.get(t)===e}function Ee(t,e){Me(t);e.getStage()&&(Ce.set(t,e),Ae&&e._fire("gotpointercapture",Pe(new PointerEvent("gotpointercapture"))))}function Me(t,e){const i=Ce.get(t);if(!i)return;const s=i.getStage();s&&s.content,Ce.delete(t),Ae&&i._fire("lostpointercapture",Pe(new PointerEvent("lostpointercapture")))}const Ie="mouseleave",Re="mouseover",De="mouseenter",Le="mousemove",Oe="mousedown",ze="mouseup",Fe="pointermove",Ge="pointerdown",Ve="pointerup",We="pointercancel",Be="pointerout",Ne="pointerleave",je="pointerover",He="pointerenter",Ue="contextmenu",Xe="touchstart",Ye="touchend",Je="touchmove",qe="touchcancel",Ke="wheel",Ze=[[De,"_pointerenter"],[Oe,"_pointerdown"],[Le,"_pointermove"],[ze,"_pointerup"],[Ie,"_pointerleave"],[Xe,"_pointerdown"],[Je,"_pointermove"],[Ye,"_pointerup"],[qe,"_pointercancel"],[Re,"_pointerover"],[Ke,"_wheel"],[Ue,"_contextmenu"],[Ge,"_pointerdown"],[Fe,"_pointermove"],[Ve,"_pointerup"],[We,"_pointercancel"],[Ne,"_pointerleave"],["lostpointercapture","_lostpointercapture"]],$e={mouse:{[Be]:"mouseout",[Ne]:Ie,[je]:Re,[He]:De,[Fe]:Le,[Ge]:Oe,[Ve]:ze,[We]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[Be]:"touchout",[Ne]:"touchleave",[je]:"touchover",[He]:"touchenter",[Fe]:Je,[Ge]:Xe,[Ve]:Ye,[We]:qe,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[Be]:Be,[Ne]:Ne,[je]:je,[He]:He,[Fe]:Fe,[Ge]:Ge,[Ve]:Ve,[We]:We,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},Qe=t=>t.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",ti=t=>{const e=Qe(t);return"pointer"===e?At.pointerEventsEnabled&&$e.pointer:"touch"===e?$e.touch:"mouse"===e?$e.mouse:void 0};function ei(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&Gt.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const ii=[];class si extends Se{constructor(t){super(ei(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),ii.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{ei(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();e||i||Gt.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"),Se.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&Gt._isInDocument(t)&&this.container().removeChild(t);const e=ii.indexOf(this);return e>-1&&ii.splice(e,1),Gt.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}:(Gt.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 Yt({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,s=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),s.forEach(function(e){if(!e.isVisible())return;const s=e._toKonvaCanvas(t);i.drawImage(s._canvas,t.x,t.y,s.getWidth()/s.getPixelRatio(),s.getHeight()/s.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children;for(let i=e.length-1;i>=0;i--){const s=e[i].getIntersection(t);if(s)return s}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach(i=>{i.setSize({width:t,height:e}),i.draw()})}add(t,...e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}super.add(t);const i=this.children.length;return i>5&&Gt.warn("The stage has "+i+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),t.setSize({width:this.width(),height:this.height()}),t.draw(),At.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return ke(t,this)}setPointerCapture(t){Ee(t,this)}releaseCapture(t){Me(t)}getLayers(){return this.children}_bindContentEvents(){At.isBrowser&&Ze.forEach(([t,e])=>{this.content.addEventListener(t,t=>{this[e](t)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=ti(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=ti(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=ti(t.type),i=Qe(t.type);if(!e)return;this.setPointersPositions(t);const s=this._getTargetShape(i),r=!(At.isDragging()||At.isTransforming())||At.hitOnDragEnabled;s&&r?(s._fireAndBubble(e.pointerout,{evt:t}),s._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"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=ti(t.type),i=Qe(t.type);if(!e)return;this.setPointersPositions(t);let s=!1;this._changedPointerPositions.forEach(r=>{const n=this.getIntersection(r);if(qt.justDragged=!1,At["_"+i+"ListenClick"]=!0,!n||!n.isListening())return void(this[i+"ClickStartShape"]=void 0);At.capturePointerEventsEnabled&&n.setPointerCapture(r.id),this[i+"ClickStartShape"]=n,n._fireAndBubble(e.pointerdown,{evt:t,pointerId:r.id}),s=!0;const a=t.type.indexOf("touch")>=0;n.preventDefault()&&t.cancelable&&a&&t.preventDefault()}),s||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=ti(t.type),i=Qe(t.type);if(!e)return;const s=t.type.indexOf("touch")>=0||"touch"===t.pointerType;At.isDragging()&&qt.node.preventDefault()&&t.cancelable&&s&&t.preventDefault(),this.setPointersPositions(t);if(!(!(At.isDragging()||At.isTransforming())||At.hitOnDragEnabled))return;const r={};let n=!1;const a=this._getTargetShape(i);this._changedPointerPositions.forEach(s=>{const o=Te(s.id)||this.getIntersection(s),h=s.id,l={evt:t,pointerId:h},d=a!==o;if(d&&a&&(a._fireAndBubble(e.pointerout,{...l},o),a._fireAndBubble(e.pointerleave,{...l},o)),o){if(r[o._id])return;r[o._id]=!0}o&&o.isListening()?(n=!0,d&&(o._fireAndBubble(e.pointerover,{...l},a),o._fireAndBubble(e.pointerenter,{...l},a),this[i+"targetShape"]=o),o._fireAndBubble(e.pointermove,{...l})):a&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[i+"targetShape"]=null)}),n||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=ti(t.type),i=Qe(t.type);if(!e)return;this.setPointersPositions(t);const s=this[i+"ClickStartShape"],r=this[i+"ClickEndShape"],n={};let a=!1;this._changedPointerPositions.forEach(o=>{const h=Te(o.id)||this.getIntersection(o);if(h){if(h.releaseCapture(o.id),n[h._id])return;n[h._id]=!0}const l=o.id,d={evt:t,pointerId:l};let c=!1;At["_"+i+"InDblClickWindow"]?(c=!0,clearTimeout(this[i+"DblTimeout"])):qt.justDragged||(At["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){At["_"+i+"InDblClickWindow"]=!1},At.dblClickWindow),h&&h.isListening()?(a=!0,this[i+"ClickEndShape"]=h,h._fireAndBubble(e.pointerup,{...d}),At["_"+i+"ListenClick"]&&s&&s===h&&(h._fireAndBubble(e.pointerclick,{...d}),c&&r&&r===h&&h._fireAndBubble(e.pointerdblclick,{...d}))):(this[i+"ClickEndShape"]=null,a||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),a=!0),At["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:l}),c&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:l}))}),a||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),At["_"+i+"ListenClick"]=!1,t.cancelable&&"touch"!==i&&"pointer"!==i&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ue,{evt:t}):this._fire(Ue,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ke,{evt:t}):this._fire(Ke,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=Te(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(Ve,Pe(t)),Me(t.pointerId)}_lostpointercapture(t){Me(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:Gt._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:s,id:Gt._getFirstPointerId(t)}])}_setPointerPosition(t){Gt.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 Yt({width:this.width(),height:this.height()}),this.bufferHitCanvas=new Jt({pixelRatio:1,width:this.width(),height:this.height()}),!At.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 Gt.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}}si.prototype.nodeType="Stage",Tt(si),ae.addGetterSetter(si,"container"),At.isBrowser&&document.addEventListener("visibilitychange",()=>{ii.forEach(t=>{t.batchDraw()})});const ri="hasShadow",ni="shadowRGBA",ai="patternImage",oi="linearGradient",hi="radialGradient";let li;function di(){return li||(li=Gt.createCanvasElement().getContext("2d"),li)}const ci={};class ui extends xe{constructor(t){let e;super(t);let i=0;for(;e=Gt.getHitColor(),!e||e in ci;)if(i++,i>=1e4){Gt.warn("Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it."),e=Gt.getRandomColor();break}this.colorKey=e,ci[e]=this}getContext(){return Gt.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return Gt.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(ri,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(ai,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=di().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new kt;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(At.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const i=e.getMatrix(),s="undefined"==typeof DOMMatrix?{a:i[0],b:i[1],c:i[2],d:i[3],e:i[4],f:i[5]}:new DOMMatrix(i);t.setTransform(s)}return t}}_getLinearGradient(){return this._getCache(oi,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=di(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),r=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}_getRadialGradient(){return this._getCache(hi,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=di(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),r=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}getShadowRGBA(){return this._getCache(ni,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=Gt.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 xe.prototype.destroy.call(this),delete ci[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),s=this.hasStroke(),r=1!==this.getAbsoluteOpacity();if(i&&s&&r)return!0;const n=this.hasShadow(),a=this.shadowForStrokeEnabled();return!!(i&&s&&n&&a)}setStrokeHitEnabled(t){Gt.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}getSelfRect(){const t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){let e=!1,i=this.getParent();for(;i;){if(i.isCached()){e=!0;break}i=i.getParent()}const s=t.skipTransform,r=t.relativeTo||e&&this.getStage()||void 0,n=this.getSelfRect(),a=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,o=n.width+a,h=n.height+a,l=!t.skipShadow&&this.hasShadow(),d=l?this.shadowOffsetX():0,c=l?this.shadowOffsetY():0,u=o+Math.abs(d),g=h+Math.abs(c),p=l&&this.shadowBlur()||0,m={width:u+2*p,height:g+2*p,x:-(a/2+p)+Math.min(d,0)+n.x,y:-(a/2+p)+Math.min(c,0)+n.y};return s?m:this._transformedRect(m,r)}drawScene(t,e,i){const s=this.getLayer(),r=(t||s.getCanvas()).getContext(),n=this._getCanvasCache(),a=this.getSceneFunc(),o=this.hasShadow();let h;const l=e===this;if(!this.isVisible()&&!l)return this;if(n){r.save();const t=this.getAbsoluteTransform(e).getMatrix();return r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(r),r.restore(),this}if(!a)return this;if(r.save(),this._useBufferCanvas()){h=this.getStage();const t=i||h.bufferCanvas,s=t.getContext();s.clear(),s.save(),s._applyLineJoin(this),s._applyMiterLimit(this);const n=this.getAbsoluteTransform(e).getMatrix();s.transform(n[0],n[1],n[2],n[3],n[4],n[5]),a.call(this,s,this),s.restore();const d=t.pixelRatio;o&&r._applyShadow(this),l||(r._applyOpacity(this),r._applyGlobalCompositeOperation(this)),r.drawImage(t._canvas,t.x||0,t.y||0,t.width/d,t.height/d)}else{if(r._applyLineJoin(this),r._applyMiterLimit(this),!l){const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),r._applyOpacity(this),r._applyGlobalCompositeOperation(this)}o&&r._applyShadow(this),a.call(this,r,this)}return r.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),r=t||s.hitCanvas,n=r&&r.getContext(),a=this.hitFunc()||this.sceneFunc(),o=this._getCanvasCache(),h=o&&o.hit;if(this.colorKey||Gt.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),h){n.save();const t=this.getAbsoluteTransform(e).getMatrix();return n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(n),n.restore(),this}if(!a)return this;n.save(),n._applyLineJoin(this),n._applyMiterLimit(this);if(!(this===e)){const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return a.call(this,n,this),n.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,r=s.getContext(),n=s.getWidth(),a=s.getHeight();r.clear(),r.drawImage(i._canvas,0,0,n,a);try{const e=r.getImageData(0,0,n,a),i=e.data,s=i.length,o=Gt._hexToRgb(this.colorKey);for(let e=0;e<s;e+=4){i[e+3]>t?(i[e]=o.r,i[e+1]=o.g,i[e+2]=o.b,i[e+3]=255):i[e+3]=0}r.putImageData(e,0,0)}catch(t){Gt.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}hasPointerCapture(t){return ke(t,this)}setPointerCapture(t){Ee(t,this)}releaseCapture(t){Me(t)}}ui.prototype._fillFunc=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},ui.prototype._strokeFunc=function(t){t.stroke()},ui.prototype._fillFuncHit=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},ui.prototype._strokeFuncHit=function(t){t.stroke()},ui.prototype._centroid=!1,ui.prototype.nodeType="Shape",Tt(ui),ui.prototype.eventListeners={},ui.prototype.on.call(ui.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(ri)}),ui.prototype.on.call(ui.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(ni)}),ui.prototype.on.call(ui.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",function(){this._clearCache(ai)}),ui.prototype.on.call(ui.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",function(){this._clearCache(oi)}),ui.prototype.on.call(ui.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",function(){this._clearCache(hi)}),ae.addGetterSetter(ui,"stroke",void 0,ie()),ae.addGetterSetter(ui,"strokeWidth",2,$t()),ae.addGetterSetter(ui,"fillAfterStrokeEnabled",!1),ae.addGetterSetter(ui,"hitStrokeWidth","auto",te()),ae.addGetterSetter(ui,"strokeHitEnabled",!0,se()),ae.addGetterSetter(ui,"perfectDrawEnabled",!0,se()),ae.addGetterSetter(ui,"shadowForStrokeEnabled",!0,se()),ae.addGetterSetter(ui,"lineJoin"),ae.addGetterSetter(ui,"lineCap"),ae.addGetterSetter(ui,"miterLimit"),ae.addGetterSetter(ui,"sceneFunc"),ae.addGetterSetter(ui,"hitFunc"),ae.addGetterSetter(ui,"dash"),ae.addGetterSetter(ui,"dashOffset",0,$t()),ae.addGetterSetter(ui,"shadowColor",void 0,ee()),ae.addGetterSetter(ui,"shadowBlur",0,$t()),ae.addGetterSetter(ui,"shadowOpacity",1,$t()),ae.addComponentsGetterSetter(ui,"shadowOffset",["x","y"]),ae.addGetterSetter(ui,"shadowOffsetX",0,$t()),ae.addGetterSetter(ui,"shadowOffsetY",0,$t()),ae.addGetterSetter(ui,"fillPatternImage"),ae.addGetterSetter(ui,"fill",void 0,ie()),ae.addGetterSetter(ui,"fillPatternX",0,$t()),ae.addGetterSetter(ui,"fillPatternY",0,$t()),ae.addGetterSetter(ui,"fillLinearGradientColorStops"),ae.addGetterSetter(ui,"strokeLinearGradientColorStops"),ae.addGetterSetter(ui,"fillRadialGradientStartRadius",0),ae.addGetterSetter(ui,"fillRadialGradientEndRadius",0),ae.addGetterSetter(ui,"fillRadialGradientColorStops"),ae.addGetterSetter(ui,"fillPatternRepeat","repeat"),ae.addGetterSetter(ui,"fillEnabled",!0),ae.addGetterSetter(ui,"strokeEnabled",!0),ae.addGetterSetter(ui,"shadowEnabled",!0),ae.addGetterSetter(ui,"dashEnabled",!0),ae.addGetterSetter(ui,"strokeScaleEnabled",!0),ae.addGetterSetter(ui,"fillPriority","color"),ae.addComponentsGetterSetter(ui,"fillPatternOffset",["x","y"]),ae.addGetterSetter(ui,"fillPatternOffsetX",0,$t()),ae.addGetterSetter(ui,"fillPatternOffsetY",0,$t()),ae.addComponentsGetterSetter(ui,"fillPatternScale",["x","y"]),ae.addGetterSetter(ui,"fillPatternScaleX",1,$t()),ae.addGetterSetter(ui,"fillPatternScaleY",1,$t()),ae.addComponentsGetterSetter(ui,"fillLinearGradientStartPoint",["x","y"]),ae.addComponentsGetterSetter(ui,"strokeLinearGradientStartPoint",["x","y"]),ae.addGetterSetter(ui,"fillLinearGradientStartPointX",0),ae.addGetterSetter(ui,"strokeLinearGradientStartPointX",0),ae.addGetterSetter(ui,"fillLinearGradientStartPointY",0),ae.addGetterSetter(ui,"strokeLinearGradientStartPointY",0),ae.addComponentsGetterSetter(ui,"fillLinearGradientEndPoint",["x","y"]),ae.addComponentsGetterSetter(ui,"strokeLinearGradientEndPoint",["x","y"]),ae.addGetterSetter(ui,"fillLinearGradientEndPointX",0),ae.addGetterSetter(ui,"strokeLinearGradientEndPointX",0),ae.addGetterSetter(ui,"fillLinearGradientEndPointY",0),ae.addGetterSetter(ui,"strokeLinearGradientEndPointY",0),ae.addComponentsGetterSetter(ui,"fillRadialGradientStartPoint",["x","y"]),ae.addGetterSetter(ui,"fillRadialGradientStartPointX",0),ae.addGetterSetter(ui,"fillRadialGradientStartPointY",0),ae.addComponentsGetterSetter(ui,"fillRadialGradientEndPoint",["x","y"]),ae.addGetterSetter(ui,"fillRadialGradientEndPointX",0),ae.addGetterSetter(ui,"fillRadialGradientEndPointY",0),ae.addGetterSetter(ui,"fillPatternRotation",0),ae.addGetterSetter(ui,"fillRule",void 0,ee()),ae.backCompat(ui,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const gi=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],pi=gi.length;class mi extends Se{constructor(t){super(t),this.canvas=new Yt,this.hitCanvas=new Jt({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(){xe.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(!xe.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(xe.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(xe.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 xe.prototype.remove.call(this),t&&t.parentNode&&Gt._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&&Gt.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(),xe.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(){Gt.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){Gt.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,Gt.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<pi;s++){const r=gi[s],n=this._getIntersection({x:t.x+r.x*e,y:t.y+r.y*e}),a=n.shape;if(a)return a;if(i=!!n.antialiased,!n.antialiased)break}if(!i)return null;e+=1}}_getIntersection(t){const e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,s=i[3];if(255===s){const t=Gt.getHitColorKey(i[0],i[1],i[2]),e=ci[t];return e?{shape:e}:{antialiased:!0}}return s>0?{antialiased:!0}:{}}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),Se.prototype.drawScene.call(this,r,e,i),this._fire("draw",{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),Se.prototype.drawHit.call(this,s,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){Gt.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return Gt.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 Gt.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}mi.prototype.nodeType="Layer",Tt(mi),ae.addGetterSetter(mi,"imageSmoothingEnabled",!0),ae.addGetterSetter(mi,"clearBeforeDraw",!0),ae.addGetterSetter(mi,"hitGraphEnabled",!0,se());class fi extends mi{constructor(t){super(t),this.listening(!1),Gt.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}fi.prototype.nodeType="FastLayer",Tt(fi);class _i extends Se{_validateAdd(t){const e=t.getType();"Group"!==e&&"Shape"!==e&&Gt.throw("You may only add groups and shapes to groups.")}}_i.prototype.nodeType="Group",Tt(_i);const vi=Ct.performance&&Ct.performance.now?function(){return Ct.performance.now()}:function(){return(new Date).getTime()};class yi{constructor(t,e){this.id=yi.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:vi(),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=yi.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=vi(),yi._addAnimation(this),this}stop(){return yi._removeAnimation(this),this}_updateFrameObject(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(t){this.animations.push(t),this._handleAnimation()}static _removeAnimation(t){const e=t.id,i=this.animations,s=i.length;for(let t=0;t<s;t++)if(i[t].id===e){this.animations.splice(t,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],r=s.layers,n=s.func;s._updateFrameObject(vi());const a=r.length;let o;if(o=!n||!1!==n.call(s,s.frame),o)for(let e=0;e<a;e++){const i=r[e];void 0!==i._id&&(t[i._id]=i)}}for(const e in t)t.hasOwnProperty(e)&&t[e].batchDraw()}static _animationLoop(){const t=yi;t.animations.length?(t._runFrames(),Gt.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,Gt.requestAnimFrame(this._animationLoop))}}yi.animations=[],yi.animIdCounter=0,yi.animRunning=!1;const wi={node:1,duration:1,easing:1,onFinish:1,yoyo:1},xi=["fill","stroke","shadowColor"];let bi=0;class Si{constructor(t,e,i,s,r,n,a){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=n,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}fire(t){const e=this[t];e&&e()}setTime(t){t>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class Ci{constructor(t){const e=this,i=t.node,s=i._id,r=t.easing||Ai.Linear,n=!!t.yoyo;let a,o;a=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=i,this._id=bi++;const h=i.getLayer()||(i instanceof At.Stage?i.getLayers():null);for(o in h||Gt.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new yi(function(){e.tween.onEnterFrame()},h),this.tween=new Si(o,function(t){e._tweenFunc(t)},r,0,1,1e3*a,n),this._addListeners(),Ci.attrs[s]||(Ci.attrs[s]={}),Ci.attrs[s][this._id]||(Ci.attrs[s][this._id]={}),Ci.tweens[s]||(Ci.tweens[s]={}),t)void 0===wi[o]&&this._addAttr(o,t[o]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){const i=this.node,s=i._id;let r,n,a,o,h;const l=Ci.tweens[s][t];l&&delete Ci.attrs[s][l][t];let d=i.getAttr(t);if(Gt._isArray(e))if(r=[],n=Math.max(e.length,d.length),"points"===t&&e.length!==d.length&&(e.length>d.length?(o=d,d=Gt._prepareArrayForTween(d,e,i.closed())):(a=e,e=Gt._prepareArrayForTween(e,d,i.closed()))),0===t.indexOf("fill"))for(let t=0;t<n;t++)if(t%2==0)r.push(e[t]-d[t]);else{const i=Gt.colorToRGBA(d[t]);h=Gt.colorToRGBA(e[t]),d[t]=i,r.push({r:h.r-i.r,g:h.g-i.g,b:h.b-i.b,a:h.a-i.a})}else for(let t=0;t<n;t++)r.push(e[t]-d[t]);else-1!==xi.indexOf(t)?(d=Gt.colorToRGBA(d),h=Gt.colorToRGBA(e),r={r:h.r-d.r,g:h.g-d.g,b:h.b-d.b,a:h.a-d.a}):r=e-d;Ci.attrs[s][this._id][t]={start:d,diff:r,end:e,trueEnd:a,trueStart:o},Ci.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=Ci.attrs[e._id][this._id];let s,r,n,a,o,h,l,d;for(s in i){if(r=i[s],n=r.start,a=r.diff,d=r.end,Gt._isArray(n))if(o=[],l=Math.max(n.length,d.length),0===s.indexOf("fill"))for(h=0;h<l;h++)h%2==0?o.push((n[h]||0)+a[h]*t):o.push("rgba("+Math.round(n[h].r+a[h].r*t)+","+Math.round(n[h].g+a[h].g*t)+","+Math.round(n[h].b+a[h].b*t)+","+(n[h].a+a[h].a*t)+")");else for(h=0;h<l;h++)o.push((n[h]||0)+a[h]*t);else o=-1!==xi.indexOf(s)?"rgba("+Math.round(n.r+a.r*t)+","+Math.round(n.g+a.g*t)+","+Math.round(n.b+a.b*t)+","+(n.a+a.a*t)+")":n+a*t;e.setAttr(s,o)}}_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=Ci.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=Ci.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=Ci.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const e in i)delete Ci.tweens[t][e];delete Ci.attrs[t][e],Ci.tweens[t]&&(0===Object.keys(Ci.tweens[t]).length&&delete Ci.tweens[t],0===Object.keys(Ci.attrs[t]).length&&delete Ci.attrs[t])}}Ci.attrs={},Ci.tweens={},xe.prototype.to=function(t){const e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()};new Ci(t).play()};const Ai={BackEaseIn(t,e,i,s){const r=1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},BackEaseOut(t,e,i,s){const r=1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},BackEaseInOut(t,e,i,s){let r=1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},ElasticEaseIn(t,e,i,s,r,n){let a=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,a=n/4):a=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-a)*(2*Math.PI)/n)+e)},ElasticEaseOut(t,e,i,s,r,n){let a=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,a=n/4):a=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-a)*(2*Math.PI)/n)+i+e)},ElasticEaseInOut(t,e,i,s,r,n){let a=0;return 0===t?e:2==(t/=s/2)?e+i:(n||(n=s*(.3*1.5)),!r||r<Math.abs(i)?(r=i,a=n/4):a=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-a)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*(2*Math.PI)/n)*.5+i+e)},BounceEaseOut:(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,s)=>i-Ai.BounceEaseOut(s-t,0,i,s)+e,BounceEaseInOut:(t,e,i,s)=>t<s/2?.5*Ai.BounceEaseIn(2*t,0,i,s)+e:.5*Ai.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},Ti=Gt._assign(At,{Util:Gt,Transform:kt,Node:xe,Container:Se,Stage:si,stages:ii,Layer:mi,FastLayer:fi,Group:_i,DD:qt,Shape:ui,shapes:ci,Animation:yi,Tween:Ci,Easings:Ai,Context:jt,Canvas:Xt});class Pi extends ui{_sceneFunc(t){const e=At.getAngle(this.angle()),i=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,i),t.arc(0,0,this.innerRadius(),e,0,!i),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),i=this.clockwise(),s=At.getAngle(i?360-this.angle():this.angle()),r=Math.cos(Math.min(s,Math.PI)),n=Math.sin(Math.min(Math.max(Math.PI,s),3*Math.PI/2)),a=Math.sin(Math.min(s,Math.PI/2)),o=r*(r>0?t:e),h=n*(n>0?t:e),l=a*(a>0?e:t);return{x:o,y:i?-1*l:h,width:1*e-o,height:l-h}}}function ki(t,e,i,s,r,n,a){const o=Math.sqrt(Math.pow(i-t,2)+Math.pow(s-e,2)),h=Math.sqrt(Math.pow(r-i,2)+Math.pow(n-s,2)),l=a*o/(o+h),d=a*h/(o+h);return[i-l*(r-t),s-l*(n-e),i+d*(r-t),s+d*(n-e)]}function Ei(t,e){const i=t.length,s=[];for(let r=2;r<i-2;r+=2){const i=ki(t[r-2],t[r-1],t[r],t[r+1],t[r+2],t[r+3],e);isNaN(i[0])||(s.push(i[0]),s.push(i[1]),s.push(t[r]),s.push(t[r+1]),s.push(i[2]),s.push(i[3]))}return s}Pi.prototype._centroid=!0,Pi.prototype.className="Arc",Pi.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],Tt(Pi),ae.addGetterSetter(Pi,"innerRadius",0,$t()),ae.addGetterSetter(Pi,"outerRadius",0,$t()),ae.addGetterSetter(Pi,"angle",0,$t()),ae.addGetterSetter(Pi,"clockwise",!1,se());class Mi extends ui{constructor(t){super(t),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(t){const e=this.points(),i=e.length,s=this.tension(),r=this.closed(),n=this.bezier();if(!i)return;let a=0;if(t.beginPath(),t.moveTo(e[0],e[1]),0!==s&&i>4){const s=this.getTensionPoints(),n=s.length;for(a=r?0:4,r||t.quadraticCurveTo(s[0],s[1],s[2],s[3]);a<n-2;)t.bezierCurveTo(s[a++],s[a++],s[a++],s[a++],s[a++],s[a++]);r||t.quadraticCurveTo(s[n-2],s[n-1],e[i-2],e[i-1])}else if(n)for(a=2;a<i;)t.bezierCurveTo(e[a++],e[a++],e[a++],e[a++],e[a++],e[a++]);else for(a=2;a<i;a+=2)t.lineTo(e[a],e[a+1]);r?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():Ei(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=ki(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),r=ki(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),n=Ei(t,i);return[s[2],s[3]].concat(n).concat([r[0],r[1],t[e-2],t[e-1],r[2],r[3],s[0],s[1],t[0],t[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let t=this.points();if(t.length<4)return{x:t[0]||0,y:t[1]||0,width:0,height:0};t=0!==this.tension()?[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.points();let e,i,s=t[0],r=t[0],n=t[1],a=t[1];for(let o=0;o<t.length/2;o++)e=t[2*o],i=t[2*o+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),a=Math.max(a,i);return{x:s,y:n,width:r-s,height:a-n}}}Mi.prototype.className="Line",Mi.prototype._attrsAffectingSize=["points","bezier","tension"],Tt(Mi),ae.addGetterSetter(Mi,"closed",!1),ae.addGetterSetter(Mi,"bezier",!1),ae.addGetterSetter(Mi,"tension",0,$t()),ae.addGetterSetter(Mi,"points",[],function(){if(At.isUnminified)return function(t,e){const i=Int8Array?Object.getPrototypeOf(Int8Array):null;return i&&t instanceof i||(Gt._isArray(t)?t.forEach(function(t){Gt._isNumber(t)||Gt.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")}):Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),t}}());const Ii=[[],[],[-.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]],Ri=[[],[],[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]],Di=[[1],[1,1],[1,2,1],[1,3,3,1]],Li=(t,e,i)=>{let s,r;const n=i/2;s=0;for(let i=0;i<20;i++)r=n*Ii[20][i]+n,s+=Ri[20][i]*zi(t,e,r);return n*s},Oi=(t,e,i)=>{void 0===i&&(i=1);const s=t[0]-2*t[1]+t[2],r=e[0]-2*e[1]+e[2],n=2*t[1]-2*t[0],a=2*e[1]-2*e[0],o=4*(s*s+r*r),h=4*(s*n+r*a),l=n*n+a*a;if(0===o)return i*Math.sqrt(Math.pow(t[2]-t[0],2)+Math.pow(e[2]-e[0],2));const d=h/(2*o),c=i+d,u=l/o-d*d,g=c*c+u>0?Math.sqrt(c*c+u):0,p=d*d+u>0?Math.sqrt(d*d+u):0,m=d+Math.sqrt(d*d+u)!==0?u*Math.log(Math.abs((c+g)/(d+p))):0;return Math.sqrt(o)/2*(c*g-d*p+m)};function zi(t,e,i){const s=Fi(1,i,t),r=Fi(1,i,e),n=s*s+r*r;return Math.sqrt(n)}const Fi=(t,e,i)=>{const s=i.length-1;let r,n;if(0===s)return 0;if(0===t){n=0;for(let t=0;t<=s;t++)n+=Di[s][t]*Math.pow(1-e,s-t)*Math.pow(e,t)*i[t];return n}r=new Array(s);for(let t=0;t<s;t++)r[t]=s*(i[t+1]-i[t]);return Fi(t-1,e,r)},Gi=(t,e,i)=>{let s=1,r=t/e,n=(t-i(r))/e,a=0;for(;s>.001;){const o=i(r+n),h=Math.abs(t-o)/e;if(h<s)s=h,r+=n;else{const a=i(r-n),o=Math.abs(t-a)/e;o<s?(s=o,r-=n):n/=2}if(a++,a>500)break}return r};class Vi extends ui{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=Vi.parsePathData(this.data()),this.pathLength=Vi.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const r=e[s].command,n=e[s].points;switch(r){case"L":t.lineTo(n[0],n[1]);break;case"M":t.moveTo(n[0],n[1]);break;case"C":t.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]);break;case"Q":t.quadraticCurveTo(n[0],n[1],n[2],n[3]);break;case"A":const e=n[0],s=n[1],r=n[2],a=n[3],o=n[4],h=n[5],l=n[6],d=n[7],c=r>a?r:a,u=r>a?1:r/a,g=r>a?a/r:1;t.translate(e,s),t.rotate(l),t.scale(u,g),t.arc(0,0,c,o,o+h,1-d),t.scale(1/u,1/g),t.rotate(-l),t.translate(-e,-s);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(e){if("A"===e.command){const i=e.points[4],s=e.points[5],r=e.points[4]+s;let n=Math.PI/180;if(Math.abs(i-r)<n&&(n=Math.abs(i-r)),s<0)for(let s=i-n;s>r;s-=n){const i=Vi.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}else for(let s=i+n;s<r;s+=n){const i=Vi.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}}else if("C"===e.command)for(let i=0;i<=1;i+=.01){const s=Vi.getPointOnCubicBezier(i,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);t.push(s.x,s.y)}else t=t.concat(e.points)});let e,i,s=t[0],r=t[0],n=t[1],a=t[1];for(let o=0;o<t.length/2;o++)e=t[2*o],i=t[2*o+1],isNaN(e)||(s=Math.min(s,e),r=Math.max(r,e)),isNaN(i)||(n=Math.min(n,i),a=Math.max(a,i));return{x:s,y:n,width:r-s,height:a-n}}getLength(){return this.pathLength}getPointAtLength(t){return Vi.getPointAtLengthOfDataArray(t,this.dataArray)}static getLineLength(t,e,i,s){return Math.sqrt((i-t)*(i-t)+(s-e)*(s-e))}static getPathLength(t){let e=0;for(let i=0;i<t.length;++i)e+=t[i].pathLength;return e}static getPointAtLengthOfDataArray(t,e){let i,s=0,r=e.length;if(!r)return null;for(;s<r&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===r)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01){return"M"===e[s].command?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y}}const n=e[s],a=n.points;switch(n.command){case"L":return Vi.getPointOnLine(t,n.start.x,n.start.y,a[0],a[1]);case"C":return Vi.getPointOnCubicBezier(Gi(t,Vi.getPathLength(e),t=>Li([n.start.x,a[0],a[2],a[4]],[n.start.y,a[1],a[3],a[5]],t)),n.start.x,n.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return Vi.getPointOnQuadraticBezier(Gi(t,Vi.getPathLength(e),t=>Oi([n.start.x,a[0],a[2]],[n.start.y,a[1],a[3]],t)),n.start.x,n.start.y,a[0],a[1],a[2],a[3]);case"A":const i=a[0],s=a[1],r=a[2],o=a[3],h=a[5],l=a[6];let d=a[4];return d+=h*t/n.pathLength,Vi.getPointOnEllipticalArc(i,s,r,o,d,l)}return null}static getPointOnLine(t,e,i,s,r,n,a){n=null!=n?n:e,a=null!=a?a:i;const o=this.getLineLength(e,i,s,r);if(o<1e-10)return{x:e,y:i};if(s===e)return{x:n,y:a+(r>i?t:-t)};const h=(r-i)/(s-e),l=Math.sqrt(t*t/(1+h*h))*(s<e?-1:1),d=h*l;if(Math.abs(a-i-h*(n-e))<1e-10)return{x:n+l,y:a+d};const c=((n-e)*(s-e)+(a-i)*(r-i))/(o*o),u=e+c*(s-e),g=i+c*(r-i),p=this.getLineLength(n,a,u,g),m=Math.sqrt(t*t-p*p),f=Math.sqrt(m*m/(1+h*h))*(s<e?-1:1);return{x:u+f,y:g+h*f}}static getPointOnCubicBezier(t,e,i,s,r,n,a,o,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 u(t){return(1-t)*(1-t)*(1-t)}return{x:o*l(t)+n*d(t)+s*c(t)+e*u(t),y:h*l(t)+a*d(t)+r*c(t)+i*u(t)}}static getPointOnQuadraticBezier(t,e,i,s,r,n,a){function o(t){return t*t}function h(t){return 2*t*(1-t)}function l(t){return(1-t)*(1-t)}return{x:n*o(t)+s*h(t)+e*l(t),y:a*o(t)+r*h(t)+i*l(t)}}static getPointOnEllipticalArc(t,e,i,s,r,n){const a=Math.cos(n),o=Math.sin(n),h=i*Math.cos(r),l=s*Math.sin(r);return{x:t+(h*a-l*o),y:e+(h*o+l*a)}}static parsePathData(t){if(!t)return[];let e=t;const i=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];e=e.replace(new RegExp(" ","g"),",");for(let t=0;t<i.length;t++)e=e.replace(new RegExp(i[t],"g"),"|"+i[t]);const s=e.split("|"),r=[],n=[];let a=0,o=0;const h=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let l;for(let t=1;t<s.length;t++){let e=s[t],i=e.charAt(0);for(e=e.slice(1),n.length=0;l=h.exec(e);)n.push(l[0]);let d=[],c="A"===i||"a"===i?0:-1;for(let t=0,e=n.length;t<e;t++){const e=n[t];if("00"!==e)if(c>=0){if(3===c){if(/^[01]{2}\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),d.push(parseFloat(e.slice(2))),c+=3,c>=7&&(c-=7);continue}if("11"===e||"10"===e||"01"===e){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}else if(4===c){if(/^[01]\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseFloat(e.slice(1))),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t),c+=1,c>=7&&(c-=7)}else{const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t)}else d.push(0,0),c>=0&&(c+=2,c>=7&&(c-=7))}for(;d.length>0&&!isNaN(d[0]);){let t="",e=[];const s=a,n=o;let h,l,c,u,g,p,m,f,_,v;switch(i){case"l":a+=d.shift(),o+=d.shift(),t="L",e.push(a,o);break;case"L":a=d.shift(),o=d.shift(),e.push(a,o);break;case"m":const s=d.shift(),n=d.shift();if(a+=s,o+=n,t="M",r.length>2&&"z"===r[r.length-1].command)for(let t=r.length-2;t>=0;t--)if("M"===r[t].command){a=r[t].points[0]+s,o=r[t].points[1]+n;break}e.push(a,o),i="l";break;case"M":a=d.shift(),o=d.shift(),t="M",e.push(a,o),i="L";break;case"h":a+=d.shift(),t="L",e.push(a,o);break;case"H":a=d.shift(),t="L",e.push(a,o);break;case"v":o+=d.shift(),t="L",e.push(a,o);break;case"V":o=d.shift(),t="L",e.push(a,o);break;case"C":e.push(d.shift(),d.shift(),d.shift(),d.shift()),a=d.shift(),o=d.shift(),e.push(a,o);break;case"c":e.push(a+d.shift(),o+d.shift(),a+d.shift(),o+d.shift()),a+=d.shift(),o+=d.shift(),t="C",e.push(a,o);break;case"S":l=a,c=o,h=r[r.length-1],"C"===h.command&&(l=a+(a-h.points[2]),c=o+(o-h.points[3])),e.push(l,c,d.shift(),d.shift()),a=d.shift(),o=d.shift(),t="C",e.push(a,o);break;case"s":l=a,c=o,h=r[r.length-1],"C"===h.command&&(l=a+(a-h.points[2]),c=o+(o-h.points[3])),e.push(l,c,a+d.shift(),o+d.shift()),a+=d.shift(),o+=d.shift(),t="C",e.push(a,o);break;case"Q":e.push(d.shift(),d.shift()),a=d.shift(),o=d.shift(),e.push(a,o);break;case"q":e.push(a+d.shift(),o+d.shift()),a+=d.shift(),o+=d.shift(),t="Q",e.push(a,o);break;case"T":l=a,c=o,h=r[r.length-1],"Q"===h.command&&(l=a+(a-h.points[0]),c=o+(o-h.points[1])),a=d.shift(),o=d.shift(),t="Q",e.push(l,c,a,o);break;case"t":l=a,c=o,h=r[r.length-1],"Q"===h.command&&(l=a+(a-h.points[0]),c=o+(o-h.points[1])),a+=d.shift(),o+=d.shift(),t="Q",e.push(l,c,a,o);break;case"A":u=d.shift(),g=d.shift(),p=d.shift(),m=d.shift(),f=d.shift(),_=a,v=o,a=d.shift(),o=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(_,v,a,o,m,f,u,g,p);break;case"a":u=d.shift(),g=d.shift(),p=d.shift(),m=d.shift(),f=d.shift(),_=a,v=o,a+=d.shift(),o+=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(_,v,a,o,m,f,u,g,p)}r.push({command:t||i,points:e,start:{x:s,y:n},pathLength:this.calcLength(s,n,t||i,e)})}"z"!==i&&"Z"!==i||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r}static calcLength(t,e,i,s){let r,n,a,o;const h=Vi;switch(i){case"L":return h.getLineLength(t,e,s[0],s[1]);case"C":return Li([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return Oi([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":r=0;const i=s[4],l=s[5],d=s[4]+l;let c=Math.PI/180;if(Math.abs(i-d)<c&&(c=Math.abs(i-d)),n=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],i,0),l<0)for(o=i-c;o>d;o-=c)a=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],o,0),r+=h.getLineLength(n.x,n.y,a.x,a.y),n=a;else for(o=i+c;o<d;o+=c)a=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],o,0),r+=h.getLineLength(n.x,n.y,a.x,a.y),n=a;return a=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),r+=h.getLineLength(n.x,n.y,a.x,a.y),r}return 0}static convertEndpointToCenterParameterization(t,e,i,s,r,n,a,o,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,u=d*d/(a*a)+c*c/(o*o);u>1&&(a*=Math.sqrt(u),o*=Math.sqrt(u));let g=Math.sqrt((a*a*(o*o)-a*a*(c*c)-o*o*(d*d))/(a*a*(c*c)+o*o*(d*d)));r===n&&(g*=-1),isNaN(g)&&(g=0);const p=g*a*c/o,m=g*-o*d/a,f=(t+i)/2+Math.cos(l)*p-Math.sin(l)*m,_=(e+s)/2+Math.sin(l)*p+Math.cos(l)*m,v=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},y=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(v(t)*v(e))},w=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(y(t,e))},x=w([1,0],[(d-p)/a,(c-m)/o]),b=[(d-p)/a,(c-m)/o],S=[(-1*d-p)/a,(-1*c-m)/o];let C=w(b,S);return y(b,S)<=-1&&(C=Math.PI),y(b,S)>=1&&(C=0),0===n&&C>0&&(C-=2*Math.PI),1===n&&C<0&&(C+=2*Math.PI),[f,_,a,o,x,C,l,n]}}Vi.prototype.className="Path",Vi.prototype._attrsAffectingSize=["data"],Tt(Vi),ae.addGetterSetter(Vi,"data");class Wi extends Mi{_sceneFunc(t){super._sceneFunc(t);const e=2*Math.PI,i=this.points();let s=i;const r=0!==this.tension()&&i.length>4;r&&(s=this.getTensionPoints());const n=this.pointerLength(),a=i.length;let o,h;if(r){const t=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[a-2],i[a-1]],e=Vi.calcLength(s[s.length-4],s[s.length-3],"C",t),r=Vi.getPointOnQuadraticBezier(Math.min(1,1-n/e),t[0],t[1],t[2],t[3],t[4],t[5]);o=i[a-2]-r.x,h=i[a-1]-r.y}else o=i[a-2]-i[a-4],h=i[a-1]-i[a-3];const l=(Math.atan2(h,o)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[a-2],i[a-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),r?(o=(s[0]+s[2])/2-i[0],h=(s[1]+s[3])/2-i[1]):(o=i[2]-i[0],h=i[3]-i[1]),t.rotate((Math.atan2(-h,-o)+e)%e),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){const e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x,y:t.y-e,width:t.width,height:t.height+2*e}}}Wi.prototype.className="Arrow",Tt(Wi),ae.addGetterSetter(Wi,"pointerLength",10,$t()),ae.addGetterSetter(Wi,"pointerWidth",10,$t()),ae.addGetterSetter(Wi,"pointerAtBeginning",!1),ae.addGetterSetter(Wi,"pointerAtEnding",!0);class Bi extends ui{_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)}}Bi.prototype._centroid=!0,Bi.prototype.className="Circle",Bi.prototype._attrsAffectingSize=["radius"],Tt(Bi),ae.addGetterSetter(Bi,"radius",0,$t());class Ni extends ui{_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)}}Ni.prototype.className="Ellipse",Ni.prototype._centroid=!0,Ni.prototype._attrsAffectingSize=["radiusX","radiusY"],Tt(Ni),ae.addComponentsGetterSetter(Ni,"radius",["x","y"]),ae.addGetterSetter(Ni,"radiusX",0,$t()),ae.addGetterSetter(Ni,"radiusY",0,$t());let ji=class t extends ui{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",t=>{this._removeImageLoad(t.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){const t=!!this.cornerRadius(),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),r=this.attrs.image;let n;if(r){const t=this.attrs.cropWidth,s=this.attrs.cropHeight;n=t&&s?[r,this.cropX(),this.cropY(),t,s,0,0,e,i]:[r,0,0,e,i]}(this.hasFill()||this.hasStroke()||s)&&(t.beginPath(),s?Gt.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),r&&(s&&t.clip(),t.drawImage.apply(t,n))}_hitFunc(t){const e=this.width(),i=this.height(),s=this.cornerRadius();t.beginPath(),s?Gt.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e,i;return null!==(i=null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width)&&void 0!==i?i:0}getHeight(){var t,e,i;return null!==(i=null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height)&&void 0!==i?i:0}static fromURL(e,i,s=null){const r=Gt.createImageElement();r.onload=function(){const e=new t({image:r});i(e)},r.onerror=s,r.crossOrigin="Anonymous",r.src=e}};ji.prototype.className="Image",ji.prototype._attrsAffectingSize=["image"],Tt(ji),ae.addGetterSetter(ji,"cornerRadius",0,Qt(4)),ae.addGetterSetter(ji,"image"),ae.addComponentsGetterSetter(ji,"crop",["x","y","width","height"]),ae.addGetterSetter(ji,"cropX",0,$t()),ae.addGetterSetter(ji,"cropY",0,$t()),ae.addGetterSetter(ji,"cropWidth",0,$t()),ae.addGetterSetter(ji,"cropHeight",0,$t());const Hi=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],Ui="up",Xi="right",Yi="down",Ji="left",qi=Hi.length;class Ki extends _i{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<qi;e++)t.on(Hi[e]+"Change.konva",s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t,e,i,s,r,n,a,o=this.getText(),h=this.getTag();if(o&&h){switch(t=o.width(),e=o.height(),i=h.pointerDirection(),s=h.pointerWidth(),a=h.pointerHeight(),r=0,n=0,i){case Ui:r=t/2,n=-1*a;break;case Xi:r=t+s,n=e/2;break;case Yi:r=t/2,n=e+a;break;case Ji:r=-1*s,n=e/2}h.setAttrs({x:-1*r,y:-1*n,width:t,height:e}),o.setAttrs({x:-1*r,y:-1*n})}}}Ki.prototype.className="Label",Tt(Ki);class Zi extends ui{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),r=this.pointerWidth(),n=this.pointerHeight(),a=this.cornerRadius();let o=0,h=0,l=0,d=0;"number"==typeof a?o=h=l=d=Math.min(a,e/2,i/2):(o=Math.min(a[0]||0,e/2,i/2),h=Math.min(a[1]||0,e/2,i/2),d=Math.min(a[2]||0,e/2,i/2),l=Math.min(a[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(o,0),s===Ui&&(t.lineTo((e-r)/2,0),t.lineTo(e/2,-1*n),t.lineTo((e+r)/2,0)),t.lineTo(e-h,0),t.arc(e-h,h,h,3*Math.PI/2,0,!1),s===Xi&&(t.lineTo(e,(i-n)/2),t.lineTo(e+r,i/2),t.lineTo(e,(i+n)/2)),t.lineTo(e,i-d),t.arc(e-d,i-d,d,0,Math.PI/2,!1),s===Yi&&(t.lineTo((e+r)/2,i),t.lineTo(e/2,i+n),t.lineTo((e-r)/2,i)),t.lineTo(l,i),t.arc(l,i-l,l,Math.PI/2,Math.PI,!1),s===Ji&&(t.lineTo(0,(i+n)/2),t.lineTo(-1*r,i/2),t.lineTo(0,(i-n)/2)),t.lineTo(0,o),t.arc(o,o,o,Math.PI,3*Math.PI/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),r=this.pointerDirection(),n=this.width(),a=this.height();return r===Ui?(e-=s,a+=s):r===Yi?a+=s:r===Ji?(t-=1.5*i,n+=i):r===Xi&&(n+=1.5*i),{x:t,y:e,width:n,height:a}}}Zi.prototype.className="Tag",Tt(Zi),ae.addGetterSetter(Zi,"pointerDirection","none"),ae.addGetterSetter(Zi,"pointerWidth",0,$t()),ae.addGetterSetter(Zi,"pointerHeight",0,$t()),ae.addGetterSetter(Zi,"cornerRadius",0,Qt(4));class $i extends ui{_sceneFunc(t){const e=this.cornerRadius(),i=this.width(),s=this.height();t.beginPath(),e?Gt.drawRoundedRectPath(t,i,s,e):t.rect(0,0,i,s),t.closePath(),t.fillStrokeShape(this)}}$i.prototype.className="Rect",Tt($i),ae.addGetterSetter($i,"cornerRadius",0,Qt(4));class Qi extends ui{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),r=this.cornerRadius();if(t.beginPath(),r)Gt.drawRoundedPolygonPath(t,e,s,i,r);else{t.moveTo(e[0].x,e[0].y);for(let i=1;i<e.length;i++)t.lineTo(e[i].x,e[i].y)}t.closePath(),t.fillStrokeShape(this)}_getPoints(){const t=this.attrs.sides,e=this.attrs.radius||0,i=[];for(let s=0;s<t;s++)i.push({x:e*Math.sin(2*s*Math.PI/t),y:-1*e*Math.cos(2*s*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].x,s=t[0].y,r=t[0].y;return t.forEach(t=>{e=Math.min(e,t.x),i=Math.max(i,t.x),s=Math.min(s,t.y),r=Math.max(r,t.y)}),{x:e,y:s,width:i-e,height:r-s}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}Qi.prototype.className="RegularPolygon",Qi.prototype._centroid=!0,Qi.prototype._attrsAffectingSize=["radius"],Tt(Qi),ae.addGetterSetter(Qi,"radius",0,$t()),ae.addGetterSetter(Qi,"sides",0,$t()),ae.addGetterSetter(Qi,"cornerRadius",0,Qt(4));const ts=2*Math.PI;class es extends ui{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,ts,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),ts,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)}}es.prototype.className="Ring",es.prototype._centroid=!0,es.prototype._attrsAffectingSize=["innerRadius","outerRadius"],Tt(es),ae.addGetterSetter(es,"innerRadius",0,$t()),ae.addGetterSetter(es,"outerRadius",0,$t());class is extends ui{constructor(t){super(t),this._updated=!0,this.anim=new yi(()=>{const t=this._updated;return this._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,r=this.animations()[e],n=this.frameOffsets(),a=r[s+0],o=r[s+1],h=r[s+2],l=r[s+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(n){const s=n[e],r=2*i;t.drawImage(d,a,o,h,l,s[r+0],s[r+1],h,l)}else t.drawImage(d,a,o,h,l,0,0,h,l)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,r=this.animations()[e],n=this.frameOffsets(),a=r[s+2],o=r[s+3];if(t.beginPath(),n){const s=n[e],r=2*i;t.rect(s[r+0],s[r+1],a,o)}else t.rect(0,0,a,o);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)}}is.prototype.className="Sprite",Tt(is),ae.addGetterSetter(is,"animation"),ae.addGetterSetter(is,"animations"),ae.addGetterSetter(is,"frameOffsets"),ae.addGetterSetter(is,"image"),ae.addGetterSetter(is,"frameIndex",0,$t()),ae.addGetterSetter(is,"frameRate",17,$t()),ae.backCompat(is,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class ss extends ui{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let r=1;r<2*s;r++){const n=r%2==0?i:e,a=n*Math.sin(r*Math.PI/s),o=-1*n*Math.cos(r*Math.PI/s);t.lineTo(a,o)}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 rs(t){return[...t].reduce((t,e,i,s)=>{if(/\p{Emoji}/u.test(e)){const r=s[i+1];r&&/\p{Emoji_Modifier}|\u200D/u.test(r)?(t.push(e+r),s[i+1]=""):t.push(e)}else/\p{Regional_Indicator}{2}/u.test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}ss.prototype.className="Star",ss.prototype._centroid=!0,ss.prototype._attrsAffectingSize=["innerRadius","outerRadius"],Tt(ss),ae.addGetterSetter(ss,"numPoints",5,$t()),ae.addGetterSetter(ss,"innerRadius",0,$t()),ae.addGetterSetter(ss,"outerRadius",0,$t());const ns="auto",as="inherit",os="justify",hs="left",ls="middle",ds="normal",cs=" ",us="none",gs=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],ps=gs.length;let ms;function fs(){return ms||(ms=Gt.createCanvasElement().getContext("2d"),ms)}class _s extends ui{constructor(t){super(function(t){return(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||t.fillPatternImage||(t.fill=t.fill||"black"),t}(t)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<ps;t++)this.on(gs[t]+"Change.konva",this._setTextData);this._setTextData()}_sceneFunc(t){var e,i;const s=this.textArr,r=s.length;if(!this.text())return;let n,a=this.padding(),o=this.fontSize(),h=this.lineHeight()*o,l=this.verticalAlign(),d=this.direction(),c=0,u=this.align(),g=this.getWidth(),p=this.letterSpacing(),m=this.charRenderFunc(),f=this.fill(),_=this.textDecoration(),v=-1!==_.indexOf("underline"),y=-1!==_.indexOf("line-through");d=d===as?t.direction:d;let w=h/2,x=ls;if(!At.legacyTextRendering){const t=this.measureSize("M");x="alphabetic";w=((null!==(e=t.fontBoundingBoxAscent)&&void 0!==e?e:t.actualBoundingBoxAscent)-(null!==(i=t.fontBoundingBoxDescent)&&void 0!==i?i:t.actualBoundingBoxDescent))/2+h/2}for("rtl"===d&&t.setAttr("direction",d),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",x),t.setAttr("textAlign",hs),l===ls?c=(this.getHeight()-r*h-2*a)/2:"bottom"===l&&(c=this.getHeight()-r*h-2*a),t.translate(a,c+a),n=0;n<r;n++){let e=0,i=0;const l=s[n],c=l.text,_=l.width,x=l.lastInParagraph;if(t.save(),"right"===u?e+=g-_-2*a:"center"===u&&(e+=(g-_-2*a)/2),v){t.save(),t.beginPath();const s=e,r=w+i+(At.legacyTextRendering?Math.round(o/2):Math.round(o/4));t.moveTo(s,r);const n=u!==os||x?_:g-2*a;t.lineTo(s+Math.round(n),r),t.lineWidth=o/15;const h=this._getLinearGradient();t.strokeStyle=h||f,t.stroke(),t.restore()}const b=e;if("rtl"===d||0===p&&u!==os&&!m)0!==p&&t.setAttr("letterSpacing",`${p}px`),this._partialTextX=e,this._partialTextY=w+i,this._partialText=c,t.fillStrokeShape(this);else{const r=c.split(" ").length-1,o=rs(c);for(let h=0;h<o.length;h++){const l=o[h];if(" "!==l||x||u!==os||(e+=(g-2*a-_)/r),this._partialTextX=e,this._partialTextY=w+i,this._partialText=l,m){t.save();m({char:l,index:h+s.slice(0,n).reduce((t,e)=>t+rs(e.text).length,0),x:e,y:w+i,lineIndex:n,column:h,isLastInLine:x,width:this.measureSize(l).width,context:t})}t.fillStrokeShape(this),m&&t.restore(),e+=this.measureSize(l).width+p}}if(y){t.save(),t.beginPath();const e=At.legacyTextRendering?0:-Math.round(o/4),s=b;t.moveTo(s,w+i+e);const r=u!==os||x?_:g-2*a;t.lineTo(s+Math.round(r),w+i+e),t.lineWidth=o/15;const n=this._getLinearGradient();t.strokeStyle=n||f,t.stroke(),t.restore()}t.restore(),r>1&&(w+=h)}}_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=Gt._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===ns||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===ns||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return Gt.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i,s,r,n,a,o,h,l,d,c;let u,g=fs(),p=this.fontSize();g.save(),g.font=this._getContextFont(),u=g.measureText(t),g.restore();const m=p/100;return{actualBoundingBoxAscent:null!==(e=u.actualBoundingBoxAscent)&&void 0!==e?e:71.58203125*m,actualBoundingBoxDescent:null!==(i=u.actualBoundingBoxDescent)&&void 0!==i?i:0,actualBoundingBoxLeft:null!==(s=u.actualBoundingBoxLeft)&&void 0!==s?s:-7.421875*m,actualBoundingBoxRight:null!==(r=u.actualBoundingBoxRight)&&void 0!==r?r:75.732421875*m,alphabeticBaseline:null!==(n=u.alphabeticBaseline)&&void 0!==n?n:0,emHeightAscent:null!==(a=u.emHeightAscent)&&void 0!==a?a:100*m,emHeightDescent:null!==(o=u.emHeightDescent)&&void 0!==o?o:-20*m,fontBoundingBoxAscent:null!==(h=u.fontBoundingBoxAscent)&&void 0!==h?h:91*m,fontBoundingBoxDescent:null!==(l=u.fontBoundingBoxDescent)&&void 0!==l?l:21*m,hangingBaseline:null!==(d=u.hangingBaseline)&&void 0!==d?d:72.80000305175781*m,ideographicBaseline:null!==(c=u.ideographicBaseline)&&void 0!==c?c:-21*m,width:u.width,height:p}}_getContextFont(){return this.fontStyle()+cs+this.fontVariant()+cs+(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()===os&&(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 fs().measureText(t).width+e*i}_setTextData(){let t=this.text().split("\n"),e=+this.fontSize(),i=0,s=this.lineHeight()*e,r=this.attrs.width,n=this.attrs.height,a=r!==ns&&void 0!==r,o=n!==ns&&void 0!==n,h=this.padding(),l=r-2*h,d=n-2*h,c=0,u=this.wrap(),g="char"!==u&&u!==us,p=this.ellipsis();this.textArr=[],fs().font=this._getContextFont();const m=p?this._getTextWidth("…"):0;for(let e=0,r=t.length;e<r;++e){let n=t[e],h=this._getTextWidth(n);if(a&&h>l)for(;n.length>0;){let t=0,e=rs(n).length,r="",a=0;for(;t<e;){const i=t+e>>>1,h=rs(n).slice(0,i+1).join(""),u=this._getTextWidth(h);(p&&o&&c+s>d?u+m:u)<=l?(t=i+1,r=h,a=u):e=i}if(!r)break;if(g){const e=rs(n),i=rs(r),s=e[i.length];let o;if((s===cs||"-"===s)&&a<=l)o=i.length;else{const t=i.lastIndexOf(cs),e=i.lastIndexOf("-");o=Math.max(t,e)+1}o>0&&(t=o,r=e.slice(0,t).join(""),a=this._getTextWidth(r))}r=r.trimRight(),this._addTextLine(r),i=Math.max(i,a),c+=s;if(this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if(n=rs(n).slice(t).join("").trimLeft(),n.length>0&&(h=this._getTextWidth(n),h<=l)){this._addTextLine(n),c+=s,i=Math.max(i,h);break}}else this._addTextLine(n),c+=s,i=Math.max(i,h),this._shouldHandleEllipsis(c)&&e<r-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),o&&c+s>d)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,r=s!==ns&&void 0!==s,n=s-2*this.padding();return!(this.wrap()!==us)||r&&t+i>n}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==ns&&void 0!==t,i=t-2*this.padding(),s=this.ellipsis(),r=this.textArr[this.textArr.length-1];if(r&&s){if(e){this._getTextWidth(r.text+"…")<i||(r.text=r.text.slice(0,r.text.length-3))}this.textArr.splice(this.textArr.length-1,1),this._addTextLine(r.text+"…")}}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=-1!==this.textDecoration().indexOf("underline")||-1!==this.textDecoration().indexOf("line-through"),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas()}}_s.prototype._fillFunc=function(t){t.fillText(this._partialText,this._partialTextX,this._partialTextY)},_s.prototype._strokeFunc=function(t){t.setAttr("miterLimit",2),t.strokeText(this._partialText,this._partialTextX,this._partialTextY)},_s.prototype.className="Text",_s.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],Tt(_s),ae.overWriteSetter(_s,"width",te()),ae.overWriteSetter(_s,"height",te()),ae.addGetterSetter(_s,"direction",as),ae.addGetterSetter(_s,"fontFamily","Arial"),ae.addGetterSetter(_s,"fontSize",12,$t()),ae.addGetterSetter(_s,"fontStyle",ds),ae.addGetterSetter(_s,"fontVariant",ds),ae.addGetterSetter(_s,"padding",0,$t()),ae.addGetterSetter(_s,"align",hs),ae.addGetterSetter(_s,"verticalAlign","top"),ae.addGetterSetter(_s,"lineHeight",1,$t()),ae.addGetterSetter(_s,"wrap","word"),ae.addGetterSetter(_s,"ellipsis",!1,se()),ae.addGetterSetter(_s,"letterSpacing",0,$t()),ae.addGetterSetter(_s,"text","",ee()),ae.addGetterSetter(_s,"textDecoration",""),ae.addGetterSetter(_s,"charRenderFunc",void 0);const vs="normal";function ys(t){t.fillText(this.partialText,0,0)}function ws(t){t.strokeText(this.partialText,0,0)}class xs extends ui{constructor(t){super(t),this.dummyCanvas=Gt.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 Vi.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;return t>this.pathLength?null:Vi.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=Vi.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.textBaseline()),t.setAttr("textAlign","left"),t.save();const e=this.textDecoration(),i=this.fill(),s=this.fontSize(),r=this.glyphInfo,n=-1!==e.indexOf("underline"),a=-1!==e.indexOf("line-through");n&&t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),this.partialText=r[e].text,t.fillStrokeShape(this),n&&(0===e&&t.moveTo(0,s/2+1),t.lineTo(r[e].width,s/2+1)),t.restore()}if(n&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),a){t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),0===e&&t.moveTo(0,0),t.lineTo(r[e].width,0),t.restore()}t.strokeStyle=i,t.lineWidth=s/20,t.stroke()}t.restore()}_hitFunc(t){t.beginPath();const e=this.glyphInfo;if(e.length>=1){const i=e[0].p0;t.moveTo(i.x,i.y)}for(let i=0;i<e.length;i++){const s=e[i].p1;t.lineTo(s.x,s.y)}t.setAttr("lineWidth",this.fontSize()),t.setAttr("strokeStyle",this.colorKey),t.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return Gt.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(t){return _s.prototype.setText.call(this,t)}_getContextFont(){return _s.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=rs(this.text()),e=[];let i=0;for(let s=0;s<t.length;s++)e.push({char:t[s],width:this._getTextSize(t[s]).width}),i+=e[s].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const r=this.letterSpacing(),n=this.align(),a=this.kerningFunc(),o=Math.max(this.textWidth+((this.attrs.text||"").length-1)*r,0);let h=0;"center"===n&&(h=Math.max(0,this.pathLength/2-o/2)),"right"===n&&(h=Math.max(0,this.pathLength-o));let l=h;for(let i=0;i<e.length;i++){const s=this._getPointAtLength(l);if(!s)return;const h=e[i].char;let d=e[i].width+r;if(" "===h&&"justify"===n){const t=this.text().split(" ").length-1;d+=(this.pathLength-o)/t}const c=this._getPointAtLength(l+d);if(!c)return;const u=Vi.getLineLength(s.x,s.y,c.x,c.y);let g=0;if(a)try{g=a(e[i-1].char,h)*this.fontSize()}catch(t){g=0}s.x+=g,c.x+=g,this.textWidth+=g;const p=Vi.getPointOnLine(g+u/2,s.x,s.y,c.x,c.y),m=Math.atan2(c.y-s.y,c.x-s.x);this.glyphInfo.push({transposeX:p.x,transposeY:p.y,text:t[i],rotation:m,p0:s,p1:c,width:u}),l+=d}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(e){t.push(e.p0.x),t.push(e.p0.y),t.push(e.p1.x),t.push(e.p1.y)});let e,i,s=t[0]||0,r=t[0]||0,n=t[1]||0,a=t[1]||0;for(let o=0;o<t.length/2;o++)e=t[2*o],i=t[2*o+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),a=Math.max(a,i);const o=this.fontSize();return{x:s-o/2,y:n-o/2,width:r-s+o,height:a-n+o}}destroy(){return Gt.releaseCanvas(this.dummyCanvas),super.destroy()}}xs.prototype._fillFunc=ys,xs.prototype._strokeFunc=ws,xs.prototype._fillFuncHit=ys,xs.prototype._strokeFuncHit=ws,xs.prototype.className="TextPath",xs.prototype._attrsAffectingSize=["text","fontSize","data"],Tt(xs),ae.addGetterSetter(xs,"data"),ae.addGetterSetter(xs,"fontFamily","Arial"),ae.addGetterSetter(xs,"fontSize",12,$t()),ae.addGetterSetter(xs,"fontStyle",vs),ae.addGetterSetter(xs,"align","left"),ae.addGetterSetter(xs,"letterSpacing",0,$t()),ae.addGetterSetter(xs,"textBaseline","middle"),ae.addGetterSetter(xs,"fontVariant",vs),ae.addGetterSetter(xs,"text",""),ae.addGetterSetter(xs,"textDecoration",""),ae.addGetterSetter(xs,"kerningFunc",void 0);const bs="tr-konva",Ss=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(t=>t+`.${bs}`).join(" "),Cs="nodesRect",As=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],Ts={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},Ps="ontouchstart"in At._global;const ks=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function Es(t,e,i){const s=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),r=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return{...t,rotation:t.rotation+e,x:s,y:r}}function Ms(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 Es(t,e,i)}let Is=0;class Rs extends _i{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(Ss,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return Gt.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 bs+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(t=>!t.isAncestorOf(this)||(Gt.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(As.map(t=>t+`.${this._getEventNamespace()}`).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)}),this._resetTransformCache();return!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,i=>{e=t.getAbsolutePosition(),this.isDragging()||t===this.findOne(".back")||this.startDrag(i,!1)}),t.on(`dragmove.${this._getEventNamespace()}`,i=>{if(!e)return;const s=t.getAbsolutePosition(),r=s.x-e.x,n=s.y-e.y;this.nodes().forEach(e=>{if(e===t)return;if(e.isDragging())return;const s=e.getAbsolutePosition();e.setAbsolutePosition({x:s.x+r,y:s.y+n}),e.startDrag(i)}),e=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(t=>{t.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(Cs),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(Cs,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),i){const s=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),r=t.getAbsoluteScale(i),n=t.getAbsolutePosition(i),a=s.x*r.x-t.offsetX()*r.x,o=s.y*r.y-t.offsetY()*r.y,h=(At.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return Es({x:n.x+a*Math.cos(h)+o*Math.sin(-h),y:n.y+o*Math.cos(h)+a*Math.sin(h),width:s.width*r.x,height:s.height*r.y,rotation:h},-At.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map(e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),s=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],r=e.getAbsoluteTransform();s.forEach(function(e){const i=r.point(e);t.push(i)})});const e=new kt;e.rotate(-At.getAngle(this.rotation()));let i=1/0,s=1/0,r=-1/0,n=-1/0;t.forEach(function(t){const a=e.point(t);void 0===i&&(i=r=a.x,s=n=a.y),i=Math.min(i,a.x),s=Math.min(s,a.y),r=Math.max(r,a.x),n=Math.max(n,a.y)}),e.invert();const a=e.point({x:i,y:s});return{x:a.x,y:a.y,width:r-i,height:n-s,rotation:At.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(),ks.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new $i({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:Ps?10:"auto"}),i=this;e.on("mousedown touchstart",function(t){i._handleMouseDown(t)}),e.on("dragstart",t=>{e.stopDrag(),t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),e.on("mouseenter",()=>{const i=At.getAngle(this.rotation()),s=this.rotateAnchorCursor(),r=function(t,e,i){if("rotater"===t)return i;e+=Gt.degToRad(Ts[t]||0);const s=(Gt.radToDeg(e)%360+360)%360;return Gt._inRange(s,337.5,360)||Gt._inRange(s,0,22.5)?"ns-resize":Gt._inRange(s,22.5,67.5)?"nesw-resize":Gt._inRange(s,67.5,112.5)?"ew-resize":Gt._inRange(s,112.5,157.5)?"nwse-resize":Gt._inRange(s,157.5,202.5)?"ns-resize":Gt._inRange(s,202.5,247.5)?"nesw-resize":Gt._inRange(s,247.5,292.5)?"ew-resize":Gt._inRange(s,292.5,337.5)?"nwse-resize":(Gt.error("Transformer has unknown angle for cursor detection: "+s),"pointer")}(t,i,s);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 ui({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()*Gt._sign(e.height())-s),t.fillStrokeShape(e)},hitFunc:(t,e)=>{if(!this.shouldOverdrawWholeArea())return;const i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}});this.add(t),this._proxyDrag(t),t.on("dragstart",t=>{t.cancelBubble=!0}),t.on("dragmove",t=>{t.cancelBubble=!0}),t.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{this.update()})}_handleMouseDown(t){if(this._transforming)return;this._movingAnchorName=t.target.name().split(" ")[0];const e=this._getNodeRect(),i=e.width,s=e.height,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/r),this.cos=Math.abs(i/r),"undefined"!=typeof window&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const n=t.target.getAbsolutePosition(),a=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:a.x-n.x,y:a.y-n.y},Is++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(e=>{e._fire("transformstart",{evt:t.evt,target:e})})}_handleMouseMove(t){let e,i,s;const r=this.findOne("."+this._movingAnchorName),n=r.getStage();n.setPointersPositions(t);const a=n.getPointerPosition();let o={x:a.x-this._anchorDragOffset.x,y:a.y-this._anchorDragOffset.y};const h=r.getAbsolutePosition();this.anchorDragBoundFunc()&&(o=this.anchorDragBoundFunc()(h,o,t)),r.setAbsolutePosition(o);const l=r.getAbsolutePosition();if(h.x===l.x&&h.y===l.y)return;if("rotater"===this._movingAnchorName){const s=this._getNodeRect();e=r.x()-s.width/2,i=-r.y()+s.height/2;let n=Math.atan2(-i,e)+Math.PI/2;s.height<0&&(n-=Math.PI);const a=At.getAngle(this.rotation())+n,o=At.getAngle(this.rotationSnapTolerance()),h=function(t,e,i){let s=e;for(let r=0;r<t.length;r++){const n=At.getAngle(t[r]),a=Math.abs(n-e)%(2*Math.PI);Math.min(a,2*Math.PI-a)<i&&(s=n)}return s}(this.rotationSnaps(),a,o),l=Ms(s,h-s.rotation);return void this._fitNodesInto(l,t)}const d=this.shiftBehavior();let c;c="inverted"===d?this.keepRatio()&&!t.shiftKey:"none"===d?this.keepRatio():this.keepRatio()||t.shiftKey;let u=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};s=Math.sqrt(Math.pow(t.x-r.x(),2)+Math.pow(t.y-r.y(),2));const n=this.findOne(".top-left").x()>t.x?-1:1,a=this.findOne(".top-left").y()>t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,this.findOne(".top-left").x(t.x-e),this.findOne(".top-left").y(t.y-i)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(r.y());else if("top-right"===this._movingAnchorName){if(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};s=Math.sqrt(Math.pow(r.x()-t.x,2)+Math.pow(t.y-r.y(),2));const n=this.findOne(".top-right").x()<t.x?-1:1,a=this.findOne(".top-right").y()>t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,this.findOne(".top-right").x(t.x+e),this.findOne(".top-right").y(t.y-i)}var g=r.position();this.findOne(".top-left").y(g.y),this.findOne(".bottom-right").x(g.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(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};s=Math.sqrt(Math.pow(t.x-r.x(),2)+Math.pow(r.y()-t.y,2));const n=t.x<r.x()?-1:1,a=r.y()<t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,r.x(t.x-e),r.y(t.y+i)}g=r.position(),this.findOne(".top-left").x(g.x),this.findOne(".bottom-right").y(g.y)}else if("bottom-center"===this._movingAnchorName)this.findOne(".bottom-right").y(r.y());else if("bottom-right"===this._movingAnchorName){if(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};s=Math.sqrt(Math.pow(r.x()-t.x,2)+Math.pow(r.y()-t.y,2));const n=this.findOne(".bottom-right").x()<t.x?-1:1,a=this.findOne(".bottom-right").y()<t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,this.findOne(".bottom-right").x(t.x+e),this.findOne(".bottom-right").y(t.y+i)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(u=this.centeredScaling()||t.altKey,u){const t=this.findOne(".top-left"),e=this.findOne(".bottom-right"),i=t.x(),s=t.y(),r=this.getWidth()-e.x(),n=this.getHeight()-e.y();e.move({x:-i,y:-s}),t.move({x:r,y:n})}const p=this.findOne(".top-left").getAbsolutePosition();e=p.x,i=p.y;const m=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),f=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:i,width:m,height:f,rotation:At.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();Is--,this._fire("transformend",{evt:t,target:i}),null===(e=this.getLayer())||void 0===e||e.batchDraw(),i&&this._nodes.forEach(e=>{var i;e._fire("transformend",{evt:t,target:e}),null===(i=e.getLayer())||void 0===i||i.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const i=this._getNodeRect();if(Gt._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(Gt._inRange(t.height,2*-this.padding()-1,1))return void this.update();const s=new kt;if(s.rotate(At.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=s.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=s.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=s.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=s.point({x:0,y:2*this.padding()});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(i,t);e?t=e:Gt.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const r=1e7,n=new kt;n.translate(i.x,i.y),n.rotate(i.rotation),n.scale(i.width/r,i.height/r);const a=new kt,o=t.width/r,h=t.height/r;!1===this.flipEnabled()?(a.translate(t.x,t.y),a.rotate(t.rotation),a.translate(t.width<0?t.width:0,t.height<0?t.height:0),a.scale(Math.abs(o),Math.abs(h))):(a.translate(t.x,t.y),a.rotate(t.rotation),a.scale(o,h));const l=a.multiply(n.invert());this._nodes.forEach(t=>{var e;if(!t.getStage())return;const i=t.getParent().getAbsoluteTransform(),s=t.getTransform().copy();s.translate(t.offsetX(),t.offsetY());const r=new kt;r.multiply(i.copy().invert()).multiply(l).multiply(i).multiply(s);const n=r.decompose();t.setAttrs(n),null===(e=t.getLayer())||void 0===e||e.batchDraw()}),this.rotation(Gt._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(Gt._getRotation(e.rotation));const i=e.width,s=e.height,r=this.enabledAnchors(),n=this.resizeEnabled(),a=this.padding(),o=this.anchorSize(),h=this.find("._anchor");h.forEach(t=>{t.setAttrs({width:o,height:o,offsetX:o/2,offsetY:o/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:o/2+a,offsetY:o/2+a,visible:n&&r.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:o/2+a,visible:n&&r.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:o/2-a,offsetY:o/2+a,visible:n&&r.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:o/2+a,visible:n&&r.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:o/2-a,visible:n&&r.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:o/2+a,offsetY:o/2-a,visible:n&&r.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:o/2-a,visible:n&&r.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:o/2-a,offsetY:o/2-a,visible:n&&r.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*Gt._sign(s)-a,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=""),_i.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return xe.prototype.toObject.call(this)}clone(t){return xe.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}Rs.isTransforming=()=>Is>0,Rs.prototype.className="Transformer",Tt(Rs),ae.addGetterSetter(Rs,"enabledAnchors",ks,function(t){return t instanceof Array||Gt.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach(function(t){-1===ks.indexOf(t)&&Gt.warn("Unknown anchor name: "+t+". Available names are: "+ks.join(", "))}),t||[]}),ae.addGetterSetter(Rs,"flipEnabled",!0,se()),ae.addGetterSetter(Rs,"resizeEnabled",!0),ae.addGetterSetter(Rs,"anchorSize",10,$t()),ae.addGetterSetter(Rs,"rotateEnabled",!0),ae.addGetterSetter(Rs,"rotateLineVisible",!0),ae.addGetterSetter(Rs,"rotationSnaps",[]),ae.addGetterSetter(Rs,"rotateAnchorOffset",50,$t()),ae.addGetterSetter(Rs,"rotateAnchorCursor","crosshair"),ae.addGetterSetter(Rs,"rotationSnapTolerance",5,$t()),ae.addGetterSetter(Rs,"borderEnabled",!0),ae.addGetterSetter(Rs,"anchorStroke","rgb(0, 161, 255)"),ae.addGetterSetter(Rs,"anchorStrokeWidth",1,$t()),ae.addGetterSetter(Rs,"anchorFill","white"),ae.addGetterSetter(Rs,"anchorCornerRadius",0,$t()),ae.addGetterSetter(Rs,"borderStroke","rgb(0, 161, 255)"),ae.addGetterSetter(Rs,"borderStrokeWidth",1,$t()),ae.addGetterSetter(Rs,"borderDash"),ae.addGetterSetter(Rs,"keepRatio",!0),ae.addGetterSetter(Rs,"shiftBehavior","default"),ae.addGetterSetter(Rs,"centeredScaling",!1),ae.addGetterSetter(Rs,"ignoreStroke",!1),ae.addGetterSetter(Rs,"padding",0,$t()),ae.addGetterSetter(Rs,"nodes"),ae.addGetterSetter(Rs,"node"),ae.addGetterSetter(Rs,"boundBoxFunc"),ae.addGetterSetter(Rs,"anchorDragBoundFunc"),ae.addGetterSetter(Rs,"anchorStyleFunc"),ae.addGetterSetter(Rs,"shouldOverdrawWholeArea",!1),ae.addGetterSetter(Rs,"useSingleNodeRotation",!0),ae.backCompat(Rs,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class Ds extends ui{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,At.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 Ls(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}Ds.prototype.className="Wedge",Ds.prototype._centroid=!0,Ds.prototype._attrsAffectingSize=["radius"],Tt(Ds),ae.addGetterSetter(Ds,"radius",0,$t()),ae.addGetterSetter(Ds,"angle",0,$t()),ae.addGetterSetter(Ds,"clockwise",!1),ae.backCompat(Ds,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});const Os=[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],zs=[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];ae.addGetterSetter(xe,"blurRadius",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"brightness",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"contrast",0,$t(),ae.afterSetFilter);function Fs(t,e,i,s,r){const n=i-e,a=r-s;if(0===n)return s+a/2;if(0===a)return s;let o=(t-e)/n;return o=a*o+s,o}ae.addGetterSetter(xe,"embossStrength",.5,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"embossWhiteLevel",.5,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"embossDirection","top-left",void 0,ae.afterSetFilter),ae.addGetterSetter(xe,"embossBlend",!1,void 0,ae.afterSetFilter);ae.addGetterSetter(xe,"enhance",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"hue",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"saturation",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"luminance",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"hue",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"saturation",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"value",0,$t(),ae.afterSetFilter);function Gs(t,e,i){let s=4*(i*t.width+e);const r=[];return r.push(t.data[s++],t.data[s++],t.data[s++],t.data[s++]),r}function Vs(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))}ae.addGetterSetter(xe,"kaleidoscopePower",2,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"kaleidoscopeAngle",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"threshold",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"noise",.2,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"pixelSize",8,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"levels",.5,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"blue",0,Zt,ae.afterSetFilter);ae.addGetterSetter(xe,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"blue",0,Zt,ae.afterSetFilter),ae.addGetterSetter(xe,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t});ae.addGetterSetter(xe,"threshold",.5,$t(),ae.afterSetFilter);const Ws=Ti.Util._assign(Ti,{Arc:Pi,Arrow:Wi,Circle:Bi,Ellipse:Ni,Image:ji,Label:Ki,Tag:Zi,Line:Mi,Path:Vi,Rect:$i,RegularPolygon:Qi,Ring:es,Sprite:is,Star:ss,Text:_s,TextPath:xs,Transformer:Rs,Wedge:Ds,Filters:{Blur:function(t){const e=Math.round(this.blurRadius());e>0&&function(t,e){const i=t.data,s=t.width,r=t.height;let n,a,o,h,l,d,c,u,g,p,m,f,_,v,y,w,x,b,S,C;const A=e+e+1,T=s-1,P=r-1,k=e+1,E=k*(k+1)/2,M=new Ls,I=Os[e],R=zs[e];let D=null,L=M,O=null,z=null;for(let t=1;t<A;t++)L=L.next=new Ls,t===k&&(D=L);L.next=M,o=a=0;for(let t=0;t<r;t++){f=_=v=y=h=l=d=c=0,u=k*(w=i[a]),g=k*(x=i[a+1]),p=k*(b=i[a+2]),m=k*(S=i[a+3]),h+=E*w,l+=E*x,d+=E*b,c+=E*S,L=M;for(let t=0;t<k;t++)L.r=w,L.g=x,L.b=b,L.a=S,L=L.next;for(let t=1;t<k;t++)n=a+((T<t?T:t)<<2),h+=(L.r=w=i[n])*(C=k-t),l+=(L.g=x=i[n+1])*C,d+=(L.b=b=i[n+2])*C,c+=(L.a=S=i[n+3])*C,f+=w,_+=x,v+=b,y+=S,L=L.next;O=M,z=D;for(let t=0;t<s;t++)i[a+3]=S=c*I>>R,0!==S?(S=255/S,i[a]=(h*I>>R)*S,i[a+1]=(l*I>>R)*S,i[a+2]=(d*I>>R)*S):i[a]=i[a+1]=i[a+2]=0,h-=u,l-=g,d-=p,c-=m,u-=O.r,g-=O.g,p-=O.b,m-=O.a,n=o+((n=t+e+1)<T?n:T)<<2,f+=O.r=i[n],_+=O.g=i[n+1],v+=O.b=i[n+2],y+=O.a=i[n+3],h+=f,l+=_,d+=v,c+=y,O=O.next,u+=w=z.r,g+=x=z.g,p+=b=z.b,m+=S=z.a,f-=w,_-=x,v-=b,y-=S,z=z.next,a+=4;o+=s}for(let t=0;t<s;t++){_=v=y=f=l=d=c=h=0,a=t<<2,u=k*(w=i[a]),g=k*(x=i[a+1]),p=k*(b=i[a+2]),m=k*(S=i[a+3]),h+=E*w,l+=E*x,d+=E*b,c+=E*S,L=M;for(let t=0;t<k;t++)L.r=w,L.g=x,L.b=b,L.a=S,L=L.next;let o=s;for(let r=1;r<=e;r++)a=o+t<<2,h+=(L.r=w=i[a])*(C=k-r),l+=(L.g=x=i[a+1])*C,d+=(L.b=b=i[a+2])*C,c+=(L.a=S=i[a+3])*C,f+=w,_+=x,v+=b,y+=S,L=L.next,r<P&&(o+=s);a=t,O=M,z=D;for(let e=0;e<r;e++)n=a<<2,i[n+3]=S=c*I>>R,S>0?(S=255/S,i[n]=(h*I>>R)*S,i[n+1]=(l*I>>R)*S,i[n+2]=(d*I>>R)*S):i[n]=i[n+1]=i[n+2]=0,h-=u,l-=g,d-=p,c-=m,u-=O.r,g-=O.g,p-=O.b,m-=O.a,n=t+((n=e+k)<P?n:P)*s<<2,h+=f+=O.r=i[n],l+=_+=O.g=i[n+1],d+=v+=O.b=i[n+2],c+=y+=O.a=i[n+3],O=O.next,u+=w=z.r,g+=x=z.g,p+=b=z.b,m+=S=z.a,f-=w,_-=x,v-=b,y-=S,z=z.next,a+=s}}(t,e)},Brightness:function(t){const e=this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]=Math.min(255,i[t]*e),i[t+1]=Math.min(255,i[t+1]*e),i[t+2]=Math.min(255,i[t+2]*e)},Brighten:function(t){const e=255*this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]+=e,i[t+1]+=e,i[t+2]+=e},Contrast:function(t){const e=Math.pow((this.contrast()+100)/100,2),i=t.data,s=i.length;let r=150,n=150,a=150;for(let t=0;t<s;t+=4)r=i[t],n=i[t+1],a=i[t+2],r/=255,r-=.5,r*=e,r+=.5,r*=255,n/=255,n-=.5,n*=e,n+=.5,n*=255,a/=255,a-=.5,a*=e,a+=.5,a*=255,r=r<0?0:r>255?255:r,n=n<0?0:n>255?255:n,a=a<0?0:a>255?255:a,i[t]=r,i[t+1]=n,i[t+2]=a},Emboss:function(t){var e,i,s,r,n,a,o,h,l;const d=t.data,c=t.width,u=t.height,g=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)),p=Math.min(1,Math.max(0,null!==(r=null===(s=this.embossWhiteLevel)||void 0===s?void 0:s.call(this))&&void 0!==r?r:.5)),m=null!==(o={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[null!==(a=null===(n=this.embossDirection)||void 0===n?void 0:n.call(this))&&void 0!==a?a:"top-left"])&&void 0!==o?o:315,f=!(null===(l=null===(h=this.embossBlend)||void 0===h?void 0:h.call(this))||void 0===l||!l),_=10*g,v=255*p,y=m*Math.PI/180,w=Math.cos(y),x=Math.sin(y),b=128/1020*_,S=new Uint8ClampedArray(d),C=new Float32Array(c*u);for(let t=0,e=0;e<d.length;e+=4,t++)C[t]=.2126*S[e]+.7152*S[e+1]+.0722*S[e+2];const A=[-1,0,1,-2,0,2,-1,0,1],T=[-1,-2,-1,0,0,0,1,2,1],P=[-c-1,-c,1-c,-1,0,1,c-1,c,c+1],k=t=>t<0?0:t>255?255:t;for(let t=1;t<u-1;t++)for(let e=1;e<c-1;e++){const i=t*c+e;let s=0,r=0;s+=C[i+P[0]]*A[0],r+=C[i+P[0]]*T[0],s+=C[i+P[1]]*A[1],r+=C[i+P[1]]*T[1],s+=C[i+P[2]]*A[2],r+=C[i+P[2]]*T[2],s+=C[i+P[3]]*A[3],r+=C[i+P[3]]*T[3],s+=C[i+P[5]]*A[5],r+=C[i+P[5]]*T[5],s+=C[i+P[6]]*A[6],r+=C[i+P[6]]*T[6],s+=C[i+P[7]]*A[7],r+=C[i+P[7]]*T[7],s+=C[i+P[8]]*A[8],r+=C[i+P[8]]*T[8];const n=k(v+(w*s+x*r)*b),a=4*i;if(f){const t=n-v;d[a]=k(S[a]+t),d[a+1]=k(S[a+1]+t),d[a+2]=k(S[a+2]+t),d[a+3]=S[a+3]}else d[a]=d[a+1]=d[a+2]=n,d[a+3]=S[a+3]}for(let t=0;t<c;t++){let e=4*t,i=4*((u-1)*c+t);d[e]=S[e],d[e+1]=S[e+1],d[e+2]=S[e+2],d[e+3]=S[e+3],d[i]=S[i],d[i+1]=S[i+1],d[i+2]=S[i+2],d[i+3]=S[i+3]}for(let t=1;t<u-1;t++){let e=t*c*4,i=4*(t*c+(c-1));d[e]=S[e],d[e+1]=S[e+1],d[e+2]=S[e+2],d[e+3]=S[e+3],d[i]=S[i],d[i+1]=S[i+1],d[i+2]=S[i+2],d[i+3]=S[i+3]}return t},Enhance:function(t){const e=t.data,i=e.length;let s,r,n,a=e[0],o=a,h=e[1],l=h,d=e[2],c=d;const u=this.enhance();if(0===u)return;for(let t=0;t<i;t+=4)s=e[t+0],s<a?a=s:s>o&&(o=s),r=e[t+1],r<h?h=r:r>l&&(l=r),n=e[t+2],n<d?d=n:n>c&&(c=n);let g,p,m,f,_,v;if(o===a&&(o=255,a=0),l===h&&(l=255,h=0),c===d&&(c=255,d=0),u>0)g=o+u*(255-o),p=a-u*(a-0),m=l+u*(255-l),f=h-u*(h-0),_=c+u*(255-c),v=d-u*(d-0);else{const t=.5*(o+a);g=o+u*(o-t),p=a+u*(a-t);const e=.5*(l+h);m=l+u*(l-e),f=h+u*(h-e);const i=.5*(c+d);_=c+u*(c-i),v=d+u*(d-i)}for(let t=0;t<i;t+=4)e[t+0]=Fs(e[t+0],a,o,p,g),e[t+1]=Fs(e[t+1],h,l,f,m),e[t+2]=Fs(e[t+2],d,c,v,_)},Grayscale:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=.34*e[t]+.5*e[t+1]+.16*e[t+2];e[t]=i,e[t+1]=i,e[t+2]=i}},HSL:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.saturation()),r=Math.abs(this.hue()+360)%360,n=127*this.luminance(),a=1*s*Math.cos(r*Math.PI/180),o=1*s*Math.sin(r*Math.PI/180),h=.299+.701*a+.167*o,l=.587-.587*a+.33*o,d=.114-.114*a-.497*o,c=.299-.299*a-.328*o,u=.587+.413*a+.035*o,g=.114-.114*a+.293*o,p=.299-.3*a+1.25*o,m=.587-.586*a-1.05*o,f=.114+.886*a-.2*o;let _,v,y,w;for(let t=0;t<i;t+=4)_=e[t+0],v=e[t+1],y=e[t+2],w=e[t+3],e[t+0]=h*_+l*v+d*y+n,e[t+1]=c*_+u*v+g*y+n,e[t+2]=p*_+m*v+f*y+n,e[t+3]=w},HSV:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.value()),r=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,a=s*r*Math.cos(n*Math.PI/180),o=s*r*Math.sin(n*Math.PI/180),h=.299*s+.701*a+.167*o,l=.587*s-.587*a+.33*o,d=.114*s-.114*a-.497*o,c=.299*s-.299*a-.328*o,u=.587*s+.413*a+.035*o,g=.114*s-.114*a+.293*o,p=.299*s-.3*a+1.25*o,m=.587*s-.586*a-1.05*o,f=.114*s+.886*a-.2*o;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2],n=e[t+3];e[t+0]=h*i+l*s+d*r,e[t+1]=c*i+u*s+g*r,e[t+2]=p*i+m*s+f*r,e[t+3]=n}},Invert:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},Kaleidoscope:function(t){const e=t.width,i=t.height;let s,r,n,a,o,h,l,d,c,u,g=Math.round(this.kaleidoscopePower());const p=Math.round(this.kaleidoscopeAngle()),m=Math.floor(e*(p%360)/360);if(g<1)return;const f=Gt.createCanvasElement();f.width=e,f.height=i;const _=f.getContext("2d").getImageData(0,0,e,i);Gt.releaseCanvas(f),function(t,e,i){const s=t.data,r=e.data,n=t.width,a=t.height,o=i.polarCenterX||n/2,h=i.polarCenterY||a/2;let l=Math.sqrt(o*o+h*h),d=n-o,c=a-h;const u=Math.sqrt(d*d+c*c);l=u>l?u:l;const g=a,p=n,m=360/p*Math.PI/180;for(let t=0;t<p;t+=1){const e=Math.sin(t*m),i=Math.cos(t*m);for(let a=0;a<g;a+=1){d=Math.floor(o+l*a/g*i),c=Math.floor(h+l*a/g*e);let u=4*(c*n+d);const p=s[u+0],m=s[u+1],f=s[u+2],_=s[u+3];u=4*(t+a*n),r[u+0]=p,r[u+1]=m,r[u+2]=f,r[u+3]=_}}}(t,_,{polarCenterX:e/2,polarCenterY:i/2});let v=e/Math.pow(2,g);for(;v<=8;)v*=2,g-=1;v=Math.ceil(v);let y=v,w=0,x=y,b=1;for(m+v>e&&(w=y,x=0,b=-1),r=0;r<i;r+=1)for(s=w;s!==x;s+=b)n=Math.round(s+m)%e,c=4*(e*r+n),o=_.data[c+0],h=_.data[c+1],l=_.data[c+2],d=_.data[c+3],u=4*(e*r+s),_.data[u+0]=o,_.data[u+1]=h,_.data[u+2]=l,_.data[u+3]=d;for(r=0;r<i;r+=1)for(y=Math.floor(v),a=0;a<g;a+=1){for(s=0;s<y+1;s+=1)c=4*(e*r+s),o=_.data[c+0],h=_.data[c+1],l=_.data[c+2],d=_.data[c+3],u=4*(e*r+2*y-s-1),_.data[u+0]=o,_.data[u+1]=h,_.data[u+2]=l,_.data[u+3]=d;y*=2}!function(t,e,i){const s=t.data,r=e.data,n=t.width,a=t.height,o=i.polarCenterX||n/2,h=i.polarCenterY||a/2;let l=Math.sqrt(o*o+h*h),d=n-o,c=a-h;const u=Math.sqrt(d*d+c*c);l=u>l?u:l;const g=a,p=n;let m,f;for(d=0;d<n;d+=1)for(c=0;c<a;c+=1){const t=d-o,e=c-h,i=Math.sqrt(t*t+e*e)*g/l;let a=(180*Math.atan2(e,t)/Math.PI+360+0)%360;a=a*p/360,m=Math.floor(a),f=Math.floor(i);let u=4*(f*n+m);const _=s[u+0],v=s[u+1],y=s[u+2],w=s[u+3];u=4*(c*n+d),r[u+0]=_,r[u+1]=v,r[u+2]=y,r[u+3]=w}}(_,t,{})},Mask:function(t){let e=function(t,e){const i=Gs(t,0,0),s=Gs(t,t.width-1,0),r=Gs(t,0,t.height-1),n=Gs(t,t.width-1,t.height-1),a=e||10;if(Vs(i,s)<a&&Vs(s,n)<a&&Vs(n,r)<a&&Vs(r,i)<a){const e=function(t){const e=[0,0,0];for(let i=0;i<t.length;i++)e[0]+=t[i][0],e[1]+=t[i][1],e[2]+=t[i][2];return e[0]/=t.length,e[1]/=t.length,e[2]/=t.length,e}([s,i,n,r]),o=[];for(let i=0;i<t.width*t.height;i++){const s=Vs(e,[t.data[4*i],t.data[4*i+1],t.data[4*i+2]]);o[i]=s<a?0:255}return o}}(t,this.threshold());return e&&(e=function(t,e,i){const s=[1,1,1,1,0,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),a=[];for(let o=0;o<i;o++)for(let h=0;h<e;h++){const l=o*e+h;let d=0;for(let a=0;a<r;a++)for(let l=0;l<r;l++){const c=o+a-n,u=h+l-n;if(c>=0&&c<i&&u>=0&&u<e){const i=s[a*r+l];d+=t[c*e+u]*i}}a[l]=2040===d?255:0}return a}(e,t.width,t.height),e=function(t,e,i){const s=[1,1,1,1,1,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),a=[];for(let o=0;o<i;o++)for(let h=0;h<e;h++){const l=o*e+h;let d=0;for(let a=0;a<r;a++)for(let l=0;l<r;l++){const c=o+a-n,u=h+l-n;if(c>=0&&c<i&&u>=0&&u<e){const i=s[a*r+l];d+=t[c*e+u]*i}}a[l]=d>=1020?255:0}return a}(e,t.width,t.height),e=function(t,e,i){const s=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),a=[];for(let o=0;o<i;o++)for(let h=0;h<e;h++){const l=o*e+h;let d=0;for(let a=0;a<r;a++)for(let l=0;l<r;l++){const c=o+a-n,u=h+l-n;if(c>=0&&c<i&&u>=0&&u<e){const i=s[a*r+l];d+=t[c*e+u]*i}}a[l]=d}return a}(e,t.width,t.height),function(t,e){for(let i=0;i<t.width*t.height;i++)t.data[4*i+3]=e[i]}(t,e)),t},Noise:function(t){const e=255*this.noise(),i=t.data,s=i.length,r=e/2;for(let t=0;t<s;t+=4)i[t+0]+=r-2*r*Math.random(),i[t+1]+=r-2*r*Math.random(),i[t+2]+=r-2*r*Math.random()},Pixelate:function(t){let e=Math.ceil(this.pixelSize()),i=t.width,s=t.height,r=Math.ceil(i/e),n=Math.ceil(s/e),a=t.data;if(e<=0)Gt.error("pixelSize value can not be <= 0");else for(let t=0;t<r;t+=1)for(let r=0;r<n;r+=1){let n=0,o=0,h=0,l=0;const d=t*e,c=d+e,u=r*e,g=u+e;let p=0;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=u;e<g;e+=1){if(e>=s)continue;const r=4*(i*e+t);n+=a[r+0],o+=a[r+1],h+=a[r+2],l+=a[r+3],p+=1}n/=p,o/=p,h/=p,l/=p;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=u;e<g;e+=1){if(e>=s)continue;const r=4*(i*e+t);a[r+0]=n,a[r+1]=o,a[r+2]=h,a[r+3]=l}}},Posterize:function(t){const e=Math.round(254*this.levels())+1,i=t.data,s=i.length,r=255/e;for(let t=0;t<s;t+=1)i[t]=Math.floor(i[t]/r)*r},RGB:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue();for(let t=0;t<i;t+=4){const i=(.34*e[t]+.5*e[t+1]+.16*e[t+2])/255;e[t]=i*s,e[t+1]=i*r,e[t+2]=i*n,e[t+3]=e[t+3]}},RGBA:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue(),a=this.alpha();for(let t=0;t<i;t+=4){const i=1-a;e[t]=s*a+e[t]*i,e[t+1]=r*a+e[t+1]*i,e[t+2]=n*a+e[t+2]*i}},Sepia:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2];e[t+0]=Math.min(255,.393*i+.769*s+.189*r),e[t+1]=Math.min(255,.349*i+.686*s+.168*r),e[t+2]=Math.min(255,.272*i+.534*s+.131*r)}},Solarize:function(t){const e=t.data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2];.2126*i+.7152*s+.0722*r>=128&&(e[t]=255-i,e[t+1]=255-s,e[t+2]=255-r)}return t},Threshold:function(t){const e=255*this.threshold(),i=t.data,s=i.length;for(let t=0;t<s;t+=1)i[t]=i[t]<e?0:255}}});class Bs{screenToWorld(t){return{x:t.x,y:t.y,z:0}}worldToScreen(t){return{x:t.x,y:t.y}}getScale(){return{x:1,y:1,z:1}}}class Ns{constructor(t,e,i){this.setColor(t,e,i)}asHex(){return"#"+this.HEX}asRGB(){return{r:this.R,g:this.G,b:this.B}}setColor(t,e,i){this.R=t,this.G=e,this.B=i,this.HEX=this.rgbToHex(t,e,i)}rgbToHex(t,e,i){const s=t=>{const e=t.toString(16);return"0"===e?"00":e};return s(t)+s(e)+s(i)}}const js=new Map([["solid",[]],["dot",[30,30,.001,30]],["dash",[30,30]]]);class Hs{constructor(t,e=null,i=new Bs){var s,r;if(this._worldTransformer=i,e){this._ref=e;let t=this._ref.getAttr("wcsPoints");if(!t){t=[];const e=this._ref.points();let i;for(let s=0;s<e.length;s+=2)i=this._worldTransformer.screenToWorld({x:e[s],y:e[s+1]}),t.push({x:i.x,y:i.y,z:i.z});this._ref.setAttr("wcsPoints",t)}return}t||(t={}),t.points||(t.points=[{x:0,y:0},{x:100,y:100}]);const n=[],a=[];t.points.forEach(t=>{n.push(t.x,t.y);const e=this._worldTransformer.screenToWorld({x:t.x,y:t.y});a.push({x:e.x,y:e.y,z:e.z})}),this._ref=new Ws.Line({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.width)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:n,draggable:!0,strokeScaleEnabled:!1,dash:js.get(t.type)||[]}),this._ref.setAttr("wcsPoints",a),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation)}),this._ref.on("transformend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.on("dragend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Line"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){return this._ref.points()}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}getLineType(){let t;switch(this._ref.dash()||[]){case js.get("dot"):t="dot";break;case js.get("dash"):t="dash";break;default:t="solid"}return t}setLineType(t){const e=js.get(t);e&&this._ref.dash(e)}addPoints(t){let e=this._ref.points();const i=this._ref.getAttr("wcsPoints");t.forEach(t=>{e=e.concat([t.x,t.y]);const s=this._worldTransformer.screenToWorld(t);i.push(s)}),this._ref.points(e)}updateScreenCoordinates(){const t=this._ref.getAttr("wcsPoints"),e=[];let i=this._ref.getAbsoluteTransform().copy();i=i.invert(),t.forEach(t=>{let s=this._worldTransformer.worldToScreen(t);s=i.point({x:s.x,y:s.y}),e.push(s.x),e.push(s.y)}),this._ref.points([]),this._ref.points(e),this._ref.clearCache()}}class Us{constructor(t,e=null,i=new Bs){var s,r,n;if(this.TEXT_FONT_FAMILY="Calibri",this._worldTransformer=i,e){this._ref=e;return void(this._ref.getAttr("wcsStart")||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.text||(t.text="default"),this._ref=new Ws.Text({x:t.position.x,y:t.position.y,text:t.text,fontSize:null!==(s=t.fontSize)&&void 0!==s?s:34,fontFamily:this.TEXT_FONT_FAMILY,fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",align:"left",draggable:!0,rotation:null!==(n=t.rotation)&&void 0!==n?n:0}),this._ref.width(this._ref.getTextWidth()),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<Math.round(this.getFontSize())&&(n=Math.round(this.getFontSize())),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Text"}getColor(){return this._ref.fill()}setColor(t){this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getText(){return this._ref.text()}setText(t){this._ref.text(t)}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getFontSize(){return this._ref.fontSize()}setFontSize(t){this._ref.fontSize(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));let e=this._ref.getStage().getAbsoluteTransform().copy();e=e.invert();const i=e.point(t);this._ref.position({x:i.x,y:i.y})}}class Xs{constructor(t,e=null,i=new Bs){var s,r,n,a;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200),this._ref=new Ws.Rect({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.lineWidth)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,width:null!==(n=t.width)&&void 0!==n?n:200,height:null!==(a=t.height)&&void 0!==a?a:200,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}getWidth(){return this._ref.width()}getHeight(){return this._ref.height()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Rectangle"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}function Ys(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}class Js{constructor(t,e=null,i=new Bs){var s,r,n;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsPosition"),i=this._ref.getAttr("wcsRadiusX"),s=this._ref.getAttr("wcsRadiusY");return t||this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),i||this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:e.x()+e.radiusX(),y:e.y()})),void(s||this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()+e.radiusY()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(null!==(s=t.radius)&&void 0!==s||(t.radius={x:0,y:0}),t.radius.x=Ys(t.position,t.position2),t.position3?t.radius.y=Ys(t.position,t.position3):t.radius.x=t.radius.y):t.radius||(t.radius={x:25,y:25}),this._ref=new Ws.Ellipse({stroke:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:null!==(n=t.lineWidth)&&void 0!==n?n:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,radiusX:t.radius.x,radiusY:t.radius.y,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t.radius.x,y:this._ref.y()})),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t.radius.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.radiusX();i&&(r*=e.scaleX);let n=this._ref.radiusY();s&&(n*=e.scaleY);r<25&&(r=25),n<25&&(n=25),t.evt.ctrlKey||t.evt.shiftKey?i?this._ref.radius({x:r,y:r}):this._ref.radius({x:n,y:n}):this._ref.radius({x:r,y:n}),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t,y:e}))}getRadiusX(){return this._ref.radiusX()}setRadiusX(t){this._ref.radiusX(t),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t,y:this._ref.y()}))}getRadiusY(){return this._ref.radiusY()}setRadiusY(t){this._ref.radiusY(t),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t}))}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Ellipse"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX")),i=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));let s=this._ref.getStage().getAbsoluteTransform().copy();s=s.invert();const r=s.point({x:t.x,y:t.y});this._ref.position({x:r.x,y:r.y}),this._ref.radius({x:Math.abs(s.point(e).x-r.x),y:Math.abs(s.point(i).y-r.y)})}}class qs{constructor(t,e=null,i=new Bs){var s,r;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");return t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.points()[0],y:e.points()[1]})),void(i||this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:e.points()[2],y:e.points()[3]})))}t||(t={}),t.start||(t.start={x:0,y:0}),t.end||(t.end={x:100,y:100}),this._ref=new Ws.Arrow({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[t.start.x,t.start.y,t.end.x,t.end.y],draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.start.x,y:t.start.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.end.x,y:t.end.y})),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.points(),s=this._ref.getAbsoluteTransform(),r=s.point({x:i[0],y:i[1]}),n=s.point({x:i[2],y:i[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(r)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(n))}),this._ref.on("dragend",t=>{const e=this._ref.points(),i=t.target.getAbsoluteTransform(),s=i.point({x:e[0],y:e[1]}),r=i.point({x:e[2],y:e[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(s)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(r))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Arrow"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t),this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){const t=this._ref.points();return[{x:t[0],y:t[1]},{x:t[2],y:t[3]}]}setPoints(t){2===t.length&&(this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t[0].x,y:t[0].y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t[1].x,y:t[1].y})),this._ref.points([t[0].x,t[0].y,t[1].x,t[1].y]))}getStartPoint(){const t=this._ref.points();return{x:t[0],y:t[1]}}setStartPoint(t,e){const i=this._ref.points();this._ref.points([t,e,i[2],i[3]]),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getEndPoint(){const t=this._ref.points();return{x:t[2],y:t[3]}}setEndPoint(t,e){const i=this._ref.points();this._ref.points([i[0],i[1],t,e]),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t,y:e}))}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getAbsoluteTransform().copy();i=i.invert();const s=i.point({x:t.x,y:t.y}),r=i.point({x:e.x,y:e.y});this._ref.points([s.x,s.y,r.x,r.y])}}class Ks{constructor(t,e=null,i=new Bs){var s,r;if(this._ratio=1,this.EPSILON=1e-5,this.BASE64_HEADER_START="data:image/",this.BASE64_NOT_FOUND="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=",this._worldTransformer=i,e){e.src&&e.src.startsWith(this.BASE64_HEADER_START)||(e.src=this.BASE64_NOT_FOUND),e.height()<=this.EPSILON&&e.height(32),e.width()<=this.EPSILON&&e.width(32),this._ref=e,this._canvasImage=e.image(),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width();const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.src&&t.src.startsWith(this.BASE64_HEADER_START)||(t.src=this.BASE64_NOT_FOUND),t.position2&&(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y),this._canvasImage=new Image,this._canvasImage.onload=()=>{if(this._ref.image(this._canvasImage),this._ref.height()<=this.EPSILON&&this._ref.height(this._canvasImage.height),this._ref.width()<=this.EPSILON&&this._ref.width(this._canvasImage.width),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width(),(t.width<=this.EPSILON||t.height<=this.EPSILON)&&(t.maxWidth>=this.EPSILON||t.maxWidth>=this.EPSILON)){const e=t.maxHeight-this._canvasImage.height,i=t.maxWidth-this._canvasImage.width;(e<=this.EPSILON||i<=this.EPSILON)&&(i<=this.EPSILON&&i<e/this._ratio?(this._ref.height(t.maxWidth*this._ratio),this._ref.width(t.maxWidth)):(this._ref.width(t.maxHeight/this._ratio),this._ref.height(t.maxHeight)))}const e=this._worldTransformer.screenToWorld({x:t.position.x+this._ref.width(),y:t.position.y+this._ref.height()});this._ref.setAttr("wcsEnd",e)},this._canvasImage.onerror=()=>{this._canvasImage.onerror=function(){},this._canvasImage.src=this.BASE64_NOT_FOUND},this._canvasImage.src=t.src,this._ref=new Ws.Image({x:t.position.x,y:t.position.y,image:this._canvasImage,width:null!==(s=t.width)&&void 0!==s?s:0,height:null!==(r=t.height)&&void 0!==r?r:0,draggable:!0}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),t.position2&&this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),t.evt.ctrlKey||t.evt.shiftKey?i?(this._ref.width(r),this._ref.height(r*this._ratio)):(this._ref.width(n/this._ratio),this._ref.height(n)):(i&&this._ref.width(r),s&&this._ref.height(n)),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getSrc(){return this._canvasImage.src}setSrc(t){this._canvasImage.src=t}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t),this._ref.height(t*this._ratio);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t),this._ref.width(t/this._ratio);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Image"}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}class Zs{constructor(t,e=null,i=new Bs){var s,r,n,a;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200);this._ref=new Ws.Shape({x:t.position.x,y:t.position.y,width:null!==(s=t.width)&&void 0!==s?s:200,height:null!==(r=t.height)&&void 0!==r?r:200,stroke:null!==(n=t.color)&&void 0!==n?n:"#ff0000",strokeWidth:null!==(a=t.lineWidth)&&void 0!==a?a:4,draggable:!0,strokeScaleEnabled:!1,globalCompositeOperation:"source-over",sceneFunc:(t,e)=>{const i=this._ref.width(),s=this._ref.height(),r=[{x:0,y:0},{x:0+i,y:0},{x:0+i,y:0+s},{x:0,y:0+s},{x:0,y:0}];function n(n,a){const o={x:(h={x:0,y:0}).x+i/2,y:h.y+s/2};var h;t.beginPath();for(let e=0;e<r.length-1;e++){let i=a;const s=r[e+1].x-r[e].x,h=r[e+1].y-r[e].y,l=Math.sqrt(s*s+h*h),d=Math.floor(l/i);i=a+d/(l%i);let c=r[e].x+s/d/2,u=r[e].y+h/d/2;const g=r[e+1].x,p=r[e+1].y,m=Math.atan((p-u)/(g-c)),f=m+Math.PI,_=c>o.x&&u>o.y;for(let e=0;e<d;e++)_?t.arc(c,u,n,m,f):t.arc(c,u,n,f,m),c+=s/d,u+=h/d}t.closePath(),t.fillStrokeShape(e)}i>=49||s>=49?n(8,15):i>=25||s>=25?n(4,7.5):(t.beginPath(),t.lineTo(r[1].x,r[1].y),t.lineTo(r[2].x,r[2].y),t.lineTo(r[3].x,r[3].y),t.lineTo(r[4].x,r[4].y),t.closePath(),t.fillStrokeShape(e))}}),this._ref.className="Cloud",this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.getSelfRect=()=>({x:-8,y:-8,width:this._ref.width()+16,height:this._ref.height()+16}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Cloud"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.position({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}const $s={SelectMarkup:{name:"SelectMarkup",initializer:null},Line:{name:"Line",initializer:(t,e=null,...i)=>new Hs(e,t,...i)},Text:{name:"Text",initializer:(t,e=null,...i)=>new Us(e,t,...i)},Rectangle:{name:"Rect",initializer:(t,e=null,...i)=>new Xs(e,t,...i)},Ellipse:{name:"Ellipse",initializer:(t,e=null,...i)=>new Js(e,t,...i)},Arrow:{name:"Arrow",initializer:(t,e=null,...i)=>new qs(e,t,...i)},Image:{name:"Image",initializer:(t,e=null,...i)=>new Ks(e,t,...i)},Cloud:{name:"Cloud",initializer:(t,e=null,...i)=>new Zs(e,t,...i)}};class Qs{constructor(){this._markupIsActive=!1,this._markupColor=new Ns(255,0,0),this.lineWidth=4,this.lineType="solid",this.fontSize=34,this.changeActiveDragger=t=>{const e=t.data;this._markupContainer.className=this._container.className.split(" ").filter(t=>!t.startsWith("oda-cursor-")).filter(t=>t).concat(`oda-cursor-${e.toLowerCase()}`).join(" "),this.removeTextInput(),this.removeImageInput(),this.enableEditMode(e)},this.resizeContainer=()=>{const{offsetLeft:t,offsetTop:e,offsetWidth:i,offsetHeight:s}=this._container;i&&s&&(this._markupContainer.style.left=`${t}px`,this._markupContainer.style.top=`${e}px`,this._konvaStage.width(i),this._konvaStage.height(s),this.getObjects().forEach(t=>{t.updateScreenCoordinates()}))},this.pan=()=>{this.updateScreenCoordinatesForAll()},this.zoomAt=()=>{this.updateScreenCoordinatesForAll()},this.changeCameraMode=()=>{this.clearOverlay()},this.redirectToViewer=t=>{this._viewer&&this._viewer.emit(t)},this.getRelativePointPosition=(t,e)=>{const i=e.getAbsoluteTransform().copy();return i.invert(),i.point(t)},this.getRelativePointerPosition=t=>this.getRelativePointPosition(t.getStage().getPointerPosition(),t)}initialize(t,e,i,s){this._viewer=i,this._worldTransformer=null!=s?s:new Bs,this._container=t,this._markupContainer=document.createElement("div"),this._markupContainer.id="markup-container",this._markupContainer.style.position="absolute",this._markupContainer.style.outline="0px",this._markupContainer.style.pointerEvents="none";this._container.parentElement.appendChild(this._markupContainer),this._markupColor.setColor(255,0,0),this.initializeKonva(),this._resizeObserver=new ResizeObserver(this.resizeContainer),this._resizeObserver.observe(t),this._viewer&&(this._viewer.addEventListener("changeactivedragger",this.changeActiveDragger),this._viewer.addEventListener("pan",this.pan),this._viewer.addEventListener("zoomat",this.zoomAt),this._viewer.addEventListener("changecameramode",this.changeCameraMode))}dispose(){var t,e;this._viewer&&(this._viewer.removeEventListener("changecameramode",this.changeCameraMode),this._viewer.removeEventListener("zoomat",this.zoomAt),this._viewer.removeEventListener("pan",this.pan),this._viewer.removeEventListener("changeactivedragger",this.changeActiveDragger)),null===(t=this._resizeObserver)||void 0===t||t.disconnect(),this._resizeObserver=void 0,this.destroyKonva(),null===(e=this._markupContainer)||void 0===e||e.remove(),this._markupContainer=void 0,this._container=void 0,this._viewer=void 0,this._worldTransformer=void 0,this._markupIsActive=!1}syncOverlay(){}clearOverlay(){this.removeTextInput(),this.removeImageInput(),this.clearSelected(),this.getObjects().forEach(t=>t.delete())}getMarkupColor(){return this._markupColor.asRGB()}setMarkupColor(t,e,i){this._markupColor.setColor(t,e,i),this.redirectToViewer({type:"changemarkupcolor",data:{r:t,g:e,b:i}})}colorizeAllMarkup(t,e,i){this.setMarkupColor(t,e,i);const s=new Ns(t,e,i).asHex();this.getObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}colorizeSelectedMarkups(t,e,i){const s=new Ns(t,e,i).asHex();this.getSelectedObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}setViewpoint(t){var e,i,s,r,n,a,o,h;this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._konvaStage.scale({x:1,y:1}),this._konvaStage.position({x:0,y:0});const l=(null===(e=t.custom_fields)||void 0===e?void 0:e.markup_color)||{r:255,g:0,b:0};this.setMarkupColor(l.r,l.g,l.b),null===(i=t.lines)||void 0===i||i.forEach(t=>{const e=[];t.points.forEach(t=>{const i=this._worldTransformer.worldToScreen(t);e.push(i.x),e.push(i.y)}),this.addLine(e,t.color,t.type,t.width,t.id)}),null===(s=t.texts)||void 0===s||s.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position);this.addText(t.text,e,t.angle,t.color,t.text_size,t.font_size,t.id)}),null===(r=t.rectangles)||void 0===r||r.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addRectangle(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(n=t.ellipses)||void 0===n||n.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null,s=t.position3?this._worldTransformer.worldToScreen(t.position3):null;this.addEllipse(e,i,s,t.radius,t.line_width,t.color,t.id)}),null===(a=t.arrows)||void 0===a||a.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.start),i=this._worldTransformer.worldToScreen(t.end);this.addArrow(e,i,t.color,t.id)}),null===(o=t.clouds)||void 0===o||o.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addCloud(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(h=t.images)||void 0===h||h.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addImage(e,i,t.src,t.width,t.height,t.id)})}getViewpoint(t){return t||(t={}),t.lines=this.getMarkupLines(),t.texts=this.getMarkupTexts(),t.arrows=this.getMarkupArrows(),t.clouds=this.getMarkupClouds(),t.ellipses=this.getMarkupEllipses(),t.images=this.getMarkupImages(),t.rectangles=this.getMarkupRectangles(),t.custom_fields={markup_color:this.getMarkupColor()},t.snapshot={data:this.combineMarkupWithDrawing()},t}enableEditMode(t){return t&&$s[t]?(this._markupMode=t,this._markupContainer.style.pointerEvents="all",this._markupIsActive=!0):(this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._markupContainer.style.pointerEvents="none",this._markupIsActive=!1),this}createObject(t,e){const i=$s[t];if(!i||!i.initializer)throw new Error(`Markup CreateObject - unsupported markup type ${t}`);const s=i.initializer(null,e,this._worldTransformer);return this.addObject(s),s}getObjects(){const t=[];return Object.keys($s).forEach(e=>{const i=$s[e];this.konvaLayerFind(e).forEach(e=>t.push(i.initializer(e,null,this._worldTransformer)))}),t}getSelectedObjects(){return this._konvaTransformer?this._konvaTransformer.nodes().map(t=>{const e=t.className,i=Object.values($s).find(t=>t.name===e);return i?i.initializer(t,null,this._worldTransformer):null}).filter(t=>t):[]}selectObjects(t){if(!this._konvaTransformer)return;const e=this._konvaTransformer.nodes().concat(t.map(t=>t.ref()));this._konvaTransformer.nodes(e)}clearSelected(){this._konvaTransformer&&this._konvaTransformer.nodes([])}addObject(t){"Image"===t.type()?this._groupImages.add(t.ref()):"Text"===t.type()?this._groupTexts.add(t.ref()):this._groupGeometry.add(t.ref())}konvaLayerFind(t){if(!this._konvaLayer)return[];const e=$s[t];return e&&e.initializer?this._konvaLayer.find(e.name).filter(t=>t.parent===this._konvaLayer||t.parent===this._groupImages||t.parent===this._groupGeometry||t.parent===this._groupTexts):[]}updateScreenCoordinatesForAll(){this.getObjects().forEach(t=>{t.updateScreenCoordinates()})}initializeKonva(){const t=new Ws.Stage({container:this._markupContainer,width:this._container.clientWidth,height:this._container.clientHeight});this._konvaStage=t;const e=new Ws.Layer({pixelRation:window.devicePixelRatio});t.add(e),this._groupImages=new Ws.Group,e.add(this._groupImages),this._groupGeometry=new Ws.Group,e.add(this._groupGeometry),this._groupTexts=new Ws.Group,e.add(this._groupTexts),this._konvaLayer=e;const i=new Ws.Transformer({shouldOverdrawWholeArea:!1,keepRatio:!1,flipEnabled:!1});e.add(i),this._konvaTransformer=i;let s,r,n,a=!1;t.on("mousedown touchstart",e=>{if(!this._markupIsActive||e.target!==t||"Text"===this._markupMode||"Image"===this._markupMode)return;if(e.target===t&&i.nodes().length>0)return void i.nodes([]);const n=this.getRelativePointerPosition(t);r=n,a=["Arrow","Cloud","Ellipse","Line","Rectangle"].some(t=>t===this._markupMode),"Line"===this._markupMode&&(s=this.addLine([n.x,n.y,n.x,n.y]))}),t.on("mouseup touchend",()=>{if(this._markupIsActive){if(a){const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,s=i?r.x:Math.min(r.x,e.x),n=i?r.y:Math.min(r.y,e.y),a=i?200:Math.abs(r.x-e.x),o=i?200:Math.abs(r.y-e.y);i&&("Rectangle"===this._markupMode?this.addRectangle({x:s,y:n},null,a,o):"Ellipse"===this._markupMode?this.addEllipse({x:s,y:n},null,null,{x:a/2,y:o/2}):"Arrow"===this._markupMode?this.addArrow({x:r.x,y:r.y},{x:i?r.x+200:e.x,y:i?n:e.y}):"Cloud"===this._markupMode&&this.addCloud({x:s,y:n},null,Math.max(100,a),Math.max(100,o)))}n=void 0,a=!1}}),t.on("mousemove touchmove",()=>{if(!this._markupIsActive)return;if(!a)return;const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,o=i?r.x:Math.min(r.x,e.x),h=i?r.y:Math.min(r.y,e.y),l=i?200:Math.abs(r.x-e.x),d=i?200:Math.abs(r.y-e.y);"Line"===this._markupMode?s.addPoints([{x:e.x,y:e.y}]):"Arrow"===this._markupMode?n?n.setEndPoint(e.x,e.y):n=this.addArrow({x:r.x,y:r.y},{x:e.x,y:e.y}):"Rectangle"===this._markupMode?n?(n.setPosition(o,h),n.setWidth(l),n.setHeight(d)):n=this.addRectangle({x:o,y:h},null,l,d):"Ellipse"===this._markupMode?n?(n.setPosition(o,h),n.setRadiusX(l),n.setRadiusY(d)):n=this.addEllipse({x:o,y:h},null,null,{x:l,y:d}):"Cloud"===this._markupMode&&(n?(n.setPosition(o,h),n.setWidth(Math.max(100,l)),n.setHeight(Math.max(100,d))):n=this.addCloud({x:o,y:h},null,l,d))}),t.on("click tap",e=>{if(!this._markupIsActive)return;if(e.target===t){if("Text"===this._markupMode){if(this._textInputRef&&this._textInputRef.value)this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle);else if(0===i.nodes().length){const i=this.getRelativePointerPosition(t);this.createTextInput(i,e.evt.pageX,e.evt.pageY,0,null)}}else if("Image"===this._markupMode)if(this._imageInputRef&&this._imageInputRef.value)this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,this._imageInputRef.value,0,0,this._imageInputRef.value);else if(0===i.nodes().length){const e=this.getRelativePointerPosition(t);this.createImageInput(e)}return void i.nodes([])}if("Text"===this._markupMode||"SelectMarkup"===this._markupMode){if("Text"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._textInputRef&&this._textInputRef.value?this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle):this.createTextInput({x:e.target.attrs.x,y:e.target.attrs.y},e.evt.pageX,e.evt.pageY,e.target.attrs.rotation,e.target.attrs.text));this.removeTextInput()}if("Image"===this._markupMode||"SelectMarkup"===this._markupMode){if("Image"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._imageInputRef&&this._imageInputRef.value?this.addImage(this._imageInputPos,null,this._imageInputRef.value,0,0):this.createImageInput({x:e.target.attrs.x,y:e.target.attrs.y}));this.removeImageInput()}i.nodes().filter(t=>"Cloud"===t.className||"Image"===t.className).length>0||"Cloud"===e.target.className||"Image"===e.target.className?i.rotateEnabled(!1):i.rotateEnabled(!0);const s=e.evt.shiftKey||e.evt.ctrlKey||e.evt.metaKey,r=i.nodes().indexOf(e.target)>=0;if(s||r){if(s&&r){const t=i.nodes().slice();t.splice(t.indexOf(e.target),1),i.nodes(t)}else if(s&&!r){const t=i.nodes().concat([e.target]);i.nodes(t)}}else i.nodes([e.target])});const o=t.container();o.tabIndex=1,o.focus(),o.addEventListener("keydown",t=>{if(this._markupIsActive)return"Delete"===t.code?(this.getSelectedObjects().forEach(t=>t.delete()),void this.clearSelected()):void t.preventDefault()})}destroyKonva(){var t;this.removeTextInput(),this.removeImageInput(),this.clearOverlay(),null===(t=this._konvaStage)||void 0===t||t.destroy(),this._groupImages=void 0,this._groupGeometry=void 0,this._groupTexts=void 0,this._konvaLayer=void 0,this._konvaTransformer=void 0,this._konvaStage=void 0}getMarkupLines(){const t=[];return this.konvaLayerFind("Line").forEach(e=>{const i=e.getAttr("wcsPoints");if(!i)return;const s=new Hs(null,e,this._worldTransformer),r={id:s.id(),points:i,color:s.getColor()||"#ff0000",type:s.getLineType()||this.lineType,width:s.getLineWidth()||this.lineWidth};t.push(r)}),t}getMarkupTexts(){const t=[];return this.konvaLayerFind("Text").forEach(e=>{const i=this._worldTransformer.getScale(),s=e.getAttr("wcsStart"),r=this._konvaStage.getAbsoluteTransform(),n=new Us(null,e,this._worldTransformer),a={id:n.id(),position:s,text:n.getText(),text_size:.02*i.y,angle:n.getRotation(),color:n.getColor(),font_size:n.getFontSize()*r.getMatrix()[0]};t.push(a)}),t}getMarkupRectangles(){const t=[];return this.konvaLayerFind("Rectangle").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),a=new Xs(null,e,this._worldTransformer),o={id:a.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:a.getLineWidth(),color:a.getColor()};t.push(o)}),t}getMarkupEllipses(){const t=[];return this.konvaLayerFind("Ellipse").forEach(e=>{const i=e.getAttr("wcsPosition"),s=e.getAttr("wcsRadiusX"),r=e.getAttr("wcsRadiusY"),n=this._konvaStage.getAbsoluteTransform().getMatrix()[0],a=new Js(null,e,this._worldTransformer),o={id:a.id(),position:i,position2:s,position3:r,radius:{x:e.getRadiusX()*n,y:e.getRadiusY()*n},line_width:a.getLineWidth(),color:a.getColor()};t.push(o)}),t}getMarkupArrows(){const t=[];return this.konvaLayerFind("Arrow").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=new qs(null,e,this._worldTransformer),n={id:r.id(),start:i,end:s,color:r.getColor()};t.push(n)}),t}getMarkupImages(){const t=[];return this.konvaLayerFind("Image").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._konvaStage.getAbsoluteTransform().getMatrix()[0],n=new Ks(null,e,this._worldTransformer),a={id:n.id(),position:i,position2:s,src:n.getSrc(),width:n.getWidth()*r,height:n.getHeight()*r};t.push(a)}),t}getMarkupClouds(){const t=[];return this.konvaLayerFind("Cloud").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),a=new Zs(null,e,this._worldTransformer),o={id:a.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:a.getLineWidth(),color:a.getColor()};t.push(o)}),t}combineMarkupWithDrawing(){this.clearSelected();const t=document.createElement("canvas");if(this._konvaStage){t.width=this._konvaStage.width(),t.height=this._konvaStage.height();const e=t.getContext("2d");this._container instanceof HTMLCanvasElement&&e.drawImage(this._container,0,0),e.drawImage(this._konvaStage.toCanvas({pixelRatio:window.devicePixelRatio}),0,0)}return t.toDataURL("image/jpeg",.25)}addLine(t,e,i,s,r){if(!t||0===t.length)return;const n=[];for(let e=0;e<t.length;e+=2)n.push({x:t[e],y:t[e+1]});const a=new Hs({points:n,type:i||this.lineType,width:s||this.lineWidth,color:e||this._markupColor.asHex(),id:r},null,this._worldTransformer);return this.addObject(a),a}createTextInput(t,e,i,s,r){this._textInputRef?this.removeTextInput():(this._textInputPos=t,this._textInputAngle=s,this._textInputRef=document.createElement("textarea"),this._textInputRef.style.zIndex="9999",this._textInputRef.style.position="absolute",this._textInputRef.style.display="block",this._textInputRef.style.top=i+"px",this._textInputRef.style.left=e+"px",this._textInputRef.style.fontSize=`${this.fontSize}px`,this._textInputRef.style.color=`${this._markupColor.asHex()}`,this._textInputRef.style.fontFamily="Calibri",this._textInputRef.onkeydown=t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle)),"Escape"===t.key&&(t.preventDefault(),this.removeTextInput())},r&&(this._textInputRef.value=r),document.body.appendChild(this._textInputRef),setTimeout(()=>{this._textInputRef.focus()},50))}removeTextInput(){var t;null===(t=this._textInputRef)||void 0===t||t.remove(),this._textInputRef=null,this._textInputPos=null,this._textInputAngle=0}createImageInput(t){if(this._imageInputRef)this.removeImageInput();else{const e=t=>new Promise((e,i)=>{const s=new FileReader;s.readAsDataURL(t),s.onload=()=>{e(s.result)},s.onerror=t=>{i(t)}});this._imageInputPos=t,this._imageInputRef=document.createElement("input"),this._imageInputRef.style.display="none",this._imageInputRef.type="file",this._imageInputRef.accept="image/png, image/jpeg",this._imageInputRef.onchange=async t=>{const i=t.target.files[0],s=await e(i);this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,s.toString(),0,0)},this._imageInputRef.oncancel=()=>{this.removeImageInput()},document.body.appendChild(this._imageInputRef),setTimeout(()=>{this._imageInputRef.click()},50)}}removeImageInput(){var t;null===(t=this._imageInputRef)||void 0===t||t.remove(),this._imageInputRef=null,this._imageInputPos=null}addText(t,e,i,s,r,n,a){var o;if(!t)return;null===(o=this.getSelectedObjects().shift())||void 0===o||o.delete(),this.clearSelected(),this.removeTextInput();const h=1e-6;if(r&&r>h&&(!n||n<h)){const t=.02;n=r/(this._worldTransformer.getScale().y/t)/34}const l=new Us({position:{x:e.x,y:e.y},text:t,rotation:i,fontSize:n||this.fontSize,color:s||this._markupColor.asHex(),id:a},null,this._worldTransformer);return this.addObject(l),l}addRectangle(t,e,i,s,r,n,a){if(!t)return;const o=new Xs({position:t,position2:e,width:i,height:s,lineWidth:r||this.lineWidth,color:n||this._markupColor.asHex(),id:a},null,this._worldTransformer);return this.addObject(o),o}addEllipse(t,e,i,s,r,n,a){if(!t)return;const o=new Js({position:t,position2:e,position3:i,radius:s,lineWidth:r,color:n||this._markupColor.asHex(),id:a},null,this._worldTransformer);return this.addObject(o),o}addArrow(t,e,i,s){if(!t||!e)return;const r=new qs({start:t,end:e,color:i||this._markupColor.asHex(),id:s},null,this._worldTransformer);return this.addObject(r),r}addCloud(t,e,i,s,r,n,a){if(!t||!i||!s)return;const o=new Zs({position:t,position2:e,width:i,height:s,color:n||this._markupColor.asHex(),lineWidth:r||this.lineWidth,id:a},null,this._worldTransformer);return this.addObject(o),o}addImage(t,e,i,s,r,n){var a;if(!t||!i)return;null===(a=this.getSelectedObjects().shift())||void 0===a||a.delete(),this.clearSelected(),this.removeImageInput();const o=new Ks({position:t,position2:e,src:i,width:s,height:r,maxWidth:this._konvaStage.width()-t.x,maxHeight:this._konvaStage.height()-t.y,id:n},null,this._worldTransformer);return this.addObject(o),o}}const tr="$MarkupTempEntity_Line";class er extends w{constructor(t){super(t),this.press=!1}dispose(){super.dispose(),this.end(),this.points=null,this.drawPoints=null}start(t,e){const i=this.getViewer().screenToWorld(t,e);this.drawPoints=[i[0],i[1],i[2]]}drag(t,e){if(this.isDragging){const i=this.getViewer().screenToWorld(t,e);this.drawPoints.push(i[0],i[1],i[2]),this._updateFrame()}}end(){this.entity&&(this.entity.delete(),this.drawPoints=null,this.entity=null)}_updateFrame(){if(this.entity){const t=this.getViewer().getMarkupModel();t.removeEntity(this.entity),t.delete(),this.entity.delete()}this.entity=this.getActiveMarkupEntity(tr);const t=this.entity.openObject();t.appendPolyline(this.drawPoints).delete(),t.delete()}}const ir="$MarkupTempEntity_Text";class sr extends w{constructor(t){super(t),this.TEXT_HEIGHT_ALIGN=24,this.press=!1}dispose(){var t;super.dispose(),null===(t=this.textRef)||void 0===t||t.remove(),this.textRef=null}_finishInput(){var t;this.textRef&&this.textRef.value.trimLeft()&&this._updateFrame(),null===(t=this.textRef)||void 0===t||t.remove(),this.textRef=null}start(t,e,i,s){this.textRef?this._finishInput():(this.textRef=document.createElement("textarea"),this.textRef.style.zIndex="9999",this.textRef.style.position="absolute",this.textRef.style.display="block",this.textRef.style.top=s+"px",this.textRef.style.left=i+"px",this.textRef.onkeypress=t=>{"Enter"===t.key&&(t.preventDefault(),this._finishInput())},document.body.appendChild(this.textRef),this.press=!0,this.m_center=this.screenToWorld(t,e+this.TEXT_HEIGHT_ALIGN),this.needInputText=!0)}_updateFrame(){this.entity=this.getActiveMarkupEntity(ir);const t=this.entity.openObject(),e=this.getViewer().activeView,i=this.toPoint(e.viewPosition),s=this.toPoint(e.viewTarget),r=e.eyeToWorldMatrix,n=i.sub(s).asVector(),a=this.toVector([1,0,0]).transformBy(r),o=this.createMatrix3d();o.setToWorldToPlane(this.toGeVector(n)),a.transformBy(o);const h=-Math.atan2(-a.y,a.x);let l=1;const d=e.projectionMatrix.get(1,1),c=1e-6;d<c&&d>-c||(l=1/d);const u=t.appendText(this.toGePoint(this.m_center),this.textRef.value.trimLeft()),g=u.openAsText();g.setNormal(this.toGeVector(n)),g.setRotation(h),g.setTextSize(.02*l),g.delete(),u.delete(),t.delete()}}class rr{constructor(){this._markupColor={r:255,g:0,b:0},this.lineWidth=4,this.fontSize=34}initialize(t,e,i,s){this._viewer=i,this._viewer.registerDragger("Line",er),this._viewer.registerDragger("Text",sr)}dispose(){}syncOverlay(){}clearOverlay(){if(!this._viewer.visualizeJs)return;const t=this._viewer.visViewer().getMarkupModel();t.clearEntities(),t.delete()}getMarkupColor(){return this._markupColor}setMarkupColor(t,e,i){const s={r:t,g:e,b:i};this._markupColor=s,this._viewer.emitEvent({type:"changemarkupcolor",data:s})}colorizeAllMarkup(t=255,e=0,i=0){if(!this._viewer.visualizeJs)return;const s=this._viewer.visViewer().getMarkupModel().getEntitiesIterator();for(;!s.done();s.step()){const r=s.getEntity().openObject(),n=r.getName();n!==tr&&n!==ir||r.setColor(t,e,i),r.delete()}s.delete(),this._viewer.update()}colorizeSelectedMarkups(t=255,e=0,i=0){throw new Error("Not implemented yet")}setViewpoint(t){function e(t){return[t.x,t.y,t.z]}function i(t,e){return t.Point3d.createFromArray(e)}if(!this._viewer.visualizeJs)return;const s=this._viewer.visLib(),r=this._viewer.visViewer().activeView;this._viewer.syncOverlay();const n=t.custom_fields.markup_color||{r:255,g:0,b:0};if(this.setMarkupColor(n.r,n.g,n.b),t.lines)for(const e of t.lines){const t=this._viewer.addMarkupEntity(tr).openObject(),i=[];for(const t of e.points)i.push(t.x,t.y,t.z);t.appendPolyline(i).delete(),t.delete()}if(t.texts){const n=i(s,r.viewPosition),a=i(s,r.viewTarget),o=n.sub(a).asVector();for(const i of t.texts){const t=this._viewer.addMarkupEntity(ir).openObject(),s=t.appendText(e(i.position),i.text),r=s.openAsText();r.setNormal(e(o)),r.setRotation(i.angle),r.setTextSize(i.text_size),r.delete(),s.delete(),t.delete()}}this._viewer.update()}getViewpoint(t){if(!this._viewer.visualizeJs)return{};function e(t){return{x:t[0],y:t[1],z:t[2]}}const i=this._viewer.visLib(),s=this._viewer.visViewer();t||(t={}),t.lines=[],t.texts=[];const r=s.getMarkupModel().getEntitiesIterator();for(;!r.done();r.step()){const i=r.getEntity().openObject(),s=i.getName(),n=i.getGeometryDataIterator();if(n.done()){i.delete();continue}const a=n.getGeometryData();if(s===tr){const i=a.openAsPolyline(),s=i.getPoints(),r={points:[]};for(const t of s)r.points.push(e(t));t.lines.push(r),i.delete()}else if(s===ir){const i=a.openAsText(),s={position:e(i.getPosition()),text:i.getString(),angle:i.getRotation(),text_size:i.getTextSize()};t.texts.push(s),i.delete()}i.delete()}return r.delete(),t.snapshot={data:i.canvas.toDataURL("image/jpeg",.25)},t.custom_fields={markup_color:this.getMarkupColor()},t}enableEditMode(t){return this}createObject(t,e){}getObjects(){return[]}getSelectedObjects(){return[]}selectObjects(t){}clearSelected(){}}class nr{static createMarkup(t="Konva"){let e;switch(t){case"Konva":e=new Qs;break;case"Visualize":e=new rr;break;default:throw new Error(`Unknown Markup type: ${t}`)}return e}}const ar="$OVERLAY_VIEW_NAME",or=t=>null!=t;t.CANVAS_EVENTS=_,t.CanvasEvents=f,t.Component=class{constructor(t){this.name=""}dispose(){}},t.Dragger=class{constructor(t){this.name=""}dispose(){}},t.FileLoader=ct,t.Info=v,t.Loader=d,t.Markup=Qs,t.OdBaseDragger=w,t.Options=m,t.Viewer=class extends xt{constructor(t,e={}){var i;super(),this._visualizeJsUrl="",this.configure(e),this.client=t,this.options=new m(this),this.loaders=[],this.models=[],this.info=new v,this.canvasEvents=_.slice(),this.canvaseventlistener=t=>this.emit(t),this._activeDragger=null,this._components=[],this._renderNeeded=!1,this._renderTime=0,this._enableAutoUpdate=null===(i=e.enableAutoUpdate)||void 0===i||i,this._isRunAsyncUpdate=!1,this.render=this.render.bind(this),this.update=this.update.bind(this),this._markup=nr.createMarkup(e.markupType)}get visualizeJsUrl(){return this._visualizeJsUrl}get visualizeJs(){return this._visualizeJs}visLib(){return this._visualizeJs}visViewer(){return this._viewer}get markup(){return this._markup}configure(t){return this._visualizeJsUrl=t.visualizeJsUrl||"https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js",this._crossOrigin=t.crossOrigin,this}get draggers(){return[...q.getDraggers().keys()]}get components(){return[...lt.getComponents().keys()]}async initialize(t,e){this.addEventListener("optionschange",t=>this.syncOptions(t.data));const i=window.devicePixelRatio,s=t.parentElement.getBoundingClientRect(),r=s.width||1,n=s.height||1;t.width=Math.round(r*i),t.height=Math.round(n*i),t.style.width=r+"px",t.style.height=n+"px",t.parentElement.style.touchAction="none",t.style.touchAction="none",this._visualizeTimestamp=Date.now();const a=this._visualizeTimestamp,o=await(async(t,e,i={})=>{const s=await bt(t,i);return await new Promise((i,r)=>{const n={urlMemFile:t+".wasm",TOTAL_MEMORY:134217728,onprogress:e},a=window.getVisualizeLibInst(n);a.loadWasmError=r,a.postRun.push(()=>{window.getVisualizeLibInst.script=s,i(a)})})})(this.visualizeJsUrl,t=>{const{loaded:i,total:s}=t;e&&e(new ProgressEvent("progress",{lengthComputable:!0,loaded:i,total:s})),this.emitEvent({type:"initializeprogress",data:i/s,loaded:i,total:s})},{crossOrigin:this._crossOrigin});if(a!==this._visualizeTimestamp)throw new Error("Viewer error: dispose() was called before initialize() completed. Are you using React strict mode?");this._visualizeJs=o,this._visualizeJs.canvas=t,this._viewer=o.Viewer.create(),this._viewer.resize(0,t.width,t.height,0),this.canvas=t,this.canvasEvents.forEach(e=>t.addEventListener(e,this.canvaseventlistener)),this._markup.initialize(this.canvas,this.canvasEvents,this,this);for(const t of lt.getComponents().keys())this._components.push(lt.createComponent(t,this));return this.syncOptions(),this.syncOverlay(),this._renderTime=performance.now(),this.render(this._renderTime),this.emitEvent({type:"initialize"}),this}dispose(){return this.cancel(),this.clear(),this.emitEvent({type:"dispose"}),this.removeAllListeners(),this.setActiveDragger(),this._components.forEach(t=>t.dispose()),this._components=[],this._markup.dispose(),this.canvas&&(this.canvasEvents.forEach(t=>this.canvas.removeEventListener(t,this.canvaseventlistener)),this.canvas=void 0),this._viewer&&this._viewer.clear(),this._visualizeJs=void 0,this._visualizeTimestamp=void 0,this._viewer=void 0,this}isInitialized(){return!!this.visualizeJs}setSize(t,e,i=!0){this.visualizeJs&&(this.canvas.width=Math.round(t*window.devicePixelRatio),this.canvas.height=Math.round(e*window.devicePixelRatio),i&&(this.canvas.style.width=t+"px",this.canvas.style.height=e+"px"),this._viewer.resize(0,this.canvas.width,this.canvas.height,0),this.update(!0),this.emitEvent({type:"resize",width:t,height:e}))}resize(){if(console.warn("Viewer.resize() has been deprecated since 26.9 and will be removed in a future release, use Viewer.setSize() instead."),!this.visualizeJs)return this;if(!this.canvas.parentElement)return this;const{width:t,height:e}=this.canvas.parentElement.getBoundingClientRect();return t&&e?(this.setSize(t,e),this):this}update(t=!1){this._enableAutoUpdate&&(this._renderNeeded=!0,t&&this.render()),this.emitEvent({type:"update",data:t})}render(t){var e,i;if(!this.visualizeJs)return;if(this._isRunAsyncUpdate)return;if(!(this.visViewer().isRunningAnimation()||this._renderNeeded))return;t||(t=performance.now());const s=(t-this._renderTime)/1e3;this._renderTime=t,this._renderNeeded=!this.visViewer().getActiveDevice().isValid(),this.visViewer().update(),null===(i=null===(e=this._activeDragger)||void 0===e?void 0:e.updatePreview)||void 0===i||i.call(e),this.emitEvent({type:"render",time:t,deltaTime:s})}async loadReferences(t){var e;if(!this.visualizeJs)return this;if(!this.client)return this;if(!t.getReferences)return this;const i=new AbortController;null===(e=this._abortControllerForReferences)||void 0===e||e.abort(),this._abortControllerForReferences=i;let s=[];await t.getReferences(i.signal).then(t=>s=t.references).catch(t=>console.error("Cannot load model references.",t));for(const t of s)await this.client.downloadFile(t.id,void 0,i.signal).then(e=>{var i;return null===(i=this.visualizeJs)||void 0===i?void 0:i.getViewer().addEmbeddedFile(t.name,new Uint8Array(e))}).catch(e=>console.error(`Cannot load reference file ${t.name}.`,e));return this}applyModelTransformMatrix(t){this.executeCommand("applyModelTransform",t)}applySceneGraphSettings(t=this.options){if(!this.visualizeJs)return;const e=this.visLib(),i=this.visViewer().getActiveDevice();or(t.sceneGraph)&&i.setOptionBool(e.DeviceOptions.kDelaySceneGraphProc,!t.sceneGraph),i.delete(),this.update()}async open(t,e={}){if(!this.visualizeJs)return this;this.cancel(),this.clear(),this.emitEvent({type:"open",mode:"file",file:t});let i=t;if(i&&"function"==typeof i.getModels){const e=await i.getModels();i=e.find(t=>t.default)||e[0]||t}if(i&&"string"==typeof i.database&&(t=i.file),!i)throw new Error("Format not supported");let s=e.format;s||"string"!=typeof t.type||(s=t.type.split(".").pop()),s||"string"!=typeof t||(s=t.split(".").pop()),!s&&t instanceof globalThis.File&&(s=t.name.split(".").pop());const r=wt.createLoader(this,i,s);if(!r)throw new Error("Format not supported");this.loaders.push(r),this.emitEvent({type:"geometrystart",file:t,model:i});try{await this.loadReferences(i),await r.load(i,s,e)}catch(e){throw this.emitEvent({type:"geometryerror",data:e,file:t,model:i}),e}return this.emitEvent({type:"geometryend",file:t,model:i}),this.visualizeJs&&(this.applyModelTransformMatrix(i),this.applySceneGraphSettings()),this}openVsfFile(t){if(console.warn("Viewer.openVsfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead."),!this.visualizeJs)return this;this.cancel(),this.clear(),this.emitEvent({type:"open",mode:"file",file:"",buffer:t});const e=this.visViewer();this.emitEvent({type:"geometrystart",file:"",buffer:t});try{const i=t instanceof Uint8Array?t:new Uint8Array(t);e.parseFile(i),this.syncOptions(),this.syncOverlay(),this.update(!0),this.emitEvent({type:"geometryprogress",data:1,file:"",buffer:t}),this.emitEvent({type:"databasechunk",data:i,file:"",buffer:t})}catch(e){throw this.emitEvent({type:"geometryerror",data:e,file:"",buffer:t}),e}return this.emitEvent({type:"geometryend",file:"",buffer:t}),this}openVsfxFile(t){if(console.warn("Viewer.openVsfxFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead."),!this.visualizeJs)return this;this.cancel(),this.clear(),this.emitEvent({type:"open",mode:"file",file:"",buffer:t});const e=this.visViewer();this.emitEvent({type:"geometrystart",file:"",buffer:t});try{const i=t instanceof Uint8Array?t:new Uint8Array(t);e.parseVsfx(i),this.syncOptions(),this.syncOverlay(),this.update(!0),this.emitEvent({type:"geometryprogress",data:1,file:"",buffer:t}),this.emitEvent({type:"databasechunk",data:i,file:"",buffer:t})}catch(e){throw this.emitEvent({type:"geometryerror",data:e,file:"",buffer:t}),e}return this.emitEvent({type:"geometryend",file:"",buffer:t}),this}cancel(){var t;return null===(t=this._abortControllerForReferences)||void 0===t||t.abort(),this._abortControllerForReferences=void 0,this.loaders.forEach(t=>t.cancel()),this.emitEvent({type:"cancel"}),this}clear(){if(!this.visualizeJs)return this;const t=this.visViewer();return this.setActiveDragger(),this.clearSlices(),this.clearOverlay(),this.clearSelected(),this.loaders.forEach(t=>t.dispose()),this.loaders=[],this.models.forEach(t=>t.dispose()),this.models=[],t.clear(),t.createLocalDatabase(),this.syncOptions(),this.syncOverlay(),this.update(!0),this.emitEvent({type:"clear"}),this}is3D(){if(!this.visualizeJs)return!1;const t=this.visViewer().getActiveExtents(),e=t.min();return 0!==t.max()[2]-e[2]}syncOptions(t=this.options){if(!this.visualizeJs)return this;const e=this.visLib(),i=this.visViewer(),s=i.getActiveDevice();if(s.isNull())return this;const r=s.getActiveView();let n;r.enableDefaultLighting(!0,e.DefaultLightingType.kTwoLights),r.setDefaultLightingIntensity(1.25);try{n=i.findVisualStyle("OpenCloud")}catch{n=void 0}if(!n||n.isNull()){n=i.createVisualStyle("OpenCloud");const t=new e.OdTvColorDef(66,66,66),s=i.findVisualStyle("Realistic"),r=n.openObject();r.copyFrom(s),r.setOptionInt32(e.VisualStyleOptions.kFaceModifiers,0,e.VisualStyleOperations.kSet),r.setOptionInt32(e.VisualStyleOptions.kEdgeModel,2,e.VisualStyleOperations.kSet),r.setOptionDouble(e.VisualStyleOptions.kEdgeCreaseAngle,60,e.VisualStyleOperations.kSet),r.setOptionInt32(e.VisualStyleOptions.kEdgeStyles,0,e.VisualStyleOperations.kSet),r.setOptionInt32(e.VisualStyleOptions.kEdgeModifiers,8,e.VisualStyleOperations.kSet),r.setOptionColor(e.VisualStyleOptions.kEdgeColorValue,t,e.VisualStyleOperations.kSet),r.delete()}r.visualStyle=n,t.showWCS!==i.getEnableWCS()&&i.setEnableWCS(t.showWCS),t.cameraAnimation!==i.getEnableAnimation()&&i.setEnableAnimation(t.cameraAnimation);const a=!0===t.antialiasing||"fxaa"===t.antialiasing;if(a!==i.fxaaAntiAliasing3d&&(i.fxaaAntiAliasing3d=a,i.fxaaQuality=5),t.shadows!==i.shadows&&(i.shadows=t.shadows),t.groundShadow!==i.groundShadow&&(i.groundShadow=t.groundShadow),t.ambientOcclusion!==s.getOptionBool(e.DeviceOptions.kSSAOEnable)){s.setOptionBool(e.DeviceOptions.kSSAOEnable,t.ambientOcclusion),s.setOptionBool(e.DeviceOptions.kSSAODynamicRadius,!0),s.setOptionDouble(e.DeviceOptions.kSSAORadius,1),s.setOptionInt32(e.DeviceOptions.kSSAOLoops,32),s.setOptionDouble(e.DeviceOptions.kSSAOPower,2),s.setOptionInt32(e.DeviceOptions.kSSAOBlurRadius,2);const r=i.activeView;r.setSSAOEnabled(t.ambientOcclusion),r.delete()}if(or(t.edgeModel)){const r=s.getActiveView(),n=i.findVisualStyle("OpenCloud"),a=n.openObject();a.setOptionInt32(e.VisualStyleOptions.kEdgeModel,t.edgeModel?2:0,e.VisualStyleOperations.kSet),r.visualStyle=n,a.delete(),n.delete(),r.delete()}const o=t.enableCustomHighlight?t:m.defaults(),{Entry:h,OdTvRGBColorDef:l}=e,d=i.findHighlightStyle("Web_Default").openObject();if(or(o.facesColor)){const t=new l(o.facesColor.r,o.facesColor.g,o.facesColor.b);d.setFacesColor(h.k3D.value|h.k3DTop.value,t),t.delete()}if(or(o.facesOverlap)&&d.setFacesVisibility(h.k3DTop.value,o.facesOverlap),or(o.facesTransparancy)&&d.setFacesTransparency(h.k3D.value|h.k3DTop.value,o.facesTransparancy),or(o.edgesColor)){const t=new l(o.edgesColor.r,o.edgesColor.g,o.edgesColor.b);d.setEdgesColor(h.k3DTop.value|h.k3D.value|h.k2D.value|h.k2DTop.value,t),t.delete()}if(or(o.edgesVisibility)&&d.setEdgesVisibility(h.k2D.value|h.k2DTop.value|h.k3DTop.value|h.k3D.value,o.edgesVisibility),or(o.edgesOverlap)){const t=!or(o.edgesVisibility)||o.edgesVisibility;d.setEdgesVisibility(h.k2DTop.value|h.k3DTop.value,o.edgesOverlap&&t)}return r.delete(),s.delete(),this.update(),this}syncOverlay(){if(!this.visualizeJs)return;const t=this.visViewer(),e=t.activeView;let i=t.getViewByName(ar);if(!i){const s=t.getMarkupModel(),r=t.getActiveDevice();i=r.createView(ar,!1),i.addModel(s),e.addSibling(i),r.addView(i)}i.viewPosition=e.viewPosition,i.viewTarget=e.viewTarget,i.upVector=e.upVector,i.viewFieldWidth=e.viewFieldWidth,i.viewFieldHeight=e.viewFieldHeight;const s=i.getViewport();i.setViewport(s.lowerLeft,s.upperRight),i.vportRect=e.vportRect,this._markup.syncOverlay(),this.update()}clearOverlay(){this.visualizeJs&&(this._markup.clearOverlay(),this.update())}clearSlices(){if(!this.visualizeJs)return;const t=this.visViewer().activeView;t.removeCuttingPlanes(),t.delete(),this.update()}getSelected(){return this.executeCommand("getSelected")}setSelected(t){this.executeCommand("setSelected",t)}getSelected2(){return this.executeCommand("getSelected2")}setSelected2(t){this.executeCommand("setSelected2",t)}clearSelected(){this.executeCommand("clearSelected")}hideSelected(){this.executeCommand("hideSelected")}isolateSelected(){this.executeCommand("isolateSelected")}showAll(){this.executeCommand("showAll")}explode(t=0){this.executeCommand("explode",t)}collect(){this.executeCommand("collect")}registerDragger(t,e){console.warn("Viewer.registerDragger() has been deprecated since 25.12 and will be removed in a future release, use draggers('visualizejs').registerDragger() instead."),q.registerDragger(t,t=>new e(t))}activeDragger(){return this._activeDragger}setActiveDragger(t=""){var e,i;if(!this._activeDragger||this._activeDragger.name!==t){const s=this._activeDragger;let r=null;this._activeDragger&&(this._activeDragger.dispose(),this._activeDragger=null),this.visualizeJs&&(r=q.createDragger(t,this),r&&(this._activeDragger=r,null===(i=(e=this._activeDragger).initialize)||void 0===i||i.call(e)));const n=this.canvas;n&&(s&&n.classList.remove(`oda-cursor-${s.name.toLowerCase()}`),r&&n.classList.add(`oda-cursor-${r.name.toLowerCase()}`)),this.emitEvent({type:"changeactivedragger",data:t}),this.update()}return this._activeDragger}resetActiveDragger(){const t=this._activeDragger;t&&(this.setActiveDragger(),this.setActiveDragger(t.name))}getComponent(t){return this._components.find(e=>e.name===t)}drawViewpoint(t){var e,i;if(!this.visualizeJs)return;const s=this.visViewer().activeView,r=t=>[t.x,t.y,t.z],n=null===(e=this._activeDragger)||void 0===e?void 0:e.name;this.setActiveDragger(),this.clearSlices(),this.clearOverlay(),this.clearSelected(),this.showAll(),this.explode(),(t=>{t&&(s.setView(r(t.view_point),r(t.direction),r(t.up_vector),t.field_width,t.field_height,!0),this.syncOverlay(),this.emitEvent({type:"changecameramode",mode:"orthographic"}))})(t.orthogonal_camera),t.perspective_camera,(t=>{if(t)for(const e of t){const t=new(this.visLib().OdTvPlane);t.set(r(e.location),r(e.direction)),s.addCuttingPlane(t),s.setEnableCuttingPlaneFill(!0,102,102,102)}})(t.clipping_planes),(t=>{t&&this.setSelected(t.map(t=>t.handle))})((null===(i=t.custom_fields)||void 0===i?void 0:i.selection2)||t.selection),this._markup.setViewpoint(t),this.setActiveDragger(n),this.emitEvent({type:"drawviewpoint",data:t}),this.update()}createViewpoint(){if(!this.visualizeJs)return{};const t=this.visViewer().activeView,e=t=>({x:t[0],y:t[1],z:t[2]}),i={custom_fields:{}};return i.orthogonal_camera={view_point:e(t.viewPosition),direction:e(t.viewTarget),up_vector:e(t.upVector),field_width:t.viewFieldWidth,field_height:t.viewFieldHeight,view_to_world_scale:1},i.perspective_camera=void 0,i.clipping_planes=(()=>{const i=[];for(let s=0;s<t.numCuttingPlanes();s++){const r=t.getCuttingPlane(s),n={location:e(r.getOrigin()),direction:e(r.normal())};i.push(n)}return i})(),i.selection=(()=>this.getSelected().map(t=>({handle:t})))(),i.description=(new Date).toDateString(),this._markup.getViewpoint(i),i.custom_fields.selection2=(()=>this.getSelected2().map(t=>({handle:t})))(),this.emitEvent({type:"createviewpoint",data:i}),i}screenToWorld(t){if(!this.visualizeJs)return{x:t.x,y:t.y,z:0};const e=this.visViewer().activeView,i=e.transformScreenToWorld(t.x*window.devicePixelRatio,t.y*window.devicePixelRatio),s={x:i[0],y:i[1],z:i[2]};return e.delete(),s}worldToScreen(t){if(!this.visualizeJs)return{x:t.x,y:t.y};const e=this.visViewer().activeView,i=e.transformWorldToScreen(t.x,t.y,t.z),s={x:i[0]/window.devicePixelRatio,y:i[1]/window.devicePixelRatio};return e.delete(),s}getScale(){const t={x:1,y:1,z:1},e=this.visViewer().activeView.projectionMatrix,i=1e-6,s=e.get(0,0);(s>i||s<-1e-6)&&(t.x=1/s);const r=e.get(1,1);(r>i||r<-1e-6)&&(t.y=1/r);const n=e.get(2,2);return(n>i||n<-1e-6)&&(t.z=1/n),t}executeCommand(t,...e){return tt.executeCommand(t,this,...e)}addMarkupEntity(t){if(!this.visualizeJs)return null;this.syncOverlay();const e=this.visViewer().getMarkupModel().appendEntity(t),i=e.openObject(),s=this.getMarkupColor();return i.setColor(s.r,s.g,s.b),i.setLineWeight(2),i.delete(),this.update(),e}getMarkupColor(){return console.warn("Viewer.getMarkupColor() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.getMarkupColor() instead."),this._markup.getMarkupColor()}setMarkupColor(t=255,e=0,i=0){console.warn("Viewer.setMarkupColor() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.setMarkupColor() instead."),this._markup.setMarkupColor(t,e,i)}colorizeAllMarkup(t=255,e=0,i=0){console.warn("Viewer.colorizeAllMarkup() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.colorizeAllMarkup() instead."),this._markup.colorizeAllMarkup(t,e,i)}colorizeSelectedMarkups(t=255,e=0,i=0){this._markup.colorizeSelectedMarkups(t,e,i)}scheduleUpdateAsync(t=50){return new Promise((e,i)=>{setTimeout(()=>{var s,r,n;try{this._enableAutoUpdate&&(null===(s=this.visViewer())||void 0===s||s.update(t),null===(n=null===(r=this._activeDragger)||void 0===r?void 0:r.updatePreview)||void 0===n||n.call(r)),this.emitEvent({type:"update",data:!1}),e()}catch(t){console.error(t),i()}},0)})}async updateAsync(t=50,e=50){if(this.visualizeJs){this._isRunAsyncUpdate=!0;try{const i=this.visViewer().getActiveDevice();for(let s=0;!i.isValid()&&s<e;s++)await this.scheduleUpdateAsync(t);await this.scheduleUpdateAsync(t)}catch(t){console.error(t)}finally{this._isRunAsyncUpdate=!1}}}deviceAutoRegeneration(){const t=this.visViewer();t.getActiveDevice().getOptionDouble(this.visLib().DeviceOptions.kRegenCoef)>1&&(t.regenAll(),this.update())}},t.commands=tt,t.commandsRegistry=s,t.components=lt,t.componentsRegistry=l,t.defaultOptions=p,t.draggers=q,t.draggersRegistry=a,t.loaders=wt,t.loadersRegistry=g});
24
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ODA=t.ODA||{},t.ODA.Visualize=t.ODA.Visualize||{}))}(this,function(t){"use strict";class e{constructor(){this._commands=new Map}registerCommand(t,e,i,s){this._commands.set(t,{id:t,handler:e,thisArg:s,description:i})}registerCommandAlias(t,e){this.registerCommand(e,(e,...i)=>this.executeCommand(t,e,...i))}getCommand(t){return this._commands.get(t)}getCommands(){const t=new Map;return this._commands.forEach((e,i)=>t.set(i,e)),t}executeCommand(t,e,...i){const s=this._commands.get(t);if(!s){if(e){if(e.draggers.includes(t))return e.setActiveDragger(t)}return void console.warn(`Command '${t}' not found`)}const{handler:r,thisArg:n}=s,a=r.apply(n,[e,...i]);return null==e||e.emit({type:"command",data:t,args:i}),a}}const i=new Map;function s(t=""){let s=i.get(t);return s||(s=new e,i.set(t,s)),s}class r{constructor(){this._providers=new Map}registerDragger(t,e){this._providers.set(t,e)}registerDraggerAlias(t,e){const i=this._providers.get(t);i&&this.registerDragger(e,t=>i(t))}getDraggers(){const t=new Map;return this._providers.forEach((e,i)=>t.set(i,e)),t}createDragger(t,e){const i=this._providers.get(t);if(!i)return null;const s=i(e);return s.name=t,s}}const n=new Map;function a(t=""){let e=n.get(t);return e||(e=new r,n.set(t,e)),e}class o{constructor(){this._providers=new Map}registerComponent(t,e){this._providers.set(t,e)}registerComponentAlias(t,e){const i=this._providers.get(t);i&&this.registerComponent(e,t=>i(t))}getComponents(){const t=new Map;return this._providers.forEach((e,i)=>t.set(i,e)),t}createComponent(t,e){const i=this._providers.get(t);if(!i)return null;const s=i(e);return s.name=t,s}}const h=new Map;function l(t=""){let e=h.get(t);return e||(e=new o,h.set(t,e)),e}class d{constructor(){this.name="",this.abortController=new AbortController}dispose(){this.abortController.abort(),this.abortController=void 0}isSupport(t,e){return!1}load(t,e,i){return Promise.resolve(this)}cancel(){this.abortController.abort()}extractFileName(t){const e=/[^/\\?#:]+(?=\?|#|$)/;return"string"==typeof t?(t.match(e)||[])[0]:t instanceof globalThis.File?(t.name.match(e)||[])[0]:void 0}}class c{constructor(){this._providers=new Map}registerLoader(t,e){this._providers.set(t,e)}getLoader(t){return this._providers.get(t)}getLoaders(){const t=new Map;return this._providers.forEach((e,i)=>t.set(i,e)),t}createLoader(t,e,i){let s=null;return this._providers.forEach((r,n)=>{const a=r(t);a.isSupport(e,i)&&(s=a,s.name=n)}),s}}const u=new Map;function g(t=""){let e=u.get(t);return e||(e=new c,u.set(t,e)),e}function p(){return{showWCS:!0,cameraAnimation:!0,antialiasing:!0,groundShadow:!1,shadows:!1,cameraAxisXSpeed:4,cameraAxisYSpeed:1,ambientOcclusion:!1,enableStreamingMode:!0,enablePartialMode:!1,memoryLimit:3294967296,cuttingPlaneFillColor:{red:255,green:152,blue:0},edgesColor:{r:255,g:152,b:0},facesColor:{r:255,g:152,b:0},edgesVisibility:!0,edgesOverlap:!0,facesOverlap:!1,facesTransparancy:200,enableCustomHighlight:!0,sceneGraph:!1,edgeModel:!0,reverseZoomWheel:!1,enableZoomWheel:!0,enableGestures:!0,geometryType:"vsfx",rulerUnit:"Default",rulerPrecision:2,cameraMode:"perspective"}}class m{constructor(t){this._emitter=t,this._data={showWCS:!0,cameraAnimation:!0,antialiasing:!0,groundShadow:!1,shadows:!1,cameraAxisXSpeed:4,cameraAxisYSpeed:1,ambientOcclusion:!1,enableStreamingMode:!0,enablePartialMode:!1,memoryLimit:3294967296,cuttingPlaneFillColor:{red:255,green:152,blue:0},edgesColor:{r:255,g:152,b:0},facesColor:{r:255,g:152,b:0},edgesVisibility:!0,edgesOverlap:!0,facesOverlap:!1,facesTransparancy:200,enableCustomHighlight:!0,sceneGraph:!1,edgeModel:!0,reverseZoomWheel:!1,enableZoomWheel:!0,enableGestures:!0,geometryType:"vsfx",rulerUnit:"Default",rulerPrecision:2,cameraMode:"perspective"},this.loadFromStorage()}static defaults(){return{showWCS:!0,cameraAnimation:!0,antialiasing:!0,groundShadow:!1,shadows:!1,cameraAxisXSpeed:4,cameraAxisYSpeed:1,ambientOcclusion:!1,enableStreamingMode:!0,enablePartialMode:!1,memoryLimit:3294967296,cuttingPlaneFillColor:{red:255,green:152,blue:0},edgesColor:{r:255,g:152,b:0},facesColor:{r:255,g:152,b:0},edgesVisibility:!0,edgesOverlap:!0,facesOverlap:!1,facesTransparancy:200,enableCustomHighlight:!0,sceneGraph:!1,edgeModel:!0,reverseZoomWheel:!1,enableZoomWheel:!0,enableGestures:!0,geometryType:"vsfx",rulerUnit:"Default",rulerPrecision:2,cameraMode:"perspective"}}notifierChangeEvent(){console.warn("Options.notifierChangeEvent() has been deprecated since 25.3 and will be removed in a future release, use Options.change() instead."),this.change()}change(){void 0!==this._emitter&&(this.saveToStorage(),this._emitter.emit({type:"optionschange",data:this}))}saveToStorage(){if("undefined"!=typeof window)try{localStorage.setItem("od-client-settings",JSON.stringify(this.data))}catch(t){console.error("Cannot save client settings.",t)}}loadFromStorage(){if("undefined"!=typeof window)try{const t=localStorage.getItem("od-client-settings");if(t){const e=JSON.parse(t);this.data={...e}}}catch(t){console.error("Cannot load client settings.",t)}}resetToDefaults(t){if(void 0!==t){const e=m.defaults(),i=t.reduce((t,i)=>(t[i]=e[i],t),{});this.data={...this.data,...i}}else this.data={...this.data,...m.defaults()}}get data(){return this._data}set data(t){const e=!!t.enableStreamingMode&&t.enablePartialMode,i=!e&&t.sceneGraph;this._data={...m.defaults(),...this._data,...t,enablePartialMode:e,sceneGraph:i},this.change()}get showWCS(){return this._data.showWCS}set showWCS(t){this._data.showWCS=t,this.change()}get cameraAnimation(){return this._data.cameraAnimation}set cameraAnimation(t){this._data.cameraAnimation=t,this.change()}get antialiasing(){return this._data.antialiasing}set antialiasing(t){this._data.antialiasing=t,this.change()}get groundShadow(){return this._data.groundShadow}set groundShadow(t){this._data.groundShadow=t,this.change()}get shadows(){return this._data.shadows}set shadows(t){this._data.shadows=t,this.change()}get cameraAxisXSpeed(){return this._data.cameraAxisXSpeed}set cameraAxisXSpeed(t){this._data.cameraAxisXSpeed=t,this.change()}get cameraAxisYSpeed(){return this._data.cameraAxisYSpeed}set cameraAxisYSpeed(t){this.cameraAxisYSpeed=t,this.change()}get ambientOcclusion(){return this._data.ambientOcclusion}set ambientOcclusion(t){this._data.ambientOcclusion=t,this.change()}get enableStreamingMode(){return this._data.enableStreamingMode}set enableStreamingMode(t){this._data.enableStreamingMode=t,t||(this._data.enablePartialMode=!1),this.change()}get enablePartialMode(){return this._data.enablePartialMode}set enablePartialMode(t){this._data.enablePartialMode=t,t&&(this._data.enableStreamingMode=!0,this._data.sceneGraph=!1),this.change()}get memoryLimit(){return this._data.memoryLimit}set memoryLimit(t){this._data.memoryLimit=t,this.change()}get cuttingPlaneFillColor(){return this._data.cuttingPlaneFillColor}set cuttingPlaneFillColor(t){this._data.cuttingPlaneFillColor=t,this.change()}get edgesColor(){return this._data.edgesColor}set edgesColor(t){this._data.edgesColor=t,this.change()}get facesColor(){return this._data.facesColor}set facesColor(t){this._data.facesColor=t,this.change()}get edgesVisibility(){return this._data.edgesVisibility}set edgesVisibility(t){this._data.edgesVisibility=t,this.change()}get edgesOverlap(){return this._data.edgesOverlap}set edgesOverlap(t){this._data.edgesOverlap=t,this.change()}get facesOverlap(){return this._data.facesOverlap}set facesOverlap(t){this._data.facesOverlap=t,this.change()}get facesTransparancy(){return this._data.facesTransparancy}set facesTransparancy(t){this._data.facesTransparancy=t,this.change()}get enableCustomHighlight(){return this._data.enableCustomHighlight}set enableCustomHighlight(t){this._data.enableCustomHighlight=t,this.change()}get sceneGraph(){return this._data.sceneGraph}set sceneGraph(t){this._data.sceneGraph=t,t&&(this._data.enablePartialMode=!1),this.change()}get edgeModel(){return Boolean(this._data.edgeModel)}set edgeModel(t){this._data.edgeModel=Boolean(t),this.change()}get reverseZoomWheel(){return this._data.reverseZoomWheel}set reverseZoomWheel(t){this._data.reverseZoomWheel=!!t,this.change()}get enableZoomWheel(){return this._data.enableZoomWheel}set enableZoomWheel(t){this._data.enableZoomWheel=!!t,this.change()}get enableGestures(){return this._data.enableGestures}set enableGestures(t){this._data.enableGestures=!!t,this.change()}get geometryType(){return this._data.geometryType}set geometryType(t){this._data.geometryType=t,this.change()}get rulerUnit(){return this._data.rulerUnit}set rulerUnit(t){this._data.rulerUnit=t,this.change()}get rulerPrecision(){return this._data.rulerPrecision}set rulerPrecision(t){this._data.rulerPrecision=t,this.change()}get cameraMode(){return this._data.cameraMode||"perspective"}set cameraMode(t){this._data.cameraMode=t,this.change()}}const f=["click","contextmenu","dblclick","mousedown","mouseleave","mousemove","mouseup","pointercancel","pointerdown","pointerleave","pointermove","pointerup","touchcancel","touchend","touchmove","touchstart","wheel"],_=f;class v{constructor(){this.performance={fps:0,frameTime:0,timeToFirstRender:0,loadTime:0},this.render={viewport:{width:0,height:0},antialiasing:"",drawCalls:0,triangles:0,points:0,lines:0},this.scene={objects:0,triangles:0,points:0,lines:0,edges:0},this.optimizedScene={objects:0,triangles:0,points:0,lines:0,edges:0},this.memory={geometries:0,geometryBytes:0,textures:0,textureBytes:0,materials:0,totalEstimatedGpuBytes:0,usedJSHeapSize:0},this.system={webglRenderer:"",webglVendor:""}}}class y{constructor(t){this.setViewParams=t=>{var e;const i=this.m_module.getViewer().getActiveTvExtendedView();i.setView(t.position,t.target,t.upVector,t.viewFieldWidth,t.viewFieldHeight,t.perspective),null===(e=i.delete)||void 0===e||e.call(i)},this.getViewParams=()=>{var t;const e=this.m_module.getViewer().activeView,i={position:e.viewPosition,target:e.viewTarget,upVector:e.upVector,viewFieldWidth:e.viewFieldWidth,viewFieldHeight:e.viewFieldHeight,perspective:e.perspective};return null===(t=e.delete)||void 0===t||t.call(e),i},this.m_module=t}getViewer(){return this.m_module.getViewer()}getModel(){return this.getViewer().getMarkupModel()}copyPoint(t){const e=new this.m_module.Point3d;return e.set(t.x,t.y,t.z),e}createVector3d(){return new this.m_module.Vector3d}createPoint3d(){return new this.m_module.Point3d}createMatrix3d(){return new this.m_module.Matrix3d}createPlane(){return new this.m_module.OdTvPlane}toVector(t){return this.m_module.Vector3d.createFromArray(t)}toGeVector(t){return[t.x,t.y,t.z]}toGePoint(t){return[t.x,t.y,t.z]}toPoint(t){return this.m_module.Point3d.createFromArray(t)}screenToWorld(t,e){return this.toPoint(this.m_module.getViewer().screenToWorld(t,e))}toDoubleArray(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x),e.push(t[i].y),e.push(t[i].z);return e}correctCameraTarget(){const t=this.getViewParams(),e=this.m_module.getViewer().getActiveExtents(),{min:i,max:s}=e,r=this.toPoint(t.target);r.x>=i.x&&r.y>=i.y&&r.z>=i.z&&r.x<=s.x&&r.y<=s.y&&r.z<=s.z||(t.target=e.center(),this.setViewParams(t))}}class w extends y{constructor(t){super(t.visualizeJs),this.beginInteractivity=()=>{const t=this.getViewer().activeView;t.beginInteractivity&&(t.beginInteractivity(24),this.subject.update()),t.delete()},this.endInteractivity=()=>{const t=this.getViewer().activeView;if(t.endInteractivity){t.endInteractivity();const e=this.getViewer().getActiveDevice(),i=this.m_module.canvas;e.invalidate([0,0,i.width,i.height]),e.delete(),this.subject.update()}t.delete()},this.subject=t,this.needInputText=!1,this.mouseDownPosition={x:0,y:0},this.autoSelect=!1,this.onmessage=t=>this.subject.emitEvent(t),this.canvasEvents=_}initialize(){this.canvasEvents=this.canvasEvents.filter(t=>"function"==typeof this[t]),this.canvasEvents.forEach(t=>this[t]=this[t].bind(this)),this.canvasEvents.forEach(t=>this.subject.on(t,this[t])),this.getViewer().setEnableAutoSelect(!!this.autoSelect)}dispose(){this.canvasEvents.forEach(t=>this.subject.off(t,this[t]))}relativeCoords(t){return{x:t.offsetX*window.devicePixelRatio,y:t.offsetY*window.devicePixelRatio}}pointerdown(t){if(!t.isPrimary||w.isGestureActive)return;t.target.setPointerCapture(t.pointerId);const e=this.relativeCoords(t);this.isDragging=!0,this.mouseDownPosition={x:e.x,y:e.y},this.start(e.x,e.y,t.clientX,t.clientY),this.subject.update()}pointerup(t){if(w.needSkipPointerUp)return;if(!t.isPrimary)return;t.target.releasePointerCapture(t.pointerId);const e=this.relativeCoords(t);this.end(e.x,e.y,t.clientX,t.clientY),this.isDragging=!1,this.subject.update()}pointercancel(t){t.isPrimary&&this.m_module.canvas.dispatchEvent(new PointerEvent("pointerup",t))}pointermove(t){if(!t.isPrimary||w.isGestureActive)return;const e=this.relativeCoords(t);this.drag(e.x,e.y,t.clientX,t.clientY),this.isDragging&&this.subject.update()}click(t){const e=this.getViewer(),i=this.relativeCoords(t),s=i.x,r=i.y,n=Math.abs(s-this.mouseDownPosition.x)<5&&Math.abs(r-this.mouseDownPosition.y)<5;if(e&&e.getEnableAutoSelect()&&n){e.unselect(),e.select(s,r,s,r),this.subject.update();const t=e.getSelected();this.onmessage({type:"select",data:t,handles:this.subject.getSelected()}),this.onmessage({type:"select2",data:t,handles:this.subject.getSelected2()})}}dblclick(t){const e=this.getViewer(),i=this.relativeCoords(t),s=i.x,r=i.y,n=e.getActiveDevice(),a=n.viewAt([s,r]);if(a&&!a.active)e.activeView=a,a.delete(),this.subject.update();else if(e&&e.getEnableAutoSelect()){const t=e.getSelected();if(!t.isNull()&&0!==t.numItems()){const i=t.getIterator(),s=i.getEntity();e.zoomToEntity(s),this.onmessage({type:"zoomtoentity",data:s}),this.subject.update(),this.deleteAll([i,s])}}n.delete()}start(t,e,i=0,s=0){}drag(t,e,i=0,s=0){}end(t,e,i=0,s=0){}getActiveMarkupEntity(t){return this.subject.addMarkupEntity(t)}syncOverlayView(){return this.subject.syncOverlay()}deleteAll(t){var e;for(const i of t)null===(e=null==i?void 0:i.delete)||void 0===e||e.call(i)}updatePreview(){}static set isGestureActive(t){w._isGestureActive!==t&&(w._isGestureActive=t,w._isGestureActive&&(w.needSkipPointerUp=!0))}static get isGestureActive(){return w._isGestureActive}static get needSkipPointerUp(){return!!w._needSkipPointerUp&&(w.needSkipPointerUp=!1,!0)}static set needSkipPointerUp(t){w._needSkipPointerUp=t}}function x(t,e,i){return t||((t=document.createElement("div")).setAttribute("data-testid",i),e.appendChild(t)),t}function b(t,e){return t&&e.removeChild(t),null}function S(t,e,i){const s=e.Point3d.createFromArray(t),r=i.activeView,n=r.worldToDeviceMatrix,a=s.transformBy(n),o={x:a.x/window.devicePixelRatio,y:a.y/window.devicePixelRatio};return n.delete(),s.delete(),a.delete(),r.delete(),o}function C(t){return t<0?Math.ceil(t):Math.floor(t)}w._isGestureActive=!1,w._needSkipPointerUp=!1;function A(t,e,i,s,r){const n=((t,e,i,s)=>{const r=e.x-t.x,n=e.y-t.y,a=s.x-i.x,o=s.y-i.y,h=(-n*(t.x-i.x)+r*(t.y-i.y))/(-a*n+r*o),l=(+a*(t.y-i.y)-o*(t.x-i.x))/(-a*n+r*o);return h>=0&&h<=1&&l>=0&&l<=1&&{x:C(t.x+l*r),y:C(t.y+l*n)}})(t,e,i,s);n&&r.push(n)}function T(t,e,i){return t.x<=e&&t.x>=0&&t.y<=i&&t.y>=0}function k(t,e){t&&(t.onclick=e?()=>e():()=>{})}function P(t,e){t.style.pointerEvents=e?"auto":"none"}class E{constructor(t,e,i){this.htmlElemStartPoint=null,this.htmlElemEndPoint=null,this.htmlElemLine=null,this.htmlElemTitle=null,this.startPoint=null,this.endPoint=null,this.scale=1,this.unit="",this.precision=2,this.size=10,this.lineThickness=2,this.style={border:"2px solid #FFFFFF",background:"#009bff",color:"white",boxShadow:"0 0 10px rgba(0,0,0,0.5)"},this.htmlElemStartPoint=x(this.htmlElemStartPoint,t,"ruler-start"),this.htmlElemEndPoint=x(this.htmlElemEndPoint,t,"ruler-end"),this.htmlElemLine=x(this.htmlElemLine,t,"ruler-line"),this.htmlElemTitle=x(this.htmlElemTitle,t,"ruler-value"),this.viewer=e,this.moduleInstance=i,this.targetElement=t,this.isFinishDraw=!1}drawMeasureLine(){const t=this.size,e=this.moduleInstance.canvas.getBoundingClientRect();if(this.startPoint){this.htmlElemStartPoint=x(this.htmlElemStartPoint,this.targetElement,"ruler-start");const i=S(this.startPoint,this.moduleInstance,this.viewer);T(i,e.width,e.height)?(this.htmlElemStartPoint.style.display="block",this.htmlElemStartPoint.style.cursor="pointer",this.htmlElemStartPoint.style.position="absolute",this.htmlElemStartPoint.style.top=i.y-t/2+"px",this.htmlElemStartPoint.style.left=i.x-t/2+"px",this.htmlElemStartPoint.style.borderRadius=`${t}px`,this.htmlElemStartPoint.style.border=this.style.border,this.htmlElemStartPoint.style.background=this.style.background,this.htmlElemStartPoint.style.zIndex="2",this.htmlElemStartPoint.style.width=`${t}px`,this.htmlElemStartPoint.style.height=`${t}px`,this.htmlElemStartPoint.style.boxShadow=this.style.boxShadow):this.htmlElemStartPoint.style.display="none"}if(this.endPoint&&this.isFinishDraw){this.htmlElemEndPoint=x(this.htmlElemEndPoint,this.targetElement,"ruler-end");const i=S(this.endPoint,this.moduleInstance,this.viewer);T(i,e.width,e.height)?(this.htmlElemEndPoint.style.display="block",this.htmlElemEndPoint.style.cursor="pointer",this.htmlElemEndPoint.style.position="absolute",this.htmlElemEndPoint.style.top=i.y-t/2+"px",this.htmlElemEndPoint.style.left=i.x-t/2+"px",this.htmlElemEndPoint.style.borderRadius=`${t}px`,this.htmlElemEndPoint.style.border=this.style.border,this.htmlElemEndPoint.style.background=this.style.background,this.htmlElemEndPoint.style.zIndex="2",this.htmlElemEndPoint.style.width=`${t}px`,this.htmlElemEndPoint.style.height=`${t}px`,this.htmlElemEndPoint.style.boxShadow=this.style.boxShadow):this.htmlElemEndPoint.style.display="none"}if(this.endPoint&&this.startPoint){const t=S(this.startPoint,this.moduleInstance,this.viewer),i=S(this.endPoint,this.moduleInstance,this.viewer),{p1:s,p2:r,angle:n,width:a}=function(t,e,i,s){const r={x:0,y:0},n={x:i,y:0},a={x:0,y:s},o={x:i,y:s},h=[];A(t,e,r,n,h),A(t,e,r,a,h),A(t,e,a,o,h),A(t,e,o,n,h);let l=null,d=null;0===h.length?(l=t,d=e):1===h.length?T(t,i,s)?(l=t,d=h[0]):(l=h[0],d=e):(l=h[0],d=h[1]);const c=d.x-l.x,u=d.y-l.y;let g=180*Math.atan(u/c)/Math.PI;return c<0&&(g-=180),{angle:g,width:Math.sqrt(Math.pow(c,2)+Math.pow(u,2)),p1:l,p2:d}}(t,i,e.width,e.height),o=r.x-s.x,h=r.y-s.y,l=this.lineThickness;if(T(s,e.width,e.height)&&T(r,e.width,e.height)){this.htmlElemLine=x(this.htmlElemLine,this.targetElement,"ruler-line"),this.htmlElemLine.style.display="block",this.htmlElemLine.style.cursor="pointer",this.htmlElemLine.style.position="absolute",this.htmlElemLine.style.top=`${s.y}px`,this.htmlElemLine.style.left=`${s.x}px`,this.htmlElemLine.style.width=`${a}px`,this.htmlElemLine.style.transform=`rotate(${n}deg)`,this.htmlElemLine.style.transformOrigin=`0px ${l/2}px`,this.htmlElemLine.style.boxShadow=this.style.boxShadow,this.htmlElemLine.style.border="none",this.htmlElemLine.style.background=this.style.background,this.htmlElemLine.style.zIndex="1",this.htmlElemLine.style.height=`${l}px`;const t=this.getDistance(),e=s.x+o/2,i=s.y+h/2;this.htmlElemTitle=x(this.htmlElemTitle,this.targetElement,"ruler-value"),this.htmlElemTitle.style.display="block",this.htmlElemTitle.style.cursor="pointer",this.htmlElemTitle.style.font="10px",this.htmlElemTitle.style.color="white",this.htmlElemTitle.style.position="Absolute",this.htmlElemTitle.style.top=`${i}px`,this.htmlElemTitle.style.left=`${e}px`,this.htmlElemTitle.style.transform="translate(-50%, -50%)",this.htmlElemTitle.style.borderRadius="5px",this.htmlElemTitle.style.boxShadow=this.style.boxShadow,this.htmlElemTitle.style.border="none",this.htmlElemTitle.style.background=this.style.background,this.htmlElemTitle.style.zIndex="3",this.htmlElemTitle.style.padding="2px",this.htmlElemTitle.style.textAlign="center",this.htmlElemTitle.innerHTML=this.formatDistance(t)}else this.htmlElemLine.style.display="none",this.htmlElemTitle.style.display="none"}}getDistance(){let t=function(t,e,i){const s=i.Point3d.createFromArray(t),r=i.Point3d.createFromArray(e),n=s.distanceTo(r).toFixed(2);return s.delete(),r.delete(),n}(this.startPoint,this.endPoint,this.moduleInstance);return Math.abs(this.scale)>1e-10&&(t/=this.scale),t}calculatePrecision(t){const e=Math.abs(t);return e>=1e3?0:e>=10?1:e>=.1?2:e>=.001?3:e>0?Math.floor(-Math.log10(e))+1:2}formatDistance(t){let e;e="Auto"===this.precision?this.calculatePrecision(t):Number.isFinite(this.precision)?this.precision:parseFloat(this.precision),Number.isFinite(e)?e<0?e=0:e>10&&(e=10):e=2;let i=t.toFixed(e);return"Auto"===this.precision&&(i=i.replace(/\.0+$/,"").replace(/\.$/,"")),+i!==t&&(i="~ "+i),`${i} ${this.unit}`}setStartPoint(t){this.startPoint=t,this.drawMeasureLine()}setEndPoint(t,e){this.isFinishDraw=void 0===e||e,this.endPoint=t,this.drawMeasureLine()}update(){this.drawMeasureLine()}setSize(t){this.size=t,this.drawMeasureLine()}clear(){this.endPoint=null,this.startPoint=null,this.htmlElemStartPoint=b(this.htmlElemStartPoint,this.targetElement),this.htmlElemEndPoint=b(this.htmlElemEndPoint,this.targetElement),this.htmlElemLine=b(this.htmlElemLine,this.targetElement),this.htmlElemTitle=b(this.htmlElemTitle,this.targetElement)}setUnit(t){this.unit=t,this.drawMeasureLine()}setConversionFactor(t){this.scale=t,this.drawMeasureLine()}setPrecision(t){this.precision=t,this.drawMeasureLine()}setStyle(t){this.style=t,this.drawMeasureLine()}setSelectionReactor(t){k(this.htmlElemStartPoint,t?t.onStartPoint:null),k(this.htmlElemEndPoint,t?t.onEndPoint:null),k(this.htmlElemTitle,t?t.onTitle:null)}setSelectability(t){P(this.htmlElemStartPoint,t),P(this.htmlElemEndPoint,t),P(this.htmlElemLine,t),P(this.htmlElemTitle,t)}}function M(t,e){return t[e]||e}class I extends w{constructor(t){var e,i;super(t),this.lineThickness=2,this.press=!1,this.gripingRadius=5,this.firstPoint=null,this.secondPoint=null,this.rulerUnitTable={Millimeters:"mm",Centimeters:"cm",Meters:"m",Feet:"ft",Inches:"in",Yards:"yd",Kilometers:"km",Miles:"mi",Micrometers:"µm",Mils:"mil",MicroInches:"µin",Default:"unit"},this.rulerUnit=null!==(e=t.options.rulerUnit)&&void 0!==e?e:"Default",this.rulerPrecision=null!==(i=t.options.rulerPrecision)&&void 0!==i?i:"Default",this.items=[],this.canvasEvents.push("resize","optionsChange")}initialize(){super.initialize(),this.m_overlayElement=document.createElement("div"),this.m_overlayElement.style.background="rgba(0,0,0,0)",this.m_overlayElement.style.position="fixed",this.m_overlayElement.style.zIndex="1",this.m_overlayElement.style.pointerEvents="none",document.body.appendChild(this.m_overlayElement),this.subject.addEventListener("optionschange",this.optionsChange),this.resize()}dispose(){super.dispose(),this.m_overlayElement.remove(),this.subject.removeEventListener("optionschange",this.optionsChange)}updatePreview(){this.items.forEach(t=>t.update())}resize(){const t=this.m_module.canvas.getBoundingClientRect();this.m_overlayElement.style.top=`${t.top}px`,this.m_overlayElement.style.left=`${t.left}px`,this.m_overlayElement.style.width=`${t.width}px`,this.m_overlayElement.style.height=`${t.height}px`}getSnapPointRadius(){const t=this.getViewer().activeView.viewDcCorners(),e=t.lowerLeft,i=t.upperRight;return i[0]-=e[0],i[1]-=e[1],Math.min(i[0],i[1])/120}start(t,e){this.createNewMeasureIfNeed();const i=this.getViewer().getSnapPoint(t,e,this.gripingRadius);i&&(this.firstPoint=i,this.previewMeasureLine.setStartPoint(this.firstPoint))}drag(t,e){this.createNewMeasureIfNeed();const i=this.getViewer().getSnapPoint(t,e,this.gripingRadius);this.isDragging?i?this.firstPoint?(this.secondPoint=i,this.previewMeasureLine.setStartPoint(this.firstPoint),this.previewMeasureLine.setEndPoint(this.secondPoint,!0)):(this.firstPoint=i,this.previewMeasureLine.setStartPoint(this.firstPoint)):(this.secondPoint=null,this.previewMeasureLine.clear(),this.previewMeasureLine.setStartPoint(this.firstPoint),this.previewMeasureLine.setEndPoint(this.getViewer().screenToWorld(t,e),!1)):i?this.previewMeasureLine.setStartPoint(i):this.previewMeasureLine.clear()}end(){if(this.firstPoint&&this.secondPoint){const t=this.createMeasureLine();t.setStartPoint(this.firstPoint),t.setEndPoint(this.secondPoint,!0)}this.firstPoint=null,this.secondPoint=null,this.previewMeasureLine.clear()}createNewMeasureIfNeed(){this.previewMeasureLine||(this.previewMeasureLine=this.createMeasureLine())}createMeasureLine(){const t=this.m_module.getViewer(),e=new E(this.m_overlayElement,t,this.m_module);e.lineThickness=this.lineThickness||e.lineThickness;const i="Default"===this.rulerUnit,s="Default"===this.rulerPrecision;if(e.setUnit(M(this.rulerUnitTable,i?t.getUnit():this.rulerUnit)),i)e.setConversionFactor(1);else{const i=this.getKUnitByName(t.getUnit()),s=this.getKUnitByName(this.subject.options.rulerUnit),r=t.getUnitsConversionCoef(i,s);this.conversionFactor=1/r,e.setConversionFactor(this.conversionFactor)}return s?e.setPrecision(2):e.setPrecision(this.rulerPrecision),this.items.push(e),e}optionsChange(t){var e,i;const s=t.data,r=null!==(e=s.rulerUnit)&&void 0!==e?e:"Default",n=null!==(i=s.rulerPrecision)&&void 0!==i?i:"Default",a=this.rulerUnit!==r,o=this.rulerPrecision!==n;if(!a&&!o)return;this.rulerUnit=r,this.rulerPrecision=n;const h=this.m_module.getViewer().getUnit(),l=this.getKUnitByName(r),d=this.getKUnitByName(h);this.items.forEach(t=>{if(a)if("Default"===r)t.setUnit(M(this.rulerUnitTable,h)),t.setConversionFactor(1);else{t.setUnit(M(this.rulerUnitTable,r));const e=this.m_module.getViewer().getUnitsConversionCoef(d,l);this.conversionFactor=1/e,t.setConversionFactor(this.conversionFactor)}o&&("Default"===n?t.setPrecision(2):t.setPrecision(n))})}getKUnitByName(t){let e=this.m_module.Units.kUserDefined;switch(t){case"Millimeters":e=this.m_module.Units.kMillimeters;break;case"Centimeters":e=this.m_module.Units.kCentimeters;break;case"Meters":e=this.m_module.Units.kMeters;break;case"Feet":e=this.m_module.Units.kFeet;break;case"Inches":e=this.m_module.Units.kInches;break;case"Yards":e=this.m_module.Units.kYards;break;case"Kilometers":e=this.m_module.Units.kKilometers;break;case"Miles":e=this.m_module.Units.kMiles;break;case"Micrometers":e=this.m_module.Units.kMicrometers;break;case"Mils":e=this.m_module.Units.kMils;break;case"MicroInches":e=this.m_module.Units.kMicroInches}return e}}class R{constructor(t,e,i,s){this.hasEventListeners=!1;const r="#35436E";this.container=e,this.container.style.touchAction="none",this.canvas=document.createElement("canvas"),this.canvas.id="odJoyStickCanvas",this.canvas.width=200,this.canvas.height=200,this.container.appendChild(this.canvas);const n=this.canvas.getContext("2d");let a=0;const o=2*Math.PI,h=(this.canvas.width-(this.canvas.width/2+10))/2,l=h+5,d=h+30,c=this.canvas.width/2,u=this.canvas.height/2;let g=c,p=u;this.onMouseDown=()=>{event.preventDefault(),a=1},this.onMouseMove=e=>{e.preventDefault(),1===a&&(g=e.pageX,p=e.pageY,this.canvas.offsetParent&&"BODY"===this.canvas.offsetParent.tagName.toUpperCase()?(g-=this.canvas.offsetLeft,p-=this.canvas.offsetTop):this.canvas.offsetParent&&(g-=this.canvas.offsetParent.offsetLeft,p-=this.canvas.offsetParent.offsetTop),n.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawExternal(),this.drawInternal(),i({x:(g-c)/l*100,y:(p-u)/l*100*-1,global:t}))},this.onMouseUp=()=>{event.preventDefault(),a=0,g=c,p=u,n.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawExternal(),this.drawInternal(),i({x:(g-c)/l*100,y:(p-u)/l*100*-1,global:t})},this.drawExternal=()=>{n.beginPath(),n.arc(c,u,d,0,o,!1),n.lineWidth=2,n.strokeStyle=r,n.globalAlpha=.5,n.stroke()},this.drawInternal=()=>{n.beginPath(),g<h&&(g=l),g+h>this.canvas.width&&(g=this.canvas.width-l),p<h&&(p=l),p+h>this.canvas.height&&(p=this.canvas.height-l),n.arc(g,p,h,0,o,!1),n.fillStyle=r,n.lineWidth=2,n.strokeStyle="#003300",n.globalAlpha=.5,n.fill(),n.stroke()};const m=()=>{this.hasEventListeners||(this.canvas.addEventListener("pointerdown",this.onMouseDown,!1),document.addEventListener("pointermove",this.onMouseMove,!1),document.addEventListener("pointerup",this.onMouseUp,!1),this.hasEventListeners=!0)},f=()=>{this.hasEventListeners&&(this.canvas.removeEventListener("pointerdown",this.onMouseDown,!1),document.removeEventListener("pointermove",this.onMouseMove,!1),document.removeEventListener("pointerup",this.onMouseUp,!1),this.hasEventListeners=!1)},_=()=>{if(s){const t=s.getBoundingClientRect();this.container.style.top=t.height-200+"px",this.container.style.left=`${t.left}px`,this.container.style.width="200px",this.container.style.height="200px"}},v=()=>{const t=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),e=window.innerWidth<1024;t||e?(this.container.style.display="block",m()):(this.container.style.display="none",f())};this.onResize=()=>{v(),setTimeout(_,500)},v(),_(),window.addEventListener("resize",this.onResize,!1),this.drawExternal(),this.drawInternal()}cleanup(){window.removeEventListener("resize",this.onResize,!1),this.hasEventListeners&&(this.canvas.removeEventListener("pointerdown",this.onMouseDown,!1),document.removeEventListener("pointermove",this.onMouseMove,!1),document.removeEventListener("pointerup",this.onMouseUp,!1),this.hasEventListeners=!1),this.canvas.remove()}}class D extends w{constructor(t){super(t),this.viewer=void 0,this.multiplier=5,this.baseSpeed=1,this.keyPressMap=new Set,this.keydown=this.keydown.bind(this),this.keyup=this.keyup.bind(this),this.lastFrameTS=0,this.lastFrameJoyStickTS=0,this.animationId=void 0,this.processMovement=this.processMovement.bind(this),this.processJoyStickMovement=this.processJoyStickMovement.bind(this),this.deltaAngle=Math.PI/3600,this.autoSelect=!0,this.isJoyStickMoving=!1,this.addJoyStickDragger(t.canvas.parentElement)}initialize(){super.initialize(),this.viewer=this.getViewer(),window.addEventListener("keydown",this.keydown,!1),window.addEventListener("keyup",this.keyup,!1),this.oldWCSEnableValue=this.viewer.getEnableWCS(),this.viewer.setEnableWCS(!1);const t=this.viewer.activeView,e=this.getMaxDimension(t);this.baseSpeed=e/3e4,this.subject.emitEvent({type:"walkstart"}),this.viewParams=this.getViewParams(),this.setViewParams(this.viewParams);const i=this.viewer.getActiveModel();this.cameraId=i.appendCamera("Camera0"),this.setupCamera(t),i.delete(),this.cameraWalker=new this.m_module.OdTvCameraWalker,this.cameraWalker.setCamera(this.cameraId),this.subject.update(),this.enableZoomWheelPreviousValue=this.subject.options.enableZoomWheel,this.subject.options.enableZoomWheel=!1}dispose(){var t;if(this.oldWCSEnableValue=void 0!==this.oldWCSEnableValue?this.oldWCSEnableValue:this.subject.options.showWCS,this.viewer.setEnableWCS(this.oldWCSEnableValue),super.dispose(),this.keyPressMap.clear(),window.removeEventListener("keydown",this.keydown),window.removeEventListener("keyup",this.keyup),this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0),this.cameraId){const e=this.viewer.getActiveModel();e.removeEntity(this.cameraId),e.delete(),null===(t=this.cameraWalker)||void 0===t||t.delete()}if(this.viewParams){this.setViewParams(this.viewParams);this.viewer.activeView.delete()}this.subject.update(!0),this.subject.options.enableZoomWheel=this.enableZoomWheelPreviousValue,this.joyStickOverlayElement.remove(),this.joyStickDragger.cleanup()}keydown(t){switch(t.code){case"NumpadSubtract":case"Minus":this.multiplier>1&&(this.multiplier=this.multiplier-1,this.subject.emitEvent({type:"walkspeedchange",data:this.multiplier}));break;case"NumpadAdd":case"Equal":this.multiplier<10&&(this.multiplier=this.multiplier+1,this.subject.emitEvent({type:"walkspeedchange",data:this.multiplier}));break;case"KeyW":case"KeyA":case"KeyS":case"KeyD":case"KeyQ":case"KeyE":this.keyPressMap.add(t.code),this.animationId||this.processMovement(0)}}keyup(t){this.keyPressMap.delete(t.code),this.keyPressMap.size<1&&this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameTS=0)}processMovement(t){if(this.animationId=requestAnimationFrame(this.processMovement),0!==this.lastFrameTS){const e=t-this.lastFrameTS;if(e>0){const t=this.multiplier*e*this.baseSpeed;Array.from(this.keyPressMap).forEach(e=>{switch(e){case"KeyW":this.moveForward(t);break;case"KeyS":this.moveBackward(t);break;case"KeyA":this.cameraWalker.moveLeft(t);break;case"KeyD":this.cameraWalker.moveRight(t);break;case"KeyQ":this.cameraWalker.moveUp(t);break;case"KeyE":this.cameraWalker.moveDown(t)}}),this.proceedChangeCamera()}}this.lastFrameTS=t}start(t,e){this.dragPosition={x:t,y:e}}drag(t,e){if(this.cameraId&&this.isDragging){const i=t-this.dragPosition.x,s=e-this.dragPosition.y;this.dragPosition={x:t,y:e},0!==i&&this.turnLeft(-i*this.deltaAngle),0!==s&&this.cameraWalker.turnDown(s*this.deltaAngle),this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}moveForward(t){const{Vector3d:e}=this.m_module,i=this.cameraWalker.camera().openObjectAsCamera(),s=e.createFromArray(i.target()),r=e.createFromArray(i.direction()),n=e.createFromArray(i.upVector()),a=e.createFromArray(i.position());let o=e.createFromArray([r.x,r.y,0]);Math.abs(r.x)>.001&&Math.abs(r.y)>.001?o.setToProduct(o.normalize(),t):o=e.createFromArray([0,t,0]);const h=a.add(o),l=s.add(o);i.setupCamera(h.toArray(),l.toArray(),n.toArray())}moveBackward(t){this.moveForward(-t)}turnLeft(t){const e=this.cameraWalker.camera().openObjectAsCamera(),i=this.toVector(e.direction()),s=this.toVector(e.upVector()),r=e.position(),n=this.createMatrix3d();n.setToRotation(t,[0,0,1],r),i.transformBy(n),s.transformBy(n),e.setupCameraByDirection(r,i.toArray(),s.toArray()),e.delete()}setupCamera(t){const e=this.cameraId.openObjectAsCamera(),i=t.viewTarget;e.setDisplayGlyph(!1),e.setDisplayTarget(!1),e.setAutoAdjust(!0),e.setupCamera(t.viewPosition,i,t.upVector),e.setNearClip(!1,1),e.setFarClip(!1,0),e.setViewParameters(t.viewFieldWidth,t.viewFieldHeight,!0);const s=(r=t.lensLength,n=t.viewFieldWidth,a=t.viewFieldHeight,r/42*Math.sqrt(n*n+a*a));var r,n,a;const o=this.toPoint(t.viewTarget),h=this.toPoint(t.viewPosition),l=h.sub(o),d=l.asVector(),c=d.normalize(),u=this.toGeVector(c),g=[u[0]*s,u[1]*s,u[2]*s],p=this.toPoint(t.viewTarget),m=this.toPoint(g),f=p.add(m);e.setupCamera(this.toGePoint(f),t.viewTarget,t.upVector),this.deleteAll([o,h,l,d,c,p,m,f]),e.assignView(t),e.delete()}getMaxDimension(t){const[e,i,s]=t.sceneExtents.max(),[r,n,a]=t.sceneExtents.min(),o=[e-r,i-n,s-a];return Math.max(...o)}addJoyStickDragger(t){this.joyStickOverlayElement=document.createElement("div"),this.joyStickOverlayElement.id="joyStickDiv",this.joyStickOverlayElement.style.background="rgba(0,0,0,0)",this.joyStickOverlayElement.style.position="fixed",this.joyStickOverlayElement.style.zIndex="0",t.appendChild(this.joyStickOverlayElement),this.joyStickDragger=new R(this,this.joyStickOverlayElement,t=>{Math.sqrt(t.x*t.x+t.y*t.y)>20?(this.lastJoyStickCoord={x:t.x,y:t.y},this.animationId||this.isJoyStickMoving||(this.isJoyStickMoving=!0,this.processJoyStickMovement(0))):(this.isJoyStickMoving=!1,window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameJoyStickTS=0)},this.m_module.canvas)}processJoyStickMovement(t){if(this.isJoyStickMoving){if(this.animationId=requestAnimationFrame(this.processJoyStickMovement),0!==this.lastFrameJoyStickTS){const e=t-this.lastFrameJoyStickTS;if(e>0){const t=100,i=this.lastJoyStickCoord.y/t,s=this.lastJoyStickCoord.x/t,r=this.multiplier*e*this.baseSpeed;this.moveTotal(r,i,s)}}this.lastFrameJoyStickTS=t}}moveTotal(t,e,i){0!==e&&this.moveForward(t*e),0!==i&&this.cameraWalker.moveRight(t*i),this.proceedChangeCamera()}proceedChangeCamera(){this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}class L extends w{constructor(t){super(t),this.viewer=void 0,this.multiplier=5,this.speed=1,this.keyPressMap=new Set,this.keydown=this.keydown.bind(this),this.keyup=this.keyup.bind(this),this.lastFrameTS=0,this.lastFrameJoyStickTS=0,this.animationId=void 0,this.processMovement=this.processMovement.bind(this),this.processJoyStickMovement=this.processJoyStickMovement.bind(this),this.deltaAngle=Math.PI/3600,this.autoSelect=!0,this.isJoyStickMoving=!1,this.addJoyStickDragger(t.canvas.parentElement)}initialize(){super.initialize(),this.viewer=this.getViewer(),window.addEventListener("keydown",this.keydown,!1),window.addEventListener("keyup",this.keyup,!1),this.oldWCSEnableValue=this.viewer.getEnableWCS(),this.viewer.setEnableWCS(!1);const t=this.viewer.activeView,e=this.getMaxDimension(t);this.speed=e/3e4,this.subject.emitEvent({type:"flystart"}),this.viewParams=this.getViewParams(),this.setViewParams(this.viewParams);const i=this.viewer.getActiveModel();this.cameraId=i.appendCamera("Camera0"),this.setupCamera(t),i.delete(),this.cameraFlyer=new this.m_module.OdTvCameraWalker,this.cameraFlyer.setCamera(this.cameraId),this.subject.update(),this.enableZoomWheelPreviousValue=this.subject.options.enableZoomWheel,this.subject.options.enableZoomWheel=!1}dispose(){var t;if(this.oldWCSEnableValue=void 0!==this.oldWCSEnableValue?this.oldWCSEnableValue:this.subject.options.showWCS,this.viewer.setEnableWCS(this.oldWCSEnableValue),super.dispose(),this.keyPressMap.clear(),window.removeEventListener("keydown",this.keydown),window.removeEventListener("keyup",this.keyup),this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0),this.cameraId){const e=this.viewer.getActiveModel();e.removeEntity(this.cameraId),e.delete(),null===(t=this.cameraFlyer)||void 0===t||t.delete()}if(this.viewParams){this.setViewParams(this.viewParams);this.viewer.activeView.delete()}this.subject.update(!0),this.subject.options.enableZoomWheel=this.enableZoomWheelPreviousValue,this.joyStickOverlayElement.remove(),this.joyStickDragger.cleanup()}keydown(t){switch(t.code){case"NumpadSubtract":case"Minus":this.multiplier>1&&(this.multiplier=this.multiplier-1,this.subject.emitEvent({type:"flyspeedchange",data:this.multiplier}));break;case"NumpadAdd":case"Equal":this.multiplier<10&&(this.multiplier=this.multiplier+1,this.subject.emitEvent({type:"flyspeedchange",data:this.multiplier}));break;case"KeyW":case"KeyA":case"KeyS":case"KeyD":case"KeyQ":case"KeyE":this.keyPressMap.add(t.code),this.animationId||this.processMovement(0)}}keyup(t){this.keyPressMap.delete(t.code),this.keyPressMap.size<1&&this.animationId&&(window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameTS=0)}processMovement(t){if(this.animationId=requestAnimationFrame(this.processMovement),0!==this.lastFrameTS){const e=t-this.lastFrameTS,i=this.multiplier*e*this.speed;for(const t of this.keyPressMap)switch(t){case"KeyW":this.cameraFlyer.moveForward(i);break;case"KeyS":this.cameraFlyer.moveBackward(i);break;case"KeyA":this.cameraFlyer.moveLeft(i);break;case"KeyD":this.cameraFlyer.moveRight(i);break;case"KeyQ":this.cameraFlyer.moveUp(i);break;case"KeyE":this.cameraFlyer.moveDown(i)}this.subject.update(),this.subject.emitEvent({type:"changecamera"})}this.lastFrameTS=t}start(t,e){this.dragPosition={x:t,y:e}}drag(t,e){if(this.cameraId&&this.isDragging){const i=t-this.dragPosition.x,s=e-this.dragPosition.y;this.dragPosition={x:t,y:e},0!==i&&this.turnLeft(-i*this.deltaAngle),0!==s&&this.cameraFlyer.turnDown(s*this.deltaAngle),this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}turnLeft(t){const e=this.cameraFlyer.camera().openObjectAsCamera(),i=this.toVector(e.direction()),s=this.toVector(e.upVector()),r=e.position(),n=this.createMatrix3d();n.setToRotation(t,[0,0,1],r),i.transformBy(n),s.transformBy(n),e.setupCameraByDirection(r,i.toArray(),s.toArray()),e.delete()}setupCamera(t){const e=this.cameraId.openObjectAsCamera(),i=t.viewTarget;e.setDisplayGlyph(!1),e.setDisplayTarget(!1),e.setAutoAdjust(!0),e.setupCamera(t.viewPosition,i,t.upVector),e.setNearClip(!1,1),e.setFarClip(!1,0),e.setViewParameters(t.viewFieldWidth,t.viewFieldHeight,!0);const s=(r=t.lensLength,n=t.viewFieldWidth,a=t.viewFieldHeight,r/42*Math.sqrt(n*n+a*a));var r,n,a;const o=this.toPoint(t.viewTarget),h=this.toPoint(t.viewPosition),l=h.sub(o),d=l.asVector(),c=d.normalize(),u=this.toGeVector(c),g=[u[0]*s,u[1]*s,u[2]*s],p=this.toPoint(t.viewTarget),m=this.toPoint(g),f=p.add(m);e.setupCamera(this.toGePoint(f),t.viewTarget,t.upVector),this.deleteAll([o,h,l,d,c,p,m,f]),e.assignView(t),e.delete()}getMaxDimension(t){const[e,i,s]=t.sceneExtents.max(),[r,n,a]=t.sceneExtents.min(),o=[e-r,i-n,s-a];return Math.max(...o)}addJoyStickDragger(t){this.joyStickOverlayElement=document.createElement("div"),this.joyStickOverlayElement.id="joyStickDiv",this.joyStickOverlayElement.style.background="rgba(0,0,0,0)",this.joyStickOverlayElement.style.position="fixed",this.joyStickOverlayElement.style.zIndex="0",t.appendChild(this.joyStickOverlayElement),this.joyStickDragger=new R(this,this.joyStickOverlayElement,t=>{Math.sqrt(t.x*t.x+t.y*t.y)>20?(this.lastJoyStickCoord={x:t.x,y:t.y},this.animationId||this.isJoyStickMoving||(this.isJoyStickMoving=!0,this.processJoyStickMovement(0))):(this.isJoyStickMoving=!1,window.cancelAnimationFrame(this.animationId),this.animationId=void 0,this.lastFrameJoyStickTS=0)},this.m_module.canvas)}processJoyStickMovement(t){if(this.isJoyStickMoving){if(this.animationId=requestAnimationFrame(this.processJoyStickMovement),0!==this.lastFrameJoyStickTS){const e=t-this.lastFrameJoyStickTS;if(e>0){const t=100,i=this.lastJoyStickCoord.y/t,s=this.lastJoyStickCoord.x/t,r=this.multiplier*e*this.speed;this.moveTotal(r,i,s)}}this.lastFrameJoyStickTS=t}}moveTotal(t,e,i){0!==e&&(e>0?this.cameraFlyer.moveForward(t*e):this.cameraFlyer.moveBackward(t*Math.abs(e))),0!==i&&this.cameraFlyer.moveRight(t*i),this.subject.update(),this.subject.emitEvent({type:"changecamera"})}}class O extends w{constructor(t){super(t),this.press=!1;const e=this.getViewer().getActiveExtents(),i=e.min(),s=e.max();this.m_size_x=Math.abs(s[0]-i[0])/2,this.m_size_y=Math.abs(s[1]-i[1])/2,this.m_size_z=Math.abs(s[2]-i[2])/2,this.m_center=this.toPoint(e.center()),this.m_normal=this.createNormal();const r=this.getViewer().activeView,n=this.createPlane();n.set(this.toGePoint(this.m_center),this.m_normal),r.addCuttingPlane(n),this.index=r.numCuttingPlanes()-1;const{red:a,green:o,blue:h}=this.subject.options.cuttingPlaneFillColor;r.setEnableCuttingPlaneFill(!0,a,o,h),r.setCuttingPlaneFillPatternEnabled(!0,this.m_module.CuttingPlaneFillStyle.kHorizontalBars,0,0,0),this.m_model=this.getModel(),this.createPreview(),this.deleteAll([e,r,n])}dispose(){super.dispose(),this.m_entity&&(this.m_model.removeEntity(this.m_entity),this.deleteAll([this.m_model,this.m_entity,this.planePreview,this.m_center]),this.m_entity=null,this.planePreview=null,this.subject.update())}createNormal(){return[0,0,0]}handleDelta(t){return t}getPlanePreviewCoordinate(){return[]}start(t,e){this.press=!0,this.m_last=this.screenToWorld(t,e),this.m_click={x:t,y:e}}drag(t,e){if(this.press){const i=this.screenToWorld(t,e),s=this.handleDelta(i.sub(this.m_last)),r=this.m_center;this.m_center=r.add(s);const n=this.m_last;this.m_last=i;const a=this.getViewer().activeView,o=this.createPlane(),h=o.set(this.toGePoint(this.m_center),this.m_normal),l=a.updateCuttingPlane(this.index,o);this.drawPreview(),this.deleteAll([a,o,r,s,n,h,l]);const d=this.getViewer().getActiveDevice();d.invalidate(d.getSize())}}end(t,e){if(this.press=!1,t===this.m_click.x&&e===this.m_click.y){this.m_normal=[-1*this.m_normal[0],-1*this.m_normal[1],-1*this.m_normal[2]];const t=this.getViewer().activeView,e=this.createPlane();e.set(this.toGePoint(this.m_center),this.m_normal),t.updateCuttingPlane(this.index,e),this.deleteAll([t,e,this.m_last]);const i=this.getViewer().getActiveDevice();i.invalidate(i.getSize())}}createPreview(){this.m_entity=this.m_model.appendEntity("&CuttingPlanePreview");const t=this.m_module.GeometryTypes,e=new this.m_module.OdTvTransparencyDef,i=new this.m_module.OdTvColorDef(112,112,112);e.setValue(.9);const s=this.m_entity.openObject();s.setColor(i,t.kFaces.value),i.setColor(112,112,112),s.setColor(i,t.kEdges.value),s.setLineWeight(5),s.setTransparency(e,t.kFaces),e.setValue(1),s.setTransparency(e,t.kEdges),this.planePreview=s.appendPolygon(this.getPlanePreviewCoordinate());const r=this.planePreview.openAsPolygon();r.setFilled(!0),this.deleteAll([e,i,s,r,t]),this.subject.syncOverlay()}drawPreview(){const t=this.planePreview.openAsPolygon();t.setPoints(this.getPlanePreviewCoordinate()),this.deleteAll([t]),this.subject.syncOverlay()}}class z extends O{createNormal(){return[1,0,0]}handleDelta(t){return t.y=0,t.z=0,t}getPlanePreviewCoordinate(){return[this.m_center.x,this.m_center.y-this.m_size_y,this.m_center.z-this.m_size_z,this.m_center.x,this.m_center.y+this.m_size_y,this.m_center.z-this.m_size_z,this.m_center.x,this.m_center.y+this.m_size_y,this.m_center.z+this.m_size_z,this.m_center.x,this.m_center.y-this.m_size_y,this.m_center.z+this.m_size_z]}}class F extends O{createNormal(){return[0,1,0]}handleDelta(t){return t.x=0,t.z=0,t}getPlanePreviewCoordinate(){return[this.m_center.x-this.m_size_x,this.m_center.y,this.m_center.z-this.m_size_z,this.m_center.x+this.m_size_x,this.m_center.y,this.m_center.z-this.m_size_z,this.m_center.x+this.m_size_x,this.m_center.y,this.m_center.z+this.m_size_z,this.m_center.x-this.m_size_x,this.m_center.y,this.m_center.z+this.m_size_z]}}class G extends O{createNormal(){return[0,0,1]}handleDelta(t){return t.x=0,t.y=0,t}getPlanePreviewCoordinate(){return[this.m_center.x-this.m_size_x,this.m_center.y-this.m_size_y,this.m_center.z,this.m_center.x+this.m_size_x,this.m_center.y-this.m_size_y,this.m_center.z,this.m_center.x+this.m_size_x,this.m_center.y+this.m_size_y,this.m_center.z,this.m_center.x-this.m_size_x,this.m_center.y+this.m_size_y,this.m_center.z]}}class V{constructor(t,e,i,s){this._m_module=t,this._subject=e,this._beginInteractivity=i,this._endInteractivity=s}beginAction(t,e){this.m_viewCenter=this.getCenter(),this.m_startPoint={x:t,y:e};this.getViewer().activeView.delete(),this._beginInteractivity()}action(t,e){var i,s;const r=this.getViewer().activeView,n=r.vportRect,a=Math.max(Math.abs(n[2]-n[0]),Math.abs(n[3]-n[1])),o=(this.m_startPoint.x-t)*Math.PI/a,h=(this.m_startPoint.y-e)*Math.PI/a;this.m_startPoint.x=t,this.m_startPoint.y=e;const l=h,d=o,c={position:r.viewPosition,target:r.viewTarget,upVector:r.upVector,viewFieldWidth:r.viewFieldWidth,viewFieldHeight:r.viewFieldHeight,perspective:r.perspective};r.delete();const u=this.getSideVector(c);0!==l&&this.calculateXOrbit(c,-l,u),0!==d&&this.calculateYOrbit(c,d,u),u.delete();const g=this.getViewer().getActiveTvExtendedView();g.setView(c.position,c.target,c.upVector,c.viewFieldWidth,c.viewFieldHeight,c.perspective),g.delete(),null===(s=null===(i=this._subject.activeDragger())||void 0===i?void 0:i.updatePreview)||void 0===s||s.call(i),this._subject.emitEvent({type:"orbit"}),this._subject.emitEvent({type:"changecamera"})}endAction(){this._endInteractivity()}getSideVector(t){const e=this.toVector(t.upVector),i=this.toPoint(t.target),s=this.toPoint(t.position),r=i.sub(s),n=r.asVector();if(n.length()<1e-10){const t=this.toVector(this._m_module.Vector3d.kXAxis);return this.deleteAll([r,e,i,s,n]),t}const a=e.crossProduct(n);if(a.length()<1e-10){const t=this.toVector(this._m_module.Vector3d.kXAxis);return this.deleteAll([r,e,i,s,n,a]),t}const o=a.normalize();return this.deleteAll([r,e,i,s,n,a]),o}calculateXOrbit(t,e,i){{const s=this.toPoint(t.position),r=this.toPoint(this.m_viewCenter),n=s.rotateByBasePoint(e,i,r);t.position=n.toArray(),this.deleteAll([s,r,n])}{const s=this.toPoint(t.target),r=this.toPoint(this.m_viewCenter),n=s.rotateByBasePoint(e,i,r);t.target=n.toArray(),this.deleteAll([s,r,n])}{const e=this.toPoint(t.position),s=this.toPoint(t.target),r=s.sub(e),n=r.asVector();if(n.length()<1e-10)return void this.deleteAll([e,s,r,n]);const a=n.crossProduct(i);if(a.length()<1e-10)return void this.deleteAll([e,s,r,n,a]);const o=a.normalize();t.upVector=o.toArray(),this.deleteAll([e,s,r,n,a,o])}}calculateYOrbit(t,e,i){{const i=this.toPoint(t.position),s=this.toPoint(this.m_viewCenter),r=this.toVector(this._m_module.Vector3d.kZAxis),n=i.rotateByBasePoint(e,r,s);t.position=n.toArray(),this.deleteAll([r,i,s,n])}{const i=this.toPoint(t.target),s=this.toPoint(this.m_viewCenter),r=this.toVector(this._m_module.Vector3d.kZAxis),n=i.rotateByBasePoint(e,r,s);t.target=n.toArray(),this.deleteAll([r,i,s,n])}{const s=this.toVector(this._m_module.Vector3d.kZAxis),r=this.toPoint(t.target),n=this.toPoint(t.position),a=i.rotateBy(e,s),o=r.sub(n),h=o.asVector();if(h.length()<1e-10)return void this.deleteAll([s,r,n,a,o,h]);const l=h.crossProduct(a);if(l.length()<1e-10)return void this.deleteAll([s,r,n,a,o,h,l]);const d=l.normalize();t.upVector=d.toArray(),this.deleteAll([s,r,n,a,o,h,l,d])}}getCenter(){const t=this.getViewer();let e;const i=t.getSelected();if(i.isNull()||0===i.numItems())e=t.getActiveExtents().center();else{const t=i.getIterator();let s,r,n;for(;!t.done();t.step())r=t.getEntity(),s=r.getWCSExtents(),n?n.addExt(s):n=s;e=n.center(),n.delete(),t.delete()}return e}getViewer(){return this._m_module.getViewer()}toVector(t){return this._m_module.Vector3d.createFromArray(t)}toPoint(t){return this._m_module.Point3d.createFromArray(t)}deleteAll(t){var e;for(const i of t)null===(e=null==i?void 0:i.delete)||void 0===e||e.call(i)}}class W extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this._orbitAction=new V(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity)}start(t,e){this.press=!0,this._orbitAction.beginAction(t,e)}setDefaultViewParams(){const t=this.getViewer().getActiveTvExtendedView();t.setView(this.startCameraParams.position,this.startCameraParams.target,this.startCameraParams.upVector,this.startCameraParams.viewFieldWidth,this.startCameraParams.viewFieldHeight,this.startCameraParams.perspective),t.delete()}drag(t,e){this.press&&this._orbitAction.action(t,e)}end(){this.press=!1,this._orbitAction.endAction()}}class B{constructor(t,e,i,s,r,n){this._m_module=t,this._subject=e,this._beginInteractivity=i,this._endInteractivity=s,this._getViewParams=r,this._setViewParams=n}beginAction(t,e,i,s){this._m_start=this.screenToWorld(t,e),this._deltaScreenPosition={x:i,y:s},this._beginInteractivity()}action(t,e,i,s){var r,n;const{Vector3d:a}=this._m_module,o=this._getViewParams(),h=this.screenToWorld(t,e),l=this._m_start.sub(h).asVector(),d=a.createFromArray(o.target),c=d.add(l);o.target=c.toArray();const u=a.createFromArray(o.position),g=u.add(l);o.position=g.toArray(),this._setViewParams(o),d.delete(),c.delete(),u.delete(),g.delete(),null===(n=null===(r=this._subject.activeDragger())||void 0===r?void 0:r.updatePreview)||void 0===n||n.call(r),this._subject.emitEvent({type:"pan",x:i,y:s,dX:i-this._deltaScreenPosition.x,dY:s-this._deltaScreenPosition.y}),this._subject.emitEvent({type:"changecamera"}),this._deltaScreenPosition={x:i,y:s}}endAction(){this._endInteractivity()}screenToWorld(t,e){return this._m_module.Point3d.createFromArray(this._m_module.getViewer().screenToWorld(t,e))}}class N extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this._panAction=new B(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity,this.getViewParams,this.setViewParams)}start(t,e,i,s){this.press=!0,this._panAction.beginAction(t,e,i,s)}drag(t,e,i,s){this.press&&this._panAction.action(t,e,i,s)}end(t,e){this.press=!1,this._panAction.endAction()}}class j{constructor(t,e){this._m_module=t,this._subject=e}action(t,e,i,s,r){var n,a;this._m_module.getViewer().zoomAt(i,t,e),this._subject.deviceAutoRegeneration(),null===(a=null===(n=this._subject.activeDragger())||void 0===n?void 0:n.updatePreview)||void 0===a||a.call(n),this._subject.emitEvent({type:"zoomat",data:i,x:s,y:r}),this._subject.emitEvent({type:"changecamera"})}}class H extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this._zoomAction=new j(this.m_module,this.subject)}start(t,e,i=0,s=0){this.press=!0,this.pressX=t,this.pressY=e,this.absoluteX=i,this.absoluteY=s,this.prevY=e,this.beginInteractivity()}drag(t,e){const i=e-this.prevY;if(this.prevY=e,this.press&&Math.abs(i)>=1e-5){const t=.975,e=i>0?1/t:t;this._zoomAction.action(this.pressX,this.pressY,e,this.absoluteX,this.absoluteY)}}end(){this.press=!1,this.endInteractivity()}}class U extends w{constructor(t){super(t),this.canvasEvents=["wheel"],this._zoomAction=new j(this.m_module,this.subject),this._endInteractivityTimeOutId=void 0,this._isEnableInteractivityMode=!1}wheel(t){if(!this.subject.options.enableZoomWheel)return;(t=t||window.event).preventDefault();const e=this.subject.options.reverseZoomWheel?.925:1/.925,i=this.subject.options.reverseZoomWheel?1/.925:.925;if(this.getViewer()){const s=t.deltaY>0?e:i;this._zoomAction.action(t.offsetX*window.devicePixelRatio,t.offsetY*window.devicePixelRatio,s,t.offsetX,t.offsetY),this._isEnableInteractivityMode||(this._isEnableInteractivityMode=!0,this.beginInteractivity()),this._endInteractivityTimeOutId&&clearTimeout(this._endInteractivityTimeOutId),this._isEnableInteractivityMode||(this._isEnableInteractivityMode=!0,this.beginInteractivity()),this._endInteractivityTimeOutId&&clearTimeout(this._endInteractivityTimeOutId),this.subject.update(!0),this._endInteractivityTimeOutId=setTimeout(()=>{this._endInteractivityTimeOutId=void 0,this.endInteractivity(),this._isEnableInteractivityMode=!1},100)}}dispose(){this._endInteractivityTimeOutId&&(clearTimeout(this._endInteractivityTimeOutId),this.endInteractivity(),this._isEnableInteractivityMode=!1)}}class X{constructor(){this.m_start=[0,0,0],this.m_end=[0,0,0],this.m_model=null}createPoint3d(){return new this.m_module.Point3d}init(t,e){this.m_module=t,this.m_model=e}getViewer(){return this.m_module.getViewer()}setValue(t){this.m_end=t,this.draw()}setStartPoint(t){this.m_start=t,this.m_end=t,this.draw()}toDoubleArray(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].x),e.push(t[i].y),e.push(t[i].z);return e}draw(){const t=this.getViewer().activeView,e=t.viewingMatrix,i=[];i.push(this.m_start),i.push(this.createPoint3d()),i.push(this.m_end),i.push(this.createPoint3d());const s=this.createPoint3d();s.set(this.m_start[0],this.m_start[1],this.m_start[2]);const r=this.createPoint3d();r.set(this.m_end[0],this.m_end[1],this.m_end[2]),s.transformBy(e),r.transformBy(e),i[1].x=s.x,i[3].x=r.x,i[1].y=r.y,i[3].y=s.y,i[1].z=i[3].z=r.z;const n=t.eyeToWorldMatrix;if(i[1].transformBy(n),i[3].transformBy(n),this.m_entity)this.m_frame.openAsPolygon().setPoints(this.toDoubleArray(i));else{this.m_entity=this.m_model.appendEntity("");const t=this.m_entity.openObject();t.setColor(112,112,112),t.setLineWeight(2),this.m_frame=t.appendPolygon(this.toDoubleArray(i)),t.delete()}}clear(){this.m_entity&&(this.m_model.removeEntity(this.m_entity),this.m_entity=null)}}class Y extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this.needInputText=!1,this.m_frame=new X,this.m_frame.init(this.m_module,this.getModel())}start(t,e){this.press=!0,this.m_minX=t,this.m_minY=e;const i=this.screenToWorld(t,e);this.m_frame.setStartPoint(i)}drag(t,e){if(this.press){this.m_maxX=t,this.m_maxY=e;const i=this.screenToWorld(t,e);this.m_frame.setValue(i)}}end(t,e){this.press=!1,this.m_maxX=t,this.m_maxY=e,this.m_minX!==this.m_maxX&&this.m_minY!==this.m_maxY&&(this.m_frame.clear(),this.getViewer().zoomWindow(this.m_minX,this.m_minY,this.m_maxX,this.m_maxY))}}class J extends w{constructor(t){super(t),this.autoSelect=!0,this.press=!1,this.maxPolarAngle=Math.PI/2,this.minPolarAngle=0}start(t,e){this.press=!0,this.m_viewCenter=this.getCenter(),this.m_startPoint={x:t,y:e};const i=this.getViewer().activeView;this.startCameraParams=this.getViewParams();const s=i.vportRect;this.m_delta=Math.max(s[1]-s[0],s[2]-s[3]),this.beginInteractivity()}setDefaultViewParams(){this.setViewParams(this.startCameraParams)}drag(t,e){if(this.press){let i=t-this.m_startPoint.x,s=e-this.m_startPoint.y;i*=Math.PI/this.m_delta,s*=Math.PI/this.m_delta,this.setDefaultViewParams();const{Vector3d:r,Matrix3d:n}=this.m_module,a=r.createFromArray(this.startCameraParams.target),o=r.createFromArray(this.startCameraParams.position).sub(a),h=o.normalize(),l=new n;l.setToIdentity();const d=new n;d.setToIdentity();const c=r.createFromArray([h.x,h.y,h.z]),u=r.createFromArray(this.startCameraParams.upVector),g=c.crossProduct(u);let p=r.createFromArray([c.x,c.y,0]);p.length()<=1e-5?p.set(-g.y,g.x,0):p=p.normalize();i-=Math.sign(p.dotProduct(r.createFromArray([-1,0,0])))*p.angleTo(r.createFromArray([0,1,0]));let m=r.createFromArray([h.x,h.y,0]),f=0;m.length()<=1e-5?f=-h.z*Math.PI/2:(m=m.normalize(),f=-m.angleTo(h)),s-=f,l.setToRotation(-i,[0,0,1],[0,0,0]);const _=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,s));d.setToRotation(_,[1,0,0],[0,0,0]);const v=l.postMultBy(d);let y=r.createFromArray([0,1,0]).transformBy(v);const w=r.createFromArray([0,0,1]).transformBy(v);y.setLength(o.length()),y=a.add(y);const x=this.getViewParams();x.position=y.toArray(),x.upVector=w.toArray(),this.setViewParams(x)}}end(){this.press=!1,this.endInteractivity()}getCenter(){const t=this.getViewer();let e=t.getActiveExtents();const i=t.getSelected();if(!i.isNull()&&0!==i.numItems()){const t=i.getIterator(),s=t.getEntity();if(1===s.getType()){const t=s.openObject();e.delete(),e=t.getExtents(),t.delete()}else if(2===s.getType()){const t=s.openObjectAsInsert(),i=t.getExtents();e.delete(),e=i.ext,i.delete(),t.delete()}t.delete()}const s=e.center();return e.delete(),s}}const q=a("visualizejs");q.registerDragger("Pan",t=>new N(t)),q.registerDragger("Orbit",t=>new W(t)),q.registerDragger("Zoom",t=>new H(t)),q.registerDragger("ZoomWindow",t=>new Y(t)),q.registerDragger("ZoomWheel",t=>new U(t)),q.registerDragger("OrbitAroundBuilding",t=>new J(t)),q.registerDragger("MeasureLine",t=>new I(t)),q.registerDragger("CuttingPlaneXAxis",t=>new z(t)),q.registerDragger("CuttingPlaneYAxis",t=>new F(t)),q.registerDragger("CuttingPlaneZAxis",t=>new G(t)),q.registerDragger("Walk",t=>new D(t)),q.registerDragger("Fly",t=>new L(t));const K=(t,e,i)=>{const{translate:s,scale:r,rotation:n}=t,a=new i.Matrix3d;a.setTranslation([s.x,s.y,s.z]);const o=new i.Matrix3d;o.setToRotation(n.angle,[n.x,n.y,n.z],e);const h=new i.Matrix3d;return h.setToScaling(r,e),o.postMultBy(a).postMultBy(h)};function Z(t,e=0){if(!t.visualizeJs)return;t.visViewer().explode(e),t.update(),t.emitEvent({type:"explode",data:e})}function $(t,e=""){if(!t.visualizeJs)return;const i=t.visLib(),s=t.visViewer(),r=i.DefaultViewPosition;s.setDefaultViewPositionWithAnimation(r[e]),t.update(),t.emit({type:"viewposition",data:e})}function Q(t){return"$"===t.getName()[0]}const tt=s("visualizejs");tt.registerCommand("applyModelTransform",function(t,e){var i;if(!t.visualizeJs)return;if(!e.getModelTransformMatrix)return;const s=t.visLib(),r=t.visViewer(),n=r.getModelIterator();for(;!n.done();n.step()){const t=n.getModel(),i=e.getModelTransformMatrix(t.getDatabaseHandle());if(i){const e=t.getExtents();e.transformBy(t.getUnitsMatrix());const r=K(i,e.center(),s);t.setModelingMatrix(r,!0)}}n.delete(),null===(i=r.clearViewExtentsCache)||void 0===i||i.call(r),t.update()}),tt.registerCommand("clearMarkup",function(t){t.clearOverlay()}),tt.registerCommand("clearSelected",function(t){if(!t.visualizeJs)return;t.visViewer().unselect(),t.update(),t.emitEvent({type:"select",handles:[]}),t.emitEvent({type:"select2",handles:[]})}),tt.registerCommand("clearSlices",function(t){t.clearSlices()}),tt.registerCommand("createPreview",function(t,e="image/jpeg",i=.25){var s;return t.visualizeJs&&(null===(s=t.canvas)||void 0===s?void 0:s.toDataURL(e,i))||""}),tt.registerCommand("explode",Z),tt.registerCommand("collect",function(t){Z(t,0)}),tt.registerCommand("getDefaultViewPositions",function(t){if(!t.visualizeJs)return[];const e=t.visLib().DefaultViewPosition;return Object.keys(e).filter(t=>"values"!==t)}),tt.registerCommand("getModels",function(t){if(!t.visualizeJs)return[];const e=[],i=t.visViewer().getModelIterator();for(;!i.done();i.step()){const t=i.getModel();"$"!==t.getName()[0]&&e.push(t.getDatabaseHandle())}return i.delete(),e}),tt.registerCommand("getSelected",function(t){if(!t.visualizeJs)return[];const e=[],i=t.visViewer().getSelected();if(!i.isNull()&&0!==i.numItems()){const t=i.getIterator();for(;!t.done();t.step()){const i=t.getEntity(),s=1===i.getType()?i.openObject():2===i.getType()?i.openObjectAsInsert():null;if(s){const t=s.getNativeDatabaseHandle();"-1"!==t&&e.push(t),s.delete()}}t.delete()}return e}),tt.registerCommand("getSelected2",function(t){const e=t.executeCommand("getSelected"),i=t.models[0];return e.map(t=>`${i.id}:${t}`)}),tt.registerCommand("hideSelected",function(t){if(!t.visualizeJs)return;t.visViewer().hideSelectedObjects(!1),t.update(),t.emitEvent({type:"hide"}),t.emitEvent({type:"select",handles:[]}),t.emitEvent({type:"select2",handles:[]})}),tt.registerCommand("isolateSelected",function(t){if(!t.visualizeJs)return;t.visViewer().isolateSelectedObjects(!1),t.update(),t.emitEvent({type:"isolate"})}),tt.registerCommand("regenerateAll",function(t){if(!t.visualizeJs)return;t.visViewer().regenAll(),t.update(),t.emit({type:"regenerateall"})}),tt.registerCommand("resetView",function(t){t.visualizeJs&&(t.executeCommand("setActiveDragger"),t.executeCommand("clearSlices"),t.executeCommand("clearOverlay"),t.executeCommand("setMarkupColor"),t.executeCommand("clearSelected"),t.executeCommand("showAll"),t.executeCommand("explode",0),t.executeCommand("zoomToExtents",!0),t.emit({type:"resetview"}))}),tt.registerCommand("selectModel",function(t,e){if(!t.visualizeJs)return;const i=t.visViewer(),s=i.activeView,r=i.getModelIterator();for(;!r.done();r.step()){const n=r.getModel();if(n.getDatabaseHandle()===e){const e=s.selectCrossing([0,9999,9999,0],n);i.setSelected(e),t.update(),t.emitEvent({type:"select",handles:t.getSelected()}),t.emitEvent({type:"select2",handles:t.getSelected2()}),e.delete();break}}r.delete()}),tt.registerCommand("setActiveDragger",function(t,e=""){t.setActiveDragger(e)}),tt.registerCommand("setDefaultViewPosition",$),tt.registerCommand("setMarkupColor",function(t,e=255,i=0,s=0){t.markup.setMarkupColor(e,i,s)}),tt.registerCommand("setSelected",function(t,e=[]){if(!t.visualizeJs)return;const i=e.map(t=>t.slice(t.indexOf(":")+1)),s=t.visLib(),r=t.visViewer(),n=new s.OdTvSelectionSet;i.forEach(t=>{const e=r.getEntityByOriginalHandle(t+"");e.isNull()||n.appendEntity(e)}),r.setSelected(n),t.update(),t.emitEvent({type:"select",data:n,handles:i}),t.emitEvent({type:"select2",data:n,handles:e}),n.delete()}),tt.registerCommand("setSelected2",function(t,e=[]){const i=[];return e.forEach(e=>{e.includes(":")?t.models.forEach(t=>{e.split(":",1)[0]===t.id+""&&i.push(e)}):i.push(e)}),t.executeCommand("setSelected",i)}),tt.registerCommand("showAll",function(t){if(!t.visualizeJs)return;t.visViewer().unisolateSelectedObjects(!1),t.update(),t.emitEvent({type:"showall"})}),tt.registerCommand("zoomToExtents",function(t,e=!1,i=t.options.cameraAnimation){if(!t.visualizeJs)return;const s=t.visViewer(),r=s.getEnableAnimation();s.setEnableAnimation(i),s.zoomExtents(e),s.update(),s.setEnableAnimation(r),t.deviceAutoRegeneration(),t.update(),t.emitEvent({type:"zoom"})}),tt.registerCommand("zoomToObjects",function(t,e=[]){var i;if(!t.visualizeJs)return;const s=t.visLib(),r=t.visViewer(),n=new s.OdTvSelectionSet;e.forEach(t=>{const e=r.getEntityByOriginalHandle(t+"");e.isNull()||n.appendEntity(e)}),null===(i=r.zoomToObjects)||void 0===i||i.call(r,n),t.deviceAutoRegeneration(),t.update(),t.emitEvent({type:"zoom"}),n.delete()}),tt.registerCommand("zoomToSelected",function(t){var e;if(!t.visualizeJs)return;const i=t.visViewer(),s=i.getSelected();null===(e=i.zoomToObjects)||void 0===e||e.call(i,s),t.deviceAutoRegeneration(),t.update(),t.emitEvent({type:"zoom"})}),tt.registerCommand("autoTransformAllModelsToCentralPoint",async function(t,e){var i;if(!t.visualizeJs)return;if(!e.getModelTransformMatrix)return;const s=t.visLib(),r=t.visViewer(),n=r.getActiveExtents().center(),a=r.getModelIterator();for(;!a.done();a.step()){const t=a.getModel();if(!Q(t)){const i=t.getExtents(),r=t.getUnitsMatrix();i.transformBy(t.getUnitsMatrix());const a=t.getUnitsMatrix().invert(),o=i.center(),h=1,l=new s.Matrix3d,d=new s.Matrix3d;d.setTranslation([n[0]-o[0],n[1]-o[1],n[2]-o[2]]),l.setToScaling(h,n);const c=a.postMultBy(l).postMultBy(d).postMultBy(r),u=c.scale(),g={translate:{x:c.get(0,3)-(1-u)*o[0],y:c.get(1,3)-(1-u)*o[1],z:c.get(2,3)-(1-u)*o[2]},rotation:{x:0,y:0,z:1,angle:0},scale:u},p=K(g,o,s);t.setModelingMatrix(p,!0),n[0]+=Math.abs(i.max()[0]-i.min()[0])*u,await e.setModelTransformMatrix(t.getDatabaseHandle(),g)}t.delete()}a.delete(),null===(i=r.clearViewExtentsCache)||void 0===i||i.call(r),t.update()}),tt.registerCommand("k3DViewTop",t=>$(t,"k3DViewTop")),tt.registerCommand("k3DViewBottom",t=>$(t,"k3DViewBottom")),tt.registerCommand("k3DViewLeft",t=>$(t,"k3DViewLeft")),tt.registerCommand("k3DViewRight",t=>$(t,"k3DViewRight")),tt.registerCommand("k3DViewFront",t=>$(t,"k3DViewFront")),tt.registerCommand("k3DViewBack",t=>$(t,"k3DViewBack")),tt.registerCommand("k3DViewSE",t=>$(t,"k3DViewSE")),tt.registerCommand("k3DViewSW",t=>$(t,"k3DViewSW")),tt.registerCommand("k3DViewNE",t=>$(t,"k3DViewNE")),tt.registerCommand("k3DViewNW",t=>$(t,"k3DViewNW")),tt.registerCommandAlias("clearMarkup","clearOverlay"),tt.registerCommandAlias("clearSelected","unselect"),tt.registerCommandAlias("zoomToExtents","zoomExtents");class et{constructor(t){this.optionsChange=()=>{this.switchCameraMode(this.viewer.options.cameraMode)},this.geometryEnd=()=>{const t=this.viewer.visViewer().activeView,e=this.getCameraMode(t);this.viewer.options.cameraMode=e,this.viewer.emitEvent({type:"changecameramode",mode:e}),t.delete()},this.viewer=t,this.viewer.addEventListener("databasechunk",this.geometryEnd),this.viewer.addEventListener("clear",this.geometryEnd),this.viewer.addEventListener("optionschange",this.optionsChange),this.viewer.addEventListener("initialize",this.optionsChange)}dispose(){this.viewer.removeEventListener("databasechunk",this.geometryEnd),this.viewer.removeEventListener("clear",this.geometryEnd),this.viewer.removeEventListener("optionschange",this.optionsChange),this.viewer.removeEventListener("initialize",this.optionsChange)}getCameraMode(t){return t.perspective?"perspective":"orthographic"}switchCameraMode(t){if(!t)return;const e=this.viewer.visViewer().activeView;t!==this.getCameraMode(e)&&(e.perspective=!e.perspective,this.viewer.update(),this.viewer.emitEvent({type:"changecameramode",mode:t})),e.delete()}}class it{constructor(t){this.animate=(t=0)=>{this.requestId=requestAnimationFrame(this.animate),this.viewer.render(t),this.viewer.emitEvent({type:"animate",time:t})},this.viewer=t,this.animate()}dispose(){cancelAnimationFrame(this.requestId)}}class st{constructor(t){this.resizeViewer=t=>{const{width:e,height:i}=t[0].contentRect;e&&i&&this.viewer.setSize(e,i)},this.viewer=t,this.resizeObserver=new ResizeObserver(this.resizeViewer),this.resizeObserver.observe(t.canvas.parentElement)}dispose(){this.resizeObserver.disconnect()}}class rt{constructor(t){this.viewer=t,this.zoomWheelDragger=new U(t),this.zoomWheelDragger.name="ZoomWheel",this.zoomWheelDragger.initialize()}dispose(){this.zoomWheelDragger.dispose(),this.zoomWheelDragger=void 0}}var nt;!function(t){t[t.None=0]="None",t[t.Orbit=1]="Orbit",t[t.Pan=2]="Pan",t[t.Zoom=3]="Zoom"}(nt||(nt={}));class at extends w{get isSingleTouchEnabled(){return this._isSingleTouchEnabled}set isSingleTouchEnabled(t){this._isSingleTouchEnabled=t}constructor(t){super(t),this._previousEvents=new Map,this._currentEvents=new Map,this._lastGestureAction=nt.None,this._maxInitialDistanceDifference=30*window.devicePixelRatio,this._isSingleTouchEnabled=!1,this._orbitAction=new V(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity),this._panAction=new B(this.m_module,this.subject,this.beginInteractivity,this.endInteractivity,this.getViewParams,this.setViewParams),this._zoomAction=new j(this.m_module,this.subject)}getMiddlePoint(t){if(2!==t.size)return;const e=this.getKeys(t),i=this.relativeCoords(t.get(e[0])),s=this.relativeCoords(t.get(e[1]));return{x:Math.floor((i.x+s.x)/2),y:Math.floor((i.y+s.y)/2)}}getFirstPoint(t){if(t.size<1)return;const e=this.getKeys(t);return this.relativeCoords(t.get(e[0]))}getDistance(t){if(2!==t.size)return-1;const e=this.getKeys(t),i=this.relativeCoords(t.get(e[0])),s=this.relativeCoords(t.get(e[1]));return Math.hypot(i.x-s.x,i.y-s.y)}updateEvent(t){const e=!this._currentEvents.get(t.pointerId);if(e&&2===this._currentEvents.size)return;const i=this._currentEvents.get(t.pointerId);i&&this._previousEvents.set(i.pointerId,i),this._currentEvents.set(t.pointerId,t),e&&(this._initialDistance=this.getDistance(this._currentEvents))}removeEvent(t){this._currentEvents.delete(t.pointerId),this._previousEvents.delete(t.pointerId),this._currentEvents.size<2&&(this._initialDistance=-1)}getKeys(t){return Array.from(t.keys())}analyzeGesture(){if(2===this._currentEvents.size){const t=this.getDistance(this._currentEvents),e=this.getDistance(this._previousEvents);Math.abs(this._initialDistance-t)<=this._maxInitialDistanceDifference?this.executePanAction(this.getMiddlePoint(this._currentEvents)):-1!==e&&t!==e&&this.executeZoomAction(t,e)}else 1===this._currentEvents.size&&this.isSingleTouchEnabled&&this.executeOrbitAction(this.getFirstPoint(this._currentEvents))}executeZoomAction(t,e){this._lastGestureAction!==nt.Zoom&&(this.executeEndAction(this._lastGestureAction),this._lastGestureAction=nt.Zoom,w.isGestureActive=!0);const i=1+(t-e)/700,s=this.getMiddlePoint(this._currentEvents);this._zoomAction.action(s.x,s.y,i,s.x,s.y),this.subject.update()}executePanAction(t){this._lastGestureAction!==nt.Pan&&(this.executeEndAction(this._lastGestureAction),this._lastGestureAction=nt.Pan,w.isGestureActive=!0,this._panAction.beginAction(t.x,t.y,t.x,t.y)),this._panAction.action(t.x,t.y,t.x,t.y),this.subject.update()}executeOrbitAction(t){this._lastGestureAction!==nt.Orbit&&(this.executeEndAction(this._lastGestureAction),this._lastGestureAction=nt.Orbit,w.isGestureActive=!0,this._orbitAction.beginAction(t.x,t.y)),this._orbitAction.action(t.x,t.y),this.subject.update()}executeEndAction(t){t===nt.Orbit&&this._orbitAction.endAction(),t===nt.Pan&&this._panAction.endAction(),w.isGestureActive=!1}needIgnoreEvent(t){return!this.subject.options.enableZoomWheel||!this.subject.options.enableGestures||!this.eventIsTouchEvent(t)}eventIsTouchEvent(t){return"touch"===t.pointerType||""===t.pointerType}pointerdown(t){this.needIgnoreEvent(t)||this.updateEvent(t)}pointermove(t){this.needIgnoreEvent(t)||(this.updateEvent(t),this.analyzeGesture())}pointerup(t){this.needIgnoreEvent(t)||(this.removeEvent(t),this._currentEvents.size<2&&(this.executeEndAction(this._lastGestureAction),w.isGestureActive=!1),this._lastGestureAction=nt.None)}pointercancel(t){this.needIgnoreEvent(t)||this.pointerup(t)}pointerleave(t){this.needIgnoreEvent(t)||this.pointerup(t)}}class ot{constructor(t){this.viewer=t,this.gestureManager=new at(t),this.gestureManager.initialize()}dispose(){this.gestureManager.dispose(),this.gestureManager=void 0}}class ht{constructor(t){this.savedCameraSettings=null,this.onDatabaseChunk=()=>{this.viewer.visualizeJs&&(this.savedCameraSettings=this.getOrthogonalCameraSettings())},this.viewer=t,this.viewer.addEventListener("databasechunk",this.onDatabaseChunk),this.viewer.on("resetview",this.resetCameraPosition)}dispose(){this.viewer.off("resetview",this.resetCameraPosition),this.viewer.removeEventListener("databasechunk",this.onDatabaseChunk)}resetCameraPosition(){this.savedCameraSettings&&this.viewer.visualizeJs&&this.setOrthogonalCameraSettings(this.savedCameraSettings)}getOrthogonalCameraSettings(){const t=this.viewer.visViewer().activeView;return{view_point:this.getPoint3dFromArray(t.viewPosition),direction:this.getPoint3dFromArray(t.viewTarget),up_vector:this.getPoint3dFromArray(t.upVector),field_width:t.viewFieldWidth,field_height:t.viewFieldHeight,view_to_world_scale:1}}setOrthogonalCameraSettings(t){const e=this.viewer.visViewer().activeView;t&&e.setView(this.getLogicalPoint3dAsArray(t.view_point),this.getLogicalPoint3dAsArray(t.direction),this.getLogicalPoint3dAsArray(t.up_vector),t.field_width,t.field_height,!0)}getPoint3dFromArray(t){return{x:t[0],y:t[1],z:t[2]}}getLogicalPoint3dAsArray(t){return[t.x,t.y,t.z]}}const lt=l("visualizejs");lt.registerComponent("CameraComponent",t=>new et(t)),lt.registerComponent("ResizeCanvasComponent",t=>new st(t)),lt.registerComponent("RenderLoopComponent",t=>new it(t)),lt.registerComponent("ZoomWheelComponent",t=>new rt(t)),lt.registerComponent("GestureManagerComponent",t=>new ot(t)),lt.registerComponent("ResetComponent",t=>new ht(t));class dt{dispose(){}}class ct{constructor(){this.requestHeader={},this.withCredentials=!1,this.abortSignal=void 0}setRequestHeader(t){this.requestHeader=t}setWithCredentials(t){this.withCredentials=t}setAbortSignal(t){this.abortSignal=t}load(t,e){if("string"==typeof t){const i=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:this.abortSignal});return fetch(i).then(t=>{if(!t.ok)throw new Error(`Failed to fetch "${t.url}", status ${t.status}`);const i=t.headers.get("X-File-Size")||t.headers.get("Content-Length"),s=parseInt(i||"",10)||0,r=s>0,n=new ReadableStream({async start(i){const n=t.body.getReader();let a=0;try{for(;;){const{done:t,value:o}=await n.read();if(t)break;e&&(a+=o.byteLength,e(new ProgressEvent("progress",{lengthComputable:r,loaded:a,total:s}))),i.enqueue(o)}i.close()}catch(t){i.error(t)}}});return new Response(n)}).then(t=>t.arrayBuffer())}if(t instanceof globalThis.File)return new Promise((i,s)=>{const r=new FileReader;r.onload=()=>i(r.result),r.onerror=()=>s(r.error),r.onprogress=e,r.readAsArrayBuffer(new Blob([t]))});if(e){const i=t.byteLength;e(new ProgressEvent("progress",{lengthComputable:i>0,loaded:i,total:i}))}return Promise.resolve(t)}}class ut extends d{constructor(t){super(),this.viewer=t}isSupport(t,e){return("string"==typeof t||t instanceof globalThis.File||t instanceof ArrayBuffer)&&/vsf$/i.test(e)}async load(t,e,i={}){if(!this.viewer.visualizeJs)return this;const s=this.viewer.visViewer(),r=new ct;r.setRequestHeader(i.requestHeader),r.setWithCredentials(i.withCredentials),r.setAbortSignal(this.abortController.signal);const n=await r.load(t,e=>{const{lengthComputable:i,loaded:s,total:r}=e,n=i?s/r:1;this.viewer.emitEvent({type:"geometryprogress",data:n,file:t})}),a=new Uint8Array(n);if(!this.viewer.visualizeJs)return this;try{s.parseFile(a)}catch(t){throw console.error("VSF parse error.",t),t}const o=new dt;return o.id=i.modelId||this.extractFileName(t),this.viewer.models.push(o),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:a,file:t}),this}}class gt extends d{constructor(t){super(),this.viewer=t}isSupport(t,e){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&/.data$/i.test(t.database)}async load(t,e){if(!this.viewer.visualizeJs)return this;const i=this.viewer.visViewer(),s=[t.database,...t.geometry];console.time("File load time");for(let e=0;e<s.length;e++){const r=s[e],n=i=>{const r=(e+i)/s.length;this.viewer.emitEvent({type:"geometryprogress",data:r,file:t.file,model:t})},a=await t.downloadResource(r,n,this.abortController.signal),o=new Uint8Array(a);if(!this.viewer.visualizeJs)return this;try{i.parseStream(o)}catch(t){throw console.error("VSF parse error.",t),t}if(0===e){const e=new dt;e.id=t.file.id,this.viewer.models.push(e),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:o,file:t.file,model:t})}else this.viewer.update(),this.viewer.emitEvent({type:"geometrychunk",data:o,file:t.file,model:t})}return console.timeEnd("File load time"),this}}class pt extends d{constructor(t){super(),this.viewer=t}isSupport(t,e){return("string"==typeof t||t instanceof globalThis.File||t instanceof ArrayBuffer)&&/vsfx$/i.test(e)}async load(t,e,i={}){if(!this.viewer.visualizeJs)return this;const s=this.viewer.visViewer(),r=new ct;r.setRequestHeader(i.requestHeader),r.setWithCredentials(i.withCredentials),r.setAbortSignal(this.abortController.signal);const n=await r.load(t,e=>{const{lengthComputable:i,loaded:s,total:r}=e,n=i?s/r:1;this.viewer.emitEvent({type:"geometryprogress",data:n,file:t})}),a=new Uint8Array(n);if(!this.viewer.visualizeJs)return this;try{s.parseVsfx(a)}catch(t){throw console.error("VSFX parse error.",t),t}const o=new dt;return o.id=i.modelId||this.extractFileName(t),this.viewer.models.push(o),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:a,file:t}),this}}class mt extends d{constructor(t){super(),this.viewer=t}isSupport(t){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&/.vsfx$/i.test(t.database)&&!1===this.viewer.options.enableStreamingMode}async load(t){if(!this.viewer.visualizeJs)return Promise.resolve(this);const e=this.viewer.visViewer();console.time("File load time");const i=await t.downloadResource(t.database,e=>{this.viewer.emitEvent({type:"geometryprogress",data:e,file:t.file,model:t})},this.abortController.signal),s=new Uint8Array(i);if(!this.viewer.visualizeJs)return this;try{e.parseVsfx(s)}catch(t){throw console.error("VSFX parse error.",t),t}const r=new dt;return r.id=t.file.id,this.viewer.models.push(r),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(!0),this.viewer.emitEvent({type:"databasechunk",data:s,file:t.file,model:t}),console.timeEnd("File load time"),this}}var ft;!function(t){t[t.kDelay=0]="kDelay",t[t.kNormal=1]="kNormal",t[t.kForce=2]="kForce"}(ft||(ft={}));class _t{constructor(){this.lastUpdate=0,this.delayUpdateTime=1e3}initialize(t){this.viewer=t,this.lastUpdate=performance.now()}update(t){const e=t!==ft.kDelay||performance.now()-this.lastUpdate>=this.delayUpdateTime,i=t===ft.kForce;e&&(this.viewer.update(i),this.lastUpdate=performance.now(),this.delayUpdateTime*=2)}}class vt extends d{constructor(t){super(),this.viewer=t}isSupport(t){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&/.vsfx$/i.test(t.database)&&!0===this.viewer.options.enableStreamingMode&&!1===this.viewer.options.enablePartialMode&&!/.rcs$/i.test(t.name)}async load(t){if(!this.viewer.visualizeJs)return this;const e=this.viewer.visLib(),i=this.viewer.visViewer(),s=new _t;s.initialize(this.viewer);let r=!1;return console.time("File load time"),await t.downloadResource(t.database,(n,a)=>{if(!this.viewer.visualizeJs)return;let o;try{o=i.parseVsfx(a)}catch(t){throw console.error("VSFX parse error.",t),t}this.viewer.emitEvent({type:"geometryprogress",data:n,file:t.file,model:t});let h=!1;if((o===e.DatabaseStreamStatus.ReadyServiceData||o===e.DatabaseStreamStatus.Complete&&!r)&&(r=!0,h=!0),h){const e=new dt;e.id=t.file.id,this.viewer.models.push(e),this.viewer.syncOptions(),this.viewer.syncOverlay(),s.update(ft.kForce),this.viewer.emitEvent({type:"databasechunk",data:a,file:t.file,model:t})}else s.update(ft.kDelay),this.viewer.emitEvent({type:"geometrychunk",data:a,file:t.file,model:t})},this.abortController.signal),s.update(ft.kNormal),console.timeEnd("File load time"),Promise.resolve(this)}}class yt extends d{constructor(t){super(),this.viewer=t,this.abortControllerForRequestMap=new Map}isSupport(t){return"object"==typeof t&&"string"==typeof t.database&&"function"==typeof t.downloadResource&&"function"==typeof t.downloadResourceRange&&/.vsfx$/i.test(t.database)&&(!0===this.viewer.options.enablePartialMode||/.rcs$/i.test(t.name))}async load(t){if(!this.viewer.visualizeJs)return this;const e=this.viewer.visViewer();let i=!1;const s=new Map;let r=0;const n=()=>clearTimeout(r),a=new AbortController;this.abortControllerForRequestMap.set(0,a);const o=new _t;o.initialize(this.viewer),e.memoryLimit=this.viewer.options.memoryLimit;const h=(i,s,r=0)=>{if(!this.viewer.visualizeJs)return;let n;try{n=e.parseVsfxInPartialMode(r,s)}catch(t){throw console.error("VSFX parse error.",t),t}if(this.viewer.emitEvent({type:"geometryprogress",data:i,file:t.file,model:t}),n){const e=new dt;e.id=t.file.id,this.viewer.models.push(e),this.viewer.syncOptions(),this.viewer.syncOverlay(),o.update(ft.kForce),this.viewer.emitEvent({type:"databasechunk",data:s,file:t.file,model:t})}else o.update(ft.kDelay),this.viewer.emitEvent({type:"geometrychunk",data:s,file:t.file,model:t})},l=async(i,s,r)=>{const n=new AbortController;this.abortControllerForRequestMap.set(s,n);try{await t.downloadResourceRange(i,s,r,h,n.signal)}catch(e){this.viewer.emitEvent({type:"geometryerror",data:e,file:t.file,model:t})}finally{r.forEach(t=>e.onRequestResponseComplete(t.requestId)),this.abortControllerForRequestMap.delete(s),o.update(ft.kNormal)}},d=(t,e)=>{const i=[];for(let s=0;s<e.size();s++){const r=e.get(s);i.push({requestId:t,begin:Number(r.begin),end:Number(r.end)-1}),r.delete()}return i},c={onServicePartReceived:t=>{t&&(i=!0,this.abortController.abort())},onRequest:(e,i)=>{const s=d(e,i);l(t.database,e,s)},onFullLoaded:()=>{o.update(ft.kNormal)},onRequestResponseParsed:t=>{this.abortControllerForRequestMap.delete(t),o.update(ft.kNormal)},onRequestAborted:t=>{const e=this.abortControllerForRequestMap.get(t);e&&e.abort()},onRequestResourceFile:(e,i,o)=>{const h=`${t.fileId}${t.file.type}`,c=d(e,o);let u=[],g=0;const p=s.get(h);return p&&(u=p.ranges,g=p.number),g<=5?(s.set(h,{ranges:[],number:g+1}),void l(h,e,c)):(u=u.concat(c),u.length>=50?(r&&(window.clearTimeout(r),r=0),s.set(h,{ranges:[],number:g+1}),void l(h,e,u)):(s.set(h,{ranges:u,number:g+1}),void(0===r&&(r=window.setTimeout(()=>{a.signal.removeEventListener("abort",n),r=0,s.forEach((t,i)=>{t.ranges.length>0&&(s.set(i,{ranges:[],number:t.number+1}),l(i,e,t.ranges))})},250),a.signal.addEventListener("abort",n,{once:!0})))))}};e.attachPartialResolver(c);try{await t.downloadResource(t.database,h,this.abortController.signal)}catch(t){if(window.clearTimeout(r),!i)throw t}return this}cancel(){super.cancel(),this.abortControllerForRequestMap.forEach(t=>t.abort())}}const wt=g("visualizejs");wt.registerLoader("vsf-file",t=>new ut(t)),wt.registerLoader("vsf-cloud",t=>new gt(t)),wt.registerLoader("vsfx-file",t=>new pt(t)),wt.registerLoader("vsfx-cloud",t=>new mt(t)),wt.registerLoader("vsfx-cloud-streaming",t=>new vt(t)),wt.registerLoader("vsfx-cloud-partial",t=>new yt(t));class xt{constructor(){this._listeners={}}addEventListener(t,e){return void 0===this._listeners[t]&&(this._listeners[t]=[]),this._listeners[t].push(e),this}removeEventListener(t,e){if(void 0===this._listeners[t])return this;const i=this._listeners[t].filter(t=>t!==e);return 0!==i.length?this._listeners[t]=i:delete this._listeners[t],this}removeAllListeners(t){return t?delete this._listeners[t]:this._listeners={},this}emitEvent(t){if(void 0===this._listeners[t.type])return!1;return this._listeners[t.type].slice().forEach(e=>e.call(this,t)),!0}on(t,e){return this.addEventListener(t,e)}off(t,e){return this.removeEventListener(t,e)}emit(t,...e){return"string"==typeof t?this.emitEvent({type:t,args:e}):"object"==typeof t&&this.emitEvent(t)}}function bt(t,e){if(window.getVisualizeLibInst){const e=window.getVisualizeLibInst.script;if(e){if(e.src===t)return Promise.resolve(e);e.remove()}delete window.getVisualizeLibInst}return function(t,e={}){return new Promise((i,s)=>{const r=document.createElement("script");r.src=t,r.async=!0,r.crossOrigin=e.crossOrigin,r.onload=()=>i(r),r.onerror=()=>{r.remove(),s(new Error(`GET ${t} failed to load script`))},document.body.appendChild(r)})}(t,e)}const St=Math.PI/180;const Ct="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},At={_global:Ct,version:"10.0.12",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:t=>At.angleDeg?t*St:t,enableTrace:!1,pointerEventsEnabled:!0,autoDrawEnabled:!0,hitOnDragEnabled:!1,capturePointerEventsEnabled:!1,_mouseListenClick:!1,_touchListenClick:!1,_pointerListenClick:!1,_mouseInDblClickWindow:!1,_touchInDblClickWindow:!1,_pointerInDblClickWindow:!1,_mouseDblClickPointerId:null,_touchDblClickPointerId:null,_pointerDblClickPointerId:null,_renderBackend:"web",legacyTextRendering:!1,pixelRatio:"undefined"!=typeof window&&window.devicePixelRatio||1,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:()=>At.DD.isDragging,isTransforming(){var t,e;return null!==(e=null===(t=At.Transformer)||void 0===t?void 0:t.isTransforming())&&void 0!==e&&e},isDragReady:()=>!!At.DD.node,releaseCanvasOnDestroy:!0,document:Ct.document,_injectGlobal(t){void 0!==Ct.Konva&&console.error("Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment."),Ct.Konva=t}},Tt=t=>{At[t.prototype.getClassName()]=t};At._injectGlobal(At);const kt=()=>{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 Pt{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 Pt(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){const e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}translate(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}scale(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.m[0]*e+this.m[2]*i,r=this.m[1]*e+this.m[3]*i,n=this.m[0]*-i+this.m[2]*e,a=this.m[1]*-i+this.m[3]*e;return this.m[0]=s,this.m[1]=r,this.m[2]=n,this.m[3]=a,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,e){const i=this.m[0]+this.m[2]*e,s=this.m[1]+this.m[3]*e,r=this.m[2]+this.m[0]*t,n=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=s,this.m[2]=r,this.m[3]=n,this}multiply(t){const e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],s=this.m[0]*t.m[2]+this.m[2]*t.m[3],r=this.m[1]*t.m[2]+this.m[3]*t.m[3],n=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],a=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=r,this.m[4]=n,this.m[5]=a,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,s=-this.m[2]*t,r=this.m[0]*t,n=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),a=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=s,this.m[3]=r,this.m[4]=n,this.m[5]=a,this}getMatrix(){return this.m}decompose(){const t=this.m[0],e=this.m[1],i=this.m[2],s=this.m[3],r=t*s-e*i,n={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=t||0!=e){const a=Math.sqrt(t*t+e*e);n.rotation=e>0?Math.acos(t/a):-Math.acos(t/a),n.scaleX=a,n.scaleY=r/a,n.skewX=(t*i+e*s)/r,n.skewY=0}else if(0!=i||0!=s){const a=Math.sqrt(i*i+s*s);n.rotation=Math.PI/2-(s>0?Math.acos(-i/a):-Math.acos(i/a)),n.scaleX=r/a,n.scaleY=a,n.skewX=0,n.skewY=(t*i+e*s)/r}return n.rotation=Gt._getRotation(n.rotation),n}}const Et=Math.PI/180,Mt=180/Math.PI,It="#",Rt="Konva error: ",Dt={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]},Lt=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;let Ot=[],zt=null;const Ft="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)},Gt={_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){Ot.push(t),1===Ot.length&&Ft(function(){const t=Ot;Ot=[],t.forEach(function(t){t()})})},createCanvasElement(){kt();const t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:()=>(kt(),document.createElement("img")),_isInDocument(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage(t,e){const i=Gt.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(It,"");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 It+t},isCanvasFarblingActive(){if(null!==zt)return zt;if("undefined"==typeof document)return zt=!1,!1;const t=this.createCanvasElement();t.width=10,t.height=10;const e=t.getContext("2d",{willReadFrequently:!0});e.clearRect(0,0,10,10),e.fillStyle="#282828",e.fillRect(0,0,10,10);const i=e.getImageData(0,0,10,10).data;let s=!1;for(let t=0;t<100;t++)if(40!==i[4*t]||40!==i[4*t+1]||40!==i[4*t+2]||255!==i[4*t+3]){s=!0;break}return zt=s,this.releaseCanvas(t),zt},getHitColor(){const t=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(t):t},getHitColorKey(t,e,i){return this.isCanvasFarblingActive()&&(t=5*Math.round(t/5),e=5*Math.round(e/5),i=5*Math.round(i/5)),It+this._rgbToHex(t,e,i)},getSnappedHexColor(t){const e=this._hexToRgb(t);return It+this._rgbToHex(5*Math.round(e.r/5),5*Math.round(e.g/5),5*Math.round(e.b/5))},getRGB(t){let e;return t in Dt?(e=Dt[t],{r:e[0],g:e[1],b:e[2]}):t[0]===It?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=Lt.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",Gt._namedColorToRBA(t)||Gt._hex3ColorToRGBA(t)||Gt._hex4ColorToRGBA(t)||Gt._hex6ColorToRGBA(t)||Gt._hex8ColorToRGBA(t)||Gt._rgbColorToRGBA(t)||Gt._rgbaColorToRGBA(t)||Gt._hslColorToRGBA(t)),_namedColorToRBA(t){const e=Dt[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA(t){if(0===t.indexOf("rgb(")){const e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA(t){if(0===t.indexOf("rgba(")){const e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map((t,e)=>"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){const[e,...i]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),s=Number(i[0])/360,r=Number(i[1])/100,n=Number(i[2])/100;let a,o,h;if(0===r)return h=255*n,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};a=n<.5?n*(1+r):n+r-n*r;const l=2*n-a,d=[0,0,0];for(let t=0;t<3;t++)o=s+1/3*-(t-1),o<0&&o++,o>1&&o--,h=6*o<1?l+6*(a-l)*o:2*o<1?a:3*o<2?l+(a-l)*(2/3-o)*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*Et,radToDeg:t=>t*Mt,_degToRad:t=>(Gt.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),Gt.degToRad(t)),_radToDeg:t=>(Gt.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),Gt.radToDeg(t)),_getRotation:t=>At.angleDeg?Gt.radToDeg(t):t,_capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),throw(t){throw new Error(Rt+t)},error(t){console.error(Rt+t)},warn(t){At.showWarnings&&console.warn("Konva warning: "+t)},each(t,e){for(const i in t)e(i,t[i])},_inRange:(t,e,i)=>e<=t&&t<i,_getProjectionToSegment(t,e,i,s,r,n){let a,o,h;const l=(t-i)*(t-i)+(e-s)*(e-s);if(0==l)a=t,o=e,h=(r-i)*(r-i)+(n-s)*(n-s);else{const d=((r-t)*(i-t)+(n-e)*(s-e))/l;d<0?(a=t,o=e,h=(t-r)*(t-r)+(e-n)*(e-n)):d>1?(a=i,o=s,h=(i-r)*(i-r)+(s-n)*(s-n)):(a=t+d*(i-t),o=e+d*(s-e),h=(a-r)*(a-r)+(o-n)*(o-n))}return[a,o,h]},_getProjectionToLine(t,e,i){const s=Gt.cloneObject(t);let r=Number.MAX_VALUE;return e.forEach(function(n,a){if(!i&&a===e.length-1)return;const o=e[(a+1)%e.length],h=Gt._getProjectionToSegment(n.x,n.y,o.x,o.y,t.x,t.y),l=h[0],d=h[1],c=h[2];c<r&&(s.x=l,s.y=d,r=c)}),s},_prepareArrayForTween(t,e,i){const s=[],r=[];if(t.length>e.length){const i=e;e=t,t=i}for(let e=0;e<t.length;e+=2)s.push({x:t[e],y:t[e+1]});for(let t=0;t<e.length;t+=2)r.push({x:e[t],y:e[t+1]});const n=[];return r.forEach(function(t){const e=Gt._getProjectionToLine(t,s,i);n.push(e.x),n.push(e.y)}),n},_prepareToStringify(t){let e;t.visitedByCircularReferenceRemoval=!0;for(const i in t)if(t.hasOwnProperty(i)&&t[i]&&"object"==typeof t[i])if(e=Object.getOwnPropertyDescriptor(t,i),t[i].visitedByCircularReferenceRemoval||Gt._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===Gt._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){At.releaseCanvasOnDestroy&&t.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(t,e,i,s){let r=e<0?e:0,n=i<0?i:0;e=Math.abs(e),i=Math.abs(i);let a=0,o=0,h=0,l=0;"number"==typeof s?a=o=h=l=Math.min(s,e/2,i/2):(a=Math.min(s[0]||0,e/2,i/2),o=Math.min(s[1]||0,e/2,i/2),l=Math.min(s[2]||0,e/2,i/2),h=Math.min(s[3]||0,e/2,i/2)),t.moveTo(r+a,n),t.lineTo(r+e-o,n),t.arc(r+e-o,n+o,o,3*Math.PI/2,0,!1),t.lineTo(r+e,n+i-l),t.arc(r+e-l,n+i-l,l,0,Math.PI/2,!1),t.lineTo(r+h,n+i),t.arc(r+h,n+i-h,h,Math.PI/2,Math.PI,!1),t.lineTo(r,n+a),t.arc(r+a,n+a,a,Math.PI,3*Math.PI/2,!1)},drawRoundedPolygonPath(t,e,i,s,r){s=Math.abs(s);for(let n=0;n<i;n++){const a=e[(n-1+i)%i],o=e[n],h=e[(n+1)%i],l={x:o.x-a.x,y:o.y-a.y},d={x:h.x-o.x,y:h.y-o.y},c=Math.hypot(l.x,l.y),u=Math.hypot(d.x,d.y);let g;g="number"==typeof r?r:n<r.length?r[n]:0;g=s*Math.cos(Math.PI/i)*Math.min(1,g/s*2);const p={x:l.x/c,y:l.y/c},m={x:d.x/u,y:d.y/u},f={x:o.x-p.x*g,y:o.y-p.y*g},_={x:o.x+m.x*g,y:o.y+m.y*g};0===n?t.moveTo(f.x,f.y):t.lineTo(f.x,f.y),t.arcTo(o.x,o.y,_.x,_.y,g)}}};const Vt=["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 Wt,Bt=null;function Nt(){if(null!==Bt)return Bt;try{const t=Gt.createCanvasElement().getContext("2d");return t?!!t&&"filter"in t:(Bt=!1,!1)}catch(t){return Bt=!1,!1}}class jt{constructor(t){this.canvas=t,At.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(t){t.fillEnabled()&&this._fill(t)}_fill(t){}strokeShape(t){t.hasStroke()&&this._stroke(t)}_stroke(t){}fillStrokeShape(t){t.attrs.fillAfterStrokeEnabled?(this.strokeShape(t),this.fillShape(t)):(this.fillShape(t),this.strokeShape(t))}getTrace(t,e){let i,s,r,n,a=this.traceArr,o=a.length,h="";for(i=0;i<o;i++)s=a[i],r=s.method,r?(n=s.args,h+=r,t?h+="()":Gt._isArray(n[0])?h+="(["+n.join(",")+"])":(e&&(n=n.map(t=>"number"==typeof t?Math.floor(t):t)),h+="("+n.join(",")+")")):(h+=s.property,t||(h+="="+s.val)),h+=";";return h}clearTrace(){this.traceArr=[]}_trace(t){let e,i=this.traceArr;i.push(t),e=i.length,e>=100&&i.shift()}reset(){const t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}getCanvas(){return this.canvas}clear(t){const e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}_applyLineCap(t){const e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}_applyOpacity(t){const e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)}_applyLineJoin(t){const e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}_applyMiterLimit(t){const e=t.attrs.miterLimit;null!=e&&this.setAttr("miterLimit",e)}setAttr(t,e){this._context[t]=e}arc(t,e,i,s,r,n){this._context.arc(t,e,i,s,r,n)}arcTo(t,e,i,s,r){this._context.arcTo(t,e,i,s,r)}beginPath(){this._context.beginPath()}bezierCurveTo(t,e,i,s,r,n){this._context.bezierCurveTo(t,e,i,s,r,n)}clearRect(t,e,i,s){this._context.clearRect(t,e,i,s)}clip(...t){this._context.clip.apply(this._context,t)}closePath(){this._context.closePath()}createImageData(t,e){const i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}createLinearGradient(t,e,i,s){return this._context.createLinearGradient(t,e,i,s)}createPattern(t,e){return this._context.createPattern(t,e)}createRadialGradient(t,e,i,s,r,n){return this._context.createRadialGradient(t,e,i,s,r,n)}drawImage(t,e,i,s,r,n,a,o,h){const l=arguments,d=this._context;3===l.length?d.drawImage(t,e,i):5===l.length?d.drawImage(t,e,i,s,r):9===l.length&&d.drawImage(t,e,i,s,r,n,a,o,h)}ellipse(t,e,i,s,r,n,a,o){this._context.ellipse(t,e,i,s,r,n,a,o)}isPointInPath(t,e,i,s){return i?this._context.isPointInPath(i,t,e,s):this._context.isPointInPath(t,e,s)}fill(...t){this._context.fill.apply(this._context,t)}fillRect(t,e,i,s){this._context.fillRect(t,e,i,s)}strokeRect(t,e,i,s){this._context.strokeRect(t,e,i,s)}fillText(t,e,i,s){s?this._context.fillText(t,e,i,s):this._context.fillText(t,e,i)}measureText(t){return this._context.measureText(t)}getImageData(t,e,i,s){return this._context.getImageData(t,e,i,s)}lineTo(t,e){this._context.lineTo(t,e)}moveTo(t,e){this._context.moveTo(t,e)}rect(t,e,i,s){this._context.rect(t,e,i,s)}roundRect(t,e,i,s,r){this._context.roundRect(t,e,i,s,r)}putImageData(t,e,i){this._context.putImageData(t,e,i)}quadraticCurveTo(t,e,i,s){this._context.quadraticCurveTo(t,e,i,s)}restore(){this._context.restore()}rotate(t){this._context.rotate(t)}save(){this._context.save()}scale(t,e){this._context.scale(t,e)}setLineDash(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}getLineDash(){return this._context.getLineDash()}setTransform(t,e,i,s,r,n){this._context.setTransform(t,e,i,s,r,n)}stroke(t){t?this._context.stroke(t):this._context.stroke()}strokeText(t,e,i,s){this._context.strokeText(t,e,i,s)}transform(t,e,i,s,r,n){this._context.transform(t,e,i,s,r,n)}translate(t,e){this._context.translate(t,e)}_enableTrace(){let t,e,i=this,s=Vt.length,r=this.setAttr;const n=function(t){let s,r=i[t];i[t]=function(){return e=function(t){const e=[],i=t.length,s=Gt;for(let r=0;r<i;r++){let i=t[r];s._isNumber(i)?i=Math.round(1e3*i)/1e3:s._isString(i)||(i+=""),e.push(i)}return e}(Array.prototype.slice.call(arguments,0)),s=r.apply(i,arguments),i._trace({method:t,args:e}),s}};for(t=0;t<s;t++)n(Vt[t]);i.setAttr=function(){r.apply(i,arguments);const t=arguments[0];let e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),i._trace({property:t,val:e})}}_applyGlobalCompositeOperation(t){const e=t.attrs.globalCompositeOperation;!e||"source-over"===e||this.setAttr("globalCompositeOperation",e)}}["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"].forEach(function(t){Object.defineProperty(jt.prototype,t,{get(){return this._context[t]},set(e){this._context[t]=e}})});class Ht extends jt{constructor(t,{willReadFrequently:e=!1}={}){super(t),this._context=t._canvas.getContext("2d",{willReadFrequently:e})}_fillColor(t){const e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}_fillPattern(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}_fillLinearGradient(t){const e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fillRadialGradient(t){const e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}_fill(t){const e=t.fill(),i=t.getFillPriority();if(e&&"color"===i)return void this._fillColor(t);const s=t.getFillPatternImage();if(s&&"pattern"===i)return void this._fillPattern(t);const r=t.getFillLinearGradientColorStops();if(r&&"linear-gradient"===i)return void this._fillLinearGradient(t);const n=t.getFillRadialGradientColorStops();n&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):s?this._fillPattern(t):r?this._fillLinearGradient(t):n&&this._fillRadialGradient(t)}_strokeLinearGradient(t){const e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),s=t.getStrokeLinearGradientColorStops(),r=this.createLinearGradient(e.x,e.y,i.x,i.y);if(s){for(let t=0;t<s.length;t+=2)r.addColorStop(s[t],s[t+1]);this.setAttr("strokeStyle",r)}}_stroke(t){const e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();const t=this.getCanvas().getPixelRatio();this.setTransform(t,0,0,t,0,0)}this._applyLineCap(t),e&&t.dashEnabled()&&(this.setLineDash(e),this.setAttr("lineDashOffset",t.dashOffset())),this.setAttr("lineWidth",t.strokeWidth()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)");t.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(t):this.setAttr("strokeStyle",t.stroke()),t._strokeFunc(this),i||this.restore()}}_applyShadow(t){var e,i,s;const r=null!==(e=t.getShadowRGBA())&&void 0!==e?e:"black",n=null!==(i=t.getShadowBlur())&&void 0!==i?i:5,a=null!==(s=t.getShadowOffset())&&void 0!==s?s:{x:0,y:0},o=t.getAbsoluteScale(),h=this.canvas.getPixelRatio(),l=o.x*h,d=o.y*h;this.setAttr("shadowColor",r),this.setAttr("shadowBlur",n*Math.min(Math.abs(l),Math.abs(d))),this.setAttr("shadowOffsetX",a.x*l),this.setAttr("shadowOffsetY",a.y*d)}}class Ut extends jt{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 Xt{constructor(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const e=(t||{}).pixelRatio||At.pixelRatio||function(){if(Wt)return Wt;const t=Gt.createCanvasElement(),e=t.getContext("2d");return Wt=(At._global.devicePixelRatio||1)/(e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1),Gt.releaseCanvas(t),Wt}();this.pixelRatio=e,this._canvas=Gt.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(t){const e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)}setWidth(t){this.width=this._canvas.width=t*this.pixelRatio,this._canvas.style.width=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}setHeight(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";const e=this.pixelRatio;this.getContext()._context.scale(e,e)}getWidth(){return this.width}getHeight(){return this.height}setSize(t,e){this.setWidth(t||0),this.setHeight(e||0)}toDataURL(t,e){try{return this._canvas.toDataURL(t,e)}catch(t){try{return this._canvas.toDataURL()}catch(t){return Gt.error("Unable to get data URL. "+t.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}}class Yt extends Xt{constructor(t={width:0,height:0,willReadFrequently:!1}){super(t),this.context=new Ht(this,{willReadFrequently:t.willReadFrequently}),this.setSize(t.width,t.height)}}class Jt extends Xt{constructor(t={width:0,height:0}){super(t),this.hitCanvas=!0,this.context=new Ut(this),this.setSize(t.width,t.height)}}const qt={get isDragging(){let t=!1;return qt._dragElements.forEach(e=>{"dragging"===e.dragStatus&&(t=!0)}),t},justDragged:!1,get node(){let t;return qt._dragElements.forEach(e=>{t=e.node}),t},_dragElements:new Map,_drag(t){const e=[];qt._dragElements.forEach((i,s)=>{const{node:r}=i,n=r.getStage();n.setPointersPositions(t),void 0===i.pointerId&&(i.pointerId=Gt._getFirstPointerId(t));const a=n._changedPointerPositions.find(t=>t.id===i.pointerId);if(a){if("dragging"!==i.dragStatus){const e=r.dragDistance();if(Math.max(Math.abs(a.x-i.startPointerPos.x),Math.abs(a.y-i.startPointerPos.y))<e)return;if(r.startDrag({evt:t}),!r.isDragging())return}r._setDragPosition(t,i),e.push(r)}}),e.forEach(e=>{e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)})},_endDragBefore(t){const e=[];qt._dragElements.forEach(i=>{const{node:s}=i,r=s.getStage();t&&r.setPointersPositions(t);if(!r._changedPointerPositions.find(t=>t.id===i.pointerId))return;"dragging"!==i.dragStatus&&"stopped"!==i.dragStatus||(qt.justDragged=!0,At._mouseListenClick=!1,At._touchListenClick=!1,At._pointerListenClick=!1,i.dragStatus="stopped");const n=i.node.getLayer()||i.node instanceof At.Stage&&i.node;n&&-1===e.indexOf(n)&&e.push(n)}),e.forEach(t=>{t.draw()})},_endDragAfter(t){qt._dragElements.forEach((e,i)=>{"stopped"===e.dragStatus&&e.node.fire("dragend",{type:"dragend",target:e.node,evt:t},!0),"dragging"!==e.dragStatus&&qt._dragElements.delete(i)})}};function Kt(t){return Gt._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)||Gt._isBoolean(t)?t:Object.prototype.toString.call(t)}function Zt(t){return t>255?255:t<0?0:Math.round(t)}function $t(){if(At.isUnminified)return function(t,e){return Gt._isNumber(t)||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function Qt(t){if(At.isUnminified)return function(e,i){let s=Gt._isNumber(e),r=Gt._isArray(e)&&e.length==t;return s||r||Gt.warn(Kt(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array<number>('+t+")"),e}}function te(){if(At.isUnminified)return function(t,e){return Gt._isNumber(t)||"auto"===t||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function ee(){if(At.isUnminified)return function(t,e){return Gt._isString(t)||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function ie(){if(At.isUnminified)return function(t,e){const i=Gt._isString(t),s="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||s||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}}function se(){if(At.isUnminified)return function(t,e){return!0===t||!1===t||Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}At.isBrowser&&(window.addEventListener("mouseup",qt._endDragBefore,!0),window.addEventListener("touchend",qt._endDragBefore,!0),window.addEventListener("touchcancel",qt._endDragBefore,!0),window.addEventListener("mousemove",qt._drag),window.addEventListener("touchmove",qt._drag),window.addEventListener("mouseup",qt._endDragAfter,!1),window.addEventListener("touchend",qt._endDragAfter,!1),window.addEventListener("touchcancel",qt._endDragAfter,!1));const re="get",ne="set",ae={addGetterSetter(t,e,i,s,r){ae.addGetter(t,e,i),ae.addSetter(t,e,s,r),ae.addOverloadedGetterSetter(t,e)},addGetter(t,e,i){const s=re+Gt._capitalize(e);t.prototype[s]=t.prototype[s]||function(){const t=this.attrs[e];return void 0===t?i:t}},addSetter(t,e,i,s){const r=ne+Gt._capitalize(e);t.prototype[r]||ae.overWriteSetter(t,e,i,s)},overWriteSetter(t,e,i,s){const r=ne+Gt._capitalize(e);t.prototype[r]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),s&&s.call(this),this}},addComponentsGetterSetter(t,e,i,s,r){const n=i.length,a=Gt._capitalize,o=re+a(e),h=ne+a(e);t.prototype[o]=function(){const t={};for(let s=0;s<n;s++){const r=i[s];t[r]=this.getAttr(e+a(r))}return t};const l=function(t){if(At.isUnminified)return function(e,i){return null==e||Gt.isObject(e)||Gt.warn(Kt(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}}(i);t.prototype[h]=function(t){const n=this.attrs[e];s&&(t=s.call(this,t,e)),l&&l.call(this,t,e);for(const i in t)t.hasOwnProperty(i)&&this._setAttr(e+a(i),t[i]);return t||i.forEach(t=>{this._setAttr(e+a(t),void 0)}),this._fireChangeEvent(e,n,t),r&&r.call(this),this},ae.addOverloadedGetterSetter(t,e)},addOverloadedGetterSetter(t,e){const i=Gt._capitalize(e),s=ne+i,r=re+i;t.prototype[e]=function(){return arguments.length?(this[s](arguments[0]),this):this[r]()}},addDeprecatedGetterSetter(t,e,i,s){Gt.error("Adding deprecated "+e);const r=re+Gt._capitalize(e),n=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[r]=function(){Gt.error(n);const t=this.attrs[e];return void 0===t?i:t},ae.addSetter(t,e,s,function(){Gt.error(n)}),ae.addOverloadedGetterSetter(t,e)},backCompat(t,e){Gt.each(e,function(e,i){const s=t.prototype[i],r=re+Gt._capitalize(e),n=ne+Gt._capitalize(e);function a(){s.apply(this,arguments),Gt.error('"'+e+'" method is deprecated and will be removed soon. Use ""'+i+'" instead.')}t.prototype[e]=a,t.prototype[r]=a,t.prototype[n]=a})},afterSetFilter(){this._filterUpToDate=!1}};function oe(t){const e=/(\w+)\(([^)]+)\)/g;let i;for(;null!==(i=e.exec(t));){const[,t,e]=i;switch(t){case"blur":{const t=parseFloat(e.replace("px",""));return function(e){this.blurRadius(.5*t);const i=At.Filters;i&&i.Blur&&i.Blur.call(this,e)}}case"brightness":{const t=e.includes("%")?parseFloat(e)/100:parseFloat(e);return function(e){this.brightness(t);const i=At.Filters;i&&i.Brightness&&i.Brightness.call(this,e)}}case"contrast":{const t=parseFloat(e);return function(e){const i=100*(Math.sqrt(t)-1);this.contrast(i);const s=At.Filters;s&&s.Contrast&&s.Contrast.call(this,e)}}case"grayscale":return function(t){const e=At.Filters;e&&e.Grayscale&&e.Grayscale.call(this,t)};case"sepia":return function(t){const e=At.Filters;e&&e.Sepia&&e.Sepia.call(this,t)};case"invert":return function(t){const e=At.Filters;e&&e.Invert&&e.Invert.call(this,t)};default:Gt.warn(`CSS filter "${t}" is not supported in fallback mode. Consider using function filters for better compatibility.`)}}return()=>{}}const he="absoluteOpacity",le="allEventListeners",de="absoluteTransform",ce="absoluteScale",ue="canvas",ge="listening",pe="Shape",me=" ",fe="stage",_e="transform",ve="visible",ye=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(me);let we=1;class xe{constructor(t){this._id=we++,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!==_e&&t!==de||!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===_e||t===de)&&!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(me);this.on(i,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,i)}_getCanvasCache(){return this._cache.get(ue)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===de&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(ue)){const{scene:t,filter:e,hit:i,buffer:s}=this._cache.get(ue);Gt.releaseCanvas(t,e,i,s),this._cache.delete(ue)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const e=t||{};let i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let s=Math.ceil(e.width||i.width),r=Math.ceil(e.height||i.height),n=e.pixelRatio,a=void 0===e.x?Math.floor(i.x):e.x,o=void 0===e.y?Math.floor(i.y):e.y,h=e.offset||0,l=e.drawBorder||!1,d=e.hitCanvasPixelRatio||1;if(!s||!r)return void Gt.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)-a)>.5?1:0),r+=2*h+(Math.abs(Math.round(i.y)-o)>.5?1:0),a-=h,o-=h;const c=new Yt({pixelRatio:n,width:s,height:r}),u=new Yt({pixelRatio:n,width:0,height:0,willReadFrequently:!0}),g=new Jt({pixelRatio:d,width:s,height:r}),p=c.getContext(),m=g.getContext(),f=new Yt({width:c.width/c.pixelRatio+Math.abs(a),height:c.height/c.pixelRatio+Math.abs(o),pixelRatio:c.pixelRatio}),_=f.getContext();return g.isCache=!0,c.isCache=!0,this._cache.delete(ue),this._filterUpToDate=!1,!1===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,u.getContext()._context.imageSmoothingEnabled=!1),p.save(),m.save(),_.save(),p.translate(-a,-o),m.translate(-a,-o),_.translate(-a,-o),f.x=a,f.y=o,this._isUnderCache=!0,this._clearSelfAndDescendantCache(he),this._clearSelfAndDescendantCache(ce),this.drawScene(c,this,f),this.drawHit(g,this),this._isUnderCache=!1,p.restore(),m.restore(),l&&(p.save(),p.beginPath(),p.rect(0,0,s,r),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.set(ue,{scene:c,filter:u,hit:g,buffer:f,x:a,y:o}),this._requestDraw(),this}isCached(){return this._cache.has(ue)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,e){const i=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let s=1/0,r=1/0,n=-1/0,a=-1/0;const o=this.getAbsoluteTransform(e);return i.forEach(function(t){const e=o.point(t);void 0===s&&(s=n=e.x,r=a=e.y),s=Math.min(s,e.x),r=Math.min(r,e.y),n=Math.max(n,e.x),a=Math.max(a,e.y)}),{x:s,y:r,width:n-s,height:a-r}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const e=this._getCanvasCache();t.translate(e.x,e.y);const i=this._getCachedSceneCanvas(),s=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/s,i.height/s),t.restore()}_drawCachedHitCanvas(t){const e=this._getCanvasCache(),i=e.hit;t.save(),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0,i.width/i.pixelRatio,i.height/i.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t,e,i,s,r=this.filters(),n=this._getCanvasCache(),a=n.scene,o=n.filter,h=o.getContext();if(!r||0===r.length)return a;if(this._filterUpToDate)return o;let l=!0;for(let t=0;t<r.length;t++)if("string"==typeof r[t]&&Nt(),"string"!=typeof r[t]||!Nt()){l=!1;break}const d=a.pixelRatio;if(o.setSize(a.width/a.pixelRatio,a.height/a.pixelRatio),l){const t=r.join(" ");return h.save(),h.setAttr("filter",t),h.drawImage(a._canvas,0,0,a.getWidth()/d,a.getHeight()/d),h.restore(),this._filterUpToDate=!0,o}try{for(t=r.length,h.clear(),h.drawImage(a._canvas,0,0,a.getWidth()/d,a.getHeight()/d),e=h.getImageData(0,0,o.getWidth(),o.getHeight()),i=0;i<t;i++)s=r[i],"string"==typeof s&&(s=oe(s)),s.call(this,e),h.putImageData(e,0,0)}catch(t){Gt.error("Unable to apply filter. "+t.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,o}on(t,e){if(this._cache&&this._cache.delete(le),3===arguments.length)return this._delegate.apply(this,arguments);const i=t.split(me);for(let t=0;t<i.length;t++){const s=i[t].split("."),r=s[0],n=s[1]||"";this.eventListeners[r]||(this.eventListeners[r]=[]),this.eventListeners[r].push({name:n,handler:e})}return this}off(t,e){let i,s,r,n,a,o,h=(t||"").split(me),l=h.length;if(this._cache&&this._cache.delete(le),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<l;i++)if(r=h[i],n=r.split("."),a=n[0],o=n[1],a)this.eventListeners[a]&&this._off(a,o,e);else for(s in this.eventListeners)this._off(s,o,e);return this}dispatchEvent(t){const e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this}addEventListener(t,e){return this.on(t,function(t){e.call(this,t.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,e,i){const s=this;this.on(t,function(t){const r=t.target.findAncestors(e,!0,s);for(let e=0;e<r.length;e++)(t=Gt.cloneObject(t)).currentTarget=r[e],i.call(r[e],t)})}remove(){return this.isDragging()&&this.stopDrag(),qt._dragElements.delete(this._id),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(de),this._clearSelfAndDescendantCache(he),this._clearSelfAndDescendantCache(ce),this._clearSelfAndDescendantCache(fe),this._clearSelfAndDescendantCache(ve),this._clearSelfAndDescendantCache(ge)}_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"+Gt._capitalize(t);return Gt._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"+Gt._capitalize(e),Gt._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]))}),this}isListening(){return this._getCache(ge,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(ve,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const e=this.getParent();return!e||e===t||this===t||e._isVisible(t)}shouldDrawHit(t,e=!1){if(t)return this._isVisible(t)&&this._isListening(t);const i=this.getLayer();let s=!1;qt._dragElements.forEach(t=>{"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===i)&&(s=!0)});const r=!e&&!At.hitOnDragEnabled&&(s||At.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,r=this.getDepth(),n=this,a=0;const o=this.getStage();return"Stage"!==n.nodeType&&o&&function o(h){for(t=[],e=h.length,i=0;i<e;i++)s=h[i],a++,s.nodeType!==pe&&(t=t.concat(s.getChildren().slice())),s._id===n._id&&(i=e);t.length>0&&t[0].getDepth()<=r&&o(t)}(o.getChildren()),a}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(_e),this._clearSelfAndDescendantCache(de)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges(()=>{this.x(t.x),this.y(t.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const t=this.getStage();if(!t)return null;const e=t.getPointerPosition();if(!e)return null;const i=this.getAbsoluteTransform().copy();return i.invert(),i.point(e)}getAbsolutePosition(t){let e=!1,i=this.parent;for(;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);const s=this.getAbsoluteTransform(t).getMatrix(),r=new Pt,n=this.offset();return r.m=s.slice(),r.translate(n.x,n.y),r.getTranslation()}setAbsolutePosition(t){const{x:e,y:i,...s}=this._clearTransform();this.attrs.x=e,this.attrs.y=i,this._clearCache(_e);const r=this._getAbsoluteTransform().copy();return r.invert(),r.translate(t.x,t.y),t={x:this.attrs.x+r.getTranslation().x,y:this.attrs.y+r.getTranslation().y},this._setTransform(s),this.setPosition({x:t.x,y:t.y}),this._clearCache(_e),this._clearSelfAndDescendantCache(de),this}_setTransform(t){let e;for(e in t)this.attrs[e]=t[e]}_clearTransform(){const t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}move(t){let e=t.x,i=t.y,s=this.x(),r=this.y();return void 0!==e&&(s+=e),void 0!==i&&(r+=i),this.setPosition({x:s,y:r}),this}_eachAncestorReverse(t,e){let i,s,r=[],n=this.getParent();if(!e||e._id!==this._id){for(r.unshift(this);n&&(!e||n._id!==e._id);)r.unshift(n),n=n.parent;for(i=r.length,s=0;s<i;s++)t(r[s])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return Gt.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 Gt.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 Gt.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 Gt.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 Gt.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&Gt.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(he,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity();const e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t,e,i,s,r,n=this.getAttrs();const a={attrs:{},className:this.getClassName()};for(t in n)e=n[t],r=Gt.isObject(e)&&!Gt._isPlainObject(e)&&!Gt._isArray(e),r||(i="function"==typeof this[t]&&this[t],delete n[t],s=i?i.call(this):null,n[t]=e,s!==e&&(a.attrs[t]=e));return Gt._prepareToStringify(a)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,e,i){const s=[];e&&this._isMatch(t)&&s.push(this);let r=this.parent;for(;r;){if(r===i)return s;r._isMatch(t)&&s.push(r),r=r.parent}return s}isAncestorOf(t){return!1}findAncestor(t,e,i){return this.findAncestors(t,e,i)[0]}_isMatch(t){if(!t)return!1;if("function"==typeof t)return t(this);let e,i,s=t.replace(/ /g,"").split(","),r=s.length;for(e=0;e<r;e++)if(i=s[e],Gt.isValidSelector(i)||(Gt.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),Gt.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),Gt.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(fe,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(de,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let e;if(t)return e=new Pt,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(de)||new Pt,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();const t=this.transformsEnabled();if("all"===t)e.multiply(this.getTransform());else if("position"===t){const t=this.attrs.x||0,i=this.attrs.y||0,s=this.attrs.offsetX||0,r=this.attrs.offsetY||0;e.translate(t-s,i-r)}return e.dirty=!1,e}}getAbsoluteScale(t){let e=this;for(;e;)e._isUnderCache&&(t=e),e=e.getParent();const i=this.getAbsoluteTransform(t).decompose();return{x:i.scaleX,y:i.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(_e,this._getTransform)}_getTransform(){var t,e;const i=this._cache.get(_e)||new Pt;i.reset();const s=this.x(),r=this.y(),n=At.getAngle(this.rotation()),a=null!==(t=this.attrs.scaleX)&&void 0!==t?t:1,o=null!==(e=this.attrs.scaleY)&&void 0!==e?e:1,h=this.attrs.skewX||0,l=this.attrs.skewY||0,d=this.attrs.offsetX||0,c=this.attrs.offsetY||0;return 0===s&&0===r||i.translate(s,r),0!==n&&i.rotate(n),0===h&&0===l||i.skew(h,l),1===a&&1===o||i.scale(a,o),0===d&&0===c||i.translate(-1*d,-1*c),i.dirty=!1,i}clone(t){let e,i,s,r,n,a=Gt.cloneObject(this.attrs);for(e in t)a[e]=t[e];const o=new this.constructor(a);for(e in this.eventListeners)for(i=this.eventListeners[e],s=i.length,r=0;r<s;r++)n=i[r],n.name.indexOf("konva")<0&&(o.eventListeners[e]||(o.eventListeners[e]=[]),o.eventListeners[e].push(n));return o}_toKonvaCanvas(t){t=t||{};const e=this.getClientRect(),i=this.getStage(),s=void 0!==t.x?t.x:Math.floor(e.x),r=void 0!==t.y?t.y:Math.floor(e.y),n=t.pixelRatio||1,a=new Yt({width:t.width||Math.ceil(e.width)||(i?i.width():0),height:t.height||Math.ceil(e.height)||(i?i.height():0),pixelRatio:n}),o=a.getContext(),h=new Yt({width:a.width/a.pixelRatio+Math.abs(s),height:a.height/a.pixelRatio+Math.abs(r),pixelRatio:a.pixelRatio});return!1===t.imageSmoothingEnabled&&(o._context.imageSmoothingEnabled=!1),o.save(),(s||r)&&o.translate(-1*s,-1*r),this.drawScene(a,void 0,h),o.restore(),a}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,Gt._urlToImage(this.toDataURL(t),function(t){e(t),null==i||i(t)})}catch(t){i(t)}})}toBlob(t){return new Promise((e,i)=>{try{const i=null==t?void 0:t.callback;i&&delete t.callback,this.toCanvas(t).toBlob(t=>{e(t),null==i||i(t)},null==t?void 0:t.mimeType,null==t?void 0:t.quality)}catch(t){i(t)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():At.dragDistance}_off(t,e,i){let s,r,n,a=this.eventListeners[t];for(s=0;s<a.length;s++)if(r=a[s].name,n=a[s].handler,!("konva"===r&&"konva"!==e||e&&r!==e||i&&i!==n)){if(a.splice(s,1),0===a.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"+Gt._capitalize(t)];return Gt._isFunction(i)?i.call(this,e):this._setAttr(t,e),this}_requestDraw(){if(At.autoDrawEnabled){const t=this.getLayer()||this.getStage();null==t||t.batchDraw()}}_setAttr(t,e){const i=this.attrs[t];(i!==e||Gt.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===pe&&(e.target=this);const s=["mouseenter","mouseleave","pointerenter","pointerleave","touchenter","touchleave"];if(!(-1!==s.indexOf(t)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);const r=-1!==s.indexOf(t)&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!r&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i):this._fireAndBubble.call(this.parent,t,e))}}_getProtoListeners(t){var e,i,s;const r=null!==(e=this._cache.get(le))&&void 0!==e?e:{};let n=null==r?void 0:r[t];if(void 0===n){n=[];let e=Object.getPrototypeOf(this);for(;e;){const r=null!==(s=null===(i=e.eventListeners)||void 0===i?void 0:i[t])&&void 0!==s?s:[];n.push(...r),e=Object.getPrototypeOf(e)}r[t]=n,this._cache.set(le,r)}return n}_fire(t,e){(e=e||{}).currentTarget=this,e.type=t;const i=this._getProtoListeners(t);if(i)for(let t=0;t<i.length;t++)i[t].handler.call(this,e);const s=this.eventListeners[t];if(s)for(let t=0;t<s.length;t++)s[t].handler.call(this,e)}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const e=t?t.pointerId:void 0,i=this.getStage(),s=this.getAbsolutePosition();if(!i)return;const r=i._getPointerById(e)||i._changedPointerPositions[0]||s;qt._dragElements.set(this._id,{node:this,startPointerPos:r,offset:{x:r.x-s.x,y:r.y-s.y},dragStatus:"ready",pointerId:e})}startDrag(t,e=!0){qt._dragElements.has(this._id)||this._createDragElement(t);qt._dragElements.get(this._id).dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:t&&t.evt},e)}_setDragPosition(t,e){const i=this.getStage()._getPointerById(e.pointerId);if(!i)return;let s={x:i.x-e.offset.x,y:i.y-e.offset.y};const r=this.dragBoundFunc();if(void 0!==r){const e=r.call(this,s,t);e?s=e:Gt.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=qt._dragElements.get(this._id);e&&(e.dragStatus="stopped"),qt._endDragBefore(t),qt._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=qt._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)||At.dragButtons.indexOf(t.evt.button)>=0))return;if(this.isDragging())return;let e=!1;qt._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=qt._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&qt._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 Gt.haveIntersection(i,this.getClientRect())}static create(t,e){return Gt._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}static _createNode(t,e){let i,s,r,n=xe.prototype.getClassName.call(t),a=t.children;e&&(t.attrs.container=e),At[n]||(Gt.warn('Can not find a node with class name "'+n+'". Fallback to "Shape".'),n="Shape");if(i=new(0,At[n])(t.attrs),a)for(s=a.length,r=0;r<s;r++)i.add(xe._createNode(a[r]));return i}}xe.prototype.nodeType="Node",xe.prototype._attrsAffectingSize=[],xe.prototype.eventListeners={},xe.prototype.on.call(xe.prototype,ye,function(){this._batchingTransformChange?this._needClearTransformCache=!0:(this._clearCache(_e),this._clearSelfAndDescendantCache(de))}),xe.prototype.on.call(xe.prototype,"visibleChange.konva",function(){this._clearSelfAndDescendantCache(ve)}),xe.prototype.on.call(xe.prototype,"listeningChange.konva",function(){this._clearSelfAndDescendantCache(ge)}),xe.prototype.on.call(xe.prototype,"opacityChange.konva",function(){this._clearSelfAndDescendantCache(he)});const be=ae.addGetterSetter;be(xe,"zIndex"),be(xe,"absolutePosition"),be(xe,"position"),be(xe,"x",0,$t()),be(xe,"y",0,$t()),be(xe,"globalCompositeOperation","source-over",ee()),be(xe,"opacity",1,$t()),be(xe,"name","",ee()),be(xe,"id","",ee()),be(xe,"rotation",0,$t()),ae.addComponentsGetterSetter(xe,"scale",["x","y"]),be(xe,"scaleX",1,$t()),be(xe,"scaleY",1,$t()),ae.addComponentsGetterSetter(xe,"skew",["x","y"]),be(xe,"skewX",0,$t()),be(xe,"skewY",0,$t()),ae.addComponentsGetterSetter(xe,"offset",["x","y"]),be(xe,"offsetX",0,$t()),be(xe,"offsetY",0,$t()),be(xe,"dragDistance",void 0,$t()),be(xe,"width",0,$t()),be(xe,"height",0,$t()),be(xe,"listening",!0,se()),be(xe,"preventDefault",!0,se()),be(xe,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),be(xe,"visible",!0,se()),be(xe,"transformsEnabled","all",ee()),be(xe,"size"),be(xe,"dragBoundFunc"),be(xe,"draggable",!1,se()),ae.backCompat(xe,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});class Se extends xe{constructor(){super(...arguments),this.children=[]}getChildren(t){const e=this.children||[];return t?e.filter(t):e}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(t=>{t.parent=null,t.index=0,t.destroy()}),this.children=[],this._requestDraw(),this}add(...t){if(0===t.length)return this;if(t.length>1){for(let e=0;e<t.length;e++)this.add(t[e]);return this}const e=t[0];return e.getParent()?(e.moveTo(this),this):(this._validateAdd(e),e.index=this.getChildren().length,e.parent=this,e._clearCaches(),this.getChildren().push(e),this._fire("add",{child:e}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(t){return this._generalFind(t,!1)}findOne(t){const e=this._generalFind(t,!0);return e.length>0?e[0]:void 0}_generalFind(t,e){const i=[];return this._descendants(s=>{const r=s._isMatch(t);return r&&i.push(s),!(!r||!e)}),i}_descendants(t){let e=!1;const i=this.getChildren();for(const s of i){if(e=t(s),e)return!0;if(s.hasChildren()&&(e=s._descendants(t),e))return!0}return!1}toObject(){const t=xe.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=xe.prototype.clone.call(this,t);return this.getChildren().forEach(function(t){e.add(t.clone())}),e}getAllIntersections(t){const e=[];return this.find("Shape").forEach(i=>{i.isVisible()&&i.intersects(t)&&e.push(i)}),e}_clearSelfAndDescendantCache(t){var e;super._clearSelfAndDescendantCache(t),this.isCached()||null===(e=this.children)||void 0===e||e.forEach(function(e){e._clearSelfAndDescendantCache(t)})}_setChildrenIndices(){var t;null===(t=this.children)||void 0===t||t.forEach(function(t,e){t.index=e}),this._requestDraw()}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas(),n=r&&r.getContext(),a=this._getCanvasCache(),o=a&&a.scene,h=r&&r.isCache;if(!this.isVisible()&&!h)return this;if(o){n.save();const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(n),n.restore()}else this._drawChildren("drawScene",r,e,i);return this}drawHit(t,e){if(!this.shouldDrawHit(e))return this;const i=this.getLayer(),s=t||i&&i.hitCanvas,r=s&&s.getContext(),n=this._getCanvasCache();if(n&&n.hit){r.save();const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(r),r.restore()}else this._drawChildren("drawHit",s,e);return this}_drawChildren(t,e,i,s){var r;const n=e&&e.getContext(),a=this.clipWidth(),o=this.clipHeight(),h=this.clipFunc(),l="number"==typeof a&&"number"==typeof o||h,d=i===this;if(l){n.save();const t=this.getAbsoluteTransform(i);let e,s=t.getMatrix();if(n.transform(s[0],s[1],s[2],s[3],s[4],s[5]),n.beginPath(),h)e=h.call(this,n,this);else{const t=this.clipX(),e=this.clipY();n.rect(t||0,e||0,a,o)}n.clip.apply(n,e),s=t.copy().invert().getMatrix(),n.transform(s[0],s[1],s[2],s[3],s[4],s[5])}const c=!d&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;c&&(n.save(),n._applyGlobalCompositeOperation(this)),null===(r=this.children)||void 0===r||r.forEach(function(r){r[t](e,i,s)}),c&&n.restore(),l&&n.restore()}getClientRect(t={}){var e;const i=t.skipTransform,s=t.relativeTo;let r,n,a,o,h={x:1/0,y:1/0,width:0,height:0};const l=this;null===(e=this.children)||void 0===e||e.forEach(function(e){if(!e.visible())return;const i=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===i.width&&0===i.height||(void 0===r?(r=i.x,n=i.y,a=i.x+i.width,o=i.y+i.height):(r=Math.min(r,i.x),n=Math.min(n,i.y),a=Math.max(a,i.x+i.width),o=Math.max(o,i.y+i.height)))});const d=this.find("Shape");let c=!1;for(let t=0;t<d.length;t++){if(d[t]._isVisible(this)){c=!0;break}}return h=c&&void 0!==r?{x:r,y:n,width:a-r,height:o-n}:{x:0,y:0,width:0,height:0},i?h:this._transformedRect(h,s)}}ae.addComponentsGetterSetter(Se,"clip",["x","y","width","height"]),ae.addGetterSetter(Se,"clipX",void 0,$t()),ae.addGetterSetter(Se,"clipY",void 0,$t()),ae.addGetterSetter(Se,"clipWidth",void 0,$t()),ae.addGetterSetter(Se,"clipHeight",void 0,$t()),ae.addGetterSetter(Se,"clipFunc");const Ce=new Map,Ae=void 0!==At._global.PointerEvent;function Te(t){return Ce.get(t)}function ke(t){return{evt:t,pointerId:t.pointerId}}function Pe(t,e){return Ce.get(t)===e}function Ee(t,e){Me(t);e.getStage()&&(Ce.set(t,e),Ae&&e._fire("gotpointercapture",ke(new PointerEvent("gotpointercapture"))))}function Me(t,e){const i=Ce.get(t);if(!i)return;const s=i.getStage();s&&s.content,Ce.delete(t),Ae&&i._fire("lostpointercapture",ke(new PointerEvent("lostpointercapture")))}const Ie="mouseleave",Re="mouseover",De="mouseenter",Le="mousemove",Oe="mousedown",ze="mouseup",Fe="pointermove",Ge="pointerdown",Ve="pointerup",We="pointercancel",Be="pointerout",Ne="pointerleave",je="pointerover",He="pointerenter",Ue="contextmenu",Xe="touchstart",Ye="touchend",Je="touchmove",qe="touchcancel",Ke="wheel",Ze=[[De,"_pointerenter"],[Oe,"_pointerdown"],[Le,"_pointermove"],[ze,"_pointerup"],[Ie,"_pointerleave"],[Xe,"_pointerdown"],[Je,"_pointermove"],[Ye,"_pointerup"],[qe,"_pointercancel"],[Re,"_pointerover"],[Ke,"_wheel"],[Ue,"_contextmenu"],[Ge,"_pointerdown"],[Fe,"_pointermove"],[Ve,"_pointerup"],[We,"_pointercancel"],[Ne,"_pointerleave"],["lostpointercapture","_lostpointercapture"]],$e={mouse:{[Be]:"mouseout",[Ne]:Ie,[je]:Re,[He]:De,[Fe]:Le,[Ge]:Oe,[Ve]:ze,[We]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[Be]:"touchout",[Ne]:"touchleave",[je]:"touchover",[He]:"touchenter",[Fe]:Je,[Ge]:Xe,[Ve]:Ye,[We]:qe,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[Be]:Be,[Ne]:Ne,[je]:je,[He]:He,[Fe]:Fe,[Ge]:Ge,[Ve]:Ve,[We]:We,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},Qe=t=>t.indexOf("pointer")>=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse",ti=t=>{const e=Qe(t);return"pointer"===e?At.pointerEventsEnabled&&$e.pointer:"touch"===e?$e.touch:"mouse"===e?$e.mouse:void 0};function ei(t={}){return(t.clipFunc||t.clipWidth||t.clipHeight)&&Gt.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}const ii=[];class si extends Se{constructor(t){super(ei(t)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),ii.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{ei(this.attrs)}),this._checkVisibility()}_validateAdd(t){const e="Layer"===t.getType(),i="FastLayer"===t.getType();e||i||Gt.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"),Se.prototype.clone.call(this,t)}destroy(){super.destroy();const t=this.content;t&&Gt._isInDocument(t)&&this.container().removeChild(t);const e=ii.indexOf(this);return e>-1&&ii.splice(e,1),Gt.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}:(Gt.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 Yt({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,s=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),s.forEach(function(e){if(!e.isVisible())return;const s=e._toKonvaCanvas(t);i.drawImage(s._canvas,t.x,t.y,s.getWidth()/s.getPixelRatio(),s.getHeight()/s.getPixelRatio())}),e}getIntersection(t){if(!t)return null;const e=this.children;for(let i=e.length-1;i>=0;i--){const s=e[i].getIntersection(t);if(s)return s}return null}_resizeDOM(){const t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach(i=>{i.setSize({width:t,height:e}),i.draw()})}add(t,...e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}super.add(t);const i=this.children.length;return i>5&&Gt.warn("The stage has "+i+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),t.setSize({width:this.width(),height:this.height()}),t.draw(),At.isBrowser&&this.content.appendChild(t.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(t){return Pe(t,this)}setPointerCapture(t){Ee(t,this)}releaseCapture(t){Me(t)}getLayers(){return this.children}_bindContentEvents(){At.isBrowser&&Ze.forEach(([t,e])=>{this.content.addEventListener(t,t=>{this[e](t)},{passive:!1})})}_pointerenter(t){this.setPointersPositions(t);const e=ti(t.type);e&&this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}_pointerover(t){this.setPointersPositions(t);const e=ti(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=ti(t.type),i=Qe(t.type);if(!e)return;this.setPointersPositions(t);const s=this._getTargetShape(i),r=!(At.isDragging()||At.isTransforming())||At.hitOnDragEnabled;s&&r?(s._fireAndBubble(e.pointerout,{evt:t}),s._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"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=ti(t.type),i=Qe(t.type);if(!e)return;this.setPointersPositions(t);let s=!1;this._changedPointerPositions.forEach(r=>{const n=this.getIntersection(r);if(qt.justDragged=!1,At["_"+i+"ListenClick"]=!0,!n||!n.isListening())return void(this[i+"ClickStartShape"]=void 0);At.capturePointerEventsEnabled&&n.setPointerCapture(r.id),this[i+"ClickStartShape"]=n,n._fireAndBubble(e.pointerdown,{evt:t,pointerId:r.id}),s=!0;const a=t.type.indexOf("touch")>=0;n.preventDefault()&&t.cancelable&&a&&t.preventDefault()}),s||this._fire(e.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(t){const e=ti(t.type),i=Qe(t.type);if(!e)return;const s=t.type.indexOf("touch")>=0||"touch"===t.pointerType;At.isDragging()&&qt.node.preventDefault()&&t.cancelable&&s&&t.preventDefault(),this.setPointersPositions(t);if(!(!(At.isDragging()||At.isTransforming())||At.hitOnDragEnabled))return;const r={};let n=!1;const a=this._getTargetShape(i);this._changedPointerPositions.forEach(s=>{const o=Te(s.id)||this.getIntersection(s),h=s.id,l={evt:t,pointerId:h},d=a!==o;if(d&&a&&(a._fireAndBubble(e.pointerout,{...l},o),a._fireAndBubble(e.pointerleave,{...l},o)),o){if(r[o._id])return;r[o._id]=!0}o&&o.isListening()?(n=!0,d&&(o._fireAndBubble(e.pointerover,{...l},a),o._fireAndBubble(e.pointerenter,{...l},a),this[i+"targetShape"]=o),o._fireAndBubble(e.pointermove,{...l})):a&&(this._fire(e.pointerover,{evt:t,target:this,currentTarget:this,pointerId:h}),this[i+"targetShape"]=null)}),n||this._fire(e.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(t){const e=ti(t.type),i=Qe(t.type);if(!e)return;this.setPointersPositions(t);const s=this[i+"ClickStartShape"],r=this[i+"ClickEndShape"],n={};let a=!1;this._changedPointerPositions.forEach(o=>{const h=Te(o.id)||this.getIntersection(o);if(h){if(h.releaseCapture(o.id),n[h._id])return;n[h._id]=!0}const l=o.id,d={evt:t,pointerId:l};let c=!1;At["_"+i+"InDblClickWindow"]?(c=!0,clearTimeout(this[i+"DblTimeout"])):qt.justDragged||(At["_"+i+"InDblClickWindow"]=!0,clearTimeout(this[i+"DblTimeout"])),this[i+"DblTimeout"]=setTimeout(function(){At["_"+i+"InDblClickWindow"]=!1},At.dblClickWindow),h&&h.isListening()?(a=!0,this[i+"ClickEndShape"]=h,h._fireAndBubble(e.pointerup,{...d}),At["_"+i+"ListenClick"]&&s&&s===h&&(h._fireAndBubble(e.pointerclick,{...d}),c&&r&&r===h&&h._fireAndBubble(e.pointerdblclick,{...d}))):(this[i+"ClickEndShape"]=null,a||(this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),a=!0),At["_"+i+"ListenClick"]&&this._fire(e.pointerclick,{evt:t,target:this,currentTarget:this,pointerId:l}),c&&this._fire(e.pointerdblclick,{evt:t,target:this,currentTarget:this,pointerId:l}))}),a||this._fire(e.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),At["_"+i+"ListenClick"]=!1,t.cancelable&&"touch"!==i&&"pointer"!==i&&t.preventDefault()}_contextmenu(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ue,{evt:t}):this._fire(Ue,{evt:t,target:this,currentTarget:this})}_wheel(t){this.setPointersPositions(t);const e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(Ke,{evt:t}):this._fire(Ke,{evt:t,target:this,currentTarget:this})}_pointercancel(t){this.setPointersPositions(t);const e=Te(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(Ve,ke(t)),Me(t.pointerId)}_lostpointercapture(t){Me(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:Gt._getFirstPointerId(t)}],this._changedPointerPositions=[{x:i,y:s,id:Gt._getFirstPointerId(t)}])}_setPointerPosition(t){Gt.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 Yt({width:this.width(),height:this.height()}),this.bufferHitCanvas=new Jt({pixelRatio:1,width:this.width(),height:this.height()}),!At.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 Gt.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}}si.prototype.nodeType="Stage",Tt(si),ae.addGetterSetter(si,"container"),At.isBrowser&&document.addEventListener("visibilitychange",()=>{ii.forEach(t=>{t.batchDraw()})});const ri="hasShadow",ni="shadowRGBA",ai="patternImage",oi="linearGradient",hi="radialGradient";let li;function di(){return li||(li=Gt.createCanvasElement().getContext("2d"),li)}const ci={};class ui extends xe{constructor(t){let e;super(t);let i=0;for(;e=Gt.getHitColor(),!e||e in ci;)if(i++,i>=1e4){Gt.warn("Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it."),e=Gt.getRandomColor();break}this.colorKey=e,ci[e]=this}getContext(){return Gt.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return Gt.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(ri,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(ai,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const t=di().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){const e=new Pt;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(At.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const i=e.getMatrix(),s="undefined"==typeof DOMMatrix?{a:i[0],b:i[1],c:i[2],d:i[3],e:i[4],f:i[5]}:new DOMMatrix(i);t.setTransform(s)}return t}}_getLinearGradient(){return this._getCache(oi,this.__getLinearGradient)}__getLinearGradient(){const t=this.fillLinearGradientColorStops();if(t){const e=di(),i=this.fillLinearGradientStartPoint(),s=this.fillLinearGradientEndPoint(),r=e.createLinearGradient(i.x,i.y,s.x,s.y);for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}_getRadialGradient(){return this._getCache(hi,this.__getRadialGradient)}__getRadialGradient(){const t=this.fillRadialGradientColorStops();if(t){const e=di(),i=this.fillRadialGradientStartPoint(),s=this.fillRadialGradientEndPoint(),r=e.createRadialGradient(i.x,i.y,this.fillRadialGradientStartRadius(),s.x,s.y,this.fillRadialGradientEndRadius());for(let e=0;e<t.length;e+=2)r.addColorStop(t[e],t[e+1]);return r}}getShadowRGBA(){return this._getCache(ni,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const t=Gt.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 xe.prototype.destroy.call(this),delete ci[this.colorKey],delete this.colorKey,this}_useBufferCanvas(t){var e;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;const i=t||this.hasFill(),s=this.hasStroke(),r=1!==this.getAbsoluteOpacity();if(i&&s&&r)return!0;const n=this.hasShadow(),a=this.shadowForStrokeEnabled();return!!(i&&s&&n&&a)}setStrokeHitEnabled(t){Gt.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return 0!==this.hitStrokeWidth()}getSelfRect(){const t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}getClientRect(t={}){let e=!1,i=this.getParent();for(;i;){if(i.isCached()){e=!0;break}i=i.getParent()}const s=t.skipTransform,r=t.relativeTo||e&&this.getStage()||void 0,n=this.getSelfRect(),a=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,o=n.width+a,h=n.height+a,l=!t.skipShadow&&this.hasShadow(),d=l?this.shadowOffsetX():0,c=l?this.shadowOffsetY():0,u=o+Math.abs(d),g=h+Math.abs(c),p=l&&this.shadowBlur()||0,m={width:u+2*p,height:g+2*p,x:-(a/2+p)+Math.min(d,0)+n.x,y:-(a/2+p)+Math.min(c,0)+n.y};return s?m:this._transformedRect(m,r)}drawScene(t,e,i){const s=this.getLayer(),r=(t||s.getCanvas()).getContext(),n=this._getCanvasCache(),a=this.getSceneFunc(),o=this.hasShadow();let h;const l=e===this;if(!this.isVisible()&&!l)return this;if(n){r.save();const t=this.getAbsoluteTransform(e).getMatrix();return r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedSceneCanvas(r),r.restore(),this}if(!a)return this;if(r.save(),this._useBufferCanvas()){h=this.getStage();const t=i||h.bufferCanvas,s=t.getContext();s.clear(),s.save(),s._applyLineJoin(this),s._applyMiterLimit(this);const n=this.getAbsoluteTransform(e).getMatrix();s.transform(n[0],n[1],n[2],n[3],n[4],n[5]),a.call(this,s,this),s.restore();const d=t.pixelRatio;o&&r._applyShadow(this),l||(r._applyOpacity(this),r._applyGlobalCompositeOperation(this)),r.drawImage(t._canvas,t.x||0,t.y||0,t.width/d,t.height/d)}else{if(r._applyLineJoin(this),r._applyMiterLimit(this),!l){const t=this.getAbsoluteTransform(e).getMatrix();r.transform(t[0],t[1],t[2],t[3],t[4],t[5]),r._applyOpacity(this),r._applyGlobalCompositeOperation(this)}o&&r._applyShadow(this),a.call(this,r,this)}return r.restore(),this}drawHit(t,e,i=!1){if(!this.shouldDrawHit(e,i))return this;const s=this.getLayer(),r=t||s.hitCanvas,n=r&&r.getContext(),a=this.hitFunc()||this.sceneFunc(),o=this._getCanvasCache(),h=o&&o.hit;if(this.colorKey||Gt.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),h){n.save();const t=this.getAbsoluteTransform(e).getMatrix();return n.transform(t[0],t[1],t[2],t[3],t[4],t[5]),this._drawCachedHitCanvas(n),n.restore(),this}if(!a)return this;n.save(),n._applyLineJoin(this),n._applyMiterLimit(this);if(!(this===e)){const t=this.getAbsoluteTransform(e).getMatrix();n.transform(t[0],t[1],t[2],t[3],t[4],t[5])}return a.call(this,n,this),n.restore(),this}drawHitFromCache(t=0){const e=this._getCanvasCache(),i=this._getCachedSceneCanvas(),s=e.hit,r=s.getContext(),n=s.getWidth(),a=s.getHeight();r.clear(),r.drawImage(i._canvas,0,0,n,a);try{const e=r.getImageData(0,0,n,a),i=e.data,s=i.length,o=Gt._hexToRgb(this.colorKey);for(let e=0;e<s;e+=4){i[e+3]>t?(i[e]=o.r,i[e+1]=o.g,i[e+2]=o.b,i[e+3]=255):i[e+3]=0}r.putImageData(e,0,0)}catch(t){Gt.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}hasPointerCapture(t){return Pe(t,this)}setPointerCapture(t){Ee(t,this)}releaseCapture(t){Me(t)}}ui.prototype._fillFunc=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},ui.prototype._strokeFunc=function(t){t.stroke()},ui.prototype._fillFuncHit=function(t){const e=this.attrs.fillRule;e?t.fill(e):t.fill()},ui.prototype._strokeFuncHit=function(t){t.stroke()},ui.prototype._centroid=!1,ui.prototype.nodeType="Shape",Tt(ui),ui.prototype.eventListeners={},ui.prototype.on.call(ui.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(ri)}),ui.prototype.on.call(ui.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",function(){this._clearCache(ni)}),ui.prototype.on.call(ui.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",function(){this._clearCache(ai)}),ui.prototype.on.call(ui.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",function(){this._clearCache(oi)}),ui.prototype.on.call(ui.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",function(){this._clearCache(hi)}),ae.addGetterSetter(ui,"stroke",void 0,ie()),ae.addGetterSetter(ui,"strokeWidth",2,$t()),ae.addGetterSetter(ui,"fillAfterStrokeEnabled",!1),ae.addGetterSetter(ui,"hitStrokeWidth","auto",te()),ae.addGetterSetter(ui,"strokeHitEnabled",!0,se()),ae.addGetterSetter(ui,"perfectDrawEnabled",!0,se()),ae.addGetterSetter(ui,"shadowForStrokeEnabled",!0,se()),ae.addGetterSetter(ui,"lineJoin"),ae.addGetterSetter(ui,"lineCap"),ae.addGetterSetter(ui,"miterLimit"),ae.addGetterSetter(ui,"sceneFunc"),ae.addGetterSetter(ui,"hitFunc"),ae.addGetterSetter(ui,"dash"),ae.addGetterSetter(ui,"dashOffset",0,$t()),ae.addGetterSetter(ui,"shadowColor",void 0,ee()),ae.addGetterSetter(ui,"shadowBlur",0,$t()),ae.addGetterSetter(ui,"shadowOpacity",1,$t()),ae.addComponentsGetterSetter(ui,"shadowOffset",["x","y"]),ae.addGetterSetter(ui,"shadowOffsetX",0,$t()),ae.addGetterSetter(ui,"shadowOffsetY",0,$t()),ae.addGetterSetter(ui,"fillPatternImage"),ae.addGetterSetter(ui,"fill",void 0,ie()),ae.addGetterSetter(ui,"fillPatternX",0,$t()),ae.addGetterSetter(ui,"fillPatternY",0,$t()),ae.addGetterSetter(ui,"fillLinearGradientColorStops"),ae.addGetterSetter(ui,"strokeLinearGradientColorStops"),ae.addGetterSetter(ui,"fillRadialGradientStartRadius",0),ae.addGetterSetter(ui,"fillRadialGradientEndRadius",0),ae.addGetterSetter(ui,"fillRadialGradientColorStops"),ae.addGetterSetter(ui,"fillPatternRepeat","repeat"),ae.addGetterSetter(ui,"fillEnabled",!0),ae.addGetterSetter(ui,"strokeEnabled",!0),ae.addGetterSetter(ui,"shadowEnabled",!0),ae.addGetterSetter(ui,"dashEnabled",!0),ae.addGetterSetter(ui,"strokeScaleEnabled",!0),ae.addGetterSetter(ui,"fillPriority","color"),ae.addComponentsGetterSetter(ui,"fillPatternOffset",["x","y"]),ae.addGetterSetter(ui,"fillPatternOffsetX",0,$t()),ae.addGetterSetter(ui,"fillPatternOffsetY",0,$t()),ae.addComponentsGetterSetter(ui,"fillPatternScale",["x","y"]),ae.addGetterSetter(ui,"fillPatternScaleX",1,$t()),ae.addGetterSetter(ui,"fillPatternScaleY",1,$t()),ae.addComponentsGetterSetter(ui,"fillLinearGradientStartPoint",["x","y"]),ae.addComponentsGetterSetter(ui,"strokeLinearGradientStartPoint",["x","y"]),ae.addGetterSetter(ui,"fillLinearGradientStartPointX",0),ae.addGetterSetter(ui,"strokeLinearGradientStartPointX",0),ae.addGetterSetter(ui,"fillLinearGradientStartPointY",0),ae.addGetterSetter(ui,"strokeLinearGradientStartPointY",0),ae.addComponentsGetterSetter(ui,"fillLinearGradientEndPoint",["x","y"]),ae.addComponentsGetterSetter(ui,"strokeLinearGradientEndPoint",["x","y"]),ae.addGetterSetter(ui,"fillLinearGradientEndPointX",0),ae.addGetterSetter(ui,"strokeLinearGradientEndPointX",0),ae.addGetterSetter(ui,"fillLinearGradientEndPointY",0),ae.addGetterSetter(ui,"strokeLinearGradientEndPointY",0),ae.addComponentsGetterSetter(ui,"fillRadialGradientStartPoint",["x","y"]),ae.addGetterSetter(ui,"fillRadialGradientStartPointX",0),ae.addGetterSetter(ui,"fillRadialGradientStartPointY",0),ae.addComponentsGetterSetter(ui,"fillRadialGradientEndPoint",["x","y"]),ae.addGetterSetter(ui,"fillRadialGradientEndPointX",0),ae.addGetterSetter(ui,"fillRadialGradientEndPointY",0),ae.addGetterSetter(ui,"fillPatternRotation",0),ae.addGetterSetter(ui,"fillRule",void 0,ee()),ae.backCompat(ui,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});const gi=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],pi=gi.length;class mi extends Se{constructor(t){super(t),this.canvas=new Yt,this.hitCanvas=new Jt({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(){xe.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(!xe.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(xe.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(xe.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 xe.prototype.remove.call(this),t&&t.parentNode&&Gt._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&&Gt.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(),xe.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(){Gt.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){Gt.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,Gt.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<pi;s++){const r=gi[s],n=this._getIntersection({x:t.x+r.x*e,y:t.y+r.y*e}),a=n.shape;if(a)return a;if(i=!!n.antialiased,!n.antialiased)break}if(!i)return null;e+=1}}_getIntersection(t){const e=this.hitCanvas.pixelRatio,i=this.hitCanvas.context.getImageData(Math.round(t.x*e),Math.round(t.y*e),1,1).data,s=i[3];if(255===s){const t=Gt.getHitColorKey(i[0],i[1],i[2]),e=ci[t];return e?{shape:e}:{antialiased:!0}}return s>0?{antialiased:!0}:{}}drawScene(t,e,i){const s=this.getLayer(),r=t||s&&s.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),Se.prototype.drawScene.call(this,r,e,i),this._fire("draw",{node:this}),this}drawHit(t,e){const i=this.getLayer(),s=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),Se.prototype.drawHit.call(this,s,e),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(t){Gt.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}getHitGraphEnabled(t){return Gt.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 Gt.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}}mi.prototype.nodeType="Layer",Tt(mi),ae.addGetterSetter(mi,"imageSmoothingEnabled",!0),ae.addGetterSetter(mi,"clearBeforeDraw",!0),ae.addGetterSetter(mi,"hitGraphEnabled",!0,se());class fi extends mi{constructor(t){super(t),this.listening(!1),Gt.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}}fi.prototype.nodeType="FastLayer",Tt(fi);class _i extends Se{_validateAdd(t){const e=t.getType();"Group"!==e&&"Shape"!==e&&Gt.throw("You may only add groups and shapes to groups.")}}_i.prototype.nodeType="Group",Tt(_i);const vi=Ct.performance&&Ct.performance.now?function(){return Ct.performance.now()}:function(){return(new Date).getTime()};class yi{constructor(t,e){this.id=yi.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:vi(),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=yi.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=vi(),yi._addAnimation(this),this}stop(){return yi._removeAnimation(this),this}_updateFrameObject(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(t){this.animations.push(t),this._handleAnimation()}static _removeAnimation(t){const e=t.id,i=this.animations,s=i.length;for(let t=0;t<s;t++)if(i[t].id===e){this.animations.splice(t,1);break}}static _runFrames(){const t={},e=this.animations;for(let i=0;i<e.length;i++){const s=e[i],r=s.layers,n=s.func;s._updateFrameObject(vi());const a=r.length;let o;if(o=!n||!1!==n.call(s,s.frame),o)for(let e=0;e<a;e++){const i=r[e];void 0!==i._id&&(t[i._id]=i)}}for(const e in t)t.hasOwnProperty(e)&&t[e].batchDraw()}static _animationLoop(){const t=yi;t.animations.length?(t._runFrames(),Gt.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,Gt.requestAnimFrame(this._animationLoop))}}yi.animations=[],yi.animIdCounter=0,yi.animRunning=!1;const wi={node:1,duration:1,easing:1,onFinish:1,yoyo:1},xi=["fill","stroke","shadowColor"];let bi=0;class Si{constructor(t,e,i,s,r,n,a){this.prop=t,this.propFunc=e,this.begin=s,this._pos=s,this.duration=n,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}fire(t){const e=this[t];e&&e()}setTime(t){t>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}getTime(){return this._time}setPosition(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}getPosition(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}play(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}pause(){this.state=1,this.fire("onPause")}getTimer(){return(new Date).getTime()}}class Ci{constructor(t){const e=this,i=t.node,s=i._id,r=t.easing||Ai.Linear,n=!!t.yoyo;let a,o;a=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=i,this._id=bi++;const h=i.getLayer()||(i instanceof At.Stage?i.getLayers():null);for(o in h||Gt.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new yi(function(){e.tween.onEnterFrame()},h),this.tween=new Si(o,function(t){e._tweenFunc(t)},r,0,1,1e3*a,n),this._addListeners(),Ci.attrs[s]||(Ci.attrs[s]={}),Ci.attrs[s][this._id]||(Ci.attrs[s][this._id]={}),Ci.tweens[s]||(Ci.tweens[s]={}),t)void 0===wi[o]&&this._addAttr(o,t[o]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,e){const i=this.node,s=i._id;let r,n,a,o,h;const l=Ci.tweens[s][t];l&&delete Ci.attrs[s][l][t];let d=i.getAttr(t);if(Gt._isArray(e))if(r=[],n=Math.max(e.length,d.length),"points"===t&&e.length!==d.length&&(e.length>d.length?(o=d,d=Gt._prepareArrayForTween(d,e,i.closed())):(a=e,e=Gt._prepareArrayForTween(e,d,i.closed()))),0===t.indexOf("fill"))for(let t=0;t<n;t++)if(t%2==0)r.push(e[t]-d[t]);else{const i=Gt.colorToRGBA(d[t]);h=Gt.colorToRGBA(e[t]),d[t]=i,r.push({r:h.r-i.r,g:h.g-i.g,b:h.b-i.b,a:h.a-i.a})}else for(let t=0;t<n;t++)r.push(e[t]-d[t]);else-1!==xi.indexOf(t)?(d=Gt.colorToRGBA(d),h=Gt.colorToRGBA(e),r={r:h.r-d.r,g:h.g-d.g,b:h.b-d.b,a:h.a-d.a}):r=e-d;Ci.attrs[s][this._id][t]={start:d,diff:r,end:e,trueEnd:a,trueStart:o},Ci.tweens[s][t]=this._id}_tweenFunc(t){const e=this.node,i=Ci.attrs[e._id][this._id];let s,r,n,a,o,h,l,d;for(s in i){if(r=i[s],n=r.start,a=r.diff,d=r.end,Gt._isArray(n))if(o=[],l=Math.max(n.length,d.length),0===s.indexOf("fill"))for(h=0;h<l;h++)h%2==0?o.push((n[h]||0)+a[h]*t):o.push("rgba("+Math.round(n[h].r+a[h].r*t)+","+Math.round(n[h].g+a[h].g*t)+","+Math.round(n[h].b+a[h].b*t)+","+(n[h].a+a[h].a*t)+")");else for(h=0;h<l;h++)o.push((n[h]||0)+a[h]*t);else o=-1!==xi.indexOf(s)?"rgba("+Math.round(n.r+a.r*t)+","+Math.round(n.g+a.g*t)+","+Math.round(n.b+a.b*t)+","+(n.a+a.a*t)+")":n+a*t;e.setAttr(s,o)}}_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=Ci.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=Ci.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=Ci.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const e in i)delete Ci.tweens[t][e];delete Ci.attrs[t][e],Ci.tweens[t]&&(0===Object.keys(Ci.tweens[t]).length&&delete Ci.tweens[t],0===Object.keys(Ci.attrs[t]).length&&delete Ci.attrs[t])}}Ci.attrs={},Ci.tweens={},xe.prototype.to=function(t){const e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()};new Ci(t).play()};const Ai={BackEaseIn(t,e,i,s){const r=1.70158;return i*(t/=s)*t*((r+1)*t-r)+e},BackEaseOut(t,e,i,s){const r=1.70158;return i*((t=t/s-1)*t*((r+1)*t+r)+1)+e},BackEaseInOut(t,e,i,s){let r=1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(r*=1.525))*t-r))+e:i/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},ElasticEaseIn(t,e,i,s,r,n){let a=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,a=n/4):a=n/(2*Math.PI)*Math.asin(i/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*s-a)*(2*Math.PI)/n)+e)},ElasticEaseOut(t,e,i,s,r,n){let a=0;return 0===t?e:1===(t/=s)?e+i:(n||(n=.3*s),!r||r<Math.abs(i)?(r=i,a=n/4):a=n/(2*Math.PI)*Math.asin(i/r),r*Math.pow(2,-10*t)*Math.sin((t*s-a)*(2*Math.PI)/n)+i+e)},ElasticEaseInOut(t,e,i,s,r,n){let a=0;return 0===t?e:2==(t/=s/2)?e+i:(n||(n=s*(.3*1.5)),!r||r<Math.abs(i)?(r=i,a=n/4):a=n/(2*Math.PI)*Math.asin(i/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*s-a)*(2*Math.PI)/n)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*s-a)*(2*Math.PI)/n)*.5+i+e)},BounceEaseOut:(t,e,i,s)=>(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e,BounceEaseIn:(t,e,i,s)=>i-Ai.BounceEaseOut(s-t,0,i,s)+e,BounceEaseInOut:(t,e,i,s)=>t<s/2?.5*Ai.BounceEaseIn(2*t,0,i,s)+e:.5*Ai.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},Ti=Gt._assign(At,{Util:Gt,Transform:Pt,Node:xe,Container:Se,Stage:si,stages:ii,Layer:mi,FastLayer:fi,Group:_i,DD:qt,Shape:ui,shapes:ci,Animation:yi,Tween:Ci,Easings:Ai,Context:jt,Canvas:Xt});class ki extends ui{_sceneFunc(t){const e=At.getAngle(this.angle()),i=this.clockwise();t.beginPath(),t.arc(0,0,this.outerRadius(),0,e,i),t.arc(0,0,this.innerRadius(),e,0,!i),t.closePath(),t.fillStrokeShape(this)}getWidth(){return 2*this.outerRadius()}getHeight(){return 2*this.outerRadius()}setWidth(t){this.outerRadius(t/2)}setHeight(t){this.outerRadius(t/2)}getSelfRect(){const t=this.innerRadius(),e=this.outerRadius(),i=this.clockwise(),s=At.getAngle(i?360-this.angle():this.angle()),r=Math.cos(Math.min(s,Math.PI)),n=Math.sin(Math.min(Math.max(Math.PI,s),3*Math.PI/2)),a=Math.sin(Math.min(s,Math.PI/2)),o=r*(r>0?t:e),h=n*(n>0?t:e),l=a*(a>0?e:t);return{x:o,y:i?-1*l:h,width:1*e-o,height:l-h}}}function Pi(t,e,i,s,r,n,a){const o=Math.sqrt(Math.pow(i-t,2)+Math.pow(s-e,2)),h=Math.sqrt(Math.pow(r-i,2)+Math.pow(n-s,2)),l=a*o/(o+h),d=a*h/(o+h);return[i-l*(r-t),s-l*(n-e),i+d*(r-t),s+d*(n-e)]}function Ei(t,e){const i=t.length,s=[];for(let r=2;r<i-2;r+=2){const i=Pi(t[r-2],t[r-1],t[r],t[r+1],t[r+2],t[r+3],e);isNaN(i[0])||(s.push(i[0]),s.push(i[1]),s.push(t[r]),s.push(t[r+1]),s.push(i[2]),s.push(i[3]))}return s}ki.prototype._centroid=!0,ki.prototype.className="Arc",ki.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],Tt(ki),ae.addGetterSetter(ki,"innerRadius",0,$t()),ae.addGetterSetter(ki,"outerRadius",0,$t()),ae.addGetterSetter(ki,"angle",0,$t()),ae.addGetterSetter(ki,"clockwise",!1,se());class Mi extends ui{constructor(t){super(t),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(t){const e=this.points(),i=e.length,s=this.tension(),r=this.closed(),n=this.bezier();if(!i)return;let a=0;if(t.beginPath(),t.moveTo(e[0],e[1]),0!==s&&i>4){const s=this.getTensionPoints(),n=s.length;for(a=r?0:4,r||t.quadraticCurveTo(s[0],s[1],s[2],s[3]);a<n-2;)t.bezierCurveTo(s[a++],s[a++],s[a++],s[a++],s[a++],s[a++]);r||t.quadraticCurveTo(s[n-2],s[n-1],e[i-2],e[i-1])}else if(n)for(a=2;a<i;)t.bezierCurveTo(e[a++],e[a++],e[a++],e[a++],e[a++],e[a++]);else for(a=2;a<i;a+=2)t.lineTo(e[a],e[a+1]);r?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():Ei(this.points(),this.tension())}_getTensionPointsClosed(){const t=this.points(),e=t.length,i=this.tension(),s=Pi(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),r=Pi(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),n=Ei(t,i);return[s[2],s[3]].concat(n).concat([r[0],r[1],t[e-2],t[e-1],r[2],r[3],s[0],s[1],t[0],t[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let t=this.points();if(t.length<4)return{x:t[0]||0,y:t[1]||0,width:0,height:0};t=0!==this.tension()?[t[0],t[1],...this._getTensionPoints(),t[t.length-2],t[t.length-1]]:this.points();let e,i,s=t[0],r=t[0],n=t[1],a=t[1];for(let o=0;o<t.length/2;o++)e=t[2*o],i=t[2*o+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),a=Math.max(a,i);return{x:s,y:n,width:r-s,height:a-n}}}Mi.prototype.className="Line",Mi.prototype._attrsAffectingSize=["points","bezier","tension"],Tt(Mi),ae.addGetterSetter(Mi,"closed",!1),ae.addGetterSetter(Mi,"bezier",!1),ae.addGetterSetter(Mi,"tension",0,$t()),ae.addGetterSetter(Mi,"points",[],function(){if(At.isUnminified)return function(t,e){const i=Int8Array?Object.getPrototypeOf(Int8Array):null;return i&&t instanceof i||(Gt._isArray(t)?t.forEach(function(t){Gt._isNumber(t)||Gt.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")}):Gt.warn(Kt(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),t}}());const Ii=[[],[],[-.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]],Ri=[[],[],[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]],Di=[[1],[1,1],[1,2,1],[1,3,3,1]],Li=(t,e,i)=>{let s,r;const n=i/2;s=0;for(let i=0;i<20;i++)r=n*Ii[20][i]+n,s+=Ri[20][i]*zi(t,e,r);return n*s},Oi=(t,e,i)=>{void 0===i&&(i=1);const s=t[0]-2*t[1]+t[2],r=e[0]-2*e[1]+e[2],n=2*t[1]-2*t[0],a=2*e[1]-2*e[0],o=4*(s*s+r*r),h=4*(s*n+r*a),l=n*n+a*a;if(0===o)return i*Math.sqrt(Math.pow(t[2]-t[0],2)+Math.pow(e[2]-e[0],2));const d=h/(2*o),c=i+d,u=l/o-d*d,g=c*c+u>0?Math.sqrt(c*c+u):0,p=d*d+u>0?Math.sqrt(d*d+u):0,m=d+Math.sqrt(d*d+u)!==0?u*Math.log(Math.abs((c+g)/(d+p))):0;return Math.sqrt(o)/2*(c*g-d*p+m)};function zi(t,e,i){const s=Fi(1,i,t),r=Fi(1,i,e),n=s*s+r*r;return Math.sqrt(n)}const Fi=(t,e,i)=>{const s=i.length-1;let r,n;if(0===s)return 0;if(0===t){n=0;for(let t=0;t<=s;t++)n+=Di[s][t]*Math.pow(1-e,s-t)*Math.pow(e,t)*i[t];return n}r=new Array(s);for(let t=0;t<s;t++)r[t]=s*(i[t+1]-i[t]);return Fi(t-1,e,r)},Gi=(t,e,i)=>{let s=1,r=t/e,n=(t-i(r))/e,a=0;for(;s>.001;){const o=i(r+n),h=Math.abs(t-o)/e;if(h<s)s=h,r+=n;else{const a=i(r-n),o=Math.abs(t-a)/e;o<s?(s=o,r-=n):n/=2}if(a++,a>500)break}return r};class Vi extends ui{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=Vi.parsePathData(this.data()),this.pathLength=Vi.getPathLength(this.dataArray)}_sceneFunc(t){const e=this.dataArray;t.beginPath();let i=!1;for(let s=0;s<e.length;s++){const r=e[s].command,n=e[s].points;switch(r){case"L":t.lineTo(n[0],n[1]);break;case"M":t.moveTo(n[0],n[1]);break;case"C":t.bezierCurveTo(n[0],n[1],n[2],n[3],n[4],n[5]);break;case"Q":t.quadraticCurveTo(n[0],n[1],n[2],n[3]);break;case"A":const e=n[0],s=n[1],r=n[2],a=n[3],o=n[4],h=n[5],l=n[6],d=n[7],c=r>a?r:a,u=r>a?1:r/a,g=r>a?a/r:1;t.translate(e,s),t.rotate(l),t.scale(u,g),t.arc(0,0,c,o,o+h,1-d),t.scale(1/u,1/g),t.rotate(-l),t.translate(-e,-s);break;case"z":i=!0,t.closePath()}}i||this.hasFill()?t.fillStrokeShape(this):t.strokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(e){if("A"===e.command){const i=e.points[4],s=e.points[5],r=e.points[4]+s;let n=Math.PI/180;if(Math.abs(i-r)<n&&(n=Math.abs(i-r)),s<0)for(let s=i-n;s>r;s-=n){const i=Vi.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}else for(let s=i+n;s<r;s+=n){const i=Vi.getPointOnEllipticalArc(e.points[0],e.points[1],e.points[2],e.points[3],s,0);t.push(i.x,i.y)}}else if("C"===e.command)for(let i=0;i<=1;i+=.01){const s=Vi.getPointOnCubicBezier(i,e.start.x,e.start.y,e.points[0],e.points[1],e.points[2],e.points[3],e.points[4],e.points[5]);t.push(s.x,s.y)}else t=t.concat(e.points)});let e,i,s=t[0],r=t[0],n=t[1],a=t[1];for(let o=0;o<t.length/2;o++)e=t[2*o],i=t[2*o+1],isNaN(e)||(s=Math.min(s,e),r=Math.max(r,e)),isNaN(i)||(n=Math.min(n,i),a=Math.max(a,i));return{x:s,y:n,width:r-s,height:a-n}}getLength(){return this.pathLength}getPointAtLength(t){return Vi.getPointAtLengthOfDataArray(t,this.dataArray)}static getLineLength(t,e,i,s){return Math.sqrt((i-t)*(i-t)+(s-e)*(s-e))}static getPathLength(t){let e=0;for(let i=0;i<t.length;++i)e+=t[i].pathLength;return e}static getPointAtLengthOfDataArray(t,e){let i,s=0,r=e.length;if(!r)return null;for(;s<r&&t>e[s].pathLength;)t-=e[s].pathLength,++s;if(s===r)return i=e[s-1].points.slice(-2),{x:i[0],y:i[1]};if(t<.01){return"M"===e[s].command?(i=e[s].points.slice(0,2),{x:i[0],y:i[1]}):{x:e[s].start.x,y:e[s].start.y}}const n=e[s],a=n.points;switch(n.command){case"L":return Vi.getPointOnLine(t,n.start.x,n.start.y,a[0],a[1]);case"C":return Vi.getPointOnCubicBezier(Gi(t,Vi.getPathLength(e),t=>Li([n.start.x,a[0],a[2],a[4]],[n.start.y,a[1],a[3],a[5]],t)),n.start.x,n.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return Vi.getPointOnQuadraticBezier(Gi(t,Vi.getPathLength(e),t=>Oi([n.start.x,a[0],a[2]],[n.start.y,a[1],a[3]],t)),n.start.x,n.start.y,a[0],a[1],a[2],a[3]);case"A":const i=a[0],s=a[1],r=a[2],o=a[3],h=a[5],l=a[6];let d=a[4];return d+=h*t/n.pathLength,Vi.getPointOnEllipticalArc(i,s,r,o,d,l)}return null}static getPointOnLine(t,e,i,s,r,n,a){n=null!=n?n:e,a=null!=a?a:i;const o=this.getLineLength(e,i,s,r);if(o<1e-10)return{x:e,y:i};if(s===e)return{x:n,y:a+(r>i?t:-t)};const h=(r-i)/(s-e),l=Math.sqrt(t*t/(1+h*h))*(s<e?-1:1),d=h*l;if(Math.abs(a-i-h*(n-e))<1e-10)return{x:n+l,y:a+d};const c=((n-e)*(s-e)+(a-i)*(r-i))/(o*o),u=e+c*(s-e),g=i+c*(r-i),p=this.getLineLength(n,a,u,g),m=Math.sqrt(t*t-p*p),f=Math.sqrt(m*m/(1+h*h))*(s<e?-1:1);return{x:u+f,y:g+h*f}}static getPointOnCubicBezier(t,e,i,s,r,n,a,o,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 u(t){return(1-t)*(1-t)*(1-t)}return{x:o*l(t)+n*d(t)+s*c(t)+e*u(t),y:h*l(t)+a*d(t)+r*c(t)+i*u(t)}}static getPointOnQuadraticBezier(t,e,i,s,r,n,a){function o(t){return t*t}function h(t){return 2*t*(1-t)}function l(t){return(1-t)*(1-t)}return{x:n*o(t)+s*h(t)+e*l(t),y:a*o(t)+r*h(t)+i*l(t)}}static getPointOnEllipticalArc(t,e,i,s,r,n){const a=Math.cos(n),o=Math.sin(n),h=i*Math.cos(r),l=s*Math.sin(r);return{x:t+(h*a-l*o),y:e+(h*o+l*a)}}static parsePathData(t){if(!t)return[];let e=t;const i=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];e=e.replace(new RegExp(" ","g"),",");for(let t=0;t<i.length;t++)e=e.replace(new RegExp(i[t],"g"),"|"+i[t]);const s=e.split("|"),r=[],n=[];let a=0,o=0;const h=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let l;for(let t=1;t<s.length;t++){let e=s[t],i=e.charAt(0);for(e=e.slice(1),n.length=0;l=h.exec(e);)n.push(l[0]);let d=[],c="A"===i||"a"===i?0:-1;for(let t=0,e=n.length;t<e;t++){const e=n[t];if("00"!==e)if(c>=0){if(3===c){if(/^[01]{2}\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),d.push(parseFloat(e.slice(2))),c+=3,c>=7&&(c-=7);continue}if("11"===e||"10"===e||"01"===e){d.push(parseInt(e[0],10)),d.push(parseInt(e[1],10)),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}else if(4===c){if(/^[01]\d+(?:\.\d+)?$/.test(e)){d.push(parseInt(e[0],10)),d.push(parseFloat(e.slice(1))),c+=2,c>=7&&(c-=7);continue}if("0"===e||"1"===e){d.push(parseInt(e,10)),c+=1,c>=7&&(c-=7);continue}}const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t),c+=1,c>=7&&(c-=7)}else{const t=parseFloat(e);isNaN(t)?d.push(0):d.push(t)}else d.push(0,0),c>=0&&(c+=2,c>=7&&(c-=7))}for(;d.length>0&&!isNaN(d[0]);){let t="",e=[];const s=a,n=o;let h,l,c,u,g,p,m,f,_,v;switch(i){case"l":a+=d.shift(),o+=d.shift(),t="L",e.push(a,o);break;case"L":a=d.shift(),o=d.shift(),e.push(a,o);break;case"m":const s=d.shift(),n=d.shift();if(a+=s,o+=n,t="M",r.length>2&&"z"===r[r.length-1].command)for(let t=r.length-2;t>=0;t--)if("M"===r[t].command){a=r[t].points[0]+s,o=r[t].points[1]+n;break}e.push(a,o),i="l";break;case"M":a=d.shift(),o=d.shift(),t="M",e.push(a,o),i="L";break;case"h":a+=d.shift(),t="L",e.push(a,o);break;case"H":a=d.shift(),t="L",e.push(a,o);break;case"v":o+=d.shift(),t="L",e.push(a,o);break;case"V":o=d.shift(),t="L",e.push(a,o);break;case"C":e.push(d.shift(),d.shift(),d.shift(),d.shift()),a=d.shift(),o=d.shift(),e.push(a,o);break;case"c":e.push(a+d.shift(),o+d.shift(),a+d.shift(),o+d.shift()),a+=d.shift(),o+=d.shift(),t="C",e.push(a,o);break;case"S":l=a,c=o,h=r[r.length-1],"C"===h.command&&(l=a+(a-h.points[2]),c=o+(o-h.points[3])),e.push(l,c,d.shift(),d.shift()),a=d.shift(),o=d.shift(),t="C",e.push(a,o);break;case"s":l=a,c=o,h=r[r.length-1],"C"===h.command&&(l=a+(a-h.points[2]),c=o+(o-h.points[3])),e.push(l,c,a+d.shift(),o+d.shift()),a+=d.shift(),o+=d.shift(),t="C",e.push(a,o);break;case"Q":e.push(d.shift(),d.shift()),a=d.shift(),o=d.shift(),e.push(a,o);break;case"q":e.push(a+d.shift(),o+d.shift()),a+=d.shift(),o+=d.shift(),t="Q",e.push(a,o);break;case"T":l=a,c=o,h=r[r.length-1],"Q"===h.command&&(l=a+(a-h.points[0]),c=o+(o-h.points[1])),a=d.shift(),o=d.shift(),t="Q",e.push(l,c,a,o);break;case"t":l=a,c=o,h=r[r.length-1],"Q"===h.command&&(l=a+(a-h.points[0]),c=o+(o-h.points[1])),a+=d.shift(),o+=d.shift(),t="Q",e.push(l,c,a,o);break;case"A":u=d.shift(),g=d.shift(),p=d.shift(),m=d.shift(),f=d.shift(),_=a,v=o,a=d.shift(),o=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(_,v,a,o,m,f,u,g,p);break;case"a":u=d.shift(),g=d.shift(),p=d.shift(),m=d.shift(),f=d.shift(),_=a,v=o,a+=d.shift(),o+=d.shift(),t="A",e=this.convertEndpointToCenterParameterization(_,v,a,o,m,f,u,g,p)}r.push({command:t||i,points:e,start:{x:s,y:n},pathLength:this.calcLength(s,n,t||i,e)})}"z"!==i&&"Z"!==i||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r}static calcLength(t,e,i,s){let r,n,a,o;const h=Vi;switch(i){case"L":return h.getLineLength(t,e,s[0],s[1]);case"C":return Li([t,s[0],s[2],s[4]],[e,s[1],s[3],s[5]],1);case"Q":return Oi([t,s[0],s[2]],[e,s[1],s[3]],1);case"A":r=0;const i=s[4],l=s[5],d=s[4]+l;let c=Math.PI/180;if(Math.abs(i-d)<c&&(c=Math.abs(i-d)),n=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],i,0),l<0)for(o=i-c;o>d;o-=c)a=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],o,0),r+=h.getLineLength(n.x,n.y,a.x,a.y),n=a;else for(o=i+c;o<d;o+=c)a=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],o,0),r+=h.getLineLength(n.x,n.y,a.x,a.y),n=a;return a=h.getPointOnEllipticalArc(s[0],s[1],s[2],s[3],d,0),r+=h.getLineLength(n.x,n.y,a.x,a.y),r}return 0}static convertEndpointToCenterParameterization(t,e,i,s,r,n,a,o,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,u=d*d/(a*a)+c*c/(o*o);u>1&&(a*=Math.sqrt(u),o*=Math.sqrt(u));let g=Math.sqrt((a*a*(o*o)-a*a*(c*c)-o*o*(d*d))/(a*a*(c*c)+o*o*(d*d)));r===n&&(g*=-1),isNaN(g)&&(g=0);const p=g*a*c/o,m=g*-o*d/a,f=(t+i)/2+Math.cos(l)*p-Math.sin(l)*m,_=(e+s)/2+Math.sin(l)*p+Math.cos(l)*m,v=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},y=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(v(t)*v(e))},w=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(y(t,e))},x=w([1,0],[(d-p)/a,(c-m)/o]),b=[(d-p)/a,(c-m)/o],S=[(-1*d-p)/a,(-1*c-m)/o];let C=w(b,S);return y(b,S)<=-1&&(C=Math.PI),y(b,S)>=1&&(C=0),0===n&&C>0&&(C-=2*Math.PI),1===n&&C<0&&(C+=2*Math.PI),[f,_,a,o,x,C,l,n]}}Vi.prototype.className="Path",Vi.prototype._attrsAffectingSize=["data"],Tt(Vi),ae.addGetterSetter(Vi,"data");class Wi extends Mi{_sceneFunc(t){super._sceneFunc(t);const e=2*Math.PI,i=this.points();let s=i;const r=0!==this.tension()&&i.length>4;r&&(s=this.getTensionPoints());const n=this.pointerLength(),a=i.length;let o,h;if(r){const t=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1],i[a-2],i[a-1]],e=Vi.calcLength(s[s.length-4],s[s.length-3],"C",t),r=Vi.getPointOnQuadraticBezier(Math.min(1,1-n/e),t[0],t[1],t[2],t[3],t[4],t[5]);o=i[a-2]-r.x,h=i[a-1]-r.y}else o=i[a-2]-i[a-4],h=i[a-1]-i[a-3];const l=(Math.atan2(h,o)+e)%e,d=this.pointerWidth();this.pointerAtEnding()&&(t.save(),t.beginPath(),t.translate(i[a-2],i[a-1]),t.rotate(l),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/2),t.closePath(),t.restore(),this.__fillStroke(t)),this.pointerAtBeginning()&&(t.save(),t.beginPath(),t.translate(i[0],i[1]),r?(o=(s[0]+s[2])/2-i[0],h=(s[1]+s[3])/2-i[1]):(o=i[2]-i[0],h=i[3]-i[1]),t.rotate((Math.atan2(-h,-o)+e)%e),t.moveTo(0,0),t.lineTo(-n,d/2),t.lineTo(-n,-d/2),t.closePath(),t.restore(),this.__fillStroke(t))}__fillStroke(t){const e=this.dashEnabled();e&&(this.attrs.dashEnabled=!1,t.setLineDash([])),t.fillStrokeShape(this),e&&(this.attrs.dashEnabled=!0)}getSelfRect(){const t=super.getSelfRect(),e=this.pointerWidth()/2;return{x:t.x,y:t.y-e,width:t.width,height:t.height+2*e}}}Wi.prototype.className="Arrow",Tt(Wi),ae.addGetterSetter(Wi,"pointerLength",10,$t()),ae.addGetterSetter(Wi,"pointerWidth",10,$t()),ae.addGetterSetter(Wi,"pointerAtBeginning",!1),ae.addGetterSetter(Wi,"pointerAtEnding",!0);class Bi extends ui{_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)}}Bi.prototype._centroid=!0,Bi.prototype.className="Circle",Bi.prototype._attrsAffectingSize=["radius"],Tt(Bi),ae.addGetterSetter(Bi,"radius",0,$t());class Ni extends ui{_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)}}Ni.prototype.className="Ellipse",Ni.prototype._centroid=!0,Ni.prototype._attrsAffectingSize=["radiusX","radiusY"],Tt(Ni),ae.addComponentsGetterSetter(Ni,"radius",["x","y"]),ae.addGetterSetter(Ni,"radiusX",0,$t()),ae.addGetterSetter(Ni,"radiusY",0,$t());let ji=class t extends ui{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",t=>{this._removeImageLoad(t.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&4===t.readyState||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){const t=!!this.cornerRadius(),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas(!0)}_sceneFunc(t){const e=this.getWidth(),i=this.getHeight(),s=this.cornerRadius(),r=this.attrs.image;let n;if(r){const t=this.attrs.cropWidth,s=this.attrs.cropHeight;n=t&&s?[r,this.cropX(),this.cropY(),t,s,0,0,e,i]:[r,0,0,e,i]}(this.hasFill()||this.hasStroke()||s)&&(t.beginPath(),s?Gt.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)),r&&(s&&t.clip(),t.drawImage.apply(t,n))}_hitFunc(t){const e=this.width(),i=this.height(),s=this.cornerRadius();t.beginPath(),s?Gt.drawRoundedRectPath(t,e,i,s):t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,e,i;return null!==(i=null!==(t=this.attrs.width)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.width)&&void 0!==i?i:0}getHeight(){var t,e,i;return null!==(i=null!==(t=this.attrs.height)&&void 0!==t?t:null===(e=this.image())||void 0===e?void 0:e.height)&&void 0!==i?i:0}static fromURL(e,i,s=null){const r=Gt.createImageElement();r.onload=function(){const e=new t({image:r});i(e)},r.onerror=s,r.crossOrigin="Anonymous",r.src=e}};ji.prototype.className="Image",ji.prototype._attrsAffectingSize=["image"],Tt(ji),ae.addGetterSetter(ji,"cornerRadius",0,Qt(4)),ae.addGetterSetter(ji,"image"),ae.addComponentsGetterSetter(ji,"crop",["x","y","width","height"]),ae.addGetterSetter(ji,"cropX",0,$t()),ae.addGetterSetter(ji,"cropY",0,$t()),ae.addGetterSetter(ji,"cropWidth",0,$t()),ae.addGetterSetter(ji,"cropHeight",0,$t());const Hi=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],Ui="up",Xi="right",Yi="down",Ji="left",qi=Hi.length;class Ki extends _i{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<qi;e++)t.on(Hi[e]+"Change.konva",s)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let t,e,i,s,r,n,a,o=this.getText(),h=this.getTag();if(o&&h){switch(t=o.width(),e=o.height(),i=h.pointerDirection(),s=h.pointerWidth(),a=h.pointerHeight(),r=0,n=0,i){case Ui:r=t/2,n=-1*a;break;case Xi:r=t+s,n=e/2;break;case Yi:r=t/2,n=e+a;break;case Ji:r=-1*s,n=e/2}h.setAttrs({x:-1*r,y:-1*n,width:t,height:e}),o.setAttrs({x:-1*r,y:-1*n})}}}Ki.prototype.className="Label",Tt(Ki);class Zi extends ui{_sceneFunc(t){const e=this.width(),i=this.height(),s=this.pointerDirection(),r=this.pointerWidth(),n=this.pointerHeight(),a=this.cornerRadius();let o=0,h=0,l=0,d=0;"number"==typeof a?o=h=l=d=Math.min(a,e/2,i/2):(o=Math.min(a[0]||0,e/2,i/2),h=Math.min(a[1]||0,e/2,i/2),d=Math.min(a[2]||0,e/2,i/2),l=Math.min(a[3]||0,e/2,i/2)),t.beginPath(),t.moveTo(o,0),s===Ui&&(t.lineTo((e-r)/2,0),t.lineTo(e/2,-1*n),t.lineTo((e+r)/2,0)),t.lineTo(e-h,0),t.arc(e-h,h,h,3*Math.PI/2,0,!1),s===Xi&&(t.lineTo(e,(i-n)/2),t.lineTo(e+r,i/2),t.lineTo(e,(i+n)/2)),t.lineTo(e,i-d),t.arc(e-d,i-d,d,0,Math.PI/2,!1),s===Yi&&(t.lineTo((e+r)/2,i),t.lineTo(e/2,i+n),t.lineTo((e-r)/2,i)),t.lineTo(l,i),t.arc(l,i-l,l,Math.PI/2,Math.PI,!1),s===Ji&&(t.lineTo(0,(i+n)/2),t.lineTo(-1*r,i/2),t.lineTo(0,(i-n)/2)),t.lineTo(0,o),t.arc(o,o,o,Math.PI,3*Math.PI/2,!1),t.closePath(),t.fillStrokeShape(this)}getSelfRect(){let t=0,e=0,i=this.pointerWidth(),s=this.pointerHeight(),r=this.pointerDirection(),n=this.width(),a=this.height();return r===Ui?(e-=s,a+=s):r===Yi?a+=s:r===Ji?(t-=1.5*i,n+=i):r===Xi&&(n+=1.5*i),{x:t,y:e,width:n,height:a}}}Zi.prototype.className="Tag",Tt(Zi),ae.addGetterSetter(Zi,"pointerDirection","none"),ae.addGetterSetter(Zi,"pointerWidth",0,$t()),ae.addGetterSetter(Zi,"pointerHeight",0,$t()),ae.addGetterSetter(Zi,"cornerRadius",0,Qt(4));class $i extends ui{_sceneFunc(t){const e=this.cornerRadius(),i=this.width(),s=this.height();t.beginPath(),e?Gt.drawRoundedRectPath(t,i,s,e):t.rect(0,0,i,s),t.closePath(),t.fillStrokeShape(this)}}$i.prototype.className="Rect",Tt($i),ae.addGetterSetter($i,"cornerRadius",0,Qt(4));class Qi extends ui{_sceneFunc(t){const e=this._getPoints(),i=this.radius(),s=this.sides(),r=this.cornerRadius();if(t.beginPath(),r)Gt.drawRoundedPolygonPath(t,e,s,i,r);else{t.moveTo(e[0].x,e[0].y);for(let i=1;i<e.length;i++)t.lineTo(e[i].x,e[i].y)}t.closePath(),t.fillStrokeShape(this)}_getPoints(){const t=this.attrs.sides,e=this.attrs.radius||0,i=[];for(let s=0;s<t;s++)i.push({x:e*Math.sin(2*s*Math.PI/t),y:-1*e*Math.cos(2*s*Math.PI/t)});return i}getSelfRect(){const t=this._getPoints();let e=t[0].x,i=t[0].x,s=t[0].y,r=t[0].y;return t.forEach(t=>{e=Math.min(e,t.x),i=Math.max(i,t.x),s=Math.min(s,t.y),r=Math.max(r,t.y)}),{x:e,y:s,width:i-e,height:r-s}}getWidth(){return 2*this.radius()}getHeight(){return 2*this.radius()}setWidth(t){this.radius(t/2)}setHeight(t){this.radius(t/2)}}Qi.prototype.className="RegularPolygon",Qi.prototype._centroid=!0,Qi.prototype._attrsAffectingSize=["radius"],Tt(Qi),ae.addGetterSetter(Qi,"radius",0,$t()),ae.addGetterSetter(Qi,"sides",0,$t()),ae.addGetterSetter(Qi,"cornerRadius",0,Qt(4));const ts=2*Math.PI;class es extends ui{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.innerRadius(),0,ts,!1),t.moveTo(this.outerRadius(),0),t.arc(0,0,this.outerRadius(),ts,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)}}es.prototype.className="Ring",es.prototype._centroid=!0,es.prototype._attrsAffectingSize=["innerRadius","outerRadius"],Tt(es),ae.addGetterSetter(es,"innerRadius",0,$t()),ae.addGetterSetter(es,"outerRadius",0,$t());class is extends ui{constructor(t){super(t),this._updated=!0,this.anim=new yi(()=>{const t=this._updated;return this._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,r=this.animations()[e],n=this.frameOffsets(),a=r[s+0],o=r[s+1],h=r[s+2],l=r[s+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,l),t.closePath(),t.fillStrokeShape(this)),d)if(n){const s=n[e],r=2*i;t.drawImage(d,a,o,h,l,s[r+0],s[r+1],h,l)}else t.drawImage(d,a,o,h,l,0,0,h,l)}_hitFunc(t){const e=this.animation(),i=this.frameIndex(),s=4*i,r=this.animations()[e],n=this.frameOffsets(),a=r[s+2],o=r[s+3];if(t.beginPath(),n){const s=n[e],r=2*i;t.rect(s[r+0],s[r+1],a,o)}else t.rect(0,0,a,o);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)}}is.prototype.className="Sprite",Tt(is),ae.addGetterSetter(is,"animation"),ae.addGetterSetter(is,"animations"),ae.addGetterSetter(is,"frameOffsets"),ae.addGetterSetter(is,"image"),ae.addGetterSetter(is,"frameIndex",0,$t()),ae.addGetterSetter(is,"frameRate",17,$t()),ae.backCompat(is,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});class ss extends ui{_sceneFunc(t){const e=this.innerRadius(),i=this.outerRadius(),s=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(let r=1;r<2*s;r++){const n=r%2==0?i:e,a=n*Math.sin(r*Math.PI/s),o=-1*n*Math.cos(r*Math.PI/s);t.lineTo(a,o)}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 rs(t){return[...t].reduce((t,e,i,s)=>{if(/\p{Emoji}/u.test(e)){const r=s[i+1];r&&/\p{Emoji_Modifier}|\u200D/u.test(r)?(t.push(e+r),s[i+1]=""):t.push(e)}else/\p{Regional_Indicator}{2}/u.test(e+(s[i+1]||""))?t.push(e+s[i+1]):i>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(e)?t[t.length-1]+=e:e&&t.push(e);return t},[])}ss.prototype.className="Star",ss.prototype._centroid=!0,ss.prototype._attrsAffectingSize=["innerRadius","outerRadius"],Tt(ss),ae.addGetterSetter(ss,"numPoints",5,$t()),ae.addGetterSetter(ss,"innerRadius",0,$t()),ae.addGetterSetter(ss,"outerRadius",0,$t());const ns="auto",as="inherit",os="justify",hs="left",ls="middle",ds="normal",cs=" ",us="none",gs=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],ps=gs.length;let ms;function fs(){return ms||(ms=Gt.createCanvasElement().getContext("2d"),ms)}class _s extends ui{constructor(t){super(function(t){return(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||t.fillPatternImage||(t.fill=t.fill||"black"),t}(t)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<ps;t++)this.on(gs[t]+"Change.konva",this._setTextData);this._setTextData()}_sceneFunc(t){var e,i;const s=this.textArr,r=s.length;if(!this.text())return;let n,a=this.padding(),o=this.fontSize(),h=this.lineHeight()*o,l=this.verticalAlign(),d=this.direction(),c=0,u=this.align(),g=this.getWidth(),p=this.letterSpacing(),m=this.charRenderFunc(),f=this.fill(),_=this.textDecoration(),v=-1!==_.indexOf("underline"),y=-1!==_.indexOf("line-through");d=d===as?t.direction:d;let w=h/2,x=ls;if(!At.legacyTextRendering){const t=this.measureSize("M");x="alphabetic";w=((null!==(e=t.fontBoundingBoxAscent)&&void 0!==e?e:t.actualBoundingBoxAscent)-(null!==(i=t.fontBoundingBoxDescent)&&void 0!==i?i:t.actualBoundingBoxDescent))/2+h/2}for("rtl"===d&&t.setAttr("direction",d),t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",x),t.setAttr("textAlign",hs),l===ls?c=(this.getHeight()-r*h-2*a)/2:"bottom"===l&&(c=this.getHeight()-r*h-2*a),t.translate(a,c+a),n=0;n<r;n++){let e=0,i=0;const l=s[n],c=l.text,_=l.width,x=l.lastInParagraph;if(t.save(),"right"===u?e+=g-_-2*a:"center"===u&&(e+=(g-_-2*a)/2),v){t.save(),t.beginPath();const s=e,r=w+i+(At.legacyTextRendering?Math.round(o/2):Math.round(o/4));t.moveTo(s,r);const n=u!==os||x?_:g-2*a;t.lineTo(s+Math.round(n),r),t.lineWidth=o/15;const h=this._getLinearGradient();t.strokeStyle=h||f,t.stroke(),t.restore()}const b=e;if("rtl"===d||0===p&&u!==os&&!m)0!==p&&t.setAttr("letterSpacing",`${p}px`),this._partialTextX=e,this._partialTextY=w+i,this._partialText=c,t.fillStrokeShape(this);else{const r=c.split(" ").length-1,o=rs(c);for(let h=0;h<o.length;h++){const l=o[h];if(" "!==l||x||u!==os||(e+=(g-2*a-_)/r),this._partialTextX=e,this._partialTextY=w+i,this._partialText=l,m){t.save();m({char:l,index:h+s.slice(0,n).reduce((t,e)=>t+rs(e.text).length,0),x:e,y:w+i,lineIndex:n,column:h,isLastInLine:x,width:this.measureSize(l).width,context:t})}t.fillStrokeShape(this),m&&t.restore(),e+=this.measureSize(l).width+p}}if(y){t.save(),t.beginPath();const e=At.legacyTextRendering?0:-Math.round(o/4),s=b;t.moveTo(s,w+i+e);const r=u!==os||x?_:g-2*a;t.lineTo(s+Math.round(r),w+i+e),t.lineWidth=o/15;const n=this._getLinearGradient();t.strokeStyle=n||f,t.stroke(),t.restore()}t.restore(),r>1&&(w+=h)}}_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=Gt._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this}getWidth(){return this.attrs.width===ns||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}getHeight(){return this.attrs.height===ns||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return Gt.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(t){var e,i,s,r,n,a,o,h,l,d,c;let u,g=fs(),p=this.fontSize();g.save(),g.font=this._getContextFont(),u=g.measureText(t),g.restore();const m=p/100;return{actualBoundingBoxAscent:null!==(e=u.actualBoundingBoxAscent)&&void 0!==e?e:71.58203125*m,actualBoundingBoxDescent:null!==(i=u.actualBoundingBoxDescent)&&void 0!==i?i:0,actualBoundingBoxLeft:null!==(s=u.actualBoundingBoxLeft)&&void 0!==s?s:-7.421875*m,actualBoundingBoxRight:null!==(r=u.actualBoundingBoxRight)&&void 0!==r?r:75.732421875*m,alphabeticBaseline:null!==(n=u.alphabeticBaseline)&&void 0!==n?n:0,emHeightAscent:null!==(a=u.emHeightAscent)&&void 0!==a?a:100*m,emHeightDescent:null!==(o=u.emHeightDescent)&&void 0!==o?o:-20*m,fontBoundingBoxAscent:null!==(h=u.fontBoundingBoxAscent)&&void 0!==h?h:91*m,fontBoundingBoxDescent:null!==(l=u.fontBoundingBoxDescent)&&void 0!==l?l:21*m,hangingBaseline:null!==(d=u.hangingBaseline)&&void 0!==d?d:72.80000305175781*m,ideographicBaseline:null!==(c=u.ideographicBaseline)&&void 0!==c?c:-21*m,width:u.width,height:p}}_getContextFont(){return this.fontStyle()+cs+this.fontVariant()+cs+(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()===os&&(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 fs().measureText(t).width+e*i}_setTextData(){let t=this.text().split("\n"),e=+this.fontSize(),i=0,s=this.lineHeight()*e,r=this.attrs.width,n=this.attrs.height,a=r!==ns&&void 0!==r,o=n!==ns&&void 0!==n,h=this.padding(),l=r-2*h,d=n-2*h,c=0,u=this.wrap(),g="char"!==u&&u!==us,p=this.ellipsis();this.textArr=[],fs().font=this._getContextFont();const m=p?this._getTextWidth("…"):0;for(let e=0,r=t.length;e<r;++e){let n=t[e],h=this._getTextWidth(n);if(a&&h>l)for(;n.length>0;){let t=0,e=rs(n).length,r="",a=0;for(;t<e;){const i=t+e>>>1,h=rs(n).slice(0,i+1).join(""),u=this._getTextWidth(h);(p&&o&&c+s>d?u+m:u)<=l?(t=i+1,r=h,a=u):e=i}if(!r)break;if(g){const e=rs(n),i=rs(r),s=e[i.length];let o;if((s===cs||"-"===s)&&a<=l)o=i.length;else{const t=i.lastIndexOf(cs),e=i.lastIndexOf("-");o=Math.max(t,e)+1}o>0&&(t=o,r=e.slice(0,t).join(""),a=this._getTextWidth(r))}r=r.trimRight(),this._addTextLine(r),i=Math.max(i,a),c+=s;if(this._shouldHandleEllipsis(c)){this._tryToAddEllipsisToLastLine();break}if(n=rs(n).slice(t).join("").trimLeft(),n.length>0&&(h=this._getTextWidth(n),h<=l)){this._addTextLine(n),c+=s,i=Math.max(i,h);break}}else this._addTextLine(n),c+=s,i=Math.max(i,h),this._shouldHandleEllipsis(c)&&e<r-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),o&&c+s>d)break}this.textHeight=e,this.textWidth=i}_shouldHandleEllipsis(t){const e=+this.fontSize(),i=this.lineHeight()*e,s=this.attrs.height,r=s!==ns&&void 0!==s,n=s-2*this.padding();return!(this.wrap()!==us)||r&&t+i>n}_tryToAddEllipsisToLastLine(){const t=this.attrs.width,e=t!==ns&&void 0!==t,i=t-2*this.padding(),s=this.ellipsis(),r=this.textArr[this.textArr.length-1];if(r&&s){if(e){this._getTextWidth(r.text+"…")<i||(r.text=r.text.slice(0,r.text.length-3))}this.textArr.splice(this.textArr.length-1,1),this._addTextLine(r.text+"…")}}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const t=-1!==this.textDecoration().indexOf("underline")||-1!==this.textDecoration().indexOf("line-through"),e=this.hasShadow();return!(!t||!e)||super._useBufferCanvas()}}_s.prototype._fillFunc=function(t){t.fillText(this._partialText,this._partialTextX,this._partialTextY)},_s.prototype._strokeFunc=function(t){t.setAttr("miterLimit",2),t.strokeText(this._partialText,this._partialTextX,this._partialTextY)},_s.prototype.className="Text",_s.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],Tt(_s),ae.overWriteSetter(_s,"width",te()),ae.overWriteSetter(_s,"height",te()),ae.addGetterSetter(_s,"direction",as),ae.addGetterSetter(_s,"fontFamily","Arial"),ae.addGetterSetter(_s,"fontSize",12,$t()),ae.addGetterSetter(_s,"fontStyle",ds),ae.addGetterSetter(_s,"fontVariant",ds),ae.addGetterSetter(_s,"padding",0,$t()),ae.addGetterSetter(_s,"align",hs),ae.addGetterSetter(_s,"verticalAlign","top"),ae.addGetterSetter(_s,"lineHeight",1,$t()),ae.addGetterSetter(_s,"wrap","word"),ae.addGetterSetter(_s,"ellipsis",!1,se()),ae.addGetterSetter(_s,"letterSpacing",0,$t()),ae.addGetterSetter(_s,"text","",ee()),ae.addGetterSetter(_s,"textDecoration",""),ae.addGetterSetter(_s,"charRenderFunc",void 0);const vs="normal";function ys(t){t.fillText(this.partialText,0,0)}function ws(t){t.strokeText(this.partialText,0,0)}class xs extends ui{constructor(t){super(t),this.dummyCanvas=Gt.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 Vi.getPathLength(this.dataArray)}_getPointAtLength(t){if(!this.attrs.data)return null;return t>this.pathLength?null:Vi.getPointAtLengthOfDataArray(t,this.dataArray)}_readDataAttribute(){this.dataArray=Vi.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.textBaseline()),t.setAttr("textAlign","left"),t.save();const e=this.textDecoration(),i=this.fill(),s=this.fontSize(),r=this.glyphInfo,n=-1!==e.indexOf("underline"),a=-1!==e.indexOf("line-through");n&&t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),this.partialText=r[e].text,t.fillStrokeShape(this),n&&(0===e&&t.moveTo(0,s/2+1),t.lineTo(r[e].width,s/2+1)),t.restore()}if(n&&(t.strokeStyle=i,t.lineWidth=s/20,t.stroke()),a){t.beginPath();for(let e=0;e<r.length;e++){t.save();const i=r[e].p0;t.translate(i.x,i.y),t.rotate(r[e].rotation),0===e&&t.moveTo(0,0),t.lineTo(r[e].width,0),t.restore()}t.strokeStyle=i,t.lineWidth=s/20,t.stroke()}t.restore()}_hitFunc(t){t.beginPath();const e=this.glyphInfo;if(e.length>=1){const i=e[0].p0;t.moveTo(i.x,i.y)}for(let i=0;i<e.length;i++){const s=e[i].p1;t.lineTo(s.x,s.y)}t.setAttr("lineWidth",this.fontSize()),t.setAttr("strokeStyle",this.colorKey),t.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return Gt.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(t){return _s.prototype.setText.call(this,t)}_getContextFont(){return _s.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=rs(this.text()),e=[];let i=0;for(let s=0;s<t.length;s++)e.push({char:t[s],width:this._getTextSize(t[s]).width}),i+=e[s].width;const{height:s}=this._getTextSize(this.attrs.text);if(this.textWidth=i,this.textHeight=s,this.glyphInfo=[],!this.attrs.data)return null;const r=this.letterSpacing(),n=this.align(),a=this.kerningFunc(),o=Math.max(this.textWidth+((this.attrs.text||"").length-1)*r,0);let h=0;"center"===n&&(h=Math.max(0,this.pathLength/2-o/2)),"right"===n&&(h=Math.max(0,this.pathLength-o));let l=h;for(let i=0;i<e.length;i++){const s=this._getPointAtLength(l);if(!s)return;const h=e[i].char;let d=e[i].width+r;if(" "===h&&"justify"===n){const t=this.text().split(" ").length-1;d+=(this.pathLength-o)/t}const c=this._getPointAtLength(l+d);if(!c)return;const u=Vi.getLineLength(s.x,s.y,c.x,c.y);let g=0;if(a)try{g=a(e[i-1].char,h)*this.fontSize()}catch(t){g=0}s.x+=g,c.x+=g,this.textWidth+=g;const p=Vi.getPointOnLine(g+u/2,s.x,s.y,c.x,c.y),m=Math.atan2(c.y-s.y,c.x-s.x);this.glyphInfo.push({transposeX:p.x,transposeY:p.y,text:t[i],rotation:m,p0:s,p1:c,width:u}),l+=d}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const t=[];this.glyphInfo.forEach(function(e){t.push(e.p0.x),t.push(e.p0.y),t.push(e.p1.x),t.push(e.p1.y)});let e,i,s=t[0]||0,r=t[0]||0,n=t[1]||0,a=t[1]||0;for(let o=0;o<t.length/2;o++)e=t[2*o],i=t[2*o+1],s=Math.min(s,e),r=Math.max(r,e),n=Math.min(n,i),a=Math.max(a,i);const o=this.fontSize();return{x:s-o/2,y:n-o/2,width:r-s+o,height:a-n+o}}destroy(){return Gt.releaseCanvas(this.dummyCanvas),super.destroy()}}xs.prototype._fillFunc=ys,xs.prototype._strokeFunc=ws,xs.prototype._fillFuncHit=ys,xs.prototype._strokeFuncHit=ws,xs.prototype.className="TextPath",xs.prototype._attrsAffectingSize=["text","fontSize","data"],Tt(xs),ae.addGetterSetter(xs,"data"),ae.addGetterSetter(xs,"fontFamily","Arial"),ae.addGetterSetter(xs,"fontSize",12,$t()),ae.addGetterSetter(xs,"fontStyle",vs),ae.addGetterSetter(xs,"align","left"),ae.addGetterSetter(xs,"letterSpacing",0,$t()),ae.addGetterSetter(xs,"textBaseline","middle"),ae.addGetterSetter(xs,"fontVariant",vs),ae.addGetterSetter(xs,"text",""),ae.addGetterSetter(xs,"textDecoration",""),ae.addGetterSetter(xs,"kerningFunc",void 0);const bs="tr-konva",Ss=["resizeEnabledChange","rotateAnchorOffsetChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(t=>t+`.${bs}`).join(" "),Cs="nodesRect",As=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],Ts={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},ks="ontouchstart"in At._global;const Ps=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function Es(t,e,i){const s=i.x+(t.x-i.x)*Math.cos(e)-(t.y-i.y)*Math.sin(e),r=i.y+(t.x-i.x)*Math.sin(e)+(t.y-i.y)*Math.cos(e);return{...t,rotation:t.rotation+e,x:s,y:r}}function Ms(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 Es(t,e,i)}let Is=0;class Rs extends _i{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(Ss,this.update),this.getNode()&&this.update()}attachTo(t){return this.setNode(t),this}setNode(t){return Gt.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 bs+this._id}setNodes(t=[]){this._nodes&&this._nodes.length&&this.detach();const e=t.filter(t=>!t.isAncestorOf(this)||(Gt.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(As.map(t=>t+`.${this._getEventNamespace()}`).join(" "),e),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,e),this._proxyDrag(t)}),this._resetTransformCache();return!!this.findOne(".top-left")&&this.update(),this}_proxyDrag(t){let e;t.on(`dragstart.${this._getEventNamespace()}`,i=>{e=t.getAbsolutePosition(),this.isDragging()||t===this.findOne(".back")||this.startDrag(i,!1)}),t.on(`dragmove.${this._getEventNamespace()}`,i=>{if(!e)return;const s=t.getAbsolutePosition(),r=s.x-e.x,n=s.y-e.y;this.nodes().forEach(e=>{if(e===t)return;if(e.isDragging())return;const s=e.getAbsolutePosition();e.setAbsolutePosition({x:s.x+r,y:s.y+n}),e.startDrag(i)}),e=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(t=>{t.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(Cs),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(Cs,this.__getNodeRect)}__getNodeShape(t,e=this.rotation(),i){const s=t.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),r=t.getAbsoluteScale(i),n=t.getAbsolutePosition(i),a=s.x*r.x-t.offsetX()*r.x,o=s.y*r.y-t.offsetY()*r.y,h=(At.getAngle(t.getAbsoluteRotation())+2*Math.PI)%(2*Math.PI);return Es({x:n.x+a*Math.cos(h)+o*Math.sin(-h),y:n.y+o*Math.cos(h)+a*Math.sin(h),width:s.width*r.x,height:s.height*r.y,rotation:h},-At.getAngle(e),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const t=[];this.nodes().map(e=>{const i=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),s=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x+i.width,y:i.y+i.height},{x:i.x,y:i.y+i.height}],r=e.getAbsoluteTransform();s.forEach(function(e){const i=r.point(e);t.push(i)})});const e=new Pt;e.rotate(-At.getAngle(this.rotation()));let i=1/0,s=1/0,r=-1/0,n=-1/0;t.forEach(function(t){const a=e.point(t);void 0===i&&(i=r=a.x,s=n=a.y),i=Math.min(i,a.x),s=Math.min(s,a.y),r=Math.max(r,a.x),n=Math.max(n,a.y)}),e.invert();const a=e.point({x:i,y:s});return{x:a.x,y:a.y,width:r-i,height:n-s,rotation:At.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(),Ps.forEach(t=>{this._createAnchor(t)}),this._createAnchor("rotater")}_createAnchor(t){const e=new $i({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:t+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:ks?10:"auto"}),i=this;e.on("mousedown touchstart",function(t){i._handleMouseDown(t)}),e.on("dragstart",t=>{e.stopDrag(),t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),e.on("mouseenter",()=>{const i=At.getAngle(this.rotation()),s=this.rotateAnchorCursor(),r=function(t,e,i){if("rotater"===t)return i;e+=Gt.degToRad(Ts[t]||0);const s=(Gt.radToDeg(e)%360+360)%360;return Gt._inRange(s,337.5,360)||Gt._inRange(s,0,22.5)?"ns-resize":Gt._inRange(s,22.5,67.5)?"nesw-resize":Gt._inRange(s,67.5,112.5)?"ew-resize":Gt._inRange(s,112.5,157.5)?"nwse-resize":Gt._inRange(s,157.5,202.5)?"ns-resize":Gt._inRange(s,202.5,247.5)?"nesw-resize":Gt._inRange(s,247.5,292.5)?"ew-resize":Gt._inRange(s,292.5,337.5)?"nwse-resize":(Gt.error("Transformer has unknown angle for cursor detection: "+s),"pointer")}(t,i,s);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 ui({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()*Gt._sign(e.height())-s),t.fillStrokeShape(e)},hitFunc:(t,e)=>{if(!this.shouldOverdrawWholeArea())return;const i=this.padding();t.beginPath(),t.rect(-i,-i,e.width()+2*i,e.height()+2*i),t.fillStrokeShape(e)}});this.add(t),this._proxyDrag(t),t.on("dragstart",t=>{t.cancelBubble=!0}),t.on("dragmove",t=>{t.cancelBubble=!0}),t.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{this.update()})}_handleMouseDown(t){if(this._transforming)return;this._movingAnchorName=t.target.name().split(" ")[0];const e=this._getNodeRect(),i=e.width,s=e.height,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));this.sin=Math.abs(s/r),this.cos=Math.abs(i/r),"undefined"!=typeof window&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const n=t.target.getAbsolutePosition(),a=t.target.getStage().getPointerPosition();this._anchorDragOffset={x:a.x-n.x,y:a.y-n.y},Is++,this._fire("transformstart",{evt:t.evt,target:this.getNode()}),this._nodes.forEach(e=>{e._fire("transformstart",{evt:t.evt,target:e})})}_handleMouseMove(t){let e,i,s;const r=this.findOne("."+this._movingAnchorName),n=r.getStage();n.setPointersPositions(t);const a=n.getPointerPosition();let o={x:a.x-this._anchorDragOffset.x,y:a.y-this._anchorDragOffset.y};const h=r.getAbsolutePosition();this.anchorDragBoundFunc()&&(o=this.anchorDragBoundFunc()(h,o,t)),r.setAbsolutePosition(o);const l=r.getAbsolutePosition();if(h.x===l.x&&h.y===l.y)return;if("rotater"===this._movingAnchorName){const s=this._getNodeRect();e=r.x()-s.width/2,i=-r.y()+s.height/2;let n=Math.atan2(-i,e)+Math.PI/2;s.height<0&&(n-=Math.PI);const a=At.getAngle(this.rotation())+n,o=At.getAngle(this.rotationSnapTolerance()),h=function(t,e,i){let s=e;for(let r=0;r<t.length;r++){const n=At.getAngle(t[r]),a=Math.abs(n-e)%(2*Math.PI);Math.min(a,2*Math.PI-a)<i&&(s=n)}return s}(this.rotationSnaps(),a,o),l=Ms(s,h-s.rotation);return void this._fitNodesInto(l,t)}const d=this.shiftBehavior();let c;c="inverted"===d?this.keepRatio()&&!t.shiftKey:"none"===d?this.keepRatio():this.keepRatio()||t.shiftKey;let u=this.centeredScaling()||t.altKey;if("top-left"===this._movingAnchorName){if(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};s=Math.sqrt(Math.pow(t.x-r.x(),2)+Math.pow(t.y-r.y(),2));const n=this.findOne(".top-left").x()>t.x?-1:1,a=this.findOne(".top-left").y()>t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,this.findOne(".top-left").x(t.x-e),this.findOne(".top-left").y(t.y-i)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(r.y());else if("top-right"===this._movingAnchorName){if(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};s=Math.sqrt(Math.pow(r.x()-t.x,2)+Math.pow(t.y-r.y(),2));const n=this.findOne(".top-right").x()<t.x?-1:1,a=this.findOne(".top-right").y()>t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,this.findOne(".top-right").x(t.x+e),this.findOne(".top-right").y(t.y-i)}var g=r.position();this.findOne(".top-left").y(g.y),this.findOne(".bottom-right").x(g.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(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};s=Math.sqrt(Math.pow(t.x-r.x(),2)+Math.pow(r.y()-t.y,2));const n=t.x<r.x()?-1:1,a=r.y()<t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,r.x(t.x-e),r.y(t.y+i)}g=r.position(),this.findOne(".top-left").x(g.x),this.findOne(".bottom-right").y(g.y)}else if("bottom-center"===this._movingAnchorName)this.findOne(".bottom-right").y(r.y());else if("bottom-right"===this._movingAnchorName){if(c){const t=u?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};s=Math.sqrt(Math.pow(r.x()-t.x,2)+Math.pow(r.y()-t.y,2));const n=this.findOne(".bottom-right").x()<t.x?-1:1,a=this.findOne(".bottom-right").y()<t.y?-1:1;e=s*this.cos*n,i=s*this.sin*a,this.findOne(".bottom-right").x(t.x+e),this.findOne(".bottom-right").y(t.y+i)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(u=this.centeredScaling()||t.altKey,u){const t=this.findOne(".top-left"),e=this.findOne(".bottom-right"),i=t.x(),s=t.y(),r=this.getWidth()-e.x(),n=this.getHeight()-e.y();e.move({x:-i,y:-s}),t.move({x:r,y:n})}const p=this.findOne(".top-left").getAbsolutePosition();e=p.x,i=p.y;const m=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),f=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:e,y:i,width:m,height:f,rotation:At.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();Is--,this._fire("transformend",{evt:t,target:i}),null===(e=this.getLayer())||void 0===e||e.batchDraw(),i&&this._nodes.forEach(e=>{var i;e._fire("transformend",{evt:t,target:e}),null===(i=e.getLayer())||void 0===i||i.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(t,e){const i=this._getNodeRect();if(Gt._inRange(t.width,2*-this.padding()-1,1))return void this.update();if(Gt._inRange(t.height,2*-this.padding()-1,1))return void this.update();const s=new Pt;if(s.rotate(At.getAngle(this.rotation())),this._movingAnchorName&&t.width<0&&this._movingAnchorName.indexOf("left")>=0){const e=s.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=s.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=s.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=s.point({x:0,y:2*this.padding()});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=e.x,this._anchorDragOffset.y-=e.y,t.height+=2*this.padding()}if(this.boundBoxFunc()){const e=this.boundBoxFunc()(i,t);e?t=e:Gt.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const r=1e7,n=new Pt;n.translate(i.x,i.y),n.rotate(i.rotation),n.scale(i.width/r,i.height/r);const a=new Pt,o=t.width/r,h=t.height/r;!1===this.flipEnabled()?(a.translate(t.x,t.y),a.rotate(t.rotation),a.translate(t.width<0?t.width:0,t.height<0?t.height:0),a.scale(Math.abs(o),Math.abs(h))):(a.translate(t.x,t.y),a.rotate(t.rotation),a.scale(o,h));const l=a.multiply(n.invert());this._nodes.forEach(t=>{var e;if(!t.getStage())return;const i=t.getParent().getAbsoluteTransform(),s=t.getTransform().copy();s.translate(t.offsetX(),t.offsetY());const r=new Pt;r.multiply(i.copy().invert()).multiply(l).multiply(i).multiply(s);const n=r.decompose();t.setAttrs(n),null===(e=t.getLayer())||void 0===e||e.batchDraw()}),this.rotation(Gt._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(Gt._getRotation(e.rotation));const i=e.width,s=e.height,r=this.enabledAnchors(),n=this.resizeEnabled(),a=this.padding(),o=this.anchorSize(),h=this.find("._anchor");h.forEach(t=>{t.setAttrs({width:o,height:o,offsetX:o/2,offsetY:o/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:o/2+a,offsetY:o/2+a,visible:n&&r.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:i/2,y:0,offsetY:o/2+a,visible:n&&r.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:i,y:0,offsetX:o/2-a,offsetY:o/2+a,visible:n&&r.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:s/2,offsetX:o/2+a,visible:n&&r.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:i,y:s/2,offsetX:o/2-a,visible:n&&r.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:s,offsetX:o/2+a,offsetY:o/2-a,visible:n&&r.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:i/2,y:s,offsetY:o/2-a,visible:n&&r.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:i,y:s,offsetX:o/2-a,offsetY:o/2-a,visible:n&&r.indexOf("bottom-right")>=0}),this._batchChangeChild(".rotater",{x:i/2,y:-this.rotateAnchorOffset()*Gt._sign(s)-a,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=""),_i.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}toObject(){return xe.prototype.toObject.call(this)}clone(t){return xe.prototype.clone.call(this,t)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}}Rs.isTransforming=()=>Is>0,Rs.prototype.className="Transformer",Tt(Rs),ae.addGetterSetter(Rs,"enabledAnchors",Ps,function(t){return t instanceof Array||Gt.warn("enabledAnchors value should be an array"),t instanceof Array&&t.forEach(function(t){-1===Ps.indexOf(t)&&Gt.warn("Unknown anchor name: "+t+". Available names are: "+Ps.join(", "))}),t||[]}),ae.addGetterSetter(Rs,"flipEnabled",!0,se()),ae.addGetterSetter(Rs,"resizeEnabled",!0),ae.addGetterSetter(Rs,"anchorSize",10,$t()),ae.addGetterSetter(Rs,"rotateEnabled",!0),ae.addGetterSetter(Rs,"rotateLineVisible",!0),ae.addGetterSetter(Rs,"rotationSnaps",[]),ae.addGetterSetter(Rs,"rotateAnchorOffset",50,$t()),ae.addGetterSetter(Rs,"rotateAnchorCursor","crosshair"),ae.addGetterSetter(Rs,"rotationSnapTolerance",5,$t()),ae.addGetterSetter(Rs,"borderEnabled",!0),ae.addGetterSetter(Rs,"anchorStroke","rgb(0, 161, 255)"),ae.addGetterSetter(Rs,"anchorStrokeWidth",1,$t()),ae.addGetterSetter(Rs,"anchorFill","white"),ae.addGetterSetter(Rs,"anchorCornerRadius",0,$t()),ae.addGetterSetter(Rs,"borderStroke","rgb(0, 161, 255)"),ae.addGetterSetter(Rs,"borderStrokeWidth",1,$t()),ae.addGetterSetter(Rs,"borderDash"),ae.addGetterSetter(Rs,"keepRatio",!0),ae.addGetterSetter(Rs,"shiftBehavior","default"),ae.addGetterSetter(Rs,"centeredScaling",!1),ae.addGetterSetter(Rs,"ignoreStroke",!1),ae.addGetterSetter(Rs,"padding",0,$t()),ae.addGetterSetter(Rs,"nodes"),ae.addGetterSetter(Rs,"node"),ae.addGetterSetter(Rs,"boundBoxFunc"),ae.addGetterSetter(Rs,"anchorDragBoundFunc"),ae.addGetterSetter(Rs,"anchorStyleFunc"),ae.addGetterSetter(Rs,"shouldOverdrawWholeArea",!1),ae.addGetterSetter(Rs,"useSingleNodeRotation",!0),ae.backCompat(Rs,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});class Ds extends ui{_sceneFunc(t){t.beginPath(),t.arc(0,0,this.radius(),0,At.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 Ls(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}Ds.prototype.className="Wedge",Ds.prototype._centroid=!0,Ds.prototype._attrsAffectingSize=["radius"],Tt(Ds),ae.addGetterSetter(Ds,"radius",0,$t()),ae.addGetterSetter(Ds,"angle",0,$t()),ae.addGetterSetter(Ds,"clockwise",!1),ae.backCompat(Ds,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});const Os=[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],zs=[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];ae.addGetterSetter(xe,"blurRadius",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"brightness",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"contrast",0,$t(),ae.afterSetFilter);function Fs(t,e,i,s,r){const n=i-e,a=r-s;if(0===n)return s+a/2;if(0===a)return s;let o=(t-e)/n;return o=a*o+s,o}ae.addGetterSetter(xe,"embossStrength",.5,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"embossWhiteLevel",.5,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"embossDirection","top-left",void 0,ae.afterSetFilter),ae.addGetterSetter(xe,"embossBlend",!1,void 0,ae.afterSetFilter);ae.addGetterSetter(xe,"enhance",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"hue",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"saturation",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"luminance",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"hue",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"saturation",0,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"value",0,$t(),ae.afterSetFilter);function Gs(t,e,i){let s=4*(i*t.width+e);const r=[];return r.push(t.data[s++],t.data[s++],t.data[s++],t.data[s++]),r}function Vs(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))}ae.addGetterSetter(xe,"kaleidoscopePower",2,$t(),ae.afterSetFilter),ae.addGetterSetter(xe,"kaleidoscopeAngle",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"threshold",0,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"noise",.2,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"pixelSize",8,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"levels",.5,$t(),ae.afterSetFilter);ae.addGetterSetter(xe,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"blue",0,Zt,ae.afterSetFilter);ae.addGetterSetter(xe,"red",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),ae.addGetterSetter(xe,"blue",0,Zt,ae.afterSetFilter),ae.addGetterSetter(xe,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t});ae.addGetterSetter(xe,"threshold",.5,$t(),ae.afterSetFilter);const Ws=Ti.Util._assign(Ti,{Arc:ki,Arrow:Wi,Circle:Bi,Ellipse:Ni,Image:ji,Label:Ki,Tag:Zi,Line:Mi,Path:Vi,Rect:$i,RegularPolygon:Qi,Ring:es,Sprite:is,Star:ss,Text:_s,TextPath:xs,Transformer:Rs,Wedge:Ds,Filters:{Blur:function(t){const e=Math.round(this.blurRadius());e>0&&function(t,e){const i=t.data,s=t.width,r=t.height;let n,a,o,h,l,d,c,u,g,p,m,f,_,v,y,w,x,b,S,C;const A=e+e+1,T=s-1,k=r-1,P=e+1,E=P*(P+1)/2,M=new Ls,I=Os[e],R=zs[e];let D=null,L=M,O=null,z=null;for(let t=1;t<A;t++)L=L.next=new Ls,t===P&&(D=L);L.next=M,o=a=0;for(let t=0;t<r;t++){f=_=v=y=h=l=d=c=0,u=P*(w=i[a]),g=P*(x=i[a+1]),p=P*(b=i[a+2]),m=P*(S=i[a+3]),h+=E*w,l+=E*x,d+=E*b,c+=E*S,L=M;for(let t=0;t<P;t++)L.r=w,L.g=x,L.b=b,L.a=S,L=L.next;for(let t=1;t<P;t++)n=a+((T<t?T:t)<<2),h+=(L.r=w=i[n])*(C=P-t),l+=(L.g=x=i[n+1])*C,d+=(L.b=b=i[n+2])*C,c+=(L.a=S=i[n+3])*C,f+=w,_+=x,v+=b,y+=S,L=L.next;O=M,z=D;for(let t=0;t<s;t++)i[a+3]=S=c*I>>R,0!==S?(S=255/S,i[a]=(h*I>>R)*S,i[a+1]=(l*I>>R)*S,i[a+2]=(d*I>>R)*S):i[a]=i[a+1]=i[a+2]=0,h-=u,l-=g,d-=p,c-=m,u-=O.r,g-=O.g,p-=O.b,m-=O.a,n=o+((n=t+e+1)<T?n:T)<<2,f+=O.r=i[n],_+=O.g=i[n+1],v+=O.b=i[n+2],y+=O.a=i[n+3],h+=f,l+=_,d+=v,c+=y,O=O.next,u+=w=z.r,g+=x=z.g,p+=b=z.b,m+=S=z.a,f-=w,_-=x,v-=b,y-=S,z=z.next,a+=4;o+=s}for(let t=0;t<s;t++){_=v=y=f=l=d=c=h=0,a=t<<2,u=P*(w=i[a]),g=P*(x=i[a+1]),p=P*(b=i[a+2]),m=P*(S=i[a+3]),h+=E*w,l+=E*x,d+=E*b,c+=E*S,L=M;for(let t=0;t<P;t++)L.r=w,L.g=x,L.b=b,L.a=S,L=L.next;let o=s;for(let r=1;r<=e;r++)a=o+t<<2,h+=(L.r=w=i[a])*(C=P-r),l+=(L.g=x=i[a+1])*C,d+=(L.b=b=i[a+2])*C,c+=(L.a=S=i[a+3])*C,f+=w,_+=x,v+=b,y+=S,L=L.next,r<k&&(o+=s);a=t,O=M,z=D;for(let e=0;e<r;e++)n=a<<2,i[n+3]=S=c*I>>R,S>0?(S=255/S,i[n]=(h*I>>R)*S,i[n+1]=(l*I>>R)*S,i[n+2]=(d*I>>R)*S):i[n]=i[n+1]=i[n+2]=0,h-=u,l-=g,d-=p,c-=m,u-=O.r,g-=O.g,p-=O.b,m-=O.a,n=t+((n=e+P)<k?n:k)*s<<2,h+=f+=O.r=i[n],l+=_+=O.g=i[n+1],d+=v+=O.b=i[n+2],c+=y+=O.a=i[n+3],O=O.next,u+=w=z.r,g+=x=z.g,p+=b=z.b,m+=S=z.a,f-=w,_-=x,v-=b,y-=S,z=z.next,a+=s}}(t,e)},Brightness:function(t){const e=this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]=Math.min(255,i[t]*e),i[t+1]=Math.min(255,i[t+1]*e),i[t+2]=Math.min(255,i[t+2]*e)},Brighten:function(t){const e=255*this.brightness(),i=t.data,s=i.length;for(let t=0;t<s;t+=4)i[t]+=e,i[t+1]+=e,i[t+2]+=e},Contrast:function(t){const e=Math.pow((this.contrast()+100)/100,2),i=t.data,s=i.length;let r=150,n=150,a=150;for(let t=0;t<s;t+=4)r=i[t],n=i[t+1],a=i[t+2],r/=255,r-=.5,r*=e,r+=.5,r*=255,n/=255,n-=.5,n*=e,n+=.5,n*=255,a/=255,a-=.5,a*=e,a+=.5,a*=255,r=r<0?0:r>255?255:r,n=n<0?0:n>255?255:n,a=a<0?0:a>255?255:a,i[t]=r,i[t+1]=n,i[t+2]=a},Emboss:function(t){var e,i,s,r,n,a,o,h,l;const d=t.data,c=t.width,u=t.height,g=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)),p=Math.min(1,Math.max(0,null!==(r=null===(s=this.embossWhiteLevel)||void 0===s?void 0:s.call(this))&&void 0!==r?r:.5)),m=null!==(o={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[null!==(a=null===(n=this.embossDirection)||void 0===n?void 0:n.call(this))&&void 0!==a?a:"top-left"])&&void 0!==o?o:315,f=!(null===(l=null===(h=this.embossBlend)||void 0===h?void 0:h.call(this))||void 0===l||!l),_=10*g,v=255*p,y=m*Math.PI/180,w=Math.cos(y),x=Math.sin(y),b=128/1020*_,S=new Uint8ClampedArray(d),C=new Float32Array(c*u);for(let t=0,e=0;e<d.length;e+=4,t++)C[t]=.2126*S[e]+.7152*S[e+1]+.0722*S[e+2];const A=[-1,0,1,-2,0,2,-1,0,1],T=[-1,-2,-1,0,0,0,1,2,1],k=[-c-1,-c,1-c,-1,0,1,c-1,c,c+1],P=t=>t<0?0:t>255?255:t;for(let t=1;t<u-1;t++)for(let e=1;e<c-1;e++){const i=t*c+e;let s=0,r=0;s+=C[i+k[0]]*A[0],r+=C[i+k[0]]*T[0],s+=C[i+k[1]]*A[1],r+=C[i+k[1]]*T[1],s+=C[i+k[2]]*A[2],r+=C[i+k[2]]*T[2],s+=C[i+k[3]]*A[3],r+=C[i+k[3]]*T[3],s+=C[i+k[5]]*A[5],r+=C[i+k[5]]*T[5],s+=C[i+k[6]]*A[6],r+=C[i+k[6]]*T[6],s+=C[i+k[7]]*A[7],r+=C[i+k[7]]*T[7],s+=C[i+k[8]]*A[8],r+=C[i+k[8]]*T[8];const n=P(v+(w*s+x*r)*b),a=4*i;if(f){const t=n-v;d[a]=P(S[a]+t),d[a+1]=P(S[a+1]+t),d[a+2]=P(S[a+2]+t),d[a+3]=S[a+3]}else d[a]=d[a+1]=d[a+2]=n,d[a+3]=S[a+3]}for(let t=0;t<c;t++){let e=4*t,i=4*((u-1)*c+t);d[e]=S[e],d[e+1]=S[e+1],d[e+2]=S[e+2],d[e+3]=S[e+3],d[i]=S[i],d[i+1]=S[i+1],d[i+2]=S[i+2],d[i+3]=S[i+3]}for(let t=1;t<u-1;t++){let e=t*c*4,i=4*(t*c+(c-1));d[e]=S[e],d[e+1]=S[e+1],d[e+2]=S[e+2],d[e+3]=S[e+3],d[i]=S[i],d[i+1]=S[i+1],d[i+2]=S[i+2],d[i+3]=S[i+3]}return t},Enhance:function(t){const e=t.data,i=e.length;let s,r,n,a=e[0],o=a,h=e[1],l=h,d=e[2],c=d;const u=this.enhance();if(0===u)return;for(let t=0;t<i;t+=4)s=e[t+0],s<a?a=s:s>o&&(o=s),r=e[t+1],r<h?h=r:r>l&&(l=r),n=e[t+2],n<d?d=n:n>c&&(c=n);let g,p,m,f,_,v;if(o===a&&(o=255,a=0),l===h&&(l=255,h=0),c===d&&(c=255,d=0),u>0)g=o+u*(255-o),p=a-u*(a-0),m=l+u*(255-l),f=h-u*(h-0),_=c+u*(255-c),v=d-u*(d-0);else{const t=.5*(o+a);g=o+u*(o-t),p=a+u*(a-t);const e=.5*(l+h);m=l+u*(l-e),f=h+u*(h-e);const i=.5*(c+d);_=c+u*(c-i),v=d+u*(d-i)}for(let t=0;t<i;t+=4)e[t+0]=Fs(e[t+0],a,o,p,g),e[t+1]=Fs(e[t+1],h,l,f,m),e[t+2]=Fs(e[t+2],d,c,v,_)},Grayscale:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=.34*e[t]+.5*e[t+1]+.16*e[t+2];e[t]=i,e[t+1]=i,e[t+2]=i}},HSL:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.saturation()),r=Math.abs(this.hue()+360)%360,n=127*this.luminance(),a=1*s*Math.cos(r*Math.PI/180),o=1*s*Math.sin(r*Math.PI/180),h=.299+.701*a+.167*o,l=.587-.587*a+.33*o,d=.114-.114*a-.497*o,c=.299-.299*a-.328*o,u=.587+.413*a+.035*o,g=.114-.114*a+.293*o,p=.299-.3*a+1.25*o,m=.587-.586*a-1.05*o,f=.114+.886*a-.2*o;let _,v,y,w;for(let t=0;t<i;t+=4)_=e[t+0],v=e[t+1],y=e[t+2],w=e[t+3],e[t+0]=h*_+l*v+d*y+n,e[t+1]=c*_+u*v+g*y+n,e[t+2]=p*_+m*v+f*y+n,e[t+3]=w},HSV:function(t){const e=t.data,i=e.length,s=Math.pow(2,this.value()),r=Math.pow(2,this.saturation()),n=Math.abs(this.hue()+360)%360,a=s*r*Math.cos(n*Math.PI/180),o=s*r*Math.sin(n*Math.PI/180),h=.299*s+.701*a+.167*o,l=.587*s-.587*a+.33*o,d=.114*s-.114*a-.497*o,c=.299*s-.299*a-.328*o,u=.587*s+.413*a+.035*o,g=.114*s-.114*a+.293*o,p=.299*s-.3*a+1.25*o,m=.587*s-.586*a-1.05*o,f=.114*s+.886*a-.2*o;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2],n=e[t+3];e[t+0]=h*i+l*s+d*r,e[t+1]=c*i+u*s+g*r,e[t+2]=p*i+m*s+f*r,e[t+3]=n}},Invert:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4)e[t]=255-e[t],e[t+1]=255-e[t+1],e[t+2]=255-e[t+2]},Kaleidoscope:function(t){const e=t.width,i=t.height;let s,r,n,a,o,h,l,d,c,u,g=Math.round(this.kaleidoscopePower());const p=Math.round(this.kaleidoscopeAngle()),m=Math.floor(e*(p%360)/360);if(g<1)return;const f=Gt.createCanvasElement();f.width=e,f.height=i;const _=f.getContext("2d").getImageData(0,0,e,i);Gt.releaseCanvas(f),function(t,e,i){const s=t.data,r=e.data,n=t.width,a=t.height,o=i.polarCenterX||n/2,h=i.polarCenterY||a/2;let l=Math.sqrt(o*o+h*h),d=n-o,c=a-h;const u=Math.sqrt(d*d+c*c);l=u>l?u:l;const g=a,p=n,m=360/p*Math.PI/180;for(let t=0;t<p;t+=1){const e=Math.sin(t*m),i=Math.cos(t*m);for(let a=0;a<g;a+=1){d=Math.floor(o+l*a/g*i),c=Math.floor(h+l*a/g*e);let u=4*(c*n+d);const p=s[u+0],m=s[u+1],f=s[u+2],_=s[u+3];u=4*(t+a*n),r[u+0]=p,r[u+1]=m,r[u+2]=f,r[u+3]=_}}}(t,_,{polarCenterX:e/2,polarCenterY:i/2});let v=e/Math.pow(2,g);for(;v<=8;)v*=2,g-=1;v=Math.ceil(v);let y=v,w=0,x=y,b=1;for(m+v>e&&(w=y,x=0,b=-1),r=0;r<i;r+=1)for(s=w;s!==x;s+=b)n=Math.round(s+m)%e,c=4*(e*r+n),o=_.data[c+0],h=_.data[c+1],l=_.data[c+2],d=_.data[c+3],u=4*(e*r+s),_.data[u+0]=o,_.data[u+1]=h,_.data[u+2]=l,_.data[u+3]=d;for(r=0;r<i;r+=1)for(y=Math.floor(v),a=0;a<g;a+=1){for(s=0;s<y+1;s+=1)c=4*(e*r+s),o=_.data[c+0],h=_.data[c+1],l=_.data[c+2],d=_.data[c+3],u=4*(e*r+2*y-s-1),_.data[u+0]=o,_.data[u+1]=h,_.data[u+2]=l,_.data[u+3]=d;y*=2}!function(t,e,i){const s=t.data,r=e.data,n=t.width,a=t.height,o=i.polarCenterX||n/2,h=i.polarCenterY||a/2;let l=Math.sqrt(o*o+h*h),d=n-o,c=a-h;const u=Math.sqrt(d*d+c*c);l=u>l?u:l;const g=a,p=n;let m,f;for(d=0;d<n;d+=1)for(c=0;c<a;c+=1){const t=d-o,e=c-h,i=Math.sqrt(t*t+e*e)*g/l;let a=(180*Math.atan2(e,t)/Math.PI+360+0)%360;a=a*p/360,m=Math.floor(a),f=Math.floor(i);let u=4*(f*n+m);const _=s[u+0],v=s[u+1],y=s[u+2],w=s[u+3];u=4*(c*n+d),r[u+0]=_,r[u+1]=v,r[u+2]=y,r[u+3]=w}}(_,t,{})},Mask:function(t){let e=function(t,e){const i=Gs(t,0,0),s=Gs(t,t.width-1,0),r=Gs(t,0,t.height-1),n=Gs(t,t.width-1,t.height-1),a=e||10;if(Vs(i,s)<a&&Vs(s,n)<a&&Vs(n,r)<a&&Vs(r,i)<a){const e=function(t){const e=[0,0,0];for(let i=0;i<t.length;i++)e[0]+=t[i][0],e[1]+=t[i][1],e[2]+=t[i][2];return e[0]/=t.length,e[1]/=t.length,e[2]/=t.length,e}([s,i,n,r]),o=[];for(let i=0;i<t.width*t.height;i++){const s=Vs(e,[t.data[4*i],t.data[4*i+1],t.data[4*i+2]]);o[i]=s<a?0:255}return o}}(t,this.threshold());return e&&(e=function(t,e,i){const s=[1,1,1,1,0,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),a=[];for(let o=0;o<i;o++)for(let h=0;h<e;h++){const l=o*e+h;let d=0;for(let a=0;a<r;a++)for(let l=0;l<r;l++){const c=o+a-n,u=h+l-n;if(c>=0&&c<i&&u>=0&&u<e){const i=s[a*r+l];d+=t[c*e+u]*i}}a[l]=2040===d?255:0}return a}(e,t.width,t.height),e=function(t,e,i){const s=[1,1,1,1,1,1,1,1,1],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),a=[];for(let o=0;o<i;o++)for(let h=0;h<e;h++){const l=o*e+h;let d=0;for(let a=0;a<r;a++)for(let l=0;l<r;l++){const c=o+a-n,u=h+l-n;if(c>=0&&c<i&&u>=0&&u<e){const i=s[a*r+l];d+=t[c*e+u]*i}}a[l]=d>=1020?255:0}return a}(e,t.width,t.height),e=function(t,e,i){const s=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],r=Math.round(Math.sqrt(s.length)),n=Math.floor(r/2),a=[];for(let o=0;o<i;o++)for(let h=0;h<e;h++){const l=o*e+h;let d=0;for(let a=0;a<r;a++)for(let l=0;l<r;l++){const c=o+a-n,u=h+l-n;if(c>=0&&c<i&&u>=0&&u<e){const i=s[a*r+l];d+=t[c*e+u]*i}}a[l]=d}return a}(e,t.width,t.height),function(t,e){for(let i=0;i<t.width*t.height;i++)t.data[4*i+3]=e[i]}(t,e)),t},Noise:function(t){const e=255*this.noise(),i=t.data,s=i.length,r=e/2;for(let t=0;t<s;t+=4)i[t+0]+=r-2*r*Math.random(),i[t+1]+=r-2*r*Math.random(),i[t+2]+=r-2*r*Math.random()},Pixelate:function(t){let e=Math.ceil(this.pixelSize()),i=t.width,s=t.height,r=Math.ceil(i/e),n=Math.ceil(s/e),a=t.data;if(e<=0)Gt.error("pixelSize value can not be <= 0");else for(let t=0;t<r;t+=1)for(let r=0;r<n;r+=1){let n=0,o=0,h=0,l=0;const d=t*e,c=d+e,u=r*e,g=u+e;let p=0;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=u;e<g;e+=1){if(e>=s)continue;const r=4*(i*e+t);n+=a[r+0],o+=a[r+1],h+=a[r+2],l+=a[r+3],p+=1}n/=p,o/=p,h/=p,l/=p;for(let t=d;t<c;t+=1)if(!(t>=i))for(let e=u;e<g;e+=1){if(e>=s)continue;const r=4*(i*e+t);a[r+0]=n,a[r+1]=o,a[r+2]=h,a[r+3]=l}}},Posterize:function(t){const e=Math.round(254*this.levels())+1,i=t.data,s=i.length,r=255/e;for(let t=0;t<s;t+=1)i[t]=Math.floor(i[t]/r)*r},RGB:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue();for(let t=0;t<i;t+=4){const i=(.34*e[t]+.5*e[t+1]+.16*e[t+2])/255;e[t]=i*s,e[t+1]=i*r,e[t+2]=i*n,e[t+3]=e[t+3]}},RGBA:function(t){const e=t.data,i=e.length,s=this.red(),r=this.green(),n=this.blue(),a=this.alpha();for(let t=0;t<i;t+=4){const i=1-a;e[t]=s*a+e[t]*i,e[t+1]=r*a+e[t+1]*i,e[t+2]=n*a+e[t+2]*i}},Sepia:function(t){const e=t.data,i=e.length;for(let t=0;t<i;t+=4){const i=e[t+0],s=e[t+1],r=e[t+2];e[t+0]=Math.min(255,.393*i+.769*s+.189*r),e[t+1]=Math.min(255,.349*i+.686*s+.168*r),e[t+2]=Math.min(255,.272*i+.534*s+.131*r)}},Solarize:function(t){const e=t.data;for(let t=0;t<e.length;t+=4){const i=e[t],s=e[t+1],r=e[t+2];.2126*i+.7152*s+.0722*r>=128&&(e[t]=255-i,e[t+1]=255-s,e[t+2]=255-r)}return t},Threshold:function(t){const e=255*this.threshold(),i=t.data,s=i.length;for(let t=0;t<s;t+=1)i[t]=i[t]<e?0:255}}});class Bs{screenToWorld(t){return{x:t.x,y:t.y,z:0}}worldToScreen(t){return{x:t.x,y:t.y}}getScale(){return{x:1,y:1,z:1}}}class Ns{constructor(t,e,i){this.setColor(t,e,i)}asHex(){return"#"+this.HEX}asRGB(){return{r:this.R,g:this.G,b:this.B}}setColor(t,e,i){this.R=t,this.G=e,this.B=i,this.HEX=this.rgbToHex(t,e,i)}rgbToHex(t,e,i){const s=t=>{const e=t.toString(16);return"0"===e?"00":e};return s(t)+s(e)+s(i)}}const js=new Map([["solid",[]],["dot",[30,30,.001,30]],["dash",[30,30]]]);class Hs{constructor(t,e=null,i=new Bs){var s,r;if(this._worldTransformer=i,e){this._ref=e;let t=this._ref.getAttr("wcsPoints");if(!t){t=[];const e=this._ref.points();let i;for(let s=0;s<e.length;s+=2)i=this._worldTransformer.screenToWorld({x:e[s],y:e[s+1]}),t.push({x:i.x,y:i.y,z:i.z});this._ref.setAttr("wcsPoints",t)}return}t||(t={}),t.points||(t.points=[{x:0,y:0},{x:100,y:100}]);const n=[],a=[];t.points.forEach(t=>{n.push(t.x,t.y);const e=this._worldTransformer.screenToWorld({x:t.x,y:t.y});a.push({x:e.x,y:e.y,z:e.z})}),this._ref=new Ws.Line({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.width)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:n,draggable:!0,strokeScaleEnabled:!1,dash:js.get(t.type)||[]}),this._ref.setAttr("wcsPoints",a),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation)}),this._ref.on("transformend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.on("dragend",()=>{const t=this._ref.getAbsoluteTransform(),e=[],i=this._ref.points();let s;for(let r=0;r<i.length;r+=2){const n=t.point({x:i[r],y:i[r+1]});s=this._worldTransformer.screenToWorld({x:n.x,y:n.y}),e.push({x:s.x,y:s.y,z:s.z})}this._ref.setAttr("wcsPoints",e)}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Line"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){return this._ref.points()}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}getLineType(){let t;switch(this._ref.dash()||[]){case js.get("dot"):t="dot";break;case js.get("dash"):t="dash";break;default:t="solid"}return t}setLineType(t){const e=js.get(t);e&&this._ref.dash(e)}addPoints(t){let e=this._ref.points();const i=this._ref.getAttr("wcsPoints");t.forEach(t=>{e=e.concat([t.x,t.y]);const s=this._worldTransformer.screenToWorld(t);i.push(s)}),this._ref.points(e)}updateScreenCoordinates(){const t=this._ref.getAttr("wcsPoints"),e=[];let i=this._ref.getAbsoluteTransform().copy();i=i.invert(),t.forEach(t=>{let s=this._worldTransformer.worldToScreen(t);s=i.point({x:s.x,y:s.y}),e.push(s.x),e.push(s.y)}),this._ref.points([]),this._ref.points(e),this._ref.clearCache()}}class Us{constructor(t,e=null,i=new Bs){var s,r,n;if(this.TEXT_FONT_FAMILY="Calibri",this._worldTransformer=i,e){this._ref=e;return void(this._ref.getAttr("wcsStart")||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.text||(t.text="default"),this._ref=new Ws.Text({x:t.position.x,y:t.position.y,text:t.text,fontSize:null!==(s=t.fontSize)&&void 0!==s?s:34,fontFamily:this.TEXT_FONT_FAMILY,fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",align:"left",draggable:!0,rotation:null!==(n=t.rotation)&&void 0!==n?n:0}),this._ref.width(this._ref.getTextWidth()),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<Math.round(this.getFontSize())&&(n=Math.round(this.getFontSize())),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Text"}getColor(){return this._ref.fill()}setColor(t){this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getText(){return this._ref.text()}setText(t){this._ref.text(t)}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getFontSize(){return this._ref.fontSize()}setFontSize(t){this._ref.fontSize(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));let e=this._ref.getStage().getAbsoluteTransform().copy();e=e.invert();const i=e.point(t);this._ref.position({x:i.x,y:i.y})}}class Xs{constructor(t,e=null,i=new Bs){var s,r,n,a;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200),this._ref=new Ws.Rect({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",strokeWidth:null!==(r=t.lineWidth)&&void 0!==r?r:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,width:null!==(n=t.width)&&void 0!==n?n:200,height:null!==(a=t.height)&&void 0!==a?a:200,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY);r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}getWidth(){return this._ref.width()}getHeight(){return this._ref.height()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Rectangle"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}setLineWidth(t){this._ref.strokeWidth(t)}getLineWidth(){return this._ref.strokeWidth()}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}function Ys(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}class Js{constructor(t,e=null,i=new Bs){var s,r,n;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsPosition"),i=this._ref.getAttr("wcsRadiusX"),s=this._ref.getAttr("wcsRadiusY");return t||this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),i||this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:e.x()+e.radiusX(),y:e.y()})),void(s||this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()+e.radiusY()})))}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(null!==(s=t.radius)&&void 0!==s||(t.radius={x:0,y:0}),t.radius.x=Ys(t.position,t.position2),t.position3?t.radius.y=Ys(t.position,t.position3):t.radius.x=t.radius.y):t.radius||(t.radius={x:25,y:25}),this._ref=new Ws.Ellipse({stroke:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:null!==(n=t.lineWidth)&&void 0!==n?n:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",x:t.position.x,y:t.position.y,radiusX:t.radius.x,radiusY:t.radius.y,draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t.radius.x,y:this._ref.y()})),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t.radius.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.radiusX();i&&(r*=e.scaleX);let n=this._ref.radiusY();s&&(n*=e.scaleY);r<25&&(r=25),n<25&&(n=25),t.evt.ctrlKey||t.evt.shiftKey?i?this._ref.radius({x:r,y:r}):this._ref.radius({x:n,y:n}):this._ref.radius({x:r,y:n}),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform(),e=t.point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld(e));const i=t.point({x:this._ref.x()+this._ref.radiusX(),y:this._ref.y()});this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld(i));const s=t.point({x:this._ref.x(),y:this._ref.y()+this._ref.radiusY()});this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld(s))}),this._ref.id(this._ref._id.toString())}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsPosition",this._worldTransformer.screenToWorld({x:t,y:e}))}getRadiusX(){return this._ref.radiusX()}setRadiusX(t){this._ref.radiusX(t),this._ref.setAttr("wcsRadiusX",this._worldTransformer.screenToWorld({x:this._ref.x()+t,y:this._ref.y()}))}getRadiusY(){return this._ref.radiusY()}setRadiusY(t){this._ref.radiusY(t),this._ref.setAttr("wcsRadiusY",this._worldTransformer.screenToWorld({x:this._ref.x(),y:this._ref.y()+t}))}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Ellipse"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX")),i=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));let s=this._ref.getStage().getAbsoluteTransform().copy();s=s.invert();const r=s.point({x:t.x,y:t.y});this._ref.position({x:r.x,y:r.y}),this._ref.radius({x:Math.abs(s.point(e).x-r.x),y:Math.abs(s.point(i).y-r.y)})}}class qs{constructor(t,e=null,i=new Bs){var s,r;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");return t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.points()[0],y:e.points()[1]})),void(i||this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:e.points()[2],y:e.points()[3]})))}t||(t={}),t.start||(t.start={x:0,y:0}),t.end||(t.end={x:100,y:100}),this._ref=new Ws.Arrow({stroke:null!==(s=t.color)&&void 0!==s?s:"#ff0000",fill:null!==(r=t.color)&&void 0!==r?r:"#ff0000",strokeWidth:4,globalCompositeOperation:"source-over",lineCap:"round",lineJoin:"round",points:[t.start.x,t.start.y,t.end.x,t.end.y],draggable:!0,strokeScaleEnabled:!1}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.start.x,y:t.start.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.end.x,y:t.end.y})),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.points(),s=this._ref.getAbsoluteTransform(),r=s.point({x:i[0],y:i[1]}),n=s.point({x:i[2],y:i[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(r)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(n))}),this._ref.on("dragend",t=>{const e=this._ref.points(),i=t.target.getAbsoluteTransform(),s=i.point({x:e[0],y:e[1]}),r=i.point({x:e[2],y:e[3]});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(s)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld(r))}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Arrow"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t),this._ref.fill(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPoints(){const t=this._ref.points();return[{x:t[0],y:t[1]},{x:t[2],y:t[3]}]}setPoints(t){2===t.length&&(this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t[0].x,y:t[0].y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t[1].x,y:t[1].y})),this._ref.points([t[0].x,t[0].y,t[1].x,t[1].y]))}getStartPoint(){const t=this._ref.points();return{x:t[0],y:t[1]}}setStartPoint(t,e){const i=this._ref.points();this._ref.points([t,e,i[2],i[3]]),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}))}getEndPoint(){const t=this._ref.points();return{x:t[2],y:t[3]}}setEndPoint(t,e){const i=this._ref.points();this._ref.points([i[0],i[1],t,e]),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t,y:e}))}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getAbsoluteTransform().copy();i=i.invert();const s=i.point({x:t.x,y:t.y}),r=i.point({x:e.x,y:e.y});this._ref.points([s.x,s.y,r.x,r.y])}}class Ks{constructor(t,e=null,i=new Bs){var s,r;if(this._ratio=1,this.EPSILON=1e-5,this.BASE64_HEADER_START="data:image/",this.BASE64_NOT_FOUND="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=",this._worldTransformer=i,e){e.src&&e.src.startsWith(this.BASE64_HEADER_START)||(e.src=this.BASE64_NOT_FOUND),e.height()<=this.EPSILON&&e.height(32),e.width()<=this.EPSILON&&e.width(32),this._ref=e,this._canvasImage=e.image(),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width();const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.src&&t.src.startsWith(this.BASE64_HEADER_START)||(t.src=this.BASE64_NOT_FOUND),t.position2&&(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y),this._canvasImage=new Image,this._canvasImage.onload=()=>{if(this._ref.image(this._canvasImage),this._ref.height()<=this.EPSILON&&this._ref.height(this._canvasImage.height),this._ref.width()<=this.EPSILON&&this._ref.width(this._canvasImage.width),this._ratio=this._ref.height()<=this.EPSILON||this._ref.width()<=this.EPSILON?1:this._ref.height()/this._ref.width(),(t.width<=this.EPSILON||t.height<=this.EPSILON)&&(t.maxWidth>=this.EPSILON||t.maxWidth>=this.EPSILON)){const e=t.maxHeight-this._canvasImage.height,i=t.maxWidth-this._canvasImage.width;(e<=this.EPSILON||i<=this.EPSILON)&&(i<=this.EPSILON&&i<e/this._ratio?(this._ref.height(t.maxWidth*this._ratio),this._ref.width(t.maxWidth)):(this._ref.width(t.maxHeight/this._ratio),this._ref.height(t.maxHeight)))}const e=this._worldTransformer.screenToWorld({x:t.position.x+this._ref.width(),y:t.position.y+this._ref.height()});this._ref.setAttr("wcsEnd",e)},this._canvasImage.onerror=()=>{this._canvasImage.onerror=function(){},this._canvasImage.src=this.BASE64_NOT_FOUND},this._canvasImage.src=t.src,this._ref=new Ws.Image({x:t.position.x,y:t.position.y,image:this._canvasImage,width:null!==(s=t.width)&&void 0!==s?s:0,height:null!==(r=t.height)&&void 0!==r?r:0,draggable:!0}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),t.position2&&this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),t.evt.ctrlKey||t.evt.shiftKey?i?(this._ref.width(r),this._ref.height(r*this._ratio)):(this._ref.width(n/this._ratio),this._ref.height(n)):(i&&this._ref.width(r),s&&this._ref.height(n)),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.id(this._ref._id.toString())}getSrc(){return this._canvasImage.src}setSrc(t){this._canvasImage.src=t}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t),this._ref.height(t*this._ratio);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t),this._ref.width(t/this._ratio);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Image"}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.getPosition()}setPosition(t,e){this._ref.setPosition({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}class Zs{constructor(t,e=null,i=new Bs){var s,r,n,a;if(this._worldTransformer=i,e){this._ref=e;const t=this._ref.getAttr("wcsStart"),i=this._ref.getAttr("wcsEnd");if(t||this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:e.x(),y:e.y()})),!i){const t={x:e.x()+e.width(),y:e.y()+e.height()};this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x,y:t.y}))}return}t||(t={}),t.position||(t.position={x:0,y:0}),t.position2?(t.width=t.position2.x-t.position.x,t.height=t.position2.y-t.position.y):t.width&&t.height?t.position2={x:t.position.x+t.width,y:t.position.y+t.height}:(t.position2={x:200,y:200},t.width=200,t.height=200);this._ref=new Ws.Shape({x:t.position.x,y:t.position.y,width:null!==(s=t.width)&&void 0!==s?s:200,height:null!==(r=t.height)&&void 0!==r?r:200,stroke:null!==(n=t.color)&&void 0!==n?n:"#ff0000",strokeWidth:null!==(a=t.lineWidth)&&void 0!==a?a:4,draggable:!0,strokeScaleEnabled:!1,globalCompositeOperation:"source-over",sceneFunc:(t,e)=>{const i=this._ref.width(),s=this._ref.height(),r=[{x:0,y:0},{x:0+i,y:0},{x:0+i,y:0+s},{x:0,y:0+s},{x:0,y:0}];function n(n,a){const o={x:(h={x:0,y:0}).x+i/2,y:h.y+s/2};var h;t.beginPath();for(let e=0;e<r.length-1;e++){let i=a;const s=r[e+1].x-r[e].x,h=r[e+1].y-r[e].y,l=Math.sqrt(s*s+h*h),d=Math.floor(l/i);i=a+d/(l%i);let c=r[e].x+s/d/2,u=r[e].y+h/d/2;const g=r[e+1].x,p=r[e+1].y,m=Math.atan((p-u)/(g-c)),f=m+Math.PI,_=c>o.x&&u>o.y;for(let e=0;e<d;e++)_?t.arc(c,u,n,m,f):t.arc(c,u,n,f,m),c+=s/d,u+=h/d}t.closePath(),t.fillStrokeShape(e)}i>=49||s>=49?n(8,15):i>=25||s>=25?n(4,7.5):(t.beginPath(),t.lineTo(r[1].x,r[1].y),t.lineTo(r[2].x,r[2].y),t.lineTo(r[3].x,r[3].y),t.lineTo(r[4].x,r[4].y),t.closePath(),t.fillStrokeShape(e))}}),this._ref.className="Cloud",this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t.position.x,y:t.position.y})),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.position2.x,y:t.position2.y})),this._ref.on("transform",t=>{const e=t.target.attrs,i=Math.abs(e.scaleX-1)>1e-5,s=Math.abs(e.scaleY-1)>1e-5;let r=this._ref.width();i&&(r*=e.scaleX);let n=this._ref.height();s&&(n*=e.scaleY),r<50&&(r=50),n<50&&(n=50),i&&this._ref.width(r),s&&this._ref.height(n),this._ref.scale({x:1,y:1})}),this._ref.on("transformend",t=>{const e=t.target.attrs;e.rotation!==this._ref.rotation()&&this._ref.rotation(e.rotation);const i=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(i)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:i.x+this._ref.width(),y:i.y+this._ref.height()}))}),this._ref.on("dragend",()=>{const t=this._ref.getStage().getAbsoluteTransform().point({x:this._ref.x(),y:this._ref.y()});this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld(t)),this._ref.setAttr("wcsEnd",this._worldTransformer.screenToWorld({x:t.x+this._ref.width(),y:t.y+this._ref.height()}))}),this._ref.getSelfRect=()=>({x:-8,y:-8,width:this._ref.width()+16,height:this._ref.height()+16}),this._ref.id(this._ref._id.toString())}ref(){return this._ref}id(){return this._ref.id()}enableMouseEditing(t){this._ref.draggable(t)}type(){return"Cloud"}getColor(){return this._ref.stroke()}setColor(t){this._ref.stroke(t)}getRotation(){return this._ref.rotation()}setRotation(t){this._ref.rotation(t)}getZIndex(){return this._ref.zIndex()}setZIndex(t){this._ref.zIndex(t)}delete(){this._ref.destroy(),this._ref=null}getPosition(){return this._ref.position()}setPosition(t,e){this._ref.position({x:t,y:e}),this._ref.setAttr("wcsStart",this._worldTransformer.screenToWorld({x:t,y:e}));const i={x:t+this._ref.width(),y:e+this._ref.y()},s=this._worldTransformer.screenToWorld(i);this._ref.setAttr("wcsEnd",s)}getWidth(){return this._ref.width()}setWidth(t){this._ref.width(t);const e={x:this._ref.x()+t,y:this._ref.y()+this._ref.height()},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getHeight(){return this._ref.height()}setHeight(t){this._ref.height(t);const e={x:this._ref.x()+this._ref.width(),y:this._ref.y()+t},i=this._worldTransformer.screenToWorld(e);this._ref.setAttr("wcsEnd",i)}getLineWidth(){return this._ref.strokeWidth()}setLineWidth(t){this._ref.strokeWidth(t)}updateScreenCoordinates(){const t=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart")),e=this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));let i=this._ref.getStage().getAbsoluteTransform().copy();i=i.invert();const s=i.point(t),r=i.point(e);this._ref.position({x:s.x,y:s.y}),this._ref.width(Math.abs(r.x-s.x)),this._ref.height(Math.abs(r.y-s.y))}}const $s={SelectMarkup:{name:"SelectMarkup",initializer:null},Line:{name:"Line",initializer:(t,e=null,...i)=>new Hs(e,t,...i)},Text:{name:"Text",initializer:(t,e=null,...i)=>new Us(e,t,...i)},Rectangle:{name:"Rect",initializer:(t,e=null,...i)=>new Xs(e,t,...i)},Ellipse:{name:"Ellipse",initializer:(t,e=null,...i)=>new Js(e,t,...i)},Arrow:{name:"Arrow",initializer:(t,e=null,...i)=>new qs(e,t,...i)},Image:{name:"Image",initializer:(t,e=null,...i)=>new Ks(e,t,...i)},Cloud:{name:"Cloud",initializer:(t,e=null,...i)=>new Zs(e,t,...i)}};class Qs{constructor(){this._markupIsActive=!1,this._markupColor=new Ns(255,0,0),this.lineWidth=4,this.lineType="solid",this.fontSize=34,this.changeActiveDragger=t=>{const e=t.data;this._markupContainer.className=this._container.className.split(" ").filter(t=>!t.startsWith("oda-cursor-")).filter(t=>t).concat(`oda-cursor-${e.toLowerCase()}`).join(" "),this.removeTextInput(),this.removeImageInput(),this.enableEditMode(e)},this.resizeContainer=()=>{const{offsetLeft:t,offsetTop:e,offsetWidth:i,offsetHeight:s}=this._container;i&&s&&(this._markupContainer.style.left=`${t}px`,this._markupContainer.style.top=`${e}px`,this._konvaStage.width(i),this._konvaStage.height(s),this.getObjects().forEach(t=>{t.updateScreenCoordinates()}))},this.pan=()=>{this.updateScreenCoordinatesForAll()},this.zoomAt=()=>{this.updateScreenCoordinatesForAll()},this.changeCameraMode=()=>{this.clearOverlay()},this.redirectToViewer=t=>{this._viewer&&this._viewer.emit(t)},this.getRelativePointPosition=(t,e)=>{const i=e.getAbsoluteTransform().copy();return i.invert(),i.point(t)},this.getRelativePointerPosition=t=>this.getRelativePointPosition(t.getStage().getPointerPosition(),t)}initialize(t,e,i,s){this._viewer=i,this._worldTransformer=null!=s?s:new Bs,this._container=t,this._markupContainer=document.createElement("div"),this._markupContainer.id="markup-container",this._markupContainer.style.position="absolute",this._markupContainer.style.outline="0px",this._markupContainer.style.pointerEvents="none";this._container.parentElement.appendChild(this._markupContainer),this._markupColor.setColor(255,0,0),this.initializeKonva(),this._resizeObserver=new ResizeObserver(this.resizeContainer),this._resizeObserver.observe(t),this._viewer&&(this._viewer.addEventListener("changeactivedragger",this.changeActiveDragger),this._viewer.addEventListener("pan",this.pan),this._viewer.addEventListener("zoomat",this.zoomAt),this._viewer.addEventListener("changecameramode",this.changeCameraMode))}dispose(){var t,e;this._viewer&&(this._viewer.removeEventListener("changecameramode",this.changeCameraMode),this._viewer.removeEventListener("zoomat",this.zoomAt),this._viewer.removeEventListener("pan",this.pan),this._viewer.removeEventListener("changeactivedragger",this.changeActiveDragger)),null===(t=this._resizeObserver)||void 0===t||t.disconnect(),this._resizeObserver=void 0,this.destroyKonva(),null===(e=this._markupContainer)||void 0===e||e.remove(),this._markupContainer=void 0,this._container=void 0,this._viewer=void 0,this._worldTransformer=void 0,this._markupIsActive=!1}syncOverlay(){}clearOverlay(){this.removeTextInput(),this.removeImageInput(),this.clearSelected(),this.getObjects().forEach(t=>t.delete())}getMarkupColor(){return this._markupColor.asRGB()}setMarkupColor(t,e,i){this._markupColor.setColor(t,e,i),this.redirectToViewer({type:"changemarkupcolor",data:{r:t,g:e,b:i}})}colorizeAllMarkup(t,e,i){this.setMarkupColor(t,e,i);const s=new Ns(t,e,i).asHex();this.getObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}colorizeSelectedMarkups(t,e,i){const s=new Ns(t,e,i).asHex();this.getSelectedObjects().filter(t=>{var e;return null===(e=t.setColor)||void 0===e?void 0:e.call(t,s)})}setViewpoint(t){var e,i,s,r,n,a,o,h;this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._konvaStage.scale({x:1,y:1}),this._konvaStage.position({x:0,y:0});const l=(null===(e=t.custom_fields)||void 0===e?void 0:e.markup_color)||{r:255,g:0,b:0};this.setMarkupColor(l.r,l.g,l.b),null===(i=t.lines)||void 0===i||i.forEach(t=>{const e=[];t.points.forEach(t=>{const i=this._worldTransformer.worldToScreen(t);e.push(i.x),e.push(i.y)}),this.addLine(e,t.color,t.type,t.width,t.id)}),null===(s=t.texts)||void 0===s||s.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position);this.addText(t.text,e,t.angle,t.color,t.text_size,t.font_size,t.id)}),null===(r=t.rectangles)||void 0===r||r.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addRectangle(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(n=t.ellipses)||void 0===n||n.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null,s=t.position3?this._worldTransformer.worldToScreen(t.position3):null;this.addEllipse(e,i,s,t.radius,t.line_width,t.color,t.id)}),null===(a=t.arrows)||void 0===a||a.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.start),i=this._worldTransformer.worldToScreen(t.end);this.addArrow(e,i,t.color,t.id)}),null===(o=t.clouds)||void 0===o||o.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addCloud(e,i,t.width,t.height,t.line_width,t.color,t.id)}),null===(h=t.images)||void 0===h||h.forEach(t=>{const e=this._worldTransformer.worldToScreen(t.position),i=t.position2?this._worldTransformer.worldToScreen(t.position2):null;this.addImage(e,i,t.src,t.width,t.height,t.id)})}getViewpoint(t){return t||(t={}),t.lines=this.getMarkupLines(),t.texts=this.getMarkupTexts(),t.arrows=this.getMarkupArrows(),t.clouds=this.getMarkupClouds(),t.ellipses=this.getMarkupEllipses(),t.images=this.getMarkupImages(),t.rectangles=this.getMarkupRectangles(),t.custom_fields={markup_color:this.getMarkupColor()},t.snapshot={data:this.combineMarkupWithDrawing()},t}enableEditMode(t){return t&&$s[t]?(this._markupMode=t,this._markupContainer.style.pointerEvents="all",this._markupIsActive=!0):(this.clearSelected(),this.removeTextInput(),this.removeImageInput(),this._markupContainer.style.pointerEvents="none",this._markupIsActive=!1),this}createObject(t,e){const i=$s[t];if(!i||!i.initializer)throw new Error(`Markup CreateObject - unsupported markup type ${t}`);const s=i.initializer(null,e,this._worldTransformer);return this.addObject(s),s}getObjects(){const t=[];return Object.keys($s).forEach(e=>{const i=$s[e];this.konvaLayerFind(e).forEach(e=>t.push(i.initializer(e,null,this._worldTransformer)))}),t}getSelectedObjects(){return this._konvaTransformer?this._konvaTransformer.nodes().map(t=>{const e=t.className,i=Object.values($s).find(t=>t.name===e);return i?i.initializer(t,null,this._worldTransformer):null}).filter(t=>t):[]}selectObjects(t){if(!this._konvaTransformer)return;const e=this._konvaTransformer.nodes().concat(t.map(t=>t.ref()));this._konvaTransformer.nodes(e)}clearSelected(){this._konvaTransformer&&this._konvaTransformer.nodes([])}addObject(t){"Image"===t.type()?this._groupImages.add(t.ref()):"Text"===t.type()?this._groupTexts.add(t.ref()):this._groupGeometry.add(t.ref())}konvaLayerFind(t){if(!this._konvaLayer)return[];const e=$s[t];return e&&e.initializer?this._konvaLayer.find(e.name).filter(t=>t.parent===this._konvaLayer||t.parent===this._groupImages||t.parent===this._groupGeometry||t.parent===this._groupTexts):[]}updateScreenCoordinatesForAll(){this.getObjects().forEach(t=>{t.updateScreenCoordinates()})}initializeKonva(){const t=new Ws.Stage({container:this._markupContainer,width:this._container.clientWidth,height:this._container.clientHeight});this._konvaStage=t;const e=new Ws.Layer({pixelRation:window.devicePixelRatio});t.add(e),this._groupImages=new Ws.Group,e.add(this._groupImages),this._groupGeometry=new Ws.Group,e.add(this._groupGeometry),this._groupTexts=new Ws.Group,e.add(this._groupTexts),this._konvaLayer=e;const i=new Ws.Transformer({shouldOverdrawWholeArea:!1,keepRatio:!1,flipEnabled:!1});e.add(i),this._konvaTransformer=i;let s,r,n,a=!1;t.on("mousedown touchstart",e=>{if(!this._markupIsActive||e.target!==t||"Text"===this._markupMode||"Image"===this._markupMode)return;if(e.target===t&&i.nodes().length>0)return void i.nodes([]);const n=this.getRelativePointerPosition(t);r=n,a=["Arrow","Cloud","Ellipse","Line","Rectangle"].some(t=>t===this._markupMode),"Line"===this._markupMode&&(s=this.addLine([n.x,n.y,n.x,n.y]))}),t.on("mouseup touchend",()=>{if(this._markupIsActive){if(a){const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,s=i?r.x:Math.min(r.x,e.x),n=i?r.y:Math.min(r.y,e.y),a=i?200:Math.abs(r.x-e.x),o=i?200:Math.abs(r.y-e.y);i&&("Rectangle"===this._markupMode?this.addRectangle({x:s,y:n},null,a,o):"Ellipse"===this._markupMode?this.addEllipse({x:s,y:n},null,null,{x:a/2,y:o/2}):"Arrow"===this._markupMode?this.addArrow({x:r.x,y:r.y},{x:i?r.x+200:e.x,y:i?n:e.y}):"Cloud"===this._markupMode&&this.addCloud({x:s,y:n},null,Math.max(100,a),Math.max(100,o)))}n=void 0,a=!1}}),t.on("mousemove touchmove",()=>{if(!this._markupIsActive)return;if(!a)return;const e=this.getRelativePointerPosition(t),i=r&&e.x===r.x&&e.y===r.y,o=i?r.x:Math.min(r.x,e.x),h=i?r.y:Math.min(r.y,e.y),l=i?200:Math.abs(r.x-e.x),d=i?200:Math.abs(r.y-e.y);"Line"===this._markupMode?s.addPoints([{x:e.x,y:e.y}]):"Arrow"===this._markupMode?n?n.setEndPoint(e.x,e.y):n=this.addArrow({x:r.x,y:r.y},{x:e.x,y:e.y}):"Rectangle"===this._markupMode?n?(n.setPosition(o,h),n.setWidth(l),n.setHeight(d)):n=this.addRectangle({x:o,y:h},null,l,d):"Ellipse"===this._markupMode?n?(n.setPosition(o,h),n.setRadiusX(l),n.setRadiusY(d)):n=this.addEllipse({x:o,y:h},null,null,{x:l,y:d}):"Cloud"===this._markupMode&&(n?(n.setPosition(o,h),n.setWidth(Math.max(100,l)),n.setHeight(Math.max(100,d))):n=this.addCloud({x:o,y:h},null,l,d))}),t.on("click tap",e=>{if(!this._markupIsActive)return;if(e.target===t){if("Text"===this._markupMode){if(this._textInputRef&&this._textInputRef.value)this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle);else if(0===i.nodes().length){const i=this.getRelativePointerPosition(t);this.createTextInput(i,e.evt.pageX,e.evt.pageY,0,null)}}else if("Image"===this._markupMode)if(this._imageInputRef&&this._imageInputRef.value)this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,this._imageInputRef.value,0,0,this._imageInputRef.value);else if(0===i.nodes().length){const e=this.getRelativePointerPosition(t);this.createImageInput(e)}return void i.nodes([])}if("Text"===this._markupMode||"SelectMarkup"===this._markupMode){if("Text"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._textInputRef&&this._textInputRef.value?this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle):this.createTextInput({x:e.target.attrs.x,y:e.target.attrs.y},e.evt.pageX,e.evt.pageY,e.target.attrs.rotation,e.target.attrs.text));this.removeTextInput()}if("Image"===this._markupMode||"SelectMarkup"===this._markupMode){if("Image"===e.target.className&&1===i.nodes().length&&i.nodes()[0]===e.target)return void(this._imageInputRef&&this._imageInputRef.value?this.addImage(this._imageInputPos,null,this._imageInputRef.value,0,0):this.createImageInput({x:e.target.attrs.x,y:e.target.attrs.y}));this.removeImageInput()}i.nodes().filter(t=>"Cloud"===t.className||"Image"===t.className).length>0||"Cloud"===e.target.className||"Image"===e.target.className?i.rotateEnabled(!1):i.rotateEnabled(!0);const s=e.evt.shiftKey||e.evt.ctrlKey||e.evt.metaKey,r=i.nodes().indexOf(e.target)>=0;if(s||r){if(s&&r){const t=i.nodes().slice();t.splice(t.indexOf(e.target),1),i.nodes(t)}else if(s&&!r){const t=i.nodes().concat([e.target]);i.nodes(t)}}else i.nodes([e.target])});const o=t.container();o.tabIndex=1,o.focus(),o.addEventListener("keydown",t=>{if(this._markupIsActive)return"Delete"===t.code?(this.getSelectedObjects().forEach(t=>t.delete()),void this.clearSelected()):void t.preventDefault()})}destroyKonva(){var t;this.removeTextInput(),this.removeImageInput(),this.clearOverlay(),null===(t=this._konvaStage)||void 0===t||t.destroy(),this._groupImages=void 0,this._groupGeometry=void 0,this._groupTexts=void 0,this._konvaLayer=void 0,this._konvaTransformer=void 0,this._konvaStage=void 0}getMarkupLines(){const t=[];return this.konvaLayerFind("Line").forEach(e=>{const i=e.getAttr("wcsPoints");if(!i)return;const s=new Hs(null,e,this._worldTransformer),r={id:s.id(),points:i,color:s.getColor()||"#ff0000",type:s.getLineType()||this.lineType,width:s.getLineWidth()||this.lineWidth};t.push(r)}),t}getMarkupTexts(){const t=[];return this.konvaLayerFind("Text").forEach(e=>{const i=this._worldTransformer.getScale(),s=e.getAttr("wcsStart"),r=this._konvaStage.getAbsoluteTransform(),n=new Us(null,e,this._worldTransformer),a={id:n.id(),position:s,text:n.getText(),text_size:.02*i.y,angle:n.getRotation(),color:n.getColor(),font_size:n.getFontSize()*r.getMatrix()[0]};t.push(a)}),t}getMarkupRectangles(){const t=[];return this.konvaLayerFind("Rectangle").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),a=new Xs(null,e,this._worldTransformer),o={id:a.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:a.getLineWidth(),color:a.getColor()};t.push(o)}),t}getMarkupEllipses(){const t=[];return this.konvaLayerFind("Ellipse").forEach(e=>{const i=e.getAttr("wcsPosition"),s=e.getAttr("wcsRadiusX"),r=e.getAttr("wcsRadiusY"),n=this._konvaStage.getAbsoluteTransform().getMatrix()[0],a=new Js(null,e,this._worldTransformer),o={id:a.id(),position:i,position2:s,position3:r,radius:{x:e.getRadiusX()*n,y:e.getRadiusY()*n},line_width:a.getLineWidth(),color:a.getColor()};t.push(o)}),t}getMarkupArrows(){const t=[];return this.konvaLayerFind("Arrow").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=new qs(null,e,this._worldTransformer),n={id:r.id(),start:i,end:s,color:r.getColor()};t.push(n)}),t}getMarkupImages(){const t=[];return this.konvaLayerFind("Image").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._konvaStage.getAbsoluteTransform().getMatrix()[0],n=new Ks(null,e,this._worldTransformer),a={id:n.id(),position:i,position2:s,src:n.getSrc(),width:n.getWidth()*r,height:n.getHeight()*r};t.push(a)}),t}getMarkupClouds(){const t=[];return this.konvaLayerFind("Cloud").forEach(e=>{const i=e.getAttr("wcsStart"),s=e.getAttr("wcsEnd"),r=this._worldTransformer.worldToScreen(i),n=this._worldTransformer.worldToScreen(s),a=new Zs(null,e,this._worldTransformer),o={id:a.id(),position:i,position2:s,width:Math.abs(r.x-n.x),height:Math.abs(r.y-n.y),line_width:a.getLineWidth(),color:a.getColor()};t.push(o)}),t}combineMarkupWithDrawing(){this.clearSelected();const t=document.createElement("canvas");if(this._konvaStage){t.width=this._konvaStage.width(),t.height=this._konvaStage.height();const e=t.getContext("2d");this._container instanceof HTMLCanvasElement&&e.drawImage(this._container,0,0),e.drawImage(this._konvaStage.toCanvas({pixelRatio:window.devicePixelRatio}),0,0)}return t.toDataURL("image/jpeg",.25)}addLine(t,e,i,s,r){if(!t||0===t.length)return;const n=[];for(let e=0;e<t.length;e+=2)n.push({x:t[e],y:t[e+1]});const a=new Hs({points:n,type:i||this.lineType,width:s||this.lineWidth,color:e||this._markupColor.asHex(),id:r},null,this._worldTransformer);return this.addObject(a),a}createTextInput(t,e,i,s,r){this._textInputRef?this.removeTextInput():(this._textInputPos=t,this._textInputAngle=s,this._textInputRef=document.createElement("textarea"),this._textInputRef.style.zIndex="9999",this._textInputRef.style.position="absolute",this._textInputRef.style.display="block",this._textInputRef.style.top=i+"px",this._textInputRef.style.left=e+"px",this._textInputRef.style.fontSize=`${this.fontSize}px`,this._textInputRef.style.color=`${this._markupColor.asHex()}`,this._textInputRef.style.fontFamily="Calibri",this._textInputRef.onkeydown=t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.addText(this._textInputRef.value,this._textInputPos,this._textInputAngle)),"Escape"===t.key&&(t.preventDefault(),this.removeTextInput())},r&&(this._textInputRef.value=r),document.body.appendChild(this._textInputRef),setTimeout(()=>{this._textInputRef.focus()},50))}removeTextInput(){var t;null===(t=this._textInputRef)||void 0===t||t.remove(),this._textInputRef=null,this._textInputPos=null,this._textInputAngle=0}createImageInput(t){if(this._imageInputRef)this.removeImageInput();else{const e=t=>new Promise((e,i)=>{const s=new FileReader;s.readAsDataURL(t),s.onload=()=>{e(s.result)},s.onerror=t=>{i(t)}});this._imageInputPos=t,this._imageInputRef=document.createElement("input"),this._imageInputRef.style.display="none",this._imageInputRef.type="file",this._imageInputRef.accept="image/png, image/jpeg",this._imageInputRef.onchange=async t=>{const i=t.target.files[0],s=await e(i);this.addImage({x:this._imageInputPos.x,y:this._imageInputPos.y},null,s.toString(),0,0)},this._imageInputRef.oncancel=()=>{this.removeImageInput()},document.body.appendChild(this._imageInputRef),setTimeout(()=>{this._imageInputRef.click()},50)}}removeImageInput(){var t;null===(t=this._imageInputRef)||void 0===t||t.remove(),this._imageInputRef=null,this._imageInputPos=null}addText(t,e,i,s,r,n,a){var o;if(!t)return;null===(o=this.getSelectedObjects().shift())||void 0===o||o.delete(),this.clearSelected(),this.removeTextInput();const h=1e-6;if(r&&r>h&&(!n||n<h)){const t=.02;n=r/(this._worldTransformer.getScale().y/t)/34}const l=new Us({position:{x:e.x,y:e.y},text:t,rotation:i,fontSize:n||this.fontSize,color:s||this._markupColor.asHex(),id:a},null,this._worldTransformer);return this.addObject(l),l}addRectangle(t,e,i,s,r,n,a){if(!t)return;const o=new Xs({position:t,position2:e,width:i,height:s,lineWidth:r||this.lineWidth,color:n||this._markupColor.asHex(),id:a},null,this._worldTransformer);return this.addObject(o),o}addEllipse(t,e,i,s,r,n,a){if(!t)return;const o=new Js({position:t,position2:e,position3:i,radius:s,lineWidth:r,color:n||this._markupColor.asHex(),id:a},null,this._worldTransformer);return this.addObject(o),o}addArrow(t,e,i,s){if(!t||!e)return;const r=new qs({start:t,end:e,color:i||this._markupColor.asHex(),id:s},null,this._worldTransformer);return this.addObject(r),r}addCloud(t,e,i,s,r,n,a){if(!t||!i||!s)return;const o=new Zs({position:t,position2:e,width:i,height:s,color:n||this._markupColor.asHex(),lineWidth:r||this.lineWidth,id:a},null,this._worldTransformer);return this.addObject(o),o}addImage(t,e,i,s,r,n){var a;if(!t||!i)return;null===(a=this.getSelectedObjects().shift())||void 0===a||a.delete(),this.clearSelected(),this.removeImageInput();const o=new Ks({position:t,position2:e,src:i,width:s,height:r,maxWidth:this._konvaStage.width()-t.x,maxHeight:this._konvaStage.height()-t.y,id:n},null,this._worldTransformer);return this.addObject(o),o}}const tr="$MarkupTempEntity_Line";class er extends w{constructor(t){super(t),this.press=!1}dispose(){super.dispose(),this.end(),this.points=null,this.drawPoints=null}start(t,e){const i=this.getViewer().screenToWorld(t,e);this.drawPoints=[i[0],i[1],i[2]]}drag(t,e){if(this.isDragging){const i=this.getViewer().screenToWorld(t,e);this.drawPoints.push(i[0],i[1],i[2]),this._updateFrame()}}end(){this.entity&&(this.entity.delete(),this.drawPoints=null,this.entity=null)}_updateFrame(){if(this.entity){const t=this.getViewer().getMarkupModel();t.removeEntity(this.entity),t.delete(),this.entity.delete()}this.entity=this.getActiveMarkupEntity(tr);const t=this.entity.openObject();t.appendPolyline(this.drawPoints).delete(),t.delete()}}const ir="$MarkupTempEntity_Text";class sr extends w{constructor(t){super(t),this.TEXT_HEIGHT_ALIGN=24,this.press=!1}dispose(){var t;super.dispose(),null===(t=this.textRef)||void 0===t||t.remove(),this.textRef=null}_finishInput(){var t;this.textRef&&this.textRef.value.trimLeft()&&this._updateFrame(),null===(t=this.textRef)||void 0===t||t.remove(),this.textRef=null}start(t,e,i,s){this.textRef?this._finishInput():(this.textRef=document.createElement("textarea"),this.textRef.style.zIndex="9999",this.textRef.style.position="absolute",this.textRef.style.display="block",this.textRef.style.top=s+"px",this.textRef.style.left=i+"px",this.textRef.onkeypress=t=>{"Enter"===t.key&&(t.preventDefault(),this._finishInput())},document.body.appendChild(this.textRef),this.press=!0,this.m_center=this.screenToWorld(t,e+this.TEXT_HEIGHT_ALIGN),this.needInputText=!0)}_updateFrame(){this.entity=this.getActiveMarkupEntity(ir);const t=this.entity.openObject(),e=this.getViewer().activeView,i=this.toPoint(e.viewPosition),s=this.toPoint(e.viewTarget),r=e.eyeToWorldMatrix,n=i.sub(s).asVector(),a=this.toVector([1,0,0]).transformBy(r),o=this.createMatrix3d();o.setToWorldToPlane(this.toGeVector(n)),a.transformBy(o);const h=-Math.atan2(-a.y,a.x);let l=1;const d=e.projectionMatrix.get(1,1),c=1e-6;d<c&&d>-c||(l=1/d);const u=t.appendText(this.toGePoint(this.m_center),this.textRef.value.trimLeft()),g=u.openAsText();g.setNormal(this.toGeVector(n)),g.setRotation(h),g.setTextSize(.02*l),g.delete(),u.delete(),t.delete()}}class rr{constructor(){this._markupColor={r:255,g:0,b:0},this.lineWidth=4,this.fontSize=34}initialize(t,e,i,s){this._viewer=i,this._viewer.registerDragger("Line",er),this._viewer.registerDragger("Text",sr)}dispose(){}syncOverlay(){}clearOverlay(){if(!this._viewer.visualizeJs)return;const t=this._viewer.visViewer().getMarkupModel();t.clearEntities(),t.delete()}getMarkupColor(){return this._markupColor}setMarkupColor(t,e,i){const s={r:t,g:e,b:i};this._markupColor=s,this._viewer.emitEvent({type:"changemarkupcolor",data:s})}colorizeAllMarkup(t=255,e=0,i=0){if(!this._viewer.visualizeJs)return;const s=this._viewer.visViewer().getMarkupModel().getEntitiesIterator();for(;!s.done();s.step()){const r=s.getEntity().openObject(),n=r.getName();n!==tr&&n!==ir||r.setColor(t,e,i),r.delete()}s.delete(),this._viewer.update()}colorizeSelectedMarkups(t=255,e=0,i=0){throw new Error("Not implemented yet")}setViewpoint(t){function e(t){return[t.x,t.y,t.z]}function i(t,e){return t.Point3d.createFromArray(e)}if(!this._viewer.visualizeJs)return;const s=this._viewer.visLib(),r=this._viewer.visViewer().activeView;this._viewer.syncOverlay();const n=t.custom_fields.markup_color||{r:255,g:0,b:0};if(this.setMarkupColor(n.r,n.g,n.b),t.lines)for(const e of t.lines){const t=this._viewer.addMarkupEntity(tr).openObject(),i=[];for(const t of e.points)i.push(t.x,t.y,t.z);t.appendPolyline(i).delete(),t.delete()}if(t.texts){const n=i(s,r.viewPosition),a=i(s,r.viewTarget),o=n.sub(a).asVector();for(const i of t.texts){const t=this._viewer.addMarkupEntity(ir).openObject(),s=t.appendText(e(i.position),i.text),r=s.openAsText();r.setNormal(e(o)),r.setRotation(i.angle),r.setTextSize(i.text_size),r.delete(),s.delete(),t.delete()}}this._viewer.update()}getViewpoint(t){if(!this._viewer.visualizeJs)return{};function e(t){return{x:t[0],y:t[1],z:t[2]}}const i=this._viewer.visLib(),s=this._viewer.visViewer();t||(t={}),t.lines=[],t.texts=[];const r=s.getMarkupModel().getEntitiesIterator();for(;!r.done();r.step()){const i=r.getEntity().openObject(),s=i.getName(),n=i.getGeometryDataIterator();if(n.done()){i.delete();continue}const a=n.getGeometryData();if(s===tr){const i=a.openAsPolyline(),s=i.getPoints(),r={points:[]};for(const t of s)r.points.push(e(t));t.lines.push(r),i.delete()}else if(s===ir){const i=a.openAsText(),s={position:e(i.getPosition()),text:i.getString(),angle:i.getRotation(),text_size:i.getTextSize()};t.texts.push(s),i.delete()}i.delete()}return r.delete(),t.snapshot={data:i.canvas.toDataURL("image/jpeg",.25)},t.custom_fields={markup_color:this.getMarkupColor()},t}enableEditMode(t){return this}createObject(t,e){}getObjects(){return[]}getSelectedObjects(){return[]}selectObjects(t){}clearSelected(){}}class nr{static createMarkup(t="Konva"){let e;switch(t){case"Konva":e=new Qs;break;case"Visualize":e=new rr;break;default:throw new Error(`Unknown Markup type: ${t}`)}return e}}const ar="$OVERLAY_VIEW_NAME",or=t=>null!=t;t.CANVAS_EVENTS=_,t.CanvasEvents=f,t.Component=class{constructor(t){this.name=""}dispose(){}},t.Dragger=class{constructor(t){this.name=""}dispose(){}},t.FileLoader=ct,t.Info=v,t.Loader=d,t.Markup=Qs,t.OdBaseDragger=w,t.Options=m,t.Viewer=class extends xt{constructor(t,e={}){var i;super(),this._visualizeJsUrl="",this.configure(e),this.client=t,this.options=new m(this),this.loaders=[],this.models=[],this.info=new v,this.canvasEvents=_.slice(),this.canvaseventlistener=t=>this.emit(t),this._activeDragger=null,this._components=[],this._renderNeeded=!1,this._renderTime=0,this._enableAutoUpdate=null===(i=e.enableAutoUpdate)||void 0===i||i,this._isRunAsyncUpdate=!1,this.render=this.render.bind(this),this.update=this.update.bind(this),this._markup=nr.createMarkup(e.markupType)}get visualizeJsUrl(){return this._visualizeJsUrl}get visualizeJs(){return this._visualizeJs}visLib(){return this._visualizeJs}visViewer(){return this._viewer}get markup(){return this._markup}configure(t){return this._visualizeJsUrl=t.visualizeJsUrl||"https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js",this._crossOrigin=t.crossOrigin,this}get draggers(){return[...q.getDraggers().keys()]}get components(){return[...lt.getComponents().keys()]}async initialize(t,e){this.addEventListener("optionschange",t=>this.syncOptions(t.data));const i=window.devicePixelRatio,s=t.parentElement.getBoundingClientRect(),r=s.width||1,n=s.height||1;t.width=Math.round(r*i),t.height=Math.round(n*i),t.style.width=r+"px",t.style.height=n+"px",t.parentElement.style.touchAction="none",t.style.touchAction="none",this._visualizeTimestamp=Date.now();const a=this._visualizeTimestamp,o=await(async(t,e,i={})=>{const s=await bt(t,i);return await new Promise((i,r)=>{const n={urlMemFile:t+".wasm",TOTAL_MEMORY:134217728,onprogress:e},a=window.getVisualizeLibInst(n);a.loadWasmError=r,a.postRun.push(()=>{window.getVisualizeLibInst.script=s,i(a)})})})(this.visualizeJsUrl,t=>{const{loaded:i,total:s}=t;e&&e(new ProgressEvent("progress",{lengthComputable:!0,loaded:i,total:s})),this.emitEvent({type:"initializeprogress",data:i/s,loaded:i,total:s})},{crossOrigin:this._crossOrigin});if(a!==this._visualizeTimestamp)throw new Error("Viewer error: dispose() was called before initialize() completed. Are you using React strict mode?");this._visualizeJs=o,this._visualizeJs.canvas=t,this._viewer=o.Viewer.create(),this._viewer.resize(0,t.width,t.height,0),this.canvas=t,this.canvasEvents.forEach(e=>t.addEventListener(e,this.canvaseventlistener)),this._markup.initialize(this.canvas,this.canvasEvents,this,this);for(const t of lt.getComponents().keys())this._components.push(lt.createComponent(t,this));return this.syncOptions(),this.syncOverlay(),this._renderTime=performance.now(),this.render(this._renderTime),this.emitEvent({type:"initialize"}),this}dispose(){return this.cancel(),this.clear(),this.emitEvent({type:"dispose"}),this.removeAllListeners(),this.setActiveDragger(),this._components.forEach(t=>t.dispose()),this._components=[],this._markup.dispose(),this.canvas&&(this.canvasEvents.forEach(t=>this.canvas.removeEventListener(t,this.canvaseventlistener)),this.canvas=void 0),this._viewer&&this._viewer.clear(),this._visualizeJs=void 0,this._visualizeTimestamp=void 0,this._viewer=void 0,this}isInitialized(){return!!this.visualizeJs}setSize(t,e,i=!0){this.visualizeJs&&(this.canvas.width=Math.round(t*window.devicePixelRatio),this.canvas.height=Math.round(e*window.devicePixelRatio),i&&(this.canvas.style.width=t+"px",this.canvas.style.height=e+"px"),this._viewer.resize(0,this.canvas.width,this.canvas.height,0),this.update(!0),this.emitEvent({type:"resize",width:t,height:e}))}resize(){if(console.warn("Viewer.resize() has been deprecated since 26.9 and will be removed in a future release, use Viewer.setSize() instead."),!this.visualizeJs)return this;if(!this.canvas.parentElement)return this;const{width:t,height:e}=this.canvas.parentElement.getBoundingClientRect();return t&&e?(this.setSize(t,e),this):this}update(t=!1){this._enableAutoUpdate&&(this._renderNeeded=!0,t&&this.render()),this.emitEvent({type:"update",data:t})}render(t){var e,i;if(!this.visualizeJs)return;if(this._isRunAsyncUpdate)return;if(!(this.visViewer().isRunningAnimation()||this._renderNeeded))return;t||(t=performance.now());const s=(t-this._renderTime)/1e3;this._renderTime=t,this._renderNeeded=!this.visViewer().getActiveDevice().isValid(),this.visViewer().update(),null===(i=null===(e=this._activeDragger)||void 0===e?void 0:e.updatePreview)||void 0===i||i.call(e),this.emitEvent({type:"render",time:t,deltaTime:s})}async loadReferences(t){var e;if(!this.visualizeJs)return this;if(!this.client)return this;if(!t.getReferences)return this;const i=new AbortController;null===(e=this._abortControllerForReferences)||void 0===e||e.abort(),this._abortControllerForReferences=i;let s=[];await t.getReferences(i.signal).then(t=>s=t.references).catch(t=>console.error("Cannot load model references.",t));for(const t of s)await this.client.downloadFile(t.id,void 0,i.signal).then(e=>{var i;return null===(i=this.visualizeJs)||void 0===i?void 0:i.getViewer().addEmbeddedFile(t.name,new Uint8Array(e))}).catch(e=>console.error(`Cannot load reference file ${t.name}.`,e));return this}applyModelTransformMatrix(t){this.executeCommand("applyModelTransform",t)}applySceneGraphSettings(t=this.options){if(!this.visualizeJs)return;const e=this.visLib(),i=this.visViewer().getActiveDevice();or(t.sceneGraph)&&i.setOptionBool(e.DeviceOptions.kDelaySceneGraphProc,!t.sceneGraph),i.delete(),this.update()}async open(t,e={}){if(!this.visualizeJs)return this;this.cancel(),this.clear(),this.emitEvent({type:"open",mode:"file",file:t});let i=t;if(i&&"function"==typeof i.getModels){const e=await i.getModels();i=e.find(t=>t.default)||e[0]||t}if(i&&"string"==typeof i.database&&(t=i.file),!i)throw new Error("Format not supported");let s=e.format;s||"string"!=typeof t.type||(s=t.type.split(".").pop()),s||"string"!=typeof t||(s=t.split(".").pop()),!s&&t instanceof globalThis.File&&(s=t.name.split(".").pop());const r=wt.createLoader(this,i,s);if(!r)throw new Error("Format not supported");this.loaders.push(r),this.emitEvent({type:"geometrystart",file:t,model:i});try{await this.loadReferences(i),await r.load(i,s,e)}catch(e){throw this.emitEvent({type:"geometryerror",data:e,file:t,model:i}),e}return this.emitEvent({type:"geometryend",file:t,model:i}),this.visualizeJs&&(this.applyModelTransformMatrix(i),this.applySceneGraphSettings()),this}openVsfFile(t){if(console.warn("Viewer.openVsfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead."),!this.visualizeJs)return this;this.cancel(),this.clear(),this.emitEvent({type:"open",mode:"file",file:"",buffer:t});const e=this.visViewer();this.emitEvent({type:"geometrystart",file:"",buffer:t});try{const i=t instanceof Uint8Array?t:new Uint8Array(t);e.parseFile(i),this.syncOptions(),this.syncOverlay(),this.update(!0),this.emitEvent({type:"geometryprogress",data:1,file:"",buffer:t}),this.emitEvent({type:"databasechunk",data:i,file:"",buffer:t})}catch(e){throw this.emitEvent({type:"geometryerror",data:e,file:"",buffer:t}),e}return this.emitEvent({type:"geometryend",file:"",buffer:t}),this}openVsfxFile(t){if(console.warn("Viewer.openVsfxFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead."),!this.visualizeJs)return this;this.cancel(),this.clear(),this.emitEvent({type:"open",mode:"file",file:"",buffer:t});const e=this.visViewer();this.emitEvent({type:"geometrystart",file:"",buffer:t});try{const i=t instanceof Uint8Array?t:new Uint8Array(t);e.parseVsfx(i),this.syncOptions(),this.syncOverlay(),this.update(!0),this.emitEvent({type:"geometryprogress",data:1,file:"",buffer:t}),this.emitEvent({type:"databasechunk",data:i,file:"",buffer:t})}catch(e){throw this.emitEvent({type:"geometryerror",data:e,file:"",buffer:t}),e}return this.emitEvent({type:"geometryend",file:"",buffer:t}),this}cancel(){var t;return null===(t=this._abortControllerForReferences)||void 0===t||t.abort(),this._abortControllerForReferences=void 0,this.loaders.forEach(t=>t.cancel()),this.emitEvent({type:"cancel"}),this}clear(){if(!this.visualizeJs)return this;const t=this.visViewer();return this.setActiveDragger(),this.clearSlices(),this.clearOverlay(),this.clearSelected(),this.loaders.forEach(t=>t.dispose()),this.loaders=[],this.models.forEach(t=>t.dispose()),this.models=[],t.clear(),t.createLocalDatabase(),this.syncOptions(),this.syncOverlay(),this.update(!0),this.emitEvent({type:"clear"}),this}is3D(){if(!this.visualizeJs)return!1;const t=this.visViewer().getActiveExtents(),e=t.min();return 0!==t.max()[2]-e[2]}syncOptions(t=this.options){if(!this.visualizeJs)return this;const e=this.visLib(),i=this.visViewer(),s=i.getActiveDevice();if(s.isNull())return this;const r=s.getActiveView();let n;r.enableDefaultLighting(!0,e.DefaultLightingType.kTwoLights),r.setDefaultLightingIntensity(1.25);try{n=i.findVisualStyle("OpenCloud")}catch{n=void 0}if(!n||n.isNull()){n=i.createVisualStyle("OpenCloud");const t=new e.OdTvColorDef(66,66,66),s=i.findVisualStyle("Realistic"),r=n.openObject();r.copyFrom(s),r.setOptionInt32(e.VisualStyleOptions.kFaceModifiers,0,e.VisualStyleOperations.kSet),r.setOptionInt32(e.VisualStyleOptions.kEdgeModel,2,e.VisualStyleOperations.kSet),r.setOptionDouble(e.VisualStyleOptions.kEdgeCreaseAngle,60,e.VisualStyleOperations.kSet),r.setOptionInt32(e.VisualStyleOptions.kEdgeStyles,0,e.VisualStyleOperations.kSet),r.setOptionInt32(e.VisualStyleOptions.kEdgeModifiers,8,e.VisualStyleOperations.kSet),r.setOptionColor(e.VisualStyleOptions.kEdgeColorValue,t,e.VisualStyleOperations.kSet),r.delete()}r.visualStyle=n,t.showWCS!==i.getEnableWCS()&&i.setEnableWCS(t.showWCS),t.cameraAnimation!==i.getEnableAnimation()&&i.setEnableAnimation(t.cameraAnimation);const a=!0===t.antialiasing||"fxaa"===t.antialiasing;if(a!==i.fxaaAntiAliasing3d&&(i.fxaaAntiAliasing3d=a,i.fxaaQuality=5),t.shadows!==i.shadows&&(i.shadows=t.shadows),t.groundShadow!==i.groundShadow&&(i.groundShadow=t.groundShadow),t.ambientOcclusion!==s.getOptionBool(e.DeviceOptions.kSSAOEnable)){s.setOptionBool(e.DeviceOptions.kSSAOEnable,t.ambientOcclusion),s.setOptionBool(e.DeviceOptions.kSSAODynamicRadius,!0),s.setOptionDouble(e.DeviceOptions.kSSAORadius,1),s.setOptionInt32(e.DeviceOptions.kSSAOLoops,32),s.setOptionDouble(e.DeviceOptions.kSSAOPower,2),s.setOptionInt32(e.DeviceOptions.kSSAOBlurRadius,2);const r=i.activeView;r.setSSAOEnabled(t.ambientOcclusion),r.delete()}if(or(t.edgeModel)){const r=s.getActiveView(),n=i.findVisualStyle("OpenCloud"),a=n.openObject();a.setOptionInt32(e.VisualStyleOptions.kEdgeModel,t.edgeModel?2:0,e.VisualStyleOperations.kSet),r.visualStyle=n,a.delete(),n.delete(),r.delete()}const o=t.enableCustomHighlight?t:m.defaults(),{Entry:h,OdTvRGBColorDef:l}=e,d=i.findHighlightStyle("Web_Default").openObject();if(or(o.facesColor)){const t=new l(o.facesColor.r,o.facesColor.g,o.facesColor.b);d.setFacesColor(h.k3D.value|h.k3DTop.value,t),t.delete()}if(or(o.facesOverlap)&&d.setFacesVisibility(h.k3DTop.value,o.facesOverlap),or(o.facesTransparancy)&&d.setFacesTransparency(h.k3D.value|h.k3DTop.value,o.facesTransparancy),or(o.edgesColor)){const t=new l(o.edgesColor.r,o.edgesColor.g,o.edgesColor.b);d.setEdgesColor(h.k3DTop.value|h.k3D.value|h.k2D.value|h.k2DTop.value,t),t.delete()}if(or(o.edgesVisibility)&&d.setEdgesVisibility(h.k2D.value|h.k2DTop.value|h.k3DTop.value|h.k3D.value,o.edgesVisibility),or(o.edgesOverlap)){const t=!or(o.edgesVisibility)||o.edgesVisibility;d.setEdgesVisibility(h.k2DTop.value|h.k3DTop.value,o.edgesOverlap&&t)}return r.delete(),s.delete(),this.update(),this}syncOverlay(){if(!this.visualizeJs)return;const t=this.visViewer(),e=t.activeView;let i=t.getViewByName(ar);if(!i){const s=t.getMarkupModel(),r=t.getActiveDevice();i=r.createView(ar,!1),i.addModel(s),e.addSibling(i),r.addView(i)}i.viewPosition=e.viewPosition,i.viewTarget=e.viewTarget,i.upVector=e.upVector,i.viewFieldWidth=e.viewFieldWidth,i.viewFieldHeight=e.viewFieldHeight;const s=i.getViewport();i.setViewport(s.lowerLeft,s.upperRight),i.vportRect=e.vportRect,this._markup.syncOverlay(),this.update()}clearOverlay(){this.visualizeJs&&(this._markup.clearOverlay(),this.update())}clearSlices(){if(!this.visualizeJs)return;const t=this.visViewer().activeView;t.removeCuttingPlanes(),t.delete(),this.update()}getSelected(){return this.executeCommand("getSelected")}setSelected(t){this.executeCommand("setSelected",t)}getSelected2(){return this.executeCommand("getSelected2")}setSelected2(t){this.executeCommand("setSelected2",t)}clearSelected(){this.executeCommand("clearSelected")}hideSelected(){this.executeCommand("hideSelected")}isolateSelected(){this.executeCommand("isolateSelected")}showAll(){this.executeCommand("showAll")}explode(t=0){this.executeCommand("explode",t)}collect(){this.executeCommand("collect")}registerDragger(t,e){console.warn("Viewer.registerDragger() has been deprecated since 25.12 and will be removed in a future release, use draggers('visualizejs').registerDragger() instead."),q.registerDragger(t,t=>new e(t))}activeDragger(){return this._activeDragger}setActiveDragger(t=""){var e,i;if(!this._activeDragger||this._activeDragger.name!==t){const s=this._activeDragger;let r=null;this._activeDragger&&(this._activeDragger.dispose(),this._activeDragger=null),this.visualizeJs&&(r=q.createDragger(t,this),r&&(this._activeDragger=r,null===(i=(e=this._activeDragger).initialize)||void 0===i||i.call(e)));const n=this.canvas;n&&(s&&n.classList.remove(`oda-cursor-${s.name.toLowerCase()}`),r&&n.classList.add(`oda-cursor-${r.name.toLowerCase()}`)),this.emitEvent({type:"changeactivedragger",data:t}),this.update()}return this._activeDragger}resetActiveDragger(){const t=this._activeDragger;t&&(this.setActiveDragger(),this.setActiveDragger(t.name))}getComponent(t){return this._components.find(e=>e.name===t)}drawViewpoint(t){var e,i;if(!this.visualizeJs)return;const s=this.visViewer().activeView,r=t=>[t.x,t.y,t.z],n=null===(e=this._activeDragger)||void 0===e?void 0:e.name;this.setActiveDragger(),this.clearSlices(),this.clearOverlay(),this.clearSelected(),this.showAll(),this.explode(),(t=>{t&&(s.setView(r(t.view_point),r(t.direction),r(t.up_vector),t.field_width,t.field_height,!0),this.syncOverlay(),this.emitEvent({type:"changecameramode",mode:"orthographic"}))})(t.orthogonal_camera),t.perspective_camera,(t=>{if(t)for(const e of t){const t=new(this.visLib().OdTvPlane);t.set(r(e.location),r(e.direction)),s.addCuttingPlane(t),s.setEnableCuttingPlaneFill(!0,102,102,102)}})(t.clipping_planes),(t=>{t&&this.setSelected(t.map(t=>t.handle))})((null===(i=t.custom_fields)||void 0===i?void 0:i.selection2)||t.selection),this._markup.setViewpoint(t),this.setActiveDragger(n),this.emitEvent({type:"drawviewpoint",data:t}),this.update()}createViewpoint(){if(!this.visualizeJs)return{};const t=this.visViewer().activeView,e=t=>({x:t[0],y:t[1],z:t[2]}),i={custom_fields:{}};return i.orthogonal_camera={view_point:e(t.viewPosition),direction:e(t.viewTarget),up_vector:e(t.upVector),field_width:t.viewFieldWidth,field_height:t.viewFieldHeight,view_to_world_scale:1},i.perspective_camera=void 0,i.clipping_planes=(()=>{const i=[];for(let s=0;s<t.numCuttingPlanes();s++){const r=t.getCuttingPlane(s),n={location:e(r.getOrigin()),direction:e(r.normal())};i.push(n)}return i})(),i.selection=(()=>this.getSelected().map(t=>({handle:t})))(),i.description=(new Date).toDateString(),this._markup.getViewpoint(i),i.custom_fields.selection2=(()=>this.getSelected2().map(t=>({handle:t})))(),this.emitEvent({type:"createviewpoint",data:i}),i}screenToWorld(t){if(!this.visualizeJs)return{x:t.x,y:t.y,z:0};const e=this.visViewer().activeView,i=e.transformScreenToWorld(t.x*window.devicePixelRatio,t.y*window.devicePixelRatio),s={x:i[0],y:i[1],z:i[2]};return e.delete(),s}worldToScreen(t){if(!this.visualizeJs)return{x:t.x,y:t.y};const e=this.visViewer().activeView,i=e.transformWorldToScreen(t.x,t.y,t.z),s={x:i[0]/window.devicePixelRatio,y:i[1]/window.devicePixelRatio};return e.delete(),s}getScale(){const t={x:1,y:1,z:1},e=this.visViewer().activeView.projectionMatrix,i=1e-6,s=e.get(0,0);(s>i||s<-1e-6)&&(t.x=1/s);const r=e.get(1,1);(r>i||r<-1e-6)&&(t.y=1/r);const n=e.get(2,2);return(n>i||n<-1e-6)&&(t.z=1/n),t}executeCommand(t,...e){return tt.executeCommand(t,this,...e)}addMarkupEntity(t){if(!this.visualizeJs)return null;this.syncOverlay();const e=this.visViewer().getMarkupModel().appendEntity(t),i=e.openObject(),s=this.getMarkupColor();return i.setColor(s.r,s.g,s.b),i.setLineWeight(2),i.delete(),this.update(),e}getMarkupColor(){return console.warn("Viewer.getMarkupColor() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.getMarkupColor() instead."),this._markup.getMarkupColor()}setMarkupColor(t=255,e=0,i=0){console.warn("Viewer.setMarkupColor() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.setMarkupColor() instead."),this._markup.setMarkupColor(t,e,i)}colorizeAllMarkup(t=255,e=0,i=0){console.warn("Viewer.colorizeAllMarkup() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.colorizeAllMarkup() instead."),this._markup.colorizeAllMarkup(t,e,i)}colorizeSelectedMarkups(t=255,e=0,i=0){this._markup.colorizeSelectedMarkups(t,e,i)}scheduleUpdateAsync(t=50){return new Promise((e,i)=>{setTimeout(()=>{var s,r,n;try{this._enableAutoUpdate&&(null===(s=this.visViewer())||void 0===s||s.update(t),null===(n=null===(r=this._activeDragger)||void 0===r?void 0:r.updatePreview)||void 0===n||n.call(r)),this.emitEvent({type:"update",data:!1}),e()}catch(t){console.error(t),i()}},0)})}async updateAsync(t=50,e=50){if(this.visualizeJs){this._isRunAsyncUpdate=!0;try{const i=this.visViewer().getActiveDevice();for(let s=0;!i.isValid()&&s<e;s++)await this.scheduleUpdateAsync(t);await this.scheduleUpdateAsync(t)}catch(t){console.error(t)}finally{this._isRunAsyncUpdate=!1}}}deviceAutoRegeneration(){const t=this.visViewer();t.getActiveDevice().getOptionDouble(this.visLib().DeviceOptions.kRegenCoef)>1&&(t.regenAll(),this.update())}},t.commands=tt,t.commandsRegistry=s,t.components=lt,t.componentsRegistry=l,t.defaultOptions=p,t.draggers=q,t.draggersRegistry=a,t.loaders=wt,t.loadersRegistry=g});