@tsparticles/plugin-trail 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.
Files changed (53) hide show
  1. package/877.min.js +2 -0
  2. package/877.min.js.LICENSE.txt +1 -0
  3. package/LICENSE +21 -0
  4. package/README.md +74 -0
  5. package/browser/Options/Classes/Trail.js +23 -0
  6. package/browser/Options/Classes/TrailFill.js +14 -0
  7. package/browser/Options/Interfaces/ITrail.js +1 -0
  8. package/browser/Options/Interfaces/ITrailFill.js +1 -0
  9. package/browser/TrailInstance.js +72 -0
  10. package/browser/TrailPlugin.js +24 -0
  11. package/browser/index.js +7 -0
  12. package/browser/package.json +1 -0
  13. package/browser/types.js +1 -0
  14. package/cjs/Options/Classes/Trail.js +23 -0
  15. package/cjs/Options/Classes/TrailFill.js +14 -0
  16. package/cjs/Options/Interfaces/ITrail.js +1 -0
  17. package/cjs/Options/Interfaces/ITrailFill.js +1 -0
  18. package/cjs/TrailInstance.js +72 -0
  19. package/cjs/TrailPlugin.js +24 -0
  20. package/cjs/index.js +7 -0
  21. package/cjs/package.json +1 -0
  22. package/cjs/types.js +1 -0
  23. package/dist_browser_TrailPlugin_js.js +60 -0
  24. package/esm/Options/Classes/Trail.js +23 -0
  25. package/esm/Options/Classes/TrailFill.js +14 -0
  26. package/esm/Options/Interfaces/ITrail.js +1 -0
  27. package/esm/Options/Interfaces/ITrailFill.js +1 -0
  28. package/esm/TrailInstance.js +72 -0
  29. package/esm/TrailPlugin.js +24 -0
  30. package/esm/index.js +7 -0
  31. package/esm/package.json +1 -0
  32. package/esm/types.js +1 -0
  33. package/package.json +95 -0
  34. package/report.html +40 -0
  35. package/tsparticles.plugin.trail.js +317 -0
  36. package/tsparticles.plugin.trail.min.js +2 -0
  37. package/tsparticles.plugin.trail.min.js.LICENSE.txt +1 -0
  38. package/types/Options/Classes/Trail.d.ts +10 -0
  39. package/types/Options/Classes/TrailFill.d.ts +7 -0
  40. package/types/Options/Interfaces/ITrail.d.ts +6 -0
  41. package/types/Options/Interfaces/ITrailFill.d.ts +5 -0
  42. package/types/TrailInstance.d.ts +11 -0
  43. package/types/TrailPlugin.d.ts +11 -0
  44. package/types/index.d.ts +2 -0
  45. package/types/types.d.ts +12 -0
  46. package/umd/Options/Classes/Trail.js +37 -0
  47. package/umd/Options/Classes/TrailFill.js +28 -0
  48. package/umd/Options/Interfaces/ITrail.js +12 -0
  49. package/umd/Options/Interfaces/ITrailFill.js +12 -0
  50. package/umd/TrailInstance.js +86 -0
  51. package/umd/TrailPlugin.js +38 -0
  52. package/umd/index.js +54 -0
  53. package/umd/types.js +12 -0
