vislite 0.1.0 → 0.2.0-alpha.7

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 (112) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +24 -1
  3. package/LICENSE +20 -20
  4. package/README.md +53 -38
  5. package/lib/Canvas/index.umd.js +135 -46
  6. package/lib/Canvas/index.umd.min.js +7 -3
  7. package/lib/Cardinal/index.umd.js +6 -2
  8. package/lib/Cardinal/index.umd.min.js +6 -2
  9. package/lib/Eoap/index.umd.js +9 -5
  10. package/lib/Eoap/index.umd.min.js +6 -2
  11. package/lib/Hermite/index.umd.js +6 -2
  12. package/lib/Hermite/index.umd.min.js +6 -2
  13. package/lib/Matrix4/index.umd.js +6 -2
  14. package/lib/Matrix4/index.umd.min.js +6 -2
  15. package/lib/Mercator/index.umd.js +42 -0
  16. package/lib/Mercator/index.umd.min.js +15 -0
  17. package/lib/OralCanvas/index.es.js +124 -44
  18. package/lib/OralCanvas/index.es.min.js +7 -3
  19. package/lib/OralWebGL/index.es.js +567 -0
  20. package/lib/OralWebGL/index.es.min.js +15 -0
  21. package/lib/SVG/index.umd.js +16 -5
  22. package/lib/SVG/index.umd.min.js +7 -3
  23. package/lib/WebGL/index.umd.js +626 -0
  24. package/lib/WebGL/index.umd.min.js +15 -0
  25. package/lib/animation/index.umd.js +6 -2
  26. package/lib/animation/index.umd.min.js +6 -2
  27. package/lib/getLoopColors/index.umd.js +6 -2
  28. package/lib/getLoopColors/index.umd.min.js +6 -2
  29. package/lib/index.umd.js +1514 -863
  30. package/lib/index.umd.min.js +7 -3
  31. package/lib/rotate/index.umd.js +6 -2
  32. package/lib/rotate/index.umd.min.js +6 -2
  33. package/lib/ruler/index.umd.js +6 -2
  34. package/lib/ruler/index.umd.min.js +6 -2
  35. package/lib/viewHandler/index.umd.js +129 -0
  36. package/lib/viewHandler/index.umd.min.js +15 -0
  37. package/miniprogram/ui-canvas/index.js +18 -3
  38. package/miniprogram/ui-canvas/index.json +4 -4
  39. package/miniprogram/ui-canvas/index.wxml +4 -4
  40. package/miniprogram/ui-canvas/index.wxss +5 -5
  41. package/package/Canvas/index.ts +1 -1
  42. package/package/Cardinal/index.ts +2 -2
  43. package/package/Eoap/index.ts +2 -2
  44. package/package/Hermite/index.ts +2 -2
  45. package/package/Matrix4/index.ts +2 -2
  46. package/package/Mercator/index.ts +3 -0
  47. package/package/OralCanvas/index.ts +1 -1
  48. package/package/OralWebGL/index.ts +2 -0
  49. package/package/SVG/index.ts +2 -2
  50. package/package/WebGL/index.ts +2 -0
  51. package/package/animation/index.ts +2 -2
  52. package/package/getLoopColors/index.ts +2 -2
  53. package/package/index.ts +32 -9
  54. package/package/rotate/index.ts +2 -2
  55. package/package/ruler/index.ts +2 -2
  56. package/package/viewHandler/index.ts +3 -0
  57. package/package.json +11 -2
  58. package/src/Canvas.ts +10 -1
  59. package/src/Eoap.ts +5 -5
  60. package/src/Matrix4/index.ts +76 -76
  61. package/src/Matrix4/move.ts +12 -12
  62. package/src/Matrix4/rotate.ts +15 -15
  63. package/src/Matrix4/scale.ts +11 -11
  64. package/src/Matrix4/transform.ts +64 -64
  65. package/src/Mercator.ts +27 -0
  66. package/src/SVG.ts +1 -1
  67. package/src/WebGL.ts +53 -0
  68. package/src/animation.ts +99 -99
  69. package/src/common/assemble.ts +23 -0
  70. package/src/common/canvas/arc.ts +50 -50
  71. package/src/common/canvas/config.ts +7 -6
  72. package/src/common/canvas/index.ts +29 -28
  73. package/src/common/canvas/painter.ts +51 -8
  74. package/src/common/canvas/texts.ts +19 -0
  75. package/src/common/setStyle.ts +5 -5
  76. package/src/common/svg/config.ts +127 -126
  77. package/src/common/svg/index.ts +13 -3
  78. package/src/common/svg/tool.ts +43 -42
  79. package/src/common/webgl/buffer.ts +80 -0
  80. package/src/common/webgl/doDraw.ts +97 -0
  81. package/src/common/webgl/getColorFactory.ts +27 -0
  82. package/src/common/webgl/getShader.ts +62 -0
  83. package/src/common/webgl/getTexture.ts +12 -0
  84. package/src/common/webgl/getWebGLContext.ts +28 -0
  85. package/src/common/webgl/index.ts +212 -0
  86. package/src/common/webgl/shader.ts +76 -0
  87. package/src/common/webgl/texture.ts +99 -0
  88. package/src/getLoopColors.ts +42 -42
  89. package/src/interpolation/Cardinal.ts +91 -91
  90. package/src/interpolation/Hermite.ts +65 -65
  91. package/src/rotate.ts +7 -7
  92. package/src/ruler.ts +99 -99
  93. package/src/viewHandler.ts +140 -0
  94. package/types/Canvas.d.ts +220 -283
  95. package/types/CanvasConfig.d.ts +81 -0
  96. package/types/Cardinal.d.ts +13 -13
  97. package/types/Hermite.d.ts +18 -18
  98. package/types/Map.d.ts +10 -0
  99. package/types/Matrix4.d.ts +42 -42
  100. package/types/Object3D.d.ts +106 -0
  101. package/types/SVG.d.ts +210 -264
  102. package/types/SVGConfig.d.ts +59 -0
  103. package/types/Scene3D.d.ts +7 -0
  104. package/types/WebGL.d.ts +29 -0
  105. package/types/animation.d.ts +6 -6
  106. package/types/getLoopColors.d.ts +2 -2
  107. package/types/index.d.ts +70 -26
  108. package/types/rotate.d.ts +2 -2
  109. package/types/ruler.d.ts +2 -2
  110. package/types/viewHandler.d.ts +13 -0
  111. package/uni-app/ui-canvas.vue +94 -20
  112. package/types/Eoap.d.ts +0 -10
