@tsparticles/preset-squares 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.
|
@@ -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
|
-
/* Preset v4.0
|
|
2
|
+
/* Preset 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
|
}
|
|
@@ -713,38 +713,38 @@
|
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
class EventDispatcher {
|
|
716
|
-
|
|
716
|
+
#listeners;
|
|
717
717
|
constructor() {
|
|
718
|
-
this
|
|
718
|
+
this.#listeners = new Map();
|
|
719
719
|
}
|
|
720
720
|
addEventListener(type, listener) {
|
|
721
721
|
this.removeEventListener(type, listener);
|
|
722
|
-
let arr = this.
|
|
722
|
+
let arr = this.#listeners.get(type);
|
|
723
723
|
if (!arr) {
|
|
724
724
|
arr = [];
|
|
725
|
-
this.
|
|
725
|
+
this.#listeners.set(type, arr);
|
|
726
726
|
}
|
|
727
727
|
arr.push(listener);
|
|
728
728
|
}
|
|
729
729
|
dispatchEvent(type, args) {
|
|
730
|
-
const listeners = this.
|
|
730
|
+
const listeners = this.#listeners.get(type);
|
|
731
731
|
listeners?.forEach(handler => {
|
|
732
732
|
handler(args);
|
|
733
733
|
});
|
|
734
734
|
}
|
|
735
735
|
hasEventListener(type) {
|
|
736
|
-
return !!this.
|
|
736
|
+
return !!this.#listeners.get(type);
|
|
737
737
|
}
|
|
738
738
|
removeAllEventListeners(type) {
|
|
739
739
|
if (!type) {
|
|
740
|
-
this
|
|
740
|
+
this.#listeners = new Map();
|
|
741
741
|
}
|
|
742
742
|
else {
|
|
743
|
-
this.
|
|
743
|
+
this.#listeners.delete(type);
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
removeEventListener(type, listener) {
|
|
747
|
-
const arr = this.
|
|
747
|
+
const arr = this.#listeners.get(type);
|
|
748
748
|
if (!arr) {
|
|
749
749
|
return;
|
|
750
750
|
}
|
|
@@ -753,7 +753,7 @@
|
|
|
753
753
|
return;
|
|
754
754
|
}
|
|
755
755
|
if (length === deleteCount) {
|
|
756
|
-
this.
|
|
756
|
+
this.#listeners.delete(type);
|
|
757
757
|
}
|
|
758
758
|
else {
|
|
759
759
|
arr.splice(idx, deleteCount);
|
|
@@ -791,19 +791,19 @@
|
|
|
791
791
|
presets = new Map();
|
|
792
792
|
shapeDrawers = new Map();
|
|
793
793
|
updaters = new Map();
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
794
|
+
#allLoadersSet = new Set();
|
|
795
|
+
#configs = new Map();
|
|
796
|
+
#engine;
|
|
797
|
+
#executedSet = new Set();
|
|
798
|
+
#initialized = false;
|
|
799
|
+
#isRunningLoaders = false;
|
|
800
|
+
#loadPromises = new Set();
|
|
801
801
|
constructor(engine) {
|
|
802
|
-
this
|
|
802
|
+
this.#engine = engine;
|
|
803
803
|
}
|
|
804
804
|
get configs() {
|
|
805
805
|
const res = {};
|
|
806
|
-
for (const [name, config] of this
|
|
806
|
+
for (const [name, config] of this.#configs) {
|
|
807
807
|
res[name] = config;
|
|
808
808
|
}
|
|
809
809
|
return res;
|
|
@@ -813,8 +813,8 @@
|
|
|
813
813
|
}
|
|
814
814
|
addConfig(config) {
|
|
815
815
|
const key = config.key ?? config.name ?? "default";
|
|
816
|
-
this.
|
|
817
|
-
this.
|
|
816
|
+
this.#configs.set(key, config);
|
|
817
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
818
818
|
}
|
|
819
819
|
addEasing(name, easing) {
|
|
820
820
|
if (this.easingFunctions.get(name)) {
|
|
@@ -875,21 +875,21 @@
|
|
|
875
875
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
876
876
|
}
|
|
877
877
|
async init() {
|
|
878
|
-
if (this
|
|
878
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
879
879
|
return;
|
|
880
880
|
}
|
|
881
|
-
this
|
|
882
|
-
this
|
|
883
|
-
this
|
|
881
|
+
this.#isRunningLoaders = true;
|
|
882
|
+
this.#executedSet = new Set();
|
|
883
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
884
884
|
try {
|
|
885
|
-
for (const loader of this
|
|
886
|
-
await this
|
|
885
|
+
for (const loader of this.#allLoadersSet) {
|
|
886
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
889
|
finally {
|
|
890
|
-
this.
|
|
891
|
-
this
|
|
892
|
-
this
|
|
890
|
+
this.#loadPromises.clear();
|
|
891
|
+
this.#isRunningLoaders = false;
|
|
892
|
+
this.#initialized = true;
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
895
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -900,24 +900,24 @@
|
|
|
900
900
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
901
901
|
}
|
|
902
902
|
async register(...loaders) {
|
|
903
|
-
if (this
|
|
903
|
+
if (this.#initialized) {
|
|
904
904
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
905
905
|
}
|
|
906
906
|
for (const loader of loaders) {
|
|
907
|
-
if (this
|
|
908
|
-
await this
|
|
907
|
+
if (this.#isRunningLoaders) {
|
|
908
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
909
909
|
}
|
|
910
910
|
else {
|
|
911
|
-
this.
|
|
911
|
+
this.#loadPromises.add(loader);
|
|
912
912
|
}
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
|
-
async
|
|
915
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
916
916
|
if (executed.has(loader))
|
|
917
917
|
return;
|
|
918
918
|
executed.add(loader);
|
|
919
919
|
allLoaders.add(loader);
|
|
920
|
-
await loader(this
|
|
920
|
+
await loader(this.#engine);
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
923
|
|
|
@@ -997,17 +997,17 @@
|
|
|
997
997
|
};
|
|
998
998
|
class Engine {
|
|
999
999
|
pluginManager = new PluginManager(this);
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1000
|
+
#domArray = [];
|
|
1001
|
+
#eventDispatcher = new EventDispatcher();
|
|
1002
|
+
#initialized = false;
|
|
1003
1003
|
get items() {
|
|
1004
|
-
return this
|
|
1004
|
+
return this.#domArray;
|
|
1005
1005
|
}
|
|
1006
1006
|
get version() {
|
|
1007
|
-
return "4.0
|
|
1007
|
+
return "4.1.0";
|
|
1008
1008
|
}
|
|
1009
1009
|
addEventListener(type, listener) {
|
|
1010
|
-
this.
|
|
1010
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1011
1011
|
}
|
|
1012
1012
|
checkVersion(pluginVersion) {
|
|
1013
1013
|
if (this.version === pluginVersion) {
|
|
@@ -1016,17 +1016,17 @@
|
|
|
1016
1016
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1017
1017
|
}
|
|
1018
1018
|
dispatchEvent(type, args) {
|
|
1019
|
-
this.
|
|
1019
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1020
1020
|
}
|
|
1021
1021
|
async init() {
|
|
1022
|
-
if (this
|
|
1022
|
+
if (this.#initialized) {
|
|
1023
1023
|
return;
|
|
1024
1024
|
}
|
|
1025
1025
|
await this.pluginManager.init();
|
|
1026
|
-
this
|
|
1026
|
+
this.#initialized = true;
|
|
1027
1027
|
}
|
|
1028
1028
|
item(index) {
|
|
1029
|
-
const
|
|
1029
|
+
const items = this.items, item = items[index];
|
|
1030
1030
|
if (item?.destroyed) {
|
|
1031
1031
|
items.splice(index, removeDeleteCount);
|
|
1032
1032
|
return;
|
|
@@ -1080,7 +1080,7 @@
|
|
|
1080
1080
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1081
1081
|
}
|
|
1082
1082
|
removeEventListener(type, listener) {
|
|
1083
|
-
this.
|
|
1083
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1084
1084
|
}
|
|
1085
1085
|
}
|
|
1086
1086
|
|
|
@@ -1851,43 +1851,6 @@
|
|
|
1851
1851
|
}
|
|
1852
1852
|
}
|
|
1853
1853
|
|
|
1854
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1855
|
-
destroy;
|
|
1856
|
-
constructor() {
|
|
1857
|
-
super();
|
|
1858
|
-
this.destroy = DestroyType.none;
|
|
1859
|
-
this.speed = 2;
|
|
1860
|
-
}
|
|
1861
|
-
load(data) {
|
|
1862
|
-
super.load(data);
|
|
1863
|
-
if (isNull(data)) {
|
|
1864
|
-
return;
|
|
1865
|
-
}
|
|
1866
|
-
if (data.destroy !== undefined) {
|
|
1867
|
-
this.destroy = data.destroy;
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1873
|
-
animation;
|
|
1874
|
-
constructor() {
|
|
1875
|
-
super();
|
|
1876
|
-
this.animation = new OpacityAnimation();
|
|
1877
|
-
this.value = 1;
|
|
1878
|
-
}
|
|
1879
|
-
load(data) {
|
|
1880
|
-
if (isNull(data)) {
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
super.load(data);
|
|
1884
|
-
const animation = data.animation;
|
|
1885
|
-
if (animation !== undefined) {
|
|
1886
|
-
this.animation.load(animation);
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
1854
|
class Stroke {
|
|
1892
1855
|
color;
|
|
1893
1856
|
opacity;
|
|
@@ -2055,43 +2018,6 @@
|
|
|
2055
2018
|
}
|
|
2056
2019
|
}
|
|
2057
2020
|
|
|
2058
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2059
|
-
destroy;
|
|
2060
|
-
constructor() {
|
|
2061
|
-
super();
|
|
2062
|
-
this.destroy = DestroyType.none;
|
|
2063
|
-
this.speed = 5;
|
|
2064
|
-
}
|
|
2065
|
-
load(data) {
|
|
2066
|
-
super.load(data);
|
|
2067
|
-
if (isNull(data)) {
|
|
2068
|
-
return;
|
|
2069
|
-
}
|
|
2070
|
-
if (data.destroy !== undefined) {
|
|
2071
|
-
this.destroy = data.destroy;
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2077
|
-
animation;
|
|
2078
|
-
constructor() {
|
|
2079
|
-
super();
|
|
2080
|
-
this.animation = new SizeAnimation();
|
|
2081
|
-
this.value = 3;
|
|
2082
|
-
}
|
|
2083
|
-
load(data) {
|
|
2084
|
-
super.load(data);
|
|
2085
|
-
if (isNull(data)) {
|
|
2086
|
-
return;
|
|
2087
|
-
}
|
|
2088
|
-
const animation = data.animation;
|
|
2089
|
-
if (animation !== undefined) {
|
|
2090
|
-
this.animation.load(animation);
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
2021
|
class ZIndex extends ValueWithRandom {
|
|
2096
2022
|
opacityRate;
|
|
2097
2023
|
sizeRate;
|
|
@@ -2125,24 +2051,21 @@
|
|
|
2125
2051
|
groups;
|
|
2126
2052
|
move;
|
|
2127
2053
|
number;
|
|
2128
|
-
opacity;
|
|
2129
2054
|
paint;
|
|
2130
2055
|
palette;
|
|
2131
2056
|
reduceDuplicates;
|
|
2132
2057
|
shape;
|
|
2133
|
-
size;
|
|
2134
2058
|
zIndex;
|
|
2135
|
-
|
|
2136
|
-
|
|
2059
|
+
#container;
|
|
2060
|
+
#pluginManager;
|
|
2137
2061
|
constructor(pluginManager, container) {
|
|
2138
|
-
this
|
|
2139
|
-
this
|
|
2062
|
+
this.#pluginManager = pluginManager;
|
|
2063
|
+
this.#container = container;
|
|
2140
2064
|
this.bounce = new ParticlesBounce();
|
|
2141
2065
|
this.effect = new Effect();
|
|
2142
2066
|
this.groups = {};
|
|
2143
2067
|
this.move = new Move();
|
|
2144
2068
|
this.number = new ParticlesNumber();
|
|
2145
|
-
this.opacity = new Opacity();
|
|
2146
2069
|
this.paint = new Paint();
|
|
2147
2070
|
this.paint.color = new AnimatableColor();
|
|
2148
2071
|
this.paint.color.value = "#fff";
|
|
@@ -2150,7 +2073,6 @@
|
|
|
2150
2073
|
this.paint.fill.enable = true;
|
|
2151
2074
|
this.reduceDuplicates = false;
|
|
2152
2075
|
this.shape = new Shape();
|
|
2153
|
-
this.size = new Size();
|
|
2154
2076
|
this.zIndex = new ZIndex();
|
|
2155
2077
|
}
|
|
2156
2078
|
load(data) {
|
|
@@ -2159,7 +2081,7 @@
|
|
|
2159
2081
|
}
|
|
2160
2082
|
if (data.palette) {
|
|
2161
2083
|
this.palette = data.palette;
|
|
2162
|
-
this
|
|
2084
|
+
this.#importPalette(this.palette);
|
|
2163
2085
|
}
|
|
2164
2086
|
if (data.groups !== undefined) {
|
|
2165
2087
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2179,7 +2101,6 @@
|
|
|
2179
2101
|
this.effect.load(data.effect);
|
|
2180
2102
|
this.move.load(data.move);
|
|
2181
2103
|
this.number.load(data.number);
|
|
2182
|
-
this.opacity.load(data.opacity);
|
|
2183
2104
|
const paintToLoad = data.paint;
|
|
2184
2105
|
if (paintToLoad) {
|
|
2185
2106
|
if (isArray(paintToLoad)) {
|
|
@@ -2198,15 +2119,14 @@
|
|
|
2198
2119
|
}
|
|
2199
2120
|
}
|
|
2200
2121
|
this.shape.load(data.shape);
|
|
2201
|
-
this.size.load(data.size);
|
|
2202
2122
|
this.zIndex.load(data.zIndex);
|
|
2203
|
-
if (this
|
|
2204
|
-
for (const plugin of this.
|
|
2123
|
+
if (this.#container) {
|
|
2124
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2205
2125
|
if (plugin.loadParticlesOptions) {
|
|
2206
|
-
plugin.loadParticlesOptions(this
|
|
2126
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2207
2127
|
}
|
|
2208
2128
|
}
|
|
2209
|
-
const updaters = this.
|
|
2129
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2210
2130
|
if (updaters) {
|
|
2211
2131
|
for (const updater of updaters) {
|
|
2212
2132
|
if (updater.loadOptions) {
|
|
@@ -2216,8 +2136,8 @@
|
|
|
2216
2136
|
}
|
|
2217
2137
|
}
|
|
2218
2138
|
}
|
|
2219
|
-
|
|
2220
|
-
const paletteData = this.
|
|
2139
|
+
#importPalette = (palette) => {
|
|
2140
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2221
2141
|
if (!paletteData) {
|
|
2222
2142
|
return;
|
|
2223
2143
|
}
|
|
@@ -2296,11 +2216,11 @@
|
|
|
2296
2216
|
smooth;
|
|
2297
2217
|
style;
|
|
2298
2218
|
zLayers;
|
|
2299
|
-
|
|
2300
|
-
|
|
2219
|
+
#container;
|
|
2220
|
+
#pluginManager;
|
|
2301
2221
|
constructor(pluginManager, container) {
|
|
2302
|
-
this
|
|
2303
|
-
this
|
|
2222
|
+
this.#pluginManager = pluginManager;
|
|
2223
|
+
this.#container = container;
|
|
2304
2224
|
this.autoPlay = true;
|
|
2305
2225
|
this.background = new Background();
|
|
2306
2226
|
this.clear = true;
|
|
@@ -2311,7 +2231,7 @@
|
|
|
2311
2231
|
this.duration = 0;
|
|
2312
2232
|
this.fpsLimit = 120;
|
|
2313
2233
|
this.hdr = true;
|
|
2314
|
-
this.particles = loadParticlesOptions(this
|
|
2234
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2315
2235
|
this.pauseOnBlur = true;
|
|
2316
2236
|
this.pauseOnOutsideViewport = true;
|
|
2317
2237
|
this.resize = new ResizeEvent();
|
|
@@ -2326,12 +2246,12 @@
|
|
|
2326
2246
|
if (data.preset !== undefined) {
|
|
2327
2247
|
this.preset = data.preset;
|
|
2328
2248
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2329
|
-
this
|
|
2249
|
+
this.#importPreset(preset);
|
|
2330
2250
|
});
|
|
2331
2251
|
}
|
|
2332
2252
|
if (data.palette !== undefined) {
|
|
2333
2253
|
this.palette = data.palette;
|
|
2334
|
-
this
|
|
2254
|
+
this.#importPalette(this.palette);
|
|
2335
2255
|
}
|
|
2336
2256
|
if (data.autoPlay !== undefined) {
|
|
2337
2257
|
this.autoPlay = data.autoPlay;
|
|
@@ -2385,12 +2305,12 @@
|
|
|
2385
2305
|
if (data.smooth !== undefined) {
|
|
2386
2306
|
this.smooth = data.smooth;
|
|
2387
2307
|
}
|
|
2388
|
-
this.
|
|
2389
|
-
plugin.loadOptions(this
|
|
2308
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2309
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2390
2310
|
});
|
|
2391
2311
|
}
|
|
2392
|
-
|
|
2393
|
-
const paletteData = this.
|
|
2312
|
+
#importPalette = palette => {
|
|
2313
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2394
2314
|
if (!paletteData) {
|
|
2395
2315
|
return;
|
|
2396
2316
|
}
|
|
@@ -2407,8 +2327,8 @@
|
|
|
2407
2327
|
},
|
|
2408
2328
|
});
|
|
2409
2329
|
};
|
|
2410
|
-
|
|
2411
|
-
this.load(this.
|
|
2330
|
+
#importPreset = preset => {
|
|
2331
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2412
2332
|
};
|
|
2413
2333
|
}
|
|
2414
2334
|
|
|
@@ -3031,13 +2951,13 @@
|
|
|
3031
2951
|
|
|
3032
2952
|
class EmittersPlugin {
|
|
3033
2953
|
id = "emitters";
|
|
3034
|
-
|
|
2954
|
+
#instancesManager;
|
|
3035
2955
|
constructor(instancesManager) {
|
|
3036
|
-
this
|
|
2956
|
+
this.#instancesManager = instancesManager;
|
|
3037
2957
|
}
|
|
3038
2958
|
async getPlugin(container) {
|
|
3039
2959
|
const { EmittersPluginInstance } = await Promise.resolve().then(function () { return EmittersPluginInstance$1; });
|
|
3040
|
-
return new EmittersPluginInstance(this
|
|
2960
|
+
return new EmittersPluginInstance(this.#instancesManager, container);
|
|
3041
2961
|
}
|
|
3042
2962
|
loadOptions(_container, options, source) {
|
|
3043
2963
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -3090,7 +3010,7 @@
|
|
|
3090
3010
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
3091
3011
|
|
|
3092
3012
|
async function loadEmittersPluginSimple(engine) {
|
|
3093
|
-
engine.checkVersion("4.0
|
|
3013
|
+
engine.checkVersion("4.1.0");
|
|
3094
3014
|
await engine.pluginManager.register(async (e) => {
|
|
3095
3015
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
3096
3016
|
await addEmittersShapesManager(e);
|
|
@@ -3111,15 +3031,15 @@
|
|
|
3111
3031
|
return input.startsWith("#");
|
|
3112
3032
|
}
|
|
3113
3033
|
handleColor(color) {
|
|
3114
|
-
return this
|
|
3034
|
+
return this.#parseString(color.value);
|
|
3115
3035
|
}
|
|
3116
3036
|
handleRangeColor(color) {
|
|
3117
|
-
return this
|
|
3037
|
+
return this.#parseString(color.value);
|
|
3118
3038
|
}
|
|
3119
3039
|
parseString(input) {
|
|
3120
|
-
return this
|
|
3040
|
+
return this.#parseString(input);
|
|
3121
3041
|
}
|
|
3122
|
-
|
|
3042
|
+
#parseString(hexColor) {
|
|
3123
3043
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
3124
3044
|
return;
|
|
3125
3045
|
}
|
|
@@ -3138,7 +3058,7 @@
|
|
|
3138
3058
|
}
|
|
3139
3059
|
|
|
3140
3060
|
async function loadHexColorPlugin(engine) {
|
|
3141
|
-
engine.checkVersion("4.0
|
|
3061
|
+
engine.checkVersion("4.1.0");
|
|
3142
3062
|
await engine.pluginManager.register(e => {
|
|
3143
3063
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
3144
3064
|
});
|
|
@@ -3146,20 +3066,20 @@
|
|
|
3146
3066
|
|
|
3147
3067
|
const defaultOpacity = 1;
|
|
3148
3068
|
class PaintUpdater {
|
|
3149
|
-
|
|
3150
|
-
|
|
3069
|
+
#container;
|
|
3070
|
+
#pluginManager;
|
|
3151
3071
|
constructor(pluginManager, container) {
|
|
3152
|
-
this
|
|
3153
|
-
this
|
|
3072
|
+
this.#container = container;
|
|
3073
|
+
this.#pluginManager = pluginManager;
|
|
3154
3074
|
}
|
|
3155
3075
|
init(particle) {
|
|
3156
|
-
const container = this
|
|
3076
|
+
const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates), color = paint?.color, paintColor = color ?? undefined, fill = paint?.fill, stroke = paint?.stroke;
|
|
3157
3077
|
if (fill) {
|
|
3158
3078
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3159
3079
|
particle.fillEnabled = fill.enable;
|
|
3160
3080
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3161
3081
|
particle.fillAnimation = fillColor.animation;
|
|
3162
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3082
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3163
3083
|
if (fillHslColor) {
|
|
3164
3084
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3165
3085
|
}
|
|
@@ -3175,7 +3095,7 @@
|
|
|
3175
3095
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3176
3096
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3177
3097
|
particle.strokeAnimation = strokeColor.animation;
|
|
3178
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3098
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3179
3099
|
if (strokeHslColor) {
|
|
3180
3100
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3181
3101
|
}
|
|
@@ -3207,7 +3127,7 @@
|
|
|
3207
3127
|
}
|
|
3208
3128
|
|
|
3209
3129
|
async function loadPaintUpdater(engine) {
|
|
3210
|
-
engine.checkVersion("4.0
|
|
3130
|
+
engine.checkVersion("4.1.0");
|
|
3211
3131
|
await engine.pluginManager.register(e => {
|
|
3212
3132
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3213
3133
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3273,9 +3193,9 @@
|
|
|
3273
3193
|
|
|
3274
3194
|
const doublePIDeg = 360;
|
|
3275
3195
|
class RotateUpdater {
|
|
3276
|
-
container;
|
|
3196
|
+
#container;
|
|
3277
3197
|
constructor(container) {
|
|
3278
|
-
this
|
|
3198
|
+
this.#container = container;
|
|
3279
3199
|
}
|
|
3280
3200
|
init(particle) {
|
|
3281
3201
|
const rotateOptions = particle.options.rotate;
|
|
@@ -3307,7 +3227,7 @@
|
|
|
3307
3227
|
if (rotateAnimation.enable) {
|
|
3308
3228
|
particle.rotate.decay = identity - getRangeValue(rotateAnimation.decay);
|
|
3309
3229
|
particle.rotate.velocity =
|
|
3310
|
-
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this
|
|
3230
|
+
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
|
|
3311
3231
|
if (!rotateAnimation.sync) {
|
|
3312
3232
|
particle.rotate.velocity *= getRandom();
|
|
3313
3233
|
}
|
|
@@ -3341,7 +3261,7 @@
|
|
|
3341
3261
|
}
|
|
3342
3262
|
|
|
3343
3263
|
async function loadRotateUpdater(engine) {
|
|
3344
|
-
engine.checkVersion("4.0
|
|
3264
|
+
engine.checkVersion("4.1.0");
|
|
3345
3265
|
await engine.pluginManager.register(e => {
|
|
3346
3266
|
e.pluginManager.addParticleUpdater("rotate", container => {
|
|
3347
3267
|
return Promise.resolve(new RotateUpdater(container));
|
|
@@ -3349,21 +3269,63 @@
|
|
|
3349
3269
|
});
|
|
3350
3270
|
}
|
|
3351
3271
|
|
|
3272
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3273
|
+
destroy;
|
|
3274
|
+
constructor() {
|
|
3275
|
+
super();
|
|
3276
|
+
this.destroy = DestroyType.none;
|
|
3277
|
+
this.speed = 5;
|
|
3278
|
+
}
|
|
3279
|
+
load(data) {
|
|
3280
|
+
super.load(data);
|
|
3281
|
+
if (isNull(data)) {
|
|
3282
|
+
return;
|
|
3283
|
+
}
|
|
3284
|
+
if (data.destroy !== undefined) {
|
|
3285
|
+
this.destroy = data.destroy;
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3291
|
+
animation;
|
|
3292
|
+
constructor() {
|
|
3293
|
+
super();
|
|
3294
|
+
this.animation = new SizeAnimation();
|
|
3295
|
+
this.value = 3;
|
|
3296
|
+
}
|
|
3297
|
+
load(data) {
|
|
3298
|
+
super.load(data);
|
|
3299
|
+
if (isNull(data)) {
|
|
3300
|
+
return;
|
|
3301
|
+
}
|
|
3302
|
+
const animation = data.animation;
|
|
3303
|
+
if (animation !== undefined) {
|
|
3304
|
+
this.animation.load(animation);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
|
|
3352
3309
|
const minLoops = 0;
|
|
3353
3310
|
class SizeUpdater {
|
|
3354
|
-
|
|
3311
|
+
#container;
|
|
3355
3312
|
constructor(container) {
|
|
3356
|
-
this
|
|
3313
|
+
this.#container = container;
|
|
3357
3314
|
}
|
|
3358
3315
|
init(particle) {
|
|
3359
|
-
const container = this
|
|
3360
|
-
if (
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3316
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3317
|
+
if (!sizeOptions) {
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3321
|
+
if (!sizeAnimation.enable) {
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3325
|
+
if (sizeAnimation.sync) {
|
|
3326
|
+
return;
|
|
3366
3327
|
}
|
|
3328
|
+
particle.size.velocity *= getRandom();
|
|
3367
3329
|
}
|
|
3368
3330
|
isEnabled(particle) {
|
|
3369
3331
|
return (!particle.destroyed &&
|
|
@@ -3373,12 +3335,26 @@
|
|
|
3373
3335
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3374
3336
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3375
3337
|
}
|
|
3338
|
+
loadOptions(options, ...sources) {
|
|
3339
|
+
options.size ??= new Size();
|
|
3340
|
+
for (const source of sources) {
|
|
3341
|
+
options.size.load(source?.size);
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
preInit(particle) {
|
|
3345
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3346
|
+
if (!sizeOptions) {
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3349
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3350
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3351
|
+
}
|
|
3376
3352
|
reset(particle) {
|
|
3377
3353
|
particle.size.time = 0;
|
|
3378
3354
|
particle.size.loops = 0;
|
|
3379
3355
|
}
|
|
3380
3356
|
update(particle, delta) {
|
|
3381
|
-
if (!this.isEnabled(particle)) {
|
|
3357
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3382
3358
|
return;
|
|
3383
3359
|
}
|
|
3384
3360
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3386,7 +3362,7 @@
|
|
|
3386
3362
|
}
|
|
3387
3363
|
|
|
3388
3364
|
async function loadSizeUpdater(engine) {
|
|
3389
|
-
engine.checkVersion("4.0
|
|
3365
|
+
engine.checkVersion("4.1.0");
|
|
3390
3366
|
await engine.pluginManager.register(e => {
|
|
3391
3367
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3392
3368
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3410,7 +3386,7 @@
|
|
|
3410
3386
|
}
|
|
3411
3387
|
|
|
3412
3388
|
async function loadSquareShape(engine) {
|
|
3413
|
-
engine.checkVersion("4.0
|
|
3389
|
+
engine.checkVersion("4.1.0");
|
|
3414
3390
|
await engine.pluginManager.register(e => {
|
|
3415
3391
|
e.pluginManager.addShape(["edge", "square"], () => Promise.resolve(new SquareDrawer()));
|
|
3416
3392
|
});
|
|
@@ -3494,58 +3470,58 @@
|
|
|
3494
3470
|
}
|
|
3495
3471
|
}
|
|
3496
3472
|
class RenderManager {
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3473
|
+
#canvasClearPlugins;
|
|
3474
|
+
#canvasManager;
|
|
3475
|
+
#canvasPaintPlugins;
|
|
3476
|
+
#clearDrawPlugins;
|
|
3477
|
+
#colorPlugins;
|
|
3478
|
+
#container;
|
|
3479
|
+
#context;
|
|
3480
|
+
#contextSettings;
|
|
3481
|
+
#drawParticlePlugins;
|
|
3482
|
+
#drawParticlesCleanupPlugins;
|
|
3483
|
+
#drawParticlesSetupPlugins;
|
|
3484
|
+
#drawPlugins;
|
|
3485
|
+
#drawSettingsCleanupPlugins;
|
|
3486
|
+
#drawSettingsSetupPlugins;
|
|
3487
|
+
#pluginManager;
|
|
3488
|
+
#postDrawUpdaters;
|
|
3489
|
+
#preDrawUpdaters;
|
|
3490
|
+
#reusableColorStyles = {};
|
|
3491
|
+
#reusablePluginColors = [undefined, undefined];
|
|
3492
|
+
#reusableTransform = {};
|
|
3517
3493
|
constructor(pluginManager, container, canvasManager) {
|
|
3518
|
-
this
|
|
3519
|
-
this
|
|
3520
|
-
this
|
|
3521
|
-
this
|
|
3522
|
-
this
|
|
3523
|
-
this
|
|
3524
|
-
this
|
|
3525
|
-
this
|
|
3526
|
-
this
|
|
3527
|
-
this
|
|
3528
|
-
this
|
|
3529
|
-
this
|
|
3530
|
-
this
|
|
3531
|
-
this
|
|
3532
|
-
this
|
|
3533
|
-
this
|
|
3494
|
+
this.#pluginManager = pluginManager;
|
|
3495
|
+
this.#container = container;
|
|
3496
|
+
this.#canvasManager = canvasManager;
|
|
3497
|
+
this.#context = null;
|
|
3498
|
+
this.#preDrawUpdaters = [];
|
|
3499
|
+
this.#postDrawUpdaters = [];
|
|
3500
|
+
this.#colorPlugins = [];
|
|
3501
|
+
this.#canvasClearPlugins = [];
|
|
3502
|
+
this.#canvasPaintPlugins = [];
|
|
3503
|
+
this.#clearDrawPlugins = [];
|
|
3504
|
+
this.#drawParticlePlugins = [];
|
|
3505
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3506
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3507
|
+
this.#drawPlugins = [];
|
|
3508
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3509
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3534
3510
|
}
|
|
3535
3511
|
get settings() {
|
|
3536
|
-
return this
|
|
3512
|
+
return this.#contextSettings;
|
|
3537
3513
|
}
|
|
3538
3514
|
canvasClear() {
|
|
3539
|
-
if (!this.
|
|
3515
|
+
if (!this.#container.actualOptions.clear) {
|
|
3540
3516
|
return;
|
|
3541
3517
|
}
|
|
3542
3518
|
this.draw(ctx => {
|
|
3543
|
-
clear(ctx, this.
|
|
3519
|
+
clear(ctx, this.#canvasManager.size);
|
|
3544
3520
|
});
|
|
3545
3521
|
}
|
|
3546
3522
|
clear() {
|
|
3547
3523
|
let pluginHandled = false;
|
|
3548
|
-
for (const plugin of this
|
|
3524
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
3549
3525
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
3550
3526
|
if (pluginHandled) {
|
|
3551
3527
|
break;
|
|
@@ -3558,21 +3534,21 @@
|
|
|
3558
3534
|
}
|
|
3559
3535
|
destroy() {
|
|
3560
3536
|
this.stop();
|
|
3561
|
-
this
|
|
3562
|
-
this
|
|
3563
|
-
this
|
|
3564
|
-
this
|
|
3565
|
-
this
|
|
3566
|
-
this
|
|
3567
|
-
this
|
|
3568
|
-
this
|
|
3569
|
-
this
|
|
3570
|
-
this
|
|
3571
|
-
this
|
|
3572
|
-
this
|
|
3537
|
+
this.#preDrawUpdaters = [];
|
|
3538
|
+
this.#postDrawUpdaters = [];
|
|
3539
|
+
this.#colorPlugins = [];
|
|
3540
|
+
this.#canvasClearPlugins = [];
|
|
3541
|
+
this.#canvasPaintPlugins = [];
|
|
3542
|
+
this.#clearDrawPlugins = [];
|
|
3543
|
+
this.#drawParticlePlugins = [];
|
|
3544
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3545
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3546
|
+
this.#drawPlugins = [];
|
|
3547
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3548
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3573
3549
|
}
|
|
3574
3550
|
draw(cb) {
|
|
3575
|
-
const ctx = this
|
|
3551
|
+
const ctx = this.#context;
|
|
3576
3552
|
if (!ctx) {
|
|
3577
3553
|
return;
|
|
3578
3554
|
}
|
|
@@ -3587,21 +3563,21 @@
|
|
|
3587
3563
|
return;
|
|
3588
3564
|
}
|
|
3589
3565
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
3590
|
-
let [fColor, sColor] = this
|
|
3566
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
3591
3567
|
fColor ??= pfColor;
|
|
3592
3568
|
sColor ??= psColor;
|
|
3593
3569
|
if (!fColor && !sColor) {
|
|
3594
3570
|
return;
|
|
3595
3571
|
}
|
|
3596
|
-
const container = this
|
|
3572
|
+
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;
|
|
3597
3573
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
3598
3574
|
colorStyles.fill = fill;
|
|
3599
3575
|
colorStyles.stroke = stroke;
|
|
3600
3576
|
this.draw((context) => {
|
|
3601
|
-
for (const plugin of this
|
|
3577
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
3602
3578
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
3603
3579
|
}
|
|
3604
|
-
this
|
|
3580
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
3605
3581
|
drawParticle({
|
|
3606
3582
|
container,
|
|
3607
3583
|
context,
|
|
@@ -3612,35 +3588,35 @@
|
|
|
3612
3588
|
opacity: opacity,
|
|
3613
3589
|
transform,
|
|
3614
3590
|
});
|
|
3615
|
-
this
|
|
3616
|
-
for (const plugin of this
|
|
3591
|
+
this.#applyPostDrawUpdaters(particle);
|
|
3592
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
3617
3593
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
3618
3594
|
}
|
|
3619
3595
|
});
|
|
3620
3596
|
}
|
|
3621
3597
|
drawParticlePlugins(particle, delta) {
|
|
3622
3598
|
this.draw(ctx => {
|
|
3623
|
-
for (const plugin of this
|
|
3599
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
3624
3600
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
3625
3601
|
}
|
|
3626
3602
|
});
|
|
3627
3603
|
}
|
|
3628
3604
|
drawParticles(delta) {
|
|
3629
|
-
const { particles } = this
|
|
3605
|
+
const { particles } = this.#container;
|
|
3630
3606
|
this.clear();
|
|
3631
3607
|
particles.update(delta);
|
|
3632
3608
|
this.draw(ctx => {
|
|
3633
|
-
for (const plugin of this
|
|
3609
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
3634
3610
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
3635
3611
|
}
|
|
3636
|
-
for (const plugin of this
|
|
3612
|
+
for (const plugin of this.#drawPlugins) {
|
|
3637
3613
|
plugin.draw?.(ctx, delta);
|
|
3638
3614
|
}
|
|
3639
3615
|
particles.drawParticles(delta);
|
|
3640
|
-
for (const plugin of this
|
|
3616
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
3641
3617
|
plugin.clearDraw?.(ctx, delta);
|
|
3642
3618
|
}
|
|
3643
|
-
for (const plugin of this
|
|
3619
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
3644
3620
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
3645
3621
|
}
|
|
3646
3622
|
});
|
|
@@ -3651,64 +3627,64 @@
|
|
|
3651
3627
|
this.paint();
|
|
3652
3628
|
}
|
|
3653
3629
|
initPlugins() {
|
|
3654
|
-
this
|
|
3655
|
-
this
|
|
3656
|
-
this
|
|
3657
|
-
this
|
|
3658
|
-
this
|
|
3659
|
-
this
|
|
3660
|
-
this
|
|
3661
|
-
this
|
|
3662
|
-
this
|
|
3663
|
-
this
|
|
3664
|
-
for (const plugin of this.
|
|
3630
|
+
this.#colorPlugins = [];
|
|
3631
|
+
this.#canvasClearPlugins = [];
|
|
3632
|
+
this.#canvasPaintPlugins = [];
|
|
3633
|
+
this.#clearDrawPlugins = [];
|
|
3634
|
+
this.#drawParticlePlugins = [];
|
|
3635
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3636
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3637
|
+
this.#drawPlugins = [];
|
|
3638
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3639
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3640
|
+
for (const plugin of this.#container.plugins) {
|
|
3665
3641
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
3666
|
-
this.
|
|
3642
|
+
this.#colorPlugins.push(plugin);
|
|
3667
3643
|
}
|
|
3668
3644
|
if (plugin.canvasClear) {
|
|
3669
|
-
this.
|
|
3645
|
+
this.#canvasClearPlugins.push(plugin);
|
|
3670
3646
|
}
|
|
3671
3647
|
if (plugin.canvasPaint) {
|
|
3672
|
-
this.
|
|
3648
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
3673
3649
|
}
|
|
3674
3650
|
if (plugin.drawParticle) {
|
|
3675
|
-
this.
|
|
3651
|
+
this.#drawParticlePlugins.push(plugin);
|
|
3676
3652
|
}
|
|
3677
3653
|
if (plugin.drawParticleSetup) {
|
|
3678
|
-
this.
|
|
3654
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
3679
3655
|
}
|
|
3680
3656
|
if (plugin.drawParticleCleanup) {
|
|
3681
|
-
this.
|
|
3657
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
3682
3658
|
}
|
|
3683
3659
|
if (plugin.draw) {
|
|
3684
|
-
this.
|
|
3660
|
+
this.#drawPlugins.push(plugin);
|
|
3685
3661
|
}
|
|
3686
3662
|
if (plugin.drawSettingsSetup) {
|
|
3687
|
-
this.
|
|
3663
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
3688
3664
|
}
|
|
3689
3665
|
if (plugin.drawSettingsCleanup) {
|
|
3690
|
-
this.
|
|
3666
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
3691
3667
|
}
|
|
3692
3668
|
if (plugin.clearDraw) {
|
|
3693
|
-
this.
|
|
3669
|
+
this.#clearDrawPlugins.push(plugin);
|
|
3694
3670
|
}
|
|
3695
3671
|
}
|
|
3696
3672
|
}
|
|
3697
3673
|
initUpdaters() {
|
|
3698
|
-
this
|
|
3699
|
-
this
|
|
3700
|
-
for (const updater of this.
|
|
3674
|
+
this.#preDrawUpdaters = [];
|
|
3675
|
+
this.#postDrawUpdaters = [];
|
|
3676
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
3701
3677
|
if (updater.afterDraw) {
|
|
3702
|
-
this.
|
|
3678
|
+
this.#postDrawUpdaters.push(updater);
|
|
3703
3679
|
}
|
|
3704
3680
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
3705
|
-
this.
|
|
3681
|
+
this.#preDrawUpdaters.push(updater);
|
|
3706
3682
|
}
|
|
3707
3683
|
}
|
|
3708
3684
|
}
|
|
3709
3685
|
paint() {
|
|
3710
3686
|
let handled = false;
|
|
3711
|
-
for (const plugin of this
|
|
3687
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
3712
3688
|
handled = plugin.canvasPaint?.() ?? false;
|
|
3713
3689
|
if (handled) {
|
|
3714
3690
|
break;
|
|
@@ -3721,35 +3697,35 @@
|
|
|
3721
3697
|
}
|
|
3722
3698
|
paintBase(baseColor) {
|
|
3723
3699
|
this.draw(ctx => {
|
|
3724
|
-
paintBase(ctx, this.
|
|
3700
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
3725
3701
|
});
|
|
3726
3702
|
}
|
|
3727
3703
|
paintImage(image, opacity) {
|
|
3728
3704
|
this.draw(ctx => {
|
|
3729
|
-
paintImage(ctx, this.
|
|
3705
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
3730
3706
|
});
|
|
3731
3707
|
}
|
|
3732
3708
|
setContext(context) {
|
|
3733
|
-
this
|
|
3734
|
-
if (this
|
|
3735
|
-
this.
|
|
3709
|
+
this.#context = context;
|
|
3710
|
+
if (this.#context) {
|
|
3711
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
3736
3712
|
}
|
|
3737
3713
|
}
|
|
3738
3714
|
setContextSettings(settings) {
|
|
3739
|
-
this
|
|
3715
|
+
this.#contextSettings = settings;
|
|
3740
3716
|
}
|
|
3741
3717
|
stop() {
|
|
3742
3718
|
this.draw(ctx => {
|
|
3743
|
-
clear(ctx, this.
|
|
3719
|
+
clear(ctx, this.#canvasManager.size);
|
|
3744
3720
|
});
|
|
3745
3721
|
}
|
|
3746
|
-
|
|
3747
|
-
for (const updater of this
|
|
3722
|
+
#applyPostDrawUpdaters = particle => {
|
|
3723
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
3748
3724
|
updater.afterDraw?.(particle);
|
|
3749
3725
|
}
|
|
3750
3726
|
};
|
|
3751
|
-
|
|
3752
|
-
for (const updater of this
|
|
3727
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
3728
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
3753
3729
|
if (updater.getColorStyles) {
|
|
3754
3730
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
3755
3731
|
if (fill) {
|
|
@@ -3768,22 +3744,22 @@
|
|
|
3768
3744
|
updater.beforeDraw?.(particle);
|
|
3769
3745
|
}
|
|
3770
3746
|
};
|
|
3771
|
-
|
|
3747
|
+
#getPluginParticleColors = particle => {
|
|
3772
3748
|
let fColor, sColor;
|
|
3773
|
-
for (const plugin of this
|
|
3749
|
+
for (const plugin of this.#colorPlugins) {
|
|
3774
3750
|
if (!fColor && plugin.particleFillColor) {
|
|
3775
|
-
fColor = rangeColorToHsl(this
|
|
3751
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
3776
3752
|
}
|
|
3777
3753
|
if (!sColor && plugin.particleStrokeColor) {
|
|
3778
|
-
sColor = rangeColorToHsl(this
|
|
3754
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
3779
3755
|
}
|
|
3780
3756
|
if (fColor && sColor) {
|
|
3781
3757
|
break;
|
|
3782
3758
|
}
|
|
3783
3759
|
}
|
|
3784
|
-
this
|
|
3785
|
-
this
|
|
3786
|
-
return this
|
|
3760
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
3761
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
3762
|
+
return this.#reusablePluginColors;
|
|
3787
3763
|
};
|
|
3788
3764
|
}
|
|
3789
3765
|
|
|
@@ -3841,53 +3817,53 @@
|
|
|
3841
3817
|
renderCanvas;
|
|
3842
3818
|
size;
|
|
3843
3819
|
zoom = defaultZoom;
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3820
|
+
#container;
|
|
3821
|
+
#generated;
|
|
3822
|
+
#mutationObserver;
|
|
3823
|
+
#originalStyle;
|
|
3824
|
+
#pluginManager;
|
|
3825
|
+
#pointerEvents;
|
|
3826
|
+
#resizePlugins;
|
|
3827
|
+
#standardSize;
|
|
3828
|
+
#zoomCenter;
|
|
3853
3829
|
constructor(pluginManager, container) {
|
|
3854
|
-
this
|
|
3855
|
-
this
|
|
3830
|
+
this.#pluginManager = pluginManager;
|
|
3831
|
+
this.#container = container;
|
|
3856
3832
|
this.render = new RenderManager(pluginManager, container, this);
|
|
3857
|
-
this
|
|
3833
|
+
this.#standardSize = {
|
|
3858
3834
|
height: 0,
|
|
3859
3835
|
width: 0,
|
|
3860
3836
|
};
|
|
3861
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
3837
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
3862
3838
|
this.size = {
|
|
3863
3839
|
height: stdSize.height * pxRatio,
|
|
3864
3840
|
width: stdSize.width * pxRatio,
|
|
3865
3841
|
};
|
|
3866
|
-
this
|
|
3867
|
-
this
|
|
3868
|
-
this
|
|
3842
|
+
this.#generated = false;
|
|
3843
|
+
this.#resizePlugins = [];
|
|
3844
|
+
this.#pointerEvents = "none";
|
|
3869
3845
|
}
|
|
3870
|
-
get
|
|
3871
|
-
return this.
|
|
3846
|
+
get #fullScreen() {
|
|
3847
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
3872
3848
|
}
|
|
3873
3849
|
destroy() {
|
|
3874
3850
|
this.stop();
|
|
3875
|
-
if (this
|
|
3851
|
+
if (this.#generated) {
|
|
3876
3852
|
const element = this.domElement;
|
|
3877
3853
|
element?.remove();
|
|
3878
3854
|
this.domElement = undefined;
|
|
3879
3855
|
this.renderCanvas = undefined;
|
|
3880
3856
|
}
|
|
3881
3857
|
else {
|
|
3882
|
-
this
|
|
3858
|
+
this.#resetOriginalStyle();
|
|
3883
3859
|
}
|
|
3884
3860
|
this.render.destroy();
|
|
3885
|
-
this
|
|
3861
|
+
this.#resizePlugins = [];
|
|
3886
3862
|
}
|
|
3887
3863
|
getZoomCenter() {
|
|
3888
|
-
const pxRatio = this.
|
|
3889
|
-
if (this
|
|
3890
|
-
return this
|
|
3864
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
3865
|
+
if (this.#zoomCenter) {
|
|
3866
|
+
return this.#zoomCenter;
|
|
3891
3867
|
}
|
|
3892
3868
|
return {
|
|
3893
3869
|
x: (width * half) / pxRatio,
|
|
@@ -3895,20 +3871,20 @@
|
|
|
3895
3871
|
};
|
|
3896
3872
|
}
|
|
3897
3873
|
init() {
|
|
3898
|
-
this
|
|
3874
|
+
this.#safeMutationObserver(obs => {
|
|
3899
3875
|
obs.disconnect();
|
|
3900
3876
|
});
|
|
3901
|
-
this
|
|
3877
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
3902
3878
|
for (const record of records) {
|
|
3903
3879
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
3904
|
-
this
|
|
3880
|
+
this.#repairStyle();
|
|
3905
3881
|
}
|
|
3906
3882
|
}
|
|
3907
3883
|
});
|
|
3908
3884
|
this.resize();
|
|
3909
|
-
this
|
|
3885
|
+
this.#initStyle();
|
|
3910
3886
|
this.initBackground();
|
|
3911
|
-
this
|
|
3887
|
+
this.#safeMutationObserver(obs => {
|
|
3912
3888
|
const element = this.domElement;
|
|
3913
3889
|
if (!element || !(element instanceof Node)) {
|
|
3914
3890
|
return;
|
|
@@ -3919,13 +3895,13 @@
|
|
|
3919
3895
|
this.render.init();
|
|
3920
3896
|
}
|
|
3921
3897
|
initBackground() {
|
|
3922
|
-
const
|
|
3898
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
3923
3899
|
if (!element) {
|
|
3924
3900
|
return;
|
|
3925
3901
|
}
|
|
3926
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
3902
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
3927
3903
|
if (color) {
|
|
3928
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
3904
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
3929
3905
|
}
|
|
3930
3906
|
else {
|
|
3931
3907
|
elementStyle.backgroundColor = "";
|
|
@@ -3936,27 +3912,27 @@
|
|
|
3936
3912
|
elementStyle.backgroundSize = background.size || "";
|
|
3937
3913
|
}
|
|
3938
3914
|
initPlugins() {
|
|
3939
|
-
this
|
|
3940
|
-
for (const plugin of this.
|
|
3915
|
+
this.#resizePlugins = [];
|
|
3916
|
+
for (const plugin of this.#container.plugins) {
|
|
3941
3917
|
if (plugin.resize) {
|
|
3942
|
-
this.
|
|
3918
|
+
this.#resizePlugins.push(plugin);
|
|
3943
3919
|
}
|
|
3944
3920
|
}
|
|
3945
3921
|
}
|
|
3946
3922
|
loadCanvas(canvas) {
|
|
3947
|
-
if (this
|
|
3923
|
+
if (this.#generated && this.domElement) {
|
|
3948
3924
|
this.domElement.remove();
|
|
3949
3925
|
}
|
|
3950
|
-
const container = this
|
|
3926
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
3951
3927
|
this.domElement = domCanvas;
|
|
3952
|
-
this
|
|
3928
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
3953
3929
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
3954
3930
|
const domElement = this.domElement;
|
|
3955
3931
|
if (domElement) {
|
|
3956
3932
|
domElement.ariaHidden = "true";
|
|
3957
|
-
this
|
|
3933
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
3958
3934
|
}
|
|
3959
|
-
const standardSize = this
|
|
3935
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
3960
3936
|
if (domElement) {
|
|
3961
3937
|
standardSize.height = domElement.offsetHeight;
|
|
3962
3938
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -3965,7 +3941,7 @@
|
|
|
3965
3941
|
standardSize.height = renderCanvas.height;
|
|
3966
3942
|
standardSize.width = renderCanvas.width;
|
|
3967
3943
|
}
|
|
3968
|
-
const pxRatio = this.
|
|
3944
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
3969
3945
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
3970
3946
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
3971
3947
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -3976,12 +3952,12 @@
|
|
|
3976
3952
|
willReadFrequently: false,
|
|
3977
3953
|
});
|
|
3978
3954
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
3979
|
-
this
|
|
3955
|
+
this.#safeMutationObserver(obs => {
|
|
3980
3956
|
obs.disconnect();
|
|
3981
3957
|
});
|
|
3982
3958
|
container.retina.init();
|
|
3983
3959
|
this.initBackground();
|
|
3984
|
-
this
|
|
3960
|
+
this.#safeMutationObserver(obs => {
|
|
3985
3961
|
const element = this.domElement;
|
|
3986
3962
|
if (!element || !(element instanceof Node)) {
|
|
3987
3963
|
return;
|
|
@@ -3994,11 +3970,11 @@
|
|
|
3994
3970
|
if (!element) {
|
|
3995
3971
|
return false;
|
|
3996
3972
|
}
|
|
3997
|
-
const container = this
|
|
3973
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
3998
3974
|
if (renderCanvas === undefined) {
|
|
3999
3975
|
return false;
|
|
4000
3976
|
}
|
|
4001
|
-
const currentSize = container.canvas
|
|
3977
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4002
3978
|
width: element.offsetWidth,
|
|
4003
3979
|
height: element.offsetHeight,
|
|
4004
3980
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4017,7 +3993,7 @@
|
|
|
4017
3993
|
const canvasSize = this.size;
|
|
4018
3994
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4019
3995
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4020
|
-
if (this.
|
|
3996
|
+
if (this.#container.started) {
|
|
4021
3997
|
container.particles.setResizeFactor({
|
|
4022
3998
|
width: currentSize.width / oldSize.width,
|
|
4023
3999
|
height: currentSize.height / oldSize.height,
|
|
@@ -4030,46 +4006,46 @@
|
|
|
4030
4006
|
if (!element) {
|
|
4031
4007
|
return;
|
|
4032
4008
|
}
|
|
4033
|
-
this
|
|
4034
|
-
this
|
|
4009
|
+
this.#pointerEvents = type;
|
|
4010
|
+
this.#repairStyle();
|
|
4035
4011
|
}
|
|
4036
4012
|
setZoom(zoomLevel, center) {
|
|
4037
4013
|
this.zoom = zoomLevel;
|
|
4038
|
-
this
|
|
4014
|
+
this.#zoomCenter = center;
|
|
4039
4015
|
}
|
|
4040
4016
|
stop() {
|
|
4041
|
-
this
|
|
4017
|
+
this.#safeMutationObserver(obs => {
|
|
4042
4018
|
obs.disconnect();
|
|
4043
4019
|
});
|
|
4044
|
-
this
|
|
4020
|
+
this.#mutationObserver = undefined;
|
|
4045
4021
|
this.render.stop();
|
|
4046
4022
|
}
|
|
4047
4023
|
async windowResize() {
|
|
4048
4024
|
if (!this.domElement || !this.resize()) {
|
|
4049
4025
|
return;
|
|
4050
4026
|
}
|
|
4051
|
-
const container = this
|
|
4027
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4052
4028
|
container.particles.setDensity();
|
|
4053
|
-
this
|
|
4029
|
+
this.#applyResizePlugins();
|
|
4054
4030
|
if (needsRefresh) {
|
|
4055
4031
|
await container.refresh();
|
|
4056
4032
|
}
|
|
4057
4033
|
}
|
|
4058
|
-
|
|
4059
|
-
for (const plugin of this
|
|
4034
|
+
#applyResizePlugins = () => {
|
|
4035
|
+
for (const plugin of this.#resizePlugins) {
|
|
4060
4036
|
plugin.resize?.();
|
|
4061
4037
|
}
|
|
4062
4038
|
};
|
|
4063
|
-
|
|
4064
|
-
const element = this.domElement, options = this.
|
|
4039
|
+
#initStyle = () => {
|
|
4040
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4065
4041
|
if (!element) {
|
|
4066
4042
|
return;
|
|
4067
4043
|
}
|
|
4068
|
-
if (this
|
|
4069
|
-
this
|
|
4044
|
+
if (this.#fullScreen) {
|
|
4045
|
+
this.#setFullScreenStyle();
|
|
4070
4046
|
}
|
|
4071
4047
|
else {
|
|
4072
|
-
this
|
|
4048
|
+
this.#resetOriginalStyle();
|
|
4073
4049
|
}
|
|
4074
4050
|
for (const key in options.style) {
|
|
4075
4051
|
if (!key || !(key in options.style)) {
|
|
@@ -4082,72 +4058,72 @@
|
|
|
4082
4058
|
element.style.setProperty(key, value, "important");
|
|
4083
4059
|
}
|
|
4084
4060
|
};
|
|
4085
|
-
|
|
4061
|
+
#repairStyle = () => {
|
|
4086
4062
|
const element = this.domElement;
|
|
4087
4063
|
if (!element) {
|
|
4088
4064
|
return;
|
|
4089
4065
|
}
|
|
4090
|
-
this
|
|
4066
|
+
this.#safeMutationObserver(observer => {
|
|
4091
4067
|
observer.disconnect();
|
|
4092
4068
|
});
|
|
4093
|
-
this
|
|
4069
|
+
this.#initStyle();
|
|
4094
4070
|
this.initBackground();
|
|
4095
|
-
const pointerEvents = this
|
|
4071
|
+
const pointerEvents = this.#pointerEvents;
|
|
4096
4072
|
element.style.pointerEvents = pointerEvents;
|
|
4097
4073
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4098
|
-
this
|
|
4074
|
+
this.#safeMutationObserver(observer => {
|
|
4099
4075
|
if (!(element instanceof Node)) {
|
|
4100
4076
|
return;
|
|
4101
4077
|
}
|
|
4102
4078
|
observer.observe(element, { attributes: true });
|
|
4103
4079
|
});
|
|
4104
4080
|
};
|
|
4105
|
-
|
|
4106
|
-
const element = this.domElement, originalStyle = this
|
|
4081
|
+
#resetOriginalStyle = () => {
|
|
4082
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4107
4083
|
if (!element || !originalStyle) {
|
|
4108
4084
|
return;
|
|
4109
4085
|
}
|
|
4110
4086
|
setStyle(element, originalStyle, true);
|
|
4111
4087
|
};
|
|
4112
|
-
|
|
4113
|
-
if (!this
|
|
4088
|
+
#safeMutationObserver = callback => {
|
|
4089
|
+
if (!this.#mutationObserver) {
|
|
4114
4090
|
return;
|
|
4115
4091
|
}
|
|
4116
|
-
callback(this
|
|
4092
|
+
callback(this.#mutationObserver);
|
|
4117
4093
|
};
|
|
4118
|
-
|
|
4094
|
+
#setFullScreenStyle = () => {
|
|
4119
4095
|
const element = this.domElement;
|
|
4120
4096
|
if (!element) {
|
|
4121
4097
|
return;
|
|
4122
4098
|
}
|
|
4123
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4099
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4124
4100
|
};
|
|
4125
4101
|
}
|
|
4126
4102
|
|
|
4127
4103
|
class EventListeners {
|
|
4128
|
-
container;
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4104
|
+
#container;
|
|
4105
|
+
#handlers;
|
|
4106
|
+
#resizeObserver;
|
|
4107
|
+
#resizeTimeout;
|
|
4132
4108
|
constructor(container) {
|
|
4133
|
-
this
|
|
4134
|
-
this
|
|
4109
|
+
this.#container = container;
|
|
4110
|
+
this.#handlers = {
|
|
4135
4111
|
visibilityChange: () => {
|
|
4136
|
-
this
|
|
4112
|
+
this.#handleVisibilityChange();
|
|
4137
4113
|
},
|
|
4138
4114
|
resize: () => {
|
|
4139
|
-
this
|
|
4115
|
+
this.#handleWindowResize();
|
|
4140
4116
|
},
|
|
4141
4117
|
};
|
|
4142
4118
|
}
|
|
4143
4119
|
addListeners() {
|
|
4144
|
-
this
|
|
4120
|
+
this.#manageListeners(true);
|
|
4145
4121
|
}
|
|
4146
4122
|
removeListeners() {
|
|
4147
|
-
this
|
|
4123
|
+
this.#manageListeners(false);
|
|
4148
4124
|
}
|
|
4149
|
-
|
|
4150
|
-
const container = this
|
|
4125
|
+
#handleVisibilityChange = () => {
|
|
4126
|
+
const container = this.#container, options = container.actualOptions;
|
|
4151
4127
|
if (!options.pauseOnBlur) {
|
|
4152
4128
|
return;
|
|
4153
4129
|
}
|
|
@@ -4165,24 +4141,24 @@
|
|
|
4165
4141
|
}
|
|
4166
4142
|
}
|
|
4167
4143
|
};
|
|
4168
|
-
|
|
4169
|
-
if (this
|
|
4170
|
-
clearTimeout(this
|
|
4171
|
-
|
|
4144
|
+
#handleWindowResize = () => {
|
|
4145
|
+
if (this.#resizeTimeout) {
|
|
4146
|
+
clearTimeout(this.#resizeTimeout);
|
|
4147
|
+
this.#resizeTimeout = undefined;
|
|
4172
4148
|
}
|
|
4173
4149
|
const handleResize = async () => {
|
|
4174
|
-
const canvas = this
|
|
4150
|
+
const canvas = this.#container.canvas;
|
|
4175
4151
|
await canvas.windowResize();
|
|
4176
4152
|
};
|
|
4177
|
-
this
|
|
4153
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4178
4154
|
};
|
|
4179
|
-
|
|
4180
|
-
const handlers = this
|
|
4181
|
-
this
|
|
4155
|
+
#manageListeners = add => {
|
|
4156
|
+
const handlers = this.#handlers;
|
|
4157
|
+
this.#manageResize(add);
|
|
4182
4158
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
4183
4159
|
};
|
|
4184
|
-
|
|
4185
|
-
const handlers = this
|
|
4160
|
+
#manageResize = add => {
|
|
4161
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
4186
4162
|
if (!options.resize.enable) {
|
|
4187
4163
|
return;
|
|
4188
4164
|
}
|
|
@@ -4191,22 +4167,22 @@
|
|
|
4191
4167
|
return;
|
|
4192
4168
|
}
|
|
4193
4169
|
const canvasEl = container.canvas.domElement;
|
|
4194
|
-
if (this
|
|
4170
|
+
if (this.#resizeObserver && !add) {
|
|
4195
4171
|
if (canvasEl) {
|
|
4196
|
-
this.
|
|
4172
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
4197
4173
|
}
|
|
4198
|
-
this.
|
|
4199
|
-
|
|
4174
|
+
this.#resizeObserver.disconnect();
|
|
4175
|
+
this.#resizeObserver = undefined;
|
|
4200
4176
|
}
|
|
4201
|
-
else if (!this
|
|
4202
|
-
this
|
|
4177
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4178
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4203
4179
|
const entry = entries.find(e => e.target === canvasEl);
|
|
4204
4180
|
if (!entry) {
|
|
4205
4181
|
return;
|
|
4206
4182
|
}
|
|
4207
|
-
this
|
|
4183
|
+
this.#handleWindowResize();
|
|
4208
4184
|
});
|
|
4209
|
-
this.
|
|
4185
|
+
this.#resizeObserver.observe(canvasEl);
|
|
4210
4186
|
}
|
|
4211
4187
|
};
|
|
4212
4188
|
}
|
|
@@ -4279,24 +4255,24 @@
|
|
|
4279
4255
|
unbreakable;
|
|
4280
4256
|
velocity;
|
|
4281
4257
|
zIndexFactor;
|
|
4282
|
-
|
|
4258
|
+
#cachedOpacityData = {
|
|
4283
4259
|
fillOpacity: defaultOpacity$1,
|
|
4284
4260
|
opacity: defaultOpacity$1,
|
|
4285
4261
|
strokeOpacity: defaultOpacity$1,
|
|
4286
4262
|
};
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4263
|
+
#cachedPosition = Vector3d.origin;
|
|
4264
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
4265
|
+
#cachedTransform = {
|
|
4290
4266
|
a: 1,
|
|
4291
4267
|
b: 0,
|
|
4292
4268
|
c: 0,
|
|
4293
4269
|
d: 1,
|
|
4294
4270
|
};
|
|
4295
|
-
|
|
4296
|
-
|
|
4271
|
+
#container;
|
|
4272
|
+
#pluginManager;
|
|
4297
4273
|
constructor(pluginManager, container) {
|
|
4298
|
-
this
|
|
4299
|
-
this
|
|
4274
|
+
this.#pluginManager = pluginManager;
|
|
4275
|
+
this.#container = container;
|
|
4300
4276
|
}
|
|
4301
4277
|
destroy(override) {
|
|
4302
4278
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -4305,7 +4281,7 @@
|
|
|
4305
4281
|
this.destroyed = true;
|
|
4306
4282
|
this.bubble.inRange = false;
|
|
4307
4283
|
this.slow.inRange = false;
|
|
4308
|
-
const container = this
|
|
4284
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
4309
4285
|
shapeDrawer?.particleDestroy?.(this);
|
|
4310
4286
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
4311
4287
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -4313,12 +4289,12 @@
|
|
|
4313
4289
|
for (const updater of container.particleUpdaters) {
|
|
4314
4290
|
updater.particleDestroyed?.(this, override);
|
|
4315
4291
|
}
|
|
4316
|
-
this.
|
|
4292
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
4317
4293
|
particle: this,
|
|
4318
4294
|
});
|
|
4319
4295
|
}
|
|
4320
4296
|
draw(delta) {
|
|
4321
|
-
const container = this
|
|
4297
|
+
const container = this.#container, render = container.canvas.render;
|
|
4322
4298
|
render.drawParticlePlugins(this, delta);
|
|
4323
4299
|
render.drawParticle(this, delta);
|
|
4324
4300
|
}
|
|
@@ -4326,50 +4302,50 @@
|
|
|
4326
4302
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
4327
4303
|
}
|
|
4328
4304
|
getFillColor() {
|
|
4329
|
-
return this
|
|
4305
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
4330
4306
|
}
|
|
4331
4307
|
getMass() {
|
|
4332
4308
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
4333
4309
|
}
|
|
4334
4310
|
getOpacity() {
|
|
4335
4311
|
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? getRangeValue(this.opacity?.value ?? defaultOpacity$1), fillOpacity = this.fillOpacity ?? defaultOpacity$1, strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
|
|
4336
|
-
this.
|
|
4337
|
-
this.
|
|
4338
|
-
this.
|
|
4339
|
-
return this
|
|
4312
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
4313
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
4314
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
4315
|
+
return this.#cachedOpacityData;
|
|
4340
4316
|
}
|
|
4341
4317
|
getPosition() {
|
|
4342
|
-
this.
|
|
4343
|
-
this.
|
|
4344
|
-
this.
|
|
4345
|
-
return this
|
|
4318
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
4319
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
4320
|
+
this.#cachedPosition.z = this.position.z;
|
|
4321
|
+
return this.#cachedPosition;
|
|
4346
4322
|
}
|
|
4347
4323
|
getRadius() {
|
|
4348
4324
|
return this.bubble.radius ?? this.size.value;
|
|
4349
4325
|
}
|
|
4350
4326
|
getRotateData() {
|
|
4351
4327
|
const angle = this.getAngle();
|
|
4352
|
-
this.
|
|
4353
|
-
this.
|
|
4354
|
-
return this
|
|
4328
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
4329
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
4330
|
+
return this.#cachedRotateData;
|
|
4355
4331
|
}
|
|
4356
4332
|
getStrokeColor() {
|
|
4357
|
-
return this
|
|
4333
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
4358
4334
|
}
|
|
4359
4335
|
getTransformData(externalTransform) {
|
|
4360
4336
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
4361
|
-
this.
|
|
4362
|
-
this.
|
|
4337
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
4338
|
+
this.#cachedTransform.b = rotating
|
|
4363
4339
|
? rotateData.sin * (externalTransform.b ?? identity)
|
|
4364
4340
|
: (externalTransform.b ?? defaultTransform.b);
|
|
4365
|
-
this.
|
|
4341
|
+
this.#cachedTransform.c = rotating
|
|
4366
4342
|
? -rotateData.sin * (externalTransform.c ?? identity)
|
|
4367
4343
|
: (externalTransform.c ?? defaultTransform.c);
|
|
4368
|
-
this.
|
|
4369
|
-
return this
|
|
4344
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
4345
|
+
return this.#cachedTransform;
|
|
4370
4346
|
}
|
|
4371
4347
|
init(id, position, overrideOptions, group) {
|
|
4372
|
-
const container = this
|
|
4348
|
+
const container = this.#container;
|
|
4373
4349
|
this.id = id;
|
|
4374
4350
|
this.group = group;
|
|
4375
4351
|
this.justWarped = false;
|
|
@@ -4389,21 +4365,27 @@
|
|
|
4389
4365
|
moveSpeed: 0,
|
|
4390
4366
|
sizeAnimationSpeed: 0,
|
|
4391
4367
|
};
|
|
4368
|
+
this.size = {
|
|
4369
|
+
value: 1,
|
|
4370
|
+
max: 1,
|
|
4371
|
+
min: 1,
|
|
4372
|
+
enable: false,
|
|
4373
|
+
};
|
|
4392
4374
|
this.outType = ParticleOutType.normal;
|
|
4393
4375
|
this.ignoresResizeRatio = true;
|
|
4394
|
-
const
|
|
4376
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
4395
4377
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
4396
4378
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
4397
4379
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
4398
4380
|
if (overrideOptions) {
|
|
4399
|
-
if (overrideOptions.effect?.type) {
|
|
4381
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
4400
4382
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
4401
4383
|
if (effect) {
|
|
4402
4384
|
this.effect = effect;
|
|
4403
4385
|
effectOptions.load(overrideOptions.effect);
|
|
4404
4386
|
}
|
|
4405
4387
|
}
|
|
4406
|
-
if (overrideOptions.shape?.type) {
|
|
4388
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
4407
4389
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
4408
4390
|
if (shape) {
|
|
4409
4391
|
this.shape = shape;
|
|
@@ -4412,21 +4394,20 @@
|
|
|
4412
4394
|
}
|
|
4413
4395
|
}
|
|
4414
4396
|
if (this.effect === randomColorValue) {
|
|
4415
|
-
const availableEffects = [...this.
|
|
4397
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
4416
4398
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
4417
4399
|
}
|
|
4418
4400
|
if (this.shape === randomColorValue) {
|
|
4419
|
-
const availableShapes = [...this.
|
|
4401
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
4420
4402
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
4421
4403
|
}
|
|
4422
4404
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
4423
4405
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
4424
4406
|
particlesOptions.load(overrideOptions);
|
|
4425
|
-
const effectData = this.effectData;
|
|
4407
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
4426
4408
|
if (effectData) {
|
|
4427
4409
|
particlesOptions.load(effectData.particles);
|
|
4428
4410
|
}
|
|
4429
|
-
const shapeData = this.shapeData;
|
|
4430
4411
|
if (shapeData) {
|
|
4431
4412
|
particlesOptions.load(shapeData.particles);
|
|
4432
4413
|
}
|
|
@@ -4434,7 +4415,9 @@
|
|
|
4434
4415
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
4435
4416
|
this.options = particlesOptions;
|
|
4436
4417
|
container.retina.initParticle(this);
|
|
4437
|
-
|
|
4418
|
+
for (const updater of container.particleUpdaters) {
|
|
4419
|
+
updater.preInit?.(this);
|
|
4420
|
+
}
|
|
4438
4421
|
this.bubble = {
|
|
4439
4422
|
inRange: false,
|
|
4440
4423
|
};
|
|
@@ -4442,8 +4425,8 @@
|
|
|
4442
4425
|
inRange: false,
|
|
4443
4426
|
factor: 1,
|
|
4444
4427
|
};
|
|
4445
|
-
this
|
|
4446
|
-
this.initialVelocity = this
|
|
4428
|
+
this.#initPosition(position);
|
|
4429
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
4447
4430
|
this.velocity = this.initialVelocity.copy();
|
|
4448
4431
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
4449
4432
|
this.sides = 24;
|
|
@@ -4474,12 +4457,11 @@
|
|
|
4474
4457
|
plugin.particleCreated?.(this);
|
|
4475
4458
|
}
|
|
4476
4459
|
}
|
|
4477
|
-
isInsideCanvas() {
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
position.x <= canvasSize.width + radius);
|
|
4460
|
+
isInsideCanvas(direction) {
|
|
4461
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
4462
|
+
}
|
|
4463
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
4464
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
4483
4465
|
}
|
|
4484
4466
|
isShowingBack() {
|
|
4485
4467
|
if (!this.roll) {
|
|
@@ -4504,13 +4486,13 @@
|
|
|
4504
4486
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
4505
4487
|
}
|
|
4506
4488
|
reset() {
|
|
4507
|
-
for (const updater of this.
|
|
4489
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4508
4490
|
updater.reset?.(this);
|
|
4509
4491
|
}
|
|
4510
4492
|
}
|
|
4511
|
-
|
|
4493
|
+
#calcPosition = (position, zIndex) => {
|
|
4512
4494
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
4513
|
-
const container = this
|
|
4495
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
4514
4496
|
while (!signal.aborted) {
|
|
4515
4497
|
for (const plugin of plugins) {
|
|
4516
4498
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -4522,10 +4504,10 @@
|
|
|
4522
4504
|
size: canvasSize,
|
|
4523
4505
|
position: posVec,
|
|
4524
4506
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
4525
|
-
this
|
|
4526
|
-
this
|
|
4527
|
-
this
|
|
4528
|
-
this
|
|
4507
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
4508
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
4509
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
4510
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
4529
4511
|
let isValidPosition = true;
|
|
4530
4512
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
4531
4513
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -4541,8 +4523,8 @@
|
|
|
4541
4523
|
}
|
|
4542
4524
|
return posVec;
|
|
4543
4525
|
};
|
|
4544
|
-
|
|
4545
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
4526
|
+
#calculateVelocity = () => {
|
|
4527
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
4546
4528
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
4547
4529
|
return res;
|
|
4548
4530
|
}
|
|
@@ -4558,27 +4540,86 @@
|
|
|
4558
4540
|
}
|
|
4559
4541
|
return res;
|
|
4560
4542
|
};
|
|
4561
|
-
|
|
4543
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
4562
4544
|
fixOutMode({
|
|
4563
4545
|
outMode,
|
|
4564
4546
|
checkModes: [OutMode.bounce],
|
|
4565
4547
|
coord: pos.x,
|
|
4566
|
-
maxCoord: this.
|
|
4548
|
+
maxCoord: this.#container.canvas.size.width,
|
|
4567
4549
|
setCb: (value) => (pos.x += value),
|
|
4568
4550
|
radius,
|
|
4569
4551
|
});
|
|
4570
4552
|
};
|
|
4571
|
-
|
|
4553
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
4572
4554
|
fixOutMode({
|
|
4573
4555
|
outMode,
|
|
4574
4556
|
checkModes: [OutMode.bounce],
|
|
4575
4557
|
coord: pos.y,
|
|
4576
|
-
maxCoord: this.
|
|
4558
|
+
maxCoord: this.#container.canvas.size.height,
|
|
4577
4559
|
setCb: (value) => (pos.y += value),
|
|
4578
4560
|
radius,
|
|
4579
4561
|
});
|
|
4580
4562
|
};
|
|
4581
|
-
|
|
4563
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
4564
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
4565
|
+
if (direction === OutModeDirection.bottom) {
|
|
4566
|
+
return {
|
|
4567
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
4568
|
+
reason: "default",
|
|
4569
|
+
};
|
|
4570
|
+
}
|
|
4571
|
+
if (direction === OutModeDirection.left) {
|
|
4572
|
+
return {
|
|
4573
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
4574
|
+
reason: "default",
|
|
4575
|
+
};
|
|
4576
|
+
}
|
|
4577
|
+
if (direction === OutModeDirection.right) {
|
|
4578
|
+
return {
|
|
4579
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
4580
|
+
reason: "default",
|
|
4581
|
+
};
|
|
4582
|
+
}
|
|
4583
|
+
if (direction === OutModeDirection.top) {
|
|
4584
|
+
return {
|
|
4585
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
4586
|
+
reason: "default",
|
|
4587
|
+
};
|
|
4588
|
+
}
|
|
4589
|
+
return {
|
|
4590
|
+
inside: position.x >= -radius &&
|
|
4591
|
+
position.y >= -radius &&
|
|
4592
|
+
position.y <= canvasSize.height + radius &&
|
|
4593
|
+
position.x <= canvasSize.width + radius,
|
|
4594
|
+
reason: "default",
|
|
4595
|
+
};
|
|
4596
|
+
};
|
|
4597
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
4598
|
+
return {
|
|
4599
|
+
canvasSize: this.#container.canvas.size,
|
|
4600
|
+
direction,
|
|
4601
|
+
outMode,
|
|
4602
|
+
particle: this,
|
|
4603
|
+
radius: this.getRadius(),
|
|
4604
|
+
};
|
|
4605
|
+
};
|
|
4606
|
+
#getInsideCanvasResult = (data) => {
|
|
4607
|
+
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;
|
|
4608
|
+
if (!shapeCheck && !effectCheck) {
|
|
4609
|
+
return defaultResult;
|
|
4610
|
+
}
|
|
4611
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
4612
|
+
if (shapeResult && effectResult) {
|
|
4613
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
4614
|
+
return {
|
|
4615
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
4616
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
4617
|
+
reason: "combined",
|
|
4618
|
+
};
|
|
4619
|
+
}
|
|
4620
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
4621
|
+
};
|
|
4622
|
+
#getRollColor = color => {
|
|
4582
4623
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
4583
4624
|
return color;
|
|
4584
4625
|
}
|
|
@@ -4593,8 +4634,8 @@
|
|
|
4593
4634
|
}
|
|
4594
4635
|
return color;
|
|
4595
4636
|
};
|
|
4596
|
-
|
|
4597
|
-
const container = this
|
|
4637
|
+
#initPosition = position => {
|
|
4638
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
4598
4639
|
if (!initialPosition) {
|
|
4599
4640
|
throw new Error("a valid position cannot be found for particle");
|
|
4600
4641
|
}
|
|
@@ -4617,45 +4658,58 @@
|
|
|
4617
4658
|
}
|
|
4618
4659
|
this.offset = Vector.origin;
|
|
4619
4660
|
};
|
|
4661
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
4662
|
+
if (typeof result === "boolean") {
|
|
4663
|
+
return {
|
|
4664
|
+
inside: result,
|
|
4665
|
+
reason,
|
|
4666
|
+
};
|
|
4667
|
+
}
|
|
4668
|
+
return {
|
|
4669
|
+
inside: result.inside,
|
|
4670
|
+
margin: result.margin,
|
|
4671
|
+
reason: result.reason ?? reason,
|
|
4672
|
+
};
|
|
4673
|
+
};
|
|
4620
4674
|
}
|
|
4621
4675
|
|
|
4622
4676
|
class SpatialHashGrid {
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4677
|
+
#cellSize;
|
|
4678
|
+
#cells = new Map();
|
|
4679
|
+
#circlePool = [];
|
|
4680
|
+
#circlePoolIdx;
|
|
4681
|
+
#pendingCellSize;
|
|
4682
|
+
#rectanglePool = [];
|
|
4683
|
+
#rectanglePoolIdx;
|
|
4630
4684
|
constructor(cellSize) {
|
|
4631
|
-
this
|
|
4632
|
-
this
|
|
4633
|
-
this
|
|
4685
|
+
this.#cellSize = cellSize;
|
|
4686
|
+
this.#circlePoolIdx = 0;
|
|
4687
|
+
this.#rectanglePoolIdx = 0;
|
|
4634
4688
|
}
|
|
4635
4689
|
clear() {
|
|
4636
|
-
this.
|
|
4637
|
-
const pendingCellSize = this
|
|
4690
|
+
this.#cells.clear();
|
|
4691
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
4638
4692
|
if (pendingCellSize) {
|
|
4639
|
-
this
|
|
4693
|
+
this.#cellSize = pendingCellSize;
|
|
4640
4694
|
}
|
|
4641
|
-
this
|
|
4695
|
+
this.#pendingCellSize = undefined;
|
|
4642
4696
|
}
|
|
4643
4697
|
insert(particle) {
|
|
4644
|
-
const { x, y } = particle.getPosition(), key = this
|
|
4645
|
-
if (!this.
|
|
4646
|
-
this.
|
|
4698
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
4699
|
+
if (!this.#cells.has(key)) {
|
|
4700
|
+
this.#cells.set(key, []);
|
|
4647
4701
|
}
|
|
4648
|
-
this.
|
|
4702
|
+
this.#cells.get(key)?.push(particle);
|
|
4649
4703
|
}
|
|
4650
4704
|
query(range, check, out = []) {
|
|
4651
|
-
const bounds = this
|
|
4705
|
+
const bounds = this.#getRangeBounds(range);
|
|
4652
4706
|
if (!bounds) {
|
|
4653
4707
|
return out;
|
|
4654
4708
|
}
|
|
4655
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
4709
|
+
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);
|
|
4656
4710
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
4657
4711
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
4658
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
4712
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
4659
4713
|
if (!cellParticles) {
|
|
4660
4714
|
continue;
|
|
4661
4715
|
}
|
|
@@ -4672,29 +4726,29 @@
|
|
|
4672
4726
|
return out;
|
|
4673
4727
|
}
|
|
4674
4728
|
queryCircle(position, radius, check, out = []) {
|
|
4675
|
-
const circle = this
|
|
4676
|
-
this
|
|
4729
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
4730
|
+
this.#releaseShapes();
|
|
4677
4731
|
return result;
|
|
4678
4732
|
}
|
|
4679
4733
|
queryRectangle(position, size, check, out = []) {
|
|
4680
|
-
const rect = this
|
|
4681
|
-
this
|
|
4734
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
4735
|
+
this.#releaseShapes();
|
|
4682
4736
|
return result;
|
|
4683
4737
|
}
|
|
4684
4738
|
setCellSize(cellSize) {
|
|
4685
|
-
this
|
|
4739
|
+
this.#pendingCellSize = cellSize;
|
|
4686
4740
|
}
|
|
4687
|
-
|
|
4688
|
-
return (this
|
|
4741
|
+
#acquireCircle(x, y, r) {
|
|
4742
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
4689
4743
|
}
|
|
4690
|
-
|
|
4691
|
-
return (this
|
|
4744
|
+
#acquireRectangle(x, y, w, h) {
|
|
4745
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
4692
4746
|
}
|
|
4693
|
-
|
|
4694
|
-
const cellX = Math.floor(x / this
|
|
4747
|
+
#cellKeyFromCoords(x, y) {
|
|
4748
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
4695
4749
|
return `${cellX}_${cellY}`;
|
|
4696
4750
|
}
|
|
4697
|
-
|
|
4751
|
+
#getRangeBounds(range) {
|
|
4698
4752
|
if (range instanceof Circle) {
|
|
4699
4753
|
const r = range.radius, { x, y } = range.position;
|
|
4700
4754
|
return {
|
|
@@ -4715,53 +4769,53 @@
|
|
|
4715
4769
|
}
|
|
4716
4770
|
return null;
|
|
4717
4771
|
}
|
|
4718
|
-
|
|
4719
|
-
this
|
|
4720
|
-
this
|
|
4772
|
+
#releaseShapes() {
|
|
4773
|
+
this.#circlePoolIdx = 0;
|
|
4774
|
+
this.#rectanglePoolIdx = 0;
|
|
4721
4775
|
}
|
|
4722
4776
|
}
|
|
4723
4777
|
|
|
4724
4778
|
class ParticlesManager {
|
|
4725
4779
|
checkParticlePositionPlugins;
|
|
4726
4780
|
grid;
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4781
|
+
#array;
|
|
4782
|
+
#container;
|
|
4783
|
+
#groupLimits;
|
|
4784
|
+
#limit;
|
|
4785
|
+
#nextId;
|
|
4786
|
+
#particleBuckets;
|
|
4787
|
+
#particleResetPlugins;
|
|
4788
|
+
#particleUpdatePlugins;
|
|
4789
|
+
#pluginManager;
|
|
4790
|
+
#pool;
|
|
4791
|
+
#postParticleUpdatePlugins;
|
|
4792
|
+
#postUpdatePlugins;
|
|
4793
|
+
#resizeFactor;
|
|
4794
|
+
#updatePlugins;
|
|
4795
|
+
#zBuckets;
|
|
4742
4796
|
constructor(pluginManager, container) {
|
|
4743
|
-
this
|
|
4744
|
-
this
|
|
4745
|
-
this
|
|
4746
|
-
this
|
|
4747
|
-
this
|
|
4748
|
-
this
|
|
4749
|
-
this
|
|
4750
|
-
this
|
|
4751
|
-
this
|
|
4797
|
+
this.#pluginManager = pluginManager;
|
|
4798
|
+
this.#container = container;
|
|
4799
|
+
this.#nextId = 0;
|
|
4800
|
+
this.#array = [];
|
|
4801
|
+
this.#pool = [];
|
|
4802
|
+
this.#limit = 0;
|
|
4803
|
+
this.#groupLimits = new Map();
|
|
4804
|
+
this.#particleBuckets = new Map();
|
|
4805
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
4752
4806
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
4753
4807
|
this.checkParticlePositionPlugins = [];
|
|
4754
|
-
this
|
|
4755
|
-
this
|
|
4756
|
-
this
|
|
4757
|
-
this
|
|
4758
|
-
this
|
|
4808
|
+
this.#particleResetPlugins = [];
|
|
4809
|
+
this.#particleUpdatePlugins = [];
|
|
4810
|
+
this.#postUpdatePlugins = [];
|
|
4811
|
+
this.#postParticleUpdatePlugins = [];
|
|
4812
|
+
this.#updatePlugins = [];
|
|
4759
4813
|
}
|
|
4760
4814
|
get count() {
|
|
4761
|
-
return this.
|
|
4815
|
+
return this.#array.length;
|
|
4762
4816
|
}
|
|
4763
4817
|
addParticle(position, overrideOptions, group, initializer) {
|
|
4764
|
-
const limitMode = this.
|
|
4818
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
4765
4819
|
if (limit > minLimit) {
|
|
4766
4820
|
switch (limitMode) {
|
|
4767
4821
|
case LimitMode.delete: {
|
|
@@ -4779,20 +4833,20 @@
|
|
|
4779
4833
|
}
|
|
4780
4834
|
}
|
|
4781
4835
|
try {
|
|
4782
|
-
const particle = this.
|
|
4783
|
-
particle.init(this
|
|
4836
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
4837
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
4784
4838
|
let canAdd = true;
|
|
4785
4839
|
if (initializer) {
|
|
4786
4840
|
canAdd = initializer(particle);
|
|
4787
4841
|
}
|
|
4788
4842
|
if (!canAdd) {
|
|
4789
|
-
this.
|
|
4843
|
+
this.#pool.push(particle);
|
|
4790
4844
|
return;
|
|
4791
4845
|
}
|
|
4792
|
-
this.
|
|
4793
|
-
this
|
|
4794
|
-
this
|
|
4795
|
-
this.
|
|
4846
|
+
this.#array.push(particle);
|
|
4847
|
+
this.#insertParticleIntoBucket(particle);
|
|
4848
|
+
this.#nextId++;
|
|
4849
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
4796
4850
|
particle,
|
|
4797
4851
|
});
|
|
4798
4852
|
return particle;
|
|
@@ -4803,25 +4857,25 @@
|
|
|
4803
4857
|
return undefined;
|
|
4804
4858
|
}
|
|
4805
4859
|
clear() {
|
|
4806
|
-
this
|
|
4807
|
-
this.
|
|
4808
|
-
this
|
|
4860
|
+
this.#array = [];
|
|
4861
|
+
this.#particleBuckets.clear();
|
|
4862
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
4809
4863
|
}
|
|
4810
4864
|
destroy() {
|
|
4811
|
-
this
|
|
4812
|
-
this.
|
|
4813
|
-
this.
|
|
4814
|
-
this
|
|
4865
|
+
this.#array = [];
|
|
4866
|
+
this.#pool.length = 0;
|
|
4867
|
+
this.#particleBuckets.clear();
|
|
4868
|
+
this.#zBuckets = [];
|
|
4815
4869
|
this.checkParticlePositionPlugins = [];
|
|
4816
|
-
this
|
|
4817
|
-
this
|
|
4818
|
-
this
|
|
4819
|
-
this
|
|
4820
|
-
this
|
|
4870
|
+
this.#particleResetPlugins = [];
|
|
4871
|
+
this.#particleUpdatePlugins = [];
|
|
4872
|
+
this.#postUpdatePlugins = [];
|
|
4873
|
+
this.#postParticleUpdatePlugins = [];
|
|
4874
|
+
this.#updatePlugins = [];
|
|
4821
4875
|
}
|
|
4822
4876
|
drawParticles(delta) {
|
|
4823
|
-
for (let i = this.
|
|
4824
|
-
const bucket = this
|
|
4877
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
4878
|
+
const bucket = this.#zBuckets[i];
|
|
4825
4879
|
if (!bucket) {
|
|
4826
4880
|
continue;
|
|
4827
4881
|
}
|
|
@@ -4831,24 +4885,24 @@
|
|
|
4831
4885
|
}
|
|
4832
4886
|
}
|
|
4833
4887
|
filter(condition) {
|
|
4834
|
-
return this.
|
|
4888
|
+
return this.#array.filter(condition);
|
|
4835
4889
|
}
|
|
4836
4890
|
find(condition) {
|
|
4837
|
-
return this.
|
|
4891
|
+
return this.#array.find(condition);
|
|
4838
4892
|
}
|
|
4839
4893
|
get(index) {
|
|
4840
|
-
return this
|
|
4894
|
+
return this.#array[index];
|
|
4841
4895
|
}
|
|
4842
4896
|
async init() {
|
|
4843
|
-
const container = this
|
|
4897
|
+
const container = this.#container, options = container.actualOptions;
|
|
4844
4898
|
this.checkParticlePositionPlugins = [];
|
|
4845
|
-
this
|
|
4846
|
-
this
|
|
4847
|
-
this
|
|
4848
|
-
this
|
|
4849
|
-
this
|
|
4850
|
-
this.
|
|
4851
|
-
this
|
|
4899
|
+
this.#updatePlugins = [];
|
|
4900
|
+
this.#particleUpdatePlugins = [];
|
|
4901
|
+
this.#postUpdatePlugins = [];
|
|
4902
|
+
this.#particleResetPlugins = [];
|
|
4903
|
+
this.#postParticleUpdatePlugins = [];
|
|
4904
|
+
this.#particleBuckets.clear();
|
|
4905
|
+
this.#resetBuckets(container.zLayers);
|
|
4852
4906
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
4853
4907
|
for (const plugin of container.plugins) {
|
|
4854
4908
|
if (plugin.redrawInit) {
|
|
@@ -4858,26 +4912,26 @@
|
|
|
4858
4912
|
this.checkParticlePositionPlugins.push(plugin);
|
|
4859
4913
|
}
|
|
4860
4914
|
if (plugin.update) {
|
|
4861
|
-
this.
|
|
4915
|
+
this.#updatePlugins.push(plugin);
|
|
4862
4916
|
}
|
|
4863
4917
|
if (plugin.particleUpdate) {
|
|
4864
|
-
this.
|
|
4918
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
4865
4919
|
}
|
|
4866
4920
|
if (plugin.postUpdate) {
|
|
4867
|
-
this.
|
|
4921
|
+
this.#postUpdatePlugins.push(plugin);
|
|
4868
4922
|
}
|
|
4869
4923
|
if (plugin.particleReset) {
|
|
4870
|
-
this.
|
|
4924
|
+
this.#particleResetPlugins.push(plugin);
|
|
4871
4925
|
}
|
|
4872
4926
|
if (plugin.postParticleUpdate) {
|
|
4873
|
-
this.
|
|
4927
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
4874
4928
|
}
|
|
4875
4929
|
}
|
|
4876
|
-
await this.
|
|
4877
|
-
for (const drawer of this.
|
|
4930
|
+
await this.#container.initDrawersAndUpdaters();
|
|
4931
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
4878
4932
|
await drawer.init?.(container);
|
|
4879
4933
|
}
|
|
4880
|
-
for (const drawer of this.
|
|
4934
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
4881
4935
|
await drawer.init?.(container);
|
|
4882
4936
|
}
|
|
4883
4937
|
let handled = false;
|
|
@@ -4911,10 +4965,10 @@
|
|
|
4911
4965
|
async redraw() {
|
|
4912
4966
|
this.clear();
|
|
4913
4967
|
await this.init();
|
|
4914
|
-
this.
|
|
4968
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
4915
4969
|
}
|
|
4916
4970
|
remove(particle, group, override) {
|
|
4917
|
-
this.removeAt(this.
|
|
4971
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
4918
4972
|
}
|
|
4919
4973
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
4920
4974
|
if (index < minIndex || index > this.count) {
|
|
@@ -4922,7 +4976,7 @@
|
|
|
4922
4976
|
}
|
|
4923
4977
|
let deleted = 0;
|
|
4924
4978
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
4925
|
-
if (this
|
|
4979
|
+
if (this.#removeParticle(i, group, override)) {
|
|
4926
4980
|
i--;
|
|
4927
4981
|
deleted++;
|
|
4928
4982
|
}
|
|
@@ -4932,9 +4986,9 @@
|
|
|
4932
4986
|
this.removeAt(minIndex, quantity, group);
|
|
4933
4987
|
}
|
|
4934
4988
|
setDensity() {
|
|
4935
|
-
const options = this.
|
|
4989
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
4936
4990
|
let pluginsCount = 0;
|
|
4937
|
-
for (const plugin of this.
|
|
4991
|
+
for (const plugin of this.#container.plugins) {
|
|
4938
4992
|
if (plugin.particlesDensityCount) {
|
|
4939
4993
|
pluginsCount += plugin.particlesDensityCount();
|
|
4940
4994
|
}
|
|
@@ -4944,51 +4998,51 @@
|
|
|
4944
4998
|
if (!groupData) {
|
|
4945
4999
|
continue;
|
|
4946
5000
|
}
|
|
4947
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
4948
|
-
this
|
|
5001
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5002
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
4949
5003
|
}
|
|
4950
|
-
this
|
|
5004
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
4951
5005
|
}
|
|
4952
5006
|
setResizeFactor(factor) {
|
|
4953
|
-
this
|
|
5007
|
+
this.#resizeFactor = factor;
|
|
4954
5008
|
}
|
|
4955
5009
|
update(delta) {
|
|
4956
5010
|
this.grid.clear();
|
|
4957
|
-
for (const plugin of this
|
|
5011
|
+
for (const plugin of this.#updatePlugins) {
|
|
4958
5012
|
plugin.update?.(delta);
|
|
4959
5013
|
}
|
|
4960
|
-
const particlesToDelete = this
|
|
4961
|
-
for (const plugin of this
|
|
5014
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5015
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
4962
5016
|
plugin.postUpdate?.(delta);
|
|
4963
5017
|
}
|
|
4964
|
-
this
|
|
5018
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
4965
5019
|
if (particlesToDelete.size) {
|
|
4966
5020
|
for (const particle of particlesToDelete) {
|
|
4967
5021
|
this.remove(particle);
|
|
4968
5022
|
}
|
|
4969
5023
|
}
|
|
4970
|
-
|
|
5024
|
+
this.#resizeFactor = undefined;
|
|
4971
5025
|
}
|
|
4972
|
-
|
|
4973
|
-
this.
|
|
5026
|
+
#addToPool = (...particles) => {
|
|
5027
|
+
this.#pool.push(...particles);
|
|
4974
5028
|
};
|
|
4975
|
-
|
|
5029
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
4976
5030
|
const numberOptions = options.number;
|
|
4977
5031
|
if (!numberOptions.density.enable) {
|
|
4978
5032
|
if (group === undefined) {
|
|
4979
|
-
this
|
|
5033
|
+
this.#limit = numberOptions.limit.value;
|
|
4980
5034
|
}
|
|
4981
5035
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
4982
|
-
this.
|
|
5036
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
4983
5037
|
}
|
|
4984
5038
|
return;
|
|
4985
5039
|
}
|
|
4986
|
-
const densityFactor = this
|
|
5040
|
+
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);
|
|
4987
5041
|
if (group === undefined) {
|
|
4988
|
-
this
|
|
5042
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
4989
5043
|
}
|
|
4990
5044
|
else {
|
|
4991
|
-
this.
|
|
5045
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
4992
5046
|
}
|
|
4993
5047
|
if (particlesCount < particlesNumber) {
|
|
4994
5048
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -4997,18 +5051,18 @@
|
|
|
4997
5051
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
4998
5052
|
}
|
|
4999
5053
|
};
|
|
5000
|
-
|
|
5054
|
+
#createBuckets = (zLayers) => {
|
|
5001
5055
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5002
5056
|
return Array.from({ length: bucketCount }, () => []);
|
|
5003
5057
|
};
|
|
5004
|
-
|
|
5005
|
-
const maxBucketIndex = this.
|
|
5058
|
+
#getBucketIndex = (zIndex) => {
|
|
5059
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5006
5060
|
if (maxBucketIndex <= minIndex) {
|
|
5007
5061
|
return minIndex;
|
|
5008
5062
|
}
|
|
5009
5063
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5010
5064
|
};
|
|
5011
|
-
|
|
5065
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5012
5066
|
let start = minIndex, end = bucket.length;
|
|
5013
5067
|
while (start < end) {
|
|
5014
5068
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5025,8 +5079,8 @@
|
|
|
5025
5079
|
}
|
|
5026
5080
|
return start;
|
|
5027
5081
|
};
|
|
5028
|
-
|
|
5029
|
-
const container = this
|
|
5082
|
+
#initDensityFactor = densityOptions => {
|
|
5083
|
+
const container = this.#container;
|
|
5030
5084
|
if (!densityOptions.enable) {
|
|
5031
5085
|
return defaultDensityFactor;
|
|
5032
5086
|
}
|
|
@@ -5036,82 +5090,82 @@
|
|
|
5036
5090
|
}
|
|
5037
5091
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5038
5092
|
};
|
|
5039
|
-
|
|
5040
|
-
const bucketIndex = this
|
|
5093
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5094
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5041
5095
|
if (!bucket) {
|
|
5042
5096
|
return;
|
|
5043
5097
|
}
|
|
5044
|
-
bucket.splice(this
|
|
5045
|
-
this.
|
|
5098
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5099
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5046
5100
|
};
|
|
5047
|
-
|
|
5048
|
-
const particle = this
|
|
5101
|
+
#removeParticle = (index, group, override) => {
|
|
5102
|
+
const particle = this.#array[index];
|
|
5049
5103
|
if (!particle) {
|
|
5050
5104
|
return false;
|
|
5051
5105
|
}
|
|
5052
5106
|
if (particle.group !== group) {
|
|
5053
5107
|
return false;
|
|
5054
5108
|
}
|
|
5055
|
-
this.
|
|
5056
|
-
this
|
|
5109
|
+
this.#array.splice(index, deleteCount);
|
|
5110
|
+
this.#removeParticleFromBucket(particle);
|
|
5057
5111
|
particle.destroy(override);
|
|
5058
|
-
this.
|
|
5112
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5059
5113
|
particle,
|
|
5060
5114
|
});
|
|
5061
|
-
this
|
|
5115
|
+
this.#addToPool(particle);
|
|
5062
5116
|
return true;
|
|
5063
5117
|
};
|
|
5064
|
-
|
|
5065
|
-
const bucketIndex = this.
|
|
5118
|
+
#removeParticleFromBucket = (particle) => {
|
|
5119
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5066
5120
|
if (!bucket) {
|
|
5067
|
-
this.
|
|
5121
|
+
this.#particleBuckets.delete(particle.id);
|
|
5068
5122
|
return;
|
|
5069
5123
|
}
|
|
5070
|
-
const particleIndex = this
|
|
5124
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5071
5125
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5072
|
-
this.
|
|
5126
|
+
this.#particleBuckets.delete(particle.id);
|
|
5073
5127
|
return;
|
|
5074
5128
|
}
|
|
5075
5129
|
bucket.splice(particleIndex, deleteCount);
|
|
5076
|
-
this.
|
|
5130
|
+
this.#particleBuckets.delete(particle.id);
|
|
5077
5131
|
};
|
|
5078
|
-
|
|
5132
|
+
#resetBuckets = (zLayers) => {
|
|
5079
5133
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5080
|
-
if (this.
|
|
5081
|
-
this
|
|
5134
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
5135
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5082
5136
|
return;
|
|
5083
5137
|
}
|
|
5084
|
-
for (const bucket of this
|
|
5138
|
+
for (const bucket of this.#zBuckets) {
|
|
5085
5139
|
bucket.length = minIndex;
|
|
5086
5140
|
}
|
|
5087
5141
|
};
|
|
5088
|
-
|
|
5089
|
-
const newBucketIndex = this
|
|
5142
|
+
#updateParticleBucket = (particle) => {
|
|
5143
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5090
5144
|
if (currentBucketIndex === undefined) {
|
|
5091
|
-
this
|
|
5145
|
+
this.#insertParticleIntoBucket(particle);
|
|
5092
5146
|
return;
|
|
5093
5147
|
}
|
|
5094
5148
|
if (currentBucketIndex === newBucketIndex) {
|
|
5095
5149
|
return;
|
|
5096
5150
|
}
|
|
5097
|
-
const currentBucket = this
|
|
5151
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5098
5152
|
if (currentBucket) {
|
|
5099
|
-
const particleIndex = this
|
|
5153
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5100
5154
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5101
5155
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5102
5156
|
}
|
|
5103
5157
|
}
|
|
5104
|
-
const newBucket = this
|
|
5158
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5105
5159
|
if (!newBucket) {
|
|
5106
|
-
this.
|
|
5160
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5107
5161
|
return;
|
|
5108
5162
|
}
|
|
5109
|
-
newBucket.splice(this
|
|
5110
|
-
this.
|
|
5163
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
5164
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5111
5165
|
};
|
|
5112
|
-
|
|
5113
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5114
|
-
for (const particle of this
|
|
5166
|
+
#updateParticlesPhase1 = (delta) => {
|
|
5167
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
5168
|
+
for (const particle of this.#array) {
|
|
5115
5169
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5116
5170
|
particle.position.x *= resizeFactor.width;
|
|
5117
5171
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5119,10 +5173,10 @@
|
|
|
5119
5173
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5120
5174
|
}
|
|
5121
5175
|
particle.ignoresResizeRatio = false;
|
|
5122
|
-
for (const plugin of this
|
|
5176
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5123
5177
|
plugin.particleReset?.(particle);
|
|
5124
5178
|
}
|
|
5125
|
-
for (const plugin of this
|
|
5179
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5126
5180
|
if (particle.destroyed) {
|
|
5127
5181
|
break;
|
|
5128
5182
|
}
|
|
@@ -5136,36 +5190,36 @@
|
|
|
5136
5190
|
}
|
|
5137
5191
|
return particlesToDelete;
|
|
5138
5192
|
};
|
|
5139
|
-
|
|
5140
|
-
for (const particle of this
|
|
5193
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
5194
|
+
for (const particle of this.#array) {
|
|
5141
5195
|
if (particle.destroyed) {
|
|
5142
5196
|
particlesToDelete.add(particle);
|
|
5143
5197
|
continue;
|
|
5144
5198
|
}
|
|
5145
|
-
for (const updater of this.
|
|
5199
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5146
5200
|
updater.update(particle, delta);
|
|
5147
5201
|
}
|
|
5148
5202
|
if (!particle.spawning) {
|
|
5149
|
-
for (const plugin of this
|
|
5203
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5150
5204
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5151
5205
|
}
|
|
5152
5206
|
}
|
|
5153
|
-
this
|
|
5207
|
+
this.#updateParticleBucket(particle);
|
|
5154
5208
|
}
|
|
5155
5209
|
};
|
|
5156
5210
|
}
|
|
5157
5211
|
|
|
5158
5212
|
class Retina {
|
|
5159
|
-
container;
|
|
5160
5213
|
pixelRatio;
|
|
5161
5214
|
reduceFactor;
|
|
5215
|
+
#container;
|
|
5162
5216
|
constructor(container) {
|
|
5163
|
-
this
|
|
5217
|
+
this.#container = container;
|
|
5164
5218
|
this.pixelRatio = defaultRatio;
|
|
5165
5219
|
this.reduceFactor = defaultReduceFactor;
|
|
5166
5220
|
}
|
|
5167
5221
|
init() {
|
|
5168
|
-
const container = this
|
|
5222
|
+
const container = this.#container, options = container.actualOptions;
|
|
5169
5223
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
5170
5224
|
this.reduceFactor = defaultReduceFactor;
|
|
5171
5225
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -5179,7 +5233,6 @@
|
|
|
5179
5233
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
5180
5234
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
5181
5235
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
5182
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
5183
5236
|
const maxDistance = props.maxDistance;
|
|
5184
5237
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
5185
5238
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -5217,73 +5270,73 @@
|
|
|
5217
5270
|
shapeDrawers;
|
|
5218
5271
|
started;
|
|
5219
5272
|
zLayers;
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5273
|
+
#delay;
|
|
5274
|
+
#delayTimeout;
|
|
5275
|
+
#delta = { value: 0, factor: 0 };
|
|
5276
|
+
#dispatchCallback;
|
|
5277
|
+
#drawAnimationFrame;
|
|
5278
|
+
#duration;
|
|
5279
|
+
#eventListeners;
|
|
5280
|
+
#firstStart;
|
|
5281
|
+
#initialSourceOptions;
|
|
5282
|
+
#lastFrameTime;
|
|
5283
|
+
#lifeTime;
|
|
5284
|
+
#onDestroy;
|
|
5285
|
+
#options;
|
|
5286
|
+
#paused;
|
|
5287
|
+
#pluginManager;
|
|
5288
|
+
#smooth;
|
|
5289
|
+
#sourceOptions;
|
|
5237
5290
|
constructor(params) {
|
|
5238
5291
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
5239
|
-
this
|
|
5240
|
-
this
|
|
5241
|
-
this
|
|
5292
|
+
this.#pluginManager = pluginManager;
|
|
5293
|
+
this.#dispatchCallback = dispatchCallback;
|
|
5294
|
+
this.#onDestroy = onDestroy;
|
|
5242
5295
|
this.id = Symbol(id);
|
|
5243
5296
|
this.fpsLimit = 120;
|
|
5244
5297
|
this.hdr = false;
|
|
5245
|
-
this
|
|
5246
|
-
this
|
|
5247
|
-
this
|
|
5248
|
-
this
|
|
5249
|
-
this
|
|
5298
|
+
this.#smooth = false;
|
|
5299
|
+
this.#delay = 0;
|
|
5300
|
+
this.#duration = 0;
|
|
5301
|
+
this.#lifeTime = 0;
|
|
5302
|
+
this.#firstStart = true;
|
|
5250
5303
|
this.started = false;
|
|
5251
5304
|
this.destroyed = false;
|
|
5252
|
-
this
|
|
5253
|
-
this
|
|
5305
|
+
this.#paused = true;
|
|
5306
|
+
this.#lastFrameTime = 0;
|
|
5254
5307
|
this.zLayers = 100;
|
|
5255
5308
|
this.pageHidden = false;
|
|
5256
|
-
this
|
|
5257
|
-
this
|
|
5309
|
+
this.#sourceOptions = sourceOptions;
|
|
5310
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5258
5311
|
this.effectDrawers = new Map();
|
|
5259
5312
|
this.shapeDrawers = new Map();
|
|
5260
5313
|
this.particleUpdaters = [];
|
|
5261
5314
|
this.retina = new Retina(this);
|
|
5262
|
-
this.canvas = new CanvasManager(this
|
|
5263
|
-
this.particles = new ParticlesManager(this
|
|
5315
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
5316
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
5264
5317
|
this.plugins = [];
|
|
5265
5318
|
this.particleDestroyedPlugins = [];
|
|
5266
5319
|
this.particleCreatedPlugins = [];
|
|
5267
5320
|
this.particlePositionPlugins = [];
|
|
5268
|
-
this
|
|
5269
|
-
this.actualOptions = loadContainerOptions(this
|
|
5270
|
-
this
|
|
5321
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
5322
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
5323
|
+
this.#eventListeners = new EventListeners(this);
|
|
5271
5324
|
this.dispatchEvent(EventType.containerBuilt);
|
|
5272
5325
|
}
|
|
5273
5326
|
get animationStatus() {
|
|
5274
|
-
return !this
|
|
5327
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
5275
5328
|
}
|
|
5276
5329
|
get options() {
|
|
5277
|
-
return this
|
|
5330
|
+
return this.#options;
|
|
5278
5331
|
}
|
|
5279
5332
|
get sourceOptions() {
|
|
5280
|
-
return this
|
|
5333
|
+
return this.#sourceOptions;
|
|
5281
5334
|
}
|
|
5282
5335
|
addLifeTime(value) {
|
|
5283
|
-
this
|
|
5336
|
+
this.#lifeTime += value;
|
|
5284
5337
|
}
|
|
5285
5338
|
alive() {
|
|
5286
|
-
return !this
|
|
5339
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
5287
5340
|
}
|
|
5288
5341
|
destroy(remove = true) {
|
|
5289
5342
|
if (!guardCheck(this)) {
|
|
@@ -5305,13 +5358,13 @@
|
|
|
5305
5358
|
this.shapeDrawers = new Map();
|
|
5306
5359
|
this.particleUpdaters = [];
|
|
5307
5360
|
this.plugins.length = 0;
|
|
5308
|
-
this.
|
|
5361
|
+
this.#pluginManager.clearPlugins(this);
|
|
5309
5362
|
this.destroyed = true;
|
|
5310
|
-
this
|
|
5363
|
+
this.#onDestroy(remove);
|
|
5311
5364
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
5312
5365
|
}
|
|
5313
5366
|
dispatchEvent(type, data) {
|
|
5314
|
-
this
|
|
5367
|
+
this.#dispatchCallback(type, {
|
|
5315
5368
|
container: this,
|
|
5316
5369
|
data,
|
|
5317
5370
|
});
|
|
@@ -5321,12 +5374,12 @@
|
|
|
5321
5374
|
return;
|
|
5322
5375
|
}
|
|
5323
5376
|
let refreshTime = force;
|
|
5324
|
-
this
|
|
5377
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
5325
5378
|
if (refreshTime) {
|
|
5326
|
-
this
|
|
5379
|
+
this.#lastFrameTime = undefined;
|
|
5327
5380
|
refreshTime = false;
|
|
5328
5381
|
}
|
|
5329
|
-
this
|
|
5382
|
+
this.#nextFrame(timestamp);
|
|
5330
5383
|
});
|
|
5331
5384
|
}
|
|
5332
5385
|
async export(type, options = {}) {
|
|
@@ -5348,7 +5401,7 @@
|
|
|
5348
5401
|
return;
|
|
5349
5402
|
}
|
|
5350
5403
|
const allContainerPlugins = new Map();
|
|
5351
|
-
for (const plugin of this.
|
|
5404
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
5352
5405
|
const containerPlugin = await plugin.getPlugin(this);
|
|
5353
5406
|
if (containerPlugin.preInit) {
|
|
5354
5407
|
await containerPlugin.preInit();
|
|
@@ -5356,8 +5409,8 @@
|
|
|
5356
5409
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
5357
5410
|
}
|
|
5358
5411
|
await this.initDrawersAndUpdaters();
|
|
5359
|
-
this
|
|
5360
|
-
this.actualOptions = loadContainerOptions(this
|
|
5412
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5413
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5361
5414
|
this.plugins.length = 0;
|
|
5362
5415
|
this.particleDestroyedPlugins.length = 0;
|
|
5363
5416
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -5384,11 +5437,11 @@
|
|
|
5384
5437
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
5385
5438
|
this.hdr = hdr;
|
|
5386
5439
|
this.zLayers = zLayers;
|
|
5387
|
-
this
|
|
5388
|
-
this
|
|
5389
|
-
this
|
|
5440
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
5441
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
5442
|
+
this.#lifeTime = 0;
|
|
5390
5443
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
5391
|
-
this
|
|
5444
|
+
this.#smooth = smooth;
|
|
5392
5445
|
for (const plugin of this.plugins) {
|
|
5393
5446
|
await plugin.init?.();
|
|
5394
5447
|
}
|
|
@@ -5401,7 +5454,7 @@
|
|
|
5401
5454
|
this.dispatchEvent(EventType.particlesSetup);
|
|
5402
5455
|
}
|
|
5403
5456
|
async initDrawersAndUpdaters() {
|
|
5404
|
-
const pluginManager = this
|
|
5457
|
+
const pluginManager = this.#pluginManager;
|
|
5405
5458
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
5406
5459
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
5407
5460
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -5410,18 +5463,18 @@
|
|
|
5410
5463
|
if (!guardCheck(this)) {
|
|
5411
5464
|
return;
|
|
5412
5465
|
}
|
|
5413
|
-
if (this
|
|
5414
|
-
cancelAnimation(this
|
|
5415
|
-
|
|
5466
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
5467
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
5468
|
+
this.#drawAnimationFrame = undefined;
|
|
5416
5469
|
}
|
|
5417
|
-
if (this
|
|
5470
|
+
if (this.#paused) {
|
|
5418
5471
|
return;
|
|
5419
5472
|
}
|
|
5420
5473
|
for (const plugin of this.plugins) {
|
|
5421
5474
|
plugin.pause?.();
|
|
5422
5475
|
}
|
|
5423
5476
|
if (!this.pageHidden) {
|
|
5424
|
-
this
|
|
5477
|
+
this.#paused = true;
|
|
5425
5478
|
}
|
|
5426
5479
|
this.dispatchEvent(EventType.containerPaused);
|
|
5427
5480
|
}
|
|
@@ -5429,13 +5482,13 @@
|
|
|
5429
5482
|
if (!guardCheck(this)) {
|
|
5430
5483
|
return;
|
|
5431
5484
|
}
|
|
5432
|
-
const needsUpdate = this
|
|
5433
|
-
if (this
|
|
5434
|
-
this
|
|
5485
|
+
const needsUpdate = this.#paused || force;
|
|
5486
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
5487
|
+
this.#firstStart = false;
|
|
5435
5488
|
return;
|
|
5436
5489
|
}
|
|
5437
|
-
if (this
|
|
5438
|
-
this
|
|
5490
|
+
if (this.#paused) {
|
|
5491
|
+
this.#paused = false;
|
|
5439
5492
|
}
|
|
5440
5493
|
if (needsUpdate) {
|
|
5441
5494
|
for (const plugin of this.plugins) {
|
|
@@ -5458,10 +5511,10 @@
|
|
|
5458
5511
|
if (!guardCheck(this)) {
|
|
5459
5512
|
return;
|
|
5460
5513
|
}
|
|
5461
|
-
this
|
|
5462
|
-
this
|
|
5463
|
-
this
|
|
5464
|
-
this.actualOptions = loadContainerOptions(this
|
|
5514
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5515
|
+
this.#sourceOptions = sourceOptions;
|
|
5516
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5517
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5465
5518
|
return this.refresh();
|
|
5466
5519
|
}
|
|
5467
5520
|
async start() {
|
|
@@ -5472,7 +5525,7 @@
|
|
|
5472
5525
|
this.started = true;
|
|
5473
5526
|
await new Promise(resolve => {
|
|
5474
5527
|
const start = async () => {
|
|
5475
|
-
this.
|
|
5528
|
+
this.#eventListeners.addListeners();
|
|
5476
5529
|
for (const plugin of this.plugins) {
|
|
5477
5530
|
await plugin.start?.();
|
|
5478
5531
|
}
|
|
@@ -5480,20 +5533,20 @@
|
|
|
5480
5533
|
this.play();
|
|
5481
5534
|
resolve();
|
|
5482
5535
|
};
|
|
5483
|
-
this
|
|
5536
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
5484
5537
|
});
|
|
5485
5538
|
}
|
|
5486
5539
|
stop() {
|
|
5487
5540
|
if (!guardCheck(this) || !this.started) {
|
|
5488
5541
|
return;
|
|
5489
5542
|
}
|
|
5490
|
-
if (this
|
|
5491
|
-
clearTimeout(this
|
|
5492
|
-
|
|
5543
|
+
if (this.#delayTimeout) {
|
|
5544
|
+
clearTimeout(this.#delayTimeout);
|
|
5545
|
+
this.#delayTimeout = undefined;
|
|
5493
5546
|
}
|
|
5494
|
-
this
|
|
5547
|
+
this.#firstStart = true;
|
|
5495
5548
|
this.started = false;
|
|
5496
|
-
this.
|
|
5549
|
+
this.#eventListeners.removeListeners();
|
|
5497
5550
|
this.pause();
|
|
5498
5551
|
this.particles.clear();
|
|
5499
5552
|
this.canvas.stop();
|
|
@@ -5503,7 +5556,7 @@
|
|
|
5503
5556
|
this.particleCreatedPlugins.length = 0;
|
|
5504
5557
|
this.particleDestroyedPlugins.length = 0;
|
|
5505
5558
|
this.particlePositionPlugins.length = 0;
|
|
5506
|
-
this
|
|
5559
|
+
this.#sourceOptions = this.#options;
|
|
5507
5560
|
this.dispatchEvent(EventType.containerStopped);
|
|
5508
5561
|
}
|
|
5509
5562
|
updateActualOptions() {
|
|
@@ -5515,23 +5568,23 @@
|
|
|
5515
5568
|
}
|
|
5516
5569
|
return refresh;
|
|
5517
5570
|
}
|
|
5518
|
-
|
|
5571
|
+
#nextFrame = (timestamp) => {
|
|
5519
5572
|
try {
|
|
5520
|
-
if (!this
|
|
5521
|
-
this
|
|
5522
|
-
timestamp < this
|
|
5573
|
+
if (!this.#smooth &&
|
|
5574
|
+
this.#lastFrameTime !== undefined &&
|
|
5575
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
5523
5576
|
this.draw(false);
|
|
5524
5577
|
return;
|
|
5525
5578
|
}
|
|
5526
|
-
this
|
|
5527
|
-
updateDelta(this
|
|
5528
|
-
this.addLifeTime(this.
|
|
5529
|
-
this
|
|
5530
|
-
if (this.
|
|
5579
|
+
this.#lastFrameTime ??= timestamp;
|
|
5580
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
5581
|
+
this.addLifeTime(this.#delta.value);
|
|
5582
|
+
this.#lastFrameTime = timestamp;
|
|
5583
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
5531
5584
|
this.draw(false);
|
|
5532
5585
|
return;
|
|
5533
5586
|
}
|
|
5534
|
-
this.canvas.render.drawParticles(this
|
|
5587
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
5535
5588
|
if (!this.alive()) {
|
|
5536
5589
|
this.destroy();
|
|
5537
5590
|
return;
|
|
@@ -5552,44 +5605,44 @@
|
|
|
5552
5605
|
});
|
|
5553
5606
|
|
|
5554
5607
|
class EmittersPluginInstance {
|
|
5555
|
-
container;
|
|
5556
|
-
|
|
5608
|
+
#container;
|
|
5609
|
+
#instancesManager;
|
|
5557
5610
|
constructor(instancesManager, container) {
|
|
5558
|
-
this
|
|
5559
|
-
this
|
|
5560
|
-
this.
|
|
5611
|
+
this.#instancesManager = instancesManager;
|
|
5612
|
+
this.#container = container;
|
|
5613
|
+
this.#instancesManager.initContainer(container);
|
|
5561
5614
|
}
|
|
5562
5615
|
async init() {
|
|
5563
|
-
const emittersOptions = this
|
|
5616
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
5564
5617
|
if (isArray(emittersOptions)) {
|
|
5565
5618
|
for (const emitterOptions of emittersOptions) {
|
|
5566
|
-
await this.
|
|
5619
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
5567
5620
|
}
|
|
5568
5621
|
}
|
|
5569
5622
|
else {
|
|
5570
|
-
await this.
|
|
5623
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
5571
5624
|
}
|
|
5572
5625
|
}
|
|
5573
5626
|
pause() {
|
|
5574
|
-
for (const emitter of this.
|
|
5627
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
5575
5628
|
emitter.pause();
|
|
5576
5629
|
}
|
|
5577
5630
|
}
|
|
5578
5631
|
play() {
|
|
5579
|
-
for (const emitter of this.
|
|
5632
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
5580
5633
|
emitter.play();
|
|
5581
5634
|
}
|
|
5582
5635
|
}
|
|
5583
5636
|
resize() {
|
|
5584
|
-
for (const emitter of this.
|
|
5637
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
5585
5638
|
emitter.resize();
|
|
5586
5639
|
}
|
|
5587
5640
|
}
|
|
5588
5641
|
stop() {
|
|
5589
|
-
this.
|
|
5642
|
+
this.#instancesManager.clear(this.#container);
|
|
5590
5643
|
}
|
|
5591
5644
|
update(delta) {
|
|
5592
|
-
this.
|
|
5645
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
5593
5646
|
emitter.update(delta);
|
|
5594
5647
|
});
|
|
5595
5648
|
}
|
|
@@ -5622,16 +5675,16 @@
|
|
|
5622
5675
|
|
|
5623
5676
|
const defaultIndex = 0;
|
|
5624
5677
|
class EmittersInstancesManager {
|
|
5625
|
-
|
|
5626
|
-
|
|
5678
|
+
#containerArrays;
|
|
5679
|
+
#pluginManager;
|
|
5627
5680
|
constructor(pluginManager) {
|
|
5628
|
-
this
|
|
5629
|
-
this
|
|
5681
|
+
this.#containerArrays = new Map();
|
|
5682
|
+
this.#pluginManager = pluginManager;
|
|
5630
5683
|
}
|
|
5631
5684
|
async addEmitter(container, options, position) {
|
|
5632
5685
|
const emitterOptions = new Emitter();
|
|
5633
5686
|
emitterOptions.load(options);
|
|
5634
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
5687
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
5635
5688
|
this.removeEmitter(container, emitter);
|
|
5636
5689
|
}, emitterOptions, position);
|
|
5637
5690
|
await emitter.init();
|
|
@@ -5640,22 +5693,22 @@
|
|
|
5640
5693
|
}
|
|
5641
5694
|
clear(container) {
|
|
5642
5695
|
this.initContainer(container);
|
|
5643
|
-
this.
|
|
5696
|
+
this.#containerArrays.set(container, []);
|
|
5644
5697
|
}
|
|
5645
5698
|
getArray(container) {
|
|
5646
5699
|
this.initContainer(container);
|
|
5647
|
-
let array = this.
|
|
5700
|
+
let array = this.#containerArrays.get(container);
|
|
5648
5701
|
if (!array) {
|
|
5649
5702
|
array = [];
|
|
5650
|
-
this.
|
|
5703
|
+
this.#containerArrays.set(container, array);
|
|
5651
5704
|
}
|
|
5652
5705
|
return array;
|
|
5653
5706
|
}
|
|
5654
5707
|
initContainer(container) {
|
|
5655
|
-
if (this.
|
|
5708
|
+
if (this.#containerArrays.has(container)) {
|
|
5656
5709
|
return;
|
|
5657
5710
|
}
|
|
5658
|
-
this.
|
|
5711
|
+
this.#containerArrays.set(container, []);
|
|
5659
5712
|
container.getEmitter = (idxOrName) => {
|
|
5660
5713
|
const array = this.getArray(container);
|
|
5661
5714
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -5724,34 +5777,34 @@
|
|
|
5724
5777
|
spawnStrokeColor;
|
|
5725
5778
|
spawnStrokeOpacity;
|
|
5726
5779
|
spawnStrokeWidth;
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5780
|
+
#container;
|
|
5781
|
+
#currentDuration;
|
|
5782
|
+
#currentEmitDelay;
|
|
5783
|
+
#currentSpawnDelay;
|
|
5784
|
+
#duration;
|
|
5785
|
+
#emitDelay;
|
|
5786
|
+
#firstSpawn;
|
|
5787
|
+
#immortal;
|
|
5788
|
+
#initialPosition;
|
|
5789
|
+
#lifeCount;
|
|
5790
|
+
#mutationObserver;
|
|
5791
|
+
#particlesOptions;
|
|
5792
|
+
#paused;
|
|
5793
|
+
#pluginManager;
|
|
5794
|
+
#removeCallback;
|
|
5795
|
+
#resizeObserver;
|
|
5796
|
+
#shape;
|
|
5797
|
+
#size;
|
|
5798
|
+
#spawnDelay;
|
|
5799
|
+
#startParticlesAdded;
|
|
5747
5800
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
5748
|
-
this
|
|
5749
|
-
this
|
|
5750
|
-
this
|
|
5751
|
-
this
|
|
5752
|
-
this
|
|
5753
|
-
this
|
|
5754
|
-
this
|
|
5801
|
+
this.#pluginManager = pluginManager;
|
|
5802
|
+
this.#container = container;
|
|
5803
|
+
this.#removeCallback = removeCallback;
|
|
5804
|
+
this.#currentDuration = 0;
|
|
5805
|
+
this.#currentEmitDelay = 0;
|
|
5806
|
+
this.#currentSpawnDelay = 0;
|
|
5807
|
+
this.#initialPosition = position;
|
|
5755
5808
|
if (options instanceof Emitter) {
|
|
5756
5809
|
this.options = options;
|
|
5757
5810
|
}
|
|
@@ -5759,159 +5812,159 @@
|
|
|
5759
5812
|
this.options = new Emitter();
|
|
5760
5813
|
this.options.load(options);
|
|
5761
5814
|
}
|
|
5762
|
-
this
|
|
5815
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
5763
5816
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
5764
5817
|
container.retina.reduceFactor
|
|
5765
5818
|
: Infinity;
|
|
5766
|
-
this.position = this
|
|
5819
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
5767
5820
|
this.name = this.options.name;
|
|
5768
5821
|
this.fill = this.options.fill;
|
|
5769
|
-
this
|
|
5770
|
-
this
|
|
5822
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
5823
|
+
this.#startParticlesAdded = false;
|
|
5771
5824
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
5772
5825
|
particlesOptions.move ??= {};
|
|
5773
5826
|
particlesOptions.move.direction ??= this.options.direction;
|
|
5774
5827
|
if (this.options.spawn.fill?.color) {
|
|
5775
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
5828
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
5776
5829
|
}
|
|
5777
5830
|
if (this.options.spawn.stroke?.color) {
|
|
5778
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
5779
|
-
}
|
|
5780
|
-
this
|
|
5781
|
-
this
|
|
5782
|
-
this
|
|
5783
|
-
this.size = getSize(this
|
|
5784
|
-
this
|
|
5785
|
-
this
|
|
5831
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
5832
|
+
}
|
|
5833
|
+
this.#paused = !this.options.autoPlay;
|
|
5834
|
+
this.#particlesOptions = particlesOptions;
|
|
5835
|
+
this.#size = this.#calcSize();
|
|
5836
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
5837
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
5838
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
5786
5839
|
if (this.options.domId) {
|
|
5787
5840
|
const element = safeDocument().getElementById(this.options.domId);
|
|
5788
5841
|
if (element) {
|
|
5789
|
-
this
|
|
5842
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
5790
5843
|
this.resize();
|
|
5791
5844
|
});
|
|
5792
|
-
this
|
|
5845
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
5793
5846
|
this.resize();
|
|
5794
5847
|
});
|
|
5795
|
-
this.
|
|
5848
|
+
this.#mutationObserver.observe(element, {
|
|
5796
5849
|
attributes: true,
|
|
5797
5850
|
attributeFilter: ["style", "width", "height"],
|
|
5798
5851
|
});
|
|
5799
|
-
this.
|
|
5852
|
+
this.#resizeObserver.observe(element);
|
|
5800
5853
|
}
|
|
5801
5854
|
}
|
|
5802
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
5855
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
5803
5856
|
if (shapeGenerator) {
|
|
5804
|
-
this
|
|
5857
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
5805
5858
|
}
|
|
5806
|
-
this.
|
|
5859
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
5807
5860
|
emitter: this,
|
|
5808
5861
|
});
|
|
5809
5862
|
this.play();
|
|
5810
5863
|
}
|
|
5811
5864
|
externalPause() {
|
|
5812
|
-
this
|
|
5865
|
+
this.#paused = true;
|
|
5813
5866
|
this.pause();
|
|
5814
5867
|
}
|
|
5815
5868
|
externalPlay() {
|
|
5816
|
-
this
|
|
5869
|
+
this.#paused = false;
|
|
5817
5870
|
this.play();
|
|
5818
5871
|
}
|
|
5819
5872
|
async init() {
|
|
5820
|
-
await this
|
|
5873
|
+
await this.#shape?.init();
|
|
5821
5874
|
}
|
|
5822
5875
|
pause() {
|
|
5823
|
-
if (this
|
|
5876
|
+
if (this.#paused) {
|
|
5824
5877
|
return;
|
|
5825
5878
|
}
|
|
5826
|
-
|
|
5879
|
+
this.#emitDelay = undefined;
|
|
5827
5880
|
}
|
|
5828
5881
|
play() {
|
|
5829
|
-
if (this
|
|
5882
|
+
if (this.#paused) {
|
|
5830
5883
|
return;
|
|
5831
5884
|
}
|
|
5832
|
-
if (!((this
|
|
5833
|
-
(this
|
|
5885
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
5886
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
5834
5887
|
return;
|
|
5835
5888
|
}
|
|
5836
|
-
const container = this
|
|
5837
|
-
if (this
|
|
5889
|
+
const container = this.#container;
|
|
5890
|
+
if (this.#emitDelay === undefined) {
|
|
5838
5891
|
const delay = getRangeValue(this.options.rate.delay);
|
|
5839
|
-
this
|
|
5892
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
5840
5893
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
5841
5894
|
: Infinity;
|
|
5842
5895
|
}
|
|
5843
|
-
if (this
|
|
5844
|
-
this
|
|
5896
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
5897
|
+
this.#prepareToDie();
|
|
5845
5898
|
}
|
|
5846
5899
|
}
|
|
5847
5900
|
resize() {
|
|
5848
|
-
const initialPosition = this
|
|
5901
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
5849
5902
|
this.position =
|
|
5850
5903
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
5851
5904
|
? initialPosition
|
|
5852
|
-
: this
|
|
5853
|
-
this
|
|
5854
|
-
this.size = getSize(this
|
|
5855
|
-
this
|
|
5905
|
+
: this.#calcPosition();
|
|
5906
|
+
this.#size = this.#calcSize();
|
|
5907
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
5908
|
+
this.#shape?.resize(this.position, this.size);
|
|
5856
5909
|
}
|
|
5857
5910
|
update(delta) {
|
|
5858
|
-
if (this
|
|
5911
|
+
if (this.#paused) {
|
|
5859
5912
|
return;
|
|
5860
5913
|
}
|
|
5861
|
-
const container = this
|
|
5862
|
-
if (this
|
|
5863
|
-
this
|
|
5864
|
-
this
|
|
5865
|
-
this
|
|
5914
|
+
const container = this.#container;
|
|
5915
|
+
if (this.#firstSpawn) {
|
|
5916
|
+
this.#firstSpawn = false;
|
|
5917
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
5918
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
5866
5919
|
}
|
|
5867
|
-
if (!this
|
|
5868
|
-
this
|
|
5869
|
-
this
|
|
5920
|
+
if (!this.#startParticlesAdded) {
|
|
5921
|
+
this.#startParticlesAdded = true;
|
|
5922
|
+
this.#emitParticles(this.options.startCount);
|
|
5870
5923
|
}
|
|
5871
|
-
if (this
|
|
5872
|
-
this
|
|
5873
|
-
if (this
|
|
5924
|
+
if (this.#duration !== undefined) {
|
|
5925
|
+
this.#currentDuration += delta.value;
|
|
5926
|
+
if (this.#currentDuration >= this.#duration) {
|
|
5874
5927
|
this.pause();
|
|
5875
|
-
if (this
|
|
5876
|
-
|
|
5928
|
+
if (this.#spawnDelay !== undefined) {
|
|
5929
|
+
this.#spawnDelay = undefined;
|
|
5877
5930
|
}
|
|
5878
|
-
if (!this
|
|
5879
|
-
this
|
|
5931
|
+
if (!this.#immortal) {
|
|
5932
|
+
this.#lifeCount--;
|
|
5880
5933
|
}
|
|
5881
|
-
if (this
|
|
5882
|
-
this.position = this
|
|
5883
|
-
this
|
|
5884
|
-
this
|
|
5934
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
5935
|
+
this.position = this.#calcPosition();
|
|
5936
|
+
this.#shape?.resize(this.position, this.size);
|
|
5937
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
5885
5938
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
5886
5939
|
container.retina.reduceFactor
|
|
5887
5940
|
: Infinity;
|
|
5888
5941
|
}
|
|
5889
5942
|
else {
|
|
5890
|
-
this
|
|
5943
|
+
this.#destroy();
|
|
5891
5944
|
}
|
|
5892
|
-
this
|
|
5893
|
-
|
|
5945
|
+
this.#currentDuration -= this.#duration;
|
|
5946
|
+
this.#duration = undefined;
|
|
5894
5947
|
}
|
|
5895
5948
|
}
|
|
5896
|
-
if (this
|
|
5897
|
-
this
|
|
5898
|
-
if (this
|
|
5899
|
-
this.
|
|
5949
|
+
if (this.#spawnDelay !== undefined) {
|
|
5950
|
+
this.#currentSpawnDelay += delta.value;
|
|
5951
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
5952
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
5900
5953
|
this.play();
|
|
5901
|
-
this
|
|
5902
|
-
|
|
5954
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
5955
|
+
this.#spawnDelay = undefined;
|
|
5903
5956
|
}
|
|
5904
5957
|
}
|
|
5905
|
-
if (this
|
|
5906
|
-
this
|
|
5907
|
-
if (this
|
|
5908
|
-
this
|
|
5909
|
-
this
|
|
5958
|
+
if (this.#emitDelay !== undefined) {
|
|
5959
|
+
this.#currentEmitDelay += delta.value;
|
|
5960
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
5961
|
+
this.#emit();
|
|
5962
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
5910
5963
|
}
|
|
5911
5964
|
}
|
|
5912
5965
|
}
|
|
5913
|
-
|
|
5914
|
-
const container = this
|
|
5966
|
+
#calcPosition() {
|
|
5967
|
+
const container = this.#container;
|
|
5915
5968
|
if (this.options.domId) {
|
|
5916
5969
|
const element = safeDocument().getElementById(this.options.domId);
|
|
5917
5970
|
if (element) {
|
|
@@ -5927,8 +5980,8 @@
|
|
|
5927
5980
|
position: this.options.position,
|
|
5928
5981
|
});
|
|
5929
5982
|
}
|
|
5930
|
-
|
|
5931
|
-
const container = this
|
|
5983
|
+
#calcSize() {
|
|
5984
|
+
const container = this.#container;
|
|
5932
5985
|
if (this.options.domId) {
|
|
5933
5986
|
const element = safeDocument().getElementById(this.options.domId);
|
|
5934
5987
|
if (element) {
|
|
@@ -5951,32 +6004,32 @@
|
|
|
5951
6004
|
return size;
|
|
5952
6005
|
})());
|
|
5953
6006
|
}
|
|
5954
|
-
|
|
5955
|
-
this
|
|
5956
|
-
this
|
|
5957
|
-
this
|
|
5958
|
-
this
|
|
5959
|
-
this
|
|
5960
|
-
this.
|
|
6007
|
+
#destroy = () => {
|
|
6008
|
+
this.#mutationObserver?.disconnect();
|
|
6009
|
+
this.#mutationObserver = undefined;
|
|
6010
|
+
this.#resizeObserver?.disconnect();
|
|
6011
|
+
this.#resizeObserver = undefined;
|
|
6012
|
+
this.#removeCallback(this);
|
|
6013
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
5961
6014
|
emitter: this,
|
|
5962
6015
|
});
|
|
5963
6016
|
};
|
|
5964
|
-
|
|
5965
|
-
if (this
|
|
6017
|
+
#emit() {
|
|
6018
|
+
if (this.#paused) {
|
|
5966
6019
|
return;
|
|
5967
6020
|
}
|
|
5968
6021
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
5969
|
-
this
|
|
6022
|
+
this.#emitParticles(quantity);
|
|
5970
6023
|
}
|
|
5971
|
-
|
|
5972
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
6024
|
+
#emitParticles(quantity) {
|
|
6025
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
5973
6026
|
{}), fillHslAnimation = this.options.spawn.fill?.color?.animation, fillEnabled = this.options.spawn.fill?.enable ?? !!this.options.spawn.fill?.color, fillOpacity = this.options.spawn.fill?.opacity === undefined
|
|
5974
6027
|
? defaultOpacity$1
|
|
5975
6028
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
5976
6029
|
? defaultOpacity$1
|
|
5977
6030
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
5978
6031
|
? defaultStrokeWidth
|
|
5979
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
6032
|
+
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.#container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this.#shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
|
|
5980
6033
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
5981
6034
|
const particlesOptions = needsCopy
|
|
5982
6035
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -5987,23 +6040,23 @@
|
|
|
5987
6040
|
this.spawnStrokeWidth = strokeWidth;
|
|
5988
6041
|
if (this.spawnFillColor) {
|
|
5989
6042
|
if (fillHslAnimation && maxValues) {
|
|
5990
|
-
this.spawnFillColor.h = this
|
|
5991
|
-
this.spawnFillColor.s = this
|
|
5992
|
-
this.spawnFillColor.l = this
|
|
6043
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
6044
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
6045
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
5993
6046
|
}
|
|
5994
6047
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
5995
6048
|
}
|
|
5996
6049
|
if (this.spawnStrokeColor) {
|
|
5997
6050
|
if (strokeHslAnimation && maxValues) {
|
|
5998
|
-
this.spawnStrokeColor.h = this
|
|
5999
|
-
this.spawnStrokeColor.s = this
|
|
6000
|
-
this.spawnStrokeColor.l = this
|
|
6051
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
6052
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
6053
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
6001
6054
|
}
|
|
6002
6055
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
6003
6056
|
}
|
|
6004
6057
|
let position = this.position;
|
|
6005
|
-
if (this
|
|
6006
|
-
const shapePosData = this.
|
|
6058
|
+
if (this.#shape) {
|
|
6059
|
+
const shapePosData = this.#shape.randomPosition();
|
|
6007
6060
|
if (shapePosData) {
|
|
6008
6061
|
position = shapePosData.position;
|
|
6009
6062
|
const replaceData = shapeOptions.replace;
|
|
@@ -6016,21 +6069,21 @@
|
|
|
6016
6069
|
}
|
|
6017
6070
|
}
|
|
6018
6071
|
if (position) {
|
|
6019
|
-
this.
|
|
6072
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
6020
6073
|
}
|
|
6021
6074
|
}
|
|
6022
6075
|
}
|
|
6023
|
-
|
|
6024
|
-
if (this
|
|
6076
|
+
#prepareToDie = () => {
|
|
6077
|
+
if (this.#paused) {
|
|
6025
6078
|
return;
|
|
6026
6079
|
}
|
|
6027
6080
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
6028
|
-
if ((this
|
|
6029
|
-
this
|
|
6081
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
6082
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
6030
6083
|
}
|
|
6031
6084
|
};
|
|
6032
|
-
|
|
6033
|
-
const container = this
|
|
6085
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
6086
|
+
const container = this.#container;
|
|
6034
6087
|
if (!animation.enable) {
|
|
6035
6088
|
return initValue;
|
|
6036
6089
|
}
|