vislite 1.12.0-alpha.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +402 -401
  3. package/LICENSE +20 -20
  4. package/README-en.md +245 -245
  5. package/README.md +245 -245
  6. package/bin/formatArgv.js +30 -30
  7. package/bin/help.js +17 -17
  8. package/bin/run +21 -21
  9. package/bin/skills.js +26 -26
  10. package/lib/BarLayout/index.es.js +348 -348
  11. package/lib/Buffer/index.es.js +34 -34
  12. package/lib/Canvas/index.es.js +804 -789
  13. package/lib/Canvas/index.es.min.js +1 -1
  14. package/lib/Cardinal/index.es.js +89 -89
  15. package/lib/Eoap/index.es.js +32 -32
  16. package/lib/Hermite/index.es.js +34 -34
  17. package/lib/MapCoordinate/index.es.js +199 -199
  18. package/lib/Matrix4/index.es.js +123 -123
  19. package/lib/Mercator/index.es.js +18 -18
  20. package/lib/PieLayout/index.es.js +115 -115
  21. package/lib/RawCanvas/index.es.js +736 -721
  22. package/lib/RawCanvas/index.es.min.js +1 -1
  23. package/lib/SVG/index.es.js +626 -626
  24. package/lib/Shader/index.es.js +34 -34
  25. package/lib/Texture/index.es.js +52 -52
  26. package/lib/TreeLayout/index.es.js +301 -301
  27. package/lib/animation/index.es.js +2 -2
  28. package/lib/assemble/index.es.js +19 -19
  29. package/lib/getLoopColors/index.es.js +34 -34
  30. package/lib/getWebGLContext/index.es.js +61 -61
  31. package/lib/index.umd.js +2797 -2782
  32. package/lib/index.umd.min.js +2 -2
  33. package/lib/initOption/index.es.js +5 -5
  34. package/lib/mergeOption/index.es.js +34 -34
  35. package/lib/move/index.es.js +6 -6
  36. package/lib/rotate/index.es.js +6 -6
  37. package/lib/ruler/index.es.js +136 -136
  38. package/lib/scale/index.es.js +5 -5
  39. package/minialipay/ui-canvas/drawImage.js +35 -35
  40. package/minialipay/ui-canvas/index.acss +4 -4
  41. package/minialipay/ui-canvas/index.axml +3 -3
  42. package/minialipay/ui-canvas/index.d.ts +1 -1
  43. package/minialipay/ui-canvas/index.js +100 -100
  44. package/minialipay/ui-canvas/index.json +6 -6
  45. package/miniprogram/ui-canvas/drawImage.js +35 -35
  46. package/miniprogram/ui-canvas/index.js +125 -125
  47. package/miniprogram/ui-canvas/index.json +4 -4
  48. package/miniprogram/ui-canvas/index.wxml +4 -4
  49. package/miniprogram/ui-canvas/index.wxss +5 -5
  50. package/package/BarLayout/index.ts +2 -2
  51. package/package/Buffer/index.ts +2 -2
  52. package/package/Canvas/index.ts +2 -2
  53. package/package/Cardinal/index.ts +2 -2
  54. package/package/Eoap/index.ts +2 -2
  55. package/package/Hermite/index.ts +2 -2
  56. package/package/MapCoordinate/index.ts +2 -2
  57. package/package/Matrix4/index.ts +2 -2
  58. package/package/Mercator/index.ts +2 -2
  59. package/package/PieLayout/index.ts +2 -2
  60. package/package/RawCanvas/index.ts +2 -2
  61. package/package/SVG/index.ts +2 -2
  62. package/package/Shader/index.ts +2 -2
  63. package/package/Texture/index.ts +2 -2
  64. package/package/TreeLayout/index.ts +2 -2
  65. package/package/animation/index.ts +5 -5
  66. package/package/assemble/index.ts +2 -2
  67. package/package/getLoopColors/index.ts +2 -2
  68. package/package/getWebGLContext/index.ts +40 -40
  69. package/package/index.ts +84 -84
  70. package/package/initOption/index.ts +2 -2
  71. package/package/mergeOption/index.ts +2 -2
  72. package/package/move/index.ts +2 -2
  73. package/package/rotate/index.ts +2 -2
  74. package/package/ruler/index.ts +2 -2
  75. package/package/scale/index.ts +2 -2
  76. package/package/throttle/index.ts +2 -2
  77. package/package.json +79 -79
  78. package/skills/vislite-lib/BarLayout.md +117 -117
  79. package/skills/vislite-lib/Canvas.md +183 -183
  80. package/skills/vislite-lib/Interpolation.md +129 -129
  81. package/skills/vislite-lib/Matrix.md +174 -174
  82. package/skills/vislite-lib/PieLayout.md +131 -131
  83. package/skills/vislite-lib/Projections.md +158 -158
  84. package/skills/vislite-lib/SKILL.md +179 -179
  85. package/skills/vislite-lib/SVG.md +137 -137
  86. package/skills/vislite-lib/TreeLayout.md +176 -176
  87. package/skills/vislite-lib/Utilities.md +261 -261
  88. package/skills/vislite-lib/WebGL.md +106 -106
  89. package/skills/vislite-lib/minialipay/ui-canvas.md +95 -95
  90. package/skills/vislite-lib/miniprogram/ui-canvas.md +98 -98
  91. package/skills/vislite-lib/uniapp/ui-canvas.md +113 -113
  92. package/src/Canvas.ts +89 -89
  93. package/src/Eoap.ts +66 -66
  94. package/src/Matrix4/index.ts +84 -84
  95. package/src/Matrix4/move.ts +12 -12
  96. package/src/Matrix4/rotate.ts +15 -15
  97. package/src/Matrix4/scale.ts +11 -11
  98. package/src/Matrix4/transform.ts +64 -64
  99. package/src/Mercator.ts +27 -27
  100. package/src/SVG.ts +86 -86
  101. package/src/common/assemble.ts +30 -30
  102. package/src/common/canvas/arc.ts +51 -51
  103. package/src/common/canvas/config.ts +176 -176
  104. package/src/common/canvas/default.ts +64 -64
  105. package/src/common/canvas/gradient.ts +31 -31
  106. package/src/common/canvas/index.ts +189 -189
  107. package/src/common/canvas/painter.ts +475 -454
  108. package/src/common/canvas/texts.ts +18 -18
  109. package/src/common/map/getBoundary.ts +15 -15
  110. package/src/common/map/tool.ts +29 -29
  111. package/src/common/option.ts +31 -31
  112. package/src/common/setStyle.ts +5 -5
  113. package/src/common/svg/config.ts +213 -213
  114. package/src/common/svg/default.ts +29 -29
  115. package/src/common/svg/gradient.ts +53 -53
  116. package/src/common/svg/index.ts +420 -420
  117. package/src/common/svg/tool.ts +51 -51
  118. package/src/common/tree/index.ts +25 -25
  119. package/src/common/tree/toInnerTree.ts +61 -61
  120. package/src/common/tree/toPlainTree.ts +135 -135
  121. package/src/common/type.ts +26 -26
  122. package/src/common/webgl/buffer.ts +79 -79
  123. package/src/common/webgl/getWebGLContext.ts +45 -45
  124. package/src/common/webgl/shader.ts +75 -75
  125. package/src/common/webgl/texture.ts +98 -98
  126. package/src/coordinate/MapCoordinate.ts +80 -80
  127. package/src/getLoopColors.ts +42 -42
  128. package/src/interpolation/Cardinal.ts +110 -110
  129. package/src/interpolation/Hermite.ts +65 -65
  130. package/src/layout/BarLayout.ts +249 -249
  131. package/src/layout/PieLayout.ts +146 -146
  132. package/src/layout/TreeLayout.ts +200 -200
  133. package/src/move.ts +7 -7
  134. package/src/rotate.ts +7 -7
  135. package/src/ruler.ts +209 -209
  136. package/src/scale.ts +6 -6
  137. package/types/Bar.d.ts +91 -91
  138. package/types/BarConfig.d.ts +4 -4
  139. package/types/BarLayout.d.ts +48 -48
  140. package/types/BarOption.d.ts +31 -31
  141. package/types/Buffer.d.ts +30 -30
  142. package/types/Canvas.d.ts +379 -379
  143. package/types/CanvasConfig.d.ts +61 -61
  144. package/types/CanvasOption.d.ts +13 -13
  145. package/types/CanvasOpts.d.ts +9 -9
  146. package/types/Cardinal.d.ts +20 -20
  147. package/types/Gradient.d.ts +20 -20
  148. package/types/Hermite.d.ts +25 -25
  149. package/types/Map.d.ts +9 -9
  150. package/types/MapConfig.d.ts +27 -27
  151. package/types/MapCoordinate.d.ts +22 -22
  152. package/types/Matrix4.d.ts +79 -79
  153. package/types/Pie.d.ts +73 -73
  154. package/types/PieConfig.d.ts +26 -26
  155. package/types/PieLayout.d.ts +40 -40
  156. package/types/PieOption.d.ts +21 -21
  157. package/types/SVG.d.ts +282 -282
  158. package/types/SVGConfig.d.ts +54 -54
  159. package/types/Shader.d.ts +22 -22
  160. package/types/Texture.d.ts +22 -22
  161. package/types/Tree.d.ts +74 -74
  162. package/types/TreeConfig.d.ts +52 -52
  163. package/types/TreeLayout.d.ts +71 -71
  164. package/types/TreeOption.d.ts +48 -48
  165. package/types/animation.d.ts +26 -26
  166. package/types/assemble.d.ts +14 -14
  167. package/types/getLoopColors.d.ts +13 -13
  168. package/types/getWebGLContext.d.ts +7 -7
  169. package/types/index.d.ts +220 -221
  170. package/types/module.d.ts +110 -110
  171. package/types/move.d.ts +15 -15
  172. package/types/option.d.ts +12 -12
  173. package/types/painterConfig.d.ts +14 -14
  174. package/types/rotate.d.ts +15 -15
  175. package/types/ruler.d.ts +24 -24
  176. package/types/scale.d.ts +15 -15
  177. package/types/throttle.d.ts +6 -6
  178. package/types/ui-canvas.d.ts +4 -4
  179. package/types/uni-canvas.d.ts +3 -3
  180. package/uni-app/drawImage.js +19 -19
  181. package/uni-app/ui-canvas.vue +295 -295
