@leafer-in/viewport 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/viewport.cjs +5 -4
- package/dist/viewport.esm.js +5 -4
- package/dist/viewport.esm.min.js +1 -1
- package/dist/viewport.js +5 -4
- package/dist/viewport.min.cjs +1 -1
- package/dist/viewport.min.js +1 -1
- package/package.json +4 -4
- package/src/type/viewport.ts +4 -3
package/dist/viewport.cjs
CHANGED
|
@@ -18,13 +18,14 @@ function addViewport(leafer, mergeConfig, custom) {
|
|
|
18
18
|
}));
|
|
19
19
|
}
|
|
20
20
|
function addViewportConfig(leafer, mergeConfig) {
|
|
21
|
-
|
|
22
|
-
core.DataHelper.assign(leafer.config, mergeConfig);
|
|
23
|
-
core.DataHelper.assign(leafer.config, {
|
|
21
|
+
const viewportConfig = {
|
|
24
22
|
wheel: { preventDefault: true },
|
|
25
23
|
touch: { preventDefault: true },
|
|
26
24
|
pointer: { preventDefaultMenu: true }
|
|
27
|
-
}
|
|
25
|
+
};
|
|
26
|
+
if (mergeConfig)
|
|
27
|
+
core.DataHelper.assign(viewportConfig, mergeConfig);
|
|
28
|
+
core.DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
function custom(leafer) {
|
package/dist/viewport.esm.js
CHANGED
|
@@ -16,13 +16,14 @@ function addViewport(leafer, mergeConfig, custom) {
|
|
|
16
16
|
}));
|
|
17
17
|
}
|
|
18
18
|
function addViewportConfig(leafer, mergeConfig) {
|
|
19
|
-
|
|
20
|
-
DataHelper.assign(leafer.config, mergeConfig);
|
|
21
|
-
DataHelper.assign(leafer.config, {
|
|
19
|
+
const viewportConfig = {
|
|
22
20
|
wheel: { preventDefault: true },
|
|
23
21
|
touch: { preventDefault: true },
|
|
24
22
|
pointer: { preventDefaultMenu: true }
|
|
25
|
-
}
|
|
23
|
+
};
|
|
24
|
+
if (mergeConfig)
|
|
25
|
+
DataHelper.assign(viewportConfig, mergeConfig);
|
|
26
|
+
DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function custom(leafer) {
|
package/dist/viewport.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MoveEvent as t,ZoomEvent as e,PointHelper as o,DataHelper as a,Debug as i,Platform as n,MathHelper as s,RotateEvent as r,Leafer as c,Bounds as m,InteractionBase as h,Dragger as l,BoundsHelper as u,Plugin as f}from"@leafer-ui/core";function g(a,i,n){d(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))})),a.on_(e.BEFORE_ZOOM,(t=>{const{zoomLayer:e}=a,i=a.getValidScale(t.scale);1!==i&&(o.scaleOf(e,t,i),e.scale=e.__.scaleX*i)})))}function d(t,e){
|
|
1
|
+
import{MoveEvent as t,ZoomEvent as e,PointHelper as o,DataHelper as a,Debug as i,Platform as n,MathHelper as s,RotateEvent as r,Leafer as c,Bounds as m,InteractionBase as h,Dragger as l,BoundsHelper as u,Plugin as f}from"@leafer-ui/core";function g(a,i,n){d(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))})),a.on_(e.BEFORE_ZOOM,(t=>{const{zoomLayer:e}=a,i=a.getValidScale(t.scale);1!==i&&(o.scaleOf(e,t,i),e.scale=e.__.scaleX*i)})))}function d(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 v=i.get("LeaferTypeCreator"),p={list:{},register(t,e){D[t]&&v.repeat(t),D[t]=e},run(t,e){const o=D[t];o&&o(e)}},{list:D,register:O}=p;O("viewport",g),O("custom",(function(t){g(t,null,!0)})),O("design",(function(t){g(t,{zoom:{min:.01,max:256},move:{holdSpaceKey:!0,holdMiddleKey:!0}})})),O("document",(function(t){g(t,{zoom:{min:1},move:{scroll:"limit"}})}));const y={getData(t){const e=t[0],a=t[1],i=o.getCenter(e.from,a.from),n=o.getCenter(e.to,a.to),s={x:n.x-i.x,y:n.y-i.y},r=o.getDistance(e.from,a.from);return{move:s,scale:o.getDistance(e.to,a.to)/r,rotation:o.getRotation(e.from,a.from,e.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,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 T=c.prototype,b=new m;function z(t,e){return Object.assign(Object.assign({},e),{moveX:t.x,moveY:t.y})}function x(t,e){return Object.assign(Object.assign({},e),{scale:t})}T.initType=function(t){p.run(t,this)},T.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}=b.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}},T.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:s.float(t)};const j=h.prototype;j.createTransformer=function(){this.transformer=new E(this)},j.move=function(t){this.transformer.move(t)},j.zoom=function(t){this.transformer.zoom(t)},j.rotate=function(t){this.transformer.rotate(t)},j.transformEnd=function(){this.transformer.transformEnd()},j.wheel=function(t){const{wheel:e}=this.config;if(e.disabled)return;const o=e.getScale?e.getScale(t,e):M.getScale(t,e);1!==o?this.zoom(x(o,t)):this.move(z(e.getMove?e.getMove(t,e):M.getMove(t,e),t))},j.multiTouch=function(t,e){if(this.config.multiTouch.disabled)return;const{move:o,rotation:a,scale:i,center:n}=y.getData(e);Object.assign(t,n),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(x(i,t)),this.move(z(o,t))};const _=l.prototype,{abs:R}=Math;_.checkDragEndAnimate=function(t,e){const{moveX:a,moveY:i}=this.dragData,n=R(a),s=R(i),r=e?1:.1,c=this.interaction.m.dragAnimate&&this.canAnimate&&this.moving&&(n>r||s>r);if(c){const r="touch"===t.pointerType?3:1,c=70;n*(e=e?.95:r)>c?e=c/n:s*e>c&&(e=c/s),t=Object.assign({},t),o.move(t,a*e,i*e),this.drag(t),this.animate((()=>{this.dragEnd(t,1)}))}return c},_.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},_.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},_.autoMoveOnDragOut=function(t){const{interaction:e,downData:a,canDragOut:i}=this,{autoDistance:n,dragOut:s}=e.m;if(!s||!i||!n)return;const r=e.shrinkCanvasBounds,{x:c,y:m}=r,h=u.maxX(r),l=u.maxY(r),f=t.x<c?n:h<t.x?-n:0,g=t.y<m?n:l<t.y?-n:0;let d=0,v=0;this.autoMoveTimer=setInterval((()=>{d+=f,v+=g,o.move(a,f,g),o.move(this.dragData,f,g),e.move(Object.assign(Object.assign({},t),{moveX:f,moveY:g,totalX:d,totalY:v,moveType:"drag"})),e.pointerMoveReal(t)}),10)},_.autoMoveCancel=function(){this.autoMoveTimer&&(clearInterval(this.autoMoveTimer),this.autoMoveTimer=0)},f.add("viewport");export{p as LeaferTypeCreator,y as MultiTouchHelper,E as Transformer,M as WheelEventHelper,g as addViewport,d as addViewportConfig};
|
package/dist/viewport.js
CHANGED
|
@@ -18,13 +18,14 @@ this.LeaferIN.viewport = (function (exports, core) {
|
|
|
18
18
|
}));
|
|
19
19
|
}
|
|
20
20
|
function addViewportConfig(leafer, mergeConfig) {
|
|
21
|
-
|
|
22
|
-
core.DataHelper.assign(leafer.config, mergeConfig);
|
|
23
|
-
core.DataHelper.assign(leafer.config, {
|
|
21
|
+
const viewportConfig = {
|
|
24
22
|
wheel: { preventDefault: true },
|
|
25
23
|
touch: { preventDefault: true },
|
|
26
24
|
pointer: { preventDefaultMenu: true }
|
|
27
|
-
}
|
|
25
|
+
};
|
|
26
|
+
if (mergeConfig)
|
|
27
|
+
core.DataHelper.assign(viewportConfig, mergeConfig);
|
|
28
|
+
core.DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
function custom(leafer) {
|
package/dist/viewport.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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,(o=>{const{zoomLayer:a}=e,i=e.getValidScale(o.scale);1!==i&&(t.PointHelper.scaleOf(a,o,i),a.scale=a.__.scaleX*i)})))}function o(e,o){
|
|
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,(o=>{const{zoomLayer:a}=e,i=e.getValidScale(o.scale);1!==i&&(t.PointHelper.scaleOf(a,o,i),a.scale=a.__.scaleX*i)})))}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(e){const{scaleX:o}=this.zoomLayer.__,{min:a,max:i,disabled:n}=this.app.config.zoom,s=Math.abs(o*e);return a&&s<a?e=a/o:i&&s>i&&(e=i/o),n?1:t.MathHelper.float(e)};const f=t.InteractionBase.prototype;f.createTransformer=function(){this.transformer=new m(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:e}=this.config;if(e.disabled)return;const o=e.getScale?e.getScale(t,e):c.getScale(t,e);1!==o?this.zoom(v(o,t)):this.move(u(e.getMove?e.getMove(t,e):c.getMove(t,e),t))},f.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),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 g=t.Dragger.prototype,{abs:p}=Math;g.checkDragEndAnimate=function(e,o){const{moveX:a,moveY:i}=this.dragData,n=p(a),s=p(i),r=o?1:.1,c=this.interaction.m.dragAnimate&&this.canAnimate&&this.moving&&(n>r||s>r);if(c){const r="touch"===e.pointerType?3:1,c=70;n*(o=o?.95:r)>c?o=c/n:s*o>c&&(o=c/s),e=Object.assign({},e),t.PointHelper.move(e,a*o,i*o),this.drag(e),this.animate((()=>{this.dragEnd(e,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(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 f=0,g=0;this.autoMoveTimer=setInterval((()=>{f+=u,g+=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:f,totalY:g,moveType:"drag"})),o.pointerMoveReal(e)}),10)},g.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;
|
package/dist/viewport.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,(o=>{const{zoomLayer:a}=t,i=t.getValidScale(o.scale);1!==i&&(e.PointHelper.scaleOf(a,o,i),a.scale=a.__.scaleX*i)})))}function a(t,o){
|
|
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,(o=>{const{zoomLayer:a}=t,i=t.getValidScale(o.scale);1!==i&&(e.PointHelper.scaleOf(a,o,i),a.scale=a.__.scaleX*i)})))}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 f(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:o}=this.zoomLayer.__,{min:a,max:i,disabled:n}=this.app.config.zoom,s=Math.abs(o*t);return a&&s<a?t=a/o:i&&s>i&&(t=i/o),n?1:e.MathHelper.float(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:e}=this.config;if(e.disabled)return;const o=e.getScale?e.getScale(t,e):m.getScale(t,e);1!==o?this.zoom(f(o,t)):this.move(v(e.getMove?e.getMove(t,e):m.getMove(t,e),t))},g.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),this.rotate(function(t,e){return Object.assign(Object.assign({},e),{rotation:t})}(a,t)),this.zoom(f(i,t)),this.move(v(o,t))};const d=e.Dragger.prototype,{abs:p}=Math;return d.checkDragEndAnimate=function(t,o){const{moveX:a,moveY:i}=this.dragData,n=p(a),s=p(i),r=o?1:.1,c=this.interaction.m.dragAnimate&&this.canAnimate&&this.moving&&(n>r||s>r);if(c){const r="touch"===t.pointerType?3:1,c=70;n*(o=o?.95:r)>c?o=c/n:s*o>c&&(o=c/s),t=Object.assign({},t),e.PointHelper.move(t,a*o,i*o),this.drag(t),this.animate((()=>{this.dragEnd(t,1)}))}return c},d.animate=function(t,e){const o=t||this.animateWait;o&&this.interaction.target.nextRender(o,null,e),this.animateWait=t},d.checkDragOut=function(t){const{interaction:e}=this;this.autoMoveCancel(),this.dragging&&!e.shrinkCanvasBounds.hitPoint(t)&&this.autoMoveOnDragOut(t)},d.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 f=0,g=0;this.autoMoveTimer=setInterval((()=>{f+=u,g+=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:f,totalY:g,moveType:"drag"})),o.pointerMoveReal(t)}),10)},d.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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/viewport",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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.2.
|
|
38
|
-
"@leafer-ui/interface": "^1.2.
|
|
39
|
-
"@leafer-in/interface": "^1.2.
|
|
37
|
+
"@leafer-ui/core": "^1.2.2",
|
|
38
|
+
"@leafer-ui/interface": "^1.2.2",
|
|
39
|
+
"@leafer-in/interface": "^1.2.2"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/type/viewport.ts
CHANGED
|
@@ -23,10 +23,11 @@ export function addViewport(leafer: ILeaferBase, mergeConfig?: ILeaferConfig, cu
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function addViewportConfig(leafer: ILeaferBase, mergeConfig?: ILeaferConfig): void {
|
|
26
|
-
|
|
27
|
-
DataHelper.assign(leafer.config, {
|
|
26
|
+
const viewportConfig: ILeaferConfig = {
|
|
28
27
|
wheel: { preventDefault: true },
|
|
29
28
|
touch: { preventDefault: true },
|
|
30
29
|
pointer: { preventDefaultMenu: true }
|
|
31
|
-
}
|
|
30
|
+
}
|
|
31
|
+
if (mergeConfig) DataHelper.assign(viewportConfig, mergeConfig)
|
|
32
|
+
DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig)
|
|
32
33
|
}
|