@leafer-in/viewport 1.9.1 → 1.9.3

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/dist/viewport.cjs CHANGED
@@ -6,7 +6,9 @@ function addViewport(leafer, mergeConfig, custom) {
6
6
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
7
7
  if (leafer.isApp || custom) return;
8
8
  leafer.__eventIds.push(leafer.on_(core.MoveEvent.BEFORE_MOVE, e => {
9
- leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
9
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false));
10
+ }), leafer.on_(core.MoveEvent.END, e => {
11
+ core.LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY));
10
12
  }), leafer.on_(core.ZoomEvent.BEFORE_ZOOM, e => {
11
13
  const {zoomLayer: zoomLayer} = leafer;
12
14
  const changeScale = leafer.getValidScale(e.scale);
@@ -221,32 +223,27 @@ class Transformer {
221
223
 
222
224
  const leafer = core.Leafer.prototype;
223
225
 
224
- const bounds = new core.Bounds;
226
+ const bounds = new core.Bounds, move = new core.Point;
225
227
 
226
228
  leafer.initType = function(type) {
227
229
  LeaferTypeCreator.run(type, this);
228
230
  };
229
231
 
230
- leafer.getValidMove = function(moveX, moveY) {
232
+ leafer.getValidMove = function(moveX, moveY, checkLimit = true) {
231
233
  const {scroll: scroll, disabled: disabled} = this.app.config.move;
234
+ move.set(moveX, moveY);
232
235
  if (scroll) {
233
236
  const type = scroll === true ? "" : scroll;
234
- if (type.includes("x")) moveX = moveX || moveY, moveY = 0; else if (type.includes("y")) moveY = moveY || moveX,
235
- moveX = 0; else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
236
- if (type.includes("limit")) {
237
- const {x: x, y: y, width: width, height: height} = bounds.set(this.__world).addPoint(this.zoomLayer);
238
- const right = x + width - this.width, bottom = y + height - this.height;
239
- if (x >= 0 && right <= 0) moveX = 0; else if (moveX > 0) {
240
- if (x + moveX > 0) moveX = -x;
241
- } else if (moveX < 0 && right + moveX < 0) moveX = -right;
242
- if (y >= 0 && bottom <= 0) moveY = 0; else if (moveY > 0) {
243
- if (y + moveY > 0) moveY = -y;
244
- } else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom;
237
+ if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0; else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0;
238
+ if (checkLimit && type.includes("limit")) {
239
+ bounds.set(this.__world).addPoint(this.zoomLayer);
240
+ core.DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, "inner", move, true);
241
+ if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0;
245
242
  }
246
243
  }
247
244
  return {
248
- x: disabled ? 0 : moveX,
249
- y: disabled ? 0 : moveY
245
+ x: disabled ? 0 : move.x,
246
+ y: disabled ? 0 : move.y
250
247
  };
251
248
  };
252
249
 
@@ -1,10 +1,12 @@
1
- import { MoveEvent, ZoomEvent, DataHelper, Debug, PointHelper, Platform, MathHelper, RotateEvent, Leafer, Bounds, InteractionBase, Dragger, isNumber, BoundsHelper, Plugin } from "@leafer-ui/core";
1
+ import { MoveEvent, LeafHelper, ZoomEvent, DataHelper, Debug, PointHelper, Platform, MathHelper, RotateEvent, Leafer, Bounds, Point, DragBoundsHelper, InteractionBase, Dragger, isNumber, BoundsHelper, Plugin } from "@leafer-ui/core";
2
2
 
3
3
  function addViewport(leafer, mergeConfig, custom) {
4
4
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
5
5
  if (leafer.isApp || custom) return;
6
6
  leafer.__eventIds.push(leafer.on_(MoveEvent.BEFORE_MOVE, e => {
7
- leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
7
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false));
8
+ }), leafer.on_(MoveEvent.END, e => {
9
+ LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY));
8
10
  }), leafer.on_(ZoomEvent.BEFORE_ZOOM, e => {
9
11
  const {zoomLayer: zoomLayer} = leafer;
10
12
  const changeScale = leafer.getValidScale(e.scale);
@@ -219,32 +221,27 @@ class Transformer {
219
221
 
220
222
  const leafer = Leafer.prototype;
221
223
 
222
- const bounds = new Bounds;
224
+ const bounds = new Bounds, move = new Point;
223
225
 
224
226
  leafer.initType = function(type) {
225
227
  LeaferTypeCreator.run(type, this);
226
228
  };
227
229
 
228
- leafer.getValidMove = function(moveX, moveY) {
230
+ leafer.getValidMove = function(moveX, moveY, checkLimit = true) {
229
231
  const {scroll: scroll, disabled: disabled} = this.app.config.move;
232
+ move.set(moveX, moveY);
230
233
  if (scroll) {
231
234
  const type = scroll === true ? "" : scroll;
232
- if (type.includes("x")) moveX = moveX || moveY, moveY = 0; else if (type.includes("y")) moveY = moveY || moveX,
233
- moveX = 0; else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
234
- if (type.includes("limit")) {
235
- const {x: x, y: y, width: width, height: height} = bounds.set(this.__world).addPoint(this.zoomLayer);
236
- const right = x + width - this.width, bottom = y + height - this.height;
237
- if (x >= 0 && right <= 0) moveX = 0; else if (moveX > 0) {
238
- if (x + moveX > 0) moveX = -x;
239
- } else if (moveX < 0 && right + moveX < 0) moveX = -right;
240
- if (y >= 0 && bottom <= 0) moveY = 0; else if (moveY > 0) {
241
- if (y + moveY > 0) moveY = -y;
242
- } else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom;
235
+ if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0; else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0;
236
+ if (checkLimit && type.includes("limit")) {
237
+ bounds.set(this.__world).addPoint(this.zoomLayer);
238
+ DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, "inner", move, true);
239
+ if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0;
243
240
  }
244
241
  }
245
242
  return {
246
- x: disabled ? 0 : moveX,
247
- y: disabled ? 0 : moveY
243
+ x: disabled ? 0 : move.x,
244
+ y: disabled ? 0 : move.y
248
245
  };
249
246
  };
250
247
 
@@ -1,2 +1,2 @@
1
- import{MoveEvent as t,ZoomEvent as e,DataHelper as o,Debug as a,PointHelper as i,Platform as n,MathHelper as s,RotateEvent as r,Leafer as c,Bounds as m,InteractionBase as h,Dragger as l,isNumber as u,BoundsHelper as d,Plugin as f}from"@leafer-ui/core";function g(o,a,i){v(o.parentApp?o.parentApp:o,a),o.isApp||i||o.__eventIds.push(o.on_(t.BEFORE_MOVE,t=>{o.zoomLayer.move(o.getValidMove(t.moveX,t.moveY))}),o.on_(e.BEFORE_ZOOM,t=>{const{zoomLayer:e}=o,a=o.getValidScale(t.scale);1!==a&&e.scaleOfWorld(t,a)}))}function v(t,e){const a={wheel:{preventDefault:!0},touch:{preventDefault:!0},pointer:{preventDefaultMenu:!0}};e&&o.assign(a,e),o.assign(t.config,a,t.userConfig)}const p=a.get("LeaferTypeCreator"),D={list:{},register(t,e){O[t]&&p.repeat(t),O[t]=e},run(t,e){const o=O[t];o&&o(e)}},{list:O,register:y}=D;y("viewport",g),y("custom",function(t){g(t,null,!0)}),y("design",function(t){g(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})}),y("document",function(t){g(t,{zoom:{min:1},move:{scroll:"limit"}})});const M={getData(t){const e=t[0],o=t[1],a=i.getCenter(e.from,o.from),n=i.getCenter(e.to,o.to),s={x:n.x-a.x,y:n.y-a.y},r=i.getDistance(e.from,o.from);return{move:s,scale:i.getDistance(e.to,o.to)/r,rotation:i.getRotation(e.from,o.from,e.to,o.to),center:n}}},T={getMove(t,e){let{moveSpeed:o}=e,{deltaX:a,deltaY:i}=t;return t.shiftKey&&!a&&(a=i,i=0),a>50&&(a=Math.max(50,a/3)),i>50&&(i=Math.max(50,i/3)),{x:-a*o*2,y:-i*o*2}},getScale(t,e){let o,a=1,{zoomMode:i,zoomSpeed:r}=e;const c=t.deltaY||t.deltaX;if(i?(o="mouse"===i||!t.deltaX&&(n.intWheelDeltaY?Math.abs(c)>17:Math.ceil(c)!==c),(t.shiftKey||t.metaKey||t.ctrlKey)&&(o=!0)):o=!t.shiftKey&&(t.metaKey||t.ctrlKey),o){r=s.within(r,0,1);a=1-c/(4*(t.deltaY?e.delta.y:e.delta.x))*r,a<.5&&(a=.5),a>=1.5&&(a=1.5)}return a}};class E{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(e){const{interaction:o}=this;e.moveType||(e.moveType="move"),this.moveData||(this.setPath(e),this.moveData=Object.assign(Object.assign({},e),{moveX:0,moveY:0}),o.emit(t.START,this.moveData)),e.path=this.moveData.path,o.emit(t.BEFORE_MOVE,e),o.emit(t.MOVE,e),this.transformEndWait()}zoom(t){const{interaction:o}=this;this.zoomData||(this.setPath(t),this.zoomData=Object.assign(Object.assign({},t),{scale:1}),o.emit(e.START,this.zoomData)),t.path=this.zoomData.path,o.emit(e.BEFORE_ZOOM,t),o.emit(e.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:e}=this;this.rotateData||(this.setPath(t),this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),e.emit(r.START,this.rotateData)),t.path=this.rotateData.path,e.emit(r.BEFORE_ROTATE,t),e.emit(r.ROTATE,t),this.transformEndWait()}setPath(t){const{interaction:e}=this,{path:o}=e.selector.getByPoint(t,e.hitRadius);t.path=o,e.cancelHover()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout(()=>{this.transformEnd()},this.interaction.p.transformTime)}transformEnd(){const{interaction:o,moveData:a,zoomData:i,rotateData:n}=this;a&&o.emit(t.END,a),i&&o.emit(e.END,i),n&&o.emit(r.END,n),this.reset()}reset(){this.zoomData=this.moveData=this.rotateData=null}destroy(){this.reset()}}const b=c.prototype,z=new m;function x(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function j(t,e){return Object.assign(Object.assign({},e),{scale:t})}b.initType=function(t){D.run(t,this)},b.getValidMove=function(t,e){const{scroll:o,disabled:a}=this.app.config.move;if(o){const a=!0===o?"":o;if(a.includes("x")?(t=t||e,e=0):a.includes("y")?(e=e||t,t=0):Math.abs(t)>Math.abs(e)?e=0:t=0,a.includes("limit")){const{x:o,y:a,width:i,height:n}=z.set(this.__world).addPoint(this.zoomLayer),s=o+i-this.width,r=a+n-this.height;o>=0&&s<=0?t=0:t>0?o+t>0&&(t=-o):t<0&&s+t<0&&(t=-s),a>=0&&r<=0?e=0:e>0?a+e>0&&(e=-a):e<0&&r+e<0&&(e=-r)}}return{x:a?0:t,y:a?0:e}},b.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:o,max:a,disabled:i}=this.app.config.zoom,n=Math.abs(e*t);return o&&n<o?t=o/e:a&&n>a&&(t=a/e),i?1:t};const R=h.prototype;R.createTransformer=function(){this.transformer=new E(this)},R.move=function(t){this.transformer.move(t)},R.zoom=function(t){this.transformer.zoom(t)},R.rotate=function(t){this.transformer.rotate(t)},R.transformEnd=function(){this.transformer.transformEnd()},R.wheel=function(t){const{wheel:e,pointer:o}=this.config,{posDeltaSpeed:a,negDeltaSpeed:n}=e;if(e.disabled)return;t.deltaX>0?a&&(t.deltaX*=a):n&&(t.deltaX*=n),t.deltaY>0?a&&(t.deltaY*=a):n&&(t.deltaY*=n);const s=e.getScale?e.getScale(t,e):T.getScale(t,e);if(1!==s)this.zoom(j(s,t));else{const a=e.getMove?e.getMove(t,e):T.getMove(t,e);o.snap&&i.round(a),this.move(x(a,t))}},R.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:i,center:n}=M.getData(e);Object.assign(t,n),t.multiTouch=!0,this.pointerWaitCancel(),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(j(i,t)),this.move(x(o,t))};const S=l.prototype,{abs:X}=Math;S.checkDragEndAnimate=function(t,e){const{moveX:o,moveY:a}=this.dragData,n=X(o),s=X(a),r=e?1:.1,c=this.canAnimate&&this.moving&&(n>r||s>r)&&this.interaction.m.dragAnimate;if(c){const r="touch"===t.pointerType?3:1,m=70;n*(e=e?u(c)?c:.95:r)>m?e=m/n:s*e>m&&(e=m/s),t=Object.assign({},t),i.move(t,o*e,a*e),this.drag(t),this.animate(()=>{this.dragEnd(t,1)})}return c},S.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},S.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},S.autoMoveOnDragOut=function(t){const{interaction:e,downData:o,canDragOut:a}=this,{autoDistance:n,dragOut:s}=e.m;if(!s||!a||!n)return;const r=e.shrinkCanvasBounds,{x:c,y:m}=r,h=d.maxX(r),l=d.maxY(r),u=t.x<c?n:h<t.x?-n:0,f=t.y<m?n:l<t.y?-n:0;let g=0,v=0;this.autoMoveTimer=setInterval(()=>{g+=u,v+=f,i.move(o,u,f),i.move(this.dragData,u,f),e.move(Object.assign(Object.assign({},t),{moveX:u,moveY:f,totalX:g,totalY:v,moveType:"drag"})),e.pointerMoveReal(t)},10)},S.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},f.add("viewport");export{D as LeaferTypeCreator,M as MultiTouchHelper,E as Transformer,T as WheelEventHelper,g as addViewport,v as addViewportConfig};
1
+ import{MoveEvent as t,LeafHelper as e,ZoomEvent as o,DataHelper as a,Debug as i,PointHelper as n,Platform as s,MathHelper as r,RotateEvent as c,Leafer as m,Bounds as h,Point as l,DragBoundsHelper as u,InteractionBase as d,Dragger as f,isNumber as g,BoundsHelper as v,Plugin as p}from"@leafer-ui/core";function D(a,i,n){y(a.parentApp?a.parentApp:a,i),a.isApp||n||a.__eventIds.push(a.on_(t.BEFORE_MOVE,t=>{a.zoomLayer.move(a.getValidMove(t.moveX,t.moveY,!1))}),a.on_(t.END,t=>{e.animateMove(a.zoomLayer,a.getValidMove(t.moveX,t.moveY))}),a.on_(o.BEFORE_ZOOM,t=>{const{zoomLayer:e}=a,o=a.getValidScale(t.scale);1!==o&&e.scaleOfWorld(t,o)}))}function y(t,e){const o={wheel:{preventDefault:!0},touch:{preventDefault:!0},pointer:{preventDefaultMenu:!0}};e&&a.assign(o,e),a.assign(t.config,o,t.userConfig)}const O=i.get("LeaferTypeCreator"),M={list:{},register(t,e){E[t]&&O.repeat(t),E[t]=e},run(t,e){const o=E[t];o&&o(e)}},{list:E,register:T}=M;T("viewport",D),T("custom",function(t){D(t,null,!0)}),T("design",function(t){D(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})}),T("document",function(t){D(t,{zoom:{min:1},move:{scroll:"limit"}})});const b={getData(t){const e=t[0],o=t[1],a=n.getCenter(e.from,o.from),i=n.getCenter(e.to,o.to),s={x:i.x-a.x,y:i.y-a.y},r=n.getDistance(e.from,o.from);return{move:s,scale:n.getDistance(e.to,o.to)/r,rotation:n.getRotation(e.from,o.from,e.to,o.to),center:i}}},x={getMove(t,e){let{moveSpeed:o}=e,{deltaX:a,deltaY:i}=t;return t.shiftKey&&!a&&(a=i,i=0),a>50&&(a=Math.max(50,a/3)),i>50&&(i=Math.max(50,i/3)),{x:-a*o*2,y:-i*o*2}},getScale(t,e){let o,a=1,{zoomMode:i,zoomSpeed:n}=e;const c=t.deltaY||t.deltaX;if(i?(o="mouse"===i||!t.deltaX&&(s.intWheelDeltaY?Math.abs(c)>17:Math.ceil(c)!==c),(t.shiftKey||t.metaKey||t.ctrlKey)&&(o=!0)):o=!t.shiftKey&&(t.metaKey||t.ctrlKey),o){n=r.within(n,0,1);a=1-c/(4*(t.deltaY?e.delta.y:e.delta.x))*n,a<.5&&(a=.5),a>=1.5&&(a=1.5)}return a}};class z{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(e){const{interaction:o}=this;e.moveType||(e.moveType="move"),this.moveData||(this.setPath(e),this.moveData=Object.assign(Object.assign({},e),{moveX:0,moveY:0}),o.emit(t.START,this.moveData)),e.path=this.moveData.path,o.emit(t.BEFORE_MOVE,e),o.emit(t.MOVE,e),this.transformEndWait()}zoom(t){const{interaction:e}=this;this.zoomData||(this.setPath(t),this.zoomData=Object.assign(Object.assign({},t),{scale:1}),e.emit(o.START,this.zoomData)),t.path=this.zoomData.path,e.emit(o.BEFORE_ZOOM,t),e.emit(o.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:e}=this;this.rotateData||(this.setPath(t),this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),e.emit(c.START,this.rotateData)),t.path=this.rotateData.path,e.emit(c.BEFORE_ROTATE,t),e.emit(c.ROTATE,t),this.transformEndWait()}setPath(t){const{interaction:e}=this,{path:o}=e.selector.getByPoint(t,e.hitRadius);t.path=o,e.cancelHover()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout(()=>{this.transformEnd()},this.interaction.p.transformTime)}transformEnd(){const{interaction:e,moveData:a,zoomData:i,rotateData:n}=this;a&&e.emit(t.END,a),i&&e.emit(o.END,i),n&&e.emit(c.END,n),this.reset()}reset(){this.zoomData=this.moveData=this.rotateData=null}destroy(){this.reset()}}const j=m.prototype,X=new h,Y=new l;function R(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function S(t,e){return Object.assign(Object.assign({},e),{scale:t})}j.initType=function(t){M.run(t,this)},j.getValidMove=function(t,e,o=!0){const{scroll:a,disabled:i}=this.app.config.move;if(Y.set(t,e),a){const t=!0===a?"":a;t.includes("x")?Y.y=0:t.includes("y")?Y.x=0:Math.abs(Y.x)>Math.abs(Y.y)?Y.y=0:Y.x=0,o&&t.includes("limit")&&(X.set(this.__world).addPoint(this.zoomLayer),u.getValidMove(X,this.canvas.bounds,"inner",Y,!0),t.includes("x")?Y.y=0:t.includes("y")&&(Y.x=0))}return{x:i?0:Y.x,y:i?0:Y.y}},j.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:o,max:a,disabled:i}=this.app.config.zoom,n=Math.abs(e*t);return o&&n<o?t=o/e:a&&n>a&&(t=a/e),i?1:t};const _=d.prototype;_.createTransformer=function(){this.transformer=new z(this)},_.move=function(t){this.transformer.move(t)},_.zoom=function(t){this.transformer.zoom(t)},_.rotate=function(t){this.transformer.rotate(t)},_.transformEnd=function(){this.transformer.transformEnd()},_.wheel=function(t){const{wheel:e,pointer:o}=this.config,{posDeltaSpeed:a,negDeltaSpeed:i}=e;if(e.disabled)return;t.deltaX>0?a&&(t.deltaX*=a):i&&(t.deltaX*=i),t.deltaY>0?a&&(t.deltaY*=a):i&&(t.deltaY*=i);const s=e.getScale?e.getScale(t,e):x.getScale(t,e);if(1!==s)this.zoom(S(s,t));else{const a=e.getMove?e.getMove(t,e):x.getMove(t,e);o.snap&&n.round(a),this.move(R(a,t))}},_.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:i,center:n}=b.getData(e);Object.assign(t,n),t.multiTouch=!0,this.pointerWaitCancel(),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(S(i,t)),this.move(R(o,t))};const w=f.prototype,{abs:A}=Math;w.checkDragEndAnimate=function(t,e){const{moveX:o,moveY:a}=this.dragData,i=A(o),s=A(a),r=e?1:.1,c=this.canAnimate&&this.moving&&(i>r||s>r)&&this.interaction.m.dragAnimate;if(c){const r="touch"===t.pointerType?3:1,m=70;i*(e=e?g(c)?c:.95:r)>m?e=m/i:s*e>m&&(e=m/s),t=Object.assign({},t),n.move(t,o*e,a*e),this.drag(t),this.animate(()=>{this.dragEnd(t,1)})}return c},w.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},w.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},w.autoMoveOnDragOut=function(t){const{interaction:e,downData:o,canDragOut:a}=this,{autoDistance:i,dragOut:s}=e.m;if(!s||!a||!i)return;const r=e.shrinkCanvasBounds,{x:c,y:m}=r,h=v.maxX(r),l=v.maxY(r),u=t.x<c?i:h<t.x?-i:0,d=t.y<m?i:l<t.y?-i:0;let f=0,g=0;this.autoMoveTimer=setInterval(()=>{f+=u,g+=d,n.move(o,u,d),n.move(this.dragData,u,d),e.move(Object.assign(Object.assign({},t),{moveX:u,moveY:d,totalX:f,totalY:g,moveType:"drag"})),e.pointerMoveReal(t)},10)},w.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},p.add("viewport");export{M as LeaferTypeCreator,b as MultiTouchHelper,z as Transformer,x as WheelEventHelper,D as addViewport,y as addViewportConfig};
2
2
  //# sourceMappingURL=viewport.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewport.esm.min.js","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)\n if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed\n if (scale < 0.5) scale = 0.5\n if (scale >= 1.5) scale = 1.5\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number): IPointData {\n const { scroll, disabled } = this.app.config.move\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) moveX = moveX || moveY, moveY = 0\n else if (type.includes('y')) moveY = moveY || moveX, moveX = 0\n else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0\n\n if (type.includes('limit')) {\n const { x, y, width, height } = bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n const right = x + width - this.width, bottom = y + height - this.height\n\n if (x >= 0 && right <= 0) moveX = 0 // includeX\n else if (moveX > 0) { if (x + moveX > 0) moveX = -x }\n else if (moveX < 0 && right + moveX < 0) moveX = -right\n\n if (y >= 0 && bottom <= 0) moveY = 0 // includeY\n else if (moveY > 0) { if (y + moveY > 0) moveY = -y }\n else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom\n }\n }\n return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","Math","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","abs","ceil","metaKey","ctrlKey","MathHelper","within","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","END","reset","destroy","Leafer","prototype","bounds","Bounds","getMoveEventData","getZoomEventData","initType","type","disabled","app","includes","width","height","set","__world","addPoint","right","bottom","scaleX","__","absScale","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","BoundsHelper","maxX","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"qQAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,EAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK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,GAAgBL,KACxBA,KAAKyF,iBACDzF,KAAK0F,WAAarF,EAAYsF,mBAAmBC,SAAStF,IAAON,KAAK6F,kBAAkBvF,EAChG,EAEA0D,EAAQ6B,kBAAoB,SAAUvF,GAClC,MAAMD,YAAEA,EAAWyF,SAAEA,EAAQC,WAAEA,GAAe/F,MACxCgG,aAAEA,EAAYC,QAAEA,GAAY5F,EAAYsE,EAC9C,IAAKsB,IAAYF,IAAeC,EAAc,OAE9C,MAAM7D,EAAS9B,EAAYsF,oBACrBvH,EAAEA,EAACC,EAAEA,GAAM8D,EACXc,EAAQiD,EAAaC,KAAKhE,GAC1Be,EAASgD,EAAaE,KAAKjE,GAE3B3G,EAAQ8E,EAAKlC,EAAIA,EAAI4H,EAAgB/C,EAAQ3C,EAAKlC,GAAK4H,EAAe,EACtEvK,EAAQ6E,EAAKjC,EAAIA,EAAI2H,EAAgB9C,EAAS5C,EAAKjC,GAAK2H,EAAe,EAC7E,IAAIK,EAAS,EAAGC,EAAS,EAEzBtG,KAAKuG,cAAgBC,YAAY,KAC7BH,GAAU7K,EACV8K,GAAU7K,EAEVsC,EAAYzC,KAAKwK,EAAUtK,EAAOC,GAClCsC,EAAYzC,KAAK0E,KAAKoE,SAAU5I,EAAOC,GAEvC4E,EAAY/E,KAAImF,OAAAlE,OAAAkE,OAAAlE,OAAA,GAAM+D,GAAI,CAAE9E,QAAOC,QAAO4K,SAAQC,SAAQ/F,SAAU,UACpEF,EAAYoG,gBAAgBnG,IAC7B,GACP,EAEA0D,EAAQyB,eAAiB,WACjBzF,KAAKuG,gBACLG,cAAc1G,KAAKuG,eACnBvG,KAAKuG,cAAgB,EAE7B,EC5DAI,EAAOC,IAAI"}
