@tsparticles/updater-gradient 3.0.3 → 3.2.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.
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.gradient.min.js.LICENSE.txt */
2
- !function(e,a){if("object"==typeof exports&&"object"==typeof module)module.exports=a(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],a);else{var t="object"==typeof exports?a(require("@tsparticles/engine")):a(e.window);for(var i in t)("object"==typeof exports?exports:e)[i]=t[i]}}(this,(e=>(()=>{"use strict";var a={533:a=>{a.exports=e}},t={};function i(e){var n=t[e];if(void 0!==n)return n.exports;var o=t[e]={exports:{}};return a[e](o,o.exports,i),o.exports}i.d=(e,a)=>{for(var t in a)i.o(a,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:a[t]})},i.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{i.r(n),i.d(n,{loadGradientUpdater:()=>y});var e=i(533);class a{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1,this.startValue="random"}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.sync&&(this.sync=a.sync),void 0!==a.startValue&&(this.startValue=a.startValue),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.delay&&(this.delay=(0,e.setRangeValue)(a.delay)))}}class t{constructor(){this.value=0,this.animation=new a}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)))}}class o{constructor(){this.stop=0,this.value=new e.AnimatableColor}load(a){a&&(void 0!==a.stop&&(this.stop=a.stop),this.value=e.AnimatableColor.create(this.value,a.value),void 0!==a.opacity&&(this.opacity=new t,(0,e.isNumber)(a.opacity)?this.opacity.value=a.opacity:this.opacity.load(a.opacity)))}}class s{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.delay&&(this.delay=(0,e.setRangeValue)(a.delay)),void 0!==a.sync&&(this.sync=a.sync))}}class l{constructor(){this.value=0,this.animation=new s,this.direction="clockwise"}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)),void 0!==a.direction&&(this.direction=a.direction))}}class c{constructor(){this.angle=new l,this.colors=[],this.type="random"}load(e){e&&(this.angle.load(e.angle),void 0!==e.colors&&(this.colors=e.colors.map((e=>{const a=new o;return a.load(e),a}))),void 0!==e.type&&(this.type=e.type))}}function r(e,a){if(!a.enable)return;const t=a.decay??1;switch(a.status){case"increasing":a.value>=a.max?a.status="decreasing":a.value+=(a.velocity??0)*e.factor;break;case"decreasing":a.value<=a.min?a.status="increasing":a.value-=(a.velocity??0)*e.factor}a.velocity&&1!==t&&(a.velocity*=t)}function u(e,a,t,i){if(!a||!a.enable)return;if(a.time||(a.time=0),(a.delayTime??0)>0&&a.time<(a.delayTime??0)&&(a.time+=e.value),(a.delayTime??0)>0&&a.time<(a.delayTime??0))return;const n=(a.velocity??0)*e.factor,o=a.decay??1;i&&"increasing"!==a.status?(a.value-=n,a.value<0&&(a.status="increasing",a.value+=a.value)):(a.value+=n,i&&a.value>t&&(a.status="decreasing",a.value-=a.value%t)),a.value>t&&(a.value%=t),a.velocity&&1!==o&&(a.velocity*=o)}function d(e,a){const{gradient:t}=e;if(t){!function(e,a){const t=(a.velocity??0)*e.factor,i=2*Math.PI,n=a.decay??1;a.enable&&("increasing"===a.status?(a.value+=t,a.value>i&&(a.value-=i)):(a.value-=t,a.value<0&&(a.value+=i)),a.velocity&&1!==n&&(a.velocity*=n))}(a,t.angle);for(const i of t.colors)void 0!==e.color?.h&&u(a,i.value.h,360,!1),void 0!==e.color?.s&&u(a,i.value.s,100,!0),void 0!==e.color?.l&&u(a,i.value.l,100,!0),i.opacity&&r(a,i.opacity)}}class v{getColorStyles(a,t,i,n){const o=a.gradient;if(!o)return{};const s=o.angle.value,l="radial"===o.type?t.createRadialGradient(0,0,0,0,0,i):t.createLinearGradient(Math.cos(s)*-i,Math.sin(s)*-i,Math.cos(s)*i,Math.sin(s)*i);for(const{stop:a,value:t,opacity:i}of o.colors)l.addColorStop(a,(0,e.getStyleFromHsl)({h:t.h.value,s:t.s.value,l:t.l.value},i?.value??n));return{fill:l}}init(a){const t=(0,e.itemFromSingleOrMultiple)(a.options.gradient);if(!t)return;const{angle:i}=t;a.gradient={angle:{value:(0,e.getRangeValue)(i.value),enable:i.animation.enable,velocity:(0,e.getRangeValue)(i.animation.speed)/360*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(i.animation.decay),delayTime:1e3*(0,e.getRangeValue)(i.animation.delay),time:0},type:t.type,colors:[]};let n=t.angle.direction;switch("random"===n&&(n=(0,e.getRandom)()>.5?"counter-clockwise":"clockwise"),n){case"counter-clockwise":case"counterClockwise":a.gradient.angle.status="decreasing";break;case"clockwise":a.gradient.angle.status="increasing"}const o=a.options.reduceDuplicates;for(const i of t.colors){const t=(0,e.rangeColorToHsl)(i.value,a.id,o);if(!t)continue;const n=(0,e.getHslAnimationFromHsl)(t,i.value.animation,a.container.retina.reduceFactor),s={stop:i.stop,value:n,opacity:i.opacity?{enable:i.opacity.animation.enable,max:(0,e.getRangeMax)(i.opacity.value),min:(0,e.getRangeMin)(i.opacity.value),status:"increasing",value:(0,e.getRangeValue)(i.opacity.value),velocity:(0,e.getRangeValue)(i.opacity.animation.speed)/100*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(i.opacity.animation.decay),delayTime:1e3*(0,e.getRangeValue)(i.opacity.animation.delay),time:0}:void 0},{opacity:l}=s;if(i.opacity&&l){const a=i.opacity.value;l.min=(0,e.getRangeMin)(a),l.max=(0,e.getRangeMax)(a);switch(i.opacity.animation.startValue){case"min":l.value=l.min,l.status="increasing";break;case"max":l.value=l.max,l.status="decreasing";break;default:l.value=(0,e.randomInRange)(l),l.status=(0,e.getRandom)()>=.5?"increasing":"decreasing"}}a.gradient.colors.push(s)}}isEnabled(e){return!e.destroyed&&!e.spawning&&(e.gradient?.angle.enable||(e.gradient?.colors.some((e=>e.value.h.enable||e.value.s.enable||e.value.l.enable))??!1))}loadOptions(a,...t){for(const i of t){if(!i?.gradient)continue;const t=i.gradient;t&&(a.gradient=(0,e.executeOnSingleOrMultiple)(t,(e=>{const a=new c;return a.load(e),a})))}}update(e,a){d(e,a)}}async function y(e,a=!0){await e.addParticleUpdater("gradient",(()=>new v),a)}})(),n})()));
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 r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(e=>(()=>{var t,r,n={533:t=>{t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,i),r.exports}i.m=n,i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.f={},i.e=e=>Promise.all(Object.keys(i.f).reduce(((t,r)=>(i.f[r](e,t),t)),[])),i.u=e=>e+".min.js",i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/updater-gradient:",i.l=(e,n,o,a)=>{if(t[e])t[e].push(n);else{var s,d;if(void 0!==o)for(var u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var p=u[c];if(p.getAttribute("src")==e||p.getAttribute("data-webpack")==r+o){s=p;break}}s||(d=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,i.nc&&s.setAttribute("nonce",i.nc),s.setAttribute("data-webpack",r+o),s.src=e),t[e]=[n];var l=(r,n)=>{s.onerror=s.onload=null,clearTimeout(f);var o=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),o&&o.forEach((e=>e(n))),r)return r(n)},f=setTimeout(l.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=l.bind(null,s.onerror),s.onload=l.bind(null,s.onload),d&&document.head.appendChild(s)}},i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;i.g.importScripts&&(e=i.g.location+"");var t=i.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&!e;)e=r[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=e})(),(()=>{var e={127:0};i.f.j=(t,r)=>{var n=i.o(e,t)?e[t]:void 0;if(0!==n)if(n)r.push(n[2]);else{var o=new Promise(((r,o)=>n=e[t]=[r,o]));r.push(n[2]=o);var a=i.p+i.u(t),s=new Error;i.l(a,(r=>{if(i.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var o=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+o+": "+a+")",s.name="ChunkLoadError",s.type=o,s.request=a,n[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var n,o,a=r[0],s=r[1],d=r[2],u=0;if(a.some((t=>0!==e[t]))){for(n in s)i.o(s,n)&&(i.m[n]=s[n]);if(d)d(i)}for(t&&t(r);u<a.length;u++)o=a[u],i.o(e,o)&&e[o]&&e[o][0](),e[o]=0},r=this.webpackChunk_tsparticles_updater_gradient=this.webpackChunk_tsparticles_updater_gradient||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};return(()=>{async function e(e,t=!0){await e.addParticleUpdater("gradient",(async()=>{const{GradientUpdater:e}=await i.e(914).then(i.bind(i,914));return new e}),t)}i.r(a),i.d(a,{loadGradientUpdater:()=>e})})(),a})()));
@@ -1 +1 @@
1
- /*! tsParticles Gradient Updater v3.0.3 by Matteo Bruni */
1
+ /*! tsParticles Gradient Updater v3.2.0 by Matteo Bruni */
@@ -2,8 +2,8 @@ import { type IDelta, type IParticleColorStyle, type IParticleUpdater, type Recu
2
2
  import type { GradientParticle, GradientParticlesOptions, IGradientParticlesOptions } from "./Types.js";
3
3
  export declare class GradientUpdater implements IParticleUpdater {
4
4
  getColorStyles(particle: GradientParticle, context: CanvasRenderingContext2D, radius: number, opacity: number): IParticleColorStyle;
5
- init(particle: GradientParticle): void;
5
+ init(particle: GradientParticle): Promise<void>;
6
6
  isEnabled(particle: GradientParticle): boolean;
7
7
  loadOptions(options: GradientParticlesOptions, ...sources: (RecursivePartial<IGradientParticlesOptions> | undefined)[]): void;
8
- update(particle: GradientParticle, delta: IDelta): void;
8
+ update(particle: GradientParticle, delta: IDelta): Promise<void>;
9
9
  }
package/types/Types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { GradientType, IParticleHslAnimation, IParticleNumericValueAnimation, IParticleValueAnimation, IParticlesOptions, Particle, ParticlesOptions, SingleOrMultiple } from "@tsparticles/engine";
1
+ import type { GradientType, IParticleHslAnimation, IParticleNumericValueAnimation, IParticlesOptions, Particle, ParticlesOptions, SingleOrMultiple } from "@tsparticles/engine";
2
2
  import type { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
3
3
  import type { IAnimatableGradient } from "./Options/Interfaces/IAnimatableGradient.js";
4
4
  export interface IParticleGradientColorAnimation {
@@ -7,7 +7,7 @@ export interface IParticleGradientColorAnimation {
7
7
  value: IParticleHslAnimation;
8
8
  }
9
9
  export interface IParticleGradientAnimation {
10
- angle: IParticleValueAnimation<number>;
10
+ angle: IParticleNumericValueAnimation;
11
11
  colors: IParticleGradientColorAnimation[];
12
12
  type: GradientType;
13
13
  }
@@ -1,26 +1,50 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
1
24
  (function (factory) {
2
25
  if (typeof module === "object" && typeof module.exports === "object") {
3
26
  var v = factory(require, exports);
4
27
  if (v !== undefined) module.exports = v;
5
28
  }
6
29
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "./Options/Classes/AnimatableGradient.js", "./Utils.js"], factory);
30
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/AnimatableGradient.js"], factory);
8
31
  }
9
32
  })(function (require, exports) {
10
33
  "use strict";
34
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
11
35
  Object.defineProperty(exports, "__esModule", { value: true });
12
36
  exports.GradientUpdater = void 0;
13
37
  const engine_1 = require("@tsparticles/engine");
14
38
  const AnimatableGradient_js_1 = require("./Options/Classes/AnimatableGradient.js");
15
- const Utils_js_1 = require("./Utils.js");
39
+ const double = 2, doublePI = Math.PI * double;
16
40
  class GradientUpdater {
17
41
  getColorStyles(particle, context, radius, opacity) {
18
42
  const gradient = particle.gradient;
19
43
  if (!gradient) {
20
44
  return {};
21
45
  }
22
- const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
23
- ? context.createRadialGradient(0, 0, 0, 0, 0, radius)
46
+ const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === "radial"
47
+ ? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
24
48
  : context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
25
49
  for (const { stop, value, opacity: cOpacity } of gradient.colors) {
26
50
  fillGradient.addColorStop(stop, (0, engine_1.getStyleFromHsl)({
@@ -31,19 +55,21 @@
31
55
  }
32
56
  return { fill: fillGradient };
33
57
  }
34
- init(particle) {
58
+ async init(particle) {
35
59
  const gradient = (0, engine_1.itemFromSingleOrMultiple)(particle.options.gradient);
36
60
  if (!gradient) {
37
61
  return;
38
62
  }
39
- const { angle } = gradient;
63
+ const { angle } = gradient, speedFactor = 360, delayOffset = 1;
40
64
  particle.gradient = {
41
65
  angle: {
42
66
  value: (0, engine_1.getRangeValue)(angle.value),
43
67
  enable: angle.animation.enable,
44
- velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) / 360) * particle.container.retina.reduceFactor,
45
- decay: 1 - (0, engine_1.getRangeValue)(angle.animation.decay),
46
- delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) * 1000,
68
+ velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) / speedFactor) * particle.container.retina.reduceFactor,
69
+ decay: delayOffset - (0, engine_1.getRangeValue)(angle.animation.decay),
70
+ delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) * engine_1.millisecondsToSeconds,
71
+ max: doublePI,
72
+ min: 0,
47
73
  time: 0,
48
74
  },
49
75
  type: gradient.type,
@@ -51,7 +77,7 @@
51
77
  };
52
78
  let rotateDirection = gradient.angle.direction;
53
79
  if (rotateDirection === "random") {
54
- rotateDirection = (0, engine_1.getRandom)() > 0.5 ? "counter-clockwise" : "clockwise";
80
+ rotateDirection = (0, engine_1.getRandom)() > engine_1.halfRandom ? "counter-clockwise" : "clockwise";
55
81
  }
56
82
  switch (rotateDirection) {
57
83
  case "counter-clockwise":
@@ -78,10 +104,10 @@
78
104
  min: (0, engine_1.getRangeMin)(grColor.opacity.value),
79
105
  status: "increasing",
80
106
  value: (0, engine_1.getRangeValue)(grColor.opacity.value),
81
- velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) / 100) *
107
+ velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) / engine_1.percentDenominator) *
82
108
  particle.container.retina.reduceFactor,
83
- decay: 1 - (0, engine_1.getRangeValue)(grColor.opacity.animation.decay),
84
- delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) * 1000,
109
+ decay: delayOffset - (0, engine_1.getRangeValue)(grColor.opacity.animation.decay),
110
+ delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) * engine_1.millisecondsToSeconds,
85
111
  time: 0,
