@ledvance/base 1.0.1

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 (97) hide show
  1. package/.babelrc +31 -0
  2. package/.eslintignore +6 -0
  3. package/.eslintrc.js +27 -0
  4. package/.prettierignore +0 -0
  5. package/.prettierrc.js +1 -0
  6. package/.versionrc +5 -0
  7. package/package.json +71 -0
  8. package/rn-cli.config.js +8 -0
  9. package/src/api/native.d.ts +16 -0
  10. package/src/api/native.ts +161 -0
  11. package/src/api/nativeEventEmitter.d.ts +2 -0
  12. package/src/api/nativeEventEmitter.ts +24 -0
  13. package/src/components/Card.d.ts +9 -0
  14. package/src/components/Card.tsx +35 -0
  15. package/src/components/Cell.d.ts +9 -0
  16. package/src/components/Cell.tsx +41 -0
  17. package/src/components/ColorAdjustView.d.ts +9 -0
  18. package/src/components/ColorAdjustView.tsx +66 -0
  19. package/src/components/ColorTempAdjustView.d.ts +12 -0
  20. package/src/components/ColorTempAdjustView.tsx +55 -0
  21. package/src/components/Dialog.d.ts +10 -0
  22. package/src/components/Dialog.tsx +39 -0
  23. package/src/components/InfoText.d.ts +10 -0
  24. package/src/components/InfoText.tsx +44 -0
  25. package/src/components/LampAdjustView.d.ts +13 -0
  26. package/src/components/LampAdjustView.tsx +76 -0
  27. package/src/components/LinearGradientLine.d.ts +9 -0
  28. package/src/components/LinearGradientLine.tsx +65 -0
  29. package/src/components/Page.d.ts +11 -0
  30. package/src/components/Page.tsx +35 -0
  31. package/src/components/Spacer.d.ts +7 -0
  32. package/src/components/Spacer.tsx +14 -0
  33. package/src/components/Tag.d.ts +8 -0
  34. package/src/components/Tag.tsx +57 -0
  35. package/src/components/TextButton.d.ts +9 -0
  36. package/src/components/TextButton.tsx +32 -0
  37. package/src/components/TextField.d.ts +5 -0
  38. package/src/components/TextField.tsx +74 -0
  39. package/src/components/connect.d.ts +10 -0
  40. package/src/components/connect.tsx +20 -0
  41. package/src/components/ldvColorBrightness.d.ts +1 -0
  42. package/src/components/ldvColorBrightness.tsx +18 -0
  43. package/src/components/ldvColorSlider.d.ts +14 -0
  44. package/src/components/ldvColorSlider.tsx +132 -0
  45. package/src/components/ldvPickerView.d.ts +10 -0
  46. package/src/components/ldvPickerView.tsx +68 -0
  47. package/src/components/ldvPresetView.d.ts +2 -0
  48. package/src/components/ldvPresetView.tsx +89 -0
  49. package/src/components/ldvSaturation.d.ts +2 -0
  50. package/src/components/ldvSaturation.tsx +23 -0
  51. package/src/components/ldvSlider.d.ts +15 -0
  52. package/src/components/ldvSlider.tsx +104 -0
  53. package/src/components/ldvSwitch.d.ts +9 -0
  54. package/src/components/ldvSwitch.tsx +48 -0
  55. package/src/components/ldvTemperatureSlider.d.ts +13 -0
  56. package/src/components/ldvTemperatureSlider.tsx +140 -0
  57. package/src/components/ldvTopBar.d.ts +9 -0
  58. package/src/components/ldvTopBar.tsx +64 -0
  59. package/src/components/ldvTopName.d.ts +7 -0
  60. package/src/components/ldvTopName.tsx +47 -0
  61. package/src/components/segmentControl.d.ts +1 -0
  62. package/src/components/segmentControl.tsx +66 -0
  63. package/src/components/weekSelect.d.ts +7 -0
  64. package/src/components/weekSelect.tsx +95 -0
  65. package/src/composeLayout.tsx +148 -0
  66. package/src/i18n/index.d.ts +16 -0
  67. package/src/i18n/index.ts +36 -0
  68. package/src/i18n/strings.d.ts +3139 -0
  69. package/src/i18n/strings.ts +3234 -0
  70. package/src/main.tsx +9 -0
  71. package/src/models/GlobalParams.d.ts +14 -0
  72. package/src/models/GlobalParams.ts +15 -0
  73. package/src/models/TuyaApi.d.ts +17 -0
  74. package/src/models/TuyaApi.ts +37 -0
  75. package/src/models/combine.d.ts +26 -0
  76. package/src/models/combine.ts +17 -0
  77. package/src/models/configureStore.d.ts +9 -0
  78. package/src/models/configureStore.ts +33 -0
  79. package/src/models/index.d.ts +31 -0
  80. package/src/models/index.ts +22 -0
  81. package/src/models/modules/NativePropsSlice.d.ts +25 -0
  82. package/src/models/modules/NativePropsSlice.tsx +145 -0
  83. package/src/models/modules/Result.d.ts +14 -0
  84. package/src/models/modules/Result.ts +16 -0
  85. package/src/models/modules/common.d.ts +44 -0
  86. package/src/models/modules/common.ts +161 -0
  87. package/src/res/index.d.ts +38 -0
  88. package/src/res/index.ts +37 -0
  89. package/src/utils/ColorParser.d.ts +66 -0
  90. package/src/utils/ColorParser.ts +190 -0
  91. package/src/utils/ColorUtils.d.ts +71 -0
  92. package/src/utils/ColorUtils.tsx +449 -0
  93. package/src/utils/common.d.ts +11 -0
  94. package/src/utils/common.ts +54 -0
  95. package/src/utils/index.d.ts +24 -0
  96. package/src/utils/index.ts +164 -0
  97. package/tsconfig.json +51 -0
