@ray-js/lamp-circle-picker 1.1.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 ADDED
@@ -0,0 +1,99 @@
1
+ English | [简体中文](./README-zh_CN.md)
2
+
3
+ # @ray/lamp-circle-picker
4
+
5
+ [![latest](https://img.shields.io/npm/v/@ray/lamp-annulus-color-picker/latest.svg)](https://www.npmjs.com/package/@ray/lamp-annulus-color-picker) [![download](https://img.shields.io/npm/dt/@ray/lamp-annulus-color-picker.svg)](https://www.npmjs.com/package/@ray/lamp-annulus-color-picker)
6
+
7
+ > LampCirclePicker
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ $ npm install @ray-js/components-ty-lamp
13
+ # or
14
+ $ yarn add @ray-js/components-ty-lamp
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```tsx
20
+ interface IProps {
21
+ /**
22
+ * @description.zh 色盘id 唯一标识
23
+ * @description.en Color wheel id unique identification
24
+ * @default
25
+ */
26
+ canvasId: string;
27
+ /**
28
+ * @description.zh 默认数值
29
+ * @description.en default value
30
+ * @default
31
+ */
32
+ value: number;
33
+ /**
34
+ * @description.zh 内部色环宽度
35
+ * @description.en The width of inner color ring
36
+ * @default 80
37
+ */
38
+ innerRingRadius?: number;
39
+ /**
40
+ * @description.zh 色盘宽度
41
+ * @description.en The width of color ring
42
+ * @default 140
43
+ */
44
+ radius?: number;
45
+ /**
46
+ * @description.zh 是否展示色圈
47
+ * @description.en Whether to show color circle
48
+ * @default true
49
+ */
50
+ isShowThumb?: boolean;
51
+ /**
52
+ * @description.zh 是否当前颜色文案
53
+ * @description.en Whether the current color text
54
+ * @default false
55
+ */
56
+ isShowColorTip?: boolean;
57
+ /**
58
+ * @description.zh 手指按下时的回调函数
59
+ * @description.en Finger press when the callback function
60
+ * @default ''
61
+ */
62
+ onTouchStart?: (value: number) => void;
63
+ /**
64
+ * @description.zh 手指按下拖动时的回调函数
65
+ * @description.en Finger to press the drag of the callback function
66
+ * @default ''
67
+ */
68
+ onTouchMove?: (value: number) => void;
69
+ /**
70
+ * @description.zh 手指按下结束时的回调函数
71
+ * @description.en Finger press at the end of the callback function
72
+ * @default ''
73
+ */
74
+ onTouchEnd?: (value: number) => void;
75
+ }
76
+ ```
77
+
78
+ ```tsx
79
+ // 用法
80
+ import { LampCirclePicker } from '@ray-js/components-ty-lamp';
81
+
82
+ export default () => {
83
+ const [temperature, setTemperature] = useState(20);
84
+ const handleMove = (v: number) => {
85
+ setTemperature(v);
86
+ };
87
+ const handleEnd = (v: number) => {
88
+ setTemperature(v);
89
+ };
90
+ return (
91
+ <LampCirclePicker
92
+ canvasId="whiteRing"
93
+ temperature={temperature}
94
+ onTouchMove={handleMove}
95
+ onTouchEnd={handleEnd}
96
+ />
97
+ );
98
+ };
99
+ ```
@@ -0,0 +1,18 @@
1
+ export var web = {
2
+ backgroundColor: '#f2f4f6',
3
+ navigationBarTitleText: ''
4
+ };
5
+ export var wechat = {
6
+ backgroundColor: '#f2f4f6',
7
+ navigationBarTitleText: ''
8
+ };
9
+ export var tuya = {
10
+ backgroundColor: '#f2f4f6',
11
+ navigationBarTitleText: ''
12
+ };
13
+ export var native = {
14
+ backgroundColor: 'transparent',
15
+ isBleOfflineOverlay: false,
16
+ useSafeAreaView: true,
17
+ navigationBarTitleText: ''
18
+ };
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { IProps } from './props';
3
+ export default function RectColor(props: IProps): JSX.Element;
@@ -0,0 +1,27 @@
1
+ /* eslint-disable prettier/prettier */
2
+ import React from 'react';
3
+ import RectColorPicker from './rjs';
4
+ export default function RectColor(props) {
5
+ return /*#__PURE__*/React.createElement(RectColorPicker, {
6
+ canvasId: props.canvasId,
7
+ radius: props.radius,
8
+ innerRingRadius: props.innerRingRadius,
9
+ value: props.value,
10
+ isShowColorTip: props.isShowColorTip,
11
+ bindstart: function onTouchStart(e) {
12
+ var detail = e.detail;
13
+ var temp = Math.floor(detail);
14
+ props.onTouchStart && props.onTouchStart(temp);
15
+ },
16
+ bindmove: function onTouchMove(e) {
17
+ var detail = e.detail;
18
+ var temp = Math.floor(detail);
19
+ props.onTouchMove && props.onTouchMove(temp);
20
+ },
21
+ bindend: function onTouchEnd(e) {
22
+ var detail = e.detail;
23
+ var temp = Math.floor(detail);
24
+ props.onTouchEnd && props.onTouchEnd(temp);
25
+ }
26
+ });
27
+ }
@@ -0,0 +1,7 @@
1
+ .thumb {
2
+ position: absolute;
3
+ width: 44rpx;
4
+ height: 44rpx;
5
+ border-radius: 50%;
6
+ border: 4rpx solid rgba(255, 255, 255, 0.8);
7
+ }
@@ -0,0 +1,57 @@
1
+ export interface IProps {
2
+ /**
3
+ * @description.zh 色盘id 唯一标识
4
+ * @description.en Color wheel id unique identification
5
+ * @default
6
+ */
7
+ canvasId: string;
8
+ /**
9
+ * @description.zh 默认数值
10
+ * @description.en default value
11
+ * @default
12
+ */
13
+ value: number;
14
+ /**
15
+ * @description.zh 内部色环宽度
16
+ * @description.en Drag the color ring width
17
+ * @default 80
18
+ */
19
+ innerRingRadius?: number;
20
+ /**
21
+ * @description.zh 色盘宽度
22
+ * @description.en Color plate width
23
+ * @default 140
24
+ */
25
+ radius?: number;
26
+ /**
27
+ * @description.zh 是否展示色圈
28
+ * @description.en Whether to show color circle
29
+ * @default true
30
+ */
31
+ isShowThumb?: boolean;
32
+ /**
33
+ * @description.zh 是否当前颜色文案
34
+ * @description.en Whether the current color text
35
+ * @default false
36
+ */
37
+ isShowColorTip?: boolean;
38
+ /**
39
+ * @description.zh 手指按下时的回调函数
40
+ * @description.en Finger press when the callback function
41
+ * @default ''
42
+ */
43
+ onTouchStart?: (value: number) => void;
44
+ /**
45
+ * @description.zh 手指按下拖动时的回调函数
46
+ * @description.en Finger to press the drag of the callback function
47
+ * @default ''
48
+ */
49
+ onTouchMove?: (value: number) => void;
50
+ /**
51
+ * @description.zh 手指按下结束时的回调函数
52
+ * @description.en Finger press at the end of the callback function
53
+ * @default ''
54
+ */
55
+ onTouchEnd?: (value: number) => void;
56
+ }
57
+ export declare const defaultProps: IProps;
@@ -0,0 +1,14 @@
1
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
2
+ var nilFn = function () {
3
+ return null;
4
+ };
5
+ export var defaultProps = {
6
+ innerRingRadius: 80,
7
+ radius: 140,
8
+ isShowThumb: true,
9
+ onTouchStart: nilFn,
10
+ onTouchMove: nilFn,
11
+ onTouchEnd: nilFn,
12
+ canvasId: 'AnnulusPickerColor',
13
+ value: 0
14
+ };
@@ -0,0 +1,121 @@
1
+ import "core-js/modules/es.number.constructor.js";
2
+ import "core-js/modules/es.json.stringify.js";
3
+ import Render from './indexRjs.rjs';
4
+ import { getSystemInfo } from '@ray-js/api';
5
+ var ETipRectPosition = {
6
+ LEFT: 'LEFT',
7
+ RIGHT: 'RIGHT'
8
+ };
9
+
10
+ // eslint-disable-next-line no-undef
11
+ Component({
12
+ properties: {
13
+ canvasId: String,
14
+ containerStyle: String,
15
+ radius: {
16
+ type: Number,
17
+ value: 100
18
+ },
19
+ innerRingRadius: {
20
+ type: Number,
21
+ value: 50
22
+ },
23
+ value: {
24
+ type: Number,
25
+ value: 0
26
+ },
27
+ isShowColorTip: {
28
+ type: Boolean,
29
+ value: true
30
+ },
31
+ onTouchStart: Function,
32
+ onTouchMove: Function,
33
+ onTouchEnd: Function
34
+ },
35
+ data: {
36
+ render: null,
37
+ isTouch: false,
38
+ touchType: '',
39
+ colorText: '',
40
+ tipRectPosition: ETipRectPosition.LEFT
41
+ },
42
+ observers: {
43
+ 'value.**': function value(v) {
44
+ if (Math.abs(this.lastValue / 10 - v / 10) > 1 || this.lastValue === 0 && v === 0) {
45
+ this._updatePosByRgb(v);
46
+ this.lastValue = v;
47
+ }
48
+ }
49
+ },
50
+ lifetimes: {
51
+ attached: function attached() {
52
+ this.render = new Render(this);
53
+ var _this$data = this.data,
54
+ radius = _this$data.radius,
55
+ innerRingRadius = _this$data.innerRingRadius;
56
+ this.render._setCircles(radius, innerRingRadius);
57
+ },
58
+ ready: function ready() {
59
+ var _this = this;
60
+ var canvasId = this.data.canvasId;
61
+ this.initCanvas();
62
+ setTimeout(function () {
63
+ _this.initCanvas();
64
+ _this.render.checkIsRender(canvasId);
65
+ }, 300);
66
+ }
67
+ },
68
+ methods: {
69
+ getCanvas: function getCanvas(canvas) {
70
+ if (JSON.stringify(canvas) === '{}') {
71
+ this.initCanvas();
72
+ }
73
+ },
74
+ initCanvas: function initCanvas() {
75
+ var _this$data2 = this.data,
76
+ canvasId = _this$data2.canvasId,
77
+ radius = _this$data2.radius,
78
+ innerRingRadius = _this$data2.innerRingRadius,
79
+ _this$data2$value = _this$data2.value,
80
+ value = _this$data2$value === void 0 ? 0 : _this$data2$value;
81
+ var ratio = getSystemInfo().pixelRatio || 2;
82
+ canvasId && this.render.renderAnnulusColor(canvasId, radius, innerRingRadius, ratio);
83
+ this._updatePosByRgb(value);
84
+ this.lastValue = value;
85
+ },
86
+ _updatePosByRgb: function _updatePosByRgb(value) {
87
+ var _this$render;
88
+ if (value === undefined) {
89
+ return;
90
+ }
91
+ (_this$render = this.render) === null || _this$render === void 0 ? void 0 : _this$render._getAnglePositionByValue(value);
92
+ },
93
+ _getRgb: function _getRgb(x, y) {
94
+ var _this$render2;
95
+ (_this$render2 = this.render) === null || _this$render2 === void 0 ? void 0 : _this$render2.getAnnulusImageData(x, y);
96
+ },
97
+ _getAnnulusImageData: function _getAnnulusImageData(dataRes) {
98
+ var position = dataRes.position,
99
+ touchType = dataRes.touchType;
100
+ this.touchType = touchType;
101
+ var result = this._getLengthByAnglePosition(position.x, position.y);
102
+ this.lastValue = result;
103
+ this.triggerEvent(touchType, result);
104
+ },
105
+ _getLengthByAnglePosition: function _getLengthByAnglePosition(x, y) {
106
+ var radius = this.data.radius;
107
+ var radian = Math.atan2(y - radius, x - radius); // 弧度
108
+ var angle = radian * (180 / Math.PI); // 角度
109
+ var angleData = 0;
110
+ if (+angle > 135 && +angle <= 180) {
111
+ angleData = angle - 135;
112
+ } else if (angle > -180 && angle <= 0) {
113
+ angleData = 45 + angle + 180;
114
+ } else if (angle > 0 && angle <= 45) {
115
+ angleData = 225 + angle;
116
+ }
117
+ var result = Math.round(angleData / 270 * 1000);
118
+ return result;
119
+ }
120
+ }
121
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,15 @@
1
+ <view style="{{ containerStyle }}">
2
+ <canvas
3
+ class="canvasWrapper"
4
+ type="2d"
5
+ canvas-id="{{ canvasId }}"
6
+ style="width: {{ radius * 2 }}px; height: {{ radius * 2 }}px;"
7
+ >
8
+ <canvas
9
+ class="canvasThumbWrapper"
10
+ type="2d"
11
+ canvas-id="{{ canvasId }}_thumb"
12
+ style="width: {{ radius * 2 }}px; height: {{ radius * 2 }}px;"
13
+ ></canvas>
14
+ </canvas>
15
+ </view>
@@ -0,0 +1,41 @@
1
+ .container {}
2
+
3
+ .canvasWrapper {
4
+ position: relative;
5
+ }
6
+ .canvasThumbWrapper {
7
+ z-index: 11;
8
+ }
9
+
10
+ .thumb {
11
+ position: absolute;
12
+ width: 44rpx;
13
+ height: 44rpx;
14
+ border-radius: 50%;
15
+ border: 5rpx solid rgba(255, 255, 255, 0.8);
16
+ z-index: 99;
17
+ box-shadow:0 0 7px 0 rgba(0, 0, 0, 0.16);
18
+ }
19
+
20
+ .colorTipWrapper {
21
+ position: absolute;
22
+ top: 12rpx;
23
+ left: 12rpx;
24
+ min-width: 72rpx;
25
+ padding-left: 10rpx;
26
+ padding-right: 10rpx;
27
+ height: 36rpx;
28
+ display: flex;
29
+ justify-content: center;
30
+ align-items: center;
31
+ background: rgba(0, 0, 0, 0.2);
32
+ color: #fff;
33
+ border-radius: 66rpx;
34
+ font-size: 20rpx;
35
+ z-index: 999;
36
+ }
37
+
38
+ .colorTip {
39
+ color: #fff;
40
+ font-size: 20rpx;
41
+ }
@@ -0,0 +1,216 @@
1
+ // commonColor.rjs
2
+ export default Render({
3
+ rectContext: null,
4
+
5
+ // 环形色盘
6
+ async renderAnnulusColor(id, radius, innerRingRadius, temp = 0) {
7
+ const canvas = await getCanvasById(id);
8
+ canvas.width = radius * 4;
9
+ canvas.height = radius * 4;
10
+ if (!canvas) {
11
+ console.error('canvas not found');
12
+ return;
13
+ }
14
+ const ctx = canvas.getContext('2d');
15
+
16
+ const startAngle = Math.PI * 0.75;
17
+ const endAngle = Math.PI * 0.25;
18
+
19
+ ctx.beginPath();
20
+ ctx.arc(
21
+ radius * 2,
22
+ radius * 2,
23
+ innerRingRadius * 2 + (radius - innerRingRadius),
24
+ startAngle,
25
+ endAngle
26
+ );
27
+
28
+ let grd = ctx.createRadialGradient(
29
+ 0,
30
+ radius * 2,
31
+ radius * 2,
32
+ radius * 4,
33
+ radius * 2,
34
+ radius * 2
35
+ );
36
+ grd.addColorStop(0, '#FFCD65');
37
+ grd.addColorStop(0.7, '#FEECAB');
38
+ grd.addColorStop(1, '#CEEDFF');
39
+
40
+ //设定曲线粗细度
41
+ ctx.lineWidth = (radius - innerRingRadius) * 2;
42
+ //给曲线着色
43
+ ctx.strokeStyle = grd;
44
+ //连接处样式
45
+ ctx.lineCap = 'round';
46
+ //给环着色
47
+ ctx.stroke();
48
+ ctx.closePath();
49
+ ctx.scale(2, 2);
50
+ canvas.style.width = `${radius * 2}px`;
51
+ canvas.style.height = `${radius * 2}px`;
52
+ this.annulusContext = ctx;
53
+ this.renderAnnulusColorThumb(id, temp);
54
+ },
55
+ async renderAnnulusColorThumb(id, temp = 0) {
56
+ if (!this.canvasThumb) {
57
+ this.canvasThumb = await getCanvasById(`${id}_thumb`);
58
+ this.canvasThumbCtx = this.canvasThumb.getContext('2d');
59
+ }
60
+ this.addEventListeners();
61
+ this._getAnglePositionByValue(temp);
62
+ },
63
+ async checkIsRender(id) {
64
+ const canvas = await getCanvasById(id);
65
+ this.callMethod('getCanvas', canvas);
66
+ },
67
+ _setCircles(radius, innerRingRadius) {
68
+ this.radius = radius;
69
+ this.innerRingRadius = innerRingRadius;
70
+ },
71
+ _getAnglePositionByValue(value) {
72
+ const ctx = this.annulusContext;
73
+ const angle = 135 + (value / 1000) * 270;
74
+ const x =
75
+ this.radius +
76
+ (this.innerRingRadius + (this.radius - this.innerRingRadius) / 2) *
77
+ Math.cos((angle * Math.PI) / 180);
78
+ const y =
79
+ this.radius +
80
+ (this.innerRingRadius + (this.radius - this.innerRingRadius) / 2) *
81
+ Math.sin((angle * Math.PI) / 180);
82
+ const { data } = ctx.getImageData(x * 2, y * 2, 1, 1);
83
+ this.updateThumbPosition(x, y, { r: data[0], g: data[1], b: data[2] });
84
+ },
85
+ updateThumbPosition(x, y, rgb) {
86
+ if (!this.canvasThumb) {
87
+ console.error('canvasThumb not found');
88
+ return;
89
+ }
90
+ let ctx = this.canvasThumbCtx;
91
+ this.canvasThumb.width = this.radius * 4;
92
+ this.canvasThumb.height = this.radius * 4;
93
+ ctx.clearRect(0, 0, this.canvasThumb.width, this.canvasThumb.height);
94
+ ctx.beginPath();
95
+ const radius = this.radius - this.innerRingRadius - 4; // 圆弧半径
96
+ const startAngle = 0; // 开始点
97
+ const endAngle = 2 * Math.PI; // 结束点
98
+ ctx.arc(x * 2, y * 2, radius, startAngle, endAngle, true);
99
+ ctx.shadowBlur = 24;
100
+ ctx.shadowColor = 'rgba(0, 0, 0, 0.2)';
101
+ ctx.fillStyle = 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')';
102
+ ctx.fill();
103
+ ctx.strokeStyle = '#fff';
104
+ ctx.lineWidth = 8;
105
+ ctx.stroke();
106
+ ctx.scale(2, 2);
107
+ this.canvasThumb.style.width = `${this.radius * 2}px`;
108
+ this.canvasThumb.style.height = `${this.radius * 2}px`;
109
+ },
110
+ getAnnulusImageData(x, y) {
111
+ const ctx = this.annulusContext;
112
+ if (!ctx) {
113
+ console.error('ctx not found');
114
+ return;
115
+ }
116
+ const { data } = ctx.getImageData(x * 2, y * 2, 1, 1);
117
+ const r = data[0];
118
+ const g = data[1];
119
+ const b = data[2];
120
+ this.updateThumbPosition(x, y, { r, g, b });
121
+ const dataRes = {
122
+ position: { x, y },
123
+ touchType: this.touchType,
124
+ };
125
+ this.callMethod('_getAnnulusImageData', dataRes);
126
+ },
127
+ _getRgb(x, y) {
128
+ if (x && y) {
129
+ this.getAnnulusImageData(x, y);
130
+ }
131
+ },
132
+ _getValidMaxMinRes(x, y) {
133
+ const { radius, innerRingRadius } = this;
134
+ const xDistance = Math.abs(x - radius);
135
+ const yDistance = Math.abs(y - radius);
136
+ const distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance);
137
+ const radian = Math.atan2(y - radius, x - radius);
138
+ const angle = radian * (180 / Math.PI);
139
+ if (angle < 45 || angle > 135) {
140
+ const thumbPositionY =
141
+ radius +
142
+ (innerRingRadius + (radius - innerRingRadius) / 2) *
143
+ Math.sin(Math.atan2(y - radius, x - radius));
144
+ const thumbPositionX =
145
+ radius +
146
+ (innerRingRadius + (radius - innerRingRadius) / 2) *
147
+ Math.cos(Math.atan2(y - radius, x - radius));
148
+ return { x: thumbPositionX, y: thumbPositionY };
149
+ }
150
+ if (angle >= 45 && angle < 80) {
151
+ const thumbPositionY =
152
+ radius +
153
+ (innerRingRadius + (radius - innerRingRadius) / 2) *
154
+ Math.sin(Math.atan2(210 - radius, 210 - radius));
155
+ const thumbPositionX =
156
+ radius +
157
+ (innerRingRadius + (radius - innerRingRadius) / 2) *
158
+ Math.cos(Math.atan2(210 - radius, 210 - radius));
159
+ return { x: thumbPositionX, y: thumbPositionY };
160
+ }
161
+ if (angle > 115 && angle <= 135) {
162
+ const thumbPositionY =
163
+ radius +
164
+ (innerRingRadius + (radius - innerRingRadius) / 2) *
165
+ Math.sin(Math.atan2(210 - radius, 70 - radius));
166
+ const thumbPositionX =
167
+ radius +
168
+ (innerRingRadius + (radius - innerRingRadius) / 2) *
169
+ Math.cos(Math.atan2(210 - radius, 70 - radius));
170
+ return { x: thumbPositionX, y: thumbPositionY };
171
+ }
172
+ },
173
+ handleCanvasStartEvent(evt) {
174
+ this.touchType = 'start';
175
+ const { changedTouches } = evt;
176
+ const [point] = changedTouches;
177
+ const { top, left } = this.canvasThumb.getBoundingClientRect();
178
+ const validXY = this._getValidMaxMinRes(point.clientX - left, point.clientY - top);
179
+ if (!validXY) {
180
+ return;
181
+ }
182
+ this._getRgb(validXY.x, validXY.y);
183
+ },
184
+ handleCanvasEndEvent(evt) {
185
+ this.touchType = 'end';
186
+ const { changedTouches } = evt;
187
+ const [point] = changedTouches;
188
+ const { top, left } = this.canvasThumb.getBoundingClientRect();
189
+ const validXY = this._getValidMaxMinRes(point.clientX - left, point.clientY - top);
190
+ if (!validXY) {
191
+ return;
192
+ }
193
+ this._getRgb(validXY.x, validXY.y);
194
+ },
195
+ handleCanvasMoveEvent(evt) {
196
+ this.touchType = 'move';
197
+ const { changedTouches } = evt;
198
+ const [point] = changedTouches;
199
+ const { top, left } = this.canvasThumb.getBoundingClientRect();
200
+ const validXY = this._getValidMaxMinRes(point.clientX - left, point.clientY - top);
201
+ if (!validXY) {
202
+ return;
203
+ }
204
+ this._getRgb(validXY.x, validXY.y);
205
+ },
206
+ addEventListeners() {
207
+ this.canvasThumb.addEventListener('touchstart', this.handleCanvasStartEvent, false);
208
+ this.canvasThumb.addEventListener('touchmove', this.handleCanvasMoveEvent, false);
209
+ this.canvasThumb.addEventListener('touchend', this.handleCanvasEndEvent, false);
210
+ },
211
+ removeEventListeners() {
212
+ this.canvasThumb.removeEventListener('touchstart', this.handleCanvasStartEvent);
213
+ this.canvasThumb.removeEventListener('touchmove', this.handleCanvasMoveEvent);
214
+ this.canvasThumb.removeEventListener('touchend', this.handleCanvasEndEvent);
215
+ },
216
+ });
@@ -0,0 +1,3 @@
1
+ import { kit } from '@ray-js/panel-sdk';
2
+ declare const _default: kit.I18N;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { kit } from '@ray-js/panel-sdk';
2
+ import Strings from './strings';
3
+ var I18N = kit.I18N;
4
+ export default new I18N(Strings);
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ en: {
3
+ temperature: string;
4
+ };
5
+ zh: {
6
+ temperature: string;
7
+ };
8
+ };
9
+ export default _default;
@@ -0,0 +1,8 @@
1
+ export default {
2
+ en: {
3
+ temperature: 'Temperature'
4
+ },
5
+ zh: {
6
+ temperature: '色温'
7
+ }
8
+ };
@@ -0,0 +1,18 @@
1
+ export var web = {
2
+ backgroundColor: '#f2f4f6',
3
+ navigationBarTitleText: ''
4
+ };
5
+ export var wechat = {
6
+ backgroundColor: '#f2f4f6',
7
+ navigationBarTitleText: ''
8
+ };
9
+ export var tuya = {
10
+ backgroundColor: '#f2f4f6',
11
+ navigationBarTitleText: ''
12
+ };
13
+ export var native = {
14
+ backgroundColor: 'transparent',
15
+ isBleOfflineOverlay: false,
16
+ useSafeAreaView: true,
17
+ navigationBarTitleText: ''
18
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ interface IProps {
3
+ canvasId: string;
4
+ isShowColorTip?: boolean;
5
+ radius?: number;
6
+ innerRingRadius?: number;
7
+ temperature: number;
8
+ onTouchStart?: (v: number) => void;
9
+ onTouchMove?: (v: number) => void;
10
+ onTouchEnd?: (v: number) => void;
11
+ }
12
+ declare const WhiteRing: {
13
+ (props: IProps): JSX.Element;
14
+ defaultProps: {
15
+ radius: number;
16
+ innerRingRadius: number;
17
+ isShowColorTip: boolean;
18
+ onTouchStart: () => null;
19
+ onTouchMove: () => null;
20
+ onTouchEnd: () => null;
21
+ };
22
+ };
23
+ export default WhiteRing;
package/lib/index.js ADDED
@@ -0,0 +1,54 @@
1
+ import "core-js/modules/es.math.trunc.js";
2
+ import React from 'react';
3
+ import { View, Image, Text } from '@ray-js/components';
4
+ import clsx from 'clsx';
5
+ import res from './res';
6
+ import Strings from './i18n';
7
+ import AnnulusPickerColor from './component';
8
+ import styled from './index.module.less';
9
+ var ring = res.ring;
10
+ var WhiteRing = function (props) {
11
+ var temperature = props.temperature,
12
+ radius = props.radius,
13
+ canvasId = props.canvasId,
14
+ innerRingRadius = props.innerRingRadius,
15
+ isShowColorTip = props.isShowColorTip,
16
+ onTouchStart = props.onTouchStart,
17
+ onTouchMove = props.onTouchMove,
18
+ onTouchEnd = props.onTouchEnd;
19
+ return /*#__PURE__*/React.createElement(View, {
20
+ className: clsx(styled.container, styled.flexCenter)
21
+ }, /*#__PURE__*/React.createElement(AnnulusPickerColor, {
22
+ canvasId: canvasId,
23
+ value: temperature,
24
+ radius: radius,
25
+ innerRingRadius: innerRingRadius,
26
+ isShowColorTip: isShowColorTip,
27
+ onTouchStart: onTouchStart,
28
+ onTouchMove: onTouchMove,
29
+ onTouchEnd: onTouchEnd
30
+ }), /*#__PURE__*/React.createElement(View, {
31
+ className: clsx(styled.innerBox, styled.flexCenter)
32
+ }, /*#__PURE__*/React.createElement(Image, {
33
+ src: ring,
34
+ className: styled.ringIcon
35
+ }), /*#__PURE__*/React.createElement(View, {
36
+ className: clsx(styled.textBox, styled.flexCenter)
37
+ }, /*#__PURE__*/React.createElement(Text, {
38
+ className: styled.title
39
+ }, Math.trunc(temperature / 10), "%"), /*#__PURE__*/React.createElement(Text, {
40
+ className: styled.desc
41
+ }, Strings.getLang('temperature')))));
42
+ };
43
+ var nilFn = function () {
44
+ return null;
45
+ };
46
+ WhiteRing.defaultProps = {
47
+ radius: 140,
48
+ innerRingRadius: 80,
49
+ isShowColorTip: true,
50
+ onTouchStart: nilFn,
51
+ onTouchMove: nilFn,
52
+ onTouchEnd: nilFn
53
+ };
54
+ export default WhiteRing;
@@ -0,0 +1,41 @@
1
+ .container {
2
+ position: relative;
3
+
4
+ .innerBox {
5
+ width: 276rpx;
6
+ position: absolute;
7
+
8
+ .ringIcon {
9
+ position: absolute;
10
+ width: 276rpx;
11
+ height: 276rpx;
12
+ }
13
+
14
+ .textBox {
15
+ flex-direction: column;
16
+
17
+ .title {
18
+ font-weight: 600;
19
+ font-size: 28px;
20
+ line-height: 39px;
21
+ text-align: center;
22
+ color: #FFFFFF;
23
+ }
24
+
25
+ .desc {
26
+ font-weight: 500;
27
+ font-size: 13px;
28
+ line-height: 18px;
29
+ text-align: center;
30
+ color: rgba(255, 255, 255, .45);
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ .flexCenter {
37
+ display: flex;
38
+ flex: 1;
39
+ align-items: center;
40
+ justify-content: center;
41
+ }
package/lib/props.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ export interface IProps {
2
+ /**
3
+ * @description.zh 色盘id 唯一标识
4
+ * @description.en Color wheel id unique identification
5
+ * @default
6
+ */
7
+ canvasId: string;
8
+ /**
9
+ * @description.zh 默认数值
10
+ * @description.en default value
11
+ * @default
12
+ */
13
+ value: number;
14
+ /**
15
+ * @description.zh 内部色环宽度
16
+ * @description.en The width of inner color ring
17
+ * @default 80
18
+ */
19
+ innerRingRadius?: number;
20
+ /**
21
+ * @description.zh 色盘宽度
22
+ * @description.en The width of color ring
23
+ * @default 140
24
+ */
25
+ radius?: number;
26
+ /**
27
+ * @description.zh 是否展示色圈
28
+ * @description.en Whether to show color circle
29
+ * @default true
30
+ */
31
+ isShowThumb?: boolean;
32
+ /**
33
+ * @description.zh 是否当前颜色文案
34
+ * @description.en Whether the current color text
35
+ * @default false
36
+ */
37
+ isShowColorTip?: boolean;
38
+ /**
39
+ * @description.zh 手指按下时的回调函数
40
+ * @description.en Finger press when the callback function
41
+ * @default ''
42
+ */
43
+ onTouchStart?: (value: number) => void;
44
+ /**
45
+ * @description.zh 手指按下拖动时的回调函数
46
+ * @description.en Finger to press the drag of the callback function
47
+ * @default ''
48
+ */
49
+ onTouchMove?: (value: number) => void;
50
+ /**
51
+ * @description.zh 手指按下结束时的回调函数
52
+ * @description.en Finger press at the end of the callback function
53
+ * @default ''
54
+ */
55
+ onTouchEnd?: (value: number) => void;
56
+ }
package/lib/props.js ADDED
@@ -0,0 +1 @@
1
+ export {};
Binary file
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ ring: any;
3
+ colorBg: any;
4
+ };
5
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import ring from './ring.png';
2
+ import colorBg from './colorBg.png';
3
+ export default {
4
+ ring: ring,
5
+ colorBg: colorBg
6
+ };
Binary file
@@ -0,0 +1,15 @@
1
+ declare module '*.less';
2
+ declare module '*.rjs';
3
+ declare module '*.png';
4
+ declare global {
5
+ interface Window {
6
+ devToolsExtension?: () => any;
7
+ ty: Ty;
8
+ }
9
+ }
10
+
11
+ interface Ty {
12
+ [key]: any;
13
+ }
14
+
15
+ declare const ty: Ty;
@@ -0,0 +1,8 @@
1
+ declare const rgb2hsv: any, hsv2rgb: any;
2
+ declare type HSL = {
3
+ h: number;
4
+ s: number;
5
+ l: number;
6
+ };
7
+ declare const rgbToHsl: (r: number, g: number, b: number) => HSL;
8
+ export { rgbToHsl, rgb2hsv, hsv2rgb };
@@ -0,0 +1,41 @@
1
+ import { utils } from '@ray-js/panel-sdk';
2
+ var rgb2hsv = utils.rgb2hsv,
3
+ hsv2rgb = utils.hsv2rgb;
4
+ /* eslint-disable no-param-reassign */
5
+ var rgbToHsl = function (r, g, b) {
6
+ r /= 255;
7
+ g /= 255;
8
+ b /= 255;
9
+ var max = Math.max(r, g, b);
10
+ var min = Math.min(r, g, b);
11
+ var h;
12
+ var s;
13
+ var l = (max + min) / 2;
14
+ if (max === min) {
15
+ h = 0;
16
+ s = 0; // achromatic
17
+ } else {
18
+ var d = max - min;
19
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
20
+ switch (max) {
21
+ case r:
22
+ h = (g - b) / d + (g < b ? 6 : 0);
23
+ break;
24
+ case g:
25
+ h = (b - r) / d + 2;
26
+ break;
27
+ case b:
28
+ h = (r - g) / d + 4;
29
+ break;
30
+ default:
31
+ break;
32
+ }
33
+ h /= 6;
34
+ }
35
+ return {
36
+ h: h * 360,
37
+ s: s,
38
+ l: l
39
+ };
40
+ };
41
+ export { rgbToHsl, rgb2hsv, hsv2rgb };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@ray-js/lamp-circle-picker",
3
+ "version": "1.1.1",
4
+ "description": "LampUnfilledCornerAnnulusPickerWhite",
5
+ "main": "lib/index",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "license": "MIT",
10
+ "types": "lib/index.d.ts",
11
+ "maintainers": [
12
+ "tuya_npm",
13
+ {
14
+ "name": "tuyafe",
15
+ "email": "tuyafe@tuya.com"
16
+ }
17
+ ],
18
+ "scripts": {
19
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
20
+ "build": "ray build --type=component",
21
+ "watch": "ray start --type=component",
22
+ "build:tuya": "ray build ./example --target=tuya",
23
+ "build:wechat": "ray build ./example --target=wechat",
24
+ "build:web": "ray build ./example --target=web",
25
+ "build:native": "ray build ./example --target=native",
26
+ "start:native": "ray start ./example -t native --verbose",
27
+ "start:tuya": "ray start ./example -t tuya --verbose",
28
+ "start:wechat": "ray start ./example -t wechat --verbose",
29
+ "start:web": "ray start ./example -t web",
30
+ "prepublishOnly": "yarn build",
31
+ "release-it": "standard-version"
32
+ },
33
+ "peerDependencies": {},
34
+ "devDependencies": {
35
+ "@commitlint/cli": "^7.2.1",
36
+ "@commitlint/config-conventional": "^9.0.1",
37
+ "@ray-js/babel-preset-standard": "^0.6.14",
38
+ "@ray-js/cli": "^0.6.14",
39
+ "@ray-js/components": "^0.6.14",
40
+ "@ray-js/framework": "^0.6.14",
41
+ "@ray-js/rn-transformer-helper": "^0.5.5",
42
+ "@ray-js/types": "^0.6.14",
43
+ "@types/node": "^17.0.43",
44
+ "core-js": "^3.19.1",
45
+ "eslint-config-tuya-panel": "^0.4.1",
46
+ "husky": "^1.2.0",
47
+ "lint-staged": "^10.2.11",
48
+ "standard-version": "9.3.2"
49
+ },
50
+ "husky": {
51
+ "hooks": {
52
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
53
+ "pre-commit": "lint-staged"
54
+ }
55
+ },
56
+ "lint-staged": {
57
+ "*.{ts,tsx,js,jsx}": [
58
+ "eslint --fix",
59
+ "git add"
60
+ ],
61
+ "*.{json,md,yml,yaml}": [
62
+ "prettier --write",
63
+ "git add"
64
+ ]
65
+ },
66
+ "dependencies": {
67
+ "@ray-js/panel-sdk": "^1.1.4",
68
+ "clsx": "^1.2.1"
69
+ }
70
+ }