@tsparticles/updater-twinkle 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 (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Options/Classes/Twinkle.js +14 -0
  4. package/browser/Options/Classes/TwinkleValues.js +25 -0
  5. package/browser/Options/Interfaces/ITwinkle.js +1 -0
  6. package/browser/Options/Interfaces/ITwinkleValues.js +1 -0
  7. package/browser/TwinkleUpdater.js +33 -0
  8. package/browser/index.js +4 -0
  9. package/cjs/Options/Classes/Twinkle.js +18 -0
  10. package/cjs/Options/Classes/TwinkleValues.js +29 -0
  11. package/cjs/Options/Interfaces/ITwinkle.js +2 -0
  12. package/cjs/Options/Interfaces/ITwinkleValues.js +2 -0
  13. package/cjs/TwinkleUpdater.js +37 -0
  14. package/cjs/index.js +19 -0
  15. package/esm/Options/Classes/Twinkle.js +14 -0
  16. package/esm/Options/Classes/TwinkleValues.js +25 -0
  17. package/esm/Options/Interfaces/ITwinkle.js +1 -0
  18. package/esm/Options/Interfaces/ITwinkleValues.js +1 -0
  19. package/esm/TwinkleUpdater.js +33 -0
  20. package/esm/index.js +4 -0
  21. package/package.json +82 -0
  22. package/report.html +39 -0
  23. package/tsparticles.updater.twinkle.js +192 -0
  24. package/tsparticles.updater.twinkle.min.js +2 -0
  25. package/tsparticles.updater.twinkle.min.js.LICENSE.txt +8 -0
  26. package/types/Options/Classes/Twinkle.d.ts +9 -0
  27. package/types/Options/Classes/TwinkleValues.d.ts +11 -0
  28. package/types/Options/Interfaces/ITwinkle.d.ts +5 -0
  29. package/types/Options/Interfaces/ITwinkleValues.d.ts +7 -0
  30. package/types/TwinkleUpdater.d.ts +20 -0
  31. package/types/index.d.ts +2 -0
  32. package/umd/Options/Classes/Twinkle.js +28 -0
  33. package/umd/Options/Classes/TwinkleValues.js +39 -0
  34. package/umd/Options/Interfaces/ITwinkle.js +12 -0
  35. package/umd/Options/Interfaces/ITwinkleValues.js +12 -0
  36. package/umd/TwinkleUpdater.js +47 -0
  37. package/umd/index.js +18 -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 Twinkle Updater
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-updater-twinkle/badge)](https://www.jsdelivr.com/package/npm/tsparticles-updater-twinkle)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-updater-twinkle.svg)](https://www.npmjs.com/package/tsparticles-updater-twinkle)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-updater-twinkle)](https://www.npmjs.com/package/tsparticles-updater-twinkle) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for twinkle animations.
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.updater.twinkle.min.js` file will export the function to load the updater plugin:
18
+
19
+ ```javascript
20
+ loadTwinkleUpdater;
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the updater plugin like this:
26
+
27
+ ```javascript
28
+ (async () => {
29
+ await loadTwinkleUpdater();
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-updater-twinkle
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add tsparticles-updater-twinkle
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 { loadTwinkleUpdater } = require("tsparticles-updater-twinkle");
59
+
60
+ loadTwinkleUpdater(tsParticles);
61
+ ```
62
+
63
+ or
64
+
65
+ ```javascript
66
+ import { tsParticles } from "tsparticles-engine";
67
+ import { loadTwinkleUpdater } from "tsparticles-updater-twinkle";
68
+
69
+ loadTwinkleUpdater(tsParticles);
70
+ ```
@@ -0,0 +1,14 @@
1
+ import { TwinkleValues } from "./TwinkleValues";
2
+ export class Twinkle {
3
+ constructor() {
4
+ this.lines = new TwinkleValues();
5
+ this.particles = new TwinkleValues();
6
+ }
7
+ load(data) {
8
+ if (!data) {
9
+ return;
10
+ }
11
+ this.lines.load(data.lines);
12
+ this.particles.load(data.particles);
13
+ }
14
+ }
@@ -0,0 +1,25 @@
1
+ import { OptionsColor, setRangeValue } from "@tsparticles/engine";
2
+ export class TwinkleValues {
3
+ constructor() {
4
+ this.enable = false;
5
+ this.frequency = 0.05;
6
+ this.opacity = 1;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.color !== undefined) {
13
+ this.color = OptionsColor.create(this.color, data.color);
14
+ }
15
+ if (data.enable !== undefined) {
16
+ this.enable = data.enable;
17
+ }
18
+ if (data.frequency !== undefined) {
19
+ this.frequency = data.frequency;
20
+ }
21
+ if (data.opacity !== undefined) {
22
+ this.opacity = setRangeValue(data.opacity);
23
+ }
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { getRandom, getRangeValue, getStyleFromHsl, rangeColorToHsl } from "@tsparticles/engine";
2
+ import { Twinkle } from "./Options/Classes/Twinkle";
3
+ export class TwinkleUpdater {
4
+ getColorStyles(particle, context, radius, opacity) {
5
+ const pOptions = particle.options, twinkleOptions = pOptions.twinkle;
6
+ if (!twinkleOptions) {
7
+ return {};
8
+ }
9
+ const twinkle = twinkleOptions.particles, twinkling = twinkle.enable && getRandom() < twinkle.frequency, zIndexOptions = particle.options.zIndex, zOpacityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.opacityRate, twinklingOpacity = twinkling ? getRangeValue(twinkle.opacity) * zOpacityFactor : opacity, twinkleRgb = rangeColorToHsl(twinkle.color), twinkleStyle = twinkleRgb ? getStyleFromHsl(twinkleRgb, twinklingOpacity) : undefined, res = {}, needsTwinkle = twinkling && twinkleStyle;
10
+ res.fill = needsTwinkle ? twinkleStyle : undefined;
11
+ res.stroke = needsTwinkle ? twinkleStyle : undefined;
12
+ return res;
13
+ }
14
+ init() {
15
+ }
16
+ isEnabled(particle) {
17
+ const pOptions = particle.options, twinkleOptions = pOptions.twinkle;
18
+ if (!twinkleOptions) {
19
+ return false;
20
+ }
21
+ return twinkleOptions.particles.enable;
22
+ }
23
+ loadOptions(options, ...sources) {
24
+ if (!options.twinkle) {
25
+ options.twinkle = new Twinkle();
26
+ }
27
+ for (const source of sources) {
28
+ options.twinkle.load(source === null || source === void 0 ? void 0 : source.twinkle);
29
+ }
30
+ }
31
+ update() {
32
+ }
33
+ }
@@ -0,0 +1,4 @@
1
+ import { TwinkleUpdater } from "./TwinkleUpdater";
2
+ export async function loadTwinkleUpdater(engine) {
3
+ await engine.addParticleUpdater("twinkle", () => new TwinkleUpdater());
4
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Twinkle = void 0;
4
+ const TwinkleValues_1 = require("./TwinkleValues");
5
+ class Twinkle {
6
+ constructor() {
7
+ this.lines = new TwinkleValues_1.TwinkleValues();
8
+ this.particles = new TwinkleValues_1.TwinkleValues();
9
+ }
10
+ load(data) {
11
+ if (!data) {
12
+ return;
13
+ }
14
+ this.lines.load(data.lines);
15
+ this.particles.load(data.particles);
16
+ }
17
+ }
18
+ exports.Twinkle = Twinkle;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TwinkleValues = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class TwinkleValues {
6
+ constructor() {
7
+ this.enable = false;
8
+ this.frequency = 0.05;
9
+ this.opacity = 1;
10
+ }
11
+ load(data) {
12
+ if (!data) {
13
+ return;
14
+ }
15
+ if (data.color !== undefined) {
16
+ this.color = engine_1.OptionsColor.create(this.color, data.color);
17
+ }
18
+ if (data.enable !== undefined) {
19
+ this.enable = data.enable;
20
+ }
21
+ if (data.frequency !== undefined) {
22
+ this.frequency = data.frequency;
23
+ }
24
+ if (data.opacity !== undefined) {
25
+ this.opacity = (0, engine_1.setRangeValue)(data.opacity);
26
+ }
27
+ }
28
+ }
29
+ exports.TwinkleValues = TwinkleValues;
@@ -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 });
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TwinkleUpdater = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const Twinkle_1 = require("./Options/Classes/Twinkle");
6
+ class TwinkleUpdater {
7
+ getColorStyles(particle, context, radius, opacity) {
8
+ const pOptions = particle.options, twinkleOptions = pOptions.twinkle;
9
+ if (!twinkleOptions) {
10
+ return {};
11
+ }
12
+ const twinkle = twinkleOptions.particles, twinkling = twinkle.enable && (0, engine_1.getRandom)() < twinkle.frequency, zIndexOptions = particle.options.zIndex, zOpacityFactor = Math.pow((1 - particle.zIndexFactor), zIndexOptions.opacityRate), twinklingOpacity = twinkling ? (0, engine_1.getRangeValue)(twinkle.opacity) * zOpacityFactor : opacity, twinkleRgb = (0, engine_1.rangeColorToHsl)(twinkle.color), twinkleStyle = twinkleRgb ? (0, engine_1.getStyleFromHsl)(twinkleRgb, twinklingOpacity) : undefined, res = {}, needsTwinkle = twinkling && twinkleStyle;
13
+ res.fill = needsTwinkle ? twinkleStyle : undefined;
14
+ res.stroke = needsTwinkle ? twinkleStyle : undefined;
15
+ return res;
16
+ }
17
+ init() {
18
+ }
19
+ isEnabled(particle) {
20
+ const pOptions = particle.options, twinkleOptions = pOptions.twinkle;
21
+ if (!twinkleOptions) {
22
+ return false;
23
+ }
24
+ return twinkleOptions.particles.enable;
25
+ }
26
+ loadOptions(options, ...sources) {
27
+ if (!options.twinkle) {
28
+ options.twinkle = new Twinkle_1.Twinkle();
29
+ }
30
+ for (const source of sources) {
31
+ options.twinkle.load(source === null || source === void 0 ? void 0 : source.twinkle);
32
+ }
33
+ }
34
+ update() {
35
+ }
36
+ }
37
+ exports.TwinkleUpdater = TwinkleUpdater;
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.loadTwinkleUpdater = void 0;
13
+ const TwinkleUpdater_1 = require("./TwinkleUpdater");
14
+ function loadTwinkleUpdater(engine) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ yield engine.addParticleUpdater("twinkle", () => new TwinkleUpdater_1.TwinkleUpdater());
17
+ });
18
+ }
19
+ exports.loadTwinkleUpdater = loadTwinkleUpdater;
@@ -0,0 +1,14 @@
1
+ import { TwinkleValues } from "./TwinkleValues";
2
+ export class Twinkle {
3
+ constructor() {
4
+ this.lines = new TwinkleValues();
5
+ this.particles = new TwinkleValues();
6
+ }
7
+ load(data) {
8
+ if (!data) {
9
+ return;
10
+ }
11
+ this.lines.load(data.lines);
12
+ this.particles.load(data.particles);
13
+ }
14
+ }
@@ -0,0 +1,25 @@
1
+ import { OptionsColor, setRangeValue } from "@tsparticles/engine";
2
+ export class TwinkleValues {
3
+ constructor() {
4
+ this.enable = false;
5
+ this.frequency = 0.05;
6
+ this.opacity = 1;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.color !== undefined) {
13
+ this.color = OptionsColor.create(this.color, data.color);
14
+ }
15
+ if (data.enable !== undefined) {
16
+ this.enable = data.enable;
17
+ }
18
+ if (data.frequency !== undefined) {
19
+ this.frequency = data.frequency;
20
+ }
21
+ if (data.opacity !== undefined) {
22
+ this.opacity = setRangeValue(data.opacity);
23
+ }
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { getRandom, getRangeValue, getStyleFromHsl, rangeColorToHsl } from "@tsparticles/engine";
2
+ import { Twinkle } from "./Options/Classes/Twinkle";
3
+ export class TwinkleUpdater {
4
+ getColorStyles(particle, context, radius, opacity) {
5
+ const pOptions = particle.options, twinkleOptions = pOptions.twinkle;
6
+ if (!twinkleOptions) {
7
+ return {};
8
+ }
9
+ const twinkle = twinkleOptions.particles, twinkling = twinkle.enable && getRandom() < twinkle.frequency, zIndexOptions = particle.options.zIndex, zOpacityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.opacityRate, twinklingOpacity = twinkling ? getRangeValue(twinkle.opacity) * zOpacityFactor : opacity, twinkleRgb = rangeColorToHsl(twinkle.color), twinkleStyle = twinkleRgb ? getStyleFromHsl(twinkleRgb, twinklingOpacity) : undefined, res = {}, needsTwinkle = twinkling && twinkleStyle;
10
+ res.fill = needsTwinkle ? twinkleStyle : undefined;
11
+ res.stroke = needsTwinkle ? twinkleStyle : undefined;
12
+ return res;
13
+ }
14
+ init() {
15
+ }
16
+ isEnabled(particle) {
17
+ const pOptions = particle.options, twinkleOptions = pOptions.twinkle;
18
+ if (!twinkleOptions) {
19
+ return false;
20
+ }
21
+ return twinkleOptions.particles.enable;
22
+ }
23
+ loadOptions(options, ...sources) {
24
+ if (!options.twinkle) {
25
+ options.twinkle = new Twinkle();
26
+ }
27
+ for (const source of sources) {
28
+ options.twinkle.load(source === null || source === void 0 ? void 0 : source.twinkle);
29
+ }
30
+ }
31
+ update() {
32
+ }
33
+ }
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { TwinkleUpdater } from "./TwinkleUpdater";
2
+ export async function loadTwinkleUpdater(engine) {
3
+ await engine.addParticleUpdater("twinkle", () => new TwinkleUpdater());
4
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@tsparticles/updater-twinkle",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles particles twinkle updater",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "updaters/twinkle"
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
+ "@tsparticles/updater"
65
+ ],
66
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "main": "cjs/index.js",
72
+ "jsdelivr": "tsparticles.updater.twinkle.min.js",
73
+ "unpkg": "tsparticles.updater.twinkle.min.js",
74
+ "module": "esm/index.js",
75
+ "types": "types/index.d.ts",
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "dependencies": {
80
+ "@tsparticles/engine": "^3.0.0-alpha.0"
81
+ }
82
+ }