package/877.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 877.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_trail=this.webpackChunk_tsparticles_plugin_trail||[]).push([[877],{877(i,t,e){e.d(t,{TrailPlugin:()=>o});var r=e(303);class l{load(i){(0,r.isNull)(i)||(void 0!==i.color&&(this.color=r.OptionsColor.create(this.color,i.color)),void 0!==i.image&&(this.image=i.image))}}class a{constructor(){this.enable=!1,this.length=10,this.fill=new l}load(i){(0,r.isNull)(i)||(void 0!==i.enable&&(this.enable=i.enable),void 0!==i.fill&&this.fill.load(i.fill),void 0!==i.length&&(this.length=i.length))}}class n{constructor(i,t){this._initTrail=async()=>{const i=this._container.actualOptions.trail;if(!i?.enable)return;const t=i.fill,e=r.inverseFactorNumerator/i.length;if(t.color){const i=(0,r.rangeColorToRgb)(this._engine,t.color);if(!i)return;this._trailFill={color:{...i},opacity:e}}else await new Promise(((i,l)=>{if(!t.image)return;const a=(0,r.safeDocument)().createElement("img");a.addEventListener("load",(()=>{this._trailFill={image:a,opacity:e},i()})),a.addEventListener("error",(i=>{(0,r.getLogger)().error(i),l(new Error("Error loading image"))})),a.src=t.image}))},this._container=i,this._engine=t}canvasClear(){const i=this._container,t=i.actualOptions.trail,e=this._trailFill;if(!t?.enable||!e||t.length<=0)return!1;let l=!1;const a=i.canvas;return e.color?(a.paintBase((0,r.getStyleFromRgb)(e.color,i.hdr,e.opacity)),l=!0):e.image&&(a.paintImage(e.image,e.opacity),l=!0),l}async init(){try{await this._initTrail()}catch(i){(0,r.getLogger)().error(i)}}}class o{constructor(i){this.id="trail",this._engine=i}getPlugin(i){return Promise.resolve(new n(i,this._engine))}loadOptions(i,t){if(!this.needsPlugin())return;let e=i.trail;e?.load||(i.trail=e=new a),e.load(t?.trail)}needsPlugin(){return!0}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Trail Plugin v4.0.0-alpha.0 by Matteo Bruni */
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,74 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles Trail Plugin
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-trail/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-trail)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/plugin-trail.svg)](https://www.npmjs.com/package/@tsparticles/plugin-trail)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-trail)](https://www.npmjs.com/package/@tsparticles/plugin-trail) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/tsparticles/tsparticles) plugin for handling trail feature.
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.trail.min.js` file will export the function to load the plugin:
18
+
19
+ ```javascript
20
+ loadTrailPlugin;
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 loadTrailPlugin(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-trail
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add @tsparticles/plugin-trail
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 { loadTrailPlugin } = require("@tsparticles/plugin-trail");
59
+
60
+ (async () => {
61
+ await loadTrailPlugin(tsParticles);
62
+ })();
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadTrailPlugin } from "@tsparticles/plugin-trail";
70
+
71
+ (async () => {
72
+ await loadTrailPlugin(tsParticles);
73
+ })();
74
+ ```
@@ -0,0 +1,23 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { TrailFill } from "./TrailFill.js";
3
+ export class Trail {
4
+ constructor() {
5
+ this.enable = false;
6
+ this.length = 10;
7
+ this.fill = new TrailFill();
8
+ }
9
+ load(data) {
10
+ if (isNull(data)) {
11
+ return;
12
+ }
13
+ if (data.enable !== undefined) {
14
+ this.enable = data.enable;
15
+ }
16
+ if (data.fill !== undefined) {
17
+ this.fill.load(data.fill);
18
+ }
19
+ if (data.length !== undefined) {
20
+ this.length = data.length;
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,14 @@
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
+ export class TrailFill {
3
+ load(data) {
4
+ if (isNull(data)) {
5
+ return;
6
+ }
7
+ if (data.color !== undefined) {
8
+ this.color = OptionsColor.create(this.color, data.color);
9
+ }
10
+ if (data.image !== undefined) {
11
+ this.image = data.image;
12
+ }
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import { getLogger, getStyleFromRgb, inverseFactorNumerator, rangeColorToRgb, safeDocument, } from "@tsparticles/engine";
2
+ const minimumLength = 0;
3
+ export class TrailInstance {
4
+ constructor(container, engine) {
5
+ this._initTrail = async () => {
6
+ const options = this._container.actualOptions, trail = options.trail;
7
+ if (!trail?.enable) {
8
+ return;
9
+ }
10
+ const trailFill = trail.fill, opacity = inverseFactorNumerator / trail.length;
11
+ if (trailFill.color) {
12
+ const fillColor = rangeColorToRgb(this._engine, trailFill.color);
13
+ if (!fillColor) {
14
+ return;
15
+ }
16
+ this._trailFill = {
17
+ color: {
18
+ ...fillColor,
19
+ },
20
+ opacity,
21
+ };
22
+ }
23
+ else {
24
+ await new Promise((resolve, reject) => {
25
+ if (!trailFill.image) {
26
+ return;
27
+ }
28
+ const img = safeDocument().createElement("img");
29
+ img.addEventListener("load", () => {
30
+ this._trailFill = {
31
+ image: img,
32
+ opacity,
33
+ };
34
+ resolve();
35
+ });
36
+ img.addEventListener("error", evt => {
37
+ getLogger().error(evt);
38
+ reject(new Error("Error loading image"));
39
+ });
40
+ img.src = trailFill.image;
41
+ });
42
+ }
43
+ };
44
+ this._container = container;
45
+ this._engine = engine;
46
+ }
47
+ canvasClear() {
48
+ const container = this._container, trail = container.actualOptions.trail, trailFill = this._trailFill;
49
+ if (!trail?.enable || !trailFill || trail.length <= minimumLength) {
50
+ return false;
51
+ }
52
+ let handled = false;
53
+ const canvas = container.canvas;
54
+ if (trailFill.color) {
55
+ canvas.paintBase(getStyleFromRgb(trailFill.color, container.hdr, trailFill.opacity));
56
+ handled = true;
57
+ }
58
+ else if (trailFill.image) {
59
+ canvas.paintImage(trailFill.image, trailFill.opacity);
60
+ handled = true;
61
+ }
62
+ return handled;
63
+ }
64
+ async init() {
65
+ try {
66
+ await this._initTrail();
67
+ }
68
+ catch (e) {
69
+ getLogger().error(e);
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,24 @@
1
+ import { Trail } from "./Options/Classes/Trail.js";
2
+ import { TrailInstance } from "./TrailInstance.js";
3
+ export class TrailPlugin {
4
+ constructor(engine) {
5
+ this.id = "trail";
6
+ this._engine = engine;
7
+ }
8
+ getPlugin(container) {
9
+ return Promise.resolve(new TrailInstance(container, this._engine));
10
+ }
11
+ loadOptions(options, source) {
12
+ if (!this.needsPlugin()) {
13
+ return;
14
+ }
15
+ let trailOptions = options.trail;
16
+ if (!trailOptions?.load) {
17
+ options.trail = trailOptions = new Trail();
18
+ }
19
+ trailOptions.load(source?.trail);
20
+ }
21
+ needsPlugin() {
22
+ return true;
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ export function loadTrailPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { TrailPlugin } = await import("./TrailPlugin.js");
5
+ e.addPlugin(new TrailPlugin(engine));
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { TrailFill } from "./TrailFill.js";
3
+ export class Trail {
4
+ constructor() {
5
+ this.enable = false;
6
+ this.length = 10;
7
+ this.fill = new TrailFill();
8
+ }
9
+ load(data) {
10
+ if (isNull(data)) {
11
+ return;
12
+ }
13
+ if (data.enable !== undefined) {
14
+ this.enable = data.enable;
15
+ }
16
+ if (data.fill !== undefined) {
17
+ this.fill.load(data.fill);
18
+ }
19
+ if (data.length !== undefined) {
20
+ this.length = data.length;
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,14 @@
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
+ export class TrailFill {
3
+ load(data) {
4
+ if (isNull(data)) {
5
+ return;
6
+ }
7
+ if (data.color !== undefined) {
8
+ this.color = OptionsColor.create(this.color, data.color);
9
+ }
10
+ if (data.image !== undefined) {
11
+ this.image = data.image;
12
+ }
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import { getLogger, getStyleFromRgb, inverseFactorNumerator, rangeColorToRgb, safeDocument, } from "@tsparticles/engine";
2
+ const minimumLength = 0;
3
+ export class TrailInstance {
4
+ constructor(container, engine) {
5
+ this._initTrail = async () => {
6
+ const options = this._container.actualOptions, trail = options.trail;
7
+ if (!trail?.enable) {
8
+ return;
9
+ }
10
+ const trailFill = trail.fill, opacity = inverseFactorNumerator / trail.length;
11
+ if (trailFill.color) {
12
+ const fillColor = rangeColorToRgb(this._engine, trailFill.color);
13
+ if (!fillColor) {
14
+ return;
15
+ }
16
+ this._trailFill = {
17
+ color: {
18
+ ...fillColor,
19
+ },
20
+ opacity,
21
+ };
22
+ }
23
+ else {
24
+ await new Promise((resolve, reject) => {
25
+ if (!trailFill.image) {
26
+ return;
27
+ }
28
+ const img = safeDocument().createElement("img");
29
+ img.addEventListener("load", () => {
30
+ this._trailFill = {
31
+ image: img,
32
+ opacity,
33
+ };
34
+ resolve();
35
+ });
36
+ img.addEventListener("error", evt => {
37
+ getLogger().error(evt);
38
+ reject(new Error("Error loading image"));
39
+ });
40
+ img.src = trailFill.image;
41
+ });
42
+ }
43
+ };
44
+ this._container = container;
45
+ this._engine = engine;
46
+ }
47
+ canvasClear() {
48
+ const container = this._container, trail = container.actualOptions.trail, trailFill = this._trailFill;
49
+ if (!trail?.enable || !trailFill || trail.length <= minimumLength) {
50
+ return false;
51
+ }
52
+ let handled = false;
53
+ const canvas = container.canvas;
54
+ if (trailFill.color) {
55
+ canvas.paintBase(getStyleFromRgb(trailFill.color, container.hdr, trailFill.opacity));
56
+ handled = true;
57
+ }
58
+ else if (trailFill.image) {
59
+ canvas.paintImage(trailFill.image, trailFill.opacity);
60
+ handled = true;
61
+ }
62
+ return handled;
63
+ }
64
+ async init() {
65
+ try {
66
+ await this._initTrail();
67
+ }
68
+ catch (e) {
69
+ getLogger().error(e);
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,24 @@
1
+ import { Trail } from "./Options/Classes/Trail.js";
2
+ import { TrailInstance } from "./TrailInstance.js";
3
+ export class TrailPlugin {
4
+ constructor(engine) {
5
+ this.id = "trail";
6
+ this._engine = engine;
7
+ }
8
+ getPlugin(container) {
9
+ return Promise.resolve(new TrailInstance(container, this._engine));
10
+ }
11
+ loadOptions(options, source) {
12
+ if (!this.needsPlugin()) {
13
+ return;
14
+ }
15
+ let trailOptions = options.trail;
16
+ if (!trailOptions?.load) {
17
+ options.trail = trailOptions = new Trail();
18
+ }
19
+ trailOptions.load(source?.trail);
20
+ }
21
+ needsPlugin() {
22
+ return true;
23
+ }
24
+ }
package/cjs/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export function loadTrailPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { TrailPlugin } = await import("./TrailPlugin.js");
5
+ e.addPlugin(new TrailPlugin(engine));
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
package/cjs/types.js ADDED
@@ -0,0 +1 @@
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_trail"] = this["webpackChunk_tsparticles_plugin_trail"] || []).push([["dist_browser_TrailPlugin_js"],{
19
+
20
+ /***/ "./dist/browser/Options/Classes/Trail.js"
21
+ /*!***********************************************!*\
22
+ !*** ./dist/browser/Options/Classes/Trail.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 */ Trail: () => (/* binding */ Trail)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _TrailFill_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TrailFill.js */ \"./dist/browser/Options/Classes/TrailFill.js\");\n\n\nclass Trail {\n constructor() {\n this.enable = false;\n this.length = 10;\n this.fill = new _TrailFill_js__WEBPACK_IMPORTED_MODULE_1__.TrailFill();\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n if (data.fill !== undefined) {\n this.fill.load(data.fill);\n }\n if (data.length !== undefined) {\n this.length = data.length;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-trail/./dist/browser/Options/Classes/Trail.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Options/Classes/TrailFill.js"
31
+ /*!***************************************************!*\
32
+ !*** ./dist/browser/Options/Classes/TrailFill.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 */ TrailFill: () => (/* binding */ TrailFill)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass TrailFill {\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.color !== undefined) {\n this.color = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.OptionsColor.create(this.color, data.color);\n }\n if (data.image !== undefined) {\n this.image = data.image;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-trail/./dist/browser/Options/Classes/TrailFill.js?\n}");
37
+
38
+ /***/ },
39
+
40
+ /***/ "./dist/browser/TrailInstance.js"
41
+ /*!***************************************!*\
42
+ !*** ./dist/browser/TrailInstance.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 */ TrailInstance: () => (/* binding */ TrailInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst minimumLength = 0;\nclass TrailInstance {\n constructor(container, engine) {\n this._initTrail = async () => {\n const options = this._container.actualOptions,\n trail = options.trail;\n if (!trail?.enable) {\n return;\n }\n const trailFill = trail.fill,\n opacity = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.inverseFactorNumerator / trail.length;\n if (trailFill.color) {\n const fillColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, trailFill.color);\n if (!fillColor) {\n return;\n }\n this._trailFill = {\n color: {\n ...fillColor\n },\n opacity\n };\n } else {\n await new Promise((resolve, reject) => {\n if (!trailFill.image) {\n return;\n }\n const img = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"img\");\n img.addEventListener(\"load\", () => {\n this._trailFill = {\n image: img,\n opacity\n };\n resolve();\n });\n img.addEventListener(\"error\", evt => {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLogger)().error(evt);\n reject(new Error(\"Error loading image\"));\n });\n img.src = trailFill.image;\n });\n }\n };\n this._container = container;\n this._engine = engine;\n }\n canvasClear() {\n const container = this._container,\n trail = container.actualOptions.trail,\n trailFill = this._trailFill;\n if (!trail?.enable || !trailFill || trail.length <= minimumLength) {\n return false;\n }\n let handled = false;\n const canvas = container.canvas;\n if (trailFill.color) {\n canvas.paintBase((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(trailFill.color, container.hdr, trailFill.opacity));\n handled = true;\n } else if (trailFill.image) {\n canvas.paintImage(trailFill.image, trailFill.opacity);\n handled = true;\n }\n return handled;\n }\n async init() {\n try {\n await this._initTrail();\n } catch (e) {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLogger)().error(e);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-trail/./dist/browser/TrailInstance.js?\n}");
47
+
48
+ /***/ },
49
+
50
+ /***/ "./dist/browser/TrailPlugin.js"
51
+ /*!*************************************!*\
52
+ !*** ./dist/browser/TrailPlugin.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 */ TrailPlugin: () => (/* binding */ TrailPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Trail_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Trail.js */ \"./dist/browser/Options/Classes/Trail.js\");\n/* harmony import */ var _TrailInstance_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TrailInstance.js */ \"./dist/browser/TrailInstance.js\");\n\n\nclass TrailPlugin {\n constructor(engine) {\n this.id = \"trail\";\n this._engine = engine;\n }\n getPlugin(container) {\n return Promise.resolve(new _TrailInstance_js__WEBPACK_IMPORTED_MODULE_1__.TrailInstance(container, this._engine));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin()) {\n return;\n }\n let trailOptions = options.trail;\n if (!trailOptions?.load) {\n options.trail = trailOptions = new _Options_Classes_Trail_js__WEBPACK_IMPORTED_MODULE_0__.Trail();\n }\n trailOptions.load(source?.trail);\n }\n needsPlugin() {\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-trail/./dist/browser/TrailPlugin.js?\n}");
57
+
58
+ /***/ }
59
+
60
+ }]);
@@ -0,0 +1,23 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { TrailFill } from "./TrailFill.js";
3
+ export class Trail {
4
+ constructor() {
5
+ this.enable = false;
6
+ this.length = 10;
7
+ this.fill = new TrailFill();
8
+ }
9
+ load(data) {
10
+ if (isNull(data)) {
11
+ return;
12
+ }
13
+ if (data.enable !== undefined) {
14
+ this.enable = data.enable;
15
+ }
16
+ if (data.fill !== undefined) {
17
+ this.fill.load(data.fill);
18
+ }
19
+ if (data.length !== undefined) {
20
+ this.length = data.length;
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,14 @@
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
+ export class TrailFill {
3
+ load(data) {
4
+ if (isNull(data)) {
5
+ return;
6
+ }
7
+ if (data.color !== undefined) {
8
+ this.color = OptionsColor.create(this.color, data.color);
9
+ }
10
+ if (data.image !== undefined) {
11
+ this.image = data.image;
12
+ }
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import { getLogger, getStyleFromRgb, inverseFactorNumerator, rangeColorToRgb, safeDocument, } from "@tsparticles/engine";
2
+ const minimumLength = 0;
3
+ export class TrailInstance {
4
+ constructor(container, engine) {
5
+ this._initTrail = async () => {
6
+ const options = this._container.actualOptions, trail = options.trail;
7
+ if (!trail?.enable) {
8
+ return;
9
+ }
10
+ const trailFill = trail.fill, opacity = inverseFactorNumerator / trail.length;
11
+ if (trailFill.color) {
12
+ const fillColor = rangeColorToRgb(this._engine, trailFill.color);
13
+ if (!fillColor) {
14
+ return;
15
+ }
16
+ this._trailFill = {
17
+ color: {
18
+ ...fillColor,
19
+ },
20
+ opacity,
21
+ };
22
+ }
23
+ else {
24
+ await new Promise((resolve, reject) => {
25
+ if (!trailFill.image) {
26
+ return;
27
+ }
28
+ const img = safeDocument().createElement("img");
29
+ img.addEventListener("load", () => {
30
+ this._trailFill = {
31
+ image: img,
32
+ opacity,
33
+ };
34
+ resolve();
35
+ });
36
+ img.addEventListener("error", evt => {
37
+ getLogger().error(evt);
38
+ reject(new Error("Error loading image"));
39
+ });
40
+ img.src = trailFill.image;
41
+ });
42
+ }
43
+ };
44
+ this._container = container;
45
+ this._engine = engine;
46
+ }
47
+ canvasClear() {
48
+ const container = this._container, trail = container.actualOptions.trail, trailFill = this._trailFill;
49
+ if (!trail?.enable || !trailFill || trail.length <= minimumLength) {
50
+ return false;
51
+ }
52
+ let handled = false;
53
+ const canvas = container.canvas;
54
+ if (trailFill.color) {
55
+ canvas.paintBase(getStyleFromRgb(trailFill.color, container.hdr, trailFill.opacity));
56
+ handled = true;
57
+ }
58
+ else if (trailFill.image) {
59
+ canvas.paintImage(trailFill.image, trailFill.opacity);
60
+ handled = true;
61
+ }
62
+ return handled;
63
+ }
64
+ async init() {
65
+ try {
66
+ await this._initTrail();
67
+ }
68
+ catch (e) {
69
+ getLogger().error(e);
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,24 @@
1
+ import { Trail } from "./Options/Classes/Trail.js";
2
+ import { TrailInstance } from "./TrailInstance.js";
3
+ export class TrailPlugin {
4
+ constructor(engine) {
5
+ this.id = "trail";
6
+ this._engine = engine;
7
+ }
8
+ getPlugin(container) {
9
+ return Promise.resolve(new TrailInstance(container, this._engine));
10
+ }
11
+ loadOptions(options, source) {
12
+ if (!this.needsPlugin()) {
13
+ return;
14
+ }
15
+ let trailOptions = options.trail;
16
+ if (!trailOptions?.load) {
17
+ options.trail = trailOptions = new Trail();
18
+ }
19
+ trailOptions.load(source?.trail);
20
+ }
21
+ needsPlugin() {
22
+ return true;
23
+ }
24
+ }
package/esm/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export function loadTrailPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { TrailPlugin } = await import("./TrailPlugin.js");
5
+ e.addPlugin(new TrailPlugin(engine));
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};