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