@rippleflow/water-distortion 0.1.2 → 0.1.3

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.
@@ -1,16 +1,16 @@
1
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);
2
+ var Ve = (r, e, n) => e in r ? Ye(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
3
+ var f = (r, e, n) => Ve(r, typeof e != "symbol" ? e + "" : e, n);
4
4
  import { jsxs as qe, jsx as de } from "react/jsx-runtime";
5
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));
6
+ function h(r, e, n) {
7
+ return Math.min(n, Math.max(e, r));
8
8
  }
9
9
  function Ze(r, e) {
10
10
  return Math.hypot(e.x - r.x, e.y - r.y);
11
11
  }
12
- function O(r, e, t) {
13
- return r + (e - r) * t;
12
+ function O(r, e, n) {
13
+ return r + (e - r) * n;
14
14
  }
15
15
  const J = 24, C = 128, oe = 8, se = Math.PI * 2, fe = {
16
16
  causticGain: 0.1,
@@ -272,7 +272,8 @@ void main() {
272
272
  }
273
273
  `;
274
274
  class rt {
275
- constructor(e) {
275
+ constructor(e, n = () => {
276
+ }) {
276
277
  f(this, "gl");
277
278
  f(this, "isWebGL2");
278
279
  f(this, "canLinearFloat");
@@ -296,17 +297,17 @@ class rt {
296
297
  f(this, "wakeAUniforms", new Float32Array(J * 4));
297
298
  f(this, "wakeBUniforms", new Float32Array(J * 4));
298
299
  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(
300
+ this.canvas = e, this.requestRender = n;
301
+ const { gl: t, isWebGL2: i, canLinearFloat: a } = it(e);
302
+ this.gl = t, this.isWebGL2 = i, this.canLinearFloat = a, 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
303
  t.ARRAY_BUFFER,
303
304
  new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
304
305
  t.STATIC_DRAW
305
306
  ), 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
  }
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));
308
+ resize(e, n, t, i) {
309
+ this.cssWidth = Math.max(1, e), this.cssHeight = Math.max(1, n);
310
+ const a = Math.min(2, Math.max(1, t || 1)), l = Math.max(1, Math.round(this.cssWidth * a)), c = Math.max(1, Math.round(this.cssHeight * a));
310
311
  (this.canvas.width !== l || this.canvas.height !== c) && (this.canvas.width = l, this.canvas.height = c);
311
312
  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
313
  E === this.simWidth && _ === this.simHeight || (this.simWidth = E, this.simHeight = _, this.recreateState());
@@ -318,28 +319,28 @@ class rt {
318
319
  this.textureImage = e, this.textureNeedsUpload = !0;
319
320
  return;
320
321
  }
321
- const t = new Image();
322
- t.crossOrigin = "anonymous", t.onload = () => {
323
- this.textureSource === e && (this.textureImage = t, this.textureNeedsUpload = !0);
324
- }, t.onerror = () => {
322
+ const n = new Image();
323
+ n.crossOrigin = "anonymous", n.onload = () => {
324
+ this.textureSource === e && (this.textureImage = n, this.textureNeedsUpload = !0, this.requestRender());
325
+ }, n.onerror = () => {
325
326
  this.textureSource === e && (this.textureImage = void 0, this.textureReady = !1, this.textureNeedsUpload = !1);
326
- }, t.src = e;
327
+ }, n.src = e;
327
328
  }
328
- step(e, t, n) {
329
+ step(e, n, t) {
329
330
  if (!this.stateTextures || !this.framebuffers)
330
331
  return;
331
332
  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
+ 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, n, t), i.drawArrays(i.TRIANGLE_STRIP, 0, 4), i.bindFramebuffer(i.FRAMEBUFFER, null), this.readIndex = a;
333
334
  }
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));
335
+ render(e, n = 0) {
336
+ const t = this.gl;
337
+ this.stateTextures && (e.texture ? this.setTextureSource(e.texture) : this.setTextureSource(void 0), this.uploadTextureIfNeeded(e), t.useProgram(this.materialProgram.program), t.bindFramebuffer(t.FRAMEBUFFER, null), t.viewport(0, 0, this.canvas.width, this.canvas.height), t.clearColor(0, 0, 0, 0), t.clear(t.COLOR_BUFFER_BIT), !(e.mode !== "dom" && e.texture && !this.textureReady) && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.stateTextures[this.readIndex]), t.activeTexture(t.TEXTURE1), t.bindTexture(t.TEXTURE_2D, this.backgroundTexture), t.activeTexture(t.TEXTURE2), t.bindTexture(t.TEXTURE_2D, this.causticTexture), this.prepareQuad(this.materialProgram), this.setMaterialUniforms(e, n), t.drawArrays(t.TRIANGLE_STRIP, 0, 4)));
337
338
  }
338
339
  hasVisibleActivity() {
339
340
  if (!this.framebuffers)
340
341
  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);
342
+ const e = this.gl, n = this.framebuffers[this.readIndex], t = this.simWidth * this.simHeight * 4;
343
+ (!this.activityPixels || this.activityPixels.length !== t) && (this.activityPixels = new Float32Array(t)), e.bindFramebuffer(e.FRAMEBUFFER, n);
343
344
  try {
344
345
  e.readPixels(
345
346
  0,
@@ -363,26 +364,26 @@ class rt {
363
364
  const e = this.gl;
364
365
  if (this.framebuffers) {
365
366
  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);
367
+ for (const n of this.framebuffers)
368
+ e.bindFramebuffer(e.FRAMEBUFFER, n), e.clearColor(0, 0, 0, 1), e.clear(e.COLOR_BUFFER_BIT);
368
369
  }
369
370
  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
  }
371
372
  dispose() {
372
- var t, n;
373
+ var n, t;
373
374
  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
+ (n = this.stateTextures) == null || n.forEach((i) => e.deleteTexture(i)), (t = this.framebuffers) == null || t.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
  }
376
377
  recreateState() {
377
378
  var l, c;
378
379
  const e = this.gl;
379
380
  (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();
381
+ const n = this.createStateTexture(), t = this.createStateTexture(), i = this.createFramebuffer(n), a = this.createFramebuffer(t);
382
+ this.stateTextures = [n, t], this.framebuffers = [i, a], this.readIndex = 0, this.clear();
382
383
  }
383
384
  createStateTexture() {
384
- const e = this.gl, t = q(e.createTexture(), "WebGL texture");
385
- if (e.bindTexture(e.TEXTURE_2D, t), e.texParameteri(
385
+ const e = this.gl, n = q(e.createTexture(), "WebGL texture");
386
+ if (e.bindTexture(e.TEXTURE_2D, n), e.texParameteri(
386
387
  e.TEXTURE_2D,
387
388
  e.TEXTURE_MIN_FILTER,
388
389
  this.canLinearFloat ? e.LINEAR : e.NEAREST
@@ -391,16 +392,16 @@ class rt {
391
392
  e.TEXTURE_MAG_FILTER,
392
393
  this.canLinearFloat ? e.LINEAR : e.NEAREST
393
394
  ), 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,
395
+ const t = e;
396
+ t.texImage2D(
397
+ t.TEXTURE_2D,
397
398
  0,
398
- n.RGBA32F,
399
+ t.RGBA32F,
399
400
  this.simWidth,
400
401
  this.simHeight,
401
402
  0,
402
- n.RGBA,
403
- n.FLOAT,
403
+ t.RGBA,
404
+ t.FLOAT,
404
405
  null
405
406
  );
406
407
  } else
@@ -415,19 +416,19 @@ class rt {
415
416
  e.FLOAT,
416
417
  null
417
418
  );
418
- return t;
419
+ return n;
419
420
  }
420
421
  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,
422
+ const n = this.gl, t = q(n.createFramebuffer(), "WebGL framebuffer");
423
+ if (n.bindFramebuffer(n.FRAMEBUFFER, t), n.framebufferTexture2D(
424
+ n.FRAMEBUFFER,
425
+ n.COLOR_ATTACHMENT0,
426
+ n.TEXTURE_2D,
426
427
  e,
427
428
  0
428
- ), t.checkFramebufferStatus(t.FRAMEBUFFER) !== t.FRAMEBUFFER_COMPLETE)
429
+ ), n.checkFramebufferStatus(n.FRAMEBUFFER) !== n.FRAMEBUFFER_COMPLETE)
429
430
  throw new Error("WaterDistortion could not create a float simulation target.");
430
- return t.bindFramebuffer(t.FRAMEBUFFER, null), n;
431
+ return n.bindFramebuffer(n.FRAMEBUFFER, null), t;
431
432
  }
432
433
  initializeBackgroundTexture() {
433
434
  const e = this.gl;
@@ -460,71 +461,71 @@ class rt {
460
461
  uploadTextureIfNeeded(e) {
461
462
  if (e.mode === "dom" || !this.textureImage || !this.textureNeedsUpload && !at(this.textureImage))
462
463
  return;
463
- const t = this.gl;
464
+ const n = this.gl;
464
465
  try {
465
- t.bindTexture(t.TEXTURE_2D, this.backgroundTexture), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.texImage2D(
466
- t.TEXTURE_2D,
466
+ n.bindTexture(n.TEXTURE_2D, this.backgroundTexture), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, 1), n.texImage2D(
467
+ n.TEXTURE_2D,
467
468
  0,
468
- t.RGBA,
469
- t.RGBA,
470
- t.UNSIGNED_BYTE,
469
+ n.RGBA,
470
+ n.RGBA,
471
+ n.UNSIGNED_BYTE,
471
472
  this.textureImage
472
- ), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 0), this.textureReady = !0, this.textureNeedsUpload = !1;
473
+ ), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, 0), this.textureReady = !0, this.textureNeedsUpload = !1;
473
474
  } catch {
474
475
  this.textureReady = !1, this.textureNeedsUpload = !1;
475
476
  }
476
477
  }
477
478
  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);
479
+ const n = this.gl;
480
+ n.bindBuffer(n.ARRAY_BUFFER, this.quadBuffer), n.enableVertexAttribArray(e.position), n.vertexAttribPointer(e.position, 2, n.FLOAT, !1, 0, 0);
480
481
  }
481
- setSimulationUniforms(e, t, n) {
482
+ setSimulationUniforms(e, n, t) {
482
483
  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
484
  c.fill(0), s.fill(0), d.fill(0);
484
485
  for (let _ = 0; _ < l; _ += 1) {
485
486
  const m = e[E + _], v = _ * 4;
486
487
  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
  }
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
+ 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"), t), i.uniform1f(p(i, a, "u_damping"), n.damping), i.uniform1f(p(i, a, "u_stiffness"), n.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
  }
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"),
491
+ setMaterialUniforms(e, n) {
492
+ const t = this.gl, i = this.materialProgram.program, a = e.mode !== "dom";
493
+ t.uniform1i(p(t, i, "u_state"), 0), t.uniform1i(p(t, i, "u_background"), 1), t.uniform1i(p(t, i, "u_causticMap"), 2), t.uniform2f(p(t, i, "u_texel"), 1 / this.simWidth, 1 / this.simHeight), t.uniform1f(p(t, i, "u_domMode"), e.mode === "dom" ? 1 : 0), t.uniform1f(
494
+ p(t, i, "u_textureEnabled"),
494
495
  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
+ ), t.uniform1f(p(t, i, "u_normalScale"), e.normalScale), t.uniform1f(p(t, i, "u_refractionStrength"), e.refractionStrength), t.uniform1f(p(t, i, "u_specularIntensity"), e.specularIntensity), t.uniform1f(p(t, i, "u_crestIntensity"), e.crestIntensity), t.uniform1f(p(t, i, "u_causticIntensity"), e.causticIntensity), t.uniform1f(p(t, i, "u_time"), n % 1e3);
496
497
  }
497
498
  }
498
499
  function nt() {
499
500
  const r = new Uint8Array(C * C * 4);
500
501
  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;
502
+ for (let n = 0; n < C; n += 1) {
503
+ const t = (n + 0.5) / C, i = (e + 0.5) / C, a = Math.round(ce(t, i, 0) * 255), l = Math.round(ce(t, i, 11) * 255), c = Math.round(ce(t, i, 23) * 255), s = Math.round(ce(t, i, 37) * 255), d = (e * C + n) * 4;
503
504
  r[d] = a, r[d + 1] = l, r[d + 2] = c, r[d + 3] = s;
504
505
  }
505
506
  return r;
506
507
  }
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);
508
+ function ce(r, e, n) {
509
+ const t = Math.sin(se * (e * 2 + n * 0.013)) * 0.12 + Math.sin(se * (r * 3 + e + n * 0.021)) * 0.06, i = Math.cos(se * (r * 2 + n * 0.017)) * 0.12 + Math.sin(se * (e * 3 - r + n * 0.019)) * 0.06, a = r * oe + t, l = e * oe + i, c = Math.floor(a), s = Math.floor(l);
509
510
  let d = Number.POSITIVE_INFINITY, E = Number.POSITIVE_INFINITY, _ = 0, m = 0;
510
511
  for (let P = -1; P <= 1; P += 1)
511
512
  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
+ const k = c + U, B = s + P, M = Ie(k, oe), I = Ie(B, oe), z = k + 0.16 + me(M, I, n) * 0.68, N = B + 0.16 + me(M, I, n + 1) * 0.68, D = Math.hypot(a - z, l - N);
513
514
  D < d ? (E = d, d = D, _ = M, m = I) : D < E && (E = D);
514
515
  }
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
+ 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, n + 2) * 0.26, H = A * A * 0.58 + w * 0.34;
516
517
  return We(Math.pow(H * W, 1.12));
517
518
  }
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);
519
+ function me(r, e, n) {
520
+ const t = Math.sin(r * 127.1 + e * 311.7 + n * 74.7) * 43758.5453123;
521
+ return t - Math.floor(t);
521
522
  }
522
523
  function Ie(r, e) {
523
524
  return (r % e + e) % e;
524
525
  }
525
- function Fe(r, e, t) {
526
- const n = We((t - r) / (e - r));
527
- return n * n * (3 - n * 2);
526
+ function Fe(r, e, n) {
527
+ const t = We((n - r) / (e - r));
528
+ return t * t * (3 - t * 2);
528
529
  }
529
530
  function We(r) {
530
531
  return Math.min(1, Math.max(0, r));
@@ -537,33 +538,33 @@ function it(r) {
537
538
  stencil: !1,
538
539
  premultipliedAlpha: !1,
539
540
  preserveDrawingBuffer: !1
540
- }, t = r.getContext("webgl2", e);
541
- if (t) {
542
- if (!t.getExtension("EXT_color_buffer_float"))
541
+ }, n = r.getContext("webgl2", e);
542
+ if (n) {
543
+ if (!n.getExtension("EXT_color_buffer_float"))
543
544
  throw new Error("WaterDistortion requires float render targets.");
544
545
  return {
545
- gl: t,
546
+ gl: n,
546
547
  isWebGL2: !0,
547
- canLinearFloat: !!t.getExtension("OES_texture_float_linear")
548
+ canLinearFloat: !!n.getExtension("OES_texture_float_linear")
548
549
  };
549
550
  }
550
- const n = r.getContext("webgl", e) || r.getContext(
551
+ const t = r.getContext("webgl", e) || r.getContext(
551
552
  "experimental-webgl",
552
553
  e
553
554
  );
554
- if (!n)
555
+ if (!t)
555
556
  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
+ if (!t.getExtension("OES_texture_float") || !t.getExtension("WEBGL_color_buffer_float") && !t.getExtension("EXT_color_buffer_float"))
557
558
  throw new Error("WaterDistortion requires float texture support.");
558
559
  return {
559
- gl: n,
560
+ gl: t,
560
561
  isWebGL2: !1,
561
- canLinearFloat: !!n.getExtension("OES_texture_float_linear")
562
+ canLinearFloat: !!t.getExtension("OES_texture_float_linear")
562
563
  };
563
564
  }
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)) {
565
+ function Le(r, e, n) {
566
+ const t = ke(r, r.VERTEX_SHADER, e), i = ke(r, r.FRAGMENT_SHADER, n), a = q(r.createProgram(), "WebGL program");
567
+ if (r.attachShader(a, t), r.attachShader(a, i), r.linkProgram(a), r.deleteShader(t), r.deleteShader(i), !r.getProgramParameter(a, r.LINK_STATUS)) {
567
568
  const c = r.getProgramInfoLog(a) || "Unknown shader link error.";
568
569
  throw r.deleteProgram(a), new Error(c);
569
570
  }
@@ -572,19 +573,19 @@ function Le(r, e, t) {
572
573
  throw new Error("WaterDistortion could not bind its quad attribute.");
573
574
  return { program: a, position: l };
574
575
  }
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);
576
+ function ke(r, e, n) {
577
+ const t = q(r.createShader(e), "WebGL shader");
578
+ if (r.shaderSource(t, n), r.compileShader(t), !r.getShaderParameter(t, r.COMPILE_STATUS)) {
579
+ const i = r.getShaderInfoLog(t) || "Unknown shader compile error.";
580
+ throw r.deleteShader(t), new Error(i);
580
581
  }
581
- return n;
582
+ return t;
582
583
  }
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;
584
+ function p(r, e, n) {
585
+ const t = r.getUniformLocation(e, n);
586
+ if (!t)
587
+ throw new Error(`WaterDistortion could not bind uniform ${n}.`);
588
+ return t;
588
589
  }
589
590
  function q(r, e) {
590
591
  if (!r)
@@ -594,18 +595,18 @@ function q(r, e) {
594
595
  function at(r) {
595
596
  return typeof HTMLCanvasElement < "u" && r instanceof HTMLCanvasElement || typeof HTMLVideoElement < "u" && r instanceof HTMLVideoElement || typeof OffscreenCanvas < "u" && r instanceof OffscreenCanvas;
596
597
  }
597
- function ot(r, e, t, n = Je) {
598
- const i = Math.max(0, Math.floor(e)), a = Math.max(0, Math.floor(t));
598
+ function ot(r, e, n, t = Je) {
599
+ const i = Math.max(0, Math.floor(e)), a = Math.max(0, Math.floor(n));
599
600
  if (i === 0 || a === 0)
600
601
  return !1;
601
602
  const l = (c, s) => r[(s * i + c) * 4] ?? 0;
602
603
  for (let c = 0; c < a; c += 1)
603
604
  for (let s = 0; s < i; s += 1) {
604
605
  const d = (c * i + s) * 4, E = r[d] ?? 0, _ = r[d + 1] ?? 0;
605
- if (E < -n.trough || Math.abs(_) > n.velocity)
606
+ if (E < -t.trough || Math.abs(_) > t.velocity)
606
607
  return !0;
607
608
  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
+ if (W > t.gradient || H > t.curvature)
609
610
  return !0;
610
611
  }
611
612
  return !1;
@@ -665,8 +666,8 @@ function ge(r) {
665
666
  )
666
667
  };
667
668
  }
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;
669
+ function Ue(r, e, n = r.timeStamp) {
670
+ const t = typeof r.getCoalescedEvents == "function" ? r.getCoalescedEvents() : [], i = t.length > 0 ? t : [r], a = n - r.timeStamp;
670
671
  return i.map((l) => ({
671
672
  x: l.clientX - e.left,
672
673
  y: l.clientY - e.top,
@@ -692,14 +693,14 @@ class ct {
692
693
  }
693
694
  addSample(e) {
694
695
  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);
696
+ const n = this.clampSample(e), t = this.previous;
697
+ if (!t)
698
+ return this.previous = n, this.disturbances;
699
+ n.time <= t.time && (n.time = t.time + 0.01);
700
+ const i = this.smoothSample(t, n), a = Ze(t, i);
700
701
  if (a < 0.35)
701
702
  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
+ const l = a / Math.max(0.01, i.time - t.time), c = h(1 - this.options.cursorSmoothing, 0.12, 1);
703
704
  this.smoothedVelocity = O(
704
705
  this.smoothedVelocity,
705
706
  l,
@@ -713,8 +714,8 @@ class ct {
713
714
  const E = d / s, _ = (d + 1) / s;
714
715
  this.disturbances.push(
715
716
  ve(
716
- De(n, i, E),
717
- De(n, i, _),
717
+ De(t, i, E),
718
+ De(t, i, _),
718
719
  this.smoothedVelocity,
719
720
  this.options
720
721
  )
@@ -729,18 +730,18 @@ class ct {
729
730
  time: e.time
730
731
  };
731
732
  }
732
- smoothSample(e, t) {
733
- const n = 1 - this.options.cursorSmoothing;
733
+ smoothSample(e, n) {
734
+ const t = 1 - this.options.cursorSmoothing;
734
735
  return {
735
- x: O(e.x, t.x, n),
736
- y: O(e.y, t.y, n),
737
- time: t.time
736
+ x: O(e.x, n.x, t),
737
+ y: O(e.y, n.y, t),
738
+ time: n.time
738
739
  };
739
740
  }
740
741
  }
741
- function ve(r, e, t, n) {
742
- const i = ge(n), a = h(
743
- t * i.velocityScale / i.velocityClamp,
742
+ function ve(r, e, n, t) {
743
+ const i = ge(t), a = h(
744
+ n * i.velocityScale / i.velocityClamp,
744
745
  0,
745
746
  1
746
747
  ), 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);
@@ -758,16 +759,16 @@ function ve(r, e, t, n) {
758
759
  velocity: a
759
760
  };
760
761
  }
761
- function De(r, e, t) {
762
+ function De(r, e, n) {
762
763
  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)
764
+ x: O(r.x, e.x, n),
765
+ y: O(r.y, e.y, n),
766
+ time: O(r.time, e.time, n)
766
767
  };
767
768
  }
768
769
  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);
770
+ const e = h(r, 0.85, 0.998), n = Math.ceil(Math.log(0.012) / Math.log(e));
771
+ return h(n * (1e3 / 60), 900, 5200);
771
772
  }
772
773
  const x = {
773
774
  mode: "texture",
@@ -898,48 +899,48 @@ function ft(r) {
898
899
  pauseKey: r.pauseKey || x.pauseKey
899
900
  };
900
901
  }
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 = {
902
+ function Ce(r, e, n) {
903
+ const t = h(r.x, 0, 1) * n.width, i = h(r.y, 0, 1) * n.height, a = Math.max(0.5, e.interactionRadius * 0.08), l = e.velocityClamp / e.velocityScale, c = {
903
904
  ...e,
904
- width: t.width,
905
- height: t.height,
905
+ width: n.width,
906
+ height: n.height,
906
907
  wakeLength: e.interactionRadius * 1.5
907
908
  };
908
909
  return [
909
910
  ve(
910
- { x: n - a, y: i },
911
- { x: n + a, y: i },
911
+ { x: t - a, y: i },
912
+ { x: t + a, y: i },
912
913
  l,
913
914
  c
914
915
  ),
915
916
  ve(
916
- { x: n, y: i - a },
917
- { x: n, y: i + a },
917
+ { x: t, y: i - a },
918
+ { x: t, y: i + a },
918
919
  l,
919
920
  c
920
921
  )
921
922
  ];
922
923
  }
923
924
  function mt(r) {
924
- const [e, t] = je(!1);
925
+ const [e, n] = je(!1);
925
926
  return V(() => {
926
927
  if (!r || typeof window > "u" || !window.matchMedia) {
927
- t(!1);
928
+ n(!1);
928
929
  return;
929
930
  }
930
- const n = window.matchMedia("(prefers-reduced-motion: reduce)");
931
- t(n.matches);
931
+ const t = window.matchMedia("(prefers-reduced-motion: reduce)");
932
+ n(t.matches);
932
933
  const i = (a) => {
933
- t(a.matches);
934
+ n(a.matches);
934
935
  };
935
- return n.addEventListener("change", i), () => {
936
- n.removeEventListener("change", i);
936
+ return t.addEventListener("change", i), () => {
937
+ t.removeEventListener("change", i);
937
938
  };
938
939
  }, [r]), e;
939
940
  }
940
- const gt = $e(function(e, t) {
941
+ const gt = $e(function(e, n) {
941
942
  const {
942
- underlay: n,
943
+ underlay: t,
943
944
  children: i,
944
945
  foreground: a,
945
946
  className: l,
@@ -952,7 +953,7 @@ const gt = $e(function(e, t) {
952
953
  s === "respect"
953
954
  ), ue = s === "disable" || s === "respect" && Ne, Xe = a ?? i;
954
955
  g.current = R, Qe(
955
- t,
956
+ n,
956
957
  () => ({
957
958
  triggerRipple(S) {
958
959
  B.current || M.current || H.current(
@@ -1090,7 +1091,9 @@ const gt = $e(function(e, t) {
1090
1091
  };
1091
1092
  w.current = le;
1092
1093
  try {
1093
- b = new rt(K), _.current = b, b.setTextureSource(g.current.texture);
1094
+ b = new rt(K, () => {
1095
+ w.current();
1096
+ }), _.current = b, b.setTextureSource(g.current.texture);
1094
1097
  } catch {
1095
1098
  return K.style.display = "none", _.current = null, w.current = () => {
1096
1099
  }, () => {
@@ -1192,7 +1195,7 @@ const gt = $e(function(e, t) {
1192
1195
  isolation: "isolate"
1193
1196
  };
1194
1197
  return /* @__PURE__ */ qe("div", { ref: d, className: l, style: Ge, children: [
1195
- n ? /* @__PURE__ */ de(
1198
+ t ? /* @__PURE__ */ de(
1196
1199
  "div",
1197
1200
  {
1198
1201
  style: {
@@ -1202,7 +1205,7 @@ const gt = $e(function(e, t) {
1202
1205
  pointerEvents: "none",
1203
1206
  transform: "translateZ(0)"
1204
1207
  },
1205
- children: n
1208
+ children: t
1206
1209
  }
1207
1210
  ) : null,
1208
1211
  /* @__PURE__ */ de(