@joshtol/emotive-engine 3.3.1 → 3.3.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@joshtol/emotive-engine",
4
- "version": "3.3.1",
4
+ "version": "3.3.3",
5
5
  "description": "Open-source animation engine for AI-controlled emotional visualizations with musical time synchronization",
6
6
  "main": "dist/emotive-mascot.umd.js",
7
7
  "module": "dist/mascot.js",
@@ -39,7 +39,7 @@ vec3 rgbToHsl(vec3 rgb) {
39
39
  float l = (maxC + minC) / 2.0;
40
40
 
41
41
  if (delta > 0.0001) {
42
- s = l < 0.5 ? delta / (maxC + minC) : delta / (2.0 - maxC - minC);
42
+ s = l < 0.5 ? delta / max(maxC + minC, 0.0001) : delta / max(2.0 - maxC - minC, 0.0001);
43
43
 
44
44
  // Use tolerance-based comparison instead of exact equality
45
45
  float eps = 0.0001;
@@ -135,18 +135,20 @@ vec3 applyBlendMode(vec3 base, vec3 blend, int mode) {
135
135
  } else if (mode == 2) {
136
136
  // COLOR BURN: (blend==0.0) ? 0.0 : max((1.0-((1.0-base)/blend)), 0.0)
137
137
  // Darkens base color to reflect blend color by increasing contrast
138
+ // Use safe division with epsilon to avoid division by zero
138
139
  return vec3(
139
- blend.r == 0.0 ? 0.0 : max(1.0 - ((1.0 - base.r) / blend.r), 0.0),
140
- blend.g == 0.0 ? 0.0 : max(1.0 - ((1.0 - base.g) / blend.g), 0.0),
141
- blend.b == 0.0 ? 0.0 : max(1.0 - ((1.0 - base.b) / blend.b), 0.0)
140
+ max(1.0 - ((1.0 - base.r) / max(blend.r, 0.0001)), 0.0),
141
+ max(1.0 - ((1.0 - base.g) / max(blend.g, 0.0001)), 0.0),
142
+ max(1.0 - ((1.0 - base.b) / max(blend.b, 0.0001)), 0.0)
142
143
  );
143
144
  } else if (mode == 3) {
144
145
  // COLOR DODGE: (blend==1.0) ? 1.0 : min(base/(1.0-blend), 1.0)
145
146
  // Brightens base color to reflect blend color by decreasing contrast
147
+ // Use safe division with epsilon to avoid division by zero
146
148
  return vec3(
147
- blend.r == 1.0 ? 1.0 : min(base.r / (1.0 - blend.r), 1.0),
148
- blend.g == 1.0 ? 1.0 : min(base.g / (1.0 - blend.g), 1.0),
149
- blend.b == 1.0 ? 1.0 : min(base.b / (1.0 - blend.b), 1.0)
149
+ min(base.r / max(1.0 - blend.r, 0.0001), 1.0),
150
+ min(base.g / max(1.0 - blend.g, 0.0001), 1.0),
151
+ min(base.b / max(1.0 - blend.b, 0.0001), 1.0)
150
152
  );
151
153
  } else if (mode == 4) {
152
154
  // SCREEN: 1 - (1 - base) * (1 - blend)
@@ -183,10 +185,11 @@ vec3 applyBlendMode(vec3 base, vec3 blend, int mode) {
183
185
  } else if (mode == 9) {
184
186
  // VIVID LIGHT: blend < 0.5 ? ColorBurn(base, 2*blend) : ColorDodge(base, 2*(blend-0.5))
185
187
  // Burns or dodges by increasing/decreasing contrast - extreme saturation boost
188
+ // Use safe division with epsilon to avoid division by zero
186
189
  return vec3(
187
- blend.r < 0.5 ? (blend.r == 0.0 ? 0.0 : max(1.0 - ((1.0 - base.r) / (2.0 * blend.r)), 0.0)) : (blend.r == 1.0 ? 1.0 : min(base.r / (2.0 * (1.0 - blend.r)), 1.0)),
188
- blend.g < 0.5 ? (blend.g == 0.0 ? 0.0 : max(1.0 - ((1.0 - base.g) / (2.0 * blend.g)), 0.0)) : (blend.g == 1.0 ? 1.0 : min(base.g / (2.0 * (1.0 - blend.g)), 1.0)),
189
- blend.b < 0.5 ? (blend.b == 0.0 ? 0.0 : max(1.0 - ((1.0 - base.b) / (2.0 * blend.b)), 0.0)) : (blend.b == 1.0 ? 1.0 : min(base.b / (2.0 * (1.0 - blend.b)), 1.0))
190
+ blend.r < 0.5 ? max(1.0 - ((1.0 - base.r) / max(2.0 * blend.r, 0.0001)), 0.0) : min(base.r / max(2.0 * (1.0 - blend.r), 0.0001), 1.0),
191
+ blend.g < 0.5 ? max(1.0 - ((1.0 - base.g) / max(2.0 * blend.g, 0.0001)), 0.0) : min(base.g / max(2.0 * (1.0 - blend.g), 0.0001), 1.0),
192
+ blend.b < 0.5 ? max(1.0 - ((1.0 - base.b) / max(2.0 * blend.b, 0.0001)), 0.0) : min(base.b / max(2.0 * (1.0 - blend.b), 0.0001), 1.0)
190
193
  );
191
194
  } else if (mode == 10) {
192
195
  // LINEAR LIGHT: blend < 0.5 ? LinearBurn(base, 2*blend) : LinearDodge(base, 2*(blend-0.5))