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