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