@@ -0,0 +1,449 @@
1
+ const RGB_MAX = 255.0
2
+ const HUE_MAX = 360.0
3
+ const SV_MAX = 100.0
4
+
5
+ export default class ColorUtils {
6
+ static rgb2Hsl = function(r, g?: any, b?: any) {
7
+ if (typeof r === 'object') {
8
+ const args = r
9
+ r = args.r
10
+ g = args.g
11
+ b = args.b
12
+ }
13
+ // It converts [0,255] format, to [0,1]
14
+ r = (r === RGB_MAX) ? 1 : (r % RGB_MAX / RGB_MAX)
15
+ g = (g === RGB_MAX) ? 1 : (g % RGB_MAX / RGB_MAX)
16
+ b = (b === RGB_MAX) ? 1 : (b % RGB_MAX / RGB_MAX)
17
+
18
+ const max = Math.max(r, g, b)
19
+ const min = Math.min(r, g, b)
20
+ let h, s, l = (max + min) / 2
21
+
22
+ if (max === min) {
23
+ h = s = 0 // achromatic
24
+ } else {
25
+ const d = max - min
26
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
27
+ switch (max) {
28
+ case r:
29
+ h = (g - b) / d + (g < b ? 6 : 0)
30
+ break
31
+ case g:
32
+ h = (b - r) / d + 2
33
+ break
34
+ case b:
35
+ h = (r - g) / d + 4
36
+ break
37
+ }
38
+ h /= 6
39
+ }
40
+
41
+ return {
42
+ h: Math.round(h * HUE_MAX),
43
+ s: Math.round(s * SV_MAX),
44
+ l: Math.round(l * SV_MAX),
45
+ }
46
+ }
47
+
48
+ static rgb2Hsv = function(r, g, b) {
49
+ if (typeof r === 'object') {
50
+ const args = r
51
+ r = args.r
52
+ g = args.g
53
+ b = args.b
54
+ }
55
+
56
+ // It converts [0,255] format, to [0,1]
57
+ r = (r === RGB_MAX) ? 1 : (r % RGB_MAX / RGB_MAX)
58
+ g = (g === RGB_MAX) ? 1 : (g % RGB_MAX / RGB_MAX)
59
+ b = (b === RGB_MAX) ? 1 : (b % RGB_MAX / RGB_MAX)
60
+
61
+ const max = Math.max(r, g, b)
62
+ const min = Math.min(r, g, b)
63
+ let h, s, v = max
64
+
65
+ const d = max - min
66
+
67
+ s = max === 0 ? 0 : d / max
68
+
69
+ if (max === min) {
70
+ h = 0 // achromatic
71
+ } else {
72
+ switch (max) {
73
+ case r:
74
+ h = (g - b) / d + (g < b ? 6 : 0)
75
+ break
76
+ case g:
77
+ h = (b - r) / d + 2
78
+ break
79
+ case b:
80
+ h = (r - g) / d + 4
81
+ break
82
+ }
83
+ h /= 6
84
+ }
85
+
86
+ return {
87
+ h: Math.round(h * HUE_MAX),
88
+ s: Math.round(s * SV_MAX),
89
+ v: Math.round(v * SV_MAX),
90
+ }
91
+ }
92
+
93
+ static hsl2Rgb = function(h, s, l) {
94
+ if (typeof h === 'object') {
95
+ const args = h
96
+ h = args.h
97
+ s = args.s
98
+ l = args.l
99
+ }
100
+
101
+ var r, g, b
102
+
103
+ h = _normalizeAngle(h)
104
+ h = (h === HUE_MAX) ? 1 : (h % HUE_MAX / (HUE_MAX))
105
+ s = (s === SV_MAX) ? 1 : (s % SV_MAX / (SV_MAX))
106
+ l = (l === SV_MAX) ? 1 : (l % SV_MAX / (SV_MAX))
107
+
108
+ if (s === 0) {
109
+ r = g = b = l // achromatic
110
+ } else {
111
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s
112
+ var p = 2 * l - q
113
+ r = _hue2Rgb(p, q, h + 1 / 3)
114
+ g = _hue2Rgb(p, q, h)
115
+ b = _hue2Rgb(p, q, h - 1 / 3)
116
+ }
117
+
118
+ return {
119
+ r: Math.round(r * RGB_MAX),
120
+ g: Math.round(g * RGB_MAX),
121
+ b: Math.round(b * RGB_MAX),
122
+ }
123
+ }
124
+
125
+ static hsv2Rgb = function(h, s, v) {
126
+ if (typeof h === 'object') {
127
+ const args = h
128
+ h = args.h
129
+ s = args.s
130
+ v = args.v
131
+ }
132
+
133
+ h = _normalizeAngle(h)
134
+ h = (h === HUE_MAX) ? 1 : (h % HUE_MAX / (HUE_MAX) * 6)
135
+ s = (s === SV_MAX) ? 1 : (s % SV_MAX / (SV_MAX))
136
+ v = (v === SV_MAX) ? 1 : (v % SV_MAX / (SV_MAX))
137
+
138
+ var i = Math.floor(h)
139
+ var f = h - i
140
+ var p = v * (1 - s)
141
+ var q = v * (1 - f * s)
142
+ var t = v * (1 - (1 - f) * s)
143
+ var mod = i % 6
144
+ var r = [v, q, p, p, t, v][mod]
145
+ var g = [t, v, v, q, p, p][mod]
146
+ var b = [p, p, t, v, v, q][mod]
147
+
148
+ return {
149
+ r: Math.floor(r * RGB_MAX),
150
+ g: Math.floor(g * RGB_MAX),
151
+ b: Math.floor(b * RGB_MAX),
152
+ }
153
+ }
154
+
155
+ static rgb2Hex = function(r, g, b) {
156
+ if (typeof r === 'object') {
157
+ const args = r
158
+ r = args.r
159
+ g = args.g
160
+ b = args.b
161
+ }
162
+ r = Math.round(r).toString(16)
163
+ g = Math.round(g).toString(16)
164
+ b = Math.round(b).toString(16)
165
+
166
+ r = r.length === 1 ? '0' + r : r
167
+ g = g.length === 1 ? '0' + g : g
168
+ b = b.length === 1 ? '0' + b : b
169
+
170
+ return '#' + r + g + b
171
+ }
172
+
173
+ static hex2Rgb = function(hex) {
174
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
175
+ return result ? {
176
+ r: parseInt(result[1], 16),
177
+ g: parseInt(result[2], 16),
178
+ b: parseInt(result[3], 16),
179
+ } : null
180
+ }
181
+
182
+ static hsv2Hex = function(h, s?: any, v?: any) {
183
+ const rgb = ColorUtils.hsv2Rgb(h, s, v)
184
+ return ColorUtils.rgb2Hex(rgb.r, rgb.g, rgb.b)
185
+ }
186
+
187
+ static hex2Hsv = function(hex) {
188
+ const rgb = ColorUtils.hex2Rgb(hex)!!
189
+ return ColorUtils.rgb2Hsv(rgb.r, rgb.g, rgb.b)
190
+ }
191
+
192
+ static hsl2Hex = function(h, s, l) {
193
+ const rgb = ColorUtils.hsl2Rgb(h, s, l)
194
+ return ColorUtils.rgb2Hex(rgb.r, rgb.g, rgb.b)
195
+ }
196
+
197
+ static hex2Hsl = function(hex) {
198
+ const rgb = ColorUtils.hex2Rgb(hex)!!
199
+ return ColorUtils.rgb2Hsl(rgb.r, rgb.g, rgb.b)
200
+ }
201
+
202
+ static rgb2Cmyk = function(r, g, b) {
203
+ if (typeof r === 'object') {
204
+ const args = r
205
+ r = args.r
206
+ g = args.g
207
+ b = args.b
208
+ }
209
+
210
+ const rprim = r / 255
211
+ const gprim = g / 255
212
+ const bprim = b / 255
213
+
214
+ const k = 1 - Math.max(rprim, gprim, bprim)
215
+
216
+ const c = (1 - rprim - k) / (1 - k)
217
+ const m = (1 - gprim - k) / (1 - k)
218
+ const y = (1 - bprim - k) / (1 - k)
219
+
220
+ return {
221
+ c: c.toFixed(3),
222
+ m: m.toFixed(3),
223
+ y: y.toFixed(3),
224
+ k: k.toFixed(3),
225
+ }
226
+ }
227
+
228
+ static cmyk2Rgb = function(c?: any, m?: any, y?: any, k?: any) {
229
+ if (typeof c === 'object') {
230
+ const args = c
231
+ c = args.c
232
+ m = args.m
233
+ y = args.y
234
+ k = args.k
235
+ }
236
+
237
+ var r = 255 * (1 - c) * (1 - k)
238
+ var g = 255 * (1 - m) * (1 - k)
239
+ var b = 255 * (1 - y) * (1 - k)
240
+
241
+ return {
242
+ r: Math.floor(r),
243
+ g: Math.floor(g),
244
+ b: Math.floor(b),
245
+ }
246
+ }
247
+
248
+ static hsv2Hsl = function(h, s?: any, v?: any) {
249
+ if (typeof h === 'object') {
250
+ const args = h
251
+ h = args.h
252
+ s = args.s
253
+ v = args.v
254
+ }
255
+
256
+ var l = (2 - s) * v / 2
257
+
258
+ if (l !== 0) {
259
+ if (l === SV_MAX) {
260
+ s = 0
261
+ } else if (l < SV_MAX / 2) {
262
+ s = s * v / (l * 2)
263
+ } else {
264
+ s = s * v / (2 - l * 2)
265
+ }
266
+ }
267
+
268
+ return { h: h, s: s, l: l }
269
+ }
270
+
271
+ static hsl2Hsv = function(h, s, l) {
272
+ if (typeof h === 'object') {
273
+ const args = h
274
+ h = args.h
275
+ s = args.s
276
+ l = args.l
277
+ }
278
+
279
+ s = s * (l < 50 ? l : (100 - l))
280
+
281
+ return {
282
+ h: h,
283
+ s: Math.floor(2 * s / (l + s)),
284
+ v: Math.floor(l + s),
285
+ }
286
+ }
287
+
288
+ static parseCss = function(cssString) {
289
+ if (cssString.indexOf('#') > -1) {
290
+ return ColorUtils.hex2Rgb(cssString)
291
+ }
292
+
293
+ const prefix = cssString.split('(')[0]
294
+ const args = cssString.split('(')[1].split(')')[0].split(',')
295
+
296
+ // Use the prefix as an array [r, g, b, a] to parse the colours
297
+ return prefix.split('').reduce(function(color, param, idx) {
298
+ const nextColor = color
299
+ nextColor[param] = parseFloat(args[idx])
300
+ return nextColor
301
+ }, {})
302
+ }
303
+
304
+ static stringify = function(obj) {
305
+ const prefix = Object.keys(obj).join('')
306
+ const values = Object.keys(obj).map(function(key) {
307
+ var val = obj[key]
308
+ if (key === 's' || key === 'v' || key === 'l') {
309
+ val = val + '%'
310
+ }
311
+ return val
312
+ })
313
+ return prefix + '(' + values.join(', ') + ')'
314
+ }
315
+
316
+ static hex2Decimal = function(hexColor) {
317
+ if (typeof hexColor === 'string') {
318
+ return parseInt(hexColor.replace('#', ''), 16)
319
+ }
320
+ }
321
+
322
+ static decimal2Hex = function(decimalColor) {
323
+ if (typeof decimalColor === 'string') {
324
+ return '#' + parseInt(decimalColor).toString(16)
325
+ }
326
+ return '#' + decimalColor.toString(16)
327
+ }
328
+
329
+ static random = function() {
330
+ const base = '000000'
331
+ const number = Math.floor(Math.random() * 16777215).toString(16)
332
+ return '#' + (base + number).substr(-6)
333
+ }
334
+
335
+ static rotateHue = function(hue, amount) {
336
+ if (amount === void 0) {
337
+ amount = 0
338
+ }
339
+ const aux = typeof hue === 'object'
340
+ ? (hue.h + amount) % 360
341
+ : (hue + amount) % 360
342
+
343
+ const nextHue = aux < 0 ? (360 + aux) : aux
344
+ return typeof hue === 'object'
345
+ ? Object.assign(hue, { h: nextHue })
346
+ : nextHue
347
+ }
348
+
349
+ static getColorEncoding = function(color) {
350
+ if (typeof color === 'string') {
351
+ try {
352
+ ColorUtils.hex2Rgb(color)
353
+ return 'hex'
354
+ } catch (err) { /* Silent catch */
355
+ }
356
+ }
357
+
358
+ if (typeof color !== 'object') {
359
+ return 'unknown'
360
+ }
361
+
362
+ // Now check that the sum of the components is still a number
363
+ // And different than NaN (for that the boolean check)
364
+ const c = color
365
+
366
+ if ((c.r + c.g + c.b) && typeof (c.r + c.g + c.b) === 'number') {
367
+ return 'rgb'
368
+ }
369
+
370
+ if ((c.h + c.s + c.v) && typeof (c.h + c.s + c.v) === 'number') {
371
+ return 'hsv'
372
+ }
373
+
374
+ if ((c.h + c.s + c.l) && typeof (c.h + c.s + c.l) === 'number') {
375
+ return 'hsl'
376
+ }
377
+
378
+ if ((c.c + c.m + c.y + c.k) && typeof (c.c + c.m + c.y + c.k) === 'number') {
379
+ return 'cmyk'
380
+ }
381
+
382
+ return 'unknown'
383
+ }
384
+
385
+ static any2Hsl = function(color) {
386
+ const colorEncoding = ColorUtils.getColorEncoding(color)
387
+
388
+ switch (colorEncoding) {
389
+ case 'hsl':
390
+ return color
391
+ case 'rgb':
392
+ return ColorUtils.rgb2Hsl(color)
393
+ case 'hex':
394
+ return ColorUtils.hex2Hsl(color)
395
+ case 'hsv':
396
+ return ColorUtils.hsv2Hsl(color)
397
+ case 'cmyk':
398
+ return ColorUtils.rgb2Hsl(ColorUtils.cmyk2Rgb(color))
399
+ default:
400
+ return 'unknown'
401
+ }
402
+ }
403
+
404
+ static getTransformEncodingFunction = function(color, desiredEncoding) {
405
+ const originalEncoding = ColorUtils.getColorEncoding(color)
406
+ return ColorUtils[originalEncoding + '_to_' + desiredEncoding]
407
+ }
408
+
409
+ static darken = function(color, percentage) {
410
+ const encoding = ColorUtils.getColorEncoding(color)
411
+
412
+ if (encoding === 'unknown') {
413
+ return color
414
+ }
415
+
416
+ // Missing transformation function between hsl and cmyk
417
+ // Also, this algo is simple and precise
418
+ if (encoding === 'cmyk') {
419
+ const nextCmyk = color
420
+ nextCmyk.k = Math.min(100, 100 * percentage + nextCmyk.k)
421
+ return nextCmyk
422
+ }
423
+
424
+ const hsl = ColorUtils.any2Hsl(color)
425
+ const nextHsl = { h: hsl.h, s: hsl.s, l: Math.round(hsl.l * (1 - percentage)) }
426
+
427
+ const transformFn = encoding === 'hsl'
428
+ ? c => c // If HSL return as incame
429
+ : ColorUtils.getTransformEncodingFunction(nextHsl, encoding)
430
+
431
+ if (typeof transformFn !== 'function') {
432
+ return color
433
+ }
434
+ return transformFn(nextHsl)
435
+ }
436
+ }
437
+
438
+ function _normalizeAngle(degrees) {
439
+ return (degrees % 360 + 360) % 360
440
+ }
441
+
442
+ function _hue2Rgb(p, q, t) {
443
+ if (t < 0) t += 1
444
+ if (t > 1) t -= 1
445
+ if (t < 1 / 6) return p + (q - p) * 6 * t
446
+ if (t < 1 / 2) return q
447
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
448
+ return p
449
+ }
@@ -0,0 +1,11 @@
1
+ export declare const loopText: (loop: any) => string;
2
+ export declare function getArray(arr: any, size: any): string[];
3
+ export declare function getWeek(weekString: any): number[];
4
+ /**
5
+ * 按位分割字符串
6
+ * @param {*} str 要分割的字符串
7
+ * @param {*} step 按多少位分割
8
+ * @returns ['','',...]
9
+ */
10
+ export declare function spliceByStep(str: string, step: number): string[];
11
+ export declare function hex2Int(hex: string): number;
@@ -0,0 +1,54 @@
1
+ import I18n from '../i18n/index'
2
+
3
+ const loopsText = [
4
+ I18n.getLang('timeschedule_add_schedule_weekday7_text'),
5
+ I18n.getLang('timeschedule_add_schedule_weekday1_text'),
6
+ I18n.getLang('timeschedule_add_schedule_weekday2_text'),
7
+ I18n.getLang('timeschedule_add_schedule_weekday3_text'),
8
+ I18n.getLang('timeschedule_add_schedule_weekday4_text'),
9
+ I18n.getLang('timeschedule_add_schedule_weekday5_text'),
10
+ I18n.getLang('timeschedule_add_schedule_weekday6_text'),
11
+ ]
12
+
13
+ export const loopText = (loop) => {
14
+ const loopStrArray = loopsText.filter((_item, index) => loop[index] === 1)
15
+ return loopStrArray.length == 7 ? I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') : (loopStrArray.join(' ') || I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text2'))
16
+ }
17
+
18
+ export function getArray(arr, size) { // size=5,要分割的长度
19
+ const arrNum = Math.ceil(arr.length / size) // Math.ceil()向上取整的方法,用来计算拆分后数组的长度
20
+ let index = 0 // 定义初始索引
21
+ let resIndex = 0 // 用来保存每次拆分的长度
22
+ const result: string[] = []
23
+ while (index < arrNum) {
24
+ result[index] = arr.slice(resIndex, size + resIndex)
25
+ resIndex += size
26
+ index++
27
+ }
28
+ return result
29
+ }
30
+
31
+ export function getWeek(weekString) {
32
+ const s = parseInt(weekString, 16).toString(2).padStart(8, '0')
33
+ const array = s.split('').map(item => parseInt(item)).reverse()
34
+ array.pop()
35
+ return array
36
+ }
37
+
38
+ /**
39
+ * 按位分割字符串
40
+ * @param {*} str 要分割的字符串
41
+ * @param {*} step 按多少位分割
42
+ * @returns ['','',...]
43
+ */
44
+ export function spliceByStep(str: string, step: number): string[] {
45
+ let res: string[] = []
46
+ for (let i = 0; i < str.length; i += step) {
47
+ res.push(str.substr(i, step))
48
+ }
49
+ return res
50
+ }
51
+
52
+ export function hex2Int(hex: string): number {
53
+ return parseInt(hex, 16)
54
+ }
@@ -0,0 +1,24 @@
1
+ export declare const getFaultStrings: (faultCode: string, faultValue: number, onlyPrior?: boolean) => string;
2
+ export declare const hsv2Rgb: (h: any, s: any, v: any) => {
3
+ r: number;
4
+ g: number;
5
+ b: number;
6
+ };
7
+ export declare const hex2Hsv: (hex: any) => {
8
+ h: number;
9
+ s: number;
10
+ v: number;
11
+ } | null;
12
+ export declare const rgb2Hsv: (r: any, g: any, b: any) => {
13
+ h: number;
14
+ s: number;
15
+ v: number;
16
+ };
17
+ export declare const rgb2Hex: (r: any, g: any, b: any) => string;
18
+ export declare const hsv2Hex: (h: any, s: any, v: any) => string;
19
+ export declare const getHexByHSV: (hsv: any) => any;
20
+ export declare const getHSVByHex: (string: any) => {
21
+ h: number;
22
+ s: number;
23
+ v: number;
24
+ };
@@ -0,0 +1,164 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import {Utils} from 'tuya-panel-kit'
3
+ import {store} from '../models'
4
+ import I18n from '../i18n/index'
5
+
6
+ export const getFaultStrings = (faultCode: string, faultValue: number, onlyPrior = true) => {
7
+ const {devInfo} = store.getState()
8
+ if (!faultValue) return ''
9
+ const {label} = devInfo.schema[faultCode]
10
+ const labels: string[] = []
11
+ for (let i = 0; i < label!.length; i++) {
12
+ const value = label![i]
13
+ const isExist = Utils.NumberUtils.getBitValue(faultValue, i)
14
+ if (isExist) {
15
+ labels.push(I18n.getDpLang(faultCode, value))
16
+ if (onlyPrior) break
17
+ }
18
+ }
19
+ return onlyPrior ? labels[0] : labels.join(', ')
20
+ }
21
+
22
+ const RGB_MAX = 255
23
+ const HUE_MAX = 360
24
+ const SV_MAX = 100
25
+
26
+ export const hsv2Rgb = (h, s, v) => {
27
+ if (typeof h === 'object') {
28
+ const args = h
29
+ h = args.h
30
+ s = args.s
31
+ v = args.v
32
+ }
33
+
34
+ h = _normalizeAngle(h)
35
+ h = (h === HUE_MAX) ? 1 : (h % HUE_MAX / parseFloat(HUE_MAX.toString()) * 6)
36
+ s = (s === SV_MAX) ? 1 : (s % SV_MAX / parseFloat(SV_MAX.toString()))
37
+ v = (v === SV_MAX) ? 1 : (v % SV_MAX / parseFloat(SV_MAX.toString()))
38
+
39
+ var i = Math.floor(h)
40
+ var f = h - i
41
+ var p = v * (1 - s)
42
+ var q = v * (1 - f * s)
43
+ var t = v * (1 - (1 - f) * s)
44
+ var mod = i % 6
45
+ var r = [v, q, p, p, t, v][mod]
46
+ var g = [t, v, v, q, p, p][mod]
47
+ var b = [p, p, t, v, v, q][mod]
48
+
49
+ return {
50
+ r: Math.floor(r * RGB_MAX),
51
+ g: Math.floor(g * RGB_MAX),
52
+ b: Math.floor(b * RGB_MAX),
53
+ }
54
+ }
55
+
56
+ function _normalizeAngle(degrees) {
57
+ return (degrees % 360 + 360) % 360
58
+ }
59
+
60
+ export const hex2Hsv = function (hex) {
61
+ var rgb = hex2Rgb(hex)
62
+ if (rgb) {
63
+ return rgb2Hsv(rgb.r, rgb.g, rgb.b)
64
+ } else {
65
+ return null
66
+ }
67
+
68
+ }
69
+
70
+ const hex2Rgb = function (hex) {
71
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
72
+ return result ? {
73
+ r: parseInt(result[1], 16),
74
+ g: parseInt(result[2], 16),
75
+ b: parseInt(result[3], 16),
76
+ } : null
77
+ }
78
+
79
+ export const rgb2Hsv = function (r, g, b) {
80
+ if (typeof r === 'object') {
81
+ const args = r
82
+ r = args.r
83
+ g = args.g
84
+ b = args.b
85
+ }
86
+
87
+ // It converts [0,255] format, to [0,1]
88
+ r = (r === RGB_MAX) ? 1 : (r % RGB_MAX / parseFloat(RGB_MAX.toString()))
89
+ g = (g === RGB_MAX) ? 1 : (g % RGB_MAX / parseFloat(RGB_MAX.toString()))
90
+ b = (b === RGB_MAX) ? 1 : (b % RGB_MAX / parseFloat(RGB_MAX.toString()))
91
+
92
+ var max = Math.max(r, g, b)
93
+ var min = Math.min(r, g, b)
94
+ var h, s, v = max
95
+
96
+ var d = max - min
97
+
98
+ s = max === 0 ? 0 : d / max
99
+
100
+ if (max === min) {
101
+ h = 0 // achromatic
102
+ } else {
103
+ switch (max) {
104
+ case r:
105
+ h = (g - b) / d + (g < b ? 6 : 0)
106
+ break
107
+ case g:
108
+ h = (b - r) / d + 2
109
+ break
110
+ case b:
111
+ h = (r - g) / d + 4
112
+ break
113
+ }
114
+ h /= 6
115
+ }
116
+
117
+ return {
118
+ h: Math.round(h * HUE_MAX),
119
+ s: Math.round(s * SV_MAX),
120
+ v: Math.round(v * SV_MAX),
121
+ }
122
+ }
123
+
124
+ export const rgb2Hex = function (r, g, b) {
125
+ if (typeof r === 'object') {
126
+ const args = r
127
+ r = args.r
128
+ g = args.g
129
+ b = args.b
130
+ }
131
+ r = Math.round(r).toString(16)
132
+ g = Math.round(g).toString(16)
133
+ b = Math.round(b).toString(16)
134
+
135
+ r = r.length === 1 ? '0' + r : r
136
+ g = g.length === 1 ? '0' + g : g
137
+ b = b.length === 1 ? '0' + b : b
138
+
139
+ return '#' + r + g + b
140
+ }
141
+
142
+ export const hsv2Hex = function (h, s, v) {
143
+ let rgb = hsv2Rgb(h, s, v)
144
+ return rgb2Hex(rgb.r, rgb.g, rgb.b)
145
+ }
146
+
147
+ export const getHexByHSV = (hsv) => {
148
+ const hueHex = hsv.h.toString(16).padStart(4, '0')
149
+ const satHex = (hsv.s).toString(16).padStart(4, '0')
150
+ const colorBrightnessHex = (hsv.v).toString(16).padStart(4, '0')
151
+ const allHex = hueHex + satHex + colorBrightnessHex
152
+ return allHex
153
+ }
154
+
155
+ export const getHSVByHex = (string) => {
156
+ const h = string.substring(0, 4)
157
+ const s = string.substring(4, 8)
158
+ const v = string.substring(8, 12)
159
+ return {
160
+ h: parseInt(h, 16),
161
+ s: parseInt(s, 16),
162
+ v: parseInt(v, 16),
163
+ }
164
+ }