86
112
  }
87
113
  : undefined,
@@ -105,17 +131,18 @@
105
131
  default:
106
132
  addOpacity.value = (0, engine_1.randomInRange)(addOpacity);
107
133
  addOpacity.status =
108
- (0, engine_1.getRandom)() >= 0.5 ? "increasing" : "decreasing";
134
+ (0, engine_1.getRandom)() >= engine_1.halfRandom ? "increasing" : "decreasing";
109
135
  break;
110
136
  }
111
137
  }
112
138
  particle.gradient.colors.push(addColor);
113
139
  }
140
+ await Promise.resolve();
114
141
  }
115
142
  isEnabled(particle) {
116
143
  return (!particle.destroyed &&
117
144
  !particle.spawning &&
118
- (particle.gradient?.angle.enable ||
145
+ (!!particle.gradient?.angle.enable ||
119
146
  (particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
120
147
  false)));
121
148
  }
@@ -135,8 +162,9 @@
135
162
  });
136
163
  }
137
164
  }
138
- update(particle, delta) {
139
- (0, Utils_js_1.updateGradient)(particle, delta);
165
+ async update(particle, delta) {
166
+ const { updateGradient } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_1, reject_1) => { require(["./Utils.js"], resolve_1, reject_1); }).then(__importStar));
167
+ updateGradient(particle, delta);
140
168
  }
