ace-colorpicker-rpk 0.0.12

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 (238) hide show
  1. package/.babelrc +30 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  4. package/ChangeLogs.md +22 -0
  5. package/LICENSE +21 -0
  6. package/README.md +117 -0
  7. package/addon/ace-colorpicker.css +1074 -0
  8. package/addon/ace-colorpicker.js +9602 -0
  9. package/addon/sample/colorpicker.html +199 -0
  10. package/config/rollup.config.dev.js +52 -0
  11. package/config/rollup.config.prod.js +53 -0
  12. package/dist/ace-colorpicker.css +1074 -0
  13. package/dist/ace-colorpicker.js +9736 -0
  14. package/dist/ace-colorpicker.min.js +1 -0
  15. package/gl.html +56 -0
  16. package/index.html +172 -0
  17. package/package.json +87 -0
  18. package/resources/image/ace-editor.png +0 -0
  19. package/resources/image/colorpaletts.png +0 -0
  20. package/resources/image/colorpicker.png +0 -0
  21. package/resources/image/grapes.jpg +0 -0
  22. package/resources/image/palette-type.png +0 -0
  23. package/resources/image/scalecolors-title.png +0 -0
  24. package/resources/image/scalecolors.png +0 -0
  25. package/resources/image/screen-shot.png +0 -0
  26. package/resources/image/sketch-type.png +0 -0
  27. package/src/colorpicker/BaseBox.js +94 -0
  28. package/src/colorpicker/BaseColorPicker.js +404 -0
  29. package/src/colorpicker/BaseModule.js +19 -0
  30. package/src/colorpicker/BaseSlider.js +97 -0
  31. package/src/colorpicker/BaseStore.js +71 -0
  32. package/src/colorpicker/UIElement.js +46 -0
  33. package/src/colorpicker/VerticalSlider.js +57 -0
  34. package/src/colorpicker/chromedevtool/ColorControl.js +47 -0
  35. package/src/colorpicker/chromedevtool/index.js +36 -0
  36. package/src/colorpicker/index.js +37 -0
  37. package/src/colorpicker/macos/ColorControl.js +47 -0
  38. package/src/colorpicker/macos/index.js +38 -0
  39. package/src/colorpicker/mini/ColorControl.js +40 -0
  40. package/src/colorpicker/mini/index.js +24 -0
  41. package/src/colorpicker/mini-vertical/ColorControl.js +35 -0
  42. package/src/colorpicker/mini-vertical/index.js +23 -0
  43. package/src/colorpicker/module/ColorManager.js +111 -0
  44. package/src/colorpicker/module/ColorSetsList.js +132 -0
  45. package/src/colorpicker/ring/ColorControl.js +47 -0
  46. package/src/colorpicker/ring/index.js +42 -0
  47. package/src/colorpicker/ui/ColorInformation.js +216 -0
  48. package/src/colorpicker/ui/ColorPalette.js +130 -0
  49. package/src/colorpicker/ui/ColorRing.js +68 -0
  50. package/src/colorpicker/ui/ColorSetsChooser.js +96 -0
  51. package/src/colorpicker/ui/ColorWheel.js +257 -0
  52. package/src/colorpicker/ui/CurrentColorSets.js +81 -0
  53. package/src/colorpicker/ui/CurrentColorSetsContextMenu.js +63 -0
  54. package/src/colorpicker/ui/control/Hue.js +40 -0
  55. package/src/colorpicker/ui/control/Opacity.js +65 -0
  56. package/src/colorpicker/ui/control/Value.js +50 -0
  57. package/src/colorpicker/ui/control/VerticalHue.js +39 -0
  58. package/src/colorpicker/ui/control/VerticalOpacity.js +55 -0
  59. package/src/colorpicker/vscode/ColorControl.js +40 -0
  60. package/src/colorpicker/vscode/index.js +82 -0
  61. package/src/colorpicker/xd/ColorControl.js +36 -0
  62. package/src/colorpicker/xd/index.js +36 -0
  63. package/src/extension/ace/colorview.js +198 -0
  64. package/src/extension/ace/index.js +11 -0
  65. package/src/index.js +12 -0
  66. package/src/scss/colorpicker.scss +65 -0
  67. package/src/scss/colorview.scss +32 -0
  68. package/src/scss/component/button.scss +33 -0
  69. package/src/scss/component/colorchooser.scss +141 -0
  70. package/src/scss/component/colorsets-contextmenu.scss +33 -0
  71. package/src/scss/component/colorsets.scss +89 -0
  72. package/src/scss/component/control.scss +93 -0
  73. package/src/scss/component/gradient-editor.scss +260 -0
  74. package/src/scss/component/gradient-picker.scss +241 -0
  75. package/src/scss/component/information.scss +141 -0
  76. package/src/scss/component/palette.scss +45 -0
  77. package/src/scss/index.scss +5 -0
  78. package/src/scss/mixins.scss +21 -0
  79. package/src/scss/themes/macos.scss +71 -0
  80. package/src/scss/themes/mini-vertical.scss +94 -0
  81. package/src/scss/themes/mini.scss +76 -0
  82. package/src/scss/themes/palette.scss +85 -0
  83. package/src/scss/themes/ring.scss +57 -0
  84. package/src/scss/themes/sketch.scss +172 -0
  85. package/src/scss/themes/vscode.scss +93 -0
  86. package/src/scss/themes/xd.scss +88 -0
  87. package/src/util/Blender.js +29 -0
  88. package/src/util/Canvas.js +128 -0
  89. package/src/util/Color.js +27 -0
  90. package/src/util/ColorNames.js +14 -0
  91. package/src/util/Dom.js +361 -0
  92. package/src/util/Event.js +30 -0
  93. package/src/util/EventMachin.js +349 -0
  94. package/src/util/GL.js +8 -0
  95. package/src/util/HueColor.js +49 -0
  96. package/src/util/ImageFilter.js +9 -0
  97. package/src/util/ImageLoader.js +137 -0
  98. package/src/util/Kmeans.js +237 -0
  99. package/src/util/Matrix.js +196 -0
  100. package/src/util/State.js +42 -0
  101. package/src/util/blend/composite.js +124 -0
  102. package/src/util/blend/non-separable.js +118 -0
  103. package/src/util/blend/separable.js +76 -0
  104. package/src/util/filter/StackBlur.js +517 -0
  105. package/src/util/filter/functions.js +829 -0
  106. package/src/util/filter/image/crop.js +16 -0
  107. package/src/util/filter/image/flipH.js +23 -0
  108. package/src/util/filter/image/flipV.js +25 -0
  109. package/src/util/filter/image/histogram.js +45 -0
  110. package/src/util/filter/image/index.js +18 -0
  111. package/src/util/filter/image/resize.js +18 -0
  112. package/src/util/filter/image/rotate.js +39 -0
  113. package/src/util/filter/image/rotateDegree.js +53 -0
  114. package/src/util/filter/index.js +11 -0
  115. package/src/util/filter/matrix/blur.js +12 -0
  116. package/src/util/filter/matrix/emboss.js +17 -0
  117. package/src/util/filter/matrix/gaussian-blur-5x.js +17 -0
  118. package/src/util/filter/matrix/gaussian-blur.js +16 -0
  119. package/src/util/filter/matrix/grayscale2.js +16 -0
  120. package/src/util/filter/matrix/index.js +58 -0
  121. package/src/util/filter/matrix/kirsch-horizontal.js +13 -0
  122. package/src/util/filter/matrix/kirsch-vertical.js +13 -0
  123. package/src/util/filter/matrix/laplacian-5x.js +16 -0
  124. package/src/util/filter/matrix/laplacian.js +14 -0
  125. package/src/util/filter/matrix/motion-blur-2.js +18 -0
  126. package/src/util/filter/matrix/motion-blur-3.js +19 -0
  127. package/src/util/filter/matrix/motion-blur.js +18 -0
  128. package/src/util/filter/matrix/negative.js +16 -0
  129. package/src/util/filter/matrix/normal.js +11 -0
  130. package/src/util/filter/matrix/sepia2.js +16 -0
  131. package/src/util/filter/matrix/sharpen.js +14 -0
  132. package/src/util/filter/matrix/sobel-horizontal.js +11 -0
  133. package/src/util/filter/matrix/sobel-vertical.js +11 -0
  134. package/src/util/filter/matrix/stack-blur.js +15 -0
  135. package/src/util/filter/matrix/transparency.js +16 -0
  136. package/src/util/filter/matrix/unsharp-masking.js +16 -0
  137. package/src/util/filter/multi/index.js +9 -0
  138. package/src/util/filter/multi/kirsch.js +7 -0
  139. package/src/util/filter/multi/sobel.js +7 -0
  140. package/src/util/filter/multi/vintage.js +7 -0
  141. package/src/util/filter/pixel/bitonal.js +24 -0
  142. package/src/util/filter/pixel/brightness.js +19 -0
  143. package/src/util/filter/pixel/brownie.js +23 -0
  144. package/src/util/filter/pixel/clip.js +21 -0
  145. package/src/util/filter/pixel/contrast.js +18 -0
  146. package/src/util/filter/pixel/gamma.js +13 -0
  147. package/src/util/filter/pixel/gradient.js +52 -0
  148. package/src/util/filter/pixel/grayscale.js +27 -0
  149. package/src/util/filter/pixel/hue.js +28 -0
  150. package/src/util/filter/pixel/index.js +52 -0
  151. package/src/util/filter/pixel/invert.js +16 -0
  152. package/src/util/filter/pixel/kodachrome.js +23 -0
  153. package/src/util/filter/pixel/matrix.js +28 -0
  154. package/src/util/filter/pixel/noise.js +24 -0
  155. package/src/util/filter/pixel/opacity.js +14 -0
  156. package/src/util/filter/pixel/polaroid.js +23 -0
  157. package/src/util/filter/pixel/saturation.js +30 -0
  158. package/src/util/filter/pixel/sepia.js +28 -0
  159. package/src/util/filter/pixel/shade.js +21 -0
  160. package/src/util/filter/pixel/shift.js +23 -0
  161. package/src/util/filter/pixel/solarize.js +23 -0
  162. package/src/util/filter/pixel/technicolor.js +23 -0
  163. package/src/util/filter/pixel/threshold-color.js +35 -0
  164. package/src/util/filter/pixel/threshold.js +7 -0
  165. package/src/util/filter/pixel/tint.js +20 -0
  166. package/src/util/functions/formatter.js +99 -0
  167. package/src/util/functions/fromCMYK.js +17 -0
  168. package/src/util/functions/fromHSL.js +52 -0
  169. package/src/util/functions/fromHSV.js +64 -0
  170. package/src/util/functions/fromLAB.js +99 -0
  171. package/src/util/functions/fromRGB.js +220 -0
  172. package/src/util/functions/fromYCrCb.js +16 -0
  173. package/src/util/functions/func.js +194 -0
  174. package/src/util/functions/image.js +145 -0
  175. package/src/util/functions/math.js +56 -0
  176. package/src/util/functions/mixin.js +164 -0
  177. package/src/util/functions/parser.js +294 -0
  178. package/src/util/gl/filter/index.js +9 -0
  179. package/src/util/gl/filter/matrix/blur.js +9 -0
  180. package/src/util/gl/filter/matrix/emboss.js +17 -0
  181. package/src/util/gl/filter/matrix/gaussian-blur-5x.js +15 -0
  182. package/src/util/gl/filter/matrix/gaussian-blur.js +19 -0
  183. package/src/util/gl/filter/matrix/grayscale2.js +13 -0
  184. package/src/util/gl/filter/matrix/index.js +55 -0
  185. package/src/util/gl/filter/matrix/kirsch-horizontal.js +11 -0
  186. package/src/util/gl/filter/matrix/kirsch-vertical.js +11 -0
  187. package/src/util/gl/filter/matrix/laplacian-5x.js +13 -0
  188. package/src/util/gl/filter/matrix/laplacian.js +11 -0
  189. package/src/util/gl/filter/matrix/motion-blur-2.js +17 -0
  190. package/src/util/gl/filter/matrix/motion-blur-3.js +17 -0
  191. package/src/util/gl/filter/matrix/motion-blur.js +17 -0
  192. package/src/util/gl/filter/matrix/negative.js +13 -0
  193. package/src/util/gl/filter/matrix/normal.js +8 -0
  194. package/src/util/gl/filter/matrix/sepia2.js +13 -0
  195. package/src/util/gl/filter/matrix/sharpen.js +11 -0
  196. package/src/util/gl/filter/matrix/sobel-horizontal.js +11 -0
  197. package/src/util/gl/filter/matrix/sobel-vertical.js +11 -0
  198. package/src/util/gl/filter/matrix/transparency.js +13 -0
  199. package/src/util/gl/filter/matrix/unsharp-masking.js +14 -0
  200. package/src/util/gl/filter/multi/index.js +9 -0
  201. package/src/util/gl/filter/multi/kirsch.js +7 -0
  202. package/src/util/gl/filter/multi/sobel.js +7 -0
  203. package/src/util/gl/filter/multi/vintage.js +7 -0
  204. package/src/util/gl/filter/pixel/bitonal.js +22 -0
  205. package/src/util/gl/filter/pixel/brightness.js +14 -0
  206. package/src/util/gl/filter/pixel/brownie.js +11 -0
  207. package/src/util/gl/filter/pixel/chaos.js +20 -0
  208. package/src/util/gl/filter/pixel/clip.js +20 -0
  209. package/src/util/gl/filter/pixel/contrast.js +16 -0
  210. package/src/util/gl/filter/pixel/gamma.js +16 -0
  211. package/src/util/gl/filter/pixel/gradient.js +59 -0
  212. package/src/util/gl/filter/pixel/grayscale.js +22 -0
  213. package/src/util/gl/filter/pixel/hue.js +19 -0
  214. package/src/util/gl/filter/pixel/index.js +54 -0
  215. package/src/util/gl/filter/pixel/invert.js +18 -0
  216. package/src/util/gl/filter/pixel/kodachrome.js +11 -0
  217. package/src/util/gl/filter/pixel/matrix.js +29 -0
  218. package/src/util/gl/filter/pixel/noise.js +18 -0
  219. package/src/util/gl/filter/pixel/opacity.js +17 -0
  220. package/src/util/gl/filter/pixel/polaroid.js +11 -0
  221. package/src/util/gl/filter/pixel/saturation.js +20 -0
  222. package/src/util/gl/filter/pixel/sepia.js +19 -0
  223. package/src/util/gl/filter/pixel/shade.js +20 -0
  224. package/src/util/gl/filter/pixel/shift.js +11 -0
  225. package/src/util/gl/filter/pixel/solarize.js +21 -0
  226. package/src/util/gl/filter/pixel/technicolor.js +11 -0
  227. package/src/util/gl/filter/pixel/threshold-color.js +15 -0
  228. package/src/util/gl/filter/pixel/threshold.js +7 -0
  229. package/src/util/gl/filter/pixel/tint.js +25 -0
  230. package/src/util/gl/filter/util.js +185 -0
  231. package/src/util/gl/functions.js +158 -0
  232. package/src/util/gl/index.js +543 -0
  233. package/src/util/index.js +17 -0
  234. package/stand.html +975 -0
  235. package/test/util.Blend.spec.js +15 -0
  236. package/test/util.Color.spec.js +200 -0
  237. package/test/util.Filter.spec.js +12 -0
  238. package/test/util.ImageFilter.spec.js +16 -0
