earthnut 0.0.0 → 0.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/BackgroundRipple/index.cjs +1 -0
- package/BackgroundRipple/index.mjs +1 -0
- package/LICENSE +25 -0
- package/Layout/index.cjs +1 -0
- package/Layout/index.mjs +1 -0
- package/README.md +24 -5
- package/components/button/button.d.ts +5 -0
- package/components/button/index.d.ts +3 -0
- package/components/button/style/index.d.ts +1 -0
- package/components/index.d.ts +3 -0
- package/components/layout/content.d.ts +11 -0
- package/components/layout/footer.d.ts +16 -0
- package/components/layout/header.d.ts +18 -0
- package/components/layout/index.d.ts +2 -0
- package/components/layout/layout.d.ts +50 -0
- package/components/layout/sideBar.d.ts +24 -0
- package/components/layout/types.d.ts +71 -0
- package/components/menu/index.d.ts +0 -0
- package/components/menu/menu.d.ts +0 -0
- package/components/menu/style/index.d.ts +0 -0
- package/components/ripples/RipplesEle.d.ts +36 -0
- package/components/ripples/index.d.ts +4 -0
- package/components/ripples/style/index.d.ts +0 -0
- package/components/ripples/types.d.ts +11 -0
- package/components/ripples/useOptionUpdate.d.ts +5 -0
- package/customHooks/index.d.ts +5 -0
- package/customHooks/useAnimationFrame.d.ts +42 -0
- package/customHooks/useInputIsComposing.d.ts +46 -0
- package/customHooks/useRipples/buildBackground/create-background-color.d.ts +3 -0
- package/customHooks/useRipples/buildBackground/create-linear-gradient.d.ts +3 -0
- package/customHooks/useRipples/buildBackground/default-background/_createImageData.d.ts +7 -0
- package/customHooks/useRipples/buildBackground/default-background/circleDataList.d.ts +18 -0
- package/customHooks/useRipples/buildBackground/default-background/createCanvasElementBySize.d.ts +2 -0
- package/customHooks/useRipples/buildBackground/default-background/createDefault.d.ts +2 -0
- package/customHooks/useRipples/buildBackground/default-background/index.d.ts +10 -0
- package/customHooks/useRipples/buildBackground/loadImage.d.ts +13 -0
- package/customHooks/useRipples/buildBackground/runSide.d.ts +9 -0
- package/customHooks/useRipples/buildBackground/type.d.ts +31 -0
- package/customHooks/useRipples/buildBackground/utils/bindImage.d.ts +4 -0
- package/customHooks/useRipples/buildBackground/utils/createCanvasElement.d.ts +3 -0
- package/customHooks/useRipples/buildBackground/utils/createImageBySrc.d.ts +2 -0
- package/customHooks/useRipples/buildBackground/utils/getBackgroundStyle.d.ts +3 -0
- package/customHooks/useRipples/buildBackground/utils/hideCssBackground.d.ts +10 -0
- package/customHooks/useRipples/buildBackground/utils/restore-css-background.d.ts +7 -0
- package/customHooks/useRipples/callback/destroy.d.ts +3 -0
- package/customHooks/useRipples/callback/drop.d.ts +3 -0
- package/customHooks/useRipples/callback/fade.d.ts +3 -0
- package/customHooks/useRipples/callback/reload-background.d.ts +6 -0
- package/customHooks/useRipples/callback/scale.d.ts +2 -0
- package/customHooks/useRipples/index.d.ts +40 -0
- package/customHooks/useRipples/init/index.d.ts +5 -0
- package/customHooks/useRipples/init/initEvent.d.ts +5 -0
- package/customHooks/useRipples/init/initShaders.d.ts +7 -0
- package/customHooks/useRipples/init/initTexture.d.ts +7 -0
- package/customHooks/useRipples/render/computeTextureBoundaries.d.ts +3 -0
- package/customHooks/useRipples/render/draw.d.ts +7 -0
- package/customHooks/useRipples/render/drawQuad.d.ts +7 -0
- package/customHooks/useRipples/render/dropAtPointer.d.ts +7 -0
- package/customHooks/useRipples/render/index.d.ts +6 -0
- package/customHooks/useRipples/render/swapBufferIndices.d.ts +5 -0
- package/customHooks/useRipples/render/update.d.ts +5 -0
- package/customHooks/useRipples/rippersData/defaultData.d.ts +5 -0
- package/customHooks/useRipples/rippersData/fadeData.d.ts +43 -0
- package/customHooks/useRipples/rippersData/index.d.ts +40 -0
- package/customHooks/useRipples/rippersData/loadConfig.d.ts +19 -0
- package/customHooks/useRipples/rippersData/renderData.d.ts +74 -0
- package/customHooks/useRipples/rippersData/useOptions.d.ts +81 -0
- package/customHooks/useRipples/rippersData/vertexSource.d.ts +28 -0
- package/customHooks/useRipples/ripple.html.d.ts +6 -0
- package/customHooks/useRipples/ripplesClass.d.ts +51 -0
- package/customHooks/useRipples/tools.d.ts +31 -0
- package/customHooks/useRipples/types.d.ts +192 -0
- package/customHooks/useTimeId.d.ts +55 -0
- package/dog.d.ts +3 -0
- package/index.cjs +1 -0
- package/index.d.ts +5 -0
- package/index.js.LICENSE.txt +79 -0
- package/index.mjs +1 -0
- package/package.json +86 -14
- package/styles/common.css +360 -0
- package/styles/common.scss +444 -0
- package/useAnimationFrame/index.cjs +1 -0
- package/useAnimationFrame/index.mjs +1 -0
- package/useInputIsComposing/index.cjs +1 -0
- package/useInputIsComposing/index.mjs +1 -0
- package/useRipples/index.cjs +1 -0
- package/useRipples/index.mjs +1 -0
- package/useTimeId/index.cjs +1 -0
- package/useTimeId/index.mjs +1 -0
- package/index.js +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* @Author earthnut
|
|
3
|
+
* @Email earthnut.dev@outlook.com
|
|
4
|
+
* @ProjectName website
|
|
5
|
+
* @FileName loadConfig.ts
|
|
6
|
+
* @CreateDate 周五 12/13/2024
|
|
7
|
+
* @Description 加载 config
|
|
8
|
+
****************************************************************************/
|
|
9
|
+
import { RipplesData } from './index';
|
|
10
|
+
/**
|
|
11
|
+
* 执行的配置数据
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadConfig(this: RipplesData): {
|
|
15
|
+
type: number;
|
|
16
|
+
linearSupport: boolean;
|
|
17
|
+
arrayType: Float32ArrayConstructor | null;
|
|
18
|
+
extensions: string[];
|
|
19
|
+
} | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { OriginStyle } from '../buildBackground/type';
|
|
2
|
+
import { Ripples } from '../ripplesClass';
|
|
3
|
+
import { Program, Textures } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* 原始数据类
|
|
7
|
+
*
|
|
8
|
+
* 记录了除参数数据外的运行数据
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare class RipplesRenderData {
|
|
12
|
+
/** 渲染数据流
|
|
13
|
+
*
|
|
14
|
+
* 该值在 init 中进行初始化
|
|
15
|
+
*/
|
|
16
|
+
quad: WebGLBuffer;
|
|
17
|
+
/**
|
|
18
|
+
* 上一次雨滴滴落的时间
|
|
19
|
+
*
|
|
20
|
+
* 该时间更新触发时机:
|
|
21
|
+
* - 2.2s 内没有事件触发
|
|
22
|
+
* - 鼠标交互更新
|
|
23
|
+
*/
|
|
24
|
+
lastRaindropsFallTime: number;
|
|
25
|
+
/** canvas 父级元素 该值在主 class 中初始化 */
|
|
26
|
+
parentElement: HTMLElement;
|
|
27
|
+
/** 父级元素的属性变化监听者 */
|
|
28
|
+
mutationObserver: null | MutationObserver;
|
|
29
|
+
/** 父级尺寸变化监听者 */
|
|
30
|
+
resizeObserver: null | ResizeObserver;
|
|
31
|
+
/** 渲染程序 */
|
|
32
|
+
renderProgram: Program;
|
|
33
|
+
/** 图像资源的配置 */
|
|
34
|
+
imageSource: string;
|
|
35
|
+
/** 该值于初始化着色器时初始化 */
|
|
36
|
+
dropProgram: Program;
|
|
37
|
+
/** 更新流 */
|
|
38
|
+
updateProgram: Program;
|
|
39
|
+
/** 纹理 */
|
|
40
|
+
textures: Textures;
|
|
41
|
+
/** 背景纹理 */
|
|
42
|
+
backgroundTexture: WebGLTexture;
|
|
43
|
+
/** 纹理数据 */
|
|
44
|
+
textureDelta: Float32Array<ArrayBuffer>;
|
|
45
|
+
/** */
|
|
46
|
+
framebuffers: WebGLFramebuffer[];
|
|
47
|
+
/** */
|
|
48
|
+
bufferWriteIndex: number;
|
|
49
|
+
/** */
|
|
50
|
+
bufferReadIndex: number;
|
|
51
|
+
/** 最原始的样式 */
|
|
52
|
+
originStyle: OriginStyle;
|
|
53
|
+
/** 上一次使用的样式 */
|
|
54
|
+
lastUseStyle: OriginStyle;
|
|
55
|
+
/** 事件 */
|
|
56
|
+
events: {
|
|
57
|
+
mousemove: (e: MouseEvent) => void;
|
|
58
|
+
mousedown: (e: MouseEvent) => void;
|
|
59
|
+
touchmove: (e: TouchEvent) => void;
|
|
60
|
+
touchstart: (e: TouchEvent) => void;
|
|
61
|
+
};
|
|
62
|
+
/** 渲染 id */
|
|
63
|
+
animationFrameId: number;
|
|
64
|
+
/**
|
|
65
|
+
* 构建 Ripple 的渲染数据
|
|
66
|
+
*
|
|
67
|
+
* @param canvas 使用初始化的 Canvas 元素
|
|
68
|
+
* @param callback 执行的回调,这里要对页面背景进行更新
|
|
69
|
+
* @param _Ripples 上一个回调在使用中的 this
|
|
70
|
+
*/
|
|
71
|
+
constructor(canvas: HTMLCanvasElement, callback: () => void, _Ripples: Ripples);
|
|
72
|
+
/** 销毁 */
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ImageCrossOrigin, RipplesUseOptions } from '../types';
|
|
2
|
+
/** 用户使用参数 */
|
|
3
|
+
export declare class UseOptions {
|
|
4
|
+
#private;
|
|
5
|
+
/** 倍级触发光标事件 */
|
|
6
|
+
set accelerating(value: number);
|
|
7
|
+
/**
|
|
8
|
+
* 倍级触发光标事件
|
|
9
|
+
*/
|
|
10
|
+
get accelerating(): number;
|
|
11
|
+
/** 是否与鼠标互动 */
|
|
12
|
+
set interactive(value: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* 是否与鼠标互动
|
|
15
|
+
*/
|
|
16
|
+
get interactive(): boolean;
|
|
17
|
+
/** 分辨率
|
|
18
|
+
*
|
|
19
|
+
* 纹理的尺寸,该项目中该值为纹理的宽和高
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
set resolution(value: number);
|
|
23
|
+
/**
|
|
24
|
+
* 纹理的尺寸,该项目中该值为纹理的宽和高
|
|
25
|
+
*/
|
|
26
|
+
get resolution(): number;
|
|
27
|
+
/**
|
|
28
|
+
* 扰动系数
|
|
29
|
+
*
|
|
30
|
+
* 缺省 `0.01`
|
|
31
|
+
*
|
|
32
|
+
* 取之范围 `0.01 - 1`
|
|
33
|
+
*/
|
|
34
|
+
set perturbance(value: number);
|
|
35
|
+
/**
|
|
36
|
+
* 扰动系数
|
|
37
|
+
*/
|
|
38
|
+
get perturbance(): number;
|
|
39
|
+
/**
|
|
40
|
+
* 扩散半径
|
|
41
|
+
*
|
|
42
|
+
* 缺省为 `20`
|
|
43
|
+
*/
|
|
44
|
+
set dropRadius(value: number);
|
|
45
|
+
/**
|
|
46
|
+
* 扩散半径
|
|
47
|
+
*/
|
|
48
|
+
get dropRadius(): number;
|
|
49
|
+
/** 传入的背景图片 */
|
|
50
|
+
imgUrl: string | string[] | null;
|
|
51
|
+
/** 闲置波动 */
|
|
52
|
+
set idleFluctuations(value: boolean);
|
|
53
|
+
/**
|
|
54
|
+
* 闲置波动
|
|
55
|
+
*/
|
|
56
|
+
get idleFluctuations(): boolean;
|
|
57
|
+
/** 雨滴落下的时间间隔 */
|
|
58
|
+
set raindropsTimeInterval(value: number);
|
|
59
|
+
/**
|
|
60
|
+
* 雨滴落下的时间间隔
|
|
61
|
+
*/
|
|
62
|
+
get raindropsTimeInterval(): number;
|
|
63
|
+
/** crossOrigin (是否跨域) */
|
|
64
|
+
crossOrigin: ImageCrossOrigin;
|
|
65
|
+
/** canvas 的显隐 */
|
|
66
|
+
visible: boolean;
|
|
67
|
+
/** 当前执行的状态 */
|
|
68
|
+
running: boolean;
|
|
69
|
+
/** 当前执行的状态 */
|
|
70
|
+
set playingState(value: boolean);
|
|
71
|
+
/**
|
|
72
|
+
* 当前执行的状态
|
|
73
|
+
*/
|
|
74
|
+
get playingState(): boolean;
|
|
75
|
+
/** 上一次执行渲染状态 */
|
|
76
|
+
lastRunningState: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* 构建使用参数的数据
|
|
79
|
+
*/
|
|
80
|
+
constructor(options: RipplesUseOptions);
|
|
81
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
export declare const vertexShader = "\n attribute vec2 vertex;\n varying vec2 coord;\n void main() {\n coord = vertex * 0.5 + 0.5;\n gl_Position = vec4(vertex, 0.0, 1.0);\n }";
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare const updateProgramFragmentSource = "\n precision highp float;\n\n uniform sampler2D texture;\n uniform vec2 delta;\n\n varying vec2 coord;\n\n void main() {\n vec4 info = texture2D(texture, coord);\n \n vec2 dx = vec2(delta.x, 0.0);\n vec2 dy = vec2(0.0, delta.y);\n \n float average = (\n texture2D(texture, coord - dx).r +\n texture2D(texture, coord - dy).r +\n texture2D(texture, coord + dx).r +\n texture2D(texture, coord + dy).r\n ) * 0.25;\n \n info.g += (average - info.r) * 2.0;\n info.g *= 0.995;\n info.r += info.g;\n \n gl_FragColor = info;\n }\n ";
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export declare const renderVertexSource = "\n precision highp float;\n\n attribute vec2 vertex;\n uniform vec2 topLeft;\n uniform vec2 bottomRight;\n uniform vec2 containerRatio;\n varying vec2 ripplesCoord;\n varying vec2 backgroundCoord;\n void main() {\n backgroundCoord = mix(topLeft, bottomRight, vertex * 0.5 + 0.5);\n backgroundCoord.y = 1.0 - backgroundCoord.y;\n ripplesCoord = vec2(vertex.x, -vertex.y) * containerRatio * 0.5 + 0.5;\n gl_Position = vec4(vertex.x, -vertex.y, 0.0, 1.0);\n }\n ";
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare const renderProgramFragmentSource = "\n precision highp float;\n\n uniform sampler2D samplerBackground;\n uniform sampler2D samplerRipples;\n uniform vec2 delta;\n\n uniform float perturbance;\n varying vec2 ripplesCoord;\n varying vec2 backgroundCoord;\n\n void main() {\n float height = texture2D(samplerRipples, ripplesCoord).r;\n float heightX = texture2D(samplerRipples, vec2(ripplesCoord.x + delta.x, ripplesCoord.y)).r;\n float heightY = texture2D(samplerRipples, vec2(ripplesCoord.x, ripplesCoord.y + delta.y)).r;\n vec3 dx = vec3(delta.x, heightX - height, 0.0);\n vec3 dy = vec3(0.0, heightY - height, delta.y);\n vec2 offset = -normalize(cross(dy, dx)).xz;\n float specular = pow(max(0.0, dot(offset, normalize(vec2(-0.6, 1.0)))), 4.0);\n gl_FragColor = texture2D(samplerBackground, backgroundCoord + offset * perturbance) + specular;\n }";
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* fragmentSource
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare const dropProgramFragmentSource = "precision highp float;\n\n const float PI = 3.141592653589793;\n uniform sampler2D texture;\n uniform vec2 center;\n uniform float radius;\n uniform float strength;\n\n varying vec2 coord;\n\n void main() {\n vec4 info = texture2D(texture, coord);\n\n float drop = max(0.0, 1.0 - length(center * 0.5 + 0.5 - coord) / radius);\n drop = 0.5 - cos(drop * PI) * 0.5;\n info.r += drop * strength;\n gl_FragColor = info;\n }";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RipplesData } from './rippersData';
|
|
2
|
+
import { RipplesOptions } from './types';
|
|
3
|
+
import { RipplesRenderData } from './rippersData/renderData';
|
|
4
|
+
import { UseOptions } from './rippersData/useOptions';
|
|
5
|
+
import { FadeData } from './rippersData/fadeData';
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* ## 水波动涟漪的效果
|
|
9
|
+
*
|
|
10
|
+
* 魔改自大佬的[jQuey 代码](https://github.com/sirxemic/jquery.ripples)
|
|
11
|
+
*/
|
|
12
|
+
export declare class Ripples extends RipplesData {
|
|
13
|
+
#private;
|
|
14
|
+
/** 渲染数据 */
|
|
15
|
+
renderData: RipplesRenderData | null;
|
|
16
|
+
/** 使用参数 */
|
|
17
|
+
options: UseOptions;
|
|
18
|
+
/** 背景使用的数据 */
|
|
19
|
+
fadeData: FadeData;
|
|
20
|
+
defaults: import("./types").RipplesUseOptions;
|
|
21
|
+
/** 初始化状态 */
|
|
22
|
+
initialized: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 构建 Ripple 对象
|
|
25
|
+
*/
|
|
26
|
+
constructor(canvas: HTMLCanvasElement, options?: RipplesOptions);
|
|
27
|
+
/** 模拟雨滴下落 */
|
|
28
|
+
raindropsFall(): void;
|
|
29
|
+
/** 公共方法,触发 */
|
|
30
|
+
drop(x: number, y: number, radius: number, strength: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* 缓进缓出
|
|
33
|
+
*/
|
|
34
|
+
fade(): void;
|
|
35
|
+
/** 元素的尺寸发生变化 */
|
|
36
|
+
reloadBackground(): void;
|
|
37
|
+
/** 销毁 */
|
|
38
|
+
destroy(): void;
|
|
39
|
+
/** 展示元素 */
|
|
40
|
+
show(): void;
|
|
41
|
+
/** 隐藏元素 */
|
|
42
|
+
hide(): void;
|
|
43
|
+
/** 暂停动画涟漪状态 */
|
|
44
|
+
pause(): void;
|
|
45
|
+
/** 播放动画涟漪状态 */
|
|
46
|
+
play(): void;
|
|
47
|
+
/** 切换当前状态 */
|
|
48
|
+
changePlayingState(): void;
|
|
49
|
+
/** 给初始化变量赋值 */
|
|
50
|
+
set(property: keyof RipplesOptions, value: unknown): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* @Author earthnut
|
|
3
|
+
* @Email earthnut.dev@outlook.com
|
|
4
|
+
* @ProjectName website
|
|
5
|
+
* @FileName tools.ts
|
|
6
|
+
* @CreateDate 周六 12/07/2024
|
|
7
|
+
* @Description 工具
|
|
8
|
+
****************************************************************************/
|
|
9
|
+
import { Ripples } from './ripplesClass';
|
|
10
|
+
import { Program } from './types';
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* 增加 WebGLProgram
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare function createProgram(vertexSource: string, fragmentSource: string, gl: WebGLRenderingContext, _uniformValues?: string): Program;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* 绑定纹理
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export declare function bindTexture(this: Ripples, texture: WebGLTexture, unit?: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* 给 canvas 设置样式
|
|
26
|
+
*/
|
|
27
|
+
export declare function setCanvasStyle(canvas: HTMLCanvasElement): void;
|
|
28
|
+
/** 背景色值为空 */
|
|
29
|
+
export declare function isNoneBackGroundColor(color: string): boolean;
|
|
30
|
+
/** 背景图为空 */
|
|
31
|
+
export declare function isNoneBackgroundImage(src: string): boolean;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* @Author earthnut
|
|
3
|
+
* @Email earthnut.dev@outlook.com
|
|
4
|
+
* @ProjectName react-ripples
|
|
5
|
+
* @FileName interface.ts
|
|
6
|
+
* @CreateDate 周二 12/17/2024
|
|
7
|
+
* @Description BackgroundRipples 的类型声明文件
|
|
8
|
+
****************************************************************************/
|
|
9
|
+
import { CSSProperties, ReactElement } from 'react';
|
|
10
|
+
export type ImageCrossOrigin = 'anonymous' | 'use-credentials' | 'no-cors';
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* 背景涟漪的 props 类型
|
|
14
|
+
*
|
|
15
|
+
* - children 可选属性,定义子组件或子组件们
|
|
16
|
+
* - style 可选属性,定义自定义外壳的样式,在内含 `children` 时生效
|
|
17
|
+
* - option 可选属性,自定义涟漪的初始化属性
|
|
18
|
+
* - resolution 分辨率,纹理的尺寸,该项目中该值为纹理的宽和高,缺省为 `256`
|
|
19
|
+
* - dropRadius 扩撒半径,缺省值为 `20`
|
|
20
|
+
* - perturbance 扰动系数,缺省为 `0.03`
|
|
21
|
+
* - interactive 光标交互,缺省为 `true` ,关闭须显示传入 `false` 值
|
|
22
|
+
* - accelerating 加速光标移动触发,缺省为 `1`
|
|
23
|
+
* - crossOrigin 原始样式
|
|
24
|
+
* - imgUrl 原始背景图片地址
|
|
25
|
+
* - playingState 当前的播放状态,缺省为 `true` ,设定为 `false` 时并不关闭,而是暂停
|
|
26
|
+
* - raindropsTimeInterval 雨滴滴落的间隔,缺省为 `3600`,可设置区间为 `10 ~ 12000`
|
|
27
|
+
* 该值还将影响无背景设置时默认背景的切换频率,几乎每两个雨滴落下就会切换一次背景
|
|
28
|
+
* - idleFluctuations 闲置波动,在光标交互不触发时,将触发模拟雨滴,缺省为 `true`
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export interface BackgroundRipplesProps {
|
|
32
|
+
/**
|
|
33
|
+
* 用于设定外层的样式
|
|
34
|
+
*/
|
|
35
|
+
style?: CSSProperties;
|
|
36
|
+
/** 子元素 */
|
|
37
|
+
children?: ReactElement;
|
|
38
|
+
/**
|
|
39
|
+
* ## 可设定涟漪的参数
|
|
40
|
+
*
|
|
41
|
+
* - resolution 波速,值越小,波动越快。缺省为 `360`
|
|
42
|
+
* - dropRadius 波动强度,值越小,波动效果越大,缺省值为 `12`
|
|
43
|
+
* - perturbance 扰动系数,值越大,对原背景造成干涉越强,缺省为 `0.01`
|
|
44
|
+
* - interactive 光标交互,缺省为 `true` ,关闭须显示传入 `false` 值
|
|
45
|
+
* - accelerating 加速光标移动触发,类似于扰动系数,及作用与鼠标或手指触发,缺省为 `1`
|
|
46
|
+
* - crossOrigin 原始样式
|
|
47
|
+
* - imgUrl 原始背景图片地址
|
|
48
|
+
* - playingState 当前的播放状态,缺省为 `true` ,设定为 `false` 时并不关闭,而是暂停
|
|
49
|
+
* - raindropsTimeInterval 雨滴滴落的间隔,缺省为 `3650`,可设置区间为 `10 ~ 12000`,值越小,雨越大
|
|
50
|
+
* 该值还将影响无背景设置时默认背景的切换频率,几乎每两个雨滴落下就会切换一次背景
|
|
51
|
+
* - idleFluctuations 闲置波动,在光标交互不触发时,将触发模拟雨滴,缺省为 `true`
|
|
52
|
+
*/
|
|
53
|
+
option?: RipplesOptions;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* WebGLProgram
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
export interface Program {
|
|
61
|
+
id: WebGLProgram;
|
|
62
|
+
uniforms: {
|
|
63
|
+
[x: string]: Float32Array;
|
|
64
|
+
};
|
|
65
|
+
locations: {
|
|
66
|
+
[x: string]: WebGLUniformLocation;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export type RipplesUseOptions = {
|
|
70
|
+
/**
|
|
71
|
+
* 波速
|
|
72
|
+
*
|
|
73
|
+
* 作用为波传播的速度,值越大,波传播的越慢
|
|
74
|
+
*
|
|
75
|
+
* 缺省为 `360`
|
|
76
|
+
*/
|
|
77
|
+
resolution: number;
|
|
78
|
+
/**
|
|
79
|
+
* 波动强度
|
|
80
|
+
*
|
|
81
|
+
* 值越小,波动越明显
|
|
82
|
+
*
|
|
83
|
+
* 缺省为 `12`
|
|
84
|
+
*/
|
|
85
|
+
dropRadius: number;
|
|
86
|
+
/**
|
|
87
|
+
* 扰动系数
|
|
88
|
+
*
|
|
89
|
+
* 缺省 `0.01`
|
|
90
|
+
*
|
|
91
|
+
* 取之范围 `0.01 - 1`
|
|
92
|
+
*
|
|
93
|
+
* 值越大,扰动效果越明显
|
|
94
|
+
*/
|
|
95
|
+
perturbance: number;
|
|
96
|
+
/**
|
|
97
|
+
* 是否开启光标滑动轨迹
|
|
98
|
+
*
|
|
99
|
+
* 缺省为 `true`
|
|
100
|
+
*/
|
|
101
|
+
interactive: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* 加速光标移动触发,缺省为 `1`
|
|
104
|
+
*
|
|
105
|
+
*
|
|
106
|
+
* 由于大佬原方法在光标触发 mousemove 时不怎么明显
|
|
107
|
+
*
|
|
108
|
+
* 所以以倍级触发会让波动更加明显
|
|
109
|
+
*
|
|
110
|
+
* 可设置区间为 `2 - 100`
|
|
111
|
+
*/
|
|
112
|
+
accelerating: number;
|
|
113
|
+
/**
|
|
114
|
+
* 原设定的背景图片
|
|
115
|
+
*
|
|
116
|
+
* 缺省为 `''`
|
|
117
|
+
*/
|
|
118
|
+
crossOrigin: ImageCrossOrigin;
|
|
119
|
+
/**
|
|
120
|
+
* 设定的元素背景的 url 地址
|
|
121
|
+
*
|
|
122
|
+
* 缺省为 `''`
|
|
123
|
+
*/
|
|
124
|
+
imgUrl: string | string[] | null;
|
|
125
|
+
/**
|
|
126
|
+
* 当前涟漪的状态
|
|
127
|
+
*
|
|
128
|
+
* 缺省为 `true` , 即涟漪触发正在执行
|
|
129
|
+
*/
|
|
130
|
+
playingState: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* 雨滴滴落的时间间隔
|
|
133
|
+
*
|
|
134
|
+
* 单位为 ms
|
|
135
|
+
*
|
|
136
|
+
* 缺省值为 `3600`
|
|
137
|
+
*
|
|
138
|
+
*
|
|
139
|
+
* 可设置区间为 `10 ~ 12000`
|
|
140
|
+
*
|
|
141
|
+
* 该值还将影响无背景设置时默认背景的切换频率,几乎每两个雨滴落下就会切换一次背景
|
|
142
|
+
*/
|
|
143
|
+
raindropsTimeInterval: number;
|
|
144
|
+
/**
|
|
145
|
+
* 闲置波动
|
|
146
|
+
*
|
|
147
|
+
* 在光标交互不触发时,将触发模拟雨滴
|
|
148
|
+
*
|
|
149
|
+
* 缺省为 `true`
|
|
150
|
+
*/
|
|
151
|
+
idleFluctuations: boolean;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
* 涟漪设定参数
|
|
156
|
+
*
|
|
157
|
+
* - resolution 分波速,值越小,波动越快。缺省为 `360`
|
|
158
|
+
* - dropRadius 波动强度,值越小,波动效果越大,缺省值为 `12`
|
|
159
|
+
* - perturbance 扰动系数,值越大,对原背景造成干涉越强,缺省为 `0.01`
|
|
160
|
+
* - interactive 光标交互,缺省为 `true` ,关闭须显示传入 `false` 值
|
|
161
|
+
* - accelerating 加速光标移动触发,类似于扰动系数,及作用与鼠标或手指触发,缺省为 `1`
|
|
162
|
+
* - crossOrigin 原始样式
|
|
163
|
+
* - imgUrl 原始背景图片地址
|
|
164
|
+
* - playingState 当前的播放状态,缺省为 `true` ,设定为 `false` 时并不关闭,而是暂停
|
|
165
|
+
* - raindropsTimeInterval 雨滴滴落的间隔,缺省为 `3650`,可设置区间为 `10 ~ 12000`,值越小,雨越大
|
|
166
|
+
* 该值还将影响无背景设置时默认背景的切换频率,几乎每两个雨滴落下就会切换一次背景
|
|
167
|
+
* - idleFluctuations 闲置波动,在光标交互不触发时,将触发模拟雨滴,缺省为 `true`
|
|
168
|
+
*/
|
|
169
|
+
export type RipplesOptions = {
|
|
170
|
+
[x in keyof RipplesUseOptions]?: RipplesUseOptions[x];
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 初始默认值
|
|
174
|
+
*/
|
|
175
|
+
export interface RipplesDefaultData {
|
|
176
|
+
/** 默认的图像地址 */
|
|
177
|
+
imgUrl: '';
|
|
178
|
+
/** */
|
|
179
|
+
resolution: 256;
|
|
180
|
+
dropRadius: 10;
|
|
181
|
+
perturbance: 0.03;
|
|
182
|
+
interactive: true;
|
|
183
|
+
crossOrigin: '';
|
|
184
|
+
playingState: true;
|
|
185
|
+
accelerating: 1;
|
|
186
|
+
raindropsTimeInterval: 3600;
|
|
187
|
+
idleFluctuations: true;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
*/
|
|
192
|
+
export type Textures = WebGLTexture[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* @Author earthnut
|
|
3
|
+
* @Email earthnut.dev@outlook.com
|
|
4
|
+
* @ProjectName earthnut
|
|
5
|
+
* @FilePath /src/customHooks/useAnimationFrame.ts
|
|
6
|
+
* @FileName useTimeId.ts
|
|
7
|
+
* @CreateDate 周二 01/07/2025
|
|
8
|
+
* @Description 使用定时器返回的时间戳
|
|
9
|
+
****************************************************************************/
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* ### 导出一个使用 `useRef` 创建的 `NodeJS.Timeout`
|
|
13
|
+
*
|
|
14
|
+
* 该数值在组件卸载时会自动调用 `clearTimeout` 清理
|
|
15
|
+
*
|
|
16
|
+
* @version 0.0.3
|
|
17
|
+
* @see https://earthnut.dev/use-time-id
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* 使用:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { useTimeId } from 'earthnut/useTimeId';
|
|
24
|
+
* // 也可以全量导入
|
|
25
|
+
* // import { useTimeId } from 'earthnut';
|
|
26
|
+
* ...
|
|
27
|
+
* const timeoutId = useTimeId();
|
|
28
|
+
*
|
|
29
|
+
* useEffect(()=>{
|
|
30
|
+
* timeoutId.current = setTimeout(()=>{
|
|
31
|
+
* ...
|
|
32
|
+
* } ,delay);
|
|
33
|
+
* });
|
|
34
|
+
* ...
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* 其实,正确的用法是这样的:
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
*
|
|
42
|
+
* useEffect(()=>{
|
|
43
|
+
* const timeId = setTimeout(()=>{
|
|
44
|
+
* ...
|
|
45
|
+
* }, delay) ;
|
|
46
|
+
*
|
|
47
|
+
* return ()=> timeId && clearTimeout(timeId);
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* 根本就不用引入这个自定义 `hook` , 哈哈哈哈哈
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
export declare function useTimeId(): import("react").RefObject<NodeJS.Timeout | undefined>;
|
package/dog.d.ts
ADDED