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,99 @@
1
+
2
+ /**
3
+ * @method format
4
+ *
5
+ * convert color to format string
6
+ *
7
+ * // hex
8
+ * color.format({ r : 255, g : 255, b : 255, a: 1 }, 'hex') // #FFFFFFFF
9
+ *
10
+ * // rgb
11
+ * color.format({ r : 255, g : 255, b : 255 }, 'rgb') // rgba(255, 255, 255, 0.5);
12
+ *
13
+ * // rgba
14
+ * color.format({ r : 255, g : 255, b : 255, a : 0.5 }, 'rgb') // rgba(255, 255, 255, 0.5);
15
+ *
16
+ * @param {Object} obj obj has r, g, b and a attributes
17
+ * @param {"hex"/"rgb"} type format string type
18
+ * @returns {*}
19
+ */
20
+ export function format(obj, type, defaultColor = 'rgba(0, 0, 0, 0)') {
21
+
22
+ if (Array.isArray(obj)) {
23
+ obj = { r: obj[0], g: obj[1], b: obj[2], a: obj[3] }
24
+ }
25
+
26
+ if (type == 'hex') {
27
+ return hex(obj);
28
+ } else if (type == 'rgb') {
29
+ return rgb(obj, defaultColor);
30
+ } else if (type == 'hsl') {
31
+ return hsl(obj);
32
+ }
33
+
34
+ return obj;
35
+ }
36
+
37
+ export function hex(obj) {
38
+ if (Array.isArray(obj)) {
39
+ obj = { r: obj[0], g: obj[1], b: obj[2], a: obj[3] }
40
+ }
41
+
42
+ var r = obj.r.toString(16);
43
+ if (obj.r < 16) r = "0" + r;
44
+
45
+ var g = obj.g.toString(16);
46
+ if (obj.g < 16) g = "0" + g;
47
+
48
+ var b = obj.b.toString(16);
49
+ if (obj.b < 16) b = "0" + b;
50
+
51
+
52
+ var alphaValue = ''
53
+ if (obj.a < 1) {
54
+ var alpha = Math.floor(obj.a * 255)
55
+ var alphaValue = alpha.toString(16);
56
+ if (alpha < 16) alphaValue = "0" + alphaValue;
57
+ }
58
+
59
+ return `#${r}${g}${b}${alphaValue}`;
60
+ }
61
+
62
+ export function rgb (obj, defaultColor = 'rgba(0, 0, 0, 0)') {
63
+ if (Array.isArray(obj)) {
64
+ obj = { r: obj[0], g: obj[1], b: obj[2], a: obj[3] }
65
+ }
66
+
67
+ if (typeof obj == 'undefined') {
68
+ return undefined;
69
+ }
70
+
71
+ if (obj.a == 1 || typeof obj.a == 'undefined') {
72
+ if (isNaN(obj.r)) {
73
+ return defaultColor;
74
+ }
75
+ return `rgb(${obj.r},${obj.g},${obj.b})`;
76
+ } else {
77
+ return `rgba(${obj.r},${obj.g},${obj.b},${obj.a})`;
78
+ }
79
+ }
80
+
81
+ export function hsl (obj) {
82
+ if (Array.isArray(obj)) {
83
+ obj = { r: obj[0], g: obj[1], b: obj[2], a: obj[3] }
84
+ }
85
+
86
+ if (obj.a == 1 || typeof obj.a == 'undefined') {
87
+ return `hsl(${obj.h},${obj.s}%,${obj.l}%)`;
88
+ } else {
89
+ return `hsla(${obj.h},${obj.s}%,${obj.l}%,${obj.a})`;
90
+ }
91
+
92
+ }
93
+
94
+ export default {
95
+ format,
96
+ rgb,
97
+ hsl,
98
+ hex
99
+ };
@@ -0,0 +1,17 @@
1
+
2
+ export function CMYKtoRGB(c, m, y, k) {
3
+
4
+ if (arguments.length == 1) {
5
+ var { c, m, y, k } = arguments[0];
6
+ }
7
+
8
+ const R = 255 * (1 - c) * (1 - k);
9
+ const G = 255 * (1 - m) * (1 - k);
10
+ const B = 255 * (1 - y) * (1 - k);
11
+
12
+ return { r: R, g: G, b: B }
13
+ }
14
+
15
+ export default {
16
+ CMYKtoRGB
17
+ }
@@ -0,0 +1,52 @@
1
+ import { RGBtoHSV } from './fromRGB'
2
+ import { round } from './math'
3
+
4
+ export function HUEtoRGB(p, q, t) {
5
+ if (t < 0) t += 1;
6
+ if (t > 1) t -= 1;
7
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
8
+ if (t < 1 / 2) return q;
9
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
10
+ return p;
11
+ }
12
+
13
+ export function HSLtoHSV(h, s, l) {
14
+
15
+ if (arguments.length == 1) {
16
+ var { h, s, l } = arguments[0];
17
+ }
18
+ const rgb = HSLtoRGB(h, s, l);
19
+
20
+ return RGBtoHSV(rgb.r, rgb.g, rgb.b);
21
+ }
22
+
23
+ export function HSLtoRGB(h, s, l) {
24
+
25
+ if (arguments.length == 1) {
26
+ var { h, s, l } = arguments[0];
27
+ }
28
+
29
+ var r, g, b;
30
+
31
+ h /= 360;
32
+ s /= 100;
33
+ l /= 100;
34
+
35
+ if (s == 0) {
36
+ r = g = b = l; // achromatic
37
+ } else {
38
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
39
+ var p = 2 * l - q;
40
+ r = HUEtoRGB(p, q, h + 1 / 3);
41
+ g = HUEtoRGB(p, q, h);
42
+ b = HUEtoRGB(p, q, h - 1 / 3);
43
+ }
44
+
45
+ return { r: round(r * 255), g: round(g * 255), b: round(b * 255) };
46
+ }
47
+
48
+ export default {
49
+ HUEtoRGB,
50
+ HSLtoHSV,
51
+ HSLtoRGB
52
+ }
@@ -0,0 +1,64 @@
1
+ import { round } from './math'
2
+ import { RGBtoHSL } from './fromRGB'
3
+
4
+ /**
5
+ * @method HSVtoRGB
6
+ *
7
+ * convert hsv to rgb
8
+ *
9
+ * color.HSVtoRGB(0,0,1) === #FFFFF === { r : 255, g : 0, b : 0 }
10
+ *
11
+ * @param {Number} H hue color number (min : 0, max : 360)
12
+ * @param {Number} S Saturation number (min : 0, max : 1)
13
+ * @param {Number} V Value number (min : 0, max : 1 )
14
+ * @returns {Object}
15
+ */
16
+ export function HSVtoRGB(h, s, v) {
17
+
18
+ if (arguments.length == 1) {
19
+ var { h, s, v } = arguments[0];
20
+ }
21
+
22
+ var H = h;
23
+ var S = s;
24
+ var V = v;
25
+
26
+ if (H >= 360) {
27
+ H = 0;
28
+ }
29
+
30
+ const C = S * V;
31
+ const X = C * (1 - Math.abs((H / 60) % 2 - 1));
32
+ const m = V - C;
33
+
34
+ let temp = [];
35
+
36
+ if (0 <= H && H < 60) { temp = [C, X, 0]; }
37
+ else if (60 <= H && H < 120) { temp = [X, C, 0]; }
38
+ else if (120 <= H && H < 180) { temp = [0, C, X]; }
39
+ else if (180 <= H && H < 240) { temp = [0, X, C]; }
40
+ else if (240 <= H && H < 300) { temp = [X, 0, C]; }
41
+ else if (300 <= H && H < 360) { temp = [C, 0, X]; }
42
+
43
+ return {
44
+ r: round((temp[0] + m) * 255),
45
+ g: round((temp[1] + m) * 255),
46
+ b: round((temp[2] + m) * 255)
47
+ };
48
+ }
49
+
50
+ export function HSVtoHSL(h, s, v) {
51
+
52
+ if (arguments.length == 1) {
53
+ var { h, s, v } = arguments[0];
54
+ }
55
+
56
+ const rgb = HSVtoRGB(h, s, v);
57
+
58
+ return RGBtoHSL(rgb.r, rgb.g, rgb.b);
59
+ }
60
+
61
+ export default {
62
+ HSVtoHSL,
63
+ HSVtoRGB
64
+ }
@@ -0,0 +1,99 @@
1
+ import { round } from './math'
2
+
3
+ export function ReverseXyz(n) {
4
+ return (Math.pow(n, 3) > 0.008856) ? Math.pow(n, 3) : (n - 16 / 116) / 7.787;
5
+ }
6
+
7
+ export function ReverseRGB(n) {
8
+ return (n > 0.0031308) ? 1.055 * (Math.pow(n, (1 / 2.4))) - 0.055 : 12.92 * n;
9
+ }
10
+
11
+ export function XYZtoRGB(x, y, z) {
12
+ if (arguments.length == 1) {
13
+ var { x, y, z } = arguments[0];
14
+ }
15
+ //X, Y and Z input refer to a D65/2° standard illuminant.
16
+ //sR, sG and sB (standard RGB) output range = 0 ÷ 255
17
+
18
+ let X = x / 100.0
19
+ let Y = y / 100.0
20
+ let Z = z / 100.0
21
+
22
+ let R = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
23
+ let G = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
24
+ let B = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
25
+
26
+ R = ReverseRGB(R);
27
+ G = ReverseRGB(G);
28
+ B = ReverseRGB(B);
29
+
30
+ const r = round(R * 255);
31
+ const g = round(G * 255);
32
+ const b = round(B * 255);
33
+
34
+ return { r, g, b };
35
+ }
36
+
37
+ export function LABtoXYZ(l, a, b) {
38
+ if (arguments.length == 1) {
39
+ var { l, a, b } = arguments[0];
40
+ }
41
+ //Reference-X, Y and Z refer to specific illuminants and observers.
42
+ //Common reference values are available below in this same page.
43
+
44
+ let Y = (l + 16) / 116
45
+ let X = a / 500 + Y
46
+ let Z = Y - b / 200
47
+
48
+ Y = ReverseXyz(Y);
49
+ X = ReverseXyz(X);
50
+ Z = ReverseXyz(Z);
51
+
52
+ const x = X * 95.047
53
+ const y = Y * 100.000
54
+ const z = Z * 108.883
55
+
56
+ return { x, y, z };
57
+ }
58
+
59
+ export function PivotXyz(n) {
60
+ return (n > 0.008856) ? Math.pow(n, (1 / 3)) : (7.787 * n + 16) / 116;
61
+ }
62
+
63
+
64
+ export function XYZtoLAB(x, y, z) {
65
+ if (arguments.length == 1) {
66
+ var { x, y, z } = arguments[0];
67
+ }
68
+
69
+ //Reference-X, Y and Z refer to specific illuminants and observers.
70
+ //Common reference values are available below in this same page.
71
+ // Observer= 2°, Illuminant= D65
72
+
73
+ let X = x / 95.047;
74
+ let Y = y / 100.00;
75
+ let Z = z / 108.883;
76
+
77
+ X = PivotXyz(X);
78
+ Y = PivotXyz(Y);
79
+ Z = PivotXyz(Z);
80
+
81
+ const l = (116 * Y) - 16;
82
+ const a = 500 * (X - Y);
83
+ const b = 200 * (Y - Z);
84
+
85
+ return { l, a, b };
86
+ }
87
+
88
+ export function LABtoRGB(l, a, b) {
89
+ if (arguments.length == 1) {
90
+ var { l, a, b } = arguments[0];
91
+ }
92
+ return XYZtoRGB(LABtoXYZ(l, a, b));
93
+ }
94
+
95
+ export default {
96
+ XYZtoRGB,
97
+ LABtoRGB,
98
+ LABtoXYZ
99
+ }
@@ -0,0 +1,220 @@
1
+ import { round } from './math'
2
+ import { parse } from './parser';
3
+
4
+ /**
5
+ * @method RGBtoHSV
6
+ *
7
+ * convert rgb to hsv
8
+ *
9
+ * color.RGBtoHSV(0, 0, 255) === { h : 240, s : 1, v : 1 } === '#FFFF00'
10
+ *
11
+ * @param {Number} R red color value
12
+ * @param {Number} G green color value
13
+ * @param {Number} B blue color value
14
+ * @return {Object} hsv color code
15
+ */
16
+ export function RGBtoHSV(r, g, b) {
17
+
18
+ if (arguments.length == 1) {
19
+ var { r, g, b } = arguments[0];
20
+ }
21
+
22
+ const R1 = r / 255;
23
+ const G1 = g / 255;
24
+ const B1 = b / 255;
25
+
26
+ const MaxC = Math.max(R1, G1, B1);
27
+ const MinC = Math.min(R1, G1, B1);
28
+
29
+ const DeltaC = MaxC - MinC;
30
+
31
+ var H = 0;
32
+
33
+ if (DeltaC == 0) { H = 0; }
34
+ else if (MaxC == R1) {
35
+ H = 60 * (((G1 - B1) / DeltaC) % 6);
36
+ } else if (MaxC == G1) {
37
+ H = 60 * (((B1 - R1) / DeltaC) + 2);
38
+ } else if (MaxC == B1) {
39
+ H = 60 * (((R1 - G1) / DeltaC) + 4);
40
+ }
41
+
42
+ if (H < 0) {
43
+ H = 360 + H;
44
+ }
45
+
46
+ var S = 0;
47
+
48
+ if (MaxC == 0) S = 0;
49
+ else S = DeltaC / MaxC;
50
+
51
+ var V = MaxC;
52
+
53
+ return { h: H, s: S, v: V };
54
+ }
55
+
56
+
57
+ export function RGBtoCMYK(r, g, b) {
58
+
59
+ if (arguments.length == 1) {
60
+ var { r, g, b } = arguments[0];
61
+ }
62
+
63
+ const R1 = r / 255;
64
+ const G1 = g / 255;
65
+ const B1 = b / 255;
66
+
67
+ const K = 1 - Math.max(R1, G1, B1);
68
+ const C = (1 - R1 - K) / (1 - K);
69
+ const M = (1 - G1 - K) / (1 - K);
70
+ const Y = (1 - B1 - K) / (1 - K);
71
+
72
+ return { c: C, m: M, y: Y, k: K };
73
+ }
74
+
75
+
76
+ export function RGBtoHSL(r, g, b) {
77
+
78
+ if (arguments.length == 1) {
79
+ var { r, g, b } = arguments[0];
80
+ }
81
+
82
+ r /= 255, g /= 255, b /= 255;
83
+ var max = Math.max(r, g, b), min = Math.min(r, g, b);
84
+ var h, s, l = (max + min) / 2;
85
+
86
+ if (max == min) {
87
+ h = s = 0; // achromatic
88
+ } else {
89
+ var d = max - min;
90
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
91
+ switch (max) {
92
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
93
+ case g: h = (b - r) / d + 2; break;
94
+ case b: h = (r - g) / d + 4; break;
95
+ }
96
+ h /= 6;
97
+ }
98
+
99
+ return { h: round(h * 360), s: round(s * 100), l: round(l * 100) };
100
+ }
101
+
102
+ export function c(r, g, b) {
103
+
104
+ if (arguments.length == 1) {
105
+ var { r, g, b } = arguments[0];
106
+ }
107
+ return gray((r + g + b) / 3 > 90 ? 0 : 255);
108
+ }
109
+
110
+ export function gray(gray) {
111
+ return { r: gray, g: gray, b: gray };
112
+ }
113
+
114
+ export function RGBtoSimpleGray(r, g, b) {
115
+
116
+ if (arguments.length == 1) {
117
+ var { r, g, b } = arguments[0];
118
+ }
119
+ return gray(Math.ceil((r + g + b) / 3));
120
+ }
121
+
122
+
123
+ export function RGBtoGray(r, g, b) {
124
+
125
+ if (arguments.length == 1) {
126
+ var { r, g, b } = arguments[0];
127
+ }
128
+ return gray(RGBtoYCrCb(r, g, b).y);
129
+ }
130
+
131
+
132
+ export function brightness(r, g, b) {
133
+ return Math.ceil(r * 0.2126 + g * 0.7152 + b * 0.0722);
134
+ }
135
+
136
+ export const luminance = brightness;
137
+
138
+ export function relativeLuminance (r, g, b) {
139
+ let R = (r / 255)
140
+ let G = (g / 255)
141
+ let B = (b / 255)
142
+
143
+ R = PivotRGB(R, 0.03928);
144
+ G = PivotRGB(G, 0.03928);
145
+ B = PivotRGB(B, 0.03928);
146
+
147
+ return luminance(R, G, B);
148
+ }
149
+
150
+ export function contrastRatio (color1, color2) {
151
+ var c1 = parse(color1);
152
+ var c2 = parse(color2);
153
+
154
+ var L1 = relativeLuminance(c1.r, c1.g, c1.b);
155
+ var L2 = relativeLuminance(c2.r, c2.g, c2.b);
156
+
157
+ return (L1 + 0.05) / (L2 + 0.05)
158
+ }
159
+
160
+
161
+
162
+ export function RGBtoYCrCb(r, g, b) {
163
+
164
+ if (arguments.length == 1) {
165
+ var { r, g, b } = arguments[0];
166
+ }
167
+ const Y = brightness(r, g, b);
168
+ const Cb = 0.564 * (b - Y)
169
+ const Cr = 0.713 * (r - Y)
170
+
171
+ return { y: Y, cr: Cr, cb: Cb };
172
+ }
173
+
174
+ export function PivotRGB(n, point = 0.04045) {
175
+ return ((n > point) ? Math.pow((n + 0.055) / 1.055, 2.4) : n / 12.92) * 100;
176
+ }
177
+
178
+
179
+ export function RGBtoXYZ(r, g, b) {
180
+ //sR, sG and sB (Standard RGB) input range = 0 ÷ 255
181
+ //X, Y and Z output refer to a D65/2° standard illuminant.
182
+ if (arguments.length == 1) {
183
+ var { r, g, b } = arguments[0];
184
+ }
185
+
186
+ let R = (r / 255)
187
+ let G = (g / 255)
188
+ let B = (b / 255)
189
+
190
+ R = PivotRGB(R);
191
+ G = PivotRGB(G);
192
+ B = PivotRGB(B);
193
+
194
+ const x = R * 0.4124 + G * 0.3576 + B * 0.1805;
195
+ const y = R * 0.2126 + G * 0.7152 + B * 0.0722;
196
+ const z = R * 0.0193 + G * 0.1192 + B * 0.9505;
197
+
198
+ return { x, y, z }
199
+ }
200
+
201
+ export function RGBtoLAB(r, g, b) {
202
+ if (arguments.length == 1) {
203
+ var { r, g, b } = arguments[0];
204
+ }
205
+ return XYZtoLAB(RGBtoXYZ(r, g, b));
206
+ }
207
+
208
+ export default {
209
+ RGBtoCMYK,
210
+ RGBtoGray,
211
+ RGBtoHSL,
212
+ RGBtoHSV,
213
+ RGBtoLAB,
214
+ RGBtoSimpleGray,
215
+ RGBtoXYZ,
216
+ RGBtoYCrCb,
217
+ c,
218
+ brightness,
219
+ gray
220
+ }
@@ -0,0 +1,16 @@
1
+ export function YCrCbtoRGB(y, cr, cb, bit) {
2
+
3
+ if (arguments.length == 1) {
4
+ var { y, cr, cb, bit } = arguments[0];
5
+ bit = bit || 0;
6
+ }
7
+ const R = y + 1.402 * (cr - bit);
8
+ const G = y - 0.344 * (cb - bit) - 0.714 * (cr - bit);
9
+ const B = y + 1.772 * (cb - bit);
10
+
11
+ return { r: Math.ceil(R), g: Math.ceil(G), b: Math.ceil(B) }
12
+ }
13
+
14
+ export default {
15
+ YCrCbtoRGB
16
+ }