vislite 0.3.0 → 0.3.1

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 (129) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +7 -1
  3. package/LICENSE +20 -20
  4. package/README.md +53 -53
  5. package/lib/Buffer/index.umd.js +2 -2
  6. package/lib/Buffer/index.umd.min.js +2 -2
  7. package/lib/Canvas/index.umd.js +11 -6
  8. package/lib/Canvas/index.umd.min.js +3 -3
  9. package/lib/Cardinal/index.umd.js +2 -2
  10. package/lib/Cardinal/index.umd.min.js +2 -2
  11. package/lib/Eoap/index.umd.js +2 -2
  12. package/lib/Eoap/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 +11 -6
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +10 -5
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +9 -4
  24. package/lib/SVG/index.umd.min.js +3 -3
  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 +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/WebGL/index.umd.js +10 -5
  30. package/lib/WebGL/index.umd.min.js +3 -3
  31. package/lib/animation/index.umd.js +2 -2
  32. package/lib/animation/index.umd.min.js +2 -2
  33. package/lib/getLoopColors/index.umd.js +2 -2
  34. package/lib/getLoopColors/index.umd.min.js +2 -2
  35. package/lib/getWebGLContext/index.umd.js +2 -2
  36. package/lib/getWebGLContext/index.umd.min.js +2 -2
  37. package/lib/index.umd.js +11 -6
  38. package/lib/index.umd.min.js +3 -3
  39. package/lib/rotate/index.umd.js +2 -2
  40. package/lib/rotate/index.umd.min.js +2 -2
  41. package/lib/ruler/index.umd.js +2 -2
  42. package/lib/ruler/index.umd.min.js +2 -2
  43. package/lib/viewHandler/index.umd.js +2 -2
  44. package/lib/viewHandler/index.umd.min.js +2 -2
  45. package/miniprogram/ui-canvas/index.js +99 -99
  46. package/miniprogram/ui-canvas/index.json +4 -4
  47. package/miniprogram/ui-canvas/index.wxml +4 -4
  48. package/miniprogram/ui-canvas/index.wxss +5 -5
  49. package/package/Buffer/index.ts +1 -1
  50. package/package/Canvas/index.ts +1 -1
  51. package/package/Cardinal/index.ts +2 -2
  52. package/package/Eoap/index.ts +2 -2
  53. package/package/Hermite/index.ts +2 -2
  54. package/package/Matrix4/index.ts +2 -2
  55. package/package/Mercator/index.ts +2 -2
  56. package/package/OralCanvas/index.ts +1 -1
  57. package/package/OralWebGL/index.ts +1 -1
  58. package/package/SVG/index.ts +2 -2
  59. package/package/Shader/index.ts +1 -1
  60. package/package/Texture/index.ts +1 -1
  61. package/package/WebGL/index.ts +1 -1
  62. package/package/animation/index.ts +2 -2
  63. package/package/getLoopColors/index.ts +2 -2
  64. package/package/getWebGLContext/index.ts +39 -39
  65. package/package/index.ts +56 -56
  66. package/package/rotate/index.ts +2 -2
  67. package/package/ruler/index.ts +2 -2
  68. package/package/viewHandler/index.ts +2 -2
  69. package/package.json +1 -1
  70. package/src/Canvas.ts +56 -56
  71. package/src/Eoap.ts +66 -66
  72. package/src/Matrix4/index.ts +76 -76
  73. package/src/Matrix4/move.ts +12 -12
  74. package/src/Matrix4/rotate.ts +15 -15
  75. package/src/Matrix4/scale.ts +11 -11
  76. package/src/Matrix4/transform.ts +64 -64
  77. package/src/Mercator.ts +26 -26
  78. package/src/SVG.ts +23 -23
  79. package/src/WebGL.ts +52 -52
  80. package/src/animation.ts +99 -99
  81. package/src/common/assemble.ts +1 -1
  82. package/src/common/canvas/arc.ts +50 -50
  83. package/src/common/canvas/config.ts +157 -157
  84. package/src/common/canvas/gradient.ts +29 -29
  85. package/src/common/canvas/index.ts +10 -7
  86. package/src/common/canvas/painter.ts +355 -355
  87. package/src/common/canvas/texts.ts +18 -18
  88. package/src/common/setStyle.ts +5 -5
  89. package/src/common/svg/config.ts +173 -173
  90. package/src/common/svg/index.ts +334 -334
  91. package/src/common/svg/tool.ts +43 -43
  92. package/src/common/webgl/buffer.ts +79 -79
  93. package/src/common/webgl/doDraw.ts +106 -106
  94. package/src/common/webgl/getColorFactory.ts +26 -26
  95. package/src/common/webgl/getShader.ts +75 -75
  96. package/src/common/webgl/getTexture.ts +11 -11
  97. package/src/common/webgl/getWebGLContext.ts +27 -27
  98. package/src/common/webgl/index.ts +216 -216
  99. package/src/common/webgl/shader.ts +75 -75
  100. package/src/common/webgl/texture.ts +99 -99
  101. package/src/getLoopColors.ts +42 -42
  102. package/src/interpolation/Cardinal.ts +109 -109
  103. package/src/interpolation/Hermite.ts +65 -65
  104. package/src/rotate.ts +7 -7
  105. package/src/ruler.ts +99 -99
  106. package/src/viewHandler.ts +139 -139
  107. package/types/Buffer.d.ts +23 -23
  108. package/types/Canvas.d.ts +282 -282
  109. package/types/CanvasConfig.d.ts +80 -80
  110. package/types/Cardinal.d.ts +13 -13
  111. package/types/Gradient.d.ts +14 -14
  112. package/types/Hermite.d.ts +18 -18
  113. package/types/Map.d.ts +9 -9
  114. package/types/Matrix4.d.ts +42 -42
  115. package/types/Object3D.d.ts +113 -113
  116. package/types/SVG.d.ts +210 -210
  117. package/types/SVGConfig.d.ts +58 -58
  118. package/types/Scene3D.d.ts +6 -6
  119. package/types/Shader.d.ts +15 -15
  120. package/types/Texture.d.ts +16 -16
  121. package/types/WebGL.d.ts +38 -38
  122. package/types/animation.d.ts +6 -6
  123. package/types/getLoopColors.d.ts +2 -2
  124. package/types/getWebGLContext.d.ts +2 -2
  125. package/types/index.d.ts +129 -129
  126. package/types/rotate.d.ts +2 -2
  127. package/types/ruler.d.ts +2 -2
  128. package/types/viewHandler.d.ts +12 -12
  129. package/uni-app/ui-canvas.vue +212 -212
