vislite 1.3.0 → 1.4.0-alpha.0

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