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.
Files changed (109) hide show
  1. package/.eslintrc.js +24 -0
  2. package/CHANGELOG +2 -0
  3. package/lib/Buffer/index.umd.js +2 -2
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +13 -8
  6. package/lib/Canvas/index.umd.min.js +3 -3
  7. package/lib/Cardinal/index.umd.js +2 -2
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +2 -2
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +7 -4
  12. package/lib/Geometry/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +8 -6
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +7 -5
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +6 -4
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +2 -2
  26. package/lib/Shader/index.umd.min.js +2 -2
  27. package/lib/Texture/index.umd.js +4 -3
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +8 -5
  30. package/lib/TreeLayout/index.umd.min.js +2 -2
  31. package/lib/WebGL/index.umd.js +7 -5
  32. package/lib/WebGL/index.umd.min.js +3 -3
  33. package/lib/animation/index.umd.js +4 -3
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +2 -2
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +2 -2
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +4 -3
  40. package/lib/getWebGLContext/index.umd.min.js +2 -2
  41. package/lib/index.umd.js +35 -20
  42. package/lib/index.umd.min.js +3 -3
  43. package/lib/move/index.umd.js +2 -2
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +4 -3
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +2 -2
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +2 -2
  50. package/lib/ruler/index.umd.min.js +2 -2
  51. package/lib/scale/index.umd.js +2 -2
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +2 -2
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +4 -4
  56. package/lib/viewHandler/index.umd.min.js +3 -3
  57. package/package.json +6 -2
  58. package/src/Canvas.ts +8 -5
  59. package/src/Eoap.ts +6 -6
  60. package/src/Geometry.ts +5 -5
  61. package/src/Matrix4/index.ts +4 -4
  62. package/src/Matrix4/move.ts +1 -1
  63. package/src/Matrix4/rotate.ts +1 -1
  64. package/src/Matrix4/transform.ts +1 -1
  65. package/src/Mercator.ts +4 -4
  66. package/src/SVG.ts +2 -2
  67. package/src/WebGL.ts +3 -3
  68. package/src/animation.ts +6 -6
  69. package/src/common/assemble.ts +1 -1
  70. package/src/common/canvas/arc.ts +4 -3
  71. package/src/common/canvas/config.ts +5 -5
  72. package/src/common/canvas/gradient.ts +6 -6
  73. package/src/common/canvas/index.ts +13 -12
  74. package/src/common/canvas/painter.ts +5 -14
  75. package/src/common/geometry/prism-horizontal.ts +4 -2
  76. package/src/common/geometry/prism-vertical.ts +3 -3
  77. package/src/common/geometry/sphere-fragment.ts +5 -4
  78. package/src/common/geometry/tool/circle.ts +2 -2
  79. package/src/common/mergeOption.ts +1 -1
  80. package/src/common/setStyle.ts +1 -1
  81. package/src/common/svg/config.ts +11 -11
  82. package/src/common/svg/dictionary.ts +1 -1
  83. package/src/common/svg/gradient.ts +12 -12
  84. package/src/common/svg/index.ts +6 -6
  85. package/src/common/svg/tool.ts +2 -2
  86. package/src/common/tree/toInnerTree.ts +4 -3
  87. package/src/common/tree/toPlainTree.ts +8 -7
  88. package/src/common/webgl/buffer.ts +4 -4
  89. package/src/common/webgl/doDraw.ts +2 -2
  90. package/src/common/webgl/getColorFactory.ts +6 -6
  91. package/src/common/webgl/getShader.ts +5 -5
  92. package/src/common/webgl/getTexture.ts +2 -2
  93. package/src/common/webgl/getWebGLContext.ts +5 -4
  94. package/src/common/webgl/index.ts +11 -10
  95. package/src/common/webgl/shader.ts +6 -6
  96. package/src/common/webgl/texture.ts +7 -6
  97. package/src/formatColor.ts +5 -5
  98. package/src/getLoopColors.ts +1 -1
  99. package/src/interpolation/Cardinal.ts +1 -1
  100. package/src/interpolation/Hermite.ts +3 -3
  101. package/src/layout/TreeLayout.ts +21 -21
  102. package/src/move.ts +1 -1
  103. package/src/resizeObserver.ts +2 -1
  104. package/src/rotate.ts +1 -1
  105. package/src/ruler.ts +18 -18
  106. package/src/throttle.ts +3 -2
  107. package/src/viewHandler.ts +13 -13
  108. package/types/CanvasOption.d.ts +3 -2
  109. 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
