@ray-js/lamp-bead-strip 1.0.1-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.
@@ -0,0 +1,115 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:28:07
6
+ * @Description:
7
+ */
8
+ import { arrayFill, getListByIndex, findOverlapIndices, averageRGBColors } from '../utils';
9
+
10
+ /** 穿梭 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const min = -1;
13
+ const max = 20;
14
+ let fastIndex = min;
15
+ let fastColorIndex = 0;
16
+ let fastDirection = 0;
17
+ let slowIndex = max;
18
+ let slowColorIndex = 1;
19
+ let slowDirection = 1;
20
+ let time = colors.length * 26 * 2 - 1;
21
+ const closeList = arrayFill(20, closeRgb);
22
+ const colorList = [];
23
+ while (time >= 0) {
24
+ const currCloseList = [...closeList];
25
+ // fast
26
+ let fastIndexArr = [];
27
+ const fastColor = getListByIndex(colors, fastColorIndex);
28
+ if (!fastDirection) {
29
+ const fastStartIndex = fastIndex - 5 + 1;
30
+ const fastEndIndex = fastIndex;
31
+ fastIndexArr = [fastStartIndex, fastEndIndex];
32
+ const fastColorNumber = 5 + fastStartIndex > 5 ? 5 : 5 + fastStartIndex;
33
+ const fastColorList = arrayFill(fastColorNumber, fastColor);
34
+ if (fastColorNumber > 0) {
35
+ currCloseList.splice(fastStartIndex >= 0 ? fastStartIndex : 0, fastColorNumber, ...fastColorList);
36
+ }
37
+ } else {
38
+ const fastStartIndex = fastIndex;
39
+ const fastEndIndex = 5 + fastIndex - 1;
40
+ fastIndexArr = [fastStartIndex, fastEndIndex];
41
+ const fastColorNumber = fastStartIndex < 0 ? 5 + fastStartIndex : 20 - fastIndex > 5 ? 5 : 20 - fastIndex;
42
+ const fastColorList = arrayFill(fastColorNumber, fastColor);
43
+ if (fastColorNumber > 0) {
44
+ currCloseList.splice(fastStartIndex >= 0 ? fastStartIndex : 0, fastColorNumber, ...fastColorList);
45
+ }
46
+ }
47
+
48
+ // slow
49
+ let slowIndexArr = [];
50
+ const slowColor = getListByIndex(colors, slowColorIndex);
51
+ if (slowDirection) {
52
+ const slowStartIndex = slowIndex;
53
+ const slowEndIndex = 5 + slowIndex - 1;
54
+ slowIndexArr = [slowStartIndex, slowEndIndex];
55
+ const slowColorNumber = slowStartIndex < 0 ? 5 + slowStartIndex : 20 - slowIndex > 5 ? 5 : 20 - slowIndex;
56
+ const slowColorList = arrayFill(slowColorNumber, slowColor);
57
+ if (slowColorNumber > 0) {
58
+ currCloseList.splice(slowStartIndex >= 0 ? slowStartIndex : 0, slowColorNumber, ...slowColorList);
59
+ }
60
+ } else {
61
+ const slowStartIndex = slowIndex - 5 + 1;
62
+ const slowEndIndex = slowIndex;
63
+ slowIndexArr = [slowStartIndex, slowEndIndex];
64
+ const slowColorNumber = 5 + slowStartIndex > 5 ? 5 : 5 + slowStartIndex;
65
+ const slowColorList = arrayFill(slowColorNumber, slowColor);
66
+ if (slowColorNumber > 0) {
67
+ currCloseList.splice(slowStartIndex >= 0 ? slowStartIndex : 0, slowColorNumber, ...slowColorList);
68
+ }
69
+ }
70
+
71
+ // 合并逻辑
72
+ const staggerList = findOverlapIndices(fastIndexArr, slowIndexArr);
73
+ if (staggerList.length) {
74
+ const averageColor = averageRGBColors([fastColor, slowColor]);
75
+ currCloseList.splice(staggerList[0], staggerList.length, ...arrayFill(staggerList.length, averageColor));
76
+ }
77
+ if (!fastDirection) {
78
+ fastIndex += 2;
79
+ } else {
80
+ fastIndex -= 2;
81
+ }
82
+ if (slowDirection) {
83
+ slowIndex--;
84
+ } else {
85
+ slowIndex++;
86
+ }
87
+ if (!fastDirection && fastIndexArr[0] >= max) {
88
+ fastColorIndex++;
89
+ fastDirection = 1;
90
+ fastIndex = max;
91
+ }
92
+ if (fastDirection && fastIndexArr[1] <= min) {
93
+ fastColorIndex++;
94
+ fastDirection = 0;
95
+ fastIndex = min;
96
+ }
97
+ if (!slowDirection && slowIndexArr[0] === max) {
98
+ slowColorIndex++;
99
+ slowDirection = 1;
100
+ slowIndex = max;
101
+ }
102
+ if (slowDirection && slowIndexArr[1] === min) {
103
+ slowColorIndex++;
104
+ slowDirection = 0;
105
+ slowIndex = min;
106
+ }
107
+ time--;
108
+ colorList.push(currCloseList);
109
+ }
110
+ return {
111
+ colorList,
112
+ length: colorList.length
113
+ };
114
+ };
115
+ export default mode;
@@ -0,0 +1,32 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:28:35
6
+ * @Description:
7
+ */
8
+ import { arrayFill } from '../utils';
9
+
10
+ /** 乱闪 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const numberRange = [8, 10, 15, 18];
13
+ const closeColors = arrayFill(20, closeRgb);
14
+ const colorAnimation = arrayFill(20, '').map(() => {
15
+ const lightNum = numberRange[Math.ceil(Math.random() * (numberRange.length - 1))];
16
+ const lightArr = [...closeColors];
17
+ arrayFill(lightNum, '').forEach(() => {
18
+ const color = colors[Math.round(Math.random() * (colors.length - 1))];
19
+ const lightIndexList = lightArr.map((item, index) => item !== closeRgb ? null : index).filter(item => item !== null);
20
+ const randomIndex = Math.random() * (lightIndexList.length - 1);
21
+ const index = Math.round(randomIndex);
22
+ const lightIndex = lightIndexList[index];
23
+ lightArr[lightIndex] = color;
24
+ });
25
+ return arrayFill(3, lightArr);
26
+ }).flat(1);
27
+ return {
28
+ colorList: colorAnimation,
29
+ length: colorAnimation.length
30
+ };
31
+ };
32
+ export default mode;
@@ -0,0 +1,55 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:28:53
6
+ * @Description:
7
+ */
8
+ import { arrayFill, getListByIndex } from '../utils';
9
+
10
+ /** 开合 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const {
13
+ expand
14
+ } = option || {};
15
+ const closeColors = arrayFill(20, closeRgb);
16
+ const colorAnimation = colors.map((item, index) => {
17
+ const leftColor = item;
18
+ const rightColor = getListByIndex(colors, index + 1);
19
+ const listClose = arrayFill(11, '').map((_, ind) => {
20
+ const leftColors = arrayFill(ind, leftColor);
21
+ const currList = [...closeColors];
22
+ currList.splice(0, ind, ...leftColors);
23
+ if (expand) {
24
+ const rightNum = 10 - ind;
25
+ const rightColors = arrayFill(rightNum, rightColor);
26
+ currList.splice(currList.length - rightNum, rightNum, ...rightColors);
27
+ } else {
28
+ const rightColors = arrayFill(ind, rightColor);
29
+ currList.splice(currList.length - ind, ind, ...rightColors);
30
+ }
31
+ return currList;
32
+ });
33
+ const listOpen = arrayFill(11, '').map((_, indexs) => {
34
+ const currIndex = 10 - indexs;
35
+ const leftColors = arrayFill(currIndex, leftColor);
36
+ const currList = [...closeColors];
37
+ currList.splice(0, currIndex, ...leftColors);
38
+ if (expand) {
39
+ const rightColorExpand = getListByIndex(colors, index + 2);
40
+ const rightColors = arrayFill(indexs, rightColorExpand);
41
+ currList.splice(currList.length - indexs, indexs, ...rightColors);
42
+ } else {
43
+ const rightColors = arrayFill(currIndex, rightColor);
44
+ currList.splice(currList.length - currIndex, currIndex, ...rightColors);
45
+ }
46
+ return currList;
47
+ });
48
+ return [listClose, listOpen].flat(1);
49
+ }).flat(1);
50
+ return {
51
+ colorList: colorAnimation,
52
+ length: colorAnimation.length
53
+ };
54
+ };
55
+ export default mode;
@@ -0,0 +1,65 @@
1
+ import { arrayFill } from '../utils';
2
+
3
+ /** 跳变 */
4
+ const mode = (colors, option) => {
5
+ const {
6
+ segmented
7
+ } = option || {};
8
+ if (!segmented) {
9
+ let allColor = [];
10
+ colors.forEach(element => {
11
+ const colorList = arrayFill(8, element);
12
+ allColor = [...allColor, ...colorList];
13
+ });
14
+ const colorList = allColor.map(item => arrayFill(20, item));
15
+ return {
16
+ colorList,
17
+ length: colorList.length
18
+ };
19
+ }
20
+ let num = 0;
21
+ let currColors = colors;
22
+ switch (colors.length) {
23
+ case 2:
24
+ num = 10;
25
+ currColors = arrayFill(2, colors).flat(1);
26
+ break;
27
+ case 3:
28
+ num = 7;
29
+ currColors = arrayFill(20, colors).flat(1);
30
+ break;
31
+ case 4:
32
+ num = 5;
33
+ currColors = arrayFill(2, colors).flat(1);
34
+ break;
35
+ case 5:
36
+ num = 4;
37
+ currColors = arrayFill(2, colors).flat(1);
38
+ break;
39
+ case 6:
40
+ num = 5;
41
+ currColors = arrayFill(2, colors).flat(1);
42
+ break;
43
+ case 7:
44
+ num = 5;
45
+ currColors = arrayFill(4, colors).flat(1);
46
+ break;
47
+ case 8:
48
+ num = 5;
49
+ break;
50
+ default:
51
+ break;
52
+ }
53
+ const allColorList = currColors.map(item => arrayFill(num, item)).flat(1);
54
+ const colorList = arrayFill(allColorList.length / num, '').map((_, index) => {
55
+ const endIndex = index * num + 20;
56
+ if (endIndex >= allColorList.length) return [];
57
+ const list = allColorList.slice(index * num, index * num + 20).reverse();
58
+ return arrayFill(8, list);
59
+ }).flat(1);
60
+ return {
61
+ colorList,
62
+ length: colorList.length
63
+ };
64
+ };
65
+ export default mode;
@@ -0,0 +1,30 @@
1
+ import { generateGradientColors, getListByIndex, arrayFill } from '../utils';
2
+
3
+ /** 呼吸 */
4
+ const mode = (colors, option, closeRgb) => {
5
+ const {
6
+ segmented
7
+ } = option || {};
8
+ let allColor = [];
9
+ colors.forEach((element, index) => {
10
+ const afterColor = colors[index + 1] || colors[0];
11
+ const colorList = generateGradientColors([element, closeRgb], 5);
12
+ const afterList = generateGradientColors([closeRgb, afterColor], 5);
13
+ allColor = [...allColor, ...colorList, ...afterList];
14
+ });
15
+ if (!segmented) {
16
+ const colorList = allColor.map(item => arrayFill(20, item));
17
+ return {
18
+ colorList,
19
+ length: colorList.length
20
+ };
21
+ }
22
+ const colorList = allColor.map((_, index) => {
23
+ return [...arrayFill(4, allColor[index]), ...arrayFill(4, getListByIndex(allColor, index + 10)), ...arrayFill(4, getListByIndex(allColor, index + 20)), ...arrayFill(4, getListByIndex(allColor, index + 30)), ...arrayFill(4, getListByIndex(allColor, index + 40))];
24
+ });
25
+ return {
26
+ colorList,
27
+ length: colorList.length
28
+ };
29
+ };
30
+ export default mode;
@@ -0,0 +1,33 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:23:35
6
+ * @Description:
7
+ */
8
+ import { splitNumber, arrayFill } from '../utils';
9
+
10
+ /** 闪烁 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const {
13
+ segmented
14
+ } = option || {};
15
+ const rangeNum = 7;
16
+ if (!segmented) {
17
+ const colorList = colors.map(item => [...arrayFill(rangeNum, arrayFill(20, item)), ...arrayFill(rangeNum, arrayFill(20, closeRgb))]).flat(1);
18
+ return {
19
+ colorList,
20
+ length: colorList.length
21
+ };
22
+ }
23
+ const segmentArr = splitNumber(20, colors.length);
24
+ const partColor = segmentArr.map((num, index) => {
25
+ return arrayFill(num, colors[index]);
26
+ }).flat(1);
27
+ const colorList = [...arrayFill(rangeNum, partColor), ...arrayFill(rangeNum, arrayFill(20, closeRgb))];
28
+ return {
29
+ colorList,
30
+ length: colorList.length
31
+ };
32
+ };
33
+ export default mode;
@@ -0,0 +1,52 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:24:56
6
+ * @Description:
7
+ */
8
+ import { arrayFill } from '../utils';
9
+
10
+ /** 流星 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const {
13
+ direction,
14
+ expand
15
+ } = option || {};
16
+ let allColor = [];
17
+ let currIndex = 0;
18
+ colors.forEach(item => {
19
+ if (!expand) {
20
+ // 流星
21
+ const closeList = arrayFill(19, closeRgb);
22
+ const colorList = arrayFill(5, item);
23
+ allColor = [...allColor, ...closeList, ...colorList];
24
+ } else if (expand === 1) {
25
+ // 流星雨
26
+ const closeList = arrayFill(7, closeRgb);
27
+ const colorList = arrayFill(5, item);
28
+ allColor = [...allColor, ...closeList, ...colorList, ...closeList, ...colorList];
29
+ } else {
30
+ // 幻彩流星
31
+ const currColor = colors[currIndex];
32
+ const afterColor = colors[currIndex + 1];
33
+ if (!currColor) return;
34
+ const closeList = arrayFill(7, closeRgb);
35
+ const colorList = arrayFill(5, currColor);
36
+ const afterColorList = afterColor ? arrayFill(5, afterColor) : [];
37
+ currIndex += 2;
38
+ allColor = [...allColor, ...closeList, ...colorList, ...(afterColor ? closeList : []), ...afterColorList];
39
+ }
40
+ });
41
+ const colorList = allColor.map((_, index) => {
42
+ const endIndex = index + 20;
43
+ const endColor = endIndex > allColor.length - 1 ? allColor.slice(0, endIndex - allColor.length + 1) : [];
44
+ const list = [...allColor.slice(index, index + 20), ...endColor];
45
+ return direction ? list : list.reverse();
46
+ });
47
+ return {
48
+ colorList,
49
+ length: colorList.length
50
+ };
51
+ };
52
+ export default mode;
@@ -0,0 +1,63 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:25:16
6
+ * @Description:
7
+ */
8
+ import { arrayFill, splitLight } from '../utils';
9
+
10
+ /** 堆积 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const {
13
+ direction,
14
+ segmented
15
+ } = option || {};
16
+ const closeArrList = arrayFill(20, closeRgb);
17
+ // 全段
18
+ if (!segmented) {
19
+ const allColor = colors.map(item => {
20
+ let count = 0;
21
+ const currColorList = new Array(20).fill('').map(() => {
22
+ const list = new Array(21 - count).fill('').map((_, index) => {
23
+ const currList = [...closeArrList.slice(0, 20 - count), ...arrayFill(count, item)];
24
+ if (index) currList[index - 1] = item;
25
+ if (direction) return currList.reverse();
26
+ return currList;
27
+ });
28
+ count++;
29
+ return list;
30
+ });
31
+ return currColorList;
32
+ }).flat(2);
33
+ return {
34
+ colorList: allColor,
35
+ length: allColor.length
36
+ };
37
+ }
38
+ // 分段
39
+ const {
40
+ arr,
41
+ color
42
+ } = splitLight(colors);
43
+ const allColor = color.map(colorList => {
44
+ let count = 0;
45
+ const currItemColorList = arr.map((item, index) => arrayFill(item, colorList[index])).flat(1);
46
+ const currColorList = new Array(20).fill('').map(() => {
47
+ const list = new Array(21 - count).fill('').map((_, index) => {
48
+ const currList = [...closeArrList.slice(0, 20 - count), ...currItemColorList.slice(0, count).reverse()];
49
+ if (index) currList[index - 1] = currItemColorList[count];
50
+ if (direction) return currList.reverse();
51
+ return currList;
52
+ });
53
+ count++;
54
+ return list;
55
+ });
56
+ return currColorList;
57
+ }).flat(2);
58
+ return {
59
+ colorList: allColor,
60
+ length: allColor.length
61
+ };
62
+ };
63
+ export default mode;
@@ -0,0 +1,69 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:26:02
6
+ * @Description:
7
+ */
8
+ import { arrayFill, splitArray } from '../utils';
9
+
10
+ /** 飘落 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const {
13
+ direction,
14
+ segmented
15
+ } = option || {};
16
+ const arrList = arrayFill(20, closeRgb);
17
+ // 全段
18
+ if (!segmented) {
19
+ const allColor = colors.map(item => {
20
+ let count = 0;
21
+ const currColorList = new Array(5).fill('').map(() => {
22
+ const list = new Array(21 - count).fill('').map((_, index) => {
23
+ const currList = [...arrList.slice(0, 20 - count), ...arrayFill(count, item)];
24
+ const currIndex = index - 4;
25
+ currIndex >= 0 && (currList[currIndex] = item);
26
+ currIndex + 1 >= 0 && (currList[currIndex + 1] = item);
27
+ currIndex + 2 >= 0 && (currList[currIndex + 2] = item);
28
+ currIndex + 3 >= 0 && (currList[currIndex + 3] = item);
29
+ if (direction) return currList.reverse();
30
+ return currList;
31
+ });
32
+ count += 4;
33
+ return list;
34
+ });
35
+ return [...currColorList, arrayFill(6, arrayFill(20, item))];
36
+ }).flat(2);
37
+ return {
38
+ colorList: allColor,
39
+ length: allColor.length
40
+ };
41
+ }
42
+ // 分段
43
+ let colorList = colors.length === 5 ? colors : arrayFill(5, colors).flat(1);
44
+ const colorSplit = splitArray(colorList, 5);
45
+ const allColor = colorSplit.map(colorItemList => {
46
+ let count = 0;
47
+ const currColorList = new Array(5).fill('').map((_, colorIndex) => {
48
+ const currColor = colorItemList[colorIndex];
49
+ const list = new Array(21 - count).fill('').map((__, index) => {
50
+ const currList = [...arrList.slice(0, 20 - count), new Array(colorIndex).fill('').map((___, ind) => arrayFill(4, colorItemList[ind])).reverse()].flat(2);
51
+ const currIndex = index - 4;
52
+ currIndex >= 0 && (currList[currIndex] = currColor);
53
+ currIndex + 1 >= 0 && (currList[currIndex + 1] = currColor);
54
+ currIndex + 2 >= 0 && (currList[currIndex + 2] = currColor);
55
+ currIndex + 3 >= 0 && (currList[currIndex + 3] = currColor);
56
+ if (direction) return currList.reverse();
57
+ return currList;
58
+ });
59
+ count += 4;
60
+ return list;
61
+ });
62
+ return currColorList;
63
+ }).flat(2);
64
+ return {
65
+ colorList: allColor,
66
+ length: allColor.length
67
+ };
68
+ };
69
+ export default mode;
@@ -0,0 +1,27 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:26:29
6
+ * @Description:
7
+ */
8
+ import { arrayFill } from '../utils';
9
+
10
+ /** 追光 */
11
+ const mode = (colors, option) => {
12
+ const {
13
+ direction
14
+ } = option || {};
15
+ const allColor = colors.map(item => arrayFill(20, item)).flat(1);
16
+ const colorList = allColor.map((_, index) => {
17
+ const endIndex = index + 20;
18
+ const endColor = endIndex > allColor.length - 1 ? allColor.slice(0, endIndex - allColor.length + 1) : [];
19
+ const list = [...allColor.slice(index, index + 20), ...endColor];
20
+ return !direction ? list.reverse() : list;
21
+ });
22
+ return {
23
+ colorList,
24
+ length: colorList.length
25
+ };
26
+ };
27
+ export default mode;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * @Author: mjh
3
+ * @Date: 2024-10-21 14:23:12
4
+ * @LastEditors: mjh
5
+ * @LastEditTime: 2024-10-21 14:26:55
6
+ * @Description:
7
+ */
8
+ import { arrayFill } from '../utils';
9
+
10
+ /** 飘动 */
11
+ const mode = (colors, option, closeRgb) => {
12
+ const {
13
+ direction
14
+ } = option || {};
15
+ const colorList = arrayFill(2, colors).flat(1);
16
+ const colorAllList = colorList.map(item => [...arrayFill(5, item), ...arrayFill(5, closeRgb)]).flat(1);
17
+ const loopColorList = [...colorAllList, ...colorAllList.slice(0, 19)];
18
+ const colorAnimation = loopColorList.map((_, index) => {
19
+ if (index + 19 > loopColorList.length - 1) return [];
20
+ const list = loopColorList.slice(index, index + 20);
21
+ return direction ? list : list.reverse();
22
+ }).filter(item => item.length);
23
+ return {
24
+ colorList: colorAnimation,
25
+ length: colorAnimation.length
26
+ };
27
+ };
28
+ export default mode;