@jayf0x/fluidity-js 0.2.9 → 0.3.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/index.js CHANGED
@@ -1,1521 +1,24 @@
1
- import { forwardRef as be, useEffect as B, useImperativeHandle as Te, useRef as I } from "react";
2
- import { jsx as ye } from "react/jsx-runtime";
3
- var De = {
4
- densityDissipation: [0.94, 1],
5
- velocityDissipation: [0.9, 0.999],
6
- splatRadius: [1e-3, 0.04],
7
- splatForce: [0.1, 5],
8
- specularExp: [0.1, 10],
9
- shine: [0, 0.15],
10
- warpStrength: [1e-3, 0.1]
1
+ import { forwardRef as e, useEffect as t, useImperativeHandle as n, useRef as r } from "react";
2
+ import { jsx as i } from "react/jsx-runtime";
3
+ //#region src/core/config.ts
4
+ var a = {
5
+ densityDissipation: [.94, 1],
6
+ velocityDissipation: [.9, .999],
7
+ splatRadius: [.001, .04],
8
+ splatForce: [.1, 5],
9
+ specularExp: [.1, 10],
10
+ shine: [0, .15],
11
+ warpStrength: [.001, .1]
11
12
  };
12
- function G(r) {
13
- const e = { ...r };
14
- for (const [t, [n, i]] of Object.entries(De)) {
15
- const s = r[t];
16
- s !== void 0 && s >= 0 && s <= 1 && (e[t] = n + (i - n) * s);
17
- }
18
- return e;
19
- }
20
- var we = {
21
- densityDissipation: 0.83,
22
- velocityDissipation: 0.91,
23
- pressureIterations: 1,
24
- curl: 0,
25
- splatRadius: 0.1,
26
- splatForce: 0.08,
27
- refraction: 1,
28
- specularExp: 0,
29
- shine: 0,
30
- waterColor: "#000000",
31
- glowColor: "#b3d9ff",
32
- algorithm: "aurora",
33
- warpStrength: 0.04
34
- }, ve = {
35
- ...we,
36
- densityDissipation: 0.9,
37
- velocityDissipation: 0.9,
38
- pressureIterations: 3,
39
- curl: 0.2,
40
- splatRadius: 0.2,
41
- splatForce: 0.5,
42
- refraction: 0.2,
43
- specularExp: 0.01,
44
- shine: 0.5,
45
- waterColor: "#090017",
46
- glowColor: "#b04721"
47
- }, W = {
48
- dpr: typeof window < "u" ? 1 / (window.devicePixelRatio || 1) : 1,
49
- sim: 0.5
50
- }, Se = {
51
- backgroundColor: "#0a0a0a",
52
- backgroundSize: "cover",
53
- mouseEnabled: !0,
54
- workerEnabled: !0
55
- }, A = {
56
- ...Se,
57
- effect: 0,
58
- imageSize: "cover"
59
- }, V = {
60
- ...Se,
61
- fontSize: 100,
62
- color: "#ffffff",
63
- fontFamily: "sans-serif",
64
- fontWeight: 900
65
- }, _e = {
66
- calm: {
67
- densityDissipation: 0.98,
68
- velocityDissipation: 0.81,
69
- curl: 1e-4,
70
- splatRadius: 0.05,
71
- splatForce: 0.08,
72
- refraction: 0.15,
73
- shine: 0.03,
74
- glowColor: "#99d9ff",
75
- waterColor: "#00050d"
76
- },
77
- sand: {
78
- densityDissipation: 0.95,
79
- velocityDissipation: 0.81,
80
- curl: 1,
81
- splatRadius: 0.23,
82
- splatForce: 0.16,
83
- refraction: 0.8,
84
- specularExp: 0,
85
- shine: 0.33,
86
- glowColor: "#070707",
87
- waterColor: "#735420"
88
- },
89
- wave: {
90
- densityDissipation: 0.9,
91
- velocityDissipation: 0.2,
92
- curl: 0.2,
93
- splatRadius: 0.1,
94
- splatForce: 0.22,
95
- refraction: 0.35,
96
- shine: 0.2,
97
- glowColor: "#80ccff",
98
- waterColor: "#000308"
99
- },
100
- neon: {
101
- densityDissipation: 0.75,
102
- velocityDissipation: 0.3,
103
- curl: 0.05,
104
- splatRadius: 0.18,
105
- splatForce: 0.29,
106
- refraction: 0.25,
107
- specularExp: 0.04,
108
- shine: 0.93,
109
- glowColor: "#ff33cc",
110
- waterColor: "#0d0014"
111
- },
112
- smoke: {
113
- densityDissipation: 0.93,
114
- velocityDissipation: 0.71,
115
- curl: 0.04,
116
- splatRadius: 0.21,
117
- splatForce: 0.14,
118
- refraction: 0.08,
119
- shine: 0,
120
- glowColor: "#808080",
121
- waterColor: "#0f0f0f"
122
- }
123
- };
124
- function te(r) {
125
- if (Array.isArray(r))
126
- return r;
127
- const e = r.slice(1, 7);
128
- return e.length === 3 ? [
129
- parseInt(e[0] + e[0], 16) / 255,
130
- parseInt(e[1] + e[1], 16) / 255,
131
- parseInt(e[2] + e[2], 16) / 255
132
- ] : [
133
- parseInt(e.slice(0, 2), 16) / 255,
134
- parseInt(e.slice(2, 4), 16) / 255,
135
- parseInt(e.slice(4, 6), 16) / 255
136
- ];
137
- }
138
- function ee(r = {}, e, t = we) {
139
- return {
140
- ...e ? {
141
- ...t,
142
- ..._e[e]
143
- } : t,
144
- ...r
145
- };
146
- }
147
- function N(r, e, t, n, i = "cover") {
148
- let s;
149
- i === "cover" ? s = Math.max(t / r, n / e) : i === "contain" ? s = Math.min(t / r, n / e) : typeof i == "string" && i.endsWith("%") ? s = Math.min(t / r, n / e) * (parseFloat(i) / 100) : typeof i == "string" && i.endsWith("px") ? s = parseFloat(i) / Math.max(r, e) : typeof i == "number" ? s = i : s = Math.max(t / r, n / e);
150
- const a = r * s, c = e * s;
151
- return {
152
- x: (t - a) / 2,
153
- y: (n - c) / 2,
154
- drawW: a,
155
- drawH: c
156
- };
157
- }
158
- function Ce(r, e, t, n, i = null, s = "cover") {
159
- const { text: a, fontSize: c, color: x, fontFamily: u = "sans-serif", fontWeight: v = 900 } = n, l = new OffscreenCanvas(e, t), o = l.getContext("2d");
160
- ((p) => {
161
- if (i) {
162
- o.clearRect(0, 0, e, t), o.fillStyle = "black", o.fillRect(0, 0, e, t);
163
- const { x: h, y: g, drawW: T, drawH: R } = N(i.width, i.height, e, t, s);
164
- o.drawImage(i, h, g, T, R);
165
- } else
166
- o.fillStyle = "black", o.fillRect(0, 0, e, t);
167
- o.fillStyle = p, o.font = `${v} ${c}px ${u}`, o.textAlign = "center", o.textBaseline = "middle", o.fillText(a, e / 2, t / 2);
168
- })(x);
169
- const m = J(r, l);
170
- o.fillStyle = "black", o.fillRect(0, 0, e, t), o.fillStyle = "white", o.font = `${v} ${c}px ${u}`, o.textAlign = "center", o.textBaseline = "middle", o.fillText(a, e / 2, t / 2);
171
- const d = J(r, l);
172
- return {
173
- backgroundTex: m,
174
- obstacleTex: d,
175
- coverageTex: d
176
- };
177
- }
178
- function Be(r, e, t, n, i = 0, s = "cover", a = null, c = "cover") {
179
- const x = new OffscreenCanvas(t, n), u = x.getContext("2d"), { x: v, y: l, drawW: o, drawH: f } = N(e.width, e.height, t, n, s);
180
- if (u.clearRect(0, 0, t, n), u.fillStyle = "black", u.fillRect(0, 0, t, n), a) {
181
- const { x: p, y: h, drawW: g, drawH: T } = N(a.width, a.height, t, n, c);
182
- u.filter = `brightness(${i}) blur(8px)`, u.drawImage(a, p, h, g, T), u.filter = "none";
183
- }
184
- u.drawImage(e, v, l, o, f);
185
- const m = J(r, x);
186
- u.clearRect(0, 0, t, n), u.fillStyle = "black", u.fillRect(0, 0, t, n), u.filter = `brightness(${i}) blur(8px)`, u.drawImage(e, v, l, o, f), u.filter = "none";
187
- const d = J(r, x);
188
- return u.clearRect(0, 0, t, n), u.fillStyle = "black", u.fillRect(0, 0, t, n), u.fillStyle = "white", u.fillRect(Math.max(0, v), Math.max(0, l), Math.min(o, t - Math.max(0, v)), Math.min(f, n - Math.max(0, l))), {
189
- backgroundTex: m,
190
- obstacleTex: d,
191
- coverageTex: J(r, x)
192
- };
193
- }
194
- function J(r, e) {
195
- const t = r.createTexture();
196
- return r.bindTexture(r.TEXTURE_2D, t), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, !0), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, r.RGBA, r.UNSIGNED_BYTE, e), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), t;
197
- }
198
- function Oe(r, e, t, n, i = null, s = "cover") {
199
- const { text: a, fontSize: c, color: x, fontFamily: u = "sans-serif", fontWeight: v = 900 } = n, l = new OffscreenCanvas(e, t), o = l.getContext("2d");
200
- ((p) => {
201
- if (i) {
202
- o.clearRect(0, 0, e, t), o.fillStyle = "black", o.fillRect(0, 0, e, t);
203
- const { x: h, y: g, drawW: T, drawH: R } = N(i.width, i.height, e, t, s);
204
- o.drawImage(i, h, g, T, R);
205
- } else
206
- o.fillStyle = "black", o.fillRect(0, 0, e, t);
207
- o.fillStyle = p, o.font = `${v} ${c}px ${u}`, o.textAlign = "center", o.textBaseline = "middle", o.fillText(a, e / 2, t / 2);
208
- })(x);
209
- const m = Z(r, l, e, t);
210
- o.fillStyle = "black", o.fillRect(0, 0, e, t), o.fillStyle = "white", o.font = `${v} ${c}px ${u}`, o.textAlign = "center", o.textBaseline = "middle", o.fillText(a, e / 2, t / 2);
211
- const d = Z(r, l, e, t);
212
- return {
213
- backgroundTex: m,
214
- backgroundView: m.createView(),
215
- obstacleTex: d,
216
- obstacleView: d.createView(),
217
- coverageTex: d,
218
- coverageView: d.createView(),
219
- sharedCoverage: !0
220
- };
221
- }
222
- function Ve(r, e, t, n, i = 0, s = "cover", a = null, c = "cover") {
223
- const x = new OffscreenCanvas(t, n), u = x.getContext("2d"), { x: v, y: l, drawW: o, drawH: f } = N(e.width, e.height, t, n, s);
224
- if (u.clearRect(0, 0, t, n), u.fillStyle = "black", u.fillRect(0, 0, t, n), a) {
225
- const { x: h, y: g, drawW: T, drawH: R } = N(a.width, a.height, t, n, c);
226
- u.filter = `brightness(${i}) blur(8px)`, u.drawImage(a, h, g, T, R), u.filter = "none";
227
- }
228
- u.drawImage(e, v, l, o, f);
229
- const m = Z(r, x, t, n);
230
- u.clearRect(0, 0, t, n), u.fillStyle = "black", u.fillRect(0, 0, t, n), u.filter = `brightness(${i}) blur(8px)`, u.drawImage(e, v, l, o, f), u.filter = "none";
231
- const d = Z(r, x, t, n);
232
- u.clearRect(0, 0, t, n), u.fillStyle = "black", u.fillRect(0, 0, t, n), u.fillStyle = "white", u.fillRect(Math.max(0, v), Math.max(0, l), Math.min(o, t - Math.max(0, v)), Math.min(f, n - Math.max(0, l)));
233
- const p = Z(r, x, t, n);
234
- return {
235
- backgroundTex: m,
236
- backgroundView: m.createView(),
237
- obstacleTex: d,
238
- obstacleView: d.createView(),
239
- coverageTex: p,
240
- coverageView: p.createView(),
241
- sharedCoverage: !1
242
- };
243
- }
244
- function Z(r, e, t, n) {
245
- const i = r.createTexture({
246
- size: [t, n],
247
- format: "rgba8unorm",
248
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
249
- });
250
- return r.queue.copyExternalImageToTexture({ source: e }, { texture: i }, [t, n]), i;
251
- }
252
- async function ce(r) {
253
- const e = await fetch(r);
254
- if (!e.ok)
255
- throw new Error(`Failed to fetch image: ${r} (${e.status})`);
256
- const t = await e.blob();
257
- return createImageBitmap(t);
258
- }
259
- var z = () => {
260
- }, F = `precision highp float;
261
- attribute vec2 aPosition;
262
- varying vec2 vUv;
263
- varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
264
- uniform vec2 texelSize;
265
- void main () {
266
- vUv = aPosition * 0.5 + 0.5;
267
- vL = vUv - vec2(texelSize.x, 0.0);
268
- vR = vUv + vec2(texelSize.x, 0.0);
269
- vT = vUv + vec2(0.0, texelSize.y);
270
- vB = vUv - vec2(0.0, texelSize.y);
271
- gl_Position = vec4(aPosition, 0.0, 1.0);
272
- }`, Fe = `precision highp float;
273
- varying vec2 vUv;
274
- uniform sampler2D uVelocity;
275
- uniform sampler2D uSource;
276
- uniform sampler2D uObstacle;
277
- uniform vec2 texelSize;
278
- uniform float dt;
279
- uniform float dissipation;
280
- void main () {
281
- float obs = texture2D(uObstacle, vUv).r;
282
- vec2 coord = vUv - dt * texture2D(uVelocity, vUv).xy * texelSize;
283
-
284
-
285
-
286
- gl_FragColor = dissipation * texture2D(uSource, coord) * (1.0 - obs);
287
- }`, Le = `precision highp float;
288
- varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
289
- uniform sampler2D uVelocity;
290
- uniform sampler2D uObstacle;
291
- void main () {
292
- float L = texture2D(uVelocity, vL).x * (1.0 - texture2D(uObstacle, vL).r);
293
- float R = texture2D(uVelocity, vR).x * (1.0 - texture2D(uObstacle, vR).r);
294
- float T = texture2D(uVelocity, vT).y * (1.0 - texture2D(uObstacle, vT).r);
295
- float B = texture2D(uVelocity, vB).y * (1.0 - texture2D(uObstacle, vB).r);
296
- gl_FragColor = vec4(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);
297
- }`, Pe = `precision highp float;
298
- varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
299
- uniform sampler2D uPressure;
300
- uniform sampler2D uDivergence;
301
- uniform sampler2D uObstacle;
302
- void main () {
303
- float C = texture2D(uPressure, vUv).x;
304
- float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);
305
- float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);
306
- float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);
307
- float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);
308
- float div = texture2D(uDivergence, vUv).x;
309
- gl_FragColor = vec4((L + R + B + T - div) * 0.25, 0.0, 0.0, 1.0);
310
- }`, Ae = `precision highp float;
311
- varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
312
- uniform sampler2D uPressure;
313
- uniform sampler2D uVelocity;
314
- uniform sampler2D uObstacle;
315
- void main () {
316
- float obs = texture2D(uObstacle, vUv).r;
317
- float C = texture2D(uPressure, vUv).x;
318
- float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);
319
- float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);
320
- float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);
321
- float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);
322
- vec2 vel = (texture2D(uVelocity, vUv).xy - vec2(R - L, T - B)) * (1.0 - obs);
323
- gl_FragColor = vec4(vel, 0.0, 1.0);
324
- }`, Me = `precision highp float;
325
- varying vec2 vUv;
326
- uniform sampler2D uTarget;
327
- uniform float aspectRatio;
328
- uniform vec3 color;
329
- uniform vec2 point;
330
- uniform float radius;
331
- void main () {
332
- vec2 p = vUv - point.xy;
333
- p.x *= aspectRatio;
334
- vec3 splat = exp(-dot(p, p) / radius) * color;
335
- gl_FragColor = vec4(texture2D(uTarget, vUv).xyz + splat, 1.0);
336
- }`, ze = `precision highp float;
337
- varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
338
- uniform sampler2D uVelocity;
339
- void main () {
340
- float L = texture2D(uVelocity, vL).y;
341
- float R = texture2D(uVelocity, vR).y;
342
- float T = texture2D(uVelocity, vT).x;
343
- float B = texture2D(uVelocity, vB).x;
344
- gl_FragColor = vec4(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);
345
- }`, Xe = `precision highp float;
346
- varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
347
- uniform sampler2D uVelocity;
348
- uniform sampler2D uCurl;
349
- uniform float curl;
350
- uniform float dt;
351
- void main () {
352
- float L = texture2D(uCurl, vL).x;
353
- float R = texture2D(uCurl, vR).x;
354
- float T = texture2D(uCurl, vT).x;
355
- float B = texture2D(uCurl, vB).x;
356
- float C = texture2D(uCurl, vUv).x;
357
- vec2 force = 0.5 * vec2(abs(T) - abs(B), abs(R) - abs(L));
358
- force /= length(force) + 0.0001;
359
- force *= curl * 30.0 * C;
360
- gl_FragColor = vec4(texture2D(uVelocity, vUv).xy + force * dt, 0.0, 1.0);
361
- }`, ke = `precision highp float;
362
- varying vec2 vUv;
363
- uniform sampler2D uTexture;
364
- uniform sampler2D uObstacle;
365
- uniform sampler2D uBackground;
366
- uniform sampler2D uCoverage;
367
- uniform sampler2D uVelocity;
368
- uniform vec2 texelSize;
369
- uniform vec3 uWaterColor;
370
- uniform vec3 uGlowColor;
371
- uniform float uRefraction;
372
- uniform float uSpecularExp;
373
- uniform float uShine;
374
- uniform float uWarpStrength;
375
- uniform int uAlgorithm;
376
- uniform int uEnableAlpha;
377
- void main () {
378
- float obs = texture2D(uObstacle, vUv).r;
379
-
380
-
381
- float density = max(texture2D(uTexture, vUv).r, 0.0) * (1.0 - obs);
382
- float coverage = texture2D(uCoverage, vUv).r;
383
-
384
-
385
-
386
-
387
- float sx = texelSize.x * 6.0, sy = texelSize.y * 6.0;
388
- float d00 = max(texture2D(uTexture, vUv + vec2(-sx, -sy)).r, 0.0);
389
- float d10 = max(texture2D(uTexture, vUv + vec2(0.0, -sy)).r, 0.0);
390
- float d20 = max(texture2D(uTexture, vUv + vec2( sx, -sy)).r, 0.0);
391
- float d01 = max(texture2D(uTexture, vUv + vec2(-sx, 0.0)).r, 0.0);
392
- float d21 = max(texture2D(uTexture, vUv + vec2( sx, 0.0)).r, 0.0);
393
- float d02 = max(texture2D(uTexture, vUv + vec2(-sx, sy)).r, 0.0);
394
- float d12 = max(texture2D(uTexture, vUv + vec2(0.0, sy)).r, 0.0);
395
- float d22 = max(texture2D(uTexture, vUv + vec2( sx, sy)).r, 0.0);
396
- float gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);
397
- float gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);
398
- vec3 normal = normalize(vec3(gx, gy, 1.2));
399
- vec3 lightDir = normalize(vec3(0.5, 1.0, 0.5));
400
- vec3 halfV = normalize(lightDir + vec3(0.0, 0.0, 1.0));
401
-
402
-
403
- float specDen = density * min(density * 5.0, 1.0);
404
- float spec = pow(max(dot(normal, halfV), 0.0), uSpecularExp) * uShine * specDen;
405
-
406
-
407
-
408
- vec3 bgRaw = texture2D(uBackground, vUv).rgb;
409
- vec3 bg = mix(uWaterColor, bgRaw, coverage);
410
- vec3 color = bg;
411
- if (uAlgorithm == 1) {
412
-
413
-
414
- vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 3.0, 0.0, 1.0);
415
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);
416
- color = refrBg + spec * uGlowColor * 2.5;
417
- color = mix(color, bg * 0.6, obs * 0.3);
418
- } else if (uAlgorithm == 2) {
419
-
420
-
421
- float inkD = min(density * 4.0, 1.0);
422
- vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 0.4, 0.0, 1.0);
423
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);
424
- color = mix(refrBg, uWaterColor + spec * uGlowColor, inkD);
425
- color = mix(color, bg * 0.5, obs * 0.15);
426
- } else if (uAlgorithm == 3) {
427
-
428
-
429
- vec2 vel = texture2D(uVelocity, vUv).xy;
430
- float velMag = clamp(length(vel) * 20.0, 0.0, 1.0);
431
- vec2 warpUv = clamp(vUv + vel * uWarpStrength, 0.0, 1.0);
432
- vec3 warpBg = mix(uWaterColor, texture2D(uBackground, warpUv).rgb, coverage);
433
- color = mix(bg, warpBg, velMag * (1.0 - obs));
434
- color += spec * uGlowColor * velMag * 1.5;
435
- color += uWaterColor * density * 0.3;
436
- color = mix(color, bg * 0.5, obs * 0.2);
437
- } else if (uAlgorithm == 4) {
438
-
439
-
440
- vec2 rippleUv = clamp(vUv + normal.xy * uRefraction * density * 6.0, 0.0, 1.0);
441
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, rippleUv, 1.0 - obs)).rgb, coverage);
442
- float fresnel = pow(clamp(1.0 - dot(normal, vec3(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;
443
- color = refrBg;
444
- color += fresnel * uGlowColor * 2.0;
445
- color += spec * uGlowColor * density * 2.0;
446
- color = mix(color, bg * 0.5, obs * 0.2);
447
- } else {
448
-
449
-
450
- vec2 refrUv = vUv + normal.xy * uRefraction * density;
451
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);
452
- color = mix(refrBg, uWaterColor, min(density * 1.5, 0.8));
453
- color += spec * uGlowColor;
454
- color = mix(color, bg * 0.5, obs * 0.2);
455
- }
456
-
457
-
458
- float alpha = clamp(max(density * 1.5, coverage), 0.0, 1.0);
459
- if (uEnableAlpha == 1) {
460
- gl_FragColor = vec4(color * alpha, alpha);
461
- } else {
462
- gl_FragColor = vec4(color, 1.0);
463
- }
464
- }`;
465
- function Ie(r, e = !0) {
466
- const t = {
467
- alpha: e,
468
- depth: !1,
469
- stencil: !1,
470
- antialias: !0,
471
- preserveDrawingBuffer: !1
472
- };
473
- let n = r.getContext("webgl2", t);
474
- const i = !!n;
475
- i || (n = r.getContext("webgl", t), n.getExtension("EXT_color_buffer_half_float"));
476
- const s = i ? null : n.getExtension("OES_texture_half_float"), a = i ? n.HALF_FLOAT : s.HALF_FLOAT_OES;
477
- return n.getExtension("EXT_color_buffer_float"), n.getExtension("OES_texture_half_float_linear"), {
478
- type: i ? "webgl2" : "webgl1",
479
- gl: n,
480
- isWebGL2: i,
481
- ext: {
482
- internalFormat: i ? n.RGBA16F : n.RGBA,
483
- format: n.RGBA,
484
- type: a
485
- }
486
- };
487
- }
488
- async function Ge(r, e = !0) {
489
- if (typeof navigator > "u" || !navigator.gpu)
490
- return null;
491
- try {
492
- const t = await navigator.gpu.requestAdapter();
493
- if (!t)
494
- return null;
495
- const n = await t.requestDevice(), i = r.getContext("webgpu");
496
- if (!i)
497
- return null;
498
- const s = navigator.gpu.getPreferredCanvasFormat();
499
- return i.configure({
500
- device: n,
501
- format: s,
502
- alphaMode: e ? "premultiplied" : "opaque"
503
- }), {
504
- type: "webgpu",
505
- adapter: t,
506
- device: n,
507
- context: i,
508
- format: s
509
- };
510
- } catch {
511
- return null;
512
- }
513
- }
514
- var L = class {
515
- program;
516
- uniforms = {};
517
- _gl;
518
- constructor(r, e, t) {
519
- this._gl = r, this.program = r.createProgram(), r.attachShader(this.program, this._compile(r.VERTEX_SHADER, e)), r.attachShader(this.program, this._compile(r.FRAGMENT_SHADER, t)), r.linkProgram(this.program);
520
- const n = r.getProgramParameter(this.program, r.ACTIVE_UNIFORMS);
521
- for (let i = 0; i < n; i++) {
522
- const s = r.getActiveUniform(this.program, i).name;
523
- this.uniforms[s] = r.getUniformLocation(this.program, s);
524
- }
525
- }
526
- _compile(r, e) {
527
- const t = this._gl, n = t.createShader(r);
528
- return t.shaderSource(n, e), t.compileShader(n), n;
529
- }
530
- bind() {
531
- this._gl.useProgram(this.program);
532
- }
533
- dispose() {
534
- this._gl.deleteProgram(this.program);
535
- }
536
- };
537
- function We(r) {
538
- return {
539
- advection: new L(r, F, Fe),
540
- divergence: new L(r, F, Le),
541
- pressure: new L(r, F, Pe),
542
- gradientSubtract: new L(r, F, Ae),
543
- splat: new L(r, F, Me),
544
- curl: new L(r, F, ze),
545
- vorticity: new L(r, F, Xe),
546
- display: new L(r, F, ke)
547
- };
548
- }
549
- function ie(r, e, t, n) {
550
- r.activeTexture(r.TEXTURE0);
551
- const i = r.createTexture();
552
- r.bindTexture(r.TEXTURE_2D, i), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.texImage2D(r.TEXTURE_2D, 0, e.internalFormat, t, n, 0, e.format, e.type, null);
553
- const s = r.createFramebuffer();
554
- return r.bindFramebuffer(r.FRAMEBUFFER, s), r.framebufferTexture2D(r.FRAMEBUFFER, r.COLOR_ATTACHMENT0, r.TEXTURE_2D, i, 0), {
555
- tex: i,
556
- fbo: s,
557
- width: t,
558
- height: n
559
- };
560
- }
561
- function ue(r, e, t, n) {
562
- let i = ie(r, e, t, n), s = ie(r, e, t, n);
563
- return {
564
- get read() {
565
- return i;
566
- },
567
- get write() {
568
- return s;
569
- },
570
- swap() {
571
- [i, s] = [s, i];
572
- },
573
- dispose() {
574
- r.deleteTexture(i.tex), r.deleteFramebuffer(i.fbo), r.deleteTexture(s.tex), r.deleteFramebuffer(s.fbo);
575
- }
576
- };
577
- }
578
- function Ne(r) {
579
- const e = r.createBuffer();
580
- return r.bindBuffer(r.ARRAY_BUFFER, e), r.bufferData(r.ARRAY_BUFFER, new Float32Array([
581
- -1,
582
- -1,
583
- -1,
584
- 1,
585
- 1,
586
- 1,
587
- 1,
588
- -1
589
- ]), r.STATIC_DRAW), r.vertexAttribPointer(0, 2, r.FLOAT, !1, 0, 0), r.enableVertexAttribArray(0), function(n) {
590
- r.bindFramebuffer(r.FRAMEBUFFER, n), r.drawArrays(r.TRIANGLE_FAN, 0, 4);
591
- };
592
- }
593
- var $e = `struct U {
594
- texelSize : vec2f,
595
- dt : f32,
596
- dissipation: f32,
597
- }
598
- @group(0) @binding(0) var<uniform> u : U;
599
- @group(0) @binding(1) var samp : sampler;
600
- @group(0) @binding(2) var uVel : texture_2d<f32>;
601
- @group(0) @binding(3) var uSrc : texture_2d<f32>;
602
- @group(0) @binding(4) var uObs : texture_2d<f32>;
603
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
604
- var o: VSOut;
605
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
606
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
607
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
608
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
609
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
610
- o.pos = vec4f(a, 0.0, 1.0);
611
- return o;
612
- }
613
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
614
- let obs = textureSample(uObs, samp, i.uv).r;
615
- let vel = textureSample(uVel, samp, i.uv).xy;
616
- let coord = i.uv - u.dt * vel * u.texelSize;
617
- let src = textureSample(uSrc, samp, coord);
618
- return u.dissipation * src * (1.0 - obs);
619
- }`, qe = `struct U { texelSize: vec2f, _pad: vec2f }
620
- @group(0) @binding(0) var<uniform> u : U;
621
- @group(0) @binding(1) var samp : sampler;
622
- @group(0) @binding(2) var uVel : texture_2d<f32>;
623
- @group(0) @binding(3) var uObs : texture_2d<f32>;
624
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
625
- var o: VSOut;
626
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
627
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
628
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
629
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
630
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
631
- o.pos = vec4f(a, 0.0, 1.0);
632
- return o;
633
- }
634
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
635
- let L = textureSample(uVel, samp, i.vL).x * (1.0 - textureSample(uObs, samp, i.vL).r);
636
- let R = textureSample(uVel, samp, i.vR).x * (1.0 - textureSample(uObs, samp, i.vR).r);
637
- let T = textureSample(uVel, samp, i.vT).y * (1.0 - textureSample(uObs, samp, i.vT).r);
638
- let B = textureSample(uVel, samp, i.vB).y * (1.0 - textureSample(uObs, samp, i.vB).r);
639
- return vec4f(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);
640
- }`, He = `struct U { texelSize: vec2f, _pad: vec2f }
641
- @group(0) @binding(0) var<uniform> u : U;
642
- @group(0) @binding(1) var samp : sampler;
643
- @group(0) @binding(2) var uPres: texture_2d<f32>;
644
- @group(0) @binding(3) var uDiv : texture_2d<f32>;
645
- @group(0) @binding(4) var uObs : texture_2d<f32>;
646
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
647
- var o: VSOut;
648
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
649
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
650
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
651
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
652
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
653
- o.pos = vec4f(a, 0.0, 1.0);
654
- return o;
655
- }
656
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
657
- let C = textureSample(uPres, samp, i.uv).x;
658
- let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);
659
- let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);
660
- let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);
661
- let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);
662
- let dv = textureSample(uDiv, samp, i.uv).x;
663
- return vec4f((L + R + B + T - dv) * 0.25, 0.0, 0.0, 1.0);
664
- }`, Ye = `struct U { texelSize: vec2f, _pad: vec2f }
665
- @group(0) @binding(0) var<uniform> u : U;
666
- @group(0) @binding(1) var samp : sampler;
667
- @group(0) @binding(2) var uPres: texture_2d<f32>;
668
- @group(0) @binding(3) var uVel : texture_2d<f32>;
669
- @group(0) @binding(4) var uObs : texture_2d<f32>;
670
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
671
- var o: VSOut;
672
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
673
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
674
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
675
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
676
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
677
- o.pos = vec4f(a, 0.0, 1.0);
678
- return o;
679
- }
680
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
681
- let obs = textureSample(uObs, samp, i.uv).r;
682
- let C = textureSample(uPres, samp, i.uv).x;
683
- let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);
684
- let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);
685
- let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);
686
- let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);
687
- let vel = (textureSample(uVel, samp, i.uv).xy - vec2f(R - L, T - B)) * (1.0 - obs);
688
- return vec4f(vel, 0.0, 1.0);
689
- }`, je = `struct U {
690
- texelSize : vec2f,
691
- aspectRatio: f32,
692
- radius : f32,
693
- color : vec4f,
694
- point : vec2f,
695
- _pad : vec2f,
696
- }
697
- @group(0) @binding(0) var<uniform> u : U;
698
- @group(0) @binding(1) var samp : sampler;
699
- @group(0) @binding(2) var uTgt : texture_2d<f32>;
700
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
701
- var o: VSOut;
702
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
703
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
704
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
705
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
706
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
707
- o.pos = vec4f(a, 0.0, 1.0);
708
- return o;
709
- }
710
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
711
- var p = i.uv - u.point;
712
- p.x *= u.aspectRatio;
713
- let sp = exp(-dot(p, p) / u.radius) * u.color.xyz;
714
- return vec4f(textureSample(uTgt, samp, i.uv).xyz + sp, 1.0);
715
- }`, Qe = `struct U { texelSize: vec2f, _pad: vec2f }
716
- @group(0) @binding(0) var<uniform> u : U;
717
- @group(0) @binding(1) var samp : sampler;
718
- @group(0) @binding(2) var uVel : texture_2d<f32>;
719
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
720
- var o: VSOut;
721
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
722
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
723
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
724
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
725
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
726
- o.pos = vec4f(a, 0.0, 1.0);
727
- return o;
728
- }
729
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
730
- let L = textureSample(uVel, samp, i.vL).y;
731
- let R = textureSample(uVel, samp, i.vR).y;
732
- let T = textureSample(uVel, samp, i.vT).x;
733
- let B = textureSample(uVel, samp, i.vB).x;
734
- return vec4f(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);
735
- }`, Ke = `struct U {
736
- texelSize: vec2f,
737
- curl : f32,
738
- dt : f32,
739
- }
740
- @group(0) @binding(0) var<uniform> u : U;
741
- @group(0) @binding(1) var samp : sampler;
742
- @group(0) @binding(2) var uVel : texture_2d<f32>;
743
- @group(0) @binding(3) var uCrl : texture_2d<f32>;
744
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
745
- var o: VSOut;
746
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
747
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
748
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
749
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
750
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
751
- o.pos = vec4f(a, 0.0, 1.0);
752
- return o;
753
- }
754
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
755
- let L = textureSample(uCrl, samp, i.vL).x;
756
- let R = textureSample(uCrl, samp, i.vR).x;
757
- let T = textureSample(uCrl, samp, i.vT).x;
758
- let B = textureSample(uCrl, samp, i.vB).x;
759
- let C = textureSample(uCrl, samp, i.uv).x;
760
- var force = 0.5 * vec2f(abs(T) - abs(B), abs(R) - abs(L));
761
- force /= length(force) + 0.0001;
762
- force *= u.curl * 30.0 * C;
763
- let vel = textureSample(uVel, samp, i.uv).xy + force * u.dt;
764
- return vec4f(vel, 0.0, 1.0);
765
- }`, Je = `struct U {
766
- texelSize : vec2f,
767
- refraction : f32,
768
- specularExp : f32,
769
- waterColor : vec4f,
770
- glowColor : vec4f,
771
- shine : f32,
772
- warpStrength: f32,
773
- algorithm : i32,
774
- enableAlpha : i32,
775
- }
776
- @group(0) @binding(0) var<uniform> u : U;
777
- @group(0) @binding(1) var samp : sampler;
778
- @group(0) @binding(2) var uTex : texture_2d<f32>;
779
- @group(0) @binding(3) var uObs : texture_2d<f32>;
780
- @group(0) @binding(4) var uBg : texture_2d<f32>;
781
- @group(0) @binding(5) var uCov : texture_2d<f32>;
782
- @group(0) @binding(6) var uVel : texture_2d<f32>;
783
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
784
- var o: VSOut;
785
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
786
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
787
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
788
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
789
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
790
- o.pos = vec4f(a, 0.0, 1.0);
791
- return o;
792
- }
793
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
794
- let obs = textureSample(uObs, samp, i.uv).r;
795
- let density = max(textureSample(uTex, samp, i.uv).r, 0.0) * (1.0 - obs);
796
- let cov = textureSample(uCov, samp, i.uv).r;
797
- let sx = u.texelSize.x * 6.0;
798
- let sy = u.texelSize.y * 6.0;
799
- let d00 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, -sy)).r, 0.0);
800
- let d10 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, -sy)).r, 0.0);
801
- let d20 = max(textureSample(uTex, samp, i.uv + vec2f( sx, -sy)).r, 0.0);
802
- let d01 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, 0.0)).r, 0.0);
803
- let d21 = max(textureSample(uTex, samp, i.uv + vec2f( sx, 0.0)).r, 0.0);
804
- let d02 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, sy)).r, 0.0);
805
- let d12 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, sy)).r, 0.0);
806
- let d22 = max(textureSample(uTex, samp, i.uv + vec2f( sx, sy)).r, 0.0);
807
- let gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);
808
- let gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);
809
- let norm = normalize(vec3f(gx, gy, 1.2));
810
- let ldir = normalize(vec3f(0.5, 1.0, 0.5));
811
- let halfV = normalize(ldir + vec3f(0.0, 0.0, 1.0));
812
- let specDen = density * min(density * 5.0, 1.0);
813
- let spec = pow(max(dot(norm, halfV), 0.0), u.specularExp) * u.shine * specDen;
814
- let bgRaw = textureSample(uBg, samp, i.uv).rgb;
815
- let wc = u.waterColor.rgb;
816
- let gc = u.glowColor.rgb;
817
- let bg = mix(wc, bgRaw, cov);
818
- var color = bg;
819
- if (u.algorithm == 1) {
820
- let ruv = clamp(i.uv + norm.xy * u.refraction * density * 3.0, vec2f(0.0), vec2f(1.0));
821
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
822
- color = rbg + spec * gc * 2.5;
823
- color = mix(color, bg * 0.6, obs * 0.3);
824
- } else if (u.algorithm == 2) {
825
- let inkD = min(density * 4.0, 1.0);
826
- let ruv = clamp(i.uv + norm.xy * u.refraction * density * 0.4, vec2f(0.0), vec2f(1.0));
827
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
828
- color = mix(rbg, wc + spec * gc, inkD);
829
- color = mix(color, bg * 0.5, obs * 0.15);
830
- } else if (u.algorithm == 3) {
831
- let vel = textureSample(uVel, samp, i.uv).xy;
832
- let velMag = clamp(length(vel) * 20.0, 0.0, 1.0);
833
- let wuv = clamp(i.uv + vel * u.warpStrength, vec2f(0.0), vec2f(1.0));
834
- let wbg = mix(wc, textureSample(uBg, samp, wuv).rgb, cov);
835
- color = mix(bg, wbg, velMag * (1.0 - obs));
836
- color += spec * gc * velMag * 1.5;
837
- color += wc * density * 0.3;
838
- color = mix(color, bg * 0.5, obs * 0.2);
839
- } else if (u.algorithm == 4) {
840
- let ruv = clamp(i.uv + norm.xy * u.refraction * density * 6.0, vec2f(0.0), vec2f(1.0));
841
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
842
- let fres = pow(clamp(1.0 - dot(norm, vec3f(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;
843
- color = rbg;
844
- color += fres * gc * 2.0;
845
- color += spec * gc * density * 2.0;
846
- color = mix(color, bg * 0.5, obs * 0.2);
847
- } else {
848
- let ruv = i.uv + norm.xy * u.refraction * density;
849
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
850
- color = mix(rbg, wc, min(density * 1.5, 0.8));
851
- color += spec * gc;
852
- color = mix(color, bg * 0.5, obs * 0.2);
853
- }
854
- let alpha = clamp(max(density * 1.5, cov), 0.0, 1.0);
855
- if (u.enableAlpha == 1) {
856
- return vec4f(color * alpha, alpha);
857
- }
858
- return vec4f(color, 1.0);
859
- }`, Ze = {
860
- arrayStride: 8,
861
- attributes: [{
862
- shaderLocation: 0,
863
- offset: 0,
864
- format: "float32x2"
865
- }]
866
- }, xe = new Float32Array([
867
- -1,
868
- -1,
869
- -1,
870
- 1,
871
- 1,
872
- -1,
873
- 1,
874
- -1,
875
- -1,
876
- 1,
877
- 1,
878
- 1
879
- ]);
880
- function et(r) {
881
- const e = r.createBuffer({
882
- size: xe.byteLength,
883
- usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
884
- });
885
- return r.queue.writeBuffer(e, 0, xe), e;
886
- }
887
- function se(r, e, t, n) {
888
- const i = r.createTexture({
889
- size: [t, n],
890
- format: e,
891
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
892
- });
893
- return {
894
- tex: i,
895
- view: i.createView(),
896
- width: t,
897
- height: n
898
- };
899
- }
900
- function le(r, e, t, n) {
901
- let i = se(r, e, t, n), s = se(r, e, t, n);
902
- return {
903
- get read() {
904
- return i;
905
- },
906
- get write() {
907
- return s;
908
- },
909
- swap() {
910
- [i, s] = [s, i];
911
- },
912
- dispose() {
913
- i.tex.destroy(), s.tex.destroy();
914
- }
915
- };
916
- }
917
- function P(r, e, t, n) {
918
- const i = r.createShaderModule({ code: e });
919
- return r.createRenderPipeline({
920
- layout: "auto",
921
- vertex: {
922
- module: i,
923
- entryPoint: "vs",
924
- buffers: [Ze]
925
- },
926
- fragment: {
927
- module: i,
928
- entryPoint: "fs",
929
- targets: [{
930
- format: t,
931
- ...n ? { blend: n } : {}
932
- }]
933
- },
934
- primitive: { topology: "triangle-list" }
935
- });
936
- }
937
- var tt = {
938
- color: {
939
- operation: "add",
940
- srcFactor: "one",
941
- dstFactor: "zero"
942
- },
943
- alpha: {
944
- operation: "add",
945
- srcFactor: "one",
946
- dstFactor: "zero"
947
- }
948
- };
949
- function rt(r, e, t = !0) {
950
- const n = "rgba16float";
951
- return {
952
- advection: P(r, $e, n),
953
- divergence: P(r, qe, n),
954
- pressure: P(r, He, n),
955
- gradientSubtract: P(r, Ye, n),
956
- splat: P(r, je, n),
957
- curl: P(r, Qe, n),
958
- vorticity: P(r, Ke, n),
959
- display: P(r, Je, e, t ? void 0 : tt)
960
- };
961
- }
962
- function nt(r) {
963
- return r.createSampler({
964
- magFilter: "linear",
965
- minFilter: "linear",
966
- addressModeU: "clamp-to-edge",
967
- addressModeV: "clamp-to-edge"
968
- });
969
- }
970
- function C(r, e) {
971
- return r.createBuffer({
972
- size: e,
973
- usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
974
- });
975
- }
976
- function he(r, e, t, n, i, s) {
977
- const a = new Float32Array([
978
- t,
979
- n,
980
- i,
981
- s
982
- ]);
983
- r.queue.writeBuffer(e, 0, a);
984
- }
985
- function re(r, e, t, n) {
986
- const i = new Float32Array([
987
- t,
988
- n,
989
- 0,
990
- 0
991
- ]);
992
- r.queue.writeBuffer(e, 0, i);
993
- }
994
- function it(r, e, t, n, i, s) {
995
- const a = new Float32Array([
996
- t,
997
- n,
998
- i,
999
- s
1000
- ]);
1001
- r.queue.writeBuffer(e, 0, a);
1002
- }
1003
- function ne(r, e, t, n, i, s, a, c, x, u, v) {
1004
- const l = /* @__PURE__ */ new Float32Array(12);
1005
- l[0] = t, l[1] = n, l[2] = i, l[3] = s, l[4] = a, l[5] = c, l[6] = x, l[7] = 0, l[8] = u, l[9] = v, l[10] = 0, l[11] = 0, r.queue.writeBuffer(e, 0, l);
1006
- }
1007
- function st(r, e, t, n, i, s, a, c, x, u, v, l) {
1008
- const o = /* @__PURE__ */ new Float32Array(16), f = new Int32Array(o.buffer);
1009
- o[0] = t, o[1] = n, o[2] = i, o[3] = s, o[4] = a[0], o[5] = a[1], o[6] = a[2], o[7] = 0, o[8] = c[0], o[9] = c[1], o[10] = c[2], o[11] = 0, o[12] = x, o[13] = u, f[14] = v, f[15] = l ? 1 : 0, r.queue.writeBuffer(e, 0, o);
1010
- }
1011
- function D(r, e, t, n, i) {
1012
- const s = r.beginRenderPass({ colorAttachments: [{
1013
- view: i,
1014
- clearValue: [
1015
- 0,
1016
- 0,
1017
- 0,
1018
- 0
1019
- ],
1020
- loadOp: "clear",
1021
- storeOp: "store"
1022
- }] });
1023
- s.setPipeline(e), s.setBindGroup(0, t), s.setVertexBuffer(0, n), s.draw(6), s.end();
1024
- }
1025
- function ot(r, e, t, n, i) {
1026
- const s = r.beginRenderPass({ colorAttachments: [{
1027
- view: i,
1028
- clearValue: [
1029
- 0,
1030
- 0,
1031
- 0,
1032
- 0
1033
- ],
1034
- loadOp: "clear",
1035
- storeOp: "store"
1036
- }] });
1037
- s.setPipeline(e), s.setBindGroup(0, t), s.setVertexBuffer(0, n), s.draw(6), s.end();
13
+ function o(e) {
14
+ let t = { ...e };
15
+ for (let [n, [r, i]] of Object.entries(a)) {
16
+ let a = e[n];
17
+ a !== void 0 && a >= 0 && a <= 1 && (t[n] = r + (i - r) * a);
18
+ }
19
+ return t;
1038
20
  }
1039
- var me = typeof requestAnimationFrame < "u" ? requestAnimationFrame.bind(globalThis) : (r) => setTimeout(r, 1e3 / 60), at = typeof cancelAnimationFrame < "u" ? cancelAnimationFrame.bind(globalThis) : clearTimeout, K = 0.016, de = {
1040
- standard: 0,
1041
- glass: 1,
1042
- ink: 2,
1043
- aurora: 3,
1044
- ripple: 4
1045
- }, pe = class Re {
1046
- #r;
1047
- #i = null;
1048
- #U = null;
1049
- #g = null;
1050
- #b = null;
1051
- #s = null;
1052
- #t = null;
1053
- #c = null;
1054
- #f = null;
1055
- #d = null;
1056
- #T = null;
1057
- #h = null;
1058
- #S = null;
1059
- #v = null;
1060
- #Y = null;
1061
- #P = null;
1062
- #j = null;
1063
- #l = null;
1064
- #n = null;
1065
- #O = null;
1066
- #R = null;
1067
- #V = null;
1068
- #p = null;
1069
- #A = null;
1070
- #M = null;
1071
- #z = null;
1072
- #X = null;
1073
- #k = null;
1074
- #D = null;
1075
- #_ = null;
1076
- #I = null;
1077
- #G = null;
1078
- #W = null;
1079
- #o = 0;
1080
- #a = 0;
1081
- #y = 0;
1082
- #w = 0;
1083
- #x = 1;
1084
- #Q = 1;
1085
- #C = 0.5;
1086
- #m = null;
1087
- #F = "cover";
1088
- #B;
1089
- #e = {
1090
- x: 0,
1091
- y: 0,
1092
- dx: 0,
1093
- dy: 0,
1094
- targetX: 0,
1095
- targetY: 0,
1096
- moved: !1
1097
- };
1098
- #K = !1;
1099
- #u = null;
1100
- #E = null;
1101
- #N = !1;
1102
- #J = !1;
1103
- #$ = !0;
1104
- constructor(e, t = {}, n = {}, i, s = !0) {
1105
- if (this.#r = e, this.#Q = Math.max(0.1, Math.min(1, n.dpr ?? 1)), this.#C = Math.max(0.1, Math.min(1, n.sim ?? 0.5)), this.#B = ee(t), this.#$ = s, i)
1106
- this.#v = i, this.#re(i);
1107
- else {
1108
- const { gl: a, ext: c } = Ie(e, s);
1109
- this.#i = a, this.#U = c, this.#g = We(a), this.#b = Ne(a), a.clearColor(0, 0, 0, s ? 0 : 1);
1110
- }
1111
- }
1112
- static async create(e, t = {}, n = {}, i = !0, s = !0) {
1113
- return new Re(e, t, n, (i ? await Ge(e, s) : null) ?? void 0, s);
1114
- }
1115
- setTextSource(e) {
1116
- this.#u = {
1117
- type: "text",
1118
- opts: e
1119
- }, this.#q(), this.#L(), this.#H();
1120
- }
1121
- async setImageSource(e, t = 0, n = "cover") {
1122
- const i = await ce(e);
1123
- if (this.#J) {
1124
- i.close();
1125
- return;
1126
- }
1127
- this.#u = {
1128
- type: "image",
1129
- bitmap: i,
1130
- effect: t,
1131
- size: n
1132
- }, this.#q(), this.#L(), this.#H();
1133
- }
1134
- setImageBitmap(e, t = 0, n = "cover") {
1135
- this.#u = {
1136
- type: "image",
1137
- bitmap: e,
1138
- effect: t,
1139
- size: n
1140
- }, this.#q(), this.#L(), this.#H();
1141
- }
1142
- setBackground(e, t = "cover") {
1143
- this.#m && this.#m !== e && this.#m.close(), this.#m = e, this.#F = t ?? "cover", this.#u && this.#o > 0 && this.#a > 0 && this.#L();
1144
- }
1145
- handleMove(e, t, n = 1) {
1146
- if (!this.#K) {
1147
- this.#e.x = this.#e.targetX = e, this.#e.y = this.#e.targetY = t, this.#K = !0;
1148
- return;
1149
- }
1150
- this.#e.moved = !0, this.#e.dx = (e - this.#e.targetX) * n, this.#e.dy = (t - this.#e.targetY) * n, this.#e.targetX = e, this.#e.targetY = t;
1151
- }
1152
- splat(e, t, n, i, s = 1) {
1153
- !this.#N || this.#o === 0 || (this.#v ? this.#se(e, t, n, i, s) : this.#oe(e, t, n, i, s));
1154
- }
1155
- updateQuality(e) {
1156
- e.dpr !== void 0 && (this.#Q = Math.max(0.1, Math.min(1, e.dpr))), e.sim !== void 0 && (this.#C = Math.max(0.1, Math.min(1, e.sim)));
1157
- }
1158
- resize(e, t, n) {
1159
- if (n !== void 0 ? this.#x = n : typeof window < "u" && window.devicePixelRatio && (this.#x = window.devicePixelRatio), e !== void 0 && e > 0) {
1160
- if (t === void 0 || t <= 0)
1161
- return;
1162
- this.#o = this.#r.width = e, this.#a = this.#r.height = t, this.#y = Math.max(1, Math.round(e * this.#C)), this.#w = Math.max(1, Math.round(t * this.#C)), this.#Z();
1163
- } else
1164
- this.#q();
1165
- this.#u && this.#L(), this.#H();
1166
- }
1167
- updateConfig(e) {
1168
- Object.assign(this.#B, e);
1169
- }
1170
- destroy() {
1171
- if (this.#J = !0, this.stop(), this.#ee(), this.#te(), this.#m && (this.#m.close(), this.#m = null), this.#v)
1172
- this.#A?.destroy(), this.#M?.destroy(), this.#z?.destroy(), this.#X?.destroy(), this.#k?.destroy(), this.#D?.destroy(), this.#_?.destroy(), this.#I?.destroy(), this.#G?.destroy(), this.#W?.destroy(), this.#P?.destroy(), this.#v.device.destroy();
1173
- else {
1174
- const e = this.#i;
1175
- for (const t of Object.values(this.#g))
1176
- t.dispose();
1177
- e.getExtension("WEBGL_lose_context")?.loseContext();
1178
- }
1179
- }
1180
- start() {
1181
- if (this.#E !== null)
1182
- return;
1183
- const e = () => {
1184
- this.#ne(), this.#E = me(e);
1185
- };
1186
- this.#E = me(e);
1187
- }
1188
- stop() {
1189
- this.#E !== null && (at(this.#E), this.#E = null);
1190
- }
1191
- get isRunning() {
1192
- return this.#E !== null;
1193
- }
1194
- #re(e) {
1195
- const { device: t, format: n } = e;
1196
- this.#Y = rt(t, n, this.#$), this.#P = et(t), this.#j = nt(t), this.#A = C(t, 16), this.#M = C(t, 16), this.#z = C(t, 16), this.#X = C(t, 16), this.#k = C(t, 16), this.#D = C(t, 48), this.#_ = C(t, 48), this.#I = C(t, 16), this.#G = C(t, 16), this.#W = C(t, 64);
1197
- }
1198
- #q() {
1199
- const e = this.#r;
1200
- "clientWidth" in e && e.clientWidth > 0 ? (this.#x = (typeof window < "u" && window.devicePixelRatio || 1) * this.#Q, this.#o = e.width = Math.round(e.clientWidth * this.#x), this.#a = e.height = Math.round(e.clientHeight * this.#x)) : (this.#o = e.width, this.#a = e.height), !(this.#o === 0 || this.#a === 0) && (this.#y = Math.max(1, Math.round(this.#o * this.#C)), this.#w = Math.max(1, Math.round(this.#a * this.#C)), this.#Z());
1201
- }
1202
- #Z() {
1203
- if (this.#ee(), this.#v) {
1204
- const { device: e } = this.#v, t = "rgba16float", n = this.#y, i = this.#w;
1205
- this.#l = le(e, t, n, i), this.#n = le(e, t, n, i), this.#R = le(e, t, n, i), this.#O = se(e, t, n, i), this.#V = se(e, t, n, i);
1206
- } else {
1207
- const e = this.#i, t = this.#U, n = this.#y, i = this.#w;
1208
- this.#s = ue(e, t, n, i), this.#t = ue(e, t, n, i), this.#f = ue(e, t, n, i), this.#c = ie(e, t, n, i), this.#d = ie(e, t, n, i);
1209
- }
1210
- }
1211
- #L() {
1212
- if (!(!this.#u || this.#o === 0 || this.#a === 0)) {
1213
- if (this.#te(), this.#v) {
1214
- const { device: e } = this.#v;
1215
- this.#u.type === "text" ? this.#p = Oe(e, this.#o, this.#a, this.#u.opts, this.#m, this.#F) : this.#p = Ve(e, this.#u.bitmap, this.#o, this.#a, this.#u.effect, this.#u.size, this.#m, this.#F);
1216
- } else {
1217
- const e = this.#i;
1218
- if (this.#u.type === "text") {
1219
- const { backgroundTex: t, obstacleTex: n, coverageTex: i } = Ce(e, this.#o, this.#a, this.#u.opts, this.#m, this.#F);
1220
- this.#T = t, this.#h = n, this.#S = i;
1221
- } else {
1222
- const { backgroundTex: t, obstacleTex: n, coverageTex: i } = Be(e, this.#u.bitmap, this.#o, this.#a, this.#u.effect, this.#u.size, this.#m, this.#F);
1223
- this.#T = t, this.#h = n, this.#S = i;
1224
- }
1225
- }
1226
- this.#N = !0;
1227
- }
1228
- }
1229
- #H() {
1230
- this.#N && !this.isRunning && this.start();
1231
- }
1232
- #ee() {
1233
- if (this.#v)
1234
- this.#l?.dispose(), this.#n?.dispose(), this.#R?.dispose(), this.#O?.tex.destroy(), this.#V?.tex.destroy(), this.#l = this.#n = this.#R = null, this.#O = this.#V = null;
1235
- else {
1236
- const e = this.#i;
1237
- this.#s?.dispose(), this.#t?.dispose(), this.#f?.dispose(), this.#c && (e.deleteTexture(this.#c.tex), e.deleteFramebuffer(this.#c.fbo)), this.#d && (e.deleteTexture(this.#d.tex), e.deleteFramebuffer(this.#d.fbo)), this.#s = this.#t = this.#f = this.#c = this.#d = null;
1238
- }
1239
- }
1240
- #te() {
1241
- if (this.#v)
1242
- this.#p && (this.#p.backgroundTex.destroy(), this.#p.obstacleTex.destroy(), this.#p.sharedCoverage || this.#p.coverageTex.destroy(), this.#p = null);
1243
- else {
1244
- const e = this.#i;
1245
- this.#T && e.deleteTexture(this.#T), this.#h && e.deleteTexture(this.#h), this.#S && this.#S !== this.#h && e.deleteTexture(this.#S), this.#T = this.#h = this.#S = null;
1246
- }
1247
- }
1248
- #ne() {
1249
- !this.#N || this.#o === 0 || (this.#v ? this.#ie() : this.#ae());
1250
- }
1251
- #ie() {
1252
- const e = this.#v, t = e.device, n = this.#Y, i = this.#P, s = this.#j, a = this.#B, c = this.#p;
1253
- if (!this.#l || !this.#n)
1254
- return;
1255
- this.#e.x += (this.#e.targetX - this.#e.x) * 0.15, this.#e.y += (this.#e.targetY - this.#e.y) * 0.15;
1256
- const x = this.#y, u = this.#w, v = this.#o, l = this.#a, o = 1 / x, f = 1 / u;
1257
- he(t, this.#A, o, f, K, a.velocityDissipation), re(t, this.#z, o, f), re(t, this.#X, o, f), re(t, this.#k, o, f), re(t, this.#I, o, f), it(t, this.#G, o, f, a.curl, K), st(t, this.#W, 1 / v, 1 / l, a.refraction, a.specularExp, te(a.waterColor), te(a.glowColor), a.shine, a.warpStrength ?? 0.015, de[a.algorithm] ?? 0, this.#$);
1258
- const m = t.createCommandEncoder(), d = (h, g) => t.createBindGroup({
1259
- layout: h.getBindGroupLayout(0),
1260
- entries: g
1261
- }), p = {
1262
- binding: 1,
1263
- resource: s
1264
- };
1265
- {
1266
- const h = d(n.advection, [
1267
- {
1268
- binding: 0,
1269
- resource: { buffer: this.#A }
1270
- },
1271
- p,
1272
- {
1273
- binding: 2,
1274
- resource: this.#n.read.view
1275
- },
1276
- {
1277
- binding: 3,
1278
- resource: this.#n.read.view
1279
- },
1280
- {
1281
- binding: 4,
1282
- resource: c.obstacleView
1283
- }
1284
- ]);
1285
- D(m, n.advection, h, i, this.#n.write.view);
1286
- }
1287
- this.#n.swap();
1288
- {
1289
- he(t, this.#M, o, f, K, a.densityDissipation);
1290
- const h = d(n.advection, [
1291
- {
1292
- binding: 0,
1293
- resource: { buffer: this.#M }
1294
- },
1295
- p,
1296
- {
1297
- binding: 2,
1298
- resource: this.#n.read.view
1299
- },
1300
- {
1301
- binding: 3,
1302
- resource: this.#l.read.view
1303
- },
1304
- {
1305
- binding: 4,
1306
- resource: c.obstacleView
1307
- }
1308
- ]);
1309
- D(m, n.advection, h, i, this.#l.write.view);
1310
- }
1311
- this.#l.swap();
1312
- {
1313
- const h = d(n.curl, [
1314
- {
1315
- binding: 0,
1316
- resource: { buffer: this.#I }
1317
- },
1318
- p,
1319
- {
1320
- binding: 2,
1321
- resource: this.#n.read.view
1322
- }
1323
- ]);
1324
- D(m, n.curl, h, i, this.#V.view);
1325
- }
1326
- {
1327
- const h = d(n.vorticity, [
1328
- {
1329
- binding: 0,
1330
- resource: { buffer: this.#G }
1331
- },
1332
- p,
1333
- {
1334
- binding: 2,
1335
- resource: this.#n.read.view
1336
- },
1337
- {
1338
- binding: 3,
1339
- resource: this.#V.view
1340
- }
1341
- ]);
1342
- D(m, n.vorticity, h, i, this.#n.write.view);
1343
- }
1344
- if (this.#n.swap(), this.#e.moved) {
1345
- const h = this.#e.x * this.#x / v, g = this.#e.y * this.#x / l;
1346
- ne(t, this.#D, o, f, v / l, a.splatRadius, this.#e.dx * a.splatForce, this.#e.dy * a.splatForce, 0, h, g);
1347
- {
1348
- const T = d(n.splat, [
1349
- {
1350
- binding: 0,
1351
- resource: { buffer: this.#D }
1352
- },
1353
- p,
1354
- {
1355
- binding: 2,
1356
- resource: this.#n.read.view
1357
- }
1358
- ]);
1359
- D(m, n.splat, T, i, this.#n.write.view);
1360
- }
1361
- this.#n.swap(), ne(t, this.#_, o, f, v / l, a.splatRadius, 1, 1, 1, h, g);
1362
- {
1363
- const T = d(n.splat, [
1364
- {
1365
- binding: 0,
1366
- resource: { buffer: this.#_ }
1367
- },
1368
- p,
1369
- {
1370
- binding: 2,
1371
- resource: this.#l.read.view
1372
- }
1373
- ]);
1374
- D(m, n.splat, T, i, this.#l.write.view);
1375
- }
1376
- this.#l.swap(), this.#e.moved = !1;
1377
- }
1378
- {
1379
- const h = d(n.divergence, [
1380
- {
1381
- binding: 0,
1382
- resource: { buffer: this.#z }
1383
- },
1384
- p,
1385
- {
1386
- binding: 2,
1387
- resource: this.#n.read.view
1388
- },
1389
- {
1390
- binding: 3,
1391
- resource: c.obstacleView
1392
- }
1393
- ]);
1394
- D(m, n.divergence, h, i, this.#O.view);
1395
- }
1396
- for (let h = 0; h < a.pressureIterations; h++) {
1397
- const g = d(n.pressure, [
1398
- {
1399
- binding: 0,
1400
- resource: { buffer: this.#X }
1401
- },
1402
- p,
1403
- {
1404
- binding: 2,
1405
- resource: this.#R.read.view
1406
- },
1407
- {
1408
- binding: 3,
1409
- resource: this.#O.view
1410
- },
1411
- {
1412
- binding: 4,
1413
- resource: c.obstacleView
1414
- }
1415
- ]);
1416
- D(m, n.pressure, g, i, this.#R.write.view), this.#R.swap();
1417
- }
1418
- {
1419
- const h = d(n.gradientSubtract, [
1420
- {
1421
- binding: 0,
1422
- resource: { buffer: this.#k }
1423
- },
1424
- p,
1425
- {
1426
- binding: 2,
1427
- resource: this.#R.read.view
1428
- },
1429
- {
1430
- binding: 3,
1431
- resource: this.#n.read.view
1432
- },
1433
- {
1434
- binding: 4,
1435
- resource: c.obstacleView
1436
- }
1437
- ]);
1438
- D(m, n.gradientSubtract, h, i, this.#n.write.view);
1439
- }
1440
- this.#n.swap();
1441
- {
1442
- const h = e.context.getCurrentTexture().createView(), g = d(n.display, [
1443
- {
1444
- binding: 0,
1445
- resource: { buffer: this.#W }
1446
- },
1447
- p,
1448
- {
1449
- binding: 2,
1450
- resource: this.#l.read.view
1451
- },
1452
- {
1453
- binding: 3,
1454
- resource: c.obstacleView
1455
- },
1456
- {
1457
- binding: 4,
1458
- resource: c.backgroundView
1459
- },
1460
- {
1461
- binding: 5,
1462
- resource: c.coverageView
1463
- },
1464
- {
1465
- binding: 6,
1466
- resource: this.#n.read.view
1467
- }
1468
- ]);
1469
- ot(m, n.display, g, i, h);
1470
- }
1471
- t.queue.submit([m.finish()]);
1472
- }
1473
- #se(e, t, n, i, s) {
1474
- const a = this.#v.device, c = this.#Y.splat, x = this.#P, u = this.#j, v = this.#B, l = this.#y, o = this.#w, f = 1 / l, m = 1 / o, d = a.createCommandEncoder(), p = {
1475
- binding: 1,
1476
- resource: u
1477
- }, h = (R) => a.createBindGroup({
1478
- layout: c.getBindGroupLayout(0),
1479
- entries: R
1480
- }), g = e * this.#x / this.#o, T = t * this.#x / this.#a;
1481
- ne(a, this.#D, f, m, this.#o / this.#a, v.splatRadius, n * v.splatForce * s, i * v.splatForce * s, 0, g, T), D(d, c, h([
1482
- {
1483
- binding: 0,
1484
- resource: { buffer: this.#D }
1485
- },
1486
- p,
1487
- {
1488
- binding: 2,
1489
- resource: this.#n.read.view
1490
- }
1491
- ]), x, this.#n.write.view), this.#n.swap(), ne(a, this.#_, f, m, this.#o / this.#a, v.splatRadius, s, s, s, g, T), D(d, c, h([
1492
- {
1493
- binding: 0,
1494
- resource: { buffer: this.#_ }
1495
- },
1496
- p,
1497
- {
1498
- binding: 2,
1499
- resource: this.#l.read.view
1500
- }
1501
- ]), x, this.#l.write.view), this.#l.swap(), a.queue.submit([d.finish()]);
1502
- }
1503
- #oe(e, t, n, i, s) {
1504
- const a = this.#i, c = this.#B, x = this.#g.splat, u = this.#b;
1505
- a.viewport(0, 0, this.#y, this.#w), x.bind(), a.uniform1f(x.uniforms.aspectRatio, this.#o / this.#a), a.uniform2f(x.uniforms.point, e * this.#x / this.#o, 1 - t * this.#x / this.#a), a.uniform1f(x.uniforms.radius, c.splatRadius), a.uniform1i(x.uniforms.uTarget, 0), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, this.#t.read.tex), a.uniform3f(x.uniforms.color, n * c.splatForce * s, -i * c.splatForce * s, 0), u(this.#t.write.fbo), this.#t.swap(), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, this.#s.read.tex), a.uniform3f(x.uniforms.color, s, s, s), u(this.#s.write.fbo), this.#s.swap();
1506
- }
1507
- #ae() {
1508
- if (!this.#s || !this.#t)
1509
- return;
1510
- const e = this.#i, t = this.#B, { advection: n, divergence: i, pressure: s, gradientSubtract: a, splat: c, curl: x, vorticity: u, display: v } = this.#g;
1511
- this.#e.x += (this.#e.targetX - this.#e.x) * 0.15, this.#e.y += (this.#e.targetY - this.#e.y) * 0.15;
1512
- const l = this.#y, o = this.#w, f = this.#b;
1513
- e.viewport(0, 0, l, o), n.bind(), e.uniform2f(n.uniforms.texelSize, 1 / l, 1 / o), e.uniform1f(n.uniforms.dt, K), e.uniform1i(n.uniforms.uObstacle, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#h), e.uniform1f(n.uniforms.dissipation, t.velocityDissipation), e.uniform1i(n.uniforms.uVelocity, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), e.uniform1i(n.uniforms.uSource, 1), f(this.#t.write.fbo), this.#t.swap(), e.uniform1f(n.uniforms.dissipation, t.densityDissipation), e.uniform1i(n.uniforms.uSource, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#s.read.tex), f(this.#s.write.fbo), this.#s.swap(), x.bind(), e.uniform2f(x.uniforms.texelSize, 1 / l, 1 / o), e.uniform1i(x.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), f(this.#d.fbo), u.bind(), e.uniform2f(u.uniforms.texelSize, 1 / l, 1 / o), e.uniform1f(u.uniforms.curl, t.curl), e.uniform1f(u.uniforms.dt, K), e.uniform1i(u.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), e.uniform1i(u.uniforms.uCurl, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#d.tex), f(this.#t.write.fbo), this.#t.swap(), this.#e.moved && (c.bind(), e.uniform1f(c.uniforms.aspectRatio, this.#o / this.#a), e.uniform2f(c.uniforms.point, this.#e.x * this.#x / this.#o, 1 - this.#e.y * this.#x / this.#a), e.uniform1f(c.uniforms.radius, t.splatRadius), e.uniform1i(c.uniforms.uTarget, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), e.uniform3f(c.uniforms.color, this.#e.dx * t.splatForce, -this.#e.dy * t.splatForce, 0), f(this.#t.write.fbo), this.#t.swap(), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#s.read.tex), e.uniform3f(c.uniforms.color, 1, 1, 1), f(this.#s.write.fbo), this.#s.swap(), this.#e.moved = !1), i.bind(), e.uniform2f(i.uniforms.texelSize, 1 / l, 1 / o), e.uniform1i(i.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), e.uniform1i(i.uniforms.uObstacle, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#h), f(this.#c.fbo), s.bind(), e.uniform2f(s.uniforms.texelSize, 1 / l, 1 / o), e.uniform1i(s.uniforms.uDivergence, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#c.tex), e.uniform1i(s.uniforms.uObstacle, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#h);
1514
- for (let m = 0; m < t.pressureIterations; m++)
1515
- e.uniform1i(s.uniforms.uPressure, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#f.read.tex), f(this.#f.write.fbo), this.#f.swap();
1516
- a.bind(), e.uniform2f(a.uniforms.texelSize, 1 / l, 1 / o), e.uniform1i(a.uniforms.uPressure, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#f.read.tex), e.uniform1i(a.uniforms.uVelocity, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), e.uniform1i(a.uniforms.uObstacle, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#h), f(this.#t.write.fbo), this.#t.swap(), e.viewport(0, 0, this.#o, this.#a), e.bindFramebuffer(e.FRAMEBUFFER, null), e.clear(e.COLOR_BUFFER_BIT), v.bind(), e.uniform2f(v.uniforms.texelSize, 1 / this.#o, 1 / this.#a), e.uniform3fv(v.uniforms.uWaterColor, te(t.waterColor)), e.uniform3fv(v.uniforms.uGlowColor, te(t.glowColor)), e.uniform1f(v.uniforms.uRefraction, t.refraction), e.uniform1f(v.uniforms.uSpecularExp, t.specularExp), e.uniform1f(v.uniforms.uShine, t.shine), e.uniform1f(v.uniforms.uWarpStrength, t.warpStrength ?? 0.015), e.uniform1i(v.uniforms.uAlgorithm, de[t.algorithm] ?? 0), e.uniform1i(v.uniforms.uEnableAlpha, this.#$ ? 1 : 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#s.read.tex), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#h), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#T), e.activeTexture(e.TEXTURE3), e.bindTexture(e.TEXTURE_2D, this.#S), e.activeTexture(e.TEXTURE4), e.bindTexture(e.TEXTURE_2D, this.#t.read.tex), e.uniform1i(v.uniforms.uTexture, 0), e.uniform1i(v.uniforms.uObstacle, 1), e.uniform1i(v.uniforms.uBackground, 2), e.uniform1i(v.uniforms.uCoverage, 3), e.uniform1i(v.uniforms.uVelocity, 4), f(null);
1517
- }
1518
- }, Ee = `const W = {
21
+ var s = {
1519
22
  densityDissipation: .83,
1520
23
  velocityDissipation: .91,
1521
24
  pressureIterations: 1,
@@ -1529,18 +32,38 @@ var me = typeof requestAnimationFrame < "u" ? requestAnimationFrame.bind(globalT
1529
32
  glowColor: "#b3d9ff",
1530
33
  algorithm: "aurora",
1531
34
  warpStrength: .04
1532
- };
1533
- ({ ...W });
1534
- typeof window < "u" && 1 / (window.devicePixelRatio || 1);
1535
- const N = {
35
+ }, c = {
36
+ ...s,
37
+ densityDissipation: .9,
38
+ velocityDissipation: .9,
39
+ pressureIterations: 3,
40
+ curl: .2,
41
+ splatRadius: .2,
42
+ splatForce: .5,
43
+ refraction: .2,
44
+ specularExp: .01,
45
+ shine: .5,
46
+ waterColor: "#090017",
47
+ glowColor: "#b04721"
48
+ }, l = {
49
+ dpr: typeof window < "u" ? 1 / (window.devicePixelRatio || 1) : 1,
50
+ sim: .5
51
+ }, u = {
1536
52
  backgroundColor: "#0a0a0a",
1537
53
  backgroundSize: "cover",
1538
54
  mouseEnabled: !0,
1539
55
  workerEnabled: !0
1540
- };
1541
- ({ ...N });
1542
- ({ ...N });
1543
- const q = {
56
+ }, d = {
57
+ ...u,
58
+ effect: 0,
59
+ imageSize: "cover"
60
+ }, f = {
61
+ ...u,
62
+ fontSize: 100,
63
+ color: "#ffffff",
64
+ fontFamily: "sans-serif",
65
+ fontWeight: 900
66
+ }, p = {
1544
67
  calm: {
1545
68
  densityDissipation: .98,
1546
69
  velocityDissipation: .81,
@@ -1599,294 +122,203 @@ const q = {
1599
122
  waterColor: "#0f0f0f"
1600
123
  }
1601
124
  };
1602
- function F(r) {
1603
- if (Array.isArray(r)) return r;
1604
- const e = r.slice(1, 7);
1605
- return e.length === 3 ? [
1606
- parseInt(e[0] + e[0], 16) / 255,
1607
- parseInt(e[1] + e[1], 16) / 255,
1608
- parseInt(e[2] + e[2], 16) / 255
125
+ function m(e) {
126
+ if (Array.isArray(e)) return e;
127
+ let t = e.slice(1, 7);
128
+ return t.length === 3 ? [
129
+ parseInt(t[0] + t[0], 16) / 255,
130
+ parseInt(t[1] + t[1], 16) / 255,
131
+ parseInt(t[2] + t[2], 16) / 255
1609
132
  ] : [
1610
- parseInt(e.slice(0, 2), 16) / 255,
1611
- parseInt(e.slice(2, 4), 16) / 255,
1612
- parseInt(e.slice(4, 6), 16) / 255
133
+ parseInt(t.slice(0, 2), 16) / 255,
134
+ parseInt(t.slice(2, 4), 16) / 255,
135
+ parseInt(t.slice(4, 6), 16) / 255
1613
136
  ];
1614
137
  }
1615
- function H(r = {}, e, t = W) {
138
+ function h(e = {}, t, n = s) {
139
+ return {
140
+ ...t ? {
141
+ ...n,
142
+ ...p[t]
143
+ } : n,
144
+ ...e
145
+ };
146
+ }
147
+ //#endregion
148
+ //#region src/core/textures.ts
149
+ function g(e, t, n, r, i = "cover") {
150
+ let a;
151
+ a = i === "cover" ? Math.max(n / e, r / t) : i === "contain" ? Math.min(n / e, r / t) : typeof i == "string" && i.endsWith("%") ? Math.min(n / e, r / t) * (parseFloat(i) / 100) : typeof i == "string" && i.endsWith("px") ? parseFloat(i) / Math.max(e, t) : typeof i == "number" ? i : Math.max(n / e, r / t);
152
+ let o = e * a, s = t * a;
1616
153
  return {
1617
- ...e ? {
1618
- ...t,
1619
- ...q[e]
1620
- } : t,
1621
- ...r
154
+ x: (n - o) / 2,
155
+ y: (r - s) / 2,
156
+ drawW: o,
157
+ drawH: s
1622
158
  };
1623
159
  }
1624
- const w = \`precision highp float;
1625
- attribute vec2 aPosition;
1626
- varying vec2 vUv;
1627
- varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
1628
- uniform vec2 texelSize;
1629
- void main () {
1630
- vUv = aPosition * 0.5 + 0.5;
1631
- vL = vUv - vec2(texelSize.x, 0.0);
1632
- vR = vUv + vec2(texelSize.x, 0.0);
1633
- vT = vUv + vec2(0.0, texelSize.y);
1634
- vB = vUv - vec2(0.0, texelSize.y);
1635
- gl_Position = vec4(aPosition, 0.0, 1.0);
1636
- }\`, Q = \`precision highp float;
1637
- varying vec2 vUv;
1638
- uniform sampler2D uVelocity;
1639
- uniform sampler2D uSource;
1640
- uniform sampler2D uObstacle;
1641
- uniform vec2 texelSize;
1642
- uniform float dt;
1643
- uniform float dissipation;
1644
- void main () {
1645
- float obs = texture2D(uObstacle, vUv).r;
1646
- vec2 coord = vUv - dt * texture2D(uVelocity, vUv).xy * texelSize;
1647
-
1648
-
1649
-
1650
- gl_FragColor = dissipation * texture2D(uSource, coord) * (1.0 - obs);
1651
- }\`, j = \`precision highp float;
1652
- varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
1653
- uniform sampler2D uVelocity;
1654
- uniform sampler2D uObstacle;
1655
- void main () {
1656
- float L = texture2D(uVelocity, vL).x * (1.0 - texture2D(uObstacle, vL).r);
1657
- float R = texture2D(uVelocity, vR).x * (1.0 - texture2D(uObstacle, vR).r);
1658
- float T = texture2D(uVelocity, vT).y * (1.0 - texture2D(uObstacle, vT).r);
1659
- float B = texture2D(uVelocity, vB).y * (1.0 - texture2D(uObstacle, vB).r);
1660
- gl_FragColor = vec4(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);
1661
- }\`, K = \`precision highp float;
1662
- varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
1663
- uniform sampler2D uPressure;
1664
- uniform sampler2D uDivergence;
1665
- uniform sampler2D uObstacle;
1666
- void main () {
1667
- float C = texture2D(uPressure, vUv).x;
1668
- float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);
1669
- float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);
1670
- float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);
1671
- float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);
1672
- float div = texture2D(uDivergence, vUv).x;
1673
- gl_FragColor = vec4((L + R + B + T - div) * 0.25, 0.0, 0.0, 1.0);
1674
- }\`, J = \`precision highp float;
1675
- varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
1676
- uniform sampler2D uPressure;
1677
- uniform sampler2D uVelocity;
1678
- uniform sampler2D uObstacle;
1679
- void main () {
1680
- float obs = texture2D(uObstacle, vUv).r;
1681
- float C = texture2D(uPressure, vUv).x;
1682
- float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);
1683
- float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);
1684
- float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);
1685
- float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);
1686
- vec2 vel = (texture2D(uVelocity, vUv).xy - vec2(R - L, T - B)) * (1.0 - obs);
1687
- gl_FragColor = vec4(vel, 0.0, 1.0);
1688
- }\`, Z = \`precision highp float;
1689
- varying vec2 vUv;
1690
- uniform sampler2D uTarget;
1691
- uniform float aspectRatio;
1692
- uniform vec3 color;
1693
- uniform vec2 point;
1694
- uniform float radius;
1695
- void main () {
1696
- vec2 p = vUv - point.xy;
1697
- p.x *= aspectRatio;
1698
- vec3 splat = exp(-dot(p, p) / radius) * color;
1699
- gl_FragColor = vec4(texture2D(uTarget, vUv).xyz + splat, 1.0);
1700
- }\`, ee = \`precision highp float;
1701
- varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
1702
- uniform sampler2D uVelocity;
1703
- void main () {
1704
- float L = texture2D(uVelocity, vL).y;
1705
- float R = texture2D(uVelocity, vR).y;
1706
- float T = texture2D(uVelocity, vT).x;
1707
- float B = texture2D(uVelocity, vB).x;
1708
- gl_FragColor = vec4(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);
1709
- }\`, te = \`precision highp float;
1710
- varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;
1711
- uniform sampler2D uVelocity;
1712
- uniform sampler2D uCurl;
1713
- uniform float curl;
1714
- uniform float dt;
1715
- void main () {
1716
- float L = texture2D(uCurl, vL).x;
1717
- float R = texture2D(uCurl, vR).x;
1718
- float T = texture2D(uCurl, vT).x;
1719
- float B = texture2D(uCurl, vB).x;
1720
- float C = texture2D(uCurl, vUv).x;
1721
- vec2 force = 0.5 * vec2(abs(T) - abs(B), abs(R) - abs(L));
1722
- force /= length(force) + 0.0001;
1723
- force *= curl * 30.0 * C;
1724
- gl_FragColor = vec4(texture2D(uVelocity, vUv).xy + force * dt, 0.0, 1.0);
1725
- }\`, re = \`precision highp float;
1726
- varying vec2 vUv;
1727
- uniform sampler2D uTexture;
1728
- uniform sampler2D uObstacle;
1729
- uniform sampler2D uBackground;
1730
- uniform sampler2D uCoverage;
1731
- uniform sampler2D uVelocity;
1732
- uniform vec2 texelSize;
1733
- uniform vec3 uWaterColor;
1734
- uniform vec3 uGlowColor;
1735
- uniform float uRefraction;
1736
- uniform float uSpecularExp;
1737
- uniform float uShine;
1738
- uniform float uWarpStrength;
1739
- uniform int uAlgorithm;
1740
- uniform int uEnableAlpha;
1741
- void main () {
1742
- float obs = texture2D(uObstacle, vUv).r;
1743
-
1744
-
1745
- float density = max(texture2D(uTexture, vUv).r, 0.0) * (1.0 - obs);
1746
- float coverage = texture2D(uCoverage, vUv).r;
1747
-
1748
-
1749
-
1750
-
1751
- float sx = texelSize.x * 6.0, sy = texelSize.y * 6.0;
1752
- float d00 = max(texture2D(uTexture, vUv + vec2(-sx, -sy)).r, 0.0);
1753
- float d10 = max(texture2D(uTexture, vUv + vec2(0.0, -sy)).r, 0.0);
1754
- float d20 = max(texture2D(uTexture, vUv + vec2( sx, -sy)).r, 0.0);
1755
- float d01 = max(texture2D(uTexture, vUv + vec2(-sx, 0.0)).r, 0.0);
1756
- float d21 = max(texture2D(uTexture, vUv + vec2( sx, 0.0)).r, 0.0);
1757
- float d02 = max(texture2D(uTexture, vUv + vec2(-sx, sy)).r, 0.0);
1758
- float d12 = max(texture2D(uTexture, vUv + vec2(0.0, sy)).r, 0.0);
1759
- float d22 = max(texture2D(uTexture, vUv + vec2( sx, sy)).r, 0.0);
1760
- float gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);
1761
- float gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);
1762
- vec3 normal = normalize(vec3(gx, gy, 1.2));
1763
- vec3 lightDir = normalize(vec3(0.5, 1.0, 0.5));
1764
- vec3 halfV = normalize(lightDir + vec3(0.0, 0.0, 1.0));
1765
-
1766
-
1767
- float specDen = density * min(density * 5.0, 1.0);
1768
- float spec = pow(max(dot(normal, halfV), 0.0), uSpecularExp) * uShine * specDen;
1769
-
1770
-
1771
-
1772
- vec3 bgRaw = texture2D(uBackground, vUv).rgb;
1773
- vec3 bg = mix(uWaterColor, bgRaw, coverage);
1774
- vec3 color = bg;
1775
- if (uAlgorithm == 1) {
1776
-
1777
-
1778
- vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 3.0, 0.0, 1.0);
1779
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);
1780
- color = refrBg + spec * uGlowColor * 2.5;
1781
- color = mix(color, bg * 0.6, obs * 0.3);
1782
- } else if (uAlgorithm == 2) {
1783
-
1784
-
1785
- float inkD = min(density * 4.0, 1.0);
1786
- vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 0.4, 0.0, 1.0);
1787
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);
1788
- color = mix(refrBg, uWaterColor + spec * uGlowColor, inkD);
1789
- color = mix(color, bg * 0.5, obs * 0.15);
1790
- } else if (uAlgorithm == 3) {
1791
-
1792
-
1793
- vec2 vel = texture2D(uVelocity, vUv).xy;
1794
- float velMag = clamp(length(vel) * 20.0, 0.0, 1.0);
1795
- vec2 warpUv = clamp(vUv + vel * uWarpStrength, 0.0, 1.0);
1796
- vec3 warpBg = mix(uWaterColor, texture2D(uBackground, warpUv).rgb, coverage);
1797
- color = mix(bg, warpBg, velMag * (1.0 - obs));
1798
- color += spec * uGlowColor * velMag * 1.5;
1799
- color += uWaterColor * density * 0.3;
1800
- color = mix(color, bg * 0.5, obs * 0.2);
1801
- } else if (uAlgorithm == 4) {
1802
-
1803
-
1804
- vec2 rippleUv = clamp(vUv + normal.xy * uRefraction * density * 6.0, 0.0, 1.0);
1805
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, rippleUv, 1.0 - obs)).rgb, coverage);
1806
- float fresnel = pow(clamp(1.0 - dot(normal, vec3(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;
1807
- color = refrBg;
1808
- color += fresnel * uGlowColor * 2.0;
1809
- color += spec * uGlowColor * density * 2.0;
1810
- color = mix(color, bg * 0.5, obs * 0.2);
1811
- } else {
1812
-
1813
-
1814
- vec2 refrUv = vUv + normal.xy * uRefraction * density;
1815
- vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);
1816
- color = mix(refrBg, uWaterColor, min(density * 1.5, 0.8));
1817
- color += spec * uGlowColor;
1818
- color = mix(color, bg * 0.5, obs * 0.2);
1819
- }
1820
-
1821
-
1822
- float alpha = clamp(max(density * 1.5, coverage), 0.0, 1.0);
1823
- if (uEnableAlpha == 1) {
1824
- gl_FragColor = vec4(color * alpha, alpha);
1825
- } else {
1826
- gl_FragColor = vec4(color, 1.0);
1827
- }
1828
- }\`;
1829
- function ie(r, e = !0) {
1830
- const t = {
1831
- alpha: e,
160
+ function _(e, t, n, r, i = null, a = "cover") {
161
+ let { text: o, fontSize: s, color: c, fontFamily: l = "sans-serif", fontWeight: u = 900 } = r, d = new OffscreenCanvas(t, n), f = d.getContext("2d");
162
+ ((e) => {
163
+ if (i) {
164
+ f.clearRect(0, 0, t, n), f.fillStyle = "black", f.fillRect(0, 0, t, n);
165
+ let { x: e, y: r, drawW: o, drawH: s } = g(i.width, i.height, t, n, a);
166
+ f.drawImage(i, e, r, o, s);
167
+ } else f.fillStyle = "black", f.fillRect(0, 0, t, n);
168
+ f.fillStyle = e, f.font = `${u} ${s}px ${l}`, f.textAlign = "center", f.textBaseline = "middle", f.fillText(o, t / 2, n / 2);
169
+ })(c);
170
+ let p = y(e, d);
171
+ f.fillStyle = "black", f.fillRect(0, 0, t, n), f.fillStyle = "white", f.font = `${u} ${s}px ${l}`, f.textAlign = "center", f.textBaseline = "middle", f.fillText(o, t / 2, n / 2);
172
+ let m = y(e, d);
173
+ return {
174
+ backgroundTex: p,
175
+ obstacleTex: m,
176
+ coverageTex: m
177
+ };
178
+ }
179
+ function v(e, t, n, r, i = 0, a = "cover", o = null, s = "cover") {
180
+ let c = new OffscreenCanvas(n, r), l = c.getContext("2d"), { x: u, y: d, drawW: f, drawH: p } = g(t.width, t.height, n, r, a);
181
+ if (l.clearRect(0, 0, n, r), l.fillStyle = "black", l.fillRect(0, 0, n, r), o) {
182
+ let { x: e, y: t, drawW: a, drawH: c } = g(o.width, o.height, n, r, s);
183
+ l.filter = `brightness(${i}) blur(8px)`, l.drawImage(o, e, t, a, c), l.filter = "none";
184
+ }
185
+ l.drawImage(t, u, d, f, p);
186
+ let m = y(e, c);
187
+ l.clearRect(0, 0, n, r), l.fillStyle = "black", l.fillRect(0, 0, n, r), l.filter = `brightness(${i}) blur(8px)`, l.drawImage(t, u, d, f, p), l.filter = "none";
188
+ let h = y(e, c);
189
+ return l.clearRect(0, 0, n, r), l.fillStyle = "black", l.fillRect(0, 0, n, r), l.fillStyle = "white", l.fillRect(Math.max(0, u), Math.max(0, d), Math.min(f, n - Math.max(0, u)), Math.min(p, r - Math.max(0, d))), {
190
+ backgroundTex: m,
191
+ obstacleTex: h,
192
+ coverageTex: y(e, c)
193
+ };
194
+ }
195
+ function y(e, t) {
196
+ let n = e.createTexture();
197
+ return e.bindTexture(e.TEXTURE_2D, n), e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, !0), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, t), 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), n;
198
+ }
199
+ function b(e, t, n, r, i = null, a = "cover") {
200
+ let { text: o, fontSize: s, color: c, fontFamily: l = "sans-serif", fontWeight: u = 900 } = r, d = new OffscreenCanvas(t, n), f = d.getContext("2d");
201
+ ((e) => {
202
+ if (i) {
203
+ f.clearRect(0, 0, t, n), f.fillStyle = "black", f.fillRect(0, 0, t, n);
204
+ let { x: e, y: r, drawW: o, drawH: s } = g(i.width, i.height, t, n, a);
205
+ f.drawImage(i, e, r, o, s);
206
+ } else f.fillStyle = "black", f.fillRect(0, 0, t, n);
207
+ f.fillStyle = e, f.font = `${u} ${s}px ${l}`, f.textAlign = "center", f.textBaseline = "middle", f.fillText(o, t / 2, n / 2);
208
+ })(c);
209
+ let p = S(e, d, t, n);
210
+ f.fillStyle = "black", f.fillRect(0, 0, t, n), f.fillStyle = "white", f.font = `${u} ${s}px ${l}`, f.textAlign = "center", f.textBaseline = "middle", f.fillText(o, t / 2, n / 2);
211
+ let m = S(e, d, t, n);
212
+ return {
213
+ backgroundTex: p,
214
+ backgroundView: p.createView(),
215
+ obstacleTex: m,
216
+ obstacleView: m.createView(),
217
+ coverageTex: m,
218
+ coverageView: m.createView(),
219
+ sharedCoverage: !0
220
+ };
221
+ }
222
+ function x(e, t, n, r, i = 0, a = "cover", o = null, s = "cover") {
223
+ let c = new OffscreenCanvas(n, r), l = c.getContext("2d"), { x: u, y: d, drawW: f, drawH: p } = g(t.width, t.height, n, r, a);
224
+ if (l.clearRect(0, 0, n, r), l.fillStyle = "black", l.fillRect(0, 0, n, r), o) {
225
+ let { x: e, y: t, drawW: a, drawH: c } = g(o.width, o.height, n, r, s);
226
+ l.filter = `brightness(${i}) blur(8px)`, l.drawImage(o, e, t, a, c), l.filter = "none";
227
+ }
228
+ l.drawImage(t, u, d, f, p);
229
+ let m = S(e, c, n, r);
230
+ l.clearRect(0, 0, n, r), l.fillStyle = "black", l.fillRect(0, 0, n, r), l.filter = `brightness(${i}) blur(8px)`, l.drawImage(t, u, d, f, p), l.filter = "none";
231
+ let h = S(e, c, n, r);
232
+ l.clearRect(0, 0, n, r), l.fillStyle = "black", l.fillRect(0, 0, n, r), l.fillStyle = "white", l.fillRect(Math.max(0, u), Math.max(0, d), Math.min(f, n - Math.max(0, u)), Math.min(p, r - Math.max(0, d)));
233
+ let _ = S(e, c, n, r);
234
+ return {
235
+ backgroundTex: m,
236
+ backgroundView: m.createView(),
237
+ obstacleTex: h,
238
+ obstacleView: h.createView(),
239
+ coverageTex: _,
240
+ coverageView: _.createView(),
241
+ sharedCoverage: !1
242
+ };
243
+ }
244
+ function S(e, t, n, r) {
245
+ let i = e.createTexture({
246
+ size: [n, r],
247
+ format: "rgba8unorm",
248
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
249
+ });
250
+ return e.queue.copyExternalImageToTexture({ source: t }, { texture: i }, [n, r]), i;
251
+ }
252
+ async function C(e) {
253
+ let t = await fetch(e);
254
+ if (!t.ok) throw Error(`Failed to fetch image: ${e} (${t.status})`);
255
+ let n = await t.blob();
256
+ return createImageBitmap(n);
257
+ }
258
+ //#endregion
259
+ //#region src/utils/index.ts
260
+ var w = "precision highp float;\n attribute vec2 aPosition;\n varying vec2 vUv;\n varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform vec2 texelSize;\n void main () {\n vUv = aPosition * 0.5 + 0.5;\n vL = vUv - vec2(texelSize.x, 0.0);\n vR = vUv + vec2(texelSize.x, 0.0);\n vT = vUv + vec2(0.0, texelSize.y);\n vB = vUv - vec2(0.0, texelSize.y);\n gl_Position = vec4(aPosition, 0.0, 1.0);\n }", T = "precision highp float;\n varying vec2 vUv;\n uniform sampler2D uVelocity;\n uniform sampler2D uSource;\n uniform sampler2D uObstacle;\n uniform vec2 texelSize;\n uniform float dt;\n uniform float dissipation;\n void main () {\n float obs = texture2D(uObstacle, vUv).r;\n vec2 coord = vUv - dt * texture2D(uVelocity, vUv).xy * texelSize;\n \n \n \n gl_FragColor = dissipation * texture2D(uSource, coord) * (1.0 - obs);\n }", E = "precision highp float;\n varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uVelocity;\n uniform sampler2D uObstacle;\n void main () {\n float L = texture2D(uVelocity, vL).x * (1.0 - texture2D(uObstacle, vL).r);\n float R = texture2D(uVelocity, vR).x * (1.0 - texture2D(uObstacle, vR).r);\n float T = texture2D(uVelocity, vT).y * (1.0 - texture2D(uObstacle, vT).r);\n float B = texture2D(uVelocity, vB).y * (1.0 - texture2D(uObstacle, vB).r);\n gl_FragColor = vec4(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);\n }", D = "precision highp float;\n varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uPressure;\n uniform sampler2D uDivergence;\n uniform sampler2D uObstacle;\n void main () {\n float C = texture2D(uPressure, vUv).x;\n float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);\n float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);\n float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);\n float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);\n float div = texture2D(uDivergence, vUv).x;\n gl_FragColor = vec4((L + R + B + T - div) * 0.25, 0.0, 0.0, 1.0);\n }", O = "precision highp float;\n varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uPressure;\n uniform sampler2D uVelocity;\n uniform sampler2D uObstacle;\n void main () {\n float obs = texture2D(uObstacle, vUv).r;\n float C = texture2D(uPressure, vUv).x;\n float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);\n float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);\n float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);\n float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);\n vec2 vel = (texture2D(uVelocity, vUv).xy - vec2(R - L, T - B)) * (1.0 - obs);\n gl_FragColor = vec4(vel, 0.0, 1.0);\n }", k = "precision highp float;\n varying vec2 vUv;\n uniform sampler2D uTarget;\n uniform float aspectRatio;\n uniform vec3 color;\n uniform vec2 point;\n uniform float radius;\n void main () {\n vec2 p = vUv - point.xy;\n p.x *= aspectRatio;\n vec3 splat = exp(-dot(p, p) / radius) * color;\n gl_FragColor = vec4(texture2D(uTarget, vUv).xyz + splat, 1.0);\n }", A = "precision highp float;\n varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uVelocity;\n void main () {\n float L = texture2D(uVelocity, vL).y;\n float R = texture2D(uVelocity, vR).y;\n float T = texture2D(uVelocity, vT).x;\n float B = texture2D(uVelocity, vB).x;\n gl_FragColor = vec4(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);\n }", j = "precision highp float;\n varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uVelocity;\n uniform sampler2D uCurl;\n uniform float curl;\n uniform float dt;\n void main () {\n float L = texture2D(uCurl, vL).x;\n float R = texture2D(uCurl, vR).x;\n float T = texture2D(uCurl, vT).x;\n float B = texture2D(uCurl, vB).x;\n float C = texture2D(uCurl, vUv).x;\n vec2 force = 0.5 * vec2(abs(T) - abs(B), abs(R) - abs(L));\n force /= length(force) + 0.0001;\n force *= curl * 30.0 * C;\n gl_FragColor = vec4(texture2D(uVelocity, vUv).xy + force * dt, 0.0, 1.0);\n }", M = "precision highp float;\n varying vec2 vUv;\n uniform sampler2D uTexture;\n uniform sampler2D uObstacle;\n uniform sampler2D uBackground;\n uniform sampler2D uCoverage;\n uniform sampler2D uVelocity;\n uniform vec2 texelSize;\n uniform vec3 uWaterColor;\n uniform vec3 uGlowColor;\n uniform float uRefraction;\n uniform float uSpecularExp;\n uniform float uShine;\n uniform float uWarpStrength;\n uniform int uAlgorithm;\n uniform int uEnableAlpha;\n void main () {\n float obs = texture2D(uObstacle, vUv).r;\n \n \n float density = max(texture2D(uTexture, vUv).r, 0.0) * (1.0 - obs);\n float coverage = texture2D(uCoverage, vUv).r;\n \n \n \n \n float sx = texelSize.x * 6.0, sy = texelSize.y * 6.0;\n float d00 = max(texture2D(uTexture, vUv + vec2(-sx, -sy)).r, 0.0);\n float d10 = max(texture2D(uTexture, vUv + vec2(0.0, -sy)).r, 0.0);\n float d20 = max(texture2D(uTexture, vUv + vec2( sx, -sy)).r, 0.0);\n float d01 = max(texture2D(uTexture, vUv + vec2(-sx, 0.0)).r, 0.0);\n float d21 = max(texture2D(uTexture, vUv + vec2( sx, 0.0)).r, 0.0);\n float d02 = max(texture2D(uTexture, vUv + vec2(-sx, sy)).r, 0.0);\n float d12 = max(texture2D(uTexture, vUv + vec2(0.0, sy)).r, 0.0);\n float d22 = max(texture2D(uTexture, vUv + vec2( sx, sy)).r, 0.0);\n float gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);\n float gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);\n vec3 normal = normalize(vec3(gx, gy, 1.2));\n vec3 lightDir = normalize(vec3(0.5, 1.0, 0.5));\n vec3 halfV = normalize(lightDir + vec3(0.0, 0.0, 1.0));\n \n \n float specDen = density * min(density * 5.0, 1.0);\n float spec = pow(max(dot(normal, halfV), 0.0), uSpecularExp) * uShine * specDen;\n \n \n \n vec3 bgRaw = texture2D(uBackground, vUv).rgb;\n vec3 bg = mix(uWaterColor, bgRaw, coverage);\n vec3 color = bg;\n if (uAlgorithm == 1) {\n \n \n vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 3.0, 0.0, 1.0);\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);\n color = refrBg + spec * uGlowColor * 2.5;\n color = mix(color, bg * 0.6, obs * 0.3);\n } else if (uAlgorithm == 2) {\n \n \n float inkD = min(density * 4.0, 1.0);\n vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 0.4, 0.0, 1.0);\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);\n color = mix(refrBg, uWaterColor + spec * uGlowColor, inkD);\n color = mix(color, bg * 0.5, obs * 0.15);\n } else if (uAlgorithm == 3) {\n \n \n vec2 vel = texture2D(uVelocity, vUv).xy;\n float velMag = clamp(length(vel) * 20.0, 0.0, 1.0);\n vec2 warpUv = clamp(vUv + vel * uWarpStrength, 0.0, 1.0);\n vec3 warpBg = mix(uWaterColor, texture2D(uBackground, warpUv).rgb, coverage);\n color = mix(bg, warpBg, velMag * (1.0 - obs));\n color += spec * uGlowColor * velMag * 1.5;\n color += uWaterColor * density * 0.3;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else if (uAlgorithm == 4) {\n \n \n vec2 rippleUv = clamp(vUv + normal.xy * uRefraction * density * 6.0, 0.0, 1.0);\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, rippleUv, 1.0 - obs)).rgb, coverage);\n float fresnel = pow(clamp(1.0 - dot(normal, vec3(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;\n color = refrBg;\n color += fresnel * uGlowColor * 2.0;\n color += spec * uGlowColor * density * 2.0;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else {\n \n \n vec2 refrUv = vUv + normal.xy * uRefraction * density;\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);\n color = mix(refrBg, uWaterColor, min(density * 1.5, 0.8));\n color += spec * uGlowColor;\n color = mix(color, bg * 0.5, obs * 0.2);\n }\n \n \n float alpha = clamp(max(density * 1.5, coverage), 0.0, 1.0);\n if (uEnableAlpha == 1) {\n gl_FragColor = vec4(color * alpha, alpha);\n } else {\n gl_FragColor = vec4(color, 1.0);\n }\n }";
261
+ //#endregion
262
+ //#region src/core/gl-utils.ts
263
+ function N(e, t = !0) {
264
+ let n = {
265
+ alpha: t,
1832
266
  depth: !1,
1833
267
  stencil: !1,
1834
268
  antialias: !0,
1835
269
  preserveDrawingBuffer: !1
1836
- };
1837
- let i = r.getContext("webgl2", t);
1838
- const s = !!i;
1839
- s || (i = r.getContext("webgl", t), i.getExtension("EXT_color_buffer_half_float"));
1840
- const o = s ? null : i.getExtension("OES_texture_half_float"), u = s ? i.HALF_FLOAT : o.HALF_FLOAT_OES;
1841
- return i.getExtension("EXT_color_buffer_float"), i.getExtension("OES_texture_half_float_linear"), {
1842
- type: s ? "webgl2" : "webgl1",
1843
- gl: i,
1844
- isWebGL2: s,
270
+ }, r = e.getContext("webgl2", n), i = !!r;
271
+ i || (r = e.getContext("webgl", n), r.getExtension("EXT_color_buffer_half_float"));
272
+ let a = i ? null : r.getExtension("OES_texture_half_float"), o = i ? r.HALF_FLOAT : a.HALF_FLOAT_OES;
273
+ return r.getExtension("EXT_color_buffer_float"), r.getExtension("OES_texture_half_float_linear"), {
274
+ type: i ? "webgl2" : "webgl1",
275
+ gl: r,
276
+ isWebGL2: i,
1845
277
  ext: {
1846
- internalFormat: s ? i.RGBA16F : i.RGBA,
1847
- format: i.RGBA,
1848
- type: u
278
+ internalFormat: i ? r.RGBA16F : r.RGBA,
279
+ format: r.RGBA,
280
+ type: o
1849
281
  }
1850
282
  };
1851
283
  }
1852
- async function se(r, e = !0) {
284
+ async function P(e, t = !0) {
1853
285
  if (typeof navigator > "u" || !navigator.gpu) return null;
1854
286
  try {
1855
- const t = await navigator.gpu.requestAdapter();
1856
- if (!t) return null;
1857
- const i = await t.requestDevice(), s = r.getContext("webgpu");
1858
- if (!s) return null;
1859
- const o = navigator.gpu.getPreferredCanvasFormat();
1860
- return s.configure({
1861
- device: i,
1862
- format: o,
1863
- alphaMode: e ? "premultiplied" : "opaque"
287
+ let n = await navigator.gpu.requestAdapter();
288
+ if (!n) return null;
289
+ let r = await n.requestDevice(), i = e.getContext("webgpu");
290
+ if (!i) return null;
291
+ let a = navigator.gpu.getPreferredCanvasFormat();
292
+ return i.configure({
293
+ device: r,
294
+ format: a,
295
+ alphaMode: t ? "premultiplied" : "opaque"
1864
296
  }), {
1865
297
  type: "webgpu",
1866
- adapter: t,
1867
- device: i,
1868
- context: s,
1869
- format: o
298
+ adapter: n,
299
+ device: r,
300
+ context: i,
301
+ format: a
1870
302
  };
1871
303
  } catch {
1872
304
  return null;
1873
305
  }
1874
306
  }
1875
- var E = class {
307
+ var F = class {
1876
308
  program;
1877
309
  uniforms = {};
1878
310
  _gl;
1879
- constructor(r, e, t) {
1880
- this._gl = r, this.program = r.createProgram(), r.attachShader(this.program, this._compile(r.VERTEX_SHADER, e)), r.attachShader(this.program, this._compile(r.FRAGMENT_SHADER, t)), r.linkProgram(this.program);
1881
- const i = r.getProgramParameter(this.program, r.ACTIVE_UNIFORMS);
1882
- for (let s = 0; s < i; s++) {
1883
- const o = r.getActiveUniform(this.program, s).name;
1884
- this.uniforms[o] = r.getUniformLocation(this.program, o);
311
+ constructor(e, t, n) {
312
+ this._gl = e, this.program = e.createProgram(), e.attachShader(this.program, this._compile(e.VERTEX_SHADER, t)), e.attachShader(this.program, this._compile(e.FRAGMENT_SHADER, n)), e.linkProgram(this.program);
313
+ let r = e.getProgramParameter(this.program, e.ACTIVE_UNIFORMS);
314
+ for (let t = 0; t < r; t++) {
315
+ let n = e.getActiveUniform(this.program, t).name;
316
+ this.uniforms[n] = e.getUniformLocation(this.program, n);
1885
317
  }
1886
318
  }
1887
- _compile(r, e) {
1888
- const t = this._gl, i = t.createShader(r);
1889
- return t.shaderSource(i, e), t.compileShader(i), i;
319
+ _compile(e, t) {
320
+ let n = this._gl, r = n.createShader(e);
321
+ return n.shaderSource(r, t), n.compileShader(r), r;
1890
322
  }
1891
323
  bind() {
1892
324
  this._gl.useProgram(this.program);
@@ -1895,50 +327,50 @@ var E = class {
1895
327
  this._gl.deleteProgram(this.program);
1896
328
  }
1897
329
  };
1898
- function oe(r) {
330
+ function I(e) {
1899
331
  return {
1900
- advection: new E(r, w, Q),
1901
- divergence: new E(r, w, j),
1902
- pressure: new E(r, w, K),
1903
- gradientSubtract: new E(r, w, J),
1904
- splat: new E(r, w, Z),
1905
- curl: new E(r, w, ee),
1906
- vorticity: new E(r, w, te),
1907
- display: new E(r, w, re)
332
+ advection: new F(e, w, T),
333
+ divergence: new F(e, w, E),
334
+ pressure: new F(e, w, D),
335
+ gradientSubtract: new F(e, w, O),
336
+ splat: new F(e, w, k),
337
+ curl: new F(e, w, A),
338
+ vorticity: new F(e, w, j),
339
+ display: new F(e, w, M)
1908
340
  };
1909
341
  }
1910
- function L(r, e, t, i) {
1911
- r.activeTexture(r.TEXTURE0);
1912
- const s = r.createTexture();
1913
- r.bindTexture(r.TEXTURE_2D, s), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.texImage2D(r.TEXTURE_2D, 0, e.internalFormat, t, i, 0, e.format, e.type, null);
1914
- const o = r.createFramebuffer();
1915
- return r.bindFramebuffer(r.FRAMEBUFFER, o), r.framebufferTexture2D(r.FRAMEBUFFER, r.COLOR_ATTACHMENT0, r.TEXTURE_2D, s, 0), {
1916
- tex: s,
1917
- fbo: o,
1918
- width: t,
1919
- height: i
342
+ function L(e, t, n, r) {
343
+ e.activeTexture(e.TEXTURE0);
344
+ let i = e.createTexture();
345
+ e.bindTexture(e.TEXTURE_2D, i), 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(e.TEXTURE_2D, 0, t.internalFormat, n, r, 0, t.format, t.type, null);
346
+ let a = e.createFramebuffer();
347
+ return e.bindFramebuffer(e.FRAMEBUFFER, a), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, i, 0), {
348
+ tex: i,
349
+ fbo: a,
350
+ width: n,
351
+ height: r
1920
352
  };
1921
353
  }
1922
- function X(r, e, t, i) {
1923
- let s = L(r, e, t, i), o = L(r, e, t, i);
354
+ function R(e, t, n, r) {
355
+ let i = L(e, t, n, r), a = L(e, t, n, r);
1924
356
  return {
1925
357
  get read() {
1926
- return s;
358
+ return i;
1927
359
  },
1928
360
  get write() {
1929
- return o;
361
+ return a;
1930
362
  },
1931
363
  swap() {
1932
- [s, o] = [o, s];
364
+ [i, a] = [a, i];
1933
365
  },
1934
366
  dispose() {
1935
- r.deleteTexture(s.tex), r.deleteFramebuffer(s.fbo), r.deleteTexture(o.tex), r.deleteFramebuffer(o.fbo);
367
+ e.deleteTexture(i.tex), e.deleteFramebuffer(i.fbo), e.deleteTexture(a.tex), e.deleteFramebuffer(a.fbo);
1936
368
  }
1937
369
  };
1938
370
  }
1939
- function ae(r) {
1940
- const e = r.createBuffer();
1941
- return r.bindBuffer(r.ARRAY_BUFFER, e), r.bufferData(r.ARRAY_BUFFER, new Float32Array([
371
+ function z(e) {
372
+ let t = e.createBuffer();
373
+ return e.bindBuffer(e.ARRAY_BUFFER, t), e.bufferData(e.ARRAY_BUFFER, new Float32Array([
1942
374
  -1,
1943
375
  -1,
1944
376
  -1,
@@ -1947,284 +379,20 @@ function ae(r) {
1947
379
  1,
1948
380
  1,
1949
381
  -1
1950
- ]), r.STATIC_DRAW), r.vertexAttribPointer(0, 2, r.FLOAT, !1, 0, 0), r.enableVertexAttribArray(0), function(i) {
1951
- r.bindFramebuffer(r.FRAMEBUFFER, i), r.drawArrays(r.TRIANGLE_FAN, 0, 4);
382
+ ]), e.STATIC_DRAW), e.vertexAttribPointer(0, 2, e.FLOAT, !1, 0, 0), e.enableVertexAttribArray(0), function(t) {
383
+ e.bindFramebuffer(e.FRAMEBUFFER, t), e.drawArrays(e.TRIANGLE_FAN, 0, 4);
1952
384
  };
1953
385
  }
1954
- const ue = \`struct U {
1955
- texelSize : vec2f,
1956
- dt : f32,
1957
- dissipation: f32,
1958
- }
1959
- @group(0) @binding(0) var<uniform> u : U;
1960
- @group(0) @binding(1) var samp : sampler;
1961
- @group(0) @binding(2) var uVel : texture_2d<f32>;
1962
- @group(0) @binding(3) var uSrc : texture_2d<f32>;
1963
- @group(0) @binding(4) var uObs : texture_2d<f32>;
1964
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
1965
- var o: VSOut;
1966
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
1967
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
1968
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
1969
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
1970
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
1971
- o.pos = vec4f(a, 0.0, 1.0);
1972
- return o;
1973
- }
1974
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
1975
- let obs = textureSample(uObs, samp, i.uv).r;
1976
- let vel = textureSample(uVel, samp, i.uv).xy;
1977
- let coord = i.uv - u.dt * vel * u.texelSize;
1978
- let src = textureSample(uSrc, samp, coord);
1979
- return u.dissipation * src * (1.0 - obs);
1980
- }\`, ne = \`struct U { texelSize: vec2f, _pad: vec2f }
1981
- @group(0) @binding(0) var<uniform> u : U;
1982
- @group(0) @binding(1) var samp : sampler;
1983
- @group(0) @binding(2) var uVel : texture_2d<f32>;
1984
- @group(0) @binding(3) var uObs : texture_2d<f32>;
1985
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
1986
- var o: VSOut;
1987
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
1988
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
1989
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
1990
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
1991
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
1992
- o.pos = vec4f(a, 0.0, 1.0);
1993
- return o;
1994
- }
1995
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
1996
- let L = textureSample(uVel, samp, i.vL).x * (1.0 - textureSample(uObs, samp, i.vL).r);
1997
- let R = textureSample(uVel, samp, i.vR).x * (1.0 - textureSample(uObs, samp, i.vR).r);
1998
- let T = textureSample(uVel, samp, i.vT).y * (1.0 - textureSample(uObs, samp, i.vT).r);
1999
- let B = textureSample(uVel, samp, i.vB).y * (1.0 - textureSample(uObs, samp, i.vB).r);
2000
- return vec4f(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);
2001
- }\`, le = \`struct U { texelSize: vec2f, _pad: vec2f }
2002
- @group(0) @binding(0) var<uniform> u : U;
2003
- @group(0) @binding(1) var samp : sampler;
2004
- @group(0) @binding(2) var uPres: texture_2d<f32>;
2005
- @group(0) @binding(3) var uDiv : texture_2d<f32>;
2006
- @group(0) @binding(4) var uObs : texture_2d<f32>;
2007
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
2008
- var o: VSOut;
2009
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
2010
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
2011
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
2012
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
2013
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
2014
- o.pos = vec4f(a, 0.0, 1.0);
2015
- return o;
2016
- }
2017
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
2018
- let C = textureSample(uPres, samp, i.uv).x;
2019
- let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);
2020
- let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);
2021
- let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);
2022
- let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);
2023
- let dv = textureSample(uDiv, samp, i.uv).x;
2024
- return vec4f((L + R + B + T - dv) * 0.25, 0.0, 0.0, 1.0);
2025
- }\`, ce = \`struct U { texelSize: vec2f, _pad: vec2f }
2026
- @group(0) @binding(0) var<uniform> u : U;
2027
- @group(0) @binding(1) var samp : sampler;
2028
- @group(0) @binding(2) var uPres: texture_2d<f32>;
2029
- @group(0) @binding(3) var uVel : texture_2d<f32>;
2030
- @group(0) @binding(4) var uObs : texture_2d<f32>;
2031
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
2032
- var o: VSOut;
2033
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
2034
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
2035
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
2036
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
2037
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
2038
- o.pos = vec4f(a, 0.0, 1.0);
2039
- return o;
2040
- }
2041
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
2042
- let obs = textureSample(uObs, samp, i.uv).r;
2043
- let C = textureSample(uPres, samp, i.uv).x;
2044
- let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);
2045
- let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);
2046
- let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);
2047
- let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);
2048
- let vel = (textureSample(uVel, samp, i.uv).xy - vec2f(R - L, T - B)) * (1.0 - obs);
2049
- return vec4f(vel, 0.0, 1.0);
2050
- }\`, fe = \`struct U {
2051
- texelSize : vec2f,
2052
- aspectRatio: f32,
2053
- radius : f32,
2054
- color : vec4f,
2055
- point : vec2f,
2056
- _pad : vec2f,
2057
- }
2058
- @group(0) @binding(0) var<uniform> u : U;
2059
- @group(0) @binding(1) var samp : sampler;
2060
- @group(0) @binding(2) var uTgt : texture_2d<f32>;
2061
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
2062
- var o: VSOut;
2063
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
2064
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
2065
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
2066
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
2067
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
2068
- o.pos = vec4f(a, 0.0, 1.0);
2069
- return o;
2070
- }
2071
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
2072
- var p = i.uv - u.point;
2073
- p.x *= u.aspectRatio;
2074
- let sp = exp(-dot(p, p) / u.radius) * u.color.xyz;
2075
- return vec4f(textureSample(uTgt, samp, i.uv).xyz + sp, 1.0);
2076
- }\`, ve = \`struct U { texelSize: vec2f, _pad: vec2f }
2077
- @group(0) @binding(0) var<uniform> u : U;
2078
- @group(0) @binding(1) var samp : sampler;
2079
- @group(0) @binding(2) var uVel : texture_2d<f32>;
2080
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
2081
- var o: VSOut;
2082
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
2083
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
2084
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
2085
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
2086
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
2087
- o.pos = vec4f(a, 0.0, 1.0);
2088
- return o;
2089
- }
2090
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
2091
- let L = textureSample(uVel, samp, i.vL).y;
2092
- let R = textureSample(uVel, samp, i.vR).y;
2093
- let T = textureSample(uVel, samp, i.vT).x;
2094
- let B = textureSample(uVel, samp, i.vB).x;
2095
- return vec4f(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);
2096
- }\`, xe = \`struct U {
2097
- texelSize: vec2f,
2098
- curl : f32,
2099
- dt : f32,
2100
- }
2101
- @group(0) @binding(0) var<uniform> u : U;
2102
- @group(0) @binding(1) var samp : sampler;
2103
- @group(0) @binding(2) var uVel : texture_2d<f32>;
2104
- @group(0) @binding(3) var uCrl : texture_2d<f32>;
2105
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
2106
- var o: VSOut;
2107
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
2108
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
2109
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
2110
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
2111
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
2112
- o.pos = vec4f(a, 0.0, 1.0);
2113
- return o;
2114
- }
2115
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
2116
- let L = textureSample(uCrl, samp, i.vL).x;
2117
- let R = textureSample(uCrl, samp, i.vR).x;
2118
- let T = textureSample(uCrl, samp, i.vT).x;
2119
- let B = textureSample(uCrl, samp, i.vB).x;
2120
- let C = textureSample(uCrl, samp, i.uv).x;
2121
- var force = 0.5 * vec2f(abs(T) - abs(B), abs(R) - abs(L));
2122
- force /= length(force) + 0.0001;
2123
- force *= u.curl * 30.0 * C;
2124
- let vel = textureSample(uVel, samp, i.uv).xy + force * u.dt;
2125
- return vec4f(vel, 0.0, 1.0);
2126
- }\`, me = \`struct U {
2127
- texelSize : vec2f,
2128
- refraction : f32,
2129
- specularExp : f32,
2130
- waterColor : vec4f,
2131
- glowColor : vec4f,
2132
- shine : f32,
2133
- warpStrength: f32,
2134
- algorithm : i32,
2135
- enableAlpha : i32,
2136
- }
2137
- @group(0) @binding(0) var<uniform> u : U;
2138
- @group(0) @binding(1) var samp : sampler;
2139
- @group(0) @binding(2) var uTex : texture_2d<f32>;
2140
- @group(0) @binding(3) var uObs : texture_2d<f32>;
2141
- @group(0) @binding(4) var uBg : texture_2d<f32>;
2142
- @group(0) @binding(5) var uCov : texture_2d<f32>;
2143
- @group(0) @binding(6) var uVel : texture_2d<f32>;
2144
- @vertex fn vs(@location(0) a: vec2f) -> VSOut {
2145
- var o: VSOut;
2146
- o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);
2147
- o.vL = o.uv - vec2f(u.texelSize.x, 0.0);
2148
- o.vR = o.uv + vec2f(u.texelSize.x, 0.0);
2149
- o.vT = o.uv + vec2f(0.0, u.texelSize.y);
2150
- o.vB = o.uv - vec2f(0.0, u.texelSize.y);
2151
- o.pos = vec4f(a, 0.0, 1.0);
2152
- return o;
2153
- }
2154
- @fragment fn fs(i: VSOut) -> @location(0) vec4f {
2155
- let obs = textureSample(uObs, samp, i.uv).r;
2156
- let density = max(textureSample(uTex, samp, i.uv).r, 0.0) * (1.0 - obs);
2157
- let cov = textureSample(uCov, samp, i.uv).r;
2158
- let sx = u.texelSize.x * 6.0;
2159
- let sy = u.texelSize.y * 6.0;
2160
- let d00 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, -sy)).r, 0.0);
2161
- let d10 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, -sy)).r, 0.0);
2162
- let d20 = max(textureSample(uTex, samp, i.uv + vec2f( sx, -sy)).r, 0.0);
2163
- let d01 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, 0.0)).r, 0.0);
2164
- let d21 = max(textureSample(uTex, samp, i.uv + vec2f( sx, 0.0)).r, 0.0);
2165
- let d02 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, sy)).r, 0.0);
2166
- let d12 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, sy)).r, 0.0);
2167
- let d22 = max(textureSample(uTex, samp, i.uv + vec2f( sx, sy)).r, 0.0);
2168
- let gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);
2169
- let gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);
2170
- let norm = normalize(vec3f(gx, gy, 1.2));
2171
- let ldir = normalize(vec3f(0.5, 1.0, 0.5));
2172
- let halfV = normalize(ldir + vec3f(0.0, 0.0, 1.0));
2173
- let specDen = density * min(density * 5.0, 1.0);
2174
- let spec = pow(max(dot(norm, halfV), 0.0), u.specularExp) * u.shine * specDen;
2175
- let bgRaw = textureSample(uBg, samp, i.uv).rgb;
2176
- let wc = u.waterColor.rgb;
2177
- let gc = u.glowColor.rgb;
2178
- let bg = mix(wc, bgRaw, cov);
2179
- var color = bg;
2180
- if (u.algorithm == 1) {
2181
- let ruv = clamp(i.uv + norm.xy * u.refraction * density * 3.0, vec2f(0.0), vec2f(1.0));
2182
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
2183
- color = rbg + spec * gc * 2.5;
2184
- color = mix(color, bg * 0.6, obs * 0.3);
2185
- } else if (u.algorithm == 2) {
2186
- let inkD = min(density * 4.0, 1.0);
2187
- let ruv = clamp(i.uv + norm.xy * u.refraction * density * 0.4, vec2f(0.0), vec2f(1.0));
2188
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
2189
- color = mix(rbg, wc + spec * gc, inkD);
2190
- color = mix(color, bg * 0.5, obs * 0.15);
2191
- } else if (u.algorithm == 3) {
2192
- let vel = textureSample(uVel, samp, i.uv).xy;
2193
- let velMag = clamp(length(vel) * 20.0, 0.0, 1.0);
2194
- let wuv = clamp(i.uv + vel * u.warpStrength, vec2f(0.0), vec2f(1.0));
2195
- let wbg = mix(wc, textureSample(uBg, samp, wuv).rgb, cov);
2196
- color = mix(bg, wbg, velMag * (1.0 - obs));
2197
- color += spec * gc * velMag * 1.5;
2198
- color += wc * density * 0.3;
2199
- color = mix(color, bg * 0.5, obs * 0.2);
2200
- } else if (u.algorithm == 4) {
2201
- let ruv = clamp(i.uv + norm.xy * u.refraction * density * 6.0, vec2f(0.0), vec2f(1.0));
2202
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
2203
- let fres = pow(clamp(1.0 - dot(norm, vec3f(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;
2204
- color = rbg;
2205
- color += fres * gc * 2.0;
2206
- color += spec * gc * density * 2.0;
2207
- color = mix(color, bg * 0.5, obs * 0.2);
2208
- } else {
2209
- let ruv = i.uv + norm.xy * u.refraction * density;
2210
- let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);
2211
- color = mix(rbg, wc, min(density * 1.5, 0.8));
2212
- color += spec * gc;
2213
- color = mix(color, bg * 0.5, obs * 0.2);
2214
- }
2215
- let alpha = clamp(max(density * 1.5, cov), 0.0, 1.0);
2216
- if (u.enableAlpha == 1) {
2217
- return vec4f(color * alpha, alpha);
2218
- }
2219
- return vec4f(color, 1.0);
2220
- }\`, pe = {
386
+ //#endregion
387
+ //#region src/core/wgsl-shaders.ts
388
+ var B = "struct U {\n texelSize : vec2f,\n dt : f32,\n dissipation: f32,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@group(0) @binding(3) var uSrc : texture_2d<f32>;\n@group(0) @binding(4) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let obs = textureSample(uObs, samp, i.uv).r;\n let vel = textureSample(uVel, samp, i.uv).xy;\n let coord = i.uv - u.dt * vel * u.texelSize;\n let src = textureSample(uSrc, samp, coord);\n return u.dissipation * src * (1.0 - obs);\n}", V = "struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@group(0) @binding(3) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let L = textureSample(uVel, samp, i.vL).x * (1.0 - textureSample(uObs, samp, i.vL).r);\n let R = textureSample(uVel, samp, i.vR).x * (1.0 - textureSample(uObs, samp, i.vR).r);\n let T = textureSample(uVel, samp, i.vT).y * (1.0 - textureSample(uObs, samp, i.vT).r);\n let B = textureSample(uVel, samp, i.vB).y * (1.0 - textureSample(uObs, samp, i.vB).r);\n return vec4f(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);\n}", H = "struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uPres: texture_2d<f32>;\n@group(0) @binding(3) var uDiv : texture_2d<f32>;\n@group(0) @binding(4) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let C = textureSample(uPres, samp, i.uv).x;\n let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);\n let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);\n let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);\n let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);\n let dv = textureSample(uDiv, samp, i.uv).x;\n return vec4f((L + R + B + T - dv) * 0.25, 0.0, 0.0, 1.0);\n}", U = "struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uPres: texture_2d<f32>;\n@group(0) @binding(3) var uVel : texture_2d<f32>;\n@group(0) @binding(4) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let obs = textureSample(uObs, samp, i.uv).r;\n let C = textureSample(uPres, samp, i.uv).x;\n let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);\n let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);\n let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);\n let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);\n let vel = (textureSample(uVel, samp, i.uv).xy - vec2f(R - L, T - B)) * (1.0 - obs);\n return vec4f(vel, 0.0, 1.0);\n}", ee = "struct U {\n texelSize : vec2f,\n aspectRatio: f32,\n radius : f32,\n color : vec4f, \n point : vec2f,\n _pad : vec2f,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uTgt : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n var p = i.uv - u.point;\n p.x *= u.aspectRatio;\n let sp = exp(-dot(p, p) / u.radius) * u.color.xyz;\n return vec4f(textureSample(uTgt, samp, i.uv).xyz + sp, 1.0);\n}", te = "struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let L = textureSample(uVel, samp, i.vL).y;\n let R = textureSample(uVel, samp, i.vR).y;\n let T = textureSample(uVel, samp, i.vT).x;\n let B = textureSample(uVel, samp, i.vB).x;\n return vec4f(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);\n}", ne = "struct U {\n texelSize: vec2f,\n curl : f32,\n dt : f32,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@group(0) @binding(3) var uCrl : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let L = textureSample(uCrl, samp, i.vL).x;\n let R = textureSample(uCrl, samp, i.vR).x;\n let T = textureSample(uCrl, samp, i.vT).x;\n let B = textureSample(uCrl, samp, i.vB).x;\n let C = textureSample(uCrl, samp, i.uv).x;\n var force = 0.5 * vec2f(abs(T) - abs(B), abs(R) - abs(L));\n force /= length(force) + 0.0001;\n force *= u.curl * 30.0 * C;\n let vel = textureSample(uVel, samp, i.uv).xy + force * u.dt;\n return vec4f(vel, 0.0, 1.0);\n}", re = "struct U {\n texelSize : vec2f,\n refraction : f32,\n specularExp : f32,\n waterColor : vec4f,\n glowColor : vec4f,\n shine : f32,\n warpStrength: f32,\n algorithm : i32,\n enableAlpha : i32,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uTex : texture_2d<f32>;\n@group(0) @binding(3) var uObs : texture_2d<f32>;\n@group(0) @binding(4) var uBg : texture_2d<f32>;\n@group(0) @binding(5) var uCov : texture_2d<f32>;\n@group(0) @binding(6) var uVel : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let obs = textureSample(uObs, samp, i.uv).r;\n let density = max(textureSample(uTex, samp, i.uv).r, 0.0) * (1.0 - obs);\n let cov = textureSample(uCov, samp, i.uv).r;\n let sx = u.texelSize.x * 6.0;\n let sy = u.texelSize.y * 6.0;\n let d00 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, -sy)).r, 0.0);\n let d10 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, -sy)).r, 0.0);\n let d20 = max(textureSample(uTex, samp, i.uv + vec2f( sx, -sy)).r, 0.0);\n let d01 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, 0.0)).r, 0.0);\n let d21 = max(textureSample(uTex, samp, i.uv + vec2f( sx, 0.0)).r, 0.0);\n let d02 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, sy)).r, 0.0);\n let d12 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, sy)).r, 0.0);\n let d22 = max(textureSample(uTex, samp, i.uv + vec2f( sx, sy)).r, 0.0);\n let gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);\n let gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);\n let norm = normalize(vec3f(gx, gy, 1.2));\n let ldir = normalize(vec3f(0.5, 1.0, 0.5));\n let halfV = normalize(ldir + vec3f(0.0, 0.0, 1.0));\n let specDen = density * min(density * 5.0, 1.0);\n let spec = pow(max(dot(norm, halfV), 0.0), u.specularExp) * u.shine * specDen;\n let bgRaw = textureSample(uBg, samp, i.uv).rgb;\n let wc = u.waterColor.rgb;\n let gc = u.glowColor.rgb;\n let bg = mix(wc, bgRaw, cov);\n var color = bg;\n if (u.algorithm == 1) {\n let ruv = clamp(i.uv + norm.xy * u.refraction * density * 3.0, vec2f(0.0), vec2f(1.0));\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n color = rbg + spec * gc * 2.5;\n color = mix(color, bg * 0.6, obs * 0.3);\n } else if (u.algorithm == 2) {\n let inkD = min(density * 4.0, 1.0);\n let ruv = clamp(i.uv + norm.xy * u.refraction * density * 0.4, vec2f(0.0), vec2f(1.0));\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n color = mix(rbg, wc + spec * gc, inkD);\n color = mix(color, bg * 0.5, obs * 0.15);\n } else if (u.algorithm == 3) {\n let vel = textureSample(uVel, samp, i.uv).xy;\n let velMag = clamp(length(vel) * 20.0, 0.0, 1.0);\n let wuv = clamp(i.uv + vel * u.warpStrength, vec2f(0.0), vec2f(1.0));\n let wbg = mix(wc, textureSample(uBg, samp, wuv).rgb, cov);\n color = mix(bg, wbg, velMag * (1.0 - obs));\n color += spec * gc * velMag * 1.5;\n color += wc * density * 0.3;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else if (u.algorithm == 4) {\n let ruv = clamp(i.uv + norm.xy * u.refraction * density * 6.0, vec2f(0.0), vec2f(1.0));\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n let fres = pow(clamp(1.0 - dot(norm, vec3f(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;\n color = rbg;\n color += fres * gc * 2.0;\n color += spec * gc * density * 2.0;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else {\n let ruv = i.uv + norm.xy * u.refraction * density;\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n color = mix(rbg, wc, min(density * 1.5, 0.8));\n color += spec * gc;\n color = mix(color, bg * 0.5, obs * 0.2);\n }\n let alpha = clamp(max(density * 1.5, cov), 0.0, 1.0);\n if (u.enableAlpha == 1) {\n return vec4f(color * alpha, alpha);\n }\n return vec4f(color, 1.0);\n}", ie = {
2221
389
  arrayStride: 8,
2222
390
  attributes: [{
2223
391
  shaderLocation: 0,
2224
392
  offset: 0,
2225
393
  format: "float32x2"
2226
394
  }]
2227
- }, G = new Float32Array([
395
+ }, ae = new Float32Array([
2228
396
  -1,
2229
397
  -1,
2230
398
  -1,
@@ -2238,64 +406,64 @@ const ue = \`struct U {
2238
406
  1,
2239
407
  1
2240
408
  ]);
2241
- function de(r) {
2242
- const e = r.createBuffer({
2243
- size: G.byteLength,
409
+ function oe(e) {
410
+ let t = e.createBuffer({
411
+ size: ae.byteLength,
2244
412
  usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
2245
413
  });
2246
- return r.queue.writeBuffer(e, 0, G), e;
414
+ return e.queue.writeBuffer(t, 0, ae), t;
2247
415
  }
2248
- function A(r, e, t, i) {
2249
- const s = r.createTexture({
2250
- size: [t, i],
2251
- format: e,
416
+ function W(e, t, n, r) {
417
+ let i = e.createTexture({
418
+ size: [n, r],
419
+ format: t,
2252
420
  usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
2253
421
  });
2254
422
  return {
2255
- tex: s,
2256
- view: s.createView(),
2257
- width: t,
2258
- height: i
423
+ tex: i,
424
+ view: i.createView(),
425
+ width: n,
426
+ height: r
2259
427
  };
2260
428
  }
2261
- function z(r, e, t, i) {
2262
- let s = A(r, e, t, i), o = A(r, e, t, i);
429
+ function G(e, t, n, r) {
430
+ let i = W(e, t, n, r), a = W(e, t, n, r);
2263
431
  return {
2264
432
  get read() {
2265
- return s;
433
+ return i;
2266
434
  },
2267
435
  get write() {
2268
- return o;
436
+ return a;
2269
437
  },
2270
438
  swap() {
2271
- [s, o] = [o, s];
439
+ [i, a] = [a, i];
2272
440
  },
2273
441
  dispose() {
2274
- s.tex.destroy(), o.tex.destroy();
442
+ i.tex.destroy(), a.tex.destroy();
2275
443
  }
2276
444
  };
2277
445
  }
2278
- function U(r, e, t, i) {
2279
- const s = r.createShaderModule({ code: e });
2280
- return r.createRenderPipeline({
446
+ function K(e, t, n, r) {
447
+ let i = e.createShaderModule({ code: t });
448
+ return e.createRenderPipeline({
2281
449
  layout: "auto",
2282
450
  vertex: {
2283
- module: s,
451
+ module: i,
2284
452
  entryPoint: "vs",
2285
- buffers: [pe]
453
+ buffers: [ie]
2286
454
  },
2287
455
  fragment: {
2288
- module: s,
456
+ module: i,
2289
457
  entryPoint: "fs",
2290
458
  targets: [{
2291
- format: t,
2292
- ...i ? { blend: i } : {}
459
+ format: n,
460
+ ...r ? { blend: r } : {}
2293
461
  }]
2294
462
  },
2295
463
  primitive: { topology: "triangle-list" }
2296
464
  });
2297
465
  }
2298
- const he = {
466
+ var se = {
2299
467
  color: {
2300
468
  operation: "add",
2301
469
  srcFactor: "one",
@@ -2307,71 +475,71 @@ const he = {
2307
475
  dstFactor: "zero"
2308
476
  }
2309
477
  };
2310
- function ge(r, e, t = !0) {
2311
- const i = "rgba16float";
478
+ function ce(e, t, n = !0) {
479
+ let r = "rgba16float";
2312
480
  return {
2313
- advection: U(r, ue, i),
2314
- divergence: U(r, ne, i),
2315
- pressure: U(r, le, i),
2316
- gradientSubtract: U(r, ce, i),
2317
- splat: U(r, fe, i),
2318
- curl: U(r, ve, i),
2319
- vorticity: U(r, xe, i),
2320
- display: U(r, me, e, t ? void 0 : he)
481
+ advection: K(e, B, r),
482
+ divergence: K(e, V, r),
483
+ pressure: K(e, H, r),
484
+ gradientSubtract: K(e, U, r),
485
+ splat: K(e, ee, r),
486
+ curl: K(e, te, r),
487
+ vorticity: K(e, ne, r),
488
+ display: K(e, re, t, n ? void 0 : se)
2321
489
  };
2322
490
  }
2323
- function Te(r) {
2324
- return r.createSampler({
491
+ function le(e) {
492
+ return e.createSampler({
2325
493
  magFilter: "linear",
2326
494
  minFilter: "linear",
2327
495
  addressModeU: "clamp-to-edge",
2328
496
  addressModeV: "clamp-to-edge"
2329
497
  });
2330
498
  }
2331
- function S(r, e) {
2332
- return r.createBuffer({
2333
- size: e,
499
+ function q(e, t) {
500
+ return e.createBuffer({
501
+ size: t,
2334
502
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
2335
503
  });
2336
504
  }
2337
- function M(r, e, t, i, s, o) {
2338
- const u = new Float32Array([
2339
- t,
505
+ function ue(e, t, n, r, i, a) {
506
+ let o = new Float32Array([
507
+ n,
508
+ r,
2340
509
  i,
2341
- s,
2342
- o
510
+ a
2343
511
  ]);
2344
- r.queue.writeBuffer(e, 0, u);
512
+ e.queue.writeBuffer(t, 0, o);
2345
513
  }
2346
- function P(r, e, t, i) {
2347
- const s = new Float32Array([
2348
- t,
2349
- i,
514
+ function J(e, t, n, r) {
515
+ let i = new Float32Array([
516
+ n,
517
+ r,
2350
518
  0,
2351
519
  0
2352
520
  ]);
2353
- r.queue.writeBuffer(e, 0, s);
521
+ e.queue.writeBuffer(t, 0, i);
2354
522
  }
2355
- function be(r, e, t, i, s, o) {
2356
- const u = new Float32Array([
2357
- t,
523
+ function de(e, t, n, r, i, a) {
524
+ let o = new Float32Array([
525
+ n,
526
+ r,
2358
527
  i,
2359
- s,
2360
- o
528
+ a
2361
529
  ]);
2362
- r.queue.writeBuffer(e, 0, u);
530
+ e.queue.writeBuffer(t, 0, o);
2363
531
  }
2364
- function V(r, e, t, i, s, o, u, c, v, n, f) {
2365
- const l = /* @__PURE__ */ new Float32Array(12);
2366
- l[0] = t, l[1] = i, l[2] = s, l[3] = o, l[4] = u, l[5] = c, l[6] = v, l[7] = 0, l[8] = n, l[9] = f, l[10] = 0, l[11] = 0, r.queue.writeBuffer(e, 0, l);
532
+ function Y(e, t, n, r, i, a, o, s, c, l, u) {
533
+ let d = /* @__PURE__ */ new Float32Array(12);
534
+ d[0] = n, d[1] = r, d[2] = i, d[3] = a, d[4] = o, d[5] = s, d[6] = c, d[7] = 0, d[8] = l, d[9] = u, d[10] = 0, d[11] = 0, e.queue.writeBuffer(t, 0, d);
2367
535
  }
2368
- function ye(r, e, t, i, s, o, u, c, v, n, f, l) {
2369
- const a = /* @__PURE__ */ new Float32Array(16), x = new Int32Array(a.buffer);
2370
- a[0] = t, a[1] = i, a[2] = s, a[3] = o, a[4] = u[0], a[5] = u[1], a[6] = u[2], a[7] = 0, a[8] = c[0], a[9] = c[1], a[10] = c[2], a[11] = 0, a[12] = v, a[13] = n, x[14] = f, x[15] = l ? 1 : 0, r.queue.writeBuffer(e, 0, a);
536
+ function fe(e, t, n, r, i, a, o, s, c, l, u, d) {
537
+ let f = /* @__PURE__ */ new Float32Array(16), p = new Int32Array(f.buffer);
538
+ f[0] = n, f[1] = r, f[2] = i, f[3] = a, f[4] = o[0], f[5] = o[1], f[6] = o[2], f[7] = 0, f[8] = s[0], f[9] = s[1], f[10] = s[2], f[11] = 0, f[12] = c, f[13] = l, p[14] = u, p[15] = +!!d, e.queue.writeBuffer(t, 0, f);
2371
539
  }
2372
- function y(r, e, t, i, s) {
2373
- const o = r.beginRenderPass({ colorAttachments: [{
2374
- view: s,
540
+ function X(e, t, n, r, i) {
541
+ let a = e.beginRenderPass({ colorAttachments: [{
542
+ view: i,
2375
543
  clearValue: [
2376
544
  0,
2377
545
  0,
@@ -2381,11 +549,11 @@ function y(r, e, t, i, s) {
2381
549
  loadOp: "clear",
2382
550
  storeOp: "store"
2383
551
  }] });
2384
- o.setPipeline(e), o.setBindGroup(0, t), o.setVertexBuffer(0, i), o.draw(6), o.end();
552
+ a.setPipeline(t), a.setBindGroup(0, n), a.setVertexBuffer(0, r), a.draw(6), a.end();
2385
553
  }
2386
- function Se(r, e, t, i, s) {
2387
- const o = r.beginRenderPass({ colorAttachments: [{
2388
- view: s,
554
+ function pe(e, t, n, r, i) {
555
+ let a = e.beginRenderPass({ colorAttachments: [{
556
+ view: i,
2389
557
  clearValue: [
2390
558
  0,
2391
559
  0,
@@ -2395,169 +563,61 @@ function Se(r, e, t, i, s) {
2395
563
  loadOp: "clear",
2396
564
  storeOp: "store"
2397
565
  }] });
2398
- o.setPipeline(e), o.setBindGroup(0, t), o.setVertexBuffer(0, i), o.draw(6), o.end();
2399
- }
2400
- function _(r, e, t, i, s = "cover") {
2401
- let o;
2402
- s === "cover" ? o = Math.max(t / r, i / e) : s === "contain" ? o = Math.min(t / r, i / e) : typeof s == "string" && s.endsWith("%") ? o = Math.min(t / r, i / e) * (parseFloat(s) / 100) : typeof s == "string" && s.endsWith("px") ? o = parseFloat(s) / Math.max(r, e) : typeof s == "number" ? o = s : o = Math.max(t / r, i / e);
2403
- const u = r * o, c = e * o;
2404
- return {
2405
- x: (t - u) / 2,
2406
- y: (i - c) / 2,
2407
- drawW: u,
2408
- drawH: c
2409
- };
2410
- }
2411
- function Re(r, e, t, i, s = null, o = "cover") {
2412
- const { text: u, fontSize: c, color: v, fontFamily: n = "sans-serif", fontWeight: f = 900 } = i, l = new OffscreenCanvas(e, t), a = l.getContext("2d");
2413
- ((h) => {
2414
- if (s) {
2415
- a.clearRect(0, 0, e, t), a.fillStyle = "black", a.fillRect(0, 0, e, t);
2416
- const { x: m, y: T, drawW: b, drawH: D } = _(s.width, s.height, e, t, o);
2417
- a.drawImage(s, m, T, b, D);
2418
- } else a.fillStyle = "black", a.fillRect(0, 0, e, t);
2419
- a.fillStyle = h, a.font = \`\${f} \${c}px \${n}\`, a.textAlign = "center", a.textBaseline = "middle", a.fillText(u, e / 2, t / 2);
2420
- })(v);
2421
- const p = B(r, l);
2422
- a.fillStyle = "black", a.fillRect(0, 0, e, t), a.fillStyle = "white", a.font = \`\${f} \${c}px \${n}\`, a.textAlign = "center", a.textBaseline = "middle", a.fillText(u, e / 2, t / 2);
2423
- const d = B(r, l);
2424
- return {
2425
- backgroundTex: p,
2426
- obstacleTex: d,
2427
- coverageTex: d
2428
- };
2429
- }
2430
- function we(r, e, t, i, s = 0, o = "cover", u = null, c = "cover") {
2431
- const v = new OffscreenCanvas(t, i), n = v.getContext("2d"), { x: f, y: l, drawW: a, drawH: x } = _(e.width, e.height, t, i, o);
2432
- if (n.clearRect(0, 0, t, i), n.fillStyle = "black", n.fillRect(0, 0, t, i), u) {
2433
- const { x: h, y: m, drawW: T, drawH: b } = _(u.width, u.height, t, i, c);
2434
- n.filter = \`brightness(\${s}) blur(8px)\`, n.drawImage(u, h, m, T, b), n.filter = "none";
2435
- }
2436
- n.drawImage(e, f, l, a, x);
2437
- const p = B(r, v);
2438
- n.clearRect(0, 0, t, i), n.fillStyle = "black", n.fillRect(0, 0, t, i), n.filter = \`brightness(\${s}) blur(8px)\`, n.drawImage(e, f, l, a, x), n.filter = "none";
2439
- const d = B(r, v);
2440
- return n.clearRect(0, 0, t, i), n.fillStyle = "black", n.fillRect(0, 0, t, i), n.fillStyle = "white", n.fillRect(Math.max(0, f), Math.max(0, l), Math.min(a, t - Math.max(0, f)), Math.min(x, i - Math.max(0, l))), {
2441
- backgroundTex: p,
2442
- obstacleTex: d,
2443
- coverageTex: B(r, v)
2444
- };
2445
- }
2446
- function B(r, e) {
2447
- const t = r.createTexture();
2448
- return r.bindTexture(r.TEXTURE_2D, t), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, !0), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, r.RGBA, r.UNSIGNED_BYTE, e), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), t;
2449
- }
2450
- function Ee(r, e, t, i, s = null, o = "cover") {
2451
- const { text: u, fontSize: c, color: v, fontFamily: n = "sans-serif", fontWeight: f = 900 } = i, l = new OffscreenCanvas(e, t), a = l.getContext("2d");
2452
- ((h) => {
2453
- if (s) {
2454
- a.clearRect(0, 0, e, t), a.fillStyle = "black", a.fillRect(0, 0, e, t);
2455
- const { x: m, y: T, drawW: b, drawH: D } = _(s.width, s.height, e, t, o);
2456
- a.drawImage(s, m, T, b, D);
2457
- } else a.fillStyle = "black", a.fillRect(0, 0, e, t);
2458
- a.fillStyle = h, a.font = \`\${f} \${c}px \${n}\`, a.textAlign = "center", a.textBaseline = "middle", a.fillText(u, e / 2, t / 2);
2459
- })(v);
2460
- const p = O(r, l, e, t);
2461
- a.fillStyle = "black", a.fillRect(0, 0, e, t), a.fillStyle = "white", a.font = \`\${f} \${c}px \${n}\`, a.textAlign = "center", a.textBaseline = "middle", a.fillText(u, e / 2, t / 2);
2462
- const d = O(r, l, e, t);
2463
- return {
2464
- backgroundTex: p,
2465
- backgroundView: p.createView(),
2466
- obstacleTex: d,
2467
- obstacleView: d.createView(),
2468
- coverageTex: d,
2469
- coverageView: d.createView(),
2470
- sharedCoverage: !0
2471
- };
2472
- }
2473
- function Ue(r, e, t, i, s = 0, o = "cover", u = null, c = "cover") {
2474
- const v = new OffscreenCanvas(t, i), n = v.getContext("2d"), { x: f, y: l, drawW: a, drawH: x } = _(e.width, e.height, t, i, o);
2475
- if (n.clearRect(0, 0, t, i), n.fillStyle = "black", n.fillRect(0, 0, t, i), u) {
2476
- const { x: m, y: T, drawW: b, drawH: D } = _(u.width, u.height, t, i, c);
2477
- n.filter = \`brightness(\${s}) blur(8px)\`, n.drawImage(u, m, T, b, D), n.filter = "none";
2478
- }
2479
- n.drawImage(e, f, l, a, x);
2480
- const p = O(r, v, t, i);
2481
- n.clearRect(0, 0, t, i), n.fillStyle = "black", n.fillRect(0, 0, t, i), n.filter = \`brightness(\${s}) blur(8px)\`, n.drawImage(e, f, l, a, x), n.filter = "none";
2482
- const d = O(r, v, t, i);
2483
- n.clearRect(0, 0, t, i), n.fillStyle = "black", n.fillRect(0, 0, t, i), n.fillStyle = "white", n.fillRect(Math.max(0, f), Math.max(0, l), Math.min(a, t - Math.max(0, f)), Math.min(x, i - Math.max(0, l)));
2484
- const h = O(r, v, t, i);
2485
- return {
2486
- backgroundTex: p,
2487
- backgroundView: p.createView(),
2488
- obstacleTex: d,
2489
- obstacleView: d.createView(),
2490
- coverageTex: h,
2491
- coverageView: h.createView(),
2492
- sharedCoverage: !1
2493
- };
566
+ a.setPipeline(t), a.setBindGroup(0, n), a.setVertexBuffer(0, r), a.draw(6), a.end();
2494
567
  }
2495
- function O(r, e, t, i) {
2496
- const s = r.createTexture({
2497
- size: [t, i],
2498
- format: "rgba8unorm",
2499
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
2500
- });
2501
- return r.queue.copyExternalImageToTexture({ source: e }, { texture: s }, [t, i]), s;
2502
- }
2503
- async function De(r) {
2504
- const e = await fetch(r);
2505
- if (!e.ok) throw new Error(\`Failed to fetch image: \${r} (\${e.status})\`);
2506
- const t = await e.blob();
2507
- return createImageBitmap(t);
2508
- }
2509
- const I = typeof requestAnimationFrame < "u" ? requestAnimationFrame.bind(globalThis) : (r) => setTimeout(r, 1e3 / 60), _e = typeof cancelAnimationFrame < "u" ? cancelAnimationFrame.bind(globalThis) : clearTimeout, C = .016, k = {
568
+ //#endregion
569
+ //#region src/core/simulation.ts
570
+ var me = typeof requestAnimationFrame < "u" ? requestAnimationFrame.bind(globalThis) : (e) => setTimeout(e, 1e3 / 60), he = typeof cancelAnimationFrame < "u" ? cancelAnimationFrame.bind(globalThis) : clearTimeout, Z = .016, ge = {
2510
571
  standard: 0,
2511
572
  glass: 1,
2512
573
  ink: 2,
2513
574
  aurora: 3,
2514
575
  ripple: 4
2515
- };
2516
- var Ce = class $ {
2517
- #O;
2518
- #x = null;
2519
- #j = null;
2520
- #F = null;
2521
- #Y = null;
2522
- #a = null;
576
+ }, Q = class e {
577
+ #e;
578
+ #t = null;
579
+ #n = null;
580
+ #r = null;
2523
581
  #i = null;
582
+ #a = null;
583
+ #o = null;
584
+ #s = null;
585
+ #c = null;
586
+ #l = null;
587
+ #u = null;
2524
588
  #d = null;
589
+ #f = null;
590
+ #p = null;
591
+ #m = null;
2525
592
  #h = null;
2526
593
  #g = null;
594
+ #_ = null;
595
+ #v = null;
596
+ #y = null;
597
+ #b = null;
598
+ #x = null;
2527
599
  #S = null;
2528
- #c = null;
600
+ #C = null;
601
+ #w = null;
2529
602
  #T = null;
2530
- #n = null;
2531
- #q = null;
2532
- #P = null;
2533
- #H = null;
2534
- #u = null;
2535
- #t = null;
603
+ #E = null;
2536
604
  #D = null;
2537
- #b = null;
2538
- #_ = null;
2539
- #v = null;
2540
- #V = null;
2541
- #L = null;
605
+ #O = null;
606
+ #k = null;
2542
607
  #A = null;
2543
- #X = null;
2544
- #z = null;
2545
- #R = null;
2546
- #w = null;
2547
- #G = null;
608
+ #j = null;
2548
609
  #M = null;
2549
- #I = null;
2550
- #r = 0;
2551
- #s = 0;
2552
- #m = 0;
2553
- #p = 0;
2554
- #l = 1;
2555
- #Q = 1;
2556
- #E = .5;
2557
- #f = null;
2558
- #C = "cover";
2559
- #U;
2560
- #e = {
610
+ #N = 0;
611
+ #P = 0;
612
+ #F = 0;
613
+ #I = 0;
614
+ #L = 1;
615
+ #R = 1;
616
+ #z = .5;
617
+ #B = null;
618
+ #V = "cover";
619
+ #H;
620
+ #U = {
2561
621
  x: 0,
2562
622
  y: 0,
2563
623
  dx: 0,
@@ -2566,947 +626,852 @@ var Ce = class $ {
2566
626
  targetY: 0,
2567
627
  moved: !1
2568
628
  };
2569
- #K = !1;
2570
- #o = null;
2571
- #y = null;
2572
- #k = !1;
629
+ #W = !1;
630
+ #G = null;
631
+ #K = null;
632
+ #q = !1;
2573
633
  #J = !1;
2574
- #W = !0;
2575
- constructor(e, t = {}, i = {}, s, o = !0) {
2576
- if (this.#O = e, this.#Q = Math.max(.1, Math.min(1, i.dpr ?? 1)), this.#E = Math.max(.1, Math.min(1, i.sim ?? .5)), this.#U = H(t), this.#W = o, s) this.#n = s, this.#re(s);
634
+ #Y = !0;
635
+ constructor(e, t = {}, n = {}, r, i = !0) {
636
+ if (this.#e = e, this.#R = Math.max(.1, Math.min(1, n.dpr ?? 1)), this.#z = Math.max(.1, Math.min(1, n.sim ?? .5)), this.#H = h(t), this.#Y = i, r) this.#p = r, this.#X(r);
2577
637
  else {
2578
- const { gl: u, ext: c } = ie(e, o);
2579
- this.#x = u, this.#j = c, this.#F = oe(u), this.#Y = ae(u), u.clearColor(0, 0, 0, o ? 0 : 1);
638
+ let { gl: t, ext: n } = N(e, i);
639
+ this.#t = t, this.#n = n, this.#r = I(t), this.#i = z(t), t.clearColor(0, 0, 0, +!i);
2580
640
  }
2581
641
  }
2582
- /**
2583
- * WebGPU-first factory. Tries WebGPU, falls back to WebGL2 WebGL1.
2584
- * This is the recommended entry point when WebGPU support is desired.
2585
- */
2586
- static async create(e, t = {}, i = {}, s = !0, o = !0) {
2587
- return new $(e, t, i, (s ? await se(e, o) : null) ?? void 0, o);
642
+ static async create(t, n = {}, r = {}, i = !0, a = !0) {
643
+ return new e(t, n, r, (i ? await P(t, a) : null) ?? void 0, a);
2588
644
  }
2589
645
  setTextSource(e) {
2590
- this.#o = {
646
+ this.#G = {
2591
647
  type: "text",
2592
648
  opts: e
2593
- }, this.#N(), this.#B(), this.#$();
649
+ }, this.#Z(), this.#$(), this.#ee();
2594
650
  }
2595
- async setImageSource(e, t = 0, i = "cover") {
2596
- const s = await De(e);
651
+ async setImageSource(e, t = 0, n = "cover") {
652
+ let r = await C(e);
2597
653
  if (this.#J) {
2598
- s.close();
654
+ r.close();
2599
655
  return;
2600
656
  }
2601
- this.#o = {
657
+ this.#G = {
2602
658
  type: "image",
2603
- bitmap: s,
659
+ bitmap: r,
2604
660
  effect: t,
2605
- size: i
2606
- }, this.#N(), this.#B(), this.#$();
661
+ size: n
662
+ }, this.#Z(), this.#$(), this.#ee();
2607
663
  }
2608
- setImageBitmap(e, t = 0, i = "cover") {
2609
- this.#o = {
664
+ setImageBitmap(e, t = 0, n = "cover") {
665
+ this.#G = {
2610
666
  type: "image",
2611
667
  bitmap: e,
2612
668
  effect: t,
2613
- size: i
2614
- }, this.#N(), this.#B(), this.#$();
669
+ size: n
670
+ }, this.#Z(), this.#$(), this.#ee();
2615
671
  }
2616
672
  setBackground(e, t = "cover") {
2617
- this.#f && this.#f !== e && this.#f.close(), this.#f = e, this.#C = t ?? "cover", this.#o && this.#r > 0 && this.#s > 0 && this.#B();
673
+ this.#B && this.#B !== e && this.#B.close(), this.#B = e, this.#V = t ?? "cover", this.#G && this.#N > 0 && this.#P > 0 && this.#$();
2618
674
  }
2619
- handleMove(e, t, i = 1) {
2620
- if (!this.#K) {
2621
- this.#e.x = this.#e.targetX = e, this.#e.y = this.#e.targetY = t, this.#K = !0;
675
+ handleMove(e, t, n = 1) {
676
+ if (!this.#W) {
677
+ this.#U.x = this.#U.targetX = e, this.#U.y = this.#U.targetY = t, this.#W = !0;
2622
678
  return;
2623
679
  }
2624
- this.#e.moved = !0, this.#e.dx = (e - this.#e.targetX) * i, this.#e.dy = (t - this.#e.targetY) * i, this.#e.targetX = e, this.#e.targetY = t;
680
+ this.#U.moved = !0, this.#U.dx = (e - this.#U.targetX) * n, this.#U.dy = (t - this.#U.targetY) * n, this.#U.targetX = e, this.#U.targetY = t;
2625
681
  }
2626
- /**
2627
- * Immediately applies one fluid splat at (x, y) with explicit velocity (vx, vy).
2628
- * Safe to call multiple times per frame — each call writes directly to the FBOs.
2629
- * Designed for programmatic use cases (e.g. particle systems, attractor paths)
2630
- * where you want N independent injection points per frame without flooding the
2631
- * mouse-state machine or the worker message queue.
2632
- */
2633
- splat(e, t, i, s, o = 1) {
2634
- !this.#k || this.#r === 0 || (this.#n ? this.#oe(e, t, i, s, o) : this.#ae(e, t, i, s, o));
682
+ splat(e, t, n, r, i = 1) {
683
+ !this.#q || this.#N === 0 || (this.#p ? this.#ae(e, t, n, r, i) : this.#oe(e, t, n, r, i));
2635
684
  }
2636
685
  updateQuality(e) {
2637
- e.dpr !== void 0 && (this.#Q = Math.max(.1, Math.min(1, e.dpr))), e.sim !== void 0 && (this.#E = Math.max(.1, Math.min(1, e.sim)));
686
+ e.dpr !== void 0 && (this.#R = Math.max(.1, Math.min(1, e.dpr))), e.sim !== void 0 && (this.#z = Math.max(.1, Math.min(1, e.sim)));
2638
687
  }
2639
- resize(e, t, i) {
2640
- if (i !== void 0 ? this.#l = i : typeof window < "u" && window.devicePixelRatio && (this.#l = window.devicePixelRatio), e !== void 0 && e > 0) {
688
+ resize(e, t, n) {
689
+ if (n === void 0 ? typeof window < "u" && window.devicePixelRatio && (this.#L = window.devicePixelRatio) : this.#L = n, e !== void 0 && e > 0) {
2641
690
  if (t === void 0 || t <= 0) return;
2642
- this.#r = this.#O.width = e, this.#s = this.#O.height = t, this.#m = Math.max(1, Math.round(e * this.#E)), this.#p = Math.max(1, Math.round(t * this.#E)), this.#Z();
2643
- } else this.#N();
2644
- this.#o && this.#B(), this.#$();
691
+ this.#N = this.#e.width = e, this.#P = this.#e.height = t, this.#F = Math.max(1, Math.round(e * this.#z)), this.#I = Math.max(1, Math.round(t * this.#z)), this.#Q();
692
+ } else this.#Z();
693
+ this.#G && this.#$(), this.#ee();
2645
694
  }
2646
695
  updateConfig(e) {
2647
- Object.assign(this.#U, e);
696
+ Object.assign(this.#H, e);
2648
697
  }
2649
698
  destroy() {
2650
- if (this.#J = !0, this.stop(), this.#ee(), this.#te(), this.#f && (this.#f.close(), this.#f = null), this.#n) this.#V?.destroy(), this.#L?.destroy(), this.#A?.destroy(), this.#X?.destroy(), this.#z?.destroy(), this.#R?.destroy(), this.#w?.destroy(), this.#G?.destroy(), this.#M?.destroy(), this.#I?.destroy(), this.#P?.destroy(), this.#n.device.destroy();
699
+ if (this.#J = !0, this.stop(), this.#te(), this.#ne(), this.#B &&= (this.#B.close(), null), this.#p) this.#C?.destroy(), this.#w?.destroy(), this.#T?.destroy(), this.#E?.destroy(), this.#D?.destroy(), this.#O?.destroy(), this.#k?.destroy(), this.#A?.destroy(), this.#j?.destroy(), this.#M?.destroy(), this.#h?.destroy(), this.#p.device.destroy();
2651
700
  else {
2652
- const e = this.#x;
2653
- for (const t of Object.values(this.#F)) t.dispose();
701
+ let e = this.#t;
702
+ for (let e of Object.values(this.#r)) e.dispose();
2654
703
  e.getExtension("WEBGL_lose_context")?.loseContext();
2655
704
  }
2656
705
  }
2657
706
  start() {
2658
- if (this.#y !== null) return;
2659
- const e = () => {
2660
- this.#ie(), this.#y = I(e);
707
+ if (this.#K !== null) return;
708
+ let e = () => {
709
+ this.#re(), this.#K = me(e);
2661
710
  };
2662
- this.#y = I(e);
711
+ this.#K = me(e);
2663
712
  }
2664
713
  stop() {
2665
- this.#y !== null && (_e(this.#y), this.#y = null);
714
+ this.#K !== null && (he(this.#K), this.#K = null);
2666
715
  }
2667
716
  get isRunning() {
2668
- return this.#y !== null;
2669
- }
2670
- #re(e) {
2671
- const { device: t, format: i } = e;
2672
- this.#q = ge(t, i, this.#W), this.#P = de(t), this.#H = Te(t), this.#V = S(t, 16), this.#L = S(t, 16), this.#A = S(t, 16), this.#X = S(t, 16), this.#z = S(t, 16), this.#R = S(t, 48), this.#w = S(t, 48), this.#G = S(t, 16), this.#M = S(t, 16), this.#I = S(t, 64);
717
+ return this.#K !== null;
2673
718
  }
2674
- #N() {
2675
- const e = this.#O;
2676
- "clientWidth" in e && e.clientWidth > 0 ? (this.#l = (typeof window < "u" && window.devicePixelRatio || 1) * this.#Q, this.#r = e.width = Math.round(e.clientWidth * this.#l), this.#s = e.height = Math.round(e.clientHeight * this.#l)) : (this.#r = e.width, this.#s = e.height), !(this.#r === 0 || this.#s === 0) && (this.#m = Math.max(1, Math.round(this.#r * this.#E)), this.#p = Math.max(1, Math.round(this.#s * this.#E)), this.#Z());
719
+ #X(e) {
720
+ let { device: t, format: n } = e;
721
+ this.#m = ce(t, n, this.#Y), this.#h = oe(t), this.#g = le(t), this.#C = q(t, 16), this.#w = q(t, 16), this.#T = q(t, 16), this.#E = q(t, 16), this.#D = q(t, 16), this.#O = q(t, 48), this.#k = q(t, 48), this.#A = q(t, 16), this.#j = q(t, 16), this.#M = q(t, 64);
2677
722
  }
2678
723
  #Z() {
2679
- if (this.#ee(), this.#n) {
2680
- const { device: e } = this.#n, t = "rgba16float", i = this.#m, s = this.#p;
2681
- this.#u = z(e, t, i, s), this.#t = z(e, t, i, s), this.#b = z(e, t, i, s), this.#D = A(e, t, i, s), this.#_ = A(e, t, i, s);
724
+ let e = this.#e;
725
+ "clientWidth" in e && e.clientWidth > 0 ? (this.#L = (typeof window < "u" && window.devicePixelRatio || 1) * this.#R, this.#N = e.width = Math.round(e.clientWidth * this.#L), this.#P = e.height = Math.round(e.clientHeight * this.#L)) : (this.#N = e.width, this.#P = e.height), !(this.#N === 0 || this.#P === 0) && (this.#F = Math.max(1, Math.round(this.#N * this.#z)), this.#I = Math.max(1, Math.round(this.#P * this.#z)), this.#Q());
726
+ }
727
+ #Q() {
728
+ if (this.#te(), this.#p) {
729
+ let { device: e } = this.#p, t = "rgba16float", n = this.#F, r = this.#I;
730
+ this.#_ = G(e, t, n, r), this.#v = G(e, t, n, r), this.#b = G(e, t, n, r), this.#y = W(e, t, n, r), this.#x = W(e, t, n, r);
2682
731
  } else {
2683
- const e = this.#x, t = this.#j, i = this.#m, s = this.#p;
2684
- this.#a = X(e, t, i, s), this.#i = X(e, t, i, s), this.#h = X(e, t, i, s), this.#d = L(e, t, i, s), this.#g = L(e, t, i, s);
732
+ let e = this.#t, t = this.#n, n = this.#F, r = this.#I;
733
+ this.#a = R(e, t, n, r), this.#o = R(e, t, n, r), this.#c = R(e, t, n, r), this.#s = L(e, t, n, r), this.#l = L(e, t, n, r);
2685
734
  }
2686
735
  }
2687
- #B() {
2688
- if (!(!this.#o || this.#r === 0 || this.#s === 0)) {
2689
- if (this.#te(), this.#n) {
2690
- const { device: e } = this.#n;
2691
- this.#o.type === "text" ? this.#v = Ee(e, this.#r, this.#s, this.#o.opts, this.#f, this.#C) : this.#v = Ue(e, this.#o.bitmap, this.#r, this.#s, this.#o.effect, this.#o.size, this.#f, this.#C);
736
+ #$() {
737
+ if (!(!this.#G || this.#N === 0 || this.#P === 0)) {
738
+ if (this.#ne(), this.#p) {
739
+ let { device: e } = this.#p;
740
+ this.#G.type === "text" ? this.#S = b(e, this.#N, this.#P, this.#G.opts, this.#B, this.#V) : this.#S = x(e, this.#G.bitmap, this.#N, this.#P, this.#G.effect, this.#G.size, this.#B, this.#V);
2692
741
  } else {
2693
- const e = this.#x;
2694
- if (this.#o.type === "text") {
2695
- const { backgroundTex: t, obstacleTex: i, coverageTex: s } = Re(e, this.#r, this.#s, this.#o.opts, this.#f, this.#C);
2696
- this.#S = t, this.#c = i, this.#T = s;
742
+ let e = this.#t;
743
+ if (this.#G.type === "text") {
744
+ let { backgroundTex: t, obstacleTex: n, coverageTex: r } = _(e, this.#N, this.#P, this.#G.opts, this.#B, this.#V);
745
+ this.#u = t, this.#d = n, this.#f = r;
2697
746
  } else {
2698
- const { backgroundTex: t, obstacleTex: i, coverageTex: s } = we(e, this.#o.bitmap, this.#r, this.#s, this.#o.effect, this.#o.size, this.#f, this.#C);
2699
- this.#S = t, this.#c = i, this.#T = s;
747
+ let { backgroundTex: t, obstacleTex: n, coverageTex: r } = v(e, this.#G.bitmap, this.#N, this.#P, this.#G.effect, this.#G.size, this.#B, this.#V);
748
+ this.#u = t, this.#d = n, this.#f = r;
2700
749
  }
2701
750
  }
2702
- this.#k = !0;
751
+ this.#q = !0;
2703
752
  }
2704
753
  }
2705
- #$() {
2706
- this.#k && !this.isRunning && this.start();
2707
- }
2708
754
  #ee() {
2709
- if (this.#n) this.#u?.dispose(), this.#t?.dispose(), this.#b?.dispose(), this.#D?.tex.destroy(), this.#_?.tex.destroy(), this.#u = this.#t = this.#b = null, this.#D = this.#_ = null;
755
+ this.#q && !this.isRunning && this.start();
756
+ }
757
+ #te() {
758
+ if (this.#p) this.#_?.dispose(), this.#v?.dispose(), this.#b?.dispose(), this.#y?.tex.destroy(), this.#x?.tex.destroy(), this.#_ = this.#v = this.#b = null, this.#y = this.#x = null;
2710
759
  else {
2711
- const e = this.#x;
2712
- this.#a?.dispose(), this.#i?.dispose(), this.#h?.dispose(), this.#d && (e.deleteTexture(this.#d.tex), e.deleteFramebuffer(this.#d.fbo)), this.#g && (e.deleteTexture(this.#g.tex), e.deleteFramebuffer(this.#g.fbo)), this.#a = this.#i = this.#h = this.#d = this.#g = null;
760
+ let e = this.#t;
761
+ this.#a?.dispose(), this.#o?.dispose(), this.#c?.dispose(), this.#s && (e.deleteTexture(this.#s.tex), e.deleteFramebuffer(this.#s.fbo)), this.#l && (e.deleteTexture(this.#l.tex), e.deleteFramebuffer(this.#l.fbo)), this.#a = this.#o = this.#c = this.#s = this.#l = null;
2713
762
  }
2714
763
  }
2715
- #te() {
2716
- if (this.#n) this.#v && (this.#v.backgroundTex.destroy(), this.#v.obstacleTex.destroy(), this.#v.sharedCoverage || this.#v.coverageTex.destroy(), this.#v = null);
764
+ #ne() {
765
+ if (this.#p) this.#S &&= (this.#S.backgroundTex.destroy(), this.#S.obstacleTex.destroy(), this.#S.sharedCoverage || this.#S.coverageTex.destroy(), null);
2717
766
  else {
2718
- const e = this.#x;
2719
- this.#S && e.deleteTexture(this.#S), this.#c && e.deleteTexture(this.#c), this.#T && this.#T !== this.#c && e.deleteTexture(this.#T), this.#S = this.#c = this.#T = null;
767
+ let e = this.#t;
768
+ this.#u && e.deleteTexture(this.#u), this.#d && e.deleteTexture(this.#d), this.#f && this.#f !== this.#d && e.deleteTexture(this.#f), this.#u = this.#d = this.#f = null;
2720
769
  }
2721
770
  }
2722
- #ie() {
2723
- !this.#k || this.#r === 0 || (this.#n ? this.#se() : this.#ue());
771
+ #re() {
772
+ !this.#q || this.#N === 0 || (this.#p ? this.#ie() : this.#se());
2724
773
  }
2725
- #se() {
2726
- const e = this.#n, t = e.device, i = this.#q, s = this.#P, o = this.#H, u = this.#U, c = this.#v;
2727
- if (!this.#u || !this.#t) return;
2728
- this.#e.x += (this.#e.targetX - this.#e.x) * .15, this.#e.y += (this.#e.targetY - this.#e.y) * .15;
2729
- const v = this.#m, n = this.#p, f = this.#r, l = this.#s, a = 1 / v, x = 1 / n;
2730
- M(t, this.#V, a, x, C, u.velocityDissipation), P(t, this.#A, a, x), P(t, this.#X, a, x), P(t, this.#z, a, x), P(t, this.#G, a, x), be(t, this.#M, a, x, u.curl, C), ye(t, this.#I, 1 / f, 1 / l, u.refraction, u.specularExp, F(u.waterColor), F(u.glowColor), u.shine, u.warpStrength ?? .015, k[u.algorithm] ?? 0, this.#W);
2731
- const p = t.createCommandEncoder(), d = (m, T) => t.createBindGroup({
2732
- layout: m.getBindGroupLayout(0),
2733
- entries: T
2734
- }), h = {
774
+ #ie() {
775
+ let e = this.#p, t = e.device, n = this.#m, r = this.#h, i = this.#g, a = this.#H, o = this.#S;
776
+ if (!this.#_ || !this.#v) return;
777
+ this.#U.x += (this.#U.targetX - this.#U.x) * .15, this.#U.y += (this.#U.targetY - this.#U.y) * .15;
778
+ let s = this.#F, c = this.#I, l = this.#N, u = this.#P, d = 1 / s, f = 1 / c;
779
+ ue(t, this.#C, d, f, Z, a.velocityDissipation), J(t, this.#T, d, f), J(t, this.#E, d, f), J(t, this.#D, d, f), J(t, this.#A, d, f), de(t, this.#j, d, f, a.curl, Z), fe(t, this.#M, 1 / l, 1 / u, a.refraction, a.specularExp, m(a.waterColor), m(a.glowColor), a.shine, a.warpStrength ?? .015, ge[a.algorithm] ?? 0, this.#Y);
780
+ let p = t.createCommandEncoder(), h = (e, n) => t.createBindGroup({
781
+ layout: e.getBindGroupLayout(0),
782
+ entries: n
783
+ }), g = {
2735
784
  binding: 1,
2736
- resource: o
785
+ resource: i
2737
786
  };
2738
787
  {
2739
- const m = d(i.advection, [
788
+ let e = h(n.advection, [
2740
789
  {
2741
790
  binding: 0,
2742
- resource: { buffer: this.#V }
791
+ resource: { buffer: this.#C }
2743
792
  },
2744
- h,
793
+ g,
2745
794
  {
2746
795
  binding: 2,
2747
- resource: this.#t.read.view
796
+ resource: this.#v.read.view
2748
797
  },
2749
798
  {
2750
799
  binding: 3,
2751
- resource: this.#t.read.view
800
+ resource: this.#v.read.view
2752
801
  },
2753
802
  {
2754
803
  binding: 4,
2755
- resource: c.obstacleView
804
+ resource: o.obstacleView
2756
805
  }
2757
806
  ]);
2758
- y(p, i.advection, m, s, this.#t.write.view);
807
+ X(p, n.advection, e, r, this.#v.write.view);
2759
808
  }
2760
- this.#t.swap();
809
+ this.#v.swap();
2761
810
  {
2762
- M(t, this.#L, a, x, C, u.densityDissipation);
2763
- const m = d(i.advection, [
811
+ ue(t, this.#w, d, f, Z, a.densityDissipation);
812
+ let e = h(n.advection, [
2764
813
  {
2765
814
  binding: 0,
2766
- resource: { buffer: this.#L }
815
+ resource: { buffer: this.#w }
2767
816
  },
2768
- h,
817
+ g,
2769
818
  {
2770
819
  binding: 2,
2771
- resource: this.#t.read.view
820
+ resource: this.#v.read.view
2772
821
  },
2773
822
  {
2774
823
  binding: 3,
2775
- resource: this.#u.read.view
824
+ resource: this.#_.read.view
2776
825
  },
2777
826
  {
2778
827
  binding: 4,
2779
- resource: c.obstacleView
828
+ resource: o.obstacleView
2780
829
  }
2781
830
  ]);
2782
- y(p, i.advection, m, s, this.#u.write.view);
831
+ X(p, n.advection, e, r, this.#_.write.view);
2783
832
  }
2784
- this.#u.swap();
833
+ this.#_.swap();
2785
834
  {
2786
- const m = d(i.curl, [
835
+ let e = h(n.curl, [
2787
836
  {
2788
837
  binding: 0,
2789
- resource: { buffer: this.#G }
838
+ resource: { buffer: this.#A }
2790
839
  },
2791
- h,
840
+ g,
2792
841
  {
2793
842
  binding: 2,
2794
- resource: this.#t.read.view
843
+ resource: this.#v.read.view
2795
844
  }
2796
845
  ]);
2797
- y(p, i.curl, m, s, this.#_.view);
846
+ X(p, n.curl, e, r, this.#x.view);
2798
847
  }
2799
848
  {
2800
- const m = d(i.vorticity, [
849
+ let e = h(n.vorticity, [
2801
850
  {
2802
851
  binding: 0,
2803
- resource: { buffer: this.#M }
852
+ resource: { buffer: this.#j }
2804
853
  },
2805
- h,
854
+ g,
2806
855
  {
2807
856
  binding: 2,
2808
- resource: this.#t.read.view
857
+ resource: this.#v.read.view
2809
858
  },
2810
859
  {
2811
860
  binding: 3,
2812
- resource: this.#_.view
861
+ resource: this.#x.view
2813
862
  }
2814
863
  ]);
2815
- y(p, i.vorticity, m, s, this.#t.write.view);
864
+ X(p, n.vorticity, e, r, this.#v.write.view);
2816
865
  }
2817
- if (this.#t.swap(), this.#e.moved) {
2818
- const m = this.#e.x * this.#l / f, T = this.#e.y * this.#l / l;
2819
- V(t, this.#R, a, x, f / l, u.splatRadius, this.#e.dx * u.splatForce, this.#e.dy * u.splatForce, 0, m, T);
866
+ if (this.#v.swap(), this.#U.moved) {
867
+ let e = this.#U.x * this.#L / l, i = this.#U.y * this.#L / u;
868
+ Y(t, this.#O, d, f, l / u, a.splatRadius, this.#U.dx * a.splatForce, this.#U.dy * a.splatForce, 0, e, i);
2820
869
  {
2821
- const b = d(i.splat, [
870
+ let e = h(n.splat, [
2822
871
  {
2823
872
  binding: 0,
2824
- resource: { buffer: this.#R }
873
+ resource: { buffer: this.#O }
2825
874
  },
2826
- h,
875
+ g,
2827
876
  {
2828
877
  binding: 2,
2829
- resource: this.#t.read.view
878
+ resource: this.#v.read.view
2830
879
  }
2831
880
  ]);
2832
- y(p, i.splat, b, s, this.#t.write.view);
881
+ X(p, n.splat, e, r, this.#v.write.view);
2833
882
  }
2834
- this.#t.swap(), V(t, this.#w, a, x, f / l, u.splatRadius, 1, 1, 1, m, T);
883
+ this.#v.swap(), Y(t, this.#k, d, f, l / u, a.splatRadius, 1, 1, 1, e, i);
2835
884
  {
2836
- const b = d(i.splat, [
885
+ let e = h(n.splat, [
2837
886
  {
2838
887
  binding: 0,
2839
- resource: { buffer: this.#w }
888
+ resource: { buffer: this.#k }
2840
889
  },
2841
- h,
890
+ g,
2842
891
  {
2843
892
  binding: 2,
2844
- resource: this.#u.read.view
893
+ resource: this.#_.read.view
2845
894
  }
2846
895
  ]);
2847
- y(p, i.splat, b, s, this.#u.write.view);
896
+ X(p, n.splat, e, r, this.#_.write.view);
2848
897
  }
2849
- this.#u.swap(), this.#e.moved = !1;
898
+ this.#_.swap(), this.#U.moved = !1;
2850
899
  }
2851
900
  {
2852
- const m = d(i.divergence, [
901
+ let e = h(n.divergence, [
2853
902
  {
2854
903
  binding: 0,
2855
- resource: { buffer: this.#A }
904
+ resource: { buffer: this.#T }
2856
905
  },
2857
- h,
906
+ g,
2858
907
  {
2859
908
  binding: 2,
2860
- resource: this.#t.read.view
909
+ resource: this.#v.read.view
2861
910
  },
2862
911
  {
2863
912
  binding: 3,
2864
- resource: c.obstacleView
913
+ resource: o.obstacleView
2865
914
  }
2866
915
  ]);
2867
- y(p, i.divergence, m, s, this.#D.view);
916
+ X(p, n.divergence, e, r, this.#y.view);
2868
917
  }
2869
- for (let m = 0; m < u.pressureIterations; m++) {
2870
- const T = d(i.pressure, [
918
+ for (let e = 0; e < a.pressureIterations; e++) {
919
+ let e = h(n.pressure, [
2871
920
  {
2872
921
  binding: 0,
2873
- resource: { buffer: this.#X }
922
+ resource: { buffer: this.#E }
2874
923
  },
2875
- h,
924
+ g,
2876
925
  {
2877
926
  binding: 2,
2878
927
  resource: this.#b.read.view
2879
928
  },
2880
929
  {
2881
930
  binding: 3,
2882
- resource: this.#D.view
931
+ resource: this.#y.view
2883
932
  },
2884
933
  {
2885
934
  binding: 4,
2886
- resource: c.obstacleView
935
+ resource: o.obstacleView
2887
936
  }
2888
937
  ]);
2889
- y(p, i.pressure, T, s, this.#b.write.view), this.#b.swap();
938
+ X(p, n.pressure, e, r, this.#b.write.view), this.#b.swap();
2890
939
  }
2891
940
  {
2892
- const m = d(i.gradientSubtract, [
941
+ let e = h(n.gradientSubtract, [
2893
942
  {
2894
943
  binding: 0,
2895
- resource: { buffer: this.#z }
944
+ resource: { buffer: this.#D }
2896
945
  },
2897
- h,
946
+ g,
2898
947
  {
2899
948
  binding: 2,
2900
949
  resource: this.#b.read.view
2901
950
  },
2902
951
  {
2903
952
  binding: 3,
2904
- resource: this.#t.read.view
953
+ resource: this.#v.read.view
2905
954
  },
2906
955
  {
2907
956
  binding: 4,
2908
- resource: c.obstacleView
957
+ resource: o.obstacleView
2909
958
  }
2910
959
  ]);
2911
- y(p, i.gradientSubtract, m, s, this.#t.write.view);
960
+ X(p, n.gradientSubtract, e, r, this.#v.write.view);
2912
961
  }
2913
- this.#t.swap();
962
+ this.#v.swap();
2914
963
  {
2915
- const m = e.context.getCurrentTexture().createView(), T = d(i.display, [
964
+ let t = e.context.getCurrentTexture().createView(), i = h(n.display, [
2916
965
  {
2917
966
  binding: 0,
2918
- resource: { buffer: this.#I }
967
+ resource: { buffer: this.#M }
2919
968
  },
2920
- h,
969
+ g,
2921
970
  {
2922
971
  binding: 2,
2923
- resource: this.#u.read.view
972
+ resource: this.#_.read.view
2924
973
  },
2925
974
  {
2926
975
  binding: 3,
2927
- resource: c.obstacleView
976
+ resource: o.obstacleView
2928
977
  },
2929
978
  {
2930
979
  binding: 4,
2931
- resource: c.backgroundView
980
+ resource: o.backgroundView
2932
981
  },
2933
982
  {
2934
983
  binding: 5,
2935
- resource: c.coverageView
984
+ resource: o.coverageView
2936
985
  },
2937
986
  {
2938
987
  binding: 6,
2939
- resource: this.#t.read.view
988
+ resource: this.#v.read.view
2940
989
  }
2941
990
  ]);
2942
- Se(p, i.display, T, s, m);
991
+ pe(p, n.display, i, r, t);
2943
992
  }
2944
993
  t.queue.submit([p.finish()]);
2945
994
  }
2946
- #oe(e, t, i, s, o) {
2947
- const u = this.#n.device, c = this.#q.splat, v = this.#P, n = this.#H, f = this.#U, l = this.#m, a = this.#p, x = 1 / l, p = 1 / a, d = u.createCommandEncoder(), h = {
995
+ #ae(e, t, n, r, i) {
996
+ let a = this.#p.device, o = this.#m.splat, s = this.#h, c = this.#g, l = this.#H, u = this.#F, d = this.#I, f = 1 / u, p = 1 / d, m = a.createCommandEncoder(), h = {
2948
997
  binding: 1,
2949
- resource: n
2950
- }, m = (D) => u.createBindGroup({
2951
- layout: c.getBindGroupLayout(0),
2952
- entries: D
2953
- }), T = e * this.#l / this.#r, b = t * this.#l / this.#s;
2954
- V(u, this.#R, x, p, this.#r / this.#s, f.splatRadius, i * f.splatForce * o, s * f.splatForce * o, 0, T, b), y(d, c, m([
998
+ resource: c
999
+ }, g = (e) => a.createBindGroup({
1000
+ layout: o.getBindGroupLayout(0),
1001
+ entries: e
1002
+ }), _ = e * this.#L / this.#N, v = t * this.#L / this.#P;
1003
+ Y(a, this.#O, f, p, this.#N / this.#P, l.splatRadius, n * l.splatForce * i, r * l.splatForce * i, 0, _, v), X(m, o, g([
2955
1004
  {
2956
1005
  binding: 0,
2957
- resource: { buffer: this.#R }
1006
+ resource: { buffer: this.#O }
2958
1007
  },
2959
1008
  h,
2960
1009
  {
2961
1010
  binding: 2,
2962
- resource: this.#t.read.view
1011
+ resource: this.#v.read.view
2963
1012
  }
2964
- ]), v, this.#t.write.view), this.#t.swap(), V(u, this.#w, x, p, this.#r / this.#s, f.splatRadius, o, o, o, T, b), y(d, c, m([
1013
+ ]), s, this.#v.write.view), this.#v.swap(), Y(a, this.#k, f, p, this.#N / this.#P, l.splatRadius, i, i, i, _, v), X(m, o, g([
2965
1014
  {
2966
1015
  binding: 0,
2967
- resource: { buffer: this.#w }
1016
+ resource: { buffer: this.#k }
2968
1017
  },
2969
1018
  h,
2970
1019
  {
2971
1020
  binding: 2,
2972
- resource: this.#u.read.view
1021
+ resource: this.#_.read.view
2973
1022
  }
2974
- ]), v, this.#u.write.view), this.#u.swap(), u.queue.submit([d.finish()]);
1023
+ ]), s, this.#_.write.view), this.#_.swap(), a.queue.submit([m.finish()]);
2975
1024
  }
2976
- #ae(e, t, i, s, o) {
2977
- const u = this.#x, c = this.#U, v = this.#F.splat, n = this.#Y;
2978
- u.viewport(0, 0, this.#m, this.#p), v.bind(), u.uniform1f(v.uniforms.aspectRatio, this.#r / this.#s), u.uniform2f(v.uniforms.point, e * this.#l / this.#r, 1 - t * this.#l / this.#s), u.uniform1f(v.uniforms.radius, c.splatRadius), u.uniform1i(v.uniforms.uTarget, 0), u.activeTexture(u.TEXTURE0), u.bindTexture(u.TEXTURE_2D, this.#i.read.tex), u.uniform3f(v.uniforms.color, i * c.splatForce * o, -s * c.splatForce * o, 0), n(this.#i.write.fbo), this.#i.swap(), u.activeTexture(u.TEXTURE0), u.bindTexture(u.TEXTURE_2D, this.#a.read.tex), u.uniform3f(v.uniforms.color, o, o, o), n(this.#a.write.fbo), this.#a.swap();
1025
+ #oe(e, t, n, r, i) {
1026
+ let a = this.#t, o = this.#H, s = this.#r.splat, c = this.#i;
1027
+ a.viewport(0, 0, this.#F, this.#I), s.bind(), a.uniform1f(s.uniforms.aspectRatio, this.#N / this.#P), a.uniform2f(s.uniforms.point, e * this.#L / this.#N, 1 - t * this.#L / this.#P), a.uniform1f(s.uniforms.radius, o.splatRadius), a.uniform1i(s.uniforms.uTarget, 0), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, this.#o.read.tex), a.uniform3f(s.uniforms.color, n * o.splatForce * i, -r * o.splatForce * i, 0), c(this.#o.write.fbo), this.#o.swap(), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, this.#a.read.tex), a.uniform3f(s.uniforms.color, i, i, i), c(this.#a.write.fbo), this.#a.swap();
2979
1028
  }
2980
- #ue() {
2981
- if (!this.#a || !this.#i) return;
2982
- const e = this.#x, t = this.#U, { advection: i, divergence: s, pressure: o, gradientSubtract: u, splat: c, curl: v, vorticity: n, display: f } = this.#F;
2983
- this.#e.x += (this.#e.targetX - this.#e.x) * .15, this.#e.y += (this.#e.targetY - this.#e.y) * .15;
2984
- const l = this.#m, a = this.#p, x = this.#Y;
2985
- e.viewport(0, 0, l, a), i.bind(), e.uniform2f(i.uniforms.texelSize, 1 / l, 1 / a), e.uniform1f(i.uniforms.dt, C), e.uniform1i(i.uniforms.uObstacle, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#c), e.uniform1f(i.uniforms.dissipation, t.velocityDissipation), e.uniform1i(i.uniforms.uVelocity, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), e.uniform1i(i.uniforms.uSource, 1), x(this.#i.write.fbo), this.#i.swap(), e.uniform1f(i.uniforms.dissipation, t.densityDissipation), e.uniform1i(i.uniforms.uSource, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#a.read.tex), x(this.#a.write.fbo), this.#a.swap(), v.bind(), e.uniform2f(v.uniforms.texelSize, 1 / l, 1 / a), e.uniform1i(v.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), x(this.#g.fbo), n.bind(), e.uniform2f(n.uniforms.texelSize, 1 / l, 1 / a), e.uniform1f(n.uniforms.curl, t.curl), e.uniform1f(n.uniforms.dt, C), e.uniform1i(n.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), e.uniform1i(n.uniforms.uCurl, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#g.tex), x(this.#i.write.fbo), this.#i.swap(), this.#e.moved && (c.bind(), e.uniform1f(c.uniforms.aspectRatio, this.#r / this.#s), e.uniform2f(c.uniforms.point, this.#e.x * this.#l / this.#r, 1 - this.#e.y * this.#l / this.#s), e.uniform1f(c.uniforms.radius, t.splatRadius), e.uniform1i(c.uniforms.uTarget, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), e.uniform3f(c.uniforms.color, this.#e.dx * t.splatForce, -this.#e.dy * t.splatForce, 0), x(this.#i.write.fbo), this.#i.swap(), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#a.read.tex), e.uniform3f(c.uniforms.color, 1, 1, 1), x(this.#a.write.fbo), this.#a.swap(), this.#e.moved = !1), s.bind(), e.uniform2f(s.uniforms.texelSize, 1 / l, 1 / a), e.uniform1i(s.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), e.uniform1i(s.uniforms.uObstacle, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#c), x(this.#d.fbo), o.bind(), e.uniform2f(o.uniforms.texelSize, 1 / l, 1 / a), e.uniform1i(o.uniforms.uDivergence, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#d.tex), e.uniform1i(o.uniforms.uObstacle, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#c);
2986
- for (let p = 0; p < t.pressureIterations; p++) e.uniform1i(o.uniforms.uPressure, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#h.read.tex), x(this.#h.write.fbo), this.#h.swap();
2987
- u.bind(), e.uniform2f(u.uniforms.texelSize, 1 / l, 1 / a), e.uniform1i(u.uniforms.uPressure, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#h.read.tex), e.uniform1i(u.uniforms.uVelocity, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), e.uniform1i(u.uniforms.uObstacle, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#c), x(this.#i.write.fbo), this.#i.swap(), e.viewport(0, 0, this.#r, this.#s), e.bindFramebuffer(e.FRAMEBUFFER, null), e.clear(e.COLOR_BUFFER_BIT), f.bind(), e.uniform2f(f.uniforms.texelSize, 1 / this.#r, 1 / this.#s), e.uniform3fv(f.uniforms.uWaterColor, F(t.waterColor)), e.uniform3fv(f.uniforms.uGlowColor, F(t.glowColor)), e.uniform1f(f.uniforms.uRefraction, t.refraction), e.uniform1f(f.uniforms.uSpecularExp, t.specularExp), e.uniform1f(f.uniforms.uShine, t.shine), e.uniform1f(f.uniforms.uWarpStrength, t.warpStrength ?? .015), e.uniform1i(f.uniforms.uAlgorithm, k[t.algorithm] ?? 0), e.uniform1i(f.uniforms.uEnableAlpha, this.#W ? 1 : 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#a.read.tex), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#c), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#S), e.activeTexture(e.TEXTURE3), e.bindTexture(e.TEXTURE_2D, this.#T), e.activeTexture(e.TEXTURE4), e.bindTexture(e.TEXTURE_2D, this.#i.read.tex), e.uniform1i(f.uniforms.uTexture, 0), e.uniform1i(f.uniforms.uObstacle, 1), e.uniform1i(f.uniforms.uBackground, 2), e.uniform1i(f.uniforms.uCoverage, 3), e.uniform1i(f.uniforms.uVelocity, 4), x(null);
1029
+ #se() {
1030
+ if (!this.#a || !this.#o) return;
1031
+ let e = this.#t, t = this.#H, { advection: n, divergence: r, pressure: i, gradientSubtract: a, splat: o, curl: s, vorticity: c, display: l } = this.#r;
1032
+ this.#U.x += (this.#U.targetX - this.#U.x) * .15, this.#U.y += (this.#U.targetY - this.#U.y) * .15;
1033
+ let u = this.#F, d = this.#I, f = this.#i;
1034
+ e.viewport(0, 0, u, d), n.bind(), e.uniform2f(n.uniforms.texelSize, 1 / u, 1 / d), e.uniform1f(n.uniforms.dt, Z), e.uniform1i(n.uniforms.uObstacle, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#d), e.uniform1f(n.uniforms.dissipation, t.velocityDissipation), e.uniform1i(n.uniforms.uVelocity, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), e.uniform1i(n.uniforms.uSource, 1), f(this.#o.write.fbo), this.#o.swap(), e.uniform1f(n.uniforms.dissipation, t.densityDissipation), e.uniform1i(n.uniforms.uSource, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#a.read.tex), f(this.#a.write.fbo), this.#a.swap(), s.bind(), e.uniform2f(s.uniforms.texelSize, 1 / u, 1 / d), e.uniform1i(s.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), f(this.#l.fbo), c.bind(), e.uniform2f(c.uniforms.texelSize, 1 / u, 1 / d), e.uniform1f(c.uniforms.curl, t.curl), e.uniform1f(c.uniforms.dt, Z), e.uniform1i(c.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), e.uniform1i(c.uniforms.uCurl, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#l.tex), f(this.#o.write.fbo), this.#o.swap(), this.#U.moved && (o.bind(), e.uniform1f(o.uniforms.aspectRatio, this.#N / this.#P), e.uniform2f(o.uniforms.point, this.#U.x * this.#L / this.#N, 1 - this.#U.y * this.#L / this.#P), e.uniform1f(o.uniforms.radius, t.splatRadius), e.uniform1i(o.uniforms.uTarget, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), e.uniform3f(o.uniforms.color, this.#U.dx * t.splatForce, -this.#U.dy * t.splatForce, 0), f(this.#o.write.fbo), this.#o.swap(), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#a.read.tex), e.uniform3f(o.uniforms.color, 1, 1, 1), f(this.#a.write.fbo), this.#a.swap(), this.#U.moved = !1), r.bind(), e.uniform2f(r.uniforms.texelSize, 1 / u, 1 / d), e.uniform1i(r.uniforms.uVelocity, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), e.uniform1i(r.uniforms.uObstacle, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#d), f(this.#s.fbo), i.bind(), e.uniform2f(i.uniforms.texelSize, 1 / u, 1 / d), e.uniform1i(i.uniforms.uDivergence, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#s.tex), e.uniform1i(i.uniforms.uObstacle, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#d);
1035
+ for (let n = 0; n < t.pressureIterations; n++) e.uniform1i(i.uniforms.uPressure, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#c.read.tex), f(this.#c.write.fbo), this.#c.swap();
1036
+ a.bind(), e.uniform2f(a.uniforms.texelSize, 1 / u, 1 / d), e.uniform1i(a.uniforms.uPressure, 0), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#c.read.tex), e.uniform1i(a.uniforms.uVelocity, 1), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), e.uniform1i(a.uniforms.uObstacle, 2), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#d), f(this.#o.write.fbo), this.#o.swap(), e.viewport(0, 0, this.#N, this.#P), e.bindFramebuffer(e.FRAMEBUFFER, null), e.clear(e.COLOR_BUFFER_BIT), l.bind(), e.uniform2f(l.uniforms.texelSize, 1 / this.#N, 1 / this.#P), e.uniform3fv(l.uniforms.uWaterColor, m(t.waterColor)), e.uniform3fv(l.uniforms.uGlowColor, m(t.glowColor)), e.uniform1f(l.uniforms.uRefraction, t.refraction), e.uniform1f(l.uniforms.uSpecularExp, t.specularExp), e.uniform1f(l.uniforms.uShine, t.shine), e.uniform1f(l.uniforms.uWarpStrength, t.warpStrength ?? .015), e.uniform1i(l.uniforms.uAlgorithm, ge[t.algorithm] ?? 0), e.uniform1i(l.uniforms.uEnableAlpha, +!!this.#Y), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, this.#a.read.tex), e.activeTexture(e.TEXTURE1), e.bindTexture(e.TEXTURE_2D, this.#d), e.activeTexture(e.TEXTURE2), e.bindTexture(e.TEXTURE_2D, this.#u), e.activeTexture(e.TEXTURE3), e.bindTexture(e.TEXTURE_2D, this.#f), e.activeTexture(e.TEXTURE4), e.bindTexture(e.TEXTURE_2D, this.#o.read.tex), e.uniform1i(l.uniforms.uTexture, 0), e.uniform1i(l.uniforms.uObstacle, 1), e.uniform1i(l.uniforms.uBackground, 2), e.uniform1i(l.uniforms.uCoverage, 3), e.uniform1i(l.uniforms.uVelocity, 4), f(null);
2988
1037
  }
2989
- };
2990
- let g = null, Y;
2991
- const R = new Promise((r) => {
2992
- Y = r;
2993
- });
2994
- self.onmessage = async (r) => {
2995
- const { type: e, ...t } = r.data;
1038
+ }, _e = "const e={densityDissipation:.83,velocityDissipation:.91,pressureIterations:1,curl:0,splatRadius:.1,splatForce:.08,refraction:1,specularExp:0,shine:0,waterColor:`#000000`,glowColor:`#b3d9ff`,algorithm:`aurora`,warpStrength:.04};({...e}),typeof window<`u`&&1/(window.devicePixelRatio||1);const t={backgroundColor:`#0a0a0a`,backgroundSize:`cover`,mouseEnabled:!0,workerEnabled:!0};({...t}),{...t};const n={calm:{densityDissipation:.98,velocityDissipation:.81,curl:1e-4,splatRadius:.05,splatForce:.08,refraction:.15,shine:.03,glowColor:`#99d9ff`,waterColor:`#00050d`},sand:{densityDissipation:.95,velocityDissipation:.81,curl:1,splatRadius:.23,splatForce:.16,refraction:.8,specularExp:0,shine:.33,glowColor:`#070707`,waterColor:`#735420`},wave:{densityDissipation:.9,velocityDissipation:.2,curl:.2,splatRadius:.1,splatForce:.22,refraction:.35,shine:.2,glowColor:`#80ccff`,waterColor:`#000308`},neon:{densityDissipation:.75,velocityDissipation:.3,curl:.05,splatRadius:.18,splatForce:.29,refraction:.25,specularExp:.04,shine:.93,glowColor:`#ff33cc`,waterColor:`#0d0014`},smoke:{densityDissipation:.93,velocityDissipation:.71,curl:.04,splatRadius:.21,splatForce:.14,refraction:.08,shine:0,glowColor:`#808080`,waterColor:`#0f0f0f`}};function r(e){if(Array.isArray(e))return e;let t=e.slice(1,7);return t.length===3?[parseInt(t[0]+t[0],16)/255,parseInt(t[1]+t[1],16)/255,parseInt(t[2]+t[2],16)/255]:[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255]}function i(t={},r,i=e){return{...r?{...i,...n[r]}:i,...t}}const a=`precision highp float;\n attribute vec2 aPosition;\n varying vec2 vUv;\n varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform vec2 texelSize;\n void main () {\n vUv = aPosition * 0.5 + 0.5;\n vL = vUv - vec2(texelSize.x, 0.0);\n vR = vUv + vec2(texelSize.x, 0.0);\n vT = vUv + vec2(0.0, texelSize.y);\n vB = vUv - vec2(0.0, texelSize.y);\n gl_Position = vec4(aPosition, 0.0, 1.0);\n }`;function o(e,t=!0){let n={alpha:t,depth:!1,stencil:!1,antialias:!0,preserveDrawingBuffer:!1},r=e.getContext(`webgl2`,n),i=!!r;i||(r=e.getContext(`webgl`,n),r.getExtension(`EXT_color_buffer_half_float`));let a=i?null:r.getExtension(`OES_texture_half_float`),o=i?r.HALF_FLOAT:a.HALF_FLOAT_OES;return r.getExtension(`EXT_color_buffer_float`),r.getExtension(`OES_texture_half_float_linear`),{type:i?`webgl2`:`webgl1`,gl:r,isWebGL2:i,ext:{internalFormat:i?r.RGBA16F:r.RGBA,format:r.RGBA,type:o}}}async function s(e,t=!0){if(typeof navigator>`u`||!navigator.gpu)return null;try{let n=await navigator.gpu.requestAdapter();if(!n)return null;let r=await n.requestDevice(),i=e.getContext(`webgpu`);if(!i)return null;let a=navigator.gpu.getPreferredCanvasFormat();return i.configure({device:r,format:a,alphaMode:t?`premultiplied`:`opaque`}),{type:`webgpu`,adapter:n,device:r,context:i,format:a}}catch{return null}}var c=class{program;uniforms={};_gl;constructor(e,t,n){this._gl=e,this.program=e.createProgram(),e.attachShader(this.program,this._compile(e.VERTEX_SHADER,t)),e.attachShader(this.program,this._compile(e.FRAGMENT_SHADER,n)),e.linkProgram(this.program);let r=e.getProgramParameter(this.program,e.ACTIVE_UNIFORMS);for(let t=0;t<r;t++){let n=e.getActiveUniform(this.program,t).name;this.uniforms[n]=e.getUniformLocation(this.program,n)}}_compile(e,t){let n=this._gl,r=n.createShader(e);return n.shaderSource(r,t),n.compileShader(r),r}bind(){this._gl.useProgram(this.program)}dispose(){this._gl.deleteProgram(this.program)}};function l(e){return{advection:new c(e,a,`precision highp float;\n varying vec2 vUv;\n uniform sampler2D uVelocity;\n uniform sampler2D uSource;\n uniform sampler2D uObstacle;\n uniform vec2 texelSize;\n uniform float dt;\n uniform float dissipation;\n void main () {\n float obs = texture2D(uObstacle, vUv).r;\n vec2 coord = vUv - dt * texture2D(uVelocity, vUv).xy * texelSize;\n \n \n \n gl_FragColor = dissipation * texture2D(uSource, coord) * (1.0 - obs);\n }`),divergence:new c(e,a,`precision highp float;\n varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uVelocity;\n uniform sampler2D uObstacle;\n void main () {\n float L = texture2D(uVelocity, vL).x * (1.0 - texture2D(uObstacle, vL).r);\n float R = texture2D(uVelocity, vR).x * (1.0 - texture2D(uObstacle, vR).r);\n float T = texture2D(uVelocity, vT).y * (1.0 - texture2D(uObstacle, vT).r);\n float B = texture2D(uVelocity, vB).y * (1.0 - texture2D(uObstacle, vB).r);\n gl_FragColor = vec4(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);\n }`),pressure:new c(e,a,`precision highp float;\n varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uPressure;\n uniform sampler2D uDivergence;\n uniform sampler2D uObstacle;\n void main () {\n float C = texture2D(uPressure, vUv).x;\n float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);\n float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);\n float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);\n float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);\n float div = texture2D(uDivergence, vUv).x;\n gl_FragColor = vec4((L + R + B + T - div) * 0.25, 0.0, 0.0, 1.0);\n }`),gradientSubtract:new c(e,a,`precision highp float;\n varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uPressure;\n uniform sampler2D uVelocity;\n uniform sampler2D uObstacle;\n void main () {\n float obs = texture2D(uObstacle, vUv).r;\n float C = texture2D(uPressure, vUv).x;\n float L = mix(texture2D(uPressure, vL).x, C, texture2D(uObstacle, vL).r);\n float R = mix(texture2D(uPressure, vR).x, C, texture2D(uObstacle, vR).r);\n float T = mix(texture2D(uPressure, vT).x, C, texture2D(uObstacle, vT).r);\n float B = mix(texture2D(uPressure, vB).x, C, texture2D(uObstacle, vB).r);\n vec2 vel = (texture2D(uVelocity, vUv).xy - vec2(R - L, T - B)) * (1.0 - obs);\n gl_FragColor = vec4(vel, 0.0, 1.0);\n }`),splat:new c(e,a,`precision highp float;\n varying vec2 vUv;\n uniform sampler2D uTarget;\n uniform float aspectRatio;\n uniform vec3 color;\n uniform vec2 point;\n uniform float radius;\n void main () {\n vec2 p = vUv - point.xy;\n p.x *= aspectRatio;\n vec3 splat = exp(-dot(p, p) / radius) * color;\n gl_FragColor = vec4(texture2D(uTarget, vUv).xyz + splat, 1.0);\n }`),curl:new c(e,a,`precision highp float;\n varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uVelocity;\n void main () {\n float L = texture2D(uVelocity, vL).y;\n float R = texture2D(uVelocity, vR).y;\n float T = texture2D(uVelocity, vT).x;\n float B = texture2D(uVelocity, vB).x;\n gl_FragColor = vec4(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);\n }`),vorticity:new c(e,a,`precision highp float;\n varying vec2 vUv; varying vec2 vL; varying vec2 vR; varying vec2 vT; varying vec2 vB;\n uniform sampler2D uVelocity;\n uniform sampler2D uCurl;\n uniform float curl;\n uniform float dt;\n void main () {\n float L = texture2D(uCurl, vL).x;\n float R = texture2D(uCurl, vR).x;\n float T = texture2D(uCurl, vT).x;\n float B = texture2D(uCurl, vB).x;\n float C = texture2D(uCurl, vUv).x;\n vec2 force = 0.5 * vec2(abs(T) - abs(B), abs(R) - abs(L));\n force /= length(force) + 0.0001;\n force *= curl * 30.0 * C;\n gl_FragColor = vec4(texture2D(uVelocity, vUv).xy + force * dt, 0.0, 1.0);\n }`),display:new c(e,a,`precision highp float;\n varying vec2 vUv;\n uniform sampler2D uTexture;\n uniform sampler2D uObstacle;\n uniform sampler2D uBackground;\n uniform sampler2D uCoverage;\n uniform sampler2D uVelocity;\n uniform vec2 texelSize;\n uniform vec3 uWaterColor;\n uniform vec3 uGlowColor;\n uniform float uRefraction;\n uniform float uSpecularExp;\n uniform float uShine;\n uniform float uWarpStrength;\n uniform int uAlgorithm;\n uniform int uEnableAlpha;\n void main () {\n float obs = texture2D(uObstacle, vUv).r;\n \n \n float density = max(texture2D(uTexture, vUv).r, 0.0) * (1.0 - obs);\n float coverage = texture2D(uCoverage, vUv).r;\n \n \n \n \n float sx = texelSize.x * 6.0, sy = texelSize.y * 6.0;\n float d00 = max(texture2D(uTexture, vUv + vec2(-sx, -sy)).r, 0.0);\n float d10 = max(texture2D(uTexture, vUv + vec2(0.0, -sy)).r, 0.0);\n float d20 = max(texture2D(uTexture, vUv + vec2( sx, -sy)).r, 0.0);\n float d01 = max(texture2D(uTexture, vUv + vec2(-sx, 0.0)).r, 0.0);\n float d21 = max(texture2D(uTexture, vUv + vec2( sx, 0.0)).r, 0.0);\n float d02 = max(texture2D(uTexture, vUv + vec2(-sx, sy)).r, 0.0);\n float d12 = max(texture2D(uTexture, vUv + vec2(0.0, sy)).r, 0.0);\n float d22 = max(texture2D(uTexture, vUv + vec2( sx, sy)).r, 0.0);\n float gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);\n float gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);\n vec3 normal = normalize(vec3(gx, gy, 1.2));\n vec3 lightDir = normalize(vec3(0.5, 1.0, 0.5));\n vec3 halfV = normalize(lightDir + vec3(0.0, 0.0, 1.0));\n \n \n float specDen = density * min(density * 5.0, 1.0);\n float spec = pow(max(dot(normal, halfV), 0.0), uSpecularExp) * uShine * specDen;\n \n \n \n vec3 bgRaw = texture2D(uBackground, vUv).rgb;\n vec3 bg = mix(uWaterColor, bgRaw, coverage);\n vec3 color = bg;\n if (uAlgorithm == 1) {\n \n \n vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 3.0, 0.0, 1.0);\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);\n color = refrBg + spec * uGlowColor * 2.5;\n color = mix(color, bg * 0.6, obs * 0.3);\n } else if (uAlgorithm == 2) {\n \n \n float inkD = min(density * 4.0, 1.0);\n vec2 refrUv = clamp(vUv + normal.xy * uRefraction * density * 0.4, 0.0, 1.0);\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);\n color = mix(refrBg, uWaterColor + spec * uGlowColor, inkD);\n color = mix(color, bg * 0.5, obs * 0.15);\n } else if (uAlgorithm == 3) {\n \n \n vec2 vel = texture2D(uVelocity, vUv).xy;\n float velMag = clamp(length(vel) * 20.0, 0.0, 1.0);\n vec2 warpUv = clamp(vUv + vel * uWarpStrength, 0.0, 1.0);\n vec3 warpBg = mix(uWaterColor, texture2D(uBackground, warpUv).rgb, coverage);\n color = mix(bg, warpBg, velMag * (1.0 - obs));\n color += spec * uGlowColor * velMag * 1.5;\n color += uWaterColor * density * 0.3;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else if (uAlgorithm == 4) {\n \n \n vec2 rippleUv = clamp(vUv + normal.xy * uRefraction * density * 6.0, 0.0, 1.0);\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, rippleUv, 1.0 - obs)).rgb, coverage);\n float fresnel = pow(clamp(1.0 - dot(normal, vec3(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;\n color = refrBg;\n color += fresnel * uGlowColor * 2.0;\n color += spec * uGlowColor * density * 2.0;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else {\n \n \n vec2 refrUv = vUv + normal.xy * uRefraction * density;\n vec3 refrBg = mix(uWaterColor, texture2D(uBackground, mix(vUv, refrUv, 1.0 - obs)).rgb, coverage);\n color = mix(refrBg, uWaterColor, min(density * 1.5, 0.8));\n color += spec * uGlowColor;\n color = mix(color, bg * 0.5, obs * 0.2);\n }\n \n \n float alpha = clamp(max(density * 1.5, coverage), 0.0, 1.0);\n if (uEnableAlpha == 1) {\n gl_FragColor = vec4(color * alpha, alpha);\n } else {\n gl_FragColor = vec4(color, 1.0);\n }\n }`)}}function u(e,t,n,r){e.activeTexture(e.TEXTURE0);let i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i),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(e.TEXTURE_2D,0,t.internalFormat,n,r,0,t.format,t.type,null);let a=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,a),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fbo:a,width:n,height:r}}function d(e,t,n,r){let i=u(e,t,n,r),a=u(e,t,n,r);return{get read(){return i},get write(){return a},swap(){[i,a]=[a,i]},dispose(){e.deleteTexture(i.tex),e.deleteFramebuffer(i.fbo),e.deleteTexture(a.tex),e.deleteFramebuffer(a.fbo)}}}function f(e){let t=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,t),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),e.STATIC_DRAW),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(0),function(t){e.bindFramebuffer(e.FRAMEBUFFER,t),e.drawArrays(e.TRIANGLE_FAN,0,4)}}const p={arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},m=new Float32Array([-1,-1,-1,1,1,-1,1,-1,-1,1,1,1]);function h(e){let t=e.createBuffer({size:m.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});return e.queue.writeBuffer(t,0,m),t}function g(e,t,n,r){let i=e.createTexture({size:[n,r],format:t,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC});return{tex:i,view:i.createView(),width:n,height:r}}function _(e,t,n,r){let i=g(e,t,n,r),a=g(e,t,n,r);return{get read(){return i},get write(){return a},swap(){[i,a]=[a,i]},dispose(){i.tex.destroy(),a.tex.destroy()}}}function v(e,t,n,r){let i=e.createShaderModule({code:t});return e.createRenderPipeline({layout:`auto`,vertex:{module:i,entryPoint:`vs`,buffers:[p]},fragment:{module:i,entryPoint:`fs`,targets:[{format:n,...r?{blend:r}:{}}]},primitive:{topology:`triangle-list`}})}const y={color:{operation:`add`,srcFactor:`one`,dstFactor:`zero`},alpha:{operation:`add`,srcFactor:`one`,dstFactor:`zero`}};function b(e,t,n=!0){let r=`rgba16float`;return{advection:v(e,`struct U {\n texelSize : vec2f,\n dt : f32,\n dissipation: f32,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@group(0) @binding(3) var uSrc : texture_2d<f32>;\n@group(0) @binding(4) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let obs = textureSample(uObs, samp, i.uv).r;\n let vel = textureSample(uVel, samp, i.uv).xy;\n let coord = i.uv - u.dt * vel * u.texelSize;\n let src = textureSample(uSrc, samp, coord);\n return u.dissipation * src * (1.0 - obs);\n}`,r),divergence:v(e,`struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@group(0) @binding(3) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let L = textureSample(uVel, samp, i.vL).x * (1.0 - textureSample(uObs, samp, i.vL).r);\n let R = textureSample(uVel, samp, i.vR).x * (1.0 - textureSample(uObs, samp, i.vR).r);\n let T = textureSample(uVel, samp, i.vT).y * (1.0 - textureSample(uObs, samp, i.vT).r);\n let B = textureSample(uVel, samp, i.vB).y * (1.0 - textureSample(uObs, samp, i.vB).r);\n return vec4f(0.5 * (R - L + T - B), 0.0, 0.0, 1.0);\n}`,r),pressure:v(e,`struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uPres: texture_2d<f32>;\n@group(0) @binding(3) var uDiv : texture_2d<f32>;\n@group(0) @binding(4) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let C = textureSample(uPres, samp, i.uv).x;\n let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);\n let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);\n let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);\n let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);\n let dv = textureSample(uDiv, samp, i.uv).x;\n return vec4f((L + R + B + T - dv) * 0.25, 0.0, 0.0, 1.0);\n}`,r),gradientSubtract:v(e,`struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uPres: texture_2d<f32>;\n@group(0) @binding(3) var uVel : texture_2d<f32>;\n@group(0) @binding(4) var uObs : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let obs = textureSample(uObs, samp, i.uv).r;\n let C = textureSample(uPres, samp, i.uv).x;\n let L = mix(textureSample(uPres, samp, i.vL).x, C, textureSample(uObs, samp, i.vL).r);\n let R = mix(textureSample(uPres, samp, i.vR).x, C, textureSample(uObs, samp, i.vR).r);\n let T = mix(textureSample(uPres, samp, i.vT).x, C, textureSample(uObs, samp, i.vT).r);\n let B = mix(textureSample(uPres, samp, i.vB).x, C, textureSample(uObs, samp, i.vB).r);\n let vel = (textureSample(uVel, samp, i.uv).xy - vec2f(R - L, T - B)) * (1.0 - obs);\n return vec4f(vel, 0.0, 1.0);\n}`,r),splat:v(e,`struct U {\n texelSize : vec2f,\n aspectRatio: f32,\n radius : f32,\n color : vec4f, \n point : vec2f,\n _pad : vec2f,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uTgt : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n var p = i.uv - u.point;\n p.x *= u.aspectRatio;\n let sp = exp(-dot(p, p) / u.radius) * u.color.xyz;\n return vec4f(textureSample(uTgt, samp, i.uv).xyz + sp, 1.0);\n}`,r),curl:v(e,`struct U { texelSize: vec2f, _pad: vec2f }\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let L = textureSample(uVel, samp, i.vL).y;\n let R = textureSample(uVel, samp, i.vR).y;\n let T = textureSample(uVel, samp, i.vT).x;\n let B = textureSample(uVel, samp, i.vB).x;\n return vec4f(0.5 * (R - L - T + B), 0.0, 0.0, 1.0);\n}`,r),vorticity:v(e,`struct U {\n texelSize: vec2f,\n curl : f32,\n dt : f32,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uVel : texture_2d<f32>;\n@group(0) @binding(3) var uCrl : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let L = textureSample(uCrl, samp, i.vL).x;\n let R = textureSample(uCrl, samp, i.vR).x;\n let T = textureSample(uCrl, samp, i.vT).x;\n let B = textureSample(uCrl, samp, i.vB).x;\n let C = textureSample(uCrl, samp, i.uv).x;\n var force = 0.5 * vec2f(abs(T) - abs(B), abs(R) - abs(L));\n force /= length(force) + 0.0001;\n force *= u.curl * 30.0 * C;\n let vel = textureSample(uVel, samp, i.uv).xy + force * u.dt;\n return vec4f(vel, 0.0, 1.0);\n}`,r),display:v(e,`struct U {\n texelSize : vec2f,\n refraction : f32,\n specularExp : f32,\n waterColor : vec4f,\n glowColor : vec4f,\n shine : f32,\n warpStrength: f32,\n algorithm : i32,\n enableAlpha : i32,\n}\n@group(0) @binding(0) var<uniform> u : U;\n@group(0) @binding(1) var samp : sampler;\n@group(0) @binding(2) var uTex : texture_2d<f32>;\n@group(0) @binding(3) var uObs : texture_2d<f32>;\n@group(0) @binding(4) var uBg : texture_2d<f32>;\n@group(0) @binding(5) var uCov : texture_2d<f32>;\n@group(0) @binding(6) var uVel : texture_2d<f32>;\n@vertex fn vs(@location(0) a: vec2f) -> VSOut {\n var o: VSOut;\n o.uv = vec2f(a.x * 0.5 + 0.5, 0.5 - a.y * 0.5);\n o.vL = o.uv - vec2f(u.texelSize.x, 0.0);\n o.vR = o.uv + vec2f(u.texelSize.x, 0.0);\n o.vT = o.uv + vec2f(0.0, u.texelSize.y);\n o.vB = o.uv - vec2f(0.0, u.texelSize.y);\n o.pos = vec4f(a, 0.0, 1.0);\n return o;\n}\n@fragment fn fs(i: VSOut) -> @location(0) vec4f {\n let obs = textureSample(uObs, samp, i.uv).r;\n let density = max(textureSample(uTex, samp, i.uv).r, 0.0) * (1.0 - obs);\n let cov = textureSample(uCov, samp, i.uv).r;\n let sx = u.texelSize.x * 6.0;\n let sy = u.texelSize.y * 6.0;\n let d00 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, -sy)).r, 0.0);\n let d10 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, -sy)).r, 0.0);\n let d20 = max(textureSample(uTex, samp, i.uv + vec2f( sx, -sy)).r, 0.0);\n let d01 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, 0.0)).r, 0.0);\n let d21 = max(textureSample(uTex, samp, i.uv + vec2f( sx, 0.0)).r, 0.0);\n let d02 = max(textureSample(uTex, samp, i.uv + vec2f(-sx, sy)).r, 0.0);\n let d12 = max(textureSample(uTex, samp, i.uv + vec2f(0.0, sy)).r, 0.0);\n let d22 = max(textureSample(uTex, samp, i.uv + vec2f( sx, sy)).r, 0.0);\n let gx = (d20 + 2.0*d21 + d22) - (d00 + 2.0*d01 + d02);\n let gy = (d02 + 2.0*d12 + d22) - (d00 + 2.0*d10 + d20);\n let norm = normalize(vec3f(gx, gy, 1.2));\n let ldir = normalize(vec3f(0.5, 1.0, 0.5));\n let halfV = normalize(ldir + vec3f(0.0, 0.0, 1.0));\n let specDen = density * min(density * 5.0, 1.0);\n let spec = pow(max(dot(norm, halfV), 0.0), u.specularExp) * u.shine * specDen;\n let bgRaw = textureSample(uBg, samp, i.uv).rgb;\n let wc = u.waterColor.rgb;\n let gc = u.glowColor.rgb;\n let bg = mix(wc, bgRaw, cov);\n var color = bg;\n if (u.algorithm == 1) {\n let ruv = clamp(i.uv + norm.xy * u.refraction * density * 3.0, vec2f(0.0), vec2f(1.0));\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n color = rbg + spec * gc * 2.5;\n color = mix(color, bg * 0.6, obs * 0.3);\n } else if (u.algorithm == 2) {\n let inkD = min(density * 4.0, 1.0);\n let ruv = clamp(i.uv + norm.xy * u.refraction * density * 0.4, vec2f(0.0), vec2f(1.0));\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n color = mix(rbg, wc + spec * gc, inkD);\n color = mix(color, bg * 0.5, obs * 0.15);\n } else if (u.algorithm == 3) {\n let vel = textureSample(uVel, samp, i.uv).xy;\n let velMag = clamp(length(vel) * 20.0, 0.0, 1.0);\n let wuv = clamp(i.uv + vel * u.warpStrength, vec2f(0.0), vec2f(1.0));\n let wbg = mix(wc, textureSample(uBg, samp, wuv).rgb, cov);\n color = mix(bg, wbg, velMag * (1.0 - obs));\n color += spec * gc * velMag * 1.5;\n color += wc * density * 0.3;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else if (u.algorithm == 4) {\n let ruv = clamp(i.uv + norm.xy * u.refraction * density * 6.0, vec2f(0.0), vec2f(1.0));\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n let fres = pow(clamp(1.0 - dot(norm, vec3f(0.0, 0.0, 1.0)), 0.0, 1.0), 3.0) * density;\n color = rbg;\n color += fres * gc * 2.0;\n color += spec * gc * density * 2.0;\n color = mix(color, bg * 0.5, obs * 0.2);\n } else {\n let ruv = i.uv + norm.xy * u.refraction * density;\n let rbg = mix(wc, textureSample(uBg, samp, mix(i.uv, ruv, 1.0 - obs)).rgb, cov);\n color = mix(rbg, wc, min(density * 1.5, 0.8));\n color += spec * gc;\n color = mix(color, bg * 0.5, obs * 0.2);\n }\n let alpha = clamp(max(density * 1.5, cov), 0.0, 1.0);\n if (u.enableAlpha == 1) {\n return vec4f(color * alpha, alpha);\n }\n return vec4f(color, 1.0);\n}`,t,n?void 0:y)}}function x(e){return e.createSampler({magFilter:`linear`,minFilter:`linear`,addressModeU:`clamp-to-edge`,addressModeV:`clamp-to-edge`})}function S(e,t){return e.createBuffer({size:t,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST})}function C(e,t,n,r,i,a){let o=new Float32Array([n,r,i,a]);e.queue.writeBuffer(t,0,o)}function w(e,t,n,r){let i=new Float32Array([n,r,0,0]);e.queue.writeBuffer(t,0,i)}function T(e,t,n,r,i,a){let o=new Float32Array([n,r,i,a]);e.queue.writeBuffer(t,0,o)}function E(e,t,n,r,i,a,o,s,c,l,u){let d=new Float32Array(12);d[0]=n,d[1]=r,d[2]=i,d[3]=a,d[4]=o,d[5]=s,d[6]=c,d[7]=0,d[8]=l,d[9]=u,d[10]=0,d[11]=0,e.queue.writeBuffer(t,0,d)}function D(e,t,n,r,i,a,o,s,c,l,u,d){let f=new Float32Array(16),p=new Int32Array(f.buffer);f[0]=n,f[1]=r,f[2]=i,f[3]=a,f[4]=o[0],f[5]=o[1],f[6]=o[2],f[7]=0,f[8]=s[0],f[9]=s[1],f[10]=s[2],f[11]=0,f[12]=c,f[13]=l,p[14]=u,p[15]=+!!d,e.queue.writeBuffer(t,0,f)}function O(e,t,n,r,i){let a=e.beginRenderPass({colorAttachments:[{view:i,clearValue:[0,0,0,0],loadOp:`clear`,storeOp:`store`}]});a.setPipeline(t),a.setBindGroup(0,n),a.setVertexBuffer(0,r),a.draw(6),a.end()}function k(e,t,n,r,i){let a=e.beginRenderPass({colorAttachments:[{view:i,clearValue:[0,0,0,0],loadOp:`clear`,storeOp:`store`}]});a.setPipeline(t),a.setBindGroup(0,n),a.setVertexBuffer(0,r),a.draw(6),a.end()}function A(e,t,n,r,i=`cover`){let a;a=i===`cover`?Math.max(n/e,r/t):i===`contain`?Math.min(n/e,r/t):typeof i==`string`&&i.endsWith(`%`)?Math.min(n/e,r/t)*(parseFloat(i)/100):typeof i==`string`&&i.endsWith(`px`)?parseFloat(i)/Math.max(e,t):typeof i==`number`?i:Math.max(n/e,r/t);let o=e*a,s=t*a;return{x:(n-o)/2,y:(r-s)/2,drawW:o,drawH:s}}function j(e,t,n,r,i=null,a=`cover`){let{text:o,fontSize:s,color:c,fontFamily:l=`sans-serif`,fontWeight:u=900}=r,d=new OffscreenCanvas(t,n),f=d.getContext(`2d`);(e=>{if(i){f.clearRect(0,0,t,n),f.fillStyle=`black`,f.fillRect(0,0,t,n);let{x:e,y:r,drawW:o,drawH:s}=A(i.width,i.height,t,n,a);f.drawImage(i,e,r,o,s)}else f.fillStyle=`black`,f.fillRect(0,0,t,n);f.fillStyle=e,f.font=`${u} ${s}px ${l}`,f.textAlign=`center`,f.textBaseline=`middle`,f.fillText(o,t/2,n/2)})(c);let p=N(e,d);f.fillStyle=`black`,f.fillRect(0,0,t,n),f.fillStyle=`white`,f.font=`${u} ${s}px ${l}`,f.textAlign=`center`,f.textBaseline=`middle`,f.fillText(o,t/2,n/2);let m=N(e,d);return{backgroundTex:p,obstacleTex:m,coverageTex:m}}function M(e,t,n,r,i=0,a=`cover`,o=null,s=`cover`){let c=new OffscreenCanvas(n,r),l=c.getContext(`2d`),{x:u,y:d,drawW:f,drawH:p}=A(t.width,t.height,n,r,a);if(l.clearRect(0,0,n,r),l.fillStyle=`black`,l.fillRect(0,0,n,r),o){let{x:e,y:t,drawW:a,drawH:c}=A(o.width,o.height,n,r,s);l.filter=`brightness(${i}) blur(8px)`,l.drawImage(o,e,t,a,c),l.filter=`none`}l.drawImage(t,u,d,f,p);let m=N(e,c);l.clearRect(0,0,n,r),l.fillStyle=`black`,l.fillRect(0,0,n,r),l.filter=`brightness(${i}) blur(8px)`,l.drawImage(t,u,d,f,p),l.filter=`none`;let h=N(e,c);return l.clearRect(0,0,n,r),l.fillStyle=`black`,l.fillRect(0,0,n,r),l.fillStyle=`white`,l.fillRect(Math.max(0,u),Math.max(0,d),Math.min(f,n-Math.max(0,u)),Math.min(p,r-Math.max(0,d))),{backgroundTex:m,obstacleTex:h,coverageTex:N(e,c)}}function N(e,t){let n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),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),n}function P(e,t,n,r,i=null,a=`cover`){let{text:o,fontSize:s,color:c,fontFamily:l=`sans-serif`,fontWeight:u=900}=r,d=new OffscreenCanvas(t,n),f=d.getContext(`2d`);(e=>{if(i){f.clearRect(0,0,t,n),f.fillStyle=`black`,f.fillRect(0,0,t,n);let{x:e,y:r,drawW:o,drawH:s}=A(i.width,i.height,t,n,a);f.drawImage(i,e,r,o,s)}else f.fillStyle=`black`,f.fillRect(0,0,t,n);f.fillStyle=e,f.font=`${u} ${s}px ${l}`,f.textAlign=`center`,f.textBaseline=`middle`,f.fillText(o,t/2,n/2)})(c);let p=I(e,d,t,n);f.fillStyle=`black`,f.fillRect(0,0,t,n),f.fillStyle=`white`,f.font=`${u} ${s}px ${l}`,f.textAlign=`center`,f.textBaseline=`middle`,f.fillText(o,t/2,n/2);let m=I(e,d,t,n);return{backgroundTex:p,backgroundView:p.createView(),obstacleTex:m,obstacleView:m.createView(),coverageTex:m,coverageView:m.createView(),sharedCoverage:!0}}function F(e,t,n,r,i=0,a=`cover`,o=null,s=`cover`){let c=new OffscreenCanvas(n,r),l=c.getContext(`2d`),{x:u,y:d,drawW:f,drawH:p}=A(t.width,t.height,n,r,a);if(l.clearRect(0,0,n,r),l.fillStyle=`black`,l.fillRect(0,0,n,r),o){let{x:e,y:t,drawW:a,drawH:c}=A(o.width,o.height,n,r,s);l.filter=`brightness(${i}) blur(8px)`,l.drawImage(o,e,t,a,c),l.filter=`none`}l.drawImage(t,u,d,f,p);let m=I(e,c,n,r);l.clearRect(0,0,n,r),l.fillStyle=`black`,l.fillRect(0,0,n,r),l.filter=`brightness(${i}) blur(8px)`,l.drawImage(t,u,d,f,p),l.filter=`none`;let h=I(e,c,n,r);l.clearRect(0,0,n,r),l.fillStyle=`black`,l.fillRect(0,0,n,r),l.fillStyle=`white`,l.fillRect(Math.max(0,u),Math.max(0,d),Math.min(f,n-Math.max(0,u)),Math.min(p,r-Math.max(0,d)));let g=I(e,c,n,r);return{backgroundTex:m,backgroundView:m.createView(),obstacleTex:h,obstacleView:h.createView(),coverageTex:g,coverageView:g.createView(),sharedCoverage:!1}}function I(e,t,n,r){let i=e.createTexture({size:[n,r],format:`rgba8unorm`,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT});return e.queue.copyExternalImageToTexture({source:t},{texture:i},[n,r]),i}async function L(e){let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch image: ${e} (${t.status})`);let n=await t.blob();return createImageBitmap(n)}const R=typeof requestAnimationFrame<`u`?requestAnimationFrame.bind(globalThis):e=>setTimeout(e,1e3/60),z=typeof cancelAnimationFrame<`u`?cancelAnimationFrame.bind(globalThis):clearTimeout,B=.016,V={standard:0,glass:1,ink:2,aurora:3,ripple:4};var H=class e{#e;#t=null;#n=null;#r=null;#i=null;#a=null;#o=null;#s=null;#c=null;#l=null;#u=null;#d=null;#f=null;#p=null;#m=null;#h=null;#g=null;#_=null;#v=null;#y=null;#b=null;#x=null;#S=null;#C=null;#w=null;#T=null;#E=null;#D=null;#O=null;#k=null;#A=null;#j=null;#M=null;#N=0;#P=0;#F=0;#I=0;#L=1;#R=1;#z=.5;#B=null;#V=`cover`;#H;#U={x:0,y:0,dx:0,dy:0,targetX:0,targetY:0,moved:!1};#W=!1;#G=null;#K=null;#q=!1;#J=!1;#Y=!0;constructor(e,t={},n={},r,a=!0){if(this.#e=e,this.#R=Math.max(.1,Math.min(1,n.dpr??1)),this.#z=Math.max(.1,Math.min(1,n.sim??.5)),this.#H=i(t),this.#Y=a,r)this.#p=r,this.#X(r);else{let{gl:t,ext:n}=o(e,a);this.#t=t,this.#n=n,this.#r=l(t),this.#i=f(t),t.clearColor(0,0,0,+!a)}}static async create(t,n={},r={},i=!0,a=!0){return new e(t,n,r,(i?await s(t,a):null)??void 0,a)}setTextSource(e){this.#G={type:`text`,opts:e},this.#Z(),this.#$(),this.#ee()}async setImageSource(e,t=0,n=`cover`){let r=await L(e);if(this.#J){r.close();return}this.#G={type:`image`,bitmap:r,effect:t,size:n},this.#Z(),this.#$(),this.#ee()}setImageBitmap(e,t=0,n=`cover`){this.#G={type:`image`,bitmap:e,effect:t,size:n},this.#Z(),this.#$(),this.#ee()}setBackground(e,t=`cover`){this.#B&&this.#B!==e&&this.#B.close(),this.#B=e,this.#V=t??`cover`,this.#G&&this.#N>0&&this.#P>0&&this.#$()}handleMove(e,t,n=1){if(!this.#W){this.#U.x=this.#U.targetX=e,this.#U.y=this.#U.targetY=t,this.#W=!0;return}this.#U.moved=!0,this.#U.dx=(e-this.#U.targetX)*n,this.#U.dy=(t-this.#U.targetY)*n,this.#U.targetX=e,this.#U.targetY=t}splat(e,t,n,r,i=1){!this.#q||this.#N===0||(this.#p?this.#ae(e,t,n,r,i):this.#oe(e,t,n,r,i))}updateQuality(e){e.dpr!==void 0&&(this.#R=Math.max(.1,Math.min(1,e.dpr))),e.sim!==void 0&&(this.#z=Math.max(.1,Math.min(1,e.sim)))}resize(e,t,n){if(n===void 0?typeof window<`u`&&window.devicePixelRatio&&(this.#L=window.devicePixelRatio):this.#L=n,e!==void 0&&e>0){if(t===void 0||t<=0)return;this.#N=this.#e.width=e,this.#P=this.#e.height=t,this.#F=Math.max(1,Math.round(e*this.#z)),this.#I=Math.max(1,Math.round(t*this.#z)),this.#Q()}else this.#Z();this.#G&&this.#$(),this.#ee()}updateConfig(e){Object.assign(this.#H,e)}destroy(){if(this.#J=!0,this.stop(),this.#te(),this.#ne(),this.#B&&=(this.#B.close(),null),this.#p)this.#C?.destroy(),this.#w?.destroy(),this.#T?.destroy(),this.#E?.destroy(),this.#D?.destroy(),this.#O?.destroy(),this.#k?.destroy(),this.#A?.destroy(),this.#j?.destroy(),this.#M?.destroy(),this.#h?.destroy(),this.#p.device.destroy();else{let e=this.#t;for(let e of Object.values(this.#r))e.dispose();e.getExtension(`WEBGL_lose_context`)?.loseContext()}}start(){if(this.#K!==null)return;let e=()=>{this.#re(),this.#K=R(e)};this.#K=R(e)}stop(){this.#K!==null&&(z(this.#K),this.#K=null)}get isRunning(){return this.#K!==null}#X(e){let{device:t,format:n}=e;this.#m=b(t,n,this.#Y),this.#h=h(t),this.#g=x(t),this.#C=S(t,16),this.#w=S(t,16),this.#T=S(t,16),this.#E=S(t,16),this.#D=S(t,16),this.#O=S(t,48),this.#k=S(t,48),this.#A=S(t,16),this.#j=S(t,16),this.#M=S(t,64)}#Z(){let e=this.#e;`clientWidth`in e&&e.clientWidth>0?(this.#L=(typeof window<`u`&&window.devicePixelRatio||1)*this.#R,this.#N=e.width=Math.round(e.clientWidth*this.#L),this.#P=e.height=Math.round(e.clientHeight*this.#L)):(this.#N=e.width,this.#P=e.height),!(this.#N===0||this.#P===0)&&(this.#F=Math.max(1,Math.round(this.#N*this.#z)),this.#I=Math.max(1,Math.round(this.#P*this.#z)),this.#Q())}#Q(){if(this.#te(),this.#p){let{device:e}=this.#p,t=`rgba16float`,n=this.#F,r=this.#I;this.#_=_(e,t,n,r),this.#v=_(e,t,n,r),this.#b=_(e,t,n,r),this.#y=g(e,t,n,r),this.#x=g(e,t,n,r)}else{let e=this.#t,t=this.#n,n=this.#F,r=this.#I;this.#a=d(e,t,n,r),this.#o=d(e,t,n,r),this.#c=d(e,t,n,r),this.#s=u(e,t,n,r),this.#l=u(e,t,n,r)}}#$(){if(!(!this.#G||this.#N===0||this.#P===0)){if(this.#ne(),this.#p){let{device:e}=this.#p;this.#G.type===`text`?this.#S=P(e,this.#N,this.#P,this.#G.opts,this.#B,this.#V):this.#S=F(e,this.#G.bitmap,this.#N,this.#P,this.#G.effect,this.#G.size,this.#B,this.#V)}else{let e=this.#t;if(this.#G.type===`text`){let{backgroundTex:t,obstacleTex:n,coverageTex:r}=j(e,this.#N,this.#P,this.#G.opts,this.#B,this.#V);this.#u=t,this.#d=n,this.#f=r}else{let{backgroundTex:t,obstacleTex:n,coverageTex:r}=M(e,this.#G.bitmap,this.#N,this.#P,this.#G.effect,this.#G.size,this.#B,this.#V);this.#u=t,this.#d=n,this.#f=r}}this.#q=!0}}#ee(){this.#q&&!this.isRunning&&this.start()}#te(){if(this.#p)this.#_?.dispose(),this.#v?.dispose(),this.#b?.dispose(),this.#y?.tex.destroy(),this.#x?.tex.destroy(),this.#_=this.#v=this.#b=null,this.#y=this.#x=null;else{let e=this.#t;this.#a?.dispose(),this.#o?.dispose(),this.#c?.dispose(),this.#s&&(e.deleteTexture(this.#s.tex),e.deleteFramebuffer(this.#s.fbo)),this.#l&&(e.deleteTexture(this.#l.tex),e.deleteFramebuffer(this.#l.fbo)),this.#a=this.#o=this.#c=this.#s=this.#l=null}}#ne(){if(this.#p)this.#S&&=(this.#S.backgroundTex.destroy(),this.#S.obstacleTex.destroy(),this.#S.sharedCoverage||this.#S.coverageTex.destroy(),null);else{let e=this.#t;this.#u&&e.deleteTexture(this.#u),this.#d&&e.deleteTexture(this.#d),this.#f&&this.#f!==this.#d&&e.deleteTexture(this.#f),this.#u=this.#d=this.#f=null}}#re(){!this.#q||this.#N===0||(this.#p?this.#ie():this.#se())}#ie(){let e=this.#p,t=e.device,n=this.#m,i=this.#h,a=this.#g,o=this.#H,s=this.#S;if(!this.#_||!this.#v)return;this.#U.x+=(this.#U.targetX-this.#U.x)*.15,this.#U.y+=(this.#U.targetY-this.#U.y)*.15;let c=this.#F,l=this.#I,u=this.#N,d=this.#P,f=1/c,p=1/l;C(t,this.#C,f,p,B,o.velocityDissipation),w(t,this.#T,f,p),w(t,this.#E,f,p),w(t,this.#D,f,p),w(t,this.#A,f,p),T(t,this.#j,f,p,o.curl,B),D(t,this.#M,1/u,1/d,o.refraction,o.specularExp,r(o.waterColor),r(o.glowColor),o.shine,o.warpStrength??.015,V[o.algorithm]??0,this.#Y);let m=t.createCommandEncoder(),h=(e,n)=>t.createBindGroup({layout:e.getBindGroupLayout(0),entries:n}),g={binding:1,resource:a};{let e=h(n.advection,[{binding:0,resource:{buffer:this.#C}},g,{binding:2,resource:this.#v.read.view},{binding:3,resource:this.#v.read.view},{binding:4,resource:s.obstacleView}]);O(m,n.advection,e,i,this.#v.write.view)}this.#v.swap();{C(t,this.#w,f,p,B,o.densityDissipation);let e=h(n.advection,[{binding:0,resource:{buffer:this.#w}},g,{binding:2,resource:this.#v.read.view},{binding:3,resource:this.#_.read.view},{binding:4,resource:s.obstacleView}]);O(m,n.advection,e,i,this.#_.write.view)}this.#_.swap();{let e=h(n.curl,[{binding:0,resource:{buffer:this.#A}},g,{binding:2,resource:this.#v.read.view}]);O(m,n.curl,e,i,this.#x.view)}{let e=h(n.vorticity,[{binding:0,resource:{buffer:this.#j}},g,{binding:2,resource:this.#v.read.view},{binding:3,resource:this.#x.view}]);O(m,n.vorticity,e,i,this.#v.write.view)}if(this.#v.swap(),this.#U.moved){let e=this.#U.x*this.#L/u,r=this.#U.y*this.#L/d;E(t,this.#O,f,p,u/d,o.splatRadius,this.#U.dx*o.splatForce,this.#U.dy*o.splatForce,0,e,r);{let e=h(n.splat,[{binding:0,resource:{buffer:this.#O}},g,{binding:2,resource:this.#v.read.view}]);O(m,n.splat,e,i,this.#v.write.view)}this.#v.swap(),E(t,this.#k,f,p,u/d,o.splatRadius,1,1,1,e,r);{let e=h(n.splat,[{binding:0,resource:{buffer:this.#k}},g,{binding:2,resource:this.#_.read.view}]);O(m,n.splat,e,i,this.#_.write.view)}this.#_.swap(),this.#U.moved=!1}{let e=h(n.divergence,[{binding:0,resource:{buffer:this.#T}},g,{binding:2,resource:this.#v.read.view},{binding:3,resource:s.obstacleView}]);O(m,n.divergence,e,i,this.#y.view)}for(let e=0;e<o.pressureIterations;e++){let e=h(n.pressure,[{binding:0,resource:{buffer:this.#E}},g,{binding:2,resource:this.#b.read.view},{binding:3,resource:this.#y.view},{binding:4,resource:s.obstacleView}]);O(m,n.pressure,e,i,this.#b.write.view),this.#b.swap()}{let e=h(n.gradientSubtract,[{binding:0,resource:{buffer:this.#D}},g,{binding:2,resource:this.#b.read.view},{binding:3,resource:this.#v.read.view},{binding:4,resource:s.obstacleView}]);O(m,n.gradientSubtract,e,i,this.#v.write.view)}this.#v.swap();{let t=e.context.getCurrentTexture().createView(),r=h(n.display,[{binding:0,resource:{buffer:this.#M}},g,{binding:2,resource:this.#_.read.view},{binding:3,resource:s.obstacleView},{binding:4,resource:s.backgroundView},{binding:5,resource:s.coverageView},{binding:6,resource:this.#v.read.view}]);k(m,n.display,r,i,t)}t.queue.submit([m.finish()])}#ae(e,t,n,r,i){let a=this.#p.device,o=this.#m.splat,s=this.#h,c=this.#g,l=this.#H,u=this.#F,d=this.#I,f=1/u,p=1/d,m=a.createCommandEncoder(),h={binding:1,resource:c},g=e=>a.createBindGroup({layout:o.getBindGroupLayout(0),entries:e}),_=e*this.#L/this.#N,v=t*this.#L/this.#P;E(a,this.#O,f,p,this.#N/this.#P,l.splatRadius,n*l.splatForce*i,r*l.splatForce*i,0,_,v),O(m,o,g([{binding:0,resource:{buffer:this.#O}},h,{binding:2,resource:this.#v.read.view}]),s,this.#v.write.view),this.#v.swap(),E(a,this.#k,f,p,this.#N/this.#P,l.splatRadius,i,i,i,_,v),O(m,o,g([{binding:0,resource:{buffer:this.#k}},h,{binding:2,resource:this.#_.read.view}]),s,this.#_.write.view),this.#_.swap(),a.queue.submit([m.finish()])}#oe(e,t,n,r,i){let a=this.#t,o=this.#H,s=this.#r.splat,c=this.#i;a.viewport(0,0,this.#F,this.#I),s.bind(),a.uniform1f(s.uniforms.aspectRatio,this.#N/this.#P),a.uniform2f(s.uniforms.point,e*this.#L/this.#N,1-t*this.#L/this.#P),a.uniform1f(s.uniforms.radius,o.splatRadius),a.uniform1i(s.uniforms.uTarget,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this.#o.read.tex),a.uniform3f(s.uniforms.color,n*o.splatForce*i,-r*o.splatForce*i,0),c(this.#o.write.fbo),this.#o.swap(),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this.#a.read.tex),a.uniform3f(s.uniforms.color,i,i,i),c(this.#a.write.fbo),this.#a.swap()}#se(){if(!this.#a||!this.#o)return;let e=this.#t,t=this.#H,{advection:n,divergence:i,pressure:a,gradientSubtract:o,splat:s,curl:c,vorticity:l,display:u}=this.#r;this.#U.x+=(this.#U.targetX-this.#U.x)*.15,this.#U.y+=(this.#U.targetY-this.#U.y)*.15;let d=this.#F,f=this.#I,p=this.#i;e.viewport(0,0,d,f),n.bind(),e.uniform2f(n.uniforms.texelSize,1/d,1/f),e.uniform1f(n.uniforms.dt,B),e.uniform1i(n.uniforms.uObstacle,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#d),e.uniform1f(n.uniforms.dissipation,t.velocityDissipation),e.uniform1i(n.uniforms.uVelocity,1),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),e.uniform1i(n.uniforms.uSource,1),p(this.#o.write.fbo),this.#o.swap(),e.uniform1f(n.uniforms.dissipation,t.densityDissipation),e.uniform1i(n.uniforms.uSource,2),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,this.#a.read.tex),p(this.#a.write.fbo),this.#a.swap(),c.bind(),e.uniform2f(c.uniforms.texelSize,1/d,1/f),e.uniform1i(c.uniforms.uVelocity,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),p(this.#l.fbo),l.bind(),e.uniform2f(l.uniforms.texelSize,1/d,1/f),e.uniform1f(l.uniforms.curl,t.curl),e.uniform1f(l.uniforms.dt,B),e.uniform1i(l.uniforms.uVelocity,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),e.uniform1i(l.uniforms.uCurl,1),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.#l.tex),p(this.#o.write.fbo),this.#o.swap(),this.#U.moved&&(s.bind(),e.uniform1f(s.uniforms.aspectRatio,this.#N/this.#P),e.uniform2f(s.uniforms.point,this.#U.x*this.#L/this.#N,1-this.#U.y*this.#L/this.#P),e.uniform1f(s.uniforms.radius,t.splatRadius),e.uniform1i(s.uniforms.uTarget,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),e.uniform3f(s.uniforms.color,this.#U.dx*t.splatForce,-this.#U.dy*t.splatForce,0),p(this.#o.write.fbo),this.#o.swap(),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#a.read.tex),e.uniform3f(s.uniforms.color,1,1,1),p(this.#a.write.fbo),this.#a.swap(),this.#U.moved=!1),i.bind(),e.uniform2f(i.uniforms.texelSize,1/d,1/f),e.uniform1i(i.uniforms.uVelocity,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),e.uniform1i(i.uniforms.uObstacle,1),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.#d),p(this.#s.fbo),a.bind(),e.uniform2f(a.uniforms.texelSize,1/d,1/f),e.uniform1i(a.uniforms.uDivergence,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#s.tex),e.uniform1i(a.uniforms.uObstacle,1),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.#d);for(let n=0;n<t.pressureIterations;n++)e.uniform1i(a.uniforms.uPressure,2),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,this.#c.read.tex),p(this.#c.write.fbo),this.#c.swap();o.bind(),e.uniform2f(o.uniforms.texelSize,1/d,1/f),e.uniform1i(o.uniforms.uPressure,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#c.read.tex),e.uniform1i(o.uniforms.uVelocity,1),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),e.uniform1i(o.uniforms.uObstacle,2),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,this.#d),p(this.#o.write.fbo),this.#o.swap(),e.viewport(0,0,this.#N,this.#P),e.bindFramebuffer(e.FRAMEBUFFER,null),e.clear(e.COLOR_BUFFER_BIT),u.bind(),e.uniform2f(u.uniforms.texelSize,1/this.#N,1/this.#P),e.uniform3fv(u.uniforms.uWaterColor,r(t.waterColor)),e.uniform3fv(u.uniforms.uGlowColor,r(t.glowColor)),e.uniform1f(u.uniforms.uRefraction,t.refraction),e.uniform1f(u.uniforms.uSpecularExp,t.specularExp),e.uniform1f(u.uniforms.uShine,t.shine),e.uniform1f(u.uniforms.uWarpStrength,t.warpStrength??.015),e.uniform1i(u.uniforms.uAlgorithm,V[t.algorithm]??0),e.uniform1i(u.uniforms.uEnableAlpha,+!!this.#Y),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.#a.read.tex),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this.#d),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,this.#u),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_2D,this.#f),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_2D,this.#o.read.tex),e.uniform1i(u.uniforms.uTexture,0),e.uniform1i(u.uniforms.uObstacle,1),e.uniform1i(u.uniforms.uBackground,2),e.uniform1i(u.uniforms.uCoverage,3),e.uniform1i(u.uniforms.uVelocity,4),p(null)}};let U=null,W;const G=new Promise(e=>{W=e});self.onmessage=async e=>{let{type:t,...n}=e.data;try{switch(t){case`init`:{let{canvas:e,width:t,height:r,config:i,dpr:a,quality:o,useWebGPU:s,enableAlpha:c}=n;e.width=t,e.height=r,U=await H.create(e,i,o??{},s??!0,c??!0),U.resize(t,r,a||1),W(),self.postMessage({type:`ready`});break}case`setTextSource`:if(await G,!U)return;U.setTextSource(n.opts);break;case`setImageSource`:if(await G,!U)return;await U.setImageSource(n.src,n.effect,n.size);break;case`setImageBitmap`:if(await G,!U)return;U.setImageBitmap(n.bitmap,n.effect,n.size);break;case`setBackground`:if(await G,!U)return;U.setBackground(n.bitmap,n.size);break;case`splat`:if(await G,!U)return;U.splat(n.x,n.y,n.vx,n.vy,n.strength??1);break;case`move`:if(await G,!U)return;U.handleMove(n.x,n.y,n.strength??1);break;case`resize`:if(await G,!U)return;U.resize(n.width,n.height,n.dpr);break;case`updateQuality`:if(await G,!U)return;U.updateQuality(n.quality);break;case`updateConfig`:if(await G,!U)return;U.updateConfig(n.config);break;case`destroy`:await G,U?.destroy(),U=null;break;default:}}catch(e){self.postMessage({type:`error`,message:e?.message??String(e)})}};", ve = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", _e], { type: "text/javascript;charset=utf-8" });
1039
+ function ye(e) {
1040
+ let t;
2996
1041
  try {
2997
- switch (e) {
2998
- case "init": {
2999
- const { canvas: i, width: s, height: o, config: u, dpr: c, quality: v, useWebGPU: n, enableAlpha: f } = t;
3000
- i.width = s, i.height = o, g = await Ce.create(i, u, v ?? {}, n ?? !0, f ?? !0), g.resize(s, o, c || 1), Y(), self.postMessage({ type: "ready" });
3001
- break;
3002
- }
3003
- case "setTextSource":
3004
- if (await R, !g) return;
3005
- g.setTextSource(t.opts);
3006
- break;
3007
- case "setImageSource":
3008
- if (await R, !g) return;
3009
- await g.setImageSource(t.src, t.effect, t.size);
3010
- break;
3011
- case "setImageBitmap":
3012
- if (await R, !g) return;
3013
- g.setImageBitmap(t.bitmap, t.effect, t.size);
3014
- break;
3015
- case "setBackground":
3016
- if (await R, !g) return;
3017
- g.setBackground(t.bitmap, t.size);
3018
- break;
3019
- case "splat":
3020
- if (await R, !g) return;
3021
- g.splat(t.x, t.y, t.vx, t.vy, t.strength ?? 1);
3022
- break;
3023
- case "move":
3024
- if (await R, !g) return;
3025
- g.handleMove(t.x, t.y, t.strength ?? 1);
3026
- break;
3027
- case "resize":
3028
- if (await R, !g) return;
3029
- g.resize(t.width, t.height, t.dpr);
3030
- break;
3031
- case "updateQuality":
3032
- if (await R, !g) return;
3033
- g.updateQuality(t.quality);
3034
- break;
3035
- case "updateConfig":
3036
- if (await R, !g) return;
3037
- g.updateConfig(t.config);
3038
- break;
3039
- case "destroy":
3040
- await R, g?.destroy(), g = null;
3041
- break;
3042
- default:
3043
- }
3044
- } catch (i) {
3045
- self.postMessage({
3046
- type: "error",
3047
- message: i?.message ?? String(i)
1042
+ if (t = ve && (self.URL || self.webkitURL).createObjectURL(ve), !t) throw "";
1043
+ let n = new Worker(t, {
1044
+ type: "module",
1045
+ name: e?.name
1046
+ });
1047
+ return n.addEventListener("error", () => {
1048
+ (self.URL || self.webkitURL).revokeObjectURL(t);
1049
+ }), n;
1050
+ } catch {
1051
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(_e), {
1052
+ type: "module",
1053
+ name: e?.name
3048
1054
  });
3049
1055
  }
3050
- };
3051
- `, ge = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Ee], { type: "text/javascript;charset=utf-8" });
3052
- function ut(r) {
3053
- let e;
3054
- try {
3055
- if (e = ge && (self.URL || self.webkitURL).createObjectURL(ge), !e)
3056
- throw "";
3057
- const t = new Worker(e, {
3058
- type: "module",
3059
- name: r?.name
3060
- });
3061
- return t.addEventListener("error", () => {
3062
- (self.URL || self.webkitURL).revokeObjectURL(e);
3063
- }), t;
3064
- } catch {
3065
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Ee), {
3066
- type: "module",
3067
- name: r?.name
3068
- });
3069
- }
3070
1056
  }
3071
- var lt = typeof Worker < "u" && typeof OffscreenCanvas < "u", ct = class {
3072
- #r = null;
3073
- #i = null;
3074
- #U;
3075
- #g;
3076
- #b;
3077
- #s;
3078
- #t;
3079
- #c = null;
3080
- #f = null;
3081
- constructor(r, { workerEnabled: e = !0, webGPUEnabled: t = !0, alphaEnabled: n = !0, quality: i = {}, config: s = {} } = {}) {
3082
- this.#s = Math.max(0.1, Math.min(1, i.dpr ?? 1)), this.#t = Math.max(0.1, Math.min(1, i.sim ?? 0.5)), this.#g = t, this.#b = n, this.#U = e && lt, this.#U ? this.#T(r, s) : this.#d(r, s);
3083
- }
3084
- setTextSource(r) {
3085
- this.#r ? this.#r.postMessage({
3086
- type: "setTextSource",
3087
- opts: r
3088
- }) : this.#i ? this.#i.setTextSource(r) : (this.#c = r, this.#f = null);
3089
- }
3090
- setImageSource(r, e = A.effect, t = A.imageSize) {
3091
- if (this.#r) {
3092
- const n = new URL(r, location.href).href;
3093
- this.#r.postMessage({
3094
- type: "setImageSource",
3095
- src: n,
3096
- effect: e,
3097
- size: t
3098
- });
3099
- } else
3100
- this.#i ? this.#i.setImageSource(r, e, t) : (this.#f = {
3101
- src: r,
3102
- effect: e,
3103
- size: t
3104
- }, this.#c = null);
3105
- }
3106
- setBackground(r, e = "cover") {
3107
- if (this.#r) {
3108
- const t = r ? [r] : [];
3109
- this.#r.postMessage({
3110
- type: "setBackground",
3111
- bitmap: r ?? null,
3112
- size: e
3113
- }, t);
3114
- } else
3115
- this.#i?.setBackground(r ?? null, e);
3116
- }
3117
- splat(r, e, t, n, i = 1) {
3118
- this.#r ? this.#r.postMessage({
3119
- type: "splat",
3120
- x: r,
3121
- y: e,
3122
- vx: t,
3123
- vy: n,
3124
- strength: i
3125
- }) : this.#i.splat(r, e, t, n, i);
3126
- }
3127
- handleMove(r, e, t = 1) {
3128
- this.#r ? this.#r.postMessage({
3129
- type: "move",
3130
- x: r,
3131
- y: e,
3132
- strength: t
3133
- }) : this.#i.handleMove(r, e, t);
3134
- }
3135
- updateQuality(r) {
3136
- this.#s = Math.max(0.1, Math.min(1, r.dpr ?? this.#s)), this.#t = Math.max(0.1, Math.min(1, r.sim ?? this.#t)), this.#r ? this.#r.postMessage({
3137
- type: "updateQuality",
3138
- quality: {
3139
- dpr: this.#s,
3140
- sim: this.#t
3141
- }
3142
- }) : this.#i.updateQuality(r);
3143
- }
3144
- updateConfig(r) {
3145
- this.#r ? this.#r.postMessage({
3146
- type: "updateConfig",
3147
- config: r
3148
- }) : this.#i.updateConfig(r);
3149
- }
3150
- resize(r, e) {
3151
- const t = (typeof window < "u" && window.devicePixelRatio || 1) * this.#s;
3152
- this.#r ? this.#r.postMessage({
3153
- type: "resize",
3154
- width: r,
3155
- height: e,
3156
- dpr: t
3157
- }) : this.#i?.resize(r, e, t);
3158
- }
3159
- destroy() {
3160
- if (this.#r) {
3161
- const r = this.#r;
3162
- this.#r = null, r.postMessage({ type: "destroy" }), setTimeout(() => r.terminate(), 50);
3163
- } else
3164
- this.#i?.destroy(), this.#i = null;
3165
- }
3166
- #d(r, e) {
3167
- const t = {
3168
- dpr: this.#s,
3169
- sim: this.#t
3170
- };
3171
- this.#g && typeof navigator < "u" && navigator.gpu ? pe.create(r, e, t, !0, this.#b).then((n) => {
3172
- if (this.#i = n, this.#c)
3173
- n.setTextSource(this.#c), this.#c = null;
3174
- else if (this.#f) {
3175
- const { src: i, effect: s, size: a } = this.#f;
3176
- n.setImageSource(i, s, a), this.#f = null;
3177
- }
3178
- }).catch((n) => {
3179
- }) : this.#i = new pe(r, e, t, void 0, this.#b);
3180
- }
3181
- #T(r, e) {
3182
- const t = (typeof window < "u" && window.devicePixelRatio || 1) * this.#s, n = Math.round(r.clientWidth * t), i = Math.round(r.clientHeight * t);
3183
- r.width = n, r.height = i;
3184
- let s;
3185
- try {
3186
- s = r.transferControlToOffscreen();
3187
- } catch {
3188
- this.#U = !1, this.#d(r, e);
3189
- return;
3190
- }
3191
- const a = this.#r = new ut();
3192
- a.onerror = (c) => /* @__PURE__ */ z("Worker error:", c.message), a.onmessage = (c) => {
3193
- c.data.type === "error" && c.data.message;
3194
- }, a.postMessage({
3195
- type: "init",
3196
- canvas: s,
3197
- width: n,
3198
- height: i,
3199
- config: e,
3200
- dpr: t,
3201
- quality: {
3202
- dpr: this.#s,
3203
- sim: this.#t
3204
- },
3205
- useWebGPU: this.#g,
3206
- enableAlpha: this.#b
3207
- }, [s]);
3208
- }
1057
+ //#endregion
1058
+ //#region src/fluid-controller.ts
1059
+ var be = typeof Worker < "u" && typeof OffscreenCanvas < "u", xe = class {
1060
+ #e = null;
1061
+ #t = null;
1062
+ #n;
1063
+ #r;
1064
+ #i;
1065
+ #a;
1066
+ #o;
1067
+ #s = null;
1068
+ #c = null;
1069
+ constructor(e, { workerEnabled: t = !0, webGPUEnabled: n = !0, alphaEnabled: r = !0, quality: i = {}, config: a = {} } = {}) {
1070
+ this.#a = Math.max(.1, Math.min(1, i.dpr ?? 1)), this.#o = Math.max(.1, Math.min(1, i.sim ?? .5)), this.#r = n, this.#i = r, this.#n = t && be, this.#n ? this.#u(e, a) : this.#l(e, a);
1071
+ }
1072
+ setTextSource(e) {
1073
+ this.#e ? this.#e.postMessage({
1074
+ type: "setTextSource",
1075
+ opts: e
1076
+ }) : this.#t ? this.#t.setTextSource(e) : (this.#s = e, this.#c = null);
1077
+ }
1078
+ setImageSource(e, t = d.effect, n = d.imageSize) {
1079
+ if (this.#e) {
1080
+ let r = new URL(e, location.href).href;
1081
+ this.#e.postMessage({
1082
+ type: "setImageSource",
1083
+ src: r,
1084
+ effect: t,
1085
+ size: n
1086
+ });
1087
+ } else this.#t ? this.#t.setImageSource(e, t, n) : (this.#c = {
1088
+ src: e,
1089
+ effect: t,
1090
+ size: n
1091
+ }, this.#s = null);
1092
+ }
1093
+ setBackground(e, t = "cover") {
1094
+ if (this.#e) {
1095
+ let n = e ? [e] : [];
1096
+ this.#e.postMessage({
1097
+ type: "setBackground",
1098
+ bitmap: e ?? null,
1099
+ size: t
1100
+ }, n);
1101
+ } else this.#t?.setBackground(e ?? null, t);
1102
+ }
1103
+ splat(e, t, n, r, i = 1) {
1104
+ this.#e ? this.#e.postMessage({
1105
+ type: "splat",
1106
+ x: e,
1107
+ y: t,
1108
+ vx: n,
1109
+ vy: r,
1110
+ strength: i
1111
+ }) : this.#t.splat(e, t, n, r, i);
1112
+ }
1113
+ handleMove(e, t, n = 1) {
1114
+ this.#e ? this.#e.postMessage({
1115
+ type: "move",
1116
+ x: e,
1117
+ y: t,
1118
+ strength: n
1119
+ }) : this.#t.handleMove(e, t, n);
1120
+ }
1121
+ updateQuality(e) {
1122
+ this.#a = Math.max(.1, Math.min(1, e.dpr ?? this.#a)), this.#o = Math.max(.1, Math.min(1, e.sim ?? this.#o)), this.#e ? this.#e.postMessage({
1123
+ type: "updateQuality",
1124
+ quality: {
1125
+ dpr: this.#a,
1126
+ sim: this.#o
1127
+ }
1128
+ }) : this.#t.updateQuality(e);
1129
+ }
1130
+ updateConfig(e) {
1131
+ this.#e ? this.#e.postMessage({
1132
+ type: "updateConfig",
1133
+ config: e
1134
+ }) : this.#t.updateConfig(e);
1135
+ }
1136
+ resize(e, t) {
1137
+ let n = (typeof window < "u" && window.devicePixelRatio || 1) * this.#a;
1138
+ this.#e ? this.#e.postMessage({
1139
+ type: "resize",
1140
+ width: e,
1141
+ height: t,
1142
+ dpr: n
1143
+ }) : this.#t?.resize(e, t, n);
1144
+ }
1145
+ destroy() {
1146
+ if (this.#e) {
1147
+ let e = this.#e;
1148
+ this.#e = null, e.postMessage({ type: "destroy" }), setTimeout(() => e.terminate(), 50);
1149
+ } else this.#t?.destroy(), this.#t = null;
1150
+ }
1151
+ #l(e, t) {
1152
+ let n = {
1153
+ dpr: this.#a,
1154
+ sim: this.#o
1155
+ };
1156
+ this.#r && typeof navigator < "u" && navigator.gpu ? Q.create(e, t, n, !0, this.#i).then((e) => {
1157
+ if (this.#t = e, this.#s) e.setTextSource(this.#s), this.#s = null;
1158
+ else if (this.#c) {
1159
+ let { src: t, effect: n, size: r } = this.#c;
1160
+ e.setImageSource(t, n, r), this.#c = null;
1161
+ }
1162
+ }).catch((e) => {}) : this.#t = new Q(e, t, n, void 0, this.#i);
1163
+ }
1164
+ #u(e, t) {
1165
+ let n = (typeof window < "u" && window.devicePixelRatio || 1) * this.#a, r = Math.round(e.clientWidth * n), i = Math.round(e.clientHeight * n);
1166
+ e.width = r, e.height = i;
1167
+ let a;
1168
+ try {
1169
+ a = e.transferControlToOffscreen();
1170
+ } catch {
1171
+ this.#n = !1, this.#l(e, t);
1172
+ return;
1173
+ }
1174
+ let o = this.#e = new ye();
1175
+ o.onerror = (e) => (e.message, void 0), o.onmessage = (e) => {
1176
+ e.data.type === "error" && e.data.message;
1177
+ }, o.postMessage({
1178
+ type: "init",
1179
+ canvas: a,
1180
+ width: r,
1181
+ height: i,
1182
+ config: t,
1183
+ dpr: n,
1184
+ quality: {
1185
+ dpr: this.#a,
1186
+ sim: this.#o
1187
+ },
1188
+ useWebGPU: this.#r,
1189
+ enableAlpha: this.#i
1190
+ }, [a]);
1191
+ }
3209
1192
  };
3210
- function Ue(r, { workerEnabled: e = !0, webGPUEnabled: t = !0, alphaEnabled: n = !0, pixelRatio: i, simResolution: s, config: a = {} } = {}) {
3211
- const c = {
3212
- dpr: i,
3213
- sim: s
3214
- }, x = I(null), u = I({
3215
- workerEnabled: e,
3216
- quality: c,
3217
- config: a
3218
- }), v = I(Math.max(0.1, Math.min(1, i ?? W.dpr ?? 1))), l = I({
3219
- pixelRatio: i,
3220
- simResolution: s
3221
- });
3222
- return B(() => {
3223
- const o = r.current;
3224
- if (!o)
3225
- return;
3226
- const f = document.createElement("canvas");
3227
- f.id = `fluid_canvas_${Date.now()}`, f.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;", o.appendChild(f);
3228
- const { workerEnabled: m, quality: d, config: p } = u.current, h = (window.devicePixelRatio || 1) * v.current, g = o.getBoundingClientRect(), T = Math.round((g.width || o.clientWidth) * h) || 0, R = Math.round((g.height || o.clientHeight) * h) || 0;
3229
- T > 0 && (f.width = T, f.height = R);
3230
- const O = new ct(f, {
3231
- workerEnabled: m,
3232
- webGPUEnabled: t,
3233
- alphaEnabled: n,
3234
- quality: d,
3235
- config: p
3236
- });
3237
- x.current = O, T > 0 && R > 0 && O.resize(T, R);
3238
- const X = new ResizeObserver(($) => {
3239
- for (const q of $) {
3240
- const k = (window.devicePixelRatio || 1) * v.current, { inlineSize: H, blockSize: Y } = q.contentBoxSize[0];
3241
- O.resize(Math.round(H * k), Math.round(Y * k));
3242
- }
3243
- });
3244
- return X.observe(o), () => {
3245
- X.disconnect(), O.destroy(), f.remove(), x.current = null;
3246
- };
3247
- }, [t, n]), B(() => {
3248
- v.current = Math.max(0.1, Math.min(1, i ?? W.dpr ?? 1));
3249
- const o = l.current;
3250
- l.current = {
3251
- pixelRatio: i,
3252
- simResolution: s
3253
- };
3254
- const f = x.current, m = r.current;
3255
- if (!f || !m || o.pixelRatio === i && o.simResolution === s)
3256
- return;
3257
- f.updateQuality({
3258
- dpr: i,
3259
- sim: s
3260
- });
3261
- const d = (window.devicePixelRatio || 1) * v.current, p = m.clientWidth, h = m.clientHeight;
3262
- p > 0 && h > 0 && f.resize(Math.round(p * d), Math.round(h * d));
3263
- }, [
3264
- i,
3265
- s,
3266
- t,
3267
- n
3268
- ]), x;
3269
- }
3270
- var xt = be(function({ text: e, fontSize: t = V.fontSize, color: n = V.color, fontFamily: i = V.fontFamily, fontWeight: s = V.fontWeight, className: a, style: c, preset: x, algorithm: u, backgroundColor: v = V.backgroundColor, backgroundSrc: l, backgroundSize: o = V.backgroundSize, mouseEnabled: f = V.mouseEnabled, workerEnabled: m = V.workerEnabled, webGPUEnabled: d = !0, alphaEnabled: p = !0, pixelRatio: h = W.dpr, simResolution: g = W.sim, densityDissipation: T, velocityDissipation: R, pressureIterations: O, curl: X, splatRadius: $, splatForce: q, refraction: k, specularExp: H, shine: Y, waterColor: oe, glowColor: ae, warpStrength: j }, Q) {
3271
- const E = I(null), y = Object.fromEntries(Object.entries({
3272
- densityDissipation: T,
3273
- velocityDissipation: R,
3274
- pressureIterations: O,
3275
- curl: X,
3276
- splatRadius: $,
3277
- splatForce: q,
3278
- refraction: k,
3279
- specularExp: H,
3280
- shine: Y,
3281
- waterColor: oe,
3282
- glowColor: ae,
3283
- algorithm: u,
3284
- warpStrength: j
3285
- }).filter(([, b]) => b !== void 0)), w = Ue(E, {
3286
- workerEnabled: m,
3287
- webGPUEnabled: d,
3288
- alphaEnabled: p,
3289
- pixelRatio: h,
3290
- simResolution: g,
3291
- config: G(ee(y, x, ve))
3292
- });
3293
- return Te(Q, () => ({
3294
- reset() {
3295
- w.current?.setTextSource({
3296
- text: e,
3297
- fontSize: t,
3298
- color: n,
3299
- fontFamily: i,
3300
- fontWeight: s
3301
- });
3302
- },
3303
- move(b, S, U = 1) {
3304
- w.current?.handleMove(b, S, U);
3305
- },
3306
- splat(b, S, U, _, M = 1) {
3307
- w.current?.splat(b, S, U, _, M);
3308
- },
3309
- updateConfig(b) {
3310
- w.current?.updateConfig(G(b));
3311
- }
3312
- }), [
3313
- e,
3314
- t,
3315
- n,
3316
- i,
3317
- s
3318
- ]), B(() => {
3319
- w.current?.setTextSource({
3320
- text: e,
3321
- fontSize: t,
3322
- color: n,
3323
- fontFamily: i,
3324
- fontWeight: s
3325
- });
3326
- }, [
3327
- e,
3328
- t,
3329
- n,
3330
- i,
3331
- s,
3332
- d,
3333
- p
3334
- ]), B(() => {
3335
- w.current?.updateConfig(G(ee(y, x, ve)));
3336
- }, [
3337
- x,
3338
- JSON.stringify(y),
3339
- d,
3340
- p
3341
- ]), B(() => {
3342
- if (!l) {
3343
- w.current?.setBackground(null);
3344
- return;
3345
- }
3346
- let b = !1;
3347
- return ce(l).then((S) => {
3348
- if (b) {
3349
- S.close();
3350
- return;
3351
- }
3352
- w.current?.setBackground(S, o);
3353
- }).catch((S) => /* @__PURE__ */ z("backgroundSrc load failed:", S)), () => {
3354
- b = !0;
3355
- };
3356
- }, [
3357
- l,
3358
- o,
3359
- d,
3360
- p
3361
- ]), B(() => {
3362
- if (!f)
3363
- return;
3364
- const b = E.current;
3365
- if (!b)
3366
- return;
3367
- const S = (_) => {
3368
- const M = b.getBoundingClientRect();
3369
- w.current?.handleMove(_.clientX - M.left, _.clientY - M.top, 2);
3370
- }, U = (_) => {
3371
- _.preventDefault();
3372
- const M = b.getBoundingClientRect(), fe = _.touches[0];
3373
- w.current?.handleMove(fe.clientX - M.left, fe.clientY - M.top, 1);
3374
- };
3375
- return b.addEventListener("mousemove", S), b.addEventListener("touchmove", U, { passive: !1 }), () => {
3376
- b.removeEventListener("mousemove", S), b.removeEventListener("touchmove", U);
3377
- };
3378
- }, [f]), /* @__PURE__ */ ye("div", {
3379
- ref: E,
3380
- className: a,
3381
- style: {
3382
- position: "relative",
3383
- display: "block",
3384
- width: "100%",
3385
- height: "100%",
3386
- background: v,
3387
- ...c
3388
- }
3389
- });
3390
- }), ht = be(function({ src: e, effect: t = A.effect, imageSize: n = A.imageSize, className: i, style: s, preset: a, algorithm: c, backgroundColor: x = A.backgroundColor, backgroundSrc: u, backgroundSize: v = A.backgroundSize, mouseEnabled: l = A.mouseEnabled, workerEnabled: o = A.workerEnabled, webGPUEnabled: f = !0, alphaEnabled: m = !0, pixelRatio: d = W.dpr, simResolution: p = W.sim, densityDissipation: h, velocityDissipation: g, pressureIterations: T, curl: R, splatRadius: O, splatForce: X, refraction: $, specularExp: q, shine: k, waterColor: H, glowColor: Y, warpStrength: oe }, ae) {
3391
- const j = I(null), Q = Object.fromEntries(Object.entries({
3392
- densityDissipation: h,
3393
- velocityDissipation: g,
3394
- pressureIterations: T,
3395
- curl: R,
3396
- splatRadius: O,
3397
- splatForce: X,
3398
- refraction: $,
3399
- specularExp: q,
3400
- shine: k,
3401
- waterColor: H,
3402
- glowColor: Y,
3403
- algorithm: c,
3404
- warpStrength: oe
3405
- }).filter(([, y]) => y !== void 0)), E = Ue(j, {
3406
- workerEnabled: o,
3407
- webGPUEnabled: f,
3408
- alphaEnabled: m,
3409
- pixelRatio: d,
3410
- simResolution: p,
3411
- config: G(ee(Q, a))
3412
- });
3413
- return Te(ae, () => ({
3414
- reset() {
3415
- e && E.current?.setImageSource(e, t, n);
3416
- },
3417
- move(y, w, b = 1) {
3418
- E.current?.handleMove(y, w, b);
3419
- },
3420
- splat(y, w, b, S, U = 1) {
3421
- E.current?.splat(y, w, b, S, U);
3422
- },
3423
- updateConfig(y) {
3424
- E.current?.updateConfig(G(y));
3425
- }
3426
- }), [
3427
- e,
3428
- t,
3429
- n
3430
- ]), B(() => {
3431
- e && E.current?.setImageSource(e, t, n);
3432
- }, [
3433
- e,
3434
- t,
3435
- n,
3436
- f,
3437
- m
3438
- ]), B(() => {
3439
- E.current?.updateConfig(G(ee(Q, a)));
3440
- }, [
3441
- a,
3442
- JSON.stringify(Q),
3443
- f,
3444
- m
3445
- ]), B(() => {
3446
- if (!u) {
3447
- E.current?.setBackground(null);
3448
- return;
3449
- }
3450
- let y = !1;
3451
- return ce(u).then((w) => {
3452
- if (y) {
3453
- w.close();
3454
- return;
3455
- }
3456
- E.current?.setBackground(w, v);
3457
- }).catch((w) => /* @__PURE__ */ z("backgroundSrc load failed:", w)), () => {
3458
- y = !0;
3459
- };
3460
- }, [
3461
- u,
3462
- v,
3463
- f,
3464
- m
3465
- ]), B(() => {
3466
- if (!l)
3467
- return;
3468
- const y = j.current;
3469
- if (!y)
3470
- return;
3471
- const w = (S) => {
3472
- const U = y.getBoundingClientRect();
3473
- E.current?.handleMove(S.clientX - U.left, S.clientY - U.top, 2);
3474
- }, b = (S) => {
3475
- S.preventDefault();
3476
- const U = y.getBoundingClientRect(), _ = S.touches[0];
3477
- E.current?.handleMove(_.clientX - U.left, _.clientY - U.top, 1);
3478
- };
3479
- return y.addEventListener("mousemove", w), y.addEventListener("touchmove", b, { passive: !1 }), () => {
3480
- y.removeEventListener("mousemove", w), y.removeEventListener("touchmove", b);
3481
- };
3482
- }, [l]), /* @__PURE__ */ ye("div", {
3483
- ref: j,
3484
- className: i,
3485
- style: {
3486
- position: "relative",
3487
- display: "block",
3488
- width: "100%",
3489
- height: "100%",
3490
- background: x,
3491
- ...s
3492
- }
3493
- });
1193
+ //#endregion
1194
+ //#region src/react/useFluid.ts
1195
+ function $(e, { workerEnabled: n = !0, webGPUEnabled: i = !0, alphaEnabled: a = !0, pixelRatio: o, simResolution: s, config: c = {} } = {}) {
1196
+ let u = {
1197
+ dpr: o,
1198
+ sim: s
1199
+ }, d = r(null), f = r({
1200
+ workerEnabled: n,
1201
+ quality: u,
1202
+ config: c
1203
+ }), p = r(Math.max(.1, Math.min(1, o ?? l.dpr ?? 1))), m = r({
1204
+ pixelRatio: o,
1205
+ simResolution: s
1206
+ });
1207
+ return t(() => {
1208
+ let t = e.current;
1209
+ if (!t) return;
1210
+ let n = document.createElement("canvas");
1211
+ n.id = `fluid_canvas_${Date.now()}`, n.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;", t.appendChild(n);
1212
+ let { workerEnabled: r, quality: o, config: s } = f.current, c = (window.devicePixelRatio || 1) * p.current, l = t.getBoundingClientRect(), u = Math.round((l.width || t.clientWidth) * c) || 0, m = Math.round((l.height || t.clientHeight) * c) || 0;
1213
+ u > 0 && (n.width = u, n.height = m);
1214
+ let h = new xe(n, {
1215
+ workerEnabled: r,
1216
+ webGPUEnabled: i,
1217
+ alphaEnabled: a,
1218
+ quality: o,
1219
+ config: s
1220
+ });
1221
+ d.current = h, u > 0 && m > 0 && h.resize(u, m);
1222
+ let g = new ResizeObserver((e) => {
1223
+ for (let t of e) {
1224
+ let e = (window.devicePixelRatio || 1) * p.current, { inlineSize: n, blockSize: r } = t.contentBoxSize[0];
1225
+ h.resize(Math.round(n * e), Math.round(r * e));
1226
+ }
1227
+ });
1228
+ return g.observe(t), () => {
1229
+ g.disconnect(), h.destroy(), n.remove(), d.current = null;
1230
+ };
1231
+ }, [i, a]), t(() => {
1232
+ p.current = Math.max(.1, Math.min(1, o ?? l.dpr ?? 1));
1233
+ let t = m.current;
1234
+ m.current = {
1235
+ pixelRatio: o,
1236
+ simResolution: s
1237
+ };
1238
+ let n = d.current, r = e.current;
1239
+ if (!n || !r || t.pixelRatio === o && t.simResolution === s) return;
1240
+ n.updateQuality({
1241
+ dpr: o,
1242
+ sim: s
1243
+ });
1244
+ let i = (window.devicePixelRatio || 1) * p.current, a = r.clientWidth, c = r.clientHeight;
1245
+ a > 0 && c > 0 && n.resize(Math.round(a * i), Math.round(c * i));
1246
+ }, [
1247
+ o,
1248
+ s,
1249
+ i,
1250
+ a
1251
+ ]), d;
1252
+ }
1253
+ //#endregion
1254
+ //#region src/react/FluidText.tsx
1255
+ var Se = e(function({ text: e, fontSize: a = f.fontSize, color: s = f.color, fontFamily: u = f.fontFamily, fontWeight: d = f.fontWeight, className: p, style: m, preset: g, algorithm: _, backgroundColor: v = f.backgroundColor, backgroundSrc: y, backgroundSize: b = f.backgroundSize, mouseEnabled: x = f.mouseEnabled, workerEnabled: S = f.workerEnabled, webGPUEnabled: w = !0, alphaEnabled: T = !0, pixelRatio: E = l.dpr, simResolution: D = l.sim, densityDissipation: O, velocityDissipation: k, pressureIterations: A, curl: j, splatRadius: M, splatForce: N, refraction: P, specularExp: F, shine: I, waterColor: L, glowColor: R, warpStrength: z }, B) {
1256
+ let V = r(null), H = Object.fromEntries(Object.entries({
1257
+ densityDissipation: O,
1258
+ velocityDissipation: k,
1259
+ pressureIterations: A,
1260
+ curl: j,
1261
+ splatRadius: M,
1262
+ splatForce: N,
1263
+ refraction: P,
1264
+ specularExp: F,
1265
+ shine: I,
1266
+ waterColor: L,
1267
+ glowColor: R,
1268
+ algorithm: _,
1269
+ warpStrength: z
1270
+ }).filter(([, e]) => e !== void 0)), U = $(V, {
1271
+ workerEnabled: S,
1272
+ webGPUEnabled: w,
1273
+ alphaEnabled: T,
1274
+ pixelRatio: E,
1275
+ simResolution: D,
1276
+ config: o(h(H, g, c))
1277
+ });
1278
+ return n(B, () => ({
1279
+ reset() {
1280
+ U.current?.setTextSource({
1281
+ text: e,
1282
+ fontSize: a,
1283
+ color: s,
1284
+ fontFamily: u,
1285
+ fontWeight: d
1286
+ });
1287
+ },
1288
+ move(e, t, n = 1) {
1289
+ U.current?.handleMove(e, t, n);
1290
+ },
1291
+ splat(e, t, n, r, i = 1) {
1292
+ U.current?.splat(e, t, n, r, i);
1293
+ },
1294
+ updateConfig(e) {
1295
+ U.current?.updateConfig(o(e));
1296
+ }
1297
+ }), [
1298
+ e,
1299
+ a,
1300
+ s,
1301
+ u,
1302
+ d
1303
+ ]), t(() => {
1304
+ U.current?.setTextSource({
1305
+ text: e,
1306
+ fontSize: a,
1307
+ color: s,
1308
+ fontFamily: u,
1309
+ fontWeight: d
1310
+ });
1311
+ }, [
1312
+ e,
1313
+ a,
1314
+ s,
1315
+ u,
1316
+ d,
1317
+ w,
1318
+ T
1319
+ ]), t(() => {
1320
+ U.current?.updateConfig(o(h(H, g, c)));
1321
+ }, [
1322
+ g,
1323
+ JSON.stringify(H),
1324
+ w,
1325
+ T
1326
+ ]), t(() => {
1327
+ if (!y) {
1328
+ U.current?.setBackground(null);
1329
+ return;
1330
+ }
1331
+ let e = !1;
1332
+ return C(y).then((t) => {
1333
+ if (e) {
1334
+ t.close();
1335
+ return;
1336
+ }
1337
+ U.current?.setBackground(t, b);
1338
+ }).catch((e) => void 0), () => {
1339
+ e = !0;
1340
+ };
1341
+ }, [
1342
+ y,
1343
+ b,
1344
+ w,
1345
+ T
1346
+ ]), t(() => {
1347
+ if (!x) return;
1348
+ let e = V.current;
1349
+ if (!e) return;
1350
+ let t = (t) => {
1351
+ let n = e.getBoundingClientRect();
1352
+ U.current?.handleMove(t.clientX - n.left, t.clientY - n.top, 2);
1353
+ }, n = (t) => {
1354
+ t.preventDefault();
1355
+ let n = e.getBoundingClientRect(), r = t.touches[0];
1356
+ U.current?.handleMove(r.clientX - n.left, r.clientY - n.top, 1);
1357
+ };
1358
+ return e.addEventListener("mousemove", t), e.addEventListener("touchmove", n, { passive: !1 }), () => {
1359
+ e.removeEventListener("mousemove", t), e.removeEventListener("touchmove", n);
1360
+ };
1361
+ }, [x]), /* @__PURE__ */ i("div", {
1362
+ ref: V,
1363
+ className: p,
1364
+ style: {
1365
+ position: "relative",
1366
+ display: "block",
1367
+ width: "100%",
1368
+ height: "100%",
1369
+ background: v,
1370
+ ...m
1371
+ }
1372
+ });
1373
+ }), Ce = e(function({ src: e, effect: a = d.effect, imageSize: s = d.imageSize, className: c, style: u, preset: f, algorithm: p, backgroundColor: m = d.backgroundColor, backgroundSrc: g, backgroundSize: _ = d.backgroundSize, mouseEnabled: v = d.mouseEnabled, workerEnabled: y = d.workerEnabled, webGPUEnabled: b = !0, alphaEnabled: x = !0, pixelRatio: S = l.dpr, simResolution: w = l.sim, densityDissipation: T, velocityDissipation: E, pressureIterations: D, curl: O, splatRadius: k, splatForce: A, refraction: j, specularExp: M, shine: N, waterColor: P, glowColor: F, warpStrength: I }, L) {
1374
+ let R = r(null), z = Object.fromEntries(Object.entries({
1375
+ densityDissipation: T,
1376
+ velocityDissipation: E,
1377
+ pressureIterations: D,
1378
+ curl: O,
1379
+ splatRadius: k,
1380
+ splatForce: A,
1381
+ refraction: j,
1382
+ specularExp: M,
1383
+ shine: N,
1384
+ waterColor: P,
1385
+ glowColor: F,
1386
+ algorithm: p,
1387
+ warpStrength: I
1388
+ }).filter(([, e]) => e !== void 0)), B = $(R, {
1389
+ workerEnabled: y,
1390
+ webGPUEnabled: b,
1391
+ alphaEnabled: x,
1392
+ pixelRatio: S,
1393
+ simResolution: w,
1394
+ config: o(h(z, f))
1395
+ });
1396
+ return n(L, () => ({
1397
+ reset() {
1398
+ e && B.current?.setImageSource(e, a, s);
1399
+ },
1400
+ move(e, t, n = 1) {
1401
+ B.current?.handleMove(e, t, n);
1402
+ },
1403
+ splat(e, t, n, r, i = 1) {
1404
+ B.current?.splat(e, t, n, r, i);
1405
+ },
1406
+ updateConfig(e) {
1407
+ B.current?.updateConfig(o(e));
1408
+ }
1409
+ }), [
1410
+ e,
1411
+ a,
1412
+ s
1413
+ ]), t(() => {
1414
+ e && B.current?.setImageSource(e, a, s);
1415
+ }, [
1416
+ e,
1417
+ a,
1418
+ s,
1419
+ b,
1420
+ x
1421
+ ]), t(() => {
1422
+ B.current?.updateConfig(o(h(z, f)));
1423
+ }, [
1424
+ f,
1425
+ JSON.stringify(z),
1426
+ b,
1427
+ x
1428
+ ]), t(() => {
1429
+ if (!g) {
1430
+ B.current?.setBackground(null);
1431
+ return;
1432
+ }
1433
+ let e = !1;
1434
+ return C(g).then((t) => {
1435
+ if (e) {
1436
+ t.close();
1437
+ return;
1438
+ }
1439
+ B.current?.setBackground(t, _);
1440
+ }).catch((e) => void 0), () => {
1441
+ e = !0;
1442
+ };
1443
+ }, [
1444
+ g,
1445
+ _,
1446
+ b,
1447
+ x
1448
+ ]), t(() => {
1449
+ if (!v) return;
1450
+ let e = R.current;
1451
+ if (!e) return;
1452
+ let t = (t) => {
1453
+ let n = e.getBoundingClientRect();
1454
+ B.current?.handleMove(t.clientX - n.left, t.clientY - n.top, 2);
1455
+ }, n = (t) => {
1456
+ t.preventDefault();
1457
+ let n = e.getBoundingClientRect(), r = t.touches[0];
1458
+ B.current?.handleMove(r.clientX - n.left, r.clientY - n.top, 1);
1459
+ };
1460
+ return e.addEventListener("mousemove", t), e.addEventListener("touchmove", n, { passive: !1 }), () => {
1461
+ e.removeEventListener("mousemove", t), e.removeEventListener("touchmove", n);
1462
+ };
1463
+ }, [v]), /* @__PURE__ */ i("div", {
1464
+ ref: R,
1465
+ className: c,
1466
+ style: {
1467
+ position: "relative",
1468
+ display: "block",
1469
+ width: "100%",
1470
+ height: "100%",
1471
+ background: m,
1472
+ ...u
1473
+ }
1474
+ });
3494
1475
  });
3495
- export {
3496
- we as DEFAULT_CONFIG,
3497
- ve as DEFAULT_CONFIG_TEXT,
3498
- A as DEFAULT_PROPS_IMAGE,
3499
- Se as DEFAULT_PROPS_SHARED,
3500
- V as DEFAULT_PROPS_TEXT,
3501
- ct as FluidController,
3502
- ht as FluidImage,
3503
- pe as FluidSimulation,
3504
- xt as FluidText,
3505
- _e as PRESETS,
3506
- De as PROP_RANGES,
3507
- ce as loadImageBitmap,
3508
- ee as mergeConfig,
3509
- G as normalizeConfig,
3510
- te as parseColor,
3511
- Ue as useFluid
3512
- };
1476
+ //#endregion
1477
+ export { s as DEFAULT_CONFIG, c as DEFAULT_CONFIG_TEXT, d as DEFAULT_PROPS_IMAGE, u as DEFAULT_PROPS_SHARED, f as DEFAULT_PROPS_TEXT, xe as FluidController, Ce as FluidImage, Q as FluidSimulation, Se as FluidText, p as PRESETS, a as PROP_RANGES, C as loadImageBitmap, h as mergeConfig, o as normalizeConfig, m as parseColor, $ as useFluid };