@@ -31,813 +31,828 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
31
31
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
32
  };
33
33
 
34
- var rotate = function (cx, cy, deg, x, y) {
35
- var cos = Math.cos(deg), sin = Math.sin(deg);
36
- return [
37
- +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
38
- +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
39
- ];
40
- };
41
- function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
42
- if (rotateA < 0) {
43
- beginA += rotateA;
44
- rotateA *= -1;
45
- }
46
- var temp = [];
47
- var p;
48
- p = rotate(0, 0, beginA, r1, 0);
49
- temp[0] = p[0];
50
- temp[1] = p[1];
51
- p = rotate(0, 0, rotateA, p[0], p[1]);
52
- temp[2] = p[0];
53
- temp[3] = p[1];
54
- p = rotate(0, 0, beginA, r2, 0);
55
- temp[4] = p[0];
56
- temp[5] = p[1];
57
- p = rotate(0, 0, rotateA, p[0], p[1]);
58
- temp[6] = p[0];
59
- temp[7] = p[1];
60
- 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);
34
+ var rotate = function (cx, cy, deg, x, y) {
35
+ var cos = Math.cos(deg), sin = Math.sin(deg);
36
+ return [
37
+ +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
38
+ +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
39
+ ];
40
+ };
41
+ function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
42
+ if (rotateA < 0) {
43
+ beginA += rotateA;
44
+ rotateA *= -1;
45
+ }
46
+ var temp = [];
47
+ var p;
48
+ p = rotate(0, 0, beginA, r1, 0);
49
+ temp[0] = p[0];
50
+ temp[1] = p[1];
51
+ p = rotate(0, 0, rotateA, p[0], p[1]);
52
+ temp[2] = p[0];
53
+ temp[3] = p[1];
54
+ p = rotate(0, 0, beginA, r2, 0);
55
+ temp[4] = p[0];
56
+ temp[5] = p[1];
57
+ p = rotate(0, 0, rotateA, p[0], p[1]);
58
+ temp[6] = p[0];
59
+ temp[7] = p[1];
60
+ 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);
61
61
  }
62
62
 
63
- var initText = function (painter, config, x, y, deg) {
64
- painter.beginPath();
65
- painter.translate(x, y);
66
- painter.rotate(deg);
67
- painter.font =
68
- config.fontStyle +
69
- " " +
70
- config.fontWeight +
71
- " " +
72
- config.fontSize +
73
- "px " +
74
- config.fontFamily;
75
- return painter;
76
- };
77
- var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
78
- if (r1 > r2) {
79
- var temp = r1;
80
- r1 = r2;
81
- r2 = temp;
82
- }
83
- beginDeg = beginDeg % (Math.PI * 2);
84
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
85
- deg = Math.PI * 2;
86
- }
87
- else {
88
- deg = deg % (Math.PI * 2);
89
- }
90
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
91
- if (r < 0)
92
- r = -r;
93
- painter.beginPath();
94
- painter.moveTo(begInnerX, begInnerY);
95
- painter.arc(cx, cy, r1, beginA, endA, false);
96
- if (config.arcEndCap == "round")
97
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
98
- else if (config.arcEndCap == "-round")
99
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
100
- else
101
- painter.lineTo(endOuterX, endOuterY);
102
- painter.arc(cx, cy, r2, endA, beginA, true);
103
- if (config.arcStartCap == "round")
104
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
105
- else if (config.arcStartCap == "-round")
106
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
107
- else
108
- painter.lineTo(begInnerX, begInnerY);
109
- });
110
- if (config.arcStartCap == "butt")
111
- painter.closePath();
112
- return painter;
113
- };
114
- var initCircle = function (painter, cx, cy, r) {
115
- painter.beginPath();
116
- painter.moveTo(cx + r, cy);
117
- painter.arc(cx, cy, r, 0, Math.PI * 2);
118
- return painter;
119
- };
120
- var initRect = function (painter, config, x, y, width, height) {
121
- painter.beginPath();
122
- var rectRadius = [];
123
- if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
124
- for (var index = 0; index < 4; index++) {
125
- rectRadius.push.apply(rectRadius, config.rectRadius);
126
- }
127
- }
128
- if (rectRadius.length >= 4) {
129
- painter.arc(x + rectRadius[0], y + rectRadius[0], rectRadius[0], Math.PI, Math.PI * 1.5);
130
- painter.arc(x + width - rectRadius[1], y + rectRadius[1], rectRadius[1], 1.5 * Math.PI, 0);
131
- painter.arc(x + width - rectRadius[2], y + height - rectRadius[2], rectRadius[2], 0, Math.PI * 0.5);
132
- painter.arc(x + rectRadius[3], y + height - rectRadius[3], rectRadius[3], 0.5 * Math.PI, Math.PI);
133
- painter.closePath();
134
- }
135
- else {
136
- painter.rect(x, y, width, height);
137
- }
138
- return painter;
63
+ var initText = function (painter, config, x, y, deg) {
64
+ painter.beginPath();
65
+ painter.translate(x, y);
66
+ painter.rotate(deg);
67
+ painter.font =
68
+ config.fontStyle +
69
+ " " +
70
+ config.fontWeight +
71
+ " " +
72
+ config.fontSize +
73
+ "px " +
74
+ config.fontFamily;
75
+ return painter;
76
+ };
77
+ var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
78
+ if (r1 > r2) {
79
+ var temp = r1;
80
+ r1 = r2;
81
+ r2 = temp;
82
+ }
83
+ beginDeg = beginDeg % (Math.PI * 2);
84
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
85
+ deg = Math.PI * 2;
86
+ }
87
+ else {
88
+ deg = deg % (Math.PI * 2);
89
+ }
90
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
91
+ if (r < 0)
92
+ r = -r;
93
+ painter.beginPath();
94
+ painter.moveTo(begInnerX, begInnerY);
95
+ painter.arc(cx, cy, r1, beginA, endA, false);
96
+ if (config.arcEndCap == "round")
97
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
98
+ else if (config.arcEndCap == "-round")
99
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
100
+ else
101
+ painter.lineTo(endOuterX, endOuterY);
102
+ painter.arc(cx, cy, r2, endA, beginA, true);
103
+ if (config.arcStartCap == "round")
104
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
105
+ else if (config.arcStartCap == "-round")
106
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
107
+ else
108
+ painter.lineTo(begInnerX, begInnerY);
109
+ });
110
+ if (config.arcStartCap == "butt")
111
+ painter.closePath();
112
+ return painter;
113
+ };
114
+ var initCircle = function (painter, cx, cy, r) {
115
+ painter.beginPath();
116
+ painter.moveTo(cx + r, cy);
117
+ painter.arc(cx, cy, r, 0, Math.PI * 2);
118
+ return painter;
119
+ };
120
+ var initRect = function (painter, config, x, y, width, height) {
121
+ painter.beginPath();
122
+ var rectRadius = [];
123
+ if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
124
+ for (var index = 0; index < 4; index++) {
125
+ rectRadius.push.apply(rectRadius, config.rectRadius);
126
+ }
127
+ }
128
+ if (rectRadius.length >= 4) {
129
+ painter.arc(x + rectRadius[0], y + rectRadius[0], rectRadius[0], Math.PI, Math.PI * 1.5);
130
+ painter.arc(x + width - rectRadius[1], y + rectRadius[1], rectRadius[1], 1.5 * Math.PI, 0);
131
+ painter.arc(x + width - rectRadius[2], y + height - rectRadius[2], rectRadius[2], 0, Math.PI * 0.5);
132
+ painter.arc(x + rectRadius[3], y + height - rectRadius[3], rectRadius[3], 0.5 * Math.PI, Math.PI);
133
+ painter.closePath();
134
+ }
135
+ else {
136
+ painter.rect(x, y, width, height);
137
+ }
138
+ return painter;
139
139
  };
