@jayf0x/fluidity-js 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jay Verstraete
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # fluidity-js
2
+
3
+ **WebGL fluid simulation for React — interactive text and image effects powered by Navier-Stokes.**
4
+
5
+ [![npm](https://img.shields.io/npm/v/fluidity-js)](https://www.npmjs.com/package/fluidity-js)
6
+ [![license](https://img.shields.io/npm/l/fluidity-js)](./LICENSE)
7
+ [![size](https://img.shields.io/bundlephobia/minzip/fluidity-js)](https://bundlephobia.com/package/fluidity-js)
8
+
9
+ [**Live demo →**](https://jayf0x.github.io/fluidity)
10
+
11
+ ---
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm i fluidity-js
17
+ # or
18
+ pnpm add fluidity-js
19
+ ```
20
+
21
+ Requires React ≥ 17 and a browser with WebGL2 support.
22
+
23
+ ---
24
+
25
+ ## Quick start
26
+
27
+ ### FluidText
28
+
29
+ ```tsx
30
+ import { FluidText } from 'fluidity-js';
31
+
32
+ export function Hero() {
33
+ return (
34
+ <div style={{ width: '100%', height: 300 }}>
35
+ <FluidText text="hello world" fontSize={120} color="#ffffff" />
36
+ </div>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ### FluidImage
42
+
43
+ ```tsx
44
+ import { FluidImage } from 'fluidity-js';
45
+
46
+ export function Cover() {
47
+ return (
48
+ <div style={{ width: '100%', height: '100vh' }}>
49
+ <FluidImage src="/hero.jpg" imageSize="cover" />
50
+ </div>
51
+ );
52
+ }
53
+ ```
54
+
55
+ ### useFluid hook (custom canvas)
56
+
57
+ ```tsx
58
+ import { useRef, useEffect } from 'react';
59
+ import { useFluid } from 'fluidity-js';
60
+
61
+ export function Custom() {
62
+ const containerRef = useRef<HTMLDivElement>(null);
63
+ const controllerRef = useFluid(containerRef, { worker: false });
64
+
65
+ useEffect(() => {
66
+ controllerRef.current?.setTextSource({ text: 'custom', fontSize: 80, color: '#fff' });
67
+ }, []);
68
+
69
+ return <div ref={containerRef} style={{ width: 400, height: 200 }} />;
70
+ }
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Props
76
+
77
+ ### FluidTextProps
78
+
79
+ | Prop | Type | Default | Description |
80
+ |------|------|---------|-------------|
81
+ | `text` | `string` | — | Text to render. Changes trigger a texture rebuild. |
82
+ | `fontSize` | `number` | `100` | Font size in pixels. |
83
+ | `color` | `string` | `'#ffffff'` | CSS colour string for the text. |
84
+ | `fontFamily` | `string` | `'sans-serif'` | Font family. |
85
+ | `fontWeight` | `string \| number` | `900` | Font weight. |
86
+ | `config` | `Partial<FluidConfig>` | — | Simulation config overrides. |
87
+ | `preset` | `PresetKey` | — | Named preset as base config. |
88
+ | `algorithm` | `FluidAlgorithm` | `'standard'` | Rendering algorithm (see below). |
89
+ | `backgroundColor` | `string` | `'#0a0a0a'` | CSS colour behind the canvas (shows through transparent areas). |
90
+ | `backgroundSrc` | `string` | — | URL/path composited as background behind text. |
91
+ | `backgroundSize` | `string \| number` | `'cover'` | Sizing mode for `backgroundSrc`. |
92
+ | `isMouseEnabled` | `boolean` | `true` | Auto-wire mouse/touch events. |
93
+ | `isWorkerEnabled` | `boolean` | `true` | Run in Web Worker via OffscreenCanvas. |
94
+ | `className` | `string` | — | Class applied to the container div. |
95
+ | `style` | `CSSProperties` | — | Inline styles merged on container div. |
96
+
97
+ ### FluidImageProps
98
+
99
+ All shared props (above) plus:
100
+
101
+ | Prop | Type | Default | Description |
102
+ |------|------|---------|-------------|
103
+ | `src` | `string` | — | Image URL. Changing reloads the simulation. |
104
+ | `effect` | `number` | `0.4` | Obstacle boundary strength (0–1). |
105
+ | `imageSize` | `string \| number` | `'cover'` | `'cover'` \| `'contain'` \| `'50%'` \| `'200px'` \| scale factor. |
106
+
107
+ ### FluidAlgorithm
108
+
109
+ | Value | Visual character |
110
+ |-------|-----------------|
111
+ | `'standard'` | Colour overlay blended over refracted background (default) |
112
+ | `'glass'` | Strong UV distortion only — bent-glass, no colour overlay |
113
+ | `'ink'` | Dense opaque pigment accumulates and stains |
114
+ | `'aurora'` | Velocity-field UV warp — liquid metal / lava-lamp |
115
+ | `'ripple'` | Exaggerated normals + Fresnel rim — calm water surface |
116
+
117
+ ```tsx
118
+ <FluidImage src="/photo.jpg" algorithm="aurora" />
119
+ <FluidText text="fluid" algorithm="ripple" config={{ warpStrength: 0.03 }} />
120
+ ```
121
+
122
+ ### FluidConfig
123
+
124
+ | Key | Type | Default | Description |
125
+ |-----|------|---------|-------------|
126
+ | `densityDissipation` | `number` | `0.992` | How long ink lingers (0–1). |
127
+ | `velocityDissipation` | `number` | `0.93` | How quickly velocity decays (0–1). |
128
+ | `pressureIterations` | `number` | `25` | Jacobi iterations — higher is more accurate but slower. |
129
+ | `curl` | `number` | `0.0001` | Vorticity confinement — swirl factor. Visible effect starts around `0.1`; `0.2`–`0.5` for strong swirl. |
130
+ | `splatRadius` | `number` | `0.004` | Brush radius. |
131
+ | `splatForce` | `number` | `0.91` | Force applied by brush. |
132
+ | `refraction` | `number` | `0.25` | Background warp / refraction strength. |
133
+ | `specularExp` | `number` | `1.01` | Specular highlight exponent. |
134
+ | `shine` | `number` | `0.01` | Highlight intensity. |
135
+ | `waterColor` | `[R, G, B]` | `[0, 0, 0]` | Base fluid colour (0–1 each). |
136
+ | `glowColor` | `[R, G, B]` | `[0.7, 0.85, 1.0]` | Glow / specular colour (0–1 each). |
137
+ | `algorithm` | `FluidAlgorithm` | `'standard'` | Display rendering algorithm. |
138
+ | `warpStrength` | `number` | `0.015` | UV warp intensity for the `aurora` algorithm. |
139
+
140
+ ---
141
+
142
+ ## FluidHandle (ref API)
143
+
144
+ ```tsx
145
+ const ref = useRef<FluidHandle>(null);
146
+ // ...
147
+ ref.current?.reset();
148
+ ref.current?.updateConfig({ shine: 0.05, curl: 0.2 });
149
+ ref.current?.updateLocation({ x: 200, y: 150, strength: 5 });
150
+ ```
151
+
152
+ | Method | Description |
153
+ |--------|-------------|
154
+ | `reset()` | Re-initialises simulation and reloads source. |
155
+ | `updateConfig(patch)` | Merges a partial config update into the running simulation. |
156
+ | `updateLocation({ x, y, strength? })` | Programmatic pointer input (coordinates relative to canvas). |
157
+
158
+ ---
159
+
160
+ ## Presets
161
+
162
+ Pass `preset="storm"` (or any key below) to use a named configuration bundle. Your own `config` props override preset values.
163
+
164
+ ```tsx
165
+ <FluidText text="wave" preset="wave" />
166
+ ```
167
+
168
+ | Preset | Description |
169
+ |--------|-------------|
170
+ | `calm` | Slow, peaceful drift |
171
+ | `storm` | Violent, turbulent chaos |
172
+ | `wave` | Rolling vortex eddies |
173
+ | `neon` | Vivid glowing highlights |
174
+ | `smoke` | Dense, rising smoke |
175
+
176
+ You can also import `PRESETS` directly:
177
+
178
+ ```ts
179
+ import { PRESETS } from 'fluidity-js';
180
+ // PRESETS.storm → Partial<FluidConfig>
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Browser support
186
+
187
+ | Feature | Support |
188
+ |---------|---------|
189
+ | WebGL2 | Required (Chrome 56+, Firefox 51+, Safari 15+) |
190
+ | WebGL1 | Automatic fallback |
191
+ | OffscreenCanvas + Worker | Chrome 69+, Firefox 105+ (auto-detected; falls back to main thread) |
192
+
193
+ ---
194
+
195
+ ## License
196
+
197
+ [MIT](./LICENSE)