vislite 0.6.0-alpha.0 → 0.6.0-alpha.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/.eslintrc.js +24 -0
- package/CHANGELOG +2 -0
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +13 -8
- package/lib/Canvas/index.umd.min.js +3 -3
- package/lib/Cardinal/index.umd.js +2 -2
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +2 -2
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Geometry/index.umd.js +7 -4
- package/lib/Geometry/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +2 -2
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +2 -2
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +2 -2
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +8 -6
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +7 -5
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +6 -4
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +2 -2
- package/lib/Shader/index.umd.min.js +2 -2
- package/lib/Texture/index.umd.js +4 -3
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +8 -5
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +7 -5
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +4 -3
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +2 -2
- package/lib/formatColor/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +2 -2
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +4 -3
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +35 -20
- package/lib/index.umd.min.js +3 -3
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +4 -3
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +2 -2
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +2 -2
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +2 -2
- package/lib/throttle/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +4 -4
- package/lib/viewHandler/index.umd.min.js +3 -3
- package/package.json +6 -2
- package/src/Canvas.ts +8 -5
- package/src/Eoap.ts +6 -6
- package/src/Geometry.ts +5 -5
- package/src/Matrix4/index.ts +4 -4
- package/src/Matrix4/move.ts +1 -1
- package/src/Matrix4/rotate.ts +1 -1
- package/src/Matrix4/transform.ts +1 -1
- package/src/Mercator.ts +4 -4
- package/src/SVG.ts +2 -2
- package/src/WebGL.ts +3 -3
- package/src/animation.ts +6 -6
- package/src/common/assemble.ts +1 -1
- package/src/common/canvas/arc.ts +4 -3
- package/src/common/canvas/config.ts +5 -5
- package/src/common/canvas/gradient.ts +6 -6
- package/src/common/canvas/index.ts +13 -12
- package/src/common/canvas/painter.ts +5 -14
- package/src/common/geometry/prism-horizontal.ts +4 -2
- package/src/common/geometry/prism-vertical.ts +3 -3
- package/src/common/geometry/sphere-fragment.ts +5 -4
- package/src/common/geometry/tool/circle.ts +2 -2
- package/src/common/mergeOption.ts +1 -1
- package/src/common/setStyle.ts +1 -1
- package/src/common/svg/config.ts +11 -11
- package/src/common/svg/dictionary.ts +1 -1
- package/src/common/svg/gradient.ts +12 -12
- package/src/common/svg/index.ts +6 -6
- package/src/common/svg/tool.ts +2 -2
- package/src/common/tree/toInnerTree.ts +4 -3
- package/src/common/tree/toPlainTree.ts +8 -7
- package/src/common/webgl/buffer.ts +4 -4
- package/src/common/webgl/doDraw.ts +2 -2
- package/src/common/webgl/getColorFactory.ts +6 -6
- package/src/common/webgl/getShader.ts +5 -5
- package/src/common/webgl/getTexture.ts +2 -2
- package/src/common/webgl/getWebGLContext.ts +5 -4
- package/src/common/webgl/index.ts +11 -10
- package/src/common/webgl/shader.ts +6 -6
- package/src/common/webgl/texture.ts +7 -6
- package/src/formatColor.ts +5 -5
- package/src/getLoopColors.ts +1 -1
- package/src/interpolation/Cardinal.ts +1 -1
- package/src/interpolation/Hermite.ts +3 -3
- package/src/layout/TreeLayout.ts +21 -21
- package/src/move.ts +1 -1
- package/src/resizeObserver.ts +2 -1
- package/src/rotate.ts +1 -1
- package/src/ruler.ts +18 -18
- package/src/throttle.ts +3 -2
- package/src/viewHandler.ts +13 -13
- package/types/CanvasOption.d.ts +3 -2
- package/types/CanvasOpts.d.ts +10 -0
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// type = gl.TEXTURE_2D 二维纹理
|
|
3
3
|
// type = gl.TEXTURE_CUBE_MAP 立方体纹理
|
|
4
4
|
// unit表示开启的纹理单元编号
|
|
5
|
-
|
|
5
|
+
const initTexture = (painter: WebGLRenderingContext, type: number, unit: number) => {
|
|
6
6
|
|
|
7
7
|
// 创建纹理对象
|
|
8
|
-
|
|
8
|
+
const texture = painter.createTexture()
|
|
9
9
|
|
|
10
10
|
// 开启纹理单元,unit表示开启的编号
|
|
11
11
|
painter.activeTexture(painter['TEXTURE' + unit])
|
|
@@ -29,20 +29,21 @@ let initTexture = (painter: WebGLRenderingContext, type: number, unit: number) =
|
|
|
29
29
|
// gl.UNSIGNED_SHORT_5_6_5: 表示RGB,每一个分量分别占据占据5, 6, 5比特
|
|
30
30
|
// gl.UNSIGNED_SHORT_4_4_4_4: 表示RGBA,每一个分量分别占据占据4, 4, 4, 4比特
|
|
31
31
|
// gl.UNSIGNED_SHORT_5_5_5_1: 表示RGBA,每一个分量分别占据占据5比特,A分量占据1比特
|
|
32
|
-
|
|
32
|
+
const linkImage = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, image: TexImageSource) => {
|
|
33
33
|
painter.texImage2D(type, level, format, format, textureType, image)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const linkCube = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, images: TexImageSource[], width: number, height: number, texture: WebGLTexture) => {
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const types = [
|
|
39
39
|
painter.TEXTURE_CUBE_MAP_POSITIVE_X, // 右
|
|
40
40
|
painter.TEXTURE_CUBE_MAP_NEGATIVE_X, // 左
|
|
41
41
|
painter.TEXTURE_CUBE_MAP_POSITIVE_Y, // 上
|
|
42
42
|
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y, // 下
|
|
43
43
|
painter.TEXTURE_CUBE_MAP_POSITIVE_Z, // 后
|
|
44
44
|
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z // 前
|
|
45
|
-
]
|
|
45
|
+
]
|
|
46
|
+
let target: number
|
|
46
47
|
|
|
47
48
|
for (let i = 0; i < types.length; i++) {
|
|
48
49
|
if (images[i]) {
|
package/src/formatColor.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const toHex = (value: number) => {
|
|
2
|
+
const hex = value.toString(16)
|
|
3
3
|
return hex.length == 1 ? ("0" + hex) : hex
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export default function (color: string, format: string) {
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const colorNode = document.getElementsByTagName('head')[0]
|
|
9
9
|
colorNode.style['color'] = color
|
|
10
10
|
|
|
11
11
|
// 获取结点的全部样式
|
|
12
|
-
|
|
12
|
+
const allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
13
13
|
document.defaultView.getComputedStyle(colorNode, null) :
|
|
14
14
|
(colorNode as any).currentStyle
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',')
|
|
17
17
|
for (let index = 0; index < oralFormat.length; index++) {
|
|
18
18
|
oralFormat[index] = +oralFormat[index]
|
|
19
19
|
}
|
package/src/getLoopColors.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 获取一组循环色彩
|
|
2
2
|
export default function (num: number, alpha: number = 1) {
|
|
3
3
|
// 颜色集合
|
|
4
|
-
|
|
4
|
+
const colorList = [
|
|
5
5
|
'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
|
|
6
6
|
'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
|
|
7
7
|
'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
|
|
@@ -27,7 +27,7 @@ class Hermite implements HermiteType {
|
|
|
27
27
|
// 记录原始尺寸
|
|
28
28
|
this.__a = x1
|
|
29
29
|
this.__b = x2
|
|
30
|
-
|
|
30
|
+
const p3 = this.__u * s1,
|
|
31
31
|
p4 = this.__u * s2
|
|
32
32
|
// 缩放到[0,1]定义域
|
|
33
33
|
y1 /= (x2 - x1)
|
|
@@ -54,10 +54,10 @@ class Hermite implements HermiteType {
|
|
|
54
54
|
*/
|
|
55
55
|
use(x: number) {
|
|
56
56
|
if (this.__MR) {
|
|
57
|
-
|
|
57
|
+
const sx = (x - this.__a) / (this.__b - this.__a),
|
|
58
58
|
sx2 = sx * sx,
|
|
59
59
|
sx3 = sx * sx2
|
|
60
|
-
|
|
60
|
+
const sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3]
|
|
61
61
|
return sResult * (this.__b - this.__a)
|
|
62
62
|
} else throw new Error('You shoud first set the position!')
|
|
63
63
|
}
|
package/src/layout/TreeLayout.ts
CHANGED
|
@@ -35,11 +35,11 @@ class TreeLayout extends Tree implements TreeLayoutType {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
use(initTree: any, noOpens = {}) {
|
|
38
|
-
|
|
38
|
+
const tree = super.use(initTree, noOpens)
|
|
39
39
|
|
|
40
40
|
// 校对偏差
|
|
41
41
|
if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
|
|
42
|
-
for (
|
|
42
|
+
for (const key in tree.node) {
|
|
43
43
|
if (!tree.node[key].show) {
|
|
44
44
|
|
|
45
45
|
let deep = 0, pid = key
|
|
@@ -57,13 +57,13 @@ class TreeLayout extends Tree implements TreeLayoutType {
|
|
|
57
57
|
if (this.__option.type == 'rect') {
|
|
58
58
|
if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const perW = this.__option.height / tree.size
|
|
61
|
+
const perD = this.__option.width / (tree.deep - 1)
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const balanceW = this.__option.y - this.__option.height * 0.5
|
|
64
|
+
const flag = this.__option.direction == 'LR' ? 1 : -1
|
|
65
65
|
|
|
66
|
-
for (
|
|
66
|
+
for (const key in tree.node) {
|
|
67
67
|
if (tree.deep == 1) {
|
|
68
68
|
tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag
|
|
69
69
|
tree.node[key].top = this.__option.y
|
|
@@ -74,18 +74,18 @@ class TreeLayout extends Tree implements TreeLayoutType {
|
|
|
74
74
|
}
|
|
75
75
|
} else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const perW = this.__option.width / tree.size
|
|
78
|
+
const perD = this.__option.height / (tree.deep - 1)
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const balanceW = this.__option.x - this.__option.width * 0.5
|
|
81
|
+
const flag = this.__option.direction == 'TB' ? 1 : -1
|
|
82
82
|
|
|
83
|
-
for (
|
|
83
|
+
for (const key in tree.node) {
|
|
84
84
|
if (tree.deep == 1) {
|
|
85
85
|
tree.node[key].left = this.__option.x
|
|
86
86
|
tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag
|
|
87
87
|
} else {
|
|
88
|
-
|
|
88
|
+
const left = tree.node[key].left
|
|
89
89
|
|
|
90
90
|
tree.node[key].left = tree.node[key].top * perW + balanceW
|
|
91
91
|
tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag
|
|
@@ -95,16 +95,16 @@ class TreeLayout extends Tree implements TreeLayoutType {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
} else if (this.__option.type == 'circle') {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
const cx = this.__option.x, cy = this.__option.y
|
|
99
|
+
const deg = Math.PI * 2 / tree.size
|
|
100
|
+
const per = this.__option.radius / (tree.deep - 1)
|
|
101
101
|
|
|
102
|
-
for (
|
|
102
|
+
for (const key in tree.node) {
|
|
103
103
|
if (tree.node[key].left == 0.5) {
|
|
104
104
|
tree.node[key].left = cx
|
|
105
105
|
tree.node[key].top = cy
|
|
106
106
|
} else {
|
|
107
|
-
|
|
107
|
+
const position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy)
|
|
108
108
|
|
|
109
109
|
tree.node[key].left = position[0]
|
|
110
110
|
tree.node[key].top = position[1]
|
|
@@ -135,13 +135,13 @@ class TreeLayout extends Tree implements TreeLayoutType {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
private doUpdate() {
|
|
138
|
-
|
|
138
|
+
const newTree = this.use(this.__oralTree, this.__noOpens)
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
const cacheTree = JSON.parse(JSON.stringify(newTree))
|
|
141
141
|
|
|
142
142
|
animation((deep) => {
|
|
143
143
|
|
|
144
|
-
for (
|
|
144
|
+
for (const key in cacheTree.node) {
|
|
145
145
|
if (newTree.node[key].show || this.__preTree.node[key].show) {
|
|
146
146
|
cacheTree.node[key].show = true
|
|
147
147
|
|
package/src/move.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 点(x,y)沿着向量(ax,ay)方向移动距离d
|
|
2
2
|
export default function (ax: number, ay: number, d: number, x: number, y: number): [number, number] {
|
|
3
|
-
|
|
3
|
+
const sqrt = Math.sqrt(ax * ax + ay * ay)
|
|
4
4
|
return [
|
|
5
5
|
ax * d / sqrt + x,
|
|
6
6
|
ay * d / sqrt + y
|
package/src/resizeObserver.ts
CHANGED
package/src/rotate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 点(x,y)围绕中心(cx,cy)旋转deg度
|
|
2
2
|
export default function (cx: number, cy: number, deg: number, x: number, y: number): [number, number] {
|
|
3
|
-
|
|
3
|
+
const cos = Math.cos(deg), sin = Math.sin(deg)
|
|
4
4
|
return [
|
|
5
5
|
(x - cx) * cos - (y - cy) * sin + cx,
|
|
6
6
|
(x - cx) * sin + (y - cy) * cos + cy
|
package/src/ruler.ts
CHANGED
|
@@ -7,7 +7,7 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
7
7
|
|
|
8
8
|
// 如果最大值最小值反了
|
|
9
9
|
if (maxValue < minValue) {
|
|
10
|
-
|
|
10
|
+
const temp = minValue
|
|
11
11
|
minValue = maxValue
|
|
12
12
|
maxValue = temp
|
|
13
13
|
}
|
|
@@ -18,12 +18,12 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// 为了变成 -100 ~ 100 需要放大或者缩小的倍数
|
|
21
|
-
|
|
21
|
+
const times100 =
|
|
22
22
|
|
|
23
23
|
(function (_value) {
|
|
24
24
|
|
|
25
25
|
// 先确定基调,是放大还是缩小
|
|
26
|
-
|
|
26
|
+
const _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1
|
|
27
27
|
|
|
28
28
|
// 记录当前缩放倍数
|
|
29
29
|
let _times100 = -1, _tiemsValue = _value
|
|
@@ -59,11 +59,11 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
// 求解出 -100 ~ 100 的最佳间距值 后直接转换原来的倍数
|
|
62
|
-
|
|
62
|
+
const distance100_oral = Math.ceil((maxValue - minValue) * times100 / num)
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const getResult = (changValue: number) => {
|
|
65
65
|
// 校对一下
|
|
66
|
-
|
|
66
|
+
const distance100 = {
|
|
67
67
|
3: 2,
|
|
68
68
|
4: 5,
|
|
69
69
|
6: 5,
|
|
@@ -86,12 +86,12 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
86
86
|
27: 25
|
|
87
87
|
}[distance100_oral + changValue] || (distance100_oral + changValue)
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
const distance = distance100 / times100
|
|
90
90
|
|
|
91
91
|
// 最小值,也就是起点
|
|
92
|
-
|
|
92
|
+
const begin = Math.floor(minValue / distance) * distance
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
const rulerArray = []
|
|
95
95
|
// 获取最终的刻度尺数组
|
|
96
96
|
rulerArray.push(begin)
|
|
97
97
|
for (let index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
|
|
@@ -103,10 +103,10 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
103
103
|
|
|
104
104
|
let rulerArray = getResult(0)
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
const balanceMax = () => {
|
|
107
|
+
const rulerArray_temp = []
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
const changeDist = rulerArray[rulerArray.length - 1] - option.max
|
|
110
110
|
for (let index = 0; index < rulerArray.length; index++) {
|
|
111
111
|
if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) {
|
|
112
112
|
// 多余的
|
|
@@ -118,10 +118,10 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
118
118
|
return rulerArray_temp
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const balanceMin = () => {
|
|
122
|
+
const rulerArray_temp = []
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
const changeDist = rulerArray[0] - option.min
|
|
125
125
|
for (let index = 0; index < rulerArray.length; index++) {
|
|
126
126
|
rulerArray_temp[index] = rulerArray[index] - changeDist
|
|
127
127
|
if (maxValue <= rulerArray_temp[index]) break
|
|
@@ -135,20 +135,20 @@ export default function (maxValue: number, minValue: number, num: number, option
|
|
|
135
135
|
// 上下界限制
|
|
136
136
|
if ('max' in option && 'min' in option && option.max >= maxValue && option.min <= minValue) {
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
const isAnswer = () => {
|
|
139
139
|
|
|
140
140
|
// 先判断原始的是否可行
|
|
141
141
|
if (rulerArray[0] >= option.min && rulerArray[rulerArray.length - 1] <= option.max) return true
|
|
142
142
|
|
|
143
143
|
// 再判断max调整是否可行
|
|
144
|
-
|
|
144
|
+
const rulerArray_max = balanceMax()
|
|
145
145
|
if (rulerArray_max[0] >= option.min && rulerArray_max[rulerArray_max.length - 1] <= option.max) {
|
|
146
146
|
rulerArray = rulerArray_max
|
|
147
147
|
return true
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
// 再判断max调整是否可行
|
|
151
|
-
|
|
151
|
+
const rulerArray_min = balanceMin()
|
|
152
152
|
if (rulerArray_min[0] >= option.min && rulerArray_min[rulerArray_max.length - 1] <= option.max) {
|
|
153
153
|
rulerArray = rulerArray_min
|
|
154
154
|
return true
|
package/src/throttle.ts
CHANGED
|
@@ -17,7 +17,8 @@ export default function (callback: Function, option: throttleOptionType = {}) {
|
|
|
17
17
|
|
|
18
18
|
let arg: any
|
|
19
19
|
return function () {
|
|
20
|
-
|
|
20
|
+
const _this = this
|
|
21
|
+
// eslint-disable-next-line prefer-rest-params
|
|
21
22
|
arg = arguments
|
|
22
23
|
|
|
23
24
|
// 如果前置任务都完成了
|
|
@@ -27,7 +28,7 @@ export default function (callback: Function, option: throttleOptionType = {}) {
|
|
|
27
28
|
}
|
|
28
29
|
hadInterval = true
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
const interval = setInterval(() => {
|
|
31
32
|
if (hadClick) {
|
|
32
33
|
if (!option.keep) {
|
|
33
34
|
callback.apply(_this, arg)
|
package/src/viewHandler.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { callbackFun } from '../types/viewHandler'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const mousePosition = (el: HTMLElement, event: any) => {
|
|
4
|
+
const bounding = el.getBoundingClientRect()
|
|
5
5
|
return {
|
|
6
6
|
"x": event.clientX - bounding.left,
|
|
7
7
|
"y": event.clientY - bounding.top
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const getKeyString = (event: any) => {
|
|
12
12
|
return {
|
|
13
13
|
37: "left",
|
|
14
14
|
38: "up",
|
|
@@ -19,11 +19,11 @@ let getKeyString = (event: any) => {
|
|
|
19
19
|
|
|
20
20
|
export default function (callback: callbackFun) {
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const el = document.getElementsByTagName('body')[0]
|
|
23
23
|
|
|
24
24
|
// 键盘控制
|
|
25
25
|
el.addEventListener("keydown", function (event) {
|
|
26
|
-
|
|
26
|
+
const keyCode = getKeyString(event)
|
|
27
27
|
|
|
28
28
|
// 视角向上
|
|
29
29
|
if (keyCode == 'up') {
|
|
@@ -69,7 +69,7 @@ export default function (callback: callbackFun) {
|
|
|
69
69
|
|
|
70
70
|
// 鼠标控制
|
|
71
71
|
let mouseP = null;
|
|
72
|
-
|
|
72
|
+
const doMove = function (event) {
|
|
73
73
|
|
|
74
74
|
// 单纯移动
|
|
75
75
|
if (mouseP == null) {
|
|
@@ -84,13 +84,13 @@ export default function (callback: callbackFun) {
|
|
|
84
84
|
// 按下移动
|
|
85
85
|
else {
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
const tempMouseP = mousePosition(el, event)
|
|
88
88
|
|
|
89
89
|
// 先求解出轨迹向量
|
|
90
|
-
|
|
90
|
+
const normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
|
|
91
91
|
|
|
92
92
|
// 方向向量旋转90deg得到旋转向量
|
|
93
|
-
|
|
93
|
+
const rotateNormal = [
|
|
94
94
|
normal[1],
|
|
95
95
|
normal[0],
|
|
96
96
|
0
|
|
@@ -113,7 +113,7 @@ export default function (callback: callbackFun) {
|
|
|
113
113
|
el.addEventListener("mousedown", (event) => {
|
|
114
114
|
mouseP = mousePosition(el, event)
|
|
115
115
|
})
|
|
116
|
-
el.addEventListener("mouseup", (
|
|
116
|
+
el.addEventListener("mouseup", () => {
|
|
117
117
|
mouseP = null
|
|
118
118
|
})
|
|
119
119
|
el.addEventListener("mousemove", (event) => {
|
|
@@ -121,7 +121,7 @@ export default function (callback: callbackFun) {
|
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
// 手指控制
|
|
124
|
-
el.addEventListener("touchend", (
|
|
124
|
+
el.addEventListener("touchend", () => {
|
|
125
125
|
mouseP = null;
|
|
126
126
|
})
|
|
127
127
|
el.addEventListener("touchstart", (event) => {
|
|
@@ -131,10 +131,10 @@ export default function (callback: callbackFun) {
|
|
|
131
131
|
doMove(event.touches[0])
|
|
132
132
|
})
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
const doScale = function (value: number, event: Event) {
|
|
135
135
|
if (value == 0) return
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
const baseTimes = 0.899
|
|
138
138
|
callback({
|
|
139
139
|
type: "scale",
|
|
140
140
|
value: value < 0 ? baseTimes : 2 - baseTimes,
|
package/types/CanvasOption.d.ts
CHANGED