node-red-contrib-huemagic 2.8.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +229 -0
- package/README.md +806 -729
- package/examples/Hue Bridge.json +189 -35
- package/examples/Hue Brightness.json +124 -14
- package/examples/Hue Buttons.json +88 -0
- package/examples/Hue Group.json +575 -63
- package/examples/Hue Light.json +805 -58
- package/examples/Hue Magic.json +69 -24
- package/examples/Hue Motion.json +110 -42
- package/examples/Hue Rules.json +105 -37
- package/examples/Hue Scene.json +145 -28
- package/examples/Hue Temperature.json +124 -14
- package/huemagic/animations/001-sunny.json +22 -22
- package/huemagic/animations/002-cloudy.json +46 -46
- package/huemagic/animations/003-nightsky.json +20 -20
- package/huemagic/animations/004-sunrise.json +54 -54
- package/huemagic/animations/005-sunset.json +46 -46
- package/huemagic/animations/006-fireplace.json +74 -74
- package/huemagic/animations/007-spring.json +31 -31
- package/huemagic/animations/008-autmn.json +23 -23
- package/huemagic/animations/009-winter.json +23 -23
- package/huemagic/animations/010-dirtyfog.json +23 -23
- package/huemagic/animations/011-lgbt.json +49 -50
- package/huemagic/animations/012-rasta.json +28 -29
- package/huemagic/animations/013-strobo.json +30 -31
- package/huemagic/animations/014-randomrainbow.json +30 -31
- package/huemagic/animations/015-sos.json +158 -159
- package/huemagic/animations/016-milkyway.json +83 -0
- package/huemagic/animations/017-beach.json +40 -0
- package/huemagic/animations/018-forest.json +43 -0
- package/huemagic/animations/019-christmas.json +30 -0
- package/huemagic/animations/020-superhero.json +56 -0
- package/huemagic/animations/021-neoncity.json +52 -0
- package/huemagic/animations/previews/001-sunny.gif +0 -0
- package/huemagic/animations/previews/002-cloudy.gif +0 -0
- package/huemagic/animations/previews/003-nightsky.gif +0 -0
- package/huemagic/animations/previews/004-sunrise.gif +0 -0
- package/huemagic/animations/previews/005-sunset.gif +0 -0
- package/huemagic/animations/previews/006-fireplace.gif +0 -0
- package/huemagic/animations/previews/007-spring.gif +0 -0
- package/huemagic/animations/previews/008-autmn.gif +0 -0
- package/huemagic/animations/previews/009-winter.gif +0 -0
- package/huemagic/animations/previews/010-dirtyfog.gif +0 -0
- package/huemagic/animations/previews/011-lgbt.gif +0 -0
- package/huemagic/animations/previews/012-rasta.gif +0 -0
- package/huemagic/animations/previews/013-strobo.gif +0 -0
- package/huemagic/animations/previews/014-randomrainbow.gif +0 -0
- package/huemagic/animations/previews/015-sos.gif +0 -0
- package/huemagic/animations/previews/016-milkyway.gif +0 -0
- package/huemagic/animations/previews/017-beach.gif +0 -0
- package/huemagic/animations/previews/018-forest.gif +0 -0
- package/huemagic/animations/previews/019-christmas.gif +0 -0
- package/huemagic/animations/previews/020-superhero.gif +0 -0
- package/huemagic/animations/previews/021-neoncity.gif +0 -0
- package/huemagic/hue-bridge-config.html +105 -61
- package/huemagic/hue-bridge-config.js +629 -319
- package/huemagic/hue-bridge.html +41 -21
- package/huemagic/hue-bridge.js +191 -398
- package/huemagic/hue-brightness.html +130 -49
- package/huemagic/hue-brightness.js +131 -35
- package/huemagic/hue-buttons.html +197 -0
- package/huemagic/hue-buttons.js +152 -0
- package/huemagic/hue-group.html +137 -60
- package/huemagic/hue-group.js +394 -367
- package/huemagic/hue-light.html +133 -59
- package/huemagic/hue-light.js +551 -336
- package/huemagic/hue-magic.html +91 -237
- package/huemagic/hue-magic.js +57 -27
- package/huemagic/hue-motion.html +128 -50
- package/huemagic/hue-motion.js +116 -87
- package/huemagic/hue-rules.html +121 -50
- package/huemagic/hue-rules.js +84 -64
- package/huemagic/hue-scene.html +96 -115
- package/huemagic/hue-scene.js +65 -96
- package/huemagic/hue-temperature.html +130 -49
- package/huemagic/hue-temperature.js +136 -32
- package/huemagic/icons/hue-bridge.png +0 -0
- package/huemagic/icons/hue-bridge.svg +3 -0
- package/huemagic/icons/hue-brightness.png +0 -0
- package/huemagic/icons/hue-brightness.svg +11 -0
- package/huemagic/icons/hue-buttons.png +0 -0
- package/huemagic/icons/hue-buttons.svg +4 -0
- package/huemagic/icons/hue-group.png +0 -0
- package/huemagic/icons/hue-group.svg +12 -0
- package/huemagic/icons/hue-light.png +0 -0
- package/huemagic/icons/hue-light.svg +3 -0
- package/huemagic/icons/hue-magic.png +0 -0
- package/huemagic/icons/hue-magic.svg +3 -0
- package/huemagic/icons/hue-motion.png +0 -0
- package/huemagic/icons/hue-motion.svg +9 -0
- package/huemagic/icons/hue-rules.png +0 -0
- package/huemagic/icons/hue-rules.svg +4 -0
- package/huemagic/icons/hue-scene.png +0 -0
- package/huemagic/icons/hue-scene.svg +5 -0
- package/huemagic/icons/hue-temperature.png +0 -0
- package/huemagic/icons/hue-temperature.svg +7 -0
- package/huemagic/locales/de/hue-bridge-config.html +17 -12
- package/huemagic/locales/de/hue-bridge-config.json +7 -5
- package/huemagic/locales/de/hue-bridge.html +64 -145
- package/huemagic/locales/de/hue-bridge.json +6 -17
- package/huemagic/locales/de/hue-brightness.html +52 -38
- package/huemagic/locales/de/hue-brightness.json +7 -2
- package/huemagic/locales/de/hue-buttons.html +58 -0
- package/huemagic/locales/de/hue-buttons.json +28 -0
- package/huemagic/locales/de/hue-group.html +46 -122
- package/huemagic/locales/de/hue-group.json +4 -2
- package/huemagic/locales/de/hue-light.html +68 -116
- package/huemagic/locales/de/hue-light.json +5 -2
- package/huemagic/locales/de/hue-magic.html +65 -57
- package/huemagic/locales/de/hue-magic.json +2 -1
- package/huemagic/locales/de/hue-motion.html +48 -44
- package/huemagic/locales/de/hue-motion.json +6 -3
- package/huemagic/locales/de/hue-rules.html +68 -73
- package/huemagic/locales/de/hue-rules.json +5 -2
- package/huemagic/locales/de/hue-scene.html +23 -32
- package/huemagic/locales/de/hue-scene.json +5 -2
- package/huemagic/locales/de/hue-temperature.html +53 -36
- package/huemagic/locales/de/hue-temperature.json +7 -2
- package/huemagic/locales/en-US/hue-bridge-config.html +17 -12
- package/huemagic/locales/en-US/hue-bridge-config.json +5 -3
- package/huemagic/locales/en-US/hue-bridge.html +64 -145
- package/huemagic/locales/en-US/hue-bridge.json +5 -16
- package/huemagic/locales/en-US/hue-brightness.html +52 -38
- package/huemagic/locales/en-US/hue-brightness.json +10 -3
- package/huemagic/locales/en-US/hue-buttons.html +58 -0
- package/huemagic/locales/en-US/hue-buttons.json +34 -0
- package/huemagic/locales/en-US/hue-group.html +46 -122
- package/huemagic/locales/en-US/hue-group.json +7 -3
- package/huemagic/locales/en-US/hue-light.html +68 -116
- package/huemagic/locales/en-US/hue-light.json +8 -3
- package/huemagic/locales/en-US/hue-magic.html +65 -57
- package/huemagic/locales/en-US/hue-magic.json +3 -1
- package/huemagic/locales/en-US/hue-motion.html +48 -44
- package/huemagic/locales/en-US/hue-motion.json +9 -4
- package/huemagic/locales/en-US/hue-rules.html +68 -73
- package/huemagic/locales/en-US/hue-rules.json +5 -2
- package/huemagic/locales/en-US/hue-scene.html +23 -32
- package/huemagic/locales/en-US/hue-scene.json +5 -2
- package/huemagic/locales/en-US/hue-temperature.html +53 -36
- package/huemagic/locales/en-US/hue-temperature.json +10 -3
- package/huemagic/utils/api.js +290 -0
- package/huemagic/utils/color.js +382 -0
- package/{utils → huemagic/utils}/merge.js +9 -6
- package/huemagic/utils/messages.js +447 -0
- package/package.json +12 -12
- package/examples/Hue Switch.json +0 -40
- package/examples/Hue Tap.json +0 -40
- package/huemagic/assets/anime.js +0 -8
- package/huemagic/hue-switch.html +0 -119
- package/huemagic/hue-switch.js +0 -113
- package/huemagic/hue-tap.html +0 -119
- package/huemagic/hue-tap.js +0 -74
- package/huemagic/icons/hue-button.png +0 -0
- package/huemagic/icons/hue-switch.png +0 -0
- package/huemagic/icons/hue-tap.png +0 -0
- package/huemagic/locales/de/hue-switch.html +0 -50
- package/huemagic/locales/de/hue-switch.json +0 -31
- package/huemagic/locales/de/hue-tap.html +0 -41
- package/huemagic/locales/de/hue-tap.json +0 -23
- package/huemagic/locales/en-US/hue-switch.html +0 -50
- package/huemagic/locales/en-US/hue-switch.json +0 -31
- package/huemagic/locales/en-US/hue-tap.html +0 -41
- package/huemagic/locales/en-US/hue-tap.json +0 -23
- package/utils/messages.js +0 -571
- package/utils/rgb.js +0 -188
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
// EXTERNAL HELPERS
|
|
2
|
+
const colornames = require("colornames");
|
|
3
|
+
const colornamer = require('color-namer');
|
|
4
|
+
const getColors = require('get-image-colors');
|
|
5
|
+
|
|
6
|
+
// RGB -> XY
|
|
7
|
+
function rgbToXy(red, green, blue, gamut = null)
|
|
8
|
+
{
|
|
9
|
+
var colorGamut = { red: [1.0, 0], green: [0.0, 1.0], blue: [0.0, 0.0] };
|
|
10
|
+
if(!!gamut)
|
|
11
|
+
{
|
|
12
|
+
colorGamut = { red: [gamut.red.x, gamut.red.y], green: [gamut.green.x, gamut.green.y], blue: [gamut.blue.x, gamut.blue.y] };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
red = parseFloat(red / 255);
|
|
16
|
+
green = parseFloat(green / 255);
|
|
17
|
+
blue = parseFloat(blue / 255);
|
|
18
|
+
|
|
19
|
+
red = _getGammaCorrectedValue(red);
|
|
20
|
+
green = _getGammaCorrectedValue(green);
|
|
21
|
+
blue = _getGammaCorrectedValue(blue);
|
|
22
|
+
|
|
23
|
+
let x = red * 0.649926 + green * 0.103455 + blue * 0.197109;
|
|
24
|
+
let y = red * 0.234327 + green * 0.743075 + blue * 0.022598;
|
|
25
|
+
let z = red * 0.0000000 + green * 0.053077 + blue * 1.035763;
|
|
26
|
+
|
|
27
|
+
let xy = {
|
|
28
|
+
x: x / (x + y + z),
|
|
29
|
+
y: y / (x + y + z)
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if(!_xyIsInGamutRange(xy, colorGamut))
|
|
33
|
+
{
|
|
34
|
+
xy = _getClosestColor(xy, colorGamut);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return xy;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _getGammaCorrectedValue(value)
|
|
41
|
+
{
|
|
42
|
+
return (value > 0.04045) ? Math.pow((value + 0.055) / (1.0 + 0.055), 2.4) : (value / 12.92)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _xyIsInGamutRange(xy, gamut)
|
|
46
|
+
{
|
|
47
|
+
if(Array.isArray(xy))
|
|
48
|
+
{
|
|
49
|
+
xy = {
|
|
50
|
+
x: xy[0],
|
|
51
|
+
y: xy[1]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const v0 = [gamut.blue[0] - gamut.red[0], gamut.blue[1] - gamut.red[1]];
|
|
56
|
+
const v1 = [gamut.green[0] - gamut.red[0], gamut.green[1] - gamut.red[1]];
|
|
57
|
+
const v2 = [xy.x - gamut.red[0], xy.y - gamut.red[1]];
|
|
58
|
+
|
|
59
|
+
const dot00 = (v0[0] * v0[0]) + (v0[1] * v0[1]);
|
|
60
|
+
const dot01 = (v0[0] * v1[0]) + (v0[1] * v1[1]);
|
|
61
|
+
const dot02 = (v0[0] * v2[0]) + (v0[1] * v2[1]);
|
|
62
|
+
const dot11 = (v1[0] * v1[0]) + (v1[1] * v1[1]);
|
|
63
|
+
const dot12 = (v1[0] * v2[0]) + (v1[1] * v2[1]);
|
|
64
|
+
|
|
65
|
+
const invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
|
|
66
|
+
|
|
67
|
+
const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
|
|
68
|
+
const v = (dot00 * dot12 - dot01 * dot02) * invDenom;
|
|
69
|
+
|
|
70
|
+
return ((u >= 0) && (v >= 0) && (u + v < 1));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _getClosestColor(xy, gamut)
|
|
74
|
+
{
|
|
75
|
+
let greenBlue = {
|
|
76
|
+
a: {
|
|
77
|
+
x: gamut.green[0],
|
|
78
|
+
y: gamut.green[1]
|
|
79
|
+
},
|
|
80
|
+
b: {
|
|
81
|
+
x: gamut.blue[0],
|
|
82
|
+
y: gamut.blue[1]
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
let greenRed = {
|
|
87
|
+
a: {
|
|
88
|
+
x: gamut.green[0],
|
|
89
|
+
y: gamut.green[1]
|
|
90
|
+
},
|
|
91
|
+
b: {
|
|
92
|
+
x: gamut.red[0],
|
|
93
|
+
y: gamut.red[1]
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
let blueRed = {
|
|
98
|
+
a: {
|
|
99
|
+
x: gamut.red[0],
|
|
100
|
+
y: gamut.red[1]
|
|
101
|
+
},
|
|
102
|
+
b: {
|
|
103
|
+
x: gamut.blue[0],
|
|
104
|
+
y: gamut.blue[1]
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
let closestColorPoints = {
|
|
109
|
+
greenBlue: _getClosestPoint(xy,greenBlue.a, greenBlue.b),
|
|
110
|
+
greenRed: _getClosestPoint(xy,greenRed.a, greenRed.b),
|
|
111
|
+
blueRed: _getClosestPoint(xy,blueRed.a, blueRed.b)
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
let distance = {
|
|
115
|
+
greenBlue: _getLineDistance(xy,closestColorPoints.greenBlue),
|
|
116
|
+
greenRed: _getLineDistance(xy,closestColorPoints.greenRed),
|
|
117
|
+
blueRed: _getLineDistance(xy,closestColorPoints.blueRed)
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
let closestDistance;
|
|
121
|
+
let closestColor;
|
|
122
|
+
for (let i in distance)
|
|
123
|
+
{
|
|
124
|
+
if(distance.hasOwnProperty(i))
|
|
125
|
+
{
|
|
126
|
+
if(!closestDistance)
|
|
127
|
+
{
|
|
128
|
+
closestDistance = distance[i];
|
|
129
|
+
closestColor = i;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if(closestDistance > distance[i])
|
|
133
|
+
{
|
|
134
|
+
closestDistance = distance[i];
|
|
135
|
+
closestColor = i;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return closestColorPoints[closestColor];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function _getLineDistance(pointA,pointB)
|
|
144
|
+
{
|
|
145
|
+
return Math.hypot(pointB.x - pointA.x, pointB.y - pointA.y);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function _getClosestPoint(xy, pointA, pointB)
|
|
149
|
+
{
|
|
150
|
+
let xy2a = [xy.x - pointA.x, xy.y - pointA.y];
|
|
151
|
+
let a2b = [pointB.x - pointA.x, pointB.y - pointA.y];
|
|
152
|
+
let a2bSqr = Math.pow(a2b[0],2) + Math.pow(a2b[1],2);
|
|
153
|
+
let xy2a_dot_a2b = xy2a[0] * a2b[0] + xy2a[1] * a2b[1];
|
|
154
|
+
let t = xy2a_dot_a2b /a2bSqr;
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
x: pointA.x + a2b[0] * t,
|
|
158
|
+
y: pointA.y + a2b[1] * t
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// XY -> RGB
|
|
163
|
+
function xyBriToRgb(x, y, bri)
|
|
164
|
+
{
|
|
165
|
+
const z = 1.0 - x - y;
|
|
166
|
+
const Y = bri / 100;
|
|
167
|
+
const X = (Y / y) * x;
|
|
168
|
+
const Z = (Y / y) * z;
|
|
169
|
+
|
|
170
|
+
let r = X * 1.656492 - Y * 0.354851 - Z * 0.255038;
|
|
171
|
+
let g = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;
|
|
172
|
+
let b = X * 0.051713 - Y * 0.121364 + Z * 1.011530;
|
|
173
|
+
|
|
174
|
+
r = _getReversedGammaCorrectedValue(r);
|
|
175
|
+
g = _getReversedGammaCorrectedValue(g);
|
|
176
|
+
b = _getReversedGammaCorrectedValue(b);
|
|
177
|
+
|
|
178
|
+
r = Math.max(r, 0);
|
|
179
|
+
g = Math.max(g, 0);
|
|
180
|
+
b = Math.max(b, 0);
|
|
181
|
+
|
|
182
|
+
let max = Math.max(r, g, b);
|
|
183
|
+
if (max > 1)
|
|
184
|
+
{
|
|
185
|
+
r = r / max;
|
|
186
|
+
g = g / max;
|
|
187
|
+
b = b / max;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { r: Math.floor(r * 255), g: Math.floor(g * 255), b: Math.floor(b * 255), };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function _getReversedGammaCorrectedValue(value)
|
|
194
|
+
{
|
|
195
|
+
return value <= 0.0031308 ? 12.92 * value : (1.0 + 0.055) * Math.pow(value, (1.0 / 2.4)) - 0.055;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// RGB -> HEX
|
|
199
|
+
function rgbHex(red, green, blue, alpha)
|
|
200
|
+
{
|
|
201
|
+
const isPercent = (red + (alpha || '')).toString().includes('%');
|
|
202
|
+
|
|
203
|
+
if (typeof red === 'string') {
|
|
204
|
+
[red, green, blue, alpha] = red.match(/(0?\.?\d{1,3})%?\b/g).map(component => Number(component));
|
|
205
|
+
} else if (alpha !== undefined) {
|
|
206
|
+
alpha = Number.parseFloat(alpha);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (typeof red !== 'number' ||
|
|
210
|
+
typeof green !== 'number' ||
|
|
211
|
+
typeof blue !== 'number' ||
|
|
212
|
+
red > 255 ||
|
|
213
|
+
green > 255 ||
|
|
214
|
+
blue > 255
|
|
215
|
+
) {
|
|
216
|
+
throw new TypeError('Expected three numbers below 256');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (typeof alpha === 'number') {
|
|
220
|
+
if (!isPercent && alpha >= 0 && alpha <= 1) {
|
|
221
|
+
alpha = Math.round(255 * alpha);
|
|
222
|
+
} else if (isPercent && alpha >= 0 && alpha <= 100) {
|
|
223
|
+
alpha = Math.round(255 * alpha / 100);
|
|
224
|
+
} else {
|
|
225
|
+
throw new TypeError(`Expected alpha value (${alpha}) as a fraction or percentage`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
alpha = (alpha | 1 << 8).toString(16).slice(1);
|
|
229
|
+
} else {
|
|
230
|
+
alpha = '';
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1) + alpha;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// HEX -> RGB
|
|
237
|
+
function hexRgb(hex, options = {})
|
|
238
|
+
{
|
|
239
|
+
const hexCharacters = 'a-f\\d';
|
|
240
|
+
const match3or4Hex = `#?[${hexCharacters}]{3}[${hexCharacters}]?`;
|
|
241
|
+
const match6or8Hex = `#?[${hexCharacters}]{6}([${hexCharacters}]{2})?`;
|
|
242
|
+
const nonHexChars = new RegExp(`[^#${hexCharacters}]`, 'gi');
|
|
243
|
+
const validHexSize = new RegExp(`^${match3or4Hex}$|^${match6or8Hex}$`, 'i');
|
|
244
|
+
|
|
245
|
+
if (typeof hex !== 'string' || nonHexChars.test(hex) || !validHexSize.test(hex)) {
|
|
246
|
+
throw new TypeError('Expected a valid hex string');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
hex = hex.replace(/^#/, '');
|
|
250
|
+
let alphaFromHex = 1;
|
|
251
|
+
|
|
252
|
+
if (hex.length === 8) {
|
|
253
|
+
alphaFromHex = Number.parseInt(hex.slice(6, 8), 16) / 255;
|
|
254
|
+
hex = hex.slice(0, 6);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (hex.length === 4) {
|
|
258
|
+
alphaFromHex = Number.parseInt(hex.slice(3, 4).repeat(2), 16) / 255;
|
|
259
|
+
hex = hex.slice(0, 3);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (hex.length === 3) {
|
|
263
|
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const number = Number.parseInt(hex, 16);
|
|
267
|
+
const red = number >> 16;
|
|
268
|
+
const green = (number >> 8) & 255;
|
|
269
|
+
const blue = number & 255;
|
|
270
|
+
const alpha = typeof options.alpha === 'number' ? options.alpha : alphaFromHex;
|
|
271
|
+
|
|
272
|
+
return [red, green, blue];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// RANDOM HEX COLOR GENERATOR
|
|
276
|
+
function randomHexColor()
|
|
277
|
+
{
|
|
278
|
+
return '#' + (Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, "0");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function rgbToHsl(r, g, b)
|
|
282
|
+
{
|
|
283
|
+
r /= 255, g /= 255, b /= 255;
|
|
284
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
285
|
+
var h, s, l = (max + min) / 2;
|
|
286
|
+
|
|
287
|
+
if(max == min)
|
|
288
|
+
{
|
|
289
|
+
h = s = 0;
|
|
290
|
+
}
|
|
291
|
+
else
|
|
292
|
+
{
|
|
293
|
+
var d = max - min;
|
|
294
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
295
|
+
switch(max)
|
|
296
|
+
{
|
|
297
|
+
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
|
298
|
+
case g: h = (b - r) / d + 2; break;
|
|
299
|
+
case b: h = (r - g) / d + 4; break;
|
|
300
|
+
}
|
|
301
|
+
h /= 6;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return [h, s, l];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function hslToRgb(h, s, l)
|
|
308
|
+
{
|
|
309
|
+
var r, g, b;
|
|
310
|
+
|
|
311
|
+
if(s == 0)
|
|
312
|
+
{
|
|
313
|
+
r = g = b = l; // achromatic
|
|
314
|
+
}
|
|
315
|
+
else
|
|
316
|
+
{
|
|
317
|
+
var hue2rgb = function hue2rgb(p, q, t)
|
|
318
|
+
{
|
|
319
|
+
if(t < 0) t += 1;
|
|
320
|
+
if(t > 1) t -= 1;
|
|
321
|
+
if(t < 1/6) return p + (q - p) * 6 * t;
|
|
322
|
+
if(t < 1/2) return q;
|
|
323
|
+
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
|
|
324
|
+
return p;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
328
|
+
var p = 2 * l - q;
|
|
329
|
+
r = hue2rgb(p, q, h + 1/3);
|
|
330
|
+
g = hue2rgb(p, q, h);
|
|
331
|
+
b = hue2rgb(p, q, h - 1/3);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// MIX TWO COLORS
|
|
338
|
+
function mixColors(rgbA, rgbB, amount = 0.5)
|
|
339
|
+
{
|
|
340
|
+
var r = _colorChannelMixer(rgbA[0], rgbB[0], amount);
|
|
341
|
+
var g = _colorChannelMixer(rgbA[1], rgbB[1], amount);
|
|
342
|
+
var b = _colorChannelMixer(rgbA[2], rgbB[2], amount);
|
|
343
|
+
|
|
344
|
+
return [r, g, b];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function _colorChannelMixer(colorChannelA, colorChannelB, amount)
|
|
348
|
+
{
|
|
349
|
+
var channelA = colorChannelA * amount;
|
|
350
|
+
var channelB = colorChannelB * (1 - amount);
|
|
351
|
+
|
|
352
|
+
return parseInt(channelA + channelB);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// GET CURRENT COLOR TEMPERATURE
|
|
356
|
+
function colorTemperature()
|
|
357
|
+
{
|
|
358
|
+
let hour = (new Date()).getHours();
|
|
359
|
+
let minute = (new Date()).getMinutes();
|
|
360
|
+
let time = hour + minute * 0.01667;
|
|
361
|
+
|
|
362
|
+
let autoTemperature = Math.floor(3.125 * time ** 2 - 87.5 * time + 812);
|
|
363
|
+
autoTemperature = (autoTemperature < 153) ? 153 : autoTemperature;
|
|
364
|
+
autoTemperature = (autoTemperature > 500) ? 500 : autoTemperature;
|
|
365
|
+
|
|
366
|
+
return autoTemperature;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
// EXPORT
|
|
371
|
+
module.exports.rgbToXy = rgbToXy;
|
|
372
|
+
module.exports.rgbHex = rgbHex;
|
|
373
|
+
module.exports.rgbToHsl = rgbToHsl;
|
|
374
|
+
module.exports.hslToRgb = hslToRgb;
|
|
375
|
+
module.exports.xyBriToRgb = xyBriToRgb;
|
|
376
|
+
module.exports.hexRgb = hexRgb;
|
|
377
|
+
module.exports.randomHexColor = randomHexColor;
|
|
378
|
+
module.exports.colornames = colornames;
|
|
379
|
+
module.exports.colornamer = colornamer;
|
|
380
|
+
module.exports.getColors = getColors;
|
|
381
|
+
module.exports.colorTemperature = colorTemperature;
|
|
382
|
+
module.exports.mixColors = mixColors;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
module.exports =
|
|
2
|
-
{
|
|
3
|
-
deep: mergeDeep
|
|
4
|
-
};
|
|
5
|
-
|
|
6
1
|
function mergeDeep(...objects)
|
|
7
2
|
{
|
|
3
|
+
// CLEANUP FROM HTTP NODE
|
|
4
|
+
delete objects.req;
|
|
5
|
+
delete objects.res;
|
|
6
|
+
|
|
7
|
+
// BEGIN MERGING …
|
|
8
8
|
const isObject = obj => obj && typeof obj === 'object';
|
|
9
9
|
return objects.reduce((prev, obj) =>
|
|
10
10
|
{
|
|
@@ -29,4 +29,7 @@ function mergeDeep(...objects)
|
|
|
29
29
|
|
|
30
30
|
return prev;
|
|
31
31
|
}, {});
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// EXPORT
|
|
35
|
+
module.exports.deep = mergeDeep;
|