@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 CHANGED
@@ -4,59 +4,61 @@
4
4
  [![license](https://img.shields.io/npm/l/@jayf0x/fluidity-js)](./LICENSE)
5
5
  [![size](https://img.shields.io/bundlephobia/minzip/@jayf0x/fluidity-js)](https://bundlephobia.com/package/@jayf0x/fluidity-js)
6
6
 
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>
11
-
7
+ <a href="https://raw.githubusercontent.com/jayf0x/fluidity/main/assets/preview.gif">
12
8
  <p align="center">
13
- <strong>
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
- yarn install @jayf0x/fluidity-js
22
- pnpm install @jayf0x/fluidity-js
16
+ # or: npm install / yarn add / pnpm add
23
17
  ```
24
18
 
25
- > uses latest `WebGPU` 🔥 With WebGL2 or WebGL1 supported as fallback
19
+ > **WebGPU-first** 🔥 falls back automatically to WebGL2 / WebGL1.
26
20
 
27
21
  ---
28
22
 
29
23
  ## React examples
30
24
 
31
- **FluidText:**
25
+ **Text that moves with your cursor:**
32
26
 
33
27
  ```tsx
34
28
  import { FluidText } from '@jayf0x/fluidity-js';
35
29
 
36
- export const FancyHero = () => {
30
+ export function Hero() {
37
31
  return (
38
- <div style={{ width: '100%', height: 300 }}>
39
- <FluidText text="🔥 SupportsEmoji 🔥" fontSize={120} color="#ffffff" />
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
- **FluidImage:**
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 className="size-full">
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
- **Handle custom events with a ref**
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 fluidRef = useRef<FluidHandle>(null);
69
+ const fluid = useRef<FluidHandle>(null);
70
+
68
71
  return (
69
72
  <>
70
- <FluidText ref={fluidRef} isMouseEnabled={false} text="Amazing" fontSize={120} color="#fff" />
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: [number, number, number];
28
- glowColor: [number, number, number];
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 {