vislite 0.8.1-alpha.1 → 0.8.1

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