vislite 1.0.0-next.2 → 1.0.0-next.4

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