@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 +67 -64
- package/dist/view.esm.js +66 -63
- package/dist/view.esm.min.js +1 -1
- package/dist/view.esm.min.js.map +1 -1
- package/dist/view.js +65 -67
- package/dist/view.min.cjs +1 -1
- package/dist/view.min.cjs.map +1 -1
- package/dist/view.min.js +1 -1
- package/dist/view.min.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +9 -9
- package/types/index.d.ts +1 -1
package/dist/view.cjs
CHANGED
|
@@ -1,96 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var draw = require(
|
|
3
|
+
var draw = require("@leafer-ui/draw");
|
|
4
4
|
|
|
5
5
|
function getZoomScale(scaleX, type) {
|
|
6
6
|
let scale = 1;
|
|
7
|
-
const out = type ===
|
|
7
|
+
const out = type === "out", absScale = Math.abs(scaleX);
|
|
8
8
|
if (absScale > 1) {
|
|
9
|
-
while (out ? scale < absScale : scale <= absScale)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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(
|
|
33
|
-
|
|
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 (
|
|
36
|
+
if (draw.isData(optionsOrPadding)) {
|
|
37
37
|
padding = optionsOrPadding.padding;
|
|
38
38
|
scroll = optionsOrPadding.scroll;
|
|
39
39
|
transition = optionsOrPadding.transition;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
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 (
|
|
48
|
+
const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
|
|
49
|
+
if (draw.isString(zoomType)) {
|
|
49
50
|
switch (zoomType) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 ===
|
|
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
|
|
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 ===
|
|
5
|
+
const out = type === "out", absScale = Math.abs(scaleX);
|
|
6
6
|
if (absScale > 1) {
|
|
7
|
-
while (out ? scale < absScale : scale <= absScale)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
31
|
-
|
|
29
|
+
Plugin.add("view");
|
|
30
|
+
|
|
31
|
+
Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
|
|
32
32
|
this.killAnimate();
|
|
33
33
|
let padding;
|
|
34
|
-
if (
|
|
34
|
+
if (isData(optionsOrPadding)) {
|
|
35
35
|
padding = optionsOrPadding.padding;
|
|
36
36
|
scroll = optionsOrPadding.scroll;
|
|
37
37
|
transition = optionsOrPadding.transition;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
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 (
|
|
46
|
+
const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
|
|
47
|
+
if (isString(zoomType)) {
|
|
47
48
|
switch (zoomType) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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 ===
|
|
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);
|
package/dist/view.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Plugin as t,Leafer as e,
|
|
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
|
package/dist/view.esm.min.js.map
CHANGED
|
@@ -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 (
|
|
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,CCRAO,EAAOC,IAAI,QAGXC,EAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAIDC,EAAqBN,IACrBG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAC3BC,EAAUH,EAEjB,MAAMO,UAAEA,GAAcH,KAChBI,EAAcJ,KAAKK,OAAOC,OAAOC,QAAQC,OAAOC,EAAOV,GAAW,GAAKA,GAAUO,EAAS,IAAII,EAC9FC,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,GAAIC,EAASxB,GAET,O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QA,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,EAAYC,QAAQnB,EAAMnB,EAAQU,GAClCV,EAAOsC,QAAQtC,EAAQU,GAEvBS,EAAK1C,QAAUiC,EACfS,EAAKR,QAAUD,GAGJ,MAAXnB,EAAgB2C,EAAQ,EACR,MAAX3C,IAAgB0C,EAAQ,GAEjCI,EAAYE,KAAKpB,EAAMc,EAAOC,GAC9BlC,EAAOuC,KAAKN,EAAOC,GAEnBrC,EAAUkC,IAAIZ,EAAM3B,GAEbQ,CAEX,CAEA,OAAOH,EAAU2C,cAErB"}
|
package/dist/view.js
CHANGED
|
@@ -1,95 +1,97 @@
|
|
|
1
|
-
(function
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
(function(draw) {
|
|
2
|
+
"use strict";
|
|
4
3
|
function getZoomScale(scaleX, type) {
|
|
5
4
|
let scale = 1;
|
|
6
|
-
const out = type ===
|
|
5
|
+
const out = type === "out", absScale = Math.abs(scaleX);
|
|
7
6
|
if (absScale > 1) {
|
|
8
|
-
while (out ? scale < absScale : scale <= absScale)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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.
|
|
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 (
|
|
31
|
+
if (draw.isData(optionsOrPadding)) {
|
|
36
32
|
padding = optionsOrPadding.padding;
|
|
37
33
|
scroll = optionsOrPadding.scroll;
|
|
38
34
|
transition = optionsOrPadding.transition;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
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 (
|
|
43
|
+
const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
|
|
44
|
+
if (draw.isString(zoomType)) {
|
|
48
45
|
switch (zoomType) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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 ===
|
|
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
|
|
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
|
package/dist/view.min.cjs.map
CHANGED
|
@@ -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 (
|
|
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","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Ae,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/dist/view.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t){"use strict";function e(t,e){let i=1;const s="out"===e,
|
|
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
|
package/dist/view.min.js.map
CHANGED
|
@@ -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 (
|
|
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,GAAUO,EAAS,IAAII,EAAAA,OAC9FC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAMJ,EAAEA,E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IiC,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.
|
|
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.
|
|
38
|
-
"@leafer-ui/interface": "^1.
|
|
39
|
-
"@leafer-in/interface": "^1.
|
|
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 (
|
|
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
|
|
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 (
|
|
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 (
|
|
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 (
|
|
61
|
+
} else if (isObject(zoomType)) {
|
|
62
62
|
|
|
63
63
|
const data = { x, y, scaleX, scaleY }
|
|
64
|
-
const
|
|
64
|
+
const isArr = isArray(zoomType)
|
|
65
65
|
|
|
66
|
-
if (
|
|
67
|
-
const list: 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 { };
|