@tsparticles/preset-snow 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
|
}
|
|
@@ -705,38 +705,38 @@
|
|
|
705
705
|
}
|
|
706
706
|
|
|
707
707
|
class EventDispatcher {
|
|
708
|
-
|
|
708
|
+
#listeners;
|
|
709
709
|
constructor() {
|
|
710
|
-
this
|
|
710
|
+
this.#listeners = new Map();
|
|
711
711
|
}
|
|
712
712
|
addEventListener(type, listener) {
|
|
713
713
|
this.removeEventListener(type, listener);
|
|
714
|
-
let arr = this.
|
|
714
|
+
let arr = this.#listeners.get(type);
|
|
715
715
|
if (!arr) {
|
|
716
716
|
arr = [];
|
|
717
|
-
this.
|
|
717
|
+
this.#listeners.set(type, arr);
|
|
718
718
|
}
|
|
719
719
|
arr.push(listener);
|
|
720
720
|
}
|
|
721
721
|
dispatchEvent(type, args) {
|
|
722
|
-
const listeners = this.
|
|
722
|
+
const listeners = this.#listeners.get(type);
|
|
723
723
|
listeners?.forEach(handler => {
|
|
724
724
|
handler(args);
|
|
725
725
|
});
|
|
726
726
|
}
|
|
727
727
|
hasEventListener(type) {
|
|
728
|
-
return !!this.
|
|
728
|
+
return !!this.#listeners.get(type);
|
|
729
729
|
}
|
|
730
730
|
removeAllEventListeners(type) {
|
|
731
731
|
if (!type) {
|
|
732
|
-
this
|
|
732
|
+
this.#listeners = new Map();
|
|
733
733
|
}
|
|
734
734
|
else {
|
|
735
|
-
this.
|
|
735
|
+
this.#listeners.delete(type);
|
|
736
736
|
}
|
|
737
737
|
}
|
|
738
738
|
removeEventListener(type, listener) {
|
|
739
|
-
const arr = this.
|
|
739
|
+
const arr = this.#listeners.get(type);
|
|
740
740
|
if (!arr) {
|
|
741
741
|
return;
|
|
742
742
|
}
|
|
@@ -745,7 +745,7 @@
|
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
747
|
if (length === deleteCount) {
|
|
748
|
-
this.
|
|
748
|
+
this.#listeners.delete(type);
|
|
749
749
|
}
|
|
750
750
|
else {
|
|
751
751
|
arr.splice(idx, deleteCount);
|
|
@@ -783,19 +783,19 @@
|
|
|
783
783
|
presets = new Map();
|
|
784
784
|
shapeDrawers = new Map();
|
|
785
785
|
updaters = new Map();
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
786
|
+
#allLoadersSet = new Set();
|
|
787
|
+
#configs = new Map();
|
|
788
|
+
#engine;
|
|
789
|
+
#executedSet = new Set();
|
|
790
|
+
#initialized = false;
|
|
791
|
+
#isRunningLoaders = false;
|
|
792
|
+
#loadPromises = new Set();
|
|
793
793
|
constructor(engine) {
|
|
794
|
-
this
|
|
794
|
+
this.#engine = engine;
|
|
795
795
|
}
|
|
796
796
|
get configs() {
|
|
797
797
|
const res = {};
|
|
798
|
-
for (const [name, config] of this
|
|
798
|
+
for (const [name, config] of this.#configs) {
|
|
799
799
|
res[name] = config;
|
|
800
800
|
}
|
|
801
801
|
return res;
|
|
@@ -805,8 +805,8 @@
|
|
|
805
805
|
}
|
|
806
806
|
addConfig(config) {
|
|
807
807
|
const key = config.key ?? config.name ?? "default";
|
|
808
|
-
this.
|
|
809
|
-
this.
|
|
808
|
+
this.#configs.set(key, config);
|
|
809
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
810
810
|
}
|
|
811
811
|
addEasing(name, easing) {
|
|
812
812
|
if (this.easingFunctions.get(name)) {
|
|
@@ -867,21 +867,21 @@
|
|
|
867
867
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
868
868
|
}
|
|
869
869
|
async init() {
|
|
870
|
-
if (this
|
|
870
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
871
871
|
return;
|
|
872
872
|
}
|
|
873
|
-
this
|
|
874
|
-
this
|
|
875
|
-
this
|
|
873
|
+
this.#isRunningLoaders = true;
|
|
874
|
+
this.#executedSet = new Set();
|
|
875
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
876
876
|
try {
|
|
877
|
-
for (const loader of this
|
|
878
|
-
await this
|
|
877
|
+
for (const loader of this.#allLoadersSet) {
|
|
878
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
879
879
|
}
|
|
880
880
|
}
|
|
881
881
|
finally {
|
|
882
|
-
this.
|
|
883
|
-
this
|
|
884
|
-
this
|
|
882
|
+
this.#loadPromises.clear();
|
|
883
|
+
this.#isRunningLoaders = false;
|
|
884
|
+
this.#initialized = true;
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -892,24 +892,24 @@
|
|
|
892
892
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
893
893
|
}
|
|
894
894
|
async register(...loaders) {
|
|
895
|
-
if (this
|
|
895
|
+
if (this.#initialized) {
|
|
896
896
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
897
897
|
}
|
|
898
898
|
for (const loader of loaders) {
|
|
899
|
-
if (this
|
|
900
|
-
await this
|
|
899
|
+
if (this.#isRunningLoaders) {
|
|
900
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
901
901
|
}
|
|
902
902
|
else {
|
|
903
|
-
this.
|
|
903
|
+
this.#loadPromises.add(loader);
|
|
904
904
|
}
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
|
-
async
|
|
907
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
908
908
|
if (executed.has(loader))
|
|
909
909
|
return;
|
|
910
910
|
executed.add(loader);
|
|
911
911
|
allLoaders.add(loader);
|
|
912
|
-
await loader(this
|
|
912
|
+
await loader(this.#engine);
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
915
|
|
|
@@ -989,17 +989,17 @@
|
|
|
989
989
|
};
|
|
990
990
|
class Engine {
|
|
991
991
|
pluginManager = new PluginManager(this);
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
992
|
+
#domArray = [];
|
|
993
|
+
#eventDispatcher = new EventDispatcher();
|
|
994
|
+
#initialized = false;
|
|
995
995
|
get items() {
|
|
996
|
-
return this
|
|
996
|
+
return this.#domArray;
|
|
997
997
|
}
|
|
998
998
|
get version() {
|
|
999
|
-
return "4.0
|
|
999
|
+
return "4.1.0";
|
|
1000
1000
|
}
|
|
1001
1001
|
addEventListener(type, listener) {
|
|
1002
|
-
this.
|
|
1002
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1003
1003
|
}
|
|
1004
1004
|
checkVersion(pluginVersion) {
|
|
1005
1005
|
if (this.version === pluginVersion) {
|
|
@@ -1008,17 +1008,17 @@
|
|
|
1008
1008
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1009
1009
|
}
|
|
1010
1010
|
dispatchEvent(type, args) {
|
|
1011
|
-
this.
|
|
1011
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1012
1012
|
}
|
|
1013
1013
|
async init() {
|
|
1014
|
-
if (this
|
|
1014
|
+
if (this.#initialized) {
|
|
1015
1015
|
return;
|
|
1016
1016
|
}
|
|
1017
1017
|
await this.pluginManager.init();
|
|
1018
|
-
this
|
|
1018
|
+
this.#initialized = true;
|
|
1019
1019
|
}
|
|
1020
1020
|
item(index) {
|
|
1021
|
-
const
|
|
1021
|
+
const items = this.items, item = items[index];
|
|
1022
1022
|
if (item?.destroyed) {
|
|
1023
1023
|
items.splice(index, removeDeleteCount);
|
|
1024
1024
|
return;
|
|
@@ -1072,7 +1072,7 @@
|
|
|
1072
1072
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1073
1073
|
}
|
|
1074
1074
|
removeEventListener(type, listener) {
|
|
1075
|
-
this.
|
|
1075
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
@@ -1843,43 +1843,6 @@
|
|
|
1843
1843
|
}
|
|
1844
1844
|
}
|
|
1845
1845
|
|
|
1846
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1847
|
-
destroy;
|
|
1848
|
-
constructor() {
|
|
1849
|
-
super();
|
|
1850
|
-
this.destroy = DestroyType.none;
|
|
1851
|
-
this.speed = 2;
|
|
1852
|
-
}
|
|
1853
|
-
load(data) {
|
|
1854
|
-
super.load(data);
|
|
1855
|
-
if (isNull(data)) {
|
|
1856
|
-
return;
|
|
1857
|
-
}
|
|
1858
|
-
if (data.destroy !== undefined) {
|
|
1859
|
-
this.destroy = data.destroy;
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1865
|
-
animation;
|
|
1866
|
-
constructor() {
|
|
1867
|
-
super();
|
|
1868
|
-
this.animation = new OpacityAnimation();
|
|
1869
|
-
this.value = 1;
|
|
1870
|
-
}
|
|
1871
|
-
load(data) {
|
|
1872
|
-
if (isNull(data)) {
|
|
1873
|
-
return;
|
|
1874
|
-
}
|
|
1875
|
-
super.load(data);
|
|
1876
|
-
const animation = data.animation;
|
|
1877
|
-
if (animation !== undefined) {
|
|
1878
|
-
this.animation.load(animation);
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
1846
|
class Stroke {
|
|
1884
1847
|
color;
|
|
1885
1848
|
opacity;
|
|
@@ -2047,43 +2010,6 @@
|
|
|
2047
2010
|
}
|
|
2048
2011
|
}
|
|
2049
2012
|
|
|
2050
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2051
|
-
destroy;
|
|
2052
|
-
constructor() {
|
|
2053
|
-
super();
|
|
2054
|
-
this.destroy = DestroyType.none;
|
|
2055
|
-
this.speed = 5;
|
|
2056
|
-
}
|
|
2057
|
-
load(data) {
|
|
2058
|
-
super.load(data);
|
|
2059
|
-
if (isNull(data)) {
|
|
2060
|
-
return;
|
|
2061
|
-
}
|
|
2062
|
-
if (data.destroy !== undefined) {
|
|
2063
|
-
this.destroy = data.destroy;
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2069
|
-
animation;
|
|
2070
|
-
constructor() {
|
|
2071
|
-
super();
|
|
2072
|
-
this.animation = new SizeAnimation();
|
|
2073
|
-
this.value = 3;
|
|
2074
|
-
}
|
|
2075
|
-
load(data) {
|
|
2076
|
-
super.load(data);
|
|
2077
|
-
if (isNull(data)) {
|
|
2078
|
-
return;
|
|
2079
|
-
}
|
|
2080
|
-
const animation = data.animation;
|
|
2081
|
-
if (animation !== undefined) {
|
|
2082
|
-
this.animation.load(animation);
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
2013
|
class ZIndex extends ValueWithRandom {
|
|
2088
2014
|
opacityRate;
|
|
2089
2015
|
sizeRate;
|
|
@@ -2117,24 +2043,21 @@
|
|
|
2117
2043
|
groups;
|
|
2118
2044
|
move;
|
|
2119
2045
|
number;
|
|
2120
|
-
opacity;
|
|
2121
2046
|
paint;
|
|
2122
2047
|
palette;
|
|
2123
2048
|
reduceDuplicates;
|
|
2124
2049
|
shape;
|
|
2125
|
-
size;
|
|
2126
2050
|
zIndex;
|
|
2127
|
-
|
|
2128
|
-
|
|
2051
|
+
#container;
|
|
2052
|
+
#pluginManager;
|
|
2129
2053
|
constructor(pluginManager, container) {
|
|
2130
|
-
this
|
|
2131
|
-
this
|
|
2054
|
+
this.#pluginManager = pluginManager;
|
|
2055
|
+
this.#container = container;
|
|
2132
2056
|
this.bounce = new ParticlesBounce();
|
|
2133
2057
|
this.effect = new Effect();
|
|
2134
2058
|
this.groups = {};
|
|
2135
2059
|
this.move = new Move();
|
|
2136
2060
|
this.number = new ParticlesNumber();
|
|
2137
|
-
this.opacity = new Opacity();
|
|
2138
2061
|
this.paint = new Paint();
|
|
2139
2062
|
this.paint.color = new AnimatableColor();
|
|
2140
2063
|
this.paint.color.value = "#fff";
|
|
@@ -2142,7 +2065,6 @@
|
|
|
2142
2065
|
this.paint.fill.enable = true;
|
|
2143
2066
|
this.reduceDuplicates = false;
|
|
2144
2067
|
this.shape = new Shape();
|
|
2145
|
-
this.size = new Size();
|
|
2146
2068
|
this.zIndex = new ZIndex();
|
|
2147
2069
|
}
|
|
2148
2070
|
load(data) {
|
|
@@ -2151,7 +2073,7 @@
|
|
|
2151
2073
|
}
|
|
2152
2074
|
if (data.palette) {
|
|
2153
2075
|
this.palette = data.palette;
|
|
2154
|
-
this
|
|
2076
|
+
this.#importPalette(this.palette);
|
|
2155
2077
|
}
|
|
2156
2078
|
if (data.groups !== undefined) {
|
|
2157
2079
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2171,7 +2093,6 @@
|
|
|
2171
2093
|
this.effect.load(data.effect);
|
|
2172
2094
|
this.move.load(data.move);
|
|
2173
2095
|
this.number.load(data.number);
|
|
2174
|
-
this.opacity.load(data.opacity);
|
|
2175
2096
|
const paintToLoad = data.paint;
|
|
2176
2097
|
if (paintToLoad) {
|
|
2177
2098
|
if (isArray(paintToLoad)) {
|
|
@@ -2190,15 +2111,14 @@
|
|
|
2190
2111
|
}
|
|
2191
2112
|
}
|
|
2192
2113
|
this.shape.load(data.shape);
|
|
2193
|
-
this.size.load(data.size);
|
|
2194
2114
|
this.zIndex.load(data.zIndex);
|
|
2195
|
-
if (this
|
|
2196
|
-
for (const plugin of this.
|
|
2115
|
+
if (this.#container) {
|
|
2116
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2197
2117
|
if (plugin.loadParticlesOptions) {
|
|
2198
|
-
plugin.loadParticlesOptions(this
|
|
2118
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2199
2119
|
}
|
|
2200
2120
|
}
|
|
2201
|
-
const updaters = this.
|
|
2121
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2202
2122
|
if (updaters) {
|
|
2203
2123
|
for (const updater of updaters) {
|
|
2204
2124
|
if (updater.loadOptions) {
|
|
@@ -2208,8 +2128,8 @@
|
|
|
2208
2128
|
}
|
|
2209
2129
|
}
|
|
2210
2130
|
}
|
|
2211
|
-
|
|
2212
|
-
const paletteData = this.
|
|
2131
|
+
#importPalette = (palette) => {
|
|
2132
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2213
2133
|
if (!paletteData) {
|
|
2214
2134
|
return;
|
|
2215
2135
|
}
|
|
@@ -2288,11 +2208,11 @@
|
|
|
2288
2208
|
smooth;
|
|
2289
2209
|
style;
|
|
2290
2210
|
zLayers;
|
|
2291
|
-
|
|
2292
|
-
|
|
2211
|
+
#container;
|
|
2212
|
+
#pluginManager;
|
|
2293
2213
|
constructor(pluginManager, container) {
|
|
2294
|
-
this
|
|
2295
|
-
this
|
|
2214
|
+
this.#pluginManager = pluginManager;
|
|
2215
|
+
this.#container = container;
|
|
2296
2216
|
this.autoPlay = true;
|
|
2297
2217
|
this.background = new Background();
|
|
2298
2218
|
this.clear = true;
|
|
@@ -2303,7 +2223,7 @@
|
|
|
2303
2223
|
this.duration = 0;
|
|
2304
2224
|
this.fpsLimit = 120;
|
|
2305
2225
|
this.hdr = true;
|
|
2306
|
-
this.particles = loadParticlesOptions(this
|
|
2226
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2307
2227
|
this.pauseOnBlur = true;
|
|
2308
2228
|
this.pauseOnOutsideViewport = true;
|
|
2309
2229
|
this.resize = new ResizeEvent();
|
|
@@ -2318,12 +2238,12 @@
|
|
|
2318
2238
|
if (data.preset !== undefined) {
|
|
2319
2239
|
this.preset = data.preset;
|
|
2320
2240
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2321
|
-
this
|
|
2241
|
+
this.#importPreset(preset);
|
|
2322
2242
|
});
|
|
2323
2243
|
}
|
|
2324
2244
|
if (data.palette !== undefined) {
|
|
2325
2245
|
this.palette = data.palette;
|
|
2326
|
-
this
|
|
2246
|
+
this.#importPalette(this.palette);
|
|
2327
2247
|
}
|
|
2328
2248
|
if (data.autoPlay !== undefined) {
|
|
2329
2249
|
this.autoPlay = data.autoPlay;
|
|
@@ -2377,12 +2297,12 @@
|
|
|
2377
2297
|
if (data.smooth !== undefined) {
|
|
2378
2298
|
this.smooth = data.smooth;
|
|
2379
2299
|
}
|
|
2380
|
-
this.
|
|
2381
|
-
plugin.loadOptions(this
|
|
2300
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2301
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2382
2302
|
});
|
|
2383
2303
|
}
|
|
2384
|
-
|
|
2385
|
-
const paletteData = this.
|
|
2304
|
+
#importPalette = palette => {
|
|
2305
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2386
2306
|
if (!paletteData) {
|
|
2387
2307
|
return;
|
|
2388
2308
|
}
|
|
@@ -2399,8 +2319,8 @@
|
|
|
2399
2319
|
},
|
|
2400
2320
|
});
|
|
2401
2321
|
};
|
|
2402
|
-
|
|
2403
|
-
this.load(this.
|
|
2322
|
+
#importPreset = preset => {
|
|
2323
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2404
2324
|
};
|
|
2405
2325
|
}
|
|
2406
2326
|
|
|
@@ -2869,7 +2789,7 @@
|
|
|
2869
2789
|
}
|
|
2870
2790
|
|
|
2871
2791
|
async function loadBlendPlugin(engine) {
|
|
2872
|
-
engine.checkVersion("4.0
|
|
2792
|
+
engine.checkVersion("4.1.0");
|
|
2873
2793
|
await engine.pluginManager.register(e => {
|
|
2874
2794
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2875
2795
|
});
|
|
@@ -2906,7 +2826,7 @@
|
|
|
2906
2826
|
}
|
|
2907
2827
|
|
|
2908
2828
|
async function loadCircleShape(engine) {
|
|
2909
|
-
engine.checkVersion("4.0
|
|
2829
|
+
engine.checkVersion("4.1.0");
|
|
2910
2830
|
await engine.pluginManager.register(e => {
|
|
2911
2831
|
e.pluginManager.addShape(["circle"], () => {
|
|
2912
2832
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2927,15 +2847,15 @@
|
|
|
2927
2847
|
return input.startsWith("#");
|
|
2928
2848
|
}
|
|
2929
2849
|
handleColor(color) {
|
|
2930
|
-
return this
|
|
2850
|
+
return this.#parseString(color.value);
|
|
2931
2851
|
}
|
|
2932
2852
|
handleRangeColor(color) {
|
|
2933
|
-
return this
|
|
2853
|
+
return this.#parseString(color.value);
|
|
2934
2854
|
}
|
|
2935
2855
|
parseString(input) {
|
|
2936
|
-
return this
|
|
2856
|
+
return this.#parseString(input);
|
|
2937
2857
|
}
|
|
2938
|
-
|
|
2858
|
+
#parseString(hexColor) {
|
|
2939
2859
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
2940
2860
|
return;
|
|
2941
2861
|
}
|
|
@@ -2954,7 +2874,7 @@
|
|
|
2954
2874
|
}
|
|
2955
2875
|
|
|
2956
2876
|
async function loadHexColorPlugin(engine) {
|
|
2957
|
-
engine.checkVersion("4.0
|
|
2877
|
+
engine.checkVersion("4.1.0");
|
|
2958
2878
|
await engine.pluginManager.register(e => {
|
|
2959
2879
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2960
2880
|
});
|
|
@@ -3007,7 +2927,7 @@
|
|
|
3007
2927
|
}
|
|
3008
2928
|
|
|
3009
2929
|
async function loadHslColorPlugin(engine) {
|
|
3010
|
-
engine.checkVersion("4.0
|
|
2930
|
+
engine.checkVersion("4.1.0");
|
|
3011
2931
|
await engine.pluginManager.register(e => {
|
|
3012
2932
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3013
2933
|
});
|
|
@@ -3015,13 +2935,13 @@
|
|
|
3015
2935
|
|
|
3016
2936
|
class MovePlugin {
|
|
3017
2937
|
id = "move";
|
|
3018
|
-
|
|
2938
|
+
#pluginManager;
|
|
3019
2939
|
constructor(pluginManager) {
|
|
3020
|
-
this
|
|
2940
|
+
this.#pluginManager = pluginManager;
|
|
3021
2941
|
}
|
|
3022
2942
|
async getPlugin(container) {
|
|
3023
2943
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3024
|
-
return new MovePluginInstance(this
|
|
2944
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3025
2945
|
}
|
|
3026
2946
|
loadOptions() {
|
|
3027
2947
|
}
|
|
@@ -3031,7 +2951,7 @@
|
|
|
3031
2951
|
}
|
|
3032
2952
|
|
|
3033
2953
|
async function loadMovePlugin(engine) {
|
|
3034
|
-
engine.checkVersion("4.0
|
|
2954
|
+
engine.checkVersion("4.1.0");
|
|
3035
2955
|
await engine.pluginManager.register(e => {
|
|
3036
2956
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3037
2957
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3049,18 +2969,58 @@
|
|
|
3049
2969
|
});
|
|
3050
2970
|
}
|
|
3051
2971
|
|
|
2972
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
2973
|
+
destroy;
|
|
2974
|
+
constructor() {
|
|
2975
|
+
super();
|
|
2976
|
+
this.destroy = DestroyType.none;
|
|
2977
|
+
this.speed = 2;
|
|
2978
|
+
}
|
|
2979
|
+
load(data) {
|
|
2980
|
+
super.load(data);
|
|
2981
|
+
if (isNull(data)) {
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
if (data.destroy !== undefined) {
|
|
2985
|
+
this.destroy = data.destroy;
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
2991
|
+
animation;
|
|
2992
|
+
constructor() {
|
|
2993
|
+
super();
|
|
2994
|
+
this.animation = new OpacityAnimation();
|
|
2995
|
+
this.value = 1;
|
|
2996
|
+
}
|
|
2997
|
+
load(data) {
|
|
2998
|
+
if (isNull(data)) {
|
|
2999
|
+
return;
|
|
3000
|
+
}
|
|
3001
|
+
super.load(data);
|
|
3002
|
+
const animation = data.animation;
|
|
3003
|
+
if (animation !== undefined) {
|
|
3004
|
+
this.animation.load(animation);
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3052
3009
|
class OpacityUpdater {
|
|
3053
|
-
container;
|
|
3010
|
+
#container;
|
|
3054
3011
|
constructor(container) {
|
|
3055
|
-
this
|
|
3012
|
+
this.#container = container;
|
|
3056
3013
|
}
|
|
3057
3014
|
init(particle) {
|
|
3058
3015
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3016
|
+
if (!opacityOptions) {
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3059
3019
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3060
3020
|
const opacityAnimation = opacityOptions.animation;
|
|
3061
3021
|
if (opacityAnimation.enable) {
|
|
3062
3022
|
particle.opacity.velocity =
|
|
3063
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3023
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3064
3024
|
if (!opacityAnimation.sync) {
|
|
3065
3025
|
particle.opacity.velocity *= getRandom();
|
|
3066
3026
|
}
|
|
@@ -3076,6 +3036,12 @@
|
|
|
3076
3036
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3077
3037
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3078
3038
|
}
|
|
3039
|
+
loadOptions(options, ...sources) {
|
|
3040
|
+
options.opacity ??= new Opacity();
|
|
3041
|
+
for (const source of sources) {
|
|
3042
|
+
options.opacity.load(source?.opacity);
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3079
3045
|
reset(particle) {
|
|
3080
3046
|
if (!particle.opacity) {
|
|
3081
3047
|
return;
|
|
@@ -3084,7 +3050,7 @@
|
|
|
3084
3050
|
particle.opacity.loops = 0;
|
|
3085
3051
|
}
|
|
3086
3052
|
update(particle, delta) {
|
|
3087
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3053
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3088
3054
|
return;
|
|
3089
3055
|
}
|
|
3090
3056
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3092,7 +3058,7 @@
|
|
|
3092
3058
|
}
|
|
3093
3059
|
|
|
3094
3060
|
async function loadOpacityUpdater(engine) {
|
|
3095
|
-
engine.checkVersion("4.0
|
|
3061
|
+
engine.checkVersion("4.1.0");
|
|
3096
3062
|
await engine.pluginManager.register(e => {
|
|
3097
3063
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3098
3064
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3114,10 +3080,9 @@
|
|
|
3114
3080
|
}
|
|
3115
3081
|
const velocity = data.particle.velocity.x;
|
|
3116
3082
|
let bounced = false;
|
|
3117
|
-
if (
|
|
3118
|
-
data.
|
|
3119
|
-
|
|
3120
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3083
|
+
if (data.outOfCanvas &&
|
|
3084
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3085
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3121
3086
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3122
3087
|
data.particle.velocity.x *= -newVelocity;
|
|
3123
3088
|
bounced = true;
|
|
@@ -3126,10 +3091,10 @@
|
|
|
3126
3091
|
return;
|
|
3127
3092
|
}
|
|
3128
3093
|
const minPos = data.offset.x + data.size;
|
|
3129
|
-
if (data.
|
|
3094
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3130
3095
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3131
3096
|
}
|
|
3132
|
-
else if (data.
|
|
3097
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3133
3098
|
data.particle.position.x = minPos;
|
|
3134
3099
|
}
|
|
3135
3100
|
if (data.outMode === OutMode.split) {
|
|
@@ -3149,10 +3114,9 @@
|
|
|
3149
3114
|
}
|
|
3150
3115
|
const velocity = data.particle.velocity.y;
|
|
3151
3116
|
let bounced = false;
|
|
3152
|
-
if (
|
|
3153
|
-
data.
|
|
3154
|
-
|
|
3155
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3117
|
+
if (data.outOfCanvas &&
|
|
3118
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3119
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3156
3120
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3157
3121
|
data.particle.velocity.y *= -newVelocity;
|
|
3158
3122
|
bounced = true;
|
|
@@ -3161,10 +3125,10 @@
|
|
|
3161
3125
|
return;
|
|
3162
3126
|
}
|
|
3163
3127
|
const minPos = data.offset.y + data.size;
|
|
3164
|
-
if (data.
|
|
3128
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3165
3129
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3166
3130
|
}
|
|
3167
|
-
else if (data.
|
|
3131
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3168
3132
|
data.particle.position.y = minPos;
|
|
3169
3133
|
}
|
|
3170
3134
|
if (data.outMode === OutMode.split) {
|
|
@@ -3173,24 +3137,24 @@
|
|
|
3173
3137
|
}
|
|
3174
3138
|
|
|
3175
3139
|
class BounceOutMode {
|
|
3176
|
-
container;
|
|
3177
3140
|
modes;
|
|
3178
|
-
|
|
3141
|
+
#container;
|
|
3142
|
+
#particleBouncePlugins;
|
|
3179
3143
|
constructor(container) {
|
|
3180
|
-
this
|
|
3144
|
+
this.#container = container;
|
|
3181
3145
|
this.modes = [
|
|
3182
3146
|
OutMode.bounce,
|
|
3183
3147
|
OutMode.split,
|
|
3184
3148
|
];
|
|
3185
|
-
this
|
|
3149
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3186
3150
|
}
|
|
3187
3151
|
update(particle, direction, delta, outMode) {
|
|
3188
3152
|
if (!this.modes.includes(outMode)) {
|
|
3189
3153
|
return;
|
|
3190
3154
|
}
|
|
3191
|
-
const container = this
|
|
3155
|
+
const container = this.#container;
|
|
3192
3156
|
let handled = false;
|
|
3193
|
-
for (const plugin of this
|
|
3157
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3194
3158
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3195
3159
|
if (handled) {
|
|
3196
3160
|
break;
|
|
@@ -3199,29 +3163,26 @@
|
|
|
3199
3163
|
if (handled) {
|
|
3200
3164
|
return;
|
|
3201
3165
|
}
|
|
3202
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3203
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3204
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3166
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3167
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3168
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3205
3169
|
}
|
|
3206
3170
|
}
|
|
3207
3171
|
|
|
3208
3172
|
const minVelocity$3 = 0;
|
|
3209
3173
|
class DestroyOutMode {
|
|
3210
|
-
container;
|
|
3211
3174
|
modes;
|
|
3212
|
-
constructor(
|
|
3213
|
-
this.container = container;
|
|
3175
|
+
constructor(_container) {
|
|
3214
3176
|
this.modes = [OutMode.destroy];
|
|
3215
3177
|
}
|
|
3216
3178
|
update(particle, direction, _delta, outMode) {
|
|
3217
3179
|
if (!this.modes.includes(outMode)) {
|
|
3218
3180
|
return;
|
|
3219
3181
|
}
|
|
3220
|
-
const container = this.container;
|
|
3221
3182
|
switch (particle.outType) {
|
|
3222
3183
|
case ParticleOutType.normal:
|
|
3223
3184
|
case ParticleOutType.outside:
|
|
3224
|
-
if (
|
|
3185
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3225
3186
|
return;
|
|
3226
3187
|
}
|
|
3227
3188
|
break;
|
|
@@ -3242,10 +3203,10 @@
|
|
|
3242
3203
|
|
|
3243
3204
|
const minVelocity$2 = 0;
|
|
3244
3205
|
class NoneOutMode {
|
|
3245
|
-
container;
|
|
3246
3206
|
modes;
|
|
3207
|
+
#container;
|
|
3247
3208
|
constructor(container) {
|
|
3248
|
-
this
|
|
3209
|
+
this.#container = container;
|
|
3249
3210
|
this.modes = [OutMode.none];
|
|
3250
3211
|
}
|
|
3251
3212
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3258,7 +3219,7 @@
|
|
|
3258
3219
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3259
3220
|
return;
|
|
3260
3221
|
}
|
|
3261
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3222
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3262
3223
|
if (!gravityOptions.enable) {
|
|
3263
3224
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3264
3225
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3284,17 +3245,17 @@
|
|
|
3284
3245
|
|
|
3285
3246
|
const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
|
|
3286
3247
|
class OutOutMode {
|
|
3287
|
-
container;
|
|
3288
3248
|
modes;
|
|
3249
|
+
#container;
|
|
3289
3250
|
constructor(container) {
|
|
3290
|
-
this
|
|
3251
|
+
this.#container = container;
|
|
3291
3252
|
this.modes = [OutMode.out];
|
|
3292
3253
|
}
|
|
3293
3254
|
update(particle, direction, _delta, outMode) {
|
|
3294
3255
|
if (!this.modes.includes(outMode)) {
|
|
3295
3256
|
return;
|
|
3296
3257
|
}
|
|
3297
|
-
const container = this
|
|
3258
|
+
const container = this.#container;
|
|
3298
3259
|
switch (particle.outType) {
|
|
3299
3260
|
case ParticleOutType.inside: {
|
|
3300
3261
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3324,7 +3285,7 @@
|
|
|
3324
3285
|
break;
|
|
3325
3286
|
}
|
|
3326
3287
|
default: {
|
|
3327
|
-
if (
|
|
3288
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3328
3289
|
return;
|
|
3329
3290
|
}
|
|
3330
3291
|
switch (particle.outType) {
|
|
@@ -3408,16 +3369,16 @@
|
|
|
3408
3369
|
};
|
|
3409
3370
|
class OutOfCanvasUpdater {
|
|
3410
3371
|
updaters;
|
|
3411
|
-
container;
|
|
3372
|
+
#container;
|
|
3412
3373
|
constructor(container) {
|
|
3413
|
-
this
|
|
3374
|
+
this.#container = container;
|
|
3414
3375
|
this.updaters = new Map();
|
|
3415
3376
|
}
|
|
3416
3377
|
init(particle) {
|
|
3417
|
-
this
|
|
3418
|
-
this
|
|
3419
|
-
this
|
|
3420
|
-
this
|
|
3378
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3379
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3380
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3381
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3421
3382
|
}
|
|
3422
3383
|
isEnabled(particle) {
|
|
3423
3384
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3425,18 +3386,18 @@
|
|
|
3425
3386
|
update(particle, delta) {
|
|
3426
3387
|
const outModes = particle.options.move.outModes;
|
|
3427
3388
|
particle.justWarped = false;
|
|
3428
|
-
this
|
|
3429
|
-
this
|
|
3430
|
-
this
|
|
3431
|
-
this
|
|
3389
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3390
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3391
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3392
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3432
3393
|
}
|
|
3433
|
-
|
|
3394
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3434
3395
|
const outModes = particle.options.move.outModes;
|
|
3435
3396
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3436
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3397
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3437
3398
|
}
|
|
3438
3399
|
};
|
|
3439
|
-
|
|
3400
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3440
3401
|
for (const updater of this.updaters.values()) {
|
|
3441
3402
|
updater.update(particle, direction, delta, outMode);
|
|
3442
3403
|
}
|
|
@@ -3444,7 +3405,7 @@
|
|
|
3444
3405
|
}
|
|
3445
3406
|
|
|
3446
3407
|
async function loadOutModesUpdater(engine) {
|
|
3447
|
-
engine.checkVersion("4.0
|
|
3408
|
+
engine.checkVersion("4.1.0");
|
|
3448
3409
|
await engine.pluginManager.register(e => {
|
|
3449
3410
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3450
3411
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3454,20 +3415,20 @@
|
|
|
3454
3415
|
|
|
3455
3416
|
const defaultOpacity = 1;
|
|
3456
3417
|
class PaintUpdater {
|
|
3457
|
-
|
|
3458
|
-
|
|
3418
|
+
#container;
|
|
3419
|
+
#pluginManager;
|
|
3459
3420
|
constructor(pluginManager, container) {
|
|
3460
|
-
this
|
|
3461
|
-
this
|
|
3421
|
+
this.#container = container;
|
|
3422
|
+
this.#pluginManager = pluginManager;
|
|
3462
3423
|
}
|
|
3463
3424
|
init(particle) {
|
|
3464
|
-
const container = this
|
|
3425
|
+
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;
|
|
3465
3426
|
if (fill) {
|
|
3466
3427
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3467
3428
|
particle.fillEnabled = fill.enable;
|
|
3468
3429
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3469
3430
|
particle.fillAnimation = fillColor.animation;
|
|
3470
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3431
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3471
3432
|
if (fillHslColor) {
|
|
3472
3433
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3473
3434
|
}
|
|
@@ -3483,7 +3444,7 @@
|
|
|
3483
3444
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3484
3445
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3485
3446
|
particle.strokeAnimation = strokeColor.animation;
|
|
3486
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3447
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3487
3448
|
if (strokeHslColor) {
|
|
3488
3449
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3489
3450
|
}
|
|
@@ -3515,7 +3476,7 @@
|
|
|
3515
3476
|
}
|
|
3516
3477
|
|
|
3517
3478
|
async function loadPaintUpdater(engine) {
|
|
3518
|
-
engine.checkVersion("4.0
|
|
3479
|
+
engine.checkVersion("4.1.0");
|
|
3519
3480
|
await engine.pluginManager.register(e => {
|
|
3520
3481
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3521
3482
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3570,27 +3531,69 @@
|
|
|
3570
3531
|
}
|
|
3571
3532
|
|
|
3572
3533
|
async function loadRgbColorPlugin(engine) {
|
|
3573
|
-
engine.checkVersion("4.0
|
|
3534
|
+
engine.checkVersion("4.1.0");
|
|
3574
3535
|
await engine.pluginManager.register(e => {
|
|
3575
3536
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3576
3537
|
});
|
|
3577
3538
|
}
|
|
3578
3539
|
|
|
3540
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3541
|
+
destroy;
|
|
3542
|
+
constructor() {
|
|
3543
|
+
super();
|
|
3544
|
+
this.destroy = DestroyType.none;
|
|
3545
|
+
this.speed = 5;
|
|
3546
|
+
}
|
|
3547
|
+
load(data) {
|
|
3548
|
+
super.load(data);
|
|
3549
|
+
if (isNull(data)) {
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
if (data.destroy !== undefined) {
|
|
3553
|
+
this.destroy = data.destroy;
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3559
|
+
animation;
|
|
3560
|
+
constructor() {
|
|
3561
|
+
super();
|
|
3562
|
+
this.animation = new SizeAnimation();
|
|
3563
|
+
this.value = 3;
|
|
3564
|
+
}
|
|
3565
|
+
load(data) {
|
|
3566
|
+
super.load(data);
|
|
3567
|
+
if (isNull(data)) {
|
|
3568
|
+
return;
|
|
3569
|
+
}
|
|
3570
|
+
const animation = data.animation;
|
|
3571
|
+
if (animation !== undefined) {
|
|
3572
|
+
this.animation.load(animation);
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3579
3577
|
const minLoops = 0;
|
|
3580
3578
|
class SizeUpdater {
|
|
3581
|
-
|
|
3579
|
+
#container;
|
|
3582
3580
|
constructor(container) {
|
|
3583
|
-
this
|
|
3581
|
+
this.#container = container;
|
|
3584
3582
|
}
|
|
3585
3583
|
init(particle) {
|
|
3586
|
-
const container = this
|
|
3587
|
-
if (
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3584
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3585
|
+
if (!sizeOptions) {
|
|
3586
|
+
return;
|
|
3587
|
+
}
|
|
3588
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3589
|
+
if (!sizeAnimation.enable) {
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3592
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3593
|
+
if (sizeAnimation.sync) {
|
|
3594
|
+
return;
|
|
3593
3595
|
}
|
|
3596
|
+
particle.size.velocity *= getRandom();
|
|
3594
3597
|
}
|
|
3595
3598
|
isEnabled(particle) {
|
|
3596
3599
|
return (!particle.destroyed &&
|
|
@@ -3600,12 +3603,26 @@
|
|
|
3600
3603
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3601
3604
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3602
3605
|
}
|
|
3606
|
+
loadOptions(options, ...sources) {
|
|
3607
|
+
options.size ??= new Size();
|
|
3608
|
+
for (const source of sources) {
|
|
3609
|
+
options.size.load(source?.size);
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
preInit(particle) {
|
|
3613
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3614
|
+
if (!sizeOptions) {
|
|
3615
|
+
return;
|
|
3616
|
+
}
|
|
3617
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3618
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3619
|
+
}
|
|
3603
3620
|
reset(particle) {
|
|
3604
3621
|
particle.size.time = 0;
|
|
3605
3622
|
particle.size.loops = 0;
|
|
3606
3623
|
}
|
|
3607
3624
|
update(particle, delta) {
|
|
3608
|
-
if (!this.isEnabled(particle)) {
|
|
3625
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3609
3626
|
return;
|
|
3610
3627
|
}
|
|
3611
3628
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3613,7 +3630,7 @@
|
|
|
3613
3630
|
}
|
|
3614
3631
|
|
|
3615
3632
|
async function loadSizeUpdater(engine) {
|
|
3616
|
-
engine.checkVersion("4.0
|
|
3633
|
+
engine.checkVersion("4.1.0");
|
|
3617
3634
|
await engine.pluginManager.register(e => {
|
|
3618
3635
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3619
3636
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3622,7 +3639,7 @@
|
|
|
3622
3639
|
}
|
|
3623
3640
|
|
|
3624
3641
|
async function loadBasic(engine) {
|
|
3625
|
-
engine.checkVersion("4.0
|
|
3642
|
+
engine.checkVersion("4.1.0");
|
|
3626
3643
|
await engine.pluginManager.register(async (e) => {
|
|
3627
3644
|
await Promise.all([
|
|
3628
3645
|
loadBlendPlugin(e),
|
|
@@ -3737,9 +3754,9 @@
|
|
|
3737
3754
|
|
|
3738
3755
|
const maxAngle = 360, moveSpeedFactor$1 = 10, defaultDistance = 0;
|
|
3739
3756
|
class WobbleUpdater {
|
|
3740
|
-
|
|
3757
|
+
#container;
|
|
3741
3758
|
constructor(container) {
|
|
3742
|
-
this
|
|
3759
|
+
this.#container = container;
|
|
3743
3760
|
}
|
|
3744
3761
|
init(particle) {
|
|
3745
3762
|
const wobbleOpt = particle.options.wobble;
|
|
@@ -3758,7 +3775,7 @@
|
|
|
3758
3775
|
};
|
|
3759
3776
|
}
|
|
3760
3777
|
particle.retina.wobbleDistance =
|
|
3761
|
-
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.
|
|
3778
|
+
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.#container.retina.pixelRatio;
|
|
3762
3779
|
}
|
|
3763
3780
|
isEnabled(particle) {
|
|
3764
3781
|
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
|
|
@@ -3773,12 +3790,12 @@
|
|
|
3773
3790
|
if (!this.isEnabled(particle)) {
|
|
3774
3791
|
return;
|
|
3775
3792
|
}
|
|
3776
|
-
updateWobble(this
|
|
3793
|
+
updateWobble(this.#container, particle, delta);
|
|
3777
3794
|
}
|
|
3778
3795
|
}
|
|
3779
3796
|
|
|
3780
3797
|
async function loadWobbleUpdater(engine) {
|
|
3781
|
-
engine.checkVersion("4.0
|
|
3798
|
+
engine.checkVersion("4.1.0");
|
|
3782
3799
|
await engine.pluginManager.register(e => {
|
|
3783
3800
|
e.pluginManager.addParticleUpdater("wobble", container => {
|
|
3784
3801
|
return Promise.resolve(new WobbleUpdater(container));
|
|
@@ -3835,58 +3852,58 @@
|
|
|
3835
3852
|
}
|
|
3836
3853
|
}
|
|
3837
3854
|
class RenderManager {
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3855
|
+
#canvasClearPlugins;
|
|
3856
|
+
#canvasManager;
|
|
3857
|
+
#canvasPaintPlugins;
|
|
3858
|
+
#clearDrawPlugins;
|
|
3859
|
+
#colorPlugins;
|
|
3860
|
+
#container;
|
|
3861
|
+
#context;
|
|
3862
|
+
#contextSettings;
|
|
3863
|
+
#drawParticlePlugins;
|
|
3864
|
+
#drawParticlesCleanupPlugins;
|
|
3865
|
+
#drawParticlesSetupPlugins;
|
|
3866
|
+
#drawPlugins;
|
|
3867
|
+
#drawSettingsCleanupPlugins;
|
|
3868
|
+
#drawSettingsSetupPlugins;
|
|
3869
|
+
#pluginManager;
|
|
3870
|
+
#postDrawUpdaters;
|
|
3871
|
+
#preDrawUpdaters;
|
|
3872
|
+
#reusableColorStyles = {};
|
|
3873
|
+
#reusablePluginColors = [undefined, undefined];
|
|
3874
|
+
#reusableTransform = {};
|
|
3858
3875
|
constructor(pluginManager, container, canvasManager) {
|
|
3859
|
-
this
|
|
3860
|
-
this
|
|
3861
|
-
this
|
|
3862
|
-
this
|
|
3863
|
-
this
|
|
3864
|
-
this
|
|
3865
|
-
this
|
|
3866
|
-
this
|
|
3867
|
-
this
|
|
3868
|
-
this
|
|
3869
|
-
this
|
|
3870
|
-
this
|
|
3871
|
-
this
|
|
3872
|
-
this
|
|
3873
|
-
this
|
|
3874
|
-
this
|
|
3876
|
+
this.#pluginManager = pluginManager;
|
|
3877
|
+
this.#container = container;
|
|
3878
|
+
this.#canvasManager = canvasManager;
|
|
3879
|
+
this.#context = null;
|
|
3880
|
+
this.#preDrawUpdaters = [];
|
|
3881
|
+
this.#postDrawUpdaters = [];
|
|
3882
|
+
this.#colorPlugins = [];
|
|
3883
|
+
this.#canvasClearPlugins = [];
|
|
3884
|
+
this.#canvasPaintPlugins = [];
|
|
3885
|
+
this.#clearDrawPlugins = [];
|
|
3886
|
+
this.#drawParticlePlugins = [];
|
|
3887
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3888
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3889
|
+
this.#drawPlugins = [];
|
|
3890
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3891
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3875
3892
|
}
|
|
3876
3893
|
get settings() {
|
|
3877
|
-
return this
|
|
3894
|
+
return this.#contextSettings;
|
|
3878
3895
|
}
|
|
3879
3896
|
canvasClear() {
|
|
3880
|
-
if (!this.
|
|
3897
|
+
if (!this.#container.actualOptions.clear) {
|
|
3881
3898
|
return;
|
|
3882
3899
|
}
|
|
3883
3900
|
this.draw(ctx => {
|
|
3884
|
-
clear(ctx, this.
|
|
3901
|
+
clear(ctx, this.#canvasManager.size);
|
|
3885
3902
|
});
|
|
3886
3903
|
}
|
|
3887
3904
|
clear() {
|
|
3888
3905
|
let pluginHandled = false;
|
|
3889
|
-
for (const plugin of this
|
|
3906
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
3890
3907
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
3891
3908
|
if (pluginHandled) {
|
|
3892
3909
|
break;
|
|
@@ -3899,21 +3916,21 @@
|
|
|
3899
3916
|
}
|
|
3900
3917
|
destroy() {
|
|
3901
3918
|
this.stop();
|
|
3902
|
-
this
|
|
3903
|
-
this
|
|
3904
|
-
this
|
|
3905
|
-
this
|
|
3906
|
-
this
|
|
3907
|
-
this
|
|
3908
|
-
this
|
|
3909
|
-
this
|
|
3910
|
-
this
|
|
3911
|
-
this
|
|
3912
|
-
this
|
|
3913
|
-
this
|
|
3919
|
+
this.#preDrawUpdaters = [];
|
|
3920
|
+
this.#postDrawUpdaters = [];
|
|
3921
|
+
this.#colorPlugins = [];
|
|
3922
|
+
this.#canvasClearPlugins = [];
|
|
3923
|
+
this.#canvasPaintPlugins = [];
|
|
3924
|
+
this.#clearDrawPlugins = [];
|
|
3925
|
+
this.#drawParticlePlugins = [];
|
|
3926
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3927
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3928
|
+
this.#drawPlugins = [];
|
|
3929
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3930
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3914
3931
|
}
|
|
3915
3932
|
draw(cb) {
|
|
3916
|
-
const ctx = this
|
|
3933
|
+
const ctx = this.#context;
|
|
3917
3934
|
if (!ctx) {
|
|
3918
3935
|
return;
|
|
3919
3936
|
}
|
|
@@ -3928,21 +3945,21 @@
|
|
|
3928
3945
|
return;
|
|
3929
3946
|
}
|
|
3930
3947
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
3931
|
-
let [fColor, sColor] = this
|
|
3948
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
3932
3949
|
fColor ??= pfColor;
|
|
3933
3950
|
sColor ??= psColor;
|
|
3934
3951
|
if (!fColor && !sColor) {
|
|
3935
3952
|
return;
|
|
3936
3953
|
}
|
|
3937
|
-
const container = this
|
|
3954
|
+
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;
|
|
3938
3955
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
3939
3956
|
colorStyles.fill = fill;
|
|
3940
3957
|
colorStyles.stroke = stroke;
|
|
3941
3958
|
this.draw((context) => {
|
|
3942
|
-
for (const plugin of this
|
|
3959
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
3943
3960
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
3944
3961
|
}
|
|
3945
|
-
this
|
|
3962
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
3946
3963
|
drawParticle({
|
|
3947
3964
|
container,
|
|
3948
3965
|
context,
|
|
@@ -3953,35 +3970,35 @@
|
|
|
3953
3970
|
opacity: opacity,
|
|
3954
3971
|
transform,
|
|
3955
3972
|
});
|
|
3956
|
-
this
|
|
3957
|
-
for (const plugin of this
|
|
3973
|
+
this.#applyPostDrawUpdaters(particle);
|
|
3974
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
3958
3975
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
3959
3976
|
}
|
|
3960
3977
|
});
|
|
3961
3978
|
}
|
|
3962
3979
|
drawParticlePlugins(particle, delta) {
|
|
3963
3980
|
this.draw(ctx => {
|
|
3964
|
-
for (const plugin of this
|
|
3981
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
3965
3982
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
3966
3983
|
}
|
|
3967
3984
|
});
|
|
3968
3985
|
}
|
|
3969
3986
|
drawParticles(delta) {
|
|
3970
|
-
const { particles } = this
|
|
3987
|
+
const { particles } = this.#container;
|
|
3971
3988
|
this.clear();
|
|
3972
3989
|
particles.update(delta);
|
|
3973
3990
|
this.draw(ctx => {
|
|
3974
|
-
for (const plugin of this
|
|
3991
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
3975
3992
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
3976
3993
|
}
|
|
3977
|
-
for (const plugin of this
|
|
3994
|
+
for (const plugin of this.#drawPlugins) {
|
|
3978
3995
|
plugin.draw?.(ctx, delta);
|
|
3979
3996
|
}
|
|
3980
3997
|
particles.drawParticles(delta);
|
|
3981
|
-
for (const plugin of this
|
|
3998
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
3982
3999
|
plugin.clearDraw?.(ctx, delta);
|
|
3983
4000
|
}
|
|
3984
|
-
for (const plugin of this
|
|
4001
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
3985
4002
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
3986
4003
|
}
|
|
3987
4004
|
});
|
|
@@ -3992,64 +4009,64 @@
|
|
|
3992
4009
|
this.paint();
|
|
3993
4010
|
}
|
|
3994
4011
|
initPlugins() {
|
|
3995
|
-
this
|
|
3996
|
-
this
|
|
3997
|
-
this
|
|
3998
|
-
this
|
|
3999
|
-
this
|
|
4000
|
-
this
|
|
4001
|
-
this
|
|
4002
|
-
this
|
|
4003
|
-
this
|
|
4004
|
-
this
|
|
4005
|
-
for (const plugin of this.
|
|
4012
|
+
this.#colorPlugins = [];
|
|
4013
|
+
this.#canvasClearPlugins = [];
|
|
4014
|
+
this.#canvasPaintPlugins = [];
|
|
4015
|
+
this.#clearDrawPlugins = [];
|
|
4016
|
+
this.#drawParticlePlugins = [];
|
|
4017
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4018
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4019
|
+
this.#drawPlugins = [];
|
|
4020
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4021
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4022
|
+
for (const plugin of this.#container.plugins) {
|
|
4006
4023
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4007
|
-
this.
|
|
4024
|
+
this.#colorPlugins.push(plugin);
|
|
4008
4025
|
}
|
|
4009
4026
|
if (plugin.canvasClear) {
|
|
4010
|
-
this.
|
|
4027
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4011
4028
|
}
|
|
4012
4029
|
if (plugin.canvasPaint) {
|
|
4013
|
-
this.
|
|
4030
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4014
4031
|
}
|
|
4015
4032
|
if (plugin.drawParticle) {
|
|
4016
|
-
this.
|
|
4033
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4017
4034
|
}
|
|
4018
4035
|
if (plugin.drawParticleSetup) {
|
|
4019
|
-
this.
|
|
4036
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4020
4037
|
}
|
|
4021
4038
|
if (plugin.drawParticleCleanup) {
|
|
4022
|
-
this.
|
|
4039
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4023
4040
|
}
|
|
4024
4041
|
if (plugin.draw) {
|
|
4025
|
-
this.
|
|
4042
|
+
this.#drawPlugins.push(plugin);
|
|
4026
4043
|
}
|
|
4027
4044
|
if (plugin.drawSettingsSetup) {
|
|
4028
|
-
this.
|
|
4045
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4029
4046
|
}
|
|
4030
4047
|
if (plugin.drawSettingsCleanup) {
|
|
4031
|
-
this.
|
|
4048
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4032
4049
|
}
|
|
4033
4050
|
if (plugin.clearDraw) {
|
|
4034
|
-
this.
|
|
4051
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4035
4052
|
}
|
|
4036
4053
|
}
|
|
4037
4054
|
}
|
|
4038
4055
|
initUpdaters() {
|
|
4039
|
-
this
|
|
4040
|
-
this
|
|
4041
|
-
for (const updater of this.
|
|
4056
|
+
this.#preDrawUpdaters = [];
|
|
4057
|
+
this.#postDrawUpdaters = [];
|
|
4058
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4042
4059
|
if (updater.afterDraw) {
|
|
4043
|
-
this.
|
|
4060
|
+
this.#postDrawUpdaters.push(updater);
|
|
4044
4061
|
}
|
|
4045
4062
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4046
|
-
this.
|
|
4063
|
+
this.#preDrawUpdaters.push(updater);
|
|
4047
4064
|
}
|
|
4048
4065
|
}
|
|
4049
4066
|
}
|
|
4050
4067
|
paint() {
|
|
4051
4068
|
let handled = false;
|
|
4052
|
-
for (const plugin of this
|
|
4069
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4053
4070
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4054
4071
|
if (handled) {
|
|
4055
4072
|
break;
|
|
@@ -4062,35 +4079,35 @@
|
|
|
4062
4079
|
}
|
|
4063
4080
|
paintBase(baseColor) {
|
|
4064
4081
|
this.draw(ctx => {
|
|
4065
|
-
paintBase(ctx, this.
|
|
4082
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4066
4083
|
});
|
|
4067
4084
|
}
|
|
4068
4085
|
paintImage(image, opacity) {
|
|
4069
4086
|
this.draw(ctx => {
|
|
4070
|
-
paintImage(ctx, this.
|
|
4087
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4071
4088
|
});
|
|
4072
4089
|
}
|
|
4073
4090
|
setContext(context) {
|
|
4074
|
-
this
|
|
4075
|
-
if (this
|
|
4076
|
-
this.
|
|
4091
|
+
this.#context = context;
|
|
4092
|
+
if (this.#context) {
|
|
4093
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4077
4094
|
}
|
|
4078
4095
|
}
|
|
4079
4096
|
setContextSettings(settings) {
|
|
4080
|
-
this
|
|
4097
|
+
this.#contextSettings = settings;
|
|
4081
4098
|
}
|
|
4082
4099
|
stop() {
|
|
4083
4100
|
this.draw(ctx => {
|
|
4084
|
-
clear(ctx, this.
|
|
4101
|
+
clear(ctx, this.#canvasManager.size);
|
|
4085
4102
|
});
|
|
4086
4103
|
}
|
|
4087
|
-
|
|
4088
|
-
for (const updater of this
|
|
4104
|
+
#applyPostDrawUpdaters = particle => {
|
|
4105
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4089
4106
|
updater.afterDraw?.(particle);
|
|
4090
4107
|
}
|
|
4091
4108
|
};
|
|
4092
|
-
|
|
4093
|
-
for (const updater of this
|
|
4109
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4110
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4094
4111
|
if (updater.getColorStyles) {
|
|
4095
4112
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4096
4113
|
if (fill) {
|
|
@@ -4109,22 +4126,22 @@
|
|
|
4109
4126
|
updater.beforeDraw?.(particle);
|
|
4110
4127
|
}
|
|
4111
4128
|
};
|
|
4112
|
-
|
|
4129
|
+
#getPluginParticleColors = particle => {
|
|
4113
4130
|
let fColor, sColor;
|
|
4114
|
-
for (const plugin of this
|
|
4131
|
+
for (const plugin of this.#colorPlugins) {
|
|
4115
4132
|
if (!fColor && plugin.particleFillColor) {
|
|
4116
|
-
fColor = rangeColorToHsl(this
|
|
4133
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4117
4134
|
}
|
|
4118
4135
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4119
|
-
sColor = rangeColorToHsl(this
|
|
4136
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4120
4137
|
}
|
|
4121
4138
|
if (fColor && sColor) {
|
|
4122
4139
|
break;
|
|
4123
4140
|
}
|
|
4124
4141
|
}
|
|
4125
|
-
this
|
|
4126
|
-
this
|
|
4127
|
-
return this
|
|
4142
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4143
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4144
|
+
return this.#reusablePluginColors;
|
|
4128
4145
|
};
|
|
4129
4146
|
}
|
|
4130
4147
|
|
|
@@ -4182,53 +4199,53 @@
|
|
|
4182
4199
|
renderCanvas;
|
|
4183
4200
|
size;
|
|
4184
4201
|
zoom = defaultZoom;
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4202
|
+
#container;
|
|
4203
|
+
#generated;
|
|
4204
|
+
#mutationObserver;
|
|
4205
|
+
#originalStyle;
|
|
4206
|
+
#pluginManager;
|
|
4207
|
+
#pointerEvents;
|
|
4208
|
+
#resizePlugins;
|
|
4209
|
+
#standardSize;
|
|
4210
|
+
#zoomCenter;
|
|
4194
4211
|
constructor(pluginManager, container) {
|
|
4195
|
-
this
|
|
4196
|
-
this
|
|
4212
|
+
this.#pluginManager = pluginManager;
|
|
4213
|
+
this.#container = container;
|
|
4197
4214
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4198
|
-
this
|
|
4215
|
+
this.#standardSize = {
|
|
4199
4216
|
height: 0,
|
|
4200
4217
|
width: 0,
|
|
4201
4218
|
};
|
|
4202
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4219
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4203
4220
|
this.size = {
|
|
4204
4221
|
height: stdSize.height * pxRatio,
|
|
4205
4222
|
width: stdSize.width * pxRatio,
|
|
4206
4223
|
};
|
|
4207
|
-
this
|
|
4208
|
-
this
|
|
4209
|
-
this
|
|
4224
|
+
this.#generated = false;
|
|
4225
|
+
this.#resizePlugins = [];
|
|
4226
|
+
this.#pointerEvents = "none";
|
|
4210
4227
|
}
|
|
4211
|
-
get
|
|
4212
|
-
return this.
|
|
4228
|
+
get #fullScreen() {
|
|
4229
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4213
4230
|
}
|
|
4214
4231
|
destroy() {
|
|
4215
4232
|
this.stop();
|
|
4216
|
-
if (this
|
|
4233
|
+
if (this.#generated) {
|
|
4217
4234
|
const element = this.domElement;
|
|
4218
4235
|
element?.remove();
|
|
4219
4236
|
this.domElement = undefined;
|
|
4220
4237
|
this.renderCanvas = undefined;
|
|
4221
4238
|
}
|
|
4222
4239
|
else {
|
|
4223
|
-
this
|
|
4240
|
+
this.#resetOriginalStyle();
|
|
4224
4241
|
}
|
|
4225
4242
|
this.render.destroy();
|
|
4226
|
-
this
|
|
4243
|
+
this.#resizePlugins = [];
|
|
4227
4244
|
}
|
|
4228
4245
|
getZoomCenter() {
|
|
4229
|
-
const pxRatio = this.
|
|
4230
|
-
if (this
|
|
4231
|
-
return this
|
|
4246
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4247
|
+
if (this.#zoomCenter) {
|
|
4248
|
+
return this.#zoomCenter;
|
|
4232
4249
|
}
|
|
4233
4250
|
return {
|
|
4234
4251
|
x: (width * half) / pxRatio,
|
|
@@ -4236,20 +4253,20 @@
|
|
|
4236
4253
|
};
|
|
4237
4254
|
}
|
|
4238
4255
|
init() {
|
|
4239
|
-
this
|
|
4256
|
+
this.#safeMutationObserver(obs => {
|
|
4240
4257
|
obs.disconnect();
|
|
4241
4258
|
});
|
|
4242
|
-
this
|
|
4259
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4243
4260
|
for (const record of records) {
|
|
4244
4261
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4245
|
-
this
|
|
4262
|
+
this.#repairStyle();
|
|
4246
4263
|
}
|
|
4247
4264
|
}
|
|
4248
4265
|
});
|
|
4249
4266
|
this.resize();
|
|
4250
|
-
this
|
|
4267
|
+
this.#initStyle();
|
|
4251
4268
|
this.initBackground();
|
|
4252
|
-
this
|
|
4269
|
+
this.#safeMutationObserver(obs => {
|
|
4253
4270
|
const element = this.domElement;
|
|
4254
4271
|
if (!element || !(element instanceof Node)) {
|
|
4255
4272
|
return;
|
|
@@ -4260,13 +4277,13 @@
|
|
|
4260
4277
|
this.render.init();
|
|
4261
4278
|
}
|
|
4262
4279
|
initBackground() {
|
|
4263
|
-
const
|
|
4280
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4264
4281
|
if (!element) {
|
|
4265
4282
|
return;
|
|
4266
4283
|
}
|
|
4267
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4284
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4268
4285
|
if (color) {
|
|
4269
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4286
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4270
4287
|
}
|
|
4271
4288
|
else {
|
|
4272
4289
|
elementStyle.backgroundColor = "";
|
|
@@ -4277,27 +4294,27 @@
|
|
|
4277
4294
|
elementStyle.backgroundSize = background.size || "";
|
|
4278
4295
|
}
|
|
4279
4296
|
initPlugins() {
|
|
4280
|
-
this
|
|
4281
|
-
for (const plugin of this.
|
|
4297
|
+
this.#resizePlugins = [];
|
|
4298
|
+
for (const plugin of this.#container.plugins) {
|
|
4282
4299
|
if (plugin.resize) {
|
|
4283
|
-
this.
|
|
4300
|
+
this.#resizePlugins.push(plugin);
|
|
4284
4301
|
}
|
|
4285
4302
|
}
|
|
4286
4303
|
}
|
|
4287
4304
|
loadCanvas(canvas) {
|
|
4288
|
-
if (this
|
|
4305
|
+
if (this.#generated && this.domElement) {
|
|
4289
4306
|
this.domElement.remove();
|
|
4290
4307
|
}
|
|
4291
|
-
const container = this
|
|
4308
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4292
4309
|
this.domElement = domCanvas;
|
|
4293
|
-
this
|
|
4310
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4294
4311
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4295
4312
|
const domElement = this.domElement;
|
|
4296
4313
|
if (domElement) {
|
|
4297
4314
|
domElement.ariaHidden = "true";
|
|
4298
|
-
this
|
|
4315
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4299
4316
|
}
|
|
4300
|
-
const standardSize = this
|
|
4317
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4301
4318
|
if (domElement) {
|
|
4302
4319
|
standardSize.height = domElement.offsetHeight;
|
|
4303
4320
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4306,7 +4323,7 @@
|
|
|
4306
4323
|
standardSize.height = renderCanvas.height;
|
|
4307
4324
|
standardSize.width = renderCanvas.width;
|
|
4308
4325
|
}
|
|
4309
|
-
const pxRatio = this.
|
|
4326
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4310
4327
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4311
4328
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4312
4329
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4317,12 +4334,12 @@
|
|
|
4317
4334
|
willReadFrequently: false,
|
|
4318
4335
|
});
|
|
4319
4336
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4320
|
-
this
|
|
4337
|
+
this.#safeMutationObserver(obs => {
|
|
4321
4338
|
obs.disconnect();
|
|
4322
4339
|
});
|
|
4323
4340
|
container.retina.init();
|
|
4324
4341
|
this.initBackground();
|
|
4325
|
-
this
|
|
4342
|
+
this.#safeMutationObserver(obs => {
|
|
4326
4343
|
const element = this.domElement;
|
|
4327
4344
|
if (!element || !(element instanceof Node)) {
|
|
4328
4345
|
return;
|
|
@@ -4335,11 +4352,11 @@
|
|
|
4335
4352
|
if (!element) {
|
|
4336
4353
|
return false;
|
|
4337
4354
|
}
|
|
4338
|
-
const container = this
|
|
4355
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4339
4356
|
if (renderCanvas === undefined) {
|
|
4340
4357
|
return false;
|
|
4341
4358
|
}
|
|
4342
|
-
const currentSize = container.canvas
|
|
4359
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4343
4360
|
width: element.offsetWidth,
|
|
4344
4361
|
height: element.offsetHeight,
|
|
4345
4362
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4358,7 +4375,7 @@
|
|
|
4358
4375
|
const canvasSize = this.size;
|
|
4359
4376
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4360
4377
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4361
|
-
if (this.
|
|
4378
|
+
if (this.#container.started) {
|
|
4362
4379
|
container.particles.setResizeFactor({
|
|
4363
4380
|
width: currentSize.width / oldSize.width,
|
|
4364
4381
|
height: currentSize.height / oldSize.height,
|
|
@@ -4371,46 +4388,46 @@
|
|
|
4371
4388
|
if (!element) {
|
|
4372
4389
|
return;
|
|
4373
4390
|
}
|
|
4374
|
-
this
|
|
4375
|
-
this
|
|
4391
|
+
this.#pointerEvents = type;
|
|
4392
|
+
this.#repairStyle();
|
|
4376
4393
|
}
|
|
4377
4394
|
setZoom(zoomLevel, center) {
|
|
4378
4395
|
this.zoom = zoomLevel;
|
|
4379
|
-
this
|
|
4396
|
+
this.#zoomCenter = center;
|
|
4380
4397
|
}
|
|
4381
4398
|
stop() {
|
|
4382
|
-
this
|
|
4399
|
+
this.#safeMutationObserver(obs => {
|
|
4383
4400
|
obs.disconnect();
|
|
4384
4401
|
});
|
|
4385
|
-
this
|
|
4402
|
+
this.#mutationObserver = undefined;
|
|
4386
4403
|
this.render.stop();
|
|
4387
4404
|
}
|
|
4388
4405
|
async windowResize() {
|
|
4389
4406
|
if (!this.domElement || !this.resize()) {
|
|
4390
4407
|
return;
|
|
4391
4408
|
}
|
|
4392
|
-
const container = this
|
|
4409
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4393
4410
|
container.particles.setDensity();
|
|
4394
|
-
this
|
|
4411
|
+
this.#applyResizePlugins();
|
|
4395
4412
|
if (needsRefresh) {
|
|
4396
4413
|
await container.refresh();
|
|
4397
4414
|
}
|
|
4398
4415
|
}
|
|
4399
|
-
|
|
4400
|
-
for (const plugin of this
|
|
4416
|
+
#applyResizePlugins = () => {
|
|
4417
|
+
for (const plugin of this.#resizePlugins) {
|
|
4401
4418
|
plugin.resize?.();
|
|
4402
4419
|
}
|
|
4403
4420
|
};
|
|
4404
|
-
|
|
4405
|
-
const element = this.domElement, options = this.
|
|
4421
|
+
#initStyle = () => {
|
|
4422
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4406
4423
|
if (!element) {
|
|
4407
4424
|
return;
|
|
4408
4425
|
}
|
|
4409
|
-
if (this
|
|
4410
|
-
this
|
|
4426
|
+
if (this.#fullScreen) {
|
|
4427
|
+
this.#setFullScreenStyle();
|
|
4411
4428
|
}
|
|
4412
4429
|
else {
|
|
4413
|
-
this
|
|
4430
|
+
this.#resetOriginalStyle();
|
|
4414
4431
|
}
|
|
4415
4432
|
for (const key in options.style) {
|
|
4416
4433
|
if (!key || !(key in options.style)) {
|
|
@@ -4423,72 +4440,72 @@
|
|
|
4423
4440
|
element.style.setProperty(key, value, "important");
|
|
4424
4441
|
}
|
|
4425
4442
|
};
|
|
4426
|
-
|
|
4443
|
+
#repairStyle = () => {
|
|
4427
4444
|
const element = this.domElement;
|
|
4428
4445
|
if (!element) {
|
|
4429
4446
|
return;
|
|
4430
4447
|
}
|
|
4431
|
-
this
|
|
4448
|
+
this.#safeMutationObserver(observer => {
|
|
4432
4449
|
observer.disconnect();
|
|
4433
4450
|
});
|
|
4434
|
-
this
|
|
4451
|
+
this.#initStyle();
|
|
4435
4452
|
this.initBackground();
|
|
4436
|
-
const pointerEvents = this
|
|
4453
|
+
const pointerEvents = this.#pointerEvents;
|
|
4437
4454
|
element.style.pointerEvents = pointerEvents;
|
|
4438
4455
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4439
|
-
this
|
|
4456
|
+
this.#safeMutationObserver(observer => {
|
|
4440
4457
|
if (!(element instanceof Node)) {
|
|
4441
4458
|
return;
|
|
4442
4459
|
}
|
|
4443
4460
|
observer.observe(element, { attributes: true });
|
|
4444
4461
|
});
|
|
4445
4462
|
};
|
|
4446
|
-
|
|
4447
|
-
const element = this.domElement, originalStyle = this
|
|
4463
|
+
#resetOriginalStyle = () => {
|
|
4464
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4448
4465
|
if (!element || !originalStyle) {
|
|
4449
4466
|
return;
|
|
4450
4467
|
}
|
|
4451
4468
|
setStyle(element, originalStyle, true);
|
|
4452
4469
|
};
|
|
4453
|
-
|
|
4454
|
-
if (!this
|
|
4470
|
+
#safeMutationObserver = callback => {
|
|
4471
|
+
if (!this.#mutationObserver) {
|
|
4455
4472
|
return;
|
|
4456
4473
|
}
|
|
4457
|
-
callback(this
|
|
4474
|
+
callback(this.#mutationObserver);
|
|
4458
4475
|
};
|
|
4459
|
-
|
|
4476
|
+
#setFullScreenStyle = () => {
|
|
4460
4477
|
const element = this.domElement;
|
|
4461
4478
|
if (!element) {
|
|
4462
4479
|
return;
|
|
4463
4480
|
}
|
|
4464
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4481
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4465
4482
|
};
|
|
4466
4483
|
}
|
|
4467
4484
|
|
|
4468
4485
|
class EventListeners {
|
|
4469
|
-
container;
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4486
|
+
#container;
|
|
4487
|
+
#handlers;
|
|
4488
|
+
#resizeObserver;
|
|
4489
|
+
#resizeTimeout;
|
|
4473
4490
|
constructor(container) {
|
|
4474
|
-
this
|
|
4475
|
-
this
|
|
4491
|
+
this.#container = container;
|
|
4492
|
+
this.#handlers = {
|
|
4476
4493
|
visibilityChange: () => {
|
|
4477
|
-
this
|
|
4494
|
+
this.#handleVisibilityChange();
|
|
4478
4495
|
},
|
|
4479
4496
|
resize: () => {
|
|
4480
|
-
this
|
|
4497
|
+
this.#handleWindowResize();
|
|
4481
4498
|
},
|
|
4482
4499
|
};
|
|
4483
4500
|
}
|
|
4484
4501
|
addListeners() {
|
|
4485
|
-
this
|
|
4502
|
+
this.#manageListeners(true);
|
|
4486
4503
|
}
|
|
4487
4504
|
removeListeners() {
|
|
4488
|
-
this
|
|
4505
|
+
this.#manageListeners(false);
|
|
4489
4506
|
}
|
|
4490
|
-
|
|
4491
|
-
const container = this
|
|
4507
|
+
#handleVisibilityChange = () => {
|
|
4508
|
+
const container = this.#container, options = container.actualOptions;
|
|
4492
4509
|
if (!options.pauseOnBlur) {
|
|
4493
4510
|
return;
|
|
4494
4511
|
}
|
|
@@ -4506,24 +4523,24 @@
|
|
|
4506
4523
|
}
|
|
4507
4524
|
}
|
|
4508
4525
|
};
|
|
4509
|
-
|
|
4510
|
-
if (this
|
|
4511
|
-
clearTimeout(this
|
|
4512
|
-
|
|
4526
|
+
#handleWindowResize = () => {
|
|
4527
|
+
if (this.#resizeTimeout) {
|
|
4528
|
+
clearTimeout(this.#resizeTimeout);
|
|
4529
|
+
this.#resizeTimeout = undefined;
|
|
4513
4530
|
}
|
|
4514
4531
|
const handleResize = async () => {
|
|
4515
|
-
const canvas = this
|
|
4532
|
+
const canvas = this.#container.canvas;
|
|
4516
4533
|
await canvas.windowResize();
|
|
4517
4534
|
};
|
|
4518
|
-
this
|
|
4535
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4519
4536
|
};
|
|
4520
|
-
|
|
4521
|
-
const handlers = this
|
|
4522
|
-
this
|
|
4537
|
+
#manageListeners = add => {
|
|
4538
|
+
const handlers = this.#handlers;
|
|
4539
|
+
this.#manageResize(add);
|
|
4523
4540
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
4524
4541
|
};
|
|
4525
|
-
|
|
4526
|
-
const handlers = this
|
|
4542
|
+
#manageResize = add => {
|
|
4543
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
4527
4544
|
if (!options.resize.enable) {
|
|
4528
4545
|
return;
|
|
4529
4546
|
}
|
|
@@ -4532,22 +4549,22 @@
|
|
|
4532
4549
|
return;
|
|
4533
4550
|
}
|
|
4534
4551
|
const canvasEl = container.canvas.domElement;
|
|
4535
|
-
if (this
|
|
4552
|
+
if (this.#resizeObserver && !add) {
|
|
4536
4553
|
if (canvasEl) {
|
|
4537
|
-
this.
|
|
4554
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
4538
4555
|
}
|
|
4539
|
-
this.
|
|
4540
|
-
|
|
4556
|
+
this.#resizeObserver.disconnect();
|
|
4557
|
+
this.#resizeObserver = undefined;
|
|
4541
4558
|
}
|
|
4542
|
-
else if (!this
|
|
4543
|
-
this
|
|
4559
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4560
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4544
4561
|
const entry = entries.find(e => e.target === canvasEl);
|
|
4545
4562
|
if (!entry) {
|
|
4546
4563
|
return;
|
|
4547
4564
|
}
|
|
4548
|
-
this
|
|
4565
|
+
this.#handleWindowResize();
|
|
4549
4566
|
});
|
|
4550
|
-
this.
|
|
4567
|
+
this.#resizeObserver.observe(canvasEl);
|
|
4551
4568
|
}
|
|
4552
4569
|
};
|
|
4553
4570
|
}
|
|
@@ -4620,24 +4637,24 @@
|
|
|
4620
4637
|
unbreakable;
|
|
4621
4638
|
velocity;
|
|
4622
4639
|
zIndexFactor;
|
|
4623
|
-
|
|
4640
|
+
#cachedOpacityData = {
|
|
4624
4641
|
fillOpacity: defaultOpacity$1,
|
|
4625
4642
|
opacity: defaultOpacity$1,
|
|
4626
4643
|
strokeOpacity: defaultOpacity$1,
|
|
4627
4644
|
};
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4645
|
+
#cachedPosition = Vector3d.origin;
|
|
4646
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
4647
|
+
#cachedTransform = {
|
|
4631
4648
|
a: 1,
|
|
4632
4649
|
b: 0,
|
|
4633
4650
|
c: 0,
|
|
4634
4651
|
d: 1,
|
|
4635
4652
|
};
|
|
4636
|
-
|
|
4637
|
-
|
|
4653
|
+
#container;
|
|
4654
|
+
#pluginManager;
|
|
4638
4655
|
constructor(pluginManager, container) {
|
|
4639
|
-
this
|
|
4640
|
-
this
|
|
4656
|
+
this.#pluginManager = pluginManager;
|
|
4657
|
+
this.#container = container;
|
|
4641
4658
|
}
|
|
4642
4659
|
destroy(override) {
|
|
4643
4660
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -4646,7 +4663,7 @@
|
|
|
4646
4663
|
this.destroyed = true;
|
|
4647
4664
|
this.bubble.inRange = false;
|
|
4648
4665
|
this.slow.inRange = false;
|
|
4649
|
-
const container = this
|
|
4666
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
4650
4667
|
shapeDrawer?.particleDestroy?.(this);
|
|
4651
4668
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
4652
4669
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -4654,12 +4671,12 @@
|
|
|
4654
4671
|
for (const updater of container.particleUpdaters) {
|
|
4655
4672
|
updater.particleDestroyed?.(this, override);
|
|
4656
4673
|
}
|
|
4657
|
-
this.
|
|
4674
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
4658
4675
|
particle: this,
|
|
4659
4676
|
});
|
|
4660
4677
|
}
|
|
4661
4678
|
draw(delta) {
|
|
4662
|
-
const container = this
|
|
4679
|
+
const container = this.#container, render = container.canvas.render;
|
|
4663
4680
|
render.drawParticlePlugins(this, delta);
|
|
4664
4681
|
render.drawParticle(this, delta);
|
|
4665
4682
|
}
|
|
@@ -4667,50 +4684,50 @@
|
|
|
4667
4684
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
4668
4685
|
}
|
|
4669
4686
|
getFillColor() {
|
|
4670
|
-
return this
|
|
4687
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
4671
4688
|
}
|
|
4672
4689
|
getMass() {
|
|
4673
4690
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
4674
4691
|
}
|
|
4675
4692
|
getOpacity() {
|
|
4676
4693
|
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;
|
|
4677
|
-
this.
|
|
4678
|
-
this.
|
|
4679
|
-
this.
|
|
4680
|
-
return this
|
|
4694
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
4695
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
4696
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
4697
|
+
return this.#cachedOpacityData;
|
|
4681
4698
|
}
|
|
4682
4699
|
getPosition() {
|
|
4683
|
-
this.
|
|
4684
|
-
this.
|
|
4685
|
-
this.
|
|
4686
|
-
return this
|
|
4700
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
4701
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
4702
|
+
this.#cachedPosition.z = this.position.z;
|
|
4703
|
+
return this.#cachedPosition;
|
|
4687
4704
|
}
|
|
4688
4705
|
getRadius() {
|
|
4689
4706
|
return this.bubble.radius ?? this.size.value;
|
|
4690
4707
|
}
|
|
4691
4708
|
getRotateData() {
|
|
4692
4709
|
const angle = this.getAngle();
|
|
4693
|
-
this.
|
|
4694
|
-
this.
|
|
4695
|
-
return this
|
|
4710
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
4711
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
4712
|
+
return this.#cachedRotateData;
|
|
4696
4713
|
}
|
|
4697
4714
|
getStrokeColor() {
|
|
4698
|
-
return this
|
|
4715
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
4699
4716
|
}
|
|
4700
4717
|
getTransformData(externalTransform) {
|
|
4701
4718
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
4702
|
-
this.
|
|
4703
|
-
this.
|
|
4719
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
4720
|
+
this.#cachedTransform.b = rotating
|
|
4704
4721
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
4705
4722
|
: (externalTransform.b ?? defaultTransform.b);
|
|
4706
|
-
this.
|
|
4723
|
+
this.#cachedTransform.c = rotating
|
|
4707
4724
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
4708
4725
|
: (externalTransform.c ?? defaultTransform.c);
|
|
4709
|
-
this.
|
|
4710
|
-
return this
|
|
4726
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
4727
|
+
return this.#cachedTransform;
|
|
4711
4728
|
}
|
|
4712
4729
|
init(id, position, overrideOptions, group) {
|
|
4713
|
-
const container = this
|
|
4730
|
+
const container = this.#container;
|
|
4714
4731
|
this.id = id;
|
|
4715
4732
|
this.group = group;
|
|
4716
4733
|
this.justWarped = false;
|
|
@@ -4730,21 +4747,27 @@
|
|
|
4730
4747
|
moveSpeed: 0,
|
|
4731
4748
|
sizeAnimationSpeed: 0,
|
|
4732
4749
|
};
|
|
4750
|
+
this.size = {
|
|
4751
|
+
value: 1,
|
|
4752
|
+
max: 1,
|
|
4753
|
+
min: 1,
|
|
4754
|
+
enable: false,
|
|
4755
|
+
};
|
|
4733
4756
|
this.outType = ParticleOutType.normal;
|
|
4734
4757
|
this.ignoresResizeRatio = true;
|
|
4735
|
-
const
|
|
4758
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
4736
4759
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
4737
4760
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
4738
4761
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
4739
4762
|
if (overrideOptions) {
|
|
4740
|
-
if (overrideOptions.effect?.type) {
|
|
4763
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
4741
4764
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
4742
4765
|
if (effect) {
|
|
4743
4766
|
this.effect = effect;
|
|
4744
4767
|
effectOptions.load(overrideOptions.effect);
|
|
4745
4768
|
}
|
|
4746
4769
|
}
|
|
4747
|
-
if (overrideOptions.shape?.type) {
|
|
4770
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
4748
4771
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
4749
4772
|
if (shape) {
|
|
4750
4773
|
this.shape = shape;
|
|
@@ -4753,21 +4776,20 @@
|
|
|
4753
4776
|
}
|
|
4754
4777
|
}
|
|
4755
4778
|
if (this.effect === randomColorValue) {
|
|
4756
|
-
const availableEffects = [...this.
|
|
4779
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
4757
4780
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
4758
4781
|
}
|
|
4759
4782
|
if (this.shape === randomColorValue) {
|
|
4760
|
-
const availableShapes = [...this.
|
|
4783
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
4761
4784
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
4762
4785
|
}
|
|
4763
4786
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
4764
4787
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
4765
4788
|
particlesOptions.load(overrideOptions);
|
|
4766
|
-
const effectData = this.effectData;
|
|
4789
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
4767
4790
|
if (effectData) {
|
|
4768
4791
|
particlesOptions.load(effectData.particles);
|
|
4769
4792
|
}
|
|
4770
|
-
const shapeData = this.shapeData;
|
|
4771
4793
|
if (shapeData) {
|
|
4772
4794
|
particlesOptions.load(shapeData.particles);
|
|
4773
4795
|
}
|
|
@@ -4775,7 +4797,9 @@
|
|
|
4775
4797
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
4776
4798
|
this.options = particlesOptions;
|
|
4777
4799
|
container.retina.initParticle(this);
|
|
4778
|
-
|
|
4800
|
+
for (const updater of container.particleUpdaters) {
|
|
4801
|
+
updater.preInit?.(this);
|
|
4802
|
+
}
|
|
4779
4803
|
this.bubble = {
|
|
4780
4804
|
inRange: false,
|
|
4781
4805
|
};
|
|
@@ -4783,8 +4807,8 @@
|
|
|
4783
4807
|
inRange: false,
|
|
4784
4808
|
factor: 1,
|
|
4785
4809
|
};
|
|
4786
|
-
this
|
|
4787
|
-
this.initialVelocity = this
|
|
4810
|
+
this.#initPosition(position);
|
|
4811
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
4788
4812
|
this.velocity = this.initialVelocity.copy();
|
|
4789
4813
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
4790
4814
|
this.sides = 24;
|
|
@@ -4815,12 +4839,11 @@
|
|
|
4815
4839
|
plugin.particleCreated?.(this);
|
|
4816
4840
|
}
|
|
4817
4841
|
}
|
|
4818
|
-
isInsideCanvas() {
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
position.x <= canvasSize.width + radius);
|
|
4842
|
+
isInsideCanvas(direction) {
|
|
4843
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
4844
|
+
}
|
|
4845
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
4846
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
4824
4847
|
}
|
|
4825
4848
|
isShowingBack() {
|
|
4826
4849
|
if (!this.roll) {
|
|
@@ -4845,13 +4868,13 @@
|
|
|
4845
4868
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
4846
4869
|
}
|
|
4847
4870
|
reset() {
|
|
4848
|
-
for (const updater of this.
|
|
4871
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4849
4872
|
updater.reset?.(this);
|
|
4850
4873
|
}
|
|
4851
4874
|
}
|
|
4852
|
-
|
|
4875
|
+
#calcPosition = (position, zIndex) => {
|
|
4853
4876
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
4854
|
-
const container = this
|
|
4877
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
4855
4878
|
while (!signal.aborted) {
|
|
4856
4879
|
for (const plugin of plugins) {
|
|
4857
4880
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -4863,10 +4886,10 @@
|
|
|
4863
4886
|
size: canvasSize,
|
|
4864
4887
|
position: posVec,
|
|
4865
4888
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
4866
|
-
this
|
|
4867
|
-
this
|
|
4868
|
-
this
|
|
4869
|
-
this
|
|
4889
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
4890
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
4891
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
4892
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
4870
4893
|
let isValidPosition = true;
|
|
4871
4894
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
4872
4895
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -4882,8 +4905,8 @@
|
|
|
4882
4905
|
}
|
|
4883
4906
|
return posVec;
|
|
4884
4907
|
};
|
|
4885
|
-
|
|
4886
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
4908
|
+
#calculateVelocity = () => {
|
|
4909
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
4887
4910
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
4888
4911
|
return res;
|
|
4889
4912
|
}
|
|
@@ -4899,27 +4922,86 @@
|
|
|
4899
4922
|
}
|
|
4900
4923
|
return res;
|
|
4901
4924
|
};
|
|
4902
|
-
|
|
4925
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
4903
4926
|
fixOutMode({
|
|
4904
4927
|
outMode,
|
|
4905
4928
|
checkModes: [OutMode.bounce],
|
|
4906
4929
|
coord: pos.x,
|
|
4907
|
-
maxCoord: this.
|
|
4930
|
+
maxCoord: this.#container.canvas.size.width,
|
|
4908
4931
|
setCb: (value) => (pos.x += value),
|
|
4909
4932
|
radius,
|
|
4910
4933
|
});
|
|
4911
4934
|
};
|
|
4912
|
-
|
|
4935
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
4913
4936
|
fixOutMode({
|
|
4914
4937
|
outMode,
|
|
4915
4938
|
checkModes: [OutMode.bounce],
|
|
4916
4939
|
coord: pos.y,
|
|
4917
|
-
maxCoord: this.
|
|
4940
|
+
maxCoord: this.#container.canvas.size.height,
|
|
4918
4941
|
setCb: (value) => (pos.y += value),
|
|
4919
4942
|
radius,
|
|
4920
4943
|
});
|
|
4921
4944
|
};
|
|
4922
|
-
|
|
4945
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
4946
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
4947
|
+
if (direction === OutModeDirection.bottom) {
|
|
4948
|
+
return {
|
|
4949
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
4950
|
+
reason: "default",
|
|
4951
|
+
};
|
|
4952
|
+
}
|
|
4953
|
+
if (direction === OutModeDirection.left) {
|
|
4954
|
+
return {
|
|
4955
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
4956
|
+
reason: "default",
|
|
4957
|
+
};
|
|
4958
|
+
}
|
|
4959
|
+
if (direction === OutModeDirection.right) {
|
|
4960
|
+
return {
|
|
4961
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
4962
|
+
reason: "default",
|
|
4963
|
+
};
|
|
4964
|
+
}
|
|
4965
|
+
if (direction === OutModeDirection.top) {
|
|
4966
|
+
return {
|
|
4967
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
4968
|
+
reason: "default",
|
|
4969
|
+
};
|
|
4970
|
+
}
|
|
4971
|
+
return {
|
|
4972
|
+
inside: position.x >= -radius &&
|
|
4973
|
+
position.y >= -radius &&
|
|
4974
|
+
position.y <= canvasSize.height + radius &&
|
|
4975
|
+
position.x <= canvasSize.width + radius,
|
|
4976
|
+
reason: "default",
|
|
4977
|
+
};
|
|
4978
|
+
};
|
|
4979
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
4980
|
+
return {
|
|
4981
|
+
canvasSize: this.#container.canvas.size,
|
|
4982
|
+
direction,
|
|
4983
|
+
outMode,
|
|
4984
|
+
particle: this,
|
|
4985
|
+
radius: this.getRadius(),
|
|
4986
|
+
};
|
|
4987
|
+
};
|
|
4988
|
+
#getInsideCanvasResult = (data) => {
|
|
4989
|
+
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;
|
|
4990
|
+
if (!shapeCheck && !effectCheck) {
|
|
4991
|
+
return defaultResult;
|
|
4992
|
+
}
|
|
4993
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
4994
|
+
if (shapeResult && effectResult) {
|
|
4995
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
4996
|
+
return {
|
|
4997
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
4998
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
4999
|
+
reason: "combined",
|
|
5000
|
+
};
|
|
5001
|
+
}
|
|
5002
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5003
|
+
};
|
|
5004
|
+
#getRollColor = color => {
|
|
4923
5005
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
4924
5006
|
return color;
|
|
4925
5007
|
}
|
|
@@ -4934,8 +5016,8 @@
|
|
|
4934
5016
|
}
|
|
4935
5017
|
return color;
|
|
4936
5018
|
};
|
|
4937
|
-
|
|
4938
|
-
const container = this
|
|
5019
|
+
#initPosition = position => {
|
|
5020
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
4939
5021
|
if (!initialPosition) {
|
|
4940
5022
|
throw new Error("a valid position cannot be found for particle");
|
|
4941
5023
|
}
|
|
@@ -4958,45 +5040,58 @@
|
|
|
4958
5040
|
}
|
|
4959
5041
|
this.offset = Vector.origin;
|
|
4960
5042
|
};
|
|
5043
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5044
|
+
if (typeof result === "boolean") {
|
|
5045
|
+
return {
|
|
5046
|
+
inside: result,
|
|
5047
|
+
reason,
|
|
5048
|
+
};
|
|
5049
|
+
}
|
|
5050
|
+
return {
|
|
5051
|
+
inside: result.inside,
|
|
5052
|
+
margin: result.margin,
|
|
5053
|
+
reason: result.reason ?? reason,
|
|
5054
|
+
};
|
|
5055
|
+
};
|
|
4961
5056
|
}
|
|
4962
5057
|
|
|
4963
5058
|
class SpatialHashGrid {
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
5059
|
+
#cellSize;
|
|
5060
|
+
#cells = new Map();
|
|
5061
|
+
#circlePool = [];
|
|
5062
|
+
#circlePoolIdx;
|
|
5063
|
+
#pendingCellSize;
|
|
5064
|
+
#rectanglePool = [];
|
|
5065
|
+
#rectanglePoolIdx;
|
|
4971
5066
|
constructor(cellSize) {
|
|
4972
|
-
this
|
|
4973
|
-
this
|
|
4974
|
-
this
|
|
5067
|
+
this.#cellSize = cellSize;
|
|
5068
|
+
this.#circlePoolIdx = 0;
|
|
5069
|
+
this.#rectanglePoolIdx = 0;
|
|
4975
5070
|
}
|
|
4976
5071
|
clear() {
|
|
4977
|
-
this.
|
|
4978
|
-
const pendingCellSize = this
|
|
5072
|
+
this.#cells.clear();
|
|
5073
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
4979
5074
|
if (pendingCellSize) {
|
|
4980
|
-
this
|
|
5075
|
+
this.#cellSize = pendingCellSize;
|
|
4981
5076
|
}
|
|
4982
|
-
this
|
|
5077
|
+
this.#pendingCellSize = undefined;
|
|
4983
5078
|
}
|
|
4984
5079
|
insert(particle) {
|
|
4985
|
-
const { x, y } = particle.getPosition(), key = this
|
|
4986
|
-
if (!this.
|
|
4987
|
-
this.
|
|
5080
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5081
|
+
if (!this.#cells.has(key)) {
|
|
5082
|
+
this.#cells.set(key, []);
|
|
4988
5083
|
}
|
|
4989
|
-
this.
|
|
5084
|
+
this.#cells.get(key)?.push(particle);
|
|
4990
5085
|
}
|
|
4991
5086
|
query(range, check, out = []) {
|
|
4992
|
-
const bounds = this
|
|
5087
|
+
const bounds = this.#getRangeBounds(range);
|
|
4993
5088
|
if (!bounds) {
|
|
4994
5089
|
return out;
|
|
4995
5090
|
}
|
|
4996
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5091
|
+
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);
|
|
4997
5092
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
4998
5093
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
4999
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5094
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5000
5095
|
if (!cellParticles) {
|
|
5001
5096
|
continue;
|
|
5002
5097
|
}
|
|
@@ -5013,29 +5108,29 @@
|
|
|
5013
5108
|
return out;
|
|
5014
5109
|
}
|
|
5015
5110
|
queryCircle(position, radius, check, out = []) {
|
|
5016
|
-
const circle = this
|
|
5017
|
-
this
|
|
5111
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5112
|
+
this.#releaseShapes();
|
|
5018
5113
|
return result;
|
|
5019
5114
|
}
|
|
5020
5115
|
queryRectangle(position, size, check, out = []) {
|
|
5021
|
-
const rect = this
|
|
5022
|
-
this
|
|
5116
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5117
|
+
this.#releaseShapes();
|
|
5023
5118
|
return result;
|
|
5024
5119
|
}
|
|
5025
5120
|
setCellSize(cellSize) {
|
|
5026
|
-
this
|
|
5121
|
+
this.#pendingCellSize = cellSize;
|
|
5027
5122
|
}
|
|
5028
|
-
|
|
5029
|
-
return (this
|
|
5123
|
+
#acquireCircle(x, y, r) {
|
|
5124
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5030
5125
|
}
|
|
5031
|
-
|
|
5032
|
-
return (this
|
|
5126
|
+
#acquireRectangle(x, y, w, h) {
|
|
5127
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5033
5128
|
}
|
|
5034
|
-
|
|
5035
|
-
const cellX = Math.floor(x / this
|
|
5129
|
+
#cellKeyFromCoords(x, y) {
|
|
5130
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5036
5131
|
return `${cellX}_${cellY}`;
|
|
5037
5132
|
}
|
|
5038
|
-
|
|
5133
|
+
#getRangeBounds(range) {
|
|
5039
5134
|
if (range instanceof Circle) {
|
|
5040
5135
|
const r = range.radius, { x, y } = range.position;
|
|
5041
5136
|
return {
|
|
@@ -5056,53 +5151,53 @@
|
|
|
5056
5151
|
}
|
|
5057
5152
|
return null;
|
|
5058
5153
|
}
|
|
5059
|
-
|
|
5060
|
-
this
|
|
5061
|
-
this
|
|
5154
|
+
#releaseShapes() {
|
|
5155
|
+
this.#circlePoolIdx = 0;
|
|
5156
|
+
this.#rectanglePoolIdx = 0;
|
|
5062
5157
|
}
|
|
5063
5158
|
}
|
|
5064
5159
|
|
|
5065
5160
|
class ParticlesManager {
|
|
5066
5161
|
checkParticlePositionPlugins;
|
|
5067
5162
|
grid;
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5163
|
+
#array;
|
|
5164
|
+
#container;
|
|
5165
|
+
#groupLimits;
|
|
5166
|
+
#limit;
|
|
5167
|
+
#nextId;
|
|
5168
|
+
#particleBuckets;
|
|
5169
|
+
#particleResetPlugins;
|
|
5170
|
+
#particleUpdatePlugins;
|
|
5171
|
+
#pluginManager;
|
|
5172
|
+
#pool;
|
|
5173
|
+
#postParticleUpdatePlugins;
|
|
5174
|
+
#postUpdatePlugins;
|
|
5175
|
+
#resizeFactor;
|
|
5176
|
+
#updatePlugins;
|
|
5177
|
+
#zBuckets;
|
|
5083
5178
|
constructor(pluginManager, container) {
|
|
5084
|
-
this
|
|
5085
|
-
this
|
|
5086
|
-
this
|
|
5087
|
-
this
|
|
5088
|
-
this
|
|
5089
|
-
this
|
|
5090
|
-
this
|
|
5091
|
-
this
|
|
5092
|
-
this
|
|
5179
|
+
this.#pluginManager = pluginManager;
|
|
5180
|
+
this.#container = container;
|
|
5181
|
+
this.#nextId = 0;
|
|
5182
|
+
this.#array = [];
|
|
5183
|
+
this.#pool = [];
|
|
5184
|
+
this.#limit = 0;
|
|
5185
|
+
this.#groupLimits = new Map();
|
|
5186
|
+
this.#particleBuckets = new Map();
|
|
5187
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5093
5188
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5094
5189
|
this.checkParticlePositionPlugins = [];
|
|
5095
|
-
this
|
|
5096
|
-
this
|
|
5097
|
-
this
|
|
5098
|
-
this
|
|
5099
|
-
this
|
|
5190
|
+
this.#particleResetPlugins = [];
|
|
5191
|
+
this.#particleUpdatePlugins = [];
|
|
5192
|
+
this.#postUpdatePlugins = [];
|
|
5193
|
+
this.#postParticleUpdatePlugins = [];
|
|
5194
|
+
this.#updatePlugins = [];
|
|
5100
5195
|
}
|
|
5101
5196
|
get count() {
|
|
5102
|
-
return this.
|
|
5197
|
+
return this.#array.length;
|
|
5103
5198
|
}
|
|
5104
5199
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5105
|
-
const limitMode = this.
|
|
5200
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5106
5201
|
if (limit > minLimit) {
|
|
5107
5202
|
switch (limitMode) {
|
|
5108
5203
|
case LimitMode.delete: {
|
|
@@ -5120,20 +5215,20 @@
|
|
|
5120
5215
|
}
|
|
5121
5216
|
}
|
|
5122
5217
|
try {
|
|
5123
|
-
const particle = this.
|
|
5124
|
-
particle.init(this
|
|
5218
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5219
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5125
5220
|
let canAdd = true;
|
|
5126
5221
|
if (initializer) {
|
|
5127
5222
|
canAdd = initializer(particle);
|
|
5128
5223
|
}
|
|
5129
5224
|
if (!canAdd) {
|
|
5130
|
-
this.
|
|
5225
|
+
this.#pool.push(particle);
|
|
5131
5226
|
return;
|
|
5132
5227
|
}
|
|
5133
|
-
this.
|
|
5134
|
-
this
|
|
5135
|
-
this
|
|
5136
|
-
this.
|
|
5228
|
+
this.#array.push(particle);
|
|
5229
|
+
this.#insertParticleIntoBucket(particle);
|
|
5230
|
+
this.#nextId++;
|
|
5231
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5137
5232
|
particle,
|
|
5138
5233
|
});
|
|
5139
5234
|
return particle;
|
|
@@ -5144,25 +5239,25 @@
|
|
|
5144
5239
|
return undefined;
|
|
5145
5240
|
}
|
|
5146
5241
|
clear() {
|
|
5147
|
-
this
|
|
5148
|
-
this.
|
|
5149
|
-
this
|
|
5242
|
+
this.#array = [];
|
|
5243
|
+
this.#particleBuckets.clear();
|
|
5244
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5150
5245
|
}
|
|
5151
5246
|
destroy() {
|
|
5152
|
-
this
|
|
5153
|
-
this.
|
|
5154
|
-
this.
|
|
5155
|
-
this
|
|
5247
|
+
this.#array = [];
|
|
5248
|
+
this.#pool.length = 0;
|
|
5249
|
+
this.#particleBuckets.clear();
|
|
5250
|
+
this.#zBuckets = [];
|
|
5156
5251
|
this.checkParticlePositionPlugins = [];
|
|
5157
|
-
this
|
|
5158
|
-
this
|
|
5159
|
-
this
|
|
5160
|
-
this
|
|
5161
|
-
this
|
|
5252
|
+
this.#particleResetPlugins = [];
|
|
5253
|
+
this.#particleUpdatePlugins = [];
|
|
5254
|
+
this.#postUpdatePlugins = [];
|
|
5255
|
+
this.#postParticleUpdatePlugins = [];
|
|
5256
|
+
this.#updatePlugins = [];
|
|
5162
5257
|
}
|
|
5163
5258
|
drawParticles(delta) {
|
|
5164
|
-
for (let i = this.
|
|
5165
|
-
const bucket = this
|
|
5259
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5260
|
+
const bucket = this.#zBuckets[i];
|
|
5166
5261
|
if (!bucket) {
|
|
5167
5262
|
continue;
|
|
5168
5263
|
}
|
|
@@ -5172,24 +5267,24 @@
|
|
|
5172
5267
|
}
|
|
5173
5268
|
}
|
|
5174
5269
|
filter(condition) {
|
|
5175
|
-
return this.
|
|
5270
|
+
return this.#array.filter(condition);
|
|
5176
5271
|
}
|
|
5177
5272
|
find(condition) {
|
|
5178
|
-
return this.
|
|
5273
|
+
return this.#array.find(condition);
|
|
5179
5274
|
}
|
|
5180
5275
|
get(index) {
|
|
5181
|
-
return this
|
|
5276
|
+
return this.#array[index];
|
|
5182
5277
|
}
|
|
5183
5278
|
async init() {
|
|
5184
|
-
const container = this
|
|
5279
|
+
const container = this.#container, options = container.actualOptions;
|
|
5185
5280
|
this.checkParticlePositionPlugins = [];
|
|
5186
|
-
this
|
|
5187
|
-
this
|
|
5188
|
-
this
|
|
5189
|
-
this
|
|
5190
|
-
this
|
|
5191
|
-
this.
|
|
5192
|
-
this
|
|
5281
|
+
this.#updatePlugins = [];
|
|
5282
|
+
this.#particleUpdatePlugins = [];
|
|
5283
|
+
this.#postUpdatePlugins = [];
|
|
5284
|
+
this.#particleResetPlugins = [];
|
|
5285
|
+
this.#postParticleUpdatePlugins = [];
|
|
5286
|
+
this.#particleBuckets.clear();
|
|
5287
|
+
this.#resetBuckets(container.zLayers);
|
|
5193
5288
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5194
5289
|
for (const plugin of container.plugins) {
|
|
5195
5290
|
if (plugin.redrawInit) {
|
|
@@ -5199,26 +5294,26 @@
|
|
|
5199
5294
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5200
5295
|
}
|
|
5201
5296
|
if (plugin.update) {
|
|
5202
|
-
this.
|
|
5297
|
+
this.#updatePlugins.push(plugin);
|
|
5203
5298
|
}
|
|
5204
5299
|
if (plugin.particleUpdate) {
|
|
5205
|
-
this.
|
|
5300
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5206
5301
|
}
|
|
5207
5302
|
if (plugin.postUpdate) {
|
|
5208
|
-
this.
|
|
5303
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5209
5304
|
}
|
|
5210
5305
|
if (plugin.particleReset) {
|
|
5211
|
-
this.
|
|
5306
|
+
this.#particleResetPlugins.push(plugin);
|
|
5212
5307
|
}
|
|
5213
5308
|
if (plugin.postParticleUpdate) {
|
|
5214
|
-
this.
|
|
5309
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5215
5310
|
}
|
|
5216
5311
|
}
|
|
5217
|
-
await this.
|
|
5218
|
-
for (const drawer of this.
|
|
5312
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5313
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5219
5314
|
await drawer.init?.(container);
|
|
5220
5315
|
}
|
|
5221
|
-
for (const drawer of this.
|
|
5316
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5222
5317
|
await drawer.init?.(container);
|
|
5223
5318
|
}
|
|
5224
5319
|
let handled = false;
|
|
@@ -5252,10 +5347,10 @@
|
|
|
5252
5347
|
async redraw() {
|
|
5253
5348
|
this.clear();
|
|
5254
5349
|
await this.init();
|
|
5255
|
-
this.
|
|
5350
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5256
5351
|
}
|
|
5257
5352
|
remove(particle, group, override) {
|
|
5258
|
-
this.removeAt(this.
|
|
5353
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5259
5354
|
}
|
|
5260
5355
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5261
5356
|
if (index < minIndex || index > this.count) {
|
|
@@ -5263,7 +5358,7 @@
|
|
|
5263
5358
|
}
|
|
5264
5359
|
let deleted = 0;
|
|
5265
5360
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5266
|
-
if (this
|
|
5361
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5267
5362
|
i--;
|
|
5268
5363
|
deleted++;
|
|
5269
5364
|
}
|
|
@@ -5273,9 +5368,9 @@
|
|
|
5273
5368
|
this.removeAt(minIndex, quantity, group);
|
|
5274
5369
|
}
|
|
5275
5370
|
setDensity() {
|
|
5276
|
-
const options = this.
|
|
5371
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5277
5372
|
let pluginsCount = 0;
|
|
5278
|
-
for (const plugin of this.
|
|
5373
|
+
for (const plugin of this.#container.plugins) {
|
|
5279
5374
|
if (plugin.particlesDensityCount) {
|
|
5280
5375
|
pluginsCount += plugin.particlesDensityCount();
|
|
5281
5376
|
}
|
|
@@ -5285,51 +5380,51 @@
|
|
|
5285
5380
|
if (!groupData) {
|
|
5286
5381
|
continue;
|
|
5287
5382
|
}
|
|
5288
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5289
|
-
this
|
|
5383
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5384
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5290
5385
|
}
|
|
5291
|
-
this
|
|
5386
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5292
5387
|
}
|
|
5293
5388
|
setResizeFactor(factor) {
|
|
5294
|
-
this
|
|
5389
|
+
this.#resizeFactor = factor;
|
|
5295
5390
|
}
|
|
5296
5391
|
update(delta) {
|
|
5297
5392
|
this.grid.clear();
|
|
5298
|
-
for (const plugin of this
|
|
5393
|
+
for (const plugin of this.#updatePlugins) {
|
|
5299
5394
|
plugin.update?.(delta);
|
|
5300
5395
|
}
|
|
5301
|
-
const particlesToDelete = this
|
|
5302
|
-
for (const plugin of this
|
|
5396
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5397
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5303
5398
|
plugin.postUpdate?.(delta);
|
|
5304
5399
|
}
|
|
5305
|
-
this
|
|
5400
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5306
5401
|
if (particlesToDelete.size) {
|
|
5307
5402
|
for (const particle of particlesToDelete) {
|
|
5308
5403
|
this.remove(particle);
|
|
5309
5404
|
}
|
|
5310
5405
|
}
|
|
5311
|
-
|
|
5406
|
+
this.#resizeFactor = undefined;
|
|
5312
5407
|
}
|
|
5313
|
-
|
|
5314
|
-
this.
|
|
5408
|
+
#addToPool = (...particles) => {
|
|
5409
|
+
this.#pool.push(...particles);
|
|
5315
5410
|
};
|
|
5316
|
-
|
|
5411
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5317
5412
|
const numberOptions = options.number;
|
|
5318
5413
|
if (!numberOptions.density.enable) {
|
|
5319
5414
|
if (group === undefined) {
|
|
5320
|
-
this
|
|
5415
|
+
this.#limit = numberOptions.limit.value;
|
|
5321
5416
|
}
|
|
5322
5417
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5323
|
-
this.
|
|
5418
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5324
5419
|
}
|
|
5325
5420
|
return;
|
|
5326
5421
|
}
|
|
5327
|
-
const densityFactor = this
|
|
5422
|
+
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);
|
|
5328
5423
|
if (group === undefined) {
|
|
5329
|
-
this
|
|
5424
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5330
5425
|
}
|
|
5331
5426
|
else {
|
|
5332
|
-
this.
|
|
5427
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5333
5428
|
}
|
|
5334
5429
|
if (particlesCount < particlesNumber) {
|
|
5335
5430
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5338,18 +5433,18 @@
|
|
|
5338
5433
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5339
5434
|
}
|
|
5340
5435
|
};
|
|
5341
|
-
|
|
5436
|
+
#createBuckets = (zLayers) => {
|
|
5342
5437
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5343
5438
|
return Array.from({ length: bucketCount }, () => []);
|
|
5344
5439
|
};
|
|
5345
|
-
|
|
5346
|
-
const maxBucketIndex = this.
|
|
5440
|
+
#getBucketIndex = (zIndex) => {
|
|
5441
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5347
5442
|
if (maxBucketIndex <= minIndex) {
|
|
5348
5443
|
return minIndex;
|
|
5349
5444
|
}
|
|
5350
5445
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5351
5446
|
};
|
|
5352
|
-
|
|
5447
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5353
5448
|
let start = minIndex, end = bucket.length;
|
|
5354
5449
|
while (start < end) {
|
|
5355
5450
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5366,8 +5461,8 @@
|
|
|
5366
5461
|
}
|
|
5367
5462
|
return start;
|
|
5368
5463
|
};
|
|
5369
|
-
|
|
5370
|
-
const container = this
|
|
5464
|
+
#initDensityFactor = densityOptions => {
|
|
5465
|
+
const container = this.#container;
|
|
5371
5466
|
if (!densityOptions.enable) {
|
|
5372
5467
|
return defaultDensityFactor;
|
|
5373
5468
|
}
|
|
@@ -5377,82 +5472,82 @@
|
|
|
5377
5472
|
}
|
|
5378
5473
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5379
5474
|
};
|
|
5380
|
-
|
|
5381
|
-
const bucketIndex = this
|
|
5475
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5476
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5382
5477
|
if (!bucket) {
|
|
5383
5478
|
return;
|
|
5384
5479
|
}
|
|
5385
|
-
bucket.splice(this
|
|
5386
|
-
this.
|
|
5480
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5481
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5387
5482
|
};
|
|
5388
|
-
|
|
5389
|
-
const particle = this
|
|
5483
|
+
#removeParticle = (index, group, override) => {
|
|
5484
|
+
const particle = this.#array[index];
|
|
5390
5485
|
if (!particle) {
|
|
5391
5486
|
return false;
|
|
5392
5487
|
}
|
|
5393
5488
|
if (particle.group !== group) {
|
|
5394
5489
|
return false;
|
|
5395
5490
|
}
|
|
5396
|
-
this.
|
|
5397
|
-
this
|
|
5491
|
+
this.#array.splice(index, deleteCount);
|
|
5492
|
+
this.#removeParticleFromBucket(particle);
|
|
5398
5493
|
particle.destroy(override);
|
|
5399
|
-
this.
|
|
5494
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5400
5495
|
particle,
|
|
5401
5496
|
});
|
|
5402
|
-
this
|
|
5497
|
+
this.#addToPool(particle);
|
|
5403
5498
|
return true;
|
|
5404
5499
|
};
|
|
5405
|
-
|
|
5406
|
-
const bucketIndex = this.
|
|
5500
|
+
#removeParticleFromBucket = (particle) => {
|
|
5501
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5407
5502
|
if (!bucket) {
|
|
5408
|
-
this.
|
|
5503
|
+
this.#particleBuckets.delete(particle.id);
|
|
5409
5504
|
return;
|
|
5410
5505
|
}
|
|
5411
|
-
const particleIndex = this
|
|
5506
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5412
5507
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5413
|
-
this.
|
|
5508
|
+
this.#particleBuckets.delete(particle.id);
|
|
5414
5509
|
return;
|
|
5415
5510
|
}
|
|
5416
5511
|
bucket.splice(particleIndex, deleteCount);
|
|
5417
|
-
this.
|
|
5512
|
+
this.#particleBuckets.delete(particle.id);
|
|
5418
5513
|
};
|
|
5419
|
-
|
|
5514
|
+
#resetBuckets = (zLayers) => {
|
|
5420
5515
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5421
|
-
if (this.
|
|
5422
|
-
this
|
|
5516
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
5517
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5423
5518
|
return;
|
|
5424
5519
|
}
|
|
5425
|
-
for (const bucket of this
|
|
5520
|
+
for (const bucket of this.#zBuckets) {
|
|
5426
5521
|
bucket.length = minIndex;
|
|
5427
5522
|
}
|
|
5428
5523
|
};
|
|
5429
|
-
|
|
5430
|
-
const newBucketIndex = this
|
|
5524
|
+
#updateParticleBucket = (particle) => {
|
|
5525
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5431
5526
|
if (currentBucketIndex === undefined) {
|
|
5432
|
-
this
|
|
5527
|
+
this.#insertParticleIntoBucket(particle);
|
|
5433
5528
|
return;
|
|
5434
5529
|
}
|
|
5435
5530
|
if (currentBucketIndex === newBucketIndex) {
|
|
5436
5531
|
return;
|
|
5437
5532
|
}
|
|
5438
|
-
const currentBucket = this
|
|
5533
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5439
5534
|
if (currentBucket) {
|
|
5440
|
-
const particleIndex = this
|
|
5535
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5441
5536
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5442
5537
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5443
5538
|
}
|
|
5444
5539
|
}
|
|
5445
|
-
const newBucket = this
|
|
5540
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5446
5541
|
if (!newBucket) {
|
|
5447
|
-
this.
|
|
5542
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5448
5543
|
return;
|
|
5449
5544
|
}
|
|
5450
|
-
newBucket.splice(this
|
|
5451
|
-
this.
|
|
5545
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
5546
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5452
5547
|
};
|
|
5453
|
-
|
|
5454
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5455
|
-
for (const particle of this
|
|
5548
|
+
#updateParticlesPhase1 = (delta) => {
|
|
5549
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
5550
|
+
for (const particle of this.#array) {
|
|
5456
5551
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5457
5552
|
particle.position.x *= resizeFactor.width;
|
|
5458
5553
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5460,10 +5555,10 @@
|
|
|
5460
5555
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5461
5556
|
}
|
|
5462
5557
|
particle.ignoresResizeRatio = false;
|
|
5463
|
-
for (const plugin of this
|
|
5558
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5464
5559
|
plugin.particleReset?.(particle);
|
|
5465
5560
|
}
|
|
5466
|
-
for (const plugin of this
|
|
5561
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5467
5562
|
if (particle.destroyed) {
|
|
5468
5563
|
break;
|
|
5469
5564
|
}
|
|
@@ -5477,36 +5572,36 @@
|
|
|
5477
5572
|
}
|
|
5478
5573
|
return particlesToDelete;
|
|
5479
5574
|
};
|
|
5480
|
-
|
|
5481
|
-
for (const particle of this
|
|
5575
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
5576
|
+
for (const particle of this.#array) {
|
|
5482
5577
|
if (particle.destroyed) {
|
|
5483
5578
|
particlesToDelete.add(particle);
|
|
5484
5579
|
continue;
|
|
5485
5580
|
}
|
|
5486
|
-
for (const updater of this.
|
|
5581
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5487
5582
|
updater.update(particle, delta);
|
|
5488
5583
|
}
|
|
5489
5584
|
if (!particle.spawning) {
|
|
5490
|
-
for (const plugin of this
|
|
5585
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5491
5586
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5492
5587
|
}
|
|
5493
5588
|
}
|
|
5494
|
-
this
|
|
5589
|
+
this.#updateParticleBucket(particle);
|
|
5495
5590
|
}
|
|
5496
5591
|
};
|
|
5497
5592
|
}
|
|
5498
5593
|
|
|
5499
5594
|
class Retina {
|
|
5500
|
-
container;
|
|
5501
5595
|
pixelRatio;
|
|
5502
5596
|
reduceFactor;
|
|
5597
|
+
#container;
|
|
5503
5598
|
constructor(container) {
|
|
5504
|
-
this
|
|
5599
|
+
this.#container = container;
|
|
5505
5600
|
this.pixelRatio = defaultRatio;
|
|
5506
5601
|
this.reduceFactor = defaultReduceFactor;
|
|
5507
5602
|
}
|
|
5508
5603
|
init() {
|
|
5509
|
-
const container = this
|
|
5604
|
+
const container = this.#container, options = container.actualOptions;
|
|
5510
5605
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
5511
5606
|
this.reduceFactor = defaultReduceFactor;
|
|
5512
5607
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -5520,7 +5615,6 @@
|
|
|
5520
5615
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
5521
5616
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
5522
5617
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
5523
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
5524
5618
|
const maxDistance = props.maxDistance;
|
|
5525
5619
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
5526
5620
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -5558,73 +5652,73 @@
|
|
|
5558
5652
|
shapeDrawers;
|
|
5559
5653
|
started;
|
|
5560
5654
|
zLayers;
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5655
|
+
#delay;
|
|
5656
|
+
#delayTimeout;
|
|
5657
|
+
#delta = { value: 0, factor: 0 };
|
|
5658
|
+
#dispatchCallback;
|
|
5659
|
+
#drawAnimationFrame;
|
|
5660
|
+
#duration;
|
|
5661
|
+
#eventListeners;
|
|
5662
|
+
#firstStart;
|
|
5663
|
+
#initialSourceOptions;
|
|
5664
|
+
#lastFrameTime;
|
|
5665
|
+
#lifeTime;
|
|
5666
|
+
#onDestroy;
|
|
5667
|
+
#options;
|
|
5668
|
+
#paused;
|
|
5669
|
+
#pluginManager;
|
|
5670
|
+
#smooth;
|
|
5671
|
+
#sourceOptions;
|
|
5578
5672
|
constructor(params) {
|
|
5579
5673
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
5580
|
-
this
|
|
5581
|
-
this
|
|
5582
|
-
this
|
|
5674
|
+
this.#pluginManager = pluginManager;
|
|
5675
|
+
this.#dispatchCallback = dispatchCallback;
|
|
5676
|
+
this.#onDestroy = onDestroy;
|
|
5583
5677
|
this.id = Symbol(id);
|
|
5584
5678
|
this.fpsLimit = 120;
|
|
5585
5679
|
this.hdr = false;
|
|
5586
|
-
this
|
|
5587
|
-
this
|
|
5588
|
-
this
|
|
5589
|
-
this
|
|
5590
|
-
this
|
|
5680
|
+
this.#smooth = false;
|
|
5681
|
+
this.#delay = 0;
|
|
5682
|
+
this.#duration = 0;
|
|
5683
|
+
this.#lifeTime = 0;
|
|
5684
|
+
this.#firstStart = true;
|
|
5591
5685
|
this.started = false;
|
|
5592
5686
|
this.destroyed = false;
|
|
5593
|
-
this
|
|
5594
|
-
this
|
|
5687
|
+
this.#paused = true;
|
|
5688
|
+
this.#lastFrameTime = 0;
|
|
5595
5689
|
this.zLayers = 100;
|
|
5596
5690
|
this.pageHidden = false;
|
|
5597
|
-
this
|
|
5598
|
-
this
|
|
5691
|
+
this.#sourceOptions = sourceOptions;
|
|
5692
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5599
5693
|
this.effectDrawers = new Map();
|
|
5600
5694
|
this.shapeDrawers = new Map();
|
|
5601
5695
|
this.particleUpdaters = [];
|
|
5602
5696
|
this.retina = new Retina(this);
|
|
5603
|
-
this.canvas = new CanvasManager(this
|
|
5604
|
-
this.particles = new ParticlesManager(this
|
|
5697
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
5698
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
5605
5699
|
this.plugins = [];
|
|
5606
5700
|
this.particleDestroyedPlugins = [];
|
|
5607
5701
|
this.particleCreatedPlugins = [];
|
|
5608
5702
|
this.particlePositionPlugins = [];
|
|
5609
|
-
this
|
|
5610
|
-
this.actualOptions = loadContainerOptions(this
|
|
5611
|
-
this
|
|
5703
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
5704
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
5705
|
+
this.#eventListeners = new EventListeners(this);
|
|
5612
5706
|
this.dispatchEvent(EventType.containerBuilt);
|
|
5613
5707
|
}
|
|
5614
5708
|
get animationStatus() {
|
|
5615
|
-
return !this
|
|
5709
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
5616
5710
|
}
|
|
5617
5711
|
get options() {
|
|
5618
|
-
return this
|
|
5712
|
+
return this.#options;
|
|
5619
5713
|
}
|
|
5620
5714
|
get sourceOptions() {
|
|
5621
|
-
return this
|
|
5715
|
+
return this.#sourceOptions;
|
|
5622
5716
|
}
|
|
5623
5717
|
addLifeTime(value) {
|
|
5624
|
-
this
|
|
5718
|
+
this.#lifeTime += value;
|
|
5625
5719
|
}
|
|
5626
5720
|
alive() {
|
|
5627
|
-
return !this
|
|
5721
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
5628
5722
|
}
|
|
5629
5723
|
destroy(remove = true) {
|
|
5630
5724
|
if (!guardCheck(this)) {
|
|
@@ -5646,13 +5740,13 @@
|
|
|
5646
5740
|
this.shapeDrawers = new Map();
|
|
5647
5741
|
this.particleUpdaters = [];
|
|
5648
5742
|
this.plugins.length = 0;
|
|
5649
|
-
this.
|
|
5743
|
+
this.#pluginManager.clearPlugins(this);
|
|
5650
5744
|
this.destroyed = true;
|
|
5651
|
-
this
|
|
5745
|
+
this.#onDestroy(remove);
|
|
5652
5746
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
5653
5747
|
}
|
|
5654
5748
|
dispatchEvent(type, data) {
|
|
5655
|
-
this
|
|
5749
|
+
this.#dispatchCallback(type, {
|
|
5656
5750
|
container: this,
|
|
5657
5751
|
data,
|
|
5658
5752
|
});
|
|
@@ -5662,12 +5756,12 @@
|
|
|
5662
5756
|
return;
|
|
5663
5757
|
}
|
|
5664
5758
|
let refreshTime = force;
|
|
5665
|
-
this
|
|
5759
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
5666
5760
|
if (refreshTime) {
|
|
5667
|
-
this
|
|
5761
|
+
this.#lastFrameTime = undefined;
|
|
5668
5762
|
refreshTime = false;
|
|
5669
5763
|
}
|
|
5670
|
-
this
|
|
5764
|
+
this.#nextFrame(timestamp);
|
|
5671
5765
|
});
|
|
5672
5766
|
}
|
|
5673
5767
|
async export(type, options = {}) {
|
|
@@ -5689,7 +5783,7 @@
|
|
|
5689
5783
|
return;
|
|
5690
5784
|
}
|
|
5691
5785
|
const allContainerPlugins = new Map();
|
|
5692
|
-
for (const plugin of this.
|
|
5786
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
5693
5787
|
const containerPlugin = await plugin.getPlugin(this);
|
|
5694
5788
|
if (containerPlugin.preInit) {
|
|
5695
5789
|
await containerPlugin.preInit();
|
|
@@ -5697,8 +5791,8 @@
|
|
|
5697
5791
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
5698
5792
|
}
|
|
5699
5793
|
await this.initDrawersAndUpdaters();
|
|
5700
|
-
this
|
|
5701
|
-
this.actualOptions = loadContainerOptions(this
|
|
5794
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5795
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5702
5796
|
this.plugins.length = 0;
|
|
5703
5797
|
this.particleDestroyedPlugins.length = 0;
|
|
5704
5798
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -5725,11 +5819,11 @@
|
|
|
5725
5819
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
5726
5820
|
this.hdr = hdr;
|
|
5727
5821
|
this.zLayers = zLayers;
|
|
5728
|
-
this
|
|
5729
|
-
this
|
|
5730
|
-
this
|
|
5822
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
5823
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
5824
|
+
this.#lifeTime = 0;
|
|
5731
5825
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
5732
|
-
this
|
|
5826
|
+
this.#smooth = smooth;
|
|
5733
5827
|
for (const plugin of this.plugins) {
|
|
5734
5828
|
await plugin.init?.();
|
|
5735
5829
|
}
|
|
@@ -5742,7 +5836,7 @@
|
|
|
5742
5836
|
this.dispatchEvent(EventType.particlesSetup);
|
|
5743
5837
|
}
|
|
5744
5838
|
async initDrawersAndUpdaters() {
|
|
5745
|
-
const pluginManager = this
|
|
5839
|
+
const pluginManager = this.#pluginManager;
|
|
5746
5840
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
5747
5841
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
5748
5842
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -5751,18 +5845,18 @@
|
|
|
5751
5845
|
if (!guardCheck(this)) {
|
|
5752
5846
|
return;
|
|
5753
5847
|
}
|
|
5754
|
-
if (this
|
|
5755
|
-
cancelAnimation(this
|
|
5756
|
-
|
|
5848
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
5849
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
5850
|
+
this.#drawAnimationFrame = undefined;
|
|
5757
5851
|
}
|
|
5758
|
-
if (this
|
|
5852
|
+
if (this.#paused) {
|
|
5759
5853
|
return;
|
|
5760
5854
|
}
|
|
5761
5855
|
for (const plugin of this.plugins) {
|
|
5762
5856
|
plugin.pause?.();
|
|
5763
5857
|
}
|
|
5764
5858
|
if (!this.pageHidden) {
|
|
5765
|
-
this
|
|
5859
|
+
this.#paused = true;
|
|
5766
5860
|
}
|
|
5767
5861
|
this.dispatchEvent(EventType.containerPaused);
|
|
5768
5862
|
}
|
|
@@ -5770,13 +5864,13 @@
|
|
|
5770
5864
|
if (!guardCheck(this)) {
|
|
5771
5865
|
return;
|
|
5772
5866
|
}
|
|
5773
|
-
const needsUpdate = this
|
|
5774
|
-
if (this
|
|
5775
|
-
this
|
|
5867
|
+
const needsUpdate = this.#paused || force;
|
|
5868
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
5869
|
+
this.#firstStart = false;
|
|
5776
5870
|
return;
|
|
5777
5871
|
}
|
|
5778
|
-
if (this
|
|
5779
|
-
this
|
|
5872
|
+
if (this.#paused) {
|
|
5873
|
+
this.#paused = false;
|
|
5780
5874
|
}
|
|
5781
5875
|
if (needsUpdate) {
|
|
5782
5876
|
for (const plugin of this.plugins) {
|
|
@@ -5799,10 +5893,10 @@
|
|
|
5799
5893
|
if (!guardCheck(this)) {
|
|
5800
5894
|
return;
|
|
5801
5895
|
}
|
|
5802
|
-
this
|
|
5803
|
-
this
|
|
5804
|
-
this
|
|
5805
|
-
this.actualOptions = loadContainerOptions(this
|
|
5896
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5897
|
+
this.#sourceOptions = sourceOptions;
|
|
5898
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5899
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5806
5900
|
return this.refresh();
|
|
5807
5901
|
}
|
|
5808
5902
|
async start() {
|
|
@@ -5813,7 +5907,7 @@
|
|
|
5813
5907
|
this.started = true;
|
|
5814
5908
|
await new Promise(resolve => {
|
|
5815
5909
|
const start = async () => {
|
|
5816
|
-
this.
|
|
5910
|
+
this.#eventListeners.addListeners();
|
|
5817
5911
|
for (const plugin of this.plugins) {
|
|
5818
5912
|
await plugin.start?.();
|
|
5819
5913
|
}
|
|
@@ -5821,20 +5915,20 @@
|
|
|
5821
5915
|
this.play();
|
|
5822
5916
|
resolve();
|
|
5823
5917
|
};
|
|
5824
|
-
this
|
|
5918
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
5825
5919
|
});
|
|
5826
5920
|
}
|
|
5827
5921
|
stop() {
|
|
5828
5922
|
if (!guardCheck(this) || !this.started) {
|
|
5829
5923
|
return;
|
|
5830
5924
|
}
|
|
5831
|
-
if (this
|
|
5832
|
-
clearTimeout(this
|
|
5833
|
-
|
|
5925
|
+
if (this.#delayTimeout) {
|
|
5926
|
+
clearTimeout(this.#delayTimeout);
|
|
5927
|
+
this.#delayTimeout = undefined;
|
|
5834
5928
|
}
|
|
5835
|
-
this
|
|
5929
|
+
this.#firstStart = true;
|
|
5836
5930
|
this.started = false;
|
|
5837
|
-
this.
|
|
5931
|
+
this.#eventListeners.removeListeners();
|
|
5838
5932
|
this.pause();
|
|
5839
5933
|
this.particles.clear();
|
|
5840
5934
|
this.canvas.stop();
|
|
@@ -5844,7 +5938,7 @@
|
|
|
5844
5938
|
this.particleCreatedPlugins.length = 0;
|
|
5845
5939
|
this.particleDestroyedPlugins.length = 0;
|
|
5846
5940
|
this.particlePositionPlugins.length = 0;
|
|
5847
|
-
this
|
|
5941
|
+
this.#sourceOptions = this.#options;
|
|
5848
5942
|
this.dispatchEvent(EventType.containerStopped);
|
|
5849
5943
|
}
|
|
5850
5944
|
updateActualOptions() {
|
|
@@ -5856,23 +5950,23 @@
|
|
|
5856
5950
|
}
|
|
5857
5951
|
return refresh;
|
|
5858
5952
|
}
|
|
5859
|
-
|
|
5953
|
+
#nextFrame = (timestamp) => {
|
|
5860
5954
|
try {
|
|
5861
|
-
if (!this
|
|
5862
|
-
this
|
|
5863
|
-
timestamp < this
|
|
5955
|
+
if (!this.#smooth &&
|
|
5956
|
+
this.#lastFrameTime !== undefined &&
|
|
5957
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
5864
5958
|
this.draw(false);
|
|
5865
5959
|
return;
|
|
5866
5960
|
}
|
|
5867
|
-
this
|
|
5868
|
-
updateDelta(this
|
|
5869
|
-
this.addLifeTime(this.
|
|
5870
|
-
this
|
|
5871
|
-
if (this.
|
|
5961
|
+
this.#lastFrameTime ??= timestamp;
|
|
5962
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
5963
|
+
this.addLifeTime(this.#delta.value);
|
|
5964
|
+
this.#lastFrameTime = timestamp;
|
|
5965
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
5872
5966
|
this.draw(false);
|
|
5873
5967
|
return;
|
|
5874
5968
|
}
|
|
5875
|
-
this.canvas.render.drawParticles(this
|
|
5969
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
5876
5970
|
if (!this.alive()) {
|
|
5877
5971
|
this.destroy();
|
|
5878
5972
|
return;
|
|
@@ -5893,10 +5987,10 @@
|
|
|
5893
5987
|
});
|
|
5894
5988
|
|
|
5895
5989
|
class BlendPluginInstance {
|
|
5896
|
-
|
|
5897
|
-
|
|
5990
|
+
#container;
|
|
5991
|
+
#defaultCompositeValue;
|
|
5898
5992
|
constructor(container) {
|
|
5899
|
-
this
|
|
5993
|
+
this.#container = container;
|
|
5900
5994
|
}
|
|
5901
5995
|
drawParticleCleanup(context, particle) {
|
|
5902
5996
|
if (!particle.options.blend?.enable) {
|
|
@@ -5913,14 +6007,14 @@
|
|
|
5913
6007
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
5914
6008
|
}
|
|
5915
6009
|
drawSettingsCleanup(context) {
|
|
5916
|
-
if (!this
|
|
6010
|
+
if (!this.#defaultCompositeValue) {
|
|
5917
6011
|
return;
|
|
5918
6012
|
}
|
|
5919
|
-
context.globalCompositeOperation = this
|
|
6013
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
5920
6014
|
}
|
|
5921
6015
|
drawSettingsSetup(context) {
|
|
5922
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
5923
|
-
this
|
|
6016
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6017
|
+
this.#defaultCompositeValue = previousComposite;
|
|
5924
6018
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
5925
6019
|
}
|
|
5926
6020
|
}
|
|
@@ -6063,11 +6157,11 @@
|
|
|
6063
6157
|
class MovePluginInstance {
|
|
6064
6158
|
availablePathGenerators;
|
|
6065
6159
|
pathGenerators;
|
|
6066
|
-
|
|
6067
|
-
|
|
6160
|
+
#container;
|
|
6161
|
+
#pluginManager;
|
|
6068
6162
|
constructor(pluginManager, container) {
|
|
6069
|
-
this
|
|
6070
|
-
this
|
|
6163
|
+
this.#pluginManager = pluginManager;
|
|
6164
|
+
this.#container = container;
|
|
6071
6165
|
this.availablePathGenerators = new Map();
|
|
6072
6166
|
this.pathGenerators = new Map();
|
|
6073
6167
|
}
|
|
@@ -6098,7 +6192,7 @@
|
|
|
6098
6192
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6099
6193
|
inverse: gravityOptions.inverse,
|
|
6100
6194
|
};
|
|
6101
|
-
initSpin(this
|
|
6195
|
+
initSpin(this.#container, particle);
|
|
6102
6196
|
}
|
|
6103
6197
|
particleDestroyed(particle) {
|
|
6104
6198
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6109,7 +6203,7 @@
|
|
|
6109
6203
|
if (!moveOptions.enable) {
|
|
6110
6204
|
return;
|
|
6111
6205
|
}
|
|
6112
|
-
const container = this
|
|
6206
|
+
const container = this.#container, slowFactor = getProximitySpeedFactor(particle), reduceFactor = container.retina.reduceFactor, baseSpeed = particle.retina.moveSpeed, moveDrift = particle.retina.moveDrift, maxSize = particle.size.max, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor, deltaFactor = delta.factor || defaultDeltaFactor, moveSpeed = baseSpeed * sizeFactor * slowFactor * deltaFactor * half, maxSpeed = particle.retina.maxSpeed;
|
|
6113
6207
|
if (moveOptions.spin.enable) {
|
|
6114
6208
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6115
6209
|
}
|
|
@@ -6119,18 +6213,18 @@
|
|
|
6119
6213
|
applyDistance(particle);
|
|
6120
6214
|
}
|
|
6121
6215
|
preInit() {
|
|
6122
|
-
return this
|
|
6216
|
+
return this.#init();
|
|
6123
6217
|
}
|
|
6124
6218
|
redrawInit() {
|
|
6125
|
-
return this
|
|
6219
|
+
return this.#init();
|
|
6126
6220
|
}
|
|
6127
6221
|
update() {
|
|
6128
6222
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6129
6223
|
pathGenerator.update();
|
|
6130
6224
|
}
|
|
6131
6225
|
}
|
|
6132
|
-
async
|
|
6133
|
-
const availablePathGenerators = await this.
|
|
6226
|
+
async #init() {
|
|
6227
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6134
6228
|
if (!availablePathGenerators) {
|
|
6135
6229
|
return;
|
|
6136
6230
|
}
|