@firecms/neat 0.3.0 → 0.5.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/README.md CHANGED
@@ -1,28 +1,28 @@
1
1
  # Neat gradients
2
2
 
3
- Create awesome 3d gradients with this library based on three.js.
3
+ Create awesome 3D gradients with this library based on three.js.
4
4
 
5
5
  Check the demo and gradients editor to find your perfect config here:
6
6
  [https://neat.firecms.co/](https://neat.firecms.co/)
7
7
 
8
8
  Neat is released under the CC license, so you can use it for free in your projects,
9
9
  commercial or not. You can also modify it and redistribute it, but you must keep
10
- the license and the credits.
10
+ the license and the credits.
11
11
 
12
12
 
13
- ## Installation:
13
+ ## Installation
14
14
 
15
- ```
16
- yarn install @firecms/neat three.js
15
+ ```bash
16
+ yarn add @firecms/neat three
17
17
  ```
18
18
 
19
19
  or
20
20
 
21
- ```
22
- npm install @firecms/neat three.js
21
+ ```bash
22
+ npm install @firecms/neat three
23
23
  ```
24
24
 
25
- ## Usage:
25
+ ## Usage
26
26
 
27
27
  You can use the library to create a gradient in your website or application. You need to define a config and then
28
28
  create a new `NeatGradient` instance. You are encouraged to use the [gradients editor](https://neat.firecms.co/) to
@@ -58,19 +58,20 @@ export const config: NeatConfig = {
58
58
  enabled: false
59
59
  }
60
60
  ],
61
- speed: 4, // from 0 to 10
62
- horizontalPressure: 4, // from 0 to 10
63
- verticalPressure: 5, // from 0 to 10
64
- waveFrequencyX: 2, // from 0 to 10
65
- waveFrequencyY: 3, // from 0 to 10
66
- waveAmplitude: 5, // from 0 to 10
67
- shadows: 0, // from 0 to 10
68
- highlights: 2, // from 0 to 10
69
- saturation: 7, // from -10 to 10
61
+ speed: 4,
62
+ horizontalPressure: 4,
63
+ verticalPressure: 5,
64
+ waveFrequencyX: 2,
65
+ waveFrequencyY: 3,
66
+ waveAmplitude: 5,
67
+ shadows: 0,
68
+ highlights: 2,
69
+ colorSaturation: 7,
70
+ colorBrightness: 1,
70
71
  wireframe: false,
71
- colorBlending: 6, // from 0 to 10
72
+ colorBlending: 6,
72
73
  backgroundColor: "#003FFF",
73
- backgroundAlpha: 1 // from 0 to 1
74
+ backgroundAlpha: 1
74
75
  };
75
76
 
76
77
 
@@ -90,67 +91,47 @@ neat.destroy();
90
91
 
91
92
  ### React example
92
93
 
93
- ```tsx
94
- import React, { useEffect, useRef, useState } from "react";
95
- import { NeatConfig, NeatGradient } from "@firecms/neat";
94
+ ```tsx
95
+ import React, { useEffect, useRef } from "react";
96
+ import { NeatGradient } from "@firecms/neat";
96
97
 
