@ray-js/lamp-bead-strip 1.0.3-beta-33 → 1.1.0-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 +57 -0
- package/lib/components/index.rjs +26 -1
- package/lib/index.js +8 -2
- package/lib/props.d.ts +24 -0
- package/lib/props.js +4 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@ yarn start:tuya
|
|
|
29
29
|
|
|
30
30
|
### Basic usage
|
|
31
31
|
|
|
32
|
+
`colors`and `canvasId`are mandatory, otherwise the animation cannot run`canvasId`must ensure page uniqueness. When we input different animation modes`mode`, the component will automatically play the animation.
|
|
33
|
+
|
|
32
34
|
```tsx
|
|
33
35
|
import LampBeadStrip from '@ray-js/lamp-bead-strip';
|
|
34
36
|
export default () => (
|
|
@@ -44,6 +46,8 @@ export default () => (
|
|
|
44
46
|
|
|
45
47
|
### Pauses
|
|
46
48
|
|
|
49
|
+
`ready`allows you to set whether the animation of the component plays or pauses.
|
|
50
|
+
|
|
47
51
|
```tsx
|
|
48
52
|
import LampBeadStrip from '@ray-js/lamp-bead-strip';
|
|
49
53
|
export default () => (
|
|
@@ -57,8 +61,36 @@ export default () => (
|
|
|
57
61
|
);
|
|
58
62
|
```
|
|
59
63
|
|
|
64
|
+
### Customize Scaling Size
|
|
65
|
+
|
|
66
|
+
Since the components are drawn through canvas, the internal dimensions are fixed. The component internally handles screen scaling logic, which is controlled through the`scale`property. If you want to modify the size of a component, you can customize the`scale`property to achieve your goal. The following use case expects the component size to be`1.1`times larger than before.
|
|
67
|
+
|
|
68
|
+
> It should be noted that the component only sets the scale once during initialization, so if the scale property is changed or set after initialization, it will be invalid
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import LampBeadStrip from '@ray-js/lamp-bead-strip';
|
|
72
|
+
import { getSystemInfoSync } from '@ray-js/ray';
|
|
73
|
+
|
|
74
|
+
const { windowWidth = 375 } = getSystemInfoSync();
|
|
75
|
+
export default () => {
|
|
76
|
+
const scale = (windowWidth / 375) * 1.1;
|
|
77
|
+
return (
|
|
78
|
+
<LampBeadStrip
|
|
79
|
+
containerStyle={`height: ${48 * 1.1}rpx;width:${570 * 1.1}rpx;`}
|
|
80
|
+
mode={16}
|
|
81
|
+
canvasId="template2"
|
|
82
|
+
scale={scale}
|
|
83
|
+
colors={['rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,0,255)']}
|
|
84
|
+
contentValue={{ expand: 1 }}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
60
90
|
### Set the light off color
|
|
61
91
|
|
|
92
|
+
`closeColor` can set the color of lights that do not have color in the animation, that is, the color of the light beads that turn off the lights in the device. This way, the light strip component can adapt to multiple background colors, preventing the node color that turns off the lights from being the same as the background color.
|
|
93
|
+
|
|
62
94
|
```tsx
|
|
63
95
|
import LampBeadStrip from '@ray-js/lamp-bead-strip';
|
|
64
96
|
|
|
@@ -74,6 +106,31 @@ export default () => {
|
|
|
74
106
|
};
|
|
75
107
|
```
|
|
76
108
|
|
|
109
|
+
### Custom Animation(v1.1.0)
|
|
110
|
+
|
|
111
|
+
`customAnimationList`: Attributes can be used to customize animations. They are a list of animation frames, which is a two-dimensional array. Each internal array consists of 20 colors, equivalent to the colors of 20 lights in the animation frame component. The component will automatically loop through this animation list.
|
|
112
|
+
`customAnimationChangeTime`: Switching the time of custom animation, the playback speed is controlled by this attribute, representing how much time to switch one stitch, in milliseconds.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import LampBeadStrip from '@ray-js/lamp-bead-strip';
|
|
116
|
+
import React, { useMemo } from 'react';
|
|
117
|
+
|
|
118
|
+
export default () => {
|
|
119
|
+
const customAnimationList = useMemo(() => {
|
|
120
|
+
const colors = ['rgb(255,0,0)', 'rgb(0,255,0)', 'rgb(0,0,255)'];
|
|
121
|
+
return colors.map(item => new Array(20).fill(item));
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<LampBeadStrip
|
|
126
|
+
canvasId="template4"
|
|
127
|
+
customAnimationList={customAnimationList}
|
|
128
|
+
customAnimationChangeTime={500}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
77
134
|
### Animation Mode
|
|
78
135
|
|
|
79
136
|
> Phase 1: 6, 1. Gradient, 2. Jump, 3. Breath, 4. Blink, 10. Flowing Water, 11. Rainbow
|
package/lib/components/index.rjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: mjh
|
|
3
3
|
* @Date: 2024-09-02 11:42:04
|
|
4
4
|
* @LastEditors: mjh
|
|
5
|
-
* @LastEditTime:
|
|
5
|
+
* @LastEditTime: 2025-01-20 10:05:42
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -20,6 +20,7 @@ export default Render({
|
|
|
20
20
|
mode: null,
|
|
21
21
|
animationStore: null,
|
|
22
22
|
closeRgb: null,
|
|
23
|
+
preCustom: null,
|
|
23
24
|
/**
|
|
24
25
|
* @name: 渲染灯带动画
|
|
25
26
|
* @desc:
|
|
@@ -39,6 +40,11 @@ export default Render({
|
|
|
39
40
|
this.ctx.scale(this.scale, this.scale);
|
|
40
41
|
}
|
|
41
42
|
this.ready = props.ready ?? true
|
|
43
|
+
// 自定义动画模式
|
|
44
|
+
if (props.customAnimationList) {
|
|
45
|
+
this.checkCustomAnimation(props)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
42
48
|
// 只有关键属性变化才重置动画
|
|
43
49
|
const isSameContent = `${props.closeColor}${props.mode}${props.colors.length}${props.contentValue.expand}${props.contentValue.segmented}` === `${this.closeRgb}${this.mode}${this.colors.length}${this.contentValue.expand}${this.contentValue.segmented}`
|
|
44
50
|
this.closeRgb = props.closeColor;
|
|
@@ -94,6 +100,25 @@ export default Render({
|
|
|
94
100
|
this.offset += 1;
|
|
95
101
|
if(this.offset === length) this.offset = 0
|
|
96
102
|
},
|
|
103
|
+
checkCustomAnimation(props) {
|
|
104
|
+
const isSameContent = this.preCustom ? `${JSON.stringify(props.customAnimationList)}${props.customAnimationChangeTime}` === this.preCustom : false;
|
|
105
|
+
this.preCustom = `${JSON.stringify(props.customAnimationList)}${props.customAnimationChangeTime}`;
|
|
106
|
+
// 重置动画
|
|
107
|
+
if (!isSameContent) {
|
|
108
|
+
this.offset = 0
|
|
109
|
+
}
|
|
110
|
+
this.stopLight();
|
|
111
|
+
this.drawCustom(props.customAnimationList);
|
|
112
|
+
if(!this.ready) return
|
|
113
|
+
this.timer = setInterval(() => {
|
|
114
|
+
this.drawCustom(props.customAnimationList);
|
|
115
|
+
}, props.customAnimationChangeTime);
|
|
116
|
+
},
|
|
117
|
+
drawCustom(colorList) {
|
|
118
|
+
this.drawPoint(colorList[this.offset]);
|
|
119
|
+
this.offset += 1;
|
|
120
|
+
if(this.offset === colorList.length) this.offset = 0
|
|
121
|
+
},
|
|
97
122
|
/**
|
|
98
123
|
* @name: 绘制点
|
|
99
124
|
* @desc:
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
const _excluded = ["standardScale"];
|
|
2
4
|
import React from 'react';
|
|
3
5
|
import LampBeadStripRjs from './components';
|
|
4
6
|
import { getSystemInfoRes } from './utils';
|
|
@@ -7,11 +9,15 @@ const {
|
|
|
7
9
|
windowWidth = 375
|
|
8
10
|
} = getSystemInfoRes();
|
|
9
11
|
const LampBeadStrip = props => {
|
|
12
|
+
const {
|
|
13
|
+
standardScale = 1
|
|
14
|
+
} = props,
|
|
15
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
10
16
|
// 组件缩放能力
|
|
11
17
|
|
|
12
18
|
return /*#__PURE__*/React.createElement(LampBeadStripRjs, {
|
|
13
|
-
prop: _objectSpread(_objectSpread({},
|
|
14
|
-
scale:
|
|
19
|
+
prop: _objectSpread(_objectSpread({}, rest), {}, {
|
|
20
|
+
scale: rest.scale || windowWidth / 375 * standardScale
|
|
15
21
|
})
|
|
16
22
|
});
|
|
17
23
|
};
|
package/lib/props.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface IProps {
|
|
|
6
6
|
*/
|
|
7
7
|
className?: string;
|
|
8
8
|
/**
|
|
9
|
+
* @description.zh 动画模式 1-16
|
|
9
10
|
* @description.en Animation mode 1-16
|
|
10
11
|
* @default 1
|
|
11
12
|
*/
|
|
@@ -31,12 +32,14 @@ export interface IProps {
|
|
|
31
32
|
*/
|
|
32
33
|
colors: string[];
|
|
33
34
|
/**
|
|
35
|
+
* @description.zh 动画速度 1%-100% 对应动画帧刷新间隔 60ms~350ms,速度值越大,间隔越短
|
|
34
36
|
* @description.en The animation speed ranges from 1% to 100%, corresponding to a frame refresh interval of 60ms to 350ms. The larger the speed value, the shorter the interval
|
|
35
37
|
* @default 50
|
|
36
38
|
*/
|
|
37
39
|
speed?: number;
|
|
38
40
|
/**
|
|
39
41
|
* @description.zh 是否播放动画
|
|
42
|
+
* @description.en Whether to play the animation.
|
|
40
43
|
* @default true
|
|
41
44
|
*/
|
|
42
45
|
ready?: boolean;
|
|
@@ -60,5 +63,26 @@ export interface IProps {
|
|
|
60
63
|
* @default 'rgb(58,58,58)'
|
|
61
64
|
*/
|
|
62
65
|
closeColor?: string;
|
|
66
|
+
/**
|
|
67
|
+
* @description.zh 自定义动画列表
|
|
68
|
+
* @description.en Custom Animation List
|
|
69
|
+
* @default undefined
|
|
70
|
+
* @version 1.1.0
|
|
71
|
+
*/
|
|
72
|
+
customAnimationList?: string[][];
|
|
73
|
+
/**
|
|
74
|
+
* @description.zh 自定义动画切换帧时间,单位毫秒
|
|
75
|
+
* @description.en Custom animation switching frame time, in milliseconds
|
|
76
|
+
* @default 100
|
|
77
|
+
* @version 1.1.0
|
|
78
|
+
*/
|
|
79
|
+
customAnimationChangeTime?: number;
|
|
80
|
+
/**
|
|
81
|
+
* @description.zh 标准缩放比例,内部表达式: windowWidth / 375 * standardScale, 目的简化书写
|
|
82
|
+
* @description.en Standard scaling ratio, internal expression: windowWidth / 375 * standardScale, Purpose: Simplify Writing
|
|
83
|
+
* @default 1
|
|
84
|
+
* @version 1.1.0
|
|
85
|
+
*/
|
|
86
|
+
standardScale?: number;
|
|
63
87
|
}
|
|
64
88
|
export declare const defaultProps: IProps;
|
package/lib/props.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: mjh
|
|
3
3
|
* @Date: 2024-09-12 09:55:13
|
|
4
4
|
* @LastEditors: mjh
|
|
5
|
-
* @LastEditTime:
|
|
5
|
+
* @LastEditTime: 2025-01-20 10:37:05
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -14,5 +14,7 @@ export const defaultProps = {
|
|
|
14
14
|
colors: [],
|
|
15
15
|
contentValue: {},
|
|
16
16
|
closeColor: 'rgb(58,58,58)',
|
|
17
|
-
className: ''
|
|
17
|
+
className: '',
|
|
18
|
+
customAnimationChangeTime: 100,
|
|
19
|
+
standardScale: 1
|
|
18
20
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/lamp-bead-strip",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-beta-2",
|
|
4
4
|
"description": "动画灯珠条带",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
20
|
-
"build": "ray build --type=component",
|
|
20
|
+
"build": "patch-package && ray build --type=component",
|
|
21
21
|
"watch": "ray start --type=component --output ./example/src/lib",
|
|
22
|
-
"build:tuya": "ray build ./example
|
|
22
|
+
"build:tuya": "ray build ./example",
|
|
23
23
|
"build:wechat": "ray build ./example --target=wechat",
|
|
24
24
|
"build:web": "ray build ./example --target=web",
|
|
25
25
|
"build:native": "ray build ./example --target=native",
|
|
26
26
|
"start:native": "ray start ./example -t native --verbose",
|
|
27
|
-
"start:tuya": "ray start ./example
|
|
27
|
+
"start:tuya": "ray start ./example",
|
|
28
28
|
"start:wechat": "ray start ./example -t wechat --verbose",
|
|
29
29
|
"start:web": "ray start ./example -t web",
|
|
30
30
|
"prepublishOnly": "yarn build",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@commitlint/cli": "^7.2.1",
|
|
39
39
|
"@commitlint/config-conventional": "^9.0.1",
|
|
40
|
-
"@ray-js/cli": "^1.
|
|
41
|
-
"@ray-js/panel-sdk": "^1.
|
|
42
|
-
"@ray-js/ray": "^1.
|
|
40
|
+
"@ray-js/cli": "^1.4.9",
|
|
41
|
+
"@ray-js/panel-sdk": "^1.12.1",
|
|
42
|
+
"@ray-js/ray": "^1.4.9",
|
|
43
43
|
"core-js": "^3.19.1",
|
|
44
44
|
"eslint-config-tuya-panel": "^0.4.2",
|
|
45
45
|
"husky": "^1.2.0",
|