@tsparticles/engine 4.0.4 → 4.1.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.
- package/browser/Core/CanvasManager.js +72 -72
- package/browser/Core/Container.js +85 -85
- package/browser/Core/Engine.js +11 -11
- package/browser/Core/Particle.js +142 -63
- package/browser/Core/ParticlesManager.js +138 -138
- package/browser/Core/RenderManager.js +110 -110
- package/browser/Core/Retina.js +3 -4
- package/browser/Core/Utils/EventListeners.js +31 -31
- package/browser/Core/Utils/PluginManager.js +26 -26
- package/browser/Core/Utils/SpatialHashGrid.js +36 -36
- package/browser/Core/Utils/Vectors.js +3 -3
- package/browser/Options/Classes/Options.js +13 -13
- package/browser/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/browser/Utils/EventDispatcher.js +10 -10
- package/browser/exports.js +0 -4
- package/cjs/Core/CanvasManager.js +72 -72
- package/cjs/Core/Container.js +85 -85
- package/cjs/Core/Engine.js +11 -11
- package/cjs/Core/Particle.js +142 -63
- package/cjs/Core/ParticlesManager.js +138 -138
- package/cjs/Core/RenderManager.js +110 -110
- package/cjs/Core/Retina.js +3 -4
- package/cjs/Core/Utils/EventListeners.js +31 -31
- package/cjs/Core/Utils/PluginManager.js +26 -26
- package/cjs/Core/Utils/SpatialHashGrid.js +36 -36
- package/cjs/Core/Utils/Vectors.js +3 -3
- package/cjs/Options/Classes/Options.js +13 -13
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/cjs/Utils/EventDispatcher.js +10 -10
- package/cjs/exports.js +0 -4
- package/esm/Core/CanvasManager.js +72 -72
- package/esm/Core/Container.js +85 -85
- package/esm/Core/Engine.js +11 -11
- package/esm/Core/Particle.js +142 -63
- package/esm/Core/ParticlesManager.js +138 -138
- package/esm/Core/RenderManager.js +110 -110
- package/esm/Core/Retina.js +3 -4
- package/esm/Core/Utils/EventListeners.js +31 -31
- package/esm/Core/Utils/PluginManager.js +26 -26
- package/esm/Core/Utils/SpatialHashGrid.js +36 -36
- package/esm/Core/Utils/Vectors.js +3 -3
- package/esm/Options/Classes/Options.js +13 -13
- package/esm/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/esm/Utils/EventDispatcher.js +10 -10
- package/esm/exports.js +0 -4
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +690 -697
- package/tsparticles.engine.min.js +1 -1
- package/types/Core/CanvasManager.d.ts +1 -16
- package/types/Core/Container.d.ts +1 -18
- package/types/Core/Engine.d.ts +1 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +2 -0
- package/types/Core/Interfaces/IParticleCanvasBounds.d.ts +16 -0
- package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -0
- package/types/Core/Interfaces/IShapeDrawer.d.ts +2 -0
- package/types/Core/Particle.d.ts +5 -13
- package/types/Core/ParticlesManager.d.ts +1 -28
- package/types/Core/RenderManager.d.ts +1 -23
- package/types/Core/Retina.d.ts +1 -1
- package/types/Core/Utils/EventListeners.d.ts +1 -8
- package/types/Core/Utils/PluginManager.d.ts +1 -8
- package/types/Core/Utils/SpatialHashGrid.d.ts +1 -12
- package/types/Core/Utils/Vectors.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +1 -4
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -7
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -4
- package/types/Utils/EventDispatcher.d.ts +1 -1
- package/types/export-types.d.ts +1 -4
- package/types/exports.d.ts +0 -4
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/browser/Options/Classes/Particles/Size/Size.js +0 -21
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/browser/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/cjs/Options/Classes/Particles/Size/Size.js +0 -21
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/cjs/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
- package/cjs/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
- package/cjs/Options/Interfaces/Particles/Size/ISize.js +0 -1
- package/cjs/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/esm/Options/Classes/Particles/Size/Size.js +0 -21
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/esm/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
- package/esm/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
- package/esm/Options/Interfaces/Particles/Size/ISize.js +0 -1
- package/esm/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +0 -10
- package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -10
- package/types/Options/Classes/Particles/Size/Size.d.ts +0 -10
- package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -10
- package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -5
- /package/browser/{Options/Interfaces/Particles/Opacity/IOpacity.js → Core/Interfaces/IParticleCanvasBounds.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js → cjs/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Size/ISize.js → esm/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
package/tsparticles.engine.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* tsParticles Engine v4.0
|
|
2
|
+
/* tsParticles Engine v4.1.0 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -804,38 +804,38 @@
|
|
|
804
804
|
}
|
|
805
805
|
|
|
806
806
|
class EventDispatcher {
|
|
807
|
-
|
|
807
|
+
#listeners;
|
|
808
808
|
constructor() {
|
|
809
|
-
this
|
|
809
|
+
this.#listeners = new Map();
|
|
810
810
|
}
|
|
811
811
|
addEventListener(type, listener) {
|
|
812
812
|
this.removeEventListener(type, listener);
|
|
813
|
-
let arr = this.
|
|
813
|
+
let arr = this.#listeners.get(type);
|
|
814
814
|
if (!arr) {
|
|
815
815
|
arr = [];
|
|
816
|
-
this.
|
|
816
|
+
this.#listeners.set(type, arr);
|
|
817
817
|
}
|
|
818
818
|
arr.push(listener);
|
|
819
819
|
}
|
|
820
820
|
dispatchEvent(type, args) {
|
|
821
|
-
const listeners = this.
|
|
821
|
+
const listeners = this.#listeners.get(type);
|
|
822
822
|
listeners?.forEach(handler => {
|
|
823
823
|
handler(args);
|
|
824
824
|
});
|
|
825
825
|
}
|
|
826
826
|
hasEventListener(type) {
|
|
827
|
-
return !!this.
|
|
827
|
+
return !!this.#listeners.get(type);
|
|
828
828
|
}
|
|
829
829
|
removeAllEventListeners(type) {
|
|
830
830
|
if (!type) {
|
|
831
|
-
this
|
|
831
|
+
this.#listeners = new Map();
|
|
832
832
|
}
|
|
833
833
|
else {
|
|
834
|
-
this.
|
|
834
|
+
this.#listeners.delete(type);
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
837
|
removeEventListener(type, listener) {
|
|
838
|
-
const arr = this.
|
|
838
|
+
const arr = this.#listeners.get(type);
|
|
839
839
|
if (!arr) {
|
|
840
840
|
return;
|
|
841
841
|
}
|
|
@@ -844,7 +844,7 @@
|
|
|
844
844
|
return;
|
|
845
845
|
}
|
|
846
846
|
if (length === deleteCount) {
|
|
847
|
-
this.
|
|
847
|
+
this.#listeners.delete(type);
|
|
848
848
|
}
|
|
849
849
|
else {
|
|
850
850
|
arr.splice(idx, deleteCount);
|
|
@@ -882,19 +882,19 @@
|
|
|
882
882
|
presets = new Map();
|
|
883
883
|
shapeDrawers = new Map();
|
|
884
884
|
updaters = new Map();
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
885
|
+
#allLoadersSet = new Set();
|
|
886
|
+
#configs = new Map();
|
|
887
|
+
#engine;
|
|
888
|
+
#executedSet = new Set();
|
|
889
|
+
#initialized = false;
|
|
890
|
+
#isRunningLoaders = false;
|
|
891
|
+
#loadPromises = new Set();
|
|
892
892
|
constructor(engine) {
|
|
893
|
-
this
|
|
893
|
+
this.#engine = engine;
|
|
894
894
|
}
|
|
895
895
|
get configs() {
|
|
896
896
|
const res = {};
|
|
897
|
-
for (const [name, config] of this
|
|
897
|
+
for (const [name, config] of this.#configs) {
|
|
898
898
|
res[name] = config;
|
|
899
899
|
}
|
|
900
900
|
return res;
|
|
@@ -904,8 +904,8 @@
|
|
|
904
904
|
}
|
|
905
905
|
addConfig(config) {
|
|
906
906
|
const key = config.key ?? config.name ?? "default";
|
|
907
|
-
this.
|
|
908
|
-
this.
|
|
907
|
+
this.#configs.set(key, config);
|
|
908
|
+
this.#engine.dispatchEvent(exports.EventType.configAdded, { data: { name: key, config } });
|
|
909
909
|
}
|
|
910
910
|
addEasing(name, easing) {
|
|
911
911
|
if (this.easingFunctions.get(name)) {
|
|
@@ -966,21 +966,21 @@
|
|
|
966
966
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
967
967
|
}
|
|
968
968
|
async init() {
|
|
969
|
-
if (this
|
|
969
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
970
970
|
return;
|
|
971
971
|
}
|
|
972
|
-
this
|
|
973
|
-
this
|
|
974
|
-
this
|
|
972
|
+
this.#isRunningLoaders = true;
|
|
973
|
+
this.#executedSet = new Set();
|
|
974
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
975
975
|
try {
|
|
976
|
-
for (const loader of this
|
|
977
|
-
await this
|
|
976
|
+
for (const loader of this.#allLoadersSet) {
|
|
977
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
finally {
|
|
981
|
-
this.
|
|
982
|
-
this
|
|
983
|
-
this
|
|
981
|
+
this.#loadPromises.clear();
|
|
982
|
+
this.#isRunningLoaders = false;
|
|
983
|
+
this.#initialized = true;
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
986
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -991,24 +991,24 @@
|
|
|
991
991
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
992
992
|
}
|
|
993
993
|
async register(...loaders) {
|
|
994
|
-
if (this
|
|
994
|
+
if (this.#initialized) {
|
|
995
995
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
996
996
|
}
|
|
997
997
|
for (const loader of loaders) {
|
|
998
|
-
if (this
|
|
999
|
-
await this
|
|
998
|
+
if (this.#isRunningLoaders) {
|
|
999
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
1000
1000
|
}
|
|
1001
1001
|
else {
|
|
1002
|
-
this.
|
|
1002
|
+
this.#loadPromises.add(loader);
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
1005
1005
|
}
|
|
1006
|
-
async
|
|
1006
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
1007
1007
|
if (executed.has(loader))
|
|
1008
1008
|
return;
|
|
1009
1009
|
executed.add(loader);
|
|
1010
1010
|
allLoaders.add(loader);
|
|
1011
|
-
await loader(this
|
|
1011
|
+
await loader(this.#engine);
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
1014
1014
|
|
|
@@ -1111,17 +1111,17 @@
|
|
|
1111
1111
|
};
|
|
1112
1112
|
class Engine {
|
|
1113
1113
|
pluginManager = new PluginManager(this);
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1114
|
+
#domArray = [];
|
|
1115
|
+
#eventDispatcher = new EventDispatcher();
|
|
1116
|
+
#initialized = false;
|
|
1117
1117
|
get items() {
|
|
1118
|
-
return this
|
|
1118
|
+
return this.#domArray;
|
|
1119
1119
|
}
|
|
1120
1120
|
get version() {
|
|
1121
|
-
return "4.0
|
|
1121
|
+
return "4.1.0";
|
|
1122
1122
|
}
|
|
1123
1123
|
addEventListener(type, listener) {
|
|
1124
|
-
this.
|
|
1124
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1125
1125
|
}
|
|
1126
1126
|
checkVersion(pluginVersion) {
|
|
1127
1127
|
if (this.version === pluginVersion) {
|
|
@@ -1130,17 +1130,17 @@
|
|
|
1130
1130
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1131
1131
|
}
|
|
1132
1132
|
dispatchEvent(type, args) {
|
|
1133
|
-
this.
|
|
1133
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1134
1134
|
}
|
|
1135
1135
|
async init() {
|
|
1136
|
-
if (this
|
|
1136
|
+
if (this.#initialized) {
|
|
1137
1137
|
return;
|
|
1138
1138
|
}
|
|
1139
1139
|
await this.pluginManager.init();
|
|
1140
|
-
this
|
|
1140
|
+
this.#initialized = true;
|
|
1141
1141
|
}
|
|
1142
1142
|
item(index) {
|
|
1143
|
-
const
|
|
1143
|
+
const items = this.items, item = items[index];
|
|
1144
1144
|
if (item?.destroyed) {
|
|
1145
1145
|
items.splice(index, removeDeleteCount);
|
|
1146
1146
|
return;
|
|
@@ -1194,7 +1194,7 @@
|
|
|
1194
1194
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1195
1195
|
}
|
|
1196
1196
|
removeEventListener(type, listener) {
|
|
1197
|
-
this.
|
|
1197
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1198
1198
|
}
|
|
1199
1199
|
}
|
|
1200
1200
|
|
|
@@ -1965,43 +1965,6 @@
|
|
|
1965
1965
|
}
|
|
1966
1966
|
}
|
|
1967
1967
|
|
|
1968
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1969
|
-
destroy;
|
|
1970
|
-
constructor() {
|
|
1971
|
-
super();
|
|
1972
|
-
this.destroy = exports.DestroyType.none;
|
|
1973
|
-
this.speed = 2;
|
|
1974
|
-
}
|
|
1975
|
-
load(data) {
|
|
1976
|
-
super.load(data);
|
|
1977
|
-
if (isNull(data)) {
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
if (data.destroy !== undefined) {
|
|
1981
|
-
this.destroy = data.destroy;
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1987
|
-
animation;
|
|
1988
|
-
constructor() {
|
|
1989
|
-
super();
|
|
1990
|
-
this.animation = new OpacityAnimation();
|
|
1991
|
-
this.value = 1;
|
|
1992
|
-
}
|
|
1993
|
-
load(data) {
|
|
1994
|
-
if (isNull(data)) {
|
|
1995
|
-
return;
|
|
1996
|
-
}
|
|
1997
|
-
super.load(data);
|
|
1998
|
-
const animation = data.animation;
|
|
1999
|
-
if (animation !== undefined) {
|
|
2000
|
-
this.animation.load(animation);
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
1968
|
class Stroke {
|
|
2006
1969
|
color;
|
|
2007
1970
|
opacity;
|
|
@@ -2169,43 +2132,6 @@
|
|
|
2169
2132
|
}
|
|
2170
2133
|
}
|
|
2171
2134
|
|
|
2172
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2173
|
-
destroy;
|
|
2174
|
-
constructor() {
|
|
2175
|
-
super();
|
|
2176
|
-
this.destroy = exports.DestroyType.none;
|
|
2177
|
-
this.speed = 5;
|
|
2178
|
-
}
|
|
2179
|
-
load(data) {
|
|
2180
|
-
super.load(data);
|
|
2181
|
-
if (isNull(data)) {
|
|
2182
|
-
return;
|
|
2183
|
-
}
|
|
2184
|
-
if (data.destroy !== undefined) {
|
|
2185
|
-
this.destroy = data.destroy;
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
|
|
2190
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2191
|
-
animation;
|
|
2192
|
-
constructor() {
|
|
2193
|
-
super();
|
|
2194
|
-
this.animation = new SizeAnimation();
|
|
2195
|
-
this.value = 3;
|
|
2196
|
-
}
|
|
2197
|
-
load(data) {
|
|
2198
|
-
super.load(data);
|
|
2199
|
-
if (isNull(data)) {
|
|
2200
|
-
return;
|
|
2201
|
-
}
|
|
2202
|
-
const animation = data.animation;
|
|
2203
|
-
if (animation !== undefined) {
|
|
2204
|
-
this.animation.load(animation);
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
|
|
2209
2135
|
class ZIndex extends ValueWithRandom {
|
|
2210
2136
|
opacityRate;
|
|
2211
2137
|
sizeRate;
|
|
@@ -2239,24 +2165,21 @@
|
|
|
2239
2165
|
groups;
|
|
2240
2166
|
move;
|
|
2241
2167
|
number;
|
|
2242
|
-
opacity;
|
|
2243
2168
|
paint;
|
|
2244
2169
|
palette;
|
|
2245
2170
|
reduceDuplicates;
|
|
2246
2171
|
shape;
|
|
2247
|
-
size;
|
|
2248
2172
|
zIndex;
|
|
2249
|
-
|
|
2250
|
-
|
|
2173
|
+
#container;
|
|
2174
|
+
#pluginManager;
|
|
2251
2175
|
constructor(pluginManager, container) {
|
|
2252
|
-
this
|
|
2253
|
-
this
|
|
2176
|
+
this.#pluginManager = pluginManager;
|
|
2177
|
+
this.#container = container;
|
|
2254
2178
|
this.bounce = new ParticlesBounce();
|
|
2255
2179
|
this.effect = new Effect();
|
|
2256
2180
|
this.groups = {};
|
|
2257
2181
|
this.move = new Move();
|
|
2258
2182
|
this.number = new ParticlesNumber();
|
|
2259
|
-
this.opacity = new Opacity();
|
|
2260
2183
|
this.paint = new Paint();
|
|
2261
2184
|
this.paint.color = new AnimatableColor();
|
|
2262
2185
|
this.paint.color.value = "#fff";
|
|
@@ -2264,7 +2187,6 @@
|
|
|
2264
2187
|
this.paint.fill.enable = true;
|
|
2265
2188
|
this.reduceDuplicates = false;
|
|
2266
2189
|
this.shape = new Shape();
|
|
2267
|
-
this.size = new Size();
|
|
2268
2190
|
this.zIndex = new ZIndex();
|
|
2269
2191
|
}
|
|
2270
2192
|
load(data) {
|
|
@@ -2273,7 +2195,7 @@
|
|
|
2273
2195
|
}
|
|
2274
2196
|
if (data.palette) {
|
|
2275
2197
|
this.palette = data.palette;
|
|
2276
|
-
this
|
|
2198
|
+
this.#importPalette(this.palette);
|
|
2277
2199
|
}
|
|
2278
2200
|
if (data.groups !== undefined) {
|
|
2279
2201
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2293,7 +2215,6 @@
|
|
|
2293
2215
|
this.effect.load(data.effect);
|
|
2294
2216
|
this.move.load(data.move);
|
|
2295
2217
|
this.number.load(data.number);
|
|
2296
|
-
this.opacity.load(data.opacity);
|
|
2297
2218
|
const paintToLoad = data.paint;
|
|
2298
2219
|
if (paintToLoad) {
|
|
2299
2220
|
if (isArray(paintToLoad)) {
|
|
@@ -2312,15 +2233,14 @@
|
|
|
2312
2233
|
}
|
|
2313
2234
|
}
|
|
2314
2235
|
this.shape.load(data.shape);
|
|
2315
|
-
this.size.load(data.size);
|
|
2316
2236
|
this.zIndex.load(data.zIndex);
|
|
2317
|
-
if (this
|
|
2318
|
-
for (const plugin of this.
|
|
2237
|
+
if (this.#container) {
|
|
2238
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2319
2239
|
if (plugin.loadParticlesOptions) {
|
|
2320
|
-
plugin.loadParticlesOptions(this
|
|
2240
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2321
2241
|
}
|
|
2322
2242
|
}
|
|
2323
|
-
const updaters = this.
|
|
2243
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2324
2244
|
if (updaters) {
|
|
2325
2245
|
for (const updater of updaters) {
|
|
2326
2246
|
if (updater.loadOptions) {
|
|
@@ -2330,8 +2250,8 @@
|
|
|
2330
2250
|
}
|
|
2331
2251
|
}
|
|
2332
2252
|
}
|
|
2333
|
-
|
|
2334
|
-
const paletteData = this.
|
|
2253
|
+
#importPalette = (palette) => {
|
|
2254
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2335
2255
|
if (!paletteData) {
|
|
2336
2256
|
return;
|
|
2337
2257
|
}
|
|
@@ -2410,11 +2330,11 @@
|
|
|
2410
2330
|
smooth;
|
|
2411
2331
|
style;
|
|
2412
2332
|
zLayers;
|
|
2413
|
-
|
|
2414
|
-
|
|
2333
|
+
#container;
|
|
2334
|
+
#pluginManager;
|
|
2415
2335
|
constructor(pluginManager, container) {
|
|
2416
|
-
this
|
|
2417
|
-
this
|
|
2336
|
+
this.#pluginManager = pluginManager;
|
|
2337
|
+
this.#container = container;
|
|
2418
2338
|
this.autoPlay = true;
|
|
2419
2339
|
this.background = new Background();
|
|
2420
2340
|
this.clear = true;
|
|
@@ -2425,7 +2345,7 @@
|
|
|
2425
2345
|
this.duration = 0;
|
|
2426
2346
|
this.fpsLimit = 120;
|
|
2427
2347
|
this.hdr = true;
|
|
2428
|
-
this.particles = loadParticlesOptions(this
|
|
2348
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2429
2349
|
this.pauseOnBlur = true;
|
|
2430
2350
|
this.pauseOnOutsideViewport = true;
|
|
2431
2351
|
this.resize = new ResizeEvent();
|
|
@@ -2440,12 +2360,12 @@
|
|
|
2440
2360
|
if (data.preset !== undefined) {
|
|
2441
2361
|
this.preset = data.preset;
|
|
2442
2362
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2443
|
-
this
|
|
2363
|
+
this.#importPreset(preset);
|
|
2444
2364
|
});
|
|
2445
2365
|
}
|
|
2446
2366
|
if (data.palette !== undefined) {
|
|
2447
2367
|
this.palette = data.palette;
|
|
2448
|
-
this
|
|
2368
|
+
this.#importPalette(this.palette);
|
|
2449
2369
|
}
|
|
2450
2370
|
if (data.autoPlay !== undefined) {
|
|
2451
2371
|
this.autoPlay = data.autoPlay;
|
|
@@ -2499,12 +2419,12 @@
|
|
|
2499
2419
|
if (data.smooth !== undefined) {
|
|
2500
2420
|
this.smooth = data.smooth;
|
|
2501
2421
|
}
|
|
2502
|
-
this.
|
|
2503
|
-
plugin.loadOptions(this
|
|
2422
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2423
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2504
2424
|
});
|
|
2505
2425
|
}
|
|
2506
|
-
|
|
2507
|
-
const paletteData = this.
|
|
2426
|
+
#importPalette = palette => {
|
|
2427
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2508
2428
|
if (!paletteData) {
|
|
2509
2429
|
return;
|
|
2510
2430
|
}
|
|
@@ -2521,8 +2441,8 @@
|
|
|
2521
2441
|
},
|
|
2522
2442
|
});
|
|
2523
2443
|
};
|
|
2524
|
-
|
|
2525
|
-
this.load(this.
|
|
2444
|
+
#importPreset = preset => {
|
|
2445
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2526
2446
|
};
|
|
2527
2447
|
}
|
|
2528
2448
|
|
|
@@ -3021,58 +2941,58 @@
|
|
|
3021
2941
|
}
|
|
3022
2942
|
}
|
|
3023
2943
|
class RenderManager {
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
2944
|
+
#canvasClearPlugins;
|
|
2945
|
+
#canvasManager;
|
|
2946
|
+
#canvasPaintPlugins;
|
|
2947
|
+
#clearDrawPlugins;
|
|
2948
|
+
#colorPlugins;
|
|
2949
|
+
#container;
|
|
2950
|
+
#context;
|
|
2951
|
+
#contextSettings;
|
|
2952
|
+
#drawParticlePlugins;
|
|
2953
|
+
#drawParticlesCleanupPlugins;
|
|
2954
|
+
#drawParticlesSetupPlugins;
|
|
2955
|
+
#drawPlugins;
|
|
2956
|
+
#drawSettingsCleanupPlugins;
|
|
2957
|
+
#drawSettingsSetupPlugins;
|
|
2958
|
+
#pluginManager;
|
|
2959
|
+
#postDrawUpdaters;
|
|
2960
|
+
#preDrawUpdaters;
|
|
2961
|
+
#reusableColorStyles = {};
|
|
2962
|
+
#reusablePluginColors = [undefined, undefined];
|
|
2963
|
+
#reusableTransform = {};
|
|
3044
2964
|
constructor(pluginManager, container, canvasManager) {
|
|
3045
|
-
this
|
|
3046
|
-
this
|
|
3047
|
-
this
|
|
3048
|
-
this
|
|
3049
|
-
this
|
|
3050
|
-
this
|
|
3051
|
-
this
|
|
3052
|
-
this
|
|
3053
|
-
this
|
|
3054
|
-
this
|
|
3055
|
-
this
|
|
3056
|
-
this
|
|
3057
|
-
this
|
|
3058
|
-
this
|
|
3059
|
-
this
|
|
3060
|
-
this
|
|
2965
|
+
this.#pluginManager = pluginManager;
|
|
2966
|
+
this.#container = container;
|
|
2967
|
+
this.#canvasManager = canvasManager;
|
|
2968
|
+
this.#context = null;
|
|
2969
|
+
this.#preDrawUpdaters = [];
|
|
2970
|
+
this.#postDrawUpdaters = [];
|
|
2971
|
+
this.#colorPlugins = [];
|
|
2972
|
+
this.#canvasClearPlugins = [];
|
|
2973
|
+
this.#canvasPaintPlugins = [];
|
|
2974
|
+
this.#clearDrawPlugins = [];
|
|
2975
|
+
this.#drawParticlePlugins = [];
|
|
2976
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
2977
|
+
this.#drawParticlesSetupPlugins = [];
|
|
2978
|
+
this.#drawPlugins = [];
|
|
2979
|
+
this.#drawSettingsSetupPlugins = [];
|
|
2980
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3061
2981
|
}
|
|
3062
2982
|
get settings() {
|
|
3063
|
-
return this
|
|
2983
|
+
return this.#contextSettings;
|
|
3064
2984
|
}
|
|
3065
2985
|
canvasClear() {
|
|
3066
|
-
if (!this.
|
|
2986
|
+
if (!this.#container.actualOptions.clear) {
|
|
3067
2987
|
return;
|
|
3068
2988
|
}
|
|
3069
2989
|
this.draw(ctx => {
|
|
3070
|
-
clear(ctx, this.
|
|
2990
|
+
clear(ctx, this.#canvasManager.size);
|
|
3071
2991
|
});
|
|
3072
2992
|
}
|
|
3073
2993
|
clear() {
|
|
3074
2994
|
let pluginHandled = false;
|
|
3075
|
-
for (const plugin of this
|
|
2995
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
3076
2996
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
3077
2997
|
if (pluginHandled) {
|
|
3078
2998
|
break;
|
|
@@ -3085,21 +3005,21 @@
|
|
|
3085
3005
|
}
|
|
3086
3006
|
destroy() {
|
|
3087
3007
|
this.stop();
|
|
3088
|
-
this
|
|
3089
|
-
this
|
|
3090
|
-
this
|
|
3091
|
-
this
|
|
3092
|
-
this
|
|
3093
|
-
this
|
|
3094
|
-
this
|
|
3095
|
-
this
|
|
3096
|
-
this
|
|
3097
|
-
this
|
|
3098
|
-
this
|
|
3099
|
-
this
|
|
3008
|
+
this.#preDrawUpdaters = [];
|
|
3009
|
+
this.#postDrawUpdaters = [];
|
|
3010
|
+
this.#colorPlugins = [];
|
|
3011
|
+
this.#canvasClearPlugins = [];
|
|
3012
|
+
this.#canvasPaintPlugins = [];
|
|
3013
|
+
this.#clearDrawPlugins = [];
|
|
3014
|
+
this.#drawParticlePlugins = [];
|
|
3015
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3016
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3017
|
+
this.#drawPlugins = [];
|
|
3018
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3019
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3100
3020
|
}
|
|
3101
3021
|
draw(cb) {
|
|
3102
|
-
const ctx = this
|
|
3022
|
+
const ctx = this.#context;
|
|
3103
3023
|
if (!ctx) {
|
|
3104
3024
|
return;
|
|
3105
3025
|
}
|
|
@@ -3114,21 +3034,21 @@
|
|
|
3114
3034
|
return;
|
|
3115
3035
|
}
|
|
3116
3036
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
3117
|
-
let [fColor, sColor] = this
|
|
3037
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
3118
3038
|
fColor ??= pfColor;
|
|
3119
3039
|
sColor ??= psColor;
|
|
3120
3040
|
if (!fColor && !sColor) {
|
|
3121
3041
|
return;
|
|
3122
3042
|
}
|
|
3123
|
-
const container = this
|
|
3043
|
+
const container = this.#container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this.#reusableTransform, colorStyles = this.#reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
|
|
3124
3044
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
3125
3045
|
colorStyles.fill = fill;
|
|
3126
3046
|
colorStyles.stroke = stroke;
|
|
3127
3047
|
this.draw((context) => {
|
|
3128
|
-
for (const plugin of this
|
|
3048
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
3129
3049
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
3130
3050
|
}
|
|
3131
|
-
this
|
|
3051
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
3132
3052
|
drawParticle({
|
|
3133
3053
|
container,
|
|
3134
3054
|
context,
|
|
@@ -3139,35 +3059,35 @@
|
|
|
3139
3059
|
opacity: opacity,
|
|
3140
3060
|
transform,
|
|
3141
3061
|
});
|
|
3142
|
-
this
|
|
3143
|
-
for (const plugin of this
|
|
3062
|
+
this.#applyPostDrawUpdaters(particle);
|
|
3063
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
3144
3064
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
3145
3065
|
}
|
|
3146
3066
|
});
|
|
3147
3067
|
}
|
|
3148
3068
|
drawParticlePlugins(particle, delta) {
|
|
3149
3069
|
this.draw(ctx => {
|
|
3150
|
-
for (const plugin of this
|
|
3070
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
3151
3071
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
3152
3072
|
}
|
|
3153
3073
|
});
|
|
3154
3074
|
}
|
|
3155
3075
|
drawParticles(delta) {
|
|
3156
|
-
const { particles } = this
|
|
3076
|
+
const { particles } = this.#container;
|
|
3157
3077
|
this.clear();
|
|
3158
3078
|
particles.update(delta);
|
|
3159
3079
|
this.draw(ctx => {
|
|
3160
|
-
for (const plugin of this
|
|
3080
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
3161
3081
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
3162
3082
|
}
|
|
3163
|
-
for (const plugin of this
|
|
3083
|
+
for (const plugin of this.#drawPlugins) {
|
|
3164
3084
|
plugin.draw?.(ctx, delta);
|
|
3165
3085
|
}
|
|
3166
3086
|
particles.drawParticles(delta);
|
|
3167
|
-
for (const plugin of this
|
|
3087
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
3168
3088
|
plugin.clearDraw?.(ctx, delta);
|
|
3169
3089
|
}
|
|
3170
|
-
for (const plugin of this
|
|
3090
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
3171
3091
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
3172
3092
|
}
|
|
3173
3093
|
});
|
|
@@ -3178,64 +3098,64 @@
|
|
|
3178
3098
|
this.paint();
|
|
3179
3099
|
}
|
|
3180
3100
|
initPlugins() {
|
|
3181
|
-
this
|
|
3182
|
-
this
|
|
3183
|
-
this
|
|
3184
|
-
this
|
|
3185
|
-
this
|
|
3186
|
-
this
|
|
3187
|
-
this
|
|
3188
|
-
this
|
|
3189
|
-
this
|
|
3190
|
-
this
|
|
3191
|
-
for (const plugin of this.
|
|
3101
|
+
this.#colorPlugins = [];
|
|
3102
|
+
this.#canvasClearPlugins = [];
|
|
3103
|
+
this.#canvasPaintPlugins = [];
|
|
3104
|
+
this.#clearDrawPlugins = [];
|
|
3105
|
+
this.#drawParticlePlugins = [];
|
|
3106
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3107
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3108
|
+
this.#drawPlugins = [];
|
|
3109
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3110
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3111
|
+
for (const plugin of this.#container.plugins) {
|
|
3192
3112
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
3193
|
-
this.
|
|
3113
|
+
this.#colorPlugins.push(plugin);
|
|
3194
3114
|
}
|
|
3195
3115
|
if (plugin.canvasClear) {
|
|
3196
|
-
this.
|
|
3116
|
+
this.#canvasClearPlugins.push(plugin);
|
|
3197
3117
|
}
|
|
3198
3118
|
if (plugin.canvasPaint) {
|
|
3199
|
-
this.
|
|
3119
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
3200
3120
|
}
|
|
3201
3121
|
if (plugin.drawParticle) {
|
|
3202
|
-
this.
|
|
3122
|
+
this.#drawParticlePlugins.push(plugin);
|
|
3203
3123
|
}
|
|
3204
3124
|
if (plugin.drawParticleSetup) {
|
|
3205
|
-
this.
|
|
3125
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
3206
3126
|
}
|
|
3207
3127
|
if (plugin.drawParticleCleanup) {
|
|
3208
|
-
this.
|
|
3128
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
3209
3129
|
}
|
|
3210
3130
|
if (plugin.draw) {
|
|
3211
|
-
this.
|
|
3131
|
+
this.#drawPlugins.push(plugin);
|
|
3212
3132
|
}
|
|
3213
3133
|
if (plugin.drawSettingsSetup) {
|
|
3214
|
-
this.
|
|
3134
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
3215
3135
|
}
|
|
3216
3136
|
if (plugin.drawSettingsCleanup) {
|
|
3217
|
-
this.
|
|
3137
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
3218
3138
|
}
|
|
3219
3139
|
if (plugin.clearDraw) {
|
|
3220
|
-
this.
|
|
3140
|
+
this.#clearDrawPlugins.push(plugin);
|
|
3221
3141
|
}
|
|
3222
3142
|
}
|
|
3223
3143
|
}
|
|
3224
3144
|
initUpdaters() {
|
|
3225
|
-
this
|
|
3226
|
-
this
|
|
3227
|
-
for (const updater of this.
|
|
3145
|
+
this.#preDrawUpdaters = [];
|
|
3146
|
+
this.#postDrawUpdaters = [];
|
|
3147
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
3228
3148
|
if (updater.afterDraw) {
|
|
3229
|
-
this.
|
|
3149
|
+
this.#postDrawUpdaters.push(updater);
|
|
3230
3150
|
}
|
|
3231
3151
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
3232
|
-
this.
|
|
3152
|
+
this.#preDrawUpdaters.push(updater);
|
|
3233
3153
|
}
|
|
3234
3154
|
}
|
|
3235
3155
|
}
|
|
3236
3156
|
paint() {
|
|
3237
3157
|
let handled = false;
|
|
3238
|
-
for (const plugin of this
|
|
3158
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
3239
3159
|
handled = plugin.canvasPaint?.() ?? false;
|
|
3240
3160
|
if (handled) {
|
|
3241
3161
|
break;
|
|
@@ -3248,35 +3168,35 @@
|
|
|
3248
3168
|
}
|
|
3249
3169
|
paintBase(baseColor) {
|
|
3250
3170
|
this.draw(ctx => {
|
|
3251
|
-
paintBase(ctx, this.
|
|
3171
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
3252
3172
|
});
|
|
3253
3173
|
}
|
|
3254
3174
|
paintImage(image, opacity) {
|
|
3255
3175
|
this.draw(ctx => {
|
|
3256
|
-
paintImage(ctx, this.
|
|
3176
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
3257
3177
|
});
|
|
3258
3178
|
}
|
|
3259
3179
|
setContext(context) {
|
|
3260
|
-
this
|
|
3261
|
-
if (this
|
|
3262
|
-
this.
|
|
3180
|
+
this.#context = context;
|
|
3181
|
+
if (this.#context) {
|
|
3182
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
3263
3183
|
}
|
|
3264
3184
|
}
|
|
3265
3185
|
setContextSettings(settings) {
|
|
3266
|
-
this
|
|
3186
|
+
this.#contextSettings = settings;
|
|
3267
3187
|
}
|
|
3268
3188
|
stop() {
|
|
3269
3189
|
this.draw(ctx => {
|
|
3270
|
-
clear(ctx, this.
|
|
3190
|
+
clear(ctx, this.#canvasManager.size);
|
|
3271
3191
|
});
|
|
3272
3192
|
}
|
|
3273
|
-
|
|
3274
|
-
for (const updater of this
|
|
3193
|
+
#applyPostDrawUpdaters = particle => {
|
|
3194
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
3275
3195
|
updater.afterDraw?.(particle);
|
|
3276
3196
|
}
|
|
3277
3197
|
};
|
|
3278
|
-
|
|
3279
|
-
for (const updater of this
|
|
3198
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
3199
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
3280
3200
|
if (updater.getColorStyles) {
|
|
3281
3201
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
3282
3202
|
if (fill) {
|
|
@@ -3295,22 +3215,22 @@
|
|
|
3295
3215
|
updater.beforeDraw?.(particle);
|
|
3296
3216
|
}
|
|
3297
3217
|
};
|
|
3298
|
-
|
|
3218
|
+
#getPluginParticleColors = particle => {
|
|
3299
3219
|
let fColor, sColor;
|
|
3300
|
-
for (const plugin of this
|
|
3220
|
+
for (const plugin of this.#colorPlugins) {
|
|
3301
3221
|
if (!fColor && plugin.particleFillColor) {
|
|
3302
|
-
fColor = rangeColorToHsl(this
|
|
3222
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
3303
3223
|
}
|
|
3304
3224
|
if (!sColor && plugin.particleStrokeColor) {
|
|
3305
|
-
sColor = rangeColorToHsl(this
|
|
3225
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
3306
3226
|
}
|
|
3307
3227
|
if (fColor && sColor) {
|
|
3308
3228
|
break;
|
|
3309
3229
|
}
|
|
3310
3230
|
}
|
|
3311
|
-
this
|
|
3312
|
-
this
|
|
3313
|
-
return this
|
|
3231
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
3232
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
3233
|
+
return this.#reusablePluginColors;
|
|
3314
3234
|
};
|
|
3315
3235
|
}
|
|
3316
3236
|
|
|
@@ -3368,53 +3288,53 @@
|
|
|
3368
3288
|
renderCanvas;
|
|
3369
3289
|
size;
|
|
3370
3290
|
zoom = defaultZoom;
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3291
|
+
#container;
|
|
3292
|
+
#generated;
|
|
3293
|
+
#mutationObserver;
|
|
3294
|
+
#originalStyle;
|
|
3295
|
+
#pluginManager;
|
|
3296
|
+
#pointerEvents;
|
|
3297
|
+
#resizePlugins;
|
|
3298
|
+
#standardSize;
|
|
3299
|
+
#zoomCenter;
|
|
3380
3300
|
constructor(pluginManager, container) {
|
|
3381
|
-
this
|
|
3382
|
-
this
|
|
3301
|
+
this.#pluginManager = pluginManager;
|
|
3302
|
+
this.#container = container;
|
|
3383
3303
|
this.render = new RenderManager(pluginManager, container, this);
|
|
3384
|
-
this
|
|
3304
|
+
this.#standardSize = {
|
|
3385
3305
|
height: 0,
|
|
3386
3306
|
width: 0,
|
|
3387
3307
|
};
|
|
3388
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
3308
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
3389
3309
|
this.size = {
|
|
3390
3310
|
height: stdSize.height * pxRatio,
|
|
3391
3311
|
width: stdSize.width * pxRatio,
|
|
3392
3312
|
};
|
|
3393
|
-
this
|
|
3394
|
-
this
|
|
3395
|
-
this
|
|
3313
|
+
this.#generated = false;
|
|
3314
|
+
this.#resizePlugins = [];
|
|
3315
|
+
this.#pointerEvents = "none";
|
|
3396
3316
|
}
|
|
3397
|
-
get
|
|
3398
|
-
return this.
|
|
3317
|
+
get #fullScreen() {
|
|
3318
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
3399
3319
|
}
|
|
3400
3320
|
destroy() {
|
|
3401
3321
|
this.stop();
|
|
3402
|
-
if (this
|
|
3322
|
+
if (this.#generated) {
|
|
3403
3323
|
const element = this.domElement;
|
|
3404
3324
|
element?.remove();
|
|
3405
3325
|
this.domElement = undefined;
|
|
3406
3326
|
this.renderCanvas = undefined;
|
|
3407
3327
|
}
|
|
3408
3328
|
else {
|
|
3409
|
-
this
|
|
3329
|
+
this.#resetOriginalStyle();
|
|
3410
3330
|
}
|
|
3411
3331
|
this.render.destroy();
|
|
3412
|
-
this
|
|
3332
|
+
this.#resizePlugins = [];
|
|
3413
3333
|
}
|
|
3414
3334
|
getZoomCenter() {
|
|
3415
|
-
const pxRatio = this.
|
|
3416
|
-
if (this
|
|
3417
|
-
return this
|
|
3335
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
3336
|
+
if (this.#zoomCenter) {
|
|
3337
|
+
return this.#zoomCenter;
|
|
3418
3338
|
}
|
|
3419
3339
|
return {
|
|
3420
3340
|
x: (width * half) / pxRatio,
|
|
@@ -3422,20 +3342,20 @@
|
|
|
3422
3342
|
};
|
|
3423
3343
|
}
|
|
3424
3344
|
init() {
|
|
3425
|
-
this
|
|
3345
|
+
this.#safeMutationObserver(obs => {
|
|
3426
3346
|
obs.disconnect();
|
|
3427
3347
|
});
|
|
3428
|
-
this
|
|
3348
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
3429
3349
|
for (const record of records) {
|
|
3430
3350
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
3431
|
-
this
|
|
3351
|
+
this.#repairStyle();
|
|
3432
3352
|
}
|
|
3433
3353
|
}
|
|
3434
3354
|
});
|
|
3435
3355
|
this.resize();
|
|
3436
|
-
this
|
|
3356
|
+
this.#initStyle();
|
|
3437
3357
|
this.initBackground();
|
|
3438
|
-
this
|
|
3358
|
+
this.#safeMutationObserver(obs => {
|
|
3439
3359
|
const element = this.domElement;
|
|
3440
3360
|
if (!element || !(element instanceof Node)) {
|
|
3441
3361
|
return;
|
|
@@ -3446,13 +3366,13 @@
|
|
|
3446
3366
|
this.render.init();
|
|
3447
3367
|
}
|
|
3448
3368
|
initBackground() {
|
|
3449
|
-
const
|
|
3369
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
3450
3370
|
if (!element) {
|
|
3451
3371
|
return;
|
|
3452
3372
|
}
|
|
3453
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
3373
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
3454
3374
|
if (color) {
|
|
3455
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
3375
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
3456
3376
|
}
|
|
3457
3377
|
else {
|
|
3458
3378
|
elementStyle.backgroundColor = "";
|
|
@@ -3463,27 +3383,27 @@
|
|
|
3463
3383
|
elementStyle.backgroundSize = background.size || "";
|
|
3464
3384
|
}
|
|
3465
3385
|
initPlugins() {
|
|
3466
|
-
this
|
|
3467
|
-
for (const plugin of this.
|
|
3386
|
+
this.#resizePlugins = [];
|
|
3387
|
+
for (const plugin of this.#container.plugins) {
|
|
3468
3388
|
if (plugin.resize) {
|
|
3469
|
-
this.
|
|
3389
|
+
this.#resizePlugins.push(plugin);
|
|
3470
3390
|
}
|
|
3471
3391
|
}
|
|
3472
3392
|
}
|
|
3473
3393
|
loadCanvas(canvas) {
|
|
3474
|
-
if (this
|
|
3394
|
+
if (this.#generated && this.domElement) {
|
|
3475
3395
|
this.domElement.remove();
|
|
3476
3396
|
}
|
|
3477
|
-
const container = this
|
|
3397
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
3478
3398
|
this.domElement = domCanvas;
|
|
3479
|
-
this
|
|
3399
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
3480
3400
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
3481
3401
|
const domElement = this.domElement;
|
|
3482
3402
|
if (domElement) {
|
|
3483
3403
|
domElement.ariaHidden = "true";
|
|
3484
|
-
this
|
|
3404
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
3485
3405
|
}
|
|
3486
|
-
const standardSize = this
|
|
3406
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
3487
3407
|
if (domElement) {
|
|
3488
3408
|
standardSize.height = domElement.offsetHeight;
|
|
3489
3409
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -3492,7 +3412,7 @@
|
|
|
3492
3412
|
standardSize.height = renderCanvas.height;
|
|
3493
3413
|
standardSize.width = renderCanvas.width;
|
|
3494
3414
|
}
|
|
3495
|
-
const pxRatio = this.
|
|
3415
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
3496
3416
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
3497
3417
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
3498
3418
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -3503,12 +3423,12 @@
|
|
|
3503
3423
|
willReadFrequently: false,
|
|
3504
3424
|
});
|
|
3505
3425
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
3506
|
-
this
|
|
3426
|
+
this.#safeMutationObserver(obs => {
|
|
3507
3427
|
obs.disconnect();
|
|
3508
3428
|
});
|
|
3509
3429
|
container.retina.init();
|
|
3510
3430
|
this.initBackground();
|
|
3511
|
-
this
|
|
3431
|
+
this.#safeMutationObserver(obs => {
|
|
3512
3432
|
const element = this.domElement;
|
|
3513
3433
|
if (!element || !(element instanceof Node)) {
|
|
3514
3434
|
return;
|
|
@@ -3521,11 +3441,11 @@
|
|
|
3521
3441
|
if (!element) {
|
|
3522
3442
|
return false;
|
|
3523
3443
|
}
|
|
3524
|
-
const container = this
|
|
3444
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
3525
3445
|
if (renderCanvas === undefined) {
|
|
3526
3446
|
return false;
|
|
3527
3447
|
}
|
|
3528
|
-
const currentSize = container.canvas
|
|
3448
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
3529
3449
|
width: element.offsetWidth,
|
|
3530
3450
|
height: element.offsetHeight,
|
|
3531
3451
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -3544,7 +3464,7 @@
|
|
|
3544
3464
|
const canvasSize = this.size;
|
|
3545
3465
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
3546
3466
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
3547
|
-
if (this.
|
|
3467
|
+
if (this.#container.started) {
|
|
3548
3468
|
container.particles.setResizeFactor({
|
|
3549
3469
|
width: currentSize.width / oldSize.width,
|
|
3550
3470
|
height: currentSize.height / oldSize.height,
|
|
@@ -3557,46 +3477,46 @@
|
|
|
3557
3477
|
if (!element) {
|
|
3558
3478
|
return;
|
|
3559
3479
|
}
|
|
3560
|
-
this
|
|
3561
|
-
this
|
|
3480
|
+
this.#pointerEvents = type;
|
|
3481
|
+
this.#repairStyle();
|
|
3562
3482
|
}
|
|
3563
3483
|
setZoom(zoomLevel, center) {
|
|
3564
3484
|
this.zoom = zoomLevel;
|
|
3565
|
-
this
|
|
3485
|
+
this.#zoomCenter = center;
|
|
3566
3486
|
}
|
|
3567
3487
|
stop() {
|
|
3568
|
-
this
|
|
3488
|
+
this.#safeMutationObserver(obs => {
|
|
3569
3489
|
obs.disconnect();
|
|
3570
3490
|
});
|
|
3571
|
-
this
|
|
3491
|
+
this.#mutationObserver = undefined;
|
|
3572
3492
|
this.render.stop();
|
|
3573
3493
|
}
|
|
3574
3494
|
async windowResize() {
|
|
3575
3495
|
if (!this.domElement || !this.resize()) {
|
|
3576
3496
|
return;
|
|
3577
3497
|
}
|
|
3578
|
-
const container = this
|
|
3498
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
3579
3499
|
container.particles.setDensity();
|
|
3580
|
-
this
|
|
3500
|
+
this.#applyResizePlugins();
|
|
3581
3501
|
if (needsRefresh) {
|
|
3582
3502
|
await container.refresh();
|
|
3583
3503
|
}
|
|
3584
3504
|
}
|
|
3585
|
-
|
|
3586
|
-
for (const plugin of this
|
|
3505
|
+
#applyResizePlugins = () => {
|
|
3506
|
+
for (const plugin of this.#resizePlugins) {
|
|
3587
3507
|
plugin.resize?.();
|
|
3588
3508
|
}
|
|
3589
3509
|
};
|
|
3590
|
-
|
|
3591
|
-
const element = this.domElement, options = this.
|
|
3510
|
+
#initStyle = () => {
|
|
3511
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
3592
3512
|
if (!element) {
|
|
3593
3513
|
return;
|
|
3594
3514
|
}
|
|
3595
|
-
if (this
|
|
3596
|
-
this
|
|
3515
|
+
if (this.#fullScreen) {
|
|
3516
|
+
this.#setFullScreenStyle();
|
|
3597
3517
|
}
|
|
3598
3518
|
else {
|
|
3599
|
-
this
|
|
3519
|
+
this.#resetOriginalStyle();
|
|
3600
3520
|
}
|
|
3601
3521
|
for (const key in options.style) {
|
|
3602
3522
|
if (!key || !(key in options.style)) {
|
|
@@ -3609,72 +3529,72 @@
|
|
|
3609
3529
|
element.style.setProperty(key, value, "important");
|
|
3610
3530
|
}
|
|
3611
3531
|
};
|
|
3612
|
-
|
|
3532
|
+
#repairStyle = () => {
|
|
3613
3533
|
const element = this.domElement;
|
|
3614
3534
|
if (!element) {
|
|
3615
3535
|
return;
|
|
3616
3536
|
}
|
|
3617
|
-
this
|
|
3537
|
+
this.#safeMutationObserver(observer => {
|
|
3618
3538
|
observer.disconnect();
|
|
3619
3539
|
});
|
|
3620
|
-
this
|
|
3540
|
+
this.#initStyle();
|
|
3621
3541
|
this.initBackground();
|
|
3622
|
-
const pointerEvents = this
|
|
3542
|
+
const pointerEvents = this.#pointerEvents;
|
|
3623
3543
|
element.style.pointerEvents = pointerEvents;
|
|
3624
3544
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
3625
|
-
this
|
|
3545
|
+
this.#safeMutationObserver(observer => {
|
|
3626
3546
|
if (!(element instanceof Node)) {
|
|
3627
3547
|
return;
|
|
3628
3548
|
}
|
|
3629
3549
|
observer.observe(element, { attributes: true });
|
|
3630
3550
|
});
|
|
3631
3551
|
};
|
|
3632
|
-
|
|
3633
|
-
const element = this.domElement, originalStyle = this
|
|
3552
|
+
#resetOriginalStyle = () => {
|
|
3553
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
3634
3554
|
if (!element || !originalStyle) {
|
|
3635
3555
|
return;
|
|
3636
3556
|
}
|
|
3637
3557
|
setStyle(element, originalStyle, true);
|
|
3638
3558
|
};
|
|
3639
|
-
|
|
3640
|
-
if (!this
|
|
3559
|
+
#safeMutationObserver = callback => {
|
|
3560
|
+
if (!this.#mutationObserver) {
|
|
3641
3561
|
return;
|
|
3642
3562
|
}
|
|
3643
|
-
callback(this
|
|
3563
|
+
callback(this.#mutationObserver);
|
|
3644
3564
|
};
|
|
3645
|
-
|
|
3565
|
+
#setFullScreenStyle = () => {
|
|
3646
3566
|
const element = this.domElement;
|
|
3647
3567
|
if (!element) {
|
|
3648
3568
|
return;
|
|
3649
3569
|
}
|
|
3650
|
-
setStyle(element, getFullScreenStyle(this.
|
|
3570
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
3651
3571
|
};
|
|
3652
3572
|
}
|
|
3653
3573
|
|
|
3654
3574
|
class EventListeners {
|
|
3655
|
-
container;
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3575
|
+
#container;
|
|
3576
|
+
#handlers;
|
|
3577
|
+
#resizeObserver;
|
|
3578
|
+
#resizeTimeout;
|
|
3659
3579
|
constructor(container) {
|
|
3660
|
-
this
|
|
3661
|
-
this
|
|
3580
|
+
this.#container = container;
|
|
3581
|
+
this.#handlers = {
|
|
3662
3582
|
visibilityChange: () => {
|
|
3663
|
-
this
|
|
3583
|
+
this.#handleVisibilityChange();
|
|
3664
3584
|
},
|
|
3665
3585
|
resize: () => {
|
|
3666
|
-
this
|
|
3586
|
+
this.#handleWindowResize();
|
|
3667
3587
|
},
|
|
3668
3588
|
};
|
|
3669
3589
|
}
|
|
3670
3590
|
addListeners() {
|
|
3671
|
-
this
|
|
3591
|
+
this.#manageListeners(true);
|
|
3672
3592
|
}
|
|
3673
3593
|
removeListeners() {
|
|
3674
|
-
this
|
|
3594
|
+
this.#manageListeners(false);
|
|
3675
3595
|
}
|
|
3676
|
-
|
|
3677
|
-
const container = this
|
|
3596
|
+
#handleVisibilityChange = () => {
|
|
3597
|
+
const container = this.#container, options = container.actualOptions;
|
|
3678
3598
|
if (!options.pauseOnBlur) {
|
|
3679
3599
|
return;
|
|
3680
3600
|
}
|
|
@@ -3692,24 +3612,24 @@
|
|
|
3692
3612
|
}
|
|
3693
3613
|
}
|
|
3694
3614
|
};
|
|
3695
|
-
|
|
3696
|
-
if (this
|
|
3697
|
-
clearTimeout(this
|
|
3698
|
-
|
|
3615
|
+
#handleWindowResize = () => {
|
|
3616
|
+
if (this.#resizeTimeout) {
|
|
3617
|
+
clearTimeout(this.#resizeTimeout);
|
|
3618
|
+
this.#resizeTimeout = undefined;
|
|
3699
3619
|
}
|
|
3700
3620
|
const handleResize = async () => {
|
|
3701
|
-
const canvas = this
|
|
3621
|
+
const canvas = this.#container.canvas;
|
|
3702
3622
|
await canvas.windowResize();
|
|
3703
3623
|
};
|
|
3704
|
-
this
|
|
3624
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
3705
3625
|
};
|
|
3706
|
-
|
|
3707
|
-
const handlers = this
|
|
3708
|
-
this
|
|
3626
|
+
#manageListeners = add => {
|
|
3627
|
+
const handlers = this.#handlers;
|
|
3628
|
+
this.#manageResize(add);
|
|
3709
3629
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
3710
3630
|
};
|
|
3711
|
-
|
|
3712
|
-
const handlers = this
|
|
3631
|
+
#manageResize = add => {
|
|
3632
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
3713
3633
|
if (!options.resize.enable) {
|
|
3714
3634
|
return;
|
|
3715
3635
|
}
|
|
@@ -3718,22 +3638,22 @@
|
|
|
3718
3638
|
return;
|
|
3719
3639
|
}
|
|
3720
3640
|
const canvasEl = container.canvas.domElement;
|
|
3721
|
-
if (this
|
|
3641
|
+
if (this.#resizeObserver && !add) {
|
|
3722
3642
|
if (canvasEl) {
|
|
3723
|
-
this.
|
|
3643
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
3724
3644
|
}
|
|
3725
|
-
this.
|
|
3726
|
-
|
|
3645
|
+
this.#resizeObserver.disconnect();
|
|
3646
|
+
this.#resizeObserver = undefined;
|
|
3727
3647
|
}
|
|
3728
|
-
else if (!this
|
|
3729
|
-
this
|
|
3648
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
3649
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
3730
3650
|
const entry = entries.find(e => e.target === canvasEl);
|
|
3731
3651
|
if (!entry) {
|
|
3732
3652
|
return;
|
|
3733
3653
|
}
|
|
3734
|
-
this
|
|
3654
|
+
this.#handleWindowResize();
|
|
3735
3655
|
});
|
|
3736
|
-
this.
|
|
3656
|
+
this.#resizeObserver.observe(canvasEl);
|
|
3737
3657
|
}
|
|
3738
3658
|
};
|
|
3739
3659
|
}
|
|
@@ -3806,24 +3726,24 @@
|
|
|
3806
3726
|
unbreakable;
|
|
3807
3727
|
velocity;
|
|
3808
3728
|
zIndexFactor;
|
|
3809
|
-
|
|
3729
|
+
#cachedOpacityData = {
|
|
3810
3730
|
fillOpacity: defaultOpacity,
|
|
3811
3731
|
opacity: defaultOpacity,
|
|
3812
3732
|
strokeOpacity: defaultOpacity,
|
|
3813
3733
|
};
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3734
|
+
#cachedPosition = Vector3d.origin;
|
|
3735
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
3736
|
+
#cachedTransform = {
|
|
3817
3737
|
a: 1,
|
|
3818
3738
|
b: 0,
|
|
3819
3739
|
c: 0,
|
|
3820
3740
|
d: 1,
|
|
3821
3741
|
};
|
|
3822
|
-
|
|
3823
|
-
|
|
3742
|
+
#container;
|
|
3743
|
+
#pluginManager;
|
|
3824
3744
|
constructor(pluginManager, container) {
|
|
3825
|
-
this
|
|
3826
|
-
this
|
|
3745
|
+
this.#pluginManager = pluginManager;
|
|
3746
|
+
this.#container = container;
|
|
3827
3747
|
}
|
|
3828
3748
|
destroy(override) {
|
|
3829
3749
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -3832,7 +3752,7 @@
|
|
|
3832
3752
|
this.destroyed = true;
|
|
3833
3753
|
this.bubble.inRange = false;
|
|
3834
3754
|
this.slow.inRange = false;
|
|
3835
|
-
const container = this
|
|
3755
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
3836
3756
|
shapeDrawer?.particleDestroy?.(this);
|
|
3837
3757
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
3838
3758
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -3840,12 +3760,12 @@
|
|
|
3840
3760
|
for (const updater of container.particleUpdaters) {
|
|
3841
3761
|
updater.particleDestroyed?.(this, override);
|
|
3842
3762
|
}
|
|
3843
|
-
this.
|
|
3763
|
+
this.#container.dispatchEvent(exports.EventType.particleDestroyed, {
|
|
3844
3764
|
particle: this,
|
|
3845
3765
|
});
|
|
3846
3766
|
}
|
|
3847
3767
|
draw(delta) {
|
|
3848
|
-
const container = this
|
|
3768
|
+
const container = this.#container, render = container.canvas.render;
|
|
3849
3769
|
render.drawParticlePlugins(this, delta);
|
|
3850
3770
|
render.drawParticle(this, delta);
|
|
3851
3771
|
}
|
|
@@ -3853,50 +3773,50 @@
|
|
|
3853
3773
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
3854
3774
|
}
|
|
3855
3775
|
getFillColor() {
|
|
3856
|
-
return this
|
|
3776
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
3857
3777
|
}
|
|
3858
3778
|
getMass() {
|
|
3859
3779
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
3860
3780
|
}
|
|
3861
3781
|
getOpacity() {
|
|
3862
3782
|
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? getRangeValue(this.opacity?.value ?? defaultOpacity), fillOpacity = this.fillOpacity ?? defaultOpacity, strokeOpacity = this.strokeOpacity ?? defaultOpacity;
|
|
3863
|
-
this.
|
|
3864
|
-
this.
|
|
3865
|
-
this.
|
|
3866
|
-
return this
|
|
3783
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
3784
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
3785
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
3786
|
+
return this.#cachedOpacityData;
|
|
3867
3787
|
}
|
|
3868
3788
|
getPosition() {
|
|
3869
|
-
this.
|
|
3870
|
-
this.
|
|
3871
|
-
this.
|
|
3872
|
-
return this
|
|
3789
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
3790
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
3791
|
+
this.#cachedPosition.z = this.position.z;
|
|
3792
|
+
return this.#cachedPosition;
|
|
3873
3793
|
}
|
|
3874
3794
|
getRadius() {
|
|
3875
3795
|
return this.bubble.radius ?? this.size.value;
|
|
3876
3796
|
}
|
|
3877
3797
|
getRotateData() {
|
|
3878
3798
|
const angle = this.getAngle();
|
|
3879
|
-
this.
|
|
3880
|
-
this.
|
|
3881
|
-
return this
|
|
3799
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
3800
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
3801
|
+
return this.#cachedRotateData;
|
|
3882
3802
|
}
|
|
3883
3803
|
getStrokeColor() {
|
|
3884
|
-
return this
|
|
3804
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
3885
3805
|
}
|
|
3886
3806
|
getTransformData(externalTransform) {
|
|
3887
3807
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
3888
|
-
this.
|
|
3889
|
-
this.
|
|
3808
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
3809
|
+
this.#cachedTransform.b = rotating
|
|
3890
3810
|
? rotateData.sin * (externalTransform.b ?? identity)
|
|
3891
3811
|
: (externalTransform.b ?? defaultTransform.b);
|
|
3892
|
-
this.
|
|
3812
|
+
this.#cachedTransform.c = rotating
|
|
3893
3813
|
? -rotateData.sin * (externalTransform.c ?? identity)
|
|
3894
3814
|
: (externalTransform.c ?? defaultTransform.c);
|
|
3895
|
-
this.
|
|
3896
|
-
return this
|
|
3815
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
3816
|
+
return this.#cachedTransform;
|
|
3897
3817
|
}
|
|
3898
3818
|
init(id, position, overrideOptions, group) {
|
|
3899
|
-
const container = this
|
|
3819
|
+
const container = this.#container;
|
|
3900
3820
|
this.id = id;
|
|
3901
3821
|
this.group = group;
|
|
3902
3822
|
this.justWarped = false;
|
|
@@ -3916,21 +3836,27 @@
|
|
|
3916
3836
|
moveSpeed: 0,
|
|
3917
3837
|
sizeAnimationSpeed: 0,
|
|
3918
3838
|
};
|
|
3839
|
+
this.size = {
|
|
3840
|
+
value: 1,
|
|
3841
|
+
max: 1,
|
|
3842
|
+
min: 1,
|
|
3843
|
+
enable: false,
|
|
3844
|
+
};
|
|
3919
3845
|
this.outType = exports.ParticleOutType.normal;
|
|
3920
3846
|
this.ignoresResizeRatio = true;
|
|
3921
|
-
const
|
|
3847
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
3922
3848
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
3923
3849
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
3924
3850
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
3925
3851
|
if (overrideOptions) {
|
|
3926
|
-
if (overrideOptions.effect?.type) {
|
|
3852
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
3927
3853
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
3928
3854
|
if (effect) {
|
|
3929
3855
|
this.effect = effect;
|
|
3930
3856
|
effectOptions.load(overrideOptions.effect);
|
|
3931
3857
|
}
|
|
3932
3858
|
}
|
|
3933
|
-
if (overrideOptions.shape?.type) {
|
|
3859
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
3934
3860
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
3935
3861
|
if (shape) {
|
|
3936
3862
|
this.shape = shape;
|
|
@@ -3939,21 +3865,20 @@
|
|
|
3939
3865
|
}
|
|
3940
3866
|
}
|
|
3941
3867
|
if (this.effect === randomColorValue) {
|
|
3942
|
-
const availableEffects = [...this.
|
|
3868
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
3943
3869
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
3944
3870
|
}
|
|
3945
3871
|
if (this.shape === randomColorValue) {
|
|
3946
|
-
const availableShapes = [...this.
|
|
3872
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
3947
3873
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
3948
3874
|
}
|
|
3949
3875
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
3950
3876
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
3951
3877
|
particlesOptions.load(overrideOptions);
|
|
3952
|
-
const effectData = this.effectData;
|
|
3878
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
3953
3879
|
if (effectData) {
|
|
3954
3880
|
particlesOptions.load(effectData.particles);
|
|
3955
3881
|
}
|
|
3956
|
-
const shapeData = this.shapeData;
|
|
3957
3882
|
if (shapeData) {
|
|
3958
3883
|
particlesOptions.load(shapeData.particles);
|
|
3959
3884
|
}
|
|
@@ -3961,7 +3886,9 @@
|
|
|
3961
3886
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
3962
3887
|
this.options = particlesOptions;
|
|
3963
3888
|
container.retina.initParticle(this);
|
|
3964
|
-
|
|
3889
|
+
for (const updater of container.particleUpdaters) {
|
|
3890
|
+
updater.preInit?.(this);
|
|
3891
|
+
}
|
|
3965
3892
|
this.bubble = {
|
|
3966
3893
|
inRange: false,
|
|
3967
3894
|
};
|
|
@@ -3969,8 +3896,8 @@
|
|
|
3969
3896
|
inRange: false,
|
|
3970
3897
|
factor: 1,
|
|
3971
3898
|
};
|
|
3972
|
-
this
|
|
3973
|
-
this.initialVelocity = this
|
|
3899
|
+
this.#initPosition(position);
|
|
3900
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
3974
3901
|
this.velocity = this.initialVelocity.copy();
|
|
3975
3902
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
3976
3903
|
this.sides = 24;
|
|
@@ -4001,12 +3928,11 @@
|
|
|
4001
3928
|
plugin.particleCreated?.(this);
|
|
4002
3929
|
}
|
|
4003
3930
|
}
|
|
4004
|
-
isInsideCanvas() {
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
position.x <= canvasSize.width + radius);
|
|
3931
|
+
isInsideCanvas(direction) {
|
|
3932
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
3933
|
+
}
|
|
3934
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
3935
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
4010
3936
|
}
|
|
4011
3937
|
isShowingBack() {
|
|
4012
3938
|
if (!this.roll) {
|
|
@@ -4031,13 +3957,13 @@
|
|
|
4031
3957
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
4032
3958
|
}
|
|
4033
3959
|
reset() {
|
|
4034
|
-
for (const updater of this.
|
|
3960
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4035
3961
|
updater.reset?.(this);
|
|
4036
3962
|
}
|
|
4037
3963
|
}
|
|
4038
|
-
|
|
3964
|
+
#calcPosition = (position, zIndex) => {
|
|
4039
3965
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
4040
|
-
const container = this
|
|
3966
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
4041
3967
|
while (!signal.aborted) {
|
|
4042
3968
|
for (const plugin of plugins) {
|
|
4043
3969
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -4049,10 +3975,10 @@
|
|
|
4049
3975
|
size: canvasSize,
|
|
4050
3976
|
position: posVec,
|
|
4051
3977
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
4052
|
-
this
|
|
4053
|
-
this
|
|
4054
|
-
this
|
|
4055
|
-
this
|
|
3978
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
3979
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
3980
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
3981
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
4056
3982
|
let isValidPosition = true;
|
|
4057
3983
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
4058
3984
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -4068,8 +3994,8 @@
|
|
|
4068
3994
|
}
|
|
4069
3995
|
return posVec;
|
|
4070
3996
|
};
|
|
4071
|
-
|
|
4072
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
3997
|
+
#calculateVelocity = () => {
|
|
3998
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
4073
3999
|
if (moveOptions.direction === exports.MoveDirection.inside || moveOptions.direction === exports.MoveDirection.outside) {
|
|
4074
4000
|
return res;
|
|
4075
4001
|
}
|
|
@@ -4085,27 +4011,86 @@
|
|
|
4085
4011
|
}
|
|
4086
4012
|
return res;
|
|
4087
4013
|
};
|
|
4088
|
-
|
|
4014
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
4089
4015
|
fixOutMode({
|
|
4090
4016
|
outMode,
|
|
4091
4017
|
checkModes: [exports.OutMode.bounce],
|
|
4092
4018
|
coord: pos.x,
|
|
4093
|
-
maxCoord: this.
|
|
4019
|
+
maxCoord: this.#container.canvas.size.width,
|
|
4094
4020
|
setCb: (value) => (pos.x += value),
|
|
4095
4021
|
radius,
|
|
4096
4022
|
});
|
|
4097
4023
|
};
|
|
4098
|
-
|
|
4024
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
4099
4025
|
fixOutMode({
|
|
4100
4026
|
outMode,
|
|
4101
4027
|
checkModes: [exports.OutMode.bounce],
|
|
4102
4028
|
coord: pos.y,
|
|
4103
|
-
maxCoord: this.
|
|
4029
|
+
maxCoord: this.#container.canvas.size.height,
|
|
4104
4030
|
setCb: (value) => (pos.y += value),
|
|
4105
4031
|
radius,
|
|
4106
4032
|
});
|
|
4107
4033
|
};
|
|
4108
|
-
|
|
4034
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
4035
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === exports.OutMode.bounce;
|
|
4036
|
+
if (direction === exports.OutModeDirection.bottom) {
|
|
4037
|
+
return {
|
|
4038
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
4039
|
+
reason: "default",
|
|
4040
|
+
};
|
|
4041
|
+
}
|
|
4042
|
+
if (direction === exports.OutModeDirection.left) {
|
|
4043
|
+
return {
|
|
4044
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
4045
|
+
reason: "default",
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
4048
|
+
if (direction === exports.OutModeDirection.right) {
|
|
4049
|
+
return {
|
|
4050
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
4051
|
+
reason: "default",
|
|
4052
|
+
};
|
|
4053
|
+
}
|
|
4054
|
+
if (direction === exports.OutModeDirection.top) {
|
|
4055
|
+
return {
|
|
4056
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
4057
|
+
reason: "default",
|
|
4058
|
+
};
|
|
4059
|
+
}
|
|
4060
|
+
return {
|
|
4061
|
+
inside: position.x >= -radius &&
|
|
4062
|
+
position.y >= -radius &&
|
|
4063
|
+
position.y <= canvasSize.height + radius &&
|
|
4064
|
+
position.x <= canvasSize.width + radius,
|
|
4065
|
+
reason: "default",
|
|
4066
|
+
};
|
|
4067
|
+
};
|
|
4068
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
4069
|
+
return {
|
|
4070
|
+
canvasSize: this.#container.canvas.size,
|
|
4071
|
+
direction,
|
|
4072
|
+
outMode,
|
|
4073
|
+
particle: this,
|
|
4074
|
+
radius: this.getRadius(),
|
|
4075
|
+
};
|
|
4076
|
+
};
|
|
4077
|
+
#getInsideCanvasResult = (data) => {
|
|
4078
|
+
const defaultResult = this.#getDefaultInsideCanvasResult(data.direction, data.outMode), container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined, effectDrawer = this.effect ? container.effectDrawers.get(this.effect) : undefined, shapeCheck = shapeDrawer?.isInsideCanvas, effectCheck = effectDrawer?.isInsideCanvas;
|
|
4079
|
+
if (!shapeCheck && !effectCheck) {
|
|
4080
|
+
return defaultResult;
|
|
4081
|
+
}
|
|
4082
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
4083
|
+
if (shapeResult && effectResult) {
|
|
4084
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
4085
|
+
return {
|
|
4086
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
4087
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
4088
|
+
reason: "combined",
|
|
4089
|
+
};
|
|
4090
|
+
}
|
|
4091
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
4092
|
+
};
|
|
4093
|
+
#getRollColor = color => {
|
|
4109
4094
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
4110
4095
|
return color;
|
|
4111
4096
|
}
|
|
@@ -4120,8 +4105,8 @@
|
|
|
4120
4105
|
}
|
|
4121
4106
|
return color;
|
|
4122
4107
|
};
|
|
4123
|
-
|
|
4124
|
-
const container = this
|
|
4108
|
+
#initPosition = position => {
|
|
4109
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
4125
4110
|
if (!initialPosition) {
|
|
4126
4111
|
throw new Error("a valid position cannot be found for particle");
|
|
4127
4112
|
}
|
|
@@ -4144,45 +4129,58 @@
|
|
|
4144
4129
|
}
|
|
4145
4130
|
this.offset = Vector.origin;
|
|
4146
4131
|
};
|
|
4132
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
4133
|
+
if (typeof result === "boolean") {
|
|
4134
|
+
return {
|
|
4135
|
+
inside: result,
|
|
4136
|
+
reason,
|
|
4137
|
+
};
|
|
4138
|
+
}
|
|
4139
|
+
return {
|
|
4140
|
+
inside: result.inside,
|
|
4141
|
+
margin: result.margin,
|
|
4142
|
+
reason: result.reason ?? reason,
|
|
4143
|
+
};
|
|
4144
|
+
};
|
|
4147
4145
|
}
|
|
4148
4146
|
|
|
4149
4147
|
class SpatialHashGrid {
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4148
|
+
#cellSize;
|
|
4149
|
+
#cells = new Map();
|
|
4150
|
+
#circlePool = [];
|
|
4151
|
+
#circlePoolIdx;
|
|
4152
|
+
#pendingCellSize;
|
|
4153
|
+
#rectanglePool = [];
|
|
4154
|
+
#rectanglePoolIdx;
|
|
4157
4155
|
constructor(cellSize) {
|
|
4158
|
-
this
|
|
4159
|
-
this
|
|
4160
|
-
this
|
|
4156
|
+
this.#cellSize = cellSize;
|
|
4157
|
+
this.#circlePoolIdx = 0;
|
|
4158
|
+
this.#rectanglePoolIdx = 0;
|
|
4161
4159
|
}
|
|
4162
4160
|
clear() {
|
|
4163
|
-
this.
|
|
4164
|
-
const pendingCellSize = this
|
|
4161
|
+
this.#cells.clear();
|
|
4162
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
4165
4163
|
if (pendingCellSize) {
|
|
4166
|
-
this
|
|
4164
|
+
this.#cellSize = pendingCellSize;
|
|
4167
4165
|
}
|
|
4168
|
-
this
|
|
4166
|
+
this.#pendingCellSize = undefined;
|
|
4169
4167
|
}
|
|
4170
4168
|
insert(particle) {
|
|
4171
|
-
const { x, y } = particle.getPosition(), key = this
|
|
4172
|
-
if (!this.
|
|
4173
|
-
this.
|
|
4169
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
4170
|
+
if (!this.#cells.has(key)) {
|
|
4171
|
+
this.#cells.set(key, []);
|
|
4174
4172
|
}
|
|
4175
|
-
this.
|
|
4173
|
+
this.#cells.get(key)?.push(particle);
|
|
4176
4174
|
}
|
|
4177
4175
|
query(range, check, out = []) {
|
|
4178
|
-
const bounds = this
|
|
4176
|
+
const bounds = this.#getRangeBounds(range);
|
|
4179
4177
|
if (!bounds) {
|
|
4180
4178
|
return out;
|
|
4181
4179
|
}
|
|
4182
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
4180
|
+
const minCellX = Math.floor(bounds.minX / this.#cellSize), maxCellX = Math.floor(bounds.maxX / this.#cellSize), minCellY = Math.floor(bounds.minY / this.#cellSize), maxCellY = Math.floor(bounds.maxY / this.#cellSize);
|
|
4183
4181
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
4184
4182
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
4185
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
4183
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
4186
4184
|
if (!cellParticles) {
|
|
4187
4185
|
continue;
|
|
4188
4186
|
}
|
|
@@ -4199,29 +4197,29 @@
|
|
|
4199
4197
|
return out;
|
|
4200
4198
|
}
|
|
4201
4199
|
queryCircle(position, radius, check, out = []) {
|
|
4202
|
-
const circle = this
|
|
4203
|
-
this
|
|
4200
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
4201
|
+
this.#releaseShapes();
|
|
4204
4202
|
return result;
|
|
4205
4203
|
}
|
|
4206
4204
|
queryRectangle(position, size, check, out = []) {
|
|
4207
|
-
const rect = this
|
|
4208
|
-
this
|
|
4205
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
4206
|
+
this.#releaseShapes();
|
|
4209
4207
|
return result;
|
|
4210
4208
|
}
|
|
4211
4209
|
setCellSize(cellSize) {
|
|
4212
|
-
this
|
|
4210
|
+
this.#pendingCellSize = cellSize;
|
|
4213
4211
|
}
|
|
4214
|
-
|
|
4215
|
-
return (this
|
|
4212
|
+
#acquireCircle(x, y, r) {
|
|
4213
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
4216
4214
|
}
|
|
4217
|
-
|
|
4218
|
-
return (this
|
|
4215
|
+
#acquireRectangle(x, y, w, h) {
|
|
4216
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
4219
4217
|
}
|
|
4220
|
-
|
|
4221
|
-
const cellX = Math.floor(x / this
|
|
4218
|
+
#cellKeyFromCoords(x, y) {
|
|
4219
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
4222
4220
|
return `${cellX}_${cellY}`;
|
|
4223
4221
|
}
|
|
4224
|
-
|
|
4222
|
+
#getRangeBounds(range) {
|
|
4225
4223
|
if (range instanceof Circle) {
|
|
4226
4224
|
const r = range.radius, { x, y } = range.position;
|
|
4227
4225
|
return {
|
|
@@ -4242,53 +4240,53 @@
|
|
|
4242
4240
|
}
|
|
4243
4241
|
return null;
|
|
4244
4242
|
}
|
|
4245
|
-
|
|
4246
|
-
this
|
|
4247
|
-
this
|
|
4243
|
+
#releaseShapes() {
|
|
4244
|
+
this.#circlePoolIdx = 0;
|
|
4245
|
+
this.#rectanglePoolIdx = 0;
|
|
4248
4246
|
}
|
|
4249
4247
|
}
|
|
4250
4248
|
|
|
4251
4249
|
class ParticlesManager {
|
|
4252
4250
|
checkParticlePositionPlugins;
|
|
4253
4251
|
grid;
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4252
|
+
#array;
|
|
4253
|
+
#container;
|
|
4254
|
+
#groupLimits;
|
|
4255
|
+
#limit;
|
|
4256
|
+
#nextId;
|
|
4257
|
+
#particleBuckets;
|
|
4258
|
+
#particleResetPlugins;
|
|
4259
|
+
#particleUpdatePlugins;
|
|
4260
|
+
#pluginManager;
|
|
4261
|
+
#pool;
|
|
4262
|
+
#postParticleUpdatePlugins;
|
|
4263
|
+
#postUpdatePlugins;
|
|
4264
|
+
#resizeFactor;
|
|
4265
|
+
#updatePlugins;
|
|
4266
|
+
#zBuckets;
|
|
4269
4267
|
constructor(pluginManager, container) {
|
|
4270
|
-
this
|
|
4271
|
-
this
|
|
4272
|
-
this
|
|
4273
|
-
this
|
|
4274
|
-
this
|
|
4275
|
-
this
|
|
4276
|
-
this
|
|
4277
|
-
this
|
|
4278
|
-
this
|
|
4268
|
+
this.#pluginManager = pluginManager;
|
|
4269
|
+
this.#container = container;
|
|
4270
|
+
this.#nextId = 0;
|
|
4271
|
+
this.#array = [];
|
|
4272
|
+
this.#pool = [];
|
|
4273
|
+
this.#limit = 0;
|
|
4274
|
+
this.#groupLimits = new Map();
|
|
4275
|
+
this.#particleBuckets = new Map();
|
|
4276
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
4279
4277
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
4280
4278
|
this.checkParticlePositionPlugins = [];
|
|
4281
|
-
this
|
|
4282
|
-
this
|
|
4283
|
-
this
|
|
4284
|
-
this
|
|
4285
|
-
this
|
|
4279
|
+
this.#particleResetPlugins = [];
|
|
4280
|
+
this.#particleUpdatePlugins = [];
|
|
4281
|
+
this.#postUpdatePlugins = [];
|
|
4282
|
+
this.#postParticleUpdatePlugins = [];
|
|
4283
|
+
this.#updatePlugins = [];
|
|
4286
4284
|
}
|
|
4287
4285
|
get count() {
|
|
4288
|
-
return this.
|
|
4286
|
+
return this.#array.length;
|
|
4289
4287
|
}
|
|
4290
4288
|
addParticle(position, overrideOptions, group, initializer) {
|
|
4291
|
-
const limitMode = this.
|
|
4289
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
4292
4290
|
if (limit > minLimit) {
|
|
4293
4291
|
switch (limitMode) {
|
|
4294
4292
|
case exports.LimitMode.delete: {
|
|
@@ -4306,20 +4304,20 @@
|
|
|
4306
4304
|
}
|
|
4307
4305
|
}
|
|
4308
4306
|
try {
|
|
4309
|
-
const particle = this.
|
|
4310
|
-
particle.init(this
|
|
4307
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
4308
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
4311
4309
|
let canAdd = true;
|
|
4312
4310
|
if (initializer) {
|
|
4313
4311
|
canAdd = initializer(particle);
|
|
4314
4312
|
}
|
|
4315
4313
|
if (!canAdd) {
|
|
4316
|
-
this.
|
|
4314
|
+
this.#pool.push(particle);
|
|
4317
4315
|
return;
|
|
4318
4316
|
}
|
|
4319
|
-
this.
|
|
4320
|
-
this
|
|
4321
|
-
this
|
|
4322
|
-
this.
|
|
4317
|
+
this.#array.push(particle);
|
|
4318
|
+
this.#insertParticleIntoBucket(particle);
|
|
4319
|
+
this.#nextId++;
|
|
4320
|
+
this.#container.dispatchEvent(exports.EventType.particleAdded, {
|
|
4323
4321
|
particle,
|
|
4324
4322
|
});
|
|
4325
4323
|
return particle;
|
|
@@ -4330,25 +4328,25 @@
|
|
|
4330
4328
|
return undefined;
|
|
4331
4329
|
}
|
|
4332
4330
|
clear() {
|
|
4333
|
-
this
|
|
4334
|
-
this.
|
|
4335
|
-
this
|
|
4331
|
+
this.#array = [];
|
|
4332
|
+
this.#particleBuckets.clear();
|
|
4333
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
4336
4334
|
}
|
|
4337
4335
|
destroy() {
|
|
4338
|
-
this
|
|
4339
|
-
this.
|
|
4340
|
-
this.
|
|
4341
|
-
this
|
|
4336
|
+
this.#array = [];
|
|
4337
|
+
this.#pool.length = 0;
|
|
4338
|
+
this.#particleBuckets.clear();
|
|
4339
|
+
this.#zBuckets = [];
|
|
4342
4340
|
this.checkParticlePositionPlugins = [];
|
|
4343
|
-
this
|
|
4344
|
-
this
|
|
4345
|
-
this
|
|
4346
|
-
this
|
|
4347
|
-
this
|
|
4341
|
+
this.#particleResetPlugins = [];
|
|
4342
|
+
this.#particleUpdatePlugins = [];
|
|
4343
|
+
this.#postUpdatePlugins = [];
|
|
4344
|
+
this.#postParticleUpdatePlugins = [];
|
|
4345
|
+
this.#updatePlugins = [];
|
|
4348
4346
|
}
|
|
4349
4347
|
drawParticles(delta) {
|
|
4350
|
-
for (let i = this.
|
|
4351
|
-
const bucket = this
|
|
4348
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
4349
|
+
const bucket = this.#zBuckets[i];
|
|
4352
4350
|
if (!bucket) {
|
|
4353
4351
|
continue;
|
|
4354
4352
|
}
|
|
@@ -4358,24 +4356,24 @@
|
|
|
4358
4356
|
}
|
|
4359
4357
|
}
|
|
4360
4358
|
filter(condition) {
|
|
4361
|
-
return this.
|
|
4359
|
+
return this.#array.filter(condition);
|
|
4362
4360
|
}
|
|
4363
4361
|
find(condition) {
|
|
4364
|
-
return this.
|
|
4362
|
+
return this.#array.find(condition);
|
|
4365
4363
|
}
|
|
4366
4364
|
get(index) {
|
|
4367
|
-
return this
|
|
4365
|
+
return this.#array[index];
|
|
4368
4366
|
}
|
|
4369
4367
|
async init() {
|
|
4370
|
-
const container = this
|
|
4368
|
+
const container = this.#container, options = container.actualOptions;
|
|
4371
4369
|
this.checkParticlePositionPlugins = [];
|
|
4372
|
-
this
|
|
4373
|
-
this
|
|
4374
|
-
this
|
|
4375
|
-
this
|
|
4376
|
-
this
|
|
4377
|
-
this.
|
|
4378
|
-
this
|
|
4370
|
+
this.#updatePlugins = [];
|
|
4371
|
+
this.#particleUpdatePlugins = [];
|
|
4372
|
+
this.#postUpdatePlugins = [];
|
|
4373
|
+
this.#particleResetPlugins = [];
|
|
4374
|
+
this.#postParticleUpdatePlugins = [];
|
|
4375
|
+
this.#particleBuckets.clear();
|
|
4376
|
+
this.#resetBuckets(container.zLayers);
|
|
4379
4377
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
4380
4378
|
for (const plugin of container.plugins) {
|
|
4381
4379
|
if (plugin.redrawInit) {
|
|
@@ -4385,26 +4383,26 @@
|
|
|
4385
4383
|
this.checkParticlePositionPlugins.push(plugin);
|
|
4386
4384
|
}
|
|
4387
4385
|
if (plugin.update) {
|
|
4388
|
-
this.
|
|
4386
|
+
this.#updatePlugins.push(plugin);
|
|
4389
4387
|
}
|
|
4390
4388
|
if (plugin.particleUpdate) {
|
|
4391
|
-
this.
|
|
4389
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
4392
4390
|
}
|
|
4393
4391
|
if (plugin.postUpdate) {
|
|
4394
|
-
this.
|
|
4392
|
+
this.#postUpdatePlugins.push(plugin);
|
|
4395
4393
|
}
|
|
4396
4394
|
if (plugin.particleReset) {
|
|
4397
|
-
this.
|
|
4395
|
+
this.#particleResetPlugins.push(plugin);
|
|
4398
4396
|
}
|
|
4399
4397
|
if (plugin.postParticleUpdate) {
|
|
4400
|
-
this.
|
|
4398
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
4401
4399
|
}
|
|
4402
4400
|
}
|
|
4403
|
-
await this.
|
|
4404
|
-
for (const drawer of this.
|
|
4401
|
+
await this.#container.initDrawersAndUpdaters();
|
|
4402
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
4405
4403
|
await drawer.init?.(container);
|
|
4406
4404
|
}
|
|
4407
|
-
for (const drawer of this.
|
|
4405
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
4408
4406
|
await drawer.init?.(container);
|
|
4409
4407
|
}
|
|
4410
4408
|
let handled = false;
|
|
@@ -4438,10 +4436,10 @@
|
|
|
4438
4436
|
async redraw() {
|
|
4439
4437
|
this.clear();
|
|
4440
4438
|
await this.init();
|
|
4441
|
-
this.
|
|
4439
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
4442
4440
|
}
|
|
4443
4441
|
remove(particle, group, override) {
|
|
4444
|
-
this.removeAt(this.
|
|
4442
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
4445
4443
|
}
|
|
4446
4444
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
4447
4445
|
if (index < minIndex || index > this.count) {
|
|
@@ -4449,7 +4447,7 @@
|
|
|
4449
4447
|
}
|
|
4450
4448
|
let deleted = 0;
|
|
4451
4449
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
4452
|
-
if (this
|
|
4450
|
+
if (this.#removeParticle(i, group, override)) {
|
|
4453
4451
|
i--;
|
|
4454
4452
|
deleted++;
|
|
4455
4453
|
}
|
|
@@ -4459,9 +4457,9 @@
|
|
|
4459
4457
|
this.removeAt(minIndex, quantity, group);
|
|
4460
4458
|
}
|
|
4461
4459
|
setDensity() {
|
|
4462
|
-
const options = this.
|
|
4460
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
4463
4461
|
let pluginsCount = 0;
|
|
4464
|
-
for (const plugin of this.
|
|
4462
|
+
for (const plugin of this.#container.plugins) {
|
|
4465
4463
|
if (plugin.particlesDensityCount) {
|
|
4466
4464
|
pluginsCount += plugin.particlesDensityCount();
|
|
4467
4465
|
}
|
|
@@ -4471,51 +4469,51 @@
|
|
|
4471
4469
|
if (!groupData) {
|
|
4472
4470
|
continue;
|
|
4473
4471
|
}
|
|
4474
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
4475
|
-
this
|
|
4472
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
4473
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
4476
4474
|
}
|
|
4477
|
-
this
|
|
4475
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
4478
4476
|
}
|
|
4479
4477
|
setResizeFactor(factor) {
|
|
4480
|
-
this
|
|
4478
|
+
this.#resizeFactor = factor;
|
|
4481
4479
|
}
|
|
4482
4480
|
update(delta) {
|
|
4483
4481
|
this.grid.clear();
|
|
4484
|
-
for (const plugin of this
|
|
4482
|
+
for (const plugin of this.#updatePlugins) {
|
|
4485
4483
|
plugin.update?.(delta);
|
|
4486
4484
|
}
|
|
4487
|
-
const particlesToDelete = this
|
|
4488
|
-
for (const plugin of this
|
|
4485
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
4486
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
4489
4487
|
plugin.postUpdate?.(delta);
|
|
4490
4488
|
}
|
|
4491
|
-
this
|
|
4489
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
4492
4490
|
if (particlesToDelete.size) {
|
|
4493
4491
|
for (const particle of particlesToDelete) {
|
|
4494
4492
|
this.remove(particle);
|
|
4495
4493
|
}
|
|
4496
4494
|
}
|
|
4497
|
-
|
|
4495
|
+
this.#resizeFactor = undefined;
|
|
4498
4496
|
}
|
|
4499
|
-
|
|
4500
|
-
this.
|
|
4497
|
+
#addToPool = (...particles) => {
|
|
4498
|
+
this.#pool.push(...particles);
|
|
4501
4499
|
};
|
|
4502
|
-
|
|
4500
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
4503
4501
|
const numberOptions = options.number;
|
|
4504
4502
|
if (!numberOptions.density.enable) {
|
|
4505
4503
|
if (group === undefined) {
|
|
4506
|
-
this
|
|
4504
|
+
this.#limit = numberOptions.limit.value;
|
|
4507
4505
|
}
|
|
4508
4506
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
4509
|
-
this.
|
|
4507
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
4510
4508
|
}
|
|
4511
4509
|
return;
|
|
4512
4510
|
}
|
|
4513
|
-
const densityFactor = this
|
|
4511
|
+
const densityFactor = this.#initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
4514
4512
|
if (group === undefined) {
|
|
4515
|
-
this
|
|
4513
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
4516
4514
|
}
|
|
4517
4515
|
else {
|
|
4518
|
-
this.
|
|
4516
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
4519
4517
|
}
|
|
4520
4518
|
if (particlesCount < particlesNumber) {
|
|
4521
4519
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -4524,18 +4522,18 @@
|
|
|
4524
4522
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
4525
4523
|
}
|
|
4526
4524
|
};
|
|
4527
|
-
|
|
4525
|
+
#createBuckets = (zLayers) => {
|
|
4528
4526
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
4529
4527
|
return Array.from({ length: bucketCount }, () => []);
|
|
4530
4528
|
};
|
|
4531
|
-
|
|
4532
|
-
const maxBucketIndex = this.
|
|
4529
|
+
#getBucketIndex = (zIndex) => {
|
|
4530
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
4533
4531
|
if (maxBucketIndex <= minIndex) {
|
|
4534
4532
|
return minIndex;
|
|
4535
4533
|
}
|
|
4536
4534
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
4537
4535
|
};
|
|
4538
|
-
|
|
4536
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
4539
4537
|
let start = minIndex, end = bucket.length;
|
|
4540
4538
|
while (start < end) {
|
|
4541
4539
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -4552,8 +4550,8 @@
|
|
|
4552
4550
|
}
|
|
4553
4551
|
return start;
|
|
4554
4552
|
};
|
|
4555
|
-
|
|
4556
|
-
const container = this
|
|
4553
|
+
#initDensityFactor = densityOptions => {
|
|
4554
|
+
const container = this.#container;
|
|
4557
4555
|
if (!densityOptions.enable) {
|
|
4558
4556
|
return defaultDensityFactor;
|
|
4559
4557
|
}
|
|
@@ -4563,82 +4561,82 @@
|
|
|
4563
4561
|
}
|
|
4564
4562
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
4565
4563
|
};
|
|
4566
|
-
|
|
4567
|
-
const bucketIndex = this
|
|
4564
|
+
#insertParticleIntoBucket = (particle) => {
|
|
4565
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
4568
4566
|
if (!bucket) {
|
|
4569
4567
|
return;
|
|
4570
4568
|
}
|
|
4571
|
-
bucket.splice(this
|
|
4572
|
-
this.
|
|
4569
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
4570
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
4573
4571
|
};
|
|
4574
|
-
|
|
4575
|
-
const particle = this
|
|
4572
|
+
#removeParticle = (index, group, override) => {
|
|
4573
|
+
const particle = this.#array[index];
|
|
4576
4574
|
if (!particle) {
|
|
4577
4575
|
return false;
|
|
4578
4576
|
}
|
|
4579
4577
|
if (particle.group !== group) {
|
|
4580
4578
|
return false;
|
|
4581
4579
|
}
|
|
4582
|
-
this.
|
|
4583
|
-
this
|
|
4580
|
+
this.#array.splice(index, deleteCount);
|
|
4581
|
+
this.#removeParticleFromBucket(particle);
|
|
4584
4582
|
particle.destroy(override);
|
|
4585
|
-
this.
|
|
4583
|
+
this.#container.dispatchEvent(exports.EventType.particleRemoved, {
|
|
4586
4584
|
particle,
|
|
4587
4585
|
});
|
|
4588
|
-
this
|
|
4586
|
+
this.#addToPool(particle);
|
|
4589
4587
|
return true;
|
|
4590
4588
|
};
|
|
4591
|
-
|
|
4592
|
-
const bucketIndex = this.
|
|
4589
|
+
#removeParticleFromBucket = (particle) => {
|
|
4590
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
4593
4591
|
if (!bucket) {
|
|
4594
|
-
this.
|
|
4592
|
+
this.#particleBuckets.delete(particle.id);
|
|
4595
4593
|
return;
|
|
4596
4594
|
}
|
|
4597
|
-
const particleIndex = this
|
|
4595
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
4598
4596
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
4599
|
-
this.
|
|
4597
|
+
this.#particleBuckets.delete(particle.id);
|
|
4600
4598
|
return;
|
|
4601
4599
|
}
|
|
4602
4600
|
bucket.splice(particleIndex, deleteCount);
|
|
4603
|
-
this.
|
|
4601
|
+
this.#particleBuckets.delete(particle.id);
|
|
4604
4602
|
};
|
|
4605
|
-
|
|
4603
|
+
#resetBuckets = (zLayers) => {
|
|
4606
4604
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
4607
|
-
if (this.
|
|
4608
|
-
this
|
|
4605
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
4606
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
4609
4607
|
return;
|
|
4610
4608
|
}
|
|
4611
|
-
for (const bucket of this
|
|
4609
|
+
for (const bucket of this.#zBuckets) {
|
|
4612
4610
|
bucket.length = minIndex;
|
|
4613
4611
|
}
|
|
4614
4612
|
};
|
|
4615
|
-
|
|
4616
|
-
const newBucketIndex = this
|
|
4613
|
+
#updateParticleBucket = (particle) => {
|
|
4614
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
4617
4615
|
if (currentBucketIndex === undefined) {
|
|
4618
|
-
this
|
|
4616
|
+
this.#insertParticleIntoBucket(particle);
|
|
4619
4617
|
return;
|
|
4620
4618
|
}
|
|
4621
4619
|
if (currentBucketIndex === newBucketIndex) {
|
|
4622
4620
|
return;
|
|
4623
4621
|
}
|
|
4624
|
-
const currentBucket = this
|
|
4622
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
4625
4623
|
if (currentBucket) {
|
|
4626
|
-
const particleIndex = this
|
|
4624
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
4627
4625
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
4628
4626
|
currentBucket.splice(particleIndex, deleteCount);
|
|
4629
4627
|
}
|
|
4630
4628
|
}
|
|
4631
|
-
const newBucket = this
|
|
4629
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
4632
4630
|
if (!newBucket) {
|
|
4633
|
-
this.
|
|
4631
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
4634
4632
|
return;
|
|
4635
4633
|
}
|
|
4636
|
-
newBucket.splice(this
|
|
4637
|
-
this.
|
|
4634
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
4635
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
4638
4636
|
};
|
|
4639
|
-
|
|
4640
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
4641
|
-
for (const particle of this
|
|
4637
|
+
#updateParticlesPhase1 = (delta) => {
|
|
4638
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
4639
|
+
for (const particle of this.#array) {
|
|
4642
4640
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
4643
4641
|
particle.position.x *= resizeFactor.width;
|
|
4644
4642
|
particle.position.y *= resizeFactor.height;
|
|
@@ -4646,10 +4644,10 @@
|
|
|
4646
4644
|
particle.initialPosition.y *= resizeFactor.height;
|
|
4647
4645
|
}
|
|
4648
4646
|
particle.ignoresResizeRatio = false;
|
|
4649
|
-
for (const plugin of this
|
|
4647
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
4650
4648
|
plugin.particleReset?.(particle);
|
|
4651
4649
|
}
|
|
4652
|
-
for (const plugin of this
|
|
4650
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
4653
4651
|
if (particle.destroyed) {
|
|
4654
4652
|
break;
|
|
4655
4653
|
}
|
|
@@ -4663,36 +4661,36 @@
|
|
|
4663
4661
|
}
|
|
4664
4662
|
return particlesToDelete;
|
|
4665
4663
|
};
|
|
4666
|
-
|
|
4667
|
-
for (const particle of this
|
|
4664
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
4665
|
+
for (const particle of this.#array) {
|
|
4668
4666
|
if (particle.destroyed) {
|
|
4669
4667
|
particlesToDelete.add(particle);
|
|
4670
4668
|
continue;
|
|
4671
4669
|
}
|
|
4672
|
-
for (const updater of this.
|
|
4670
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4673
4671
|
updater.update(particle, delta);
|
|
4674
4672
|
}
|
|
4675
4673
|
if (!particle.spawning) {
|
|
4676
|
-
for (const plugin of this
|
|
4674
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
4677
4675
|
plugin.postParticleUpdate?.(particle, delta);
|
|
4678
4676
|
}
|
|
4679
4677
|
}
|
|
4680
|
-
this
|
|
4678
|
+
this.#updateParticleBucket(particle);
|
|
4681
4679
|
}
|
|
4682
4680
|
};
|
|
4683
4681
|
}
|
|
4684
4682
|
|
|
4685
4683
|
class Retina {
|
|
4686
|
-
container;
|
|
4687
4684
|
pixelRatio;
|
|
4688
4685
|
reduceFactor;
|
|
4686
|
+
#container;
|
|
4689
4687
|
constructor(container) {
|
|
4690
|
-
this
|
|
4688
|
+
this.#container = container;
|
|
4691
4689
|
this.pixelRatio = defaultRatio;
|
|
4692
4690
|
this.reduceFactor = defaultReduceFactor;
|
|
4693
4691
|
}
|
|
4694
4692
|
init() {
|
|
4695
|
-
const container = this
|
|
4693
|
+
const container = this.#container, options = container.actualOptions;
|
|
4696
4694
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
4697
4695
|
this.reduceFactor = defaultReduceFactor;
|
|
4698
4696
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -4706,7 +4704,6 @@
|
|
|
4706
4704
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
4707
4705
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
4708
4706
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
4709
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
4710
4707
|
const maxDistance = props.maxDistance;
|
|
4711
4708
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
4712
4709
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -4744,73 +4741,73 @@
|
|
|
4744
4741
|
shapeDrawers;
|
|
4745
4742
|
started;
|
|
4746
4743
|
zLayers;
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4744
|
+
#delay;
|
|
4745
|
+
#delayTimeout;
|
|
4746
|
+
#delta = { value: 0, factor: 0 };
|
|
4747
|
+
#dispatchCallback;
|
|
4748
|
+
#drawAnimationFrame;
|
|
4749
|
+
#duration;
|
|
4750
|
+
#eventListeners;
|
|
4751
|
+
#firstStart;
|
|
4752
|
+
#initialSourceOptions;
|
|
4753
|
+
#lastFrameTime;
|
|
4754
|
+
#lifeTime;
|
|
4755
|
+
#onDestroy;
|
|
4756
|
+
#options;
|
|
4757
|
+
#paused;
|
|
4758
|
+
#pluginManager;
|
|
4759
|
+
#smooth;
|
|
4760
|
+
#sourceOptions;
|
|
4764
4761
|
constructor(params) {
|
|
4765
4762
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
4766
|
-
this
|
|
4767
|
-
this
|
|
4768
|
-
this
|
|
4763
|
+
this.#pluginManager = pluginManager;
|
|
4764
|
+
this.#dispatchCallback = dispatchCallback;
|
|
4765
|
+
this.#onDestroy = onDestroy;
|
|
4769
4766
|
this.id = Symbol(id);
|
|
4770
4767
|
this.fpsLimit = 120;
|
|
4771
4768
|
this.hdr = false;
|
|
4772
|
-
this
|
|
4773
|
-
this
|
|
4774
|
-
this
|
|
4775
|
-
this
|
|
4776
|
-
this
|
|
4769
|
+
this.#smooth = false;
|
|
4770
|
+
this.#delay = 0;
|
|
4771
|
+
this.#duration = 0;
|
|
4772
|
+
this.#lifeTime = 0;
|
|
4773
|
+
this.#firstStart = true;
|
|
4777
4774
|
this.started = false;
|
|
4778
4775
|
this.destroyed = false;
|
|
4779
|
-
this
|
|
4780
|
-
this
|
|
4776
|
+
this.#paused = true;
|
|
4777
|
+
this.#lastFrameTime = 0;
|
|
4781
4778
|
this.zLayers = 100;
|
|
4782
4779
|
this.pageHidden = false;
|
|
4783
|
-
this
|
|
4784
|
-
this
|
|
4780
|
+
this.#sourceOptions = sourceOptions;
|
|
4781
|
+
this.#initialSourceOptions = sourceOptions;
|
|
4785
4782
|
this.effectDrawers = new Map();
|
|
4786
4783
|
this.shapeDrawers = new Map();
|
|
4787
4784
|
this.particleUpdaters = [];
|
|
4788
4785
|
this.retina = new Retina(this);
|
|
4789
|
-
this.canvas = new CanvasManager(this
|
|
4790
|
-
this.particles = new ParticlesManager(this
|
|
4786
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
4787
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
4791
4788
|
this.plugins = [];
|
|
4792
4789
|
this.particleDestroyedPlugins = [];
|
|
4793
4790
|
this.particleCreatedPlugins = [];
|
|
4794
4791
|
this.particlePositionPlugins = [];
|
|
4795
|
-
this
|
|
4796
|
-
this.actualOptions = loadContainerOptions(this
|
|
4797
|
-
this
|
|
4792
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
4793
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
4794
|
+
this.#eventListeners = new EventListeners(this);
|
|
4798
4795
|
this.dispatchEvent(exports.EventType.containerBuilt);
|
|
4799
4796
|
}
|
|
4800
4797
|
get animationStatus() {
|
|
4801
|
-
return !this
|
|
4798
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
4802
4799
|
}
|
|
4803
4800
|
get options() {
|
|
4804
|
-
return this
|
|
4801
|
+
return this.#options;
|
|
4805
4802
|
}
|
|
4806
4803
|
get sourceOptions() {
|
|
4807
|
-
return this
|
|
4804
|
+
return this.#sourceOptions;
|
|
4808
4805
|
}
|
|
4809
4806
|
addLifeTime(value) {
|
|
4810
|
-
this
|
|
4807
|
+
this.#lifeTime += value;
|
|
4811
4808
|
}
|
|
4812
4809
|
alive() {
|
|
4813
|
-
return !this
|
|
4810
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
4814
4811
|
}
|
|
4815
4812
|
destroy(remove = true) {
|
|
4816
4813
|
if (!guardCheck(this)) {
|
|
@@ -4832,13 +4829,13 @@
|
|
|
4832
4829
|
this.shapeDrawers = new Map();
|
|
4833
4830
|
this.particleUpdaters = [];
|
|
4834
4831
|
this.plugins.length = 0;
|
|
4835
|
-
this.
|
|
4832
|
+
this.#pluginManager.clearPlugins(this);
|
|
4836
4833
|
this.destroyed = true;
|
|
4837
|
-
this
|
|
4834
|
+
this.#onDestroy(remove);
|
|
4838
4835
|
this.dispatchEvent(exports.EventType.containerDestroyed);
|
|
4839
4836
|
}
|
|
4840
4837
|
dispatchEvent(type, data) {
|
|
4841
|
-
this
|
|
4838
|
+
this.#dispatchCallback(type, {
|
|
4842
4839
|
container: this,
|
|
4843
4840
|
data,
|
|
4844
4841
|
});
|
|
@@ -4848,12 +4845,12 @@
|
|
|
4848
4845
|
return;
|
|
4849
4846
|
}
|
|
4850
4847
|
let refreshTime = force;
|
|
4851
|
-
this
|
|
4848
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
4852
4849
|
if (refreshTime) {
|
|
4853
|
-
this
|
|
4850
|
+
this.#lastFrameTime = undefined;
|
|
4854
4851
|
refreshTime = false;
|
|
4855
4852
|
}
|
|
4856
|
-
this
|
|
4853
|
+
this.#nextFrame(timestamp);
|
|
4857
4854
|
});
|
|
4858
4855
|
}
|
|
4859
4856
|
async export(type, options = {}) {
|
|
@@ -4875,7 +4872,7 @@
|
|
|
4875
4872
|
return;
|
|
4876
4873
|
}
|
|
4877
4874
|
const allContainerPlugins = new Map();
|
|
4878
|
-
for (const plugin of this.
|
|
4875
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
4879
4876
|
const containerPlugin = await plugin.getPlugin(this);
|
|
4880
4877
|
if (containerPlugin.preInit) {
|
|
4881
4878
|
await containerPlugin.preInit();
|
|
@@ -4883,8 +4880,8 @@
|
|
|
4883
4880
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
4884
4881
|
}
|
|
4885
4882
|
await this.initDrawersAndUpdaters();
|
|
4886
|
-
this
|
|
4887
|
-
this.actualOptions = loadContainerOptions(this
|
|
4883
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
4884
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
4888
4885
|
this.plugins.length = 0;
|
|
4889
4886
|
this.particleDestroyedPlugins.length = 0;
|
|
4890
4887
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -4911,11 +4908,11 @@
|
|
|
4911
4908
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
4912
4909
|
this.hdr = hdr;
|
|
4913
4910
|
this.zLayers = zLayers;
|
|
4914
|
-
this
|
|
4915
|
-
this
|
|
4916
|
-
this
|
|
4911
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
4912
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
4913
|
+
this.#lifeTime = 0;
|
|
4917
4914
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
4918
|
-
this
|
|
4915
|
+
this.#smooth = smooth;
|
|
4919
4916
|
for (const plugin of this.plugins) {
|
|
4920
4917
|
await plugin.init?.();
|
|
4921
4918
|
}
|
|
@@ -4928,7 +4925,7 @@
|
|
|
4928
4925
|
this.dispatchEvent(exports.EventType.particlesSetup);
|
|
4929
4926
|
}
|
|
4930
4927
|
async initDrawersAndUpdaters() {
|
|
4931
|
-
const pluginManager = this
|
|
4928
|
+
const pluginManager = this.#pluginManager;
|
|
4932
4929
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
4933
4930
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
4934
4931
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -4937,18 +4934,18 @@
|
|
|
4937
4934
|
if (!guardCheck(this)) {
|
|
4938
4935
|
return;
|
|
4939
4936
|
}
|
|
4940
|
-
if (this
|
|
4941
|
-
cancelAnimation(this
|
|
4942
|
-
|
|
4937
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
4938
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
4939
|
+
this.#drawAnimationFrame = undefined;
|
|
4943
4940
|
}
|
|
4944
|
-
if (this
|
|
4941
|
+
if (this.#paused) {
|
|
4945
4942
|
return;
|
|
4946
4943
|
}
|
|
4947
4944
|
for (const plugin of this.plugins) {
|
|
4948
4945
|
plugin.pause?.();
|
|
4949
4946
|
}
|
|
4950
4947
|
if (!this.pageHidden) {
|
|
4951
|
-
this
|
|
4948
|
+
this.#paused = true;
|
|
4952
4949
|
}
|
|
4953
4950
|
this.dispatchEvent(exports.EventType.containerPaused);
|
|
4954
4951
|
}
|
|
@@ -4956,13 +4953,13 @@
|
|
|
4956
4953
|
if (!guardCheck(this)) {
|
|
4957
4954
|
return;
|
|
4958
4955
|
}
|
|
4959
|
-
const needsUpdate = this
|
|
4960
|
-
if (this
|
|
4961
|
-
this
|
|
4956
|
+
const needsUpdate = this.#paused || force;
|
|
4957
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
4958
|
+
this.#firstStart = false;
|
|
4962
4959
|
return;
|
|
4963
4960
|
}
|
|
4964
|
-
if (this
|
|
4965
|
-
this
|
|
4961
|
+
if (this.#paused) {
|
|
4962
|
+
this.#paused = false;
|
|
4966
4963
|
}
|
|
4967
4964
|
if (needsUpdate) {
|
|
4968
4965
|
for (const plugin of this.plugins) {
|
|
@@ -4985,10 +4982,10 @@
|
|
|
4985
4982
|
if (!guardCheck(this)) {
|
|
4986
4983
|
return;
|
|
4987
4984
|
}
|
|
4988
|
-
this
|
|
4989
|
-
this
|
|
4990
|
-
this
|
|
4991
|
-
this.actualOptions = loadContainerOptions(this
|
|
4985
|
+
this.#initialSourceOptions = sourceOptions;
|
|
4986
|
+
this.#sourceOptions = sourceOptions;
|
|
4987
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
4988
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
4992
4989
|
return this.refresh();
|
|
4993
4990
|
}
|
|
4994
4991
|
async start() {
|
|
@@ -4999,7 +4996,7 @@
|
|
|
4999
4996
|
this.started = true;
|
|
5000
4997
|
await new Promise(resolve => {
|
|
5001
4998
|
const start = async () => {
|
|
5002
|
-
this.
|
|
4999
|
+
this.#eventListeners.addListeners();
|
|
5003
5000
|
for (const plugin of this.plugins) {
|
|
5004
5001
|
await plugin.start?.();
|
|
5005
5002
|
}
|
|
@@ -5007,20 +5004,20 @@
|
|
|
5007
5004
|
this.play();
|
|
5008
5005
|
resolve();
|
|
5009
5006
|
};
|
|
5010
|
-
this
|
|
5007
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
5011
5008
|
});
|
|
5012
5009
|
}
|
|
5013
5010
|
stop() {
|
|
5014
5011
|
if (!guardCheck(this) || !this.started) {
|
|
5015
5012
|
return;
|
|
5016
5013
|
}
|
|
5017
|
-
if (this
|
|
5018
|
-
clearTimeout(this
|
|
5019
|
-
|
|
5014
|
+
if (this.#delayTimeout) {
|
|
5015
|
+
clearTimeout(this.#delayTimeout);
|
|
5016
|
+
this.#delayTimeout = undefined;
|
|
5020
5017
|
}
|
|
5021
|
-
this
|
|
5018
|
+
this.#firstStart = true;
|
|
5022
5019
|
this.started = false;
|
|
5023
|
-
this.
|
|
5020
|
+
this.#eventListeners.removeListeners();
|
|
5024
5021
|
this.pause();
|
|
5025
5022
|
this.particles.clear();
|
|
5026
5023
|
this.canvas.stop();
|
|
@@ -5030,7 +5027,7 @@
|
|
|
5030
5027
|
this.particleCreatedPlugins.length = 0;
|
|
5031
5028
|
this.particleDestroyedPlugins.length = 0;
|
|
5032
5029
|
this.particlePositionPlugins.length = 0;
|
|
5033
|
-
this
|
|
5030
|
+
this.#sourceOptions = this.#options;
|
|
5034
5031
|
this.dispatchEvent(exports.EventType.containerStopped);
|
|
5035
5032
|
}
|
|
5036
5033
|
updateActualOptions() {
|
|
@@ -5042,23 +5039,23 @@
|
|
|
5042
5039
|
}
|
|
5043
5040
|
return refresh;
|
|
5044
5041
|
}
|
|
5045
|
-
|
|
5042
|
+
#nextFrame = (timestamp) => {
|
|
5046
5043
|
try {
|
|
5047
|
-
if (!this
|
|
5048
|
-
this
|
|
5049
|
-
timestamp < this
|
|
5044
|
+
if (!this.#smooth &&
|
|
5045
|
+
this.#lastFrameTime !== undefined &&
|
|
5046
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
5050
5047
|
this.draw(false);
|
|
5051
5048
|
return;
|
|
5052
5049
|
}
|
|
5053
|
-
this
|
|
5054
|
-
updateDelta(this
|
|
5055
|
-
this.addLifeTime(this.
|
|
5056
|
-
this
|
|
5057
|
-
if (this.
|
|
5050
|
+
this.#lastFrameTime ??= timestamp;
|
|
5051
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
5052
|
+
this.addLifeTime(this.#delta.value);
|
|
5053
|
+
this.#lastFrameTime = timestamp;
|
|
5054
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
5058
5055
|
this.draw(false);
|
|
5059
5056
|
return;
|
|
5060
5057
|
}
|
|
5061
|
-
this.canvas.render.drawParticles(this
|
|
5058
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
5062
5059
|
if (!this.alive()) {
|
|
5063
5060
|
this.destroy();
|
|
5064
5061
|
return;
|
|
@@ -5093,8 +5090,6 @@
|
|
|
5093
5090
|
exports.MoveCenter = MoveCenter;
|
|
5094
5091
|
exports.MoveGravity = MoveGravity;
|
|
5095
5092
|
exports.MovePath = MovePath;
|
|
5096
|
-
exports.Opacity = Opacity;
|
|
5097
|
-
exports.OpacityAnimation = OpacityAnimation;
|
|
5098
5093
|
exports.Options = Options;
|
|
5099
5094
|
exports.OptionsColor = OptionsColor;
|
|
5100
5095
|
exports.OutModes = OutModes;
|
|
@@ -5110,8 +5105,6 @@
|
|
|
5110
5105
|
exports.Rectangle = Rectangle;
|
|
5111
5106
|
exports.ResizeEvent = ResizeEvent;
|
|
5112
5107
|
exports.Shape = Shape;
|
|
5113
|
-
exports.Size = Size;
|
|
5114
|
-
exports.SizeAnimation = SizeAnimation;
|
|
5115
5108
|
exports.Spin = Spin;
|
|
5116
5109
|
exports.Stroke = Stroke;
|
|
5117
5110
|
exports.ValueWithRandom = ValueWithRandom;
|