@tsparticles/plugin-motion 3.9.1 → 4.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.
package/235.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 235.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_motion=this.webpackChunk_tsparticles_plugin_motion||[]).push([[235],{235(e,t,i){i.d(t,{MotionPlugin:()=>s});var a=i(303);class o{constructor(){this.factor=4,this.value=!0}load(e){(0,a.isNull)(e)||(void 0!==e.factor&&(this.factor=e.factor),void 0!==e.value&&(this.value=e.value))}}class n{constructor(){this.disable=!0,this.reduce=new o}load(e){(0,a.isNull)(e)||(void 0!==e.disable&&(this.disable=e.disable),this.reduce.load(e.reduce))}}class r{constructor(e){this._handleMotionChange=e=>{const t=this._container,i=t.actualOptions.motion;i&&(e.matches?i.disable?t.retina.reduceFactor=0:t.retina.reduceFactor=i.reduce.value?1/i.reduce.factor:1:t.retina.reduceFactor=1)},this._container=e}async init(){const e=this._container,t=e.actualOptions.motion;if(!t||!t.disable&&!t.reduce.value)return void(e.retina.reduceFactor=1);const i=(0,a.safeMatchMedia)("(prefers-reduced-motion: reduce)");if(!i)return void(e.retina.reduceFactor=1);this._handleMotionChange(i);i.addEventListener("change",(()=>{(async()=>{this._handleMotionChange(i);try{await e.refresh()}catch{}})()})),await Promise.resolve()}}class s{constructor(){this.id="motion"}getPlugin(e){return Promise.resolve(new r(e))}loadOptions(e,t){if(!this.needsPlugin())return;let i=e.motion;i?.load||(e.motion=i=new n),i.load(t?.motion)}needsPlugin(){return!0}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Motion Plugin v4.0.0-alpha.0 by Matteo Bruni */
@@ -1,7 +1,7 @@
1
1
  import { safeMatchMedia } from "@tsparticles/engine";
2
2
  const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
3
3
  export class MotionInstance {
4
- constructor(container, engine) {
4
+ constructor(container) {
5
5
  this._handleMotionChange = mediaQuery => {
6
6
  const container = this._container, motion = container.actualOptions.motion;
7
7
  if (!motion) {
@@ -20,7 +20,6 @@ export class MotionInstance {
20
20
  }
21
21
  };
22
22
  this._container = container;
23
- this._engine = engine;
24
23
  }
25
24
  async init() {
26
25
  const container = this._container, options = container.actualOptions.motion;
@@ -44,12 +43,7 @@ export class MotionInstance {
44
43
  }
45
44
  })();
46
45
  };
47
- if (mediaQuery.addEventListener !== undefined) {
48
- mediaQuery.addEventListener("change", handleChange);
49
- }
50
- else if (mediaQuery.addListener !== undefined) {
51
- mediaQuery.addListener(handleChange);
52
- }
46
+ mediaQuery.addEventListener("change", handleChange);
53
47
  await Promise.resolve();
54
48
  }
55
49
  }
@@ -1,12 +1,11 @@
1
1
  import { Motion } from "./Options/Classes/Motion.js";
2
2
  import { MotionInstance } from "./MotionInstance.js";
3
3
  export class MotionPlugin {
4
- constructor(engine) {
4
+ constructor() {
5
5
  this.id = "motion";
6
- this._engine = engine;
7
6
  }
8
7
  getPlugin(container) {
9
- return Promise.resolve(new MotionInstance(container, this._engine));
8
+ return Promise.resolve(new MotionInstance(container));
10
9
  }
11
10
  loadOptions(options, source) {
12
11
  if (!this.needsPlugin()) {
package/browser/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { MotionPlugin } from "./MotionPlugin.js";
2
- export async function loadMotionPlugin(engine, refresh = true) {
3
- engine.checkVersion("3.9.1");
4
- await engine.addPlugin(new MotionPlugin(engine), refresh);
1
+ export function loadMotionPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { MotionPlugin } = await import("./MotionPlugin.js");
5
+ e.addPlugin(new MotionPlugin());
6
+ });
5
7
  }
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MotionInstance = void 0;
4
- const engine_1 = require("@tsparticles/engine");
1
+ import { safeMatchMedia } from "@tsparticles/engine";
5
2
  const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
6
- class MotionInstance {
7
- constructor(container, engine) {
3
+ export class MotionInstance {
4
+ constructor(container) {
8
5
  this._handleMotionChange = mediaQuery => {
9
6
  const container = this._container, motion = container.actualOptions.motion;
10
7
  if (!motion) {
@@ -23,7 +20,6 @@ class MotionInstance {
23
20
  }
24
21
  };
25
22
  this._container = container;
26
- this._engine = engine;
27
23
  }
28
24
  async init() {
29
25
  const container = this._container, options = container.actualOptions.motion;
@@ -31,7 +27,7 @@ class MotionInstance {
31
27
  container.retina.reduceFactor = 1;
32
28
  return;
33
29
  }
34
- const mediaQuery = (0, engine_1.safeMatchMedia)("(prefers-reduced-motion: reduce)");
30
+ const mediaQuery = safeMatchMedia("(prefers-reduced-motion: reduce)");
35
31
  if (!mediaQuery) {
36
32
  container.retina.reduceFactor = defaultFactor;
37
33
  return;
@@ -47,13 +43,7 @@ class MotionInstance {
47
43
  }
48
44
  })();
49
45
  };
50
- if (mediaQuery.addEventListener !== undefined) {
51
- mediaQuery.addEventListener("change", handleChange);
52
- }
53
- else if (mediaQuery.addListener !== undefined) {
54
- mediaQuery.addListener(handleChange);
55
- }
46
+ mediaQuery.addEventListener("change", handleChange);
56
47
  await Promise.resolve();
57
48
  }
58
49
  }
59
- exports.MotionInstance = MotionInstance;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MotionPlugin = void 0;
4
- const Motion_js_1 = require("./Options/Classes/Motion.js");
5
- const MotionInstance_js_1 = require("./MotionInstance.js");
6
- class MotionPlugin {
7
- constructor(engine) {
1
+ import { Motion } from "./Options/Classes/Motion.js";
2
+ import { MotionInstance } from "./MotionInstance.js";
3
+ export class MotionPlugin {
4
+ constructor() {
8
5
  this.id = "motion";
9
- this._engine = engine;
10
6
  }
11
7
  getPlugin(container) {
12
- return Promise.resolve(new MotionInstance_js_1.MotionInstance(container, this._engine));
8
+ return Promise.resolve(new MotionInstance(container));
13
9
  }
14
10
  loadOptions(options, source) {
15
11
  if (!this.needsPlugin()) {
@@ -17,7 +13,7 @@ class MotionPlugin {
17
13
  }
18
14
  let motionOptions = options.motion;
19
15
  if (!motionOptions?.load) {
20
- options.motion = motionOptions = new Motion_js_1.Motion();
16
+ options.motion = motionOptions = new Motion();
21
17
  }
22
18
  motionOptions.load(source?.motion);
23
19
  }
@@ -25,4 +21,3 @@ class MotionPlugin {
25
21
  return true;
26
22
  }
27
23
  }
28
- exports.MotionPlugin = MotionPlugin;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Motion = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const MotionReduce_js_1 = require("./MotionReduce.js");
6
- class Motion {
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { MotionReduce } from "./MotionReduce.js";
3
+ export class Motion {
7
4
  constructor() {
8
5
  this.disable = true;
9
- this.reduce = new MotionReduce_js_1.MotionReduce();
6
+ this.reduce = new MotionReduce();
10
7
  }
11
8
  load(data) {
12
- if ((0, engine_1.isNull)(data)) {
9
+ if (isNull(data)) {
13
10
  return;
14
11
  }
15
12
  if (data.disable !== undefined) {
@@ -18,4 +15,3 @@ class Motion {
18
15
  this.reduce.load(data.reduce);
19
16
  }
20
17
  }
21
- exports.Motion = Motion;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MotionReduce = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- class MotionReduce {
1
+ import { isNull } from "@tsparticles/engine";
2
+ export class MotionReduce {
6
3
  constructor() {
7
4
  this.factor = 4;
8
5
  this.value = true;
9
6
  }
10
7
  load(data) {
11
- if ((0, engine_1.isNull)(data)) {
8
+ if (isNull(data)) {
12
9
  return;
13
10
  }
14
11
  if (data.factor !== undefined) {
@@ -19,4 +16,3 @@ class MotionReduce {
19
16
  }
20
17
  }
21
18
  }
22
- exports.MotionReduce = MotionReduce;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/index.js CHANGED
@@ -1,8 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadMotionPlugin = loadMotionPlugin;
4
- const MotionPlugin_js_1 = require("./MotionPlugin.js");
5
- async function loadMotionPlugin(engine, refresh = true) {
6
- engine.checkVersion("3.9.1");
7
- await engine.addPlugin(new MotionPlugin_js_1.MotionPlugin(engine), refresh);
1
+ export function loadMotionPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { MotionPlugin } = await import("./MotionPlugin.js");
5
+ e.addPlugin(new MotionPlugin());
6
+ });
8
7
  }
package/cjs/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -0,0 +1,60 @@
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
+ * v4.0.0-alpha.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_plugin_motion"] = this["webpackChunk_tsparticles_plugin_motion"] || []).push([["dist_browser_MotionPlugin_js"],{
19
+
20
+ /***/ "./dist/browser/MotionInstance.js"
21
+ /*!****************************************!*\
22
+ !*** ./dist/browser/MotionInstance.js ***!
23
+ \****************************************/
24
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
+
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ MotionInstance: () => (/* binding */ MotionInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst defaultFactor = 1,\n defaultReduce = 1,\n disableReduce = 0,\n identity = 1;\nclass MotionInstance {\n constructor(container) {\n this._handleMotionChange = mediaQuery => {\n const container = this._container,\n motion = container.actualOptions.motion;\n if (!motion) {\n return;\n }\n if (mediaQuery.matches) {\n if (motion.disable) {\n container.retina.reduceFactor = disableReduce;\n } else {\n container.retina.reduceFactor = motion.reduce.value ? identity / motion.reduce.factor : defaultFactor;\n }\n } else {\n container.retina.reduceFactor = defaultReduce;\n }\n };\n this._container = container;\n }\n async init() {\n const container = this._container,\n options = container.actualOptions.motion;\n if (!(options && (options.disable || options.reduce.value))) {\n container.retina.reduceFactor = 1;\n return;\n }\n const mediaQuery = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeMatchMedia)(\"(prefers-reduced-motion: reduce)\");\n if (!mediaQuery) {\n container.retina.reduceFactor = defaultFactor;\n return;\n }\n this._handleMotionChange(mediaQuery);\n const handleChange = () => {\n void (async () => {\n this._handleMotionChange(mediaQuery);\n try {\n await container.refresh();\n } catch {}\n })();\n };\n mediaQuery.addEventListener(\"change\", handleChange);\n await Promise.resolve();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/MotionInstance.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/MotionPlugin.js"
31
+ /*!**************************************!*\
32
+ !*** ./dist/browser/MotionPlugin.js ***!
33
+ \**************************************/
34
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
35
+
36
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ MotionPlugin: () => (/* binding */ MotionPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Motion_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Motion.js */ \"./dist/browser/Options/Classes/Motion.js\");\n/* harmony import */ var _MotionInstance_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./MotionInstance.js */ \"./dist/browser/MotionInstance.js\");\n\n\nclass MotionPlugin {\n constructor() {\n this.id = \"motion\";\n }\n getPlugin(container) {\n return Promise.resolve(new _MotionInstance_js__WEBPACK_IMPORTED_MODULE_1__.MotionInstance(container));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin()) {\n return;\n }\n let motionOptions = options.motion;\n if (!motionOptions?.load) {\n options.motion = motionOptions = new _Options_Classes_Motion_js__WEBPACK_IMPORTED_MODULE_0__.Motion();\n }\n motionOptions.load(source?.motion);\n }\n needsPlugin() {\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/MotionPlugin.js?\n}");
37
+
38
+ /***/ },
39
+
40
+ /***/ "./dist/browser/Options/Classes/Motion.js"
41
+ /*!************************************************!*\
42
+ !*** ./dist/browser/Options/Classes/Motion.js ***!
43
+ \************************************************/
44
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
45
+
46
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Motion: () => (/* binding */ Motion)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _MotionReduce_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./MotionReduce.js */ \"./dist/browser/Options/Classes/MotionReduce.js\");\n\n\nclass Motion {\n constructor() {\n this.disable = true;\n this.reduce = new _MotionReduce_js__WEBPACK_IMPORTED_MODULE_1__.MotionReduce();\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.disable !== undefined) {\n this.disable = data.disable;\n }\n this.reduce.load(data.reduce);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/Options/Classes/Motion.js?\n}");
47
+
48
+ /***/ },
49
+
50
+ /***/ "./dist/browser/Options/Classes/MotionReduce.js"
51
+ /*!******************************************************!*\
52
+ !*** ./dist/browser/Options/Classes/MotionReduce.js ***!
53
+ \******************************************************/
54
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
55
+
56
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ MotionReduce: () => (/* binding */ MotionReduce)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass MotionReduce {\n constructor() {\n this.factor = 4;\n this.value = true;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.factor !== undefined) {\n this.factor = data.factor;\n }\n if (data.value !== undefined) {\n this.value = data.value;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/Options/Classes/MotionReduce.js?\n}");
57
+
58
+ /***/ }
59
+
60
+ }]);
@@ -1,7 +1,7 @@
1
1
  import { safeMatchMedia } from "@tsparticles/engine";
2
2
  const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
3
3
  export class MotionInstance {
4
- constructor(container, engine) {
4
+ constructor(container) {
5
5
  this._handleMotionChange = mediaQuery => {
6
6
  const container = this._container, motion = container.actualOptions.motion;
7
7
  if (!motion) {
@@ -20,7 +20,6 @@ export class MotionInstance {
20
20
  }
21
21
  };
22
22
  this._container = container;
23
- this._engine = engine;
24
23
  }
25
24
  async init() {
26
25
  const container = this._container, options = container.actualOptions.motion;
@@ -44,12 +43,7 @@ export class MotionInstance {
44
43
  }
45
44
  })();
46
45
  };
47
- if (mediaQuery.addEventListener !== undefined) {
48
- mediaQuery.addEventListener("change", handleChange);
49
- }
50
- else if (mediaQuery.addListener !== undefined) {
51
- mediaQuery.addListener(handleChange);
52
- }
46
+ mediaQuery.addEventListener("change", handleChange);
53
47
  await Promise.resolve();
54
48
  }
55
49
  }
@@ -1,12 +1,11 @@
1
1
  import { Motion } from "./Options/Classes/Motion.js";
2
2
  import { MotionInstance } from "./MotionInstance.js";
3
3
  export class MotionPlugin {
4
- constructor(engine) {
4
+ constructor() {
5
5
  this.id = "motion";
6
- this._engine = engine;
7
6
  }
8
7
  getPlugin(container) {
9
- return Promise.resolve(new MotionInstance(container, this._engine));
8
+ return Promise.resolve(new MotionInstance(container));
10
9
  }
11
10
  loadOptions(options, source) {
12
11
  if (!this.needsPlugin()) {
package/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { MotionPlugin } from "./MotionPlugin.js";
2
- export async function loadMotionPlugin(engine, refresh = true) {
3
- engine.checkVersion("3.9.1");
4
- await engine.addPlugin(new MotionPlugin(engine), refresh);
1
+ export function loadMotionPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { MotionPlugin } = await import("./MotionPlugin.js");
5
+ e.addPlugin(new MotionPlugin());
6
+ });
5
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-motion",
3
- "version": "3.9.1",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "tsParticles motion sickness plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -86,9 +86,10 @@
86
86
  "./package.json": "./package.json"
87
87
  },
88
88
  "dependencies": {
89
- "@tsparticles/engine": "3.9.1"
89
+ "@tsparticles/engine": "4.0.0-alpha.0"
90
90
  },
91
91
  "publishConfig": {
92
92
  "access": "public"
93
- }
93
+ },
94
+ "type": "module"
94
95
  }