@@ -0,0 +1,59 @@
1
+ export default interface SVGConfigType {
2
+
3
+ /**
4
+ * 填充色或图案,默认"#000"
5
+ */
6
+ fillStyle?: string
7
+
8
+ /**
9
+ * 轮廓色或图案,默认"#000"
10
+ */
11
+ strokeStyle?: string
12
+
13
+ /**
14
+ * 线条宽度,默认1(单位px)
15
+ */
16
+ lineWidth?: number
17
+
18
+ /**
19
+ * 文字水平对齐方式,默认"left"左对齐(还有"center"居中和"right"右对齐)
20
+ */
21
+ textAlign?: string
22
+
23
+ /**
24
+ * 文字垂直对齐方式,默认"middle"垂直居中(还有"top"上对齐和"bottom"下对齐)
25
+ */
26
+ textBaseline?: string
27
+
28
+ /**
29
+ * 设置线条虚线,默认为[]表示使用实线绘制
30
+ *
31
+ * 值应该是一个数组,格式:[实线长,虚线长,实线长 ...],数组长度任意,会自动循环
32
+ */
33
+ lineDash?: Array<number>
34
+
35
+ /**
36
+ * 文字大小,默认16
37
+ */
38
+ "fontSize"?: number
39
+ "font-size"?: number // 向下兼容
40
+
41
+ /**
42
+ * 字体,默认"sans-serif"
43
+ */
44
+ "fontFamily"?: string
45
+ "font-family"?: string // 向下兼容
46
+
47
+ /**
48
+ * 圆弧开始端闭合方式,默认"butt"直线闭合(还有"round"圆帽闭合,"-round"反圆帽闭合)
49
+ */
50
+ "arcStartCap"?: string
51
+ "arc-start-cap"?: string // 向下兼容
52
+
53
+ /**
54
+ * 圆弧结束端闭合方式,默认"butt"直线闭合(还有"round"圆帽闭合,"-round"反圆帽闭合)
55
+ */
56
+ "arcEndCap"?: string
57
+ "arc-end-cap"?: string // 向下兼容
58
+
59
+ }
@@ -0,0 +1,7 @@
1
+ import Object3D from './Object3D'
2
+ import Matrix4Type from './Matrix4'
3
+
4
+ export default interface Scene3D {
5
+ children: Object3D[]
6
+ matrix: Matrix4Type
7
+ }
@@ -0,0 +1,29 @@
1
+ import Object3DType from './Object3D'
2
+ import Matrix4Type from './Matrix4'
3
+
4
+ export default interface WebGLType {
5
+
6
+ matrix(initMatrix4?: number[]): Matrix4Type
7
+
8
+ /**
9
+ * 使用模型数据绘制
10
+ * @param object3D 记录着的模型数据
11
+ */
12
+ render(object3D: Object3DType): void
13
+
14
+ /**
15
+ * 重新绘制
16
+ */
17
+ review(): this
18
+
19
+ /**
20
+ * 返回变换矩阵
21
+ */
22
+ getMatrix(): Matrix4Type
23
+
24
+ /**
25
+ * 返回所有的Object3D内容
26
+ */
27
+ getObject3D(): Object3DType[]
28
+
29
+ }
@@ -1,7 +1,7 @@
1
- interface animationFun {
2
- (deep: number): void
3
- }
4
-
5
- export default interface animationType {
6
- (doback: animationFun, duration?: number, callback?: animationFun): Function
1
+ interface animationFun {
2
+ (deep: number): void
3
+ }
4
+
5
+ export default interface animationType {
6
+ (doback: animationFun, duration?: number, callback?: animationFun): Function
7
7
  }
@@ -1,3 +1,3 @@
1
- export default interface getLoopColorsType {
2
- (num: number, alpha?: number): string[]
1
+ export default interface getLoopColorsType {
2
+ (num: number, alpha?: number): string[]
3
3
  }
package/types/index.d.ts CHANGED
@@ -1,58 +1,102 @@
1
- import Matrix4Type from './Matrix4'
2
- import CanvasType from './Canvas'
3
- import SVGType from './SVG'
4
- import EoapType from './Eoap'
5
- import HermiteType from './Hermite'
6
1
  import CardinalType from './Cardinal'
2
+ import HermiteType from './Hermite'
3
+
4
+ import Matrix4Type from './Matrix4'
7
5
  import rotateType from './rotate'
8
- import animationType from './animation'
6
+
9
7
  import getLoopColorsType from './getLoopColors'
8
+ import animationType from './animation'
10
9
  import rulerType from './ruler'
11
10
 
12
- interface NewCanvasType extends CanvasType {
13
- new(el: HTMLElement | null): this
14
- }
11
+ import SVGType from './SVG'
12
+ import CanvasType from './Canvas'
13
+ import WebGLType from './WebGL'
14
+
15
+ import MapType from './Map'
15
16
 
17
+ import viewHandlerType from './viewHandler'
18
+
19
+ // 插值
16
20
  interface NewCardinalType extends CardinalType {
17
21
  new(t?: number): this
18
22
  }
19
-
20
- interface NewEoapType extends EoapType {
21
- new(scale?: number, center?: number[]): this
22
- }
23
-
24
23
  interface NewHermiteType extends HermiteType {
25
- new(u: number): this
24
+ new(u?: number): this
26
25
  }
27
26
 
27
+ // 变换
28
28
  interface NewMatrix4Type extends Matrix4Type {
29
29
  new(initMatrix4?: number[]): this
30
30
  }
31
31
 
32
+ // 画笔
32
33
  interface NewSVGType extends SVGType {
33
34
  new(el: HTMLElement | null): this
34
35
  }
36
+ interface NewCanvasType extends CanvasType {
37
+ new(el: HTMLElement | null): this
38
+ }
39
+ interface NewWebGLType extends WebGLType {
40
+ new(el: HTMLElement | null): this
41
+ }
42
+
43
+ // 投影
44
+ interface NewEoapType extends MapType {
45
+ new(scale?: number, center?: number[]): this
46
+ }
47
+ interface NewMercatorType extends MapType {
48
+ new(scale?: number, center?: number[]): this
49
+ }
35
50
 
36
51
  export default class VISLite {
52
+
53
+ // 插值
54
+ static Cardinal: NewCardinalType
55
+ static Hermite: NewHermiteType
56
+
57
+ // 变换
37
58
  static Matrix4: NewMatrix4Type
38
- static Canvas: NewCanvasType
39
- static SVG: NewSVGType
40
- static Eoap: NewEoapType
41
59
  static rotate: rotateType
42
- static Hermite: NewHermiteType
43
- static Cardinal: NewCardinalType
60
+
61
+ // 工具
44
62
  static getLoopColors: getLoopColorsType
45
63
  static animation: animationType
46
64
  static ruler: rulerType
65
+
66
+ // 画笔
67
+ static SVG: NewSVGType
68
+ static Canvas: NewCanvasType
69
+ static WebGL: NewWebGLType
70
+
71
+ // 投影
72
+ static Eoap: NewEoapType
73
+ static Mercator: NewMercatorType
74
+
75
+ // 辅助
76
+ static viewHandler: viewHandlerType
47
77
  }
48
78
 
79
+ // 插值
80
+ export let Cardinal: NewCardinalType
81
+ export let Hermite: NewHermiteType
82
+
83
+ // 变换
49
84
  export let Matrix4: NewMatrix4Type
50
- export let Canvas: NewCanvasType
51
- export let SVG: NewSVGType
52
- export let Eoap: NewEoapType
53
85
  export let rotate: rotateType
54
- export let Hermite: NewHermiteType
55
- export let Cardinal: NewCardinalType
86
+
87
+ // 工具
56
88
  export let getLoopColors: getLoopColorsType
57
89
  export let animation: animationType
58
- export let ruler: rulerType
90
+ export let ruler: rulerType
91
+
92
+ // 画笔
93
+ export let SVG: NewSVGType
94
+ export let Canvas: NewCanvasType
95
+ export let WebGL: NewWebGLType
96
+
97
+ // 投影
98
+ export let Eoap: NewEoapType
99
+ export let Mercator: NewMercatorType
100
+
101
+ // 辅助
102
+ export let viewHandler: viewHandlerType
package/types/rotate.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export default interface rotateType {
2
- (cx: number, cy: number, deg: number, x: number, y: number): number[]
1
+ export default interface rotateType {
2
+ (cx: number, cy: number, deg: number, x: number, y: number): number[]
3
3
  }
package/types/ruler.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export default interface rulerType {
2
- (maxValue: number, minValue: number, num: number): number[]
1
+ export default interface rulerType {
2
+ (maxValue: number, minValue: number, num: number): number[]
3
3
  }
@@ -0,0 +1,13 @@
1
+ export interface paramsType {
2
+ type: string
3
+ value: number,
4
+ normal: number[]
5
+ }
6
+
7
+ export interface callbackFun {
8
+ (params: paramsType): void
9
+ }
10
+
11
+ export default interface viewHandlerType {
12
+ (callback: callbackFun): void
13
+ }
@@ -1,7 +1,15 @@
1
1
  <template>
2
- <view>
2
+ <view :class="cover || isH5 ? 'cover-view' : 'normal-view'">
3
+ <view :class="'view-img view-' + uniqueid" @touchstart="doitstart">
4
+ <image
5
+ :style="{ width: width + 'px', height: height + 'px' }"
6
+ :src="viewImg"
7
+ ></image>
8
+ </view>
9
+
3
10
  <!-- #ifdef MP-ALIPAY -->
4
11
  <canvas
12
+ class="painter"
5
13
  :id="'painter-' + uniqueid"
6
14
  @touchstart="doitstart"
7
15
  :style="{ width: width + 'px', height: height + 'px' }"
@@ -14,6 +22,7 @@
14
22
  <!-- #endif -->
15
23
  <!-- #ifdef MP-WEIXIN -->
16
24
  <canvas
25
+ class="painter"
17
26
  canvas-id="painter"
18
27
  @touchstart="doitstart"
19
28
  :style="{ width: width + 'px', height: height + 'px' }"
@@ -26,6 +35,7 @@
26
35
  <!-- #endif -->
27
36
  <!-- #ifndef MP-WEIXIN||MP-ALIPAY -->
28
37
  <canvas
38
+ class="painter"
29
39
  :canvas-id="'painter-' + uniqueid"
30
40
  @touchstart="doitstart"
31
41
  :style="{ width: width + 'px', height: height + 'px' }"
@@ -45,6 +55,13 @@ export default {
45
55
  return {
46
56
  uniqueid: (Math.random() * 10000).toFixed(0),
47
57
  help: {},
58
+ viewImg: "",
59
+ // #ifdef H5
60
+ isH5: true
61
+ // #endif
62
+ // #ifndef H5
63
+ isH5: false
64
+ // #endif
48
65
  };
49
66
  },
50
67
  props: {
@@ -58,19 +75,25 @@ export default {
58
75
  },
59
76
  touchstart: {
60
77
  type: Function,
61
- default: () => {},
78
+ default: () => { },
62
79
  },
80
+ cover: {
81
+ type: Boolean,
82
+ default: true
83
+ }
63
84
  },
64
85
  methods: {
65
86
  fetch() {
66
87
  // #ifdef MP-WEIXIN
67
88
  let painter = uni.createCanvasContext("painter", this);
68
89
  let region = uni.createCanvasContext("region", this);
90
+ let painterid = "painter";
69
91
  let regionid = "region";
70
92
  // #endif
71
93
  // #ifndef MP-WEIXIN
72
94
  let painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
73
95
  let region = uni.createCanvasContext("region-" + this.uniqueid, this);
96
+ let painterid = "painter-" + this.uniqueid;
74
97
  let regionid = "region-" + this.uniqueid;
75
98
  // #endif
76
99
 
@@ -114,34 +137,76 @@ export default {
114
137
  this.help.instance.draw = () => {
115
138
  painter.draw();
116
139
  region.draw();
140
+
141
+ // 如果不使用原生渲染
142
+ if (!this.cover && !this.isH5) {
143
+ uni.canvasToTempFilePath({
144
+ canvasId: painterid,
145
+ success: (e) => {
146
+ this.viewImg = e.tempFilePath;
147
+ }
148
+ }, this);
149
+ }
150
+
117
151
  };
118
152
  return new Promise((resolve, reject) => {
153
+ this.help.instance.toDataURL = () => {
154
+ return new Promise((resolveUrl) => {
155
+ uni.canvasToTempFilePath(
156
+ {
157
+ canvasId: painterid,
158
+ success: function (e) {
159
+ resolveUrl(e.tempFilePath);
160
+ },
161
+ },
162
+ this
163
+ );
164
+ });
165
+ };
166
+
119
167
  resolve(this.help.instance);
120
168
  });
121
169
  },
122
170
  doit(event, doback) {
123
171
  let doRun = (x, y) => {
124
172
  this.help.instance.getRegion(x, y).then((regionName) => {
125
- doback(regionName);
173
+ // 兼容旧语法
174
+ if (doback) doback(regionName);
175
+
176
+ this.$emit("dotouchstart", {
177
+ name: regionName,
178
+ x: x,
179
+ y: y,
180
+ });
126
181
  });
127
182
  };
128
183
 
129
- // #ifdef MP-ALIPAY
130
- uni
131
- .createSelectorQuery()
132
- .selectViewport()
133
- .scrollOffset()
134
- .exec((ret) => {
135
- let x = event.touches[0].x + ret[0].scrollLeft;
136
- let y = event.touches[0].y + ret[0].scrollTop;
137
- doRun(x, y);
138
- });
139
- // #endif
140
- // #ifndef MP-ALIPAY
141
- let x = event.touches[0].x;
142
- let y = event.touches[0].y;
143
- doRun(x, y);
144
- // #endif
184
+ if (this.cover || this.isH5) {
185
+
186
+ // #ifdef MP-ALIPAY
187
+ uni
188
+ .createSelectorQuery()
189
+ .selectViewport()
190
+ .scrollOffset()
191
+ .exec((ret) => {
192
+ let x = event.touches[0].x + ret[0].scrollLeft;
193
+ let y = event.touches[0].y + ret[0].scrollTop;
194
+ doRun(x, y);
195
+ });
196
+ // #endif
197
+ // #ifndef MP-ALIPAY
198
+ let x = event.touches[0].x;
199
+ let y = event.touches[0].y;
200
+ doRun(x, y);
201
+ // #endif
202
+
203
+ } else {
204
+
205
+ uni.createSelectorQuery().in(this).select('.view-' + this.uniqueid).boundingClientRect(data => {
206
+ doRun(event.touches[0].pageX - data.left, event.touches[0].pageY - data.top);
207
+ }).exec()
208
+
209
+ }
145
210
  },
146
211
  doitstart(event) {
147
212
  this.doit(event, this.touchstart);
@@ -150,10 +215,19 @@ export default {
150
215
  };
151
216
  </script>
152
217
 
153
- <style lang="scss" scoped>
218
+ <style lang="css" scoped>
154
219
  /* 辅助的区域不应该可以看见 */
155
220
  .region {
156
221
  position: fixed;
157
222
  left: 50000px;
158
223
  }
224
+
225
+ .cover-view .view-img {
226
+ display: none;
227
+ }
228
+
229
+ .normal-view .painter {
230
+ position: fixed;
231
+ left: 50000px;
232
+ }
159
233
  </style>
package/types/Eoap.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export default interface EoapType {
2
-
3
- /**
4
- * 返回该点的绘图坐标(特别需要注意,计算出来的位置是偏离中心点的距离)
5
- * @param longitude 经纬度
6
- * @param latitude
7
- */
8
- use(longitude: number, latitude: number): number[]
9
-
10
- }