@@ -0,0 +1,237 @@
1
+ function array_equals(v1, v2) {
2
+ if (v1.length !== v2.length) return false;
3
+ for (var i = 0, len = v1.length; i < len; ++i) {
4
+ if (v1[i] !== v2[i]) return false;
5
+ }
6
+ return true;
7
+ }
8
+
9
+ function euclidean(v1, v2) {
10
+ var total = 0;
11
+
12
+ for (var i = 0, len = v1.length; i < len; i++) {
13
+ total += Math.pow(v2[i] - v1[i], 2);
14
+ }
15
+
16
+ return Math.sqrt(total);
17
+ }
18
+
19
+ function manhattan(v1, v2) {
20
+ var total = 0;
21
+
22
+ for (var i = 0, len = v1.length; i < len; i++) {
23
+ total += Math.abs(v2[i] - v1[i]);
24
+ }
25
+
26
+ return total;
27
+ }
28
+
29
+ function max(v1, v2) {
30
+ var max = 0;
31
+ for (var i = 0, len = v1.length; i < len; i++) {
32
+ max = Math.max(max, Math.abs(v2[i] - v1[i]));
33
+ }
34
+
35
+ return max;
36
+ }
37
+
38
+
39
+
40
+ const distances = {
41
+ euclidean,
42
+ manhattan,
43
+ max
44
+ }
45
+
46
+ const create_random_number = {
47
+ linear: function (num, count) {
48
+ var centeroids = [];
49
+ var start = Math.round(Math.random() * num);
50
+ var dist = Math.floor(num / count);
51
+
52
+ do {
53
+
54
+ centeroids.push(start);
55
+
56
+ start = (start + dist) % num;
57
+
58
+ } while (centeroids.length < count);
59
+
60
+
61
+ return centeroids;
62
+ },
63
+
64
+ shuffle: function (num, count) {
65
+ var centeroids = [];
66
+
67
+ while (centeroids.length < count) {
68
+
69
+ var index = Math.round(Math.random() * num);
70
+
71
+ if (centeroids.indexOf(index) == -1) {
72
+ centeroids.push(index);
73
+ }
74
+
75
+ }
76
+
77
+ return centeroids;
78
+ }
79
+
80
+
81
+ }
82
+
83
+ function randomCentroids(points, k, method = 'linear') {
84
+
85
+ var centeroids = create_random_number[method](points.length, k);
86
+
87
+
88
+
89
+ return centeroids.map(i => {
90
+ return points[i];
91
+ })
92
+
93
+ // var centeroids = points.slice(0);
94
+
95
+ // centeroids.sort(function () {
96
+ // return (Math.round(Math.random()) - 0.5);
97
+ // })
98
+
99
+ // return centeroids.slice(0, k);
100
+ }
101
+
102
+ function closestCenteroid(point, centeroids, distance) {
103
+ var min = Infinity, kIndex = 0;
104
+
105
+ centeroids.forEach((center, i) => {
106
+ var dist = distance(point, center);
107
+
108
+ if (dist < min) {
109
+ min = dist;
110
+ kIndex = i;
111
+ }
112
+ })
113
+
114
+ return kIndex;
115
+ }
116
+
117
+ function getCenteroid(assigned) {
118
+
119
+ if (!assigned.length) return [];
120
+
121
+ // initialize centeroid list
122
+ let centeroid = new Array(assigned[0].length);
123
+ for (var i = 0, len = centeroid.length; i < len; i++) {
124
+ centeroid[i] = 0;
125
+ }
126
+
127
+ for (var index = 0, len = assigned.length; index < len; index++) {
128
+ var it = assigned[index];
129
+
130
+ var last = (index + 1);
131
+
132
+ for (var j = 0, jLen = it.length; j < jLen; j++) {
133
+ centeroid[j] += (it[j] - centeroid[j]) / last;
134
+ }
135
+ }
136
+
137
+ centeroid = centeroid.map(it => {
138
+ return Math.floor(it);
139
+ })
140
+
141
+ return centeroid;
142
+ }
143
+
144
+ function unique_array(arrays) {
145
+ return arrays;
146
+ var set = {};
147
+ var count = arrays.length;
148
+ let it = null;
149
+ while (count--) {
150
+ it = arrays[count];
151
+ set[JSON.stringify(it)] = it;
152
+ }
153
+
154
+ return Object.values(set);
155
+ }
156
+
157
+ function splitK(k, points, centeroids, distance) {
158
+ let assignment = new Array(k);
159
+
160
+ for (var i = 0; i < k; i++) {
161
+ assignment[i] = [];
162
+ }
163
+
164
+ for (var idx = 0, pointLength = points.length; idx < pointLength; idx++) {
165
+ var point = points[idx];
166
+ var index = closestCenteroid(point, centeroids, distance);
167
+ assignment[index].push(point);
168
+ }
169
+
170
+ return assignment;
171
+ }
172
+
173
+ function setNewCenteroid(k, points, assignment, centeroids, movement, randomFunction) {
174
+
175
+
176
+ for (var i = 0; i < k; i++) {
177
+ let assigned = assignment[i];
178
+
179
+ const centeroid = centeroids[i];
180
+ let newCenteroid = new Array(centeroid.length);
181
+
182
+ if (assigned.length > 0) {
183
+ newCenteroid = getCenteroid(assigned);
184
+ } else {
185
+ var idx = Math.floor(randomFunction() * points.length);
186
+ newCenteroid = points[idx];
187
+ }
188
+
189
+ if (array_equals(newCenteroid, centeroid)) {
190
+ movement = false;
191
+ } else {
192
+ movement = true;
193
+ }
194
+
195
+ centeroids[i] = newCenteroid;
196
+ }
197
+
198
+ return movement;
199
+ }
200
+
201
+ function kmeans(points, k, distanceFunction, period = 10, initialRandom = 'linear') {
202
+ points = unique_array(points);
203
+
204
+ k = k || Math.max(2, Math.ceil(Math.sqrt(points.length / 2)));
205
+
206
+ let distance = distanceFunction || 'euclidean';
207
+ if (typeof distance == 'string') {
208
+ distance = distances[distance];
209
+ }
210
+
211
+ var rng_seed = 0;
212
+ var random = function () {
213
+ rng_seed = (rng_seed * 9301 + 49297) % 233280;
214
+ return rng_seed / 233280;
215
+ };
216
+
217
+ let centeroids = randomCentroids(points, k, initialRandom);
218
+
219
+ let movement = true;
220
+ let iterations = 0;
221
+ while (movement) {
222
+ const assignment = splitK(k, points, centeroids, distance);
223
+
224
+ movement = setNewCenteroid(k, points, assignment, centeroids, false, random);
225
+
226
+ iterations++;
227
+
228
+ if (iterations % period == 0) {
229
+ break;
230
+ }
231
+
232
+ }
233
+
234
+ return centeroids;
235
+ }
236
+
237
+ export default kmeans
@@ -0,0 +1,196 @@
1
+ const CONSTANT = {
2
+
3
+ identity () {
4
+ return [
5
+ 1, 0, 0,
6
+ 0, 1, 0,
7
+ 0, 0, 1
8
+ ]
9
+ },
10
+
11
+ stretching (k) {
12
+ return [
13
+ k, 0, 0,
14
+ 0, 1, 0,
15
+ 0, 0, 1
16
+ ]
17
+ },
18
+
19
+ squeezing (k) {
20
+ return [
21
+ k, 0, 0,
22
+ 0, 1/k, 0,
23
+ 0, 0, 1
24
+ ]
25
+ },
26
+
27
+ scale (sx = 1, sy = 1) {
28
+ sx = sx || sx === 0 ? sx : 1;
29
+ sy = sy || sy === 0 ? sy : 1;
30
+ return [
31
+ sx, 0, 0,
32
+ 0, sy, 0,
33
+ 0, 0, 1
34
+ ]
35
+ },
36
+
37
+ scaleX (sx) {
38
+ return this.scale(sx)
39
+ },
40
+
41
+ scaleY (sy) {
42
+ return this.scale(1, sy)
43
+ },
44
+
45
+ translate (tx, ty) {
46
+ return [
47
+ 1, 0, tx,
48
+ 0, 1, ty,
49
+ 0, 0, 1
50
+ ]
51
+ },
52
+
53
+ rotate (angle){
54
+ const r = this.radian(angle)
55
+ return [
56
+ Math.cos(r), -Math.sin(r), 0,
57
+ Math.sin(r), Math.cos(r), 0,
58
+ 0, 0, 1
59
+ ]
60
+ },
61
+
62
+ rotate90 () {
63
+ return [
64
+ 0, -1, 0,
65
+ 1, 0, 0,
66
+ 0, 0, 1
67
+ ]
68
+ },
69
+
70
+ rotate180 () {
71
+ return [
72
+ -1, 0, 0,
73
+ 0, -1, 0,
74
+ 0, 0, 1
75
+ ]
76
+ },
77
+
78
+ rotate270 () {
79
+ return [
80
+ 0, 1, 0,
81
+ -1, 0, 0,
82
+ 0, 0, 1
83
+ ]
84
+ },
85
+
86
+ radian (degree) {
87
+ return degree * Math.PI / 180
88
+ },
89
+
90
+ skew (degreeX, degreeY) {
91
+ const radianX = this.radian(degreeX);
92
+ const radianY = this.radian(degreeY);
93
+ return [
94
+ 1, Math.tan(radianX), 0,
95
+ Math.tan(radianY), 1, 0,
96
+ 0, 0, 1
97
+ ]
98
+ },
99
+
100
+ skewX (degreeX) {
101
+ const radianX = this.radian(degreeX);
102
+
103
+ return [
104
+ 1, Math.tan(radianX), 0,
105
+ 0, 1, 0,
106
+ 0, 0, 1
107
+ ]
108
+ },
109
+
110
+ skewY (degreeY) {
111
+ const radianY = this.radian(degreeY);
112
+
113
+ return [
114
+ 1, 0, 0,
115
+ Math.tan(radianY), 1, 0,
116
+ 0, 0, 1
117
+ ]
118
+ },
119
+
120
+ shear1 (angle) {
121
+ return [
122
+ 1, -Math.tan(this.radian(angle)/2), 0,
123
+ 0, 1, 0,
124
+ 0, 0, 1
125
+ ]
126
+ },
127
+ shear2 (angle) {
128
+ return [
129
+ 1, 0, 0,
130
+ Math.sin(this.radian(angle)), 1, 0,
131
+ 0, 0, 1
132
+ ]
133
+ }
134
+ }
135
+
136
+ const Matrix = {
137
+ CONSTANT,
138
+
139
+ radian (angle) {
140
+ return CONSTANT.radian(angle)
141
+ },
142
+
143
+ multiply (A, C) {
144
+ // console.log(JSON.stringify(A), JSON.stringify(C))
145
+ return [
146
+ A[0] * C[0] + A[1] * C[1] + A[2] * C[2],
147
+ A[3] * C[0] + A[4] * C[1] + A[5] * C[2],
148
+ A[6] * C[0] + A[7] * C[1] + A[8] * C[2]
149
+ ]
150
+ },
151
+
152
+ identity (B) {
153
+ return this.multiply(CONSTANT.identity(), B)
154
+ },
155
+
156
+ translate (x, y, B) {
157
+ return this.multiply(
158
+ CONSTANT.translate(x, y),
159
+ B
160
+ )
161
+ },
162
+
163
+ rotate (angle, B) {
164
+ return this.multiply(
165
+ CONSTANT.rotate(angle),
166
+ B
167
+ )
168
+ },
169
+
170
+ shear1 (angle, B) {
171
+ return this.multiply(
172
+ CONSTANT.shear1(angle),
173
+ B
174
+ )
175
+ },
176
+
177
+ shear2 (angle, B) {
178
+ return this.multiply(
179
+ CONSTANT.shear2(angle),
180
+ B
181
+ )
182
+ },
183
+
184
+ rotateShear(angle, B) {
185
+
186
+ let arr = B
187
+
188
+ arr = this.shear1(angle, arr)
189
+ arr = this.shear2(angle, arr)
190
+ arr = this.shear1(angle, arr)
191
+
192
+ return arr
193
+ }
194
+ }
195
+
196
+ export default Matrix
@@ -0,0 +1,42 @@
1
+ const DELEGATE_SPLIT = '.';
2
+
3
+ export default class State {
4
+ constructor (masterObj, settingObj = {}) {
5
+
6
+ this.masterObj = masterObj;
7
+ this.settingObj = settingObj;
8
+ }
9
+
10
+ set (key, value, defaultValue = undefined) {
11
+ this.settingObj[key] = value || defaultValue;
12
+ }
13
+
14
+ init (key, ...args) {
15
+
16
+ if (!this.has(key)) {
17
+
18
+ const arr = key.split(DELEGATE_SPLIT);
19
+
20
+ const obj = this.masterObj.refs[arr[0]] || this.masterObj[arr[0]] || this.masterObj;
21
+ const method = arr.pop();
22
+
23
+ if (obj[method]) {
24
+ const value = obj[method].apply(obj, args);
25
+
26
+ this.set(key, value);
27
+ }
28
+
29
+ }
30
+ }
31
+
32
+ get (key, defaultValue = '') {
33
+
34
+ this.init(key, defaultValue);
35
+
36
+ return this.settingObj[key] || defaultValue;
37
+ }
38
+
39
+ has (key) {
40
+ return !!this.settingObj[key];
41
+ }
42
+ }
@@ -0,0 +1,124 @@
1
+ const modes = {
2
+ 'clear' : {
3
+ alpha () { return 0; },
4
+ color () { return 0; }
5
+ },
6
+ 'copy' : {
7
+ alpha (Ab, As) {
8
+ return As;
9
+ },
10
+ color (Ab, As, Cb, Cs) {
11
+ return As * Cs;
12
+ }
13
+ },
14
+ 'destination' : {
15
+ alpha (Ab, As) {
16
+ return Ab;
17
+ },
18
+ color (Ab, As, Cb, Cs) {
19
+ return Ab * Cb;
20
+ }
21
+ },
22
+ 'source-over' : {
23
+ alpha (Ab, As) {
24
+ return As + Ab * ( 1 - As);
25
+ },
26
+ color (Ab, As, Cb, Cs) {
27
+ return As * Cs + Ab * Cb * (1 - As);
28
+ }
29
+ },
30
+ 'destination-over' : {
31
+ alpha (Ab, As) {
32
+ return As * (1 - Ab) + Ab;
33
+ },
34
+ color (Ab, As, Cb, Cs) {
35
+ return As * Cs * (1 - Ab) + Ab * Cb;
36
+ }
37
+ },
38
+ 'source-in' : {
39
+ alpha (Ab, As) {
40
+ return As * Ab;
41
+ },
42
+ color (Ab, As, Cb, Cs) {
43
+ return As * Cs * Ab;
44
+ }
45
+ },
46
+ 'destination-in' : {
47
+ alpha (Ab, As) {
48
+ return As * Ab;
49
+ },
50
+ color (Ab, As, Cb, Cs) {
51
+ return As * Cb * Ab;
52
+ }
53
+ },
54
+ 'source-out' : {
55
+ alpha (Ab, As) {
56
+ return As * (1 - Ab);
57
+ },
58
+ color (Ab, As, Cb, Cs) {
59
+ return As * Cs * (1 - Ab);
60
+ }
61
+ },
62
+ 'destination-out' : {
63
+ alpha (Ab, As) {
64
+ return Ab * (1 - As);
65
+ },
66
+ color (Ab, As, Cb, Cs) {
67
+ return Ab * Cb * (1 - As);
68
+ }
69
+ },
70
+ 'source-atop' : {
71
+ alpha (Ab, As) {
72
+ return As * Ab + Ab * (1 - As);
73
+ },
74
+ color (Ab, As, Cb, Cs) {
75
+ return As * Cs * Ab + Ab * Cb * (1 - As);
76
+ }
77
+ },
78
+ 'destination-atop' : {
79
+ alpha (Ab, As) {
80
+ return As * (1 - Ab) + Ab * As;
81
+ },
82
+ color (Ab, As, Cb, Cs) {
83
+ return As * Cs * (1 - Ab) + Ab * Cb * As;
84
+ }
85
+ },
86
+ 'xor' : {
87
+ alpha (Ab, As) {
88
+ return As * (1 - Ab) + Ab * (1 - As);
89
+ },
90
+ color (Ab, As, Cb, Cs) {
91
+ return As * Cs * (1 - Ab) + Ab * Cb * (1 - As);
92
+ }
93
+ },
94
+ 'lighter' : {
95
+ alpha (Ab, As) {
96
+ return As + Ab
97
+ },
98
+ color (Ab, As, Cb, Cs) {
99
+ return As * Cs + Ab * Cb;
100
+ }
101
+ }
102
+
103
+
104
+
105
+
106
+ }
107
+
108
+ function composite (back, source, mode) {
109
+ return {
110
+ r : modes[mode].color(back.a, source.a, back.r / 255, source.r / 255) * 255,
111
+ g : modes[mode].color(back.a, source.a, back.g / 255, source.g / 255) * 255,
112
+ b : modes[mode].color(back.a, source.a, back.b / 255, source.b / 255) * 255,
113
+ a : modes[mode].alpha(back.a, source.a)
114
+ }
115
+ }
116
+
117
+ // alias
118
+ Object.keys(modes).forEach(mode => {
119
+ composite[mode] = function (back, source) {
120
+ return composite(back, source, mode);
121
+ }
122
+ })
123
+
124
+ export default composite;
@@ -0,0 +1,118 @@
1
+ // refer to https://www.w3.org/TR/compositing-1
2
+
3
+ var util = {
4
+ lum ( color) {
5
+ return 0.3 * color.r + 0.59 * color.g + 0.11 * color.b;
6
+ },
7
+
8
+ clipColor(c) {
9
+ const l = this.lum(c)
10
+ const n = this.min(c)
11
+ const x = this.max(c)
12
+
13
+ let color = Object.assign({}, c);
14
+
15
+ if(n < 0) {
16
+ color.r = l + (((color.r - l) * l) / (l - n))
17
+ color.g = l + (((color.g - l) * l) / (l - n))
18
+ color.b = l + (((color.b - l) * l) / (l - n))
19
+ }
20
+
21
+
22
+ if(x > 1) {
23
+ color.r = l + (((color.r - l) * (1 - l)) / (x - l))
24
+ color.g = l + (((color.g - l) * (1 - l)) / (x - l))
25
+ color.b = l + (((color.b - l) * (1 - l)) / (x - l))
26
+ }
27
+
28
+ return color;
29
+ },
30
+ setLum(color, l) {
31
+ const d = l - this.lum(color)
32
+ const r = color.r + d;
33
+ const g = color.g + d;
34
+ const b = color.b + d;
35
+
36
+ return this.clipColor({r, g, b})
37
+ },
38
+
39
+ sat (color) {
40
+ return this.max(color) - this.min(color)
41
+ },
42
+
43
+ max (color) {
44
+ return Math.max(color.r, color.g, color.b);
45
+ },
46
+
47
+ min (color) {
48
+ return Math.min(color.r, color.g, color.b);
49
+ },
50
+
51
+ mid (color) {
52
+ return (color.r + color.g + color.b) - this.max(color) - this.min(color);
53
+ },
54
+
55
+ setSat(color, s) {
56
+ color.max = this.max(color);
57
+ color.min = this.min(color);
58
+ color.mid = this.mid(color);
59
+
60
+ if(color.max > color.min) {
61
+ color.mid = (((color.mid - color.min) * s) / (color.max - color.min))
62
+ color.max = s
63
+ } else {
64
+ color.mid = color.max = 0
65
+ }
66
+
67
+ color.min = 0
68
+
69
+ return color;
70
+ }
71
+ }
72
+
73
+ var modes = {
74
+ /* nonseparable mode */
75
+ hue (back, source) {
76
+ return util.setLum(util.setSat(source, util.sat(back)), util.lum(back))
77
+ },
78
+
79
+ saturation (back, source) {
80
+ return util.setLum(util.setSat(back, util.sat(source)), util.lum(back))
81
+ },
82
+
83
+ color (back, source) {
84
+ return util.setLum(source, util.lum(back));
85
+ },
86
+
87
+ luminosity (back, source) {
88
+ return util.setLum(back, util.lum(source))
89
+ }
90
+
91
+ }
92
+
93
+ function recover (c) {
94
+ c.r *= 255;
95
+ c.g *= 255;
96
+ c.b *= 255;
97
+ return c;
98
+ }
99
+
100
+ function minify (c) {
101
+ c.r /= 255;
102
+ c.g /= 255;
103
+ c.b /= 255;
104
+ return c;
105
+ }
106
+
107
+ function nonseparable (back, source, mode) {
108
+ return recover(modes[mode](minify(back), minify(source)));
109
+ }
110
+
111
+ // alias
112
+ Object.keys(modes).forEach(mode => {
113
+ nonseparable[mode] = function (back, source) {
114
+ return nonseparable(back, source, mode);
115
+ }
116
+ })
117
+
118
+ export default nonseparable;