@flowscape-ui/core-sdk 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -71
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1255 -636
- package/dist/index.d.ts +1255 -636
- package/dist/index.js +1 -1
- package/package.json +20 -7
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import R from'konva';var lt=Object.defineProperty;var dt=(K,o,e)=>o in K?lt(K,o,{enumerable:true,configurable:true,writable:true,value:e}):K[o]=e;var a=(K,o,e)=>dt(K,typeof o!="symbol"?o+"":o,e);var G=class{constructor(o,e={}){a(this,"konvaNode");a(this,"id");this.konvaNode=o,this.id=e.id??`node_${String(Date.now())}_${String(Math.random())}`,e.x&&this.konvaNode.x(e.x),e.y&&this.konvaNode.y(e.y),e.width&&this.konvaNode.width(e.width),e.height&&this.konvaNode.height(e.height);}getNode(){return this.konvaNode}setPosition({x:o,y:e}){this.konvaNode.position({x:o,y:e});}getPosition(){return this.konvaNode.position()}remove(){this.konvaNode.destroy();}};var ye=class extends G{constructor(o){let e=new R.Rect({x:o.x??0,y:o.y??0,width:o.width??100,height:o.height??100,fill:o.fill??"lightgray",stroke:o.stroke??"black",strokeWidth:o.strokeWidth??1,cornerRadius:o.cornerRadius??0,draggable:true});super(e,o);}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}setCornerRadius(o){return this.konvaNode.cornerRadius(o),this}setSize({width:o,height:e}){return this.konvaNode.size({width:o,height:e}),this}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}getCornerRadius(){return this.konvaNode.cornerRadius()}};var we=class{constructor(){a(this,"_listeners");this._listeners=new Map;}get listeners(){return this._listeners}on(o,e){this._listeners.has(o)||this._listeners.set(o,[]),this._listeners.get(o).push(e);}off(o,e){let t=this._listeners.get(o);t&&this._listeners.set(o,t.filter(n=>n!==e));}once(o,e){let t=((...n)=>{this.off(o,t),e(...n);});this.on(o,t);}emit(o,...e){let t=this._listeners.get(o);t&&[...t].forEach(n=>{n(...e);});}};var xe=class extends G{constructor(o={}){let e=new R.Text({x:o.x??0,y:o.y??0,...o.width?{width:o.width}:{},...o.height?{height:o.height}:{},text:o.text??"Text",fontSize:o.fontSize??16,fontFamily:o.fontFamily??"Inter, Arial, sans-serif",fontStyle:o.fontStyle??"normal",fill:o.fill??"#ffffff",align:o.align??"left",padding:o.padding??0});super(e,o);}getText(){return this.konvaNode.text()}getFontSize(){return this.konvaNode.fontSize()}getFontFamily(){return this.konvaNode.fontFamily()}getFontStyle(){return this.konvaNode.fontStyle()}getFill(){return this.konvaNode.fill()}getAlign(){return this.konvaNode.align()}getPadding(){return this.konvaNode.padding()}getSize(){return this.konvaNode.size()}setText(o){return this.konvaNode.text(o),this}setFontSize(o){return this.konvaNode.fontSize(o),this}setFontFamily(o){return this.konvaNode.fontFamily(o),this}setFontStyle(o){return this.konvaNode.fontStyle(o),this}setFill(o){return this.konvaNode.fill(o),this}setAlign(o){return this.konvaNode.align(o),this}setPadding(o){return this.konvaNode.padding(o),this}setSize({width:o,height:e}){return this.konvaNode.size({width:o,height:e}),this}};var Ne=class extends G{constructor(o={}){let e=new R.Image({});e.x(o.x??0),e.y(o.y??0),e.width(o.width??150),e.height(o.height??150),e.image(o.image??null),super(e,o),!o.image&&o.src&&this.setSrc(o.src);}getSize(){return this.konvaNode.size()}async setSrc(o,e="anonymous"){let t=await this._loadHTMLImage(o,e);return this.konvaNode.image(t),this.konvaNode.getLayer()?.batchDraw(),this}setImage(o){return this.konvaNode.image(o),this.konvaNode.getLayer()?.batchDraw(),this}setSize({width:o,height:e}){return this.konvaNode.size({width:o,height:e}),this}_loadHTMLImage(o,e="anonymous"){return new Promise((t,n)=>{let r=globalThis.Image??null;if(!r){n(new Error("Image constructor is not available in current environment"));return}let i=new r,s=e;i.crossOrigin=s,i.onload=()=>{t(i);},i.onerror=()=>{n(new Error(`Failed to load image: ${o}`));},i.src=o;})}};var ke=class extends G{constructor(o={}){let e=new R.Circle({});e.x(o.x??0),e.y(o.y??0),e.radius(o.radius??0),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),e.draggable(true),super(e,o);}getRadius(){return this.konvaNode.radius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setRadius(o){return this.konvaNode.radius(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var Se=class extends G{constructor(o={}){let e=new R.Ellipse({});e.x(o.x??0),e.y(o.y??0),e.radiusX(o.radiusX??0),e.radiusY(o.radiusY??0),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),super(e,o);}getRadiusX(){return this.konvaNode.radiusX()}getRadiusY(){return this.konvaNode.radiusY()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setRadiusX(o){return this.konvaNode.radiusX(o),this}setRadiusY(o){return this.konvaNode.radiusY(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var Ce=class extends G{constructor(o={}){let e=new R.Arc({});e.x(o.x??0),e.y(o.y??0),e.innerRadius(o.innerRadius??0),e.outerRadius(o.outerRadius??0),e.angle(o.angle??0),e.rotation(o.rotation??0),o.clockwise!==void 0&&e.clockwise(o.clockwise),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),super(e,o);}getInnerRadius(){return this.konvaNode.innerRadius()}getOuterRadius(){return this.konvaNode.outerRadius()}getAngle(){return this.konvaNode.angle()}isClockwise(){return this.konvaNode.clockwise()}setInnerRadius(o){return this.konvaNode.innerRadius(o),this}setOuterRadius(o){return this.konvaNode.outerRadius(o),this}setAngle(o){return this.konvaNode.angle(o),this}setRotationDeg(o){return this.konvaNode.rotation(o),this}setClockwise(o){return this.konvaNode.clockwise(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var Te=class extends G{constructor(o={}){let e=new R.Arrow({});e.x(o.x??0),e.y(o.y??0),e.points(o.points??[]),o.tension&&e.tension(o.tension),o.pointerLength&&e.pointerLength(o.pointerLength),o.pointerWidth&&e.pointerWidth(o.pointerWidth),o.pointerAtBeginning&&e.pointerAtBeginning(o.pointerAtBeginning),o.pointerAtEnding&&e.pointerAtEnding(o.pointerAtEnding),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),super(e,o);}getPoints(){return this.konvaNode.points()}getTension(){return this.konvaNode.tension()}getPointerLength(){return this.konvaNode.pointerLength()}getPointerWidth(){return this.konvaNode.pointerWidth()}getPointerAtBeginning(){return this.konvaNode.pointerAtBeginning()}getPointerAtEnding(){return this.konvaNode.pointerAtEnding()}setPoints(o){return this.konvaNode.points(o),this}setTension(o){return this.konvaNode.tension(o),this}setPointerLength(o){return this.konvaNode.pointerLength(o),this}setPointerWidth(o){return this.konvaNode.pointerWidth(o),this}setPointerAtBeginning(o){return this.konvaNode.pointerAtBeginning(o),this}setPointerAtEnding(o){return this.konvaNode.pointerAtEnding(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var Ke=class extends G{constructor(o={}){let e=new R.RegularPolygon({});e.x(o.x??0),e.y(o.y??0),e.sides(o.sides??3),e.radius(o.radius??60),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),super(e,o);}getSides(){return this.konvaNode.sides()}getRadius(){return this.konvaNode.radius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setSides(o){return this.konvaNode.sides(o),this}setRadius(o){return this.konvaNode.radius(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var Me=class extends G{constructor(o={}){let e=new R.Star({});e.x(o.x??0),e.y(o.y??0),e.numPoints(o.numPoints??5),e.innerRadius(o.innerRadius??20),e.outerRadius(o.outerRadius??40),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),super(e,o);}getNumPoints(){return this.konvaNode.numPoints()}getInnerRadius(){return this.konvaNode.innerRadius()}getOuterRadius(){return this.konvaNode.outerRadius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setNumPoints(o){return this.konvaNode.numPoints(o),this}setInnerRadius(o){return this.konvaNode.innerRadius(o),this}setOuterRadius(o){return this.konvaNode.outerRadius(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var Pe=class extends G{constructor(o={}){let e=new R.Ring({});e.x(o.x??0),e.y(o.y??0),e.innerRadius(o.innerRadius??20),e.outerRadius(o.outerRadius??40),e.fill(o.fill??"black"),e.stroke(o.stroke??"black"),e.strokeWidth(o.strokeWidth??0),super(e,o);}getInnerRadius(){return this.konvaNode.innerRadius()}getOuterRadius(){return this.konvaNode.outerRadius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setInnerRadius(o){return this.konvaNode.innerRadius(o),this}setOuterRadius(o){return this.konvaNode.outerRadius(o),this}setFill(o){return this.konvaNode.fill(o),this}setStroke(o){return this.konvaNode.stroke(o),this}setStrokeWidth(o){return this.konvaNode.strokeWidth(o),this}};var de=class extends G{constructor(o={}){let e=new R.Group({});e.x(o.x??0),e.y(o.y??0),e.draggable(o.draggable??true),o.listening!==void 0&&e.listening(o.listening),o.clip&&e.clip(o.clip),super(e,o);}addChild(o){let e=o.getNode?o.getNode():o;return this.konvaNode.add(e),this.konvaNode.getLayer()?.batchDraw(),this}removeChild(o){return (o.getNode?o.getNode():o).remove(),this.konvaNode.getLayer()?.batchDraw(),this}removeAllChildren(){return this.konvaNode.removeChildren(),this.konvaNode.getLayer()?.batchDraw(),this}getChildren(){return this.konvaNode.getChildren()}findByName(o){return this.konvaNode.find(`.${o}`)}setDraggable(o){return this.konvaNode.draggable(o),this}isDraggable(){return this.konvaNode.draggable()}setListening(o){return this.konvaNode.listening(o),this}isListening(){return this.konvaNode.listening()}setClip(o){return this.konvaNode.clip(o),this.konvaNode.getLayer()?.batchDraw(),this}};var Ae=class{constructor(o,e){a(this,"_layer");a(this,"_world");a(this,"_nodes",new Map);a(this,"_stage");a(this,"_eventBus");a(this,"_batchDrawScheduled",false);a(this,"_listCache",null);a(this,"_listCacheInvalidated",true);this._layer=new R.Layer,this._world=new R.Group,this._layer.add(this._world),this._stage=o,this._stage.add(this._layer),this._eventBus=e;}get layer(){return this._layer}get world(){return this._world}get stage(){return this._stage}get eventBus(){return this._eventBus}addShape(o){let e=new ye(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addText(o){let e=new xe(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addImage(o){let e=new Ne(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addCircle(o){let e=new ke(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addEllipse(o){let e=new Se(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addArc(o){let e=new Ce(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addStar(o){let e=new Me(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addArrow(o){let e=new Te(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addRing(o){let e=new Pe(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addRegularPolygon(o){let e=new Ke(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addGroup(o){let e=new de(o);return this._world.add(e.getNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}remove(o){this._eventBus.emit("node:removed",o),o.remove(),this._nodes.delete(o.id),this._listCacheInvalidated=true,this._scheduleBatchDraw();}findById(o){return this._nodes.get(o)}list(){return (this._listCacheInvalidated||!this._listCache)&&(this._listCache=Array.from(this._nodes.values()),this._listCacheInvalidated=false),this._listCache}_scheduleBatchDraw(){if(this._batchDrawScheduled)return;this._batchDrawScheduled=true;let o=globalThis.requestAnimationFrame;o(()=>{this._batchDrawScheduled=false,this._layer.batchDraw();});}};var Re=class{constructor(o){a(this,"_stage");a(this,"_eventBus");a(this,"_target");a(this,"_scale");a(this,"_minScale");a(this,"_maxScale");a(this,"_zoomStep");a(this,"_panStep");a(this,"_wheelScheduled",false);a(this,"_pendingWheelEvent",null);this._stage=o.stage,this._eventBus=o.eventBus,this._target=o.target??o.stage,this._scale=o.initialScale??1,this._minScale=o.minScale??.1,this._maxScale=o.maxScale??5,this._zoomStep=o.zoomStep??1.05,this._panStep=o.panStep??40,this._initWheelZoom();}_initWheelZoom(){this._stage.on("wheel",o=>{if(o.evt.preventDefault(),this._pendingWheelEvent=o.evt,this._wheelScheduled)return;this._wheelScheduled=true;let e=globalThis.requestAnimationFrame;e(()=>{this._wheelScheduled=false,this._pendingWheelEvent&&(this._handleWheel(this._pendingWheelEvent),this._pendingWheelEvent=null);});});}_handleWheel(o){let e=this._target.scaleX()||1,t=this._stage.getPointerPosition();if(!t)return;let n=this._zoomStep,i=(o.deltaY>0?-1:1)>0?e*n:e/n;i=Math.max(this._minScale,Math.min(this._maxScale,i));let s={x:(t.x-this._target.x())/e,y:(t.y-this._target.y())/e};this._target.scale({x:i,y:i});let l={x:t.x-s.x*i,y:t.y-s.y*i};this._target.position(l),this._stage.batchDraw(),this._scale=i,this._eventBus.emit("camera:zoom",{scale:this._scale,position:l});}get zoomStep(){return this._zoomStep}get panStep(){return this._panStep}setZoom(o){this._scale=Math.max(this._minScale,Math.min(this._maxScale,o)),this._target.scale({x:this._scale,y:this._scale}),this._stage.batchDraw(),this._eventBus.emit("camera:setZoom",{scale:this._scale});}zoomIn(o){o===void 0?this.setZoom(this._scale*this._zoomStep):this.setZoom(this._scale+o);}zoomOut(o){o===void 0?this.setZoom(this._scale/this._zoomStep):this.setZoom(this._scale-o);}reset(){this.setZoom(1),this._target.position({x:0,y:0}),this._stage.batchDraw(),this._eventBus.emit("camera:reset");}setDraggable(o){this._stage.draggable(o);}setZoomStep(o){o&&o>0&&(this._zoomStep=o,this._eventBus.emit("camera:zoomStep",{zoomStep:o}));}setPanStep(o){typeof o=="number"&&isFinite(o)&&(this._panStep=o,this._eventBus.emit("camera:panStep",{panStep:o}));}};var he=class{constructor(o=16){a(this,"_lastTime",0);a(this,"_throttle");this._throttle=o;}shouldExecute(){let o=Date.now();return o-this._lastTime<this._throttle?false:(this._lastTime=o,true)}reset(){this._lastTime=0;}setThrottle(o){this._throttle=o;}getThrottle(){return this._throttle}};var ze=class{constructor(o={}){a(this,"_enabled");a(this,"_levels");a(this,"_currentScale",1);a(this,"_appliedNodes",new Map);this._enabled=o.enabled??true,this._levels=o.levels??[{minScale:0,maxScale:.1,simplify:true,disableStroke:true,disableShadow:true,disablePerfectDraw:true},{minScale:.1,maxScale:.3,simplify:true,disableShadow:true,disablePerfectDraw:true},{minScale:.3,maxScale:1/0,simplify:false}];}_getLODLevel(o){return this._enabled?this._levels.find(t=>o>=t.minScale&&o<t.maxScale)??null:null}applyLOD(o,e){if(!this._enabled)return;this._currentScale=e;let t=this._getLODLevel(e);if(!t?.simplify){this._restoreNode(o);return}let n=o.getNode(),r=this._appliedNodes.get(o.id);r!==t&&(r||(n._originalLOD={stroke:n.stroke?.(),strokeEnabled:n.strokeEnabled(),shadow:n.shadowEnabled(),perfectDraw:n.perfectDrawEnabled?.()}),t.disableStroke&&n.strokeEnabled(false),t.disableShadow&&n.shadowEnabled(false),t.disablePerfectDraw&&n.perfectDrawEnabled&&n.perfectDrawEnabled(false),this._appliedNodes.set(o.id,t));}_restoreNode(o){let e=o.getNode(),t=e._originalLOD;t&&(e.strokeEnabled(t.strokeEnabled),e.shadowEnabled(t.shadow),t.perfectDraw!==void 0&&e.perfectDrawEnabled&&e.perfectDrawEnabled(t.perfectDraw),this._appliedNodes.delete(o.id),delete e._originalLOD);}applyToAll(o,e){if(this._enabled)for(let t of o)this.applyLOD(t,e);}restoreAll(o){for(let e of o)this._restoreNode(e);this._appliedNodes.clear();}enable(){this._enabled=true;}disable(o){this._enabled=false,this.restoreAll(o);}get enabled(){return this._enabled}get currentScale(){return this._currentScale}getStats(){return {enabled:this._enabled,currentScale:this._currentScale,appliedNodes:this._appliedNodes.size,currentLevel:this._getLODLevel(this._currentScale)}}setLevels(o){this._levels=o;}};var Ie=class{constructor(o,e,t,n={}){this._stage=o;this._world=e;this._nodeManager=t;a(this,"_enabled");a(this,"_bufferZone");a(this,"_throttle");a(this,"_viewport",{x:0,y:0,width:0,height:0});a(this,"_visibleNodes",new Set);a(this,"_hiddenNodes",new Set);a(this,"_updateScheduled",false);a(this,"_lod",null);this._enabled=n.enabled??true,this._bufferZone=n.bufferZone??200,this._throttle=new he(n.throttleMs??16),n.lod&&(this._lod=new ze(n.lod)),this._updateViewport(),this._setupListeners(),this._enabled&&this.updateVisibility();}_updateViewport(){let o=this._world.scaleX(),e=this._world.position();this._viewport={x:-e.x/o-this._bufferZone,y:-e.y/o-this._bufferZone,width:this._stage.width()/o+this._bufferZone*2,height:this._stage.height()/o+this._bufferZone*2};}_getNodeBBox(o){let t=o.getNode().getClientRect({relativeTo:this._world});return {x:t.x,y:t.y,width:t.width,height:t.height}}_isNodeVisible(o){let e=this._getNodeBBox(o);return !(e.x+e.width<this._viewport.x||e.x>this._viewport.x+this._viewport.width||e.y+e.height<this._viewport.y||e.y>this._viewport.y+this._viewport.height)}updateVisibility(){if(!this._enabled||!this._throttle.shouldExecute())return;let o=this._nodeManager.list(),e=new Set,t=0;for(let n of o){let r=this._isNodeVisible(n),i=n.getNode();r?(e.add(n.id),this._hiddenNodes.has(n.id)&&(i.visible(true),i.listening(true),this._hiddenNodes.delete(n.id),t++)):this._hiddenNodes.has(n.id)||(i.visible(false),i.listening(false),this._hiddenNodes.add(n.id),t++);}if(this._visibleNodes=e,this._lod?.enabled&&t>0){let n=this._world.scaleX();for(let r of o)e.has(r.id)&&this._lod.applyLOD(r,n);}t>0&&this._nodeManager.layer.batchDraw();}_setupListeners(){this._world.on("xChange yChange scaleXChange scaleYChange",()=>{this._scheduleUpdate();}),typeof globalThis.window<"u"&&globalThis.window.addEventListener("resize",()=>{this._updateViewport(),this._scheduleUpdate();}),this._nodeManager.eventBus.on("node:removed",o=>{this._visibleNodes.delete(o.id),this._hiddenNodes.delete(o.id);});}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=true,globalThis.requestAnimationFrame(()=>{this._updateViewport(),this.updateVisibility(),this._updateScheduled=false;}));}enable(){this._enabled||(this._enabled=true,this.updateVisibility());}disable(){if(this._enabled){this._enabled=false;for(let o of this._hiddenNodes){let e=this._nodeManager.findById(o);if(e){let t=e.getNode();t.visible(true),t.listening(true);}}this._hiddenNodes.clear(),this._visibleNodes.clear(),this._nodeManager.layer.batchDraw();}}getStats(){let o=this._nodeManager.list().length,e=this._visibleNodes.size,t=this._hiddenNodes.size;return {total:o,visible:e,hidden:t,cullingRate:o>0?t/o*100:0}}setBufferZone(o){this._bufferZone=o,this._updateViewport(),this._scheduleUpdate();}setThrottle(o){this._throttle=new he(o);}get enabled(){return this._enabled}get viewport(){return {...this._viewport}}forceUpdate(){this._throttle.reset(),this._updateViewport(),this.updateVisibility();}get lod(){return this._lod}destroy(){if(this.disable(),this._visibleNodes.clear(),this._hiddenNodes.clear(),this._lod){let o=this._nodeManager.list();this._lod.restoreAll(o);}}};var De=class{constructor(o,e=[]){a(this,"_core");a(this,"_items",[]);this._core=o,e.length&&this.addPlugins(e);}addPlugins(o){let e=[];for(let t of o)this._items.includes(t)||(this._items.push(t),t.attach(this._core),e.push(t),this._core.eventBus.emit("plugin:added",t.constructor.name));return e}removePlugins(o){let e=[];for(let t of o){let n=this._items.indexOf(t);n!==-1&&(t.detach(this._core),this._items.splice(n,1),e.push(t),this._core.eventBus.emit("plugin:removed",t.constructor.name));}return e}removeAllPlugins(){let o=[...this._items];for(let e of o)e.detach(this._core);this._items=[];for(let e of o)this._core.eventBus.emit("plugin:removed",e.constructor.name);return o}list(){return [...this._items]}get(o){return this._items.find(e=>e.constructor.name===o)}};var O=class{attach(o){this.onAttach(o);}detach(o){this.onDetach(o);}};var Ye=class{constructor(o){a(this,"_stage");a(this,"_eventBus");a(this,"_initialWidth");a(this,"_initialHeight");a(this,"_autoResize");a(this,"_backgroundColor");a(this,"_draggable");a(this,"_minScale");a(this,"_maxScale");a(this,"_gridLayer");a(this,"container");a(this,"nodes");a(this,"camera");a(this,"virtualization");a(this,"plugins");this.container=o.container,this._initialWidth=o.width??800,this._initialHeight=o.height??800,this._autoResize=o.autoResize??true,this._backgroundColor=o.backgroundColor??"#1e1e1e",this._draggable=o.draggable??true,this._minScale=o.minScale??.1,this._maxScale=o.maxScale??500,this._stage=new R.Stage({container:this.container,width:this._autoResize?this.container.offsetWidth:this._initialWidth,height:this._autoResize?this.container.offsetHeight:this._initialHeight,draggable:false}),this._autoResize||(this.container.style.width=`${String(this._initialWidth)}px`,this.container.style.height=`${String(this._initialHeight)}px`),this.container.style.background=this._backgroundColor,this._eventBus=new we,this._gridLayer=new R.Layer({listening:false}),this._stage.add(this._gridLayer),this.nodes=new Ae(this._stage,this._eventBus),this.camera=new Re({stage:this._stage,target:this.nodes.world,eventBus:this._eventBus,initialScale:1,draggable:false,minScale:this._minScale,maxScale:this._maxScale}),this.virtualization=new Ie(this._stage,this.nodes.world,this.nodes,o.virtualization),this.plugins=new De(this,o.plugins??[]);}get eventBus(){return this._eventBus}get stage(){return this._stage}get gridLayer(){return this._gridLayer}get draggable(){return this._draggable}get autoResize(){return this._autoResize}get backgroundColor(){return this._backgroundColor}get initialWidth(){return this._initialWidth}get initialHeight(){return this._initialHeight}get minScale(){return this._minScale}get maxScale(){return this._maxScale}setSize({width:o,height:e}){this._stage.size({width:o,height:e}),this._stage.fire("resize"),this._eventBus.emit("stage:resized",{width:o,height:e});}setBackgroundColor(o){this.container.style.background=o;}setDraggable(o){this._stage.draggable(o),this._draggable=o;}};var Ue=class extends O{constructor(e){super();a(this,"_core");a(this,"_layer");a(this,"_image");a(this,"_src");a(this,"_width");a(this,"_height");a(this,"_opacity");this._src=e.src,this._width=e.width,this._height=e.height,this._opacity=e.opacity??1;}onAttach(e){this._core=e,this._layer=new R.Layer({name:"logo-layer",listening:false}),this._core.stage.add(this._layer),this._image=new R.Image({image:void 0,width:this._width,height:this._height,name:"logo-background",listening:false,opacity:this._opacity}),this._layer.add(this._image),this.setSource(this._src);let t=this._core.stage;t.on("resize.logo",()=>{this._layout();}),t.on("xChange.logo yChange.logo scaleXChange.logo scaleYChange.logo",()=>{this._layout();}),this._layout(),this._core.stage.batchDraw();}onDetach(e){e.stage.off(".logo"),this._image&&this._image.destroy(),this._layer&&this._layer.destroy();}setOpacity(e){this._opacity=e,this._image&&this._core&&(this._image.opacity(e),this._core.stage.batchDraw());}setSize({width:e,height:t}){this._width=e,this._height=t,this._layout(),this._core&&this._core.stage.batchDraw();}setSource(e){this._src=e,this._loadImageFromString(e);}_setImage(e){this._image&&(this._image.image(e),this._layout(),this._core&&this._core.stage.batchDraw());}_loadImageFromString(e){R.Image.fromURL(e,t=>{let n=t.image();n&&this._setImage(n);});}_layout(){if(!this._core||!this._image)return;let e=this._core.stage,t=e.width(),n=e.height(),r=e.scaleX(),i=e.position(),s={x:Math.floor(t/2),y:Math.floor(n/2)};this._image.scale({x:1/r,y:1/r});let l=this._width,d=this._height;this._image.size({width:l,height:d}),this._image.offset({x:l/2,y:d/2});let u=(s.x-i.x)/r,h=(s.y-i.y)/r;this._image.position({x:u,y:h}),this._image.opacity(this._opacity),this._layer&&this._layer.moveToBottom();}};var Ve=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_attached",false);a(this,"_panning",false);a(this,"_last",null);a(this,"_prevCursor",null);a(this,"_prevStageDraggable");a(this,"_onWheelDOM",e=>{if(!this._core||e.ctrlKey)return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation?.();let{deltaX:n,deltaY:r,shiftKey:i}=e;if(this._isTouchpadWheel(e)){if(i){let l=-(Math.abs(n)>=Math.abs(r)?n:r);this._pan(l,0);}else {let s=-n,l=-r;this._pan(s,l);}return}if(i){let s=r<0?-Math.abs(r):Math.abs(r);this._pan(s,0);}else {let s=-r;this._pan(0,s);}});a(this,"_onMouseDownKonva",e=>{if(!this._core||!this._options.enablePanning)return;let t=e.evt.button;if(!(this._options.allowMiddleButtonPan&&t===1||this._options.allowRightButtonPan&&t===2))return;this._panning=true;let r=this._core.stage.getPointerPosition();r&&(this._last={x:r.x,y:r.y});let i=this._core.stage.container();this._prevCursor=i.style.cursor||null,i.style.cursor="grabbing",e.evt.preventDefault();});a(this,"_onMouseMoveKonva",e=>{if(!this._core||!this._options.enablePanning||!this._panning||!this._last)return;let t=this._core.stage.getPointerPosition();if(!t)return;let n=t.x-this._last.x,r=t.y-this._last.y;this._pan(n,r),this._last={x:t.x,y:t.y};});a(this,"_onMouseUpKonva",e=>{if(!this._options.enablePanning||(this._panning=false,this._last=null,!this._core))return;let t=this._core.stage.container();this._prevCursor!==null?(t.style.cursor=this._prevCursor,this._prevCursor=null):t.style.removeProperty("cursor");});a(this,"_onMouseLeaveKonva",e=>{if(!this._options.enablePanning||(this._panning=false,this._last=null,!this._core))return;let t=this._core.stage.container();this._prevCursor!==null?(t.style.cursor=this._prevCursor,this._prevCursor=null):t.style.removeProperty("cursor");});a(this,"_onContextMenuDOM",e=>{this._options.disableContextMenu&&e.preventDefault();});a(this,"_handleKeyDown",e=>{if(this._options.ignoreEditableTargets&&this._isEditableTarget(e.target)||!this._core)return;let t=e.code==="Equal"||e.code==="NumpadAdd",n=e.code==="Minus"||e.code==="NumpadSubtract";if(t||n){e.preventDefault(),t?this._core.camera.zoomIn():this._core.camera.zoomOut();return}if(this._options.enableArrows){let r=this._core.camera.panStep;switch(e.key){case "ArrowLeft":e.preventDefault(),this._pan(r,0);return;case "ArrowRight":e.preventDefault(),this._pan(-r,0);return;case "ArrowUp":e.preventDefault(),this._pan(0,r);return;case "ArrowDown":e.preventDefault(),this._pan(0,-r);return}}});let{target:t=globalThis,zoomStep:n=1.1,panStep:r=40,ignoreEditableTargets:i=true,enableArrows:s=true,enablePanning:l=true,allowMiddleButtonPan:d=true,allowRightButtonPan:u=true,disableContextMenu:h=true}=e;this._options={target:t,zoomStep:n,panStep:r,ignoreEditableTargets:i,enableArrows:s,enablePanning:l,allowMiddleButtonPan:d,allowRightButtonPan:u,disableContextMenu:h};}setOptions(e){let t=this._options.disableContextMenu;if(this._options={...this._options,...e},this._attached&&this._core&&(typeof e.zoomStep=="number"&&this._core.camera.setZoomStep(this._options.zoomStep),typeof e.panStep=="number"&&this._core.camera.setPanStep(this._options.panStep),typeof e.disableContextMenu=="boolean"&&e.disableContextMenu!==t)){let n=this._core.stage.container();this._options.disableContextMenu?n.addEventListener("contextmenu",this._onContextMenuDOM):n.removeEventListener("contextmenu",this._onContextMenuDOM);}}onAttach(e){this._core=e;let t=this._core.stage;typeof this._options.zoomStep=="number"&&this._core.camera.setZoomStep(this._options.zoomStep),typeof this._options.panStep=="number"&&this._core.camera.setPanStep(this._options.panStep),this._prevStageDraggable=t.draggable(),t.draggable(false),this._options.target.addEventListener("keydown",this._handleKeyDown),this._options.enablePanning&&(t.on("mousedown.cameraHotkeys",this._onMouseDownKonva),t.on("mousemove.cameraHotkeys",this._onMouseMoveKonva),t.on("mouseup.cameraHotkeys",this._onMouseUpKonva),t.on("mouseleave.cameraHotkeys",this._onMouseLeaveKonva),this._options.disableContextMenu&&t.container().addEventListener("contextmenu",this._onContextMenuDOM)),t.container().addEventListener("wheel",this._onWheelDOM,{passive:false,capture:true}),t.on("wheel.cameraHotkeysGuard",r=>{r.evt.ctrlKey||(r.evt.preventDefault(),r.cancelBubble=true);}),this._attached=true;}onDetach(e){if(!this._attached)return;this._options.target.removeEventListener("keydown",this._handleKeyDown);let n=e.stage;n.off(".cameraHotkeys"),n.off(".cameraHotkeysGuard"),n.container().removeEventListener("wheel",this._onWheelDOM),this._options.enablePanning&&n.container().removeEventListener("contextmenu",this._onContextMenuDOM),this._prevStageDraggable!==void 0&&n.draggable(this._prevStageDraggable),this._attached=false,this._last=null,this._prevCursor=null;}_isEditableTarget(e){let t=e;if(!t)return false;let n=t.tagName;return t.isContentEditable||n==="INPUT"||n==="TEXTAREA"||n==="SELECT"}_isTouchpadWheel(e){return e.deltaMode===0&&(Math.abs(e.deltaX)>0||Math.abs(e.deltaY)<50)}_pan(e,t){if(!this._core)return;let n=this._core.nodes.world,r=n.x()+e,i=n.y()+t;n.position({x:r,y:i}),this._core.eventBus.emit("camera:pan",{dx:e,dy:t,position:{x:r,y:i}}),this._core.stage.batchDraw();}};var Ee=class{constructor(o){a(this,"deps");this.deps=o;}ensure(o){this.deps.ensureTempMulti(o);}destroy(){this.deps.destroyTempMulti();}commitToPermanentGroup(){this.deps.commitTempMultiToGroup();}isActive(){return this.deps.isActive()}forceUpdateOverlays(){this.deps.forceUpdate();}onWorldChanged(){this.deps.onWorldChanged?this.deps.onWorldChanged():this.deps.forceUpdate();}isInsideTempByTarget(o){return this.deps.isInsideTempByTarget?this.deps.isInsideTempByTarget(o):false}};function ue(K,o,e,t=6){if(!K||!o||!e)return;let n=e.getClientRect({skipShadow:true,skipStroke:false}),r=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),i=e.getAbsoluteScale(),s=Math.abs(i.x)||1,l=Math.abs(i.y)||1,d=r.width*s,u=r.height*l,h=(()=>{let g=e.getAbsoluteTransform().decompose();return typeof g.rotation=="number"?g.rotation:0})(),c=Math.abs((h%180+180)%180)>.5,p=o.findOne(".top-center"),f=o.findOne(".middle-right"),b=o.findOne(".bottom-center"),_=o.findOne(".middle-left");if(p){let g=c?d:n.width,m=t;p.setAttrs({opacity:0,width:g,height:m,offsetX:g/2,offsetY:0});}if(b){let g=c?d:n.width,m=t;b.setAttrs({opacity:0,width:g,height:m,offsetX:g/2,offsetY:m});}if(_){let g=t,m=c?u:n.height;_.setAttrs({opacity:0,width:g,height:m,offsetX:0,offsetY:m/2});}if(f){let g=t,m=c?u:n.height;f.setAttrs({opacity:0,width:g,height:m,offsetX:g,offsetY:m/2});}}function ie(K){return new R.Circle({name:K,radius:4,width:25,height:25,fill:"#ffffff",stroke:"#2b83ff",strokeWidth:1.5,opacity:0,hitStrokeWidth:16,draggable:true,dragOnTop:true,listening:true,cursor:"pointer"})}var We=class{constructor(o){a(this,"core");a(this,"getNode");a(this,"getTransformer");a(this,"onUpdate");a(this,"group",null);a(this,"handles",{tl:null,tr:null,br:null,bl:null});a(this,"dragState",null);a(this,"centerAbsStart",null);this.core=o.core,this.getNode=o.getNode,this.getTransformer=o.getTransformer,o.onUpdate&&(this.onUpdate=o.onUpdate);}attach(){if(!this.getNode())return;let e=this.core.nodes.layer;this.detach();let t=new R.Group({name:"rotate-handles-group",listening:true});e.add(t),this.group=t;let n=ie("rotate-tl"),r=ie("rotate-tr"),i=ie("rotate-br"),s=ie("rotate-bl");t.add(n),t.add(r),t.add(i),t.add(s),this.handles={tl:n,tr:r,br:i,bl:s};let l=d=>{d.on("mouseenter.rotate",()=>{this.core.stage.container().style.cursor="pointer";}),d.on("mouseleave.rotate",()=>{this.core.stage.container().style.cursor="default";}),d.on("dragstart.rotate",()=>{let u=this.getNode();if(!u)return;let h=u.getAbsoluteTransform().decompose();this.centerAbsStart=this.getNodeCenterAbs(u);let c=this.core.stage.getPointerPosition()??d.getAbsolutePosition(),p=Math.atan2(c.y-this.centerAbsStart.y,c.x-this.centerAbsStart.x)*180/Math.PI;this.dragState={base:h.rotation||0,start:p},this.core.stage.draggable(false),this.core.stage.container().style.cursor="grabbing",this.getTransformer()?.moveToTop(),this.placeBelowTransformer();}),d.on("dragmove.rotate",u=>{let h=this.getNode();if(!h||!this.dragState)return;let c=this.centerAbsStart??this.getNodeCenterAbs(h),p=this.core.stage.getPointerPosition()??d.getAbsolutePosition(),f=Math.atan2(p.y-c.y,p.x-c.x)*180/Math.PI,b=this.dragState.base+(f-this.dragState.start),_=this.getTransformer();if(u.evt.shiftKey&&_){let m=w=>{let N=w%360;return N<0&&(N+=360),N},v=(w,N)=>m(w-N+180)-180,y=Array.isArray(_.rotationSnaps())?_.rotationSnaps().map(w=>m(w)):void 0,x=typeof _.rotationSnapTolerance=="function"?_.rotationSnapTolerance():5;if(y?.length){let w=m(b),N=b,k=1/0;for(let C of y){let M=Math.abs(v(w,C));M<k&&M<=x&&(N=C,k=M);}k!==1/0&&(b=N);}}if(h.rotation(b),this.centerAbsStart){let m=this.getNodeCenterAbs(h),v=this.centerAbsStart.x-m.x,y=this.centerAbsStart.y-m.y,x=h.getParent();if(x){let w=x.getAbsoluteTransform().copy().invert(),N=w.point({x:m.x,y:m.y}),k=w.point({x:m.x+v,y:m.y+y}),C=h.x()+(k.x-N.x),M=h.y()+(k.y-N.y);h.position({x:C,y:M});}}let g=this.getTransformer();g?.forceUpdate(),g&&ue(this.core,g,h),this.updatePosition(),this.placeBelowTransformer(),this.core.nodes.layer.batchDraw(),this.onUpdate&&this.onUpdate();}),d.on("dragend.rotate",()=>{this.dragState=null,this.centerAbsStart=null,this.core.stage.draggable(false),this.updatePosition(),this.placeBelowTransformer(),this.core.stage.container().style.cursor="pointer",this.onUpdate&&this.onUpdate();});};l(n),l(r),l(i),l(s),this.updatePosition(),this.placeBelowTransformer();}detach(){this.group&&(this.group.destroy(),this.group=null),this.handles={tl:null,tr:null,br:null,bl:null},this.dragState=null,this.centerAbsStart=null;}moveToTop(){this.placeBelowTransformer();}updatePosition(){let o=this.getNode();if(!o||!this.group)return;let e=o.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),t=e.width,n=e.height;if(t<=0||n<=0)return;let r=o.getAbsoluteTransform().copy(),i=w=>r.point(w),s=12,l=i({x:e.x+t/2,y:e.y+n/2}),d=i({x:e.x,y:e.y}),u=i({x:e.x+t,y:e.y}),h=i({x:e.x+t,y:e.y+n}),c=i({x:e.x,y:e.y+n}),p=w=>{let N=w.x-l.x,k=w.y-l.y,C=Math.hypot(N,k)||1;return {x:N/C,y:k/C}},f=p(d),b=p(u),_=p(h),g=p(c),m={x:d.x+f.x*s,y:d.y+f.y*s},v={x:u.x+b.x*s,y:u.y+b.y*s},y={x:h.x+_.x*s,y:h.y+_.y*s},x={x:c.x+g.x*s,y:c.y+g.y*s};this.handles.tl&&this.handles.tl.absolutePosition(m),this.handles.tr&&this.handles.tr.absolutePosition(v),this.handles.br&&this.handles.br.absolutePosition(y),this.handles.bl&&this.handles.bl.absolutePosition(x),this.placeBelowTransformer();}placeBelowTransformer(){if(!this.group)return;let o=this.getTransformer(),e=this.core.nodes.layer;if(o&&o.getLayer()===e){let t=o.zIndex(),n=this.group.zIndex();if(n>=t){let r=n-t+1;for(let i=0;i<r&&this.group.zIndex()>0;i++)this.group.moveDown();}}else this.group.moveToBottom();}getNodeCenterAbs(o){let e=o.getAbsoluteTransform().copy(),t=o.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),n=t.x+t.width/2,r=t.y+t.height/2;return e.point({x:n,y:r})}};var Xe=class{constructor(o){a(this,"core");a(this,"tr",null);a(this,"sizeLabel",null);a(this,"rotateGroup",null);a(this,"rotateCtrl",null);a(this,"keepRatioPredicate",null);a(this,"boundNode",null);a(this,"hitRect",null);a(this,"transformOppositeCorner",null);a(this,"trWasVisibleBeforeDrag",false);a(this,"labelWasVisibleBeforeDrag",false);a(this,"rotateWasVisibleBeforeDrag",false);a(this,"rotateCtrlWasAttachedBeforeDrag",false);this.core=o;}attach(o,e){this.detach(),this.boundNode=o,this.keepRatioPredicate=e?.keepRatioCornerOnlyShift??null;let t=this.core.nodes.layer,n=new R.Transformer({rotateEnabled:false,keepRatio:false,rotationSnapTolerance:15,rotationSnaps:[0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345,360],enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"],borderEnabled:true,borderStroke:"#2b83ff",borderStrokeWidth:1.5,name:"overlay-transformer"});t.add(n),n.nodes([o]),n.boundBoxFunc((s,l)=>{let u=Math.max(1,Math.abs(l.width)),h=Math.max(1,Math.abs(l.height));return {...l,width:u,height:h}}),this.tr=n,ue(this.core,n,o);let r=()=>{let s=typeof n.getActiveAnchor=="function"?n.getActiveAnchor():"",l=s==="top-left"||s==="top-right"||s==="bottom-left"||s==="bottom-right",d=this.keepRatioPredicate?this.keepRatioPredicate():false;n.keepRatio(l&&d);};n.on("transformstart.overlayKeepRatio",()=>{r();let s=typeof n.getActiveAnchor=="function"?n.getActiveAnchor():"";if(s==="top-left"||s==="top-right"||s==="bottom-left"||s==="bottom-right"){let d=o instanceof R.Group,u,h,c=0,p=0;if(d){let g=o.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});u=g.width,h=g.height,c=g.x,p=g.y;}else u=o.width(),h=o.height();let f=o.getAbsoluteTransform(),b=0,_=0;s==="top-left"?(b=c+u,_=p+h):s==="top-right"?(b=c,_=p+h):s==="bottom-right"?(b=c,_=p):(b=c+u,_=p),this.transformOppositeCorner=f.point({x:b,y:_});}else this.transformOppositeCorner=null;}),n.on("transform.overlayKeepRatio",r);let i=()=>{if(this.boundNode){if(this.transformOppositeCorner){let s=typeof n.getActiveAnchor=="function"?n.getActiveAnchor():"",l=this.boundNode.getAbsoluteTransform(),d=this.boundNode instanceof R.Group,u,h,c=0,p=0;if(d){let y=this.boundNode.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});u=y.width,h=y.height,c=y.x,p=y.y;}else u=this.boundNode.width(),h=this.boundNode.height();let f=0,b=0;s==="top-left"?(f=c+u,b=p+h):s==="top-right"?(f=c,b=p+h):s==="bottom-right"?(f=c,b=p):s==="bottom-left"&&(f=c+u,b=p);let _=l.point({x:f,y:b}),g=this.transformOppositeCorner.x-_.x,m=this.transformOppositeCorner.y-_.y,v=this.boundNode.getParent();if(v&&(Math.abs(g)>.01||Math.abs(m)>.01)){let y=v.getAbsoluteTransform().copy().invert(),x=this.boundNode.getAbsolutePosition(),w={x:x.x+g,y:x.y+m},N=y.point(w);this.boundNode.position(N);}}this.tr?.forceUpdate(),ue(this.core,this.tr,this.boundNode),this.rotateCtrl?.updatePosition(),this.tr?.moveToTop(),t.batchDraw();}};n.on("transform.overlayFrameTransform",i),n.on("transformend.overlayFrameTransform",()=>{this.transformOppositeCorner=null,i();}),this.ensureSizeLabel(),this.updateSizeLabel(),this.updateHitRect(),this.rotateCtrl&&(this.rotateCtrl.detach(),this.rotateCtrl=null),this.rotateCtrl=new We({core:this.core,getNode:()=>this.boundNode,getTransformer:()=>this.tr,onUpdate:()=>{this.forceUpdate(),this.core.nodes.layer.batchDraw();}}),this.rotateCtrl.attach(),this.rotateCtrl.updatePosition(),this.tr.moveToTop(),t.batchDraw();}detach(){this.tr&&(this.tr.off(".overlayKeepRatio"),this.tr.off(".overlayFrameTransform"),this.tr.destroy(),this.tr=null),this.transformOppositeCorner=null,this.sizeLabel&&(this.sizeLabel.destroy(),this.sizeLabel=null),this.hitRect&&(this.hitRect.destroy(),this.hitRect=null),this.rotateGroup&&(this.rotateGroup.destroy(),this.rotateGroup=null),this.rotateCtrl&&(this.rotateCtrl.detach(),this.rotateCtrl=null);}forceUpdate(){this.boundNode&&(this.tr?.forceUpdate(),ue(this.core,this.tr,this.boundNode),this.rotateCtrl?.updatePosition(),this.tr?.moveToTop(),this.updateSizeLabel(),this.updateHitRect());}onWorldChanged(){this.forceUpdate();}hideOverlaysForDrag(){this.tr?(this.trWasVisibleBeforeDrag=this.tr.visible(),this.tr.visible(false)):this.trWasVisibleBeforeDrag=false,this.sizeLabel?(this.labelWasVisibleBeforeDrag=this.sizeLabel.visible(),this.sizeLabel.visible(false)):this.labelWasVisibleBeforeDrag=false,this.rotateGroup?(this.rotateWasVisibleBeforeDrag=this.rotateGroup.visible(),this.rotateGroup.visible(false)):this.rotateWasVisibleBeforeDrag=false,this.rotateCtrl?(this.rotateCtrlWasAttachedBeforeDrag=true,this.rotateCtrl.detach()):this.rotateCtrlWasAttachedBeforeDrag=false;}restoreOverlaysAfterDrag(){this.tr&&this.trWasVisibleBeforeDrag&&this.tr.visible(true),this.sizeLabel&&this.labelWasVisibleBeforeDrag&&this.sizeLabel.visible(true),this.rotateGroup&&this.rotateWasVisibleBeforeDrag&&this.rotateGroup.visible(true),this.rotateCtrl&&this.rotateCtrlWasAttachedBeforeDrag&&(this.rotateCtrl.attach(),this.rotateCtrl.updatePosition(),this.tr?.moveToTop()),this.trWasVisibleBeforeDrag=false,this.labelWasVisibleBeforeDrag=false,this.rotateWasVisibleBeforeDrag=false,this.rotateCtrlWasAttachedBeforeDrag=false,this.forceUpdate();}ensureSizeLabel(){let o=this.core.nodes.layer;this.sizeLabel&&this.sizeLabel.destroy();let e=new R.Label({listening:false,opacity:.95}),t=new R.Tag({fill:"#2b83ff",cornerRadius:4,lineJoin:"round"}),n=new R.Text({text:"",fontFamily:"Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell",fontSize:12,fill:"#ffffff",padding:6,align:"center"});e.add(t),e.add(n),o.add(e),this.sizeLabel=e;}updateSizeLabel(){if(!this.boundNode||!this.sizeLabel)return;let o=this.core.nodes.world,e=this.boundNode.getClientRect({skipShadow:true,skipStroke:true}),t=e.width/Math.max(1e-6,o.scaleX()),n=e.height/Math.max(1e-6,o.scaleY()),r=Math.max(0,Math.round(t)),i=Math.max(0,Math.round(n));this.sizeLabel.getText().text(String(r)+" \xD7 "+String(i));let l=8,d=e.x+e.width/2,u=e.y+e.height+l,c=this.sizeLabel.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width;this.sizeLabel.setAttrs({x:d-c/2,y:u}),this.sizeLabel.moveToTop();}updateHitRect(){if(!this.boundNode)return;let o=this.core.nodes.layer,e=this.boundNode.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),t={x:e.x,y:e.y},n=e.width,r=e.height;if(!this.hitRect){let i=new R.Rect({name:"overlay-hit",x:t.x,y:t.y,width:n,height:r,fill:"rgba(0,0,0,0.001)",listening:true,perfectDrawEnabled:false});i.on("mousedown.overlayHit",s=>{if(s.evt.button!==0)return;s.cancelBubble=true;let l=this.boundNode;typeof l.startDrag=="function"&&l.startDrag();}),this.boundNode instanceof R.Container?(this.boundNode.add(i),i.moveToBottom(),this.hitRect=i,o.batchDraw()):i.destroy();return}this.hitRect.position(t),this.hitRect.size({width:n,height:r}),this.hitRect.moveToBottom();}};var ge=class{constructor(){a(this,"_scheduled",false);}schedule(o){this._scheduled||(this._scheduled=true,globalThis.requestAnimationFrame(()=>{this._scheduled=false,o();}));}isScheduled(){return this._scheduled}cancel(){this._scheduled=false;}};var fe=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_selected",null);a(this,"_prevDraggable",null);a(this,"_transformer",null);a(this,"_transformerWasVisibleBeforeDrag",false);a(this,"_cornerHandlesWereVisibleBeforeDrag",false);a(this,"_sizeLabelWasVisibleBeforeDrag",false);a(this,"_rotateHandlesWereVisibleBeforeDrag",false);a(this,"_cornerHandlesGroup",null);a(this,"_cornerHandles",{tl:null,tr:null,br:null,bl:null});a(this,"_cornerHandlesSuppressed",false);a(this,"_transformOppositeCorner",null);a(this,"_sizeLabel",null);a(this,"_radiusLabel",null);a(this,"_rotateHandlesGroup",null);a(this,"_rotateHandles",{tl:null,tr:null,br:null,bl:null});a(this,"_rotateDragState",null);a(this,"_rotateCenterAbsStart",null);a(this,"_prevStageDraggableBeforeRotate",null);a(this,"_worldSyncRafId",null);a(this,"_onCameraZoomEvent",null);a(this,"_hoverTr",null);a(this,"_isPointerDown",false);a(this,"_autoPanRafId",null);a(this,"_autoPanActive",false);a(this,"_autoPanEdgePx");a(this,"_autoPanMaxSpeedPx");a(this,"_draggingNode",null);a(this,"_ratioKeyPressed",false);a(this,"_onGlobalKeyDown",null);a(this,"_onGlobalKeyUp",null);a(this,"_tempMultiSet",new Set);a(this,"_tempMultiGroup",null);a(this,"_tempMultiTr",null);a(this,"_tempOverlay",null);a(this,"_tempRotateHandlesGroup",null);a(this,"_tempRotateHandles",{tl:null,tr:null,br:null,bl:null});a(this,"_tempPlacement",new Map);a(this,"_tempMultiSizeLabel",null);a(this,"_tempMultiHitRect",null);a(this,"_multiCtrl",null);a(this,"_parentGroupDuringChildEdit",null);a(this,"_parentGroupPrevDraggable",null);a(this,"_dragMoveScheduled",false);a(this,"_batchDrawScheduled",false);a(this,"_hoverThrottle",new he(16));a(this,"_uiUpdateDebounce",new ge);a(this,"_onMouseDown",e=>{if(!this._core||e.evt.button!==0)return;let t=this._core.stage,n=this._core.nodes.layer;if(e.target===t||e.target.getLayer()!==n){let g=false;if(this._selected){let m=t.getPointerPosition();if(m){let v=this._selected.getNode(),y=v.getClientRect({skipShadow:true,skipStroke:false});if(m.x>=y.x&&m.x<=y.x+y.width&&m.y>=y.y&&m.y<=y.y+y.height&&(g=true,typeof v.startDrag=="function")){let w=v,N=3,k=e.evt.clientX,C=e.evt.clientY,M=typeof w.draggable=="function"?w.draggable():false,z=t.draggable(),V=false,L=D=>{let ee=Math.abs(D.evt.clientX-k),Z=Math.abs(D.evt.clientY-C);!V&&(ee>N||Z>N)&&(V=true,typeof w.draggable=="function"&&!M&&w.draggable(true),v.on("dragstart.selection-once-bbox",()=>{t.draggable(false);}),v.on("dragend.selection-once-bbox",()=>{t.draggable(z),typeof w.draggable=="function"&&w.draggable(this._options.dragEnabled?true:M),this._selected&&(this._refreshTransformer(),this._core?.nodes.layer.batchDraw()),v.off(".selection-once-bbox");}),v.startDrag(),e.cancelBubble=true);},T=()=>{!V&&this._options.deselectOnEmptyClick&&this._clearSelection(),t.off("mousemove.selection-once-bbox"),t.off("mouseup.selection-once-bbox");};t.on("mousemove.selection-once-bbox",L),t.on("mouseup.selection-once-bbox",T);}}}g||this._options.deselectOnEmptyClick&&this._clearSelection();return}let r=e.target;if(!this._options.selectablePredicate(r))return;let i=this._findBaseNodeByTarget(r);if(!i)return;if(this._selected){let g=this._selected.getNode();((v,y)=>{let x=y;for(;x;){if(x===v)return true;x=x.getParent();}return false})(g,r)&&(i=this._selected);}let s=i.getNode(),l=3,d=e.evt.clientX,u=e.evt.clientY,h=false,c=g=>{if(h)return;let m=Math.abs(g.evt.clientX-d),v=Math.abs(g.evt.clientY-u);(m>l||v>l)&&(h=true,typeof s.startDrag=="function"&&s.startDrag(),this._core?.stage.off("mousemove.selection-once"),this._core?.stage.off("mouseup.selection-once"));},p=()=>{this._core?.stage.off("mousemove.selection-once"),this._core?.stage.off("mouseup.selection-once");};if(this._core.stage.on("mousemove.selection-once",c),this._core.stage.on("mouseup.selection-once",p),typeof s.isDragging=="function"&&s.isDragging())return;let f=typeof s.draggable=="function",b=f?s.draggable():false,_=t.draggable();f&&s.draggable(true),s.on("dragstart.selection-once",()=>{t.draggable(false);}),s.on("dragend.selection-once",()=>{t.draggable(_),f&&(this._options.dragEnabled?s.draggable(true):s.draggable(b)),this._select(i);});});a(this,"_onHoverMoveThrottled",e=>{this._hoverThrottle.shouldExecute()&&this._onHoverMove(e);});a(this,"_onHoverMove",e=>{if(!this._core)return;let t=this._core.stage,n=this._core.nodes.layer,r=e.target;if((()=>{if(!!!this._tempMultiGroup){let v=r;for(;v;){if(v instanceof R.Group&&typeof v.name=="function"){let y=v.name();if(typeof y=="string"&&(y.includes("temp-multi-group")||y.includes("area-temp-group")))return true}v=v.getParent();}return false}let m=r;for(;m;){if(m===this._tempMultiGroup)return true;m=m.getParent();}return false})()){this._destroyHoverTr();return}let s=typeof e.evt.buttons=="number"?e.evt.buttons:0;if(this._isPointerDown||s&1){this._destroyHoverTr();return}if(r===t||r.getLayer()!==n){this._destroyHoverTr();return}let l=this._core.nodes.list().map(g=>g.getNode()),d=new Set(l),u=g=>{let m=g;for(;m;){if(d.has(m))return m;m=m.getParent();}return null},c=(g=>{let m=g,v=null;for(;m;)d.has(m)&&m instanceof R.Group&&(v=m),m=m.getParent();return v})(r),p=u(r),f=e.evt.ctrlKey,b=f?p??c:c??p;if(!f&&this._selected&&p&&!(this._selected.getNode()instanceof R.Group)){let g=this._selected.getNode();c&&((v,y,x)=>{if(!x)return false;let w=(N,k)=>{let C=k;for(;C;){if(C===N)return true;C=C.getParent();}return false};return w(x,v)&&w(x,y)})(g,p,c)&&g!==p&&(b=p);}if(!b){this._destroyHoverTr();return}if(!this._options.selectablePredicate(b)){this._destroyHoverTr();return}if(this._selected){let g=this._selected.getNode();if(f?b===g:b===g||((y,x)=>{let w=x;for(;w;){if(w===y)return true;w=w.getParent();}return false})(g,b)){this._destroyHoverTr();return}}let _=this._ensureHoverTr();_.nodes([b]),_.visible(true),_.moveToTop(),n.batchDraw();});a(this,"_onHoverDown",()=>{this._isPointerDown=true,this._destroyHoverTr();});a(this,"_onHoverUp",()=>{this._isPointerDown=false;});a(this,"_onHoverLeave",e=>{this._destroyHoverTr();});a(this,"_onNodeRemoved",e=>{this._selected&&this._selected===e&&this._clearSelection();});let{dragEnabled:t=true,enableTransformer:n=true,deselectOnEmptyClick:r=true,selectablePredicate:i}=e;this._options={dragEnabled:t,enableTransformer:n,deselectOnEmptyClick:r,selectablePredicate:i??(()=>true),autoPanEnabled:e.autoPanEnabled??true,autoPanEdgePx:e.autoPanEdgePx??40,autoPanMaxSpeedPx:e.autoPanMaxSpeedPx??24},this._autoPanEdgePx=this._options.autoPanEdgePx,this._autoPanMaxSpeedPx=this._options.autoPanMaxSpeedPx;}getMultiGroupController(){if(!this._core)throw new Error("Core is not attached");return this._multiCtrl??(this._multiCtrl=new Ee({ensureTempMulti:e=>{this._ensureTempMulti(e);},destroyTempMulti:()=>{this._destroyTempMulti();},commitTempMultiToGroup:()=>{this._commitTempMultiToGroup();},isActive:()=>!!this._tempMultiGroup||this._tempMultiSet.size>0,forceUpdate:()=>{this._tempOverlay?.forceUpdate();},onWorldChanged:()=>{this._tempOverlay?.onWorldChanged();},isInsideTempByTarget:e=>this._tempMultiGroup?e===this._tempMultiGroup?true:e.isAncestorOf(this._tempMultiGroup)||this._tempMultiGroup.isAncestorOf(e):false})),this._multiCtrl}_startAutoPanLoop(){if(!this._core||this._autoPanRafId!=null)return;this._autoPanActive=true;let e=this._core.nodes.world,t=this._core.stage,n=()=>{if(this._autoPanRafId=null,!this._core||!this._autoPanActive)return;let r=t.getPointerPosition();if(r){let i=t.width(),s=t.height(),l=this._autoPanEdgePx,d=0,u=0,h=Math.max(0,l-r.x),c=Math.max(0,r.x-(i-l)),p=Math.max(0,l-r.y),f=Math.max(0,r.y-(s-l)),b=_=>Math.min(1,_/l);if(d=this._autoPanMaxSpeedPx*(b(c)-b(h)),u=this._autoPanMaxSpeedPx*(b(f)-b(p)),d!==0||u!==0){if(e.x(e.x()-d),e.y(e.y()-u),this._draggingNode&&typeof this._draggingNode.setAbsolutePosition=="function"){let _=this._draggingNode.getAbsolutePosition();this._draggingNode.setAbsolutePosition({x:_.x+d,y:_.y+u}),this._transformer?.forceUpdate();}this._core.nodes.layer.batchDraw();}}this._autoPanRafId=globalThis.requestAnimationFrame(n);};this._autoPanRafId=globalThis.requestAnimationFrame(n);}_stopAutoPanLoop(){this._autoPanActive=false,this._autoPanRafId!=null&&(globalThis.cancelAnimationFrame(this._autoPanRafId),this._autoPanRafId=null);}_scheduleBatchDraw(){if(this._batchDrawScheduled)return;this._batchDrawScheduled=true;let e=globalThis.requestAnimationFrame;e(()=>{this._batchDrawScheduled=false,this._core?.stage.batchDraw();});}setOptions(e){this._options={...this._options,...e},this._core&&this._refreshTransformer(),typeof e.autoPanEdgePx=="number"&&(this._autoPanEdgePx=e.autoPanEdgePx),typeof e.autoPanMaxSpeedPx=="number"&&(this._autoPanMaxSpeedPx=e.autoPanMaxSpeedPx),e.autoPanEnabled===false&&this._stopAutoPanLoop();}onAttach(e){this._core=e,this._multiCtrl=new Ee({ensureTempMulti:s=>{this._ensureTempMulti(s);},destroyTempMulti:()=>{this._destroyTempMulti();},commitTempMultiToGroup:()=>{this._commitTempMultiToGroup();},isActive:()=>!!this._tempMultiGroup,isInsideTempByTarget:s=>{if(!this._tempMultiGroup)return false;let l=s;for(;l;){if(l===this._tempMultiGroup)return true;l=l.getParent();}return false},forceUpdate:()=>{this._tempMultiTr?.forceUpdate(),this._updateTempMultiSizeLabel(),this._updateTempMultiHitRect(),this._updateTempRotateHandlesPosition(),this._scheduleBatchDraw();},onWorldChanged:()=>{this._tempMultiTr?.forceUpdate(),this._updateTempMultiSizeLabel(),this._updateTempMultiHitRect(),this._updateTempRotateHandlesPosition(),this._scheduleBatchDraw(),this._destroyHoverTr();}});let t=e.stage;t.on("mousedown.selection",this._onMouseDown),t.on("click.selection",s=>{if(!this._core)return;let l=this._core.stage,d=this._core.nodes.layer;if(s.evt.button!==0)return;if(s.target===l||s.target.getLayer()!==d){this._options.deselectOnEmptyClick&&(this._destroyTempMulti(),this._clearSelection());return}let u=s.target;if(!this._options.selectablePredicate(u))return;if(s.evt.shiftKey||s.evt.ctrlKey||s.evt.metaKey){let c=this._findBaseNodeByTarget(u);if(!c)return;let f=c.getNode().getParent();if(f&&f instanceof R.Group&&f!==this._core.nodes.world)return;if(this._tempMultiSet.size===0&&this._selected&&this._selected!==c&&(this._tempMultiSet.add(this._selected),this._transformer&&(this._transformer.destroy(),this._transformer=null),this._destroyCornerRadiusHandles(),this._destroyRotateHandles(),this._destroySizeLabel(),this._selected=null),Array.from(this._tempMultiSet).includes(c)?this._tempMultiSet.delete(c):this._tempMultiSet.add(c),this._tempMultiSet.size===0){this._destroyTempMulti(),this._clearSelection();return}if(this._tempMultiSet.size===1){let _=this._tempMultiSet.values().next(),g=_.done?null:_.value;if(!g)return;this._destroyTempMulti(),this._select(g),this._scheduleBatchDraw();return}this._ensureTempMulti(Array.from(this._tempMultiSet)),this._scheduleBatchDraw();return}let h=this._findBaseNodeByTarget(u);h&&(this._destroyTempMulti(),this._select(h),this._scheduleBatchDraw());}),t.on("dblclick.selection",s=>{if(!this._core)return;let l=this._core.nodes.layer;if(s.target===t||s.target.getLayer()!==l||s.evt.button!==0||!this._selected)return;let d=this._selected.getNode();if(d instanceof R.Group&&typeof d.isAncestorOf=="function"&&d.isAncestorOf(s.target)){s.cancelBubble=true;let u=null;for(let h of this._core.nodes.list()){let c=h.getNode();if(typeof d.isAncestorOf=="function"&&d.isAncestorOf(c)&&c!==d&&typeof c.isAncestorOf=="function"&&c.isAncestorOf(s.target)){let p=true;for(let f of this._core.nodes.list()){if(f===h)continue;let b=f.getNode();if(typeof d.isAncestorOf=="function"&&d.isAncestorOf(b)&&typeof c.isAncestorOf=="function"&&c.isAncestorOf(b)&&typeof b.isAncestorOf=="function"&&b.isAncestorOf(s.target)){p=false;break}}if(p){u=h;break}}}if(u??(u=this._core.nodes.list().find(h=>h.getNode()===s.target)??null),u){this._select(u);let h=u.getNode();typeof h.draggable=="function"&&h.draggable(true),d instanceof R.Group&&(this._parentGroupDuringChildEdit=d,this._parentGroupPrevDraggable=typeof d.draggable=="function"?d.draggable():null,typeof d.draggable=="function"&&d.draggable(false)),this._core.stage.batchDraw();}}}),e.eventBus.on("node:removed",this._onNodeRemoved),t.on("mousemove.hover",this._onHoverMoveThrottled),t.on("mouseleave.hover",this._onHoverLeave),t.on("mousedown.hover",this._onHoverDown),t.on("mouseup.hover",this._onHoverUp),t.on("touchstart.hover",this._onHoverDown),t.on("touchend.hover",this._onHoverUp),this._core.nodes.layer.on("dragstart.hover",()=>{this._destroyHoverTr();}),this._core.nodes.layer.on("dragmove.hover",()=>{this._destroyHoverTr();});let n=this._core.nodes.layer;n.on("dragstart.selectionAutoPan",s=>{if(!this._options.autoPanEnabled)return;let l=s.target;this._options.selectablePredicate(l)&&(this._draggingNode=l,this._startAutoPanLoop());}),n.on("dragend.selectionAutoPan",()=>{this._draggingNode=null,this._stopAutoPanLoop();});let r=this._core.nodes.world,i=()=>{this._core&&this._worldSyncRafId==null&&(this._worldSyncRafId=globalThis.requestAnimationFrame(()=>{this._worldSyncRafId=null,this._core&&((this._transformer||this._cornerHandlesGroup||this._rotateHandlesGroup||this._sizeLabel||this._tempMultiGroup)&&(this._transformer?.forceUpdate(),this._hoverTr?.forceUpdate(),this._restyleSideAnchors(),this._updateCornerRadiusHandlesPosition(),this._updateRotateHandlesPosition(),this._updateSizeLabel(),this._updateCornerRadiusHandlesVisibility(),this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw()),this._destroyHoverTr());}));};r.on("xChange.selectionCamera yChange.selectionCamera scaleXChange.selectionCamera scaleYChange.selectionCamera",i),this._onCameraZoomEvent=()=>{i();},e.eventBus.on("camera:zoom",this._onCameraZoomEvent),e.eventBus.on("camera:setZoom",this._onCameraZoomEvent),e.eventBus.on("camera:reset",this._onCameraZoomEvent),this._onGlobalKeyDown=s=>{s.key==="Shift"&&(this._ratioKeyPressed=true);let l=s.ctrlKey||s.metaKey;l&&!s.shiftKey&&s.code==="KeyG"&&(s.preventDefault(),this._commitTempMultiToGroup()),l&&s.shiftKey&&s.code==="KeyG"&&(s.preventDefault(),this._tryUngroupSelectedGroup());},this._onGlobalKeyUp=s=>{s.key==="Shift"&&(this._ratioKeyPressed=false);},globalThis.addEventListener("keydown",this._onGlobalKeyDown),globalThis.addEventListener("keyup",this._onGlobalKeyUp);}onDetach(e){this._destroyTempMulti(),this._clearSelection(),e.stage.off(".selection"),e.stage.off(".hover"),this._core?.nodes.layer.off(".hover"),this._core?.nodes.world.off(".selectionCamera"),this._core?.nodes.layer.off(".selectionAutoPan"),this._worldSyncRafId!=null&&(globalThis.cancelAnimationFrame(this._worldSyncRafId),this._worldSyncRafId=null),this._onCameraZoomEvent&&(e.eventBus.off("camera:zoom",this._onCameraZoomEvent),e.eventBus.off("camera:setZoom",this._onCameraZoomEvent),e.eventBus.off("camera:reset",this._onCameraZoomEvent),this._onCameraZoomEvent=null),e.eventBus.off("node:removed",this._onNodeRemoved),this._destroyHoverTr(),this._onGlobalKeyDown&&globalThis.removeEventListener("keydown",this._onGlobalKeyDown),this._onGlobalKeyUp&&globalThis.removeEventListener("keyup",this._onGlobalKeyUp),this._onGlobalKeyDown=null,this._onGlobalKeyUp=null;}_select(e){if(!this._core)return;let t=this._core;this._clearSelection();let n=e.getNode();this._prevDraggable=n.draggable(),this._options.dragEnabled&&typeof n.draggable=="function"&&n.draggable(true),this._selected=e,this._refreshTransformer(),t.eventBus.emit("node:selected",e),n.on("dragstart.selection",()=>{this._draggingNode=n,this._transformer&&(this._transformerWasVisibleBeforeDrag=this._transformer.visible(),this._transformer.visible(false)),this._cornerHandlesGroup&&(this._cornerHandlesWereVisibleBeforeDrag=this._cornerHandlesGroup.visible(),this._cornerHandlesGroup.visible(false)),this._rotateHandlesGroup&&(this._rotateHandlesWereVisibleBeforeDrag=this._rotateHandlesGroup.visible(),this._rotateHandlesGroup.visible(false)),this._sizeLabel&&(this._sizeLabelWasVisibleBeforeDrag=this._sizeLabel.visible(),this._sizeLabel.visible(false)),this._core?.stage.batchDraw(),this._startAutoPanLoop();}),n.on("dragmove.selection",()=>{if(this._dragMoveScheduled)return;this._dragMoveScheduled=true;let r=globalThis.requestAnimationFrame;r(()=>{this._dragMoveScheduled=false,this._scheduleBatchDraw();});}),n.on("dragend.selection",()=>{let r={};typeof n.x=="function"&&(r.x=n.x()),typeof n.y=="function"&&(r.y=n.y()),typeof n.width=="function"&&(r.width=n.width()),typeof n.height=="function"&&(r.height=n.height()),typeof n.rotation=="function"&&(r.rotation=n.rotation()),typeof n.scaleX=="function"&&(r.scaleX=n.scaleX()),typeof n.scaleY=="function"&&(r.scaleY=n.scaleY()),t.eventBus.emit("node:transformed",e,r);}),n.on("transformend.selection",()=>{let r={};typeof n.x=="function"&&(r.x=n.x()),typeof n.y=="function"&&(r.y=n.y()),typeof n.width=="function"&&(r.width=n.width()),typeof n.height=="function"&&(r.height=n.height()),typeof n.rotation=="function"&&(r.rotation=n.rotation()),typeof n.scaleX=="function"&&(r.scaleX=n.scaleX()),typeof n.scaleY=="function"&&(r.scaleY=n.scaleY()),this._core?.eventBus.emit("node:transformed",e,r);}),n.on("dragend.selection",()=>{this._draggingNode=null,this._transformer&&(this._transformerWasVisibleBeforeDrag&&this._transformer.visible(true),this._transformerWasVisibleBeforeDrag=false),this._cornerHandlesGroup&&(this._cornerHandlesWereVisibleBeforeDrag&&this._cornerHandlesGroup.visible(true),this._cornerHandlesWereVisibleBeforeDrag=false),this._rotateHandlesGroup&&(this._rotateHandlesWereVisibleBeforeDrag&&this._rotateHandlesGroup.visible(true),this._rotateHandlesWereVisibleBeforeDrag=false),this._sizeLabel&&(this._sizeLabelWasVisibleBeforeDrag&&this._sizeLabel.visible(true),this._sizeLabelWasVisibleBeforeDrag=false),this._stopAutoPanLoop(),this._select(e),this._core?.stage.batchDraw();}),n.on("mousedown.selection",r=>{let i=r.evt.button;(i===1||i===2)&&typeof n.draggable=="function"&&n.draggable(false);});}_clearSelection(){if(!this._selected)return;let e=this._selected,t=this._selected.getNode();if(typeof t.draggable=="function"&&this._prevDraggable!==null&&t.draggable(this._prevDraggable),this._prevDraggable=null,this._parentGroupDuringChildEdit){let n=this._parentGroupDuringChildEdit;typeof n.draggable=="function"&&this._parentGroupPrevDraggable!==null&&n.draggable(this._parentGroupPrevDraggable),this._parentGroupDuringChildEdit=null,this._parentGroupPrevDraggable=null;}t.off(".selection"),t.off(".selection-once"),this._destroyCornerRadiusHandles(),this._destroyRotateHandles(),this._destroySizeLabel(),this._transformer&&(this._transformer.destroy(),this._transformer=null),this._selected=null,this._core&&(this._core.eventBus.emit("node:deselected",e),this._core.eventBus.emit("selection:cleared")),this._core?.stage.batchDraw();}_ensureTempMulti(e){if(!this._core)return;let t=this._core.nodes.world;this._tempMultiSet.clear();for(let s of e)this._tempMultiSet.add(s);if(!this._tempMultiGroup){let s=new R.Group({name:"temp-multi-group"});t.add(s),this._tempMultiGroup=s,this._tempPlacement.clear();for(let h of e){let c=h.getNode(),p=c.getParent();if(!p)continue;let f=c.zIndex(),b=c.getAbsolutePosition(),_=typeof c.draggable=="function"?c.draggable():null;this._tempPlacement.set(c,{parent:p,indexInParent:f,abs:b,prevDraggable:_}),s.add(c),c.setAbsolutePosition(b),typeof c.draggable=="function"&&c.draggable(false),c.off(".tempMultiChild"),c.on("dragstart.tempMultiChild",g=>{g.cancelBubble=true;let m=c;typeof m.stopDrag=="function"&&m.stopDrag();}),c.on("mousedown.tempMultiChild",g=>{if(g.evt.button!==0)return;g.cancelBubble=true;let m=s;typeof m.startDrag=="function"&&m.startDrag();});}this._tempOverlay??(this._tempOverlay=new Xe(this._core)),this._tempOverlay.attach(s,{keepRatioCornerOnlyShift:()=>this._ratioKeyPressed});let l=this._core.stage,d=l.draggable();s.draggable(true);let u=()=>{this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw();};s.on("dragstart.tempMulti",()=>{l.draggable(false),this._draggingNode=s,this._startAutoPanLoop(),this._tempOverlay?.hideOverlaysForDrag(),u();}),s.on("dragmove.tempMulti",u),s.on("transform.tempMulti",u),s.on("dragend.tempMulti",()=>{l.draggable(d),this._draggingNode=null,this._stopAutoPanLoop(),this._tempOverlay?.restoreOverlaysAfterDrag(),u();}),this._core.eventBus.emit("selection:multi:created",e);return}let n=[...this._tempMultiGroup.getChildren()],r=e.map(s=>s.getNode());n.length===r.length&&r.every(s=>n.includes(s))||(this._destroyTempMulti(),this._ensureTempMulti(e));}_destroyTempMulti(){if(this._core&&!(!this._tempMultiGroup&&this._tempMultiSet.size===0)){if(this._tempOverlay&&(this._tempOverlay.detach(),this._tempOverlay=null),this._tempMultiGroup){this._tempMultiGroup.off(".tempMulti");let e=[...this._tempMultiGroup.getChildren()];for(let t of e){t.off(".tempMultiChild");let n=this._tempPlacement.get(t),r=t.getAbsoluteTransform().copy(),i=n?.parent??this._core.nodes.world;t.moveTo(i);let s=i.getAbsoluteTransform().copy();s.invert();let d=s.multiply(r).decompose();if(typeof t.position=="function"?t.position({x:d.x,y:d.y}):t.setAbsolutePosition({x:d.x,y:d.y}),typeof t.rotation=="function"&&t.rotation(d.rotation),typeof t.scale=="function"&&t.scale({x:d.scaleX,y:d.scaleY}),n){let u=t.zIndex(),h=n.indexInParent;if(u!==h){let c=h-u;if(c>0)for(let p=0;p<c&&t.zIndex()<n.parent.children.length-1;p++)t.moveUp();else if(c<0)for(let p=0;p<Math.abs(c)&&t.zIndex()>0;p++)t.moveDown();}typeof t.draggable=="function"&&n.prevDraggable!==null&&t.draggable(n.prevDraggable);}}this._tempMultiGroup.destroy(),this._tempMultiGroup=null;}this._tempPlacement.clear(),this._tempMultiSet.clear(),this._core.eventBus.emit("selection:multi:destroyed");}}_updateTempRotateHandlesPosition(){if(!this._core||!this._tempMultiGroup||!this._tempRotateHandlesGroup)return;let e=this._tempMultiGroup,t=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),n=t.width,r=t.height;if(n<=0||r<=0)return;let i=e.getAbsoluteTransform().copy(),s=N=>i.point(N),l=12,d=s({x:t.x+n/2,y:t.y+r/2}),u=s({x:t.x,y:t.y}),h=s({x:t.x+n,y:t.y}),c=s({x:t.x+n,y:t.y+r}),p=s({x:t.x,y:t.y+r}),f=N=>{let k=N.x-d.x,C=N.y-d.y,M=Math.hypot(k,C)||1;return {x:k/M,y:C/M}},b=f(u),_=f(h),g=f(c),m=f(p),v={x:u.x+b.x*l,y:u.y+b.y*l},y={x:h.x+_.x*l,y:h.y+_.y*l},x={x:c.x+g.x*l,y:c.y+g.y*l},w={x:p.x+m.x*l,y:p.y+m.y*l};this._tempRotateHandles.tl&&this._tempRotateHandles.tl.absolutePosition(v),this._tempRotateHandles.tr&&this._tempRotateHandles.tr.absolutePosition(y),this._tempRotateHandles.br&&this._tempRotateHandles.br.absolutePosition(x),this._tempRotateHandles.bl&&this._tempRotateHandles.bl.absolutePosition(w),this._tempRotateHandlesGroup.moveToTop();}_updateTempMultiSizeLabel(){if(!this._core||!this._tempMultiGroup||!this._tempMultiSizeLabel)return;let e=this._core.nodes.world,t=this._tempMultiGroup.getClientRect({skipShadow:true,skipStroke:true}),n=t.width/Math.max(1e-6,e.scaleX()),r=t.height/Math.max(1e-6,e.scaleY()),i=Math.max(0,Math.round(n)),s=Math.max(0,Math.round(r));this._tempMultiSizeLabel.getText().text(String(i)+" \xD7 "+String(s));let d=8,u=t.x+t.width/2,h=t.y+t.height+d,p=this._tempMultiSizeLabel.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width;this._tempMultiSizeLabel.setAttrs({x:u-p/2,y:h}),this._tempMultiSizeLabel.moveToTop();}_updateTempMultiHitRect(){if(!this._core||!this._tempMultiGroup)return;let e=this._core.nodes.layer,t=this._tempMultiGroup.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),n={x:t.x,y:t.y},r=t.width,i=t.height;if(!this._tempMultiHitRect){let s=new R.Rect({name:"temp-multi-hit",x:n.x,y:n.y,width:r,height:i,fill:"rgba(0,0,0,0.001)",listening:true,perfectDrawEnabled:false});s.on("mousedown.tempMultiHit",l=>{if(l.evt.button!==0)return;l.cancelBubble=true;let d=this._tempMultiGroup;typeof d.startDrag=="function"&&d.startDrag();}),this._tempMultiGroup.add(s),s.moveToBottom(),this._tempMultiHitRect=s,e.batchDraw();return}this._tempMultiHitRect.position(n),this._tempMultiHitRect.size({width:r,height:i}),this._tempMultiHitRect.moveToBottom();}_commitTempMultiToGroup(){if(!this._core||!this._tempMultiGroup||this._tempMultiSet.size<2)return;let e=this._core.nodes,t=this._tempMultiGroup.getAbsolutePosition(),n=e.addGroup({x:t.x,y:t.y,draggable:true}),r=n.getNode(),i=[...this._tempMultiGroup.getChildren()],s=[],l=i.sort((p,f)=>p.zIndex()-f.zIndex()),d=Math.max(...l.map(p=>p.zIndex()));for(let p of l){p.off(".tempMultiChild");let f=p.getAbsolutePosition();r.add(p),p.setAbsolutePosition(f),typeof p.draggable=="function"&&p.draggable(false);let b=this._core.nodes.list().find(_=>_.getNode()===p);b&&s.push(b);}let u=this._core.nodes.world,h=r.zIndex(),c=d;if(h<c){let p=c-h;for(let f=0;f<p&&r.zIndex()<u.children.length-1;f++)r.moveUp();}this._tempMultiTr&&(this._tempMultiTr.destroy(),this._tempMultiTr=null),this._tempOverlay&&(this._tempOverlay.detach(),this._tempOverlay=null),this._tempMultiGroup.off(".tempMulti"),this._tempMultiGroup.destroy(),this._tempMultiGroup=null,this._tempPlacement.clear(),this._tempMultiSet.clear(),typeof r.draggable=="function"&&r.draggable(true),this._core.eventBus.emit("group:created",n,s),this._select(n),this._core.stage.batchDraw();}_tryUngroupSelectedGroup(){if(!this._core||!this._selected)return;let e=this._selected.getNode();if(!(e instanceof R.Group))return;let t=[...e.getChildren()],n=this._core.nodes.world;for(let i of t){let s=i.getAbsoluteTransform().copy();n.add(i);let l=n.getAbsoluteTransform().copy();l.invert();let u=l.multiply(s).decompose();typeof i.position=="function"?i.position({x:u.x,y:u.y}):i.setAbsolutePosition({x:u.x,y:u.y}),typeof i.rotation=="function"&&i.rotation(u.rotation),typeof i.scale=="function"&&i.scale({x:u.scaleX,y:u.scaleY}),typeof i.draggable=="function"&&i.draggable(true);}let r=this._selected;this._selected=null,this._transformer?.destroy(),this._transformer=null,this._destroySizeLabel(),this._core.nodes.remove(r),this._core.stage.batchDraw();}_ensureHoverTr(){if(!this._core)throw new Error("Core is not attached");if(this._hoverTr?.getParent())return this._hoverTr;let e=new R.Transformer({rotateEnabled:false,enabledAnchors:[],rotationSnaps:[0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345,360],borderEnabled:true,borderStroke:"#2b83ff",borderStrokeWidth:1.5,listening:false,name:"hover-transformer"});return this._core.nodes.layer.add(e),this._hoverTr=e,e}_destroyHoverTr(){this._hoverTr&&(this._hoverTr.destroy(),this._hoverTr=null);}_refreshTransformer(){if(!this._core||(this._transformer&&(this._transformer.destroy(),this._transformer=null),!this._options.enableTransformer||!this._selected))return;let e=this._core.nodes.layer,t=new R.Transformer({rotateEnabled:false,rotationSnapTolerance:15,flipEnabled:false,keepRatio:false,rotationSnaps:[0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345,360],enabledAnchors:["top-left","top-center","top-right","middle-right","bottom-right","bottom-center","bottom-left","middle-left"]});e.add(t),t.nodes([this._selected.getNode()]),t.boundBoxFunc((s,l)=>{let u=l.width,h=l.height,c=l.x,p=l.y;return (u<0||u<1)&&(u=1),(h<0||h<1)&&(h=1),{...l,x:c,y:p,width:u,height:h}}),this._transformer=t,this._restyleSideAnchors(),this._setupCornerRadiusHandles(false),this._setupRotateHandles(),this._setupSizeLabel();let n=()=>{let s=typeof t.getActiveAnchor=="function"?t.getActiveAnchor():"",l=s==="top-left"||s==="top-right"||s==="bottom-left"||s==="bottom-right";t.keepRatio(l&&this._ratioKeyPressed);};t.on("transformstart.keepratio",()=>{n(),this._cornerHandlesSuppressed=true,this._cornerHandlesGroup?.visible(false),this._hideRadiusLabel();let s=this._selected?.getNode(),l=typeof t.getActiveAnchor=="function"?t.getActiveAnchor():"";if(s&&(l==="top-left"||l==="top-right"||l==="bottom-left"||l==="bottom-right")){let u=s instanceof R.Group,h,c,p=0,f=0;if(u){let m=s.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});h=m.width,c=m.height,p=m.x,f=m.y;}else h=s.width(),c=s.height();let b=s.getAbsoluteTransform(),_=0,g=0;l==="top-left"?(_=p+h,g=f+c):l==="top-right"?(_=p,g=f+c):l==="bottom-right"?(_=p,g=f):(_=p+h,g=f),this._transformOppositeCorner=b.point({x:_,y:g});}else this._transformOppositeCorner=null;}),t.on("transform.keepratio",n),t.on("transform.corner-sync",()=>{let s=this._selected?.getNode();if(s&&(this._bakeRectScale(s),this._transformOppositeCorner)){let l=typeof t.getActiveAnchor=="function"?t.getActiveAnchor():"",d=s.getAbsoluteTransform(),u=s instanceof R.Group,h,c,p=0,f=0;if(u){let x=s.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});h=x.width,c=x.height,p=x.x,f=x.y;}else h=s.width(),c=s.height();let b=0,_=0;l==="top-left"?(b=p+h,_=f+c):l==="top-right"?(b=p,_=f+c):l==="bottom-right"?(b=p,_=f):l==="bottom-left"&&(b=p+h,_=f);let g=d.point({x:b,y:_}),m=this._transformOppositeCorner.x-g.x,v=this._transformOppositeCorner.y-g.y,y=s.getParent();if(y&&(Math.abs(m)>.01||Math.abs(v)>.01)){let x=y.getAbsoluteTransform().copy().invert(),w=s.getAbsolutePosition(),N={x:w.x+m,y:w.y+v},k=x.point(N);s.position(k);}}this._restyleSideAnchors(),this._scheduleUIUpdate(),this._updateTempRotateHandlesPosition(),this._core?.nodes.layer.batchDraw();}),t.on("transformend.corner-sync",()=>{this._cornerHandlesSuppressed=false,this._transformOppositeCorner=null,this._restyleSideAnchors(),this._scheduleUIUpdate(),this._core?.nodes.layer.batchDraw();});let r=this._selected.getNode();r.off(".overlay-sync");let i=()=>{this._restyleSideAnchors(),this._scheduleUIUpdate(),this._scheduleBatchDraw();};r.on("widthChange.overlay-sync heightChange.overlay-sync scaleXChange.overlay-sync scaleYChange.overlay-sync rotationChange.overlay-sync xChange.overlay-sync yChange.overlay-sync",i),this._scheduleBatchDraw();}_restyleSideAnchors(){if(!this._core||!this._selected||!this._transformer)return;let e=this._selected.getNode();ue(this._core,this._transformer,e);}_setupRotateHandles(){if(!this._core||!this._selected)return;let e=this._core.nodes.layer;this._destroyRotateHandles();let t=new R.Group({name:"rotate-handles-group",listening:true});e.add(t),t.moveToTop(),this._rotateHandlesGroup=t;let n=ie("rotate-tl"),r=ie("rotate-tr"),i=ie("rotate-br"),s=ie("rotate-bl");t.add(n),t.add(r),t.add(i),t.add(s),this._rotateHandles={tl:n,tr:r,br:i,bl:s};let l=u=>{u.on("dragstart.rotate",()=>{if(!this._selected)return;let h=this._selected.getNode(),c=h.getAbsoluteTransform().decompose(),p=this._getNodeCenterAbs(h);this._rotateCenterAbsStart=p;let f=this._core?.stage.getPointerPosition()??u.getAbsolutePosition(),b=Math.atan2(f.y-p.y,f.x-p.x)*180/Math.PI;this._rotateDragState={base:c.rotation||0,start:b},this._core&&(this._prevStageDraggableBeforeRotate=this._core.stage.draggable()),typeof h.draggable=="function"&&h.draggable(false),this._core?.stage.draggable(false),this._core&&(this._core.stage.container().style.cursor="grabbing");}),u.on("dragmove.rotate",h=>{if(!this._core||!this._selected||!this._rotateDragState)return;let c=this._selected.getNode(),p=this._rotateCenterAbsStart??this._getNodeCenterAbs(c),f=this._core.stage.getPointerPosition()??u.getAbsolutePosition(),b=Math.atan2(f.y-p.y,f.x-p.x)*180/Math.PI,_=this._rotateDragState.base+(b-this._rotateDragState.start),g=v=>{let y=v%360;return y<0&&(y+=360),y},m=(v,y)=>g(v-y+180)-180;if(h.evt.shiftKey){let v=this._transformer,y,x=5;if(v){let w=v.rotationSnaps();Array.isArray(w)&&(y=w.map(k=>g(k)));let N=v.rotationSnapTolerance();typeof N=="number"&&(x=N);}if(y?.length){let w=g(_),N=_,k=1/0;for(let C of y){let M=Math.abs(m(w,C));M<k&&M<=x&&(N=C,k=M);}k!==1/0&&(_=N);}}if(c.rotation(_),this._rotateCenterAbsStart){let v=this._getNodeCenterAbs(c),y=this._rotateCenterAbsStart.x-v.x,x=this._rotateCenterAbsStart.y-v.y,w=c.getParent();if(w){let N=w.getAbsoluteTransform().copy().invert(),k=N.point({x:v.x,y:v.y}),C=N.point({x:v.x+y,y:v.y+x}),M=c.x()+(C.x-k.x),z=c.y()+(C.y-k.y);typeof c.position=="function"&&c.position({x:M,y:z});}}this._transformer?.forceUpdate(),this._restyleSideAnchors(),this._core.nodes.layer.batchDraw(),this._scheduleUIUpdate();}),u.on("dragend.rotate",()=>{if(this._rotateDragState=null,this._rotateCenterAbsStart=null,this._selected){let h=this._selected.getNode();this._options.dragEnabled&&typeof h.draggable=="function"&&h.draggable(true);}this._core&&this._prevStageDraggableBeforeRotate!==null&&(this._core.stage.draggable(this._prevStageDraggableBeforeRotate),this._prevStageDraggableBeforeRotate=null),this._restyleSideAnchors(),this._scheduleUIUpdate(),this._core?.nodes.layer.batchDraw(),this._core&&(this._core.stage.container().style.cursor="grab");});};l(n),l(r),l(i),l(s);let d=u=>{this._core&&(this._core.stage.container().style.cursor=u);};this._rotateHandles.tl&&(this._rotateHandles.tl.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.tl.on("mouseleave.rotate-cursor",()=>{d("default");})),this._rotateHandles.tr&&(this._rotateHandles.tr.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.tr.on("mouseleave.rotate-cursor",()=>{d("default");})),this._rotateHandles.br&&(this._rotateHandles.br.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.br.on("mouseleave.rotate-cursor",()=>{d("default");})),this._rotateHandles.bl&&(this._rotateHandles.bl.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.bl.on("mouseleave.rotate-cursor",()=>{d("default");})),this._updateRotateHandlesPosition();}_destroyRotateHandles(){this._rotateHandlesGroup&&(this._rotateHandlesGroup.destroy(),this._rotateHandlesGroup=null),this._rotateHandles={tl:null,tr:null,br:null,bl:null},this._rotateDragState=null;}_getNodeCenterAbs(e){let t=e.getAbsoluteTransform().copy(),n=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});return t.point({x:n.x+n.width/2,y:n.y+n.height/2})}_updateRotateHandlesPosition(){if(!this._core||!this._selected||!this._rotateHandlesGroup)return;let e=this._selected.getNode(),t=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),n=t.width,r=t.height;if(n<=0||r<=0)return;let i=e.getAbsoluteTransform().copy(),s=k=>i.point(k),l=12,d=s({x:t.x+n/2,y:t.y+r/2}),u=s({x:t.x,y:t.y}),h=s({x:t.x+n,y:t.y}),c=s({x:t.x+n,y:t.y+r}),p=s({x:t.x,y:t.y+r}),f=k=>{let C=k.x-d.x,M=k.y-d.y,z=Math.hypot(C,M)||1;return {x:C/z,y:M/z}},b=f(u),_=f(h),g=f(c),m=f(p),v={x:u.x+b.x*l,y:u.y+b.y*l},y={x:h.x+_.x*l,y:h.y+_.y*l},x={x:c.x+g.x*l,y:c.y+g.y*l},w={x:p.x+m.x*l,y:p.y+m.y*l};this._rotateHandles.tl&&this._rotateHandles.tl.absolutePosition(v),this._rotateHandles.tr&&this._rotateHandles.tr.absolutePosition(y),this._rotateHandles.br&&this._rotateHandles.br.absolutePosition(x),this._rotateHandles.bl&&this._rotateHandles.bl.absolutePosition(w);let N=this._rotateHandlesGroup.getParent();if(N){let k=N.getAbsoluteTransform().decompose(),C=1/(Math.abs(k.scaleX)||1),M=1/(Math.abs(k.scaleY)||1);this._rotateHandles.tl&&this._rotateHandles.tl.scale({x:C,y:M}),this._rotateHandles.tr&&this._rotateHandles.tr.scale({x:C,y:M}),this._rotateHandles.br&&this._rotateHandles.br.scale({x:C,y:M}),this._rotateHandles.bl&&this._rotateHandles.bl.scale({x:C,y:M});}this._rotateHandlesGroup.moveToTop();}_setupSizeLabel(){if(!this._core||!this._selected)return;let e=this._core.nodes.layer;this._destroySizeLabel();let t=new R.Label({listening:false,opacity:.95}),n=new R.Tag({fill:"#2b83ff",cornerRadius:4,shadowColor:"#000",shadowBlur:6,shadowOpacity:.25}),r=new R.Text({text:"",fontFamily:"Inter, Calibri, Arial, sans-serif",fontSize:12,padding:4,fill:"#ffffff"});t.add(n),t.add(r),e.add(t),this._sizeLabel=t,this._updateSizeLabel();}_scheduleUIUpdate(){this._uiUpdateDebounce.schedule(()=>{this._updateSizeLabel(),this._updateRotateHandlesPosition(),this._updateCornerRadiusHandlesPosition();});}_updateSizeLabel(){if(!this._core||!this._selected||!this._sizeLabel)return;let e=this._selected.getNode(),t=e.getClientRect({skipShadow:true,skipStroke:false}),n=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),r=e.getAbsoluteTransform().decompose(),i=this._core.nodes.world.getAbsoluteTransform().decompose(),s=Math.abs(r.scaleX)||1,l=Math.abs(r.scaleY)||1,d=Math.abs(i.scaleX)||1,u=Math.abs(i.scaleY)||1,h=n.width*(s/d),c=n.height*(l/u),p=Math.max(0,Math.round(h)),f=Math.max(0,Math.round(c));this._sizeLabel.getText().text(String(p)+" \xD7 "+String(f));let _=8,g=t.x+t.width/2,m=t.y+t.height+_,y=this._sizeLabel.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width;this._sizeLabel.absolutePosition({x:g,y:m}),this._sizeLabel.offsetX(y/2),this._sizeLabel.offsetY(0);let x=this._sizeLabel.getParent();if(x){let w=x.getAbsoluteTransform().decompose(),N=1/(Math.abs(w.scaleX)||1),k=1/(Math.abs(w.scaleY)||1);this._sizeLabel.scale({x:N,y:k});}this._sizeLabel.moveToTop(),this._transformer&&this._transformer.moveToTop(),this._cornerHandlesGroup&&this._cornerHandlesGroup.moveToTop();}_destroySizeLabel(){this._sizeLabel&&(this._sizeLabel.destroy(),this._sizeLabel=null);}_isCornerRadiusSupported(e){return e instanceof R.Rect}_getCornerRadiusArray(e){let t=e.cornerRadius();if(Array.isArray(t)){let[r=0,i=0,s=0,l=0]=t;return [r||0,i||0,s||0,l||0]}let n=typeof t=="number"?t:0;return [n,n,n,n]}_setCornerRadiusArray(e,t){let[n,r,i,s]=t;n===r&&r===i&&i===s?e.cornerRadius(n):e.cornerRadius(t);}_setupCornerRadiusHandles(e=false){if(!this._core||!this._selected)return;let t=this._selected.getNode();if(!this._isCornerRadiusSupported(t))return;let n=this._core.nodes.layer,r=this._core.stage;this._destroyCornerRadiusHandles();let i=new R.Group({name:"corner-radius-handles-group",listening:true});n.add(i),i.moveToTop(),i.visible(false),this._cornerHandlesGroup=i,t.off(".cornerRadiusHover"),t.on("mouseenter.cornerRadiusHover",()=>{!this._core||!this._cornerHandlesGroup||this._core.nodes.world.scaleX()<.3||this._cornerHandlesGroup.visible(true);}),t.on("mouseleave.cornerRadiusHover",()=>{if(!this._cornerHandlesGroup)return;let S=r.getPointerPosition();if(!S){this._cornerHandlesGroup.visible(false);return}let P=n.getIntersection(S);P&&this._cornerHandlesGroup.isAncestorOf(P)||this._cornerHandlesGroup.visible(false);}),i.on("mouseenter.cornerRadiusHover",()=>{!this._core||!this._cornerHandlesGroup||this._core.nodes.world.scaleX()<.3||this._cornerHandlesGroup.visible(true);}),i.on("mouseleave.cornerRadiusHover",()=>{this._cornerHandlesGroup&&this._cornerHandlesGroup.visible(false);});let s=r.getPointerPosition();if(s&&this._core.nodes.world.scaleX()>=.3){let A=n.getIntersection(s);A&&(A===t||t.isAncestorOf(A))&&this._cornerHandlesGroup.visible(true);}let l=()=>{let S=t.width(),P=t.height(),A=t.getAbsoluteScale(),B=1/(Math.abs(A.x)||1),Y=1/(Math.abs(A.y)||1),F=12*B,H=12*Y,J=Math.max(0,S/2-F),oe=Math.max(0,P/2-H),Q=Math.min(J,oe);return {tl:{corner:{x:F,y:H},sign:{x:1,y:1},side:Q},tr:{corner:{x:S-F,y:H},sign:{x:-1,y:1},side:Q},br:{corner:{x:S-F,y:P-H},sign:{x:-1,y:-1},side:Q},bl:{corner:{x:F,y:P-H},sign:{x:1,y:-1},side:Q}}},d=(S,P)=>{let A=t.getAbsoluteTransform().copy(),B=W=>A.copy().invert().point(W),Y=W=>A.point(W),H=l()[P],J=B(S),oe=J.x-H.corner.x,Q=J.y-H.corner.y,E=(H.sign.x*oe+H.sign.y*Q)/2;E=Math.max(0,Math.min(H.side,E));let I={x:H.corner.x+H.sign.x*E,y:H.corner.y+H.sign.y*E};return {snappedAbs:Y(I),r:E,meta:H}},u=S=>new R.Line({name:S,points:[],stroke:e?"#4a90e2":"",strokeWidth:e?1:0,dash:e?[4,4]:[],closed:true,listening:false}),h=u("corner-square-tl"),c=u("corner-square-tr"),p=u("corner-square-br"),f=u("corner-square-bl");i.add(h,c,p,f);let b=S=>{let P=new R.Circle({name:S,radius:4,fill:"#ffffff",stroke:"#4a90e2",strokeWidth:1.5,draggable:true,dragOnTop:true,hitStrokeWidth:16});return P.on("mouseenter.corner-radius",()=>{this._core&&(this._core.stage.container().style.cursor="default");}),P},_=b("corner-radius-tl"),g=b("corner-radius-tr"),m=b("corner-radius-br"),v=b("corner-radius-bl");i.add(_,g,m,v),this._cornerHandles={tl:_,tr:g,br:m,bl:v};let y={tl:0,tr:1,br:2,bl:3},x=false,w=null,N=false,k=()=>{let S=t.getAbsoluteTransform().copy(),P=t.width(),A=t.height();return S.point({x:P/2,y:A/2})},C=()=>{let S={};return this._cornerHandles.tl&&(S.tl=this._cornerHandles.tl.getAbsolutePosition()),this._cornerHandles.tr&&(S.tr=this._cornerHandles.tr.getAbsolutePosition()),this._cornerHandles.br&&(S.br=this._cornerHandles.br.getAbsolutePosition()),this._cornerHandles.bl&&(S.bl=this._cornerHandles.bl.getAbsolutePosition()),S},M=(S,P=8)=>{let A=k();return Math.hypot(S.x-A.x,S.y-A.y)<=P},z=(S,P=6)=>{let A=k();return Math.min(Math.abs(S.x-A.x),Math.abs(S.y-A.y))<=P},V=(S,P=8)=>{let A=C(),B=0;return ["tl","tr","br","bl"].forEach(Y=>{let F=A[Y];F&&Math.hypot(F.x-S.x,F.y-S.y)<=P&&B++;}),B>=2},L=S=>{if(!x||w)return;let P=k(),A=S.x-P.x,B=S.y-P.y,Y=Math.hypot(A,B);if(Y<.1)return;A/=Y,B/=Y;let F=t.getAbsoluteTransform().copy(),H=l(),J=["tl","tr","br","bl"].reduce((E,I)=>{let se=H[I],W=F.point(se.corner),ne=W.x-P.x,U=W.y-P.y,$=Math.hypot(ne,U)||1;return E[I]={x:ne/$,y:U/$},E},{}),oe="tl",Q=-1/0;["tl","tr","br","bl"].forEach(E=>{let I=J[E],se=A*I.x+B*I.y;se>Q&&(Q=se,oe=E);}),w=oe;},T=S=>P=>{L(P);let A=w??S,{snappedAbs:B,r:Y,meta:F}=d(P,A),H=t.width(),J=t.height(),oe=Math.max(0,Math.min(H,J)/2),Q=F.side>0?Y/F.side:0,E=Math.round(Q*oe);E=Math.max(0,Math.min(E,oe));let I=this._getCornerRadiusArray(t),se=y[A];return N?I[se]=E:(I[0]=E,I[1]=E,I[2]=E,I[3]=E),this._setCornerRadiusArray(t,I),this._showRadiusLabelForCorner(se),D(),this._core?.nodes.layer.batchDraw(),B};_.dragBoundFunc(T("tl")),g.dragBoundFunc(T("tr")),m.dragBoundFunc(T("br")),v.dragBoundFunc(T("bl"));let D=()=>{let{tl:S,tr:P,br:A,bl:B}=this._cornerHandles;if(!S||!P||!A||!B)return;if(this._cornerHandlesSuppressed){this._cornerHandlesGroup?.visible(false),this._radiusLabel?.visible(false);return}if(this._core&&this._cornerHandlesGroup&&this._radiusLabel){if(this._core.nodes.world.scaleX()<.3){this._cornerHandlesGroup.visible(false),this._radiusLabel.visible(false);return}this._cornerHandlesGroup.visible(true);}let Y=t.getAbsoluteTransform().copy(),F=n.getAbsoluteTransform().copy().invert(),H=W=>Y.point(W),J=W=>F.point(Y.point(W)),oe=l(),Q=this._getCornerRadiusArray(t),E=(W,ne,U)=>{let $=oe[W],me=t.width(),Be=t.height(),ve=Math.max(0,Math.min(me,Be)/2),He=Math.max(0,Math.min(ve,Q[ne]||0)),Oe=ve>0?He/ve:0,tt=Math.max(0,Math.min($.side,Oe*$.side)),at={x:$.corner.x+$.sign.x*tt,y:$.corner.y+$.sign.y*tt};U.absolutePosition(H(at));},I=(W,ne)=>{let U=oe[W],$=U.corner,me={x:U.corner.x+U.sign.x*U.side,y:U.corner.y+U.sign.y*U.side},Be=J({x:$.x,y:$.y}),ve=J({x:me.x,y:$.y}),He=J({x:me.x,y:me.y}),Oe=J({x:$.x,y:me.y});ne.points([Be.x,Be.y,ve.x,ve.y,He.x,He.y,Oe.x,Oe.y]);};I("tl",h),I("tr",c),I("br",p),I("bl",f),E("tl",0,S),E("tr",1,P),E("br",2,A),E("bl",3,B);let se=this._cornerHandlesGroup?.getParent();if(se){let W=se.getAbsoluteTransform().decompose(),ne=1/(Math.abs(W.scaleX)||1),U=1/(Math.abs(W.scaleY)||1);S.scale({x:ne,y:U}),P.scale({x:ne,y:U}),A.scale({x:ne,y:U}),B.scale({x:ne,y:U});}this._cornerHandlesGroup?.moveToTop();};this._updateCornerRadiusHandlesPosition=D;let ee=(S,P)=>{N=!!P?.evt?.altKey;let A=S.getAbsolutePosition();if(x=M(A,8)||z(A,6)||V(A,8),w=null,x){let B=this._core?.stage.getPointerPosition()??A;L(B);}},Z=(S,P)=>A=>{N=A.evt.altKey;},ae=()=>{x=false,w=null,N=false;};_.on("dragstart.corner-radius",S=>{ee(_,S);}),g.on("dragstart.corner-radius",S=>{ee(g,S);}),m.on("dragstart.corner-radius",S=>{ee(m,S);}),v.on("dragstart.corner-radius",S=>{ee(v,S);}),_.on("dragmove.corner-radius",Z()),g.on("dragmove.corner-radius",Z()),m.on("dragmove.corner-radius",Z()),v.on("dragmove.corner-radius",Z()),_.on("dragend.corner-radius",ae),g.on("dragend.corner-radius",ae),m.on("dragend.corner-radius",ae),v.on("dragend.corner-radius",ae);let X=S=>()=>{this._showRadiusLabelForCorner(S);},q=()=>{this._hideRadiusLabel();},te=S=>()=>{this._showRadiusLabelForCorner(S);};_.on("mouseenter.corner-radius",X(0)),g.on("mouseenter.corner-radius",X(1)),m.on("mouseenter.corner-radius",X(2)),v.on("mouseenter.corner-radius",X(3)),_.on("mouseleave.corner-radius",q),g.on("mouseleave.corner-radius",q),m.on("mouseleave.corner-radius",q),v.on("mouseleave.corner-radius",q),_.on("dragstart.corner-radius",X(0)),g.on("dragstart.corner-radius",X(1)),m.on("dragstart.corner-radius",X(2)),v.on("dragstart.corner-radius",X(3)),_.on("dragmove.corner-radius",te(0)),g.on("dragmove.corner-radius",te(1)),m.on("dragmove.corner-radius",te(2)),v.on("dragmove.corner-radius",te(3)),_.on("dragend.corner-radius",q),g.on("dragend.corner-radius",q),m.on("dragend.corner-radius",q),v.on("dragend.corner-radius",q);let re=()=>{if(!this._selected)return;this._selected.getNode().draggable(false);},le=()=>{if(!this._selected)return;let S=this._selected.getNode();this._options.dragEnabled&&S.draggable(true);};_.on("mousedown.corner-radius touchstart.corner-radius",re),g.on("mousedown.corner-radius touchstart.corner-radius",re),m.on("mousedown.corner-radius touchstart.corner-radius",re),v.on("mousedown.corner-radius touchstart.corner-radius",re),_.on("mouseup.corner-radius touchend.corner-radius",le),g.on("mouseup.corner-radius touchend.corner-radius",le),m.on("mouseup.corner-radius touchend.corner-radius",le),v.on("mouseup.corner-radius touchend.corner-radius",le);let j=".corner-squares",be=false,_e=()=>{be||(be=true,R.Util.requestAnimFrame(()=>{be=false,D(),this._core?.nodes.layer.batchDraw();}));};r.on(["wheel","resize","xChange","yChange","positionChange","scaleXChange","scaleYChange","scaleChange"].map(S=>S+j).join(" "),_e),n.on(["xChange","yChange","positionChange","scaleXChange","scaleYChange","scaleChange"].map(S=>S+j).join(" "),_e),t.on(["dragmove","transform","xChange","yChange","widthChange","heightChange","rotationChange","scaleXChange","scaleYChange","positionChange","scaleChange"].map(S=>S+j).join(" "),_e),this._transformer&&(this._transformer.on("transformstart"+j,()=>{this._cornerHandlesSuppressed=true,this._cornerHandlesGroup?.visible(false),this._hideRadiusLabel(),this._core?.nodes.layer.batchDraw();}),this._transformer.on("transform"+j,()=>{D(),this._core?.nodes.layer.batchDraw();}),this._transformer.on("transformend"+j,()=>{this._cornerHandlesSuppressed=false,_e();})),i.on("destroy"+j,()=>{r.off(j),n.off(j),t.off(j),this._transformer?.off(j);}),D(),n.batchDraw();}_destroyCornerRadiusHandles(){this._cornerHandlesGroup&&(this._cornerHandlesGroup.destroy(),this._cornerHandlesGroup=null),this._cornerHandles={tl:null,tr:null,br:null,bl:null},this._core&&(this._core.stage.container().style.cursor="default"),this._destroyRadiusLabel(),this._selected&&this._selected.getNode().off(".overlay-sync");}_bakeRectScale(e){if(!(e instanceof R.Rect))return;let t=e.scaleX(),n=e.scaleY();if(t===1&&n===1)return;let r=e.getAbsolutePosition(),i=e.width(),s=e.height(),l=Math.abs(t)*i,d=Math.abs(n)*s;e.width(l),e.height(d),e.scaleX(1),e.scaleY(1),e.setAbsolutePosition(r);}_updateCornerRadiusHandlesPosition(){if(!this._core||!this._selected||!this._cornerHandlesGroup)return;let e=this._selected.getNode();if(!this._isCornerRadiusSupported(e))return;let t=e,n=t.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),r=n.width,i=n.height;if(r<=0||i<=0)return;let s=t.getAbsoluteTransform().copy(),l=N=>s.point(N),d=t.getAbsoluteScale(),u=1/(Math.abs(d.x)||1),h=1/(Math.abs(d.y)||1),c=12*u,p=12*h,f=this._getCornerRadiusArray(t),b=Math.min(r,i)/2||1,_=N=>{let k=Math.hypot(N.x,N.y)||1;return {x:N.x/k,y:N.y/k}},g=[_({x:r/2-c,y:i/2-p}),_({x:-(r/2-c),y:i/2-p}),_({x:-(r/2-c),y:-(i/2-p)}),_({x:r/2-c,y:-(i/2-p)})],m=l({x:n.x+c+g[0].x*Math.min(b,f[0]),y:n.y+p+g[0].y*Math.min(b,f[0])}),v=l({x:n.x+r-c+g[1].x*Math.min(b,f[1]),y:n.y+p+g[1].y*Math.min(b,f[1])}),y=l({x:n.x+r-c+g[2].x*Math.min(b,f[2]),y:n.y+i-p+g[2].y*Math.min(b,f[2])}),x=l({x:n.x+c+g[3].x*Math.min(b,f[3]),y:n.y+i-p+g[3].y*Math.min(b,f[3])});this._cornerHandles.tl&&this._cornerHandles.tl.absolutePosition(m),this._cornerHandles.tr&&this._cornerHandles.tr.absolutePosition(v),this._cornerHandles.br&&this._cornerHandles.br.absolutePosition(y),this._cornerHandles.bl&&this._cornerHandles.bl.absolutePosition(x);let w=this._cornerHandlesGroup.getParent();if(w){let N=w.getAbsoluteTransform().decompose(),k=1/(Math.abs(N.scaleX)||1),C=1/(Math.abs(N.scaleY)||1);this._cornerHandles.tl&&this._cornerHandles.tl.scale({x:k,y:C}),this._cornerHandles.tr&&this._cornerHandles.tr.scale({x:k,y:C}),this._cornerHandles.br&&this._cornerHandles.br.scale({x:k,y:C}),this._cornerHandles.bl&&this._cornerHandles.bl.scale({x:k,y:C});}this._cornerHandlesGroup.moveToTop();}_updateCornerRadiusHandlesVisibility(){if(!this._core||!this._selected||!this._cornerHandlesGroup)return;let t=this._core.nodes.world.scaleX(),n=this._core.stage,r=this._core.nodes.layer,i=this._selected.getNode(),s=n.getPointerPosition();if(!s){t<.3&&this._cornerHandlesGroup.visible(false);return}if(t<.3){this._cornerHandlesGroup.visible(false);return}let l=r.getIntersection(s);if(l){let d=l===i||i.isAncestorOf(l),u=this._cornerHandlesGroup.isAncestorOf(l);d||u?this._cornerHandlesGroup.visible(true):this._cornerHandlesGroup.visible(false);}else this._cornerHandlesGroup.visible(false);}_ensureRadiusLabel(){if(!this._core)return null;if(this._radiusLabel)return this._radiusLabel;let e=this._core.nodes.layer,t=new R.Label({listening:false,opacity:.95}),n=new R.Tag({fill:"#2b83ff",cornerRadius:4,shadowColor:"#000",shadowBlur:6,shadowOpacity:.25}),r=new R.Text({text:"",fontFamily:"Inter, Calibri, Arial, sans-serif",fontSize:12,padding:4,fill:"#ffffff"});return t.add(n),t.add(r),t.visible(false),e.add(t),this._radiusLabel=t,t}_updateRadiusLabelAt(e,t){let n=this._ensureRadiusLabel();if(!n)return;n.getText().text(t);let s=n.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width,l={x:8,y:8};n.absolutePosition({x:e.x-l.x,y:e.y+l.y}),n.offsetX(s),n.offsetY(0);let d=n.getParent();if(d){let u=d.getAbsoluteTransform().decompose(),h=1/(Math.abs(u.scaleX)||1),c=1/(Math.abs(u.scaleY)||1);n.scale({x:h,y:c});}n.visible(true),n.moveToTop(),this._transformer&&this._transformer.moveToTop();}_showRadiusLabelForCorner(e){if(!this._core||!this._selected)return;let t=this._selected.getNode();if(!this._isCornerRadiusSupported(t))return;let n=t,r=this._getCornerRadiusArray(n),i=Math.round(r[e]),s=e===0?this._cornerHandles.tl:e===1?this._cornerHandles.tr:e===2?this._cornerHandles.br:this._cornerHandles.bl;if(!s)return;let l=s.getAbsolutePosition();this._updateRadiusLabelAt(l,"Radius "+String(i));}_hideRadiusLabel(){this._radiusLabel&&this._radiusLabel.visible(false);}_destroyRadiusLabel(){this._radiusLabel&&(this._radiusLabel.destroy(),this._radiusLabel=null);}_findBaseNodeByTarget(e){if(!this._core)return null;if(this._selected){let n=this._selected.getNode();if(n===e)return this._selected;if(typeof n.isAncestorOf=="function"&&n.isAncestorOf(e))return this._selected}let t=null;for(let n of this._core.nodes.list()){let r=n.getNode();if(typeof r.isAncestorOf=="function"&&r.isAncestorOf(e)){let i=true;for(let s of this._core.nodes.list()){if(s===n)continue;let l=s.getNode();if(typeof l.isAncestorOf=="function"&&l.isAncestorOf(r)){i=false;break}}i&&(t=n);}}if(t)return t;for(let n of this._core.nodes.list())if(n.getNode()===e)return n;return null}};var Ze=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_layer",null);a(this,"_shape",null);a(this,"_stepX");a(this,"_stepY");a(this,"_color");a(this,"_lineWidth");a(this,"_visible");a(this,"_minScaleToShow");a(this,"_enableSnap");a(this,"_dragMoveHandler",null);a(this,"_nodesAddHandler",null);a(this,"_nodesRemoveHandler",null);a(this,"_redrawScheduled",false);a(this,"_transformersCache",[]);a(this,"_cacheInvalidated",true);this._stepX=Math.max(1,e.stepX??1),this._stepY=Math.max(1,e.stepY??1),this._color=e.color??"#2b313a",this._lineWidth=e.lineWidth??1,this._visible=e.visible??true,this._minScaleToShow=e.minScaleToShow??8,this._enableSnap=e.enableSnap??true;}onAttach(e){this._core=e;let t=e.nodes.layer,n=(h,c)=>{if(!this._visible||!this._core)return;let p=this._core.stage,f=this._core.nodes.world,b=f.scaleX();if(this._minScaleToShow!=null&&b<this._minScaleToShow)return;let _=p.width(),g=p.height(),m=f.scaleX(),v=f.scaleY(),y=Math.max(1,this._stepX)*Math.max(1e-6,m),x=Math.max(1,this._stepY)*Math.max(1e-6,v),w=(f.x()%y+y)%y,N=(f.y()%x+x)%x;h.beginPath(),h.lineWidth=this._lineWidth,h.strokeStyle=this._color;for(let k=w;k<=_;k+=y)h.moveTo(k,0),h.lineTo(k,g);for(let k=N;k<=g;k+=x)h.moveTo(0,k),h.lineTo(_,k);h.stroke();},r=new R.Shape({listening:false,sceneFunc:n});t.add(r),this._layer=t,this._shape=r;let i=e.stage,s=e.nodes.world;i.on("resize.grid",()=>{this._scheduleRedraw();}),s.on("xChange.grid yChange.grid scaleXChange.grid scaleYChange.grid",()=>{this._scheduleRedraw();}),(()=>{this._cacheInvalidated&&(this._transformersCache=t.find("Transformer"),this._cacheInvalidated=false);for(let h of this._transformersCache)h.moveToTop();this._shape?.moveToTop();for(let h of this._transformersCache)h.moveToTop();})(),this._dragMoveHandler=h=>{if(!this._core||!this._enableSnap)return;let c=this._core.stage,p=this._core.nodes.world,f=h.target;if(f===c||f instanceof R.Layer)return;let b=this._core.nodes.layer,_=f,g=false;for(;_;){if(_===b){g=true;break}_=_.getParent();}if(!g)return;let m=f;if(typeof m.draggable=="function"&&!m.draggable())return;let v=f.getAbsolutePosition(),y=p.scaleX()||1,x=p.scaleY()||1;if(this._minScaleToShow!=null?y>=this._minScaleToShow:false){let N=(v.x-p.x())/y,k=(v.y-p.y())/x,C=Math.max(1,this._stepX),M=Math.max(1,this._stepY),z=Math.round(N/C)*C,V=Math.round(k/M)*M,L=z*y+p.x(),T=V*x+p.y();(Math.abs(L-v.x)>.001||Math.abs(T-v.y)>.001)&&f.absolutePosition({x:L,y:T});}else {let N=(v.x-p.x())/y,k=(v.y-p.y())/x,C=Math.max(1,this._stepX),M=Math.max(1,this._stepY),z=Math.round(N/C)*C,V=Math.round(k/M)*M,L=z*y+p.x(),T=V*x+p.y();(Math.abs(L-v.x)>.001||Math.abs(T-v.y)>.001)&&f.absolutePosition({x:L,y:T});}},i.on("dragmove.grid",this._dragMoveHandler);let d=h=>{let c=h;if((typeof c.getClassName=="function"?c.getClassName():"")!=="Transformer")return;let f=h,b=(_,g)=>{let m=g;if(!this._enableSnap||!this._core||!(typeof c.nodes=="function"?c.nodes():[])[0])return m;let x=typeof c.getActiveAnchor=="function"?c.getActiveAnchor():"";if(x==="rotater")return m;let w=Math.max(1,this._stepX),N=Math.max(1,this._stepY),k=typeof x=="string"?x:"",C=this._core.nodes.world.getAbsoluteTransform(),M=C.copy();M.invert();let z=m.x,V=m.x+m.width,L=m.y,T=m.y+m.height,D=M.point({x:z,y:L}).x,ee=M.point({x:V,y:L}).x,Z=M.point({x:z,y:L}).y,ae=M.point({x:z,y:T}).y,X=D,q=ee,te=Z,re=ae,le=(B,Y)=>Math.round((B+1e-9)/Y)*Y;k.includes("left")&&(X=le(D,w)),k.includes("right")&&(q=le(ee,w)),k.includes("top")&&(te=le(Z,N)),k.includes("bottom")&&(re=le(ae,N)),q-X<w&&(k.includes("left")?X=q-w:q=X+w),re-te<N&&(k.includes("top")?te=re-N:re=te+N);let j=C.point({x:X,y:te}).x,be=C.point({x:X,y:te}).y,_e=C.point({x:q,y:te}).x,S=C.point({x:X,y:re}).y,P=B=>Math.round(B*1e3)/1e3;return {x:P(j),y:P(be),width:P(_e-j),height:P(S-be),rotation:m.rotation}};globalThis.queueMicrotask(()=>{f.boundBoxFunc(b);});},u=h=>{d(h);let c=h,p=typeof c.getChildren=="function"?c.getChildren():[];for(let f of p)u(f);};u(e.nodes.layer),this._nodesAddHandler=h=>{let c=h.child??h.target;u(c);let p=c;if((typeof p.getClassName=="function"?p.getClassName():"")==="Transformer"){this._cacheInvalidated=true,c.moveToTop(),this._shape?.moveToTop(),this._transformersCache=t.find("Transformer"),this._cacheInvalidated=false;for(let b of this._transformersCache)b.moveToTop();}},this._nodesRemoveHandler=h=>{let c=h.child??h.target,p=_=>{let g=_;(typeof g.getClassName=="function"?g.getClassName():"")==="Transformer"&&_.boundBoxFunc?.(void 0);let v=typeof g.getChildren=="function"?g.getChildren():[];for(let y of v)p(y);};p(c);let f=c;(typeof f.getClassName=="function"?f.getClassName():"")==="Transformer"&&(this._cacheInvalidated=true),this._shape?.moveToTop(),this._cacheInvalidated&&(this._transformersCache=t.find("Transformer"),this._cacheInvalidated=false);for(let _ of this._transformersCache)_.moveToTop();},e.nodes.layer.on("add.grid",this._nodesAddHandler),e.nodes.layer.on("remove.grid",this._nodesRemoveHandler),e.nodes.layer.on("cornerRadiusChange.grid",h=>{let c=h.target;if((typeof c.getClassName=="function"?c.getClassName():"")!=="Rect")return;let f=c.cornerRadius;if(typeof f!="function")return;let b=f.call(c),_=y=>{c.cornerRadius(y);},g=this._core?.stage,m=g?.scaleX()??1,v=this._minScaleToShow!=null?m>=this._minScaleToShow:false;if(Array.isArray(b)){let y=b.map(x=>{if(v){let w=g?.scaleX()??1,N=g?.scaleY()??1,k=x*(.5*(w+N));return Math.max(0,Math.round(k))/Math.max(1e-6,.5*(w+N))}else return Math.max(0,Math.round(x))});_(y);}else if(typeof b=="number")if(v){let y=g?.scaleX()??1,x=g?.scaleY()??1,w=b*(.5*(y+x)),N=Math.max(0,Math.round(w));_(N/Math.max(1e-6,.5*(y+x)));}else _(Math.max(0,Math.round(b)));});}_scheduleRedraw(){if(this._redrawScheduled)return;this._redrawScheduled=true;let e=globalThis.requestAnimationFrame;e(()=>{this._redrawScheduled=false,this._layer?.batchDraw();});}onDetach(e){e.stage.off(".grid"),e.nodes.layer.off(".grid"),this._shape&&this._shape.destroy(),this._shape=null,this._layer=null,this._dragMoveHandler=null,this._nodesAddHandler=null,this._nodesRemoveHandler=null,e.stage.batchDraw();}setVisible(e){this._visible=e,this._core&&this._core.stage.batchDraw();}get stepX(){return this._stepX}get stepY(){return this._stepY}get minScaleToShow(){return this._minScaleToShow}setStep(e,t){this._stepX=Math.max(1,e),this._stepY=Math.max(1,t),this._core&&this._core.stage.batchDraw();}setMinScaleToShow(e){this._minScaleToShow=e,this._core&&this._core.stage.batchDraw();}setSnap(e){this._enableSnap=e;}};var qe=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_layer",null);a(this,"_hGroup");a(this,"_vGroup");a(this,"_hBg");a(this,"_vBg");a(this,"_hTicksShape");a(this,"_vTicksShape");a(this,"_hBorder");a(this,"_vBorder");a(this,"_redrawScheduled",false);a(this,"_lastRedrawTime",0);a(this,"_redrawThrottleMs",16);a(this,"_panThrottleMs",32);a(this,"_cachedActiveGuide",null);a(this,"_cacheInvalidated",true);a(this,"_stepsCache",new Map);let{thicknessPx:t=30,fontFamily:n="Inter, Calibri, Arial, sans-serif",fontSizePx:r=10,color:i="#8c8c8c",bgColor:s="#2c2c2c",borderColor:l="#1f1f1f",enabled:d=true}=e;this._options={thicknessPx:t,fontFamily:n,fontSizePx:r,color:i,bgColor:s,borderColor:l,enabled:d};}_calculateNiceStep(e){if(!isFinite(e)||e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),n=e/t,r;return n<=1?r=1:n<=2?r=2:n<=5?r=5:r=10,r*t}_formatNumber(e){return Math.round(e).toString()}_getStepsConfig(e){let t=this._stepsCache.get(e);if(t)return t;let n=this._options.thicknessPx,i=50/e,s=this._calculateNiceStep(i);s<1&&(s=1);let l=s*e,d,u,h,c;l>=60?(d=s*10,u=s*5,h=s,c=s):l>=40?(d=s*10,u=s*5,h=s*5,c=s):(d=s*10,u=s*5,h=s*10,c=s);let p={step:s,stepPx:l,majorStep:d,mediumStep:u,labelStep:h,drawStep:c,drawStepEpsilon:c*.01,majorTickLength:n*.6,mediumTickLength:n*.4,minorTickLength:n*.25,fontString:`${String(this._options.fontSizePx)}px ${this._options.fontFamily}`};if(this._stepsCache.size>10){let f=this._stepsCache.keys().next().value;f!==void 0&&this._stepsCache.delete(f);}return this._stepsCache.set(e,p),p}onAttach(e){this._core=e,this._layer=new R.Layer({name:"ruler-layer",listening:true}),this._options.enabled&&e.stage.add(this._layer),this._hGroup=new R.Group({listening:true}),this._vGroup=new R.Group({listening:true}),this._layer.add(this._hGroup),this._layer.add(this._vGroup),this._hBg=new R.Rect({fill:this._options.bgColor,listening:true,name:"ruler-h-bg"}),this._vBg=new R.Rect({fill:this._options.bgColor,listening:true,name:"ruler-v-bg"}),this._hGroup.add(this._hBg),this._vGroup.add(this._vBg),this._hBorder=new R.Line({stroke:this._options.borderColor,strokeWidth:1,listening:false}),this._vBorder=new R.Line({stroke:this._options.borderColor,strokeWidth:1,listening:false}),this._hGroup.add(this._hBorder),this._vGroup.add(this._vBorder),this._hTicksShape=new R.Shape({listening:false,sceneFunc:r=>{let i=this._getActiveGuideInfo();this._drawHorizontalRuler(r,i);}}),this._hGroup.add(this._hTicksShape),this._vTicksShape=new R.Shape({listening:false,sceneFunc:r=>{let i=this._getActiveGuideInfo();this._drawVerticalRuler(r,i);}}),this._vGroup.add(this._vTicksShape);let t=e.stage,n=e.nodes.world;t.on("resize.ruler",()=>{this._scheduleRedraw();}),n.on("xChange.ruler yChange.ruler",()=>{this._invalidateGuideCache(),this._scheduleRedraw(true);}),n.on("scaleXChange.ruler scaleYChange.ruler",()=>{this._invalidateGuideCache(),this._scheduleRedraw(false);}),t.on("guidesChanged.ruler",()=>{this._invalidateGuideCache(),this._scheduleRedraw();}),this._redraw(),e.stage.batchDraw();}onDetach(e){e.stage.off(".ruler"),e.nodes.world.off(".ruler"),this._layer&&(this._layer.destroy(),this._layer=null);}_getActiveGuideInfo(){if(!this._core)return null;if(!this._cacheInvalidated)return this._cachedActiveGuide;let e=this._core.stage.findOne(".guides-layer");if(!e)return this._cachedActiveGuide=null,this._cacheInvalidated=false,null;let t=e.find("Line");for(let n of t){let r=n;if(r.strokeWidth()===2){let i=r.worldCoord,s=r.name()==="guide-h"?"h":"v";return this._cachedActiveGuide={type:s,coord:i},this._cacheInvalidated=false,this._cachedActiveGuide}}return this._cachedActiveGuide=null,this._cacheInvalidated=false,null}_invalidateGuideCache(){this._cacheInvalidated=true;}_drawRuler(e,t,n){if(!this._core)return;let r=this._core.stage,i=this._core.nodes.world,s=i.scaleX()||1e-9,l=this._options.thicknessPx,d=t==="h",u=d?r.width():r.height(),h=d?i.x():i.y(),c=n?.type===(d?"v":"h")?n.coord:null,p=this._getStepsConfig(s),{majorStep:f,mediumStep:b,labelStep:_,drawStep:g,drawStepEpsilon:m,majorTickLength:v,mediumTickLength:y,minorTickLength:x,fontString:w}=p;e.save();let N=-h/s,k=Math.floor(N/g)*g,C=[],M=[],z=[],V=[],L=null;for(let T=k;;T+=g){let D=h+T*s;if(D>u)break;if(D<0)continue;if(c!==null&&Math.abs(T-c)<m){L=D,V.push({pos:D,text:this._formatNumber(T)});continue}let Z=Math.abs(T%f)<m,ae=!Z&&Math.abs(T%b)<m;Z?C.push(D):ae?M.push(D):z.push(D),Math.abs(T%_)<m&&V.push({pos:D,text:this._formatNumber(T)});}if(z.length>0){e.strokeStyle=this._options.color,e.globalAlpha=.4,e.lineWidth=1,e.beginPath();for(let T of z)d?(e.moveTo(T,l),e.lineTo(T,l-x)):(e.moveTo(l,T),e.lineTo(l-x,T));e.stroke();}if(M.length>0){e.strokeStyle=this._options.color,e.globalAlpha=.6,e.lineWidth=1,e.beginPath();for(let T of M)d?(e.moveTo(T,l),e.lineTo(T,l-y)):(e.moveTo(l,T),e.lineTo(l-y,T));e.stroke();}if(C.length>0){e.strokeStyle=this._options.color,e.globalAlpha=.9,e.lineWidth=1,e.beginPath();for(let T of C)d?(e.moveTo(T,l),e.lineTo(T,l-v)):(e.moveTo(l,T),e.lineTo(l-v,T));e.stroke();}if(L!==null&&(e.strokeStyle="#ff8c00",e.globalAlpha=1,e.lineWidth=2,e.beginPath(),d?(e.moveTo(L,l),e.lineTo(L,l-v)):(e.moveTo(l,L),e.lineTo(l-v,L)),e.stroke()),V.length>0){e.font=w,e.textBaseline="top",e.textAlign="left";for(let T of V){let D=T.pos===L;if(e.globalAlpha=D?1:.9,e.fillStyle=D?"#ff8c00":this._options.color,d)e.fillText(T.text,T.pos+4,4);else {let Z=T.pos+4;e.setTransform(0,-1,1,0,4,Z),e.fillText(T.text,0,0),e.setTransform(1,0,0,1,0,0);}}}if(c!==null){let T=h+c*s;if(T>=0&&T<=u&&!(Math.abs(c%g)<m))if(e.strokeStyle="#ff8c00",e.globalAlpha=1,e.lineWidth=2,e.beginPath(),d?(e.moveTo(T,l),e.lineTo(T,l-v)):(e.moveTo(l,T),e.lineTo(l-v,T)),e.stroke(),e.fillStyle="#ff8c00",e.font=w,e.textBaseline="top",e.textAlign="left",d)e.fillText(this._formatNumber(c),T+4,4);else {let Z=T+4;e.setTransform(0,-1,1,0,4,Z),e.fillText(this._formatNumber(c),0,0),e.setTransform(1,0,0,1,0,0);}}e.restore();}_drawHorizontalRuler(e,t){this._drawRuler(e,"h",t);}_drawVerticalRuler(e,t){this._drawRuler(e,"v",t);}_redraw(){if(!this._core||!this._layer)return;let e=this._core.stage,t=e.width(),n=e.height(),r=this._options.thicknessPx;this._hBg&&this._hBg.size({width:t,height:r}),this._vBg&&this._vBg.size({width:r,height:n}),this._hBorder&&this._hBorder.points([0,r,t,r]),this._vBorder&&this._vBorder.points([r,0,r,n]),this._layer.batchDraw();}_scheduleRedraw(e=false){if(!this._core||!this._layer)return;let n=globalThis.performance.now()-this._lastRedrawTime;if(this._redrawScheduled)return;this._redrawScheduled=true;let r=e?this._panThrottleMs:this._redrawThrottleMs;if(n>=r)globalThis.requestAnimationFrame(()=>{this._redrawScheduled=false,this._lastRedrawTime=globalThis.performance.now(),this._redraw();});else {let i=r-n;globalThis.setTimeout(()=>{globalThis.requestAnimationFrame(()=>{this._redrawScheduled=false,this._lastRedrawTime=globalThis.performance.now(),this._redraw();});},i);}}show(){this._core&&this._layer&&(this._core.stage.add(this._layer),this._layer.moveToTop(),this._redraw(),this._core.stage.batchDraw());}hide(){this._layer?.getStage()&&(this._layer.remove(),this._core?.stage.batchDraw());}toggle(){this._layer?.getStage()?this.hide():this.show();}isVisible(){return !!this._layer?.getStage()}};var Ge=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_guidesLayer",null);a(this,"_guides",[]);a(this,"_activeGuide",null);a(this,"_draggingGuide",null);a(this,"_rulerLayerCache",null);a(this,"_updateScheduled",false);a(this,"_dragMoveScheduled",false);a(this,"_batchDrawScheduled",false);let{guideColor:t="#8e3e2c",activeColor:n="#2b83ff",rulerThicknessPx:r=30,snapToGrid:i=true,gridStep:s=1}=e;this._options={guideColor:t,activeColor:n,rulerThicknessPx:r,snapToGrid:i,gridStep:s};}onAttach(e){if(this._core=e,!e.stage.findOne(".ruler-layer"))throw new Error("RulerGuidesPlugin requires RulerPlugin to be added to the CoreEngine first. Please add RulerPlugin before RulerGuidesPlugin.");this._guidesLayer=new R.Layer({name:"guides-layer"}),e.stage.add(this._guidesLayer),this._guidesLayer.moveToTop();let n=e.stage,r=this._options.rulerThicknessPx;n.on("mousedown.ruler-guides",()=>{let s=n.getPointerPosition();if(!s)return;let l=n.getIntersection(s);l&&(l.name()==="guide-h"||l.name()==="guide-v")||(s.y<=r&&s.x>=r?this._startCreateGuide("h"):s.x<=r&&s.y>=r?this._startCreateGuide("v"):this._setActiveGuide(null));}),n.on("mousemove.ruler-guides",()=>{let s=n.getPointerPosition();if(!s)return;let l=n.getIntersection(s);if(l){let d=l.name();if(d==="guide-h"||d==="guide-v"||d.includes("_anchor")||d.includes("rotater")||l.draggable())return}s.y<=r&&s.x>=r?n.container().style.cursor="ns-resize":s.x<=r&&s.y>=r?n.container().style.cursor="ew-resize":this._draggingGuide||(n.container().style.cursor="default");}),this._rulerLayerCache=e.stage.findOne(".ruler-layer"),e.nodes.world.on("xChange.ruler-guides yChange.ruler-guides scaleXChange.ruler-guides scaleYChange.ruler-guides",()=>{this._scheduleUpdate();}),n.on("resize.ruler-guides",()=>{this._scheduleUpdate();}),e.stage.batchDraw();}onDetach(e){e.stage.off(".ruler-guides"),e.nodes.world.off(".ruler-guides"),this._guidesLayer&&(this._guidesLayer.destroy(),this._guidesLayer=null),this._guides=[],this._activeGuide=null,this._draggingGuide=null;}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=true,globalThis.requestAnimationFrame(()=>{this._updateScheduled=false,this._updateGuidesPositions();}));}_updateGuidesPositions(){if(!this._core||this._guides.length===0)return;let e=this._core.nodes.world,t=e.scaleX(),n=e.x(),r=e.y(),i=this._core.stage.width(),s=this._core.stage.height(),l=[0,0,i,0],d=[0,0,0,s];for(let u of this._guides){let h=u.worldCoord;if(u.name()==="guide-h"){let p=r+h*t;u.position({x:0,y:p}),u.points(l);}else {let p=n+h*t;u.position({x:p,y:0}),u.points(d);}}this._guidesLayer?.batchDraw();}_snapToGrid(e){if(!this._options.snapToGrid)return Math.round(e);let t=this._options.gridStep;return Math.round(e/t)*t}_scheduleBatchDraw(){this._batchDrawScheduled||(this._batchDrawScheduled=true,globalThis.requestAnimationFrame(()=>{this._batchDrawScheduled=false,this._core?.stage.batchDraw();}));}_startCreateGuide(e){if(!this._core||!this._guidesLayer)return;let t=this._core.stage,n=this._core.nodes.world,r=n.scaleX(),i=t.getPointerPosition();if(!i)return;let s=e==="h"?(i.y-n.y())/r:(i.x-n.x())/r,l=this._snapToGrid(s),d=new R.Line({name:e==="h"?"guide-h":"guide-v",stroke:this._options.guideColor,strokeWidth:1,opacity:1,draggable:true,hitStrokeWidth:8,dragBoundFunc:p=>{if(!this._core)return p;let f=this._core.nodes.world,b=f.scaleX();if(e==="h"){let _=(p.y-f.y())/b,g=this._snapToGrid(_);return {x:0,y:f.y()+g*b}}else {let _=(p.x-f.x())/b,g=this._snapToGrid(_);return {x:f.x()+g*b,y:0}}}});d.worldCoord=l,d.on("mouseenter",()=>{this._core&&(this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize"),this._scheduleBatchDraw();}),d.on("mouseleave",()=>{this._core&&!this._draggingGuide&&(this._core.stage.container().style.cursor="default"),this._scheduleBatchDraw();}),d.on("click",()=>{this._setActiveGuide(d);}),d.on("dragstart",()=>{let p=d;this._draggingGuide={type:e,line:p},this._setActiveGuide(p),this._core&&(this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize");}),d.on("dragmove",()=>{!this._core||this._dragMoveScheduled||(this._dragMoveScheduled=true,globalThis.requestAnimationFrame(()=>{if(this._dragMoveScheduled=false,!this._core)return;let p=this._core.nodes.world,f=p.scaleX(),b=d.getAbsolutePosition(),_=e==="h"?(b.y-p.y())/f:(b.x-p.x())/f,g=this._snapToGrid(_);d.worldCoord=g,this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize",this._rulerLayerCache&&this._rulerLayerCache.batchDraw();}));}),d.on("dragend",()=>{this._draggingGuide=null,this._core&&(this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize");});let u=d;this._guidesLayer.add(u),this._guides.push(u),this._setActiveGuide(u),e==="h"?(d.position({x:0,y:n.y()+l*r}),d.points([0,0,t.width(),0])):(d.position({x:n.x()+l*r,y:0}),d.points([0,0,0,t.height()])),this._draggingGuide={type:e,line:u};let h=()=>{if(!this._draggingGuide||!this._core)return;let p=this._core.stage.getPointerPosition();if(!p)return;let f=this._core.nodes.world,b=f.scaleX(),_=e==="h"?(p.y-f.y())/b:(p.x-f.x())/b,g=this._snapToGrid(_);d.worldCoord=g,e==="h"?(d.position({x:0,y:f.y()+g*b}),d.points([0,0,this._core.stage.width(),0])):(d.position({x:f.x()+g*b,y:0}),d.points([0,0,0,this._core.stage.height()])),this._scheduleBatchDraw();},c=()=>{this._draggingGuide=null,this._core&&(this._core.stage.off("mousemove.guide-create"),this._core.stage.off("mouseup.guide-create"));};t.on("mousemove.guide-create",h),t.on("mouseup.guide-create",c),this._scheduleBatchDraw();}_setActiveGuide(e){this._activeGuide&&this._activeGuide!==e&&(this._activeGuide.stroke(this._options.guideColor),this._activeGuide.strokeWidth(1)),this._activeGuide=e,e&&(e.stroke(this._options.activeColor),e.strokeWidth(2)),this._rulerLayerCache&&this._rulerLayerCache.batchDraw(),this._core?.stage.fire("guidesChanged.ruler"),this._scheduleBatchDraw();}getActiveGuide(){return this._activeGuide}getActiveGuideInfo(){if(!this._activeGuide)return null;let e=this._activeGuide.worldCoord;return {type:this._activeGuide.name()==="guide-h"?"h":"v",coord:e}}removeActiveGuide(){this._activeGuide&&(this._activeGuide.destroy(),this._guides=this._guides.filter(e=>e!==this._activeGuide),this._activeGuide=null,this._scheduleBatchDraw());}getGuides(){return [...this._guides]}clearGuides(){this._guides.forEach(e=>e.destroy()),this._guides=[],this._activeGuide=null,this._scheduleBatchDraw();}};var je=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_highlightLayer",null);a(this,"_hGroup",null);a(this,"_vGroup",null);a(this,"_hHighlights",[]);a(this,"_vHighlights",[]);a(this,"_updateDebounce",new ge);a(this,"_transformersCache",[]);a(this,"_cacheInvalidated",true);let{highlightColor:t="#2b83ff",highlightOpacity:n=.3,rulerThicknessPx:r=30}=e;this._options={highlightColor:t,highlightOpacity:n,rulerThicknessPx:r};}onAttach(e){this._core=e;let t=e.stage.findOne(".ruler-layer");if(!t){globalThis.console.warn("RulerHighlightPlugin: RulerPlugin not found. Please add RulerPlugin before RulerHighlightPlugin. Plugin will not work without RulerPlugin.");return}this._highlightLayer=t;let n=t.find("Group");if(n.length>=2)this._hGroup=n[0],this._vGroup=n[1];else {globalThis.console.warn("RulerHighlightPlugin: Could not find ruler groups");return}e.nodes.world.on("xChange.ruler-highlight yChange.ruler-highlight scaleXChange.ruler-highlight scaleYChange.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("resize.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("transform.ruler-highlight transformend.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("click.ruler-highlight",()=>{this._invalidateCache(),this._scheduleUpdate();}),e.stage.on("dragmove.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("mouseup.ruler-highlight",()=>{this._invalidateCache(),this._scheduleUpdate();}),this._updateHighlights();}onDetach(e){try{e.stage.off(".ruler-highlight"),e.nodes.world.off(".ruler-highlight");}catch{}this._hHighlights.forEach(t=>{try{t.destroy();}catch{}}),this._vHighlights.forEach(t=>{try{t.destroy();}catch{}}),this._hHighlights=[],this._vHighlights=[],this._highlightLayer=null,this._hGroup=null,this._vGroup=null;}_scheduleUpdate(){this._updateDebounce.schedule(()=>{this._updateHighlights();});}_invalidateCache(){this._cacheInvalidated=true;}_updateHighlights(){if(!this._core||!this._highlightLayer)return;for(let b of this._hHighlights)b.destroy();this._hHighlights=[];for(let b of this._vHighlights)b.destroy();this._vHighlights=[];let e=this._getSelectedKonvaNodes();if(e.length===0){this._highlightLayer.batchDraw();return}let t=this._core.stage,n=this._core.nodes.world,r=t.width(),i=t.height(),s=this._options.rulerThicknessPx,l=n.scaleX(),d=n.x(),u=n.y(),h=[],c=[];for(let b of e){let _=b.getClientRect({relativeTo:n}),g=d+_.x*l,m=d+(_.x+_.width)*l,v=u+_.y*l,y=u+(_.y+_.height)*l;if(g<r&&m>s){let x=Math.max(s,g),w=Math.min(r,m);x<w&&h.push({start:x,end:w});}if(v<i&&y>s){let x=Math.max(s,v),w=Math.min(i,y);x<w&&c.push({start:x,end:w});}}let p=this._mergeSegments(h),f=this._mergeSegments(c);if(this._hGroup)for(let b of p){let _=new R.Rect({x:b.start,y:0,width:b.end-b.start,height:s,fill:this._options.highlightColor,opacity:this._options.highlightOpacity,listening:false,name:"ruler-highlight-h"});this._hGroup.add(_),_.setZIndex(1),this._hHighlights.push(_);}if(this._vGroup)for(let b of f){let _=new R.Rect({x:0,y:b.start,width:s,height:b.end-b.start,fill:this._options.highlightColor,opacity:this._options.highlightOpacity,listening:false,name:"ruler-highlight-v"});this._vGroup.add(_),_.setZIndex(1),this._vHighlights.push(_);}this._highlightLayer.batchDraw();}_collectNodes(e,t){let n=e.getClassName(),r=e.name(),s=["overlay-hit","ruler-","guide-","_anchor","back","rotater"].some(l=>r.includes(l));if(!(n==="Transformer"||n==="Layer"||s))if(n==="Group"){let d=e.getChildren();if(d.length===0)return;for(let u of d)this._collectNodes(u,t);}else t.includes(e)||t.push(e);}_mergeSegments(e){if(e.length===0)return [];let t=e.slice().sort((s,l)=>s.start-l.start),n=t[0];if(!n)return [];let r=[],i={start:n.start,end:n.end};for(let s=1;s<t.length;s++){let l=t[s];l&&(l.start<=i.end+1?i.end=Math.max(i.end,l.end):(r.push(i),i={start:l.start,end:l.end}));}return r.push(i),r}_getSelectedKonvaNodes(){if(!this._core)return [];let e=[];try{this._cacheInvalidated&&(this._transformersCache=this._core.stage.find("Transformer"),this._cacheInvalidated=!1);for(let n of this._transformersCache){let r=n.nodes();for(let i of r)e.includes(i)||e.push(i);}}catch{}let t=[];for(let n of e)this._collectNodes(n,t);return t}update(){this._updateHighlights();}};var $e=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_visible",true);a(this,"_handleKeyDown",e=>{if(e.shiftKey&&(e.key==="r"||e.key==="R"||e.key==="\u043A"||e.key==="\u041A")){e.preventDefault(),this.toggle();return}(e.code==="Delete"||e.code==="Backspace")&&this.deleteActiveGuide()&&e.preventDefault();});let{enabled:t=true}=e;this._options={enabled:t};}onAttach(e){this._options.enabled&&(this._core=e,this._bindKeyboardEvents());}onDetach(e){this._unbindKeyboardEvents();}_bindKeyboardEvents(){globalThis.addEventListener("keydown",this._handleKeyDown);}_unbindKeyboardEvents(){globalThis.removeEventListener("keydown",this._handleKeyDown);}toggle(){this._visible?this.hide():this.show();}show(){if(!this._core)return;this._visible=true;let e=this._core.stage.findOne(".ruler-layer");e&&!e.isVisible()&&e.show();let t=this._core.stage.findOne(".guides-layer");t&&!t.isVisible()&&t.show(),this._core.stage.batchDraw();}hide(){if(!this._core)return;this._visible=false;let e=this._core.stage.findOne(".ruler-layer");e?.isVisible()&&e.hide();let t=this._core.stage.findOne(".guides-layer");t?.isVisible()&&t.hide(),this._core.stage.batchDraw();}isVisible(){return this._visible}deleteActiveGuide(){if(!this._core)return false;let e=this._core.plugins.list().find(t=>t instanceof Ge);return e&&"getActiveGuide"in e&&"removeActiveGuide"in e&&e.getActiveGuide.call(e)?(e.removeActiveGuide.call(e),true):false}};var Qe=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_layer",null);a(this,"_rect",null);a(this,"_start",null);a(this,"_transformer",null);a(this,"_selecting",false);a(this,"_options");this._options={rectStroke:e.rectStroke??"#2b83ff",rectFill:e.rectFill??"#2b83ff",rectStrokeWidth:e.rectStrokeWidth??1,rectOpacity:e.rectOpacity??.15,enableKeyboardShortcuts:e.enableKeyboardShortcuts??true};}onAttach(e){this._core=e;let t=new R.Layer({name:"area-selection-layer",listening:false});e.stage.add(t),this._layer=t,this._rect=new R.Rect({x:0,y:0,width:0,height:0,visible:false,stroke:this._options.rectStroke,strokeWidth:this._options.rectStrokeWidth,fill:this._options.rectFill,opacity:this._options.rectOpacity,listening:false}),t.add(this._rect);let n=e.stage;n.on("mousedown.area",r=>{if(r.evt.button!==0||r.target!==n&&r.target.getLayer()===e.nodes.layer)return;let i=n.getPointerPosition();if(!i||!this._rect)return;let s=n.findOne(".ruler-layer");if(s&&r.target.getLayer()===s)return;let l=n.findOne(".guides-layer");if(l&&r.target.getLayer()===l)return;let d=30;i.y<=d||i.x<=d||this._pointerInsidePermanentGroupBBox(i)||(this._selecting=true,this._start={x:i.x,y:i.y},this._rect.visible(true),this._rect.position({x:i.x,y:i.y}),this._rect.size({width:0,height:0}),this._layer?.batchDraw());}),n.on("mousemove.area",()=>{if(!this._selecting||!this._rect||!this._start)return;let r=n.getPointerPosition();if(!r)return;let i=30;if(r.y<=i||r.x<=i){this._selecting=false,this._rect.visible(false),this._layer?.batchDraw();return}let l=Math.min(this._start.x,r.x),d=Math.min(this._start.y,r.y),u=Math.abs(r.x-this._start.x),h=Math.abs(r.y-this._start.y);this._rect.position({x:l,y:d}),this._rect.size({width:u,height:h}),this._layer?.batchDraw();let c={x:l,y:d,width:u,height:h},p=this._core?.nodes.list()??[],f=new Set;for(let g of p){let m=g.getNode();if(m.getLayer()!==this._core?.nodes.layer)continue;let y=m.getClientRect({skipShadow:true,skipStroke:false});if(this._rectsIntersect(c,y)){let x=this._findOwningGroupBaseNode(m);f.add(x??g);}}let b=Array.from(f),_=this._getSelectionPlugin();if(_){let g=_.getMultiGroupController();b.length>0?g.ensure(b):g.destroy(),this._core?.stage.batchDraw();}}),n.on("mouseup.area",()=>{this._selecting&&this._finalizeArea();}),n.on("click.area",r=>{if(!this._core||r.evt.shiftKey)return;let s=this._getSelectionPlugin()?.getMultiGroupController(),l=!!s?.isActive();if(!l&&!this._isPermanentGroupSelected())return;let d=r.target,u=this._currentGroupNode();u?this._isAncestor(u,d)||this._clearSelection():l&&s&&(s.isInsideTempByTarget(d)||(s.destroy(),this._core.stage.batchDraw()));});}onDetach(e){e.stage.off(".area"),this._clearSelection(),this._layer&&this._layer.destroy(),this._layer=null,this._rect=null;}_finalizeArea(){if(!this._core||!this._rect||!this._start)return;this._selecting=false;let e=this._rect.getClientRect({skipStroke:true});this._rect.visible(false),this._layer?.batchDraw();let t=this._core.nodes.list(),n=[];for(let i of t){let s=i.getNode();if(s.getLayer()!==this._core.nodes.layer)continue;let d=s.getClientRect({skipShadow:true,skipStroke:false});this._rectsIntersect(e,d)&&n.push(s);}let r=this._getSelectionPlugin();if(r){let i=this._core.nodes.list(),s=new Set;for(let d of n){let u=i.find(c=>c.getNode()===d)??null,h=this._findOwningGroupBaseNode(d);h?s.add(h):u&&s.add(u);}let l=Array.from(s);l.length>0?(r.getMultiGroupController().ensure(l),this._core.stage.batchDraw()):r.getMultiGroupController().destroy();}}_clearSelection(){this._isPermanentGroupSelected()&&(this._transformer&&this._transformer.destroy(),this._transformer=null,this._core?.stage.batchDraw());let t=this._getSelectionPlugin()?.getMultiGroupController();t&&t.destroy();}_getSelectionPlugin(){return this._core?this._core.plugins.list().find(t=>t instanceof fe)??null:null}_rectsIntersect(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}_findOwningGroupBaseNode(e){if(!this._core)return null;let n=this._core.nodes.list().filter(i=>i instanceof de),r=e;for(;r;){let i=n.find(s=>s.getNode()===r)??null;if(i)return i;r=r.getParent();}return null}_isAncestor(e,t){let n=t;for(;n;){if(n===e)return true;n=n.getParent();}return false}_isPermanentGroupSelected(){if(!this._transformer)return false;let t=(typeof this._transformer.nodes=="function"?this._transformer.nodes():[])[0];return !t||!this._core?false:this._core.nodes.list().some(n=>n instanceof de&&n.getNode()===t)}_currentGroupNode(){if(!this._transformer)return null;let t=(typeof this._transformer.nodes=="function"?this._transformer.nodes():[])[0];return t&&t instanceof R.Group?t:null}_pointerInsidePermanentGroupBBox(e){if(!this._core)return false;let t=this._core.nodes.list();for(let n of t){if(!(n instanceof de))continue;let i=n.getNode().getClientRect({skipShadow:true,skipStroke:true});if(e.x>=i.x&&e.x<=i.x+i.width&&e.y>=i.y&&e.y<=i.y+i.height)return true}return false}};var et=class extends O{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_clipboard",null);a(this,"_selectionPlugin");a(this,"_onKeyDown",e=>{if(!this._core)return;if(!this._selectionPlugin){let r=this._core.plugins.list().find(i=>i instanceof fe);r&&(this._selectionPlugin=r);}if(!this._selectionPlugin||this._options.ignoreEditableTargets&&this._isEditableTarget(e.target))return;let t=e.ctrlKey||e.metaKey,n=e.shiftKey;if(t&&e.code==="KeyC"){e.preventDefault(),this._handleCopy();return}if(t&&e.code==="KeyX"){e.preventDefault(),this._handleCut();return}if(t&&e.code==="KeyV"){e.preventDefault(),this._handlePaste();return}if(e.code==="Delete"||e.code==="Backspace"){e.preventDefault(),this._handleDelete();return}if(t&&(e.code==="BracketRight"||n&&e.code==="Equal")){e.preventDefault(),this._handleMoveUp();return}if(t&&(e.code==="BracketLeft"||n&&e.code==="Minus")){e.preventDefault(),this._handleMoveDown();return}});let{target:t=globalThis,ignoreEditableTargets:n=true}=e;this._options={target:t,ignoreEditableTargets:n};}onAttach(e){this._core=e,this._options.target.addEventListener("keydown",this._onKeyDown);}onDetach(e){this._options.target.removeEventListener("keydown",this._onKeyDown),this._core=void 0,this._selectionPlugin=void 0,this._clipboard=null;}_isEditableTarget(e){if(!e||!(e instanceof HTMLElement))return false;let t=e.tagName.toLowerCase();return !!(t==="input"||t==="textarea"||e.isContentEditable)}_handleCopy(){let e=this._getSelectedNodes();if(e.length===0)return;let t=e.map(r=>this._serializeNode(r)),n=this._computeSelectionWorldCenter(e);this._clipboard={nodes:t,center:n},this._core&&this._core.eventBus.emit("clipboard:copy",e);}_handleCut(){let e=this._getSelectedNodes();if(e.length===0)return;let t=e.map(r=>this._serializeNode(r)),n=this._computeSelectionWorldCenter(e);this._clipboard={nodes:t,center:n},this._deleteNodes(e),this._core&&this._core.eventBus.emit("clipboard:cut",e);}_handlePaste(){if(!this._core||!this._clipboard||this._clipboard.nodes.length===0)return;let e=this._getPastePosition(),t=this._getClipboardCenter(),n=[];for(let r of this._clipboard.nodes){let i=r.position.x-t.x,s=r.position.y-t.y,l=this._deserializeNode(r,{x:e.x+i,y:e.y+s});l&&n.push(l);}n.length>0&&this._core.eventBus.emit("clipboard:paste",n),this._core.nodes.layer.batchDraw();}_handleDelete(){let e=this._getSelectedNodes();e.length!==0&&this._deleteNodes(e);}_getSelectedNodes(){if(!this._selectionPlugin)return [];let e=this._selectionPlugin._tempMultiGroup;if(e&&typeof e.getChildren=="function"&&this._core){let r=e.getChildren(),i=this._core.nodes.list(),s=new Set;for(let l of r){let d=i.find(u=>u.getNode()===l);d&&s.add(d);}if(s.size>0)return Array.from(s)}let t=this._selectionPlugin._tempMultiSet;if(t&&t.size>0)return Array.from(t);let n=this._selectionPlugin._selected;return n?[n]:[]}_deleteNodes(e){if(this._core){if(this._selectionPlugin){let t=this._selectionPlugin;typeof t._destroyTempMulti=="function"&&t._destroyTempMulti(),typeof t._clearSelection=="function"&&t._clearSelection();}for(let t of e)this._core.nodes.remove(t);}}_serializeNode(e){let t=e.getNode(),n=t.getAttrs(),r=this._getNodeTypeFromKonva(t),i={x:0,y:0};if(this._core){let d=t.getAbsolutePosition(),h=this._core.nodes.world.getAbsoluteTransform().copy().invert().point(d);i={x:h.x,y:h.y};}let s={type:r,config:{...n,id:void 0},position:i};if(r==="group"){let d=t.getChildren(),u=[];for(let h of d){let c=this._serializeKonvaNode(h);c&&u.push(c);}u.length>0&&(s.children=u);}return s}_serializeKonvaNode(e){if(!this._core)return null;let t=e.getAttrs(),r=e.getClassName().toLowerCase();r==="rect"&&(r="shape");let i={type:r,config:{...t,id:void 0},position:{x:e.x(),y:e.y()}};if(e instanceof R.Group){let s=e.getChildren(),l=[];for(let d of s){let u=this._serializeKonvaNode(d);u&&l.push(u);}l.length>0&&(i.children=l);}return i}_getNodeTypeFromKonva(e){let t=e.getClassName();return {Rect:"shape",Circle:"circle",Ellipse:"ellipse",Text:"text",Image:"image",Group:"group",Arc:"arc",Star:"star",Arrow:"arrow",Ring:"ring",RegularPolygon:"regularPolygon",Label:"label"}[t]??t.toLowerCase()}_deserializeNode(e,t){if(!this._core)return null;let{zIndex:n,...r}=e.config,i={...r,x:t.x,y:t.y};try{let s=null;switch(e.type){case "shape":s=this._core.nodes.addShape(i);break;case "text":s=this._core.nodes.addText(i);break;case "circle":s=this._core.nodes.addCircle(i);break;case "ellipse":s=this._core.nodes.addEllipse(i);break;case "arc":s=this._core.nodes.addArc(i);break;case "star":s=this._core.nodes.addStar(i);break;case "arrow":s=this._core.nodes.addArrow(i);break;case "ring":s=this._core.nodes.addRing(i);break;case "regularPolygon":case "regularpolygon":s=this._core.nodes.addRegularPolygon(i);break;case "image":s=this._core.nodes.addImage(i);break;case "label":return globalThis.console.warn("LabelNode is not supported for copy/paste yet"),null;case "group":{s=this._core.nodes.addGroup(i);let d=s.getNode();if(e.config.scaleX!==void 0&&d.scaleX(e.config.scaleX),e.config.scaleY!==void 0&&d.scaleY(e.config.scaleY),e.config.rotation!==void 0&&d.rotation(e.config.rotation),e.config.skewX!==void 0&&d.skewX(e.config.skewX),e.config.skewY!==void 0&&d.skewY(e.config.skewY),e.config.offsetX!==void 0&&d.offsetX(e.config.offsetX),e.config.offsetY!==void 0&&d.offsetY(e.config.offsetY),e.children&&e.children.length>0)for(let u of e.children){let h=this._deserializeNode(u,{x:u.position.x,y:u.position.y});if(h){let c=h.getNode();typeof c.draggable=="function"&&c.draggable(!1),c.moveTo(d);}}break}default:return globalThis.console.warn(`Unknown node type: ${e.type}`),null}let l=s.getNode();return e.config.scaleX!==void 0&&l.scaleX(e.config.scaleX),e.config.scaleY!==void 0&&l.scaleY(e.config.scaleY),e.config.rotation!==void 0&&l.rotation(e.config.rotation),e.config.skewX!==void 0&&l.skewX(e.config.skewX),e.config.skewY!==void 0&&l.skewY(e.config.skewY),e.config.offsetX!==void 0&&l.offsetX(e.config.offsetX),e.config.offsetY!==void 0&&l.offsetY(e.config.offsetY),s}catch(s){return globalThis.console.error("Failed to deserialize node:",s),null}}_getPastePosition(){if(!this._core)return {x:0,y:0};let t=this._core.stage.getPointerPosition();if(t&&this._isPointerOnScreen(t)){let i=this._core.nodes.world.getAbsoluteTransform().copy().invert().point(t);return {x:i.x,y:i.y}}return this._getScreenCenter()}_isPointerOnScreen(e){if(!this._core)return false;let t=this._core.stage,n=t.width(),r=t.height();return e.x>=0&&e.x<=n&&e.y>=0&&e.y<=r}_getScreenCenter(){if(!this._core)return {x:0,y:0};let e=this._core.stage,t=this._core.nodes.world,n=e.width()/2,r=e.height()/2,s=t.getAbsoluteTransform().copy().invert().point({x:n,y:r});return {x:s.x,y:s.y}}_getClipboardCenter(){if(!this._clipboard||this._clipboard.nodes.length===0)return {x:0,y:0};if(this._clipboard.center)return this._clipboard.center;let e=0,t=0;for(let n of this._clipboard.nodes)e+=n.position.x,t+=n.position.y;return {x:e/this._clipboard.nodes.length,y:t/this._clipboard.nodes.length}}_computeSelectionWorldCenter(e){if(!this._core||e.length===0)return {x:0,y:0};let t=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let c of e){let f=c.getNode().getClientRect({skipShadow:true,skipStroke:true});t=Math.min(t,f.x),n=Math.min(n,f.y),r=Math.max(r,f.x+f.width),i=Math.max(i,f.y+f.height);}if(!isFinite(t)||!isFinite(n)||!isFinite(r)||!isFinite(i))return {x:0,y:0};let s=(t+r)/2,l=(n+i)/2,h=this._core.nodes.world.getAbsoluteTransform().copy().invert().point({x:s,y:l});return {x:h.x,y:h.y}}_handleMoveUp(){let e=this._getSelectedNodes();if(e.length!==0){for(let t of e){let n=t.getNode();if(this._isNodeInsidePermanentGroup(n))continue;let r=n.zIndex();n.moveUp();let i=n.zIndex();this._syncGroupZIndex(n),this._core&&r!==i&&this._core.eventBus.emit("node:zIndexChanged",t,r,i);}this._core&&(this._core.nodes.layer.draw(),this._core.stage.batchDraw());}}_handleMoveDown(){let e=this._getSelectedNodes();if(e.length!==0){for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n)continue;let r=n.getNode();if(this._isNodeInsidePermanentGroup(r))continue;let i=r.zIndex();r.moveDown();let s=r.zIndex();this._syncGroupZIndex(r),this._core&&i!==s&&this._core.eventBus.emit("node:zIndexChanged",n,i,s);}this._core&&(this._core.nodes.layer.draw(),this._core.stage.batchDraw());}}_isNodeInsidePermanentGroup(e){if(e instanceof R.Group)return false;let t=e.getParent();return t?t instanceof R.Group&&t.name()!=="world":false}_syncGroupZIndex(e){let t=e.getParent();t&&(e instanceof R.Group||t instanceof R.Group&&t.name());}};export{Ce as ArcNode,Qe as AreaSelectionPlugin,Te as ArrowNode,Ve as CameraHotkeysPlugin,Re as CameraManager,ke as CircleNode,Ye as CoreEngine,ge as DebounceHelper,Se as EllipseNode,we as EventBus,Ze as GridPlugin,de as GroupNode,Ne as ImageNode,Ue as LogoPlugin,et as NodeHotkeysPlugin,Ae as NodeManager,De as Plugins,Ke as RegularPolygonNode,Pe as RingNode,Ge as RulerGuidesPlugin,je as RulerHighlightPlugin,$e as RulerManagerPlugin,qe as RulerPlugin,fe as SelectionPlugin,ye as ShapeNode,Me as StarNode,xe as TextNode,he as ThrottleHelper};
|
|
1
|
+
import M from'konva';var Ct=Object.defineProperty;var Tt=(C,n,e)=>n in C?Ct(C,n,{enumerable:true,configurable:true,writable:true,value:e}):C[n]=e;var a=(C,n,e)=>Tt(C,typeof n!="symbol"?n+"":n,e);var Ae=class{constructor(){a(this,"_listeners");this._listeners=new Map;}get listeners(){return this._listeners}on(n,e){this._listeners.has(n)||this._listeners.set(n,[]),this._listeners.get(n).push(e);}off(n,e){let t=this._listeners.get(n);t&&this._listeners.set(n,t.filter(o=>o!==e));}once(n,e){let t=((...o)=>{this.off(n,t),e(...o);});this.on(n,t);}emit(n,...e){let t=this._listeners.get(n);t&&[...t].forEach(o=>{o(...e);});}};var Ee=class{constructor(n){a(this,"_stage");a(this,"_eventBus");a(this,"_target");a(this,"_scale");a(this,"_minScale");a(this,"_maxScale");a(this,"_zoomStep");a(this,"_panStep");a(this,"_wheelScheduled",false);a(this,"_pendingWheelEvent",null);this._stage=n.stage,this._eventBus=n.eventBus,this._target=n.target??n.stage,this._scale=n.initialScale??1,this._minScale=n.minScale??.1,this._maxScale=n.maxScale??5,this._zoomStep=n.zoomStep??1.05,this._panStep=n.panStep??40,this._initWheelZoom();}_initWheelZoom(){this._stage.on("wheel",n=>{if(n.evt.preventDefault(),this._pendingWheelEvent=n.evt,this._wheelScheduled)return;this._wheelScheduled=true;let e=globalThis.requestAnimationFrame;e(()=>{this._wheelScheduled=false,this._pendingWheelEvent&&(this._handleWheel(this._pendingWheelEvent),this._pendingWheelEvent=null);});});}_handleWheel(n){let e=this._target.scaleX()||1,t=this._stage.getPointerPosition();if(!t)return;let o=this._zoomStep,s=(n.deltaY>0?-1:1)>0?e*o:e/o;s=Math.max(this._minScale,Math.min(this._maxScale,s));let r={x:(t.x-this._target.x())/e,y:(t.y-this._target.y())/e};this._target.scale({x:s,y:s});let l={x:t.x-r.x*s,y:t.y-r.y*s};this._target.position(l),this._stage.batchDraw(),this._scale=s,this._eventBus.emit("camera:zoom",{scale:this._scale,position:l});}get zoomStep(){return this._zoomStep}get panStep(){return this._panStep}setZoom(n){this._scale=Math.max(this._minScale,Math.min(this._maxScale,n)),this._target.scale({x:this._scale,y:this._scale}),this._stage.batchDraw(),this._eventBus.emit("camera:setZoom",{scale:this._scale});}zoomIn(n){n===void 0?this.setZoom(this._scale*this._zoomStep):this.setZoom(this._scale+n);}zoomOut(n){n===void 0?this.setZoom(this._scale/this._zoomStep):this.setZoom(this._scale-n);}reset(){this.setZoom(1),this._target.position({x:0,y:0}),this._stage.batchDraw(),this._eventBus.emit("camera:reset");}setDraggable(n){this._stage.draggable(n);}setZoomStep(n){n&&n>0&&(this._zoomStep=n,this._eventBus.emit("camera:zoomStep",{zoomStep:n}));}setPanStep(n){typeof n=="number"&&isFinite(n)&&(this._panStep=n,this._eventBus.emit("camera:panStep",{panStep:n}));}};var Pe=class{constructor(n){a(this,"_node");a(this,"_addons",new Set);this._node=n;}add(n){let e=Array.isArray(n)?n:[n];for(let t of e)this._addons.has(t)||(this._addons.add(t),t.attach(this._node));return this._node}remove(n){let e=Array.isArray(n)?n:[n];for(let t of e)this._addons.has(t)&&(this._addons.delete(t),t.detach(this._node));return this._node}list(){return Array.from(this._addons)}has(n){return this._addons.has(n)}clear(){this._addons.forEach(n=>{n.detach(this._node);}),this._addons.clear();}};var O=class{constructor(n,e={}){a(this,"konvaNode");a(this,"id");a(this,"addons");this.konvaNode=n,this.id=e.id??`node_${String(Date.now())}_${String(Math.random())}`,this.addons=new Pe(this),e.x&&this.konvaNode.x(e.x),e.y&&this.konvaNode.y(e.y),e.width&&this.konvaNode.width(e.width),e.height&&this.konvaNode.height(e.height);}getKonvaNode(){return this.konvaNode}setPosition({x:n,y:e}){return this.konvaNode.position({x:n,y:e}),this}getPosition(){return this.konvaNode.position()}remove(){this.addons.clear(),this.konvaNode.destroy();}};var Oe=class extends O{constructor(n={}){let e=new M.Arc({});e.x(n.x??0),e.y(n.y??0),e.innerRadius(n.innerRadius??0),e.outerRadius(n.outerRadius??0),e.angle(n.angle??0),e.rotation(n.rotation??0),n.clockwise!==void 0&&e.clockwise(n.clockwise),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),super(e,n);}getInnerRadius(){return this.konvaNode.innerRadius()}getOuterRadius(){return this.konvaNode.outerRadius()}getAngle(){return this.konvaNode.angle()}isClockwise(){return this.konvaNode.clockwise()}setInnerRadius(n){return this.konvaNode.innerRadius(n),this}setOuterRadius(n){return this.konvaNode.outerRadius(n),this}setAngle(n){return this.konvaNode.angle(n),this}setRotationDeg(n){return this.konvaNode.rotation(n),this}setClockwise(n){return this.konvaNode.clockwise(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var Ie=class extends O{constructor(n={}){let e=new M.Arrow({});e.x(n.x??0),e.y(n.y??0),e.points(n.points??[]),n.tension&&e.tension(n.tension),n.pointerLength&&e.pointerLength(n.pointerLength),n.pointerWidth&&e.pointerWidth(n.pointerWidth),n.pointerAtBeginning&&e.pointerAtBeginning(n.pointerAtBeginning),n.pointerAtEnding&&e.pointerAtEnding(n.pointerAtEnding),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),super(e,n);}getPoints(){return this.konvaNode.points()}getTension(){return this.konvaNode.tension()}getPointerLength(){return this.konvaNode.pointerLength()}getPointerWidth(){return this.konvaNode.pointerWidth()}getPointerAtBeginning(){return this.konvaNode.pointerAtBeginning()}getPointerAtEnding(){return this.konvaNode.pointerAtEnding()}setPoints(n){return this.konvaNode.points(n),this}setTension(n){return this.konvaNode.tension(n),this}setPointerLength(n){return this.konvaNode.pointerLength(n),this}setPointerWidth(n){return this.konvaNode.pointerWidth(n),this}setPointerAtBeginning(n){return this.konvaNode.pointerAtBeginning(n),this}setPointerAtEnding(n){return this.konvaNode.pointerAtEnding(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var ze=class extends O{constructor(n={}){let e=new M.Circle({});e.x(n.x??0),e.y(n.y??0),e.radius(n.radius??0),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),e.draggable(true),super(e,n);}getRadius(){return this.konvaNode.radius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setRadius(n){return this.konvaNode.radius(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var We=class extends O{constructor(n={}){let e=new M.Ellipse({});e.x(n.x??0),e.y(n.y??0),e.radiusX(n.radiusX??0),e.radiusY(n.radiusY??0),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),super(e,n);}getRadiusX(){return this.konvaNode.radiusX()}getRadiusY(){return this.konvaNode.radiusY()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setRadiusX(n){return this.konvaNode.radiusX(n),this}setRadiusY(n){return this.konvaNode.radiusY(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var de=class extends O{constructor(n={}){let e=new M.Group({});e.x(n.x??0),e.y(n.y??0),e.draggable(n.draggable??true),n.listening!==void 0&&e.listening(n.listening),n.clip&&e.clip(n.clip),super(e,n);}addChild(n){let e=n.getKonvaNode?n.getKonvaNode():n;return this.konvaNode.add(e),this.konvaNode.getLayer()?.batchDraw(),this}removeChild(n){return (n.getKonvaNode?n.getKonvaNode():n).remove(),this.konvaNode.getLayer()?.batchDraw(),this}removeAllChildren(){return this.konvaNode.removeChildren(),this.konvaNode.getLayer()?.batchDraw(),this}getChildren(){return this.konvaNode.getChildren()}findByName(n){return this.konvaNode.find(`.${n}`)}setDraggable(n){return this.konvaNode.draggable(n),this}isDraggable(){return this.konvaNode.draggable()}setListening(n){return this.konvaNode.listening(n),this}isListening(){return this.konvaNode.listening()}setClip(n){return this.konvaNode.clip(n),this.konvaNode.getLayer()?.batchDraw(),this}};var Xe=class extends O{constructor(n={}){let e=new M.Image({});e.x(n.x??0),e.y(n.y??0),e.width(n.width??150),e.height(n.height??150),e.image(n.image??null),super(e,n),!n.image&&n.src&&this.setSrc(n.src);}getSize(){return this.konvaNode.size()}async setSrc(n,e="anonymous"){let t=await this._loadHTMLImage(n,e);return this.konvaNode.image(t),this.konvaNode.getLayer()?.batchDraw(),this}setImage(n){return this.konvaNode.image(n),this.konvaNode.getLayer()?.batchDraw(),this}setSize({width:n,height:e}){return this.konvaNode.size({width:n,height:e}),this}setCornerRadius(n){return this.konvaNode.cornerRadius(n),this}getCornerRadius(){return this.konvaNode.cornerRadius()}_loadHTMLImage(n,e="anonymous"){return new Promise((t,o)=>{let i=globalThis.Image??null;if(!i){o(new Error("Image constructor is not available in current environment"));return}let s=new i,r=e;s.crossOrigin=r,s.onload=()=>{t(s);},s.onerror=()=>{o(new Error(`Failed to load image: ${n}`));},s.src=n;})}};var Ye=class extends O{constructor(n={}){let e=new M.RegularPolygon({});e.x(n.x??0),e.y(n.y??0),e.sides(n.sides??3),e.radius(n.radius??60),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),super(e,n);}getSides(){return this.konvaNode.sides()}getRadius(){return this.konvaNode.radius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setSides(n){return this.konvaNode.sides(n),this}setRadius(n){return this.konvaNode.radius(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var Fe=class extends O{constructor(n={}){let e=new M.Ring({});e.x(n.x??0),e.y(n.y??0),e.innerRadius(n.innerRadius??20),e.outerRadius(n.outerRadius??40),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),super(e,n);}getInnerRadius(){return this.konvaNode.innerRadius()}getOuterRadius(){return this.konvaNode.outerRadius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setInnerRadius(n){return this.konvaNode.innerRadius(n),this}setOuterRadius(n){return this.konvaNode.outerRadius(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var Ue=class extends O{constructor(n){let e=new M.Rect({x:n.x??0,y:n.y??0,width:n.width??100,height:n.height??100,fill:n.fill??"lightgray",stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,cornerRadius:n.cornerRadius??0,draggable:true});super(e,n);}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}setCornerRadius(n){return this.konvaNode.cornerRadius(n),this}setSize({width:n,height:e}){return this.konvaNode.size({width:n,height:e}),this}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}getCornerRadius(){return this.konvaNode.cornerRadius()}};var Ve=class extends O{constructor(n={}){let e=new M.Star({});e.x(n.x??0),e.y(n.y??0),e.numPoints(n.numPoints??5),e.innerRadius(n.innerRadius??20),e.outerRadius(n.outerRadius??40),e.fill(n.fill??"black"),e.stroke(n.stroke??"black"),e.strokeWidth(n.strokeWidth??0),super(e,n);}getNumPoints(){return this.konvaNode.numPoints()}getInnerRadius(){return this.konvaNode.innerRadius()}getOuterRadius(){return this.konvaNode.outerRadius()}getFill(){return this.konvaNode.fill()}getStroke(){return this.konvaNode.stroke()}getStrokeWidth(){return this.konvaNode.strokeWidth()}setNumPoints(n){return this.konvaNode.numPoints(n),this}setInnerRadius(n){return this.konvaNode.innerRadius(n),this}setOuterRadius(n){return this.konvaNode.outerRadius(n),this}setFill(n){return this.konvaNode.fill(n),this}setStroke(n){return this.konvaNode.stroke(n),this}setStrokeWidth(n){return this.konvaNode.strokeWidth(n),this}};var xe=class extends O{constructor(e={}){let t=new M.Text({x:e.x??0,y:e.y??0,...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},text:e.text??"Text",fontSize:e.fontSize??16,fontFamily:e.fontFamily??"Inter, Arial, sans-serif",fontStyle:e.fontStyle??"normal",fill:e.fill??"#ffffff",align:e.align??"left",verticalAlign:e.verticalAlign??"top",padding:e.padding??0,lineHeight:e.lineHeight??1});super(t,e);a(this,"_editable");a(this,"_isEditing",false);a(this,"_textarea",null);a(this,"_onTextChangeCallbacks",[]);a(this,"_onEditStartCallbacks",[]);a(this,"_onEditEndCallbacks",[]);a(this,"_pendingGroupEditDblClick",false);a(this,"_groupEditClickResetAttached",false);a(this,"_oldText","");a(this,"_keyHandler",null);a(this,"_clickHandler",null);a(this,"_syncTextareaRafId",null);this._editable=e.editable??true,this._editable&&this._setupEditHandler(),this._setupTransformHandler();}getText(){return this.konvaNode.text()}setText(e){return this.konvaNode.text(e),this}setFontSize(e){return this.konvaNode.fontSize(e),this}setFontFamily(e){return this.konvaNode.fontFamily(e),this}setFill(e){return this.konvaNode.fill(e),this}setAlign(e){return this.konvaNode.align(e),this}setPadding(e){return this.konvaNode.padding(e),this}setSize({width:e,height:t}){return this.konvaNode.size({width:e,height:t}),this}setLineHeight(e){return this.konvaNode.lineHeight(e),this}setVerticalAlign(e){return this.konvaNode.verticalAlign(e),this}isEditable(){return this._editable}setEditable(e){return this._editable===e?this:(this._editable=e,e?this._setupEditHandler():(this.konvaNode.off("dblclick.textEdit dbltap.textEdit"),this._isEditing&&this.cancelEdit()),this)}isEditing(){return this._isEditing}startEdit(){this._isEditing||this._openTextarea();}finishEdit(){!this._isEditing||!this._textarea||this._saveAndClose(false);}cancelEdit(){!this._isEditing||!this._textarea||this._saveAndClose(true);}onTextChange(e){return this._onTextChangeCallbacks.push(e),this}offTextChange(e){let t=this._onTextChangeCallbacks.indexOf(e);return t!==-1&&this._onTextChangeCallbacks.splice(t,1),this}onEditStart(e){return this._onEditStartCallbacks.push(e),this}offEditStart(e){let t=this._onEditStartCallbacks.indexOf(e);return t!==-1&&this._onEditStartCallbacks.splice(t,1),this}onEditEnd(e){return this._onEditEndCallbacks.push(e),this}offEditEnd(e){let t=this._onEditEndCallbacks.indexOf(e);return t!==-1&&this._onEditEndCallbacks.splice(t,1),this}_setupEditHandler(){this.konvaNode.on("dblclick.textEdit dbltap.textEdit",()=>{let e=this.konvaNode.getParent(),t=e?e.getParent():null;if(!(e instanceof M.Group&&t instanceof M.Group)){this._openTextarea();return}if(!this._groupEditClickResetAttached){let i=this.konvaNode.getStage();i&&(this._groupEditClickResetAttached=true,i.on("mousedown.textEditGroupReset",s=>{s.target!==this.konvaNode&&(this._pendingGroupEditDblClick=false);}));}if(!this._isEditing){if(!this._pendingGroupEditDblClick){this._pendingGroupEditDblClick=true;return}this._pendingGroupEditDblClick=false,this._openTextarea();}});}_setupTransformHandler(){this.konvaNode.on("transform.textResize",()=>{let e=this.konvaNode.scaleX(),t=this.konvaNode.scaleY(),o=Math.max(1,this.konvaNode.width()*e);this.konvaNode.width(o);let i=this.konvaNode.height(),s=Math.max(1,i*t);this.konvaNode.height(s),this.konvaNode.scaleX(1),this.konvaNode.scaleY(1);});}_syncTextareaPosition(){if(!this._isEditing||!this._textarea)return;let e=this.konvaNode.getStage();if(!e)return;let t=this.konvaNode.absolutePosition(),o=e.container().getBoundingClientRect(),i=this.konvaNode.getAbsoluteScale();this._textarea.style.top=String(o.top+t.y)+"px",this._textarea.style.left=String(o.left+t.x)+"px",this._textarea.style.width=String((this.konvaNode.width()-this.konvaNode.padding()*2)*i.x)+"px",this._textarea.style.fontSize=String(this.konvaNode.fontSize()*i.x)+"px",this._syncTextareaRafId=globalThis.requestAnimationFrame(()=>{this._syncTextareaPosition();});}_openTextarea(){if(this._isEditing)return;let e=this.konvaNode.getStage();if(!e)return;this._isEditing=true,this._oldText=this.konvaNode.text(),this.konvaNode.hide(),e.batchDraw();let t=this.konvaNode.absolutePosition(),o=e.container().getBoundingClientRect(),i=this.konvaNode.getAbsoluteScale(),s=globalThis.document.createElement("textarea");globalThis.document.body.appendChild(s),this._textarea=s,s.value=this.konvaNode.text(),s.style.position="absolute",s.style.top=String(o.top+t.y)+"px",s.style.left=String(o.left+t.x)+"px",s.style.width=String((this.konvaNode.width()-this.konvaNode.padding()*2)*i.x)+"px",s.style.fontSize=String(this.konvaNode.fontSize()*i.x)+"px",s.style.border="none",s.style.padding="0",s.style.margin="0",s.style.overflow="hidden",s.style.background="none",s.style.outline="none",s.style.resize="none",s.style.lineHeight=String(this.konvaNode.lineHeight()),s.style.fontFamily=this.konvaNode.fontFamily(),s.style.transformOrigin="left top",s.style.textAlign=this.konvaNode.align();let r=this.konvaNode.fill();s.style.color=typeof r=="string"?r:"#000000";let l=this.konvaNode.fontStyle();s.style.fontStyle=l.includes("italic")?"italic":"normal",s.style.fontWeight=l.includes("bold")?"bold":"normal";let d=this.konvaNode.rotation();d&&(s.style.transform="rotateZ("+String(d)+"deg)"),s.style.height="auto",s.focus(),s.select(),this._syncTextareaRafId=globalThis.requestAnimationFrame(()=>{this._syncTextareaPosition();});for(let c of this._onEditStartCallbacks)c();this._keyHandler=c=>{if(c.key==="Enter"&&(c.ctrlKey||c.metaKey)){c.preventDefault(),this._saveAndClose(false);return}if(c.key==="Escape"){c.preventDefault(),this._saveAndClose(true);return}globalThis.requestAnimationFrame(()=>{this._textarea&&(this._textarea.style.height="auto",this._textarea.style.height=String(this._textarea.scrollHeight+this.konvaNode.fontSize())+"px");});},this._clickHandler=c=>{c.target!==s&&this._saveAndClose(false);},s.addEventListener("keydown",this._keyHandler),globalThis.setTimeout(()=>{this._clickHandler&&(globalThis.addEventListener("click",this._clickHandler),globalThis.addEventListener("touchstart",this._clickHandler));});}_saveAndClose(e){if(!this._textarea)return;let t=e?this._oldText:this._textarea.value;if(this.konvaNode.text(t),!e){let o=this._textarea,i=this.konvaNode.getAbsoluteScale(),s=i.x||i.y||1,r=o.scrollHeight/s,l=this.konvaNode.height();Number.isFinite(r)&&r>l&&this.konvaNode.height(r);}this._syncTextareaRafId!==null&&(globalThis.cancelAnimationFrame(this._syncTextareaRafId),this._syncTextareaRafId=null),this._keyHandler&&this._textarea.removeEventListener("keydown",this._keyHandler),this._clickHandler&&(globalThis.removeEventListener("click",this._clickHandler),globalThis.removeEventListener("touchstart",this._clickHandler)),this._textarea.remove(),this._textarea=null,this._keyHandler=null,this._clickHandler=null,this.konvaNode.show(),this.konvaNode.getStage()?.batchDraw(),this._isEditing=false,this._pendingGroupEditDblClick=false;for(let o of this._onTextChangeCallbacks)o({oldText:this._oldText,newText:t,cancelled:e});for(let o of this._onEditEndCallbacks)o();}};var Re=class{constructor(n,e){a(this,"_layer");a(this,"_world");a(this,"_nodes",new Map);a(this,"_stage");a(this,"_eventBus");a(this,"_batchDrawScheduled",false);a(this,"_listCache",null);a(this,"_listCacheInvalidated",true);this._layer=new M.Layer,this._world=new M.Group,this._layer.add(this._world),this._stage=n,this._stage.add(this._layer),this._eventBus=e;}get layer(){return this._layer}get world(){return this._world}get stage(){return this._stage}get eventBus(){return this._eventBus}addShape(n){let e=new Ue(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addText(n){let e=new xe(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addImage(n){let e=new Xe(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addCircle(n){let e=new ze(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addEllipse(n){let e=new We(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addArc(n){let e=new Oe(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addStar(n){let e=new Ve(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addArrow(n){let e=new Ie(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addRing(n){let e=new Fe(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addRegularPolygon(n){let e=new Ye(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}addGroup(n){let e=new de(n);return this._world.add(e.getKonvaNode()),this._nodes.set(e.id,e),this._listCacheInvalidated=true,this._eventBus.emit("node:created",e),this._scheduleBatchDraw(),e}remove(n){this._eventBus.emit("node:removed",n),n.remove(),this._nodes.delete(n.id),this._listCacheInvalidated=true,this._scheduleBatchDraw();}findById(n){return this._nodes.get(n)}list(){return (this._listCacheInvalidated||!this._listCache)&&(this._listCache=Array.from(this._nodes.values()),this._listCacheInvalidated=false),this._listCache}_scheduleBatchDraw(){if(this._batchDrawScheduled)return;this._batchDrawScheduled=true;let n=globalThis.requestAnimationFrame;n(()=>{this._batchDrawScheduled=false,this._layer.batchDraw();});}};var pe=class{constructor(n=16){a(this,"_lastTime",0);a(this,"_throttle");this._throttle=n;}shouldExecute(){let n=Date.now();return n-this._lastTime<this._throttle?false:(this._lastTime=n,true)}reset(){this._lastTime=0;}setThrottle(n){this._throttle=n;}getThrottle(){return this._throttle}};var je=class{constructor(n={}){a(this,"_enabled");a(this,"_levels");a(this,"_currentScale",1);a(this,"_appliedNodes",new Map);this._enabled=n.enabled??true,this._levels=n.levels??[{minScale:0,maxScale:.1,simplify:true,disableStroke:true,disableShadow:true,disablePerfectDraw:true},{minScale:.1,maxScale:.3,simplify:true,disableShadow:true,disablePerfectDraw:true},{minScale:.3,maxScale:1/0,simplify:false}];}_getLODLevel(n){return this._enabled?this._levels.find(t=>n>=t.minScale&&n<t.maxScale)??null:null}applyLOD(n,e){if(!this._enabled)return;this._currentScale=e;let t=this._getLODLevel(e);if(!t?.simplify){this._restoreNode(n);return}let o=n.getKonvaNode(),i=this._appliedNodes.get(n.id);i!==t&&(i||(o._originalLOD={stroke:o.stroke?.(),strokeEnabled:o.strokeEnabled(),shadow:o.shadowEnabled(),perfectDraw:o.perfectDrawEnabled?.()}),t.disableStroke&&o.strokeEnabled(false),t.disableShadow&&o.shadowEnabled(false),t.disablePerfectDraw&&o.perfectDrawEnabled&&o.perfectDrawEnabled(false),this._appliedNodes.set(n.id,t));}_restoreNode(n){let e=n.getKonvaNode(),t=e._originalLOD;t&&(e.strokeEnabled(t.strokeEnabled),e.shadowEnabled(t.shadow),t.perfectDraw!==void 0&&e.perfectDrawEnabled&&e.perfectDrawEnabled(t.perfectDraw),this._appliedNodes.delete(n.id),delete e._originalLOD);}applyToAll(n,e){if(this._enabled)for(let t of n)this.applyLOD(t,e);}restoreAll(n){for(let e of n)this._restoreNode(e);this._appliedNodes.clear();}enable(){this._enabled=true;}disable(n){this._enabled=false,this.restoreAll(n);}get enabled(){return this._enabled}get currentScale(){return this._currentScale}getStats(){return {enabled:this._enabled,currentScale:this._currentScale,appliedNodes:this._appliedNodes.size,currentLevel:this._getLODLevel(this._currentScale)}}setLevels(n){this._levels=n;}};var Ze=class{constructor(n,e,t,o={}){this._stage=n;this._world=e;this._nodeManager=t;a(this,"_enabled");a(this,"_bufferZone");a(this,"_throttle");a(this,"_viewport",{x:0,y:0,width:0,height:0});a(this,"_visibleNodes",new Set);a(this,"_hiddenNodes",new Set);a(this,"_updateScheduled",false);a(this,"_lod",null);this._enabled=o.enabled??true,this._bufferZone=o.bufferZone??200,this._throttle=new pe(o.throttleMs??16),o.lod&&(this._lod=new je(o.lod)),this._updateViewport(),this._setupListeners(),this._enabled&&this.updateVisibility();}_updateViewport(){let n=this._world.scaleX(),e=this._world.position();this._viewport={x:-e.x/n-this._bufferZone,y:-e.y/n-this._bufferZone,width:this._stage.width()/n+this._bufferZone*2,height:this._stage.height()/n+this._bufferZone*2};}_getNodeBBox(n){let t=n.getKonvaNode().getClientRect({relativeTo:this._world});return {x:t.x,y:t.y,width:t.width,height:t.height}}_isNodeVisible(n){let e=this._getNodeBBox(n);return !(e.x+e.width<this._viewport.x||e.x>this._viewport.x+this._viewport.width||e.y+e.height<this._viewport.y||e.y>this._viewport.y+this._viewport.height)}updateVisibility(){if(!this._enabled||!this._throttle.shouldExecute())return;let n=this._nodeManager.list(),e=new Set,t=0;for(let o of n){let i=this._isNodeVisible(o),s=o.getKonvaNode();i?(e.add(o.id),this._hiddenNodes.has(o.id)&&(s.visible(true),s.listening(true),this._hiddenNodes.delete(o.id),t++)):this._hiddenNodes.has(o.id)||(s.visible(false),s.listening(false),this._hiddenNodes.add(o.id),t++);}if(this._visibleNodes=e,this._lod?.enabled&&t>0){let o=this._world.scaleX();for(let i of n)e.has(i.id)&&this._lod.applyLOD(i,o);}t>0&&this._nodeManager.layer.batchDraw();}_setupListeners(){this._world.on("xChange yChange scaleXChange scaleYChange",()=>{this._scheduleUpdate();}),typeof globalThis.window<"u"&&globalThis.window.addEventListener("resize",()=>{this._updateViewport(),this._scheduleUpdate();}),this._nodeManager.eventBus.on("node:removed",n=>{this._visibleNodes.delete(n.id),this._hiddenNodes.delete(n.id);});}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=true,globalThis.requestAnimationFrame(()=>{this._updateViewport(),this.updateVisibility(),this._updateScheduled=false;}));}enable(){this._enabled||(this._enabled=true,this.updateVisibility());}disable(){if(this._enabled){this._enabled=false;for(let n of this._hiddenNodes){let e=this._nodeManager.findById(n);if(e){let t=e.getKonvaNode();t.visible(true),t.listening(true);}}this._hiddenNodes.clear(),this._visibleNodes.clear(),this._nodeManager.layer.batchDraw();}}getStats(){let n=this._nodeManager.list().length,e=this._visibleNodes.size,t=this._hiddenNodes.size;return {total:n,visible:e,hidden:t,cullingRate:n>0?t/n*100:0}}setBufferZone(n){this._bufferZone=n,this._updateViewport(),this._scheduleUpdate();}setThrottle(n){this._throttle=new pe(n);}get enabled(){return this._enabled}get viewport(){return {...this._viewport}}forceUpdate(){this._throttle.reset(),this._updateViewport(),this.updateVisibility();}get lod(){return this._lod}destroy(){if(this.disable(),this._visibleNodes.clear(),this._hiddenNodes.clear(),this._lod){let n=this._nodeManager.list();this._lod.restoreAll(n);}}};var qe=class{constructor(n){a(this,"_plugin");a(this,"_addons",new Set);a(this,"_core");this._plugin=n;}_attachAll(n){this._core=n,this._addons.forEach(e=>{e.attach(this._plugin,n);});}_detachAll(n){this._addons.forEach(e=>{e.detach(this._plugin,n);}),this._core=void 0;}add(n){let e=Array.isArray(n)?n:[n];for(let t of e)this._addons.has(t)||(this._addons.add(t),this._core&&t.attach(this._plugin,this._core));return this._plugin}remove(n){let e=Array.isArray(n)?n:[n];for(let t of e)this._addons.has(t)&&(this._addons.delete(t),this._core&&t.detach(this._plugin,this._core));return this._plugin}list(){return Array.from(this._addons)}has(n){return this._addons.has(n)}clear(){if(this._core){let n=this._core;this._addons.forEach(e=>{e.detach(this._plugin,n);});}this._addons.clear();}};var H=class{constructor(){a(this,"addons");this.addons=new qe(this);}attach(n){this.onAttach(n),this.addons._attachAll(n);}detach(n){this.addons._detachAll(n),this.onDetach(n);}};var Be=class{constructor(n,e=[]){a(this,"_core");a(this,"_items",[]);this._core=n,e.length&&this.addPlugins(e);}addPlugins(n){let e=[];for(let t of n)this._items.includes(t)||(this._items.push(t),t.attach(this._core),e.push(t),this._core.eventBus.emit("plugin:added",t.constructor.name));return e}removePlugins(n){let e=[];for(let t of n){let o=this._items.indexOf(t);o!==-1&&(t.detach(this._core),this._items.splice(o,1),e.push(t),this._core.eventBus.emit("plugin:removed",t.constructor.name));}return e}removeAllPlugins(){let n=[...this._items];for(let e of n)e.detach(this._core);this._items=[];for(let e of n)this._core.eventBus.emit("plugin:removed",e.constructor.name);return n}list(){return [...this._items]}get(n){return this._items.find(e=>e.constructor.name===n)}};var ot=class{constructor(n){a(this,"_stage");a(this,"_eventBus");a(this,"_initialWidth");a(this,"_initialHeight");a(this,"_autoResize");a(this,"_backgroundColor");a(this,"_draggable");a(this,"_minScale");a(this,"_maxScale");a(this,"_gridLayer");a(this,"_resizeObserver",null);a(this,"container");a(this,"nodes");a(this,"camera");a(this,"virtualization");a(this,"plugins");a(this,"_handleResize",()=>{if(!this._autoResize)return;let n=this.container.offsetWidth,e=this.container.offsetHeight;(n!==this._stage.width()||e!==this._stage.height())&&this.setSize({width:n,height:e});});this.container=n.container,this._initialWidth=n.width??800,this._initialHeight=n.height??800,this._autoResize=n.autoResize??true,this._backgroundColor=n.backgroundColor??"#1e1e1e",this._draggable=n.draggable??true,this._minScale=n.minScale??.1,this._maxScale=n.maxScale??500,this._stage=new M.Stage({container:this.container,width:this._autoResize?this.container.offsetWidth:this._initialWidth,height:this._autoResize?this.container.offsetHeight:this._initialHeight,draggable:false}),this._autoResize||(this.container.style.width=`${String(this._initialWidth)}px`,this.container.style.height=`${String(this._initialHeight)}px`),this.container.style.background=this._backgroundColor,this._eventBus=new Ae,this._gridLayer=new M.Layer({listening:false}),this._stage.add(this._gridLayer),this.nodes=new Re(this._stage,this._eventBus),this.camera=new Ee({stage:this._stage,target:this.nodes.world,eventBus:this._eventBus,initialScale:1,draggable:false,minScale:this._minScale,maxScale:this._maxScale}),this.virtualization=new Ze(this._stage,this.nodes.world,this.nodes,n.virtualization),this.plugins=new Be(this),n.plugins?.length&&this.plugins.addPlugins(n.plugins),this._autoResize&&this._setupAutoResize();}_setupAutoResize(){typeof ResizeObserver<"u"?(this._resizeObserver=new ResizeObserver(()=>{this._handleResize();}),this._resizeObserver.observe(this.container)):globalThis.addEventListener("resize",this._handleResize);}destroy(){this._resizeObserver?(this._resizeObserver.disconnect(),this._resizeObserver=null):globalThis.removeEventListener("resize",this._handleResize),this._stage.destroy();}get eventBus(){return this._eventBus}get stage(){return this._stage}get gridLayer(){return this._gridLayer}get draggable(){return this._draggable}get autoResize(){return this._autoResize}get backgroundColor(){return this._backgroundColor}get initialWidth(){return this._initialWidth}get initialHeight(){return this._initialHeight}get minScale(){return this._minScale}get maxScale(){return this._maxScale}setSize({width:n,height:e}){this._stage.size({width:n,height:e}),this._stage.fire("resize"),this._eventBus.emit("stage:resized",{width:n,height:e});}setBackgroundColor(n){this.container.style.background=n;}setDraggable(n){this._stage.draggable(n),this._draggable=n;}setAutoResize(n){this._autoResize!==n&&(this._autoResize=n,n?(this._setupAutoResize(),this._handleResize()):this._resizeObserver?(this._resizeObserver.disconnect(),this._resizeObserver=null):globalThis.removeEventListener("resize",this._handleResize));}};var Me=class{constructor(){a(this,"_actions",[]);a(this,"_currentIndex",-1);}push(n){this._currentIndex<this._actions.length-1&&this.pop(this._currentIndex+1),this._actions.push(n),this._currentIndex=this._actions.length-1,this._debug("push",n);}pop(n){if(n<0||n>this._actions.length)return;let e=this._actions.splice(n);this._currentIndex=Math.min(this._currentIndex,this._actions.length-1),this._debug("pop",{fromIndex:n,removedCount:e.length});}select(n){if(n<-1||n>=this._actions.length)return;let e=this._currentIndex;this._currentIndex=n,this._debug("select",{oldIndex:e,newIndex:n});}getCurrentIndex(){return this._currentIndex}get length(){return this._actions.length}getActions(){return [...this._actions]}canUndo(){return this._currentIndex>=0}canRedo(){return this._currentIndex<this._actions.length-1}undo(){if(!this.canUndo())return this._debug("undo","cannot undo - at beginning"),null;let n=this._actions[this._currentIndex];return this._currentIndex--,this._debug("undo",{action:n,newIndex:this._currentIndex}),n??null}redo(){if(!this.canRedo())return this._debug("redo","cannot redo - at end"),null;this._currentIndex++;let n=this._actions[this._currentIndex];return this._debug("redo",{action:n,newIndex:this._currentIndex}),n??null}clear(){this._actions=[],this._currentIndex=-1,this._debug("clear","history cleared");}getAction(n){return n<0||n>=this._actions.length?null:this._actions[n]??null}_debug(n,e){}};var _e=class{constructor(){a(this,"_scheduled",false);}schedule(n){this._scheduled||(this._scheduled=true,globalThis.requestAnimationFrame(()=>{this._scheduled=false,n();}));}isScheduled(){return this._scheduled}cancel(){this._scheduled=false;}};var $e=class{constructor(n){a(this,"deps");this.deps=n;}ensure(n){this.deps.ensureTempMulti(n);}destroy(){this.deps.destroyTempMulti();}commitToPermanentGroup(){this.deps.commitTempMultiToGroup();}isActive(){return this.deps.isActive()}forceUpdateOverlays(){this.deps.forceUpdate();}onWorldChanged(){this.deps.onWorldChanged?this.deps.onWorldChanged():this.deps.forceUpdate();}isInsideTempByTarget(n){return this.deps.isInsideTempByTarget?this.deps.isInsideTempByTarget(n):false}};function Ne(C){if(C instanceof M.Group){let n=C.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});return {x:n.x,y:n.y,width:n.width,height:n.height}}return {x:0,y:0,width:C.width(),height:C.height()}}function ke(C,n){let{x:e,y:t,width:o,height:i}=n;switch(C){case "top-left":return {x:e+o,y:t+i};case "top-right":return {x:e,y:t+i};case "bottom-right":return {x:e,y:t};case "bottom-left":return {x:e+o,y:t};case "middle-left":return {x:e+o,y:t+i/2};case "middle-right":return {x:e,y:t+i/2};case "top-center":return {x:e+o/2,y:t+i};case "bottom-center":return {x:e+o/2,y:t};default:return null}}function fe(C,n,e,t=6){if(!C||!n||!e)return;let o=e.getClientRect({skipShadow:true,skipStroke:false}),i=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),s=e.getAbsoluteScale(),r=Math.abs(s.x)||1,l=Math.abs(s.y)||1,d=i.width*r,c=i.height*l,h=(()=>{let _=e.getAbsoluteTransform().decompose();return typeof _.rotation=="number"?_.rotation:0})(),u=Math.abs((h%180+180)%180)>.5,p=n.findOne(".top-center"),f=n.findOne(".middle-right"),m=n.findOne(".bottom-center"),v=n.findOne(".middle-left");if(p){let _=u?d:o.width,g=t;p.setAttrs({opacity:0,width:_,height:g,offsetX:_/2,offsetY:0});}if(m){let _=u?d:o.width,g=t;m.setAttrs({opacity:0,width:_,height:g,offsetX:_/2,offsetY:g});}if(v){let _=t,g=u?c:o.height;v.setAttrs({opacity:0,width:_,height:g,offsetX:0,offsetY:g/2});}if(f){let _=t,g=u?c:o.height;f.setAttrs({opacity:0,width:_,height:g,offsetX:_,offsetY:g/2});}}function re(C){return new M.Circle({name:C,radius:4,width:25,height:25,fill:"#ffffff",stroke:"#2b83ff",strokeWidth:1.5,opacity:0,hitStrokeWidth:16,draggable:true,dragOnTop:true,listening:true,cursor:"pointer"})}var Je=class{constructor(n){a(this,"core");a(this,"getKonvaNode");a(this,"getTransformer");a(this,"onUpdate");a(this,"group",null);a(this,"handles",{tl:null,tr:null,br:null,bl:null});a(this,"dragState",null);a(this,"centerAbsStart",null);this.core=n.core,this.getKonvaNode=n.getNode,this.getTransformer=n.getTransformer,n.onUpdate&&(this.onUpdate=n.onUpdate);}attach(){if(!this.getKonvaNode())return;let e=this.core.nodes.layer;this.detach();let t=new M.Group({name:"rotate-handles-group",listening:true});e.add(t),this.group=t;let o=re("rotate-tl"),i=re("rotate-tr"),s=re("rotate-br"),r=re("rotate-bl");t.add(o),t.add(i),t.add(s),t.add(r),this.handles={tl:o,tr:i,br:s,bl:r};let l=d=>{d.on("mouseenter.rotate",()=>{this.core.stage.container().style.cursor="pointer";}),d.on("mouseleave.rotate",()=>{this.core.stage.container().style.cursor="default";}),d.on("dragstart.rotate",()=>{let c=this.getKonvaNode();if(!c)return;let h=c.getAbsoluteTransform().decompose();this.centerAbsStart=this.getNodeCenterAbs(c);let u=this.core.stage.getPointerPosition()??d.getAbsolutePosition(),p=Math.atan2(u.y-this.centerAbsStart.y,u.x-this.centerAbsStart.x)*180/Math.PI;this.dragState={base:h.rotation||0,start:p},this.core.stage.draggable(false),this.core.stage.container().style.cursor="grabbing",this.getTransformer()?.moveToTop(),this.placeBelowTransformer();}),d.on("dragmove.rotate",c=>{let h=this.getKonvaNode();if(!h||!this.dragState)return;let u=this.centerAbsStart??this.getNodeCenterAbs(h),p=this.core.stage.getPointerPosition()??d.getAbsolutePosition(),f=Math.atan2(p.y-u.y,p.x-u.x)*180/Math.PI,m=this.dragState.base+(f-this.dragState.start),v=this.getTransformer();if(c.evt.shiftKey&&v){let g=x=>{let w=x%360;return w<0&&(w+=360),w},b=(x,w)=>g(x-w+180)-180,y=Array.isArray(v.rotationSnaps())?v.rotationSnaps().map(x=>g(x)):void 0,N=typeof v.rotationSnapTolerance=="function"?v.rotationSnapTolerance():5;if(y?.length){let x=g(m),w=m,k=1/0;for(let T of y){let A=Math.abs(b(x,T));A<k&&A<=N&&(w=T,k=A);}k!==1/0&&(m=w);}}if(h.rotation(m),this.centerAbsStart){let g=this.getNodeCenterAbs(h),b=this.centerAbsStart.x-g.x,y=this.centerAbsStart.y-g.y,N=h.getParent();if(N){let x=N.getAbsoluteTransform().copy().invert(),w=x.point({x:g.x,y:g.y}),k=x.point({x:g.x+b,y:g.y+y}),T=h.x()+(k.x-w.x),A=h.y()+(k.y-w.y);h.position({x:T,y:A});}}let _=this.getTransformer();_?.forceUpdate(),_&&fe(this.core,_,h),this.updatePosition(),this.placeBelowTransformer(),this.core.nodes.layer.batchDraw(),this.onUpdate&&this.onUpdate();}),d.on("dragend.rotate",()=>{this.dragState=null,this.centerAbsStart=null,this.core.stage.draggable(false),this.updatePosition(),this.placeBelowTransformer(),this.core.stage.container().style.cursor="pointer",this.onUpdate&&this.onUpdate();});};l(o),l(i),l(s),l(r),this.updatePosition(),this.placeBelowTransformer();}detach(){this.group&&(this.group.destroy(),this.group=null),this.handles={tl:null,tr:null,br:null,bl:null},this.dragState=null,this.centerAbsStart=null;}moveToTop(){this.placeBelowTransformer();}updatePosition(){let n=this.getKonvaNode();if(!n||!this.group)return;let e=n.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),t=e.width,o=e.height;if(t<=0||o<=0)return;let i=n.getAbsoluteTransform().copy(),s=x=>i.point(x),r=12,l=s({x:e.x+t/2,y:e.y+o/2}),d=s({x:e.x,y:e.y}),c=s({x:e.x+t,y:e.y}),h=s({x:e.x+t,y:e.y+o}),u=s({x:e.x,y:e.y+o}),p=x=>{let w=x.x-l.x,k=x.y-l.y,T=Math.hypot(w,k)||1;return {x:w/T,y:k/T}},f=p(d),m=p(c),v=p(h),_=p(u),g={x:d.x+f.x*r,y:d.y+f.y*r},b={x:c.x+m.x*r,y:c.y+m.y*r},y={x:h.x+v.x*r,y:h.y+v.y*r},N={x:u.x+_.x*r,y:u.y+_.y*r};this.handles.tl&&this.handles.tl.absolutePosition(g),this.handles.tr&&this.handles.tr.absolutePosition(b),this.handles.br&&this.handles.br.absolutePosition(y),this.handles.bl&&this.handles.bl.absolutePosition(N),this.placeBelowTransformer();}placeBelowTransformer(){if(!this.group)return;let n=this.getTransformer(),e=this.core.nodes.layer;if(n&&n.getLayer()===e){let t=n.zIndex(),o=this.group.zIndex();if(o>=t){let i=o-t+1;for(let s=0;s<i&&this.group.zIndex()>0;s++)this.group.moveDown();}}else this.group.moveToBottom();}getNodeCenterAbs(n){let e=n.getAbsoluteTransform().copy(),t=n.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),o=t.x+t.width/2,i=t.y+t.height/2;return e.point({x:o,y:i})}};var Qe=class{constructor(n){a(this,"core");a(this,"tr",null);a(this,"sizeLabel",null);a(this,"rotateGroup",null);a(this,"rotateCtrl",null);a(this,"keepRatioPredicate",null);a(this,"boundNode",null);a(this,"hitRect",null);a(this,"transformOppositeCorner",null);a(this,"trWasVisibleBeforeDrag",false);a(this,"labelWasVisibleBeforeDrag",false);a(this,"rotateWasVisibleBeforeDrag",false);a(this,"rotateCtrlWasAttachedBeforeDrag",false);this.core=n;}attach(n,e){this.detach(),this.boundNode=n,this.keepRatioPredicate=e?.keepRatioCornerOnlyShift??null;let t=this.core.nodes.layer,o=new M.Transformer({rotateEnabled:false,keepRatio:false,rotationSnapTolerance:15,rotationSnaps:[0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345,360],enabledAnchors:["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"],borderEnabled:true,borderStroke:"#2b83ff",borderStrokeWidth:1.5,name:"overlay-transformer"});t.add(o),o.nodes([n]),o.boundBoxFunc((r,l)=>{let c=Math.max(1,Math.abs(l.width)),h=Math.max(1,Math.abs(l.height));return {...l,width:c,height:h}}),this.tr=o,fe(this.core,o,n);let i=()=>{let r=typeof o.getActiveAnchor=="function"?o.getActiveAnchor():"",l=r==="top-left"||r==="top-right"||r==="bottom-left"||r==="bottom-right",d=this.keepRatioPredicate?this.keepRatioPredicate():false;o.keepRatio(l&&d);};o.on("transformstart.overlayKeepRatio",()=>{i();let l=(typeof o.getActiveAnchor=="function"?o.getActiveAnchor():"")??"",d=Ne(n),c=ke(l,d);if(!c){this.transformOppositeCorner=null;return}let h=n.getAbsoluteTransform();this.transformOppositeCorner=h.point({x:c.x,y:c.y});}),o.on("transform.overlayKeepRatio",i);let s=()=>{if(this.boundNode){if(this.transformOppositeCorner){let l=(typeof o.getActiveAnchor=="function"?o.getActiveAnchor():"")??"",d=this.boundNode.getAbsoluteTransform(),c=Ne(this.boundNode),h=ke(l,c);if(!h)return;let u=d.point({x:h.x,y:h.y}),p=this.transformOppositeCorner.x-u.x,f=this.transformOppositeCorner.y-u.y,m=this.boundNode.getParent();if(m&&(Math.abs(p)>.01||Math.abs(f)>.01)){let v=m.getAbsoluteTransform().copy().invert(),_=this.boundNode.getAbsolutePosition(),g={x:_.x+p,y:_.y+f},b=v.point(g);this.boundNode.position(b);}}this.tr?.forceUpdate(),fe(this.core,this.tr,this.boundNode),this.rotateCtrl?.updatePosition(),this.tr?.moveToTop(),t.batchDraw();}};o.on("transform.overlayFrameTransform",s),o.on("transformend.overlayFrameTransform",()=>{this.transformOppositeCorner=null,s();}),this.ensureSizeLabel(),this.updateSizeLabel(),this.updateHitRect(),this.rotateCtrl&&(this.rotateCtrl.detach(),this.rotateCtrl=null),this.rotateCtrl=new Je({core:this.core,getNode:()=>this.boundNode,getTransformer:()=>this.tr,onUpdate:()=>{this.forceUpdate(),this.core.nodes.layer.batchDraw();}}),this.rotateCtrl.attach(),this.rotateCtrl.updatePosition(),this.tr.moveToTop(),t.batchDraw();}detach(){this.tr&&(this.tr.off(".overlayKeepRatio"),this.tr.off(".overlayFrameTransform"),this.tr.destroy(),this.tr=null),this.transformOppositeCorner=null,this.sizeLabel&&(this.sizeLabel.destroy(),this.sizeLabel=null),this.hitRect&&(this.hitRect.destroy(),this.hitRect=null),this.rotateGroup&&(this.rotateGroup.destroy(),this.rotateGroup=null),this.rotateCtrl&&(this.rotateCtrl.detach(),this.rotateCtrl=null);}forceUpdate(){this.boundNode&&(this.tr?.forceUpdate(),fe(this.core,this.tr,this.boundNode),this.rotateCtrl?.updatePosition(),this.tr?.moveToTop(),this.updateSizeLabel(),this.updateHitRect());}onWorldChanged(){this.forceUpdate();}hideOverlaysForDrag(){this.tr?(this.trWasVisibleBeforeDrag=this.tr.visible(),this.tr.visible(false)):this.trWasVisibleBeforeDrag=false,this.sizeLabel?(this.labelWasVisibleBeforeDrag=this.sizeLabel.visible(),this.sizeLabel.visible(false)):this.labelWasVisibleBeforeDrag=false,this.rotateGroup?(this.rotateWasVisibleBeforeDrag=this.rotateGroup.visible(),this.rotateGroup.visible(false)):this.rotateWasVisibleBeforeDrag=false,this.rotateCtrl?(this.rotateCtrlWasAttachedBeforeDrag=true,this.rotateCtrl.detach()):this.rotateCtrlWasAttachedBeforeDrag=false;}restoreOverlaysAfterDrag(){this.tr&&this.trWasVisibleBeforeDrag&&this.tr.visible(true),this.sizeLabel&&this.labelWasVisibleBeforeDrag&&this.sizeLabel.visible(true),this.rotateGroup&&this.rotateWasVisibleBeforeDrag&&this.rotateGroup.visible(true),this.rotateCtrl&&this.rotateCtrlWasAttachedBeforeDrag&&(this.rotateCtrl.attach(),this.rotateCtrl.updatePosition(),this.tr?.moveToTop()),this.trWasVisibleBeforeDrag=false,this.labelWasVisibleBeforeDrag=false,this.rotateWasVisibleBeforeDrag=false,this.rotateCtrlWasAttachedBeforeDrag=false,this.forceUpdate();}ensureSizeLabel(){let n=this.core.nodes.layer;this.sizeLabel&&this.sizeLabel.destroy();let e=new M.Label({listening:false,opacity:.95}),t=new M.Tag({fill:"#2b83ff",cornerRadius:4,lineJoin:"round"}),o=new M.Text({text:"",fontFamily:"Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell",fontSize:12,fill:"#ffffff",padding:6,align:"center"});e.add(t),e.add(o),n.add(e),this.sizeLabel=e;}updateSizeLabel(){if(!this.boundNode||!this.sizeLabel)return;let n=this.core.nodes.world,e=this.boundNode.getClientRect({skipShadow:true,skipStroke:true}),t=e.width/Math.max(1e-6,n.scaleX()),o=e.height/Math.max(1e-6,n.scaleY()),i=Math.max(0,Math.round(t)),s=Math.max(0,Math.round(o));this.sizeLabel.getText().text(String(i)+" \xD7 "+String(s));let l=8,d=e.x+e.width/2,c=e.y+e.height+l,u=this.sizeLabel.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width;this.sizeLabel.setAttrs({x:d-u/2,y:c}),this.sizeLabel.moveToTop();}updateHitRect(){if(!this.boundNode)return;let n=this.core.nodes.layer,e=this.boundNode.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),t={x:e.x,y:e.y},o=e.width,i=e.height;if(!this.hitRect){let s=new M.Rect({name:"overlay-hit",x:t.x,y:t.y,width:o,height:i,fill:"rgba(0,0,0,0.001)",listening:true,perfectDrawEnabled:false});s.on("mousedown.overlayHit",r=>{if(r.evt.button!==0)return;r.cancelBubble=true;let l=this.boundNode;typeof l.startDrag=="function"&&l.startDrag();}),this.boundNode instanceof M.Container?(this.boundNode.add(s),s.moveToBottom(),this.hitRect=s,n.batchDraw()):s.destroy();return}this.hitRect.position(t),this.hitRect.size({width:o,height:i}),this.hitRect.moveToBottom();}};var ve=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_selected",null);a(this,"_prevDraggable",null);a(this,"_transformer",null);a(this,"_transformerWasVisibleBeforeDrag",false);a(this,"_cornerHandlesWereVisibleBeforeDrag",false);a(this,"_sizeLabelWasVisibleBeforeDrag",false);a(this,"_rotateHandlesWereVisibleBeforeDrag",false);a(this,"_cornerHandlesGroup",null);a(this,"_cornerHandles",{tl:null,tr:null,br:null,bl:null});a(this,"_cornerHandlesSuppressed",false);a(this,"_transformOppositeCorner",null);a(this,"_sizeLabel",null);a(this,"_radiusLabel",null);a(this,"_rotateHandlesGroup",null);a(this,"_rotateHandles",{tl:null,tr:null,br:null,bl:null});a(this,"_rotateDragState",null);a(this,"_rotateCenterAbsStart",null);a(this,"_prevStageDraggableBeforeRotate",null);a(this,"_worldSyncRafId",null);a(this,"_onCameraZoomEvent",null);a(this,"_hoverTr",null);a(this,"_isPointerDown",false);a(this,"_autoPanRafId",null);a(this,"_autoPanActive",false);a(this,"_autoPanEdgePx");a(this,"_autoPanMaxSpeedPx");a(this,"_draggingNode",null);a(this,"_ratioKeyPressed",false);a(this,"_onGlobalKeyDown",null);a(this,"_onGlobalKeyUp",null);a(this,"_tempMultiSet",new Set);a(this,"_tempMultiNodes",[]);a(this,"_tempMultiInitialTransforms",new Map);a(this,"_tempMultiGroup",null);a(this,"_tempOverlay",null);a(this,"_multiCtrl",null);a(this,"_parentGroupDuringChildEdit",null);a(this,"_parentGroupPrevDraggable",null);a(this,"_dragMoveScheduled",false);a(this,"_batchDrawScheduled",false);a(this,"_hoverThrottle",new pe(16));a(this,"_uiUpdateDebounce",new _e);a(this,"_onMouseDown",e=>{if(!this._core||e.evt.button!==0)return;let t=this._core.stage,o=this._core.nodes.layer;if(e.target===t||e.target.getLayer()!==o){let _=false;if(this._selected){let g=t.getPointerPosition();if(g){let b=this._selected.getKonvaNode(),y=b.getClientRect({skipShadow:true,skipStroke:false});if(g.x>=y.x&&g.x<=y.x+y.width&&g.y>=y.y&&g.y<=y.y+y.height&&(_=true,typeof b.startDrag=="function")){let x=b,w=3,k=e.evt.clientX,T=e.evt.clientY,A=typeof x.draggable=="function"?x.draggable():false,R=t.draggable(),D=false,B=L=>{let ee=Math.abs(L.evt.clientX-k),j=Math.abs(L.evt.clientY-T);!D&&(ee>w||j>w)&&(D=true,typeof x.draggable=="function"&&!A&&x.draggable(true),b.on("dragstart.selection-once-bbox",()=>{t.draggable(false);}),b.on("dragend.selection-once-bbox",()=>{t.draggable(R),typeof x.draggable=="function"&&x.draggable(this._options.dragEnabled?true:A),this._selected&&(this._refreshTransformer(),this._core?.nodes.layer.batchDraw()),b.off(".selection-once-bbox");}),b.startDrag(),e.cancelBubble=true);},K=()=>{!D&&this._options.deselectOnEmptyClick&&this._clearSelection(),t.off("mousemove.selection-once-bbox"),t.off("mouseup.selection-once-bbox");};t.on("mousemove.selection-once-bbox",B),t.on("mouseup.selection-once-bbox",K);}}}_||this._options.deselectOnEmptyClick&&this._clearSelection();return}let i=e.target;if(!this._options.selectablePredicate(i))return;let s=this._findBaseNodeByTarget(i);if(!s)return;if(this._selected){let _=this._selected.getKonvaNode();((b,y)=>{let N=y;for(;N;){if(N===b)return true;N=N.getParent();}return false})(_,i)&&(s=this._selected);}let r=s.getKonvaNode();r instanceof M.Group&&this._disableGroupChildrenDragging(r);let l=3,d=e.evt.clientX,c=e.evt.clientY,h=false,u=_=>{if(h)return;let g=Math.abs(_.evt.clientX-d),b=Math.abs(_.evt.clientY-c);(g>l||b>l)&&(h=true,typeof r.startDrag=="function"&&r.startDrag(),this._core?.stage.off("mousemove.selection-once"),this._core?.stage.off("mouseup.selection-once"));},p=()=>{this._core?.stage.off("mousemove.selection-once"),this._core?.stage.off("mouseup.selection-once");};if(this._core.stage.on("mousemove.selection-once",u),this._core.stage.on("mouseup.selection-once",p),typeof r.isDragging=="function"&&r.isDragging())return;let f=typeof r.draggable=="function",m=f?r.draggable():false,v=t.draggable();f&&r.draggable(true),r.on("dragstart.selection-once",()=>{t.draggable(false);}),r.on("dragend.selection-once",()=>{t.draggable(v),f&&(this._options.dragEnabled?r.draggable(true):r.draggable(m)),this._select(s);});});a(this,"_onHoverMoveThrottled",e=>{this._hoverThrottle.shouldExecute()&&this._onHoverMove(e);});a(this,"_onHoverMove",e=>{if(!this._core)return;let t=this._core.stage,o=this._core.nodes.layer,i=e.target;if((()=>{if(!!!this._tempMultiGroup){let b=i;for(;b;){if(b instanceof M.Group&&typeof b.name=="function"){let y=b.name();if(typeof y=="string"&&(y.includes("temp-multi-group")||y.includes("area-temp-group")))return true}b=b.getParent();}return false}let g=i;for(;g;){if(g===this._tempMultiGroup)return true;g=g.getParent();}return false})()){this._destroyHoverTr();return}let r=typeof e.evt.buttons=="number"?e.evt.buttons:0;if(this._isPointerDown||r&1){this._destroyHoverTr();return}if(i===t||i.getLayer()!==o){this._destroyHoverTr();return}let l=this._core.nodes.list().map(_=>_.getKonvaNode()),d=new Set(l),c=_=>{let g=_;for(;g;){if(d.has(g))return g;g=g.getParent();}return null},u=(_=>{let g=_,b=null;for(;g;)d.has(g)&&g instanceof M.Group&&(b=g),g=g.getParent();return b})(i),p=c(i),f=e.evt.ctrlKey,m=f?p??u:u??p;if(!f&&this._selected&&p&&!(this._selected.getKonvaNode()instanceof M.Group)){let _=this._selected.getKonvaNode();u&&((b,y,N)=>{if(!N)return false;let x=(w,k)=>{let T=k;for(;T;){if(T===w)return true;T=T.getParent();}return false};return x(N,b)&&x(N,y)})(_,p,u)&&_!==p&&(m=p);}if(!m){this._destroyHoverTr();return}if(!this._options.selectablePredicate(m)){this._destroyHoverTr();return}if(this._selected){let _=this._selected.getKonvaNode();if(f?m===_:m===_||((y,N)=>{let x=N;for(;x;){if(x===y)return true;x=x.getParent();}return false})(_,m)){this._destroyHoverTr();return}}let v=this._ensureHoverTr();v.nodes([m]),v.visible(true),v.moveToTop(),o.batchDraw();});a(this,"_onHoverDown",()=>{this._isPointerDown=true,this._destroyHoverTr();});a(this,"_onHoverUp",()=>{this._isPointerDown=false;});a(this,"_onHoverLeave",e=>{this._destroyHoverTr();});a(this,"_onNodeRemoved",e=>{this._selected&&this._selected===e&&this._clearSelection();});let{dragEnabled:t=true,enableTransformer:o=true,deselectOnEmptyClick:i=true,selectablePredicate:s}=e;this._options={dragEnabled:t,enableTransformer:o,deselectOnEmptyClick:i,selectablePredicate:s??(()=>true),autoPanEnabled:e.autoPanEnabled??true,autoPanEdgePx:e.autoPanEdgePx??40,autoPanMaxSpeedPx:e.autoPanMaxSpeedPx??24},this._autoPanEdgePx=this._options.autoPanEdgePx,this._autoPanMaxSpeedPx=this._options.autoPanMaxSpeedPx;}getMultiGroupController(){if(!this._core)throw new Error("Core is not attached");return this._multiCtrl??(this._multiCtrl=new $e({ensureTempMulti:e=>{this._ensureTempMulti(e);},destroyTempMulti:()=>{this._destroyTempMulti();},commitTempMultiToGroup:()=>{this._commitTempMultiToGroup();},isActive:()=>!!this._tempMultiGroup||this._tempMultiSet.size>0,forceUpdate:()=>{this._tempOverlay?.forceUpdate();},onWorldChanged:()=>{this._tempOverlay?.onWorldChanged();},isInsideTempByTarget:e=>this._tempMultiGroup?e===this._tempMultiGroup?true:e.isAncestorOf(this._tempMultiGroup)||this._tempMultiGroup.isAncestorOf(e):false})),this._multiCtrl}_startAutoPanLoop(){if(!this._core||this._autoPanRafId!=null)return;this._autoPanActive=true;let e=this._core.nodes.world,t=this._core.stage,o=()=>{if(this._autoPanRafId=null,!this._core||!this._autoPanActive)return;let i=t.getPointerPosition();if(i){let s=t.width(),r=t.height(),l=this._autoPanEdgePx,d=0,c=0,h=Math.max(0,l-i.x),u=Math.max(0,i.x-(s-l)),p=Math.max(0,l-i.y),f=Math.max(0,i.y-(r-l)),m=v=>Math.min(1,v/l);if(d=this._autoPanMaxSpeedPx*(m(u)-m(h)),c=this._autoPanMaxSpeedPx*(m(f)-m(p)),d!==0||c!==0){if(e.x(e.x()-d),e.y(e.y()-c),this._draggingNode&&typeof this._draggingNode.setAbsolutePosition=="function"){let v=this._draggingNode.getAbsolutePosition();this._draggingNode.setAbsolutePosition({x:v.x+d,y:v.y+c}),this._transformer?.forceUpdate();}this._core.nodes.layer.batchDraw();}}this._autoPanRafId=globalThis.requestAnimationFrame(o);};this._autoPanRafId=globalThis.requestAnimationFrame(o);}_stopAutoPanLoop(){this._autoPanActive=false,this._autoPanRafId!=null&&(globalThis.cancelAnimationFrame(this._autoPanRafId),this._autoPanRafId=null);}_scheduleBatchDraw(){if(this._batchDrawScheduled)return;this._batchDrawScheduled=true;let e=globalThis.requestAnimationFrame;e(()=>{this._batchDrawScheduled=false,this._core?.stage.batchDraw();});}setOptions(e){this._options={...this._options,...e},this._core&&this._refreshTransformer(),typeof e.autoPanEdgePx=="number"&&(this._autoPanEdgePx=e.autoPanEdgePx),typeof e.autoPanMaxSpeedPx=="number"&&(this._autoPanMaxSpeedPx=e.autoPanMaxSpeedPx),e.autoPanEnabled===false&&this._stopAutoPanLoop();}onAttach(e){this._core=e;let t=e.stage;t.on("mousedown.selection",this._onMouseDown),t.on("click.selection",r=>{if(!this._core)return;let l=this._core.stage,d=this._core.nodes.layer;if(r.evt.button!==0)return;if(r.target===l||r.target.getLayer()!==d){if(!!l.getAttr("_skipSelectionEmptyClickOnce")){l.setAttr("_skipSelectionEmptyClickOnce",false),r.cancelBubble=true;return}this._options.deselectOnEmptyClick&&(this._destroyTempMulti(),this._clearSelection());return}let c=r.target;if(!this._options.selectablePredicate(c))return;if(r.evt.shiftKey||r.evt.ctrlKey||r.evt.metaKey){let u=this._findBaseNodeByTarget(c);if(!u)return;let f=u.getKonvaNode().getParent();if(f&&f instanceof M.Group&&f!==this._core.nodes.world)return;if(this._tempMultiSet.size===0&&this._selected&&this._selected!==u&&(this._tempMultiSet.add(this._selected),this._transformer&&(this._transformer.destroy(),this._transformer=null),this._destroyCornerRadiusHandles(),this._destroyRotateHandles(),this._destroySizeLabel(),this._selected=null),Array.from(this._tempMultiSet).includes(u)?this._tempMultiSet.delete(u):this._tempMultiSet.add(u),this._tempMultiSet.size===0){this._destroyTempMulti(),this._clearSelection();return}if(this._tempMultiSet.size===1){let v=this._tempMultiSet.values().next(),_=v.done?void 0:v.value;_&&(this._destroyTempMulti(),this._select(_),this._scheduleBatchDraw());return}this._ensureTempMulti(Array.from(this._tempMultiSet)),this._scheduleBatchDraw();return}let h=this._findBaseNodeByTarget(c);h&&(this._destroyTempMulti(),this._select(h),this._scheduleBatchDraw());}),t.on("dblclick.selection",r=>{if(!this._core)return;let l=this._core.nodes.layer;if(r.target===t||r.target.getLayer()!==l||r.evt.button!==0||!this._selected)return;let d=this._selected.getKonvaNode();if(d instanceof M.Group&&typeof d.isAncestorOf=="function"&&d.isAncestorOf(r.target)){r.cancelBubble=true;let c=null;for(let h of this._core.nodes.list()){let u=h.getKonvaNode();if(typeof d.isAncestorOf=="function"&&d.isAncestorOf(u)&&u!==d&&typeof u.isAncestorOf=="function"&&u.isAncestorOf(r.target)){let p=true;for(let f of this._core.nodes.list()){if(f===h)continue;let m=f.getKonvaNode();if(typeof d.isAncestorOf=="function"&&d.isAncestorOf(m)&&typeof u.isAncestorOf=="function"&&u.isAncestorOf(m)&&typeof m.isAncestorOf=="function"&&m.isAncestorOf(r.target)){p=false;break}}if(p){c=h;break}}}if(c??(c=this._core.nodes.list().find(h=>h.getKonvaNode()===r.target)??null),c){this._select(c);let h=c.getKonvaNode();typeof h.draggable=="function"&&h.draggable(true),d instanceof M.Group&&(this._parentGroupDuringChildEdit=d,this._parentGroupPrevDraggable=typeof d.draggable=="function"?d.draggable():null,typeof d.draggable=="function"&&d.draggable(false)),this._core.stage.batchDraw();}}}),e.eventBus.on("node:removed",this._onNodeRemoved),t.on("mousemove.hover",this._onHoverMoveThrottled),t.on("mouseleave.hover",this._onHoverLeave),t.on("mousedown.hover",this._onHoverDown),t.on("mouseup.hover",this._onHoverUp),t.on("touchstart.hover",this._onHoverDown),t.on("touchend.hover",this._onHoverUp),this._core.nodes.layer.on("dragstart.hover",()=>{this._destroyHoverTr();}),this._core.nodes.layer.on("dragmove.hover",()=>{this._destroyHoverTr();});let o=this._core.nodes.layer;o.on("dragstart.selectionAutoPan",r=>{if(!this._options.autoPanEnabled)return;let l=r.target;this._options.selectablePredicate(l)&&(this._draggingNode=l,this._startAutoPanLoop());}),o.on("dragend.selectionAutoPan",()=>{this._draggingNode=null,this._stopAutoPanLoop();});let i=this._core.nodes.world,s=()=>{this._core&&this._worldSyncRafId==null&&(this._worldSyncRafId=globalThis.requestAnimationFrame(()=>{this._worldSyncRafId=null,this._core&&((this._transformer||this._cornerHandlesGroup||this._rotateHandlesGroup||this._sizeLabel||this._tempMultiGroup)&&(this._transformer?.forceUpdate(),this._hoverTr?.forceUpdate(),this._restyleSideAnchors(),this._updateCornerRadiusHandlesPosition(),this._updateRotateHandlesPosition(),this._updateSizeLabel(),this._updateCornerRadiusHandlesVisibility(),this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw()),this._destroyHoverTr());}));};i.on("xChange.selectionCamera yChange.selectionCamera scaleXChange.selectionCamera scaleYChange.selectionCamera",s),this._onCameraZoomEvent=()=>{s();},e.eventBus.on("camera:zoom",this._onCameraZoomEvent),e.eventBus.on("camera:setZoom",this._onCameraZoomEvent),e.eventBus.on("camera:reset",this._onCameraZoomEvent),this._onGlobalKeyDown=r=>{r.key==="Shift"&&(this._ratioKeyPressed=true);let l=r.ctrlKey||r.metaKey;l&&!r.shiftKey&&r.code==="KeyG"&&(r.preventDefault(),this._commitTempMultiToGroup()),l&&r.shiftKey&&r.code==="KeyG"&&(r.preventDefault(),this._tryUngroupSelectedGroup());},this._onGlobalKeyUp=r=>{r.key==="Shift"&&(this._ratioKeyPressed=false);},globalThis.addEventListener("keydown",this._onGlobalKeyDown),globalThis.addEventListener("keyup",this._onGlobalKeyUp);}onDetach(e){this._destroyTempMulti(),this._clearSelection(),e.stage.off(".selection"),e.stage.off(".hover"),this._core?.nodes.layer.off(".hover"),this._core?.nodes.world.off(".selectionCamera"),this._core?.nodes.layer.off(".selectionAutoPan"),this._worldSyncRafId!=null&&(globalThis.cancelAnimationFrame(this._worldSyncRafId),this._worldSyncRafId=null),this._onCameraZoomEvent&&(e.eventBus.off("camera:zoom",this._onCameraZoomEvent),e.eventBus.off("camera:setZoom",this._onCameraZoomEvent),e.eventBus.off("camera:reset",this._onCameraZoomEvent),this._onCameraZoomEvent=null),e.eventBus.off("node:removed",this._onNodeRemoved),this._destroyHoverTr(),this._onGlobalKeyDown&&globalThis.removeEventListener("keydown",this._onGlobalKeyDown),this._onGlobalKeyUp&&globalThis.removeEventListener("keyup",this._onGlobalKeyUp),this._onGlobalKeyDown=null,this._onGlobalKeyUp=null;}_select(e){if(!this._core)return;let t=this._core;this._clearSelection();let o=e.getKonvaNode();this._prevDraggable=o.draggable(),this._options.dragEnabled&&typeof o.draggable=="function"&&o.draggable(true),o instanceof M.Group&&this._disableGroupChildrenDragging(o),this._selected=e,this._refreshTransformer(),t.eventBus.emit("node:selected",e),o.on("dragstart.selection",()=>{this._draggingNode=o,this._transformer&&(this._transformerWasVisibleBeforeDrag=this._transformer.visible(),this._transformer.visible(false)),this._cornerHandlesGroup&&(this._cornerHandlesWereVisibleBeforeDrag=this._cornerHandlesGroup.visible(),this._cornerHandlesGroup.visible(false)),this._rotateHandlesGroup&&(this._rotateHandlesWereVisibleBeforeDrag=this._rotateHandlesGroup.visible(),this._rotateHandlesGroup.visible(false)),this._sizeLabel&&(this._sizeLabelWasVisibleBeforeDrag=this._sizeLabel.visible(),this._sizeLabel.visible(false)),this._core?.stage.batchDraw(),this._startAutoPanLoop();}),o.on("dragmove.selection",()=>{if(this._dragMoveScheduled)return;this._dragMoveScheduled=true;let i=globalThis.requestAnimationFrame;i(()=>{this._dragMoveScheduled=false,this._scheduleBatchDraw();});}),o.on("dragend.selection",()=>{let i={};typeof o.x=="function"&&(i.x=o.x()),typeof o.y=="function"&&(i.y=o.y()),typeof o.width=="function"&&(i.width=o.width()),typeof o.height=="function"&&(i.height=o.height()),typeof o.rotation=="function"&&(i.rotation=o.rotation()),typeof o.scaleX=="function"&&(i.scaleX=o.scaleX()),typeof o.scaleY=="function"&&(i.scaleY=o.scaleY()),t.eventBus.emit("node:transformed",e,i);}),o.on("transformend.selection",()=>{let i={};typeof o.x=="function"&&(i.x=o.x()),typeof o.y=="function"&&(i.y=o.y()),typeof o.width=="function"&&(i.width=o.width()),typeof o.height=="function"&&(i.height=o.height()),typeof o.rotation=="function"&&(i.rotation=o.rotation()),typeof o.scaleX=="function"&&(i.scaleX=o.scaleX()),typeof o.scaleY=="function"&&(i.scaleY=o.scaleY()),this._core?.eventBus.emit("node:transformed",e,i);}),o.on("dragend.selection",()=>{this._draggingNode=null,this._transformer&&(this._transformerWasVisibleBeforeDrag&&this._transformer.visible(true),this._transformerWasVisibleBeforeDrag=false),this._cornerHandlesGroup&&(this._cornerHandlesWereVisibleBeforeDrag&&this._cornerHandlesGroup.visible(true),this._cornerHandlesWereVisibleBeforeDrag=false),this._rotateHandlesGroup&&(this._rotateHandlesWereVisibleBeforeDrag&&this._rotateHandlesGroup.visible(true),this._rotateHandlesWereVisibleBeforeDrag=false),this._sizeLabel&&(this._sizeLabelWasVisibleBeforeDrag&&this._sizeLabel.visible(true),this._sizeLabelWasVisibleBeforeDrag=false),this._stopAutoPanLoop(),this._select(e),this._core?.stage.batchDraw();}),o.on("mousedown.selection",i=>{let s=i.evt.button;(s===1||s===2)&&typeof o.draggable=="function"&&o.draggable(false);});}_clearSelection(){if(!this._selected)return;let e=this._selected,t=this._selected.getKonvaNode();if(typeof t.draggable=="function"&&this._prevDraggable!==null&&t.draggable(this._prevDraggable),this._prevDraggable=null,this._parentGroupDuringChildEdit){let o=this._parentGroupDuringChildEdit;typeof o.draggable=="function"&&this._parentGroupPrevDraggable!==null&&o.draggable(this._parentGroupPrevDraggable),this._parentGroupDuringChildEdit=null,this._parentGroupPrevDraggable=null;}t.off(".selection"),t.off(".selection-once"),this._destroyCornerRadiusHandles(),this._destroyRotateHandles(),this._destroySizeLabel(),this._transformer&&(this._transformer.destroy(),this._transformer=null),this._selected=null,this._core&&(this._core.eventBus.emit("node:deselected",e),this._core.eventBus.emit("selection:cleared")),this._core?.stage.batchDraw();}_applyOverlayTransformToNodes(e,t){if(!this._core)return;let o=e.getAbsoluteTransform().copy(),i=t.copy();i.invert();let s=o.multiply(i);for(let r of this._tempMultiNodes){let l=this._tempMultiInitialTransforms.get(r);if(!l)continue;let d=s.copy().multiply(l),c=r.getParent();if(!c)continue;let h=c.getAbsoluteTransform().copy();h.invert();let p=h.multiply(d).decompose();typeof r.position=="function"&&r.position({x:p.x,y:p.y}),typeof r.rotation=="function"&&r.rotation(p.rotation),typeof r.scale=="function"&&r.scale({x:p.scaleX,y:p.scaleY});}}_updateTempMultiOverlayBBox(){if(!this._core||!this._tempMultiGroup)return;let e=this._computeUnionBBox(Array.from(this._tempMultiSet));if(!e)return;this._tempMultiGroup.position({x:e.x,y:e.y});let t=this._tempMultiGroup.findOne(".temp-multi-overlay-rect");t&&t.size({width:e.width,height:e.height});}_computeUnionBBox(e){if(e.length===0||!this._core)return null;let t=this._core.nodes.world,o=1/0,i=1/0,s=-1/0,r=-1/0;for(let l of e){let c=l.getKonvaNode().getClientRect({skipShadow:true,skipStroke:false}),h=t.getAbsoluteTransform().copy().invert(),u=[h.point({x:c.x,y:c.y}),h.point({x:c.x+c.width,y:c.y}),h.point({x:c.x+c.width,y:c.y+c.height}),h.point({x:c.x,y:c.y+c.height})];for(let p of u)o=Math.min(o,p.x),i=Math.min(i,p.y),s=Math.max(s,p.x),r=Math.max(r,p.y);}return !isFinite(o)||!isFinite(i)||!isFinite(s)||!isFinite(r)?null:{x:o,y:i,width:s-o,height:r-i}}_ensureTempMulti(e){if(!this._core)return;let t=this._core.nodes.world,o=this._core.nodes.layer;this._tempMultiSet.clear();for(let u of e)this._tempMultiSet.add(u);let i=e.map(u=>u.getKonvaNode());if(this._tempMultiGroup&&this._tempMultiNodes.length>0){if(this._tempMultiNodes.length===i.length&&i.every(p=>this._tempMultiNodes.includes(p)))return;this._destroyTempMulti();}let s=this._computeUnionBBox(e);if(!s)return;this._tempMultiNodes=i;let r=new M.Group({name:"temp-multi-overlay",x:s.x,y:s.y});t.add(r),this._tempMultiGroup=r;let l=new M.Rect({x:0,y:0,width:s.width,height:s.height,fill:"rgba(0,0,0,0.001)",listening:false,name:"temp-multi-overlay-rect"});r.add(l),this._tempOverlay??(this._tempOverlay=new Qe(this._core)),this._tempOverlay.attach(r,{keepRatioCornerOnlyShift:()=>this._ratioKeyPressed});let d=this._core.stage,c=d.draggable();r.draggable(true);let h=null;r.on("dragstart.tempMulti",()=>{this._tempMultiInitialTransforms.clear();for(let u of this._tempMultiNodes)this._tempMultiInitialTransforms.set(u,u.getAbsoluteTransform().copy());h=r.getAbsoluteTransform().copy(),d.draggable(false),this._draggingNode=r,this._startAutoPanLoop(),this._tempOverlay?.hideOverlaysForDrag();}),r.on("dragmove.tempMulti",()=>{h&&(this._applyOverlayTransformToNodes(r,h),this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw());}),r.on("dragend.tempMulti",()=>{if(d.draggable(c),this._draggingNode=null,this._stopAutoPanLoop(),this._tempOverlay?.restoreOverlaysAfterDrag(),this._core){let p=this._core.nodes.world.getAbsoluteTransform().copy().invert();for(let f of this._tempMultiSet){let v=f.getKonvaNode().getAbsoluteTransform().copy(),g=p.copy().multiply(v).decompose();this._core.eventBus.emit("node:transformed",f,{x:g.x,y:g.y,rotation:g.rotation,scaleX:g.scaleX,scaleY:g.scaleY});}}this._updateTempMultiOverlayBBox(),h=null,this._tempMultiInitialTransforms.clear(),this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw();}),r.on("transformstart.tempMulti",()=>{this._tempMultiInitialTransforms.clear();for(let u of this._tempMultiNodes)this._tempMultiInitialTransforms.set(u,u.getAbsoluteTransform().copy());h=r.getAbsoluteTransform().copy();}),r.on("transform.tempMulti",()=>{h&&(this._applyOverlayTransformToNodes(r,h),this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw());}),r.on("transformend.tempMulti",()=>{if(this._core){let p=this._core.nodes.world.getAbsoluteTransform().copy().invert();for(let f of this._tempMultiSet){let v=f.getKonvaNode().getAbsoluteTransform().copy(),g=p.copy().multiply(v).decompose();this._core.eventBus.emit("node:transformed",f,{x:g.x,y:g.y,rotation:g.rotation,scaleX:g.scaleX,scaleY:g.scaleY});}}this._updateTempMultiOverlayBBox(),h=null,this._tempMultiInitialTransforms.clear(),this._tempOverlay?.forceUpdate(),this._scheduleBatchDraw();}),o.batchDraw(),this._core.eventBus.emit("selection:multi:created",e);}_destroyTempMulti(){this._core&&(!this._tempMultiGroup&&this._tempMultiSet.size===0||(this._tempOverlay&&(this._tempOverlay.detach(),this._tempOverlay=null),this._tempMultiGroup&&(this._tempMultiGroup.off(".tempMulti"),this._tempMultiGroup.destroy(),this._tempMultiGroup=null),this._tempMultiNodes=[],this._tempMultiInitialTransforms.clear(),this._tempMultiSet.clear(),this._core.nodes.layer.batchDraw(),this._core.eventBus.emit("selection:multi:destroyed")));}_commitTempMultiToGroup(){if(!this._core||!this._tempMultiGroup||this._tempMultiSet.size<2)return;let e=this._core.nodes,t=this._computeUnionBBox(Array.from(this._tempMultiSet));if(!t)return;let o=e.addGroup({x:t.x,y:t.y,draggable:true}),i=o.getKonvaNode(),s=[],r=[...this._tempMultiNodes].sort((u,p)=>u.zIndex()-p.zIndex()),l=Math.max(...r.map(u=>u.zIndex()));for(let u of r){let p=u.getAbsolutePosition();i.add(u),u.setAbsolutePosition(p),typeof u.draggable=="function"&&u.draggable(false);let f=this._core.nodes.list().find(m=>m.getKonvaNode()===u);f&&s.push(f);}let d=this._core.nodes.world,c=i.zIndex(),h=l;if(c<h){let u=h-c;for(let p=0;p<u&&i.zIndex()<d.children.length-1;p++)i.moveUp();}this._tempOverlay&&(this._tempOverlay.detach(),this._tempOverlay=null),this._tempMultiGroup.off(".tempMulti"),this._tempMultiGroup.destroy(),this._tempMultiGroup=null,this._tempMultiNodes=[],this._tempMultiSet.clear(),typeof i.draggable=="function"&&i.draggable(true),this._core.eventBus.emit("group:created",o,s),this._select(o),this._core.stage.batchDraw();}_tryUngroupSelectedGroup(){if(!this._core||!this._selected)return;let e=this._selected.getKonvaNode();if(!(e instanceof M.Group))return;let t=[...e.getChildren()],o=this._core.nodes.world,i=[];for(let r of t){let l=r.getAbsoluteTransform().copy();o.add(r);let d=o.getAbsoluteTransform().copy();d.invert();let h=d.multiply(l).decompose();typeof r.position=="function"?r.position({x:h.x,y:h.y}):r.setAbsolutePosition({x:h.x,y:h.y}),typeof r.rotation=="function"&&r.rotation(h.rotation),typeof r.scale=="function"&&r.scale({x:h.scaleX,y:h.scaleY}),typeof r.draggable=="function"&&r.draggable(true);for(let u of this._core.nodes.list())if(u.getKonvaNode()===r){i.push(u);break}}let s=this._selected;this._selected=null,this._transformer?.destroy(),this._transformer=null,this._destroySizeLabel(),this._core.eventBus.emit("group:ungrouped",s,i),this._core.nodes.remove(s),this._core.stage.batchDraw();}_ensureHoverTr(){if(!this._core)throw new Error("Core is not attached");if(this._hoverTr?.getParent())return this._hoverTr;let e=new M.Transformer({rotateEnabled:false,enabledAnchors:[],rotationSnaps:[0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345,360],borderEnabled:true,borderStroke:"#2b83ff",borderStrokeWidth:1.5,listening:false,name:"hover-transformer"});return this._core.nodes.layer.add(e),this._hoverTr=e,e}_destroyHoverTr(){this._hoverTr&&(this._hoverTr.destroy(),this._hoverTr=null);}_refreshTransformer(){if(!this._core||(this._transformer&&(this._transformer.destroy(),this._transformer=null),!this._options.enableTransformer||!this._selected))return;let e=this._core.nodes.layer,t=new M.Transformer({rotateEnabled:false,rotationSnapTolerance:15,flipEnabled:false,keepRatio:false,rotationSnaps:[0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345,360],enabledAnchors:["top-left","top-center","top-right","middle-right","bottom-right","bottom-center","bottom-left","middle-left"]});e.add(t),t.nodes([this._selected.getKonvaNode()]),t.boundBoxFunc((r,l)=>{let c=l.width,h=l.height,u=l.x,p=l.y;return (c<0||c<1)&&(c=1),(h<0||h<1)&&(h=1),{...l,x:u,y:p,width:c,height:h}}),this._transformer=t,this._restyleSideAnchors(),this._setupCornerRadiusHandles(false),this._setupRotateHandles(),this._setupSizeLabel();let o=()=>{let r=typeof t.getActiveAnchor=="function"?t.getActiveAnchor():"",l=r==="top-left"||r==="top-right"||r==="bottom-left"||r==="bottom-right";t.keepRatio(l&&this._ratioKeyPressed);};t.on("transformstart.keepratio",()=>{o(),this._cornerHandlesSuppressed=true,this._cornerHandlesGroup?.visible(false),this._hideRadiusLabel();let r=this._selected?.getKonvaNode(),d=(typeof t.getActiveAnchor=="function"?t.getActiveAnchor():"")??"";if(!r){this._transformOppositeCorner=null;return}let c=Ne(r),h=ke(d,c);if(!h){this._transformOppositeCorner=null;return}let u=r.getAbsoluteTransform();this._transformOppositeCorner=u.point({x:h.x,y:h.y});}),t.on("transform.keepratio",o),t.on("transform.corner-sync",()=>{let r=this._selected?.getKonvaNode();if(r&&(this._bakeRectScale(r),this._transformOppositeCorner)){let d=(typeof t.getActiveAnchor=="function"?t.getActiveAnchor():"")??"",c=r.getAbsoluteTransform(),h=Ne(r),u=ke(d,h);if(!u)return;let p=c.point({x:u.x,y:u.y}),f=this._transformOppositeCorner.x-p.x,m=this._transformOppositeCorner.y-p.y,v=r.getParent();if(v&&(Math.abs(f)>.01||Math.abs(m)>.01)){let _=v.getAbsoluteTransform().copy().invert(),g=r.getAbsolutePosition(),b={x:g.x+f,y:g.y+m},y=_.point(b);r.position(y);}}this._restyleSideAnchors(),this._scheduleUIUpdate(),this._core?.nodes.layer.batchDraw();}),t.on("transformend.corner-sync",()=>{this._cornerHandlesSuppressed=false,this._transformOppositeCorner=null,this._restyleSideAnchors(),this._scheduleUIUpdate(),this._core?.nodes.layer.batchDraw();});let i=this._selected.getKonvaNode();i.off(".overlay-sync");let s=()=>{this._restyleSideAnchors(),this._scheduleUIUpdate(),this._scheduleBatchDraw();};i.on("widthChange.overlay-sync heightChange.overlay-sync scaleXChange.overlay-sync scaleYChange.overlay-sync rotationChange.overlay-sync xChange.overlay-sync yChange.overlay-sync",s),this._scheduleBatchDraw();}_restyleSideAnchors(){if(!this._core||!this._selected||!this._transformer)return;let e=this._selected.getKonvaNode();fe(this._core,this._transformer,e);}_setupRotateHandles(){if(!this._core||!this._selected)return;let e=this._core.nodes.layer;this._destroyRotateHandles();let t=new M.Group({name:"rotate-handles-group",listening:true});e.add(t),t.moveToTop(),this._rotateHandlesGroup=t;let o=re("rotate-tl"),i=re("rotate-tr"),s=re("rotate-br"),r=re("rotate-bl");t.add(o),t.add(i),t.add(s),t.add(r),this._rotateHandles={tl:o,tr:i,br:s,bl:r};let l=c=>{c.on("dragstart.rotate",()=>{if(!this._selected)return;let h=this._selected.getKonvaNode(),u=h.getAbsoluteTransform().decompose(),p=this._getNodeCenterAbs(h);this._rotateCenterAbsStart=p;let f=this._core?.stage.getPointerPosition()??c.getAbsolutePosition(),m=Math.atan2(f.y-p.y,f.x-p.x)*180/Math.PI;this._rotateDragState={base:u.rotation||0,start:m},this._core&&(this._prevStageDraggableBeforeRotate=this._core.stage.draggable()),typeof h.draggable=="function"&&h.draggable(false),this._core?.stage.draggable(false),this._core&&(this._core.stage.container().style.cursor="grabbing");}),c.on("dragmove.rotate",h=>{if(!this._core||!this._selected||!this._rotateDragState)return;let u=this._selected.getKonvaNode(),p=this._rotateCenterAbsStart??this._getNodeCenterAbs(u),f=this._core.stage.getPointerPosition()??c.getAbsolutePosition(),m=Math.atan2(f.y-p.y,f.x-p.x)*180/Math.PI,v=this._rotateDragState.base+(m-this._rotateDragState.start),_=b=>{let y=b%360;return y<0&&(y+=360),y},g=(b,y)=>_(b-y+180)-180;if(h.evt.shiftKey){let b=this._transformer,y,N=5;if(b){let x=b.rotationSnaps();Array.isArray(x)&&(y=x.map(k=>_(k)));let w=b.rotationSnapTolerance();typeof w=="number"&&(N=w);}if(y?.length){let x=_(v),w=v,k=1/0;for(let T of y){let A=Math.abs(g(x,T));A<k&&A<=N&&(w=T,k=A);}k!==1/0&&(v=w);}}if(u.rotation(v),this._rotateCenterAbsStart){let b=this._getNodeCenterAbs(u),y=this._rotateCenterAbsStart.x-b.x,N=this._rotateCenterAbsStart.y-b.y,x=u.getParent();if(x){let w=x.getAbsoluteTransform().copy().invert(),k=w.point({x:b.x,y:b.y}),T=w.point({x:b.x+y,y:b.y+N}),A=u.x()+(T.x-k.x),R=u.y()+(T.y-k.y);typeof u.position=="function"&&u.position({x:A,y:R});}}this._transformer?.forceUpdate(),this._restyleSideAnchors(),this._core.nodes.layer.batchDraw(),this._scheduleUIUpdate();}),c.on("dragend.rotate",()=>{if(this._rotateDragState=null,this._rotateCenterAbsStart=null,this._selected){let h=this._selected.getKonvaNode();this._options.dragEnabled&&typeof h.draggable=="function"&&h.draggable(true);let u={x:h.x(),y:h.y(),rotation:h.rotation()};this._core?.eventBus.emit("node:transformed",this._selected,u);}this._core&&this._prevStageDraggableBeforeRotate!==null&&(this._core.stage.draggable(this._prevStageDraggableBeforeRotate),this._prevStageDraggableBeforeRotate=null),this._restyleSideAnchors(),this._scheduleUIUpdate(),this._core?.nodes.layer.batchDraw(),this._core&&(this._core.stage.container().style.cursor="grab");});};l(o),l(i),l(s),l(r);let d=c=>{this._core&&(this._core.stage.container().style.cursor=c);};this._rotateHandles.tl&&(this._rotateHandles.tl.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.tl.on("mouseleave.rotate-cursor",()=>{d("default");})),this._rotateHandles.tr&&(this._rotateHandles.tr.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.tr.on("mouseleave.rotate-cursor",()=>{d("default");})),this._rotateHandles.br&&(this._rotateHandles.br.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.br.on("mouseleave.rotate-cursor",()=>{d("default");})),this._rotateHandles.bl&&(this._rotateHandles.bl.on("mouseenter.rotate-cursor",()=>{d("pointer");}),this._rotateHandles.bl.on("mouseleave.rotate-cursor",()=>{d("default");})),this._updateRotateHandlesPosition();}_destroyRotateHandles(){this._rotateHandlesGroup&&(this._rotateHandlesGroup.destroy(),this._rotateHandlesGroup=null),this._rotateHandles={tl:null,tr:null,br:null,bl:null},this._rotateDragState=null;}_getNodeCenterAbs(e){let t=e.getAbsoluteTransform().copy(),o=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false});return t.point({x:o.x+o.width/2,y:o.y+o.height/2})}_updateRotateHandlesPosition(){if(!this._core||!this._selected||!this._rotateHandlesGroup)return;let e=this._selected.getKonvaNode(),t=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:false}),o=t.width,i=t.height;if(o<=0||i<=0)return;let s=e.getAbsoluteTransform().copy(),r=k=>s.point(k),l=12,d=r({x:t.x+o/2,y:t.y+i/2}),c=r({x:t.x,y:t.y}),h=r({x:t.x+o,y:t.y}),u=r({x:t.x+o,y:t.y+i}),p=r({x:t.x,y:t.y+i}),f=k=>{let T=k.x-d.x,A=k.y-d.y,R=Math.hypot(T,A)||1;return {x:T/R,y:A/R}},m=f(c),v=f(h),_=f(u),g=f(p),b={x:c.x+m.x*l,y:c.y+m.y*l},y={x:h.x+v.x*l,y:h.y+v.y*l},N={x:u.x+_.x*l,y:u.y+_.y*l},x={x:p.x+g.x*l,y:p.y+g.y*l};this._rotateHandles.tl&&this._rotateHandles.tl.absolutePosition(b),this._rotateHandles.tr&&this._rotateHandles.tr.absolutePosition(y),this._rotateHandles.br&&this._rotateHandles.br.absolutePosition(N),this._rotateHandles.bl&&this._rotateHandles.bl.absolutePosition(x);let w=this._rotateHandlesGroup.getParent();if(w){let k=w.getAbsoluteTransform().decompose(),T=1/(Math.abs(k.scaleX)||1),A=1/(Math.abs(k.scaleY)||1);this._rotateHandles.tl&&this._rotateHandles.tl.scale({x:T,y:A}),this._rotateHandles.tr&&this._rotateHandles.tr.scale({x:T,y:A}),this._rotateHandles.br&&this._rotateHandles.br.scale({x:T,y:A}),this._rotateHandles.bl&&this._rotateHandles.bl.scale({x:T,y:A});}this._rotateHandlesGroup.moveToTop();}_setupSizeLabel(){if(!this._core||!this._selected)return;let e=this._core.nodes.layer;this._destroySizeLabel();let t=new M.Label({listening:false,opacity:.95}),o=new M.Tag({fill:"#2b83ff",cornerRadius:4,shadowColor:"#000",shadowBlur:6,shadowOpacity:.25}),i=new M.Text({text:"",fontFamily:"Inter, Calibri, Arial, sans-serif",fontSize:12,padding:4,fill:"#ffffff"});t.add(o),t.add(i),e.add(t),this._sizeLabel=t,this._updateSizeLabel();}_scheduleUIUpdate(){this._uiUpdateDebounce.schedule(()=>{this._updateSizeLabel(),this._updateRotateHandlesPosition(),this._updateCornerRadiusHandlesPosition();});}_updateSizeLabel(){if(!this._core||!this._selected||!this._sizeLabel)return;let e=this._selected.getKonvaNode(),t=e.getClientRect({skipShadow:true,skipStroke:false}),o=e.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),i=e.getAbsoluteTransform().decompose(),s=this._core.nodes.world.getAbsoluteTransform().decompose(),r=Math.abs(i.scaleX)||1,l=Math.abs(i.scaleY)||1,d=Math.abs(s.scaleX)||1,c=Math.abs(s.scaleY)||1,h=o.width*(r/d),u=o.height*(l/c),p=Math.max(0,Math.round(h)),f=Math.max(0,Math.round(u));this._sizeLabel.getText().text(String(p)+" \xD7 "+String(f));let v=8,_=t.x+t.width/2,g=t.y+t.height+v,y=this._sizeLabel.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width;this._sizeLabel.absolutePosition({x:_,y:g}),this._sizeLabel.offsetX(y/2),this._sizeLabel.offsetY(0);let N=this._sizeLabel.getParent();if(N){let x=N.getAbsoluteTransform().decompose(),w=1/(Math.abs(x.scaleX)||1),k=1/(Math.abs(x.scaleY)||1);this._sizeLabel.scale({x:w,y:k});}this._sizeLabel.moveToTop(),this._transformer&&this._transformer.moveToTop(),this._cornerHandlesGroup&&this._cornerHandlesGroup.moveToTop();}_destroySizeLabel(){this._sizeLabel&&(this._sizeLabel.destroy(),this._sizeLabel=null);}_isCornerRadiusSupported(e){return e instanceof M.Rect||e instanceof M.Image}_getCornerRadiusArray(e){let t=e.cornerRadius();if(Array.isArray(t)){let[i=0,s=0,r=0,l=0]=t;return [i||0,s||0,r||0,l||0]}let o=typeof t=="number"?t:0;return [o,o,o,o]}_setCornerRadiusArray(e,t){let[o,i,s,r]=t;o===i&&i===s&&s===r?e.cornerRadius(o):e.cornerRadius(t);}_setupCornerRadiusHandles(e=false){if(!this._core||!this._selected)return;let t=this._selected.getKonvaNode();if(!this._isCornerRadiusSupported(t))return;let o=this._core.nodes.layer,i=this._core.stage;this._destroyCornerRadiusHandles();let s=new M.Group({name:"corner-radius-handles-group",listening:true});o.add(s),s.moveToTop(),s.visible(false),this._cornerHandlesGroup=s,t.off(".cornerRadiusHover"),t.on("mouseenter.cornerRadiusHover",()=>{!this._core||!this._cornerHandlesGroup||this._core.nodes.world.scaleX()<.3||this._cornerHandlesGroup.visible(true);}),t.on("mouseleave.cornerRadiusHover",()=>{if(!this._cornerHandlesGroup)return;let S=i.getPointerPosition();if(!S){this._cornerHandlesGroup.visible(false);return}let E=o.getIntersection(S);E&&this._cornerHandlesGroup.isAncestorOf(E)||this._cornerHandlesGroup.visible(false);}),s.on("mouseenter.cornerRadiusHover",()=>{!this._core||!this._cornerHandlesGroup||this._core.nodes.world.scaleX()<.3||this._cornerHandlesGroup.visible(true);}),s.on("mouseleave.cornerRadiusHover",()=>{this._cornerHandlesGroup&&this._cornerHandlesGroup.visible(false);});let r=i.getPointerPosition();if(r&&this._core.nodes.world.scaleX()>=.3){let P=o.getIntersection(r);P&&(P===t||t.isAncestorOf(P))&&this._cornerHandlesGroup.visible(true);}let l=()=>{let S=t.width(),E=t.height(),P=t.getAbsoluteScale(),I=1/(Math.abs(P.x)||1),F=1/(Math.abs(P.y)||1),U=12*I,z=12*F,J=Math.max(0,S/2-U),oe=Math.max(0,E/2-z),Q=Math.min(J,oe);return {tl:{corner:{x:U,y:z},sign:{x:1,y:1},side:Q},tr:{corner:{x:S-U,y:z},sign:{x:-1,y:1},side:Q},br:{corner:{x:S-U,y:E-z},sign:{x:-1,y:-1},side:Q},bl:{corner:{x:U,y:E-z},sign:{x:1,y:-1},side:Q}}},d=(S,E)=>{let P=t.getAbsoluteTransform().copy(),I=X=>P.copy().invert().point(X),F=X=>P.point(X),z=l()[E],J=I(S),oe=J.x-z.corner.x,Q=J.y-z.corner.y,G=(z.sign.x*oe+z.sign.y*Q)/2;G=Math.max(0,Math.min(z.side,G));let W={x:z.corner.x+z.sign.x*G,y:z.corner.y+z.sign.y*G};return {snappedAbs:F(W),r:G,meta:z}},c=S=>new M.Line({name:S,points:[],stroke:e?"#4a90e2":"",strokeWidth:e?1:0,dash:e?[4,4]:[],closed:true,listening:false}),h=c("corner-square-tl"),u=c("corner-square-tr"),p=c("corner-square-br"),f=c("corner-square-bl");s.add(h,u,p,f);let m=S=>{let E=new M.Circle({name:S,radius:4,fill:"#ffffff",stroke:"#4a90e2",strokeWidth:1.5,draggable:true,dragOnTop:true,hitStrokeWidth:16});return E.on("mouseenter.corner-radius",()=>{this._core&&(this._core.stage.container().style.cursor="default");}),E},v=m("corner-radius-tl"),_=m("corner-radius-tr"),g=m("corner-radius-br"),b=m("corner-radius-bl");s.add(v,_,g,b),this._cornerHandles={tl:v,tr:_,br:g,bl:b};let y={tl:0,tr:1,br:2,bl:3},N=false,x=null,w=false,k=()=>{let S=t.getAbsoluteTransform().copy(),E=t.width(),P=t.height();return S.point({x:E/2,y:P/2})},T=()=>{let S={};return this._cornerHandles.tl&&(S.tl=this._cornerHandles.tl.getAbsolutePosition()),this._cornerHandles.tr&&(S.tr=this._cornerHandles.tr.getAbsolutePosition()),this._cornerHandles.br&&(S.br=this._cornerHandles.br.getAbsolutePosition()),this._cornerHandles.bl&&(S.bl=this._cornerHandles.bl.getAbsolutePosition()),S},A=(S,E=8)=>{let P=k();return Math.hypot(S.x-P.x,S.y-P.y)<=E},R=(S,E=6)=>{let P=k();return Math.min(Math.abs(S.x-P.x),Math.abs(S.y-P.y))<=E},D=(S,E=8)=>{let P=T(),I=0;return ["tl","tr","br","bl"].forEach(F=>{let U=P[F];U&&Math.hypot(U.x-S.x,U.y-S.y)<=E&&I++;}),I>=2},B=S=>{if(!N||x)return;let E=k(),P=S.x-E.x,I=S.y-E.y,F=Math.hypot(P,I);if(F<.1)return;P/=F,I/=F;let U=t.getAbsoluteTransform().copy(),z=l(),J=["tl","tr","br","bl"].reduce((G,W)=>{let ie=z[W],X=U.point(ie.corner),ne=X.x-E.x,V=X.y-E.y,$=Math.hypot(ne,V)||1;return G[W]={x:ne/$,y:V/$},G},{}),oe="tl",Q=-1/0;["tl","tr","br","bl"].forEach(G=>{let W=J[G],ie=P*W.x+I*W.y;ie>Q&&(Q=ie,oe=G);}),x=oe;},K=S=>E=>{B(E);let P=x??S,{snappedAbs:I,r:F,meta:U}=d(E,P),z=t.width(),J=t.height(),oe=Math.max(0,Math.min(z,J)/2),Q=U.side>0?F/U.side:0,G=Math.round(Q*oe);G=Math.max(0,Math.min(G,oe));let W=this._getCornerRadiusArray(t),ie=y[P];return w?W[ie]=G:(W[0]=G,W[1]=G,W[2]=G,W[3]=G),this._setCornerRadiusArray(t,W),this._showRadiusLabelForCorner(ie),L(),this._core?.nodes.layer.batchDraw(),I};v.dragBoundFunc(K("tl")),_.dragBoundFunc(K("tr")),g.dragBoundFunc(K("br")),b.dragBoundFunc(K("bl"));let L=()=>{let{tl:S,tr:E,br:P,bl:I}=this._cornerHandles;if(!S||!E||!P||!I)return;if(this._cornerHandlesSuppressed){this._cornerHandlesGroup?.visible(false),this._radiusLabel?.visible(false);return}if(this._core&&this._cornerHandlesGroup&&this._radiusLabel){if(this._core.nodes.world.scaleX()<.3){this._cornerHandlesGroup.visible(false),this._radiusLabel.visible(false);return}this._cornerHandlesGroup.visible(true);}let F=t.getAbsoluteTransform().copy(),U=o.getAbsoluteTransform().copy().invert(),z=X=>F.point(X),J=X=>U.point(F.point(X)),oe=l(),Q=this._getCornerRadiusArray(t),G=(X,ne,V)=>{let $=oe[X],ye=t.width(),De=t.height(),we=Math.max(0,Math.min(ye,De)/2),Le=Math.max(0,Math.min(we,Q[ne]||0)),Ge=we>0?Le/we:0,bt=Math.max(0,Math.min($.side,Ge*$.side)),St={x:$.corner.x+$.sign.x*bt,y:$.corner.y+$.sign.y*bt};V.absolutePosition(z(St));},W=(X,ne)=>{let V=oe[X],$=V.corner,ye={x:V.corner.x+V.sign.x*V.side,y:V.corner.y+V.sign.y*V.side},De=J({x:$.x,y:$.y}),we=J({x:ye.x,y:$.y}),Le=J({x:ye.x,y:ye.y}),Ge=J({x:$.x,y:ye.y});ne.points([De.x,De.y,we.x,we.y,Le.x,Le.y,Ge.x,Ge.y]);};W("tl",h),W("tr",u),W("br",p),W("bl",f),G("tl",0,S),G("tr",1,E),G("br",2,P),G("bl",3,I);let ie=this._cornerHandlesGroup?.getParent();if(ie){let X=ie.getAbsoluteTransform().decompose(),ne=1/(Math.abs(X.scaleX)||1),V=1/(Math.abs(X.scaleY)||1);S.scale({x:ne,y:V}),E.scale({x:ne,y:V}),P.scale({x:ne,y:V}),I.scale({x:ne,y:V});}this._cornerHandlesGroup?.moveToTop();};this._updateCornerRadiusHandlesPosition=L;let ee=(S,E)=>{w=!!E?.evt?.altKey;let P=S.getAbsolutePosition();if(N=A(P,8)||R(P,6)||D(P,8),x=null,N){let I=this._core?.stage.getPointerPosition()??P;B(I);}},j=(S,E)=>P=>{w=P.evt.altKey;},ae=()=>{if(N=false,x=null,w=false,this._selected&&this._core){let S=this._selected.getKonvaNode(),E={x:S.x(),y:S.y()};typeof S.width=="function"&&(E.width=S.width()),typeof S.height=="function"&&(E.height=S.height()),this._core.eventBus.emit("node:transformed",this._selected,E);}};v.on("dragstart.corner-radius",S=>{ee(v,S);}),_.on("dragstart.corner-radius",S=>{ee(_,S);}),g.on("dragstart.corner-radius",S=>{ee(g,S);}),b.on("dragstart.corner-radius",S=>{ee(b,S);}),v.on("dragmove.corner-radius",j()),_.on("dragmove.corner-radius",j()),g.on("dragmove.corner-radius",j()),b.on("dragmove.corner-radius",j()),v.on("dragend.corner-radius",ae),_.on("dragend.corner-radius",ae),g.on("dragend.corner-radius",ae),b.on("dragend.corner-radius",ae);let Y=S=>()=>{this._showRadiusLabelForCorner(S);},Z=()=>{this._hideRadiusLabel();},te=S=>()=>{this._showRadiusLabelForCorner(S);};v.on("mouseenter.corner-radius",Y(0)),_.on("mouseenter.corner-radius",Y(1)),g.on("mouseenter.corner-radius",Y(2)),b.on("mouseenter.corner-radius",Y(3)),v.on("mouseleave.corner-radius",Z),_.on("mouseleave.corner-radius",Z),g.on("mouseleave.corner-radius",Z),b.on("mouseleave.corner-radius",Z),v.on("dragstart.corner-radius",Y(0)),_.on("dragstart.corner-radius",Y(1)),g.on("dragstart.corner-radius",Y(2)),b.on("dragstart.corner-radius",Y(3)),v.on("dragmove.corner-radius",te(0)),_.on("dragmove.corner-radius",te(1)),g.on("dragmove.corner-radius",te(2)),b.on("dragmove.corner-radius",te(3)),v.on("dragend.corner-radius",Z),_.on("dragend.corner-radius",Z),g.on("dragend.corner-radius",Z),b.on("dragend.corner-radius",Z);let se=()=>{if(!this._selected)return;this._selected.getKonvaNode().draggable(false);},le=()=>{if(!this._selected)return;let S=this._selected.getKonvaNode();this._options.dragEnabled&&S.draggable(true);};v.on("mousedown.corner-radius touchstart.corner-radius",se),_.on("mousedown.corner-radius touchstart.corner-radius",se),g.on("mousedown.corner-radius touchstart.corner-radius",se),b.on("mousedown.corner-radius touchstart.corner-radius",se),v.on("mouseup.corner-radius touchend.corner-radius",le),_.on("mouseup.corner-radius touchend.corner-radius",le),g.on("mouseup.corner-radius touchend.corner-radius",le),b.on("mouseup.corner-radius touchend.corner-radius",le);let q=".corner-squares",me=false,be=()=>{me||(me=true,M.Util.requestAnimFrame(()=>{me=false,L(),this._core?.nodes.layer.batchDraw();}));};i.on(["wheel","resize","xChange","yChange","positionChange","scaleXChange","scaleYChange","scaleChange"].map(S=>S+q).join(" "),be),o.on(["xChange","yChange","positionChange","scaleXChange","scaleYChange","scaleChange"].map(S=>S+q).join(" "),be),t.on(["dragmove","transform","xChange","yChange","widthChange","heightChange","rotationChange","scaleXChange","scaleYChange","positionChange","scaleChange"].map(S=>S+q).join(" "),be),this._transformer&&(this._transformer.on("transformstart"+q,()=>{this._cornerHandlesSuppressed=true,this._cornerHandlesGroup?.visible(false),this._hideRadiusLabel(),this._core?.nodes.layer.batchDraw();}),this._transformer.on("transform"+q,()=>{L(),this._core?.nodes.layer.batchDraw();}),this._transformer.on("transformend"+q,()=>{this._cornerHandlesSuppressed=false,be();})),s.on("destroy"+q,()=>{i.off(q),o.off(q),t.off(q),this._transformer?.off(q);}),L(),o.batchDraw();}_destroyCornerRadiusHandles(){this._cornerHandlesGroup&&(this._cornerHandlesGroup.destroy(),this._cornerHandlesGroup=null),this._cornerHandles={tl:null,tr:null,br:null,bl:null},this._core&&(this._core.stage.container().style.cursor="default"),this._destroyRadiusLabel(),this._selected&&this._selected.getKonvaNode().off(".overlay-sync");}_bakeRectScale(e){if(!(e instanceof M.Rect))return;let t=e.scaleX(),o=e.scaleY();if(t===1&&o===1)return;let i=e.getAbsolutePosition(),s=e.width(),r=e.height(),l=Math.abs(t)*s,d=Math.abs(o)*r;e.width(l),e.height(d),e.scaleX(1),e.scaleY(1),e.setAbsolutePosition(i);}_updateCornerRadiusHandlesPosition(){if(!this._core||!this._selected||!this._cornerHandlesGroup)return;let e=this._selected.getKonvaNode();if(!this._isCornerRadiusSupported(e))return;let t=e,o=t.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}),i=o.width,s=o.height;if(i<=0||s<=0)return;let r=t.getAbsoluteTransform().copy(),l=w=>r.point(w),d=t.getAbsoluteScale(),c=1/(Math.abs(d.x)||1),h=1/(Math.abs(d.y)||1),u=12*c,p=12*h,f=this._getCornerRadiusArray(t),m=Math.min(i,s)/2||1,v=w=>{let k=Math.hypot(w.x,w.y)||1;return {x:w.x/k,y:w.y/k}},_=[v({x:i/2-u,y:s/2-p}),v({x:-(i/2-u),y:s/2-p}),v({x:-(i/2-u),y:-(s/2-p)}),v({x:i/2-u,y:-(s/2-p)})],g=l({x:o.x+u+_[0].x*Math.min(m,f[0]),y:o.y+p+_[0].y*Math.min(m,f[0])}),b=l({x:o.x+i-u+_[1].x*Math.min(m,f[1]),y:o.y+p+_[1].y*Math.min(m,f[1])}),y=l({x:o.x+i-u+_[2].x*Math.min(m,f[2]),y:o.y+s-p+_[2].y*Math.min(m,f[2])}),N=l({x:o.x+u+_[3].x*Math.min(m,f[3]),y:o.y+s-p+_[3].y*Math.min(m,f[3])});this._cornerHandles.tl&&this._cornerHandles.tl.absolutePosition(g),this._cornerHandles.tr&&this._cornerHandles.tr.absolutePosition(b),this._cornerHandles.br&&this._cornerHandles.br.absolutePosition(y),this._cornerHandles.bl&&this._cornerHandles.bl.absolutePosition(N);let x=this._cornerHandlesGroup.getParent();if(x){let w=x.getAbsoluteTransform().decompose(),k=1/(Math.abs(w.scaleX)||1),T=1/(Math.abs(w.scaleY)||1);this._cornerHandles.tl&&this._cornerHandles.tl.scale({x:k,y:T}),this._cornerHandles.tr&&this._cornerHandles.tr.scale({x:k,y:T}),this._cornerHandles.br&&this._cornerHandles.br.scale({x:k,y:T}),this._cornerHandles.bl&&this._cornerHandles.bl.scale({x:k,y:T});}this._cornerHandlesGroup.moveToTop();}_updateCornerRadiusHandlesVisibility(){if(!this._core||!this._selected||!this._cornerHandlesGroup)return;let t=this._core.nodes.world.scaleX(),o=this._core.stage,i=this._core.nodes.layer,s=this._selected.getKonvaNode(),r=o.getPointerPosition();if(!r){t<.3&&this._cornerHandlesGroup.visible(false);return}if(t<.3){this._cornerHandlesGroup.visible(false);return}let l=i.getIntersection(r);if(l){let d=l===s||s.isAncestorOf(l),c=this._cornerHandlesGroup.isAncestorOf(l);d||c?this._cornerHandlesGroup.visible(true):this._cornerHandlesGroup.visible(false);}else this._cornerHandlesGroup.visible(false);}_ensureRadiusLabel(){if(!this._core)return null;if(this._radiusLabel)return this._radiusLabel;let e=this._core.nodes.layer,t=new M.Label({listening:false,opacity:.95}),o=new M.Tag({fill:"#2b83ff",cornerRadius:4,shadowColor:"#000",shadowBlur:6,shadowOpacity:.25}),i=new M.Text({text:"",fontFamily:"Inter, Calibri, Arial, sans-serif",fontSize:12,padding:4,fill:"#ffffff"});return t.add(o),t.add(i),t.visible(false),e.add(t),this._radiusLabel=t,t}_updateRadiusLabelAt(e,t){let o=this._ensureRadiusLabel();if(!o)return;o.getText().text(t);let r=o.getClientRect({skipTransform:true,skipShadow:true,skipStroke:true}).width,l={x:8,y:8};o.absolutePosition({x:e.x-l.x,y:e.y+l.y}),o.offsetX(r),o.offsetY(0);let d=o.getParent();if(d){let c=d.getAbsoluteTransform().decompose(),h=1/(Math.abs(c.scaleX)||1),u=1/(Math.abs(c.scaleY)||1);o.scale({x:h,y:u});}o.visible(true),o.moveToTop(),this._transformer&&this._transformer.moveToTop();}_showRadiusLabelForCorner(e){if(!this._core||!this._selected)return;let t=this._selected.getKonvaNode();if(!this._isCornerRadiusSupported(t))return;let o=t,i=this._getCornerRadiusArray(o),s=Math.round(i[e]),r=e===0?this._cornerHandles.tl:e===1?this._cornerHandles.tr:e===2?this._cornerHandles.br:this._cornerHandles.bl;if(!r)return;let l=r.getAbsolutePosition();this._updateRadiusLabelAt(l,"Radius "+String(s));}_hideRadiusLabel(){this._radiusLabel&&this._radiusLabel.visible(false);}_destroyRadiusLabel(){this._radiusLabel&&(this._radiusLabel.destroy(),this._radiusLabel=null);}_findBaseNodeByTarget(e){if(!this._core)return null;if(this._selected){let o=this._selected.getKonvaNode();if(o===e)return this._selected;if(typeof o.isAncestorOf=="function"&&o.isAncestorOf(e))return this._selected}let t=null;for(let o of this._core.nodes.list()){let i=o.getKonvaNode();if(typeof i.isAncestorOf=="function"&&i.isAncestorOf(e)){let s=true;for(let r of this._core.nodes.list()){if(r===o)continue;let l=r.getKonvaNode();if(typeof l.isAncestorOf=="function"&&l.isAncestorOf(i)){s=false;break}}s&&(t=o);}}if(t)return t;for(let o of this._core.nodes.list())if(o.getKonvaNode()===e)return o;return null}_disableGroupChildrenDragging(e){let t=e.getChildren();for(let o of t){let i=o;typeof i.draggable=="function"&&i.draggable(false);}}};var it=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_layer",null);a(this,"_rect",null);a(this,"_start",null);a(this,"_transformer",null);a(this,"_selecting",false);a(this,"_skipNextClick",false);a(this,"_lastPickedBaseNodes",[]);a(this,"_options");this._options={rectStroke:e.rectStroke??"#2b83ff",rectFill:e.rectFill??"#2b83ff",rectStrokeWidth:e.rectStrokeWidth??1,rectOpacity:e.rectOpacity??.15,enableKeyboardShortcuts:e.enableKeyboardShortcuts??true};}onAttach(e){this._core=e;let t=new M.Layer({name:"area-selection-layer",listening:false});e.stage.add(t),this._layer=t,this._rect=new M.Rect({x:0,y:0,width:0,height:0,visible:false,stroke:this._options.rectStroke,strokeWidth:this._options.rectStrokeWidth,fill:this._options.rectFill,opacity:this._options.rectOpacity,listening:false}),t.add(this._rect);let o=e.stage;o.on("mousedown.area",i=>{if(i.evt.button!==0||i.target!==o&&i.target.getLayer()===e.nodes.layer)return;let s=o.getPointerPosition();if(!s||!this._rect)return;let r=o.findOne(".ruler-layer");if(r&&i.target.getLayer()===r)return;let l=o.findOne(".guides-layer");if(l&&i.target.getLayer()===l)return;let d=30;s.y<=d||s.x<=d||(this._selecting=true,this._start={x:s.x,y:s.y},this._rect.visible(true),this._rect.position({x:s.x,y:s.y}),this._rect.size({width:0,height:0}),this._layer?.batchDraw(),this._lastPickedBaseNodes=[]);}),o.on("mousemove.area",()=>{if(!this._selecting||!this._rect||!this._start)return;let i=o.getPointerPosition();if(!i)return;let s=30;if(i.y<=s||i.x<=s){this._selecting=false,this._rect.visible(false),this._layer?.batchDraw();return}let l=Math.min(this._start.x,i.x),d=Math.min(this._start.y,i.y),c=Math.abs(i.x-this._start.x),h=Math.abs(i.y-this._start.y);this._rect.position({x:l,y:d}),this._rect.size({width:c,height:h}),this._layer?.batchDraw();let u={x:l,y:d,width:c,height:h},p=this._core?.nodes.list()??[],f=new Set;for(let _ of p){if(_ instanceof de)continue;let g=_.getKonvaNode();if(g.getLayer()!==this._core?.nodes.layer)continue;let y=g.getClientRect({skipShadow:true,skipStroke:false});if(this._rectsIntersect(u,y)){let N=this._findOwningGroupBaseNode(g);f.add(N??_);}}let m=Array.from(f),v=this._getSelectionPlugin();if(m.length>0&&(this._lastPickedBaseNodes=m),v){let _=v.getMultiGroupController();m.length>0&&_.ensure(m),this._core?.stage.batchDraw();}}),o.on("mouseup.area",i=>{if(!this._selecting)return;let s=false;if(this._rect?.visible()){let r=this._rect.size();s=r.width>2||r.height>2;}this._finalizeArea(),s&&(this._skipNextClick=true,this._core?.stage.setAttr("_skipSelectionEmptyClickOnce",true),i.cancelBubble=true);}),o.on("click.area",i=>{if(!this._core)return;if(this._skipNextClick){this._skipNextClick=false,i.cancelBubble=true;return}if(i.evt.shiftKey)return;let r=this._getSelectionPlugin()?.getMultiGroupController(),l=!!r?.isActive();if(!l&&!this._isPermanentGroupSelected())return;let d=i.target,c=this._currentGroupNode();c?this._isAncestor(c,d)||this._clearSelection():l&&r&&(r.isInsideTempByTarget(d)||(r.destroy(),this._core.stage.batchDraw()));});}onDetach(e){e.stage.off(".area"),this._clearSelection(),this._layer&&this._layer.destroy(),this._layer=null,this._rect=null;}_finalizeArea(){if(!this._core||!this._rect||!this._start)return;this._selecting=false;let e=this._rect.getClientRect({skipStroke:true});this._rect.visible(false),this._layer?.batchDraw();let t=[];if(this._lastPickedBaseNodes.length>0)t=[...this._lastPickedBaseNodes];else {let i=this._core.nodes.list(),s=[];for(let d of i){let c=d.getKonvaNode();if(c.getLayer()!==this._core.nodes.layer)continue;let u=c.getClientRect({skipShadow:true,skipStroke:false});this._rectsIntersect(e,u)&&s.push(c);}let r=this._core.nodes.list(),l=new Set;for(let d of s){let c=r.find(u=>u.getKonvaNode()===d)??null,h=this._findOwningGroupBaseNode(d);h?l.add(h):c&&!(c instanceof de)&&l.add(c);}t=Array.from(l);}let o=this._getSelectionPlugin();o&&(t.length>0?(o.getMultiGroupController().ensure(t),this._core.stage.batchDraw()):o.getMultiGroupController().destroy()),this._lastPickedBaseNodes=[];}_clearSelection(){this._isPermanentGroupSelected()&&(this._transformer&&this._transformer.destroy(),this._transformer=null,this._core?.stage.batchDraw());let t=this._getSelectionPlugin()?.getMultiGroupController();t&&t.destroy();}_getSelectionPlugin(){return this._core?this._core.plugins.list().find(t=>t instanceof ve)??null:null}_rectsIntersect(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}_findOwningGroupBaseNode(e){if(!this._core)return null;let o=this._core.nodes.list().filter(r=>r instanceof de),i=e,s=null;for(;i;){let r=o.find(l=>l.getKonvaNode()===i)??null;r&&(s=r),i=i.getParent();}return s}_isAncestor(e,t){let o=t;for(;o;){if(o===e)return true;o=o.getParent();}return false}_isPermanentGroupSelected(){if(!this._transformer)return false;let t=(typeof this._transformer.nodes=="function"?this._transformer.nodes():[])[0];return !t||!this._core?false:this._core.nodes.list().some(o=>o instanceof de&&o.getKonvaNode()===t)}_currentGroupNode(){if(!this._transformer)return null;let t=(typeof this._transformer.nodes=="function"?this._transformer.nodes():[])[0];return t&&t instanceof M.Group?t:null}};var st=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_attached",false);a(this,"_panning",false);a(this,"_last",null);a(this,"_prevCursor",null);a(this,"_prevStageDraggable");a(this,"_onWheelDOM",e=>{if(!this._core||e.ctrlKey)return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation?.();let{deltaX:o,deltaY:i,shiftKey:s}=e;if(this._isTouchpadWheel(e)){if(s){let l=-(Math.abs(o)>=Math.abs(i)?o:i);this._pan(l,0);}else {let r=-o,l=-i;this._pan(r,l);}return}if(s){let r=i<0?-Math.abs(i):Math.abs(i);this._pan(r,0);}else {let r=-i;this._pan(0,r);}});a(this,"_onMouseDownKonva",e=>{if(!this._core||!this._options.enablePanning)return;let t=e.evt.button;if(!(this._options.allowMiddleButtonPan&&t===1||this._options.allowRightButtonPan&&t===2))return;this._panning=true;let i=this._core.stage.getPointerPosition();i&&(this._last={x:i.x,y:i.y});let s=this._core.stage.container();this._prevCursor=s.style.cursor||null,s.style.cursor="grabbing",e.evt.preventDefault();});a(this,"_onMouseMoveKonva",e=>{if(!this._core||!this._options.enablePanning||!this._panning||!this._last)return;let t=this._core.stage.getPointerPosition();if(!t)return;let o=t.x-this._last.x,i=t.y-this._last.y;this._pan(o,i),this._last={x:t.x,y:t.y};});a(this,"_onMouseUpKonva",e=>{if(!this._options.enablePanning||(this._panning=false,this._last=null,!this._core))return;let t=this._core.stage.container();this._prevCursor!==null?(t.style.cursor=this._prevCursor,this._prevCursor=null):t.style.removeProperty("cursor");});a(this,"_onMouseLeaveKonva",e=>{if(!this._options.enablePanning||(this._panning=false,this._last=null,!this._core))return;let t=this._core.stage.container();this._prevCursor!==null?(t.style.cursor=this._prevCursor,this._prevCursor=null):t.style.removeProperty("cursor");});a(this,"_onContextMenuDOM",e=>{this._options.disableContextMenu&&e.preventDefault();});a(this,"_handleKeyDown",e=>{if(this._options.ignoreEditableTargets&&this._isEditableTarget(e.target)||!this._core)return;let t=e.code==="Equal"||e.code==="NumpadAdd",o=e.code==="Minus"||e.code==="NumpadSubtract";if(t||o){e.preventDefault(),t?this._core.camera.zoomIn():this._core.camera.zoomOut();return}if(this._options.enableArrows){let i=this._core.camera.panStep;switch(e.key){case "ArrowLeft":e.preventDefault(),this._pan(i,0);return;case "ArrowRight":e.preventDefault(),this._pan(-i,0);return;case "ArrowUp":e.preventDefault(),this._pan(0,i);return;case "ArrowDown":e.preventDefault(),this._pan(0,-i);return}}});let{target:t=globalThis,zoomStep:o=1.1,panStep:i=40,ignoreEditableTargets:s=true,enableArrows:r=true,enablePanning:l=true,allowMiddleButtonPan:d=true,allowRightButtonPan:c=true,disableContextMenu:h=true}=e;this._options={target:t,zoomStep:o,panStep:i,ignoreEditableTargets:s,enableArrows:r,enablePanning:l,allowMiddleButtonPan:d,allowRightButtonPan:c,disableContextMenu:h};}setOptions(e){let t=this._options.disableContextMenu;if(this._options={...this._options,...e},this._attached&&this._core&&(typeof e.zoomStep=="number"&&this._core.camera.setZoomStep(this._options.zoomStep),typeof e.panStep=="number"&&this._core.camera.setPanStep(this._options.panStep),typeof e.disableContextMenu=="boolean"&&e.disableContextMenu!==t)){let o=this._core.stage.container();this._options.disableContextMenu?o.addEventListener("contextmenu",this._onContextMenuDOM):o.removeEventListener("contextmenu",this._onContextMenuDOM);}}onAttach(e){this._core=e;let t=this._core.stage;typeof this._options.zoomStep=="number"&&this._core.camera.setZoomStep(this._options.zoomStep),typeof this._options.panStep=="number"&&this._core.camera.setPanStep(this._options.panStep),this._prevStageDraggable=t.draggable(),t.draggable(false),this._options.target.addEventListener("keydown",this._handleKeyDown),this._options.enablePanning&&(t.on("mousedown.cameraHotkeys",this._onMouseDownKonva),t.on("mousemove.cameraHotkeys",this._onMouseMoveKonva),t.on("mouseup.cameraHotkeys",this._onMouseUpKonva),t.on("mouseleave.cameraHotkeys",this._onMouseLeaveKonva),this._options.disableContextMenu&&t.container().addEventListener("contextmenu",this._onContextMenuDOM)),t.container().addEventListener("wheel",this._onWheelDOM,{passive:false,capture:true}),t.on("wheel.cameraHotkeysGuard",i=>{i.evt.ctrlKey||(i.evt.preventDefault(),i.cancelBubble=true);}),this._attached=true;}onDetach(e){if(!this._attached)return;this._options.target.removeEventListener("keydown",this._handleKeyDown);let o=e.stage;o.off(".cameraHotkeys"),o.off(".cameraHotkeysGuard"),o.container().removeEventListener("wheel",this._onWheelDOM),this._options.enablePanning&&o.container().removeEventListener("contextmenu",this._onContextMenuDOM),this._prevStageDraggable!==void 0&&o.draggable(this._prevStageDraggable),this._attached=false,this._last=null,this._prevCursor=null;}_isEditableTarget(e){let t=e;if(!t)return false;let o=t.tagName;return t.isContentEditable||o==="INPUT"||o==="TEXTAREA"||o==="SELECT"}_isTouchpadWheel(e){return e.deltaMode===0&&(Math.abs(e.deltaX)>0||Math.abs(e.deltaY)<50)}_pan(e,t){if(!this._core)return;let o=this._core.nodes.world,i=o.x()+e,s=o.y()+t;o.position({x:i,y:s}),this._core.eventBus.emit("camera:pan",{dx:e,dy:t,position:{x:i,y:s}}),this._core.stage.batchDraw();}};var rt=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_layer",null);a(this,"_shape",null);a(this,"_stepX");a(this,"_stepY");a(this,"_color");a(this,"_lineWidth");a(this,"_visible");a(this,"_minScaleToShow");a(this,"_enableSnap");a(this,"_dragMoveHandler",null);a(this,"_nodesAddHandler",null);a(this,"_nodesRemoveHandler",null);a(this,"_redrawScheduled",false);a(this,"_transformersCache",[]);a(this,"_cacheInvalidated",true);this._stepX=Math.max(1,e.stepX??1),this._stepY=Math.max(1,e.stepY??1),this._color=e.color??"#2b313a",this._lineWidth=e.lineWidth??1,this._visible=e.visible??true,this._minScaleToShow=e.minScaleToShow??8,this._enableSnap=e.enableSnap??true;}onAttach(e){this._core=e;let t=e.nodes.layer,o=(h,u)=>{if(!this._visible||!this._core)return;let p=this._core.stage,f=this._core.nodes.world,m=f.scaleX();if(this._minScaleToShow!=null&&m<this._minScaleToShow)return;let v=p.width(),_=p.height(),g=f.scaleX(),b=f.scaleY(),y=Math.max(1,this._stepX)*Math.max(1e-6,g),N=Math.max(1,this._stepY)*Math.max(1e-6,b),x=(f.x()%y+y)%y,w=(f.y()%N+N)%N;h.beginPath(),h.lineWidth=this._lineWidth,h.strokeStyle=this._color;for(let k=x;k<=v;k+=y)h.moveTo(k,0),h.lineTo(k,_);for(let k=w;k<=_;k+=N)h.moveTo(0,k),h.lineTo(v,k);h.stroke();},i=new M.Shape({listening:false,sceneFunc:o});t.add(i),this._layer=t,this._shape=i;let s=e.stage,r=e.nodes.world;s.on("resize.grid",()=>{this._scheduleRedraw();}),r.on("xChange.grid yChange.grid scaleXChange.grid scaleYChange.grid",()=>{this._scheduleRedraw();}),(()=>{this._cacheInvalidated&&(this._transformersCache=t.find("Transformer"),this._cacheInvalidated=false);for(let h of this._transformersCache)h.moveToTop();this._shape?.moveToTop();for(let h of this._transformersCache)h.moveToTop();})(),this._dragMoveHandler=h=>{if(!this._core||!this._enableSnap)return;let u=this._core.stage,p=this._core.nodes.world,f=h.target;if(f===u||f instanceof M.Layer)return;let m=this._core.nodes.layer,v=f,_=false;for(;v;){if(v===m){_=true;break}v=v.getParent();}if(!_)return;let g=f;if(typeof g.draggable=="function"&&!g.draggable())return;let b=f.getAbsolutePosition(),y=p.scaleX()||1,N=p.scaleY()||1;if(this._minScaleToShow!=null?y>=this._minScaleToShow:false){let w=(b.x-p.x())/y,k=(b.y-p.y())/N,T=Math.max(1,this._stepX),A=Math.max(1,this._stepY),R=Math.round(w/T)*T,D=Math.round(k/A)*A,B=R*y+p.x(),K=D*N+p.y();(Math.abs(B-b.x)>.001||Math.abs(K-b.y)>.001)&&f.absolutePosition({x:B,y:K});}else {let w=(b.x-p.x())/y,k=(b.y-p.y())/N,T=Math.max(1,this._stepX),A=Math.max(1,this._stepY),R=Math.round(w/T)*T,D=Math.round(k/A)*A,B=R*y+p.x(),K=D*N+p.y();(Math.abs(B-b.x)>.001||Math.abs(K-b.y)>.001)&&f.absolutePosition({x:B,y:K});}},s.on("dragmove.grid",this._dragMoveHandler);let d=h=>{let u=h;if((typeof u.getClassName=="function"?u.getClassName():"")!=="Transformer")return;let f=h,m=(v,_)=>{let g=_;if(!this._enableSnap||!this._core||!(typeof u.nodes=="function"?u.nodes():[])[0])return g;let N=typeof u.getActiveAnchor=="function"?u.getActiveAnchor():"";if(N==="rotater")return g;let x=Math.max(1,this._stepX),w=Math.max(1,this._stepY),k=typeof N=="string"?N:"",T=this._core.nodes.world.getAbsoluteTransform(),A=T.copy();A.invert();let R=g.x,D=g.x+g.width,B=g.y,K=g.y+g.height,L=A.point({x:R,y:B}).x,ee=A.point({x:D,y:B}).x,j=A.point({x:R,y:B}).y,ae=A.point({x:R,y:K}).y,Y=L,Z=ee,te=j,se=ae,le=(I,F)=>Math.round((I+1e-9)/F)*F;k.includes("left")&&(Y=le(L,x)),k.includes("right")&&(Z=le(ee,x)),k.includes("top")&&(te=le(j,w)),k.includes("bottom")&&(se=le(ae,w)),Z-Y<x&&(k.includes("left")?Y=Z-x:Z=Y+x),se-te<w&&(k.includes("top")?te=se-w:se=te+w);let q=T.point({x:Y,y:te}).x,me=T.point({x:Y,y:te}).y,be=T.point({x:Z,y:te}).x,S=T.point({x:Y,y:se}).y,E=I=>Math.round(I*1e3)/1e3;return {x:E(q),y:E(me),width:E(be-q),height:E(S-me),rotation:g.rotation}};globalThis.queueMicrotask(()=>{f.boundBoxFunc(m);});},c=h=>{d(h);let u=h,p=typeof u.getChildren=="function"?u.getChildren():[];for(let f of p)c(f);};c(e.nodes.layer),this._nodesAddHandler=h=>{let u=h.child??h.target;c(u);let p=u;if((typeof p.getClassName=="function"?p.getClassName():"")==="Transformer"){this._cacheInvalidated=true,u.moveToTop(),this._shape?.moveToTop(),this._transformersCache=t.find("Transformer"),this._cacheInvalidated=false;for(let m of this._transformersCache)m.moveToTop();}},this._nodesRemoveHandler=h=>{let u=h.child??h.target,p=v=>{let _=v;(typeof _.getClassName=="function"?_.getClassName():"")==="Transformer"&&v.boundBoxFunc?.(void 0);let b=typeof _.getChildren=="function"?_.getChildren():[];for(let y of b)p(y);};p(u);let f=u;(typeof f.getClassName=="function"?f.getClassName():"")==="Transformer"&&(this._cacheInvalidated=true),this._shape?.moveToTop(),this._cacheInvalidated&&(this._transformersCache=t.find("Transformer"),this._cacheInvalidated=false);for(let v of this._transformersCache)v.moveToTop();},e.nodes.layer.on("add.grid",this._nodesAddHandler),e.nodes.layer.on("remove.grid",this._nodesRemoveHandler),e.nodes.layer.on("cornerRadiusChange.grid",h=>{let u=h.target;if((typeof u.getClassName=="function"?u.getClassName():"")!=="Rect")return;let f=u.cornerRadius;if(typeof f!="function")return;let m=f.call(u),v=y=>{u.cornerRadius(y);},_=this._core?.stage,g=_?.scaleX()??1,b=this._minScaleToShow!=null?g>=this._minScaleToShow:false;if(Array.isArray(m)){let y=m.map(N=>{if(b){let x=_?.scaleX()??1,w=_?.scaleY()??1,k=N*(.5*(x+w));return Math.max(0,Math.round(k))/Math.max(1e-6,.5*(x+w))}else return Math.max(0,Math.round(N))});v(y);}else if(typeof m=="number")if(b){let y=_?.scaleX()??1,N=_?.scaleY()??1,x=m*(.5*(y+N)),w=Math.max(0,Math.round(x));v(w/Math.max(1e-6,.5*(y+N)));}else v(Math.max(0,Math.round(m)));});}_scheduleRedraw(){if(this._redrawScheduled)return;this._redrawScheduled=true;let e=globalThis.requestAnimationFrame;e(()=>{this._redrawScheduled=false,this._layer?.batchDraw();});}onDetach(e){e.stage.off(".grid"),e.nodes.layer.off(".grid"),this._shape&&this._shape.destroy(),this._shape=null,this._layer=null,this._dragMoveHandler=null,this._nodesAddHandler=null,this._nodesRemoveHandler=null,e.stage.batchDraw();}setVisible(e){this._visible=e,this._core&&this._core.stage.batchDraw();}get stepX(){return this._stepX}get stepY(){return this._stepY}get minScaleToShow(){return this._minScaleToShow}setStep(e,t){this._stepX=Math.max(1,e),this._stepY=Math.max(1,t),this._core&&this._core.stage.batchDraw();}setMinScaleToShow(e){this._minScaleToShow=e,this._core&&this._core.stage.batchDraw();}setSnap(e){this._enableSnap=e;}};var at=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_history");a(this,"_options");a(this,"_isUndoRedoInProgress",false);a(this,"_dragStartStateCache",new Map);a(this,"_isBatchMode",false);a(this,"_batchBuffer",[]);a(this,"_batchCommitTimer",null);a(this,"_onKeyDown",e=>{if(!this._core||this._options.ignoreEditableTargets&&this._isEditableTarget(e.target))return;let t=e.ctrlKey||e.metaKey,o=e.shiftKey;if(t&&!o&&e.code==="KeyZ"){e.preventDefault(),this._performUndo();return}if(t&&o&&e.code==="KeyZ"){e.preventDefault(),this._performRedo();return}});a(this,"_onDragStart",e=>{if(this._isUndoRedoInProgress)return;let t=e.target;this._debug("dragstart raw target",{targetName:t.name(),targetClassName:t.getClassName(),targetId:t.id()});let o=t.name();if(typeof o=="string"&&o.includes("temp-multi-group")){this._isBatchMode=true,this._batchBuffer=[];let r=t.getChildren();for(let l of r){let d=this._findBaseNodeByKonva(l);if(d){let c=this._captureTransformState(d);this._dragStartStateCache.set(d.id,c),this._debug("dragstart (temp-multi child)",{nodeId:d.id});}}return}let i=this._findBaseNodeByKonva(t);if(i){let s=this._captureTransformState(i);this._dragStartStateCache.set(i.id,s),this._debug("dragstart",{nodeId:i.id,state:s});}else this._debug("dragstart - baseNode not found for target");});a(this,"_onDragEnd",e=>{});a(this,"_onTransformStart",e=>{if(this._isUndoRedoInProgress)return;let t=e.target;this._debug("transformstart raw target",{targetName:t.name(),targetClassName:t.getClassName(),targetId:t.id()});let o=t.name();if(typeof o=="string"&&o.includes("temp-multi-group")){this._isBatchMode=true,this._batchBuffer=[];let r=t.getChildren();for(let l of r){let d=this._findBaseNodeByKonva(l);if(d){let c=this._captureTransformState(d);this._dragStartStateCache.set(d.id,c),this._debug("transformstart (temp-multi child)",{nodeId:d.id});}}return}let i=this._findBaseNodeByKonva(t);if(i){let s=this._captureTransformState(i);this._dragStartStateCache.set(i.id,s),this._debug("transformstart",{nodeId:i.id,state:s});}else this._debug("transformstart - baseNode not found for target");});a(this,"_onTransformEnd",e=>{});a(this,"_onNodeCreated",e=>{if(this._isUndoRedoInProgress){this._debug("node:created skipped (undo/redo in progress)",e.id);return}let t=this._serializeNode(e),o={type:"create",nodeId:e.id,before:null,after:t,timestamp:Date.now()};this._history.push(o),this._dragStartStateCache.set(e.id,this._captureTransformState(e)),this._trimHistoryIfNeeded();});a(this,"_onNodeRemoved",e=>{if(this._isUndoRedoInProgress)return;let t=this._serializeNode(e),o={type:"remove",nodeId:e.id,before:t,after:null,timestamp:Date.now()};this._isBatchMode?this._batchBuffer.push(o):(this._history.push(o),this._trimHistoryIfNeeded()),this._dragStartStateCache.delete(e.id);});a(this,"_onNodeTransformed",(e,t)=>{if(this._isUndoRedoInProgress){this._debug("node:transformed skipped (undo/redo in progress)",e.id);return}let o=this._dragStartStateCache.get(e.id),i=this._buildAfterState(e,t);if(!o){this._debug("transform - no before state, saving current",e.id),this._dragStartStateCache.set(e.id,i);return}if(this._statesEqual(o,i)){this._debug("transform skipped - no changes",e.id);return}let s={type:"transform",nodeId:e.id,before:o,after:i,timestamp:Date.now()};this._debug("transform recorded",{nodeId:e.id,before:o,after:i,batchMode:this._isBatchMode}),this._isBatchMode?(this._batchBuffer.push(s),this._scheduleBatchCommit()):(this._history.push(s),this._trimHistoryIfNeeded()),this._dragStartStateCache.set(e.id,i);});a(this,"_onZIndexChanged",(e,t,o)=>{if(this._isUndoRedoInProgress)return;let i={type:"zIndex",nodeId:e.id,before:{zIndex:t},after:{zIndex:o},timestamp:Date.now()};this._history.push(i),this._trimHistoryIfNeeded();});a(this,"_onGroupCreated",(e,t)=>{if(this._isUndoRedoInProgress)return;let o=t.map(r=>this._serializeNode(r)),i=t.map(r=>r.id),s={type:"group",nodeId:e.id,before:{childIds:i,childStates:o},after:this._serializeNode(e),timestamp:Date.now()};this._history.push(s),this._trimHistoryIfNeeded();});a(this,"_onGroupUngrouped",(e,t)=>{if(this._isUndoRedoInProgress)return;let o=this._serializeNode(e),i=t.map(r=>this._serializeNode(r)),s={type:"ungroup",nodeId:e.id,before:o,after:{childStates:i},timestamp:Date.now()};this._history.push(s),this._trimHistoryIfNeeded();});this._history=new Me;let{target:t=globalThis,ignoreEditableTargets:o=true,maxHistoryLength:i=100}=e;this._options={target:t,ignoreEditableTargets:o,maxHistoryLength:i};}getHistoryManager(){return this._history}startBatch(){this._batchCommitTimer!==null&&(globalThis.clearTimeout(this._batchCommitTimer),this._batchCommitTimer=null),this._isBatchMode=true,this._batchBuffer=[],this._debug("batch started");}commitBatch(){this._batchCommitTimer!==null&&(globalThis.clearTimeout(this._batchCommitTimer),this._batchCommitTimer=null),this._finishBatch();}isBatchMode(){return this._isBatchMode}onAttach(e){this._core=e,this._options.target.addEventListener("keydown",this._onKeyDown),e.eventBus.on("node:created",this._onNodeCreated),e.eventBus.on("node:removed",this._onNodeRemoved),e.eventBus.on("node:transformed",this._onNodeTransformed),e.eventBus.on("node:zIndexChanged",this._onZIndexChanged),e.eventBus.on("group:created",this._onGroupCreated),e.eventBus.on("group:ungrouped",this._onGroupUngrouped);let t=e.nodes.world,o=e.nodes.layer;t.on("dragstart.history",this._onDragStart),t.on("dragend.history",this._onDragEnd),o.on("transformstart.history",this._onTransformStart),o.on("transformend.history",this._onTransformEnd),this._debug("attached");}onDetach(e){this._options.target.removeEventListener("keydown",this._onKeyDown),e.eventBus.off("node:created",this._onNodeCreated),e.eventBus.off("node:removed",this._onNodeRemoved),e.eventBus.off("node:transformed",this._onNodeTransformed),e.eventBus.off("node:zIndexChanged",this._onZIndexChanged),e.eventBus.off("group:created",this._onGroupCreated),e.eventBus.off("group:ungrouped",this._onGroupUngrouped),e.nodes.world.off(".history"),e.nodes.layer.off(".history"),this._core=void 0,this._dragStartStateCache.clear(),this._debug("detached");}_isEditableTarget(e){if(!e||!(e instanceof HTMLElement))return false;let t=e.tagName.toLowerCase();return !!(t==="input"||t==="textarea"||e.isContentEditable)}_finishBatch(){if(!this._isBatchMode||this._batchBuffer.length===0){this._isBatchMode=false,this._batchBuffer=[];return}let e={type:"batch",nodeId:"",before:null,after:null,timestamp:Date.now(),children:[...this._batchBuffer]};this._debug("batch recorded",{childCount:this._batchBuffer.length}),this._history.push(e),this._trimHistoryIfNeeded(),this._isBatchMode=false,this._batchBuffer=[];}_performUndo(){if(!this._core)return;let e=this._history.undo();if(!e){this._debug("undo","nothing to undo");return}this._isUndoRedoInProgress=true;try{this._applyActionState(e,"before"),this._debug("undo applied",e);}finally{this._isUndoRedoInProgress=false;}this._core.stage.batchDraw();}_performRedo(){if(!this._core)return;let e=this._history.redo();if(!e){this._debug("redo","nothing to redo");return}this._isUndoRedoInProgress=true;try{this._applyActionState(e,"after"),this._debug("redo applied",e);}finally{this._isUndoRedoInProgress=false;}this._core.stage.batchDraw();}_applyActionState(e,t){if(!this._core)return;let o=t==="before"?e.before:e.after;switch(e.type){case "create":if(t==="before"){let i=this._core.nodes.findById(e.nodeId);i&&this._core.nodes.remove(i);}else o&&this._recreateNode(o);break;case "remove":if(t==="before")o&&this._recreateNode(o);else {let i=this._core.nodes.findById(e.nodeId);i&&this._core.nodes.remove(i);}break;case "transform":if(o&&typeof o=="object"){let i=this._core.nodes.findById(e.nodeId);this._debug("transform apply",{nodeId:e.nodeId,nodeFound:!!i,state:o}),i&&this._applyTransformState(i,o);}break;case "zIndex":if(o&&typeof o=="object"&&"zIndex"in o){let i=this._core.nodes.findById(e.nodeId);i&&i.getKonvaNode().zIndex(o.zIndex);}break;case "group":this._applyGroupAction(e,t);break;case "ungroup":this._applyUngroupAction(e,t);break;case "batch":if(e.children){let i=t==="before"?[...e.children].reverse():e.children;for(let s of i)this._applyActionState(s,t);}break;default:this._debug("unknown action type",e.type);}}_applyTransformState(e,t){let o=e.getKonvaNode();this._debug("applyTransformState",{nodeId:e.id,current:{x:o.x(),y:o.y(),rotation:o.rotation(),scaleX:o.scaleX(),scaleY:o.scaleY()},target:t}),typeof t.x=="number"&&o.x(t.x),typeof t.y=="number"&&o.y(t.y),typeof t.width=="number"&&typeof o.width=="function"&&o.width(t.width),typeof t.height=="number"&&typeof o.height=="function"&&o.height(t.height),typeof t.rotation=="number"&&o.rotation(t.rotation),typeof t.scaleX=="number"&&o.scaleX(t.scaleX),typeof t.scaleY=="number"&&o.scaleY(t.scaleY);let i=o;typeof t.cornerRadius=="number"&&typeof i.cornerRadius=="function"&&i.cornerRadius(t.cornerRadius),this._dragStartStateCache.set(e.id,this._captureTransformState(e));}_applyGroupAction(e,t){if(this._core){if(t==="before"){let o=this._core.nodes.findById(e.nodeId);if(o&&e.before){let i=e.before;this._core.nodes.remove(o);for(let s of i.childStates)this._recreateNode(s);}}else if(e.after){let o=e.after;this._recreateNode(o);}}}_applyUngroupAction(e,t){if(this._core)if(t==="before"){if(e.before){let o=e.before;this._recreateNode(o);}}else {let o=this._core.nodes.findById(e.nodeId);if(o&&e.after){let i=e.after;this._core.nodes.remove(o);for(let s of i.childStates)this._recreateNode(s);}}}_recreateNode(e){if(!this._core)return null;let{nodeType:t,attrs:o}=e,{id:i,zIndex:s,...r}=o;try{let l=null;switch(t){case "shape":l=this._core.nodes.addShape(r);break;case "text":l=this._core.nodes.addText(r);break;case "circle":l=this._core.nodes.addCircle(r);break;case "ellipse":l=this._core.nodes.addEllipse(r);break;case "arc":l=this._core.nodes.addArc(r);break;case "star":l=this._core.nodes.addStar(r);break;case "arrow":l=this._core.nodes.addArrow(r);break;case "ring":l=this._core.nodes.addRing(r);break;case "regularPolygon":case "regularpolygon":l=this._core.nodes.addRegularPolygon(r);break;case "image":l=this._core.nodes.addImage(r);break;case "group":{if(l=this._core.nodes.addGroup(r),e.children&&e.children.length>0){let d=l.getKonvaNode();for(let c of e.children){let h=this._recreateNode(c);h&&h.getKonvaNode().moveTo(d);}}break}default:return this._debug("recreateNode",`unknown type: ${t}`),null}if(e.parentId){let d=this._core.nodes.findById(e.parentId);if(d){let c=d.getKonvaNode();l.getKonvaNode().moveTo(c),this._debug("recreateNode - moved to parent",{nodeId:l.id,parentId:e.parentId});}}return this._debug("recreateNode",{nodeType:t,nodeId:l.id,parentId:e.parentId}),l}catch(l){return this._debug("recreateNode error",l),null}}_scheduleBatchCommit(){this._batchCommitTimer!==null&&globalThis.clearTimeout(this._batchCommitTimer),this._batchCommitTimer=globalThis.setTimeout(()=>{this._batchCommitTimer=null,this._finishBatch();},50);}_serializeNode(e){let t=e.getKonvaNode(),o=t.getAttrs(),i=this._getNodeType(t),s={nodeType:i,nodeId:e.id,attrs:{...o}},r=t.getParent();if(r&&this._core){let l=this._findBaseNodeByKonva(r);if(l&&l.id!==e.id){let d=this._core.nodes.world;r!==d&&(s.parentId=l.id);}}if(i==="group"){let d=t.getChildren();s.children=[];for(let c of d){let h=this._findBaseNodeByKonva(c);h&&s.children.push(this._serializeNode(h));}}return s}_captureTransformState(e){let t=e.getKonvaNode(),o=t.getAbsoluteTransform().decompose(),i={absX:o.x,absY:o.y,absRotation:o.rotation,absScaleX:o.scaleX,absScaleY:o.scaleY,x:t.x(),y:t.y(),rotation:t.rotation(),scaleX:t.scaleX(),scaleY:t.scaleY()};typeof t.width=="function"&&(i.width=t.width()),typeof t.height=="function"&&(i.height=t.height());let s=t;return typeof s.cornerRadius=="function"&&(i.cornerRadius=s.cornerRadius()),i}_buildAfterState(e,t){let o=e.getKonvaNode(),i=t.x??o.x(),s=t.y??o.y(),r=t.rotation??o.rotation(),l=t.scaleX??o.scaleX(),d=t.scaleY??o.scaleY(),c={absX:i,absY:s,absRotation:r,absScaleX:l,absScaleY:d,x:i,y:s,rotation:r,scaleX:l,scaleY:d};typeof o.width=="function"&&(c.width=t.width??o.width()),typeof o.height=="function"&&(c.height=t.height??o.height());let h=o;return typeof h.cornerRadius=="function"&&(c.cornerRadius=h.cornerRadius()),c}_getNodeType(e){let t=e.getClassName();return {Rect:"shape",Circle:"circle",Ellipse:"ellipse",Text:"text",Image:"image",Group:"group",Arc:"arc",Star:"star",Arrow:"arrow",Ring:"ring",RegularPolygon:"regularPolygon"}[t]??t.toLowerCase()}_findBaseNodeByKonva(e){if(!this._core)return null;for(let o of this._core.nodes.list())if(o.getKonvaNode()===e)return o;let t=e.getParent();for(;t;){for(let o of this._core.nodes.list())if(o.getKonvaNode()===t)return o;t=t.getParent();}return null}_statesEqual(e,t){let i=["absX","absY","absRotation","absScaleX","absScaleY"];for(let r of i){let l=e[r],d=t[r];if(typeof l=="number"&&typeof d=="number"){if(Math.abs(l-d)>.001)return false}else if(l!==d)return false}let s=["width","height","cornerRadius"];for(let r of s)if(e[r]!==t[r])return false;return true}_trimHistoryIfNeeded(){if(!(this._options.maxHistoryLength<=0))for(;this._history.length>this._options.maxHistoryLength;){this._history.pop(0);break}}_debug(e,t){}};var dt=class extends H{constructor(e){super();a(this,"_core");a(this,"_layer");a(this,"_image");a(this,"_src");a(this,"_width");a(this,"_height");a(this,"_opacity");this._src=e.src,this._width=e.width,this._height=e.height,this._opacity=e.opacity??1;}onAttach(e){this._core=e,this._layer=new M.Layer({name:"logo-layer",listening:false}),this._core.stage.add(this._layer),this._image=new M.Image({image:void 0,width:this._width,height:this._height,name:"logo-background",listening:false,opacity:this._opacity}),this._layer.add(this._image),this.setSource(this._src);let t=this._core.stage;t.on("resize.logo",()=>{this._layout();}),t.on("xChange.logo yChange.logo scaleXChange.logo scaleYChange.logo",()=>{this._layout();}),this._layout(),this._core.stage.batchDraw();}onDetach(e){e.stage.off(".logo"),this._image&&this._image.destroy(),this._layer&&this._layer.destroy();}setOpacity(e){this._opacity=e,this._image&&this._core&&(this._image.opacity(e),this._core.stage.batchDraw());}setSize({width:e,height:t}){this._width=e,this._height=t,this._layout(),this._core&&this._core.stage.batchDraw();}setSource(e){this._src=e,this._loadImageFromString(e);}_setImage(e){this._image&&(this._image.image(e),this._layout(),this._core&&this._core.stage.batchDraw());}_loadImageFromString(e){M.Image.fromURL(e,t=>{let o=t.image();o&&this._setImage(o);});}_layout(){if(!this._core||!this._image)return;let e=this._core.stage,t=e.width(),o=e.height(),i=e.scaleX(),s=e.position(),r={x:Math.floor(t/2),y:Math.floor(o/2)};this._image.scale({x:1/i,y:1/i});let l=this._width,d=this._height;this._image.size({width:l,height:d}),this._image.offset({x:l/2,y:d/2});let c=(r.x-s.x)/i,h=(r.y-s.y)/i;this._image.position({x:c,y:h}),this._image.opacity(this._opacity),this._layer&&this._layer.moveToBottom();}};var ht=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_clipboard",null);a(this,"_selectionPlugin");a(this,"_onKeyDown",e=>{if(!this._core)return;if(!this._selectionPlugin){let i=this._core.plugins.list().find(s=>s instanceof ve);i&&(this._selectionPlugin=i);}if(!this._selectionPlugin||this._options.ignoreEditableTargets&&this._isEditableTarget(e.target))return;let t=e.ctrlKey||e.metaKey,o=e.shiftKey;if(!t&&!o&&e.code==="Enter"){let i=this._getSelectedNodes();if(i.length===1&&i[0]instanceof xe){e.preventDefault(),i[0].startEdit();return}}if(t&&e.code==="KeyC"){e.preventDefault(),this._handleCopy();return}if(t&&e.code==="KeyX"){e.preventDefault(),this._handleCut();return}if(t&&e.code==="KeyV"){e.preventDefault(),this._handlePaste();return}if(e.code==="Delete"||e.code==="Backspace"){e.preventDefault(),this._handleDelete();return}if(t&&o&&e.code==="BracketRight"){e.preventDefault(),this._handleMoveToTop();return}if(t&&o&&e.code==="BracketLeft"){e.preventDefault(),this._handleMoveToBottom();return}if(t&&(e.code==="BracketRight"||o&&e.code==="Equal")){e.preventDefault(),this._handleMoveUp();return}if(t&&(e.code==="BracketLeft"||o&&e.code==="Minus")){e.preventDefault(),this._handleMoveDown();return}});let{target:t=globalThis,ignoreEditableTargets:o=true}=e;this._options={target:t,ignoreEditableTargets:o};}onAttach(e){this._core=e,this._options.target.addEventListener("keydown",this._onKeyDown);}onDetach(e){this._options.target.removeEventListener("keydown",this._onKeyDown),this._core=void 0,this._selectionPlugin=void 0,this._clipboard=null;}_isEditableTarget(e){if(!e||!(e instanceof HTMLElement))return false;let t=e.tagName.toLowerCase();return !!(t==="input"||t==="textarea"||e.isContentEditable)}_handleCopy(){let e=this._getSelectedNodes();if(e.length===0)return;let t=e.map(i=>this._serializeNode(i)),o=this._computeSelectionWorldCenter(e);this._clipboard={nodes:t,center:o},this._core&&this._core.eventBus.emit("clipboard:copy",e);}_handleCut(){let e=this._getSelectedNodes();if(e.length===0)return;let t=e.map(i=>this._serializeNode(i)),o=this._computeSelectionWorldCenter(e);this._clipboard={nodes:t,center:o},this._deleteNodes(e),this._core&&this._core.eventBus.emit("clipboard:cut",e);}_handlePaste(){if(!this._core||!this._clipboard||this._clipboard.nodes.length===0)return;let e=this._getPastePosition(),t=this._getClipboardCenter(),o=[];for(let i of this._clipboard.nodes){let s=i.position.x-t.x,r=i.position.y-t.y,l=this._deserializeNode(i,{x:e.x+s,y:e.y+r});l&&o.push(l);}o.length>0&&this._core.eventBus.emit("clipboard:paste",o),this._core.nodes.layer.batchDraw();}_handleDelete(){let e=this._getSelectedNodes();e.length!==0&&this._deleteNodes(e);}_getSelectedNodes(){if(!this._selectionPlugin)return [];let e=this._selectionPlugin._tempMultiGroup;if(e&&typeof e.getChildren=="function"&&this._core){let i=e.getChildren(),s=this._core.nodes.list(),r=new Set;for(let l of i){let d=s.find(c=>c.getKonvaNode()===l);d&&r.add(d);}if(r.size>0)return Array.from(r)}let t=this._selectionPlugin._tempMultiSet;if(t&&t.size>0)return Array.from(t);let o=this._selectionPlugin._selected;return o?[o]:[]}_deleteNodes(e){if(!this._core)return;if(this._selectionPlugin){let o=this._selectionPlugin;typeof o._destroyTempMulti=="function"&&o._destroyTempMulti(),typeof o._clearSelection=="function"&&o._clearSelection();}let t=this._core.plugins.get("HistoryPlugin");e.length>1&&t&&t.startBatch();for(let o of e)this._core.nodes.remove(o);e.length>1&&t&&t.commitBatch();}_serializeNode(e){let t=e.getKonvaNode(),o=t.getAttrs(),i=this._getNodeTypeFromKonva(t),s={x:0,y:0};if(this._core){let d=t.getAbsolutePosition(),h=this._core.nodes.world.getAbsoluteTransform().copy().invert().point(d);s={x:h.x,y:h.y};}let r={type:i,config:{...o,id:void 0},position:s};if(i==="group"){let d=t.getChildren(),c=[];for(let h of d){let u=this._serializeKonvaNode(h);u&&c.push(u);}c.length>0&&(r.children=c);}return r}_serializeKonvaNode(e){if(!this._core)return null;let t=e.getAttrs(),i=e.getClassName().toLowerCase();i==="rect"&&(i="shape");let s={type:i,config:{...t,id:void 0},position:{x:e.x(),y:e.y()}};if(e instanceof M.Group){let r=e.getChildren(),l=[];for(let d of r){let c=this._serializeKonvaNode(d);c&&l.push(c);}l.length>0&&(s.children=l);}return s}_getNodeTypeFromKonva(e){let t=e.getClassName();return {Rect:"shape",Circle:"circle",Ellipse:"ellipse",Text:"text",Image:"image",Group:"group",Arc:"arc",Star:"star",Arrow:"arrow",Ring:"ring",RegularPolygon:"regularPolygon",Label:"label"}[t]??t.toLowerCase()}_deserializeNode(e,t){if(!this._core)return null;let{zIndex:o,...i}=e.config,s={...i,x:t.x,y:t.y};try{let r=null;switch(e.type){case "shape":r=this._core.nodes.addShape(s);break;case "text":r=this._core.nodes.addText(s);break;case "circle":r=this._core.nodes.addCircle(s);break;case "ellipse":r=this._core.nodes.addEllipse(s);break;case "arc":r=this._core.nodes.addArc(s);break;case "star":r=this._core.nodes.addStar(s);break;case "arrow":r=this._core.nodes.addArrow(s);break;case "ring":r=this._core.nodes.addRing(s);break;case "regularPolygon":case "regularpolygon":r=this._core.nodes.addRegularPolygon(s);break;case "image":r=this._core.nodes.addImage(s);break;case "label":return globalThis.console.warn("LabelNode is not supported for copy/paste yet"),null;case "group":{r=this._core.nodes.addGroup(s);let d=r.getKonvaNode();if(e.config.scaleX!==void 0&&d.scaleX(e.config.scaleX),e.config.scaleY!==void 0&&d.scaleY(e.config.scaleY),e.config.rotation!==void 0&&d.rotation(e.config.rotation),e.config.skewX!==void 0&&d.skewX(e.config.skewX),e.config.skewY!==void 0&&d.skewY(e.config.skewY),e.config.offsetX!==void 0&&d.offsetX(e.config.offsetX),e.config.offsetY!==void 0&&d.offsetY(e.config.offsetY),e.children&&e.children.length>0)for(let c of e.children){let h=this._deserializeNode(c,{x:c.position.x,y:c.position.y});if(h){let u=h.getKonvaNode();typeof u.draggable=="function"&&u.draggable(!1),u.moveTo(d);}}break}default:return globalThis.console.warn(`Unknown node type: ${e.type}`),null}let l=r.getKonvaNode();return e.config.scaleX!==void 0&&l.scaleX(e.config.scaleX),e.config.scaleY!==void 0&&l.scaleY(e.config.scaleY),e.config.rotation!==void 0&&l.rotation(e.config.rotation),e.config.skewX!==void 0&&l.skewX(e.config.skewX),e.config.skewY!==void 0&&l.skewY(e.config.skewY),e.config.offsetX!==void 0&&l.offsetX(e.config.offsetX),e.config.offsetY!==void 0&&l.offsetY(e.config.offsetY),r}catch(r){return globalThis.console.error("Failed to deserialize node:",r),null}}_getPastePosition(){if(!this._core)return {x:0,y:0};let t=this._core.stage.getPointerPosition();if(t&&this._isPointerOnScreen(t)){let s=this._core.nodes.world.getAbsoluteTransform().copy().invert().point(t);return {x:s.x,y:s.y}}return this._getScreenCenter()}_isPointerOnScreen(e){if(!this._core)return false;let t=this._core.stage,o=t.width(),i=t.height();return e.x>=0&&e.x<=o&&e.y>=0&&e.y<=i}_getScreenCenter(){if(!this._core)return {x:0,y:0};let e=this._core.stage,t=this._core.nodes.world,o=e.width()/2,i=e.height()/2,r=t.getAbsoluteTransform().copy().invert().point({x:o,y:i});return {x:r.x,y:r.y}}_getClipboardCenter(){if(!this._clipboard||this._clipboard.nodes.length===0)return {x:0,y:0};if(this._clipboard.center)return this._clipboard.center;let e=0,t=0;for(let o of this._clipboard.nodes)e+=o.position.x,t+=o.position.y;return {x:e/this._clipboard.nodes.length,y:t/this._clipboard.nodes.length}}_computeSelectionWorldCenter(e){if(!this._core||e.length===0)return {x:0,y:0};let t=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(let u of e){let f=u.getKonvaNode().getClientRect({skipShadow:true,skipStroke:true});t=Math.min(t,f.x),o=Math.min(o,f.y),i=Math.max(i,f.x+f.width),s=Math.max(s,f.y+f.height);}if(!isFinite(t)||!isFinite(o)||!isFinite(i)||!isFinite(s))return {x:0,y:0};let r=(t+i)/2,l=(o+s)/2,h=this._core.nodes.world.getAbsoluteTransform().copy().invert().point({x:r,y:l});return {x:h.x,y:h.y}}_handleMoveUp(){let e=this._getSelectedNodes();if(e.length!==0){for(let t of e){let o=t.getKonvaNode();if(this._isNodeInsidePermanentGroup(o))continue;let i=o.zIndex();o.moveUp();let s=o.zIndex();this._syncGroupZIndex(o),this._core&&i!==s&&this._core.eventBus.emit("node:zIndexChanged",t,i,s);}this._core&&(this._core.nodes.layer.draw(),this._core.stage.batchDraw());}}_handleMoveDown(){let e=this._getSelectedNodes();if(e.length!==0){for(let t=e.length-1;t>=0;t--){let o=e[t];if(!o)continue;let i=o.getKonvaNode();if(this._isNodeInsidePermanentGroup(i))continue;let s=i.zIndex();i.moveDown();let r=i.zIndex();this._syncGroupZIndex(i),this._core&&s!==r&&this._core.eventBus.emit("node:zIndexChanged",o,s,r);}this._core&&(this._core.nodes.layer.draw(),this._core.stage.batchDraw());}}_handleMoveToTop(){let e=this._getSelectedNodes();if(e.length===0)return;let t=[...e].sort((o,i)=>{let s=o.getKonvaNode(),r=i.getKonvaNode();return s.zIndex()-r.zIndex()});for(let o of t){let i=o.getKonvaNode();if(this._isNodeInsidePermanentGroup(i))continue;let s=i.zIndex();i.moveToTop();let r=i.zIndex();this._syncGroupZIndex(i),this._core&&s!==r&&this._core.eventBus.emit("node:zIndexChanged",o,s,r);}this._core&&(this._core.nodes.layer.draw(),this._core.stage.batchDraw());}_handleMoveToBottom(){let e=this._getSelectedNodes();if(e.length===0)return;let t=[...e].sort((o,i)=>{let s=o.getKonvaNode();return i.getKonvaNode().zIndex()-s.zIndex()});for(let o of t){let i=o.getKonvaNode();if(this._isNodeInsidePermanentGroup(i))continue;let s=i.zIndex();i.moveToBottom();let r=i.zIndex();this._syncGroupZIndex(i),this._core&&s!==r&&this._core.eventBus.emit("node:zIndexChanged",o,s,r);}this._core&&(this._core.nodes.layer.draw(),this._core.stage.batchDraw());}_isNodeInsidePermanentGroup(e){if(e instanceof M.Group)return false;let t=e.getParent();return !(!t||!(t instanceof M.Group)||t===this._core?.nodes.world)}_syncGroupZIndex(e){let t=e.getParent();t&&(e instanceof M.Group||t instanceof M.Group&&t.name());}};var ge=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_guidesLayer",null);a(this,"_guides",[]);a(this,"_activeGuide",null);a(this,"_draggingGuide",null);a(this,"_rulerLayerCache",null);a(this,"_updateScheduled",false);a(this,"_dragMoveScheduled",false);a(this,"_batchDrawScheduled",false);let{guideColor:t="#8e3e2c",activeColor:o="#2b83ff",rulerThicknessPx:i=30,snapToGrid:s=true,gridStep:r=1}=e;this._options={guideColor:t,activeColor:o,rulerThicknessPx:i,snapToGrid:s,gridStep:r};}onAttach(e){if(this._core=e,!e.stage.findOne(".ruler-layer"))throw new Error("RulerGuidesPlugin requires RulerPlugin to be added to the CoreEngine first. Please add RulerPlugin before RulerGuidesPlugin.");this._guidesLayer=new M.Layer({name:"guides-layer"}),e.stage.add(this._guidesLayer),this._guidesLayer.moveToTop();let o=e.stage,i=this._options.rulerThicknessPx;o.on("mousedown.ruler-guides",()=>{let r=o.getPointerPosition();if(!r)return;let l=o.getIntersection(r);l&&(l.name()==="guide-h"||l.name()==="guide-v")||(r.y<=i&&r.x>=i?this._startCreateGuide("h"):r.x<=i&&r.y>=i?this._startCreateGuide("v"):this._setActiveGuide(null));}),o.on("mousemove.ruler-guides",()=>{let r=o.getPointerPosition();if(!r)return;let l=o.getIntersection(r);if(l){let d=l.name();if(d==="guide-h"||d==="guide-v"||d.includes("_anchor")||d.includes("rotater")||l.draggable())return}r.y<=i&&r.x>=i?o.container().style.cursor="ns-resize":r.x<=i&&r.y>=i?o.container().style.cursor="ew-resize":this._draggingGuide||(o.container().style.cursor="default");}),this._rulerLayerCache=e.stage.findOne(".ruler-layer"),e.nodes.world.on("xChange.ruler-guides yChange.ruler-guides scaleXChange.ruler-guides scaleYChange.ruler-guides",()=>{this._scheduleUpdate();}),o.on("resize.ruler-guides",()=>{this._scheduleUpdate();}),e.stage.batchDraw();}onDetach(e){e.stage.off(".ruler-guides"),e.nodes.world.off(".ruler-guides"),this._guidesLayer&&(this._guidesLayer.destroy(),this._guidesLayer=null),this._guides=[],this._activeGuide=null,this._draggingGuide=null;}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=true,globalThis.requestAnimationFrame(()=>{this._updateScheduled=false,this._updateGuidesPositions();}));}_updateGuidesPositions(){if(!this._core||this._guides.length===0)return;let e=this._core.nodes.world,t=e.scaleX(),o=e.x(),i=e.y(),s=this._core.stage.width(),r=this._core.stage.height(),l=[0,0,s,0],d=[0,0,0,r];for(let c of this._guides){let h=c.worldCoord;if(c.name()==="guide-h"){let p=i+h*t;c.position({x:0,y:p}),c.points(l);}else {let p=o+h*t;c.position({x:p,y:0}),c.points(d);}}this._guidesLayer?.batchDraw();}_snapToGrid(e){if(!this._options.snapToGrid)return Math.round(e);let t=this._options.gridStep;return Math.round(e/t)*t}_scheduleBatchDraw(){this._batchDrawScheduled||(this._batchDrawScheduled=true,globalThis.requestAnimationFrame(()=>{this._batchDrawScheduled=false,this._core?.stage.batchDraw();}));}_startCreateGuide(e){if(!this._core||!this._guidesLayer)return;let t=this._core.stage,o=this._core.nodes.world,i=o.scaleX(),s=t.getPointerPosition();if(!s)return;let r=e==="h"?(s.y-o.y())/i:(s.x-o.x())/i,l=this._snapToGrid(r),d=new M.Line({name:e==="h"?"guide-h":"guide-v",stroke:this._options.guideColor,strokeWidth:1,opacity:1,draggable:true,hitStrokeWidth:8,dragBoundFunc:p=>{if(!this._core)return p;let f=this._core.nodes.world,m=f.scaleX();if(e==="h"){let v=(p.y-f.y())/m,_=this._snapToGrid(v);return {x:0,y:f.y()+_*m}}else {let v=(p.x-f.x())/m,_=this._snapToGrid(v);return {x:f.x()+_*m,y:0}}}});d.worldCoord=l,d.on("mouseenter",()=>{this._core&&(this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize"),this._scheduleBatchDraw();}),d.on("mouseleave",()=>{this._core&&!this._draggingGuide&&(this._core.stage.container().style.cursor="default"),this._scheduleBatchDraw();}),d.on("click",()=>{this._setActiveGuide(d);}),d.on("dragstart",()=>{let p=d;this._draggingGuide={type:e,line:p},this._setActiveGuide(p),this._core&&(this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize");}),d.on("dragmove",()=>{!this._core||this._dragMoveScheduled||(this._dragMoveScheduled=true,globalThis.requestAnimationFrame(()=>{if(this._dragMoveScheduled=false,!this._core)return;let p=this._core.nodes.world,f=p.scaleX(),m=d.getAbsolutePosition(),v=e==="h"?(m.y-p.y())/f:(m.x-p.x())/f,_=this._snapToGrid(v);d.worldCoord=_,this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize",this._rulerLayerCache&&this._rulerLayerCache.batchDraw();}));}),d.on("dragend",()=>{this._draggingGuide=null,this._core&&(this._core.stage.container().style.cursor=e==="h"?"ns-resize":"ew-resize");});let c=d;this._guidesLayer.add(c),this._guides.push(c),this._setActiveGuide(c),e==="h"?(d.position({x:0,y:o.y()+l*i}),d.points([0,0,t.width(),0])):(d.position({x:o.x()+l*i,y:0}),d.points([0,0,0,t.height()])),this._draggingGuide={type:e,line:c};let h=()=>{if(!this._draggingGuide||!this._core)return;let p=this._core.stage.getPointerPosition();if(!p)return;let f=this._core.nodes.world,m=f.scaleX(),v=e==="h"?(p.y-f.y())/m:(p.x-f.x())/m,_=this._snapToGrid(v);d.worldCoord=_,e==="h"?(d.position({x:0,y:f.y()+_*m}),d.points([0,0,this._core.stage.width(),0])):(d.position({x:f.x()+_*m,y:0}),d.points([0,0,0,this._core.stage.height()])),this._scheduleBatchDraw();},u=()=>{this._draggingGuide=null,this._core&&(this._core.stage.off("mousemove.guide-create"),this._core.stage.off("mouseup.guide-create"));};t.on("mousemove.guide-create",h),t.on("mouseup.guide-create",u),this._scheduleBatchDraw();}_setActiveGuide(e){this._activeGuide&&this._activeGuide!==e&&(this._activeGuide.stroke(this._options.guideColor),this._activeGuide.strokeWidth(1)),this._activeGuide=e,e&&(e.stroke(this._options.activeColor),e.strokeWidth(2)),this._rulerLayerCache&&this._rulerLayerCache.batchDraw(),this._core?.stage.fire("guidesChanged.ruler"),this._scheduleBatchDraw();}getActiveGuide(){return this._activeGuide}getActiveGuideInfo(){if(!this._activeGuide)return null;let e=this._activeGuide.worldCoord;return {type:this._activeGuide.name()==="guide-h"?"h":"v",coord:e}}removeActiveGuide(){this._activeGuide&&(this._activeGuide.destroy(),this._guides=this._guides.filter(e=>e!==this._activeGuide),this._activeGuide=null,this._scheduleBatchDraw());}getGuides(){return [...this._guides]}clearGuides(){this._guides.forEach(e=>e.destroy()),this._guides=[],this._activeGuide=null,this._scheduleBatchDraw();}};var Ce=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_highlightLayer",null);a(this,"_hGroup",null);a(this,"_vGroup",null);a(this,"_hHighlights",[]);a(this,"_vHighlights",[]);a(this,"_updateDebounce",new _e);a(this,"_transformersCache",[]);a(this,"_cacheInvalidated",true);let{highlightColor:t="#2b83ff",highlightOpacity:o=.3,rulerThicknessPx:i=30}=e;this._options={highlightColor:t,highlightOpacity:o,rulerThicknessPx:i};}onAttach(e){this._core=e;let t=e.stage.findOne(".ruler-layer");if(!t){globalThis.console.warn("RulerHighlightPlugin: RulerPlugin not found. Please add RulerPlugin before RulerHighlightPlugin. Plugin will not work without RulerPlugin.");return}this._highlightLayer=t;let o=t.find("Group");if(o.length>=2)this._hGroup=o[0],this._vGroup=o[1];else {globalThis.console.warn("RulerHighlightPlugin: Could not find ruler groups");return}e.nodes.world.on("xChange.ruler-highlight yChange.ruler-highlight scaleXChange.ruler-highlight scaleYChange.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("resize.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("transform.ruler-highlight transformend.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("click.ruler-highlight",()=>{this._invalidateCache(),this._scheduleUpdate();}),e.stage.on("dragmove.ruler-highlight",()=>{this._scheduleUpdate();}),e.stage.on("mouseup.ruler-highlight",()=>{this._invalidateCache(),this._scheduleUpdate();}),this._updateHighlights();}onDetach(e){try{e.stage.off(".ruler-highlight"),e.nodes.world.off(".ruler-highlight");}catch{}this._hHighlights.forEach(t=>{try{t.destroy();}catch{}}),this._vHighlights.forEach(t=>{try{t.destroy();}catch{}}),this._hHighlights=[],this._vHighlights=[],this._highlightLayer=null,this._hGroup=null,this._vGroup=null;}_scheduleUpdate(){this._updateDebounce.schedule(()=>{this._updateHighlights();});}_invalidateCache(){this._cacheInvalidated=true;}_updateHighlights(){if(!this._core||!this._highlightLayer)return;for(let m of this._hHighlights)m.destroy();this._hHighlights=[];for(let m of this._vHighlights)m.destroy();this._vHighlights=[];let e=this._getSelectedKonvaNodes();if(e.length===0){this._highlightLayer.batchDraw();return}let t=this._core.stage,o=this._core.nodes.world,i=t.width(),s=t.height(),r=this._options.rulerThicknessPx,l=o.scaleX(),d=o.x(),c=o.y(),h=[],u=[];for(let m of e){let v=m.getClientRect({relativeTo:o}),_=d+v.x*l,g=d+(v.x+v.width)*l,b=c+v.y*l,y=c+(v.y+v.height)*l;if(_<i&&g>r){let N=Math.max(r,_),x=Math.min(i,g);N<x&&h.push({start:N,end:x});}if(b<s&&y>r){let N=Math.max(r,b),x=Math.min(s,y);N<x&&u.push({start:N,end:x});}}let p=this._mergeSegments(h),f=this._mergeSegments(u);if(this._hGroup)for(let m of p){let v=new M.Rect({x:m.start,y:0,width:m.end-m.start,height:r,fill:this._options.highlightColor,opacity:this._options.highlightOpacity,listening:false,name:"ruler-highlight-h"});this._hGroup.add(v),v.setZIndex(1),this._hHighlights.push(v);}if(this._vGroup)for(let m of f){let v=new M.Rect({x:0,y:m.start,width:r,height:m.end-m.start,fill:this._options.highlightColor,opacity:this._options.highlightOpacity,listening:false,name:"ruler-highlight-v"});this._vGroup.add(v),v.setZIndex(1),this._vHighlights.push(v);}this._highlightLayer.batchDraw();}_collectNodes(e,t){let o=e.getClassName(),i=e.name(),r=["overlay-hit","ruler-","guide-","_anchor","back","rotater"].some(l=>i.includes(l));if(!(o==="Transformer"||o==="Layer"||r))if(o==="Group"){let d=e.getChildren();if(d.length===0)return;for(let c of d)this._collectNodes(c,t);}else t.includes(e)||t.push(e);}_mergeSegments(e){if(e.length===0)return [];let t=e.slice().sort((r,l)=>r.start-l.start),o=t[0];if(!o)return [];let i=[],s={start:o.start,end:o.end};for(let r=1;r<t.length;r++){let l=t[r];l&&(l.start<=s.end+1?s.end=Math.max(s.end,l.end):(i.push(s),s={start:l.start,end:l.end}));}return i.push(s),i}_getSelectedKonvaNodes(){if(!this._core)return [];let e=[];try{this._cacheInvalidated&&(this._transformersCache=this._core.stage.find("Transformer"),this._cacheInvalidated=!1);for(let o of this._transformersCache){let i=o.nodes();for(let s of i)e.includes(s)||e.push(s);}}catch{}let t=[];for(let o of e)this._collectNodes(o,t);return t}update(){this._updateHighlights();}};var Te=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_visible",true);a(this,"_handleKeyDown",e=>{if(e.shiftKey&&(e.key==="r"||e.key==="R"||e.key==="\u043A"||e.key==="\u041A")){e.preventDefault(),this.toggle();return}(e.code==="Delete"||e.code==="Backspace")&&this.deleteActiveGuide()&&e.preventDefault();});let{enabled:t=true}=e;this._options={enabled:t};}onAttach(e){this._options.enabled&&(this._core=e,this._bindKeyboardEvents());}onDetach(e){this._unbindKeyboardEvents();}_bindKeyboardEvents(){globalThis.addEventListener("keydown",this._handleKeyDown);}_unbindKeyboardEvents(){globalThis.removeEventListener("keydown",this._handleKeyDown);}toggle(){this._visible?this.hide():this.show();}show(){if(!this._core)return;this._visible=true;let e=this._core.stage.findOne(".ruler-layer");e&&!e.isVisible()&&e.show();let t=this._core.stage.findOne(".guides-layer");t&&!t.isVisible()&&t.show(),this._core.stage.batchDraw();}hide(){if(!this._core)return;this._visible=false;let e=this._core.stage.findOne(".ruler-layer");e?.isVisible()&&e.hide();let t=this._core.stage.findOne(".guides-layer");t?.isVisible()&&t.hide(),this._core.stage.batchDraw();}isVisible(){return this._visible}deleteActiveGuide(){if(!this._core)return false;let e=this._core.plugins.list().find(t=>t instanceof ge);return e&&"getActiveGuide"in e&&"removeActiveGuide"in e&&e.getActiveGuide.call(e)?(e.removeActiveGuide.call(e),true):false}};var ct=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_layer",null);a(this,"_hGroup");a(this,"_vGroup");a(this,"_hBg");a(this,"_vBg");a(this,"_hTicksShape");a(this,"_vTicksShape");a(this,"_hBorder");a(this,"_vBorder");a(this,"_redrawScheduled",false);a(this,"_lastRedrawTime",0);a(this,"_redrawThrottleMs",16);a(this,"_panThrottleMs",32);a(this,"_cachedActiveGuide",null);a(this,"_cacheInvalidated",true);a(this,"_stepsCache",new Map);let{thicknessPx:t=30,fontFamily:o="Inter, Calibri, Arial, sans-serif",fontSizePx:i=10,color:s="#8c8c8c",bgColor:r="#2c2c2c",borderColor:l="#1f1f1f",enabled:d=true}=e;this._options={thicknessPx:t,fontFamily:o,fontSizePx:i,color:s,bgColor:r,borderColor:l,enabled:d};}_calculateNiceStep(e){if(!isFinite(e)||e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),o=e/t,i;return o<=1?i=1:o<=2?i=2:o<=5?i=5:i=10,i*t}_formatNumber(e){return Math.round(e).toString()}_getStepsConfig(e){let t=this._stepsCache.get(e);if(t)return t;let o=this._options.thicknessPx,s=50/e,r=this._calculateNiceStep(s);r<1&&(r=1);let l=r*e,d,c,h,u;l>=60?(d=r*10,c=r*5,h=r,u=r):l>=40?(d=r*10,c=r*5,h=r*5,u=r):(d=r*10,c=r*5,h=r*10,u=r);let p={step:r,stepPx:l,majorStep:d,mediumStep:c,labelStep:h,drawStep:u,drawStepEpsilon:u*.01,majorTickLength:o*.6,mediumTickLength:o*.4,minorTickLength:o*.25,fontString:`${String(this._options.fontSizePx)}px ${this._options.fontFamily}`};if(this._stepsCache.size>10){let f=this._stepsCache.keys().next().value;f!==void 0&&this._stepsCache.delete(f);}return this._stepsCache.set(e,p),p}onAttach(e){this._core=e,this._layer=new M.Layer({name:"ruler-layer",listening:true}),this._options.enabled&&e.stage.add(this._layer),this._hGroup=new M.Group({listening:true}),this._vGroup=new M.Group({listening:true}),this._layer.add(this._hGroup),this._layer.add(this._vGroup),this._hBg=new M.Rect({fill:this._options.bgColor,listening:true,name:"ruler-h-bg"}),this._vBg=new M.Rect({fill:this._options.bgColor,listening:true,name:"ruler-v-bg"}),this._hGroup.add(this._hBg),this._vGroup.add(this._vBg),this._hBorder=new M.Line({stroke:this._options.borderColor,strokeWidth:1,listening:false}),this._vBorder=new M.Line({stroke:this._options.borderColor,strokeWidth:1,listening:false}),this._hGroup.add(this._hBorder),this._vGroup.add(this._vBorder),this._hTicksShape=new M.Shape({listening:false,sceneFunc:i=>{let s=this._getActiveGuideInfo();this._drawHorizontalRuler(i,s);}}),this._hGroup.add(this._hTicksShape),this._vTicksShape=new M.Shape({listening:false,sceneFunc:i=>{let s=this._getActiveGuideInfo();this._drawVerticalRuler(i,s);}}),this._vGroup.add(this._vTicksShape);let t=e.stage,o=e.nodes.world;t.on("resize.ruler",()=>{this._scheduleRedraw();}),o.on("xChange.ruler yChange.ruler",()=>{this._invalidateGuideCache(),this._scheduleRedraw(true);}),o.on("scaleXChange.ruler scaleYChange.ruler",()=>{this._invalidateGuideCache(),this._scheduleRedraw(false);}),t.on("guidesChanged.ruler",()=>{this._invalidateGuideCache(),this._scheduleRedraw();}),this._redraw(),e.stage.batchDraw();}onDetach(e){e.stage.off(".ruler"),e.nodes.world.off(".ruler"),this._layer&&(this._layer.destroy(),this._layer=null);}_getActiveGuideInfo(){if(!this._core)return null;if(!this._cacheInvalidated)return this._cachedActiveGuide;let e=this._core.stage.findOne(".guides-layer");if(!e)return this._cachedActiveGuide=null,this._cacheInvalidated=false,null;let t=e.find("Line");for(let o of t){let i=o;if(i.strokeWidth()===2){let s=i.worldCoord,r=i.name()==="guide-h"?"h":"v";return this._cachedActiveGuide={type:r,coord:s},this._cacheInvalidated=false,this._cachedActiveGuide}}return this._cachedActiveGuide=null,this._cacheInvalidated=false,null}_invalidateGuideCache(){this._cacheInvalidated=true;}_drawRuler(e,t,o){if(!this._core)return;let i=this._core.stage,s=this._core.nodes.world,r=s.scaleX()||1e-9,l=this._options.thicknessPx,d=t==="h",c=d?i.width():i.height(),h=d?s.x():s.y(),u=o?.type===(d?"v":"h")?o.coord:null,p=this._getStepsConfig(r),{majorStep:f,mediumStep:m,labelStep:v,drawStep:_,drawStepEpsilon:g,majorTickLength:b,mediumTickLength:y,minorTickLength:N,fontString:x}=p;e.save();let w=-h/r,k=Math.floor(w/_)*_,T=[],A=[],R=[],D=[],B=null;for(let K=k;;K+=_){let L=h+K*r;if(L>c)break;if(L<0)continue;if(u!==null&&Math.abs(K-u)<g){B=L,D.push({pos:L,text:this._formatNumber(K)});continue}let j=Math.abs(K%f)<g,ae=!j&&Math.abs(K%m)<g;j?T.push(L):ae?A.push(L):R.push(L),Math.abs(K%v)<g&&D.push({pos:L,text:this._formatNumber(K)});}if(R.length>0){e.strokeStyle=this._options.color,e.globalAlpha=.4,e.lineWidth=1,e.beginPath();for(let K of R)d?(e.moveTo(K,l),e.lineTo(K,l-N)):(e.moveTo(l,K),e.lineTo(l-N,K));e.stroke();}if(A.length>0){e.strokeStyle=this._options.color,e.globalAlpha=.6,e.lineWidth=1,e.beginPath();for(let K of A)d?(e.moveTo(K,l),e.lineTo(K,l-y)):(e.moveTo(l,K),e.lineTo(l-y,K));e.stroke();}if(T.length>0){e.strokeStyle=this._options.color,e.globalAlpha=.9,e.lineWidth=1,e.beginPath();for(let K of T)d?(e.moveTo(K,l),e.lineTo(K,l-b)):(e.moveTo(l,K),e.lineTo(l-b,K));e.stroke();}if(B!==null&&(e.strokeStyle="#ff8c00",e.globalAlpha=1,e.lineWidth=2,e.beginPath(),d?(e.moveTo(B,l),e.lineTo(B,l-b)):(e.moveTo(l,B),e.lineTo(l-b,B)),e.stroke()),D.length>0){e.font=x,e.textBaseline="top",e.textAlign="left";for(let K of D){let L=K.pos===B;if(e.globalAlpha=L?1:.9,e.fillStyle=L?"#ff8c00":this._options.color,d)e.fillText(K.text,K.pos+4,4);else {let j=K.pos+4;e.setTransform(0,-1,1,0,4,j),e.fillText(K.text,0,0),e.setTransform(1,0,0,1,0,0);}}}if(u!==null){let K=h+u*r;if(K>=0&&K<=c&&!(Math.abs(u%_)<g))if(e.strokeStyle="#ff8c00",e.globalAlpha=1,e.lineWidth=2,e.beginPath(),d?(e.moveTo(K,l),e.lineTo(K,l-b)):(e.moveTo(l,K),e.lineTo(l-b,K)),e.stroke(),e.fillStyle="#ff8c00",e.font=x,e.textBaseline="top",e.textAlign="left",d)e.fillText(this._formatNumber(u),K+4,4);else {let j=K+4;e.setTransform(0,-1,1,0,4,j),e.fillText(this._formatNumber(u),0,0),e.setTransform(1,0,0,1,0,0);}}e.restore();}_drawHorizontalRuler(e,t){this._drawRuler(e,"h",t);}_drawVerticalRuler(e,t){this._drawRuler(e,"v",t);}_redraw(){if(!this._core||!this._layer)return;let e=this._core.stage,t=e.width(),o=e.height(),i=this._options.thicknessPx;this._hBg&&this._hBg.size({width:t,height:i}),this._vBg&&this._vBg.size({width:i,height:o}),this._hBorder&&this._hBorder.points([0,i,t,i]),this._vBorder&&this._vBorder.points([i,0,i,o]),this._layer.batchDraw();}_scheduleRedraw(e=false){if(!this._core||!this._layer)return;let o=globalThis.performance.now()-this._lastRedrawTime;if(this._redrawScheduled)return;this._redrawScheduled=true;let i=e?this._panThrottleMs:this._redrawThrottleMs;if(o>=i)globalThis.requestAnimationFrame(()=>{this._redrawScheduled=false,this._lastRedrawTime=globalThis.performance.now(),this._redraw();});else {let s=i-o;globalThis.setTimeout(()=>{globalThis.requestAnimationFrame(()=>{this._redrawScheduled=false,this._lastRedrawTime=globalThis.performance.now(),this._redraw();});},s);}}show(){this._core&&this._layer&&(this._core.stage.add(this._layer),this._layer.moveToTop(),this._redraw(),this._core.stage.batchDraw());}hide(){this._layer?.getStage()&&(this._layer.remove(),this._core?.stage.batchDraw());}toggle(){this._layer?.getStage()?this.hide():this.show();}isVisible(){return !!this._layer?.getStage()}};var ut=class extends H{constructor(e={}){super();a(this,"_core");a(this,"_options");a(this,"_layer",null);a(this,"_dragMoveHandler",null);a(this,"_dragEndHandler",null);a(this,"_nodesAddHandler",null);a(this,"_nodesRemoveHandler",null);let{guidelineColor:t="#8e3e2c",guidelineWidth:o=1,guidelineDash:i=[0,0],thresholdPx:s=8}=e;this._options={guidelineColor:t,guidelineWidth:o,guidelineDash:i,thresholdPx:s};}_applyGapSnappingForDrag(e,t,o){if(!this._core)return;let i=this._options.thresholdPx,s=e.getClientRect({skipShadow:true,skipStroke:false}),r=o.x-t.x,l=o.y-t.y,d={x:s.x+r,y:s.y+l,width:s.width,height:s.height},c=this._collectOtherNodeBoxes(e),h=i+1,u=0,p=i+1,f=0;for(let m of c){let v=m.box;if(!(d.y>v.y+v.height||d.y+d.height<v.y)){let b=d.x,y=d.x+d.width,N=v.x,x=v.x+v.width;if(N>=y){let w=N-y;w>0&&w<h&&(h=w,u=w);}if(x<=b){let w=b-x;w>0&&w<h&&(h=w,u=-w);}}if(!(d.x>v.x+v.width||d.x+d.width<v.x)){let b=d.y,y=d.y+d.height,N=v.y,x=v.y+v.height;if(N>=y){let w=N-y;w>0&&w<p&&(p=w,f=w);}if(x<=b){let w=b-x;w>0&&w<p&&(p=w,f=-w);}}}h<=i&&(o.x+=u),p<=i&&(o.y+=f);}onAttach(e){this._core=e;let t=new M.Layer({name:"snap-guides-layer"});e.stage.add(t),t.moveToTop(),this._layer=t,this._dragMoveHandler=i=>{this._onDragMove(i);},this._dragEndHandler=()=>{this._clearGuides();},e.stage.on("dragmove.snap-guides",this._dragMoveHandler),e.stage.on("dragend.snap-guides",this._dragEndHandler);let o=e.nodes.layer;this._nodesAddHandler=i=>{let r=i.child??i.target;this._walkAttachTransformers(r);},this._nodesRemoveHandler=i=>{let r=i.child??i.target;this._walkDetachTransformers(r);},o.on("add.snap-guides",this._nodesAddHandler),o.on("remove.snap-guides",this._nodesRemoveHandler),this._attachExistingTransformers();}onDetach(e){e.stage.off(".snap-guides"),e.nodes.layer.off(".snap-guides");let t=e.nodes.layer.find("Transformer");for(let o of t)o.off(".snap-guides-resize");this._layer&&(this._layer.destroy(),this._layer=null),this._dragMoveHandler=null,this._dragEndHandler=null,this._nodesAddHandler=null,this._nodesRemoveHandler=null,this._core=void 0;}_onDragMove(e){if(!this._core||!this._layer)return;if(this._isVisualLinesShouldCleared(e.target)){this._clearGuides();return}let t=this._core.stage,o=this._core.nodes.layer,i=e.target;if(i===t||i instanceof M.Layer)return;let s=i,r=false;for(;s;){if(s===o){r=true;break}s=s.getParent();}if(!r)return;let l=i;if(typeof l.draggable=="function"&&!l.draggable())return;this._clearGuides();let d=this._getLineGuideStops(i),c=this._getObjectSnappingEdges(i),h=this._getGuides(d,c);if(!h.length)return;let u=i.absolutePosition(),p={...u};for(let f of h)f.orientation==="V"?p.x=f.lineGuide+f.offset:p.y=f.lineGuide+f.offset;this._applyGapSnappingForDrag(i,u,p),i.absolutePosition(p),this._drawDragGuides(i);}_clearGuides(){if(!this._layer)return;let e=this._layer.find(".snap-guid-line");for(let t of e)t.destroy();this._layer.batchDraw();}_drawDragGuides(e){if(!this._core||!this._layer)return;let t=e.getClientRect({skipShadow:true,skipStroke:false}),o=this._buildDragRays(t),i=this._collectOtherNodeBoxes(e);if(!i.length)return;let s=16;for(let r of o){let l=[];for(let p of i){let f=this._intersectRayWithBox(r.origin,r.dir,p.box);f&&l.push({...f,box:p.box});}if(!l.length)continue;l.sort((p,f)=>p.tEnter-f.tEnter);let d=l.slice(0,s);if(!d.length)continue;let c=0;for(let p of d)p.tExit>c&&(c=p.tExit);if(c<=0)continue;let h;r.dir==="right"?h=[0,0,c,0]:r.dir==="left"?h=[0,0,-c,0]:r.dir==="down"?h=[0,0,0,c]:h=[0,0,0,-c];let u=new M.Line({points:h,stroke:this._options.guidelineColor,strokeWidth:this._options.guidelineWidth,name:"snap-guid-line",dash:this._options.guidelineDash,listening:false});this._layer.add(u),u.absolutePosition({x:r.origin.x,y:r.origin.y});for(let p of d){let f=p.tEnter,m=p.tExit,v=this._pointOnRay(r.origin,r.dir,f),_=this._pointOnRay(r.origin,r.dir,m),g=p.box,b=0,y=0;if(r.dir==="right"){let N=t.x+t.width,x=g.x,w=g.x+g.width;b=x-N,y=w-N;}else if(r.dir==="left"){let N=t.x,x=g.x,w=g.x+g.width;b=N-w,y=N-x;}else if(r.dir==="down"){let N=t.y+t.height,x=g.y,w=g.y+g.height;b=x-N,y=w-N;}else {let N=t.y,x=g.y,w=g.y+g.height;b=N-w,y=N-x;}b=Math.max(0,b),y=Math.max(0,y),this._drawRayMarkerWithLabel(v.x,v.y,b,r.dir),this._drawRayMarkerWithLabel(_.x,_.y,y,r.dir);}}this._layer.batchDraw();}_pointOnRay(e,t,o){return t==="right"?{x:e.x+o,y:e.y}:t==="left"?{x:e.x-o,y:e.y}:t==="down"?{x:e.x,y:e.y+o}:{x:e.x,y:e.y-o}}_drawRayMarkerWithLabel(e,t,o,i){if(!this._layer)return;let s=4,r=new M.Line({points:[-s,-s,s,s],stroke:this._options.guidelineColor,strokeWidth:1,name:"snap-guid-line",listening:false});this._layer.add(r),r.absolutePosition({x:e,y:t});let l=new M.Line({points:[-s,s,s,-s],stroke:this._options.guidelineColor,strokeWidth:1,name:"snap-guid-line",listening:false});this._layer.add(l),l.absolutePosition({x:e,y:t});}_buildDragRays(e){let t=[],o=e.x+e.width/2,i=e.y+e.height/2;t.push({origin:{x:o,y:i},dir:"up"},{origin:{x:o,y:i},dir:"down"},{origin:{x:o,y:i},dir:"left"},{origin:{x:o,y:i},dir:"right"}),t.push({origin:{x:o,y:e.y},dir:"up"},{origin:{x:o,y:e.y+e.height},dir:"down"},{origin:{x:e.x,y:i},dir:"left"},{origin:{x:e.x+e.width,y:i},dir:"right"});let s={x:e.x,y:e.y},r={x:e.x+e.width,y:e.y},l={x:e.x+e.width,y:e.y+e.height},d={x:e.x,y:e.y+e.height};return t.push({origin:s,dir:"up"},{origin:s,dir:"left"},{origin:r,dir:"up"},{origin:r,dir:"right"},{origin:l,dir:"down"},{origin:l,dir:"right"},{origin:d,dir:"down"},{origin:d,dir:"left"}),t}_collectOtherNodeBoxes(e){let t=[];if(!this._core)return t;let o=this._core.nodes.list();for(let i of o){let s=i.getKonvaNode();if(s===e)continue;let r=s,l=e;if(typeof r.isAncestorOf=="function"&&r.isAncestorOf(e)||typeof l.isAncestorOf=="function"&&l.isAncestorOf(s))continue;let d=s.getClientRect({skipShadow:true,skipStroke:false});t.push({node:s,box:{x:d.x,y:d.y,width:d.width,height:d.height}});}return t}_intersectRayWithBox(e,t,o){let i=e.x,s=e.y,r=o.x,l=o.y,d=o.x+o.width,c=o.y+o.height;if(t==="right"||t==="left"){if(s<l||s>c)return null;if(t==="right"){if(d<=i)return null;let h=Math.max(r,i),u=d,p=h-i,f=u-i;return f<=0||f<=p?null:{tEnter:p,tExit:f}}else {if(r>=i)return null;let h=Math.min(d,i),u=r,p=i-h,f=i-u;return f<=0||f<=p?null:{tEnter:p,tExit:f}}}if(i<r||i>d)return null;if(t==="down"){if(c<=s)return null;let h=Math.max(l,s),u=c,p=h-s,f=u-s;return f<=0||f<=p?null:{tEnter:p,tExit:f}}else {if(l>=s)return null;let h=Math.min(c,s),u=l,p=s-h,f=s-u;return f<=0||f<=p?null:{tEnter:p,tExit:f}}}_getLineGuideStops(e){if(!this._core)return {vertical:[],horizontal:[]};let t=this._core.stage,o=[0,t.width()/2,t.width()],i=[0,t.height()/2,t.height()],s=this._core.nodes.list();for(let r of s){let l=r.getKonvaNode();if(l===e)continue;let d=l,c=e;if(typeof d.isAncestorOf=="function"&&d.isAncestorOf(e)||typeof c.isAncestorOf=="function"&&c.isAncestorOf(l))continue;let h=l.getClientRect({skipShadow:true,skipStroke:false});o.push(h.x,h.x+h.width,h.x+h.width/2),i.push(h.y,h.y+h.height,h.y+h.height/2);}return {vertical:o,horizontal:i}}_getObjectSnappingEdges(e){let t=e.getClientRect({skipShadow:true,skipStroke:false}),o=e.absolutePosition();return {vertical:[{guide:Math.round(t.x),offset:Math.round(o.x-t.x),snap:"start"},{guide:Math.round(t.x+t.width/2),offset:Math.round(o.x-t.x-t.width/2),snap:"center"},{guide:Math.round(t.x+t.width),offset:Math.round(o.x-t.x-t.width),snap:"end"}],horizontal:[{guide:Math.round(t.y),offset:Math.round(o.y-t.y),snap:"start"},{guide:Math.round(t.y+t.height/2),offset:Math.round(o.y-t.y-t.height/2),snap:"center"},{guide:Math.round(t.y+t.height),offset:Math.round(o.y-t.y-t.height),snap:"end"}]}}_getGuides(e,t){let o=[],i=[],s=this._options.thresholdPx;for(let l of e.vertical)for(let d of t.vertical){let c=Math.abs(l-d.guide);c<s&&o.push({lineGuide:l,diff:c,snap:d.snap,offset:d.offset});}for(let l of e.horizontal)for(let d of t.horizontal){let c=Math.abs(l-d.guide);c<s&&i.push({lineGuide:l,diff:c,snap:d.snap,offset:d.offset});}let r=[];if(o.length>0){let[l]=[...o].sort((d,c)=>d.diff-c.diff);l&&r.push({lineGuide:l.lineGuide,offset:l.offset,orientation:"V",snap:l.snap});}if(i.length>0){let[l]=[...i].sort((d,c)=>d.diff-c.diff);l&&r.push({lineGuide:l.lineGuide,offset:l.offset,orientation:"H",snap:l.snap});}return r}_attachExistingTransformers(){if(!this._core)return;let e=this._core.nodes.layer;this._walkAttachTransformers(e);}_walkAttachTransformers(e){this._attachTransformer(e);let t=e,o=typeof t.getChildren=="function"?t.getChildren():[];for(let i of o)this._walkAttachTransformers(i);}_attachTransformer(e){let t=e;if((typeof t.getClassName=="function"?t.getClassName():"")!=="Transformer")return;let i=e;i.off(".snap-guides-resize"),i.on("transform.snap-guides-resize",()=>{this._handleTransformerTransform(i);}),i.on("transformend.snap-guides-resize",()=>{this._clearGuides();});}_walkDetachTransformers(e){let t=e;(typeof t.getClassName=="function"?t.getClassName():"")==="Transformer"&&e.off(".snap-guides-resize");let i=typeof t.getChildren=="function"?t.getChildren():[];for(let s of i)this._walkDetachTransformers(s);}_handleTransformerTransform(e){if(!this._core||!this._layer)return;if((typeof e.getActiveAnchor=="function"?e.getActiveAnchor():"")==="rotater"||this._isVisualLinesShouldCleared(e)){this._clearGuides();return}let i=(typeof e.nodes=="function"?e.nodes():[])[0];if(!i)return;let s=i,r=typeof s.getLayer=="function"?s.getLayer():null;if(!r||r!==this._core.nodes.layer)return;this._clearGuides();let l=this._getLineGuideStops(i),d=this._getObjectSnappingEdges(i),c=this._getGuides(l,d);if(!c.length)return;let h=i.absolutePosition();for(let u of c)u.orientation==="V"?h.x=u.lineGuide+u.offset:h.y=u.lineGuide+u.offset;i.absolutePosition(h),this._drawResizeGuides(e,i,c);}_drawResizeGuides(e,t,o){if(!this._core||!this._layer)return;let i=typeof e.getActiveAnchor=="function"?e.getActiveAnchor():"";if(!i)return;let s=t.getClientRect({skipShadow:true,skipStroke:false}),r=o.some(p=>p.orientation==="V"),l=o.some(p=>p.orientation==="H"),c=this._buildResizeRays(i,s).filter(p=>!((p.dir==="left"||p.dir==="right")&&!l||(p.dir==="up"||p.dir==="down")&&!r));if(!c.length)return;let h=this._collectOtherNodeBoxes(t);if(!h.length)return;let u=16;for(let p of c){let f=[];for(let b of h){let y=this._intersectRayWithBox(p.origin,p.dir,b.box);y&&f.push({...y,box:b.box});}if(!f.length)continue;f.sort((b,y)=>b.tEnter-y.tEnter);let m=f.slice(0,u);if(!m.length)continue;let v=0;for(let b of m)b.tExit>v&&(v=b.tExit);if(v<=0)continue;let _;p.dir==="right"?_=[0,0,v,0]:p.dir==="left"?_=[0,0,-v,0]:p.dir==="down"?_=[0,0,0,v]:_=[0,0,0,-v];let g=new M.Line({points:_,stroke:this._options.guidelineColor,strokeWidth:this._options.guidelineWidth,name:"snap-guid-line",dash:this._options.guidelineDash,listening:false});this._layer.add(g),g.absolutePosition({x:p.origin.x,y:p.origin.y});for(let b of m){let y=b.tEnter,N=b.tExit,x=this._pointOnRay(p.origin,p.dir,y),w=this._pointOnRay(p.origin,p.dir,N),k=b.box,T=0,A=0;if(p.dir==="right"){let R=s.x+s.width,D=k.x,B=k.x+k.width;T=D-R,A=B-R;}else if(p.dir==="left"){let R=s.x,D=k.x,B=k.x+k.width;T=R-B,A=R-D;}else if(p.dir==="down"){let R=s.y+s.height,D=k.y,B=k.y+k.height;T=D-R,A=B-R;}else {let R=s.y,D=k.y,B=k.y+k.height;T=R-B,A=R-D;}T=Math.max(0,T),A=Math.max(0,A),this._drawRayMarkerWithLabel(x.x,x.y,T,p.dir),this._drawRayMarkerWithLabel(w.x,w.y,A,p.dir);}}this._layer.batchDraw();}_buildResizeRays(e,t){let o={x:t.x,y:t.y},i={x:t.x+t.width,y:t.y},s={x:t.x+t.width,y:t.y+t.height},r={x:t.x,y:t.y+t.height},l=[];switch(e){case "top-left":l.push({origin:o,dir:"up"},{origin:o,dir:"left"});break;case "top-right":l.push({origin:i,dir:"up"},{origin:i,dir:"right"});break;case "bottom-right":l.push({origin:s,dir:"down"},{origin:s,dir:"right"});break;case "bottom-left":l.push({origin:r,dir:"down"},{origin:r,dir:"left"});break;case "middle-left":l.push({origin:o,dir:"up"},{origin:o,dir:"left"});break;case "middle-right":l.push({origin:i,dir:"up"},{origin:i,dir:"right"});break;case "top-center":l.push({origin:o,dir:"up"},{origin:o,dir:"left"});break;case "bottom-center":l.push({origin:r,dir:"down"},{origin:r,dir:"left"});break;}return l}_isVisualLinesShouldCleared(e){let t=e;for(;t;){let o=t,i=typeof o.name=="function"?o.name():"";if(i.startsWith("rotate-")||i==="rotate-handles-group"||i.startsWith("corner-radius-")||i==="corner-radius-handles-group")return true;t=t.getParent();}return false}};var ce=class{attach(n){this.onAttach(n);}detach(n){this.onDetach(n);}};var pt=class extends ce{constructor(e={}){super();a(this,"mode");a(this,"intensity");a(this,"pixelRatio");a(this,"nodes",new WeakMap);this.mode=e.mode??"sepia";let t=e.intensity??.4;this.intensity=Math.max(0,Math.min(1,t)),this.pixelRatio=e.pixelRatio??3;}onAttach(e){if(this.nodes.has(e))return;let t=e.getKonvaNode(),o=t.filters(),i=Array.isArray(o)?o:[],s=t,r=typeof s.red=="function"?s.red():0,l=typeof s.green=="function"?s.green():0,d=typeof s.blue=="function"?s.blue():0,c=typeof s.alpha=="function"?s.alpha():1,h=typeof s.hue=="function"?s.hue():0,u=typeof s.saturation=="function"?s.saturation():0,p=typeof s.luminance=="function"?s.luminance():0,f={prevFilters:[...i],prevRed:r,prevGreen:l,prevBlue:d,prevAlpha:c,prevHue:h,prevSaturation:u,prevLuminance:p,mouseEnterHandler:()=>{},mouseLeaveHandler:()=>{},hadHover:false};f.mouseEnterHandler=()=>{if(f.hadHover=true,t.cache({pixelRatio:this.pixelRatio}),this.mode==="sepia"){let m=t.filters(),v=Array.isArray(m)?m:[];v.includes(M.Filters.Sepia)||t.filters([...v,M.Filters.Sepia]);}else {let m=t.filters(),v=Array.isArray(m)?m:[];v.includes(M.Filters.HSL)||t.filters([...v,M.Filters.HSL]);let _=this.intensity,g=18,b=.2,y=g*_,N=b*_;switch(this.mode){case "warm":{typeof s.hue=="function"&&s.hue(f.prevHue+y),typeof s.saturation=="function"&&s.saturation(f.prevSaturation+N);break}case "cool":{typeof s.hue=="function"&&s.hue(f.prevHue-y),typeof s.saturation=="function"&&s.saturation(f.prevSaturation+N);break}}}t.getLayer()?.batchDraw();},f.mouseLeaveHandler=()=>{f.hadHover&&(t.filters(f.prevFilters),(this.mode==="warm"||this.mode==="cool")&&(typeof s.red=="function"&&s.red(f.prevRed),typeof s.green=="function"&&s.green(f.prevGreen),typeof s.blue=="function"&&s.blue(f.prevBlue),typeof s.alpha=="function"&&s.alpha(f.prevAlpha),typeof s.hue=="function"&&s.hue(f.prevHue),typeof s.saturation=="function"&&s.saturation(f.prevSaturation),typeof s.luminance=="function"&&s.luminance(f.prevLuminance)),t.getLayer()?.batchDraw(),t.clearCache());},t.on("mouseenter.imageHoverFilterAddon",f.mouseEnterHandler),t.on("mouseleave.imageHoverFilterAddon",f.mouseLeaveHandler),this.nodes.set(e,f);}onDetach(e){let t=this.nodes.get(e);if(!t)return;let o=e.getKonvaNode();o.off("mouseenter.imageHoverFilterAddon",t.mouseEnterHandler),o.off("mouseleave.imageHoverFilterAddon",t.mouseLeaveHandler),o.filters(t.prevFilters);let i=o;(this.mode==="warm"||this.mode==="cool")&&(typeof i.red=="function"&&i.red(t.prevRed),typeof i.green=="function"&&i.green(t.prevGreen),typeof i.blue=="function"&&i.blue(t.prevBlue),typeof i.alpha=="function"&&i.alpha(t.prevAlpha)),o.getLayer()?.batchDraw(),o.clearCache(),this.nodes.delete(e);}};var ue=class{attach(n,e){this.onAttach(n,e);}detach(n,e){this.onDetach(n,e);}};var ft=class extends ue{constructor(e={}){super();a(this,"_options");a(this,"_instance",null);a(this,"_owned",false);this._options=e;}onAttach(e,t){if(this._instance)return;let o=t.plugins.list().find(s=>s instanceof ge);if(o){this._instance=o,this._owned=false;return}let i=new ge(this._options);t.plugins.addPlugins([i]),this._instance=i,this._owned=true;}onDetach(e,t){this._instance&&(this._owned&&t.plugins.removePlugins([this._instance]),this._instance=null,this._owned=false);}};var gt=class extends ue{constructor(e={}){super();a(this,"_options");a(this,"_instance",null);a(this,"_owned",false);this._options=e;}onAttach(e,t){if(this._instance)return;let o=t.plugins.list().find(s=>s instanceof Ce);if(o){this._instance=o,this._owned=false;return}let i=new Ce(this._options);t.plugins.addPlugins([i]),this._instance=i,this._owned=true;}onDetach(e,t){this._instance&&(this._owned&&t.plugins.removePlugins([this._instance]),this._instance=null,this._owned=false);}};var _t=class extends ue{constructor(e={}){super();a(this,"_options");a(this,"_instance",null);a(this,"_owned",false);this._options=e;}onAttach(e,t){if(this._instance)return;let o=t.plugins.list().find(s=>s instanceof Te);if(o){this._instance=o,this._owned=false;return}let i=new Te(this._options);t.plugins.addPlugins([i]),this._instance=i,this._owned=true;}onDetach(e,t){this._instance&&(this._owned&&t.plugins.removePlugins([this._instance]),this._instance=null,this._owned=false);}};var vt=class extends ce{constructor(e={}){super();a(this,"stroke");a(this,"strokeWidth");a(this,"fill");a(this,"mode");a(this,"nodes",new WeakMap);this.stroke=e.stroke??"#1976d2",this.strokeWidth=e.strokeWidth??2,this.fill=e.fill??"rgba(255, 255, 0, 0.25)",this.mode=e.mode??"stroke";}onAttach(e){if(this.nodes.has(e))return;let t=e.getKonvaNode(),o={mouseEnterHandler:()=>{},mouseLeaveHandler:()=>{},prevStroke:e.getStroke(),prevStrokeWidth:e.getStrokeWidth(),prevStrokeEnabled:t.strokeEnabled(),prevFill:t.fill(),prevFillEnabled:t.fillEnabled(),hadHover:false};o.mouseEnterHandler=()=>{o.prevStroke=e.getStroke(),o.prevStrokeWidth=e.getStrokeWidth(),o.prevStrokeEnabled=t.strokeEnabled(),o.prevFill=t.fill(),o.prevFillEnabled=t.fillEnabled(),o.hadHover=true,(this.mode==="stroke"||this.mode==="both")&&(t.strokeEnabled(true),t.stroke(this.stroke),t.strokeWidth(this.strokeWidth)),(this.mode==="fill"||this.mode==="both")&&(t.fillEnabled(true),t.fill(this.fill)),t.getLayer()?.batchDraw();},o.mouseLeaveHandler=()=>{o.hadHover&&(t.strokeEnabled(o.prevStrokeEnabled),typeof o.prevStroke=="string"&&t.stroke(o.prevStroke),t.strokeWidth(o.prevStrokeWidth),t.fillEnabled(o.prevFillEnabled),typeof o.prevFill=="string"&&t.fill(o.prevFill),t.getLayer()?.batchDraw());},t.on("mouseenter.shapeHoverHighlightAddon",o.mouseEnterHandler),t.on("mouseleave.shapeHoverHighlightAddon",o.mouseLeaveHandler),this.nodes.set(e,o);}onDetach(e){let t=this.nodes.get(e);if(!t)return;let o=e.getKonvaNode();o.off("mouseenter.shapeHoverHighlightAddon",t.mouseEnterHandler),o.off("mouseleave.shapeHoverHighlightAddon",t.mouseLeaveHandler),t.hadHover&&(o.strokeEnabled(t.prevStrokeEnabled),typeof t.prevStroke=="string"&&o.stroke(t.prevStroke),o.strokeWidth(t.prevStrokeWidth),o.fillEnabled(t.prevFillEnabled),typeof t.prevFill=="string"&&o.fill(t.prevFill),o.getLayer()?.batchDraw()),this.nodes.delete(e);}};var mt=class extends ce{constructor(){super(...arguments);a(this,"nodes",new WeakMap);}onAttach(e){if(this.nodes.has(e))return;let t=o=>{if(o.cancelled)return;let i=this.normalize(o.newText);i!==o.newText&&(e.setText(i),e.getKonvaNode().getLayer()?.batchDraw());};e.onTextChange(t),this.nodes.set(e,{handler:t});}onDetach(e){let t=this.nodes.get(e);t&&(e.offTextChange(t.handler),this.nodes.delete(e));}normalize(e){return e?e.replace(/[ \t]+/g," ").trim():""}};export{it as AreaSelectionPlugin,st as CameraHotkeysPlugin,Ee as CameraManager,ot as CoreEngine,_e as DebounceHelper,Ae as EventBus,rt as GridPlugin,Me as HistoryManager,at as HistoryPlugin,pt as ImageHoverFilterAddon,dt as LogoPlugin,ce as NodeAddon,Pe as NodeAddons,ht as NodeHotkeysPlugin,Re as NodeManager,ue as PluginAddon,Be as Plugins,ft as RulerGuidesAddon,ge as RulerGuidesPlugin,gt as RulerHighlightAddon,Ce as RulerHighlightPlugin,_t as RulerManagerAddon,Te as RulerManagerPlugin,ct as RulerPlugin,ve as SelectionPlugin,vt as ShapeHoverHighlightAddon,mt as TextAutoTrimAddon,pe as ThrottleHelper,ut as VisualGuidesPlugin};
|