@ledvance/base 1.1.13 → 1.1.15

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 (65) hide show
  1. package/.prettierrc.js +0 -0
  2. package/package.json +1 -1
  3. package/src/api/native.d.ts +5 -0
  4. package/src/api/native.ts +193 -160
  5. package/src/api/nativeEventEmitter.ts +54 -54
  6. package/src/components/Card.tsx +25 -25
  7. package/src/components/Cell.tsx +32 -32
  8. package/src/components/ColorAdjustView.tsx +44 -44
  9. package/src/components/ColorTempAdjustView.tsx +37 -37
  10. package/src/components/ColorsLine.d.ts +7 -0
  11. package/src/components/ColorsLine.tsx +48 -0
  12. package/src/components/DeleteButton.d.ts +1 -1
  13. package/src/components/DeleteButton.tsx +27 -27
  14. package/src/components/Dialog.tsx +28 -28
  15. package/src/components/FanAdjustView.tsx +115 -105
  16. package/src/components/InfoText.tsx +29 -29
  17. package/src/components/LampAdjustView.tsx +52 -52
  18. package/src/components/LinearGradientLine.tsx +53 -53
  19. package/src/components/MoodColorsLine.d.ts +9 -0
  20. package/src/components/MoodColorsLine.tsx +38 -0
  21. package/src/components/Page.tsx +34 -34
  22. package/src/components/Popup.tsx +17 -17
  23. package/src/components/Segmented.d.ts +2 -2
  24. package/src/components/Segmented.tsx +66 -65
  25. package/src/components/Spacer.tsx +5 -5
  26. package/src/components/Tag.tsx +42 -42
  27. package/src/components/TextButton.d.ts +1 -1
  28. package/src/components/TextButton.tsx +23 -23
  29. package/src/components/TextField.tsx +58 -58
  30. package/src/components/connect.tsx +10 -10
  31. package/src/components/ldvColorBrightness.tsx +12 -12
  32. package/src/components/ldvColorSlider.tsx +109 -109
  33. package/src/components/ldvPickerView.tsx +70 -70
  34. package/src/components/ldvPresetView.tsx +68 -68
  35. package/src/components/ldvSaturation.tsx +14 -14
  36. package/src/components/ldvSlider.d.ts +3 -3
  37. package/src/components/ldvSlider.tsx +93 -93
  38. package/src/components/ldvSwitch.tsx +35 -35
  39. package/src/components/ldvTemperatureSlider.tsx +120 -120
  40. package/src/components/ldvTopBar.tsx +50 -50
  41. package/src/components/ldvTopName.tsx +44 -44
  42. package/src/components/segmentControl.tsx +59 -59
  43. package/src/components/weekSelect.tsx +76 -76
  44. package/src/composeLayout.tsx +165 -165
  45. package/src/i18n/index.ts +12 -12
  46. package/src/i18n/strings.ts +11004 -11004
  47. package/src/main.tsx +4 -4
  48. package/src/models/GlobalParams.ts +7 -7
  49. package/src/models/TuyaApi.d.ts +3 -3
  50. package/src/models/TuyaApi.ts +61 -61
  51. package/src/models/combine.ts +7 -7
  52. package/src/models/configureStore.ts +14 -14
  53. package/src/models/index.ts +4 -4
  54. package/src/models/modules/NativePropsSlice.tsx +170 -169
  55. package/src/models/modules/Result.ts +8 -8
  56. package/src/models/modules/common.ts +90 -90
  57. package/src/res/index.ts +35 -35
  58. package/src/utils/ColorParser.ts +150 -150
  59. package/src/utils/ColorUtils.tsx +414 -414
  60. package/src/utils/Support.d.ts +9 -0
  61. package/src/utils/Support.ts +85 -0
  62. package/src/utils/cctUtils.d.ts +1 -0
  63. package/src/utils/cctUtils.ts +111 -0
  64. package/src/utils/common.ts +186 -174
  65. package/src/utils/index.ts +123 -123
package/src/res/index.ts CHANGED
@@ -1,37 +1,37 @@
1
1
  export default {
2
- button: 'button',
3
- tuya_decrease: 'tuya_decrease',
4
- tuya_goto_icon: 'tuya_goto_icon',
5
- tuya_increase: 'tuya_increase',
6
- tuya_select_icon: 'tuya_select_icon',
7
- ldv_timer_empty: 'timer_empty',
8
- ldv_right_arrow: 'arrow',
9
- ldv_list_select: 'list_select',
10
- ic_check: 'ic_check',
11
- ic_uncheck: 'ic_uncheck',
12
- rhythm_icon1: 'rhythm_icon1',
13
- rhythm_icon2: 'rhythm_icon2',
14
- rhythm_icon3: 'rhythm_icon3',
15
- rhythm_icon4: 'rhythm_icon4',
16
- color_temperature_wheel: 'color_temperature_wheel',
17
- color_wheel: 'color_wheel',
18
- ic_more: 'ic_more',
19
- ic_cancel: 'ic_cancel',
20
- scene_goodnight: 'scene_goodnight',
21
- scene_reading: 'scene_reading',
22
- scene_work: 'scene_work',
23
- scene_leisure: 'scene_leisure',
24
- scene_custom1: 'scene_custom1',
25
- scene_custom2: 'scene_custom2',
26
- biorhythm_plan_timer: 'biorhythm_plantimer',
27
- add: 'add',
28
- delete: 'delete',
29
- icon_edit_scene: 'icon_edit_scene',
30
- device_panel_timer_add: require('./materialiconsOutlinedArrowsNavAddBox.png'),
31
- device_panel_schedule_add: 'device_panel_schedule_add',
32
- device_panel_schedule_alert: 'device_panel_schedule_alert',
33
- ic_arrows_nav_clear: require('./materialiconsFilledCancel.png'),
34
- ic_info: 'ic_info',
35
- ic_warning_amber: 'ic_warning_amber',
36
- rn_ic_download: 'rn_ic_download',
2
+ button: 'button',
3
+ tuya_decrease: 'tuya_decrease',
4
+ tuya_goto_icon: 'tuya_goto_icon',
5
+ tuya_increase: 'tuya_increase',
6
+ tuya_select_icon: 'tuya_select_icon',
7
+ ldv_timer_empty: 'timer_empty',
8
+ ldv_right_arrow: 'arrow',
9
+ ldv_list_select: 'list_select',
10
+ ic_check: 'ic_check',
11
+ ic_uncheck: 'ic_uncheck',
12
+ rhythm_icon1: 'rhythm_icon1',
13
+ rhythm_icon2: 'rhythm_icon2',
14
+ rhythm_icon3: 'rhythm_icon3',
15
+ rhythm_icon4: 'rhythm_icon4',
16
+ color_temperature_wheel: 'color_temperature_wheel',
17
+ color_wheel: 'color_wheel',
18
+ ic_more: 'ic_more',
19
+ ic_cancel: 'ic_cancel',
20
+ scene_goodnight: 'scene_goodnight',
21
+ scene_reading: 'scene_reading',
22
+ scene_work: 'scene_work',
23
+ scene_leisure: 'scene_leisure',
24
+ scene_custom1: 'scene_custom1',
25
+ scene_custom2: 'scene_custom2',
26
+ biorhythm_plan_timer: 'biorhythm_plantimer',
27
+ add: 'add',
28
+ delete: 'delete',
29
+ icon_edit_scene: 'icon_edit_scene',
30
+ device_panel_timer_add: require('./materialiconsOutlinedArrowsNavAddBox.png'),
31
+ device_panel_schedule_add: 'device_panel_schedule_add',
32
+ device_panel_schedule_alert: 'device_panel_schedule_alert',
33
+ ic_arrows_nav_clear: require('./materialiconsFilledCancel.png'),
34
+ ic_info: 'ic_info',
35
+ ic_warning_amber: 'ic_warning_amber',
36
+ rn_ic_download: 'rn_ic_download',
37
37
  }
@@ -1,190 +1,190 @@
1
- import { TYSdk, Utils } from 'tuya-panel-kit'
1
+ import {TYSdk, Utils} from 'tuya-panel-kit'
2
2
  import ColorObj from 'color'
3
3
 
4
4
  interface SceneValueData {
5
- t: number; // 时长
6
- f: number; // 频率
7
- m: number; // 模式
8
- h: number; // 彩光色相
9
- s: number; // 彩光饱和度
10
- v: number; // 彩光亮度
11
- b: number; // 白光亮度
12
- k: number; // 白光色温
5
+ t: number; // 时长
6
+ f: number; // 频率
7
+ m: number; // 模式
8
+ h: number; // 彩光色相
9
+ s: number; // 彩光饱和度
10
+ v: number; // 彩光亮度
11
+ b: number; // 白光亮度
12
+ k: number; // 白光色温
13
13
  }
14
14
 
15
- const { color: ColorUtils } = Utils.ColorUtils
15
+ const {color: ColorUtils} = Utils.ColorUtils
16
16
 
17
17
  let sendMusicEnabled = false
18
18
 
19
19
  export const musicEnabled = () => {
20
- sendMusicEnabled = true
20
+ sendMusicEnabled = true
21
21
  }
22
22
  export const musicDisabled = () => {
23
- sendMusicEnabled = false
23
+ sendMusicEnabled = false
24
24
  }
25
25
 
26
26
  export const isSendMusicEnabled = () => {
27
- return sendMusicEnabled
27
+ return sendMusicEnabled
28
28
  }
29
29
 
30
30
  class Parser {
31
- format(value: string, len = 2) {
32
- let v = `${value}`
33
- if (v.length < len) {
34
- v = '0'.repeat(len - v.length) + v
35
- } else {
36
- v = v.slice(0, len)
37
- }
38
- return v
31
+ format(value: string, len = 2) {
32
+ let v = `${value}`
33
+ if (v.length < len) {
34
+ v = '0'.repeat(len - v.length) + v
35
+ } else {
36
+ v = v.slice(0, len)
39
37
  }
40
-
41
- /**
42
- * @desc 将10进制的hsv转换成16进制的hhsssvvvv
43
- * 范围为h(0-360) s(0-1000) v(0-1000)
44
- * @param {Array} hsvArr - [h, s, v]
45
- *
46
- * @return {String} 'hhhhssssvvvv'
47
- *
48
- */
49
- encodeColorData(h: number, s: number, v: number): string {
50
- let hue = h % 360
51
- hue = hue > 0 ? hue : h
52
- hue = hue < 0 ? 360 + hue : hue
53
-
54
- return [hue, s, v].reduce((curr: string, next: number) => {
55
- let hex = parseInt(`${next}`, 10).toString(16)
56
- hex = this.format(hex, 4)
57
- return curr + hex
58
- }, '')
59
- }
60
-
61
- // t: time; f: frequence; m: sceneMode=[0,1,2];
62
- // h: hue; s: saturation; v: lightValue; b: whiteBright; k: kelvin
63
- encodeSceneData(scenes: SceneValueData[], sceneNum: number) {
64
- const scenesValue = scenes.reduce((sum: string, seconde: SceneValueData) => {
65
- const { t, f, m, h = 0, s = 0, v = 0, b = 0, k = 0 } = seconde
66
- const tfm = [t, f, m].reduce((total: string, next: number) => {
67
- let cur = parseInt(`${next}`, 10).toString(16)
68
- cur = this.format(cur, 2)
69
- return total + cur
70
- }, '')
71
- const hsvbk = [h, s, v, b, k].reduce((total: string, next: number) => {
72
- let cur = parseInt(`${next}`, 10).toString(16)
73
- cur = this.format(cur, 4)
74
- return total + cur
75
- }, '')
76
- return sum + tfm + hsvbk
77
- }, '')
78
- return this.format(`${sceneNum}`, 2) + scenesValue
79
- }
80
-
81
- // m: mode; h: hue; s: saturation; v: lightValue; b: whiteBright; k: kelvin;
82
- // mode: 0 - 跳变; 1 - 呼吸;
83
- encodeControlData(m: number, h: number, s: number, v: number, b: number, k: number) {
84
- const hsvbk = [h, s, v, b, k].reduce((total: string, next: number) => {
85
- let cur = parseInt(`${next}`, 10).toString(16)
86
- cur = this.format(cur, 4)
87
- return total + cur
88
- }, '')
89
- return m + hsvbk
90
- }
91
-
92
- /**
93
- * @desc 将16进制的hhsssvvv转换成10进制的hsv
94
- * 范围为h(0-360) s(0-1000) v(0-1000)
95
- * @param {String} hsvStr - encoded hsvStr (hhhhssssvvvv)
96
- *
97
- * @return {Array} [h, s, v]
98
- *
99
- */
100
- decodeColorData(byte: string) {
101
- if (!byte || byte.length !== 12) {
102
- return [0, 1000, 1000]
103
- }
104
- const b = byte.match(/[a-z\d]{4}/gi) || []
105
- return b.reduce((curr: number[], hex: string) => {
106
- curr.push(parseInt(hex, 16))
107
- return curr
108
- }, [])
38
+ return v
39
+ }
40
+
41
+ /**
42
+ * @desc 将10进制的hsv转换成16进制的hhsssvvvv
43
+ * 范围为h(0-360) s(0-1000) v(0-1000)
44
+ * @param {Array} hsvArr - [h, s, v]
45
+ *
46
+ * @return {String} 'hhhhssssvvvv'
47
+ *
48
+ */
49
+ encodeColorData(h: number, s: number, v: number): string {
50
+ let hue = h % 360
51
+ hue = hue > 0 ? hue : h
52
+ hue = hue < 0 ? 360 + hue : hue
53
+
54
+ return [hue, s, v].reduce((curr: string, next: number) => {
55
+ let hex = parseInt(`${next}`, 10).toString(16)
56
+ hex = this.format(hex, 4)
57
+ return curr + hex
58
+ }, '')
59
+ }
60
+
61
+ // t: time; f: frequence; m: sceneMode=[0,1,2];
62
+ // h: hue; s: saturation; v: lightValue; b: whiteBright; k: kelvin
63
+ encodeSceneData(scenes: SceneValueData[], sceneNum: number) {
64
+ const scenesValue = scenes.reduce((sum: string, seconde: SceneValueData) => {
65
+ const {t, f, m, h = 0, s = 0, v = 0, b = 0, k = 0} = seconde
66
+ const tfm = [t, f, m].reduce((total: string, next: number) => {
67
+ let cur = parseInt(`${next}`, 10).toString(16)
68
+ cur = this.format(cur, 2)
69
+ return total + cur
70
+ }, '')
71
+ const hsvbk = [h, s, v, b, k].reduce((total: string, next: number) => {
72
+ let cur = parseInt(`${next}`, 10).toString(16)
73
+ cur = this.format(cur, 4)
74
+ return total + cur
75
+ }, '')
76
+ return sum + tfm + hsvbk
77
+ }, '')
78
+ return this.format(`${sceneNum}`, 2) + scenesValue
79
+ }
80
+
81
+ // m: mode; h: hue; s: saturation; v: lightValue; b: whiteBright; k: kelvin;
82
+ // mode: 0 - 跳变; 1 - 呼吸;
83
+ encodeControlData(m: number, h: number, s: number, v: number, b: number, k: number) {
84
+ const hsvbk = [h, s, v, b, k].reduce((total: string, next: number) => {
85
+ let cur = parseInt(`${next}`, 10).toString(16)
86
+ cur = this.format(cur, 4)
87
+ return total + cur
88
+ }, '')
89
+ return m + hsvbk
90
+ }
91
+
92
+ /**
93
+ * @desc 将16进制的hhsssvvv转换成10进制的hsv
94
+ * 范围为h(0-360) s(0-1000) v(0-1000)
95
+ * @param {String} hsvStr - encoded hsvStr (hhhhssssvvvv)
96
+ *
97
+ * @return {Array} [h, s, v]
98
+ *
99
+ */
100
+ decodeColorData(byte: string) {
101
+ if (!byte || byte.length !== 12) {
102
+ return [0, 1000, 1000]
109
103
  }
110
-
111
- decodeSceneData(byte: string) {
112
- if (!byte || (byte.length - 2) % 26 !== 0) {
113
- return {
114
- sceneNum: 0,
115
- scenes: [],
116
- }
117
- }
118
- const sceneNum = byte.slice(0, 2)
119
- const sceneValueArr = byte.slice(2).match(/[a-z\d]{26}/gi) || []
120
- const scenes = sceneValueArr.map((item: string) => {
121
- const tfm = item.slice(0, 6)
122
- const [t, f, m] = (tfm.match(/[a-z\d]{2}/gi) || []).map(v => parseInt(v, 16))
123
- const hsvbk = item.slice(6)
124
- const [h, s, v, b, k] = (hsvbk.match(/[a-z\d]{4}/gi) || []).map(d => parseInt(d, 16))
125
- return { t, f, m, h, s, v, b, k }
126
- })
127
- return {
128
- sceneNum: parseInt(sceneNum, 16),
129
- scenes,
130
- }
131
- }
132
-
133
- bright2Opacity(brightness: number, option = { min: 0.3, max: 1 }) {
134
- const { min = 0.3, max = 1 } = option
135
- return Math.round((min + ((brightness - 10) / (1000 - 10)) * (max - min)) * 100) / 100
104
+ const b = byte.match(/[a-z\d]{4}/gi) || []
105
+ return b.reduce((curr: number[], hex: string) => {
106
+ curr.push(parseInt(hex, 16))
107
+ return curr
108
+ }, [])
109
+ }
110
+
111
+ decodeSceneData(byte: string) {
112
+ if (!byte || (byte.length - 2) % 26 !== 0) {
113
+ return {
114
+ sceneNum: 0,
115
+ scenes: [],
116
+ }
136
117
  }
137
-
138
- /**
139
- * 格式化hsv
140
- * 亮度将转化为透明度变化
141
- */
142
- hsv2rgba(hue: number, saturation: number, bright: number) {
143
- let color = ColorUtils.hsb2hex(hue, saturation / 10, 100)
144
- color = new ColorObj(color).alpha(this.bright2Opacity(bright)).rgbString()
145
- return color
146
- }
147
-
148
- brightKelvin2rgba(bright: number, kelvin: number) {
149
- let color = ColorUtils.brightKelvin2rgb(1000, kelvin)
150
- color = new ColorObj(color).alpha(this.bright2Opacity(bright)).rgbString()
151
- return color
118
+ const sceneNum = byte.slice(0, 2)
119
+ const sceneValueArr = byte.slice(2).match(/[a-z\d]{26}/gi) || []
120
+ const scenes = sceneValueArr.map((item: string) => {
121
+ const tfm = item.slice(0, 6)
122
+ const [t, f, m] = (tfm.match(/[a-z\d]{2}/gi) || []).map(v => parseInt(v, 16))
123
+ const hsvbk = item.slice(6)
124
+ const [h, s, v, b, k] = (hsvbk.match(/[a-z\d]{4}/gi) || []).map(d => parseInt(d, 16))
125
+ return {t, f, m, h, s, v, b, k}
126
+ })
127
+ return {
128
+ sceneNum: parseInt(sceneNum, 16),
129
+ scenes,
152
130
  }
131
+ }
132
+
133
+ bright2Opacity(brightness: number, option = {min: 0.3, max: 1}) {
134
+ const {min = 0.3, max = 1} = option
135
+ return Math.round((min + ((brightness - 10) / (1000 - 10)) * (max - min)) * 100) / 100
136
+ }
137
+
138
+ /**
139
+ * 格式化hsv
140
+ * 亮度将转化为透明度变化
141
+ */
142
+ hsv2rgba(hue: number, saturation: number, bright: number) {
143
+ let color = ColorUtils.hsb2hex(hue, saturation / 10, 100)
144
+ color = new ColorObj(color).alpha(this.bright2Opacity(bright)).rgbString()
145
+ return color
146
+ }
147
+
148
+ brightKelvin2rgba(bright: number, kelvin: number) {
149
+ let color = ColorUtils.brightKelvin2rgb(1000, kelvin)
150
+ color = new ColorObj(color).alpha(this.bright2Opacity(bright)).rgbString()
151
+ return color
152
+ }
153
153
  }
154
154
 
155
155
  export const ColorParser = new Parser()
156
156
 
157
157
  export const calcPercent = (start: number, end: number, pos: number, min = 0) => {
158
- const distance = end - start
159
- const diff = pos - start
160
- return (diff / distance) * (1 - min) + min
158
+ const distance = end - start
159
+ const diff = pos - start
160
+ return (diff / distance) * (1 - min) + min
161
161
  }
162
162
 
163
163
  export const calcPosition = (start: number, end: number, percent: number) => {
164
- const distance = end - start
165
- return percent * distance + start
164
+ const distance = end - start
165
+ return percent * distance + start
166
166
  }
167
167
 
168
168
  export const randomHsb = () => {
169
- const random = (min: number, max: number) => {
170
- let x = max
171
- let y = min
172
- if (x < y) {
173
- x = min
174
- y = max
175
- }
176
- return Math.random() * (x - y) + y
169
+ const random = (min: number, max: number) => {
170
+ let x = max
171
+ let y = min
172
+ if (x < y) {
173
+ x = min
174
+ y = max
177
175
  }
178
- return [random(0, 360), 100, 100]
176
+ return Math.random() * (x - y) + y
177
+ }
178
+ return [random(0, 360), 100, 100]
179
179
  }
180
180
 
181
181
  export const arrayToObject = (arr: any[]) => {
182
- if (arr.length === 0) {
183
- return {}
184
- }
185
- return Object.assign({}, ...arr)
182
+ if (arr.length === 0) {
183
+ return {}
184
+ }
185
+ return Object.assign({}, ...arr)
186
186
  }
187
187
 
188
188
  export const isCapability = (id: number) => {
189
- return (TYSdk.devInfo.capability & (1 << id)) > 0 // eslint-disable-line no-bitwise
189
+ return (TYSdk.devInfo.capability & (1 << id)) > 0 // eslint-disable-line no-bitwise
190
190
  }