1
+ {"version":3,"file":"viewport.esm.min.js","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper, LeafHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false))\n }),\n leafer.on_(MoveEvent.END, (e: MoveEvent) => {\n LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)\n if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed\n if (scale < 0.5) scale = 0.5\n if (scale >= 1.5) scale = 1.5\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds, Point, DragBoundsHelper } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds(), move = new Point()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number, checkLimit = true): IPointData {\n const { scroll, disabled } = this.app.config.move\n move.set(moveX, moveY)\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0\n\n if (checkLimit && type.includes('limit')) {\n bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, 'inner', move, true)\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n }\n }\n\n return { x: disabled ? 0 : move.x, y: disabled ? 0 : move.y }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","END","LeafHelper","animateMove","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","Math","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","abs","ceil","metaKey","ctrlKey","MathHelper","within","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","reset","destroy","Leafer","prototype","bounds","Bounds","Point","getMoveEventData","getZoomEventData","initType","type","checkLimit","disabled","app","set","includes","__world","addPoint","DragBoundsHelper","canvas","scaleX","__","absScale","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","right","BoundsHelper","maxX","bottom","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"sTAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,EAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,OAAO,MAEhEhB,EAAOQ,IAAIC,EAAUQ,IAAMN,IACvBO,EAAWC,YAAYnB,EAAOY,UAAWZ,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,UAE5EhB,EAAOQ,IAAIY,EAAUC,YAAcV,IAC/B,MAAMC,UAAEA,GAAcZ,EAChBsB,EAActB,EAAOuB,cAAcZ,EAAEa,OACvB,IAAhBF,GAAmBV,EAAUa,aAAad,EAAGW,KAG7D,CAEM,SAAUnB,EAAkBH,EAAqBC,GACnD,MAAMyB,EAAgC,CAClCC,MAAO,CAAEC,gBAAgB,GACzBC,MAAO,CAAED,gBAAgB,GACzBE,QAAS,CAAEC,oBAAoB,IAE/B9B,GAAa+B,EAAWC,OAAOP,EAAgBzB,GACnD+B,EAAWC,OAAOjC,EAAOkC,OAAQR,EAAgB1B,EAAOmC,WAC5D,CCtBA,MAAMC,EAAQC,EAAMC,IAAI,qBAEXC,EAAoB,CAE7BC,KAAM,CAAA,EAEN,QAAAC,CAASC,EAAcC,GACnBH,EAAKE,IAASN,EAAMQ,OAAOF,GAC3BF,EAAKE,GAAQC,CACjB,EAEA,GAAAE,CAAIH,EAAc1C,GACd,MAAM2C,EAAKH,EAAKE,GAChBC,GAAMA,EAAG3C,EACb,IAIEwC,KAAEA,EAAIC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F,EAAYqG,gBAAgBpG,IAC7B,GACP,EAEAyD,EAAQyB,eAAiB,WACjBxF,KAAKwG,gBACLG,cAAc3G,KAAKwG,eACnBxG,KAAKwG,cAAgB,EAE7B,EC5DAI,EAAOC,IAAI"}
package/dist/viewport.js CHANGED
@@ -6,7 +6,9 @@ this.LeaferIN.viewport = function(exports, core) {
6
6
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
7
7
  if (leafer.isApp || custom) return;
8
8
  leafer.__eventIds.push(leafer.on_(core.MoveEvent.BEFORE_MOVE, e => {
9
- leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
9
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false));
10
+ }), leafer.on_(core.MoveEvent.END, e => {
11
+ core.LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY));
10
12
  }), leafer.on_(core.ZoomEvent.BEFORE_ZOOM, e => {
11
13
  const {zoomLayer: zoomLayer} = leafer;
12
14
  const changeScale = leafer.getValidScale(e.scale);
@@ -205,30 +207,25 @@ this.LeaferIN.viewport = function(exports, core) {
205
207
  }
206
208
  }
207
209
  const leafer = core.Leafer.prototype;
208
- const bounds = new core.Bounds;
210
+ const bounds = new core.Bounds, move = new core.Point;
209
211
  leafer.initType = function(type) {
210
212
  LeaferTypeCreator.run(type, this);
211
213
  };
212
- leafer.getValidMove = function(moveX, moveY) {
214
+ leafer.getValidMove = function(moveX, moveY, checkLimit = true) {
213
215
  const {scroll: scroll, disabled: disabled} = this.app.config.move;
216
+ move.set(moveX, moveY);
214
217
  if (scroll) {
215
218
  const type = scroll === true ? "" : scroll;
216
- if (type.includes("x")) moveX = moveX || moveY, moveY = 0; else if (type.includes("y")) moveY = moveY || moveX,
217
- moveX = 0; else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
218
- if (type.includes("limit")) {
219
- const {x: x, y: y, width: width, height: height} = bounds.set(this.__world).addPoint(this.zoomLayer);
220
- const right = x + width - this.width, bottom = y + height - this.height;
221
- if (x >= 0 && right <= 0) moveX = 0; else if (moveX > 0) {
222
- if (x + moveX > 0) moveX = -x;
223
- } else if (moveX < 0 && right + moveX < 0) moveX = -right;
224
- if (y >= 0 && bottom <= 0) moveY = 0; else if (moveY > 0) {
225
- if (y + moveY > 0) moveY = -y;
226
- } else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom;
219
+ if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0; else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0;
220
+ if (checkLimit && type.includes("limit")) {
221
+ bounds.set(this.__world).addPoint(this.zoomLayer);
222
+ core.DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, "inner", move, true);
223
+ if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0;
227
224
  }
228
225
  }
229
226
  return {
230
- x: disabled ? 0 : moveX,
231
- y: disabled ? 0 : moveY
227
+ x: disabled ? 0 : move.x,
228
+ y: disabled ? 0 : move.y
232
229
  };
233
230
  };
234
231
  leafer.getValidScale = function(changeScale) {
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@leafer-ui/core");function e(e,a,i){o(e.parentApp?e.parentApp:e,a),e.isApp||i||e.__eventIds.push(e.on_(t.MoveEvent.BEFORE_MOVE,t=>{e.zoomLayer.move(e.getValidMove(t.moveX,t.moveY))}),e.on_(t.ZoomEvent.BEFORE_ZOOM,t=>{const{zoomLayer:o}=e,a=e.getValidScale(t.scale);1!==a&&o.scaleOfWorld(t,a)}))}function o(e,o){const a={wheel:{preventDefault:!0},touch:{preventDefault:!0},pointer:{preventDefaultMenu:!0}};o&&t.DataHelper.assign(a,o),t.DataHelper.assign(e.config,a,e.userConfig)}const a=t.Debug.get("LeaferTypeCreator"),i={list:{},register(t,e){n[t]&&a.repeat(t),n[t]=e},run(t,e){const o=n[t];o&&o(e)}},{list:n,register:s}=i;s("viewport",e),s("custom",function(t){e(t,null,!0)}),s("design",function(t){e(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})}),s("document",function(t){e(t,{zoom:{min:1},move:{scroll:"limit"}})});const r={getData(e){const o=e[0],a=e[1],i=t.PointHelper.getCenter(o.from,a.from),n=t.PointHelper.getCenter(o.to,a.to),s={x:n.x-i.x,y:n.y-i.y},r=t.PointHelper.getDistance(o.from,a.from);return{move:s,scale:t.PointHelper.getDistance(o.to,a.to)/r,rotation:t.PointHelper.getRotation(o.from,a.from,o.to,a.to),center:n}}},c={getMove(t,e){let{moveSpeed:o}=e,{deltaX:a,deltaY:i}=t;return t.shiftKey&&!a&&(a=i,i=0),a>50&&(a=Math.max(50,a/3)),i>50&&(i=Math.max(50,i/3)),{x:-a*o*2,y:-i*o*2}},getScale(e,o){let a,i=1,{zoomMode:n,zoomSpeed:s}=o;const r=e.deltaY||e.deltaX;if(n?(a="mouse"===n||!e.deltaX&&(t.Platform.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(e.shiftKey||e.metaKey||e.ctrlKey)&&(a=!0)):a=!e.shiftKey&&(e.metaKey||e.ctrlKey),a){s=t.MathHelper.within(s,0,1);i=1-r/(4*(e.deltaY?o.delta.y:o.delta.x))*s,i<.5&&(i=.5),i>=1.5&&(i=1.5)}return i}};class m{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(e){const{interaction:o}=this;e.moveType||(e.moveType="move"),this.moveData||(this.setPath(e),this.moveData=Object.assign(Object.assign({},e),{moveX:0,moveY:0}),o.emit(t.MoveEvent.START,this.moveData)),e.path=this.moveData.path,o.emit(t.MoveEvent.BEFORE_MOVE,e),o.emit(t.MoveEvent.MOVE,e),this.transformEndWait()}zoom(e){const{interaction:o}=this;this.zoomData||(this.setPath(e),this.zoomData=Object.assign(Object.assign({},e),{scale:1}),o.emit(t.ZoomEvent.START,this.zoomData)),e.path=this.zoomData.path,o.emit(t.ZoomEvent.BEFORE_ZOOM,e),o.emit(t.ZoomEvent.ZOOM,e),this.transformEndWait()}rotate(e){const{interaction:o}=this;this.rotateData||(this.setPath(e),this.rotateData=Object.assign(Object.assign({},e),{rotation:0}),o.emit(t.RotateEvent.START,this.rotateData)),e.path=this.rotateData.path,o.emit(t.RotateEvent.BEFORE_ROTATE,e),o.emit(t.RotateEvent.ROTATE,e),this.transformEndWait()}setPath(t){const{interaction:e}=this,{path:o}=e.selector.getByPoint(t,e.hitRadius);t.path=o,e.cancelHover()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout(()=>{this.transformEnd()},this.interaction.p.transformTime)}transformEnd(){const{interaction:e,moveData:o,zoomData:a,rotateData:i}=this;o&&e.emit(t.MoveEvent.END,o),a&&e.emit(t.ZoomEvent.END,a),i&&e.emit(t.RotateEvent.END,i),this.reset()}reset(){this.zoomData=this.moveData=this.rotateData=null}destroy(){this.reset()}}const h=t.Leafer.prototype,l=new t.Bounds;function u(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function v(t,e){return Object.assign(Object.assign({},e),{scale:t})}h.initType=function(t){i.run(t,this)},h.getValidMove=function(t,e){const{scroll:o,disabled:a}=this.app.config.move;if(o){const a=!0===o?"":o;if(a.includes("x")?(t=t||e,e=0):a.includes("y")?(e=e||t,t=0):Math.abs(t)>Math.abs(e)?e=0:t=0,a.includes("limit")){const{x:o,y:a,width:i,height:n}=l.set(this.__world).addPoint(this.zoomLayer),s=o+i-this.width,r=a+n-this.height;o>=0&&s<=0?t=0:t>0?o+t>0&&(t=-o):t<0&&s+t<0&&(t=-s),a>=0&&r<=0?e=0:e>0?a+e>0&&(e=-a):e<0&&r+e<0&&(e=-r)}}return{x:a?0:t,y:a?0:e}},h.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:o,max:a,disabled:i}=this.app.config.zoom,n=Math.abs(e*t);return o&&n<o?t=o/e:a&&n>a&&(t=a/e),i?1:t};const d=t.InteractionBase.prototype;d.createTransformer=function(){this.transformer=new m(this)},d.move=function(t){this.transformer.move(t)},d.zoom=function(t){this.transformer.zoom(t)},d.rotate=function(t){this.transformer.rotate(t)},d.transformEnd=function(){this.transformer.transformEnd()},d.wheel=function(e){const{wheel:o,pointer:a}=this.config,{posDeltaSpeed:i,negDeltaSpeed:n}=o;if(o.disabled)return;e.deltaX>0?i&&(e.deltaX*=i):n&&(e.deltaX*=n),e.deltaY>0?i&&(e.deltaY*=i):n&&(e.deltaY*=n);const s=o.getScale?o.getScale(e,o):c.getScale(e,o);if(1!==s)this.zoom(v(s,e));else{const i=o.getMove?o.getMove(e,o):c.getMove(e,o);a.snap&&t.PointHelper.round(i),this.move(u(i,e))}},d.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:i,center:n}=r.getData(e);Object.assign(t,n),t.multiTouch=!0,this.pointerWaitCancel(),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(v(i,t)),this.move(u(o,t))};const p=t.Dragger.prototype,{abs:f}=Math;p.checkDragEndAnimate=function(e,o){const{moveX:a,moveY:i}=this.dragData,n=f(a),s=f(i),r=o?1:.1,c=this.canAnimate&&this.moving&&(n>r||s>r)&&this.interaction.m.dragAnimate;if(c){const r="touch"===e.pointerType?3:1,m=70;n*(o=o?t.isNumber(c)?c:.95:r)>m?o=m/n:s*o>m&&(o=m/s),e=Object.assign({},e),t.PointHelper.move(e,a*o,i*o),this.drag(e),this.animate(()=>{this.dragEnd(e,1)})}return c},p.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},p.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},p.autoMoveOnDragOut=function(e){const{interaction:o,downData:a,canDragOut:i}=this,{autoDistance:n,dragOut:s}=o.m;if(!s||!i||!n)return;const r=o.shrinkCanvasBounds,{x:c,y:m}=r,h=t.BoundsHelper.maxX(r),l=t.BoundsHelper.maxY(r),u=e.x<c?n:h<e.x?-n:0,v=e.y<m?n:l<e.y?-n:0;let d=0,p=0;this.autoMoveTimer=setInterval(()=>{d+=u,p+=v,t.PointHelper.move(a,u,v),t.PointHelper.move(this.dragData,u,v),o.move(Object.assign(Object.assign({},e),{moveX:u,moveY:v,totalX:d,totalY:p,moveType:"drag"})),o.pointerMoveReal(e)},10)},p.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},t.Plugin.add("viewport"),exports.LeaferTypeCreator=i,exports.MultiTouchHelper=r,exports.Transformer=m,exports.WheelEventHelper=c,exports.addViewport=e,exports.addViewportConfig=o;
1
+ "use strict";var t=require("@leafer-ui/core");function e(e,a,n){o(e.parentApp?e.parentApp:e,a),e.isApp||n||e.__eventIds.push(e.on_(t.MoveEvent.BEFORE_MOVE,t=>{e.zoomLayer.move(e.getValidMove(t.moveX,t.moveY,!1))}),e.on_(t.MoveEvent.END,o=>{t.LeafHelper.animateMove(e.zoomLayer,e.getValidMove(o.moveX,o.moveY))}),e.on_(t.ZoomEvent.BEFORE_ZOOM,t=>{const{zoomLayer:o}=e,a=e.getValidScale(t.scale);1!==a&&o.scaleOfWorld(t,a)}))}function o(e,o){const a={wheel:{preventDefault:!0},touch:{preventDefault:!0},pointer:{preventDefaultMenu:!0}};o&&t.DataHelper.assign(a,o),t.DataHelper.assign(e.config,a,e.userConfig)}const a=t.Debug.get("LeaferTypeCreator"),n={list:{},register(t,e){i[t]&&a.repeat(t),i[t]=e},run(t,e){const o=i[t];o&&o(e)}},{list:i,register:s}=n;s("viewport",e),s("custom",function(t){e(t,null,!0)}),s("design",function(t){e(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})}),s("document",function(t){e(t,{zoom:{min:1},move:{scroll:"limit"}})});const r={getData(e){const o=e[0],a=e[1],n=t.PointHelper.getCenter(o.from,a.from),i=t.PointHelper.getCenter(o.to,a.to),s={x:i.x-n.x,y:i.y-n.y},r=t.PointHelper.getDistance(o.from,a.from);return{move:s,scale:t.PointHelper.getDistance(o.to,a.to)/r,rotation:t.PointHelper.getRotation(o.from,a.from,o.to,a.to),center:i}}},m={getMove(t,e){let{moveSpeed:o}=e,{deltaX:a,deltaY:n}=t;return t.shiftKey&&!a&&(a=n,n=0),a>50&&(a=Math.max(50,a/3)),n>50&&(n=Math.max(50,n/3)),{x:-a*o*2,y:-n*o*2}},getScale(e,o){let a,n=1,{zoomMode:i,zoomSpeed:s}=o;const r=e.deltaY||e.deltaX;if(i?(a="mouse"===i||!e.deltaX&&(t.Platform.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(e.shiftKey||e.metaKey||e.ctrlKey)&&(a=!0)):a=!e.shiftKey&&(e.metaKey||e.ctrlKey),a){s=t.MathHelper.within(s,0,1);n=1-r/(4*(e.deltaY?o.delta.y:o.delta.x))*s,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}};class c{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(e){const{interaction:o}=this;e.moveType||(e.moveType="move"),this.moveData||(this.setPath(e),this.moveData=Object.assign(Object.assign({},e),{moveX:0,moveY:0}),o.emit(t.MoveEvent.START,this.moveData)),e.path=this.moveData.path,o.emit(t.MoveEvent.BEFORE_MOVE,e),o.emit(t.MoveEvent.MOVE,e),this.transformEndWait()}zoom(e){const{interaction:o}=this;this.zoomData||(this.setPath(e),this.zoomData=Object.assign(Object.assign({},e),{scale:1}),o.emit(t.ZoomEvent.START,this.zoomData)),e.path=this.zoomData.path,o.emit(t.ZoomEvent.BEFORE_ZOOM,e),o.emit(t.ZoomEvent.ZOOM,e),this.transformEndWait()}rotate(e){const{interaction:o}=this;this.rotateData||(this.setPath(e),this.rotateData=Object.assign(Object.assign({},e),{rotation:0}),o.emit(t.RotateEvent.START,this.rotateData)),e.path=this.rotateData.path,o.emit(t.RotateEvent.BEFORE_ROTATE,e),o.emit(t.RotateEvent.ROTATE,e),this.transformEndWait()}setPath(t){const{interaction:e}=this,{path:o}=e.selector.getByPoint(t,e.hitRadius);t.path=o,e.cancelHover()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout(()=>{this.transformEnd()},this.interaction.p.transformTime)}transformEnd(){const{interaction:e,moveData:o,zoomData:a,rotateData:n}=this;o&&e.emit(t.MoveEvent.END,o),a&&e.emit(t.ZoomEvent.END,a),n&&e.emit(t.RotateEvent.END,n),this.reset()}reset(){this.zoomData=this.moveData=this.rotateData=null}destroy(){this.reset()}}const h=t.Leafer.prototype,l=new t.Bounds,u=new t.Point;function v(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function d(t,e){return Object.assign(Object.assign({},e),{scale:t})}h.initType=function(t){n.run(t,this)},h.getValidMove=function(e,o,a=!0){const{scroll:n,disabled:i}=this.app.config.move;if(u.set(e,o),n){const e=!0===n?"":n;e.includes("x")?u.y=0:e.includes("y")?u.x=0:Math.abs(u.x)>Math.abs(u.y)?u.y=0:u.x=0,a&&e.includes("limit")&&(l.set(this.__world).addPoint(this.zoomLayer),t.DragBoundsHelper.getValidMove(l,this.canvas.bounds,"inner",u,!0),e.includes("x")?u.y=0:e.includes("y")&&(u.x=0))}return{x:i?0:u.x,y:i?0:u.y}},h.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:o,max:a,disabled:n}=this.app.config.zoom,i=Math.abs(e*t);return o&&i<o?t=o/e:a&&i>a&&(t=a/e),n?1:t};const p=t.InteractionBase.prototype;p.createTransformer=function(){this.transformer=new c(this)},p.move=function(t){this.transformer.move(t)},p.zoom=function(t){this.transformer.zoom(t)},p.rotate=function(t){this.transformer.rotate(t)},p.transformEnd=function(){this.transformer.transformEnd()},p.wheel=function(e){const{wheel:o,pointer:a}=this.config,{posDeltaSpeed:n,negDeltaSpeed:i}=o;if(o.disabled)return;e.deltaX>0?n&&(e.deltaX*=n):i&&(e.deltaX*=i),e.deltaY>0?n&&(e.deltaY*=n):i&&(e.deltaY*=i);const s=o.getScale?o.getScale(e,o):m.getScale(e,o);if(1!==s)this.zoom(d(s,e));else{const n=o.getMove?o.getMove(e,o):m.getMove(e,o);a.snap&&t.PointHelper.round(n),this.move(v(n,e))}},p.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:n,center:i}=r.getData(e);Object.assign(t,i),t.multiTouch=!0,this.pointerWaitCancel(),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(d(n,t)),this.move(v(o,t))};const g=t.Dragger.prototype,{abs:f}=Math;g.checkDragEndAnimate=function(e,o){const{moveX:a,moveY:n}=this.dragData,i=f(a),s=f(n),r=o?1:.1,m=this.canAnimate&&this.moving&&(i>r||s>r)&&this.interaction.m.dragAnimate;if(m){const r="touch"===e.pointerType?3:1,c=70;i*(o=o?t.isNumber(m)?m:.95:r)>c?o=c/i:s*o>c&&(o=c/s),e=Object.assign({},e),t.PointHelper.move(e,a*o,n*o),this.drag(e),this.animate(()=>{this.dragEnd(e,1)})}return m},g.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},g.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},g.autoMoveOnDragOut=function(e){const{interaction:o,downData:a,canDragOut:n}=this,{autoDistance:i,dragOut:s}=o.m;if(!s||!n||!i)return;const r=o.shrinkCanvasBounds,{x:m,y:c}=r,h=t.BoundsHelper.maxX(r),l=t.BoundsHelper.maxY(r),u=e.x<m?i:h<e.x?-i:0,v=e.y<c?i:l<e.y?-i:0;let d=0,p=0;this.autoMoveTimer=setInterval(()=>{d+=u,p+=v,t.PointHelper.move(a,u,v),t.PointHelper.move(this.dragData,u,v),o.move(Object.assign(Object.assign({},e),{moveX:u,moveY:v,totalX:d,totalY:p,moveType:"drag"})),o.pointerMoveReal(e)},10)},g.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},t.Plugin.add("viewport"),exports.LeaferTypeCreator=n,exports.MultiTouchHelper=r,exports.Transformer=c,exports.WheelEventHelper=m,exports.addViewport=e,exports.addViewportConfig=o;
2
2
  //# sourceMappingURL=viewport.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewport.min.cjs","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)\n if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed\n if (scale < 0.5) scale = 0.5\n if (scale >= 1.5) scale = 1.5\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number): IPointData {\n const { scroll, disabled } = this.app.config.move\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) moveX = moveX || moveY, moveY = 0\n else if (type.includes('y')) moveY = moveY || moveX, moveX = 0\n else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0\n\n if (type.includes('limit')) {\n const { x, y, width, height } = bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n const right = x + width - this.width, bottom = y + height - this.height\n\n if (x >= 0 && right <= 0) moveX = 0 // includeX\n else if (moveX > 0) { if (x + moveX > 0) moveX = -x }\n else if (moveX < 0 && right + moveX < 0) moveX = -right\n\n if (y >= 0 && bottom <= 0) moveY = 0 // includeY\n else if (moveY > 0) { if (y + moveY > 0) moveY = -y }\n else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom\n }\n }\n return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","Math","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","abs","ceil","metaKey","ctrlKey","MathHelper","within","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","END","reset","destroy","Leafer","prototype","bounds","Bounds","getMoveEventData","getZoomEventData","initType","type","disabled","app","includes","width","height","set","__world","addPoint","right","bottom","scaleX","__","absScale","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","BoundsHelper","maxX","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"uDAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,YAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,UAEzDhB,EAAOQ,IAAIS,EAAAA,UAAUC,YAAcP,IAC/B,MAAMC,UAAEA,GAAcZ,EAChBmB,EAAcnB,EAAOoB,cAAcT,EAAEU,OACvB,IAAhBF,GAAmBP,EAAUU,aAAaX,EAAGQ,KAG7D,CAEM,SAAUhB,EAAkBH,EAAqBC,GACnD,MAAMsB,EAAgC,CAClCC,MAAO,CAAEC,gBAAgB,GACzBC,MAAO,CAAED,gBAAgB,GACzBE,QAAS,CAAEC,oBAAoB,IAE/B3B,GAAa4B,aAAWC,OAAOP,EAAgBtB,GACnD4B,EAAAA,WAAWC,OAAO9B,EA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AAYsE,EAC9C,IAAKsB,IAAYF,IAAeC,EAAc,OAE9C,MAAM7D,EAAS9B,EAAYsF,oBACrBvH,EAAEA,EAACC,EAAEA,GAAM8D,EACXc,EAAQiD,EAAAA,aAAaC,KAAKhE,GAC1Be,EAASgD,EAAAA,aAAaE,KAAKjE,GAE3B3G,EAAQ8E,EAAKlC,EAAIA,EAAI4H,EAAgB/C,EAAQ3C,EAAKlC,GAAK4H,EAAe,EACtEvK,EAAQ6E,EAAKjC,EAAIA,EAAI2H,EAAgB9C,EAAS5C,EAAKjC,GAAK2H,EAAe,EAC7E,IAAIK,EAAS,EAAGC,EAAS,EAEzBtG,KAAKuG,cAAgBC,YAAY,KAC7BH,GAAU7K,EACV8K,GAAU7K,EAEVsC,EAAAA,YAAYzC,KAAKwK,EAAUtK,EAAOC,GAClCsC,EAAAA,YAAYzC,KAAK0E,KAAKoE,SAAU5I,EAAOC,GAEvC4E,EAAY/E,KAAImF,OAAAlE,OAAAkE,OAAAlE,OAAA,GAAM+D,GAAI,CAAE9E,QAAOC,QAAO4K,SAAQC,SAAQ/F,SAAU,UACpEF,EAAYoG,gBAAgBnG,IAC7B,GACP,EAEA0D,EAAQyB,eAAiB,WACjBzF,KAAKuG,gBACLG,cAAc1G,KAAKuG,eACnBvG,KAAKuG,cAAgB,EAE7B,EC5DAI,EAAAA,OAAOC,IAAI"}
