@tsparticles/updater-tilt 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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Options/Classes/Tilt.js +24 -0
  4. package/browser/Options/Classes/TiltAnimation.js +26 -0
  5. package/browser/Options/Interfaces/ITilt.js +1 -0
  6. package/browser/Options/Interfaces/ITiltAnimation.js +1 -0
  7. package/browser/TiltDirection.js +1 -0
  8. package/browser/TiltUpdater.js +97 -0
  9. package/browser/index.js +4 -0
  10. package/cjs/Options/Classes/Tilt.js +28 -0
  11. package/cjs/Options/Classes/TiltAnimation.js +30 -0
  12. package/cjs/Options/Interfaces/ITilt.js +2 -0
  13. package/cjs/Options/Interfaces/ITiltAnimation.js +2 -0
  14. package/cjs/TiltDirection.js +2 -0
  15. package/cjs/TiltUpdater.js +101 -0
  16. package/cjs/index.js +19 -0
  17. package/esm/Options/Classes/Tilt.js +24 -0
  18. package/esm/Options/Classes/TiltAnimation.js +26 -0
  19. package/esm/Options/Interfaces/ITilt.js +1 -0
  20. package/esm/Options/Interfaces/ITiltAnimation.js +1 -0
  21. package/esm/TiltDirection.js +1 -0
  22. package/esm/TiltUpdater.js +97 -0
  23. package/esm/index.js +4 -0
  24. package/package.json +82 -0
  25. package/report.html +39 -0
  26. package/tsparticles.updater.tilt.js +263 -0
  27. package/tsparticles.updater.tilt.min.js +2 -0
  28. package/tsparticles.updater.tilt.min.js.LICENSE.txt +8 -0
  29. package/types/Options/Classes/Tilt.d.ts +13 -0
  30. package/types/Options/Classes/TiltAnimation.d.ts +10 -0
  31. package/types/Options/Interfaces/ITilt.d.ts +8 -0
  32. package/types/Options/Interfaces/ITiltAnimation.d.ts +7 -0
  33. package/types/TiltDirection.d.ts +6 -0
  34. package/types/TiltUpdater.d.ts +27 -0
  35. package/types/index.d.ts +2 -0
  36. package/umd/Options/Classes/Tilt.js +38 -0
  37. package/umd/Options/Classes/TiltAnimation.js +40 -0
  38. package/umd/Options/Interfaces/ITilt.js +12 -0
  39. package/umd/Options/Interfaces/ITiltAnimation.js +12 -0
  40. package/umd/TiltDirection.js +12 -0
  41. package/umd/TiltUpdater.js +111 -0
  42. package/umd/index.js +18 -0
