vislite 0.8.0 → 1.0.0-next.0

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 (201) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +17 -2
  3. package/LICENSE +20 -20
  4. package/README.md +2 -36
  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 +9 -24
  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/SVG/index.umd.js +19 -35
  20. package/lib/SVG/index.umd.min.js +3 -3
  21. package/lib/Shader/index.umd.js +3 -82
  22. package/lib/Shader/index.umd.min.js +3 -3
  23. package/lib/Texture/index.umd.js +2 -2
  24. package/lib/Texture/index.umd.min.js +2 -2
  25. package/lib/TreeLayout/index.umd.js +2 -2
  26. package/lib/TreeLayout/index.umd.min.js +2 -2
  27. package/lib/animation/index.umd.js +2 -2
  28. package/lib/animation/index.umd.min.js +2 -2
  29. package/lib/getLoopColors/index.umd.js +2 -2
  30. package/lib/getLoopColors/index.umd.min.js +2 -2
  31. package/lib/getWebGLContext/index.umd.js +2 -2
  32. package/lib/getWebGLContext/index.umd.min.js +2 -2
  33. package/lib/index.umd.js +104 -944
  34. package/lib/index.umd.min.js +3 -3
  35. package/lib/move/index.umd.js +2 -2
  36. package/lib/move/index.umd.min.js +2 -2
  37. package/lib/resizeObserver/index.umd.js +2 -2
  38. package/lib/resizeObserver/index.umd.min.js +2 -2
  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/scale/index.umd.js +2 -2
  44. package/lib/scale/index.umd.min.js +2 -2
  45. package/lib/throttle/index.umd.js +2 -2
  46. package/lib/throttle/index.umd.min.js +2 -2
  47. package/miniprogram/ui-canvas/index.js +100 -107
  48. package/miniprogram/ui-canvas/index.json +4 -4
  49. package/miniprogram/ui-canvas/index.wxml +4 -4
  50. package/miniprogram/ui-canvas/index.wxss +5 -5
  51. package/package/Buffer/index.ts +2 -2
  52. package/package/Canvas/index.ts +2 -2
  53. package/package/Cardinal/index.ts +2 -2
  54. package/package/Eoap/index.ts +2 -2
  55. package/package/Hermite/index.ts +2 -2
  56. package/package/Matrix4/index.ts +2 -2
  57. package/package/Mercator/index.ts +2 -2
  58. package/package/SVG/index.ts +2 -2
  59. package/package/Shader/index.ts +2 -39
  60. package/package/Texture/index.ts +2 -2
  61. package/package/TreeLayout/index.ts +2 -2
  62. package/package/animation/index.ts +2 -2
  63. package/package/getLoopColors/index.ts +2 -2
  64. package/package/index.ts +67 -76
  65. package/package/move/index.ts +2 -2
  66. package/package/resizeObserver/index.ts +2 -2
  67. package/package/rotate/index.ts +2 -2
  68. package/package/ruler/index.ts +2 -2
  69. package/package/scale/index.ts +2 -2
  70. package/package/throttle/index.ts +2 -2
  71. package/package.json +1 -1
  72. package/src/Eoap.ts +66 -66
  73. package/src/Matrix4/index.ts +84 -84
  74. package/src/Matrix4/move.ts +12 -12
  75. package/src/Matrix4/rotate.ts +15 -15
  76. package/src/Matrix4/scale.ts +11 -11
  77. package/src/Matrix4/transform.ts +64 -64
  78. package/src/Mercator.ts +27 -27
  79. package/src/SVG.ts +24 -24
  80. package/src/animation.ts +98 -98
  81. package/src/common/assemble.ts +22 -22
  82. package/src/common/canvas/arc.ts +51 -51
  83. package/src/common/canvas/config.ts +158 -158
  84. package/src/common/canvas/gradient.ts +24 -29
  85. package/src/common/canvas/index.ts +1 -12
  86. package/src/common/canvas/texts.ts +18 -18
  87. package/src/common/mergeOption.ts +6 -6
  88. package/src/common/setStyle.ts +5 -5
  89. package/src/common/svg/config.ts +190 -190
  90. package/src/common/svg/gradient.ts +53 -63
  91. package/src/common/svg/index.ts +347 -356
  92. package/src/common/svg/tool.ts +44 -44
  93. package/src/common/tree/index.ts +25 -25
  94. package/src/common/tree/toInnerTree.ts +59 -59
  95. package/src/common/tree/toPlainTree.ts +132 -132
  96. package/src/common/webgl/buffer.ts +79 -79
  97. package/src/common/webgl/getWebGLContext.ts +1 -1
  98. package/src/common/webgl/shader.ts +75 -75
  99. package/src/common/webgl/texture.ts +97 -97
  100. package/src/formatColor.ts +44 -44
  101. package/src/getLoopColors.ts +42 -42
  102. package/src/interpolation/Cardinal.ts +110 -110
  103. package/src/interpolation/Hermite.ts +65 -65
  104. package/src/layout/TreeLayout.ts +188 -188
  105. package/src/move.ts +7 -7
  106. package/src/resizeObserver.ts +37 -37
  107. package/src/rotate.ts +7 -7
  108. package/src/ruler.ts +209 -209
  109. package/src/scale.ts +6 -6
  110. package/src/throttle.ts +52 -52
  111. package/types/Buffer.d.ts +23 -23
  112. package/types/CanvasConfig.d.ts +106 -106
  113. package/types/CanvasOption.d.ts +8 -8
  114. package/types/CanvasOpts.d.ts +9 -9
  115. package/types/Cardinal.d.ts +13 -13
  116. package/types/Gradient.d.ts +14 -14
  117. package/types/Hermite.d.ts +18 -18
  118. package/types/Map.d.ts +9 -9
  119. package/types/Matrix4.d.ts +47 -47
  120. package/types/SVG.d.ts +238 -238
  121. package/types/SVGConfig.d.ts +79 -79
  122. package/types/Shader.d.ts +16 -23
  123. package/types/Texture.d.ts +16 -16
  124. package/types/Tree.d.ts +69 -69
  125. package/types/TreeConfig.d.ts +36 -36
  126. package/types/TreeLayout.d.ts +54 -54
  127. package/types/TreeOption.d.ts +48 -48
  128. package/types/animation.d.ts +9 -6
  129. package/types/getLoopColors.d.ts +5 -2
  130. package/types/getWebGLContext.d.ts +3 -0
  131. package/types/index.d.ts +149 -176
  132. package/types/move.d.ts +5 -2
  133. package/types/painterConfig.d.ts +2 -2
  134. package/types/resizeObserver.d.ts +5 -2
  135. package/types/rotate.d.ts +5 -2
  136. package/types/ruler.d.ts +10 -7
  137. package/types/scale.d.ts +5 -2
  138. package/types/throttle.d.ts +7 -4
  139. package/types/throttleOption.d.ts +21 -21
  140. package/uni-app/ui-canvas.vue +4 -11
  141. package/lib/Geometry/index.umd.d.ts +0 -3
  142. package/lib/Geometry/index.umd.js +0 -353
  143. package/lib/Geometry/index.umd.min.d.ts +0 -3
  144. package/lib/Geometry/index.umd.min.js +0 -11
  145. package/lib/OralCanvas/index.es.d.ts +0 -3
  146. package/lib/OralCanvas/index.es.js +0 -693
  147. package/lib/OralCanvas/index.es.min.d.ts +0 -3
  148. package/lib/OralCanvas/index.es.min.js +0 -11
  149. package/lib/OralWebGL/index.es.d.ts +0 -3
  150. package/lib/OralWebGL/index.es.js +0 -639
  151. package/lib/OralWebGL/index.es.min.d.ts +0 -3
  152. package/lib/OralWebGL/index.es.min.js +0 -11
  153. package/lib/WebGL/index.umd.d.ts +0 -3
  154. package/lib/WebGL/index.umd.js +0 -712
  155. package/lib/WebGL/index.umd.min.d.ts +0 -3
  156. package/lib/WebGL/index.umd.min.js +0 -11
  157. package/lib/formatColor/index.umd.d.ts +0 -3
  158. package/lib/formatColor/index.umd.js +0 -59
  159. package/lib/formatColor/index.umd.min.d.ts +0 -3
  160. package/lib/formatColor/index.umd.min.js +0 -11
  161. package/lib/viewHandler/index.umd.d.ts +0 -3
  162. package/lib/viewHandler/index.umd.js +0 -139
  163. package/lib/viewHandler/index.umd.min.d.ts +0 -3
  164. package/lib/viewHandler/index.umd.min.js +0 -11
  165. package/package/Geometry/index.ts +0 -3
  166. package/package/OralCanvas/index.ts +0 -3
  167. package/package/OralWebGL/index.ts +0 -3
  168. package/package/WebGL/index.ts +0 -3
  169. package/package/formatColor/index.ts +0 -3
  170. package/package/viewHandler/index.ts +0 -3
  171. package/src/Geometry.ts +0 -211
  172. package/src/WebGL.ts +0 -67
  173. package/src/common/geometry/prism-horizontal.ts +0 -50
  174. package/src/common/geometry/prism-vertical.ts +0 -55
  175. package/src/common/geometry/sphere-fragment.ts +0 -40
  176. package/src/common/geometry/tool/circle.ts +0 -18
  177. package/src/common/geometry/tool/rotateLine.ts +0 -49
  178. package/src/common/geometry/tool/triangles.ts +0 -24
  179. package/src/common/webgl/doDraw.ts +0 -109
  180. package/src/common/webgl/getColorFactory.ts +0 -27
  181. package/src/common/webgl/getShader.ts +0 -49
  182. package/src/common/webgl/getTexture.ts +0 -12
  183. package/src/common/webgl/index.ts +0 -228
  184. package/src/shader/fsColor.c +0 -8
  185. package/src/shader/fsColors.c +0 -8
  186. package/src/shader/fsCube.c +0 -9
  187. package/src/shader/fsImage.c +0 -9
  188. package/src/shader/vsColor.c +0 -18
  189. package/src/shader/vsColors.c +0 -14
  190. package/src/shader/vsCube.c +0 -14
  191. package/src/shader/vsImage.c +0 -14
  192. package/src/viewHandler.ts +0 -161
  193. package/types/Geometry.d.ts +0 -133
  194. package/types/GeometryOption.d.ts +0 -12
  195. package/types/GeometryResult.d.ts +0 -19
  196. package/types/Object3D.d.ts +0 -115
  197. package/types/Scene3D.d.ts +0 -7
  198. package/types/WebGL.d.ts +0 -39
  199. package/types/WebGLOption.d.ts +0 -15
  200. package/types/formatColor.d.ts +0 -3
  201. package/types/viewHandler.d.ts +0 -14