140
140
 
141
- function texts (painter, contents, width, height, doback) {
142
- var lineNumber = 0, content = "";
143
- for (var i = 0; i < contents.length; i++) {
144
- if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
145
- lineNumber += 1;
146
- doback(content, (lineNumber - 0.5) * height);
147
- content = contents[i];
148
- }
149
- else if (i == contents.length - 1) {
150
- lineNumber += 1;
151
- doback(content + contents[i], (lineNumber - 0.5) * height);
152
- }
153
- else {
154
- content += contents[i];
155
- }
156
- }
157
- return lineNumber * height;
141
+ function texts (painter, contents, width, height, doback) {
142
+ var lineNumber = 0, content = "";
143
+ for (var i = 0; i < contents.length; i++) {
144
+ if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
145
+ lineNumber += 1;
146
+ doback(content, (lineNumber - 0.5) * height);
147
+ content = contents[i];
148
+ }
149
+ else if (i == contents.length - 1) {
150
+ lineNumber += 1;
151
+ doback(content + contents[i], (lineNumber - 0.5) * height);
152
+ }
153
+ else {
154
+ content += contents[i];
155
+ }
156
+ }
157
+ return lineNumber * height;
158
158
  }
159
159
 
160
- function defaultFactory (type) {
161
- var special = {
162
- "fontSize": 16,
163
- "fontFamily": "sans-serif",
164
- "fontWeight": 400,
165
- "fontStyle": "normal",
166
- "arcStartCap": 'butt',
167
- "arcEndCap": 'butt',
168
- "rectRadius": []
169
- };
170
- var init = {
171
- "fillStyle": 'black',
172
- "strokeStyle": 'black',
173
- "lineWidth": 1,
174
- "lineCap": "butt",
175
- "lineJoin": "miter",
176
- "lineDash": [],
177
- "textAlign": 'left',
178
- "textBaseline": 'middle',
179
- "shadowBlur": 0,
180
- "shadowColor": "black"
181
- };
182
- if (type == 'special')
183
- return special;
184
- else if (type == 'init')
185
- return init;
186
- else
187
- return __assign(__assign({}, special), init);
160
+ function defaultFactory (type) {
161
+ var special = {
162
+ "fontSize": 16,
163
+ "fontFamily": "sans-serif",
164
+ "fontWeight": 400,
165
+ "fontStyle": "normal",
166
+ "arcStartCap": 'butt',
167
+ "arcEndCap": 'butt',
168
+ "rectRadius": []
169
+ };
170
+ var init = {
171
+ "fillStyle": 'black',
172
+ "strokeStyle": 'black',
173
+ "lineWidth": 1,
174
+ "lineCap": "butt",
175
+ "lineJoin": "miter",
176
+ "lineDash": [],
177
+ "textAlign": 'left',
178
+ "textBaseline": 'middle',
179
+ "shadowBlur": 0,
180
+ "shadowColor": "black"
181
+ };
182
+ if (type == 'special')
183
+ return special;
184
+ else if (type == 'init')
185
+ return init;
186
+ else
187
+ return __assign(__assign({}, special), init);
188
188
  }
189
189
 
190
- var Painter = (function () {
191
- function Painter(canvas, opts, region, isPainter, scaleSize) {
192
- if (opts === void 0) { opts = {}; }
193
- if (isPainter === void 0) { isPainter = false; }
194
- this.__region = null;
195
- this.__onlyRegion = false;
196
- this.__onlyView = false;
197
- this.__specialConfig = defaultFactory("special");
198
- this.__initConfig = defaultFactory("init");
199
- this.painter = canvas.getContext("2d", opts);
200
- this.__region = region;
201
- this.__isPainter = isPainter;
202
- this.painter.textBaseline = 'middle';
203
- this.painter.textAlign = 'left';
204
- this.painter.shadowColor = 'black';
205
- }
206
- Painter.prototype.useConfig = function (key, value) {
207
- if (this.__region && !this.__onlyView) {
208
- if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
209
- this.__region.useConfig(key, value);
210
- }
211
- }
212
- if (this.__isPainter && this.__onlyRegion)
213
- return this;
214
- if (key == 'lineDash') {
215
- if (this.painter.setLineDash)
216
- this.painter.setLineDash(value);
217
- }
218
- else if (key in this.__specialConfig) {
219
- if (key == 'fontSize') {
220
- value = Math.round(value);
221
- }
222
- this.__specialConfig[key] = value;
223
- }
224
- else if (key in this.__initConfig) {
225
- this.painter[key] = value;
226
- }
227
- else {
228
- throw new Error('Illegal configuration item of painter : ' + key + " !");
229
- }
230
- return this;
231
- };
232
- Painter.prototype.fillText = function (text, x, y, deg) {
233
- if (deg === void 0) { deg = 0; }
234
- if (this.__region && !this.__onlyView)
235
- this.__region.fillText(text, x, y, deg);
236
- if (this.__isPainter && this.__onlyRegion)
237
- return this;
238
- this.painter.save();
239
- initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
240
- this.painter.restore();
241
- return this;
242
- };
243
- Painter.prototype.strokeText = function (text, x, y, deg) {
244
- if (deg === void 0) { deg = 0; }
245
- if (this.__region && !this.__onlyView)
246
- this.__region.strokeText(text, x, y, deg);
247
- if (this.__isPainter && this.__onlyRegion)
248
- return this;
249
- this.painter.save();
250
- initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
251
- this.painter.restore();
252
- return this;
253
- };
254
- Painter.prototype.fullText = function (text, x, y, deg) {
255
- if (deg === void 0) { deg = 0; }
256
- if (this.__region && !this.__onlyView)
257
- this.__region.fullText(text, x, y, deg);
258
- if (this.__isPainter && this.__onlyRegion)
259
- return this;
260
- this.painter.save();
261
- initText(this.painter, this.__specialConfig, x, y, deg);
262
- this.painter.fillText(text, 0, 0);
263
- this.painter.strokeText(text, 0, 0);
264
- this.painter.restore();
265
- return this;
266
- };
267
- Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
268
- var _this = this;
269
- if (lineHeight === void 0) { lineHeight = 1.2; }
270
- if (deg === void 0) { deg = 0; }
271
- var h = 0;
272
- if (this.__region && !this.__onlyView)
273
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
274
- if (this.__isPainter && this.__onlyRegion)
275
- return h;
276
- this.painter.save();
277
- initText(this.painter, this.__specialConfig, x, y, deg);
278
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
279
- _this.painter.fillText(content, 0, top);
280
- });
281
- this.painter.restore();
282
- return height;
283
- };
284
- Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
285
- var _this = this;
286
- if (lineHeight === void 0) { lineHeight = 1.2; }
287
- if (deg === void 0) { deg = 0; }
288
- var h = 0;
289
- if (this.__region && !this.__onlyView)
290
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
291
- if (this.__isPainter && this.__onlyRegion)
292
- return h;
293
- this.painter.save();
294
- initText(this.painter, this.__specialConfig, x, y, deg);
295
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
296
- _this.painter.strokeText(content, 0, top);
297
- });
298
- this.painter.restore();
299
- return height;
300
- };
301
- Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
302
- var _this = this;
303
- if (lineHeight === void 0) { lineHeight = 1.2; }
304
- if (deg === void 0) { deg = 0; }
305
- var h = 0;
306
- if (this.__region && !this.__onlyView)
307
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
308
- if (this.__isPainter && this.__onlyRegion)
309
- return h;
310
- this.painter.save();
311
- initText(this.painter, this.__specialConfig, x, y, deg);
312
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
313
- _this.painter.fillText(content, 0, top);
314
- _this.painter.strokeText(content, 0, top);
315
- });
316
- this.painter.restore();
317
- return height;
318
- };
319
- Painter.prototype.beginPath = function () {
320
- if (this.__region && !this.__onlyView)
321
- this.__region.beginPath();
322
- if (this.__isPainter && this.__onlyRegion)
323
- return this;
324
- this.painter.beginPath();
325
- return this;
326
- };
327
- Painter.prototype.closePath = function () {
328
- if (this.__region && !this.__onlyView)
329
- this.__region.closePath();
330
- if (this.__isPainter && this.__onlyRegion)
331
- return this;
332
- this.painter.closePath();
333
- return this;
334
- };
335
- Painter.prototype.moveTo = function (x, y) {
336
- if (this.__region && !this.__onlyView)
337
- this.__region.moveTo(x, y);
338
- if (this.__isPainter && this.__onlyRegion)
339
- return this;
340
- this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
341
- return this;
342
- };
343
- Painter.prototype.lineTo = function (x, y) {
344
- if (this.__region && !this.__onlyView)
345
- this.__region.lineTo(x, y);
346
- if (this.__isPainter && this.__onlyRegion)
347
- return this;
348
- this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
349
- return this;
350
- };
351
- Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
352
- if (this.__region && !this.__onlyView)
353
- this.__region.arc(x, y, r, beginDeg, deg);
354
- if (this.__isPainter && this.__onlyRegion)
355
- return this;
356
- this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
357
- return this;
358
- };
359
- Painter.prototype.fill = function () {
360
- if (this.__region && !this.__onlyView)
361
- this.__region.fill();
362
- if (this.__isPainter && this.__onlyRegion)
363
- return this;
364
- this.painter.fill();
365
- return this;
366
- };
367
- Painter.prototype.stroke = function () {
368
- if (this.__region && !this.__onlyView)
369
- this.__region.stroke();
370
- if (this.__isPainter && this.__onlyRegion)
371
- return this;
372
- this.painter.stroke();
373
- return this;
374
- };
375
- Painter.prototype.full = function () {
376
- if (this.__region && !this.__onlyView)
377
- this.__region.full();
378
- if (this.__isPainter && this.__onlyRegion)
379
- return this;
380
- this.painter.fill();
381
- this.painter.stroke();
382
- return this;
383
- };
384
- Painter.prototype.save = function () {
385
- if (this.__region && !this.__onlyView)
386
- this.__region.save();
387
- if (this.__isPainter && this.__onlyRegion)
388
- return this;
389
- this.painter.save();
390
- return this;
391
- };
392
- Painter.prototype.restore = function () {
393
- if (this.__region && !this.__onlyView)
394
- this.__region.restore();
395
- if (this.__isPainter && this.__onlyRegion)
396
- return this;
397
- this.painter.restore();
398
- return this;
399
- };
400
- Painter.prototype.clip = function () {
401
- if (this.__region && !this.__onlyView)
402
- this.__region.clip();
403
- if (this.__isPainter && this.__onlyRegion)
404
- return this;
405
- this.painter.clip();
406
- return this;
407
- };
408
- Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
409
- if (this.__region && !this.__onlyView)
410
- this.__region.quadraticCurveTo(cpx, cpy, x, y);
411
- if (this.__isPainter && this.__onlyRegion)
412
- return this;
413
- this.painter.quadraticCurveTo(cpx, cpy, x, y);
414
- return this;
415
- };
416
- Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
417
- if (this.__region && !this.__onlyView)
418
- this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
419
- if (this.__isPainter && this.__onlyRegion)
420
- return this;
421
- this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
422
- return this;
423
- };
424
- Painter.prototype.clearRect = function (x, y, w, h) {
425
- if (this.__region && !this.__onlyView)
426
- this.__region.clearRect(x, y, w, h);
427
- if (this.__isPainter && this.__onlyRegion)
428
- return this;
429
- this.painter.clearRect(x, y, w, h);
430
- return this;
431
- };
432
- Painter.prototype.clearCircle = function (cx, cy, r) {
433
- if (this.__region && !this.__onlyView)
434
- this.__region.clearCircle(cx, cy, r);
435
- if (this.__isPainter && this.__onlyRegion)
436
- return this;
437
- this.painter.beginPath();
438
- this.painter.globalCompositeOperation = "destination-out";
439
- this.painter.arc(cx, cy, r, 0, Math.PI * 2);
440
- this.painter.fill();
441
- this.painter.globalCompositeOperation = "source-over";
442
- this.painter.closePath();
443
- return this;
444
- };
445
- Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
446
- if (this.__region && !this.__onlyView)
447
- this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
448
- if (this.__isPainter && this.__onlyRegion)
449
- return this;
450
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
451
- return this;
452
- };
453
- Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
454
- if (this.__region && !this.__onlyView)
455
- this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
456
- if (this.__isPainter && this.__onlyRegion)
457
- return this;
458
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
459
- return this;
460
- };
461
- Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
462
- if (this.__region && !this.__onlyView)
463
- this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
464
- if (this.__isPainter && this.__onlyRegion)
465
- return this;
466
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
467
- this.painter.fill();
468
- this.painter.stroke();
469
- return this;
470
- };
471
- Painter.prototype.fillCircle = function (cx, cy, r) {
472
- if (this.__region && !this.__onlyView)
473
- this.__region.fillCircle(cx, cy, r);
474
- if (this.__isPainter && this.__onlyRegion)
475
- return this;
476
- initCircle(this.painter, cx, cy, r).fill();
477
- return this;
478
- };
479
- Painter.prototype.strokeCircle = function (cx, cy, r) {
480
- if (this.__region && !this.__onlyView)
481
- this.__region.strokeCircle(cx, cy, r);
482
- if (this.__isPainter && this.__onlyRegion)
483
- return this;
484
- initCircle(this.painter, cx, cy, r).stroke();
485
- return this;
486
- };
487
- Painter.prototype.fullCircle = function (cx, cy, r) {
488
- if (this.__region && !this.__onlyView)
489
- this.__region.fullCircle(cx, cy, r);
490
- if (this.__isPainter && this.__onlyRegion)
491
- return this;
492
- initCircle(this.painter, cx, cy, r);
493
- this.painter.fill();
494
- this.painter.stroke();
495
- return this;
496
- };
497
- Painter.prototype.fillRect = function (x, y, width, height) {
498
- if (this.__region && !this.__onlyView)
499
- this.__region.fillRect(x, y, width, height);
500
- if (this.__isPainter && this.__onlyRegion)
501
- return this;
502
- initRect(this.painter, this.__specialConfig, x, y, width, height).fill();
503
- return this;
504
- };
505
- Painter.prototype.strokeRect = function (x, y, width, height) {
506
- if (this.__region && !this.__onlyView)
507
- this.__region.strokeRect(x, y, width, height);
508
- if (this.__isPainter && this.__onlyRegion)
509
- return this;
510
- initRect(this.painter, this.__specialConfig, x, y, width, height).stroke();
511
- return this;
512
- };
513
- Painter.prototype.fullRect = function (x, y, width, height) {
514
- if (this.__region && !this.__onlyView)
515
- this.__region.fullRect(x, y, width, height);
516
- if (this.__isPainter && this.__onlyRegion)
517
- return this;
518
- initRect(this.painter, this.__specialConfig, x, y, width, height);
519
- this.painter.fill();
520
- this.painter.stroke();
521
- return this;
522
- };
523
- Painter.prototype.draw = function () {
524
- return Promise.resolve();
525
- };
526
- Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
527
- var _this = this;
528
- if (isImage === void 0) { isImage = false; }
529
- return new Promise(function (resolve) {
530
- if (_this.__region && !_this.__onlyView) {
531
- _this.__region.fillRect(x, y, w, h);
532
- }
533
- if (_this.__isPainter && _this.__onlyRegion) {
534
- resolve({});
535
- return;
536
- }
537
- if (typeof img == 'string' && !isImage) {
538
- var imgInstance_1 = new Image();
539
- imgInstance_1.onload = function () {
540
- _this.painter.drawImage(imgInstance_1, x, y, w, h);
541
- resolve({});
542
- };
543
- imgInstance_1.src = img;
544
- }
545
- else {
546
- _this.painter.drawImage(img, x, y, w, h);
547
- resolve({});
548
- }
549
- });
550
- };
551
- Painter.prototype.translate = function (dx, dy) {
552
- this.painter.translate(dx, dy);
553
- return this;
554
- };
555
- Painter.prototype.rotate = function (deg) {
556
- this.painter.rotate(deg);
557
- return this;
558
- };
559
- Painter.prototype.install = function (methods) {
560
- var _this = this;
561
- var _loop_1 = function (key) {
562
- if (key in this_1) {
563
- throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.");
564
- }
565
- else {
566
- this_1[key] = function () {
567
- var args = [];
568
- for (var _i = 0; _i < arguments.length; _i++) {
569
- args[_i] = arguments[_i];
570
- }
571
- var value = methods[key].apply(_this, args);
572
- if (value != void 0)
573
- return value;
574
- return _this;
575
- };
576
- }
577
- };
578
- var this_1 = this;
579
- for (var key in methods) {
580
- _loop_1(key);
581
- }
582
- return this;
583
- };
584
- return Painter;
190
+ var Painter = (function () {
191
+ function Painter(canvas, opts, region, isPainter, scaleSize) {
192
+ if (opts === void 0) { opts = {}; }
193
+ if (isPainter === void 0) { isPainter = false; }
194
+ this.__region = null;
195
+ this.__onlyRegion = false;
196
+ this.__onlyView = false;
197
+ this.__specialConfig = defaultFactory("special");
198
+ this.__initConfig = defaultFactory("init");
199
+ this.painter = canvas.getContext("2d", opts);
200
+ this.__region = region;
201
+ this.__isPainter = isPainter;
202
+ this.painter.textBaseline = 'middle';
203
+ this.painter.textAlign = 'left';
204
+ this.painter.shadowColor = 'black';
205
+ }
206
+ Painter.prototype.useConfig = function (key, value) {
207
+ if (this.__region && !this.__onlyView) {
208
+ if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
209
+ this.__region.useConfig(key, value);
210
+ }
211
+ }
212
+ if (this.__isPainter && this.__onlyRegion)
213
+ return this;
214
+ if (key == 'lineDash') {
215
+ if (this.painter.setLineDash)
216
+ this.painter.setLineDash(value);
217
+ }
218
+ else if (key in this.__specialConfig) {
219
+ if (key == 'fontSize') {
220
+ value = Math.round(value);
221
+ }
222
+ this.__specialConfig[key] = value;
223
+ }
224
+ else if (key in this.__initConfig) {
225
+ this.painter[key] = value;
226
+ }
227
+ else {
228
+ throw new Error('Illegal configuration item of painter : ' + key + " !");
229
+ }
230
+ return this;
231
+ };
232
+ Painter.prototype.fillText = function (text, x, y, deg) {
233
+ if (deg === void 0) { deg = 0; }
234
+ if (this.__region && !this.__onlyView)
235
+ this.__region.fillText(text, x, y, deg);
236
+ if (this.__isPainter && this.__onlyRegion)
237
+ return this;
238
+ this.painter.save();
239
+ initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
240
+ this.painter.restore();
241
+ return this;
242
+ };
243
+ Painter.prototype.strokeText = function (text, x, y, deg) {
244
+ if (deg === void 0) { deg = 0; }
245
+ if (this.__region && !this.__onlyView)
246
+ this.__region.strokeText(text, x, y, deg);
247
+ if (this.__isPainter && this.__onlyRegion)
248
+ return this;
249
+ this.painter.save();
250
+ initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
251
+ this.painter.restore();
252
+ return this;
253
+ };
254
+ Painter.prototype.fullText = function (text, x, y, deg) {
255
+ if (deg === void 0) { deg = 0; }
256
+ if (this.__region && !this.__onlyView)
257
+ this.__region.fullText(text, x, y, deg);
258
+ if (this.__isPainter && this.__onlyRegion)
259
+ return this;
260
+ this.painter.save();
261
+ initText(this.painter, this.__specialConfig, x, y, deg);
262
+ this.painter.fillText(text, 0, 0);
263
+ this.painter.strokeText(text, 0, 0);
264
+ this.painter.restore();
265
+ return this;
266
+ };
267
+ Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
268
+ var _this = this;
269
+ if (lineHeight === void 0) { lineHeight = 1.2; }
270
+ if (deg === void 0) { deg = 0; }
271
+ var h = 0;
272
+ if (this.__region && !this.__onlyView)
273
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
274
+ if (this.__isPainter && this.__onlyRegion)
275
+ return h;
276
+ this.painter.save();
277
+ initText(this.painter, this.__specialConfig, x, y, deg);
278
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
279
+ _this.painter.fillText(content, 0, top);
280
+ });
281
+ this.painter.restore();
282
+ return height;
283
+ };
284
+ Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
285
+ var _this = this;
286
+ if (lineHeight === void 0) { lineHeight = 1.2; }
287
+ if (deg === void 0) { deg = 0; }
288
+ var h = 0;
289
+ if (this.__region && !this.__onlyView)
290
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
291
+ if (this.__isPainter && this.__onlyRegion)
292
+ return h;
293
+ this.painter.save();
294
+ initText(this.painter, this.__specialConfig, x, y, deg);
295
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
296
+ _this.painter.strokeText(content, 0, top);
297
+ });
298
+ this.painter.restore();
299
+ return height;
300
+ };
301
+ Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
302
+ var _this = this;
303
+ if (lineHeight === void 0) { lineHeight = 1.2; }
304
+ if (deg === void 0) { deg = 0; }
305
+ var h = 0;
306
+ if (this.__region && !this.__onlyView)
307
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
308
+ if (this.__isPainter && this.__onlyRegion)
309
+ return h;
310
+ this.painter.save();
311
+ initText(this.painter, this.__specialConfig, x, y, deg);
312
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
313
+ _this.painter.fillText(content, 0, top);
314
+ _this.painter.strokeText(content, 0, top);
315
+ });
316
+ this.painter.restore();
317
+ return height;
318
+ };
319
+ Painter.prototype.beginPath = function () {
320
+ if (this.__region && !this.__onlyView)
321
+ this.__region.beginPath();
322
+ if (this.__isPainter && this.__onlyRegion)
323
+ return this;
324
+ this.painter.beginPath();
325
+ return this;
326
+ };
327
+ Painter.prototype.closePath = function () {
328
+ if (this.__region && !this.__onlyView)
329
+ this.__region.closePath();
330
+ if (this.__isPainter && this.__onlyRegion)
331
+ return this;
332
+ this.painter.closePath();
333
+ return this;
334
+ };
335
+ Painter.prototype.moveTo = function (x, y) {
336
+ if (this.__region && !this.__onlyView)
337
+ this.__region.moveTo(x, y);
338
+ if (this.__isPainter && this.__onlyRegion)
339
+ return this;
340
+ this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
341
+ return this;
342
+ };
343
+ Painter.prototype.lineTo = function (x, y) {
344
+ if (this.__region && !this.__onlyView)
345
+ this.__region.lineTo(x, y);
346
+ if (this.__isPainter && this.__onlyRegion)
347
+ return this;
348
+ this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
349
+ return this;
350
+ };
351
+ Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
352
+ if (this.__region && !this.__onlyView)
353
+ this.__region.arc(x, y, r, beginDeg, deg);
354
+ if (this.__isPainter && this.__onlyRegion)
355
+ return this;
356
+ this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
357
+ return this;
358
+ };
359
+ Painter.prototype.fill = function () {
360
+ if (this.__region && !this.__onlyView)
361
+ this.__region.fill();
362
+ if (this.__isPainter && this.__onlyRegion)
363
+ return this;
364
+ this.painter.fill();
365
+ return this;
366
+ };
367
+ Painter.prototype.stroke = function () {
368
+ if (this.__region && !this.__onlyView)
369
+ this.__region.stroke();
370
+ if (this.__isPainter && this.__onlyRegion)
371
+ return this;
372
+ this.painter.stroke();
373
+ return this;
374
+ };
375
+ Painter.prototype.full = function () {
376
+ if (this.__region && !this.__onlyView)
377
+ this.__region.full();
378
+ if (this.__isPainter && this.__onlyRegion)
379
+ return this;
380
+ this.painter.fill();
381
+ this.painter.stroke();
382
+ return this;
383
+ };
384
+ Painter.prototype.save = function () {
385
+ if (this.__region && !this.__onlyView)
386
+ this.__region.save();
387
+ if (this.__isPainter && this.__onlyRegion)
388
+ return this;
389
+ this.painter.save();
390
+ return this;
391
+ };
392
+ Painter.prototype.restore = function () {
393
+ if (this.__region && !this.__onlyView)
394
+ this.__region.restore();
395
+ if (this.__isPainter && this.__onlyRegion)
396
+ return this;
397
+ this.painter.restore();
398
+ return this;
399
+ };
400
+ Painter.prototype.clip = function () {
401
+ if (this.__region && !this.__onlyView)
402
+ this.__region.clip();
403
+ if (this.__isPainter && this.__onlyRegion)
404
+ return this;
405
+ this.painter.clip();
406
+ return this;
407
+ };
408
+ Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
409
+ if (this.__region && !this.__onlyView)
410
+ this.__region.quadraticCurveTo(cpx, cpy, x, y);
411
+ if (this.__isPainter && this.__onlyRegion)
412
+ return this;
413
+ this.painter.quadraticCurveTo(cpx, cpy, x, y);
414
+ return this;
415
+ };
416
+ Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
417
+ if (this.__region && !this.__onlyView)
418
+ this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
419
+ if (this.__isPainter && this.__onlyRegion)
420
+ return this;
421
+ this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
422
+ return this;
423
+ };
424
+ Painter.prototype.clearRect = function (x, y, w, h) {
425
+ if (this.__region && !this.__onlyView)
426
+ this.__region.clearRect(x, y, w, h);
427
+ if (this.__isPainter && this.__onlyRegion)
428
+ return this;
429
+ this.painter.clearRect(x, y, w, h);
430
+ return this;
431
+ };
432
+ Painter.prototype.clearCircle = function (cx, cy, r) {
433
+ if (this.__region && !this.__onlyView)
434
+ this.__region.clearCircle(cx, cy, r);
435
+ if (this.__isPainter && this.__onlyRegion)
436
+ return this;
437
+ this.painter.beginPath();
438
+ this.painter.globalCompositeOperation = "destination-out";
439
+ this.painter.arc(cx, cy, r, 0, Math.PI * 2);
440
+ this.painter.fill();
441
+ this.painter.globalCompositeOperation = "source-over";
442
+ this.painter.closePath();
443
+ return this;
444
+ };
445
+ Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
446
+ if (this.__region && !this.__onlyView)
447
+ this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
448
+ if (this.__isPainter && this.__onlyRegion)
449
+ return this;
450
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
451
+ return this;
452
+ };
453
+ Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
454
+ if (this.__region && !this.__onlyView)
455
+ this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
456
+ if (this.__isPainter && this.__onlyRegion)
457
+ return this;
458
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
459
+ return this;
460
+ };
461
+ Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
462
+ if (this.__region && !this.__onlyView)
463
+ this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
464
+ if (this.__isPainter && this.__onlyRegion)
465
+ return this;
466
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
467
+ this.painter.fill();
468
+ this.painter.stroke();
469
+ return this;
470
+ };
471
+ Painter.prototype.fillCircle = function (cx, cy, r) {
472
+ if (this.__region && !this.__onlyView)
473
+ this.__region.fillCircle(cx, cy, r);
474
+ if (this.__isPainter && this.__onlyRegion)
475
+ return this;
476
+ initCircle(this.painter, cx, cy, r).fill();
477
+ return this;
478
+ };
479
+ Painter.prototype.strokeCircle = function (cx, cy, r) {
480
+ if (this.__region && !this.__onlyView)
481
+ this.__region.strokeCircle(cx, cy, r);
482
+ if (this.__isPainter && this.__onlyRegion)
483
+ return this;
484
+ initCircle(this.painter, cx, cy, r).stroke();
485
+ return this;
486
+ };
487
+ Painter.prototype.fullCircle = function (cx, cy, r) {
488
+ if (this.__region && !this.__onlyView)
489
+ this.__region.fullCircle(cx, cy, r);
490
+ if (this.__isPainter && this.__onlyRegion)
491
+ return this;
492
+ initCircle(this.painter, cx, cy, r);
493
+ this.painter.fill();
494
+ this.painter.stroke();
495
+ return this;
496
+ };
497
+ Painter.prototype.fillRect = function (x, y, width, height) {
498
+ if (this.__region && !this.__onlyView)
499
+ this.__region.fillRect(x, y, width, height);
500
+ if (this.__isPainter && this.__onlyRegion)
501
+ return this;
502
+ initRect(this.painter, this.__specialConfig, x, y, width, height).fill();
503
+ return this;
504
+ };
505
+ Painter.prototype.strokeRect = function (x, y, width, height) {
506
+ if (this.__region && !this.__onlyView)
507
+ this.__region.strokeRect(x, y, width, height);
508
+ if (this.__isPainter && this.__onlyRegion)
509
+ return this;
510
+ initRect(this.painter, this.__specialConfig, x, y, width, height).stroke();
511
+ return this;
512
+ };
513
+ Painter.prototype.fullRect = function (x, y, width, height) {
514
+ if (this.__region && !this.__onlyView)
515
+ this.__region.fullRect(x, y, width, height);
516
+ if (this.__isPainter && this.__onlyRegion)
517
+ return this;
518
+ initRect(this.painter, this.__specialConfig, x, y, width, height);
519
+ this.painter.fill();
520
+ this.painter.stroke();
521
+ return this;
522
+ };
523
+ Painter.prototype.draw = function () {
524
+ return Promise.resolve();
525
+ };
526
+ Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
527
+ var _this = this;
528
+ if (isImage === void 0) { isImage = false; }
529
+ return new Promise(function (resolve) {
530
+ if (_this.__region && !_this.__onlyView) {
531
+ _this.__region.fillRect(x, y, w, h);
532
+ }
533
+ if (_this.__isPainter && _this.__onlyRegion) {
534
+ resolve({});
535
+ return;
536
+ }
537
+ if (typeof img == 'string' && !isImage) {
538
+ var imgInstance_1 = new Image();
539
+ var mat_1 = null;
540
+ if (_this.painter.getTransform)
541
+ mat_1 = _this.painter.getTransform();
542
+ var alpha_1 = _this.painter.globalAlpha;
543
+ var compOp_1 = _this.painter.globalCompositeOperation;
544
+ var smoothEnable_1 = _this.painter.imageSmoothingEnabled;
545
+ var smoothQuality_1 = _this.painter.imageSmoothingQuality;
546
+ imgInstance_1.onload = function () {
547
+ _this.painter.save();
548
+ if (mat_1)
549
+ _this.painter.setTransform(mat_1);
550
+ _this.painter.globalAlpha = alpha_1;
551
+ _this.painter.globalCompositeOperation = compOp_1;
552
+ _this.painter.imageSmoothingEnabled = smoothEnable_1;
553
+ _this.painter.imageSmoothingQuality = smoothQuality_1;
554
+ _this.painter.drawImage(imgInstance_1, x, y, w, h);
555
+ _this.painter.restore();
556
+ resolve({});
557
+ };
558
+ imgInstance_1.src = img;
559
+ }
560
+ else {
561
+ _this.painter.drawImage(img, x, y, w, h);
562
+ resolve({});
563
+ }
564
+ });
565
+ };
566
+ Painter.prototype.translate = function (dx, dy) {
567
+ this.painter.translate(dx, dy);
568
+ return this;
569
+ };
570
+ Painter.prototype.rotate = function (deg) {
571
+ this.painter.rotate(deg);
572
+ return this;
573
+ };
574
+ Painter.prototype.install = function (methods) {
575
+ var _this = this;
576
+ var _loop_1 = function (key) {
577
+ if (key in this_1) {
578
+ throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.");
579
+ }
580
+ else {
581
+ this_1[key] = function () {
582
+ var args = [];
583
+ for (var _i = 0; _i < arguments.length; _i++) {
584
+ args[_i] = arguments[_i];
585
+ }
586
+ var value = methods[key].apply(_this, args);
587
+ if (value != void 0)
588
+ return value;
589
+ return _this;
590
+ };
591
+ }
592
+ };
593
+ var this_1 = this;
594
+ for (var key in methods) {
595
+ _loop_1(key);
596
+ }
597
+ return this;
598
+ };
599
+ return Painter;
585
600
  }());
