@tsparticles/updater-size 3.0.0-alpha.0 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,12 +91,12 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadSizeUpdater": () => (/* binding */ loadSizeUpdater)
94
+ loadSizeUpdater: () => (/* binding */ loadSizeUpdater)
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/SizeUpdater.js
99
+ ;// CONCATENATED MODULE: ./dist/browser/Utils.js
100
100
 
101
101
  function checkDestroy(particle, value, minValue, maxValue) {
102
102
  switch (particle.options.size.animation.destroy) {
@@ -113,61 +113,71 @@ function checkDestroy(particle, value, minValue, maxValue) {
113
113
  }
114
114
  }
115
115
  function updateSize(particle, delta) {
116
- var _a, _b, _c, _d, _e;
117
- const sizeVelocity = ((_a = particle.size.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor,
118
- minValue = particle.size.min,
119
- maxValue = particle.size.max,
120
- decay = (_b = particle.size.decay) !== null && _b !== void 0 ? _b : 1;
121
- if (particle.destroyed || !particle.size.enable || ((_c = particle.size.maxLoops) !== null && _c !== void 0 ? _c : 0) > 0 && ((_d = particle.size.loops) !== null && _d !== void 0 ? _d : 0) > ((_e = particle.size.maxLoops) !== null && _e !== void 0 ? _e : 0)) {
116
+ const data = particle.size;
117
+ if (particle.destroyed || !data || !data.enable || (data.maxLoops ?? 0) > 0 && (data.loops ?? 0) > (data.maxLoops ?? 0)) {
118
+ return;
119
+ }
120
+ const sizeVelocity = (data.velocity ?? 0) * delta.factor,
121
+ minValue = data.min,
122
+ maxValue = data.max,
123
+ decay = data.decay ?? 1;
124
+ if (!data.time) {
125
+ data.time = 0;
126
+ }
127
+ if ((data.delayTime ?? 0) > 0 && data.time < (data.delayTime ?? 0)) {
128
+ data.time += delta.value;
129
+ }
130
+ if ((data.delayTime ?? 0) > 0 && data.time < (data.delayTime ?? 0)) {
122
131
  return;
123
132
  }
124
- switch (particle.size.status) {
133
+ switch (data.status) {
125
134
  case "increasing":
126
- if (particle.size.value >= maxValue) {
127
- particle.size.status = "decreasing";
128
- if (!particle.size.loops) {
129
- particle.size.loops = 0;
135
+ if (data.value >= maxValue) {
136
+ data.status = "decreasing";
137
+ if (!data.loops) {
138
+ data.loops = 0;
130
139
  }
131
- particle.size.loops++;
140
+ data.loops++;
132
141
  } else {
133
- particle.size.value += sizeVelocity;
142
+ data.value += sizeVelocity;
134
143
  }
135
144
  break;
136
145
  case "decreasing":
137
- if (particle.size.value <= minValue) {
138
- particle.size.status = "increasing";
139
- if (!particle.size.loops) {
140
- particle.size.loops = 0;
146
+ if (data.value <= minValue) {
147
+ data.status = "increasing";
148
+ if (!data.loops) {
149
+ data.loops = 0;
141
150
  }
142
- particle.size.loops++;
151
+ data.loops++;
143
152
  } else {
144
- particle.size.value -= sizeVelocity;
153
+ data.value -= sizeVelocity;
145
154
  }
146
155
  }
147
- if (particle.size.velocity && decay !== 1) {
148
- particle.size.velocity *= decay;
156
+ if (data.velocity && decay !== 1) {
157
+ data.velocity *= decay;
149
158
  }
150
- checkDestroy(particle, particle.size.value, minValue, maxValue);
159
+ checkDestroy(particle, data.value, minValue, maxValue);
151
160
  if (!particle.destroyed) {
152
- particle.size.value = (0,engine_root_window_.clamp)(particle.size.value, minValue, maxValue);
161
+ data.value = (0,engine_root_window_.clamp)(data.value, minValue, maxValue);
153
162
  }
154
163
  }
164
+ ;// CONCATENATED MODULE: ./dist/browser/SizeUpdater.js
165
+
166
+
155
167
  class SizeUpdater {
156
168
  init(particle) {
157
- var _a;
158
169
  const container = particle.container,
159
170
  sizeOptions = particle.options.size,
160
171
  sizeAnimation = sizeOptions.animation;
161
172
  if (sizeAnimation.enable) {
162
- particle.size.velocity = ((_a = particle.retina.sizeAnimationSpeed) !== null && _a !== void 0 ? _a : container.retina.sizeAnimationSpeed) / 100 * container.retina.reduceFactor;
173
+ particle.size.velocity = (particle.retina.sizeAnimationSpeed ?? container.retina.sizeAnimationSpeed) / 100 * container.retina.reduceFactor;
163
174
  if (!sizeAnimation.sync) {
164
175
  particle.size.velocity *= (0,engine_root_window_.getRandom)();
165
176
  }
166
177
  }
167
178
  }
168
179
  isEnabled(particle) {
169
- var _a, _b, _c, _d;
170
- return !particle.destroyed && !particle.spawning && particle.size.enable && (((_a = particle.size.maxLoops) !== null && _a !== void 0 ? _a : 0) <= 0 || ((_b = particle.size.maxLoops) !== null && _b !== void 0 ? _b : 0) > 0 && ((_c = particle.size.loops) !== null && _c !== void 0 ? _c : 0) < ((_d = particle.size.maxLoops) !== null && _d !== void 0 ? _d : 0));
180
+ return !particle.destroyed && !particle.spawning && particle.size.enable && ((particle.size.maxLoops ?? 0) <= 0 || (particle.size.maxLoops ?? 0) > 0 && (particle.size.loops ?? 0) < (particle.size.maxLoops ?? 0));
171
181
  }
172
182
  reset(particle) {
173
183
  particle.size.loops = 0;
@@ -181,8 +191,8 @@ class SizeUpdater {
181
191
  }
182
192
  ;// CONCATENATED MODULE: ./dist/browser/index.js
183
193
 
184
- async function loadSizeUpdater(engine) {
185
- await engine.addParticleUpdater("size", () => new SizeUpdater());
194
+ async function loadSizeUpdater(engine, refresh = true) {
195
+ await engine.addParticleUpdater("size", () => new SizeUpdater(), refresh);
186
196
  }
187
197
  })();
188
198
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.size.min.js.LICENSE.txt */
2
- !function(e,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var o="object"==typeof exports?i(require("@tsparticles/engine")):i(e.window);for(var s in o)("object"==typeof exports?exports:e)[s]=o[s]}}(this,(e=>(()=>{"use strict";var i={533:i=>{i.exports=e}},o={};function s(e){var t=o[e];if(void 0!==t)return t.exports;var n=o[e]={exports:{}};return i[e](n,n.exports,s),n.exports}s.d=(e,i)=>{for(var o in i)s.o(i,o)&&!s.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:i[o]})},s.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};return(()=>{s.r(t),s.d(t,{loadSizeUpdater:()=>o});var e=s(533);class i{init(i){var o;const s=i.container,t=i.options.size.animation;t.enable&&(i.size.velocity=(null!==(o=i.retina.sizeAnimationSpeed)&&void 0!==o?o:s.retina.sizeAnimationSpeed)/100*s.retina.reduceFactor,t.sync||(i.size.velocity*=(0,e.getRandom)()))}isEnabled(e){var i,o,s,t;return!e.destroyed&&!e.spawning&&e.size.enable&&((null!==(i=e.size.maxLoops)&&void 0!==i?i:0)<=0||(null!==(o=e.size.maxLoops)&&void 0!==o?o:0)>0&&(null!==(s=e.size.loops)&&void 0!==s?s:0)<(null!==(t=e.size.maxLoops)&&void 0!==t?t:0))}reset(e){e.size.loops=0}update(i,o){this.isEnabled(i)&&function(i,o){var s,t,n,a,r;const l=(null!==(s=i.size.velocity)&&void 0!==s?s:0)*o.factor,d=i.size.min,p=i.size.max,c=null!==(t=i.size.decay)&&void 0!==t?t:1;if(!(i.destroyed||!i.size.enable||(null!==(n=i.size.maxLoops)&&void 0!==n?n:0)>0&&(null!==(a=i.size.loops)&&void 0!==a?a:0)>(null!==(r=i.size.maxLoops)&&void 0!==r?r:0))){switch(i.size.status){case"increasing":i.size.value>=p?(i.size.status="decreasing",i.size.loops||(i.size.loops=0),i.size.loops++):i.size.value+=l;break;case"decreasing":i.size.value<=d?(i.size.status="increasing",i.size.loops||(i.size.loops=0),i.size.loops++):i.size.value-=l}i.size.velocity&&1!==c&&(i.size.velocity*=c),function(e,i,o,s){switch(e.options.size.animation.destroy){case"max":i>=s&&e.destroy();break;case"min":i<=o&&e.destroy()}}(i,i.size.value,d,p),i.destroyed||(i.size.value=(0,e.clamp)(i.size.value,d,p))}}(i,o)}}async function o(e){await e.addParticleUpdater("size",(()=>new i))}})(),t})()));
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 i in t)("object"==typeof exports?exports:e)[i]=t[i]}}(this,(e=>(()=>{"use strict";var o={533:o=>{o.exports=e}},t={};function i(e){var s=t[e];if(void 0!==s)return s.exports;var a=t[e]={exports:{}};return o[e](a,a.exports,i),a.exports}i.d=(e,o)=>{for(var t in o)i.o(o,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},i.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return(()=>{i.r(s),i.d(s,{loadSizeUpdater:()=>t});var e=i(533);class o{init(o){const t=o.container,i=o.options.size.animation;i.enable&&(o.size.velocity=(o.retina.sizeAnimationSpeed??t.retina.sizeAnimationSpeed)/100*t.retina.reduceFactor,i.sync||(o.size.velocity*=(0,e.getRandom)()))}isEnabled(e){return!e.destroyed&&!e.spawning&&e.size.enable&&((e.size.maxLoops??0)<=0||(e.size.maxLoops??0)>0&&(e.size.loops??0)<(e.size.maxLoops??0))}reset(e){e.size.loops=0}update(o,t){this.isEnabled(o)&&function(o,t){const i=o.size;if(o.destroyed||!i||!i.enable||(i.maxLoops??0)>0&&(i.loops??0)>(i.maxLoops??0))return;const s=(i.velocity??0)*t.factor,a=i.min,n=i.max,r=i.decay??1;if(i.time||(i.time=0),(i.delayTime??0)>0&&i.time<(i.delayTime??0)&&(i.time+=t.value),!((i.delayTime??0)>0&&i.time<(i.delayTime??0))){switch(i.status){case"increasing":i.value>=n?(i.status="decreasing",i.loops||(i.loops=0),i.loops++):i.value+=s;break;case"decreasing":i.value<=a?(i.status="increasing",i.loops||(i.loops=0),i.loops++):i.value-=s}i.velocity&&1!==r&&(i.velocity*=r),function(e,o,t,i){switch(e.options.size.animation.destroy){case"max":o>=i&&e.destroy();break;case"min":o<=t&&e.destroy()}}(o,i.value,a,n),o.destroyed||(i.value=(0,e.clamp)(i.value,a,n))}}(o,t)}}async function t(e,t=!0){await e.addParticleUpdater("size",(()=>new o),t)}})(),s})()));
@@ -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.0
8
- */
1
+ /*! tsParticles Size Updater v3.0.0-beta.0 by Matteo Bruni */
@@ -1,4 +1,4 @@
1
- import type { IDelta, IParticleUpdater, Particle } from "@tsparticles/engine";
1
+ import { type IDelta, type IParticleUpdater, type Particle } from "@tsparticles/engine";
2
2
  export declare class SizeUpdater implements IParticleUpdater {
3
3
  init(particle: Particle): void;
4
4
  isEnabled(particle: Particle): boolean;
@@ -0,0 +1,2 @@
1
+ import { type IDelta, type Particle } from "@tsparticles/engine";
2
+ export declare function updateSize(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 loadSizeUpdater(engine: Engine): Promise<void>;
2
+ export declare function loadSizeUpdater(engine: Engine, refresh?: boolean): Promise<void>;
@@ -4,75 +4,20 @@
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"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SizeUpdater = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
- function checkDestroy(particle, value, minValue, maxValue) {
15
- switch (particle.options.size.animation.destroy) {
16
- case "max":
17
- if (value >= maxValue) {
18
- particle.destroy();
19
- }
20
- break;
21
- case "min":
22
- if (value <= minValue) {
23
- particle.destroy();
24
- }
25
- break;
26
- }
27
- }
28
- function updateSize(particle, delta) {
29
- var _a, _b, _c, _d, _e;
30
- const sizeVelocity = ((_a = particle.size.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, minValue = particle.size.min, maxValue = particle.size.max, decay = (_b = particle.size.decay) !== null && _b !== void 0 ? _b : 1;
31
- if (particle.destroyed ||
32
- !particle.size.enable ||
33
- (((_c = particle.size.maxLoops) !== null && _c !== void 0 ? _c : 0) > 0 && ((_d = particle.size.loops) !== null && _d !== void 0 ? _d : 0) > ((_e = particle.size.maxLoops) !== null && _e !== void 0 ? _e : 0))) {
34
- return;
35
- }
36
- switch (particle.size.status) {
37
- case "increasing":
38
- if (particle.size.value >= maxValue) {
39
- particle.size.status = "decreasing";
40
- if (!particle.size.loops) {
41
- particle.size.loops = 0;
42
- }
43
- particle.size.loops++;
44
- }
45
- else {
46
- particle.size.value += sizeVelocity;
47
- }
48
- break;
49
- case "decreasing":
50
- if (particle.size.value <= minValue) {
51
- particle.size.status = "increasing";
52
- if (!particle.size.loops) {
53
- particle.size.loops = 0;
54
- }
55
- particle.size.loops++;
56
- }
57
- else {
58
- particle.size.value -= sizeVelocity;
59
- }
60
- }
61
- if (particle.size.velocity && decay !== 1) {
62
- particle.size.velocity *= decay;
63
- }
64
- checkDestroy(particle, particle.size.value, minValue, maxValue);
65
- if (!particle.destroyed) {
66
- particle.size.value = (0, engine_1.clamp)(particle.size.value, minValue, maxValue);
67
- }
68
- }
14
+ const Utils_1 = require("./Utils");
69
15
  class SizeUpdater {
70
16
  init(particle) {
71
- var _a;
72
17
  const container = particle.container, sizeOptions = particle.options.size, sizeAnimation = sizeOptions.animation;
73
18
  if (sizeAnimation.enable) {
74
19
  particle.size.velocity =
75
- (((_a = particle.retina.sizeAnimationSpeed) !== null && _a !== void 0 ? _a : container.retina.sizeAnimationSpeed) / 100) *
20
+ ((particle.retina.sizeAnimationSpeed ?? container.retina.sizeAnimationSpeed) / 100) *
76
21
  container.retina.reduceFactor;
77
22
  if (!sizeAnimation.sync) {
78
23
  particle.size.velocity *= (0, engine_1.getRandom)();
@@ -80,12 +25,11 @@
80
25
  }
81
26
  }
82
27
  isEnabled(particle) {
83
- var _a, _b, _c, _d;
84
28
  return (!particle.destroyed &&
85
29
  !particle.spawning &&
86
30
  particle.size.enable &&
87
- (((_a = particle.size.maxLoops) !== null && _a !== void 0 ? _a : 0) <= 0 ||
88
- (((_b = particle.size.maxLoops) !== null && _b !== void 0 ? _b : 0) > 0 && ((_c = particle.size.loops) !== null && _c !== void 0 ? _c : 0) < ((_d = particle.size.maxLoops) !== null && _d !== void 0 ? _d : 0))));
31
+ ((particle.size.maxLoops ?? 0) <= 0 ||
32
+ ((particle.size.maxLoops ?? 0) > 0 && (particle.size.loops ?? 0) < (particle.size.maxLoops ?? 0))));
89
33
  }
90
34
  reset(particle) {
91
35
  particle.size.loops = 0;
@@ -94,7 +38,7 @@
94
38
  if (!this.isEnabled(particle)) {
95
39
  return;
96
40
  }
97
- updateSize(particle, delta);
41
+ (0, Utils_1.updateSize)(particle, delta);
98
42
  }
99
43
  }
100
44
  exports.SizeUpdater = SizeUpdater;
package/umd/Utils.js ADDED
@@ -0,0 +1,80 @@
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.updateSize = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ function checkDestroy(particle, value, minValue, maxValue) {
15
+ switch (particle.options.size.animation.destroy) {
16
+ case "max":
17
+ if (value >= maxValue) {
18
+ particle.destroy();
19
+ }
20
+ break;
21
+ case "min":
22
+ if (value <= minValue) {
23
+ particle.destroy();
24
+ }
25
+ break;
26
+ }
27
+ }
28
+ function updateSize(particle, delta) {
29
+ const data = particle.size;
30
+ if (particle.destroyed ||
31
+ !data ||
32
+ !data.enable ||
33
+ ((data.maxLoops ?? 0) > 0 && (data.loops ?? 0) > (data.maxLoops ?? 0))) {
34
+ return;
35
+ }
36
+ const sizeVelocity = (data.velocity ?? 0) * delta.factor, minValue = data.min, maxValue = data.max, decay = data.decay ?? 1;
37
+ if (!data.time) {
38
+ data.time = 0;
39
+ }
40
+ if ((data.delayTime ?? 0) > 0 && data.time < (data.delayTime ?? 0)) {
41
+ data.time += delta.value;
42
+ }
43
+ if ((data.delayTime ?? 0) > 0 && data.time < (data.delayTime ?? 0)) {
44
+ return;
45
+ }
46
+ switch (data.status) {
47
+ case "increasing":
48
+ if (data.value >= maxValue) {
49
+ data.status = "decreasing";
50
+ if (!data.loops) {
51
+ data.loops = 0;
52
+ }
53
+ data.loops++;
54
+ }
55
+ else {
56
+ data.value += sizeVelocity;
57
+ }
58
+ break;
59
+ case "decreasing":
60
+ if (data.value <= minValue) {
61
+ data.status = "increasing";
62
+ if (!data.loops) {
63
+ data.loops = 0;
64
+ }
65
+ data.loops++;
66
+ }
67
+ else {
68
+ data.value -= sizeVelocity;
69
+ }
70
+ }
71
+ if (data.velocity && decay !== 1) {
72
+ data.velocity *= decay;
73
+ }
74
+ checkDestroy(particle, data.value, minValue, maxValue);
75
+ if (!particle.destroyed) {
76
+ data.value = (0, engine_1.clamp)(data.value, minValue, maxValue);
77
+ }
78
+ }
79
+ exports.updateSize = updateSize;
80
+ });
package/umd/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadSizeUpdater = void 0;
13
13
  const SizeUpdater_1 = require("./SizeUpdater");
14
- async function loadSizeUpdater(engine) {
15
- await engine.addParticleUpdater("size", () => new SizeUpdater_1.SizeUpdater());
14
+ async function loadSizeUpdater(engine, refresh = true) {
15
+ await engine.addParticleUpdater("size", () => new SizeUpdater_1.SizeUpdater(), refresh);
16
16
  }
17
17
  exports.loadSizeUpdater = loadSizeUpdater;
18
18
  });