1
+ {"version":3,"file":"viewport.min.cjs","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper, LeafHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false))\n }),\n leafer.on_(MoveEvent.END, (e: MoveEvent) => {\n LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)\n if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed\n if (scale < 0.5) scale = 0.5\n if (scale >= 1.5) scale = 1.5\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds, Point, DragBoundsHelper } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds(), move = new Point()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number, checkLimit = true): IPointData {\n const { scroll, disabled } = this.app.config.move\n move.set(moveX, moveY)\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0\n\n if (checkLimit && type.includes('limit')) {\n bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, 'inner', move, true)\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n }\n }\n\n return { x: disabled ? 0 : move.x, y: disabled ? 0 : move.y }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","END","LeafHelper","animateMove","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","Math","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","abs","ceil","metaKey","ctrlKey","MathHelper","within","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","reset","destroy","Leafer","prototype","bounds","Bounds","Point","getMoveEventData","getZoomEventData","initType","type","checkLimit","disabled","app","set","includes","__world","addPoint","DragBoundsHelper","canvas","scaleX","__","absScale","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","right","BoundsHelper","maxX","bottom","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"uDAK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qG,gBAAgBpG,IAC7B,GACP,EAEAyD,EAAQyB,eAAiB,WACjBxF,KAAKwG,gBACLG,cAAc3G,KAAKwG,eACnBxG,KAAKwG,cAAgB,EAE7B,EC5DAI,EAAAA,OAAOC,IAAI"}
@@ -1,2 +1,2 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.viewport=function(t,e){"use strict";function o(t,o,i){a(t.parentApp?t.parentApp:t,o),t.isApp||i||t.__eventIds.push(t.on_(e.MoveEvent.BEFORE_MOVE,e=>{t.zoomLayer.move(t.getValidMove(e.moveX,e.moveY))}),t.on_(e.ZoomEvent.BEFORE_ZOOM,e=>{const{zoomLayer:o}=t,a=t.getValidScale(e.scale);1!==a&&o.scaleOfWorld(e,a)}))}function a(t,o){const a={wheel:{preventDefault:!0},touch:{preventDefault:!0},pointer:{preventDefaultMenu:!0}};o&&e.DataHelper.assign(a,o),e.DataHelper.assign(t.config,a,t.userConfig)}const i=e.Debug.get("LeaferTypeCreator"),n={list:{},register(t,e){s[t]&&i.repeat(t),s[t]=e},run(t,e){const o=s[t];o&&o(e)}},{list:s,register:r}=n;r("viewport",o),r("custom",function(t){o(t,null,!0)}),r("design",function(t){o(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})}),r("document",function(t){o(t,{zoom:{min:1},move:{scroll:"limit"}})});const c={getData(t){const o=t[0],a=t[1],i=e.PointHelper.getCenter(o.from,a.from),n=e.PointHelper.getCenter(o.to,a.to),s={x:n.x-i.x,y:n.y-i.y},r=e.PointHelper.getDistance(o.from,a.from);return{move:s,scale:e.PointHelper.getDistance(o.to,a.to)/r,rotation:e.PointHelper.getRotation(o.from,a.from,o.to,a.to),center:n}}},m={getMove(t,e){let{moveSpeed:o}=e,{deltaX:a,deltaY:i}=t;return t.shiftKey&&!a&&(a=i,i=0),a>50&&(a=Math.max(50,a/3)),i>50&&(i=Math.max(50,i/3)),{x:-a*o*2,y:-i*o*2}},getScale(t,o){let a,i=1,{zoomMode:n,zoomSpeed:s}=o;const r=t.deltaY||t.deltaX;if(n?(a="mouse"===n||!t.deltaX&&(e.Platform.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(t.shiftKey||t.metaKey||t.ctrlKey)&&(a=!0)):a=!t.shiftKey&&(t.metaKey||t.ctrlKey),a){s=e.MathHelper.within(s,0,1);i=1-r/(4*(t.deltaY?o.delta.y:o.delta.x))*s,i<.5&&(i=.5),i>=1.5&&(i=1.5)}return i}};class h{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(t){const{interaction:o}=this;t.moveType||(t.moveType="move"),this.moveData||(this.setPath(t),this.moveData=Object.assign(Object.assign({},t),{moveX:0,moveY:0}),o.emit(e.MoveEvent.START,this.moveData)),t.path=this.moveData.path,o.emit(e.MoveEvent.BEFORE_MOVE,t),o.emit(e.MoveEvent.MOVE,t),this.transformEndWait()}zoom(t){const{interaction:o}=this;this.zoomData||(this.setPath(t),this.zoomData=Object.assign(Object.assign({},t),{scale:1}),o.emit(e.ZoomEvent.START,this.zoomData)),t.path=this.zoomData.path,o.emit(e.ZoomEvent.BEFORE_ZOOM,t),o.emit(e.ZoomEvent.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:o}=this;this.rotateData||(this.setPath(t),this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),o.emit(e.RotateEvent.START,this.rotateData)),t.path=this.rotateData.path,o.emit(e.RotateEvent.BEFORE_ROTATE,t),o.emit(e.RotateEvent.ROTATE,t),this.transformEndWait()}setPath(t){const{interaction:e}=this,{path:o}=e.selector.getByPoint(t,e.hitRadius);t.path=o,e.cancelHover()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout(()=>{this.transformEnd()},this.interaction.p.transformTime)}transformEnd(){const{interaction:t,moveData:o,zoomData:a,rotateData:i}=this;o&&t.emit(e.MoveEvent.END,o),a&&t.emit(e.ZoomEvent.END,a),i&&t.emit(e.RotateEvent.END,i),this.reset()}reset(){this.zoomData=this.moveData=this.rotateData=null}destroy(){this.reset()}}const l=e.Leafer.prototype,u=new e.Bounds;function v(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function d(t,e){return Object.assign(Object.assign({},e),{scale:t})}l.initType=function(t){n.run(t,this)},l.getValidMove=function(t,e){const{scroll:o,disabled:a}=this.app.config.move;if(o){const a=!0===o?"":o;if(a.includes("x")?(t=t||e,e=0):a.includes("y")?(e=e||t,t=0):Math.abs(t)>Math.abs(e)?e=0:t=0,a.includes("limit")){const{x:o,y:a,width:i,height:n}=u.set(this.__world).addPoint(this.zoomLayer),s=o+i-this.width,r=a+n-this.height;o>=0&&s<=0?t=0:t>0?o+t>0&&(t=-o):t<0&&s+t<0&&(t=-s),a>=0&&r<=0?e=0:e>0?a+e>0&&(e=-a):e<0&&r+e<0&&(e=-r)}}return{x:a?0:t,y:a?0:e}},l.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:o,max:a,disabled:i}=this.app.config.zoom,n=Math.abs(e*t);return o&&n<o?t=o/e:a&&n>a&&(t=a/e),i?1:t};const f=e.InteractionBase.prototype;f.createTransformer=function(){this.transformer=new h(this)},f.move=function(t){this.transformer.move(t)},f.zoom=function(t){this.transformer.zoom(t)},f.rotate=function(t){this.transformer.rotate(t)},f.transformEnd=function(){this.transformer.transformEnd()},f.wheel=function(t){const{wheel:o,pointer:a}=this.config,{posDeltaSpeed:i,negDeltaSpeed:n}=o;if(o.disabled)return;t.deltaX>0?i&&(t.deltaX*=i):n&&(t.deltaX*=n),t.deltaY>0?i&&(t.deltaY*=i):n&&(t.deltaY*=n);const s=o.getScale?o.getScale(t,o):m.getScale(t,o);if(1!==s)this.zoom(d(s,t));else{const i=o.getMove?o.getMove(t,o):m.getMove(t,o);a.snap&&e.PointHelper.round(i),this.move(v(i,t))}},f.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:i,center:n}=c.getData(e);Object.assign(t,n),t.multiTouch=!0,this.pointerWaitCancel(),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(d(i,t)),this.move(v(o,t))};const g=e.Dragger.prototype,{abs:p}=Math;return g.checkDragEndAnimate=function(t,o){const{moveX:a,moveY:i}=this.dragData,n=p(a),s=p(i),r=o?1:.1,c=this.canAnimate&&this.moving&&(n>r||s>r)&&this.interaction.m.dragAnimate;if(c){const r="touch"===t.pointerType?3:1,m=70;n*(o=o?e.isNumber(c)?c:.95:r)>m?o=m/n:s*o>m&&(o=m/s),t=Object.assign({},t),e.PointHelper.move(t,a*o,i*o),this.drag(t),this.animate(()=>{this.dragEnd(t,1)})}return c},g.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},g.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},g.autoMoveOnDragOut=function(t){const{interaction:o,downData:a,canDragOut:i}=this,{autoDistance:n,dragOut:s}=o.m;if(!s||!i||!n)return;const r=o.shrinkCanvasBounds,{x:c,y:m}=r,h=e.BoundsHelper.maxX(r),l=e.BoundsHelper.maxY(r),u=t.x<c?n:h<t.x?-n:0,v=t.y<m?n:l<t.y?-n:0;let d=0,f=0;this.autoMoveTimer=setInterval(()=>{d+=u,f+=v,e.PointHelper.move(a,u,v),e.PointHelper.move(this.dragData,u,v),o.move(Object.assign(Object.assign({},t),{moveX:u,moveY:v,totalX:d,totalY:f,moveType:"drag"})),o.pointerMoveReal(t)},10)},g.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},e.Plugin.add("viewport"),t.LeaferTypeCreator=n,t.MultiTouchHelper=c,t.Transformer=h,t.WheelEventHelper=m,t.addViewport=o,t.addViewportConfig=a,t}({},LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.viewport=function(t,e){"use strict";function o(t,o,n){a(t.parentApp?t.parentApp:t,o),t.isApp||n||t.__eventIds.push(t.on_(e.MoveEvent.BEFORE_MOVE,e=>{t.zoomLayer.move(t.getValidMove(e.moveX,e.moveY,!1))}),t.on_(e.MoveEvent.END,o=>{e.LeafHelper.animateMove(t.zoomLayer,t.getValidMove(o.moveX,o.moveY))}),t.on_(e.ZoomEvent.BEFORE_ZOOM,e=>{const{zoomLayer:o}=t,a=t.getValidScale(e.scale);1!==a&&o.scaleOfWorld(e,a)}))}function a(t,o){const a={wheel:{preventDefault:!0},touch:{preventDefault:!0},pointer:{preventDefaultMenu:!0}};o&&e.DataHelper.assign(a,o),e.DataHelper.assign(t.config,a,t.userConfig)}const n=e.Debug.get("LeaferTypeCreator"),i={list:{},register(t,e){s[t]&&n.repeat(t),s[t]=e},run(t,e){const o=s[t];o&&o(e)}},{list:s,register:r}=i;r("viewport",o),r("custom",function(t){o(t,null,!0)}),r("design",function(t){o(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})}),r("document",function(t){o(t,{zoom:{min:1},move:{scroll:"limit"}})});const m={getData(t){const o=t[0],a=t[1],n=e.PointHelper.getCenter(o.from,a.from),i=e.PointHelper.getCenter(o.to,a.to),s={x:i.x-n.x,y:i.y-n.y},r=e.PointHelper.getDistance(o.from,a.from);return{move:s,scale:e.PointHelper.getDistance(o.to,a.to)/r,rotation:e.PointHelper.getRotation(o.from,a.from,o.to,a.to),center:i}}},c={getMove(t,e){let{moveSpeed:o}=e,{deltaX:a,deltaY:n}=t;return t.shiftKey&&!a&&(a=n,n=0),a>50&&(a=Math.max(50,a/3)),n>50&&(n=Math.max(50,n/3)),{x:-a*o*2,y:-n*o*2}},getScale(t,o){let a,n=1,{zoomMode:i,zoomSpeed:s}=o;const r=t.deltaY||t.deltaX;if(i?(a="mouse"===i||!t.deltaX&&(e.Platform.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(t.shiftKey||t.metaKey||t.ctrlKey)&&(a=!0)):a=!t.shiftKey&&(t.metaKey||t.ctrlKey),a){s=e.MathHelper.within(s,0,1);n=1-r/(4*(t.deltaY?o.delta.y:o.delta.x))*s,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}};class h{get transforming(){return!!(this.moveData||this.zoomData||this.rotateData)}constructor(t){this.interaction=t}move(t){const{interaction:o}=this;t.moveType||(t.moveType="move"),this.moveData||(this.setPath(t),this.moveData=Object.assign(Object.assign({},t),{moveX:0,moveY:0}),o.emit(e.MoveEvent.START,this.moveData)),t.path=this.moveData.path,o.emit(e.MoveEvent.BEFORE_MOVE,t),o.emit(e.MoveEvent.MOVE,t),this.transformEndWait()}zoom(t){const{interaction:o}=this;this.zoomData||(this.setPath(t),this.zoomData=Object.assign(Object.assign({},t),{scale:1}),o.emit(e.ZoomEvent.START,this.zoomData)),t.path=this.zoomData.path,o.emit(e.ZoomEvent.BEFORE_ZOOM,t),o.emit(e.ZoomEvent.ZOOM,t),this.transformEndWait()}rotate(t){const{interaction:o}=this;this.rotateData||(this.setPath(t),this.rotateData=Object.assign(Object.assign({},t),{rotation:0}),o.emit(e.RotateEvent.START,this.rotateData)),t.path=this.rotateData.path,o.emit(e.RotateEvent.BEFORE_ROTATE,t),o.emit(e.RotateEvent.ROTATE,t),this.transformEndWait()}setPath(t){const{interaction:e}=this,{path:o}=e.selector.getByPoint(t,e.hitRadius);t.path=o,e.cancelHover()}transformEndWait(){clearTimeout(this.transformTimer),this.transformTimer=setTimeout(()=>{this.transformEnd()},this.interaction.p.transformTime)}transformEnd(){const{interaction:t,moveData:o,zoomData:a,rotateData:n}=this;o&&t.emit(e.MoveEvent.END,o),a&&t.emit(e.ZoomEvent.END,a),n&&t.emit(e.RotateEvent.END,n),this.reset()}reset(){this.zoomData=this.moveData=this.rotateData=null}destroy(){this.reset()}}const l=e.Leafer.prototype,u=new e.Bounds,v=new e.Point;function d(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function f(t,e){return Object.assign(Object.assign({},e),{scale:t})}l.initType=function(t){i.run(t,this)},l.getValidMove=function(t,o,a=!0){const{scroll:n,disabled:i}=this.app.config.move;if(v.set(t,o),n){const t=!0===n?"":n;t.includes("x")?v.y=0:t.includes("y")?v.x=0:Math.abs(v.x)>Math.abs(v.y)?v.y=0:v.x=0,a&&t.includes("limit")&&(u.set(this.__world).addPoint(this.zoomLayer),e.DragBoundsHelper.getValidMove(u,this.canvas.bounds,"inner",v,!0),t.includes("x")?v.y=0:t.includes("y")&&(v.x=0))}return{x:i?0:v.x,y:i?0:v.y}},l.getValidScale=function(t){const{scaleX:e}=this.zoomLayer.__,{min:o,max:a,disabled:n}=this.app.config.zoom,i=Math.abs(e*t);return o&&i<o?t=o/e:a&&i>a&&(t=a/e),n?1:t};const g=e.InteractionBase.prototype;g.createTransformer=function(){this.transformer=new h(this)},g.move=function(t){this.transformer.move(t)},g.zoom=function(t){this.transformer.zoom(t)},g.rotate=function(t){this.transformer.rotate(t)},g.transformEnd=function(){this.transformer.transformEnd()},g.wheel=function(t){const{wheel:o,pointer:a}=this.config,{posDeltaSpeed:n,negDeltaSpeed:i}=o;if(o.disabled)return;t.deltaX>0?n&&(t.deltaX*=n):i&&(t.deltaX*=i),t.deltaY>0?n&&(t.deltaY*=n):i&&(t.deltaY*=i);const s=o.getScale?o.getScale(t,o):c.getScale(t,o);if(1!==s)this.zoom(f(s,t));else{const n=o.getMove?o.getMove(t,o):c.getMove(t,o);a.snap&&e.PointHelper.round(n),this.move(d(n,t))}},g.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:n,center:i}=m.getData(e);Object.assign(t,i),t.multiTouch=!0,this.pointerWaitCancel(),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(f(n,t)),this.move(d(o,t))};const p=e.Dragger.prototype,{abs:D}=Math;return p.checkDragEndAnimate=function(t,o){const{moveX:a,moveY:n}=this.dragData,i=D(a),s=D(n),r=o?1:.1,m=this.canAnimate&&this.moving&&(i>r||s>r)&&this.interaction.m.dragAnimate;if(m){const r="touch"===t.pointerType?3:1,c=70;i*(o=o?e.isNumber(m)?m:.95:r)>c?o=c/i:s*o>c&&(o=c/s),t=Object.assign({},t),e.PointHelper.move(t,a*o,n*o),this.drag(t),this.animate(()=>{this.dragEnd(t,1)})}return m},p.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},p.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},p.autoMoveOnDragOut=function(t){const{interaction:o,downData:a,canDragOut:n}=this,{autoDistance:i,dragOut:s}=o.m;if(!s||!n||!i)return;const r=o.shrinkCanvasBounds,{x:m,y:c}=r,h=e.BoundsHelper.maxX(r),l=e.BoundsHelper.maxY(r),u=t.x<m?i:h<t.x?-i:0,v=t.y<c?i:l<t.y?-i:0;let d=0,f=0;this.autoMoveTimer=setInterval(()=>{d+=u,f+=v,e.PointHelper.move(a,u,v),e.PointHelper.move(this.dragData,u,v),o.move(Object.assign(Object.assign({},t),{moveX:u,moveY:v,totalX:d,totalY:f,moveType:"drag"})),o.pointerMoveReal(t)},10)},p.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},e.Plugin.add("viewport"),t.LeaferTypeCreator=i,t.MultiTouchHelper=m,t.Transformer=h,t.WheelEventHelper=c,t.addViewport=o,t.addViewportConfig=a,t}({},LeaferUI);
2
2
  //# sourceMappingURL=viewport.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewport.min.js","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)\n if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed\n if (scale < 0.5) scale = 0.5\n if (scale >= 1.5) scale = 1.5\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number): IPointData {\n const { scroll, disabled } = this.app.config.move\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) moveX = moveX || moveY, moveY = 0\n else if (type.includes('y')) moveY = moveY || moveX, moveX = 0\n else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0\n\n if (type.includes('limit')) {\n const { x, y, width, height } = bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n const right = x + width - this.width, bottom = y + height - this.height\n\n if (x >= 0 && right <= 0) moveX = 0 // includeX\n else if (moveX > 0) { if (x + moveX > 0) moveX = -x }\n else if (moveX < 0 && right + moveX < 0) moveX = -right\n\n if (y >= 0 && bottom <= 0) moveY = 0 // includeY\n else if (moveY > 0) { if (y + moveY > 0) moveY = -y }\n else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom\n }\n }\n return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","Math","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","abs","ceil","metaKey","ctrlKey","MathHelper","within","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","END","reset","destroy","Leafer","prototype","bounds","Bounds","getMoveEventData","getZoomEventData","initType","type","disabled","app","includes","width","height","set","__world","addPoint","right","bottom","scaleX","__","absScale","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","BoundsHelper","maxX","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"2FAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,YAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,UAEzDhB,EAAOQ,IAAIS,EAAAA,UAAUC,YAAcP,IAC/B,MAAMC,UAAEA,GAAcZ,EAChBmB,EAAcnB,EAAOoB,cAAcT,EAAEU,OACvB,IAAhBF,GAAmBP,EAAUU,aAAaX,EAAGQ,KAG7D,CAEM,SAAUhB,EAAkBH,EAAqBC,GACnD,MAAMsB,EAAgC,CAClCC,MAAO,CAAEC,gBAAgB,GACzBC,MAAO,CAAED,gBAAgB,GACzBE,QAAS,CAAEC,oBAAoB,IAE/B3B,GAAa4B,aAAWC,OAAOP,EAAgBtB,GACnD4B,EAAAA,WAAWC,OAAO9B,EAAO+B,OAAQR,EAAgBvB,EAAOgC,WAC5D,CCnBA,MAAMC,EAAQC,EAAAA,MAAMC,IAAI,qBAEXC,EAAoB,CAE7BC,KAAM,CAAA,EAEN,QAAAC,CAASC,EAAcC,GACnBH,EAAKE,IAASN,EAAMQ,OAAOF,GAC3BF,EAAKE,GAAQC,CACjB,EAEA,GAAAE,CAAIH,EAAcvC,GACd,MAAMwC,EAAKH,EAAKE,GAChBC,GAAMA,EAAGxC,EACb,IAIEqC,KAAEA,EAAIC,SAAEA,GAAaF,EAE3BE,EAAS,WAAYvC,GACrBuC,EAAS,SC1BH,SAAiBtC,GACnBD,EAAYC,EAAQ,MAAM,EAC9B,GDyBAsC,EAAS,SE3BH,SAAiBtC,GACnBD,EAAYC,EAA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AA,YAAYzC,KAAKwK,EAAUtK,EAAOC,GAClCsC,EAAAA,YAAYzC,KAAK0E,KAAKoE,SAAU5I,EAAOC,GAEvC4E,EAAY/E,KAAImF,OAAAlE,OAAAkE,OAAAlE,OAAA,GAAM+D,GAAI,CAAE9E,QAAOC,QAAO4K,SAAQC,SAAQ/F,SAAU,UACpEF,EAAYoG,gBAAgBnG,IAC7B,GACP,EAEA0D,EAAQyB,eAAiB,WACjBzF,KAAKuG,gBACLG,cAAc1G,KAAKuG,eACnBvG,KAAKuG,cAAgB,EAE7B,EC5DAI,EAAAA,OAAOC,IAAI"}
