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