@jayf0x/fluidity-js 0.1.5 β†’ 0.1.7

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/README.md CHANGED
@@ -1,56 +1,62 @@
1
- # fluidity-js
2
-
3
- **WebGL fluid simulation for React β€” interactive text and image effects powered by Navier-Stokes.**
1
+ # fluidity-js - πŸ”₯Upgrade your UXπŸ”₯
4
2
 
5
3
  [![npm](https://img.shields.io/npm/v/@jayf0x/fluidity-js)](https://www.npmjs.com/package/@jayf0x/fluidity-js)
6
4
  [![license](https://img.shields.io/npm/l/@jayf0x/fluidity-js)](./LICENSE)
7
5
  [![size](https://img.shields.io/bundlephobia/minzip/@jayf0x/fluidity-js)](https://bundlephobia.com/package/@jayf0x/fluidity-js)
8
6
 
9
- [**Live demo β†’**](https://jayf0x.github.io/fluidity)
10
-
11
- ---
7
+ <a href="https://jayf0x.github.io/fluidity">
8
+ <p align="center" title='Try if you can make this effect.'>
9
+ <img align="center" src="assets/preview.gif" alt="preview" height="300px"/>
10
+ </p>
12
11
 
13
- ## Install
12
+ <p align="center">
13
+ <strong>
14
+ Live demo β†’
15
+ </strong>
16
+ </p>
17
+ </a>
14
18
 
15
19
  ```bash
16
- npm i @jayf0x/fluidity-js
20
+ bun add @jayf0x/fluidity-js
21
+ yarn install @jayf0x/fluidity-js
22
+ pnpm install @jayf0x/fluidity-js
17
23
  ```
18
24
 
19
- Requires React β‰₯ 17 and WebGL (WebGL2 recommended; WebGL1 supported as fallback).
25
+ > uses latest `WebGPU` πŸ”₯ With WebGL2 or WebGL1 supported as fallback
20
26
 
21
27
  ---
22
28
 
23
- ## Usage
29
+ ## React examples
24
30
 
25
- ### FluidText
31
+ **FluidText:**
26
32
 
27
33
  ```tsx
28
34
  import { FluidText } from '@jayf0x/fluidity-js';
29
35
 
30
- export function Hero() {
36
+ export const FancyHero = () => {
31
37
  return (
32
38
  <div style={{ width: '100%', height: 300 }}>
33
- <FluidText text="hello" fontSize={120} color="#ffffff" />
39
+ <FluidText text="πŸ”₯ SupportsEmoji πŸ”₯" fontSize={120} color="#ffffff" />
34
40
  </div>
35
41
  );
36
- }
42
+ };
37
43
  ```
38
44
 
39
- ### FluidImage
45
+ **FluidImage:**
40
46
 
41
47
  ```tsx
42
48
  import { FluidImage } from '@jayf0x/fluidity-js';
43
49
 
44
50
  export function Cover() {
45
51
  return (
46
- <div style={{ width: '100%', height: '100vh' }}>
52
+ <div className="size-full">
47
53
  <FluidImage src="/hero.jpg" algorithm="aurora" />
48
54
  </div>
49
55
  );
50
56
  }
51
57
  ```
52
58
 
53
- ### Ref API
59
+ **Handle custom events with a ref**
54
60
 
55
61
  ```tsx
56
62
  import { useRef } from 'react';
@@ -58,13 +64,10 @@ import { useRef } from 'react';
58
64
  import { FluidText } from '@jayf0x/fluidity-js';
59
65
 
60
66
  export function Interactive() {
61
- const fluid = useRef<FluidHandle>(null);
62
-
67
+ const fluidRef = useRef<FluidHandle>(null);
63
68
  return (
64
69
  <>
65
- <div style={{ width: '100%', height: 300 }}>
66
- <FluidText ref={fluid} text="fluid" fontSize={120} color="#fff" />
67
- </div>
70
+ <FluidText ref={fluidRef} isMouseEnabled={false} text="Amazing" fontSize={120} color="#fff" />
68
71
  <button onClick={() => fluid.current?.reset()}>Reset</button>
69
72
  <button onClick={() => fluid.current?.updateConfig({ curl: 0.3 })}>Swirl</button>
70
73
  </>
@@ -72,9 +75,7 @@ export function Interactive() {
72
75
  }
73
76
  ```
74
77
 
75
- `FluidHandle` is a global type β€” no import needed.
76
-
77
- More examples β†’ [`demo/src/examples/`](./demo/src/examples/)
78
+ Official examples β†’ [`demo/src/examples/`](./demo/src/examples/)
78
79
 
79
80
  ---
80
81
 
@@ -100,18 +101,19 @@ More examples β†’ [`demo/src/examples/`](./demo/src/examples/)
100
101
 
101
102
  ### Shared props
102
103
 
103
- | Prop | Type | Default |
104
- | ----------------- | ---------------------- | ------------ |
105
- | `config` | `Partial<FluidConfig>` | β€” |
106
- | `preset` | `PresetKey` | β€” |
107
- | `algorithm` | `FluidAlgorithm` | `'standard'` |
108
- | `backgroundColor` | `string` | `'#0a0a0a'` |
109
- | `backgroundSrc` | `string` | β€” |
110
- | `backgroundSize` | `string \| number` | `'cover'` |
111
- | `isMouseEnabled` | `boolean` | `true` |
112
- | `isWorkerEnabled` | `boolean` | `true` |
113
- | `className` | `string` | β€” |
114
- | `style` | `CSSProperties` | β€” |
104
+ | Prop | Type | Default |
105
+ | ----------------- | ---------------------- | ---------------------- |
106
+ | `config` | `Partial<FluidConfig>` | β€” |
107
+ | `preset` | `PresetKey` | β€” |
108
+ | `algorithm` | `FluidAlgorithm` | `'standard'` |
109
+ | `quality` | `FluidQuality` | `{ dpr: 1, sim: 0.5 }` |
110
+ | `backgroundColor` | `string` | `'#0a0a0a'` |
111
+ | `backgroundSrc` | `string` | β€” |
112
+ | `backgroundSize` | `string \| number` | `'cover'` |
113
+ | `isMouseEnabled` | `boolean` | `true` |
114
+ | `isWorkerEnabled` | `boolean` | `true` |
115
+ | `className` | `string` | β€” |
116
+ | `style` | `CSSProperties` | β€” |
115
117
 
116
118
  ---
117
119
 
@@ -132,6 +134,31 @@ More examples β†’ [`demo/src/examples/`](./demo/src/examples/)
132
134
 
133
135
  ---
134
136
 
137
+ ## Quality
138
+
139
+ `quality` controls rendering resolution on two independent axes. Both props are reactive β€” you can adjust them at runtime.
140
+
141
+ | Field | Range | Default | Description |
142
+ | ----- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
143
+ | `dpr` | 0.1 – 1 | `1` | Canvas backing resolution as a fraction of `devicePixelRatio`. `0.5` on a Retina screen renders at 1Γ— instead of 2Γ—, saving ~75% fill rate. |
144
+ | `sim` | 0.1 – 1 | `0.5` | Simulation FBO size as a fraction of canvas size. Lower = cheaper GPU, less fluid detail. |
145
+
146
+ ```tsx
147
+ <FluidText text="hello" quality={{ dpr: 0.75, sim: 0.25 }} />
148
+ ```
149
+
150
+ `dpr` and `sim` are independent β€” you can run a sharp canvas at a coarser simulation:
151
+
152
+ ```tsx
153
+ // Sharp display, cheap simulation
154
+ <FluidImage src="/hero.jpg" quality={{ dpr: 1, sim: 0.2 }} />
155
+
156
+ // Lower display res, full simulation quality
157
+ <FluidImage src="/hero.jpg" quality={{ dpr: 0.5, sim: 1 }} />
158
+ ```
159
+
160
+ ---
161
+
135
162
  ## FluidConfig
136
163
 
137
164
  | Key | Default | Description |
package/dist/globals.d.ts CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  type FluidAlgorithm = 'standard' | 'glass' | 'ink' | 'aurora' | 'ripple';
4
4
 
5
+ /**
6
+ * Granular performance/quality controls. Both axes are independent β€” you can
7
+ * run a sharp display at a coarser simulation, or vice versa.
8
+ * Reactive: changes after mount are applied on the next animation frame.
9
+ */
10
+ interface FluidQuality {
11
+ /** devicePixelRatio multiplier for canvas backing resolution. Range [0.1, 1]. Default 1 (native). On Retina, 0.5 β†’ 1Γ— pixels (75% less fill). */
12
+ dpr?: number;
13
+ /** Simulation FBO size as a fraction of canvas size. Range [0.1, 1]. Default 0.5 (current behavior). Higher = more fluid detail, more GPU. */
14
+ sim?: number;
15
+ }
16
+
5
17
  interface FluidConfig {
6
18
  densityDissipation: number;
7
19
  velocityDissipation: number;
@@ -22,8 +34,8 @@ type PresetKey = 'calm' | 'sand' | 'wave' | 'neon' | 'smoke';
22
34
 
23
35
  interface FluidHandle {
24
36
  reset(): void;
25
- move(opts: { x: number; y: number; strength?: number }): void;
26
- splat(x: number, y: number, vx: number, vy: number, strength?: number): void;
37
+ move(x: number, y: number, strength?: number): void;
38
+ splat(x: number, y: number, velocityX: number, velocityY: number, strength?: number): void;
27
39
  updateConfig(config: Partial<FluidConfig>): void;
28
40
  }
29
41
 
@@ -33,6 +45,7 @@ interface FluidBaseProps {
33
45
  config?: Partial<FluidConfig>;
34
46
  isMouseEnabled?: boolean;
35
47
  isWorkerEnabled?: boolean;
48
+ quality?: FluidQuality;
36
49
  preset?: PresetKey;
37
50
  algorithm?: FluidAlgorithm;
38
51
  backgroundColor?: string;