react-smokey-fluid-cursor 1.0.3 → 2.0.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.mjs CHANGED
@@ -1,293 +1,195 @@
1
1
  "use client";
2
- var Me=Object.defineProperty;var ie=Object.getOwnPropertySymbols;var Oe=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable;var oe=(f,c,v)=>c in f?Me(f,c,{enumerable:!0,configurable:!0,writable:!0,value:v}):f[c]=v,N=(f,c)=>{for(var v in c||(c={}))Oe.call(c,v)&&oe(f,v,c[v]);if(ie)for(var v of ie(c))Ye.call(c,v)&&oe(f,v,c[v]);return f};import ae from"react";var ne=f=>{let c=document.getElementById(f.id);if(!c)return;let v=document.createElement("style");v.textContent=`
3
- #${f.id} {
4
- position: fixed;
5
- top: 0;
6
- left: 0;
7
- width: 100%;
8
- height: 100%;
9
- pointer-events: none;
10
- z-index: -9999;
11
- }
12
- `,document.head.appendChild(v),j();class ue{constructor(){this.id=-1;this.texcoordX=0;this.texcoordY=0;this.prevTexcoordX=0;this.prevTexcoordY=0;this.deltaX=0;this.deltaY=0;this.down=!1;this.moved=!1;this.color=[30,0,300]}}let S=[];S.push(new ue);let{gl:t,ext:T}=ce(c);T.supportLinearFiltering||(f.dyeResolution=512,f.shading=!1);function ce(e){let r={alpha:!0,depth:!1,stencil:!1,antialias:!1,preserveDrawingBuffer:!1},i=e.getContext("webgl2",r),o=!!i;if(o||(i=e.getContext("webgl",r)||e.getContext("experimental-webgl",r)),!i)throw new Error("WebGL not supported");let n=null,u,a;if(o){let l=i;l.getExtension("EXT_color_buffer_float"),u=!!l.getExtension("OES_texture_float_linear"),a=l.HALF_FLOAT}else{let l=i;if(n=l.getExtension("OES_texture_half_float"),u=!!l.getExtension("OES_texture_half_float_linear"),!n)throw new Error("OES_texture_half_float not supported on WebGL1");a=n.HALF_FLOAT_OES}i.clearColor(0,0,0,1);let m=null,d=null,y=null;if(o){let l=i;m=F(l,l.RGBA16F,l.RGBA,a),d=F(l,l.RG16F,l.RG,a),y=F(l,l.R16F,l.RED,a)}else{let l=i;m=F(l,l.RGBA,l.RGBA,a),d=F(l,l.RGBA,l.RGBA,a),y=F(l,l.RGBA,l.RGBA,a)}return{gl:i,ext:{formatRGBA:m,formatRG:d,formatR:y,halfFloatTexType:a,supportLinearFiltering:u,isWebGL2:o}}}function F(e,r,i,o){if(!se(e,r,i,o)){if(e.RGBA16F!==void 0){let n=e;switch(r){case n.R16F:return F(n,n.RG16F,n.RG,o);case n.RG16F:return F(n,n.RGBA16F,n.RGBA,o);default:return null}}return null}return{internalFormat:r,format:i}}function se(e,r,i,o){let n=e.createTexture();if(!n)return!1;e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),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,r,4,4,0,i,o,null);let u=e.createFramebuffer();if(!u)return!1;e.bindFramebuffer(e.FRAMEBUFFER,u),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0);let a=e.checkFramebufferStatus(e.FRAMEBUFFER);return e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(u),e.deleteTexture(n),a===e.FRAMEBUFFER_COMPLETE}class le{constructor(r,i){this.vertexShader=r,this.fragmentShaderSource=i,this.programs={},this.activeProgram=null,this.uniforms={}}setKeywords(r){let i=0;for(let n=0;n<r.length;n++)i+=ze(r[n]);let o=this.programs[i];if(!o){let n=x(t,t.FRAGMENT_SHADER,V(this.fragmentShaderSource,r));o=I(t,this.vertexShader,n),this.programs[i]=o}o!==this.activeProgram&&(this.uniforms=W(t,o),this.activeProgram=o)}bind(){this.activeProgram&&t.useProgram(this.activeProgram)}}class E{constructor(r,i){this.program=I(t,r,i),this.uniforms=W(t,this.program)}bind(){this.program&&t.useProgram(this.program)}}function I(e,r,i){let o=e.createProgram();return e.attachShader(o,r),e.attachShader(o,i),e.bindAttribLocation(o,0,"aPosition"),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)||console.trace(e.getProgramInfoLog(o)),o}function W(e,r){let i={},o=e.getProgramParameter(r,e.ACTIVE_UNIFORMS);for(let n=0;n<o;n++){let u=e.getActiveUniform(r,n);if(!u)continue;let a=u.name,m=e.getUniformLocation(r,a);m&&(i[a]=m)}return i}function x(e,r,i){let o=e.createShader(r);return e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||console.trace(e.getShaderInfoLog(o)),o}function V(e,r){if(!r||r.length===0)return e;let i="";return r.forEach(o=>{i+="#define "+o+`
13
- `}),i+e}let b=x(t,t.VERTEX_SHADER,`
14
- precision highp float;
15
-
16
- attribute vec2 aPosition;
17
- varying vec2 vUv;
18
- varying vec2 vL;
19
- varying vec2 vR;
20
- varying vec2 vT;
21
- varying vec2 vB;
22
- uniform vec2 texelSize;
23
-
24
- void main () {
25
- vUv = aPosition * 0.5 + 0.5;
26
- vL = vUv - vec2(texelSize.x, 0.0);
27
- vR = vUv + vec2(texelSize.x, 0.0);
28
- vT = vUv + vec2(0.0, texelSize.y);
29
- vB = vUv - vec2(0.0, texelSize.y);
30
- gl_Position = vec4(aPosition, 0.0, 1.0);
31
- }
32
- `),fe=x(t,t.FRAGMENT_SHADER,`
33
- precision mediump float;
34
- precision mediump sampler2D;
35
-
36
- varying highp vec2 vUv;
37
- uniform sampler2D uTexture;
38
-
39
- void main () {
40
- gl_FragColor = texture2D(uTexture, vUv);
41
- }
42
- `),me=x(t,t.FRAGMENT_SHADER,`
43
- precision mediump float;
44
- precision mediump sampler2D;
45
-
46
- varying highp vec2 vUv;
47
- uniform sampler2D uTexture;
48
- uniform float value;
49
-
50
- void main () {
51
- gl_FragColor = value * texture2D(uTexture, vUv);
52
- }
53
- `),de=`
54
- precision highp float;
55
- precision highp sampler2D;
56
-
57
- varying vec2 vUv;
58
- varying vec2 vL;
59
- varying vec2 vR;
60
- varying vec2 vT;
61
- varying vec2 vB;
62
- uniform sampler2D uTexture;
63
- uniform vec2 texelSize;
64
-
65
- void main () {
66
- vec3 c = texture2D(uTexture, vUv).rgb;
67
-
68
- #ifdef shading
69
- // Calculate normal from neighboring pixels for lighting
70
- vec3 lc = texture2D(uTexture, vL).rgb;
71
- vec3 rc = texture2D(uTexture, vR).rgb;
72
- vec3 tc = texture2D(uTexture, vT).rgb;
73
- vec3 bc = texture2D(uTexture, vB).rgb;
74
-
75
- float dx = length(rc) - length(lc);
76
- float dy = length(tc) - length(bc);
77
-
78
- vec3 n = normalize(vec3(dx, dy, length(texelSize)));
79
- vec3 l = vec3(0.0, 0.0, 1.0);
80
-
81
- // Apply diffuse lighting
82
- float diffuse = clamp(dot(n, l) + 0.7, 0.7, 1.0);
83
- c *= diffuse;
84
- #endif
85
-
86
- // Use brightest channel for alpha
87
- float a = max(c.r, max(c.g, c.b));
88
- gl_FragColor = vec4(c, a);
89
- }
90
- `,ve=x(t,t.FRAGMENT_SHADER,`
91
- precision highp float;
92
- precision highp sampler2D;
93
-
94
- varying vec2 vUv;
95
- uniform sampler2D uTarget;
96
- uniform float aspectRatio;
97
- uniform vec3 color;
98
- uniform vec2 point;
99
- uniform float radius;
100
-
101
- void main () {
102
- // Calculate Gaussian splat
103
- vec2 p = vUv - point.xy;
104
- p.x *= aspectRatio;
105
- vec3 splat = exp(-dot(p, p) / radius) * color;
106
- vec3 base = texture2D(uTarget, vUv).xyz;
107
- gl_FragColor = vec4(base + splat, 1.0);
108
- }
109
- `),he=x(t,t.FRAGMENT_SHADER,V(`
110
- precision highp float;
111
- precision highp sampler2D;
112
-
113
- varying vec2 vUv;
114
- uniform sampler2D uVelocity;
115
- uniform sampler2D uSource;
116
- uniform vec2 texelSize;
117
- uniform vec2 dyeTexelSize;
118
- uniform float dt;
119
- uniform float dissipation;
120
-
121
- // Manual bilinear filtering for WebGL1 without linear filtering support
122
- vec4 bilerp (sampler2D sam, vec2 uv, vec2 tsize) {
123
- vec2 st = uv / tsize - 0.5;
124
-
125
- vec2 iuv = floor(st);
126
- vec2 fuv = fract(st);
127
-
128
- vec4 a = texture2D(sam, (iuv + vec2(0.5, 0.5)) * tsize);
129
- vec4 b = texture2D(sam, (iuv + vec2(1.5, 0.5)) * tsize);
130
- vec4 c = texture2D(sam, (iuv + vec2(0.5, 1.5)) * tsize);
131
- vec4 d = texture2D(sam, (iuv + vec2(1.5, 1.5)) * tsize);
132
-
133
- return mix(mix(a, b, fuv.x), mix(c, d, fuv.x), fuv.y);
134
- }
135
-
136
- void main () {
137
- #ifdef MANUAL_FILTERING
138
- // Manual filtering for devices without linear filtering
139
- vec2 coord = vUv - dt * bilerp(uVelocity, vUv, texelSize).xy * texelSize;
140
- vec4 result = bilerp(uSource, coord, dyeTexelSize);
141
- #else
142
- // Standard texture lookup with linear filtering
143
- vec2 coord = vUv - dt * texture2D(uVelocity, vUv).xy * texelSize;
144
- vec4 result = texture2D(uSource, coord);
145
- #endif
146
- // Apply dissipation (fade over time)
147
- float decay = 1.0 + dissipation * dt;
148
- gl_FragColor = result / decay;
149
- }
150
- `,T.supportLinearFiltering?null:["MANUAL_FILTERING"])),pe=x(t,t.FRAGMENT_SHADER,`
151
- precision mediump float;
152
- precision mediump sampler2D;
153
-
154
- varying highp vec2 vUv;
155
- varying highp vec2 vL;
156
- varying highp vec2 vR;
157
- varying highp vec2 vT;
158
- varying highp vec2 vB;
159
- uniform sampler2D uVelocity;
160
-
161
- void main () {
162
- // Sample neighboring velocities
163
- float L = texture2D(uVelocity, vL).x;
164
- float R = texture2D(uVelocity, vR).x;
165
- float T = texture2D(uVelocity, vT).y;
166
- float B = texture2D(uVelocity, vB).y;
167
-
168
- vec2 C = texture2D(uVelocity, vUv).xy;
169
-
170
- // Boundary conditions
171
- if (vL.x < 0.0) { L = -C.x; }
172
- if (vR.x > 1.0) { R = -C.x; }
173
- if (vT.y > 1.0) { T = -C.y; }
174
- if (vB.y < 0.0) { B = -C.y; }
175
-
176
- // Calculate divergence
177
- float div = 0.5 * (R - L + T - B);
178
- gl_FragColor = vec4(div, 0.0, 0.0, 1.0);
179
- }
180
- `),xe=x(t,t.FRAGMENT_SHADER,`
181
- precision mediump float;
182
- precision mediump sampler2D;
183
-
184
- varying highp vec2 vUv;
185
- varying highp vec2 vL;
186
- varying highp vec2 vR;
187
- varying highp vec2 vT;
188
- varying highp vec2 vB;
189
- uniform sampler2D uVelocity;
190
-
191
- void main () {
192
- // Sample velocity components for curl calculation
193
- float L = texture2D(uVelocity, vL).y;
194
- float R = texture2D(uVelocity, vR).y;
195
- float T = texture2D(uVelocity, vT).x;
196
- float B = texture2D(uVelocity, vB).x;
197
- float vorticity = R - L - T + B;
198
- gl_FragColor = vec4(0.5 * vorticity, 0.0, 0.0, 1.0);
199
- }
200
- `),ge=x(t,t.FRAGMENT_SHADER,`
201
- precision highp float;
202
- precision highp sampler2D;
203
-
204
- varying vec2 vUv;
205
- varying vec2 vL;
206
- varying vec2 vR;
207
- varying vec2 vT;
208
- varying vec2 vB;
209
- uniform sampler2D uVelocity;
210
- uniform sampler2D uCurl;
211
- uniform float curl;
212
- uniform float dt;
213
-
214
- void main () {
215
- // Sample curl from neighbors
216
- float L = texture2D(uCurl, vL).x;
217
- float R = texture2D(uCurl, vR).x;
218
- float T = texture2D(uCurl, vT).x;
219
- float B = texture2D(uCurl, vB).x;
220
- float C = texture2D(uCurl, vUv).x;
221
-
222
- // Calculate vorticity force
223
- vec2 force = 0.5 * vec2(abs(T) - abs(B), abs(R) - abs(L));
224
- force /= length(force) + 0.0001; // Normalize
225
- force *= curl * C; // Scale by curl strength
226
- force.y *= -1.0; // Adjust coordinate system
227
-
228
- // Apply force to velocity
229
- vec2 velocity = texture2D(uVelocity, vUv).xy;
230
- velocity += force * dt;
231
- velocity = min(max(velocity, -1000.0), 1000.0); // Clamp to prevent explosion
232
- gl_FragColor = vec4(velocity, 0.0, 1.0);
233
- }
234
- `),be=x(t,t.FRAGMENT_SHADER,`
235
- precision mediump float;
236
- precision mediump sampler2D;
237
-
238
- varying highp vec2 vUv;
239
- varying highp vec2 vL;
240
- varying highp vec2 vR;
241
- varying highp vec2 vT;
242
- varying highp vec2 vB;
243
- uniform sampler2D uPressure;
244
- uniform sampler2D uDivergence;
245
-
246
- void main () {
247
- // Sample pressure from neighbors
248
- float L = texture2D(uPressure, vL).x;
249
- float R = texture2D(uPressure, vR).x;
250
- float T = texture2D(uPressure, vT).x;
251
- float B = texture2D(uPressure, vB).x;
252
- float C = texture2D(uPressure, vUv).x;
253
- float divergence = texture2D(uDivergence, vUv).x;
254
-
255
- // Jacobi iteration for pressure solve
256
- float pressure = (L + R + B + T - divergence) * 0.25;
257
- gl_FragColor = vec4(pressure, 0.0, 0.0, 1.0);
258
- }
259
- `),Re=x(t,t.FRAGMENT_SHADER,`
260
- precision mediump float;
261
- precision mediump sampler2D;
262
-
263
- varying highp vec2 vUv;
264
- varying highp vec2 vL;
265
- varying highp vec2 vR;
266
- varying highp vec2 vT;
267
- varying highp vec2 vB;
268
- uniform sampler2D uPressure;
269
- uniform sampler2D uVelocity;
270
-
271
- void main () {
272
- // Calculate pressure gradient
273
- float L = texture2D(uPressure, vL).x;
274
- float R = texture2D(uPressure, vR).x;
275
- float T = texture2D(uPressure, vT).x;
276
- float B = texture2D(uPressure, vB).x;
277
- vec2 velocity = texture2D(uVelocity, vUv).xy;
278
-
279
- // Subtract gradient to make velocity divergence-free
280
- velocity.xy -= vec2(R - L, T - B);
281
- gl_FragColor = vec4(velocity, 0.0, 1.0);
282
- }
283
- `),p=(()=>{let e=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,e),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),t.STATIC_DRAW);let r=t.createBuffer();return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,r),t.bufferData(t.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,0,2,3]),t.STATIC_DRAW),t.vertexAttribPointer(0,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(0),(i,o=!1)=>{i==null?(t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight),t.bindFramebuffer(t.FRAMEBUFFER,null)):(t.viewport(0,0,i.width,i.height),t.bindFramebuffer(t.FRAMEBUFFER,i.fbo)),o&&(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT)),t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)}})(),h,s,P,G,D,H=new E(b,fe),X=new E(b,me),L=new E(b,ve),g=new E(b,he),z=new E(b,pe),M=new E(b,xe),_=new E(b,ge),B=new E(b,be),w=new E(b,Re),U=new le(b,de);function k(){let e=re(f.simResolution),r=re(f.dyeResolution),i=T.halfFloatTexType,o=T.formatRGBA,n=T.formatRG,u=T.formatR,a=T.supportLinearFiltering?t.LINEAR:t.NEAREST;t.disable(t.BLEND),h==null?h=O(r.width,r.height,o.internalFormat,o.format,i,a):h=K(h,r.width,r.height,o.internalFormat,o.format,i,a),s==null?s=O(e.width,e.height,n.internalFormat,n.format,i,a):s=K(s,e.width,e.height,n.internalFormat,n.format,i,a),P=A(e.width,e.height,u.internalFormat,u.format,i,t.NEAREST),G=A(e.width,e.height,u.internalFormat,u.format,i,t.NEAREST),D=O(e.width,e.height,u.internalFormat,u.format,i,t.NEAREST)}function A(e,r,i,o,n,u){t.activeTexture(t.TEXTURE0);let a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,u),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,u),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texImage2D(t.TEXTURE_2D,0,i,e,r,0,o,n,null);let m=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,m),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,a,0),t.viewport(0,0,e,r),t.clear(t.COLOR_BUFFER_BIT);let d=1/e,y=1/r;return{texture:a,fbo:m,width:e,height:r,texelSizeX:d,texelSizeY:y,attach(l){return t.activeTexture(t.TEXTURE0+l),t.bindTexture(t.TEXTURE_2D,a),l}}}function O(e,r,i,o,n,u){let a=A(e,r,i,o,n,u),m=A(e,r,i,o,n,u);return{width:e,height:r,texelSizeX:a.texelSizeX,texelSizeY:a.texelSizeY,get read(){return a},set read(d){a=d},get write(){return m},set write(d){m=d},swap(){let d=a;a=m,m=d}}}function Te(e,r,i,o,n,u,a){let m=A(r,i,o,n,u,a);return H.bind(),t.uniform1i(H.uniforms.uTexture,e.attach(0)),p(m),m}function K(e,r,i,o,n,u,a){return e.width===r&&e.height===i||(e.read=Te(e.read,r,i,o,n,u,a),e.write=A(r,i,o,n,u,a),e.width=r,e.height=i,e.texelSizeX=1/r,e.texelSizeY=1/i),e}function Ee(){let e=[];f.shading&&e.push("shading"),U.setKeywords(e)}Ee(),k();let q=Date.now(),C=0;function $(){let e=ye();j()&&k(),Se(e),Fe(),De(e),Le(null),requestAnimationFrame($)}function ye(){let e=Date.now(),r=(e-q)/1e3;return r=Math.min(r,.016666),q=e,r}function j(){let e=R(c.clientWidth),r=R(c.clientHeight);return c.width!==e||c.height!==r?(c.width=e,c.height=r,!0):!1}function Se(e){C+=e*f.colorUpdateSpeed,C>=1&&(C=Xe(C,0,1),S.forEach(r=>{r.color=te(Y())}))}function Fe(){S.forEach(e=>{e.moved&&(e.moved=!1,Ae(e))})}function De(e){t.disable(t.BLEND),M.bind(),t.uniform2f(M.uniforms.texelSize,s.texelSizeX,s.texelSizeY),t.uniform1i(M.uniforms.uVelocity,s.read.attach(0)),p(G),_.bind(),t.uniform2f(_.uniforms.texelSize,s.texelSizeX,s.texelSizeY),t.uniform1i(_.uniforms.uVelocity,s.read.attach(0)),t.uniform1i(_.uniforms.uCurl,G.attach(1)),t.uniform1f(_.uniforms.curl,f.curl),t.uniform1f(_.uniforms.dt,e),p(s.write),s.swap(),z.bind(),t.uniform2f(z.uniforms.texelSize,s.texelSizeX,s.texelSizeY),t.uniform1i(z.uniforms.uVelocity,s.read.attach(0)),p(P),X.bind(),t.uniform1i(X.uniforms.uTexture,D.read.attach(0)),t.uniform1f(X.uniforms.value,f.pressure),p(D.write),D.swap(),B.bind(),t.uniform2f(B.uniforms.texelSize,s.texelSizeX,s.texelSizeY),t.uniform1i(B.uniforms.uDivergence,P.attach(0));for(let i=0;i<f.pressureIteration;i++)t.uniform1i(B.uniforms.uPressure,D.read.attach(1)),p(D.write),D.swap();w.bind(),t.uniform2f(w.uniforms.texelSize,s.texelSizeX,s.texelSizeY),t.uniform1i(w.uniforms.uPressure,D.read.attach(0)),t.uniform1i(w.uniforms.uVelocity,s.read.attach(1)),p(s.write),s.swap(),g.bind(),t.uniform2f(g.uniforms.texelSize,s.texelSizeX,s.texelSizeY),T.supportLinearFiltering||t.uniform2f(g.uniforms.dyeTexelSize,s.texelSizeX,s.texelSizeY);let r=s.read.attach(0);t.uniform1i(g.uniforms.uVelocity,r),t.uniform1i(g.uniforms.uSource,r),t.uniform1f(g.uniforms.dt,e),t.uniform1f(g.uniforms.dissipation,f.velocityDissipation),p(s.write),s.swap(),T.supportLinearFiltering||t.uniform2f(g.uniforms.dyeTexelSize,h.texelSizeX,h.texelSizeY),t.uniform1i(g.uniforms.uVelocity,s.read.attach(0)),t.uniform1i(g.uniforms.uSource,h.read.attach(1)),t.uniform1f(g.uniforms.dissipation,f.densityDissipation),p(h.write),h.swap()}function Le(e){t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.BLEND),_e(e)}function _e(e){let r=e==null?t.drawingBufferWidth:e.width,i=e==null?t.drawingBufferHeight:e.height;U.bind(),f.shading&&t.uniform2f(U.uniforms.texelSize,1/r,1/i),t.uniform1i(U.uniforms.uTexture,h.read.attach(0)),p(e)}function Ae(e){let r=e.deltaX*f.splatForce,i=e.deltaY*f.splatForce,o=Pe(e.color);Q(e.texcoordX,e.texcoordY,r,i,o)}function J(e){let r=Y();r.r*=10,r.g*=10,r.b*=10;let i=10*(Math.random()-.5),o=30*(Math.random()-.5);Q(e.texcoordX,e.texcoordY,i,o,r)}function Q(e,r,i,o,n){L.bind(),t.uniform1i(L.uniforms.uTarget,s.read.attach(0)),t.uniform1f(L.uniforms.aspectRatio,c.width/c.height),t.uniform2f(L.uniforms.point,e,r),t.uniform3f(L.uniforms.color,i,o,0),t.uniform1f(L.uniforms.radius,Be(f.splatRadius/100)),p(s.write),s.swap(),t.uniform1i(L.uniforms.uTarget,h.read.attach(0)),t.uniform3f(L.uniforms.color,n.r,n.g,n.b),p(h.write),h.swap()}function Be(e){let r=c.width/c.height;return r>1&&(e*=r),e}window.addEventListener("mousedown",e=>{let r=S[0],i=c.getBoundingClientRect(),o=R(e.clientX-i.left),n=R(e.clientY-i.top);Z(r,-1,o,n),J(r)}),window.addEventListener("mousemove",e=>{let r=S[0],i=c.getBoundingClientRect(),o=R(e.clientX-i.left),n=R(e.clientY-i.top),u=r.color;ee(r,o,n,u)}),window.addEventListener("touchstart",e=>{let r=e.targetTouches,i=c.getBoundingClientRect(),o=S[0];for(let n=0;n<r.length;n++){let u=R(r[n].clientX-i.left),a=R(r[n].clientY-i.top);Z(o,r[n].identifier,u,a),J(o)}}),window.addEventListener("touchmove",e=>{e.preventDefault();let r=e.targetTouches,i=c.getBoundingClientRect(),o=S[0];for(let n=0;n<r.length;n++){let u=R(r[n].clientX-i.left),a=R(r[n].clientY-i.top);ee(o,u,a,o.color)}},{passive:!1}),window.addEventListener("touchend",e=>{let r=e.changedTouches,i=S[0];for(let o=0;o<r.length;o++)we(i)});function Z(e,r,i,o){e.id=r,e.down=!0,e.moved=!1,e.texcoordX=i/c.width,e.texcoordY=1-o/c.height,e.prevTexcoordX=e.texcoordX,e.prevTexcoordY=e.texcoordY,e.deltaX=0,e.deltaY=0,e.color=te(Y())}function ee(e,r,i,o){e.prevTexcoordX=e.texcoordX,e.prevTexcoordY=e.texcoordY,e.texcoordX=r/c.width,e.texcoordY=1-i/c.height,e.deltaX=Ue(e.texcoordX-e.prevTexcoordX),e.deltaY=Ce(e.texcoordY-e.prevTexcoordY),e.moved=Math.abs(e.deltaX)>0||Math.abs(e.deltaY)>0,e.color=o}function we(e){e.down=!1}function Ue(e){let r=c.width/c.height;return r<1&&(e*=r),e}function Ce(e){let r=c.width/c.height;return r>1&&(e/=r),e}function Y(){let e=Ge(Math.random(),1,1);return e.r*=.15,e.g*=.15,e.b*=.15,e}function te(e){return[e.r,e.g,e.b]}function Pe(e){return{r:e[0],g:e[1],b:e[2]}}function Ge(e,r,i){let o=0,n=0,u=0,a=Math.floor(e*6),m=e*6-a,d=i*(1-r),y=i*(1-m*r),l=i*(1-(1-m)*r);switch(a%6){case 0:o=i,n=l,u=d;break;case 1:o=y,n=i,u=d;break;case 2:o=d,n=i,u=l;break;case 3:o=d,n=y,u=i;break;case 4:o=l,n=d,u=i;break;case 5:o=i,n=d,u=y;break}return{r:o,g:n,b:u}}function Xe(e,r,i){let o=i-r;return o===0?r:(e-r)%o+r}function re(e){let r=t.drawingBufferWidth/t.drawingBufferHeight;r<1&&(r=1/r);let i=Math.round(e),o=Math.round(e*r);return t.drawingBufferWidth>t.drawingBufferHeight?{width:o,height:i}:{width:i,height:o}}function R(e){let r=window.devicePixelRatio||1;return Math.floor(e*r)}function ze(e){if(e.length===0)return 0;let r=0;for(let i=0;i<e.length;i++)r=(r<<5)-r+e.charCodeAt(i),r|=0;return r}$()};var We={simResolution:128,dyeResolution:1440,captureResolution:512,densityDissipation:3.5,velocityDissipation:2,pressure:.1,pressureIteration:20,curl:10,splatRadius:.5,splatForce:6e3,shading:!0,colorUpdateSpeed:10,paused:!1,backColor:{r:0,g:0,b:0},transparent:!0,id:"smokey-fluid-canvas"},$e=({config:f})=>{let c=N(N({},We),f);return ae.useEffect(()=>{if(document){let v=document.createElement("style");v.textContent=`
284
- #${c.id} {
285
- position: fixed;
286
- top: 0;
287
- left: 0;
288
- width: 100%;
289
- height: 100%;
290
- pointer-events: none;
291
- z-index: -9999;
292
- }
293
- `,document.head.appendChild(v),ne(c)}},[]),ae.createElement("canvas",{id:c.id})};export{$e as SmokeyFluidCursor};
2
+ import A from"react";var it={simResolution:128,dyeResolution:1440,captureResolution:512,densityDissipation:3.5,velocityDissipation:2,pressure:.1,pressureIteration:20,curl:10,splatRadius:.5,splatForce:6e3,shading:!0,colorUpdateSpeed:10,paused:!1,backColor:{r:0,g:0,b:0},transparent:!0,id:"smokey-fluid-canvas",position:"fixed",zIndex:-9999,pointerEvents:!1,maxDpr:2,pauseOnHidden:!0,respectReducedMotion:!0,palette:null,colorIntensity:.15},Be=l=>{var u;return l?typeof l!="string"?l:(u=document.querySelector(l))!=null?u:document.getElementById(l):null},ut=l=>{let u=l.trim().replace(/^#/,"");return u.length===3&&(u=u[0]+u[0]+u[1]+u[1]+u[2]+u[2]),/^[0-9a-f]{6}$/i.test(u)?{r:parseInt(u.slice(0,2),16)/255,g:parseInt(u.slice(2,4),16)/255,b:parseInt(u.slice(4,6),16)/255}:null},st=l=>{var s;if(l>=0||typeof document=="undefined"||typeof process!="undefined"&&((s=process.env)==null?void 0:s.NODE_ENV)==="production")return;let u=window.getComputedStyle(document.body).backgroundColor;u&&u!=="transparent"&&!/rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/.test(u)&&console.warn("[smokey-fluid-cursor] <body> has an opaque background ("+u+") and the canvas sits at z-index "+l+`, so the effect will be painted over and stay invisible.
3
+ Move the background to <html>, or give the canvas a zIndex above your background.`)},at=()=>typeof window!="undefined"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,ue={dispose:()=>{},pause:()=>{},resume:()=>{},isPaused:()=>!0,setConfig:()=>{},splat:()=>{},canvas:null},Ce=(l={})=>{var Le,we,_e;let u={...it,...l};if(typeof document=="undefined")return ue;let E=!1,s=(Le=Be(u.canvas))!=null?Le:document.getElementById(u.id);if(!s){let e=(we=Be(u.container))!=null?we:document.body;if(!e)return ue;s=document.createElement("canvas"),s.id=u.id,e.appendChild(s),E=!0}u.className&&s.classList.add(...u.className.split(/\s+/));let z=u.position==="fixed"||u.position==="absolute";Object.assign(s.style,{position:u.position,...z?{top:"0",left:"0",width:"100%",height:"100%"}:{},display:"block",pointerEvents:u.pointerEvents?"auto":"none",zIndex:String(u.zIndex)}),st(u.zIndex),I();class L{constructor(){this.id=-1;this.texcoordX=0;this.texcoordY=0;this.prevTexcoordX=0;this.prevTexcoordY=0;this.deltaX=0;this.deltaY=0;this.down=!1;this.moved=!1;this.color=[30,0,300]}}let g=[];g.push(new L);let t,h;try{({gl:t,ext:h}=m(s))}catch(e){typeof console!="undefined"&&console.warn("[smokey-fluid-cursor] WebGL is unavailable; the cursor effect is disabled.",e);let r=s,n=E;return{...ue,dispose:()=>{n&&r.remove()},setConfig:o=>{o.zIndex!==void 0&&(r.style.zIndex=String(o.zIndex)),o.pointerEvents!==void 0&&(r.style.pointerEvents=o.pointerEvents?"auto":"none")},get canvas(){return r}}}h.supportLinearFiltering||(u.dyeResolution=512,u.shading=!1);function m(e){let r={alpha:!0,depth:!1,stencil:!1,antialias:!1,preserveDrawingBuffer:!1},n=e.getContext("webgl2",r),o=!!n;if(o||(n=e.getContext("webgl",r)||e.getContext("experimental-webgl",r)),!n)throw new Error("WebGL not supported");let i=null,c,a;if(o){let f=n;f.getExtension("EXT_color_buffer_float"),c=!!f.getExtension("OES_texture_float_linear"),a=f.HALF_FLOAT}else{let f=n;if(i=f.getExtension("OES_texture_half_float"),c=!!f.getExtension("OES_texture_half_float_linear"),!i)throw new Error("OES_texture_half_float not supported on WebGL1");a=i.HALF_FLOAT_OES}n.clearColor(0,0,0,1);let v=null,x=null,_=null;if(o){let f=n;v=p(f,f.RGBA16F,f.RGBA,a),x=p(f,f.RG16F,f.RG,a),_=p(f,f.R16F,f.RED,a)}else{let f=n;v=p(f,f.RGBA,f.RGBA,a),x=p(f,f.RGBA,f.RGBA,a),_=p(f,f.RGBA,f.RGBA,a)}return{gl:n,ext:{formatRGBA:v,formatRG:x,formatR:_,halfFloatTexType:a,supportLinearFiltering:c,isWebGL2:o}}}function p(e,r,n,o){if(!K(e,r,n,o)){if(e.RGBA16F!==void 0){let i=e;switch(r){case i.R16F:return p(i,i.RG16F,i.RG,o);case i.RG16F:return p(i,i.RGBA16F,i.RGBA,o);default:return null}}return null}return{internalFormat:r,format:n}}function K(e,r,n,o){let i=e.createTexture();if(!i)return!1;e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),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,r,4,4,0,n,o,null);let c=e.createFramebuffer();if(!c)return!1;e.bindFramebuffer(e.FRAMEBUFFER,c),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0);let a=e.checkFramebufferStatus(e.FRAMEBUFFER);return e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(c),e.deleteTexture(i),a===e.FRAMEBUFFER_COMPLETE}class X{constructor(r,n){this.vertexShader=r,this.fragmentShaderSource=n,this.programs={},this.activeProgram=null,this.uniforms={}}setKeywords(r){let n=0;for(let i=0;i<r.length;i++)n+=nt(r[i]);let o=this.programs[n];if(!o){let i=F(t,t.FRAGMENT_SHADER,ce(this.fragmentShaderSource,r));o=se(t,this.vertexShader,i),this.programs[n]=o}o!==this.activeProgram&&(this.uniforms=ae(t,o),this.activeProgram=o)}bind(){this.activeProgram&&t.useProgram(this.activeProgram)}}class w{constructor(r,n){this.program=se(t,r,n),this.uniforms=ae(t,this.program)}bind(){this.program&&t.useProgram(this.program)}}function se(e,r,n){let o=e.createProgram();return e.attachShader(o,r),e.attachShader(o,n),e.bindAttribLocation(o,0,"aPosition"),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)||console.trace(e.getProgramInfoLog(o)),o}function ae(e,r){let n={},o=e.getProgramParameter(r,e.ACTIVE_UNIFORMS);for(let i=0;i<o;i++){let c=e.getActiveUniform(r,i);if(!c)continue;let a=c.name,v=e.getUniformLocation(r,a);v&&(n[a]=v)}return n}function F(e,r,n){let o=e.createShader(r);return e.shaderSource(o,n),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||console.trace(e.getShaderInfoLog(o)),o}function ce(e,r){if(!r||r.length===0)return e;let n="";return r.forEach(o=>{n+="#define "+o+`
4
+ `}),n+e}let D=F(t,t.VERTEX_SHADER,`precision highp float;
5
+ attribute vec2 aPosition;
6
+ varying vec2 vUv;
7
+ varying vec2 vL;
8
+ varying vec2 vR;
9
+ varying vec2 vT;
10
+ varying vec2 vB;
11
+ uniform vec2 texelSize;
12
+ void main () {
13
+ vUv = aPosition * 0.5 + 0.5;
14
+ vL = vUv - vec2(texelSize.x, 0.0);
15
+ vR = vUv + vec2(texelSize.x, 0.0);
16
+ vT = vUv + vec2(0.0, texelSize.y);
17
+ vB = vUv - vec2(0.0, texelSize.y);
18
+ gl_Position = vec4(aPosition, 0.0, 1.0);
19
+ }`),Ae=F(t,t.FRAGMENT_SHADER,`precision mediump float;
20
+ precision mediump sampler2D;
21
+ varying highp vec2 vUv;
22
+ uniform sampler2D uTexture;
23
+ void main () {
24
+ gl_FragColor = texture2D(uTexture, vUv);
25
+ }`),Pe=F(t,t.FRAGMENT_SHADER,`precision mediump float;
26
+ precision mediump sampler2D;
27
+ varying highp vec2 vUv;
28
+ uniform sampler2D uTexture;
29
+ uniform float value;
30
+ void main () {
31
+ gl_FragColor = value * texture2D(uTexture, vUv);
32
+ }`),Ue=`precision highp float;
33
+ precision highp sampler2D;
34
+ varying vec2 vUv;
35
+ varying vec2 vL;
36
+ varying vec2 vR;
37
+ varying vec2 vT;
38
+ varying vec2 vB;
39
+ uniform sampler2D uTexture;
40
+ uniform vec2 texelSize;
41
+ void main () {
42
+ vec3 c = texture2D(uTexture, vUv).rgb;
43
+ #ifdef shading
44
+ vec3 lc = texture2D(uTexture, vL).rgb;
45
+ vec3 rc = texture2D(uTexture, vR).rgb;
46
+ vec3 tc = texture2D(uTexture, vT).rgb;
47
+ vec3 bc = texture2D(uTexture, vB).rgb;
48
+ float dx = length(rc) - length(lc);
49
+ float dy = length(tc) - length(bc);
50
+ vec3 n = normalize(vec3(dx, dy, length(texelSize)));
51
+ vec3 l = vec3(0.0, 0.0, 1.0);
52
+ float diffuse = clamp(dot(n, l) + 0.7, 0.7, 1.0);
53
+ c *= diffuse;
54
+ #endif
55
+ float a = max(c.r, max(c.g, c.b));
56
+ gl_FragColor = vec4(c, a);
57
+ }`,Ge=F(t,t.FRAGMENT_SHADER,`precision highp float;
58
+ precision highp sampler2D;
59
+ varying vec2 vUv;
60
+ uniform sampler2D uTarget;
61
+ uniform float aspectRatio;
62
+ uniform vec3 color;
63
+ uniform vec2 point;
64
+ uniform float radius;
65
+ void main () {
66
+ vec2 p = vUv - point.xy;
67
+ p.x *= aspectRatio;
68
+ vec3 splat = exp(-dot(p, p) / radius) * color;
69
+ vec3 base = texture2D(uTarget, vUv).xyz;
70
+ gl_FragColor = vec4(base + splat, 1.0);
71
+ }`),Me=F(t,t.FRAGMENT_SHADER,ce(`precision highp float;
72
+ precision highp sampler2D;
73
+ varying vec2 vUv;
74
+ uniform sampler2D uVelocity;
75
+ uniform sampler2D uSource;
76
+ uniform vec2 texelSize;
77
+ uniform vec2 dyeTexelSize;
78
+ uniform float dt;
79
+ uniform float dissipation;
80
+ vec4 bilerp (sampler2D sam, vec2 uv, vec2 tsize) {
81
+ vec2 st = uv / tsize - 0.5;
82
+ vec2 iuv = floor(st);
83
+ vec2 fuv = fract(st);
84
+ vec4 a = texture2D(sam, (iuv + vec2(0.5, 0.5)) * tsize);
85
+ vec4 b = texture2D(sam, (iuv + vec2(1.5, 0.5)) * tsize);
86
+ vec4 c = texture2D(sam, (iuv + vec2(0.5, 1.5)) * tsize);
87
+ vec4 d = texture2D(sam, (iuv + vec2(1.5, 1.5)) * tsize);
88
+ return mix(mix(a, b, fuv.x), mix(c, d, fuv.x), fuv.y);
89
+ }
90
+ void main () {
91
+ #ifdef MANUAL_FILTERING
92
+ vec2 coord = vUv - dt * bilerp(uVelocity, vUv, texelSize).xy * texelSize;
93
+ vec4 result = bilerp(uSource, coord, dyeTexelSize);
94
+ #else
95
+ vec2 coord = vUv - dt * texture2D(uVelocity, vUv).xy * texelSize;
96
+ vec4 result = texture2D(uSource, coord);
97
+ #endif
98
+ float decay = 1.0 + dissipation * dt;
99
+ gl_FragColor = result / decay;
100
+ }`,h.supportLinearFiltering?null:["MANUAL_FILTERING"])),ze=F(t,t.FRAGMENT_SHADER,`precision mediump float;
101
+ precision mediump sampler2D;
102
+ varying highp vec2 vUv;
103
+ varying highp vec2 vL;
104
+ varying highp vec2 vR;
105
+ varying highp vec2 vT;
106
+ varying highp vec2 vB;
107
+ uniform sampler2D uVelocity;
108
+ void main () {
109
+ float L = texture2D(uVelocity, vL).x;
110
+ float R = texture2D(uVelocity, vR).x;
111
+ float T = texture2D(uVelocity, vT).y;
112
+ float B = texture2D(uVelocity, vB).y;
113
+ vec2 C = texture2D(uVelocity, vUv).xy;
114
+ if (vL.x < 0.0) { L = -C.x; }
115
+ if (vR.x > 1.0) { R = -C.x; }
116
+ if (vT.y > 1.0) { T = -C.y; }
117
+ if (vB.y < 0.0) { B = -C.y; }
118
+ float div = 0.5 * (R - L + T - B);
119
+ gl_FragColor = vec4(div, 0.0, 0.0, 1.0);
120
+ }`),Ie=F(t,t.FRAGMENT_SHADER,`precision mediump float;
121
+ precision mediump sampler2D;
122
+ varying highp vec2 vUv;
123
+ varying highp vec2 vL;
124
+ varying highp vec2 vR;
125
+ varying highp vec2 vT;
126
+ varying highp vec2 vB;
127
+ uniform sampler2D uVelocity;
128
+ void main () {
129
+ float L = texture2D(uVelocity, vL).y;
130
+ float R = texture2D(uVelocity, vR).y;
131
+ float T = texture2D(uVelocity, vT).x;
132
+ float B = texture2D(uVelocity, vB).x;
133
+ float vorticity = R - L - T + B;
134
+ gl_FragColor = vec4(0.5 * vorticity, 0.0, 0.0, 1.0);
135
+ }`),Xe=F(t,t.FRAGMENT_SHADER,`precision highp float;
136
+ precision highp sampler2D;
137
+ varying vec2 vUv;
138
+ varying vec2 vL;
139
+ varying vec2 vR;
140
+ varying vec2 vT;
141
+ varying vec2 vB;
142
+ uniform sampler2D uVelocity;
143
+ uniform sampler2D uCurl;
144
+ uniform float curl;
145
+ uniform float dt;
146
+ void main () {
147
+ float L = texture2D(uCurl, vL).x;
148
+ float R = texture2D(uCurl, vR).x;
149
+ float T = texture2D(uCurl, vT).x;
150
+ float B = texture2D(uCurl, vB).x;
151
+ float C = texture2D(uCurl, vUv).x;
152
+ vec2 force = 0.5 * vec2(abs(T) - abs(B), abs(R) - abs(L));
153
+ force /= length(force) + 0.0001;
154
+ force *= curl * C;
155
+ force.y *= -1.0;
156
+ vec2 velocity = texture2D(uVelocity, vUv).xy;
157
+ velocity += force * dt;
158
+ velocity = min(max(velocity, -1000.0), 1000.0);
159
+ gl_FragColor = vec4(velocity, 0.0, 1.0);
160
+ }`),Oe=F(t,t.FRAGMENT_SHADER,`precision mediump float;
161
+ precision mediump sampler2D;
162
+ varying highp vec2 vUv;
163
+ varying highp vec2 vL;
164
+ varying highp vec2 vR;
165
+ varying highp vec2 vT;
166
+ varying highp vec2 vB;
167
+ uniform sampler2D uPressure;
168
+ uniform sampler2D uDivergence;
169
+ void main () {
170
+ float L = texture2D(uPressure, vL).x;
171
+ float R = texture2D(uPressure, vR).x;
172
+ float T = texture2D(uPressure, vT).x;
173
+ float B = texture2D(uPressure, vB).x;
174
+ float C = texture2D(uPressure, vUv).x;
175
+ float divergence = texture2D(uDivergence, vUv).x;
176
+ float pressure = (L + R + B + T - divergence) * 0.25;
177
+ gl_FragColor = vec4(pressure, 0.0, 0.0, 1.0);
178
+ }`),Ne=F(t,t.FRAGMENT_SHADER,`precision mediump float;
179
+ precision mediump sampler2D;
180
+ varying highp vec2 vUv;
181
+ varying highp vec2 vL;
182
+ varying highp vec2 vR;
183
+ varying highp vec2 vT;
184
+ varying highp vec2 vB;
185
+ uniform sampler2D uPressure;
186
+ uniform sampler2D uVelocity;
187
+ void main () {
188
+ float L = texture2D(uPressure, vL).x;
189
+ float R = texture2D(uPressure, vR).x;
190
+ float T = texture2D(uPressure, vT).x;
191
+ float B = texture2D(uPressure, vB).x;
192
+ vec2 velocity = texture2D(uVelocity, vUv).xy;
193
+ velocity.xy -= vec2(R - L, T - B);
194
+ gl_FragColor = vec4(velocity, 0.0, 1.0);
195
+ }`),T=(()=>{let e=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,e),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),t.STATIC_DRAW);let r=t.createBuffer();return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,r),t.bufferData(t.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,0,2,3]),t.STATIC_DRAW),t.vertexAttribPointer(0,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(0),(n,o=!1)=>{n==null?(t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight),t.bindFramebuffer(t.FRAMEBUFFER,null)):(t.viewport(0,0,n.width,n.height),t.bindFramebuffer(t.FRAMEBUFFER,n.fbo)),o&&(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT)),t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)}})(),b,d,j,J,B,le=new w(D,Ae),$=new w(D,Pe),C=new w(D,Ge),S=new w(D,Me),Z=new w(D,ze),Q=new w(D,Ie),P=new w(D,Xe),O=new w(D,Oe),N=new w(D,Ne),H=new X(D,Ue);function ee(){let e=ye(u.simResolution),r=ye(u.dyeResolution),n=h.halfFloatTexType,o=h.formatRGBA,i=h.formatRG,c=h.formatR,a=h.supportLinearFiltering?t.LINEAR:t.NEAREST;t.disable(t.BLEND),b==null?b=te(r.width,r.height,o.internalFormat,o.format,n,a):b=de(b,r.width,r.height,o.internalFormat,o.format,n,a),d==null?d=te(e.width,e.height,i.internalFormat,i.format,n,a):d=de(d,e.width,e.height,i.internalFormat,i.format,n,a),j=U(e.width,e.height,c.internalFormat,c.format,n,t.NEAREST),J=U(e.width,e.height,c.internalFormat,c.format,n,t.NEAREST),B=te(e.width,e.height,c.internalFormat,c.format,n,t.NEAREST)}function U(e,r,n,o,i,c){t.activeTexture(t.TEXTURE0);let a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,c),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texImage2D(t.TEXTURE_2D,0,n,e,r,0,o,i,null);let v=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,v),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,a,0),t.viewport(0,0,e,r),t.clear(t.COLOR_BUFFER_BIT);let x=1/e,_=1/r;return{texture:a,fbo:v,width:e,height:r,texelSizeX:x,texelSizeY:_,attach(f){return t.activeTexture(t.TEXTURE0+f),t.bindTexture(t.TEXTURE_2D,a),f}}}function te(e,r,n,o,i,c){let a=U(e,r,n,o,i,c),v=U(e,r,n,o,i,c);return{width:e,height:r,texelSizeX:a.texelSizeX,texelSizeY:a.texelSizeY,get read(){return a},set read(x){a=x},get write(){return v},set write(x){v=x},swap(){let x=a;a=v,v=x}}}function He(e,r,n,o,i,c,a){let v=U(r,n,o,i,c,a);return le.bind(),t.uniform1i(le.uniforms.uTexture,e.attach(0)),T(v),v}function de(e,r,n,o,i,c,a){return e.width===r&&e.height===n||(e.read=He(e.read,r,n,o,i,c,a),e.write=U(r,n,o,i,c,a),e.width=r,e.height=n,e.texelSizeX=1/r,e.texelSizeY=1/n),e}function Ye(){let e=[];u.shading&&e.push("shading"),H.setKeywords(e)}Ye(),ee();let re=Date.now(),Y=0,ne=0;function fe(){let e=We();I()&&ee(),ke(e),Ve(),u.paused||qe(e),me(null),ne=requestAnimationFrame(fe)}function We(){let e=Date.now(),r=(e-re)/1e3;return r=Math.min(r,.016666),re=e,r}function I(){let e=y(s.clientWidth),r=y(s.clientHeight);return s.width!==e||s.height!==r?(s.width=e,s.height=r,!0):!1}function ke(e){Y+=e*u.colorUpdateSpeed,Y>=1&&(Y=rt(Y,0,1),g.forEach(r=>{r.color=Te(W())}))}function Ve(){g.forEach(e=>{e.moved&&(e.moved=!1,je(e))})}function qe(e){t.disable(t.BLEND),Q.bind(),t.uniform2f(Q.uniforms.texelSize,d.texelSizeX,d.texelSizeY),t.uniform1i(Q.uniforms.uVelocity,d.read.attach(0)),T(J),P.bind(),t.uniform2f(P.uniforms.texelSize,d.texelSizeX,d.texelSizeY),t.uniform1i(P.uniforms.uVelocity,d.read.attach(0)),t.uniform1i(P.uniforms.uCurl,J.attach(1)),t.uniform1f(P.uniforms.curl,u.curl),t.uniform1f(P.uniforms.dt,e),T(d.write),d.swap(),Z.bind(),t.uniform2f(Z.uniforms.texelSize,d.texelSizeX,d.texelSizeY),t.uniform1i(Z.uniforms.uVelocity,d.read.attach(0)),T(j),$.bind(),t.uniform1i($.uniforms.uTexture,B.read.attach(0)),t.uniform1f($.uniforms.value,u.pressure),T(B.write),B.swap(),O.bind(),t.uniform2f(O.uniforms.texelSize,d.texelSizeX,d.texelSizeY),t.uniform1i(O.uniforms.uDivergence,j.attach(0));for(let n=0;n<u.pressureIteration;n++)t.uniform1i(O.uniforms.uPressure,B.read.attach(1)),T(B.write),B.swap();N.bind(),t.uniform2f(N.uniforms.texelSize,d.texelSizeX,d.texelSizeY),t.uniform1i(N.uniforms.uPressure,B.read.attach(0)),t.uniform1i(N.uniforms.uVelocity,d.read.attach(1)),T(d.write),d.swap(),S.bind(),t.uniform2f(S.uniforms.texelSize,d.texelSizeX,d.texelSizeY),h.supportLinearFiltering||t.uniform2f(S.uniforms.dyeTexelSize,d.texelSizeX,d.texelSizeY);let r=d.read.attach(0);t.uniform1i(S.uniforms.uVelocity,r),t.uniform1i(S.uniforms.uSource,r),t.uniform1f(S.uniforms.dt,e),t.uniform1f(S.uniforms.dissipation,u.velocityDissipation),T(d.write),d.swap(),h.supportLinearFiltering||t.uniform2f(S.uniforms.dyeTexelSize,b.texelSizeX,b.texelSizeY),t.uniform1i(S.uniforms.uVelocity,d.read.attach(0)),t.uniform1i(S.uniforms.uSource,b.read.attach(1)),t.uniform1f(S.uniforms.dissipation,u.densityDissipation),T(b.write),b.swap()}function me(e){t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.BLEND),Ke(e)}function Ke(e){let r=e==null?t.drawingBufferWidth:e.width,n=e==null?t.drawingBufferHeight:e.height;H.bind(),u.shading&&t.uniform2f(H.uniforms.texelSize,1/r,1/n),t.uniform1i(H.uniforms.uTexture,b.read.attach(0)),T(e)}function je(e){let r=e.deltaX*u.splatForce,n=e.deltaY*u.splatForce,o=et(e.color);oe(e.texcoordX,e.texcoordY,r,n,o)}function ve(e){let r=W();r.r*=10,r.g*=10,r.b*=10;let n=10*(Math.random()-.5),o=30*(Math.random()-.5);oe(e.texcoordX,e.texcoordY,n,o,r)}function oe(e,r,n,o,i){C.bind(),t.uniform1i(C.uniforms.uTarget,d.read.attach(0)),t.uniform1f(C.uniforms.aspectRatio,s.width/s.height),t.uniform2f(C.uniforms.point,e,r),t.uniform3f(C.uniforms.color,n,o,0),t.uniform1f(C.uniforms.radius,Je(u.splatRadius/100)),T(d.write),d.swap(),t.uniform1i(C.uniforms.uTarget,b.read.attach(0)),t.uniform3f(C.uniforms.color,i.r,i.g,i.b),T(b.write),b.swap()}function Je(e){let r=s.width/s.height;return r>1&&(e*=r),e}let he=e=>{let r=g[0],n=s.getBoundingClientRect(),o=y(e.clientX-n.left),i=y(e.clientY-n.top);Re(r,-1,o,i),ve(r)},pe=e=>{let r=g[0],n=s.getBoundingClientRect(),o=y(e.clientX-n.left),i=y(e.clientY-n.top),c=r.color;Ee(r,o,i,c)},xe=e=>{let r=e.targetTouches,n=s.getBoundingClientRect(),o=g[0];for(let i=0;i<r.length;i++){let c=y(r[i].clientX-n.left),a=y(r[i].clientY-n.top);Re(o,r[i].identifier,c,a),ve(o)}},ge=e=>{e.preventDefault();let r=e.targetTouches,n=s.getBoundingClientRect(),o=g[0];for(let i=0;i<r.length;i++){let c=y(r[i].clientX-n.left),a=y(r[i].clientY-n.top);Ee(o,c,a,o.color)}},be=e=>{let r=e.changedTouches,n=g[0];for(let o=0;o<r.length;o++)$e(n)};window.addEventListener("mousedown",he),window.addEventListener("mousemove",pe),window.addEventListener("touchstart",xe),window.addEventListener("touchmove",ge,{passive:!1}),window.addEventListener("touchend",be);function Re(e,r,n,o){e.id=r,e.down=!0,e.moved=!1,e.texcoordX=n/s.width,e.texcoordY=1-o/s.height,e.prevTexcoordX=e.texcoordX,e.prevTexcoordY=e.texcoordY,e.deltaX=0,e.deltaY=0,e.color=Te(W())}function Ee(e,r,n,o){e.prevTexcoordX=e.texcoordX,e.prevTexcoordY=e.texcoordY,e.texcoordX=r/s.width,e.texcoordY=1-n/s.height,e.deltaX=Ze(e.texcoordX-e.prevTexcoordX),e.deltaY=Qe(e.texcoordY-e.prevTexcoordY),e.moved=Math.abs(e.deltaX)>0||Math.abs(e.deltaY)>0,e.color=o}function $e(e){e.down=!1}function Ze(e){let r=s.width/s.height;return r<1&&(e*=r),e}function Qe(e){let r=s.width/s.height;return r>1&&(e/=r),e}function W(){let e=u.colorIntensity,r=u.palette;if(r&&r.length>0){let o=r[Math.floor(Math.random()*r.length)],i=ut(o);if(i)return{r:i.r*e,g:i.g*e,b:i.b*e}}let n=tt(Math.random(),1,1);return n.r*=e,n.g*=e,n.b*=e,n}function Te(e){return[e.r,e.g,e.b]}function et(e){return{r:e[0],g:e[1],b:e[2]}}function tt(e,r,n){let o=0,i=0,c=0,a=Math.floor(e*6),v=e*6-a,x=n*(1-r),_=n*(1-v*r),f=n*(1-(1-v)*r);switch(a%6){case 0:o=n,i=f,c=x;break;case 1:o=_,i=n,c=x;break;case 2:o=x,i=n,c=f;break;case 3:o=x,i=_,c=n;break;case 4:o=f,i=x,c=n;break;case 5:o=n,i=x,c=_;break}return{r:o,g:i,b:c}}function rt(e,r,n){let o=n-r;return o===0?r:(e-r)%o+r}function ye(e){let r=t.drawingBufferWidth/t.drawingBufferHeight;r<1&&(r=1/r);let n=Math.round(e),o=Math.round(e*r);return t.drawingBufferWidth>t.drawingBufferHeight?{width:o,height:n}:{width:n,height:o}}function y(e){let r=Math.min(window.devicePixelRatio||1,Math.max(1,u.maxDpr));return Math.floor(e*r)}function nt(e){if(e.length===0)return 0;let r=0;for(let n=0;n<e.length;n++)r=(r<<5)-r+e.charCodeAt(n),r|=0;return r}function ot(){var e,r;ie||(ie=!0,q(),window.removeEventListener("mousedown",he),window.removeEventListener("mousemove",pe),window.removeEventListener("touchstart",xe),window.removeEventListener("touchmove",ge),window.removeEventListener("touchend",be),window.removeEventListener("resize",Se),document.removeEventListener("visibilitychange",Fe),(e=R==null?void 0:R.removeEventListener)==null||e.call(R,"change",De),G==null||G.disconnect(),E&&(s==null||s.remove()),(r=t.getExtension("WEBGL_lose_context"))==null||r.loseContext())}let ie=!1,k=!1;function V(){k||ie||(k=!0,re=Date.now(),ne=requestAnimationFrame(fe))}function q(){k=!1,cancelAnimationFrame(ne)}let Fe=()=>{u.pauseOnHidden&&(document.hidden?q():M||V())},Se=()=>I(),G=typeof ResizeObserver!="undefined"?new ResizeObserver(()=>I()):null;G==null||G.observe(s);let R=typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,De=()=>{u.respectReducedMotion&&(R!=null&&R.matches?q():M||V())},M=!1;return window.addEventListener("resize",Se),document.addEventListener("visibilitychange",Fe),(_e=R==null?void 0:R.addEventListener)==null||_e.call(R,"change",De),u.respectReducedMotion&&at()?(M=!0,me(null)):V(),{dispose:ot,pause(){M=!0,q()},resume(){M=!1,V()},isPaused:()=>M||!k,setConfig(e){let r=e.simResolution!==void 0&&e.simResolution!==u.simResolution||e.dyeResolution!==void 0&&e.dyeResolution!==u.dyeResolution;Object.assign(u,e),e.maxDpr!==void 0&&I(),r&&ee(),e.zIndex!==void 0&&(s.style.zIndex=String(e.zIndex)),e.pointerEvents!==void 0&&(s.style.pointerEvents=e.pointerEvents?"auto":"none")},splat(e,r,n){let o=s.getBoundingClientRect(),i=y(e),c=y(r),a=n!=null?n:W();oe(i,s.height-c,0,0,a)},get canvas(){return s}}};import{jsx as ft}from"react/jsx-runtime";var ct=["densityDissipation","velocityDissipation","pressure","pressureIteration","curl","splatRadius","splatForce","shading","colorUpdateSpeed","paused","transparent","backColor","palette","colorIntensity","zIndex","pointerEvents","maxDpr","pauseOnHidden","respectReducedMotion"],lt=l=>JSON.stringify([l==null?void 0:l.id,l==null?void 0:l.position,l==null?void 0:l.className,l==null?void 0:l.simResolution,l==null?void 0:l.dyeResolution,l==null?void 0:l.captureResolution]);function dt(l,u){let E=A.useRef(null),s=A.useRef(l);s.current=l;let z=lt(l);return A.useEffect(()=>{let L=Ce({...s.current,...u!=null&&u.current?{container:u.current}:{}});return E.current=L,()=>{L.dispose(),E.current=null}},[z,u]),A.useEffect(()=>{let L=E.current;if(!L||!l)return;let g={};for(let t of ct)l[t]!==void 0&&(g[t]=l[t]);L.setConfig(g)}),E}var xt=A.forwardRef(function({config:u,scoped:E=!1,className:s,style:z,children:L},g){let t=A.useRef(null),h=dt(u,E?t:void 0);return A.useImperativeHandle(g,()=>({dispose:()=>{var m;return(m=h.current)==null?void 0:m.dispose()},pause:()=>{var m;return(m=h.current)==null?void 0:m.pause()},resume:()=>{var m;return(m=h.current)==null?void 0:m.resume()},isPaused:()=>{var m,p;return(p=(m=h.current)==null?void 0:m.isPaused())!=null?p:!0},setConfig:m=>{var p;return(p=h.current)==null?void 0:p.setConfig(m)},splat:(m,p,K)=>{var X;return(X=h.current)==null?void 0:X.splat(m,p,K)},get canvas(){var m,p;return(p=(m=h.current)==null?void 0:m.canvas)!=null?p:null}}),[h]),E?ft("div",{ref:t,className:s,style:{position:"relative",overflow:"hidden",...z},children:L}):null});export{xt as SmokeyFluidCursor,Ce as initFluid,dt as useSmokeyFluidCursor};