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