141
169
  }
142
170
  exports.GradientUpdater = GradientUpdater;
package/umd/Utils.js CHANGED
@@ -4,116 +4,23 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.updateGradient = void 0;
13
- function updateColorOpacity(delta, value) {
14
- if (!value.enable) {
15
- return;
16
- }
17
- const decay = value.decay ?? 1;
18
- switch (value.status) {
19
- case "increasing":
20
- if (value.value >= value.max) {
21
- value.status = "decreasing";
22
- }
23
- else {
24
- value.value += (value.velocity ?? 0) * delta.factor;
25
- }
26
- break;
27
- case "decreasing":
28
- if (value.value <= value.min) {
29
- value.status = "increasing";
30
- }
31
- else {
32
- value.value -= (value.velocity ?? 0) * delta.factor;
33
- }
34
- break;
35
- }
36
- if (value.velocity && decay !== 1) {
37
- value.velocity *= decay;
38
- }
39
- }
40
- function updateColorValue(delta, colorValue, max, decrease) {
41
- if (!colorValue || !colorValue.enable) {
42
- return;
43
- }
44
- if (!colorValue.time) {
45
- colorValue.time = 0;
46
- }
47
- if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
48
- colorValue.time += delta.value;
49
- }
50
- if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
51
- return;
52
- }
53
- const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
54
- if (!decrease || colorValue.status === "increasing") {
55
- colorValue.value += velocity;
56
- if (decrease && colorValue.value > max) {
57
- colorValue.status = "decreasing";
58
- colorValue.value -= colorValue.value % max;
59
- }
60
- }
61
- else {
62
- colorValue.value -= velocity;
63
- if (colorValue.value < 0) {
64
- colorValue.status = "increasing";
65
- colorValue.value += colorValue.value;
66
- }
67
- }
68
- if (colorValue.value > max) {
69
- colorValue.value %= max;
70
- }
71
- if (colorValue.velocity && decay !== 1) {
72
- colorValue.velocity *= decay;
73
- }
74
- }
75
- function updateAngle(delta, angle) {
76
- const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 1;
77
- if (!angle.enable) {
78
- return;
79
- }
80
- switch (angle.status) {
81
- case "increasing":
82
- angle.value += speed;
83
- if (angle.value > max) {
84
- angle.value -= max;
85
- }
86
- break;
87
- case "decreasing":
88
- default:
89
- angle.value -= speed;
90
- if (angle.value < 0) {
91
- angle.value += max;
92
- }
93
- break;
94
- }
95
- if (angle.velocity && decay !== 1) {
96
- angle.velocity *= decay;
97
- }
98
- }
13
+ const engine_1 = require("@tsparticles/engine");
99
14
  function updateGradient(particle, delta) {
100
15
  const { gradient } = particle;
101
16
  if (!gradient) {
102
17
  return;
103
18
  }
104
- updateAngle(delta, gradient.angle);
19
+ (0, engine_1.updateAnimation)(particle, gradient.angle, false, "none", delta);
105
20
  for (const color of gradient.colors) {
106
- if (particle.color?.h !== undefined) {
107
- updateColorValue(delta, color.value.h, 360, false);
108
- }
109
- if (particle.color?.s !== undefined) {
110
- updateColorValue(delta, color.value.s, 100, true);
111
- }
112
- if (particle.color?.l !== undefined) {
113
- updateColorValue(delta, color.value.l, 100, true);
114
- }
21
+ (0, engine_1.updateColor)(color.value, delta);
115
22
  if (color.opacity) {
116
- updateColorOpacity(delta, color.opacity);
23
+ (0, engine_1.updateAnimation)(particle, color.opacity, true, "none", delta);
117
24
  }
118
25
  }
119
26
  }
