@tsparticles/path-curves 3.0.0-alpha.1 → 3.0.0-beta.1

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.
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.1
7
+ * v3.0.0-beta.1
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,8 +91,8 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "curvesPathName": () => (/* binding */ curvesPathName),
95
- "loadCurvesPath": () => (/* binding */ loadCurvesPath)
94
+ curvesPathName: () => (/* binding */ curvesPathName),
95
+ loadCurvesPath: () => (/* binding */ loadCurvesPath)
96
96
  });
97
97
 
98
98
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -105,7 +105,7 @@ function CurvesPathGen(rndFunc, period, nbHarmonics, attenHarmonics, lowValue =
105
105
  amplitudes = [],
106
106
  increments = [],
107
107
  phases = [],
108
- randomFunc = rndFunc !== null && rndFunc !== void 0 ? rndFunc : engine_root_window_.getRandom;
108
+ randomFunc = rndFunc ?? engine_root_window_.getRandom;
109
109
  let globAmplitude = 0;
110
110
  if (nbHarmonics < 1) nbHarmonics = 1;
111
111
  for (let kh = 1; kh <= nbHarmonics; ++kh) {
@@ -137,7 +137,6 @@ function CurvesPathGen(rndFunc, period, nbHarmonics, attenHarmonics, lowValue =
137
137
  ;// CONCATENATED MODULE: ./dist/browser/CurvesPathGenerator.js
138
138
 
139
139
 
140
-
141
140
  class CurvesPathGenerator {
142
141
  constructor() {
143
142
  this.options = {
@@ -150,11 +149,11 @@ class CurvesPathGenerator {
150
149
  };
151
150
  }
152
151
  generate(p) {
153
- if (p.pathGen === undefined) {
152
+ if (!p.pathGen) {
154
153
  const options = this.options;
155
154
  p.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
156
155
  }
157
- if (p.curveVelocity === undefined) {
156
+ if (!p.curveVelocity) {
158
157
  p.curveVelocity = engine_root_window_.Vector.origin;
159
158
  p.curveVelocity.length = (0,engine_root_window_.getRandom)() * 0.6 + 0.8;
160
159
  p.curveVelocity.angle = (0,engine_root_window_.getRandom)() * Math.PI * 2;
@@ -167,18 +166,20 @@ class CurvesPathGenerator {
167
166
  return p.curveVelocity;
168
167
  }
169
168
  init(container) {
170
- var _a, _b, _c, _d, _e;
171
- const sourceOptions = container.actualOptions.particles.move.path.options;
172
- if (typeof sourceOptions.rndFunc === "function") {
173
- this.options.rndFunc = sourceOptions.rndFunc;
174
- } else if (typeof sourceOptions.rndFunc === "string") {
175
- this.options.rndFunc = window[sourceOptions.rndFunc] || this.options.rndFunc;
169
+ const sourceOptions = container.actualOptions.particles.move.path.options,
170
+ {
171
+ options
172
+ } = this;
173
+ if ((0,engine_root_window_.isFunction)(sourceOptions.rndFunc)) {
174
+ options.rndFunc = sourceOptions.rndFunc;
175
+ } else if ((0,engine_root_window_.isString)(sourceOptions.rndFunc)) {
176
+ options.rndFunc = window[sourceOptions.rndFunc] || this.options.rndFunc;
176
177
  }
177
- this.options.period = (_a = sourceOptions.period) !== null && _a !== void 0 ? _a : this.options.period;
178
- this.options.nbHarmonics = (_b = sourceOptions.nbHarmonics) !== null && _b !== void 0 ? _b : this.options.nbHarmonics;
179
- this.options.attenHarmonics = (_c = sourceOptions.attenHarmonics) !== null && _c !== void 0 ? _c : this.options.attenHarmonics;
180
- this.options.lowValue = (_d = sourceOptions.lowValue) !== null && _d !== void 0 ? _d : this.options.lowValue;
181
- this.options.highValue = (_e = sourceOptions.highValue) !== null && _e !== void 0 ? _e : this.options.highValue;
178
+ options.period = sourceOptions.period ?? options.period;
179
+ options.nbHarmonics = sourceOptions.nbHarmonics ?? options.nbHarmonics;
180
+ options.attenHarmonics = sourceOptions.attenHarmonics ?? options.attenHarmonics;
181
+ options.lowValue = sourceOptions.lowValue ?? options.lowValue;
182
+ options.highValue = sourceOptions.highValue ?? options.highValue;
182
183
  }
183
184
  reset(particle) {
184
185
  delete particle.pathGen;
@@ -189,8 +190,8 @@ class CurvesPathGenerator {
189
190
  ;// CONCATENATED MODULE: ./dist/browser/index.js
190
191
 
191
192
  const curvesPathName = "curvesPathGenerator";
192
- function loadCurvesPath(engine) {
193
- engine.addPathGenerator(curvesPathName, new CurvesPathGenerator());
193
+ async function loadCurvesPath(engine, refresh = true) {
194
+ await engine.addPathGenerator(curvesPathName, new CurvesPathGenerator(), refresh);
194
195
  }
195
196
  })();
196
197
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.path.curves.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var o="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},o={};function n(e){var i=o[e];if(void 0!==i)return i.exports;var r=o[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.r(i),n.d(i,{curvesPathName:()=>o,loadCurvesPath:()=>r});var e=n(533);class t{constructor(){this.options={rndFunc:null,period:100,nbHarmonics:2,attenHarmonics:.8,lowValue:-.03,highValue:.03}}generate(t){if(void 0===t.pathGen){const o=this.options;t.pathGen=function(t,o,n,i,r=0,s=1){const a=[],l=[],c=[],u=[],p=[],d=null!=t?t:e.getRandom;let h=0;n<1&&(n=1);for(let e=1;e<=n;++e)a[e]=d(),l[e]=d(),c[e]=1===e?1:c[e-1]*i,h+=c[e],u[e]=e/o,p[e]=d();return c.forEach(((e,t)=>c[t]=e/h*(s-r))),()=>{let e,t,o=0;for(let i=n;i>=1;--i)e=p[i]+=u[i],p[i]>=1&&(e=p[i]-=1,a[i]=l[i],l[i]=d()),t=e**2*(3-2*e),o+=(a[i]*(1-t)+l[i]*t)*c[i];return o+r}}(o.rndFunc,o.period,o.nbHarmonics,o.attenHarmonics,o.lowValue,o.highValue)}return void 0===t.curveVelocity?(t.curveVelocity=e.Vector.origin,t.curveVelocity.length=.6*(0,e.getRandom)()+.8,t.curveVelocity.angle=(0,e.getRandom)()*Math.PI*2):(t.curveVelocity.length+=.01,t.curveVelocity.angle=(t.curveVelocity.angle+t.pathGen())%(2*Math.PI)),t.velocity.x=0,t.velocity.y=0,t.curveVelocity}init(e){var t,o,n,i,r;const s=e.actualOptions.particles.move.path.options;"function"==typeof s.rndFunc?this.options.rndFunc=s.rndFunc:"string"==typeof s.rndFunc&&(this.options.rndFunc=window[s.rndFunc]||this.options.rndFunc),this.options.period=null!==(t=s.period)&&void 0!==t?t:this.options.period,this.options.nbHarmonics=null!==(o=s.nbHarmonics)&&void 0!==o?o:this.options.nbHarmonics,this.options.attenHarmonics=null!==(n=s.attenHarmonics)&&void 0!==n?n:this.options.attenHarmonics,this.options.lowValue=null!==(i=s.lowValue)&&void 0!==i?i:this.options.lowValue,this.options.highValue=null!==(r=s.highValue)&&void 0!==r?r:this.options.highValue}reset(e){delete e.pathGen,delete e.curveVelocity}update(){}}const o="curvesPathGenerator";function r(e){e.addPathGenerator(o,new t)}})(),i})()));
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var n="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{curvesPathName:()=>n,loadCurvesPath:()=>i});var e=o(533);class t{constructor(){this.options={rndFunc:null,period:100,nbHarmonics:2,attenHarmonics:.8,lowValue:-.03,highValue:.03}}generate(t){if(!t.pathGen){const n=this.options;t.pathGen=function(t,n,o,r,i=0,a=1){const c=[],l=[],s=[],u=[],p=[],d=t??e.getRandom;let h=0;o<1&&(o=1);for(let e=1;e<=o;++e)c[e]=d(),l[e]=d(),s[e]=1===e?1:s[e-1]*r,h+=s[e],u[e]=e/n,p[e]=d();return s.forEach(((e,t)=>s[t]=e/h*(a-i))),()=>{let e,t,n=0;for(let r=o;r>=1;--r)e=p[r]+=u[r],p[r]>=1&&(e=p[r]-=1,c[r]=l[r],l[r]=d()),t=e**2*(3-2*e),n+=(c[r]*(1-t)+l[r]*t)*s[r];return n+i}}(n.rndFunc,n.period,n.nbHarmonics,n.attenHarmonics,n.lowValue,n.highValue)}return t.curveVelocity?(t.curveVelocity.length+=.01,t.curveVelocity.angle=(t.curveVelocity.angle+t.pathGen())%(2*Math.PI)):(t.curveVelocity=e.Vector.origin,t.curveVelocity.length=.6*(0,e.getRandom)()+.8,t.curveVelocity.angle=(0,e.getRandom)()*Math.PI*2),t.velocity.x=0,t.velocity.y=0,t.curveVelocity}init(t){const n=t.actualOptions.particles.move.path.options,{options:o}=this;(0,e.isFunction)(n.rndFunc)?o.rndFunc=n.rndFunc:(0,e.isString)(n.rndFunc)&&(o.rndFunc=window[n.rndFunc]||this.options.rndFunc),o.period=n.period??o.period,o.nbHarmonics=n.nbHarmonics??o.nbHarmonics,o.attenHarmonics=n.attenHarmonics??o.attenHarmonics,o.lowValue=n.lowValue??o.lowValue,o.highValue=n.highValue??o.highValue}reset(e){delete e.pathGen,delete e.curveVelocity}update(){}}const n="curvesPathGenerator";async function i(e,o=!0){await e.addPathGenerator(n,new t,o)}})(),r})()));
@@ -1,8 +1 @@
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-alpha.1
8
- */
1
+ /*! tsParticles Curves Path v3.0.0-beta.1 by Matteo Bruni */
@@ -1,7 +1,6 @@
1
- import type { Container, IMovePathGenerator } from "@tsparticles/engine";
2
- import type { CurvesPathParticle } from "./CurvesPathParticle";
3
- import type { ICurvesOptions } from "./ICurvesOptions";
4
- import { Vector } from "@tsparticles/engine";
1
+ import { type Container, type IMovePathGenerator, Vector } from "@tsparticles/engine";
2
+ import type { CurvesPathParticle } from "./CurvesPathParticle.js";
3
+ import type { ICurvesOptions } from "./ICurvesOptions.js";
5
4
  declare global {
6
5
  interface Window {
7
6
  [key: string]: unknown;
package/types/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
2
  export declare const curvesPathName = "curvesPathGenerator";
3
- export declare function loadCurvesPath(engine: Engine): void;
3
+ export declare function loadCurvesPath(engine: Engine, refresh?: boolean): Promise<void>;
package/umd/Curves.js CHANGED
@@ -12,7 +12,7 @@
12
12
  exports.CurvesPathGen = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  function CurvesPathGen(rndFunc, period, nbHarmonics, attenHarmonics, lowValue = 0, highValue = 1) {
15
- const arP0 = [], arP1 = [], amplitudes = [], increments = [], phases = [], randomFunc = rndFunc !== null && rndFunc !== void 0 ? rndFunc : engine_1.getRandom;
15
+ const arP0 = [], arP1 = [], amplitudes = [], increments = [], phases = [], randomFunc = rndFunc ?? engine_1.getRandom;
16
16
  let globAmplitude = 0;
17
17
  if (nbHarmonics < 1)
18
18
  nbHarmonics = 1;
@@ -4,15 +4,14 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./Curves", "@tsparticles/engine", "@tsparticles/engine"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Curves.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CurvesPathGenerator = void 0;
13
- const Curves_1 = require("./Curves");
14
13
  const engine_1 = require("@tsparticles/engine");
15
- const engine_2 = require("@tsparticles/engine");
14
+ const Curves_js_1 = require("./Curves.js");
16
15
  class CurvesPathGenerator {
17
16
  constructor() {
18
17
  this.options = {
@@ -25,14 +24,14 @@
25
24
  };
26
25
  }
27
26
  generate(p) {
28
- if (p.pathGen === undefined) {
27
+ if (!p.pathGen) {
29
28
  const options = this.options;
30
- p.pathGen = (0, Curves_1.CurvesPathGen)(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
29
+ p.pathGen = (0, Curves_js_1.CurvesPathGen)(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
31
30
  }
32
- if (p.curveVelocity === undefined) {
31
+ if (!p.curveVelocity) {
33
32
  p.curveVelocity = engine_1.Vector.origin;
34
- p.curveVelocity.length = (0, engine_2.getRandom)() * 0.6 + 0.8;
35
- p.curveVelocity.angle = (0, engine_2.getRandom)() * Math.PI * 2;
33
+ p.curveVelocity.length = (0, engine_1.getRandom)() * 0.6 + 0.8;
34
+ p.curveVelocity.angle = (0, engine_1.getRandom)() * Math.PI * 2;
36
35
  }
37
36
  else {
38
37
  p.curveVelocity.length += 0.01;
@@ -43,20 +42,19 @@
43
42
  return p.curveVelocity;
44
43
  }
45
44
  init(container) {
46
- var _a, _b, _c, _d, _e;
47
- const sourceOptions = container.actualOptions.particles.move.path.options;
48
- if (typeof sourceOptions.rndFunc === "function") {
49
- this.options.rndFunc = sourceOptions.rndFunc;
45
+ const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
46
+ if ((0, engine_1.isFunction)(sourceOptions.rndFunc)) {
47
+ options.rndFunc = sourceOptions.rndFunc;
50
48
  }
51
- else if (typeof sourceOptions.rndFunc === "string") {
52
- this.options.rndFunc =
49
+ else if ((0, engine_1.isString)(sourceOptions.rndFunc)) {
50
+ options.rndFunc =
53
51
  window[sourceOptions.rndFunc] || this.options.rndFunc;
54
52
  }
55
- this.options.period = (_a = sourceOptions.period) !== null && _a !== void 0 ? _a : this.options.period;
56
- this.options.nbHarmonics = (_b = sourceOptions.nbHarmonics) !== null && _b !== void 0 ? _b : this.options.nbHarmonics;
57
- this.options.attenHarmonics = (_c = sourceOptions.attenHarmonics) !== null && _c !== void 0 ? _c : this.options.attenHarmonics;
58
- this.options.lowValue = (_d = sourceOptions.lowValue) !== null && _d !== void 0 ? _d : this.options.lowValue;
59
- this.options.highValue = (_e = sourceOptions.highValue) !== null && _e !== void 0 ? _e : this.options.highValue;
53
+ options.period = sourceOptions.period ?? options.period;
54
+ options.nbHarmonics = sourceOptions.nbHarmonics ?? options.nbHarmonics;
55
+ options.attenHarmonics = sourceOptions.attenHarmonics ?? options.attenHarmonics;
56
+ options.lowValue = sourceOptions.lowValue ?? options.lowValue;
57
+ options.highValue = sourceOptions.highValue ?? options.highValue;
60
58
  }
61
59
  reset(particle) {
62
60
  delete particle.pathGen;
package/umd/index.js CHANGED
@@ -4,16 +4,16 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./CurvesPathGenerator"], factory);
7
+ define(["require", "exports", "./CurvesPathGenerator.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadCurvesPath = exports.curvesPathName = void 0;
13
- const CurvesPathGenerator_1 = require("./CurvesPathGenerator");
13
+ const CurvesPathGenerator_js_1 = require("./CurvesPathGenerator.js");
14
14
  exports.curvesPathName = "curvesPathGenerator";
15
- function loadCurvesPath(engine) {
16
- engine.addPathGenerator(exports.curvesPathName, new CurvesPathGenerator_1.CurvesPathGenerator());
15
+ async function loadCurvesPath(engine, refresh = true) {
16
+ await engine.addPathGenerator(exports.curvesPathName, new CurvesPathGenerator_js_1.CurvesPathGenerator(), refresh);
17
17
  }
18
18
  exports.loadCurvesPath = loadCurvesPath;
19
19
  });