@tsparticles/updater-color 3.0.0-alpha.1 → 3.0.0-beta.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.
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.1
7
+ * v3.0.0-beta.1
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,22 +91,29 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadColorUpdater": () => (/* binding */ loadColorUpdater)
94
+ loadColorUpdater: () => (/* binding */ loadColorUpdater)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
98
98
  var engine_root_window_ = __webpack_require__(533);
99
- ;// CONCATENATED MODULE: ./dist/browser/ColorUpdater.js
99
+ ;// CONCATENATED MODULE: ./dist/browser/Utils.js
100
100
 
101
- function updateColorValue(delta, value, valueAnimation, max, decrease) {
102
- var _a, _b;
103
- const colorValue = value;
104
- if (!colorValue || !valueAnimation.enable || colorValue.loops !== undefined && colorValue.maxLoops !== undefined && colorValue.maxLoops > 0 && colorValue.loops >= colorValue.maxLoops) {
101
+ function updateColorValue(delta, colorValue, valueAnimation, max, decrease) {
102
+ if (!colorValue || !valueAnimation.enable || (colorValue.maxLoops ?? 0) > 0 && (colorValue.loops ?? 0) > (colorValue.maxLoops ?? 0)) {
103
+ return;
104
+ }
105
+ if (!colorValue.time) {
106
+ colorValue.time = 0;
107
+ }
108
+ if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
109
+ colorValue.time += delta.value;
110
+ }
111
+ if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
105
112
  return;
106
113
  }
107
114
  const offset = (0,engine_root_window_.randomInRange)(valueAnimation.offset),
108
- velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6,
109
- decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
115
+ velocity = (colorValue.velocity ?? 0) * delta.factor + offset * 3.6,
116
+ decay = colorValue.decay ?? 1;
110
117
  if (!decrease || colorValue.status === "increasing") {
111
118
  colorValue.value += velocity;
112
119
  if (colorValue.value > max) {
@@ -138,21 +145,35 @@ function updateColorValue(delta, value, valueAnimation, max, decrease) {
138
145
  }
139
146
  }
140
147
  function updateColor(particle, delta) {
141
- var _a, _b, _c;
142
- const animationOptions = particle.options.color.animation;
143
- const h = (_a = particle.color) === null || _a === void 0 ? void 0 : _a.h,
144
- s = (_b = particle.color) === null || _b === void 0 ? void 0 : _b.s,
145
- l = (_c = particle.color) === null || _c === void 0 ? void 0 : _c.l;
148
+ const {
149
+ h: hAnimation,
150
+ s: sAnimation,
151
+ l: lAnimation
152
+ } = particle.options.color.animation,
153
+ {
154
+ color
155
+ } = particle;
156
+ if (!color) {
157
+ return;
158
+ }
159
+ const {
160
+ h,
161
+ s,
162
+ l
163
+ } = color;
146
164
  if (h) {
147
- updateColorValue(delta, h, animationOptions.h, 360, false);
165
+ updateColorValue(delta, h, hAnimation, 360, false);
148
166
  }
149
167
  if (s) {
150
- updateColorValue(delta, s, animationOptions.s, 100, true);
168
+ updateColorValue(delta, s, sAnimation, 100, true);
151
169
  }
152
170
  if (l) {
153
- updateColorValue(delta, l, animationOptions.l, 100, true);
171
+ updateColorValue(delta, l, lAnimation, 100, true);
154
172
  }
155
173
  }
174
+ ;// CONCATENATED MODULE: ./dist/browser/ColorUpdater.js
175
+
176
+
156
177
  class ColorUpdater {
157
178
  constructor(container) {
158
179
  this.container = container;
@@ -164,9 +185,15 @@ class ColorUpdater {
164
185
  }
165
186
  }
166
187
  isEnabled(particle) {
167
- var _a, _b, _c;
168
- const animationOptions = particle.options.color.animation;
169
- return !particle.destroyed && !particle.spawning && (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h.value) !== undefined && animationOptions.h.enable || ((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s.value) !== undefined && animationOptions.s.enable || ((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l.value) !== undefined && animationOptions.l.enable);
188
+ const {
189
+ h: hAnimation,
190
+ s: sAnimation,
191
+ l: lAnimation
192
+ } = particle.options.color.animation,
193
+ {
194
+ color
195
+ } = particle;
196
+ return !particle.destroyed && !particle.spawning && (color?.h.value !== undefined && hAnimation.enable || color?.s.value !== undefined && sAnimation.enable || color?.l.value !== undefined && lAnimation.enable);
170
197
  }
171
198
  update(particle, delta) {
172
199
  updateColor(particle, delta);
@@ -174,8 +201,8 @@ class ColorUpdater {
174
201
  }
175
202
  ;// CONCATENATED MODULE: ./dist/browser/index.js
176
203
 
177
- async function loadColorUpdater(engine) {
178
- await engine.addParticleUpdater("color", container => new ColorUpdater(container));
204
+ async function loadColorUpdater(engine, refresh = true) {
205
+ await engine.addParticleUpdater("color", container => new ColorUpdater(container), refresh);
179
206
  }
180
207
  })();
181
208
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.color.min.js.LICENSE.txt */
2
- !function(o,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var t="object"==typeof exports?e(require("@tsparticles/engine")):e(o.window);for(var n in t)("object"==typeof exports?exports:o)[n]=t[n]}}(this,(o=>(()=>{"use strict";var e={533:e=>{e.exports=o}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var l=t[o]={exports:{}};return e[o](l,l.exports,n),l.exports}n.d=(o,e)=>{for(var t in e)n.o(e,t)&&!n.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:e[t]})},n.o=(o,e)=>Object.prototype.hasOwnProperty.call(o,e),n.r=o=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{loadColorUpdater:()=>l});var o=n(533);function e(e,t,n,r,l){var i,a;const s=t;if(!s||!n.enable||void 0!==s.loops&&void 0!==s.maxLoops&&s.maxLoops>0&&s.loops>=s.maxLoops)return;const c=(0,o.randomInRange)(n.offset),d=(null!==(i=t.velocity)&&void 0!==i?i:0)*e.factor+3.6*c,u=null!==(a=t.decay)&&void 0!==a?a:1;l&&"increasing"!==s.status?(s.value-=d,s.value<0&&(s.loops||(s.loops=0),s.loops++,s.status="increasing",s.value+=s.value)):(s.value+=d,s.value>r&&(s.loops||(s.loops=0),s.loops++,l&&(s.status="decreasing",s.value-=s.value%r))),s.velocity&&1!==u&&(s.velocity*=u),s.value>r&&(s.value%=r)}class t{constructor(o){this.container=o}init(e){const t=(0,o.rangeColorToHsl)(e.options.color,e.id,e.options.reduceDuplicates);t&&(e.color=(0,o.getHslAnimationFromHsl)(t,e.options.color.animation,this.container.retina.reduceFactor))}isEnabled(o){var e,t,n;const r=o.options.color.animation;return!o.destroyed&&!o.spawning&&(void 0!==(null===(e=o.color)||void 0===e?void 0:e.h.value)&&r.h.enable||void 0!==(null===(t=o.color)||void 0===t?void 0:t.s.value)&&r.s.enable||void 0!==(null===(n=o.color)||void 0===n?void 0:n.l.value)&&r.l.enable)}update(o,t){!function(o,t){var n,r,l;const i=o.options.color.animation,a=null===(n=o.color)||void 0===n?void 0:n.h,s=null===(r=o.color)||void 0===r?void 0:r.s,c=null===(l=o.color)||void 0===l?void 0:l.l;a&&e(t,a,i.h,360,!1),s&&e(t,s,i.s,100,!0),c&&e(t,c,i.l,100,!0)}(o,t)}}async function l(o){await o.addParticleUpdater("color",(o=>new t(o)))}})(),r})()));
2
+ !function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],o);else{var t="object"==typeof exports?o(require("@tsparticles/engine")):o(e.window);for(var r in t)("object"==typeof exports?exports:e)[r]=t[r]}}(this,(e=>(()=>{"use strict";var o={533:o=>{o.exports=e}},t={};function r(e){var n=t[e];if(void 0!==n)return n.exports;var i=t[e]={exports:{}};return o[e](i,i.exports,r),i.exports}r.d=(e,o)=>{for(var t in o)r.o(o,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},r.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{loadColorUpdater:()=>i});var e=r(533);function o(o,t,r,n,i){if(!t||!r.enable||(t.maxLoops??0)>0&&(t.loops??0)>(t.maxLoops??0))return;if(t.time||(t.time=0),(t.delayTime??0)>0&&t.time<(t.delayTime??0)&&(t.time+=o.value),(t.delayTime??0)>0&&t.time<(t.delayTime??0))return;const a=(0,e.randomInRange)(r.offset),l=(t.velocity??0)*o.factor+3.6*a,s=t.decay??1;i&&"increasing"!==t.status?(t.value-=l,t.value<0&&(t.loops||(t.loops=0),t.loops++,t.status="increasing",t.value+=t.value)):(t.value+=l,t.value>n&&(t.loops||(t.loops=0),t.loops++,i&&(t.status="decreasing",t.value-=t.value%n))),t.velocity&&1!==s&&(t.velocity*=s),t.value>n&&(t.value%=n)}class t{constructor(e){this.container=e}init(o){const t=(0,e.rangeColorToHsl)(o.options.color,o.id,o.options.reduceDuplicates);t&&(o.color=(0,e.getHslAnimationFromHsl)(t,o.options.color.animation,this.container.retina.reduceFactor))}isEnabled(e){const{h:o,s:t,l:r}=e.options.color.animation,{color:n}=e;return!e.destroyed&&!e.spawning&&(void 0!==n?.h.value&&o.enable||void 0!==n?.s.value&&t.enable||void 0!==n?.l.value&&r.enable)}update(e,t){!function(e,t){const{h:r,s:n,l:i}=e.options.color.animation,{color:a}=e;if(!a)return;const{h:l,s,l:c}=a;l&&o(t,l,r,360,!1),s&&o(t,s,n,100,!0),c&&o(t,c,i,100,!0)}(e,t)}}async function i(e,o=!0){await e.addParticleUpdater("color",(e=>new t(e)),o)}})(),n})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.1
8
- */
1
+ /*! tsParticles Color Updater v3.0.0-beta.1 by Matteo Bruni */
@@ -1,4 +1,4 @@
1
- import type { Container, IDelta, IParticleUpdater, Particle } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, type IParticleUpdater, type Particle } from "@tsparticles/engine";
2
2
  export declare class ColorUpdater implements IParticleUpdater {
3
3
  private readonly container;
4
4
  constructor(container: Container);
@@ -0,0 +1,2 @@
1
+ import { type IDelta, type Particle } from "@tsparticles/engine";
2
+ export declare function updateColor(particle: Particle, delta: IDelta): void;
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadColorUpdater(engine: Engine): Promise<void>;
2
+ export declare function loadColorUpdater(engine: Engine, refresh?: boolean): Promise<void>;
@@ -4,70 +4,14 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Utils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ColorUpdater = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
- function updateColorValue(delta, value, valueAnimation, max, decrease) {
15
- var _a, _b;
16
- const colorValue = value;
17
- if (!colorValue ||
18
- !valueAnimation.enable ||
19
- (colorValue.loops !== undefined &&
20
- colorValue.maxLoops !== undefined &&
21
- colorValue.maxLoops > 0 &&
22
- colorValue.loops >= colorValue.maxLoops)) {
23
- return;
24
- }
25
- const offset = (0, engine_1.randomInRange)(valueAnimation.offset), velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
26
- if (!decrease || colorValue.status === "increasing") {
27
- colorValue.value += velocity;
28
- if (colorValue.value > max) {
29
- if (!colorValue.loops) {
30
- colorValue.loops = 0;
31
- }
32
- colorValue.loops++;
33
- if (decrease) {
34
- colorValue.status = "decreasing";
35
- colorValue.value -= colorValue.value % max;
36
- }
37
- }
38
- }
39
- else {
40
- colorValue.value -= velocity;
41
- if (colorValue.value < 0) {
42
- if (!colorValue.loops) {
43
- colorValue.loops = 0;
44
- }
45
- colorValue.loops++;
46
- colorValue.status = "increasing";
47
- colorValue.value += colorValue.value;
48
- }
49
- }
50
- if (colorValue.velocity && decay !== 1) {
51
- colorValue.velocity *= decay;
52
- }
53
- if (colorValue.value > max) {
54
- colorValue.value %= max;
55
- }
56
- }
57
- function updateColor(particle, delta) {
58
- var _a, _b, _c;
59
- const animationOptions = particle.options.color.animation;
60
- const h = (_a = particle.color) === null || _a === void 0 ? void 0 : _a.h, s = (_b = particle.color) === null || _b === void 0 ? void 0 : _b.s, l = (_c = particle.color) === null || _c === void 0 ? void 0 : _c.l;
61
- if (h) {
62
- updateColorValue(delta, h, animationOptions.h, 360, false);
63
- }
64
- if (s) {
65
- updateColorValue(delta, s, animationOptions.s, 100, true);
66
- }
67
- if (l) {
68
- updateColorValue(delta, l, animationOptions.l, 100, true);
69
- }
70
- }
14
+ const Utils_js_1 = require("./Utils.js");
71
15
  class ColorUpdater {
72
16
  constructor(container) {
73
17
  this.container = container;
@@ -79,16 +23,15 @@
79
23
  }
80
24
  }
81
25
  isEnabled(particle) {
82
- var _a, _b, _c;
83
- const animationOptions = particle.options.color.animation;
26
+ const { h: hAnimation, s: sAnimation, l: lAnimation } = particle.options.color.animation, { color } = particle;
84
27
  return (!particle.destroyed &&
85
28
  !particle.spawning &&
86
- ((((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h.value) !== undefined && animationOptions.h.enable) ||
87
- (((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s.value) !== undefined && animationOptions.s.enable) ||
88
- (((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l.value) !== undefined && animationOptions.l.enable)));
29
+ ((color?.h.value !== undefined && hAnimation.enable) ||
30
+ (color?.s.value !== undefined && sAnimation.enable) ||
31
+ (color?.l.value !== undefined && lAnimation.enable)));
89
32
  }
90
33
  update(particle, delta) {
91
- updateColor(particle, delta);
34
+ (0, Utils_js_1.updateColor)(particle, delta);
92
35
  }
93
36
  }
94
37
  exports.ColorUpdater = ColorUpdater;
package/umd/Utils.js ADDED
@@ -0,0 +1,78 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.updateColor = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ function updateColorValue(delta, colorValue, valueAnimation, max, decrease) {
15
+ if (!colorValue ||
16
+ !valueAnimation.enable ||
17
+ ((colorValue.maxLoops ?? 0) > 0 && (colorValue.loops ?? 0) > (colorValue.maxLoops ?? 0))) {
18
+ return;
19
+ }
20
+ if (!colorValue.time) {
21
+ colorValue.time = 0;
22
+ }
23
+ if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
24
+ colorValue.time += delta.value;
25
+ }
26
+ if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
27
+ return;
28
+ }
29
+ const offset = (0, engine_1.randomInRange)(valueAnimation.offset), velocity = (colorValue.velocity ?? 0) * delta.factor + offset * 3.6, decay = colorValue.decay ?? 1;
30
+ if (!decrease || colorValue.status === "increasing") {
31
+ colorValue.value += velocity;
32
+ if (colorValue.value > max) {
33
+ if (!colorValue.loops) {
34
+ colorValue.loops = 0;
35
+ }
36
+ colorValue.loops++;
37
+ if (decrease) {
38
+ colorValue.status = "decreasing";
39
+ colorValue.value -= colorValue.value % max;
40
+ }
41
+ }
42
+ }
43
+ else {
44
+ colorValue.value -= velocity;
45
+ if (colorValue.value < 0) {
46
+ if (!colorValue.loops) {
47
+ colorValue.loops = 0;
48
+ }
49
+ colorValue.loops++;
50
+ colorValue.status = "increasing";
51
+ colorValue.value += colorValue.value;
52
+ }
53
+ }
54
+ if (colorValue.velocity && decay !== 1) {
55
+ colorValue.velocity *= decay;
56
+ }
57
+ if (colorValue.value > max) {
58
+ colorValue.value %= max;
59
+ }
60
+ }
61
+ function updateColor(particle, delta) {
62
+ const { h: hAnimation, s: sAnimation, l: lAnimation } = particle.options.color.animation, { color } = particle;
63
+ if (!color) {
64
+ return;
65
+ }
66
+ const { h, s, l } = color;
67
+ if (h) {
68
+ updateColorValue(delta, h, hAnimation, 360, false);
69
+ }
70
+ if (s) {
71
+ updateColorValue(delta, s, sAnimation, 100, true);
72
+ }
73
+ if (l) {
74
+ updateColorValue(delta, l, lAnimation, 100, true);
75
+ }
76
+ }
77
+ exports.updateColor = updateColor;
78
+ });
package/umd/index.js CHANGED
@@ -4,15 +4,15 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./ColorUpdater"], factory);
7
+ define(["require", "exports", "./ColorUpdater.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadColorUpdater = void 0;
13
- const ColorUpdater_1 = require("./ColorUpdater");
14
- async function loadColorUpdater(engine) {
15
- await engine.addParticleUpdater("color", (container) => new ColorUpdater_1.ColorUpdater(container));
13
+ const ColorUpdater_js_1 = require("./ColorUpdater.js");
14
+ async function loadColorUpdater(engine, refresh = true) {
15
+ await engine.addParticleUpdater("color", (container) => new ColorUpdater_js_1.ColorUpdater(container), refresh);
16
16
  }
17
17
  exports.loadColorUpdater = loadColorUpdater;
18
18
  });