earthnut 0.1.2 → 0.1.3-beta.0
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/Layout/index.cjs +1 -0
- package/Layout/index.mjs +1 -0
- package/README.md +28 -0
- package/components/button/button.d.ts +5 -0
- package/components/button/index.d.ts +3 -0
- package/components/index.d.ts +3 -0
- package/components/layout/EnLayoutContent.d.ts +3 -0
- package/components/layout/content.d.ts +11 -0
- package/components/layout/footer.d.ts +16 -0
- package/components/layout/generate-class.d.ts +2 -0
- package/components/layout/get-value.d.ts +4 -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 +101 -0
- package/components/menu/index.d.ts +0 -0
- package/components/menu/menu.d.ts +0 -0
- package/components/ripples/RipplesEle.d.ts +35 -0
- package/components/ripples/index.d.ts +4 -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/load-image.d.ts +13 -0
- package/customHooks/useRipples/buildBackground/run-side.d.ts +9 -0
- package/customHooks/useRipples/buildBackground/type.d.ts +31 -0
- package/customHooks/useRipples/buildBackground/utils/bind-image.d.ts +4 -0
- package/customHooks/useRipples/buildBackground/utils/create-canvas-element.d.ts +3 -0
- package/customHooks/useRipples/buildBackground/utils/create-image-by-src.d.ts +2 -0
- package/customHooks/useRipples/buildBackground/utils/get-background-style.d.ts +3 -0
- package/customHooks/useRipples/buildBackground/utils/hide-css-background.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 +198 -0
- package/customHooks/useTimeId.d.ts +46 -0
- package/dog.d.ts +2 -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 +2 -2
- 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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Ripples } from '../ripplesClass';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* 加载图像
|
|
5
|
+
*
|
|
6
|
+
* - 初始化的时候首先触发加载背景图像
|
|
7
|
+
* - 通过 Ripple 的 set 方法设置属性 imgUrl 值时将触发
|
|
8
|
+
* - 尺寸发生变化时亦将触发更改
|
|
9
|
+
* - 父元素的样式属性发生变更时也会触发
|
|
10
|
+
*
|
|
11
|
+
* 在加载过程中如果渲染的图片为非法的(加载错误)那么将查找当前的背景色或是背景图作为依据,再就是都没有的情况下将会渲染一个类似于旧地板的色
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadImage(this: Ripples): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** 原使用的样式 */
|
|
2
|
+
export type OriginStyle = {
|
|
3
|
+
/** 原始使用行内背景样式 */
|
|
4
|
+
inlineBackground: string;
|
|
5
|
+
/** 原始使用的行内背景色 */
|
|
6
|
+
inlineBackgroundColor: string;
|
|
7
|
+
/** 原始使用的背景图的样式 */
|
|
8
|
+
inlineBackgroundImage: string;
|
|
9
|
+
/** 元素的位置 */
|
|
10
|
+
position: string;
|
|
11
|
+
/** 元素的背景色 */
|
|
12
|
+
backgroundColor: string;
|
|
13
|
+
/** 元素的背景图 */
|
|
14
|
+
backgroundImage: string;
|
|
15
|
+
/** 元素的背景图的尺寸(多背景下) */
|
|
16
|
+
backgroundSize: string;
|
|
17
|
+
/** 元素的背景图的位置 */
|
|
18
|
+
backgroundPosition: string;
|
|
19
|
+
/** 元素的背景图的重复方式 */
|
|
20
|
+
backgroundRepeat: string;
|
|
21
|
+
/** 元素的背景图的剪切方式 */
|
|
22
|
+
backgroundClip: string;
|
|
23
|
+
/** 元素的背景图的起点 */
|
|
24
|
+
backgroundOrigin: string;
|
|
25
|
+
/** 元素的背景图相对视口的滚动方式 */
|
|
26
|
+
backgroundAttachment: string;
|
|
27
|
+
/** 当前的宽 */
|
|
28
|
+
width: number;
|
|
29
|
+
/** 当前的高 */
|
|
30
|
+
height: number;
|
|
31
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BackgroundRipplesProps, RippleImgUrl, RipplesOptions } from './types';
|
|
2
|
+
import { Ripples } from './ripplesClass';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* ## 使用绘制 ripples 上一层
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @param canvas `usrRef` 包裹的 `HTMLCanvasElement`,用于绘制图像
|
|
9
|
+
* @param props 初始化的
|
|
10
|
+
* @version 0.0.3
|
|
11
|
+
* @see https://earthnut.dev/use-ripples
|
|
12
|
+
* @see JQuery https://github.com/sirxemic/jquery.ripples
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* 下面是在 <BackgroundRipple> 中使用
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { useRipples } from 'earthnut/useRipples';
|
|
19
|
+
* // 也可以使用包全量导入
|
|
20
|
+
* // import { useRipples } from 'earthnut';
|
|
21
|
+
*
|
|
22
|
+
* export function BackgroundRipple(props: BackgroundRipplesProps) {
|
|
23
|
+
*
|
|
24
|
+
* // canvas 元素
|
|
25
|
+
* const canvas = useRef<HTMLCanvasElement>(null);
|
|
26
|
+
*
|
|
27
|
+
* // 使用 ripples
|
|
28
|
+
* const ripplesRef = useRipples(canvas, props);
|
|
29
|
+
*
|
|
30
|
+
* return (<>
|
|
31
|
+
* <canvas ref={canvas}></canvas>
|
|
32
|
+
* {props.children}
|
|
33
|
+
* </>);
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
export declare function useRipples(canvas: React.RefObject<HTMLCanvasElement | null>, props?: BackgroundRipplesProps): React.RefObject<Ripples | null>;
|
|
40
|
+
export type { Ripples, BackgroundRipplesProps, RipplesOptions, RippleImgUrl };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Ripples } from '../ripplesClass';
|
|
2
|
+
export type DrawImage = {
|
|
3
|
+
/** 资源 */
|
|
4
|
+
resource: HTMLCanvasElement | HTMLImageElement;
|
|
5
|
+
/** 类型 */
|
|
6
|
+
kind: 'image' | 'linear-gradient' | 'background-color' | 'default' | 'mix';
|
|
7
|
+
/** 标识 */
|
|
8
|
+
tag: string;
|
|
9
|
+
/** 当前的宽 */
|
|
10
|
+
width: number;
|
|
11
|
+
/** 当前的高 */
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
/** 背景渐变的数据 */
|
|
15
|
+
export declare class FadeData {
|
|
16
|
+
/** 背景页面的数据 */
|
|
17
|
+
backgroundInfo: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
/** 缺省背景图时的 id */
|
|
22
|
+
transparentId: NodeJS.Timeout;
|
|
23
|
+
/** 最后使用
|
|
24
|
+
*
|
|
25
|
+
* 如果没有 toBeList 为空值,则当前渲染的为此纹理)绘制的图像
|
|
26
|
+
*/
|
|
27
|
+
lastDrawImage: DrawImage;
|
|
28
|
+
/** 当前绘制的图像
|
|
29
|
+
*
|
|
30
|
+
* 该值仅出现在需要渐变过程中,一旦渐变完成,实际渲染的值就成了最后渲染的值
|
|
31
|
+
*/
|
|
32
|
+
toBeList: DrawImage[];
|
|
33
|
+
/** 绘制进度 */
|
|
34
|
+
drawProgress: number;
|
|
35
|
+
/** 是否处于绘制过渡状态 */
|
|
36
|
+
isTransitioning: boolean;
|
|
37
|
+
/** 执行渐变 */
|
|
38
|
+
run(): void;
|
|
39
|
+
/** 销毁 */
|
|
40
|
+
destroy(): void;
|
|
41
|
+
/** 创建背景渐变的数据 */
|
|
42
|
+
constructor(_Ripples: Ripples);
|
|
43
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* @Author earthnut
|
|
3
|
+
* @Email earthnut.dev@outlook.com
|
|
4
|
+
* @ProjectName website
|
|
5
|
+
* @FileName dataStore.ts
|
|
6
|
+
* @CreateDate 周六 12/07/2024
|
|
7
|
+
* @Description 数据库
|
|
8
|
+
****************************************************************************/
|
|
9
|
+
/**
|
|
10
|
+
* Ripple 使用的数据,Ripple 继承该类
|
|
11
|
+
*/
|
|
12
|
+
export declare class RipplesData {
|
|
13
|
+
/**
|
|
14
|
+
* canvas 元素
|
|
15
|
+
*/
|
|
16
|
+
canvas: HTMLCanvasElement;
|
|
17
|
+
/**
|
|
18
|
+
* WebGL 绘图上下文
|
|
19
|
+
*/
|
|
20
|
+
gl: WebGLRenderingContext;
|
|
21
|
+
/**
|
|
22
|
+
* 配置
|
|
23
|
+
*/
|
|
24
|
+
config: {
|
|
25
|
+
type: number;
|
|
26
|
+
linearSupport: boolean;
|
|
27
|
+
extensions: string[];
|
|
28
|
+
arrayType: Float32ArrayConstructor | null;
|
|
29
|
+
} | null;
|
|
30
|
+
/**
|
|
31
|
+
* 初始化情况
|
|
32
|
+
*/
|
|
33
|
+
initState: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 构造方法
|
|
36
|
+
*
|
|
37
|
+
* @param canvas 传入 canvas 元素来初始化必要的数据
|
|
38
|
+
*/
|
|
39
|
+
constructor(canvas: HTMLCanvasElement);
|
|
40
|
+
}
|
|
@@ -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, RippleImgUrl, 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: RippleImgUrl;
|
|
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;
|