@elementalfx/fluid 0.0.0-stage → 0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 aviyer42
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 CHANGED
@@ -1,3 +1,102 @@
1
- # Temporary Holding Version
1
+ # @elementalfx/fluid
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An interactive WebGL fluid simulation for the web: a smoke or ink trail that follows the cursor over your page, a slowly flowing background behind your content, or splashes fired from code.
4
+
5
+ About 9 KB gzipped including its runtime. Transparent where there's no dye, so your page shows through.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @elementalfx/fluid
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```js
16
+ import { createFluid } from '@elementalfx/fluid';
17
+
18
+ // A cursor trail over the whole page (pointer-events: none, never blocks clicks).
19
+ const trail = createFluid(document.body, { preset: 'smoke' });
20
+
21
+ // A living background behind a hero section's content.
22
+ const hero = createFluid('.hero', { preset: 'neon' });
23
+
24
+ // Splashes from code, e.g. when a button is clicked.
25
+ button.addEventListener('click', (event) => {
26
+ const rect = hero.element.getBoundingClientRect();
27
+ hero.burst(8, { x: event.clientX - rect.left, y: event.clientY - rect.top });
28
+ });
29
+ ```
30
+
31
+ ### HTML element
32
+
33
+ ```js
34
+ import '@elementalfx/fluid/element';
35
+ ```
36
+
37
+ ```html
38
+ <!-- Background behind the element's content -->
39
+ <fx-fluid preset="ink" style="height: 60vh">
40
+ <h1>Content stays on top</h1>
41
+ </fx-fluid>
42
+
43
+ <!-- Cursor trail over the whole page -->
44
+ <fx-fluid page preset="smoke"></fx-fluid>
45
+ ```
46
+
47
+ Attributes: `preset`, `mode`, `colors`, `brightness`, `dye-dissipation`, `velocity-dissipation`, `curl`, `splat-radius`, `splat-force`, `ambient`, `shading`, `opacity`, `quality`, `interactive`, `page`.
48
+
49
+ ### Script tag
50
+
51
+ ```html
52
+ <script src="https://unpkg.com/@elementalfx/fluid/dist/fluid.global.js"></script>
53
+ <script>
54
+ ElementalFX.fluid.createFluid(document.body, { preset: 'ink' });
55
+ </script>
56
+ ```
57
+
58
+ ## Presets
59
+
60
+ | Preset | Look |
61
+ | --- | --- |
62
+ | `ink` | Saturated, random hues that linger (default) |
63
+ | `smoke` | Soft white smoke that fades quickly; best on dark pages |
64
+ | `neon` | Bright cyan, magenta, lime and gold with strong swirls |
65
+
66
+ ## Options
67
+
68
+ | Option | Default | Description |
69
+ | --- | --- | --- |
70
+ | `preset` | `'ink'` | Starting values for the options below |
71
+ | `mode` | auto | `'cursor'` (page overlay) on `document.body`, `'background'` (behind content) elsewhere |
72
+ | `colors` | `'rainbow'` | Hex colors to pick from, or `'rainbow'` |
73
+ | `brightness` | `0.2` | Brightness of injected dye |
74
+ | `dyeDissipation` | `1` | How fast dye fades, per second |
75
+ | `velocityDissipation` | `0.2` | How fast motion fades, per second |
76
+ | `pressure` | `0.8` | Fraction of pressure kept between frames |
77
+ | `curl` | `30` | Swirl strength |
78
+ | `splatRadius` | `0.25` | Splat size relative to the area |
79
+ | `splatForce` | `6000` | How hard pointer movement pushes |
80
+ | `ambient` | `0` / `1` | Invisible strokes that keep it flowing on their own; 1 by default in background mode |
81
+ | `shading` | `1` | Soft 3D shading, 0 to 1 |
82
+ | `opacity` | `1` | Maximum opacity |
83
+ | `quality` | `'auto'` | `'low'`, `'medium'`, `'high'`, or `'auto'` (by device, stepping down if frames run below ~40 fps) |
84
+ | `interactive` | `true` | Pointer movement stirs the fluid |
85
+ | `zIndex` | `2147483000` | z-index of the cursor overlay |
86
+ | `respectReducedMotion` | `true` | Stay off when the user prefers reduced motion |
87
+ | `pauseOffscreen` | `true` | Stop animating out of view |
88
+ | `maxPixelRatio` | `2` | Cap on devicePixelRatio |
89
+
90
+ ## Methods
91
+
92
+ `splat(x, y, dx, dy, color?)`, `burst(count?, at?)`, `set(options)`, `clear()`, `pause()`, `play()`, `destroy()`, plus `ready`, `mode` and `quality`.
93
+
94
+ ## How it works
95
+
96
+ A grid solver after Jos Stam's *Stable Fluids* (SIGGRAPH 1999) and Mark Harris's *Fast Fluid Dynamics Simulation on the GPU* (GPU Gems, ch. 38), all on the GPU in half-float textures. Each frame it computes curl and adds vorticity confinement, solves for pressure with Jacobi iterations warm-started from the last frame, subtracts the pressure gradient so the flow stays incompressible, then moves velocity and dye along the flow. When nothing has moved for a few seconds it clears and stops drawing.
97
+
98
+ Inspired by Pavel Dobryakov's [WebGL Fluid Simulation](https://github.com/PavelDoGreat/WebGL-Fluid-Simulation) (MIT), whose parameter names and defaults this package follows so they feel familiar. The code here is a fresh implementation on the shared elementalfx WebGL toolkit.
99
+
100
+ Needs a GPU that can render to half-float textures; elsewhere `ready` resolves to `false` and nothing is drawn.
101
+
102
+ MIT License