@leafer-ui/core 1.6.7 → 1.7.0
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 +2 -1
- package/lib/core.esm.js +2 -1
- 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
CHANGED
|
@@ -696,6 +696,7 @@ const config = {
|
|
|
696
696
|
delta: { x: 80 / 4, y: 8.0 },
|
|
697
697
|
},
|
|
698
698
|
pointer: {
|
|
699
|
+
type: 'pointer',
|
|
699
700
|
snap: true,
|
|
700
701
|
hitRadius: 5,
|
|
701
702
|
tapTime: 120,
|
|
@@ -1239,7 +1240,7 @@ ui$1.__updateHitCanvas = function () {
|
|
|
1239
1240
|
h.resize({ width, height, pixelRatio: 1 });
|
|
1240
1241
|
h.clear();
|
|
1241
1242
|
core.ImageManager.patternLocked = true;
|
|
1242
|
-
this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y)
|
|
1243
|
+
this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
|
|
1243
1244
|
core.ImageManager.patternLocked = false;
|
|
1244
1245
|
h.resetTransform();
|
|
1245
1246
|
data.__isHitPixel = true;
|
package/lib/core.esm.js
CHANGED
|
@@ -695,6 +695,7 @@ const config = {
|
|
|
695
695
|
delta: { x: 80 / 4, y: 8.0 },
|
|
696
696
|
},
|
|
697
697
|
pointer: {
|
|
698
|
+
type: 'pointer',
|
|
698
699
|
snap: true,
|
|
699
700
|
hitRadius: 5,
|
|
700
701
|
tapTime: 120,
|
|
@@ -1238,7 +1239,7 @@ ui$1.__updateHitCanvas = function () {
|
|
|
1238
1239
|
h.resize({ width, height, pixelRatio: 1 });
|
|
1239
1240
|
h.clear();
|
|
1240
1241
|
ImageManager.patternLocked = true;
|
|
1241
|
-
this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y)
|
|
1242
|
+
this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
|
|
1242
1243
|
ImageManager.patternLocked = false;
|
|
1243
1244
|
h.resetTransform();
|
|
1244
1245
|
data.__isHitPixel = true;
|
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,emptyData as h}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as o,Creator as d,DataHelper as g,canvasSizeAttrs as l,LayoutEvent as c,RenderEvent as u,Event as p,EventCreator as _,registerUIEvent as v,LeafList as m,PointHelper as f,BoundsHelper as y,Debug as E,Platform as D,Bounds as P,ResizeEvent as w,LeaferEvent as T,CanvasManager as O,Leaf as x,Matrix as L,tempBounds as R,ImageManager as C,LeaferCanvasBase as b}from"@leafer/core";function S(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 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:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&d.editor(a,this)}}__setApp(){const{canvas:t}=this,{realCanvas:e,view:i}=this.config;e||i===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable()}__updateLocalBounds(){this.forEach((t=>t.updateLayout())),super.__updateLocalBounds()}start(){super.start(),this.forEach((t=>t.start()))}stop(){this.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.forEach((t=>t.lockLayout()))}forceRender(t,e){this.forEach((i=>i.forceRender(t,e)))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),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){t.context&&this.forEach((i=>e.matrix?i.__render(t,e):t.copyWorld(i.canvas,e&&e.bounds)))}__onResize(t){this.forEach((e=>e.resize(t))),super.__onResize(t)}updateLayout(){this.forEach((t=>t.updateLayout()))}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&g.assign(e,t),this.autoLayout&&g.copyAttrs(e,this,l),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once([[c.END,this.__onReady,this],[u.START,this.__onCreated,this],[u.END,this.__onViewReady,this]]),this.realCanvas&&this.__eventIds.push(t.on_(u.END,this.__onChildRenderEnd,this))}};M=S([o()],M);const k={},A={isHoldSpaceKey:()=>A.isHold("Space"),isHold:t=>k[t],setDownCode(t){k[t]||(k[t]=!0)},setUpCode(t){k[t]=!1}},H={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 B extends p{get spaceKey(){return A.isHoldSpaceKey()}get left(){return H.left(this)}get right(){return H.right(this)}get middle(){return H.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){_.changeName(t,e)}}let I=class extends B{};I.POINTER="pointer",I.BEFORE_DOWN="pointer.before_down",I.BEFORE_MOVE="pointer.before_move",I.BEFORE_UP="pointer.before_up",I.DOWN="pointer.down",I.MOVE="pointer.move",I.UP="pointer.up",I.OVER="pointer.over",I.OUT="pointer.out",I.ENTER="pointer.enter",I.LEAVE="pointer.leave",I.TAP="tap",I.DOUBLE_TAP="double_tap",I.CLICK="click",I.DOUBLE_CLICK="double_click",I.LONG_PRESS="long_press",I.LONG_TAP="long_tap",I.MENU="pointer.menu",I.MENU_TAP="pointer.menu_tap",I=S([v()],I);const N=I,F={};let K=class extends I{static setList(t){this.list=t instanceof m?t:new m(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 f.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)),y.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(F,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(F,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(F,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 y.set(i,e.x-t.x,e.y-t.y,t.x,t.y),y.unsign(i),i}assignMove(t){F.x=t?this.totalX:this.moveX,F.y=t?this.totalY:this.moveY}};K.BEFORE_DRAG="drag.before_drag",K.START="drag.start",K.DRAG="drag",K.END="drag.end",K.OVER="drag.over",K.OUT="drag.out",K.ENTER="drag.enter",K.LEAVE="drag.leave",K=S([v()],K);const W=K;let V=class extends I{static setList(t){K.setList(t)}static setData(t){K.setData(t)}};V.DROP="drop",V=S([v()],V);let U=class extends K{};U.BEFORE_MOVE="move.before_move",U.START="move.start",U.MOVE="move",U.END="move.end",U=S([v()],U);let j=class extends I{};j.BEFORE_ROTATE="rotate.before_rotate",j.START="rotate.start",j.ROTATE="rotate",j.END="rotate.end",j=S([v()],j);let z=class extends K{};z.SWIPE="swipe",z.LEFT="swipe.left",z.RIGHT="swipe.right",z.UP="swipe.up",z.DOWN="swipe.down",z=S([v()],z);let G=class extends I{};G.BEFORE_ZOOM="zoom.before_zoom",G.START="zoom.start",G.ZOOM="zoom",G.END="zoom.end",G=S([v()],G);let X=class extends B{};X.DOWN="key.down",X.HOLD="key.hold",X.UP="key.up",X=S([v()],X);const Y={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?z.UP:t>45&&t<135?z.DOWN:t<=45&&t>=-45?z.RIGHT:z.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:Z.getSwipeDirection(f.getAngle(t,i))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:void 0===t.buttons?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new m,{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(K.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},Z=Y,q=new m,{getDragEventData:J,getDropEventData:Q,getSwipeEventData:$}=Y;class tt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=J(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=K.list||this.draggableList||q;return this.dragging&&(s?t?q:new m(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(U.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&H.left(t),this.dragging&&(this.interaction.emit(K.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 m(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:r}=s;this.dragData=J(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(U.BEFORE_MOVE,this.dragData),e.emit(U.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(K.BEFORE_DRAG,this.dragData),e.emit(K.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(K.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(K.OUT,t,i),e.emit(K.OVER,t,s)):e.emit(K.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(K.LEAVE,t,i,s),e.emit(K.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=J(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(U.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.emit(K.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(f.getDistance(e,t)>a.config.pointer.swipeDistance){const t=$(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=Q(t,e,K.data);s.path=i,this.interaction.emit(V.DROP,s),this.interaction.emit(K.LEAVE,t,i)}dragReset(){K.list=K.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 et=E.get("emit");const it=["move","zoom","rotate","key"];function st(t,e,i,s,a){if(it.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!rt(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&&at(r,e,i,s,a)}}function at(t,i,s,a,r){if(t.destroyed)return!1;if(t.__.hitSelf&&!rt(t,r)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=_.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function rt(t,e){return e&&e.has(t)}const nt={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:ht,pathCanDrag:ot,pathHasOutside:dt}=Y;class gt{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&&H.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&H.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&A.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=g.clone(nt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new m(t),this.createTransformer(),this.dragger=new tt(this),s&&(this.config=g.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(H.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(I.BEFORE_DOWN,t),this.emit(I.DOWN,t),H.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=H.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&&H.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(I.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=f.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(I.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;H.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(I.BEFORE_UP,t),this.emit(I.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(I.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(I.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,A.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,A.setUpCode(e),this.emit(X.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new m),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(I.OUT,t,i),this.emit(I.OVER,t,e)):this.emit(I.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(I.LEAVE,t,i,e),this.emit(I.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(I.LEAVE,t),this.dragger.dragging&&this.emit(V.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=[I.DOUBLE_TAP,I.DOUBLE_CLICK].some((e=>ht(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;D.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&&!dt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!ot(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: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:I.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&&f.round(s),s}emitTap(t){this.emit(I.TAP,t),this.emit(I.CLICK,t)}emitDoubleTap(t){this.emit(I.DOUBLE_TAP,t),this.emit(I.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(I.LONG_PRESS,t)}),this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(I.LONG_TAP,t),(ht(t.path,I.LONG_TAP)||ht(t.path,I.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 P(this.canvas.bounds),this.shrinkCanvasBounds.spread(-("number"==typeof t?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(w.RESIZE,this.__onResize,this)],t.once(T.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],at(a,t,e,!0,s))return;a.isApp&&st(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&st(a,t,e,!1,s),at(a,t,e,!1,s))return}catch(t){et.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 lt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}lt.custom={};class ct extends O{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new m,this.pixelList=new m}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),d.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),d.hitCanvas()}clearImageType(){this.__clearLeafList(this.pixelList)}clearPathType(){this.__clearLeafList(this.pathList)}__clearLeafList(t){t.length&&(t.forEach((t=>{t.__hitCanvas&&(t.__hitCanvas.destroy(),t.__hitCanvas=null)})),t.reset())}__autoClear(){this.pathList.length+this.pixelList.length>this.maxTotal&&this.clear()}clear(){this.clearPathType(),this.clearImageType()}}const{toInnerRadiusPointOf:ut,copy:pt,setRadius:_t}=f,vt={},mt=x.prototype;mt.__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&&(pt(vt,t),_t(t=vt,e.hitRadius)),ut(t,i,vt),e.hitBox||a){if(y.hitRadiusPoint(s.boxBounds,vt))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(vt)},mt.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},mt.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},mt.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},mt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const ft=new L,yt=i.prototype;yt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const t=this.__,{hitCanvasManager:e}=this.leafer||this.parent.leafer,i=(t.__isAlphaPixelFill||t.__isCanvas)&&"pixel"===t.hitFill,s=t.__isAlphaPixelStroke&&"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=D.image.hitCanvasSize,n=r.hitScale=R.set(0,0,a,a).getFitMatrix(e).a,{x:h,y:o,width:d,height:g}=R.set(e).scale(n);r.resize({width:d,height:g,pixelRatio:1}),r.clear(),C.patternLocked=!0,this.__renderShape(r,{matrix:ft.setWith(this.__world).scaleWith(1/n).invertWith().translate(-h,-o)},!i,!s),C.patternLocked=!1,r.resetTransform(),t.__isHitPixel=!0}else t.__isHitPixel&&(t.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(t)},yt.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__isAlphaPixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__strokeWidth:r}=e,n=e.stroke&&("path"===a||"pixel"===a&&!e.__isAlphaPixelStroke)||"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 Et=i.prototype,Dt=s.prototype,Pt=a.prototype;Dt.__updateHitCanvas=Pt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Et.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Dt.__hitFill=Pt.__hitFill=function(t){return this.__hitCanvas?Et.__hitFill.call(this,t):y.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=h),this.updateLayout(),function(t){return t.leafer?t.leafer.selector:D.selector||(D.selector=d.selector())}(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const wt=b.prototype;wt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},wt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},wt.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:r,radiusY:n}=t;e&&(s-=e.x,a-=e.y),R.set(s-r,a-n,2*r,2*n).scale(i).ceil();const{data:h}=this.context.getImageData(R.x,R.y,R.width||1,R.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{M as App,lt as Cursor,K as DragEvent,tt as Dragger,V as DropEvent,ct as HitCanvasManager,gt as InteractionBase,Y as InteractionHelper,X as KeyEvent,A as Keyboard,U as MoveEvent,W as MyDragEvent,N as MyPointerEvent,H as PointerButton,I as PointerEvent,j as RotateEvent,z as SwipeEvent,B as UIEvent,G 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,emptyData as h}from"@leafer-ui/draw";export*from"@leafer-ui/draw";import{registerUI as o,Creator as d,DataHelper as g,canvasSizeAttrs as l,LayoutEvent as c,RenderEvent as u,Event as p,EventCreator as _,registerUIEvent as v,LeafList as m,PointHelper as f,BoundsHelper as y,Debug as E,Platform as D,Bounds as P,ResizeEvent as w,LeaferEvent as T,CanvasManager as O,Leaf as x,Matrix as L,tempBounds as R,ImageManager as C,LeaferCanvasBase as b}from"@leafer/core";function S(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 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:s,editor:a}=t;e&&(this.ground=this.addLeafer(e)),(i||a)&&(this.tree=this.addLeafer(i||{type:t.type||"design"})),(s||a)&&(this.sky=this.addLeafer(s)),a&&d.editor(a,this)}}__setApp(){const{canvas:t}=this,{realCanvas:e,view:i}=this.config;e||i===this.canvas.view||!t.parentView?this.realCanvas=!0:t.unrealCanvas(),this.leafer=this,this.watcher.disable(),this.layouter.disable()}__updateLocalBounds(){this.forEach((t=>t.updateLayout())),super.__updateLocalBounds()}start(){super.start(),this.forEach((t=>t.start()))}stop(){this.forEach((t=>t.stop())),super.stop()}unlockLayout(){super.unlockLayout(),this.forEach((t=>t.unlockLayout()))}lockLayout(){super.lockLayout(),this.forEach((t=>t.lockLayout()))}forceRender(t,e){this.forEach((i=>i.forceRender(t,e)))}addLeafer(e){const i=new t(e);return this.add(i),i}add(t,e){if(!t.view){if(this.realCanvas&&!this.canvas.bounds)return void setTimeout((()=>this.add(t,e)),10);t.init(this.__getChildConfig(t.userConfig),this)}super.add(t,e),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){t.context&&this.forEach((i=>e.matrix?i.__render(t,e):t.copyWorld(i.canvas,e&&e.bounds)))}__onResize(t){this.forEach((e=>e.resize(t))),super.__onResize(t)}updateLayout(){this.forEach((t=>t.updateLayout()))}__getChildConfig(t){const e=Object.assign({},this.config);return e.hittable=e.realCanvas=void 0,t&&g.assign(e,t),this.autoLayout&&g.copyAttrs(e,this,l),e.view=this.realCanvas?void 0:this.view,e.fill=void 0,e}__listenChildEvents(t){t.once([[c.END,this.__onReady,this],[u.START,this.__onCreated,this],[u.END,this.__onViewReady,this]]),this.realCanvas&&this.__eventIds.push(t.on_(u.END,this.__onChildRenderEnd,this))}};M=S([o()],M);const k={},A={isHoldSpaceKey:()=>A.isHold("Space"),isHold:t=>k[t],setDownCode(t){k[t]||(k[t]=!0)},setUpCode(t){k[t]=!1}},H={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 B extends p{get spaceKey(){return A.isHoldSpaceKey()}get left(){return H.left(this)}get right(){return H.right(this)}get middle(){return H.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){_.changeName(t,e)}}let I=class extends B{};I.POINTER="pointer",I.BEFORE_DOWN="pointer.before_down",I.BEFORE_MOVE="pointer.before_move",I.BEFORE_UP="pointer.before_up",I.DOWN="pointer.down",I.MOVE="pointer.move",I.UP="pointer.up",I.OVER="pointer.over",I.OUT="pointer.out",I.ENTER="pointer.enter",I.LEAVE="pointer.leave",I.TAP="tap",I.DOUBLE_TAP="double_tap",I.CLICK="click",I.DOUBLE_CLICK="double_click",I.LONG_PRESS="long_press",I.LONG_TAP="long_tap",I.MENU="pointer.menu",I.MENU_TAP="pointer.menu_tap",I=S([v()],I);const N=I,F={};let K=class extends I{static setList(t){this.list=t instanceof m?t:new m(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 f.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)),y.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(F,null,!0)}getInnerMove(t,e){return t||(t=this.current),this.assignMove(e),t.getInnerPoint(F,null,!0)}getLocalMove(t,e){return t||(t=this.current),this.assignMove(e),t.getLocalPoint(F,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 y.set(i,e.x-t.x,e.y-t.y,t.x,t.y),y.unsign(i),i}assignMove(t){F.x=t?this.totalX:this.moveX,F.y=t?this.totalY:this.moveY}};K.BEFORE_DRAG="drag.before_drag",K.START="drag.start",K.DRAG="drag",K.END="drag.end",K.OVER="drag.over",K.OUT="drag.out",K.ENTER="drag.enter",K.LEAVE="drag.leave",K=S([v()],K);const W=K;let V=class extends I{static setList(t){K.setList(t)}static setData(t){K.setData(t)}};V.DROP="drop",V=S([v()],V);let U=class extends K{};U.BEFORE_MOVE="move.before_move",U.START="move.start",U.MOVE="move",U.END="move.end",U=S([v()],U);let j=class extends I{};j.BEFORE_ROTATE="rotate.before_rotate",j.START="rotate.start",j.ROTATE="rotate",j.END="rotate.end",j=S([v()],j);let z=class extends K{};z.SWIPE="swipe",z.LEFT="swipe.left",z.RIGHT="swipe.right",z.UP="swipe.up",z.DOWN="swipe.down",z=S([v()],z);let G=class extends I{};G.BEFORE_ZOOM="zoom.before_zoom",G.START="zoom.start",G.ZOOM="zoom",G.END="zoom.end",G=S([v()],G);let X=class extends B{};X.DOWN="key.down",X.HOLD="key.hold",X.UP="key.up",X=S([v()],X);const Y={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?z.UP:t>45&&t<135?z.DOWN:t<=45&&t>=-45?z.RIGHT:z.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:Z.getSwipeDirection(f.getAngle(t,i))}),getBase(t){const e=1===t.button?4:t.button;return{altKey:t.altKey,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,metaKey:t.metaKey,buttons:void 0===t.buttons?1:0===t.buttons?e:t.buttons,origin:t}},pathHasEventType(t,e){const{list:i}=t;for(let t=0,s=i.length;t<s;t++)if(i[t].hasEvent(e))return!0;return!1},filterPathByEventType(t,e){const i=new m,{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(K.DRAG))),pathHasOutside:t=>t&&t.list.some((t=>t.isOutside))},Z=Y,q=new m,{getDragEventData:J,getDropEventData:Q,getSwipeEventData:$}=Y;class tt{constructor(t){this.interaction=t}setDragData(t){this.animateWait&&this.dragEndReal(),this.downData=this.interaction.downData,this.dragData=J(t,t,t),this.canAnimate=this.canDragOut=!0}getList(t,e){const{proxy:i}=this.interaction.selector,s=i&&i.list.length,a=K.list||this.draggableList||q;return this.dragging&&(s?t?q:new m(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(U.START,this.dragData)),this.moving||this.dragStart(t,e),this.drag(t)}dragStart(t,e){this.dragging||(this.dragging=e&&H.left(t),this.dragging&&(this.interaction.emit(K.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 m(e);break}}drag(t){const{interaction:e,dragData:i,downData:s}=this,{path:a,throughPath:r}=s;this.dragData=J(s,i,t),r&&(this.dragData.throughPath=r),this.dragData.path=a,this.moving?(this.dragData.moveType="drag",e.emit(U.BEFORE_MOVE,this.dragData),e.emit(U.MOVE,this.dragData)):this.dragging&&(this.dragReal(),e.emit(K.BEFORE_DRAG,this.dragData),e.emit(K.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(K.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(K.OUT,t,i),e.emit(K.OVER,t,s)):e.emit(K.OVER,t,s)}dragEnterOrLeave(t){const{interaction:e}=this,{dragEnterPath:i}=this,{path:s}=t;e.emit(K.LEAVE,t,i,s),e.emit(K.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=J(i,t,t);if(r&&(n.throughPath=r),n.path=a,this.moving&&(this.moving=!1,n.moveType="drag",e.emit(U.END,n)),this.dragging){const a=this.getList();this.dragging=!1,e.emit(K.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(f.getDistance(e,t)>a.config.pointer.swipeDistance){const t=$(e,i,s);this.interaction.emit(t.type,t)}}drop(t,e,i){const s=Q(t,e,K.data);s.path=i,this.interaction.emit(V.DROP,s),this.interaction.emit(K.LEAVE,t,i)}dragReset(){K.list=K.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 et=E.get("emit");const it=["move","zoom","rotate","key"];function st(t,e,i,s,a){if(it.some((t=>e.startsWith(t)))&&t.__.hitChildren&&!rt(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&&at(r,e,i,s,a)}}function at(t,i,s,a,r){if(t.destroyed)return!1;if(t.__.hitSelf&&!rt(t,r)&&(e.updateEventStyle&&!a&&e.updateEventStyle(t,i),t.hasEvent(i,a))){s.phase=a?1:t===s.target?2:3;const e=_.get(i,s);if(t.emitEvent(e,a),e.isStop)return!0}return!1}function rt(t,e){return e&&e.has(t)}const nt={wheel:{zoomSpeed:.5,moveSpeed:.5,rotateSpeed:.5,delta:{x:20,y:8}},pointer:{type:"pointer",snap:!0,hitRadius:5,tapTime:120,longPressTime:800,transformTime:500,hover:!0,dragHover:!0,dragDistance:2,swipeDistance:20},touch:{preventDefault:"auto"},multiTouch:{},move:{autoDistance:2},zoom:{},cursor:!0,keyEvent:!0},{pathHasEventType:ht,pathCanDrag:ot,pathHasOutside:dt}=Y;class gt{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&&H.middle(this.downData)}get isHoldRightKey(){return this.m.holdRightKey&&this.downData&&H.right(this.downData)}get isHoldSpaceKey(){return this.m.holdSpaceKey&&A.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=g.clone(nt),this.tapCount=0,this.downKeyMap={},this.target=t,this.canvas=e,this.selector=i,this.defaultPath=new m(t),this.createTransformer(),this.dragger=new tt(this),s&&(this.config=g.default(s,this.config)),this.__listenEvents()}start(){this.running=!0}stop(){this.running=!1}receive(t){}pointerDown(t,e){t||(t=this.hoverData),t&&(H.defaultLeft(t),this.updateDownData(t),this.checkPath(t,e),this.downTime=Date.now(),this.emit(I.BEFORE_DOWN,t),this.emit(I.DOWN,t),H.left(t)&&(this.tapWait(),this.longPressWait(t)),this.waitRightTap=H.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&&H.defaultLeft(t);(this.canvas.bounds.hitPoint(t)||e)&&(this.pointerMoveReal(t),e&&this.dragger.checkDragOut(t))}pointerMoveReal(t){if(this.emit(I.BEFORE_MOVE,t,this.defaultPath),this.downData){const e=f.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(I.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;H.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(I.BEFORE_UP,t),this.emit(I.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(I.MENU,t),this.waitMenuTap=!0,!this.downData&&this.waitRightTap&&this.menuTap(t)}menuTap(t){this.waitRightTap&&this.waitMenuTap&&(this.emit(I.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,A.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,A.setUpCode(e),this.emit(X.UP,t,this.defaultPath),"grab"===this.cursor&&this.updateCursor()}pointerHover(t){!this.canHover||this.dragging&&!this.p.dragHover||(t.path||(t.path=new m),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(I.OUT,t,i),this.emit(I.OVER,t,e)):this.emit(I.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(I.LEAVE,t,i,e),this.emit(I.ENTER,t,e,i)}touchLeave(t){"touch"===t.pointerType&&this.enterPath&&(this.emit(I.LEAVE,t),this.dragger.dragging&&this.emit(V.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=[I.DOUBLE_TAP,I.DOUBLE_CLICK].some((e=>ht(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;D.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&&!dt(t.path))&&(t.path=this.defaultPath)}canMove(t){return t&&(this.moveMode||"auto"===this.m.drag&&!ot(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: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:I.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&&f.round(s),s}emitTap(t){this.emit(I.TAP,t),this.emit(I.CLICK,t)}emitDoubleTap(t){this.emit(I.DOUBLE_TAP,t),this.emit(I.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(I.LONG_PRESS,t)}),this.p.longPressTime)}longTap(t){let e;return this.longPressed&&(this.emit(I.LONG_TAP,t),(ht(t.path,I.LONG_TAP)||ht(t.path,I.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 P(this.canvas.bounds),this.shrinkCanvasBounds.spread(-("number"==typeof t?t:2))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(w.RESIZE,this.__onResize,this)],t.once(T.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],at(a,t,e,!0,s))return;a.isApp&&st(a,t,e,!0,s)}for(let r=0,n=i.length;r<n;r++)if(a=i.list[r],a.isApp&&st(a,t,e,!1,s),at(a,t,e,!1,s))return}catch(t){et.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 lt{static set(t,e){this.custom[t]=e}static get(t){return this.custom[t]}}lt.custom={};class ct extends O{constructor(){super(...arguments),this.maxTotal=1e3,this.pathList=new m,this.pixelList=new m}getPixelType(t,e){return this.__autoClear(),this.pixelList.add(t),d.hitCanvas(e)}getPathType(t){return this.__autoClear(),this.pathList.add(t),d.hitCanvas()}clearImageType(){this.__clearLeafList(this.pixelList)}clearPathType(){this.__clearLeafList(this.pathList)}__clearLeafList(t){t.length&&(t.forEach((t=>{t.__hitCanvas&&(t.__hitCanvas.destroy(),t.__hitCanvas=null)})),t.reset())}__autoClear(){this.pathList.length+this.pixelList.length>this.maxTotal&&this.clear()}clear(){this.clearPathType(),this.clearImageType()}}const{toInnerRadiusPointOf:ut,copy:pt,setRadius:_t}=f,vt={},mt=x.prototype;mt.__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&&(pt(vt,t),_t(t=vt,e.hitRadius)),ut(t,i,vt),e.hitBox||a){if(y.hitRadiusPoint(s.boxBounds,vt))return!0;if(a)return!1}return!s.hitCanvasChanged&&this.__hitCanvas||(this.__updateHitCanvas(),s.boundsChanged||(s.hitCanvasChanged=!1)),this.__hit(vt)},mt.__hitFill=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitFill(t,this.__.windingRule)},mt.__hitStroke=function(t,e){var i;return null===(i=this.__hitCanvas)||void 0===i?void 0:i.hitStroke(t,e)},mt.__hitPixel=function(t){var e;return null===(e=this.__hitCanvas)||void 0===e?void 0:e.hitPixel(t,this.__layout.renderBounds,this.__hitCanvas.hitScale)},mt.__drawHitPath=function(t){t&&this.__drawRenderPath(t)};const ft=new L,yt=i.prototype;yt.__updateHitCanvas=function(){this.__box&&this.__box.__updateHitCanvas();const t=this.__,{hitCanvasManager:e}=this.leafer||this.parent.leafer,i=(t.__isAlphaPixelFill||t.__isCanvas)&&"pixel"===t.hitFill,s=t.__isAlphaPixelStroke&&"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=D.image.hitCanvasSize,n=r.hitScale=R.set(0,0,a,a).getFitMatrix(e).a,{x:h,y:o,width:d,height:g}=R.set(e).scale(n);r.resize({width:d,height:g,pixelRatio:1}),r.clear(),C.patternLocked=!0,this.__renderShape(r,{matrix:ft.setWith(this.__world).scaleWith(1/n).invertWith().translate(-h,-o),ignoreFill:!i,ignoreStroke:!s}),C.patternLocked=!1,r.resetTransform(),t.__isHitPixel=!0}else t.__isHitPixel&&(t.__isHitPixel=!1);this.__drawHitPath(r),r.setStrokeOptions(t)},yt.__hit=function(t){if(this.__box&&this.__box.__hit(t))return!0;const e=this.__;if(e.__isHitPixel&&this.__hitPixel(t))return!0;const{hitFill:i}=e,s=(e.fill||e.__isCanvas)&&("path"===i||"pixel"===i&&!(e.__isAlphaPixelFill||e.__isCanvas))||"all"===i;if(s&&this.__hitFill(t))return!0;const{hitStroke:a,__strokeWidth:r}=e,n=e.stroke&&("path"===a||"pixel"===a&&!e.__isAlphaPixelStroke)||"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 Et=i.prototype,Dt=s.prototype,Pt=a.prototype;Dt.__updateHitCanvas=Pt.__updateHitCanvas=function(){this.stroke||this.cornerRadius||(this.fill||this.__.__isCanvas)&&"pixel"===this.hitFill||"all"===this.hitStroke?Et.__updateHitCanvas.call(this):this.__hitCanvas&&(this.__hitCanvas=null)},Dt.__hitFill=Pt.__hitFill=function(t){return this.__hitCanvas?Et.__hitFill.call(this,t):y.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=h),this.updateLayout(),function(t){return t.leafer?t.leafer.selector:D.selector||(D.selector=d.selector())}(this).getByPoint(t,e.hitRadius||0,Object.assign(Object.assign({},e),{target:this}))};const wt=b.prototype;wt.hitFill=function(t,e){return e?this.context.isPointInPath(t.x,t.y,e):this.context.isPointInPath(t.x,t.y)},wt.hitStroke=function(t,e){return this.strokeWidth=e,this.context.isPointInStroke(t.x,t.y)},wt.hitPixel=function(t,e,i=1){let{x:s,y:a,radiusX:r,radiusY:n}=t;e&&(s-=e.x,a-=e.y),R.set(s-r,a-n,2*r,2*n).scale(i).ceil();const{data:h}=this.context.getImageData(R.x,R.y,R.width||1,R.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{M as App,lt as Cursor,K as DragEvent,tt as Dragger,V as DropEvent,ct as HitCanvasManager,gt as InteractionBase,Y as InteractionHelper,X as KeyEvent,A as Keyboard,U as MoveEvent,W as MyDragEvent,N as MyPointerEvent,H as PointerButton,I as PointerEvent,j as RotateEvent,z as SwipeEvent,B as UIEvent,G as ZoomEvent};
|
|
2
2
|
//# sourceMappingURL=core.esm.min.js.map
|