@leafer-ui/core 1.12.0 → 1.12.2

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/lib/core.cjs CHANGED
@@ -452,6 +452,8 @@ exports.MoveEvent.START = "move.start";
452
452
 
453
453
  exports.MoveEvent.MOVE = "move";
454
454
 
455
+ exports.MoveEvent.DRAG_ANIMATE = "move.drag_animate";
456
+
455
457
  exports.MoveEvent.END = "move.end";
456
458
 
457
459
  exports.MoveEvent = __decorate([ core.registerUIEvent() ], exports.MoveEvent);
@@ -550,6 +552,7 @@ const InteractionHelper = {
550
552
  ctrlKey: e.ctrlKey,
551
553
  shiftKey: e.shiftKey,
552
554
  metaKey: e.metaKey,
555
+ time: Date.now(),
553
556
  buttons: core.isUndefined(e.buttons) ? 1 : e.buttons === 0 ? pointerUpButtons : e.buttons,
554
557
  origin: e
555
558
  };
@@ -585,6 +588,7 @@ const {getDragEventData: getDragEventData, getDropEventData: getDropEventData, g
585
588
 
586
589
  class Dragger {
587
590
  constructor(interaction) {
591
+ this.dragDataList = [];
588
592
  this.interaction = interaction;
589
593
  }
590
594
  setDragData(data) {
@@ -647,6 +651,7 @@ class Dragger {
647
651
  this.dragData = getDragEventData(downData, dragData, data);
648
652
  if (throughPath) this.dragData.throughPath = throughPath;
649
653
  this.dragData.path = path;
654
+ this.dragDataList.push(this.dragData);
650
655
  if (this.moving) {
651
656
  data.moving = true;
652
657
  this.dragData.moveType = "drag";
@@ -697,9 +702,9 @@ class Dragger {
697
702
  interaction.emit(exports.DragEvent.ENTER, data, path, dragEnterPath);
698
703
  this.dragEnterPath = path;
699
704
  }
700
- dragEnd(data, speed) {
705
+ dragEnd(data) {
701
706
  if (!this.dragging && !this.moving) return;
702
- if (this.checkDragEndAnimate(data, speed)) return;
707
+ if (this.checkDragEndAnimate(data)) return;
703
708
  this.dragEndReal(data);
704
709
  }
705
710
  dragEndReal(data) {
@@ -741,11 +746,13 @@ class Dragger {
741
746
  }
742
747
  dragReset() {
743
748
  exports.DragEvent.list = exports.DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
749
+ this.dragDataList = [];
744
750
  }
745
751
  checkDragEndAnimate(_data, _speed) {
746
752
  return false;
747
753
  }
748
754
  animate(_func, _off) {}
755
+ stopAnimate() {}
749
756
  checkDragOut(_data) {}
750
757
  autoMoveOnDragOut(_data) {}
751
758
  autoMoveCancel() {}
@@ -1139,6 +1146,9 @@ class InteractionBase {
1139
1146
  this.pointerHover(hoverData);
1140
1147
  }
1141
1148
  }
1149
+ stopDragAnimate() {
1150
+ this.dragger.stopAnimate();
1151
+ }
1142
1152
  updateDownData(data, options, merge) {
1143
1153
  const {downData: downData} = this;
1144
1154
  if (!data && downData) data = downData;
@@ -1322,7 +1332,7 @@ core.Platform.getSelector = function(leaf) {
1322
1332
  return leaf.leafer ? leaf.leafer.selector : core.Platform.selector || (core.Platform.selector = core.Creator.selector());
1323
1333
  };
1324
1334
 
1325
- const {toInnerRadiusPointOf: toInnerRadiusPointOf, copy: copy, setRadius: setRadius} = core.PointHelper;
1335
+ const {toInnerRadiusPointOf: toInnerRadiusPointOf, copyRadiusPoint: copyRadiusPoint} = core.PointHelper;
1326
1336
 
1327
1337
  const {hitRadiusPoint: hitRadiusPoint, hitPoint: hitPoint} = core.BoundsHelper;
1328
1338
 
@@ -1332,8 +1342,7 @@ const leaf = core.Leaf.prototype;
1332
1342
 
1333
1343
  leaf.hit = function(worldPoint, hitRadius = 0) {
1334
1344
  this.updateLayout();
1335
- copy(worldRadiusPoint, worldPoint);
1336
- setRadius(worldRadiusPoint, hitRadius);
1345
+ copyRadiusPoint(worldRadiusPoint, worldPoint, hitRadius);
1337
1346
  const world = this.__world;
1338
1347
  if (hitRadius ? !hitRadiusPoint(world, worldRadiusPoint) : !hitPoint(world, worldRadiusPoint)) return false;
1339
1348
  return this.isBranch ? core.Platform.getSelector(this).hitPoint(Object.assign({}, worldRadiusPoint), hitRadius, {
@@ -1341,14 +1350,14 @@ leaf.hit = function(worldPoint, hitRadius = 0) {
1341
1350
  }) : this.__hitWorld(worldRadiusPoint);
1342
1351
  };
1343
1352
 
1344
- leaf.__hitWorld = function(point) {
1353
+ leaf.__hitWorld = function(point, forceHitFill) {
1345
1354
  const data = this.__;
1346
1355
  if (!data.hitSelf) return false;
1347
1356
  const world = this.__world, layout = this.__layout;
1348
1357
  const isSmall = world.width < 10 && world.height < 10;
1349
1358
  if (data.hitRadius) {
1350
- copy(inner, point), point = inner;
1351
- setRadius(point, data.hitRadius);
1359
+ copyRadiusPoint(inner, point, data.hitRadius);
1360
+ point = inner;
1352
1361
  }
1353
1362
  toInnerRadiusPointOf(point, world, inner);
1354
1363
  if (data.hitBox || isSmall) {
@@ -1359,7 +1368,7 @@ leaf.__hitWorld = function(point) {
1359
1368
  this.__updateHitCanvas();
1360
1369
  if (!layout.boundsChanged) layout.hitCanvasChanged = false;
1361
1370
  }
1362
- return this.__hit(inner);
1371
+ return this.__hit(inner, forceHitFill);
1363
1372
  };
1364
1373
 
1365
1374
  leaf.__hitFill = function(inner) {
@@ -1426,12 +1435,12 @@ ui$1.__updateHitCanvas = function() {
1426
1435
  h.setStrokeOptions(data);
1427
1436
  };
1428
1437
 
1429
- ui$1.__hit = function(inner) {
1438
+ ui$1.__hit = function(inner, forceHitFill) {
1430
1439
  if (this.__box && this.__box.__hit(inner)) return true;
1431
1440
  const data = this.__;
1432
1441
  if (data.__isHitPixel && this.__hitPixel(inner)) return true;
1433
1442
  const {hitFill: hitFill} = data;
1434
- const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all";
1443
+ const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all" || forceHitFill;
1435
1444
  if (needHitFillPath && this.__hitFill(inner)) return true;
1436
1445
  const {hitStroke: hitStroke, __maxStrokeWidth: strokeWidth} = data;
1437
1446
  const needHitStrokePath = data.stroke && (hitStroke === "path" || hitStroke === "pixel" && !data.__isAlphaPixelStroke) || hitStroke === "all";
package/lib/core.esm.js CHANGED
@@ -452,6 +452,8 @@ MoveEvent.START = "move.start";
452
452
 
453
453
  MoveEvent.MOVE = "move";
454
454
 
455
+ MoveEvent.DRAG_ANIMATE = "move.drag_animate";
456
+
455
457
  MoveEvent.END = "move.end";
456
458
 
457
459
  MoveEvent = __decorate([ registerUIEvent() ], MoveEvent);
@@ -550,6 +552,7 @@ const InteractionHelper = {
550
552
  ctrlKey: e.ctrlKey,
551
553
  shiftKey: e.shiftKey,
552
554
  metaKey: e.metaKey,
555
+ time: Date.now(),
553
556
  buttons: isUndefined(e.buttons) ? 1 : e.buttons === 0 ? pointerUpButtons : e.buttons,
554
557
  origin: e
555
558
  };
@@ -585,6 +588,7 @@ const {getDragEventData: getDragEventData, getDropEventData: getDropEventData, g
585
588
 
586
589
  class Dragger {
587
590
  constructor(interaction) {
591
+ this.dragDataList = [];
588
592
  this.interaction = interaction;
589
593
  }
590
594
  setDragData(data) {
@@ -647,6 +651,7 @@ class Dragger {
647
651
  this.dragData = getDragEventData(downData, dragData, data);
648
652
  if (throughPath) this.dragData.throughPath = throughPath;
649
653
  this.dragData.path = path;
654
+ this.dragDataList.push(this.dragData);
650
655
  if (this.moving) {
651
656
  data.moving = true;
652
657
  this.dragData.moveType = "drag";
@@ -697,9 +702,9 @@ class Dragger {
697
702
  interaction.emit(DragEvent.ENTER, data, path, dragEnterPath);
698
703
  this.dragEnterPath = path;
699
704
  }
700
- dragEnd(data, speed) {
705
+ dragEnd(data) {
701
706
  if (!this.dragging && !this.moving) return;
702
- if (this.checkDragEndAnimate(data, speed)) return;
707
+ if (this.checkDragEndAnimate(data)) return;
703
708
  this.dragEndReal(data);
704
709
  }
705
710
  dragEndReal(data) {
@@ -741,11 +746,13 @@ class Dragger {
741
746
  }
742
747
  dragReset() {
743
748
  DragEvent.list = DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
749
+ this.dragDataList = [];
744
750
  }
745
751
  checkDragEndAnimate(_data, _speed) {
746
752
  return false;
747
753
  }
748
754
  animate(_func, _off) {}
755
+ stopAnimate() {}
749
756
  checkDragOut(_data) {}
750
757
  autoMoveOnDragOut(_data) {}
751
758
  autoMoveCancel() {}
@@ -1139,6 +1146,9 @@ class InteractionBase {
1139
1146
  this.pointerHover(hoverData);
1140
1147
  }
1141
1148
  }
1149
+ stopDragAnimate() {
1150
+ this.dragger.stopAnimate();
1151
+ }
1142
1152
  updateDownData(data, options, merge) {
1143
1153
  const {downData: downData} = this;
1144
1154
  if (!data && downData) data = downData;
@@ -1322,7 +1332,7 @@ Platform.getSelector = function(leaf) {
1322
1332
  return leaf.leafer ? leaf.leafer.selector : Platform.selector || (Platform.selector = Creator.selector());
1323
1333
  };
1324
1334
 
1325
- const {toInnerRadiusPointOf: toInnerRadiusPointOf, copy: copy, setRadius: setRadius} = PointHelper;
1335
+ const {toInnerRadiusPointOf: toInnerRadiusPointOf, copyRadiusPoint: copyRadiusPoint} = PointHelper;
1326
1336
 
1327
1337
  const {hitRadiusPoint: hitRadiusPoint, hitPoint: hitPoint} = BoundsHelper;
1328
1338
 
@@ -1332,8 +1342,7 @@ const leaf = Leaf.prototype;
1332
1342
 
1333
1343
  leaf.hit = function(worldPoint, hitRadius = 0) {
1334
1344
  this.updateLayout();
1335
- copy(worldRadiusPoint, worldPoint);
1336
- setRadius(worldRadiusPoint, hitRadius);
1345
+ copyRadiusPoint(worldRadiusPoint, worldPoint, hitRadius);
1337
1346
  const world = this.__world;
1338
1347
  if (hitRadius ? !hitRadiusPoint(world, worldRadiusPoint) : !hitPoint(world, worldRadiusPoint)) return false;
1339
1348
  return this.isBranch ? Platform.getSelector(this).hitPoint(Object.assign({}, worldRadiusPoint), hitRadius, {
@@ -1341,14 +1350,14 @@ leaf.hit = function(worldPoint, hitRadius = 0) {
1341
1350
  }) : this.__hitWorld(worldRadiusPoint);
1342
1351
  };
1343
1352
 
1344
- leaf.__hitWorld = function(point) {
1353
+ leaf.__hitWorld = function(point, forceHitFill) {
1345
1354
  const data = this.__;
1346
1355
  if (!data.hitSelf) return false;
1347
1356
  const world = this.__world, layout = this.__layout;
1348
1357
  const isSmall = world.width < 10 && world.height < 10;
1349
1358
  if (data.hitRadius) {
1350
- copy(inner, point), point = inner;
1351
- setRadius(point, data.hitRadius);
1359
+ copyRadiusPoint(inner, point, data.hitRadius);
1360
+ point = inner;
1352
1361
  }
1353
1362
  toInnerRadiusPointOf(point, world, inner);
1354
1363
  if (data.hitBox || isSmall) {
@@ -1359,7 +1368,7 @@ leaf.__hitWorld = function(point) {
1359
1368
  this.__updateHitCanvas();
1360
1369
  if (!layout.boundsChanged) layout.hitCanvasChanged = false;
1361
1370
  }
1362
- return this.__hit(inner);
1371
+ return this.__hit(inner, forceHitFill);
1363
1372
  };
1364
1373
 
1365
1374
  leaf.__hitFill = function(inner) {
@@ -1426,12 +1435,12 @@ ui$1.__updateHitCanvas = function() {
1426
1435
  h.setStrokeOptions(data);
1427
1436
  };
1428
1437
 
1429
- ui$1.__hit = function(inner) {
1438
+ ui$1.__hit = function(inner, forceHitFill) {
1430
1439
  if (this.__box && this.__box.__hit(inner)) return true;
1431
1440
  const data = this.__;
1432
1441
  if (data.__isHitPixel && this.__hitPixel(inner)) return true;
1433
1442
  const {hitFill: hitFill} = data;
1434
- const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all";
1443
+ const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all" || forceHitFill;
1435
1444
  if (needHitFillPath && this.__hitFill(inner)) return true;
1436
1445
  const {hitStroke: hitStroke, __maxStrokeWidth: strokeWidth} = data;
1437
1446
  const needHitStrokePath = data.stroke && (hitStroke === "path" || hitStroke === "pixel" && !data.__isAlphaPixelStroke) || hitStroke === "all";
@@ -1,2 +1,2 @@
1
- import{Leafer as t,State as e,UI as i,Rect as s,Box as a,Text as n,Group as r,emptyData as h}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as o,Creator as d,isUndefined as g,DataHelper as l,canvasSizeAttrs as c,LayoutEvent as u,RenderEvent as p,Event as _,EventCreator as m,MathHelper as v,BoundsHelper as f,Bounds as y,isFinite as E,registerUIEvent as D,LeafList as P,PointHelper as x,LeafHelper as w,isString as O,isNumber as T,Debug as L,Platform as R,ResizeEvent as C,LeaferEvent as b,CanvasManager as M,Leaf as S,Matrix as k,tempBounds as B,ImageManager as A,LeaferCanvasBase as H}from"@leafer/core";function I(t,e,i,s){var a,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var h=t.length-1;h>=0;h--)(a=t[h])&&(r=(n<3?a(r):n>3?a(e,i,r):a(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}"function"==typeof SuppressedError&&SuppressedError;let F=class extends t{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,e){if(super.init(t,e),t){const{ground:e,tree:i,sky:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&d.editor(a,this)}}__setApp(){const{canvas:t}=this,{realCanvas:e,view:i}=this.config;e||i===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable()}__updateLocalBounds(){this.forEach(t=>t.updateLayout()),super.__updateLocalBounds()}start(){super.start(),this.forEach(t=>t.start())}stop(){this.forEach(t=>t.stop()),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach(t=>t.unlockLayout())}lockLayout(){super.lockLayout(),this.forEach(t=>t.lockLayout())}forceRender(t,e){this.forEach(i=>i.forceRender(t,e))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout(()=>this.add(t,e),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),g(e)||(t.canvas.childIndex=e),this.__listenChildEvents(t)}forEach(t){this.children.forEach(t)}__onCreated(){this.created=this.children.every(t=>t.created)}__onReady(){this.children.every(t=>t.ready)&&super.__onReady()}__onViewReady(){this.children.every(t=>t.viewReady)&&super.__onViewReady()}__onChildRenderEnd(t){this.renderer.addBlock(t.renderBounds),this.viewReady&&this.renderer.update()}__render(t,e){t.context&&this.forEach(i=>e.matrix?i.__render(t,e):t.copyWorld(i.canvas,e.bounds))}__onResize(t){this.forEach(e=>e.resize(t)),super.__onResize(t)}updateLayout(){this.forEach(t=>t.updateLayout())}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&l.assign(e,t),this.autoLayout&&l.copyAttrs(e,this,c),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once([[u.END,this.__onReady,this],[p.START,this.__onCreated,this],[p.END,this.__onViewReady,this]]),this.realCanvas&&this.__eventIds.push(t.on_(p.END,this.__onChildRenderEnd,this))}};F=I([o()],F);const N={},K={isHoldSpaceKey:()=>K.isHold("Space"),isHold:t=>N[t],isHoldKeys:(t,e)=>e?t(e):void 0,setDownCode(t){N[t]||(N[t]=!0)},setUpCode(t){N[t]=!1}},W={LEFT:1,RIGHT:2,MIDDLE:4,defaultLeft(t){t.buttons||(t.buttons=1)},left:t=>1===t.buttons,right:t=>2===t.buttons,middle:t=>4===t.buttons};class V extends _{get spaceKey(){return K.isHoldSpaceKey()}get left(){return W.left(this)}get right(){return W.right(this)}get middle(){return W.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}isHoldKeys(t){return K.isHoldKeys(t,this)}getBoxPoint(t){return(t||this.current).getBoxPoint(this)}getInnerPoint(t){return(t||this.current).getInnerPoint(this)}getLocalPoint(t){return(t||this.current).getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}getInner(t){return this.getInnerPoint(t)}getLocal(t){return this.getLocalPoint(t)}getPage(){return this.getPagePoint()}static changeName(t,e){m.changeName(t,e)}}const{min:U,max:j,abs:X}=Math,{float:Y,sign:z}=v,{minX:G,maxX:Z,minY:q,maxY:J}=f,Q=new y,$=new y,tt={limitMove(t,e){const{dragBounds:i,dragBoundsType:s}=t;i&&et.getValidMove(t.__localBoxBounds,et.getDragBounds(t),s,e,!0),et.axisMove(t,e)},limitScaleOf(t,e,i,s){const{dragBounds:a,dragBoundsType:n}=t;a&&et.getValidScaleOf(t.__localBoxBounds,et.getDragBounds(t),n,t.getLocalPointByInner(t.getInnerPointByBox(e)),i,s,!0)},axisMove(t,e){const{draggable:i}=t;"x"===i&&(e.y=0),"y"===i&&(e.x=0)},getDragBounds(t){const{dragBounds:e}=t;return"parent"===e?t.parent.boxBounds:e},isInnerMode:(t,e,i,s)=>"inner"===i||"auto"===i&&t[s]>e[s],getValidMove(t,e,i,s,a){const n=t.x+s.x,r=t.y+s.y,h=n+t.width,o=r+t.height,d=e.x+e.width,g=e.y+e.height;return a||(s=Object.assign({},s)),et.isInnerMode(t,e,i,"width")?n>e.x?s.x+=e.x-n:h<d&&(s.x+=d-h):n<e.x?s.x+=e.x-n:h>d&&(s.x+=d-h),et.isInnerMode(t,e,i,"height")?r>e.y?s.y+=e.y-r:o<g&&(s.y+=g-o):r<e.y?s.y+=e.y-r:o>g&&(s.y+=g-o),s.x=Y(s.x),s.y=Y(s.y),s},getValidScaleOf(t,e,i,s,a,n,r){r||(a=Object.assign({},a)),$.set(e),Q.set(t).scaleOf(s,a.x,a.y);const h=(s.x-t.x)/t.width,o=1-h,d=(s.y-t.y)/t.height,g=1-d;let l,c,u,p,_=1,m=1;return et.isInnerMode(t,e,i,"width")?(a.x<0&&Q.scaleOf(s,_=1/a.x,1),u=Y(Q.minX-$.minX),p=Y($.maxX-Q.maxX),l=h&&u>0?1+u/(h*Q.width):1,c=o&&p>0?1+p/(o*Q.width):1,_*=j(l,c)):(a.x<0&&((Y(G(t)-G(e))<=0||Y(Z(e)-Z(t))<=0)&&Q.scaleOf(s,_=1/a.x,1),Q.unsign()),u=Y($.minX-Q.minX),p=Y(Q.maxX-$.maxX),l=h&&u>0?1-u/(h*Q.width):1,c=o&&p>0?1-p/(o*Q.width):1,_*=U(l,c)),et.isInnerMode(t,e,i,"height")?(a.y<0&&Q.scaleOf(s,1,m=1/a.y),u=Y(Q.minY-$.minY),p=Y($.maxY-Q.maxY),l=d&&u>0?1+u/(d*Q.height):1,c=g&&p>0?1+p/(g*Q.height):1,m*=j(l,c),n&&(l=j(X(_),X(m)),_=z(_)*l,m=z(m)*l)):(a.y<0&&((Y(q(t)-q(e))<=0||Y(J(e)-J(t))<=0)&&Q.scaleOf(s,1,m=1/a.y),Q.unsign()),u=Y($.minY-Q.minY),p=Y(Q.maxY-$.maxY),l=d&&u>0?1-u/(d*Q.height):1,c=g&&p>0?1-p/(g*Q.height):1,m*=U(l,c)),a.x*=E(_)?_:1,a.y*=E(m)?m:1,a}},et=tt;let it=class extends V{};it.POINTER="pointer",it.BEFORE_DOWN="pointer.before_down",it.BEFORE_MOVE="pointer.before_move",it.BEFORE_UP="pointer.before_up",it.DOWN="pointer.down",it.MOVE="pointer.move",it.UP="pointer.up",it.OVER="pointer.over",it.OUT="pointer.out",it.ENTER="pointer.enter",it.LEAVE="pointer.leave",it.TAP="tap",it.DOUBLE_TAP="double_tap",it.CLICK="click",it.DOUBLE_CLICK="double_click",it.LONG_PRESS="long_press",it.LONG_TAP="long_tap",it.MENU="pointer.menu",it.MENU_TAP="pointer.menu_tap",it=I([D()],it);const st=it,at={};let nt=class extends it{static setList(t){this.list=t instanceof P?t:new P(t)}static setData(t){this.data=t}static getValidMove(t,e,i,s=!0){const a=t.getLocalPoint(i,null,!0);return x.move(a,e.x-t.x,e.y-t.y),s&&this.limitMove(t,a),tt.axisMove(t,a),a}static limitMove(t,e){tt.limitMove(t,e)}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(at,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(at,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(at,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}getPageBounds(){const t=this.getPageTotal(),e=this.getPagePoint(),i={};return f.set(i,e.x-t.x,e.y-t.y,t.x,t.y),f.unsign(i),i}assignMove(t){at.x=t?this.totalX:this.moveX,at.y=t?this.totalY:this.moveY}};nt.BEFORE_DRAG="drag.before_drag",nt.START="drag.start",nt.DRAG="drag",nt.END="drag.end",nt.OVER="drag.over",nt.OUT="drag.out",nt.ENTER="drag.enter",nt.LEAVE="drag.leave",nt=I([D()],nt);const rt=nt;let ht=class extends it{static setList(t){nt.setList(t)}static setData(t){nt.setData(t)}};ht.DROP="drop",ht=I([D()],ht);let ot=class extends nt{};ot.BEFORE_MOVE="move.before_move",ot.START="move.start",ot.MOVE="move",ot.END="move.end",ot=I([D()],ot);let dt=class extends V{};dt=I([D()],dt);const gt=dt;let lt=class extends it{};lt.BEFORE_ROTATE="rotate.before_rotate",lt.START="rotate.start",lt.ROTATE="rotate",lt.END="rotate.end",lt=I([D()],lt);let ct=class extends nt{};ct.SWIPE="swipe",ct.LEFT="swipe.left",ct.RIGHT="swipe.right",ct.UP="swipe.up",ct.DOWN="swipe.down",ct=I([D()],ct);let ut=class extends it{};ut.BEFORE_ZOOM="zoom.before_zoom",ut.START="zoom.start",ut.ZOOM="zoom",ut.END="zoom.end",ut=I([D()],ut);let pt=class extends V{};pt.BEFORE_DOWN="key.before_down",pt.BEFORE_UP="key.before_up",pt.DOWN="key.down",pt.HOLD="key.hold",pt.UP="key.up",pt=I([D()],pt);const _t={getDragEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:i.x,y:i.y,moveX:i.x-e.x,moveY:i.y-e.y,totalX:i.x-t.x,totalY:i.y-t.y}),getDropEventData:(t,e,i)=>Object.assign(Object.assign({},t),{list:e,data:i}),getSwipeDirection:t=>t<-45&&t>-135?ct.UP:t>45&&t<135?ct.DOWN:t<=45&&t>=-45?ct.RIGHT:ct.LEFT,getSwipeEventData:(t,e,i)=>Object.assign(Object.assign({},i),{moveX:e.moveX,moveY:e.moveY,totalX:i.x-t.x,totalY:i.y-t.y,type:mt.getSwipeDirection(x.getAngle(t,i))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:g(t.buttons)?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new P,{list:s}=t;for(let t=0,a=s.length;t<a;t++)s[t].hasEvent(e)&&i.add(s[t]);return i},pathCanDrag:t=>t&&t.list.some(t=>w.draggable(t)||!t.isLeafer&&t.hasEvent(nt.DRAG)),pathHasOutside:t=>t&&t.list.some(t=>t.isOutside)},mt=_t,vt=new P,{getDragEventData:ft,getDropEventData:yt,getSwipeEventData:Et}=_t;class Dt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=ft(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=nt.list||this.draggableList||vt;return this.dragging&&(s?t?vt:new P(e?[...i.list,...i.dragHoverExclude]:i.list):a)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(ot.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&W.left(t),this.dragging&&(this.interaction.emit(nt.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach(t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y})}getDraggableList(t){let e;for(let i=0,s=t.length;i<s;i++)if(e=t.list[i],w.draggable(e)){this.draggableList=new P(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:n}=s;this.dragData=ft(s,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=a,this.moving?(t.moving=!0,this.dragData.moveType="drag",e.emit(ot.BEFORE_MOVE,this.dragData),e.emit(ot.MOVE,this.dragData)):this.dragging&&(t.dragging=!0,this.dragReal(),e.emit(nt.BEFORE_DRAG,this.dragData),e.emit(nt.DRAG,this.dragData))}dragReal(t){const{interaction:e}=this,{running:i}=e,s=this.realDraggableList;if(s.length&&i){const{totalX:i,totalY:a}=this.dragData,{dragLimitAnimate:n}=e.p,r=!n||!!t;s.forEach(e=>{if(e.draggable){const s=O(e.draggable),h=nt.getValidMove(e,this.dragStartPoints[e.innerId],{x:i,y:a},r||s);n&&!s&&t?w.animateMove(e,h,T(n)?n:.3):e.move(h)}})}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:s}=t;this.dragOverPath=s,i?s.indexAt(0)!==i.indexAt(0)&&(e.emit(nt.OUT,t,i),e.emit(nt.OVER,t,s)):e.emit(nt.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(nt.LEAVE,t,i,s),e.emit(nt.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,e){(this.dragging||this.moving)&&(this.checkDragEndAnimate(t,e)||this.dragEndReal(t))}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:a,throughPath:n}=i,r=ft(i,t,t);if(n&&(r.throughPath=n),r.path=a,this.moving&&(this.moving=!1,r.moveType="drag",e.emit(ot.END,r)),this.dragging){const a=this.getList();this.dragging=!1,e.p.dragLimitAnimate&&this.dragReal(!0),e.emit(nt.END,r),this.swipe(t,i,s,r),this.drop(t,a,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}swipe(t,e,i,s){const{interaction:a}=this;if(x.getDistance(e,t)>a.config.pointer.swipeDistance){const t=Et(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=yt(t,e,nt.data);s.path=i,this.interaction.emit(ht.DROP,s),this.interaction.emit(nt.LEAVE,t,i)}dragReset(){nt.list=nt.data=this.draggableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragEndAnimate(t,e){return!1}animate(t,e){}checkDragOut(t){}autoMoveOnDragOut(t){}autoMoveCancel(){}destroy(){this.dragReset()}}const Pt=L.get("emit");const xt=["move","zoom","rotate","key"];function wt(t,e,i,s,a){if(xt.some(t=>e.startsWith(t))&&t.__.hitChildren&&!Tt(t,a)){let n;for(let r=0,h=t.children.length;r<h;r++)n=t.children[r],!i.path.has(n)&&n.__.hittable&&Ot(n,e,i,s,a)}}function Ot(t,i,s,a,n){if(t.destroyed)return!1;if(t.__.hitSelf&&!Tt(t,n)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=m.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function Tt(t,e){return e&&e.has(t)}const Lt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{type:"pointer",snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:Rt,pathCanDrag:Ct,pathHasOutside:bt}=_t;class Mt{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.m.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.p.hover&&!this.config.mobile}get isDragEmpty(){return this.m.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.m.dragEmpty&&!this.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.m.holdMiddleKey&&this.downData&&W.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&W.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&K.isHoldSpaceKey()}get m(){return this.config.move}get p(){return this.config.pointer}get hitRadius(){return this.p.hitRadius}constructor(t,e,i,s){this.config=l.clone(Lt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new P(t),this.createTransformer(),this.dragger=new Dt(this),s&&(this.config=l.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(W.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(it.BEFORE_DOWN,t),this.emit(it.DOWN,t),W.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=W.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&W.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(it.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=x.getDistance(this.downData,t)>this.p.dragDistance;e&&(this.pointerWaitCancel(),this.waitRightTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(it.MOVE,t),this.pointerHover(t),this.dragging&&(this.dragger.dragOverOrOut(t),this.dragger.dragEnterOrLeave(t))),this.updateCursor(this.downData||t)}pointerUp(t){const{downData:e}=this;if(t||(t=e),!e)return;W.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(it.BEFORE_UP,t),this.emit(it.UP,t),this.touchLeave(t),t.isCancel||(this.tap(t),this.menuTap(t)),this.dragger.dragEnd(t),this.updateCursor(i)}pointerCancel(){const t=Object.assign({},this.dragger.dragData);t.isCancel=!0,this.pointerUp(t)}menu(t){this.findPath(t),this.emit(it.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(it.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}createTransformer(){}move(t){}zoom(t){}rotate(t){}transformEnd(){}wheel(t){}multiTouch(t,e){}keyDown(t){if(!this.config.keyEvent)return;this.emit(pt.BEFORE_DOWN,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,K.setDownCode(e),this.emit(pt.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(pt.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;this.emit(pt.BEFORE_UP,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]=!1,K.setUpCode(e),this.emit(pt.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new P),this.pointerOverOrOut(t),this.pointerEnterOrLeave(t))}pointerOverOrOut(t){const{path:e}=t,{overPath:i}=this;this.overPath=e,i?e.indexAt(0)!==i.indexAt(0)&&(this.emit(it.OUT,t,i),this.emit(it.OVER,t,e)):this.emit(it.OVER,t,e)}pointerEnterOrLeave(t){let{path:e}=t;this.downData&&!this.moveMode&&(e=e.clone(),this.downData.path.forEach(t=>e.add(t)));const{enterPath:i}=this;this.enterPath=e,this.emit(it.LEAVE,t,i,e),this.emit(it.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(it.LEAVE,t),this.dragger.dragging&&this.emit(ht.LEAVE,t))}tap(t){const{pointer:e}=this.config,i=this.longTap(t);if(!e.tapMore&&i)return;if(!this.waitTap)return;e.tapMore&&this.emitTap(t);const s=Date.now()-this.downTime,a=[it.DOUBLE_TAP,it.DOUBLE_CLICK].some(e=>Rt(t.path,e));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout(()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))},e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.p,{bottomList:a,target:n}=this;R.backgrounder||t.origin||n&&n.updateLayout();const r=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));return r.throughPath&&(t.throughPath=r.throughPath),t.path=r.path,r.path}isRootPath(t){return t&&t.path.list[0].isLeafer}isTreePath(t){const e=this.target.app;return!(!e||!e.isApp)&&(e.editor&&!t.path.has(e.editor)&&t.path.has(e.tree)&&!t.target.syncEventer)}checkPath(t,e){(e||this.moveMode&&!bt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!Ct(t.path))&&!bt(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData:s}=this;!t&&s&&(t=s),t&&(this.findPath(t,e),i&&s&&t.path.addList(s.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(!1,!0),name:it.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e),s={x:t.clientX-i.x,y:t.clientY-i.y},{bounds:a}=this.canvas;return s.x*=a.width/i.width,s.y*=a.height/i.height,this.p.snap&&x.round(s),s}emitTap(t){this.emit(it.TAP,t),this.emit(it.CLICK,t)}emitDoubleTap(t){this.emit(it.DOUBLE_TAP,t),this.emit(it.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){this.waitTap&&(clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0)}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout(()=>{this.longPressed=!0,this.emit(it.LONG_PRESS,t)},this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(it.LONG_TAP,t),(Rt(t.path,it.LONG_TAP)||Rt(t.path,it.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressed=!1)}__onResize(){const{dragOut:t}=this.m;this.shrinkCanvasBounds=new y(this.canvas.bounds),this.shrinkCanvasBounds.spread(-(T(t)?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(C.RESIZE,this.__onResize,this)],t.once(b.READY,()=>this.__onResize())}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}emit(t,e,i,s){this.running&&function(t,e,i,s){if(!i&&!e.path)return;let a;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let n=i.length-1;n>-1;n--){if(a=i.list[n],Ot(a,t,e,!0,s))return;a.isApp&&wt(a,t,e,!0,s)}for(let n=0,r=i.length;n<r;n++)if(a=i.list[n],a.isApp&&wt(a,t,e,!1,s),Ot(a,t,e,!1,s))return}catch(t){Pt.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer&&this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class St{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}St.custom={};class kt extends M{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new P,this.pixelList=new P}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),d.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),d.hitCanvas()}clearImageType(){this.__clearLeafList(this.pixelList)}clearPathType(){this.__clearLeafList(this.pathList)}__clearLeafList(t){t.length&&(t.forEach(t=>{t.__hitCanvas&&(t.__hitCanvas.destroy(),t.__hitCanvas=null)}),t.reset())}__autoClear(){this.pathList.length+this.pixelList.length>this.maxTotal&&this.clear()}clear(){this.clearPathType(),this.clearImageType()}}R.getSelector=function(t){return t.leafer?t.leafer.selector:R.selector||(R.selector=d.selector())};const{toInnerRadiusPointOf:Bt,copy:At,setRadius:Ht}=x,{hitRadiusPoint:It,hitPoint:Ft}=f,Nt={},Kt={},Wt=S.prototype;Wt.hit=function(t,e=0){this.updateLayout(),At(Kt,t),Ht(Kt,e);const i=this.__world;return!!(e?It(i,Kt):Ft(i,Kt))&&(this.isBranch?R.getSelector(this).hitPoint(Object.assign({},Kt),e,{target:this}):this.__hitWorld(Kt))},Wt.__hitWorld=function(t){const e=this.__;if(!e.hitSelf)return!1;const i=this.__world,s=this.__layout,a=i.width<10&&i.height<10;if(e.hitRadius&&(At(Nt,t),Ht(t=Nt,e.hitRadius)),Bt(t,i,Nt),e.hitBox||a){if(f.hitRadiusPoint(s.boxBounds,Nt))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(Nt)},Wt.__hitFill=function(t){const e=this.__hitCanvas;return e&&e.hitFill(t,this.__.windingRule)},Wt.__hitStroke=function(t,e){const i=this.__hitCanvas;return i&&i.hitStroke(t,e)},Wt.__hitPixel=function(t){const e=this.__hitCanvas;return e&&e.hitPixel(t,this.__layout.renderBounds,e.hitScale)},Wt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Vt=new k,Ut=i.prototype;Ut.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const{hitCanvasManager:t}=this.leafer||this.parent&&this.parent.leafer||{};if(!t)return;const e=this.__,i=(e.__isAlphaPixelFill||e.__isCanvas)&&"pixel"===e.hitFill,s=e.__isAlphaPixelStroke&&"pixel"===e.hitStroke,a=i||s;this.__hitCanvas||(this.__hitCanvas=a?t.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):t.getPathType(this));const n=this.__hitCanvas;if(a){const{renderBounds:t}=this.__layout,a=R.image.hitCanvasSize,r=n.hitScale=B.set(0,0,a,a).getFitMatrix(t).a,{x:h,y:o,width:d,height:g}=B.set(t).scale(r);n.resize({width:d,height:g,pixelRatio:1}),n.clear(),A.patternLocked=!0,this.__renderShape(n,{matrix:Vt.setWith(this.__world).scaleWith(1/r).invertWith().translate(-h,-o),ignoreFill:!i,ignoreStroke:!s}),A.patternLocked=!1,n.resetTransform(),e.__isHitPixel=!0}else e.__isHitPixel&&(e.__isHitPixel=!1);this.__drawHitPath(n),n.setStrokeOptions(e)},Ut.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__isAlphaPixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__maxStrokeWidth:n}=e,r=e.stroke&&("path"===a||"pixel"===a&&!e.__isAlphaPixelStroke)||"all"===a;if(!s&&!r)return!1;const h=2*t.radiusX;let o=h;if(r)switch(e.strokeAlign){case"inside":if(o+=2*n,!s&&this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h;break;case"center":o+=n;break;case"outside":if(o+=2*n,!s){if(!this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h}}return!!o&&this.__hitStroke(t,o)};const jt=i.prototype,Xt=s.prototype,Yt=a.prototype;Xt.__updateHitCanvas=Yt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?jt.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Xt.__hitFill=Yt.__hitFill=function(t){return this.__hitCanvas?jt.__hitFill.call(this,t):f.hitRadiusPoint(this.__layout.boxBounds,t)},n.prototype.__drawHitPath=function(t){const{__lineHeight:e,fontSize:i,__baseLine:s,__letterSpacing:a,__textDrawData:n}=this.__;t.beginPath(),a<0?this.__drawPathByBox(t):n.rows.forEach(a=>t.rect(a.x,a.y-s,a.width,e<i?i:e))},r.prototype.pick=function(t,e){return e||(e=h),this.updateLayout(),R.getSelector(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const zt=H.prototype;zt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},zt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},zt.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:n,radiusY:r}=t;e&&(s-=e.x,a-=e.y),B.set(s-n,a-r,2*n,2*r).scale(i).ceil();const{data:h}=this.context.getImageData(B.x,B.y,B.width||1,B.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};export{F as App,St as Cursor,tt as DragBoundsHelper,nt as DragEvent,Dt as Dragger,ht as DropEvent,kt as HitCanvasManager,Mt as InteractionBase,_t as InteractionHelper,pt as KeyEvent,K as Keyboard,ot as MoveEvent,rt as MyDragEvent,st as MyPointerEvent,gt as MyTouchEvent,W as PointerButton,it as PointerEvent,lt as RotateEvent,ct as SwipeEvent,dt as TouchEvent,V as UIEvent,ut as ZoomEvent};
1
+ import{Leafer as t,State as e,UI as i,Rect as s,Box as a,Text as n,Group as r,emptyData as h}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as o,Creator as d,isUndefined as g,DataHelper as l,canvasSizeAttrs as c,LayoutEvent as u,RenderEvent as p,Event as _,EventCreator as m,MathHelper as v,BoundsHelper as f,Bounds as y,isFinite as E,registerUIEvent as D,LeafList as P,PointHelper as x,LeafHelper as w,isString as O,isNumber as T,Debug as L,Platform as R,ResizeEvent as C,LeaferEvent as b,CanvasManager as M,Leaf as S,Matrix as A,tempBounds as k,ImageManager as B,LeaferCanvasBase as H}from"@leafer/core";function I(t,e,i,s){var a,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var h=t.length-1;h>=0;h--)(a=t[h])&&(r=(n<3?a(r):n>3?a(e,i,r):a(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}"function"==typeof SuppressedError&&SuppressedError;let F=class extends t{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,e){if(super.init(t,e),t){const{ground:e,tree:i,sky:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&d.editor(a,this)}}__setApp(){const{canvas:t}=this,{realCanvas:e,view:i}=this.config;e||i===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable()}__updateLocalBounds(){this.forEach(t=>t.updateLayout()),super.__updateLocalBounds()}start(){super.start(),this.forEach(t=>t.start())}stop(){this.forEach(t=>t.stop()),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach(t=>t.unlockLayout())}lockLayout(){super.lockLayout(),this.forEach(t=>t.lockLayout())}forceRender(t,e){this.forEach(i=>i.forceRender(t,e))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout(()=>this.add(t,e),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),g(e)||(t.canvas.childIndex=e),this.__listenChildEvents(t)}forEach(t){this.children.forEach(t)}__onCreated(){this.created=this.children.every(t=>t.created)}__onReady(){this.children.every(t=>t.ready)&&super.__onReady()}__onViewReady(){this.children.every(t=>t.viewReady)&&super.__onViewReady()}__onChildRenderEnd(t){this.renderer.addBlock(t.renderBounds),this.viewReady&&this.renderer.update()}__render(t,e){t.context&&this.forEach(i=>e.matrix?i.__render(t,e):t.copyWorld(i.canvas,e.bounds))}__onResize(t){this.forEach(e=>e.resize(t)),super.__onResize(t)}updateLayout(){this.forEach(t=>t.updateLayout())}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&l.assign(e,t),this.autoLayout&&l.copyAttrs(e,this,c),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once([[u.END,this.__onReady,this],[p.START,this.__onCreated,this],[p.END,this.__onViewReady,this]]),this.realCanvas&&this.__eventIds.push(t.on_(p.END,this.__onChildRenderEnd,this))}};F=I([o()],F);const N={},K={isHoldSpaceKey:()=>K.isHold("Space"),isHold:t=>N[t],isHoldKeys:(t,e)=>e?t(e):void 0,setDownCode(t){N[t]||(N[t]=!0)},setUpCode(t){N[t]=!1}},W={LEFT:1,RIGHT:2,MIDDLE:4,defaultLeft(t){t.buttons||(t.buttons=1)},left:t=>1===t.buttons,right:t=>2===t.buttons,middle:t=>4===t.buttons};class V extends _{get spaceKey(){return K.isHoldSpaceKey()}get left(){return W.left(this)}get right(){return W.right(this)}get middle(){return W.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}isHoldKeys(t){return K.isHoldKeys(t,this)}getBoxPoint(t){return(t||this.current).getBoxPoint(this)}getInnerPoint(t){return(t||this.current).getInnerPoint(this)}getLocalPoint(t){return(t||this.current).getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}getInner(t){return this.getInnerPoint(t)}getLocal(t){return this.getLocalPoint(t)}getPage(){return this.getPagePoint()}static changeName(t,e){m.changeName(t,e)}}const{min:U,max:j,abs:X}=Math,{float:Y,sign:z}=v,{minX:G,maxX:Z,minY:q,maxY:J}=f,Q=new y,$=new y,tt={limitMove(t,e){const{dragBounds:i,dragBoundsType:s}=t;i&&et.getValidMove(t.__localBoxBounds,et.getDragBounds(t),s,e,!0),et.axisMove(t,e)},limitScaleOf(t,e,i,s){const{dragBounds:a,dragBoundsType:n}=t;a&&et.getValidScaleOf(t.__localBoxBounds,et.getDragBounds(t),n,t.getLocalPointByInner(t.getInnerPointByBox(e)),i,s,!0)},axisMove(t,e){const{draggable:i}=t;"x"===i&&(e.y=0),"y"===i&&(e.x=0)},getDragBounds(t){const{dragBounds:e}=t;return"parent"===e?t.parent.boxBounds:e},isInnerMode:(t,e,i,s)=>"inner"===i||"auto"===i&&t[s]>e[s],getValidMove(t,e,i,s,a){const n=t.x+s.x,r=t.y+s.y,h=n+t.width,o=r+t.height,d=e.x+e.width,g=e.y+e.height;return a||(s=Object.assign({},s)),et.isInnerMode(t,e,i,"width")?n>e.x?s.x+=e.x-n:h<d&&(s.x+=d-h):n<e.x?s.x+=e.x-n:h>d&&(s.x+=d-h),et.isInnerMode(t,e,i,"height")?r>e.y?s.y+=e.y-r:o<g&&(s.y+=g-o):r<e.y?s.y+=e.y-r:o>g&&(s.y+=g-o),s.x=Y(s.x),s.y=Y(s.y),s},getValidScaleOf(t,e,i,s,a,n,r){r||(a=Object.assign({},a)),$.set(e),Q.set(t).scaleOf(s,a.x,a.y);const h=(s.x-t.x)/t.width,o=1-h,d=(s.y-t.y)/t.height,g=1-d;let l,c,u,p,_=1,m=1;return et.isInnerMode(t,e,i,"width")?(a.x<0&&Q.scaleOf(s,_=1/a.x,1),u=Y(Q.minX-$.minX),p=Y($.maxX-Q.maxX),l=h&&u>0?1+u/(h*Q.width):1,c=o&&p>0?1+p/(o*Q.width):1,_*=j(l,c)):(a.x<0&&((Y(G(t)-G(e))<=0||Y(Z(e)-Z(t))<=0)&&Q.scaleOf(s,_=1/a.x,1),Q.unsign()),u=Y($.minX-Q.minX),p=Y(Q.maxX-$.maxX),l=h&&u>0?1-u/(h*Q.width):1,c=o&&p>0?1-p/(o*Q.width):1,_*=U(l,c)),et.isInnerMode(t,e,i,"height")?(a.y<0&&Q.scaleOf(s,1,m=1/a.y),u=Y(Q.minY-$.minY),p=Y($.maxY-Q.maxY),l=d&&u>0?1+u/(d*Q.height):1,c=g&&p>0?1+p/(g*Q.height):1,m*=j(l,c),n&&(l=j(X(_),X(m)),_=z(_)*l,m=z(m)*l)):(a.y<0&&((Y(q(t)-q(e))<=0||Y(J(e)-J(t))<=0)&&Q.scaleOf(s,1,m=1/a.y),Q.unsign()),u=Y($.minY-Q.minY),p=Y(Q.maxY-$.maxY),l=d&&u>0?1-u/(d*Q.height):1,c=g&&p>0?1-p/(g*Q.height):1,m*=U(l,c)),a.x*=E(_)?_:1,a.y*=E(m)?m:1,a}},et=tt;let it=class extends V{};it.POINTER="pointer",it.BEFORE_DOWN="pointer.before_down",it.BEFORE_MOVE="pointer.before_move",it.BEFORE_UP="pointer.before_up",it.DOWN="pointer.down",it.MOVE="pointer.move",it.UP="pointer.up",it.OVER="pointer.over",it.OUT="pointer.out",it.ENTER="pointer.enter",it.LEAVE="pointer.leave",it.TAP="tap",it.DOUBLE_TAP="double_tap",it.CLICK="click",it.DOUBLE_CLICK="double_click",it.LONG_PRESS="long_press",it.LONG_TAP="long_tap",it.MENU="pointer.menu",it.MENU_TAP="pointer.menu_tap",it=I([D()],it);const st=it,at={};let nt=class extends it{static setList(t){this.list=t instanceof P?t:new P(t)}static setData(t){this.data=t}static getValidMove(t,e,i,s=!0){const a=t.getLocalPoint(i,null,!0);return x.move(a,e.x-t.x,e.y-t.y),s&&this.limitMove(t,a),tt.axisMove(t,a),a}static limitMove(t,e){tt.limitMove(t,e)}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(at,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(at,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(at,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}getPageBounds(){const t=this.getPageTotal(),e=this.getPagePoint(),i={};return f.set(i,e.x-t.x,e.y-t.y,t.x,t.y),f.unsign(i),i}assignMove(t){at.x=t?this.totalX:this.moveX,at.y=t?this.totalY:this.moveY}};nt.BEFORE_DRAG="drag.before_drag",nt.START="drag.start",nt.DRAG="drag",nt.END="drag.end",nt.OVER="drag.over",nt.OUT="drag.out",nt.ENTER="drag.enter",nt.LEAVE="drag.leave",nt=I([D()],nt);const rt=nt;let ht=class extends it{static setList(t){nt.setList(t)}static setData(t){nt.setData(t)}};ht.DROP="drop",ht=I([D()],ht);let ot=class extends nt{};ot.BEFORE_MOVE="move.before_move",ot.START="move.start",ot.MOVE="move",ot.DRAG_ANIMATE="move.drag_animate",ot.END="move.end",ot=I([D()],ot);let dt=class extends V{};dt=I([D()],dt);const gt=dt;let lt=class extends it{};lt.BEFORE_ROTATE="rotate.before_rotate",lt.START="rotate.start",lt.ROTATE="rotate",lt.END="rotate.end",lt=I([D()],lt);let ct=class extends nt{};ct.SWIPE="swipe",ct.LEFT="swipe.left",ct.RIGHT="swipe.right",ct.UP="swipe.up",ct.DOWN="swipe.down",ct=I([D()],ct);let ut=class extends it{};ut.BEFORE_ZOOM="zoom.before_zoom",ut.START="zoom.start",ut.ZOOM="zoom",ut.END="zoom.end",ut=I([D()],ut);let pt=class extends V{};pt.BEFORE_DOWN="key.before_down",pt.BEFORE_UP="key.before_up",pt.DOWN="key.down",pt.HOLD="key.hold",pt.UP="key.up",pt=I([D()],pt);const _t={getDragEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:i.x,y:i.y,moveX:i.x-e.x,moveY:i.y-e.y,totalX:i.x-t.x,totalY:i.y-t.y}),getDropEventData:(t,e,i)=>Object.assign(Object.assign({},t),{list:e,data:i}),getSwipeDirection:t=>t<-45&&t>-135?ct.UP:t>45&&t<135?ct.DOWN:t<=45&&t>=-45?ct.RIGHT:ct.LEFT,getSwipeEventData:(t,e,i)=>Object.assign(Object.assign({},i),{moveX:e.moveX,moveY:e.moveY,totalX:i.x-t.x,totalY:i.y-t.y,type:mt.getSwipeDirection(x.getAngle(t,i))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,time:Date.now(),buttons:g(t.buttons)?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new P,{list:s}=t;for(let t=0,a=s.length;t<a;t++)s[t].hasEvent(e)&&i.add(s[t]);return i},pathCanDrag:t=>t&&t.list.some(t=>w.draggable(t)||!t.isLeafer&&t.hasEvent(nt.DRAG)),pathHasOutside:t=>t&&t.list.some(t=>t.isOutside)},mt=_t,vt=new P,{getDragEventData:ft,getDropEventData:yt,getSwipeEventData:Et}=_t;class Dt{constructor(t){this.dragDataList=[],this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=ft(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=nt.list||this.draggableList||vt;return this.dragging&&(s?t?vt:new P(e?[...i.list,...i.dragHoverExclude]:i.list):a)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(ot.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&W.left(t),this.dragging&&(this.interaction.emit(nt.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach(t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y})}getDraggableList(t){let e;for(let i=0,s=t.length;i<s;i++)if(e=t.list[i],w.draggable(e)){this.draggableList=new P(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:n}=s;this.dragData=ft(s,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=a,this.dragDataList.push(this.dragData),this.moving?(t.moving=!0,this.dragData.moveType="drag",e.emit(ot.BEFORE_MOVE,this.dragData),e.emit(ot.MOVE,this.dragData)):this.dragging&&(t.dragging=!0,this.dragReal(),e.emit(nt.BEFORE_DRAG,this.dragData),e.emit(nt.DRAG,this.dragData))}dragReal(t){const{interaction:e}=this,{running:i}=e,s=this.realDraggableList;if(s.length&&i){const{totalX:i,totalY:a}=this.dragData,{dragLimitAnimate:n}=e.p,r=!n||!!t;s.forEach(e=>{if(e.draggable){const s=O(e.draggable),h=nt.getValidMove(e,this.dragStartPoints[e.innerId],{x:i,y:a},r||s);n&&!s&&t?w.animateMove(e,h,T(n)?n:.3):e.move(h)}})}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:s}=t;this.dragOverPath=s,i?s.indexAt(0)!==i.indexAt(0)&&(e.emit(nt.OUT,t,i),e.emit(nt.OVER,t,s)):e.emit(nt.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(nt.LEAVE,t,i,s),e.emit(nt.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t){(this.dragging||this.moving)&&(this.checkDragEndAnimate(t)||this.dragEndReal(t))}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:a,throughPath:n}=i,r=ft(i,t,t);if(n&&(r.throughPath=n),r.path=a,this.moving&&(this.moving=!1,r.moveType="drag",e.emit(ot.END,r)),this.dragging){const a=this.getList();this.dragging=!1,e.p.dragLimitAnimate&&this.dragReal(!0),e.emit(nt.END,r),this.swipe(t,i,s,r),this.drop(t,a,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}swipe(t,e,i,s){const{interaction:a}=this;if(x.getDistance(e,t)>a.config.pointer.swipeDistance){const t=Et(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=yt(t,e,nt.data);s.path=i,this.interaction.emit(ht.DROP,s),this.interaction.emit(nt.LEAVE,t,i)}dragReset(){nt.list=nt.data=this.draggableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null,this.dragDataList=[]}checkDragEndAnimate(t,e){return!1}animate(t,e){}stopAnimate(){}checkDragOut(t){}autoMoveOnDragOut(t){}autoMoveCancel(){}destroy(){this.dragReset()}}const Pt=L.get("emit");const xt=["move","zoom","rotate","key"];function wt(t,e,i,s,a){if(xt.some(t=>e.startsWith(t))&&t.__.hitChildren&&!Tt(t,a)){let n;for(let r=0,h=t.children.length;r<h;r++)n=t.children[r],!i.path.has(n)&&n.__.hittable&&Ot(n,e,i,s,a)}}function Ot(t,i,s,a,n){if(t.destroyed)return!1;if(t.__.hitSelf&&!Tt(t,n)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=m.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function Tt(t,e){return e&&e.has(t)}const Lt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{type:"pointer",snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:Rt,pathCanDrag:Ct,pathHasOutside:bt}=_t;class Mt{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.m.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.p.hover&&!this.config.mobile}get isDragEmpty(){return this.m.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.m.dragEmpty&&!this.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.m.holdMiddleKey&&this.downData&&W.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&W.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&K.isHoldSpaceKey()}get m(){return this.config.move}get p(){return this.config.pointer}get hitRadius(){return this.p.hitRadius}constructor(t,e,i,s){this.config=l.clone(Lt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new P(t),this.createTransformer(),this.dragger=new Dt(this),s&&(this.config=l.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(W.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(it.BEFORE_DOWN,t),this.emit(it.DOWN,t),W.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=W.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&W.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(it.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=x.getDistance(this.downData,t)>this.p.dragDistance;e&&(this.pointerWaitCancel(),this.waitRightTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(it.MOVE,t),this.pointerHover(t),this.dragging&&(this.dragger.dragOverOrOut(t),this.dragger.dragEnterOrLeave(t))),this.updateCursor(this.downData||t)}pointerUp(t){const{downData:e}=this;if(t||(t=e),!e)return;W.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(it.BEFORE_UP,t),this.emit(it.UP,t),this.touchLeave(t),t.isCancel||(this.tap(t),this.menuTap(t)),this.dragger.dragEnd(t),this.updateCursor(i)}pointerCancel(){const t=Object.assign({},this.dragger.dragData);t.isCancel=!0,this.pointerUp(t)}menu(t){this.findPath(t),this.emit(it.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(it.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}createTransformer(){}move(t){}zoom(t){}rotate(t){}transformEnd(){}wheel(t){}multiTouch(t,e){}keyDown(t){if(!this.config.keyEvent)return;this.emit(pt.BEFORE_DOWN,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,K.setDownCode(e),this.emit(pt.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(pt.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;this.emit(pt.BEFORE_UP,t,this.defaultPath);const{code:e}=t;this.downKeyMap[e]=!1,K.setUpCode(e),this.emit(pt.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new P),this.pointerOverOrOut(t),this.pointerEnterOrLeave(t))}pointerOverOrOut(t){const{path:e}=t,{overPath:i}=this;this.overPath=e,i?e.indexAt(0)!==i.indexAt(0)&&(this.emit(it.OUT,t,i),this.emit(it.OVER,t,e)):this.emit(it.OVER,t,e)}pointerEnterOrLeave(t){let{path:e}=t;this.downData&&!this.moveMode&&(e=e.clone(),this.downData.path.forEach(t=>e.add(t)));const{enterPath:i}=this;this.enterPath=e,this.emit(it.LEAVE,t,i,e),this.emit(it.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(it.LEAVE,t),this.dragger.dragging&&this.emit(ht.LEAVE,t))}tap(t){const{pointer:e}=this.config,i=this.longTap(t);if(!e.tapMore&&i)return;if(!this.waitTap)return;e.tapMore&&this.emitTap(t);const s=Date.now()-this.downTime,a=[it.DOUBLE_TAP,it.DOUBLE_CLICK].some(e=>Rt(t.path,e));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout(()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))},e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.p,{bottomList:a,target:n}=this;R.backgrounder||t.origin||n&&n.updateLayout();const r=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));return r.throughPath&&(t.throughPath=r.throughPath),t.path=r.path,r.path}isRootPath(t){return t&&t.path.list[0].isLeafer}isTreePath(t){const e=this.target.app;return!(!e||!e.isApp)&&(e.editor&&!t.path.has(e.editor)&&t.path.has(e.tree)&&!t.target.syncEventer)}checkPath(t,e){(e||this.moveMode&&!bt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!Ct(t.path))&&!bt(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}stopDragAnimate(){this.dragger.stopAnimate()}updateDownData(t,e,i){const{downData:s}=this;!t&&s&&(t=s),t&&(this.findPath(t,e),i&&s&&t.path.addList(s.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(!1,!0),name:it.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e),s={x:t.clientX-i.x,y:t.clientY-i.y},{bounds:a}=this.canvas;return s.x*=a.width/i.width,s.y*=a.height/i.height,this.p.snap&&x.round(s),s}emitTap(t){this.emit(it.TAP,t),this.emit(it.CLICK,t)}emitDoubleTap(t){this.emit(it.DOUBLE_TAP,t),this.emit(it.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){this.waitTap&&(clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0)}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout(()=>{this.longPressed=!0,this.emit(it.LONG_PRESS,t)},this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(it.LONG_TAP,t),(Rt(t.path,it.LONG_TAP)||Rt(t.path,it.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressed=!1)}__onResize(){const{dragOut:t}=this.m;this.shrinkCanvasBounds=new y(this.canvas.bounds),this.shrinkCanvasBounds.spread(-(T(t)?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(C.RESIZE,this.__onResize,this)],t.once(b.READY,()=>this.__onResize())}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}emit(t,e,i,s){this.running&&function(t,e,i,s){if(!i&&!e.path)return;let a;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let n=i.length-1;n>-1;n--){if(a=i.list[n],Ot(a,t,e,!0,s))return;a.isApp&&wt(a,t,e,!0,s)}for(let n=0,r=i.length;n<r;n++)if(a=i.list[n],a.isApp&&wt(a,t,e,!1,s),Ot(a,t,e,!1,s))return}catch(t){Pt.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer&&this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class St{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}St.custom={};class At extends M{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new P,this.pixelList=new P}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),d.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),d.hitCanvas()}clearImageType(){this.__clearLeafList(this.pixelList)}clearPathType(){this.__clearLeafList(this.pathList)}__clearLeafList(t){t.length&&(t.forEach(t=>{t.__hitCanvas&&(t.__hitCanvas.destroy(),t.__hitCanvas=null)}),t.reset())}__autoClear(){this.pathList.length+this.pixelList.length>this.maxTotal&&this.clear()}clear(){this.clearPathType(),this.clearImageType()}}R.getSelector=function(t){return t.leafer?t.leafer.selector:R.selector||(R.selector=d.selector())};const{toInnerRadiusPointOf:kt,copyRadiusPoint:Bt}=x,{hitRadiusPoint:Ht,hitPoint:It}=f,Ft={},Nt={},Kt=S.prototype;Kt.hit=function(t,e=0){this.updateLayout(),Bt(Nt,t,e);const i=this.__world;return!!(e?Ht(i,Nt):It(i,Nt))&&(this.isBranch?R.getSelector(this).hitPoint(Object.assign({},Nt),e,{target:this}):this.__hitWorld(Nt))},Kt.__hitWorld=function(t,e){const i=this.__;if(!i.hitSelf)return!1;const s=this.__world,a=this.__layout,n=s.width<10&&s.height<10;if(i.hitRadius&&(Bt(Ft,t,i.hitRadius),t=Ft),kt(t,s,Ft),i.hitBox||n){if(f.hitRadiusPoint(a.boxBounds,Ft))return!0;if(n)return!1}return!a.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),a.boundsChanged||(a.hitCanvasChanged=!1)),this.__hit(Ft,e)},Kt.__hitFill=function(t){const e=this.__hitCanvas;return e&&e.hitFill(t,this.__.windingRule)},Kt.__hitStroke=function(t,e){const i=this.__hitCanvas;return i&&i.hitStroke(t,e)},Kt.__hitPixel=function(t){const e=this.__hitCanvas;return e&&e.hitPixel(t,this.__layout.renderBounds,e.hitScale)},Kt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Wt=new A,Vt=i.prototype;Vt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const{hitCanvasManager:t}=this.leafer||this.parent&&this.parent.leafer||{};if(!t)return;const e=this.__,i=(e.__isAlphaPixelFill||e.__isCanvas)&&"pixel"===e.hitFill,s=e.__isAlphaPixelStroke&&"pixel"===e.hitStroke,a=i||s;this.__hitCanvas||(this.__hitCanvas=a?t.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):t.getPathType(this));const n=this.__hitCanvas;if(a){const{renderBounds:t}=this.__layout,a=R.image.hitCanvasSize,r=n.hitScale=k.set(0,0,a,a).getFitMatrix(t).a,{x:h,y:o,width:d,height:g}=k.set(t).scale(r);n.resize({width:d,height:g,pixelRatio:1}),n.clear(),B.patternLocked=!0,this.__renderShape(n,{matrix:Wt.setWith(this.__world).scaleWith(1/r).invertWith().translate(-h,-o),ignoreFill:!i,ignoreStroke:!s}),B.patternLocked=!1,n.resetTransform(),e.__isHitPixel=!0}else e.__isHitPixel&&(e.__isHitPixel=!1);this.__drawHitPath(n),n.setStrokeOptions(e)},Vt.__hit=function(t,e){if(this.__box&&this.__box.__hit(t))return!0;const i=this.__;if(i.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:s}=i,a=(i.fill||i.__isCanvas)&&("path"===s||"pixel"===s&&!(i.__isAlphaPixelFill||i.__isCanvas))||"all"===s||e;if(a&&this.__hitFill(t))return!0;const{hitStroke:n,__maxStrokeWidth:r}=i,h=i.stroke&&("path"===n||"pixel"===n&&!i.__isAlphaPixelStroke)||"all"===n;if(!a&&!h)return!1;const o=2*t.radiusX;let d=o;if(h)switch(i.strokeAlign){case"inside":if(d+=2*r,!a&&this.__hitFill(t)&&this.__hitStroke(t,d))return!0;d=o;break;case"center":d+=r;break;case"outside":if(d+=2*r,!a){if(!this.__hitFill(t)&&this.__hitStroke(t,d))return!0;d=o}}return!!d&&this.__hitStroke(t,d)};const Ut=i.prototype,jt=s.prototype,Xt=a.prototype;jt.__updateHitCanvas=Xt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Ut.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},jt.__hitFill=Xt.__hitFill=function(t){return this.__hitCanvas?Ut.__hitFill.call(this,t):f.hitRadiusPoint(this.__layout.boxBounds,t)},n.prototype.__drawHitPath=function(t){const{__lineHeight:e,fontSize:i,__baseLine:s,__letterSpacing:a,__textDrawData:n}=this.__;t.beginPath(),a<0?this.__drawPathByBox(t):n.rows.forEach(a=>t.rect(a.x,a.y-s,a.width,e<i?i:e))},r.prototype.pick=function(t,e){return e||(e=h),this.updateLayout(),R.getSelector(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const Yt=H.prototype;Yt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},Yt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},Yt.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:n,radiusY:r}=t;e&&(s-=e.x,a-=e.y),k.set(s-n,a-r,2*n,2*r).scale(i).ceil();const{data:h}=this.context.getImageData(k.x,k.y,k.width||1,k.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};export{F as App,St as Cursor,tt as DragBoundsHelper,nt as DragEvent,Dt as Dragger,ht as DropEvent,At as HitCanvasManager,Mt as InteractionBase,_t as InteractionHelper,pt as KeyEvent,K as Keyboard,ot as MoveEvent,rt as MyDragEvent,st as MyPointerEvent,gt as MyTouchEvent,W as PointerButton,it as PointerEvent,lt as RotateEvent,ct as SwipeEvent,dt as TouchEvent,V as UIEvent,ut as ZoomEvent};
2
2
  //# sourceMappingURL=core.esm.min.js.map