@leafer-in/view 1.8.0 → 1.9.1

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/view.cjs CHANGED
@@ -1,96 +1,102 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var draw = require('@leafer-ui/draw');
3
+ var draw = require("@leafer-ui/draw");
4
4
 
5
5
  function getZoomScale(scaleX, type) {
6
6
  let scale = 1;
7
- const out = type === 'out', absScale = Math.abs(scaleX);
7
+ const out = type === "out", absScale = Math.abs(scaleX);
8
8
  if (absScale > 1) {
9
- while (out ? scale < absScale : scale <= absScale)
10
- scale *= 2;
11
- if (out)
12
- scale /= 2;
13
- }
14
- else {
15
- while (out ? scale >= absScale : scale > absScale)
16
- scale /= 2;
17
- if (!out)
18
- scale *= 2;
9
+ while (out ? scale < absScale : scale <= absScale) scale *= 2;
10
+ if (out) scale /= 2;
11
+ } else {
12
+ while (out ? scale >= absScale : scale > absScale) scale /= 2;
13
+ if (!out) scale *= 2;
19
14
  }
20
15
  return scale / scaleX;
21
16
  }
17
+
22
18
  function getFixBounds(bounds, scaleBounds) {
23
- let { x, y, width, height } = bounds;
19
+ let {x: x, y: y, width: width, height: height} = bounds;
24
20
  let fix;
25
- if (!height)
26
- height = width * (scaleBounds.height / scaleBounds.width), fix = true;
27
- if (!width)
28
- width = height * (scaleBounds.width / scaleBounds.height), fix = true;
29
- return fix ? { x, y, width, height } : bounds;
21
+ if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true;
22
+ if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true;
23
+ return fix ? {
24
+ x: x,
25
+ y: y,
26
+ width: width,
27
+ height: height
28
+ } : bounds;
30
29
  }
31
30
 
32
- draw.Plugin.add('view');
33
- draw.Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition) {
31
+ draw.Plugin.add("view");
32
+
33
+ draw.Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
34
34
  this.killAnimate();
35
35
  let padding;
36
- if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
36
+ if (draw.isData(optionsOrPadding)) {
37
37
  padding = optionsOrPadding.padding;
38
38
  scroll = optionsOrPadding.scroll;
39
39
  transition = optionsOrPadding.transition;
40
- }
41
- else
42
- padding = optionsOrPadding;
43
- const { zoomLayer } = this;
44
- const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new draw.Bounds();
45
- const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
40
+ } else padding = optionsOrPadding;
41
+ const {zoomLayer: zoomLayer} = this;
42
+ const limitBounds = this.canvas.bounds.clone().shrink(draw.isNull(padding) ? 30 : padding), bounds = new draw.Bounds;
43
+ const center = {
44
+ x: limitBounds.x + limitBounds.width / 2,
45
+ y: limitBounds.y + limitBounds.height / 2
46
+ };
46
47
  let changeScale;
