vislite 1.2.0-alpha.1 → 1.2.0-alpha.3

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 (77) hide show
  1. package/CHANGELOG +257 -250
  2. package/README.md +165 -166
  3. package/lib/Buffer/index.es.js +1 -1
  4. package/lib/Buffer/index.es.min.js +1 -1
  5. package/lib/Canvas/index.es.js +17 -8
  6. package/lib/Canvas/index.es.min.js +2 -2
  7. package/lib/Cardinal/index.es.js +1 -1
  8. package/lib/Cardinal/index.es.min.js +1 -1
  9. package/lib/Eoap/index.es.js +1 -1
  10. package/lib/Eoap/index.es.min.js +1 -1
  11. package/lib/Hermite/index.es.js +1 -1
  12. package/lib/Hermite/index.es.min.js +1 -1
  13. package/lib/Matrix4/index.es.js +1 -1
  14. package/lib/Matrix4/index.es.min.js +1 -1
  15. package/lib/Mercator/index.es.js +1 -1
  16. package/lib/Mercator/index.es.min.js +1 -1
  17. package/lib/RawCanvas/index.es.js +12 -3
  18. package/lib/RawCanvas/index.es.min.js +2 -2
  19. package/lib/SVG/index.es.js +1 -1
  20. package/lib/SVG/index.es.min.js +1 -1
  21. package/lib/Shader/index.es.js +1 -1
  22. package/lib/Shader/index.es.min.js +1 -1
  23. package/lib/Texture/index.es.js +1 -1
  24. package/lib/Texture/index.es.min.js +1 -1
  25. package/lib/TreeLayout/index.es.js +6 -6
  26. package/lib/TreeLayout/index.es.min.js +1 -1
  27. package/lib/animation/index.es.js +1 -1
  28. package/lib/animation/index.es.min.js +1 -1
  29. package/lib/assemble/index.es.d.ts +3 -0
  30. package/lib/assemble/index.es.js +23 -0
  31. package/lib/assemble/index.es.min.d.ts +3 -0
  32. package/lib/assemble/index.es.min.js +5 -0
  33. package/lib/getLoopColors/index.es.js +1 -1
  34. package/lib/getLoopColors/index.es.min.js +1 -1
  35. package/lib/getWebGLContext/index.es.js +1 -1
  36. package/lib/getWebGLContext/index.es.min.js +1 -1
  37. package/lib/index.umd.js +60 -12
  38. package/lib/index.umd.min.js +2 -2
  39. package/lib/initOption/index.es.d.ts +3 -0
  40. package/lib/initOption/index.es.js +12 -0
  41. package/lib/initOption/index.es.min.d.ts +3 -0
  42. package/lib/initOption/index.es.min.js +5 -0
  43. package/lib/mergeOption/index.es.d.ts +3 -0
  44. package/lib/mergeOption/index.es.js +42 -0
  45. package/lib/mergeOption/index.es.min.d.ts +3 -0
  46. package/lib/mergeOption/index.es.min.js +5 -0
  47. package/lib/move/index.es.js +1 -1
  48. package/lib/move/index.es.min.js +1 -1
  49. package/lib/rotate/index.es.js +1 -1
  50. package/lib/rotate/index.es.min.js +1 -1
  51. package/lib/ruler/index.es.js +1 -1
  52. package/lib/ruler/index.es.min.js +1 -1
  53. package/lib/scale/index.es.js +1 -1
  54. package/lib/scale/index.es.min.js +1 -1
  55. package/lib/throttle/index.es.js +5 -5
  56. package/lib/throttle/index.es.min.js +1 -1
  57. package/miniprogram/ui-canvas/index.js +115 -115
  58. package/package/assemble/index.ts +3 -0
  59. package/package/index.ts +11 -1
  60. package/package/initOption/index.ts +3 -0
  61. package/package/mergeOption/index.ts +3 -0
  62. package/package.json +1 -1
  63. package/src/Canvas.ts +84 -84
  64. package/src/animation.ts +98 -98
  65. package/src/common/canvas/gradient.ts +32 -24
  66. package/src/common/canvas/index.ts +182 -177
  67. package/src/common/option.ts +30 -0
  68. package/src/common/tree/index.ts +2 -2
  69. package/src/common/type.ts +27 -0
  70. package/src/layout/TreeLayout.ts +2 -2
  71. package/src/throttle.ts +2 -2
  72. package/types/Canvas.d.ts +10 -1
  73. package/types/assemble.d.ts +6 -0
  74. package/types/index.d.ts +161 -146
  75. package/types/option.d.ts +13 -0
  76. package/types/uni-canvas.d.ts +4 -0
  77. package/src/common/mergeOption.ts +0 -7
