@firecms/neat 0.1.1 → 0.1.3

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.
@@ -0,0 +1,323 @@
1
+ (function(l,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],m):(l=typeof globalThis<"u"?globalThis:l||self,m(l.FireCMS={},l.THREE))})(this,function(l,m){"use strict";function O(t){if(t&&t.__esModule)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const i=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const n=O(m),x=50,g=80,T=!0,p=5,j=new n.Clock;class R{_speed=-1;_horizontalPressure=-1;_verticalPressure=-1;_waveFrequencyX=-1;_waveFrequencyY=-1;_waveAmplitude=-1;_shadows=-1;_highlights=-1;_saturation=-1;_colorBlending=-1;_colors=[];_wireframe=!1;_backgroundColor="#FFFFFF";_backgroundAlpha=1;requestRef=-1;sizeObserver;sceneState;constructor(e){const{ref:o,speed:i=4,horizontalPressure:u=3,verticalPressure:s=3,waveFrequencyX:a=5,waveFrequencyY:v=5,waveAmplitude:h=3,colors:f,highlights:c=4,shadows:_=4,saturation:w=0,colorBlending:z=5,wireframe:b=!1,backgroundColor:B="#FFFFFF",backgroundAlpha:D=1,resolution:Y=1}=e,M=o.width,E=o.height;this.destroy=this.destroy.bind(this),this._initScene=this._initScene.bind(this),this._buildMaterial=this._buildMaterial.bind(this),this.speed=i,this.horizontalPressure=u,this.verticalPressure=s,this.waveFrequencyX=a,this.waveFrequencyY=v,this.waveAmplitude=h,this.colorBlending=z,this.colors=f,this.shadows=_,this.highlights=c,this.saturation=w,this.wireframe=b,this.backgroundColor=B,this.backgroundAlpha=D,this.sceneState=this._initScene(o,M,E,Y);const{renderer:P,camera:G,scene:H,meshes:L}=this.sceneState;let q=0;const N=()=>{Math.floor(q*10)%5===0&&k(o),P.setClearColor(this._backgroundColor,this._backgroundAlpha),L.forEach(r=>{const y=[...this._colors.map(d=>({is_active:d.enabled,color:new n.Color(d.color),influence:d.influence})),...Array.from({length:p-this._colors.length}).map(()=>({is_active:!1,color:new n.Color(0)}))];q+=j.getDelta()*this._speed,r.material.uniforms.u_time.value=q,r.material.uniforms.u_resolution={value:new n.Vector2(M,E)},r.material.uniforms.u_color_pressure={value:new n.Vector2(this._horizontalPressure,this._verticalPressure)},r.material.uniforms.u_wave_frequency_x={value:this._waveFrequencyX},r.material.uniforms.u_wave_frequency_y={value:this._waveFrequencyY},r.material.uniforms.u_wave_amplitude={value:this._waveAmplitude},r.material.uniforms.u_plane_width={value:x},r.material.uniforms.u_plane_height={value:g},r.material.uniforms.u_color_blending={value:this._colorBlending},r.material.uniforms.u_colors={value:y},r.material.uniforms.u_colors_count={value:p},r.material.uniforms.u_shadows={value:this._shadows},r.material.uniforms.u_highlights={value:this._highlights},r.material.uniforms.u_saturation={value:this._saturation},r.material.wireframe=this._wireframe}),P.render(H,G),this.requestRef=requestAnimationFrame(N)},W=()=>{const r=P.domElement,y=r.clientWidth,d=r.clientHeight;this.sceneState.renderer.setSize(y,d,!1),C(this.sceneState.camera,y,d)};this.sizeObserver=new ResizeObserver(r=>{W()}),this.sizeObserver.observe(o),N()}destroy(){this&&(cancelAnimationFrame(this.requestRef),this.sizeObserver.disconnect())}set speed(e){this._speed=e/20}set horizontalPressure(e){this._horizontalPressure=e/4}set verticalPressure(e){this._verticalPressure=e/4}set waveFrequencyX(e){this._waveFrequencyX=e*.04}set waveFrequencyY(e){this._waveFrequencyY=e*.04}set waveAmplitude(e){this._waveAmplitude=e*.75}set colors(e){this._colors=e}set highlights(e){this._highlights=e/100}set shadows(e){this._shadows=e/100}set saturation(e){this._saturation=e/10}set colorBlending(e){this._colorBlending=e/10}set wireframe(e){this._wireframe=e}set backgroundColor(e){this._backgroundColor=e}set backgroundAlpha(e){this._backgroundAlpha=e}_initScene(e,o,i,u){const s=new n.WebGLRenderer({alpha:!0,canvas:e});s.setClearColor(16711680,.5),s.setSize(o,i,!1);const a=[],v=new n.Scene,h=this._buildMaterial(o,i),f=new n.PlaneGeometry(x,g,240*u,240*u),c=new n.Mesh(f,h);c.rotation.x=-Math.PI/3.5,c.position.z=-1,a.push(c),v.add(c);const _=new n.OrthographicCamera(0,0,0,0,0,0);return C(_,o,i),{renderer:s,camera:_,scene:v,meshes:a}}_buildMaterial(e,o){const i=[...this._colors.map(a=>({is_active:a.enabled,color:new n.Color(a.color),influence:a.influence})),...Array.from({length:p-this._colors.length}).map(()=>({is_active:!1,color:new n.Color(0)}))],u={u_time:{value:0},u_color_pressure:{value:new n.Vector2(this._horizontalPressure,this._verticalPressure)},u_wave_frequency_x:{value:this._waveFrequencyX},u_wave_frequency_y:{value:this._waveFrequencyY},u_wave_amplitude:{value:this._waveAmplitude},u_resolution:{value:new n.Vector2(e,o)},u_colors:{value:i},u_colors_count:{value:this._colors.length},u_plane_width:{value:x},u_plane_height:{value:g},u_shadows:{value:this._shadows},u_highlights:{value:this._highlights}},s=new n.ShaderMaterial({uniforms:u,vertexShader:F()+V()+S()+I(),fragmentShader:F()+S()+K()});return s.wireframe=T,s}}function C(t,e,o){const s=e*o/1e6*x*g/1.5,a=e/o,v=Math.sqrt(s*a),h=s/v,f=-x/2,c=Math.min((f+v)/1.5,x/2),_=g/4,w=Math.max((_-h)/2,-g/4),z=-100,b=1e3;t.left=f,t.right=c,t.top=_,t.bottom=w,t.near=z,t.far=b,t.updateProjectionMatrix()}function I(){return`
2
+
3
+ void main() {
4
+
5
+ vUv = uv;
6
+
7
+ v_displacement_amount = cnoise( vec3(
8
+ u_wave_frequency_x * position.x + u_time,
9
+ u_wave_frequency_y * position.y + u_time,
10
+ u_time
11
+ ));
12
+
13
+ vec3 color;
14
+
15
+ // float t = mod(u_base_color, 100.0);
16
+ color = u_colors[0].color;
17
+
18
+ vec2 noise_cord = vUv * u_color_pressure;
19
+
20
+ const float minNoise = .0;
21
+ const float maxNoise = .9;
22
+
23
+ for (int i = 1; i < u_colors_count; i++) {
24
+
25
+ if(u_colors[i].is_active == 1.0){
26
+ float noiseFlow = (1. + float(i)) / 30.;
27
+ float noiseSpeed = (1. + float(i)) * 0.11;
28
+ float noiseSeed = 13. + float(i) * 7.;
29
+
30
+ float noise = snoise(
31
+ vec3(
32
+ noise_cord.x * u_color_pressure.x + u_time * noiseFlow * 2.,
33
+ noise_cord.y * u_color_pressure.y,
34
+ u_time * noiseSpeed
35
+ ) + noiseSeed
36
+ );
37
+
38
+ noise = clamp(minNoise, maxNoise + float(i) * 0.02, noise);
39
+ vec3 nextColor = u_colors[i].color;
40
+ color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));
41
+ }
42
+
43
+ }
44
+
45
+ v_color = color;
46
+
47
+ vec3 newPosition = position + normal * v_displacement_amount * u_wave_amplitude;
48
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );
49
+
50
+ v_new_position = gl_Position;
51
+ }
52
+ `}function K(){return`
53
+
54
+ void main(){
55
+ vec3 color = v_color;
56
+
57
+ color.rgb += pow(v_displacement_amount, 1.0) * u_highlights;
58
+ color.rgb -= pow(1.0 - v_displacement_amount, 2.0) * u_shadows;
59
+ color = saturation(color, 1.0 + u_saturation);
60
+
61
+ gl_FragColor = vec4(color,1.0);
62
+ }
63
+ `}const F=()=>`
64
+ precision highp float;
65
+
66
+ struct Color {
67
+ float is_active;
68
+ vec3 color;
69
+ float value;
70
+ };
71
+
72
+ uniform float u_time;
73
+
74
+ uniform float u_wave_amplitude;
75
+ uniform float u_wave_frequency_x;
76
+ uniform float u_wave_frequency_y;
77
+
78
+ uniform vec2 u_color_pressure;
79
+
80
+ uniform float u_plane_width;
81
+ uniform float u_plane_height;
82
+
83
+ uniform float u_shadows;
84
+ uniform float u_highlights;
85
+ uniform float u_saturation;
86
+
87
+ uniform float u_color_blending;
88
+
89
+ uniform int u_colors_count;
90
+ uniform Color u_colors[5];
91
+ uniform vec2 u_resolution;
92
+
93
+ varying vec2 vUv;
94
+ varying vec4 v_new_position;
95
+ varying vec3 v_color;
96
+ varying float v_displacement_amount;
97
+
98
+ `,V=()=>`
99
+
100
+ vec3 mod289(vec3 x)
101
+ {
102
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
103
+ }
104
+
105
+ vec4 mod289(vec4 x)
106
+ {
107
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
108
+ }
109
+
110
+ vec4 permute(vec4 x)
111
+ {
112
+ return mod289(((x*34.0)+1.0)*x);
113
+ }
114
+
115
+ vec4 taylorInvSqrt(vec4 r)
116
+ {
117
+ return 1.79284291400159 - 0.85373472095314 * r;
118
+ }
119
+
120
+ vec3 fade(vec3 t) {
121
+ return t*t*t*(t*(t*6.0-15.0)+10.0);
122
+ }
123
+
124
+ float snoise(vec3 v)
125
+ {
126
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
127
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
128
+
129
+ // First corner
130
+ vec3 i = floor(v + dot(v, C.yyy) );
131
+ vec3 x0 = v - i + dot(i, C.xxx) ;
132
+
133
+ // Other corners
134
+ vec3 g = step(x0.yzx, x0.xyz);
135
+ vec3 l = 1.0 - g;
136
+ vec3 i1 = min( g.xyz, l.zxy );
137
+ vec3 i2 = max( g.xyz, l.zxy );
138
+
139
+ // x0 = x0 - 0.0 + 0.0 * C.xxx;
140
+ // x1 = x0 - i1 + 1.0 * C.xxx;
141
+ // x2 = x0 - i2 + 2.0 * C.xxx;
142
+ // x3 = x0 - 1.0 + 3.0 * C.xxx;
143
+ vec3 x1 = x0 - i1 + C.xxx;
144
+ vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
145
+ vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
146
+
147
+ // Permutations
148
+ i = mod289(i);
149
+ vec4 p = permute( permute( permute(
150
+ i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
151
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
152
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
153
+
154
+ // Gradients: 7x7 points over a square, mapped onto an octahedron.
155
+ // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
156
+ float n_ = 0.142857142857; // 1.0/7.0
157
+ vec3 ns = n_ * D.wyz - D.xzx;
158
+
159
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
160
+
161
+ vec4 x_ = floor(j * ns.z);
162
+ vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
163
+
164
+ vec4 x = x_ *ns.x + ns.yyyy;
165
+ vec4 y = y_ *ns.x + ns.yyyy;
166
+ vec4 h = 1.0 - abs(x) - abs(y);
167
+
168
+ vec4 b0 = vec4( x.xy, y.xy );
169
+ vec4 b1 = vec4( x.zw, y.zw );
170
+
171
+ //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
172
+ //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
173
+ vec4 s0 = floor(b0)*2.0 + 1.0;
174
+ vec4 s1 = floor(b1)*2.0 + 1.0;
175
+ vec4 sh = -step(h, vec4(0.0));
176
+
177
+ vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
178
+ vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
179
+
180
+ vec3 p0 = vec3(a0.xy,h.x);
181
+ vec3 p1 = vec3(a0.zw,h.y);
182
+ vec3 p2 = vec3(a1.xy,h.z);
183
+ vec3 p3 = vec3(a1.zw,h.w);
184
+
185
+ //Normalise gradients
186
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
187
+ p0 *= norm.x;
188
+ p1 *= norm.y;
189
+ p2 *= norm.z;
190
+ p3 *= norm.w;
191
+
192
+ // Mix final noise value
193
+ vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
194
+ m = m * m;
195
+ return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
196
+ dot(p2,x2), dot(p3,x3) ) );
197
+ }
198
+
199
+ // Classic Perlin noise
200
+ float cnoise(vec3 P)
201
+ {
202
+ vec3 Pi0 = floor(P); // Integer part for indexing
203
+ vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1
204
+ Pi0 = mod289(Pi0);
205
+ Pi1 = mod289(Pi1);
206
+ vec3 Pf0 = fract(P); // Fractional part for interpolation
207
+ vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
208
+ vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
209
+ vec4 iy = vec4(Pi0.yy, Pi1.yy);
210
+ vec4 iz0 = Pi0.zzzz;
211
+ vec4 iz1 = Pi1.zzzz;
212
+
213
+ vec4 ixy = permute(permute(ix) + iy);
214
+ vec4 ixy0 = permute(ixy + iz0);
215
+ vec4 ixy1 = permute(ixy + iz1);
216
+
217
+ vec4 gx0 = ixy0 * (1.0 / 7.0);
218
+ vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
219
+ gx0 = fract(gx0);
220
+ vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
221
+ vec4 sz0 = step(gz0, vec4(0.0));
222
+ gx0 -= sz0 * (step(0.0, gx0) - 0.5);
223
+ gy0 -= sz0 * (step(0.0, gy0) - 0.5);
224
+
225
+ vec4 gx1 = ixy1 * (1.0 / 7.0);
226
+ vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
227
+ gx1 = fract(gx1);
228
+ vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
229
+ vec4 sz1 = step(gz1, vec4(0.0));
230
+ gx1 -= sz1 * (step(0.0, gx1) - 0.5);
231
+ gy1 -= sz1 * (step(0.0, gy1) - 0.5);
232
+
233
+ vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
234
+ vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
235
+ vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
236
+ vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
237
+ vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
238
+ vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
239
+ vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
240
+ vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
241
+
242
+ vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
243
+ g000 *= norm0.x;
244
+ g010 *= norm0.y;
245
+ g100 *= norm0.z;
246
+ g110 *= norm0.w;
247
+ vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
248
+ g001 *= norm1.x;
249
+ g011 *= norm1.y;
250
+ g101 *= norm1.z;
251
+ g111 *= norm1.w;
252
+
253
+ float n000 = dot(g000, Pf0);
254
+ float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
255
+ float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
256
+ float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
257
+ float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
258
+ float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
259
+ float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
260
+ float n111 = dot(g111, Pf1);
261
+
262
+ vec3 fade_xyz = fade(Pf0);
263
+ vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
264
+ vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
265
+ float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
266
+ return 2.2 * n_xyz;
267
+ }
268
+
269
+ // YUV to RGB matrix
270
+ mat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,
271
+ 1.0, -0.39465, -0.58060,
272
+ 1.0, 2.03211, 0.0);
273
+
274
+ // RGB to YUV matrix
275
+ mat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722,
276
+ -0.09991, -0.33609, 0.43600,
277
+ 0.615, -0.5586, -0.05639);
278
+
279
+ `,S=()=>`
280
+
281
+ vec3 saturation(vec3 rgb, float adjustment) {
282
+ const vec3 W = vec3(0.2125, 0.7154, 0.0721);
283
+ vec3 intensity = vec3(dot(rgb, W));
284
+ return mix(intensity, rgb, adjustment);
285
+ }
286
+
287
+ float saturation(vec3 rgb)
288
+ {
289
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
290
+ vec4 p = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));
291
+ vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));
292
+
293
+ float d = q.x - min(q.w, q.y);
294
+ float e = 1.0e-10;
295
+ return abs(6.0 * d + e);
296
+ }
297
+
298
+ // get saturation of a color in values between 0 and 1
299
+ float getSaturation(vec3 color) {
300
+ float max = max(color.r, max(color.g, color.b));
301
+ float min = min(color.r, min(color.g, color.b));
302
+ return (max - min) / max;
303
+ }
304
+
305
+ vec3 rgb2hsv(vec3 c)
306
+ {
307
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
308
+ vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
309
+ vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
310
+
311
+ float d = q.x - min(q.w, q.y);
312
+ float e = 1.0e-10;
313
+ return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
314
+ }
315
+
316
+ vec3 hsv2rgb(vec3 c)
317
+ {
318
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
319
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
320
+ return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
321
+ }
322
+ `,A=t=>{t.id="neat-link",t.href="https://neat.firecms.co",t.target="_blank",t.style.position="absolute",t.style.display="block",t.style.opacity="1",t.style.bottom="0",t.style.right="0",t.style.padding="10px",t.style.color="#dcdcdc",t.style.fontFamily="sans-serif",t.style.fontSize="16px",t.style.fontWeight="bold",t.style.textDecoration="none",t.style.zIndex="100",t.innerHTML="NEAT"},k=t=>{const e=t.parentElement?.getElementsByTagName("a");if(e){for(let i=0;i<e.length;i++)if(e[i].id==="neat-link"){A(e[i]);return}}const o=document.createElement("a");A(o),t.parentElement?.appendChild(o)};l.NeatGradient=R,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
323
+ //# sourceMappingURL=index.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../src/NeatGradient.ts"],"sourcesContent":["import * as THREE from \"three\";\n\nconst PLANE_WIDTH = 50;\nconst PLANE_HEIGHT = 80;\n\nconst WIREFRAME = true;\nconst COLORS_COUNT = 5;\n\nconst clock = new THREE.Clock();\n\ntype SceneState = {\n renderer: THREE.WebGLRenderer,\n camera: THREE.OrthographicCamera,\n scene: THREE.Scene,\n meshes: THREE.Mesh[],\n}\n\nexport type NeatConfig = {\n speed?: number;\n horizontalPressure?: number;\n verticalPressure?: number;\n waveFrequencyX?: number;\n waveFrequencyY?: number;\n waveAmplitude?: number;\n highlights?: number;\n shadows?: number;\n saturation?: number;\n colors: NeatColor[];\n colorBlending?: number;\n wireframe?: boolean;\n backgroundColor?: string;\n backgroundAlpha?: number;\n};\n\nexport type NeatColor = {\n color: string;\n enabled: boolean;\n /**\n * Value from 0 to 1\n */\n influence?: number;\n}\n\nexport type NeatController = {\n destroy: () => void;\n}\n\nexport class NeatGradient implements NeatController {\n\n private _speed: number = -1;\n\n private _horizontalPressure: number = -1;\n private _verticalPressure: number = -1;\n\n private _waveFrequencyX: number = -1;\n private _waveFrequencyY: number = -1;\n private _waveAmplitude: number = -1;\n\n private _shadows: number = -1;\n private _highlights: number = -1;\n private _saturation: number = -1;\n\n private _colorBlending: number = -1;\n\n private _colors: NeatColor[] = [];\n private _wireframe: boolean = false;\n\n private _backgroundColor: string = \"#FFFFFF\";\n private _backgroundAlpha: number = 1.0;\n\n private requestRef: number = -1;\n private sizeObserver: ResizeObserver;\n private readonly sceneState: SceneState;\n\n constructor(config: NeatConfig & { ref: HTMLCanvasElement, resolution?: number }) {\n\n const {\n ref,\n speed = 4,\n horizontalPressure = 3,\n verticalPressure = 3,\n waveFrequencyX = 5,\n waveFrequencyY = 5,\n waveAmplitude = 3,\n colors,\n highlights = 4,\n shadows = 4,\n saturation = 0,\n colorBlending = 5,\n wireframe = false,\n backgroundColor = \"#FFFFFF\",\n backgroundAlpha = 1.0,\n resolution = 1\n } = config;\n\n const width = ref.width,\n height = ref.height;\n\n this.destroy = this.destroy.bind(this);\n this._initScene = this._initScene.bind(this);\n this._buildMaterial = this._buildMaterial.bind(this);\n\n this.speed = speed;\n this.horizontalPressure = horizontalPressure;\n this.verticalPressure = verticalPressure;\n this.waveFrequencyX = waveFrequencyX;\n this.waveFrequencyY = waveFrequencyY;\n this.waveAmplitude = waveAmplitude;\n this.colorBlending = colorBlending;\n this.colors = colors;\n this.shadows = shadows;\n this.highlights = highlights;\n this.saturation = saturation;\n this.wireframe = wireframe;\n this.backgroundColor = backgroundColor;\n this.backgroundAlpha = backgroundAlpha;\n\n this.sceneState = this._initScene(ref, width, height, resolution);\n\n const { renderer, camera, scene, meshes } = this.sceneState;\n\n let tick = 0;\n const render = () => {\n\n if (Math.floor(tick * 10) % 5 === 0) {\n addNeatLink(ref);\n }\n\n renderer.setClearColor(this._backgroundColor, this._backgroundAlpha);\n meshes.forEach((mesh) => {\n\n const colors = [\n ...this._colors.map(color => ({\n is_active: color.enabled,\n color: new THREE.Color(color.color),\n influence: color.influence\n })),\n ...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({\n is_active: false,\n color: new THREE.Color(0x000000)\n }))\n ];\n\n tick += clock.getDelta() * this._speed;\n // @ts-ignore\n mesh.material.uniforms.u_time.value = tick;\n // @ts-ignore\n mesh.material.uniforms.u_resolution = { value: new THREE.Vector2(width, height) };\n // @ts-ignore\n mesh.material.uniforms.u_color_pressure = { value: new THREE.Vector2(this._horizontalPressure, this._verticalPressure) };\n // @ts-ignore\n mesh.material.uniforms.u_wave_frequency_x = { value: this._waveFrequencyX };\n // @ts-ignore\n mesh.material.uniforms.u_wave_frequency_y = { value: this._waveFrequencyY };\n // @ts-ignore\n mesh.material.uniforms.u_wave_amplitude = { value: this._waveAmplitude };\n // @ts-ignore\n mesh.material.uniforms.u_plane_width = { value: PLANE_WIDTH };\n // @ts-ignore\n mesh.material.uniforms.u_plane_height = { value: PLANE_HEIGHT };\n // @ts-ignore\n mesh.material.uniforms.u_color_blending = { value: this._colorBlending };\n // @ts-ignore\n mesh.material.uniforms.u_colors = { value: colors };\n // @ts-ignore\n mesh.material.uniforms.u_colors_count = { value: COLORS_COUNT };\n // @ts-ignore\n mesh.material.uniforms.u_shadows = { value: this._shadows };\n // @ts-ignore\n mesh.material.uniforms.u_highlights = { value: this._highlights };\n // @ts-ignore\n mesh.material.uniforms.u_saturation = { value: this._saturation };\n // @ts-ignore\n mesh.material.wireframe = this._wireframe;\n });\n\n renderer.render(scene, camera);\n this.requestRef = requestAnimationFrame(render);\n };\n\n const setSize = () => {\n const canvas = renderer.domElement;\n const width = canvas.clientWidth;\n const height = canvas.clientHeight;\n\n this.sceneState.renderer.setSize(width, height, false);\n updateCamera(this.sceneState.camera, width, height);\n };\n\n this.sizeObserver = new ResizeObserver(entries => {\n setSize();\n });\n\n this.sizeObserver.observe(ref);\n\n\n render();\n }\n\n destroy() {\n if (this) {\n cancelAnimationFrame(this.requestRef);\n this.sizeObserver.disconnect();\n }\n }\n\n set speed(speed: number) {\n this._speed = speed / 20;\n }\n\n set horizontalPressure(horizontalPressure: number) {\n this._horizontalPressure = horizontalPressure / 4;\n }\n\n set verticalPressure(verticalPressure: number) {\n this._verticalPressure = verticalPressure / 4;\n }\n\n set waveFrequencyX(waveFrequencyX: number) {\n this._waveFrequencyX = waveFrequencyX * 0.04;\n }\n\n set waveFrequencyY(waveFrequencyY: number) {\n this._waveFrequencyY = waveFrequencyY * 0.04;\n }\n\n set waveAmplitude(waveAmplitude: number) {\n this._waveAmplitude = waveAmplitude * .75;\n }\n\n set colors(colors: NeatColor[]) {\n this._colors = colors;\n }\n\n set highlights(highlights: number) {\n this._highlights = highlights / 100;\n }\n\n set shadows(shadows: number) {\n this._shadows = shadows / 100;\n }\n\n set saturation(saturation: number) {\n this._saturation = saturation / 10;\n }\n\n set colorBlending(colorBlending: number) {\n this._colorBlending = colorBlending / 10;\n }\n\n set wireframe(wireframe: boolean) {\n this._wireframe = wireframe;\n }\n\n set backgroundColor(backgroundColor: string) {\n this._backgroundColor = backgroundColor;\n }\n\n set backgroundAlpha(backgroundAlpha: number) {\n this._backgroundAlpha = backgroundAlpha;\n }\n\n _initScene(ref: HTMLCanvasElement, width: number, height: number, resolution: number): SceneState {\n\n const renderer = new THREE.WebGLRenderer({\n // antialias: true,\n alpha: true,\n canvas: ref\n });\n\n renderer.setClearColor(0xFF0000, .5);\n renderer.setSize(width, height, false);\n\n const meshes: THREE.Mesh[] = [];\n\n const scene = new THREE.Scene();\n\n const material = this._buildMaterial(width, height);\n\n const geo = new THREE.PlaneGeometry(PLANE_WIDTH, PLANE_HEIGHT, 240 * resolution, 240 * resolution);\n const plane = new THREE.Mesh(geo, material);\n plane.rotation.x = -Math.PI / 3.5;\n plane.position.z = -1;\n meshes.push(plane);\n scene.add(plane);\n\n const camera = new THREE.OrthographicCamera(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);\n // camera.zoom = 1;\n updateCamera(camera, width, height);\n\n return {\n renderer,\n camera,\n scene,\n meshes\n };\n }\n\n _buildMaterial(width: number, height: number) {\n\n const colors = [\n ...this._colors.map(color => ({\n is_active: color.enabled,\n color: new THREE.Color(color.color),\n influence: color.influence\n })),\n ...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({\n is_active: false,\n color: new THREE.Color(0x000000)\n }))\n ];\n\n const uniforms = {\n u_time: { value: 0 },\n u_color_pressure: { value: new THREE.Vector2(this._horizontalPressure, this._verticalPressure) },\n u_wave_frequency_x: { value: this._waveFrequencyX },\n u_wave_frequency_y: { value: this._waveFrequencyY },\n u_wave_amplitude: { value: this._waveAmplitude },\n u_resolution: { value: new THREE.Vector2(width, height) },\n u_colors: { value: colors },\n u_colors_count: { value: this._colors.length },\n u_plane_width: { value: PLANE_WIDTH },\n u_plane_height: { value: PLANE_HEIGHT },\n u_shadows: { value: this._shadows },\n u_highlights: { value: this._highlights },\n };\n\n const material = new THREE.ShaderMaterial({\n uniforms: uniforms,\n vertexShader: buildUniforms() + buildNoise() + buildColorFunctions() + buildVertexShader(),\n fragmentShader: buildUniforms() + buildColorFunctions() + buildFragmentShader()\n });\n\n material.wireframe = WIREFRAME;\n return material;\n }\n\n\n}\n\nfunction updateCamera(camera: THREE.OrthographicCamera, width: number, height: number) {\n\n const viewPortAreaRatio = 1000000;\n const areaViewPort = width * height;\n const targetPlaneArea =\n areaViewPort / viewPortAreaRatio *\n PLANE_WIDTH * PLANE_HEIGHT / 1.5;\n\n const ratio = width / height;\n\n const targetWidth = Math.sqrt(targetPlaneArea * ratio);\n const targetHeight = targetPlaneArea / targetWidth;\n\n const left = -PLANE_WIDTH / 2;\n const right = Math.min((left + targetWidth) / 1.5, PLANE_WIDTH / 2);\n\n const top = PLANE_HEIGHT / 4;\n const bottom = Math.max((top - targetHeight) / 2, -PLANE_HEIGHT / 4);\n\n const near = -100;\n const far = 1000;\n camera.left = left;\n camera.right = right;\n camera.top = top;\n camera.bottom = bottom;\n camera.near = near;\n camera.far = far;\n camera.updateProjectionMatrix();\n}\n\n\nfunction buildVertexShader() {\n return `\n\nvoid main() {\n\n vUv = uv;\n\n v_displacement_amount = cnoise( vec3(\n u_wave_frequency_x * position.x + u_time,\n u_wave_frequency_y * position.y + u_time,\n u_time\n ));\n \n vec3 color;\n\n // float t = mod(u_base_color, 100.0);\n color = u_colors[0].color;\n \n vec2 noise_cord = vUv * u_color_pressure;\n \n const float minNoise = .0;\n const float maxNoise = .9;\n \n for (int i = 1; i < u_colors_count; i++) {\n \n if(u_colors[i].is_active == 1.0){\n float noiseFlow = (1. + float(i)) / 30.;\n float noiseSpeed = (1. + float(i)) * 0.11;\n float noiseSeed = 13. + float(i) * 7.;\n \n float noise = snoise(\n vec3(\n noise_cord.x * u_color_pressure.x + u_time * noiseFlow * 2.,\n noise_cord.y * u_color_pressure.y,\n u_time * noiseSpeed\n ) + noiseSeed\n );\n \n noise = clamp(minNoise, maxNoise + float(i) * 0.02, noise);\n vec3 nextColor = u_colors[i].color;\n color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));\n }\n \n }\n \n v_color = color;\n \n vec3 newPosition = position + normal * v_displacement_amount * u_wave_amplitude;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );\n \n v_new_position = gl_Position;\n}\n`;\n}\n\nfunction buildFragmentShader() {\n return `\n\nvoid main(){\n vec3 color = v_color;\n \n color.rgb += pow(v_displacement_amount, 1.0) * u_highlights;\n color.rgb -= pow(1.0 - v_displacement_amount, 2.0) * u_shadows;\n color = saturation(color, 1.0 + u_saturation);\n \n gl_FragColor = vec4(color,1.0);\n}\n`;\n}\n\nconst buildUniforms = () => `\nprecision highp float;\n\nstruct Color {\n float is_active;\n vec3 color;\n float value;\n};\n\nuniform float u_time;\n\nuniform float u_wave_amplitude;\nuniform float u_wave_frequency_x;\nuniform float u_wave_frequency_y;\n\nuniform vec2 u_color_pressure;\n\nuniform float u_plane_width;\nuniform float u_plane_height;\n\nuniform float u_shadows;\nuniform float u_highlights;\nuniform float u_saturation;\n\nuniform float u_color_blending;\n\nuniform int u_colors_count;\nuniform Color u_colors[5];\nuniform vec2 u_resolution;\n\nvarying vec2 vUv;\nvarying vec4 v_new_position;\nvarying vec3 v_color;\nvarying float v_displacement_amount;\n\n `;\n\nconst buildNoise = () => `\n\nvec3 mod289(vec3 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 mod289(vec4 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 permute(vec4 x)\n{\n return mod289(((x*34.0)+1.0)*x);\n}\n\nvec4 taylorInvSqrt(vec4 r)\n{\n return 1.79284291400159 - 0.85373472095314 * r;\n}\n\nvec3 fade(vec3 t) {\n return t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat snoise(vec3 v)\n{\n const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\n// First corner\n vec3 i = floor(v + dot(v, C.yyy) );\n vec3 x0 = v - i + dot(i, C.xxx) ;\n\n// Other corners\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n // x0 = x0 - 0.0 + 0.0 * C.xxx;\n // x1 = x0 - i1 + 1.0 * C.xxx;\n // x2 = x0 - i2 + 2.0 * C.xxx;\n // x3 = x0 - 1.0 + 3.0 * C.xxx;\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n// Permutations\n i = mod289(i);\n vec4 p = permute( permute( permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0 ))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));\n\n// Gradients: 7x7 points over a square, mapped onto an octahedron.\n// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ *ns.x + ns.yyyy;\n vec4 y = y_ *ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;\n //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;\n vec4 s0 = floor(b0)*2.0 + 1.0;\n vec4 s1 = floor(b1)*2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n\n vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;\n\n vec3 p0 = vec3(a0.xy,h.x);\n vec3 p1 = vec3(a0.zw,h.y);\n vec3 p2 = vec3(a1.xy,h.z);\n vec3 p3 = vec3(a1.zw,h.w);\n\n//Normalise gradients\n vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n// Mix final noise value\n vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);\n m = m * m;\n return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),\n dot(p2,x2), dot(p3,x3) ) );\n}\n\n// Classic Perlin noise\nfloat cnoise(vec3 P)\n{\n vec3 Pi0 = floor(P); // Integer part for indexing\n vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n}\n\n// YUV to RGB matrix\nmat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,\n 1.0, -0.39465, -0.58060,\n 1.0, 2.03211, 0.0);\n\n// RGB to YUV matrix\nmat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722,\n -0.09991, -0.33609, 0.43600,\n 0.615, -0.5586, -0.05639);\n\n `;\n\nconst buildColorFunctions = () => `\n\nvec3 saturation(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n}\n\nfloat saturation(vec3 rgb)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return abs(6.0 * d + e);\n}\n\n// get saturation of a color in values between 0 and 1\nfloat getSaturation(vec3 color) {\n float max = max(color.r, max(color.g, color.b));\n float min = min(color.r, min(color.g, color.b));\n return (max - min) / max;\n}\n \nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n`;\n\n\nconst setLinkStyles = (link: HTMLAnchorElement) => {\n link.id = \"neat-link\";\n link.href = \"https://neat.firecms.co\";\n link.target = \"_blank\";\n link.style.position = \"absolute\";\n link.style.display = \"block\";\n link.style.opacity = \"1\";\n link.style.bottom = \"0\";\n link.style.right = \"0\";\n link.style.padding = \"10px\";\n link.style.color = \"#dcdcdc\";\n link.style.fontFamily = \"sans-serif\";\n link.style.fontSize = \"16px\";\n link.style.fontWeight = \"bold\";\n link.style.textDecoration = \"none\";\n link.style.zIndex = \"100\";\n link.innerHTML = \"NEAT\";\n}\n\nconst addNeatLink = (ref: HTMLCanvasElement) => {\n const existingLinks = ref.parentElement?.getElementsByTagName(\"a\");\n if (existingLinks) {\n for (let i = 0; i < existingLinks.length; i++) {\n if (existingLinks[i].id === \"neat-link\") {\n setLinkStyles(existingLinks[i]);\n return;\n }\n }\n }\n const link = document.createElement(\"a\");\n setLinkStyles(link);\n ref.parentElement?.appendChild(link);\n}\n"],"names":["PLANE_WIDTH","PLANE_HEIGHT","WIREFRAME","COLORS_COUNT","clock","THREE","NeatGradient","config","ref","speed","horizontalPressure","verticalPressure","waveFrequencyX","waveFrequencyY","waveAmplitude","colors","highlights","shadows","saturation","colorBlending","wireframe","backgroundColor","backgroundAlpha","resolution","width","height","renderer","camera","scene","meshes","tick","render","addNeatLink","mesh","color","setSize","canvas","updateCamera","entries","material","geo","plane","uniforms","buildUniforms","buildNoise","buildColorFunctions","buildVertexShader","buildFragmentShader","targetPlaneArea","ratio","targetWidth","targetHeight","left","right","top","bottom","near","far","setLinkStyles","link","existingLinks"],"mappings":"wjBAEMA,EAAc,GACdC,EAAe,GAEfC,EAAY,GACZC,EAAe,EAEfC,EAAQ,IAAIC,EAAM,MAuCjB,MAAMC,CAAuC,CAExC,OAAiB,GAEjB,oBAA8B,GAC9B,kBAA4B,GAE5B,gBAA0B,GAC1B,gBAA0B,GAC1B,eAAyB,GAEzB,SAAmB,GACnB,YAAsB,GACtB,YAAsB,GAEtB,eAAyB,GAEzB,QAAuB,CAAA,EACvB,WAAsB,GAEtB,iBAA2B,UAC3B,iBAA2B,EAE3B,WAAqB,GACrB,aACS,WAEjB,YAAYC,EAAsE,CAExE,KAAA,CACF,IAAAC,EACA,MAAAC,EAAQ,EACR,mBAAAC,EAAqB,EACrB,iBAAAC,EAAmB,EACnB,eAAAC,EAAiB,EACjB,eAAAC,EAAiB,EACjB,cAAAC,EAAgB,EAChB,OAAAC,EACA,WAAAC,EAAa,EACb,QAAAC,EAAU,EACV,WAAAC,EAAa,EACb,cAAAC,EAAgB,EAChB,UAAAC,EAAY,GACZ,gBAAAC,EAAkB,UAClB,gBAAAC,EAAkB,EAClB,WAAAC,EAAa,CACb,EAAAhB,EAEEiB,EAAQhB,EAAI,MACdiB,EAASjB,EAAI,OAEjB,KAAK,QAAU,KAAK,QAAQ,KAAK,IAAI,EACrC,KAAK,WAAa,KAAK,WAAW,KAAK,IAAI,EAC3C,KAAK,e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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8C5Ba,EAAiBC,GAA4B,CAC/CA,EAAK,GAAK,YACVA,EAAK,KAAO,0BACZA,EAAK,OAAS,SACdA,EAAK,MAAM,SAAW,WACtBA,EAAK,MAAM,QAAU,QACrBA,EAAK,MAAM,QAAU,IACrBA,EAAK,MAAM,OAAS,IACpBA,EAAK,MAAM,MAAQ,IACnBA,EAAK,MAAM,QAAU,OACrBA,EAAK,MAAM,MAAQ,UACnBA,EAAK,MAAM,WAAa,aACxBA,EAAK,MAAM,SAAW,OACtBA,EAAK,MAAM,WAAa,OACxBA,EAAK,MAAM,eAAiB,OAC5BA,EAAK,MAAM,OAAS,MACpBA,EAAK,UAAY,MACrB,EAEM3B,EAAexB,GAA2B,CAC5C,MAAMoD,EAAgBpD,EAAI,eAAe,qBAAqB,GAAG,EACjE,GAAIoD,GACA,QAAS,EAAI,EAAG,EAAIA,EAAc,OAAQ,IAClC,GAAAA,EAAc,GAAG,KAAO,YAAa,CACrCF,EAAcE,EAAc,EAAE,EAC9B,MACJ,EAGF,MAAAD,EAAO,SAAS,cAAc,GAAG,EACvCD,EAAcC,CAAI,EACdnD,EAAA,eAAe,YAAYmD,CAAI,CACvC"}
package/package.json CHANGED
@@ -2,18 +2,20 @@
2
2
  "name": "@firecms/neat",
3
3
  "description": "Beautiful 3D gradients for your website",
4
4
  "access": "public",
5
- "version": "0.1.1",
5
+ "version": "0.1.3",
6
6
  "main": "./dist/index.umd.js",
7
7
  "module": "./dist/index.es.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "source": "src/index.ts",
10
- "dependencies": {
11
- "typescript": "^4.8.4"
12
- },
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
13
14
  "peerDependencies": {
14
15
  "three": "^0.144.0"
15
16
  },
16
17
  "devDependencies": {
18
+ "typescript": "^4.8.4",
17
19
  "vite": "^3.1.4",
18
20
  "three": "^0.144.0"
19
21
  },
@@ -72,7 +72,7 @@ export class NeatGradient implements NeatController {
72
72
  private sizeObserver: ResizeObserver;
73
73
  private readonly sceneState: SceneState;
74
74
 
75
- constructor(config: NeatConfig & { ref: HTMLCanvasElement }) {
75
+ constructor(config: NeatConfig & { ref: HTMLCanvasElement, resolution?: number }) {
76
76
 
77
77
  const {
78
78
  ref,
@@ -90,6 +90,7 @@ export class NeatGradient implements NeatController {
90
90
  wireframe = false,
91
91
  backgroundColor = "#FFFFFF",
92
92
  backgroundAlpha = 1.0,
93
+ resolution = 1
93
94
  } = config;
94
95
 
95
96
  const width = ref.width,
@@ -114,7 +115,7 @@ export class NeatGradient implements NeatController {
114
115
  this.backgroundColor = backgroundColor;
115
116
  this.backgroundAlpha = backgroundAlpha;
116
117
 
117
- this.sceneState = this._initScene(ref, width, height);
118
+ this.sceneState = this._initScene(ref, width, height, resolution);
118
119
 
119
120
  const { renderer, camera, scene, meshes } = this.sceneState;
120
121
 
@@ -259,7 +260,7 @@ export class NeatGradient implements NeatController {
259
260
  this._backgroundAlpha = backgroundAlpha;
260
261
  }
261
262
 
262
- _initScene(ref: HTMLCanvasElement, width: number, height: number): SceneState {
263
+ _initScene(ref: HTMLCanvasElement, width: number, height: number, resolution: number): SceneState {
263
264
 
264
265
  const renderer = new THREE.WebGLRenderer({
265
266
  // antialias: true,
@@ -276,7 +277,7 @@ export class NeatGradient implements NeatController {
276
277
 
277
278
  const material = this._buildMaterial(width, height);
278
279
 
279
- const geo = new THREE.PlaneGeometry(PLANE_WIDTH, PLANE_HEIGHT, 240, 240);
280
+ const geo = new THREE.PlaneGeometry(PLANE_WIDTH, PLANE_HEIGHT, 240 * resolution, 240 * resolution);
280
281
  const plane = new THREE.Mesh(geo, material);
281
282
  plane.rotation.x = -Math.PI / 3.5;
282
283
  plane.position.z = -1;
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "dist",
4
- "module": "esnext",
5
- "target": "esnext",
6
- "lib": [
7
- "dom",
8
- "dom.iterable",
9
- "esnext"
10
- ],
11
- "moduleResolution": "node",
12
- "noFallthroughCasesInSwitch": true,
13
- "sourceMap": true,
14
- "declaration": true,
15
- "esModuleInterop": true,
16
- "noImplicitReturns": true,
17
- "noImplicitThis": true,
18
- "noImplicitAny": true,
19
- "strictNullChecks": true,
20
- "suppressImplicitAnyIndexErrors": true,
21
- "allowSyntheticDefaultImports": true,
22
- "allowJs": true,
23
- "skipLibCheck": true,
24
- "strict": true,
25
- "forceConsistentCasingInFileNames": true,
26
- "resolveJsonModule": true,
27
- "isolatedModules": true,
28
- "types": ["vite/client", "node"]
29
- },
30
- "include": [
31
- "src",
32
- "./src/**/*.ts"
33
- ],
34
- "exclude": [
35
- "node_modules",
36
- "dist"
37
- ]
38
- }
package/vite.config.js DELETED
@@ -1,23 +0,0 @@
1
- import path from "path";
2
-
3
- import {defineConfig} from "vite";
4
-
5
- const isExternal = (id) => !id.startsWith(".") && !path.isAbsolute(id);
6
-
7
- export default defineConfig(() => ({
8
- esbuild: {
9
- logOverride: {"this-is-undefined-in-esm": "silent"}
10
- },
11
- build: {
12
- lib: {
13
- entry: path.resolve(__dirname, "src/index.ts"),
14
- name: "FireCMS",
15
- fileName: (format) => `index.${format}.js`
16
- },
17
- target: "esnext",
18
- sourcemap: true,
19
- rollupOptions: {
20
- external: isExternal
21
- }
22
- }
23
- }));