47
- const { x, y, scaleX, scaleY } = zoomLayer.__;
48
- if (typeof zoomType === 'string') {
48
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
49
+ if (draw.isString(zoomType)) {
49
50
  switch (zoomType) {
50
- case 'in':
51
- changeScale = getZoomScale(scaleX, 'in');
52
- break;
53
- case 'out':
54
- changeScale = getZoomScale(scaleX, 'out');
55
- break;
56
- case 'fit':
57
- zoomType = this.boxBounds;
58
- break;
59
- case 'fit-width':
60
- zoomType = new draw.Bounds(this.boxBounds);
61
- zoomType.height = 0;
62
- break;
63
- case 'fit-height':
64
- zoomType = new draw.Bounds(this.boxBounds);
65
- zoomType.width = 0;
66
- break;
51
+ case "in":
52
+ changeScale = getZoomScale(scaleX, "in");
53
+ break;
54
+
55
+ case "out":
56
+ changeScale = getZoomScale(scaleX, "out");
57
+ break;
58
+
59
+ case "fit":
60
+ zoomType = this.boxBounds;
61
+ break;
62
+
63
+ case "fit-width":
64
+ zoomType = new draw.Bounds(this.boxBounds);
65
+ zoomType.height = 0;
66
+ break;
67
+
68
+ case "fit-height":
69
+ zoomType = new draw.Bounds(this.boxBounds);
70
+ zoomType.width = 0;
71
+ break;
67
72
  }
68
- }
69
- else if (typeof zoomType === 'number') {
73
+ } else if (draw.isNumber(zoomType)) {
70
74
  changeScale = zoomType / scaleX;
71
75
  }
72
76
  if (changeScale) {
73
77
  changeScale = this.getValidScale(changeScale);
74
78
  zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
75
- }
76
- else if (typeof zoomType === 'object') {
77
- const data = { x, y, scaleX, scaleY };
78
- const isArray = zoomType instanceof Array;
79
- if (isArray || zoomType.tag) {
80
- const list = isArray ? zoomType : [zoomType];
79
+ } else if (draw.isObject(zoomType)) {
80
+ const data = {
81
+ x: x,
82
+ y: y,
83
+ scaleX: scaleX,
84
+ scaleY: scaleY
85
+ };
86
+ const isArr = draw.isArray(zoomType);
87
+ if (isArr || zoomType.tag) {
88
+ const list = isArr ? zoomType : [ zoomType ];
81
89
  bounds.setListWithFn(list, draw.LeafBoundsHelper.worldBounds);
82
- }
83
- else {
90
+ } else {
84
91
  const innerBounds = getFixBounds(zoomType, limitBounds);
85
92
  bounds.set(zoomLayer.getWorldBounds(innerBounds));
86
93
  }
87
- const { width, height } = bounds;
94
+ const {width: width, height: height} = bounds;
88
95
  let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
89
96
  if (scroll) {
90
97
  moveX += Math.max((limitBounds.width - width) / 2, 0);
91
98
  moveY += Math.max((limitBounds.height - height) / 2, 0);
92
- }
93
- else {
99
+ } else {
94
100
  changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height));
95
101
  moveX += (limitBounds.width - width * changeScale) / 2;
96
102
  moveY += (limitBounds.height - height * changeScale) / 2;
@@ -99,10 +105,7 @@ draw.Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, trans
99
105
  data.scaleX *= changeScale;
100
106
  data.scaleY *= changeScale;
101
107
  }
102
- if (scroll === 'x')
103
- moveY = 0;
104
- else if (scroll === 'y')
105
- moveX = 0;
108
+ if (scroll === "x") moveY = 0; else if (scroll === "y") moveX = 0;
106
109
  draw.PointHelper.move(data, moveX, moveY);
107
110
  bounds.move(moveX, moveY);
108
111
  zoomLayer.set(data, transition);
package/dist/view.esm.js CHANGED
@@ -1,94 +1,100 @@
1
- import { Plugin, Leafer, Bounds, LeafBoundsHelper, PointHelper } from '@leafer-ui/draw';
1
+ import { Plugin, Leafer, isData, isNull, Bounds, isString, isNumber, isObject, isArray, LeafBoundsHelper, PointHelper } from "@leafer-ui/draw";
2
2
 
3
3
  function getZoomScale(scaleX, type) {
4
4
  let scale = 1;
5
- const out = type === 'out', absScale = Math.abs(scaleX);
5
+ const out = type === "out", absScale = Math.abs(scaleX);
6
6
  if (absScale > 1) {
7
- while (out ? scale < absScale : scale <= absScale)
8
- scale *= 2;
9
- if (out)
10
- scale /= 2;
11
- }
12
- else {
13
- while (out ? scale >= absScale : scale > absScale)
14
- scale /= 2;
15
- if (!out)
16
- scale *= 2;
7
+ while (out ? scale < absScale : scale <= absScale) scale *= 2;
8
+ if (out) scale /= 2;
9
+ } else {
10
+ while (out ? scale >= absScale : scale > absScale) scale /= 2;
11
+ if (!out) scale *= 2;
17
12
  }
18
13
  return scale / scaleX;
19
14
  }
15
+
20
16
  function getFixBounds(bounds, scaleBounds) {
21
- let { x, y, width, height } = bounds;
17
+ let {x: x, y: y, width: width, height: height} = bounds;
22
18
  let fix;
23
- if (!height)
24
- height = width * (scaleBounds.height / scaleBounds.width), fix = true;
25
- if (!width)
26
- width = height * (scaleBounds.width / scaleBounds.height), fix = true;
27
- return fix ? { x, y, width, height } : bounds;
19
+ if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true;
20
+ if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true;
21
+ return fix ? {
22
+ x: x,
23
+ y: y,
24
+ width: width,
25
+ height: height
26
+ } : bounds;
28
27
  }
29
28
 
30
- Plugin.add('view');
31
- Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition) {
29
+ Plugin.add("view");
30
+
31
+ Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
32
32
  this.killAnimate();
33
33
  let padding;
34
- if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
34
+ if (isData(optionsOrPadding)) {
35
35
  padding = optionsOrPadding.padding;
36
36
  scroll = optionsOrPadding.scroll;
37
37
  transition = optionsOrPadding.transition;
38
- }
39
- else
40
- padding = optionsOrPadding;
41
- const { zoomLayer } = this;
42
- const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
43
- const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
38
+ } else padding = optionsOrPadding;
39
+ const {zoomLayer: zoomLayer} = this;
40
+ const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds;
41
+ const center = {
42
+ x: limitBounds.x + limitBounds.width / 2,
43
+ y: limitBounds.y + limitBounds.height / 2
44
+ };
44
45
  let changeScale;