1
+ {"version":3,"file":"viewport.min.js","sources":["../../../../../../src/in/packages/viewport/src/type/viewport.ts","../../../../../../src/in/packages/viewport/src/LeaferTypeCreator.ts","../../../../../../src/in/packages/viewport/src/type/custom.ts","../../../../../../src/in/packages/viewport/src/type/design.ts","../../../../../../src/in/packages/viewport/src/type/document.ts","../../../../../../src/in/packages/viewport/src/interaction/MultiTouchHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/WheelEventHelper.ts","../../../../../../src/in/packages/viewport/src/interaction/Transformer.ts","../../../../../../src/in/packages/viewport/src/Leafer.ts","../../../../../../src/in/packages/viewport/src/interaction/Interaction.ts","../../../../../../src/in/packages/viewport/src/interaction/Dragger.ts","../../../../../../src/in/packages/viewport/src/index.ts"],"sourcesContent":["import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'\n\nimport { MoveEvent, ZoomEvent, DataHelper, LeafHelper } from '@leafer-ui/core'\n\n\nexport function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {\n addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig)\n if (leafer.isApp || custom) return\n\n leafer.__eventIds.push(\n leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {\n leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false))\n }),\n leafer.on_(MoveEvent.END, (e: MoveEvent) => {\n LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY))\n }),\n leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {\n const { zoomLayer } = leafer\n const changeScale = leafer.getValidScale(e.scale)\n if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale)\n })\n )\n}\n\nexport function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {\n const viewportConfig: ILeaferConfig = {\n wheel: { preventDefault: true },\n touch: { preventDefault: true },\n pointer: { preventDefaultMenu: true }\n }\n if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)\n DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)\n}","import { ILeaferBase, ILeaferTypeList, ILeaferTypeFunction } from '@leafer-ui/interface'\n\nimport { Debug } from '@leafer-ui/core'\n\nimport { addViewport } from './type/viewport'\nimport { custom } from './type/custom'\nimport { design } from './type/design'\nimport { document } from './type/document'\n\n\nconst debug = Debug.get('LeaferTypeCreator')\n\nexport const LeaferTypeCreator = {\n\n list: {} as ILeaferTypeList,\n\n register(name: string, fn: ILeaferTypeFunction): void {\n list[name] && debug.repeat(name)\n list[name] = fn\n },\n\n run(name: string, leafer: ILeaferBase): void {\n const fn = list[name]\n fn && fn(leafer)\n }\n\n}\n\nconst { list, register } = LeaferTypeCreator\n\nregister('viewport', addViewport)\nregister('custom', custom)\nregister('design', design)\nregister('document', document)","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function custom(leafer: ILeaferBase): void {\n addViewport(leafer, null, true)\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function design(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: {\n min: 0.01,\n max: 256\n },\n move: {\n holdSpaceKey: true,\n holdMiddleKey: true,\n }\n })\n}\n","import { ILeaferBase } from '@leafer-ui/interface'\n\nimport { addViewport } from './viewport'\n\n\nexport function document(leafer: ILeaferBase): void {\n addViewport(leafer, {\n zoom: { min: 1 },\n move: { scroll: 'limit' }\n })\n}\n","import { IMultiTouchData, IKeepTouchData } from '@leafer-ui/interface'\n\nimport { PointHelper } from '@leafer-ui/core'\n\n\nexport const MultiTouchHelper = {\n\n getData(list: IKeepTouchData[]): IMultiTouchData {\n const a = list[0], b = list[1]\n const lastCenter = PointHelper.getCenter(a.from, b.from)\n const center = PointHelper.getCenter(a.to, b.to)\n const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y }\n\n const lastDistance = PointHelper.getDistance(a.from, b.from)\n const distance = PointHelper.getDistance(a.to, b.to)\n const scale = distance / lastDistance\n\n const rotation = PointHelper.getRotation(a.from, b.from, a.to, b.to)\n\n return { move, scale, rotation, center }\n }\n\n}","import { IPointData, IWheelEvent, IWheelConfig } from '@leafer-ui/interface'\n\nimport { MathHelper, Platform } from '@leafer-ui/core'\n\n\nexport const WheelEventHelper = {\n\n getMove(event: IWheelEvent, config: IWheelConfig): IPointData {\n let { moveSpeed } = config\n let { deltaX, deltaY } = event\n if (event.shiftKey && !deltaX) { // Window\n deltaX = deltaY\n deltaY = 0\n }\n if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)\n if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)\n return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }\n },\n\n getScale(event: IWheelEvent, config: IWheelConfig): number {\n\n let zoom: boolean\n let scale = 1\n let { zoomMode, zoomSpeed } = config\n\n const delta = event.deltaY || event.deltaX\n\n if (zoomMode) {\n // mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数\n // windows 始终是整数\n zoom = (zoomMode === 'mouse') ? true : (!event.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))\n if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true\n } else {\n zoom = !event.shiftKey && (event.metaKey || event.ctrlKey)\n }\n\n if (zoom) {\n zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)\n const min = event.deltaY ? config.delta.y : config.delta.x\n scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed\n if (scale < 0.5) scale = 0.5\n if (scale >= 1.5) scale = 1.5\n }\n\n return scale\n }\n\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer } from '@leafer-ui/interface'\n\nimport { InteractionBase, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core'\n\n\nexport class Transformer {\n\n public get transforming(): boolean { return !!(this.moveData || this.zoomData || this.rotateData) }\n\n protected interaction: InteractionBase\n protected moveData: IMoveEvent\n protected zoomData: IZoomEvent\n protected rotateData: IRotateEvent\n protected transformTimer: ITimer\n\n constructor(interaction: InteractionBase) {\n this.interaction = interaction\n }\n\n public move(data: IMoveEvent): void {\n const { interaction } = this\n if (!data.moveType) data.moveType = 'move'\n\n if (!this.moveData) {\n this.setPath(data)\n this.moveData = { ...data, moveX: 0, moveY: 0 }\n interaction.emit(MoveEvent.START, this.moveData)\n }\n\n data.path = this.moveData.path\n interaction.emit(MoveEvent.BEFORE_MOVE, data)\n interaction.emit(MoveEvent.MOVE, data)\n\n this.transformEndWait()\n }\n\n public zoom(data: IZoomEvent): void {\n const { interaction } = this\n\n if (!this.zoomData) {\n this.setPath(data)\n this.zoomData = { ...data, scale: 1 }\n interaction.emit(ZoomEvent.START, this.zoomData)\n }\n\n data.path = this.zoomData.path\n interaction.emit(ZoomEvent.BEFORE_ZOOM, data)\n interaction.emit(ZoomEvent.ZOOM, data)\n\n this.transformEndWait()\n }\n\n public rotate(data: IRotateEvent): void {\n const { interaction } = this\n\n if (!this.rotateData) {\n this.setPath(data)\n this.rotateData = { ...data, rotation: 0 }\n interaction.emit(RotateEvent.START, this.rotateData)\n }\n\n data.path = this.rotateData.path\n interaction.emit(RotateEvent.BEFORE_ROTATE, data)\n interaction.emit(RotateEvent.ROTATE, data)\n\n this.transformEndWait()\n }\n\n public setPath(data: any): void {\n const { interaction } = this\n const { path } = interaction.selector.getByPoint(data, interaction.hitRadius)\n data.path = path\n interaction.cancelHover()\n }\n\n protected transformEndWait(): void {\n clearTimeout(this.transformTimer)\n this.transformTimer = setTimeout(() => {\n this.transformEnd()\n }, this.interaction.p.transformTime)\n }\n\n public transformEnd(): void {\n const { interaction, moveData, zoomData, rotateData } = this\n if (moveData) interaction.emit(MoveEvent.END, moveData)\n if (zoomData) interaction.emit(ZoomEvent.END, zoomData)\n if (rotateData) interaction.emit(RotateEvent.END, rotateData)\n this.reset()\n }\n\n public reset(): void {\n this.zoomData = this.moveData = this.rotateData = null\n }\n\n public destroy(): void {\n this.reset()\n }\n}","import { ILeaferType, IPointData } from '@leafer-ui/interface'\n\nimport { Leafer, Bounds, Point, DragBoundsHelper } from '@leafer-ui/core'\n\nimport { LeaferTypeCreator } from './LeaferTypeCreator'\n\n\nconst leafer = Leafer.prototype\nconst bounds = new Bounds(), move = new Point()\n\nleafer.initType = function (type: ILeaferType) {\n LeaferTypeCreator.run(type, this)\n}\n\nleafer.getValidMove = function (moveX: number, moveY: number, checkLimit = true): IPointData {\n const { scroll, disabled } = this.app.config.move\n move.set(moveX, moveY)\n\n if (scroll) {\n const type = scroll === true ? '' : scroll\n\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0\n\n if (checkLimit && type.includes('limit')) {\n bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)\n DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, 'inner', move, true)\n if (type.includes('x')) move.y = 0\n else if (type.includes('y')) move.x = 0\n }\n }\n\n return { x: disabled ? 0 : move.x, y: disabled ? 0 : move.y }\n}\n\nleafer.getValidScale = function (changeScale: number): number {\n const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)\n if (min && absScale < min) changeScale = min / scaleX\n else if (max && absScale > max) changeScale = max / scaleX\n return disabled ? 1 : changeScale // fix 不能过滤小数位\n}","import { IMoveEvent, IZoomEvent, IRotateEvent, IWheelEvent, IKeepTouchData, IPointData, IEvent, IPointerEvent } from '@leafer-ui/interface'\n\nimport { InteractionBase, PointHelper } from '@leafer-ui/core'\n\nimport { WheelEventHelper } from './WheelEventHelper'\nimport { Transformer } from './Transformer'\nimport { MultiTouchHelper } from './MultiTouchHelper'\n\n\nfunction getMoveEventData(move: IPointData, event: IEvent): IMoveEvent {\n return { ...event, moveX: move.x, moveY: move.y } as IMoveEvent\n}\n\nfunction getRotateEventData(rotation: number, event: IEvent): IRotateEvent {\n return { ...event, rotation } as IRotateEvent\n}\n\nfunction getZoomEventData(scale: number, event: IEvent): IZoomEvent {\n return { ...event, scale, } as IZoomEvent\n}\n\n\nconst interaction = InteractionBase.prototype\n\ninteraction.createTransformer = function (): void {\n this.transformer = new Transformer(this)\n}\n\ninteraction.move = function (data: IMoveEvent): void {\n this.transformer.move(data)\n}\n\ninteraction.zoom = function (data: IZoomEvent): void {\n this.transformer.zoom(data)\n}\n\ninteraction.rotate = function (data: IRotateEvent): void {\n this.transformer.rotate(data)\n}\n\ninteraction.transformEnd = function (): void {\n this.transformer.transformEnd()\n}\n\n\ninteraction.wheel = function (data: IWheelEvent): void {\n const { wheel, pointer } = this.config, { posDeltaSpeed, negDeltaSpeed } = wheel\n if (wheel.disabled) return\n\n if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaX *= negDeltaSpeed)\n\n if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed)\n else negDeltaSpeed && (data.deltaY *= negDeltaSpeed)\n\n const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel)\n if (scale !== 1) this.zoom(getZoomEventData(scale, data))\n else {\n const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel)\n if (pointer.snap) PointHelper.round(move)\n this.move(getMoveEventData(move, data))\n }\n}\n\n\ninteraction.multiTouch = function (data: IPointerEvent, list: IKeepTouchData[]): void {\n if (this.config.multiTouch.disabled) return\n const { move, rotation, scale, center } = MultiTouchHelper.getData(list)\n\n Object.assign(data, center)\n data.multiTouch = true\n\n this.pointerWaitCancel()\n\n this.rotate(getRotateEventData(rotation, data))\n this.zoom(getZoomEventData(scale, data))\n this.move(getMoveEventData(move, data))\n}","import { IPointerEvent, IFunction } from '@leafer-ui/interface'\n\nimport { Dragger, BoundsHelper, PointHelper, isNumber } from '@leafer-ui/core'\n\n\nconst dragger = Dragger.prototype\nconst { abs } = Math\n\ndragger.checkDragEndAnimate = function (data: IPointerEvent, speed?: number): boolean | number {\n const { moveX, moveY } = this.dragData\n const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : 0.1\n const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate\n\n if (dragAnimate) {\n const inertia = data.pointerType === 'touch' ? 3 : 1, maxMove = 70\n speed = speed ? (isNumber(dragAnimate) ? dragAnimate : 0.95) : inertia\n if (absMoveX * speed > maxMove) speed = maxMove / absMoveX\n else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY\n\n data = { ...data }\n PointHelper.move(data, moveX * speed, moveY * speed)\n\n this.drag(data)\n this.animate(() => { this.dragEnd(data, 1) })\n }\n\n return dragAnimate\n}\n\ndragger.animate = function (func?: IFunction, off?: 'off'): void { // dragEnd animation\n const animateWait = func || this.animateWait\n if (animateWait) this.interaction.target.nextRender(animateWait, null, off)\n this.animateWait = func\n}\n\ndragger.checkDragOut = function (data: IPointerEvent): void {\n const { interaction } = this\n this.autoMoveCancel()\n if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data)\n}\n\ndragger.autoMoveOnDragOut = function (data: IPointerEvent): void {\n const { interaction, downData, canDragOut } = this\n const { autoDistance, dragOut } = interaction.m\n if (!dragOut || !canDragOut || !autoDistance) return\n\n const bounds = interaction.shrinkCanvasBounds\n const { x, y } = bounds\n const right = BoundsHelper.maxX(bounds)\n const bottom = BoundsHelper.maxY(bounds)\n\n const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0)\n const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0)\n let totalX = 0, totalY = 0\n\n this.autoMoveTimer = setInterval(() => {\n totalX += moveX\n totalY += moveY\n\n PointHelper.move(downData, moveX, moveY)\n PointHelper.move(this.dragData, moveX, moveY)\n\n interaction.move({ ...data, moveX, moveY, totalX, totalY, moveType: 'drag' })\n interaction.pointerMoveReal(data)\n }, 10)\n}\n\ndragger.autoMoveCancel = function (): void {\n if (this.autoMoveTimer) {\n clearInterval(this.autoMoveTimer)\n this.autoMoveTimer = 0\n }\n}","export { LeaferTypeCreator } from './LeaferTypeCreator'\nexport { addViewport, addViewportConfig } from './type/viewport'\nexport { MultiTouchHelper } from './interaction/MultiTouchHelper'\nexport { WheelEventHelper } from './interaction/WheelEventHelper'\nexport { Transformer } from './interaction/Transformer'\n\nimport { Plugin } from '@leafer-ui/core'\n\nimport './Leafer'\nimport './interaction/Interaction'\nimport './interaction/Dragger'\n\nPlugin.add('viewport')"],"names":["addViewport","leafer","mergeConfig","custom","addViewportConfig","parentApp","isApp","__eventIds","push","on_","MoveEvent","BEFORE_MOVE","e","zoomLayer","move","getValidMove","moveX","moveY","END","LeafHelper","animateMove","ZoomEvent","BEFORE_ZOOM","changeScale","getValidScale","scale","scaleOfWorld","viewportConfig","wheel","preventDefault","touch","pointer","preventDefaultMenu","DataHelper","assign","config","userConfig","debug","Debug","get","LeaferTypeCreator","list","register","name","fn","repeat","run","zoom","min","max","holdSpaceKey","holdMiddleKey","scroll","MultiTouchHelper","getData","a","b","lastCenter","PointHelper","getCenter","from","center","to","x","y","lastDistance","getDistance","rotation","getRotation","WheelEventHelper","getMove","event","moveSpeed","deltaX","deltaY","shiftKey","Math","getScale","zoomMode","zoomSpeed","delta","Platform","intWheelDeltaY","abs","ceil","metaKey","ctrlKey","MathHelper","within","Transformer","transforming","this","moveData","zoomData","rotateData","constructor","interaction","data","moveType","setPath","Object","emit","START","path","MOVE","transformEndWait","ZOOM","rotate","RotateEvent","BEFORE_ROTATE","ROTATE","selector","getByPoint","hitRadius","cancelHover","clearTimeout","transformTimer","setTimeout","transformEnd","p","transformTime","reset","destroy","Leafer","prototype","bounds","Bounds","Point","getMoveEventData","getZoomEventData","initType","type","checkLimit","disabled","app","set","includes","__world","addPoint","DragBoundsHelper","canvas","scaleX","__","absScale","InteractionBase","createTransformer","transformer","posDeltaSpeed","negDeltaSpeed","snap","round","multiTouch","pointerWaitCancel","getRotateEventData","dragger","Dragger","checkDragEndAnimate","speed","dragData","absMoveX","absMoveY","minMove","dragAnimate","canAnimate","moving","m","inertia","pointerType","maxMove","isNumber","drag","animate","dragEnd","func","off","animateWait","target","nextRender","checkDragOut","autoMoveCancel","dragging","shrinkCanvasBounds","hitPoint","autoMoveOnDragOut","downData","canDragOut","autoDistance","dragOut","right","BoundsHelper","maxX","bottom","maxY","totalX","totalY","autoMoveTimer","setInterval","pointerMoveReal","clearInterval","Plugin","add"],"mappings":"2FAKgBA,EAAYC,EAAqBC,EAA6BC,GAC1EC,EAAkBH,EAAOI,UAAYJ,EAAOI,UAAYJ,EAAQC,GAC5DD,EAAOK,OAASH,GAEpBF,EAAOM,WAAWC,KACdP,EAAOQ,IAAIC,YAAUC,YAAcC,IAC/BX,EAAOY,UAAUC,KAAKb,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,OAAO,MAEhEhB,EAAOQ,IAAIC,EAAAA,UAAUQ,IAAMN,IACvBO,EAAAA,WAAWC,YAAYnB,EAAOY,UAAWZ,EAAOc,aAAaH,EAAEI,MAAOJ,EAAEK,UAE5EhB,EAAOQ,IAAIY,EAAAA,UAAUC,YAAcV,IAC/B,MAAMC,UAAEA,GAAcZ,EAChBsB,EAActB,EAAOuB,cA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wF,SAAEA,EAAQC,WAAEA,GAAe9F,MACxC+F,aAAEA,EAAYC,QAAEA,GAAY3F,EAAYqE,EAC9C,IAAKsB,IAAYF,IAAeC,EAAc,OAE9C,MAAM7D,EAAS7B,EAAYqF,oBACrBtH,EAAEA,EAACC,EAAEA,GAAM6D,EACX+D,EAAQC,EAAAA,aAAaC,KAAKjE,GAC1BkE,EAASF,EAAAA,aAAaG,KAAKnE,GAE3B7G,EAAQiF,EAAKlC,EAAIA,EAAI2H,EAAgBE,EAAQ3F,EAAKlC,GAAK2H,EAAe,EACtEzK,EAAQgF,EAAKjC,EAAIA,EAAI0H,EAAgBK,EAAS9F,EAAKjC,GAAK0H,EAAe,EAC7E,IAAIO,EAAS,EAAGC,EAAS,EAEzBvG,KAAKwG,cAAgBC,YAAY,KAC7BH,GAAUjL,EACVkL,GAAUjL,EAEVyC,EAAAA,YAAY5C,KAAK0K,EAAUxK,EAAOC,GAClCyC,EAAAA,YAAY5C,KAAK6E,KAAKmE,SAAU9I,EAAOC,GAEvC+E,EAAYlF,KAAIsF,OAAAlE,OAAAkE,OAAAlE,OAAA,GAAM+D,GAAI,CAAEjF,QAAOC,QAAOgL,SAAQC,SAAQhG,SAAU,UACpEF,EAAYqG,gBAAgBpG,IAC7B,GACP,EAEAyD,EAAQyB,eAAiB,WACjBxF,KAAKwG,gBACLG,cAAc3G,KAAKwG,eACnBxG,KAAKwG,cAAgB,EAE7B,EC5DAI,EAAAA,OAAOC,IAAI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/viewport",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "@leafer-in/viewport",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/core": "^1.9.1",
38
- "@leafer-ui/interface": "^1.9.1",
39
- "@leafer-in/interface": "^1.9.1"
37
+ "@leafer-ui/core": "^1.9.3",
38
+ "@leafer-ui/interface": "^1.9.3",
39
+ "@leafer-in/interface": "^1.9.3"
40
40
  }