- let initTexture = (painter: WebGLRenderingContext, type: number, unit: number) => {
5
+ const initTexture = (painter: WebGLRenderingContext, type: number, unit: number) => {
6
6
 
7
7
  // 创建纹理对象
8
- let texture = painter.createTexture()
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
- let linkImage = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, image: TexImageSource) => {
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
- let linkCube = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, images: TexImageSource[], width: number, height: number, texture: WebGLTexture) => {
36
+ const linkCube = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, images: TexImageSource[], width: number, height: number, texture: WebGLTexture) => {
37
37
 
38
- let types = [
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
- ], target: number
45
+ ]
46
+ let target: number
46
47
 
47
48
  for (let i = 0; i < types.length; i++) {
48
49
  if (images[i]) {
@@ -1,19 +1,19 @@
1
- let toHex = (value: number) => {
2
- let hex = value.toString(16)
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
- let colorNode = document.getElementsByTagName('head')[0]
8
+ const colorNode = document.getElementsByTagName('head')[0]
9
9
  colorNode.style['color'] = color
10
10
 
11
11
  // 获取结点的全部样式
12
- let allStyle = document.defaultView && document.defaultView.getComputedStyle ?
12
+ const allStyle = document.defaultView && document.defaultView.getComputedStyle ?
13
13
  document.defaultView.getComputedStyle(colorNode, null) :
14
14
  (colorNode as any).currentStyle
15
15
 
16
- let oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',')
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
  }
@@ -1,7 +1,7 @@
1
1
  // 获取一组循环色彩
2
2
  export default function (num: number, alpha: number = 1) {
3
3
  // 颜色集合
4
- let colorList = [
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 + ")",
@@ -38,7 +38,7 @@ class Cardinal implements CardinalType {
38
38
  "x": [],
39
39
  "h": []
40
40
  };
41
- var flag: number,
41
+ let flag: number,
42
42
  slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]),
43
43
  temp: number
44
44
  this.__HS.x[0] = points[0][0]
@@ -27,7 +27,7 @@ class Hermite implements HermiteType {
27
27
  // 记录原始尺寸
28
28
  this.__a = x1
29
29
  this.__b = x2
30
- let p3 = this.__u * s1,
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
- let sx = (x - this.__a) / (this.__b - this.__a),
57
+ const sx = (x - this.__a) / (this.__b - this.__a),
58
58
  sx2 = sx * sx,
59
59
  sx3 = sx * sx2
60
- let sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3]
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
  }
@@ -35,11 +35,11 @@ class TreeLayout extends Tree implements TreeLayoutType {
35
35
  }
36
36
 
37
37
  use(initTree: any, noOpens = {}) {
38
- let tree = super.use(initTree, noOpens)
38
+ const tree = super.use(initTree, noOpens)
39
39
 
40
40
  // 校对偏差
41
41
  if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
42
- for (let key in tree.node) {
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
- let perW = this.__option.height / tree.size
61
- let perD = this.__option.width / (tree.deep - 1)
60
+ const perW = this.__option.height / tree.size
61
+ const perD = this.__option.width / (tree.deep - 1)
62
62
 
63
- let balanceW = this.__option.y - this.__option.height * 0.5
64
- let flag = this.__option.direction == 'LR' ? 1 : -1
63
+ const balanceW = this.__option.y - this.__option.height * 0.5
64
+ const flag = this.__option.direction == 'LR' ? 1 : -1
65
65
 
66
- for (let key in tree.node) {
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
- let perW = this.__option.width / tree.size
78
- let perD = this.__option.height / (tree.deep - 1)
77
+ const perW = this.__option.width / tree.size
78
+ const perD = this.__option.height / (tree.deep - 1)
79
79
 
80
- let balanceW = this.__option.x - this.__option.width * 0.5
81
- let flag = this.__option.direction == 'TB' ? 1 : -1
80
+ const balanceW = this.__option.x - this.__option.width * 0.5
81
+ const flag = this.__option.direction == 'TB' ? 1 : -1
82
82
 
83
- for (let key in tree.node) {
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
- let left = tree.node[key].left
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
- let cx = this.__option.x, cy = this.__option.y
99
- let deg = Math.PI * 2 / tree.size
100
- let per = this.__option.radius / (tree.deep - 1)
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 (let key in tree.node) {
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
- let position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy)
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
- let newTree = this.use(this.__oralTree, this.__noOpens)
138
+ const newTree = this.use(this.__oralTree, this.__noOpens)
139
139
 
140
- let cacheTree = JSON.parse(JSON.stringify(newTree))
140
+ const cacheTree = JSON.parse(JSON.stringify(newTree))
141
141
 
142
142
  animation((deep) => {
143
143
 
144
- for (let key in cacheTree.node) {
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
- let sqrt = Math.sqrt(ax * ax + ay * ay)
3
+ const sqrt = Math.sqrt(ax * ax + ay * ay)
4
4
  return [
5
5
  ax * d / sqrt + x,
6
6
  ay * d / sqrt + y
@@ -1,6 +1,7 @@
1
1
  let observer: ResizeObserver
2
2
 
3
- let attrValueToCallback = {}, uniqueid = 0
3
+ const attrValueToCallback = {}
4
+ let uniqueid = 0
4
5
 
5
6
  export default function (el: HTMLElement | null, callback: Function) {
6
7
 
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
- let cos = Math.cos(deg), sin = Math.sin(deg)
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
- let temp = minValue
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
- let times100 =
21
+ const times100 =
22
22
 
23
23
  (function (_value) {
24
24
 
25
25
  // 先确定基调,是放大还是缩小
26
- let _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1
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
- let distance100_oral = Math.ceil((maxValue - minValue) * times100 / num)
62
+ const distance100_oral = Math.ceil((maxValue - minValue) * times100 / num)
63
63
 
64
- let getResult = (changValue: number) => {
64
+ const getResult = (changValue: number) => {
65
65
  // 校对一下
66
- let distance100 = {
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
- let distance = distance100 / times100
89
+ const distance = distance100 / times100
90
90
 
91
91
  // 最小值,也就是起点
92
- let begin = Math.floor(minValue / distance) * distance
92
+ const begin = Math.floor(minValue / distance) * distance
93
93
 
94
- let rulerArray = []
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
- let balanceMax = () => {
107
- let rulerArray_temp = []
106
+ const balanceMax = () => {
107
+ const rulerArray_temp = []
108
108
 
109
- let changeDist = rulerArray[rulerArray.length - 1] - option.max
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
- let balanceMin = () => {
122
- let rulerArray_temp = []
121
+ const balanceMin = () => {
122
+ const rulerArray_temp = []
123
123
 
124
- let changeDist = rulerArray[0] - option.min
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
- let isAnswer = () => {
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
- let rulerArray_max = balanceMax()
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
- let rulerArray_min = balanceMin()
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
- let _this = this
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
- let interval = setInterval(() => {
31
+ const interval = setInterval(() => {
31
32
  if (hadClick) {
32
33
  if (!option.keep) {
33
34
  callback.apply(_this, arg)
@@ -1,14 +1,14 @@
1
1
  import type { callbackFun } from '../types/viewHandler'
2
2
 
3
- let mousePosition = (el: HTMLElement, event: any) => {
4
- let bounding = el.getBoundingClientRect()
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
- let getKeyString = (event: any) => {
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
- let el = document.getElementsByTagName('body')[0]
22
+ const el = document.getElementsByTagName('body')[0]
23
23
 
24
24
  // 键盘控制
25
25
  el.addEventListener("keydown", function (event) {
26
- let keyCode = getKeyString(event)
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
- let doMove = function (event) {
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
- let tempMouseP = mousePosition(el, event)
87
+ const tempMouseP = mousePosition(el, event)
88
88
 
89
89
  // 先求解出轨迹向量
90
- let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
90
+ const normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
91
91
 
92
92
  // 方向向量旋转90deg得到旋转向量
93
- let rotateNormal = [
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", (event) => {
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", (event) => {
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
- let doScale = function (value: number, event: Event) {
134
+ const doScale = function (value: number, event: Event) {
135
135
  if (value == 0) return
136
136
 
137
- let baseTimes = 0.899
137
+ const baseTimes = 0.899
138
138
  callback({
139
139
  type: "scale",
140
140
  value: value < 0 ? baseTimes : 2 - baseTimes,
@@ -1,8 +1,9 @@
1
- export default interface CanvasOptionType {
1
+ import CanvasOptsType from "./CanvasOpts"
2
+
3
+ export default interface CanvasOptionType extends CanvasOptsType {
2
4
 
3
5
  /**
4
6
  * 是否支持区域管理,默认true
5
7
  */
6
8
  region?: boolean
7
-
8
9
  }
@@ -0,0 +1,10 @@
1
+ export default interface CanvasOptsType {
2
+
3
+ // https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently
4
+ willReadFrequently?: boolean
5
+
6
+ alpha?: boolean
7
+
8
+ storage?: string
9
+
10
+ }