@@ -1,177 +1,182 @@
1
- import type CanvasConfigType from "../../../types/CanvasConfig"
2
- import type CanvasOptsType from '../../../types/CanvasOpts'
3
-
4
- import PainterRender from "./painter"
5
- import assemble from "../assemble"
6
- import { linearGradient, radialGradient } from "./gradient"
7
- import { initText } from './config'
8
-
9
- class Canvas extends PainterRender {
10
- readonly name: string = "Canvas"
11
-
12
- private __regionList = {} //区域映射表
13
- private __scaleSize
14
-
15
- // 步长由1改为10是为了优化区域计算有时候出错问题
16
- // 2023年7月6日 于南京
17
- private __regionAssemble = assemble(0, 255, 10, 3)
18
-
19
- // 添加scaleSize参数是为了适配画布缩放后的处理
20
- // 2024年1月17日 于南京
21
- constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null, opts: CanvasOptsType = {}, scaleSize = 1) {
22
- super(
23
- ViewCanvas,
24
- opts,
25
- RegionCanvas ? new PainterRender(RegionCanvas, {
26
- willReadFrequently: true,
27
- }) : undefined, true, scaleSize
28
- )
29
-
30
- this.__scaleSize = scaleSize
31
- this.setRegion("")
32
- }
33
-
34
- config(configs: CanvasConfigType) {
35
- for (const key in configs) {
36
- this.useConfig(key, configs[key])
37
- }
38
-
39
- return this
40
- }
41
-
42
- // 是否绘制的内容只需要进行区域记录
43
- onlyRegion(flag: boolean) {
44
- this.__onlyRegion = flag
45
- return this
46
- }
47
-
48
- onlyView(flag: boolean) {
49
- this.__onlyView = flag
50
- return this
51
- }
52
-
53
- // 设置当前绘制区域名称
54
- setRegion(regionName: string | number) {
55
- if (this.__region) {
56
- if (regionName) {
57
- if (this.__regionList[regionName] == void 0) {
58
- const tempColor = this.__regionAssemble()
59
- this.__regionList[regionName] =
60
- "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
61
- }
62
-
63
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
64
- this.__region.useConfig("strokeStyle", this.__regionList[regionName])
65
- } else {
66
- this.__region.useConfig("fillStyle", "#000000") &&
67
- this.__region.useConfig("strokeStyle", "#000000")
68
- }
69
- }
70
- return this
71
- }
72
-
73
- // 获取当前事件触发的区域名称
74
- getRegion(x: number, y: number): Promise<string> {
75
- return new Promise((resolve) => {
76
- const imgData = this.__region ? this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
77
- data: [0, 0, 0, 0]
78
- }
79
-
80
- // 获取点击点的颜色
81
- let currentRGBA = imgData.data
82
-
83
- const doit = () => {
84
- if (this.__region) {
85
-
86
- // 查找当前点击的区域
87
- for (const key in this.__regionList) {
88
- if (
89
- "rgb(" +
90
- currentRGBA[0] +
91
- "," +
92
- currentRGBA[1] +
93
- "," +
94
- currentRGBA[2] +
95
- ")" ==
96
- this.__regionList[key]
97
- ) {
98
- resolve(key)
99
- break
100
- }
101
- }
102
- }
103
-
104
- resolve("")
105
- }
106
-
107
- // 如果有值
108
- if (currentRGBA) {
109
- doit()
110
- }
111
-
112
- // 否则就是在Promise中
113
- else {
114
- (imgData as any).then((data: Uint8ClampedArray) => {
115
- currentRGBA = data
116
- doit()
117
- })
118
- }
119
- })
120
- }
121
-
122
- textWidth(text: string) {
123
- this.painter.save()
124
-
125
- initText(this.painter, this.__specialConfig, 0, 0, 0)
126
-
127
- // 虽然我们限制了只可以输入字符串,可是不代表所有环境都可以保证,为了确保方法不失效,强转成字符串
128
- const width = this.painter.measureText(text + "").width
129
-
130
- this.painter.restore()
131
-
132
- return width
133
- }
134
-
135
- // 获取原始画笔
136
- getContext(isRegion = false) {
137
- return isRegion ? (this.__region ? this.__region.painter : null) : this.painter
138
- }
139
-
140
- // 获取画布信息
141
- getInfo() {
142
- return {
143
- width: this.painter.canvas.width / this.__scaleSize,
144
- height: this.painter.canvas.height / this.__scaleSize
145
- }
146
- }
147
-
148
- // 线性渐变
149
- createLinearGradient(x0: number, y0: number, x1: number, y1: number) {
150
- return linearGradient(this.painter, x0, y0, x1, y1)
151
- }
152
-
153
- // 环形渐变
154
- createRadialGradient(cx: number, cy: number, r: number) {
155
- return radialGradient(this.painter, cx, cy, r)
156
- }
157
-
158
- // 获取指定位置颜色
159
- getColor(x: number, y: number) {
160
- x *= this.__scaleSize
161
- y *= this.__scaleSize
162
- const currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data
163
- return (
164
- "rgba(" +
165
- currentRGBA[0] +
166
- "," +
167
- currentRGBA[1] +
168
- "," +
169
- currentRGBA[2] +
170
- "," +
171
- currentRGBA[3] +
172
- ")"
173
- )
174
- }
175
- }
176
-
177
- export default Canvas
1
+ import type CanvasConfigType from "../../../types/CanvasConfig"
2
+ import type CanvasOptsType from '../../../types/CanvasOpts'
3
+
4
+ import PainterRender from "./painter"
5
+ import assemble from "../assemble"
6
+ import { linearGradient, radialGradient, conicGradient } from "./gradient"
7
+ import { initText } from './config'
8
+
9
+ class Canvas extends PainterRender {
10
+ readonly name: string = "Canvas"
11
+
12
+ private __regionList = {} //区域映射表
13
+ private __scaleSize
14
+
15
+ // 步长由1改为10是为了优化区域计算有时候出错问题
16
+ // 2023年7月6日 于南京
17
+ private __regionAssemble = assemble(0, 255, 10, 3)
18
+
19
+ // 添加scaleSize参数是为了适配画布缩放后的处理
20
+ // 2024年1月17日 于南京
21
+ constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null, opts: CanvasOptsType = {}, scaleSize = 1) {
22
+ super(
23
+ ViewCanvas,
24
+ opts,
25
+ RegionCanvas ? new PainterRender(RegionCanvas, {
26
+ willReadFrequently: true,
27
+ }) : undefined, true, scaleSize
28
+ )
29
+
30
+ this.__scaleSize = scaleSize
31
+ this.setRegion("")
32
+ }
33
+
34
+ config(configs: CanvasConfigType) {
35
+ for (const key in configs) {
36
+ this.useConfig(key, configs[key])
37
+ }
38
+
39
+ return this
40
+ }
41
+
42
+ // 是否绘制的内容只需要进行区域记录
43
+ onlyRegion(flag: boolean) {
44
+ this.__onlyRegion = flag
45
+ return this
46
+ }
47
+
48
+ onlyView(flag: boolean) {
49
+ this.__onlyView = flag
50
+ return this
51
+ }
52
+
53
+ // 设置当前绘制区域名称
54
+ setRegion(regionName: string | number) {
55
+ if (this.__region) {
56
+ if (regionName) {
57
+ if (this.__regionList[regionName] == void 0) {
58
+ const tempColor = this.__regionAssemble()
59
+ this.__regionList[regionName] =
60
+ "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
61
+ }
62
+
63
+ this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
64
+ this.__region.useConfig("strokeStyle", this.__regionList[regionName])
65
+ } else {
66
+ this.__region.useConfig("fillStyle", "#000000") &&
67
+ this.__region.useConfig("strokeStyle", "#000000")
68
+ }
69
+ }
70
+ return this
71
+ }
72
+
73
+ // 获取当前事件触发的区域名称
74
+ getRegion(x: number, y: number): Promise<string> {
75
+ return new Promise((resolve) => {
76
+ const imgData = this.__region ? this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
77
+ data: [0, 0, 0, 0]
78
+ }
79
+
80
+ // 获取点击点的颜色
81
+ let currentRGBA = imgData.data
82
+
83
+ const doit = () => {
84
+ if (this.__region) {
85
+
86
+ // 查找当前点击的区域
87
+ for (const key in this.__regionList) {
88
+ if (
89
+ "rgb(" +
90
+ currentRGBA[0] +
91
+ "," +
92
+ currentRGBA[1] +
93
+ "," +
94
+ currentRGBA[2] +
95
+ ")" ==
96
+ this.__regionList[key]
97
+ ) {
98
+ resolve(key)
99
+ break
100
+ }
101
+ }
102
+ }
103
+
104
+ resolve("")
105
+ }
106
+
107
+ // 如果有值
108
+ if (currentRGBA) {
109
+ doit()
110
+ }
111
+
112
+ // 否则就是在Promise中
113
+ else {
114
+ (imgData as any).then((data: Uint8ClampedArray) => {
115
+ currentRGBA = data
116
+ doit()
117
+ })
118
+ }
119
+ })
120
+ }
121
+
122
+ textWidth(text: string) {
123
+ this.painter.save()
124
+
125
+ initText(this.painter, this.__specialConfig, 0, 0, 0)
126
+
127
+ // 虽然我们限制了只可以输入字符串,可是不代表所有环境都可以保证,为了确保方法不失效,强转成字符串
128
+ const width = this.painter.measureText(text + "").width
129
+
130
+ this.painter.restore()
131
+
132
+ return width
133
+ }
134
+
135
+ // 获取原始画笔
136
+ getContext(isRegion = false) {
137
+ return isRegion ? (this.__region ? this.__region.painter : null) : this.painter
138
+ }
139
+
140
+ // 获取画布信息
141
+ getInfo() {
142
+ return {
143
+ width: this.painter.canvas.width / this.__scaleSize,
144
+ height: this.painter.canvas.height / this.__scaleSize
145
+ }
146
+ }
147
+
148
+ // 线性渐变
149
+ createLinearGradient(x0: number, y0: number, x1: number, y1: number) {
150
+ return linearGradient(this.painter, x0, y0, x1, y1)
151
+ }
152
+
153
+ // 环形渐变
154
+ createRadialGradient(cx: number, cy: number, r: number) {
155
+ return radialGradient(this.painter, cx, cy, r)
156
+ }
157
+
158
+ // 角度渐变
159
+ createConicGradient(cx: number, cy: number, beginDeg: number, deg?: number) {
160
+ return conicGradient(this.painter, cx, cy, beginDeg, deg)
161
+ }
162
+
163
+ // 获取指定位置颜色
164
+ getColor(x: number, y: number) {
165
+ x *= this.__scaleSize
166
+ y *= this.__scaleSize
167
+ const currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data
168
+ return (
169
+ "rgba(" +
170
+ currentRGBA[0] +
171
+ "," +
172
+ currentRGBA[1] +
173
+ "," +
174
+ currentRGBA[2] +
175
+ "," +
176
+ currentRGBA[3] +
177
+ ")"
178
+ )
179
+ }
180
+ }
181
+
182
+ export default Canvas
@@ -0,0 +1,30 @@
1
+ import { isPlainObject } from "./type"
2
+
3
+ // 初始化配置
4
+ export function initOption(setOption: any, defaultOption: any) {
5
+ for (const key in setOption) {
6
+ defaultOption[key] = setOption[key]
7
+ }
8
+
9
+ return defaultOption
10
+ }
11
+
12
+ // 合并配置
13
+ export function mergeOption(oldOption: any, newOption: any) {
14
+ (function doit(oldOption, newOption) {
15
+
16
+ for (const key in newOption) {
17
+ const value = newOption[key]
18
+
19
+ if (isPlainObject(value)) {
20
+ if (!oldOption[key]) oldOption[key] = {}
21
+
22
+ doit(oldOption[key], newOption[key])
23
+ } else {
24
+ oldOption[key] = value
25
+ }
26
+
27
+ }
28
+
29
+ })(oldOption, newOption)
30
+ }
@@ -2,7 +2,7 @@ import type TreeConfigType from '../../../types/TreeConfig'
2
2
  import type { TreeResultType } from '../../../types/Tree'
