@ray-js/lamp-circle-picker 1.0.4 → 1.0.5-beta-2

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 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 var web = {
1
+ export const web = {
2
2
  backgroundColor: '#f2f4f6',
3
3
  navigationBarTitleText: ''
4
4
  };
5
- export var wechat = {
5
+ export const wechat = {
6
6
  backgroundColor: '#f2f4f6',
7
7
  navigationBarTitleText: ''
8
8
  };
9
- export var tuya = {
9
+ export const tuya = {
10
10
  backgroundColor: '#f2f4f6',
11
11
  navigationBarTitleText: ''
12
12
  };
13
- export var native = {
13
+ export const native = {
14
14
  backgroundColor: 'transparent',
15
15
  isBleOfflineOverlay: false,
16
16
  useSafeAreaView: true,
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
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;
@@ -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
- bindstart: function onTouchStart(e) {
10
- var detail = e.detail;
11
- var temp = Math.floor(detail);
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: function onTouchMove(e) {
15
- var detail = e.detail;
16
- var temp = Math.floor(detail);
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: function onTouchEnd(e) {
20
- var detail = e.detail;
21
- var temp = Math.floor(detail);
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
  });
@@ -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
@@ -1,11 +1,11 @@
1
1
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
2
- var nilFn = function () {
3
- return null;
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
- var ETipRectPosition = {
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.**': function value(v) {
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: function attached() {
57
+ attached() {
53
58
  this.render = new Render(this);
54
- var _this$data = this.data,
55
- radius = _this$data.radius,
56
- innerRingRadius = _this$data.innerRingRadius;
59
+ const {
60
+ radius,
61
+ innerRingRadius
62
+ } = this.data;
57
63
  this.render._setCircles(radius, innerRingRadius);
58
64
  },
59
- ready: function ready() {
60
- var _this = this;
61
- var canvasId = this.data.canvasId;
65
+ ready() {
66
+ const {
67
+ canvasId
68
+ } = this.data;
62
69
  this.initCanvas();
63
- setTimeout(function () {
64
- _this.initCanvas();
65
- _this.render.checkIsRender(canvasId);
70
+ setTimeout(() => {
71
+ this.initCanvas();
72
+ this.render.checkIsRender(canvasId);
66
73
  }, 300);
67
74
  }
68
75
  },
69
76
  methods: {
70
- getCanvas: function getCanvas(canvas) {
77
+ getCanvas(canvas) {
71
78
  if (JSON.stringify(canvas) === '{}') {
72
79
  this.initCanvas();
73
80
  }
74
81
  },
75
- initCanvas: function initCanvas() {
76
- var _this$data2 = this.data,
77
- canvasId = _this$data2.canvasId,
78
- radius = _this$data2.radius,
79
- innerRingRadius = _this$data2.innerRingRadius,
80
- _this$data2$value = _this$data2.value,
81
- value = _this$data2$value === void 0 ? 0 : _this$data2$value;
82
- var ratio = getSystemInfo().pixelRatio || 2;
83
- canvasId && this.render.renderAnnulusColor(canvasId, radius, innerRingRadius, ratio);
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: function _updatePosByRgb(value) {
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: function _getRgb(x, y) {
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: function _getAnnulusImageData(dataRes) {
99
- var position = dataRes.position,
100
- touchType = dataRes.touchType;
110
+ _getAnnulusImageData(dataRes) {
111
+ const {
112
+ position,
113
+ touchType
114
+ } = dataRes;
101
115
  this.touchType = touchType;
102
- var result = this._getLengthByAnglePosition(position.x, position.y);
116
+ const result = this._getLengthByAnglePosition(position.x, position.y);
103
117
  this.lastValue = result;
104
118
  this.triggerEvent(touchType, result);
105
119
  },
106
- _getLengthByAnglePosition: function _getLengthByAnglePosition(x, y) {
107
- var radius = this.data.radius;
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
- var angleData = 0;
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
- var result = Math.round(angleData / 270 * 1000);
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
- const canvas = await getCanvasById(id);
8
- canvas.width = radius * 4;
9
- canvas.height = radius * 4;
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 dataRes = {
130
+ const emitRes = {
122
131
  position: { x, y },
123
132
  touchType: this.touchType,
124
133
  };
125
- this.callMethod('_getAnnulusImageData', dataRes);
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) {
@@ -0,0 +1,12 @@
1
+ /* eslint-disable no-undef */
2
+ import Render from './index.rjs';
3
+ Component({
4
+ lifetimes: {
5
+ created() {
6
+ this.render = new Render(this);
7
+ },
8
+ ready() {
9
+ this.render.renderChannel();
10
+ }
11
+ }
12
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,8 @@
1
+ export default Render({
2
+ renderChannel() {
3
+ const eventChannelName = 'lampCirclePickerEventChannel';
4
+ this.instance.eventChannel.on(eventChannelName, (e) => {
5
+ console.log('eventChannel get', e);
6
+ });
7
+ },
8
+ });
@@ -0,0 +1,4 @@
1
+ <view
2
+ class="container"
3
+ >
4
+ </view>
@@ -0,0 +1,6 @@
1
+ .container {
2
+ position: relative;
3
+ display: flex;
4
+ align-items: center;
5
+ justify-content: center;
6
+ }
@@ -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
@@ -1,4 +1,6 @@
1
1
  import { kit } from '@ray-js/panel-sdk';
2
2
  import Strings from './strings';
3
- var I18N = kit.I18N;
3
+ const {
4
+ I18N
5
+ } = kit;
4
6
  export default new I18N(Strings);
@@ -1,16 +1,16 @@
1
- export var web = {
1
+ export const web = {
2
2
  backgroundColor: '#f2f4f6',
3
3
  navigationBarTitleText: ''
4
4
  };
5
- export var wechat = {
5
+ export const wechat = {
6
6
  backgroundColor: '#f2f4f6',
7
7
  navigationBarTitleText: ''
8
8
  };
9
- export var tuya = {
9
+ export const tuya = {
10
10
  backgroundColor: '#f2f4f6',
11
11
  navigationBarTitleText: ''
12
12
  };
13
- export var native = {
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,25 @@
1
- /// <reference types="react" />
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;
12
+ titleStyle?: React.CSSProperties;
13
+ descStyle?: React.CSSProperties;
14
+ style?: React.CSSProperties;
10
15
  }
11
16
  declare const LampCirclePicker: {
12
- (props: IProps): JSX.Element;
17
+ (props: IProps): React.JSX.Element;
13
18
  defaultProps: {
14
19
  radius: number;
15
20
  innerRingRadius: number;
21
+ useEventChannel: boolean;
22
+ eventChannelName: string;
16
23
  onTouchStart: () => null;
17
24
  onTouchMove: () => null;
18
25
  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,35 @@ 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
- var ring = res.ring;
10
- var LampCirclePicker = function (props) {
11
- var value = props.value,
12
- temperature = props.temperature,
13
- radius = props.radius,
14
- innerRingRadius = props.innerRingRadius,
15
- onTouchStart = props.onTouchStart,
16
- onTouchMove = props.onTouchMove,
17
- onTouchEnd = props.onTouchEnd;
18
- var innerImgRadius = innerRingRadius * 4 * 0.8;
19
- var _value = value !== null && value !== void 0 ? value : temperature;
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
+ titleStyle,
23
+ descStyle,
24
+ style
25
+ } = props;
26
+ const innerImgRadius = innerRingRadius * 4 * 0.8;
27
+ const _value = value !== null && value !== void 0 ? value : temperature;
20
28
  return /*#__PURE__*/React.createElement(View, {
21
- className: clsx(styled.container, styled.flexCenter)
29
+ className: clsx(styled.container, styled.flexCenter),
30
+ style: style
22
31
  }, /*#__PURE__*/React.createElement(AnnulusPickerColor, {
23
32
  value: _value,
24
33
  radius: radius,
25
34
  innerRingRadius: innerRingRadius,
35
+ useEventChannel: useEventChannel || false,
36
+ eventChannelName: eventChannelName,
26
37
  onTouchStart: onTouchStart,
27
38
  onTouchMove: onTouchMove,
28
39
  onTouchEnd: onTouchEnd
@@ -38,17 +49,19 @@ var LampCirclePicker = function (props) {
38
49
  }), /*#__PURE__*/React.createElement(View, {
39
50
  className: clsx(styled.textBox, styled.flexCenter)
40
51
  }, /*#__PURE__*/React.createElement(Text, {
41
- className: styled.title
52
+ className: styled.title,
53
+ style: titleStyle
42
54
  }, Math.trunc(_value / 10), "%"), /*#__PURE__*/React.createElement(Text, {
43
- className: styled.desc
55
+ className: styled.desc,
56
+ style: descStyle
44
57
  }, Strings.getLang('temperature')))));
45
58
  };
46
- var nilFn = function () {
47
- return null;
48
- };
59
+ const nilFn = () => null;
49
60
  LampCirclePicker.defaultProps = {
50
61
  radius: 140,
51
62
  innerRingRadius: 80,
63
+ useEventChannel: false,
64
+ eventChannelName: 'lampCirclePickerEventChannel',
52
65
  onTouchStart: nilFn,
53
66
  onTouchMove: nilFn,
54
67
  onTouchEnd: nilFn
package/lib/res/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import ring from './ring.png';
2
2
  import colorBg from './colorBg.png';
3
3
  export default {
4
- ring: ring,
5
- colorBg: colorBg
4
+ ring,
5
+ colorBg
6
6
  };
@@ -1,5 +1,5 @@
1
1
  declare const rgb2hsv: any, hsv2rgb: any;
2
- declare type HSL = {
2
+ type HSL = {
3
3
  h: number;
4
4
  s: number;
5
5
  l: number;
@@ -1,21 +1,23 @@
1
1
  import { utils } from '@ray-js/panel-sdk';
2
- var rgb2hsv = utils.rgb2hsv,
3
- hsv2rgb = utils.hsv2rgb;
2
+ const {
3
+ rgb2hsv,
4
+ hsv2rgb
5
+ } = utils;
4
6
  /* eslint-disable no-param-reassign */
5
- var rgbToHsl = function (r, g, b) {
7
+ const rgbToHsl = (r, g, b) => {
6
8
  r /= 255;
7
9
  g /= 255;
8
10
  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;
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
- var d = max - min;
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: s,
38
- l: l
39
+ s,
40
+ l
39
41
  };
40
42
  };
41
43
  export { rgbToHsl, rgb2hsv, hsv2rgb };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lamp-circle-picker",
3
- "version": "1.0.4",
3
+ "version": "1.0.5-beta-2",
4
4
  "description": "照明缺角色环",
5
5
  "main": "lib/index",
6
6
  "files": [