@cos-design/ripple-water 3.5.6 → 4.1.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/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +182 -0
- package/dist/core/packages/rippleWater/src/core.d.ts +1 -0
- package/dist/core/packages/rippleWater/src/element.d.ts +1 -0
- package/dist/core/packages/rippleWater/src/react.d.ts +3 -0
- package/dist/core/packages/rippleWater/src/vue.d.ts +2 -0
- package/dist/core/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/core/packages/shared/src/element-options.d.ts +19 -0
- package/dist/core/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/core/packages/shared/src/index.d.ts +13 -0
- package/dist/{packages → core/packages}/shared/src/math.d.ts +1 -0
- package/dist/{packages/shared/src/use-element-size.d.ts → core/packages/shared/src/react/index.d.ts} +4 -19
- package/dist/core/src/components/rippleWater/core/engine.d.ts +2 -0
- package/dist/core/src/components/rippleWater/core/index.d.ts +2 -0
- package/dist/core/src/components/rippleWater/core/types.d.ts +24 -0
- package/dist/core/src/components/rippleWater/element/index.d.ts +9 -0
- package/dist/core/src/components/rippleWater/index.d.ts +3 -0
- package/dist/core/src/components/rippleWater/react/index.d.ts +4 -0
- package/dist/{src → core/src}/vite-env.d.ts +6 -0
- package/dist/element/element.css +1 -0
- package/dist/element/index.d.ts +1 -0
- package/dist/element/index.js +223 -0
- package/dist/element/packages/rippleWater/src/core.d.ts +1 -0
- package/dist/element/packages/rippleWater/src/element.d.ts +1 -0
- package/dist/element/packages/rippleWater/src/index.d.ts +3 -0
- package/dist/element/packages/rippleWater/src/react.d.ts +3 -0
- package/dist/element/packages/rippleWater/src/vue.d.ts +2 -0
- package/dist/element/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/element/packages/shared/src/element-options.d.ts +19 -0
- package/dist/element/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/element/packages/shared/src/index.d.ts +13 -0
- package/dist/element/packages/shared/src/math.d.ts +2 -0
- package/dist/element/packages/shared/src/photo.d.ts +15 -0
- package/dist/element/packages/shared/src/pointer.d.ts +14 -0
- package/dist/element/packages/shared/src/react/index.d.ts +30 -0
- package/dist/element/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/element/packages/shared/src/size.d.ts +8 -0
- package/dist/element/packages/shared/src/visibility.d.ts +2 -0
- package/dist/element/src/components/rippleWater/core/engine.d.ts +2 -0
- package/dist/element/src/components/rippleWater/core/index.d.ts +2 -0
- package/dist/element/src/components/rippleWater/core/types.d.ts +24 -0
- package/dist/element/src/components/rippleWater/element/index.d.ts +9 -0
- package/dist/element/src/components/rippleWater/index.d.ts +3 -0
- package/dist/element/src/components/rippleWater/react/index.d.ts +4 -0
- package/dist/element/src/vite-env.d.ts +45 -0
- package/dist/react/index.cjs +76 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +205 -0
- package/dist/react/packages/rippleWater/src/core.d.ts +1 -0
- package/dist/react/packages/rippleWater/src/element.d.ts +1 -0
- package/dist/react/packages/rippleWater/src/index.d.ts +3 -0
- package/dist/react/packages/rippleWater/src/react.d.ts +3 -0
- package/dist/react/packages/rippleWater/src/vue.d.ts +2 -0
- package/dist/react/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/react/packages/shared/src/element-options.d.ts +19 -0
- package/dist/react/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/react/packages/shared/src/index.d.ts +13 -0
- package/dist/react/packages/shared/src/math.d.ts +2 -0
- package/dist/react/packages/shared/src/photo.d.ts +15 -0
- package/dist/react/packages/shared/src/pointer.d.ts +14 -0
- package/dist/react/packages/shared/src/react/index.d.ts +30 -0
- package/dist/react/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/react/packages/shared/src/size.d.ts +8 -0
- package/dist/react/packages/shared/src/visibility.d.ts +2 -0
- package/dist/react/react.css +1 -0
- package/dist/react/src/components/rippleWater/core/engine.d.ts +2 -0
- package/dist/react/src/components/rippleWater/core/index.d.ts +2 -0
- package/dist/react/src/components/rippleWater/core/types.d.ts +24 -0
- package/dist/react/src/components/rippleWater/element/index.d.ts +9 -0
- package/dist/react/src/components/rippleWater/index.d.ts +3 -0
- package/dist/react/src/components/rippleWater/react/index.d.ts +4 -0
- package/dist/react/src/vite-env.d.ts +45 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +225 -0
- package/dist/vue/packages/rippleWater/src/core.d.ts +1 -0
- package/dist/vue/packages/rippleWater/src/element.d.ts +1 -0
- package/dist/vue/packages/rippleWater/src/index.d.ts +3 -0
- package/dist/vue/packages/rippleWater/src/react.d.ts +3 -0
- package/dist/vue/packages/rippleWater/src/vue.d.ts +2 -0
- package/dist/vue/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/vue/packages/shared/src/element-options.d.ts +19 -0
- package/dist/vue/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/vue/packages/shared/src/index.d.ts +13 -0
- package/dist/vue/packages/shared/src/math.d.ts +2 -0
- package/dist/vue/packages/shared/src/photo.d.ts +15 -0
- package/dist/vue/packages/shared/src/pointer.d.ts +14 -0
- package/dist/vue/packages/shared/src/react/index.d.ts +30 -0
- package/dist/vue/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/vue/packages/shared/src/size.d.ts +8 -0
- package/dist/vue/packages/shared/src/visibility.d.ts +2 -0
- package/dist/vue/src/components/rippleWater/core/engine.d.ts +2 -0
- package/dist/vue/src/components/rippleWater/core/index.d.ts +2 -0
- package/dist/vue/src/components/rippleWater/core/types.d.ts +24 -0
- package/dist/vue/src/components/rippleWater/element/index.d.ts +9 -0
- package/dist/vue/src/components/rippleWater/index.d.ts +3 -0
- package/dist/vue/src/components/rippleWater/react/index.d.ts +4 -0
- package/dist/vue/src/vite-env.d.ts +45 -0
- package/dist/vue/vue.css +1 -0
- package/package.json +44 -12
- package/dist/index.cjs +0 -93
- package/dist/index.css +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -210
- package/dist/packages/shared/src/index.d.ts +0 -10
- package/dist/src/components/rippleWater/index.d.ts +0 -37
- /package/dist/{packages → core/packages}/rippleWater/src/index.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/photo.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/pointer.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/reduced-motion.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/size.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/visibility.d.ts +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ElementSize } from './size';
|
|
2
|
+
export interface CanvasBoxSizeInput {
|
|
3
|
+
/** 为 true 时跟随父容器尺寸(需父级有明确高度) */
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
defaultWidth: number;
|
|
8
|
+
defaultHeight: number;
|
|
9
|
+
measured: ElementSize;
|
|
10
|
+
}
|
|
11
|
+
export interface CanvasBoxSize {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
15
|
+
pending: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
|
|
18
|
+
export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured, }: CanvasBoxSizeInput) => CanvasBoxSize;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Component attribute → Core options parsing (v4 Element adapters).
|
|
3
|
+
* Keeps behavior consistent across 91 components.
|
|
4
|
+
*/
|
|
5
|
+
export type BooleanAttrMode =
|
|
6
|
+
/** `options.key = el.hasAttribute(attr)` — always written */
|
|
7
|
+
'presence'
|
|
8
|
+
/** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
|
|
9
|
+
| 'optional-true'
|
|
10
|
+
/** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
|
|
11
|
+
| 'optional-undefined';
|
|
12
|
+
export declare const camelToKebabAttr: (name: string) => string;
|
|
13
|
+
export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
14
|
+
export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
15
|
+
export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
|
|
16
|
+
export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
|
|
17
|
+
/** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
|
|
18
|
+
export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
|
|
19
|
+
export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Apply fill / explicit size to the adapter host and make the engine root fill it. */
|
|
2
|
+
export declare function applyCanvasHostBox(container: HTMLElement, root: HTMLElement, opts: {
|
|
3
|
+
fill: boolean;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}): void;
|
|
7
|
+
/**
|
|
8
|
+
* Size the adapter host (React/Vue div or custom element) so percentage widths
|
|
9
|
+
* don't collapse when the host is a shrink-wrapped flex child. Root fills the host
|
|
10
|
+
* unless `rootFillsHost` is false (e.g. PhotoAlbum sizes itself via CSS variables).
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyBlockHostBox(container: HTMLElement, root: HTMLElement, size: {
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
rootFillsHost?: boolean;
|
|
16
|
+
}): void;
|
|
17
|
+
/** Toggle empty-state nodes; author `display:` rules must not override `[hidden]`. */
|
|
18
|
+
export declare function setHidden(el: HTMLElement, hidden: boolean): void;
|
|
19
|
+
/** Stable JSON key for options, ignoring functions (callbacks). */
|
|
20
|
+
export declare function optionsFingerprint(value: unknown): string;
|
|
21
|
+
/** True when non-function fields differ (shallow). */
|
|
22
|
+
export declare function optionsVisualChanged(prev: Record<string, unknown>, next: Record<string, unknown>): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { clamp, lerp } from './math';
|
|
2
|
+
export { bindVisibilityPause } from './visibility';
|
|
3
|
+
export { prefersReducedMotion, bindPrefersReducedMotion } from './reduced-motion';
|
|
4
|
+
export { observeElementSize } from './size';
|
|
5
|
+
export type { ElementSize } from './size';
|
|
6
|
+
export { getRelativePointerPosition } from './pointer';
|
|
7
|
+
export type { PointerPosition } from './pointer';
|
|
8
|
+
export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from './photo';
|
|
9
|
+
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
|
+
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
|
+
export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
|
|
12
|
+
export type { BooleanAttrMode } from './element-options';
|
|
13
|
+
export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 图片预览组件通用照片项 */
|
|
2
|
+
export interface PhotoItem {
|
|
3
|
+
/** 图片地址 */
|
|
4
|
+
src: string;
|
|
5
|
+
/** 图片替代文本 */
|
|
6
|
+
alt?: string;
|
|
7
|
+
/** 照片标题 */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** 照片说明 */
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 线性浏览:当前索引变化(相册 / 胶卷 / 晾绳等) */
|
|
13
|
+
export type PhotoIndexChangeHandler<T = PhotoItem> = (index: number, photo: T) => void;
|
|
14
|
+
/** 环形浏览:正对镜头的面变化(走马灯 / 旋转木马等) */
|
|
15
|
+
export type PhotoFaceChangeHandler<T = PhotoItem> = (index: number, photo?: T) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PointerPosition {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
type PointLike = {
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
};
|
|
9
|
+
/** 相对元素左上角的指针坐标(兼容 mouse / touch / pointer) */
|
|
10
|
+
export declare const getRelativePointerPosition: (element: Element, event: PointLike | {
|
|
11
|
+
touches?: ArrayLike<PointLike>;
|
|
12
|
+
changedTouches?: ArrayLike<PointLike>;
|
|
13
|
+
}) => PointerPosition | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CSSProperties, RefObject } from 'react';
|
|
2
|
+
import { ElementSize } from '../size';
|
|
3
|
+
export type { CanvasBoxSize, CanvasBoxSizeInput } from '../canvas-box';
|
|
4
|
+
export { resolveCanvasBoxSize } from '../canvas-box';
|
|
5
|
+
export interface UseElementSizeOptions {
|
|
6
|
+
/** 为 false 时不观察 */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** 观察元素尺寸(clientWidth / clientHeight) */
|
|
10
|
+
export declare const useElementSize: <T extends Element>(ref: RefObject<T | null>, options?: UseElementSizeOptions) => ElementSize;
|
|
11
|
+
export interface UseCanvasBoxOptions {
|
|
12
|
+
/** 为 true 时铺满父容器(父级需有明确高度) */
|
|
13
|
+
fill?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
defaultWidth: number;
|
|
17
|
+
defaultHeight: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UseCanvasBoxResult {
|
|
20
|
+
hostRef: RefObject<HTMLDivElement | null>;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
/** 挂到宿主容器的样式(fill 时为 100%×100%) */
|
|
24
|
+
hostStyle: CSSProperties;
|
|
25
|
+
fill: boolean;
|
|
26
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
27
|
+
pending: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** 画布/效果宿主尺寸:fill 时跟随父容器,否则用显式宽高或默认值 */
|
|
30
|
+
export declare const useCanvasBox: ({ fill, width: widthProp, height: heightProp, defaultWidth, defaultHeight, }: UseCanvasBoxOptions) => UseCanvasBoxResult;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface RippleWaterOptions {
|
|
2
|
+
width?: number;
|
|
3
|
+
height?: number;
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
fromColor?: string;
|
|
6
|
+
toColor?: string;
|
|
7
|
+
color?: string;
|
|
8
|
+
waveAmplitude?: number;
|
|
9
|
+
waveSpeed?: number;
|
|
10
|
+
shimmer?: number;
|
|
11
|
+
reflection?: number;
|
|
12
|
+
rippleStrength?: number;
|
|
13
|
+
rippleRadius?: number;
|
|
14
|
+
damping?: number;
|
|
15
|
+
spread?: number;
|
|
16
|
+
interactive?: boolean;
|
|
17
|
+
showHint?: boolean;
|
|
18
|
+
hint?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RippleWaterController {
|
|
21
|
+
update(options: Partial<RippleWaterOptions>): void;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
}
|
|
24
|
+
export type RippleWaterProps = RippleWaterOptions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const TAG = "cos-ripple-water";
|
|
2
|
+
declare class CosRippleWaterElement extends HTMLElement {
|
|
3
|
+
private ctrl;
|
|
4
|
+
static get observedAttributes(): string[];
|
|
5
|
+
connectedCallback(): void;
|
|
6
|
+
disconnectedCallback(): void;
|
|
7
|
+
attributeChangedCallback(): void;
|
|
8
|
+
}
|
|
9
|
+
export { CosRippleWaterElement, TAG };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue';
|
|
5
|
+
const component: DefineComponent<object, object, unknown>;
|
|
6
|
+
export default component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '*.module.less' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.png' {
|
|
20
|
+
const src: string;
|
|
21
|
+
export default src;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.jpg' {
|
|
25
|
+
const src: string;
|
|
26
|
+
export default src;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.mp4' {
|
|
30
|
+
const src: string;
|
|
31
|
+
export default src;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.mp3' {
|
|
35
|
+
const src: string;
|
|
36
|
+
export default src;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.svg' {
|
|
40
|
+
import type { FC, SVGProps } from 'react';
|
|
41
|
+
|
|
42
|
+
export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
|
|
43
|
+
const src: string;
|
|
44
|
+
export default src;
|
|
45
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./react.css');let e=require("react"),t=require("@cos-design/shared"),n=require("react/jsx-runtime");var r=`cos-ripple-water`,i=800,a=500,o=192,s=`
|
|
2
|
+
attribute vec2 a_pos;
|
|
3
|
+
varying vec2 v_uv;
|
|
4
|
+
void main() {
|
|
5
|
+
v_uv = a_pos * 0.5 + 0.5;
|
|
6
|
+
gl_Position = vec4(a_pos, 0.0, 1.0);
|
|
7
|
+
}
|
|
8
|
+
`,c=`
|
|
9
|
+
precision highp float;
|
|
10
|
+
uniform float u_time;
|
|
11
|
+
uniform vec2 u_res;
|
|
12
|
+
uniform vec3 u_tint;
|
|
13
|
+
uniform vec3 u_from;
|
|
14
|
+
uniform vec3 u_to;
|
|
15
|
+
uniform sampler2D u_height;
|
|
16
|
+
uniform vec2 u_sim;
|
|
17
|
+
uniform float u_waveAmp;
|
|
18
|
+
uniform float u_waveSpeed;
|
|
19
|
+
uniform float u_shimmer;
|
|
20
|
+
uniform float u_reflection;
|
|
21
|
+
varying vec2 v_uv;
|
|
22
|
+
float hash(vec2 p) {
|
|
23
|
+
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
|
|
24
|
+
}
|
|
25
|
+
float ambientH(vec2 p, float t) {
|
|
26
|
+
float h = 0.0;
|
|
27
|
+
h += sin(p.x * 3.2 + t * 1.3) * cos(p.y * 2.4 - t * 0.9) * 0.45;
|
|
28
|
+
h += sin(p.x * 6.8 - t * 1.7 + p.y * 1.1) * 0.22;
|
|
29
|
+
h += sin(p.x * 12.0 + p.y * 9.0 + t * 2.4) * 0.08;
|
|
30
|
+
h += sin(p.x * 1.4 + p.y * 1.8 + t * 0.55) * 0.35;
|
|
31
|
+
return h;
|
|
32
|
+
}
|
|
33
|
+
float sampleHeight(vec2 uv) {
|
|
34
|
+
float rip = texture2D(u_height, uv).r * 2.0 - 1.0;
|
|
35
|
+
vec2 p = uv * vec2(u_res.x / u_res.y, 1.0) * 2.8;
|
|
36
|
+
float amb = ambientH(p, u_time * u_waveSpeed) * 0.035 * u_waveAmp;
|
|
37
|
+
return rip * 0.55 + amb;
|
|
38
|
+
}
|
|
39
|
+
vec3 calcNormal(vec2 uv) {
|
|
40
|
+
vec2 e = vec2(1.5 / u_sim.x, 1.5 / u_sim.y);
|
|
41
|
+
float hL = sampleHeight(uv - vec2(e.x, 0.0));
|
|
42
|
+
float hR = sampleHeight(uv + vec2(e.x, 0.0));
|
|
43
|
+
float hD = sampleHeight(uv - vec2(0.0, e.y));
|
|
44
|
+
float hU = sampleHeight(uv + vec2(0.0, e.y));
|
|
45
|
+
return normalize(vec3((hL - hR) * 14.0, (hD - hU) * 14.0, 1.0));
|
|
46
|
+
}
|
|
47
|
+
void main() {
|
|
48
|
+
vec2 uv = v_uv;
|
|
49
|
+
vec3 n = calcNormal(uv);
|
|
50
|
+
float h = sampleHeight(uv);
|
|
51
|
+
vec3 V = normalize(vec3(0.0, 0.25, 1.0));
|
|
52
|
+
vec3 L = normalize(vec3(0.45, 0.75, 0.55));
|
|
53
|
+
float ndotl = max(dot(n, L), 0.0);
|
|
54
|
+
float fresnel = pow(1.0 - max(dot(n, V), 0.0), 3.2);
|
|
55
|
+
float g = clamp((uv.x + (1.0 - uv.y)) * 0.5, 0.0, 1.0);
|
|
56
|
+
vec3 water = mix(u_from, u_to, g);
|
|
57
|
+
water = mix(water, u_from, clamp(h * 1.8 + ndotl * 0.12, 0.0, 0.28));
|
|
58
|
+
water *= 0.92 + n.y * 0.1;
|
|
59
|
+
vec3 sky = mix(u_from * 1.15, vec3(0.85, 0.92, 1.0), 0.45);
|
|
60
|
+
vec3 reflectCol = mix(sky, vec3(0.9, 0.95, 1.0), pow(max(n.y, 0.0), 2.0));
|
|
61
|
+
water = mix(water, reflectCol, fresnel * u_reflection);
|
|
62
|
+
vec3 H = normalize(L + V);
|
|
63
|
+
float spec = pow(max(dot(n, H), 0.0), 180.0);
|
|
64
|
+
float glitter = pow(max(dot(n, H), 0.0), 48.0);
|
|
65
|
+
float sparkThresh = step(0.992, glitter) * glitter;
|
|
66
|
+
vec3 sparkle = u_tint * (spec * 1.8 + sparkThresh * 2.5) * u_shimmer + vec3(1.0) * sparkThresh * 0.8 * u_shimmer;
|
|
67
|
+
float softSpec = pow(max(dot(n, H), 0.0), 16.0) * 0.22 * u_shimmer;
|
|
68
|
+
water += u_tint * softSpec + sparkle;
|
|
69
|
+
float crest = smoothstep(0.02, 0.12, abs(h)) * fresnel;
|
|
70
|
+
water += mix(u_tint, vec3(1.0), 0.4) * crest * 0.35;
|
|
71
|
+
float vig = smoothstep(1.15, 0.35, length((uv - 0.5) * vec2(1.1, 1.0)));
|
|
72
|
+
water *= 0.88 + 0.12 * vig;
|
|
73
|
+
water += (hash(uv * u_res + u_time) - 0.5) * 0.015;
|
|
74
|
+
gl_FragColor = vec4(water, 1.0);
|
|
75
|
+
}
|
|
76
|
+
`,l=e=>{let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=Number.parseInt(n,16);return Number.isNaN(r)?[.22,.74,.97]:[(r>>16&255)/255,(r>>8&255)/255,(r&255)/255]},u=(e,t,n)=>{let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null},d=(e,t,n)=>{let r=u(e,e.VERTEX_SHADER,t),i=u(e,e.FRAGMENT_SHADER,n);if(!r||!i)return null;let a=e.createProgram();return a?(e.attachShader(a,r),e.attachShader(a,i),e.linkProgram(a),e.deleteShader(r),e.deleteShader(i),e.getProgramParameter(a,e.LINK_STATUS)?a:(e.deleteProgram(a),null)):null};function f(e,n={}){let u={fill:!1,fromColor:`#52ade3`,toColor:`#013565`,color:`#a8d8f5`,waveAmplitude:1,waveSpeed:1,shimmer:1,reflection:.38,rippleStrength:1,rippleRadius:6,damping:.985,spread:.5,interactive:!0,showHint:!0,hint:`点击水面产生涟漪`,...n},f=!1,p=u.width??i,m=u.height??a,h=typeof document<`u`?document.hidden:!1,g=(0,t.prefersReducedMotion)(),_=null,v=null,y=null,b=null,x=null,S=document.createElement(`div`);S.className=r;let C=document.createElement(`canvas`);C.className=`${r}__canvas`,C.setAttribute(`role`,`img`);let w=document.createElement(`span`);w.className=`${r}__hint`,w.setAttribute(`aria-hidden`,`true`),S.append(C,w),e.appendChild(S);let T=()=>{let e=u.showHint??!0,t=u.hint??`点击水面产生涟漪`;w.textContent=t,w.hidden=!e,C.style.cursor=u.interactive??!0?`pointer`:`default`,C.setAttribute(`aria-label`,t||`涟漪水面`)},E=()=>{(0,t.applyCanvasHostBox)(e,S,{fill:!!u.fill,width:p,height:m}),C.style.width=`${p}px`,C.style.height=`${m}px`,T()},D=e=>{if(!(u.interactive??!0)||e.pointerType===`mouse`&&e.button!==0)return;let t=C.getBoundingClientRect();x={x:(e.clientX-t.left)/t.width,y:1-(e.clientY-t.top)/t.height,strength:u.rippleStrength??1}},O={w:0,h:0},k=()=>{if(O.w===p&&O.h===m&&b)return;O={w:p,h:m},b?.(),b=null;let e=Math.min(window.devicePixelRatio||1,2);C.width=Math.floor(p*e),C.height=Math.floor(m*e);let n=C.getContext(`webgl`,{alpha:!1,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!1});if(!n)return;let r=d(n,s,c);if(!r)return;let i=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,i),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let a=n.getAttribLocation(r,`a_pos`),_=n.getUniformLocation(r,`u_time`),v=n.getUniformLocation(r,`u_res`),y=n.getUniformLocation(r,`u_tint`),S=n.getUniformLocation(r,`u_from`),w=n.getUniformLocation(r,`u_to`),T=n.getUniformLocation(r,`u_height`),E=n.getUniformLocation(r,`u_sim`),D=n.getUniformLocation(r,`u_waveAmp`),k=n.getUniformLocation(r,`u_waveSpeed`),A=n.getUniformLocation(r,`u_shimmer`),j=n.getUniformLocation(r,`u_reflection`),M=o*o,N=new Float32Array(M),P=new Float32Array(M),F=new Float32Array(M),I=n.createTexture();n.bindTexture(n.TEXTURE_2D,I),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE);let L=new Uint8Array(M*4),R=()=>{for(let e=0;e<M;e++){let t=Math.max(0,Math.min(255,Math.floor((P[e]*.5+.5)*255))),n=e*4;L[n]=t,L[n+1]=t,L[n+2]=t,L[n+3]=255}n.bindTexture(n.TEXTURE_2D,I),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,o,o,0,n.RGBA,n.UNSIGNED_BYTE,L)},z=(e,n,r,i)=>{let a=e*(o-1),s=n*(o-1),c=(0,t.clamp)(i,2,12);for(let e=-c-1;e<=c+1;e++)for(let t=-c-1;t<=c+1;t++){let n=Math.round(a+t),i=Math.round(s+e);if(n<=0||n>=o-1||i<=0||i>=o-1)continue;let l=Math.sqrt(t*t+e*e),u=Math.exp(-l*l*.55)*-.35,d=Math.exp(-((l-c*.55)**2)*.9);P[i*o+n]+=r*(u+d*1.1)}},B=(e,n)=>{let r=(0,t.clamp)(e,.9,.999),i=(0,t.clamp)(n,.3,.7);for(let e=0;e<2;e++){for(let e=1;e<o-1;e++){let t=e*o;for(let e=1;e<o-1;e++){let n=t+e,a=P[n-1]+P[n+1]+P[n-o]+P[n+o];F[n]=(a*i-N[n])*r,F[n]>1.5?F[n]=1.5:F[n]<-1.5&&(F[n]=-1.5)}}let e=N;N=P,P=F,F=e,F.fill(0)}},V=e=>{let s=l(u.fromColor??`#52ade3`),c=l(u.toColor??`#013565`),d=l(u.color??`#a8d8f5`);n.viewport(0,0,C.width,C.height),n.useProgram(r),n.bindBuffer(n.ARRAY_BUFFER,i),n.enableVertexAttribArray(a),n.vertexAttribPointer(a,2,n.FLOAT,!1,0,0),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,I),n.uniform1i(T,0),n.uniform1f(_,e),n.uniform2f(v,C.width,C.height),n.uniform3f(y,d[0],d[1],d[2]),n.uniform3f(S,s[0],s[1],s[2]),n.uniform3f(w,c[0],c[1],c[2]),n.uniform2f(E,o,o),n.uniform1f(D,(0,t.clamp)(u.waveAmplitude??1,0,2)),n.uniform1f(k,(0,t.clamp)(u.waveSpeed??1,0,3)),n.uniform1f(A,(0,t.clamp)(u.shimmer??1,0,2)),n.uniform1f(j,(0,t.clamp)(u.reflection??.38,0,1)),n.drawArrays(n.TRIANGLE_STRIP,0,4)};if(R(),g){V(0),b=()=>{n.deleteTexture(I),n.deleteBuffer(i),n.deleteProgram(r)};return}let H=performance.now(),U=0,W=e=>{if(!f&&(U=requestAnimationFrame(W),!(h||g))){if(x){let e=x,n=(0,t.clamp)(e.strength,0,3),r=u.rippleRadius??6;z(e.x,e.y,n,r),z(e.x+.004,e.y-.003,n*.35,r),x=null}B(u.damping??.985,u.spread??.5),R(),V((e-H)/1e3)}};U=requestAnimationFrame(W),b=()=>{cancelAnimationFrame(U),n.deleteTexture(I),n.deleteBuffer(i),n.deleteProgram(r)}},A=()=>{if(_?.(),_=null,!(u.fill??!1)){p=u.width??i,m=u.height??a,E(),k();return}_=(0,t.observeElementSize)(e,e=>{let n=(0,t.resolveCanvasBoxSize)({fill:!0,width:u.width,height:u.height,defaultWidth:i,defaultHeight:a,measured:e});p=n.width,m=n.height,E(),k()})};return C.addEventListener(`pointerdown`,D),v=(0,t.bindVisibilityPause)(e=>{h=e}),y=(0,t.bindPrefersReducedMotion)(e=>{g=e}),A(),{update(e){let t=u.fill,n=u.width,r=u.height;u={...u,...e},T(),(u.fill!==t||u.width!==n||u.height!==r)&&A()},destroy(){f||(f=!0,b?.(),v?.(),y?.(),_?.(),C.removeEventListener(`pointerdown`,D),S.remove())}}}var p=(0,e.forwardRef)((r,i)=>{let a=(0,e.useRef)(null),o=(0,e.useRef)(null),s=(0,e.useRef)(r);s.current=r;let c=(0,e.useMemo)(()=>(0,t.optionsFingerprint)(r),[r]);return(0,e.useImperativeHandle)(i,()=>({})),(0,e.useEffect)(()=>{let e=a.current;if(!e)return;let t=f(e,s.current);return o.current=t,()=>{t.destroy(),o.current=null}},[]),(0,e.useEffect)(()=>{o.current?.update(s.current)},[c]),(0,n.jsx)(`div`,{ref:a,className:`cos-rippleWater-host`})});p.displayName=`RippleWater`,exports.RippleWater=p,exports.default=p;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { forwardRef as e, useEffect as t, useImperativeHandle as n, useMemo as r, useRef as i } from "react";
|
|
2
|
+
import { applyCanvasHostBox as a, bindPrefersReducedMotion as o, bindVisibilityPause as s, clamp as c, observeElementSize as l, optionsFingerprint as u, prefersReducedMotion as d, resolveCanvasBoxSize as f } from "@cos-design/shared";
|
|
3
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
4
|
+
import './react.css';//#region src/components/rippleWater/core/engine.ts
|
|
5
|
+
var m = "cos-ripple-water", h = 800, g = 500, _ = 192, v = "\nattribute vec2 a_pos;\nvarying vec2 v_uv;\nvoid main() {\n v_uv = a_pos * 0.5 + 0.5;\n gl_Position = vec4(a_pos, 0.0, 1.0);\n}\n", y = "\nprecision highp float;\nuniform float u_time;\nuniform vec2 u_res;\nuniform vec3 u_tint;\nuniform vec3 u_from;\nuniform vec3 u_to;\nuniform sampler2D u_height;\nuniform vec2 u_sim;\nuniform float u_waveAmp;\nuniform float u_waveSpeed;\nuniform float u_shimmer;\nuniform float u_reflection;\nvarying vec2 v_uv;\nfloat hash(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);\n}\nfloat ambientH(vec2 p, float t) {\n float h = 0.0;\n h += sin(p.x * 3.2 + t * 1.3) * cos(p.y * 2.4 - t * 0.9) * 0.45;\n h += sin(p.x * 6.8 - t * 1.7 + p.y * 1.1) * 0.22;\n h += sin(p.x * 12.0 + p.y * 9.0 + t * 2.4) * 0.08;\n h += sin(p.x * 1.4 + p.y * 1.8 + t * 0.55) * 0.35;\n return h;\n}\nfloat sampleHeight(vec2 uv) {\n float rip = texture2D(u_height, uv).r * 2.0 - 1.0;\n vec2 p = uv * vec2(u_res.x / u_res.y, 1.0) * 2.8;\n float amb = ambientH(p, u_time * u_waveSpeed) * 0.035 * u_waveAmp;\n return rip * 0.55 + amb;\n}\nvec3 calcNormal(vec2 uv) {\n vec2 e = vec2(1.5 / u_sim.x, 1.5 / u_sim.y);\n float hL = sampleHeight(uv - vec2(e.x, 0.0));\n float hR = sampleHeight(uv + vec2(e.x, 0.0));\n float hD = sampleHeight(uv - vec2(0.0, e.y));\n float hU = sampleHeight(uv + vec2(0.0, e.y));\n return normalize(vec3((hL - hR) * 14.0, (hD - hU) * 14.0, 1.0));\n}\nvoid main() {\n vec2 uv = v_uv;\n vec3 n = calcNormal(uv);\n float h = sampleHeight(uv);\n vec3 V = normalize(vec3(0.0, 0.25, 1.0));\n vec3 L = normalize(vec3(0.45, 0.75, 0.55));\n float ndotl = max(dot(n, L), 0.0);\n float fresnel = pow(1.0 - max(dot(n, V), 0.0), 3.2);\n float g = clamp((uv.x + (1.0 - uv.y)) * 0.5, 0.0, 1.0);\n vec3 water = mix(u_from, u_to, g);\n water = mix(water, u_from, clamp(h * 1.8 + ndotl * 0.12, 0.0, 0.28));\n water *= 0.92 + n.y * 0.1;\n vec3 sky = mix(u_from * 1.15, vec3(0.85, 0.92, 1.0), 0.45);\n vec3 reflectCol = mix(sky, vec3(0.9, 0.95, 1.0), pow(max(n.y, 0.0), 2.0));\n water = mix(water, reflectCol, fresnel * u_reflection);\n vec3 H = normalize(L + V);\n float spec = pow(max(dot(n, H), 0.0), 180.0);\n float glitter = pow(max(dot(n, H), 0.0), 48.0);\n float sparkThresh = step(0.992, glitter) * glitter;\n vec3 sparkle = u_tint * (spec * 1.8 + sparkThresh * 2.5) * u_shimmer + vec3(1.0) * sparkThresh * 0.8 * u_shimmer;\n float softSpec = pow(max(dot(n, H), 0.0), 16.0) * 0.22 * u_shimmer;\n water += u_tint * softSpec + sparkle;\n float crest = smoothstep(0.02, 0.12, abs(h)) * fresnel;\n water += mix(u_tint, vec3(1.0), 0.4) * crest * 0.35;\n float vig = smoothstep(1.15, 0.35, length((uv - 0.5) * vec2(1.1, 1.0)));\n water *= 0.88 + 0.12 * vig;\n water += (hash(uv * u_res + u_time) - 0.5) * 0.015;\n gl_FragColor = vec4(water, 1.0);\n}\n", b = (e) => {
|
|
6
|
+
let t = e.replace("#", ""), n = t.length === 3 ? t.split("").map((e) => e + e).join("") : t, r = Number.parseInt(n, 16);
|
|
7
|
+
return Number.isNaN(r) ? [
|
|
8
|
+
.22,
|
|
9
|
+
.74,
|
|
10
|
+
.97
|
|
11
|
+
] : [
|
|
12
|
+
(r >> 16 & 255) / 255,
|
|
13
|
+
(r >> 8 & 255) / 255,
|
|
14
|
+
(r & 255) / 255
|
|
15
|
+
];
|
|
16
|
+
}, x = (e, t, n) => {
|
|
17
|
+
let r = e.createShader(t);
|
|
18
|
+
return r ? (e.shaderSource(r, n), e.compileShader(r), e.getShaderParameter(r, e.COMPILE_STATUS) ? r : (e.deleteShader(r), null)) : null;
|
|
19
|
+
}, S = (e, t, n) => {
|
|
20
|
+
let r = x(e, e.VERTEX_SHADER, t), i = x(e, e.FRAGMENT_SHADER, n);
|
|
21
|
+
if (!r || !i) return null;
|
|
22
|
+
let a = e.createProgram();
|
|
23
|
+
return a ? (e.attachShader(a, r), e.attachShader(a, i), e.linkProgram(a), e.deleteShader(r), e.deleteShader(i), e.getProgramParameter(a, e.LINK_STATUS) ? a : (e.deleteProgram(a), null)) : null;
|
|
24
|
+
};
|
|
25
|
+
function C(e, t = {}) {
|
|
26
|
+
let n = {
|
|
27
|
+
fill: !1,
|
|
28
|
+
fromColor: "#52ade3",
|
|
29
|
+
toColor: "#013565",
|
|
30
|
+
color: "#a8d8f5",
|
|
31
|
+
waveAmplitude: 1,
|
|
32
|
+
waveSpeed: 1,
|
|
33
|
+
shimmer: 1,
|
|
34
|
+
reflection: .38,
|
|
35
|
+
rippleStrength: 1,
|
|
36
|
+
rippleRadius: 6,
|
|
37
|
+
damping: .985,
|
|
38
|
+
spread: .5,
|
|
39
|
+
interactive: !0,
|
|
40
|
+
showHint: !0,
|
|
41
|
+
hint: "点击水面产生涟漪",
|
|
42
|
+
...t
|
|
43
|
+
}, r = !1, i = n.width ?? h, u = n.height ?? g, p = typeof document < "u" ? document.hidden : !1, x = d(), C = null, w = null, T = null, E = null, D = null, O = document.createElement("div");
|
|
44
|
+
O.className = m;
|
|
45
|
+
let k = document.createElement("canvas");
|
|
46
|
+
k.className = `${m}__canvas`, k.setAttribute("role", "img");
|
|
47
|
+
let A = document.createElement("span");
|
|
48
|
+
A.className = `${m}__hint`, A.setAttribute("aria-hidden", "true"), O.append(k, A), e.appendChild(O);
|
|
49
|
+
let j = () => {
|
|
50
|
+
let e = n.showHint ?? !0, t = n.hint ?? "点击水面产生涟漪";
|
|
51
|
+
A.textContent = t, A.hidden = !e, k.style.cursor = n.interactive ?? !0 ? "pointer" : "default", k.setAttribute("aria-label", t || "涟漪水面");
|
|
52
|
+
}, M = () => {
|
|
53
|
+
a(e, O, {
|
|
54
|
+
fill: !!n.fill,
|
|
55
|
+
width: i,
|
|
56
|
+
height: u
|
|
57
|
+
}), k.style.width = `${i}px`, k.style.height = `${u}px`, j();
|
|
58
|
+
}, N = (e) => {
|
|
59
|
+
if (!(n.interactive ?? !0) || e.pointerType === "mouse" && e.button !== 0) return;
|
|
60
|
+
let t = k.getBoundingClientRect();
|
|
61
|
+
D = {
|
|
62
|
+
x: (e.clientX - t.left) / t.width,
|
|
63
|
+
y: 1 - (e.clientY - t.top) / t.height,
|
|
64
|
+
strength: n.rippleStrength ?? 1
|
|
65
|
+
};
|
|
66
|
+
}, P = {
|
|
67
|
+
w: 0,
|
|
68
|
+
h: 0
|
|
69
|
+
}, F = () => {
|
|
70
|
+
if (P.w === i && P.h === u && E) return;
|
|
71
|
+
P = {
|
|
72
|
+
w: i,
|
|
73
|
+
h: u
|
|
74
|
+
}, E?.(), E = null;
|
|
75
|
+
let e = Math.min(window.devicePixelRatio || 1, 2);
|
|
76
|
+
k.width = Math.floor(i * e), k.height = Math.floor(u * e);
|
|
77
|
+
let t = k.getContext("webgl", {
|
|
78
|
+
alpha: !1,
|
|
79
|
+
antialias: !1,
|
|
80
|
+
depth: !1,
|
|
81
|
+
stencil: !1,
|
|
82
|
+
premultipliedAlpha: !1
|
|
83
|
+
});
|
|
84
|
+
if (!t) return;
|
|
85
|
+
let a = S(t, v, y);
|
|
86
|
+
if (!a) return;
|
|
87
|
+
let o = t.createBuffer();
|
|
88
|
+
t.bindBuffer(t.ARRAY_BUFFER, o), t.bufferData(t.ARRAY_BUFFER, new Float32Array([
|
|
89
|
+
-1,
|
|
90
|
+
-1,
|
|
91
|
+
1,
|
|
92
|
+
-1,
|
|
93
|
+
-1,
|
|
94
|
+
1,
|
|
95
|
+
1,
|
|
96
|
+
1
|
|
97
|
+
]), t.STATIC_DRAW);
|
|
98
|
+
let s = t.getAttribLocation(a, "a_pos"), l = t.getUniformLocation(a, "u_time"), d = t.getUniformLocation(a, "u_res"), f = t.getUniformLocation(a, "u_tint"), m = t.getUniformLocation(a, "u_from"), h = t.getUniformLocation(a, "u_to"), g = t.getUniformLocation(a, "u_height"), C = t.getUniformLocation(a, "u_sim"), w = t.getUniformLocation(a, "u_waveAmp"), T = t.getUniformLocation(a, "u_waveSpeed"), O = t.getUniformLocation(a, "u_shimmer"), A = t.getUniformLocation(a, "u_reflection"), j = _ * _, M = new Float32Array(j), N = new Float32Array(j), F = new Float32Array(j), I = t.createTexture();
|
|
99
|
+
t.bindTexture(t.TEXTURE_2D, I), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.LINEAR), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.LINEAR), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE);
|
|
100
|
+
let L = new Uint8Array(j * 4), R = () => {
|
|
101
|
+
for (let e = 0; e < j; e++) {
|
|
102
|
+
let t = Math.max(0, Math.min(255, Math.floor((N[e] * .5 + .5) * 255))), n = e * 4;
|
|
103
|
+
L[n] = t, L[n + 1] = t, L[n + 2] = t, L[n + 3] = 255;
|
|
104
|
+
}
|
|
105
|
+
t.bindTexture(t.TEXTURE_2D, I), t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, _, _, 0, t.RGBA, t.UNSIGNED_BYTE, L);
|
|
106
|
+
}, z = (e, t, n, r) => {
|
|
107
|
+
let i = e * (_ - 1), a = t * (_ - 1), o = c(r, 2, 12);
|
|
108
|
+
for (let e = -o - 1; e <= o + 1; e++) for (let t = -o - 1; t <= o + 1; t++) {
|
|
109
|
+
let r = Math.round(i + t), s = Math.round(a + e);
|
|
110
|
+
if (r <= 0 || r >= _ - 1 || s <= 0 || s >= _ - 1) continue;
|
|
111
|
+
let c = Math.sqrt(t * t + e * e), l = Math.exp(-c * c * .55) * -.35, u = Math.exp(-((c - o * .55) ** 2) * .9);
|
|
112
|
+
N[s * _ + r] += n * (l + u * 1.1);
|
|
113
|
+
}
|
|
114
|
+
}, B = (e, t) => {
|
|
115
|
+
let n = c(e, .9, .999), r = c(t, .3, .7);
|
|
116
|
+
for (let e = 0; e < 2; e++) {
|
|
117
|
+
for (let e = 1; e < _ - 1; e++) {
|
|
118
|
+
let t = e * _;
|
|
119
|
+
for (let e = 1; e < _ - 1; e++) {
|
|
120
|
+
let i = t + e, a = N[i - 1] + N[i + 1] + N[i - _] + N[i + _];
|
|
121
|
+
F[i] = (a * r - M[i]) * n, F[i] > 1.5 ? F[i] = 1.5 : F[i] < -1.5 && (F[i] = -1.5);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let e = M;
|
|
125
|
+
M = N, N = F, F = e, F.fill(0);
|
|
126
|
+
}
|
|
127
|
+
}, V = (e) => {
|
|
128
|
+
let r = b(n.fromColor ?? "#52ade3"), i = b(n.toColor ?? "#013565"), u = b(n.color ?? "#a8d8f5");
|
|
129
|
+
t.viewport(0, 0, k.width, k.height), t.useProgram(a), t.bindBuffer(t.ARRAY_BUFFER, o), t.enableVertexAttribArray(s), t.vertexAttribPointer(s, 2, t.FLOAT, !1, 0, 0), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, I), t.uniform1i(g, 0), t.uniform1f(l, e), t.uniform2f(d, k.width, k.height), t.uniform3f(f, u[0], u[1], u[2]), t.uniform3f(m, r[0], r[1], r[2]), t.uniform3f(h, i[0], i[1], i[2]), t.uniform2f(C, _, _), t.uniform1f(w, c(n.waveAmplitude ?? 1, 0, 2)), t.uniform1f(T, c(n.waveSpeed ?? 1, 0, 3)), t.uniform1f(O, c(n.shimmer ?? 1, 0, 2)), t.uniform1f(A, c(n.reflection ?? .38, 0, 1)), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
|
|
130
|
+
};
|
|
131
|
+
if (R(), x) {
|
|
132
|
+
V(0), E = () => {
|
|
133
|
+
t.deleteTexture(I), t.deleteBuffer(o), t.deleteProgram(a);
|
|
134
|
+
};
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let H = performance.now(), U = 0, W = (e) => {
|
|
138
|
+
if (!r && (U = requestAnimationFrame(W), !(p || x))) {
|
|
139
|
+
if (D) {
|
|
140
|
+
let e = D, t = c(e.strength, 0, 3), r = n.rippleRadius ?? 6;
|
|
141
|
+
z(e.x, e.y, t, r), z(e.x + .004, e.y - .003, t * .35, r), D = null;
|
|
142
|
+
}
|
|
143
|
+
B(n.damping ?? .985, n.spread ?? .5), R(), V((e - H) / 1e3);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
U = requestAnimationFrame(W), E = () => {
|
|
147
|
+
cancelAnimationFrame(U), t.deleteTexture(I), t.deleteBuffer(o), t.deleteProgram(a);
|
|
148
|
+
};
|
|
149
|
+
}, I = () => {
|
|
150
|
+
if (C?.(), C = null, !(n.fill ?? !1)) {
|
|
151
|
+
i = n.width ?? h, u = n.height ?? g, M(), F();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
C = l(e, (e) => {
|
|
155
|
+
let t = f({
|
|
156
|
+
fill: !0,
|
|
157
|
+
width: n.width,
|
|
158
|
+
height: n.height,
|
|
159
|
+
defaultWidth: h,
|
|
160
|
+
defaultHeight: g,
|
|
161
|
+
measured: e
|
|
162
|
+
});
|
|
163
|
+
i = t.width, u = t.height, M(), F();
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
return k.addEventListener("pointerdown", N), w = s((e) => {
|
|
167
|
+
p = e;
|
|
168
|
+
}), T = o((e) => {
|
|
169
|
+
x = e;
|
|
170
|
+
}), I(), {
|
|
171
|
+
update(e) {
|
|
172
|
+
let t = n.fill, r = n.width, i = n.height;
|
|
173
|
+
n = {
|
|
174
|
+
...n,
|
|
175
|
+
...e
|
|
176
|
+
}, j(), (n.fill !== t || n.width !== r || n.height !== i) && I();
|
|
177
|
+
},
|
|
178
|
+
destroy() {
|
|
179
|
+
r || (r = !0, E?.(), w?.(), T?.(), C?.(), k.removeEventListener("pointerdown", N), O.remove());
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/components/rippleWater/react/index.tsx
|
|
185
|
+
var w = e((e, a) => {
|
|
186
|
+
let o = i(null), s = i(null), c = i(e);
|
|
187
|
+
c.current = e;
|
|
188
|
+
let l = r(() => u(e), [e]);
|
|
189
|
+
return n(a, () => ({})), t(() => {
|
|
190
|
+
let e = o.current;
|
|
191
|
+
if (!e) return;
|
|
192
|
+
let t = C(e, c.current);
|
|
193
|
+
return s.current = t, () => {
|
|
194
|
+
t.destroy(), s.current = null;
|
|
195
|
+
};
|
|
196
|
+
}, []), t(() => {
|
|
197
|
+
s.current?.update(c.current);
|
|
198
|
+
}, [l]), /* @__PURE__ */ p("div", {
|
|
199
|
+
ref: o,
|
|
200
|
+
className: "cos-rippleWater-host"
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
w.displayName = "RippleWater";
|
|
204
|
+
//#endregion
|
|
205
|
+
export { w as RippleWater, w as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/rippleWater/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/rippleWater/element';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ElementSize } from './size';
|
|
2
|
+
export interface CanvasBoxSizeInput {
|
|
3
|
+
/** 为 true 时跟随父容器尺寸(需父级有明确高度) */
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
defaultWidth: number;
|
|
8
|
+
defaultHeight: number;
|
|
9
|
+
measured: ElementSize;
|
|
10
|
+
}
|
|
11
|
+
export interface CanvasBoxSize {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
15
|
+
pending: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
|
|
18
|
+
export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured, }: CanvasBoxSizeInput) => CanvasBoxSize;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Component attribute → Core options parsing (v4 Element adapters).
|
|
3
|
+
* Keeps behavior consistent across 91 components.
|
|
4
|
+
*/
|
|
5
|
+
export type BooleanAttrMode =
|
|
6
|
+
/** `options.key = el.hasAttribute(attr)` — always written */
|
|
7
|
+
'presence'
|
|
8
|
+
/** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
|
|
9
|
+
| 'optional-true'
|
|
10
|
+
/** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
|
|
11
|
+
| 'optional-undefined';
|
|
12
|
+
export declare const camelToKebabAttr: (name: string) => string;
|
|
13
|
+
export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
14
|
+
export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
15
|
+
export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
|
|
16
|
+
export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
|
|
17
|
+
/** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
|
|
18
|
+
export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
|
|
19
|
+
export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
|