586
601
 
587
- function assemble (begin, end, step, count) {
588
- var val = [];
589
- for (var index = 0; index < count; index++)
590
- val[index] = begin;
591
- return function () {
592
- for (var i = 0; i < count; i++) {
593
- if (val[i] + step < end) {
594
- val[i] = val[i] + step;
595
- break;
596
- }
597
- else if (i < count - 1) {
598
- val[i] = begin;
599
- }
600
- }
601
- for (var k = 0; k < val.length; k++) {
602
- val[k] = +val[k].toFixed(7);
603
- }
604
- return val;
605
- };
602
+ function assemble (begin, end, step, count) {
603
+ var val = [];
604
+ for (var index = 0; index < count; index++)
605
+ val[index] = begin;
606
+ return function () {
607
+ for (var i = 0; i < count; i++) {
608
+ if (val[i] + step < end) {
609
+ val[i] = val[i] + step;
610
+ break;
611
+ }
612
+ else if (i < count - 1) {
613
+ val[i] = begin;
614
+ }
615
+ }
616
+ for (var k = 0; k < val.length; k++) {
617
+ val[k] = +val[k].toFixed(7);
618
+ }
619
+ return val;
620
+ };
606
621
  }
607
622
 
608
- var enhanceGradient = function (gradient, calcStop) {
609
- var enhanceGradient = {
610
- "value": function () {
611
- return gradient;
612
- },
613
- "setColor": function (stop, color) {
614
- gradient.addColorStop(calcStop ? calcStop(stop) : stop, color);
615
- return enhanceGradient;
616
- }
617
- };
618
- return enhanceGradient;
619
- };
620
- var linearGradient = function (painter, x0, y0, x1, y1) {
621
- var gradient = painter.createLinearGradient(x0, y0, x1, y1);
622
- return enhanceGradient(gradient);
623
- };
624
- var radialGradient = function (painter, cx, cy, r) {
625
- var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
626
- return enhanceGradient(gradient);
627
- };
628
- var conicGradient = function (painter, cx, cy, startDeg, deg) {
629
- var gradient = painter.createConicGradient(startDeg, cx, cy);
630
- return enhanceGradient(gradient, deg ? function (stop) {
631
- return deg / (Math.PI * 2) * stop;
632
- } : void 0);
623
+ var enhanceGradient = function (gradient, calcStop) {
624
+ var enhanceGradient = {
625
+ "value": function () {
626
+ return gradient;
627
+ },
628
+ "setColor": function (stop, color) {
629
+ gradient.addColorStop(calcStop ? calcStop(stop) : stop, color);
630
+ return enhanceGradient;
631
+ }
632
+ };
633
+ return enhanceGradient;
634
+ };
635
+ var linearGradient = function (painter, x0, y0, x1, y1) {
636
+ var gradient = painter.createLinearGradient(x0, y0, x1, y1);
637
+ return enhanceGradient(gradient);
638
+ };
639
+ var radialGradient = function (painter, cx, cy, r) {
640
+ var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
641
+ return enhanceGradient(gradient);
642
+ };
643
+ var conicGradient = function (painter, cx, cy, startDeg, deg) {
644
+ var gradient = painter.createConicGradient(startDeg, cx, cy);
645
+ return enhanceGradient(gradient, deg ? function (stop) {
646
+ return deg / (Math.PI * 2) * stop;
647
+ } : void 0);
633
648
  };
634
649
 
635
- function initOption(setOption, defaultOption) {
636
- for (var key in setOption) {
637
- defaultOption[key] = setOption[key];
638
- }
639
- return defaultOption;
650
+ function initOption(setOption, defaultOption) {
651
+ for (var key in setOption) {
652
+ defaultOption[key] = setOption[key];
653
+ }
654
+ return defaultOption;
640
655
  }
641
656
 
642
- var Canvas$1 = (function (_super) {
643
- __extends(Canvas, _super);
644
- function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
645
- if (opts === void 0) { opts = {}; }
646
- if (scaleSize === void 0) { scaleSize = 1; }
647
- var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
648
- willReadFrequently: true,
649
- }) : undefined, true, scaleSize) || this;
650
- _this.name = "Canvas";
651
- _this.__regionList = {};
652
- _this.__regionAssemble = assemble(0, 255, 10, 3);
653
- _this.__scaleSize = scaleSize;
654
- _this.setRegion("");
655
- return _this;
656
- }
657
- Canvas.prototype.config = function (configs) {
658
- for (var key in configs) {
659
- this.useConfig(key, configs[key]);
660
- }
661
- return this;
662
- };
663
- Canvas.prototype.reset = function (config) {
664
- if (config === void 0) { config = {}; }
665
- this.config(initOption(config, defaultFactory()));
666
- return this;
667
- };
668
- Canvas.prototype.onlyRegion = function (flag) {
669
- this.__onlyRegion = flag;
670
- return this;
671
- };
672
- Canvas.prototype.onlyView = function (flag) {
673
- this.__onlyView = flag;
674
- return this;
675
- };
676
- Canvas.prototype.setRegion = function (regionName) {
677
- if (this.__region) {
678
- if (regionName) {
679
- if (this.__regionList[regionName] == void 0) {
680
- var tempColor = this.__regionAssemble();
681
- this.__regionList[regionName] =
682
- "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
683
- }
684
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
685
- this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
686
- }
687
- else {
688
- this.__region.useConfig("fillStyle", "#000000") &&
689
- this.__region.useConfig("strokeStyle", "#000000");
690
- }
691
- }
692
- return this;
693
- };
694
- Canvas.prototype.getRegion = function (x, y) {
695
- var _this = this;
696
- return new Promise(function (resolve) {
697
- var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
698
- data: [0, 0, 0, 0]
699
- };
700
- var currentRGBA = imgData.data;
701
- var doit = function () {
702
- if (_this.__region) {
703
- for (var key in _this.__regionList) {
704
- if ("rgb(" +
705
- currentRGBA[0] +
706
- "," +
707
- currentRGBA[1] +
708
- "," +
709
- currentRGBA[2] +
710
- ")" ==
711
- _this.__regionList[key]) {
712
- resolve(key);
713
- break;
714
- }
715
- }
716
- }
717
- resolve("");
718
- };
719
- if (currentRGBA) {
720
- doit();
721
- }
722
- else {
723
- imgData.then(function (data) {
724
- currentRGBA = data;
725
- doit();
726
- });
727
- }
728
- });
729
- };
730
- Canvas.prototype.textWidth = function (text) {
731
- this.painter.save();
732
- initText(this.painter, this.__specialConfig, 0, 0, 0);
733
- var width = this.painter.measureText(text + "").width;
734
- this.painter.restore();
735
- return width;
736
- };
737
- Canvas.prototype.getContext = function (isRegion) {
738
- if (isRegion === void 0) { isRegion = false; }
739
- return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
740
- };
741
- Canvas.prototype.getInfo = function () {
742
- return {
743
- width: this.painter.canvas.width / this.__scaleSize,
744
- height: this.painter.canvas.height / this.__scaleSize
745
- };
746
- };
747
- Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
748
- return linearGradient(this.painter, x0, y0, x1, y1);
749
- };
750
- Canvas.prototype.createRadialGradient = function (cx, cy, r) {
751
- return radialGradient(this.painter, cx, cy, r);
752
- };
753
- Canvas.prototype.createConicGradient = function (cx, cy, beginDeg, deg) {
754
- return conicGradient(this.painter, cx, cy, beginDeg, deg);
755
- };
756
- Canvas.prototype.getColor = function (x, y) {
757
- x *= this.__scaleSize;
758
- y *= this.__scaleSize;
759
- var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
760
- return ("rgba(" +
761
- currentRGBA[0] +
762
- "," +
763
- currentRGBA[1] +
764
- "," +
765
- currentRGBA[2] +
766
- "," +
767
- currentRGBA[3] +
768
- ")");
769
- };
770
- return Canvas;
657
+ var Canvas$1 = (function (_super) {
658
+ __extends(Canvas, _super);
659
+ function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
660
+ if (opts === void 0) { opts = {}; }
661
+ if (scaleSize === void 0) { scaleSize = 1; }
662
+ var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
663
+ willReadFrequently: true,
664
+ }) : undefined, true, scaleSize) || this;
665
+ _this.name = "Canvas";
666
+ _this.__regionList = {};
667
+ _this.__regionAssemble = assemble(0, 255, 10, 3);
668
+ _this.__scaleSize = scaleSize;
669
+ _this.setRegion("");
670
+ return _this;
671
+ }
672
+ Canvas.prototype.config = function (configs) {
673
+ for (var key in configs) {
674
+ this.useConfig(key, configs[key]);
675
+ }
676
+ return this;
677
+ };
678
+ Canvas.prototype.reset = function (config) {
679
+ if (config === void 0) { config = {}; }
680
+ this.config(initOption(config, defaultFactory()));
681
+ return this;
682
+ };
683
+ Canvas.prototype.onlyRegion = function (flag) {
684
+ this.__onlyRegion = flag;
685
+ return this;
686
+ };
687
+ Canvas.prototype.onlyView = function (flag) {
688
+ this.__onlyView = flag;
689
+ return this;
690
+ };
691
+ Canvas.prototype.setRegion = function (regionName) {
692
+ if (this.__region) {
693
+ if (regionName) {
694
+ if (this.__regionList[regionName] == void 0) {
695
+ var tempColor = this.__regionAssemble();
696
+ this.__regionList[regionName] =
697
+ "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
698
+ }
699
+ this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
700
+ this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
701
+ }
702
+ else {
703
+ this.__region.useConfig("fillStyle", "#000000") &&
704
+ this.__region.useConfig("strokeStyle", "#000000");
705
+ }
706
+ }
707
+ return this;
708
+ };
709
+ Canvas.prototype.getRegion = function (x, y) {
710
+ var _this = this;
711
+ return new Promise(function (resolve) {
712
+ var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
713
+ data: [0, 0, 0, 0]
714
+ };
715
+ var currentRGBA = imgData.data;
716
+ var doit = function () {
717
+ if (_this.__region) {
718
+ for (var key in _this.__regionList) {
719
+ if ("rgb(" +
720
+ currentRGBA[0] +
721
+ "," +
722
+ currentRGBA[1] +
723
+ "," +
724
+ currentRGBA[2] +
725
+ ")" ==
726
+ _this.__regionList[key]) {
727
+ resolve(key);
728
+ break;
729
+ }
730
+ }
731
+ }
732
+ resolve("");
733
+ };
734
+ if (currentRGBA) {
735
+ doit();
736
+ }
737
+ else {
738
+ imgData.then(function (data) {
739
+ currentRGBA = data;
740
+ doit();
741
+ });
742
+ }
743
+ });
744
+ };
745
+ Canvas.prototype.textWidth = function (text) {
746
+ this.painter.save();
747
+ initText(this.painter, this.__specialConfig, 0, 0, 0);
748
+ var width = this.painter.measureText(text + "").width;
749
+ this.painter.restore();
750
+ return width;
751
+ };
752
+ Canvas.prototype.getContext = function (isRegion) {
753
+ if (isRegion === void 0) { isRegion = false; }
754
+ return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
755
+ };
756
+ Canvas.prototype.getInfo = function () {
757
+ return {
758
+ width: this.painter.canvas.width / this.__scaleSize,
759
+ height: this.painter.canvas.height / this.__scaleSize
760
+ };
761
+ };
762
+ Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
763
+ return linearGradient(this.painter, x0, y0, x1, y1);
764
+ };
765
+ Canvas.prototype.createRadialGradient = function (cx, cy, r) {
766
+ return radialGradient(this.painter, cx, cy, r);
767
+ };
768
+ Canvas.prototype.createConicGradient = function (cx, cy, beginDeg, deg) {
769
+ return conicGradient(this.painter, cx, cy, beginDeg, deg);
770
+ };
771
+ Canvas.prototype.getColor = function (x, y) {
772
+ x *= this.__scaleSize;
773
+ y *= this.__scaleSize;
774
+ var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
775
+ return ("rgba(" +
776
+ currentRGBA[0] +
777
+ "," +
778
+ currentRGBA[1] +
779
+ "," +
780
+ currentRGBA[2] +
781
+ "," +
782
+ currentRGBA[3] +
783
+ ")");
784
+ };
785
+ return Canvas;
771
786
  }(Painter));
