@tsparticles/preset-confetti-falling 4.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* Preset v4.0
|
|
2
|
+
/* Preset v4.1.0 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -711,38 +711,38 @@
|
|
|
711
711
|
}
|
|
712
712
|
|
|
713
713
|
class EventDispatcher {
|
|
714
|
-
|
|
714
|
+
#listeners;
|
|
715
715
|
constructor() {
|
|
716
|
-
this
|
|
716
|
+
this.#listeners = new Map();
|
|
717
717
|
}
|
|
718
718
|
addEventListener(type, listener) {
|
|
719
719
|
this.removeEventListener(type, listener);
|
|
720
|
-
let arr = this.
|
|
720
|
+
let arr = this.#listeners.get(type);
|
|
721
721
|
if (!arr) {
|
|
722
722
|
arr = [];
|
|
723
|
-
this.
|
|
723
|
+
this.#listeners.set(type, arr);
|
|
724
724
|
}
|
|
725
725
|
arr.push(listener);
|
|
726
726
|
}
|
|
727
727
|
dispatchEvent(type, args) {
|
|
728
|
-
const listeners = this.
|
|
728
|
+
const listeners = this.#listeners.get(type);
|
|
729
729
|
listeners?.forEach(handler => {
|
|
730
730
|
handler(args);
|
|
731
731
|
});
|
|
732
732
|
}
|
|
733
733
|
hasEventListener(type) {
|
|
734
|
-
return !!this.
|
|
734
|
+
return !!this.#listeners.get(type);
|
|
735
735
|
}
|
|
736
736
|
removeAllEventListeners(type) {
|
|
737
737
|
if (!type) {
|
|
738
|
-
this
|
|
738
|
+
this.#listeners = new Map();
|
|
739
739
|
}
|
|
740
740
|
else {
|
|
741
|
-
this.
|
|
741
|
+
this.#listeners.delete(type);
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
removeEventListener(type, listener) {
|
|
745
|
-
const arr = this.
|
|
745
|
+
const arr = this.#listeners.get(type);
|
|
746
746
|
if (!arr) {
|
|
747
747
|
return;
|
|
748
748
|
}
|
|
@@ -751,7 +751,7 @@
|
|
|
751
751
|
return;
|
|
752
752
|
}
|
|
753
753
|
if (length === deleteCount) {
|
|
754
|
-
this.
|
|
754
|
+
this.#listeners.delete(type);
|
|
755
755
|
}
|
|
756
756
|
else {
|
|
757
757
|
arr.splice(idx, deleteCount);
|
|
@@ -789,19 +789,19 @@
|
|
|
789
789
|
presets = new Map();
|
|
790
790
|
shapeDrawers = new Map();
|
|
791
791
|
updaters = new Map();
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
792
|
+
#allLoadersSet = new Set();
|
|
793
|
+
#configs = new Map();
|
|
794
|
+
#engine;
|
|
795
|
+
#executedSet = new Set();
|
|
796
|
+
#initialized = false;
|
|
797
|
+
#isRunningLoaders = false;
|
|
798
|
+
#loadPromises = new Set();
|
|
799
799
|
constructor(engine) {
|
|
800
|
-
this
|
|
800
|
+
this.#engine = engine;
|
|
801
801
|
}
|
|
802
802
|
get configs() {
|
|
803
803
|
const res = {};
|
|
804
|
-
for (const [name, config] of this
|
|
804
|
+
for (const [name, config] of this.#configs) {
|
|
805
805
|
res[name] = config;
|
|
806
806
|
}
|
|
807
807
|
return res;
|
|
@@ -811,8 +811,8 @@
|
|
|
811
811
|
}
|
|
812
812
|
addConfig(config) {
|
|
813
813
|
const key = config.key ?? config.name ?? "default";
|
|
814
|
-
this.
|
|
815
|
-
this.
|
|
814
|
+
this.#configs.set(key, config);
|
|
815
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
816
816
|
}
|
|
817
817
|
addEasing(name, easing) {
|
|
818
818
|
if (this.easingFunctions.get(name)) {
|
|
@@ -873,21 +873,21 @@
|
|
|
873
873
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
874
874
|
}
|
|
875
875
|
async init() {
|
|
876
|
-
if (this
|
|
876
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
877
877
|
return;
|
|
878
878
|
}
|
|
879
|
-
this
|
|
880
|
-
this
|
|
881
|
-
this
|
|
879
|
+
this.#isRunningLoaders = true;
|
|
880
|
+
this.#executedSet = new Set();
|
|
881
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
882
882
|
try {
|
|
883
|
-
for (const loader of this
|
|
884
|
-
await this
|
|
883
|
+
for (const loader of this.#allLoadersSet) {
|
|
884
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
finally {
|
|
888
|
-
this.
|
|
889
|
-
this
|
|
890
|
-
this
|
|
888
|
+
this.#loadPromises.clear();
|
|
889
|
+
this.#isRunningLoaders = false;
|
|
890
|
+
this.#initialized = true;
|
|
891
891
|
}
|
|
892
892
|
}
|
|
893
893
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -898,24 +898,24 @@
|
|
|
898
898
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
899
899
|
}
|
|
900
900
|
async register(...loaders) {
|
|
901
|
-
if (this
|
|
901
|
+
if (this.#initialized) {
|
|
902
902
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
903
903
|
}
|
|
904
904
|
for (const loader of loaders) {
|
|
905
|
-
if (this
|
|
906
|
-
await this
|
|
905
|
+
if (this.#isRunningLoaders) {
|
|
906
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
907
907
|
}
|
|
908
908
|
else {
|
|
909
|
-
this.
|
|
909
|
+
this.#loadPromises.add(loader);
|
|
910
910
|
}
|
|
911
911
|
}
|
|
912
912
|
}
|
|
913
|
-
async
|
|
913
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
914
914
|
if (executed.has(loader))
|
|
915
915
|
return;
|
|
916
916
|
executed.add(loader);
|
|
917
917
|
allLoaders.add(loader);
|
|
918
|
-
await loader(this
|
|
918
|
+
await loader(this.#engine);
|
|
919
919
|
}
|
|
920
920
|
}
|
|
921
921
|
|
|
@@ -995,17 +995,17 @@
|
|
|
995
995
|
};
|
|
996
996
|
class Engine {
|
|
997
997
|
pluginManager = new PluginManager(this);
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
998
|
+
#domArray = [];
|
|
999
|
+
#eventDispatcher = new EventDispatcher();
|
|
1000
|
+
#initialized = false;
|
|
1001
1001
|
get items() {
|
|
1002
|
-
return this
|
|
1002
|
+
return this.#domArray;
|
|
1003
1003
|
}
|
|
1004
1004
|
get version() {
|
|
1005
|
-
return "4.0
|
|
1005
|
+
return "4.1.0";
|
|
1006
1006
|
}
|
|
1007
1007
|
addEventListener(type, listener) {
|
|
1008
|
-
this.
|
|
1008
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1009
1009
|
}
|
|
1010
1010
|
checkVersion(pluginVersion) {
|
|
1011
1011
|
if (this.version === pluginVersion) {
|
|
@@ -1014,17 +1014,17 @@
|
|
|
1014
1014
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1015
1015
|
}
|
|
1016
1016
|
dispatchEvent(type, args) {
|
|
1017
|
-
this.
|
|
1017
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1018
1018
|
}
|
|
1019
1019
|
async init() {
|
|
1020
|
-
if (this
|
|
1020
|
+
if (this.#initialized) {
|
|
1021
1021
|
return;
|
|
1022
1022
|
}
|
|
1023
1023
|
await this.pluginManager.init();
|
|
1024
|
-
this
|
|
1024
|
+
this.#initialized = true;
|
|
1025
1025
|
}
|
|
1026
1026
|
item(index) {
|
|
1027
|
-
const
|
|
1027
|
+
const items = this.items, item = items[index];
|
|
1028
1028
|
if (item?.destroyed) {
|
|
1029
1029
|
items.splice(index, removeDeleteCount);
|
|
1030
1030
|
return;
|
|
@@ -1078,7 +1078,7 @@
|
|
|
1078
1078
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1079
1079
|
}
|
|
1080
1080
|
removeEventListener(type, listener) {
|
|
1081
|
-
this.
|
|
1081
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1082
1082
|
}
|
|
1083
1083
|
}
|
|
1084
1084
|
|
|
@@ -1849,43 +1849,6 @@
|
|
|
1849
1849
|
}
|
|
1850
1850
|
}
|
|
1851
1851
|
|
|
1852
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1853
|
-
destroy;
|
|
1854
|
-
constructor() {
|
|
1855
|
-
super();
|
|
1856
|
-
this.destroy = DestroyType.none;
|
|
1857
|
-
this.speed = 2;
|
|
1858
|
-
}
|
|
1859
|
-
load(data) {
|
|
1860
|
-
super.load(data);
|
|
1861
|
-
if (isNull(data)) {
|
|
1862
|
-
return;
|
|
1863
|
-
}
|
|
1864
|
-
if (data.destroy !== undefined) {
|
|
1865
|
-
this.destroy = data.destroy;
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1871
|
-
animation;
|
|
1872
|
-
constructor() {
|
|
1873
|
-
super();
|
|
1874
|
-
this.animation = new OpacityAnimation();
|
|
1875
|
-
this.value = 1;
|
|
1876
|
-
}
|
|
1877
|
-
load(data) {
|
|
1878
|
-
if (isNull(data)) {
|
|
1879
|
-
return;
|
|
1880
|
-
}
|
|
1881
|
-
super.load(data);
|
|
1882
|
-
const animation = data.animation;
|
|
1883
|
-
if (animation !== undefined) {
|
|
1884
|
-
this.animation.load(animation);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
1852
|
class Stroke {
|
|
1890
1853
|
color;
|
|
1891
1854
|
opacity;
|
|
@@ -2053,43 +2016,6 @@
|
|
|
2053
2016
|
}
|
|
2054
2017
|
}
|
|
2055
2018
|
|
|
2056
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2057
|
-
destroy;
|
|
2058
|
-
constructor() {
|
|
2059
|
-
super();
|
|
2060
|
-
this.destroy = DestroyType.none;
|
|
2061
|
-
this.speed = 5;
|
|
2062
|
-
}
|
|
2063
|
-
load(data) {
|
|
2064
|
-
super.load(data);
|
|
2065
|
-
if (isNull(data)) {
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
if (data.destroy !== undefined) {
|
|
2069
|
-
this.destroy = data.destroy;
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2075
|
-
animation;
|
|
2076
|
-
constructor() {
|
|
2077
|
-
super();
|
|
2078
|
-
this.animation = new SizeAnimation();
|
|
2079
|
-
this.value = 3;
|
|
2080
|
-
}
|
|
2081
|
-
load(data) {
|
|
2082
|
-
super.load(data);
|
|
2083
|
-
if (isNull(data)) {
|
|
2084
|
-
return;
|
|
2085
|
-
}
|
|
2086
|
-
const animation = data.animation;
|
|
2087
|
-
if (animation !== undefined) {
|
|
2088
|
-
this.animation.load(animation);
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
2019
|
class ZIndex extends ValueWithRandom {
|
|
2094
2020
|
opacityRate;
|
|
2095
2021
|
sizeRate;
|
|
@@ -2123,24 +2049,21 @@
|
|
|
2123
2049
|
groups;
|
|
2124
2050
|
move;
|
|
2125
2051
|
number;
|
|
2126
|
-
opacity;
|
|
2127
2052
|
paint;
|
|
2128
2053
|
palette;
|
|
2129
2054
|
reduceDuplicates;
|
|
2130
2055
|
shape;
|
|
2131
|
-
size;
|
|
2132
2056
|
zIndex;
|
|
2133
|
-
|
|
2134
|
-
|
|
2057
|
+
#container;
|
|
2058
|
+
#pluginManager;
|
|
2135
2059
|
constructor(pluginManager, container) {
|
|
2136
|
-
this
|
|
2137
|
-
this
|
|
2060
|
+
this.#pluginManager = pluginManager;
|
|
2061
|
+
this.#container = container;
|
|
2138
2062
|
this.bounce = new ParticlesBounce();
|
|
2139
2063
|
this.effect = new Effect();
|
|
2140
2064
|
this.groups = {};
|
|
2141
2065
|
this.move = new Move();
|
|
2142
2066
|
this.number = new ParticlesNumber();
|
|
2143
|
-
this.opacity = new Opacity();
|
|
2144
2067
|
this.paint = new Paint();
|
|
2145
2068
|
this.paint.color = new AnimatableColor();
|
|
2146
2069
|
this.paint.color.value = "#fff";
|
|
@@ -2148,7 +2071,6 @@
|
|
|
2148
2071
|
this.paint.fill.enable = true;
|
|
2149
2072
|
this.reduceDuplicates = false;
|
|
2150
2073
|
this.shape = new Shape();
|
|
2151
|
-
this.size = new Size();
|
|
2152
2074
|
this.zIndex = new ZIndex();
|
|
2153
2075
|
}
|
|
2154
2076
|
load(data) {
|
|
@@ -2157,7 +2079,7 @@
|
|
|
2157
2079
|
}
|
|
2158
2080
|
if (data.palette) {
|
|
2159
2081
|
this.palette = data.palette;
|
|
2160
|
-
this
|
|
2082
|
+
this.#importPalette(this.palette);
|
|
2161
2083
|
}
|
|
2162
2084
|
if (data.groups !== undefined) {
|
|
2163
2085
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2177,7 +2099,6 @@
|
|
|
2177
2099
|
this.effect.load(data.effect);
|
|
2178
2100
|
this.move.load(data.move);
|
|
2179
2101
|
this.number.load(data.number);
|
|
2180
|
-
this.opacity.load(data.opacity);
|
|
2181
2102
|
const paintToLoad = data.paint;
|
|
2182
2103
|
if (paintToLoad) {
|
|
2183
2104
|
if (isArray(paintToLoad)) {
|
|
@@ -2196,15 +2117,14 @@
|
|
|
2196
2117
|
}
|
|
2197
2118
|
}
|
|
2198
2119
|
this.shape.load(data.shape);
|
|
2199
|
-
this.size.load(data.size);
|
|
2200
2120
|
this.zIndex.load(data.zIndex);
|
|
2201
|
-
if (this
|
|
2202
|
-
for (const plugin of this.
|
|
2121
|
+
if (this.#container) {
|
|
2122
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2203
2123
|
if (plugin.loadParticlesOptions) {
|
|
2204
|
-
plugin.loadParticlesOptions(this
|
|
2124
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2205
2125
|
}
|
|
2206
2126
|
}
|
|
2207
|
-
const updaters = this.
|
|
2127
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2208
2128
|
if (updaters) {
|
|
2209
2129
|
for (const updater of updaters) {
|
|
2210
2130
|
if (updater.loadOptions) {
|
|
@@ -2214,8 +2134,8 @@
|
|
|
2214
2134
|
}
|
|
2215
2135
|
}
|
|
2216
2136
|
}
|
|
2217
|
-
|
|
2218
|
-
const paletteData = this.
|
|
2137
|
+
#importPalette = (palette) => {
|
|
2138
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2219
2139
|
if (!paletteData) {
|
|
2220
2140
|
return;
|
|
2221
2141
|
}
|
|
@@ -2294,11 +2214,11 @@
|
|
|
2294
2214
|
smooth;
|
|
2295
2215
|
style;
|
|
2296
2216
|
zLayers;
|
|
2297
|
-
|
|
2298
|
-
|
|
2217
|
+
#container;
|
|
2218
|
+
#pluginManager;
|
|
2299
2219
|
constructor(pluginManager, container) {
|
|
2300
|
-
this
|
|
2301
|
-
this
|
|
2220
|
+
this.#pluginManager = pluginManager;
|
|
2221
|
+
this.#container = container;
|
|
2302
2222
|
this.autoPlay = true;
|
|
2303
2223
|
this.background = new Background();
|
|
2304
2224
|
this.clear = true;
|
|
@@ -2309,7 +2229,7 @@
|
|
|
2309
2229
|
this.duration = 0;
|
|
2310
2230
|
this.fpsLimit = 120;
|
|
2311
2231
|
this.hdr = true;
|
|
2312
|
-
this.particles = loadParticlesOptions(this
|
|
2232
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2313
2233
|
this.pauseOnBlur = true;
|
|
2314
2234
|
this.pauseOnOutsideViewport = true;
|
|
2315
2235
|
this.resize = new ResizeEvent();
|
|
@@ -2324,12 +2244,12 @@
|
|
|
2324
2244
|
if (data.preset !== undefined) {
|
|
2325
2245
|
this.preset = data.preset;
|
|
2326
2246
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2327
|
-
this
|
|
2247
|
+
this.#importPreset(preset);
|
|
2328
2248
|
});
|
|
2329
2249
|
}
|
|
2330
2250
|
if (data.palette !== undefined) {
|
|
2331
2251
|
this.palette = data.palette;
|
|
2332
|
-
this
|
|
2252
|
+
this.#importPalette(this.palette);
|
|
2333
2253
|
}
|
|
2334
2254
|
if (data.autoPlay !== undefined) {
|
|
2335
2255
|
this.autoPlay = data.autoPlay;
|
|
@@ -2383,12 +2303,12 @@
|
|
|
2383
2303
|
if (data.smooth !== undefined) {
|
|
2384
2304
|
this.smooth = data.smooth;
|
|
2385
2305
|
}
|
|
2386
|
-
this.
|
|
2387
|
-
plugin.loadOptions(this
|
|
2306
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2307
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2388
2308
|
});
|
|
2389
2309
|
}
|
|
2390
|
-
|
|
2391
|
-
const paletteData = this.
|
|
2310
|
+
#importPalette = palette => {
|
|
2311
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2392
2312
|
if (!paletteData) {
|
|
2393
2313
|
return;
|
|
2394
2314
|
}
|
|
@@ -2405,8 +2325,8 @@
|
|
|
2405
2325
|
},
|
|
2406
2326
|
});
|
|
2407
2327
|
};
|
|
2408
|
-
|
|
2409
|
-
this.load(this.
|
|
2328
|
+
#importPreset = preset => {
|
|
2329
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2410
2330
|
};
|
|
2411
2331
|
}
|
|
2412
2332
|
|
|
@@ -2875,7 +2795,7 @@
|
|
|
2875
2795
|
}
|
|
2876
2796
|
|
|
2877
2797
|
async function loadBlendPlugin(engine) {
|
|
2878
|
-
engine.checkVersion("4.0
|
|
2798
|
+
engine.checkVersion("4.1.0");
|
|
2879
2799
|
await engine.pluginManager.register(e => {
|
|
2880
2800
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2881
2801
|
});
|
|
@@ -2912,7 +2832,7 @@
|
|
|
2912
2832
|
}
|
|
2913
2833
|
|
|
2914
2834
|
async function loadCircleShape(engine) {
|
|
2915
|
-
engine.checkVersion("4.0
|
|
2835
|
+
engine.checkVersion("4.1.0");
|
|
2916
2836
|
await engine.pluginManager.register(e => {
|
|
2917
2837
|
e.pluginManager.addShape(["circle"], () => {
|
|
2918
2838
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2933,15 +2853,15 @@
|
|
|
2933
2853
|
return input.startsWith("#");
|
|
2934
2854
|
}
|
|
2935
2855
|
handleColor(color) {
|
|
2936
|
-
return this
|
|
2856
|
+
return this.#parseString(color.value);
|
|
2937
2857
|
}
|
|
2938
2858
|
handleRangeColor(color) {
|
|
2939
|
-
return this
|
|
2859
|
+
return this.#parseString(color.value);
|
|
2940
2860
|
}
|
|
2941
2861
|
parseString(input) {
|
|
2942
|
-
return this
|
|
2862
|
+
return this.#parseString(input);
|
|
2943
2863
|
}
|
|
2944
|
-
|
|
2864
|
+
#parseString(hexColor) {
|
|
2945
2865
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
2946
2866
|
return;
|
|
2947
2867
|
}
|
|
@@ -2960,7 +2880,7 @@
|
|
|
2960
2880
|
}
|
|
2961
2881
|
|
|
2962
2882
|
async function loadHexColorPlugin(engine) {
|
|
2963
|
-
engine.checkVersion("4.0
|
|
2883
|
+
engine.checkVersion("4.1.0");
|
|
2964
2884
|
await engine.pluginManager.register(e => {
|
|
2965
2885
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2966
2886
|
});
|
|
@@ -3013,7 +2933,7 @@
|
|
|
3013
2933
|
}
|
|
3014
2934
|
|
|
3015
2935
|
async function loadHslColorPlugin(engine) {
|
|
3016
|
-
engine.checkVersion("4.0
|
|
2936
|
+
engine.checkVersion("4.1.0");
|
|
3017
2937
|
await engine.pluginManager.register(e => {
|
|
3018
2938
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3019
2939
|
});
|
|
@@ -3021,13 +2941,13 @@
|
|
|
3021
2941
|
|
|
3022
2942
|
class MovePlugin {
|
|
3023
2943
|
id = "move";
|
|
3024
|
-
|
|
2944
|
+
#pluginManager;
|
|
3025
2945
|
constructor(pluginManager) {
|
|
3026
|
-
this
|
|
2946
|
+
this.#pluginManager = pluginManager;
|
|
3027
2947
|
}
|
|
3028
2948
|
async getPlugin(container) {
|
|
3029
2949
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3030
|
-
return new MovePluginInstance(this
|
|
2950
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3031
2951
|
}
|
|
3032
2952
|
loadOptions() {
|
|
3033
2953
|
}
|
|
@@ -3037,7 +2957,7 @@
|
|
|
3037
2957
|
}
|
|
3038
2958
|
|
|
3039
2959
|
async function loadMovePlugin(engine) {
|
|
3040
|
-
engine.checkVersion("4.0
|
|
2960
|
+
engine.checkVersion("4.1.0");
|
|
3041
2961
|
await engine.pluginManager.register(e => {
|
|
3042
2962
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3043
2963
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3055,18 +2975,58 @@
|
|
|
3055
2975
|
});
|
|
3056
2976
|
}
|
|
3057
2977
|
|
|
2978
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
2979
|
+
destroy;
|
|
2980
|
+
constructor() {
|
|
2981
|
+
super();
|
|
2982
|
+
this.destroy = DestroyType.none;
|
|
2983
|
+
this.speed = 2;
|
|
2984
|
+
}
|
|
2985
|
+
load(data) {
|
|
2986
|
+
super.load(data);
|
|
2987
|
+
if (isNull(data)) {
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
if (data.destroy !== undefined) {
|
|
2991
|
+
this.destroy = data.destroy;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
2997
|
+
animation;
|
|
2998
|
+
constructor() {
|
|
2999
|
+
super();
|
|
3000
|
+
this.animation = new OpacityAnimation();
|
|
3001
|
+
this.value = 1;
|
|
3002
|
+
}
|
|
3003
|
+
load(data) {
|
|
3004
|
+
if (isNull(data)) {
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
super.load(data);
|
|
3008
|
+
const animation = data.animation;
|
|
3009
|
+
if (animation !== undefined) {
|
|
3010
|
+
this.animation.load(animation);
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3058
3015
|
class OpacityUpdater {
|
|
3059
|
-
container;
|
|
3016
|
+
#container;
|
|
3060
3017
|
constructor(container) {
|
|
3061
|
-
this
|
|
3018
|
+
this.#container = container;
|
|
3062
3019
|
}
|
|
3063
3020
|
init(particle) {
|
|
3064
3021
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3022
|
+
if (!opacityOptions) {
|
|
3023
|
+
return;
|
|
3024
|
+
}
|
|
3065
3025
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3066
3026
|
const opacityAnimation = opacityOptions.animation;
|
|
3067
3027
|
if (opacityAnimation.enable) {
|
|
3068
3028
|
particle.opacity.velocity =
|
|
3069
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3029
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3070
3030
|
if (!opacityAnimation.sync) {
|
|
3071
3031
|
particle.opacity.velocity *= getRandom();
|
|
3072
3032
|
}
|
|
@@ -3082,6 +3042,12 @@
|
|
|
3082
3042
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3083
3043
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3084
3044
|
}
|
|
3045
|
+
loadOptions(options, ...sources) {
|
|
3046
|
+
options.opacity ??= new Opacity();
|
|
3047
|
+
for (const source of sources) {
|
|
3048
|
+
options.opacity.load(source?.opacity);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3085
3051
|
reset(particle) {
|
|
3086
3052
|
if (!particle.opacity) {
|
|
3087
3053
|
return;
|
|
@@ -3090,7 +3056,7 @@
|
|
|
3090
3056
|
particle.opacity.loops = 0;
|
|
3091
3057
|
}
|
|
3092
3058
|
update(particle, delta) {
|
|
3093
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3059
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3094
3060
|
return;
|
|
3095
3061
|
}
|
|
3096
3062
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3098,7 +3064,7 @@
|
|
|
3098
3064
|
}
|
|
3099
3065
|
|
|
3100
3066
|
async function loadOpacityUpdater(engine) {
|
|
3101
|
-
engine.checkVersion("4.0
|
|
3067
|
+
engine.checkVersion("4.1.0");
|
|
3102
3068
|
await engine.pluginManager.register(e => {
|
|
3103
3069
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3104
3070
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3120,10 +3086,9 @@
|
|
|
3120
3086
|
}
|
|
3121
3087
|
const velocity = data.particle.velocity.x;
|
|
3122
3088
|
let bounced = false;
|
|
3123
|
-
if (
|
|
3124
|
-
data.
|
|
3125
|
-
|
|
3126
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3089
|
+
if (data.outOfCanvas &&
|
|
3090
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3091
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3127
3092
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3128
3093
|
data.particle.velocity.x *= -newVelocity;
|
|
3129
3094
|
bounced = true;
|
|
@@ -3132,10 +3097,10 @@
|
|
|
3132
3097
|
return;
|
|
3133
3098
|
}
|
|
3134
3099
|
const minPos = data.offset.x + data.size;
|
|
3135
|
-
if (data.
|
|
3100
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3136
3101
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3137
3102
|
}
|
|
3138
|
-
else if (data.
|
|
3103
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3139
3104
|
data.particle.position.x = minPos;
|
|
3140
3105
|
}
|
|
3141
3106
|
if (data.outMode === OutMode.split) {
|
|
@@ -3155,10 +3120,9 @@
|
|
|
3155
3120
|
}
|
|
3156
3121
|
const velocity = data.particle.velocity.y;
|
|
3157
3122
|
let bounced = false;
|
|
3158
|
-
if (
|
|
3159
|
-
data.
|
|
3160
|
-
|
|
3161
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3123
|
+
if (data.outOfCanvas &&
|
|
3124
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3125
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3162
3126
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3163
3127
|
data.particle.velocity.y *= -newVelocity;
|
|
3164
3128
|
bounced = true;
|
|
@@ -3167,10 +3131,10 @@
|
|
|
3167
3131
|
return;
|
|
3168
3132
|
}
|
|
3169
3133
|
const minPos = data.offset.y + data.size;
|
|
3170
|
-
if (data.
|
|
3134
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3171
3135
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3172
3136
|
}
|
|
3173
|
-
else if (data.
|
|
3137
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3174
3138
|
data.particle.position.y = minPos;
|
|
3175
3139
|
}
|
|
3176
3140
|
if (data.outMode === OutMode.split) {
|
|
@@ -3179,24 +3143,24 @@
|
|
|
3179
3143
|
}
|
|
3180
3144
|
|
|
3181
3145
|
class BounceOutMode {
|
|
3182
|
-
container;
|
|
3183
3146
|
modes;
|
|
3184
|
-
|
|
3147
|
+
#container;
|
|
3148
|
+
#particleBouncePlugins;
|
|
3185
3149
|
constructor(container) {
|
|
3186
|
-
this
|
|
3150
|
+
this.#container = container;
|
|
3187
3151
|
this.modes = [
|
|
3188
3152
|
OutMode.bounce,
|
|
3189
3153
|
OutMode.split,
|
|
3190
3154
|
];
|
|
3191
|
-
this
|
|
3155
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3192
3156
|
}
|
|
3193
3157
|
update(particle, direction, delta, outMode) {
|
|
3194
3158
|
if (!this.modes.includes(outMode)) {
|
|
3195
3159
|
return;
|
|
3196
3160
|
}
|
|
3197
|
-
const container = this
|
|
3161
|
+
const container = this.#container;
|
|
3198
3162
|
let handled = false;
|
|
3199
|
-
for (const plugin of this
|
|
3163
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3200
3164
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3201
3165
|
if (handled) {
|
|
3202
3166
|
break;
|
|
@@ -3205,29 +3169,26 @@
|
|
|
3205
3169
|
if (handled) {
|
|
3206
3170
|
return;
|
|
3207
3171
|
}
|
|
3208
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3209
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3210
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3172
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3173
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3174
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3211
3175
|
}
|
|
3212
3176
|
}
|
|
3213
3177
|
|
|
3214
3178
|
const minVelocity$3 = 0;
|
|
3215
3179
|
class DestroyOutMode {
|
|
3216
|
-
container;
|
|
3217
3180
|
modes;
|
|
3218
|
-
constructor(
|
|
3219
|
-
this.container = container;
|
|
3181
|
+
constructor(_container) {
|
|
3220
3182
|
this.modes = [OutMode.destroy];
|
|
3221
3183
|
}
|
|
3222
3184
|
update(particle, direction, _delta, outMode) {
|
|
3223
3185
|
if (!this.modes.includes(outMode)) {
|
|
3224
3186
|
return;
|
|
3225
3187
|
}
|
|
3226
|
-
const container = this.container;
|
|
3227
3188
|
switch (particle.outType) {
|
|
3228
3189
|
case ParticleOutType.normal:
|
|
3229
3190
|
case ParticleOutType.outside:
|
|
3230
|
-
if (
|
|
3191
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3231
3192
|
return;
|
|
3232
3193
|
}
|
|
3233
3194
|
break;
|
|
@@ -3248,10 +3209,10 @@
|
|
|
3248
3209
|
|
|
3249
3210
|
const minVelocity$2 = 0;
|
|
3250
3211
|
class NoneOutMode {
|
|
3251
|
-
container;
|
|
3252
3212
|
modes;
|
|
3213
|
+
#container;
|
|
3253
3214
|
constructor(container) {
|
|
3254
|
-
this
|
|
3215
|
+
this.#container = container;
|
|
3255
3216
|
this.modes = [OutMode.none];
|
|
3256
3217
|
}
|
|
3257
3218
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3264,7 +3225,7 @@
|
|
|
3264
3225
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3265
3226
|
return;
|
|
3266
3227
|
}
|
|
3267
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3228
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3268
3229
|
if (!gravityOptions.enable) {
|
|
3269
3230
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3270
3231
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3290,17 +3251,17 @@
|
|
|
3290
3251
|
|
|
3291
3252
|
const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
|
|
3292
3253
|
class OutOutMode {
|
|
3293
|
-
container;
|
|
3294
3254
|
modes;
|
|
3255
|
+
#container;
|
|
3295
3256
|
constructor(container) {
|
|
3296
|
-
this
|
|
3257
|
+
this.#container = container;
|
|
3297
3258
|
this.modes = [OutMode.out];
|
|
3298
3259
|
}
|
|
3299
3260
|
update(particle, direction, _delta, outMode) {
|
|
3300
3261
|
if (!this.modes.includes(outMode)) {
|
|
3301
3262
|
return;
|
|
3302
3263
|
}
|
|
3303
|
-
const container = this
|
|
3264
|
+
const container = this.#container;
|
|
3304
3265
|
switch (particle.outType) {
|
|
3305
3266
|
case ParticleOutType.inside: {
|
|
3306
3267
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3330,7 +3291,7 @@
|
|
|
3330
3291
|
break;
|
|
3331
3292
|
}
|
|
3332
3293
|
default: {
|
|
3333
|
-
if (
|
|
3294
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3334
3295
|
return;
|
|
3335
3296
|
}
|
|
3336
3297
|
switch (particle.outType) {
|
|
@@ -3414,16 +3375,16 @@
|
|
|
3414
3375
|
};
|
|
3415
3376
|
class OutOfCanvasUpdater {
|
|
3416
3377
|
updaters;
|
|
3417
|
-
container;
|
|
3378
|
+
#container;
|
|
3418
3379
|
constructor(container) {
|
|
3419
|
-
this
|
|
3380
|
+
this.#container = container;
|
|
3420
3381
|
this.updaters = new Map();
|
|
3421
3382
|
}
|
|
3422
3383
|
init(particle) {
|
|
3423
|
-
this
|
|
3424
|
-
this
|
|
3425
|
-
this
|
|
3426
|
-
this
|
|
3384
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3385
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3386
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3387
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3427
3388
|
}
|
|
3428
3389
|
isEnabled(particle) {
|
|
3429
3390
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3431,18 +3392,18 @@
|
|
|
3431
3392
|
update(particle, delta) {
|
|
3432
3393
|
const outModes = particle.options.move.outModes;
|
|
3433
3394
|
particle.justWarped = false;
|
|
3434
|
-
this
|
|
3435
|
-
this
|
|
3436
|
-
this
|
|
3437
|
-
this
|
|
3395
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3396
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3397
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3398
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3438
3399
|
}
|
|
3439
|
-
|
|
3400
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3440
3401
|
const outModes = particle.options.move.outModes;
|
|
3441
3402
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3442
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3403
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3443
3404
|
}
|
|
3444
3405
|
};
|
|
3445
|
-
|
|
3406
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3446
3407
|
for (const updater of this.updaters.values()) {
|
|
3447
3408
|
updater.update(particle, direction, delta, outMode);
|
|
3448
3409
|
}
|
|
@@ -3450,7 +3411,7 @@
|
|
|
3450
3411
|
}
|
|
3451
3412
|
|
|
3452
3413
|
async function loadOutModesUpdater(engine) {
|
|
3453
|
-
engine.checkVersion("4.0
|
|
3414
|
+
engine.checkVersion("4.1.0");
|
|
3454
3415
|
await engine.pluginManager.register(e => {
|
|
3455
3416
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3456
3417
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3460,20 +3421,20 @@
|
|
|
3460
3421
|
|
|
3461
3422
|
const defaultOpacity = 1;
|
|
3462
3423
|
class PaintUpdater {
|
|
3463
|
-
|
|
3464
|
-
|
|
3424
|
+
#container;
|
|
3425
|
+
#pluginManager;
|
|
3465
3426
|
constructor(pluginManager, container) {
|
|
3466
|
-
this
|
|
3467
|
-
this
|
|
3427
|
+
this.#container = container;
|
|
3428
|
+
this.#pluginManager = pluginManager;
|
|
3468
3429
|
}
|
|
3469
3430
|
init(particle) {
|
|
3470
|
-
const container = this
|
|
3431
|
+
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;
|
|
3471
3432
|
if (fill) {
|
|
3472
3433
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3473
3434
|
particle.fillEnabled = fill.enable;
|
|
3474
3435
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3475
3436
|
particle.fillAnimation = fillColor.animation;
|
|
3476
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3437
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3477
3438
|
if (fillHslColor) {
|
|
3478
3439
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3479
3440
|
}
|
|
@@ -3489,7 +3450,7 @@
|
|
|
3489
3450
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3490
3451
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3491
3452
|
particle.strokeAnimation = strokeColor.animation;
|
|
3492
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3453
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3493
3454
|
if (strokeHslColor) {
|
|
3494
3455
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3495
3456
|
}
|
|
@@ -3521,7 +3482,7 @@
|
|
|
3521
3482
|
}
|
|
3522
3483
|
|
|
3523
3484
|
async function loadPaintUpdater(engine) {
|
|
3524
|
-
engine.checkVersion("4.0
|
|
3485
|
+
engine.checkVersion("4.1.0");
|
|
3525
3486
|
await engine.pluginManager.register(e => {
|
|
3526
3487
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3527
3488
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3576,27 +3537,69 @@
|
|
|
3576
3537
|
}
|
|
3577
3538
|
|
|
3578
3539
|
async function loadRgbColorPlugin(engine) {
|
|
3579
|
-
engine.checkVersion("4.0
|
|
3540
|
+
engine.checkVersion("4.1.0");
|
|
3580
3541
|
await engine.pluginManager.register(e => {
|
|
3581
3542
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3582
3543
|
});
|
|
3583
3544
|
}
|
|
3584
3545
|
|
|
3546
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3547
|
+
destroy;
|
|
3548
|
+
constructor() {
|
|
3549
|
+
super();
|
|
3550
|
+
this.destroy = DestroyType.none;
|
|
3551
|
+
this.speed = 5;
|
|
3552
|
+
}
|
|
3553
|
+
load(data) {
|
|
3554
|
+
super.load(data);
|
|
3555
|
+
if (isNull(data)) {
|
|
3556
|
+
return;
|
|
3557
|
+
}
|
|
3558
|
+
if (data.destroy !== undefined) {
|
|
3559
|
+
this.destroy = data.destroy;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3565
|
+
animation;
|
|
3566
|
+
constructor() {
|
|
3567
|
+
super();
|
|
3568
|
+
this.animation = new SizeAnimation();
|
|
3569
|
+
this.value = 3;
|
|
3570
|
+
}
|
|
3571
|
+
load(data) {
|
|
3572
|
+
super.load(data);
|
|
3573
|
+
if (isNull(data)) {
|
|
3574
|
+
return;
|
|
3575
|
+
}
|
|
3576
|
+
const animation = data.animation;
|
|
3577
|
+
if (animation !== undefined) {
|
|
3578
|
+
this.animation.load(animation);
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3585
3583
|
const minLoops = 0;
|
|
3586
3584
|
class SizeUpdater {
|
|
3587
|
-
|
|
3585
|
+
#container;
|
|
3588
3586
|
constructor(container) {
|
|
3589
|
-
this
|
|
3587
|
+
this.#container = container;
|
|
3590
3588
|
}
|
|
3591
3589
|
init(particle) {
|
|
3592
|
-
const container = this
|
|
3593
|
-
if (
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3590
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3591
|
+
if (!sizeOptions) {
|
|
3592
|
+
return;
|
|
3593
|
+
}
|
|
3594
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3595
|
+
if (!sizeAnimation.enable) {
|
|
3596
|
+
return;
|
|
3597
|
+
}
|
|
3598
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3599
|
+
if (sizeAnimation.sync) {
|
|
3600
|
+
return;
|
|
3599
3601
|
}
|
|
3602
|
+
particle.size.velocity *= getRandom();
|
|
3600
3603
|
}
|
|
3601
3604
|
isEnabled(particle) {
|
|
3602
3605
|
return (!particle.destroyed &&
|
|
@@ -3606,12 +3609,26 @@
|
|
|
3606
3609
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3607
3610
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3608
3611
|
}
|
|
3612
|
+
loadOptions(options, ...sources) {
|
|
3613
|
+
options.size ??= new Size();
|
|
3614
|
+
for (const source of sources) {
|
|
3615
|
+
options.size.load(source?.size);
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
preInit(particle) {
|
|
3619
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3620
|
+
if (!sizeOptions) {
|
|
3621
|
+
return;
|
|
3622
|
+
}
|
|
3623
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3624
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3625
|
+
}
|
|
3609
3626
|
reset(particle) {
|
|
3610
3627
|
particle.size.time = 0;
|
|
3611
3628
|
particle.size.loops = 0;
|
|
3612
3629
|
}
|
|
3613
3630
|
update(particle, delta) {
|
|
3614
|
-
if (!this.isEnabled(particle)) {
|
|
3631
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3615
3632
|
return;
|
|
3616
3633
|
}
|
|
3617
3634
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3619,7 +3636,7 @@
|
|
|
3619
3636
|
}
|
|
3620
3637
|
|
|
3621
3638
|
async function loadSizeUpdater(engine) {
|
|
3622
|
-
engine.checkVersion("4.0
|
|
3639
|
+
engine.checkVersion("4.1.0");
|
|
3623
3640
|
await engine.pluginManager.register(e => {
|
|
3624
3641
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3625
3642
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3628,7 +3645,7 @@
|
|
|
3628
3645
|
}
|
|
3629
3646
|
|
|
3630
3647
|
async function loadBasic(engine) {
|
|
3631
|
-
engine.checkVersion("4.0
|
|
3648
|
+
engine.checkVersion("4.1.0");
|
|
3632
3649
|
await engine.pluginManager.register(async (e) => {
|
|
3633
3650
|
await Promise.all([
|
|
3634
3651
|
loadBlendPlugin(e),
|
|
@@ -3735,7 +3752,7 @@
|
|
|
3735
3752
|
}
|
|
3736
3753
|
|
|
3737
3754
|
async function loadMotionPlugin(engine) {
|
|
3738
|
-
engine.checkVersion("4.0
|
|
3755
|
+
engine.checkVersion("4.1.0");
|
|
3739
3756
|
await engine.pluginManager.register(e => {
|
|
3740
3757
|
e.pluginManager.addPlugin(new MotionPlugin());
|
|
3741
3758
|
});
|
|
@@ -3859,9 +3876,9 @@
|
|
|
3859
3876
|
}
|
|
3860
3877
|
|
|
3861
3878
|
class RollUpdater {
|
|
3862
|
-
|
|
3879
|
+
#pluginManager;
|
|
3863
3880
|
constructor(pluginManager) {
|
|
3864
|
-
this
|
|
3881
|
+
this.#pluginManager = pluginManager;
|
|
3865
3882
|
}
|
|
3866
3883
|
getTransformValues(particle) {
|
|
3867
3884
|
const roll = particle.roll?.enable && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
@@ -3871,7 +3888,7 @@
|
|
|
3871
3888
|
};
|
|
3872
3889
|
}
|
|
3873
3890
|
init(particle) {
|
|
3874
|
-
initParticle(this
|
|
3891
|
+
initParticle(this.#pluginManager, particle);
|
|
3875
3892
|
}
|
|
3876
3893
|
isEnabled(particle) {
|
|
3877
3894
|
const roll = particle.options.roll;
|
|
@@ -3892,7 +3909,7 @@
|
|
|
3892
3909
|
}
|
|
3893
3910
|
|
|
3894
3911
|
async function loadRollUpdater(engine) {
|
|
3895
|
-
engine.checkVersion("4.0
|
|
3912
|
+
engine.checkVersion("4.1.0");
|
|
3896
3913
|
await engine.pluginManager.register(e => {
|
|
3897
3914
|
e.pluginManager.addParticleUpdater("roll", () => {
|
|
3898
3915
|
return Promise.resolve(new RollUpdater(e.pluginManager));
|
|
@@ -3958,9 +3975,9 @@
|
|
|
3958
3975
|
|
|
3959
3976
|
const doublePIDeg = 360;
|
|
3960
3977
|
class RotateUpdater {
|
|
3961
|
-
container;
|
|
3978
|
+
#container;
|
|
3962
3979
|
constructor(container) {
|
|
3963
|
-
this
|
|
3980
|
+
this.#container = container;
|
|
3964
3981
|
}
|
|
3965
3982
|
init(particle) {
|
|
3966
3983
|
const rotateOptions = particle.options.rotate;
|
|
@@ -3992,7 +4009,7 @@
|
|
|
3992
4009
|
if (rotateAnimation.enable) {
|
|
3993
4010
|
particle.rotate.decay = identity$2 - getRangeValue(rotateAnimation.decay);
|
|
3994
4011
|
particle.rotate.velocity =
|
|
3995
|
-
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this
|
|
4012
|
+
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
|
|
3996
4013
|
if (!rotateAnimation.sync) {
|
|
3997
4014
|
particle.rotate.velocity *= getRandom();
|
|
3998
4015
|
}
|
|
@@ -4026,7 +4043,7 @@
|
|
|
4026
4043
|
}
|
|
4027
4044
|
|
|
4028
4045
|
async function loadRotateUpdater(engine) {
|
|
4029
|
-
engine.checkVersion("4.0
|
|
4046
|
+
engine.checkVersion("4.1.0");
|
|
4030
4047
|
await engine.pluginManager.register(e => {
|
|
4031
4048
|
e.pluginManager.addParticleUpdater("rotate", container => {
|
|
4032
4049
|
return Promise.resolve(new RotateUpdater(container));
|
|
@@ -4050,7 +4067,7 @@
|
|
|
4050
4067
|
}
|
|
4051
4068
|
|
|
4052
4069
|
async function loadSquareShape(engine) {
|
|
4053
|
-
engine.checkVersion("4.0
|
|
4070
|
+
engine.checkVersion("4.1.0");
|
|
4054
4071
|
await engine.pluginManager.register(e => {
|
|
4055
4072
|
e.pluginManager.addShape(["edge", "square"], () => Promise.resolve(new SquareDrawer()));
|
|
4056
4073
|
});
|
|
@@ -4121,9 +4138,9 @@
|
|
|
4121
4138
|
|
|
4122
4139
|
const maxAngle$1 = 360;
|
|
4123
4140
|
class TiltUpdater {
|
|
4124
|
-
container;
|
|
4141
|
+
#container;
|
|
4125
4142
|
constructor(container) {
|
|
4126
|
-
this
|
|
4143
|
+
this.#container = container;
|
|
4127
4144
|
}
|
|
4128
4145
|
getTransformValues(particle) {
|
|
4129
4146
|
const tilt = particle.tilt?.enable && particle.tilt;
|
|
@@ -4162,7 +4179,7 @@
|
|
|
4162
4179
|
const tiltAnimation = particle.options.tilt?.animation;
|
|
4163
4180
|
if (tiltAnimation?.enable) {
|
|
4164
4181
|
particle.tilt.decay = identity$2 - getRangeValue(tiltAnimation.decay);
|
|
4165
|
-
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this
|
|
4182
|
+
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this.#container.retina.reduceFactor;
|
|
4166
4183
|
if (!tiltAnimation.sync) {
|
|
4167
4184
|
particle.tilt.velocity *= getRandom();
|
|
4168
4185
|
}
|
|
@@ -4187,7 +4204,7 @@
|
|
|
4187
4204
|
}
|
|
4188
4205
|
|
|
4189
4206
|
async function loadTiltUpdater(engine) {
|
|
4190
|
-
engine.checkVersion("4.0
|
|
4207
|
+
engine.checkVersion("4.1.0");
|
|
4191
4208
|
await engine.pluginManager.register(e => {
|
|
4192
4209
|
e.pluginManager.addParticleUpdater("tilt", container => {
|
|
4193
4210
|
return Promise.resolve(new TiltUpdater(container));
|
|
@@ -4268,9 +4285,9 @@
|
|
|
4268
4285
|
|
|
4269
4286
|
const maxAngle = 360, moveSpeedFactor$1 = 10, defaultDistance = 0;
|
|
4270
4287
|
class WobbleUpdater {
|
|
4271
|
-
|
|
4288
|
+
#container;
|
|
4272
4289
|
constructor(container) {
|
|
4273
|
-
this
|
|
4290
|
+
this.#container = container;
|
|
4274
4291
|
}
|
|
4275
4292
|
init(particle) {
|
|
4276
4293
|
const wobbleOpt = particle.options.wobble;
|
|
@@ -4289,7 +4306,7 @@
|
|
|
4289
4306
|
};
|
|
4290
4307
|
}
|
|
4291
4308
|
particle.retina.wobbleDistance =
|
|
4292
|
-
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.
|
|
4309
|
+
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.#container.retina.pixelRatio;
|
|
4293
4310
|
}
|
|
4294
4311
|
isEnabled(particle) {
|
|
4295
4312
|
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
|
|
@@ -4304,12 +4321,12 @@
|
|
|
4304
4321
|
if (!this.isEnabled(particle)) {
|
|
4305
4322
|
return;
|
|
4306
4323
|
}
|
|
4307
|
-
updateWobble(this
|
|
4324
|
+
updateWobble(this.#container, particle, delta);
|
|
4308
4325
|
}
|
|
4309
4326
|
}
|
|
4310
4327
|
|
|
4311
4328
|
async function loadWobbleUpdater(engine) {
|
|
4312
|
-
engine.checkVersion("4.0
|
|
4329
|
+
engine.checkVersion("4.1.0");
|
|
4313
4330
|
await engine.pluginManager.register(e => {
|
|
4314
4331
|
e.pluginManager.addParticleUpdater("wobble", container => {
|
|
4315
4332
|
return Promise.resolve(new WobbleUpdater(container));
|
|
@@ -4436,58 +4453,58 @@
|
|
|
4436
4453
|
}
|
|
4437
4454
|
}
|
|
4438
4455
|
class RenderManager {
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4456
|
+
#canvasClearPlugins;
|
|
4457
|
+
#canvasManager;
|
|
4458
|
+
#canvasPaintPlugins;
|
|
4459
|
+
#clearDrawPlugins;
|
|
4460
|
+
#colorPlugins;
|
|
4461
|
+
#container;
|
|
4462
|
+
#context;
|
|
4463
|
+
#contextSettings;
|
|
4464
|
+
#drawParticlePlugins;
|
|
4465
|
+
#drawParticlesCleanupPlugins;
|
|
4466
|
+
#drawParticlesSetupPlugins;
|
|
4467
|
+
#drawPlugins;
|
|
4468
|
+
#drawSettingsCleanupPlugins;
|
|
4469
|
+
#drawSettingsSetupPlugins;
|
|
4470
|
+
#pluginManager;
|
|
4471
|
+
#postDrawUpdaters;
|
|
4472
|
+
#preDrawUpdaters;
|
|
4473
|
+
#reusableColorStyles = {};
|
|
4474
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4475
|
+
#reusableTransform = {};
|
|
4459
4476
|
constructor(pluginManager, container, canvasManager) {
|
|
4460
|
-
this
|
|
4461
|
-
this
|
|
4462
|
-
this
|
|
4463
|
-
this
|
|
4464
|
-
this
|
|
4465
|
-
this
|
|
4466
|
-
this
|
|
4467
|
-
this
|
|
4468
|
-
this
|
|
4469
|
-
this
|
|
4470
|
-
this
|
|
4471
|
-
this
|
|
4472
|
-
this
|
|
4473
|
-
this
|
|
4474
|
-
this
|
|
4475
|
-
this
|
|
4477
|
+
this.#pluginManager = pluginManager;
|
|
4478
|
+
this.#container = container;
|
|
4479
|
+
this.#canvasManager = canvasManager;
|
|
4480
|
+
this.#context = null;
|
|
4481
|
+
this.#preDrawUpdaters = [];
|
|
4482
|
+
this.#postDrawUpdaters = [];
|
|
4483
|
+
this.#colorPlugins = [];
|
|
4484
|
+
this.#canvasClearPlugins = [];
|
|
4485
|
+
this.#canvasPaintPlugins = [];
|
|
4486
|
+
this.#clearDrawPlugins = [];
|
|
4487
|
+
this.#drawParticlePlugins = [];
|
|
4488
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4489
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4490
|
+
this.#drawPlugins = [];
|
|
4491
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4492
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4476
4493
|
}
|
|
4477
4494
|
get settings() {
|
|
4478
|
-
return this
|
|
4495
|
+
return this.#contextSettings;
|
|
4479
4496
|
}
|
|
4480
4497
|
canvasClear() {
|
|
4481
|
-
if (!this.
|
|
4498
|
+
if (!this.#container.actualOptions.clear) {
|
|
4482
4499
|
return;
|
|
4483
4500
|
}
|
|
4484
4501
|
this.draw(ctx => {
|
|
4485
|
-
clear(ctx, this.
|
|
4502
|
+
clear(ctx, this.#canvasManager.size);
|
|
4486
4503
|
});
|
|
4487
4504
|
}
|
|
4488
4505
|
clear() {
|
|
4489
4506
|
let pluginHandled = false;
|
|
4490
|
-
for (const plugin of this
|
|
4507
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4491
4508
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4492
4509
|
if (pluginHandled) {
|
|
4493
4510
|
break;
|
|
@@ -4500,21 +4517,21 @@
|
|
|
4500
4517
|
}
|
|
4501
4518
|
destroy() {
|
|
4502
4519
|
this.stop();
|
|
4503
|
-
this
|
|
4504
|
-
this
|
|
4505
|
-
this
|
|
4506
|
-
this
|
|
4507
|
-
this
|
|
4508
|
-
this
|
|
4509
|
-
this
|
|
4510
|
-
this
|
|
4511
|
-
this
|
|
4512
|
-
this
|
|
4513
|
-
this
|
|
4514
|
-
this
|
|
4520
|
+
this.#preDrawUpdaters = [];
|
|
4521
|
+
this.#postDrawUpdaters = [];
|
|
4522
|
+
this.#colorPlugins = [];
|
|
4523
|
+
this.#canvasClearPlugins = [];
|
|
4524
|
+
this.#canvasPaintPlugins = [];
|
|
4525
|
+
this.#clearDrawPlugins = [];
|
|
4526
|
+
this.#drawParticlePlugins = [];
|
|
4527
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4528
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4529
|
+
this.#drawPlugins = [];
|
|
4530
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4531
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4515
4532
|
}
|
|
4516
4533
|
draw(cb) {
|
|
4517
|
-
const ctx = this
|
|
4534
|
+
const ctx = this.#context;
|
|
4518
4535
|
if (!ctx) {
|
|
4519
4536
|
return;
|
|
4520
4537
|
}
|
|
@@ -4529,21 +4546,21 @@
|
|
|
4529
4546
|
return;
|
|
4530
4547
|
}
|
|
4531
4548
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4532
|
-
let [fColor, sColor] = this
|
|
4549
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4533
4550
|
fColor ??= pfColor;
|
|
4534
4551
|
sColor ??= psColor;
|
|
4535
4552
|
if (!fColor && !sColor) {
|
|
4536
4553
|
return;
|
|
4537
4554
|
}
|
|
4538
|
-
const container = this
|
|
4555
|
+
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;
|
|
4539
4556
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4540
4557
|
colorStyles.fill = fill;
|
|
4541
4558
|
colorStyles.stroke = stroke;
|
|
4542
4559
|
this.draw((context) => {
|
|
4543
|
-
for (const plugin of this
|
|
4560
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4544
4561
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4545
4562
|
}
|
|
4546
|
-
this
|
|
4563
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4547
4564
|
drawParticle({
|
|
4548
4565
|
container,
|
|
4549
4566
|
context,
|
|
@@ -4554,35 +4571,35 @@
|
|
|
4554
4571
|
opacity: opacity,
|
|
4555
4572
|
transform,
|
|
4556
4573
|
});
|
|
4557
|
-
this
|
|
4558
|
-
for (const plugin of this
|
|
4574
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4575
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4559
4576
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4560
4577
|
}
|
|
4561
4578
|
});
|
|
4562
4579
|
}
|
|
4563
4580
|
drawParticlePlugins(particle, delta) {
|
|
4564
4581
|
this.draw(ctx => {
|
|
4565
|
-
for (const plugin of this
|
|
4582
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4566
4583
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4567
4584
|
}
|
|
4568
4585
|
});
|
|
4569
4586
|
}
|
|
4570
4587
|
drawParticles(delta) {
|
|
4571
|
-
const { particles } = this
|
|
4588
|
+
const { particles } = this.#container;
|
|
4572
4589
|
this.clear();
|
|
4573
4590
|
particles.update(delta);
|
|
4574
4591
|
this.draw(ctx => {
|
|
4575
|
-
for (const plugin of this
|
|
4592
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4576
4593
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4577
4594
|
}
|
|
4578
|
-
for (const plugin of this
|
|
4595
|
+
for (const plugin of this.#drawPlugins) {
|
|
4579
4596
|
plugin.draw?.(ctx, delta);
|
|
4580
4597
|
}
|
|
4581
4598
|
particles.drawParticles(delta);
|
|
4582
|
-
for (const plugin of this
|
|
4599
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4583
4600
|
plugin.clearDraw?.(ctx, delta);
|
|
4584
4601
|
}
|
|
4585
|
-
for (const plugin of this
|
|
4602
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4586
4603
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4587
4604
|
}
|
|
4588
4605
|
});
|
|
@@ -4593,64 +4610,64 @@
|
|
|
4593
4610
|
this.paint();
|
|
4594
4611
|
}
|
|
4595
4612
|
initPlugins() {
|
|
4596
|
-
this
|
|
4597
|
-
this
|
|
4598
|
-
this
|
|
4599
|
-
this
|
|
4600
|
-
this
|
|
4601
|
-
this
|
|
4602
|
-
this
|
|
4603
|
-
this
|
|
4604
|
-
this
|
|
4605
|
-
this
|
|
4606
|
-
for (const plugin of this.
|
|
4613
|
+
this.#colorPlugins = [];
|
|
4614
|
+
this.#canvasClearPlugins = [];
|
|
4615
|
+
this.#canvasPaintPlugins = [];
|
|
4616
|
+
this.#clearDrawPlugins = [];
|
|
4617
|
+
this.#drawParticlePlugins = [];
|
|
4618
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4619
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4620
|
+
this.#drawPlugins = [];
|
|
4621
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4622
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4623
|
+
for (const plugin of this.#container.plugins) {
|
|
4607
4624
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4608
|
-
this.
|
|
4625
|
+
this.#colorPlugins.push(plugin);
|
|
4609
4626
|
}
|
|
4610
4627
|
if (plugin.canvasClear) {
|
|
4611
|
-
this.
|
|
4628
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4612
4629
|
}
|
|
4613
4630
|
if (plugin.canvasPaint) {
|
|
4614
|
-
this.
|
|
4631
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4615
4632
|
}
|
|
4616
4633
|
if (plugin.drawParticle) {
|
|
4617
|
-
this.
|
|
4634
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4618
4635
|
}
|
|
4619
4636
|
if (plugin.drawParticleSetup) {
|
|
4620
|
-
this.
|
|
4637
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4621
4638
|
}
|
|
4622
4639
|
if (plugin.drawParticleCleanup) {
|
|
4623
|
-
this.
|
|
4640
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4624
4641
|
}
|
|
4625
4642
|
if (plugin.draw) {
|
|
4626
|
-
this.
|
|
4643
|
+
this.#drawPlugins.push(plugin);
|
|
4627
4644
|
}
|
|
4628
4645
|
if (plugin.drawSettingsSetup) {
|
|
4629
|
-
this.
|
|
4646
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4630
4647
|
}
|
|
4631
4648
|
if (plugin.drawSettingsCleanup) {
|
|
4632
|
-
this.
|
|
4649
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4633
4650
|
}
|
|
4634
4651
|
if (plugin.clearDraw) {
|
|
4635
|
-
this.
|
|
4652
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4636
4653
|
}
|
|
4637
4654
|
}
|
|
4638
4655
|
}
|
|
4639
4656
|
initUpdaters() {
|
|
4640
|
-
this
|
|
4641
|
-
this
|
|
4642
|
-
for (const updater of this.
|
|
4657
|
+
this.#preDrawUpdaters = [];
|
|
4658
|
+
this.#postDrawUpdaters = [];
|
|
4659
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4643
4660
|
if (updater.afterDraw) {
|
|
4644
|
-
this.
|
|
4661
|
+
this.#postDrawUpdaters.push(updater);
|
|
4645
4662
|
}
|
|
4646
4663
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4647
|
-
this.
|
|
4664
|
+
this.#preDrawUpdaters.push(updater);
|
|
4648
4665
|
}
|
|
4649
4666
|
}
|
|
4650
4667
|
}
|
|
4651
4668
|
paint() {
|
|
4652
4669
|
let handled = false;
|
|
4653
|
-
for (const plugin of this
|
|
4670
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4654
4671
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4655
4672
|
if (handled) {
|
|
4656
4673
|
break;
|
|
@@ -4663,35 +4680,35 @@
|
|
|
4663
4680
|
}
|
|
4664
4681
|
paintBase(baseColor) {
|
|
4665
4682
|
this.draw(ctx => {
|
|
4666
|
-
paintBase(ctx, this.
|
|
4683
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4667
4684
|
});
|
|
4668
4685
|
}
|
|
4669
4686
|
paintImage(image, opacity) {
|
|
4670
4687
|
this.draw(ctx => {
|
|
4671
|
-
paintImage(ctx, this.
|
|
4688
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4672
4689
|
});
|
|
4673
4690
|
}
|
|
4674
4691
|
setContext(context) {
|
|
4675
|
-
this
|
|
4676
|
-
if (this
|
|
4677
|
-
this.
|
|
4692
|
+
this.#context = context;
|
|
4693
|
+
if (this.#context) {
|
|
4694
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4678
4695
|
}
|
|
4679
4696
|
}
|
|
4680
4697
|
setContextSettings(settings) {
|
|
4681
|
-
this
|
|
4698
|
+
this.#contextSettings = settings;
|
|
4682
4699
|
}
|
|
4683
4700
|
stop() {
|
|
4684
4701
|
this.draw(ctx => {
|
|
4685
|
-
clear(ctx, this.
|
|
4702
|
+
clear(ctx, this.#canvasManager.size);
|
|
4686
4703
|
});
|
|
4687
4704
|
}
|
|
4688
|
-
|
|
4689
|
-
for (const updater of this
|
|
4705
|
+
#applyPostDrawUpdaters = particle => {
|
|
4706
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4690
4707
|
updater.afterDraw?.(particle);
|
|
4691
4708
|
}
|
|
4692
4709
|
};
|
|
4693
|
-
|
|
4694
|
-
for (const updater of this
|
|
4710
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4711
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4695
4712
|
if (updater.getColorStyles) {
|
|
4696
4713
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4697
4714
|
if (fill) {
|
|
@@ -4710,22 +4727,22 @@
|
|
|
4710
4727
|
updater.beforeDraw?.(particle);
|
|
4711
4728
|
}
|
|
4712
4729
|
};
|
|
4713
|
-
|
|
4730
|
+
#getPluginParticleColors = particle => {
|
|
4714
4731
|
let fColor, sColor;
|
|
4715
|
-
for (const plugin of this
|
|
4732
|
+
for (const plugin of this.#colorPlugins) {
|
|
4716
4733
|
if (!fColor && plugin.particleFillColor) {
|
|
4717
|
-
fColor = rangeColorToHsl(this
|
|
4734
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4718
4735
|
}
|
|
4719
4736
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4720
|
-
sColor = rangeColorToHsl(this
|
|
4737
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4721
4738
|
}
|
|
4722
4739
|
if (fColor && sColor) {
|
|
4723
4740
|
break;
|
|
4724
4741
|
}
|
|
4725
4742
|
}
|
|
4726
|
-
this
|
|
4727
|
-
this
|
|
4728
|
-
return this
|
|
4743
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4744
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4745
|
+
return this.#reusablePluginColors;
|
|
4729
4746
|
};
|
|
4730
4747
|
}
|
|
4731
4748
|
|
|
@@ -4783,53 +4800,53 @@
|
|
|
4783
4800
|
renderCanvas;
|
|
4784
4801
|
size;
|
|
4785
4802
|
zoom = defaultZoom;
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4803
|
+
#container;
|
|
4804
|
+
#generated;
|
|
4805
|
+
#mutationObserver;
|
|
4806
|
+
#originalStyle;
|
|
4807
|
+
#pluginManager;
|
|
4808
|
+
#pointerEvents;
|
|
4809
|
+
#resizePlugins;
|
|
4810
|
+
#standardSize;
|
|
4811
|
+
#zoomCenter;
|
|
4795
4812
|
constructor(pluginManager, container) {
|
|
4796
|
-
this
|
|
4797
|
-
this
|
|
4813
|
+
this.#pluginManager = pluginManager;
|
|
4814
|
+
this.#container = container;
|
|
4798
4815
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4799
|
-
this
|
|
4816
|
+
this.#standardSize = {
|
|
4800
4817
|
height: 0,
|
|
4801
4818
|
width: 0,
|
|
4802
4819
|
};
|
|
4803
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4820
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4804
4821
|
this.size = {
|
|
4805
4822
|
height: stdSize.height * pxRatio,
|
|
4806
4823
|
width: stdSize.width * pxRatio,
|
|
4807
4824
|
};
|
|
4808
|
-
this
|
|
4809
|
-
this
|
|
4810
|
-
this
|
|
4825
|
+
this.#generated = false;
|
|
4826
|
+
this.#resizePlugins = [];
|
|
4827
|
+
this.#pointerEvents = "none";
|
|
4811
4828
|
}
|
|
4812
|
-
get
|
|
4813
|
-
return this.
|
|
4829
|
+
get #fullScreen() {
|
|
4830
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4814
4831
|
}
|
|
4815
4832
|
destroy() {
|
|
4816
4833
|
this.stop();
|
|
4817
|
-
if (this
|
|
4834
|
+
if (this.#generated) {
|
|
4818
4835
|
const element = this.domElement;
|
|
4819
4836
|
element?.remove();
|
|
4820
4837
|
this.domElement = undefined;
|
|
4821
4838
|
this.renderCanvas = undefined;
|
|
4822
4839
|
}
|
|
4823
4840
|
else {
|
|
4824
|
-
this
|
|
4841
|
+
this.#resetOriginalStyle();
|
|
4825
4842
|
}
|
|
4826
4843
|
this.render.destroy();
|
|
4827
|
-
this
|
|
4844
|
+
this.#resizePlugins = [];
|
|
4828
4845
|
}
|
|
4829
4846
|
getZoomCenter() {
|
|
4830
|
-
const pxRatio = this.
|
|
4831
|
-
if (this
|
|
4832
|
-
return this
|
|
4847
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4848
|
+
if (this.#zoomCenter) {
|
|
4849
|
+
return this.#zoomCenter;
|
|
4833
4850
|
}
|
|
4834
4851
|
return {
|
|
4835
4852
|
x: (width * half) / pxRatio,
|
|
@@ -4837,20 +4854,20 @@
|
|
|
4837
4854
|
};
|
|
4838
4855
|
}
|
|
4839
4856
|
init() {
|
|
4840
|
-
this
|
|
4857
|
+
this.#safeMutationObserver(obs => {
|
|
4841
4858
|
obs.disconnect();
|
|
4842
4859
|
});
|
|
4843
|
-
this
|
|
4860
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4844
4861
|
for (const record of records) {
|
|
4845
4862
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4846
|
-
this
|
|
4863
|
+
this.#repairStyle();
|
|
4847
4864
|
}
|
|
4848
4865
|
}
|
|
4849
4866
|
});
|
|
4850
4867
|
this.resize();
|
|
4851
|
-
this
|
|
4868
|
+
this.#initStyle();
|
|
4852
4869
|
this.initBackground();
|
|
4853
|
-
this
|
|
4870
|
+
this.#safeMutationObserver(obs => {
|
|
4854
4871
|
const element = this.domElement;
|
|
4855
4872
|
if (!element || !(element instanceof Node)) {
|
|
4856
4873
|
return;
|
|
@@ -4861,13 +4878,13 @@
|
|
|
4861
4878
|
this.render.init();
|
|
4862
4879
|
}
|
|
4863
4880
|
initBackground() {
|
|
4864
|
-
const
|
|
4881
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4865
4882
|
if (!element) {
|
|
4866
4883
|
return;
|
|
4867
4884
|
}
|
|
4868
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4885
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4869
4886
|
if (color) {
|
|
4870
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4887
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4871
4888
|
}
|
|
4872
4889
|
else {
|
|
4873
4890
|
elementStyle.backgroundColor = "";
|
|
@@ -4878,27 +4895,27 @@
|
|
|
4878
4895
|
elementStyle.backgroundSize = background.size || "";
|
|
4879
4896
|
}
|
|
4880
4897
|
initPlugins() {
|
|
4881
|
-
this
|
|
4882
|
-
for (const plugin of this.
|
|
4898
|
+
this.#resizePlugins = [];
|
|
4899
|
+
for (const plugin of this.#container.plugins) {
|
|
4883
4900
|
if (plugin.resize) {
|
|
4884
|
-
this.
|
|
4901
|
+
this.#resizePlugins.push(plugin);
|
|
4885
4902
|
}
|
|
4886
4903
|
}
|
|
4887
4904
|
}
|
|
4888
4905
|
loadCanvas(canvas) {
|
|
4889
|
-
if (this
|
|
4906
|
+
if (this.#generated && this.domElement) {
|
|
4890
4907
|
this.domElement.remove();
|
|
4891
4908
|
}
|
|
4892
|
-
const container = this
|
|
4909
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4893
4910
|
this.domElement = domCanvas;
|
|
4894
|
-
this
|
|
4911
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4895
4912
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4896
4913
|
const domElement = this.domElement;
|
|
4897
4914
|
if (domElement) {
|
|
4898
4915
|
domElement.ariaHidden = "true";
|
|
4899
|
-
this
|
|
4916
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4900
4917
|
}
|
|
4901
|
-
const standardSize = this
|
|
4918
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4902
4919
|
if (domElement) {
|
|
4903
4920
|
standardSize.height = domElement.offsetHeight;
|
|
4904
4921
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4907,7 +4924,7 @@
|
|
|
4907
4924
|
standardSize.height = renderCanvas.height;
|
|
4908
4925
|
standardSize.width = renderCanvas.width;
|
|
4909
4926
|
}
|
|
4910
|
-
const pxRatio = this.
|
|
4927
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4911
4928
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4912
4929
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4913
4930
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4918,12 +4935,12 @@
|
|
|
4918
4935
|
willReadFrequently: false,
|
|
4919
4936
|
});
|
|
4920
4937
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4921
|
-
this
|
|
4938
|
+
this.#safeMutationObserver(obs => {
|
|
4922
4939
|
obs.disconnect();
|
|
4923
4940
|
});
|
|
4924
4941
|
container.retina.init();
|
|
4925
4942
|
this.initBackground();
|
|
4926
|
-
this
|
|
4943
|
+
this.#safeMutationObserver(obs => {
|
|
4927
4944
|
const element = this.domElement;
|
|
4928
4945
|
if (!element || !(element instanceof Node)) {
|
|
4929
4946
|
return;
|
|
@@ -4936,11 +4953,11 @@
|
|
|
4936
4953
|
if (!element) {
|
|
4937
4954
|
return false;
|
|
4938
4955
|
}
|
|
4939
|
-
const container = this
|
|
4956
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4940
4957
|
if (renderCanvas === undefined) {
|
|
4941
4958
|
return false;
|
|
4942
4959
|
}
|
|
4943
|
-
const currentSize = container.canvas
|
|
4960
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4944
4961
|
width: element.offsetWidth,
|
|
4945
4962
|
height: element.offsetHeight,
|
|
4946
4963
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4959,7 +4976,7 @@
|
|
|
4959
4976
|
const canvasSize = this.size;
|
|
4960
4977
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4961
4978
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4962
|
-
if (this.
|
|
4979
|
+
if (this.#container.started) {
|
|
4963
4980
|
container.particles.setResizeFactor({
|
|
4964
4981
|
width: currentSize.width / oldSize.width,
|
|
4965
4982
|
height: currentSize.height / oldSize.height,
|
|
@@ -4972,46 +4989,46 @@
|
|
|
4972
4989
|
if (!element) {
|
|
4973
4990
|
return;
|
|
4974
4991
|
}
|
|
4975
|
-
this
|
|
4976
|
-
this
|
|
4992
|
+
this.#pointerEvents = type;
|
|
4993
|
+
this.#repairStyle();
|
|
4977
4994
|
}
|
|
4978
4995
|
setZoom(zoomLevel, center) {
|
|
4979
4996
|
this.zoom = zoomLevel;
|
|
4980
|
-
this
|
|
4997
|
+
this.#zoomCenter = center;
|
|
4981
4998
|
}
|
|
4982
4999
|
stop() {
|
|
4983
|
-
this
|
|
5000
|
+
this.#safeMutationObserver(obs => {
|
|
4984
5001
|
obs.disconnect();
|
|
4985
5002
|
});
|
|
4986
|
-
this
|
|
5003
|
+
this.#mutationObserver = undefined;
|
|
4987
5004
|
this.render.stop();
|
|
4988
5005
|
}
|
|
4989
5006
|
async windowResize() {
|
|
4990
5007
|
if (!this.domElement || !this.resize()) {
|
|
4991
5008
|
return;
|
|
4992
5009
|
}
|
|
4993
|
-
const container = this
|
|
5010
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4994
5011
|
container.particles.setDensity();
|
|
4995
|
-
this
|
|
5012
|
+
this.#applyResizePlugins();
|
|
4996
5013
|
if (needsRefresh) {
|
|
4997
5014
|
await container.refresh();
|
|
4998
5015
|
}
|
|
4999
5016
|
}
|
|
5000
|
-
|
|
5001
|
-
for (const plugin of this
|
|
5017
|
+
#applyResizePlugins = () => {
|
|
5018
|
+
for (const plugin of this.#resizePlugins) {
|
|
5002
5019
|
plugin.resize?.();
|
|
5003
5020
|
}
|
|
5004
5021
|
};
|
|
5005
|
-
|
|
5006
|
-
const element = this.domElement, options = this.
|
|
5022
|
+
#initStyle = () => {
|
|
5023
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
5007
5024
|
if (!element) {
|
|
5008
5025
|
return;
|
|
5009
5026
|
}
|
|
5010
|
-
if (this
|
|
5011
|
-
this
|
|
5027
|
+
if (this.#fullScreen) {
|
|
5028
|
+
this.#setFullScreenStyle();
|
|
5012
5029
|
}
|
|
5013
5030
|
else {
|
|
5014
|
-
this
|
|
5031
|
+
this.#resetOriginalStyle();
|
|
5015
5032
|
}
|
|
5016
5033
|
for (const key in options.style) {
|
|
5017
5034
|
if (!key || !(key in options.style)) {
|
|
@@ -5024,72 +5041,72 @@
|
|
|
5024
5041
|
element.style.setProperty(key, value, "important");
|
|
5025
5042
|
}
|
|
5026
5043
|
};
|
|
5027
|
-
|
|
5044
|
+
#repairStyle = () => {
|
|
5028
5045
|
const element = this.domElement;
|
|
5029
5046
|
if (!element) {
|
|
5030
5047
|
return;
|
|
5031
5048
|
}
|
|
5032
|
-
this
|
|
5049
|
+
this.#safeMutationObserver(observer => {
|
|
5033
5050
|
observer.disconnect();
|
|
5034
5051
|
});
|
|
5035
|
-
this
|
|
5052
|
+
this.#initStyle();
|
|
5036
5053
|
this.initBackground();
|
|
5037
|
-
const pointerEvents = this
|
|
5054
|
+
const pointerEvents = this.#pointerEvents;
|
|
5038
5055
|
element.style.pointerEvents = pointerEvents;
|
|
5039
5056
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
5040
|
-
this
|
|
5057
|
+
this.#safeMutationObserver(observer => {
|
|
5041
5058
|
if (!(element instanceof Node)) {
|
|
5042
5059
|
return;
|
|
5043
5060
|
}
|
|
5044
5061
|
observer.observe(element, { attributes: true });
|
|
5045
5062
|
});
|
|
5046
5063
|
};
|
|
5047
|
-
|
|
5048
|
-
const element = this.domElement, originalStyle = this
|
|
5064
|
+
#resetOriginalStyle = () => {
|
|
5065
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
5049
5066
|
if (!element || !originalStyle) {
|
|
5050
5067
|
return;
|
|
5051
5068
|
}
|
|
5052
5069
|
setStyle(element, originalStyle, true);
|
|
5053
5070
|
};
|
|
5054
|
-
|
|
5055
|
-
if (!this
|
|
5071
|
+
#safeMutationObserver = callback => {
|
|
5072
|
+
if (!this.#mutationObserver) {
|
|
5056
5073
|
return;
|
|
5057
5074
|
}
|
|
5058
|
-
callback(this
|
|
5075
|
+
callback(this.#mutationObserver);
|
|
5059
5076
|
};
|
|
5060
|
-
|
|
5077
|
+
#setFullScreenStyle = () => {
|
|
5061
5078
|
const element = this.domElement;
|
|
5062
5079
|
if (!element) {
|
|
5063
5080
|
return;
|
|
5064
5081
|
}
|
|
5065
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5082
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
5066
5083
|
};
|
|
5067
5084
|
}
|
|
5068
5085
|
|
|
5069
5086
|
class EventListeners {
|
|
5070
|
-
container;
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5087
|
+
#container;
|
|
5088
|
+
#handlers;
|
|
5089
|
+
#resizeObserver;
|
|
5090
|
+
#resizeTimeout;
|
|
5074
5091
|
constructor(container) {
|
|
5075
|
-
this
|
|
5076
|
-
this
|
|
5092
|
+
this.#container = container;
|
|
5093
|
+
this.#handlers = {
|
|
5077
5094
|
visibilityChange: () => {
|
|
5078
|
-
this
|
|
5095
|
+
this.#handleVisibilityChange();
|
|
5079
5096
|
},
|
|
5080
5097
|
resize: () => {
|
|
5081
|
-
this
|
|
5098
|
+
this.#handleWindowResize();
|
|
5082
5099
|
},
|
|
5083
5100
|
};
|
|
5084
5101
|
}
|
|
5085
5102
|
addListeners() {
|
|
5086
|
-
this
|
|
5103
|
+
this.#manageListeners(true);
|
|
5087
5104
|
}
|
|
5088
5105
|
removeListeners() {
|
|
5089
|
-
this
|
|
5106
|
+
this.#manageListeners(false);
|
|
5090
5107
|
}
|
|
5091
|
-
|
|
5092
|
-
const container = this
|
|
5108
|
+
#handleVisibilityChange = () => {
|
|
5109
|
+
const container = this.#container, options = container.actualOptions;
|
|
5093
5110
|
if (!options.pauseOnBlur) {
|
|
5094
5111
|
return;
|
|
5095
5112
|
}
|
|
@@ -5107,24 +5124,24 @@
|
|
|
5107
5124
|
}
|
|
5108
5125
|
}
|
|
5109
5126
|
};
|
|
5110
|
-
|
|
5111
|
-
if (this
|
|
5112
|
-
clearTimeout(this
|
|
5113
|
-
|
|
5127
|
+
#handleWindowResize = () => {
|
|
5128
|
+
if (this.#resizeTimeout) {
|
|
5129
|
+
clearTimeout(this.#resizeTimeout);
|
|
5130
|
+
this.#resizeTimeout = undefined;
|
|
5114
5131
|
}
|
|
5115
5132
|
const handleResize = async () => {
|
|
5116
|
-
const canvas = this
|
|
5133
|
+
const canvas = this.#container.canvas;
|
|
5117
5134
|
await canvas.windowResize();
|
|
5118
5135
|
};
|
|
5119
|
-
this
|
|
5136
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5120
5137
|
};
|
|
5121
|
-
|
|
5122
|
-
const handlers = this
|
|
5123
|
-
this
|
|
5138
|
+
#manageListeners = add => {
|
|
5139
|
+
const handlers = this.#handlers;
|
|
5140
|
+
this.#manageResize(add);
|
|
5124
5141
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5125
5142
|
};
|
|
5126
|
-
|
|
5127
|
-
const handlers = this
|
|
5143
|
+
#manageResize = add => {
|
|
5144
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5128
5145
|
if (!options.resize.enable) {
|
|
5129
5146
|
return;
|
|
5130
5147
|
}
|
|
@@ -5133,22 +5150,22 @@
|
|
|
5133
5150
|
return;
|
|
5134
5151
|
}
|
|
5135
5152
|
const canvasEl = container.canvas.domElement;
|
|
5136
|
-
if (this
|
|
5153
|
+
if (this.#resizeObserver && !add) {
|
|
5137
5154
|
if (canvasEl) {
|
|
5138
|
-
this.
|
|
5155
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5139
5156
|
}
|
|
5140
|
-
this.
|
|
5141
|
-
|
|
5157
|
+
this.#resizeObserver.disconnect();
|
|
5158
|
+
this.#resizeObserver = undefined;
|
|
5142
5159
|
}
|
|
5143
|
-
else if (!this
|
|
5144
|
-
this
|
|
5160
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5161
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5145
5162
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5146
5163
|
if (!entry) {
|
|
5147
5164
|
return;
|
|
5148
5165
|
}
|
|
5149
|
-
this
|
|
5166
|
+
this.#handleWindowResize();
|
|
5150
5167
|
});
|
|
5151
|
-
this.
|
|
5168
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5152
5169
|
}
|
|
5153
5170
|
};
|
|
5154
5171
|
}
|
|
@@ -5221,24 +5238,24 @@
|
|
|
5221
5238
|
unbreakable;
|
|
5222
5239
|
velocity;
|
|
5223
5240
|
zIndexFactor;
|
|
5224
|
-
|
|
5241
|
+
#cachedOpacityData = {
|
|
5225
5242
|
fillOpacity: defaultOpacity$1,
|
|
5226
5243
|
opacity: defaultOpacity$1,
|
|
5227
5244
|
strokeOpacity: defaultOpacity$1,
|
|
5228
5245
|
};
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5246
|
+
#cachedPosition = Vector3d.origin;
|
|
5247
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5248
|
+
#cachedTransform = {
|
|
5232
5249
|
a: 1,
|
|
5233
5250
|
b: 0,
|
|
5234
5251
|
c: 0,
|
|
5235
5252
|
d: 1,
|
|
5236
5253
|
};
|
|
5237
|
-
|
|
5238
|
-
|
|
5254
|
+
#container;
|
|
5255
|
+
#pluginManager;
|
|
5239
5256
|
constructor(pluginManager, container) {
|
|
5240
|
-
this
|
|
5241
|
-
this
|
|
5257
|
+
this.#pluginManager = pluginManager;
|
|
5258
|
+
this.#container = container;
|
|
5242
5259
|
}
|
|
5243
5260
|
destroy(override) {
|
|
5244
5261
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5247,7 +5264,7 @@
|
|
|
5247
5264
|
this.destroyed = true;
|
|
5248
5265
|
this.bubble.inRange = false;
|
|
5249
5266
|
this.slow.inRange = false;
|
|
5250
|
-
const container = this
|
|
5267
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5251
5268
|
shapeDrawer?.particleDestroy?.(this);
|
|
5252
5269
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5253
5270
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5255,12 +5272,12 @@
|
|
|
5255
5272
|
for (const updater of container.particleUpdaters) {
|
|
5256
5273
|
updater.particleDestroyed?.(this, override);
|
|
5257
5274
|
}
|
|
5258
|
-
this.
|
|
5275
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5259
5276
|
particle: this,
|
|
5260
5277
|
});
|
|
5261
5278
|
}
|
|
5262
5279
|
draw(delta) {
|
|
5263
|
-
const container = this
|
|
5280
|
+
const container = this.#container, render = container.canvas.render;
|
|
5264
5281
|
render.drawParticlePlugins(this, delta);
|
|
5265
5282
|
render.drawParticle(this, delta);
|
|
5266
5283
|
}
|
|
@@ -5268,50 +5285,50 @@
|
|
|
5268
5285
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5269
5286
|
}
|
|
5270
5287
|
getFillColor() {
|
|
5271
|
-
return this
|
|
5288
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5272
5289
|
}
|
|
5273
5290
|
getMass() {
|
|
5274
5291
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5275
5292
|
}
|
|
5276
5293
|
getOpacity() {
|
|
5277
5294
|
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;
|
|
5278
|
-
this.
|
|
5279
|
-
this.
|
|
5280
|
-
this.
|
|
5281
|
-
return this
|
|
5295
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5296
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5297
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5298
|
+
return this.#cachedOpacityData;
|
|
5282
5299
|
}
|
|
5283
5300
|
getPosition() {
|
|
5284
|
-
this.
|
|
5285
|
-
this.
|
|
5286
|
-
this.
|
|
5287
|
-
return this
|
|
5301
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5302
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5303
|
+
this.#cachedPosition.z = this.position.z;
|
|
5304
|
+
return this.#cachedPosition;
|
|
5288
5305
|
}
|
|
5289
5306
|
getRadius() {
|
|
5290
5307
|
return this.bubble.radius ?? this.size.value;
|
|
5291
5308
|
}
|
|
5292
5309
|
getRotateData() {
|
|
5293
5310
|
const angle = this.getAngle();
|
|
5294
|
-
this.
|
|
5295
|
-
this.
|
|
5296
|
-
return this
|
|
5311
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5312
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5313
|
+
return this.#cachedRotateData;
|
|
5297
5314
|
}
|
|
5298
5315
|
getStrokeColor() {
|
|
5299
|
-
return this
|
|
5316
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5300
5317
|
}
|
|
5301
5318
|
getTransformData(externalTransform) {
|
|
5302
5319
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5303
|
-
this.
|
|
5304
|
-
this.
|
|
5320
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5321
|
+
this.#cachedTransform.b = rotating
|
|
5305
5322
|
? rotateData.sin * (externalTransform.b ?? identity$2)
|
|
5306
5323
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5307
|
-
this.
|
|
5324
|
+
this.#cachedTransform.c = rotating
|
|
5308
5325
|
? -rotateData.sin * (externalTransform.c ?? identity$2)
|
|
5309
5326
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5310
|
-
this.
|
|
5311
|
-
return this
|
|
5327
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5328
|
+
return this.#cachedTransform;
|
|
5312
5329
|
}
|
|
5313
5330
|
init(id, position, overrideOptions, group) {
|
|
5314
|
-
const container = this
|
|
5331
|
+
const container = this.#container;
|
|
5315
5332
|
this.id = id;
|
|
5316
5333
|
this.group = group;
|
|
5317
5334
|
this.justWarped = false;
|
|
@@ -5331,21 +5348,27 @@
|
|
|
5331
5348
|
moveSpeed: 0,
|
|
5332
5349
|
sizeAnimationSpeed: 0,
|
|
5333
5350
|
};
|
|
5351
|
+
this.size = {
|
|
5352
|
+
value: 1,
|
|
5353
|
+
max: 1,
|
|
5354
|
+
min: 1,
|
|
5355
|
+
enable: false,
|
|
5356
|
+
};
|
|
5334
5357
|
this.outType = ParticleOutType.normal;
|
|
5335
5358
|
this.ignoresResizeRatio = true;
|
|
5336
|
-
const
|
|
5359
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5337
5360
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5338
5361
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5339
5362
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5340
5363
|
if (overrideOptions) {
|
|
5341
|
-
if (overrideOptions.effect?.type) {
|
|
5364
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5342
5365
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5343
5366
|
if (effect) {
|
|
5344
5367
|
this.effect = effect;
|
|
5345
5368
|
effectOptions.load(overrideOptions.effect);
|
|
5346
5369
|
}
|
|
5347
5370
|
}
|
|
5348
|
-
if (overrideOptions.shape?.type) {
|
|
5371
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5349
5372
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5350
5373
|
if (shape) {
|
|
5351
5374
|
this.shape = shape;
|
|
@@ -5354,21 +5377,20 @@
|
|
|
5354
5377
|
}
|
|
5355
5378
|
}
|
|
5356
5379
|
if (this.effect === randomColorValue) {
|
|
5357
|
-
const availableEffects = [...this.
|
|
5380
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5358
5381
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5359
5382
|
}
|
|
5360
5383
|
if (this.shape === randomColorValue) {
|
|
5361
|
-
const availableShapes = [...this.
|
|
5384
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5362
5385
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5363
5386
|
}
|
|
5364
5387
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5365
5388
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5366
5389
|
particlesOptions.load(overrideOptions);
|
|
5367
|
-
const effectData = this.effectData;
|
|
5390
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5368
5391
|
if (effectData) {
|
|
5369
5392
|
particlesOptions.load(effectData.particles);
|
|
5370
5393
|
}
|
|
5371
|
-
const shapeData = this.shapeData;
|
|
5372
5394
|
if (shapeData) {
|
|
5373
5395
|
particlesOptions.load(shapeData.particles);
|
|
5374
5396
|
}
|
|
@@ -5376,7 +5398,9 @@
|
|
|
5376
5398
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5377
5399
|
this.options = particlesOptions;
|
|
5378
5400
|
container.retina.initParticle(this);
|
|
5379
|
-
|
|
5401
|
+
for (const updater of container.particleUpdaters) {
|
|
5402
|
+
updater.preInit?.(this);
|
|
5403
|
+
}
|
|
5380
5404
|
this.bubble = {
|
|
5381
5405
|
inRange: false,
|
|
5382
5406
|
};
|
|
@@ -5384,8 +5408,8 @@
|
|
|
5384
5408
|
inRange: false,
|
|
5385
5409
|
factor: 1,
|
|
5386
5410
|
};
|
|
5387
|
-
this
|
|
5388
|
-
this.initialVelocity = this
|
|
5411
|
+
this.#initPosition(position);
|
|
5412
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5389
5413
|
this.velocity = this.initialVelocity.copy();
|
|
5390
5414
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5391
5415
|
this.sides = 24;
|
|
@@ -5416,12 +5440,11 @@
|
|
|
5416
5440
|
plugin.particleCreated?.(this);
|
|
5417
5441
|
}
|
|
5418
5442
|
}
|
|
5419
|
-
isInsideCanvas() {
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
position.x <= canvasSize.width + radius);
|
|
5443
|
+
isInsideCanvas(direction) {
|
|
5444
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5445
|
+
}
|
|
5446
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5447
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5425
5448
|
}
|
|
5426
5449
|
isShowingBack() {
|
|
5427
5450
|
if (!this.roll) {
|
|
@@ -5446,13 +5469,13 @@
|
|
|
5446
5469
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5447
5470
|
}
|
|
5448
5471
|
reset() {
|
|
5449
|
-
for (const updater of this.
|
|
5472
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5450
5473
|
updater.reset?.(this);
|
|
5451
5474
|
}
|
|
5452
5475
|
}
|
|
5453
|
-
|
|
5476
|
+
#calcPosition = (position, zIndex) => {
|
|
5454
5477
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5455
|
-
const container = this
|
|
5478
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5456
5479
|
while (!signal.aborted) {
|
|
5457
5480
|
for (const plugin of plugins) {
|
|
5458
5481
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5464,10 +5487,10 @@
|
|
|
5464
5487
|
size: canvasSize,
|
|
5465
5488
|
position: posVec,
|
|
5466
5489
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5467
|
-
this
|
|
5468
|
-
this
|
|
5469
|
-
this
|
|
5470
|
-
this
|
|
5490
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5491
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5492
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5493
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5471
5494
|
let isValidPosition = true;
|
|
5472
5495
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5473
5496
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5483,8 +5506,8 @@
|
|
|
5483
5506
|
}
|
|
5484
5507
|
return posVec;
|
|
5485
5508
|
};
|
|
5486
|
-
|
|
5487
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5509
|
+
#calculateVelocity = () => {
|
|
5510
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5488
5511
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5489
5512
|
return res;
|
|
5490
5513
|
}
|
|
@@ -5500,27 +5523,86 @@
|
|
|
5500
5523
|
}
|
|
5501
5524
|
return res;
|
|
5502
5525
|
};
|
|
5503
|
-
|
|
5526
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5504
5527
|
fixOutMode({
|
|
5505
5528
|
outMode,
|
|
5506
5529
|
checkModes: [OutMode.bounce],
|
|
5507
5530
|
coord: pos.x,
|
|
5508
|
-
maxCoord: this.
|
|
5531
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5509
5532
|
setCb: (value) => (pos.x += value),
|
|
5510
5533
|
radius,
|
|
5511
5534
|
});
|
|
5512
5535
|
};
|
|
5513
|
-
|
|
5536
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5514
5537
|
fixOutMode({
|
|
5515
5538
|
outMode,
|
|
5516
5539
|
checkModes: [OutMode.bounce],
|
|
5517
5540
|
coord: pos.y,
|
|
5518
|
-
maxCoord: this.
|
|
5541
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5519
5542
|
setCb: (value) => (pos.y += value),
|
|
5520
5543
|
radius,
|
|
5521
5544
|
});
|
|
5522
5545
|
};
|
|
5523
|
-
|
|
5546
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5547
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5548
|
+
if (direction === OutModeDirection.bottom) {
|
|
5549
|
+
return {
|
|
5550
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5551
|
+
reason: "default",
|
|
5552
|
+
};
|
|
5553
|
+
}
|
|
5554
|
+
if (direction === OutModeDirection.left) {
|
|
5555
|
+
return {
|
|
5556
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5557
|
+
reason: "default",
|
|
5558
|
+
};
|
|
5559
|
+
}
|
|
5560
|
+
if (direction === OutModeDirection.right) {
|
|
5561
|
+
return {
|
|
5562
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5563
|
+
reason: "default",
|
|
5564
|
+
};
|
|
5565
|
+
}
|
|
5566
|
+
if (direction === OutModeDirection.top) {
|
|
5567
|
+
return {
|
|
5568
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5569
|
+
reason: "default",
|
|
5570
|
+
};
|
|
5571
|
+
}
|
|
5572
|
+
return {
|
|
5573
|
+
inside: position.x >= -radius &&
|
|
5574
|
+
position.y >= -radius &&
|
|
5575
|
+
position.y <= canvasSize.height + radius &&
|
|
5576
|
+
position.x <= canvasSize.width + radius,
|
|
5577
|
+
reason: "default",
|
|
5578
|
+
};
|
|
5579
|
+
};
|
|
5580
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5581
|
+
return {
|
|
5582
|
+
canvasSize: this.#container.canvas.size,
|
|
5583
|
+
direction,
|
|
5584
|
+
outMode,
|
|
5585
|
+
particle: this,
|
|
5586
|
+
radius: this.getRadius(),
|
|
5587
|
+
};
|
|
5588
|
+
};
|
|
5589
|
+
#getInsideCanvasResult = (data) => {
|
|
5590
|
+
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;
|
|
5591
|
+
if (!shapeCheck && !effectCheck) {
|
|
5592
|
+
return defaultResult;
|
|
5593
|
+
}
|
|
5594
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5595
|
+
if (shapeResult && effectResult) {
|
|
5596
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5597
|
+
return {
|
|
5598
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5599
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5600
|
+
reason: "combined",
|
|
5601
|
+
};
|
|
5602
|
+
}
|
|
5603
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5604
|
+
};
|
|
5605
|
+
#getRollColor = color => {
|
|
5524
5606
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5525
5607
|
return color;
|
|
5526
5608
|
}
|
|
@@ -5535,8 +5617,8 @@
|
|
|
5535
5617
|
}
|
|
5536
5618
|
return color;
|
|
5537
5619
|
};
|
|
5538
|
-
|
|
5539
|
-
const container = this
|
|
5620
|
+
#initPosition = position => {
|
|
5621
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5540
5622
|
if (!initialPosition) {
|
|
5541
5623
|
throw new Error("a valid position cannot be found for particle");
|
|
5542
5624
|
}
|
|
@@ -5559,45 +5641,58 @@
|
|
|
5559
5641
|
}
|
|
5560
5642
|
this.offset = Vector.origin;
|
|
5561
5643
|
};
|
|
5644
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5645
|
+
if (typeof result === "boolean") {
|
|
5646
|
+
return {
|
|
5647
|
+
inside: result,
|
|
5648
|
+
reason,
|
|
5649
|
+
};
|
|
5650
|
+
}
|
|
5651
|
+
return {
|
|
5652
|
+
inside: result.inside,
|
|
5653
|
+
margin: result.margin,
|
|
5654
|
+
reason: result.reason ?? reason,
|
|
5655
|
+
};
|
|
5656
|
+
};
|
|
5562
5657
|
}
|
|
5563
5658
|
|
|
5564
5659
|
class SpatialHashGrid {
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5660
|
+
#cellSize;
|
|
5661
|
+
#cells = new Map();
|
|
5662
|
+
#circlePool = [];
|
|
5663
|
+
#circlePoolIdx;
|
|
5664
|
+
#pendingCellSize;
|
|
5665
|
+
#rectanglePool = [];
|
|
5666
|
+
#rectanglePoolIdx;
|
|
5572
5667
|
constructor(cellSize) {
|
|
5573
|
-
this
|
|
5574
|
-
this
|
|
5575
|
-
this
|
|
5668
|
+
this.#cellSize = cellSize;
|
|
5669
|
+
this.#circlePoolIdx = 0;
|
|
5670
|
+
this.#rectanglePoolIdx = 0;
|
|
5576
5671
|
}
|
|
5577
5672
|
clear() {
|
|
5578
|
-
this.
|
|
5579
|
-
const pendingCellSize = this
|
|
5673
|
+
this.#cells.clear();
|
|
5674
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5580
5675
|
if (pendingCellSize) {
|
|
5581
|
-
this
|
|
5676
|
+
this.#cellSize = pendingCellSize;
|
|
5582
5677
|
}
|
|
5583
|
-
this
|
|
5678
|
+
this.#pendingCellSize = undefined;
|
|
5584
5679
|
}
|
|
5585
5680
|
insert(particle) {
|
|
5586
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5587
|
-
if (!this.
|
|
5588
|
-
this.
|
|
5681
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5682
|
+
if (!this.#cells.has(key)) {
|
|
5683
|
+
this.#cells.set(key, []);
|
|
5589
5684
|
}
|
|
5590
|
-
this.
|
|
5685
|
+
this.#cells.get(key)?.push(particle);
|
|
5591
5686
|
}
|
|
5592
5687
|
query(range, check, out = []) {
|
|
5593
|
-
const bounds = this
|
|
5688
|
+
const bounds = this.#getRangeBounds(range);
|
|
5594
5689
|
if (!bounds) {
|
|
5595
5690
|
return out;
|
|
5596
5691
|
}
|
|
5597
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5692
|
+
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);
|
|
5598
5693
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5599
5694
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5600
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5695
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5601
5696
|
if (!cellParticles) {
|
|
5602
5697
|
continue;
|
|
5603
5698
|
}
|
|
@@ -5614,29 +5709,29 @@
|
|
|
5614
5709
|
return out;
|
|
5615
5710
|
}
|
|
5616
5711
|
queryCircle(position, radius, check, out = []) {
|
|
5617
|
-
const circle = this
|
|
5618
|
-
this
|
|
5712
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5713
|
+
this.#releaseShapes();
|
|
5619
5714
|
return result;
|
|
5620
5715
|
}
|
|
5621
5716
|
queryRectangle(position, size, check, out = []) {
|
|
5622
|
-
const rect = this
|
|
5623
|
-
this
|
|
5717
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5718
|
+
this.#releaseShapes();
|
|
5624
5719
|
return result;
|
|
5625
5720
|
}
|
|
5626
5721
|
setCellSize(cellSize) {
|
|
5627
|
-
this
|
|
5722
|
+
this.#pendingCellSize = cellSize;
|
|
5628
5723
|
}
|
|
5629
|
-
|
|
5630
|
-
return (this
|
|
5724
|
+
#acquireCircle(x, y, r) {
|
|
5725
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5631
5726
|
}
|
|
5632
|
-
|
|
5633
|
-
return (this
|
|
5727
|
+
#acquireRectangle(x, y, w, h) {
|
|
5728
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5634
5729
|
}
|
|
5635
|
-
|
|
5636
|
-
const cellX = Math.floor(x / this
|
|
5730
|
+
#cellKeyFromCoords(x, y) {
|
|
5731
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5637
5732
|
return `${cellX}_${cellY}`;
|
|
5638
5733
|
}
|
|
5639
|
-
|
|
5734
|
+
#getRangeBounds(range) {
|
|
5640
5735
|
if (range instanceof Circle) {
|
|
5641
5736
|
const r = range.radius, { x, y } = range.position;
|
|
5642
5737
|
return {
|
|
@@ -5657,53 +5752,53 @@
|
|
|
5657
5752
|
}
|
|
5658
5753
|
return null;
|
|
5659
5754
|
}
|
|
5660
|
-
|
|
5661
|
-
this
|
|
5662
|
-
this
|
|
5755
|
+
#releaseShapes() {
|
|
5756
|
+
this.#circlePoolIdx = 0;
|
|
5757
|
+
this.#rectanglePoolIdx = 0;
|
|
5663
5758
|
}
|
|
5664
5759
|
}
|
|
5665
5760
|
|
|
5666
5761
|
class ParticlesManager {
|
|
5667
5762
|
checkParticlePositionPlugins;
|
|
5668
5763
|
grid;
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5764
|
+
#array;
|
|
5765
|
+
#container;
|
|
5766
|
+
#groupLimits;
|
|
5767
|
+
#limit;
|
|
5768
|
+
#nextId;
|
|
5769
|
+
#particleBuckets;
|
|
5770
|
+
#particleResetPlugins;
|
|
5771
|
+
#particleUpdatePlugins;
|
|
5772
|
+
#pluginManager;
|
|
5773
|
+
#pool;
|
|
5774
|
+
#postParticleUpdatePlugins;
|
|
5775
|
+
#postUpdatePlugins;
|
|
5776
|
+
#resizeFactor;
|
|
5777
|
+
#updatePlugins;
|
|
5778
|
+
#zBuckets;
|
|
5684
5779
|
constructor(pluginManager, container) {
|
|
5685
|
-
this
|
|
5686
|
-
this
|
|
5687
|
-
this
|
|
5688
|
-
this
|
|
5689
|
-
this
|
|
5690
|
-
this
|
|
5691
|
-
this
|
|
5692
|
-
this
|
|
5693
|
-
this
|
|
5780
|
+
this.#pluginManager = pluginManager;
|
|
5781
|
+
this.#container = container;
|
|
5782
|
+
this.#nextId = 0;
|
|
5783
|
+
this.#array = [];
|
|
5784
|
+
this.#pool = [];
|
|
5785
|
+
this.#limit = 0;
|
|
5786
|
+
this.#groupLimits = new Map();
|
|
5787
|
+
this.#particleBuckets = new Map();
|
|
5788
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5694
5789
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5695
5790
|
this.checkParticlePositionPlugins = [];
|
|
5696
|
-
this
|
|
5697
|
-
this
|
|
5698
|
-
this
|
|
5699
|
-
this
|
|
5700
|
-
this
|
|
5791
|
+
this.#particleResetPlugins = [];
|
|
5792
|
+
this.#particleUpdatePlugins = [];
|
|
5793
|
+
this.#postUpdatePlugins = [];
|
|
5794
|
+
this.#postParticleUpdatePlugins = [];
|
|
5795
|
+
this.#updatePlugins = [];
|
|
5701
5796
|
}
|
|
5702
5797
|
get count() {
|
|
5703
|
-
return this.
|
|
5798
|
+
return this.#array.length;
|
|
5704
5799
|
}
|
|
5705
5800
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5706
|
-
const limitMode = this.
|
|
5801
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5707
5802
|
if (limit > minLimit) {
|
|
5708
5803
|
switch (limitMode) {
|
|
5709
5804
|
case LimitMode.delete: {
|
|
@@ -5721,20 +5816,20 @@
|
|
|
5721
5816
|
}
|
|
5722
5817
|
}
|
|
5723
5818
|
try {
|
|
5724
|
-
const particle = this.
|
|
5725
|
-
particle.init(this
|
|
5819
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5820
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5726
5821
|
let canAdd = true;
|
|
5727
5822
|
if (initializer) {
|
|
5728
5823
|
canAdd = initializer(particle);
|
|
5729
5824
|
}
|
|
5730
5825
|
if (!canAdd) {
|
|
5731
|
-
this.
|
|
5826
|
+
this.#pool.push(particle);
|
|
5732
5827
|
return;
|
|
5733
5828
|
}
|
|
5734
|
-
this.
|
|
5735
|
-
this
|
|
5736
|
-
this
|
|
5737
|
-
this.
|
|
5829
|
+
this.#array.push(particle);
|
|
5830
|
+
this.#insertParticleIntoBucket(particle);
|
|
5831
|
+
this.#nextId++;
|
|
5832
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5738
5833
|
particle,
|
|
5739
5834
|
});
|
|
5740
5835
|
return particle;
|
|
@@ -5745,25 +5840,25 @@
|
|
|
5745
5840
|
return undefined;
|
|
5746
5841
|
}
|
|
5747
5842
|
clear() {
|
|
5748
|
-
this
|
|
5749
|
-
this.
|
|
5750
|
-
this
|
|
5843
|
+
this.#array = [];
|
|
5844
|
+
this.#particleBuckets.clear();
|
|
5845
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5751
5846
|
}
|
|
5752
5847
|
destroy() {
|
|
5753
|
-
this
|
|
5754
|
-
this.
|
|
5755
|
-
this.
|
|
5756
|
-
this
|
|
5848
|
+
this.#array = [];
|
|
5849
|
+
this.#pool.length = 0;
|
|
5850
|
+
this.#particleBuckets.clear();
|
|
5851
|
+
this.#zBuckets = [];
|
|
5757
5852
|
this.checkParticlePositionPlugins = [];
|
|
5758
|
-
this
|
|
5759
|
-
this
|
|
5760
|
-
this
|
|
5761
|
-
this
|
|
5762
|
-
this
|
|
5853
|
+
this.#particleResetPlugins = [];
|
|
5854
|
+
this.#particleUpdatePlugins = [];
|
|
5855
|
+
this.#postUpdatePlugins = [];
|
|
5856
|
+
this.#postParticleUpdatePlugins = [];
|
|
5857
|
+
this.#updatePlugins = [];
|
|
5763
5858
|
}
|
|
5764
5859
|
drawParticles(delta) {
|
|
5765
|
-
for (let i = this.
|
|
5766
|
-
const bucket = this
|
|
5860
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5861
|
+
const bucket = this.#zBuckets[i];
|
|
5767
5862
|
if (!bucket) {
|
|
5768
5863
|
continue;
|
|
5769
5864
|
}
|
|
@@ -5773,24 +5868,24 @@
|
|
|
5773
5868
|
}
|
|
5774
5869
|
}
|
|
5775
5870
|
filter(condition) {
|
|
5776
|
-
return this.
|
|
5871
|
+
return this.#array.filter(condition);
|
|
5777
5872
|
}
|
|
5778
5873
|
find(condition) {
|
|
5779
|
-
return this.
|
|
5874
|
+
return this.#array.find(condition);
|
|
5780
5875
|
}
|
|
5781
5876
|
get(index) {
|
|
5782
|
-
return this
|
|
5877
|
+
return this.#array[index];
|
|
5783
5878
|
}
|
|
5784
5879
|
async init() {
|
|
5785
|
-
const container = this
|
|
5880
|
+
const container = this.#container, options = container.actualOptions;
|
|
5786
5881
|
this.checkParticlePositionPlugins = [];
|
|
5787
|
-
this
|
|
5788
|
-
this
|
|
5789
|
-
this
|
|
5790
|
-
this
|
|
5791
|
-
this
|
|
5792
|
-
this.
|
|
5793
|
-
this
|
|
5882
|
+
this.#updatePlugins = [];
|
|
5883
|
+
this.#particleUpdatePlugins = [];
|
|
5884
|
+
this.#postUpdatePlugins = [];
|
|
5885
|
+
this.#particleResetPlugins = [];
|
|
5886
|
+
this.#postParticleUpdatePlugins = [];
|
|
5887
|
+
this.#particleBuckets.clear();
|
|
5888
|
+
this.#resetBuckets(container.zLayers);
|
|
5794
5889
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5795
5890
|
for (const plugin of container.plugins) {
|
|
5796
5891
|
if (plugin.redrawInit) {
|
|
@@ -5800,26 +5895,26 @@
|
|
|
5800
5895
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5801
5896
|
}
|
|
5802
5897
|
if (plugin.update) {
|
|
5803
|
-
this.
|
|
5898
|
+
this.#updatePlugins.push(plugin);
|
|
5804
5899
|
}
|
|
5805
5900
|
if (plugin.particleUpdate) {
|
|
5806
|
-
this.
|
|
5901
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5807
5902
|
}
|
|
5808
5903
|
if (plugin.postUpdate) {
|
|
5809
|
-
this.
|
|
5904
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5810
5905
|
}
|
|
5811
5906
|
if (plugin.particleReset) {
|
|
5812
|
-
this.
|
|
5907
|
+
this.#particleResetPlugins.push(plugin);
|
|
5813
5908
|
}
|
|
5814
5909
|
if (plugin.postParticleUpdate) {
|
|
5815
|
-
this.
|
|
5910
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5816
5911
|
}
|
|
5817
5912
|
}
|
|
5818
|
-
await this.
|
|
5819
|
-
for (const drawer of this.
|
|
5913
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5914
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5820
5915
|
await drawer.init?.(container);
|
|
5821
5916
|
}
|
|
5822
|
-
for (const drawer of this.
|
|
5917
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5823
5918
|
await drawer.init?.(container);
|
|
5824
5919
|
}
|
|
5825
5920
|
let handled = false;
|
|
@@ -5853,10 +5948,10 @@
|
|
|
5853
5948
|
async redraw() {
|
|
5854
5949
|
this.clear();
|
|
5855
5950
|
await this.init();
|
|
5856
|
-
this.
|
|
5951
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5857
5952
|
}
|
|
5858
5953
|
remove(particle, group, override) {
|
|
5859
|
-
this.removeAt(this.
|
|
5954
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5860
5955
|
}
|
|
5861
5956
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5862
5957
|
if (index < minIndex || index > this.count) {
|
|
@@ -5864,7 +5959,7 @@
|
|
|
5864
5959
|
}
|
|
5865
5960
|
let deleted = 0;
|
|
5866
5961
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5867
|
-
if (this
|
|
5962
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5868
5963
|
i--;
|
|
5869
5964
|
deleted++;
|
|
5870
5965
|
}
|
|
@@ -5874,9 +5969,9 @@
|
|
|
5874
5969
|
this.removeAt(minIndex, quantity, group);
|
|
5875
5970
|
}
|
|
5876
5971
|
setDensity() {
|
|
5877
|
-
const options = this.
|
|
5972
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5878
5973
|
let pluginsCount = 0;
|
|
5879
|
-
for (const plugin of this.
|
|
5974
|
+
for (const plugin of this.#container.plugins) {
|
|
5880
5975
|
if (plugin.particlesDensityCount) {
|
|
5881
5976
|
pluginsCount += plugin.particlesDensityCount();
|
|
5882
5977
|
}
|
|
@@ -5886,51 +5981,51 @@
|
|
|
5886
5981
|
if (!groupData) {
|
|
5887
5982
|
continue;
|
|
5888
5983
|
}
|
|
5889
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5890
|
-
this
|
|
5984
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5985
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5891
5986
|
}
|
|
5892
|
-
this
|
|
5987
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5893
5988
|
}
|
|
5894
5989
|
setResizeFactor(factor) {
|
|
5895
|
-
this
|
|
5990
|
+
this.#resizeFactor = factor;
|
|
5896
5991
|
}
|
|
5897
5992
|
update(delta) {
|
|
5898
5993
|
this.grid.clear();
|
|
5899
|
-
for (const plugin of this
|
|
5994
|
+
for (const plugin of this.#updatePlugins) {
|
|
5900
5995
|
plugin.update?.(delta);
|
|
5901
5996
|
}
|
|
5902
|
-
const particlesToDelete = this
|
|
5903
|
-
for (const plugin of this
|
|
5997
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5998
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5904
5999
|
plugin.postUpdate?.(delta);
|
|
5905
6000
|
}
|
|
5906
|
-
this
|
|
6001
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5907
6002
|
if (particlesToDelete.size) {
|
|
5908
6003
|
for (const particle of particlesToDelete) {
|
|
5909
6004
|
this.remove(particle);
|
|
5910
6005
|
}
|
|
5911
6006
|
}
|
|
5912
|
-
|
|
6007
|
+
this.#resizeFactor = undefined;
|
|
5913
6008
|
}
|
|
5914
|
-
|
|
5915
|
-
this.
|
|
6009
|
+
#addToPool = (...particles) => {
|
|
6010
|
+
this.#pool.push(...particles);
|
|
5916
6011
|
};
|
|
5917
|
-
|
|
6012
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5918
6013
|
const numberOptions = options.number;
|
|
5919
6014
|
if (!numberOptions.density.enable) {
|
|
5920
6015
|
if (group === undefined) {
|
|
5921
|
-
this
|
|
6016
|
+
this.#limit = numberOptions.limit.value;
|
|
5922
6017
|
}
|
|
5923
6018
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5924
|
-
this.
|
|
6019
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5925
6020
|
}
|
|
5926
6021
|
return;
|
|
5927
6022
|
}
|
|
5928
|
-
const densityFactor = this
|
|
6023
|
+
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);
|
|
5929
6024
|
if (group === undefined) {
|
|
5930
|
-
this
|
|
6025
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5931
6026
|
}
|
|
5932
6027
|
else {
|
|
5933
|
-
this.
|
|
6028
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5934
6029
|
}
|
|
5935
6030
|
if (particlesCount < particlesNumber) {
|
|
5936
6031
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5939,18 +6034,18 @@
|
|
|
5939
6034
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5940
6035
|
}
|
|
5941
6036
|
};
|
|
5942
|
-
|
|
6037
|
+
#createBuckets = (zLayers) => {
|
|
5943
6038
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5944
6039
|
return Array.from({ length: bucketCount }, () => []);
|
|
5945
6040
|
};
|
|
5946
|
-
|
|
5947
|
-
const maxBucketIndex = this.
|
|
6041
|
+
#getBucketIndex = (zIndex) => {
|
|
6042
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5948
6043
|
if (maxBucketIndex <= minIndex) {
|
|
5949
6044
|
return minIndex;
|
|
5950
6045
|
}
|
|
5951
6046
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5952
6047
|
};
|
|
5953
|
-
|
|
6048
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5954
6049
|
let start = minIndex, end = bucket.length;
|
|
5955
6050
|
while (start < end) {
|
|
5956
6051
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5967,8 +6062,8 @@
|
|
|
5967
6062
|
}
|
|
5968
6063
|
return start;
|
|
5969
6064
|
};
|
|
5970
|
-
|
|
5971
|
-
const container = this
|
|
6065
|
+
#initDensityFactor = densityOptions => {
|
|
6066
|
+
const container = this.#container;
|
|
5972
6067
|
if (!densityOptions.enable) {
|
|
5973
6068
|
return defaultDensityFactor;
|
|
5974
6069
|
}
|
|
@@ -5978,82 +6073,82 @@
|
|
|
5978
6073
|
}
|
|
5979
6074
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5980
6075
|
};
|
|
5981
|
-
|
|
5982
|
-
const bucketIndex = this
|
|
6076
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6077
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5983
6078
|
if (!bucket) {
|
|
5984
6079
|
return;
|
|
5985
6080
|
}
|
|
5986
|
-
bucket.splice(this
|
|
5987
|
-
this.
|
|
6081
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6082
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5988
6083
|
};
|
|
5989
|
-
|
|
5990
|
-
const particle = this
|
|
6084
|
+
#removeParticle = (index, group, override) => {
|
|
6085
|
+
const particle = this.#array[index];
|
|
5991
6086
|
if (!particle) {
|
|
5992
6087
|
return false;
|
|
5993
6088
|
}
|
|
5994
6089
|
if (particle.group !== group) {
|
|
5995
6090
|
return false;
|
|
5996
6091
|
}
|
|
5997
|
-
this.
|
|
5998
|
-
this
|
|
6092
|
+
this.#array.splice(index, deleteCount);
|
|
6093
|
+
this.#removeParticleFromBucket(particle);
|
|
5999
6094
|
particle.destroy(override);
|
|
6000
|
-
this.
|
|
6095
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
6001
6096
|
particle,
|
|
6002
6097
|
});
|
|
6003
|
-
this
|
|
6098
|
+
this.#addToPool(particle);
|
|
6004
6099
|
return true;
|
|
6005
6100
|
};
|
|
6006
|
-
|
|
6007
|
-
const bucketIndex = this.
|
|
6101
|
+
#removeParticleFromBucket = (particle) => {
|
|
6102
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6008
6103
|
if (!bucket) {
|
|
6009
|
-
this.
|
|
6104
|
+
this.#particleBuckets.delete(particle.id);
|
|
6010
6105
|
return;
|
|
6011
6106
|
}
|
|
6012
|
-
const particleIndex = this
|
|
6107
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
6013
6108
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
6014
|
-
this.
|
|
6109
|
+
this.#particleBuckets.delete(particle.id);
|
|
6015
6110
|
return;
|
|
6016
6111
|
}
|
|
6017
6112
|
bucket.splice(particleIndex, deleteCount);
|
|
6018
|
-
this.
|
|
6113
|
+
this.#particleBuckets.delete(particle.id);
|
|
6019
6114
|
};
|
|
6020
|
-
|
|
6115
|
+
#resetBuckets = (zLayers) => {
|
|
6021
6116
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6022
|
-
if (this.
|
|
6023
|
-
this
|
|
6117
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6118
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
6024
6119
|
return;
|
|
6025
6120
|
}
|
|
6026
|
-
for (const bucket of this
|
|
6121
|
+
for (const bucket of this.#zBuckets) {
|
|
6027
6122
|
bucket.length = minIndex;
|
|
6028
6123
|
}
|
|
6029
6124
|
};
|
|
6030
|
-
|
|
6031
|
-
const newBucketIndex = this
|
|
6125
|
+
#updateParticleBucket = (particle) => {
|
|
6126
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
6032
6127
|
if (currentBucketIndex === undefined) {
|
|
6033
|
-
this
|
|
6128
|
+
this.#insertParticleIntoBucket(particle);
|
|
6034
6129
|
return;
|
|
6035
6130
|
}
|
|
6036
6131
|
if (currentBucketIndex === newBucketIndex) {
|
|
6037
6132
|
return;
|
|
6038
6133
|
}
|
|
6039
|
-
const currentBucket = this
|
|
6134
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
6040
6135
|
if (currentBucket) {
|
|
6041
|
-
const particleIndex = this
|
|
6136
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
6042
6137
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
6043
6138
|
currentBucket.splice(particleIndex, deleteCount);
|
|
6044
6139
|
}
|
|
6045
6140
|
}
|
|
6046
|
-
const newBucket = this
|
|
6141
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
6047
6142
|
if (!newBucket) {
|
|
6048
|
-
this.
|
|
6143
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6049
6144
|
return;
|
|
6050
6145
|
}
|
|
6051
|
-
newBucket.splice(this
|
|
6052
|
-
this.
|
|
6146
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6147
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6053
6148
|
};
|
|
6054
|
-
|
|
6055
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
6056
|
-
for (const particle of this
|
|
6149
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6150
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6151
|
+
for (const particle of this.#array) {
|
|
6057
6152
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
6058
6153
|
particle.position.x *= resizeFactor.width;
|
|
6059
6154
|
particle.position.y *= resizeFactor.height;
|
|
@@ -6061,10 +6156,10 @@
|
|
|
6061
6156
|
particle.initialPosition.y *= resizeFactor.height;
|
|
6062
6157
|
}
|
|
6063
6158
|
particle.ignoresResizeRatio = false;
|
|
6064
|
-
for (const plugin of this
|
|
6159
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
6065
6160
|
plugin.particleReset?.(particle);
|
|
6066
6161
|
}
|
|
6067
|
-
for (const plugin of this
|
|
6162
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
6068
6163
|
if (particle.destroyed) {
|
|
6069
6164
|
break;
|
|
6070
6165
|
}
|
|
@@ -6078,36 +6173,36 @@
|
|
|
6078
6173
|
}
|
|
6079
6174
|
return particlesToDelete;
|
|
6080
6175
|
};
|
|
6081
|
-
|
|
6082
|
-
for (const particle of this
|
|
6176
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6177
|
+
for (const particle of this.#array) {
|
|
6083
6178
|
if (particle.destroyed) {
|
|
6084
6179
|
particlesToDelete.add(particle);
|
|
6085
6180
|
continue;
|
|
6086
6181
|
}
|
|
6087
|
-
for (const updater of this.
|
|
6182
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6088
6183
|
updater.update(particle, delta);
|
|
6089
6184
|
}
|
|
6090
6185
|
if (!particle.spawning) {
|
|
6091
|
-
for (const plugin of this
|
|
6186
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6092
6187
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6093
6188
|
}
|
|
6094
6189
|
}
|
|
6095
|
-
this
|
|
6190
|
+
this.#updateParticleBucket(particle);
|
|
6096
6191
|
}
|
|
6097
6192
|
};
|
|
6098
6193
|
}
|
|
6099
6194
|
|
|
6100
6195
|
class Retina {
|
|
6101
|
-
container;
|
|
6102
6196
|
pixelRatio;
|
|
6103
6197
|
reduceFactor;
|
|
6198
|
+
#container;
|
|
6104
6199
|
constructor(container) {
|
|
6105
|
-
this
|
|
6200
|
+
this.#container = container;
|
|
6106
6201
|
this.pixelRatio = defaultRatio;
|
|
6107
6202
|
this.reduceFactor = defaultReduceFactor;
|
|
6108
6203
|
}
|
|
6109
6204
|
init() {
|
|
6110
|
-
const container = this
|
|
6205
|
+
const container = this.#container, options = container.actualOptions;
|
|
6111
6206
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6112
6207
|
this.reduceFactor = defaultReduceFactor;
|
|
6113
6208
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6121,7 +6216,6 @@
|
|
|
6121
6216
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6122
6217
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6123
6218
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6124
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6125
6219
|
const maxDistance = props.maxDistance;
|
|
6126
6220
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6127
6221
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6159,73 +6253,73 @@
|
|
|
6159
6253
|
shapeDrawers;
|
|
6160
6254
|
started;
|
|
6161
6255
|
zLayers;
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6256
|
+
#delay;
|
|
6257
|
+
#delayTimeout;
|
|
6258
|
+
#delta = { value: 0, factor: 0 };
|
|
6259
|
+
#dispatchCallback;
|
|
6260
|
+
#drawAnimationFrame;
|
|
6261
|
+
#duration;
|
|
6262
|
+
#eventListeners;
|
|
6263
|
+
#firstStart;
|
|
6264
|
+
#initialSourceOptions;
|
|
6265
|
+
#lastFrameTime;
|
|
6266
|
+
#lifeTime;
|
|
6267
|
+
#onDestroy;
|
|
6268
|
+
#options;
|
|
6269
|
+
#paused;
|
|
6270
|
+
#pluginManager;
|
|
6271
|
+
#smooth;
|
|
6272
|
+
#sourceOptions;
|
|
6179
6273
|
constructor(params) {
|
|
6180
6274
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6181
|
-
this
|
|
6182
|
-
this
|
|
6183
|
-
this
|
|
6275
|
+
this.#pluginManager = pluginManager;
|
|
6276
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6277
|
+
this.#onDestroy = onDestroy;
|
|
6184
6278
|
this.id = Symbol(id);
|
|
6185
6279
|
this.fpsLimit = 120;
|
|
6186
6280
|
this.hdr = false;
|
|
6187
|
-
this
|
|
6188
|
-
this
|
|
6189
|
-
this
|
|
6190
|
-
this
|
|
6191
|
-
this
|
|
6281
|
+
this.#smooth = false;
|
|
6282
|
+
this.#delay = 0;
|
|
6283
|
+
this.#duration = 0;
|
|
6284
|
+
this.#lifeTime = 0;
|
|
6285
|
+
this.#firstStart = true;
|
|
6192
6286
|
this.started = false;
|
|
6193
6287
|
this.destroyed = false;
|
|
6194
|
-
this
|
|
6195
|
-
this
|
|
6288
|
+
this.#paused = true;
|
|
6289
|
+
this.#lastFrameTime = 0;
|
|
6196
6290
|
this.zLayers = 100;
|
|
6197
6291
|
this.pageHidden = false;
|
|
6198
|
-
this
|
|
6199
|
-
this
|
|
6292
|
+
this.#sourceOptions = sourceOptions;
|
|
6293
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6200
6294
|
this.effectDrawers = new Map();
|
|
6201
6295
|
this.shapeDrawers = new Map();
|
|
6202
6296
|
this.particleUpdaters = [];
|
|
6203
6297
|
this.retina = new Retina(this);
|
|
6204
|
-
this.canvas = new CanvasManager(this
|
|
6205
|
-
this.particles = new ParticlesManager(this
|
|
6298
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6299
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6206
6300
|
this.plugins = [];
|
|
6207
6301
|
this.particleDestroyedPlugins = [];
|
|
6208
6302
|
this.particleCreatedPlugins = [];
|
|
6209
6303
|
this.particlePositionPlugins = [];
|
|
6210
|
-
this
|
|
6211
|
-
this.actualOptions = loadContainerOptions(this
|
|
6212
|
-
this
|
|
6304
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6305
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6306
|
+
this.#eventListeners = new EventListeners(this);
|
|
6213
6307
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6214
6308
|
}
|
|
6215
6309
|
get animationStatus() {
|
|
6216
|
-
return !this
|
|
6310
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6217
6311
|
}
|
|
6218
6312
|
get options() {
|
|
6219
|
-
return this
|
|
6313
|
+
return this.#options;
|
|
6220
6314
|
}
|
|
6221
6315
|
get sourceOptions() {
|
|
6222
|
-
return this
|
|
6316
|
+
return this.#sourceOptions;
|
|
6223
6317
|
}
|
|
6224
6318
|
addLifeTime(value) {
|
|
6225
|
-
this
|
|
6319
|
+
this.#lifeTime += value;
|
|
6226
6320
|
}
|
|
6227
6321
|
alive() {
|
|
6228
|
-
return !this
|
|
6322
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6229
6323
|
}
|
|
6230
6324
|
destroy(remove = true) {
|
|
6231
6325
|
if (!guardCheck(this)) {
|
|
@@ -6247,13 +6341,13 @@
|
|
|
6247
6341
|
this.shapeDrawers = new Map();
|
|
6248
6342
|
this.particleUpdaters = [];
|
|
6249
6343
|
this.plugins.length = 0;
|
|
6250
|
-
this.
|
|
6344
|
+
this.#pluginManager.clearPlugins(this);
|
|
6251
6345
|
this.destroyed = true;
|
|
6252
|
-
this
|
|
6346
|
+
this.#onDestroy(remove);
|
|
6253
6347
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6254
6348
|
}
|
|
6255
6349
|
dispatchEvent(type, data) {
|
|
6256
|
-
this
|
|
6350
|
+
this.#dispatchCallback(type, {
|
|
6257
6351
|
container: this,
|
|
6258
6352
|
data,
|
|
6259
6353
|
});
|
|
@@ -6263,12 +6357,12 @@
|
|
|
6263
6357
|
return;
|
|
6264
6358
|
}
|
|
6265
6359
|
let refreshTime = force;
|
|
6266
|
-
this
|
|
6360
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6267
6361
|
if (refreshTime) {
|
|
6268
|
-
this
|
|
6362
|
+
this.#lastFrameTime = undefined;
|
|
6269
6363
|
refreshTime = false;
|
|
6270
6364
|
}
|
|
6271
|
-
this
|
|
6365
|
+
this.#nextFrame(timestamp);
|
|
6272
6366
|
});
|
|
6273
6367
|
}
|
|
6274
6368
|
async export(type, options = {}) {
|
|
@@ -6290,7 +6384,7 @@
|
|
|
6290
6384
|
return;
|
|
6291
6385
|
}
|
|
6292
6386
|
const allContainerPlugins = new Map();
|
|
6293
|
-
for (const plugin of this.
|
|
6387
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6294
6388
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6295
6389
|
if (containerPlugin.preInit) {
|
|
6296
6390
|
await containerPlugin.preInit();
|
|
@@ -6298,8 +6392,8 @@
|
|
|
6298
6392
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6299
6393
|
}
|
|
6300
6394
|
await this.initDrawersAndUpdaters();
|
|
6301
|
-
this
|
|
6302
|
-
this.actualOptions = loadContainerOptions(this
|
|
6395
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6396
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6303
6397
|
this.plugins.length = 0;
|
|
6304
6398
|
this.particleDestroyedPlugins.length = 0;
|
|
6305
6399
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6326,11 +6420,11 @@
|
|
|
6326
6420
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6327
6421
|
this.hdr = hdr;
|
|
6328
6422
|
this.zLayers = zLayers;
|
|
6329
|
-
this
|
|
6330
|
-
this
|
|
6331
|
-
this
|
|
6423
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6424
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6425
|
+
this.#lifeTime = 0;
|
|
6332
6426
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6333
|
-
this
|
|
6427
|
+
this.#smooth = smooth;
|
|
6334
6428
|
for (const plugin of this.plugins) {
|
|
6335
6429
|
await plugin.init?.();
|
|
6336
6430
|
}
|
|
@@ -6343,7 +6437,7 @@
|
|
|
6343
6437
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6344
6438
|
}
|
|
6345
6439
|
async initDrawersAndUpdaters() {
|
|
6346
|
-
const pluginManager = this
|
|
6440
|
+
const pluginManager = this.#pluginManager;
|
|
6347
6441
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6348
6442
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6349
6443
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6352,18 +6446,18 @@
|
|
|
6352
6446
|
if (!guardCheck(this)) {
|
|
6353
6447
|
return;
|
|
6354
6448
|
}
|
|
6355
|
-
if (this
|
|
6356
|
-
cancelAnimation(this
|
|
6357
|
-
|
|
6449
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6450
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6451
|
+
this.#drawAnimationFrame = undefined;
|
|
6358
6452
|
}
|
|
6359
|
-
if (this
|
|
6453
|
+
if (this.#paused) {
|
|
6360
6454
|
return;
|
|
6361
6455
|
}
|
|
6362
6456
|
for (const plugin of this.plugins) {
|
|
6363
6457
|
plugin.pause?.();
|
|
6364
6458
|
}
|
|
6365
6459
|
if (!this.pageHidden) {
|
|
6366
|
-
this
|
|
6460
|
+
this.#paused = true;
|
|
6367
6461
|
}
|
|
6368
6462
|
this.dispatchEvent(EventType.containerPaused);
|
|
6369
6463
|
}
|
|
@@ -6371,13 +6465,13 @@
|
|
|
6371
6465
|
if (!guardCheck(this)) {
|
|
6372
6466
|
return;
|
|
6373
6467
|
}
|
|
6374
|
-
const needsUpdate = this
|
|
6375
|
-
if (this
|
|
6376
|
-
this
|
|
6468
|
+
const needsUpdate = this.#paused || force;
|
|
6469
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6470
|
+
this.#firstStart = false;
|
|
6377
6471
|
return;
|
|
6378
6472
|
}
|
|
6379
|
-
if (this
|
|
6380
|
-
this
|
|
6473
|
+
if (this.#paused) {
|
|
6474
|
+
this.#paused = false;
|
|
6381
6475
|
}
|
|
6382
6476
|
if (needsUpdate) {
|
|
6383
6477
|
for (const plugin of this.plugins) {
|
|
@@ -6400,10 +6494,10 @@
|
|
|
6400
6494
|
if (!guardCheck(this)) {
|
|
6401
6495
|
return;
|
|
6402
6496
|
}
|
|
6403
|
-
this
|
|
6404
|
-
this
|
|
6405
|
-
this
|
|
6406
|
-
this.actualOptions = loadContainerOptions(this
|
|
6497
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6498
|
+
this.#sourceOptions = sourceOptions;
|
|
6499
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6500
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6407
6501
|
return this.refresh();
|
|
6408
6502
|
}
|
|
6409
6503
|
async start() {
|
|
@@ -6414,7 +6508,7 @@
|
|
|
6414
6508
|
this.started = true;
|
|
6415
6509
|
await new Promise(resolve => {
|
|
6416
6510
|
const start = async () => {
|
|
6417
|
-
this.
|
|
6511
|
+
this.#eventListeners.addListeners();
|
|
6418
6512
|
for (const plugin of this.plugins) {
|
|
6419
6513
|
await plugin.start?.();
|
|
6420
6514
|
}
|
|
@@ -6422,20 +6516,20 @@
|
|
|
6422
6516
|
this.play();
|
|
6423
6517
|
resolve();
|
|
6424
6518
|
};
|
|
6425
|
-
this
|
|
6519
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6426
6520
|
});
|
|
6427
6521
|
}
|
|
6428
6522
|
stop() {
|
|
6429
6523
|
if (!guardCheck(this) || !this.started) {
|
|
6430
6524
|
return;
|
|
6431
6525
|
}
|
|
6432
|
-
if (this
|
|
6433
|
-
clearTimeout(this
|
|
6434
|
-
|
|
6526
|
+
if (this.#delayTimeout) {
|
|
6527
|
+
clearTimeout(this.#delayTimeout);
|
|
6528
|
+
this.#delayTimeout = undefined;
|
|
6435
6529
|
}
|
|
6436
|
-
this
|
|
6530
|
+
this.#firstStart = true;
|
|
6437
6531
|
this.started = false;
|
|
6438
|
-
this.
|
|
6532
|
+
this.#eventListeners.removeListeners();
|
|
6439
6533
|
this.pause();
|
|
6440
6534
|
this.particles.clear();
|
|
6441
6535
|
this.canvas.stop();
|
|
@@ -6445,7 +6539,7 @@
|
|
|
6445
6539
|
this.particleCreatedPlugins.length = 0;
|
|
6446
6540
|
this.particleDestroyedPlugins.length = 0;
|
|
6447
6541
|
this.particlePositionPlugins.length = 0;
|
|
6448
|
-
this
|
|
6542
|
+
this.#sourceOptions = this.#options;
|
|
6449
6543
|
this.dispatchEvent(EventType.containerStopped);
|
|
6450
6544
|
}
|
|
6451
6545
|
updateActualOptions() {
|
|
@@ -6457,23 +6551,23 @@
|
|
|
6457
6551
|
}
|
|
6458
6552
|
return refresh;
|
|
6459
6553
|
}
|
|
6460
|
-
|
|
6554
|
+
#nextFrame = (timestamp) => {
|
|
6461
6555
|
try {
|
|
6462
|
-
if (!this
|
|
6463
|
-
this
|
|
6464
|
-
timestamp < this
|
|
6556
|
+
if (!this.#smooth &&
|
|
6557
|
+
this.#lastFrameTime !== undefined &&
|
|
6558
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6465
6559
|
this.draw(false);
|
|
6466
6560
|
return;
|
|
6467
6561
|
}
|
|
6468
|
-
this
|
|
6469
|
-
updateDelta(this
|
|
6470
|
-
this.addLifeTime(this.
|
|
6471
|
-
this
|
|
6472
|
-
if (this.
|
|
6562
|
+
this.#lastFrameTime ??= timestamp;
|
|
6563
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6564
|
+
this.addLifeTime(this.#delta.value);
|
|
6565
|
+
this.#lastFrameTime = timestamp;
|
|
6566
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6473
6567
|
this.draw(false);
|
|
6474
6568
|
return;
|
|
6475
6569
|
}
|
|
6476
|
-
this.canvas.render.drawParticles(this
|
|
6570
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6477
6571
|
if (!this.alive()) {
|
|
6478
6572
|
this.destroy();
|
|
6479
6573
|
return;
|
|
@@ -6494,10 +6588,10 @@
|
|
|
6494
6588
|
});
|
|
6495
6589
|
|
|
6496
6590
|
class BlendPluginInstance {
|
|
6497
|
-
|
|
6498
|
-
|
|
6591
|
+
#container;
|
|
6592
|
+
#defaultCompositeValue;
|
|
6499
6593
|
constructor(container) {
|
|
6500
|
-
this
|
|
6594
|
+
this.#container = container;
|
|
6501
6595
|
}
|
|
6502
6596
|
drawParticleCleanup(context, particle) {
|
|
6503
6597
|
if (!particle.options.blend?.enable) {
|
|
@@ -6514,14 +6608,14 @@
|
|
|
6514
6608
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6515
6609
|
}
|
|
6516
6610
|
drawSettingsCleanup(context) {
|
|
6517
|
-
if (!this
|
|
6611
|
+
if (!this.#defaultCompositeValue) {
|
|
6518
6612
|
return;
|
|
6519
6613
|
}
|
|
6520
|
-
context.globalCompositeOperation = this
|
|
6614
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6521
6615
|
}
|
|
6522
6616
|
drawSettingsSetup(context) {
|
|
6523
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6524
|
-
this
|
|
6617
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6618
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6525
6619
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6526
6620
|
}
|
|
6527
6621
|
}
|
|
@@ -6664,11 +6758,11 @@
|
|
|
6664
6758
|
class MovePluginInstance {
|
|
6665
6759
|
availablePathGenerators;
|
|
6666
6760
|
pathGenerators;
|
|
6667
|
-
|
|
6668
|
-
|
|
6761
|
+
#container;
|
|
6762
|
+
#pluginManager;
|
|
6669
6763
|
constructor(pluginManager, container) {
|
|
6670
|
-
this
|
|
6671
|
-
this
|
|
6764
|
+
this.#pluginManager = pluginManager;
|
|
6765
|
+
this.#container = container;
|
|
6672
6766
|
this.availablePathGenerators = new Map();
|
|
6673
6767
|
this.pathGenerators = new Map();
|
|
6674
6768
|
}
|
|
@@ -6699,7 +6793,7 @@
|
|
|
6699
6793
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6700
6794
|
inverse: gravityOptions.inverse,
|
|
6701
6795
|
};
|
|
6702
|
-
initSpin(this
|
|
6796
|
+
initSpin(this.#container, particle);
|
|
6703
6797
|
}
|
|
6704
6798
|
particleDestroyed(particle) {
|
|
6705
6799
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6710,7 +6804,7 @@
|
|
|
6710
6804
|
if (!moveOptions.enable) {
|
|
6711
6805
|
return;
|
|
6712
6806
|
}
|
|
6713
|
-
const container = this
|
|
6807
|
+
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;
|
|
6714
6808
|
if (moveOptions.spin.enable) {
|
|
6715
6809
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6716
6810
|
}
|
|
@@ -6720,18 +6814,18 @@
|
|
|
6720
6814
|
applyDistance(particle);
|
|
6721
6815
|
}
|
|
6722
6816
|
preInit() {
|
|
6723
|
-
return this
|
|
6817
|
+
return this.#init();
|
|
6724
6818
|
}
|
|
6725
6819
|
redrawInit() {
|
|
6726
|
-
return this
|
|
6820
|
+
return this.#init();
|
|
6727
6821
|
}
|
|
6728
6822
|
update() {
|
|
6729
6823
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6730
6824
|
pathGenerator.update();
|
|
6731
6825
|
}
|
|
6732
6826
|
}
|
|
6733
|
-
async
|
|
6734
|
-
const availablePathGenerators = await this.
|
|
6827
|
+
async #init() {
|
|
6828
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6735
6829
|
if (!availablePathGenerators) {
|
|
6736
6830
|
return;
|
|
6737
6831
|
}
|
|
@@ -6750,12 +6844,12 @@
|
|
|
6750
6844
|
|
|
6751
6845
|
const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
|
|
6752
6846
|
class MotionPluginInstance {
|
|
6753
|
-
|
|
6847
|
+
#container;
|
|
6754
6848
|
constructor(container) {
|
|
6755
|
-
this
|
|
6849
|
+
this.#container = container;
|
|
6756
6850
|
}
|
|
6757
6851
|
async init() {
|
|
6758
|
-
const container = this
|
|
6852
|
+
const container = this.#container, options = container.actualOptions.motion;
|
|
6759
6853
|
if (!(options && (options.disable || options.reduce.value))) {
|
|
6760
6854
|
container.retina.reduceFactor = 1;
|
|
6761
6855
|
return;
|
|
@@ -6765,10 +6859,10 @@
|
|
|
6765
6859
|
container.retina.reduceFactor = defaultFactor;
|
|
6766
6860
|
return;
|
|
6767
6861
|
}
|
|
6768
|
-
this
|
|
6862
|
+
this.#handleMotionChange(mediaQuery);
|
|
6769
6863
|
const handleChange = () => {
|
|
6770
6864
|
void (async () => {
|
|
6771
|
-
this
|
|
6865
|
+
this.#handleMotionChange(mediaQuery);
|
|
6772
6866
|
try {
|
|
6773
6867
|
await container.refresh();
|
|
6774
6868
|
}
|
|
@@ -6779,8 +6873,8 @@
|
|
|
6779
6873
|
mediaQuery.addEventListener("change", handleChange);
|
|
6780
6874
|
await Promise.resolve();
|
|
6781
6875
|
}
|
|
6782
|
-
|
|
6783
|
-
const container = this
|
|
6876
|
+
#handleMotionChange = mediaQuery => {
|
|
6877
|
+
const container = this.#container, motion = container.actualOptions.motion;
|
|
6784
6878
|
if (!motion) {
|
|
6785
6879
|
return;
|
|
6786
6880
|
}
|