41
41
  }
package/src/Leafer.ts CHANGED
@@ -1,41 +1,37 @@
1
1
  import { ILeaferType, IPointData } from '@leafer-ui/interface'
2
2
 
3
- import { Leafer, Bounds } from '@leafer-ui/core'
3
+ import { Leafer, Bounds, Point, DragBoundsHelper } from '@leafer-ui/core'
4
4
 
5
5
  import { LeaferTypeCreator } from './LeaferTypeCreator'
6
6
 
7
7
 
8
8
  const leafer = Leafer.prototype
9
- const bounds = new Bounds()
9
+ const bounds = new Bounds(), move = new Point()
10
10
 
11
11
  leafer.initType = function (type: ILeaferType) {
12
12
  LeaferTypeCreator.run(type, this)
13
13
  }
14
14
 
15
- leafer.getValidMove = function (moveX: number, moveY: number): IPointData {
15
+ leafer.getValidMove = function (moveX: number, moveY: number, checkLimit = true): IPointData {
16
16
  const { scroll, disabled } = this.app.config.move
17
+ move.set(moveX, moveY)
17
18
 
18
19
  if (scroll) {
19
20
  const type = scroll === true ? '' : scroll
20
21
 
21
- if (type.includes('x')) moveX = moveX || moveY, moveY = 0
22
- else if (type.includes('y')) moveY = moveY || moveX, moveX = 0
23
- else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0
22
+ if (type.includes('x')) move.y = 0
23
+ else if (type.includes('y')) move.x = 0
24
+ else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0
24
25
 
25
- if (type.includes('limit')) {
26
- const { x, y, width, height } = bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)
27
- const right = x + width - this.width, bottom = y + height - this.height
28
-
29
- if (x >= 0 && right <= 0) moveX = 0 // includeX
30
- else if (moveX > 0) { if (x + moveX > 0) moveX = -x }
31
- else if (moveX < 0 && right + moveX < 0) moveX = -right
32
-
33
- if (y >= 0 && bottom <= 0) moveY = 0 // includeY
34
- else if (moveY > 0) { if (y + moveY > 0) moveY = -y }
35
- else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom
26
+ if (checkLimit && type.includes('limit')) {
27
+ bounds.set(this.__world).addPoint(this.zoomLayer as IPointData)
28
+ DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, 'inner', move, true)
29
+ if (type.includes('x')) move.y = 0
30
+ else if (type.includes('y')) move.x = 0
36
31
  }
37
32
  }
38
- return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY }
33
+
34
+ return { x: disabled ? 0 : move.x, y: disabled ? 0 : move.y }
39
35
  }
40
36
 
41
37
  leafer.getValidScale = function (changeScale: number): number {
@@ -1,6 +1,6 @@
1
1
  import { ILeaferBase, ILeaferConfig } from '@leafer-ui/interface'
2
2
 
3
- import { MoveEvent, ZoomEvent, DataHelper } from '@leafer-ui/core'
3
+ import { MoveEvent, ZoomEvent, DataHelper, LeafHelper } from '@leafer-ui/core'
4
4
 
5
5
 
6
6
  export function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, custom?: boolean): void {
@@ -9,7 +9,10 @@ export function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, cu
9
9
 
10
10
  leafer.__eventIds.push(
11
11
  leafer.on_(MoveEvent.BEFORE_MOVE, (e: MoveEvent) => {
12
- leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY))
12
+ leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY, false))
13
+ }),
14
+ leafer.on_(MoveEvent.END, (e: MoveEvent) => {
15
+ LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY))
13
16
  }),
14
17
  leafer.on_(ZoomEvent.BEFORE_ZOOM, (e: ZoomEvent) => {
15
18
  const { zoomLayer } = leafer