772
787
 
773
- var Canvas = (function (_super) {
774
- __extends(Canvas, _super);
775
- function Canvas(el, option, width, height) {
776
- if (option === void 0) { option = {}; }
777
- if (width === void 0) { width = 0; }
778
- if (height === void 0) { height = 0; }
779
- var _this = this;
780
- if (!el) {
781
- throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
782
- }
783
- option = initOption(option, {
784
- scale: 2,
785
- region: true,
786
- willReadFrequently: false
787
- });
788
- width = width || el.clientWidth;
789
- height = height || el.clientHeight;
790
- var ViewCanvas, RegionCanvas = null;
791
- var _el = el;
792
- if (_el._vislite_canvas_) {
793
- ViewCanvas = _el._vislite_canvas_[0];
794
- RegionCanvas = _el._vislite_canvas_[1];
795
- }
796
- else {
797
- ViewCanvas = document.createElement('canvas');
798
- el.appendChild(ViewCanvas);
799
- if (option.region) {
800
- RegionCanvas = document.createElement('canvas');
801
- }
802
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
803
- el.setAttribute('vislite', 'Canvas');
804
- }
805
- var canvasArray = [RegionCanvas, ViewCanvas];
806
- for (var index = 0; index < canvasArray.length; index++) {
807
- var canvas = canvasArray[index];
808
- if (canvas) {
809
- canvas.style.width = width + "px";
810
- canvas.setAttribute('width', ((index === 1 ? option.scale : 1) * width) + "");
811
- canvas.style.height = height + "px";
812
- canvas.setAttribute('height', ((index === 1 ? option.scale : 1) * height) + "");
813
- }
814
- }
815
- _this = _super.call(this, ViewCanvas, RegionCanvas, {
816
- willReadFrequently: option.willReadFrequently,
817
- }, option.scale) || this;
818
- _this.__canvas = ViewCanvas;
819
- _this.__el = el;
820
- _this.painter.scale(option.scale, option.scale);
821
- return _this;
822
- }
823
- Canvas.prototype.toDataURL = function (type, encoderOptions) {
824
- var _this = this;
825
- if (type === void 0) { type = "image/png"; }
826
- if (encoderOptions === void 0) { encoderOptions = 0.92; }
827
- return new Promise(function (resolve) {
828
- resolve(_this.__canvas.toDataURL(type, encoderOptions));
829
- });
830
- };
831
- Canvas.prototype.bind = function (eventName, callback) {
832
- var _this = this;
833
- this.__el.addEventListener(eventName, function (event) {
834
- _this.getRegion(event.offsetX, event.offsetY).then(function (regionName) {
835
- callback(regionName, event.offsetX, event.offsetY);
836
- });
837
- });
838
- return this;
839
- };
840
- return Canvas;
788
+ var Canvas = (function (_super) {
789
+ __extends(Canvas, _super);
790
+ function Canvas(el, option, width, height) {
791
+ if (option === void 0) { option = {}; }
792
+ if (width === void 0) { width = 0; }
793
+ if (height === void 0) { height = 0; }
794
+ var _this = this;
795
+ if (!el) {
796
+ throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
797
+ }
798
+ option = initOption(option, {
799
+ scale: 2,
800
+ region: true,
801
+ willReadFrequently: false
802
+ });
803
+ width = width || el.clientWidth;
804
+ height = height || el.clientHeight;
805
+ var ViewCanvas, RegionCanvas = null;
806
+ var _el = el;
807
+ if (_el._vislite_canvas_) {
808
+ ViewCanvas = _el._vislite_canvas_[0];
809
+ RegionCanvas = _el._vislite_canvas_[1];
810
+ }
811
+ else {
812
+ ViewCanvas = document.createElement('canvas');
813
+ el.appendChild(ViewCanvas);
814
+ if (option.region) {
815
+ RegionCanvas = document.createElement('canvas');
816
+ }
817
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
818
+ el.setAttribute('vislite', 'Canvas');
819
+ }
820
+ var canvasArray = [RegionCanvas, ViewCanvas];
821
+ for (var index = 0; index < canvasArray.length; index++) {
822
+ var canvas = canvasArray[index];
823
+ if (canvas) {
824
+ canvas.style.width = width + "px";
825
+ canvas.setAttribute('width', ((index === 1 ? option.scale : 1) * width) + "");
826
+ canvas.style.height = height + "px";
827
+ canvas.setAttribute('height', ((index === 1 ? option.scale : 1) * height) + "");
828
+ }
829
+ }
830
+ _this = _super.call(this, ViewCanvas, RegionCanvas, {
831
+ willReadFrequently: option.willReadFrequently,
832
+ }, option.scale) || this;
833
+ _this.__canvas = ViewCanvas;
834
+ _this.__el = el;
835
+ _this.painter.scale(option.scale, option.scale);
836
+ return _this;
837
+ }
838
+ Canvas.prototype.toDataURL = function (type, encoderOptions) {
839
+ var _this = this;
840
+ if (type === void 0) { type = "image/png"; }
841
+ if (encoderOptions === void 0) { encoderOptions = 0.92; }
842
+ return new Promise(function (resolve) {
843
+ resolve(_this.__canvas.toDataURL(type, encoderOptions));
844
+ });
845
+ };
846
+ Canvas.prototype.bind = function (eventName, callback) {
847
+ var _this = this;
848
+ this.__el.addEventListener(eventName, function (event) {
849
+ _this.getRegion(event.offsetX, event.offsetY).then(function (regionName) {
850
+ callback(regionName, event.offsetX, event.offsetY);
851
+ });
852
+ });
853
+ return this;
854
+ };
855
+ return Canvas;
841
856
  }(Canvas$1));
842
857
 
843
858
  export { Canvas as default };