@leafer-ui/core 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core.cjs +10 -8
- package/lib/core.esm.js +10 -8
- package/lib/core.esm.min.js +1 -1
- package/lib/core.esm.min.js.map +1 -1
- package/lib/core.min.cjs +1 -1
- package/lib/core.min.cjs.map +1 -1
- package/package.json +6 -6
- package/lib/core.cjs.map +0 -1
- package/lib/core.esm.js.map +0 -1
package/lib/core.cjs
CHANGED
|
@@ -789,8 +789,7 @@ class InteractionBase {
|
|
|
789
789
|
if (this.downData) {
|
|
790
790
|
const canDrag = core.PointHelper.getDistance(this.downData, data) > this.p.dragDistance;
|
|
791
791
|
if (canDrag) {
|
|
792
|
-
|
|
793
|
-
this.pointerWaitCancel();
|
|
792
|
+
this.pointerWaitCancel();
|
|
794
793
|
this.waitRightTap = false;
|
|
795
794
|
}
|
|
796
795
|
this.dragger.checkDrag(data, canDrag);
|
|
@@ -1072,9 +1071,11 @@ class InteractionBase {
|
|
|
1072
1071
|
this.waitTap = true;
|
|
1073
1072
|
}
|
|
1074
1073
|
tapWaitCancel() {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1074
|
+
if (this.waitTap) {
|
|
1075
|
+
clearTimeout(this.tapTimer);
|
|
1076
|
+
this.waitTap = false;
|
|
1077
|
+
this.tapCount = 0;
|
|
1078
|
+
}
|
|
1078
1079
|
}
|
|
1079
1080
|
longPressWait(data) {
|
|
1080
1081
|
clearTimeout(this.longPressTimer);
|
|
@@ -1094,8 +1095,10 @@ class InteractionBase {
|
|
|
1094
1095
|
return hasLong;
|
|
1095
1096
|
}
|
|
1096
1097
|
longPressWaitCancel() {
|
|
1097
|
-
|
|
1098
|
-
|
|
1098
|
+
if (this.longPressTimer) {
|
|
1099
|
+
clearTimeout(this.longPressTimer);
|
|
1100
|
+
this.longPressed = false;
|
|
1101
|
+
}
|
|
1099
1102
|
}
|
|
1100
1103
|
__onResize() {
|
|
1101
1104
|
const { dragOut } = this.m;
|
|
@@ -1351,4 +1354,3 @@ Object.keys(draw).forEach(function (k) {
|
|
|
1351
1354
|
get: function () { return draw[k]; }
|
|
1352
1355
|
});
|
|
1353
1356
|
});
|
|
1354
|
-
//# sourceMappingURL=core.cjs.map
|
package/lib/core.esm.js
CHANGED
|
@@ -788,8 +788,7 @@ class InteractionBase {
|
|
|
788
788
|
if (this.downData) {
|
|
789
789
|
const canDrag = PointHelper.getDistance(this.downData, data) > this.p.dragDistance;
|
|
790
790
|
if (canDrag) {
|
|
791
|
-
|
|
792
|
-
this.pointerWaitCancel();
|
|
791
|
+
this.pointerWaitCancel();
|
|
793
792
|
this.waitRightTap = false;
|
|
794
793
|
}
|
|
795
794
|
this.dragger.checkDrag(data, canDrag);
|
|
@@ -1071,9 +1070,11 @@ class InteractionBase {
|
|
|
1071
1070
|
this.waitTap = true;
|
|
1072
1071
|
}
|
|
1073
1072
|
tapWaitCancel() {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1073
|
+
if (this.waitTap) {
|
|
1074
|
+
clearTimeout(this.tapTimer);
|
|
1075
|
+
this.waitTap = false;
|
|
1076
|
+
this.tapCount = 0;
|
|
1077
|
+
}
|
|
1077
1078
|
}
|
|
1078
1079
|
longPressWait(data) {
|
|
1079
1080
|
clearTimeout(this.longPressTimer);
|
|
@@ -1093,8 +1094,10 @@ class InteractionBase {
|
|
|
1093
1094
|
return hasLong;
|
|
1094
1095
|
}
|
|
1095
1096
|
longPressWaitCancel() {
|
|
1096
|
-
|
|
1097
|
-
|
|
1097
|
+
if (this.longPressTimer) {
|
|
1098
|
+
clearTimeout(this.longPressTimer);
|
|
1099
|
+
this.longPressed = false;
|
|
1100
|
+
}
|
|
1098
1101
|
}
|
|
1099
1102
|
__onResize() {
|
|
1100
1103
|
const { dragOut } = this.m;
|
|
@@ -1335,4 +1338,3 @@ canvas.hitPixel = function (radiusPoint, offset, scale = 1) {
|
|
|
1335
1338
|
};
|
|
1336
1339
|
|
|
1337
1340
|
export { App, Cursor, DragEvent, Dragger, DropEvent, HitCanvasManager, InteractionBase, InteractionHelper, KeyEvent, Keyboard, MoveEvent, MyDragEvent, MyPointerEvent, PointerButton, PointerEvent, RotateEvent, SwipeEvent, UIEvent, ZoomEvent };
|
|
1338
|
-
//# sourceMappingURL=core.esm.js.map
|
package/lib/core.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Leafer as t,State as e,UI as i,Rect as s,Box as a,Text as r,Group as n,Platform as h,Creator as o,emptyData as d}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as g,Creator as l,DataHelper as c,canvasSizeAttrs as u,LayoutEvent as p,RenderEvent as _,Event as v,EventCreator as m,registerUIEvent as f,LeafList as y,PointHelper as E,BoundsHelper as D,Debug as P,Platform as w,Bounds as T,ResizeEvent as O,LeaferEvent as x,CanvasManager as R,Leaf as C,Matrix as L,tempBounds as b,ImageManager as S,LeaferCanvasBase as M}from"@leafer/core";function k(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 h=t.length-1;h>=0;h--)(a=t[h])&&(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;let H=class extends t{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,e){if(super.init(t,e),t){const{ground:e,tree:i,sky:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&this.sky.add(this.editor=l.editor(a))}}__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()}start(){super.start(),this.forEach((t=>t.start()))}stop(){this.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.forEach((t=>t.lockLayout()))}forceRender(t,e){this.forEach((i=>i.forceRender(t,e)))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),void 0!==e&&(t.canvas.childIndex=e),this.__listenChildEvents(t)}forEach(t){this.children.forEach(t)}__onCreated(){this.created=this.children.every((t=>t.created))}__onReady(){this.children.every((t=>t.ready))&&super.__onReady()}__onViewReady(){this.children.every((t=>t.viewReady))&&super.__onViewReady()}__onChildRenderEnd(t){this.renderer.addBlock(t.renderBounds),this.viewReady&&this.renderer.update()}__render(t,e){if(t.context){const i=e.matrix;i&&t.setTransform(i.a,i.b,i.c,i.d,i.e,i.f),this.forEach((e=>t.copyWorld(e.canvas)))}}__onResize(t){this.forEach((e=>e.resize(t))),super.__onResize(t)}updateLayout(){this.forEach((t=>t.updateLayout()))}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&c.assign(e,t),this.autoLayout&&c.copyAttrs(e,this,u),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once(p.END,(()=>this.__onReady())),t.once(_.START,(()=>this.__onCreated())),t.once(_.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(_.END,this.__onChildRenderEnd,this))}};H=k([g()],H);const A={},B={isHoldSpaceKey:()=>B.isHold("Space"),isHold:t=>A[t],setDownCode(t){A[t]||(A[t]=!0)},setUpCode(t){A[t]=!1}},I={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 v{get spaceKey(){return B.isHoldSpaceKey()}get left(){return I.left(this)}get right(){return I.right(this)}get middle(){return I.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}getBoxPoint(t){return(t||this.current).getBoxPoint(this)}getInnerPoint(t){return(t||this.current).getInnerPoint(this)}getLocalPoint(t){return(t||this.current).getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}getInner(t){return this.getInnerPoint(t)}getLocal(t){return this.getLocalPoint(t)}getPage(){return this.getPagePoint()}static changeName(t,e){m.changeName(t,e)}}let F=class extends N{};F.POINTER="pointer",F.BEFORE_DOWN="pointer.before_down",F.BEFORE_MOVE="pointer.before_move",F.BEFORE_UP="pointer.before_up",F.DOWN="pointer.down",F.MOVE="pointer.move",F.UP="pointer.up",F.OVER="pointer.over",F.OUT="pointer.out",F.ENTER="pointer.enter",F.LEAVE="pointer.leave",F.TAP="tap",F.DOUBLE_TAP="double_tap",F.CLICK="click",F.DOUBLE_CLICK="double_click",F.LONG_PRESS="long_press",F.LONG_TAP="long_tap",F.MENU="pointer.menu",F.MENU_TAP="pointer.menu_tap",F=k([f()],F);const K=F,W={};let V=class extends F{static setList(t){this.list=t instanceof y?t:new y(t)}static setData(t){this.data=t}static getValidMove(t,e,i){const{draggable:s,dragBounds:a}=t,r=t.getLocalPoint(i,null,!0);return E.move(r,e.x-t.x,e.y-t.y),a&&this.getMoveInDragBounds(t.__localBoxBounds,"parent"===a?t.parent.boxBounds:a,r,!0),"x"===s&&(r.y=0),"y"===s&&(r.x=0),r}static getMoveInDragBounds(t,e,i,s){const a=t.x+i.x,r=t.y+i.y,n=a+t.width,h=r+t.height,o=e.x+e.width,d=e.y+e.height;return s||(i=Object.assign({},i)),D.includes(t,e)?(a>e.x?i.x+=e.x-a:n<o&&(i.x+=o-n),r>e.y?i.y+=e.y-r:h<d&&(i.y+=d-h)):(a<e.x?i.x+=e.x-a:n>o&&(i.x+=o-n),r<e.y?i.y+=e.y-r:h>d&&(i.y+=d-h)),i}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(W,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(W,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(W,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){W.x=t?this.totalX:this.moveX,W.y=t?this.totalY:this.moveY}};V.BEFORE_DRAG="drag.before_drag",V.START="drag.start",V.DRAG="drag",V.END="drag.end",V.OVER="drag.over",V.OUT="drag.out",V.ENTER="drag.enter",V.LEAVE="drag.leave",V=k([f()],V);const U=V;let j=class extends F{static setList(t){V.setList(t)}static setData(t){V.setData(t)}};j.DROP="drop",j=k([f()],j);let z=class extends V{};z.BEFORE_MOVE="move.before_move",z.START="move.start",z.MOVE="move",z.END="move.end",z=k([f()],z);let G=class extends N{};G.BEFORE_ROTATE="rotate.before_rotate",G.START="rotate.start",G.ROTATE="rotate",G.END="rotate.end",G=k([f()],G);let X=class extends V{};X.SWIPE="swipe",X.LEFT="swipe.left",X.RIGHT="swipe.right",X.UP="swipe.up",X.DOWN="swipe.down",X=k([f()],X);let Y=class extends N{};Y.BEFORE_ZOOM="zoom.before_zoom",Y.START="zoom.start",Y.ZOOM="zoom",Y.END="zoom.end",Y=k([f()],Y);let Z=class extends N{};Z.DOWN="key.down",Z.HOLD="key.hold",Z.UP="key.up",Z=k([f()],Z);const q={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?X.UP:t>45&&t<135?X.DOWN:t<=45&&t>=-45?X.RIGHT:X.LEFT,getSwipeEventData:(t,e,i)=>Object.assign(Object.assign({},i),{moveX:e.moveX,moveY:e.moveY,totalX:i.x-t.x,totalY:i.y-t.y,type:J.getSwipeDirection(E.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,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new y,{list:s}=t;for(let t=0,a=s.length;t<a;t++)s[t].hasEvent(e)&&i.add(s[t]);return i},pathCanDrag:t=>t&&t.list.some((t=>t.draggable||t.editable||!t.isLeafer&&t.hasEvent(V.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},J=q,Q=new y,{getDragEventData:$,getDropEventData:tt,getSwipeEventData:et}=q;class it{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=$(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=V.list||this.draggableList||Q;return this.dragging&&(s?t?Q:new y(e?[...i.list,...i.dragHoverExclude]:i.list):a)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(z.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&I.left(t),this.dragging&&(this.interaction.emit(V.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach((t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y}))}getDraggableList(t){let e;for(let i=0,s=t.length;i<s;i++)if(e=t.list[i],(e.draggable||e.editable)&&e.hitSelf&&!e.locked){this.draggableList=new y(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:r}=s;this.dragData=$(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(z.BEFORE_MOVE,this.dragData),e.emit(z.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(V.BEFORE_DRAG,this.dragData),e.emit(V.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(V.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(V.OUT,t,i),e.emit(V.OVER,t,s)):e.emit(V.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(V.LEAVE,t,i,s),e.emit(V.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,e){(this.dragging||this.moving)&&(this.checkDragEndAnimate(t,e)||this.dragEndReal(t))}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:a,throughPath:r}=i,n=$(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(z.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.emit(V.END,n),this.swipe(t,i,s,n),this.drop(t,a,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}swipe(t,e,i,s){const{interaction:a}=this;if(E.getDistance(e,t)>a.config.pointer.swipeDistance){const t=et(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=tt(t,e,V.data);s.path=i,this.interaction.emit(j.DROP,s),this.interaction.emit(V.LEAVE,t,i)}dragReset(){V.list=V.data=this.draggableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragEndAnimate(t,e){return!1}animate(t,e){}checkDragOut(t){}autoMoveOnDragOut(t){}autoMoveCancel(){}destroy(){this.dragReset()}}const st=P.get("emit");const at=["move","zoom","rotate","key"];function rt(t,e,i,s,a){if(at.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!ht(t,a)){let r;for(let n=0,h=t.children.length;n<h;n++)r=t.children[n],!i.path.has(r)&&r.__.hittable&&nt(r,e,i,s,a)}}function nt(t,i,s,a,r){if(t.destroyed)return!1;if(t.__.hitSelf&&!ht(t,r)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=m.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function ht(t,e){return e&&e.has(t)}const ot={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:dt,pathCanDrag:gt,pathHasOutside:lt}=q;class ct{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.m.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.p.hover&&!this.config.mobile}get isDragEmpty(){return this.m.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.m.dragEmpty&&!this.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.m.holdMiddleKey&&this.downData&&I.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&I.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&B.isHoldSpaceKey()}get m(){return this.config.move}get p(){return this.config.pointer}get hitRadius(){return this.p.hitRadius}constructor(t,e,i,s){this.config=c.clone(ot),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new y(t),this.createTransformer(),this.dragger=new it(this),s&&(this.config=c.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(I.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(F.BEFORE_DOWN,t),this.emit(F.DOWN,t),I.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=I.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&&I.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(F.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=E.getDistance(this.downData,t)>this.p.dragDistance;e&&((this.waitTap||this.longPressTimer)&&this.pointerWaitCancel(),this.waitRightTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(F.MOVE,t),this.pointerHover(t),this.dragging&&(this.dragger.dragOverOrOut(t),this.dragger.dragEnterOrLeave(t))),this.updateCursor(this.downData||t)}pointerUp(t){const{downData:e}=this;if(t||(t=e),!e)return;I.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(F.BEFORE_UP,t),this.emit(F.UP,t),this.touchLeave(t),t.isCancel||(this.tap(t),this.menuTap(t)),this.dragger.dragEnd(t),this.updateCursor(i)}pointerCancel(){const t=Object.assign({},this.dragger.dragData);t.isCancel=!0,this.pointerUp(t)}menu(t){this.findPath(t),this.emit(F.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(F.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}createTransformer(){}move(t){}zoom(t){}rotate(t){}transformEnd(){}wheel(t){}multiTouch(t,e){}keyDown(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,B.setDownCode(e),this.emit(Z.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(Z.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]=!1,B.setUpCode(e),this.emit(Z.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new y),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(F.OUT,t,i),this.emit(F.OVER,t,e)):this.emit(F.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(F.LEAVE,t,i,e),this.emit(F.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(F.LEAVE,t),this.dragger.dragging&&this.emit(j.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=[F.DOUBLE_TAP,F.DOUBLE_CLICK].some((e=>dt(t.path,e)));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout((()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}),e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.p,{bottomList:a,target:r}=this;w.backgrounder||t.origin||r&&r.updateLayout();const n=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));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&&!lt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!gt(t.path))&&!lt(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:F.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e),s={x:t.clientX-i.x,y:t.clientY-i.y};return this.p.snap&&E.round(s),s}emitTap(t){this.emit(F.TAP,t),this.emit(F.CLICK,t)}emitDoubleTap(t){this.emit(F.DOUBLE_TAP,t),this.emit(F.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(F.LONG_PRESS,t)}),this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(F.LONG_TAP,t),(dt(t.path,F.LONG_TAP)||dt(t.path,F.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){clearTimeout(this.longPressTimer),this.longPressed=!1}__onResize(){const{dragOut:t}=this.m;this.shrinkCanvasBounds=new T(this.canvas.bounds),this.shrinkCanvasBounds.spread(-("number"==typeof t?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(O.RESIZE,this.__onResize,this)],t.once(x.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],nt(a,t,e,!0,s))return;a.isApp&&rt(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&rt(a,t,e,!1,s),nt(a,t,e,!1,s))return}catch(t){st.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer&&this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class ut{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}ut.custom={};class pt extends R{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new y,this.pixelList=new y}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),l.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),l.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:_t,copy:vt,setRadius:mt}=E,ft={},yt=C.prototype;yt.__hitWorld=function(t){const e=this.__;if(!e.hitSelf)return!1;const i=this.__world,s=this.__layout,a=i.width<10&&i.height<10;if(e.hitRadius&&(vt(ft,t),mt(t=ft,e.hitRadius)),_t(t,i,ft),e.hitBox||a){if(D.hitRadiusPoint(s.boxBounds,ft))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(ft)},yt.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},yt.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},yt.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},yt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Et=new L,Dt=i.prototype;Dt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const t=this.__,{hitCanvasManager:e}=this.leafer||this.parent.leafer,i=(t.__pixelFill||t.__isCanvas)&&"pixel"===t.hitFill,s=t.__pixelStroke&&"pixel"===t.hitStroke,a=i||s;this.__hitCanvas||(this.__hitCanvas=a?e.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):e.getPathType(this));const r=this.__hitCanvas;if(a){const{renderBounds:e}=this.__layout,a=w.image.hitCanvasSize,n=r.hitScale=b.set(0,0,a,a).getFitMatrix(e).a,{x:h,y:o,width:d,height:g}=b.set(e).scale(n);r.resize({width:d,height:g,pixelRatio:1}),r.clear(),S.patternLocked=!0,this.__renderShape(r,{matrix:Et.setWith(this.__world).scaleWith(1/n).invertWith().translate(-h,-o)},!i,!s),S.patternLocked=!1,r.resetTransform(),t.__isHitPixel=!0}else t.__isHitPixel&&(t.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(t)},Dt.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__pixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__strokeWidth:r}=e,n=e.stroke&&("path"===a||"pixel"===a&&!e.__pixelStroke)||"all"===a;if(!s&&!n)return!1;const h=2*t.radiusX;let o=h;if(n)switch(e.strokeAlign){case"inside":if(o+=2*r,!s&&this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h;break;case"center":o+=r;break;case"outside":if(o+=2*r,!s){if(!this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h}}return!!o&&this.__hitStroke(t,o)};const Pt=i.prototype,wt=s.prototype,Tt=a.prototype;wt.__updateHitCanvas=Tt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Pt.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},wt.__hitFill=Tt.__hitFill=function(t){return this.__hitCanvas?Pt.__hitFill.call(this,t):D.hitRadiusPoint(this.__layout.boxBounds,t)},r.prototype.__drawHitPath=function(t){const{__lineHeight:e,fontSize:i,__baseLine:s,__letterSpacing:a,__textDrawData:r}=this.__;t.beginPath(),a<0?this.__drawPathByBox(t):r.rows.forEach((a=>t.rect(a.x,a.y-s,a.width,e<i?i:e)))},n.prototype.pick=function(t,e){return e||(e=d),this.updateLayout(),function(t){return t.leafer?t.leafer.selector:h.selector||(h.selector=o.selector())}(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const Ot=M.prototype;Ot.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},Ot.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},Ot.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:r,radiusY:n}=t;e&&(s-=e.x,a-=e.y),b.set(s-r,a-n,2*r,2*n).scale(i).ceil();const{data:h}=this.context.getImageData(b.x,b.y,b.width||1,b.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};export{H as App,ut as Cursor,V as DragEvent,it as Dragger,j as DropEvent,pt as HitCanvasManager,ct as InteractionBase,q as InteractionHelper,Z as KeyEvent,B as Keyboard,z as MoveEvent,U as MyDragEvent,K as MyPointerEvent,I as PointerButton,F as PointerEvent,G as RotateEvent,X as SwipeEvent,N as UIEvent,Y as ZoomEvent};
|
|
1
|
+
import{Leafer as t,State as e,UI as i,Rect as s,Box as a,Text as r,Group as n,Platform as h,Creator as o,emptyData as d}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as g,Creator as l,DataHelper as c,canvasSizeAttrs as u,LayoutEvent as p,RenderEvent as _,Event as v,EventCreator as m,registerUIEvent as f,LeafList as y,PointHelper as E,BoundsHelper as D,Debug as P,Platform as w,Bounds as T,ResizeEvent as O,LeaferEvent as x,CanvasManager as R,Leaf as C,Matrix as L,tempBounds as b,ImageManager as S,LeaferCanvasBase as M}from"@leafer/core";function k(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 h=t.length-1;h>=0;h--)(a=t[h])&&(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;let H=class extends t{get __tag(){return"App"}get isApp(){return!0}constructor(t,e){super(t,e)}init(t,e){if(super.init(t,e),t){const{ground:e,tree:i,sky:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&this.sky.add(this.editor=l.editor(a))}}__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()}start(){super.start(),this.forEach((t=>t.start()))}stop(){this.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.forEach((t=>t.lockLayout()))}forceRender(t,e){this.forEach((i=>i.forceRender(t,e)))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),void 0!==e&&(t.canvas.childIndex=e),this.__listenChildEvents(t)}forEach(t){this.children.forEach(t)}__onCreated(){this.created=this.children.every((t=>t.created))}__onReady(){this.children.every((t=>t.ready))&&super.__onReady()}__onViewReady(){this.children.every((t=>t.viewReady))&&super.__onViewReady()}__onChildRenderEnd(t){this.renderer.addBlock(t.renderBounds),this.viewReady&&this.renderer.update()}__render(t,e){if(t.context){const i=e.matrix;i&&t.setTransform(i.a,i.b,i.c,i.d,i.e,i.f),this.forEach((e=>t.copyWorld(e.canvas)))}}__onResize(t){this.forEach((e=>e.resize(t))),super.__onResize(t)}updateLayout(){this.forEach((t=>t.updateLayout()))}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&c.assign(e,t),this.autoLayout&&c.copyAttrs(e,this,u),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once(p.END,(()=>this.__onReady())),t.once(_.START,(()=>this.__onCreated())),t.once(_.END,(()=>this.__onViewReady())),this.realCanvas&&this.__eventIds.push(t.on_(_.END,this.__onChildRenderEnd,this))}};H=k([g()],H);const A={},B={isHoldSpaceKey:()=>B.isHold("Space"),isHold:t=>A[t],setDownCode(t){A[t]||(A[t]=!0)},setUpCode(t){A[t]=!1}},I={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 v{get spaceKey(){return B.isHoldSpaceKey()}get left(){return I.left(this)}get right(){return I.right(this)}get middle(){return I.middle(this)}constructor(t){super(t.type),this.bubbles=!0,Object.assign(this,t)}getBoxPoint(t){return(t||this.current).getBoxPoint(this)}getInnerPoint(t){return(t||this.current).getInnerPoint(this)}getLocalPoint(t){return(t||this.current).getLocalPoint(this)}getPagePoint(){return this.current.getPagePoint(this)}getInner(t){return this.getInnerPoint(t)}getLocal(t){return this.getLocalPoint(t)}getPage(){return this.getPagePoint()}static changeName(t,e){m.changeName(t,e)}}let F=class extends N{};F.POINTER="pointer",F.BEFORE_DOWN="pointer.before_down",F.BEFORE_MOVE="pointer.before_move",F.BEFORE_UP="pointer.before_up",F.DOWN="pointer.down",F.MOVE="pointer.move",F.UP="pointer.up",F.OVER="pointer.over",F.OUT="pointer.out",F.ENTER="pointer.enter",F.LEAVE="pointer.leave",F.TAP="tap",F.DOUBLE_TAP="double_tap",F.CLICK="click",F.DOUBLE_CLICK="double_click",F.LONG_PRESS="long_press",F.LONG_TAP="long_tap",F.MENU="pointer.menu",F.MENU_TAP="pointer.menu_tap",F=k([f()],F);const K=F,W={};let V=class extends F{static setList(t){this.list=t instanceof y?t:new y(t)}static setData(t){this.data=t}static getValidMove(t,e,i){const{draggable:s,dragBounds:a}=t,r=t.getLocalPoint(i,null,!0);return E.move(r,e.x-t.x,e.y-t.y),a&&this.getMoveInDragBounds(t.__localBoxBounds,"parent"===a?t.parent.boxBounds:a,r,!0),"x"===s&&(r.y=0),"y"===s&&(r.x=0),r}static getMoveInDragBounds(t,e,i,s){const a=t.x+i.x,r=t.y+i.y,n=a+t.width,h=r+t.height,o=e.x+e.width,d=e.y+e.height;return s||(i=Object.assign({},i)),D.includes(t,e)?(a>e.x?i.x+=e.x-a:n<o&&(i.x+=o-n),r>e.y?i.y+=e.y-r:h<d&&(i.y+=d-h)):(a<e.x?i.x+=e.x-a:n>o&&(i.x+=o-n),r<e.y?i.y+=e.y-r:h>d&&(i.y+=d-h)),i}getPageMove(t){return this.assignMove(t),this.current.getPagePoint(W,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(W,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(W,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){W.x=t?this.totalX:this.moveX,W.y=t?this.totalY:this.moveY}};V.BEFORE_DRAG="drag.before_drag",V.START="drag.start",V.DRAG="drag",V.END="drag.end",V.OVER="drag.over",V.OUT="drag.out",V.ENTER="drag.enter",V.LEAVE="drag.leave",V=k([f()],V);const U=V;let j=class extends F{static setList(t){V.setList(t)}static setData(t){V.setData(t)}};j.DROP="drop",j=k([f()],j);let z=class extends V{};z.BEFORE_MOVE="move.before_move",z.START="move.start",z.MOVE="move",z.END="move.end",z=k([f()],z);let G=class extends N{};G.BEFORE_ROTATE="rotate.before_rotate",G.START="rotate.start",G.ROTATE="rotate",G.END="rotate.end",G=k([f()],G);let X=class extends V{};X.SWIPE="swipe",X.LEFT="swipe.left",X.RIGHT="swipe.right",X.UP="swipe.up",X.DOWN="swipe.down",X=k([f()],X);let Y=class extends N{};Y.BEFORE_ZOOM="zoom.before_zoom",Y.START="zoom.start",Y.ZOOM="zoom",Y.END="zoom.end",Y=k([f()],Y);let Z=class extends N{};Z.DOWN="key.down",Z.HOLD="key.hold",Z.UP="key.up",Z=k([f()],Z);const q={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?X.UP:t>45&&t<135?X.DOWN:t<=45&&t>=-45?X.RIGHT:X.LEFT,getSwipeEventData:(t,e,i)=>Object.assign(Object.assign({},i),{moveX:e.moveX,moveY:e.moveY,totalX:i.x-t.x,totalY:i.y-t.y,type:J.getSwipeDirection(E.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,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new y,{list:s}=t;for(let t=0,a=s.length;t<a;t++)s[t].hasEvent(e)&&i.add(s[t]);return i},pathCanDrag:t=>t&&t.list.some((t=>t.draggable||t.editable||!t.isLeafer&&t.hasEvent(V.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},J=q,Q=new y,{getDragEventData:$,getDropEventData:tt,getSwipeEventData:et}=q;class it{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=$(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=V.list||this.draggableList||Q;return this.dragging&&(s?t?Q:new y(e?[...i.list,...i.dragHoverExclude]:i.list):a)}checkDrag(t,e){const{interaction:i}=this;if(this.moving&&t.buttons<1)return this.canAnimate=!1,void i.pointerCancel();!this.moving&&e&&(this.moving=i.canMove(this.downData)||i.isHoldRightKey||i.isMobileDragEmpty)&&(this.dragData.moveType="drag",i.emit(z.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&I.left(t),this.dragging&&(this.interaction.emit(V.START,this.dragData),this.getDraggableList(this.dragData.path),this.setDragStartPoints(this.realDraggableList=this.getList(!0))))}setDragStartPoints(t){this.dragStartPoints={},t.forEach((t=>this.dragStartPoints[t.innerId]={x:t.x,y:t.y}))}getDraggableList(t){let e;for(let i=0,s=t.length;i<s;i++)if(e=t.list[i],(e.draggable||e.editable)&&e.hitSelf&&!e.locked){this.draggableList=new y(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:r}=s;this.dragData=$(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(z.BEFORE_MOVE,this.dragData),e.emit(z.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(V.BEFORE_DRAG,this.dragData),e.emit(V.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(V.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(V.OUT,t,i),e.emit(V.OVER,t,s)):e.emit(V.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(V.LEAVE,t,i,s),e.emit(V.ENTER,t,s,i),this.dragEnterPath=s}dragEnd(t,e){(this.dragging||this.moving)&&(this.checkDragEndAnimate(t,e)||this.dragEndReal(t))}dragEndReal(t){const{interaction:e,downData:i,dragData:s}=this;t||(t=s);const{path:a,throughPath:r}=i,n=$(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(z.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.emit(V.END,n),this.swipe(t,i,s,n),this.drop(t,a,this.dragEnterPath)}this.autoMoveCancel(),this.dragReset(),this.animate(null,"off")}swipe(t,e,i,s){const{interaction:a}=this;if(E.getDistance(e,t)>a.config.pointer.swipeDistance){const t=et(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=tt(t,e,V.data);s.path=i,this.interaction.emit(j.DROP,s),this.interaction.emit(V.LEAVE,t,i)}dragReset(){V.list=V.data=this.draggableList=this.dragData=this.downData=this.dragOverPath=this.dragEnterPath=null}checkDragEndAnimate(t,e){return!1}animate(t,e){}checkDragOut(t){}autoMoveOnDragOut(t){}autoMoveCancel(){}destroy(){this.dragReset()}}const st=P.get("emit");const at=["move","zoom","rotate","key"];function rt(t,e,i,s,a){if(at.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!ht(t,a)){let r;for(let n=0,h=t.children.length;n<h;n++)r=t.children[n],!i.path.has(r)&&r.__.hittable&&nt(r,e,i,s,a)}}function nt(t,i,s,a,r){if(t.destroyed)return!1;if(t.__.hitSelf&&!ht(t,r)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=m.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function ht(t,e){return e&&e.has(t)}const ot={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:dt,pathCanDrag:gt,pathHasOutside:lt}=q;class ct{get dragging(){return this.dragger.dragging}get transforming(){return this.transformer.transforming}get moveMode(){return!0===this.m.drag||this.isHoldSpaceKey||this.isHoldMiddleKey||this.isHoldRightKey&&this.dragger.moving||this.isDragEmpty}get canHover(){return this.p.hover&&!this.config.mobile}get isDragEmpty(){return this.m.dragEmpty&&this.isRootPath(this.hoverData)&&(!this.downData||this.isRootPath(this.downData))}get isMobileDragEmpty(){return this.m.dragEmpty&&!this.canHover&&this.downData&&this.isTreePath(this.downData)}get isHoldMiddleKey(){return this.m.holdMiddleKey&&this.downData&&I.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&I.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&B.isHoldSpaceKey()}get m(){return this.config.move}get p(){return this.config.pointer}get hitRadius(){return this.p.hitRadius}constructor(t,e,i,s){this.config=c.clone(ot),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new y(t),this.createTransformer(),this.dragger=new it(this),s&&(this.config=c.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(I.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(F.BEFORE_DOWN,t),this.emit(F.DOWN,t),I.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=I.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&&I.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(F.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=E.getDistance(this.downData,t)>this.p.dragDistance;e&&(this.pointerWaitCancel(),this.waitRightTap=!1),this.dragger.checkDrag(t,e)}this.dragger.moving||(this.updateHoverData(t),this.checkPath(t),this.emit(F.MOVE,t),this.pointerHover(t),this.dragging&&(this.dragger.dragOverOrOut(t),this.dragger.dragEnterOrLeave(t))),this.updateCursor(this.downData||t)}pointerUp(t){const{downData:e}=this;if(t||(t=e),!e)return;I.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(F.BEFORE_UP,t),this.emit(F.UP,t),this.touchLeave(t),t.isCancel||(this.tap(t),this.menuTap(t)),this.dragger.dragEnd(t),this.updateCursor(i)}pointerCancel(){const t=Object.assign({},this.dragger.dragData);t.isCancel=!0,this.pointerUp(t)}menu(t){this.findPath(t),this.emit(F.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(F.MENU_TAP,t),this.waitRightTap=this.waitMenuTap=!1)}createTransformer(){}move(t){}zoom(t){}rotate(t){}transformEnd(){}wheel(t){}multiTouch(t,e){}keyDown(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]||(this.downKeyMap[e]=!0,B.setDownCode(e),this.emit(Z.HOLD,t,this.defaultPath),this.moveMode&&(this.cancelHover(),this.updateCursor())),this.emit(Z.DOWN,t,this.defaultPath)}keyUp(t){if(!this.config.keyEvent)return;const{code:e}=t;this.downKeyMap[e]=!1,B.setUpCode(e),this.emit(Z.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new y),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(F.OUT,t,i),this.emit(F.OVER,t,e)):this.emit(F.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(F.LEAVE,t,i,e),this.emit(F.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(F.LEAVE,t),this.dragger.dragging&&this.emit(j.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=[F.DOUBLE_TAP,F.DOUBLE_CLICK].some((e=>dt(t.path,e)));s<e.tapTime+50&&a?(this.tapCount++,2===this.tapCount?(this.tapWaitCancel(),this.emitDoubleTap(t)):(clearTimeout(this.tapTimer),this.tapTimer=setTimeout((()=>{e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}),e.tapTime))):e.tapMore||(this.tapWaitCancel(),this.emitTap(t))}findPath(t,e){const{hitRadius:i,through:s}=this.p,{bottomList:a,target:r}=this;w.backgrounder||t.origin||r&&r.updateLayout();const n=this.selector.getByPoint(t,i,Object.assign({bottomList:a,name:t.type},e||{through:s}));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&&!lt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!gt(t.path))&&!lt(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:F.MOVE}),this.hoverData=t)}updateCursor(t){if(!this.config.cursor||!this.canHover)return;if(t||(this.updateHoverData(),t=this.downData||this.hoverData),this.dragger.moving)return this.setCursor("grabbing");if(this.canMove(t))return this.setCursor(this.downData?"grabbing":"grab");if(!t)return;let e,i;const{path:s}=t;for(let t=0,a=s.length;t<a&&(e=s.list[t],i=e.syncEventer&&e.syncEventer.cursor||e.cursor,!i);t++);this.setCursor(i)}setCursor(t){this.cursor=t}getLocal(t,e){const i=this.canvas.getClientBounds(e),s={x:t.clientX-i.x,y:t.clientY-i.y};return this.p.snap&&E.round(s),s}emitTap(t){this.emit(F.TAP,t),this.emit(F.CLICK,t)}emitDoubleTap(t){this.emit(F.DOUBLE_TAP,t),this.emit(F.DOUBLE_CLICK,t)}pointerWaitCancel(){this.tapWaitCancel(),this.longPressWaitCancel()}tapWait(){clearTimeout(this.tapTimer),this.waitTap=!0}tapWaitCancel(){this.waitTap&&(clearTimeout(this.tapTimer),this.waitTap=!1,this.tapCount=0)}longPressWait(t){clearTimeout(this.longPressTimer),this.longPressTimer=setTimeout((()=>{this.longPressed=!0,this.emit(F.LONG_PRESS,t)}),this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(F.LONG_TAP,t),(dt(t.path,F.LONG_TAP)||dt(t.path,F.LONG_PRESS))&&(e=!0)),this.longPressWaitCancel(),e}longPressWaitCancel(){this.longPressTimer&&(clearTimeout(this.longPressTimer),this.longPressed=!1)}__onResize(){const{dragOut:t}=this.m;this.shrinkCanvasBounds=new T(this.canvas.bounds),this.shrinkCanvasBounds.spread(-("number"==typeof t?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(O.RESIZE,this.__onResize,this)],t.once(x.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],nt(a,t,e,!0,s))return;a.isApp&&rt(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&rt(a,t,e,!1,s),nt(a,t,e,!1,s))return}catch(t){st.error(t)}}(t,e,i,s)}destroy(){this.__eventIds.length&&(this.stop(),this.__removeListenEvents(),this.dragger.destroy(),this.transformer&&this.transformer.destroy(),this.downData=this.overPath=this.enterPath=null)}}class ut{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}ut.custom={};class pt extends R{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new y,this.pixelList=new y}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),l.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),l.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:_t,copy:vt,setRadius:mt}=E,ft={},yt=C.prototype;yt.__hitWorld=function(t){const e=this.__;if(!e.hitSelf)return!1;const i=this.__world,s=this.__layout,a=i.width<10&&i.height<10;if(e.hitRadius&&(vt(ft,t),mt(t=ft,e.hitRadius)),_t(t,i,ft),e.hitBox||a){if(D.hitRadiusPoint(s.boxBounds,ft))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(ft)},yt.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},yt.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},yt.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},yt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const Et=new L,Dt=i.prototype;Dt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const t=this.__,{hitCanvasManager:e}=this.leafer||this.parent.leafer,i=(t.__pixelFill||t.__isCanvas)&&"pixel"===t.hitFill,s=t.__pixelStroke&&"pixel"===t.hitStroke,a=i||s;this.__hitCanvas||(this.__hitCanvas=a?e.getPixelType(this,{contextSettings:{willReadFrequently:!0}}):e.getPathType(this));const r=this.__hitCanvas;if(a){const{renderBounds:e}=this.__layout,a=w.image.hitCanvasSize,n=r.hitScale=b.set(0,0,a,a).getFitMatrix(e).a,{x:h,y:o,width:d,height:g}=b.set(e).scale(n);r.resize({width:d,height:g,pixelRatio:1}),r.clear(),S.patternLocked=!0,this.__renderShape(r,{matrix:Et.setWith(this.__world).scaleWith(1/n).invertWith().translate(-h,-o)},!i,!s),S.patternLocked=!1,r.resetTransform(),t.__isHitPixel=!0}else t.__isHitPixel&&(t.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(t)},Dt.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__pixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__strokeWidth:r}=e,n=e.stroke&&("path"===a||"pixel"===a&&!e.__pixelStroke)||"all"===a;if(!s&&!n)return!1;const h=2*t.radiusX;let o=h;if(n)switch(e.strokeAlign){case"inside":if(o+=2*r,!s&&this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h;break;case"center":o+=r;break;case"outside":if(o+=2*r,!s){if(!this.__hitFill(t)&&this.__hitStroke(t,o))return!0;o=h}}return!!o&&this.__hitStroke(t,o)};const Pt=i.prototype,wt=s.prototype,Tt=a.prototype;wt.__updateHitCanvas=Tt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Pt.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},wt.__hitFill=Tt.__hitFill=function(t){return this.__hitCanvas?Pt.__hitFill.call(this,t):D.hitRadiusPoint(this.__layout.boxBounds,t)},r.prototype.__drawHitPath=function(t){const{__lineHeight:e,fontSize:i,__baseLine:s,__letterSpacing:a,__textDrawData:r}=this.__;t.beginPath(),a<0?this.__drawPathByBox(t):r.rows.forEach((a=>t.rect(a.x,a.y-s,a.width,e<i?i:e)))},n.prototype.pick=function(t,e){return e||(e=d),this.updateLayout(),function(t){return t.leafer?t.leafer.selector:h.selector||(h.selector=o.selector())}(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const Ot=M.prototype;Ot.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},Ot.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},Ot.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:r,radiusY:n}=t;e&&(s-=e.x,a-=e.y),b.set(s-r,a-n,2*r,2*n).scale(i).ceil();const{data:h}=this.context.getImageData(b.x,b.y,b.width||1,b.height||1);for(let t=0,e=h.length;t<e;t+=4)if(h[t+3]>0)return!0;return h[3]>0};export{H as App,ut as Cursor,V as DragEvent,it as Dragger,j as DropEvent,pt as HitCanvasManager,ct as InteractionBase,q as InteractionHelper,Z as KeyEvent,B as Keyboard,z as MoveEvent,U as MyDragEvent,K as MyPointerEvent,I as PointerButton,F as PointerEvent,G as RotateEvent,X as SwipeEvent,N as UIEvent,Y as ZoomEvent};
|
|
2
2
|
//# sourceMappingURL=core.esm.min.js.map
|