@tsparticles/updater-color 3.0.0-alpha.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.
@@ -0,0 +1,185 @@
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
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
55
+ /******/
56
+ /************************************************************************/
57
+ /******/ /* webpack/runtime/define property getters */
58
+ /******/ (() => {
59
+ /******/ // define getter functions for harmony exports
60
+ /******/ __webpack_require__.d = (exports, definition) => {
61
+ /******/ for(var key in definition) {
62
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
63
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
64
+ /******/ }
65
+ /******/ }
66
+ /******/ };
67
+ /******/ })();
68
+ /******/
69
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
+ /******/ (() => {
71
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
+ /******/ })();
73
+ /******/
74
+ /******/ /* webpack/runtime/make namespace object */
75
+ /******/ (() => {
76
+ /******/ // define __esModule on exports
77
+ /******/ __webpack_require__.r = (exports) => {
78
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
79
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
80
+ /******/ }
81
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
82
+ /******/ };
83
+ /******/ })();
84
+ /******/
85
+ /************************************************************************/
86
+ var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
89
+ // ESM COMPAT FLAG
90
+ __webpack_require__.r(__webpack_exports__);
91
+
92
+ // EXPORTS
93
+ __webpack_require__.d(__webpack_exports__, {
94
+ "loadColorUpdater": () => (/* binding */ loadColorUpdater)
95
+ });
96
+
97
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
98
+ var engine_root_window_ = __webpack_require__(533);
99
+ ;// CONCATENATED MODULE: ./dist/browser/ColorUpdater.js
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) {
105
+ return;
106
+ }
107
+ 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;
110
+ if (!decrease || colorValue.status === "increasing") {
111
+ colorValue.value += velocity;
112
+ if (colorValue.value > max) {
113
+ if (!colorValue.loops) {
114
+ colorValue.loops = 0;
115
+ }
116
+ colorValue.loops++;
117
+ if (decrease) {
118
+ colorValue.status = "decreasing";
119
+ colorValue.value -= colorValue.value % max;
120
+ }
121
+ }
122
+ } else {
123
+ colorValue.value -= velocity;
124
+ if (colorValue.value < 0) {
125
+ if (!colorValue.loops) {
126
+ colorValue.loops = 0;
127
+ }
128
+ colorValue.loops++;
129
+ colorValue.status = "increasing";
130
+ colorValue.value += colorValue.value;
131
+ }
132
+ }
133
+ if (colorValue.velocity && decay !== 1) {
134
+ colorValue.velocity *= decay;
135
+ }
136
+ if (colorValue.value > max) {
137
+ colorValue.value %= max;
138
+ }
139
+ }
140
+ 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;
146
+ if (h) {
147
+ updateColorValue(delta, h, animationOptions.h, 360, false);
148
+ }
149
+ if (s) {
150
+ updateColorValue(delta, s, animationOptions.s, 100, true);
151
+ }
152
+ if (l) {
153
+ updateColorValue(delta, l, animationOptions.l, 100, true);
154
+ }
155
+ }
156
+ class ColorUpdater {
157
+ constructor(container) {
158
+ this.container = container;
159
+ }
160
+ init(particle) {
161
+ const hslColor = (0,engine_root_window_.rangeColorToHsl)(particle.options.color, particle.id, particle.options.reduceDuplicates);
162
+ if (hslColor) {
163
+ particle.color = (0,engine_root_window_.getHslAnimationFromHsl)(hslColor, particle.options.color.animation, this.container.retina.reduceFactor);
164
+ }
165
+ }
166
+ 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);
170
+ }
171
+ update(particle, delta) {
172
+ updateColor(particle, delta);
173
+ }
174
+ }
175
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
176
+
177
+ async function loadColorUpdater(engine) {
178
+ await engine.addParticleUpdater("color", container => new ColorUpdater(container));
179
+ }
180
+ })();
181
+
182
+ /******/ return __webpack_exports__;
183
+ /******/ })()
184
+ ;
185
+ });
@@ -0,0 +1,2 @@
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})()));
@@ -0,0 +1,8 @@
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
+ */
@@ -0,0 +1,8 @@
1
+ import type { Container, IDelta, IParticleUpdater, Particle } from "@tsparticles/engine";
2
+ export declare class ColorUpdater implements IParticleUpdater {
3
+ private readonly container;
4
+ constructor(container: Container);
5
+ init(particle: Particle): void;
6
+ isEnabled(particle: Particle): boolean;
7
+ update(particle: Particle, delta: IDelta): void;
8
+ }
@@ -0,0 +1,2 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadColorUpdater(engine: Engine): Promise<void>;
@@ -0,0 +1,95 @@
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.ColorUpdater = void 0;
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
+ }
71
+ class ColorUpdater {
72
+ constructor(container) {
73
+ this.container = container;
74
+ }
75
+ init(particle) {
76
+ const hslColor = (0, engine_1.rangeColorToHsl)(particle.options.color, particle.id, particle.options.reduceDuplicates);
77
+ if (hslColor) {
78
+ particle.color = (0, engine_1.getHslAnimationFromHsl)(hslColor, particle.options.color.animation, this.container.retina.reduceFactor);
79
+ }
80
+ }
81
+ isEnabled(particle) {
82
+ var _a, _b, _c;
83
+ const animationOptions = particle.options.color.animation;
84
+ return (!particle.destroyed &&
85
+ !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)));
89
+ }
90
+ update(particle, delta) {
91
+ updateColor(particle, delta);
92
+ }
93
+ }
94
+ exports.ColorUpdater = ColorUpdater;
95
+ });
package/umd/index.js ADDED
@@ -0,0 +1,18 @@
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", "./ColorUpdater"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
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));
16
+ }
17
+ exports.loadColorUpdater = loadColorUpdater;
18
+ });