package/umd/index.js CHANGED
@@ -1,18 +1,44 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
1
24
  (function (factory) {
2
25
  if (typeof module === "object" && typeof module.exports === "object") {
3
26
  var v = factory(require, exports);
4
27
  if (v !== undefined) module.exports = v;
5
28
  }
6
29
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./GradientUpdater.js"], factory);
30
+ define(["require", "exports"], factory);
8
31
  }
9
32
  })(function (require, exports) {
10
33
  "use strict";
34
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
11
35
  Object.defineProperty(exports, "__esModule", { value: true });
12
36
  exports.loadGradientUpdater = void 0;
13
- const GradientUpdater_js_1 = require("./GradientUpdater.js");
14
37
  async function loadGradientUpdater(engine, refresh = true) {
15
- await engine.addParticleUpdater("gradient", () => new GradientUpdater_js_1.GradientUpdater(), refresh);
38
+ await engine.addParticleUpdater("gradient", async () => {
39
+ const { GradientUpdater } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./GradientUpdater.js"))) : new Promise((resolve_1, reject_1) => { require(["./GradientUpdater.js"], resolve_1, reject_1); }).then(__importStar));
40
+ return new GradientUpdater();
41
+ }, refresh);
16
42
  }
17
43
  exports.loadGradientUpdater = loadGradientUpdater;
18
44
  });