@tsparticles/preset-matrix 4.0.5 → 4.1.1
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.
|
|
2
|
+
/* Preset v4.1.1 */
|
|
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.
|
|
999
|
+
return "4.1.1";
|
|
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.
|
|
2792
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2829
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2877
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2930
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2954
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3061
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3408
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3479
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3534
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3633
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3642
|
+
engine.checkVersion("4.1.1");
|
|
3626
3643
|
await engine.pluginManager.register(async (e) => {
|
|
3627
3644
|
await Promise.all([
|
|
3628
3645
|
loadBlendPlugin(e),
|
|
@@ -3854,7 +3871,7 @@
|
|
|
3854
3871
|
}
|
|
3855
3872
|
|
|
3856
3873
|
async function loadMatrixShape(engine) {
|
|
3857
|
-
engine.checkVersion("4.
|
|
3874
|
+
engine.checkVersion("4.1.1");
|
|
3858
3875
|
await engine.pluginManager.register(e => {
|
|
3859
3876
|
e.pluginManager.addShape(["matrix"], () => Promise.resolve(new MatrixDrawer()));
|
|
3860
3877
|
});
|
|
@@ -3914,7 +3931,7 @@
|
|
|
3914
3931
|
}
|
|
3915
3932
|
|
|
3916
3933
|
async function loadPoissonDiscPlugin(engine) {
|
|
3917
|
-
engine.checkVersion("4.
|
|
3934
|
+
engine.checkVersion("4.1.1");
|
|
3918
3935
|
await engine.pluginManager.register(e => {
|
|
3919
3936
|
e.pluginManager.addPlugin(new PoissonDiscPlugin());
|
|
3920
3937
|
});
|
|
@@ -3922,18 +3939,18 @@
|
|
|
3922
3939
|
|
|
3923
3940
|
const defaultShadowBlur = 0, defaultShadowOffsetValue = 0;
|
|
3924
3941
|
class ShadowDrawer {
|
|
3925
|
-
|
|
3926
|
-
|
|
3942
|
+
#container;
|
|
3943
|
+
#pluginManager;
|
|
3927
3944
|
constructor(pluginManager, container) {
|
|
3928
|
-
this
|
|
3929
|
-
this
|
|
3945
|
+
this.#pluginManager = pluginManager;
|
|
3946
|
+
this.#container = container;
|
|
3930
3947
|
}
|
|
3931
3948
|
drawAfter(data) {
|
|
3932
3949
|
const { context } = data;
|
|
3933
3950
|
context.restore();
|
|
3934
3951
|
}
|
|
3935
3952
|
drawBefore(data) {
|
|
3936
|
-
const { particle, context } = data,
|
|
3953
|
+
const { particle, context } = data, container = this.#container, shadowParticle = particle, shadowColor = shadowParticle.shadowColor, shadowOffset = shadowParticle.shadowOffset;
|
|
3937
3954
|
if (!shadowColor) {
|
|
3938
3955
|
return;
|
|
3939
3956
|
}
|
|
@@ -3945,14 +3962,14 @@
|
|
|
3945
3962
|
}
|
|
3946
3963
|
particleInit(_container, particle) {
|
|
3947
3964
|
const effectData = particle.effectData, shadowColor = OptionsColor.create(new OptionsColor(), effectData?.color);
|
|
3948
|
-
particle.shadowColor = rangeColorToRgb(this
|
|
3965
|
+
particle.shadowColor = rangeColorToRgb(this.#pluginManager, shadowColor);
|
|
3949
3966
|
particle.shadowBlur = effectData?.blur ?? defaultShadowBlur;
|
|
3950
3967
|
particle.shadowOffset = effectData?.offset ?? originPoint;
|
|
3951
3968
|
}
|
|
3952
3969
|
}
|
|
3953
3970
|
|
|
3954
3971
|
async function loadShadowEffect(engine) {
|
|
3955
|
-
engine.checkVersion("4.
|
|
3972
|
+
engine.checkVersion("4.1.1");
|
|
3956
3973
|
await engine.pluginManager.register(e => {
|
|
3957
3974
|
e.pluginManager.addEffect("shadow", container => {
|
|
3958
3975
|
return Promise.resolve(new ShadowDrawer(e.pluginManager, container));
|
|
@@ -4003,13 +4020,13 @@
|
|
|
4003
4020
|
|
|
4004
4021
|
class TrailPlugin {
|
|
4005
4022
|
id = "trail";
|
|
4006
|
-
|
|
4023
|
+
#pluginManager;
|
|
4007
4024
|
constructor(pluginManager) {
|
|
4008
|
-
this
|
|
4025
|
+
this.#pluginManager = pluginManager;
|
|
4009
4026
|
}
|
|
4010
4027
|
async getPlugin(container) {
|
|
4011
4028
|
const { TrailPluginInstance } = await Promise.resolve().then(function () { return TrailPluginInstance$1; });
|
|
4012
|
-
return new TrailPluginInstance(this
|
|
4029
|
+
return new TrailPluginInstance(this.#pluginManager, container);
|
|
4013
4030
|
}
|
|
4014
4031
|
loadOptions(_container, options, source) {
|
|
4015
4032
|
if (!this.needsPlugin()) {
|
|
@@ -4027,7 +4044,7 @@
|
|
|
4027
4044
|
}
|
|
4028
4045
|
|
|
4029
4046
|
async function loadTrailPlugin(engine) {
|
|
4030
|
-
engine.checkVersion("4.
|
|
4047
|
+
engine.checkVersion("4.1.1");
|
|
4031
4048
|
await engine.pluginManager.register(e => {
|
|
4032
4049
|
e.pluginManager.addPlugin(new TrailPlugin(e.pluginManager));
|
|
4033
4050
|
});
|
|
@@ -4137,58 +4154,58 @@
|
|
|
4137
4154
|
}
|
|
4138
4155
|
}
|
|
4139
4156
|
class RenderManager {
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4157
|
+
#canvasClearPlugins;
|
|
4158
|
+
#canvasManager;
|
|
4159
|
+
#canvasPaintPlugins;
|
|
4160
|
+
#clearDrawPlugins;
|
|
4161
|
+
#colorPlugins;
|
|
4162
|
+
#container;
|
|
4163
|
+
#context;
|
|
4164
|
+
#contextSettings;
|
|
4165
|
+
#drawParticlePlugins;
|
|
4166
|
+
#drawParticlesCleanupPlugins;
|
|
4167
|
+
#drawParticlesSetupPlugins;
|
|
4168
|
+
#drawPlugins;
|
|
4169
|
+
#drawSettingsCleanupPlugins;
|
|
4170
|
+
#drawSettingsSetupPlugins;
|
|
4171
|
+
#pluginManager;
|
|
4172
|
+
#postDrawUpdaters;
|
|
4173
|
+
#preDrawUpdaters;
|
|
4174
|
+
#reusableColorStyles = {};
|
|
4175
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4176
|
+
#reusableTransform = {};
|
|
4160
4177
|
constructor(pluginManager, container, canvasManager) {
|
|
4161
|
-
this
|
|
4162
|
-
this
|
|
4163
|
-
this
|
|
4164
|
-
this
|
|
4165
|
-
this
|
|
4166
|
-
this
|
|
4167
|
-
this
|
|
4168
|
-
this
|
|
4169
|
-
this
|
|
4170
|
-
this
|
|
4171
|
-
this
|
|
4172
|
-
this
|
|
4173
|
-
this
|
|
4174
|
-
this
|
|
4175
|
-
this
|
|
4176
|
-
this
|
|
4178
|
+
this.#pluginManager = pluginManager;
|
|
4179
|
+
this.#container = container;
|
|
4180
|
+
this.#canvasManager = canvasManager;
|
|
4181
|
+
this.#context = null;
|
|
4182
|
+
this.#preDrawUpdaters = [];
|
|
4183
|
+
this.#postDrawUpdaters = [];
|
|
4184
|
+
this.#colorPlugins = [];
|
|
4185
|
+
this.#canvasClearPlugins = [];
|
|
4186
|
+
this.#canvasPaintPlugins = [];
|
|
4187
|
+
this.#clearDrawPlugins = [];
|
|
4188
|
+
this.#drawParticlePlugins = [];
|
|
4189
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4190
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4191
|
+
this.#drawPlugins = [];
|
|
4192
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4193
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4177
4194
|
}
|
|
4178
4195
|
get settings() {
|
|
4179
|
-
return this
|
|
4196
|
+
return this.#contextSettings;
|
|
4180
4197
|
}
|
|
4181
4198
|
canvasClear() {
|
|
4182
|
-
if (!this.
|
|
4199
|
+
if (!this.#container.actualOptions.clear) {
|
|
4183
4200
|
return;
|
|
4184
4201
|
}
|
|
4185
4202
|
this.draw(ctx => {
|
|
4186
|
-
clear(ctx, this.
|
|
4203
|
+
clear(ctx, this.#canvasManager.size);
|
|
4187
4204
|
});
|
|
4188
4205
|
}
|
|
4189
4206
|
clear() {
|
|
4190
4207
|
let pluginHandled = false;
|
|
4191
|
-
for (const plugin of this
|
|
4208
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4192
4209
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4193
4210
|
if (pluginHandled) {
|
|
4194
4211
|
break;
|
|
@@ -4201,21 +4218,21 @@
|
|
|
4201
4218
|
}
|
|
4202
4219
|
destroy() {
|
|
4203
4220
|
this.stop();
|
|
4204
|
-
this
|
|
4205
|
-
this
|
|
4206
|
-
this
|
|
4207
|
-
this
|
|
4208
|
-
this
|
|
4209
|
-
this
|
|
4210
|
-
this
|
|
4211
|
-
this
|
|
4212
|
-
this
|
|
4213
|
-
this
|
|
4214
|
-
this
|
|
4215
|
-
this
|
|
4221
|
+
this.#preDrawUpdaters = [];
|
|
4222
|
+
this.#postDrawUpdaters = [];
|
|
4223
|
+
this.#colorPlugins = [];
|
|
4224
|
+
this.#canvasClearPlugins = [];
|
|
4225
|
+
this.#canvasPaintPlugins = [];
|
|
4226
|
+
this.#clearDrawPlugins = [];
|
|
4227
|
+
this.#drawParticlePlugins = [];
|
|
4228
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4229
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4230
|
+
this.#drawPlugins = [];
|
|
4231
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4232
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4216
4233
|
}
|
|
4217
4234
|
draw(cb) {
|
|
4218
|
-
const ctx = this
|
|
4235
|
+
const ctx = this.#context;
|
|
4219
4236
|
if (!ctx) {
|
|
4220
4237
|
return;
|
|
4221
4238
|
}
|
|
@@ -4230,21 +4247,21 @@
|
|
|
4230
4247
|
return;
|
|
4231
4248
|
}
|
|
4232
4249
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4233
|
-
let [fColor, sColor] = this
|
|
4250
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4234
4251
|
fColor ??= pfColor;
|
|
4235
4252
|
sColor ??= psColor;
|
|
4236
4253
|
if (!fColor && !sColor) {
|
|
4237
4254
|
return;
|
|
4238
4255
|
}
|
|
4239
|
-
const container = this
|
|
4256
|
+
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;
|
|
4240
4257
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4241
4258
|
colorStyles.fill = fill;
|
|
4242
4259
|
colorStyles.stroke = stroke;
|
|
4243
4260
|
this.draw((context) => {
|
|
4244
|
-
for (const plugin of this
|
|
4261
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4245
4262
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4246
4263
|
}
|
|
4247
|
-
this
|
|
4264
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4248
4265
|
drawParticle({
|
|
4249
4266
|
container,
|
|
4250
4267
|
context,
|
|
@@ -4255,35 +4272,35 @@
|
|
|
4255
4272
|
opacity: opacity,
|
|
4256
4273
|
transform,
|
|
4257
4274
|
});
|
|
4258
|
-
this
|
|
4259
|
-
for (const plugin of this
|
|
4275
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4276
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4260
4277
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4261
4278
|
}
|
|
4262
4279
|
});
|
|
4263
4280
|
}
|
|
4264
4281
|
drawParticlePlugins(particle, delta) {
|
|
4265
4282
|
this.draw(ctx => {
|
|
4266
|
-
for (const plugin of this
|
|
4283
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4267
4284
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4268
4285
|
}
|
|
4269
4286
|
});
|
|
4270
4287
|
}
|
|
4271
4288
|
drawParticles(delta) {
|
|
4272
|
-
const { particles } = this
|
|
4289
|
+
const { particles } = this.#container;
|
|
4273
4290
|
this.clear();
|
|
4274
4291
|
particles.update(delta);
|
|
4275
4292
|
this.draw(ctx => {
|
|
4276
|
-
for (const plugin of this
|
|
4293
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4277
4294
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4278
4295
|
}
|
|
4279
|
-
for (const plugin of this
|
|
4296
|
+
for (const plugin of this.#drawPlugins) {
|
|
4280
4297
|
plugin.draw?.(ctx, delta);
|
|
4281
4298
|
}
|
|
4282
4299
|
particles.drawParticles(delta);
|
|
4283
|
-
for (const plugin of this
|
|
4300
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4284
4301
|
plugin.clearDraw?.(ctx, delta);
|
|
4285
4302
|
}
|
|
4286
|
-
for (const plugin of this
|
|
4303
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4287
4304
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4288
4305
|
}
|
|
4289
4306
|
});
|
|
@@ -4294,64 +4311,64 @@
|
|
|
4294
4311
|
this.paint();
|
|
4295
4312
|
}
|
|
4296
4313
|
initPlugins() {
|
|
4297
|
-
this
|
|
4298
|
-
this
|
|
4299
|
-
this
|
|
4300
|
-
this
|
|
4301
|
-
this
|
|
4302
|
-
this
|
|
4303
|
-
this
|
|
4304
|
-
this
|
|
4305
|
-
this
|
|
4306
|
-
this
|
|
4307
|
-
for (const plugin of this.
|
|
4314
|
+
this.#colorPlugins = [];
|
|
4315
|
+
this.#canvasClearPlugins = [];
|
|
4316
|
+
this.#canvasPaintPlugins = [];
|
|
4317
|
+
this.#clearDrawPlugins = [];
|
|
4318
|
+
this.#drawParticlePlugins = [];
|
|
4319
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4320
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4321
|
+
this.#drawPlugins = [];
|
|
4322
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4323
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4324
|
+
for (const plugin of this.#container.plugins) {
|
|
4308
4325
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4309
|
-
this.
|
|
4326
|
+
this.#colorPlugins.push(plugin);
|
|
4310
4327
|
}
|
|
4311
4328
|
if (plugin.canvasClear) {
|
|
4312
|
-
this.
|
|
4329
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4313
4330
|
}
|
|
4314
4331
|
if (plugin.canvasPaint) {
|
|
4315
|
-
this.
|
|
4332
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4316
4333
|
}
|
|
4317
4334
|
if (plugin.drawParticle) {
|
|
4318
|
-
this.
|
|
4335
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4319
4336
|
}
|
|
4320
4337
|
if (plugin.drawParticleSetup) {
|
|
4321
|
-
this.
|
|
4338
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4322
4339
|
}
|
|
4323
4340
|
if (plugin.drawParticleCleanup) {
|
|
4324
|
-
this.
|
|
4341
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4325
4342
|
}
|
|
4326
4343
|
if (plugin.draw) {
|
|
4327
|
-
this.
|
|
4344
|
+
this.#drawPlugins.push(plugin);
|
|
4328
4345
|
}
|
|
4329
4346
|
if (plugin.drawSettingsSetup) {
|
|
4330
|
-
this.
|
|
4347
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4331
4348
|
}
|
|
4332
4349
|
if (plugin.drawSettingsCleanup) {
|
|
4333
|
-
this.
|
|
4350
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4334
4351
|
}
|
|
4335
4352
|
if (plugin.clearDraw) {
|
|
4336
|
-
this.
|
|
4353
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4337
4354
|
}
|
|
4338
4355
|
}
|
|
4339
4356
|
}
|
|
4340
4357
|
initUpdaters() {
|
|
4341
|
-
this
|
|
4342
|
-
this
|
|
4343
|
-
for (const updater of this.
|
|
4358
|
+
this.#preDrawUpdaters = [];
|
|
4359
|
+
this.#postDrawUpdaters = [];
|
|
4360
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4344
4361
|
if (updater.afterDraw) {
|
|
4345
|
-
this.
|
|
4362
|
+
this.#postDrawUpdaters.push(updater);
|
|
4346
4363
|
}
|
|
4347
4364
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4348
|
-
this.
|
|
4365
|
+
this.#preDrawUpdaters.push(updater);
|
|
4349
4366
|
}
|
|
4350
4367
|
}
|
|
4351
4368
|
}
|
|
4352
4369
|
paint() {
|
|
4353
4370
|
let handled = false;
|
|
4354
|
-
for (const plugin of this
|
|
4371
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4355
4372
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4356
4373
|
if (handled) {
|
|
4357
4374
|
break;
|
|
@@ -4364,35 +4381,35 @@
|
|
|
4364
4381
|
}
|
|
4365
4382
|
paintBase(baseColor) {
|
|
4366
4383
|
this.draw(ctx => {
|
|
4367
|
-
paintBase(ctx, this.
|
|
4384
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4368
4385
|
});
|
|
4369
4386
|
}
|
|
4370
4387
|
paintImage(image, opacity) {
|
|
4371
4388
|
this.draw(ctx => {
|
|
4372
|
-
paintImage(ctx, this.
|
|
4389
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4373
4390
|
});
|
|
4374
4391
|
}
|
|
4375
4392
|
setContext(context) {
|
|
4376
|
-
this
|
|
4377
|
-
if (this
|
|
4378
|
-
this.
|
|
4393
|
+
this.#context = context;
|
|
4394
|
+
if (this.#context) {
|
|
4395
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4379
4396
|
}
|
|
4380
4397
|
}
|
|
4381
4398
|
setContextSettings(settings) {
|
|
4382
|
-
this
|
|
4399
|
+
this.#contextSettings = settings;
|
|
4383
4400
|
}
|
|
4384
4401
|
stop() {
|
|
4385
4402
|
this.draw(ctx => {
|
|
4386
|
-
clear(ctx, this.
|
|
4403
|
+
clear(ctx, this.#canvasManager.size);
|
|
4387
4404
|
});
|
|
4388
4405
|
}
|
|
4389
|
-
|
|
4390
|
-
for (const updater of this
|
|
4406
|
+
#applyPostDrawUpdaters = particle => {
|
|
4407
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4391
4408
|
updater.afterDraw?.(particle);
|
|
4392
4409
|
}
|
|
4393
4410
|
};
|
|
4394
|
-
|
|
4395
|
-
for (const updater of this
|
|
4411
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4412
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4396
4413
|
if (updater.getColorStyles) {
|
|
4397
4414
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4398
4415
|
if (fill) {
|
|
@@ -4411,22 +4428,22 @@
|
|
|
4411
4428
|
updater.beforeDraw?.(particle);
|
|
4412
4429
|
}
|
|
4413
4430
|
};
|
|
4414
|
-
|
|
4431
|
+
#getPluginParticleColors = particle => {
|
|
4415
4432
|
let fColor, sColor;
|
|
4416
|
-
for (const plugin of this
|
|
4433
|
+
for (const plugin of this.#colorPlugins) {
|
|
4417
4434
|
if (!fColor && plugin.particleFillColor) {
|
|
4418
|
-
fColor = rangeColorToHsl(this
|
|
4435
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4419
4436
|
}
|
|
4420
4437
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4421
|
-
sColor = rangeColorToHsl(this
|
|
4438
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4422
4439
|
}
|
|
4423
4440
|
if (fColor && sColor) {
|
|
4424
4441
|
break;
|
|
4425
4442
|
}
|
|
4426
4443
|
}
|
|
4427
|
-
this
|
|
4428
|
-
this
|
|
4429
|
-
return this
|
|
4444
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4445
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4446
|
+
return this.#reusablePluginColors;
|
|
4430
4447
|
};
|
|
4431
4448
|
}
|
|
4432
4449
|
|
|
@@ -4484,53 +4501,53 @@
|
|
|
4484
4501
|
renderCanvas;
|
|
4485
4502
|
size;
|
|
4486
4503
|
zoom = defaultZoom;
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4504
|
+
#container;
|
|
4505
|
+
#generated;
|
|
4506
|
+
#mutationObserver;
|
|
4507
|
+
#originalStyle;
|
|
4508
|
+
#pluginManager;
|
|
4509
|
+
#pointerEvents;
|
|
4510
|
+
#resizePlugins;
|
|
4511
|
+
#standardSize;
|
|
4512
|
+
#zoomCenter;
|
|
4496
4513
|
constructor(pluginManager, container) {
|
|
4497
|
-
this
|
|
4498
|
-
this
|
|
4514
|
+
this.#pluginManager = pluginManager;
|
|
4515
|
+
this.#container = container;
|
|
4499
4516
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4500
|
-
this
|
|
4517
|
+
this.#standardSize = {
|
|
4501
4518
|
height: 0,
|
|
4502
4519
|
width: 0,
|
|
4503
4520
|
};
|
|
4504
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4521
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4505
4522
|
this.size = {
|
|
4506
4523
|
height: stdSize.height * pxRatio,
|
|
4507
4524
|
width: stdSize.width * pxRatio,
|
|
4508
4525
|
};
|
|
4509
|
-
this
|
|
4510
|
-
this
|
|
4511
|
-
this
|
|
4526
|
+
this.#generated = false;
|
|
4527
|
+
this.#resizePlugins = [];
|
|
4528
|
+
this.#pointerEvents = "none";
|
|
4512
4529
|
}
|
|
4513
|
-
get
|
|
4514
|
-
return this.
|
|
4530
|
+
get #fullScreen() {
|
|
4531
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4515
4532
|
}
|
|
4516
4533
|
destroy() {
|
|
4517
4534
|
this.stop();
|
|
4518
|
-
if (this
|
|
4535
|
+
if (this.#generated) {
|
|
4519
4536
|
const element = this.domElement;
|
|
4520
4537
|
element?.remove();
|
|
4521
4538
|
this.domElement = undefined;
|
|
4522
4539
|
this.renderCanvas = undefined;
|
|
4523
4540
|
}
|
|
4524
4541
|
else {
|
|
4525
|
-
this
|
|
4542
|
+
this.#resetOriginalStyle();
|
|
4526
4543
|
}
|
|
4527
4544
|
this.render.destroy();
|
|
4528
|
-
this
|
|
4545
|
+
this.#resizePlugins = [];
|
|
4529
4546
|
}
|
|
4530
4547
|
getZoomCenter() {
|
|
4531
|
-
const pxRatio = this.
|
|
4532
|
-
if (this
|
|
4533
|
-
return this
|
|
4548
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4549
|
+
if (this.#zoomCenter) {
|
|
4550
|
+
return this.#zoomCenter;
|
|
4534
4551
|
}
|
|
4535
4552
|
return {
|
|
4536
4553
|
x: (width * half) / pxRatio,
|
|
@@ -4538,20 +4555,20 @@
|
|
|
4538
4555
|
};
|
|
4539
4556
|
}
|
|
4540
4557
|
init() {
|
|
4541
|
-
this
|
|
4558
|
+
this.#safeMutationObserver(obs => {
|
|
4542
4559
|
obs.disconnect();
|
|
4543
4560
|
});
|
|
4544
|
-
this
|
|
4561
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4545
4562
|
for (const record of records) {
|
|
4546
4563
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4547
|
-
this
|
|
4564
|
+
this.#repairStyle();
|
|
4548
4565
|
}
|
|
4549
4566
|
}
|
|
4550
4567
|
});
|
|
4551
4568
|
this.resize();
|
|
4552
|
-
this
|
|
4569
|
+
this.#initStyle();
|
|
4553
4570
|
this.initBackground();
|
|
4554
|
-
this
|
|
4571
|
+
this.#safeMutationObserver(obs => {
|
|
4555
4572
|
const element = this.domElement;
|
|
4556
4573
|
if (!element || !(element instanceof Node)) {
|
|
4557
4574
|
return;
|
|
@@ -4562,13 +4579,13 @@
|
|
|
4562
4579
|
this.render.init();
|
|
4563
4580
|
}
|
|
4564
4581
|
initBackground() {
|
|
4565
|
-
const
|
|
4582
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4566
4583
|
if (!element) {
|
|
4567
4584
|
return;
|
|
4568
4585
|
}
|
|
4569
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4586
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4570
4587
|
if (color) {
|
|
4571
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4588
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4572
4589
|
}
|
|
4573
4590
|
else {
|
|
4574
4591
|
elementStyle.backgroundColor = "";
|
|
@@ -4579,27 +4596,27 @@
|
|
|
4579
4596
|
elementStyle.backgroundSize = background.size || "";
|
|
4580
4597
|
}
|
|
4581
4598
|
initPlugins() {
|
|
4582
|
-
this
|
|
4583
|
-
for (const plugin of this.
|
|
4599
|
+
this.#resizePlugins = [];
|
|
4600
|
+
for (const plugin of this.#container.plugins) {
|
|
4584
4601
|
if (plugin.resize) {
|
|
4585
|
-
this.
|
|
4602
|
+
this.#resizePlugins.push(plugin);
|
|
4586
4603
|
}
|
|
4587
4604
|
}
|
|
4588
4605
|
}
|
|
4589
4606
|
loadCanvas(canvas) {
|
|
4590
|
-
if (this
|
|
4607
|
+
if (this.#generated && this.domElement) {
|
|
4591
4608
|
this.domElement.remove();
|
|
4592
4609
|
}
|
|
4593
|
-
const container = this
|
|
4610
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4594
4611
|
this.domElement = domCanvas;
|
|
4595
|
-
this
|
|
4612
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4596
4613
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4597
4614
|
const domElement = this.domElement;
|
|
4598
4615
|
if (domElement) {
|
|
4599
4616
|
domElement.ariaHidden = "true";
|
|
4600
|
-
this
|
|
4617
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4601
4618
|
}
|
|
4602
|
-
const standardSize = this
|
|
4619
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4603
4620
|
if (domElement) {
|
|
4604
4621
|
standardSize.height = domElement.offsetHeight;
|
|
4605
4622
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4608,7 +4625,7 @@
|
|
|
4608
4625
|
standardSize.height = renderCanvas.height;
|
|
4609
4626
|
standardSize.width = renderCanvas.width;
|
|
4610
4627
|
}
|
|
4611
|
-
const pxRatio = this.
|
|
4628
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4612
4629
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4613
4630
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4614
4631
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4619,12 +4636,12 @@
|
|
|
4619
4636
|
willReadFrequently: false,
|
|
4620
4637
|
});
|
|
4621
4638
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4622
|
-
this
|
|
4639
|
+
this.#safeMutationObserver(obs => {
|
|
4623
4640
|
obs.disconnect();
|
|
4624
4641
|
});
|
|
4625
4642
|
container.retina.init();
|
|
4626
4643
|
this.initBackground();
|
|
4627
|
-
this
|
|
4644
|
+
this.#safeMutationObserver(obs => {
|
|
4628
4645
|
const element = this.domElement;
|
|
4629
4646
|
if (!element || !(element instanceof Node)) {
|
|
4630
4647
|
return;
|
|
@@ -4637,11 +4654,11 @@
|
|
|
4637
4654
|
if (!element) {
|
|
4638
4655
|
return false;
|
|
4639
4656
|
}
|
|
4640
|
-
const container = this
|
|
4657
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4641
4658
|
if (renderCanvas === undefined) {
|
|
4642
4659
|
return false;
|
|
4643
4660
|
}
|
|
4644
|
-
const currentSize = container.canvas
|
|
4661
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4645
4662
|
width: element.offsetWidth,
|
|
4646
4663
|
height: element.offsetHeight,
|
|
4647
4664
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4660,7 +4677,7 @@
|
|
|
4660
4677
|
const canvasSize = this.size;
|
|
4661
4678
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4662
4679
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4663
|
-
if (this.
|
|
4680
|
+
if (this.#container.started) {
|
|
4664
4681
|
container.particles.setResizeFactor({
|
|
4665
4682
|
width: currentSize.width / oldSize.width,
|
|
4666
4683
|
height: currentSize.height / oldSize.height,
|
|
@@ -4673,46 +4690,46 @@
|
|
|
4673
4690
|
if (!element) {
|
|
4674
4691
|
return;
|
|
4675
4692
|
}
|
|
4676
|
-
this
|
|
4677
|
-
this
|
|
4693
|
+
this.#pointerEvents = type;
|
|
4694
|
+
this.#repairStyle();
|
|
4678
4695
|
}
|
|
4679
4696
|
setZoom(zoomLevel, center) {
|
|
4680
4697
|
this.zoom = zoomLevel;
|
|
4681
|
-
this
|
|
4698
|
+
this.#zoomCenter = center;
|
|
4682
4699
|
}
|
|
4683
4700
|
stop() {
|
|
4684
|
-
this
|
|
4701
|
+
this.#safeMutationObserver(obs => {
|
|
4685
4702
|
obs.disconnect();
|
|
4686
4703
|
});
|
|
4687
|
-
this
|
|
4704
|
+
this.#mutationObserver = undefined;
|
|
4688
4705
|
this.render.stop();
|
|
4689
4706
|
}
|
|
4690
4707
|
async windowResize() {
|
|
4691
4708
|
if (!this.domElement || !this.resize()) {
|
|
4692
4709
|
return;
|
|
4693
4710
|
}
|
|
4694
|
-
const container = this
|
|
4711
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4695
4712
|
container.particles.setDensity();
|
|
4696
|
-
this
|
|
4713
|
+
this.#applyResizePlugins();
|
|
4697
4714
|
if (needsRefresh) {
|
|
4698
4715
|
await container.refresh();
|
|
4699
4716
|
}
|
|
4700
4717
|
}
|
|
4701
|
-
|
|
4702
|
-
for (const plugin of this
|
|
4718
|
+
#applyResizePlugins = () => {
|
|
4719
|
+
for (const plugin of this.#resizePlugins) {
|
|
4703
4720
|
plugin.resize?.();
|
|
4704
4721
|
}
|
|
4705
4722
|
};
|
|
4706
|
-
|
|
4707
|
-
const element = this.domElement, options = this.
|
|
4723
|
+
#initStyle = () => {
|
|
4724
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4708
4725
|
if (!element) {
|
|
4709
4726
|
return;
|
|
4710
4727
|
}
|
|
4711
|
-
if (this
|
|
4712
|
-
this
|
|
4728
|
+
if (this.#fullScreen) {
|
|
4729
|
+
this.#setFullScreenStyle();
|
|
4713
4730
|
}
|
|
4714
4731
|
else {
|
|
4715
|
-
this
|
|
4732
|
+
this.#resetOriginalStyle();
|
|
4716
4733
|
}
|
|
4717
4734
|
for (const key in options.style) {
|
|
4718
4735
|
if (!key || !(key in options.style)) {
|
|
@@ -4725,72 +4742,72 @@
|
|
|
4725
4742
|
element.style.setProperty(key, value, "important");
|
|
4726
4743
|
}
|
|
4727
4744
|
};
|
|
4728
|
-
|
|
4745
|
+
#repairStyle = () => {
|
|
4729
4746
|
const element = this.domElement;
|
|
4730
4747
|
if (!element) {
|
|
4731
4748
|
return;
|
|
4732
4749
|
}
|
|
4733
|
-
this
|
|
4750
|
+
this.#safeMutationObserver(observer => {
|
|
4734
4751
|
observer.disconnect();
|
|
4735
4752
|
});
|
|
4736
|
-
this
|
|
4753
|
+
this.#initStyle();
|
|
4737
4754
|
this.initBackground();
|
|
4738
|
-
const pointerEvents = this
|
|
4755
|
+
const pointerEvents = this.#pointerEvents;
|
|
4739
4756
|
element.style.pointerEvents = pointerEvents;
|
|
4740
4757
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4741
|
-
this
|
|
4758
|
+
this.#safeMutationObserver(observer => {
|
|
4742
4759
|
if (!(element instanceof Node)) {
|
|
4743
4760
|
return;
|
|
4744
4761
|
}
|
|
4745
4762
|
observer.observe(element, { attributes: true });
|
|
4746
4763
|
});
|
|
4747
4764
|
};
|
|
4748
|
-
|
|
4749
|
-
const element = this.domElement, originalStyle = this
|
|
4765
|
+
#resetOriginalStyle = () => {
|
|
4766
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4750
4767
|
if (!element || !originalStyle) {
|
|
4751
4768
|
return;
|
|
4752
4769
|
}
|
|
4753
4770
|
setStyle(element, originalStyle, true);
|
|
4754
4771
|
};
|
|
4755
|
-
|
|
4756
|
-
if (!this
|
|
4772
|
+
#safeMutationObserver = callback => {
|
|
4773
|
+
if (!this.#mutationObserver) {
|
|
4757
4774
|
return;
|
|
4758
4775
|
}
|
|
4759
|
-
callback(this
|
|
4776
|
+
callback(this.#mutationObserver);
|
|
4760
4777
|
};
|
|
4761
|
-
|
|
4778
|
+
#setFullScreenStyle = () => {
|
|
4762
4779
|
const element = this.domElement;
|
|
4763
4780
|
if (!element) {
|
|
4764
4781
|
return;
|
|
4765
4782
|
}
|
|
4766
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4783
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4767
4784
|
};
|
|
4768
4785
|
}
|
|
4769
4786
|
|
|
4770
4787
|
class EventListeners {
|
|
4771
|
-
container;
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4788
|
+
#container;
|
|
4789
|
+
#handlers;
|
|
4790
|
+
#resizeObserver;
|
|
4791
|
+
#resizeTimeout;
|
|
4775
4792
|
constructor(container) {
|
|
4776
|
-
this
|
|
4777
|
-
this
|
|
4793
|
+
this.#container = container;
|
|
4794
|
+
this.#handlers = {
|
|
4778
4795
|
visibilityChange: () => {
|
|
4779
|
-
this
|
|
4796
|
+
this.#handleVisibilityChange();
|
|
4780
4797
|
},
|
|
4781
4798
|
resize: () => {
|
|
4782
|
-
this
|
|
4799
|
+
this.#handleWindowResize();
|
|
4783
4800
|
},
|
|
4784
4801
|
};
|
|
4785
4802
|
}
|
|
4786
4803
|
addListeners() {
|
|
4787
|
-
this
|
|
4804
|
+
this.#manageListeners(true);
|
|
4788
4805
|
}
|
|
4789
4806
|
removeListeners() {
|
|
4790
|
-
this
|
|
4807
|
+
this.#manageListeners(false);
|
|
4791
4808
|
}
|
|
4792
|
-
|
|
4793
|
-
const container = this
|
|
4809
|
+
#handleVisibilityChange = () => {
|
|
4810
|
+
const container = this.#container, options = container.actualOptions;
|
|
4794
4811
|
if (!options.pauseOnBlur) {
|
|
4795
4812
|
return;
|
|
4796
4813
|
}
|
|
@@ -4808,24 +4825,24 @@
|
|
|
4808
4825
|
}
|
|
4809
4826
|
}
|
|
4810
4827
|
};
|
|
4811
|
-
|
|
4812
|
-
if (this
|
|
4813
|
-
clearTimeout(this
|
|
4814
|
-
|
|
4828
|
+
#handleWindowResize = () => {
|
|
4829
|
+
if (this.#resizeTimeout) {
|
|
4830
|
+
clearTimeout(this.#resizeTimeout);
|
|
4831
|
+
this.#resizeTimeout = undefined;
|
|
4815
4832
|
}
|
|
4816
4833
|
const handleResize = async () => {
|
|
4817
|
-
const canvas = this
|
|
4834
|
+
const canvas = this.#container.canvas;
|
|
4818
4835
|
await canvas.windowResize();
|
|
4819
4836
|
};
|
|
4820
|
-
this
|
|
4837
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4821
4838
|
};
|
|
4822
|
-
|
|
4823
|
-
const handlers = this
|
|
4824
|
-
this
|
|
4839
|
+
#manageListeners = add => {
|
|
4840
|
+
const handlers = this.#handlers;
|
|
4841
|
+
this.#manageResize(add);
|
|
4825
4842
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
4826
4843
|
};
|
|
4827
|
-
|
|
4828
|
-
const handlers = this
|
|
4844
|
+
#manageResize = add => {
|
|
4845
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
4829
4846
|
if (!options.resize.enable) {
|
|
4830
4847
|
return;
|
|
4831
4848
|
}
|
|
@@ -4834,22 +4851,22 @@
|
|
|
4834
4851
|
return;
|
|
4835
4852
|
}
|
|
4836
4853
|
const canvasEl = container.canvas.domElement;
|
|
4837
|
-
if (this
|
|
4854
|
+
if (this.#resizeObserver && !add) {
|
|
4838
4855
|
if (canvasEl) {
|
|
4839
|
-
this.
|
|
4856
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
4840
4857
|
}
|
|
4841
|
-
this.
|
|
4842
|
-
|
|
4858
|
+
this.#resizeObserver.disconnect();
|
|
4859
|
+
this.#resizeObserver = undefined;
|
|
4843
4860
|
}
|
|
4844
|
-
else if (!this
|
|
4845
|
-
this
|
|
4861
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4862
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4846
4863
|
const entry = entries.find(e => e.target === canvasEl);
|
|
4847
4864
|
if (!entry) {
|
|
4848
4865
|
return;
|
|
4849
4866
|
}
|
|
4850
|
-
this
|
|
4867
|
+
this.#handleWindowResize();
|
|
4851
4868
|
});
|
|
4852
|
-
this.
|
|
4869
|
+
this.#resizeObserver.observe(canvasEl);
|
|
4853
4870
|
}
|
|
4854
4871
|
};
|
|
4855
4872
|
}
|
|
@@ -4922,24 +4939,24 @@
|
|
|
4922
4939
|
unbreakable;
|
|
4923
4940
|
velocity;
|
|
4924
4941
|
zIndexFactor;
|
|
4925
|
-
|
|
4942
|
+
#cachedOpacityData = {
|
|
4926
4943
|
fillOpacity: defaultOpacity$1,
|
|
4927
4944
|
opacity: defaultOpacity$1,
|
|
4928
4945
|
strokeOpacity: defaultOpacity$1,
|
|
4929
4946
|
};
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4947
|
+
#cachedPosition = Vector3d.origin;
|
|
4948
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
4949
|
+
#cachedTransform = {
|
|
4933
4950
|
a: 1,
|
|
4934
4951
|
b: 0,
|
|
4935
4952
|
c: 0,
|
|
4936
4953
|
d: 1,
|
|
4937
4954
|
};
|
|
4938
|
-
|
|
4939
|
-
|
|
4955
|
+
#container;
|
|
4956
|
+
#pluginManager;
|
|
4940
4957
|
constructor(pluginManager, container) {
|
|
4941
|
-
this
|
|
4942
|
-
this
|
|
4958
|
+
this.#pluginManager = pluginManager;
|
|
4959
|
+
this.#container = container;
|
|
4943
4960
|
}
|
|
4944
4961
|
destroy(override) {
|
|
4945
4962
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -4948,7 +4965,7 @@
|
|
|
4948
4965
|
this.destroyed = true;
|
|
4949
4966
|
this.bubble.inRange = false;
|
|
4950
4967
|
this.slow.inRange = false;
|
|
4951
|
-
const container = this
|
|
4968
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
4952
4969
|
shapeDrawer?.particleDestroy?.(this);
|
|
4953
4970
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
4954
4971
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -4956,12 +4973,12 @@
|
|
|
4956
4973
|
for (const updater of container.particleUpdaters) {
|
|
4957
4974
|
updater.particleDestroyed?.(this, override);
|
|
4958
4975
|
}
|
|
4959
|
-
this.
|
|
4976
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
4960
4977
|
particle: this,
|
|
4961
4978
|
});
|
|
4962
4979
|
}
|
|
4963
4980
|
draw(delta) {
|
|
4964
|
-
const container = this
|
|
4981
|
+
const container = this.#container, render = container.canvas.render;
|
|
4965
4982
|
render.drawParticlePlugins(this, delta);
|
|
4966
4983
|
render.drawParticle(this, delta);
|
|
4967
4984
|
}
|
|
@@ -4969,50 +4986,50 @@
|
|
|
4969
4986
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
4970
4987
|
}
|
|
4971
4988
|
getFillColor() {
|
|
4972
|
-
return this
|
|
4989
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
4973
4990
|
}
|
|
4974
4991
|
getMass() {
|
|
4975
4992
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
4976
4993
|
}
|
|
4977
4994
|
getOpacity() {
|
|
4978
4995
|
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;
|
|
4979
|
-
this.
|
|
4980
|
-
this.
|
|
4981
|
-
this.
|
|
4982
|
-
return this
|
|
4996
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
4997
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
4998
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
4999
|
+
return this.#cachedOpacityData;
|
|
4983
5000
|
}
|
|
4984
5001
|
getPosition() {
|
|
4985
|
-
this.
|
|
4986
|
-
this.
|
|
4987
|
-
this.
|
|
4988
|
-
return this
|
|
5002
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5003
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5004
|
+
this.#cachedPosition.z = this.position.z;
|
|
5005
|
+
return this.#cachedPosition;
|
|
4989
5006
|
}
|
|
4990
5007
|
getRadius() {
|
|
4991
5008
|
return this.bubble.radius ?? this.size.value;
|
|
4992
5009
|
}
|
|
4993
5010
|
getRotateData() {
|
|
4994
5011
|
const angle = this.getAngle();
|
|
4995
|
-
this.
|
|
4996
|
-
this.
|
|
4997
|
-
return this
|
|
5012
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5013
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5014
|
+
return this.#cachedRotateData;
|
|
4998
5015
|
}
|
|
4999
5016
|
getStrokeColor() {
|
|
5000
|
-
return this
|
|
5017
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5001
5018
|
}
|
|
5002
5019
|
getTransformData(externalTransform) {
|
|
5003
5020
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5004
|
-
this.
|
|
5005
|
-
this.
|
|
5021
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5022
|
+
this.#cachedTransform.b = rotating
|
|
5006
5023
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
5007
5024
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5008
|
-
this.
|
|
5025
|
+
this.#cachedTransform.c = rotating
|
|
5009
5026
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
5010
5027
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5011
|
-
this.
|
|
5012
|
-
return this
|
|
5028
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5029
|
+
return this.#cachedTransform;
|
|
5013
5030
|
}
|
|
5014
5031
|
init(id, position, overrideOptions, group) {
|
|
5015
|
-
const container = this
|
|
5032
|
+
const container = this.#container;
|
|
5016
5033
|
this.id = id;
|
|
5017
5034
|
this.group = group;
|
|
5018
5035
|
this.justWarped = false;
|
|
@@ -5032,21 +5049,27 @@
|
|
|
5032
5049
|
moveSpeed: 0,
|
|
5033
5050
|
sizeAnimationSpeed: 0,
|
|
5034
5051
|
};
|
|
5052
|
+
this.size = {
|
|
5053
|
+
value: 1,
|
|
5054
|
+
max: 1,
|
|
5055
|
+
min: 1,
|
|
5056
|
+
enable: false,
|
|
5057
|
+
};
|
|
5035
5058
|
this.outType = ParticleOutType.normal;
|
|
5036
5059
|
this.ignoresResizeRatio = true;
|
|
5037
|
-
const
|
|
5060
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5038
5061
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5039
5062
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5040
5063
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5041
5064
|
if (overrideOptions) {
|
|
5042
|
-
if (overrideOptions.effect?.type) {
|
|
5065
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5043
5066
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5044
5067
|
if (effect) {
|
|
5045
5068
|
this.effect = effect;
|
|
5046
5069
|
effectOptions.load(overrideOptions.effect);
|
|
5047
5070
|
}
|
|
5048
5071
|
}
|
|
5049
|
-
if (overrideOptions.shape?.type) {
|
|
5072
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5050
5073
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5051
5074
|
if (shape) {
|
|
5052
5075
|
this.shape = shape;
|
|
@@ -5055,21 +5078,20 @@
|
|
|
5055
5078
|
}
|
|
5056
5079
|
}
|
|
5057
5080
|
if (this.effect === randomColorValue) {
|
|
5058
|
-
const availableEffects = [...this.
|
|
5081
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5059
5082
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5060
5083
|
}
|
|
5061
5084
|
if (this.shape === randomColorValue) {
|
|
5062
|
-
const availableShapes = [...this.
|
|
5085
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5063
5086
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5064
5087
|
}
|
|
5065
5088
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5066
5089
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5067
5090
|
particlesOptions.load(overrideOptions);
|
|
5068
|
-
const effectData = this.effectData;
|
|
5091
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5069
5092
|
if (effectData) {
|
|
5070
5093
|
particlesOptions.load(effectData.particles);
|
|
5071
5094
|
}
|
|
5072
|
-
const shapeData = this.shapeData;
|
|
5073
5095
|
if (shapeData) {
|
|
5074
5096
|
particlesOptions.load(shapeData.particles);
|
|
5075
5097
|
}
|
|
@@ -5077,7 +5099,9 @@
|
|
|
5077
5099
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5078
5100
|
this.options = particlesOptions;
|
|
5079
5101
|
container.retina.initParticle(this);
|
|
5080
|
-
|
|
5102
|
+
for (const updater of container.particleUpdaters) {
|
|
5103
|
+
updater.preInit?.(this);
|
|
5104
|
+
}
|
|
5081
5105
|
this.bubble = {
|
|
5082
5106
|
inRange: false,
|
|
5083
5107
|
};
|
|
@@ -5085,8 +5109,8 @@
|
|
|
5085
5109
|
inRange: false,
|
|
5086
5110
|
factor: 1,
|
|
5087
5111
|
};
|
|
5088
|
-
this
|
|
5089
|
-
this.initialVelocity = this
|
|
5112
|
+
this.#initPosition(position);
|
|
5113
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5090
5114
|
this.velocity = this.initialVelocity.copy();
|
|
5091
5115
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5092
5116
|
this.sides = 24;
|
|
@@ -5117,12 +5141,11 @@
|
|
|
5117
5141
|
plugin.particleCreated?.(this);
|
|
5118
5142
|
}
|
|
5119
5143
|
}
|
|
5120
|
-
isInsideCanvas() {
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
position.x <= canvasSize.width + radius);
|
|
5144
|
+
isInsideCanvas(direction) {
|
|
5145
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5146
|
+
}
|
|
5147
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5148
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5126
5149
|
}
|
|
5127
5150
|
isShowingBack() {
|
|
5128
5151
|
if (!this.roll) {
|
|
@@ -5147,13 +5170,13 @@
|
|
|
5147
5170
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5148
5171
|
}
|
|
5149
5172
|
reset() {
|
|
5150
|
-
for (const updater of this.
|
|
5173
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5151
5174
|
updater.reset?.(this);
|
|
5152
5175
|
}
|
|
5153
5176
|
}
|
|
5154
|
-
|
|
5177
|
+
#calcPosition = (position, zIndex) => {
|
|
5155
5178
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5156
|
-
const container = this
|
|
5179
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5157
5180
|
while (!signal.aborted) {
|
|
5158
5181
|
for (const plugin of plugins) {
|
|
5159
5182
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5165,10 +5188,10 @@
|
|
|
5165
5188
|
size: canvasSize,
|
|
5166
5189
|
position: posVec,
|
|
5167
5190
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5168
|
-
this
|
|
5169
|
-
this
|
|
5170
|
-
this
|
|
5171
|
-
this
|
|
5191
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5192
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5193
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5194
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5172
5195
|
let isValidPosition = true;
|
|
5173
5196
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5174
5197
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5184,8 +5207,8 @@
|
|
|
5184
5207
|
}
|
|
5185
5208
|
return posVec;
|
|
5186
5209
|
};
|
|
5187
|
-
|
|
5188
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5210
|
+
#calculateVelocity = () => {
|
|
5211
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5189
5212
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5190
5213
|
return res;
|
|
5191
5214
|
}
|
|
@@ -5201,27 +5224,86 @@
|
|
|
5201
5224
|
}
|
|
5202
5225
|
return res;
|
|
5203
5226
|
};
|
|
5204
|
-
|
|
5227
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5205
5228
|
fixOutMode({
|
|
5206
5229
|
outMode,
|
|
5207
5230
|
checkModes: [OutMode.bounce],
|
|
5208
5231
|
coord: pos.x,
|
|
5209
|
-
maxCoord: this.
|
|
5232
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5210
5233
|
setCb: (value) => (pos.x += value),
|
|
5211
5234
|
radius,
|
|
5212
5235
|
});
|
|
5213
5236
|
};
|
|
5214
|
-
|
|
5237
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5215
5238
|
fixOutMode({
|
|
5216
5239
|
outMode,
|
|
5217
5240
|
checkModes: [OutMode.bounce],
|
|
5218
5241
|
coord: pos.y,
|
|
5219
|
-
maxCoord: this.
|
|
5242
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5220
5243
|
setCb: (value) => (pos.y += value),
|
|
5221
5244
|
radius,
|
|
5222
5245
|
});
|
|
5223
5246
|
};
|
|
5224
|
-
|
|
5247
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5248
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5249
|
+
if (direction === OutModeDirection.bottom) {
|
|
5250
|
+
return {
|
|
5251
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5252
|
+
reason: "default",
|
|
5253
|
+
};
|
|
5254
|
+
}
|
|
5255
|
+
if (direction === OutModeDirection.left) {
|
|
5256
|
+
return {
|
|
5257
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5258
|
+
reason: "default",
|
|
5259
|
+
};
|
|
5260
|
+
}
|
|
5261
|
+
if (direction === OutModeDirection.right) {
|
|
5262
|
+
return {
|
|
5263
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5264
|
+
reason: "default",
|
|
5265
|
+
};
|
|
5266
|
+
}
|
|
5267
|
+
if (direction === OutModeDirection.top) {
|
|
5268
|
+
return {
|
|
5269
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5270
|
+
reason: "default",
|
|
5271
|
+
};
|
|
5272
|
+
}
|
|
5273
|
+
return {
|
|
5274
|
+
inside: position.x >= -radius &&
|
|
5275
|
+
position.y >= -radius &&
|
|
5276
|
+
position.y <= canvasSize.height + radius &&
|
|
5277
|
+
position.x <= canvasSize.width + radius,
|
|
5278
|
+
reason: "default",
|
|
5279
|
+
};
|
|
5280
|
+
};
|
|
5281
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5282
|
+
return {
|
|
5283
|
+
canvasSize: this.#container.canvas.size,
|
|
5284
|
+
direction,
|
|
5285
|
+
outMode,
|
|
5286
|
+
particle: this,
|
|
5287
|
+
radius: this.getRadius(),
|
|
5288
|
+
};
|
|
5289
|
+
};
|
|
5290
|
+
#getInsideCanvasResult = (data) => {
|
|
5291
|
+
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;
|
|
5292
|
+
if (!shapeCheck && !effectCheck) {
|
|
5293
|
+
return defaultResult;
|
|
5294
|
+
}
|
|
5295
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5296
|
+
if (shapeResult && effectResult) {
|
|
5297
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5298
|
+
return {
|
|
5299
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5300
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5301
|
+
reason: "combined",
|
|
5302
|
+
};
|
|
5303
|
+
}
|
|
5304
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5305
|
+
};
|
|
5306
|
+
#getRollColor = color => {
|
|
5225
5307
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5226
5308
|
return color;
|
|
5227
5309
|
}
|
|
@@ -5236,8 +5318,8 @@
|
|
|
5236
5318
|
}
|
|
5237
5319
|
return color;
|
|
5238
5320
|
};
|
|
5239
|
-
|
|
5240
|
-
const container = this
|
|
5321
|
+
#initPosition = position => {
|
|
5322
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5241
5323
|
if (!initialPosition) {
|
|
5242
5324
|
throw new Error("a valid position cannot be found for particle");
|
|
5243
5325
|
}
|
|
@@ -5260,45 +5342,58 @@
|
|
|
5260
5342
|
}
|
|
5261
5343
|
this.offset = Vector.origin;
|
|
5262
5344
|
};
|
|
5345
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5346
|
+
if (typeof result === "boolean") {
|
|
5347
|
+
return {
|
|
5348
|
+
inside: result,
|
|
5349
|
+
reason,
|
|
5350
|
+
};
|
|
5351
|
+
}
|
|
5352
|
+
return {
|
|
5353
|
+
inside: result.inside,
|
|
5354
|
+
margin: result.margin,
|
|
5355
|
+
reason: result.reason ?? reason,
|
|
5356
|
+
};
|
|
5357
|
+
};
|
|
5263
5358
|
}
|
|
5264
5359
|
|
|
5265
5360
|
class SpatialHashGrid {
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5361
|
+
#cellSize;
|
|
5362
|
+
#cells = new Map();
|
|
5363
|
+
#circlePool = [];
|
|
5364
|
+
#circlePoolIdx;
|
|
5365
|
+
#pendingCellSize;
|
|
5366
|
+
#rectanglePool = [];
|
|
5367
|
+
#rectanglePoolIdx;
|
|
5273
5368
|
constructor(cellSize) {
|
|
5274
|
-
this
|
|
5275
|
-
this
|
|
5276
|
-
this
|
|
5369
|
+
this.#cellSize = cellSize;
|
|
5370
|
+
this.#circlePoolIdx = 0;
|
|
5371
|
+
this.#rectanglePoolIdx = 0;
|
|
5277
5372
|
}
|
|
5278
5373
|
clear() {
|
|
5279
|
-
this.
|
|
5280
|
-
const pendingCellSize = this
|
|
5374
|
+
this.#cells.clear();
|
|
5375
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5281
5376
|
if (pendingCellSize) {
|
|
5282
|
-
this
|
|
5377
|
+
this.#cellSize = pendingCellSize;
|
|
5283
5378
|
}
|
|
5284
|
-
this
|
|
5379
|
+
this.#pendingCellSize = undefined;
|
|
5285
5380
|
}
|
|
5286
5381
|
insert(particle) {
|
|
5287
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5288
|
-
if (!this.
|
|
5289
|
-
this.
|
|
5382
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5383
|
+
if (!this.#cells.has(key)) {
|
|
5384
|
+
this.#cells.set(key, []);
|
|
5290
5385
|
}
|
|
5291
|
-
this.
|
|
5386
|
+
this.#cells.get(key)?.push(particle);
|
|
5292
5387
|
}
|
|
5293
5388
|
query(range, check, out = []) {
|
|
5294
|
-
const bounds = this
|
|
5389
|
+
const bounds = this.#getRangeBounds(range);
|
|
5295
5390
|
if (!bounds) {
|
|
5296
5391
|
return out;
|
|
5297
5392
|
}
|
|
5298
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5393
|
+
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);
|
|
5299
5394
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5300
5395
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5301
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5396
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5302
5397
|
if (!cellParticles) {
|
|
5303
5398
|
continue;
|
|
5304
5399
|
}
|
|
@@ -5315,29 +5410,29 @@
|
|
|
5315
5410
|
return out;
|
|
5316
5411
|
}
|
|
5317
5412
|
queryCircle(position, radius, check, out = []) {
|
|
5318
|
-
const circle = this
|
|
5319
|
-
this
|
|
5413
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5414
|
+
this.#releaseShapes();
|
|
5320
5415
|
return result;
|
|
5321
5416
|
}
|
|
5322
5417
|
queryRectangle(position, size, check, out = []) {
|
|
5323
|
-
const rect = this
|
|
5324
|
-
this
|
|
5418
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5419
|
+
this.#releaseShapes();
|
|
5325
5420
|
return result;
|
|
5326
5421
|
}
|
|
5327
5422
|
setCellSize(cellSize) {
|
|
5328
|
-
this
|
|
5423
|
+
this.#pendingCellSize = cellSize;
|
|
5329
5424
|
}
|
|
5330
|
-
|
|
5331
|
-
return (this
|
|
5425
|
+
#acquireCircle(x, y, r) {
|
|
5426
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5332
5427
|
}
|
|
5333
|
-
|
|
5334
|
-
return (this
|
|
5428
|
+
#acquireRectangle(x, y, w, h) {
|
|
5429
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5335
5430
|
}
|
|
5336
|
-
|
|
5337
|
-
const cellX = Math.floor(x / this
|
|
5431
|
+
#cellKeyFromCoords(x, y) {
|
|
5432
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5338
5433
|
return `${cellX}_${cellY}`;
|
|
5339
5434
|
}
|
|
5340
|
-
|
|
5435
|
+
#getRangeBounds(range) {
|
|
5341
5436
|
if (range instanceof Circle) {
|
|
5342
5437
|
const r = range.radius, { x, y } = range.position;
|
|
5343
5438
|
return {
|
|
@@ -5358,53 +5453,53 @@
|
|
|
5358
5453
|
}
|
|
5359
5454
|
return null;
|
|
5360
5455
|
}
|
|
5361
|
-
|
|
5362
|
-
this
|
|
5363
|
-
this
|
|
5456
|
+
#releaseShapes() {
|
|
5457
|
+
this.#circlePoolIdx = 0;
|
|
5458
|
+
this.#rectanglePoolIdx = 0;
|
|
5364
5459
|
}
|
|
5365
5460
|
}
|
|
5366
5461
|
|
|
5367
5462
|
class ParticlesManager {
|
|
5368
5463
|
checkParticlePositionPlugins;
|
|
5369
5464
|
grid;
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5465
|
+
#array;
|
|
5466
|
+
#container;
|
|
5467
|
+
#groupLimits;
|
|
5468
|
+
#limit;
|
|
5469
|
+
#nextId;
|
|
5470
|
+
#particleBuckets;
|
|
5471
|
+
#particleResetPlugins;
|
|
5472
|
+
#particleUpdatePlugins;
|
|
5473
|
+
#pluginManager;
|
|
5474
|
+
#pool;
|
|
5475
|
+
#postParticleUpdatePlugins;
|
|
5476
|
+
#postUpdatePlugins;
|
|
5477
|
+
#resizeFactor;
|
|
5478
|
+
#updatePlugins;
|
|
5479
|
+
#zBuckets;
|
|
5385
5480
|
constructor(pluginManager, container) {
|
|
5386
|
-
this
|
|
5387
|
-
this
|
|
5388
|
-
this
|
|
5389
|
-
this
|
|
5390
|
-
this
|
|
5391
|
-
this
|
|
5392
|
-
this
|
|
5393
|
-
this
|
|
5394
|
-
this
|
|
5481
|
+
this.#pluginManager = pluginManager;
|
|
5482
|
+
this.#container = container;
|
|
5483
|
+
this.#nextId = 0;
|
|
5484
|
+
this.#array = [];
|
|
5485
|
+
this.#pool = [];
|
|
5486
|
+
this.#limit = 0;
|
|
5487
|
+
this.#groupLimits = new Map();
|
|
5488
|
+
this.#particleBuckets = new Map();
|
|
5489
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5395
5490
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5396
5491
|
this.checkParticlePositionPlugins = [];
|
|
5397
|
-
this
|
|
5398
|
-
this
|
|
5399
|
-
this
|
|
5400
|
-
this
|
|
5401
|
-
this
|
|
5492
|
+
this.#particleResetPlugins = [];
|
|
5493
|
+
this.#particleUpdatePlugins = [];
|
|
5494
|
+
this.#postUpdatePlugins = [];
|
|
5495
|
+
this.#postParticleUpdatePlugins = [];
|
|
5496
|
+
this.#updatePlugins = [];
|
|
5402
5497
|
}
|
|
5403
5498
|
get count() {
|
|
5404
|
-
return this.
|
|
5499
|
+
return this.#array.length;
|
|
5405
5500
|
}
|
|
5406
5501
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5407
|
-
const limitMode = this.
|
|
5502
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5408
5503
|
if (limit > minLimit) {
|
|
5409
5504
|
switch (limitMode) {
|
|
5410
5505
|
case LimitMode.delete: {
|
|
@@ -5422,20 +5517,20 @@
|
|
|
5422
5517
|
}
|
|
5423
5518
|
}
|
|
5424
5519
|
try {
|
|
5425
|
-
const particle = this.
|
|
5426
|
-
particle.init(this
|
|
5520
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5521
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5427
5522
|
let canAdd = true;
|
|
5428
5523
|
if (initializer) {
|
|
5429
5524
|
canAdd = initializer(particle);
|
|
5430
5525
|
}
|
|
5431
5526
|
if (!canAdd) {
|
|
5432
|
-
this.
|
|
5527
|
+
this.#pool.push(particle);
|
|
5433
5528
|
return;
|
|
5434
5529
|
}
|
|
5435
|
-
this.
|
|
5436
|
-
this
|
|
5437
|
-
this
|
|
5438
|
-
this.
|
|
5530
|
+
this.#array.push(particle);
|
|
5531
|
+
this.#insertParticleIntoBucket(particle);
|
|
5532
|
+
this.#nextId++;
|
|
5533
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5439
5534
|
particle,
|
|
5440
5535
|
});
|
|
5441
5536
|
return particle;
|
|
@@ -5446,25 +5541,25 @@
|
|
|
5446
5541
|
return undefined;
|
|
5447
5542
|
}
|
|
5448
5543
|
clear() {
|
|
5449
|
-
this
|
|
5450
|
-
this.
|
|
5451
|
-
this
|
|
5544
|
+
this.#array = [];
|
|
5545
|
+
this.#particleBuckets.clear();
|
|
5546
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5452
5547
|
}
|
|
5453
5548
|
destroy() {
|
|
5454
|
-
this
|
|
5455
|
-
this.
|
|
5456
|
-
this.
|
|
5457
|
-
this
|
|
5549
|
+
this.#array = [];
|
|
5550
|
+
this.#pool.length = 0;
|
|
5551
|
+
this.#particleBuckets.clear();
|
|
5552
|
+
this.#zBuckets = [];
|
|
5458
5553
|
this.checkParticlePositionPlugins = [];
|
|
5459
|
-
this
|
|
5460
|
-
this
|
|
5461
|
-
this
|
|
5462
|
-
this
|
|
5463
|
-
this
|
|
5554
|
+
this.#particleResetPlugins = [];
|
|
5555
|
+
this.#particleUpdatePlugins = [];
|
|
5556
|
+
this.#postUpdatePlugins = [];
|
|
5557
|
+
this.#postParticleUpdatePlugins = [];
|
|
5558
|
+
this.#updatePlugins = [];
|
|
5464
5559
|
}
|
|
5465
5560
|
drawParticles(delta) {
|
|
5466
|
-
for (let i = this.
|
|
5467
|
-
const bucket = this
|
|
5561
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5562
|
+
const bucket = this.#zBuckets[i];
|
|
5468
5563
|
if (!bucket) {
|
|
5469
5564
|
continue;
|
|
5470
5565
|
}
|
|
@@ -5474,24 +5569,24 @@
|
|
|
5474
5569
|
}
|
|
5475
5570
|
}
|
|
5476
5571
|
filter(condition) {
|
|
5477
|
-
return this.
|
|
5572
|
+
return this.#array.filter(condition);
|
|
5478
5573
|
}
|
|
5479
5574
|
find(condition) {
|
|
5480
|
-
return this.
|
|
5575
|
+
return this.#array.find(condition);
|
|
5481
5576
|
}
|
|
5482
5577
|
get(index) {
|
|
5483
|
-
return this
|
|
5578
|
+
return this.#array[index];
|
|
5484
5579
|
}
|
|
5485
5580
|
async init() {
|
|
5486
|
-
const container = this
|
|
5581
|
+
const container = this.#container, options = container.actualOptions;
|
|
5487
5582
|
this.checkParticlePositionPlugins = [];
|
|
5488
|
-
this
|
|
5489
|
-
this
|
|
5490
|
-
this
|
|
5491
|
-
this
|
|
5492
|
-
this
|
|
5493
|
-
this.
|
|
5494
|
-
this
|
|
5583
|
+
this.#updatePlugins = [];
|
|
5584
|
+
this.#particleUpdatePlugins = [];
|
|
5585
|
+
this.#postUpdatePlugins = [];
|
|
5586
|
+
this.#particleResetPlugins = [];
|
|
5587
|
+
this.#postParticleUpdatePlugins = [];
|
|
5588
|
+
this.#particleBuckets.clear();
|
|
5589
|
+
this.#resetBuckets(container.zLayers);
|
|
5495
5590
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5496
5591
|
for (const plugin of container.plugins) {
|
|
5497
5592
|
if (plugin.redrawInit) {
|
|
@@ -5501,26 +5596,26 @@
|
|
|
5501
5596
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5502
5597
|
}
|
|
5503
5598
|
if (plugin.update) {
|
|
5504
|
-
this.
|
|
5599
|
+
this.#updatePlugins.push(plugin);
|
|
5505
5600
|
}
|
|
5506
5601
|
if (plugin.particleUpdate) {
|
|
5507
|
-
this.
|
|
5602
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5508
5603
|
}
|
|
5509
5604
|
if (plugin.postUpdate) {
|
|
5510
|
-
this.
|
|
5605
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5511
5606
|
}
|
|
5512
5607
|
if (plugin.particleReset) {
|
|
5513
|
-
this.
|
|
5608
|
+
this.#particleResetPlugins.push(plugin);
|
|
5514
5609
|
}
|
|
5515
5610
|
if (plugin.postParticleUpdate) {
|
|
5516
|
-
this.
|
|
5611
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5517
5612
|
}
|
|
5518
5613
|
}
|
|
5519
|
-
await this.
|
|
5520
|
-
for (const drawer of this.
|
|
5614
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5615
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5521
5616
|
await drawer.init?.(container);
|
|
5522
5617
|
}
|
|
5523
|
-
for (const drawer of this.
|
|
5618
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5524
5619
|
await drawer.init?.(container);
|
|
5525
5620
|
}
|
|
5526
5621
|
let handled = false;
|
|
@@ -5554,10 +5649,10 @@
|
|
|
5554
5649
|
async redraw() {
|
|
5555
5650
|
this.clear();
|
|
5556
5651
|
await this.init();
|
|
5557
|
-
this.
|
|
5652
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5558
5653
|
}
|
|
5559
5654
|
remove(particle, group, override) {
|
|
5560
|
-
this.removeAt(this.
|
|
5655
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5561
5656
|
}
|
|
5562
5657
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5563
5658
|
if (index < minIndex || index > this.count) {
|
|
@@ -5565,7 +5660,7 @@
|
|
|
5565
5660
|
}
|
|
5566
5661
|
let deleted = 0;
|
|
5567
5662
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5568
|
-
if (this
|
|
5663
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5569
5664
|
i--;
|
|
5570
5665
|
deleted++;
|
|
5571
5666
|
}
|
|
@@ -5575,9 +5670,9 @@
|
|
|
5575
5670
|
this.removeAt(minIndex, quantity, group);
|
|
5576
5671
|
}
|
|
5577
5672
|
setDensity() {
|
|
5578
|
-
const options = this.
|
|
5673
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5579
5674
|
let pluginsCount = 0;
|
|
5580
|
-
for (const plugin of this.
|
|
5675
|
+
for (const plugin of this.#container.plugins) {
|
|
5581
5676
|
if (plugin.particlesDensityCount) {
|
|
5582
5677
|
pluginsCount += plugin.particlesDensityCount();
|
|
5583
5678
|
}
|
|
@@ -5587,51 +5682,51 @@
|
|
|
5587
5682
|
if (!groupData) {
|
|
5588
5683
|
continue;
|
|
5589
5684
|
}
|
|
5590
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5591
|
-
this
|
|
5685
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5686
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5592
5687
|
}
|
|
5593
|
-
this
|
|
5688
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5594
5689
|
}
|
|
5595
5690
|
setResizeFactor(factor) {
|
|
5596
|
-
this
|
|
5691
|
+
this.#resizeFactor = factor;
|
|
5597
5692
|
}
|
|
5598
5693
|
update(delta) {
|
|
5599
5694
|
this.grid.clear();
|
|
5600
|
-
for (const plugin of this
|
|
5695
|
+
for (const plugin of this.#updatePlugins) {
|
|
5601
5696
|
plugin.update?.(delta);
|
|
5602
5697
|
}
|
|
5603
|
-
const particlesToDelete = this
|
|
5604
|
-
for (const plugin of this
|
|
5698
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5699
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5605
5700
|
plugin.postUpdate?.(delta);
|
|
5606
5701
|
}
|
|
5607
|
-
this
|
|
5702
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5608
5703
|
if (particlesToDelete.size) {
|
|
5609
5704
|
for (const particle of particlesToDelete) {
|
|
5610
5705
|
this.remove(particle);
|
|
5611
5706
|
}
|
|
5612
5707
|
}
|
|
5613
|
-
|
|
5708
|
+
this.#resizeFactor = undefined;
|
|
5614
5709
|
}
|
|
5615
|
-
|
|
5616
|
-
this.
|
|
5710
|
+
#addToPool = (...particles) => {
|
|
5711
|
+
this.#pool.push(...particles);
|
|
5617
5712
|
};
|
|
5618
|
-
|
|
5713
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5619
5714
|
const numberOptions = options.number;
|
|
5620
5715
|
if (!numberOptions.density.enable) {
|
|
5621
5716
|
if (group === undefined) {
|
|
5622
|
-
this
|
|
5717
|
+
this.#limit = numberOptions.limit.value;
|
|
5623
5718
|
}
|
|
5624
5719
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5625
|
-
this.
|
|
5720
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5626
5721
|
}
|
|
5627
5722
|
return;
|
|
5628
5723
|
}
|
|
5629
|
-
const densityFactor = this
|
|
5724
|
+
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);
|
|
5630
5725
|
if (group === undefined) {
|
|
5631
|
-
this
|
|
5726
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5632
5727
|
}
|
|
5633
5728
|
else {
|
|
5634
|
-
this.
|
|
5729
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5635
5730
|
}
|
|
5636
5731
|
if (particlesCount < particlesNumber) {
|
|
5637
5732
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5640,18 +5735,18 @@
|
|
|
5640
5735
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5641
5736
|
}
|
|
5642
5737
|
};
|
|
5643
|
-
|
|
5738
|
+
#createBuckets = (zLayers) => {
|
|
5644
5739
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5645
5740
|
return Array.from({ length: bucketCount }, () => []);
|
|
5646
5741
|
};
|
|
5647
|
-
|
|
5648
|
-
const maxBucketIndex = this.
|
|
5742
|
+
#getBucketIndex = (zIndex) => {
|
|
5743
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5649
5744
|
if (maxBucketIndex <= minIndex) {
|
|
5650
5745
|
return minIndex;
|
|
5651
5746
|
}
|
|
5652
5747
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5653
5748
|
};
|
|
5654
|
-
|
|
5749
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5655
5750
|
let start = minIndex, end = bucket.length;
|
|
5656
5751
|
while (start < end) {
|
|
5657
5752
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5668,8 +5763,8 @@
|
|
|
5668
5763
|
}
|
|
5669
5764
|
return start;
|
|
5670
5765
|
};
|
|
5671
|
-
|
|
5672
|
-
const container = this
|
|
5766
|
+
#initDensityFactor = densityOptions => {
|
|
5767
|
+
const container = this.#container;
|
|
5673
5768
|
if (!densityOptions.enable) {
|
|
5674
5769
|
return defaultDensityFactor;
|
|
5675
5770
|
}
|
|
@@ -5679,82 +5774,82 @@
|
|
|
5679
5774
|
}
|
|
5680
5775
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5681
5776
|
};
|
|
5682
|
-
|
|
5683
|
-
const bucketIndex = this
|
|
5777
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5778
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5684
5779
|
if (!bucket) {
|
|
5685
5780
|
return;
|
|
5686
5781
|
}
|
|
5687
|
-
bucket.splice(this
|
|
5688
|
-
this.
|
|
5782
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5783
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5689
5784
|
};
|
|
5690
|
-
|
|
5691
|
-
const particle = this
|
|
5785
|
+
#removeParticle = (index, group, override) => {
|
|
5786
|
+
const particle = this.#array[index];
|
|
5692
5787
|
if (!particle) {
|
|
5693
5788
|
return false;
|
|
5694
5789
|
}
|
|
5695
5790
|
if (particle.group !== group) {
|
|
5696
5791
|
return false;
|
|
5697
5792
|
}
|
|
5698
|
-
this.
|
|
5699
|
-
this
|
|
5793
|
+
this.#array.splice(index, deleteCount);
|
|
5794
|
+
this.#removeParticleFromBucket(particle);
|
|
5700
5795
|
particle.destroy(override);
|
|
5701
|
-
this.
|
|
5796
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5702
5797
|
particle,
|
|
5703
5798
|
});
|
|
5704
|
-
this
|
|
5799
|
+
this.#addToPool(particle);
|
|
5705
5800
|
return true;
|
|
5706
5801
|
};
|
|
5707
|
-
|
|
5708
|
-
const bucketIndex = this.
|
|
5802
|
+
#removeParticleFromBucket = (particle) => {
|
|
5803
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5709
5804
|
if (!bucket) {
|
|
5710
|
-
this.
|
|
5805
|
+
this.#particleBuckets.delete(particle.id);
|
|
5711
5806
|
return;
|
|
5712
5807
|
}
|
|
5713
|
-
const particleIndex = this
|
|
5808
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5714
5809
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5715
|
-
this.
|
|
5810
|
+
this.#particleBuckets.delete(particle.id);
|
|
5716
5811
|
return;
|
|
5717
5812
|
}
|
|
5718
5813
|
bucket.splice(particleIndex, deleteCount);
|
|
5719
|
-
this.
|
|
5814
|
+
this.#particleBuckets.delete(particle.id);
|
|
5720
5815
|
};
|
|
5721
|
-
|
|
5816
|
+
#resetBuckets = (zLayers) => {
|
|
5722
5817
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5723
|
-
if (this.
|
|
5724
|
-
this
|
|
5818
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
5819
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5725
5820
|
return;
|
|
5726
5821
|
}
|
|
5727
|
-
for (const bucket of this
|
|
5822
|
+
for (const bucket of this.#zBuckets) {
|
|
5728
5823
|
bucket.length = minIndex;
|
|
5729
5824
|
}
|
|
5730
5825
|
};
|
|
5731
|
-
|
|
5732
|
-
const newBucketIndex = this
|
|
5826
|
+
#updateParticleBucket = (particle) => {
|
|
5827
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5733
5828
|
if (currentBucketIndex === undefined) {
|
|
5734
|
-
this
|
|
5829
|
+
this.#insertParticleIntoBucket(particle);
|
|
5735
5830
|
return;
|
|
5736
5831
|
}
|
|
5737
5832
|
if (currentBucketIndex === newBucketIndex) {
|
|
5738
5833
|
return;
|
|
5739
5834
|
}
|
|
5740
|
-
const currentBucket = this
|
|
5835
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5741
5836
|
if (currentBucket) {
|
|
5742
|
-
const particleIndex = this
|
|
5837
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5743
5838
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5744
5839
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5745
5840
|
}
|
|
5746
5841
|
}
|
|
5747
|
-
const newBucket = this
|
|
5842
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5748
5843
|
if (!newBucket) {
|
|
5749
|
-
this.
|
|
5844
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5750
5845
|
return;
|
|
5751
5846
|
}
|
|
5752
|
-
newBucket.splice(this
|
|
5753
|
-
this.
|
|
5847
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
5848
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5754
5849
|
};
|
|
5755
|
-
|
|
5756
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5757
|
-
for (const particle of this
|
|
5850
|
+
#updateParticlesPhase1 = (delta) => {
|
|
5851
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
5852
|
+
for (const particle of this.#array) {
|
|
5758
5853
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5759
5854
|
particle.position.x *= resizeFactor.width;
|
|
5760
5855
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5762,10 +5857,10 @@
|
|
|
5762
5857
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5763
5858
|
}
|
|
5764
5859
|
particle.ignoresResizeRatio = false;
|
|
5765
|
-
for (const plugin of this
|
|
5860
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5766
5861
|
plugin.particleReset?.(particle);
|
|
5767
5862
|
}
|
|
5768
|
-
for (const plugin of this
|
|
5863
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5769
5864
|
if (particle.destroyed) {
|
|
5770
5865
|
break;
|
|
5771
5866
|
}
|
|
@@ -5779,36 +5874,36 @@
|
|
|
5779
5874
|
}
|
|
5780
5875
|
return particlesToDelete;
|
|
5781
5876
|
};
|
|
5782
|
-
|
|
5783
|
-
for (const particle of this
|
|
5877
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
5878
|
+
for (const particle of this.#array) {
|
|
5784
5879
|
if (particle.destroyed) {
|
|
5785
5880
|
particlesToDelete.add(particle);
|
|
5786
5881
|
continue;
|
|
5787
5882
|
}
|
|
5788
|
-
for (const updater of this.
|
|
5883
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5789
5884
|
updater.update(particle, delta);
|
|
5790
5885
|
}
|
|
5791
5886
|
if (!particle.spawning) {
|
|
5792
|
-
for (const plugin of this
|
|
5887
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5793
5888
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5794
5889
|
}
|
|
5795
5890
|
}
|
|
5796
|
-
this
|
|
5891
|
+
this.#updateParticleBucket(particle);
|
|
5797
5892
|
}
|
|
5798
5893
|
};
|
|
5799
5894
|
}
|
|
5800
5895
|
|
|
5801
5896
|
class Retina {
|
|
5802
|
-
container;
|
|
5803
5897
|
pixelRatio;
|
|
5804
5898
|
reduceFactor;
|
|
5899
|
+
#container;
|
|
5805
5900
|
constructor(container) {
|
|
5806
|
-
this
|
|
5901
|
+
this.#container = container;
|
|
5807
5902
|
this.pixelRatio = defaultRatio;
|
|
5808
5903
|
this.reduceFactor = defaultReduceFactor;
|
|
5809
5904
|
}
|
|
5810
5905
|
init() {
|
|
5811
|
-
const container = this
|
|
5906
|
+
const container = this.#container, options = container.actualOptions;
|
|
5812
5907
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
5813
5908
|
this.reduceFactor = defaultReduceFactor;
|
|
5814
5909
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -5822,7 +5917,6 @@
|
|
|
5822
5917
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
5823
5918
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
5824
5919
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
5825
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
5826
5920
|
const maxDistance = props.maxDistance;
|
|
5827
5921
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
5828
5922
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -5860,73 +5954,73 @@
|
|
|
5860
5954
|
shapeDrawers;
|
|
5861
5955
|
started;
|
|
5862
5956
|
zLayers;
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5957
|
+
#delay;
|
|
5958
|
+
#delayTimeout;
|
|
5959
|
+
#delta = { value: 0, factor: 0 };
|
|
5960
|
+
#dispatchCallback;
|
|
5961
|
+
#drawAnimationFrame;
|
|
5962
|
+
#duration;
|
|
5963
|
+
#eventListeners;
|
|
5964
|
+
#firstStart;
|
|
5965
|
+
#initialSourceOptions;
|
|
5966
|
+
#lastFrameTime;
|
|
5967
|
+
#lifeTime;
|
|
5968
|
+
#onDestroy;
|
|
5969
|
+
#options;
|
|
5970
|
+
#paused;
|
|
5971
|
+
#pluginManager;
|
|
5972
|
+
#smooth;
|
|
5973
|
+
#sourceOptions;
|
|
5880
5974
|
constructor(params) {
|
|
5881
5975
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
5882
|
-
this
|
|
5883
|
-
this
|
|
5884
|
-
this
|
|
5976
|
+
this.#pluginManager = pluginManager;
|
|
5977
|
+
this.#dispatchCallback = dispatchCallback;
|
|
5978
|
+
this.#onDestroy = onDestroy;
|
|
5885
5979
|
this.id = Symbol(id);
|
|
5886
5980
|
this.fpsLimit = 120;
|
|
5887
5981
|
this.hdr = false;
|
|
5888
|
-
this
|
|
5889
|
-
this
|
|
5890
|
-
this
|
|
5891
|
-
this
|
|
5892
|
-
this
|
|
5982
|
+
this.#smooth = false;
|
|
5983
|
+
this.#delay = 0;
|
|
5984
|
+
this.#duration = 0;
|
|
5985
|
+
this.#lifeTime = 0;
|
|
5986
|
+
this.#firstStart = true;
|
|
5893
5987
|
this.started = false;
|
|
5894
5988
|
this.destroyed = false;
|
|
5895
|
-
this
|
|
5896
|
-
this
|
|
5989
|
+
this.#paused = true;
|
|
5990
|
+
this.#lastFrameTime = 0;
|
|
5897
5991
|
this.zLayers = 100;
|
|
5898
5992
|
this.pageHidden = false;
|
|
5899
|
-
this
|
|
5900
|
-
this
|
|
5993
|
+
this.#sourceOptions = sourceOptions;
|
|
5994
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5901
5995
|
this.effectDrawers = new Map();
|
|
5902
5996
|
this.shapeDrawers = new Map();
|
|
5903
5997
|
this.particleUpdaters = [];
|
|
5904
5998
|
this.retina = new Retina(this);
|
|
5905
|
-
this.canvas = new CanvasManager(this
|
|
5906
|
-
this.particles = new ParticlesManager(this
|
|
5999
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6000
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
5907
6001
|
this.plugins = [];
|
|
5908
6002
|
this.particleDestroyedPlugins = [];
|
|
5909
6003
|
this.particleCreatedPlugins = [];
|
|
5910
6004
|
this.particlePositionPlugins = [];
|
|
5911
|
-
this
|
|
5912
|
-
this.actualOptions = loadContainerOptions(this
|
|
5913
|
-
this
|
|
6005
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6006
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6007
|
+
this.#eventListeners = new EventListeners(this);
|
|
5914
6008
|
this.dispatchEvent(EventType.containerBuilt);
|
|
5915
6009
|
}
|
|
5916
6010
|
get animationStatus() {
|
|
5917
|
-
return !this
|
|
6011
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
5918
6012
|
}
|
|
5919
6013
|
get options() {
|
|
5920
|
-
return this
|
|
6014
|
+
return this.#options;
|
|
5921
6015
|
}
|
|
5922
6016
|
get sourceOptions() {
|
|
5923
|
-
return this
|
|
6017
|
+
return this.#sourceOptions;
|
|
5924
6018
|
}
|
|
5925
6019
|
addLifeTime(value) {
|
|
5926
|
-
this
|
|
6020
|
+
this.#lifeTime += value;
|
|
5927
6021
|
}
|
|
5928
6022
|
alive() {
|
|
5929
|
-
return !this
|
|
6023
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
5930
6024
|
}
|
|
5931
6025
|
destroy(remove = true) {
|
|
5932
6026
|
if (!guardCheck(this)) {
|
|
@@ -5948,13 +6042,13 @@
|
|
|
5948
6042
|
this.shapeDrawers = new Map();
|
|
5949
6043
|
this.particleUpdaters = [];
|
|
5950
6044
|
this.plugins.length = 0;
|
|
5951
|
-
this.
|
|
6045
|
+
this.#pluginManager.clearPlugins(this);
|
|
5952
6046
|
this.destroyed = true;
|
|
5953
|
-
this
|
|
6047
|
+
this.#onDestroy(remove);
|
|
5954
6048
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
5955
6049
|
}
|
|
5956
6050
|
dispatchEvent(type, data) {
|
|
5957
|
-
this
|
|
6051
|
+
this.#dispatchCallback(type, {
|
|
5958
6052
|
container: this,
|
|
5959
6053
|
data,
|
|
5960
6054
|
});
|
|
@@ -5964,12 +6058,12 @@
|
|
|
5964
6058
|
return;
|
|
5965
6059
|
}
|
|
5966
6060
|
let refreshTime = force;
|
|
5967
|
-
this
|
|
6061
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
5968
6062
|
if (refreshTime) {
|
|
5969
|
-
this
|
|
6063
|
+
this.#lastFrameTime = undefined;
|
|
5970
6064
|
refreshTime = false;
|
|
5971
6065
|
}
|
|
5972
|
-
this
|
|
6066
|
+
this.#nextFrame(timestamp);
|
|
5973
6067
|
});
|
|
5974
6068
|
}
|
|
5975
6069
|
async export(type, options = {}) {
|
|
@@ -5991,7 +6085,7 @@
|
|
|
5991
6085
|
return;
|
|
5992
6086
|
}
|
|
5993
6087
|
const allContainerPlugins = new Map();
|
|
5994
|
-
for (const plugin of this.
|
|
6088
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
5995
6089
|
const containerPlugin = await plugin.getPlugin(this);
|
|
5996
6090
|
if (containerPlugin.preInit) {
|
|
5997
6091
|
await containerPlugin.preInit();
|
|
@@ -5999,8 +6093,8 @@
|
|
|
5999
6093
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6000
6094
|
}
|
|
6001
6095
|
await this.initDrawersAndUpdaters();
|
|
6002
|
-
this
|
|
6003
|
-
this.actualOptions = loadContainerOptions(this
|
|
6096
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6097
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6004
6098
|
this.plugins.length = 0;
|
|
6005
6099
|
this.particleDestroyedPlugins.length = 0;
|
|
6006
6100
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6027,11 +6121,11 @@
|
|
|
6027
6121
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6028
6122
|
this.hdr = hdr;
|
|
6029
6123
|
this.zLayers = zLayers;
|
|
6030
|
-
this
|
|
6031
|
-
this
|
|
6032
|
-
this
|
|
6124
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6125
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6126
|
+
this.#lifeTime = 0;
|
|
6033
6127
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6034
|
-
this
|
|
6128
|
+
this.#smooth = smooth;
|
|
6035
6129
|
for (const plugin of this.plugins) {
|
|
6036
6130
|
await plugin.init?.();
|
|
6037
6131
|
}
|
|
@@ -6044,7 +6138,7 @@
|
|
|
6044
6138
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6045
6139
|
}
|
|
6046
6140
|
async initDrawersAndUpdaters() {
|
|
6047
|
-
const pluginManager = this
|
|
6141
|
+
const pluginManager = this.#pluginManager;
|
|
6048
6142
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6049
6143
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6050
6144
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6053,18 +6147,18 @@
|
|
|
6053
6147
|
if (!guardCheck(this)) {
|
|
6054
6148
|
return;
|
|
6055
6149
|
}
|
|
6056
|
-
if (this
|
|
6057
|
-
cancelAnimation(this
|
|
6058
|
-
|
|
6150
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6151
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6152
|
+
this.#drawAnimationFrame = undefined;
|
|
6059
6153
|
}
|
|
6060
|
-
if (this
|
|
6154
|
+
if (this.#paused) {
|
|
6061
6155
|
return;
|
|
6062
6156
|
}
|
|
6063
6157
|
for (const plugin of this.plugins) {
|
|
6064
6158
|
plugin.pause?.();
|
|
6065
6159
|
}
|
|
6066
6160
|
if (!this.pageHidden) {
|
|
6067
|
-
this
|
|
6161
|
+
this.#paused = true;
|
|
6068
6162
|
}
|
|
6069
6163
|
this.dispatchEvent(EventType.containerPaused);
|
|
6070
6164
|
}
|
|
@@ -6072,13 +6166,13 @@
|
|
|
6072
6166
|
if (!guardCheck(this)) {
|
|
6073
6167
|
return;
|
|
6074
6168
|
}
|
|
6075
|
-
const needsUpdate = this
|
|
6076
|
-
if (this
|
|
6077
|
-
this
|
|
6169
|
+
const needsUpdate = this.#paused || force;
|
|
6170
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6171
|
+
this.#firstStart = false;
|
|
6078
6172
|
return;
|
|
6079
6173
|
}
|
|
6080
|
-
if (this
|
|
6081
|
-
this
|
|
6174
|
+
if (this.#paused) {
|
|
6175
|
+
this.#paused = false;
|
|
6082
6176
|
}
|
|
6083
6177
|
if (needsUpdate) {
|
|
6084
6178
|
for (const plugin of this.plugins) {
|
|
@@ -6101,10 +6195,10 @@
|
|
|
6101
6195
|
if (!guardCheck(this)) {
|
|
6102
6196
|
return;
|
|
6103
6197
|
}
|
|
6104
|
-
this
|
|
6105
|
-
this
|
|
6106
|
-
this
|
|
6107
|
-
this.actualOptions = loadContainerOptions(this
|
|
6198
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6199
|
+
this.#sourceOptions = sourceOptions;
|
|
6200
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6201
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6108
6202
|
return this.refresh();
|
|
6109
6203
|
}
|
|
6110
6204
|
async start() {
|
|
@@ -6115,7 +6209,7 @@
|
|
|
6115
6209
|
this.started = true;
|
|
6116
6210
|
await new Promise(resolve => {
|
|
6117
6211
|
const start = async () => {
|
|
6118
|
-
this.
|
|
6212
|
+
this.#eventListeners.addListeners();
|
|
6119
6213
|
for (const plugin of this.plugins) {
|
|
6120
6214
|
await plugin.start?.();
|
|
6121
6215
|
}
|
|
@@ -6123,20 +6217,20 @@
|
|
|
6123
6217
|
this.play();
|
|
6124
6218
|
resolve();
|
|
6125
6219
|
};
|
|
6126
|
-
this
|
|
6220
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6127
6221
|
});
|
|
6128
6222
|
}
|
|
6129
6223
|
stop() {
|
|
6130
6224
|
if (!guardCheck(this) || !this.started) {
|
|
6131
6225
|
return;
|
|
6132
6226
|
}
|
|
6133
|
-
if (this
|
|
6134
|
-
clearTimeout(this
|
|
6135
|
-
|
|
6227
|
+
if (this.#delayTimeout) {
|
|
6228
|
+
clearTimeout(this.#delayTimeout);
|
|
6229
|
+
this.#delayTimeout = undefined;
|
|
6136
6230
|
}
|
|
6137
|
-
this
|
|
6231
|
+
this.#firstStart = true;
|
|
6138
6232
|
this.started = false;
|
|
6139
|
-
this.
|
|
6233
|
+
this.#eventListeners.removeListeners();
|
|
6140
6234
|
this.pause();
|
|
6141
6235
|
this.particles.clear();
|
|
6142
6236
|
this.canvas.stop();
|
|
@@ -6146,7 +6240,7 @@
|
|
|
6146
6240
|
this.particleCreatedPlugins.length = 0;
|
|
6147
6241
|
this.particleDestroyedPlugins.length = 0;
|
|
6148
6242
|
this.particlePositionPlugins.length = 0;
|
|
6149
|
-
this
|
|
6243
|
+
this.#sourceOptions = this.#options;
|
|
6150
6244
|
this.dispatchEvent(EventType.containerStopped);
|
|
6151
6245
|
}
|
|
6152
6246
|
updateActualOptions() {
|
|
@@ -6158,23 +6252,23 @@
|
|
|
6158
6252
|
}
|
|
6159
6253
|
return refresh;
|
|
6160
6254
|
}
|
|
6161
|
-
|
|
6255
|
+
#nextFrame = (timestamp) => {
|
|
6162
6256
|
try {
|
|
6163
|
-
if (!this
|
|
6164
|
-
this
|
|
6165
|
-
timestamp < this
|
|
6257
|
+
if (!this.#smooth &&
|
|
6258
|
+
this.#lastFrameTime !== undefined &&
|
|
6259
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6166
6260
|
this.draw(false);
|
|
6167
6261
|
return;
|
|
6168
6262
|
}
|
|
6169
|
-
this
|
|
6170
|
-
updateDelta(this
|
|
6171
|
-
this.addLifeTime(this.
|
|
6172
|
-
this
|
|
6173
|
-
if (this.
|
|
6263
|
+
this.#lastFrameTime ??= timestamp;
|
|
6264
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6265
|
+
this.addLifeTime(this.#delta.value);
|
|
6266
|
+
this.#lastFrameTime = timestamp;
|
|
6267
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6174
6268
|
this.draw(false);
|
|
6175
6269
|
return;
|
|
6176
6270
|
}
|
|
6177
|
-
this.canvas.render.drawParticles(this
|
|
6271
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6178
6272
|
if (!this.alive()) {
|
|
6179
6273
|
this.destroy();
|
|
6180
6274
|
return;
|
|
@@ -6195,10 +6289,10 @@
|
|
|
6195
6289
|
});
|
|
6196
6290
|
|
|
6197
6291
|
class BlendPluginInstance {
|
|
6198
|
-
|
|
6199
|
-
|
|
6292
|
+
#container;
|
|
6293
|
+
#defaultCompositeValue;
|
|
6200
6294
|
constructor(container) {
|
|
6201
|
-
this
|
|
6295
|
+
this.#container = container;
|
|
6202
6296
|
}
|
|
6203
6297
|
drawParticleCleanup(context, particle) {
|
|
6204
6298
|
if (!particle.options.blend?.enable) {
|
|
@@ -6215,14 +6309,14 @@
|
|
|
6215
6309
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6216
6310
|
}
|
|
6217
6311
|
drawSettingsCleanup(context) {
|
|
6218
|
-
if (!this
|
|
6312
|
+
if (!this.#defaultCompositeValue) {
|
|
6219
6313
|
return;
|
|
6220
6314
|
}
|
|
6221
|
-
context.globalCompositeOperation = this
|
|
6315
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6222
6316
|
}
|
|
6223
6317
|
drawSettingsSetup(context) {
|
|
6224
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6225
|
-
this
|
|
6318
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6319
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6226
6320
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6227
6321
|
}
|
|
6228
6322
|
}
|
|
@@ -6365,11 +6459,11 @@
|
|
|
6365
6459
|
class MovePluginInstance {
|
|
6366
6460
|
availablePathGenerators;
|
|
6367
6461
|
pathGenerators;
|
|
6368
|
-
|
|
6369
|
-
|
|
6462
|
+
#container;
|
|
6463
|
+
#pluginManager;
|
|
6370
6464
|
constructor(pluginManager, container) {
|
|
6371
|
-
this
|
|
6372
|
-
this
|
|
6465
|
+
this.#pluginManager = pluginManager;
|
|
6466
|
+
this.#container = container;
|
|
6373
6467
|
this.availablePathGenerators = new Map();
|
|
6374
6468
|
this.pathGenerators = new Map();
|
|
6375
6469
|
}
|
|
@@ -6400,7 +6494,7 @@
|
|
|
6400
6494
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6401
6495
|
inverse: gravityOptions.inverse,
|
|
6402
6496
|
};
|
|
6403
|
-
initSpin(this
|
|
6497
|
+
initSpin(this.#container, particle);
|
|
6404
6498
|
}
|
|
6405
6499
|
particleDestroyed(particle) {
|
|
6406
6500
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6411,7 +6505,7 @@
|
|
|
6411
6505
|
if (!moveOptions.enable) {
|
|
6412
6506
|
return;
|
|
6413
6507
|
}
|
|
6414
|
-
const container = this
|
|
6508
|
+
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;
|
|
6415
6509
|
if (moveOptions.spin.enable) {
|
|
6416
6510
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6417
6511
|
}
|
|
@@ -6421,18 +6515,18 @@
|
|
|
6421
6515
|
applyDistance(particle);
|
|
6422
6516
|
}
|
|
6423
6517
|
preInit() {
|
|
6424
|
-
return this
|
|
6518
|
+
return this.#init();
|
|
6425
6519
|
}
|
|
6426
6520
|
redrawInit() {
|
|
6427
|
-
return this
|
|
6521
|
+
return this.#init();
|
|
6428
6522
|
}
|
|
6429
6523
|
update() {
|
|
6430
6524
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6431
6525
|
pathGenerator.update();
|
|
6432
6526
|
}
|
|
6433
6527
|
}
|
|
6434
|
-
async
|
|
6435
|
-
const availablePathGenerators = await this.
|
|
6528
|
+
async #init() {
|
|
6529
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6436
6530
|
if (!availablePathGenerators) {
|
|
6437
6531
|
return;
|
|
6438
6532
|
}
|
|
@@ -6449,27 +6543,28 @@
|
|
|
6449
6543
|
MovePluginInstance: MovePluginInstance
|
|
6450
6544
|
});
|
|
6451
6545
|
|
|
6546
|
+
const defaultSize = 1;
|
|
6452
6547
|
class PoissonDiscPluginInstance {
|
|
6453
6548
|
poissonDisc;
|
|
6454
6549
|
redrawTimeout;
|
|
6455
|
-
|
|
6456
|
-
|
|
6550
|
+
#container;
|
|
6551
|
+
#currentIndex;
|
|
6457
6552
|
constructor(container) {
|
|
6458
|
-
this
|
|
6459
|
-
this
|
|
6553
|
+
this.#container = container;
|
|
6554
|
+
this.#currentIndex = 0;
|
|
6460
6555
|
}
|
|
6461
6556
|
async init() {
|
|
6462
|
-
await this
|
|
6557
|
+
await this.#initData();
|
|
6463
6558
|
}
|
|
6464
6559
|
particlePosition(position) {
|
|
6465
|
-
const container = this
|
|
6466
|
-
if (!this.poissonDisc || !(options?.enable ?? false) || this
|
|
6560
|
+
const container = this.#container, options = container.actualOptions.poisson;
|
|
6561
|
+
if (!this.poissonDisc || !(options?.enable ?? false) || this.#currentIndex >= this.poissonDisc.points.length) {
|
|
6467
6562
|
return;
|
|
6468
6563
|
}
|
|
6469
|
-
return position ?? this.poissonDisc.points[this
|
|
6564
|
+
return position ?? this.poissonDisc.points[this.#currentIndex++]?.position;
|
|
6470
6565
|
}
|
|
6471
6566
|
resize() {
|
|
6472
|
-
const container = this
|
|
6567
|
+
const container = this.#container, options = container.actualOptions.poisson;
|
|
6473
6568
|
if (!(options?.enable ?? false)) {
|
|
6474
6569
|
return;
|
|
6475
6570
|
}
|
|
@@ -6479,10 +6574,10 @@
|
|
|
6479
6574
|
const timeout = 250;
|
|
6480
6575
|
this.redrawTimeout = setTimeout(() => {
|
|
6481
6576
|
void (async () => {
|
|
6482
|
-
if (this.
|
|
6577
|
+
if (this.#container.destroyed) {
|
|
6483
6578
|
return;
|
|
6484
6579
|
}
|
|
6485
|
-
await this
|
|
6580
|
+
await this.#initData();
|
|
6486
6581
|
await container.particles.redraw();
|
|
6487
6582
|
})();
|
|
6488
6583
|
}, timeout);
|
|
@@ -6490,16 +6585,16 @@
|
|
|
6490
6585
|
stop() {
|
|
6491
6586
|
delete this.poissonDisc;
|
|
6492
6587
|
}
|
|
6493
|
-
async
|
|
6494
|
-
const container = this
|
|
6588
|
+
async #initData() {
|
|
6589
|
+
const container = this.#container, poissonOptions = container.actualOptions.poisson, particlesOptions = container.actualOptions.particles, canvasSize = container.canvas.size, pixelRatio = container.retina.pixelRatio;
|
|
6495
6590
|
if (!poissonOptions?.enable) {
|
|
6496
6591
|
return;
|
|
6497
6592
|
}
|
|
6498
|
-
this
|
|
6593
|
+
this.#currentIndex = 0;
|
|
6499
6594
|
const { PoissonDisc } = await Promise.resolve().then(function () { return PoissonDisc$1; });
|
|
6500
6595
|
this.poissonDisc = new PoissonDisc(canvasSize, poissonOptions.radius
|
|
6501
6596
|
? poissonOptions.radius * pixelRatio
|
|
6502
|
-
: Math.max(getRangeMax(particlesOptions
|
|
6597
|
+
: Math.max(getRangeMax(particlesOptions["size.value"] ?? defaultSize) * pixelRatio, Math.sqrt((canvasSize.width * canvasSize.height) / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);
|
|
6503
6598
|
const noSteps = 0;
|
|
6504
6599
|
if (poissonOptions.steps > noSteps) {
|
|
6505
6600
|
this.poissonDisc.steps(poissonOptions.steps);
|
|
@@ -6517,15 +6612,15 @@
|
|
|
6517
6612
|
|
|
6518
6613
|
const minimumLength = 0;
|
|
6519
6614
|
class TrailPluginInstance {
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6615
|
+
#container;
|
|
6616
|
+
#pluginManager;
|
|
6617
|
+
#trailFill;
|
|
6523
6618
|
constructor(pluginManager, container) {
|
|
6524
|
-
this
|
|
6525
|
-
this
|
|
6619
|
+
this.#container = container;
|
|
6620
|
+
this.#pluginManager = pluginManager;
|
|
6526
6621
|
}
|
|
6527
6622
|
canvasClear() {
|
|
6528
|
-
const container = this
|
|
6623
|
+
const container = this.#container, trail = container.actualOptions.trail, trailFill = this.#trailFill;
|
|
6529
6624
|
if (!trail?.enable || !trailFill || trail.length <= minimumLength) {
|
|
6530
6625
|
return false;
|
|
6531
6626
|
}
|
|
@@ -6543,24 +6638,24 @@
|
|
|
6543
6638
|
}
|
|
6544
6639
|
async init() {
|
|
6545
6640
|
try {
|
|
6546
|
-
await this
|
|
6641
|
+
await this.#initTrail();
|
|
6547
6642
|
}
|
|
6548
6643
|
catch (e) {
|
|
6549
6644
|
getLogger().error(e);
|
|
6550
6645
|
}
|
|
6551
6646
|
}
|
|
6552
|
-
|
|
6553
|
-
const options = this.
|
|
6647
|
+
#initTrail = async () => {
|
|
6648
|
+
const options = this.#container.actualOptions, trail = options.trail;
|
|
6554
6649
|
if (!trail?.enable) {
|
|
6555
6650
|
return;
|
|
6556
6651
|
}
|
|
6557
6652
|
const trailFill = trail.fill, opacity = inverseFactorNumerator / trail.length;
|
|
6558
6653
|
if (trailFill.color) {
|
|
6559
|
-
const fillColor = rangeColorToRgb(this
|
|
6654
|
+
const fillColor = rangeColorToRgb(this.#pluginManager, trailFill.color);
|
|
6560
6655
|
if (!fillColor) {
|
|
6561
6656
|
return;
|
|
6562
6657
|
}
|
|
6563
|
-
this
|
|
6658
|
+
this.#trailFill = {
|
|
6564
6659
|
color: {
|
|
6565
6660
|
...fillColor,
|
|
6566
6661
|
},
|
|
@@ -6574,7 +6669,7 @@
|
|
|
6574
6669
|
}
|
|
6575
6670
|
const img = safeDocument().createElement("img");
|
|
6576
6671
|
img.addEventListener("load", () => {
|
|
6577
|
-
this
|
|
6672
|
+
this.#trailFill = {
|
|
6578
6673
|
image: img,
|
|
6579
6674
|
opacity,
|
|
6580
6675
|
};
|
|
@@ -6684,10 +6779,10 @@
|
|
|
6684
6779
|
if (this.active.length <= minCount) {
|
|
6685
6780
|
continue;
|
|
6686
6781
|
}
|
|
6687
|
-
this
|
|
6782
|
+
this.#step();
|
|
6688
6783
|
}
|
|
6689
6784
|
}
|
|
6690
|
-
|
|
6785
|
+
#getNewPoint(currentPoint, tries) {
|
|
6691
6786
|
const minCoordinate = 0, gridMinValue = 0, maxNeighbourIndex = 1, newAngle = tries * (doublePI / this.retries), newDist = this.getRandom(this.radius, this.radius * double), offset = {
|
|
6692
6787
|
x: Math.cos(newAngle) * newDist,
|
|
6693
6788
|
y: Math.sin(newAngle) * newDist,
|
|
@@ -6745,7 +6840,7 @@
|
|
|
6745
6840
|
}
|
|
6746
6841
|
return newPoint;
|
|
6747
6842
|
}
|
|
6748
|
-
|
|
6843
|
+
#step() {
|
|
6749
6844
|
const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);
|
|
6750
6845
|
let foundNewPoint = false;
|
|
6751
6846
|
for (let tries = 0; tries < this.retries; tries++) {
|
|
@@ -6757,7 +6852,7 @@
|
|
|
6757
6852
|
if (!point) {
|
|
6758
6853
|
continue;
|
|
6759
6854
|
}
|
|
6760
|
-
const newPoint = this
|
|
6855
|
+
const newPoint = this.#getNewPoint(point, tries);
|
|
6761
6856
|
if (newPoint) {
|
|
6762
6857
|
foundNewPoint = true;
|
|
6763
6858
|
this.addPoint(newPoint);
|