@tsparticles/effect-trail 3.0.0-beta.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,167 @@
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
+ * v3.0.0-beta.4
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
55
+ /******/
56
+ /************************************************************************/
57
+ /******/ /* webpack/runtime/define property getters */
58
+ /******/ (() => {
59
+ /******/ // define getter functions for harmony exports
60
+ /******/ __webpack_require__.d = (exports, definition) => {
61
+ /******/ for(var key in definition) {
62
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
63
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
64
+ /******/ }
65
+ /******/ }
66
+ /******/ };
67
+ /******/ })();
68
+ /******/
69
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
+ /******/ (() => {
71
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
+ /******/ })();
73
+ /******/
74
+ /******/ /* webpack/runtime/make namespace object */
75
+ /******/ (() => {
76
+ /******/ // define __esModule on exports
77
+ /******/ __webpack_require__.r = (exports) => {
78
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
79
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
80
+ /******/ }
81
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
82
+ /******/ };
83
+ /******/ })();
84
+ /******/
85
+ /************************************************************************/
86
+ var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
89
+ // ESM COMPAT FLAG
90
+ __webpack_require__.r(__webpack_exports__);
91
+
92
+ // EXPORTS
93
+ __webpack_require__.d(__webpack_exports__, {
94
+ loadTrailEffect: () => (/* binding */ loadTrailEffect)
95
+ });
96
+
97
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
98
+ var engine_root_window_ = __webpack_require__(533);
99
+ ;// CONCATENATED MODULE: ./dist/browser/TrailDrawer.js
100
+
101
+ class TrailDrawer {
102
+ draw(data) {
103
+ const {
104
+ context,
105
+ radius,
106
+ particle
107
+ } = data,
108
+ pxRatio = particle.container.retina.pixelRatio,
109
+ currentPos = particle.getPosition();
110
+ if (!particle.trail || !particle.trailLength) {
111
+ return;
112
+ }
113
+ const pathLength = particle.trailLength;
114
+ particle.trail.push({
115
+ color: context.fillStyle ?? context.strokeStyle,
116
+ position: {
117
+ x: currentPos.x,
118
+ y: currentPos.y
119
+ }
120
+ });
121
+ if (particle.trail.length < 2) {
122
+ return;
123
+ }
124
+ if (particle.trail.length > pathLength) {
125
+ particle.trail.shift();
126
+ }
127
+ const trailLength = Math.min(particle.trail.length, pathLength),
128
+ offsetPos = {
129
+ x: currentPos.x,
130
+ y: currentPos.y
131
+ };
132
+ let lastPos = particle.trail[trailLength - 1].position;
133
+ for (let i = trailLength; i > 0; i--) {
134
+ const step = particle.trail[i - 1],
135
+ position = step.position;
136
+ if ((0,engine_root_window_.getDistance)(lastPos, position) > radius * 2) {
137
+ continue;
138
+ }
139
+ context.beginPath();
140
+ context.moveTo(lastPos.x - offsetPos.x, lastPos.y - offsetPos.y);
141
+ context.lineTo(position.x - offsetPos.x, position.y - offsetPos.y);
142
+ const width = Math.max(i / trailLength * radius * 2, pxRatio, particle.trailMinWidth ?? -1);
143
+ context.lineWidth = particle.trailMaxWidth ? Math.min(width, particle.trailMaxWidth) : width;
144
+ context.strokeStyle = step.color;
145
+ context.stroke();
146
+ lastPos = position;
147
+ }
148
+ }
149
+ particleInit(container, particle) {
150
+ particle.trail = [];
151
+ const effectData = particle.effectData;
152
+ particle.trailLength = (0,engine_root_window_.getRangeValue)(effectData?.length ?? 10) * container.retina.pixelRatio;
153
+ particle.trailMaxWidth = effectData?.maxWidth ? (0,engine_root_window_.getRangeValue)(effectData.maxWidth) * container.retina.pixelRatio : undefined;
154
+ particle.trailMinWidth = effectData?.minWidth ? (0,engine_root_window_.getRangeValue)(effectData.minWidth) * container.retina.pixelRatio : undefined;
155
+ }
156
+ }
157
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
158
+
159
+ async function loadTrailEffect(engine, refresh = true) {
160
+ await engine.addEffect("trail", new TrailDrawer(), refresh);
161
+ }
162
+ })();
163
+
164
+ /******/ return __webpack_exports__;
165
+ /******/ })()
166
+ ;
167
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.effect.trail.min.js.LICENSE.txt */
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var r in i)("object"==typeof exports?exports:t)[r]=i[r]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function r(t){var o=i[t];if(void 0!==o)return o.exports;var a=i[t]={exports:{}};return e[t](a,a.exports,r),a.exports}r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{r.r(o),r.d(o,{loadTrailEffect:()=>i});var t=r(533);class e{draw(e){const{context:i,radius:r,particle:o}=e,a=o.container.retina.pixelRatio,n=o.getPosition();if(!o.trail||!o.trailLength)return;const l=o.trailLength;if(o.trail.push({color:i.fillStyle??i.strokeStyle,position:{x:n.x,y:n.y}}),o.trail.length<2)return;o.trail.length>l&&o.trail.shift();const s=Math.min(o.trail.length,l),c=n.x,p=n.y;let d=o.trail[s-1].position;for(let e=s;e>0;e--){const n=o.trail[e-1],l=n.position;if((0,t.getDistance)(d,l)>2*r)continue;i.beginPath(),i.moveTo(d.x-c,d.y-p),i.lineTo(l.x-c,l.y-p);const f=Math.max(e/s*r*2,a,o.trailMinWidth??-1);i.lineWidth=o.trailMaxWidth?Math.min(f,o.trailMaxWidth):f,i.strokeStyle=n.color,i.stroke(),d=l}}particleInit(e,i){i.trail=[];const r=i.effectData;i.trailLength=(0,t.getRangeValue)(r?.length??10)*e.retina.pixelRatio,i.trailMaxWidth=r?.maxWidth?(0,t.getRangeValue)(r.maxWidth)*e.retina.pixelRatio:void 0,i.trailMinWidth=r?.minWidth?(0,t.getRangeValue)(r.minWidth)*e.retina.pixelRatio:void 0}}async function i(t,i=!0){await t.addEffect("trail",new e,i)}})(),o})()));
@@ -0,0 +1 @@
1
+ /*! tsParticles Trail Shape v3.0.0-beta.4 by Matteo Bruni */
@@ -0,0 +1,16 @@
1
+ import { type Container, type ICoordinates, type IEffectDrawer, type IShapeDrawData, type Particle } from "@tsparticles/engine";
2
+ type TrailStep = {
3
+ color: string | CanvasGradient | CanvasPattern;
4
+ position: ICoordinates;
5
+ };
6
+ type TrailParticle = Particle & {
7
+ trail?: TrailStep[];
8
+ trailLength?: number;
9
+ trailMaxWidth?: number;
10
+ trailMinWidth?: number;
11
+ };
12
+ export declare class TrailDrawer implements IEffectDrawer<TrailParticle> {
13
+ draw(data: IShapeDrawData<TrailParticle>): void;
14
+ particleInit(container: Container, particle: TrailParticle): void;
15
+ }
16
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadTrailEffect(engine: Engine, refresh?: boolean): Promise<void>;
@@ -0,0 +1,67 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TrailDrawer = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class TrailDrawer {
15
+ draw(data) {
16
+ const { context, radius, particle } = data, pxRatio = particle.container.retina.pixelRatio, currentPos = particle.getPosition();
17
+ if (!particle.trail || !particle.trailLength) {
18
+ return;
19
+ }
20
+ const pathLength = particle.trailLength;
21
+ particle.trail.push({
22
+ color: context.fillStyle ?? context.strokeStyle,
23
+ position: {
24
+ x: currentPos.x,
25
+ y: currentPos.y,
26
+ },
27
+ });
28
+ if (particle.trail.length < 2) {
29
+ return;
30
+ }
31
+ if (particle.trail.length > pathLength) {
32
+ particle.trail.shift();
33
+ }
34
+ const trailLength = Math.min(particle.trail.length, pathLength), offsetPos = {
35
+ x: currentPos.x,
36
+ y: currentPos.y,
37
+ };
38
+ let lastPos = particle.trail[trailLength - 1].position;
39
+ for (let i = trailLength; i > 0; i--) {
40
+ const step = particle.trail[i - 1], position = step.position;
41
+ if ((0, engine_1.getDistance)(lastPos, position) > radius * 2) {
42
+ continue;
43
+ }
44
+ context.beginPath();
45
+ context.moveTo(lastPos.x - offsetPos.x, lastPos.y - offsetPos.y);
46
+ context.lineTo(position.x - offsetPos.x, position.y - offsetPos.y);
47
+ const width = Math.max((i / trailLength) * radius * 2, pxRatio, particle.trailMinWidth ?? -1);
48
+ context.lineWidth = particle.trailMaxWidth ? Math.min(width, particle.trailMaxWidth) : width;
49
+ context.strokeStyle = step.color;
50
+ context.stroke();
51
+ lastPos = position;
52
+ }
53
+ }
54
+ particleInit(container, particle) {
55
+ particle.trail = [];
56
+ const effectData = particle.effectData;
57
+ particle.trailLength = (0, engine_1.getRangeValue)(effectData?.length ?? 10) * container.retina.pixelRatio;
58
+ particle.trailMaxWidth = effectData?.maxWidth
59
+ ? (0, engine_1.getRangeValue)(effectData.maxWidth) * container.retina.pixelRatio
60
+ : undefined;
61
+ particle.trailMinWidth = effectData?.minWidth
62
+ ? (0, engine_1.getRangeValue)(effectData.minWidth) * container.retina.pixelRatio
63
+ : undefined;
64
+ }
65
+ }
66
+ exports.TrailDrawer = TrailDrawer;
67
+ });
package/umd/index.js ADDED
@@ -0,0 +1,18 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./TrailDrawer.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadTrailEffect = void 0;
13
+ const TrailDrawer_js_1 = require("./TrailDrawer.js");
14
+ async function loadTrailEffect(engine, refresh = true) {
15
+ await engine.addEffect("trail", new TrailDrawer_js_1.TrailDrawer(), refresh);
16
+ }
17
+ exports.loadTrailEffect = loadTrailEffect;
18
+ });