@leafer-ui/core 1.0.4 → 1.0.5
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 +19 -16
- package/lib/core.esm.js +20 -17
- package/lib/core.esm.min.js +1 -1
- package/lib/core.min.cjs +1 -1
- package/package.json +10 -10
package/lib/core.cjs
CHANGED
|
@@ -671,9 +671,10 @@ class Dragger {
|
|
|
671
671
|
this.dragData = getDragEventData(data, data, data);
|
|
672
672
|
this.canAnimate = this.canDragOut = true;
|
|
673
673
|
}
|
|
674
|
-
getList() {
|
|
674
|
+
getList(realDraggable, hover) {
|
|
675
675
|
const { proxy } = this.interaction.selector;
|
|
676
|
-
|
|
676
|
+
const hasProxyList = proxy && proxy.list.length, dragList = exports.DragEvent.list || this.draggableList || emptyList;
|
|
677
|
+
return this.dragging && (hasProxyList ? (realDraggable ? emptyList : new core.LeafList(hover ? [...proxy.list, ...proxy.dragHoverExclude] : proxy.list)) : dragList);
|
|
677
678
|
}
|
|
678
679
|
checkDrag(data, canDrag) {
|
|
679
680
|
const { interaction } = this;
|
|
@@ -698,8 +699,8 @@ class Dragger {
|
|
|
698
699
|
this.dragging = canDrag && PointerButton.left(data);
|
|
699
700
|
if (this.dragging) {
|
|
700
701
|
this.interaction.emit(exports.DragEvent.START, this.dragData);
|
|
701
|
-
this.
|
|
702
|
-
this.setDragStartPoints(this.
|
|
702
|
+
this.getDraggableList(this.dragData.path);
|
|
703
|
+
this.setDragStartPoints(this.realDraggableList = this.getList(true));
|
|
703
704
|
}
|
|
704
705
|
}
|
|
705
706
|
}
|
|
@@ -707,12 +708,12 @@ class Dragger {
|
|
|
707
708
|
this.dragStartPoints = {};
|
|
708
709
|
list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
|
|
709
710
|
}
|
|
710
|
-
|
|
711
|
+
getDraggableList(path) {
|
|
711
712
|
let leaf;
|
|
712
713
|
for (let i = 0, len = path.length; i < len; i++) {
|
|
713
714
|
leaf = path.list[i];
|
|
714
|
-
if ((leaf.
|
|
715
|
-
this.
|
|
715
|
+
if ((leaf.draggable || leaf.editable) && leaf.hitSelf && !leaf.locked) {
|
|
716
|
+
this.draggableList = new core.LeafList(leaf);
|
|
716
717
|
break;
|
|
717
718
|
}
|
|
718
719
|
}
|
|
@@ -737,7 +738,7 @@ class Dragger {
|
|
|
737
738
|
}
|
|
738
739
|
dragReal() {
|
|
739
740
|
const { running } = this.interaction;
|
|
740
|
-
const list = this.
|
|
741
|
+
const list = this.realDraggableList;
|
|
741
742
|
if (list.length && running) {
|
|
742
743
|
const { totalX, totalY } = this.dragData;
|
|
743
744
|
list.forEach(leaf => leaf.draggable && leaf.move(exports.DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
|
|
@@ -826,7 +827,7 @@ class Dragger {
|
|
|
826
827
|
this.interaction.emit(exports.DragEvent.LEAVE, data, dragEnterPath);
|
|
827
828
|
}
|
|
828
829
|
dragReset() {
|
|
829
|
-
exports.DragEvent.list = exports.DragEvent.data = this.
|
|
830
|
+
exports.DragEvent.list = exports.DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
|
|
830
831
|
}
|
|
831
832
|
checkDragOut(data) {
|
|
832
833
|
const { interaction } = this;
|
|
@@ -967,6 +968,7 @@ const config = {
|
|
|
967
968
|
touch: {
|
|
968
969
|
preventDefault: true
|
|
969
970
|
},
|
|
971
|
+
multiTouch: {},
|
|
970
972
|
cursor: true,
|
|
971
973
|
keyEvent: true
|
|
972
974
|
};
|
|
@@ -1093,6 +1095,8 @@ class InteractionBase {
|
|
|
1093
1095
|
this.pointerUp(data);
|
|
1094
1096
|
}
|
|
1095
1097
|
multiTouch(data, list) {
|
|
1098
|
+
if (this.config.multiTouch.disabled)
|
|
1099
|
+
return;
|
|
1096
1100
|
const { move, angle, scale, center } = MultiTouchHelper.getData(list);
|
|
1097
1101
|
this.rotate(getRotateEventData(center, angle, data));
|
|
1098
1102
|
this.zoom(getZoomEventData(center, scale, data));
|
|
@@ -1282,7 +1286,7 @@ class InteractionBase {
|
|
|
1282
1286
|
data = this.hoverData;
|
|
1283
1287
|
if (!data)
|
|
1284
1288
|
return;
|
|
1285
|
-
this.findPath(data, { exclude: this.dragger.getList(), name: exports.PointerEvent.MOVE });
|
|
1289
|
+
this.findPath(data, { exclude: this.dragger.getList(false, true), name: exports.PointerEvent.MOVE });
|
|
1286
1290
|
this.hoverData = data;
|
|
1287
1291
|
}
|
|
1288
1292
|
updateCursor(data) {
|
|
@@ -1304,7 +1308,7 @@ class InteractionBase {
|
|
|
1304
1308
|
const { path } = data;
|
|
1305
1309
|
for (let i = 0, len = path.length; i < len; i++) {
|
|
1306
1310
|
leaf = path.list[i];
|
|
1307
|
-
cursor = leaf.syncEventer
|
|
1311
|
+
cursor = (leaf.syncEventer && leaf.syncEventer.cursor) || leaf.cursor;
|
|
1308
1312
|
if (cursor)
|
|
1309
1313
|
break;
|
|
1310
1314
|
}
|
|
@@ -1486,7 +1490,7 @@ ui$2.__updateHitCanvas = function () {
|
|
|
1486
1490
|
if (isHitPixel) {
|
|
1487
1491
|
const { renderBounds } = this.__layout;
|
|
1488
1492
|
const size = core.Platform.image.hitCanvasSize;
|
|
1489
|
-
const scale = h.hitScale = core.tempBounds.set(0, 0, size, size).getFitMatrix(renderBounds
|
|
1493
|
+
const scale = h.hitScale = core.tempBounds.set(0, 0, size, size).getFitMatrix(renderBounds).a;
|
|
1490
1494
|
const { x, y, width, height } = core.tempBounds.set(renderBounds).scale(scale);
|
|
1491
1495
|
h.resize({ width, height, pixelRatio: 1 });
|
|
1492
1496
|
h.clear();
|
|
@@ -1542,15 +1546,14 @@ ui$2.__hit = function (inner) {
|
|
|
1542
1546
|
return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
|
|
1543
1547
|
};
|
|
1544
1548
|
|
|
1545
|
-
const ui$1 =
|
|
1546
|
-
|
|
1547
|
-
rect.__updateHitCanvas = function () {
|
|
1549
|
+
const ui$1 = draw.UI.prototype, rect = draw.Rect.prototype, box = draw.Box.prototype;
|
|
1550
|
+
rect.__updateHitCanvas = box.__updateHitCanvas = function () {
|
|
1548
1551
|
if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
|
|
1549
1552
|
ui$1.__updateHitCanvas.call(this);
|
|
1550
1553
|
else if (this.__hitCanvas)
|
|
1551
1554
|
this.__hitCanvas = null;
|
|
1552
1555
|
};
|
|
1553
|
-
rect.__hitFill = function (inner) {
|
|
1556
|
+
rect.__hitFill = box.__hitFill = function (inner) {
|
|
1554
1557
|
return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : core.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
|
|
1555
1558
|
};
|
|
1556
1559
|
|
package/lib/core.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Leafer, State, UI, ImageManager, Rect, Group } from '@leafer-ui/draw';
|
|
1
|
+
import { Leafer, State, UI, ImageManager, Rect, Box, Group } from '@leafer-ui/draw';
|
|
2
2
|
export * from '@leafer-ui/draw';
|
|
3
3
|
import { registerUI, Creator, PropertyEvent, Debug, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, registerUIEvent, LeafList, BoundsHelper, PointHelper, Bounds, ResizeEvent, LeaferEvent, CanvasManager, Leaf, Matrix, Platform, tempBounds, LeaferCanvasBase } from '@leafer/core';
|
|
4
4
|
|
|
@@ -670,9 +670,10 @@ class Dragger {
|
|
|
670
670
|
this.dragData = getDragEventData(data, data, data);
|
|
671
671
|
this.canAnimate = this.canDragOut = true;
|
|
672
672
|
}
|
|
673
|
-
getList() {
|
|
673
|
+
getList(realDraggable, hover) {
|
|
674
674
|
const { proxy } = this.interaction.selector;
|
|
675
|
-
|
|
675
|
+
const hasProxyList = proxy && proxy.list.length, dragList = DragEvent.list || this.draggableList || emptyList;
|
|
676
|
+
return this.dragging && (hasProxyList ? (realDraggable ? emptyList : new LeafList(hover ? [...proxy.list, ...proxy.dragHoverExclude] : proxy.list)) : dragList);
|
|
676
677
|
}
|
|
677
678
|
checkDrag(data, canDrag) {
|
|
678
679
|
const { interaction } = this;
|
|
@@ -697,8 +698,8 @@ class Dragger {
|
|
|
697
698
|
this.dragging = canDrag && PointerButton.left(data);
|
|
698
699
|
if (this.dragging) {
|
|
699
700
|
this.interaction.emit(DragEvent.START, this.dragData);
|
|
700
|
-
this.
|
|
701
|
-
this.setDragStartPoints(this.
|
|
701
|
+
this.getDraggableList(this.dragData.path);
|
|
702
|
+
this.setDragStartPoints(this.realDraggableList = this.getList(true));
|
|
702
703
|
}
|
|
703
704
|
}
|
|
704
705
|
}
|
|
@@ -706,12 +707,12 @@ class Dragger {
|
|
|
706
707
|
this.dragStartPoints = {};
|
|
707
708
|
list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
|
|
708
709
|
}
|
|
709
|
-
|
|
710
|
+
getDraggableList(path) {
|
|
710
711
|
let leaf;
|
|
711
712
|
for (let i = 0, len = path.length; i < len; i++) {
|
|
712
713
|
leaf = path.list[i];
|
|
713
|
-
if ((leaf.
|
|
714
|
-
this.
|
|
714
|
+
if ((leaf.draggable || leaf.editable) && leaf.hitSelf && !leaf.locked) {
|
|
715
|
+
this.draggableList = new LeafList(leaf);
|
|
715
716
|
break;
|
|
716
717
|
}
|
|
717
718
|
}
|
|
@@ -736,7 +737,7 @@ class Dragger {
|
|
|
736
737
|
}
|
|
737
738
|
dragReal() {
|
|
738
739
|
const { running } = this.interaction;
|
|
739
|
-
const list = this.
|
|
740
|
+
const list = this.realDraggableList;
|
|
740
741
|
if (list.length && running) {
|
|
741
742
|
const { totalX, totalY } = this.dragData;
|
|
742
743
|
list.forEach(leaf => leaf.draggable && leaf.move(DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
|
|
@@ -825,7 +826,7 @@ class Dragger {
|
|
|
825
826
|
this.interaction.emit(DragEvent.LEAVE, data, dragEnterPath);
|
|
826
827
|
}
|
|
827
828
|
dragReset() {
|
|
828
|
-
DragEvent.list = DragEvent.data = this.
|
|
829
|
+
DragEvent.list = DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
|
|
829
830
|
}
|
|
830
831
|
checkDragOut(data) {
|
|
831
832
|
const { interaction } = this;
|
|
@@ -966,6 +967,7 @@ const config = {
|
|
|
966
967
|
touch: {
|
|
967
968
|
preventDefault: true
|
|
968
969
|
},
|
|
970
|
+
multiTouch: {},
|
|
969
971
|
cursor: true,
|
|
970
972
|
keyEvent: true
|
|
971
973
|
};
|
|
@@ -1092,6 +1094,8 @@ class InteractionBase {
|
|
|
1092
1094
|
this.pointerUp(data);
|
|
1093
1095
|
}
|
|
1094
1096
|
multiTouch(data, list) {
|
|
1097
|
+
if (this.config.multiTouch.disabled)
|
|
1098
|
+
return;
|
|
1095
1099
|
const { move, angle, scale, center } = MultiTouchHelper.getData(list);
|
|
1096
1100
|
this.rotate(getRotateEventData(center, angle, data));
|
|
1097
1101
|
this.zoom(getZoomEventData(center, scale, data));
|
|
@@ -1281,7 +1285,7 @@ class InteractionBase {
|
|
|
1281
1285
|
data = this.hoverData;
|
|
1282
1286
|
if (!data)
|
|
1283
1287
|
return;
|
|
1284
|
-
this.findPath(data, { exclude: this.dragger.getList(), name: PointerEvent.MOVE });
|
|
1288
|
+
this.findPath(data, { exclude: this.dragger.getList(false, true), name: PointerEvent.MOVE });
|
|
1285
1289
|
this.hoverData = data;
|
|
1286
1290
|
}
|
|
1287
1291
|
updateCursor(data) {
|
|
@@ -1303,7 +1307,7 @@ class InteractionBase {
|
|
|
1303
1307
|
const { path } = data;
|
|
1304
1308
|
for (let i = 0, len = path.length; i < len; i++) {
|
|
1305
1309
|
leaf = path.list[i];
|
|
1306
|
-
cursor = leaf.syncEventer
|
|
1310
|
+
cursor = (leaf.syncEventer && leaf.syncEventer.cursor) || leaf.cursor;
|
|
1307
1311
|
if (cursor)
|
|
1308
1312
|
break;
|
|
1309
1313
|
}
|
|
@@ -1485,7 +1489,7 @@ ui$2.__updateHitCanvas = function () {
|
|
|
1485
1489
|
if (isHitPixel) {
|
|
1486
1490
|
const { renderBounds } = this.__layout;
|
|
1487
1491
|
const size = Platform.image.hitCanvasSize;
|
|
1488
|
-
const scale = h.hitScale = tempBounds.set(0, 0, size, size).getFitMatrix(renderBounds
|
|
1492
|
+
const scale = h.hitScale = tempBounds.set(0, 0, size, size).getFitMatrix(renderBounds).a;
|
|
1489
1493
|
const { x, y, width, height } = tempBounds.set(renderBounds).scale(scale);
|
|
1490
1494
|
h.resize({ width, height, pixelRatio: 1 });
|
|
1491
1495
|
h.clear();
|
|
@@ -1541,15 +1545,14 @@ ui$2.__hit = function (inner) {
|
|
|
1541
1545
|
return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
|
|
1542
1546
|
};
|
|
1543
1547
|
|
|
1544
|
-
const ui$1 =
|
|
1545
|
-
|
|
1546
|
-
rect.__updateHitCanvas = function () {
|
|
1548
|
+
const ui$1 = UI.prototype, rect = Rect.prototype, box = Box.prototype;
|
|
1549
|
+
rect.__updateHitCanvas = box.__updateHitCanvas = function () {
|
|
1547
1550
|
if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
|
|
1548
1551
|
ui$1.__updateHitCanvas.call(this);
|
|
1549
1552
|
else if (this.__hitCanvas)
|
|
1550
1553
|
this.__hitCanvas = null;
|
|
1551
1554
|
};
|
|
1552
|
-
rect.__hitFill = function (inner) {
|
|
1555
|
+
rect.__hitFill = box.__hitFill = function (inner) {
|
|
1553
1556
|
return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
|
|
1554
1557
|
};
|
|
1555
1558
|
|
package/lib/core.esm.min.js
CHANGED
|
@@ -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,BoundsHelper as f,PointHelper as D,Bounds as y,ResizeEvent as E,LeaferEvent as P,CanvasManager as O,Leaf as T,Matrix as w,Platform as R,tempBounds as x,LeaferCanvasBase as C}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 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,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),void 0!==e&&(t.canvas.childIndex=e),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){if(t.context){if(e.matrix){const{a:i,b:a,c:s,d:n,e:r,f:o}=e.matrix;t.setTransform(i,a,s,n,r,o)}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=b([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}},k={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 A extends p{get spaceKey(){return S.isHoldSpaceKey()}get left(){return k.left(this)}get right(){return k.right(this)}get middle(){return k.middle(this)}constructor(t){super(t.type),this.bubbles=!0,this.getInner=this.getInnerPoint,this.getLocal=this.getLocalPoint,this.getPage=this.getPagePoint,Object.assign(this,t)}getBoxPoint(t){return t||(t=this.current),t.getBoxPoint(this)}getInnerPoint(t){return t||(t=this.current),t.getInnerPoint(this)}getLocalPoint(t){return t||(t=this.current),t.getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}static changeName(t,e){m.changeName(t,e)}}let H=class extends A{};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=H,I={};let N=class extends H{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)),f.includes(t,e)?(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)):(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(I,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(I,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(I,null,!0)}getPageTotal(){return this.getPageMove(!0)}getInnerTotal(t){return this.getInnerMove(t,!0)}getLocalTotal(t){return this.getLocalMove(t,!0)}getPageBounds(){const t=this.getPageTotal(),e=this.getPagePoint(),i={};return f.set(i,e.x-t.x,e.y-t.y,t.x,t.y),f.unsign(i),i}assignMove(t){I.x=t?this.totalX:this.moveX,I.y=t?this.totalY:this.moveY}};N.BEFORE_DRAG="drag.before_drag",N.START="drag.start",N.DRAG="drag",N.END="drag.end",N.OVER="drag.over",N.OUT="drag.out",N.ENTER="drag.enter",N.LEAVE="drag.leave",N=b([_()],N);const W=N;let z=class extends H{static setList(t){N.setList(t)}static setData(t){N.setData(t)}};z.DROP="drop",z=b([_()],z);let F=class extends N{};F.BEFORE_MOVE="move.before_move",F.START="move.start",F.MOVE="move",F.END="move.end",F=b([_()],F);let V=class extends A{};V.BEFORE_ROTATE="rotate.before_rotate",V.START="rotate.start",V.ROTATE="rotate",V.END="rotate.end",V=b([_()],V);let j=class extends N{};j.SWIPE="swipe",j.LEFT="swipe.left",j.RIGHT="swipe.right",j.UP="swipe.up",j.DOWN="swipe.down",j=b([_()],j);let K=class extends A{};K.BEFORE_ZOOM="zoom.before_zoom",K.START="zoom.start",K.ZOOM="zoom",K.END="zoom.end",K=b([_()],K);let U=class extends A{};function X(t){t.isApp||t.__eventIds.push(t.on_(F.BEFORE_MOVE,(e=>{t.zoomLayer.move(t.getValidMove(e.moveX,e.moveY))})),t.on_(K.BEFORE_ZOOM,(e=>{const{zoomLayer:i}=t,a=t.getValidScale(e.scale);1!==a&&(D.scaleOf(i,e,a),i.scale=i.__.scaleX*a)})))}U.DOWN="key.down",U.HOLD="key.hold",U.UP="key.up",U=b([_()],U);const Y=d.get("LeaferTypeCreator"),G={list:{},register(t,e){Z[t]?Y.repeat(t):Z[t]=e},run(t,e){const i=Z[t];i&&i(e)}},{list:Z,register:q}=G;q("design",X),q("document",(function(t){X(t);const{move:e,zoom:i}=t.config;e.scroll="limit",i.min=1})),q("block",(function(t){const{config:e}=t;(e.wheel||(e.wheel={})).preventDefault=!1,(e.touch||(e.touch={})).preventDefault="auto"}));const J=t.prototype;J.initType=function(t){G.run(t,this)},J.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 y(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}},J.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 Q{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(t.moveType||(t.moveType="move"),!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(F.START,this.moveData)}t.path=this.moveData.path,e.emit(F.BEFORE_MOVE,t),e.emit(F.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(K.START,this.zoomData)}t.path=this.zoomData.path,e.emit(K.BEFORE_ZOOM,t),e.emit(K.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(F.END,this.moveData),this.moveData=null)}zoomEnd(){this.zoomData&&(this.interaction.emit(K.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 $={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:tt.getSwipeDirection(D.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},pathCanDrag:t=>t&&t.list.some((t=>t.draggable||t.editable||!t.isLeafer&&t.hasEvent(N.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},tt=$,et=new v,{getDragEventData:it,getDropEventData:at,getSwipeEventData:st}=$;class nt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=it(t,t,t),this.canAnimate=this.canDragOut=!0}getList(){const{proxy:t}=this.interaction.selector;return!this.dragging||t&&t.list.length?et:N.list||this.dragableList||et}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(F.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&k.left(t),this.dragging&&(this.interaction.emit(N.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=it(a,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=s,this.moving?(this.dragData.moveType="drag",e.emit(F.BEFORE_MOVE,this.dragData),e.emit(F.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(N.BEFORE_DRAG,this.dragData),e.emit(N.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(N.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(N.OUT,t,i),e.emit(N.OVER,t,a)):e.emit(N.OVER,t,a)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:a}=t;e.emit(N.LEAVE,t,i,a),e.emit(N.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)),D.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=it(i,t,t);if(n&&(r.throughPath=n),r.path=s,this.moving&&(this.moving=!1,r.moveType="drag",e.emit(F.END,r)),this.dragging){const s=this.getList();this.dragging=!1,e.emit(N.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(D.getDistance(e,t)>s.config.pointer.swipeDistance){const t=st(e,i,a);this.interaction.emit(t.type,t)}}drop(t,e,i){const a=at(t,e,N.data);a.path=i,this.interaction.emit(z.DROP,a),this.interaction.emit(N.LEAVE,t,i)}dragReset(){N.list=N.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=f.maxX(r),c=f.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,D.move(i,l,g),D.move(this.dragData,l,g),e.move(Object.assign(Object.assign({},t),{moveX:l,moveY:g,totalX:u,totalY:p,moveType:"drag"})),e.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const rt=d.get("emit");const ot=["move","zoom","rotate","key"];function ht(t,e,i,a,s){if(ot.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!ct(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&&dt(n,e,i,a,s)}}function dt(t,i,a,s,n){if(t.destroyed)return!1;if(t.__.hitSelf&&!ct(t,n)&&(e.updateEventStyle&&!s&&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 ct(t,e){return e&&e.has(t)}const lt={getData(t){const e=t[0],i=t[1],a=D.getCenter(e.from,i.from),s=D.getCenter(e.to,i.to),n={x:s.x-a.x,y:s.y-a.y},r=D.getDistance(e.from,i.from);return{move:n,scale:D.getDistance(e.to,i.to)/r,angle:D.getRotation(e.from,i.from,e.to,i.to),center:s}}},gt={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},touch:{preventDefault:!0},cursor:!0,keyEvent:!0},{pathHasEventType:ut,getMoveEventData:pt,getZoomEventData:mt,getRotateEventData:_t,pathCanDrag:vt,pathHasOutside:ft}=$;class Dt{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.config.pointer.hover&&!this.config.mobile}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.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&k.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&k.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=c.clone(gt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new v(t),this.transformer=new Q(this),this.dragger=new nt(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&&(k.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(H.BEFORE_DOWN,t),this.emit(H.DOWN,t),k.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=k.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&k.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=D.getDistance(this.downData,t)>i;e&&(this.waitTap&&this.pointerWaitCancel(),this.waitRightTap=!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;k.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(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}=lt.getData(e);this.rotate(_t(n,a,t)),this.zoom(mt(n,s,t)),this.move(pt(n,i,t))}menu(t){this.findPath(t),this.emit(H.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(H.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,S.setDownCode(e),this.emit(U.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(U.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]=!1,S.setUpCode(e),this.emit(U.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.canHover&&(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(z.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=>ut(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.moveMode&&!ft(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.config.move.drag&&!vt(t.path))&&!ft(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData: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||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path: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}getLocal(t,e){const i=this.canvas.getClientBounds(e);return{x:t.clientX-i.x,y:t.clientY-i.y}}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),(ut(t.path,H.LONG_TAP)||ut(t.path,H.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){clearTimeout(this.longPressTimer),this.longPressed=!1}__onResize(){this.shrinkCanvasBounds=new y(this.canvas.bounds),this.shrinkCanvasBounds.spread(-2)}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(E.RESIZE,this.__onResize,this)],t.once(P.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],dt(s,t,e,!0,a))return;s.isApp&&ht(s,t,e,!0,a)}for(let n=0,r=i.length;n<r;n++)if(s=i.list[n],s.isApp&&ht(s,t,e,!1,a),dt(s,t,e,!1,a))return}catch(t){rt.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 yt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}yt.custom={};class Et extends O{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{toInnerRadiusPointOf:Pt,copy:Ot,setRadius:Tt}=D,wt={},Rt=T.prototype;Rt.__hitWorld=function(t){if(!this.__.hitSelf)return!1;this.__.hitRadius&&(Ot(wt,t),Tt(t=wt,this.__.hitRadius)),Pt(t,this.__world,wt);const{width:e,height:i}=this.__world,a=e<10&&i<10;if(this.__.hitBox||a){if(f.hitRadiusPoint(this.__layout.boxBounds,wt))return!0;if(a)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(wt)},Rt.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},Rt.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},Rt.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},Rt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const xt=new w,Ct=i.prototype;Ct.__updateHitCanvas=function(){const t=this.__,{hitCanvasManager:e}=this.leafer,i=(t.__pixelFill||t.__isCanvas)&&"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=R.image.hitCanvasSize,o=r.hitScale=x.set(0,0,n,n).getFitMatrix(e,.5).a,{x:h,y:d,width:c,height:l}=x.set(e).scale(o);r.resize({width:c,height:l,pixelRatio:1}),r.clear(),a.patternLocked=!0,this.__renderShape(r,{matrix:xt.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)},Ct.__hit=function(t){"miniapp"===R.name&&this.__drawHitPath(this.__hitCanvas);const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,a=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__pixelFill||e.__isCanvas))||"all"===i;if(a&&this.__hitFill(t))return!0;const{hitStroke:s,__strokeWidth:n}=e,r=e.stroke&&("path"===s||"pixel"===s&&!e.__pixelStroke)||"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 bt=new i,Lt=s.prototype;Lt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?bt.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Lt.__hitFill=function(t){return this.__hitCanvas?bt.__hitFill.call(this,t):f.hitRadiusPoint(this.__layout.boxBounds,t)};const Mt=i.prototype,St=n.prototype;Mt.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},Mt.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},St.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};const kt=C.prototype;kt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},kt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},kt.hitPixel=function(t,e,i=1){let{x:a,y:s,radiusX:n,radiusY:r}=t;e&&(a-=e.x,s-=e.y),x.set(a-n,s-r,2*n,2*r).scale(i).ceil();const{data:o}=this.context.getImageData(x.x,x.y,x.width||1,x.height||1);for(let t=0,e=o.length;t<e;t+=4)if(o[t+3]>0)return!0;return o[3]>0};export{L as App,yt as Cursor,N as DragEvent,z as DropEvent,Et as HitCanvasManager,Dt as InteractionBase,$ as InteractionHelper,U as KeyEvent,S as Keyboard,G as LeaferTypeCreator,F as MoveEvent,lt as MultiTouchHelper,W as MyDragEvent,B as MyPointerEvent,k as PointerButton,H as PointerEvent,V as RotateEvent,j as SwipeEvent,A as UIEvent,K as ZoomEvent,X as addInteractionWindow};
|
|
1
|
+
import{Leafer as t,State as e,UI as i,ImageManager as a,Rect as s,Box as n,Group as r}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as o,Creator as h,PropertyEvent as d,Debug as c,DataHelper as l,canvasSizeAttrs as g,LayoutEvent as u,RenderEvent as p,Event as m,EventCreator as v,registerUIEvent as _,LeafList as f,BoundsHelper as D,PointHelper as y,Bounds as E,ResizeEvent as P,LeaferEvent as O,CanvasManager as T,Leaf as w,Matrix as R,Platform as x,tempBounds as C,LeaferCanvasBase as b}from"@leafer/core";function L(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 M=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=h.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_(d.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,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),void 0!==e&&(t.canvas.childIndex=e),this.__listenChildEvents(t)}__onPropertyChange(){c.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){if(t.context){if(e.matrix){const{a:i,b:a,c:s,d:n,e:r,f:o}=e.matrix;t.setTransform(i,a,s,n,r,o)}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&&l.assign(e,t),this.autoLayout&&l.copyAttrs(e,this,g),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once(u.END,(()=>this.__onReady())),t.once(p.START,(()=>this.__onCreated())),t.once(p.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(p.END,this.__onChildRenderEnd,this))}};M=L([o()],M);const S={},k={isHoldSpaceKey:()=>k.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 H extends m{get spaceKey(){return k.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,this.getInner=this.getInnerPoint,this.getLocal=this.getLocalPoint,this.getPage=this.getPagePoint,Object.assign(this,t)}getBoxPoint(t){return t||(t=this.current),t.getBoxPoint(this)}getInnerPoint(t){return t||(t=this.current),t.getInnerPoint(this)}getLocalPoint(t){return t||(t=this.current),t.getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}static changeName(t,e){v.changeName(t,e)}}let B=class extends H{};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=L([_()],B);const I=B,N={};let W=class extends B{static setList(t){this.list=t instanceof f?t:new f(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)),D.includes(t,e)?(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)):(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(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)}getPageBounds(){const t=this.getPageTotal(),e=this.getPagePoint(),i={};return D.set(i,e.x-t.x,e.y-t.y,t.x,t.y),D.unsign(i),i}assignMove(t){N.x=t?this.totalX:this.moveX,N.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=L([_()],W);const F=W;let z=class extends B{static setList(t){W.setList(t)}static setData(t){W.setData(t)}};z.DROP="drop",z=L([_()],z);let V=class extends W{};V.BEFORE_MOVE="move.before_move",V.START="move.start",V.MOVE="move",V.END="move.end",V=L([_()],V);let j=class extends H{};j.BEFORE_ROTATE="rotate.before_rotate",j.START="rotate.start",j.ROTATE="rotate",j.END="rotate.end",j=L([_()],j);let K=class extends W{};K.SWIPE="swipe",K.LEFT="swipe.left",K.RIGHT="swipe.right",K.UP="swipe.up",K.DOWN="swipe.down",K=L([_()],K);let U=class extends H{};U.BEFORE_ZOOM="zoom.before_zoom",U.START="zoom.start",U.ZOOM="zoom",U.END="zoom.end",U=L([_()],U);let X=class extends H{};function Y(t){t.isApp||t.__eventIds.push(t.on_(V.BEFORE_MOVE,(e=>{t.zoomLayer.move(t.getValidMove(e.moveX,e.moveY))})),t.on_(U.BEFORE_ZOOM,(e=>{const{zoomLayer:i}=t,a=t.getValidScale(e.scale);1!==a&&(y.scaleOf(i,e,a),i.scale=i.__.scaleX*a)})))}X.DOWN="key.down",X.HOLD="key.hold",X.UP="key.up",X=L([_()],X);const G=c.get("LeaferTypeCreator"),Z={list:{},register(t,e){q[t]?G.repeat(t):q[t]=e},run(t,e){const i=q[t];i&&i(e)}},{list:q,register:J}=Z;J("design",Y),J("document",(function(t){Y(t);const{move:e,zoom:i}=t.config;e.scroll="limit",i.min=1})),J("block",(function(t){const{config:e}=t;(e.wheel||(e.wheel={})).preventDefault=!1,(e.touch||(e.touch={})).preventDefault="auto"}));const Q=t.prototype;Q.initType=function(t){Z.run(t,this)},Q.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}},Q.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 ${get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(t.moveType||(t.moveType="move"),!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(V.START,this.moveData)}t.path=this.moveData.path,e.emit(V.BEFORE_MOVE,t),e.emit(V.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(U.START,this.zoomData)}t.path=this.zoomData.path,e.emit(U.BEFORE_ZOOM,t),e.emit(U.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(j.START,this.rotateData)}t.path=this.rotateData.path,e.emit(j.BEFORE_ROTATE,t),e.emit(j.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(V.END,this.moveData),this.moveData=null)}zoomEnd(){this.zoomData&&(this.interaction.emit(U.END,this.zoomData),this.zoomData=null)}rotateEnd(){this.rotateData&&(this.interaction.emit(j.END,this.rotateData),this.rotateData=null)}destroy(){this.zoomData=this.moveData=this.rotateData=null}}const tt={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?K.UP:t>45&&t<135?K.DOWN:t<=45&&t>=-45?K.RIGHT:K.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:et.getSwipeDirection(y.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 f,{list:a}=t;for(let t=0,s=a.length;t<s;t++)a[t].hasEvent(e)&&i.add(a[t]);return i},pathCanDrag:t=>t&&t.list.some((t=>t.draggable||t.editable||!t.isLeafer&&t.hasEvent(W.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},et=tt,it=new f,{getDragEventData:at,getDropEventData:st,getSwipeEventData:nt}=tt;class rt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=at(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,a=i&&i.list.length,s=W.list||this.draggableList||it;return this.dragging&&(a?t?it:new f(e?[...i.list,...i.dragHoverExclude]:i.list):s)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(V.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.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach((t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y}))}getDraggableList(t){let e;for(let i=0,a=t.length;i<a;i++)if(e=t.list[i],(e.draggable||e.editable)&&e.hitSelf&&!e.locked){this.draggableList=new f(e);break}}drag(t){const{interaction:e,dragData:i,downData:a}=this,{path:s,throughPath:n}=a;this.dragData=at(a,i,t),n&&(this.dragData.throughPath=n),this.dragData.path=s,this.moving?(this.dragData.moveType="drag",e.emit(V.BEFORE_MOVE,this.dragData),e.emit(V.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.realDraggableList;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)),y.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=at(i,t,t);if(n&&(r.throughPath=n),r.path=s,this.moving&&(this.moving=!1,r.moveType="drag",e.emit(V.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(y.getDistance(e,t)>s.config.pointer.swipeDistance){const t=nt(e,i,a);this.interaction.emit(t.type,t)}}drop(t,e,i){const a=st(t,e,W.data);a.path=i,this.interaction.emit(z.DROP,a),this.interaction.emit(W.LEAVE,t,i)}dragReset(){W.list=W.data=this.draggableList=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,y.move(i,l,g),y.move(this.dragData,l,g),e.move(Object.assign(Object.assign({},t),{moveX:l,moveY:g,totalX:u,totalY:p,moveType:"drag"})),e.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const ot=c.get("emit");const ht=["move","zoom","rotate","key"];function dt(t,e,i,a,s){if(ht.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!lt(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&&ct(n,e,i,a,s)}}function ct(t,i,a,s,n){if(t.destroyed)return!1;if(t.__.hitSelf&&!lt(t,n)&&(e.updateEventStyle&&!s&&e.updateEventStyle(t,i),t.hasEvent(i,s))){a.phase=s?1:t===a.target?2:3;const e=v.get(i,a);if(t.emitEvent(e,s),e.isStop)return!0}return!1}function lt(t,e){return e&&e.has(t)}const gt={getData(t){const e=t[0],i=t[1],a=y.getCenter(e.from,i.from),s=y.getCenter(e.to,i.to),n={x:s.x-a.x,y:s.y-a.y},r=y.getDistance(e.from,i.from);return{move:n,scale:y.getDistance(e.to,i.to)/r,angle:y.getRotation(e.from,i.from,e.to,i.to),center:s}}},ut={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},touch:{preventDefault:!0},multiTouch:{},cursor:!0,keyEvent:!0},{pathHasEventType:pt,getMoveEventData:mt,getZoomEventData:vt,getRotateEventData:_t,pathCanDrag:ft,pathHasOutside:Dt}=tt;class yt{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.config.pointer.hover&&!this.config.mobile}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.canHover&&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&&k.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,e,i,a){this.config=l.clone(ut),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new f(t),this.transformer=new $(this),this.dragger=new rt(this),a&&(this.config=l.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)),this.waitRightTap=A.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&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=y.getDistance(this.downData,t)>i;e&&(this.waitTap&&this.pointerWaitCancel(),this.waitRightTap=!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),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(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){if(this.config.multiTouch.disabled)return;const{move:i,angle:a,scale:s,center:n}=gt.getData(e);this.rotate(_t(n,a,t)),this.zoom(vt(n,s,t)),this.move(mt(n,i,t))}menu(t){this.findPath(t),this.emit(B.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(B.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,k.setDownCode(e),this.emit(X.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(X.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]=!1,k.setUpCode(e),this.emit(X.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.canHover&&(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(z.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=>pt(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.moveMode&&!Dt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.config.move.drag&&!ft(t.path))&&!Dt(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData: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(!1,!0),name:B.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path: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}getLocal(t,e){const i=this.canvas.getClientBounds(e);return{x:t.clientX-i.x,y:t.clientY-i.y}}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),(pt(t.path,B.LONG_TAP)||pt(t.path,B.LONG_PRESS))&&(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_(P.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],ct(s,t,e,!0,a))return;s.isApp&&dt(s,t,e,!0,a)}for(let n=0,r=i.length;n<r;n++)if(s=i.list[n],s.isApp&&dt(s,t,e,!1,a),ct(s,t,e,!1,a))return}catch(t){ot.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 Et{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}Et.custom={};class Pt extends T{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new f,this.pixelList=new f}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),h.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),h.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{toInnerRadiusPointOf:Ot,copy:Tt,setRadius:wt}=y,Rt={},xt=w.prototype;xt.__hitWorld=function(t){if(!this.__.hitSelf)return!1;this.__.hitRadius&&(Tt(Rt,t),wt(t=Rt,this.__.hitRadius)),Ot(t,this.__world,Rt);const{width:e,height:i}=this.__world,a=e<10&&i<10;if(this.__.hitBox||a){if(D.hitRadiusPoint(this.__layout.boxBounds,Rt))return!0;if(a)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(Rt)},xt.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},xt.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},xt.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},xt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Ct=new R,bt=i.prototype;bt.__updateHitCanvas=function(){const t=this.__,{hitCanvasManager:e}=this.leafer,i=(t.__pixelFill||t.__isCanvas)&&"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=x.image.hitCanvasSize,o=r.hitScale=C.set(0,0,n,n).getFitMatrix(e).a,{x:h,y:d,width:c,height:l}=C.set(e).scale(o);r.resize({width:c,height:l,pixelRatio:1}),r.clear(),a.patternLocked=!0,this.__renderShape(r,{matrix:Ct.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)},bt.__hit=function(t){"miniapp"===x.name&&this.__drawHitPath(this.__hitCanvas);const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,a=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__pixelFill||e.__isCanvas))||"all"===i;if(a&&this.__hitFill(t))return!0;const{hitStroke:s,__strokeWidth:n}=e,r=e.stroke&&("path"===s||"pixel"===s&&!e.__pixelStroke)||"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 Lt=i.prototype,Mt=s.prototype,St=n.prototype;Mt.__updateHitCanvas=St.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Lt.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Mt.__hitFill=St.__hitFill=function(t){return this.__hitCanvas?Lt.__hitFill.call(this,t):D.hitRadiusPoint(this.__layout.boxBounds,t)};const kt=i.prototype,At=r.prototype;kt.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},kt.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},At.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};const Ht=b.prototype;Ht.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},Ht.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},Ht.hitPixel=function(t,e,i=1){let{x:a,y:s,radiusX:n,radiusY:r}=t;e&&(a-=e.x,s-=e.y),C.set(a-n,s-r,2*n,2*r).scale(i).ceil();const{data:o}=this.context.getImageData(C.x,C.y,C.width||1,C.height||1);for(let t=0,e=o.length;t<e;t+=4)if(o[t+3]>0)return!0;return o[3]>0};export{M as App,Et as Cursor,W as DragEvent,z as DropEvent,Pt as HitCanvasManager,yt as InteractionBase,tt as InteractionHelper,X as KeyEvent,k as Keyboard,Z as LeaferTypeCreator,V as MoveEvent,gt as MultiTouchHelper,F as MyDragEvent,I as MyPointerEvent,A as PointerButton,B as PointerEvent,j as RotateEvent,K as SwipeEvent,H as UIEvent,U as ZoomEvent,Y as addInteractionWindow};
|
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 a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}"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:a,editor:r}=t;i&&(this.ground=this.addLeafer(i)),(s||r)&&(this.tree=this.addLeafer(s)),(a||r)&&(this.sky=this.addLeafer(a||{type:"draw",usePartRender:!1})),r&&(this.editor=e.Creator.editor(r),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,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),void 0!==e&&(t.canvas.childIndex=e),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){if(t.context){if(e.matrix){const{a:i,b:s,c:a,d:r,e:n,f:o}=e.matrix;t.setTransform(i,s,a,r,n,o)}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={},a={isHoldSpaceKey:()=>a.isHold("Space"),isHold:t=>s[t],setDownCode(t){s[t]||(s[t]=!0)},setUpCode(t){s[t]=!1}},r={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 n extends e.Event{get spaceKey(){return a.isHoldSpaceKey()}get left(){return r.left(this)}get right(){return r.right(this)}get middle(){return r.middle(this)}constructor(t){super(t.type),this.bubbles=!0,this.getInner=this.getInnerPoint,this.getLocal=this.getLocalPoint,this.getPage=this.getPagePoint,Object.assign(this,t)}getBoxPoint(t){return t||(t=this.current),t.getBoxPoint(this)}getInnerPoint(t){return t||(t=this.current),t.getInnerPoint(this)}getLocalPoint(t){return t||(t=this.current),t.getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}static changeName(t,i){e.EventCreator.changeName(t,i)}}exports.PointerEvent=class extends n{},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 o=exports.PointerEvent,h={};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:a,x:r,y:n}=t,o=t.getLocalPoint(i,null,!0);return o.x+=e.x-r,o.y+=e.y-n,a&&this.getMoveInDragBounds(t.__local,"parent"===a?t.parent.boxBounds:a,o,!0),"x"===s&&(o.y=0),"y"===s&&(o.x=0),o}static getMoveInDragBounds(t,i,s,a){const r=t.x+s.x,n=t.y+s.y,o=r+t.width,h=n+t.height,p=i.x+i.width,g=i.y+i.height;return a||(s=Object.assign({},s)),e.BoundsHelper.includes(t,i)?(r>i.x?s.x+=i.x-r:o<p&&(s.x+=p-o),n>i.y?s.y+=i.y-n:h<g&&(s.y+=g-h)):(r<i.x?s.x+=i.x-r:o>p&&(s.x+=p-o),n<i.y?s.y+=i.y-n:h>g&&(s.y+=g-h)),s}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)}getPageBounds(){const t=this.getPageTotal(),i=this.getPagePoint(),s={};return e.BoundsHelper.set(s,i.x-t.x,i.y-t.y,t.x,t.y),e.BoundsHelper.unsign(s),s}assignMove(t){h.x=t?this.totalX:this.moveX,h.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);const p=exports.DragEvent;function g(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,a=t.getValidScale(i.scale);1!==a&&(e.PointHelper.scaleOf(s,i,a),s.scale=s.__.scaleX*a)})))}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 n{},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 n{},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 n{},exports.KeyEvent.DOWN="key.down",exports.KeyEvent.HOLD="key.hold",exports.KeyEvent.UP="key.up",exports.KeyEvent=i([e.registerUIEvent()],exports.KeyEvent);const d=e.Debug.get("LeaferTypeCreator"),l={list:{},register(t,e){c[t]?d.repeat(t):c[t]=e},run(t,e){const i=c[t];i&&i(e)}},{list:c,register:v}=l;v("design",g),v("document",(function(t){g(t);const{move:e,zoom:i}=t.config;e.scroll="limit",i.min=1})),v("block",(function(t){const{config:e}=t;(e.wheel||(e.wheel={})).preventDefault=!1,(e.touch||(e.touch={})).preventDefault="auto"}));const u=t.Leafer.prototype;u.initType=function(t){l.run(t,this)},u.getValidMove=function(t,i){const{scroll:s,disabled:a}=this.app.config.move;if(s&&(Math.abs(t)>Math.abs(i)?i=0:t=0,"limit"===s)){const{x:s,y:a,width:r,height:n}=new e.Bounds(this.__world).addPoint(this.zoomLayer),o=s+r-this.width,h=a+n-this.height;s>=0&&o<=0?t=0:t>0?s+t>0&&(t=-s):t<0&&o+t<0&&(t=-o),a>=0&&h<=0?i=0:i>0?a+i>0&&(i=-a):i<0&&h+i<0&&(i=-h)}return{x:a?0:t,y:a?0:i}},u.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:i,max:s,disabled:a}=this.app.config.zoom,r=Math.abs(e*t);return r<i?t=i/e:r>s&&(t=s/e),a?1:t};class E{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(t.moveType||(t.moveType="move"),!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 m={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:_.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:a}=t;for(let t=0,e=a.length;t<e;t++)a[t].hasEvent(i)&&s.add(a[t]);return s},pathCanDrag:t=>t&&t.list.some((t=>t.draggable||t.editable||!t.isLeafer&&t.hasEvent(exports.DragEvent.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},_=m,x=new e.LeafList,{getDragEventData:f,getDropEventData:D,getSwipeEventData:P}=m;class y{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=f(t,t,t),this.canAnimate=this.canDragOut=!0}getList(){const{proxy:t}=this.interaction.selector;return!this.dragging||t&&t.list.length?x:exports.DragEvent.list||this.dragableList||x}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(exports.MoveEvent.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&r.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,a=t.length;s<a;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:a,throughPath:r}=s;this.dragData=f(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",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:a}=this.dragData;this.interaction.config.move.dragAnimate&&this.canAnimate&&this.moving&&(Math.abs(s)>1||Math.abs(a)>1)?(t=Object.assign({},t),i=.9*(i||("touch"===t.pointerType?2:1)),e.PointHelper.move(t,s*i,a*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:a,throughPath:r}=i,n=f(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(exports.MoveEvent.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.emit(exports.DragEvent.END,n),this.swipe(t,i,s,n),this.drop(t,a,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,a){const{interaction:r}=this;if(e.PointHelper.getDistance(i,t)>r.config.pointer.swipeDistance){const t=P(i,s,a);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=D(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:a}=this,{autoDistance:r,dragOut:n}=i.config.move;if(!n||!a||!r)return;const o=i.shrinkCanvasBounds,{x:h,y:p}=o,g=e.BoundsHelper.maxX(o),d=e.BoundsHelper.maxY(o),l=t.x<h?r:g<t.x?-r:0,c=t.y<p?r:d<t.y?-r:0;let v=0,u=0;this.autoMoveTimer=setInterval((()=>{v+=l,u+=c,e.PointHelper.move(s,l,c),e.PointHelper.move(this.dragData,l,c),i.move(Object.assign(Object.assign({},t),{moveX:l,moveY:c,totalX:v,totalY:u,moveType:"drag"})),i.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const O=e.Debug.get("emit");const T=["move","zoom","rotate","key"];function w(t,e,i,s,a){if(T.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!L(t,a)){let r;for(let n=0,o=t.children.length;n<o;n++)r=t.children[n],!i.path.has(r)&&r.__.hittable&&R(r,e,i,s,a)}}function R(i,s,a,r,n){if(i.destroyed)return!1;if(i.__.hitSelf&&!L(i,n)&&(t.State.updateEventStyle&&!r&&t.State.updateEventStyle(i,s),i.hasEvent(s,r))){a.phase=r?1:i===a.target?2:3;const t=e.EventCreator.get(s,a);if(i.emitEvent(t,r),t.isStop)return!0}return!1}function L(t,e){return e&&e.has(t)}const C={getData(t){const i=t[0],s=t[1],a=e.PointHelper.getCenter(i.from,s.from),r=e.PointHelper.getCenter(i.to,s.to),n={x:r.x-a.x,y:r.y-a.y},o=e.PointHelper.getDistance(i.from,s.from);return{move:n,scale:e.PointHelper.getDistance(i.to,s.to)/o,angle:e.PointHelper.getRotation(i.from,s.from,i.to,s.to),center:r}}},b={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},touch:{preventDefault:!0},cursor:!0,keyEvent:!0},{pathHasEventType:M,getMoveEventData:S,getZoomEventData:H,getRotateEventData:B,pathCanDrag:k,pathHasOutside:A}=m;class I{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}I.custom={};class K 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{toInnerRadiusPointOf:U,copy:W,setRadius:j}=e.PointHelper,z={},N=e.Leaf.prototype;N.__hitWorld=function(t){if(!this.__.hitSelf)return!1;this.__.hitRadius&&(W(z,t),j(t=z,this.__.hitRadius)),U(t,this.__world,z);const{width:i,height:s}=this.__world,a=i<10&&s<10;if(this.__.hitBox||a){if(e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,z))return!0;if(a)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(z)},N.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},N.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},N.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},N.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const F=new e.Matrix,V=t.UI.prototype;V.__updateHitCanvas=function(){const i=this.__,{hitCanvasManager:s}=this.leafer,a=(i.__pixelFill||i.__isCanvas)&&"pixel"===i.hitFill,r=i.__pixelStroke&&"pixel"===i.hitStroke,n=a||r;this.__hitCanvas||(this.__hitCanvas=n?s.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):s.getPathType(this));const o=this.__hitCanvas;if(n){const{renderBounds:s}=this.__layout,n=e.Platform.image.hitCanvasSize,h=o.hitScale=e.tempBounds.set(0,0,n,n).getFitMatrix(s,.5).a,{x:p,y:g,width:d,height:l}=e.tempBounds.set(s).scale(h);o.resize({width:d,height:l,pixelRatio:1}),o.clear(),t.ImageManager.patternLocked=!0,this.__renderShape(o,{matrix:F.setWith(this.__world).scaleWith(1/h).invertWith().translate(-p,-g)},!a,!r),t.ImageManager.patternLocked=!1,o.resetTransform(),i.__isHitPixel=!0}else i.__isHitPixel&&(i.__isHitPixel=!1);this.__drawHitPath(o),o.setStrokeOptions(i)},V.__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,a=(i.fill||i.__isCanvas)&&("path"===s||"pixel"===s&&!(i.__pixelFill||i.__isCanvas))||"all"===s;if(a&&this.__hitFill(t))return!0;const{hitStroke:r,__strokeWidth:n}=i,o=i.stroke&&("path"===r||"pixel"===r&&!i.__pixelStroke)||"all"===r;if(!a&&!o)return!1;const h=2*t.radiusX;let p=h;if(o)switch(i.strokeAlign){case"inside":if(p+=2*n,!a&&this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h;break;case"center":p+=n;break;case"outside":if(p+=2*n,!a){if(!this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h}}return!!p&&this.__hitStroke(t,p)};const X=new t.UI,Z=t.Rect.prototype;Z.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?X.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Z.__hitFill=function(t){return this.__hitCanvas?X.__hitFill.call(this,t):e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,t)};const Y=t.UI.prototype,G=t.Group.prototype;Y.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},Y.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},G.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};const q=e.LeaferCanvasBase.prototype;q.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},q.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},q.hitPixel=function(t,i,s=1){let{x:a,y:r,radiusX:n,radiusY:o}=t;i&&(a-=i.x,r-=i.y),e.tempBounds.set(a-n,r-o,2*n,2*o).scale(s).ceil();const{data:h}=this.context.getImageData(e.tempBounds.x,e.tempBounds.y,e.tempBounds.width||1,e.tempBounds.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0},exports.Cursor=I,exports.HitCanvasManager=K,exports.InteractionBase=class{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.config.pointer.hover&&!this.config.mobile}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.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&r.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&r.right(this.downData)}get isHoldSpaceKey(){return this.config.move.holdSpaceKey&&a.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,i,s,a){this.config=e.DataHelper.clone(b),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=i,this.selector=s,this.defaultPath=new e.LeafList(t),this.transformer=new E(this),this.dragger=new y(this),a&&(this.config=e.DataHelper.default(a,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(r.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),r.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=r.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&r.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.waitRightTap=!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;r.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(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:a,center:r}=C.getData(e);this.rotate(B(r,s,t)),this.zoom(H(r,a,t)),this.move(S(r,i,t))}menu(t){this.findPath(t),this.emit(exports.PointerEvent.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(exports.PointerEvent.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,a.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){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]=!1,a.setUpCode(e),this.emit(exports.KeyEvent.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.canHover&&(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,a=[exports.PointerEvent.DOUBLE_TAP,exports.PointerEvent.DOUBLE_CLICK].some((e=>M(t.path,e)));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout((()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}),e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.config.pointer,{bottomList:a}=this,r=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));return r.throughPath&&(t.throughPath=r.throughPath),t.path=r.path,r.path}isRootPath(t){return t&&t.path.list[0].isLeafer}isTreePath(t){const e=this.target.app;return!(!e||!e.isApp)&&(e.editor&&!t.path.has(e.editor)&&t.path.has(e.tree)&&!t.target.syncEventer)}checkPath(t,e){(e||this.moveMode&&!A(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.config.move.drag&&!k(t.path))&&!A(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData:s}=this;!t&&s&&(t=s),t&&(this.findPath(t,e),i&&s&&t.path.addList(s.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(),name:exports.PointerEvent.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer?e.syncEventer.cursor:e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e);return{x:t.clientX-i.x,y:t.clientY-i.y}}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),(M(t.path,exports.PointerEvent.LONG_TAP)||M(t.path,exports.PointerEvent.LONG_PRESS))&&(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 a;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let r=i.length-1;r>-1;r--){if(a=i.list[r],R(a,t,e,!0,s))return;a.isApp&&w(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&w(a,t,e,!1,s),R(a,t,e,!1,s))return}catch(t){O.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=m,exports.Keyboard=a,exports.LeaferTypeCreator=l,exports.MultiTouchHelper=C,exports.MyDragEvent=p,exports.MyPointerEvent=o,exports.PointerButton=r,exports.UIEvent=n,exports.addInteractionWindow=g,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 a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}"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:a,editor:r}=t;i&&(this.ground=this.addLeafer(i)),(s||r)&&(this.tree=this.addLeafer(s)),(a||r)&&(this.sky=this.addLeafer(a||{type:"draw",usePartRender:!1})),r&&(this.editor=e.Creator.editor(r),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,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),void 0!==e&&(t.canvas.childIndex=e),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){if(t.context){if(e.matrix){const{a:i,b:s,c:a,d:r,e:n,f:o}=e.matrix;t.setTransform(i,s,a,r,n,o)}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={},a={isHoldSpaceKey:()=>a.isHold("Space"),isHold:t=>s[t],setDownCode(t){s[t]||(s[t]=!0)},setUpCode(t){s[t]=!1}},r={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 n extends e.Event{get spaceKey(){return a.isHoldSpaceKey()}get left(){return r.left(this)}get right(){return r.right(this)}get middle(){return r.middle(this)}constructor(t){super(t.type),this.bubbles=!0,this.getInner=this.getInnerPoint,this.getLocal=this.getLocalPoint,this.getPage=this.getPagePoint,Object.assign(this,t)}getBoxPoint(t){return t||(t=this.current),t.getBoxPoint(this)}getInnerPoint(t){return t||(t=this.current),t.getInnerPoint(this)}getLocalPoint(t){return t||(t=this.current),t.getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}static changeName(t,i){e.EventCreator.changeName(t,i)}}exports.PointerEvent=class extends n{},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 o=exports.PointerEvent,h={};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:a,x:r,y:n}=t,o=t.getLocalPoint(i,null,!0);return o.x+=e.x-r,o.y+=e.y-n,a&&this.getMoveInDragBounds(t.__local,"parent"===a?t.parent.boxBounds:a,o,!0),"x"===s&&(o.y=0),"y"===s&&(o.x=0),o}static getMoveInDragBounds(t,i,s,a){const r=t.x+s.x,n=t.y+s.y,o=r+t.width,h=n+t.height,p=i.x+i.width,g=i.y+i.height;return a||(s=Object.assign({},s)),e.BoundsHelper.includes(t,i)?(r>i.x?s.x+=i.x-r:o<p&&(s.x+=p-o),n>i.y?s.y+=i.y-n:h<g&&(s.y+=g-h)):(r<i.x?s.x+=i.x-r:o>p&&(s.x+=p-o),n<i.y?s.y+=i.y-n:h>g&&(s.y+=g-h)),s}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)}getPageBounds(){const t=this.getPageTotal(),i=this.getPagePoint(),s={};return e.BoundsHelper.set(s,i.x-t.x,i.y-t.y,t.x,t.y),e.BoundsHelper.unsign(s),s}assignMove(t){h.x=t?this.totalX:this.moveX,h.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);const p=exports.DragEvent;function g(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,a=t.getValidScale(i.scale);1!==a&&(e.PointHelper.scaleOf(s,i,a),s.scale=s.__.scaleX*a)})))}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 n{},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 n{},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 n{},exports.KeyEvent.DOWN="key.down",exports.KeyEvent.HOLD="key.hold",exports.KeyEvent.UP="key.up",exports.KeyEvent=i([e.registerUIEvent()],exports.KeyEvent);const d=e.Debug.get("LeaferTypeCreator"),l={list:{},register(t,e){c[t]?d.repeat(t):c[t]=e},run(t,e){const i=c[t];i&&i(e)}},{list:c,register:v}=l;v("design",g),v("document",(function(t){g(t);const{move:e,zoom:i}=t.config;e.scroll="limit",i.min=1})),v("block",(function(t){const{config:e}=t;(e.wheel||(e.wheel={})).preventDefault=!1,(e.touch||(e.touch={})).preventDefault="auto"}));const u=t.Leafer.prototype;u.initType=function(t){l.run(t,this)},u.getValidMove=function(t,i){const{scroll:s,disabled:a}=this.app.config.move;if(s&&(Math.abs(t)>Math.abs(i)?i=0:t=0,"limit"===s)){const{x:s,y:a,width:r,height:n}=new e.Bounds(this.__world).addPoint(this.zoomLayer),o=s+r-this.width,h=a+n-this.height;s>=0&&o<=0?t=0:t>0?s+t>0&&(t=-s):t<0&&o+t<0&&(t=-o),a>=0&&h<=0?i=0:i>0?a+i>0&&(i=-a):i<0&&h+i<0&&(i=-h)}return{x:a?0:t,y:a?0:i}},u.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:i,max:s,disabled:a}=this.app.config.zoom,r=Math.abs(e*t);return r<i?t=i/e:r>s&&(t=s/e),a?1:t};class E{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(t){const{interaction:e}=this;if(t.moveType||(t.moveType="move"),!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 m={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:_.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:a}=t;for(let t=0,e=a.length;t<e;t++)a[t].hasEvent(i)&&s.add(a[t]);return s},pathCanDrag:t=>t&&t.list.some((t=>t.draggable||t.editable||!t.isLeafer&&t.hasEvent(exports.DragEvent.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},_=m,x=new e.LeafList,{getDragEventData:f,getDropEventData:D,getSwipeEventData:P}=m;class y{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=f(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,i){const{proxy:s}=this.interaction.selector,a=s&&s.list.length,r=exports.DragEvent.list||this.draggableList||x;return this.dragging&&(a?t?x:new e.LeafList(i?[...s.list,...s.dragHoverExclude]:s.list):r)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(exports.MoveEvent.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&r.left(t),this.dragging&&(this.interaction.emit(exports.DragEvent.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach((t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y}))}getDraggableList(t){let i;for(let s=0,a=t.length;s<a;s++)if(i=t.list[s],(i.draggable||i.editable)&&i.hitSelf&&!i.locked){this.draggableList=new e.LeafList(i);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:r}=s;this.dragData=f(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",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.realDraggableList;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:a}=this.dragData;this.interaction.config.move.dragAnimate&&this.canAnimate&&this.moving&&(Math.abs(s)>1||Math.abs(a)>1)?(t=Object.assign({},t),i=.9*(i||("touch"===t.pointerType?2:1)),e.PointHelper.move(t,s*i,a*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:a,throughPath:r}=i,n=f(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(exports.MoveEvent.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.emit(exports.DragEvent.END,n),this.swipe(t,i,s,n),this.drop(t,a,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,a){const{interaction:r}=this;if(e.PointHelper.getDistance(i,t)>r.config.pointer.swipeDistance){const t=P(i,s,a);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=D(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.draggableList=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:a}=this,{autoDistance:r,dragOut:n}=i.config.move;if(!n||!a||!r)return;const o=i.shrinkCanvasBounds,{x:h,y:p}=o,g=e.BoundsHelper.maxX(o),d=e.BoundsHelper.maxY(o),l=t.x<h?r:g<t.x?-r:0,c=t.y<p?r:d<t.y?-r:0;let v=0,u=0;this.autoMoveTimer=setInterval((()=>{v+=l,u+=c,e.PointHelper.move(s,l,c),e.PointHelper.move(this.dragData,l,c),i.move(Object.assign(Object.assign({},t),{moveX:l,moveY:c,totalX:v,totalY:u,moveType:"drag"})),i.pointerMoveReal(t)}),10)}autoMoveCancel(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)}destroy(){this.dragReset()}}const O=e.Debug.get("emit");const T=["move","zoom","rotate","key"];function w(t,e,i,s,a){if(T.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!L(t,a)){let r;for(let n=0,o=t.children.length;n<o;n++)r=t.children[n],!i.path.has(r)&&r.__.hittable&&R(r,e,i,s,a)}}function R(i,s,a,r,n){if(i.destroyed)return!1;if(i.__.hitSelf&&!L(i,n)&&(t.State.updateEventStyle&&!r&&t.State.updateEventStyle(i,s),i.hasEvent(s,r))){a.phase=r?1:i===a.target?2:3;const t=e.EventCreator.get(s,a);if(i.emitEvent(t,r),t.isStop)return!0}return!1}function L(t,e){return e&&e.has(t)}const C={getData(t){const i=t[0],s=t[1],a=e.PointHelper.getCenter(i.from,s.from),r=e.PointHelper.getCenter(i.to,s.to),n={x:r.x-a.x,y:r.y-a.y},o=e.PointHelper.getDistance(i.from,s.from);return{move:n,scale:e.PointHelper.getDistance(i.to,s.to)/o,angle:e.PointHelper.getRotation(i.from,s.from,i.to,s.to),center:r}}},b={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},touch:{preventDefault:!0},multiTouch:{},cursor:!0,keyEvent:!0},{pathHasEventType:M,getMoveEventData:H,getZoomEventData:S,getRotateEventData:B,pathCanDrag:k,pathHasOutside:A}=m;class I{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}I.custom={};class K 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{toInnerRadiusPointOf:U,copy:W,setRadius:j}=e.PointHelper,z={},N=e.Leaf.prototype;N.__hitWorld=function(t){if(!this.__.hitSelf)return!1;this.__.hitRadius&&(W(z,t),j(t=z,this.__.hitRadius)),U(t,this.__world,z);const{width:i,height:s}=this.__world,a=i<10&&s<10;if(this.__.hitBox||a){if(e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,z))return!0;if(a)return!1}return!this.__layout.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),this.__layout.boundsChanged||(this.__layout.hitCanvasChanged=!1)),this.__hit(z)},N.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},N.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},N.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},N.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const F=new e.Matrix,V=t.UI.prototype;V.__updateHitCanvas=function(){const i=this.__,{hitCanvasManager:s}=this.leafer,a=(i.__pixelFill||i.__isCanvas)&&"pixel"===i.hitFill,r=i.__pixelStroke&&"pixel"===i.hitStroke,n=a||r;this.__hitCanvas||(this.__hitCanvas=n?s.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):s.getPathType(this));const o=this.__hitCanvas;if(n){const{renderBounds:s}=this.__layout,n=e.Platform.image.hitCanvasSize,h=o.hitScale=e.tempBounds.set(0,0,n,n).getFitMatrix(s).a,{x:p,y:g,width:d,height:l}=e.tempBounds.set(s).scale(h);o.resize({width:d,height:l,pixelRatio:1}),o.clear(),t.ImageManager.patternLocked=!0,this.__renderShape(o,{matrix:F.setWith(this.__world).scaleWith(1/h).invertWith().translate(-p,-g)},!a,!r),t.ImageManager.patternLocked=!1,o.resetTransform(),i.__isHitPixel=!0}else i.__isHitPixel&&(i.__isHitPixel=!1);this.__drawHitPath(o),o.setStrokeOptions(i)},V.__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,a=(i.fill||i.__isCanvas)&&("path"===s||"pixel"===s&&!(i.__pixelFill||i.__isCanvas))||"all"===s;if(a&&this.__hitFill(t))return!0;const{hitStroke:r,__strokeWidth:n}=i,o=i.stroke&&("path"===r||"pixel"===r&&!i.__pixelStroke)||"all"===r;if(!a&&!o)return!1;const h=2*t.radiusX;let p=h;if(o)switch(i.strokeAlign){case"inside":if(p+=2*n,!a&&this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h;break;case"center":p+=n;break;case"outside":if(p+=2*n,!a){if(!this.__hitFill(t)&&this.__hitStroke(t,p))return!0;p=h}}return!!p&&this.__hitStroke(t,p)};const X=t.UI.prototype,Z=t.Rect.prototype,Y=t.Box.prototype;Z.__updateHitCanvas=Y.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?X.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Z.__hitFill=Y.__hitFill=function(t){return this.__hitCanvas?X.__hitFill.call(this,t):e.BoundsHelper.hitRadiusPoint(this.__layout.boxBounds,t)};const G=t.UI.prototype,q=t.Group.prototype;G.find=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!1,e):[]},G.findOne=function(t,e){return this.leafer?this.leafer.selector.getBy(t,this,!0,e):null},q.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};const J=e.LeaferCanvasBase.prototype;J.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},J.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},J.hitPixel=function(t,i,s=1){let{x:a,y:r,radiusX:n,radiusY:o}=t;i&&(a-=i.x,r-=i.y),e.tempBounds.set(a-n,r-o,2*n,2*o).scale(s).ceil();const{data:h}=this.context.getImageData(e.tempBounds.x,e.tempBounds.y,e.tempBounds.width||1,e.tempBounds.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0},exports.Cursor=I,exports.HitCanvasManager=K,exports.InteractionBase=class{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.config.move.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.config.pointer.hover&&!this.config.mobile}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.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.config.move.holdMiddleKey&&this.downData&&r.middle(this.downData)}get isHoldRightKey(){return this.config.move.holdRightKey&&this.downData&&r.right(this.downData)}get isHoldSpaceKey(){return this.config.move.holdSpaceKey&&a.isHoldSpaceKey()}get hitRadius(){return this.config.pointer.hitRadius}constructor(t,i,s,a){this.config=e.DataHelper.clone(b),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=i,this.selector=s,this.defaultPath=new e.LeafList(t),this.transformer=new E(this),this.dragger=new y(this),a&&(this.config=e.DataHelper.default(a,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(r.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),r.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=r.right(t),this.dragger.setDragData(t),this.isHoldRightKey||this.updateCursor(t))}pointerMove(t){if(t||(t=this.hoverData),!t)return;const{downData:e}=this;e&&r.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.waitRightTap=!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;r.defaultLeft(t),t.multiTouch=e.multiTouch,this.findPath(t);const i=Object.assign(Object.assign({},t),{path:t.path.clone()});t.path.addList(e.path.list),this.checkPath(t),this.downData=null,this.emit(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){if(this.config.multiTouch.disabled)return;const{move:i,angle:s,scale:a,center:r}=C.getData(e);this.rotate(B(r,s,t)),this.zoom(S(r,a,t)),this.move(H(r,i,t))}menu(t){this.findPath(t),this.emit(exports.PointerEvent.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(exports.PointerEvent.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}move(t){this.transformer.move(t)}zoom(t){this.transformer.zoom(t)}rotate(t){this.transformer.rotate(t)}transformEnd(){this.transformer.transformEnd()}keyDown(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,a.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){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]=!1,a.setUpCode(e),this.emit(exports.KeyEvent.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){this.canHover&&(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,a=[exports.PointerEvent.DOUBLE_TAP,exports.PointerEvent.DOUBLE_CLICK].some((e=>M(t.path,e)));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout((()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}),e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.config.pointer,{bottomList:a}=this,r=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));return r.throughPath&&(t.throughPath=r.throughPath),t.path=r.path,r.path}isRootPath(t){return t&&t.path.list[0].isLeafer}isTreePath(t){const e=this.target.app;return!(!e||!e.isApp)&&(e.editor&&!t.path.has(e.editor)&&t.path.has(e.tree)&&!t.target.syncEventer)}checkPath(t,e){(e||this.moveMode&&!A(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.config.move.drag&&!k(t.path))&&!A(t.path)}isDrag(t){return this.dragger.getList().has(t)}isPress(t){return this.downData&&this.downData.path.has(t)}isHover(t){return this.enterPath&&this.enterPath.has(t)}isFocus(t){return this.focusData===t}cancelHover(){const{hoverData:t}=this;t&&(t.path=this.defaultPath,this.pointerHover(t))}updateDownData(t,e,i){const{downData:s}=this;!t&&s&&(t=s),t&&(this.findPath(t,e),i&&s&&t.path.addList(s.path.list),this.downData=t)}updateHoverData(t){t||(t=this.hoverData),t&&(this.findPath(t,{exclude:this.dragger.getList(!1,!0),name:exports.PointerEvent.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e);return{x:t.clientX-i.x,y:t.clientY-i.y}}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),(M(t.path,exports.PointerEvent.LONG_TAP)||M(t.path,exports.PointerEvent.LONG_PRESS))&&(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 a;e.type=t,i?e=Object.assign(Object.assign({},e),{path:i}):i=e.path,e.target=i.indexAt(0);try{for(let r=i.length-1;r>-1;r--){if(a=i.list[r],R(a,t,e,!0,s))return;a.isApp&&w(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&w(a,t,e,!1,s),R(a,t,e,!1,s))return}catch(t){O.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=m,exports.Keyboard=a,exports.LeaferTypeCreator=l,exports.MultiTouchHelper=C,exports.MyDragEvent=p,exports.MyPointerEvent=o,exports.PointerButton=r,exports.UIEvent=n,exports.addInteractionWindow=g,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.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "@leafer-ui/core",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,21 +19,21 @@
|
|
|
19
19
|
],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/leaferjs/ui.git"
|
|
22
|
+
"url": "https://github.com/leaferjs/leafer-ui.git"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/core/core",
|
|
25
|
-
"bugs": "https://github.com/leaferjs/ui/issues",
|
|
24
|
+
"homepage": "https://github.com/leaferjs/leafer-ui/tree/main/packages/core/core",
|
|
25
|
+
"bugs": "https://github.com/leaferjs/leafer-ui/issues",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"leafer core",
|
|
28
28
|
"leafer-ui",
|
|
29
29
|
"leaferjs"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@leafer-ui/draw": "1.0.
|
|
33
|
-
"@leafer-ui/app": "1.0.
|
|
34
|
-
"@leafer-ui/type": "1.0.
|
|
35
|
-
"@leafer-ui/interaction": "1.0.
|
|
36
|
-
"@leafer-ui/event": "1.0.
|
|
37
|
-
"@leafer-ui/hit": "1.0.
|
|
32
|
+
"@leafer-ui/draw": "1.0.5",
|
|
33
|
+
"@leafer-ui/app": "1.0.5",
|
|
34
|
+
"@leafer-ui/type": "1.0.5",
|
|
35
|
+
"@leafer-ui/interaction": "1.0.5",
|
|
36
|
+
"@leafer-ui/event": "1.0.5",
|
|
37
|
+
"@leafer-ui/hit": "1.0.5"
|
|
38
38
|
}
|
|
39
39
|
}
|