45
- const { x, y, scaleX, scaleY } = zoomLayer.__;
46
- if (typeof zoomType === 'string') {
46
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
47
+ if (isString(zoomType)) {
47
48
  switch (zoomType) {
48
- case 'in':
49
- changeScale = getZoomScale(scaleX, 'in');
50
- break;
51
- case 'out':
52
- changeScale = getZoomScale(scaleX, 'out');
53
- break;
54
- case 'fit':
55
- zoomType = this.boxBounds;
56
- break;
57
- case 'fit-width':
58
- zoomType = new Bounds(this.boxBounds);
59
- zoomType.height = 0;
60
- break;
61
- case 'fit-height':
62
- zoomType = new Bounds(this.boxBounds);
63
- zoomType.width = 0;
64
- break;
49
+ case "in":
50
+ changeScale = getZoomScale(scaleX, "in");
51
+ break;
52
+
53
+ case "out":
54
+ changeScale = getZoomScale(scaleX, "out");
55
+ break;
56
+
57
+ case "fit":
58
+ zoomType = this.boxBounds;
59
+ break;
60
+
61
+ case "fit-width":
62
+ zoomType = new Bounds(this.boxBounds);
63
+ zoomType.height = 0;
64
+ break;
65
+
66
+ case "fit-height":
67
+ zoomType = new Bounds(this.boxBounds);
68
+ zoomType.width = 0;
69
+ break;
65
70
  }
66
- }
67
- else if (typeof zoomType === 'number') {
71
+ } else if (isNumber(zoomType)) {
68
72
  changeScale = zoomType / scaleX;
69
73
  }
70
74
  if (changeScale) {
71
75
  changeScale = this.getValidScale(changeScale);
72
76
  zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
73
- }
74
- else if (typeof zoomType === 'object') {
75
- const data = { x, y, scaleX, scaleY };
76
- const isArray = zoomType instanceof Array;
77
- if (isArray || zoomType.tag) {
78
- const list = isArray ? zoomType : [zoomType];
77
+ } else if (isObject(zoomType)) {
78
+ const data = {
79
+ x: x,
80
+ y: y,
81
+ scaleX: scaleX,
82
+ scaleY: scaleY
83
+ };
84
+ const isArr = isArray(zoomType);
85
+ if (isArr || zoomType.tag) {
86
+ const list = isArr ? zoomType : [ zoomType ];
79
87
  bounds.setListWithFn(list, LeafBoundsHelper.worldBounds);
80
- }
81
- else {
88
+ } else {
82
89
  const innerBounds = getFixBounds(zoomType, limitBounds);
83
90
  bounds.set(zoomLayer.getWorldBounds(innerBounds));
84
91
  }
85
- const { width, height } = bounds;
92
+ const {width: width, height: height} = bounds;
86
93
  let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
87
94
  if (scroll) {
88
95
  moveX += Math.max((limitBounds.width - width) / 2, 0);
89
96
  moveY += Math.max((limitBounds.height - height) / 2, 0);
90
- }
91
- else {
97
+ } else {
92
98
  changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height));
93
99
  moveX += (limitBounds.width - width * changeScale) / 2;
94
100
  moveY += (limitBounds.height - height * changeScale) / 2;
@@ -97,10 +103,7 @@ Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition
97
103
  data.scaleX *= changeScale;
98
104
  data.scaleY *= changeScale;
99
105
  }
100
- if (scroll === 'x')
101
- moveY = 0;
102
- else if (scroll === 'y')
103
- moveX = 0;
106
+ if (scroll === "x") moveY = 0; else if (scroll === "y") moveX = 0;
104
107
  PointHelper.move(data, moveX, moveY);
105
108
  bounds.move(moveX, moveY);
106
109
  zoomLayer.set(data, transition);
@@ -1,2 +1,2 @@
1
- import{Plugin as t,Leafer as e,Bounds as i,LeafBoundsHelper as s,PointHelper as o}from"@leafer-ui/draw";function h(t,e){let i=1;const s="out"===e,o=Math.abs(t);if(o>1){for(;s?i<o:i<=o;)i*=2;s&&(i/=2)}else{for(;s?i>=o:i>o;)i/=2;s||(i*=2)}return i/t}t.add("view"),e.prototype.zoom=function(t,e,n,a){let c;this.killAnimate(),"object"!=typeof e||e instanceof Array?c=e:(c=e.padding,n=e.scroll,a=e.transition);const{zoomLayer:r}=this,l=this.canvas.bounds.clone().shrink(void 0!==c?c:30),d=new i,f={x:l.x+l.width/2,y:l.y+l.height/2};let u;const{x:w,y:g,scaleX:y,scaleY:x}=r.__;if("string"==typeof t)switch(t){case"in":u=h(y,"in");break;case"out":u=h(y,"out");break;case"fit":t=this.boxBounds;break;case"fit-width":(t=new i(this.boxBounds)).height=0;break;case"fit-height":(t=new i(this.boxBounds)).width=0}else"number"==typeof t&&(u=t/y);if(u)u=this.getValidScale(u),r.scaleOfWorld(f,u,u,!1,a);else if("object"==typeof t){const e={x:w,y:g,scaleX:y,scaleY:x},i=t instanceof Array;if(i||t.tag){const e=i?t:[t];d.setListWithFn(e,s.worldBounds)}else{const e=function(t,e){let i,{x:s,y:o,width:h,height:n}=t;return n||(n=h*(e.height/e.width),i=!0),h||(h=n*(e.width/e.height),i=!0),i?{x:s,y:o,width:h,height:n}:t}(t,l);d.set(r.getWorldBounds(e))}const{width:h,height:c}=d;let f=l.x-d.x,b=l.y-d.y;return n?(f+=Math.max((l.width-h)/2,0),b+=Math.max((l.height-c)/2,0)):(u=this.getValidScale(Math.min(l.width/h,l.height/c)),f+=(l.width-h*u)/2,b+=(l.height-c*u)/2,o.scaleOf(e,d,u),d.scaleOf(d,u),e.scaleX*=u,e.scaleY*=u),"x"===n?b=0:"y"===n&&(f=0),o.move(e,f,b),d.move(f,b),r.set(e,a),d}return r.worldBoxBounds};
1
+ import{Plugin as t,Leafer as e,isData as i,isNull as s,Bounds as h,isString as o,isNumber as a,isObject as n,isArray as l,LeafBoundsHelper as c,PointHelper as d}from"@leafer-ui/draw";function r(t,e){let i=1;const s="out"===e,h=Math.abs(t);if(h>1){for(;s?i<h:i<=h;)i*=2;s&&(i/=2)}else{for(;s?i>=h:i>h;)i/=2;s||(i*=2)}return i/t}t.add("view"),e.prototype.zoom=function(t,e,w,f){let u;this.killAnimate(),i(e)?(u=e.padding,w=e.scroll,f=e.transition):u=e;const{zoomLayer:g}=this,x=this.canvas.bounds.clone().shrink(s(u)?30:u),y=new h,m={x:x.x+x.width/2,y:x.y+x.height/2};let b;const{x:B,y:k,scaleX:p,scaleY:v}=g.__;if(o(t))switch(t){case"in":b=r(p,"in");break;case"out":b=r(p,"out");break;case"fit":t=this.boxBounds;break;case"fit-width":(t=new h(this.boxBounds)).height=0;break;case"fit-height":(t=new h(this.boxBounds)).width=0}else a(t)&&(b=t/p);if(b)b=this.getValidScale(b),g.scaleOfWorld(m,b,b,!1,f);else if(n(t)){const e={x:B,y:k,scaleX:p,scaleY:v},i=l(t);if(i||t.tag){const e=i?t:[t];y.setListWithFn(e,c.worldBounds)}else{const e=function(t,e){let i,{x:s,y:h,width:o,height:a}=t;return a||(a=o*(e.height/e.width),i=!0),o||(o=a*(e.width/e.height),i=!0),i?{x:s,y:h,width:o,height:a}:t}(t,x);y.set(g.getWorldBounds(e))}const{width:s,height:h}=y;let o=x.x-y.x,a=x.y-y.y;return w?(o+=Math.max((x.width-s)/2,0),a+=Math.max((x.height-h)/2,0)):(b=this.getValidScale(Math.min(x.width/s,x.height/h)),o+=(x.width-s*b)/2,a+=(x.height-h*b)/2,d.scaleOf(e,y,b),y.scaleOf(y,b),e.scaleX*=b,e.scaleY*=b),"x"===w?a=0:"y"===w&&(o=0),d.move(e,o,a),y.move(o,a),g.set(e,f),y}return g.worldBoxBounds};
2
2
  //# sourceMappingURL=view.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.esm.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (typeof zoomType === 'string') {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (typeof zoomType === 'number') {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (typeof zoomType === 'object') {\n\n const data = { x, y, scaleX, scaleY }\n const isArray = zoomType instanceof Array\n\n if (isArray || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArray ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","Array","zoomLayer","limitBounds","canvas","bounds","clone","shrink","undefined","Bounds","center","x","width","y","height","changeScale","scaleY","__","boxBounds","getValidScale","scaleOfWorld","data","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"wGAGgB,SAAAA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,OACf,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,GAEvB,OAAOA,EAAQF,CACnB,CCRAO,EAAOC,IAAI,QAGXC,EAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAI2B,iBAArBL,GAAmCA,aAA4BM,MAInEH,EAAUH,GAHbG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAGlC,MAAMK,UAAEA,GAAcH,KAChBI,EAAcJ,KAAKK,OAAOC,OAAOC,QAAQC,YAAmBC,IAAZV,EAAwBA,EAAU,IAAKO,EAAS,IAAII,EACpGC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAMJ,EAAEA,EAACE,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EA4BrE,OA1BIjB,GAEAsC,GAAS/C,KAAKiD,KAAKjC,EAAYS,MAAQA,GAAS,EAAG,GACnDuB,GAAShD,KAAKiD,KAAKjC,EAAYW,OAASA,GAAU,EAAG,KAIrDC,EAAchB,KAAKoB,cAAchC,KAAKkD,IAAIlC,EAAYS,MAAQA,EAAOT,EAAYW,OAASA,IAC1FoB,IAAU/B,EAAYS,MAAQA,EAAQG,GAAe,EACrDoB,IAAUhC,EAAYW,OAASA,EAASC,GAAe,EAEvDuB,EAAYC,QAAQlB,EAAMhB,EAAQU,GAClCV,EAAOkC,QAAQlC,EAAQU,GAEvBM,EAAKvC,QAAUiC,EACfM,EAAKL,QAAUD,GAGJ,MAAXnB,EAAgBuC,EAAQ,EACR,MAAXvC,IAAgBsC,EAAQ,GAEjCI,EAAYE,KAAKnB,EAAMa,EAAOC,GAC9B9B,EAAOmC,KAAKN,EAAOC,GAEnBjC,EAAU8B,IAAIX,EAAMxB,GAEbQ,EAIX,OAAOH,EAAUuC,cAErB"}
1
+ {"version":3,"file":"view.esm.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","isData","zoomLayer","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","scaleY","__","isString","boxBounds","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"uLAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,EAAQF,CACnB,CCRA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(scaleX, type) {
5
4
  let scale = 1;
6
- const out = type === 'out', absScale = Math.abs(scaleX);
5
+ const out = type === "out", absScale = Math.abs(scaleX);
7
6
  if (absScale > 1) {
8
- while (out ? scale < absScale : scale <= absScale)
9
- scale *= 2;
10
- if (out)
11
- scale /= 2;
12
- }
13
- else {
14
- while (out ? scale >= absScale : scale > absScale)
15
- scale /= 2;
16
- if (!out)
17
- scale *= 2;
7
+ while (out ? scale < absScale : scale <= absScale) scale *= 2;
8
+ if (out) scale /= 2;
9
+ } else {
10
+ while (out ? scale >= absScale : scale > absScale) scale /= 2;
11
+ if (!out) scale *= 2;
18
12
  }
19
13
  return scale / scaleX;
20
14
  }
21
15
  function getFixBounds(bounds, scaleBounds) {
22
- let { x, y, width, height } = bounds;
16
+ let {x: x, y: y, width: width, height: height} = bounds;
23
17
  let fix;
24
- if (!height)
25
- height = width * (scaleBounds.height / scaleBounds.width), fix = true;
26
- if (!width)
27
- width = height * (scaleBounds.width / scaleBounds.height), fix = true;
28
- return fix ? { x, y, width, height } : bounds;
18
+ if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true;
19
+ if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true;
20
+ return fix ? {
21
+ x: x,
22
+ y: y,
23
+ width: width,
24
+ height: height
25
+ } : bounds;
29
26
  }
30
-
31
- draw.Plugin.add('view');
32
- draw.Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition) {
27
+ draw.Plugin.add("view");
28
+ draw.Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
33
29
  this.killAnimate();
34
30
  let padding;
35
- if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
31
+ if (draw.isData(optionsOrPadding)) {
36
32
  padding = optionsOrPadding.padding;
37
33
  scroll = optionsOrPadding.scroll;
38
34
  transition = optionsOrPadding.transition;
39
- }
40
- else
41
- padding = optionsOrPadding;
42
- const { zoomLayer } = this;
43
- const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new draw.Bounds();
44
- const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
35
+ } else padding = optionsOrPadding;
36
+ const {zoomLayer: zoomLayer} = this;
37
+ const limitBounds = this.canvas.bounds.clone().shrink(draw.isNull(padding) ? 30 : padding), bounds = new draw.Bounds;
38
+ const center = {
39
+ x: limitBounds.x + limitBounds.width / 2,
40
+ y: limitBounds.y + limitBounds.height / 2
41
+ };
45
42
  let changeScale;
46
- const { x, y, scaleX, scaleY } = zoomLayer.__;
47
- if (typeof zoomType === 'string') {
43
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
44
+ if (draw.isString(zoomType)) {
48
45
  switch (zoomType) {
49
- case 'in':
50
- changeScale = getZoomScale(scaleX, 'in');
51
- break;
52
- case 'out':
53
- changeScale = getZoomScale(scaleX, 'out');
54
- break;
55
- case 'fit':
56
- zoomType = this.boxBounds;
57
- break;
58
- case 'fit-width':
59
- zoomType = new draw.Bounds(this.boxBounds);
60
- zoomType.height = 0;
61
- break;
62
- case 'fit-height':
63
- zoomType = new draw.Bounds(this.boxBounds);
64
- zoomType.width = 0;
65
- break;
46
+ case "in":
47
+ changeScale = getZoomScale(scaleX, "in");
48
+ break;
49
+
50
+ case "out":
51
+ changeScale = getZoomScale(scaleX, "out");
52
+ break;
53
+
54
+ case "fit":
55
+ zoomType = this.boxBounds;
56
+ break;
57
+
58
+ case "fit-width":
59
+ zoomType = new draw.Bounds(this.boxBounds);
60
+ zoomType.height = 0;
61
+ break;
62
+
63
+ case "fit-height":
64
+ zoomType = new draw.Bounds(this.boxBounds);
65
+ zoomType.width = 0;
66
+ break;
66
67
  }
67
- }
68
- else if (typeof zoomType === 'number') {
68
+ } else if (draw.isNumber(zoomType)) {
69
69
  changeScale = zoomType / scaleX;
70
70
  }
71
71
  if (changeScale) {
72
72
  changeScale = this.getValidScale(changeScale);
73
73
  zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
74
- }
75
- else if (typeof zoomType === 'object') {
76
- const data = { x, y, scaleX, scaleY };
77
- const isArray = zoomType instanceof Array;
78
- if (isArray || zoomType.tag) {
79
- const list = isArray ? zoomType : [zoomType];
74
+ } else if (draw.isObject(zoomType)) {
75
+ const data = {
76
+ x: x,
77
+ y: y,
78
+ scaleX: scaleX,
79
+ scaleY: scaleY
80
+ };
81
+ const isArr = draw.isArray(zoomType);
82
+ if (isArr || zoomType.tag) {
83
+ const list = isArr ? zoomType : [ zoomType ];
80
84
  bounds.setListWithFn(list, draw.LeafBoundsHelper.worldBounds);
81
- }
82
- else {
85
+ } else {
83
86
  const innerBounds = getFixBounds(zoomType, limitBounds);
84
87
  bounds.set(zoomLayer.getWorldBounds(innerBounds));
85
88
  }
86
- const { width, height } = bounds;
89
+ const {width: width, height: height} = bounds;
87
90
  let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
88
91
  if (scroll) {
89
92
  moveX += Math.max((limitBounds.width - width) / 2, 0);
90
93
  moveY += Math.max((limitBounds.height - height) / 2, 0);
91
- }
92
- else {
94
+ } else {
93
95
  changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height));
94
96
  moveX += (limitBounds.width - width * changeScale) / 2;
95
97
  moveY += (limitBounds.height - height * changeScale) / 2;
@@ -98,10 +100,7 @@
98
100
  data.scaleX *= changeScale;
99
101
  data.scaleY *= changeScale;
100
102
  }
101
- if (scroll === 'x')
102
- moveY = 0;
103
- else if (scroll === 'y')
104
- moveX = 0;
103
+ if (scroll === "x") moveY = 0; else if (scroll === "y") moveX = 0;
105
104
  draw.PointHelper.move(data, moveX, moveY);
106
105
  bounds.move(moveX, moveY);
107
106
  zoomLayer.set(data, transition);
@@ -109,5 +108,4 @@
109
108
  }
110
109
  return zoomLayer.worldBoxBounds;
111
110
  };
