vislite 0.5.2-alpha.1 → 0.5.2-alpha.2

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