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