@rippleflow/water-distortion 0.1.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/LICENSE +21 -0
- package/README.md +202 -0
- package/dist/WaterDistortion.d.ts +56 -0
- package/dist/WaterDistortion.d.ts.map +1 -0
- package/dist/core/math.d.ts +10 -0
- package/dist/core/math.d.ts.map +1 -0
- package/dist/core/trailEngine.d.ts +46 -0
- package/dist/core/trailEngine.d.ts.map +1 -0
- package/dist/core/waterInteraction.d.ts +58 -0
- package/dist/core/waterInteraction.d.ts.map +1 -0
- package/dist/core/waterRenderer.d.ts +66 -0
- package/dist/core/waterRenderer.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/water-distortion.cjs +251 -0
- package/dist/water-distortion.cjs.map +1 -0
- package/dist/water-distortion.js +1240 -0
- package/dist/water-distortion.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
var Ye = Object.defineProperty;
|
|
2
|
+
var Ve = (r, e, t) => e in r ? Ye(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var f = (r, e, t) => Ve(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { jsxs as qe, jsx as de } from "react/jsx-runtime";
|
|
5
|
+
import { forwardRef as $e, useRef as y, useImperativeHandle as Qe, useEffect as V, useState as je } from "react";
|
|
6
|
+
function h(r, e, t) {
|
|
7
|
+
return Math.min(t, Math.max(e, r));
|
|
8
|
+
}
|
|
9
|
+
function Ze(r, e) {
|
|
10
|
+
return Math.hypot(e.x - r.x, e.y - r.y);
|
|
11
|
+
}
|
|
12
|
+
function O(r, e, t) {
|
|
13
|
+
return r + (e - r) * t;
|
|
14
|
+
}
|
|
15
|
+
const J = 24, C = 128, oe = 8, se = Math.PI * 2, fe = {
|
|
16
|
+
causticGain: 0.1,
|
|
17
|
+
screenCompensation: 1.35,
|
|
18
|
+
maxAlpha: 0.9
|
|
19
|
+
}, Je = {
|
|
20
|
+
gradient: 8e-4,
|
|
21
|
+
curvature: 8e-4,
|
|
22
|
+
trough: 6e-3,
|
|
23
|
+
velocity: 8e-4
|
|
24
|
+
}, Ae = `
|
|
25
|
+
attribute vec2 a_position;
|
|
26
|
+
varying vec2 v_uv;
|
|
27
|
+
|
|
28
|
+
void main() {
|
|
29
|
+
v_uv = a_position * 0.5 + 0.5;
|
|
30
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
31
|
+
}
|
|
32
|
+
`, et = `
|
|
33
|
+
precision highp float;
|
|
34
|
+
|
|
35
|
+
#define MAX_WAKE_SEGMENTS ${J}
|
|
36
|
+
|
|
37
|
+
varying vec2 v_uv;
|
|
38
|
+
|
|
39
|
+
uniform sampler2D u_state;
|
|
40
|
+
uniform vec2 u_texel;
|
|
41
|
+
uniform float u_delta;
|
|
42
|
+
uniform float u_damping;
|
|
43
|
+
uniform float u_stiffness;
|
|
44
|
+
uniform float u_aspect;
|
|
45
|
+
uniform int u_wakeCount;
|
|
46
|
+
uniform vec4 u_wakeA[MAX_WAKE_SEGMENTS];
|
|
47
|
+
uniform vec4 u_wakeB[MAX_WAKE_SEGMENTS];
|
|
48
|
+
uniform vec4 u_wakeShape[MAX_WAKE_SEGMENTS];
|
|
49
|
+
|
|
50
|
+
float segmentWake(vec2 uv, vec4 wakeA, vec4 wakeB, vec4 shape) {
|
|
51
|
+
vec2 a = wakeA.xy;
|
|
52
|
+
vec2 b = wakeB.xy;
|
|
53
|
+
vec2 scale = vec2(u_aspect, 1.0);
|
|
54
|
+
vec2 p = uv * scale;
|
|
55
|
+
vec2 start = a * scale;
|
|
56
|
+
vec2 end = b * scale;
|
|
57
|
+
vec2 segment = end - start;
|
|
58
|
+
float segmentLength = max(length(segment), 0.000001);
|
|
59
|
+
vec2 dir = segment / segmentLength;
|
|
60
|
+
vec2 normal = vec2(-dir.y, dir.x);
|
|
61
|
+
float longitudinal = dot(p - start, dir);
|
|
62
|
+
float clampedLongitudinal = clamp(longitudinal, 0.0, segmentLength);
|
|
63
|
+
vec2 closest = start + dir * clampedLongitudinal;
|
|
64
|
+
vec2 delta = p - closest;
|
|
65
|
+
float perpendicular = abs(dot(delta, normal));
|
|
66
|
+
float safeRadius = max(wakeA.z, 0.00001);
|
|
67
|
+
float wakeStrength = wakeA.w;
|
|
68
|
+
float wakeLength = max(wakeB.z, safeRadius);
|
|
69
|
+
float troughStrength = shape.x;
|
|
70
|
+
float ridgeStrength = shape.y;
|
|
71
|
+
float ridgeOffset = max(shape.z, safeRadius * 0.35);
|
|
72
|
+
float minFeatureWidth = u_texel.y * 2.25;
|
|
73
|
+
float troughWidth = max(safeRadius * 0.82, minFeatureWidth);
|
|
74
|
+
float ridgeWidth = max(safeRadius * 0.9, minFeatureWidth);
|
|
75
|
+
float signedFromHead = dot(p - end, dir);
|
|
76
|
+
float behindDistance = max(-signedFromHead, 0.0);
|
|
77
|
+
float aheadDistance = max(signedFromHead, 0.0);
|
|
78
|
+
float frontMask = 1.0 - smoothstep(safeRadius * 0.35, safeRadius * 1.8, aheadDistance);
|
|
79
|
+
float trailMask = 1.0 - smoothstep(safeRadius * 0.5, wakeLength, behindDistance);
|
|
80
|
+
float segmentMask =
|
|
81
|
+
smoothstep(-safeRadius, safeRadius * 0.35, longitudinal) *
|
|
82
|
+
(1.0 - smoothstep(segmentLength + wakeLength * 0.18, segmentLength + wakeLength, longitudinal));
|
|
83
|
+
float pressureMask = frontMask * segmentMask;
|
|
84
|
+
float centerTrough = exp(-pow(perpendicular / troughWidth, 2.0));
|
|
85
|
+
float sideFade = 1.0 - smoothstep(safeRadius * 0.9, safeRadius * 2.35, perpendicular);
|
|
86
|
+
float sideRidges =
|
|
87
|
+
exp(-pow((perpendicular - ridgeOffset) / ridgeWidth, 2.0)) *
|
|
88
|
+
sideFade;
|
|
89
|
+
float trough = -centerTrough * troughStrength * pressureMask * (0.58 + trailMask * 0.42);
|
|
90
|
+
float ridges = sideRidges * ridgeStrength * 0.5 * pressureMask * (0.36 + trailMask * 0.64);
|
|
91
|
+
|
|
92
|
+
return wakeStrength * (trough + ridges);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
void main() {
|
|
96
|
+
vec4 state = texture2D(u_state, v_uv);
|
|
97
|
+
float height = state.r;
|
|
98
|
+
float velocity = state.g;
|
|
99
|
+
|
|
100
|
+
float left = texture2D(u_state, v_uv - vec2(u_texel.x, 0.0)).r;
|
|
101
|
+
float right = texture2D(u_state, v_uv + vec2(u_texel.x, 0.0)).r;
|
|
102
|
+
float down = texture2D(u_state, v_uv - vec2(0.0, u_texel.y)).r;
|
|
103
|
+
float up = texture2D(u_state, v_uv + vec2(0.0, u_texel.y)).r;
|
|
104
|
+
float neighborAverage = (left + right + down + up) * 0.25;
|
|
105
|
+
|
|
106
|
+
velocity += (neighborAverage - height) * u_stiffness * u_delta;
|
|
107
|
+
|
|
108
|
+
for (int i = 0; i < MAX_WAKE_SEGMENTS; i++) {
|
|
109
|
+
if (i >= u_wakeCount) {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
float wake = segmentWake(v_uv, u_wakeA[i], u_wakeB[i], u_wakeShape[i]);
|
|
114
|
+
|
|
115
|
+
velocity += wake * 0.12;
|
|
116
|
+
height += wake * 0.014;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
velocity *= pow(u_damping, u_delta);
|
|
120
|
+
height *= pow(0.9985, u_delta);
|
|
121
|
+
height += velocity * u_delta;
|
|
122
|
+
|
|
123
|
+
gl_FragColor = vec4(height, velocity, 0.0, 1.0);
|
|
124
|
+
}
|
|
125
|
+
`, tt = `
|
|
126
|
+
precision highp float;
|
|
127
|
+
|
|
128
|
+
varying vec2 v_uv;
|
|
129
|
+
|
|
130
|
+
uniform sampler2D u_state;
|
|
131
|
+
uniform sampler2D u_background;
|
|
132
|
+
uniform sampler2D u_causticMap;
|
|
133
|
+
uniform vec2 u_texel;
|
|
134
|
+
uniform float u_domMode;
|
|
135
|
+
uniform float u_textureEnabled;
|
|
136
|
+
uniform float u_normalScale;
|
|
137
|
+
uniform float u_refractionStrength;
|
|
138
|
+
uniform float u_specularIntensity;
|
|
139
|
+
uniform float u_crestIntensity;
|
|
140
|
+
uniform float u_causticIntensity;
|
|
141
|
+
uniform float u_time;
|
|
142
|
+
|
|
143
|
+
const float DOM_CAUSTIC_GAIN = ${fe.causticGain.toFixed(2)};
|
|
144
|
+
const float DOM_SCREEN_COMPENSATION = ${fe.screenCompensation.toFixed(2)};
|
|
145
|
+
const float DOM_MAX_ALPHA = ${fe.maxAlpha.toFixed(2)};
|
|
146
|
+
|
|
147
|
+
vec3 proceduralBackground(vec2 uv) {
|
|
148
|
+
vec3 deep = vec3(0.055, 0.075, 0.070);
|
|
149
|
+
vec3 teal = vec3(0.060, 0.320, 0.310);
|
|
150
|
+
vec3 coral = vec3(0.680, 0.230, 0.190);
|
|
151
|
+
vec3 gold = vec3(0.850, 0.710, 0.360);
|
|
152
|
+
float diagonal = smoothstep(0.05, 0.95, uv.x * 0.72 + uv.y * 0.28);
|
|
153
|
+
vec3 color = mix(deep, teal, diagonal);
|
|
154
|
+
color = mix(color, coral, smoothstep(0.18, 0.76, uv.x - uv.y * 0.18) * 0.36);
|
|
155
|
+
color = mix(color, gold, smoothstep(0.58, 1.0, uv.y + uv.x * 0.16) * 0.24);
|
|
156
|
+
return color;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
vec4 causticLayer(vec2 uv, vec2 bend, mat2 rotation, float scale, vec2 drift) {
|
|
160
|
+
vec2 p = rotation * (uv * scale + drift * u_time);
|
|
161
|
+
|
|
162
|
+
return texture2D(u_causticMap, p + bend * 0.22);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void main() {
|
|
166
|
+
vec4 center = texture2D(u_state, v_uv);
|
|
167
|
+
float height = center.r;
|
|
168
|
+
float velocity = center.g;
|
|
169
|
+
float left = texture2D(u_state, v_uv - vec2(u_texel.x, 0.0)).r;
|
|
170
|
+
float right = texture2D(u_state, v_uv + vec2(u_texel.x, 0.0)).r;
|
|
171
|
+
float down = texture2D(u_state, v_uv - vec2(0.0, u_texel.y)).r;
|
|
172
|
+
float up = texture2D(u_state, v_uv + vec2(0.0, u_texel.y)).r;
|
|
173
|
+
float dx = right - left;
|
|
174
|
+
float dy = up - down;
|
|
175
|
+
float signedCurvature = left + right + down + up - height * 4.0;
|
|
176
|
+
vec3 normal = normalize(vec3(-dx * u_normalScale, 1.0, -dy * u_normalScale));
|
|
177
|
+
vec2 refractedUv = clamp(
|
|
178
|
+
v_uv + normal.xz * u_refractionStrength * 0.025,
|
|
179
|
+
vec2(0.001),
|
|
180
|
+
vec2(0.999)
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
vec3 base = u_textureEnabled > 0.5
|
|
184
|
+
? texture2D(u_background, refractedUv).rgb
|
|
185
|
+
: proceduralBackground(refractedUv);
|
|
186
|
+
|
|
187
|
+
float gradient = length(vec2(dx, dy)) * u_normalScale;
|
|
188
|
+
float crest = smoothstep(0.012, 0.24, gradient);
|
|
189
|
+
float trough = smoothstep(0.018, 0.09, -height);
|
|
190
|
+
float heightActivity = smoothstep(0.0005, 0.018, abs(height));
|
|
191
|
+
float aspect = u_texel.y / u_texel.x;
|
|
192
|
+
vec2 causticUv = vec2(v_uv.x * aspect, v_uv.y);
|
|
193
|
+
float rawActivity =
|
|
194
|
+
gradient * 0.72 +
|
|
195
|
+
abs(signedCurvature) * u_normalScale * 0.42 +
|
|
196
|
+
abs(velocity) * 14.0 +
|
|
197
|
+
heightActivity * 0.22;
|
|
198
|
+
float edgeFade = smoothstep(0.0, 0.52, rawActivity);
|
|
199
|
+
float visibleCrest = crest * edgeFade;
|
|
200
|
+
float visibleTrough = trough * edgeFade;
|
|
201
|
+
vec2 causticBend = normal.xz * (0.22 + visibleCrest * 0.08);
|
|
202
|
+
float slopeActivity = smoothstep(0.004, 0.18, gradient);
|
|
203
|
+
float convergence = smoothstep(0.004, 0.065, max(signedCurvature * u_normalScale, 0.0));
|
|
204
|
+
float defocus = smoothstep(0.004, 0.065, max(-signedCurvature * u_normalScale, 0.0));
|
|
205
|
+
float velocityActivity = smoothstep(0.0006, 0.006, abs(velocity));
|
|
206
|
+
float activitySignal =
|
|
207
|
+
slopeActivity * 0.38 +
|
|
208
|
+
convergence * 0.58 +
|
|
209
|
+
velocityActivity * 0.28 +
|
|
210
|
+
heightActivity * 0.22;
|
|
211
|
+
float activityGate = edgeFade * smoothstep(0.0, 0.58, activitySignal);
|
|
212
|
+
float causticFocus =
|
|
213
|
+
activityGate *
|
|
214
|
+
(1.0 - defocus * 0.65) *
|
|
215
|
+
mix(0.35, 1.25, convergence);
|
|
216
|
+
vec4 causticA = causticLayer(
|
|
217
|
+
causticUv,
|
|
218
|
+
causticBend,
|
|
219
|
+
mat2(0.94, -0.34, 0.34, 0.94),
|
|
220
|
+
1.45,
|
|
221
|
+
vec2(0.032, -0.021)
|
|
222
|
+
);
|
|
223
|
+
vec4 causticB = causticLayer(
|
|
224
|
+
causticUv,
|
|
225
|
+
-causticBend * 0.72,
|
|
226
|
+
mat2(0.62, 0.78, -0.78, 0.62),
|
|
227
|
+
2.05,
|
|
228
|
+
vec2(-0.019, 0.034)
|
|
229
|
+
);
|
|
230
|
+
float sparklePhase = sin(u_time * 8.0 + causticA.b * 6.28318 + causticB.a * 3.14159);
|
|
231
|
+
float primaryLines = smoothstep(0.10, 0.76, causticA.r * 0.72 + causticB.g * 0.18);
|
|
232
|
+
float softFill = smoothstep(0.08, 0.62, causticA.g) * 0.2;
|
|
233
|
+
float sparkle = smoothstep(
|
|
234
|
+
0.62,
|
|
235
|
+
0.96,
|
|
236
|
+
max(causticA.a, causticB.b) * (0.9 + sparklePhase * 0.1)
|
|
237
|
+
);
|
|
238
|
+
float detailModulation = mix(0.58, 1.2, causticB.b);
|
|
239
|
+
float brightnessModulation = mix(0.7, 1.12, causticA.b);
|
|
240
|
+
float causticPattern = clamp(
|
|
241
|
+
(primaryLines * detailModulation + softFill + sparkle * 0.1) *
|
|
242
|
+
brightnessModulation,
|
|
243
|
+
0.0,
|
|
244
|
+
1.0
|
|
245
|
+
);
|
|
246
|
+
float caustic = causticPattern * causticFocus;
|
|
247
|
+
float baseLuminance = dot(base, vec3(0.2126, 0.7152, 0.0722));
|
|
248
|
+
float causticEnergy = 1.0 - exp(-caustic * u_causticIntensity * 0.82);
|
|
249
|
+
float textureCausticGain = mix(0.12, 0.045, smoothstep(0.46, 0.9, baseLuminance));
|
|
250
|
+
vec3 lightDirection = normalize(vec3(-0.32, 0.64, 0.42));
|
|
251
|
+
vec3 viewDirection = vec3(0.0, 1.0, 0.0);
|
|
252
|
+
vec3 halfDirection = normalize(lightDirection + viewDirection);
|
|
253
|
+
float specular = pow(max(dot(normal, halfDirection), 0.0), 82.0) * activityGate;
|
|
254
|
+
|
|
255
|
+
float causticGain = u_domMode > 0.5 ? DOM_CAUSTIC_GAIN : textureCausticGain;
|
|
256
|
+
vec3 highlight =
|
|
257
|
+
vec3(1.0, 0.98, 0.88) * specular * u_specularIntensity +
|
|
258
|
+
vec3(0.75, 0.95, 1.0) * visibleCrest * u_crestIntensity * 0.11 +
|
|
259
|
+
vec3(0.84, 1.0, 0.92) * causticEnergy * causticGain;
|
|
260
|
+
|
|
261
|
+
if (u_domMode > 0.5) {
|
|
262
|
+
float domEnergy = max(max(highlight.r, highlight.g), highlight.b);
|
|
263
|
+
vec3 overlay = highlight / max(domEnergy, 0.00001);
|
|
264
|
+
float alpha = clamp(domEnergy * DOM_SCREEN_COMPENSATION, 0.0, DOM_MAX_ALPHA);
|
|
265
|
+
|
|
266
|
+
gl_FragColor = vec4(overlay, alpha);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
vec3 color = base + highlight - vec3(0.015, 0.055, 0.070) * visibleTrough * 0.45;
|
|
271
|
+
gl_FragColor = vec4(color, 1.0);
|
|
272
|
+
}
|
|
273
|
+
`;
|
|
274
|
+
class rt {
|
|
275
|
+
constructor(e) {
|
|
276
|
+
f(this, "gl");
|
|
277
|
+
f(this, "isWebGL2");
|
|
278
|
+
f(this, "canLinearFloat");
|
|
279
|
+
f(this, "quadBuffer");
|
|
280
|
+
f(this, "simulationProgram");
|
|
281
|
+
f(this, "materialProgram");
|
|
282
|
+
f(this, "backgroundTexture");
|
|
283
|
+
f(this, "causticTexture");
|
|
284
|
+
f(this, "stateTextures");
|
|
285
|
+
f(this, "framebuffers");
|
|
286
|
+
f(this, "readIndex", 0);
|
|
287
|
+
f(this, "simWidth", 1);
|
|
288
|
+
f(this, "simHeight", 1);
|
|
289
|
+
f(this, "cssWidth", 1);
|
|
290
|
+
f(this, "cssHeight", 1);
|
|
291
|
+
f(this, "textureSource");
|
|
292
|
+
f(this, "textureImage");
|
|
293
|
+
f(this, "textureReady", !1);
|
|
294
|
+
f(this, "textureNeedsUpload", !1);
|
|
295
|
+
f(this, "activityPixels");
|
|
296
|
+
f(this, "wakeAUniforms", new Float32Array(J * 4));
|
|
297
|
+
f(this, "wakeBUniforms", new Float32Array(J * 4));
|
|
298
|
+
f(this, "wakeShapeUniforms", new Float32Array(J * 4));
|
|
299
|
+
this.canvas = e;
|
|
300
|
+
const { gl: t, isWebGL2: n, canLinearFloat: i } = it(e);
|
|
301
|
+
this.gl = t, this.isWebGL2 = n, this.canLinearFloat = i, this.quadBuffer = q(t.createBuffer(), "WebGL buffer"), this.simulationProgram = Le(t, Ae, et), this.materialProgram = Le(t, Ae, tt), this.backgroundTexture = q(t.createTexture(), "WebGL texture"), this.causticTexture = q(t.createTexture(), "WebGL texture"), t.bindBuffer(t.ARRAY_BUFFER, this.quadBuffer), t.bufferData(
|
|
302
|
+
t.ARRAY_BUFFER,
|
|
303
|
+
new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
|
|
304
|
+
t.STATIC_DRAW
|
|
305
|
+
), t.disable(t.DEPTH_TEST), t.disable(t.STENCIL_TEST), t.disable(t.BLEND), this.initializeBackgroundTexture(), this.initializeCausticTexture(), this.resize(1, 1, 1, 192);
|
|
306
|
+
}
|
|
307
|
+
resize(e, t, n, i) {
|
|
308
|
+
this.cssWidth = Math.max(1, e), this.cssHeight = Math.max(1, t);
|
|
309
|
+
const a = Math.min(2, Math.max(1, n || 1)), l = Math.max(1, Math.round(this.cssWidth * a)), c = Math.max(1, Math.round(this.cssHeight * a));
|
|
310
|
+
(this.canvas.width !== l || this.canvas.height !== c) && (this.canvas.width = l, this.canvas.height = c);
|
|
311
|
+
const s = Math.max(32, Math.round(i)), d = this.cssWidth / this.cssHeight, E = d >= 1 ? s : Math.max(1, Math.round(s * d)), _ = d >= 1 ? Math.max(1, Math.round(s / d)) : s;
|
|
312
|
+
E === this.simWidth && _ === this.simHeight || (this.simWidth = E, this.simHeight = _, this.recreateState());
|
|
313
|
+
}
|
|
314
|
+
setTextureSource(e) {
|
|
315
|
+
if (e === this.textureSource || (this.textureSource = e, this.textureImage = void 0, this.textureReady = !1, this.textureNeedsUpload = !1, !e))
|
|
316
|
+
return;
|
|
317
|
+
if (typeof e != "string") {
|
|
318
|
+
this.textureImage = e, this.textureNeedsUpload = !0;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const t = new Image();
|
|
322
|
+
t.crossOrigin = "anonymous", t.onload = () => {
|
|
323
|
+
this.textureSource === e && (this.textureImage = t, this.textureNeedsUpload = !0);
|
|
324
|
+
}, t.onerror = () => {
|
|
325
|
+
this.textureSource === e && (this.textureImage = void 0, this.textureReady = !1, this.textureNeedsUpload = !1);
|
|
326
|
+
}, t.src = e;
|
|
327
|
+
}
|
|
328
|
+
step(e, t, n) {
|
|
329
|
+
if (!this.stateTextures || !this.framebuffers)
|
|
330
|
+
return;
|
|
331
|
+
const i = this.gl, a = 1 - this.readIndex;
|
|
332
|
+
i.useProgram(this.simulationProgram.program), i.bindFramebuffer(i.FRAMEBUFFER, this.framebuffers[a]), i.viewport(0, 0, this.simWidth, this.simHeight), i.activeTexture(i.TEXTURE0), i.bindTexture(i.TEXTURE_2D, this.stateTextures[this.readIndex]), this.prepareQuad(this.simulationProgram), this.setSimulationUniforms(e, t, n), i.drawArrays(i.TRIANGLE_STRIP, 0, 4), i.bindFramebuffer(i.FRAMEBUFFER, null), this.readIndex = a;
|
|
333
|
+
}
|
|
334
|
+
render(e, t = 0) {
|
|
335
|
+
const n = this.gl;
|
|
336
|
+
this.stateTextures && (e.texture ? this.setTextureSource(e.texture) : this.setTextureSource(void 0), this.uploadTextureIfNeeded(e), n.useProgram(this.materialProgram.program), n.bindFramebuffer(n.FRAMEBUFFER, null), n.viewport(0, 0, this.canvas.width, this.canvas.height), n.clearColor(0, 0, 0, 0), n.clear(n.COLOR_BUFFER_BIT), n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, this.stateTextures[this.readIndex]), n.activeTexture(n.TEXTURE1), n.bindTexture(n.TEXTURE_2D, this.backgroundTexture), n.activeTexture(n.TEXTURE2), n.bindTexture(n.TEXTURE_2D, this.causticTexture), this.prepareQuad(this.materialProgram), this.setMaterialUniforms(e, t), n.drawArrays(n.TRIANGLE_STRIP, 0, 4));
|
|
337
|
+
}
|
|
338
|
+
hasVisibleActivity() {
|
|
339
|
+
if (!this.framebuffers)
|
|
340
|
+
return !1;
|
|
341
|
+
const e = this.gl, t = this.framebuffers[this.readIndex], n = this.simWidth * this.simHeight * 4;
|
|
342
|
+
(!this.activityPixels || this.activityPixels.length !== n) && (this.activityPixels = new Float32Array(n)), e.bindFramebuffer(e.FRAMEBUFFER, t);
|
|
343
|
+
try {
|
|
344
|
+
e.readPixels(
|
|
345
|
+
0,
|
|
346
|
+
0,
|
|
347
|
+
this.simWidth,
|
|
348
|
+
this.simHeight,
|
|
349
|
+
e.RGBA,
|
|
350
|
+
e.FLOAT,
|
|
351
|
+
this.activityPixels
|
|
352
|
+
);
|
|
353
|
+
} finally {
|
|
354
|
+
e.bindFramebuffer(e.FRAMEBUFFER, null);
|
|
355
|
+
}
|
|
356
|
+
return ot(
|
|
357
|
+
this.activityPixels,
|
|
358
|
+
this.simWidth,
|
|
359
|
+
this.simHeight
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
clear() {
|
|
363
|
+
const e = this.gl;
|
|
364
|
+
if (this.framebuffers) {
|
|
365
|
+
e.viewport(0, 0, this.simWidth, this.simHeight);
|
|
366
|
+
for (const t of this.framebuffers)
|
|
367
|
+
e.bindFramebuffer(e.FRAMEBUFFER, t), e.clearColor(0, 0, 0, 1), e.clear(e.COLOR_BUFFER_BIT);
|
|
368
|
+
}
|
|
369
|
+
e.bindFramebuffer(e.FRAMEBUFFER, null), e.viewport(0, 0, this.canvas.width, this.canvas.height), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT);
|
|
370
|
+
}
|
|
371
|
+
dispose() {
|
|
372
|
+
var t, n;
|
|
373
|
+
const e = this.gl;
|
|
374
|
+
(t = this.stateTextures) == null || t.forEach((i) => e.deleteTexture(i)), (n = this.framebuffers) == null || n.forEach((i) => e.deleteFramebuffer(i)), e.deleteTexture(this.backgroundTexture), e.deleteTexture(this.causticTexture), e.deleteBuffer(this.quadBuffer), e.deleteProgram(this.simulationProgram.program), e.deleteProgram(this.materialProgram.program);
|
|
375
|
+
}
|
|
376
|
+
recreateState() {
|
|
377
|
+
var l, c;
|
|
378
|
+
const e = this.gl;
|
|
379
|
+
(l = this.stateTextures) == null || l.forEach((s) => e.deleteTexture(s)), (c = this.framebuffers) == null || c.forEach((s) => e.deleteFramebuffer(s));
|
|
380
|
+
const t = this.createStateTexture(), n = this.createStateTexture(), i = this.createFramebuffer(t), a = this.createFramebuffer(n);
|
|
381
|
+
this.stateTextures = [t, n], this.framebuffers = [i, a], this.readIndex = 0, this.clear();
|
|
382
|
+
}
|
|
383
|
+
createStateTexture() {
|
|
384
|
+
const e = this.gl, t = q(e.createTexture(), "WebGL texture");
|
|
385
|
+
if (e.bindTexture(e.TEXTURE_2D, t), e.texParameteri(
|
|
386
|
+
e.TEXTURE_2D,
|
|
387
|
+
e.TEXTURE_MIN_FILTER,
|
|
388
|
+
this.canLinearFloat ? e.LINEAR : e.NEAREST
|
|
389
|
+
), e.texParameteri(
|
|
390
|
+
e.TEXTURE_2D,
|
|
391
|
+
e.TEXTURE_MAG_FILTER,
|
|
392
|
+
this.canLinearFloat ? e.LINEAR : e.NEAREST
|
|
393
|
+
), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), this.isWebGL2) {
|
|
394
|
+
const n = e;
|
|
395
|
+
n.texImage2D(
|
|
396
|
+
n.TEXTURE_2D,
|
|
397
|
+
0,
|
|
398
|
+
n.RGBA32F,
|
|
399
|
+
this.simWidth,
|
|
400
|
+
this.simHeight,
|
|
401
|
+
0,
|
|
402
|
+
n.RGBA,
|
|
403
|
+
n.FLOAT,
|
|
404
|
+
null
|
|
405
|
+
);
|
|
406
|
+
} else
|
|
407
|
+
e.texImage2D(
|
|
408
|
+
e.TEXTURE_2D,
|
|
409
|
+
0,
|
|
410
|
+
e.RGBA,
|
|
411
|
+
this.simWidth,
|
|
412
|
+
this.simHeight,
|
|
413
|
+
0,
|
|
414
|
+
e.RGBA,
|
|
415
|
+
e.FLOAT,
|
|
416
|
+
null
|
|
417
|
+
);
|
|
418
|
+
return t;
|
|
419
|
+
}
|
|
420
|
+
createFramebuffer(e) {
|
|
421
|
+
const t = this.gl, n = q(t.createFramebuffer(), "WebGL framebuffer");
|
|
422
|
+
if (t.bindFramebuffer(t.FRAMEBUFFER, n), t.framebufferTexture2D(
|
|
423
|
+
t.FRAMEBUFFER,
|
|
424
|
+
t.COLOR_ATTACHMENT0,
|
|
425
|
+
t.TEXTURE_2D,
|
|
426
|
+
e,
|
|
427
|
+
0
|
|
428
|
+
), t.checkFramebufferStatus(t.FRAMEBUFFER) !== t.FRAMEBUFFER_COMPLETE)
|
|
429
|
+
throw new Error("WaterDistortion could not create a float simulation target.");
|
|
430
|
+
return t.bindFramebuffer(t.FRAMEBUFFER, null), n;
|
|
431
|
+
}
|
|
432
|
+
initializeBackgroundTexture() {
|
|
433
|
+
const e = this.gl;
|
|
434
|
+
e.bindTexture(e.TEXTURE_2D, this.backgroundTexture), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), e.texImage2D(
|
|
435
|
+
e.TEXTURE_2D,
|
|
436
|
+
0,
|
|
437
|
+
e.RGBA,
|
|
438
|
+
1,
|
|
439
|
+
1,
|
|
440
|
+
0,
|
|
441
|
+
e.RGBA,
|
|
442
|
+
e.UNSIGNED_BYTE,
|
|
443
|
+
new Uint8Array([18, 28, 26, 255])
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
initializeCausticTexture() {
|
|
447
|
+
const e = this.gl;
|
|
448
|
+
e.bindTexture(e.TEXTURE_2D, this.causticTexture), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.LINEAR_MIPMAP_LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.REPEAT), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.REPEAT), e.texImage2D(
|
|
449
|
+
e.TEXTURE_2D,
|
|
450
|
+
0,
|
|
451
|
+
e.RGBA,
|
|
452
|
+
C,
|
|
453
|
+
C,
|
|
454
|
+
0,
|
|
455
|
+
e.RGBA,
|
|
456
|
+
e.UNSIGNED_BYTE,
|
|
457
|
+
nt()
|
|
458
|
+
), e.generateMipmap(e.TEXTURE_2D);
|
|
459
|
+
}
|
|
460
|
+
uploadTextureIfNeeded(e) {
|
|
461
|
+
if (e.mode === "dom" || !this.textureImage || !this.textureNeedsUpload && !at(this.textureImage))
|
|
462
|
+
return;
|
|
463
|
+
const t = this.gl;
|
|
464
|
+
try {
|
|
465
|
+
t.bindTexture(t.TEXTURE_2D, this.backgroundTexture), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.texImage2D(
|
|
466
|
+
t.TEXTURE_2D,
|
|
467
|
+
0,
|
|
468
|
+
t.RGBA,
|
|
469
|
+
t.RGBA,
|
|
470
|
+
t.UNSIGNED_BYTE,
|
|
471
|
+
this.textureImage
|
|
472
|
+
), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 0), this.textureReady = !0, this.textureNeedsUpload = !1;
|
|
473
|
+
} catch {
|
|
474
|
+
this.textureReady = !1, this.textureNeedsUpload = !1;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
prepareQuad(e) {
|
|
478
|
+
const t = this.gl;
|
|
479
|
+
t.bindBuffer(t.ARRAY_BUFFER, this.quadBuffer), t.enableVertexAttribArray(e.position), t.vertexAttribPointer(e.position, 2, t.FLOAT, !1, 0, 0);
|
|
480
|
+
}
|
|
481
|
+
setSimulationUniforms(e, t, n) {
|
|
482
|
+
const i = this.gl, a = this.simulationProgram.program, l = Math.min(e.length, J), c = this.wakeAUniforms, s = this.wakeBUniforms, d = this.wakeShapeUniforms, E = Math.max(0, e.length - J);
|
|
483
|
+
c.fill(0), s.fill(0), d.fill(0);
|
|
484
|
+
for (let _ = 0; _ < l; _ += 1) {
|
|
485
|
+
const m = e[E + _], v = _ * 4;
|
|
486
|
+
c[v] = m.ax, c[v + 1] = m.ay, c[v + 2] = m.radius, c[v + 3] = m.wakeStrength, s[v] = m.bx, s[v + 1] = m.by, s[v + 2] = m.wakeLength, s[v + 3] = m.velocity, d[v] = m.troughStrength, d[v + 1] = m.ridgeStrength, d[v + 2] = m.ridgeOffset;
|
|
487
|
+
}
|
|
488
|
+
i.uniform1i(p(i, a, "u_state"), 0), i.uniform2f(p(i, a, "u_texel"), 1 / this.simWidth, 1 / this.simHeight), i.uniform1f(p(i, a, "u_delta"), n), i.uniform1f(p(i, a, "u_damping"), t.damping), i.uniform1f(p(i, a, "u_stiffness"), t.waveSpeed), i.uniform1f(p(i, a, "u_aspect"), this.cssWidth / this.cssHeight), i.uniform1i(p(i, a, "u_wakeCount"), l), i.uniform4fv(p(i, a, "u_wakeA[0]"), c), i.uniform4fv(p(i, a, "u_wakeB[0]"), s), i.uniform4fv(p(i, a, "u_wakeShape[0]"), d);
|
|
489
|
+
}
|
|
490
|
+
setMaterialUniforms(e, t) {
|
|
491
|
+
const n = this.gl, i = this.materialProgram.program, a = e.mode !== "dom";
|
|
492
|
+
n.uniform1i(p(n, i, "u_state"), 0), n.uniform1i(p(n, i, "u_background"), 1), n.uniform1i(p(n, i, "u_causticMap"), 2), n.uniform2f(p(n, i, "u_texel"), 1 / this.simWidth, 1 / this.simHeight), n.uniform1f(p(n, i, "u_domMode"), e.mode === "dom" ? 1 : 0), n.uniform1f(
|
|
493
|
+
p(n, i, "u_textureEnabled"),
|
|
494
|
+
a && this.textureReady ? 1 : 0
|
|
495
|
+
), n.uniform1f(p(n, i, "u_normalScale"), e.normalScale), n.uniform1f(p(n, i, "u_refractionStrength"), e.refractionStrength), n.uniform1f(p(n, i, "u_specularIntensity"), e.specularIntensity), n.uniform1f(p(n, i, "u_crestIntensity"), e.crestIntensity), n.uniform1f(p(n, i, "u_causticIntensity"), e.causticIntensity), n.uniform1f(p(n, i, "u_time"), t % 1e3);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function nt() {
|
|
499
|
+
const r = new Uint8Array(C * C * 4);
|
|
500
|
+
for (let e = 0; e < C; e += 1)
|
|
501
|
+
for (let t = 0; t < C; t += 1) {
|
|
502
|
+
const n = (t + 0.5) / C, i = (e + 0.5) / C, a = Math.round(ce(n, i, 0) * 255), l = Math.round(ce(n, i, 11) * 255), c = Math.round(ce(n, i, 23) * 255), s = Math.round(ce(n, i, 37) * 255), d = (e * C + t) * 4;
|
|
503
|
+
r[d] = a, r[d + 1] = l, r[d + 2] = c, r[d + 3] = s;
|
|
504
|
+
}
|
|
505
|
+
return r;
|
|
506
|
+
}
|
|
507
|
+
function ce(r, e, t) {
|
|
508
|
+
const n = Math.sin(se * (e * 2 + t * 0.013)) * 0.12 + Math.sin(se * (r * 3 + e + t * 0.021)) * 0.06, i = Math.cos(se * (r * 2 + t * 0.017)) * 0.12 + Math.sin(se * (e * 3 - r + t * 0.019)) * 0.06, a = r * oe + n, l = e * oe + i, c = Math.floor(a), s = Math.floor(l);
|
|
509
|
+
let d = Number.POSITIVE_INFINITY, E = Number.POSITIVE_INFINITY, _ = 0, m = 0;
|
|
510
|
+
for (let P = -1; P <= 1; P += 1)
|
|
511
|
+
for (let U = -1; U <= 1; U += 1) {
|
|
512
|
+
const k = c + U, B = s + P, M = Ie(k, oe), I = Ie(B, oe), z = k + 0.16 + me(M, I, t) * 0.68, N = B + 0.16 + me(M, I, t + 1) * 0.68, D = Math.hypot(a - z, l - N);
|
|
513
|
+
D < d ? (E = d, d = D, _ = M, m = I) : D < E && (E = D);
|
|
514
|
+
}
|
|
515
|
+
const v = E - d, A = 1 - Fe(0.025, 0.13, v), w = 1 - Fe(0.08, 0.34, v), W = 0.74 + me(_, m, t + 2) * 0.26, H = A * A * 0.58 + w * 0.34;
|
|
516
|
+
return We(Math.pow(H * W, 1.12));
|
|
517
|
+
}
|
|
518
|
+
function me(r, e, t) {
|
|
519
|
+
const n = Math.sin(r * 127.1 + e * 311.7 + t * 74.7) * 43758.5453123;
|
|
520
|
+
return n - Math.floor(n);
|
|
521
|
+
}
|
|
522
|
+
function Ie(r, e) {
|
|
523
|
+
return (r % e + e) % e;
|
|
524
|
+
}
|
|
525
|
+
function Fe(r, e, t) {
|
|
526
|
+
const n = We((t - r) / (e - r));
|
|
527
|
+
return n * n * (3 - n * 2);
|
|
528
|
+
}
|
|
529
|
+
function We(r) {
|
|
530
|
+
return Math.min(1, Math.max(0, r));
|
|
531
|
+
}
|
|
532
|
+
function it(r) {
|
|
533
|
+
const e = {
|
|
534
|
+
alpha: !0,
|
|
535
|
+
antialias: !1,
|
|
536
|
+
depth: !1,
|
|
537
|
+
stencil: !1,
|
|
538
|
+
premultipliedAlpha: !1,
|
|
539
|
+
preserveDrawingBuffer: !1
|
|
540
|
+
}, t = r.getContext("webgl2", e);
|
|
541
|
+
if (t) {
|
|
542
|
+
if (!t.getExtension("EXT_color_buffer_float"))
|
|
543
|
+
throw new Error("WaterDistortion requires float render targets.");
|
|
544
|
+
return {
|
|
545
|
+
gl: t,
|
|
546
|
+
isWebGL2: !0,
|
|
547
|
+
canLinearFloat: !!t.getExtension("OES_texture_float_linear")
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
const n = r.getContext("webgl", e) || r.getContext(
|
|
551
|
+
"experimental-webgl",
|
|
552
|
+
e
|
|
553
|
+
);
|
|
554
|
+
if (!n)
|
|
555
|
+
throw new Error("WaterDistortion requires WebGL.");
|
|
556
|
+
if (!n.getExtension("OES_texture_float") || !n.getExtension("WEBGL_color_buffer_float") && !n.getExtension("EXT_color_buffer_float"))
|
|
557
|
+
throw new Error("WaterDistortion requires float texture support.");
|
|
558
|
+
return {
|
|
559
|
+
gl: n,
|
|
560
|
+
isWebGL2: !1,
|
|
561
|
+
canLinearFloat: !!n.getExtension("OES_texture_float_linear")
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
function Le(r, e, t) {
|
|
565
|
+
const n = ke(r, r.VERTEX_SHADER, e), i = ke(r, r.FRAGMENT_SHADER, t), a = q(r.createProgram(), "WebGL program");
|
|
566
|
+
if (r.attachShader(a, n), r.attachShader(a, i), r.linkProgram(a), r.deleteShader(n), r.deleteShader(i), !r.getProgramParameter(a, r.LINK_STATUS)) {
|
|
567
|
+
const c = r.getProgramInfoLog(a) || "Unknown shader link error.";
|
|
568
|
+
throw r.deleteProgram(a), new Error(c);
|
|
569
|
+
}
|
|
570
|
+
const l = r.getAttribLocation(a, "a_position");
|
|
571
|
+
if (l < 0)
|
|
572
|
+
throw new Error("WaterDistortion could not bind its quad attribute.");
|
|
573
|
+
return { program: a, position: l };
|
|
574
|
+
}
|
|
575
|
+
function ke(r, e, t) {
|
|
576
|
+
const n = q(r.createShader(e), "WebGL shader");
|
|
577
|
+
if (r.shaderSource(n, t), r.compileShader(n), !r.getShaderParameter(n, r.COMPILE_STATUS)) {
|
|
578
|
+
const i = r.getShaderInfoLog(n) || "Unknown shader compile error.";
|
|
579
|
+
throw r.deleteShader(n), new Error(i);
|
|
580
|
+
}
|
|
581
|
+
return n;
|
|
582
|
+
}
|
|
583
|
+
function p(r, e, t) {
|
|
584
|
+
const n = r.getUniformLocation(e, t);
|
|
585
|
+
if (!n)
|
|
586
|
+
throw new Error(`WaterDistortion could not bind uniform ${t}.`);
|
|
587
|
+
return n;
|
|
588
|
+
}
|
|
589
|
+
function q(r, e) {
|
|
590
|
+
if (!r)
|
|
591
|
+
throw new Error(`WaterDistortion could not create ${e}.`);
|
|
592
|
+
return r;
|
|
593
|
+
}
|
|
594
|
+
function at(r) {
|
|
595
|
+
return typeof HTMLCanvasElement < "u" && r instanceof HTMLCanvasElement || typeof HTMLVideoElement < "u" && r instanceof HTMLVideoElement || typeof OffscreenCanvas < "u" && r instanceof OffscreenCanvas;
|
|
596
|
+
}
|
|
597
|
+
function ot(r, e, t, n = Je) {
|
|
598
|
+
const i = Math.max(0, Math.floor(e)), a = Math.max(0, Math.floor(t));
|
|
599
|
+
if (i === 0 || a === 0)
|
|
600
|
+
return !1;
|
|
601
|
+
const l = (c, s) => r[(s * i + c) * 4] ?? 0;
|
|
602
|
+
for (let c = 0; c < a; c += 1)
|
|
603
|
+
for (let s = 0; s < i; s += 1) {
|
|
604
|
+
const d = (c * i + s) * 4, E = r[d] ?? 0, _ = r[d + 1] ?? 0;
|
|
605
|
+
if (E < -n.trough || Math.abs(_) > n.velocity)
|
|
606
|
+
return !0;
|
|
607
|
+
const m = s > 0 ? l(s - 1, c) : E, v = s < i - 1 ? l(s + 1, c) : E, A = c > 0 ? l(s, c - 1) : E, w = c < a - 1 ? l(s, c + 1) : E, W = Math.hypot(v - m, w - A), H = Math.abs(m + v + A + w - E * 4);
|
|
608
|
+
if (W > n.gradient || H > n.curvature)
|
|
609
|
+
return !0;
|
|
610
|
+
}
|
|
611
|
+
return !1;
|
|
612
|
+
}
|
|
613
|
+
const L = {
|
|
614
|
+
width: 1,
|
|
615
|
+
height: 1,
|
|
616
|
+
interactionRadius: 25,
|
|
617
|
+
wakeStrength: 0.54,
|
|
618
|
+
troughStrength: 0.92,
|
|
619
|
+
ridgeStrength: 0.46,
|
|
620
|
+
ridgeOffset: 10,
|
|
621
|
+
wakeLength: 84,
|
|
622
|
+
velocityScale: 1,
|
|
623
|
+
velocityClamp: 1.35,
|
|
624
|
+
cursorSmoothing: 0.2,
|
|
625
|
+
segmentSpacing: 18
|
|
626
|
+
}, st = 24;
|
|
627
|
+
function ge(r) {
|
|
628
|
+
return {
|
|
629
|
+
width: Math.max(1, r.width ?? L.width),
|
|
630
|
+
height: Math.max(1, r.height ?? L.height),
|
|
631
|
+
interactionRadius: Math.max(
|
|
632
|
+
1,
|
|
633
|
+
r.interactionRadius ?? L.interactionRadius
|
|
634
|
+
),
|
|
635
|
+
wakeStrength: Math.max(
|
|
636
|
+
0,
|
|
637
|
+
r.wakeStrength ?? L.wakeStrength
|
|
638
|
+
),
|
|
639
|
+
troughStrength: Math.max(
|
|
640
|
+
0,
|
|
641
|
+
r.troughStrength ?? L.troughStrength
|
|
642
|
+
),
|
|
643
|
+
ridgeStrength: Math.max(
|
|
644
|
+
0,
|
|
645
|
+
r.ridgeStrength ?? L.ridgeStrength
|
|
646
|
+
),
|
|
647
|
+
ridgeOffset: Math.max(0, r.ridgeOffset ?? L.ridgeOffset),
|
|
648
|
+
wakeLength: Math.max(1, r.wakeLength ?? L.wakeLength),
|
|
649
|
+
velocityScale: Math.max(
|
|
650
|
+
0.01,
|
|
651
|
+
r.velocityScale ?? L.velocityScale
|
|
652
|
+
),
|
|
653
|
+
velocityClamp: Math.max(
|
|
654
|
+
0.05,
|
|
655
|
+
r.velocityClamp ?? L.velocityClamp
|
|
656
|
+
),
|
|
657
|
+
cursorSmoothing: h(
|
|
658
|
+
r.cursorSmoothing ?? L.cursorSmoothing,
|
|
659
|
+
0,
|
|
660
|
+
0.9
|
|
661
|
+
),
|
|
662
|
+
segmentSpacing: Math.max(
|
|
663
|
+
1,
|
|
664
|
+
r.segmentSpacing ?? L.segmentSpacing
|
|
665
|
+
)
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function Ue(r, e, t = r.timeStamp) {
|
|
669
|
+
const n = typeof r.getCoalescedEvents == "function" ? r.getCoalescedEvents() : [], i = n.length > 0 ? n : [r], a = t - r.timeStamp;
|
|
670
|
+
return i.map((l) => ({
|
|
671
|
+
x: l.clientX - e.left,
|
|
672
|
+
y: l.clientY - e.top,
|
|
673
|
+
time: l.timeStamp + a
|
|
674
|
+
}));
|
|
675
|
+
}
|
|
676
|
+
class ct {
|
|
677
|
+
constructor(e = {}) {
|
|
678
|
+
f(this, "options");
|
|
679
|
+
f(this, "previous");
|
|
680
|
+
f(this, "smoothedVelocity", 0);
|
|
681
|
+
f(this, "disturbances", []);
|
|
682
|
+
this.options = ge(e);
|
|
683
|
+
}
|
|
684
|
+
configure(e) {
|
|
685
|
+
this.options = ge({
|
|
686
|
+
...this.options,
|
|
687
|
+
...e
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
reset() {
|
|
691
|
+
this.previous = void 0, this.smoothedVelocity = 0, this.disturbances.length = 0;
|
|
692
|
+
}
|
|
693
|
+
addSample(e) {
|
|
694
|
+
this.disturbances.length = 0;
|
|
695
|
+
const t = this.clampSample(e), n = this.previous;
|
|
696
|
+
if (!n)
|
|
697
|
+
return this.previous = t, this.disturbances;
|
|
698
|
+
t.time <= n.time && (t.time = n.time + 0.01);
|
|
699
|
+
const i = this.smoothSample(n, t), a = Ze(n, i);
|
|
700
|
+
if (a < 0.35)
|
|
701
|
+
return this.previous = i, this.disturbances;
|
|
702
|
+
const l = a / Math.max(0.01, i.time - n.time), c = h(1 - this.options.cursorSmoothing, 0.12, 1);
|
|
703
|
+
this.smoothedVelocity = O(
|
|
704
|
+
this.smoothedVelocity,
|
|
705
|
+
l,
|
|
706
|
+
c
|
|
707
|
+
), this.previous = i;
|
|
708
|
+
const s = Math.min(
|
|
709
|
+
st,
|
|
710
|
+
Math.max(1, Math.ceil(a / this.options.segmentSpacing))
|
|
711
|
+
);
|
|
712
|
+
for (let d = 0; d < s; d += 1) {
|
|
713
|
+
const E = d / s, _ = (d + 1) / s;
|
|
714
|
+
this.disturbances.push(
|
|
715
|
+
ve(
|
|
716
|
+
De(n, i, E),
|
|
717
|
+
De(n, i, _),
|
|
718
|
+
this.smoothedVelocity,
|
|
719
|
+
this.options
|
|
720
|
+
)
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
return this.disturbances;
|
|
724
|
+
}
|
|
725
|
+
clampSample(e) {
|
|
726
|
+
return {
|
|
727
|
+
x: h(e.x, 0, this.options.width),
|
|
728
|
+
y: h(e.y, 0, this.options.height),
|
|
729
|
+
time: e.time
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
smoothSample(e, t) {
|
|
733
|
+
const n = 1 - this.options.cursorSmoothing;
|
|
734
|
+
return {
|
|
735
|
+
x: O(e.x, t.x, n),
|
|
736
|
+
y: O(e.y, t.y, n),
|
|
737
|
+
time: t.time
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
function ve(r, e, t, n) {
|
|
742
|
+
const i = ge(n), a = h(
|
|
743
|
+
t * i.velocityScale / i.velocityClamp,
|
|
744
|
+
0,
|
|
745
|
+
1
|
|
746
|
+
), l = h(r.y / i.height, 0, 1), c = h(e.y / i.height, 0, 1), s = i.wakeLength * O(0.55, 1.35, a);
|
|
747
|
+
return {
|
|
748
|
+
ax: h(r.x / i.width, 0, 1),
|
|
749
|
+
ay: 1 - l,
|
|
750
|
+
bx: h(e.x / i.width, 0, 1),
|
|
751
|
+
by: 1 - c,
|
|
752
|
+
radius: i.interactionRadius / i.height,
|
|
753
|
+
wakeStrength: i.wakeStrength * O(0.18, 1, a),
|
|
754
|
+
troughStrength: i.troughStrength,
|
|
755
|
+
ridgeStrength: i.ridgeStrength,
|
|
756
|
+
ridgeOffset: i.ridgeOffset / i.height,
|
|
757
|
+
wakeLength: s / i.height,
|
|
758
|
+
velocity: a
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function De(r, e, t) {
|
|
762
|
+
return {
|
|
763
|
+
x: O(r.x, e.x, t),
|
|
764
|
+
y: O(r.y, e.y, t),
|
|
765
|
+
time: O(r.time, e.time, t)
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
function ut(r) {
|
|
769
|
+
const e = h(r, 0.85, 0.998), t = Math.ceil(Math.log(0.012) / Math.log(e));
|
|
770
|
+
return h(t * (1e3 / 60), 900, 5200);
|
|
771
|
+
}
|
|
772
|
+
const x = {
|
|
773
|
+
mode: "texture",
|
|
774
|
+
damping: 0.98,
|
|
775
|
+
waveSpeed: 0.4,
|
|
776
|
+
normalScale: 20,
|
|
777
|
+
refractionStrength: 0.7,
|
|
778
|
+
specularIntensity: 1,
|
|
779
|
+
crestIntensity: 0.2,
|
|
780
|
+
causticIntensity: 0,
|
|
781
|
+
simulationResolution: 192,
|
|
782
|
+
wakeStrength: 0.54,
|
|
783
|
+
interactionRadius: 25,
|
|
784
|
+
troughStrength: 0.92,
|
|
785
|
+
ridgeStrength: 0.46,
|
|
786
|
+
ridgeOffset: 10,
|
|
787
|
+
wakeLength: 84,
|
|
788
|
+
velocityScale: 1,
|
|
789
|
+
velocityClamp: 1.35,
|
|
790
|
+
cursorSmoothing: 0.2,
|
|
791
|
+
segmentSpacing: 18,
|
|
792
|
+
idleTimeout: 900,
|
|
793
|
+
interactionMode: "move",
|
|
794
|
+
runInBackground: !1,
|
|
795
|
+
pauseKey: void 0
|
|
796
|
+
}, G = 1e3 / 60, lt = 4, Pe = 360, Be = 24, ht = 200;
|
|
797
|
+
function dt(r) {
|
|
798
|
+
return r instanceof Element && r.closest(
|
|
799
|
+
"a, button, input, select, textarea, [contenteditable]:not([contenteditable=false])"
|
|
800
|
+
) !== null;
|
|
801
|
+
}
|
|
802
|
+
function ft(r) {
|
|
803
|
+
const e = r.strength === void 0 ? void 0 : r.strength / 48;
|
|
804
|
+
return {
|
|
805
|
+
mode: r.mode ?? x.mode,
|
|
806
|
+
texture: r.texture,
|
|
807
|
+
damping: h(
|
|
808
|
+
r.damping ?? r.dissipation ?? x.damping,
|
|
809
|
+
0.85,
|
|
810
|
+
0.998
|
|
811
|
+
),
|
|
812
|
+
waveSpeed: h(r.waveSpeed ?? x.waveSpeed, 0.05, 1),
|
|
813
|
+
normalScale: h(
|
|
814
|
+
r.normalScale ?? x.normalScale,
|
|
815
|
+
1,
|
|
816
|
+
80
|
|
817
|
+
),
|
|
818
|
+
refractionStrength: h(
|
|
819
|
+
r.refractionStrength ?? x.refractionStrength,
|
|
820
|
+
0,
|
|
821
|
+
2.5
|
|
822
|
+
),
|
|
823
|
+
specularIntensity: h(
|
|
824
|
+
r.specularIntensity ?? x.specularIntensity,
|
|
825
|
+
0,
|
|
826
|
+
3
|
|
827
|
+
),
|
|
828
|
+
crestIntensity: h(
|
|
829
|
+
r.crestIntensity ?? x.crestIntensity,
|
|
830
|
+
0,
|
|
831
|
+
3
|
|
832
|
+
),
|
|
833
|
+
causticIntensity: h(
|
|
834
|
+
r.causticIntensity ?? x.causticIntensity,
|
|
835
|
+
0,
|
|
836
|
+
3
|
|
837
|
+
),
|
|
838
|
+
simulationResolution: h(
|
|
839
|
+
Math.round(
|
|
840
|
+
r.simulationResolution ?? x.simulationResolution
|
|
841
|
+
),
|
|
842
|
+
64,
|
|
843
|
+
384
|
|
844
|
+
),
|
|
845
|
+
wakeStrength: h(
|
|
846
|
+
r.wakeStrength ?? r.rippleStrength ?? e ?? x.wakeStrength,
|
|
847
|
+
0,
|
|
848
|
+
3
|
|
849
|
+
),
|
|
850
|
+
interactionRadius: h(
|
|
851
|
+
r.interactionRadius ?? x.interactionRadius,
|
|
852
|
+
2,
|
|
853
|
+
80
|
|
854
|
+
),
|
|
855
|
+
troughStrength: h(
|
|
856
|
+
r.troughStrength ?? x.troughStrength,
|
|
857
|
+
0,
|
|
858
|
+
3
|
|
859
|
+
),
|
|
860
|
+
ridgeStrength: h(
|
|
861
|
+
r.ridgeStrength ?? x.ridgeStrength,
|
|
862
|
+
0,
|
|
863
|
+
3
|
|
864
|
+
),
|
|
865
|
+
ridgeOffset: h(
|
|
866
|
+
r.ridgeOffset ?? x.ridgeOffset,
|
|
867
|
+
0,
|
|
868
|
+
80
|
|
869
|
+
),
|
|
870
|
+
wakeLength: h(
|
|
871
|
+
r.wakeLength ?? x.wakeLength,
|
|
872
|
+
1,
|
|
873
|
+
240
|
|
874
|
+
),
|
|
875
|
+
velocityScale: h(
|
|
876
|
+
r.velocityScale ?? x.velocityScale,
|
|
877
|
+
0.01,
|
|
878
|
+
4
|
|
879
|
+
),
|
|
880
|
+
velocityClamp: h(
|
|
881
|
+
r.velocityClamp ?? x.velocityClamp,
|
|
882
|
+
0.05,
|
|
883
|
+
8
|
|
884
|
+
),
|
|
885
|
+
cursorSmoothing: h(
|
|
886
|
+
r.cursorSmoothing ?? x.cursorSmoothing,
|
|
887
|
+
0,
|
|
888
|
+
0.9
|
|
889
|
+
),
|
|
890
|
+
segmentSpacing: h(
|
|
891
|
+
r.segmentSpacing ?? x.segmentSpacing,
|
|
892
|
+
1,
|
|
893
|
+
96
|
|
894
|
+
),
|
|
895
|
+
idleTimeout: Math.max(120, r.idleTimeout ?? x.idleTimeout),
|
|
896
|
+
interactionMode: r.interactionMode ?? x.interactionMode,
|
|
897
|
+
runInBackground: r.runInBackground ?? x.runInBackground,
|
|
898
|
+
pauseKey: r.pauseKey || x.pauseKey
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
function Ce(r, e, t) {
|
|
902
|
+
const n = h(r.x, 0, 1) * t.width, i = h(r.y, 0, 1) * t.height, a = Math.max(0.5, e.interactionRadius * 0.08), l = e.velocityClamp / e.velocityScale, c = {
|
|
903
|
+
...e,
|
|
904
|
+
width: t.width,
|
|
905
|
+
height: t.height,
|
|
906
|
+
wakeLength: e.interactionRadius * 1.5
|
|
907
|
+
};
|
|
908
|
+
return [
|
|
909
|
+
ve(
|
|
910
|
+
{ x: n - a, y: i },
|
|
911
|
+
{ x: n + a, y: i },
|
|
912
|
+
l,
|
|
913
|
+
c
|
|
914
|
+
),
|
|
915
|
+
ve(
|
|
916
|
+
{ x: n, y: i - a },
|
|
917
|
+
{ x: n, y: i + a },
|
|
918
|
+
l,
|
|
919
|
+
c
|
|
920
|
+
)
|
|
921
|
+
];
|
|
922
|
+
}
|
|
923
|
+
function mt(r) {
|
|
924
|
+
const [e, t] = je(!1);
|
|
925
|
+
return V(() => {
|
|
926
|
+
if (!r || typeof window > "u" || !window.matchMedia) {
|
|
927
|
+
t(!1);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const n = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
931
|
+
t(n.matches);
|
|
932
|
+
const i = (a) => {
|
|
933
|
+
t(a.matches);
|
|
934
|
+
};
|
|
935
|
+
return n.addEventListener("change", i), () => {
|
|
936
|
+
n.removeEventListener("change", i);
|
|
937
|
+
};
|
|
938
|
+
}, [r]), e;
|
|
939
|
+
}
|
|
940
|
+
const gt = $e(function(e, t) {
|
|
941
|
+
const {
|
|
942
|
+
underlay: n,
|
|
943
|
+
children: i,
|
|
944
|
+
foreground: a,
|
|
945
|
+
className: l,
|
|
946
|
+
style: c,
|
|
947
|
+
reducedMotion: s = "respect"
|
|
948
|
+
} = e, d = y(null), E = y(null), _ = y(null), m = y(new ct()), v = y(null), A = y(null), w = y(() => {
|
|
949
|
+
}), W = y(() => {
|
|
950
|
+
}), H = y(() => {
|
|
951
|
+
}), P = y([]), U = y(!0), k = y(!0), B = y(!1), M = y(!1), I = y(null), z = y(0), N = y(0), D = y(0), R = ft(e), g = y(R), $ = y({ width: 1, height: 1 }), Ne = mt(
|
|
952
|
+
s === "respect"
|
|
953
|
+
), ue = s === "disable" || s === "respect" && Ne, Xe = a ?? i;
|
|
954
|
+
g.current = R, Qe(
|
|
955
|
+
t,
|
|
956
|
+
() => ({
|
|
957
|
+
triggerRipple(S) {
|
|
958
|
+
B.current || M.current || H.current(
|
|
959
|
+
Ce(
|
|
960
|
+
S,
|
|
961
|
+
g.current,
|
|
962
|
+
$.current
|
|
963
|
+
)
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
}),
|
|
967
|
+
[]
|
|
968
|
+
), V(() => {
|
|
969
|
+
var S;
|
|
970
|
+
B.current = ue, ue && (m.current.reset(), I.current = null, P.current = [], z.current = 0, N.current = 0, D.current = 0, (S = _.current) == null || S.clear()), w.current();
|
|
971
|
+
}, [ue]), V(() => {
|
|
972
|
+
const S = _.current;
|
|
973
|
+
if (!S)
|
|
974
|
+
return;
|
|
975
|
+
const { width: K, height: b } = $.current;
|
|
976
|
+
S.resize(
|
|
977
|
+
K,
|
|
978
|
+
b,
|
|
979
|
+
window.devicePixelRatio,
|
|
980
|
+
R.simulationResolution
|
|
981
|
+
), S.setTextureSource(R.texture), w.current();
|
|
982
|
+
}, [
|
|
983
|
+
R.mode,
|
|
984
|
+
R.texture,
|
|
985
|
+
R.damping,
|
|
986
|
+
R.waveSpeed,
|
|
987
|
+
R.normalScale,
|
|
988
|
+
R.refractionStrength,
|
|
989
|
+
R.specularIntensity,
|
|
990
|
+
R.crestIntensity,
|
|
991
|
+
R.causticIntensity,
|
|
992
|
+
R.simulationResolution
|
|
993
|
+
]), V(() => {
|
|
994
|
+
const S = d.current, K = E.current;
|
|
995
|
+
if (!S || !K)
|
|
996
|
+
return;
|
|
997
|
+
k.current = typeof document.hasFocus == "function" ? document.hasFocus() : !0;
|
|
998
|
+
let b = null, ie, ee = G, xe = !1, te;
|
|
999
|
+
const Y = () => {
|
|
1000
|
+
v.current !== null && (window.cancelAnimationFrame(v.current), v.current = null), A.current !== null && (window.clearTimeout(A.current), A.current = null);
|
|
1001
|
+
}, Oe = (o, u) => {
|
|
1002
|
+
m.current.configure({
|
|
1003
|
+
width: o,
|
|
1004
|
+
height: u,
|
|
1005
|
+
interactionRadius: g.current.interactionRadius,
|
|
1006
|
+
wakeStrength: g.current.wakeStrength,
|
|
1007
|
+
troughStrength: g.current.troughStrength,
|
|
1008
|
+
ridgeStrength: g.current.ridgeStrength,
|
|
1009
|
+
ridgeOffset: g.current.ridgeOffset,
|
|
1010
|
+
wakeLength: g.current.wakeLength,
|
|
1011
|
+
velocityScale: g.current.velocityScale,
|
|
1012
|
+
velocityClamp: g.current.velocityClamp,
|
|
1013
|
+
cursorSmoothing: g.current.cursorSmoothing,
|
|
1014
|
+
segmentSpacing: g.current.segmentSpacing
|
|
1015
|
+
});
|
|
1016
|
+
}, He = (o, u) => {
|
|
1017
|
+
const F = Math.max(1, o), T = Math.max(1, u);
|
|
1018
|
+
$.current = { width: F, height: T }, Oe(F, T), b == null || b.resize(
|
|
1019
|
+
F,
|
|
1020
|
+
T,
|
|
1021
|
+
window.devicePixelRatio,
|
|
1022
|
+
g.current.simulationResolution
|
|
1023
|
+
);
|
|
1024
|
+
}, pe = () => {
|
|
1025
|
+
b == null || b.render(g.current, performance.now() * 1e-3);
|
|
1026
|
+
}, X = () => {
|
|
1027
|
+
ie = void 0, ee = G;
|
|
1028
|
+
}, re = () => {
|
|
1029
|
+
Y(), m.current.reset(), I.current = null, X(), te === void 0 && (te = performance.now());
|
|
1030
|
+
}, Q = () => {
|
|
1031
|
+
const o = g.current;
|
|
1032
|
+
let u = !1;
|
|
1033
|
+
if (!(!B.current && !M.current && U.current && (o.runInBackground || !document.hidden && k.current))) {
|
|
1034
|
+
X();
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if (te !== void 0) {
|
|
1038
|
+
const T = performance.now() - te;
|
|
1039
|
+
z.current += T, N.current += T, D.current += T, te = void 0, u = !0;
|
|
1040
|
+
}
|
|
1041
|
+
(!o.runInBackground || u) && X(), pe(), w.current();
|
|
1042
|
+
}, Ee = (o) => {
|
|
1043
|
+
v.current = null;
|
|
1044
|
+
const u = g.current;
|
|
1045
|
+
if (!b || M.current || !U.current || !u.runInBackground && (document.hidden || !k.current)) {
|
|
1046
|
+
X();
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
if (B.current) {
|
|
1050
|
+
P.current = [], b.render(u, o * 1e-3), X();
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
const F = u.runInBackground ? Pe : lt, T = ie === void 0 ? G : h(
|
|
1054
|
+
o - ie,
|
|
1055
|
+
0,
|
|
1056
|
+
u.runInBackground ? G * Pe : 64
|
|
1057
|
+
);
|
|
1058
|
+
ie = o, ee = Math.min(
|
|
1059
|
+
ee + T,
|
|
1060
|
+
G * F
|
|
1061
|
+
);
|
|
1062
|
+
let Z = P.current.splice(0), be = 0;
|
|
1063
|
+
for (; ee >= G && be < F; )
|
|
1064
|
+
b.step(Z, u, 1), Z = [], ee -= G, be += 1;
|
|
1065
|
+
if (b.render(u, o * 1e-3), P.current.length > 0) {
|
|
1066
|
+
w.current();
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (o < z.current) {
|
|
1070
|
+
w.current();
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (xe) {
|
|
1074
|
+
o < N.current ? w.current() : X();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if (o < D.current) {
|
|
1078
|
+
w.current();
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
try {
|
|
1082
|
+
b.hasVisibleActivity() ? (D.current = o + ht, w.current()) : X();
|
|
1083
|
+
} catch {
|
|
1084
|
+
xe = !0, o < N.current ? w.current() : X();
|
|
1085
|
+
}
|
|
1086
|
+
}, le = () => {
|
|
1087
|
+
M.current || v.current !== null || A.current !== null || (g.current.runInBackground && document.hidden ? A.current = window.setTimeout(() => {
|
|
1088
|
+
A.current = null, Ee(performance.now());
|
|
1089
|
+
}, G) : v.current = window.requestAnimationFrame(Ee));
|
|
1090
|
+
};
|
|
1091
|
+
w.current = le;
|
|
1092
|
+
try {
|
|
1093
|
+
b = new rt(K), _.current = b, b.setTextureSource(g.current.texture);
|
|
1094
|
+
} catch {
|
|
1095
|
+
return K.style.display = "none", _.current = null, w.current = () => {
|
|
1096
|
+
}, () => {
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
const ae = () => {
|
|
1100
|
+
const o = K.getBoundingClientRect();
|
|
1101
|
+
return He(o.width, o.height), o;
|
|
1102
|
+
}, ze = () => {
|
|
1103
|
+
ae(), pe();
|
|
1104
|
+
}, he = (o) => {
|
|
1105
|
+
if (M.current || o.length === 0)
|
|
1106
|
+
return;
|
|
1107
|
+
const u = P.current;
|
|
1108
|
+
for (const Z of o)
|
|
1109
|
+
u.push(Z);
|
|
1110
|
+
u.length > Be && u.splice(0, u.length - Be);
|
|
1111
|
+
const T = performance.now() + g.current.idleTimeout;
|
|
1112
|
+
z.current = Math.max(z.current, T), N.current = Math.max(
|
|
1113
|
+
N.current,
|
|
1114
|
+
T + ut(g.current.damping)
|
|
1115
|
+
), D.current = 0, le();
|
|
1116
|
+
};
|
|
1117
|
+
H.current = he;
|
|
1118
|
+
const _e = (o) => {
|
|
1119
|
+
const u = g.current;
|
|
1120
|
+
if (B.current || M.current || !U.current || u.interactionMode === "event" || !u.runInBackground && (document.hidden || !k.current) || o.pointerType === "touch" && !o.isPrimary)
|
|
1121
|
+
return;
|
|
1122
|
+
m.current.reset();
|
|
1123
|
+
const F = ae(), [T] = Ue(o, F, performance.now());
|
|
1124
|
+
T && ((u.interactionMode === "click" || u.interactionMode === "drag") && he(
|
|
1125
|
+
Ce(
|
|
1126
|
+
{
|
|
1127
|
+
x: T.x / $.current.width,
|
|
1128
|
+
y: T.y / $.current.height
|
|
1129
|
+
},
|
|
1130
|
+
u,
|
|
1131
|
+
$.current
|
|
1132
|
+
)
|
|
1133
|
+
), u.interactionMode === "drag" ? (I.current = o.pointerId, m.current.addSample(T)) : u.interactionMode === "move" && m.current.addSample(T));
|
|
1134
|
+
}, Se = (o) => {
|
|
1135
|
+
const u = g.current;
|
|
1136
|
+
if (B.current || M.current || !U.current || u.interactionMode !== "move" && (u.interactionMode !== "drag" || I.current !== o.pointerId) || !u.runInBackground && (document.hidden || !k.current) || o.pointerType === "touch" && !o.isPrimary)
|
|
1137
|
+
return;
|
|
1138
|
+
const F = ae(), T = Ue(o, F, performance.now());
|
|
1139
|
+
for (const Z of T)
|
|
1140
|
+
he(m.current.addSample(Z));
|
|
1141
|
+
}, j = (o) => {
|
|
1142
|
+
I.current !== null && I.current !== o.pointerId || (I.current = null, m.current.reset());
|
|
1143
|
+
}, Te = (o) => {
|
|
1144
|
+
const u = g.current.pauseKey;
|
|
1145
|
+
!u || o.code !== u || o.repeat || o.altKey || o.ctrlKey || o.metaKey || dt(o.target) || (o.preventDefault(), M.current = !M.current, M.current ? re() : (Y(), Q()));
|
|
1146
|
+
}, ye = () => {
|
|
1147
|
+
Y(), document.hidden && !g.current.runInBackground ? re() : Q();
|
|
1148
|
+
}, Re = () => {
|
|
1149
|
+
k.current = !1, g.current.runInBackground ? (Y(), Q()) : re();
|
|
1150
|
+
}, we = () => {
|
|
1151
|
+
k.current = !0, Y(), Q();
|
|
1152
|
+
}, Ke = () => {
|
|
1153
|
+
Y(), !g.current.runInBackground && (document.hidden || !k.current) ? re() : Q();
|
|
1154
|
+
};
|
|
1155
|
+
W.current = Ke, ze();
|
|
1156
|
+
const Me = new ResizeObserver(() => {
|
|
1157
|
+
ae(), le();
|
|
1158
|
+
});
|
|
1159
|
+
Me.observe(K);
|
|
1160
|
+
let ne;
|
|
1161
|
+
return "IntersectionObserver" in window && (ne = new IntersectionObserver((o) => {
|
|
1162
|
+
const u = o[0];
|
|
1163
|
+
U.current = u ? u.isIntersecting : !0, U.current ? Q() : re();
|
|
1164
|
+
}), ne.observe(S)), S.addEventListener("pointerdown", _e, {
|
|
1165
|
+
passive: !0
|
|
1166
|
+
}), S.addEventListener("pointermove", Se, {
|
|
1167
|
+
passive: !0
|
|
1168
|
+
}), S.addEventListener("pointerup", j, {
|
|
1169
|
+
passive: !0
|
|
1170
|
+
}), S.addEventListener("pointerleave", j, {
|
|
1171
|
+
passive: !0
|
|
1172
|
+
}), S.addEventListener("pointercancel", j, {
|
|
1173
|
+
passive: !0
|
|
1174
|
+
}), window.addEventListener("blur", Re), window.addEventListener("focus", we), document.addEventListener("keydown", Te), document.addEventListener("visibilitychange", ye), () => {
|
|
1175
|
+
var o;
|
|
1176
|
+
Y(), Me.disconnect(), ne == null || ne.disconnect(), S.removeEventListener("pointerdown", _e), S.removeEventListener("pointermove", Se), S.removeEventListener("pointerup", j), S.removeEventListener("pointerleave", j), S.removeEventListener("pointercancel", j), window.removeEventListener("blur", Re), window.removeEventListener("focus", we), document.removeEventListener("keydown", Te), document.removeEventListener("visibilitychange", ye), (o = _.current) == null || o.dispose(), _.current = null, w.current = () => {
|
|
1177
|
+
}, W.current = () => {
|
|
1178
|
+
}, H.current = () => {
|
|
1179
|
+
};
|
|
1180
|
+
};
|
|
1181
|
+
}, []), V(() => {
|
|
1182
|
+
m.current.reset(), I.current = null;
|
|
1183
|
+
}, [R.interactionMode]), V(() => {
|
|
1184
|
+
W.current();
|
|
1185
|
+
}, [R.runInBackground]), V(() => {
|
|
1186
|
+
!R.pauseKey && M.current && (M.current = !1, W.current());
|
|
1187
|
+
}, [R.pauseKey]);
|
|
1188
|
+
const Ge = {
|
|
1189
|
+
...c,
|
|
1190
|
+
position: "relative",
|
|
1191
|
+
overflow: "hidden",
|
|
1192
|
+
isolation: "isolate"
|
|
1193
|
+
};
|
|
1194
|
+
return /* @__PURE__ */ qe("div", { ref: d, className: l, style: Ge, children: [
|
|
1195
|
+
n ? /* @__PURE__ */ de(
|
|
1196
|
+
"div",
|
|
1197
|
+
{
|
|
1198
|
+
style: {
|
|
1199
|
+
position: "absolute",
|
|
1200
|
+
inset: 0,
|
|
1201
|
+
zIndex: 0,
|
|
1202
|
+
pointerEvents: "none",
|
|
1203
|
+
transform: "translateZ(0)"
|
|
1204
|
+
},
|
|
1205
|
+
children: n
|
|
1206
|
+
}
|
|
1207
|
+
) : null,
|
|
1208
|
+
/* @__PURE__ */ de(
|
|
1209
|
+
"canvas",
|
|
1210
|
+
{
|
|
1211
|
+
ref: E,
|
|
1212
|
+
"aria-hidden": "true",
|
|
1213
|
+
style: {
|
|
1214
|
+
position: "absolute",
|
|
1215
|
+
inset: 0,
|
|
1216
|
+
zIndex: 1,
|
|
1217
|
+
width: "100%",
|
|
1218
|
+
height: "100%",
|
|
1219
|
+
pointerEvents: "none",
|
|
1220
|
+
mixBlendMode: R.mode === "dom" ? "screen" : "normal"
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
),
|
|
1224
|
+
/* @__PURE__ */ de(
|
|
1225
|
+
"div",
|
|
1226
|
+
{
|
|
1227
|
+
style: {
|
|
1228
|
+
position: "relative",
|
|
1229
|
+
zIndex: 2
|
|
1230
|
+
},
|
|
1231
|
+
children: Xe
|
|
1232
|
+
}
|
|
1233
|
+
)
|
|
1234
|
+
] });
|
|
1235
|
+
}), Et = gt;
|
|
1236
|
+
export {
|
|
1237
|
+
gt as WaterDistortion,
|
|
1238
|
+
Et as WaterLayer
|
|
1239
|
+
};
|
|
1240
|
+
//# sourceMappingURL=water-distortion.js.map
|