@leafer-in/view 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/view.cjs +19 -12
- package/dist/view.cjs.map +1 -1
- package/dist/view.esm.js +20 -13
- package/dist/view.esm.js.map +1 -1
- package/dist/view.esm.min.js +1 -1
- package/dist/view.esm.min.js.map +1 -1
- package/dist/view.js +19 -12
- package/dist/view.js.map +1 -1
- 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 +25 -13
package/dist/view.cjs
CHANGED
|
@@ -30,7 +30,8 @@ function getFixBounds(bounds, scaleBounds) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
draw.Plugin.add('view');
|
|
33
|
-
draw.Leafer.prototype.zoom = function (zoomType, padding, fixed) {
|
|
33
|
+
draw.Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
|
|
34
|
+
this.killAnimate();
|
|
34
35
|
const { zoomLayer } = this;
|
|
35
36
|
const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new draw.Bounds();
|
|
36
37
|
const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
|
|
@@ -61,10 +62,12 @@ draw.Leafer.prototype.zoom = function (zoomType, padding, fixed) {
|
|
|
61
62
|
changeScale = zoomType / scaleX;
|
|
62
63
|
}
|
|
63
64
|
if (changeScale) {
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
changeScale = this.getValidScale(changeScale);
|
|
66
|
+
zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
|
|
66
67
|
}
|
|
67
68
|
else if (typeof zoomType === 'object') {
|
|
69
|
+
const { x, y, scaleX, scaleY } = zoomLayer;
|
|
70
|
+
const data = { x, y, scaleX, scaleY };
|
|
68
71
|
const isArray = zoomType instanceof Array;
|
|
69
72
|
if (isArray || zoomType.tag) {
|
|
70
73
|
const list = isArray ? zoomType : [zoomType];
|
|
@@ -74,21 +77,25 @@ draw.Leafer.prototype.zoom = function (zoomType, padding, fixed) {
|
|
|
74
77
|
const innerBounds = getFixBounds(zoomType, limitBounds);
|
|
75
78
|
bounds.set(zoomLayer.getWorldBounds(innerBounds));
|
|
76
79
|
}
|
|
77
|
-
const {
|
|
78
|
-
let moveX = limitBounds.x - x, moveY = limitBounds.y - y;
|
|
80
|
+
const { width, height } = bounds;
|
|
81
|
+
let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
|
|
79
82
|
if (fixed) {
|
|
80
83
|
moveX += Math.max((limitBounds.width - width) / 2, 0);
|
|
81
84
|
moveY += Math.max((limitBounds.height - height) / 2, 0);
|
|
82
85
|
}
|
|
83
86
|
else {
|
|
84
|
-
|
|
85
|
-
moveX += (limitBounds.width - width *
|
|
86
|
-
moveY += (limitBounds.height - height *
|
|
87
|
-
|
|
88
|
-
bounds.scaleOf(bounds,
|
|
87
|
+
changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height));
|
|
88
|
+
moveX += (limitBounds.width - width * changeScale) / 2;
|
|
89
|
+
moveY += (limitBounds.height - height * changeScale) / 2;
|
|
90
|
+
draw.PointHelper.scaleOf(data, bounds, changeScale);
|
|
91
|
+
bounds.scaleOf(bounds, changeScale);
|
|
92
|
+
data.scaleX *= changeScale;
|
|
93
|
+
data.scaleY *= changeScale;
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
draw.PointHelper.move(data, moveX, moveY);
|
|
96
|
+
bounds.move(moveX, moveY);
|
|
97
|
+
zoomLayer.set(data, transition);
|
|
98
|
+
return bounds;
|
|
92
99
|
}
|
|
93
100
|
return zoomLayer.worldBoxBounds;
|
|
94
101
|
};
|
package/dist/view.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.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, IFourNumber, IPointData } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {\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 { scaleX } = this.__\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
|
|
1
|
+
{"version":3,"file":"view.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, 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, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\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 { scaleX } = this.__\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 { x, y, scaleX, scaleY } = zoomLayer\n const data = { x, y, scaleX, scaleY }\n\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 (fixed) {\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 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":["Plugin","Leafer","Bounds","LeafBoundsHelper","PointHelper"],"mappings":";;;;AAGgB,SAAA,YAAY,CAAC,MAAc,EAAE,IAAkB,EAAA;IAC3D,IAAI,KAAK,GAAG,CAAC;AACb,IAAA,MAAM,GAAG,GAAG,IAAI,KAAK,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;AACvD,IAAA,IAAI,QAAQ,GAAG,CAAC,EAAE;A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AG,WAAW,IAAI,CAAC;AACtD,YAAA,KAAK,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,MAAM,GAAG,WAAW,IAAI,CAAC;YAExDC,gBAAW,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC;AAC9C,YAAA,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC;AAEnC,YAAA,IAAI,CAAC,MAAM,IAAI,WAAW;AAC1B,YAAA,IAAI,CAAC,MAAM,IAAI,WAAW;;QAG9BA,gBAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC;AACpC,QAAA,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;AAEzB,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC;AAE/B,QAAA,OAAO,MAAM;;IAIjB,OAAO,SAAS,CAAC,cAAc;AAEnC,CAAC;;"}
|
package/dist/view.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin, Leafer, Bounds, LeafBoundsHelper } from '@leafer-ui/draw';
|
|
1
|
+
import { Plugin, Leafer, Bounds, LeafBoundsHelper, PointHelper } from '@leafer-ui/draw';
|
|
2
2
|
|
|
3
3
|
function getZoomScale(scaleX, type) {
|
|
4
4
|
let scale = 1;
|
|
@@ -28,7 +28,8 @@ function getFixBounds(bounds, scaleBounds) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
Plugin.add('view');
|
|
31
|
-
Leafer.prototype.zoom = function (zoomType, padding, fixed) {
|
|
31
|
+
Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
|
|
32
|
+
this.killAnimate();
|
|
32
33
|
const { zoomLayer } = this;
|
|
33
34
|
const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
|
|
34
35
|
const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
|
|
@@ -59,10 +60,12 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed) {
|
|
|
59
60
|
changeScale = zoomType / scaleX;
|
|
60
61
|
}
|
|
61
62
|
if (changeScale) {
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
changeScale = this.getValidScale(changeScale);
|
|
64
|
+
zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
|
|
64
65
|
}
|
|
65
66
|
else if (typeof zoomType === 'object') {
|
|
67
|
+
const { x, y, scaleX, scaleY } = zoomLayer;
|
|
68
|
+
const data = { x, y, scaleX, scaleY };
|
|
66
69
|
const isArray = zoomType instanceof Array;
|
|
67
70
|
if (isArray || zoomType.tag) {
|
|
68
71
|
const list = isArray ? zoomType : [zoomType];
|
|
@@ -72,21 +75,25 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed) {
|
|
|
72
75
|
const innerBounds = getFixBounds(zoomType, limitBounds);
|
|
73
76
|
bounds.set(zoomLayer.getWorldBounds(innerBounds));
|
|
74
77
|
}
|
|
75
|
-
const {
|
|
76
|
-
let moveX = limitBounds.x - x, moveY = limitBounds.y - y;
|
|
78
|
+
const { width, height } = bounds;
|
|
79
|
+
let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
|
|
77
80
|
if (fixed) {
|
|
78
81
|
moveX += Math.max((limitBounds.width - width) / 2, 0);
|
|
79
82
|
moveY += Math.max((limitBounds.height - height) / 2, 0);
|
|
80
83
|
}
|
|
81
84
|
else {
|
|
82
|
-
|
|
83
|
-
moveX += (limitBounds.width - width *
|
|
84
|
-
moveY += (limitBounds.height - height *
|
|
85
|
-
|
|
86
|
-
bounds.scaleOf(bounds,
|
|
85
|
+
changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height));
|
|
86
|
+
moveX += (limitBounds.width - width * changeScale) / 2;
|
|
87
|
+
moveY += (limitBounds.height - height * changeScale) / 2;
|
|
88
|
+
PointHelper.scaleOf(data, bounds, changeScale);
|
|
89
|
+
bounds.scaleOf(bounds, changeScale);
|
|
90
|
+
data.scaleX *= changeScale;
|
|
91
|
+
data.scaleY *= changeScale;
|
|
87
92
|
}
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
PointHelper.move(data, moveX, moveY);
|
|
94
|
+
bounds.move(moveX, moveY);
|
|
95
|
+
zoomLayer.set(data, transition);
|
|
96
|
+
return bounds;
|
|
90
97
|
}
|
|
91
98
|
return zoomLayer.worldBoxBounds;
|
|
92
99
|
};
|
package/dist/view.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.esm.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, IFourNumber, IPointData } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {\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 { scaleX } = this.__\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
|
|
1
|
+
{"version":3,"file":"view.esm.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, 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, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\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 { scaleX } = this.__\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 { x, y, scaleX, scaleY } = zoomLayer\n const data = { x, y, scaleX, scaleY }\n\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 (fixed) {\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 PointHelper.move(data, mo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AC;AACrD,YAAA,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;;aAEpD;YAEH,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,GAAG,KAAK,EAAE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAClG,YAAA,KAAK,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,KAAK,GAAG,WAAW,IAAI,CAAC;AACtD,YAAA,KAAK,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,MAAM,GAAG,WAAW,IAAI,CAAC;YAExD,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC;AAC9C,YAAA,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC;AAEnC,YAAA,IAAI,CAAC,MAAM,IAAI,WAAW;AAC1B,YAAA,IAAI,CAAC,MAAM,IAAI,WAAW;;QAG9B,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC;AACpC,QAAA,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;AAEzB,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC;AAE/B,QAAA,OAAO,MAAM;;IAIjB,OAAO,SAAS,CAAC,cAAc;AAEnC,CAAC"}
|
package/dist/view.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Plugin as t,Leafer as e,Bounds as i,LeafBoundsHelper as
|
|
1
|
+
import{Plugin as t,Leafer as e,Bounds as i,LeafBoundsHelper as s,PointHelper as h}from"@leafer-ui/draw";function o(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,a,n){this.killAnimate();const{zoomLayer:c}=this,l=this.canvas.bounds.clone().shrink(void 0!==e?e:30),r=new i,d={x:l.x+l.width/2,y:l.y+l.height/2};let f;const{scaleX:u}=this.__;if("string"==typeof t)switch(t){case"in":f=o(u,"in");break;case"out":f=o(u,"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&&(f=t/u);if(f)f=this.getValidScale(f),c.scaleOfWorld(d,f,f,!1,n);else if("object"==typeof t){const{x:e,y:i,scaleX:o,scaleY:d}=c,u={x:e,y:i,scaleX:o,scaleY:d},w=t instanceof Array;if(w||t.tag){const e=w?t:[t];r.setListWithFn(e,s.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,l);r.set(c.getWorldBounds(e))}const{width:g,height:x}=r;let y=l.x-r.x,b=l.y-r.y;return a?(y+=Math.max((l.width-g)/2,0),b+=Math.max((l.height-x)/2,0)):(f=this.getValidScale(Math.min(l.width/g,l.height/x)),y+=(l.width-g*f)/2,b+=(l.height-x*f)/2,h.scaleOf(u,r,f),r.scaleOf(r,f),u.scaleX*=f,u.scaleY*=f),h.move(u,y,b),r.move(y,b),c.set(u,n),r}return c.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, IFourNumber, IPointData } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {\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 { scaleX } = this.__\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
|
|
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, 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, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\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 { scaleX } = this.__\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 { x, y, scaleX, scaleY } = zoomLayer\n const data = { x, y, scaleX, scaleY }\n\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 (fixed) {\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 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","padding","fixed","transition","this","killAnimate","zoomLayer","limitBounds","canvas","bounds","clone","shrink","undefined","Bounds","center","x","width","y","height","changeScale","__","boxBounds","getValidScale","scaleOfWorld","scaleY","data","isArray","Array","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,EA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.zoom = function (zoomType, padding, fixed) {
|
|
32
|
+
draw.Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
|
|
33
|
+
this.killAnimate();
|
|
33
34
|
const { zoomLayer } = this;
|
|
34
35
|
const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new draw.Bounds();
|
|
35
36
|
const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
|
|
@@ -60,10 +61,12 @@
|
|
|
60
61
|
changeScale = zoomType / scaleX;
|
|
61
62
|
}
|
|
62
63
|
if (changeScale) {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
changeScale = this.getValidScale(changeScale);
|
|
65
|
+
zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition);
|
|
65
66
|
}
|
|
66
67
|
else if (typeof zoomType === 'object') {
|
|
68
|
+
const { x, y, scaleX, scaleY } = zoomLayer;
|
|
69
|
+
const data = { x, y, scaleX, scaleY };
|
|
67
70
|
const isArray = zoomType instanceof Array;
|
|
68
71
|
if (isArray || zoomType.tag) {
|
|
69
72
|
const list = isArray ? zoomType : [zoomType];
|
|
@@ -73,21 +76,25 @@
|
|
|
73
76
|
const innerBounds = getFixBounds(zoomType, limitBounds);
|
|
74
77
|
bounds.set(zoomLayer.getWorldBounds(innerBounds));
|
|
75
78
|
}
|
|
76
|
-
const {
|
|
77
|
-
let moveX = limitBounds.x - x, moveY = limitBounds.y - y;
|
|
79
|
+
const { width, height } = bounds;
|
|
80
|
+
let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
|
|
78
81
|
if (fixed) {
|
|
79
82
|
moveX += Math.max((limitBounds.width - width) / 2, 0);
|
|
80
83
|
moveY += Math.max((limitBounds.height - height) / 2, 0);
|
|
81
84
|
}
|
|
82
85
|
else {
|
|
83
|
-
|
|
84
|
-
moveX += (limitBounds.width - width *
|
|
85
|
-
moveY += (limitBounds.height - height *
|
|
86
|
-
|
|
87
|
-
bounds.scaleOf(bounds,
|
|
86
|
+
changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height));
|
|
87
|
+
moveX += (limitBounds.width - width * changeScale) / 2;
|
|
88
|
+
moveY += (limitBounds.height - height * changeScale) / 2;
|
|
89
|
+
draw.PointHelper.scaleOf(data, bounds, changeScale);
|
|
90
|
+
bounds.scaleOf(bounds, changeScale);
|
|
91
|
+
data.scaleX *= changeScale;
|
|
92
|
+
data.scaleY *= changeScale;
|
|
88
93
|
}
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
draw.PointHelper.move(data, moveX, moveY);
|
|
95
|
+
bounds.move(moveX, moveY);
|
|
96
|
+
zoomLayer.set(data, transition);
|
|
97
|
+
return bounds;
|
|
91
98
|
}
|
|
92
99
|
return zoomLayer.worldBoxBounds;
|
|
93
100
|
};
|
package/dist/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.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, IFourNumber, IPointData } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {\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 { scaleX } = this.__\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
|
|
1
|
+
{"version":3,"file":"view.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, 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, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\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 { scaleX } = this.__\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 { x, y, scaleX, scaleY } = zoomLayer\n const data = { x, y, scaleX, scaleY }\n\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 (fixed) {\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 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":["Plugin","Leafer","Bounds","LeafBoundsHelper","PointHelper"],"mappings":";;;IAGgB,SAAA,YAAY,CAAC,MAAc,EAAE,IAAkB,EAAA;QAC3D,IAAI,KAAK,GAAG,CAAC;IACb,IAAA,MAAM,GAAG,GAAG,IAAI,KAAK,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACvD,IAAA,IAAI,QAAQ,GAAG,CAAC,EAAE;IACd,QAAA,OAAO,GAAG,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,IAAI,QAAQ;gBAAE,KAAK,IAAI,CAAC;IAC7D,QAAA,IAAI,GAAG;gBAAE,KAAK,IAAI,CAAC;;aAChB;IACH,QAAA,OAAO,GAAG,GAAG,KAAK,IAAI,QAAQ,GAAG,KAAK,GAAG,QAAQ;gBAAE,KAAK,IAAI,CAAC;IAC7D,QAAA,IAAI,CAAC,GAAG;gBAAE,KAAK,IAAI,CAAC;;QAExB,OAAO,KAAK,GAAG,MAAM;IACzB;IAEgB,SAAA,YAAY,CAAC,MAAmB,EAAE,WAAwB,EAAA;QACtE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IACpC,IAAA,IAAI,GAAY;IAChB,IAAA,IAAI,CAAC,MAAM;IAAE,QAAA,MAAM,GAAG,KAAK,IAAI,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI;IAClF,I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1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
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,h){this.killAnimate();const{zoomLayer:n}=this,a=this.canvas.bounds.clone().shrink(void 0!==s?s:30),r=new e.Bounds,l={x:a.x+a.width/2,y:a.y+a.height/2};let c;const{scaleX:d}=this.__;if("string"==typeof i)switch(i){case"in":c=t(d,"in");break;case"out":c=t(d,"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&&(c=i/d);if(c)c=this.getValidScale(c),n.scaleOfWorld(l,c,c,!1,h);else if("object"==typeof i){const{x:t,y:s,scaleX:l,scaleY:d}=n,u={x:t,y:s,scaleX:l,scaleY:d},f=i instanceof Array;if(f||i.tag){const t=f?i:[i];r.setListWithFn(t,e.LeafBoundsHelper.worldBounds)}else{const e=function(e,t){let i,{x:s,y:o,width:h,height:n}=e;return n||(n=h*(t.height/t.width),i=!0),h||(h=n*(t.width/t.height),i=!0),i?{x:s,y:o,width:h,height:n}:e}(i,a);r.set(n.getWorldBounds(e))}const{width:w,height:g}=r;let x=a.x-r.x,y=a.y-r.y;return o?(x+=Math.max((a.width-w)/2,0),y+=Math.max((a.height-g)/2,0)):(c=this.getValidScale(Math.min(a.width/w,a.height/g)),x+=(a.width-w*c)/2,y+=(a.height-g*c)/2,e.PointHelper.scaleOf(u,r,c),r.scaleOf(r,c),u.scaleX*=c,u.scaleY*=c),e.PointHelper.move(u,x,y),r.move(x,y),n.set(u,h),r}return n.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, IFourNumber, IPointData } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {\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 { scaleX } = this.__\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
|
|
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, 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, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\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 { scaleX } = this.__\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 { x, y, scaleX, scaleY } = zoomLayer\n const data = { x, y, scaleX, scaleY }\n\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 (fixed) {\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 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","padding","fixed","transition","this","killAnimate","zoomLayer","limitBounds","canvas","bounds","clone","shrink","undefined","Bounds","center","x","width","y","height","changeScale","__","boxBounds","getValidScale","scaleOfWorld","scaleY","data","isArray","Array","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,EAAuBC,EAAiBC,GAE3FC,KAAKC,cAEL,MAAMC,UAAEA,GAAcF,KAChBG,EAAcH,KAAKI,OAAOC,OAAOC,QAAQC,YAAmBC,IAAZX,EAAwBA,EAAU,IAAKQ,EAAS,IAAII,EAAAA,OACpGC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAM/B,OAAEA,GAAWgB,KAAKgB,GAExB,GAAwB,iBAAbpB,EAEP,OAAQA,GACJ,IAAK,KACDmB,EAAchC,EAAaC,EAAQ,MACnC,MACJ,IAAK,MACD+B,EAAchC,EAAaC,EAAQ,OACnC,MACJ,IAAK,MACDY,EAAWI,KAAKiB,UAChB,MACJ,IAAK,aACDrB,EAAW,IAAIa,EAAAA,OAAOT,KAAKiB,YAClBH,OAAS,EAClB,MACJ,IAAK,cACDlB,EAAW,IAAIa,EAAAA,OAAOT,KAAKiB,YAClBL,MAAQ,MAIE,iBAAbhB,IACdmB,EAAcnB,EAAWZ,GAI7B,GAAI+B,EAEAA,EAAcf,KAAKkB,cAAcH,GACjCb,EAAUiB,aAAaT,EAAQK,EAAaA,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AKrC,QAAU+B,EACfM,EAAKD,QAAUL,GAGnBwB,EAAAA,YAAYE,KAAKpB,EAAMc,EAAOC,GAC9B/B,EAAOoC,KAAKN,EAAOC,GAEnBlC,EAAU+B,IAAIZ,EAAMtB,GAEbM,EAIX,OAAOH,EAAUwC,cAErB"}
|
package/dist/view.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t){"use strict";function e(t,e){let i=1;const
|
|
1
|
+
!function(t){"use strict";function e(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.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,s,o,h){this.killAnimate();const{zoomLayer:n}=this,a=this.canvas.bounds.clone().shrink(void 0!==s?s:30),c=new t.Bounds,l={x:a.x+a.width/2,y:a.y+a.height/2};let d;const{scaleX:r}=this.__;if("string"==typeof i)switch(i){case"in":d=e(r,"in");break;case"out":d=e(r,"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/r);if(d)d=this.getValidScale(d),n.scaleOfWorld(l,d,d,!1,h);else if("object"==typeof i){const{x:e,y:s,scaleX:l,scaleY:r}=n,u={x:e,y:s,scaleX:l,scaleY:r},f=i instanceof Array;if(f||i.tag){const e=f?i:[i];c.setListWithFn(e,t.LeafBoundsHelper.worldBounds)}else{const t=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}(i,a);c.set(n.getWorldBounds(t))}const{width:w,height:g}=c;let x=a.x-c.x,y=a.y-c.y;return o?(x+=Math.max((a.width-w)/2,0),y+=Math.max((a.height-g)/2,0)):(d=this.getValidScale(Math.min(a.width/w,a.height/g)),x+=(a.width-w*d)/2,y+=(a.height-g*d)/2,t.PointHelper.scaleOf(u,c,d),c.scaleOf(c,d),u.scaleX*=d,u.scaleY*=d),t.PointHelper.move(u,x,y),c.move(x,y),n.set(u,h),c}return n.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, IFourNumber, IPointData } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {\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 { scaleX } = this.__\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
|
|
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, 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, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\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 { scaleX } = this.__\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 { x, y, scaleX, scaleY } = zoomLayer\n const data = { x, y, scaleX, scaleY }\n\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 (fixed) {\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 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","padding","fixed","transition","this","killAnimate","zoomLayer","limitBounds","canvas","bounds","clone","shrink","undefined","Bounds","center","x","width","y","height","changeScale","__","boxBounds","getValidScale","scaleOfWorld","scaleY","data","isArray","Array","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"0BAGgB,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,EAAuBC,EAAiBC,GAE3FC,KAAKC,cAEL,MAAMC,UAAEA,GAAcF,KAChBG,EAAcH,KAAKI,OAAOC,OAAOC,QAAQC,YAAmBC,IAAZX,EAAwBA,EAAU,IAAKQ,EAAS,IAAII,EAAAA,OACpGC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAM/B,OAAEA,GAAWgB,KAAKgB,GAExB,GAAwB,iBAAbpB,EAEP,OAAQA,GACJ,IAAK,KACDmB,EAAchC,EAAaC,EAAQ,MACnC,MACJ,IAAK,MACD+B,EAAchC,EAAaC,EAAQ,OACnC,MACJ,IAAK,MACDY,EAAWI,KAAKiB,UAChB,MACJ,IAAK,aACDrB,EAAW,IAAIa,EAA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B,KAAKiD,IAAInC,EAAYS,MAAQA,EAAOT,EAAYW,OAASA,IAC1FqB,IAAUhC,EAAYS,MAAQA,EAAQG,GAAe,EACrDqB,IAAUjC,EAAYW,OAASA,EAASC,GAAe,EAEvDwB,EAAAA,YAAYC,QAAQnB,EAAMhB,EAAQU,GAClCV,EAAOmC,QAAQnC,EAAQU,GAEvBM,EAAKrC,QAAU+B,EACfM,EAAKD,QAAUL,GAGnBwB,EAAAA,YAAYE,KAAKpB,EAAMc,EAAOC,GAC9B/B,EAAOoC,KAAKN,EAAOC,GAEnBlC,EAAU+B,IAAIZ,EAAMtB,GAEbM,EAIX,OAAOH,EAAUwC,cAErB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/view",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
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.4.
|
|
38
|
-
"@leafer-ui/interface": "^1.4.
|
|
39
|
-
"@leafer-in/interface": "^1.4.
|
|
37
|
+
"@leafer-ui/draw": "^1.4.2",
|
|
38
|
+
"@leafer-ui/interface": "^1.4.2",
|
|
39
|
+
"@leafer-in/interface": "^1.4.2"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ILeaf, IBoundsData, IZoomType, IFourNumber, IPointData } from '@leafer-ui/interface'
|
|
2
|
-
import { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'
|
|
1
|
+
import { ILeaf, IBoundsData, IZoomType, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'
|
|
2
|
+
import { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { getFixBounds, getZoomScale } from './helper'
|
|
5
5
|
|
|
@@ -7,7 +7,9 @@ import { getFixBounds, getZoomScale } from './helper'
|
|
|
7
7
|
Plugin.add('view')
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
Leafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {
|
|
10
|
+
Leafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean, transition?: ITransition): IBoundsData {
|
|
11
|
+
|
|
12
|
+
this.killAnimate()
|
|
11
13
|
|
|
12
14
|
const { zoomLayer } = this
|
|
13
15
|
const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds()
|
|
@@ -45,10 +47,14 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fi
|
|
|
45
47
|
|
|
46
48
|
if (changeScale) {
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
changeScale = this.getValidScale(changeScale)
|
|
51
|
+
zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)
|
|
49
52
|
|
|
50
53
|
} else if (typeof zoomType === 'object') {
|
|
51
54
|
|
|
55
|
+
const { x, y, scaleX, scaleY } = zoomLayer
|
|
56
|
+
const data = { x, y, scaleX, scaleY }
|
|
57
|
+
|
|
52
58
|
const isArray = zoomType instanceof Array
|
|
53
59
|
|
|
54
60
|
if (isArray || (zoomType as ILeaf).tag) {
|
|
@@ -59,8 +65,8 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fi
|
|
|
59
65
|
bounds.set(zoomLayer.getWorldBounds(innerBounds))
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
const {
|
|
63
|
-
let moveX = limitBounds.x - x, moveY = limitBounds.y - y
|
|
68
|
+
const { width, height } = bounds
|
|
69
|
+
let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y
|
|
64
70
|
|
|
65
71
|
if (fixed) {
|
|
66
72
|
|
|
@@ -69,17 +75,23 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fi
|
|
|
69
75
|
|
|
70
76
|
} else {
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
moveX += (limitBounds.width - width *
|
|
74
|
-
moveY += (limitBounds.height - height *
|
|
78
|
+
changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))
|
|
79
|
+
moveX += (limitBounds.width - width * changeScale) / 2
|
|
80
|
+
moveY += (limitBounds.height - height * changeScale) / 2
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
bounds.scaleOf(bounds,
|
|
82
|
+
PointHelper.scaleOf(data, bounds, changeScale)
|
|
83
|
+
bounds.scaleOf(bounds, changeScale)
|
|
78
84
|
|
|
85
|
+
data.scaleX *= changeScale
|
|
86
|
+
data.scaleY *= changeScale
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
PointHelper.move(data, moveX, moveY)
|
|
90
|
+
bounds.move(moveX, moveY)
|
|
91
|
+
|
|
92
|
+
zoomLayer.set(data, transition)
|
|
93
|
+
|
|
94
|
+
return bounds
|
|
83
95
|
|
|
84
96
|
}
|
|
85
97
|
|