@@ -1,212 +1,212 @@
1
- <template>
2
- <view :class="cover || isH5 ? 'cover-view' : 'normal-view'">
3
- <view :class="'view-img view-' + uniqueid" @touchstart="doitstart">
4
- <image :style="{ width: width + 'px', height: height + 'px' }" :src="viewImg"></image>
5
- </view>
6
-
7
- <!-- #ifdef MP-ALIPAY -->
8
- <canvas class="painter" :id="'painter-' + uniqueid" @touchstart="doitstart"
9
- :style="{ width: width + 'px', height: height + 'px' }"></canvas>
10
- <canvas class="region" :id="'region-' + uniqueid" :style="{ width: width + 'px', height: height + 'px' }"></canvas>
11
- <!-- #endif -->
12
- <!-- #ifdef MP-WEIXIN -->
13
- <canvas class="painter" canvas-id="painter" @touchstart="doitstart"
14
- :style="{ width: width + 'px', height: height + 'px' }"></canvas>
15
- <canvas class="region" canvas-id="region" :style="{ width: width + 'px', height: height + 'px' }"></canvas>
16
- <!-- #endif -->
17
- <!-- #ifndef MP-WEIXIN||MP-ALIPAY -->
18
- <canvas class="painter" :canvas-id="'painter-' + uniqueid" @touchstart="doitstart"
19
- :style="{ width: width + 'px', height: height + 'px' }"></canvas>
20
- <canvas class="region" :canvas-id="'region-' + uniqueid"
21
- :style="{ width: width + 'px', height: height + 'px' }"></canvas>
22
- <!-- #endif -->
23
- </view>
24
- </template>
25
- <script>
26
- import OralCanvas from "../lib/OralCanvas/index.es.js";
27
- export default {
28
- data() {
29
- return {
30
- uniqueid: (Math.random() * 10000).toFixed(0),
31
- help: {},
32
- viewImg: "",
33
- // #ifdef H5
34
- isH5: true,
35
- // #endif
36
- // #ifndef H5
37
- isH5: false,
38
- // #endif
39
- };
40
- },
41
- props: {
42
- width: {
43
- type: Number,
44
- default: 300,
45
- },
46
- height: {
47
- type: Number,
48
- default: 150,
49
- },
50
- touchstart: {
51
- type: Function,
52
- default: () => { },
53
- },
54
- cover: {
55
- type: Boolean,
56
- default: true,
57
- },
58
- },
59
- methods: {
60
- fetch() {
61
- let painter, region, painterid, regionid;
62
- // #ifdef MP-WEIXIN
63
- painter = uni.createCanvasContext("painter", this);
64
- region = uni.createCanvasContext("region", this);
65
- painterid = "painter";
66
- regionid = "region";
67
- // #endif
68
- // #ifndef MP-WEIXIN
69
- painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
70
- region = uni.createCanvasContext("region-" + this.uniqueid, this);
71
- painterid = "painter-" + this.uniqueid;
72
- regionid = "region-" + this.uniqueid;
73
- // #endif
74
-
75
- let _this = this;
76
- this.help.instance = new OralCanvas(
77
- {
78
- getContext() {
79
- return painter;
80
- },
81
- },
82
- {
83
- getContext() {
84
- // #ifdef MP-ALIPAY
85
- let getImageData = region.getImageData;
86
- // #endif
87
- region.getImageData = (x, y, width, height) => {
88
- return new Promise((resolve, reject) => {
89
- let options = {
90
- x,
91
- y,
92
- width,
93
- height,
94
- canvasId: regionid,
95
- success: function success(res) {
96
- resolve(res.data);
97
- },
98
- fail: function fail(error) {
99
- reject(error);
100
- },
101
- };
102
-
103
- // #ifdef MP-ALIPAY
104
- getImageData(options, _this);
105
- // #endif
106
- // #ifndef MP-ALIPAY
107
- uni.canvasGetImageData(options, _this);
108
- // #endif
109
- });
110
- };
111
- return region;
112
- },
113
- }
114
- );
115
- this.help.instance.draw = () => {
116
- painter.draw();
117
- region.draw();
118
-
119
- // 如果不使用原生渲染
120
- if (!this.cover && !this.isH5) {
121
- setTimeout(() => {
122
- uni.canvasToTempFilePath(
123
- {
124
- canvasId: painterid,
125
- success: (e) => {
126
- this.viewImg = e.tempFilePath;
127
- },
128
- },
129
- this
130
- );
131
- }, 300);
132
- }
133
- };
134
- return new Promise((resolve, reject) => {
135
- this.help.instance.toDataURL = () => {
136
- return new Promise((resolveUrl) => {
137
- uni.canvasToTempFilePath(
138
- {
139
- canvasId: painterid,
140
- success: function (e) {
141
- resolveUrl(e.tempFilePath);
142
- },
143
- },
144
- this
145
- );
146
- });
147
- };
148
-
149
- resolve(this.help.instance);
150
- });
151
- },
152
- doit(event, doback) {
153
- let doRun = (x, y) => {
154
- this.help.instance.getRegion(x, y).then((regionName) => {
155
- // 兼容旧语法
156
- if (typeof doback == "function") doback(regionName);
157
-
158
- this.$emit("dotouchstart", {
159
- name: regionName,
160
- x: x,
161
- y: y,
162
- });
163
- });
164
- };
165
-
166
- if (this.cover || this.isH5) {
167
- let x = event.touches[0].x;
168
- let y = event.touches[0].y;
169
- doRun(x, y);
170
- } else {
171
- uni
172
- .createSelectorQuery()
173
- .selectViewport()
174
- .scrollOffset()
175
- .exec((ret) => {
176
- uni
177
- .createSelectorQuery()
178
- .in(this)
179
- .select(".view-" + this.uniqueid)
180
- .boundingClientRect((data) => {
181
- doRun(
182
- event.touches[0].pageX - data.left - ret[0].scrollLeft,
183
- event.touches[0].pageY - data.top - ret[0].scrollTop
184
- );
185
- })
186
- .exec();
187
- });
188
- }
189
- },
190
- doitstart(event) {
191
- this.doit(event, this.touchstart);
192
- },
193
- },
194
- };
195
- </script>
196
-
197
- <style lang="css" scoped>
198
- /* 辅助的区域不应该可以看见 */
199
- .region {
200
- position: fixed;
201
- left: 50000px;
202
- }
203
-
204
- .cover-view .view-img {
205
- display: none;
206
- }
207
-
208
- .normal-view .painter {
209
- position: fixed;
210
- left: 50000px;
211
- }
212
- </style>
1
+ <template>
2
+ <view :class="cover || isH5 ? 'cover-view' : 'normal-view'">
3
+ <view :class="'view-img view-' + uniqueid" @touchstart="doitstart">
4
+ <image :style="{ width: width + 'px', height: height + 'px' }" :src="viewImg"></image>
5
+ </view>
6
+
7
+ <!-- #ifdef MP-ALIPAY -->
8
+ <canvas class="painter" :id="'painter-' + uniqueid" @touchstart="doitstart"
9
+ :style="{ width: width + 'px', height: height + 'px' }"></canvas>
10
+ <canvas class="region" :id="'region-' + uniqueid" :style="{ width: width + 'px', height: height + 'px' }"></canvas>
11
+ <!-- #endif -->
12
+ <!-- #ifdef MP-WEIXIN -->
13
+ <canvas class="painter" canvas-id="painter" @touchstart="doitstart"
14
+ :style="{ width: width + 'px', height: height + 'px' }"></canvas>
15
+ <canvas class="region" canvas-id="region" :style="{ width: width + 'px', height: height + 'px' }"></canvas>
16
+ <!-- #endif -->
17
+ <!-- #ifndef MP-WEIXIN||MP-ALIPAY -->
18
+ <canvas class="painter" :canvas-id="'painter-' + uniqueid" @touchstart="doitstart"
19
+ :style="{ width: width + 'px', height: height + 'px' }"></canvas>
20
+ <canvas class="region" :canvas-id="'region-' + uniqueid"
21
+ :style="{ width: width + 'px', height: height + 'px' }"></canvas>
22
+ <!-- #endif -->
23
+ </view>
24
+ </template>
25
+ <script>
26
+ import OralCanvas from "../lib/OralCanvas/index.es.js";
27
+ export default {
28
+ data() {
29
+ return {
30
+ uniqueid: (Math.random() * 10000).toFixed(0),
31
+ help: {},
32
+ viewImg: "",
33
+ // #ifdef H5
34
+ isH5: true,
35
+ // #endif
36
+ // #ifndef H5
37
+ isH5: false,
38
+ // #endif
39
+ };
40
+ },
41
+ props: {
42
+ width: {
43
+ type: Number,
44
+ default: 300,
45
+ },
46
+ height: {
47
+ type: Number,
48
+ default: 150,
49
+ },
50
+ touchstart: {
51
+ type: Function,
52
+ default: () => { },
53
+ },
54
+ cover: {
55
+ type: Boolean,
56
+ default: true,
57
+ },
58
+ },
59
+ methods: {
60
+ fetch() {
61
+ let painter, region, painterid, regionid;
62
+ // #ifdef MP-WEIXIN
63
+ painter = uni.createCanvasContext("painter", this);
64
+ region = uni.createCanvasContext("region", this);
65
+ painterid = "painter";
66
+ regionid = "region";
67
+ // #endif
68
+ // #ifndef MP-WEIXIN
69
+ painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
70
+ region = uni.createCanvasContext("region-" + this.uniqueid, this);
71
+ painterid = "painter-" + this.uniqueid;
72
+ regionid = "region-" + this.uniqueid;
73
+ // #endif
74
+
75
+ let _this = this;
76
+ this.help.instance = new OralCanvas(
77
+ {
78
+ getContext() {
79
+ return painter;
80
+ },
81
+ },
82
+ {
83
+ getContext() {
84
+ // #ifdef MP-ALIPAY
85
+ let getImageData = region.getImageData;
86
+ // #endif
87
+ region.getImageData = (x, y, width, height) => {
88
+ return new Promise((resolve, reject) => {
89
+ let options = {
90
+ x,
91
+ y,
92
+ width,
93
+ height,
94
+ canvasId: regionid,
95
+ success: function success(res) {
96
+ resolve(res.data);
97
+ },
98
+ fail: function fail(error) {
99
+ reject(error);
100
+ },
101
+ };
102
+
103
+ // #ifdef MP-ALIPAY
104
+ getImageData(options, _this);
105
+ // #endif
106
+ // #ifndef MP-ALIPAY
107
+ uni.canvasGetImageData(options, _this);
108
+ // #endif
109
+ });
110
+ };
111
+ return region;
112
+ },
113
+ }
114
+ );
115
+ this.help.instance.draw = () => {
116
+ painter.draw();
117
+ region.draw();
118
+
119
+ // 如果不使用原生渲染
120
+ if (!this.cover && !this.isH5) {
121
+ setTimeout(() => {
122
+ uni.canvasToTempFilePath(
123
+ {
124
+ canvasId: painterid,
125
+ success: (e) => {
126
+ this.viewImg = e.tempFilePath;
127
+ },
128
+ },
129
+ this
130
+ );
131
+ }, 300);
132
+ }
133
+ };
134
+ return new Promise((resolve, reject) => {
135
+ this.help.instance.toDataURL = () => {
136
+ return new Promise((resolveUrl) => {
137
+ uni.canvasToTempFilePath(
138
+ {
139
+ canvasId: painterid,
140
+ success: function (e) {
141
+ resolveUrl(e.tempFilePath);
142
+ },
143
+ },
144
+ this
145
+ );
146
+ });
147
+ };
148
+
149
+ resolve(this.help.instance);
150
+ });
151
+ },
152
+ doit(event, doback) {
153
+ let doRun = (x, y) => {
154
+ this.help.instance.getRegion(x, y).then((regionName) => {
155
+ // 兼容旧语法
156
+ if (typeof doback == "function") doback(regionName);
157
+
158
+ this.$emit("dotouchstart", {
159
+ name: regionName,
160
+ x: x,
161
+ y: y,
162
+ });
163
+ });
164
+ };
165
+
166
+ if (this.cover || this.isH5) {
167
+ let x = event.touches[0].x;
168
+ let y = event.touches[0].y;
169
+ doRun(x, y);
170
+ } else {
171
+ uni
172
+ .createSelectorQuery()
173
+ .selectViewport()
174
+ .scrollOffset()
175
+ .exec((ret) => {
176
+ uni
177
+ .createSelectorQuery()
178
+ .in(this)
179
+ .select(".view-" + this.uniqueid)
180
+ .boundingClientRect((data) => {
181
+ doRun(
182
+ event.touches[0].pageX - data.left - ret[0].scrollLeft,
183
+ event.touches[0].pageY - data.top - ret[0].scrollTop
184
+ );
185
+ })
186
+ .exec();
187
+ });
188
+ }
189
+ },
190
+ doitstart(event) {
191
+ this.doit(event, this.touchstart);
192
+ },
193
+ },
194
+ };
195
+ </script>
196
+
197
+ <style lang="css" scoped>
198
+ /* 辅助的区域不应该可以看见 */
199
+ .region {
200
+ position: fixed;
201
+ left: 50000px;
202
+ }
203
+
204
+ .cover-view .view-img {
205
+ display: none;
206
+ }
207
+
208
+ .normal-view .painter {
209
+ position: fixed;
210
+ left: 50000px;
211
+ }
212
+ </style>