@leafer-ui/core 1.0.0-rc.21 → 1.0.0-rc.22

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
@@ -124,7 +124,8 @@ exports.App = class App extends draw.Leafer {
124
124
  this.renderer.update();
125
125
  }
126
126
  __render(canvas, options) {
127
- canvas.setWorld(options.matrix || this.__world);
127
+ if (options.matrix)
128
+ canvas.setWorld(options.matrix);
128
129
  this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
129
130
  }
130
131
  __onResize(event) {
@@ -246,6 +247,35 @@ exports.DragEvent = class DragEvent extends exports.PointerEvent {
246
247
  static setData(data) {
247
248
  this.data = data;
248
249
  }
250
+ static getValidMove(leaf, start, total) {
251
+ const { draggable, dragBounds, x, y } = leaf;
252
+ const move = leaf.getLocalPoint(total, null, true);
253
+ move.x += start.x - x;
254
+ move.y += start.y - y;
255
+ if (dragBounds)
256
+ this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
257
+ if (draggable === 'x')
258
+ move.y = 0;
259
+ if (draggable === 'y')
260
+ move.x = 0;
261
+ return move;
262
+ }
263
+ static getMoveInDragBounds(box, dragBounds, move, change) {
264
+ const x = box.x + move.x, y = box.y + move.y;
265
+ const right = x + box.width, bottom = y + box.height;
266
+ const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
267
+ if (!change)
268
+ move = Object.assign({}, move);
269
+ if (x < dragBounds.x)
270
+ move.x += dragBounds.x - x;
271
+ else if (right > boundsRight)
272
+ move.x += boundsRight - right;
273
+ if (y < dragBounds.y)
274
+ move.y += dragBounds.y - y;
275
+ else if (bottom > boundsBottom)
276
+ move.y += boundsBottom - bottom;
277
+ return move;
278
+ }
249
279
  getPageMove(total) {
250
280
  this.assignMove(total);
251
281
  return this.current.getPagePoint(move, null, true);
@@ -355,9 +385,7 @@ function addInteractionWindow(leafer) {
355
385
  if (leafer.isApp)
356
386
  return;
357
387
  leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, (e) => {
358
- const { x, y } = leafer.getValidMove(e.moveX, e.moveY);
359
- if (x || y)
360
- leafer.zoomLayer.move(x, y);
388
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
361
389
  }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
362
390
  const { zoomLayer } = leafer;
363
391
  const changeScale = leafer.getValidScale(e.scale);
@@ -626,9 +654,14 @@ class Dragger {
626
654
  if (this.dragging) {
627
655
  this.interaction.emit(exports.DragEvent.START, this.dragData);
628
656
  this.getDragableList(this.dragData.path);
657
+ this.setDragStartPoints(this.realDragableList = this.getList());
629
658
  }
630
659
  }
631
660
  }
661
+ setDragStartPoints(list) {
662
+ this.dragStartPoints = {};
663
+ list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
664
+ }
632
665
  getDragableList(path) {
633
666
  let leaf;
634
667
  for (let i = 0, len = path.length; i < len; i++) {
@@ -658,10 +691,10 @@ class Dragger {
658
691
  }
659
692
  dragReal() {
660
693
  const { running } = this.interaction;
661
- const list = this.getList();
694
+ const list = this.realDragableList;
662
695
  if (list.length && running) {
663
- const { moveX, moveY } = this.dragData;
664
- list.forEach(leaf => leaf.draggable && leaf.moveWorld(moveX, moveY));
696
+ const { totalX, totalY } = this.dragData;
697
+ list.forEach(leaf => leaf.draggable && leaf.move(exports.DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
665
698
  }
666
699
  }
667
700
  dragOverOrOut(data) {
@@ -1130,7 +1163,8 @@ class InteractionBase {
1130
1163
  }
1131
1164
  findPath(data, options) {
1132
1165
  const { hitRadius, through } = this.config.pointer;
1133
- const find = this.selector.getByPoint(data, hitRadius, options || { through });
1166
+ const { bottomList } = this;
1167
+ const find = this.selector.getByPoint(data, hitRadius, Object.assign({ bottomList, name: data.type }, (options || { through })));
1134
1168
  if (find.throughPath)
1135
1169
  data.throughPath = find.throughPath;
1136
1170
  data.path = find.path;
@@ -1143,7 +1177,7 @@ class InteractionBase {
1143
1177
  const app = this.target.app;
1144
1178
  if (!app || !app.isApp)
1145
1179
  return false;
1146
- return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree));
1180
+ return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
1147
1181
  }
1148
1182
  checkPath(data, useDefaultPath) {
1149
1183
  if (useDefaultPath || this.canMove(data))
@@ -1209,7 +1243,7 @@ class InteractionBase {
1209
1243
  const { path } = data;
1210
1244
  for (let i = 0, len = path.length; i < len; i++) {
1211
1245
  leaf = path.list[i];
1212
- cursor = leaf.cursor;
1246
+ cursor = leaf.syncEventer ? leaf.syncEventer.cursor : leaf.cursor;
1213
1247
  if (cursor)
1214
1248
  break;
1215
1249
  }
@@ -1367,6 +1401,8 @@ const { toInnerRadiusPointOf, copy, setRadius } = core.PointHelper;
1367
1401
  const inner = {};
1368
1402
  const leaf = core.Leaf.prototype;
1369
1403
  leaf.__hitWorld = function (point) {
1404
+ if (!this.__.hitSelf)
1405
+ return false;
1370
1406
  if (this.__.hitRadius) {
1371
1407
  copy(inner, point), point = inner;
1372
1408
  setRadius(point, this.__.hitRadius);
@@ -1394,8 +1430,8 @@ leaf.__drawHitPath = function (canvas) { if (canvas)
1394
1430
  this.__drawRenderPath(canvas); };
1395
1431
 
1396
1432
  const matrix = new core.Matrix();
1397
- const ui$1 = draw.UI.prototype;
1398
- ui$1.__updateHitCanvas = function () {
1433
+ const ui$2 = draw.UI.prototype;
1434
+ ui$2.__updateHitCanvas = function () {
1399
1435
  const data = this.__, { hitCanvasManager } = this.leafer;
1400
1436
  const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
1401
1437
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -1422,7 +1458,7 @@ ui$1.__updateHitCanvas = function () {
1422
1458
  this.__drawHitPath(h);
1423
1459
  h.setStrokeOptions(data);
1424
1460
  };
1425
- ui$1.__hit = function (inner) {
1461
+ ui$2.__hit = function (inner) {
1426
1462
  if (core.Platform.name === 'miniapp')
1427
1463
  this.__drawHitPath(this.__hitCanvas);
1428
1464
  const data = this.__;
@@ -1462,22 +1498,24 @@ ui$1.__hit = function (inner) {
1462
1498
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
1463
1499
  };
1464
1500
 
1465
- const ui = new draw.UI();
1466
- draw.Rect.prototype.__updateHitCanvas = function () {
1501
+ const ui$1 = new draw.UI();
1502
+ const rect = draw.Rect.prototype;
1503
+ rect.__updateHitCanvas = function () {
1467
1504
  if (this.stroke || this.cornerRadius)
1468
- ui.__updateHitCanvas.call(this);
1505
+ ui$1.__updateHitCanvas.call(this);
1469
1506
  };
1470
- draw.Rect.prototype.__hitFill = function (inner) {
1471
- return this.__hitCanvas ? ui.__hitFill.call(this, inner) : core.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1507
+ rect.__hitFill = function (inner) {
1508
+ return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : core.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1472
1509
  };
1473
1510
 
1474
- draw.UI.prototype.find = function (condition, options) {
1511
+ const ui = draw.UI.prototype, group = draw.Group.prototype;
1512
+ ui.find = function (condition, options) {
1475
1513
  return this.leafer ? this.leafer.selector.getBy(condition, this, false, options) : [];
1476
1514
  };
1477
- draw.UI.prototype.findOne = function (condition, options) {
1515
+ ui.findOne = function (condition, options) {
1478
1516
  return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
1479
1517
  };
1480
- draw.Group.prototype.pick = function (hitPoint, options) {
1518
+ group.pick = function (hitPoint, options) {
1481
1519
  this.__layout.update();
1482
1520
  if (!options)
1483
1521
  options = {};
package/lib/core.esm.js CHANGED
@@ -123,7 +123,8 @@ let App = class App extends Leafer {
123
123
  this.renderer.update();
124
124
  }
125
125
  __render(canvas, options) {
126
- canvas.setWorld(options.matrix || this.__world);
126
+ if (options.matrix)
127
+ canvas.setWorld(options.matrix);
127
128
  this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
128
129
  }
129
130
  __onResize(event) {
@@ -245,6 +246,35 @@ let DragEvent = class DragEvent extends PointerEvent {
245
246
  static setData(data) {
246
247
  this.data = data;
247
248
  }
249
+ static getValidMove(leaf, start, total) {
250
+ const { draggable, dragBounds, x, y } = leaf;
251
+ const move = leaf.getLocalPoint(total, null, true);
252
+ move.x += start.x - x;
253
+ move.y += start.y - y;
254
+ if (dragBounds)
255
+ this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
256
+ if (draggable === 'x')
257
+ move.y = 0;
258
+ if (draggable === 'y')
259
+ move.x = 0;
260
+ return move;
261
+ }
262
+ static getMoveInDragBounds(box, dragBounds, move, change) {
263
+ const x = box.x + move.x, y = box.y + move.y;
264
+ const right = x + box.width, bottom = y + box.height;
265
+ const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
266
+ if (!change)
267
+ move = Object.assign({}, move);
268
+ if (x < dragBounds.x)
269
+ move.x += dragBounds.x - x;
270
+ else if (right > boundsRight)
271
+ move.x += boundsRight - right;
272
+ if (y < dragBounds.y)
273
+ move.y += dragBounds.y - y;
274
+ else if (bottom > boundsBottom)
275
+ move.y += boundsBottom - bottom;
276
+ return move;
277
+ }
248
278
  getPageMove(total) {
249
279
  this.assignMove(total);
250
280
  return this.current.getPagePoint(move, null, true);
@@ -354,9 +384,7 @@ function addInteractionWindow(leafer) {
354
384
  if (leafer.isApp)
355
385
  return;
356
386
  leafer.__eventIds.push(leafer.on_(MoveEvent.BEFORE_MOVE, (e) => {
357
- const { x, y } = leafer.getValidMove(e.moveX, e.moveY);
358
- if (x || y)
359
- leafer.zoomLayer.move(x, y);
387
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
360
388
  }), leafer.on_(ZoomEvent.BEFORE_ZOOM, (e) => {
361
389
  const { zoomLayer } = leafer;
362
390
  const changeScale = leafer.getValidScale(e.scale);
@@ -625,9 +653,14 @@ class Dragger {
625
653
  if (this.dragging) {
626
654
  this.interaction.emit(DragEvent.START, this.dragData);
627
655
  this.getDragableList(this.dragData.path);
656
+ this.setDragStartPoints(this.realDragableList = this.getList());
628
657
  }
629
658
  }
630
659
  }
660
+ setDragStartPoints(list) {
661
+ this.dragStartPoints = {};
662
+ list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
663
+ }
631
664
  getDragableList(path) {
632
665
  let leaf;
633
666
  for (let i = 0, len = path.length; i < len; i++) {
@@ -657,10 +690,10 @@ class Dragger {
657
690
  }
658
691
  dragReal() {
659
692
  const { running } = this.interaction;
660
- const list = this.getList();
693
+ const list = this.realDragableList;
661
694
  if (list.length && running) {
662
- const { moveX, moveY } = this.dragData;
663
- list.forEach(leaf => leaf.draggable && leaf.moveWorld(moveX, moveY));
695
+ const { totalX, totalY } = this.dragData;
696
+ list.forEach(leaf => leaf.draggable && leaf.move(DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
664
697
  }
665
698
  }
666
699
  dragOverOrOut(data) {
@@ -1129,7 +1162,8 @@ class InteractionBase {
1129
1162
  }
1130
1163
  findPath(data, options) {
1131
1164
  const { hitRadius, through } = this.config.pointer;
1132
- const find = this.selector.getByPoint(data, hitRadius, options || { through });
1165
+ const { bottomList } = this;
1166
+ const find = this.selector.getByPoint(data, hitRadius, Object.assign({ bottomList, name: data.type }, (options || { through })));
1133
1167
  if (find.throughPath)
1134
1168
  data.throughPath = find.throughPath;
1135
1169
  data.path = find.path;
@@ -1142,7 +1176,7 @@ class InteractionBase {
1142
1176
  const app = this.target.app;
1143
1177
  if (!app || !app.isApp)
1144
1178
  return false;
1145
- return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree));
1179
+ return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
1146
1180
  }
1147
1181
  checkPath(data, useDefaultPath) {
1148
1182
  if (useDefaultPath || this.canMove(data))
@@ -1208,7 +1242,7 @@ class InteractionBase {
1208
1242
  const { path } = data;
1209
1243
  for (let i = 0, len = path.length; i < len; i++) {
1210
1244
  leaf = path.list[i];
1211
- cursor = leaf.cursor;
1245
+ cursor = leaf.syncEventer ? leaf.syncEventer.cursor : leaf.cursor;
1212
1246
  if (cursor)
1213
1247
  break;
1214
1248
  }
@@ -1366,6 +1400,8 @@ const { toInnerRadiusPointOf, copy, setRadius } = PointHelper;
1366
1400
  const inner = {};
1367
1401
  const leaf = Leaf.prototype;
1368
1402
  leaf.__hitWorld = function (point) {
1403
+ if (!this.__.hitSelf)
1404
+ return false;
1369
1405
  if (this.__.hitRadius) {
1370
1406
  copy(inner, point), point = inner;
1371
1407
  setRadius(point, this.__.hitRadius);
@@ -1393,8 +1429,8 @@ leaf.__drawHitPath = function (canvas) { if (canvas)
1393
1429
  this.__drawRenderPath(canvas); };
1394
1430
 
1395
1431
  const matrix = new Matrix();
1396
- const ui$1 = UI.prototype;
1397
- ui$1.__updateHitCanvas = function () {
1432
+ const ui$2 = UI.prototype;
1433
+ ui$2.__updateHitCanvas = function () {
1398
1434
  const data = this.__, { hitCanvasManager } = this.leafer;
1399
1435
  const isHitPixelFill = data.__pixelFill && data.hitFill === 'pixel';
1400
1436
  const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel';
@@ -1421,7 +1457,7 @@ ui$1.__updateHitCanvas = function () {
1421
1457
  this.__drawHitPath(h);
1422
1458
  h.setStrokeOptions(data);
1423
1459
  };
1424
- ui$1.__hit = function (inner) {
1460
+ ui$2.__hit = function (inner) {
1425
1461
  if (Platform.name === 'miniapp')
1426
1462
  this.__drawHitPath(this.__hitCanvas);
1427
1463
  const data = this.__;
@@ -1461,22 +1497,24 @@ ui$1.__hit = function (inner) {
1461
1497
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
1462
1498
  };
1463
1499
 
1464
- const ui = new UI();
1465
- Rect.prototype.__updateHitCanvas = function () {
1500
+ const ui$1 = new UI();
1501
+ const rect = Rect.prototype;
1502
+ rect.__updateHitCanvas = function () {
1466
1503
  if (this.stroke || this.cornerRadius)
1467
- ui.__updateHitCanvas.call(this);
1504
+ ui$1.__updateHitCanvas.call(this);
1468
1505
  };
1469
- Rect.prototype.__hitFill = function (inner) {
1470
- return this.__hitCanvas ? ui.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1506
+ rect.__hitFill = function (inner) {
1507
+ return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1471
1508
  };
1472
1509
 
1473
- UI.prototype.find = function (condition, options) {
1510
+ const ui = UI.prototype, group = Group.prototype;
1511
+ ui.find = function (condition, options) {
1474
1512
  return this.leafer ? this.leafer.selector.getBy(condition, this, false, options) : [];
1475
1513
  };
1476
- UI.prototype.findOne = function (condition, options) {
1514
+ ui.findOne = function (condition, options) {
1477
1515
  return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
1478
1516
  };
1479
- Group.prototype.pick = function (hitPoint, options) {
1517
+ group.pick = function (hitPoint, options) {
1480
1518
  this.__layout.update();
1481
1519
  if (!options)
1482
1520
  options = {};
@@ -1 +1 @@
1
- import{Leafer as t,State as e,UI as i,ImageManager as a,Rect as s,Group as n}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as r,Creator as o,PropertyEvent as h,Debug as d,DataHelper as c,canvasSizeAttrs as l,LayoutEvent as g,RenderEvent as u,Event as p,EventCreator as m,registerUIEvent as _,LeafList as v,PointHelper as f,Bounds as E,BoundsHelper as D,ResizeEvent as y,LeaferEvent as O,CanvasManager as P,LeaferCanvasBase as T,tempBounds as w,Leaf as R,Matrix as C,Platform as L}from"@leafer/core";function b(t,e,i,a){var s,n=arguments.length,r=n<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,i):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,a);else for(var o=t.length-1;o>=0;o--)(s=t[o])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}"function"==typeof SuppressedError&&SuppressedError;let x=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:a,editor:s}=t;e&&(this.ground=this.addLeafer(e)),(i||s)&&(this.tree=this.addLeafer(i)),(a||s)&&(this.sky=this.addLeafer(a||{type:"draw",usePartRender:!1})),s&&(this.editor=o.editor(s),this.sky.add(this.editor))}}__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(),this.__eventIds.push(this.on_(h.CHANGE,this.__onPropertyChange,this))}start(){super.start(),this.children.forEach((t=>t.start()))}stop(){this.children.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.children.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.children.forEach((t=>t.lockLayout()))}forceRender(t){this.children.forEach((e=>e.forceRender(t)))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t),this.__listenChildEvents(t)}__onPropertyChange(){d.showHitView&&this.children.forEach((t=>t.forceUpdate("surface")))}__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.setWorld(e.matrix||this.__world),this.children.forEach((e=>t.copyWorld(e.canvas)))}__onResize(t){this.children.forEach((e=>e.resize(t))),super.__onResize(t)}__checkUpdateLayout(){this.children.forEach((t=>t.__layout.update()))}__getChildConfig(t){let e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&c.assign(e,t),this.autoLayout&&c.copyAttrs(e,this,l),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once(g.END,(()=>this.__onReady())),t.once(u.START,(()=>this.__onCreated())),t.once(u.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(u.END,this.__onChildRenderEnd,this))}};x=b([r()],x);const M={},S={isHoldSpaceKey:()=>S.isHold("Space"),isHold:t=>M[t],setDownCode(t){M[t]||(M[t]=!0)},setUpCode(t){M[t]=!1}},A={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 k extends p{get spaceKey(){return S.isHoldSpaceKey()}get left(){return A.left(this)}get right(){return A.right(this)}get middle(){return A.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}getPage(){return this.current.getPagePoint(this)}getInner(t){return t||(t=this.current),t.getInnerPoint(this)}getLocal(t){return t||(t=this.current),t.getLocalPoint(this)}static changeName(t,e){m.changeName(t,e)}}let H=class extends k{};H.POINTER="pointer",H.BEFORE_DOWN="pointer.before_down",H.BEFORE_MOVE="pointer.before_move",H.BEFORE_UP="pointer.before_up",H.DOWN="pointer.down",H.MOVE="pointer.move",H.UP="pointer.up",H.OVER="pointer.over",H.OUT="pointer.out",H.ENTER="pointer.enter",H.LEAVE="pointer.leave",H.TAP="tap",H.DOUBLE_TAP="double_tap",H.CLICK="click",H.DOUBLE_CLICK="double_click",H.LONG_PRESS="long_press",H.LONG_TAP="long_tap",H.MENU="pointer.menu",H.MENU_TAP="pointer.menu_tap",H=b([_()],H);const B={};let W=class extends H{static setList(t){this.list=t instanceof v?t:new v(t)}static setData(t){this.data=t}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(B,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(B,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(B,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}assignMove(t){B.x=t?this.totalX:this.moveX,B.y=t?this.totalY:this.moveY}};W.BEFORE_DRAG="drag.before_drag",W.START="drag.start",W.DRAG="drag",W.END="drag.end",W.OVER="drag.over",W.OUT="drag.out",W.ENTER="drag.enter",W.LEAVE="drag.leave",W=b([_()],W);let N=class extends H{static setList(t){W.setList(t)}static setData(t){W.setData(t)}};N.DROP="drop",N=b([_()],N);let z=class extends W{};z.BEFORE_MOVE="move.before_move",z.START="move.start",z.MOVE="move",z.END="move.end",z=b([_()],z);let F=class extends k{};F.BEFORE_ROTATE="rotate.before_rotate",F.START="rotate.start",F.ROTATE="rotate",F.END="rotate.end",F=b([_()],F);let I=class extends W{};I.SWIPE="swipe",I.LEFT="swipe.left",I.RIGHT="swipe.right",I.UP="swipe.up",I.DOWN="swipe.down",I=b([_()],I);let V=class extends k{};V.BEFORE_ZOOM="zoom.before_zoom",V.START="zoom.start",V.ZOOM="zoom",V.END="zoom.end",V=b([_()],V);let j=class extends k{};function K(t){t.isApp||t.__eventIds.push(t.on_(z.BEFORE_MOVE,(e=>{const{x:i,y:a}=t.getValidMove(e.moveX,e.moveY);(i||a)&&t.zoomLayer.move(i,a)})),t.on_(V.BEFORE_ZOOM,(e=>{const{zoomLayer:i}=t,a=t.getValidScale(e.scale);1!==a&&(f.scaleOf(i,e,a),i.scale=i.__.scaleX*a)})))}j.DOWN="key.down",j.HOLD="key.hold",j.UP="key.up",j=b([_()],j);const U=d.get("LeaferTypeCreator"),X={list:{},register(t,e){Y[t]?U.repeat(t):Y[t]=e},run(t,e){const i=Y[t];i?i(e):U.error("no",t)}},{list:Y,register:G}=X;G("draw",(()=>{})),G("design",K),G("document",(function(t){K(t),t.config.move.scroll="limit",t.config.zoom.min=1})),t.prototype.initType=function(t){X.run(t,this)},t.prototype.getValidMove=function(t,e){const{scroll:i,disabled:a}=this.app.config.move;if(i&&(Math.abs(t)>Math.abs(e)?e=0:t=0,"limit"===i)){const{x:i,y:a,width:s,height:n}=new E(this.__world).addPoint(this.zoomLayer),r=i+s-this.width,o=a+n-this.height;i>=0&&r<=0?t=0:t>0?i+t>0&&(t=-i):t<0&&r+t<0&&(t=-r),a>=0&&o<=0?e=0:e>0?a+e>0&&(e=-a):e<0&&o+e<0&&(e=-o)}return{x:a?0:t,y:a?0:e}},t.prototype.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:i,max:a,disabled:s}=this.app.config.zoom,n=Math.abs(e*t);return n<i?t=i/e:n>a&&(t=a/e),s?1:t};class Z{constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(!this.moveData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.moveData=Object.assign(Object.assign({},t),{moveX:0,moveY:0}),e.cancelHover(),e.emit(z.START,this.moveData)}t.path=this.moveData.path,e.emit(z.BEFORE_MOVE,t),e.emit(z.MOVE,t),this.transformEndWait()}zoom(t){const{interaction:e}=this;if(!this.zoomData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.zoomData=Object.assign(Object.assign({},t),{scale:1}),e.cancelHover(),e.emit(V.START,this.zoomData)}t.path=this.zoomData.path,e.emit(V.BEFORE_ZOOM,t),e.emit(V.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:e}=this;if(!this.rotateData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),e.cancelHover(),e.emit(F.START,this.rotateData)}t.path=this.rotateData.path,e.emit(F.BEFORE_ROTATE,t),e.emit(F.ROTATE,t),this.transformEndWait()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout((()=>{this.transformEnd()}),this.interaction.config.pointer.transformTime)}transformEnd(){this.moveEnd(),this.zoomEnd(),this.rotateEnd()}moveEnd(){this.moveData&&(this.interaction.emit(z.END,this.moveData),this.moveData=null)}zoomEnd(){this.zoomData&&(this.interaction.emit(V.END,this.zoomData),this.zoomData=null)}rotateEnd(){this.rotateData&&(this.interaction.emit(F.END,this.rotateData),this.rotateData=null)}destroy(){this.zoomData=this.moveData=this.rotateData=null}}const q={getMoveEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,moveX:e.x,moveY:e.y}),getRotateEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,rotation:e}),getZoomEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,scale:e}),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?I.UP:t>45&&t<135?I.DOWN:t<=45&&t>=-45?I.RIGHT:I.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:J.getSwipeDirection(f.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:void 0===t.buttons?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,a=i.length;t<a;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new v,{list:a}=t;for(let t=0,s=a.length;t<s;t++)a[t].hasEvent(e)&&i.add(a[t]);return i}},J=q,Q=new v,{getDragEventData:$,getDropEventData:tt,getSwipeEventData:et}=q;class it{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=$(t,t,t),this.canAnimate=this.canDragOut=!0}getList(){const{proxy:t}=this.interaction.selector;return!this.dragging||t&&t.list.length?Q:W.list||this.dragableList||Q}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)&&i.emit(z.START,this.dragData),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&A.left(t),this.dragging&&(this.interaction.emit(W.START,this.dragData),this.getDragableList(this.dragData.path)))}getDragableList(t){let e;for(let i=0,a=t.length;i<a;i++)if(e=t.list[i],(e.__.draggable||e.__.editable)&&e.__.hitSelf&&!e.__.locked){this.dragableList=new v(e);break}}drag(t){const{interaction:e,dragData:i,downData:a}=this,{path:s,throughPath:n}=a;this.dragData=$(a,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=s,this.moving?(e.emit(z.BEFORE_MOVE,this.dragData),e.emit(z.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(W.BEFORE_DRAG,this.dragData),e.emit(W.DRAG,this.dragData))}dragReal(){const{running:t}=this.interaction,e=this.getList();if(e.length&&t){const{moveX:t,moveY:i}=this.dragData;e.forEach((e=>e.draggable&&e.moveWorld(t,i)))}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:a}=t;this.dragOverPath=a,i?a.indexAt(0)!==i.indexAt(0)&&(e.emit(W.OUT,t,i),e.emit(W.OVER,t,a)):e.emit(W.OVER,t,a)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:a}=t;e.emit(W.LEAVE,t,i,a),e.emit(W.ENTER,t,a,i),this.dragEnterPath=a}dragEnd(t,e){if(!this.dragging&&!this.moving)return;const{moveX:i,moveY:a}=this.dragData;this.interaction.config.move.dragAnimate&&this.canAnimate&&this.moving&&(Math.abs(i)>1||Math.abs(a)>1)?(t=Object.assign({},t),e=.9*(e||("touch"===t.pointerType?2:1)),f.move(t,i*e,a*e),this.drag(t),this.animate((()=>{this.dragEnd(t,1)}))):this.dragEndReal(t)}dragEndReal(t){const{interaction:e,downData:i,dragData:a}=this;t||(t=a);const{path:s,throughPath:n}=i,r=$(i,t,t);if(n&&(r.throughPath=n),r.path=s,this.moving&&(this.moving=!1,e.emit(z.END,r)),this.dragging){const s=this.getList();this.dragging=!1,e.emit(W.END,r),this.swipe(t,i,a,r),this.drop(t,s,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}animate(t,e){const i=t||this.animateWait;i&&this.interaction.target.nextRender(i,null,e),this.animateWait=t}swipe(t,e,i,a){const{interaction:s}=this;if(f.getDistance(e,t)>s.config.pointer.swipeDistance){const t=et(e,i,a);this.interaction.emit(t.type,t)}}drop(t,e,i){const a=tt(t,e,W.data);a.path=i,this.interaction.emit(N.DROP,a),this.interaction.emit(W.LEAVE,t,i)}dragReset(){W.list=W.data=this.dragableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragOut(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)}autoMoveOnDragOut(t){const{interaction:e,downData:i,canDragOut:a}=this,{autoDistance:s,dragOut:n}=e.config.move;if(!n||!a||!s)return;const r=e.shrinkCanvasBounds,{x:o,y:h}=r,d=D.maxX(r),c=D.maxY(r),l=t.x<o?s:d<t.x?-s:0,g=t.y<h?s:c<t.y?-s:0;let u=0,p=0;this.autoMoveTimer=setInterval((()=>{u+=l,p+=g,f.move(i,l,g),f.move(this.dragData,l,g),e.move(Object.assign(Object.assign({},t),{moveX:l,moveY:g,totalX:u,totalY:p})),e.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const at=d.get("emit");const st=["move","zoom","rotate","key"];function nt(t,e,i,a,s){if(st.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!ot(t,s)){let n;for(let r=0,o=t.children.length;r<o;r++)n=t.children[r],!i.path.has(n)&&n.__.hittable&&rt(n,e,i,a,s)}}function rt(t,i,a,s,n){if(t.destroyed)return!0;if(t.__.hitSelf&&!ot(t,n)&&(e.updateEventStyle&&e.updateEventStyle(t,i),t.hasEvent(i,s))){a.phase=s?1:t===a.target?2:3;const e=m.get(i,a);if(t.emitEvent(e,s),e.isStop)return!0}return!1}function ot(t,e){return e&&e.has(t)}const ht={getData(t){const e=t[0],i=t[1],a=f.getCenter(e.from,i.from),s=f.getCenter(e.to,i.to),n={x:s.x-a.x,y:s.y-a.y},r=f.getDistance(e.from,i.from);return{move:n,scale:f.getDistance(e.to,i.to)/r,angle:f.getRotation(e.from,i.from,e.to,i.to),center:s}}},dt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8},preventDefault:!0},pointer:{hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20,preventDefaultMenu:!0},cursor:{}},{pathHasEventType:ct,getMoveEventData:lt,getZoomEventData:gt,getRotateEventData:ut}=q;class pt{get dragging(){return this.dragger.dragging}get moveMode(){return this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get isDragEmpty(){return this.config.move.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.config.move.dragEmpty&&!this.config.pointer.hover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&A.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&A.right(this.downData)}get isHoldSpaceKey(){return this.config.move.holdSpaceKey&&S.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,e,i,a){this.config=dt,this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new v(t),this.transformer=new Z(this),this.dragger=new it(this),a&&(this.config=c.default(a,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(A.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(H.BEFORE_DOWN,t),this.emit(H.DOWN,t),A.left(t)?(this.tapWait(),this.longPressWait(t)):A.right(t)&&(this.waitMenuTap=!0),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&A.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){const{dragHover:e,dragDistance:i}=this.config.pointer;if(this.emit(H.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=f.getDistance(this.downData,t)>i;e&&(this.waitTap&&this.pointerWaitCancel(),this.waitMenuTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(H.MOVE,t),this.dragging&&!e||this.pointerHover(t),this.dragger.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;A.defaultLeft(t),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(H.BEFORE_UP,t),this.emit(H.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)}multiTouch(t,e){const{move:i,angle:a,scale:s,center:n}=ht.getData(e);this.rotate(ut(n,a,t)),this.zoom(gt(n,s,t)),this.move(lt(n,i,t))}menu(t){this.findPath(t),this.emit(H.MENU,t)}menuTap(t){this.waitMenuTap&&this.emit(H.MENU_TAP,t)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,S.setDownCode(e),this.emit(j.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(j.DOWN,t,this.defaultPath)}keyUp(t){const{code:e}=t;this.downKeyMap[e]=!1,S.setUpCode(e),this.emit(j.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.config.pointer.hover&&(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(H.OUT,t,i),this.emit(H.OVER,t,e)):this.emit(H.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(H.LEAVE,t,i,e),this.emit(H.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(H.LEAVE,t),this.dragger.dragging&&this.emit(N.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 a=Date.now()-this.downTime,s=[H.DOUBLE_TAP,H.DOUBLE_CLICK].some((e=>ct(t.path,e)));a<e.tapTime+50&&s?(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:a}=this.config.pointer,s=this.selector.getByPoint(t,i,e||{through:a});return s.throughPath&&(t.throughPath=s.throughPath),t.path=s.path,s.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))}checkPath(t,e){(e||this.canMove(t))&&(t.path=this.defaultPath)}canMove(t){return this.moveMode&&t&&t.path.list.every((t=>!t.isOutside))}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:a}=this;!t&&a&&(t=a),t&&(this.findPath(t,e),i&&a&&t.path.addList(a.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(),name:H.MOVE}),this.hoverData=t)}updateCursor(t){if(this.config.cursor.stop||!this.config.pointer.hover)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:a}=t;for(let t=0,s=a.length;t<s&&(e=a.list[t],i=e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}emitTap(t){this.emit(H.TAP,t),this.emit(H.CLICK,t)}emitDoubleTap(t){this.emit(H.DOUBLE_TAP,t),this.emit(H.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout((()=>{this.longPressed=!0,this.emit(H.LONG_PRESS,t)}),this.config.pointer.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(H.LONG_TAP,t),ct(t.path,H.LONG_TAP)&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){clearTimeout(this.longPressTimer),this.longPressed=!1}__onResize(){this.shrinkCanvasBounds=new E(this.canvas.bounds),this.shrinkCanvasBounds.spread(-2)}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(y.RESIZE,this.__onResize,this)],t.once(O.READY,(()=>this.__onResize()))}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}emit(t,e,i,a){this.running&&function(t,e,i,a){if(!i&&!e.path)return;let s;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(s=i.list[n],rt(s,t,e,!0,a))return;s.isApp&&nt(s,t,e,!0,a)}for(let n=0,r=i.length;n<r;n++)if(s=i.list[n],s.isApp&&nt(s,t,e,!1,a),rt(s,t,e,!1,a))return}catch(t){at.error(t)}}(t,e,i,a)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class mt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}mt.custom={};class _t extends P{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new v,this.pixelList=new v}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),o.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),o.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()}}const vt=T.prototype;vt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},vt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},vt.hitPixel=function(t,e,i=1){let{x:a,y:s,radiusX:n,radiusY:r}=t;e&&(a-=e.x,s-=e.y),w.set(a-n,s-r,2*n,2*r).scale(i).ceil();const{data:o}=this.context.getImageData(w.x,w.y,w.width,w.height);for(let t=0,e=o.length;t<e;t+=4)if(o[t+3]>0)return!0;return o[3]>0};const{toInnerRadiusPointOf:ft,copy:Et,setRadius:Dt}=f,yt={},Ot=R.prototype;Ot.__hitWorld=function(t){this.__.hitRadius&&(Et(yt,t),Dt(t=yt,this.__.hitRadius)),ft(t,this.__world,yt);const{width:e,height:i}=this.__world,a=e<10&&i<10;if(this.__.hitBox||a){if(D.hitRadiusPoint(this.__layout.boxBounds,yt))return!0;if(a)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(yt)},Ot.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},Ot.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},Ot.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},Ot.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Pt=new C,Tt=i.prototype;Tt.__updateHitCanvas=function(){const t=this.__,{hitCanvasManager:e}=this.leafer,i=t.__pixelFill&&"pixel"===t.hitFill,s=t.__pixelStroke&&"pixel"===t.hitStroke,n=i||s;this.__hitCanvas||(this.__hitCanvas=n?e.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):e.getPathType(this));const r=this.__hitCanvas;if(n){const{renderBounds:e}=this.__layout,n=L.image.hitCanvasSize,o=r.hitScale=w.set(0,0,n,n).getFitMatrix(e,.5).a,{x:h,y:d,width:c,height:l}=w.set(e).scale(o);r.resize({width:c,height:l,pixelRatio:1}),r.clear(),a.patternLocked=!0,this.__renderShape(r,{matrix:Pt.setWith(this.__world).scaleWith(1/o).invertWith().translate(-h,-d)},!i,!s),a.patternLocked=!1,r.resetTransform(),t.__isHitPixel=!0}else t.__isHitPixel&&(t.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(t)},Tt.__hit=function(t){"miniapp"===L.name&&this.__drawHitPath(this.__hitCanvas);const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,a=e.fill&&"path"==i||"all"===i;if(a&&this.__hitFill(t))return!0;const{hitStroke:s,__strokeWidth:n}=e,r=e.stroke&&"path"==s||"all"===s;if(!a&&!r)return!1;const o=2*t.radiusX;let h=o;if(r)switch(e.strokeAlign){case"inside":if(h+=2*n,!a&&this.__hitFill(t)&&this.__hitStroke(t,h))return!0;h=o;break;case"center":h+=n;break;case"outside":if(h+=2*n,!a){if(!this.__hitFill(t)&&this.__hitStroke(t,h))return!0;h=o}}return!!h&&this.__hitStroke(t,h)};const wt=new i;s.prototype.__updateHitCanvas=function(){(this.stroke||this.cornerRadius)&&wt.__updateHitCanvas.call(this)},s.prototype.__hitFill=function(t){return this.__hitCanvas?wt.__hitFill.call(this,t):D.hitRadiusPoint(this.__layout.boxBounds,t)},i.prototype.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},i.prototype.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},n.prototype.pick=function(t,e){return this.__layout.update(),e||(e={}),this.leafer?this.leafer.selector.getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this})):null};export{x as App,mt as Cursor,W as DragEvent,N as DropEvent,_t as HitCanvasManager,pt as InteractionBase,q as InteractionHelper,j as KeyEvent,S as Keyboard,X as LeaferTypeCreator,z as MoveEvent,ht as MultiTouchHelper,A as PointerButton,H as PointerEvent,F as RotateEvent,I as SwipeEvent,k as UIEvent,V as ZoomEvent};
1
+ import{Leafer as t,State as e,UI as i,ImageManager as a,Rect as s,Group as n}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as r,Creator as o,PropertyEvent as h,Debug as d,DataHelper as c,canvasSizeAttrs as l,LayoutEvent as g,RenderEvent as u,Event as p,EventCreator as m,registerUIEvent as _,LeafList as v,PointHelper as f,Bounds as D,BoundsHelper as E,ResizeEvent as y,LeaferEvent as O,CanvasManager as P,LeaferCanvasBase as T,tempBounds as w,Leaf as R,Matrix as x,Platform as b}from"@leafer/core";function C(t,e,i,a){var s,n=arguments.length,r=n<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,i):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,a);else for(var o=t.length-1;o>=0;o--)(s=t[o])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}"function"==typeof SuppressedError&&SuppressedError;let L=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:a,editor:s}=t;e&&(this.ground=this.addLeafer(e)),(i||s)&&(this.tree=this.addLeafer(i)),(a||s)&&(this.sky=this.addLeafer(a||{type:"draw",usePartRender:!1})),s&&(this.editor=o.editor(s),this.sky.add(this.editor))}}__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(),this.__eventIds.push(this.on_(h.CHANGE,this.__onPropertyChange,this))}start(){super.start(),this.children.forEach((t=>t.start()))}stop(){this.children.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.children.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.children.forEach((t=>t.lockLayout()))}forceRender(t){this.children.forEach((e=>e.forceRender(t)))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t),this.__listenChildEvents(t)}__onPropertyChange(){d.showHitView&&this.children.forEach((t=>t.forceUpdate("surface")))}__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){e.matrix&&t.setWorld(e.matrix),this.children.forEach((e=>t.copyWorld(e.canvas)))}__onResize(t){this.children.forEach((e=>e.resize(t))),super.__onResize(t)}__checkUpdateLayout(){this.children.forEach((t=>t.__layout.update()))}__getChildConfig(t){let e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&c.assign(e,t),this.autoLayout&&c.copyAttrs(e,this,l),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once(g.END,(()=>this.__onReady())),t.once(u.START,(()=>this.__onCreated())),t.once(u.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(u.END,this.__onChildRenderEnd,this))}};L=C([r()],L);const M={},S={isHoldSpaceKey:()=>S.isHold("Space"),isHold:t=>M[t],setDownCode(t){M[t]||(M[t]=!0)},setUpCode(t){M[t]=!1}},A={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 k extends p{get spaceKey(){return S.isHoldSpaceKey()}get left(){return A.left(this)}get right(){return A.right(this)}get middle(){return A.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}getPage(){return this.current.getPagePoint(this)}getInner(t){return t||(t=this.current),t.getInnerPoint(this)}getLocal(t){return t||(t=this.current),t.getLocalPoint(this)}static changeName(t,e){m.changeName(t,e)}}let B=class extends k{};B.POINTER="pointer",B.BEFORE_DOWN="pointer.before_down",B.BEFORE_MOVE="pointer.before_move",B.BEFORE_UP="pointer.before_up",B.DOWN="pointer.down",B.MOVE="pointer.move",B.UP="pointer.up",B.OVER="pointer.over",B.OUT="pointer.out",B.ENTER="pointer.enter",B.LEAVE="pointer.leave",B.TAP="tap",B.DOUBLE_TAP="double_tap",B.CLICK="click",B.DOUBLE_CLICK="double_click",B.LONG_PRESS="long_press",B.LONG_TAP="long_tap",B.MENU="pointer.menu",B.MENU_TAP="pointer.menu_tap",B=C([_()],B);const H={};let W=class extends B{static setList(t){this.list=t instanceof v?t:new v(t)}static setData(t){this.data=t}static getValidMove(t,e,i){const{draggable:a,dragBounds:s,x:n,y:r}=t,o=t.getLocalPoint(i,null,!0);return o.x+=e.x-n,o.y+=e.y-r,s&&this.getMoveInDragBounds(t.__local,"parent"===s?t.parent.boxBounds:s,o,!0),"x"===a&&(o.y=0),"y"===a&&(o.x=0),o}static getMoveInDragBounds(t,e,i,a){const s=t.x+i.x,n=t.y+i.y,r=s+t.width,o=n+t.height,h=e.x+e.width,d=e.y+e.height;return a||(i=Object.assign({},i)),s<e.x?i.x+=e.x-s:r>h&&(i.x+=h-r),n<e.y?i.y+=e.y-n:o>d&&(i.y+=d-o),i}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(H,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(H,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(H,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}assignMove(t){H.x=t?this.totalX:this.moveX,H.y=t?this.totalY:this.moveY}};W.BEFORE_DRAG="drag.before_drag",W.START="drag.start",W.DRAG="drag",W.END="drag.end",W.OVER="drag.over",W.OUT="drag.out",W.ENTER="drag.enter",W.LEAVE="drag.leave",W=C([_()],W);let I=class extends B{static setList(t){W.setList(t)}static setData(t){W.setData(t)}};I.DROP="drop",I=C([_()],I);let N=class extends W{};N.BEFORE_MOVE="move.before_move",N.START="move.start",N.MOVE="move",N.END="move.end",N=C([_()],N);let V=class extends k{};V.BEFORE_ROTATE="rotate.before_rotate",V.START="rotate.start",V.ROTATE="rotate",V.END="rotate.end",V=C([_()],V);let j=class extends W{};j.SWIPE="swipe",j.LEFT="swipe.left",j.RIGHT="swipe.right",j.UP="swipe.up",j.DOWN="swipe.down",j=C([_()],j);let z=class extends k{};z.BEFORE_ZOOM="zoom.before_zoom",z.START="zoom.start",z.ZOOM="zoom",z.END="zoom.end",z=C([_()],z);let F=class extends k{};function K(t){t.isApp||t.__eventIds.push(t.on_(N.BEFORE_MOVE,(e=>{t.zoomLayer.move(t.getValidMove(e.moveX,e.moveY))})),t.on_(z.BEFORE_ZOOM,(e=>{const{zoomLayer:i}=t,a=t.getValidScale(e.scale);1!==a&&(f.scaleOf(i,e,a),i.scale=i.__.scaleX*a)})))}F.DOWN="key.down",F.HOLD="key.hold",F.UP="key.up",F=C([_()],F);const U=d.get("LeaferTypeCreator"),X={list:{},register(t,e){Y[t]?U.repeat(t):Y[t]=e},run(t,e){const i=Y[t];i?i(e):U.error("no",t)}},{list:Y,register:G}=X;G("draw",(()=>{})),G("design",K),G("document",(function(t){K(t),t.config.move.scroll="limit",t.config.zoom.min=1})),t.prototype.initType=function(t){X.run(t,this)},t.prototype.getValidMove=function(t,e){const{scroll:i,disabled:a}=this.app.config.move;if(i&&(Math.abs(t)>Math.abs(e)?e=0:t=0,"limit"===i)){const{x:i,y:a,width:s,height:n}=new D(this.__world).addPoint(this.zoomLayer),r=i+s-this.width,o=a+n-this.height;i>=0&&r<=0?t=0:t>0?i+t>0&&(t=-i):t<0&&r+t<0&&(t=-r),a>=0&&o<=0?e=0:e>0?a+e>0&&(e=-a):e<0&&o+e<0&&(e=-o)}return{x:a?0:t,y:a?0:e}},t.prototype.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:i,max:a,disabled:s}=this.app.config.zoom,n=Math.abs(e*t);return n<i?t=i/e:n>a&&(t=a/e),s?1:t};class Z{constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(!this.moveData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.moveData=Object.assign(Object.assign({},t),{moveX:0,moveY:0}),e.cancelHover(),e.emit(N.START,this.moveData)}t.path=this.moveData.path,e.emit(N.BEFORE_MOVE,t),e.emit(N.MOVE,t),this.transformEndWait()}zoom(t){const{interaction:e}=this;if(!this.zoomData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.zoomData=Object.assign(Object.assign({},t),{scale:1}),e.cancelHover(),e.emit(z.START,this.zoomData)}t.path=this.zoomData.path,e.emit(z.BEFORE_ZOOM,t),e.emit(z.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:e}=this;if(!this.rotateData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),e.cancelHover(),e.emit(V.START,this.rotateData)}t.path=this.rotateData.path,e.emit(V.BEFORE_ROTATE,t),e.emit(V.ROTATE,t),this.transformEndWait()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout((()=>{this.transformEnd()}),this.interaction.config.pointer.transformTime)}transformEnd(){this.moveEnd(),this.zoomEnd(),this.rotateEnd()}moveEnd(){this.moveData&&(this.interaction.emit(N.END,this.moveData),this.moveData=null)}zoomEnd(){this.zoomData&&(this.interaction.emit(z.END,this.zoomData),this.zoomData=null)}rotateEnd(){this.rotateData&&(this.interaction.emit(V.END,this.rotateData),this.rotateData=null)}destroy(){this.zoomData=this.moveData=this.rotateData=null}}const q={getMoveEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,moveX:e.x,moveY:e.y}),getRotateEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,rotation:e}),getZoomEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,scale:e}),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?j.UP:t>45&&t<135?j.DOWN:t<=45&&t>=-45?j.RIGHT:j.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:J.getSwipeDirection(f.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:void 0===t.buttons?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,a=i.length;t<a;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new v,{list:a}=t;for(let t=0,s=a.length;t<s;t++)a[t].hasEvent(e)&&i.add(a[t]);return i}},J=q,Q=new v,{getDragEventData:$,getDropEventData:tt,getSwipeEventData:et}=q;class it{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=$(t,t,t),this.canAnimate=this.canDragOut=!0}getList(){const{proxy:t}=this.interaction.selector;return!this.dragging||t&&t.list.length?Q:W.list||this.dragableList||Q}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)&&i.emit(N.START,this.dragData),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&A.left(t),this.dragging&&(this.interaction.emit(W.START,this.dragData),this.getDragableList(this.dragData.path),this.setDragStartPoints(this.realDragableList=this.getList())))}setDragStartPoints(t){this.dragStartPoints={},t.forEach((t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y}))}getDragableList(t){let e;for(let i=0,a=t.length;i<a;i++)if(e=t.list[i],(e.__.draggable||e.__.editable)&&e.__.hitSelf&&!e.__.locked){this.dragableList=new v(e);break}}drag(t){const{interaction:e,dragData:i,downData:a}=this,{path:s,throughPath:n}=a;this.dragData=$(a,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=s,this.moving?(e.emit(N.BEFORE_MOVE,this.dragData),e.emit(N.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(W.BEFORE_DRAG,this.dragData),e.emit(W.DRAG,this.dragData))}dragReal(){const{running:t}=this.interaction,e=this.realDragableList;if(e.length&&t){const{totalX:t,totalY:i}=this.dragData;e.forEach((e=>e.draggable&&e.move(W.getValidMove(e,this.dragStartPoints[e.innerId],{x:t,y:i}))))}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:a}=t;this.dragOverPath=a,i?a.indexAt(0)!==i.indexAt(0)&&(e.emit(W.OUT,t,i),e.emit(W.OVER,t,a)):e.emit(W.OVER,t,a)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:a}=t;e.emit(W.LEAVE,t,i,a),e.emit(W.ENTER,t,a,i),this.dragEnterPath=a}dragEnd(t,e){if(!this.dragging&&!this.moving)return;const{moveX:i,moveY:a}=this.dragData;this.interaction.config.move.dragAnimate&&this.canAnimate&&this.moving&&(Math.abs(i)>1||Math.abs(a)>1)?(t=Object.assign({},t),e=.9*(e||("touch"===t.pointerType?2:1)),f.move(t,i*e,a*e),this.drag(t),this.animate((()=>{this.dragEnd(t,1)}))):this.dragEndReal(t)}dragEndReal(t){const{interaction:e,downData:i,dragData:a}=this;t||(t=a);const{path:s,throughPath:n}=i,r=$(i,t,t);if(n&&(r.throughPath=n),r.path=s,this.moving&&(this.moving=!1,e.emit(N.END,r)),this.dragging){const s=this.getList();this.dragging=!1,e.emit(W.END,r),this.swipe(t,i,a,r),this.drop(t,s,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}animate(t,e){const i=t||this.animateWait;i&&this.interaction.target.nextRender(i,null,e),this.animateWait=t}swipe(t,e,i,a){const{interaction:s}=this;if(f.getDistance(e,t)>s.config.pointer.swipeDistance){const t=et(e,i,a);this.interaction.emit(t.type,t)}}drop(t,e,i){const a=tt(t,e,W.data);a.path=i,this.interaction.emit(I.DROP,a),this.interaction.emit(W.LEAVE,t,i)}dragReset(){W.list=W.data=this.dragableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragOut(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)}autoMoveOnDragOut(t){const{interaction:e,downData:i,canDragOut:a}=this,{autoDistance:s,dragOut:n}=e.config.move;if(!n||!a||!s)return;const r=e.shrinkCanvasBounds,{x:o,y:h}=r,d=E.maxX(r),c=E.maxY(r),l=t.x<o?s:d<t.x?-s:0,g=t.y<h?s:c<t.y?-s:0;let u=0,p=0;this.autoMoveTimer=setInterval((()=>{u+=l,p+=g,f.move(i,l,g),f.move(this.dragData,l,g),e.move(Object.assign(Object.assign({},t),{moveX:l,moveY:g,totalX:u,totalY:p})),e.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const at=d.get("emit");const st=["move","zoom","rotate","key"];function nt(t,e,i,a,s){if(st.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!ot(t,s)){let n;for(let r=0,o=t.children.length;r<o;r++)n=t.children[r],!i.path.has(n)&&n.__.hittable&&rt(n,e,i,a,s)}}function rt(t,i,a,s,n){if(t.destroyed)return!0;if(t.__.hitSelf&&!ot(t,n)&&(e.updateEventStyle&&e.updateEventStyle(t,i),t.hasEvent(i,s))){a.phase=s?1:t===a.target?2:3;const e=m.get(i,a);if(t.emitEvent(e,s),e.isStop)return!0}return!1}function ot(t,e){return e&&e.has(t)}const ht={getData(t){const e=t[0],i=t[1],a=f.getCenter(e.from,i.from),s=f.getCenter(e.to,i.to),n={x:s.x-a.x,y:s.y-a.y},r=f.getDistance(e.from,i.from);return{move:n,scale:f.getDistance(e.to,i.to)/r,angle:f.getRotation(e.from,i.from,e.to,i.to),center:s}}},dt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8},preventDefault:!0},pointer:{hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20,preventDefaultMenu:!0},cursor:{}},{pathHasEventType:ct,getMoveEventData:lt,getZoomEventData:gt,getRotateEventData:ut}=q;class pt{get dragging(){return this.dragger.dragging}get moveMode(){return this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get isDragEmpty(){return this.config.move.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.config.move.dragEmpty&&!this.config.pointer.hover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&A.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&A.right(this.downData)}get isHoldSpaceKey(){return this.config.move.holdSpaceKey&&S.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,e,i,a){this.config=dt,this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new v(t),this.transformer=new Z(this),this.dragger=new it(this),a&&(this.config=c.default(a,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(A.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(B.BEFORE_DOWN,t),this.emit(B.DOWN,t),A.left(t)?(this.tapWait(),this.longPressWait(t)):A.right(t)&&(this.waitMenuTap=!0),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&A.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){const{dragHover:e,dragDistance:i}=this.config.pointer;if(this.emit(B.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=f.getDistance(this.downData,t)>i;e&&(this.waitTap&&this.pointerWaitCancel(),this.waitMenuTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(B.MOVE,t),this.dragging&&!e||this.pointerHover(t),this.dragger.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;A.defaultLeft(t),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(B.BEFORE_UP,t),this.emit(B.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)}multiTouch(t,e){const{move:i,angle:a,scale:s,center:n}=ht.getData(e);this.rotate(ut(n,a,t)),this.zoom(gt(n,s,t)),this.move(lt(n,i,t))}menu(t){this.findPath(t),this.emit(B.MENU,t)}menuTap(t){this.waitMenuTap&&this.emit(B.MENU_TAP,t)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,S.setDownCode(e),this.emit(F.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(F.DOWN,t,this.defaultPath)}keyUp(t){const{code:e}=t;this.downKeyMap[e]=!1,S.setUpCode(e),this.emit(F.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.config.pointer.hover&&(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(B.OUT,t,i),this.emit(B.OVER,t,e)):this.emit(B.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(B.LEAVE,t,i,e),this.emit(B.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(B.LEAVE,t),this.dragger.dragging&&this.emit(I.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 a=Date.now()-this.downTime,s=[B.DOUBLE_TAP,B.DOUBLE_CLICK].some((e=>ct(t.path,e)));a<e.tapTime+50&&s?(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:a}=this.config.pointer,{bottomList:s}=this,n=this.selector.getByPoint(t,i,Object.assign({bottomList:s,name:t.type},e||{through:a}));return n.throughPath&&(t.throughPath=n.throughPath),t.path=n.path,n.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.canMove(t))&&(t.path=this.defaultPath)}canMove(t){return this.moveMode&&t&&t.path.list.every((t=>!t.isOutside))}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:a}=this;!t&&a&&(t=a),t&&(this.findPath(t,e),i&&a&&t.path.addList(a.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(),name:B.MOVE}),this.hoverData=t)}updateCursor(t){if(this.config.cursor.stop||!this.config.pointer.hover)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:a}=t;for(let t=0,s=a.length;t<s&&(e=a.list[t],i=e.syncEventer?e.syncEventer.cursor:e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}emitTap(t){this.emit(B.TAP,t),this.emit(B.CLICK,t)}emitDoubleTap(t){this.emit(B.DOUBLE_TAP,t),this.emit(B.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout((()=>{this.longPressed=!0,this.emit(B.LONG_PRESS,t)}),this.config.pointer.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(B.LONG_TAP,t),ct(t.path,B.LONG_TAP)&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){clearTimeout(this.longPressTimer),this.longPressed=!1}__onResize(){this.shrinkCanvasBounds=new D(this.canvas.bounds),this.shrinkCanvasBounds.spread(-2)}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(y.RESIZE,this.__onResize,this)],t.once(O.READY,(()=>this.__onResize()))}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}emit(t,e,i,a){this.running&&function(t,e,i,a){if(!i&&!e.path)return;let s;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(s=i.list[n],rt(s,t,e,!0,a))return;s.isApp&&nt(s,t,e,!0,a)}for(let n=0,r=i.length;n<r;n++)if(s=i.list[n],s.isApp&&nt(s,t,e,!1,a),rt(s,t,e,!1,a))return}catch(t){at.error(t)}}(t,e,i,a)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class mt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}mt.custom={};class _t extends P{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new v,this.pixelList=new v}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),o.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),o.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()}}const vt=T.prototype;vt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},vt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},vt.hitPixel=function(t,e,i=1){let{x:a,y:s,radiusX:n,radiusY:r}=t;e&&(a-=e.x,s-=e.y),w.set(a-n,s-r,2*n,2*r).scale(i).ceil();const{data:o}=this.context.getImageData(w.x,w.y,w.width,w.height);for(let t=0,e=o.length;t<e;t+=4)if(o[t+3]>0)return!0;return o[3]>0};const{toInnerRadiusPointOf:ft,copy:Dt,setRadius:Et}=f,yt={},Ot=R.prototype;Ot.__hitWorld=function(t){if(!this.__.hitSelf)return!1;this.__.hitRadius&&(Dt(yt,t),Et(t=yt,this.__.hitRadius)),ft(t,this.__world,yt);const{width:e,height:i}=this.__world,a=e<10&&i<10;if(this.__.hitBox||a){if(E.hitRadiusPoint(this.__layout.boxBounds,yt))return!0;if(a)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(yt)},Ot.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},Ot.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},Ot.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},Ot.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Pt=new x,Tt=i.prototype;Tt.__updateHitCanvas=function(){const t=this.__,{hitCanvasManager:e}=this.leafer,i=t.__pixelFill&&"pixel"===t.hitFill,s=t.__pixelStroke&&"pixel"===t.hitStroke,n=i||s;this.__hitCanvas||(this.__hitCanvas=n?e.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):e.getPathType(this));const r=this.__hitCanvas;if(n){const{renderBounds:e}=this.__layout,n=b.image.hitCanvasSize,o=r.hitScale=w.set(0,0,n,n).getFitMatrix(e,.5).a,{x:h,y:d,width:c,height:l}=w.set(e).scale(o);r.resize({width:c,height:l,pixelRatio:1}),r.clear(),a.patternLocked=!0,this.__renderShape(r,{matrix:Pt.setWith(this.__world).scaleWith(1/o).invertWith().translate(-h,-d)},!i,!s),a.patternLocked=!1,r.resetTransform(),t.__isHitPixel=!0}else t.__isHitPixel&&(t.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(t)},Tt.__hit=function(t){"miniapp"===b.name&&this.__drawHitPath(this.__hitCanvas);const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,a=e.fill&&"path"==i||"all"===i;if(a&&this.__hitFill(t))return!0;const{hitStroke:s,__strokeWidth:n}=e,r=e.stroke&&"path"==s||"all"===s;if(!a&&!r)return!1;const o=2*t.radiusX;let h=o;if(r)switch(e.strokeAlign){case"inside":if(h+=2*n,!a&&this.__hitFill(t)&&this.__hitStroke(t,h))return!0;h=o;break;case"center":h+=n;break;case"outside":if(h+=2*n,!a){if(!this.__hitFill(t)&&this.__hitStroke(t,h))return!0;h=o}}return!!h&&this.__hitStroke(t,h)};const wt=new i,Rt=s.prototype;Rt.__updateHitCanvas=function(){(this.stroke||this.cornerRadius)&&wt.__updateHitCanvas.call(this)},Rt.__hitFill=function(t){return this.__hitCanvas?wt.__hitFill.call(this,t):E.hitRadiusPoint(this.__layout.boxBounds,t)};const xt=i.prototype,bt=n.prototype;xt.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},xt.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},bt.pick=function(t,e){return this.__layout.update(),e||(e={}),this.leafer?this.leafer.selector.getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this})):null};export{L as App,mt as Cursor,W as DragEvent,I as DropEvent,_t as HitCanvasManager,pt as InteractionBase,q as InteractionHelper,F as KeyEvent,S as Keyboard,X as LeaferTypeCreator,N as MoveEvent,ht as MultiTouchHelper,A as PointerButton,B as PointerEvent,V as RotateEvent,j as SwipeEvent,k as UIEvent,z as ZoomEvent};
package/lib/core.min.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer/core");function i(t,e,i,s){var r,a=arguments.length,o=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var n=t.length-1;n>=0;n--)(r=t[n])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError,exports.App=class extends t.Leafer{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,i){if(super.init(t,i),t){const{ground:i,tree:s,sky:r,editor:a}=t;i&&(this.ground=this.addLeafer(i)),(s||a)&&(this.tree=this.addLeafer(s)),(r||a)&&(this.sky=this.addLeafer(r||{type:"draw",usePartRender:!1})),a&&(this.editor=e.Creator.editor(a),this.sky.add(this.editor))}}__setApp(){const{canvas:t}=this,{realCanvas:i,view:s}=this.config;i||s===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable(),this.__eventIds.push(this.on_(e.PropertyEvent.CHANGE,this.__onPropertyChange,this))}start(){super.start(),this.children.forEach((t=>t.start()))}stop(){this.children.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.children.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.children.forEach((t=>t.lockLayout()))}forceRender(t){this.children.forEach((e=>e.forceRender(t)))}addLeafer(e){const i=new t.Leafer(e);return this.add(i),i}add(t){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t),this.__listenChildEvents(t)}__onPropertyChange(){e.Debug.showHitView&&this.children.forEach((t=>t.forceUpdate("surface")))}__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.setWorld(e.matrix||this.__world),this.children.forEach((e=>t.copyWorld(e.canvas)))}__onResize(t){this.children.forEach((e=>e.resize(t))),super.__onResize(t)}__checkUpdateLayout(){this.children.forEach((t=>t.__layout.update()))}__getChildConfig(t){let i=Object.assign({},this.config);return i.hittable=i.realCanvas=void 0,t&&e.DataHelper.assign(i,t),this.autoLayout&&e.DataHelper.copyAttrs(i,this,e.canvasSizeAttrs),i.view=this.realCanvas?void 0:this.view,i.fill=void 0,i}__listenChildEvents(t){t.once(e.LayoutEvent.END,(()=>this.__onReady())),t.once(e.RenderEvent.START,(()=>this.__onCreated())),t.once(e.RenderEvent.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(e.RenderEvent.END,this.__onChildRenderEnd,this))}},exports.App=i([e.registerUI()],exports.App);const s={},r={isHoldSpaceKey:()=>r.isHold("Space"),isHold:t=>s[t],setDownCode(t){s[t]||(s[t]=!0)},setUpCode(t){s[t]=!1}},a={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 o extends e.Event{get spaceKey(){return r.isHoldSpaceKey()}get left(){return a.left(this)}get right(){return a.right(this)}get middle(){return a.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}getPage(){return this.current.getPagePoint(this)}getInner(t){return t||(t=this.current),t.getInnerPoint(this)}getLocal(t){return t||(t=this.current),t.getLocalPoint(this)}static changeName(t,i){e.EventCreator.changeName(t,i)}}exports.PointerEvent=class extends o{},exports.PointerEvent.POINTER="pointer",exports.PointerEvent.BEFORE_DOWN="pointer.before_down",exports.PointerEvent.BEFORE_MOVE="pointer.before_move",exports.PointerEvent.BEFORE_UP="pointer.before_up",exports.PointerEvent.DOWN="pointer.down",exports.PointerEvent.MOVE="pointer.move",exports.PointerEvent.UP="pointer.up",exports.PointerEvent.OVER="pointer.over",exports.PointerEvent.OUT="pointer.out",exports.PointerEvent.ENTER="pointer.enter",exports.PointerEvent.LEAVE="pointer.leave",exports.PointerEvent.TAP="tap",exports.PointerEvent.DOUBLE_TAP="double_tap",exports.PointerEvent.CLICK="click",exports.PointerEvent.DOUBLE_CLICK="double_click",exports.PointerEvent.LONG_PRESS="long_press",exports.PointerEvent.LONG_TAP="long_tap",exports.PointerEvent.MENU="pointer.menu",exports.PointerEvent.MENU_TAP="pointer.menu_tap",exports.PointerEvent=i([e.registerUIEvent()],exports.PointerEvent);const n={};function h(t){t.isApp||t.__eventIds.push(t.on_(exports.MoveEvent.BEFORE_MOVE,(e=>{const{x:i,y:s}=t.getValidMove(e.moveX,e.moveY);(i||s)&&t.zoomLayer.move(i,s)})),t.on_(exports.ZoomEvent.BEFORE_ZOOM,(i=>{const{zoomLayer:s}=t,r=t.getValidScale(i.scale);1!==r&&(e.PointHelper.scaleOf(s,i,r),s.scale=s.__.scaleX*r)})))}exports.DragEvent=class extends exports.PointerEvent{static setList(t){this.list=t instanceof e.LeafList?t:new e.LeafList(t)}static setData(t){this.data=t}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(n,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(n,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(n,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}assignMove(t){n.x=t?this.totalX:this.moveX,n.y=t?this.totalY:this.moveY}},exports.DragEvent.BEFORE_DRAG="drag.before_drag",exports.DragEvent.START="drag.start",exports.DragEvent.DRAG="drag",exports.DragEvent.END="drag.end",exports.DragEvent.OVER="drag.over",exports.DragEvent.OUT="drag.out",exports.DragEvent.ENTER="drag.enter",exports.DragEvent.LEAVE="drag.leave",exports.DragEvent=i([e.registerUIEvent()],exports.DragEvent),exports.DropEvent=class extends exports.PointerEvent{static setList(t){exports.DragEvent.setList(t)}static setData(t){exports.DragEvent.setData(t)}},exports.DropEvent.DROP="drop",exports.DropEvent=i([e.registerUIEvent()],exports.DropEvent),exports.MoveEvent=class extends exports.DragEvent{},exports.MoveEvent.BEFORE_MOVE="move.before_move",exports.MoveEvent.START="move.start",exports.MoveEvent.MOVE="move",exports.MoveEvent.END="move.end",exports.MoveEvent=i([e.registerUIEvent()],exports.MoveEvent),exports.RotateEvent=class extends o{},exports.RotateEvent.BEFORE_ROTATE="rotate.before_rotate",exports.RotateEvent.START="rotate.start",exports.RotateEvent.ROTATE="rotate",exports.RotateEvent.END="rotate.end",exports.RotateEvent=i([e.registerUIEvent()],exports.RotateEvent),exports.SwipeEvent=class extends exports.DragEvent{},exports.SwipeEvent.SWIPE="swipe",exports.SwipeEvent.LEFT="swipe.left",exports.SwipeEvent.RIGHT="swipe.right",exports.SwipeEvent.UP="swipe.up",exports.SwipeEvent.DOWN="swipe.down",exports.SwipeEvent=i([e.registerUIEvent()],exports.SwipeEvent),exports.ZoomEvent=class extends o{},exports.ZoomEvent.BEFORE_ZOOM="zoom.before_zoom",exports.ZoomEvent.START="zoom.start",exports.ZoomEvent.ZOOM="zoom",exports.ZoomEvent.END="zoom.end",exports.ZoomEvent=i([e.registerUIEvent()],exports.ZoomEvent),exports.KeyEvent=class extends o{},exports.KeyEvent.DOWN="key.down",exports.KeyEvent.HOLD="key.hold",exports.KeyEvent.UP="key.up",exports.KeyEvent=i([e.registerUIEvent()],exports.KeyEvent);const p=e.Debug.get("LeaferTypeCreator"),d={list:{},register(t,e){g[t]?p.repeat(t):g[t]=e},run(t,e){const i=g[t];i?i(e):p.error("no",t)}},{list:g,register:c}=d;c("draw",(()=>{})),c("design",h),c("document",(function(t){h(t),t.config.move.scroll="limit",t.config.zoom.min=1})),t.Leafer.prototype.initType=function(t){d.run(t,this)},t.Leafer.prototype.getValidMove=function(t,i){const{scroll:s,disabled:r}=this.app.config.move;if(s&&(Math.abs(t)>Math.abs(i)?i=0:t=0,"limit"===s)){const{x:s,y:r,width:a,height:o}=new e.Bounds(this.__world).addPoint(this.zoomLayer),n=s+a-this.width,h=r+o-this.height;s>=0&&n<=0?t=0:t>0?s+t>0&&(t=-s):t<0&&n+t<0&&(t=-n),r>=0&&h<=0?i=0:i>0?r+i>0&&(i=-r):i<0&&h+i<0&&(i=-h)}return{x:r?0:t,y:r?0:i}},t.Leafer.prototype.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:i,max:s,disabled:r}=this.app.config.zoom,a=Math.abs(e*t);return a<i?t=i/e:a>s&&(t=s/e),r?1:t};class l{constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(!this.moveData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.moveData=Object.assign(Object.assign({},t),{moveX:0,moveY:0}),e.cancelHover(),e.emit(exports.MoveEvent.START,this.moveData)}t.path=this.moveData.path,e.emit(exports.MoveEvent.BEFORE_MOVE,t),e.emit(exports.MoveEvent.MOVE,t),this.transformEndWait()}zoom(t){const{interaction:e}=this;if(!this.zoomData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.zoomData=Object.assign(Object.assign({},t),{scale:1}),e.cancelHover(),e.emit(exports.ZoomEvent.START,this.zoomData)}t.path=this.zoomData.path,e.emit(exports.ZoomEvent.BEFORE_ZOOM,t),e.emit(exports.ZoomEvent.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:e}=this;if(!this.rotateData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),e.cancelHover(),e.emit(exports.RotateEvent.START,this.rotateData)}t.path=this.rotateData.path,e.emit(exports.RotateEvent.BEFORE_ROTATE,t),e.emit(exports.RotateEvent.ROTATE,t),this.transformEndWait()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout((()=>{this.transformEnd()}),this.interaction.config.pointer.transformTime)}transformEnd(){this.moveEnd(),this.zoomEnd(),this.rotateEnd()}moveEnd(){this.moveData&&(this.interaction.emit(exports.MoveEvent.END,this.moveData),this.moveData=null)}zoomEnd(){this.zoomData&&(this.interaction.emit(exports.ZoomEvent.END,this.zoomData),this.zoomData=null)}rotateEnd(){this.rotateData&&(this.interaction.emit(exports.RotateEvent.END,this.rotateData),this.rotateData=null)}destroy(){this.zoomData=this.moveData=this.rotateData=null}}const v={getMoveEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,moveX:e.x,moveY:e.y}),getRotateEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,rotation:e}),getZoomEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,scale:e}),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?exports.SwipeEvent.UP:t>45&&t<135?exports.SwipeEvent.DOWN:t<=45&&t>=-45?exports.SwipeEvent.RIGHT:exports.SwipeEvent.LEFT,getSwipeEventData:(t,i,s)=>Object.assign(Object.assign({},s),{moveX:i.moveX,moveY:i.moveY,totalX:s.x-t.x,totalY:s.y-t.y,type:u.getSwipeDirection(e.PointHelper.getAngle(t,s))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:void 0===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,i){const s=new e.LeafList,{list:r}=t;for(let t=0,e=r.length;t<e;t++)r[t].hasEvent(i)&&s.add(r[t]);return s}},u=v,E=new e.LeafList,{getDragEventData:m,getDropEventData:_,getSwipeEventData:f}=v;class x{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=m(t,t,t),this.canAnimate=this.canDragOut=!0}getList(){const{proxy:t}=this.interaction.selector;return!this.dragging||t&&t.list.length?E:exports.DragEvent.list||this.dragableList||E}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)&&i.emit(exports.MoveEvent.START,this.dragData),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&a.left(t),this.dragging&&(this.interaction.emit(exports.DragEvent.START,this.dragData),this.getDragableList(this.dragData.path)))}getDragableList(t){let i;for(let s=0,r=t.length;s<r;s++)if(i=t.list[s],(i.__.draggable||i.__.editable)&&i.__.hitSelf&&!i.__.locked){this.dragableList=new e.LeafList(i);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:r,throughPath:a}=s;this.dragData=m(s,i,t),a&&(this.dragData.throughPath=a),this.dragData.path=r,this.moving?(e.emit(exports.MoveEvent.BEFORE_MOVE,this.dragData),e.emit(exports.MoveEvent.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(exports.DragEvent.BEFORE_DRAG,this.dragData),e.emit(exports.DragEvent.DRAG,this.dragData))}dragReal(){const{running:t}=this.interaction,e=this.getList();if(e.length&&t){const{moveX:t,moveY:i}=this.dragData;e.forEach((e=>e.draggable&&e.moveWorld(t,i)))}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:s}=t;this.dragOverPath=s,i?s.indexAt(0)!==i.indexAt(0)&&(e.emit(exports.DragEvent.OUT,t,i),e.emit(exports.DragEvent.OVER,t,s)):e.emit(exports.DragEvent.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(exports.DragEvent.LEAVE,t,i,s),e.emit(exports.DragEvent.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,i){if(!this.dragging&&!this.moving)return;const{moveX:s,moveY:r}=this.dragData;this.interaction.config.move.dragAnimate&&this.canAnimate&&this.moving&&(Math.abs(s)>1||Math.abs(r)>1)?(t=Object.assign({},t),i=.9*(i||("touch"===t.pointerType?2:1)),e.PointHelper.move(t,s*i,r*i),this.drag(t),this.animate((()=>{this.dragEnd(t,1)}))):this.dragEndReal(t)}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:r,throughPath:a}=i,o=m(i,t,t);if(a&&(o.throughPath=a),o.path=r,this.moving&&(this.moving=!1,e.emit(exports.MoveEvent.END,o)),this.dragging){const r=this.getList();this.dragging=!1,e.emit(exports.DragEvent.END,o),this.swipe(t,i,s,o),this.drop(t,r,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}animate(t,e){const i=t||this.animateWait;i&&this.interaction.target.nextRender(i,null,e),this.animateWait=t}swipe(t,i,s,r){const{interaction:a}=this;if(e.PointHelper.getDistance(i,t)>a.config.pointer.swipeDistance){const t=f(i,s,r);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=_(t,e,exports.DragEvent.data);s.path=i,this.interaction.emit(exports.DropEvent.DROP,s),this.interaction.emit(exports.DragEvent.LEAVE,t,i)}dragReset(){exports.DragEvent.list=exports.DragEvent.data=this.dragableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragOut(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)}autoMoveOnDragOut(t){const{interaction:i,downData:s,canDragOut:r}=this,{autoDistance:a,dragOut:o}=i.config.move;if(!o||!r||!a)return;const n=i.shrinkCanvasBounds,{x:h,y:p}=n,d=e.BoundsHelper.maxX(n),g=e.BoundsHelper.maxY(n),c=t.x<h?a:d<t.x?-a:0,l=t.y<p?a:g<t.y?-a:0;let v=0,u=0;this.autoMoveTimer=setInterval((()=>{v+=c,u+=l,e.PointHelper.move(s,c,l),e.PointHelper.move(this.dragData,c,l),i.move(Object.assign(Object.assign({},t),{moveX:c,moveY:l,totalX:v,totalY:u})),i.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const D=e.Debug.get("emit");const P=["move","zoom","rotate","key"];function y(t,e,i,s,r){if(P.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!R(t,r)){let a;for(let o=0,n=t.children.length;o<n;o++)a=t.children[o],!i.path.has(a)&&a.__.hittable&&O(a,e,i,s,r)}}function O(i,s,r,a,o){if(i.destroyed)return!0;if(i.__.hitSelf&&!R(i,o)&&(t.State.updateEventStyle&&t.State.updateEventStyle(i,s),i.hasEvent(s,a))){r.phase=a?1:i===r.target?2:3;const t=e.EventCreator.get(s,r);if(i.emitEvent(t,a),t.isStop)return!0}return!1}function R(t,e){return e&&e.has(t)}const w={getData(t){const i=t[0],s=t[1],r=e.PointHelper.getCenter(i.from,s.from),a=e.PointHelper.getCenter(i.to,s.to),o={x:a.x-r.x,y:a.y-r.y},n=e.PointHelper.getDistance(i.from,s.from);return{move:o,scale:e.PointHelper.getDistance(i.to,s.to)/n,angle:e.PointHelper.getRotation(i.from,s.from,i.to,s.to),center:a}}},T={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8},preventDefault:!0},pointer:{hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20,preventDefaultMenu:!0},cursor:{}},{pathHasEventType:L,getMoveEventData:C,getZoomEventData:b,getRotateEventData:M}=v;class S{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}S.custom={};class H extends e.CanvasManager{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new e.LeafList,this.pixelList=new e.LeafList}getPixelType(t,i){return this.__autoClear(),this.pixelList.add(t),e.Creator.hitCanvas(i)}getPathType(t){return this.__autoClear(),this.pathList.add(t),e.Creator.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()}}const A=e.LeaferCanvasBase.prototype;A.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},A.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},A.hitPixel=function(t,i,s=1){let{x:r,y:a,radiusX:o,radiusY:n}=t;i&&(r-=i.x,a-=i.y),e.tempBounds.set(r-o,a-n,2*o,2*n).scale(s).ceil();const{data:h}=this.context.getImageData(e.tempBounds.x,e.tempBounds.y,e.tempBounds.width,e.tempBounds.height);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};const{toInnerRadiusPointOf:B,copy:k,setRadius:I}=e.PointHelper,U={},K=e.Leaf.prototype;K.__hitWorld=function(t){this.__.hitRadius&&(k(U,t),I(t=U,this.__.hitRadius)),B(t,this.__world,U);const{width:i,height:s}=this.__world,r=i<10&&s<10;if(this.__.hitBox||r){if(e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,U))return!0;if(r)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(U)},K.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},K.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},K.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},K.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const W=new e.Matrix,z=t.UI.prototype;z.__updateHitCanvas=function(){const i=this.__,{hitCanvasManager:s}=this.leafer,r=i.__pixelFill&&"pixel"===i.hitFill,a=i.__pixelStroke&&"pixel"===i.hitStroke,o=r||a;this.__hitCanvas||(this.__hitCanvas=o?s.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):s.getPathType(this));const n=this.__hitCanvas;if(o){const{renderBounds:s}=this.__layout,o=e.Platform.image.hitCanvasSize,h=n.hitScale=e.tempBounds.set(0,0,o,o).getFitMatrix(s,.5).a,{x:p,y:d,width:g,height:c}=e.tempBounds.set(s).scale(h);n.resize({width:g,height:c,pixelRatio:1}),n.clear(),t.ImageManager.patternLocked=!0,this.__renderShape(n,{matrix:W.setWith(this.__world).scaleWith(1/h).invertWith().translate(-p,-d)},!r,!a),t.ImageManager.patternLocked=!1,n.resetTransform(),i.__isHitPixel=!0}else i.__isHitPixel&&(i.__isHitPixel=!1);this.__drawHitPath(n),n.setStrokeOptions(i)},z.__hit=function(t){"miniapp"===e.Platform.name&&this.__drawHitPath(this.__hitCanvas);const i=this.__;if(i.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:s}=i,r=i.fill&&"path"==s||"all"===s;if(r&&this.__hitFill(t))return!0;const{hitStroke:a,__strokeWidth:o}=i,n=i.stroke&&"path"==a||"all"===a;if(!r&&!n)return!1;const h=2*t.radiusX;let p=h;if(n)switch(i.strokeAlign){case"inside":if(p+=2*o,!r&&this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h;break;case"center":p+=o;break;case"outside":if(p+=2*o,!r){if(!this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h}}return!!p&&this.__hitStroke(t,p)};const N=new t.UI;t.Rect.prototype.__updateHitCanvas=function(){(this.stroke||this.cornerRadius)&&N.__updateHitCanvas.call(this)},t.Rect.prototype.__hitFill=function(t){return this.__hitCanvas?N.__hitFill.call(this,t):e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,t)},t.UI.prototype.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},t.UI.prototype.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},t.Group.prototype.pick=function(t,e){return this.__layout.update(),e||(e={}),this.leafer?this.leafer.selector.getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this})):null},exports.Cursor=S,exports.HitCanvasManager=H,exports.InteractionBase=class{get dragging(){return this.dragger.dragging}get moveMode(){return this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get isDragEmpty(){return this.config.move.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.config.move.dragEmpty&&!this.config.pointer.hover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&a.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&a.right(this.downData)}get isHoldSpaceKey(){return this.config.move.holdSpaceKey&&r.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,i,s,r){this.config=T,this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=i,this.selector=s,this.defaultPath=new e.LeafList(t),this.transformer=new l(this),this.dragger=new x(this),r&&(this.config=e.DataHelper.default(r,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(a.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(exports.PointerEvent.BEFORE_DOWN,t),this.emit(exports.PointerEvent.DOWN,t),a.left(t)?(this.tapWait(),this.longPressWait(t)):a.right(t)&&(this.waitMenuTap=!0),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&a.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){const{dragHover:i,dragDistance:s}=this.config.pointer;if(this.emit(exports.PointerEvent.BEFORE_MOVE,t,this.defaultPath),this.downData){const i=e.PointHelper.getDistance(this.downData,t)>s;i&&(this.waitTap&&this.pointerWaitCancel(),this.waitMenuTap=!1),this.dragger.checkDrag(t,i)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(exports.PointerEvent.MOVE,t),this.dragging&&!i||this.pointerHover(t),this.dragger.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;a.defaultLeft(t),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(exports.PointerEvent.BEFORE_UP,t),this.emit(exports.PointerEvent.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)}multiTouch(t,e){const{move:i,angle:s,scale:r,center:a}=w.getData(e);this.rotate(M(a,s,t)),this.zoom(b(a,r,t)),this.move(C(a,i,t))}menu(t){this.findPath(t),this.emit(exports.PointerEvent.MENU,t)}menuTap(t){this.waitMenuTap&&this.emit(exports.PointerEvent.MENU_TAP,t)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,r.setDownCode(e),this.emit(exports.KeyEvent.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(exports.KeyEvent.DOWN,t,this.defaultPath)}keyUp(t){const{code:e}=t;this.downKeyMap[e]=!1,r.setUpCode(e),this.emit(exports.KeyEvent.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.config.pointer.hover&&(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(exports.PointerEvent.OUT,t,i),this.emit(exports.PointerEvent.OVER,t,e)):this.emit(exports.PointerEvent.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(exports.PointerEvent.LEAVE,t,i,e),this.emit(exports.PointerEvent.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(exports.PointerEvent.LEAVE,t),this.dragger.dragging&&this.emit(exports.DropEvent.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,r=[exports.PointerEvent.DOUBLE_TAP,exports.PointerEvent.DOUBLE_CLICK].some((e=>L(t.path,e)));s<e.tapTime+50&&r?(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.config.pointer,r=this.selector.getByPoint(t,i,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))}checkPath(t,e){(e||this.canMove(t))&&(t.path=this.defaultPath)}canMove(t){return this.moveMode&&t&&t.path.list.every((t=>!t.isOutside))}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(),name:exports.PointerEvent.MOVE}),this.hoverData=t)}updateCursor(t){if(this.config.cursor.stop||!this.config.pointer.hover)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,r=s.length;t<r&&(e=s.list[t],i=e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}emitTap(t){this.emit(exports.PointerEvent.TAP,t),this.emit(exports.PointerEvent.CLICK,t)}emitDoubleTap(t){this.emit(exports.PointerEvent.DOUBLE_TAP,t),this.emit(exports.PointerEvent.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout((()=>{this.longPressed=!0,this.emit(exports.PointerEvent.LONG_PRESS,t)}),this.config.pointer.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(exports.PointerEvent.LONG_TAP,t),L(t.path,exports.PointerEvent.LONG_TAP)&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){clearTimeout(this.longPressTimer),this.longPressed=!1}__onResize(){this.shrinkCanvasBounds=new e.Bounds(this.canvas.bounds),this.shrinkCanvasBounds.spread(-2)}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(e.ResizeEvent.RESIZE,this.__onResize,this)],t.once(e.LeaferEvent.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 r;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let a=i.length-1;a>-1;a--){if(r=i.list[a],O(r,t,e,!0,s))return;r.isApp&&y(r,t,e,!0,s)}for(let a=0,o=i.length;a<o;a++)if(r=i.list[a],r.isApp&&y(r,t,e,!1,s),O(r,t,e,!1,s))return}catch(t){D.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}},exports.InteractionHelper=v,exports.Keyboard=r,exports.LeaferTypeCreator=d,exports.MultiTouchHelper=w,exports.PointerButton=a,exports.UIEvent=o,Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
1
+ "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer/core");function i(t,e,i,s){var r,a=arguments.length,o=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var n=t.length-1;n>=0;n--)(r=t[n])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError,exports.App=class extends t.Leafer{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,i){if(super.init(t,i),t){const{ground:i,tree:s,sky:r,editor:a}=t;i&&(this.ground=this.addLeafer(i)),(s||a)&&(this.tree=this.addLeafer(s)),(r||a)&&(this.sky=this.addLeafer(r||{type:"draw",usePartRender:!1})),a&&(this.editor=e.Creator.editor(a),this.sky.add(this.editor))}}__setApp(){const{canvas:t}=this,{realCanvas:i,view:s}=this.config;i||s===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable(),this.__eventIds.push(this.on_(e.PropertyEvent.CHANGE,this.__onPropertyChange,this))}start(){super.start(),this.children.forEach((t=>t.start()))}stop(){this.children.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.children.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.children.forEach((t=>t.lockLayout()))}forceRender(t){this.children.forEach((e=>e.forceRender(t)))}addLeafer(e){const i=new t.Leafer(e);return this.add(i),i}add(t){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t),this.__listenChildEvents(t)}__onPropertyChange(){e.Debug.showHitView&&this.children.forEach((t=>t.forceUpdate("surface")))}__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){e.matrix&&t.setWorld(e.matrix),this.children.forEach((e=>t.copyWorld(e.canvas)))}__onResize(t){this.children.forEach((e=>e.resize(t))),super.__onResize(t)}__checkUpdateLayout(){this.children.forEach((t=>t.__layout.update()))}__getChildConfig(t){let i=Object.assign({},this.config);return i.hittable=i.realCanvas=void 0,t&&e.DataHelper.assign(i,t),this.autoLayout&&e.DataHelper.copyAttrs(i,this,e.canvasSizeAttrs),i.view=this.realCanvas?void 0:this.view,i.fill=void 0,i}__listenChildEvents(t){t.once(e.LayoutEvent.END,(()=>this.__onReady())),t.once(e.RenderEvent.START,(()=>this.__onCreated())),t.once(e.RenderEvent.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(e.RenderEvent.END,this.__onChildRenderEnd,this))}},exports.App=i([e.registerUI()],exports.App);const s={},r={isHoldSpaceKey:()=>r.isHold("Space"),isHold:t=>s[t],setDownCode(t){s[t]||(s[t]=!0)},setUpCode(t){s[t]=!1}},a={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 o extends e.Event{get spaceKey(){return r.isHoldSpaceKey()}get left(){return a.left(this)}get right(){return a.right(this)}get middle(){return a.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}getPage(){return this.current.getPagePoint(this)}getInner(t){return t||(t=this.current),t.getInnerPoint(this)}getLocal(t){return t||(t=this.current),t.getLocalPoint(this)}static changeName(t,i){e.EventCreator.changeName(t,i)}}exports.PointerEvent=class extends o{},exports.PointerEvent.POINTER="pointer",exports.PointerEvent.BEFORE_DOWN="pointer.before_down",exports.PointerEvent.BEFORE_MOVE="pointer.before_move",exports.PointerEvent.BEFORE_UP="pointer.before_up",exports.PointerEvent.DOWN="pointer.down",exports.PointerEvent.MOVE="pointer.move",exports.PointerEvent.UP="pointer.up",exports.PointerEvent.OVER="pointer.over",exports.PointerEvent.OUT="pointer.out",exports.PointerEvent.ENTER="pointer.enter",exports.PointerEvent.LEAVE="pointer.leave",exports.PointerEvent.TAP="tap",exports.PointerEvent.DOUBLE_TAP="double_tap",exports.PointerEvent.CLICK="click",exports.PointerEvent.DOUBLE_CLICK="double_click",exports.PointerEvent.LONG_PRESS="long_press",exports.PointerEvent.LONG_TAP="long_tap",exports.PointerEvent.MENU="pointer.menu",exports.PointerEvent.MENU_TAP="pointer.menu_tap",exports.PointerEvent=i([e.registerUIEvent()],exports.PointerEvent);const n={};function h(t){t.isApp||t.__eventIds.push(t.on_(exports.MoveEvent.BEFORE_MOVE,(e=>{t.zoomLayer.move(t.getValidMove(e.moveX,e.moveY))})),t.on_(exports.ZoomEvent.BEFORE_ZOOM,(i=>{const{zoomLayer:s}=t,r=t.getValidScale(i.scale);1!==r&&(e.PointHelper.scaleOf(s,i,r),s.scale=s.__.scaleX*r)})))}exports.DragEvent=class extends exports.PointerEvent{static setList(t){this.list=t instanceof e.LeafList?t:new e.LeafList(t)}static setData(t){this.data=t}static getValidMove(t,e,i){const{draggable:s,dragBounds:r,x:a,y:o}=t,n=t.getLocalPoint(i,null,!0);return n.x+=e.x-a,n.y+=e.y-o,r&&this.getMoveInDragBounds(t.__local,"parent"===r?t.parent.boxBounds:r,n,!0),"x"===s&&(n.y=0),"y"===s&&(n.x=0),n}static getMoveInDragBounds(t,e,i,s){const r=t.x+i.x,a=t.y+i.y,o=r+t.width,n=a+t.height,h=e.x+e.width,p=e.y+e.height;return s||(i=Object.assign({},i)),r<e.x?i.x+=e.x-r:o>h&&(i.x+=h-o),a<e.y?i.y+=e.y-a:n>p&&(i.y+=p-n),i}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(n,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(n,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(n,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}assignMove(t){n.x=t?this.totalX:this.moveX,n.y=t?this.totalY:this.moveY}},exports.DragEvent.BEFORE_DRAG="drag.before_drag",exports.DragEvent.START="drag.start",exports.DragEvent.DRAG="drag",exports.DragEvent.END="drag.end",exports.DragEvent.OVER="drag.over",exports.DragEvent.OUT="drag.out",exports.DragEvent.ENTER="drag.enter",exports.DragEvent.LEAVE="drag.leave",exports.DragEvent=i([e.registerUIEvent()],exports.DragEvent),exports.DropEvent=class extends exports.PointerEvent{static setList(t){exports.DragEvent.setList(t)}static setData(t){exports.DragEvent.setData(t)}},exports.DropEvent.DROP="drop",exports.DropEvent=i([e.registerUIEvent()],exports.DropEvent),exports.MoveEvent=class extends exports.DragEvent{},exports.MoveEvent.BEFORE_MOVE="move.before_move",exports.MoveEvent.START="move.start",exports.MoveEvent.MOVE="move",exports.MoveEvent.END="move.end",exports.MoveEvent=i([e.registerUIEvent()],exports.MoveEvent),exports.RotateEvent=class extends o{},exports.RotateEvent.BEFORE_ROTATE="rotate.before_rotate",exports.RotateEvent.START="rotate.start",exports.RotateEvent.ROTATE="rotate",exports.RotateEvent.END="rotate.end",exports.RotateEvent=i([e.registerUIEvent()],exports.RotateEvent),exports.SwipeEvent=class extends exports.DragEvent{},exports.SwipeEvent.SWIPE="swipe",exports.SwipeEvent.LEFT="swipe.left",exports.SwipeEvent.RIGHT="swipe.right",exports.SwipeEvent.UP="swipe.up",exports.SwipeEvent.DOWN="swipe.down",exports.SwipeEvent=i([e.registerUIEvent()],exports.SwipeEvent),exports.ZoomEvent=class extends o{},exports.ZoomEvent.BEFORE_ZOOM="zoom.before_zoom",exports.ZoomEvent.START="zoom.start",exports.ZoomEvent.ZOOM="zoom",exports.ZoomEvent.END="zoom.end",exports.ZoomEvent=i([e.registerUIEvent()],exports.ZoomEvent),exports.KeyEvent=class extends o{},exports.KeyEvent.DOWN="key.down",exports.KeyEvent.HOLD="key.hold",exports.KeyEvent.UP="key.up",exports.KeyEvent=i([e.registerUIEvent()],exports.KeyEvent);const p=e.Debug.get("LeaferTypeCreator"),d={list:{},register(t,e){g[t]?p.repeat(t):g[t]=e},run(t,e){const i=g[t];i?i(e):p.error("no",t)}},{list:g,register:c}=d;c("draw",(()=>{})),c("design",h),c("document",(function(t){h(t),t.config.move.scroll="limit",t.config.zoom.min=1})),t.Leafer.prototype.initType=function(t){d.run(t,this)},t.Leafer.prototype.getValidMove=function(t,i){const{scroll:s,disabled:r}=this.app.config.move;if(s&&(Math.abs(t)>Math.abs(i)?i=0:t=0,"limit"===s)){const{x:s,y:r,width:a,height:o}=new e.Bounds(this.__world).addPoint(this.zoomLayer),n=s+a-this.width,h=r+o-this.height;s>=0&&n<=0?t=0:t>0?s+t>0&&(t=-s):t<0&&n+t<0&&(t=-n),r>=0&&h<=0?i=0:i>0?r+i>0&&(i=-r):i<0&&h+i<0&&(i=-h)}return{x:r?0:t,y:r?0:i}},t.Leafer.prototype.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:i,max:s,disabled:r}=this.app.config.zoom,a=Math.abs(e*t);return a<i?t=i/e:a>s&&(t=s/e),r?1:t};class l{constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(!this.moveData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.moveData=Object.assign(Object.assign({},t),{moveX:0,moveY:0}),e.cancelHover(),e.emit(exports.MoveEvent.START,this.moveData)}t.path=this.moveData.path,e.emit(exports.MoveEvent.BEFORE_MOVE,t),e.emit(exports.MoveEvent.MOVE,t),this.transformEndWait()}zoom(t){const{interaction:e}=this;if(!this.zoomData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.zoomData=Object.assign(Object.assign({},t),{scale:1}),e.cancelHover(),e.emit(exports.ZoomEvent.START,this.zoomData)}t.path=this.zoomData.path,e.emit(exports.ZoomEvent.BEFORE_ZOOM,t),e.emit(exports.ZoomEvent.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:e}=this;if(!this.rotateData){const{path:i}=e.selector.getByPoint(t,e.hitRadius);t.path=i,this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),e.cancelHover(),e.emit(exports.RotateEvent.START,this.rotateData)}t.path=this.rotateData.path,e.emit(exports.RotateEvent.BEFORE_ROTATE,t),e.emit(exports.RotateEvent.ROTATE,t),this.transformEndWait()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout((()=>{this.transformEnd()}),this.interaction.config.pointer.transformTime)}transformEnd(){this.moveEnd(),this.zoomEnd(),this.rotateEnd()}moveEnd(){this.moveData&&(this.interaction.emit(exports.MoveEvent.END,this.moveData),this.moveData=null)}zoomEnd(){this.zoomData&&(this.interaction.emit(exports.ZoomEvent.END,this.zoomData),this.zoomData=null)}rotateEnd(){this.rotateData&&(this.interaction.emit(exports.RotateEvent.END,this.rotateData),this.rotateData=null)}destroy(){this.zoomData=this.moveData=this.rotateData=null}}const v={getMoveEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,moveX:e.x,moveY:e.y}),getRotateEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,rotation:e}),getZoomEventData:(t,e,i)=>Object.assign(Object.assign({},i),{x:t.x,y:t.y,scale:e}),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?exports.SwipeEvent.UP:t>45&&t<135?exports.SwipeEvent.DOWN:t<=45&&t>=-45?exports.SwipeEvent.RIGHT:exports.SwipeEvent.LEFT,getSwipeEventData:(t,i,s)=>Object.assign(Object.assign({},s),{moveX:i.moveX,moveY:i.moveY,totalX:s.x-t.x,totalY:s.y-t.y,type:u.getSwipeDirection(e.PointHelper.getAngle(t,s))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:void 0===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,i){const s=new e.LeafList,{list:r}=t;for(let t=0,e=r.length;t<e;t++)r[t].hasEvent(i)&&s.add(r[t]);return s}},u=v,E=new e.LeafList,{getDragEventData:m,getDropEventData:_,getSwipeEventData:x}=v;class f{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=m(t,t,t),this.canAnimate=this.canDragOut=!0}getList(){const{proxy:t}=this.interaction.selector;return!this.dragging||t&&t.list.length?E:exports.DragEvent.list||this.dragableList||E}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)&&i.emit(exports.MoveEvent.START,this.dragData),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&a.left(t),this.dragging&&(this.interaction.emit(exports.DragEvent.START,this.dragData),this.getDragableList(this.dragData.path),this.setDragStartPoints(this.realDragableList=this.getList())))}setDragStartPoints(t){this.dragStartPoints={},t.forEach((t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y}))}getDragableList(t){let i;for(let s=0,r=t.length;s<r;s++)if(i=t.list[s],(i.__.draggable||i.__.editable)&&i.__.hitSelf&&!i.__.locked){this.dragableList=new e.LeafList(i);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:r,throughPath:a}=s;this.dragData=m(s,i,t),a&&(this.dragData.throughPath=a),this.dragData.path=r,this.moving?(e.emit(exports.MoveEvent.BEFORE_MOVE,this.dragData),e.emit(exports.MoveEvent.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(exports.DragEvent.BEFORE_DRAG,this.dragData),e.emit(exports.DragEvent.DRAG,this.dragData))}dragReal(){const{running:t}=this.interaction,e=this.realDragableList;if(e.length&&t){const{totalX:t,totalY:i}=this.dragData;e.forEach((e=>e.draggable&&e.move(exports.DragEvent.getValidMove(e,this.dragStartPoints[e.innerId],{x:t,y:i}))))}}dragOverOrOut(t){const{interaction:e}=this,{dragOverPath:i}=this,{path:s}=t;this.dragOverPath=s,i?s.indexAt(0)!==i.indexAt(0)&&(e.emit(exports.DragEvent.OUT,t,i),e.emit(exports.DragEvent.OVER,t,s)):e.emit(exports.DragEvent.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(exports.DragEvent.LEAVE,t,i,s),e.emit(exports.DragEvent.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,i){if(!this.dragging&&!this.moving)return;const{moveX:s,moveY:r}=this.dragData;this.interaction.config.move.dragAnimate&&this.canAnimate&&this.moving&&(Math.abs(s)>1||Math.abs(r)>1)?(t=Object.assign({},t),i=.9*(i||("touch"===t.pointerType?2:1)),e.PointHelper.move(t,s*i,r*i),this.drag(t),this.animate((()=>{this.dragEnd(t,1)}))):this.dragEndReal(t)}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:r,throughPath:a}=i,o=m(i,t,t);if(a&&(o.throughPath=a),o.path=r,this.moving&&(this.moving=!1,e.emit(exports.MoveEvent.END,o)),this.dragging){const r=this.getList();this.dragging=!1,e.emit(exports.DragEvent.END,o),this.swipe(t,i,s,o),this.drop(t,r,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}animate(t,e){const i=t||this.animateWait;i&&this.interaction.target.nextRender(i,null,e),this.animateWait=t}swipe(t,i,s,r){const{interaction:a}=this;if(e.PointHelper.getDistance(i,t)>a.config.pointer.swipeDistance){const t=x(i,s,r);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=_(t,e,exports.DragEvent.data);s.path=i,this.interaction.emit(exports.DropEvent.DROP,s),this.interaction.emit(exports.DragEvent.LEAVE,t,i)}dragReset(){exports.DragEvent.list=exports.DragEvent.data=this.dragableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragOut(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)}autoMoveOnDragOut(t){const{interaction:i,downData:s,canDragOut:r}=this,{autoDistance:a,dragOut:o}=i.config.move;if(!o||!r||!a)return;const n=i.shrinkCanvasBounds,{x:h,y:p}=n,d=e.BoundsHelper.maxX(n),g=e.BoundsHelper.maxY(n),c=t.x<h?a:d<t.x?-a:0,l=t.y<p?a:g<t.y?-a:0;let v=0,u=0;this.autoMoveTimer=setInterval((()=>{v+=c,u+=l,e.PointHelper.move(s,c,l),e.PointHelper.move(this.dragData,c,l),i.move(Object.assign(Object.assign({},t),{moveX:c,moveY:l,totalX:v,totalY:u})),i.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const D=e.Debug.get("emit");const P=["move","zoom","rotate","key"];function y(t,e,i,s,r){if(P.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!R(t,r)){let a;for(let o=0,n=t.children.length;o<n;o++)a=t.children[o],!i.path.has(a)&&a.__.hittable&&O(a,e,i,s,r)}}function O(i,s,r,a,o){if(i.destroyed)return!0;if(i.__.hitSelf&&!R(i,o)&&(t.State.updateEventStyle&&t.State.updateEventStyle(i,s),i.hasEvent(s,a))){r.phase=a?1:i===r.target?2:3;const t=e.EventCreator.get(s,r);if(i.emitEvent(t,a),t.isStop)return!0}return!1}function R(t,e){return e&&e.has(t)}const w={getData(t){const i=t[0],s=t[1],r=e.PointHelper.getCenter(i.from,s.from),a=e.PointHelper.getCenter(i.to,s.to),o={x:a.x-r.x,y:a.y-r.y},n=e.PointHelper.getDistance(i.from,s.from);return{move:o,scale:e.PointHelper.getDistance(i.to,s.to)/n,angle:e.PointHelper.getRotation(i.from,s.from,i.to,s.to),center:a}}},T={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8},preventDefault:!0},pointer:{hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20,preventDefaultMenu:!0},cursor:{}},{pathHasEventType:L,getMoveEventData:C,getZoomEventData:b,getRotateEventData:M}=v;class S{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}S.custom={};class H extends e.CanvasManager{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new e.LeafList,this.pixelList=new e.LeafList}getPixelType(t,i){return this.__autoClear(),this.pixelList.add(t),e.Creator.hitCanvas(i)}getPathType(t){return this.__autoClear(),this.pathList.add(t),e.Creator.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()}}const B=e.LeaferCanvasBase.prototype;B.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},B.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},B.hitPixel=function(t,i,s=1){let{x:r,y:a,radiusX:o,radiusY:n}=t;i&&(r-=i.x,a-=i.y),e.tempBounds.set(r-o,a-n,2*o,2*n).scale(s).ceil();const{data:h}=this.context.getImageData(e.tempBounds.x,e.tempBounds.y,e.tempBounds.width,e.tempBounds.height);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};const{toInnerRadiusPointOf:A,copy:k,setRadius:I}=e.PointHelper,K={},U=e.Leaf.prototype;U.__hitWorld=function(t){if(!this.__.hitSelf)return!1;this.__.hitRadius&&(k(K,t),I(t=K,this.__.hitRadius)),A(t,this.__world,K);const{width:i,height:s}=this.__world,r=i<10&&s<10;if(this.__.hitBox||r){if(e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,K))return!0;if(r)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(K)},U.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},U.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},U.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},U.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const W=new e.Matrix,j=t.UI.prototype;j.__updateHitCanvas=function(){const i=this.__,{hitCanvasManager:s}=this.leafer,r=i.__pixelFill&&"pixel"===i.hitFill,a=i.__pixelStroke&&"pixel"===i.hitStroke,o=r||a;this.__hitCanvas||(this.__hitCanvas=o?s.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):s.getPathType(this));const n=this.__hitCanvas;if(o){const{renderBounds:s}=this.__layout,o=e.Platform.image.hitCanvasSize,h=n.hitScale=e.tempBounds.set(0,0,o,o).getFitMatrix(s,.5).a,{x:p,y:d,width:g,height:c}=e.tempBounds.set(s).scale(h);n.resize({width:g,height:c,pixelRatio:1}),n.clear(),t.ImageManager.patternLocked=!0,this.__renderShape(n,{matrix:W.setWith(this.__world).scaleWith(1/h).invertWith().translate(-p,-d)},!r,!a),t.ImageManager.patternLocked=!1,n.resetTransform(),i.__isHitPixel=!0}else i.__isHitPixel&&(i.__isHitPixel=!1);this.__drawHitPath(n),n.setStrokeOptions(i)},j.__hit=function(t){"miniapp"===e.Platform.name&&this.__drawHitPath(this.__hitCanvas);const i=this.__;if(i.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:s}=i,r=i.fill&&"path"==s||"all"===s;if(r&&this.__hitFill(t))return!0;const{hitStroke:a,__strokeWidth:o}=i,n=i.stroke&&"path"==a||"all"===a;if(!r&&!n)return!1;const h=2*t.radiusX;let p=h;if(n)switch(i.strokeAlign){case"inside":if(p+=2*o,!r&&this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h;break;case"center":p+=o;break;case"outside":if(p+=2*o,!r){if(!this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h}}return!!p&&this.__hitStroke(t,p)};const z=new t.UI,N=t.Rect.prototype;N.__updateHitCanvas=function(){(this.stroke||this.cornerRadius)&&z.__updateHitCanvas.call(this)},N.__hitFill=function(t){return this.__hitCanvas?z.__hitFill.call(this,t):e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,t)};const V=t.UI.prototype,F=t.Group.prototype;V.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},V.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},F.pick=function(t,e){return this.__layout.update(),e||(e={}),this.leafer?this.leafer.selector.getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this})):null},exports.Cursor=S,exports.HitCanvasManager=H,exports.InteractionBase=class{get dragging(){return this.dragger.dragging}get moveMode(){return this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get isDragEmpty(){return this.config.move.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.config.move.dragEmpty&&!this.config.pointer.hover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&a.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&a.right(this.downData)}get isHoldSpaceKey(){return this.config.move.holdSpaceKey&&r.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,i,s,r){this.config=T,this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=i,this.selector=s,this.defaultPath=new e.LeafList(t),this.transformer=new l(this),this.dragger=new f(this),r&&(this.config=e.DataHelper.default(r,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(a.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(exports.PointerEvent.BEFORE_DOWN,t),this.emit(exports.PointerEvent.DOWN,t),a.left(t)?(this.tapWait(),this.longPressWait(t)):a.right(t)&&(this.waitMenuTap=!0),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&a.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){const{dragHover:i,dragDistance:s}=this.config.pointer;if(this.emit(exports.PointerEvent.BEFORE_MOVE,t,this.defaultPath),this.downData){const i=e.PointHelper.getDistance(this.downData,t)>s;i&&(this.waitTap&&this.pointerWaitCancel(),this.waitMenuTap=!1),this.dragger.checkDrag(t,i)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(exports.PointerEvent.MOVE,t),this.dragging&&!i||this.pointerHover(t),this.dragger.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;a.defaultLeft(t),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(exports.PointerEvent.BEFORE_UP,t),this.emit(exports.PointerEvent.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)}multiTouch(t,e){const{move:i,angle:s,scale:r,center:a}=w.getData(e);this.rotate(M(a,s,t)),this.zoom(b(a,r,t)),this.move(C(a,i,t))}menu(t){this.findPath(t),this.emit(exports.PointerEvent.MENU,t)}menuTap(t){this.waitMenuTap&&this.emit(exports.PointerEvent.MENU_TAP,t)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,r.setDownCode(e),this.emit(exports.KeyEvent.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(exports.KeyEvent.DOWN,t,this.defaultPath)}keyUp(t){const{code:e}=t;this.downKeyMap[e]=!1,r.setUpCode(e),this.emit(exports.KeyEvent.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.config.pointer.hover&&(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(exports.PointerEvent.OUT,t,i),this.emit(exports.PointerEvent.OVER,t,e)):this.emit(exports.PointerEvent.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(exports.PointerEvent.LEAVE,t,i,e),this.emit(exports.PointerEvent.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(exports.PointerEvent.LEAVE,t),this.dragger.dragging&&this.emit(exports.DropEvent.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,r=[exports.PointerEvent.DOUBLE_TAP,exports.PointerEvent.DOUBLE_CLICK].some((e=>L(t.path,e)));s<e.tapTime+50&&r?(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.config.pointer,{bottomList:r}=this,a=this.selector.getByPoint(t,i,Object.assign({bottomList:r,name:t.type},e||{through:s}));return a.throughPath&&(t.throughPath=a.throughPath),t.path=a.path,a.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.canMove(t))&&(t.path=this.defaultPath)}canMove(t){return this.moveMode&&t&&t.path.list.every((t=>!t.isOutside))}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(),name:exports.PointerEvent.MOVE}),this.hoverData=t)}updateCursor(t){if(this.config.cursor.stop||!this.config.pointer.hover)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,r=s.length;t<r&&(e=s.list[t],i=e.syncEventer?e.syncEventer.cursor:e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}emitTap(t){this.emit(exports.PointerEvent.TAP,t),this.emit(exports.PointerEvent.CLICK,t)}emitDoubleTap(t){this.emit(exports.PointerEvent.DOUBLE_TAP,t),this.emit(exports.PointerEvent.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout((()=>{this.longPressed=!0,this.emit(exports.PointerEvent.LONG_PRESS,t)}),this.config.pointer.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(exports.PointerEvent.LONG_TAP,t),L(t.path,exports.PointerEvent.LONG_TAP)&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){clearTimeout(this.longPressTimer),this.longPressed=!1}__onResize(){this.shrinkCanvasBounds=new e.Bounds(this.canvas.bounds),this.shrinkCanvasBounds.spread(-2)}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(e.ResizeEvent.RESIZE,this.__onResize,this)],t.once(e.LeaferEvent.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 r;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let a=i.length-1;a>-1;a--){if(r=i.list[a],O(r,t,e,!0,s))return;r.isApp&&y(r,t,e,!0,s)}for(let a=0,o=i.length;a<o;a++)if(r=i.list[a],r.isApp&&y(r,t,e,!1,s),O(r,t,e,!1,s))return}catch(t){D.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}},exports.InteractionHelper=v,exports.Keyboard=r,exports.LeaferTypeCreator=d,exports.MultiTouchHelper=w,exports.PointerButton=a,exports.UIEvent=o,Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/core",
3
- "version": "1.0.0-rc.21",
3
+ "version": "1.0.0-rc.22",
4
4
  "description": "@leafer-ui/core",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -29,11 +29,11 @@
29
29
  "leaferjs"
30
30
  ],
31
31
  "dependencies": {
32
- "@leafer-ui/draw": "1.0.0-rc.21",
33
- "@leafer-ui/app": "1.0.0-rc.21",
34
- "@leafer-ui/type": "1.0.0-rc.21",
35
- "@leafer-ui/interaction": "1.0.0-rc.21",
36
- "@leafer-ui/event": "1.0.0-rc.21",
37
- "@leafer-ui/hit": "1.0.0-rc.21"
32
+ "@leafer-ui/draw": "1.0.0-rc.22",
33
+ "@leafer-ui/app": "1.0.0-rc.22",
34
+ "@leafer-ui/type": "1.0.0-rc.22",
35
+ "@leafer-ui/interaction": "1.0.0-rc.22",
36
+ "@leafer-ui/event": "1.0.0-rc.22",
37
+ "@leafer-ui/hit": "1.0.0-rc.22"
38
38
  }
39
39
  }