@tsparticles/preset-firefly 4.0.5 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* Preset v4.
|
|
2
|
+
/* Preset v4.1.1 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -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.
|
|
1005
|
+
return "4.1.1";
|
|
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.
|
|
2798
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2835
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2883
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2936
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2960
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3067
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3414
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3485
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3540
|
+
engine.checkVersion("4.1.1");
|
|
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
|
-
(particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3596
|
-
if (!sizeAnimation.sync) {
|
|
3597
|
-
particle.size.velocity *= getRandom();
|
|
3598
|
-
}
|
|
3590
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3591
|
+
if (!sizeOptions) {
|
|
3592
|
+
return;
|
|
3599
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;
|
|
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.
|
|
3639
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3648
|
+
engine.checkVersion("4.1.1");
|
|
3632
3649
|
await engine.pluginManager.register(async (e) => {
|
|
3633
3650
|
await Promise.all([
|
|
3634
3651
|
loadBlendPlugin(e),
|
|
@@ -3755,20 +3772,20 @@
|
|
|
3755
3772
|
})(InteractivityDetect || (InteractivityDetect = {}));
|
|
3756
3773
|
|
|
3757
3774
|
class Modes {
|
|
3758
|
-
|
|
3759
|
-
|
|
3775
|
+
#container;
|
|
3776
|
+
#pluginManager;
|
|
3760
3777
|
constructor(pluginManager, container) {
|
|
3761
|
-
this
|
|
3762
|
-
this
|
|
3778
|
+
this.#pluginManager = pluginManager;
|
|
3779
|
+
this.#container = container;
|
|
3763
3780
|
}
|
|
3764
3781
|
load(data) {
|
|
3765
3782
|
if (isNull(data)) {
|
|
3766
3783
|
return;
|
|
3767
3784
|
}
|
|
3768
|
-
if (!this
|
|
3785
|
+
if (!this.#container) {
|
|
3769
3786
|
return;
|
|
3770
3787
|
}
|
|
3771
|
-
const interactors = this.
|
|
3788
|
+
const interactors = this.#pluginManager.interactors?.get(this.#container);
|
|
3772
3789
|
if (!interactors) {
|
|
3773
3790
|
return;
|
|
3774
3791
|
}
|
|
@@ -3805,13 +3822,13 @@
|
|
|
3805
3822
|
|
|
3806
3823
|
class InteractivityPlugin {
|
|
3807
3824
|
id = "interactivity";
|
|
3808
|
-
|
|
3825
|
+
#pluginManager;
|
|
3809
3826
|
constructor(pluginManager) {
|
|
3810
|
-
this
|
|
3827
|
+
this.#pluginManager = pluginManager;
|
|
3811
3828
|
}
|
|
3812
3829
|
async getPlugin(container) {
|
|
3813
3830
|
const { InteractivityPluginInstance } = await Promise.resolve().then(function () { return InteractivityPluginInstance$1; });
|
|
3814
|
-
return new InteractivityPluginInstance(this
|
|
3831
|
+
return new InteractivityPluginInstance(this.#pluginManager, container);
|
|
3815
3832
|
}
|
|
3816
3833
|
loadOptions(container, options, source) {
|
|
3817
3834
|
if (!this.needsPlugin()) {
|
|
@@ -3819,10 +3836,10 @@
|
|
|
3819
3836
|
}
|
|
3820
3837
|
let interactivityOptions = options.interactivity;
|
|
3821
3838
|
if (!interactivityOptions?.load) {
|
|
3822
|
-
options.interactivity = interactivityOptions = new Interactivity(this
|
|
3839
|
+
options.interactivity = interactivityOptions = new Interactivity(this.#pluginManager, container);
|
|
3823
3840
|
}
|
|
3824
3841
|
interactivityOptions.load(source?.interactivity);
|
|
3825
|
-
const interactors = this.
|
|
3842
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
3826
3843
|
if (!interactors) {
|
|
3827
3844
|
return;
|
|
3828
3845
|
}
|
|
@@ -3836,7 +3853,7 @@
|
|
|
3836
3853
|
if (source?.interactivity) {
|
|
3837
3854
|
options.interactivity = deepExtend({}, source.interactivity);
|
|
3838
3855
|
}
|
|
3839
|
-
const interactors = this.
|
|
3856
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
3840
3857
|
if (!interactors) {
|
|
3841
3858
|
return;
|
|
3842
3859
|
}
|
|
@@ -3866,7 +3883,7 @@
|
|
|
3866
3883
|
const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
|
|
3867
3884
|
|
|
3868
3885
|
async function loadInteractivityPlugin(engine) {
|
|
3869
|
-
engine.checkVersion("4.
|
|
3886
|
+
engine.checkVersion("4.1.1");
|
|
3870
3887
|
await engine.pluginManager.register(e => {
|
|
3871
3888
|
const interactivityEngine = e, interactivityPluginManager = interactivityEngine.pluginManager;
|
|
3872
3889
|
interactivityPluginManager.addPlugin(new InteractivityPlugin(interactivityPluginManager));
|
|
@@ -4004,13 +4021,13 @@
|
|
|
4004
4021
|
const trailMode = "trail", defaultMin = 0, defaultWeight = 0;
|
|
4005
4022
|
class TrailMaker extends ExternalInteractorBase {
|
|
4006
4023
|
maxDistance = 0;
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4024
|
+
#delay;
|
|
4025
|
+
#lastPosition;
|
|
4026
|
+
#pluginManager;
|
|
4010
4027
|
constructor(pluginManager, container) {
|
|
4011
4028
|
super(container);
|
|
4012
|
-
this
|
|
4013
|
-
this
|
|
4029
|
+
this.#pluginManager = pluginManager;
|
|
4030
|
+
this.#delay = 0;
|
|
4014
4031
|
}
|
|
4015
4032
|
clear() {
|
|
4016
4033
|
}
|
|
@@ -4024,19 +4041,19 @@
|
|
|
4024
4041
|
if (!trailOptions)
|
|
4025
4042
|
return;
|
|
4026
4043
|
const optDelay = (trailOptions.delay * millisecondsToSeconds) / this.container.retina.reduceFactor;
|
|
4027
|
-
if (this
|
|
4028
|
-
this
|
|
4044
|
+
if (this.#delay < optDelay) {
|
|
4045
|
+
this.#delay += delta.value;
|
|
4029
4046
|
}
|
|
4030
|
-
if (this
|
|
4047
|
+
if (this.#delay < optDelay)
|
|
4031
4048
|
return;
|
|
4032
4049
|
const mousePos = interactivityData.mouse.position, canEmit = !(trailOptions.pauseOnStop &&
|
|
4033
|
-
(mousePos === this
|
|
4034
|
-
(mousePos?.x === this
|
|
4050
|
+
(mousePos === this.#lastPosition ||
|
|
4051
|
+
(mousePos?.x === this.#lastPosition?.x && mousePos?.y === this.#lastPosition?.y)));
|
|
4035
4052
|
if (mousePos) {
|
|
4036
|
-
this
|
|
4053
|
+
this.#lastPosition = { ...mousePos };
|
|
4037
4054
|
}
|
|
4038
4055
|
else {
|
|
4039
|
-
|
|
4056
|
+
this.#lastPosition = undefined;
|
|
4040
4057
|
}
|
|
4041
4058
|
if (canEmit && mousePos) {
|
|
4042
4059
|
let particleOptions = trailOptions.particles;
|
|
@@ -4055,7 +4072,7 @@
|
|
|
4055
4072
|
}, trailPaintOptions = trailOptions.particles?.paint
|
|
4056
4073
|
? itemFromSingleOrMultiple(trailOptions.particles.paint)
|
|
4057
4074
|
: undefined, fillData = trailPaintOptions?.fill, baseHsl = fillData
|
|
4058
|
-
? rangeColorToHsl(this
|
|
4075
|
+
? rangeColorToHsl(this.#pluginManager, AnimatableColor.create(undefined, fillData.color))
|
|
4059
4076
|
: undefined, h = calculateValue(colorCoords.h, baseHsl?.h, hMax), s = calculateValue(colorCoords.s, baseHsl?.s, sMax), l = calculateValue(colorCoords.l, baseHsl?.l, lMax);
|
|
4060
4077
|
if (h !== undefined || s !== undefined || l !== undefined) {
|
|
4061
4078
|
particleOptions = deepExtend({}, trailOptions.particles, {
|
|
@@ -4075,7 +4092,7 @@
|
|
|
4075
4092
|
}
|
|
4076
4093
|
container.particles.push(trailOptions.quantity, mousePos, particleOptions);
|
|
4077
4094
|
}
|
|
4078
|
-
this
|
|
4095
|
+
this.#delay -= optDelay;
|
|
4079
4096
|
}
|
|
4080
4097
|
isEnabled(interactivityData, particle) {
|
|
4081
4098
|
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
@@ -4094,7 +4111,7 @@
|
|
|
4094
4111
|
}
|
|
4095
4112
|
|
|
4096
4113
|
async function loadExternalTrailInteraction(engine) {
|
|
4097
|
-
engine.checkVersion("4.
|
|
4114
|
+
engine.checkVersion("4.1.1");
|
|
4098
4115
|
await engine.pluginManager.register((e) => {
|
|
4099
4116
|
ensureInteractivityPluginLoaded(e);
|
|
4100
4117
|
e.pluginManager.addInteractor?.("externalTrail", container => {
|
|
@@ -4213,12 +4230,12 @@
|
|
|
4213
4230
|
|
|
4214
4231
|
const noTime = 0, identity$1 = 1, infiniteValue = -1;
|
|
4215
4232
|
class LifeUpdater {
|
|
4216
|
-
container;
|
|
4233
|
+
#container;
|
|
4217
4234
|
constructor(container) {
|
|
4218
|
-
this
|
|
4235
|
+
this.#container = container;
|
|
4219
4236
|
}
|
|
4220
4237
|
init(particle) {
|
|
4221
|
-
const container = this
|
|
4238
|
+
const container = this.#container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
4222
4239
|
if (!lifeOptions) {
|
|
4223
4240
|
return;
|
|
4224
4241
|
}
|
|
@@ -4257,12 +4274,12 @@
|
|
|
4257
4274
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
4258
4275
|
return;
|
|
4259
4276
|
}
|
|
4260
|
-
updateLife(particle, delta, this
|
|
4277
|
+
updateLife(particle, delta, this.#container.canvas.size);
|
|
4261
4278
|
}
|
|
4262
4279
|
}
|
|
4263
4280
|
|
|
4264
4281
|
async function loadLifeUpdater(engine) {
|
|
4265
|
-
engine.checkVersion("4.
|
|
4282
|
+
engine.checkVersion("4.1.1");
|
|
4266
4283
|
await engine.pluginManager.register(e => {
|
|
4267
4284
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
4268
4285
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -4361,58 +4378,58 @@
|
|
|
4361
4378
|
}
|
|
4362
4379
|
}
|
|
4363
4380
|
class RenderManager {
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4381
|
+
#canvasClearPlugins;
|
|
4382
|
+
#canvasManager;
|
|
4383
|
+
#canvasPaintPlugins;
|
|
4384
|
+
#clearDrawPlugins;
|
|
4385
|
+
#colorPlugins;
|
|
4386
|
+
#container;
|
|
4387
|
+
#context;
|
|
4388
|
+
#contextSettings;
|
|
4389
|
+
#drawParticlePlugins;
|
|
4390
|
+
#drawParticlesCleanupPlugins;
|
|
4391
|
+
#drawParticlesSetupPlugins;
|
|
4392
|
+
#drawPlugins;
|
|
4393
|
+
#drawSettingsCleanupPlugins;
|
|
4394
|
+
#drawSettingsSetupPlugins;
|
|
4395
|
+
#pluginManager;
|
|
4396
|
+
#postDrawUpdaters;
|
|
4397
|
+
#preDrawUpdaters;
|
|
4398
|
+
#reusableColorStyles = {};
|
|
4399
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4400
|
+
#reusableTransform = {};
|
|
4384
4401
|
constructor(pluginManager, container, canvasManager) {
|
|
4385
|
-
this
|
|
4386
|
-
this
|
|
4387
|
-
this
|
|
4388
|
-
this
|
|
4389
|
-
this
|
|
4390
|
-
this
|
|
4391
|
-
this
|
|
4392
|
-
this
|
|
4393
|
-
this
|
|
4394
|
-
this
|
|
4395
|
-
this
|
|
4396
|
-
this
|
|
4397
|
-
this
|
|
4398
|
-
this
|
|
4399
|
-
this
|
|
4400
|
-
this
|
|
4402
|
+
this.#pluginManager = pluginManager;
|
|
4403
|
+
this.#container = container;
|
|
4404
|
+
this.#canvasManager = canvasManager;
|
|
4405
|
+
this.#context = null;
|
|
4406
|
+
this.#preDrawUpdaters = [];
|
|
4407
|
+
this.#postDrawUpdaters = [];
|
|
4408
|
+
this.#colorPlugins = [];
|
|
4409
|
+
this.#canvasClearPlugins = [];
|
|
4410
|
+
this.#canvasPaintPlugins = [];
|
|
4411
|
+
this.#clearDrawPlugins = [];
|
|
4412
|
+
this.#drawParticlePlugins = [];
|
|
4413
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4414
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4415
|
+
this.#drawPlugins = [];
|
|
4416
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4417
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4401
4418
|
}
|
|
4402
4419
|
get settings() {
|
|
4403
|
-
return this
|
|
4420
|
+
return this.#contextSettings;
|
|
4404
4421
|
}
|
|
4405
4422
|
canvasClear() {
|
|
4406
|
-
if (!this.
|
|
4423
|
+
if (!this.#container.actualOptions.clear) {
|
|
4407
4424
|
return;
|
|
4408
4425
|
}
|
|
4409
4426
|
this.draw(ctx => {
|
|
4410
|
-
clear(ctx, this.
|
|
4427
|
+
clear(ctx, this.#canvasManager.size);
|
|
4411
4428
|
});
|
|
4412
4429
|
}
|
|
4413
4430
|
clear() {
|
|
4414
4431
|
let pluginHandled = false;
|
|
4415
|
-
for (const plugin of this
|
|
4432
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4416
4433
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4417
4434
|
if (pluginHandled) {
|
|
4418
4435
|
break;
|
|
@@ -4425,21 +4442,21 @@
|
|
|
4425
4442
|
}
|
|
4426
4443
|
destroy() {
|
|
4427
4444
|
this.stop();
|
|
4428
|
-
this
|
|
4429
|
-
this
|
|
4430
|
-
this
|
|
4431
|
-
this
|
|
4432
|
-
this
|
|
4433
|
-
this
|
|
4434
|
-
this
|
|
4435
|
-
this
|
|
4436
|
-
this
|
|
4437
|
-
this
|
|
4438
|
-
this
|
|
4439
|
-
this
|
|
4445
|
+
this.#preDrawUpdaters = [];
|
|
4446
|
+
this.#postDrawUpdaters = [];
|
|
4447
|
+
this.#colorPlugins = [];
|
|
4448
|
+
this.#canvasClearPlugins = [];
|
|
4449
|
+
this.#canvasPaintPlugins = [];
|
|
4450
|
+
this.#clearDrawPlugins = [];
|
|
4451
|
+
this.#drawParticlePlugins = [];
|
|
4452
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4453
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4454
|
+
this.#drawPlugins = [];
|
|
4455
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4456
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4440
4457
|
}
|
|
4441
4458
|
draw(cb) {
|
|
4442
|
-
const ctx = this
|
|
4459
|
+
const ctx = this.#context;
|
|
4443
4460
|
if (!ctx) {
|
|
4444
4461
|
return;
|
|
4445
4462
|
}
|
|
@@ -4454,21 +4471,21 @@
|
|
|
4454
4471
|
return;
|
|
4455
4472
|
}
|
|
4456
4473
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4457
|
-
let [fColor, sColor] = this
|
|
4474
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4458
4475
|
fColor ??= pfColor;
|
|
4459
4476
|
sColor ??= psColor;
|
|
4460
4477
|
if (!fColor && !sColor) {
|
|
4461
4478
|
return;
|
|
4462
4479
|
}
|
|
4463
|
-
const container = this
|
|
4480
|
+
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;
|
|
4464
4481
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4465
4482
|
colorStyles.fill = fill;
|
|
4466
4483
|
colorStyles.stroke = stroke;
|
|
4467
4484
|
this.draw((context) => {
|
|
4468
|
-
for (const plugin of this
|
|
4485
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4469
4486
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4470
4487
|
}
|
|
4471
|
-
this
|
|
4488
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4472
4489
|
drawParticle({
|
|
4473
4490
|
container,
|
|
4474
4491
|
context,
|
|
@@ -4479,35 +4496,35 @@
|
|
|
4479
4496
|
opacity: opacity,
|
|
4480
4497
|
transform,
|
|
4481
4498
|
});
|
|
4482
|
-
this
|
|
4483
|
-
for (const plugin of this
|
|
4499
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4500
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4484
4501
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4485
4502
|
}
|
|
4486
4503
|
});
|
|
4487
4504
|
}
|
|
4488
4505
|
drawParticlePlugins(particle, delta) {
|
|
4489
4506
|
this.draw(ctx => {
|
|
4490
|
-
for (const plugin of this
|
|
4507
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4491
4508
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4492
4509
|
}
|
|
4493
4510
|
});
|
|
4494
4511
|
}
|
|
4495
4512
|
drawParticles(delta) {
|
|
4496
|
-
const { particles } = this
|
|
4513
|
+
const { particles } = this.#container;
|
|
4497
4514
|
this.clear();
|
|
4498
4515
|
particles.update(delta);
|
|
4499
4516
|
this.draw(ctx => {
|
|
4500
|
-
for (const plugin of this
|
|
4517
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4501
4518
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4502
4519
|
}
|
|
4503
|
-
for (const plugin of this
|
|
4520
|
+
for (const plugin of this.#drawPlugins) {
|
|
4504
4521
|
plugin.draw?.(ctx, delta);
|
|
4505
4522
|
}
|
|
4506
4523
|
particles.drawParticles(delta);
|
|
4507
|
-
for (const plugin of this
|
|
4524
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4508
4525
|
plugin.clearDraw?.(ctx, delta);
|
|
4509
4526
|
}
|
|
4510
|
-
for (const plugin of this
|
|
4527
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4511
4528
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4512
4529
|
}
|
|
4513
4530
|
});
|
|
@@ -4518,64 +4535,64 @@
|
|
|
4518
4535
|
this.paint();
|
|
4519
4536
|
}
|
|
4520
4537
|
initPlugins() {
|
|
4521
|
-
this
|
|
4522
|
-
this
|
|
4523
|
-
this
|
|
4524
|
-
this
|
|
4525
|
-
this
|
|
4526
|
-
this
|
|
4527
|
-
this
|
|
4528
|
-
this
|
|
4529
|
-
this
|
|
4530
|
-
this
|
|
4531
|
-
for (const plugin of this.
|
|
4538
|
+
this.#colorPlugins = [];
|
|
4539
|
+
this.#canvasClearPlugins = [];
|
|
4540
|
+
this.#canvasPaintPlugins = [];
|
|
4541
|
+
this.#clearDrawPlugins = [];
|
|
4542
|
+
this.#drawParticlePlugins = [];
|
|
4543
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4544
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4545
|
+
this.#drawPlugins = [];
|
|
4546
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4547
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4548
|
+
for (const plugin of this.#container.plugins) {
|
|
4532
4549
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4533
|
-
this.
|
|
4550
|
+
this.#colorPlugins.push(plugin);
|
|
4534
4551
|
}
|
|
4535
4552
|
if (plugin.canvasClear) {
|
|
4536
|
-
this.
|
|
4553
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4537
4554
|
}
|
|
4538
4555
|
if (plugin.canvasPaint) {
|
|
4539
|
-
this.
|
|
4556
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4540
4557
|
}
|
|
4541
4558
|
if (plugin.drawParticle) {
|
|
4542
|
-
this.
|
|
4559
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4543
4560
|
}
|
|
4544
4561
|
if (plugin.drawParticleSetup) {
|
|
4545
|
-
this.
|
|
4562
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4546
4563
|
}
|
|
4547
4564
|
if (plugin.drawParticleCleanup) {
|
|
4548
|
-
this.
|
|
4565
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4549
4566
|
}
|
|
4550
4567
|
if (plugin.draw) {
|
|
4551
|
-
this.
|
|
4568
|
+
this.#drawPlugins.push(plugin);
|
|
4552
4569
|
}
|
|
4553
4570
|
if (plugin.drawSettingsSetup) {
|
|
4554
|
-
this.
|
|
4571
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4555
4572
|
}
|
|
4556
4573
|
if (plugin.drawSettingsCleanup) {
|
|
4557
|
-
this.
|
|
4574
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4558
4575
|
}
|
|
4559
4576
|
if (plugin.clearDraw) {
|
|
4560
|
-
this.
|
|
4577
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4561
4578
|
}
|
|
4562
4579
|
}
|
|
4563
4580
|
}
|
|
4564
4581
|
initUpdaters() {
|
|
4565
|
-
this
|
|
4566
|
-
this
|
|
4567
|
-
for (const updater of this.
|
|
4582
|
+
this.#preDrawUpdaters = [];
|
|
4583
|
+
this.#postDrawUpdaters = [];
|
|
4584
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4568
4585
|
if (updater.afterDraw) {
|
|
4569
|
-
this.
|
|
4586
|
+
this.#postDrawUpdaters.push(updater);
|
|
4570
4587
|
}
|
|
4571
4588
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4572
|
-
this.
|
|
4589
|
+
this.#preDrawUpdaters.push(updater);
|
|
4573
4590
|
}
|
|
4574
4591
|
}
|
|
4575
4592
|
}
|
|
4576
4593
|
paint() {
|
|
4577
4594
|
let handled = false;
|
|
4578
|
-
for (const plugin of this
|
|
4595
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4579
4596
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4580
4597
|
if (handled) {
|
|
4581
4598
|
break;
|
|
@@ -4588,35 +4605,35 @@
|
|
|
4588
4605
|
}
|
|
4589
4606
|
paintBase(baseColor) {
|
|
4590
4607
|
this.draw(ctx => {
|
|
4591
|
-
paintBase(ctx, this.
|
|
4608
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4592
4609
|
});
|
|
4593
4610
|
}
|
|
4594
4611
|
paintImage(image, opacity) {
|
|
4595
4612
|
this.draw(ctx => {
|
|
4596
|
-
paintImage(ctx, this.
|
|
4613
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4597
4614
|
});
|
|
4598
4615
|
}
|
|
4599
4616
|
setContext(context) {
|
|
4600
|
-
this
|
|
4601
|
-
if (this
|
|
4602
|
-
this.
|
|
4617
|
+
this.#context = context;
|
|
4618
|
+
if (this.#context) {
|
|
4619
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4603
4620
|
}
|
|
4604
4621
|
}
|
|
4605
4622
|
setContextSettings(settings) {
|
|
4606
|
-
this
|
|
4623
|
+
this.#contextSettings = settings;
|
|
4607
4624
|
}
|
|
4608
4625
|
stop() {
|
|
4609
4626
|
this.draw(ctx => {
|
|
4610
|
-
clear(ctx, this.
|
|
4627
|
+
clear(ctx, this.#canvasManager.size);
|
|
4611
4628
|
});
|
|
4612
4629
|
}
|
|
4613
|
-
|
|
4614
|
-
for (const updater of this
|
|
4630
|
+
#applyPostDrawUpdaters = particle => {
|
|
4631
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4615
4632
|
updater.afterDraw?.(particle);
|
|
4616
4633
|
}
|
|
4617
4634
|
};
|
|
4618
|
-
|
|
4619
|
-
for (const updater of this
|
|
4635
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4636
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4620
4637
|
if (updater.getColorStyles) {
|
|
4621
4638
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4622
4639
|
if (fill) {
|
|
@@ -4635,22 +4652,22 @@
|
|
|
4635
4652
|
updater.beforeDraw?.(particle);
|
|
4636
4653
|
}
|
|
4637
4654
|
};
|
|
4638
|
-
|
|
4655
|
+
#getPluginParticleColors = particle => {
|
|
4639
4656
|
let fColor, sColor;
|
|
4640
|
-
for (const plugin of this
|
|
4657
|
+
for (const plugin of this.#colorPlugins) {
|
|
4641
4658
|
if (!fColor && plugin.particleFillColor) {
|
|
4642
|
-
fColor = rangeColorToHsl(this
|
|
4659
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4643
4660
|
}
|
|
4644
4661
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4645
|
-
sColor = rangeColorToHsl(this
|
|
4662
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4646
4663
|
}
|
|
4647
4664
|
if (fColor && sColor) {
|
|
4648
4665
|
break;
|
|
4649
4666
|
}
|
|
4650
4667
|
}
|
|
4651
|
-
this
|
|
4652
|
-
this
|
|
4653
|
-
return this
|
|
4668
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4669
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4670
|
+
return this.#reusablePluginColors;
|
|
4654
4671
|
};
|
|
4655
4672
|
}
|
|
4656
4673
|
|
|
@@ -4708,53 +4725,53 @@
|
|
|
4708
4725
|
renderCanvas;
|
|
4709
4726
|
size;
|
|
4710
4727
|
zoom = defaultZoom;
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4728
|
+
#container;
|
|
4729
|
+
#generated;
|
|
4730
|
+
#mutationObserver;
|
|
4731
|
+
#originalStyle;
|
|
4732
|
+
#pluginManager;
|
|
4733
|
+
#pointerEvents;
|
|
4734
|
+
#resizePlugins;
|
|
4735
|
+
#standardSize;
|
|
4736
|
+
#zoomCenter;
|
|
4720
4737
|
constructor(pluginManager, container) {
|
|
4721
|
-
this
|
|
4722
|
-
this
|
|
4738
|
+
this.#pluginManager = pluginManager;
|
|
4739
|
+
this.#container = container;
|
|
4723
4740
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4724
|
-
this
|
|
4741
|
+
this.#standardSize = {
|
|
4725
4742
|
height: 0,
|
|
4726
4743
|
width: 0,
|
|
4727
4744
|
};
|
|
4728
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4745
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4729
4746
|
this.size = {
|
|
4730
4747
|
height: stdSize.height * pxRatio,
|
|
4731
4748
|
width: stdSize.width * pxRatio,
|
|
4732
4749
|
};
|
|
4733
|
-
this
|
|
4734
|
-
this
|
|
4735
|
-
this
|
|
4750
|
+
this.#generated = false;
|
|
4751
|
+
this.#resizePlugins = [];
|
|
4752
|
+
this.#pointerEvents = "none";
|
|
4736
4753
|
}
|
|
4737
|
-
get
|
|
4738
|
-
return this.
|
|
4754
|
+
get #fullScreen() {
|
|
4755
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4739
4756
|
}
|
|
4740
4757
|
destroy() {
|
|
4741
4758
|
this.stop();
|
|
4742
|
-
if (this
|
|
4759
|
+
if (this.#generated) {
|
|
4743
4760
|
const element = this.domElement;
|
|
4744
4761
|
element?.remove();
|
|
4745
4762
|
this.domElement = undefined;
|
|
4746
4763
|
this.renderCanvas = undefined;
|
|
4747
4764
|
}
|
|
4748
4765
|
else {
|
|
4749
|
-
this
|
|
4766
|
+
this.#resetOriginalStyle();
|
|
4750
4767
|
}
|
|
4751
4768
|
this.render.destroy();
|
|
4752
|
-
this
|
|
4769
|
+
this.#resizePlugins = [];
|
|
4753
4770
|
}
|
|
4754
4771
|
getZoomCenter() {
|
|
4755
|
-
const pxRatio = this.
|
|
4756
|
-
if (this
|
|
4757
|
-
return this
|
|
4772
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4773
|
+
if (this.#zoomCenter) {
|
|
4774
|
+
return this.#zoomCenter;
|
|
4758
4775
|
}
|
|
4759
4776
|
return {
|
|
4760
4777
|
x: (width * half) / pxRatio,
|
|
@@ -4762,20 +4779,20 @@
|
|
|
4762
4779
|
};
|
|
4763
4780
|
}
|
|
4764
4781
|
init() {
|
|
4765
|
-
this
|
|
4782
|
+
this.#safeMutationObserver(obs => {
|
|
4766
4783
|
obs.disconnect();
|
|
4767
4784
|
});
|
|
4768
|
-
this
|
|
4785
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4769
4786
|
for (const record of records) {
|
|
4770
4787
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4771
|
-
this
|
|
4788
|
+
this.#repairStyle();
|
|
4772
4789
|
}
|
|
4773
4790
|
}
|
|
4774
4791
|
});
|
|
4775
4792
|
this.resize();
|
|
4776
|
-
this
|
|
4793
|
+
this.#initStyle();
|
|
4777
4794
|
this.initBackground();
|
|
4778
|
-
this
|
|
4795
|
+
this.#safeMutationObserver(obs => {
|
|
4779
4796
|
const element = this.domElement;
|
|
4780
4797
|
if (!element || !(element instanceof Node)) {
|
|
4781
4798
|
return;
|
|
@@ -4786,13 +4803,13 @@
|
|
|
4786
4803
|
this.render.init();
|
|
4787
4804
|
}
|
|
4788
4805
|
initBackground() {
|
|
4789
|
-
const
|
|
4806
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4790
4807
|
if (!element) {
|
|
4791
4808
|
return;
|
|
4792
4809
|
}
|
|
4793
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4810
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4794
4811
|
if (color) {
|
|
4795
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4812
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4796
4813
|
}
|
|
4797
4814
|
else {
|
|
4798
4815
|
elementStyle.backgroundColor = "";
|
|
@@ -4803,27 +4820,27 @@
|
|
|
4803
4820
|
elementStyle.backgroundSize = background.size || "";
|
|
4804
4821
|
}
|
|
4805
4822
|
initPlugins() {
|
|
4806
|
-
this
|
|
4807
|
-
for (const plugin of this.
|
|
4823
|
+
this.#resizePlugins = [];
|
|
4824
|
+
for (const plugin of this.#container.plugins) {
|
|
4808
4825
|
if (plugin.resize) {
|
|
4809
|
-
this.
|
|
4826
|
+
this.#resizePlugins.push(plugin);
|
|
4810
4827
|
}
|
|
4811
4828
|
}
|
|
4812
4829
|
}
|
|
4813
4830
|
loadCanvas(canvas) {
|
|
4814
|
-
if (this
|
|
4831
|
+
if (this.#generated && this.domElement) {
|
|
4815
4832
|
this.domElement.remove();
|
|
4816
4833
|
}
|
|
4817
|
-
const container = this
|
|
4834
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4818
4835
|
this.domElement = domCanvas;
|
|
4819
|
-
this
|
|
4836
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4820
4837
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4821
4838
|
const domElement = this.domElement;
|
|
4822
4839
|
if (domElement) {
|
|
4823
4840
|
domElement.ariaHidden = "true";
|
|
4824
|
-
this
|
|
4841
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4825
4842
|
}
|
|
4826
|
-
const standardSize = this
|
|
4843
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4827
4844
|
if (domElement) {
|
|
4828
4845
|
standardSize.height = domElement.offsetHeight;
|
|
4829
4846
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4832,7 +4849,7 @@
|
|
|
4832
4849
|
standardSize.height = renderCanvas.height;
|
|
4833
4850
|
standardSize.width = renderCanvas.width;
|
|
4834
4851
|
}
|
|
4835
|
-
const pxRatio = this.
|
|
4852
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4836
4853
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4837
4854
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4838
4855
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4843,12 +4860,12 @@
|
|
|
4843
4860
|
willReadFrequently: false,
|
|
4844
4861
|
});
|
|
4845
4862
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4846
|
-
this
|
|
4863
|
+
this.#safeMutationObserver(obs => {
|
|
4847
4864
|
obs.disconnect();
|
|
4848
4865
|
});
|
|
4849
4866
|
container.retina.init();
|
|
4850
4867
|
this.initBackground();
|
|
4851
|
-
this
|
|
4868
|
+
this.#safeMutationObserver(obs => {
|
|
4852
4869
|
const element = this.domElement;
|
|
4853
4870
|
if (!element || !(element instanceof Node)) {
|
|
4854
4871
|
return;
|
|
@@ -4861,11 +4878,11 @@
|
|
|
4861
4878
|
if (!element) {
|
|
4862
4879
|
return false;
|
|
4863
4880
|
}
|
|
4864
|
-
const container = this
|
|
4881
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4865
4882
|
if (renderCanvas === undefined) {
|
|
4866
4883
|
return false;
|
|
4867
4884
|
}
|
|
4868
|
-
const currentSize = container.canvas
|
|
4885
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4869
4886
|
width: element.offsetWidth,
|
|
4870
4887
|
height: element.offsetHeight,
|
|
4871
4888
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4884,7 +4901,7 @@
|
|
|
4884
4901
|
const canvasSize = this.size;
|
|
4885
4902
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4886
4903
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4887
|
-
if (this.
|
|
4904
|
+
if (this.#container.started) {
|
|
4888
4905
|
container.particles.setResizeFactor({
|
|
4889
4906
|
width: currentSize.width / oldSize.width,
|
|
4890
4907
|
height: currentSize.height / oldSize.height,
|
|
@@ -4897,46 +4914,46 @@
|
|
|
4897
4914
|
if (!element) {
|
|
4898
4915
|
return;
|
|
4899
4916
|
}
|
|
4900
|
-
this
|
|
4901
|
-
this
|
|
4917
|
+
this.#pointerEvents = type;
|
|
4918
|
+
this.#repairStyle();
|
|
4902
4919
|
}
|
|
4903
4920
|
setZoom(zoomLevel, center) {
|
|
4904
4921
|
this.zoom = zoomLevel;
|
|
4905
|
-
this
|
|
4922
|
+
this.#zoomCenter = center;
|
|
4906
4923
|
}
|
|
4907
4924
|
stop() {
|
|
4908
|
-
this
|
|
4925
|
+
this.#safeMutationObserver(obs => {
|
|
4909
4926
|
obs.disconnect();
|
|
4910
4927
|
});
|
|
4911
|
-
this
|
|
4928
|
+
this.#mutationObserver = undefined;
|
|
4912
4929
|
this.render.stop();
|
|
4913
4930
|
}
|
|
4914
4931
|
async windowResize() {
|
|
4915
4932
|
if (!this.domElement || !this.resize()) {
|
|
4916
4933
|
return;
|
|
4917
4934
|
}
|
|
4918
|
-
const container = this
|
|
4935
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4919
4936
|
container.particles.setDensity();
|
|
4920
|
-
this
|
|
4937
|
+
this.#applyResizePlugins();
|
|
4921
4938
|
if (needsRefresh) {
|
|
4922
4939
|
await container.refresh();
|
|
4923
4940
|
}
|
|
4924
4941
|
}
|
|
4925
|
-
|
|
4926
|
-
for (const plugin of this
|
|
4942
|
+
#applyResizePlugins = () => {
|
|
4943
|
+
for (const plugin of this.#resizePlugins) {
|
|
4927
4944
|
plugin.resize?.();
|
|
4928
4945
|
}
|
|
4929
4946
|
};
|
|
4930
|
-
|
|
4931
|
-
const element = this.domElement, options = this.
|
|
4947
|
+
#initStyle = () => {
|
|
4948
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4932
4949
|
if (!element) {
|
|
4933
4950
|
return;
|
|
4934
4951
|
}
|
|
4935
|
-
if (this
|
|
4936
|
-
this
|
|
4952
|
+
if (this.#fullScreen) {
|
|
4953
|
+
this.#setFullScreenStyle();
|
|
4937
4954
|
}
|
|
4938
4955
|
else {
|
|
4939
|
-
this
|
|
4956
|
+
this.#resetOriginalStyle();
|
|
4940
4957
|
}
|
|
4941
4958
|
for (const key in options.style) {
|
|
4942
4959
|
if (!key || !(key in options.style)) {
|
|
@@ -4949,72 +4966,72 @@
|
|
|
4949
4966
|
element.style.setProperty(key, value, "important");
|
|
4950
4967
|
}
|
|
4951
4968
|
};
|
|
4952
|
-
|
|
4969
|
+
#repairStyle = () => {
|
|
4953
4970
|
const element = this.domElement;
|
|
4954
4971
|
if (!element) {
|
|
4955
4972
|
return;
|
|
4956
4973
|
}
|
|
4957
|
-
this
|
|
4974
|
+
this.#safeMutationObserver(observer => {
|
|
4958
4975
|
observer.disconnect();
|
|
4959
4976
|
});
|
|
4960
|
-
this
|
|
4977
|
+
this.#initStyle();
|
|
4961
4978
|
this.initBackground();
|
|
4962
|
-
const pointerEvents = this
|
|
4979
|
+
const pointerEvents = this.#pointerEvents;
|
|
4963
4980
|
element.style.pointerEvents = pointerEvents;
|
|
4964
4981
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4965
|
-
this
|
|
4982
|
+
this.#safeMutationObserver(observer => {
|
|
4966
4983
|
if (!(element instanceof Node)) {
|
|
4967
4984
|
return;
|
|
4968
4985
|
}
|
|
4969
4986
|
observer.observe(element, { attributes: true });
|
|
4970
4987
|
});
|
|
4971
4988
|
};
|
|
4972
|
-
|
|
4973
|
-
const element = this.domElement, originalStyle = this
|
|
4989
|
+
#resetOriginalStyle = () => {
|
|
4990
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4974
4991
|
if (!element || !originalStyle) {
|
|
4975
4992
|
return;
|
|
4976
4993
|
}
|
|
4977
4994
|
setStyle(element, originalStyle, true);
|
|
4978
4995
|
};
|
|
4979
|
-
|
|
4980
|
-
if (!this
|
|
4996
|
+
#safeMutationObserver = callback => {
|
|
4997
|
+
if (!this.#mutationObserver) {
|
|
4981
4998
|
return;
|
|
4982
4999
|
}
|
|
4983
|
-
callback(this
|
|
5000
|
+
callback(this.#mutationObserver);
|
|
4984
5001
|
};
|
|
4985
|
-
|
|
5002
|
+
#setFullScreenStyle = () => {
|
|
4986
5003
|
const element = this.domElement;
|
|
4987
5004
|
if (!element) {
|
|
4988
5005
|
return;
|
|
4989
5006
|
}
|
|
4990
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5007
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4991
5008
|
};
|
|
4992
5009
|
}
|
|
4993
5010
|
|
|
4994
5011
|
class EventListeners {
|
|
4995
|
-
container;
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
5012
|
+
#container;
|
|
5013
|
+
#handlers;
|
|
5014
|
+
#resizeObserver;
|
|
5015
|
+
#resizeTimeout;
|
|
4999
5016
|
constructor(container) {
|
|
5000
|
-
this
|
|
5001
|
-
this
|
|
5017
|
+
this.#container = container;
|
|
5018
|
+
this.#handlers = {
|
|
5002
5019
|
visibilityChange: () => {
|
|
5003
|
-
this
|
|
5020
|
+
this.#handleVisibilityChange();
|
|
5004
5021
|
},
|
|
5005
5022
|
resize: () => {
|
|
5006
|
-
this
|
|
5023
|
+
this.#handleWindowResize();
|
|
5007
5024
|
},
|
|
5008
5025
|
};
|
|
5009
5026
|
}
|
|
5010
5027
|
addListeners() {
|
|
5011
|
-
this
|
|
5028
|
+
this.#manageListeners(true);
|
|
5012
5029
|
}
|
|
5013
5030
|
removeListeners() {
|
|
5014
|
-
this
|
|
5031
|
+
this.#manageListeners(false);
|
|
5015
5032
|
}
|
|
5016
|
-
|
|
5017
|
-
const container = this
|
|
5033
|
+
#handleVisibilityChange = () => {
|
|
5034
|
+
const container = this.#container, options = container.actualOptions;
|
|
5018
5035
|
if (!options.pauseOnBlur) {
|
|
5019
5036
|
return;
|
|
5020
5037
|
}
|
|
@@ -5032,24 +5049,24 @@
|
|
|
5032
5049
|
}
|
|
5033
5050
|
}
|
|
5034
5051
|
};
|
|
5035
|
-
|
|
5036
|
-
if (this
|
|
5037
|
-
clearTimeout(this
|
|
5038
|
-
|
|
5052
|
+
#handleWindowResize = () => {
|
|
5053
|
+
if (this.#resizeTimeout) {
|
|
5054
|
+
clearTimeout(this.#resizeTimeout);
|
|
5055
|
+
this.#resizeTimeout = undefined;
|
|
5039
5056
|
}
|
|
5040
5057
|
const handleResize = async () => {
|
|
5041
|
-
const canvas = this
|
|
5058
|
+
const canvas = this.#container.canvas;
|
|
5042
5059
|
await canvas.windowResize();
|
|
5043
5060
|
};
|
|
5044
|
-
this
|
|
5061
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5045
5062
|
};
|
|
5046
|
-
|
|
5047
|
-
const handlers = this
|
|
5048
|
-
this
|
|
5063
|
+
#manageListeners = add => {
|
|
5064
|
+
const handlers = this.#handlers;
|
|
5065
|
+
this.#manageResize(add);
|
|
5049
5066
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5050
5067
|
};
|
|
5051
|
-
|
|
5052
|
-
const handlers = this
|
|
5068
|
+
#manageResize = add => {
|
|
5069
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5053
5070
|
if (!options.resize.enable) {
|
|
5054
5071
|
return;
|
|
5055
5072
|
}
|
|
@@ -5058,22 +5075,22 @@
|
|
|
5058
5075
|
return;
|
|
5059
5076
|
}
|
|
5060
5077
|
const canvasEl = container.canvas.domElement;
|
|
5061
|
-
if (this
|
|
5078
|
+
if (this.#resizeObserver && !add) {
|
|
5062
5079
|
if (canvasEl) {
|
|
5063
|
-
this.
|
|
5080
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5064
5081
|
}
|
|
5065
|
-
this.
|
|
5066
|
-
|
|
5082
|
+
this.#resizeObserver.disconnect();
|
|
5083
|
+
this.#resizeObserver = undefined;
|
|
5067
5084
|
}
|
|
5068
|
-
else if (!this
|
|
5069
|
-
this
|
|
5085
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5086
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5070
5087
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5071
5088
|
if (!entry) {
|
|
5072
5089
|
return;
|
|
5073
5090
|
}
|
|
5074
|
-
this
|
|
5091
|
+
this.#handleWindowResize();
|
|
5075
5092
|
});
|
|
5076
|
-
this.
|
|
5093
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5077
5094
|
}
|
|
5078
5095
|
};
|
|
5079
5096
|
}
|
|
@@ -5146,24 +5163,24 @@
|
|
|
5146
5163
|
unbreakable;
|
|
5147
5164
|
velocity;
|
|
5148
5165
|
zIndexFactor;
|
|
5149
|
-
|
|
5166
|
+
#cachedOpacityData = {
|
|
5150
5167
|
fillOpacity: defaultOpacity$1,
|
|
5151
5168
|
opacity: defaultOpacity$1,
|
|
5152
5169
|
strokeOpacity: defaultOpacity$1,
|
|
5153
5170
|
};
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5171
|
+
#cachedPosition = Vector3d.origin;
|
|
5172
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5173
|
+
#cachedTransform = {
|
|
5157
5174
|
a: 1,
|
|
5158
5175
|
b: 0,
|
|
5159
5176
|
c: 0,
|
|
5160
5177
|
d: 1,
|
|
5161
5178
|
};
|
|
5162
|
-
|
|
5163
|
-
|
|
5179
|
+
#container;
|
|
5180
|
+
#pluginManager;
|
|
5164
5181
|
constructor(pluginManager, container) {
|
|
5165
|
-
this
|
|
5166
|
-
this
|
|
5182
|
+
this.#pluginManager = pluginManager;
|
|
5183
|
+
this.#container = container;
|
|
5167
5184
|
}
|
|
5168
5185
|
destroy(override) {
|
|
5169
5186
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5172,7 +5189,7 @@
|
|
|
5172
5189
|
this.destroyed = true;
|
|
5173
5190
|
this.bubble.inRange = false;
|
|
5174
5191
|
this.slow.inRange = false;
|
|
5175
|
-
const container = this
|
|
5192
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5176
5193
|
shapeDrawer?.particleDestroy?.(this);
|
|
5177
5194
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5178
5195
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5180,12 +5197,12 @@
|
|
|
5180
5197
|
for (const updater of container.particleUpdaters) {
|
|
5181
5198
|
updater.particleDestroyed?.(this, override);
|
|
5182
5199
|
}
|
|
5183
|
-
this.
|
|
5200
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5184
5201
|
particle: this,
|
|
5185
5202
|
});
|
|
5186
5203
|
}
|
|
5187
5204
|
draw(delta) {
|
|
5188
|
-
const container = this
|
|
5205
|
+
const container = this.#container, render = container.canvas.render;
|
|
5189
5206
|
render.drawParticlePlugins(this, delta);
|
|
5190
5207
|
render.drawParticle(this, delta);
|
|
5191
5208
|
}
|
|
@@ -5193,50 +5210,50 @@
|
|
|
5193
5210
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5194
5211
|
}
|
|
5195
5212
|
getFillColor() {
|
|
5196
|
-
return this
|
|
5213
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5197
5214
|
}
|
|
5198
5215
|
getMass() {
|
|
5199
5216
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5200
5217
|
}
|
|
5201
5218
|
getOpacity() {
|
|
5202
5219
|
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;
|
|
5203
|
-
this.
|
|
5204
|
-
this.
|
|
5205
|
-
this.
|
|
5206
|
-
return this
|
|
5220
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5221
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5222
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5223
|
+
return this.#cachedOpacityData;
|
|
5207
5224
|
}
|
|
5208
5225
|
getPosition() {
|
|
5209
|
-
this.
|
|
5210
|
-
this.
|
|
5211
|
-
this.
|
|
5212
|
-
return this
|
|
5226
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5227
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5228
|
+
this.#cachedPosition.z = this.position.z;
|
|
5229
|
+
return this.#cachedPosition;
|
|
5213
5230
|
}
|
|
5214
5231
|
getRadius() {
|
|
5215
5232
|
return this.bubble.radius ?? this.size.value;
|
|
5216
5233
|
}
|
|
5217
5234
|
getRotateData() {
|
|
5218
5235
|
const angle = this.getAngle();
|
|
5219
|
-
this.
|
|
5220
|
-
this.
|
|
5221
|
-
return this
|
|
5236
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5237
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5238
|
+
return this.#cachedRotateData;
|
|
5222
5239
|
}
|
|
5223
5240
|
getStrokeColor() {
|
|
5224
|
-
return this
|
|
5241
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5225
5242
|
}
|
|
5226
5243
|
getTransformData(externalTransform) {
|
|
5227
5244
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5228
|
-
this.
|
|
5229
|
-
this.
|
|
5245
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5246
|
+
this.#cachedTransform.b = rotating
|
|
5230
5247
|
? rotateData.sin * (externalTransform.b ?? identity$2)
|
|
5231
5248
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5232
|
-
this.
|
|
5249
|
+
this.#cachedTransform.c = rotating
|
|
5233
5250
|
? -rotateData.sin * (externalTransform.c ?? identity$2)
|
|
5234
5251
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5235
|
-
this.
|
|
5236
|
-
return this
|
|
5252
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5253
|
+
return this.#cachedTransform;
|
|
5237
5254
|
}
|
|
5238
5255
|
init(id, position, overrideOptions, group) {
|
|
5239
|
-
const container = this
|
|
5256
|
+
const container = this.#container;
|
|
5240
5257
|
this.id = id;
|
|
5241
5258
|
this.group = group;
|
|
5242
5259
|
this.justWarped = false;
|
|
@@ -5256,21 +5273,27 @@
|
|
|
5256
5273
|
moveSpeed: 0,
|
|
5257
5274
|
sizeAnimationSpeed: 0,
|
|
5258
5275
|
};
|
|
5276
|
+
this.size = {
|
|
5277
|
+
value: 1,
|
|
5278
|
+
max: 1,
|
|
5279
|
+
min: 1,
|
|
5280
|
+
enable: false,
|
|
5281
|
+
};
|
|
5259
5282
|
this.outType = ParticleOutType.normal;
|
|
5260
5283
|
this.ignoresResizeRatio = true;
|
|
5261
|
-
const
|
|
5284
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5262
5285
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5263
5286
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5264
5287
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5265
5288
|
if (overrideOptions) {
|
|
5266
|
-
if (overrideOptions.effect?.type) {
|
|
5289
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5267
5290
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5268
5291
|
if (effect) {
|
|
5269
5292
|
this.effect = effect;
|
|
5270
5293
|
effectOptions.load(overrideOptions.effect);
|
|
5271
5294
|
}
|
|
5272
5295
|
}
|
|
5273
|
-
if (overrideOptions.shape?.type) {
|
|
5296
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5274
5297
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5275
5298
|
if (shape) {
|
|
5276
5299
|
this.shape = shape;
|
|
@@ -5279,21 +5302,20 @@
|
|
|
5279
5302
|
}
|
|
5280
5303
|
}
|
|
5281
5304
|
if (this.effect === randomColorValue) {
|
|
5282
|
-
const availableEffects = [...this.
|
|
5305
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5283
5306
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5284
5307
|
}
|
|
5285
5308
|
if (this.shape === randomColorValue) {
|
|
5286
|
-
const availableShapes = [...this.
|
|
5309
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5287
5310
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5288
5311
|
}
|
|
5289
5312
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5290
5313
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5291
5314
|
particlesOptions.load(overrideOptions);
|
|
5292
|
-
const effectData = this.effectData;
|
|
5315
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5293
5316
|
if (effectData) {
|
|
5294
5317
|
particlesOptions.load(effectData.particles);
|
|
5295
5318
|
}
|
|
5296
|
-
const shapeData = this.shapeData;
|
|
5297
5319
|
if (shapeData) {
|
|
5298
5320
|
particlesOptions.load(shapeData.particles);
|
|
5299
5321
|
}
|
|
@@ -5301,7 +5323,9 @@
|
|
|
5301
5323
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5302
5324
|
this.options = particlesOptions;
|
|
5303
5325
|
container.retina.initParticle(this);
|
|
5304
|
-
|
|
5326
|
+
for (const updater of container.particleUpdaters) {
|
|
5327
|
+
updater.preInit?.(this);
|
|
5328
|
+
}
|
|
5305
5329
|
this.bubble = {
|
|
5306
5330
|
inRange: false,
|
|
5307
5331
|
};
|
|
@@ -5309,8 +5333,8 @@
|
|
|
5309
5333
|
inRange: false,
|
|
5310
5334
|
factor: 1,
|
|
5311
5335
|
};
|
|
5312
|
-
this
|
|
5313
|
-
this.initialVelocity = this
|
|
5336
|
+
this.#initPosition(position);
|
|
5337
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5314
5338
|
this.velocity = this.initialVelocity.copy();
|
|
5315
5339
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5316
5340
|
this.sides = 24;
|
|
@@ -5341,12 +5365,11 @@
|
|
|
5341
5365
|
plugin.particleCreated?.(this);
|
|
5342
5366
|
}
|
|
5343
5367
|
}
|
|
5344
|
-
isInsideCanvas() {
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
position.x <= canvasSize.width + radius);
|
|
5368
|
+
isInsideCanvas(direction) {
|
|
5369
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5370
|
+
}
|
|
5371
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5372
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5350
5373
|
}
|
|
5351
5374
|
isShowingBack() {
|
|
5352
5375
|
if (!this.roll) {
|
|
@@ -5371,13 +5394,13 @@
|
|
|
5371
5394
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5372
5395
|
}
|
|
5373
5396
|
reset() {
|
|
5374
|
-
for (const updater of this.
|
|
5397
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5375
5398
|
updater.reset?.(this);
|
|
5376
5399
|
}
|
|
5377
5400
|
}
|
|
5378
|
-
|
|
5401
|
+
#calcPosition = (position, zIndex) => {
|
|
5379
5402
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5380
|
-
const container = this
|
|
5403
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5381
5404
|
while (!signal.aborted) {
|
|
5382
5405
|
for (const plugin of plugins) {
|
|
5383
5406
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5389,10 +5412,10 @@
|
|
|
5389
5412
|
size: canvasSize,
|
|
5390
5413
|
position: posVec,
|
|
5391
5414
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5392
|
-
this
|
|
5393
|
-
this
|
|
5394
|
-
this
|
|
5395
|
-
this
|
|
5415
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5416
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5417
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5418
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5396
5419
|
let isValidPosition = true;
|
|
5397
5420
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5398
5421
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5408,8 +5431,8 @@
|
|
|
5408
5431
|
}
|
|
5409
5432
|
return posVec;
|
|
5410
5433
|
};
|
|
5411
|
-
|
|
5412
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5434
|
+
#calculateVelocity = () => {
|
|
5435
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5413
5436
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5414
5437
|
return res;
|
|
5415
5438
|
}
|
|
@@ -5425,27 +5448,86 @@
|
|
|
5425
5448
|
}
|
|
5426
5449
|
return res;
|
|
5427
5450
|
};
|
|
5428
|
-
|
|
5451
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5429
5452
|
fixOutMode({
|
|
5430
5453
|
outMode,
|
|
5431
5454
|
checkModes: [OutMode.bounce],
|
|
5432
5455
|
coord: pos.x,
|
|
5433
|
-
maxCoord: this.
|
|
5456
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5434
5457
|
setCb: (value) => (pos.x += value),
|
|
5435
5458
|
radius,
|
|
5436
5459
|
});
|
|
5437
5460
|
};
|
|
5438
|
-
|
|
5461
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5439
5462
|
fixOutMode({
|
|
5440
5463
|
outMode,
|
|
5441
5464
|
checkModes: [OutMode.bounce],
|
|
5442
5465
|
coord: pos.y,
|
|
5443
|
-
maxCoord: this.
|
|
5466
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5444
5467
|
setCb: (value) => (pos.y += value),
|
|
5445
5468
|
radius,
|
|
5446
5469
|
});
|
|
5447
5470
|
};
|
|
5448
|
-
|
|
5471
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5472
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5473
|
+
if (direction === OutModeDirection.bottom) {
|
|
5474
|
+
return {
|
|
5475
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5476
|
+
reason: "default",
|
|
5477
|
+
};
|
|
5478
|
+
}
|
|
5479
|
+
if (direction === OutModeDirection.left) {
|
|
5480
|
+
return {
|
|
5481
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5482
|
+
reason: "default",
|
|
5483
|
+
};
|
|
5484
|
+
}
|
|
5485
|
+
if (direction === OutModeDirection.right) {
|
|
5486
|
+
return {
|
|
5487
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5488
|
+
reason: "default",
|
|
5489
|
+
};
|
|
5490
|
+
}
|
|
5491
|
+
if (direction === OutModeDirection.top) {
|
|
5492
|
+
return {
|
|
5493
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5494
|
+
reason: "default",
|
|
5495
|
+
};
|
|
5496
|
+
}
|
|
5497
|
+
return {
|
|
5498
|
+
inside: position.x >= -radius &&
|
|
5499
|
+
position.y >= -radius &&
|
|
5500
|
+
position.y <= canvasSize.height + radius &&
|
|
5501
|
+
position.x <= canvasSize.width + radius,
|
|
5502
|
+
reason: "default",
|
|
5503
|
+
};
|
|
5504
|
+
};
|
|
5505
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5506
|
+
return {
|
|
5507
|
+
canvasSize: this.#container.canvas.size,
|
|
5508
|
+
direction,
|
|
5509
|
+
outMode,
|
|
5510
|
+
particle: this,
|
|
5511
|
+
radius: this.getRadius(),
|
|
5512
|
+
};
|
|
5513
|
+
};
|
|
5514
|
+
#getInsideCanvasResult = (data) => {
|
|
5515
|
+
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;
|
|
5516
|
+
if (!shapeCheck && !effectCheck) {
|
|
5517
|
+
return defaultResult;
|
|
5518
|
+
}
|
|
5519
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5520
|
+
if (shapeResult && effectResult) {
|
|
5521
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5522
|
+
return {
|
|
5523
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5524
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5525
|
+
reason: "combined",
|
|
5526
|
+
};
|
|
5527
|
+
}
|
|
5528
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5529
|
+
};
|
|
5530
|
+
#getRollColor = color => {
|
|
5449
5531
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5450
5532
|
return color;
|
|
5451
5533
|
}
|
|
@@ -5460,8 +5542,8 @@
|
|
|
5460
5542
|
}
|
|
5461
5543
|
return color;
|
|
5462
5544
|
};
|
|
5463
|
-
|
|
5464
|
-
const container = this
|
|
5545
|
+
#initPosition = position => {
|
|
5546
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5465
5547
|
if (!initialPosition) {
|
|
5466
5548
|
throw new Error("a valid position cannot be found for particle");
|
|
5467
5549
|
}
|
|
@@ -5484,45 +5566,58 @@
|
|
|
5484
5566
|
}
|
|
5485
5567
|
this.offset = Vector.origin;
|
|
5486
5568
|
};
|
|
5569
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5570
|
+
if (typeof result === "boolean") {
|
|
5571
|
+
return {
|
|
5572
|
+
inside: result,
|
|
5573
|
+
reason,
|
|
5574
|
+
};
|
|
5575
|
+
}
|
|
5576
|
+
return {
|
|
5577
|
+
inside: result.inside,
|
|
5578
|
+
margin: result.margin,
|
|
5579
|
+
reason: result.reason ?? reason,
|
|
5580
|
+
};
|
|
5581
|
+
};
|
|
5487
5582
|
}
|
|
5488
5583
|
|
|
5489
5584
|
class SpatialHashGrid {
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5585
|
+
#cellSize;
|
|
5586
|
+
#cells = new Map();
|
|
5587
|
+
#circlePool = [];
|
|
5588
|
+
#circlePoolIdx;
|
|
5589
|
+
#pendingCellSize;
|
|
5590
|
+
#rectanglePool = [];
|
|
5591
|
+
#rectanglePoolIdx;
|
|
5497
5592
|
constructor(cellSize) {
|
|
5498
|
-
this
|
|
5499
|
-
this
|
|
5500
|
-
this
|
|
5593
|
+
this.#cellSize = cellSize;
|
|
5594
|
+
this.#circlePoolIdx = 0;
|
|
5595
|
+
this.#rectanglePoolIdx = 0;
|
|
5501
5596
|
}
|
|
5502
5597
|
clear() {
|
|
5503
|
-
this.
|
|
5504
|
-
const pendingCellSize = this
|
|
5598
|
+
this.#cells.clear();
|
|
5599
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5505
5600
|
if (pendingCellSize) {
|
|
5506
|
-
this
|
|
5601
|
+
this.#cellSize = pendingCellSize;
|
|
5507
5602
|
}
|
|
5508
|
-
this
|
|
5603
|
+
this.#pendingCellSize = undefined;
|
|
5509
5604
|
}
|
|
5510
5605
|
insert(particle) {
|
|
5511
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5512
|
-
if (!this.
|
|
5513
|
-
this.
|
|
5606
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5607
|
+
if (!this.#cells.has(key)) {
|
|
5608
|
+
this.#cells.set(key, []);
|
|
5514
5609
|
}
|
|
5515
|
-
this.
|
|
5610
|
+
this.#cells.get(key)?.push(particle);
|
|
5516
5611
|
}
|
|
5517
5612
|
query(range, check, out = []) {
|
|
5518
|
-
const bounds = this
|
|
5613
|
+
const bounds = this.#getRangeBounds(range);
|
|
5519
5614
|
if (!bounds) {
|
|
5520
5615
|
return out;
|
|
5521
5616
|
}
|
|
5522
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5617
|
+
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);
|
|
5523
5618
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5524
5619
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5525
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5620
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5526
5621
|
if (!cellParticles) {
|
|
5527
5622
|
continue;
|
|
5528
5623
|
}
|
|
@@ -5539,29 +5634,29 @@
|
|
|
5539
5634
|
return out;
|
|
5540
5635
|
}
|
|
5541
5636
|
queryCircle(position, radius, check, out = []) {
|
|
5542
|
-
const circle = this
|
|
5543
|
-
this
|
|
5637
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5638
|
+
this.#releaseShapes();
|
|
5544
5639
|
return result;
|
|
5545
5640
|
}
|
|
5546
5641
|
queryRectangle(position, size, check, out = []) {
|
|
5547
|
-
const rect = this
|
|
5548
|
-
this
|
|
5642
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5643
|
+
this.#releaseShapes();
|
|
5549
5644
|
return result;
|
|
5550
5645
|
}
|
|
5551
5646
|
setCellSize(cellSize) {
|
|
5552
|
-
this
|
|
5647
|
+
this.#pendingCellSize = cellSize;
|
|
5553
5648
|
}
|
|
5554
|
-
|
|
5555
|
-
return (this
|
|
5649
|
+
#acquireCircle(x, y, r) {
|
|
5650
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5556
5651
|
}
|
|
5557
|
-
|
|
5558
|
-
return (this
|
|
5652
|
+
#acquireRectangle(x, y, w, h) {
|
|
5653
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5559
5654
|
}
|
|
5560
|
-
|
|
5561
|
-
const cellX = Math.floor(x / this
|
|
5655
|
+
#cellKeyFromCoords(x, y) {
|
|
5656
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5562
5657
|
return `${cellX}_${cellY}`;
|
|
5563
5658
|
}
|
|
5564
|
-
|
|
5659
|
+
#getRangeBounds(range) {
|
|
5565
5660
|
if (range instanceof Circle) {
|
|
5566
5661
|
const r = range.radius, { x, y } = range.position;
|
|
5567
5662
|
return {
|
|
@@ -5582,53 +5677,53 @@
|
|
|
5582
5677
|
}
|
|
5583
5678
|
return null;
|
|
5584
5679
|
}
|
|
5585
|
-
|
|
5586
|
-
this
|
|
5587
|
-
this
|
|
5680
|
+
#releaseShapes() {
|
|
5681
|
+
this.#circlePoolIdx = 0;
|
|
5682
|
+
this.#rectanglePoolIdx = 0;
|
|
5588
5683
|
}
|
|
5589
5684
|
}
|
|
5590
5685
|
|
|
5591
5686
|
class ParticlesManager {
|
|
5592
5687
|
checkParticlePositionPlugins;
|
|
5593
5688
|
grid;
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5689
|
+
#array;
|
|
5690
|
+
#container;
|
|
5691
|
+
#groupLimits;
|
|
5692
|
+
#limit;
|
|
5693
|
+
#nextId;
|
|
5694
|
+
#particleBuckets;
|
|
5695
|
+
#particleResetPlugins;
|
|
5696
|
+
#particleUpdatePlugins;
|
|
5697
|
+
#pluginManager;
|
|
5698
|
+
#pool;
|
|
5699
|
+
#postParticleUpdatePlugins;
|
|
5700
|
+
#postUpdatePlugins;
|
|
5701
|
+
#resizeFactor;
|
|
5702
|
+
#updatePlugins;
|
|
5703
|
+
#zBuckets;
|
|
5609
5704
|
constructor(pluginManager, container) {
|
|
5610
|
-
this
|
|
5611
|
-
this
|
|
5612
|
-
this
|
|
5613
|
-
this
|
|
5614
|
-
this
|
|
5615
|
-
this
|
|
5616
|
-
this
|
|
5617
|
-
this
|
|
5618
|
-
this
|
|
5705
|
+
this.#pluginManager = pluginManager;
|
|
5706
|
+
this.#container = container;
|
|
5707
|
+
this.#nextId = 0;
|
|
5708
|
+
this.#array = [];
|
|
5709
|
+
this.#pool = [];
|
|
5710
|
+
this.#limit = 0;
|
|
5711
|
+
this.#groupLimits = new Map();
|
|
5712
|
+
this.#particleBuckets = new Map();
|
|
5713
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5619
5714
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5620
5715
|
this.checkParticlePositionPlugins = [];
|
|
5621
|
-
this
|
|
5622
|
-
this
|
|
5623
|
-
this
|
|
5624
|
-
this
|
|
5625
|
-
this
|
|
5716
|
+
this.#particleResetPlugins = [];
|
|
5717
|
+
this.#particleUpdatePlugins = [];
|
|
5718
|
+
this.#postUpdatePlugins = [];
|
|
5719
|
+
this.#postParticleUpdatePlugins = [];
|
|
5720
|
+
this.#updatePlugins = [];
|
|
5626
5721
|
}
|
|
5627
5722
|
get count() {
|
|
5628
|
-
return this.
|
|
5723
|
+
return this.#array.length;
|
|
5629
5724
|
}
|
|
5630
5725
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5631
|
-
const limitMode = this.
|
|
5726
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5632
5727
|
if (limit > minLimit) {
|
|
5633
5728
|
switch (limitMode) {
|
|
5634
5729
|
case LimitMode.delete: {
|
|
@@ -5646,20 +5741,20 @@
|
|
|
5646
5741
|
}
|
|
5647
5742
|
}
|
|
5648
5743
|
try {
|
|
5649
|
-
const particle = this.
|
|
5650
|
-
particle.init(this
|
|
5744
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5745
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5651
5746
|
let canAdd = true;
|
|
5652
5747
|
if (initializer) {
|
|
5653
5748
|
canAdd = initializer(particle);
|
|
5654
5749
|
}
|
|
5655
5750
|
if (!canAdd) {
|
|
5656
|
-
this.
|
|
5751
|
+
this.#pool.push(particle);
|
|
5657
5752
|
return;
|
|
5658
5753
|
}
|
|
5659
|
-
this.
|
|
5660
|
-
this
|
|
5661
|
-
this
|
|
5662
|
-
this.
|
|
5754
|
+
this.#array.push(particle);
|
|
5755
|
+
this.#insertParticleIntoBucket(particle);
|
|
5756
|
+
this.#nextId++;
|
|
5757
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5663
5758
|
particle,
|
|
5664
5759
|
});
|
|
5665
5760
|
return particle;
|
|
@@ -5670,25 +5765,25 @@
|
|
|
5670
5765
|
return undefined;
|
|
5671
5766
|
}
|
|
5672
5767
|
clear() {
|
|
5673
|
-
this
|
|
5674
|
-
this.
|
|
5675
|
-
this
|
|
5768
|
+
this.#array = [];
|
|
5769
|
+
this.#particleBuckets.clear();
|
|
5770
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5676
5771
|
}
|
|
5677
5772
|
destroy() {
|
|
5678
|
-
this
|
|
5679
|
-
this.
|
|
5680
|
-
this.
|
|
5681
|
-
this
|
|
5773
|
+
this.#array = [];
|
|
5774
|
+
this.#pool.length = 0;
|
|
5775
|
+
this.#particleBuckets.clear();
|
|
5776
|
+
this.#zBuckets = [];
|
|
5682
5777
|
this.checkParticlePositionPlugins = [];
|
|
5683
|
-
this
|
|
5684
|
-
this
|
|
5685
|
-
this
|
|
5686
|
-
this
|
|
5687
|
-
this
|
|
5778
|
+
this.#particleResetPlugins = [];
|
|
5779
|
+
this.#particleUpdatePlugins = [];
|
|
5780
|
+
this.#postUpdatePlugins = [];
|
|
5781
|
+
this.#postParticleUpdatePlugins = [];
|
|
5782
|
+
this.#updatePlugins = [];
|
|
5688
5783
|
}
|
|
5689
5784
|
drawParticles(delta) {
|
|
5690
|
-
for (let i = this.
|
|
5691
|
-
const bucket = this
|
|
5785
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5786
|
+
const bucket = this.#zBuckets[i];
|
|
5692
5787
|
if (!bucket) {
|
|
5693
5788
|
continue;
|
|
5694
5789
|
}
|
|
@@ -5698,24 +5793,24 @@
|
|
|
5698
5793
|
}
|
|
5699
5794
|
}
|
|
5700
5795
|
filter(condition) {
|
|
5701
|
-
return this.
|
|
5796
|
+
return this.#array.filter(condition);
|
|
5702
5797
|
}
|
|
5703
5798
|
find(condition) {
|
|
5704
|
-
return this.
|
|
5799
|
+
return this.#array.find(condition);
|
|
5705
5800
|
}
|
|
5706
5801
|
get(index) {
|
|
5707
|
-
return this
|
|
5802
|
+
return this.#array[index];
|
|
5708
5803
|
}
|
|
5709
5804
|
async init() {
|
|
5710
|
-
const container = this
|
|
5805
|
+
const container = this.#container, options = container.actualOptions;
|
|
5711
5806
|
this.checkParticlePositionPlugins = [];
|
|
5712
|
-
this
|
|
5713
|
-
this
|
|
5714
|
-
this
|
|
5715
|
-
this
|
|
5716
|
-
this
|
|
5717
|
-
this.
|
|
5718
|
-
this
|
|
5807
|
+
this.#updatePlugins = [];
|
|
5808
|
+
this.#particleUpdatePlugins = [];
|
|
5809
|
+
this.#postUpdatePlugins = [];
|
|
5810
|
+
this.#particleResetPlugins = [];
|
|
5811
|
+
this.#postParticleUpdatePlugins = [];
|
|
5812
|
+
this.#particleBuckets.clear();
|
|
5813
|
+
this.#resetBuckets(container.zLayers);
|
|
5719
5814
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5720
5815
|
for (const plugin of container.plugins) {
|
|
5721
5816
|
if (plugin.redrawInit) {
|
|
@@ -5725,26 +5820,26 @@
|
|
|
5725
5820
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5726
5821
|
}
|
|
5727
5822
|
if (plugin.update) {
|
|
5728
|
-
this.
|
|
5823
|
+
this.#updatePlugins.push(plugin);
|
|
5729
5824
|
}
|
|
5730
5825
|
if (plugin.particleUpdate) {
|
|
5731
|
-
this.
|
|
5826
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5732
5827
|
}
|
|
5733
5828
|
if (plugin.postUpdate) {
|
|
5734
|
-
this.
|
|
5829
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5735
5830
|
}
|
|
5736
5831
|
if (plugin.particleReset) {
|
|
5737
|
-
this.
|
|
5832
|
+
this.#particleResetPlugins.push(plugin);
|
|
5738
5833
|
}
|
|
5739
5834
|
if (plugin.postParticleUpdate) {
|
|
5740
|
-
this.
|
|
5835
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5741
5836
|
}
|
|
5742
5837
|
}
|
|
5743
|
-
await this.
|
|
5744
|
-
for (const drawer of this.
|
|
5838
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5839
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5745
5840
|
await drawer.init?.(container);
|
|
5746
5841
|
}
|
|
5747
|
-
for (const drawer of this.
|
|
5842
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5748
5843
|
await drawer.init?.(container);
|
|
5749
5844
|
}
|
|
5750
5845
|
let handled = false;
|
|
@@ -5778,10 +5873,10 @@
|
|
|
5778
5873
|
async redraw() {
|
|
5779
5874
|
this.clear();
|
|
5780
5875
|
await this.init();
|
|
5781
|
-
this.
|
|
5876
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5782
5877
|
}
|
|
5783
5878
|
remove(particle, group, override) {
|
|
5784
|
-
this.removeAt(this.
|
|
5879
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5785
5880
|
}
|
|
5786
5881
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5787
5882
|
if (index < minIndex || index > this.count) {
|
|
@@ -5789,7 +5884,7 @@
|
|
|
5789
5884
|
}
|
|
5790
5885
|
let deleted = 0;
|
|
5791
5886
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5792
|
-
if (this
|
|
5887
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5793
5888
|
i--;
|
|
5794
5889
|
deleted++;
|
|
5795
5890
|
}
|
|
@@ -5799,9 +5894,9 @@
|
|
|
5799
5894
|
this.removeAt(minIndex, quantity, group);
|
|
5800
5895
|
}
|
|
5801
5896
|
setDensity() {
|
|
5802
|
-
const options = this.
|
|
5897
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5803
5898
|
let pluginsCount = 0;
|
|
5804
|
-
for (const plugin of this.
|
|
5899
|
+
for (const plugin of this.#container.plugins) {
|
|
5805
5900
|
if (plugin.particlesDensityCount) {
|
|
5806
5901
|
pluginsCount += plugin.particlesDensityCount();
|
|
5807
5902
|
}
|
|
@@ -5811,51 +5906,51 @@
|
|
|
5811
5906
|
if (!groupData) {
|
|
5812
5907
|
continue;
|
|
5813
5908
|
}
|
|
5814
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5815
|
-
this
|
|
5909
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5910
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5816
5911
|
}
|
|
5817
|
-
this
|
|
5912
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5818
5913
|
}
|
|
5819
5914
|
setResizeFactor(factor) {
|
|
5820
|
-
this
|
|
5915
|
+
this.#resizeFactor = factor;
|
|
5821
5916
|
}
|
|
5822
5917
|
update(delta) {
|
|
5823
5918
|
this.grid.clear();
|
|
5824
|
-
for (const plugin of this
|
|
5919
|
+
for (const plugin of this.#updatePlugins) {
|
|
5825
5920
|
plugin.update?.(delta);
|
|
5826
5921
|
}
|
|
5827
|
-
const particlesToDelete = this
|
|
5828
|
-
for (const plugin of this
|
|
5922
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5923
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5829
5924
|
plugin.postUpdate?.(delta);
|
|
5830
5925
|
}
|
|
5831
|
-
this
|
|
5926
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5832
5927
|
if (particlesToDelete.size) {
|
|
5833
5928
|
for (const particle of particlesToDelete) {
|
|
5834
5929
|
this.remove(particle);
|
|
5835
5930
|
}
|
|
5836
5931
|
}
|
|
5837
|
-
|
|
5932
|
+
this.#resizeFactor = undefined;
|
|
5838
5933
|
}
|
|
5839
|
-
|
|
5840
|
-
this.
|
|
5934
|
+
#addToPool = (...particles) => {
|
|
5935
|
+
this.#pool.push(...particles);
|
|
5841
5936
|
};
|
|
5842
|
-
|
|
5937
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5843
5938
|
const numberOptions = options.number;
|
|
5844
5939
|
if (!numberOptions.density.enable) {
|
|
5845
5940
|
if (group === undefined) {
|
|
5846
|
-
this
|
|
5941
|
+
this.#limit = numberOptions.limit.value;
|
|
5847
5942
|
}
|
|
5848
5943
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5849
|
-
this.
|
|
5944
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5850
5945
|
}
|
|
5851
5946
|
return;
|
|
5852
5947
|
}
|
|
5853
|
-
const densityFactor = this
|
|
5948
|
+
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);
|
|
5854
5949
|
if (group === undefined) {
|
|
5855
|
-
this
|
|
5950
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5856
5951
|
}
|
|
5857
5952
|
else {
|
|
5858
|
-
this.
|
|
5953
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5859
5954
|
}
|
|
5860
5955
|
if (particlesCount < particlesNumber) {
|
|
5861
5956
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5864,18 +5959,18 @@
|
|
|
5864
5959
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5865
5960
|
}
|
|
5866
5961
|
};
|
|
5867
|
-
|
|
5962
|
+
#createBuckets = (zLayers) => {
|
|
5868
5963
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5869
5964
|
return Array.from({ length: bucketCount }, () => []);
|
|
5870
5965
|
};
|
|
5871
|
-
|
|
5872
|
-
const maxBucketIndex = this.
|
|
5966
|
+
#getBucketIndex = (zIndex) => {
|
|
5967
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5873
5968
|
if (maxBucketIndex <= minIndex) {
|
|
5874
5969
|
return minIndex;
|
|
5875
5970
|
}
|
|
5876
5971
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5877
5972
|
};
|
|
5878
|
-
|
|
5973
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5879
5974
|
let start = minIndex, end = bucket.length;
|
|
5880
5975
|
while (start < end) {
|
|
5881
5976
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5892,8 +5987,8 @@
|
|
|
5892
5987
|
}
|
|
5893
5988
|
return start;
|
|
5894
5989
|
};
|
|
5895
|
-
|
|
5896
|
-
const container = this
|
|
5990
|
+
#initDensityFactor = densityOptions => {
|
|
5991
|
+
const container = this.#container;
|
|
5897
5992
|
if (!densityOptions.enable) {
|
|
5898
5993
|
return defaultDensityFactor;
|
|
5899
5994
|
}
|
|
@@ -5903,82 +5998,82 @@
|
|
|
5903
5998
|
}
|
|
5904
5999
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5905
6000
|
};
|
|
5906
|
-
|
|
5907
|
-
const bucketIndex = this
|
|
6001
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6002
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5908
6003
|
if (!bucket) {
|
|
5909
6004
|
return;
|
|
5910
6005
|
}
|
|
5911
|
-
bucket.splice(this
|
|
5912
|
-
this.
|
|
6006
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6007
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5913
6008
|
};
|
|
5914
|
-
|
|
5915
|
-
const particle = this
|
|
6009
|
+
#removeParticle = (index, group, override) => {
|
|
6010
|
+
const particle = this.#array[index];
|
|
5916
6011
|
if (!particle) {
|
|
5917
6012
|
return false;
|
|
5918
6013
|
}
|
|
5919
6014
|
if (particle.group !== group) {
|
|
5920
6015
|
return false;
|
|
5921
6016
|
}
|
|
5922
|
-
this.
|
|
5923
|
-
this
|
|
6017
|
+
this.#array.splice(index, deleteCount);
|
|
6018
|
+
this.#removeParticleFromBucket(particle);
|
|
5924
6019
|
particle.destroy(override);
|
|
5925
|
-
this.
|
|
6020
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5926
6021
|
particle,
|
|
5927
6022
|
});
|
|
5928
|
-
this
|
|
6023
|
+
this.#addToPool(particle);
|
|
5929
6024
|
return true;
|
|
5930
6025
|
};
|
|
5931
|
-
|
|
5932
|
-
const bucketIndex = this.
|
|
6026
|
+
#removeParticleFromBucket = (particle) => {
|
|
6027
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5933
6028
|
if (!bucket) {
|
|
5934
|
-
this.
|
|
6029
|
+
this.#particleBuckets.delete(particle.id);
|
|
5935
6030
|
return;
|
|
5936
6031
|
}
|
|
5937
|
-
const particleIndex = this
|
|
6032
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5938
6033
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5939
|
-
this.
|
|
6034
|
+
this.#particleBuckets.delete(particle.id);
|
|
5940
6035
|
return;
|
|
5941
6036
|
}
|
|
5942
6037
|
bucket.splice(particleIndex, deleteCount);
|
|
5943
|
-
this.
|
|
6038
|
+
this.#particleBuckets.delete(particle.id);
|
|
5944
6039
|
};
|
|
5945
|
-
|
|
6040
|
+
#resetBuckets = (zLayers) => {
|
|
5946
6041
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5947
|
-
if (this.
|
|
5948
|
-
this
|
|
6042
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6043
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5949
6044
|
return;
|
|
5950
6045
|
}
|
|
5951
|
-
for (const bucket of this
|
|
6046
|
+
for (const bucket of this.#zBuckets) {
|
|
5952
6047
|
bucket.length = minIndex;
|
|
5953
6048
|
}
|
|
5954
6049
|
};
|
|
5955
|
-
|
|
5956
|
-
const newBucketIndex = this
|
|
6050
|
+
#updateParticleBucket = (particle) => {
|
|
6051
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5957
6052
|
if (currentBucketIndex === undefined) {
|
|
5958
|
-
this
|
|
6053
|
+
this.#insertParticleIntoBucket(particle);
|
|
5959
6054
|
return;
|
|
5960
6055
|
}
|
|
5961
6056
|
if (currentBucketIndex === newBucketIndex) {
|
|
5962
6057
|
return;
|
|
5963
6058
|
}
|
|
5964
|
-
const currentBucket = this
|
|
6059
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5965
6060
|
if (currentBucket) {
|
|
5966
|
-
const particleIndex = this
|
|
6061
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5967
6062
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5968
6063
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5969
6064
|
}
|
|
5970
6065
|
}
|
|
5971
|
-
const newBucket = this
|
|
6066
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5972
6067
|
if (!newBucket) {
|
|
5973
|
-
this.
|
|
6068
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5974
6069
|
return;
|
|
5975
6070
|
}
|
|
5976
|
-
newBucket.splice(this
|
|
5977
|
-
this.
|
|
6071
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6072
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5978
6073
|
};
|
|
5979
|
-
|
|
5980
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5981
|
-
for (const particle of this
|
|
6074
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6075
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6076
|
+
for (const particle of this.#array) {
|
|
5982
6077
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5983
6078
|
particle.position.x *= resizeFactor.width;
|
|
5984
6079
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5986,10 +6081,10 @@
|
|
|
5986
6081
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5987
6082
|
}
|
|
5988
6083
|
particle.ignoresResizeRatio = false;
|
|
5989
|
-
for (const plugin of this
|
|
6084
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5990
6085
|
plugin.particleReset?.(particle);
|
|
5991
6086
|
}
|
|
5992
|
-
for (const plugin of this
|
|
6087
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5993
6088
|
if (particle.destroyed) {
|
|
5994
6089
|
break;
|
|
5995
6090
|
}
|
|
@@ -6003,36 +6098,36 @@
|
|
|
6003
6098
|
}
|
|
6004
6099
|
return particlesToDelete;
|
|
6005
6100
|
};
|
|
6006
|
-
|
|
6007
|
-
for (const particle of this
|
|
6101
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6102
|
+
for (const particle of this.#array) {
|
|
6008
6103
|
if (particle.destroyed) {
|
|
6009
6104
|
particlesToDelete.add(particle);
|
|
6010
6105
|
continue;
|
|
6011
6106
|
}
|
|
6012
|
-
for (const updater of this.
|
|
6107
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6013
6108
|
updater.update(particle, delta);
|
|
6014
6109
|
}
|
|
6015
6110
|
if (!particle.spawning) {
|
|
6016
|
-
for (const plugin of this
|
|
6111
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6017
6112
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6018
6113
|
}
|
|
6019
6114
|
}
|
|
6020
|
-
this
|
|
6115
|
+
this.#updateParticleBucket(particle);
|
|
6021
6116
|
}
|
|
6022
6117
|
};
|
|
6023
6118
|
}
|
|
6024
6119
|
|
|
6025
6120
|
class Retina {
|
|
6026
|
-
container;
|
|
6027
6121
|
pixelRatio;
|
|
6028
6122
|
reduceFactor;
|
|
6123
|
+
#container;
|
|
6029
6124
|
constructor(container) {
|
|
6030
|
-
this
|
|
6125
|
+
this.#container = container;
|
|
6031
6126
|
this.pixelRatio = defaultRatio;
|
|
6032
6127
|
this.reduceFactor = defaultReduceFactor;
|
|
6033
6128
|
}
|
|
6034
6129
|
init() {
|
|
6035
|
-
const container = this
|
|
6130
|
+
const container = this.#container, options = container.actualOptions;
|
|
6036
6131
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6037
6132
|
this.reduceFactor = defaultReduceFactor;
|
|
6038
6133
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6046,7 +6141,6 @@
|
|
|
6046
6141
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6047
6142
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6048
6143
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6049
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6050
6144
|
const maxDistance = props.maxDistance;
|
|
6051
6145
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6052
6146
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6084,73 +6178,73 @@
|
|
|
6084
6178
|
shapeDrawers;
|
|
6085
6179
|
started;
|
|
6086
6180
|
zLayers;
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6181
|
+
#delay;
|
|
6182
|
+
#delayTimeout;
|
|
6183
|
+
#delta = { value: 0, factor: 0 };
|
|
6184
|
+
#dispatchCallback;
|
|
6185
|
+
#drawAnimationFrame;
|
|
6186
|
+
#duration;
|
|
6187
|
+
#eventListeners;
|
|
6188
|
+
#firstStart;
|
|
6189
|
+
#initialSourceOptions;
|
|
6190
|
+
#lastFrameTime;
|
|
6191
|
+
#lifeTime;
|
|
6192
|
+
#onDestroy;
|
|
6193
|
+
#options;
|
|
6194
|
+
#paused;
|
|
6195
|
+
#pluginManager;
|
|
6196
|
+
#smooth;
|
|
6197
|
+
#sourceOptions;
|
|
6104
6198
|
constructor(params) {
|
|
6105
6199
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6106
|
-
this
|
|
6107
|
-
this
|
|
6108
|
-
this
|
|
6200
|
+
this.#pluginManager = pluginManager;
|
|
6201
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6202
|
+
this.#onDestroy = onDestroy;
|
|
6109
6203
|
this.id = Symbol(id);
|
|
6110
6204
|
this.fpsLimit = 120;
|
|
6111
6205
|
this.hdr = false;
|
|
6112
|
-
this
|
|
6113
|
-
this
|
|
6114
|
-
this
|
|
6115
|
-
this
|
|
6116
|
-
this
|
|
6206
|
+
this.#smooth = false;
|
|
6207
|
+
this.#delay = 0;
|
|
6208
|
+
this.#duration = 0;
|
|
6209
|
+
this.#lifeTime = 0;
|
|
6210
|
+
this.#firstStart = true;
|
|
6117
6211
|
this.started = false;
|
|
6118
6212
|
this.destroyed = false;
|
|
6119
|
-
this
|
|
6120
|
-
this
|
|
6213
|
+
this.#paused = true;
|
|
6214
|
+
this.#lastFrameTime = 0;
|
|
6121
6215
|
this.zLayers = 100;
|
|
6122
6216
|
this.pageHidden = false;
|
|
6123
|
-
this
|
|
6124
|
-
this
|
|
6217
|
+
this.#sourceOptions = sourceOptions;
|
|
6218
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6125
6219
|
this.effectDrawers = new Map();
|
|
6126
6220
|
this.shapeDrawers = new Map();
|
|
6127
6221
|
this.particleUpdaters = [];
|
|
6128
6222
|
this.retina = new Retina(this);
|
|
6129
|
-
this.canvas = new CanvasManager(this
|
|
6130
|
-
this.particles = new ParticlesManager(this
|
|
6223
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6224
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6131
6225
|
this.plugins = [];
|
|
6132
6226
|
this.particleDestroyedPlugins = [];
|
|
6133
6227
|
this.particleCreatedPlugins = [];
|
|
6134
6228
|
this.particlePositionPlugins = [];
|
|
6135
|
-
this
|
|
6136
|
-
this.actualOptions = loadContainerOptions(this
|
|
6137
|
-
this
|
|
6229
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6230
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6231
|
+
this.#eventListeners = new EventListeners(this);
|
|
6138
6232
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6139
6233
|
}
|
|
6140
6234
|
get animationStatus() {
|
|
6141
|
-
return !this
|
|
6235
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6142
6236
|
}
|
|
6143
6237
|
get options() {
|
|
6144
|
-
return this
|
|
6238
|
+
return this.#options;
|
|
6145
6239
|
}
|
|
6146
6240
|
get sourceOptions() {
|
|
6147
|
-
return this
|
|
6241
|
+
return this.#sourceOptions;
|
|
6148
6242
|
}
|
|
6149
6243
|
addLifeTime(value) {
|
|
6150
|
-
this
|
|
6244
|
+
this.#lifeTime += value;
|
|
6151
6245
|
}
|
|
6152
6246
|
alive() {
|
|
6153
|
-
return !this
|
|
6247
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6154
6248
|
}
|
|
6155
6249
|
destroy(remove = true) {
|
|
6156
6250
|
if (!guardCheck(this)) {
|
|
@@ -6172,13 +6266,13 @@
|
|
|
6172
6266
|
this.shapeDrawers = new Map();
|
|
6173
6267
|
this.particleUpdaters = [];
|
|
6174
6268
|
this.plugins.length = 0;
|
|
6175
|
-
this.
|
|
6269
|
+
this.#pluginManager.clearPlugins(this);
|
|
6176
6270
|
this.destroyed = true;
|
|
6177
|
-
this
|
|
6271
|
+
this.#onDestroy(remove);
|
|
6178
6272
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6179
6273
|
}
|
|
6180
6274
|
dispatchEvent(type, data) {
|
|
6181
|
-
this
|
|
6275
|
+
this.#dispatchCallback(type, {
|
|
6182
6276
|
container: this,
|
|
6183
6277
|
data,
|
|
6184
6278
|
});
|
|
@@ -6188,12 +6282,12 @@
|
|
|
6188
6282
|
return;
|
|
6189
6283
|
}
|
|
6190
6284
|
let refreshTime = force;
|
|
6191
|
-
this
|
|
6285
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6192
6286
|
if (refreshTime) {
|
|
6193
|
-
this
|
|
6287
|
+
this.#lastFrameTime = undefined;
|
|
6194
6288
|
refreshTime = false;
|
|
6195
6289
|
}
|
|
6196
|
-
this
|
|
6290
|
+
this.#nextFrame(timestamp);
|
|
6197
6291
|
});
|
|
6198
6292
|
}
|
|
6199
6293
|
async export(type, options = {}) {
|
|
@@ -6215,7 +6309,7 @@
|
|
|
6215
6309
|
return;
|
|
6216
6310
|
}
|
|
6217
6311
|
const allContainerPlugins = new Map();
|
|
6218
|
-
for (const plugin of this.
|
|
6312
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6219
6313
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6220
6314
|
if (containerPlugin.preInit) {
|
|
6221
6315
|
await containerPlugin.preInit();
|
|
@@ -6223,8 +6317,8 @@
|
|
|
6223
6317
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6224
6318
|
}
|
|
6225
6319
|
await this.initDrawersAndUpdaters();
|
|
6226
|
-
this
|
|
6227
|
-
this.actualOptions = loadContainerOptions(this
|
|
6320
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6321
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6228
6322
|
this.plugins.length = 0;
|
|
6229
6323
|
this.particleDestroyedPlugins.length = 0;
|
|
6230
6324
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6251,11 +6345,11 @@
|
|
|
6251
6345
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6252
6346
|
this.hdr = hdr;
|
|
6253
6347
|
this.zLayers = zLayers;
|
|
6254
|
-
this
|
|
6255
|
-
this
|
|
6256
|
-
this
|
|
6348
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6349
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6350
|
+
this.#lifeTime = 0;
|
|
6257
6351
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6258
|
-
this
|
|
6352
|
+
this.#smooth = smooth;
|
|
6259
6353
|
for (const plugin of this.plugins) {
|
|
6260
6354
|
await plugin.init?.();
|
|
6261
6355
|
}
|
|
@@ -6268,7 +6362,7 @@
|
|
|
6268
6362
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6269
6363
|
}
|
|
6270
6364
|
async initDrawersAndUpdaters() {
|
|
6271
|
-
const pluginManager = this
|
|
6365
|
+
const pluginManager = this.#pluginManager;
|
|
6272
6366
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6273
6367
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6274
6368
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6277,18 +6371,18 @@
|
|
|
6277
6371
|
if (!guardCheck(this)) {
|
|
6278
6372
|
return;
|
|
6279
6373
|
}
|
|
6280
|
-
if (this
|
|
6281
|
-
cancelAnimation(this
|
|
6282
|
-
|
|
6374
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6375
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6376
|
+
this.#drawAnimationFrame = undefined;
|
|
6283
6377
|
}
|
|
6284
|
-
if (this
|
|
6378
|
+
if (this.#paused) {
|
|
6285
6379
|
return;
|
|
6286
6380
|
}
|
|
6287
6381
|
for (const plugin of this.plugins) {
|
|
6288
6382
|
plugin.pause?.();
|
|
6289
6383
|
}
|
|
6290
6384
|
if (!this.pageHidden) {
|
|
6291
|
-
this
|
|
6385
|
+
this.#paused = true;
|
|
6292
6386
|
}
|
|
6293
6387
|
this.dispatchEvent(EventType.containerPaused);
|
|
6294
6388
|
}
|
|
@@ -6296,13 +6390,13 @@
|
|
|
6296
6390
|
if (!guardCheck(this)) {
|
|
6297
6391
|
return;
|
|
6298
6392
|
}
|
|
6299
|
-
const needsUpdate = this
|
|
6300
|
-
if (this
|
|
6301
|
-
this
|
|
6393
|
+
const needsUpdate = this.#paused || force;
|
|
6394
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6395
|
+
this.#firstStart = false;
|
|
6302
6396
|
return;
|
|
6303
6397
|
}
|
|
6304
|
-
if (this
|
|
6305
|
-
this
|
|
6398
|
+
if (this.#paused) {
|
|
6399
|
+
this.#paused = false;
|
|
6306
6400
|
}
|
|
6307
6401
|
if (needsUpdate) {
|
|
6308
6402
|
for (const plugin of this.plugins) {
|
|
@@ -6325,10 +6419,10 @@
|
|
|
6325
6419
|
if (!guardCheck(this)) {
|
|
6326
6420
|
return;
|
|
6327
6421
|
}
|
|
6328
|
-
this
|
|
6329
|
-
this
|
|
6330
|
-
this
|
|
6331
|
-
this.actualOptions = loadContainerOptions(this
|
|
6422
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6423
|
+
this.#sourceOptions = sourceOptions;
|
|
6424
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6425
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6332
6426
|
return this.refresh();
|
|
6333
6427
|
}
|
|
6334
6428
|
async start() {
|
|
@@ -6339,7 +6433,7 @@
|
|
|
6339
6433
|
this.started = true;
|
|
6340
6434
|
await new Promise(resolve => {
|
|
6341
6435
|
const start = async () => {
|
|
6342
|
-
this.
|
|
6436
|
+
this.#eventListeners.addListeners();
|
|
6343
6437
|
for (const plugin of this.plugins) {
|
|
6344
6438
|
await plugin.start?.();
|
|
6345
6439
|
}
|
|
@@ -6347,20 +6441,20 @@
|
|
|
6347
6441
|
this.play();
|
|
6348
6442
|
resolve();
|
|
6349
6443
|
};
|
|
6350
|
-
this
|
|
6444
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6351
6445
|
});
|
|
6352
6446
|
}
|
|
6353
6447
|
stop() {
|
|
6354
6448
|
if (!guardCheck(this) || !this.started) {
|
|
6355
6449
|
return;
|
|
6356
6450
|
}
|
|
6357
|
-
if (this
|
|
6358
|
-
clearTimeout(this
|
|
6359
|
-
|
|
6451
|
+
if (this.#delayTimeout) {
|
|
6452
|
+
clearTimeout(this.#delayTimeout);
|
|
6453
|
+
this.#delayTimeout = undefined;
|
|
6360
6454
|
}
|
|
6361
|
-
this
|
|
6455
|
+
this.#firstStart = true;
|
|
6362
6456
|
this.started = false;
|
|
6363
|
-
this.
|
|
6457
|
+
this.#eventListeners.removeListeners();
|
|
6364
6458
|
this.pause();
|
|
6365
6459
|
this.particles.clear();
|
|
6366
6460
|
this.canvas.stop();
|
|
@@ -6370,7 +6464,7 @@
|
|
|
6370
6464
|
this.particleCreatedPlugins.length = 0;
|
|
6371
6465
|
this.particleDestroyedPlugins.length = 0;
|
|
6372
6466
|
this.particlePositionPlugins.length = 0;
|
|
6373
|
-
this
|
|
6467
|
+
this.#sourceOptions = this.#options;
|
|
6374
6468
|
this.dispatchEvent(EventType.containerStopped);
|
|
6375
6469
|
}
|
|
6376
6470
|
updateActualOptions() {
|
|
@@ -6382,23 +6476,23 @@
|
|
|
6382
6476
|
}
|
|
6383
6477
|
return refresh;
|
|
6384
6478
|
}
|
|
6385
|
-
|
|
6479
|
+
#nextFrame = (timestamp) => {
|
|
6386
6480
|
try {
|
|
6387
|
-
if (!this
|
|
6388
|
-
this
|
|
6389
|
-
timestamp < this
|
|
6481
|
+
if (!this.#smooth &&
|
|
6482
|
+
this.#lastFrameTime !== undefined &&
|
|
6483
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6390
6484
|
this.draw(false);
|
|
6391
6485
|
return;
|
|
6392
6486
|
}
|
|
6393
|
-
this
|
|
6394
|
-
updateDelta(this
|
|
6395
|
-
this.addLifeTime(this.
|
|
6396
|
-
this
|
|
6397
|
-
if (this.
|
|
6487
|
+
this.#lastFrameTime ??= timestamp;
|
|
6488
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6489
|
+
this.addLifeTime(this.#delta.value);
|
|
6490
|
+
this.#lastFrameTime = timestamp;
|
|
6491
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6398
6492
|
this.draw(false);
|
|
6399
6493
|
return;
|
|
6400
6494
|
}
|
|
6401
|
-
this.canvas.render.drawParticles(this
|
|
6495
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6402
6496
|
if (!this.alive()) {
|
|
6403
6497
|
this.destroy();
|
|
6404
6498
|
return;
|
|
@@ -6419,10 +6513,10 @@
|
|
|
6419
6513
|
});
|
|
6420
6514
|
|
|
6421
6515
|
class BlendPluginInstance {
|
|
6422
|
-
|
|
6423
|
-
|
|
6516
|
+
#container;
|
|
6517
|
+
#defaultCompositeValue;
|
|
6424
6518
|
constructor(container) {
|
|
6425
|
-
this
|
|
6519
|
+
this.#container = container;
|
|
6426
6520
|
}
|
|
6427
6521
|
drawParticleCleanup(context, particle) {
|
|
6428
6522
|
if (!particle.options.blend?.enable) {
|
|
@@ -6439,14 +6533,14 @@
|
|
|
6439
6533
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6440
6534
|
}
|
|
6441
6535
|
drawSettingsCleanup(context) {
|
|
6442
|
-
if (!this
|
|
6536
|
+
if (!this.#defaultCompositeValue) {
|
|
6443
6537
|
return;
|
|
6444
6538
|
}
|
|
6445
|
-
context.globalCompositeOperation = this
|
|
6539
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6446
6540
|
}
|
|
6447
6541
|
drawSettingsSetup(context) {
|
|
6448
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6449
|
-
this
|
|
6542
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6543
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6450
6544
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6451
6545
|
}
|
|
6452
6546
|
}
|
|
@@ -6589,11 +6683,11 @@
|
|
|
6589
6683
|
class MovePluginInstance {
|
|
6590
6684
|
availablePathGenerators;
|
|
6591
6685
|
pathGenerators;
|
|
6592
|
-
|
|
6593
|
-
|
|
6686
|
+
#container;
|
|
6687
|
+
#pluginManager;
|
|
6594
6688
|
constructor(pluginManager, container) {
|
|
6595
|
-
this
|
|
6596
|
-
this
|
|
6689
|
+
this.#pluginManager = pluginManager;
|
|
6690
|
+
this.#container = container;
|
|
6597
6691
|
this.availablePathGenerators = new Map();
|
|
6598
6692
|
this.pathGenerators = new Map();
|
|
6599
6693
|
}
|
|
@@ -6624,7 +6718,7 @@
|
|
|
6624
6718
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6625
6719
|
inverse: gravityOptions.inverse,
|
|
6626
6720
|
};
|
|
6627
|
-
initSpin(this
|
|
6721
|
+
initSpin(this.#container, particle);
|
|
6628
6722
|
}
|
|
6629
6723
|
particleDestroyed(particle) {
|
|
6630
6724
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6635,7 +6729,7 @@
|
|
|
6635
6729
|
if (!moveOptions.enable) {
|
|
6636
6730
|
return;
|
|
6637
6731
|
}
|
|
6638
|
-
const container = this
|
|
6732
|
+
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;
|
|
6639
6733
|
if (moveOptions.spin.enable) {
|
|
6640
6734
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6641
6735
|
}
|
|
@@ -6645,18 +6739,18 @@
|
|
|
6645
6739
|
applyDistance(particle);
|
|
6646
6740
|
}
|
|
6647
6741
|
preInit() {
|
|
6648
|
-
return this
|
|
6742
|
+
return this.#init();
|
|
6649
6743
|
}
|
|
6650
6744
|
redrawInit() {
|
|
6651
|
-
return this
|
|
6745
|
+
return this.#init();
|
|
6652
6746
|
}
|
|
6653
6747
|
update() {
|
|
6654
6748
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6655
6749
|
pathGenerator.update();
|
|
6656
6750
|
}
|
|
6657
6751
|
}
|
|
6658
|
-
async
|
|
6659
|
-
const availablePathGenerators = await this.
|
|
6752
|
+
async #init() {
|
|
6753
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6660
6754
|
if (!availablePathGenerators) {
|
|
6661
6755
|
return;
|
|
6662
6756
|
}
|
|
@@ -6675,65 +6769,65 @@
|
|
|
6675
6769
|
|
|
6676
6770
|
const touchDelay = 500;
|
|
6677
6771
|
class InteractivityEventListeners {
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6772
|
+
#canPush = true;
|
|
6773
|
+
#clickPositionPlugins;
|
|
6774
|
+
#container;
|
|
6775
|
+
#handlers;
|
|
6776
|
+
#interactionManager;
|
|
6777
|
+
#touches;
|
|
6684
6778
|
constructor(container, interactionManager) {
|
|
6685
|
-
this
|
|
6686
|
-
this
|
|
6687
|
-
this
|
|
6688
|
-
this
|
|
6689
|
-
this
|
|
6779
|
+
this.#container = container;
|
|
6780
|
+
this.#clickPositionPlugins = [];
|
|
6781
|
+
this.#interactionManager = interactionManager;
|
|
6782
|
+
this.#touches = new Map();
|
|
6783
|
+
this.#handlers = {
|
|
6690
6784
|
mouseDown: () => {
|
|
6691
|
-
this
|
|
6785
|
+
this.#mouseDown();
|
|
6692
6786
|
},
|
|
6693
6787
|
mouseLeave: () => {
|
|
6694
|
-
this
|
|
6788
|
+
this.#mouseTouchFinish();
|
|
6695
6789
|
},
|
|
6696
6790
|
mouseMove: (e) => {
|
|
6697
|
-
this
|
|
6791
|
+
this.#mouseTouchMove(e);
|
|
6698
6792
|
},
|
|
6699
6793
|
mouseUp: (e) => {
|
|
6700
|
-
this
|
|
6794
|
+
this.#mouseTouchClick(e);
|
|
6701
6795
|
},
|
|
6702
6796
|
touchStart: (e) => {
|
|
6703
|
-
this
|
|
6797
|
+
this.#touchStart(e);
|
|
6704
6798
|
},
|
|
6705
6799
|
touchMove: (e) => {
|
|
6706
|
-
this
|
|
6800
|
+
this.#mouseTouchMove(e);
|
|
6707
6801
|
},
|
|
6708
6802
|
touchEnd: (e) => {
|
|
6709
|
-
this
|
|
6803
|
+
this.#touchEnd(e);
|
|
6710
6804
|
},
|
|
6711
6805
|
touchCancel: (e) => {
|
|
6712
|
-
this
|
|
6806
|
+
this.#touchEnd(e);
|
|
6713
6807
|
},
|
|
6714
6808
|
touchEndClick: (e) => {
|
|
6715
|
-
this
|
|
6809
|
+
this.#touchEndClick(e);
|
|
6716
6810
|
},
|
|
6717
6811
|
visibilityChange: () => {
|
|
6718
|
-
this
|
|
6812
|
+
this.#handleVisibilityChange();
|
|
6719
6813
|
},
|
|
6720
6814
|
};
|
|
6721
6815
|
}
|
|
6722
6816
|
addListeners() {
|
|
6723
|
-
this
|
|
6817
|
+
this.#manageListeners(true);
|
|
6724
6818
|
}
|
|
6725
6819
|
init() {
|
|
6726
|
-
this.
|
|
6727
|
-
for (const plugin of this.
|
|
6728
|
-
this.
|
|
6820
|
+
this.#clickPositionPlugins.length = 0;
|
|
6821
|
+
for (const plugin of this.#container.plugins.filter(p => !!p.clickPositionValid)) {
|
|
6822
|
+
this.#clickPositionPlugins.push(plugin);
|
|
6729
6823
|
}
|
|
6730
6824
|
}
|
|
6731
6825
|
removeListeners() {
|
|
6732
|
-
this
|
|
6826
|
+
this.#manageListeners(false);
|
|
6733
6827
|
}
|
|
6734
|
-
|
|
6735
|
-
const container = this
|
|
6736
|
-
if (this
|
|
6828
|
+
#doMouseTouchClick = e => {
|
|
6829
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions;
|
|
6830
|
+
if (this.#canPush) {
|
|
6737
6831
|
const mouseInteractivity = interactionManager.interactivityData.mouse, mousePos = mouseInteractivity.position;
|
|
6738
6832
|
if (!mousePos) {
|
|
6739
6833
|
return;
|
|
@@ -6750,15 +6844,15 @@
|
|
|
6750
6844
|
}
|
|
6751
6845
|
if (e.type === "touchend") {
|
|
6752
6846
|
setTimeout(() => {
|
|
6753
|
-
this
|
|
6847
|
+
this.#mouseTouchFinish();
|
|
6754
6848
|
}, touchDelay);
|
|
6755
6849
|
}
|
|
6756
6850
|
};
|
|
6757
|
-
|
|
6758
|
-
this
|
|
6851
|
+
#handleVisibilityChange = () => {
|
|
6852
|
+
this.#mouseTouchFinish();
|
|
6759
6853
|
};
|
|
6760
|
-
|
|
6761
|
-
const handlers = this
|
|
6854
|
+
#manageInteractivityListeners = add => {
|
|
6855
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivityEl = interactionManager.interactivityData.element;
|
|
6762
6856
|
if (!interactivityEl) {
|
|
6763
6857
|
return;
|
|
6764
6858
|
}
|
|
@@ -6789,8 +6883,8 @@
|
|
|
6789
6883
|
manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
|
|
6790
6884
|
manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
|
6791
6885
|
};
|
|
6792
|
-
|
|
6793
|
-
const handlers = this
|
|
6886
|
+
#manageListeners = add => {
|
|
6887
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, detectType = options.interactivity?.detectsOn, canvasEl = container.canvas.domElement;
|
|
6794
6888
|
if (detectType === InteractivityDetect.window) {
|
|
6795
6889
|
interactionManager.interactivityData.element = safeDocument();
|
|
6796
6890
|
}
|
|
@@ -6800,35 +6894,35 @@
|
|
|
6800
6894
|
else {
|
|
6801
6895
|
interactionManager.interactivityData.element = canvasEl;
|
|
6802
6896
|
}
|
|
6803
|
-
this
|
|
6897
|
+
this.#manageInteractivityListeners(add);
|
|
6804
6898
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
6805
6899
|
};
|
|
6806
|
-
|
|
6807
|
-
const { interactivityData } = this
|
|
6900
|
+
#mouseDown = () => {
|
|
6901
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
6808
6902
|
mouse.clicking = true;
|
|
6809
6903
|
mouse.downPosition = mouse.position;
|
|
6810
6904
|
};
|
|
6811
|
-
|
|
6812
|
-
const container = this
|
|
6905
|
+
#mouseTouchClick = e => {
|
|
6906
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
|
|
6813
6907
|
mouse.inside = true;
|
|
6814
6908
|
let handled = false;
|
|
6815
6909
|
const mousePosition = mouse.position;
|
|
6816
6910
|
if (!mousePosition || !options.interactivity?.events.onClick.enable) {
|
|
6817
6911
|
return;
|
|
6818
6912
|
}
|
|
6819
|
-
for (const plugin of this
|
|
6913
|
+
for (const plugin of this.#clickPositionPlugins) {
|
|
6820
6914
|
handled = plugin.clickPositionValid?.(mousePosition) ?? false;
|
|
6821
6915
|
if (handled) {
|
|
6822
6916
|
break;
|
|
6823
6917
|
}
|
|
6824
6918
|
}
|
|
6825
6919
|
if (!handled) {
|
|
6826
|
-
this
|
|
6920
|
+
this.#doMouseTouchClick(e);
|
|
6827
6921
|
}
|
|
6828
6922
|
mouse.clicking = false;
|
|
6829
6923
|
};
|
|
6830
|
-
|
|
6831
|
-
const { interactivityData } = this
|
|
6924
|
+
#mouseTouchFinish = () => {
|
|
6925
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
6832
6926
|
delete mouse.position;
|
|
6833
6927
|
delete mouse.clickPosition;
|
|
6834
6928
|
delete mouse.downPosition;
|
|
@@ -6836,15 +6930,15 @@
|
|
|
6836
6930
|
mouse.inside = false;
|
|
6837
6931
|
mouse.clicking = false;
|
|
6838
6932
|
};
|
|
6839
|
-
|
|
6840
|
-
const container = this
|
|
6933
|
+
#mouseTouchMove = e => {
|
|
6934
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivity = interactionManager.interactivityData, canvasEl = container.canvas.domElement;
|
|
6841
6935
|
if (!interactivity.element) {
|
|
6842
6936
|
return;
|
|
6843
6937
|
}
|
|
6844
6938
|
interactivity.mouse.inside = true;
|
|
6845
6939
|
let pos;
|
|
6846
6940
|
if (e.type.startsWith("pointer")) {
|
|
6847
|
-
this
|
|
6941
|
+
this.#canPush = true;
|
|
6848
6942
|
const mouseEvent = e;
|
|
6849
6943
|
if (interactivity.element === safeDocument()) {
|
|
6850
6944
|
if (canvasEl) {
|
|
@@ -6879,7 +6973,7 @@
|
|
|
6879
6973
|
}
|
|
6880
6974
|
}
|
|
6881
6975
|
else {
|
|
6882
|
-
this
|
|
6976
|
+
this.#canPush = e.type !== "touchmove";
|
|
6883
6977
|
if (canvasEl) {
|
|
6884
6978
|
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
|
|
6885
6979
|
if (!lastTouch) {
|
|
@@ -6899,60 +6993,60 @@
|
|
|
6899
6993
|
interactivity.mouse.position = pos;
|
|
6900
6994
|
interactivity.status = mouseMoveEvent;
|
|
6901
6995
|
};
|
|
6902
|
-
|
|
6996
|
+
#touchEnd = e => {
|
|
6903
6997
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6904
6998
|
for (const touch of touches) {
|
|
6905
|
-
this.
|
|
6999
|
+
this.#touches.delete(touch.identifier);
|
|
6906
7000
|
}
|
|
6907
|
-
this
|
|
7001
|
+
this.#mouseTouchFinish();
|
|
6908
7002
|
};
|
|
6909
|
-
|
|
7003
|
+
#touchEndClick = e => {
|
|
6910
7004
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6911
7005
|
for (const touch of touches) {
|
|
6912
|
-
this.
|
|
7006
|
+
this.#touches.delete(touch.identifier);
|
|
6913
7007
|
}
|
|
6914
|
-
this
|
|
7008
|
+
this.#mouseTouchClick(e);
|
|
6915
7009
|
};
|
|
6916
|
-
|
|
7010
|
+
#touchStart = e => {
|
|
6917
7011
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6918
7012
|
for (const touch of touches) {
|
|
6919
|
-
this.
|
|
7013
|
+
this.#touches.set(touch.identifier, performance.now());
|
|
6920
7014
|
}
|
|
6921
|
-
this
|
|
7015
|
+
this.#mouseTouchMove(e);
|
|
6922
7016
|
};
|
|
6923
7017
|
}
|
|
6924
7018
|
|
|
6925
7019
|
const clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0;
|
|
6926
7020
|
class InteractionManager {
|
|
6927
|
-
container;
|
|
6928
7021
|
interactivityData;
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
7022
|
+
#clickHandlers;
|
|
7023
|
+
#container;
|
|
7024
|
+
#eventListeners;
|
|
7025
|
+
#externalInteractors;
|
|
7026
|
+
#interactors;
|
|
7027
|
+
#intersectionObserver;
|
|
7028
|
+
#particleInteractors;
|
|
7029
|
+
#pluginManager;
|
|
6936
7030
|
constructor(pluginManager, container) {
|
|
6937
|
-
this
|
|
6938
|
-
this
|
|
6939
|
-
this
|
|
6940
|
-
this
|
|
6941
|
-
this
|
|
6942
|
-
this
|
|
6943
|
-
this
|
|
7031
|
+
this.#container = container;
|
|
7032
|
+
this.#pluginManager = pluginManager;
|
|
7033
|
+
this.#interactors = [];
|
|
7034
|
+
this.#externalInteractors = [];
|
|
7035
|
+
this.#particleInteractors = [];
|
|
7036
|
+
this.#clickHandlers = new Map();
|
|
7037
|
+
this.#eventListeners = new InteractivityEventListeners(container, this);
|
|
6944
7038
|
this.interactivityData = {
|
|
6945
7039
|
mouse: {
|
|
6946
7040
|
clicking: false,
|
|
6947
7041
|
inside: false,
|
|
6948
7042
|
},
|
|
6949
7043
|
};
|
|
6950
|
-
this
|
|
6951
|
-
this
|
|
7044
|
+
this.#intersectionObserver = safeIntersectionObserver(entries => {
|
|
7045
|
+
this.#intersectionManager(entries);
|
|
6952
7046
|
});
|
|
6953
7047
|
}
|
|
6954
7048
|
addClickHandler(callback) {
|
|
6955
|
-
const
|
|
7049
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
6956
7050
|
if (container.destroyed) {
|
|
6957
7051
|
return;
|
|
6958
7052
|
}
|
|
@@ -7014,119 +7108,119 @@
|
|
|
7014
7108
|
touchMoved = false;
|
|
7015
7109
|
};
|
|
7016
7110
|
let touched = false, touchMoved = false;
|
|
7017
|
-
this.
|
|
7018
|
-
this.
|
|
7019
|
-
this.
|
|
7020
|
-
this.
|
|
7021
|
-
this.
|
|
7022
|
-
for (const [key, handler] of this
|
|
7111
|
+
this.#clickHandlers.set(clickEvent, clickHandler);
|
|
7112
|
+
this.#clickHandlers.set(touchStartEvent, touchStartHandler);
|
|
7113
|
+
this.#clickHandlers.set(touchMoveEvent, touchMoveHandler);
|
|
7114
|
+
this.#clickHandlers.set(touchEndEvent, touchEndHandler);
|
|
7115
|
+
this.#clickHandlers.set(touchCancelEvent, touchCancelHandler);
|
|
7116
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7023
7117
|
el.addEventListener(key, handler);
|
|
7024
7118
|
}
|
|
7025
7119
|
}
|
|
7026
7120
|
addListeners() {
|
|
7027
|
-
this.
|
|
7121
|
+
this.#eventListeners.addListeners();
|
|
7028
7122
|
}
|
|
7029
7123
|
clearClickHandlers() {
|
|
7030
|
-
const
|
|
7124
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
7031
7125
|
if (container.destroyed) {
|
|
7032
7126
|
return;
|
|
7033
7127
|
}
|
|
7034
|
-
for (const [key, handler] of this
|
|
7128
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7035
7129
|
interactivityData.element?.removeEventListener(key, handler);
|
|
7036
7130
|
}
|
|
7037
|
-
this.
|
|
7131
|
+
this.#clickHandlers.clear();
|
|
7038
7132
|
}
|
|
7039
7133
|
externalInteract(delta) {
|
|
7040
|
-
for (const interactor of this
|
|
7041
|
-
const
|
|
7134
|
+
for (const interactor of this.#externalInteractors) {
|
|
7135
|
+
const interactivityData = this.interactivityData;
|
|
7042
7136
|
if (interactor.isEnabled(interactivityData)) {
|
|
7043
7137
|
interactor.interact(interactivityData, delta);
|
|
7044
7138
|
}
|
|
7045
7139
|
}
|
|
7046
7140
|
}
|
|
7047
7141
|
handleClickMode(mode) {
|
|
7048
|
-
if (this
|
|
7142
|
+
if (this.#container.destroyed) {
|
|
7049
7143
|
return;
|
|
7050
7144
|
}
|
|
7051
|
-
const
|
|
7052
|
-
for (const interactor of this
|
|
7145
|
+
const interactivityData = this.interactivityData;
|
|
7146
|
+
for (const interactor of this.#externalInteractors) {
|
|
7053
7147
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
7054
7148
|
}
|
|
7055
7149
|
}
|
|
7056
7150
|
init() {
|
|
7057
|
-
this.
|
|
7058
|
-
for (const interactor of this
|
|
7151
|
+
this.#eventListeners.init();
|
|
7152
|
+
for (const interactor of this.#interactors) {
|
|
7059
7153
|
switch (interactor.type) {
|
|
7060
7154
|
case InteractorType.external:
|
|
7061
|
-
this.
|
|
7155
|
+
this.#externalInteractors.push(interactor);
|
|
7062
7156
|
break;
|
|
7063
7157
|
case InteractorType.particles:
|
|
7064
|
-
this.
|
|
7158
|
+
this.#particleInteractors.push(interactor);
|
|
7065
7159
|
break;
|
|
7066
7160
|
}
|
|
7067
7161
|
interactor.init();
|
|
7068
7162
|
}
|
|
7069
7163
|
}
|
|
7070
7164
|
async initInteractors() {
|
|
7071
|
-
const interactors = await this.
|
|
7165
|
+
const interactors = await this.#pluginManager.getInteractors?.(this.#container, true);
|
|
7072
7166
|
if (!interactors) {
|
|
7073
7167
|
return;
|
|
7074
7168
|
}
|
|
7075
|
-
this
|
|
7076
|
-
this
|
|
7077
|
-
this
|
|
7169
|
+
this.#interactors = interactors;
|
|
7170
|
+
this.#externalInteractors = [];
|
|
7171
|
+
this.#particleInteractors = [];
|
|
7078
7172
|
}
|
|
7079
7173
|
particlesInteract(particle, delta) {
|
|
7080
|
-
const
|
|
7081
|
-
for (const interactor of this
|
|
7174
|
+
const interactivityData = this.interactivityData;
|
|
7175
|
+
for (const interactor of this.#externalInteractors) {
|
|
7082
7176
|
interactor.clear(particle, delta);
|
|
7083
7177
|
}
|
|
7084
|
-
for (const interactor of this
|
|
7178
|
+
for (const interactor of this.#particleInteractors) {
|
|
7085
7179
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7086
7180
|
interactor.interact(particle, interactivityData, delta);
|
|
7087
7181
|
}
|
|
7088
7182
|
}
|
|
7089
7183
|
}
|
|
7090
7184
|
removeListeners() {
|
|
7091
|
-
this.
|
|
7185
|
+
this.#eventListeners.removeListeners();
|
|
7092
7186
|
}
|
|
7093
7187
|
reset(particle) {
|
|
7094
|
-
const
|
|
7095
|
-
for (const interactor of this
|
|
7188
|
+
const interactivityData = this.interactivityData;
|
|
7189
|
+
for (const interactor of this.#externalInteractors) {
|
|
7096
7190
|
if (interactor.isEnabled(interactivityData)) {
|
|
7097
7191
|
interactor.reset(interactivityData, particle);
|
|
7098
7192
|
}
|
|
7099
7193
|
}
|
|
7100
|
-
for (const interactor of this
|
|
7194
|
+
for (const interactor of this.#particleInteractors) {
|
|
7101
7195
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7102
7196
|
interactor.reset(interactivityData, particle);
|
|
7103
7197
|
}
|
|
7104
7198
|
}
|
|
7105
7199
|
}
|
|
7106
7200
|
startObserving() {
|
|
7107
|
-
const
|
|
7108
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7109
|
-
this.
|
|
7201
|
+
const interactivityData = this.interactivityData;
|
|
7202
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7203
|
+
this.#intersectionObserver.observe(interactivityData.element);
|
|
7110
7204
|
}
|
|
7111
7205
|
}
|
|
7112
7206
|
stopObserving() {
|
|
7113
|
-
const
|
|
7114
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7115
|
-
this.
|
|
7207
|
+
const interactivityData = this.interactivityData;
|
|
7208
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7209
|
+
this.#intersectionObserver.unobserve(interactivityData.element);
|
|
7116
7210
|
}
|
|
7117
7211
|
}
|
|
7118
7212
|
updateMaxDistance() {
|
|
7119
7213
|
let maxTotalDistance = 0;
|
|
7120
|
-
for (const interactor of this
|
|
7214
|
+
for (const interactor of this.#interactors) {
|
|
7121
7215
|
if (interactor.maxDistance > maxTotalDistance) {
|
|
7122
7216
|
maxTotalDistance = interactor.maxDistance;
|
|
7123
7217
|
}
|
|
7124
7218
|
}
|
|
7125
|
-
const container = this
|
|
7219
|
+
const container = this.#container;
|
|
7126
7220
|
container.particles.grid.setCellSize(maxTotalDistance * container.retina.pixelRatio);
|
|
7127
7221
|
}
|
|
7128
|
-
|
|
7129
|
-
const
|
|
7222
|
+
#intersectionManager = entries => {
|
|
7223
|
+
const container = this.#container;
|
|
7130
7224
|
if (container.destroyed || !container.actualOptions.pauseOnOutsideViewport) {
|
|
7131
7225
|
return;
|
|
7132
7226
|
}
|
|
@@ -7146,13 +7240,13 @@
|
|
|
7146
7240
|
|
|
7147
7241
|
class InteractivityPluginInstance {
|
|
7148
7242
|
interactionManager;
|
|
7149
|
-
|
|
7150
|
-
|
|
7243
|
+
#container;
|
|
7244
|
+
#pluginManager;
|
|
7151
7245
|
constructor(pluginManager, container) {
|
|
7152
|
-
this
|
|
7153
|
-
this
|
|
7246
|
+
this.#container = container;
|
|
7247
|
+
this.#pluginManager = pluginManager;
|
|
7154
7248
|
this.interactionManager = new InteractionManager(pluginManager, container);
|
|
7155
|
-
this.
|
|
7249
|
+
this.#container.addClickHandler = (callback) => {
|
|
7156
7250
|
this.interactionManager.addClickHandler(callback);
|
|
7157
7251
|
};
|
|
7158
7252
|
}
|
|
@@ -7164,11 +7258,11 @@
|
|
|
7164
7258
|
}
|
|
7165
7259
|
destroy() {
|
|
7166
7260
|
this.clearClickHandlers();
|
|
7167
|
-
this.
|
|
7261
|
+
this.#pluginManager.interactors?.delete(this.#container);
|
|
7168
7262
|
}
|
|
7169
7263
|
particleCreated(particle) {
|
|
7170
|
-
const interactivityParticle = particle, interactivity = new Interactivity(this
|
|
7171
|
-
interactivity.load(this.
|
|
7264
|
+
const interactivityParticle = particle, interactivity = new Interactivity(this.#pluginManager, this.#container);
|
|
7265
|
+
interactivity.load(this.#container.actualOptions.interactivity);
|
|
7172
7266
|
interactivity.load(interactivityParticle.options.interactivity);
|
|
7173
7267
|
interactivityParticle.interactivity = interactivity;
|
|
7174
7268
|
}
|