@jayf0x/fluidity-js 0.1.7 → 0.2.2
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 +29 -22
- package/dist/globals.d.ts +11 -2
- package/dist/index.js +1464 -527
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -4,59 +4,61 @@
|
|
|
4
4
|
[](./LICENSE)
|
|
5
5
|
[](https://bundlephobia.com/package/@jayf0x/fluidity-js)
|
|
6
6
|
|
|
7
|
-
|
|
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>
|
|
11
|
-
|
|
7
|
+
<a href="https://raw.githubusercontent.com/jayf0x/fluidity/main/assets/preview.gif">
|
|
12
8
|
<p align="center">
|
|
13
|
-
<
|
|
14
|
-
Live demo →
|
|
15
|
-
</strong>
|
|
9
|
+
<img src="assets/preview.gif" alt="preview" height="300px"/>
|
|
16
10
|
</p>
|
|
11
|
+
<p align="center"><strong>Live demo →</strong></p>
|
|
17
12
|
</a>
|
|
18
13
|
|
|
19
14
|
```bash
|
|
20
15
|
bun add @jayf0x/fluidity-js
|
|
21
|
-
|
|
22
|
-
pnpm install @jayf0x/fluidity-js
|
|
16
|
+
# or: npm install / yarn add / pnpm add
|
|
23
17
|
```
|
|
24
18
|
|
|
25
|
-
>
|
|
19
|
+
> **WebGPU-first** 🔥 — falls back automatically to WebGL2 / WebGL1.
|
|
26
20
|
|
|
27
21
|
---
|
|
28
22
|
|
|
29
23
|
## React examples
|
|
30
24
|
|
|
31
|
-
**
|
|
25
|
+
**Text that moves with your cursor:**
|
|
32
26
|
|
|
33
27
|
```tsx
|
|
34
28
|
import { FluidText } from '@jayf0x/fluidity-js';
|
|
35
29
|
|
|
36
|
-
export
|
|
30
|
+
export function Hero() {
|
|
37
31
|
return (
|
|
38
|
-
<div style={{ width: '100%', height:
|
|
39
|
-
<FluidText text="
|
|
32
|
+
<div style={{ width: '100%', height: 400 }}>
|
|
33
|
+
<FluidText text="Hello World" fontSize={140} color="#ffffff" />
|
|
40
34
|
</div>
|
|
41
35
|
);
|
|
42
|
-
}
|
|
36
|
+
}
|
|
43
37
|
```
|
|
44
38
|
|
|
45
|
-
**
|
|
39
|
+
**Full-bleed image cover — one line to make it alive:**
|
|
46
40
|
|
|
47
41
|
```tsx
|
|
48
42
|
import { FluidImage } from '@jayf0x/fluidity-js';
|
|
49
43
|
|
|
50
44
|
export function Cover() {
|
|
51
45
|
return (
|
|
52
|
-
<div
|
|
46
|
+
<div style={{ width: '100%', height: '100vh' }}>
|
|
53
47
|
<FluidImage src="/hero.jpg" algorithm="aurora" />
|
|
54
48
|
</div>
|
|
55
49
|
);
|
|
56
50
|
}
|
|
57
51
|
```
|
|
58
52
|
|
|
59
|
-
**
|
|
53
|
+
**Go further — presets, algorithms, live config:**
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
<FluidText text="Wicked" preset="neon" algorithm="glass" />
|
|
57
|
+
<FluidImage src="/poster.jpg" algorithm="ripple" config={{ curl: 0.4, splatRadius: 0.008 }} />
|
|
58
|
+
<FluidText text="Chill" preset="calm" quality={{ dpr: 1, sim: 0.75 }} />
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Trigger effects programmatically:**
|
|
60
62
|
|
|
61
63
|
```tsx
|
|
62
64
|
import { useRef } from 'react';
|
|
@@ -64,12 +66,16 @@ import { useRef } from 'react';
|
|
|
64
66
|
import { FluidText } from '@jayf0x/fluidity-js';
|
|
65
67
|
|
|
66
68
|
export function Interactive() {
|
|
67
|
-
const
|
|
69
|
+
const fluid = useRef<FluidHandle>(null);
|
|
70
|
+
|
|
68
71
|
return (
|
|
69
72
|
<>
|
|
70
|
-
<
|
|
73
|
+
<div style={{ width: '100%', height: 400 }}>
|
|
74
|
+
<FluidText ref={fluid} text="Touch me" fontSize={120} color="#fff" />
|
|
75
|
+
</div>
|
|
76
|
+
<button onClick={() => fluid.current?.splat(200, 200, 8, -4)}>Splat</button>
|
|
77
|
+
<button onClick={() => fluid.current?.updateConfig({ curl: 0.5 })}>Swirl</button>
|
|
71
78
|
<button onClick={() => fluid.current?.reset()}>Reset</button>
|
|
72
|
-
<button onClick={() => fluid.current?.updateConfig({ curl: 0.3 })}>Swirl</button>
|
|
73
79
|
</>
|
|
74
80
|
);
|
|
75
81
|
}
|
|
@@ -112,6 +118,7 @@ Official examples → [`demo/src/examples/`](./demo/src/examples/)
|
|
|
112
118
|
| `backgroundSize` | `string \| number` | `'cover'` |
|
|
113
119
|
| `isMouseEnabled` | `boolean` | `true` |
|
|
114
120
|
| `isWorkerEnabled` | `boolean` | `true` |
|
|
121
|
+
| `useWebGPU` | `boolean` | `true` |
|
|
115
122
|
| `className` | `string` | — |
|
|
116
123
|
| `style` | `CSSProperties` | — |
|
|
117
124
|
|
package/dist/globals.d.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
type FluidAlgorithm = 'standard' | 'glass' | 'ink' | 'aurora' | 'ripple';
|
|
4
4
|
|
|
5
|
+
/** RGB tuple (values 0–1) or a CSS hex string (#RGB, #RRGGBB, #RRGGBBAA — alpha stripped). */
|
|
6
|
+
type FluidColor = [number, number, number] | `#${string}`;
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Granular performance/quality controls. Both axes are independent — you can
|
|
7
10
|
* run a sharp display at a coarser simulation, or vice versa.
|
|
@@ -24,8 +27,8 @@ interface FluidConfig {
|
|
|
24
27
|
refraction: number;
|
|
25
28
|
specularExp: number;
|
|
26
29
|
shine: number;
|
|
27
|
-
waterColor:
|
|
28
|
-
glowColor:
|
|
30
|
+
waterColor: FluidColor;
|
|
31
|
+
glowColor: FluidColor;
|
|
29
32
|
algorithm: FluidAlgorithm;
|
|
30
33
|
warpStrength: number;
|
|
31
34
|
}
|
|
@@ -40,7 +43,9 @@ interface FluidHandle {
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
interface FluidBaseProps {
|
|
46
|
+
/** Will apply to canvas container */
|
|
43
47
|
className?: string;
|
|
48
|
+
/** Will apply to canvas container */
|
|
44
49
|
style?: React.CSSProperties;
|
|
45
50
|
config?: Partial<FluidConfig>;
|
|
46
51
|
isMouseEnabled?: boolean;
|
|
@@ -51,6 +56,10 @@ interface FluidBaseProps {
|
|
|
51
56
|
backgroundColor?: string;
|
|
52
57
|
backgroundSrc?: string;
|
|
53
58
|
backgroundSize?: string | number;
|
|
59
|
+
/** enabled greater performance, but not every browser supports it */
|
|
60
|
+
useWebGPU?: boolean;
|
|
61
|
+
/** Enable transparent canvas (default true). Set false for a minor perf gain when transparency is not needed. */
|
|
62
|
+
enableAlpha?: boolean;
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
interface FluidTextProps extends FluidBaseProps {
|