@firecms/neat 0.5.0 → 0.5.1

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/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as l from "three";
2
- const D = 50, E = 80, pe = !0, k = 6, xe = new l.Clock(), G = be();
3
- class ze {
2
+ const U = 50, D = 80, be = !0, j = 6, ze = new l.Clock(), Q = Te();
3
+ class Be {
4
4
  _ref;
5
5
  _speed = -1;
6
6
  _horizontalPressure = -1;
@@ -61,104 +61,119 @@ class ze {
61
61
  _yOffsetColorMultiplier = 4e-3;
62
62
  _yOffsetFlowMultiplier = 4e-3;
63
63
  _tempClearColor = new l.Color();
64
+ _resizeTimeoutId = null;
65
+ _textureNeedsUpdate = !1;
66
+ _lastColorUpdate = 0;
67
+ _linkCheckCounter = 0;
68
+ _mouseUpdateScheduled = !1;
69
+ _pendingMousePosition = null;
70
+ _colorsChanged = !0;
64
71
  constructor(e) {
65
72
  const {
66
- ref: o,
73
+ ref: s,
67
74
  speed: t = 4,
68
75
  horizontalPressure: f = 3,
69
- verticalPressure: u = 3,
70
- waveFrequencyX: s = 5,
71
- waveFrequencyY: d = 5,
72
- waveAmplitude: x = 3,
73
- colors: p,
74
- highlights: y = 4,
75
- shadows: c = 4,
76
- colorSaturation: m = 0,
77
- colorBrightness: P = 1,
76
+ verticalPressure: c = 3,
77
+ waveFrequencyX: o = 5,
78
+ waveFrequencyY: p = 5,
79
+ waveAmplitude: g = 3,
80
+ colors: d,
81
+ highlights: v = 4,
82
+ shadows: u = 4,
83
+ colorSaturation: x = 0,
84
+ colorBrightness: O = 1,
78
85
  colorBlending: M = 5,
79
- grainScale: T = 2,
80
- grainIntensity: C = 0.55,
81
- grainSparsity: B = 0,
82
- grainSpeed: z = 0.1,
86
+ grainScale: z = 2,
87
+ grainIntensity: y = 0.55,
88
+ grainSparsity: F = 0,
89
+ grainSpeed: C = 0.1,
83
90
  wireframe: a = !1,
84
91
  backgroundColor: n = "#FFFFFF",
85
92
  backgroundAlpha: h = 1,
86
93
  resolution: _ = 1,
87
- seed: b,
88
- yOffset: F = 0,
89
- yOffsetWaveMultiplier: A = 4,
90
- yOffsetColorMultiplier: R = 4,
91
- yOffsetFlowMultiplier: X = 4,
92
- flowDistortionA: K = 0,
93
- flowDistortionB: H = 0,
94
- flowScale: Y = 1,
95
- flowEase: J = 0,
96
- flowEnabled: Q = !0,
97
- mouseDistortionStrength: Z = 0,
98
- mouseDistortionRadius: $ = 0.25,
99
- mouseDecayRate: ee = 0.96,
100
- mouseDarken: te = 0,
101
- enableProceduralTexture: oe = !1,
102
- textureVoidLikelihood: se = 0.45,
103
- textureVoidWidthMin: ie = 200,
104
- textureVoidWidthMax: re = 486,
105
- textureBandDensity: ae = 2.15,
106
- textureColorBlending: le = 0.01,
107
- textureSeed: ne = 333,
108
- textureEase: ue = 0.5,
109
- proceduralBackgroundColor: ce = "#000000",
110
- textureShapeTriangles: _e = 20,
111
- textureShapeCircles: he = 15,
112
- textureShapeBars: fe = 15,
113
- textureShapeSquiggles: de = 10
94
+ seed: S,
95
+ yOffset: B = 0,
96
+ yOffsetWaveMultiplier: N = 4,
97
+ yOffsetColorMultiplier: V = 4,
98
+ yOffsetFlowMultiplier: $ = 4,
99
+ flowDistortionA: ee = 0,
100
+ flowDistortionB: te = 0,
101
+ flowScale: oe = 1,
102
+ flowEase: se = 0,
103
+ flowEnabled: ie = !0,
104
+ mouseDistortionStrength: re = 0,
105
+ mouseDistortionRadius: ae = 0.25,
106
+ mouseDecayRate: le = 0.96,
107
+ mouseDarken: ne = 0,
108
+ enableProceduralTexture: ue = !1,
109
+ textureVoidLikelihood: ce = 0.45,
110
+ textureVoidWidthMin: _e = 200,
111
+ textureVoidWidthMax: he = 486,
112
+ textureBandDensity: fe = 2.15,
113
+ textureColorBlending: de = 0.01,
114
+ textureSeed: pe = 333,
115
+ textureEase: ve = 0.5,
116
+ proceduralBackgroundColor: xe = "#000000",
117
+ textureShapeTriangles: ge = 20,
118
+ textureShapeCircles: me = 15,
119
+ textureShapeBars: ye = 15,
120
+ textureShapeSquiggles: we = 10
114
121
  } = e;
115
- this._ref = o, this.destroy = this.destroy.bind(this), this._initScene = this._initScene.bind(this), this._buildMaterial = this._buildMaterial.bind(this), this.speed = t, this.horizontalPressure = f, this.verticalPressure = u, this.waveFrequencyX = s, this.waveFrequencyY = d, this.waveAmplitude = x, this.colorBlending = M, this.grainScale = T, this.grainIntensity = C, this.grainSparsity = B, this.grainSpeed = z, this.colors = p, this.shadows = c, this.highlights = y, this.colorSaturation = m, this.colorBrightness = P, this.wireframe = a, this.backgroundColor = n, this.backgroundAlpha = h, this.yOffset = F, this.yOffsetWaveMultiplier = A, this.yOffsetColorMultiplier = R, this.yOffsetFlowMultiplier = X, this.flowDistortionA = K, this.flowDistortionB = H, this.flowScale = Y, this.flowEase = J, this.flowEnabled = Q, this.mouseDistortionStrength = Z, this.mouseDistortionRadius = $, this.mouseDecayRate = ee, this.mouseDarken = te, this.enableProceduralTexture = oe, this.textureVoidLikelihood = se, this.textureVoidWidthMin = ie, this.textureVoidWidthMax = re, this.textureBandDensity = ae, this.textureColorBlending = le, this.textureSeed = ne, this.textureEase = ue, this._proceduralBackgroundColor = ce, this._textureShapeTriangles = _e, this._textureShapeCircles = he, this._textureShapeBars = fe, this._textureShapeSquiggles = de, this._setupMouseInteraction(), this.sceneState = this._initScene(_);
116
- let U = b !== void 0 ? b : we();
117
- const I = () => {
118
- const { renderer: g, camera: q, scene: O } = this.sceneState;
119
- if (Math.floor(U * 10) % 5 === 0 && (!this._linkElement || !document.contains(this._linkElement)) && (this._linkElement = ye(o)), this._cachedUniforms) {
122
+ this._ref = s, this.destroy = this.destroy.bind(this), this._initScene = this._initScene.bind(this), this._buildMaterial = this._buildMaterial.bind(this), this.speed = t, this.horizontalPressure = f, this.verticalPressure = c, this.waveFrequencyX = o, this.waveFrequencyY = p, this.waveAmplitude = g, this.colorBlending = M, this.grainScale = z, this.grainIntensity = y, this.grainSparsity = F, this.grainSpeed = C, this.colors = d, this.shadows = u, this.highlights = v, this.colorSaturation = x, this.colorBrightness = O, this.wireframe = a, this.backgroundColor = n, this.backgroundAlpha = h, this.yOffset = B, this.yOffsetWaveMultiplier = N, this.yOffsetColorMultiplier = V, this.yOffsetFlowMultiplier = $, this.flowDistortionA = ee, this.flowDistortionB = te, this.flowScale = oe, this.flowEase = se, this.flowEnabled = ie, this.mouseDistortionStrength = re, this.mouseDistortionRadius = ae, this.mouseDecayRate = le, this.mouseDarken = ne, this.enableProceduralTexture = ue, this.textureVoidLikelihood = ce, this.textureVoidWidthMin = _e, this.textureVoidWidthMax = he, this.textureBandDensity = fe, this.textureColorBlending = de, this.textureSeed = pe, this.textureEase = ve, this._proceduralBackgroundColor = xe, this._textureShapeTriangles = ge, this._textureShapeCircles = me, this._textureShapeBars = ye, this._textureShapeSquiggles = we, this._setupMouseInteraction(), this.sceneState = this._initScene(_);
123
+ let G = S !== void 0 ? S : Oe();
124
+ const X = () => {
125
+ const { renderer: w, camera: E, scene: T } = this.sceneState;
126
+ if (this._linkCheckCounter++, this._linkCheckCounter >= 300 && (this._linkCheckCounter = 0, (!this._linkElement || !document.contains(this._linkElement)) && (this._linkElement = Pe(s))), this._cachedUniforms) {
120
127
  const i = this._cachedUniforms;
121
- U += xe.getDelta() * this._speed, i.u_time.value = U, i.u_resolution.value.set(this._ref.width, this._ref.height), i.u_color_pressure.value.set(this._horizontalPressure, this._verticalPressure), i.u_wave_frequency_x.value = this._waveFrequencyX, i.u_wave_frequency_y.value = this._waveFrequencyY, i.u_wave_amplitude.value = this._waveAmplitude, i.u_color_blending.value = this._colorBlending, i.u_shadows.value = this._shadows, i.u_highlights.value = this._highlights, i.u_saturation.value = this._saturation, i.u_brightness.value = this._brightness, i.u_grain_intensity.value = this._grainIntensity, i.u_grain_sparsity.value = this._grainSparsity, i.u_grain_speed.value = this._grainSpeed, i.u_grain_scale.value = this._grainScale, i.u_y_offset.value = this._yOffset, i.u_y_offset_wave_multiplier.value = this._yOffsetWaveMultiplier, i.u_y_offset_color_multiplier.value = this._yOffsetColorMultiplier, i.u_y_offset_flow_multiplier.value = this._yOffsetFlowMultiplier, i.u_flow_distortion_a.value = this._flowDistortionA, i.u_flow_distortion_b.value = this._flowDistortionB, i.u_flow_scale.value = this._flowScale, i.u_flow_ease.value = this._flowEase, i.u_flow_enabled.value = this._flowEnabled ? 1 : 0, i.u_mouse_distortion_strength.value = this._mouseDistortionStrength, i.u_mouse_distortion_radius.value = this._mouseDistortionRadius, i.u_mouse_darken.value = this._mouseDarken, i.u_enable_procedural_texture.value = this._enableProceduralTexture ? 1 : 0, i.u_procedural_texture.value = this._proceduralTexture, i.u_texture_ease.value = this._textureEase;
122
- const w = i.u_colors.value;
123
- for (let v = 0; v < k; v++)
124
- if (v < this._colors.length) {
125
- const S = this._colors[v];
126
- w[v].is_active = S.enabled ? 1 : 0, w[v].color.setStyle(S.color, ""), w[v].influence = S.influence || 0;
127
- } else
128
- w[v].is_active = 0;
129
- i.u_colors_count.value = k, this.sceneState.meshes[0].material.wireframe = this._wireframe;
128
+ G += ze.getDelta() * this._speed, i.u_time.value = G, i.u_resolution.value.set(this._ref.width, this._ref.height), i.u_color_pressure.value.set(this._horizontalPressure, this._verticalPressure), i.u_wave_frequency_x.value = this._waveFrequencyX, i.u_wave_frequency_y.value = this._waveFrequencyY, i.u_wave_amplitude.value = this._waveAmplitude, i.u_color_blending.value = this._colorBlending, i.u_shadows.value = this._shadows, i.u_highlights.value = this._highlights, i.u_saturation.value = this._saturation, i.u_brightness.value = this._brightness, i.u_grain_intensity.value = this._grainIntensity, i.u_grain_sparsity.value = this._grainSparsity, i.u_grain_speed.value = this._grainSpeed, i.u_grain_scale.value = this._grainScale, i.u_y_offset.value = this._yOffset, i.u_y_offset_wave_multiplier.value = this._yOffsetWaveMultiplier, i.u_y_offset_color_multiplier.value = this._yOffsetColorMultiplier, i.u_y_offset_flow_multiplier.value = this._yOffsetFlowMultiplier, i.u_flow_distortion_a.value = this._flowDistortionA, i.u_flow_distortion_b.value = this._flowDistortionB, i.u_flow_scale.value = this._flowScale, i.u_flow_ease.value = this._flowEase, i.u_flow_enabled.value = this._flowEnabled ? 1 : 0, i.u_mouse_distortion_strength.value = this._mouseDistortionStrength, i.u_mouse_distortion_radius.value = this._mouseDistortionRadius, i.u_mouse_darken.value = this._mouseDarken, i.u_enable_procedural_texture.value = this._enableProceduralTexture ? 1 : 0, this._textureNeedsUpdate && this._enableProceduralTexture && (this._proceduralTexture && this._proceduralTexture.dispose(), this._proceduralTexture = this._createProceduralTexture(), this._textureNeedsUpdate = !1), i.u_procedural_texture.value = this._proceduralTexture, i.u_texture_ease.value = this._textureEase, this.sceneState.meshes[0].material.wireframe = this._wireframe;
129
+ const m = Date.now();
130
+ if (this._colorsChanged || m - this._lastColorUpdate > 100) {
131
+ this._lastColorUpdate = m, this._colorsChanged = !1;
132
+ const q = i.u_colors.value;
133
+ for (let P = 0; P < j; P++)
134
+ if (P < this._colors.length) {
135
+ const L = this._colors[P];
136
+ q[P].is_active = L.enabled ? 1 : 0, q[P].color.setStyle(L.color, ""), q[P].influence = L.influence || 0;
137
+ } else
138
+ q[P].is_active = 0;
139
+ i.u_colors_count.value = j;
140
+ }
130
141
  }
131
- if (this._mouseFBO && this._sceneMouse && this._cameraMouse) {
142
+ if (this._mouseFBO && this._sceneMouse && this._cameraMouse && this._mouseDistortionStrength > 0) {
132
143
  let i = !1;
133
- for (let v = 0; v < this._mouseObjects.length; v++) {
134
- const S = this._mouseObjects[v];
135
- S.mesh.visible && (i = !0, S.mesh.rotation.z += 0.01, S.mesh.material instanceof l.MeshBasicMaterial && (S.mesh.material.opacity *= this._mouseDecayRate, S.mesh.material.opacity < 0.01 && (S.mesh.visible = !1)));
144
+ for (let m = 0; m < this._mouseObjects.length; m++) {
145
+ const b = this._mouseObjects[m];
146
+ b.mesh.visible && (i = !0, b.mesh.rotation.z += 0.01, b.mesh.material instanceof l.MeshBasicMaterial && (b.mesh.material.opacity *= this._mouseDecayRate, b.mesh.material.opacity < 0.01 && (b.mesh.visible = !1)));
147
+ }
148
+ if (i) {
149
+ w.getClearColor(this._tempClearColor);
150
+ const m = w.getClearAlpha();
151
+ w.setClearColor(0, 0), w.setRenderTarget(this._mouseFBO), w.clear(), w.render(this._sceneMouse, this._cameraMouse), w.setRenderTarget(null), w.setClearColor(this._tempClearColor, m), this._cachedUniforms && (this._cachedUniforms.u_mouse_texture.value = this._mouseFBO.texture);
136
152
  }
137
- g.getClearColor(this._tempClearColor);
138
- const w = g.getClearAlpha();
139
- g.setClearColor(0, 0), g.setRenderTarget(this._mouseFBO), g.clear(), i && g.render(this._sceneMouse, this._cameraMouse), g.setRenderTarget(null), g.setClearColor(this._tempClearColor, w), this._cachedUniforms && (this._cachedUniforms.u_mouse_texture.value = this._mouseFBO.texture);
140
153
  }
141
- g.setClearColor(this._backgroundColor, this._backgroundAlpha), g.render(O, q), this.requestRef = requestAnimationFrame(I);
142
- }, ve = () => {
143
- const { renderer: g } = this.sceneState, q = g.domElement, O = q.clientWidth, i = q.clientHeight;
144
- if (this.sceneState.renderer.setSize(O, i, !1), W(this.sceneState.camera, O, i), this._mouseFBO && this._cameraMouse) {
145
- const w = i / 2, v = O / i;
146
- this._mouseFBO.setSize(O / 2, i / 2), this._cameraMouse.left = -w * v, this._cameraMouse.right = w * v, this._cameraMouse.top = w, this._cameraMouse.bottom = -w, this._cameraMouse.updateProjectionMatrix();
154
+ w.setClearColor(this._backgroundColor, this._backgroundAlpha), w.render(T, E), this.requestRef = requestAnimationFrame(X);
155
+ }, Se = () => {
156
+ const { renderer: w } = this.sceneState, E = w.domElement, T = E.clientWidth, i = E.clientHeight;
157
+ if (this.sceneState.renderer.setSize(T, i, !1), K(this.sceneState.camera, T, i), this._mouseFBO && this._cameraMouse) {
158
+ const m = i / 2, b = T / i;
159
+ this._mouseFBO.setSize(T / 2, i / 2), this._cameraMouse.left = -m * b, this._cameraMouse.right = m * b, this._cameraMouse.top = m, this._cameraMouse.bottom = -m, this._cameraMouse.updateProjectionMatrix();
147
160
  }
148
161
  };
149
- this.sizeObserver = new ResizeObserver((g) => {
150
- ve();
151
- }), this.sizeObserver.observe(o), I();
162
+ this.sizeObserver = new ResizeObserver(() => {
163
+ this._resizeTimeoutId !== null && clearTimeout(this._resizeTimeoutId), this._resizeTimeoutId = window.setTimeout(() => {
164
+ Se(), this._resizeTimeoutId = null;
165
+ }, 100);
166
+ }), this.sizeObserver.observe(s), X();
152
167
  }
153
168
  destroy() {
154
- this && (cancelAnimationFrame(this.requestRef), this.sizeObserver.disconnect(), this.sceneState && (this.sceneState.renderer.dispose(), this.sceneState.meshes.forEach((e) => {
155
- e.geometry.dispose(), Array.isArray(e.material) ? e.material.forEach((o) => o.dispose()) : e.material.dispose();
169
+ this && (cancelAnimationFrame(this.requestRef), this.sizeObserver.disconnect(), this._resizeTimeoutId !== null && (clearTimeout(this._resizeTimeoutId), this._resizeTimeoutId = null), this.sceneState && (this.sceneState.renderer.dispose(), this.sceneState.meshes.forEach((e) => {
170
+ e.geometry.dispose(), Array.isArray(e.material) ? e.material.forEach((s) => s.dispose()) : e.material.dispose();
156
171
  })), this._mouseFBO && this._mouseFBO.dispose(), this._proceduralTexture && this._proceduralTexture.dispose());
157
172
  }
158
173
  downloadAsPNG(e = "neat.png") {
159
174
  console.log("Downloading as PNG", this._ref);
160
- const o = this._ref.toDataURL("image/png");
161
- console.log("data", o), Se(o, e);
175
+ const s = this._ref.toDataURL("image/png");
176
+ console.log("data", s), Fe(s, e);
162
177
  }
163
178
  set speed(e) {
164
179
  this._speed = e / 20;
@@ -179,7 +194,7 @@ class ze {
179
194
  this._waveAmplitude = e * 0.75;
180
195
  }
181
196
  set colors(e) {
182
- this._colors = e;
197
+ this._colors = e, this._colorsChanged = !0;
183
198
  }
184
199
  set highlights(e) {
185
200
  this._highlights = e / 100;
@@ -275,25 +290,25 @@ class ze {
275
290
  this._mouseDarken = e;
276
291
  }
277
292
  set enableProceduralTexture(e) {
278
- this._enableProceduralTexture = e, e && !this._proceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
293
+ this._enableProceduralTexture = e, e && !this._proceduralTexture && (this._textureNeedsUpdate = !0);
279
294
  }
280
295
  set textureVoidLikelihood(e) {
281
- this._textureVoidLikelihood = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
296
+ this._textureVoidLikelihood = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
282
297
  }
283
298
  set textureVoidWidthMin(e) {
284
- this._textureVoidWidthMin = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
299
+ this._textureVoidWidthMin = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
285
300
  }
286
301
  set textureVoidWidthMax(e) {
287
- this._textureVoidWidthMax = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
302
+ this._textureVoidWidthMax = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
288
303
  }
289
304
  set textureBandDensity(e) {
290
- this._textureBandDensity = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
305
+ this._textureBandDensity = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
291
306
  }
292
307
  set textureColorBlending(e) {
293
- this._textureColorBlending = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
308
+ this._textureColorBlending = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
294
309
  }
295
310
  set textureSeed(e) {
296
- this._textureSeed = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
311
+ this._textureSeed = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
297
312
  }
298
313
  get textureEase() {
299
314
  return this._textureEase;
@@ -302,58 +317,58 @@ class ze {
302
317
  this._textureEase = e;
303
318
  }
304
319
  set proceduralBackgroundColor(e) {
305
- this._proceduralBackgroundColor = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
320
+ this._proceduralBackgroundColor = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
306
321
  }
307
322
  set textureShapeTriangles(e) {
308
- this._textureShapeTriangles = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
323
+ this._textureShapeTriangles = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
309
324
  }
310
325
  set textureShapeCircles(e) {
311
- this._textureShapeCircles = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
326
+ this._textureShapeCircles = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
312
327
  }
313
328
  set textureShapeBars(e) {
314
- this._textureShapeBars = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
329
+ this._textureShapeBars = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
315
330
  }
316
331
  set textureShapeSquiggles(e) {
317
- this._textureShapeSquiggles = e, this._enableProceduralTexture && (this._proceduralTexture = this._createProceduralTexture());
332
+ this._textureShapeSquiggles = e, this._enableProceduralTexture && (this._textureNeedsUpdate = !0);
318
333
  }
319
334
  _initScene(e) {
320
- const o = this._ref.width, t = this._ref.height;
321
- this.sceneState && this.sceneState.renderer && (this.sceneState.renderer.dispose(), this.sceneState.meshes.forEach((c) => {
322
- c.geometry.dispose(), Array.isArray(c.material) ? c.material.forEach((m) => m.dispose()) : c.material.dispose();
335
+ const s = this._ref.width, t = this._ref.height;
336
+ this.sceneState && this.sceneState.renderer && (this.sceneState.renderer.dispose(), this.sceneState.meshes.forEach((u) => {
337
+ u.geometry.dispose(), Array.isArray(u.material) ? u.material.forEach((x) => x.dispose()) : u.material.dispose();
323
338
  }));
324
339
  const f = new l.WebGLRenderer({
325
340
  alpha: !0,
326
341
  preserveDrawingBuffer: !0,
327
342
  canvas: this._ref
328
343
  });
329
- f.setClearColor(16711680, 0.5), f.setSize(o, t, !1);
330
- const u = [], s = new l.Scene(), d = this._buildMaterial(o, t), x = new l.PlaneGeometry(D, E, 240 * e, 240 * e), p = new l.Mesh(x, d);
331
- p.rotation.x = -Math.PI / 3.5, p.position.z = -1, u.push(p), s.add(p);
332
- const y = new l.OrthographicCamera(0, 0, 0, 0, 0, 0);
333
- return y.position.z = 5, W(y, o, t), {
344
+ f.setClearColor(16711680, 0.5), f.setSize(s, t, !1);
345
+ const c = [], o = new l.Scene(), p = this._buildMaterial(s, t), g = new l.PlaneGeometry(U, D, 240 * e, 240 * e), d = new l.Mesh(g, p);
346
+ d.rotation.x = -Math.PI / 3.5, d.position.z = -1, c.push(d), o.add(d);
347
+ const v = new l.OrthographicCamera(0, 0, 0, 0, 0, 0);
348
+ return v.position.z = 5, K(v, s, t), {
334
349
  renderer: f,
335
- camera: y,
336
- scene: s,
337
- meshes: u,
350
+ camera: v,
351
+ scene: o,
352
+ meshes: c,
338
353
  resolution: e
339
354
  };
340
355
  }
341
- _buildMaterial(e, o) {
342
- const t = Array.from({ length: k }).map((s, d) => ({
343
- is_active: d < this._colors.length && this._colors[d].enabled ? 1 : 0,
344
- color: new l.Color(d < this._colors.length ? this._colors[d].color : 0),
345
- influence: d < this._colors.length && this._colors[d].influence || 0
356
+ _buildMaterial(e, s) {
357
+ const t = Array.from({ length: j }).map((o, p) => ({
358
+ is_active: p < this._colors.length && this._colors[p].enabled ? 1 : 0,
359
+ color: new l.Color(p < this._colors.length ? this._colors[p].color : 0),
360
+ influence: p < this._colors.length && this._colors[p].influence || 0
346
361
  })), f = {
347
362
  u_time: { value: 0 },
348
363
  u_color_pressure: { value: new l.Vector2(this._horizontalPressure, this._verticalPressure) },
349
364
  u_wave_frequency_x: { value: this._waveFrequencyX },
350
365
  u_wave_frequency_y: { value: this._waveFrequencyY },
351
366
  u_wave_amplitude: { value: this._waveAmplitude },
352
- u_resolution: { value: new l.Vector2(e, o) },
367
+ u_resolution: { value: new l.Vector2(e, s) },
353
368
  u_colors: { value: t },
354
369
  u_colors_count: { value: this._colors.length },
355
- u_plane_width: { value: D },
356
- u_plane_height: { value: E },
370
+ u_plane_width: { value: U },
371
+ u_plane_height: { value: D },
357
372
  u_shadows: { value: this._shadows },
358
373
  u_highlights: { value: this._highlights },
359
374
  u_grain_intensity: { value: this._grainIntensity },
@@ -379,19 +394,19 @@ class ze {
379
394
  u_saturation: { value: this._saturation },
380
395
  u_brightness: { value: this._brightness },
381
396
  u_color_blending: { value: this._colorBlending }
382
- }, u = new l.ShaderMaterial({
397
+ }, c = new l.ShaderMaterial({
383
398
  uniforms: f,
384
- vertexShader: V() + L() + N() + ge(),
385
- fragmentShader: V() + N() + L() + me()
399
+ vertexShader: H() + Y() + Z() + Ce(),
400
+ fragmentShader: H() + Z() + Y() + Me()
386
401
  });
387
- return this._cachedUniforms = f, u.wireframe = pe, u;
402
+ return this._cachedUniforms = f, c.wireframe = be, c;
388
403
  }
389
404
  _setupMouseInteraction() {
390
405
  if (!this._ref)
391
406
  return;
392
- const e = this._ref.width, o = this._ref.height;
393
- this._mouseFBO = new l.WebGLRenderTarget(e / 2, o / 2), this._sceneMouse = new l.Scene();
394
- const t = o / 2, f = e / o;
407
+ const e = this._ref.width, s = this._ref.height;
408
+ this._mouseFBO = new l.WebGLRenderTarget(e / 2, s / 2), this._sceneMouse = new l.Scene();
409
+ const t = s / 2, f = e / s;
395
410
  this._cameraMouse = new l.OrthographicCamera(
396
411
  -t * f,
397
412
  t * f,
@@ -400,52 +415,59 @@ class ze {
400
415
  0,
401
416
  1e4
402
417
  ), this._cameraMouse.position.set(0, 0, 100);
403
- const u = document.createElement("canvas");
404
- u.width = 128, u.height = 128;
405
- const s = u.getContext("2d");
406
- if (s) {
407
- const c = s.createRadialGradient(64, 64, 0, 64, 64, 64);
408
- c.addColorStop(0, "rgba(255,255,255,0.8)"), c.addColorStop(0.5, "rgba(255,255,255,0.4)"), c.addColorStop(1, "rgba(255,255,255,0)"), s.fillStyle = c, s.fillRect(0, 0, 128, 128);
418
+ const c = document.createElement("canvas");
419
+ c.width = 128, c.height = 128;
420
+ const o = c.getContext("2d");
421
+ if (o) {
422
+ const u = o.createRadialGradient(64, 64, 0, 64, 64, 64);
423
+ u.addColorStop(0, "rgba(255,255,255,0.8)"), u.addColorStop(0.5, "rgba(255,255,255,0.4)"), u.addColorStop(1, "rgba(255,255,255,0)"), o.fillStyle = u, o.fillRect(0, 0, 128, 128);
409
424
  }
410
- const d = new l.CanvasTexture(u), x = new l.MeshBasicMaterial({
411
- map: d,
425
+ const p = new l.CanvasTexture(c), g = new l.MeshBasicMaterial({
426
+ map: p,
412
427
  transparent: !0,
413
428
  opacity: 1,
414
429
  depthTest: !1,
415
430
  blending: l.AdditiveBlending
416
- }), p = new l.PlaneGeometry(200, 200), y = 50;
417
- for (let c = 0; c < y; c++) {
418
- const m = new l.Mesh(p, x.clone());
419
- m.visible = !1, this._sceneMouse.add(m), this._mouseObjects.push({ mesh: m, active: !1 });
431
+ }), d = new l.PlaneGeometry(200, 200), v = 50;
432
+ for (let u = 0; u < v; u++) {
433
+ const x = new l.Mesh(d, g.clone());
434
+ x.visible = !1, this._sceneMouse.add(x), this._mouseObjects.push({ mesh: x, active: !1 });
420
435
  }
421
436
  this._updateBrushScale(), this._ref.addEventListener("mousemove", this._onMouseMove.bind(this));
422
437
  }
423
438
  _onMouseMove(e) {
424
439
  if (!this._ref || !this._sceneMouse)
425
440
  return;
426
- const o = this._ref.getBoundingClientRect(), t = this._ref.width, f = this._ref.height;
427
- this._mouse.x = e.clientX - o.left - t / 2, this._mouse.y = -(e.clientY - o.top - f / 2);
428
- const u = this._mouseObjects[this._currentBrush];
429
- u.mesh.scale.set(this._mouseBrushBaseScale, this._mouseBrushBaseScale, 1), u.active = !0, u.mesh.visible = !0, u.mesh.position.set(this._mouse.x, this._mouse.y, 0), u.mesh.rotation.z = Math.random() * Math.PI * 2, u.mesh.material instanceof l.MeshBasicMaterial && (u.mesh.material.opacity = 1), this._currentBrush = (this._currentBrush + 1) % this._mouseObjects.length;
441
+ const s = this._ref.getBoundingClientRect(), t = this._ref.width, f = this._ref.height;
442
+ this._pendingMousePosition = {
443
+ x: e.clientX - s.left - t / 2,
444
+ y: -(e.clientY - s.top - f / 2)
445
+ }, this._mouseUpdateScheduled || (this._mouseUpdateScheduled = !0, requestAnimationFrame(() => {
446
+ if (this._mouseUpdateScheduled = !1, !this._pendingMousePosition)
447
+ return;
448
+ this._mouse.x = this._pendingMousePosition.x, this._mouse.y = this._pendingMousePosition.y;
449
+ const c = this._mouseObjects[this._currentBrush];
450
+ c.mesh.scale.set(this._mouseBrushBaseScale, this._mouseBrushBaseScale, 1), c.active = !0, c.mesh.visible = !0, c.mesh.position.set(this._mouse.x, this._mouse.y, 0), c.mesh.rotation.z = Math.random() * Math.PI * 2, c.mesh.material instanceof l.MeshBasicMaterial && (c.mesh.material.opacity = 1), this._currentBrush = (this._currentBrush + 1) % this._mouseObjects.length, this._pendingMousePosition = null;
451
+ }));
430
452
  }
431
453
  _createProceduralTexture() {
432
- const o = document.createElement("canvas");
433
- o.width = 1024, o.height = 1024;
434
- const t = o.getContext("2d");
454
+ const s = document.createElement("canvas");
455
+ s.width = 1024, s.height = 1024;
456
+ const t = s.getContext("2d", { willReadFrequently: !0 });
435
457
  if (!t)
436
458
  return new l.Texture();
437
459
  let f = this._textureSeed;
438
- const u = this._textureSeed;
439
- function s() {
460
+ const c = this._textureSeed;
461
+ function o() {
440
462
  const a = Math.sin(f++) * 1e4;
441
463
  return a - Math.floor(a);
442
464
  }
443
- const d = (a) => {
444
- f = u + a;
445
- }, x = this._colors.filter((a) => a.enabled).map((a) => a.color);
446
- if (x.length === 0)
465
+ const p = (a) => {
466
+ f = c + a;
467
+ }, g = this._colors.filter((a) => a.enabled).map((a) => a.color);
468
+ if (g.length === 0)
447
469
  return new l.Texture();
448
- function p(a) {
470
+ function d(a) {
449
471
  const n = parseInt(a.replace("#", ""), 16);
450
472
  return {
451
473
  r: n >> 16 & 255,
@@ -453,90 +475,99 @@ class ze {
453
475
  b: n & 255
454
476
  };
455
477
  }
456
- function y(a, n, h) {
478
+ function v(a, n, h) {
457
479
  return "#" + ((1 << 24) + (Math.round(a) << 16) + (Math.round(n) << 8) + Math.round(h)).toString(16).slice(1);
458
480
  }
459
- const c = () => {
460
- const a = x[Math.floor(s() * x.length)], n = x[Math.floor(s() * x.length)], h = s() * this._textureColorBlending, _ = p(a), b = p(n), F = _.r + (b.r - _.r) * h, A = _.g + (b.g - _.g) * h, R = _.b + (b.b - _.b) * h;
461
- return y(F, A, R);
462
- }, m = this._proceduralBackgroundColor || "#000000";
463
- t.fillStyle = m, t.fillRect(0, 0, 1024, 1024);
464
- const P = t.createLinearGradient(0, 0, 0, 1024);
465
- P.addColorStop(0, c()), P.addColorStop(1, c()), t.fillStyle = P, t.fillRect(0, 0, 1024, 1024);
481
+ const u = () => {
482
+ const a = g[Math.floor(o() * g.length)], n = g[Math.floor(o() * g.length)], h = o() * this._textureColorBlending, _ = d(a), S = d(n), B = _.r + (S.r - _.r) * h, N = _.g + (S.g - _.g) * h, V = _.b + (S.b - _.b) * h;
483
+ return v(B, N, V);
484
+ }, x = this._proceduralBackgroundColor || "#000000";
485
+ t.fillStyle = x, t.fillRect(0, 0, 1024, 1024);
486
+ const O = t.createLinearGradient(0, 0, 0, 1024);
487
+ O.addColorStop(0, u()), O.addColorStop(1, u()), t.fillStyle = O, t.fillRect(0, 0, 1024, 1024);
466
488
  for (let a = 0; a < this._textureShapeTriangles; a++) {
467
- t.fillStyle = c(), t.beginPath();
468
- const n = s() * 1024, h = s() * 1024, _ = 100 + s() * 300;
469
- t.moveTo(n, h), t.lineTo(n + (s() - 0.5) * _, h + (s() - 0.5) * _), t.lineTo(n + (s() - 0.5) * _, h + (s() - 0.5) * _), t.fill();
489
+ t.fillStyle = u(), t.beginPath();
490
+ const n = o() * 1024, h = o() * 1024, _ = 100 + o() * 300;
491
+ t.moveTo(n, h), t.lineTo(n + (o() - 0.5) * _, h + (o() - 0.5) * _), t.lineTo(n + (o() - 0.5) * _, h + (o() - 0.5) * _), t.fill();
470
492
  }
471
493
  for (let a = 0; a < this._textureShapeCircles; a++) {
472
- t.strokeStyle = c(), t.lineWidth = 10 + s() * 50, t.beginPath();
473
- const n = s() * 1024, h = s() * 1024, _ = 50 + s() * 150;
494
+ t.strokeStyle = u(), t.lineWidth = 10 + o() * 50, t.beginPath();
495
+ const n = o() * 1024, h = o() * 1024, _ = 50 + o() * 150;
474
496
  t.arc(n, h, _, 0, Math.PI * 2), t.stroke();
475
497
  }
476
498
  for (let a = 0; a < this._textureShapeBars; a++)
477
- t.fillStyle = c(), t.save(), t.translate(s() * 1024, s() * 1024), t.rotate(s() * Math.PI), t.fillRect(-150, -25, 300, 50), t.restore();
499
+ t.fillStyle = u(), t.save(), t.translate(o() * 1024, o() * 1024), t.rotate(o() * Math.PI), t.fillRect(-150, -25, 300, 50), t.restore();
478
500
  t.lineWidth = 15, t.lineCap = "round";
479
501
  for (let a = 0; a < this._textureShapeSquiggles; a++) {
480
- t.strokeStyle = c(), t.beginPath();
481
- let n = s() * 1024, h = s() * 1024;
502
+ t.strokeStyle = u(), t.beginPath();
503
+ let n = o() * 1024, h = o() * 1024;
482
504
  t.moveTo(n, h);
483
505
  for (let _ = 0; _ < 4; _++)
484
506
  t.bezierCurveTo(
485
- n + (s() - 0.5) * 300,
486
- h + (s() - 0.5) * 300,
487
- n + (s() - 0.5) * 300,
488
- h + (s() - 0.5) * 300,
489
- n + (s() - 0.5) * 300,
490
- h + (s() - 0.5) * 300
491
- ), n += (s() - 0.5) * 300, h += (s() - 0.5) * 300;
507
+ n + (o() - 0.5) * 300,
508
+ h + (o() - 0.5) * 300,
509
+ n + (o() - 0.5) * 300,
510
+ h + (o() - 0.5) * 300,
511
+ n + (o() - 0.5) * 300,
512
+ h + (o() - 0.5) * 300
513
+ ), n += (o() - 0.5) * 300, h += (o() - 0.5) * 300;
492
514
  t.stroke();
493
515
  }
494
- d(5e4);
516
+ p(5e4);
495
517
  const M = document.createElement("canvas");
496
518
  M.width = 1024, M.height = 1024;
497
- const T = M.getContext("2d");
498
- if (!T)
519
+ const z = M.getContext("2d", { willReadFrequently: !0 });
520
+ if (!z)
499
521
  return new l.Texture();
500
- T.fillStyle = m, T.fillRect(0, 0, 1024, 1024);
501
- let C = 0;
502
- const B = [];
503
- for (; C < 1024; )
504
- if (s() < this._textureVoidLikelihood) {
505
- const n = this._textureVoidWidthMin + s() * (this._textureVoidWidthMax - this._textureVoidWidthMin);
506
- B.push({ type: "void", x: C, width: n }), C += n;
522
+ z.fillStyle = x, z.fillRect(0, 0, 1024, 1024);
523
+ let y = 0;
524
+ const F = [];
525
+ for (; y < 1024; )
526
+ if (o() < this._textureVoidLikelihood) {
527
+ const n = this._textureVoidWidthMin + o() * (this._textureVoidWidthMax - this._textureVoidWidthMin);
528
+ F.push({ type: "void", x: y, width: n }), y += n;
507
529
  } else {
508
- const n = 50 + s() * 200;
509
- B.push({ type: "matter", x: C, width: n }), C += n;
530
+ const n = 50 + o() * 200;
531
+ F.push({ type: "matter", x: y, width: n }), y += n;
510
532
  }
511
- for (const a of B)
533
+ for (const a of F)
512
534
  if (a.type === "matter") {
513
535
  const n = a.x, h = Math.min(a.x + a.width, 1024);
514
536
  let _ = n;
515
537
  for (; _ < h; ) {
516
- const b = (2 + s() * 20) / this._textureBandDensity, F = Math.floor(s() * 1024);
517
- T.drawImage(
518
- o,
519
- F,
538
+ const S = (2 + o() * 20) / this._textureBandDensity, B = Math.floor(o() * 1024);
539
+ z.drawImage(
540
+ s,
541
+ B,
520
542
  0,
521
- b,
543
+ S,
522
544
  1024,
523
545
  _,
524
546
  0,
525
- b,
547
+ S,
526
548
  1024
527
- ), _ += b;
549
+ ), _ += S;
528
550
  }
529
551
  }
530
- const z = new l.CanvasTexture(M);
531
- return z.minFilter = l.LinearMipmapLinearFilter, z.magFilter = l.LinearFilter, z.wrapS = l.RepeatWrapping, z.wrapT = l.RepeatWrapping, z.anisotropy = 16, z.needsUpdate = !0, z;
552
+ const C = new l.CanvasTexture(M);
553
+ return C.minFilter = l.LinearMipmapLinearFilter, C.magFilter = l.LinearFilter, C.wrapS = l.RepeatWrapping, C.wrapT = l.RepeatWrapping, C.anisotropy = 16, C.needsUpdate = !0, C;
532
554
  }
533
555
  }
534
- function W(r, e, o) {
535
- const u = e * o / 1e6 * D * E / 1.5, s = e / o, d = Math.sqrt(u * s), x = u / d, p = -D / 2, y = Math.min((p + d) / 1.5, D / 2), c = E / 4, m = Math.max((c - x) / 2, -E / 4), P = -100, M = 1e3;
536
- r instanceof l.OrthographicCamera ? (r.left = p, r.right = y, r.top = c, r.bottom = m, r.near = P, r.far = M, r.updateProjectionMatrix()) : r instanceof l.PerspectiveCamera && (r.aspect = e / o, r.updateProjectionMatrix());
556
+ function K(r, e, s) {
557
+ const c = e * s / 1e6 * U * D / 1.5, o = e / s, p = Math.sqrt(c * o), g = c / p;
558
+ let d = -U / 2, v = Math.min((d + p) / 1.5, U / 2), u = D / 4, x = Math.max((u - g) / 2, -D / 4);
559
+ if (o < 1) {
560
+ const z = o;
561
+ d = d * z, v = v * z;
562
+ const y = 1.05;
563
+ d = d * y, v = v * y, u = u * y, x = x * y;
564
+ }
565
+ const O = -100, M = 1e3;
566
+ r instanceof l.OrthographicCamera ? (r.left = d, r.right = v, r.top = u, r.bottom = x, r.near = O, r.far = M, r.updateProjectionMatrix()) : r instanceof l.PerspectiveCamera && (r.aspect = e / s, r.updateProjectionMatrix());
537
567
  }
538
- function ge() {
539
- return `
568
+ let R = null, A = null;
569
+ function Ce() {
570
+ return R || (R = `
540
571
  void main() {
541
572
  vUv = uv;
542
573
 
@@ -613,10 +644,10 @@ void main() {
613
644
  gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
614
645
  v_new_position = gl_Position;
615
646
  }
616
- `;
647
+ `, R);
617
648
  }
618
- function me() {
619
- return `
649
+ function Me() {
650
+ return A || (A = `
620
651
  float random(vec2 p) {
621
652
  return fract(sin(dot(p, vec2(12.9898,78.233))) * 43758.5453);
622
653
  }
@@ -698,9 +729,10 @@ void main() {
698
729
 
699
730
  gl_FragColor = vec4(color, 1.0);
700
731
  }
701
- `;
732
+ `, A);
702
733
  }
703
- const V = () => `
734
+ let k = null;
735
+ const H = () => k || (k = `
704
736
  precision highp float;
705
737
 
706
738
  struct Color {
@@ -764,7 +796,9 @@ varying vec4 v_new_position;
764
796
  varying vec3 v_color;
765
797
  varying float v_displacement_amount;
766
798
 
767
- `, L = () => `
799
+ `, k);
800
+ let I = null;
801
+ const Y = () => I || (I = `
768
802
 
769
803
  // 1. REPLACEMENT PERMUTE:
770
804
  // Uses a hash function (fract/sin) instead of a modular lookup table.
@@ -917,7 +951,9 @@ float cnoise(vec3 P)
917
951
  float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
918
952
  return 2.2 * n_xyz;
919
953
  }
920
- `, N = () => `
954
+ `, I);
955
+ let W = null;
956
+ const Z = () => W || (W = `
921
957
 
922
958
  vec3 saturation(vec3 rgb, float adjustment) {
923
959
  const vec3 W = vec3(0.2125, 0.7154, 0.0721);
@@ -960,36 +996,36 @@ vec3 hsv2rgb(vec3 c)
960
996
  vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
961
997
  return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
962
998
  }
963
- `, j = (r) => {
964
- r.id = G, r.href = "https://neat.firecms.co", r.target = "_blank", r.style.position = "absolute", r.style.display = "block", r.style.bottom = "0", r.style.right = "0", r.style.padding = "10px", r.style.color = "#dcdcdc", r.style.opacity = "0.8", r.style.fontFamily = "sans-serif", r.style.fontSize = "16px", r.style.fontWeight = "bold", r.style.textDecoration = "none", r.style.zIndex = "10000", r.innerHTML = "NEAT";
965
- }, ye = (r) => {
999
+ `, W), J = (r) => {
1000
+ r.id = Q, r.href = "https://neat.firecms.co", r.target = "_blank", r.style.position = "absolute", r.style.display = "block", r.style.bottom = "0", r.style.right = "0", r.style.padding = "10px", r.style.color = "#dcdcdc", r.style.opacity = "0.8", r.style.fontFamily = "sans-serif", r.style.fontSize = "16px", r.style.fontWeight = "bold", r.style.textDecoration = "none", r.style.zIndex = "10000", r.innerHTML = "NEAT";
1001
+ }, Pe = (r) => {
966
1002
  const e = r.parentElement?.getElementsByTagName("a");
967
1003
  if (e) {
968
1004
  for (let t = 0; t < e.length; t++)
969
- if (e[t].id === G)
970
- return j(e[t]), e[t];
1005
+ if (e[t].id === Q)
1006
+ return J(e[t]), e[t];
971
1007
  }
972
- const o = document.createElement("a");
973
- return j(o), r.parentElement?.appendChild(o), o;
1008
+ const s = document.createElement("a");
1009
+ return J(s), r.parentElement?.appendChild(s), s;
974
1010
  };
975
- function we() {
976
- const r = new Date(), e = r.getMinutes(), o = r.getSeconds();
977
- return e * 60 + o;
1011
+ function Oe() {
1012
+ const r = new Date(), e = r.getMinutes(), s = r.getSeconds();
1013
+ return e * 60 + s;
978
1014
  }
979
- function be(r = 6) {
1015
+ function Te(r = 6) {
980
1016
  const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
981
- let o = "";
1017
+ let s = "";
982
1018
  for (let t = 0; t < r; t++) {
983
1019
  const f = Math.floor(Math.random() * e.length);
984
- o += e.charAt(f);
1020
+ s += e.charAt(f);
985
1021
  }
986
- return o;
1022
+ return s;
987
1023
  }
988
- function Se(r, e) {
989
- const o = document.createElement("a");
990
- o.download = e, o.href = r, document.body.appendChild(o), o.click(), document.body.removeChild(o);
1024
+ function Fe(r, e) {
1025
+ const s = document.createElement("a");
1026
+ s.download = e, s.href = r, document.body.appendChild(s), s.click(), document.body.removeChild(s);
991
1027
  }
992
1028
  export {
993
- ze as NeatGradient
1029
+ Be as NeatGradient
994
1030
  };
995
1031
  //# sourceMappingURL=index.es.js.map