@tsparticles/preset-ambient 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
|
-
(particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3590
|
-
if (!sizeAnimation.sync) {
|
|
3591
|
-
particle.size.velocity *= getRandom();
|
|
3592
|
-
}
|
|
3584
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3585
|
+
if (!sizeOptions) {
|
|
3586
|
+
return;
|
|
3593
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;
|
|
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),
|
|
@@ -3761,58 +3778,58 @@
|
|
|
3761
3778
|
}
|
|
3762
3779
|
}
|
|
3763
3780
|
class RenderManager {
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3781
|
+
#canvasClearPlugins;
|
|
3782
|
+
#canvasManager;
|
|
3783
|
+
#canvasPaintPlugins;
|
|
3784
|
+
#clearDrawPlugins;
|
|
3785
|
+
#colorPlugins;
|
|
3786
|
+
#container;
|
|
3787
|
+
#context;
|
|
3788
|
+
#contextSettings;
|
|
3789
|
+
#drawParticlePlugins;
|
|
3790
|
+
#drawParticlesCleanupPlugins;
|
|
3791
|
+
#drawParticlesSetupPlugins;
|
|
3792
|
+
#drawPlugins;
|
|
3793
|
+
#drawSettingsCleanupPlugins;
|
|
3794
|
+
#drawSettingsSetupPlugins;
|
|
3795
|
+
#pluginManager;
|
|
3796
|
+
#postDrawUpdaters;
|
|
3797
|
+
#preDrawUpdaters;
|
|
3798
|
+
#reusableColorStyles = {};
|
|
3799
|
+
#reusablePluginColors = [undefined, undefined];
|
|
3800
|
+
#reusableTransform = {};
|
|
3784
3801
|
constructor(pluginManager, container, canvasManager) {
|
|
3785
|
-
this
|
|
3786
|
-
this
|
|
3787
|
-
this
|
|
3788
|
-
this
|
|
3789
|
-
this
|
|
3790
|
-
this
|
|
3791
|
-
this
|
|
3792
|
-
this
|
|
3793
|
-
this
|
|
3794
|
-
this
|
|
3795
|
-
this
|
|
3796
|
-
this
|
|
3797
|
-
this
|
|
3798
|
-
this
|
|
3799
|
-
this
|
|
3800
|
-
this
|
|
3802
|
+
this.#pluginManager = pluginManager;
|
|
3803
|
+
this.#container = container;
|
|
3804
|
+
this.#canvasManager = canvasManager;
|
|
3805
|
+
this.#context = null;
|
|
3806
|
+
this.#preDrawUpdaters = [];
|
|
3807
|
+
this.#postDrawUpdaters = [];
|
|
3808
|
+
this.#colorPlugins = [];
|
|
3809
|
+
this.#canvasClearPlugins = [];
|
|
3810
|
+
this.#canvasPaintPlugins = [];
|
|
3811
|
+
this.#clearDrawPlugins = [];
|
|
3812
|
+
this.#drawParticlePlugins = [];
|
|
3813
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3814
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3815
|
+
this.#drawPlugins = [];
|
|
3816
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3817
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3801
3818
|
}
|
|
3802
3819
|
get settings() {
|
|
3803
|
-
return this
|
|
3820
|
+
return this.#contextSettings;
|
|
3804
3821
|
}
|
|
3805
3822
|
canvasClear() {
|
|
3806
|
-
if (!this.
|
|
3823
|
+
if (!this.#container.actualOptions.clear) {
|
|
3807
3824
|
return;
|
|
3808
3825
|
}
|
|
3809
3826
|
this.draw(ctx => {
|
|
3810
|
-
clear(ctx, this.
|
|
3827
|
+
clear(ctx, this.#canvasManager.size);
|
|
3811
3828
|
});
|
|
3812
3829
|
}
|
|
3813
3830
|
clear() {
|
|
3814
3831
|
let pluginHandled = false;
|
|
3815
|
-
for (const plugin of this
|
|
3832
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
3816
3833
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
3817
3834
|
if (pluginHandled) {
|
|
3818
3835
|
break;
|
|
@@ -3825,21 +3842,21 @@
|
|
|
3825
3842
|
}
|
|
3826
3843
|
destroy() {
|
|
3827
3844
|
this.stop();
|
|
3828
|
-
this
|
|
3829
|
-
this
|
|
3830
|
-
this
|
|
3831
|
-
this
|
|
3832
|
-
this
|
|
3833
|
-
this
|
|
3834
|
-
this
|
|
3835
|
-
this
|
|
3836
|
-
this
|
|
3837
|
-
this
|
|
3838
|
-
this
|
|
3839
|
-
this
|
|
3845
|
+
this.#preDrawUpdaters = [];
|
|
3846
|
+
this.#postDrawUpdaters = [];
|
|
3847
|
+
this.#colorPlugins = [];
|
|
3848
|
+
this.#canvasClearPlugins = [];
|
|
3849
|
+
this.#canvasPaintPlugins = [];
|
|
3850
|
+
this.#clearDrawPlugins = [];
|
|
3851
|
+
this.#drawParticlePlugins = [];
|
|
3852
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3853
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3854
|
+
this.#drawPlugins = [];
|
|
3855
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3856
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3840
3857
|
}
|
|
3841
3858
|
draw(cb) {
|
|
3842
|
-
const ctx = this
|
|
3859
|
+
const ctx = this.#context;
|
|
3843
3860
|
if (!ctx) {
|
|
3844
3861
|
return;
|
|
3845
3862
|
}
|
|
@@ -3854,21 +3871,21 @@
|
|
|
3854
3871
|
return;
|
|
3855
3872
|
}
|
|
3856
3873
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
3857
|
-
let [fColor, sColor] = this
|
|
3874
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
3858
3875
|
fColor ??= pfColor;
|
|
3859
3876
|
sColor ??= psColor;
|
|
3860
3877
|
if (!fColor && !sColor) {
|
|
3861
3878
|
return;
|
|
3862
3879
|
}
|
|
3863
|
-
const container = this
|
|
3880
|
+
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;
|
|
3864
3881
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
3865
3882
|
colorStyles.fill = fill;
|
|
3866
3883
|
colorStyles.stroke = stroke;
|
|
3867
3884
|
this.draw((context) => {
|
|
3868
|
-
for (const plugin of this
|
|
3885
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
3869
3886
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
3870
3887
|
}
|
|
3871
|
-
this
|
|
3888
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
3872
3889
|
drawParticle({
|
|
3873
3890
|
container,
|
|
3874
3891
|
context,
|
|
@@ -3879,35 +3896,35 @@
|
|
|
3879
3896
|
opacity: opacity,
|
|
3880
3897
|
transform,
|
|
3881
3898
|
});
|
|
3882
|
-
this
|
|
3883
|
-
for (const plugin of this
|
|
3899
|
+
this.#applyPostDrawUpdaters(particle);
|
|
3900
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
3884
3901
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
3885
3902
|
}
|
|
3886
3903
|
});
|
|
3887
3904
|
}
|
|
3888
3905
|
drawParticlePlugins(particle, delta) {
|
|
3889
3906
|
this.draw(ctx => {
|
|
3890
|
-
for (const plugin of this
|
|
3907
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
3891
3908
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
3892
3909
|
}
|
|
3893
3910
|
});
|
|
3894
3911
|
}
|
|
3895
3912
|
drawParticles(delta) {
|
|
3896
|
-
const { particles } = this
|
|
3913
|
+
const { particles } = this.#container;
|
|
3897
3914
|
this.clear();
|
|
3898
3915
|
particles.update(delta);
|
|
3899
3916
|
this.draw(ctx => {
|
|
3900
|
-
for (const plugin of this
|
|
3917
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
3901
3918
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
3902
3919
|
}
|
|
3903
|
-
for (const plugin of this
|
|
3920
|
+
for (const plugin of this.#drawPlugins) {
|
|
3904
3921
|
plugin.draw?.(ctx, delta);
|
|
3905
3922
|
}
|
|
3906
3923
|
particles.drawParticles(delta);
|
|
3907
|
-
for (const plugin of this
|
|
3924
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
3908
3925
|
plugin.clearDraw?.(ctx, delta);
|
|
3909
3926
|
}
|
|
3910
|
-
for (const plugin of this
|
|
3927
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
3911
3928
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
3912
3929
|
}
|
|
3913
3930
|
});
|
|
@@ -3918,64 +3935,64 @@
|
|
|
3918
3935
|
this.paint();
|
|
3919
3936
|
}
|
|
3920
3937
|
initPlugins() {
|
|
3921
|
-
this
|
|
3922
|
-
this
|
|
3923
|
-
this
|
|
3924
|
-
this
|
|
3925
|
-
this
|
|
3926
|
-
this
|
|
3927
|
-
this
|
|
3928
|
-
this
|
|
3929
|
-
this
|
|
3930
|
-
this
|
|
3931
|
-
for (const plugin of this.
|
|
3938
|
+
this.#colorPlugins = [];
|
|
3939
|
+
this.#canvasClearPlugins = [];
|
|
3940
|
+
this.#canvasPaintPlugins = [];
|
|
3941
|
+
this.#clearDrawPlugins = [];
|
|
3942
|
+
this.#drawParticlePlugins = [];
|
|
3943
|
+
this.#drawParticlesSetupPlugins = [];
|
|
3944
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
3945
|
+
this.#drawPlugins = [];
|
|
3946
|
+
this.#drawSettingsSetupPlugins = [];
|
|
3947
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
3948
|
+
for (const plugin of this.#container.plugins) {
|
|
3932
3949
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
3933
|
-
this.
|
|
3950
|
+
this.#colorPlugins.push(plugin);
|
|
3934
3951
|
}
|
|
3935
3952
|
if (plugin.canvasClear) {
|
|
3936
|
-
this.
|
|
3953
|
+
this.#canvasClearPlugins.push(plugin);
|
|
3937
3954
|
}
|
|
3938
3955
|
if (plugin.canvasPaint) {
|
|
3939
|
-
this.
|
|
3956
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
3940
3957
|
}
|
|
3941
3958
|
if (plugin.drawParticle) {
|
|
3942
|
-
this.
|
|
3959
|
+
this.#drawParticlePlugins.push(plugin);
|
|
3943
3960
|
}
|
|
3944
3961
|
if (plugin.drawParticleSetup) {
|
|
3945
|
-
this.
|
|
3962
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
3946
3963
|
}
|
|
3947
3964
|
if (plugin.drawParticleCleanup) {
|
|
3948
|
-
this.
|
|
3965
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
3949
3966
|
}
|
|
3950
3967
|
if (plugin.draw) {
|
|
3951
|
-
this.
|
|
3968
|
+
this.#drawPlugins.push(plugin);
|
|
3952
3969
|
}
|
|
3953
3970
|
if (plugin.drawSettingsSetup) {
|
|
3954
|
-
this.
|
|
3971
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
3955
3972
|
}
|
|
3956
3973
|
if (plugin.drawSettingsCleanup) {
|
|
3957
|
-
this.
|
|
3974
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
3958
3975
|
}
|
|
3959
3976
|
if (plugin.clearDraw) {
|
|
3960
|
-
this.
|
|
3977
|
+
this.#clearDrawPlugins.push(plugin);
|
|
3961
3978
|
}
|
|
3962
3979
|
}
|
|
3963
3980
|
}
|
|
3964
3981
|
initUpdaters() {
|
|
3965
|
-
this
|
|
3966
|
-
this
|
|
3967
|
-
for (const updater of this.
|
|
3982
|
+
this.#preDrawUpdaters = [];
|
|
3983
|
+
this.#postDrawUpdaters = [];
|
|
3984
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
3968
3985
|
if (updater.afterDraw) {
|
|
3969
|
-
this.
|
|
3986
|
+
this.#postDrawUpdaters.push(updater);
|
|
3970
3987
|
}
|
|
3971
3988
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
3972
|
-
this.
|
|
3989
|
+
this.#preDrawUpdaters.push(updater);
|
|
3973
3990
|
}
|
|
3974
3991
|
}
|
|
3975
3992
|
}
|
|
3976
3993
|
paint() {
|
|
3977
3994
|
let handled = false;
|
|
3978
|
-
for (const plugin of this
|
|
3995
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
3979
3996
|
handled = plugin.canvasPaint?.() ?? false;
|
|
3980
3997
|
if (handled) {
|
|
3981
3998
|
break;
|
|
@@ -3988,35 +4005,35 @@
|
|
|
3988
4005
|
}
|
|
3989
4006
|
paintBase(baseColor) {
|
|
3990
4007
|
this.draw(ctx => {
|
|
3991
|
-
paintBase(ctx, this.
|
|
4008
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
3992
4009
|
});
|
|
3993
4010
|
}
|
|
3994
4011
|
paintImage(image, opacity) {
|
|
3995
4012
|
this.draw(ctx => {
|
|
3996
|
-
paintImage(ctx, this.
|
|
4013
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
3997
4014
|
});
|
|
3998
4015
|
}
|
|
3999
4016
|
setContext(context) {
|
|
4000
|
-
this
|
|
4001
|
-
if (this
|
|
4002
|
-
this.
|
|
4017
|
+
this.#context = context;
|
|
4018
|
+
if (this.#context) {
|
|
4019
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4003
4020
|
}
|
|
4004
4021
|
}
|
|
4005
4022
|
setContextSettings(settings) {
|
|
4006
|
-
this
|
|
4023
|
+
this.#contextSettings = settings;
|
|
4007
4024
|
}
|
|
4008
4025
|
stop() {
|
|
4009
4026
|
this.draw(ctx => {
|
|
4010
|
-
clear(ctx, this.
|
|
4027
|
+
clear(ctx, this.#canvasManager.size);
|
|
4011
4028
|
});
|
|
4012
4029
|
}
|
|
4013
|
-
|
|
4014
|
-
for (const updater of this
|
|
4030
|
+
#applyPostDrawUpdaters = particle => {
|
|
4031
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4015
4032
|
updater.afterDraw?.(particle);
|
|
4016
4033
|
}
|
|
4017
4034
|
};
|
|
4018
|
-
|
|
4019
|
-
for (const updater of this
|
|
4035
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4036
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4020
4037
|
if (updater.getColorStyles) {
|
|
4021
4038
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4022
4039
|
if (fill) {
|
|
@@ -4035,22 +4052,22 @@
|
|
|
4035
4052
|
updater.beforeDraw?.(particle);
|
|
4036
4053
|
}
|
|
4037
4054
|
};
|
|
4038
|
-
|
|
4055
|
+
#getPluginParticleColors = particle => {
|
|
4039
4056
|
let fColor, sColor;
|
|
4040
|
-
for (const plugin of this
|
|
4057
|
+
for (const plugin of this.#colorPlugins) {
|
|
4041
4058
|
if (!fColor && plugin.particleFillColor) {
|
|
4042
|
-
fColor = rangeColorToHsl(this
|
|
4059
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4043
4060
|
}
|
|
4044
4061
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4045
|
-
sColor = rangeColorToHsl(this
|
|
4062
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4046
4063
|
}
|
|
4047
4064
|
if (fColor && sColor) {
|
|
4048
4065
|
break;
|
|
4049
4066
|
}
|
|
4050
4067
|
}
|
|
4051
|
-
this
|
|
4052
|
-
this
|
|
4053
|
-
return this
|
|
4068
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4069
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4070
|
+
return this.#reusablePluginColors;
|
|
4054
4071
|
};
|
|
4055
4072
|
}
|
|
4056
4073
|
|
|
@@ -4108,53 +4125,53 @@
|
|
|
4108
4125
|
renderCanvas;
|
|
4109
4126
|
size;
|
|
4110
4127
|
zoom = defaultZoom;
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4128
|
+
#container;
|
|
4129
|
+
#generated;
|
|
4130
|
+
#mutationObserver;
|
|
4131
|
+
#originalStyle;
|
|
4132
|
+
#pluginManager;
|
|
4133
|
+
#pointerEvents;
|
|
4134
|
+
#resizePlugins;
|
|
4135
|
+
#standardSize;
|
|
4136
|
+
#zoomCenter;
|
|
4120
4137
|
constructor(pluginManager, container) {
|
|
4121
|
-
this
|
|
4122
|
-
this
|
|
4138
|
+
this.#pluginManager = pluginManager;
|
|
4139
|
+
this.#container = container;
|
|
4123
4140
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4124
|
-
this
|
|
4141
|
+
this.#standardSize = {
|
|
4125
4142
|
height: 0,
|
|
4126
4143
|
width: 0,
|
|
4127
4144
|
};
|
|
4128
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4145
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4129
4146
|
this.size = {
|
|
4130
4147
|
height: stdSize.height * pxRatio,
|
|
4131
4148
|
width: stdSize.width * pxRatio,
|
|
4132
4149
|
};
|
|
4133
|
-
this
|
|
4134
|
-
this
|
|
4135
|
-
this
|
|
4150
|
+
this.#generated = false;
|
|
4151
|
+
this.#resizePlugins = [];
|
|
4152
|
+
this.#pointerEvents = "none";
|
|
4136
4153
|
}
|
|
4137
|
-
get
|
|
4138
|
-
return this.
|
|
4154
|
+
get #fullScreen() {
|
|
4155
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4139
4156
|
}
|
|
4140
4157
|
destroy() {
|
|
4141
4158
|
this.stop();
|
|
4142
|
-
if (this
|
|
4159
|
+
if (this.#generated) {
|
|
4143
4160
|
const element = this.domElement;
|
|
4144
4161
|
element?.remove();
|
|
4145
4162
|
this.domElement = undefined;
|
|
4146
4163
|
this.renderCanvas = undefined;
|
|
4147
4164
|
}
|
|
4148
4165
|
else {
|
|
4149
|
-
this
|
|
4166
|
+
this.#resetOriginalStyle();
|
|
4150
4167
|
}
|
|
4151
4168
|
this.render.destroy();
|
|
4152
|
-
this
|
|
4169
|
+
this.#resizePlugins = [];
|
|
4153
4170
|
}
|
|
4154
4171
|
getZoomCenter() {
|
|
4155
|
-
const pxRatio = this.
|
|
4156
|
-
if (this
|
|
4157
|
-
return this
|
|
4172
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4173
|
+
if (this.#zoomCenter) {
|
|
4174
|
+
return this.#zoomCenter;
|
|
4158
4175
|
}
|
|
4159
4176
|
return {
|
|
4160
4177
|
x: (width * half) / pxRatio,
|
|
@@ -4162,20 +4179,20 @@
|
|
|
4162
4179
|
};
|
|
4163
4180
|
}
|
|
4164
4181
|
init() {
|
|
4165
|
-
this
|
|
4182
|
+
this.#safeMutationObserver(obs => {
|
|
4166
4183
|
obs.disconnect();
|
|
4167
4184
|
});
|
|
4168
|
-
this
|
|
4185
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4169
4186
|
for (const record of records) {
|
|
4170
4187
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4171
|
-
this
|
|
4188
|
+
this.#repairStyle();
|
|
4172
4189
|
}
|
|
4173
4190
|
}
|
|
4174
4191
|
});
|
|
4175
4192
|
this.resize();
|
|
4176
|
-
this
|
|
4193
|
+
this.#initStyle();
|
|
4177
4194
|
this.initBackground();
|
|
4178
|
-
this
|
|
4195
|
+
this.#safeMutationObserver(obs => {
|
|
4179
4196
|
const element = this.domElement;
|
|
4180
4197
|
if (!element || !(element instanceof Node)) {
|
|
4181
4198
|
return;
|
|
@@ -4186,13 +4203,13 @@
|
|
|
4186
4203
|
this.render.init();
|
|
4187
4204
|
}
|
|
4188
4205
|
initBackground() {
|
|
4189
|
-
const
|
|
4206
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4190
4207
|
if (!element) {
|
|
4191
4208
|
return;
|
|
4192
4209
|
}
|
|
4193
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4210
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4194
4211
|
if (color) {
|
|
4195
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4212
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4196
4213
|
}
|
|
4197
4214
|
else {
|
|
4198
4215
|
elementStyle.backgroundColor = "";
|
|
@@ -4203,27 +4220,27 @@
|
|
|
4203
4220
|
elementStyle.backgroundSize = background.size || "";
|
|
4204
4221
|
}
|
|
4205
4222
|
initPlugins() {
|
|
4206
|
-
this
|
|
4207
|
-
for (const plugin of this.
|
|
4223
|
+
this.#resizePlugins = [];
|
|
4224
|
+
for (const plugin of this.#container.plugins) {
|
|
4208
4225
|
if (plugin.resize) {
|
|
4209
|
-
this.
|
|
4226
|
+
this.#resizePlugins.push(plugin);
|
|
4210
4227
|
}
|
|
4211
4228
|
}
|
|
4212
4229
|
}
|
|
4213
4230
|
loadCanvas(canvas) {
|
|
4214
|
-
if (this
|
|
4231
|
+
if (this.#generated && this.domElement) {
|
|
4215
4232
|
this.domElement.remove();
|
|
4216
4233
|
}
|
|
4217
|
-
const container = this
|
|
4234
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4218
4235
|
this.domElement = domCanvas;
|
|
4219
|
-
this
|
|
4236
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4220
4237
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4221
4238
|
const domElement = this.domElement;
|
|
4222
4239
|
if (domElement) {
|
|
4223
4240
|
domElement.ariaHidden = "true";
|
|
4224
|
-
this
|
|
4241
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4225
4242
|
}
|
|
4226
|
-
const standardSize = this
|
|
4243
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4227
4244
|
if (domElement) {
|
|
4228
4245
|
standardSize.height = domElement.offsetHeight;
|
|
4229
4246
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4232,7 +4249,7 @@
|
|
|
4232
4249
|
standardSize.height = renderCanvas.height;
|
|
4233
4250
|
standardSize.width = renderCanvas.width;
|
|
4234
4251
|
}
|
|
4235
|
-
const pxRatio = this.
|
|
4252
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4236
4253
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4237
4254
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4238
4255
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4243,12 +4260,12 @@
|
|
|
4243
4260
|
willReadFrequently: false,
|
|
4244
4261
|
});
|
|
4245
4262
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4246
|
-
this
|
|
4263
|
+
this.#safeMutationObserver(obs => {
|
|
4247
4264
|
obs.disconnect();
|
|
4248
4265
|
});
|
|
4249
4266
|
container.retina.init();
|
|
4250
4267
|
this.initBackground();
|
|
4251
|
-
this
|
|
4268
|
+
this.#safeMutationObserver(obs => {
|
|
4252
4269
|
const element = this.domElement;
|
|
4253
4270
|
if (!element || !(element instanceof Node)) {
|
|
4254
4271
|
return;
|
|
@@ -4261,11 +4278,11 @@
|
|
|
4261
4278
|
if (!element) {
|
|
4262
4279
|
return false;
|
|
4263
4280
|
}
|
|
4264
|
-
const container = this
|
|
4281
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4265
4282
|
if (renderCanvas === undefined) {
|
|
4266
4283
|
return false;
|
|
4267
4284
|
}
|
|
4268
|
-
const currentSize = container.canvas
|
|
4285
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4269
4286
|
width: element.offsetWidth,
|
|
4270
4287
|
height: element.offsetHeight,
|
|
4271
4288
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4284,7 +4301,7 @@
|
|
|
4284
4301
|
const canvasSize = this.size;
|
|
4285
4302
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4286
4303
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4287
|
-
if (this.
|
|
4304
|
+
if (this.#container.started) {
|
|
4288
4305
|
container.particles.setResizeFactor({
|
|
4289
4306
|
width: currentSize.width / oldSize.width,
|
|
4290
4307
|
height: currentSize.height / oldSize.height,
|
|
@@ -4297,46 +4314,46 @@
|
|
|
4297
4314
|
if (!element) {
|
|
4298
4315
|
return;
|
|
4299
4316
|
}
|
|
4300
|
-
this
|
|
4301
|
-
this
|
|
4317
|
+
this.#pointerEvents = type;
|
|
4318
|
+
this.#repairStyle();
|
|
4302
4319
|
}
|
|
4303
4320
|
setZoom(zoomLevel, center) {
|
|
4304
4321
|
this.zoom = zoomLevel;
|
|
4305
|
-
this
|
|
4322
|
+
this.#zoomCenter = center;
|
|
4306
4323
|
}
|
|
4307
4324
|
stop() {
|
|
4308
|
-
this
|
|
4325
|
+
this.#safeMutationObserver(obs => {
|
|
4309
4326
|
obs.disconnect();
|
|
4310
4327
|
});
|
|
4311
|
-
this
|
|
4328
|
+
this.#mutationObserver = undefined;
|
|
4312
4329
|
this.render.stop();
|
|
4313
4330
|
}
|
|
4314
4331
|
async windowResize() {
|
|
4315
4332
|
if (!this.domElement || !this.resize()) {
|
|
4316
4333
|
return;
|
|
4317
4334
|
}
|
|
4318
|
-
const container = this
|
|
4335
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4319
4336
|
container.particles.setDensity();
|
|
4320
|
-
this
|
|
4337
|
+
this.#applyResizePlugins();
|
|
4321
4338
|
if (needsRefresh) {
|
|
4322
4339
|
await container.refresh();
|
|
4323
4340
|
}
|
|
4324
4341
|
}
|
|
4325
|
-
|
|
4326
|
-
for (const plugin of this
|
|
4342
|
+
#applyResizePlugins = () => {
|
|
4343
|
+
for (const plugin of this.#resizePlugins) {
|
|
4327
4344
|
plugin.resize?.();
|
|
4328
4345
|
}
|
|
4329
4346
|
};
|
|
4330
|
-
|
|
4331
|
-
const element = this.domElement, options = this.
|
|
4347
|
+
#initStyle = () => {
|
|
4348
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4332
4349
|
if (!element) {
|
|
4333
4350
|
return;
|
|
4334
4351
|
}
|
|
4335
|
-
if (this
|
|
4336
|
-
this
|
|
4352
|
+
if (this.#fullScreen) {
|
|
4353
|
+
this.#setFullScreenStyle();
|
|
4337
4354
|
}
|
|
4338
4355
|
else {
|
|
4339
|
-
this
|
|
4356
|
+
this.#resetOriginalStyle();
|
|
4340
4357
|
}
|
|
4341
4358
|
for (const key in options.style) {
|
|
4342
4359
|
if (!key || !(key in options.style)) {
|
|
@@ -4349,72 +4366,72 @@
|
|
|
4349
4366
|
element.style.setProperty(key, value, "important");
|
|
4350
4367
|
}
|
|
4351
4368
|
};
|
|
4352
|
-
|
|
4369
|
+
#repairStyle = () => {
|
|
4353
4370
|
const element = this.domElement;
|
|
4354
4371
|
if (!element) {
|
|
4355
4372
|
return;
|
|
4356
4373
|
}
|
|
4357
|
-
this
|
|
4374
|
+
this.#safeMutationObserver(observer => {
|
|
4358
4375
|
observer.disconnect();
|
|
4359
4376
|
});
|
|
4360
|
-
this
|
|
4377
|
+
this.#initStyle();
|
|
4361
4378
|
this.initBackground();
|
|
4362
|
-
const pointerEvents = this
|
|
4379
|
+
const pointerEvents = this.#pointerEvents;
|
|
4363
4380
|
element.style.pointerEvents = pointerEvents;
|
|
4364
4381
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4365
|
-
this
|
|
4382
|
+
this.#safeMutationObserver(observer => {
|
|
4366
4383
|
if (!(element instanceof Node)) {
|
|
4367
4384
|
return;
|
|
4368
4385
|
}
|
|
4369
4386
|
observer.observe(element, { attributes: true });
|
|
4370
4387
|
});
|
|
4371
4388
|
};
|
|
4372
|
-
|
|
4373
|
-
const element = this.domElement, originalStyle = this
|
|
4389
|
+
#resetOriginalStyle = () => {
|
|
4390
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4374
4391
|
if (!element || !originalStyle) {
|
|
4375
4392
|
return;
|
|
4376
4393
|
}
|
|
4377
4394
|
setStyle(element, originalStyle, true);
|
|
4378
4395
|
};
|
|
4379
|
-
|
|
4380
|
-
if (!this
|
|
4396
|
+
#safeMutationObserver = callback => {
|
|
4397
|
+
if (!this.#mutationObserver) {
|
|
4381
4398
|
return;
|
|
4382
4399
|
}
|
|
4383
|
-
callback(this
|
|
4400
|
+
callback(this.#mutationObserver);
|
|
4384
4401
|
};
|
|
4385
|
-
|
|
4402
|
+
#setFullScreenStyle = () => {
|
|
4386
4403
|
const element = this.domElement;
|
|
4387
4404
|
if (!element) {
|
|
4388
4405
|
return;
|
|
4389
4406
|
}
|
|
4390
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4407
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4391
4408
|
};
|
|
4392
4409
|
}
|
|
4393
4410
|
|
|
4394
4411
|
class EventListeners {
|
|
4395
|
-
container;
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4412
|
+
#container;
|
|
4413
|
+
#handlers;
|
|
4414
|
+
#resizeObserver;
|
|
4415
|
+
#resizeTimeout;
|
|
4399
4416
|
constructor(container) {
|
|
4400
|
-
this
|
|
4401
|
-
this
|
|
4417
|
+
this.#container = container;
|
|
4418
|
+
this.#handlers = {
|
|
4402
4419
|
visibilityChange: () => {
|
|
4403
|
-
this
|
|
4420
|
+
this.#handleVisibilityChange();
|
|
4404
4421
|
},
|
|
4405
4422
|
resize: () => {
|
|
4406
|
-
this
|
|
4423
|
+
this.#handleWindowResize();
|
|
4407
4424
|
},
|
|
4408
4425
|
};
|
|
4409
4426
|
}
|
|
4410
4427
|
addListeners() {
|
|
4411
|
-
this
|
|
4428
|
+
this.#manageListeners(true);
|
|
4412
4429
|
}
|
|
4413
4430
|
removeListeners() {
|
|
4414
|
-
this
|
|
4431
|
+
this.#manageListeners(false);
|
|
4415
4432
|
}
|
|
4416
|
-
|
|
4417
|
-
const container = this
|
|
4433
|
+
#handleVisibilityChange = () => {
|
|
4434
|
+
const container = this.#container, options = container.actualOptions;
|
|
4418
4435
|
if (!options.pauseOnBlur) {
|
|
4419
4436
|
return;
|
|
4420
4437
|
}
|
|
@@ -4432,24 +4449,24 @@
|
|
|
4432
4449
|
}
|
|
4433
4450
|
}
|
|
4434
4451
|
};
|
|
4435
|
-
|
|
4436
|
-
if (this
|
|
4437
|
-
clearTimeout(this
|
|
4438
|
-
|
|
4452
|
+
#handleWindowResize = () => {
|
|
4453
|
+
if (this.#resizeTimeout) {
|
|
4454
|
+
clearTimeout(this.#resizeTimeout);
|
|
4455
|
+
this.#resizeTimeout = undefined;
|
|
4439
4456
|
}
|
|
4440
4457
|
const handleResize = async () => {
|
|
4441
|
-
const canvas = this
|
|
4458
|
+
const canvas = this.#container.canvas;
|
|
4442
4459
|
await canvas.windowResize();
|
|
4443
4460
|
};
|
|
4444
|
-
this
|
|
4461
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4445
4462
|
};
|
|
4446
|
-
|
|
4447
|
-
const handlers = this
|
|
4448
|
-
this
|
|
4463
|
+
#manageListeners = add => {
|
|
4464
|
+
const handlers = this.#handlers;
|
|
4465
|
+
this.#manageResize(add);
|
|
4449
4466
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
4450
4467
|
};
|
|
4451
|
-
|
|
4452
|
-
const handlers = this
|
|
4468
|
+
#manageResize = add => {
|
|
4469
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
4453
4470
|
if (!options.resize.enable) {
|
|
4454
4471
|
return;
|
|
4455
4472
|
}
|
|
@@ -4458,22 +4475,22 @@
|
|
|
4458
4475
|
return;
|
|
4459
4476
|
}
|
|
4460
4477
|
const canvasEl = container.canvas.domElement;
|
|
4461
|
-
if (this
|
|
4478
|
+
if (this.#resizeObserver && !add) {
|
|
4462
4479
|
if (canvasEl) {
|
|
4463
|
-
this.
|
|
4480
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
4464
4481
|
}
|
|
4465
|
-
this.
|
|
4466
|
-
|
|
4482
|
+
this.#resizeObserver.disconnect();
|
|
4483
|
+
this.#resizeObserver = undefined;
|
|
4467
4484
|
}
|
|
4468
|
-
else if (!this
|
|
4469
|
-
this
|
|
4485
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4486
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4470
4487
|
const entry = entries.find(e => e.target === canvasEl);
|
|
4471
4488
|
if (!entry) {
|
|
4472
4489
|
return;
|
|
4473
4490
|
}
|
|
4474
|
-
this
|
|
4491
|
+
this.#handleWindowResize();
|
|
4475
4492
|
});
|
|
4476
|
-
this.
|
|
4493
|
+
this.#resizeObserver.observe(canvasEl);
|
|
4477
4494
|
}
|
|
4478
4495
|
};
|
|
4479
4496
|
}
|
|
@@ -4546,24 +4563,24 @@
|
|
|
4546
4563
|
unbreakable;
|
|
4547
4564
|
velocity;
|
|
4548
4565
|
zIndexFactor;
|
|
4549
|
-
|
|
4566
|
+
#cachedOpacityData = {
|
|
4550
4567
|
fillOpacity: defaultOpacity$1,
|
|
4551
4568
|
opacity: defaultOpacity$1,
|
|
4552
4569
|
strokeOpacity: defaultOpacity$1,
|
|
4553
4570
|
};
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4571
|
+
#cachedPosition = Vector3d.origin;
|
|
4572
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
4573
|
+
#cachedTransform = {
|
|
4557
4574
|
a: 1,
|
|
4558
4575
|
b: 0,
|
|
4559
4576
|
c: 0,
|
|
4560
4577
|
d: 1,
|
|
4561
4578
|
};
|
|
4562
|
-
|
|
4563
|
-
|
|
4579
|
+
#container;
|
|
4580
|
+
#pluginManager;
|
|
4564
4581
|
constructor(pluginManager, container) {
|
|
4565
|
-
this
|
|
4566
|
-
this
|
|
4582
|
+
this.#pluginManager = pluginManager;
|
|
4583
|
+
this.#container = container;
|
|
4567
4584
|
}
|
|
4568
4585
|
destroy(override) {
|
|
4569
4586
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -4572,7 +4589,7 @@
|
|
|
4572
4589
|
this.destroyed = true;
|
|
4573
4590
|
this.bubble.inRange = false;
|
|
4574
4591
|
this.slow.inRange = false;
|
|
4575
|
-
const container = this
|
|
4592
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
4576
4593
|
shapeDrawer?.particleDestroy?.(this);
|
|
4577
4594
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
4578
4595
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -4580,12 +4597,12 @@
|
|
|
4580
4597
|
for (const updater of container.particleUpdaters) {
|
|
4581
4598
|
updater.particleDestroyed?.(this, override);
|
|
4582
4599
|
}
|
|
4583
|
-
this.
|
|
4600
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
4584
4601
|
particle: this,
|
|
4585
4602
|
});
|
|
4586
4603
|
}
|
|
4587
4604
|
draw(delta) {
|
|
4588
|
-
const container = this
|
|
4605
|
+
const container = this.#container, render = container.canvas.render;
|
|
4589
4606
|
render.drawParticlePlugins(this, delta);
|
|
4590
4607
|
render.drawParticle(this, delta);
|
|
4591
4608
|
}
|
|
@@ -4593,50 +4610,50 @@
|
|
|
4593
4610
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
4594
4611
|
}
|
|
4595
4612
|
getFillColor() {
|
|
4596
|
-
return this
|
|
4613
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
4597
4614
|
}
|
|
4598
4615
|
getMass() {
|
|
4599
4616
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
4600
4617
|
}
|
|
4601
4618
|
getOpacity() {
|
|
4602
4619
|
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;
|
|
4603
|
-
this.
|
|
4604
|
-
this.
|
|
4605
|
-
this.
|
|
4606
|
-
return this
|
|
4620
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
4621
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
4622
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
4623
|
+
return this.#cachedOpacityData;
|
|
4607
4624
|
}
|
|
4608
4625
|
getPosition() {
|
|
4609
|
-
this.
|
|
4610
|
-
this.
|
|
4611
|
-
this.
|
|
4612
|
-
return this
|
|
4626
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
4627
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
4628
|
+
this.#cachedPosition.z = this.position.z;
|
|
4629
|
+
return this.#cachedPosition;
|
|
4613
4630
|
}
|
|
4614
4631
|
getRadius() {
|
|
4615
4632
|
return this.bubble.radius ?? this.size.value;
|
|
4616
4633
|
}
|
|
4617
4634
|
getRotateData() {
|
|
4618
4635
|
const angle = this.getAngle();
|
|
4619
|
-
this.
|
|
4620
|
-
this.
|
|
4621
|
-
return this
|
|
4636
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
4637
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
4638
|
+
return this.#cachedRotateData;
|
|
4622
4639
|
}
|
|
4623
4640
|
getStrokeColor() {
|
|
4624
|
-
return this
|
|
4641
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
4625
4642
|
}
|
|
4626
4643
|
getTransformData(externalTransform) {
|
|
4627
4644
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
4628
|
-
this.
|
|
4629
|
-
this.
|
|
4645
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
4646
|
+
this.#cachedTransform.b = rotating
|
|
4630
4647
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
4631
4648
|
: (externalTransform.b ?? defaultTransform.b);
|
|
4632
|
-
this.
|
|
4649
|
+
this.#cachedTransform.c = rotating
|
|
4633
4650
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
4634
4651
|
: (externalTransform.c ?? defaultTransform.c);
|
|
4635
|
-
this.
|
|
4636
|
-
return this
|
|
4652
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
4653
|
+
return this.#cachedTransform;
|
|
4637
4654
|
}
|
|
4638
4655
|
init(id, position, overrideOptions, group) {
|
|
4639
|
-
const container = this
|
|
4656
|
+
const container = this.#container;
|
|
4640
4657
|
this.id = id;
|
|
4641
4658
|
this.group = group;
|
|
4642
4659
|
this.justWarped = false;
|
|
@@ -4656,21 +4673,27 @@
|
|
|
4656
4673
|
moveSpeed: 0,
|
|
4657
4674
|
sizeAnimationSpeed: 0,
|
|
4658
4675
|
};
|
|
4676
|
+
this.size = {
|
|
4677
|
+
value: 1,
|
|
4678
|
+
max: 1,
|
|
4679
|
+
min: 1,
|
|
4680
|
+
enable: false,
|
|
4681
|
+
};
|
|
4659
4682
|
this.outType = ParticleOutType.normal;
|
|
4660
4683
|
this.ignoresResizeRatio = true;
|
|
4661
|
-
const
|
|
4684
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
4662
4685
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
4663
4686
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
4664
4687
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
4665
4688
|
if (overrideOptions) {
|
|
4666
|
-
if (overrideOptions.effect?.type) {
|
|
4689
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
4667
4690
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
4668
4691
|
if (effect) {
|
|
4669
4692
|
this.effect = effect;
|
|
4670
4693
|
effectOptions.load(overrideOptions.effect);
|
|
4671
4694
|
}
|
|
4672
4695
|
}
|
|
4673
|
-
if (overrideOptions.shape?.type) {
|
|
4696
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
4674
4697
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
4675
4698
|
if (shape) {
|
|
4676
4699
|
this.shape = shape;
|
|
@@ -4679,21 +4702,20 @@
|
|
|
4679
4702
|
}
|
|
4680
4703
|
}
|
|
4681
4704
|
if (this.effect === randomColorValue) {
|
|
4682
|
-
const availableEffects = [...this.
|
|
4705
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
4683
4706
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
4684
4707
|
}
|
|
4685
4708
|
if (this.shape === randomColorValue) {
|
|
4686
|
-
const availableShapes = [...this.
|
|
4709
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
4687
4710
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
4688
4711
|
}
|
|
4689
4712
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
4690
4713
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
4691
4714
|
particlesOptions.load(overrideOptions);
|
|
4692
|
-
const effectData = this.effectData;
|
|
4715
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
4693
4716
|
if (effectData) {
|
|
4694
4717
|
particlesOptions.load(effectData.particles);
|
|
4695
4718
|
}
|
|
4696
|
-
const shapeData = this.shapeData;
|
|
4697
4719
|
if (shapeData) {
|
|
4698
4720
|
particlesOptions.load(shapeData.particles);
|
|
4699
4721
|
}
|
|
@@ -4701,7 +4723,9 @@
|
|
|
4701
4723
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
4702
4724
|
this.options = particlesOptions;
|
|
4703
4725
|
container.retina.initParticle(this);
|
|
4704
|
-
|
|
4726
|
+
for (const updater of container.particleUpdaters) {
|
|
4727
|
+
updater.preInit?.(this);
|
|
4728
|
+
}
|
|
4705
4729
|
this.bubble = {
|
|
4706
4730
|
inRange: false,
|
|
4707
4731
|
};
|
|
@@ -4709,8 +4733,8 @@
|
|
|
4709
4733
|
inRange: false,
|
|
4710
4734
|
factor: 1,
|
|
4711
4735
|
};
|
|
4712
|
-
this
|
|
4713
|
-
this.initialVelocity = this
|
|
4736
|
+
this.#initPosition(position);
|
|
4737
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
4714
4738
|
this.velocity = this.initialVelocity.copy();
|
|
4715
4739
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
4716
4740
|
this.sides = 24;
|
|
@@ -4741,12 +4765,11 @@
|
|
|
4741
4765
|
plugin.particleCreated?.(this);
|
|
4742
4766
|
}
|
|
4743
4767
|
}
|
|
4744
|
-
isInsideCanvas() {
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
position.x <= canvasSize.width + radius);
|
|
4768
|
+
isInsideCanvas(direction) {
|
|
4769
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
4770
|
+
}
|
|
4771
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
4772
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
4750
4773
|
}
|
|
4751
4774
|
isShowingBack() {
|
|
4752
4775
|
if (!this.roll) {
|
|
@@ -4771,13 +4794,13 @@
|
|
|
4771
4794
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
4772
4795
|
}
|
|
4773
4796
|
reset() {
|
|
4774
|
-
for (const updater of this.
|
|
4797
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4775
4798
|
updater.reset?.(this);
|
|
4776
4799
|
}
|
|
4777
4800
|
}
|
|
4778
|
-
|
|
4801
|
+
#calcPosition = (position, zIndex) => {
|
|
4779
4802
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
4780
|
-
const container = this
|
|
4803
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
4781
4804
|
while (!signal.aborted) {
|
|
4782
4805
|
for (const plugin of plugins) {
|
|
4783
4806
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -4789,10 +4812,10 @@
|
|
|
4789
4812
|
size: canvasSize,
|
|
4790
4813
|
position: posVec,
|
|
4791
4814
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
4792
|
-
this
|
|
4793
|
-
this
|
|
4794
|
-
this
|
|
4795
|
-
this
|
|
4815
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
4816
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
4817
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
4818
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
4796
4819
|
let isValidPosition = true;
|
|
4797
4820
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
4798
4821
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -4808,8 +4831,8 @@
|
|
|
4808
4831
|
}
|
|
4809
4832
|
return posVec;
|
|
4810
4833
|
};
|
|
4811
|
-
|
|
4812
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
4834
|
+
#calculateVelocity = () => {
|
|
4835
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
4813
4836
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
4814
4837
|
return res;
|
|
4815
4838
|
}
|
|
@@ -4825,27 +4848,86 @@
|
|
|
4825
4848
|
}
|
|
4826
4849
|
return res;
|
|
4827
4850
|
};
|
|
4828
|
-
|
|
4851
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
4829
4852
|
fixOutMode({
|
|
4830
4853
|
outMode,
|
|
4831
4854
|
checkModes: [OutMode.bounce],
|
|
4832
4855
|
coord: pos.x,
|
|
4833
|
-
maxCoord: this.
|
|
4856
|
+
maxCoord: this.#container.canvas.size.width,
|
|
4834
4857
|
setCb: (value) => (pos.x += value),
|
|
4835
4858
|
radius,
|
|
4836
4859
|
});
|
|
4837
4860
|
};
|
|
4838
|
-
|
|
4861
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
4839
4862
|
fixOutMode({
|
|
4840
4863
|
outMode,
|
|
4841
4864
|
checkModes: [OutMode.bounce],
|
|
4842
4865
|
coord: pos.y,
|
|
4843
|
-
maxCoord: this.
|
|
4866
|
+
maxCoord: this.#container.canvas.size.height,
|
|
4844
4867
|
setCb: (value) => (pos.y += value),
|
|
4845
4868
|
radius,
|
|
4846
4869
|
});
|
|
4847
4870
|
};
|
|
4848
|
-
|
|
4871
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
4872
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
4873
|
+
if (direction === OutModeDirection.bottom) {
|
|
4874
|
+
return {
|
|
4875
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
4876
|
+
reason: "default",
|
|
4877
|
+
};
|
|
4878
|
+
}
|
|
4879
|
+
if (direction === OutModeDirection.left) {
|
|
4880
|
+
return {
|
|
4881
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
4882
|
+
reason: "default",
|
|
4883
|
+
};
|
|
4884
|
+
}
|
|
4885
|
+
if (direction === OutModeDirection.right) {
|
|
4886
|
+
return {
|
|
4887
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
4888
|
+
reason: "default",
|
|
4889
|
+
};
|
|
4890
|
+
}
|
|
4891
|
+
if (direction === OutModeDirection.top) {
|
|
4892
|
+
return {
|
|
4893
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
4894
|
+
reason: "default",
|
|
4895
|
+
};
|
|
4896
|
+
}
|
|
4897
|
+
return {
|
|
4898
|
+
inside: position.x >= -radius &&
|
|
4899
|
+
position.y >= -radius &&
|
|
4900
|
+
position.y <= canvasSize.height + radius &&
|
|
4901
|
+
position.x <= canvasSize.width + radius,
|
|
4902
|
+
reason: "default",
|
|
4903
|
+
};
|
|
4904
|
+
};
|
|
4905
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
4906
|
+
return {
|
|
4907
|
+
canvasSize: this.#container.canvas.size,
|
|
4908
|
+
direction,
|
|
4909
|
+
outMode,
|
|
4910
|
+
particle: this,
|
|
4911
|
+
radius: this.getRadius(),
|
|
4912
|
+
};
|
|
4913
|
+
};
|
|
4914
|
+
#getInsideCanvasResult = (data) => {
|
|
4915
|
+
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;
|
|
4916
|
+
if (!shapeCheck && !effectCheck) {
|
|
4917
|
+
return defaultResult;
|
|
4918
|
+
}
|
|
4919
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
4920
|
+
if (shapeResult && effectResult) {
|
|
4921
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
4922
|
+
return {
|
|
4923
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
4924
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
4925
|
+
reason: "combined",
|
|
4926
|
+
};
|
|
4927
|
+
}
|
|
4928
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
4929
|
+
};
|
|
4930
|
+
#getRollColor = color => {
|
|
4849
4931
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
4850
4932
|
return color;
|
|
4851
4933
|
}
|
|
@@ -4860,8 +4942,8 @@
|
|
|
4860
4942
|
}
|
|
4861
4943
|
return color;
|
|
4862
4944
|
};
|
|
4863
|
-
|
|
4864
|
-
const container = this
|
|
4945
|
+
#initPosition = position => {
|
|
4946
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
4865
4947
|
if (!initialPosition) {
|
|
4866
4948
|
throw new Error("a valid position cannot be found for particle");
|
|
4867
4949
|
}
|
|
@@ -4884,45 +4966,58 @@
|
|
|
4884
4966
|
}
|
|
4885
4967
|
this.offset = Vector.origin;
|
|
4886
4968
|
};
|
|
4969
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
4970
|
+
if (typeof result === "boolean") {
|
|
4971
|
+
return {
|
|
4972
|
+
inside: result,
|
|
4973
|
+
reason,
|
|
4974
|
+
};
|
|
4975
|
+
}
|
|
4976
|
+
return {
|
|
4977
|
+
inside: result.inside,
|
|
4978
|
+
margin: result.margin,
|
|
4979
|
+
reason: result.reason ?? reason,
|
|
4980
|
+
};
|
|
4981
|
+
};
|
|
4887
4982
|
}
|
|
4888
4983
|
|
|
4889
4984
|
class SpatialHashGrid {
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4985
|
+
#cellSize;
|
|
4986
|
+
#cells = new Map();
|
|
4987
|
+
#circlePool = [];
|
|
4988
|
+
#circlePoolIdx;
|
|
4989
|
+
#pendingCellSize;
|
|
4990
|
+
#rectanglePool = [];
|
|
4991
|
+
#rectanglePoolIdx;
|
|
4897
4992
|
constructor(cellSize) {
|
|
4898
|
-
this
|
|
4899
|
-
this
|
|
4900
|
-
this
|
|
4993
|
+
this.#cellSize = cellSize;
|
|
4994
|
+
this.#circlePoolIdx = 0;
|
|
4995
|
+
this.#rectanglePoolIdx = 0;
|
|
4901
4996
|
}
|
|
4902
4997
|
clear() {
|
|
4903
|
-
this.
|
|
4904
|
-
const pendingCellSize = this
|
|
4998
|
+
this.#cells.clear();
|
|
4999
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
4905
5000
|
if (pendingCellSize) {
|
|
4906
|
-
this
|
|
5001
|
+
this.#cellSize = pendingCellSize;
|
|
4907
5002
|
}
|
|
4908
|
-
this
|
|
5003
|
+
this.#pendingCellSize = undefined;
|
|
4909
5004
|
}
|
|
4910
5005
|
insert(particle) {
|
|
4911
|
-
const { x, y } = particle.getPosition(), key = this
|
|
4912
|
-
if (!this.
|
|
4913
|
-
this.
|
|
5006
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5007
|
+
if (!this.#cells.has(key)) {
|
|
5008
|
+
this.#cells.set(key, []);
|
|
4914
5009
|
}
|
|
4915
|
-
this.
|
|
5010
|
+
this.#cells.get(key)?.push(particle);
|
|
4916
5011
|
}
|
|
4917
5012
|
query(range, check, out = []) {
|
|
4918
|
-
const bounds = this
|
|
5013
|
+
const bounds = this.#getRangeBounds(range);
|
|
4919
5014
|
if (!bounds) {
|
|
4920
5015
|
return out;
|
|
4921
5016
|
}
|
|
4922
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5017
|
+
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);
|
|
4923
5018
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
4924
5019
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
4925
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5020
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
4926
5021
|
if (!cellParticles) {
|
|
4927
5022
|
continue;
|
|
4928
5023
|
}
|
|
@@ -4939,29 +5034,29 @@
|
|
|
4939
5034
|
return out;
|
|
4940
5035
|
}
|
|
4941
5036
|
queryCircle(position, radius, check, out = []) {
|
|
4942
|
-
const circle = this
|
|
4943
|
-
this
|
|
5037
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5038
|
+
this.#releaseShapes();
|
|
4944
5039
|
return result;
|
|
4945
5040
|
}
|
|
4946
5041
|
queryRectangle(position, size, check, out = []) {
|
|
4947
|
-
const rect = this
|
|
4948
|
-
this
|
|
5042
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5043
|
+
this.#releaseShapes();
|
|
4949
5044
|
return result;
|
|
4950
5045
|
}
|
|
4951
5046
|
setCellSize(cellSize) {
|
|
4952
|
-
this
|
|
5047
|
+
this.#pendingCellSize = cellSize;
|
|
4953
5048
|
}
|
|
4954
|
-
|
|
4955
|
-
return (this
|
|
5049
|
+
#acquireCircle(x, y, r) {
|
|
5050
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
4956
5051
|
}
|
|
4957
|
-
|
|
4958
|
-
return (this
|
|
5052
|
+
#acquireRectangle(x, y, w, h) {
|
|
5053
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
4959
5054
|
}
|
|
4960
|
-
|
|
4961
|
-
const cellX = Math.floor(x / this
|
|
5055
|
+
#cellKeyFromCoords(x, y) {
|
|
5056
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
4962
5057
|
return `${cellX}_${cellY}`;
|
|
4963
5058
|
}
|
|
4964
|
-
|
|
5059
|
+
#getRangeBounds(range) {
|
|
4965
5060
|
if (range instanceof Circle) {
|
|
4966
5061
|
const r = range.radius, { x, y } = range.position;
|
|
4967
5062
|
return {
|
|
@@ -4982,53 +5077,53 @@
|
|
|
4982
5077
|
}
|
|
4983
5078
|
return null;
|
|
4984
5079
|
}
|
|
4985
|
-
|
|
4986
|
-
this
|
|
4987
|
-
this
|
|
5080
|
+
#releaseShapes() {
|
|
5081
|
+
this.#circlePoolIdx = 0;
|
|
5082
|
+
this.#rectanglePoolIdx = 0;
|
|
4988
5083
|
}
|
|
4989
5084
|
}
|
|
4990
5085
|
|
|
4991
5086
|
class ParticlesManager {
|
|
4992
5087
|
checkParticlePositionPlugins;
|
|
4993
5088
|
grid;
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5089
|
+
#array;
|
|
5090
|
+
#container;
|
|
5091
|
+
#groupLimits;
|
|
5092
|
+
#limit;
|
|
5093
|
+
#nextId;
|
|
5094
|
+
#particleBuckets;
|
|
5095
|
+
#particleResetPlugins;
|
|
5096
|
+
#particleUpdatePlugins;
|
|
5097
|
+
#pluginManager;
|
|
5098
|
+
#pool;
|
|
5099
|
+
#postParticleUpdatePlugins;
|
|
5100
|
+
#postUpdatePlugins;
|
|
5101
|
+
#resizeFactor;
|
|
5102
|
+
#updatePlugins;
|
|
5103
|
+
#zBuckets;
|
|
5009
5104
|
constructor(pluginManager, container) {
|
|
5010
|
-
this
|
|
5011
|
-
this
|
|
5012
|
-
this
|
|
5013
|
-
this
|
|
5014
|
-
this
|
|
5015
|
-
this
|
|
5016
|
-
this
|
|
5017
|
-
this
|
|
5018
|
-
this
|
|
5105
|
+
this.#pluginManager = pluginManager;
|
|
5106
|
+
this.#container = container;
|
|
5107
|
+
this.#nextId = 0;
|
|
5108
|
+
this.#array = [];
|
|
5109
|
+
this.#pool = [];
|
|
5110
|
+
this.#limit = 0;
|
|
5111
|
+
this.#groupLimits = new Map();
|
|
5112
|
+
this.#particleBuckets = new Map();
|
|
5113
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5019
5114
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5020
5115
|
this.checkParticlePositionPlugins = [];
|
|
5021
|
-
this
|
|
5022
|
-
this
|
|
5023
|
-
this
|
|
5024
|
-
this
|
|
5025
|
-
this
|
|
5116
|
+
this.#particleResetPlugins = [];
|
|
5117
|
+
this.#particleUpdatePlugins = [];
|
|
5118
|
+
this.#postUpdatePlugins = [];
|
|
5119
|
+
this.#postParticleUpdatePlugins = [];
|
|
5120
|
+
this.#updatePlugins = [];
|
|
5026
5121
|
}
|
|
5027
5122
|
get count() {
|
|
5028
|
-
return this.
|
|
5123
|
+
return this.#array.length;
|
|
5029
5124
|
}
|
|
5030
5125
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5031
|
-
const limitMode = this.
|
|
5126
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5032
5127
|
if (limit > minLimit) {
|
|
5033
5128
|
switch (limitMode) {
|
|
5034
5129
|
case LimitMode.delete: {
|
|
@@ -5046,20 +5141,20 @@
|
|
|
5046
5141
|
}
|
|
5047
5142
|
}
|
|
5048
5143
|
try {
|
|
5049
|
-
const particle = this.
|
|
5050
|
-
particle.init(this
|
|
5144
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5145
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5051
5146
|
let canAdd = true;
|
|
5052
5147
|
if (initializer) {
|
|
5053
5148
|
canAdd = initializer(particle);
|
|
5054
5149
|
}
|
|
5055
5150
|
if (!canAdd) {
|
|
5056
|
-
this.
|
|
5151
|
+
this.#pool.push(particle);
|
|
5057
5152
|
return;
|
|
5058
5153
|
}
|
|
5059
|
-
this.
|
|
5060
|
-
this
|
|
5061
|
-
this
|
|
5062
|
-
this.
|
|
5154
|
+
this.#array.push(particle);
|
|
5155
|
+
this.#insertParticleIntoBucket(particle);
|
|
5156
|
+
this.#nextId++;
|
|
5157
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5063
5158
|
particle,
|
|
5064
5159
|
});
|
|
5065
5160
|
return particle;
|
|
@@ -5070,25 +5165,25 @@
|
|
|
5070
5165
|
return undefined;
|
|
5071
5166
|
}
|
|
5072
5167
|
clear() {
|
|
5073
|
-
this
|
|
5074
|
-
this.
|
|
5075
|
-
this
|
|
5168
|
+
this.#array = [];
|
|
5169
|
+
this.#particleBuckets.clear();
|
|
5170
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5076
5171
|
}
|
|
5077
5172
|
destroy() {
|
|
5078
|
-
this
|
|
5079
|
-
this.
|
|
5080
|
-
this.
|
|
5081
|
-
this
|
|
5173
|
+
this.#array = [];
|
|
5174
|
+
this.#pool.length = 0;
|
|
5175
|
+
this.#particleBuckets.clear();
|
|
5176
|
+
this.#zBuckets = [];
|
|
5082
5177
|
this.checkParticlePositionPlugins = [];
|
|
5083
|
-
this
|
|
5084
|
-
this
|
|
5085
|
-
this
|
|
5086
|
-
this
|
|
5087
|
-
this
|
|
5178
|
+
this.#particleResetPlugins = [];
|
|
5179
|
+
this.#particleUpdatePlugins = [];
|
|
5180
|
+
this.#postUpdatePlugins = [];
|
|
5181
|
+
this.#postParticleUpdatePlugins = [];
|
|
5182
|
+
this.#updatePlugins = [];
|
|
5088
5183
|
}
|
|
5089
5184
|
drawParticles(delta) {
|
|
5090
|
-
for (let i = this.
|
|
5091
|
-
const bucket = this
|
|
5185
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5186
|
+
const bucket = this.#zBuckets[i];
|
|
5092
5187
|
if (!bucket) {
|
|
5093
5188
|
continue;
|
|
5094
5189
|
}
|
|
@@ -5098,24 +5193,24 @@
|
|
|
5098
5193
|
}
|
|
5099
5194
|
}
|
|
5100
5195
|
filter(condition) {
|
|
5101
|
-
return this.
|
|
5196
|
+
return this.#array.filter(condition);
|
|
5102
5197
|
}
|
|
5103
5198
|
find(condition) {
|
|
5104
|
-
return this.
|
|
5199
|
+
return this.#array.find(condition);
|
|
5105
5200
|
}
|
|
5106
5201
|
get(index) {
|
|
5107
|
-
return this
|
|
5202
|
+
return this.#array[index];
|
|
5108
5203
|
}
|
|
5109
5204
|
async init() {
|
|
5110
|
-
const container = this
|
|
5205
|
+
const container = this.#container, options = container.actualOptions;
|
|
5111
5206
|
this.checkParticlePositionPlugins = [];
|
|
5112
|
-
this
|
|
5113
|
-
this
|
|
5114
|
-
this
|
|
5115
|
-
this
|
|
5116
|
-
this
|
|
5117
|
-
this.
|
|
5118
|
-
this
|
|
5207
|
+
this.#updatePlugins = [];
|
|
5208
|
+
this.#particleUpdatePlugins = [];
|
|
5209
|
+
this.#postUpdatePlugins = [];
|
|
5210
|
+
this.#particleResetPlugins = [];
|
|
5211
|
+
this.#postParticleUpdatePlugins = [];
|
|
5212
|
+
this.#particleBuckets.clear();
|
|
5213
|
+
this.#resetBuckets(container.zLayers);
|
|
5119
5214
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5120
5215
|
for (const plugin of container.plugins) {
|
|
5121
5216
|
if (plugin.redrawInit) {
|
|
@@ -5125,26 +5220,26 @@
|
|
|
5125
5220
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5126
5221
|
}
|
|
5127
5222
|
if (plugin.update) {
|
|
5128
|
-
this.
|
|
5223
|
+
this.#updatePlugins.push(plugin);
|
|
5129
5224
|
}
|
|
5130
5225
|
if (plugin.particleUpdate) {
|
|
5131
|
-
this.
|
|
5226
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5132
5227
|
}
|
|
5133
5228
|
if (plugin.postUpdate) {
|
|
5134
|
-
this.
|
|
5229
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5135
5230
|
}
|
|
5136
5231
|
if (plugin.particleReset) {
|
|
5137
|
-
this.
|
|
5232
|
+
this.#particleResetPlugins.push(plugin);
|
|
5138
5233
|
}
|
|
5139
5234
|
if (plugin.postParticleUpdate) {
|
|
5140
|
-
this.
|
|
5235
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5141
5236
|
}
|
|
5142
5237
|
}
|
|
5143
|
-
await this.
|
|
5144
|
-
for (const drawer of this.
|
|
5238
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5239
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5145
5240
|
await drawer.init?.(container);
|
|
5146
5241
|
}
|
|
5147
|
-
for (const drawer of this.
|
|
5242
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5148
5243
|
await drawer.init?.(container);
|
|
5149
5244
|
}
|
|
5150
5245
|
let handled = false;
|
|
@@ -5178,10 +5273,10 @@
|
|
|
5178
5273
|
async redraw() {
|
|
5179
5274
|
this.clear();
|
|
5180
5275
|
await this.init();
|
|
5181
|
-
this.
|
|
5276
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5182
5277
|
}
|
|
5183
5278
|
remove(particle, group, override) {
|
|
5184
|
-
this.removeAt(this.
|
|
5279
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5185
5280
|
}
|
|
5186
5281
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5187
5282
|
if (index < minIndex || index > this.count) {
|
|
@@ -5189,7 +5284,7 @@
|
|
|
5189
5284
|
}
|
|
5190
5285
|
let deleted = 0;
|
|
5191
5286
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5192
|
-
if (this
|
|
5287
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5193
5288
|
i--;
|
|
5194
5289
|
deleted++;
|
|
5195
5290
|
}
|
|
@@ -5199,9 +5294,9 @@
|
|
|
5199
5294
|
this.removeAt(minIndex, quantity, group);
|
|
5200
5295
|
}
|
|
5201
5296
|
setDensity() {
|
|
5202
|
-
const options = this.
|
|
5297
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5203
5298
|
let pluginsCount = 0;
|
|
5204
|
-
for (const plugin of this.
|
|
5299
|
+
for (const plugin of this.#container.plugins) {
|
|
5205
5300
|
if (plugin.particlesDensityCount) {
|
|
5206
5301
|
pluginsCount += plugin.particlesDensityCount();
|
|
5207
5302
|
}
|
|
@@ -5211,51 +5306,51 @@
|
|
|
5211
5306
|
if (!groupData) {
|
|
5212
5307
|
continue;
|
|
5213
5308
|
}
|
|
5214
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5215
|
-
this
|
|
5309
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5310
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5216
5311
|
}
|
|
5217
|
-
this
|
|
5312
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5218
5313
|
}
|
|
5219
5314
|
setResizeFactor(factor) {
|
|
5220
|
-
this
|
|
5315
|
+
this.#resizeFactor = factor;
|
|
5221
5316
|
}
|
|
5222
5317
|
update(delta) {
|
|
5223
5318
|
this.grid.clear();
|
|
5224
|
-
for (const plugin of this
|
|
5319
|
+
for (const plugin of this.#updatePlugins) {
|
|
5225
5320
|
plugin.update?.(delta);
|
|
5226
5321
|
}
|
|
5227
|
-
const particlesToDelete = this
|
|
5228
|
-
for (const plugin of this
|
|
5322
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5323
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5229
5324
|
plugin.postUpdate?.(delta);
|
|
5230
5325
|
}
|
|
5231
|
-
this
|
|
5326
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5232
5327
|
if (particlesToDelete.size) {
|
|
5233
5328
|
for (const particle of particlesToDelete) {
|
|
5234
5329
|
this.remove(particle);
|
|
5235
5330
|
}
|
|
5236
5331
|
}
|
|
5237
|
-
|
|
5332
|
+
this.#resizeFactor = undefined;
|
|
5238
5333
|
}
|
|
5239
|
-
|
|
5240
|
-
this.
|
|
5334
|
+
#addToPool = (...particles) => {
|
|
5335
|
+
this.#pool.push(...particles);
|
|
5241
5336
|
};
|
|
5242
|
-
|
|
5337
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5243
5338
|
const numberOptions = options.number;
|
|
5244
5339
|
if (!numberOptions.density.enable) {
|
|
5245
5340
|
if (group === undefined) {
|
|
5246
|
-
this
|
|
5341
|
+
this.#limit = numberOptions.limit.value;
|
|
5247
5342
|
}
|
|
5248
5343
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5249
|
-
this.
|
|
5344
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5250
5345
|
}
|
|
5251
5346
|
return;
|
|
5252
5347
|
}
|
|
5253
|
-
const densityFactor = this
|
|
5348
|
+
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);
|
|
5254
5349
|
if (group === undefined) {
|
|
5255
|
-
this
|
|
5350
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5256
5351
|
}
|
|
5257
5352
|
else {
|
|
5258
|
-
this.
|
|
5353
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5259
5354
|
}
|
|
5260
5355
|
if (particlesCount < particlesNumber) {
|
|
5261
5356
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5264,18 +5359,18 @@
|
|
|
5264
5359
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5265
5360
|
}
|
|
5266
5361
|
};
|
|
5267
|
-
|
|
5362
|
+
#createBuckets = (zLayers) => {
|
|
5268
5363
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5269
5364
|
return Array.from({ length: bucketCount }, () => []);
|
|
5270
5365
|
};
|
|
5271
|
-
|
|
5272
|
-
const maxBucketIndex = this.
|
|
5366
|
+
#getBucketIndex = (zIndex) => {
|
|
5367
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5273
5368
|
if (maxBucketIndex <= minIndex) {
|
|
5274
5369
|
return minIndex;
|
|
5275
5370
|
}
|
|
5276
5371
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5277
5372
|
};
|
|
5278
|
-
|
|
5373
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5279
5374
|
let start = minIndex, end = bucket.length;
|
|
5280
5375
|
while (start < end) {
|
|
5281
5376
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5292,8 +5387,8 @@
|
|
|
5292
5387
|
}
|
|
5293
5388
|
return start;
|
|
5294
5389
|
};
|
|
5295
|
-
|
|
5296
|
-
const container = this
|
|
5390
|
+
#initDensityFactor = densityOptions => {
|
|
5391
|
+
const container = this.#container;
|
|
5297
5392
|
if (!densityOptions.enable) {
|
|
5298
5393
|
return defaultDensityFactor;
|
|
5299
5394
|
}
|
|
@@ -5303,82 +5398,82 @@
|
|
|
5303
5398
|
}
|
|
5304
5399
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5305
5400
|
};
|
|
5306
|
-
|
|
5307
|
-
const bucketIndex = this
|
|
5401
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5402
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5308
5403
|
if (!bucket) {
|
|
5309
5404
|
return;
|
|
5310
5405
|
}
|
|
5311
|
-
bucket.splice(this
|
|
5312
|
-
this.
|
|
5406
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5407
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5313
5408
|
};
|
|
5314
|
-
|
|
5315
|
-
const particle = this
|
|
5409
|
+
#removeParticle = (index, group, override) => {
|
|
5410
|
+
const particle = this.#array[index];
|
|
5316
5411
|
if (!particle) {
|
|
5317
5412
|
return false;
|
|
5318
5413
|
}
|
|
5319
5414
|
if (particle.group !== group) {
|
|
5320
5415
|
return false;
|
|
5321
5416
|
}
|
|
5322
|
-
this.
|
|
5323
|
-
this
|
|
5417
|
+
this.#array.splice(index, deleteCount);
|
|
5418
|
+
this.#removeParticleFromBucket(particle);
|
|
5324
5419
|
particle.destroy(override);
|
|
5325
|
-
this.
|
|
5420
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5326
5421
|
particle,
|
|
5327
5422
|
});
|
|
5328
|
-
this
|
|
5423
|
+
this.#addToPool(particle);
|
|
5329
5424
|
return true;
|
|
5330
5425
|
};
|
|
5331
|
-
|
|
5332
|
-
const bucketIndex = this.
|
|
5426
|
+
#removeParticleFromBucket = (particle) => {
|
|
5427
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5333
5428
|
if (!bucket) {
|
|
5334
|
-
this.
|
|
5429
|
+
this.#particleBuckets.delete(particle.id);
|
|
5335
5430
|
return;
|
|
5336
5431
|
}
|
|
5337
|
-
const particleIndex = this
|
|
5432
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5338
5433
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5339
|
-
this.
|
|
5434
|
+
this.#particleBuckets.delete(particle.id);
|
|
5340
5435
|
return;
|
|
5341
5436
|
}
|
|
5342
5437
|
bucket.splice(particleIndex, deleteCount);
|
|
5343
|
-
this.
|
|
5438
|
+
this.#particleBuckets.delete(particle.id);
|
|
5344
5439
|
};
|
|
5345
|
-
|
|
5440
|
+
#resetBuckets = (zLayers) => {
|
|
5346
5441
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5347
|
-
if (this.
|
|
5348
|
-
this
|
|
5442
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
5443
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5349
5444
|
return;
|
|
5350
5445
|
}
|
|
5351
|
-
for (const bucket of this
|
|
5446
|
+
for (const bucket of this.#zBuckets) {
|
|
5352
5447
|
bucket.length = minIndex;
|
|
5353
5448
|
}
|
|
5354
5449
|
};
|
|
5355
|
-
|
|
5356
|
-
const newBucketIndex = this
|
|
5450
|
+
#updateParticleBucket = (particle) => {
|
|
5451
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5357
5452
|
if (currentBucketIndex === undefined) {
|
|
5358
|
-
this
|
|
5453
|
+
this.#insertParticleIntoBucket(particle);
|
|
5359
5454
|
return;
|
|
5360
5455
|
}
|
|
5361
5456
|
if (currentBucketIndex === newBucketIndex) {
|
|
5362
5457
|
return;
|
|
5363
5458
|
}
|
|
5364
|
-
const currentBucket = this
|
|
5459
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5365
5460
|
if (currentBucket) {
|
|
5366
|
-
const particleIndex = this
|
|
5461
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5367
5462
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5368
5463
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5369
5464
|
}
|
|
5370
5465
|
}
|
|
5371
|
-
const newBucket = this
|
|
5466
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5372
5467
|
if (!newBucket) {
|
|
5373
|
-
this.
|
|
5468
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5374
5469
|
return;
|
|
5375
5470
|
}
|
|
5376
|
-
newBucket.splice(this
|
|
5377
|
-
this.
|
|
5471
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
5472
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5378
5473
|
};
|
|
5379
|
-
|
|
5380
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5381
|
-
for (const particle of this
|
|
5474
|
+
#updateParticlesPhase1 = (delta) => {
|
|
5475
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
5476
|
+
for (const particle of this.#array) {
|
|
5382
5477
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5383
5478
|
particle.position.x *= resizeFactor.width;
|
|
5384
5479
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5386,10 +5481,10 @@
|
|
|
5386
5481
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5387
5482
|
}
|
|
5388
5483
|
particle.ignoresResizeRatio = false;
|
|
5389
|
-
for (const plugin of this
|
|
5484
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5390
5485
|
plugin.particleReset?.(particle);
|
|
5391
5486
|
}
|
|
5392
|
-
for (const plugin of this
|
|
5487
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5393
5488
|
if (particle.destroyed) {
|
|
5394
5489
|
break;
|
|
5395
5490
|
}
|
|
@@ -5403,36 +5498,36 @@
|
|
|
5403
5498
|
}
|
|
5404
5499
|
return particlesToDelete;
|
|
5405
5500
|
};
|
|
5406
|
-
|
|
5407
|
-
for (const particle of this
|
|
5501
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
5502
|
+
for (const particle of this.#array) {
|
|
5408
5503
|
if (particle.destroyed) {
|
|
5409
5504
|
particlesToDelete.add(particle);
|
|
5410
5505
|
continue;
|
|
5411
5506
|
}
|
|
5412
|
-
for (const updater of this.
|
|
5507
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5413
5508
|
updater.update(particle, delta);
|
|
5414
5509
|
}
|
|
5415
5510
|
if (!particle.spawning) {
|
|
5416
|
-
for (const plugin of this
|
|
5511
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5417
5512
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5418
5513
|
}
|
|
5419
5514
|
}
|
|
5420
|
-
this
|
|
5515
|
+
this.#updateParticleBucket(particle);
|
|
5421
5516
|
}
|
|
5422
5517
|
};
|
|
5423
5518
|
}
|
|
5424
5519
|
|
|
5425
5520
|
class Retina {
|
|
5426
|
-
container;
|
|
5427
5521
|
pixelRatio;
|
|
5428
5522
|
reduceFactor;
|
|
5523
|
+
#container;
|
|
5429
5524
|
constructor(container) {
|
|
5430
|
-
this
|
|
5525
|
+
this.#container = container;
|
|
5431
5526
|
this.pixelRatio = defaultRatio;
|
|
5432
5527
|
this.reduceFactor = defaultReduceFactor;
|
|
5433
5528
|
}
|
|
5434
5529
|
init() {
|
|
5435
|
-
const container = this
|
|
5530
|
+
const container = this.#container, options = container.actualOptions;
|
|
5436
5531
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
5437
5532
|
this.reduceFactor = defaultReduceFactor;
|
|
5438
5533
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -5446,7 +5541,6 @@
|
|
|
5446
5541
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
5447
5542
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
5448
5543
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
5449
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
5450
5544
|
const maxDistance = props.maxDistance;
|
|
5451
5545
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
5452
5546
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -5484,73 +5578,73 @@
|
|
|
5484
5578
|
shapeDrawers;
|
|
5485
5579
|
started;
|
|
5486
5580
|
zLayers;
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5581
|
+
#delay;
|
|
5582
|
+
#delayTimeout;
|
|
5583
|
+
#delta = { value: 0, factor: 0 };
|
|
5584
|
+
#dispatchCallback;
|
|
5585
|
+
#drawAnimationFrame;
|
|
5586
|
+
#duration;
|
|
5587
|
+
#eventListeners;
|
|
5588
|
+
#firstStart;
|
|
5589
|
+
#initialSourceOptions;
|
|
5590
|
+
#lastFrameTime;
|
|
5591
|
+
#lifeTime;
|
|
5592
|
+
#onDestroy;
|
|
5593
|
+
#options;
|
|
5594
|
+
#paused;
|
|
5595
|
+
#pluginManager;
|
|
5596
|
+
#smooth;
|
|
5597
|
+
#sourceOptions;
|
|
5504
5598
|
constructor(params) {
|
|
5505
5599
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
5506
|
-
this
|
|
5507
|
-
this
|
|
5508
|
-
this
|
|
5600
|
+
this.#pluginManager = pluginManager;
|
|
5601
|
+
this.#dispatchCallback = dispatchCallback;
|
|
5602
|
+
this.#onDestroy = onDestroy;
|
|
5509
5603
|
this.id = Symbol(id);
|
|
5510
5604
|
this.fpsLimit = 120;
|
|
5511
5605
|
this.hdr = false;
|
|
5512
|
-
this
|
|
5513
|
-
this
|
|
5514
|
-
this
|
|
5515
|
-
this
|
|
5516
|
-
this
|
|
5606
|
+
this.#smooth = false;
|
|
5607
|
+
this.#delay = 0;
|
|
5608
|
+
this.#duration = 0;
|
|
5609
|
+
this.#lifeTime = 0;
|
|
5610
|
+
this.#firstStart = true;
|
|
5517
5611
|
this.started = false;
|
|
5518
5612
|
this.destroyed = false;
|
|
5519
|
-
this
|
|
5520
|
-
this
|
|
5613
|
+
this.#paused = true;
|
|
5614
|
+
this.#lastFrameTime = 0;
|
|
5521
5615
|
this.zLayers = 100;
|
|
5522
5616
|
this.pageHidden = false;
|
|
5523
|
-
this
|
|
5524
|
-
this
|
|
5617
|
+
this.#sourceOptions = sourceOptions;
|
|
5618
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5525
5619
|
this.effectDrawers = new Map();
|
|
5526
5620
|
this.shapeDrawers = new Map();
|
|
5527
5621
|
this.particleUpdaters = [];
|
|
5528
5622
|
this.retina = new Retina(this);
|
|
5529
|
-
this.canvas = new CanvasManager(this
|
|
5530
|
-
this.particles = new ParticlesManager(this
|
|
5623
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
5624
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
5531
5625
|
this.plugins = [];
|
|
5532
5626
|
this.particleDestroyedPlugins = [];
|
|
5533
5627
|
this.particleCreatedPlugins = [];
|
|
5534
5628
|
this.particlePositionPlugins = [];
|
|
5535
|
-
this
|
|
5536
|
-
this.actualOptions = loadContainerOptions(this
|
|
5537
|
-
this
|
|
5629
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
5630
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
5631
|
+
this.#eventListeners = new EventListeners(this);
|
|
5538
5632
|
this.dispatchEvent(EventType.containerBuilt);
|
|
5539
5633
|
}
|
|
5540
5634
|
get animationStatus() {
|
|
5541
|
-
return !this
|
|
5635
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
5542
5636
|
}
|
|
5543
5637
|
get options() {
|
|
5544
|
-
return this
|
|
5638
|
+
return this.#options;
|
|
5545
5639
|
}
|
|
5546
5640
|
get sourceOptions() {
|
|
5547
|
-
return this
|
|
5641
|
+
return this.#sourceOptions;
|
|
5548
5642
|
}
|
|
5549
5643
|
addLifeTime(value) {
|
|
5550
|
-
this
|
|
5644
|
+
this.#lifeTime += value;
|
|
5551
5645
|
}
|
|
5552
5646
|
alive() {
|
|
5553
|
-
return !this
|
|
5647
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
5554
5648
|
}
|
|
5555
5649
|
destroy(remove = true) {
|
|
5556
5650
|
if (!guardCheck(this)) {
|
|
@@ -5572,13 +5666,13 @@
|
|
|
5572
5666
|
this.shapeDrawers = new Map();
|
|
5573
5667
|
this.particleUpdaters = [];
|
|
5574
5668
|
this.plugins.length = 0;
|
|
5575
|
-
this.
|
|
5669
|
+
this.#pluginManager.clearPlugins(this);
|
|
5576
5670
|
this.destroyed = true;
|
|
5577
|
-
this
|
|
5671
|
+
this.#onDestroy(remove);
|
|
5578
5672
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
5579
5673
|
}
|
|
5580
5674
|
dispatchEvent(type, data) {
|
|
5581
|
-
this
|
|
5675
|
+
this.#dispatchCallback(type, {
|
|
5582
5676
|
container: this,
|
|
5583
5677
|
data,
|
|
5584
5678
|
});
|
|
@@ -5588,12 +5682,12 @@
|
|
|
5588
5682
|
return;
|
|
5589
5683
|
}
|
|
5590
5684
|
let refreshTime = force;
|
|
5591
|
-
this
|
|
5685
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
5592
5686
|
if (refreshTime) {
|
|
5593
|
-
this
|
|
5687
|
+
this.#lastFrameTime = undefined;
|
|
5594
5688
|
refreshTime = false;
|
|
5595
5689
|
}
|
|
5596
|
-
this
|
|
5690
|
+
this.#nextFrame(timestamp);
|
|
5597
5691
|
});
|
|
5598
5692
|
}
|
|
5599
5693
|
async export(type, options = {}) {
|
|
@@ -5615,7 +5709,7 @@
|
|
|
5615
5709
|
return;
|
|
5616
5710
|
}
|
|
5617
5711
|
const allContainerPlugins = new Map();
|
|
5618
|
-
for (const plugin of this.
|
|
5712
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
5619
5713
|
const containerPlugin = await plugin.getPlugin(this);
|
|
5620
5714
|
if (containerPlugin.preInit) {
|
|
5621
5715
|
await containerPlugin.preInit();
|
|
@@ -5623,8 +5717,8 @@
|
|
|
5623
5717
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
5624
5718
|
}
|
|
5625
5719
|
await this.initDrawersAndUpdaters();
|
|
5626
|
-
this
|
|
5627
|
-
this.actualOptions = loadContainerOptions(this
|
|
5720
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5721
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5628
5722
|
this.plugins.length = 0;
|
|
5629
5723
|
this.particleDestroyedPlugins.length = 0;
|
|
5630
5724
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -5651,11 +5745,11 @@
|
|
|
5651
5745
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
5652
5746
|
this.hdr = hdr;
|
|
5653
5747
|
this.zLayers = zLayers;
|
|
5654
|
-
this
|
|
5655
|
-
this
|
|
5656
|
-
this
|
|
5748
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
5749
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
5750
|
+
this.#lifeTime = 0;
|
|
5657
5751
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
5658
|
-
this
|
|
5752
|
+
this.#smooth = smooth;
|
|
5659
5753
|
for (const plugin of this.plugins) {
|
|
5660
5754
|
await plugin.init?.();
|
|
5661
5755
|
}
|
|
@@ -5668,7 +5762,7 @@
|
|
|
5668
5762
|
this.dispatchEvent(EventType.particlesSetup);
|
|
5669
5763
|
}
|
|
5670
5764
|
async initDrawersAndUpdaters() {
|
|
5671
|
-
const pluginManager = this
|
|
5765
|
+
const pluginManager = this.#pluginManager;
|
|
5672
5766
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
5673
5767
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
5674
5768
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -5677,18 +5771,18 @@
|
|
|
5677
5771
|
if (!guardCheck(this)) {
|
|
5678
5772
|
return;
|
|
5679
5773
|
}
|
|
5680
|
-
if (this
|
|
5681
|
-
cancelAnimation(this
|
|
5682
|
-
|
|
5774
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
5775
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
5776
|
+
this.#drawAnimationFrame = undefined;
|
|
5683
5777
|
}
|
|
5684
|
-
if (this
|
|
5778
|
+
if (this.#paused) {
|
|
5685
5779
|
return;
|
|
5686
5780
|
}
|
|
5687
5781
|
for (const plugin of this.plugins) {
|
|
5688
5782
|
plugin.pause?.();
|
|
5689
5783
|
}
|
|
5690
5784
|
if (!this.pageHidden) {
|
|
5691
|
-
this
|
|
5785
|
+
this.#paused = true;
|
|
5692
5786
|
}
|
|
5693
5787
|
this.dispatchEvent(EventType.containerPaused);
|
|
5694
5788
|
}
|
|
@@ -5696,13 +5790,13 @@
|
|
|
5696
5790
|
if (!guardCheck(this)) {
|
|
5697
5791
|
return;
|
|
5698
5792
|
}
|
|
5699
|
-
const needsUpdate = this
|
|
5700
|
-
if (this
|
|
5701
|
-
this
|
|
5793
|
+
const needsUpdate = this.#paused || force;
|
|
5794
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
5795
|
+
this.#firstStart = false;
|
|
5702
5796
|
return;
|
|
5703
5797
|
}
|
|
5704
|
-
if (this
|
|
5705
|
-
this
|
|
5798
|
+
if (this.#paused) {
|
|
5799
|
+
this.#paused = false;
|
|
5706
5800
|
}
|
|
5707
5801
|
if (needsUpdate) {
|
|
5708
5802
|
for (const plugin of this.plugins) {
|
|
@@ -5725,10 +5819,10 @@
|
|
|
5725
5819
|
if (!guardCheck(this)) {
|
|
5726
5820
|
return;
|
|
5727
5821
|
}
|
|
5728
|
-
this
|
|
5729
|
-
this
|
|
5730
|
-
this
|
|
5731
|
-
this.actualOptions = loadContainerOptions(this
|
|
5822
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5823
|
+
this.#sourceOptions = sourceOptions;
|
|
5824
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5825
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5732
5826
|
return this.refresh();
|
|
5733
5827
|
}
|
|
5734
5828
|
async start() {
|
|
@@ -5739,7 +5833,7 @@
|
|
|
5739
5833
|
this.started = true;
|
|
5740
5834
|
await new Promise(resolve => {
|
|
5741
5835
|
const start = async () => {
|
|
5742
|
-
this.
|
|
5836
|
+
this.#eventListeners.addListeners();
|
|
5743
5837
|
for (const plugin of this.plugins) {
|
|
5744
5838
|
await plugin.start?.();
|
|
5745
5839
|
}
|
|
@@ -5747,20 +5841,20 @@
|
|
|
5747
5841
|
this.play();
|
|
5748
5842
|
resolve();
|
|
5749
5843
|
};
|
|
5750
|
-
this
|
|
5844
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
5751
5845
|
});
|
|
5752
5846
|
}
|
|
5753
5847
|
stop() {
|
|
5754
5848
|
if (!guardCheck(this) || !this.started) {
|
|
5755
5849
|
return;
|
|
5756
5850
|
}
|
|
5757
|
-
if (this
|
|
5758
|
-
clearTimeout(this
|
|
5759
|
-
|
|
5851
|
+
if (this.#delayTimeout) {
|
|
5852
|
+
clearTimeout(this.#delayTimeout);
|
|
5853
|
+
this.#delayTimeout = undefined;
|
|
5760
5854
|
}
|
|
5761
|
-
this
|
|
5855
|
+
this.#firstStart = true;
|
|
5762
5856
|
this.started = false;
|
|
5763
|
-
this.
|
|
5857
|
+
this.#eventListeners.removeListeners();
|
|
5764
5858
|
this.pause();
|
|
5765
5859
|
this.particles.clear();
|
|
5766
5860
|
this.canvas.stop();
|
|
@@ -5770,7 +5864,7 @@
|
|
|
5770
5864
|
this.particleCreatedPlugins.length = 0;
|
|
5771
5865
|
this.particleDestroyedPlugins.length = 0;
|
|
5772
5866
|
this.particlePositionPlugins.length = 0;
|
|
5773
|
-
this
|
|
5867
|
+
this.#sourceOptions = this.#options;
|
|
5774
5868
|
this.dispatchEvent(EventType.containerStopped);
|
|
5775
5869
|
}
|
|
5776
5870
|
updateActualOptions() {
|
|
@@ -5782,23 +5876,23 @@
|
|
|
5782
5876
|
}
|
|
5783
5877
|
return refresh;
|
|
5784
5878
|
}
|
|
5785
|
-
|
|
5879
|
+
#nextFrame = (timestamp) => {
|
|
5786
5880
|
try {
|
|
5787
|
-
if (!this
|
|
5788
|
-
this
|
|
5789
|
-
timestamp < this
|
|
5881
|
+
if (!this.#smooth &&
|
|
5882
|
+
this.#lastFrameTime !== undefined &&
|
|
5883
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
5790
5884
|
this.draw(false);
|
|
5791
5885
|
return;
|
|
5792
5886
|
}
|
|
5793
|
-
this
|
|
5794
|
-
updateDelta(this
|
|
5795
|
-
this.addLifeTime(this.
|
|
5796
|
-
this
|
|
5797
|
-
if (this.
|
|
5887
|
+
this.#lastFrameTime ??= timestamp;
|
|
5888
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
5889
|
+
this.addLifeTime(this.#delta.value);
|
|
5890
|
+
this.#lastFrameTime = timestamp;
|
|
5891
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
5798
5892
|
this.draw(false);
|
|
5799
5893
|
return;
|
|
5800
5894
|
}
|
|
5801
|
-
this.canvas.render.drawParticles(this
|
|
5895
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
5802
5896
|
if (!this.alive()) {
|
|
5803
5897
|
this.destroy();
|
|
5804
5898
|
return;
|
|
@@ -5819,10 +5913,10 @@
|
|
|
5819
5913
|
});
|
|
5820
5914
|
|
|
5821
5915
|
class BlendPluginInstance {
|
|
5822
|
-
|
|
5823
|
-
|
|
5916
|
+
#container;
|
|
5917
|
+
#defaultCompositeValue;
|
|
5824
5918
|
constructor(container) {
|
|
5825
|
-
this
|
|
5919
|
+
this.#container = container;
|
|
5826
5920
|
}
|
|
5827
5921
|
drawParticleCleanup(context, particle) {
|
|
5828
5922
|
if (!particle.options.blend?.enable) {
|
|
@@ -5839,14 +5933,14 @@
|
|
|
5839
5933
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
5840
5934
|
}
|
|
5841
5935
|
drawSettingsCleanup(context) {
|
|
5842
|
-
if (!this
|
|
5936
|
+
if (!this.#defaultCompositeValue) {
|
|
5843
5937
|
return;
|
|
5844
5938
|
}
|
|
5845
|
-
context.globalCompositeOperation = this
|
|
5939
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
5846
5940
|
}
|
|
5847
5941
|
drawSettingsSetup(context) {
|
|
5848
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
5849
|
-
this
|
|
5942
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
5943
|
+
this.#defaultCompositeValue = previousComposite;
|
|
5850
5944
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
5851
5945
|
}
|
|
5852
5946
|
}
|
|
@@ -5989,11 +6083,11 @@
|
|
|
5989
6083
|
class MovePluginInstance {
|
|
5990
6084
|
availablePathGenerators;
|
|
5991
6085
|
pathGenerators;
|
|
5992
|
-
|
|
5993
|
-
|
|
6086
|
+
#container;
|
|
6087
|
+
#pluginManager;
|
|
5994
6088
|
constructor(pluginManager, container) {
|
|
5995
|
-
this
|
|
5996
|
-
this
|
|
6089
|
+
this.#pluginManager = pluginManager;
|
|
6090
|
+
this.#container = container;
|
|
5997
6091
|
this.availablePathGenerators = new Map();
|
|
5998
6092
|
this.pathGenerators = new Map();
|
|
5999
6093
|
}
|
|
@@ -6024,7 +6118,7 @@
|
|
|
6024
6118
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6025
6119
|
inverse: gravityOptions.inverse,
|
|
6026
6120
|
};
|
|
6027
|
-
initSpin(this
|
|
6121
|
+
initSpin(this.#container, particle);
|
|
6028
6122
|
}
|
|
6029
6123
|
particleDestroyed(particle) {
|
|
6030
6124
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6035,7 +6129,7 @@
|
|
|
6035
6129
|
if (!moveOptions.enable) {
|
|
6036
6130
|
return;
|
|
6037
6131
|
}
|
|
6038
|
-
const container = this
|
|
6132
|
+
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;
|
|
6039
6133
|
if (moveOptions.spin.enable) {
|
|
6040
6134
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6041
6135
|
}
|
|
@@ -6045,18 +6139,18 @@
|
|
|
6045
6139
|
applyDistance(particle);
|
|
6046
6140
|
}
|
|
6047
6141
|
preInit() {
|
|
6048
|
-
return this
|
|
6142
|
+
return this.#init();
|
|
6049
6143
|
}
|
|
6050
6144
|
redrawInit() {
|
|
6051
|
-
return this
|
|
6145
|
+
return this.#init();
|
|
6052
6146
|
}
|
|
6053
6147
|
update() {
|
|
6054
6148
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6055
6149
|
pathGenerator.update();
|
|
6056
6150
|
}
|
|
6057
6151
|
}
|
|
6058
|
-
async
|
|
6059
|
-
const availablePathGenerators = await this.
|
|
6152
|
+
async #init() {
|
|
6153
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6060
6154
|
if (!availablePathGenerators) {
|
|
6061
6155
|
return;
|
|
6062
6156
|
}
|