@tsparticles/move-parallax 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.
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 Parallax Mover
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-move-parallax/badge)](https://www.jsdelivr.com/package/npm/tsparticles-move-parallax)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-move-parallax.svg)](https://www.npmjs.com/package/tsparticles-move-parallax)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-move-parallax)](https://www.npmjs.com/package/tsparticles-move-parallax) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) move plugin for parallax effect.
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.move.parallax.min.js` file will export the function to load the interaction plugin:
18
+
19
+ ```javascript
20
+ loadParallaxMover;
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
26
+
27
+ ```javascript
28
+ (async () => {
29
+ await loadParallaxMover(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-move-parallax
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add tsparticles-move-parallax
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 { loadParallaxMover } = require("tsparticles-move-parallax");
59
+
60
+ loadParallaxMover(tsParticles); // awaitable
61
+ ```
62
+
63
+ or
64
+
65
+ ```javascript
66
+ import { tsParticles } from "tsparticles-engine";
67
+ import { loadParallaxMover } from "tsparticles-move-parallax";
68
+
69
+ loadParallaxMover(tsParticles); // awaitable
70
+ ```
@@ -0,0 +1,29 @@
1
+ import { isSsr } from "@tsparticles/engine";
2
+ export class ParallaxMover {
3
+ init() {
4
+ }
5
+ isEnabled(particle) {
6
+ return (!isSsr() &&
7
+ !particle.destroyed &&
8
+ particle.container.actualOptions.interactivity.events.onHover.parallax.enable);
9
+ }
10
+ move(particle) {
11
+ const container = particle.container, options = container.actualOptions;
12
+ if (isSsr() || !options.interactivity.events.onHover.parallax.enable) {
13
+ return;
14
+ }
15
+ const parallaxForce = options.interactivity.events.onHover.parallax.force, mousePos = container.interactivity.mouse.position;
16
+ if (!mousePos) {
17
+ return;
18
+ }
19
+ const canvasCenter = {
20
+ x: container.canvas.size.width / 2,
21
+ y: container.canvas.size.height / 2,
22
+ }, parallaxSmooth = options.interactivity.events.onHover.parallax.smooth, factor = particle.getRadius() / parallaxForce, centerDistance = {
23
+ x: (mousePos.x - canvasCenter.x) * factor,
24
+ y: (mousePos.y - canvasCenter.y) * factor,
25
+ };
26
+ particle.offset.x += (centerDistance.x - particle.offset.x) / parallaxSmooth;
27
+ particle.offset.y += (centerDistance.y - particle.offset.y) / parallaxSmooth;
28
+ }
29
+ }
@@ -0,0 +1,4 @@
1
+ import { ParallaxMover } from "./ParallaxMover";
2
+ export async function loadParallaxMover(engine) {
3
+ engine.addMover("parallax", () => new ParallaxMover());
4
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParallaxMover = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class ParallaxMover {
6
+ init() {
7
+ }
8
+ isEnabled(particle) {
9
+ return (!(0, engine_1.isSsr)() &&
10
+ !particle.destroyed &&
11
+ particle.container.actualOptions.interactivity.events.onHover.parallax.enable);
12
+ }
13
+ move(particle) {
14
+ const container = particle.container, options = container.actualOptions;
15
+ if ((0, engine_1.isSsr)() || !options.interactivity.events.onHover.parallax.enable) {
16
+ return;
17
+ }
18
+ const parallaxForce = options.interactivity.events.onHover.parallax.force, mousePos = container.interactivity.mouse.position;
19
+ if (!mousePos) {
20
+ return;
21
+ }
22
+ const canvasCenter = {
23
+ x: container.canvas.size.width / 2,
24
+ y: container.canvas.size.height / 2,
25
+ }, parallaxSmooth = options.interactivity.events.onHover.parallax.smooth, factor = particle.getRadius() / parallaxForce, centerDistance = {
26
+ x: (mousePos.x - canvasCenter.x) * factor,
27
+ y: (mousePos.y - canvasCenter.y) * factor,
28
+ };
29
+ particle.offset.x += (centerDistance.x - particle.offset.x) / parallaxSmooth;
30
+ particle.offset.y += (centerDistance.y - particle.offset.y) / parallaxSmooth;
31
+ }
32
+ }
33
+ exports.ParallaxMover = ParallaxMover;
package/cjs/index.js ADDED
@@ -0,0 +1,19 @@
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.loadParallaxMover = void 0;
13
+ const ParallaxMover_1 = require("./ParallaxMover");
14
+ function loadParallaxMover(engine) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ engine.addMover("parallax", () => new ParallaxMover_1.ParallaxMover());
17
+ });
18
+ }
19
+ exports.loadParallaxMover = loadParallaxMover;
@@ -0,0 +1,29 @@
1
+ import { isSsr } from "@tsparticles/engine";
2
+ export class ParallaxMover {
3
+ init() {
4
+ }
5
+ isEnabled(particle) {
6
+ return (!isSsr() &&
7
+ !particle.destroyed &&
8
+ particle.container.actualOptions.interactivity.events.onHover.parallax.enable);
9
+ }
10
+ move(particle) {
11
+ const container = particle.container, options = container.actualOptions;
12
+ if (isSsr() || !options.interactivity.events.onHover.parallax.enable) {
13
+ return;
14
+ }
15
+ const parallaxForce = options.interactivity.events.onHover.parallax.force, mousePos = container.interactivity.mouse.position;
16
+ if (!mousePos) {
17
+ return;
18
+ }
19
+ const canvasCenter = {
20
+ x: container.canvas.size.width / 2,
21
+ y: container.canvas.size.height / 2,
22
+ }, parallaxSmooth = options.interactivity.events.onHover.parallax.smooth, factor = particle.getRadius() / parallaxForce, centerDistance = {
23
+ x: (mousePos.x - canvasCenter.x) * factor,
24
+ y: (mousePos.y - canvasCenter.y) * factor,
25
+ };
26
+ particle.offset.x += (centerDistance.x - particle.offset.x) / parallaxSmooth;
27
+ particle.offset.y += (centerDistance.y - particle.offset.y) / parallaxSmooth;
28
+ }
29
+ }
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { ParallaxMover } from "./ParallaxMover";
2
+ export async function loadParallaxMover(engine) {
3
+ engine.addMover("parallax", () => new ParallaxMover());
4
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@tsparticles/move-parallax",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles Parallax movement",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "move/parallax"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles",
16
+ "particle",
17
+ "canvas",
18
+ "jsparticles",
19
+ "xparticles",
20
+ "particles-js",
21
+ "particles.js",
22
+ "particles-ts",
23
+ "particles.ts",
24
+ "typescript",
25
+ "javascript",
26
+ "animation",
27
+ "web",
28
+ "html5",
29
+ "web-design",
30
+ "webdesign",
31
+ "css",
32
+ "html",
33
+ "css3",
34
+ "animated",
35
+ "background",
36
+ "@tsparticles/shape"
37
+ ],
38
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
39
+ "license": "MIT",
40
+ "bugs": {
41
+ "url": "https://github.com/matteobruni/tsparticles/issues"
42
+ },
43
+ "main": "cjs/index.js",
44
+ "jsdelivr": "tsparticles.move.parallax.min.js",
45
+ "unpkg": "tsparticles.move.parallax.min.js",
46
+ "module": "esm/index.js",
47
+ "types": "types/index.d.ts",
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "dependencies": {
52
+ "@tsparticles/engine": "^3.0.0-alpha.0"
53
+ }
54
+ }