UNPKG

11.6 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ColorUtils = void 0;
4const tslib_1 = require("tslib");
5const assert_1 = tslib_1.__importDefault(require("assert"));
6const lookupTable = new Map([
7 [100, [19, 222.1]],
8 [101, [18.7, 222.2]],
9 [102, [18.4, 222.3]],
10 [103, [18.2, 222.3]],
11 [104, [17.9, 222.4]],
12 [105, [17.6, 222.5]],
13 [106, [17.3, 222.7]],
14 [107, [17, 222.8]],
15 [108, [16.7, 222.9]],
16 [109, [16.4, 223]],
17 [110, [16.1, 223.2]],
18 [111, [15.8, 223.3]],
19 [112, [15.4, 223.4]],
20 [113, [15.2, 223.6]],
21 [114, [14.9, 223.8]],
22 [115, [14.7, 223.9]],
23 [116, [14.3, 224.1]],
24 [117, [14.1, 224.2]],
25 [118, [13.8, 224.4]],
26 [119, [13.5, 224.6]],
27 [120, [13.2, 224.8]],
28 [121, [12.9, 225]],
29 [122, [12.5, 225.3]],
30 [123, [12.2, 225.6]],
31 [124, [11.8, 225.9]],
32 [125, [11.4, 226.3]],
33 [126, [11.1, 226.7]],
34 [127, [10.7, 227.1]],
35 [128, [10.3, 227.6]],
36 [129, [9.9, 228]],
37 [130, [9.6, 228.5]],
38 [131, [9.3, 229.1]],
39 [132, [8.9, 229.6]],
40 [133, [8.5, 230.2]],
41 [134, [8.2, 230.9]],
42 [135, [7.8, 231.6]],
43 [136, [7.5, 232.5]],
44 [137, [7.1, 233.5]],
45 [138, [6.7, 234.6]],
46 [139, [6.3, 235.8]],
47 [140, [6, 237.1]],
48 [141, [5.6, 238.9]],
49 [142, [5.2, 240.9]],
50 [143, [5, 242.9]],
51 [144, [4.8, 244.9]],
52 [145, [4.6, 246.9]],
53 [146, [4.4, 249.3]],
54 [147, [4.3, 251.9]],
55 [148, [4.1, 254.9]],
56 [149, [3.9, 258]],
57 [150, [3.7, 261.8]],
58 [151, [3.4, 265.9]],
59 [152, [3.2, 271]],
60 [153, [3, 276.4]],
61 [154, [2.8, 283.6]],
62 [155, [2.6, 290.4]],
63 [156, [2.3, 295.3]],
64 [157, [2.1, 300]],
65 [158, [1.9, 300]],
66 [159, [1.6, 300]],
67 [160, [1.4, 195.8]],
68 [161, [1.2, 84.3]],
69 [162, [1.3, 58.2]],
70 [163, [1.5, 55.9]],
71 [164, [1.7, 53.2]],
72 [165, [1.9, 50.2]],
73 [166, [2.1, 47.1]],
74 [167, [2.4, 44.5]],
75 [168, [2.6, 42.6]],
76 [169, [2.9, 40.9]],
77 [170, [3.1, 39.5]],
78 [171, [3.4, 38.3]],
79 [172, [3.7, 37.3]],
80 [173, [3.9, 36.5]],
81 [174, [4.2, 35.7]],
82 [175, [4.4, 35.1]],
83 [176, [4.6, 34.5]],
84 [177, [4.9, 34]],
85 [178, [5.1, 33.5]],
86 [179, [5.3, 33]],
87 [180, [5.6, 32.7]],
88 [181, [5.8, 32.3]],
89 [182, [6, 32]],
90 [183, [6.3, 31.7]],
91 [184, [6.5, 31.4]],
92 [185, [6.7, 31.2]],
93 [186, [7, 30.9]],
94 [187, [7.2, 30.7]],
95 [188, [7.4, 30.5]],
96 [189, [7.6, 30.3]],
97 [190, [7.9, 30.1]],
98 [191, [8.1, 29.9]],
99 [192, [8.4, 29.7]],
100 [193, [8.6, 29.6]],
101 [194, [8.9, 29.5]],
102 [195, [9.1, 29.3]],
103 [196, [9.4, 29.2]],
104 [197, [9.6, 29.1]],
105 [198, [9.8, 29]],
106 [199, [10, 28.9]],
107 [200, [10.2, 28.7]],
108 [201, [10.5, 28.7]],
109 [202, [10.7, 28.6]],
110 [203, [11, 28.5]],
111 [204, [11.2, 28.4]],
112 [205, [11.4, 28.3]],
113 [206, [11.6, 28.3]],
114 [207, [11.8, 28.2]],
115 [208, [12.1, 28.1]],
116 [209, [12.3, 28.1]],
117 [210, [12.5, 28]],
118 [211, [12.7, 28]],
119 [212, [12.9, 27.9]],
120 [213, [13.2, 27.8]],
121 [214, [13.4, 27.8]],
122 [215, [13.6, 27.7]],
123 [216, [13.8, 27.7]],
124 [217, [14, 27.7]],
125 [218, [14.3, 27.6]],
126 [219, [14.5, 27.6]],
127 [220, [14.7, 27.5]],
128 [221, [14.9, 27.5]],
129 [222, [15.1, 27.5]],
130 [223, [15.3, 27.4]],
131 [224, [15.5, 27.4]],
132 [225, [15.8, 27.4]],
133 [226, [16, 27.3]],
134 [227, [16.2, 27.3]],
135 [228, [16.4, 27.3]],
136 [229, [16.6, 27.3]],
137 [230, [16.8, 27.2]],
138 [231, [17, 27.2]],
139 [232, [17.2, 27.2]],
140 [233, [17.4, 27.2]],
141 [234, [17.6, 27.2]],
142 [235, [17.8, 27.1]],
143 [236, [18, 27.1]],
144 [237, [18.2, 27.1]],
145 [238, [18.4, 27.1]],
146 [239, [18.7, 27.1]],
147 [240, [18.8, 27]],
148 [241, [19, 27]],
149 [242, [19.2, 27]],
150 [243, [19.4, 27]],
151 [244, [19.6, 27]],
152 [245, [19.8, 27]],
153 [246, [20, 27]],
154 [247, [20.3, 26.9]],
155 [248, [20.5, 26.9]],
156 [249, [20.6, 26.9]],
157 [250, [20.8, 26.9]],
158 [251, [21, 26.9]],
159 [252, [21.3, 26.9]],
160 [253, [21.5, 26.9]],
161 [254, [21.6, 26.9]],
162 [255, [21.8, 26.8]],
163 [256, [22, 26.8]],
164 [257, [22.2, 26.8]],
165 [258, [22.4, 26.8]],
166 [259, [22.6, 26.8]],
167 [260, [22.8, 26.8]],
168 [261, [23, 26.8]],
169 [262, [23.2, 26.8]],
170 [263, [23.4, 26.8]],
171 [264, [23.6, 26.8]],
172 [265, [23.8, 26.8]],
173 [266, [24, 26.8]],
174 [267, [24.1, 26.8]],
175 [268, [24.3, 26.8]],
176 [269, [24.5, 26.8]],
177 [270, [24.7, 26.8]],
178 [271, [24.8, 26.8]],
179 [272, [25.1, 26.7]],
180 [273, [25.3, 26.7]],
181 [274, [25.4, 26.7]],
182 [275, [25.6, 26.7]],
183 [276, [25.8, 26.7]],
184 [277, [26, 26.7]],
185 [278, [26.1, 26.7]],
186 [279, [26.3, 26.7]],
187 [280, [26.5, 26.7]],
188 [281, [26.7, 26.7]],
189 [282, [26.9, 26.7]],
190 [283, [27.1, 26.7]],
191 [284, [27.3, 26.7]],
192 [285, [27.5, 26.7]],
193 [286, [27.7, 26.7]],
194 [287, [27.8, 26.7]],
195 [288, [28, 26.7]],
196 [289, [28.2, 26.7]],
197 [290, [28.4, 26.7]],
198 [291, [28.6, 26.7]],
199 [292, [28.8, 26.7]],
200 [293, [28.9, 26.7]],
201 [294, [29.1, 26.7]],
202 [295, [29.3, 26.7]],
203 [296, [29.5, 26.7]],
204 [297, [29.6, 26.7]],
205 [298, [29.8, 26.7]],
206 [299, [30, 26.7]],
207 [300, [30.2, 26.7]],
208 [301, [30.4, 26.7]],
209 [302, [30.5, 26.7]],
210 [303, [30.7, 26.7]],
211 [304, [30.9, 26.7]],
212 [305, [31.1, 26.7]],
213 [306, [31.2, 26.7]],
214 [307, [31.4, 26.7]],
215 [308, [31.6, 26.7]],
216 [309, [31.8, 26.8]],
217 [310, [31.9, 26.8]],
218 [311, [32.1, 26.8]],
219 [312, [32.3, 26.8]],
220 [313, [32.5, 26.8]],
221 [314, [32.6, 26.8]],
222 [315, [32.8, 26.8]],
223 [316, [33, 26.8]],
224 [317, [33.2, 26.8]],
225 [318, [33.3, 26.8]],
226 [319, [33.5, 26.8]],
227 [320, [33.7, 26.8]],
228 [321, [33.8, 26.8]],
229 [322, [34, 26.8]],
230 [323, [34.2, 26.8]],
231 [324, [34.4, 26.8]],
232 [325, [34.5, 26.8]],
233 [326, [34.7, 26.8]],
234 [327, [34.9, 26.8]],
235 [328, [35.1, 26.8]],
236 [329, [35.2, 26.8]],
237 [330, [35.4, 26.8]],
238 [331, [35.5, 26.8]],
239 [332, [35.7, 26.8]],
240 [333, [35.9, 26.8]],
241 [334, [36.1, 26.8]],
242 [335, [36.3, 26.9]],
243 [336, [36.5, 26.9]],
244 [337, [36.7, 26.9]],
245 [338, [36.9, 26.9]],
246 [339, [37.1, 26.9]],
247 [340, [37.2, 26.9]],
248 [341, [37.4, 26.9]],
249 [342, [37.5, 26.9]],
250 [343, [37.7, 26.9]],
251 [344, [37.9, 26.9]],
252 [345, [38.1, 26.9]],
253 [346, [38.3, 26.9]],
254 [347, [38.5, 26.9]],
255 [348, [38.7, 26.9]],
256 [349, [38.9, 26.9]],
257 [350, [39, 26.9]],
258 [351, [39.2, 26.9]],
259 [352, [39.3, 27]],
260 [353, [39.5, 27]],
261 [354, [39.7, 27]],
262 [355, [39.9, 27]],
263 [356, [40.1, 27]],
264 [357, [40.2, 27]],
265 [358, [40.4, 27]],
266 [359, [40.6, 27]],
267 [360, [40.8, 27]],
268 [361, [40.9, 27]],
269 [362, [41.1, 27]],
270 [363, [41.2, 27]],
271 [364, [41.4, 27]],
272 [365, [41.6, 27]],
273 [366, [41.8, 27]],
274 [367, [42, 27]],
275 [368, [42.1, 27.1]],
276 [369, [42.3, 27.1]],
277 [370, [42.4, 27.1]],
278 [371, [42.6, 27.1]],
279 [372, [42.8, 27.1]],
280 [373, [43, 27.1]],
281 [374, [43.1, 27.1]],
282 [375, [43.2, 27.1]],
283 [376, [43.4, 27.1]],
284 [377, [43.6, 27.1]],
285 [378, [43.8, 27.1]],
286 [379, [43.9, 27.1]],
287 [380, [44.1, 27.1]],
288 [381, [44.3, 27.2]],
289 [382, [44.4, 27.2]],
290 [383, [44.6, 27.2]],
291 [384, [44.7, 27.2]],
292 [385, [44.9, 27.2]],
293 [386, [45.1, 27.2]],
294 [387, [45.3, 27.2]],
295 [388, [45.5, 27.2]],
296 [389, [45.6, 27.2]],
297 [390, [45.8, 27.2]],
298 [391, [46, 27.2]],
299 [392, [46.2, 27.2]],
300 [393, [46.4, 27.3]],
301 [394, [46.5, 27.3]],
302 [395, [46.7, 27.3]],
303 [396, [46.9, 27.3]],
304 [397, [47.1, 27.3]],
305 [398, [47.2, 27.3]],
306 [399, [47.4, 27.3]],
307 [400, [47.6, 27.3]],
308 [401, [47.7, 27.3]],
309 [402, [47.9, 27.3]],
310 [403, [48.1, 27.3]],
311 [404, [48.3, 27.3]],
312 [405, [48.5, 27.4]],
313 [406, [48.7, 27.4]],
314 [407, [48.8, 27.4]],
315 [408, [49, 27.4]],
316 [409, [49.2, 27.4]],
317 [410, [49.4, 27.4]],
318 [411, [49.6, 27.4]],
319 [412, [49.7, 27.4]],
320 [413, [49.9, 27.4]],
321 [414, [50.1, 27.4]],
322 [415, [50.2, 27.4]],
323 [416, [50.4, 27.4]],
324 [417, [50.6, 27.5]],
325 [418, [50.7, 27.5]],
326 [419, [50.9, 27.5]],
327 [420, [51.1, 27.5]],
328 [421, [51.2, 27.5]],
329 [422, [51.4, 27.5]],
330 [423, [51.6, 27.5]],
331 [424, [51.7, 27.5]],
332 [425, [51.9, 27.5]],
333 [426, [52.1, 27.5]],
334 [427, [51.2, 27.6]],
335 [428, [52.4, 27.6]],
336 [429, [52.5, 27.6]],
337 [430, [52.7, 27.6]],
338 [431, [52.9, 27.6]],
339 [432, [53.1, 27.6]],
340 [433, [53.2, 27.6]],
341 [434, [53.4, 27.6]],
342 [435, [53.6, 27.6]],
343 [436, [53.7, 27.6]],
344 [437, [53.9, 27.6]],
345 [438, [54.1, 27.7]],
346 [439, [54.2, 27.7]],
347 [440, [54.3, 27.7]],
348 [441, [54.5, 27.7]],
349 [442, [54.7, 27.7]],
350 [443, [54.8, 27.7]],
351 [444, [55, 27.7]],
352 [445, [55.2, 27.7]],
353 [446, [55.3, 27.7]],
354 [447, [55.5, 27.7]],
355 [448, [55.7, 27.7]],
356 [449, [55.8, 27.8]],
357 [450, [56, 27.8]],
358 [451, [56.2, 27.8]],
359 [452, [56.3, 27.8]],
360 [453, [56.5, 27.8]],
361 [454, [56.7, 27.8]],
362 [455, [56.8, 27.8]],
363 [456, [57, 27.8]],
364 [457, [57.2, 27.8]],
365 [458, [57.3, 27.9]],
366 [459, [57.4, 27.9]],
367 [460, [57.6, 27.9]],
368 [461, [57.8, 27.9]],
369 [462, [57.9, 27.9]],
370 [463, [58.1, 27.9]],
371 [464, [58.3, 27.9]],
372 [465, [58.4, 27.9]],
373 [466, [58.6, 27.9]],
374 [467, [58.8, 27.9]],
375 [468, [59, 28]],
376 [469, [59.1, 28]],
377 [470, [59.2, 28]],
378 [471, [59.4, 28]],
379 [472, [59.6, 28]],
380 [473, [59.7, 28]],
381 [474, [60, 28]],
382 [475, [60.1, 28]],
383 [476, [60.2, 28]],
384 [477, [60.4, 28]],
385 [478, [60.6, 28.1]],
386 [479, [60.7, 28.1]],
387 [480, [60.9, 28.1]],
388 [481, [60.1, 28.1]],
389 [482, [60.3, 28.1]],
390 [483, [61.4, 28.1]],
391 [484, [61.5, 28.1]],
392 [485, [61.7, 28.1]],
393 [486, [61.9, 28.1]],
394 [487, [62, 28.2]],
395 [488, [62.2, 28.2]],
396 [489, [62.3, 28.2]],
397 [490, [62.5, 28.2]],
398 [491, [62.7, 28.2]],
399 [492, [62.8, 28.2]],
400 [493, [63, 28.2]],
401 [494, [63.2, 28.2]],
402 [495, [63.3, 28.2]],
403 [496, [63.4, 28.2]],
404 [497, [63.6, 28.2]],
405 [498, [63.8, 28.3]],
406 [499, [63.9, 28.3]],
407 [500, [64.1, 28.3]],
408]);
409/**
410 * @group Utils
411 */
412class ColorUtils {
413 /**
414 * Returns the Hue and Saturation representation of the given color temperature in mired.
415 *
416 * @param colorTemperature - The color temperature in mired.
417 * @param roundResults - The lookup table has a precision of .1 decimal places. The given characteristics only have a step value of 1.
418 * Thus, the method will round the results by default to an integer value. This can be turned off using this option.
419 * @returns An number array of length 2 with the first element being the saturation and the second argument being the hue.
420 */
421 static colorTemperatureToHueAndSaturation(colorTemperature, roundResults = true) {
422 if (colorTemperature > 500) {
423 colorTemperature = 500;
424 }
425 else if (colorTemperature < 100) {
426 colorTemperature = 100;
427 }
428 colorTemperature = Math.round(colorTemperature); // ensure integer
429 const hueAndTemperature = lookupTable.get(colorTemperature);
430 (0, assert_1.default)(colorTemperature != null, "lookup for temperature " + colorTemperature + " did not yield any results");
431 if (roundResults) {
432 hueAndTemperature[0] = Math.round(hueAndTemperature[0]);
433 hueAndTemperature[1] = Math.round(hueAndTemperature[1]);
434 }
435 return {
436 saturation: hueAndTemperature[0],
437 hue: hueAndTemperature[1],
438 };
439 }
440}
441exports.ColorUtils = ColorUtils;
442//# sourceMappingURL=color-utils.js.map
\No newline at end of file