3
3
 
4
4
  import toPlainTree from './toPlainTree'
5
- import mergeOption from '../mergeOption'
5
+ import { initOption } from '../option'
6
6
 
7
7
  class Tree {
8
8
  readonly name: string = 'Tree'
@@ -10,7 +10,7 @@ class Tree {
10
10
  private __config: TreeConfigType
11
11
 
12
12
  constructor(config: TreeConfigType = {}) {
13
- this.__config = mergeOption(config, {
13
+ this.__config = initOption(config, {
14
14
  root: (initTree: any) => initTree,
15
15
  children: (parentTree: any) => parentTree.children,
16
16
  id: (treedata: any) => treedata.name
@@ -0,0 +1,27 @@
1
+ let toString = Object.prototype.toString
2
+
3
+ // 获取一个值的类型字符串[object type]
4
+ export function getType(value: any) {
5
+ if (value == null) {
6
+ return value === undefined ? '[object Undefined]' : '[object Null]'
7
+ }
8
+ return toString.call(value)
9
+ }
10
+
11
+ // 判断一个值是不是一个朴素的'对象'
12
+ export function isPlainObject(value: any) {
13
+ if (value === null || typeof value !== 'object' || getType(value) != '[object Object]') {
14
+ return false
15
+ }
16
+
17
+ // 如果原型为null
18
+ if (Object.getPrototypeOf(value) === null) {
19
+ return true
20
+ }
21
+
22
+ let proto = value
23
+ while (Object.getPrototypeOf(proto) !== null) {
24
+ proto = Object.getPrototypeOf(proto)
25
+ }
26
+ return Object.getPrototypeOf(value) === proto
27
+ }
@@ -3,7 +3,7 @@ import type { TreeResultType } from '../../types/Tree'
3
3
  import type TreeOptionType from '../../types/TreeOption'
4
4
 
5
5
  import Tree from '../common/tree/index'
6
- import mergeOption from '../common/mergeOption'
6
+ import { initOption } from '../common/option'
7
7
  import animation from '../animation'
8
8
  import rotate from '../rotate'
9
9
 
@@ -30,7 +30,7 @@ class TreeLayout extends Tree implements TreeLayoutType {
30
30
  private __noOpens = {}
31
31
 
32
32
  setOption(option: TreeOptionType) {
33
- mergeOption(option, this.__option)
33
+ initOption(option, this.__option)
34
34
  return this
35
35
  }
36
36
 
package/src/throttle.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type throttleOptionType from '../types/throttleOption'
2
2
 
3
- import mergeOption from './common/mergeOption'
3
+ import { initOption } from './common/option'
4
4
 
5
5
  export default function (callback: Function, option: throttleOptionType = {}) {
6
6
 
7
7
  // 校对缺省值
8
- option = mergeOption(option, <throttleOptionType>{
8
+ option = initOption(option, <throttleOptionType>{
9
9
  time: 200,
10
10
  keep: false,
11
11
  opportunity: "end"
package/types/Canvas.d.ts CHANGED
@@ -297,6 +297,15 @@ export default interface CanvasType {
297
297
  */
298
298
  createRadialGradient(cx: number, cy: number, r: number): GradientType<CanvasGradient>
299
299
 
300
+ /**
301
+ * 创建角度渐变
302
+ * @param cx 中心
303
+ * @param cy
304
+ * @param beginDeg 开始弧度
305
+ * @param deg 跨越弧度,可选,默认2PI
306
+ */
307
+ createConicGradient(cx: number, cy: number, beginDeg: number, deg?: number): GradientType<CanvasGradient>
308
+
300
309
  /**
301
310
  * 获取指定位置颜色
302
311
  * @param x
@@ -326,5 +335,5 @@ export default interface CanvasType {
326
335
  * @param eventName 事件名称
327
336
  * @param callback 回调函数
328
337
  */
329
- bind(eventName: string, callback: (regionName: string) => void): this
338
+ bind(eventName: string, callback: (regionName: string, x: number, y: number) => void): this
330
339
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 步进生成器
3
+ */
4
+ export default interface assembleType {
5
+ (begin: number, end: number, step: number, count: number): () => Array<number>
6
+ }