vislite 0.5.0 → 0.5.2-alpha.1

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