97
98
  export const MyComponent: React.FC = () => {
98
-
99
99
  const canvasRef = useRef<HTMLCanvasElement | null>(null);
100
- const gradientRef = useRef<NeatGradient | null>(null);
101
100
 
102
101
  useEffect(() => {
102
+ if (!canvasRef.current) return;
103
103
 
104
- if (!canvasRef.current)
105
- return;
106
-
107
- gradientRef.current = new NeatGradient({
104
+ const gradient = new NeatGradient({
108
105
  ref: canvasRef.current,
109
- "colors": [
110
- {
111
- "color": "#FF5373",
112
- "enabled": true
113
- },
114
- {
115
- "color": "#FFC858",
116
- "enabled": true
117
- },
118
- {
119
- "color": "#05d5ef",
120
- "enabled": true
121
- },
122
- {
123
- "color": "#6D3BFF",
124
- "enabled": true
125
- },
126
- {
127
- "color": "#f5e1e5",
128
- "enabled": false
129
- }
106
+ colors: [
107
+ { color: "#FF5373", enabled: true },
108
+ { color: "#FFC858", enabled: true },
109
+ { color: "#05d5ef", enabled: true },
110
+ { color: "#6D3BFF", enabled: true },
111
+ { color: "#f5e1e5", enabled: false }
130
112
  ],
131
- "speed": 4,
132
- "horizontalPressure": 4,
133
- "verticalPressure": 5,
134
- "waveFrequencyX": 2,
135
- "waveFrequencyY": 3,
136
- "waveAmplitude": 5,
137
- "shadows": 0,
138
- "highlights": 1,
139
- "colorSaturation": 0,
140
- "colorBrightness": 1,
141
- "wireframe": true,
142
- "colorBlending": 6,
143
- "backgroundAlpha": 0,
144
- "resolution": 1 / 2
113
+ speed: 4,
114
+ horizontalPressure: 4,
115
+ verticalPressure: 5,
116
+ waveFrequencyX: 2,
117
+ waveFrequencyY: 3,
118
+ waveAmplitude: 5,
119
+ shadows: 0,
120
+ highlights: 1,
121
+ colorSaturation: 0,
122
+ colorBrightness: 1,
123
+ wireframe: false,
124
+ colorBlending: 6,
125
+ backgroundColor: "#003FFF",
126
+ backgroundAlpha: 1,
127
+ resolution: 0.5
145
128
  });
146
129
 
147
- return gradientRef.current.destroy;
148
-
149
- }, [canvasRef.current]);
130
+ return gradient.destroy;
131
+ }, []);
150
132
 
151
133
  return (
152
134
  <canvas
153
- className={bgColor}
154
135
  style={{
155
136
  isolation: "isolate",
156
137
  height: "100%",
@@ -162,7 +143,323 @@ export const MyComponent: React.FC = () => {
162
143
  };
163
144
  ```
164
145
 
146
+ ## Configuration Parameters
147
+
148
+ ### Required Parameters
149
+
150
+ #### `ref`
151
+ - **Type:** `HTMLCanvasElement`
152
+ - **Description:** The canvas element where the gradient will be rendered
153
+ - **Required:** Yes
154
+
155
+ #### `colors`
156
+ - **Type:** `NeatColor[]`
157
+ - **Description:** Array of color objects that define the gradient palette
158
+ - **Required:** Yes
159
+ - **Color Object Properties:**
160
+ - `color` (string): Hex color value (e.g., "#FF5373")
161
+ - `enabled` (boolean): Whether the color is active in the gradient
162
+ - `influence` (number, optional): Value from 0 to 1 controlling color strength
163
+
164
+ ### Animation Parameters
165
+
166
+ #### `speed`
167
+ - **Type:** `number`
168
+ - **Range:** 0 to 10
169
+ - **Default:** 4
170
+ - **Description:** Animation speed. Set to 0 to pause all animations (waves and flow).
171
+
172
+ ### Color Pressure Parameters
173
+ *Note: These are disabled when `enableProceduralTexture` is true*
174
+
175
+ #### `horizontalPressure`
176
+ - **Type:** `number`
177
+ - **Range:** 0 to 10
178
+ - **Default:** 3
179
+ - **Description:** Horizontal color distribution intensity
180
+
181
+ #### `verticalPressure`
182
+ - **Type:** `number`
183
+ - **Range:** 0 to 10
184
+ - **Default:** 3
185
+ - **Description:** Vertical color distribution intensity
186
+
187
+ #### `colorBlending`
188
+ - **Type:** `number`
189
+ - **Range:** 0 to 10
190
+ - **Default:** 5
191
+ - **Description:** How smoothly colors blend together
192
+
193
+ ### Wave Parameters
194
+ *Note: Requires `speed > 0` to be visible*
195
+
196
+ #### `waveFrequencyX`
197
+ - **Type:** `number`
198
+ - **Range:** 0 to 10
199
+ - **Default:** 5
200
+ - **Description:** Horizontal wave frequency
201
+
202
+ #### `waveFrequencyY`
203
+ - **Type:** `number`
204
+ - **Range:** 0 to 10
205
+ - **Default:** 5
206
+ - **Description:** Vertical wave frequency
207
+
208
+ #### `waveAmplitude`
209
+ - **Type:** `number`
210
+ - **Range:** 0 to 10
211
+ - **Default:** 3
212
+ - **Description:** Wave height/intensity
213
+
214
+ ### Visual Effects Parameters
215
+
216
+ #### `shadows`
217
+ - **Type:** `number`
218
+ - **Range:** 0 to 10
219
+ - **Default:** 4
220
+ - **Description:** Intensity of shadow effects
221
+
222
+ #### `highlights`
223
+ - **Type:** `number`
224
+ - **Range:** 0 to 10
225
+ - **Default:** 4
226
+ - **Description:** Intensity of highlight effects
227
+
228
+ #### `colorSaturation`
229
+ - **Type:** `number`
230
+ - **Range:** -10 to 10
231
+ - **Default:** 0
232
+ - **Description:** Color saturation adjustment (negative values desaturate)
233
+
234
+ #### `colorBrightness`
235
+ - **Type:** `number`
236
+ - **Range:** 0 to 10
237
+ - **Default:** 1
238
+ - **Description:** Overall brightness multiplier
239
+
240
+ ### Grain Parameters
241
+
242
+ #### `grainIntensity`
243
+ - **Type:** `number`
244
+ - **Range:** 0 to 1
245
+ - **Default:** 0.55
246
+ - **Description:** Strength of film grain effect. Set to 0 to disable grain.
247
+
248
+ #### `grainScale`
249
+ - **Type:** `number`
250
+ - **Range:** 0 to 100
251
+ - **Default:** 2
252
+ - **Description:** Size of grain particles
253
+
254
+ #### `grainSparsity`
255
+ - **Type:** `number`
256
+ - **Range:** 0 to 1
257
+ - **Default:** 0.0
258
+ - **Description:** How sparse/scattered the grain appears
259
+
260
+ #### `grainSpeed`
261
+ - **Type:** `number`
262
+ - **Range:** 0 to 10
263
+ - **Default:** 0.1
264
+ - **Description:** Animation speed of grain particles
265
+
266
+ ### Shape Parameters
267
+
268
+ #### `resolution`
269
+ - **Type:** `number`
270
+ - **Range:** 0.05 to 2
271
+ - **Default:** 1
272
+ - **Description:** Mesh density/quality. Lower values improve performance but reduce visual quality.
273
+
274
+ #### `wireframe`
275
+ - **Type:** `boolean`
276
+ - **Default:** false
277
+ - **Description:** Show the 3D mesh structure. When enabled, colors, grain, and texture effects are less visible.
278
+
279
+ #### `yOffset`
280
+ - **Type:** `number`
281
+ - **Range:** 0 to 100000
282
+ - **Default:** 0
283
+ - **Description:** Vertical offset for scroll-based effects
284
+
285
+ #### `yOffsetWaveMultiplier`
286
+ - **Type:** `number`
287
+ - **Range:** 0 to 20
288
+ - **Default:** 4
289
+ - **Description:** How much vertical offset affects wave animation
290
+
291
+ #### `yOffsetColorMultiplier`
292
+ - **Type:** `number`
293
+ - **Range:** 0 to 20
294
+ - **Default:** 4
295
+ - **Description:** How much vertical offset affects color distribution
296
+
297
+ #### `yOffsetFlowMultiplier`
298
+ - **Type:** `number`
299
+ - **Range:** 0 to 20
300
+ - **Default:** 4
301
+ - **Description:** How much vertical offset affects flow field
302
+
303
+ ### Background Parameters
304
+
305
+ #### `backgroundColor`
306
+ - **Type:** `string`
307
+ - **Default:** "#FFFFFF"
308
+ - **Description:** Hex color for the background
309
+
310
+ #### `backgroundAlpha`
311
+ - **Type:** `number`
312
+ - **Range:** 0 to 1
313
+ - **Default:** 1.0
314
+ - **Description:** Background opacity (0 = transparent, 1 = opaque)
315
+
316
+ ### Flow Field Parameters
317
+ *Note: Requires `speed > 0` and `flowEnabled: true`*
318
+
319
+ #### `flowEnabled`
320
+ - **Type:** `boolean`
321
+ - **Default:** true
322
+ - **Description:** Enable/disable flow field distortion
323
+
324
+ #### `flowDistortionA`
325
+ - **Type:** `number`
326
+ - **Range:** 0 to 5
327
+ - **Default:** 0
328
+ - **Description:** Wave amplitude for flow distortion
329
+
330
+ #### `flowDistortionB`
331
+ - **Type:** `number`
332
+ - **Range:** 0 to 10
333
+ - **Default:** 0
334
+ - **Description:** Wave frequency for flow distortion
335
+
336
+ #### `flowScale`
337
+ - **Type:** `number`
338
+ - **Range:** 0 to 5
339
+ - **Default:** 1.0
340
+ - **Description:** Scale of the flow field waves
341
+
342
+ #### `flowEase`
343
+ - **Type:** `number`
344
+ - **Range:** 0 to 1
345
+ - **Default:** 0.0
346
+ - **Description:** Blend between original and flow-distorted state
347
+
348
+ ### Mouse Interaction Parameters
349
+
350
+ #### `mouseDistortionStrength`
351
+ - **Type:** `number`
352
+ - **Range:** 0 to 2.0
353
+ - **Default:** 0.0
354
+ - **Description:** Strength of mouse-driven distortion. Set to 0 to disable.
355
+
356
+ #### `mouseDistortionRadius`
357
+ - **Type:** `number`
358
+ - **Range:** 0.05 to 2.0
359
+ - **Default:** 0.25
360
+ - **Description:** Radius/area of mouse distortion effect
361
+
362
+ #### `mouseDecayRate`
363
+ - **Type:** `number`
364
+ - **Range:** 0.90 to 0.99
365
+ - **Default:** 0.96
366
+ - **Description:** How quickly mouse trails fade (0.9 = slow/wobbly, 0.99 = fast/sharp)
367
+
368
+ #### `mouseDarken`
369
+ - **Type:** `number`
370
+ - **Range:** 0 to 1
371
+ - **Default:** 0.0
372
+ - **Description:** Darkening effect at mouse interaction points
373
+
374
+ ### Procedural Texture Parameters
375
+ *Note: When enabled, replaces color pressure controls*
376
+
377
+ #### `enableProceduralTexture`
378
+ - **Type:** `boolean`
379
+ - **Default:** false
380
+ - **Description:** Enable procedurally generated texture overlay
381
+
382
+ #### `textureVoidLikelihood`
383
+ - **Type:** `number`
384
+ - **Range:** 0 to 1
385
+ - **Default:** 0.45
386
+ - **Description:** Frequency of gaps/voids in texture bands
387
+
388
+ #### `textureVoidWidthMin`
389
+ - **Type:** `number`
390
+ - **Range:** 10 to 200
391
+ - **Default:** 200
392
+ - **Description:** Minimum width of texture gaps in pixels
393
+
394
+ #### `textureVoidWidthMax`
395
+ - **Type:** `number`
396
+ - **Range:** 50 to 600
397
+ - **Default:** 486
398
+ - **Description:** Maximum width of texture gaps in pixels
399
+
400
+ #### `textureBandDensity`
401
+ - **Type:** `number`
402
+ - **Range:** 0.1 to 3
403
+ - **Default:** 2.15
404
+ - **Description:** Density of texture bands
405
+
406
+ #### `textureColorBlending`
407
+ - **Type:** `number`
408
+ - **Range:** 0 to 1
409
+ - **Default:** 0.01
410
+ - **Description:** Color blending within texture
411
+
412
+ #### `textureSeed`
413
+ - **Type:** `number`
414
+ - **Range:** 0 to 1000
415
+ - **Default:** 333
416
+ - **Description:** Random seed for texture generation (change for different patterns)
417
+
418
+ #### `textureEase`
419
+ - **Type:** `number`
420
+ - **Range:** 0 to 1
421
+ - **Default:** 0.5
422
+ - **Description:** Blend between flow field and procedural texture (0 = flow, 1 = texture)
423
+
424
+ #### `proceduralBackgroundColor`
425
+ - **Type:** `string`
426
+ - **Default:** "#000000"
427
+ - **Description:** Hex color for texture void/gap areas
428
+
429
+ #### `textureShapeTriangles`
430
+ - **Type:** `number`
431
+ - **Range:** 0 to 100
432
+ - **Default:** 20
433
+ - **Description:** Number of triangle shapes in texture
434
+
435
+ #### `textureShapeCircles`
436
+ - **Type:** `number`
437
+ - **Range:** 0 to 100
438
+ - **Default:** 15
439
+ - **Description:** Number of circle shapes in texture
440
+
441
+ #### `textureShapeBars`
442
+ - **Type:** `number`
443
+ - **Range:** 0 to 100
444
+ - **Default:** 15
445
+ - **Description:** Number of bar shapes in texture
446
+
447
+ #### `textureShapeSquiggles`
448
+ - **Type:** `number`
449
+ - **Range:** 0 to 100
450
+ - **Default:** 10
451
+ - **Description:** Number of squiggle/wavy shapes in texture
452
+
453
+ ## Tips
454
+
455
+ - Use the [online editor](https://neat.firecms.co/) to visually design your gradient and export the configuration
456
+ - Start with lower `resolution` values (0.5-1.0) for better performance, especially on mobile devices
457
+ - Set `speed: 0` to create static gradients without animation
458
+ - Combine `yOffset` with scroll position for scroll-based gradient effects
459
+ - Enable `wireframe: true` during development to understand the 3D mesh structure
460
+ - Procedural textures work best with `textureEase` values between 0.3 and 0.7
461
+ - For subtle effects, keep `mouseDistortionStrength` below 0.5
165
462
 
166
- ### NEAT link
463
+ ## NEAT Link
167
464
 
168
465
  If you want to remove the NEAT link, you can reach us at hello@firecms.co
@@ -22,10 +22,40 @@ export type NeatConfig = {
22
22
  colorBlending?: number;
23
23
  grainScale?: number;
24
24
  grainIntensity?: number;
25
+ grainSparsity?: number;
25
26
  grainSpeed?: number;
26
27
  wireframe?: boolean;
27
28
  backgroundColor?: string;
28
29
  backgroundAlpha?: number;
30
+ yOffset?: number;
31
+ yOffsetWaveMultiplier?: number;
32
+ yOffsetColorMultiplier?: number;
33
+ yOffsetFlowMultiplier?: number;
34
+ flowDistortionA?: number;
35
+ flowDistortionB?: number;
36
+ flowScale?: number;
37
+ flowEase?: number;
38
+ flowEnabled?: boolean;
39
+ /** Strength of mouse-driven distortion */
40
+ mouseDistortionStrength?: number;
41
+ /** Radius / area of mouse-driven distortion in UV space (0–1-ish) */
42
+ mouseDistortionRadius?: number;
43
+ /** How quickly mouse trails decay/fade (0.9=slow/wobbly, 0.99=fast/sharp) */
44
+ mouseDecayRate?: number;
45
+ mouseDarken?: number;
46
+ enableProceduralTexture?: boolean;
47
+ textureVoidLikelihood?: number;
48
+ textureVoidWidthMin?: number;
49
+ textureVoidWidthMax?: number;
50
+ textureBandDensity?: number;
51
+ textureColorBlending?: number;
52
+ textureSeed?: number;
53
+ textureEase?: number;
54
+ proceduralBackgroundColor?: string;
55
+ textureShapeTriangles?: number;
56
+ textureShapeCircles?: number;
57
+ textureShapeBars?: number;
58
+ textureShapeSquiggles?: number;
29
59
  };
30
60
  export type NeatColor = {
31
61
  color: string;
@@ -52,21 +82,60 @@ export declare class NeatGradient implements NeatController {
52
82
  private _brightness;
53
83
  private _grainScale;
54
84
  private _grainIntensity;
85
+ private _grainSparsity;
55
86
  private _grainSpeed;
56
87
  private _colorBlending;
57
88
  private _colors;
58
89
  private _wireframe;
59
90
  private _backgroundColor;
60
91
  private _backgroundAlpha;
92
+ private _flowDistortionA;
93
+ private _flowDistortionB;
94
+ private _flowScale;
95
+ private _flowEase;
96
+ private _flowEnabled;
97
+ private _mouseDistortionStrength;
98
+ private _mouseDistortionRadius;
99
+ private _mouseDecayRate;
100
+ private _mouseDarken;
101
+ private _mouse;
102
+ private _mouseFBO;
103
+ private _sceneMouse;
104
+ private _cameraMouse;
105
+ private _mouseObjects;
106
+ private _currentBrush;
107
+ private _mouseBrushBaseScale;
108
+ private _enableProceduralTexture;
109
+ private _textureVoidLikelihood;
110
+ private _textureVoidWidthMin;
111
+ private _textureVoidWidthMax;
112
+ private _textureBandDensity;
113
+ private _textureColorBlending;
114
+ private _textureSeed;
115
+ private _textureEase;
116
+ private _proceduralTexture;
117
+ private _proceduralBackgroundColor;
118
+ private _textureShapeTriangles;
119
+ private _textureShapeCircles;
120
+ private _textureShapeBars;
121
+ private _textureShapeSquiggles;
61
122
  private requestRef;
62
123
  private sizeObserver;
63
124
  private sceneState;
125
+ private _cachedUniforms;
126
+ private _linkElement;
127
+ private _yOffset;
128
+ private _yOffsetWaveMultiplier;
129
+ private _yOffsetColorMultiplier;
130
+ private _yOffsetFlowMultiplier;
131
+ private _tempClearColor;
64
132
  constructor(config: NeatConfig & {
65
133
  ref: HTMLCanvasElement;
66
134
  resolution?: number;
67
135
  seed?: number;
68
136
  });
69
137
  destroy(): void;
138
+ downloadAsPNG(filename?: string): void;
70
139
  set speed(speed: number);
71
140
  set horizontalPressure(horizontalPressure: number);
72
141
  set verticalPressure(verticalPressure: number);
@@ -81,12 +150,48 @@ export declare class NeatGradient implements NeatController {
81
150
  set colorBlending(colorBlending: number);
82
151
  set grainScale(grainScale: number);
83
152
  set grainIntensity(grainIntensity: number);
153
+ set grainSparsity(grainSparsity: number);
84
154
  set grainSpeed(grainSpeed: number);
85
155
  set wireframe(wireframe: boolean);
86
156
  set resolution(resolution: number);
87
157
  set backgroundColor(backgroundColor: string);
88
158
  set backgroundAlpha(backgroundAlpha: number);
159
+ set yOffset(yOffset: number);
160
+ get yOffsetWaveMultiplier(): number;
161
+ set yOffsetWaveMultiplier(value: number);
162
+ get yOffsetColorMultiplier(): number;
163
+ set yOffsetColorMultiplier(value: number);
164
+ get yOffsetFlowMultiplier(): number;
165
+ set yOffsetFlowMultiplier(value: number);
166
+ set flowDistortionA(value: number);
167
+ set flowDistortionB(value: number);
168
+ set flowScale(value: number);
169
+ set flowEase(value: number);
170
+ set flowEnabled(value: boolean);
171
+ get flowEnabled(): boolean;
172
+ set mouseDistortionStrength(value: number);
173
+ set mouseDistortionRadius(value: number);
174
+ _updateBrushScale(): void;
175
+ set mouseDecayRate(value: number);
176
+ set mouseDarken(value: number);
177
+ set enableProceduralTexture(value: boolean);
178
+ set textureVoidLikelihood(value: number);
179
+ set textureVoidWidthMin(value: number);
180
+ set textureVoidWidthMax(value: number);
181
+ set textureBandDensity(value: number);
182
+ set textureColorBlending(value: number);
183
+ set textureSeed(value: number);
184
+ get textureEase(): number;
185
+ set textureEase(value: number);
186
+ set proceduralBackgroundColor(value: string);
187
+ set textureShapeTriangles(value: number);
188
+ set textureShapeCircles(value: number);
189
+ set textureShapeBars(value: number);
190
+ set textureShapeSquiggles(value: number);
89
191
  _initScene(resolution: number): SceneState;
90
192
  _buildMaterial(width: number, height: number): THREE.ShaderMaterial;
193
+ _setupMouseInteraction(): void;
194
+ _onMouseMove(e: MouseEvent): void;
195
+ _createProceduralTexture(): THREE.Texture;
91
196
  }
92
197
  export {};