@tsparticles/plugin-motion 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/MotionInstance.js +49 -0
  4. package/browser/Options/Classes/Motion.js +16 -0
  5. package/browser/Options/Classes/MotionReduce.js +17 -0
  6. package/browser/Options/Interfaces/IMotion.js +1 -0
  7. package/browser/Options/Interfaces/IMotionReduce.js +1 -0
  8. package/browser/index.js +28 -0
  9. package/browser/types.js +1 -0
  10. package/cjs/MotionInstance.js +64 -0
  11. package/cjs/Options/Classes/Motion.js +20 -0
  12. package/cjs/Options/Classes/MotionReduce.js +21 -0
  13. package/cjs/Options/Interfaces/IMotion.js +2 -0
  14. package/cjs/Options/Interfaces/IMotionReduce.js +2 -0
  15. package/cjs/index.js +43 -0
  16. package/cjs/types.js +2 -0
  17. package/esm/MotionInstance.js +49 -0
  18. package/esm/Options/Classes/Motion.js +16 -0
  19. package/esm/Options/Classes/MotionReduce.js +17 -0
  20. package/esm/Options/Interfaces/IMotion.js +1 -0
  21. package/esm/Options/Interfaces/IMotionReduce.js +1 -0
  22. package/esm/index.js +28 -0
  23. package/esm/types.js +1 -0
  24. package/package.json +81 -0
  25. package/report.html +39 -0
  26. package/tsparticles.plugin.motion.js +209 -0
  27. package/tsparticles.plugin.motion.min.js +2 -0
  28. package/tsparticles.plugin.motion.min.js.LICENSE.txt +8 -0
  29. package/types/MotionInstance.d.ts +9 -0
  30. package/types/Options/Classes/Motion.d.ts +9 -0
  31. package/types/Options/Classes/MotionReduce.d.ts +8 -0
  32. package/types/Options/Interfaces/IMotion.d.ts +5 -0
  33. package/types/Options/Interfaces/IMotionReduce.d.ts +4 -0
  34. package/types/index.d.ts +2 -0
  35. package/types/types.d.ts +12 -0
  36. package/umd/MotionInstance.js +63 -0
  37. package/umd/Options/Classes/Motion.js +30 -0
  38. package/umd/Options/Classes/MotionReduce.js +31 -0
  39. package/umd/Options/Interfaces/IMotion.js +12 -0
  40. package/umd/Options/Interfaces/IMotionReduce.js +12 -0
  41. package/umd/index.js +42 -0
  42. package/umd/types.js +12 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles Motion Plugin
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-plugin-motion/badge)](https://www.jsdelivr.com/package/npm/tsparticles-plugin-motion)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-plugin-motion.svg)](https://www.npmjs.com/package/tsparticles-plugin-motion)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-plugin-motion)](https://www.npmjs.com/package/tsparticles-plugin-motion) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) plugin for handling motion sickness CSS value.
10
+
11
+ ## How to use it
12
+
13
+ ### CDN / Vanilla JS / jQuery
14
+
15
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
16
+
17
+ Including the `tsparticles.plugin.motion.min.js` file will export the function to load the plugin:
18
+
19
+ ```javascript
20
+ loadMotionPlugin;
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the plugin like this:
26
+
27
+ ```javascript
28
+ (async () => {
29
+ await loadMotionPlugin(tsParticles);
30
+
31
+ await tsParticles.load({
32
+ id: "tsparticles",
33
+ options: {
34
+ /* options */
35
+ },
36
+ });
37
+ })();
38
+ ```
39
+
40
+ ### ESM / CommonJS
41
+
42
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
+
44
+ ```shell
45
+ $ npm install tsparticles-plugin-motion
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add tsparticles-plugin-motion
52
+ ```
53
+
54
+ Then you need to import it in the app, like this:
55
+
56
+ ```javascript
57
+ const { tsParticles } = require("tsparticles-engine");
58
+ const { loadMotionPlugin } = require("tsparticles-plugin-motion");
59
+
60
+ loadMotionPlugin(tsParticles); // awaitable
61
+ ```
62
+
63
+ or
64
+
65
+ ```javascript
66
+ import { tsParticles } from "tsparticles-engine";
67
+ import { loadMotionPlugin } from "tsparticles-plugin-motion";
68
+
69
+ loadMotionPlugin(tsParticles); // awaitable
70
+ ```
@@ -0,0 +1,49 @@
1
+ import { safeMatchMedia } from "@tsparticles/engine";
2
+ export class MotionInstance {
3
+ constructor(container, engine) {
4
+ this._container = container;
5
+ this._engine = engine;
6
+ }
7
+ async init() {
8
+ const container = this._container, options = container.actualOptions.motion;
9
+ if (options && (options.disable || options.reduce.value)) {
10
+ const mediaQuery = safeMatchMedia("(prefers-reduced-motion: reduce)");
11
+ if (mediaQuery) {
12
+ this._handleMotionChange(mediaQuery);
13
+ const handleChange = async () => {
14
+ this._handleMotionChange(mediaQuery);
15
+ try {
16
+ await container.refresh();
17
+ }
18
+ catch (_a) {
19
+ }
20
+ };
21
+ if (mediaQuery.addEventListener !== undefined) {
22
+ mediaQuery.addEventListener("change", handleChange);
23
+ }
24
+ else if (mediaQuery.addListener !== undefined) {
25
+ mediaQuery.addListener(handleChange);
26
+ }
27
+ }
28
+ else {
29
+ container.retina.reduceFactor = 1;
30
+ }
31
+ }
32
+ else {
33
+ container.retina.reduceFactor = 1;
34
+ }
35
+ }
36
+ _handleMotionChange(mediaQuery) {
37
+ const container = this._container, motion = container.actualOptions.motion;
38
+ if (!motion) {
39
+ return;
40
+ }
41
+ container.retina.reduceFactor = mediaQuery.matches
42
+ ? motion.disable
43
+ ? 0
44
+ : motion.reduce.value
45
+ ? 1 / motion.reduce.factor
46
+ : 1
47
+ : 1;
48
+ }
49
+ }
@@ -0,0 +1,16 @@
1
+ import { MotionReduce } from "./MotionReduce";
2
+ export class Motion {
3
+ constructor() {
4
+ this.disable = false;
5
+ this.reduce = new MotionReduce();
6
+ }
7
+ load(data) {
8
+ if (!data) {
9
+ return;
10
+ }
11
+ if (data.disable !== undefined) {
12
+ this.disable = data.disable;
13
+ }
14
+ this.reduce.load(data.reduce);
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ export class MotionReduce {
2
+ constructor() {
3
+ this.factor = 4;
4
+ this.value = true;
5
+ }
6
+ load(data) {
7
+ if (!data) {
8
+ return;
9
+ }
10
+ if (data.factor !== undefined) {
11
+ this.factor = data.factor;
12
+ }
13
+ if (data.value !== undefined) {
14
+ this.value = data.value;
15
+ }
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { Motion } from "./Options/Classes/Motion";
2
+ import { MotionInstance } from "./MotionInstance";
3
+ class MotionPlugin {
4
+ constructor(engine) {
5
+ this.id = "motion";
6
+ this._engine = engine;
7
+ }
8
+ getPlugin(container) {
9
+ return new MotionInstance(container, this._engine);
10
+ }
11
+ loadOptions(options, source) {
12
+ if (!this.needsPlugin()) {
13
+ return;
14
+ }
15
+ let motionOptions = options.motion;
16
+ if ((motionOptions === null || motionOptions === void 0 ? void 0 : motionOptions.load) === undefined) {
17
+ options.motion = motionOptions = new Motion();
18
+ }
19
+ motionOptions.load(source === null || source === void 0 ? void 0 : source.motion);
20
+ }
21
+ needsPlugin() {
22
+ return true;
23
+ }
24
+ }
25
+ export async function loadMotionPlugin(engine) {
26
+ const plugin = new MotionPlugin(engine);
27
+ await engine.addPlugin(plugin);
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MotionInstance = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class MotionInstance {
15
+ constructor(container, engine) {
16
+ this._container = container;
17
+ this._engine = engine;
18
+ }
19
+ init() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const container = this._container, options = container.actualOptions.motion;
22
+ if (options && (options.disable || options.reduce.value)) {
23
+ const mediaQuery = (0, engine_1.safeMatchMedia)("(prefers-reduced-motion: reduce)");
24
+ if (mediaQuery) {
25
+ this._handleMotionChange(mediaQuery);
26
+ const handleChange = () => __awaiter(this, void 0, void 0, function* () {
27
+ this._handleMotionChange(mediaQuery);
28
+ try {
29
+ yield container.refresh();
30
+ }
31
+ catch (_a) {
32
+ }
33
+ });
34
+ if (mediaQuery.addEventListener !== undefined) {
35
+ mediaQuery.addEventListener("change", handleChange);
36
+ }
37
+ else if (mediaQuery.addListener !== undefined) {
38
+ mediaQuery.addListener(handleChange);
39
+ }
40
+ }
41
+ else {
42
+ container.retina.reduceFactor = 1;
43
+ }
44
+ }
45
+ else {
46
+ container.retina.reduceFactor = 1;
47
+ }
48
+ });
49
+ }
50
+ _handleMotionChange(mediaQuery) {
51
+ const container = this._container, motion = container.actualOptions.motion;
52
+ if (!motion) {
53
+ return;
54
+ }
55
+ container.retina.reduceFactor = mediaQuery.matches
56
+ ? motion.disable
57
+ ? 0
58
+ : motion.reduce.value
59
+ ? 1 / motion.reduce.factor
60
+ : 1
61
+ : 1;
62
+ }
63
+ }
64
+ exports.MotionInstance = MotionInstance;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Motion = void 0;
4
+ const MotionReduce_1 = require("./MotionReduce");
5
+ class Motion {
6
+ constructor() {
7
+ this.disable = false;
8
+ this.reduce = new MotionReduce_1.MotionReduce();
9
+ }
10
+ load(data) {
11
+ if (!data) {
12
+ return;
13
+ }
14
+ if (data.disable !== undefined) {
15
+ this.disable = data.disable;
16
+ }
17
+ this.reduce.load(data.reduce);
18
+ }
19
+ }
20
+ exports.Motion = Motion;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MotionReduce = void 0;
4
+ class MotionReduce {
5
+ constructor() {
6
+ this.factor = 4;
7
+ this.value = true;
8
+ }
9
+ load(data) {
10
+ if (!data) {
11
+ return;
12
+ }
13
+ if (data.factor !== undefined) {
14
+ this.factor = data.factor;
15
+ }
16
+ if (data.value !== undefined) {
17
+ this.value = data.value;
18
+ }
19
+ }
20
+ }
21
+ exports.MotionReduce = MotionReduce;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadMotionPlugin = void 0;
13
+ const Motion_1 = require("./Options/Classes/Motion");
14
+ const MotionInstance_1 = require("./MotionInstance");
15
+ class MotionPlugin {
16
+ constructor(engine) {
17
+ this.id = "motion";
18
+ this._engine = engine;
19
+ }
20
+ getPlugin(container) {
21
+ return new MotionInstance_1.MotionInstance(container, this._engine);
22
+ }
23
+ loadOptions(options, source) {
24
+ if (!this.needsPlugin()) {
25
+ return;
26
+ }
27
+ let motionOptions = options.motion;
28
+ if ((motionOptions === null || motionOptions === void 0 ? void 0 : motionOptions.load) === undefined) {
29
+ options.motion = motionOptions = new Motion_1.Motion();
30
+ }
31
+ motionOptions.load(source === null || source === void 0 ? void 0 : source.motion);
32
+ }
33
+ needsPlugin() {
34
+ return true;
35
+ }
36
+ }
37
+ function loadMotionPlugin(engine) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const plugin = new MotionPlugin(engine);
40
+ yield engine.addPlugin(plugin);
41
+ });
42
+ }
43
+ exports.loadMotionPlugin = loadMotionPlugin;
package/cjs/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,49 @@
1
+ import { safeMatchMedia } from "@tsparticles/engine";
2
+ export class MotionInstance {
3
+ constructor(container, engine) {
4
+ this._container = container;
5
+ this._engine = engine;
6
+ }
7
+ async init() {
8
+ const container = this._container, options = container.actualOptions.motion;
9
+ if (options && (options.disable || options.reduce.value)) {
10
+ const mediaQuery = safeMatchMedia("(prefers-reduced-motion: reduce)");
11
+ if (mediaQuery) {
12
+ this._handleMotionChange(mediaQuery);
13
+ const handleChange = async () => {
14
+ this._handleMotionChange(mediaQuery);
15
+ try {
16
+ await container.refresh();
17
+ }
18
+ catch (_a) {
19
+ }
20
+ };
21
+ if (mediaQuery.addEventListener !== undefined) {
22
+ mediaQuery.addEventListener("change", handleChange);
23
+ }
24
+ else if (mediaQuery.addListener !== undefined) {
25
+ mediaQuery.addListener(handleChange);
26
+ }
27
+ }
28
+ else {
29
+ container.retina.reduceFactor = 1;
30
+ }
31
+ }
32
+ else {
33
+ container.retina.reduceFactor = 1;
34
+ }
35
+ }
36
+ _handleMotionChange(mediaQuery) {
37
+ const container = this._container, motion = container.actualOptions.motion;
38
+ if (!motion) {
39
+ return;
40
+ }
41
+ container.retina.reduceFactor = mediaQuery.matches
42
+ ? motion.disable
43
+ ? 0
44
+ : motion.reduce.value
45
+ ? 1 / motion.reduce.factor
46
+ : 1
47
+ : 1;
48
+ }
49
+ }
@@ -0,0 +1,16 @@
1
+ import { MotionReduce } from "./MotionReduce";
2
+ export class Motion {
3
+ constructor() {
4
+ this.disable = false;
5
+ this.reduce = new MotionReduce();
6
+ }
7
+ load(data) {
8
+ if (!data) {
9
+ return;
10
+ }
11
+ if (data.disable !== undefined) {
12
+ this.disable = data.disable;
13
+ }
14
+ this.reduce.load(data.reduce);
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ export class MotionReduce {
2
+ constructor() {
3
+ this.factor = 4;
4
+ this.value = true;
5
+ }
6
+ load(data) {
7
+ if (!data) {
8
+ return;
9
+ }
10
+ if (data.factor !== undefined) {
11
+ this.factor = data.factor;
12
+ }
13
+ if (data.value !== undefined) {
14
+ this.value = data.value;
15
+ }
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import { Motion } from "./Options/Classes/Motion";
2
+ import { MotionInstance } from "./MotionInstance";
3
+ class MotionPlugin {
4
+ constructor(engine) {
5
+ this.id = "motion";
6
+ this._engine = engine;
7
+ }
8
+ getPlugin(container) {
9
+ return new MotionInstance(container, this._engine);
10
+ }
11
+ loadOptions(options, source) {
12
+ if (!this.needsPlugin()) {
13
+ return;
14
+ }
15
+ let motionOptions = options.motion;
16
+ if ((motionOptions === null || motionOptions === void 0 ? void 0 : motionOptions.load) === undefined) {
17
+ options.motion = motionOptions = new Motion();
18
+ }
19
+ motionOptions.load(source === null || source === void 0 ? void 0 : source.motion);
20
+ }
21
+ needsPlugin() {
22
+ return true;
23
+ }
24
+ }
25
+ export async function loadMotionPlugin(engine) {
26
+ const plugin = new MotionPlugin(engine);
27
+ await engine.addPlugin(plugin);
28
+ }
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@tsparticles/plugin-motion",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles motion sickness plugin",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "plugins/motion"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin"
64
+ ],
65
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
66
+ "license": "MIT",
67
+ "bugs": {
68
+ "url": "https://github.com/matteobruni/tsparticles/issues"
69
+ },
70
+ "main": "cjs/index.js",
71
+ "jsdelivr": "tsparticles.plugin.motion.min.js",
72
+ "unpkg": "tsparticles.plugin.motion.min.js",
73
+ "module": "esm/index.js",
74
+ "types": "types/index.d.ts",
75
+ "publishConfig": {
76
+ "access": "public"
77
+ },
78
+ "dependencies": {
79
+ "@tsparticles/engine": "^3.0.0-alpha.0"
80
+ }
81
+ }