112
-
113
111
  })(LeaferUI);
package/dist/view.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@leafer-ui/draw");function t(e,t){let i=1;const s="out"===t,o=Math.abs(e);if(o>1){for(;s?i<o:i<=o;)i*=2;s&&(i/=2)}else{for(;s?i>=o:i>o;)i/=2;s||(i*=2)}return i/e}e.Plugin.add("view"),e.Leafer.prototype.zoom=function(i,s,o,n){let h;this.killAnimate(),"object"!=typeof s||s instanceof Array?h=s:(h=s.padding,o=s.scroll,n=s.transition);const{zoomLayer:a}=this,r=this.canvas.bounds.clone().shrink(void 0!==h?h:30),l=new e.Bounds,c={x:r.x+r.width/2,y:r.y+r.height/2};let d;const{x:u,y:f,scaleX:w,scaleY:g}=a.__;if("string"==typeof i)switch(i){case"in":d=t(w,"in");break;case"out":d=t(w,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new e.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new e.Bounds(this.boxBounds)).width=0}else"number"==typeof i&&(d=i/w);if(d)d=this.getValidScale(d),a.scaleOfWorld(c,d,d,!1,n);else if("object"==typeof i){const t={x:u,y:f,scaleX:w,scaleY:g},s=i instanceof Array;if(s||i.tag){const t=s?i:[i];l.setListWithFn(t,e.LeafBoundsHelper.worldBounds)}else{const e=function(e,t){let i,{x:s,y:o,width:n,height:h}=e;return h||(h=n*(t.height/t.width),i=!0),n||(n=h*(t.width/t.height),i=!0),i?{x:s,y:o,width:n,height:h}:e}(i,r);l.set(a.getWorldBounds(e))}const{width:h,height:c}=l;let y=r.x-l.x,x=r.y-l.y;return o?(y+=Math.max((r.width-h)/2,0),x+=Math.max((r.height-c)/2,0)):(d=this.getValidScale(Math.min(r.width/h,r.height/c)),y+=(r.width-h*d)/2,x+=(r.height-c*d)/2,e.PointHelper.scaleOf(t,l,d),l.scaleOf(l,d),t.scaleX*=d,t.scaleY*=d),"x"===o?x=0:"y"===o&&(y=0),e.PointHelper.move(t,y,x),l.move(y,x),a.set(t,n),l}return a.worldBoxBounds};
1
+ "use strict";var t=require("@leafer-ui/draw");function e(t,e){let i=1;const s="out"===e,h=Math.abs(t);if(h>1){for(;s?i<h:i<=h;)i*=2;s&&(i/=2)}else{for(;s?i>=h:i>h;)i/=2;s||(i*=2)}return i/t}t.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,s,h,o){let n;this.killAnimate(),t.isData(s)?(n=s.padding,h=s.scroll,o=s.transition):n=s;const{zoomLayer:a}=this,l=this.canvas.bounds.clone().shrink(t.isNull(n)?30:n),r=new t.Bounds,d={x:l.x+l.width/2,y:l.y+l.height/2};let c;const{x:u,y:f,scaleX:w,scaleY:g}=a.__;if(t.isString(i))switch(i){case"in":c=e(w,"in");break;case"out":c=e(w,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else t.isNumber(i)&&(c=i/w);if(c)c=this.getValidScale(c),a.scaleOfWorld(d,c,c,!1,o);else if(t.isObject(i)){const e={x:u,y:f,scaleX:w,scaleY:g},s=t.isArray(i);if(s||i.tag){const e=s?i:[i];r.setListWithFn(e,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:h,width:o,height:n}=t;return n||(n=o*(e.height/e.width),i=!0),o||(o=n*(e.width/e.height),i=!0),i?{x:s,y:h,width:o,height:n}:t}(i,l);r.set(a.getWorldBounds(t))}const{width:n,height:d}=r;let x=l.x-r.x,y=l.y-r.y;return h?(x+=Math.max((l.width-n)/2,0),y+=Math.max((l.height-d)/2,0)):(c=this.getValidScale(Math.min(l.width/n,l.height/d)),x+=(l.width-n*c)/2,y+=(l.height-d*c)/2,t.PointHelper.scaleOf(e,r,c),r.scaleOf(r,c),e.scaleX*=c,e.scaleY*=c),"x"===h?y=0:"y"===h&&(x=0),t.PointHelper.move(e,x,y),r.move(x,y),a.set(e,o),r}return a.worldBoxBounds};
2
2
  //# sourceMappingURL=view.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.min.cjs","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (typeof zoomType === 'string') {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (typeof zoomType === 'number') {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (typeof zoomType === 'object') {\n\n const data = { x, y, scaleX, scaleY }\n const isArray = zoomType instanceof Array\n\n if (isArray || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArray ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","Array","zoomLayer","limitBounds","canvas","bounds","clone","shrink","undefined","Bounds","center","x","width","y","height","changeScale","scaleY","__","boxBounds","getValidScale","scaleOfWorld","data","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"8CAGgB,SAAAA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,OACf,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,GAEvB,OAAOA,EAAQF,CACnB,CCRAO,EAAAA,OAAOC,IAAI,QAGXC,EAAAA,OAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAI2B,iBAArBL,GAAmCA,aAA4BM,MAInEH,EAAUH,GAHbG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAGlC,MAAMK,UAAEA,GAAcH,KAChBI,EAAcJ,KAAKK,OAAOC,OAAOC,QAAQC,YAAmBC,IAAZV,EAAwBA,EAAU,IAAKO,EAAS,IAAII,EAAAA,OACpGC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAMJ,EAAEA,EAACE,EAAEA,EAAC/B,OAAEA,EAAMkC,OAAEA,GAAWd,EAAUe,GAE3C,GAAwB,iBAAbvB,EAEP,OAAQA,GACJ,IAAK,KACDqB,EAAclC,EAAaC,EAAQ,MACnC,MACJ,IAAK,MACDiC,EAAclC,EAAaC,EAAQ,OACnC,MACJ,IAAK,MACDY,EAAWK,KAAKmB,UAChB,MAC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T,EAAYW,OAASA,IAC1FoB,IAAU/B,EAAYS,MAAQA,EAAQG,GAAe,EACrDoB,IAAUhC,EAAYW,OAASA,EAASC,GAAe,EAEvDuB,EAAAA,YAAYC,QAAQlB,EAAMhB,EAAQU,GAClCV,EAAOkC,QAAQlC,EAAQU,GAEvBM,EAAKvC,QAAUiC,EACfM,EAAKL,QAAUD,GAGJ,MAAXnB,EAAgBuC,EAAQ,EACR,MAAXvC,IAAgBsC,EAAQ,GAEjCI,EAAAA,YAAYE,KAAKnB,EAAMa,EAAOC,GAC9B9B,EAAOmC,KAAKN,EAAOC,GAEnBjC,EAAU8B,IAAIX,EAAMxB,GAEbQ,EAIX,OAAOH,EAAUuC,cAErB"}
1
+ {"version":3,"file":"view.min.cjs","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","isData","zoomLayer","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","scaleY","__","isString","boxBounds","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"8CAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,EAAQF,CACnB,CCRAO,EAAAA,OAAOC,IAAI,QAGXC,EAAAA,OAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAIDC,EAAAA,OAAqBN,IACrBG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OA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leafer.prototype.zoom=function(i,s,o,n){let h;this.killAnimate(),"object"!=typeof s||s instanceof Array?h=s:(h=s.padding,o=s.scroll,n=s.transition);const{zoomLayer:a}=this,c=this.canvas.bounds.clone().shrink(void 0!==h?h:30),l=new t.Bounds,r={x:c.x+c.width/2,y:c.y+c.height/2};let d;const{x:f,y:u,scaleX:g,scaleY:w}=a.__;if("string"==typeof i)switch(i){case"in":d=e(g,"in");break;case"out":d=e(g,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else"number"==typeof i&&(d=i/g);if(d)d=this.getValidScale(d),a.scaleOfWorld(r,d,d,!1,n);else if("object"==typeof i){const e={x:f,y:u,scaleX:g,scaleY:w},s=i instanceof Array;if(s||i.tag){const e=s?i:[i];l.setListWithFn(e,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:o,width:n,height:h}=t;return h||(h=n*(e.height/e.width),i=!0),n||(n=h*(e.width/e.height),i=!0),i?{x:s,y:o,width:n,height:h}:t}(i,c);l.set(a.getWorldBounds(t))}const{width:h,height:r}=l;let y=c.x-l.x,x=c.y-l.y;return o?(y+=Math.max((c.width-h)/2,0),x+=Math.max((c.height-r)/2,0)):(d=this.getValidScale(Math.min(c.width/h,c.height/r)),y+=(c.width-h*d)/2,x+=(c.height-r*d)/2,t.PointHelper.scaleOf(e,l,d),l.scaleOf(l,d),e.scaleX*=d,e.scaleY*=d),"x"===o?x=0:"y"===o&&(y=0),t.PointHelper.move(e,y,x),l.move(y,x),a.set(e,n),l}return a.worldBoxBounds}}(LeaferUI);
1
+ !function(t){"use strict";function e(t,e){let i=1;const s="out"===e,h=Math.abs(t);if(h>1){for(;s?i<h:i<=h;)i*=2;s&&(i/=2)}else{for(;s?i>=h:i>h;)i/=2;s||(i*=2)}return i/t}t.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,s,h,n){let o;this.killAnimate(),t.isData(s)?(o=s.padding,h=s.scroll,n=s.transition):o=s;const{zoomLayer:a}=this,l=this.canvas.bounds.clone().shrink(t.isNull(o)?30:o),c=new t.Bounds,r={x:l.x+l.width/2,y:l.y+l.height/2};let d;const{x:u,y:f,scaleX:g,scaleY:w}=a.__;if(t.isString(i))switch(i){case"in":d=e(g,"in");break;case"out":d=e(g,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else t.isNumber(i)&&(d=i/g);if(d)d=this.getValidScale(d),a.scaleOfWorld(r,d,d,!1,n);else if(t.isObject(i)){const e={x:u,y:f,scaleX:g,scaleY:w},s=t.isArray(i);if(s||i.tag){const e=s?i:[i];c.setListWithFn(e,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:h,width:n,height:o}=t;return o||(o=n*(e.height/e.width),i=!0),n||(n=o*(e.width/e.height),i=!0),i?{x:s,y:h,width:n,height:o}:t}(i,l);c.set(a.getWorldBounds(t))}const{width:o,height:r}=c;let x=l.x-c.x,y=l.y-c.y;return h?(x+=Math.max((l.width-o)/2,0),y+=Math.max((l.height-r)/2,0)):(d=this.getValidScale(Math.min(l.width/o,l.height/r)),x+=(l.width-o*d)/2,y+=(l.height-r*d)/2,t.PointHelper.scaleOf(e,c,d),c.scaleOf(c,d),e.scaleX*=d,e.scaleY*=d),"x"===h?y=0:"y"===h&&(x=0),t.PointHelper.move(e,x,y),c.move(x,y),a.set(e,n),c}return a.worldBoxBounds}}(LeaferUI);
2
2
  //# sourceMappingURL=view.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (typeof zoomType === 'string') {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (typeof zoomType === 'number') {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (typeof zoomType === 'object') {\n\n const data = { x, y, scaleX, scaleY }\n const isArray = zoomType instanceof Array\n\n if (isArray || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArray ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","Array","zoomLayer","limitBounds","canvas","bounds","clone","shrink","undefined","Bounds","center","x","width","y","height","changeScale","scaleY","__","boxBounds","getValidScale","scaleOfWorld","data","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","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AAQU,GAClCV,EAAOkC,QAAQlC,EAAQU,GAEvBM,EAAKvC,QAAUiC,EACfM,EAAKL,QAAUD,GAGJ,MAAXnB,EAAgBuC,EAAQ,EACR,MAAXvC,IAAgBsC,EAAQ,GAEjCI,EAAAA,YAAYE,KAAKnB,EAAMa,EAAOC,GAC9B9B,EAAOmC,KAAKN,EAAOC,GAEnBjC,EAAU8B,IAAIX,EAAMxB,GAEbQ,EAIX,OAAOH,EAAUuC,cAErB"}
1
+ {"version":3,"file":"view.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","isData","zoomLayer","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","scaleY","__","isString","boxBounds","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"0BAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,EAAQF,CACnB,CCRAO,EAAAA,OAAOC,IAAI,QAGXC,EAAAA,OAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAIDC,EAAAA,OAAqBN,IACrBG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAC3BC,EAAUH,EAEjB,MAAMO,UAAEA,GAAcH,KAChBI,EAAcJ,KAAKK,OAAOC,OAAOC,QAAQC,OAAOC,EAAAA,OAAOV,GAAW,GAAKA,GA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IAAGE,IAAGD,QAAOE,UAAWT,CAC3C,CC+CgC8B,CAAazC,EAAyBS,GAC1DE,EAAO+B,IAAIlC,EAAUmC,eAAeL,GACxC,CAEA,MAAMpB,MAAEA,EAAKE,OAAEA,GAAWT,EAC1B,IAAIiC,EAAQnC,EAAYQ,EAAIN,EAAOM,EAAG4B,EAAQpC,EAAYU,EAAIR,EAAOQ,EA4BrE,OA1BIjB,GAEA0C,GAASnD,KAAKqD,KAAKrC,EAAYS,MAAQA,GAAS,EAAG,GACnD2B,GAASpD,KAAKqD,KAAKrC,EAAYW,OAASA,GAAU,EAAG,KAIrDC,EAAchB,KAAKsB,cAAclC,KAAKsD,IAAItC,EAAYS,MAAQA,EAAOT,EAAYW,OAASA,IAC1FwB,IAAUnC,EAAYS,MAAQA,EAAQG,GAAe,EACrDwB,IAAUpC,EAAYW,OAASA,EAASC,GAAe,EAEvD2B,EAAAA,YAAYC,QAAQnB,EAAMnB,EAAQU,GAClCV,EAAOsC,QAAQtC,EAAQU,GAEvBS,EAAK1C,QAAUiC,EACfS,EAAKR,QAAUD,GAGJ,MAAXnB,EAAgB2C,EAAQ,EACR,MAAX3C,IAAgB0C,EAAQ,GAEjCI,EAAAA,YAAYE,KAAKpB,EAAMc,EAAOC,GAC9BlC,EAAOuC,KAAKN,EAAOC,GAEnBrC,EAAUkC,IAAIZ,EAAM3B,GAEbQ,CAEX,CAEA,OAAOH,EAAU2C,cAErB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/view",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "@leafer-in/view",
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/draw": "^1.8.0",
38
- "@leafer-ui/interface": "^1.8.0",
39
- "@leafer-in/interface": "^1.8.0"
37
+ "@leafer-ui/draw": "^1.9.1",
38
+ "@leafer-ui/interface": "^1.9.1",
39
+ "@leafer-in/interface": "^1.9.1"
40
40
  }
41
41
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'
2
- import { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper } from '@leafer-ui/draw'
2
+ import { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'
3
3
 
4
4
  import { getFixBounds, getZoomScale } from './helper'
5
5
 
@@ -13,20 +13,20 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomO
13
13
 
14
14
  let padding: IFourNumber
15
15
 
16
- if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
16
+ if (isData<IZoomOptions>(optionsOrPadding)) {
17
17
  padding = optionsOrPadding.padding
18
18
  scroll = optionsOrPadding.scroll
19
19
  transition = optionsOrPadding.transition
20
20
  } else padding = optionsOrPadding
21
21
 
22
22
  const { zoomLayer } = this
23
- const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds()
23
+ const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()
24
24
  const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }
25
25
 
26
26
  let changeScale: number
27
27
  const { x, y, scaleX, scaleY } = zoomLayer.__
28
28
 
29
- if (typeof zoomType === 'string') {
29
+ if (isString(zoomType)) {
30
30
 
31
31
  switch (zoomType) {
32
32
  case 'in':
@@ -48,7 +48,7 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomO
48
48
  break
49
49
  }
50
50
 
51
- } else if (typeof zoomType === 'number') {
51
+ } else if (isNumber(zoomType)) {
52
52
  changeScale = zoomType / scaleX
53
53
  }
54
54
 
@@ -58,13 +58,13 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomO
58
58
  changeScale = this.getValidScale(changeScale)
59
59
  zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)
60
60
 
61
- } else if (typeof zoomType === 'object') {
61
+ } else if (isObject(zoomType)) {
62
62
 
63
63
  const data = { x, y, scaleX, scaleY }
64
- const isArray = zoomType instanceof Array
64
+ const isArr = isArray(zoomType)
65
65
 
66
- if (isArray || (zoomType as ILeaf).tag) {
67
- const list: ILeaf[] = isArray ? zoomType as ILeaf[] : [zoomType as ILeaf]
66
+ if (isArr || (zoomType as ILeaf).tag) {
67
+ const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]
68
68
  bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)
69
69
  } else {
70
70
  const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { };