@ray-js/lamp-circle-picker 1.0.4 → 1.0.5-beta-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.
- package/README.md +33 -0
- package/lib/component/index.config.js +4 -4
- package/lib/component/index.d.ts +2 -2
- package/lib/component/index.js +17 -9
- package/lib/component/props.d.ts +12 -0
- package/lib/component/props.js +4 -4
- package/lib/component/rjs/index.js +52 -36
- package/lib/component/rjs/index.rjs +24 -6
- package/lib/exampleComponent/demoRjs/index.js +12 -0
- package/lib/exampleComponent/demoRjs/index.json +3 -0
- package/lib/exampleComponent/demoRjs/index.rjs +8 -0
- package/lib/exampleComponent/demoRjs/index.tyml +4 -0
- package/lib/exampleComponent/demoRjs/index.tyss +6 -0
- package/lib/i18n/index.d.ts +12 -1
- package/lib/i18n/index.js +3 -1
- package/lib/index.config.js +4 -4
- package/lib/index.d.ts +6 -2
- package/lib/index.js +22 -15
- package/lib/res/index.js +2 -2
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +13 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,20 @@ interface IProps {
|
|
|
40
40
|
* @default 140
|
|
41
41
|
*/
|
|
42
42
|
radius?: number;
|
|
43
|
+
/**
|
|
44
|
+
* @description.zh 注意⚠️:基础库版本大于2.18.0, 是否启用事件通道,当多个 rjs 组件同时使用时,用于优化 rjs 间数据传输时的性能问题
|
|
45
|
+
* @description.en Note ⚠️ : The base library version is greater than 2.18.0, Whether to enable event channels to optimize the performance of data transfer between rjs when multiple rjs components are used simultaneously
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
useEventChannel?: boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description.zh 事件通道名称
|
|
52
|
+
* @description.en Event channel name
|
|
53
|
+
* @default 'lampCirclePickerEventChannel'
|
|
54
|
+
*/
|
|
55
|
+
eventChannelName?: string;
|
|
56
|
+
|
|
43
57
|
/**
|
|
44
58
|
* @description.zh 手指按下时的回调函数
|
|
45
59
|
* @description.en Finger press when the callback function
|
|
@@ -75,3 +89,22 @@ export default () => {
|
|
|
75
89
|
return <LampCirclePicker value={temperature} onTouchMove={handleMove} onTouchEnd={handleEnd} />;
|
|
76
90
|
};
|
|
77
91
|
```
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
// Turns on the use event channel property, which can be used in other rjs components
|
|
95
|
+
Render({
|
|
96
|
+
// other xxx
|
|
97
|
+
renderChannel() {
|
|
98
|
+
const eventChannelName = 'lampCirclePickerEventChannel';
|
|
99
|
+
this.instance.eventChannel.on(eventChannelName, e => {
|
|
100
|
+
// Here you can receive the color data that is passed when the color changes
|
|
101
|
+
const {
|
|
102
|
+
data, // temp
|
|
103
|
+
touchType, // : 'start' | 'move' | 'end'
|
|
104
|
+
pos,
|
|
105
|
+
} = e;
|
|
106
|
+
console.log('eventChannel get', e);
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const web = {
|
|
2
2
|
backgroundColor: '#f2f4f6',
|
|
3
3
|
navigationBarTitleText: ''
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export const wechat = {
|
|
6
6
|
backgroundColor: '#f2f4f6',
|
|
7
7
|
navigationBarTitleText: ''
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export const tuya = {
|
|
10
10
|
backgroundColor: '#f2f4f6',
|
|
11
11
|
navigationBarTitleText: ''
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export const native = {
|
|
14
14
|
backgroundColor: 'transparent',
|
|
15
15
|
isBleOfflineOverlay: false,
|
|
16
16
|
useSafeAreaView: true,
|
package/lib/component/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IProps } from './props';
|
|
3
|
-
export default function RectColor(props: IProps): JSX.Element;
|
|
3
|
+
export default function RectColor(props: IProps): React.JSX.Element;
|
package/lib/component/index.js
CHANGED
|
@@ -6,19 +6,27 @@ export default function RectColor(props) {
|
|
|
6
6
|
radius: props.radius,
|
|
7
7
|
innerRingRadius: props.innerRingRadius,
|
|
8
8
|
value: props.value,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
useEventChannel: props.useEventChannel,
|
|
10
|
+
eventChannelName: props.eventChannelName,
|
|
11
|
+
bindstart: e => {
|
|
12
|
+
const {
|
|
13
|
+
detail
|
|
14
|
+
} = e;
|
|
15
|
+
const temp = Math.floor(detail);
|
|
12
16
|
props.onTouchStart && props.onTouchStart(temp);
|
|
13
17
|
},
|
|
14
|
-
bindmove:
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
bindmove: e => {
|
|
19
|
+
const {
|
|
20
|
+
detail
|
|
21
|
+
} = e;
|
|
22
|
+
const temp = Math.floor(detail);
|
|
17
23
|
props.onTouchMove && props.onTouchMove(temp);
|
|
18
24
|
},
|
|
19
|
-
bindend:
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
bindend: e => {
|
|
26
|
+
const {
|
|
27
|
+
detail
|
|
28
|
+
} = e;
|
|
29
|
+
const temp = Math.floor(detail);
|
|
22
30
|
props.onTouchEnd && props.onTouchEnd(temp);
|
|
23
31
|
}
|
|
24
32
|
});
|
package/lib/component/props.d.ts
CHANGED
|
@@ -17,6 +17,18 @@ export interface IProps {
|
|
|
17
17
|
* @default 140
|
|
18
18
|
*/
|
|
19
19
|
radius?: number;
|
|
20
|
+
/**
|
|
21
|
+
* @description.zh 注意⚠️:基础库版本大于2.18.0, 是否启用事件通道,当多个 rjs 组件同时使用时,用于优化 rjs 间数据传输时的性能问题
|
|
22
|
+
* @description.en Note ⚠️ : The base library version is greater than 2.18.0, Whether to enable event channels to optimize the performance of data transfer between rjs when multiple rjs components are used simultaneously
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
useEventChannel?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @description.zh 事件通道名称
|
|
28
|
+
* @description.en Event channel name
|
|
29
|
+
* @default 'lampCirclePickerEventChannel'
|
|
30
|
+
*/
|
|
31
|
+
eventChannelName?: string;
|
|
20
32
|
/**
|
|
21
33
|
* @description.zh 手指按下时的回调函数
|
|
22
34
|
* @description.en Finger press when the callback function
|
package/lib/component/props.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export var defaultProps = {
|
|
2
|
+
const nilFn = () => null;
|
|
3
|
+
export const defaultProps = {
|
|
6
4
|
value: 0,
|
|
7
5
|
innerRingRadius: 80,
|
|
8
6
|
radius: 140,
|
|
7
|
+
useEventChannel: false,
|
|
8
|
+
eventChannelName: 'lampCirclePickerEventChannel',
|
|
9
9
|
onTouchStart: nilFn,
|
|
10
10
|
onTouchMove: nilFn,
|
|
11
11
|
onTouchEnd: nilFn
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import "core-js/modules/es.number.constructor.js";
|
|
2
|
-
import "core-js/modules/es.array.concat.js";
|
|
3
|
-
import "core-js/modules/es.array.slice.js";
|
|
4
|
-
import "core-js/modules/es.json.stringify.js";
|
|
5
1
|
import Render from './index.rjs';
|
|
6
2
|
import { getSystemInfo } from '@ray-js/api';
|
|
7
|
-
|
|
3
|
+
const ETipRectPosition = {
|
|
8
4
|
LEFT: 'LEFT',
|
|
9
5
|
RIGHT: 'RIGHT'
|
|
10
6
|
};
|
|
@@ -25,6 +21,15 @@ Component({
|
|
|
25
21
|
type: Number,
|
|
26
22
|
value: 0
|
|
27
23
|
},
|
|
24
|
+
// 是否启用事件通道
|
|
25
|
+
useEventChannel: {
|
|
26
|
+
type: Boolean,
|
|
27
|
+
value: false
|
|
28
|
+
},
|
|
29
|
+
eventChannelName: {
|
|
30
|
+
type: String,
|
|
31
|
+
value: 'lampCirclePickerEventChannel'
|
|
32
|
+
},
|
|
28
33
|
onTouchStart: Function,
|
|
29
34
|
onTouchMove: Function,
|
|
30
35
|
onTouchEnd: Function
|
|
@@ -38,7 +43,7 @@ Component({
|
|
|
38
43
|
canvasId: "canvasId_".concat(String(+new Date()).slice(-3), "_").concat(String(Math.random()).slice(-3))
|
|
39
44
|
},
|
|
40
45
|
observers: {
|
|
41
|
-
'value.**'
|
|
46
|
+
'value.**'(v) {
|
|
42
47
|
if (this.touchType === 'move') {
|
|
43
48
|
return;
|
|
44
49
|
}
|
|
@@ -49,65 +54,76 @@ Component({
|
|
|
49
54
|
}
|
|
50
55
|
},
|
|
51
56
|
lifetimes: {
|
|
52
|
-
attached
|
|
57
|
+
attached() {
|
|
53
58
|
this.render = new Render(this);
|
|
54
|
-
|
|
55
|
-
radius
|
|
56
|
-
innerRingRadius
|
|
59
|
+
const {
|
|
60
|
+
radius,
|
|
61
|
+
innerRingRadius
|
|
62
|
+
} = this.data;
|
|
57
63
|
this.render._setCircles(radius, innerRingRadius);
|
|
58
64
|
},
|
|
59
|
-
ready
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
ready() {
|
|
66
|
+
const {
|
|
67
|
+
canvasId
|
|
68
|
+
} = this.data;
|
|
62
69
|
this.initCanvas();
|
|
63
|
-
setTimeout(
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
this.initCanvas();
|
|
72
|
+
this.render.checkIsRender(canvasId);
|
|
66
73
|
}, 300);
|
|
67
74
|
}
|
|
68
75
|
},
|
|
69
76
|
methods: {
|
|
70
|
-
getCanvas
|
|
77
|
+
getCanvas(canvas) {
|
|
71
78
|
if (JSON.stringify(canvas) === '{}') {
|
|
72
79
|
this.initCanvas();
|
|
73
80
|
}
|
|
74
81
|
},
|
|
75
|
-
initCanvas
|
|
76
|
-
|
|
77
|
-
canvasId
|
|
78
|
-
radius
|
|
79
|
-
innerRingRadius
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
initCanvas() {
|
|
83
|
+
const {
|
|
84
|
+
canvasId,
|
|
85
|
+
radius,
|
|
86
|
+
innerRingRadius,
|
|
87
|
+
value = 0,
|
|
88
|
+
useEventChannel,
|
|
89
|
+
eventChannelName
|
|
90
|
+
} = this.data;
|
|
91
|
+
const ratio = getSystemInfo().pixelRatio || 2;
|
|
92
|
+
canvasId && this.render.renderAnnulusColor(canvasId, radius, innerRingRadius, ratio, {
|
|
93
|
+
useEventChannel,
|
|
94
|
+
eventChannelName
|
|
95
|
+
});
|
|
84
96
|
this._updatePosByRgb(value);
|
|
85
97
|
this.lastValue = value;
|
|
86
98
|
},
|
|
87
|
-
_updatePosByRgb
|
|
99
|
+
_updatePosByRgb(value) {
|
|
88
100
|
var _this$render;
|
|
89
101
|
if (value === undefined) {
|
|
90
102
|
return;
|
|
91
103
|
}
|
|
92
104
|
(_this$render = this.render) === null || _this$render === void 0 ? void 0 : _this$render._getAnglePositionByValue(value);
|
|
93
105
|
},
|
|
94
|
-
_getRgb
|
|
106
|
+
_getRgb(x, y) {
|
|
95
107
|
var _this$render2;
|
|
96
108
|
(_this$render2 = this.render) === null || _this$render2 === void 0 ? void 0 : _this$render2.getAnnulusImageData(x, y);
|
|
97
109
|
},
|
|
98
|
-
_getAnnulusImageData
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
_getAnnulusImageData(dataRes) {
|
|
111
|
+
const {
|
|
112
|
+
position,
|
|
113
|
+
touchType
|
|
114
|
+
} = dataRes;
|
|
101
115
|
this.touchType = touchType;
|
|
102
|
-
|
|
116
|
+
const result = this._getLengthByAnglePosition(position.x, position.y);
|
|
103
117
|
this.lastValue = result;
|
|
104
118
|
this.triggerEvent(touchType, result);
|
|
105
119
|
},
|
|
106
|
-
_getLengthByAnglePosition
|
|
107
|
-
|
|
120
|
+
_getLengthByAnglePosition(x, y) {
|
|
121
|
+
const {
|
|
122
|
+
radius
|
|
123
|
+
} = this.data;
|
|
108
124
|
var radian = Math.atan2(y - radius, x - radius); // 弧度
|
|
109
125
|
var angle = radian * (180 / Math.PI); // 角度
|
|
110
|
-
|
|
126
|
+
let angleData = 0;
|
|
111
127
|
if (+angle > 135 && +angle <= 180) {
|
|
112
128
|
angleData = angle - 135;
|
|
113
129
|
} else if (angle > -180 && angle <= 0) {
|
|
@@ -115,7 +131,7 @@ Component({
|
|
|
115
131
|
} else if (angle > 0 && angle <= 45) {
|
|
116
132
|
angleData = 225 + angle;
|
|
117
133
|
}
|
|
118
|
-
|
|
134
|
+
const result = Math.round(angleData / 270 * 1000);
|
|
119
135
|
return result;
|
|
120
136
|
}
|
|
121
137
|
}
|
|
@@ -3,14 +3,23 @@ export default Render({
|
|
|
3
3
|
rectContext: null,
|
|
4
4
|
|
|
5
5
|
// 环形色盘
|
|
6
|
-
async renderAnnulusColor(id, radius, innerRingRadius, temp = 0) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
async renderAnnulusColor(id, radius, innerRingRadius, temp = 0, options = {}) {
|
|
7
|
+
let canvas = null;
|
|
8
|
+
try {
|
|
9
|
+
canvas = await getCanvasById(id);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
10
14
|
if (!canvas) {
|
|
11
15
|
console.error('canvas not found');
|
|
12
16
|
return;
|
|
13
17
|
}
|
|
18
|
+
const { useEventChannel, eventChannelName } = options || {};
|
|
19
|
+
this.useEventChannel = useEventChannel;
|
|
20
|
+
this.eventChannelName = eventChannelName;
|
|
21
|
+
canvas.width = radius * 4;
|
|
22
|
+
canvas.height = radius * 4;
|
|
14
23
|
const ctx = canvas.getContext('2d');
|
|
15
24
|
|
|
16
25
|
const startAngle = Math.PI * 0.75;
|
|
@@ -118,11 +127,20 @@ export default Render({
|
|
|
118
127
|
const g = data[1];
|
|
119
128
|
const b = data[2];
|
|
120
129
|
this.updateThumbPosition(x, y, { r, g, b });
|
|
121
|
-
const
|
|
130
|
+
const emitRes = {
|
|
122
131
|
position: { x, y },
|
|
123
132
|
touchType: this.touchType,
|
|
124
133
|
};
|
|
125
|
-
this.callMethod('_getAnnulusImageData',
|
|
134
|
+
this.callMethod('_getAnnulusImageData', emitRes);
|
|
135
|
+
|
|
136
|
+
if (this.useEventChannel) {
|
|
137
|
+
try {
|
|
138
|
+
console.log(this.eventChannelName, 'this.eventChannelName');
|
|
139
|
+
this.instance?.eventChannel.emit(this.eventChannelName, emitRes);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
126
144
|
},
|
|
127
145
|
_getRgb(x, y) {
|
|
128
146
|
if (x && y) {
|
package/lib/i18n/index.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { kit } from '@ray-js/panel-sdk';
|
|
2
|
-
declare const _default: kit.I18N
|
|
2
|
+
declare const _default: kit.I18N<{
|
|
3
|
+
en: {
|
|
4
|
+
temperature: string;
|
|
5
|
+
};
|
|
6
|
+
zh: {
|
|
7
|
+
temperature: string;
|
|
8
|
+
};
|
|
9
|
+
}, {
|
|
10
|
+
temperature: string;
|
|
11
|
+
} | {
|
|
12
|
+
temperature: string;
|
|
13
|
+
}>;
|
|
3
14
|
export default _default;
|
package/lib/i18n/index.js
CHANGED
package/lib/index.config.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const web = {
|
|
2
2
|
backgroundColor: '#f2f4f6',
|
|
3
3
|
navigationBarTitleText: ''
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export const wechat = {
|
|
6
6
|
backgroundColor: '#f2f4f6',
|
|
7
7
|
navigationBarTitleText: ''
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export const tuya = {
|
|
10
10
|
backgroundColor: '#f2f4f6',
|
|
11
11
|
navigationBarTitleText: ''
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export const native = {
|
|
14
14
|
backgroundColor: 'transparent',
|
|
15
15
|
isBleOfflineOverlay: false,
|
|
16
16
|
useSafeAreaView: true,
|
package/lib/index.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
interface IProps {
|
|
3
3
|
radius?: number;
|
|
4
4
|
innerRingRadius?: number;
|
|
5
5
|
value: number;
|
|
6
|
+
useEventChannel?: boolean;
|
|
7
|
+
eventChannelName?: string;
|
|
6
8
|
temperature?: number;
|
|
7
9
|
onTouchStart?: (v: number) => void;
|
|
8
10
|
onTouchMove?: (v: number) => void;
|
|
9
11
|
onTouchEnd?: (v: number) => void;
|
|
10
12
|
}
|
|
11
13
|
declare const LampCirclePicker: {
|
|
12
|
-
(props: IProps): JSX.Element;
|
|
14
|
+
(props: IProps): React.JSX.Element;
|
|
13
15
|
defaultProps: {
|
|
14
16
|
radius: number;
|
|
15
17
|
innerRingRadius: number;
|
|
18
|
+
useEventChannel: boolean;
|
|
19
|
+
eventChannelName: string;
|
|
16
20
|
onTouchStart: () => null;
|
|
17
21
|
onTouchMove: () => null;
|
|
18
22
|
onTouchEnd: () => null;
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "core-js/modules/es.math.trunc.js";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { View, Image, Text } from '@ray-js/components';
|
|
4
3
|
import clsx from 'clsx';
|
|
@@ -6,23 +5,31 @@ import res from './res';
|
|
|
6
5
|
import Strings from './i18n';
|
|
7
6
|
import AnnulusPickerColor from './component';
|
|
8
7
|
import styled from './index.module.less';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
const {
|
|
9
|
+
ring
|
|
10
|
+
} = res;
|
|
11
|
+
const LampCirclePicker = props => {
|
|
12
|
+
const {
|
|
13
|
+
value,
|
|
14
|
+
temperature,
|
|
15
|
+
radius,
|
|
16
|
+
innerRingRadius,
|
|
17
|
+
useEventChannel,
|
|
18
|
+
eventChannelName,
|
|
19
|
+
onTouchStart,
|
|
20
|
+
onTouchMove,
|
|
21
|
+
onTouchEnd
|
|
22
|
+
} = props;
|
|
23
|
+
const innerImgRadius = innerRingRadius * 4 * 0.8;
|
|
24
|
+
const _value = value !== null && value !== void 0 ? value : temperature;
|
|
20
25
|
return /*#__PURE__*/React.createElement(View, {
|
|
21
26
|
className: clsx(styled.container, styled.flexCenter)
|
|
22
27
|
}, /*#__PURE__*/React.createElement(AnnulusPickerColor, {
|
|
23
28
|
value: _value,
|
|
24
29
|
radius: radius,
|
|
25
30
|
innerRingRadius: innerRingRadius,
|
|
31
|
+
useEventChannel: useEventChannel || false,
|
|
32
|
+
eventChannelName: eventChannelName,
|
|
26
33
|
onTouchStart: onTouchStart,
|
|
27
34
|
onTouchMove: onTouchMove,
|
|
28
35
|
onTouchEnd: onTouchEnd
|
|
@@ -43,12 +50,12 @@ var LampCirclePicker = function (props) {
|
|
|
43
50
|
className: styled.desc
|
|
44
51
|
}, Strings.getLang('temperature')))));
|
|
45
52
|
};
|
|
46
|
-
|
|
47
|
-
return null;
|
|
48
|
-
};
|
|
53
|
+
const nilFn = () => null;
|
|
49
54
|
LampCirclePicker.defaultProps = {
|
|
50
55
|
radius: 140,
|
|
51
56
|
innerRingRadius: 80,
|
|
57
|
+
useEventChannel: false,
|
|
58
|
+
eventChannelName: 'lampCirclePickerEventChannel',
|
|
52
59
|
onTouchStart: nilFn,
|
|
53
60
|
onTouchMove: nilFn,
|
|
54
61
|
onTouchEnd: nilFn
|
package/lib/res/index.js
CHANGED
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { utils } from '@ray-js/panel-sdk';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const {
|
|
3
|
+
rgb2hsv,
|
|
4
|
+
hsv2rgb
|
|
5
|
+
} = utils;
|
|
4
6
|
/* eslint-disable no-param-reassign */
|
|
5
|
-
|
|
7
|
+
const rgbToHsl = (r, g, b) => {
|
|
6
8
|
r /= 255;
|
|
7
9
|
g /= 255;
|
|
8
10
|
b /= 255;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const max = Math.max(r, g, b);
|
|
12
|
+
const min = Math.min(r, g, b);
|
|
13
|
+
let h;
|
|
14
|
+
let s;
|
|
15
|
+
const l = (max + min) / 2;
|
|
14
16
|
if (max === min) {
|
|
15
17
|
h = 0;
|
|
16
18
|
s = 0; // achromatic
|
|
17
19
|
} else {
|
|
18
|
-
|
|
20
|
+
const d = max - min;
|
|
19
21
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
20
22
|
switch (max) {
|
|
21
23
|
case r:
|
|
@@ -34,8 +36,8 @@ var rgbToHsl = function (r, g, b) {
|
|
|
34
36
|
}
|
|
35
37
|
return {
|
|
36
38
|
h: h * 360,
|
|
37
|
-
s
|
|
38
|
-
l
|
|
39
|
+
s,
|
|
40
|
+
l
|
|
39
41
|
};
|
|
40
42
|
};
|
|
41
43
|
export { rgbToHsl, rgb2hsv, hsv2rgb };
|