enr 2.0.0 → 2.0.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 +5 -2
- package/cjs/components/ripples/Content.js +16 -0
- package/cjs/components/ripples/LazyRippleEle.js +5 -36
- package/cjs/components/ripples/RipplesEle.js +3 -35
- package/cjs/components/ripples/imperative-handle.js +48 -0
- package/cjs/components/ripples/{useOptionUpdate.js → use-option-update.js} +2 -1
- package/cjs/customHooks/useAnimationFrame.js +2 -2
- package/cjs/customHooks/useInputIsComposing.js +2 -2
- package/cjs/customHooks/useRipples/class-build-background.js +2 -3
- package/cjs/customHooks/useRipples/class-event-action.js +3 -4
- package/cjs/customHooks/useRipples/class-param.js +24 -1
- package/cjs/customHooks/useRipples/class-ripple.js +12 -1
- package/cjs/customHooks/useRipples/class-webgl.js +10 -2
- package/cjs/customHooks/useRipples/data-default.js +4 -1
- package/cjs/customHooks/useRipples/index.js +2 -2
- package/cjs/customHooks/useTimeId.js +2 -2
- package/es/components/ripples/Content.js +16 -1
- package/es/components/ripples/LazyRippleEle.js +8 -39
- package/es/components/ripples/RipplesEle.js +6 -38
- package/es/components/ripples/imperative-handle.js +46 -0
- package/es/components/ripples/{useOptionUpdate.js → use-option-update.js} +2 -1
- package/es/customHooks/useAnimationFrame.js +2 -2
- package/es/customHooks/useInputIsComposing.js +2 -2
- package/es/customHooks/useRipples/class-build-background.js +2 -3
- package/es/customHooks/useRipples/class-event-action.js +3 -4
- package/es/customHooks/useRipples/class-param.js +25 -2
- package/es/customHooks/useRipples/class-ripple.js +12 -1
- package/es/customHooks/useRipples/class-webgl.js +10 -2
- package/es/customHooks/useRipples/data-default.js +4 -2
- package/es/customHooks/useRipples/index.js +2 -2
- package/es/customHooks/useTimeId.js +2 -2
- package/es/src/components/ripples/Content.d.ts +7 -0
- package/es/src/components/ripples/LazyRippleEle.d.ts +5 -6
- package/es/src/components/ripples/RipplesEle.d.ts +3 -3
- package/es/src/components/ripples/imperative-handle.d.ts +19 -0
- package/es/src/components/ripples/types.d.ts +6 -1
- package/es/src/customHooks/useAnimationFrame.d.ts +2 -2
- package/es/src/customHooks/useInputIsComposing.d.ts +2 -2
- package/es/src/customHooks/useRipples/class-build-background.d.ts +1 -1
- package/es/src/customHooks/useRipples/class-event-action.d.ts +3 -4
- package/es/src/customHooks/useRipples/class-param.d.ts +8 -1
- package/es/src/customHooks/useRipples/class-ripple.d.ts +18 -21
- package/es/src/customHooks/useRipples/class-webgl.d.ts +5 -2
- package/es/src/customHooks/useRipples/data-default.d.ts +2 -1
- package/es/src/customHooks/useRipples/index.d.ts +2 -2
- package/es/src/customHooks/useRipples/types.d.ts +104 -30
- package/es/src/customHooks/useTimeId.d.ts +2 -2
- package/package.json +3 -3
- /package/es/src/components/ripples/{useOptionUpdate.d.ts → use-option-update.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# enr
|
|
2
2
|
|
|
3
3
|
## 一、安装
|
|
4
4
|
|
|
@@ -10,9 +10,12 @@ npm install --save earthnut
|
|
|
10
10
|
|
|
11
11
|
## 二、涟漪背景
|
|
12
12
|
|
|
13
|
+
> [!Note]
|
|
14
|
+
> 该模块魔改自 [jquery.ripples](https://github.com/sirxemic/jquery.ripples)
|
|
15
|
+
|
|
13
16
|
- 尽管接受所有的 style 属性,但是 `position` 还是期待是非 'static' 值,否则将影响涟漪背景的渲染位置和显示状态;
|
|
14
17
|
- 当前如果设置了 `background` 的话,有可能在恢复时使得其覆盖其他子属性;
|
|
15
|
-
- 当前期待使用 `background-color` 设置背景色,而不是在上面的 `background`
|
|
18
|
+
- 当前期待使用 `background-color` 设置背景色,而不是在上面的 `background` 中设置背景色。譬如:<span style="background-color:#f0f6">`background-color: #f0f6;`</span>
|
|
16
19
|
- 当前更期待使用配置参数 `option` 的 'imgUrl' 来配置目标背景图(请注意图源的跨域问题)。譬如:`imgUrl: 'background.png'`
|
|
17
20
|
- 当然,也可以使用标准的 `background-image` 配置符合要求的背景图片(目前仅支持单张图配置)。譬如:`background-image: url(background.png);`
|
|
18
21
|
- 当前可配置 `background-image` 为渐变色,但仅支持从上到下的线性渐变(仅支持单渐变)。譬如: `background-image: linear-gradient(black, transparent);`
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
3
5
|
var styled = require('styled-components');
|
|
6
|
+
var imperativeHandle = require('./imperative-handle.js');
|
|
7
|
+
var useOptionUpdate = require('./use-option-update.js');
|
|
4
8
|
|
|
5
9
|
/** 内容组件 */
|
|
6
10
|
const Content = styled.styled.div `
|
|
@@ -15,5 +19,17 @@ const Content = styled.styled.div `
|
|
|
15
19
|
contain: layout paint style;
|
|
16
20
|
will-change: transform, opacity;
|
|
17
21
|
`;
|
|
22
|
+
const ComponentContent = ({ option, ripplesRef, canvas, ...props }) => {
|
|
23
|
+
const { children, style, ref, ..._props } = props;
|
|
24
|
+
/// 使用 配置更新
|
|
25
|
+
useOptionUpdate.useOptionUpdate(ripplesRef, option);
|
|
26
|
+
// 抛出事件 (自定义抛出事件)
|
|
27
|
+
react.useImperativeHandle(ref, imperativeHandle.createImperativeHandle(ripplesRef));
|
|
28
|
+
return (jsxRuntime.jsxs(Content, { style: {
|
|
29
|
+
backgroundRepeat: 'round',
|
|
30
|
+
...style,
|
|
31
|
+
}, ..._props, children: [jsxRuntime.jsx("canvas", { ref: canvas, "data-earthnut-ui": "canvas", width: 0, height: 0 }), children] }));
|
|
32
|
+
};
|
|
18
33
|
|
|
34
|
+
exports.ComponentContent = ComponentContent;
|
|
19
35
|
exports.Content = Content;
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var aTypeOfJs = require('a-type-of-js');
|
|
6
5
|
var react = require('react');
|
|
7
6
|
var useLazyRipple = require('../../customHooks/useRipples/use-lazy-ripple.js');
|
|
8
7
|
var Content = require('./Content.js');
|
|
9
|
-
var useOptionUpdate = require('./useOptionUpdate.js');
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
*
|
|
@@ -27,53 +25,24 @@ var useOptionUpdate = require('./useOptionUpdate.js');
|
|
|
27
25
|
* 使用:
|
|
28
26
|
*
|
|
29
27
|
* ```ts
|
|
30
|
-
* import {
|
|
28
|
+
* import { LazyBackgroundRipple } from 'enr/LazyBackgroundRipple';
|
|
31
29
|
* // 也可以全量导入
|
|
32
|
-
* // import {
|
|
30
|
+
* // import { LazyBackgroundRipple } from 'enr';
|
|
33
31
|
* ...
|
|
34
32
|
* const animationFrameId = useAnimationFrame();
|
|
35
33
|
*
|
|
36
|
-
* return <
|
|
34
|
+
* return <LazyBackgroundRipple>
|
|
37
35
|
* ...
|
|
38
|
-
* </
|
|
36
|
+
* </LazyBackgroundRipple>
|
|
39
37
|
* ```
|
|
40
38
|
*
|
|
41
39
|
*/
|
|
42
40
|
const LazyBackgroundRipple = ({ option, ...props }) => {
|
|
43
|
-
const { children, style, ref, ..._props } = props;
|
|
44
41
|
/** canvas 元素 */
|
|
45
42
|
const canvas = react.useRef(null);
|
|
46
43
|
/** 使用 ripples */
|
|
47
44
|
const { ripples } = useLazyRipple.useLazyRipples(canvas, option);
|
|
48
|
-
|
|
49
|
-
/// 使用 配置更新
|
|
50
|
-
useOptionUpdate.useOptionUpdate(ripples, option);
|
|
51
|
-
// 抛出事件 (自定义抛出事件)
|
|
52
|
-
react.useImperativeHandle(ref, () => ({
|
|
53
|
-
toggleState: () => ripples.current?.changePlayingState() ?? false,
|
|
54
|
-
get state() {
|
|
55
|
-
return ripples.current?.options.playingState ?? false;
|
|
56
|
-
},
|
|
57
|
-
pause() {
|
|
58
|
-
ripples.current?.pause();
|
|
59
|
-
},
|
|
60
|
-
play() {
|
|
61
|
-
ripples.current?.play();
|
|
62
|
-
},
|
|
63
|
-
set(options) {
|
|
64
|
-
if (aTypeOfJs.isUndefined(options))
|
|
65
|
-
return;
|
|
66
|
-
const keys = Object.keys(options);
|
|
67
|
-
for (let i = 0, j = keys.length; i < j; i++) {
|
|
68
|
-
const key = keys[i];
|
|
69
|
-
ripples.current?.set(key, options[key]);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
}));
|
|
73
|
-
return (jsxRuntime.jsxs(Content.Content, { style: {
|
|
74
|
-
backgroundRepeat: 'round',
|
|
75
|
-
...style,
|
|
76
|
-
}, ..._props, children: [jsxRuntime.jsx("canvas", { ref: canvas, "data-earthnut-ui": "canvas", width: 0, height: 0 }), children] }));
|
|
45
|
+
return jsxRuntime.jsx(Content.ComponentContent, { ripplesRef: ripples, canvas: canvas, option: option, ...props });
|
|
77
46
|
};
|
|
78
47
|
LazyBackgroundRipple.displayName = 'enr-lazy-background-ripple';
|
|
79
48
|
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var aTypeOfJs = require('a-type-of-js');
|
|
6
5
|
var react = require('react');
|
|
7
6
|
var index = require('../../customHooks/useRipples/index.js');
|
|
8
7
|
var Content = require('./Content.js');
|
|
9
|
-
var useOptionUpdate = require('./useOptionUpdate.js');
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
*
|
|
@@ -25,9 +23,9 @@ var useOptionUpdate = require('./useOptionUpdate.js');
|
|
|
25
23
|
* 使用:
|
|
26
24
|
*
|
|
27
25
|
* ```ts
|
|
28
|
-
* import { BackgroundRipple } from '
|
|
26
|
+
* import { BackgroundRipple } from 'enr/';
|
|
29
27
|
* // 也可以全量导入
|
|
30
|
-
* // import { BackgroundRipple } from '
|
|
28
|
+
* // import { BackgroundRipple } from 'enr';
|
|
31
29
|
* ...
|
|
32
30
|
* const animationFrameId = useAnimationFrame();
|
|
33
31
|
*
|
|
@@ -38,41 +36,11 @@ var useOptionUpdate = require('./useOptionUpdate.js');
|
|
|
38
36
|
*
|
|
39
37
|
*/
|
|
40
38
|
const BackgroundRipple = ({ option, ...props }) => {
|
|
41
|
-
const { children, style, ref, ..._props } = props;
|
|
42
39
|
/** canvas 元素 */
|
|
43
40
|
const canvas = react.useRef(null);
|
|
44
41
|
/** 使用 ripples */
|
|
45
42
|
const ripplesRef = index.useRipples(canvas, option);
|
|
46
|
-
|
|
47
|
-
useOptionUpdate.useOptionUpdate(ripplesRef, option);
|
|
48
|
-
// 抛出事件 (自定义抛出事件)
|
|
49
|
-
react.useImperativeHandle(ref, () => ({
|
|
50
|
-
toggleState: () => ripplesRef.current?.changePlayingState() ?? false,
|
|
51
|
-
get state() {
|
|
52
|
-
return ripplesRef.current?.options.playingState ?? false;
|
|
53
|
-
},
|
|
54
|
-
pause() {
|
|
55
|
-
ripplesRef.current?.pause();
|
|
56
|
-
},
|
|
57
|
-
play() {
|
|
58
|
-
ripplesRef.current?.play();
|
|
59
|
-
},
|
|
60
|
-
set(options) {
|
|
61
|
-
if (aTypeOfJs.isUndefined(options))
|
|
62
|
-
return;
|
|
63
|
-
const keys = Object.keys(options);
|
|
64
|
-
for (let i = 0, j = keys.length; i < j; i++) {
|
|
65
|
-
const key = keys[i];
|
|
66
|
-
ripplesRef.current?.set(key, options[key]);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
}));
|
|
70
|
-
return (jsxRuntime.jsxs(Content.Content, { style: {
|
|
71
|
-
backgroundRepeat: 'round',
|
|
72
|
-
// backgroundSize: 'cover',
|
|
73
|
-
// backgroundPosition: 'center',
|
|
74
|
-
...style,
|
|
75
|
-
}, ..._props, children: [jsxRuntime.jsx("canvas", { ref: canvas, "data-earthnut-ui": "canvas", width: 0, height: 0 }), children] }));
|
|
43
|
+
return jsxRuntime.jsx(Content.ComponentContent, { ripplesRef: ripplesRef, canvas: canvas, option: option, ...props });
|
|
76
44
|
};
|
|
77
45
|
BackgroundRipple.displayName = 'enr-background-ripple';
|
|
78
46
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var aTypeOfJs = require('a-type-of-js');
|
|
4
|
+
var dataDefault = require('../../customHooks/useRipples/data-default.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module @enr/imperative-handle
|
|
8
|
+
* @file imperative-handle.ts
|
|
9
|
+
* @description 公共的命令句柄
|
|
10
|
+
* @author Mr.MudBean <Mr.MudBean@outlook.com>
|
|
11
|
+
* @license MIT
|
|
12
|
+
* @copyright 2026 ©️ Mr.MudBean
|
|
13
|
+
* @since 2026-02-04 06:52
|
|
14
|
+
* @version 2.0.1
|
|
15
|
+
* @lastModified 2026-02-04 07:57
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* ## 通过函数构建公共的命令句柄
|
|
19
|
+
* @param ripplesRef
|
|
20
|
+
*/
|
|
21
|
+
function createImperativeHandle(ripplesRef) {
|
|
22
|
+
return () => ({
|
|
23
|
+
toggleState: () => ripplesRef.current?.changePlayingState() ?? false,
|
|
24
|
+
get state() {
|
|
25
|
+
return ripplesRef.current?.get('playingState') ?? false;
|
|
26
|
+
},
|
|
27
|
+
pause() {
|
|
28
|
+
ripplesRef.current?.pause();
|
|
29
|
+
},
|
|
30
|
+
play() {
|
|
31
|
+
ripplesRef.current?.play();
|
|
32
|
+
},
|
|
33
|
+
set(options) {
|
|
34
|
+
if (aTypeOfJs.isUndefined(options))
|
|
35
|
+
return;
|
|
36
|
+
const keys = Object.keys(options);
|
|
37
|
+
for (let i = 0, j = keys.length; i < j; i++) {
|
|
38
|
+
const key = keys[i];
|
|
39
|
+
ripplesRef.current?.set(key, options[key]);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
drop(x, y, options) {
|
|
43
|
+
ripplesRef.current?.drop(x, y, options?.radius ?? ripplesRef?.current.get('dropRadius') ?? dataDefault.defaultData.dropRadius, options?.strength ?? ripplesRef?.current?.get('perturbation') ?? 0.03);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.createImperativeHandle = createImperativeHandle;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var aTypeOfJs = require('a-type-of-js');
|
|
4
4
|
var react = require('react');
|
|
5
|
+
var dataDefault = require('../../customHooks/useRipples/data-default.js');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 更新参数数据
|
|
@@ -15,7 +16,7 @@ function useOptionUpdate(ripplesRef, option) {
|
|
|
15
16
|
if (!option || !ripplesRef.current) {
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
dataDefault.defaultDataKey.forEach(e => {
|
|
19
20
|
/** 新的值 */
|
|
20
21
|
const value = option[e];
|
|
21
22
|
/** 测试值是否相等 */
|
|
@@ -13,7 +13,7 @@ var react = require('react');
|
|
|
13
13
|
* @copyright 2026 ©️ MrMudBean
|
|
14
14
|
* @since 2025-01-07 11:23
|
|
15
15
|
* @version 2.0.0-alpha.0
|
|
16
|
-
* @lastModified 2026-02-
|
|
16
|
+
* @lastModified 2026-02-04 08:18
|
|
17
17
|
*/
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
@@ -30,7 +30,7 @@ var react = require('react');
|
|
|
30
30
|
* 使用:
|
|
31
31
|
*
|
|
32
32
|
* ```ts
|
|
33
|
-
* // import { useAnimationFrame } from '
|
|
33
|
+
* // import { useAnimationFrame } from 'enr';
|
|
34
34
|
* ...
|
|
35
35
|
*
|
|
36
36
|
* export function Home () {
|
|
@@ -12,7 +12,7 @@ var react = require('react');
|
|
|
12
12
|
* @copyright 2026 ©️ MrMudBean
|
|
13
13
|
* @since 2025-01-07 11:23
|
|
14
14
|
* @version 2.0.0-alpha.0
|
|
15
|
-
* @lastModified 2026-
|
|
15
|
+
* @lastModified 2026-02-04 08:19
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
@@ -29,7 +29,7 @@ var react = require('react');
|
|
|
29
29
|
* 使用:
|
|
30
30
|
*
|
|
31
31
|
* ```ts
|
|
32
|
-
* import { useInputIsComposing } from '
|
|
32
|
+
* import { useInputIsComposing } from 'enr';
|
|
33
33
|
*
|
|
34
34
|
* ...
|
|
35
35
|
* const inputRef = useRef<HTMLInputElement>(null);
|
|
@@ -14,7 +14,7 @@ var tools = require('./tools.js');
|
|
|
14
14
|
* @copyright 2026 ©️ MrMudBean
|
|
15
15
|
* @since 2026-01-22 14:17
|
|
16
16
|
* @version 2.0.0-alpha.0
|
|
17
|
-
* @lastModified 2026-02-
|
|
17
|
+
* @lastModified 2026-02-05 17:41
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* ## 构建背景
|
|
@@ -39,8 +39,7 @@ class BuildBackground {
|
|
|
39
39
|
* ## 默认加载的首个背景色
|
|
40
40
|
*/
|
|
41
41
|
get defaultColor() {
|
|
42
|
-
return this.elementMeta.isDark
|
|
43
|
-
// return '#00000000';
|
|
42
|
+
return this.options.loadingBackgroundColor[Number(this.elementMeta.isDark)];
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
* ## 最后使用
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var aJsTools = require('a-js-tools');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @packageDocumentation
|
|
7
6
|
* @module @enr/class-event-action
|
|
8
7
|
* @file class-event-action.ts
|
|
9
8
|
* @description 交互事件
|
|
@@ -12,7 +11,7 @@ var aJsTools = require('a-js-tools');
|
|
|
12
11
|
* @copyright 2026 ©️ MrMudBean
|
|
13
12
|
* @since 2026-01-23 01:23
|
|
14
13
|
* @version 2.0.0-alpha.0
|
|
15
|
-
* @lastModified 2026-02-
|
|
14
|
+
* @lastModified 2026-02-04 06:46
|
|
16
15
|
*/
|
|
17
16
|
/**
|
|
18
17
|
*
|
|
@@ -136,8 +135,8 @@ class EventAction {
|
|
|
136
135
|
}
|
|
137
136
|
/**
|
|
138
137
|
* 触发滴落效果
|
|
139
|
-
* @param x
|
|
140
|
-
* @param y
|
|
138
|
+
* @param x 横坐标
|
|
139
|
+
* @param y 纵坐标
|
|
141
140
|
* @param radius
|
|
142
141
|
* @param strength
|
|
143
142
|
*/
|
|
@@ -13,7 +13,7 @@ var dataDefault = require('./data-default.js');
|
|
|
13
13
|
* @copyright 2026 ©️ MrMudBean
|
|
14
14
|
* @since 2026-01-22 02:40
|
|
15
15
|
* @version 2.0.0-alpha.0
|
|
16
|
-
* @lastModified 2026-02-
|
|
16
|
+
* @lastModified 2026-02-05 19:20
|
|
17
17
|
*/
|
|
18
18
|
/**
|
|
19
19
|
* ## 传入参数
|
|
@@ -36,6 +36,8 @@ class RippleParam {
|
|
|
36
36
|
firstDrawProgressStep = 12;
|
|
37
37
|
/** canvas 的显隐 */
|
|
38
38
|
visible = false;
|
|
39
|
+
/** 初始化设定值,该值由用户设置,但不可修改 */
|
|
40
|
+
loadingBackgroundColor;
|
|
39
41
|
// ++++++++++++++++++++++ 配置数据 《〈《〈《〈《 ++++++++++++++++++++++
|
|
40
42
|
// ++++++++++++++++++++++ 》〉》〉》〉》 用户控制变量 ++++++++++++++++++++++
|
|
41
43
|
// 这些变量通过 Ripple 类的 set 方法设定
|
|
@@ -185,6 +187,7 @@ class RippleParam {
|
|
|
185
187
|
this.running = Boolean(options.playingState ?? true);
|
|
186
188
|
this.crossOrigin = options.crossOrigin;
|
|
187
189
|
this.darkMode = options.darkMode;
|
|
190
|
+
this.loadingBackgroundColor = this.getLoadingBg(options.loadingBackgroundColor);
|
|
188
191
|
}
|
|
189
192
|
/**
|
|
190
193
|
* ## 切换最后一次执行的状态
|
|
@@ -192,6 +195,26 @@ class RippleParam {
|
|
|
192
195
|
toggleLastRunningState() {
|
|
193
196
|
this._lastRunningState = !this._lastRunningState;
|
|
194
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* ## 获取初始化背景值
|
|
200
|
+
* @param _v 初始化的值
|
|
201
|
+
*/
|
|
202
|
+
getLoadingBg(_v) {
|
|
203
|
+
if (aTypeOfJs.isArray(_v)) {
|
|
204
|
+
const len = _v.length;
|
|
205
|
+
if (len === 1) {
|
|
206
|
+
const color = _v[0];
|
|
207
|
+
return [color, color];
|
|
208
|
+
}
|
|
209
|
+
else if (len === 2) {
|
|
210
|
+
return [..._v];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (aTypeOfJs.isString(_v)) {
|
|
214
|
+
return [_v, _v];
|
|
215
|
+
}
|
|
216
|
+
return ['#00000000', '#00000000'];
|
|
217
|
+
}
|
|
195
218
|
}
|
|
196
219
|
|
|
197
220
|
exports.RippleParam = RippleParam;
|
|
@@ -21,7 +21,7 @@ var dataDefault = require('./data-default.js');
|
|
|
21
21
|
* @copyright 2026 ©️ MrMudBean
|
|
22
22
|
* @since 2026-01-22 03:03
|
|
23
23
|
* @version 2.0.0-alpha.0
|
|
24
|
-
* @lastModified 2026-02-
|
|
24
|
+
* @lastModified 2026-02-05 19:24
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
/**
|
|
@@ -208,6 +208,10 @@ class Ripples {
|
|
|
208
208
|
* @param value
|
|
209
209
|
*/
|
|
210
210
|
set(property, value) {
|
|
211
|
+
// 该属性不允许被重新赋值
|
|
212
|
+
if (property === 'loadingBackgroundColor') {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
211
215
|
this.options[property] = value;
|
|
212
216
|
// 数仓更新
|
|
213
217
|
this.state.dispatch({
|
|
@@ -215,6 +219,13 @@ class Ripples {
|
|
|
215
219
|
payload: value,
|
|
216
220
|
});
|
|
217
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* 获取某一个参数的当前值
|
|
224
|
+
* @param property 要获取的键
|
|
225
|
+
*/
|
|
226
|
+
get(property) {
|
|
227
|
+
return this.options[property];
|
|
228
|
+
}
|
|
218
229
|
reducer = (state, action) => {
|
|
219
230
|
switch (action.type) {
|
|
220
231
|
case 'sizeChange':
|
|
@@ -12,7 +12,7 @@ var aTypeOfJs = require('a-type-of-js');
|
|
|
12
12
|
* @copyright 2026 ©️ MrMudBean
|
|
13
13
|
* @since 2026-01-22 02:44
|
|
14
14
|
* @version 2.0.0-alpha.0
|
|
15
|
-
* @lastModified 2026-02-
|
|
15
|
+
* @lastModified 2026-02-04 06:51
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* ## webGl
|
|
@@ -29,7 +29,10 @@ class RippleGl {
|
|
|
29
29
|
* 该值在 init 中进行初始化
|
|
30
30
|
*/
|
|
31
31
|
quad = null;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* ## [着色器](https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLProgram)
|
|
34
|
+
*
|
|
35
|
+
* 该值于初始化着色器时初始化 */
|
|
33
36
|
dropProgram;
|
|
34
37
|
/** 更新流 */
|
|
35
38
|
updateProgram;
|
|
@@ -246,6 +249,11 @@ class RippleGl {
|
|
|
246
249
|
const { gl } = this;
|
|
247
250
|
this.dropProgram = this.createProgram(this.vertexShader, this.dropProgramFragmentSource);
|
|
248
251
|
const updateProgram = (this.updateProgram = this.createProgram(this.vertexShader, this.updateProgramFragmentSource));
|
|
252
|
+
/**
|
|
253
|
+
* ### [指定了 uniform 变量的值](https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/uniform)
|
|
254
|
+
*
|
|
255
|
+
*
|
|
256
|
+
*/
|
|
249
257
|
gl.uniform2fv(updateProgram.locations.delta, this.textureDelta);
|
|
250
258
|
this.renderProgram = this.createProgram(this.renderVertexSource, this.renderProgramFragmentSource);
|
|
251
259
|
gl.uniform2fv(this.renderProgram.locations.delta, this.textureDelta);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @copyright 2026 ©️ MrMudBean
|
|
11
11
|
* @since 2026-01-22 11:55
|
|
12
12
|
* @version 2.0.0-alpha.0
|
|
13
|
-
* @lastModified 2026-
|
|
13
|
+
* @lastModified 2026-02-05 17:22
|
|
14
14
|
*/
|
|
15
15
|
/**
|
|
16
16
|
* ## 默认值
|
|
@@ -27,8 +27,11 @@ const defaultData = {
|
|
|
27
27
|
raindropsTimeInterval: 3600,
|
|
28
28
|
idleFluctuations: true,
|
|
29
29
|
darkMode: undefined,
|
|
30
|
+
loadingBackgroundColor: ['#00000000', '#00000000'],
|
|
30
31
|
};
|
|
31
32
|
/** 冷冻执行 */
|
|
32
33
|
Object.freeze(defaultData);
|
|
34
|
+
const defaultDataKey = Object.keys(defaultData);
|
|
33
35
|
|
|
34
36
|
exports.defaultData = defaultData;
|
|
37
|
+
exports.defaultDataKey = defaultDataKey;
|
|
@@ -15,7 +15,7 @@ var classRipple = require('./class-ripple.js');
|
|
|
15
15
|
* @copyright 2026 ©️ MrMudBean
|
|
16
16
|
* @since 2025-06-20 01:37
|
|
17
17
|
* @version 2.0.0-alpha.0
|
|
18
|
-
* @lastModified 2026-02-
|
|
18
|
+
* @lastModified 2026-02-04 08:19
|
|
19
19
|
*/
|
|
20
20
|
/**
|
|
21
21
|
*
|
|
@@ -32,7 +32,7 @@ var classRipple = require('./class-ripple.js');
|
|
|
32
32
|
* 下面是在 <BackgroundRipple> 中使用
|
|
33
33
|
*
|
|
34
34
|
* ```ts
|
|
35
|
-
* import { useRipples } from '
|
|
35
|
+
* import { useRipples } from 'enr';
|
|
36
36
|
*
|
|
37
37
|
* export function BackgroundRipple(props: BackgroundRipplesProps) {
|
|
38
38
|
*
|
|
@@ -12,7 +12,7 @@ var react = require('react');
|
|
|
12
12
|
* @copyright 2026 ©️ MrMudBean
|
|
13
13
|
* @since 2025-01-07 11:20
|
|
14
14
|
* @version 2.0.0-alpha.0
|
|
15
|
-
* @lastModified 2026-
|
|
15
|
+
* @lastModified 2026-02-04 08:19
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
@@ -27,7 +27,7 @@ var react = require('react');
|
|
|
27
27
|
* 使用:
|
|
28
28
|
*
|
|
29
29
|
* ```ts
|
|
30
|
-
* // import { useTimeId } from '
|
|
30
|
+
* // import { useTimeId } from 'enr';
|
|
31
31
|
* ...
|
|
32
32
|
* const timeoutId = useTimeId();
|
|
33
33
|
*
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useImperativeHandle } from 'react';
|
|
1
3
|
import { styled } from 'styled-components';
|
|
4
|
+
import { createImperativeHandle } from './imperative-handle.js';
|
|
5
|
+
import { useOptionUpdate } from './use-option-update.js';
|
|
2
6
|
|
|
3
7
|
/** 内容组件 */
|
|
4
8
|
const Content = styled.div `
|
|
@@ -13,5 +17,16 @@ const Content = styled.div `
|
|
|
13
17
|
contain: layout paint style;
|
|
14
18
|
will-change: transform, opacity;
|
|
15
19
|
`;
|
|
20
|
+
const ComponentContent = ({ option, ripplesRef, canvas, ...props }) => {
|
|
21
|
+
const { children, style, ref, ..._props } = props;
|
|
22
|
+
/// 使用 配置更新
|
|
23
|
+
useOptionUpdate(ripplesRef, option);
|
|
24
|
+
// 抛出事件 (自定义抛出事件)
|
|
25
|
+
useImperativeHandle(ref, createImperativeHandle(ripplesRef));
|
|
26
|
+
return (jsxs(Content, { style: {
|
|
27
|
+
backgroundRepeat: 'round',
|
|
28
|
+
...style,
|
|
29
|
+
}, ..._props, children: [jsx("canvas", { ref: canvas, "data-earthnut-ui": "canvas", width: 0, height: 0 }), children] }));
|
|
30
|
+
};
|
|
16
31
|
|
|
17
|
-
export { Content };
|
|
32
|
+
export { ComponentContent, Content };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef } from 'react';
|
|
5
4
|
import { useLazyRipples } from '../../customHooks/useRipples/use-lazy-ripple.js';
|
|
6
|
-
import {
|
|
7
|
-
import { useOptionUpdate } from './useOptionUpdate.js';
|
|
5
|
+
import { ComponentContent } from './Content.js';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
*
|
|
@@ -25,53 +23,24 @@ import { useOptionUpdate } from './useOptionUpdate.js';
|
|
|
25
23
|
* 使用:
|
|
26
24
|
*
|
|
27
25
|
* ```ts
|
|
28
|
-
* import {
|
|
26
|
+
* import { LazyBackgroundRipple } from 'enr/LazyBackgroundRipple';
|
|
29
27
|
* // 也可以全量导入
|
|
30
|
-
* // import {
|
|
28
|
+
* // import { LazyBackgroundRipple } from 'enr';
|
|
31
29
|
* ...
|
|
32
30
|
* const animationFrameId = useAnimationFrame();
|
|
33
31
|
*
|
|
34
|
-
* return <
|
|
32
|
+
* return <LazyBackgroundRipple>
|
|
35
33
|
* ...
|
|
36
|
-
* </
|
|
34
|
+
* </LazyBackgroundRipple>
|
|
37
35
|
* ```
|
|
38
36
|
*
|
|
39
37
|
*/
|
|
40
38
|
const LazyBackgroundRipple = ({ option, ...props }) => {
|
|
41
|
-
const { children, style, ref, ..._props } = props;
|
|
42
39
|
/** canvas 元素 */
|
|
43
40
|
const canvas = useRef(null);
|
|
44
41
|
/** 使用 ripples */
|
|
45
42
|
const { ripples } = useLazyRipples(canvas, option);
|
|
46
|
-
|
|
47
|
-
/// 使用 配置更新
|
|
48
|
-
useOptionUpdate(ripples, option);
|
|
49
|
-
// 抛出事件 (自定义抛出事件)
|
|
50
|
-
useImperativeHandle(ref, () => ({
|
|
51
|
-
toggleState: () => ripples.current?.changePlayingState() ?? false,
|
|
52
|
-
get state() {
|
|
53
|
-
return ripples.current?.options.playingState ?? false;
|
|
54
|
-
},
|
|
55
|
-
pause() {
|
|
56
|
-
ripples.current?.pause();
|
|
57
|
-
},
|
|
58
|
-
play() {
|
|
59
|
-
ripples.current?.play();
|
|
60
|
-
},
|
|
61
|
-
set(options) {
|
|
62
|
-
if (isUndefined(options))
|
|
63
|
-
return;
|
|
64
|
-
const keys = Object.keys(options);
|
|
65
|
-
for (let i = 0, j = keys.length; i < j; i++) {
|
|
66
|
-
const key = keys[i];
|
|
67
|
-
ripples.current?.set(key, options[key]);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
}));
|
|
71
|
-
return (jsxs(Content, { style: {
|
|
72
|
-
backgroundRepeat: 'round',
|
|
73
|
-
...style,
|
|
74
|
-
}, ..._props, children: [jsx("canvas", { ref: canvas, "data-earthnut-ui": "canvas", width: 0, height: 0 }), children] }));
|
|
43
|
+
return jsx(ComponentContent, { ripplesRef: ripples, canvas: canvas, option: option, ...props });
|
|
75
44
|
};
|
|
76
45
|
LazyBackgroundRipple.displayName = 'enr-lazy-background-ripple';
|
|
77
46
|
|