react-smokey-fluid-cursor 1.0.4 → 2.1.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/LICENSE +21 -0
- package/README.md +305 -115
- package/dist/index.d.mts +409 -0
- package/dist/index.d.ts +357 -3
- package/dist/index.js +195 -292
- package/dist/index.mjs +194 -292
- package/package.json +68 -20
package/dist/index.mjs
CHANGED
|
@@ -1,293 +1,195 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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 ut={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},_e=c=>{var s;return c?typeof c!="string"?c:(s=document.querySelector(c))!=null?s:document.getElementById(c):null},ct=c=>{let s=c.trim().replace(/^#/,"");return s.length===3&&(s=s[0]+s[0]+s[1]+s[1]+s[2]+s[2]),/^[0-9a-f]{6}$/i.test(s)?{r:parseInt(s.slice(0,2),16)/255,g:parseInt(s.slice(2,4),16)/255,b:parseInt(s.slice(4,6),16)/255}:null},lt=c=>{var a;if(c>=0||typeof document=="undefined"||typeof process!="undefined"&&((a=process.env)==null?void 0:a.NODE_ENV)==="production")return;let s=window.getComputedStyle(document.body).backgroundColor;s&&s!=="transparent"&&!/rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/.test(s)&&console.warn("[smokey-fluid-cursor] <body> has an opaque background ("+s+") and the canvas sits at z-index "+c+`, 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.`)},ft=()=>typeof window!="undefined"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,se={dispose:()=>{},pause:()=>{},resume:()=>{},isPaused:()=>!0,setConfig:()=>{},splat:()=>{},canvas:null},Be=(c={})=>{var we,Pe,Ce;let s={...ut,...c};if(typeof document=="undefined")return se;let b=!1,a=(we=_e(s.canvas))!=null?we:document.getElementById(s.id);if(!a){let e=(Pe=_e(s.container))!=null?Pe:document.body;if(!e)return se;a=document.createElement("canvas"),a.id=s.id,e.appendChild(a),b=!0}s.className&&a.classList.add(...s.className.split(/\s+/));let B=s.position==="fixed"||s.position==="absolute";Object.assign(a.style,{position:s.position,...B?{top:"0",left:"0",width:"100%",height:"100%"}:{},display:"block",pointerEvents:s.pointerEvents?"auto":"none",zIndex:String(s.zIndex)}),lt(s.zIndex),N();class F{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 F);let t,p;try{({gl:t,ext:p}=m(a))}catch(e){typeof console!="undefined"&&console.warn("[smokey-fluid-cursor] WebGL is unavailable; the cursor effect is disabled.",e);let r=a,n=b;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||(s.dyeResolution=512,s.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,l,u;if(o){let d=n;d.getExtension("EXT_color_buffer_float"),l=!!d.getExtension("OES_texture_float_linear"),u=d.HALF_FLOAT}else{let d=n;if(i=d.getExtension("OES_texture_half_float"),l=!!d.getExtension("OES_texture_half_float_linear"),!i)throw new Error("OES_texture_half_float not supported on WebGL1");u=i.HALF_FLOAT_OES}n.clearColor(0,0,0,1);let v=null,x=null,P=null;if(o){let d=n;v=h(d,d.RGBA16F,d.RGBA,u),x=h(d,d.RG16F,d.RG,u),P=h(d,d.R16F,d.RED,u)}else{let d=n;v=h(d,d.RGBA,d.RGBA,u),x=h(d,d.RGBA,d.RGBA,u),P=h(d,d.RGBA,d.RGBA,u)}return{gl:n,ext:{formatRGBA:v,formatRG:x,formatR:P,halfFloatTexType:u,supportLinearFiltering:l,isWebGL2:o}}}function h(e,r,n,o){if(!q(e,r,n,o)){if(e.RGBA16F!==void 0){let i=e;switch(r){case i.R16F:return h(i,i.RG16F,i.RG,o);case i.RG16F:return h(i,i.RGBA16F,i.RGBA,o);default:return null}}return null}return{internalFormat:r,format:n}}function q(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 l=e.createFramebuffer();if(!l)return!1;e.bindFramebuffer(e.FRAMEBUFFER,l),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0);let u=e.checkFramebufferStatus(e.FRAMEBUFFER);return e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(l),e.deleteTexture(i),u===e.FRAMEBUFFER_COMPLETE}class z{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+=st(r[i]);let o=this.programs[n];if(!o){let i=S(t,t.FRAGMENT_SHADER,le(this.fragmentShaderSource,r));o=ue(t,this.vertexShader,i),this.programs[n]=o}o!==this.activeProgram&&(this.uniforms=ce(t,o),this.activeProgram=o)}bind(){this.activeProgram&&t.useProgram(this.activeProgram)}}class w{constructor(r,n){this.program=ue(t,r,n),this.uniforms=ce(t,this.program)}bind(){this.program&&t.useProgram(this.program)}}function ue(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 ce(e,r){let n={},o=e.getProgramParameter(r,e.ACTIVE_UNIFORMS);for(let i=0;i<o;i++){let l=e.getActiveUniform(r,i);if(!l)continue;let u=l.name,v=e.getUniformLocation(r,u);v&&(n[u]=v)}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 le(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
|
+
}`),Ge=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
|
+
}`),Me=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
|
+
}`,Ne=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
|
+
}`),ze=S(t,t.FRAGMENT_SHADER,le(`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"])),Oe=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
|
+
}`),Xe=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
|
+
}`),ke=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
|
+
}`),He=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
|
+
}`),Ye=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
|
+
}`),E=(()=>{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,f,K,$,C,fe=new w(L,Ge),J=new w(L,Me),_=new w(L,Ne),D=new w(L,ze),Z=new w(L,Oe),Q=new w(L,Xe),U=new w(L,ke),O=new w(L,He),X=new w(L,Ye),k=new z(L,Ie);function ee(){let e=Fe(s.simResolution),r=Fe(s.dyeResolution),n=p.halfFloatTexType,o=p.formatRGBA,i=p.formatRG,l=p.formatR,u=p.supportLinearFiltering?t.LINEAR:t.NEAREST;t.disable(t.BLEND),R==null?R=te(r.width,r.height,o.internalFormat,o.format,n,u):R=de(R,r.width,r.height,o.internalFormat,o.format,n,u),f==null?f=te(e.width,e.height,i.internalFormat,i.format,n,u):f=de(f,e.width,e.height,i.internalFormat,i.format,n,u),K=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=te(e.width,e.height,l.internalFormat,l.format,n,t.NEAREST)}function G(e,r,n,o,i,l){t.activeTexture(t.TEXTURE0);let u=t.createTexture();t.bindTexture(t.TEXTURE_2D,u),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,i,null);let v=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,v),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,u,0),t.viewport(0,0,e,r),t.clear(t.COLOR_BUFFER_BIT);let x=1/e,P=1/r;return{texture:u,fbo:v,width:e,height:r,texelSizeX:x,texelSizeY:P,attach(d){return t.activeTexture(t.TEXTURE0+d),t.bindTexture(t.TEXTURE_2D,u),d}}}function te(e,r,n,o,i,l){let u=G(e,r,n,o,i,l),v=G(e,r,n,o,i,l);return{width:e,height:r,texelSizeX:u.texelSizeX,texelSizeY:u.texelSizeY,get read(){return u},set read(x){u=x},get write(){return v},set write(x){v=x},swap(){let x=u;u=v,v=x}}}function We(e,r,n,o,i,l,u){let v=G(r,n,o,i,l,u);return fe.bind(),t.uniform1i(fe.uniforms.uTexture,e.attach(0)),E(v),v}function de(e,r,n,o,i,l,u){return e.width===r&&e.height===n||(e.read=We(e.read,r,n,o,i,l,u),e.write=G(r,n,o,i,l,u),e.width=r,e.height=n,e.texelSizeX=1/r,e.texelSizeY=1/n),e}function Ve(){let e=[];s.shading&&e.push("shading"),k.setKeywords(e)}Ve(),ee();let re=Date.now(),H=0,ne=0;function me(){let e=je();N()&&ee(),qe(e),Ke(),s.paused||$e(e),ve(null),ne=requestAnimationFrame(me)}function je(){let e=Date.now(),r=(e-re)/1e3;return r=Math.min(r,.016666),re=e,r}function N(){let e=T(a.clientWidth),r=T(a.clientHeight);return a.width!==e||a.height!==r?(a.width=e,a.height=r,!0):!1}function qe(e){H+=e*s.colorUpdateSpeed,H>=1&&(H=it(H,0,1),g.forEach(r=>{r.color=Te(Y())}))}function Ke(){g.forEach(e=>{e.moved&&(e.moved=!1,Ze(e))})}function $e(e){t.disable(t.BLEND),Q.bind(),t.uniform2f(Q.uniforms.texelSize,f.texelSizeX,f.texelSizeY),t.uniform1i(Q.uniforms.uVelocity,f.read.attach(0)),E($),U.bind(),t.uniform2f(U.uniforms.texelSize,f.texelSizeX,f.texelSizeY),t.uniform1i(U.uniforms.uVelocity,f.read.attach(0)),t.uniform1i(U.uniforms.uCurl,$.attach(1)),t.uniform1f(U.uniforms.curl,s.curl),t.uniform1f(U.uniforms.dt,e),E(f.write),f.swap(),Z.bind(),t.uniform2f(Z.uniforms.texelSize,f.texelSizeX,f.texelSizeY),t.uniform1i(Z.uniforms.uVelocity,f.read.attach(0)),E(K),J.bind(),t.uniform1i(J.uniforms.uTexture,C.read.attach(0)),t.uniform1f(J.uniforms.value,s.pressure),E(C.write),C.swap(),O.bind(),t.uniform2f(O.uniforms.texelSize,f.texelSizeX,f.texelSizeY),t.uniform1i(O.uniforms.uDivergence,K.attach(0));for(let n=0;n<s.pressureIteration;n++)t.uniform1i(O.uniforms.uPressure,C.read.attach(1)),E(C.write),C.swap();X.bind(),t.uniform2f(X.uniforms.texelSize,f.texelSizeX,f.texelSizeY),t.uniform1i(X.uniforms.uPressure,C.read.attach(0)),t.uniform1i(X.uniforms.uVelocity,f.read.attach(1)),E(f.write),f.swap(),D.bind(),t.uniform2f(D.uniforms.texelSize,f.texelSizeX,f.texelSizeY),p.supportLinearFiltering||t.uniform2f(D.uniforms.dyeTexelSize,f.texelSizeX,f.texelSizeY);let r=f.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,s.velocityDissipation),E(f.write),f.swap(),p.supportLinearFiltering||t.uniform2f(D.uniforms.dyeTexelSize,R.texelSizeX,R.texelSizeY),t.uniform1i(D.uniforms.uVelocity,f.read.attach(0)),t.uniform1i(D.uniforms.uSource,R.read.attach(1)),t.uniform1f(D.uniforms.dissipation,s.densityDissipation),E(R.write),R.swap()}function ve(e){t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.enable(t.BLEND),Je(e)}function Je(e){let r=e==null?t.drawingBufferWidth:e.width,n=e==null?t.drawingBufferHeight:e.height;k.bind(),s.shading&&t.uniform2f(k.uniforms.texelSize,1/r,1/n),t.uniform1i(k.uniforms.uTexture,R.read.attach(0)),E(e)}function Ze(e){let r=e.deltaX*s.splatForce,n=e.deltaY*s.splatForce,o=nt(e.color);oe(e.texcoordX,e.texcoordY,r,n,o)}function pe(e){let r=Y();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){_.bind(),t.uniform1i(_.uniforms.uTarget,f.read.attach(0)),t.uniform1f(_.uniforms.aspectRatio,a.width/a.height),t.uniform2f(_.uniforms.point,e,r),t.uniform3f(_.uniforms.color,n,o,0),t.uniform1f(_.uniforms.radius,Qe(s.splatRadius/100)),E(f.write),f.swap(),t.uniform1i(_.uniforms.uTarget,R.read.attach(0)),t.uniform3f(_.uniforms.color,i.r,i.g,i.b),E(R.write),R.swap()}function Qe(e){let r=a.width/a.height;return r>1&&(e*=r),e}let he=e=>{let r=g[0],n=a.getBoundingClientRect(),o=T(e.clientX-n.left),i=T(e.clientY-n.top);ye(r,-1,o,i),pe(r)},xe=e=>{let r=g[0],n=a.getBoundingClientRect(),o=T(e.clientX-n.left),i=T(e.clientY-n.top),l=r.color;Ee(r,o,i,l)},be=e=>{let r=e.targetTouches,n=a.getBoundingClientRect(),o=g[0];for(let i=0;i<r.length;i++){let l=T(r[i].clientX-n.left),u=T(r[i].clientY-n.top);ye(o,r[i].identifier,l,u),pe(o)}},ge=e=>{e.preventDefault();let r=e.targetTouches,n=a.getBoundingClientRect(),o=g[0];for(let i=0;i<r.length;i++){let l=T(r[i].clientX-n.left),u=T(r[i].clientY-n.top);Ee(o,l,u,o.color)}},Re=e=>{let r=e.changedTouches,n=g[0];for(let o=0;o<r.length;o++)et(n)};window.addEventListener("mousedown",he),window.addEventListener("mousemove",xe),window.addEventListener("touchstart",be),window.addEventListener("touchmove",ge,{passive:!1}),window.addEventListener("touchend",Re);function ye(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=Te(Y())}function Ee(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=tt(e.texcoordX-e.prevTexcoordX),e.deltaY=rt(e.texcoordY-e.prevTexcoordY),e.moved=Math.abs(e.deltaX)>0||Math.abs(e.deltaY)>0,e.color=o}function et(e){e.down=!1}function tt(e){let r=a.width/a.height;return r<1&&(e*=r),e}function rt(e){let r=a.width/a.height;return r>1&&(e/=r),e}function Y(){let e=s.colorIntensity,r=s.palette;if(r&&r.length>0){let o=r[Math.floor(Math.random()*r.length)],i=ct(o);if(i)return{r:i.r*e,g:i.g*e,b:i.b*e}}let n=ot(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 nt(e){return{r:e[0],g:e[1],b:e[2]}}function ot(e,r,n){let o=0,i=0,l=0,u=Math.floor(e*6),v=e*6-u,x=n*(1-r),P=n*(1-v*r),d=n*(1-(1-v)*r);switch(u%6){case 0:o=n,i=d,l=x;break;case 1:o=P,i=n,l=x;break;case 2:o=x,i=n,l=d;break;case 3:o=x,i=P,l=n;break;case 4:o=d,i=x,l=n;break;case 5:o=n,i=x,l=P;break}return{r:o,g:i,b:l}}function it(e,r,n){let o=n-r;return o===0?r:(e-r)%o+r}function Fe(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 T(e){let r=Math.min(window.devicePixelRatio||1,Math.max(1,s.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;ie||(ie=!0,j(),window.removeEventListener("mousedown",he),window.removeEventListener("mousemove",xe),window.removeEventListener("touchstart",be),window.removeEventListener("touchmove",ge),window.removeEventListener("touchend",Re),window.removeEventListener("resize",De),document.removeEventListener("visibilitychange",Se),(e=y==null?void 0:y.removeEventListener)==null||e.call(y,"change",Le),M==null||M.disconnect(),b&&(a==null||a.remove()),(r=t.getExtension("WEBGL_lose_context"))==null||r.loseContext())}let ie=!1,W=!1;function V(){W||ie||(W=!0,re=Date.now(),ne=requestAnimationFrame(me))}function j(){W=!1,cancelAnimationFrame(ne)}let Se=()=>{s.pauseOnHidden&&(document.hidden?j():I||V())},De=()=>N(),M=typeof ResizeObserver!="undefined"?new ResizeObserver(()=>N()):null;M==null||M.observe(a);let y=typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null,Le=()=>{s.respectReducedMotion&&(y!=null&&y.matches?j():I||V())},I=!1;return window.addEventListener("resize",De),document.addEventListener("visibilitychange",Se),(Ce=y==null?void 0:y.addEventListener)==null||Ce.call(y,"change",Le),s.respectReducedMotion&&ft()?(I=!0,ve(null)):V(),{dispose:at,pause(){I=!0,j()},resume(){I=!1,V()},isPaused:()=>I||!W,setConfig(e){let r=e.simResolution!==void 0&&e.simResolution!==s.simResolution||e.dyeResolution!==void 0&&e.dyeResolution!==s.dyeResolution;Object.assign(s,e),e.maxDpr!==void 0&&N(),r&&ee(),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(),i=T(e),l=T(r),u=n!=null?n:Y();oe(i,a.height-l,0,0,u)},get canvas(){return a}}};var Ae={Spectrum:null,Sunset:["#ff4ecd","#ff8a4e","#ffd24e"],Ocean:["#4ea8ff","#4effd2","#7c4dff"],Mono:["#ffffff"],Aurora:["#3affa3","#38d9ff","#8f7bff"],Ember:["#ff5722","#ff9100","#ffc400"],Lagoon:["#00c2a8","#00a3ff","#0057d9"],Candy:["#ff8fd0","#ffa9f0","#c79bff"],Toxic:["#b6ff00","#4dff88","#00ffc8"],Royal:["#5b2bff","#8f4dff","#c44dff"],Sakura:["#ffc2dd","#ff8fb1","#ff6f91"],Mint:["#9cffd6","#5ef2c0","#2fd6a5"],Copper:["#ff9a5a","#e2703a","#b34700"],Ultraviolet:["#7b2cff","#b429ff","#ff29f0"],Ice:["#c9f0ff","#8ad4ff","#4fb3ff"],Magma:["#ff2d2d","#ff6a00","#ffb300"],Forest:["#2f9e44","#69db7c","#a9e34b"],Dusk:["#3b3b98","#7158e2","#cd84f1"],Cyber:["#00fff0","#ff00e0","#fffb00"],Pastel:["#ffd6e0","#c7ceea","#b5ead7"]},Ue={Calm:{curl:3,splatForce:4200,splatRadius:.45,densityDissipation:4.6,velocityDissipation:2.6,pressureIteration:16,colorUpdateSpeed:6},Flow:{curl:10,splatForce:6e3,splatRadius:.5,densityDissipation:3.5,velocityDissipation:2,pressureIteration:20,colorUpdateSpeed:10},Swirl:{curl:24,splatForce:7200,splatRadius:.55,densityDissipation:3,velocityDissipation:1.6,pressureIteration:24,colorUpdateSpeed:12},Storm:{curl:40,splatForce:9500,splatRadius:.65,densityDissipation:2.2,velocityDissipation:1.2,pressureIteration:28,colorUpdateSpeed:16},Wisp:{curl:6,splatForce:3200,splatRadius:.32,densityDissipation:6.5,velocityDissipation:3.4,pressureIteration:12,colorUpdateSpeed:8}},dt=()=>{let c={};for(let[s,b]of Object.entries(Ae))for(let[a,B]of Object.entries(Ue)){let F=`${s} ${a}`;c[F]={...B,palette:b?[...b]:null,colorIntensity:b===null?.15:.18}}return c},ae=dt(),mt=Object.keys(ae),vt=Object.keys(Ae),pt=Object.keys(Ue),ht=c=>ae[c];import{jsx as Rt}from"react/jsx-runtime";var xt=["densityDissipation","velocityDissipation","pressure","pressureIteration","curl","splatRadius","splatForce","shading","colorUpdateSpeed","paused","transparent","backColor","palette","colorIntensity","zIndex","pointerEvents","maxDpr","pauseOnHidden","respectReducedMotion"],bt=c=>JSON.stringify([c==null?void 0:c.id,c==null?void 0:c.position,c==null?void 0:c.className,c==null?void 0:c.simResolution,c==null?void 0:c.dyeResolution,c==null?void 0:c.captureResolution]);function gt(c,s){let b=A.useRef(null),a=A.useRef(c);a.current=c;let B=bt(c);return A.useEffect(()=>{let F=Be({...a.current,...s!=null&&s.current?{container:s.current}:{}});return b.current=F,()=>{F.dispose(),b.current=null}},[B,s]),A.useEffect(()=>{let F=b.current;if(!F||!c)return;let g={};for(let t of xt)c[t]!==void 0&&(g[t]=c[t]);F.setConfig(g)}),b}var Dt=A.forwardRef(function({config:s,scoped:b=!1,className:a,style:B,children:F},g){let t=A.useRef(null),p=gt(s,b?t:void 0);return A.useImperativeHandle(g,()=>({dispose:()=>{var m;return(m=p.current)==null?void 0:m.dispose()},pause:()=>{var m;return(m=p.current)==null?void 0:m.pause()},resume:()=>{var m;return(m=p.current)==null?void 0:m.resume()},isPaused:()=>{var m,h;return(h=(m=p.current)==null?void 0:m.isPaused())!=null?h:!0},setConfig:m=>{var h;return(h=p.current)==null?void 0:h.setConfig(m)},splat:(m,h,q)=>{var z;return(z=p.current)==null?void 0:z.splat(m,h,q)},get canvas(){var m,h;return(h=(m=p.current)==null?void 0:m.canvas)!=null?h:null}}),[p]),b?Rt("div",{ref:t,className:a,style:{position:"relative",overflow:"hidden",...B},children:F}):null});export{Dt as SmokeyFluidCursor,pt as characterNames,ht as getPreset,Be as initFluid,vt as paletteNames,mt as presetNames,ae as presets,gt as useSmokeyFluidCursor};
|