@@ -0,0 +1,263 @@
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
+ "loadTiltUpdater": () => (/* binding */ loadTiltUpdater)
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/Options/Classes/TiltAnimation.js
100
+
101
+ class TiltAnimation {
102
+ constructor() {
103
+ this.enable = false;
104
+ this.speed = 0;
105
+ this.decay = 0;
106
+ this.sync = false;
107
+ }
108
+ load(data) {
109
+ if (!data) {
110
+ return;
111
+ }
112
+ if (data.enable !== undefined) {
113
+ this.enable = data.enable;
114
+ }
115
+ if (data.speed !== undefined) {
116
+ this.speed = (0,engine_root_window_.setRangeValue)(data.speed);
117
+ }
118
+ if (data.decay !== undefined) {
119
+ this.decay = (0,engine_root_window_.setRangeValue)(data.decay);
120
+ }
121
+ if (data.sync !== undefined) {
122
+ this.sync = data.sync;
123
+ }
124
+ }
125
+ }
126
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Tilt.js
127
+
128
+
129
+ class Tilt extends engine_root_window_.ValueWithRandom {
130
+ constructor() {
131
+ super();
132
+ this.animation = new TiltAnimation();
133
+ this.direction = "clockwise";
134
+ this.enable = false;
135
+ this.value = 0;
136
+ }
137
+ load(data) {
138
+ super.load(data);
139
+ if (!data) {
140
+ return;
141
+ }
142
+ this.animation.load(data.animation);
143
+ if (data.direction !== undefined) {
144
+ this.direction = data.direction;
145
+ }
146
+ if (data.enable !== undefined) {
147
+ this.enable = data.enable;
148
+ }
149
+ }
150
+ }
151
+ ;// CONCATENATED MODULE: ./dist/browser/TiltUpdater.js
152
+
153
+
154
+ function updateTilt(particle, delta) {
155
+ var _a, _b;
156
+ if (!particle.tilt || !particle.options.tilt) {
157
+ return;
158
+ }
159
+ const tilt = particle.options.tilt,
160
+ tiltAnimation = tilt.animation,
161
+ speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor,
162
+ max = 2 * Math.PI,
163
+ decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1;
164
+ if (!tiltAnimation.enable) {
165
+ return;
166
+ }
167
+ switch (particle.tilt.status) {
168
+ case "increasing":
169
+ particle.tilt.value += speed;
170
+ if (particle.tilt.value > max) {
171
+ particle.tilt.value -= max;
172
+ }
173
+ break;
174
+ case "decreasing":
175
+ default:
176
+ particle.tilt.value -= speed;
177
+ if (particle.tilt.value < 0) {
178
+ particle.tilt.value += max;
179
+ }
180
+ break;
181
+ }
182
+ if (particle.tilt.velocity && decay !== 1) {
183
+ particle.tilt.velocity *= decay;
184
+ }
185
+ }
186
+ class TiltUpdater {
187
+ constructor(container) {
188
+ this.container = container;
189
+ }
190
+ getTransformValues(particle) {
191
+ var _a;
192
+ const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
193
+ return {
194
+ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
195
+ c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined
196
+ };
197
+ }
198
+ init(particle) {
199
+ var _a;
200
+ const tiltOptions = particle.options.tilt;
201
+ if (!tiltOptions) {
202
+ return;
203
+ }
204
+ particle.tilt = {
205
+ enable: tiltOptions.enable,
206
+ value: (0,engine_root_window_.getRangeValue)(tiltOptions.value) * Math.PI / 180,
207
+ sinDirection: (0,engine_root_window_.getRandom)() >= 0.5 ? 1 : -1,
208
+ cosDirection: (0,engine_root_window_.getRandom)() >= 0.5 ? 1 : -1
209
+ };
210
+ let tiltDirection = tiltOptions.direction;
211
+ if (tiltDirection === "random") {
212
+ const index = Math.floor((0,engine_root_window_.getRandom)() * 2);
213
+ tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
214
+ }
215
+ switch (tiltDirection) {
216
+ case "counter-clockwise":
217
+ case "counterClockwise":
218
+ particle.tilt.status = "decreasing";
219
+ break;
220
+ case "clockwise":
221
+ particle.tilt.status = "increasing";
222
+ break;
223
+ }
224
+ const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
225
+ if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) {
226
+ particle.tilt.decay = 1 - (0,engine_root_window_.getRangeValue)(tiltAnimation.decay);
227
+ particle.tilt.velocity = (0,engine_root_window_.getRangeValue)(tiltAnimation.speed) / 360 * this.container.retina.reduceFactor;
228
+ if (!tiltAnimation.sync) {
229
+ particle.tilt.velocity *= (0,engine_root_window_.getRandom)();
230
+ }
231
+ }
232
+ }
233
+ isEnabled(particle) {
234
+ var _a;
235
+ const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
236
+ return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable);
237
+ }
238
+ loadOptions(options, ...sources) {
239
+ if (!options.tilt) {
240
+ options.tilt = new Tilt();
241
+ }
242
+ for (const source of sources) {
243
+ options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
244
+ }
245
+ }
246
+ update(particle, delta) {
247
+ if (!this.isEnabled(particle)) {
248
+ return;
249
+ }
250
+ updateTilt(particle, delta);
251
+ }
252
+ }
253
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
254
+
255
+ async function loadTiltUpdater(engine) {
256
+ await engine.addParticleUpdater("tilt", container => new TiltUpdater(container));
257
+ }
258
+ })();
259
+
260
+ /******/ return __webpack_exports__;
261
+ /******/ })()
262
+ ;
263
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.updater.tilt.min.js.LICENSE.txt */
2
+ !function(t,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 i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function o(t){var n=i[t];if(void 0!==n)return n.exports;var a=i[t]={exports:{}};return e[t](a,a.exports,o),a.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadTiltUpdater:()=>l});var t=o(533);class e{constructor(){this.enable=!1,this.speed=0,this.decay=0,this.sync=!1}load(e){e&&(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.speed&&(this.speed=(0,t.setRangeValue)(e.speed)),void 0!==e.decay&&(this.decay=(0,t.setRangeValue)(e.decay)),void 0!==e.sync&&(this.sync=e.sync))}}class i extends t.ValueWithRandom{constructor(){super(),this.animation=new e,this.direction="clockwise",this.enable=!1,this.value=0}load(t){super.load(t),t&&(this.animation.load(t.animation),void 0!==t.direction&&(this.direction=t.direction),void 0!==t.enable&&(this.enable=t.enable))}}class a{constructor(t){this.container=t}getTransformValues(t){var e;const i=(null===(e=t.tilt)||void 0===e?void 0:e.enable)&&t.tilt;return{b:i?Math.cos(i.value)*i.cosDirection:void 0,c:i?Math.sin(i.value)*i.sinDirection:void 0}}init(e){var i;const o=e.options.tilt;if(!o)return;e.tilt={enable:o.enable,value:(0,t.getRangeValue)(o.value)*Math.PI/180,sinDirection:(0,t.getRandom)()>=.5?1:-1,cosDirection:(0,t.getRandom)()>=.5?1:-1};let n=o.direction;if("random"===n){n=Math.floor(2*(0,t.getRandom)())>0?"counter-clockwise":"clockwise"}switch(n){case"counter-clockwise":case"counterClockwise":e.tilt.status="decreasing";break;case"clockwise":e.tilt.status="increasing"}const a=null===(i=e.options.tilt)||void 0===i?void 0:i.animation;(null==a?void 0:a.enable)&&(e.tilt.decay=1-(0,t.getRangeValue)(a.decay),e.tilt.velocity=(0,t.getRangeValue)(a.speed)/360*this.container.retina.reduceFactor,a.sync||(e.tilt.velocity*=(0,t.getRandom)()))}isEnabled(t){var e;const i=null===(e=t.options.tilt)||void 0===e?void 0:e.animation;return!t.destroyed&&!t.spawning&&!!(null==i?void 0:i.enable)}loadOptions(t,...e){t.tilt||(t.tilt=new i);for(const i of e)t.tilt.load(null==i?void 0:i.tilt)}update(t,e){this.isEnabled(t)&&function(t,e){var i,o;if(!t.tilt||!t.options.tilt)return;const n=t.options.tilt.animation,a=(null!==(i=t.tilt.velocity)&&void 0!==i?i:0)*e.factor,l=2*Math.PI,s=null!==(o=t.tilt.decay)&&void 0!==o?o:1;n.enable&&("increasing"===t.tilt.status?(t.tilt.value+=a,t.tilt.value>l&&(t.tilt.value-=l)):(t.tilt.value-=a,t.tilt.value<0&&(t.tilt.value+=l)),t.tilt.velocity&&1!==s&&(t.tilt.velocity*=s))}(t,e)}}async function l(t){await t.addParticleUpdater("tilt",(t=>new a(t)))}})(),n})()));
@@ -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,13 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { ITilt } from "../Interfaces/ITilt";
3
+ import { TiltAnimation } from "./TiltAnimation";
4
+ import { TiltDirection } from "../../TiltDirection";
5
+ import type { TiltDirectionAlt } from "../../TiltDirection";
6
+ import { ValueWithRandom } from "@tsparticles/engine";
7
+ export declare class Tilt extends ValueWithRandom implements ITilt, IOptionLoader<ITilt> {
8
+ animation: TiltAnimation;
9
+ direction: TiltDirection | keyof typeof TiltDirection | TiltDirectionAlt;
10
+ enable: boolean;
11
+ constructor();
12
+ load(data?: RecursivePartial<ITilt>): void;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
2
+ import type { ITiltAnimation } from "../Interfaces/ITiltAnimation";
3
+ export declare class TiltAnimation implements ITiltAnimation, IOptionLoader<ITiltAnimation> {
4
+ decay: RangeValue;
5
+ enable: boolean;
6
+ speed: RangeValue;
7
+ sync: boolean;
8
+ constructor();
9
+ load(data?: RecursivePartial<ITiltAnimation>): void;
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { TiltDirection, TiltDirectionAlt } from "../../TiltDirection";
2
+ import type { ITiltAnimation } from "./ITiltAnimation";
3
+ import type { IValueWithRandom } from "@tsparticles/engine";
4
+ export interface ITilt extends IValueWithRandom {
5
+ animation: ITiltAnimation;
6
+ direction: TiltDirection | keyof typeof TiltDirection | TiltDirectionAlt;
7
+ enable: boolean;
8
+ }
@@ -0,0 +1,7 @@
1
+ import type { RangeValue } from "@tsparticles/engine";
2
+ export interface ITiltAnimation {
3
+ decay: RangeValue;
4
+ enable: boolean;
5
+ speed: RangeValue;
6
+ sync: boolean;
7
+ }
@@ -0,0 +1,6 @@
1
+ export declare const enum TiltDirection {
2
+ clockwise = "clockwise",
3
+ counterClockwise = "counter-clockwise",
4
+ random = "random"
5
+ }
6
+ export type TiltDirectionAlt = "counter-clockwise";
@@ -0,0 +1,27 @@
1
+ import type { Container, IDelta, IParticleTransformValues, IParticleUpdater, IParticleValueAnimation, IParticlesOptions, Particle, ParticlesOptions, RecursivePartial } from "@tsparticles/engine";
2
+ import type { ITilt } from "./Options/Interfaces/ITilt";
3
+ import { Tilt } from "./Options/Classes/Tilt";
4
+ export interface IParticleTiltValueAnimation extends IParticleValueAnimation<number> {
5
+ cosDirection: number;
6
+ sinDirection: number;
7
+ }
8
+ type TiltParticle = Particle & {
9
+ options: TiltParticlesOptions;
10
+ tilt?: IParticleTiltValueAnimation;
11
+ };
12
+ type ITiltParticlesOptions = IParticlesOptions & {
13
+ tilt?: ITilt;
14
+ };
15
+ type TiltParticlesOptions = ParticlesOptions & {
16
+ tilt?: Tilt;
17
+ };
18
+ export declare class TiltUpdater implements IParticleUpdater {
19
+ private readonly container;
20
+ constructor(container: Container);
21
+ getTransformValues(particle: TiltParticle): IParticleTransformValues;
22
+ init(particle: TiltParticle): void;
23
+ isEnabled(particle: TiltParticle): boolean;
24
+ loadOptions(options: TiltParticlesOptions, ...sources: (RecursivePartial<ITiltParticlesOptions> | undefined)[]): void;
25
+ update(particle: Particle, delta: IDelta): void;
26
+ }
27
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadTiltUpdater(engine: Engine): Promise<void>;
@@ -0,0 +1,38 @@
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", "./TiltAnimation", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Tilt = void 0;
13
+ const TiltAnimation_1 = require("./TiltAnimation");
14
+ const engine_1 = require("@tsparticles/engine");
15
+ class Tilt extends engine_1.ValueWithRandom {
16
+ constructor() {
17
+ super();
18
+ this.animation = new TiltAnimation_1.TiltAnimation();
19
+ this.direction = "clockwise";
20
+ this.enable = false;
21
+ this.value = 0;
22
+ }
23
+ load(data) {
24
+ super.load(data);
25
+ if (!data) {
26
+ return;
27
+ }
28
+ this.animation.load(data.animation);
29
+ if (data.direction !== undefined) {
30
+ this.direction = data.direction;
31
+ }
32
+ if (data.enable !== undefined) {
33
+ this.enable = data.enable;
34
+ }
35
+ }
36
+ }
37
+ exports.Tilt = Tilt;
38
+ });
@@ -0,0 +1,40 @@
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.TiltAnimation = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class TiltAnimation {
15
+ constructor() {
16
+ this.enable = false;
17
+ this.speed = 0;
18
+ this.decay = 0;
19
+ this.sync = false;
20
+ }
21
+ load(data) {
22
+ if (!data) {
23
+ return;
24
+ }
25
+ if (data.enable !== undefined) {
26
+ this.enable = data.enable;
27
+ }
28
+ if (data.speed !== undefined) {
29
+ this.speed = (0, engine_1.setRangeValue)(data.speed);
30
+ }
31
+ if (data.decay !== undefined) {
32
+ this.decay = (0, engine_1.setRangeValue)(data.decay);
33
+ }
34
+ if (data.sync !== undefined) {
35
+ this.sync = data.sync;
36
+ }
37
+ }
38
+ }
39
+ exports.TiltAnimation = TiltAnimation;
40
+ });
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,111 @@
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", "./Options/Classes/Tilt"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TiltUpdater = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Tilt_1 = require("./Options/Classes/Tilt");
15
+ function updateTilt(particle, delta) {
16
+ var _a, _b;
17
+ if (!particle.tilt || !particle.options.tilt) {
18
+ return;
19
+ }
20
+ const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1;
21
+ if (!tiltAnimation.enable) {
22
+ return;
23
+ }
24
+ switch (particle.tilt.status) {
25
+ case "increasing":
26
+ particle.tilt.value += speed;
27
+ if (particle.tilt.value > max) {
28
+ particle.tilt.value -= max;
29
+ }
30
+ break;
31
+ case "decreasing":
32
+ default:
33
+ particle.tilt.value -= speed;
34
+ if (particle.tilt.value < 0) {
35
+ particle.tilt.value += max;
36
+ }
37
+ break;
38
+ }
39
+ if (particle.tilt.velocity && decay !== 1) {
40
+ particle.tilt.velocity *= decay;
41
+ }
42
+ }
43
+ class TiltUpdater {
44
+ constructor(container) {
45
+ this.container = container;
46
+ }
47
+ getTransformValues(particle) {
48
+ var _a;
49
+ const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
50
+ return {
51
+ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
52
+ c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
53
+ };
54
+ }
55
+ init(particle) {
56
+ var _a;
57
+ const tiltOptions = particle.options.tilt;
58
+ if (!tiltOptions) {
59
+ return;
60
+ }
61
+ particle.tilt = {
62
+ enable: tiltOptions.enable,
63
+ value: ((0, engine_1.getRangeValue)(tiltOptions.value) * Math.PI) / 180,
64
+ sinDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
65
+ cosDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
66
+ };
67
+ let tiltDirection = tiltOptions.direction;
68
+ if (tiltDirection === "random") {
69
+ const index = Math.floor((0, engine_1.getRandom)() * 2);
70
+ tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
71
+ }
72
+ switch (tiltDirection) {
73
+ case "counter-clockwise":
74
+ case "counterClockwise":
75
+ particle.tilt.status = "decreasing";
76
+ break;
77
+ case "clockwise":
78
+ particle.tilt.status = "increasing";
79
+ break;
80
+ }
81
+ const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
82
+ if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) {
83
+ particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay);
84
+ particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
85
+ if (!tiltAnimation.sync) {
86
+ particle.tilt.velocity *= (0, engine_1.getRandom)();
87
+ }
88
+ }
89
+ }
90
+ isEnabled(particle) {
91
+ var _a;
92
+ const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
93
+ return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable);
94
+ }
95
+ loadOptions(options, ...sources) {
96
+ if (!options.tilt) {
97
+ options.tilt = new Tilt_1.Tilt();
98
+ }
99
+ for (const source of sources) {
100
+ options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
101
+ }
102
+ }
103
+ update(particle, delta) {
104
+ if (!this.isEnabled(particle)) {
105
+ return;
106
+ }
107
+ updateTilt(particle, delta);
108
+ }
109
+ }
110
+ exports.TiltUpdater = TiltUpdater;
111
+ });
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", "./TiltUpdater"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadTiltUpdater = void 0;
13
+ const TiltUpdater_1 = require("./TiltUpdater");
14
+ async function loadTiltUpdater(engine) {
15
+ await engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container));
16
+ }
17
+ exports.loadTiltUpdater = loadTiltUpdater;
18
+ });