@@ -1,693 +0,0 @@
1
- /*!
2
- * VISLite JavaScript Library v0.8.0
3
- * git+https://github.com/oi-contrib/VISLite.git
4
- *
5
- * Copyright zxl20070701
6
- * Released under the MIT license
7
- * https://zxl20070701.github.io/notebook/home.html
8
- *
9
- * Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
10
- */
11
- /******************************************************************************
12
- Copyright (c) Microsoft Corporation.
13
-
14
- Permission to use, copy, modify, and/or distribute this software for any
15
- purpose with or without fee is hereby granted.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
- PERFORMANCE OF THIS SOFTWARE.
24
- ***************************************************************************** */
25
- /* global Reflect, Promise, SuppressedError, Symbol */
26
-
27
- var extendStatics = function(d, b) {
28
- extendStatics = Object.setPrototypeOf ||
29
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
30
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
31
- return extendStatics(d, b);
32
- };
33
-
34
- function __extends(d, b) {
35
- if (typeof b !== "function" && b !== null)
36
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
37
- extendStatics(d, b);
38
- function __() { this.constructor = d; }
39
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40
- }
41
-
42
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
43
- var e = new Error(message);
44
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
- };
46
-
47
- var rotate = function (cx, cy, deg, x, y) {
48
- var cos = Math.cos(deg), sin = Math.sin(deg);
49
- return [
50
- +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
51
- +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
52
- ];
53
- };
54
- function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
55
- if (rotateA < 0) {
56
- beginA += rotateA;
57
- rotateA *= -1;
58
- }
59
- var temp = [];
60
- var p;
61
- p = rotate(0, 0, beginA, r1, 0);
62
- temp[0] = p[0];
63
- temp[1] = p[1];
64
- p = rotate(0, 0, rotateA, p[0], p[1]);
65
- temp[2] = p[0];
66
- temp[3] = p[1];
67
- p = rotate(0, 0, beginA, r2, 0);
68
- temp[4] = p[0];
69
- temp[5] = p[1];
70
- p = rotate(0, 0, rotateA, p[0], p[1]);
71
- temp[6] = p[0];
72
- temp[7] = p[1];
73
- doback(beginA, beginA + rotateA, temp[0] + cx, temp[1] + cy, temp[4] + cx, temp[5] + cy, temp[2] + cx, temp[3] + cy, temp[6] + cx, temp[7] + cy, (r2 - r1) * 0.5);
74
- }
75
-
76
- var initText = function (painter, config, x, y, deg) {
77
- painter.beginPath();
78
- painter.translate(x, y);
79
- painter.rotate(deg);
80
- painter.font =
81
- config.fontStyle +
82
- " " +
83
- config.fontWeight +
84
- " " +
85
- config.fontSize +
86
- "px " +
87
- config.fontFamily;
88
- return painter;
89
- };
90
- var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
91
- if (r1 > r2) {
92
- var temp = r1;
93
- r1 = r2;
94
- r2 = temp;
95
- }
96
- beginDeg = beginDeg % (Math.PI * 2);
97
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
98
- deg = Math.PI * 2;
99
- }
100
- else {
101
- deg = deg % (Math.PI * 2);
102
- }
103
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
104
- if (r < 0)
105
- r = -r;
106
- painter.beginPath();
107
- painter.moveTo(begInnerX, begInnerY);
108
- painter.arc(cx, cy, r1, beginA, endA, false);
109
- if (config.arcEndCap == "round")
110
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
111
- else if (config.arcEndCap == "-round")
112
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
113
- else
114
- painter.lineTo(endOuterX, endOuterY);
115
- painter.arc(cx, cy, r2, endA, beginA, true);
116
- if (config.arcStartCap == "round")
117
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
118
- else if (config.arcStartCap == "-round")
119
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
120
- else
121
- painter.lineTo(begInnerX, begInnerY);
122
- });
123
- if (config.arcStartCap == "butt")
124
- painter.closePath();
125
- return painter;
126
- };
127
- var initCircle = function (painter, cx, cy, r) {
128
- painter.beginPath();
129
- painter.moveTo(cx + r, cy);
130
- painter.arc(cx, cy, r, 0, Math.PI * 2);
131
- return painter;
132
- };
133
- var initRect = function (painter, x, y, width, height) {
134
- painter.beginPath();
135
- painter.rect(x, y, width, height);
136
- return painter;
137
- };
138
-
139
- function texts (painter, contents, width, height, doback) {
140
- var lineNumber = 0, content = "";
141
- for (var i = 0; i < contents.length; i++) {
142
- if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
143
- lineNumber += 1;
144
- doback(content, (lineNumber - 0.5) * height);
145
- content = contents[i];
146
- }
147
- else if (i == contents.length - 1) {
148
- lineNumber += 1;
149
- doback(content + contents[i], (lineNumber - 0.5) * height);
150
- }
151
- else {
152
- content += contents[i];
153
- }
154
- }
155
- return lineNumber * height;
156
- }
157
-
158
- var Painter = (function () {
159
- function Painter(canvas, opts, region, isPainter, scaleSize) {
160
- if (opts === void 0) { opts = {}; }
161
- if (isPainter === void 0) { isPainter = false; }
162
- this.__region = null;
163
- this.__onlyRegion = false;
164
- this.__specialConfig = {
165
- "fontSize": 16,
166
- "fontFamily": "sans-serif",
167
- "fontWeight": 400,
168
- "fontStyle": "normal",
169
- "arcStartCap": 'butt',
170
- "arcEndCap": 'butt'
171
- };
172
- this.__initConfig = {
173
- "fillStyle": 'black',
174
- "strokeStyle": 'black',
175
- "lineWidth": 1,
176
- "textAlign": 'left',
177
- "textBaseline": 'middle',
178
- "lineDash": [],
179
- "shadowBlur": 0,
180
- "shadowColor": "black"
181
- };
182
- this.painter = canvas.getContext("2d", opts);
183
- this.__region = region;
184
- this.__isPainter = isPainter;
185
- this.painter.textBaseline = 'middle';
186
- this.painter.textAlign = 'left';
187
- }
188
- Painter.prototype.useConfig = function (key, value) {
189
- if (this.__region) {
190
- if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
191
- this.__region.useConfig(key, value);
192
- }
193
- }
194
- if (this.__isPainter && this.__onlyRegion)
195
- return this;
196
- if (key == 'lineDash') {
197
- if (this.painter.setLineDash)
198
- this.painter.setLineDash(value);
199
- }
200
- else if (key in this.__specialConfig) {
201
- if (key == 'fontSize') {
202
- value = Math.round(value);
203
- }
204
- this.__specialConfig[key] = value;
205
- }
206
- else if (key in this.__initConfig) {
207
- this.painter[key] = value;
208
- }
209
- else {
210
- throw new Error('Illegal configuration item of painter : ' + key + " !");
211
- }
212
- return this;
213
- };
214
- Painter.prototype.fillText = function (text, x, y, deg) {
215
- if (deg === void 0) { deg = 0; }
216
- if (this.__region)
217
- this.__region.fillText(text, x, y, deg);
218
- if (this.__isPainter && this.__onlyRegion)
219
- return this;
220
- this.painter.save();
221
- initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
222
- this.painter.restore();
223
- return this;
224
- };
225
- Painter.prototype.strokeText = function (text, x, y, deg) {
226
- if (deg === void 0) { deg = 0; }
227
- if (this.__region)
228
- this.__region.strokeText(text, x, y, deg);
229
- if (this.__isPainter && this.__onlyRegion)
230
- return this;
231
- this.painter.save();
232
- initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
233
- this.painter.restore();
234
- return this;
235
- };
236
- Painter.prototype.fullText = function (text, x, y, deg) {
237
- if (deg === void 0) { deg = 0; }
238
- if (this.__region)
239
- this.__region.fullText(text, x, y, deg);
240
- if (this.__isPainter && this.__onlyRegion)
241
- return this;
242
- this.painter.save();
243
- initText(this.painter, this.__specialConfig, x, y, deg);
244
- this.painter.fillText(text, 0, 0);
245
- this.painter.strokeText(text, 0, 0);
246
- this.painter.restore();
247
- return this;
248
- };
249
- Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
250
- var _this = this;
251
- if (lineHeight === void 0) { lineHeight = 1.2; }
252
- if (deg === void 0) { deg = 0; }
253
- var h = 0;
254
- if (this.__region)
255
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
256
- if (this.__isPainter && this.__onlyRegion)
257
- return h;
258
- this.painter.save();
259
- initText(this.painter, this.__specialConfig, x, y, deg);
260
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
261
- _this.painter.fillText(content, 0, top);
262
- });
263
- this.painter.restore();
264
- return height;
265
- };
266
- Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
267
- var _this = this;
268
- if (lineHeight === void 0) { lineHeight = 1.2; }
269
- if (deg === void 0) { deg = 0; }
270
- var h = 0;
271
- if (this.__region)
272
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
273
- if (this.__isPainter && this.__onlyRegion)
274
- return h;
275
- this.painter.save();
276
- initText(this.painter, this.__specialConfig, x, y, deg);
277
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
278
- _this.painter.strokeText(content, 0, top);
279
- });
280
- this.painter.restore();
281
- return height;
282
- };
283
- Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
284
- var _this = this;
285
- if (lineHeight === void 0) { lineHeight = 1.2; }
286
- if (deg === void 0) { deg = 0; }
287
- var h = 0;
288
- if (this.__region)
289
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
290
- if (this.__isPainter && this.__onlyRegion)
291
- return h;
292
- this.painter.save();
293
- initText(this.painter, this.__specialConfig, x, y, deg);
294
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
295
- _this.painter.fillText(content, 0, top);
296
- _this.painter.strokeText(content, 0, top);
297
- });
298
- this.painter.restore();
299
- return height;
300
- };
301
- Painter.prototype.beginPath = function () {
302
- if (this.__region)
303
- this.__region.beginPath();
304
- if (this.__isPainter && this.__onlyRegion)
305
- return this;
306
- this.painter.beginPath();
307
- return this;
308
- };
309
- Painter.prototype.closePath = function () {
310
- if (this.__region)
311
- this.__region.closePath();
312
- if (this.__isPainter && this.__onlyRegion)
313
- return this;
314
- this.painter.closePath();
315
- return this;
316
- };
317
- Painter.prototype.moveTo = function (x, y) {
318
- if (this.__region)
319
- this.__region.moveTo(x, y);
320
- if (this.__isPainter && this.__onlyRegion)
321
- return this;
322
- this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
323
- return this;
324
- };
325
- Painter.prototype.lineTo = function (x, y) {
326
- if (this.__region)
327
- this.__region.lineTo(x, y);
328
- if (this.__isPainter && this.__onlyRegion)
329
- return this;
330
- this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
331
- return this;
332
- };
333
- Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
334
- if (this.__region)
335
- this.__region.arc(x, y, r, beginDeg, deg);
336
- if (this.__isPainter && this.__onlyRegion)
337
- return this;
338
- this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
339
- return this;
340
- };
341
- Painter.prototype.fill = function () {
342
- if (this.__region)
343
- this.__region.fill();
344
- if (this.__isPainter && this.__onlyRegion)
345
- return this;
346
- this.painter.fill();
347
- return this;
348
- };
349
- Painter.prototype.stroke = function () {
350
- if (this.__region)
351
- this.__region.stroke();
352
- if (this.__isPainter && this.__onlyRegion)
353
- return this;
354
- this.painter.stroke();
355
- return this;
356
- };
357
- Painter.prototype.full = function () {
358
- if (this.__region)
359
- this.__region.full();
360
- if (this.__isPainter && this.__onlyRegion)
361
- return this;
362
- this.painter.fill();
363
- this.painter.stroke();
364
- return this;
365
- };
366
- Painter.prototype.save = function () {
367
- if (this.__region)
368
- this.__region.save();
369
- if (this.__isPainter && this.__onlyRegion)
370
- return this;
371
- this.painter.save();
372
- return this;
373
- };
374
- Painter.prototype.restore = function () {
375
- if (this.__region)
376
- this.__region.restore();
377
- if (this.__isPainter && this.__onlyRegion)
378
- return this;
379
- this.painter.restore();
380
- return this;
381
- };
382
- Painter.prototype.clip = function () {
383
- if (this.__region)
384
- this.__region.clip();
385
- if (this.__isPainter && this.__onlyRegion)
386
- return this;
387
- this.painter.clip();
388
- return this;
389
- };
390
- Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
391
- if (this.__region)
392
- this.__region.quadraticCurveTo(cpx, cpy, x, y);
393
- if (this.__isPainter && this.__onlyRegion)
394
- return this;
395
- this.painter.quadraticCurveTo(cpx, cpy, x, y);
396
- return this;
397
- };
398
- Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
399
- if (this.__region)
400
- this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
401
- if (this.__isPainter && this.__onlyRegion)
402
- return this;
403
- this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
404
- return this;
405
- };
406
- Painter.prototype.clearRect = function (x, y, w, h) {
407
- if (this.__region)
408
- this.__region.clearRect(x, y, w, h);
409
- if (this.__isPainter && this.__onlyRegion)
410
- return this;
411
- this.painter.clearRect(x, y, w, h);
412
- return this;
413
- };
414
- Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
415
- if (this.__region)
416
- this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
417
- if (this.__isPainter && this.__onlyRegion)
418
- return this;
419
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
420
- return this;
421
- };
422
- Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
423
- if (this.__region)
424
- this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
425
- if (this.__isPainter && this.__onlyRegion)
426
- return this;
427
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
428
- return this;
429
- };
430
- Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
431
- if (this.__region)
432
- this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
433
- if (this.__isPainter && this.__onlyRegion)
434
- return this;
435
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
436
- this.painter.fill();
437
- this.painter.stroke();
438
- return this;
439
- };
440
- Painter.prototype.fillCircle = function (cx, cy, r) {
441
- if (this.__region)
442
- this.__region.fillCircle(cx, cy, r);
443
- if (this.__isPainter && this.__onlyRegion)
444
- return this;
445
- initCircle(this.painter, cx, cy, r).fill();
446
- return this;
447
- };
448
- Painter.prototype.strokeCircle = function (cx, cy, r) {
449
- if (this.__region)
450
- this.__region.strokeCircle(cx, cy, r);
451
- if (this.__isPainter && this.__onlyRegion)
452
- return this;
453
- initCircle(this.painter, cx, cy, r).stroke();
454
- return this;
455
- };
456
- Painter.prototype.fullCircle = function (cx, cy, r) {
457
- if (this.__region)
458
- this.__region.fullCircle(cx, cy, r);
459
- if (this.__isPainter && this.__onlyRegion)
460
- return this;
461
- initCircle(this.painter, cx, cy, r);
462
- this.painter.fill();
463
- this.painter.stroke();
464
- return this;
465
- };
466
- Painter.prototype.fillRect = function (x, y, width, height) {
467
- if (this.__region)
468
- this.__region.fillRect(x, y, width, height);
469
- if (this.__isPainter && this.__onlyRegion)
470
- return this;
471
- initRect(this.painter, x, y, width, height).fill();
472
- return this;
473
- };
474
- Painter.prototype.strokeRect = function (x, y, width, height) {
475
- if (this.__region)
476
- this.__region.strokeRect(x, y, width, height);
477
- if (this.__isPainter && this.__onlyRegion)
478
- return this;
479
- initRect(this.painter, x, y, width, height).stroke();
480
- return this;
481
- };
482
- Painter.prototype.fullRect = function (x, y, width, height) {
483
- if (this.__region)
484
- this.__region.fullRect(x, y, width, height);
485
- if (this.__isPainter && this.__onlyRegion)
486
- return this;
487
- initRect(this.painter, x, y, width, height);
488
- this.painter.fill();
489
- this.painter.stroke();
490
- return this;
491
- };
492
- Painter.prototype.draw = function () { };
493
- Painter.prototype.drawImage = function (img, x, y, w, h, isUniapp) {
494
- var _this = this;
495
- if (isUniapp === void 0) { isUniapp = false; }
496
- return new Promise(function (resolve) {
497
- if (_this.__region) {
498
- _this.__region.fillRect(x, y, w, h);
499
- resolve({});
500
- }
501
- if (_this.__isPainter && _this.__onlyRegion)
502
- return _this;
503
- if (typeof img == 'string' && !isUniapp) {
504
- var imgInstance_1 = new Image();
505
- imgInstance_1.onload = function () {
506
- _this.painter.drawImage(imgInstance_1, x, y, w, h);
507
- resolve({});
508
- };
509
- imgInstance_1.src = img;
510
- }
511
- else {
512
- _this.painter.drawImage(img, x, y, w, h);
513
- resolve({});
514
- }
515
- });
516
- };
517
- return Painter;
518
- }());
519
-
520
- function assemble (begin, end, step, count) {
521
- var val = [];
522
- for (var index = 0; index < count; index++)
523
- val[index] = begin;
524
- return function () {
525
- for (var i = 0; i < count; i++) {
526
- if (val[i] + step < end) {
527
- val[i] = +(val[i] + step).toFixed(7);
528
- break;
529
- }
530
- else if (i < count - 1) {
531
- val[i] = begin;
532
- }
533
- }
534
- return val;
535
- };
536
- }
537
-
538
- var linearGradient = function (painter, x0, y0, x1, y1) {
539
- var gradient = painter.createLinearGradient(x0, y0, x1, y1);
540
- var enhanceGradient = {
541
- "value": function () {
542
- return gradient;
543
- },
544
- "setColor": function (stop, color) {
545
- gradient.addColorStop(stop, color);
546
- return enhanceGradient;
547
- }
548
- };
549
- return enhanceGradient;
550
- };
551
- var radialGradient = function (painter, cx, cy, r) {
552
- var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
553
- var enhanceGradient = {
554
- "value": function () {
555
- return gradient;
556
- },
557
- "setColor": function (stop, color) {
558
- gradient.addColorStop(stop, color);
559
- return enhanceGradient;
560
- }
561
- };
562
- return enhanceGradient;
563
- };
564
-
565
- var oldAttrName = {
566
- "font-size": "fontSize",
567
- "font-family": "fontFamily",
568
- "font-weight": "fontWeight",
569
- "font-style": "fontStyle",
570
- "arc-start-cap": "arcStartCap",
571
- "arc-end-cap": "arcEndCap",
572
- };
573
- var Canvas = (function (_super) {
574
- __extends(Canvas, _super);
575
- function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
576
- if (opts === void 0) { opts = {}; }
577
- if (scaleSize === void 0) { scaleSize = 1; }
578
- var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
579
- willReadFrequently: true,
580
- }) : undefined, true, scaleSize) || this;
581
- _this.name = "Canvas";
582
- _this.__regionList = {};
583
- _this.__regionAssemble = assemble(0, 255, 10, 3);
584
- _this.__scaleSize = scaleSize;
585
- _this.setRegion("");
586
- return _this;
587
- }
588
- Canvas.prototype.config = function (configs) {
589
- for (var key in configs) {
590
- var _key = oldAttrName[key] || key;
591
- this.useConfig(_key, configs[key]);
592
- }
593
- return this;
594
- };
595
- Canvas.prototype.onlyRegion = function (flag) {
596
- this.__onlyRegion = flag;
597
- return this;
598
- };
599
- Canvas.prototype.setRegion = function (regionName) {
600
- if (this.__region) {
601
- if (regionName) {
602
- if (this.__regionList[regionName] == void 0) {
603
- var tempColor = this.__regionAssemble();
604
- this.__regionList[regionName] =
605
- "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
606
- }
607
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
608
- this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
609
- }
610
- else {
611
- this.__region.useConfig("fillStyle", "#000000") &&
612
- this.__region.useConfig("strokeStyle", "#000000");
613
- }
614
- }
615
- return this;
616
- };
617
- Canvas.prototype.getRegion = function (x, y) {
618
- var _this = this;
619
- return new Promise(function (resolve) {
620
- var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
621
- data: [0, 0, 0, 0]
622
- };
623
- var currentRGBA = imgData.data;
624
- var doit = function () {
625
- if (_this.__region) {
626
- for (var key in _this.__regionList) {
627
- if ("rgb(" +
628
- currentRGBA[0] +
629
- "," +
630
- currentRGBA[1] +
631
- "," +
632
- currentRGBA[2] +
633
- ")" ==
634
- _this.__regionList[key]) {
635
- resolve(key);
636
- break;
637
- }
638
- }
639
- }
640
- resolve("");
641
- };
642
- if (currentRGBA) {
643
- doit();
644
- }
645
- else {
646
- imgData.then(function (data) {
647
- currentRGBA = data;
648
- doit();
649
- });
650
- }
651
- });
652
- };
653
- Canvas.prototype.textWidth = function (text) {
654
- this.painter.save();
655
- initText(this.painter, this.__specialConfig, 0, 0, 0);
656
- var width = this.painter.measureText(text + "").width;
657
- this.painter.restore();
658
- return width;
659
- };
660
- Canvas.prototype.getContext = function (isRegion) {
661
- if (isRegion === void 0) { isRegion = false; }
662
- return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
663
- };
664
- Canvas.prototype.getInfo = function () {
665
- return {
666
- width: this.painter.canvas.width / this.__scaleSize,
667
- height: this.painter.canvas.height / this.__scaleSize
668
- };
669
- };
670
- Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
671
- return linearGradient(this.painter, x0, y0, x1, y1);
672
- };
673
- Canvas.prototype.createRadialGradient = function (cx, cy, r) {
674
- return radialGradient(this.painter, cx, cy, r);
675
- };
676
- Canvas.prototype.getColor = function (x, y) {
677
- x *= this.__scaleSize;
678
- y *= this.__scaleSize;
679
- var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
680
- return ("rgba(" +
681
- currentRGBA[0] +
682
- "," +
683
- currentRGBA[1] +
684
- "," +
685
- currentRGBA[2] +
686
- "," +
687
- currentRGBA[3] +
688
- ")");
689
- };
690
- return Canvas;
691
- }(Painter));
692
-
693
- export { Canvas as default };
@@ -1,3 +0,0 @@
1
- import { OralCanvas } from "../../types/index"
2
-
3
- export default OralCanvas