@tsparticles/preset-links 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
|
}
|
|
@@ -714,38 +714,38 @@
|
|
|
714
714
|
}
|
|
715
715
|
|
|
716
716
|
class EventDispatcher {
|
|
717
|
-
|
|
717
|
+
#listeners;
|
|
718
718
|
constructor() {
|
|
719
|
-
this
|
|
719
|
+
this.#listeners = new Map();
|
|
720
720
|
}
|
|
721
721
|
addEventListener(type, listener) {
|
|
722
722
|
this.removeEventListener(type, listener);
|
|
723
|
-
let arr = this.
|
|
723
|
+
let arr = this.#listeners.get(type);
|
|
724
724
|
if (!arr) {
|
|
725
725
|
arr = [];
|
|
726
|
-
this.
|
|
726
|
+
this.#listeners.set(type, arr);
|
|
727
727
|
}
|
|
728
728
|
arr.push(listener);
|
|
729
729
|
}
|
|
730
730
|
dispatchEvent(type, args) {
|
|
731
|
-
const listeners = this.
|
|
731
|
+
const listeners = this.#listeners.get(type);
|
|
732
732
|
listeners?.forEach(handler => {
|
|
733
733
|
handler(args);
|
|
734
734
|
});
|
|
735
735
|
}
|
|
736
736
|
hasEventListener(type) {
|
|
737
|
-
return !!this.
|
|
737
|
+
return !!this.#listeners.get(type);
|
|
738
738
|
}
|
|
739
739
|
removeAllEventListeners(type) {
|
|
740
740
|
if (!type) {
|
|
741
|
-
this
|
|
741
|
+
this.#listeners = new Map();
|
|
742
742
|
}
|
|
743
743
|
else {
|
|
744
|
-
this.
|
|
744
|
+
this.#listeners.delete(type);
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
747
|
removeEventListener(type, listener) {
|
|
748
|
-
const arr = this.
|
|
748
|
+
const arr = this.#listeners.get(type);
|
|
749
749
|
if (!arr) {
|
|
750
750
|
return;
|
|
751
751
|
}
|
|
@@ -754,7 +754,7 @@
|
|
|
754
754
|
return;
|
|
755
755
|
}
|
|
756
756
|
if (length === deleteCount) {
|
|
757
|
-
this.
|
|
757
|
+
this.#listeners.delete(type);
|
|
758
758
|
}
|
|
759
759
|
else {
|
|
760
760
|
arr.splice(idx, deleteCount);
|
|
@@ -792,19 +792,19 @@
|
|
|
792
792
|
presets = new Map();
|
|
793
793
|
shapeDrawers = new Map();
|
|
794
794
|
updaters = new Map();
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
795
|
+
#allLoadersSet = new Set();
|
|
796
|
+
#configs = new Map();
|
|
797
|
+
#engine;
|
|
798
|
+
#executedSet = new Set();
|
|
799
|
+
#initialized = false;
|
|
800
|
+
#isRunningLoaders = false;
|
|
801
|
+
#loadPromises = new Set();
|
|
802
802
|
constructor(engine) {
|
|
803
|
-
this
|
|
803
|
+
this.#engine = engine;
|
|
804
804
|
}
|
|
805
805
|
get configs() {
|
|
806
806
|
const res = {};
|
|
807
|
-
for (const [name, config] of this
|
|
807
|
+
for (const [name, config] of this.#configs) {
|
|
808
808
|
res[name] = config;
|
|
809
809
|
}
|
|
810
810
|
return res;
|
|
@@ -814,8 +814,8 @@
|
|
|
814
814
|
}
|
|
815
815
|
addConfig(config) {
|
|
816
816
|
const key = config.key ?? config.name ?? "default";
|
|
817
|
-
this.
|
|
818
|
-
this.
|
|
817
|
+
this.#configs.set(key, config);
|
|
818
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
819
819
|
}
|
|
820
820
|
addEasing(name, easing) {
|
|
821
821
|
if (this.easingFunctions.get(name)) {
|
|
@@ -876,21 +876,21 @@
|
|
|
876
876
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
877
877
|
}
|
|
878
878
|
async init() {
|
|
879
|
-
if (this
|
|
879
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
880
880
|
return;
|
|
881
881
|
}
|
|
882
|
-
this
|
|
883
|
-
this
|
|
884
|
-
this
|
|
882
|
+
this.#isRunningLoaders = true;
|
|
883
|
+
this.#executedSet = new Set();
|
|
884
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
885
885
|
try {
|
|
886
|
-
for (const loader of this
|
|
887
|
-
await this
|
|
886
|
+
for (const loader of this.#allLoadersSet) {
|
|
887
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
888
888
|
}
|
|
889
889
|
}
|
|
890
890
|
finally {
|
|
891
|
-
this.
|
|
892
|
-
this
|
|
893
|
-
this
|
|
891
|
+
this.#loadPromises.clear();
|
|
892
|
+
this.#isRunningLoaders = false;
|
|
893
|
+
this.#initialized = true;
|
|
894
894
|
}
|
|
895
895
|
}
|
|
896
896
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -901,24 +901,24 @@
|
|
|
901
901
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
902
902
|
}
|
|
903
903
|
async register(...loaders) {
|
|
904
|
-
if (this
|
|
904
|
+
if (this.#initialized) {
|
|
905
905
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
906
906
|
}
|
|
907
907
|
for (const loader of loaders) {
|
|
908
|
-
if (this
|
|
909
|
-
await this
|
|
908
|
+
if (this.#isRunningLoaders) {
|
|
909
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
910
910
|
}
|
|
911
911
|
else {
|
|
912
|
-
this.
|
|
912
|
+
this.#loadPromises.add(loader);
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
915
|
}
|
|
916
|
-
async
|
|
916
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
917
917
|
if (executed.has(loader))
|
|
918
918
|
return;
|
|
919
919
|
executed.add(loader);
|
|
920
920
|
allLoaders.add(loader);
|
|
921
|
-
await loader(this
|
|
921
|
+
await loader(this.#engine);
|
|
922
922
|
}
|
|
923
923
|
}
|
|
924
924
|
|
|
@@ -998,17 +998,17 @@
|
|
|
998
998
|
};
|
|
999
999
|
class Engine {
|
|
1000
1000
|
pluginManager = new PluginManager(this);
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1001
|
+
#domArray = [];
|
|
1002
|
+
#eventDispatcher = new EventDispatcher();
|
|
1003
|
+
#initialized = false;
|
|
1004
1004
|
get items() {
|
|
1005
|
-
return this
|
|
1005
|
+
return this.#domArray;
|
|
1006
1006
|
}
|
|
1007
1007
|
get version() {
|
|
1008
|
-
return "4.
|
|
1008
|
+
return "4.1.1";
|
|
1009
1009
|
}
|
|
1010
1010
|
addEventListener(type, listener) {
|
|
1011
|
-
this.
|
|
1011
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1012
1012
|
}
|
|
1013
1013
|
checkVersion(pluginVersion) {
|
|
1014
1014
|
if (this.version === pluginVersion) {
|
|
@@ -1017,17 +1017,17 @@
|
|
|
1017
1017
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1018
1018
|
}
|
|
1019
1019
|
dispatchEvent(type, args) {
|
|
1020
|
-
this.
|
|
1020
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1021
1021
|
}
|
|
1022
1022
|
async init() {
|
|
1023
|
-
if (this
|
|
1023
|
+
if (this.#initialized) {
|
|
1024
1024
|
return;
|
|
1025
1025
|
}
|
|
1026
1026
|
await this.pluginManager.init();
|
|
1027
|
-
this
|
|
1027
|
+
this.#initialized = true;
|
|
1028
1028
|
}
|
|
1029
1029
|
item(index) {
|
|
1030
|
-
const
|
|
1030
|
+
const items = this.items, item = items[index];
|
|
1031
1031
|
if (item?.destroyed) {
|
|
1032
1032
|
items.splice(index, removeDeleteCount);
|
|
1033
1033
|
return;
|
|
@@ -1081,7 +1081,7 @@
|
|
|
1081
1081
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1082
1082
|
}
|
|
1083
1083
|
removeEventListener(type, listener) {
|
|
1084
|
-
this.
|
|
1084
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1085
1085
|
}
|
|
1086
1086
|
}
|
|
1087
1087
|
|
|
@@ -1852,43 +1852,6 @@
|
|
|
1852
1852
|
}
|
|
1853
1853
|
}
|
|
1854
1854
|
|
|
1855
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1856
|
-
destroy;
|
|
1857
|
-
constructor() {
|
|
1858
|
-
super();
|
|
1859
|
-
this.destroy = DestroyType.none;
|
|
1860
|
-
this.speed = 2;
|
|
1861
|
-
}
|
|
1862
|
-
load(data) {
|
|
1863
|
-
super.load(data);
|
|
1864
|
-
if (isNull(data)) {
|
|
1865
|
-
return;
|
|
1866
|
-
}
|
|
1867
|
-
if (data.destroy !== undefined) {
|
|
1868
|
-
this.destroy = data.destroy;
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1874
|
-
animation;
|
|
1875
|
-
constructor() {
|
|
1876
|
-
super();
|
|
1877
|
-
this.animation = new OpacityAnimation();
|
|
1878
|
-
this.value = 1;
|
|
1879
|
-
}
|
|
1880
|
-
load(data) {
|
|
1881
|
-
if (isNull(data)) {
|
|
1882
|
-
return;
|
|
1883
|
-
}
|
|
1884
|
-
super.load(data);
|
|
1885
|
-
const animation = data.animation;
|
|
1886
|
-
if (animation !== undefined) {
|
|
1887
|
-
this.animation.load(animation);
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
1855
|
class Stroke {
|
|
1893
1856
|
color;
|
|
1894
1857
|
opacity;
|
|
@@ -2056,43 +2019,6 @@
|
|
|
2056
2019
|
}
|
|
2057
2020
|
}
|
|
2058
2021
|
|
|
2059
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2060
|
-
destroy;
|
|
2061
|
-
constructor() {
|
|
2062
|
-
super();
|
|
2063
|
-
this.destroy = DestroyType.none;
|
|
2064
|
-
this.speed = 5;
|
|
2065
|
-
}
|
|
2066
|
-
load(data) {
|
|
2067
|
-
super.load(data);
|
|
2068
|
-
if (isNull(data)) {
|
|
2069
|
-
return;
|
|
2070
|
-
}
|
|
2071
|
-
if (data.destroy !== undefined) {
|
|
2072
|
-
this.destroy = data.destroy;
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2078
|
-
animation;
|
|
2079
|
-
constructor() {
|
|
2080
|
-
super();
|
|
2081
|
-
this.animation = new SizeAnimation();
|
|
2082
|
-
this.value = 3;
|
|
2083
|
-
}
|
|
2084
|
-
load(data) {
|
|
2085
|
-
super.load(data);
|
|
2086
|
-
if (isNull(data)) {
|
|
2087
|
-
return;
|
|
2088
|
-
}
|
|
2089
|
-
const animation = data.animation;
|
|
2090
|
-
if (animation !== undefined) {
|
|
2091
|
-
this.animation.load(animation);
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
2022
|
class ZIndex extends ValueWithRandom {
|
|
2097
2023
|
opacityRate;
|
|
2098
2024
|
sizeRate;
|
|
@@ -2126,24 +2052,21 @@
|
|
|
2126
2052
|
groups;
|
|
2127
2053
|
move;
|
|
2128
2054
|
number;
|
|
2129
|
-
opacity;
|
|
2130
2055
|
paint;
|
|
2131
2056
|
palette;
|
|
2132
2057
|
reduceDuplicates;
|
|
2133
2058
|
shape;
|
|
2134
|
-
size;
|
|
2135
2059
|
zIndex;
|
|
2136
|
-
|
|
2137
|
-
|
|
2060
|
+
#container;
|
|
2061
|
+
#pluginManager;
|
|
2138
2062
|
constructor(pluginManager, container) {
|
|
2139
|
-
this
|
|
2140
|
-
this
|
|
2063
|
+
this.#pluginManager = pluginManager;
|
|
2064
|
+
this.#container = container;
|
|
2141
2065
|
this.bounce = new ParticlesBounce();
|
|
2142
2066
|
this.effect = new Effect();
|
|
2143
2067
|
this.groups = {};
|
|
2144
2068
|
this.move = new Move();
|
|
2145
2069
|
this.number = new ParticlesNumber();
|
|
2146
|
-
this.opacity = new Opacity();
|
|
2147
2070
|
this.paint = new Paint();
|
|
2148
2071
|
this.paint.color = new AnimatableColor();
|
|
2149
2072
|
this.paint.color.value = "#fff";
|
|
@@ -2151,7 +2074,6 @@
|
|
|
2151
2074
|
this.paint.fill.enable = true;
|
|
2152
2075
|
this.reduceDuplicates = false;
|
|
2153
2076
|
this.shape = new Shape();
|
|
2154
|
-
this.size = new Size();
|
|
2155
2077
|
this.zIndex = new ZIndex();
|
|
2156
2078
|
}
|
|
2157
2079
|
load(data) {
|
|
@@ -2160,7 +2082,7 @@
|
|
|
2160
2082
|
}
|
|
2161
2083
|
if (data.palette) {
|
|
2162
2084
|
this.palette = data.palette;
|
|
2163
|
-
this
|
|
2085
|
+
this.#importPalette(this.palette);
|
|
2164
2086
|
}
|
|
2165
2087
|
if (data.groups !== undefined) {
|
|
2166
2088
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2180,7 +2102,6 @@
|
|
|
2180
2102
|
this.effect.load(data.effect);
|
|
2181
2103
|
this.move.load(data.move);
|
|
2182
2104
|
this.number.load(data.number);
|
|
2183
|
-
this.opacity.load(data.opacity);
|
|
2184
2105
|
const paintToLoad = data.paint;
|
|
2185
2106
|
if (paintToLoad) {
|
|
2186
2107
|
if (isArray(paintToLoad)) {
|
|
@@ -2199,15 +2120,14 @@
|
|
|
2199
2120
|
}
|
|
2200
2121
|
}
|
|
2201
2122
|
this.shape.load(data.shape);
|
|
2202
|
-
this.size.load(data.size);
|
|
2203
2123
|
this.zIndex.load(data.zIndex);
|
|
2204
|
-
if (this
|
|
2205
|
-
for (const plugin of this.
|
|
2124
|
+
if (this.#container) {
|
|
2125
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2206
2126
|
if (plugin.loadParticlesOptions) {
|
|
2207
|
-
plugin.loadParticlesOptions(this
|
|
2127
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2208
2128
|
}
|
|
2209
2129
|
}
|
|
2210
|
-
const updaters = this.
|
|
2130
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2211
2131
|
if (updaters) {
|
|
2212
2132
|
for (const updater of updaters) {
|
|
2213
2133
|
if (updater.loadOptions) {
|
|
@@ -2217,8 +2137,8 @@
|
|
|
2217
2137
|
}
|
|
2218
2138
|
}
|
|
2219
2139
|
}
|
|
2220
|
-
|
|
2221
|
-
const paletteData = this.
|
|
2140
|
+
#importPalette = (palette) => {
|
|
2141
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2222
2142
|
if (!paletteData) {
|
|
2223
2143
|
return;
|
|
2224
2144
|
}
|
|
@@ -2297,11 +2217,11 @@
|
|
|
2297
2217
|
smooth;
|
|
2298
2218
|
style;
|
|
2299
2219
|
zLayers;
|
|
2300
|
-
|
|
2301
|
-
|
|
2220
|
+
#container;
|
|
2221
|
+
#pluginManager;
|
|
2302
2222
|
constructor(pluginManager, container) {
|
|
2303
|
-
this
|
|
2304
|
-
this
|
|
2223
|
+
this.#pluginManager = pluginManager;
|
|
2224
|
+
this.#container = container;
|
|
2305
2225
|
this.autoPlay = true;
|
|
2306
2226
|
this.background = new Background();
|
|
2307
2227
|
this.clear = true;
|
|
@@ -2312,7 +2232,7 @@
|
|
|
2312
2232
|
this.duration = 0;
|
|
2313
2233
|
this.fpsLimit = 120;
|
|
2314
2234
|
this.hdr = true;
|
|
2315
|
-
this.particles = loadParticlesOptions(this
|
|
2235
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2316
2236
|
this.pauseOnBlur = true;
|
|
2317
2237
|
this.pauseOnOutsideViewport = true;
|
|
2318
2238
|
this.resize = new ResizeEvent();
|
|
@@ -2327,12 +2247,12 @@
|
|
|
2327
2247
|
if (data.preset !== undefined) {
|
|
2328
2248
|
this.preset = data.preset;
|
|
2329
2249
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2330
|
-
this
|
|
2250
|
+
this.#importPreset(preset);
|
|
2331
2251
|
});
|
|
2332
2252
|
}
|
|
2333
2253
|
if (data.palette !== undefined) {
|
|
2334
2254
|
this.palette = data.palette;
|
|
2335
|
-
this
|
|
2255
|
+
this.#importPalette(this.palette);
|
|
2336
2256
|
}
|
|
2337
2257
|
if (data.autoPlay !== undefined) {
|
|
2338
2258
|
this.autoPlay = data.autoPlay;
|
|
@@ -2386,12 +2306,12 @@
|
|
|
2386
2306
|
if (data.smooth !== undefined) {
|
|
2387
2307
|
this.smooth = data.smooth;
|
|
2388
2308
|
}
|
|
2389
|
-
this.
|
|
2390
|
-
plugin.loadOptions(this
|
|
2309
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2310
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2391
2311
|
});
|
|
2392
2312
|
}
|
|
2393
|
-
|
|
2394
|
-
const paletteData = this.
|
|
2313
|
+
#importPalette = palette => {
|
|
2314
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2395
2315
|
if (!paletteData) {
|
|
2396
2316
|
return;
|
|
2397
2317
|
}
|
|
@@ -2408,8 +2328,8 @@
|
|
|
2408
2328
|
},
|
|
2409
2329
|
});
|
|
2410
2330
|
};
|
|
2411
|
-
|
|
2412
|
-
this.load(this.
|
|
2331
|
+
#importPreset = preset => {
|
|
2332
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2413
2333
|
};
|
|
2414
2334
|
}
|
|
2415
2335
|
|
|
@@ -2935,7 +2855,7 @@
|
|
|
2935
2855
|
}
|
|
2936
2856
|
|
|
2937
2857
|
async function loadBlendPlugin(engine) {
|
|
2938
|
-
engine.checkVersion("4.
|
|
2858
|
+
engine.checkVersion("4.1.1");
|
|
2939
2859
|
await engine.pluginManager.register(e => {
|
|
2940
2860
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2941
2861
|
});
|
|
@@ -2972,7 +2892,7 @@
|
|
|
2972
2892
|
}
|
|
2973
2893
|
|
|
2974
2894
|
async function loadCircleShape(engine) {
|
|
2975
|
-
engine.checkVersion("4.
|
|
2895
|
+
engine.checkVersion("4.1.1");
|
|
2976
2896
|
await engine.pluginManager.register(e => {
|
|
2977
2897
|
e.pluginManager.addShape(["circle"], () => {
|
|
2978
2898
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2993,15 +2913,15 @@
|
|
|
2993
2913
|
return input.startsWith("#");
|
|
2994
2914
|
}
|
|
2995
2915
|
handleColor(color) {
|
|
2996
|
-
return this
|
|
2916
|
+
return this.#parseString(color.value);
|
|
2997
2917
|
}
|
|
2998
2918
|
handleRangeColor(color) {
|
|
2999
|
-
return this
|
|
2919
|
+
return this.#parseString(color.value);
|
|
3000
2920
|
}
|
|
3001
2921
|
parseString(input) {
|
|
3002
|
-
return this
|
|
2922
|
+
return this.#parseString(input);
|
|
3003
2923
|
}
|
|
3004
|
-
|
|
2924
|
+
#parseString(hexColor) {
|
|
3005
2925
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
3006
2926
|
return;
|
|
3007
2927
|
}
|
|
@@ -3020,7 +2940,7 @@
|
|
|
3020
2940
|
}
|
|
3021
2941
|
|
|
3022
2942
|
async function loadHexColorPlugin(engine) {
|
|
3023
|
-
engine.checkVersion("4.
|
|
2943
|
+
engine.checkVersion("4.1.1");
|
|
3024
2944
|
await engine.pluginManager.register(e => {
|
|
3025
2945
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
3026
2946
|
});
|
|
@@ -3073,7 +2993,7 @@
|
|
|
3073
2993
|
}
|
|
3074
2994
|
|
|
3075
2995
|
async function loadHslColorPlugin(engine) {
|
|
3076
|
-
engine.checkVersion("4.
|
|
2996
|
+
engine.checkVersion("4.1.1");
|
|
3077
2997
|
await engine.pluginManager.register(e => {
|
|
3078
2998
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3079
2999
|
});
|
|
@@ -3081,13 +3001,13 @@
|
|
|
3081
3001
|
|
|
3082
3002
|
class MovePlugin {
|
|
3083
3003
|
id = "move";
|
|
3084
|
-
|
|
3004
|
+
#pluginManager;
|
|
3085
3005
|
constructor(pluginManager) {
|
|
3086
|
-
this
|
|
3006
|
+
this.#pluginManager = pluginManager;
|
|
3087
3007
|
}
|
|
3088
3008
|
async getPlugin(container) {
|
|
3089
3009
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3090
|
-
return new MovePluginInstance(this
|
|
3010
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3091
3011
|
}
|
|
3092
3012
|
loadOptions() {
|
|
3093
3013
|
}
|
|
@@ -3097,7 +3017,7 @@
|
|
|
3097
3017
|
}
|
|
3098
3018
|
|
|
3099
3019
|
async function loadMovePlugin(engine) {
|
|
3100
|
-
engine.checkVersion("4.
|
|
3020
|
+
engine.checkVersion("4.1.1");
|
|
3101
3021
|
await engine.pluginManager.register(e => {
|
|
3102
3022
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3103
3023
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3115,18 +3035,58 @@
|
|
|
3115
3035
|
});
|
|
3116
3036
|
}
|
|
3117
3037
|
|
|
3038
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
3039
|
+
destroy;
|
|
3040
|
+
constructor() {
|
|
3041
|
+
super();
|
|
3042
|
+
this.destroy = DestroyType.none;
|
|
3043
|
+
this.speed = 2;
|
|
3044
|
+
}
|
|
3045
|
+
load(data) {
|
|
3046
|
+
super.load(data);
|
|
3047
|
+
if (isNull(data)) {
|
|
3048
|
+
return;
|
|
3049
|
+
}
|
|
3050
|
+
if (data.destroy !== undefined) {
|
|
3051
|
+
this.destroy = data.destroy;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3057
|
+
animation;
|
|
3058
|
+
constructor() {
|
|
3059
|
+
super();
|
|
3060
|
+
this.animation = new OpacityAnimation();
|
|
3061
|
+
this.value = 1;
|
|
3062
|
+
}
|
|
3063
|
+
load(data) {
|
|
3064
|
+
if (isNull(data)) {
|
|
3065
|
+
return;
|
|
3066
|
+
}
|
|
3067
|
+
super.load(data);
|
|
3068
|
+
const animation = data.animation;
|
|
3069
|
+
if (animation !== undefined) {
|
|
3070
|
+
this.animation.load(animation);
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3118
3075
|
class OpacityUpdater {
|
|
3119
|
-
container;
|
|
3076
|
+
#container;
|
|
3120
3077
|
constructor(container) {
|
|
3121
|
-
this
|
|
3078
|
+
this.#container = container;
|
|
3122
3079
|
}
|
|
3123
3080
|
init(particle) {
|
|
3124
3081
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3082
|
+
if (!opacityOptions) {
|
|
3083
|
+
return;
|
|
3084
|
+
}
|
|
3125
3085
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3126
3086
|
const opacityAnimation = opacityOptions.animation;
|
|
3127
3087
|
if (opacityAnimation.enable) {
|
|
3128
3088
|
particle.opacity.velocity =
|
|
3129
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3089
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3130
3090
|
if (!opacityAnimation.sync) {
|
|
3131
3091
|
particle.opacity.velocity *= getRandom();
|
|
3132
3092
|
}
|
|
@@ -3142,6 +3102,12 @@
|
|
|
3142
3102
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3143
3103
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3144
3104
|
}
|
|
3105
|
+
loadOptions(options, ...sources) {
|
|
3106
|
+
options.opacity ??= new Opacity();
|
|
3107
|
+
for (const source of sources) {
|
|
3108
|
+
options.opacity.load(source?.opacity);
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3145
3111
|
reset(particle) {
|
|
3146
3112
|
if (!particle.opacity) {
|
|
3147
3113
|
return;
|
|
@@ -3150,7 +3116,7 @@
|
|
|
3150
3116
|
particle.opacity.loops = 0;
|
|
3151
3117
|
}
|
|
3152
3118
|
update(particle, delta) {
|
|
3153
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3119
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3154
3120
|
return;
|
|
3155
3121
|
}
|
|
3156
3122
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3158,7 +3124,7 @@
|
|
|
3158
3124
|
}
|
|
3159
3125
|
|
|
3160
3126
|
async function loadOpacityUpdater(engine) {
|
|
3161
|
-
engine.checkVersion("4.
|
|
3127
|
+
engine.checkVersion("4.1.1");
|
|
3162
3128
|
await engine.pluginManager.register(e => {
|
|
3163
3129
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3164
3130
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3180,10 +3146,9 @@
|
|
|
3180
3146
|
}
|
|
3181
3147
|
const velocity = data.particle.velocity.x;
|
|
3182
3148
|
let bounced = false;
|
|
3183
|
-
if (
|
|
3184
|
-
data.
|
|
3185
|
-
|
|
3186
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3149
|
+
if (data.outOfCanvas &&
|
|
3150
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3151
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3187
3152
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3188
3153
|
data.particle.velocity.x *= -newVelocity;
|
|
3189
3154
|
bounced = true;
|
|
@@ -3192,10 +3157,10 @@
|
|
|
3192
3157
|
return;
|
|
3193
3158
|
}
|
|
3194
3159
|
const minPos = data.offset.x + data.size;
|
|
3195
|
-
if (data.
|
|
3160
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3196
3161
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3197
3162
|
}
|
|
3198
|
-
else if (data.
|
|
3163
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3199
3164
|
data.particle.position.x = minPos;
|
|
3200
3165
|
}
|
|
3201
3166
|
if (data.outMode === OutMode.split) {
|
|
@@ -3215,10 +3180,9 @@
|
|
|
3215
3180
|
}
|
|
3216
3181
|
const velocity = data.particle.velocity.y;
|
|
3217
3182
|
let bounced = false;
|
|
3218
|
-
if (
|
|
3219
|
-
data.
|
|
3220
|
-
|
|
3221
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3183
|
+
if (data.outOfCanvas &&
|
|
3184
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3185
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3222
3186
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3223
3187
|
data.particle.velocity.y *= -newVelocity;
|
|
3224
3188
|
bounced = true;
|
|
@@ -3227,10 +3191,10 @@
|
|
|
3227
3191
|
return;
|
|
3228
3192
|
}
|
|
3229
3193
|
const minPos = data.offset.y + data.size;
|
|
3230
|
-
if (data.
|
|
3194
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3231
3195
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3232
3196
|
}
|
|
3233
|
-
else if (data.
|
|
3197
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3234
3198
|
data.particle.position.y = minPos;
|
|
3235
3199
|
}
|
|
3236
3200
|
if (data.outMode === OutMode.split) {
|
|
@@ -3239,24 +3203,24 @@
|
|
|
3239
3203
|
}
|
|
3240
3204
|
|
|
3241
3205
|
class BounceOutMode {
|
|
3242
|
-
container;
|
|
3243
3206
|
modes;
|
|
3244
|
-
|
|
3207
|
+
#container;
|
|
3208
|
+
#particleBouncePlugins;
|
|
3245
3209
|
constructor(container) {
|
|
3246
|
-
this
|
|
3210
|
+
this.#container = container;
|
|
3247
3211
|
this.modes = [
|
|
3248
3212
|
OutMode.bounce,
|
|
3249
3213
|
OutMode.split,
|
|
3250
3214
|
];
|
|
3251
|
-
this
|
|
3215
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3252
3216
|
}
|
|
3253
3217
|
update(particle, direction, delta, outMode) {
|
|
3254
3218
|
if (!this.modes.includes(outMode)) {
|
|
3255
3219
|
return;
|
|
3256
3220
|
}
|
|
3257
|
-
const container = this
|
|
3221
|
+
const container = this.#container;
|
|
3258
3222
|
let handled = false;
|
|
3259
|
-
for (const plugin of this
|
|
3223
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3260
3224
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3261
3225
|
if (handled) {
|
|
3262
3226
|
break;
|
|
@@ -3265,29 +3229,26 @@
|
|
|
3265
3229
|
if (handled) {
|
|
3266
3230
|
return;
|
|
3267
3231
|
}
|
|
3268
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3269
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3270
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3232
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3233
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3234
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3271
3235
|
}
|
|
3272
3236
|
}
|
|
3273
3237
|
|
|
3274
3238
|
const minVelocity$3 = 0;
|
|
3275
3239
|
class DestroyOutMode {
|
|
3276
|
-
container;
|
|
3277
3240
|
modes;
|
|
3278
|
-
constructor(
|
|
3279
|
-
this.container = container;
|
|
3241
|
+
constructor(_container) {
|
|
3280
3242
|
this.modes = [OutMode.destroy];
|
|
3281
3243
|
}
|
|
3282
3244
|
update(particle, direction, _delta, outMode) {
|
|
3283
3245
|
if (!this.modes.includes(outMode)) {
|
|
3284
3246
|
return;
|
|
3285
3247
|
}
|
|
3286
|
-
const container = this.container;
|
|
3287
3248
|
switch (particle.outType) {
|
|
3288
3249
|
case ParticleOutType.normal:
|
|
3289
3250
|
case ParticleOutType.outside:
|
|
3290
|
-
if (
|
|
3251
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3291
3252
|
return;
|
|
3292
3253
|
}
|
|
3293
3254
|
break;
|
|
@@ -3308,10 +3269,10 @@
|
|
|
3308
3269
|
|
|
3309
3270
|
const minVelocity$2 = 0;
|
|
3310
3271
|
class NoneOutMode {
|
|
3311
|
-
container;
|
|
3312
3272
|
modes;
|
|
3273
|
+
#container;
|
|
3313
3274
|
constructor(container) {
|
|
3314
|
-
this
|
|
3275
|
+
this.#container = container;
|
|
3315
3276
|
this.modes = [OutMode.none];
|
|
3316
3277
|
}
|
|
3317
3278
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3324,7 +3285,7 @@
|
|
|
3324
3285
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3325
3286
|
return;
|
|
3326
3287
|
}
|
|
3327
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3288
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3328
3289
|
if (!gravityOptions.enable) {
|
|
3329
3290
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3330
3291
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3350,17 +3311,17 @@
|
|
|
3350
3311
|
|
|
3351
3312
|
const minVelocity$1 = 0, minDistance$2 = 0, updateVector = Vector.origin;
|
|
3352
3313
|
class OutOutMode {
|
|
3353
|
-
container;
|
|
3354
3314
|
modes;
|
|
3315
|
+
#container;
|
|
3355
3316
|
constructor(container) {
|
|
3356
|
-
this
|
|
3317
|
+
this.#container = container;
|
|
3357
3318
|
this.modes = [OutMode.out];
|
|
3358
3319
|
}
|
|
3359
3320
|
update(particle, direction, _delta, outMode) {
|
|
3360
3321
|
if (!this.modes.includes(outMode)) {
|
|
3361
3322
|
return;
|
|
3362
3323
|
}
|
|
3363
|
-
const container = this
|
|
3324
|
+
const container = this.#container;
|
|
3364
3325
|
switch (particle.outType) {
|
|
3365
3326
|
case ParticleOutType.inside: {
|
|
3366
3327
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3390,7 +3351,7 @@
|
|
|
3390
3351
|
break;
|
|
3391
3352
|
}
|
|
3392
3353
|
default: {
|
|
3393
|
-
if (
|
|
3354
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3394
3355
|
return;
|
|
3395
3356
|
}
|
|
3396
3357
|
switch (particle.outType) {
|
|
@@ -3474,16 +3435,16 @@
|
|
|
3474
3435
|
};
|
|
3475
3436
|
class OutOfCanvasUpdater {
|
|
3476
3437
|
updaters;
|
|
3477
|
-
container;
|
|
3438
|
+
#container;
|
|
3478
3439
|
constructor(container) {
|
|
3479
|
-
this
|
|
3440
|
+
this.#container = container;
|
|
3480
3441
|
this.updaters = new Map();
|
|
3481
3442
|
}
|
|
3482
3443
|
init(particle) {
|
|
3483
|
-
this
|
|
3484
|
-
this
|
|
3485
|
-
this
|
|
3486
|
-
this
|
|
3444
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3445
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3446
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3447
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3487
3448
|
}
|
|
3488
3449
|
isEnabled(particle) {
|
|
3489
3450
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3491,18 +3452,18 @@
|
|
|
3491
3452
|
update(particle, delta) {
|
|
3492
3453
|
const outModes = particle.options.move.outModes;
|
|
3493
3454
|
particle.justWarped = false;
|
|
3494
|
-
this
|
|
3495
|
-
this
|
|
3496
|
-
this
|
|
3497
|
-
this
|
|
3455
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3456
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3457
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3458
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3498
3459
|
}
|
|
3499
|
-
|
|
3460
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3500
3461
|
const outModes = particle.options.move.outModes;
|
|
3501
3462
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3502
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3463
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3503
3464
|
}
|
|
3504
3465
|
};
|
|
3505
|
-
|
|
3466
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3506
3467
|
for (const updater of this.updaters.values()) {
|
|
3507
3468
|
updater.update(particle, direction, delta, outMode);
|
|
3508
3469
|
}
|
|
@@ -3510,7 +3471,7 @@
|
|
|
3510
3471
|
}
|
|
3511
3472
|
|
|
3512
3473
|
async function loadOutModesUpdater(engine) {
|
|
3513
|
-
engine.checkVersion("4.
|
|
3474
|
+
engine.checkVersion("4.1.1");
|
|
3514
3475
|
await engine.pluginManager.register(e => {
|
|
3515
3476
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3516
3477
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3520,20 +3481,20 @@
|
|
|
3520
3481
|
|
|
3521
3482
|
const defaultOpacity = 1;
|
|
3522
3483
|
class PaintUpdater {
|
|
3523
|
-
|
|
3524
|
-
|
|
3484
|
+
#container;
|
|
3485
|
+
#pluginManager;
|
|
3525
3486
|
constructor(pluginManager, container) {
|
|
3526
|
-
this
|
|
3527
|
-
this
|
|
3487
|
+
this.#container = container;
|
|
3488
|
+
this.#pluginManager = pluginManager;
|
|
3528
3489
|
}
|
|
3529
3490
|
init(particle) {
|
|
3530
|
-
const container = this
|
|
3491
|
+
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;
|
|
3531
3492
|
if (fill) {
|
|
3532
3493
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3533
3494
|
particle.fillEnabled = fill.enable;
|
|
3534
3495
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3535
3496
|
particle.fillAnimation = fillColor.animation;
|
|
3536
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3497
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3537
3498
|
if (fillHslColor) {
|
|
3538
3499
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3539
3500
|
}
|
|
@@ -3549,7 +3510,7 @@
|
|
|
3549
3510
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3550
3511
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3551
3512
|
particle.strokeAnimation = strokeColor.animation;
|
|
3552
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3513
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3553
3514
|
if (strokeHslColor) {
|
|
3554
3515
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3555
3516
|
}
|
|
@@ -3581,7 +3542,7 @@
|
|
|
3581
3542
|
}
|
|
3582
3543
|
|
|
3583
3544
|
async function loadPaintUpdater(engine) {
|
|
3584
|
-
engine.checkVersion("4.
|
|
3545
|
+
engine.checkVersion("4.1.1");
|
|
3585
3546
|
await engine.pluginManager.register(e => {
|
|
3586
3547
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3587
3548
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3636,27 +3597,69 @@
|
|
|
3636
3597
|
}
|
|
3637
3598
|
|
|
3638
3599
|
async function loadRgbColorPlugin(engine) {
|
|
3639
|
-
engine.checkVersion("4.
|
|
3600
|
+
engine.checkVersion("4.1.1");
|
|
3640
3601
|
await engine.pluginManager.register(e => {
|
|
3641
3602
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3642
3603
|
});
|
|
3643
3604
|
}
|
|
3644
3605
|
|
|
3606
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3607
|
+
destroy;
|
|
3608
|
+
constructor() {
|
|
3609
|
+
super();
|
|
3610
|
+
this.destroy = DestroyType.none;
|
|
3611
|
+
this.speed = 5;
|
|
3612
|
+
}
|
|
3613
|
+
load(data) {
|
|
3614
|
+
super.load(data);
|
|
3615
|
+
if (isNull(data)) {
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
if (data.destroy !== undefined) {
|
|
3619
|
+
this.destroy = data.destroy;
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3625
|
+
animation;
|
|
3626
|
+
constructor() {
|
|
3627
|
+
super();
|
|
3628
|
+
this.animation = new SizeAnimation();
|
|
3629
|
+
this.value = 3;
|
|
3630
|
+
}
|
|
3631
|
+
load(data) {
|
|
3632
|
+
super.load(data);
|
|
3633
|
+
if (isNull(data)) {
|
|
3634
|
+
return;
|
|
3635
|
+
}
|
|
3636
|
+
const animation = data.animation;
|
|
3637
|
+
if (animation !== undefined) {
|
|
3638
|
+
this.animation.load(animation);
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
|
|
3645
3643
|
const minLoops = 0;
|
|
3646
3644
|
class SizeUpdater {
|
|
3647
|
-
|
|
3645
|
+
#container;
|
|
3648
3646
|
constructor(container) {
|
|
3649
|
-
this
|
|
3647
|
+
this.#container = container;
|
|
3650
3648
|
}
|
|
3651
3649
|
init(particle) {
|
|
3652
|
-
const container = this
|
|
3653
|
-
if (
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3650
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3651
|
+
if (!sizeOptions) {
|
|
3652
|
+
return;
|
|
3653
|
+
}
|
|
3654
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3655
|
+
if (!sizeAnimation.enable) {
|
|
3656
|
+
return;
|
|
3659
3657
|
}
|
|
3658
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3659
|
+
if (sizeAnimation.sync) {
|
|
3660
|
+
return;
|
|
3661
|
+
}
|
|
3662
|
+
particle.size.velocity *= getRandom();
|
|
3660
3663
|
}
|
|
3661
3664
|
isEnabled(particle) {
|
|
3662
3665
|
return (!particle.destroyed &&
|
|
@@ -3666,12 +3669,26 @@
|
|
|
3666
3669
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3667
3670
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3668
3671
|
}
|
|
3672
|
+
loadOptions(options, ...sources) {
|
|
3673
|
+
options.size ??= new Size();
|
|
3674
|
+
for (const source of sources) {
|
|
3675
|
+
options.size.load(source?.size);
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
preInit(particle) {
|
|
3679
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3680
|
+
if (!sizeOptions) {
|
|
3681
|
+
return;
|
|
3682
|
+
}
|
|
3683
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3684
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3685
|
+
}
|
|
3669
3686
|
reset(particle) {
|
|
3670
3687
|
particle.size.time = 0;
|
|
3671
3688
|
particle.size.loops = 0;
|
|
3672
3689
|
}
|
|
3673
3690
|
update(particle, delta) {
|
|
3674
|
-
if (!this.isEnabled(particle)) {
|
|
3691
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3675
3692
|
return;
|
|
3676
3693
|
}
|
|
3677
3694
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3679,7 +3696,7 @@
|
|
|
3679
3696
|
}
|
|
3680
3697
|
|
|
3681
3698
|
async function loadSizeUpdater(engine) {
|
|
3682
|
-
engine.checkVersion("4.
|
|
3699
|
+
engine.checkVersion("4.1.1");
|
|
3683
3700
|
await engine.pluginManager.register(e => {
|
|
3684
3701
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3685
3702
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3688,7 +3705,7 @@
|
|
|
3688
3705
|
}
|
|
3689
3706
|
|
|
3690
3707
|
async function loadBasic(engine) {
|
|
3691
|
-
engine.checkVersion("4.
|
|
3708
|
+
engine.checkVersion("4.1.1");
|
|
3692
3709
|
await engine.pluginManager.register(async (e) => {
|
|
3693
3710
|
await Promise.all([
|
|
3694
3711
|
loadBlendPlugin(e),
|
|
@@ -3815,20 +3832,20 @@
|
|
|
3815
3832
|
})(InteractivityDetect || (InteractivityDetect = {}));
|
|
3816
3833
|
|
|
3817
3834
|
class Modes {
|
|
3818
|
-
|
|
3819
|
-
|
|
3835
|
+
#container;
|
|
3836
|
+
#pluginManager;
|
|
3820
3837
|
constructor(pluginManager, container) {
|
|
3821
|
-
this
|
|
3822
|
-
this
|
|
3838
|
+
this.#pluginManager = pluginManager;
|
|
3839
|
+
this.#container = container;
|
|
3823
3840
|
}
|
|
3824
3841
|
load(data) {
|
|
3825
3842
|
if (isNull(data)) {
|
|
3826
3843
|
return;
|
|
3827
3844
|
}
|
|
3828
|
-
if (!this
|
|
3845
|
+
if (!this.#container) {
|
|
3829
3846
|
return;
|
|
3830
3847
|
}
|
|
3831
|
-
const interactors = this.
|
|
3848
|
+
const interactors = this.#pluginManager.interactors?.get(this.#container);
|
|
3832
3849
|
if (!interactors) {
|
|
3833
3850
|
return;
|
|
3834
3851
|
}
|
|
@@ -3865,13 +3882,13 @@
|
|
|
3865
3882
|
|
|
3866
3883
|
class InteractivityPlugin {
|
|
3867
3884
|
id = "interactivity";
|
|
3868
|
-
|
|
3885
|
+
#pluginManager;
|
|
3869
3886
|
constructor(pluginManager) {
|
|
3870
|
-
this
|
|
3887
|
+
this.#pluginManager = pluginManager;
|
|
3871
3888
|
}
|
|
3872
3889
|
async getPlugin(container) {
|
|
3873
3890
|
const { InteractivityPluginInstance } = await Promise.resolve().then(function () { return InteractivityPluginInstance$1; });
|
|
3874
|
-
return new InteractivityPluginInstance(this
|
|
3891
|
+
return new InteractivityPluginInstance(this.#pluginManager, container);
|
|
3875
3892
|
}
|
|
3876
3893
|
loadOptions(container, options, source) {
|
|
3877
3894
|
if (!this.needsPlugin()) {
|
|
@@ -3879,10 +3896,10 @@
|
|
|
3879
3896
|
}
|
|
3880
3897
|
let interactivityOptions = options.interactivity;
|
|
3881
3898
|
if (!interactivityOptions?.load) {
|
|
3882
|
-
options.interactivity = interactivityOptions = new Interactivity(this
|
|
3899
|
+
options.interactivity = interactivityOptions = new Interactivity(this.#pluginManager, container);
|
|
3883
3900
|
}
|
|
3884
3901
|
interactivityOptions.load(source?.interactivity);
|
|
3885
|
-
const interactors = this.
|
|
3902
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
3886
3903
|
if (!interactors) {
|
|
3887
3904
|
return;
|
|
3888
3905
|
}
|
|
@@ -3896,7 +3913,7 @@
|
|
|
3896
3913
|
if (source?.interactivity) {
|
|
3897
3914
|
options.interactivity = deepExtend({}, source.interactivity);
|
|
3898
3915
|
}
|
|
3899
|
-
const interactors = this.
|
|
3916
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
3900
3917
|
if (!interactors) {
|
|
3901
3918
|
return;
|
|
3902
3919
|
}
|
|
@@ -3926,7 +3943,7 @@
|
|
|
3926
3943
|
const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
|
|
3927
3944
|
|
|
3928
3945
|
async function loadInteractivityPlugin(engine) {
|
|
3929
|
-
engine.checkVersion("4.
|
|
3946
|
+
engine.checkVersion("4.1.1");
|
|
3930
3947
|
await engine.pluginManager.register(e => {
|
|
3931
3948
|
const interactivityEngine = e, interactivityPluginManager = interactivityEngine.pluginManager;
|
|
3932
3949
|
interactivityPluginManager.addPlugin(new InteractivityPlugin(interactivityPluginManager));
|
|
@@ -3960,15 +3977,15 @@
|
|
|
3960
3977
|
}
|
|
3961
3978
|
|
|
3962
3979
|
class CircleWarp extends Circle {
|
|
3963
|
-
canvasSize;
|
|
3980
|
+
#canvasSize;
|
|
3964
3981
|
constructor(x, y, radius, canvasSize) {
|
|
3965
3982
|
super(x, y, radius);
|
|
3966
|
-
this
|
|
3983
|
+
this.#canvasSize = canvasSize;
|
|
3967
3984
|
}
|
|
3968
3985
|
contains(point) {
|
|
3969
3986
|
if (super.contains(point))
|
|
3970
3987
|
return true;
|
|
3971
|
-
const { width, height } = this
|
|
3988
|
+
const { width, height } = this.#canvasSize, { x, y } = point;
|
|
3972
3989
|
return (super.contains({ x: x - width, y }) ||
|
|
3973
3990
|
super.contains({ x: x + width, y }) ||
|
|
3974
3991
|
super.contains({ x, y: y - height }) ||
|
|
@@ -3981,7 +3998,7 @@
|
|
|
3981
3998
|
intersects(range) {
|
|
3982
3999
|
if (super.intersects(range))
|
|
3983
4000
|
return true;
|
|
3984
|
-
const { width, height } = this
|
|
4001
|
+
const { width, height } = this.#canvasSize, pos = range.position, shifts = [
|
|
3985
4002
|
{ x: -width, y: 0 },
|
|
3986
4003
|
{ x: width, y: 0 },
|
|
3987
4004
|
{ x: 0, y: -height },
|
|
@@ -4133,15 +4150,15 @@
|
|
|
4133
4150
|
return Math.hypot(warpDistances.x, warpDistances.y);
|
|
4134
4151
|
}
|
|
4135
4152
|
class Linker extends ParticlesInteractorBase {
|
|
4136
|
-
|
|
4137
|
-
|
|
4153
|
+
#maxDistance;
|
|
4154
|
+
#pluginManager;
|
|
4138
4155
|
constructor(pluginManager, container) {
|
|
4139
4156
|
super(container);
|
|
4140
|
-
this
|
|
4141
|
-
this
|
|
4157
|
+
this.#pluginManager = pluginManager;
|
|
4158
|
+
this.#maxDistance = 0;
|
|
4142
4159
|
}
|
|
4143
4160
|
get maxDistance() {
|
|
4144
|
-
return this
|
|
4161
|
+
return this.#maxDistance;
|
|
4145
4162
|
}
|
|
4146
4163
|
clear() {
|
|
4147
4164
|
}
|
|
@@ -4154,8 +4171,8 @@
|
|
|
4154
4171
|
return;
|
|
4155
4172
|
}
|
|
4156
4173
|
p1.links = [];
|
|
4157
|
-
if (p1.linksDistance && p1.linksDistance > this
|
|
4158
|
-
this
|
|
4174
|
+
if (p1.linksDistance && p1.linksDistance > this.#maxDistance) {
|
|
4175
|
+
this.#maxDistance = p1.linksDistance;
|
|
4159
4176
|
}
|
|
4160
4177
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
4161
4178
|
if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
@@ -4183,11 +4200,11 @@
|
|
|
4183
4200
|
continue;
|
|
4184
4201
|
}
|
|
4185
4202
|
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
4186
|
-
this
|
|
4203
|
+
this.#setColor(p1);
|
|
4187
4204
|
p1.links.push({
|
|
4188
4205
|
destination: p2,
|
|
4189
4206
|
opacity: opacityLine,
|
|
4190
|
-
color: this
|
|
4207
|
+
color: this.#getLinkColor(p1, p2),
|
|
4191
4208
|
isWarped: distWarp < distDirect,
|
|
4192
4209
|
});
|
|
4193
4210
|
}
|
|
@@ -4203,7 +4220,7 @@
|
|
|
4203
4220
|
}
|
|
4204
4221
|
reset() {
|
|
4205
4222
|
}
|
|
4206
|
-
|
|
4223
|
+
#getLinkColor(p1, p2) {
|
|
4207
4224
|
const container = this.container, linksOptions = p1.options.links;
|
|
4208
4225
|
if (!linksOptions) {
|
|
4209
4226
|
return;
|
|
@@ -4213,7 +4230,7 @@
|
|
|
4213
4230
|
: container.particles.linksColor;
|
|
4214
4231
|
return getLinkColor(p1, p2, linkColor);
|
|
4215
4232
|
}
|
|
4216
|
-
|
|
4233
|
+
#setColor(p1) {
|
|
4217
4234
|
if (!p1.options.links) {
|
|
4218
4235
|
return;
|
|
4219
4236
|
}
|
|
@@ -4224,7 +4241,7 @@
|
|
|
4224
4241
|
if (linkColor) {
|
|
4225
4242
|
return;
|
|
4226
4243
|
}
|
|
4227
|
-
linkColor = getLinkRandomColor(this
|
|
4244
|
+
linkColor = getLinkRandomColor(this.#pluginManager, linksOptions.color, linksOptions.blink, linksOptions.consent);
|
|
4228
4245
|
if (linksOptions.id === undefined) {
|
|
4229
4246
|
container.particles.linksColor = linkColor;
|
|
4230
4247
|
}
|
|
@@ -4236,13 +4253,13 @@
|
|
|
4236
4253
|
|
|
4237
4254
|
class LinksPlugin {
|
|
4238
4255
|
id = "links";
|
|
4239
|
-
|
|
4256
|
+
#pluginManager;
|
|
4240
4257
|
constructor(pluginManager) {
|
|
4241
|
-
this
|
|
4258
|
+
this.#pluginManager = pluginManager;
|
|
4242
4259
|
}
|
|
4243
4260
|
async getPlugin(container) {
|
|
4244
4261
|
const { LinkInstance } = await Promise.resolve().then(function () { return LinkInstance$1; });
|
|
4245
|
-
return new LinkInstance(this
|
|
4262
|
+
return new LinkInstance(this.#pluginManager, container);
|
|
4246
4263
|
}
|
|
4247
4264
|
loadOptions() {
|
|
4248
4265
|
}
|
|
@@ -4252,7 +4269,7 @@
|
|
|
4252
4269
|
}
|
|
4253
4270
|
|
|
4254
4271
|
async function loadParticlesLinksInteraction(engine) {
|
|
4255
|
-
engine.checkVersion("4.
|
|
4272
|
+
engine.checkVersion("4.1.1");
|
|
4256
4273
|
await engine.pluginManager.register((e) => {
|
|
4257
4274
|
const pluginManager = e.pluginManager;
|
|
4258
4275
|
ensureInteractivityPluginLoaded(e);
|
|
@@ -4320,58 +4337,58 @@
|
|
|
4320
4337
|
}
|
|
4321
4338
|
}
|
|
4322
4339
|
class RenderManager {
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4340
|
+
#canvasClearPlugins;
|
|
4341
|
+
#canvasManager;
|
|
4342
|
+
#canvasPaintPlugins;
|
|
4343
|
+
#clearDrawPlugins;
|
|
4344
|
+
#colorPlugins;
|
|
4345
|
+
#container;
|
|
4346
|
+
#context;
|
|
4347
|
+
#contextSettings;
|
|
4348
|
+
#drawParticlePlugins;
|
|
4349
|
+
#drawParticlesCleanupPlugins;
|
|
4350
|
+
#drawParticlesSetupPlugins;
|
|
4351
|
+
#drawPlugins;
|
|
4352
|
+
#drawSettingsCleanupPlugins;
|
|
4353
|
+
#drawSettingsSetupPlugins;
|
|
4354
|
+
#pluginManager;
|
|
4355
|
+
#postDrawUpdaters;
|
|
4356
|
+
#preDrawUpdaters;
|
|
4357
|
+
#reusableColorStyles = {};
|
|
4358
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4359
|
+
#reusableTransform = {};
|
|
4343
4360
|
constructor(pluginManager, container, canvasManager) {
|
|
4344
|
-
this
|
|
4345
|
-
this
|
|
4346
|
-
this
|
|
4347
|
-
this
|
|
4348
|
-
this
|
|
4349
|
-
this
|
|
4350
|
-
this
|
|
4351
|
-
this
|
|
4352
|
-
this
|
|
4353
|
-
this
|
|
4354
|
-
this
|
|
4355
|
-
this
|
|
4356
|
-
this
|
|
4357
|
-
this
|
|
4358
|
-
this
|
|
4359
|
-
this
|
|
4361
|
+
this.#pluginManager = pluginManager;
|
|
4362
|
+
this.#container = container;
|
|
4363
|
+
this.#canvasManager = canvasManager;
|
|
4364
|
+
this.#context = null;
|
|
4365
|
+
this.#preDrawUpdaters = [];
|
|
4366
|
+
this.#postDrawUpdaters = [];
|
|
4367
|
+
this.#colorPlugins = [];
|
|
4368
|
+
this.#canvasClearPlugins = [];
|
|
4369
|
+
this.#canvasPaintPlugins = [];
|
|
4370
|
+
this.#clearDrawPlugins = [];
|
|
4371
|
+
this.#drawParticlePlugins = [];
|
|
4372
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4373
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4374
|
+
this.#drawPlugins = [];
|
|
4375
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4376
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4360
4377
|
}
|
|
4361
4378
|
get settings() {
|
|
4362
|
-
return this
|
|
4379
|
+
return this.#contextSettings;
|
|
4363
4380
|
}
|
|
4364
4381
|
canvasClear() {
|
|
4365
|
-
if (!this.
|
|
4382
|
+
if (!this.#container.actualOptions.clear) {
|
|
4366
4383
|
return;
|
|
4367
4384
|
}
|
|
4368
4385
|
this.draw(ctx => {
|
|
4369
|
-
clear(ctx, this.
|
|
4386
|
+
clear(ctx, this.#canvasManager.size);
|
|
4370
4387
|
});
|
|
4371
4388
|
}
|
|
4372
4389
|
clear() {
|
|
4373
4390
|
let pluginHandled = false;
|
|
4374
|
-
for (const plugin of this
|
|
4391
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4375
4392
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4376
4393
|
if (pluginHandled) {
|
|
4377
4394
|
break;
|
|
@@ -4384,21 +4401,21 @@
|
|
|
4384
4401
|
}
|
|
4385
4402
|
destroy() {
|
|
4386
4403
|
this.stop();
|
|
4387
|
-
this
|
|
4388
|
-
this
|
|
4389
|
-
this
|
|
4390
|
-
this
|
|
4391
|
-
this
|
|
4392
|
-
this
|
|
4393
|
-
this
|
|
4394
|
-
this
|
|
4395
|
-
this
|
|
4396
|
-
this
|
|
4397
|
-
this
|
|
4398
|
-
this
|
|
4404
|
+
this.#preDrawUpdaters = [];
|
|
4405
|
+
this.#postDrawUpdaters = [];
|
|
4406
|
+
this.#colorPlugins = [];
|
|
4407
|
+
this.#canvasClearPlugins = [];
|
|
4408
|
+
this.#canvasPaintPlugins = [];
|
|
4409
|
+
this.#clearDrawPlugins = [];
|
|
4410
|
+
this.#drawParticlePlugins = [];
|
|
4411
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4412
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4413
|
+
this.#drawPlugins = [];
|
|
4414
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4415
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4399
4416
|
}
|
|
4400
4417
|
draw(cb) {
|
|
4401
|
-
const ctx = this
|
|
4418
|
+
const ctx = this.#context;
|
|
4402
4419
|
if (!ctx) {
|
|
4403
4420
|
return;
|
|
4404
4421
|
}
|
|
@@ -4413,21 +4430,21 @@
|
|
|
4413
4430
|
return;
|
|
4414
4431
|
}
|
|
4415
4432
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4416
|
-
let [fColor, sColor] = this
|
|
4433
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4417
4434
|
fColor ??= pfColor;
|
|
4418
4435
|
sColor ??= psColor;
|
|
4419
4436
|
if (!fColor && !sColor) {
|
|
4420
4437
|
return;
|
|
4421
4438
|
}
|
|
4422
|
-
const container = this
|
|
4439
|
+
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;
|
|
4423
4440
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4424
4441
|
colorStyles.fill = fill;
|
|
4425
4442
|
colorStyles.stroke = stroke;
|
|
4426
4443
|
this.draw((context) => {
|
|
4427
|
-
for (const plugin of this
|
|
4444
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4428
4445
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4429
4446
|
}
|
|
4430
|
-
this
|
|
4447
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4431
4448
|
drawParticle({
|
|
4432
4449
|
container,
|
|
4433
4450
|
context,
|
|
@@ -4438,35 +4455,35 @@
|
|
|
4438
4455
|
opacity: opacity,
|
|
4439
4456
|
transform,
|
|
4440
4457
|
});
|
|
4441
|
-
this
|
|
4442
|
-
for (const plugin of this
|
|
4458
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4459
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4443
4460
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4444
4461
|
}
|
|
4445
4462
|
});
|
|
4446
4463
|
}
|
|
4447
4464
|
drawParticlePlugins(particle, delta) {
|
|
4448
4465
|
this.draw(ctx => {
|
|
4449
|
-
for (const plugin of this
|
|
4466
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4450
4467
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4451
4468
|
}
|
|
4452
4469
|
});
|
|
4453
4470
|
}
|
|
4454
4471
|
drawParticles(delta) {
|
|
4455
|
-
const { particles } = this
|
|
4472
|
+
const { particles } = this.#container;
|
|
4456
4473
|
this.clear();
|
|
4457
4474
|
particles.update(delta);
|
|
4458
4475
|
this.draw(ctx => {
|
|
4459
|
-
for (const plugin of this
|
|
4476
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4460
4477
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4461
4478
|
}
|
|
4462
|
-
for (const plugin of this
|
|
4479
|
+
for (const plugin of this.#drawPlugins) {
|
|
4463
4480
|
plugin.draw?.(ctx, delta);
|
|
4464
4481
|
}
|
|
4465
4482
|
particles.drawParticles(delta);
|
|
4466
|
-
for (const plugin of this
|
|
4483
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4467
4484
|
plugin.clearDraw?.(ctx, delta);
|
|
4468
4485
|
}
|
|
4469
|
-
for (const plugin of this
|
|
4486
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4470
4487
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4471
4488
|
}
|
|
4472
4489
|
});
|
|
@@ -4477,64 +4494,64 @@
|
|
|
4477
4494
|
this.paint();
|
|
4478
4495
|
}
|
|
4479
4496
|
initPlugins() {
|
|
4480
|
-
this
|
|
4481
|
-
this
|
|
4482
|
-
this
|
|
4483
|
-
this
|
|
4484
|
-
this
|
|
4485
|
-
this
|
|
4486
|
-
this
|
|
4487
|
-
this
|
|
4488
|
-
this
|
|
4489
|
-
this
|
|
4490
|
-
for (const plugin of this.
|
|
4497
|
+
this.#colorPlugins = [];
|
|
4498
|
+
this.#canvasClearPlugins = [];
|
|
4499
|
+
this.#canvasPaintPlugins = [];
|
|
4500
|
+
this.#clearDrawPlugins = [];
|
|
4501
|
+
this.#drawParticlePlugins = [];
|
|
4502
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4503
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4504
|
+
this.#drawPlugins = [];
|
|
4505
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4506
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4507
|
+
for (const plugin of this.#container.plugins) {
|
|
4491
4508
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4492
|
-
this.
|
|
4509
|
+
this.#colorPlugins.push(plugin);
|
|
4493
4510
|
}
|
|
4494
4511
|
if (plugin.canvasClear) {
|
|
4495
|
-
this.
|
|
4512
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4496
4513
|
}
|
|
4497
4514
|
if (plugin.canvasPaint) {
|
|
4498
|
-
this.
|
|
4515
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4499
4516
|
}
|
|
4500
4517
|
if (plugin.drawParticle) {
|
|
4501
|
-
this.
|
|
4518
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4502
4519
|
}
|
|
4503
4520
|
if (plugin.drawParticleSetup) {
|
|
4504
|
-
this.
|
|
4521
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4505
4522
|
}
|
|
4506
4523
|
if (plugin.drawParticleCleanup) {
|
|
4507
|
-
this.
|
|
4524
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4508
4525
|
}
|
|
4509
4526
|
if (plugin.draw) {
|
|
4510
|
-
this.
|
|
4527
|
+
this.#drawPlugins.push(plugin);
|
|
4511
4528
|
}
|
|
4512
4529
|
if (plugin.drawSettingsSetup) {
|
|
4513
|
-
this.
|
|
4530
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4514
4531
|
}
|
|
4515
4532
|
if (plugin.drawSettingsCleanup) {
|
|
4516
|
-
this.
|
|
4533
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4517
4534
|
}
|
|
4518
4535
|
if (plugin.clearDraw) {
|
|
4519
|
-
this.
|
|
4536
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4520
4537
|
}
|
|
4521
4538
|
}
|
|
4522
4539
|
}
|
|
4523
4540
|
initUpdaters() {
|
|
4524
|
-
this
|
|
4525
|
-
this
|
|
4526
|
-
for (const updater of this.
|
|
4541
|
+
this.#preDrawUpdaters = [];
|
|
4542
|
+
this.#postDrawUpdaters = [];
|
|
4543
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4527
4544
|
if (updater.afterDraw) {
|
|
4528
|
-
this.
|
|
4545
|
+
this.#postDrawUpdaters.push(updater);
|
|
4529
4546
|
}
|
|
4530
4547
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4531
|
-
this.
|
|
4548
|
+
this.#preDrawUpdaters.push(updater);
|
|
4532
4549
|
}
|
|
4533
4550
|
}
|
|
4534
4551
|
}
|
|
4535
4552
|
paint() {
|
|
4536
4553
|
let handled = false;
|
|
4537
|
-
for (const plugin of this
|
|
4554
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4538
4555
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4539
4556
|
if (handled) {
|
|
4540
4557
|
break;
|
|
@@ -4547,35 +4564,35 @@
|
|
|
4547
4564
|
}
|
|
4548
4565
|
paintBase(baseColor) {
|
|
4549
4566
|
this.draw(ctx => {
|
|
4550
|
-
paintBase(ctx, this.
|
|
4567
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4551
4568
|
});
|
|
4552
4569
|
}
|
|
4553
4570
|
paintImage(image, opacity) {
|
|
4554
4571
|
this.draw(ctx => {
|
|
4555
|
-
paintImage(ctx, this.
|
|
4572
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4556
4573
|
});
|
|
4557
4574
|
}
|
|
4558
4575
|
setContext(context) {
|
|
4559
|
-
this
|
|
4560
|
-
if (this
|
|
4561
|
-
this.
|
|
4576
|
+
this.#context = context;
|
|
4577
|
+
if (this.#context) {
|
|
4578
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4562
4579
|
}
|
|
4563
4580
|
}
|
|
4564
4581
|
setContextSettings(settings) {
|
|
4565
|
-
this
|
|
4582
|
+
this.#contextSettings = settings;
|
|
4566
4583
|
}
|
|
4567
4584
|
stop() {
|
|
4568
4585
|
this.draw(ctx => {
|
|
4569
|
-
clear(ctx, this.
|
|
4586
|
+
clear(ctx, this.#canvasManager.size);
|
|
4570
4587
|
});
|
|
4571
4588
|
}
|
|
4572
|
-
|
|
4573
|
-
for (const updater of this
|
|
4589
|
+
#applyPostDrawUpdaters = particle => {
|
|
4590
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4574
4591
|
updater.afterDraw?.(particle);
|
|
4575
4592
|
}
|
|
4576
4593
|
};
|
|
4577
|
-
|
|
4578
|
-
for (const updater of this
|
|
4594
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4595
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4579
4596
|
if (updater.getColorStyles) {
|
|
4580
4597
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4581
4598
|
if (fill) {
|
|
@@ -4594,22 +4611,22 @@
|
|
|
4594
4611
|
updater.beforeDraw?.(particle);
|
|
4595
4612
|
}
|
|
4596
4613
|
};
|
|
4597
|
-
|
|
4614
|
+
#getPluginParticleColors = particle => {
|
|
4598
4615
|
let fColor, sColor;
|
|
4599
|
-
for (const plugin of this
|
|
4616
|
+
for (const plugin of this.#colorPlugins) {
|
|
4600
4617
|
if (!fColor && plugin.particleFillColor) {
|
|
4601
|
-
fColor = rangeColorToHsl(this
|
|
4618
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4602
4619
|
}
|
|
4603
4620
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4604
|
-
sColor = rangeColorToHsl(this
|
|
4621
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4605
4622
|
}
|
|
4606
4623
|
if (fColor && sColor) {
|
|
4607
4624
|
break;
|
|
4608
4625
|
}
|
|
4609
4626
|
}
|
|
4610
|
-
this
|
|
4611
|
-
this
|
|
4612
|
-
return this
|
|
4627
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4628
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4629
|
+
return this.#reusablePluginColors;
|
|
4613
4630
|
};
|
|
4614
4631
|
}
|
|
4615
4632
|
|
|
@@ -4667,53 +4684,53 @@
|
|
|
4667
4684
|
renderCanvas;
|
|
4668
4685
|
size;
|
|
4669
4686
|
zoom = defaultZoom;
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4687
|
+
#container;
|
|
4688
|
+
#generated;
|
|
4689
|
+
#mutationObserver;
|
|
4690
|
+
#originalStyle;
|
|
4691
|
+
#pluginManager;
|
|
4692
|
+
#pointerEvents;
|
|
4693
|
+
#resizePlugins;
|
|
4694
|
+
#standardSize;
|
|
4695
|
+
#zoomCenter;
|
|
4679
4696
|
constructor(pluginManager, container) {
|
|
4680
|
-
this
|
|
4681
|
-
this
|
|
4697
|
+
this.#pluginManager = pluginManager;
|
|
4698
|
+
this.#container = container;
|
|
4682
4699
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4683
|
-
this
|
|
4700
|
+
this.#standardSize = {
|
|
4684
4701
|
height: 0,
|
|
4685
4702
|
width: 0,
|
|
4686
4703
|
};
|
|
4687
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4704
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4688
4705
|
this.size = {
|
|
4689
4706
|
height: stdSize.height * pxRatio,
|
|
4690
4707
|
width: stdSize.width * pxRatio,
|
|
4691
4708
|
};
|
|
4692
|
-
this
|
|
4693
|
-
this
|
|
4694
|
-
this
|
|
4709
|
+
this.#generated = false;
|
|
4710
|
+
this.#resizePlugins = [];
|
|
4711
|
+
this.#pointerEvents = "none";
|
|
4695
4712
|
}
|
|
4696
|
-
get
|
|
4697
|
-
return this.
|
|
4713
|
+
get #fullScreen() {
|
|
4714
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4698
4715
|
}
|
|
4699
4716
|
destroy() {
|
|
4700
4717
|
this.stop();
|
|
4701
|
-
if (this
|
|
4718
|
+
if (this.#generated) {
|
|
4702
4719
|
const element = this.domElement;
|
|
4703
4720
|
element?.remove();
|
|
4704
4721
|
this.domElement = undefined;
|
|
4705
4722
|
this.renderCanvas = undefined;
|
|
4706
4723
|
}
|
|
4707
4724
|
else {
|
|
4708
|
-
this
|
|
4725
|
+
this.#resetOriginalStyle();
|
|
4709
4726
|
}
|
|
4710
4727
|
this.render.destroy();
|
|
4711
|
-
this
|
|
4728
|
+
this.#resizePlugins = [];
|
|
4712
4729
|
}
|
|
4713
4730
|
getZoomCenter() {
|
|
4714
|
-
const pxRatio = this.
|
|
4715
|
-
if (this
|
|
4716
|
-
return this
|
|
4731
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4732
|
+
if (this.#zoomCenter) {
|
|
4733
|
+
return this.#zoomCenter;
|
|
4717
4734
|
}
|
|
4718
4735
|
return {
|
|
4719
4736
|
x: (width * half) / pxRatio,
|
|
@@ -4721,20 +4738,20 @@
|
|
|
4721
4738
|
};
|
|
4722
4739
|
}
|
|
4723
4740
|
init() {
|
|
4724
|
-
this
|
|
4741
|
+
this.#safeMutationObserver(obs => {
|
|
4725
4742
|
obs.disconnect();
|
|
4726
4743
|
});
|
|
4727
|
-
this
|
|
4744
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4728
4745
|
for (const record of records) {
|
|
4729
4746
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4730
|
-
this
|
|
4747
|
+
this.#repairStyle();
|
|
4731
4748
|
}
|
|
4732
4749
|
}
|
|
4733
4750
|
});
|
|
4734
4751
|
this.resize();
|
|
4735
|
-
this
|
|
4752
|
+
this.#initStyle();
|
|
4736
4753
|
this.initBackground();
|
|
4737
|
-
this
|
|
4754
|
+
this.#safeMutationObserver(obs => {
|
|
4738
4755
|
const element = this.domElement;
|
|
4739
4756
|
if (!element || !(element instanceof Node)) {
|
|
4740
4757
|
return;
|
|
@@ -4745,13 +4762,13 @@
|
|
|
4745
4762
|
this.render.init();
|
|
4746
4763
|
}
|
|
4747
4764
|
initBackground() {
|
|
4748
|
-
const
|
|
4765
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4749
4766
|
if (!element) {
|
|
4750
4767
|
return;
|
|
4751
4768
|
}
|
|
4752
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4769
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4753
4770
|
if (color) {
|
|
4754
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4771
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4755
4772
|
}
|
|
4756
4773
|
else {
|
|
4757
4774
|
elementStyle.backgroundColor = "";
|
|
@@ -4762,27 +4779,27 @@
|
|
|
4762
4779
|
elementStyle.backgroundSize = background.size || "";
|
|
4763
4780
|
}
|
|
4764
4781
|
initPlugins() {
|
|
4765
|
-
this
|
|
4766
|
-
for (const plugin of this.
|
|
4782
|
+
this.#resizePlugins = [];
|
|
4783
|
+
for (const plugin of this.#container.plugins) {
|
|
4767
4784
|
if (plugin.resize) {
|
|
4768
|
-
this.
|
|
4785
|
+
this.#resizePlugins.push(plugin);
|
|
4769
4786
|
}
|
|
4770
4787
|
}
|
|
4771
4788
|
}
|
|
4772
4789
|
loadCanvas(canvas) {
|
|
4773
|
-
if (this
|
|
4790
|
+
if (this.#generated && this.domElement) {
|
|
4774
4791
|
this.domElement.remove();
|
|
4775
4792
|
}
|
|
4776
|
-
const container = this
|
|
4793
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4777
4794
|
this.domElement = domCanvas;
|
|
4778
|
-
this
|
|
4795
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4779
4796
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4780
4797
|
const domElement = this.domElement;
|
|
4781
4798
|
if (domElement) {
|
|
4782
4799
|
domElement.ariaHidden = "true";
|
|
4783
|
-
this
|
|
4800
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4784
4801
|
}
|
|
4785
|
-
const standardSize = this
|
|
4802
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4786
4803
|
if (domElement) {
|
|
4787
4804
|
standardSize.height = domElement.offsetHeight;
|
|
4788
4805
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4791,7 +4808,7 @@
|
|
|
4791
4808
|
standardSize.height = renderCanvas.height;
|
|
4792
4809
|
standardSize.width = renderCanvas.width;
|
|
4793
4810
|
}
|
|
4794
|
-
const pxRatio = this.
|
|
4811
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4795
4812
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4796
4813
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4797
4814
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4802,12 +4819,12 @@
|
|
|
4802
4819
|
willReadFrequently: false,
|
|
4803
4820
|
});
|
|
4804
4821
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4805
|
-
this
|
|
4822
|
+
this.#safeMutationObserver(obs => {
|
|
4806
4823
|
obs.disconnect();
|
|
4807
4824
|
});
|
|
4808
4825
|
container.retina.init();
|
|
4809
4826
|
this.initBackground();
|
|
4810
|
-
this
|
|
4827
|
+
this.#safeMutationObserver(obs => {
|
|
4811
4828
|
const element = this.domElement;
|
|
4812
4829
|
if (!element || !(element instanceof Node)) {
|
|
4813
4830
|
return;
|
|
@@ -4820,11 +4837,11 @@
|
|
|
4820
4837
|
if (!element) {
|
|
4821
4838
|
return false;
|
|
4822
4839
|
}
|
|
4823
|
-
const container = this
|
|
4840
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4824
4841
|
if (renderCanvas === undefined) {
|
|
4825
4842
|
return false;
|
|
4826
4843
|
}
|
|
4827
|
-
const currentSize = container.canvas
|
|
4844
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4828
4845
|
width: element.offsetWidth,
|
|
4829
4846
|
height: element.offsetHeight,
|
|
4830
4847
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4843,7 +4860,7 @@
|
|
|
4843
4860
|
const canvasSize = this.size;
|
|
4844
4861
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4845
4862
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4846
|
-
if (this.
|
|
4863
|
+
if (this.#container.started) {
|
|
4847
4864
|
container.particles.setResizeFactor({
|
|
4848
4865
|
width: currentSize.width / oldSize.width,
|
|
4849
4866
|
height: currentSize.height / oldSize.height,
|
|
@@ -4856,46 +4873,46 @@
|
|
|
4856
4873
|
if (!element) {
|
|
4857
4874
|
return;
|
|
4858
4875
|
}
|
|
4859
|
-
this
|
|
4860
|
-
this
|
|
4876
|
+
this.#pointerEvents = type;
|
|
4877
|
+
this.#repairStyle();
|
|
4861
4878
|
}
|
|
4862
4879
|
setZoom(zoomLevel, center) {
|
|
4863
4880
|
this.zoom = zoomLevel;
|
|
4864
|
-
this
|
|
4881
|
+
this.#zoomCenter = center;
|
|
4865
4882
|
}
|
|
4866
4883
|
stop() {
|
|
4867
|
-
this
|
|
4884
|
+
this.#safeMutationObserver(obs => {
|
|
4868
4885
|
obs.disconnect();
|
|
4869
4886
|
});
|
|
4870
|
-
this
|
|
4887
|
+
this.#mutationObserver = undefined;
|
|
4871
4888
|
this.render.stop();
|
|
4872
4889
|
}
|
|
4873
4890
|
async windowResize() {
|
|
4874
4891
|
if (!this.domElement || !this.resize()) {
|
|
4875
4892
|
return;
|
|
4876
4893
|
}
|
|
4877
|
-
const container = this
|
|
4894
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4878
4895
|
container.particles.setDensity();
|
|
4879
|
-
this
|
|
4896
|
+
this.#applyResizePlugins();
|
|
4880
4897
|
if (needsRefresh) {
|
|
4881
4898
|
await container.refresh();
|
|
4882
4899
|
}
|
|
4883
4900
|
}
|
|
4884
|
-
|
|
4885
|
-
for (const plugin of this
|
|
4901
|
+
#applyResizePlugins = () => {
|
|
4902
|
+
for (const plugin of this.#resizePlugins) {
|
|
4886
4903
|
plugin.resize?.();
|
|
4887
4904
|
}
|
|
4888
4905
|
};
|
|
4889
|
-
|
|
4890
|
-
const element = this.domElement, options = this.
|
|
4906
|
+
#initStyle = () => {
|
|
4907
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4891
4908
|
if (!element) {
|
|
4892
4909
|
return;
|
|
4893
4910
|
}
|
|
4894
|
-
if (this
|
|
4895
|
-
this
|
|
4911
|
+
if (this.#fullScreen) {
|
|
4912
|
+
this.#setFullScreenStyle();
|
|
4896
4913
|
}
|
|
4897
4914
|
else {
|
|
4898
|
-
this
|
|
4915
|
+
this.#resetOriginalStyle();
|
|
4899
4916
|
}
|
|
4900
4917
|
for (const key in options.style) {
|
|
4901
4918
|
if (!key || !(key in options.style)) {
|
|
@@ -4908,72 +4925,72 @@
|
|
|
4908
4925
|
element.style.setProperty(key, value, "important");
|
|
4909
4926
|
}
|
|
4910
4927
|
};
|
|
4911
|
-
|
|
4928
|
+
#repairStyle = () => {
|
|
4912
4929
|
const element = this.domElement;
|
|
4913
4930
|
if (!element) {
|
|
4914
4931
|
return;
|
|
4915
4932
|
}
|
|
4916
|
-
this
|
|
4933
|
+
this.#safeMutationObserver(observer => {
|
|
4917
4934
|
observer.disconnect();
|
|
4918
4935
|
});
|
|
4919
|
-
this
|
|
4936
|
+
this.#initStyle();
|
|
4920
4937
|
this.initBackground();
|
|
4921
|
-
const pointerEvents = this
|
|
4938
|
+
const pointerEvents = this.#pointerEvents;
|
|
4922
4939
|
element.style.pointerEvents = pointerEvents;
|
|
4923
4940
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4924
|
-
this
|
|
4941
|
+
this.#safeMutationObserver(observer => {
|
|
4925
4942
|
if (!(element instanceof Node)) {
|
|
4926
4943
|
return;
|
|
4927
4944
|
}
|
|
4928
4945
|
observer.observe(element, { attributes: true });
|
|
4929
4946
|
});
|
|
4930
4947
|
};
|
|
4931
|
-
|
|
4932
|
-
const element = this.domElement, originalStyle = this
|
|
4948
|
+
#resetOriginalStyle = () => {
|
|
4949
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4933
4950
|
if (!element || !originalStyle) {
|
|
4934
4951
|
return;
|
|
4935
4952
|
}
|
|
4936
4953
|
setStyle(element, originalStyle, true);
|
|
4937
4954
|
};
|
|
4938
|
-
|
|
4939
|
-
if (!this
|
|
4955
|
+
#safeMutationObserver = callback => {
|
|
4956
|
+
if (!this.#mutationObserver) {
|
|
4940
4957
|
return;
|
|
4941
4958
|
}
|
|
4942
|
-
callback(this
|
|
4959
|
+
callback(this.#mutationObserver);
|
|
4943
4960
|
};
|
|
4944
|
-
|
|
4961
|
+
#setFullScreenStyle = () => {
|
|
4945
4962
|
const element = this.domElement;
|
|
4946
4963
|
if (!element) {
|
|
4947
4964
|
return;
|
|
4948
4965
|
}
|
|
4949
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4966
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4950
4967
|
};
|
|
4951
4968
|
}
|
|
4952
4969
|
|
|
4953
4970
|
class EventListeners {
|
|
4954
|
-
container;
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4971
|
+
#container;
|
|
4972
|
+
#handlers;
|
|
4973
|
+
#resizeObserver;
|
|
4974
|
+
#resizeTimeout;
|
|
4958
4975
|
constructor(container) {
|
|
4959
|
-
this
|
|
4960
|
-
this
|
|
4976
|
+
this.#container = container;
|
|
4977
|
+
this.#handlers = {
|
|
4961
4978
|
visibilityChange: () => {
|
|
4962
|
-
this
|
|
4979
|
+
this.#handleVisibilityChange();
|
|
4963
4980
|
},
|
|
4964
4981
|
resize: () => {
|
|
4965
|
-
this
|
|
4982
|
+
this.#handleWindowResize();
|
|
4966
4983
|
},
|
|
4967
4984
|
};
|
|
4968
4985
|
}
|
|
4969
4986
|
addListeners() {
|
|
4970
|
-
this
|
|
4987
|
+
this.#manageListeners(true);
|
|
4971
4988
|
}
|
|
4972
4989
|
removeListeners() {
|
|
4973
|
-
this
|
|
4990
|
+
this.#manageListeners(false);
|
|
4974
4991
|
}
|
|
4975
|
-
|
|
4976
|
-
const container = this
|
|
4992
|
+
#handleVisibilityChange = () => {
|
|
4993
|
+
const container = this.#container, options = container.actualOptions;
|
|
4977
4994
|
if (!options.pauseOnBlur) {
|
|
4978
4995
|
return;
|
|
4979
4996
|
}
|
|
@@ -4991,24 +5008,24 @@
|
|
|
4991
5008
|
}
|
|
4992
5009
|
}
|
|
4993
5010
|
};
|
|
4994
|
-
|
|
4995
|
-
if (this
|
|
4996
|
-
clearTimeout(this
|
|
4997
|
-
|
|
5011
|
+
#handleWindowResize = () => {
|
|
5012
|
+
if (this.#resizeTimeout) {
|
|
5013
|
+
clearTimeout(this.#resizeTimeout);
|
|
5014
|
+
this.#resizeTimeout = undefined;
|
|
4998
5015
|
}
|
|
4999
5016
|
const handleResize = async () => {
|
|
5000
|
-
const canvas = this
|
|
5017
|
+
const canvas = this.#container.canvas;
|
|
5001
5018
|
await canvas.windowResize();
|
|
5002
5019
|
};
|
|
5003
|
-
this
|
|
5020
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5004
5021
|
};
|
|
5005
|
-
|
|
5006
|
-
const handlers = this
|
|
5007
|
-
this
|
|
5022
|
+
#manageListeners = add => {
|
|
5023
|
+
const handlers = this.#handlers;
|
|
5024
|
+
this.#manageResize(add);
|
|
5008
5025
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5009
5026
|
};
|
|
5010
|
-
|
|
5011
|
-
const handlers = this
|
|
5027
|
+
#manageResize = add => {
|
|
5028
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5012
5029
|
if (!options.resize.enable) {
|
|
5013
5030
|
return;
|
|
5014
5031
|
}
|
|
@@ -5017,22 +5034,22 @@
|
|
|
5017
5034
|
return;
|
|
5018
5035
|
}
|
|
5019
5036
|
const canvasEl = container.canvas.domElement;
|
|
5020
|
-
if (this
|
|
5037
|
+
if (this.#resizeObserver && !add) {
|
|
5021
5038
|
if (canvasEl) {
|
|
5022
|
-
this.
|
|
5039
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5023
5040
|
}
|
|
5024
|
-
this.
|
|
5025
|
-
|
|
5041
|
+
this.#resizeObserver.disconnect();
|
|
5042
|
+
this.#resizeObserver = undefined;
|
|
5026
5043
|
}
|
|
5027
|
-
else if (!this
|
|
5028
|
-
this
|
|
5044
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5045
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5029
5046
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5030
5047
|
if (!entry) {
|
|
5031
5048
|
return;
|
|
5032
5049
|
}
|
|
5033
|
-
this
|
|
5050
|
+
this.#handleWindowResize();
|
|
5034
5051
|
});
|
|
5035
|
-
this.
|
|
5052
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5036
5053
|
}
|
|
5037
5054
|
};
|
|
5038
5055
|
}
|
|
@@ -5105,24 +5122,24 @@
|
|
|
5105
5122
|
unbreakable;
|
|
5106
5123
|
velocity;
|
|
5107
5124
|
zIndexFactor;
|
|
5108
|
-
|
|
5125
|
+
#cachedOpacityData = {
|
|
5109
5126
|
fillOpacity: defaultOpacity$1,
|
|
5110
5127
|
opacity: defaultOpacity$1,
|
|
5111
5128
|
strokeOpacity: defaultOpacity$1,
|
|
5112
5129
|
};
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5130
|
+
#cachedPosition = Vector3d.origin;
|
|
5131
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5132
|
+
#cachedTransform = {
|
|
5116
5133
|
a: 1,
|
|
5117
5134
|
b: 0,
|
|
5118
5135
|
c: 0,
|
|
5119
5136
|
d: 1,
|
|
5120
5137
|
};
|
|
5121
|
-
|
|
5122
|
-
|
|
5138
|
+
#container;
|
|
5139
|
+
#pluginManager;
|
|
5123
5140
|
constructor(pluginManager, container) {
|
|
5124
|
-
this
|
|
5125
|
-
this
|
|
5141
|
+
this.#pluginManager = pluginManager;
|
|
5142
|
+
this.#container = container;
|
|
5126
5143
|
}
|
|
5127
5144
|
destroy(override) {
|
|
5128
5145
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5131,7 +5148,7 @@
|
|
|
5131
5148
|
this.destroyed = true;
|
|
5132
5149
|
this.bubble.inRange = false;
|
|
5133
5150
|
this.slow.inRange = false;
|
|
5134
|
-
const container = this
|
|
5151
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5135
5152
|
shapeDrawer?.particleDestroy?.(this);
|
|
5136
5153
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5137
5154
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5139,12 +5156,12 @@
|
|
|
5139
5156
|
for (const updater of container.particleUpdaters) {
|
|
5140
5157
|
updater.particleDestroyed?.(this, override);
|
|
5141
5158
|
}
|
|
5142
|
-
this.
|
|
5159
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5143
5160
|
particle: this,
|
|
5144
5161
|
});
|
|
5145
5162
|
}
|
|
5146
5163
|
draw(delta) {
|
|
5147
|
-
const container = this
|
|
5164
|
+
const container = this.#container, render = container.canvas.render;
|
|
5148
5165
|
render.drawParticlePlugins(this, delta);
|
|
5149
5166
|
render.drawParticle(this, delta);
|
|
5150
5167
|
}
|
|
@@ -5152,50 +5169,50 @@
|
|
|
5152
5169
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5153
5170
|
}
|
|
5154
5171
|
getFillColor() {
|
|
5155
|
-
return this
|
|
5172
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5156
5173
|
}
|
|
5157
5174
|
getMass() {
|
|
5158
5175
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5159
5176
|
}
|
|
5160
5177
|
getOpacity() {
|
|
5161
5178
|
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;
|
|
5162
|
-
this.
|
|
5163
|
-
this.
|
|
5164
|
-
this.
|
|
5165
|
-
return this
|
|
5179
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5180
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5181
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5182
|
+
return this.#cachedOpacityData;
|
|
5166
5183
|
}
|
|
5167
5184
|
getPosition() {
|
|
5168
|
-
this.
|
|
5169
|
-
this.
|
|
5170
|
-
this.
|
|
5171
|
-
return this
|
|
5185
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5186
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5187
|
+
this.#cachedPosition.z = this.position.z;
|
|
5188
|
+
return this.#cachedPosition;
|
|
5172
5189
|
}
|
|
5173
5190
|
getRadius() {
|
|
5174
5191
|
return this.bubble.radius ?? this.size.value;
|
|
5175
5192
|
}
|
|
5176
5193
|
getRotateData() {
|
|
5177
5194
|
const angle = this.getAngle();
|
|
5178
|
-
this.
|
|
5179
|
-
this.
|
|
5180
|
-
return this
|
|
5195
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5196
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5197
|
+
return this.#cachedRotateData;
|
|
5181
5198
|
}
|
|
5182
5199
|
getStrokeColor() {
|
|
5183
|
-
return this
|
|
5200
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5184
5201
|
}
|
|
5185
5202
|
getTransformData(externalTransform) {
|
|
5186
5203
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5187
|
-
this.
|
|
5188
|
-
this.
|
|
5204
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5205
|
+
this.#cachedTransform.b = rotating
|
|
5189
5206
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
5190
5207
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5191
|
-
this.
|
|
5208
|
+
this.#cachedTransform.c = rotating
|
|
5192
5209
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
5193
5210
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5194
|
-
this.
|
|
5195
|
-
return this
|
|
5211
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5212
|
+
return this.#cachedTransform;
|
|
5196
5213
|
}
|
|
5197
5214
|
init(id, position, overrideOptions, group) {
|
|
5198
|
-
const container = this
|
|
5215
|
+
const container = this.#container;
|
|
5199
5216
|
this.id = id;
|
|
5200
5217
|
this.group = group;
|
|
5201
5218
|
this.justWarped = false;
|
|
@@ -5215,21 +5232,27 @@
|
|
|
5215
5232
|
moveSpeed: 0,
|
|
5216
5233
|
sizeAnimationSpeed: 0,
|
|
5217
5234
|
};
|
|
5235
|
+
this.size = {
|
|
5236
|
+
value: 1,
|
|
5237
|
+
max: 1,
|
|
5238
|
+
min: 1,
|
|
5239
|
+
enable: false,
|
|
5240
|
+
};
|
|
5218
5241
|
this.outType = ParticleOutType.normal;
|
|
5219
5242
|
this.ignoresResizeRatio = true;
|
|
5220
|
-
const
|
|
5243
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5221
5244
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5222
5245
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5223
5246
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5224
5247
|
if (overrideOptions) {
|
|
5225
|
-
if (overrideOptions.effect?.type) {
|
|
5248
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5226
5249
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5227
5250
|
if (effect) {
|
|
5228
5251
|
this.effect = effect;
|
|
5229
5252
|
effectOptions.load(overrideOptions.effect);
|
|
5230
5253
|
}
|
|
5231
5254
|
}
|
|
5232
|
-
if (overrideOptions.shape?.type) {
|
|
5255
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5233
5256
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5234
5257
|
if (shape) {
|
|
5235
5258
|
this.shape = shape;
|
|
@@ -5238,21 +5261,20 @@
|
|
|
5238
5261
|
}
|
|
5239
5262
|
}
|
|
5240
5263
|
if (this.effect === randomColorValue) {
|
|
5241
|
-
const availableEffects = [...this.
|
|
5264
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5242
5265
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5243
5266
|
}
|
|
5244
5267
|
if (this.shape === randomColorValue) {
|
|
5245
|
-
const availableShapes = [...this.
|
|
5268
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5246
5269
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5247
5270
|
}
|
|
5248
5271
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5249
5272
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5250
5273
|
particlesOptions.load(overrideOptions);
|
|
5251
|
-
const effectData = this.effectData;
|
|
5274
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5252
5275
|
if (effectData) {
|
|
5253
5276
|
particlesOptions.load(effectData.particles);
|
|
5254
5277
|
}
|
|
5255
|
-
const shapeData = this.shapeData;
|
|
5256
5278
|
if (shapeData) {
|
|
5257
5279
|
particlesOptions.load(shapeData.particles);
|
|
5258
5280
|
}
|
|
@@ -5260,7 +5282,9 @@
|
|
|
5260
5282
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5261
5283
|
this.options = particlesOptions;
|
|
5262
5284
|
container.retina.initParticle(this);
|
|
5263
|
-
|
|
5285
|
+
for (const updater of container.particleUpdaters) {
|
|
5286
|
+
updater.preInit?.(this);
|
|
5287
|
+
}
|
|
5264
5288
|
this.bubble = {
|
|
5265
5289
|
inRange: false,
|
|
5266
5290
|
};
|
|
@@ -5268,8 +5292,8 @@
|
|
|
5268
5292
|
inRange: false,
|
|
5269
5293
|
factor: 1,
|
|
5270
5294
|
};
|
|
5271
|
-
this
|
|
5272
|
-
this.initialVelocity = this
|
|
5295
|
+
this.#initPosition(position);
|
|
5296
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5273
5297
|
this.velocity = this.initialVelocity.copy();
|
|
5274
5298
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5275
5299
|
this.sides = 24;
|
|
@@ -5300,12 +5324,11 @@
|
|
|
5300
5324
|
plugin.particleCreated?.(this);
|
|
5301
5325
|
}
|
|
5302
5326
|
}
|
|
5303
|
-
isInsideCanvas() {
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
position.x <= canvasSize.width + radius);
|
|
5327
|
+
isInsideCanvas(direction) {
|
|
5328
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5329
|
+
}
|
|
5330
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5331
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5309
5332
|
}
|
|
5310
5333
|
isShowingBack() {
|
|
5311
5334
|
if (!this.roll) {
|
|
@@ -5330,13 +5353,13 @@
|
|
|
5330
5353
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5331
5354
|
}
|
|
5332
5355
|
reset() {
|
|
5333
|
-
for (const updater of this.
|
|
5356
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5334
5357
|
updater.reset?.(this);
|
|
5335
5358
|
}
|
|
5336
5359
|
}
|
|
5337
|
-
|
|
5360
|
+
#calcPosition = (position, zIndex) => {
|
|
5338
5361
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5339
|
-
const container = this
|
|
5362
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5340
5363
|
while (!signal.aborted) {
|
|
5341
5364
|
for (const plugin of plugins) {
|
|
5342
5365
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5348,10 +5371,10 @@
|
|
|
5348
5371
|
size: canvasSize,
|
|
5349
5372
|
position: posVec,
|
|
5350
5373
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5351
|
-
this
|
|
5352
|
-
this
|
|
5353
|
-
this
|
|
5354
|
-
this
|
|
5374
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5375
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5376
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5377
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5355
5378
|
let isValidPosition = true;
|
|
5356
5379
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5357
5380
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5367,8 +5390,8 @@
|
|
|
5367
5390
|
}
|
|
5368
5391
|
return posVec;
|
|
5369
5392
|
};
|
|
5370
|
-
|
|
5371
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5393
|
+
#calculateVelocity = () => {
|
|
5394
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5372
5395
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5373
5396
|
return res;
|
|
5374
5397
|
}
|
|
@@ -5384,27 +5407,86 @@
|
|
|
5384
5407
|
}
|
|
5385
5408
|
return res;
|
|
5386
5409
|
};
|
|
5387
|
-
|
|
5410
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5388
5411
|
fixOutMode({
|
|
5389
5412
|
outMode,
|
|
5390
5413
|
checkModes: [OutMode.bounce],
|
|
5391
5414
|
coord: pos.x,
|
|
5392
|
-
maxCoord: this.
|
|
5415
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5393
5416
|
setCb: (value) => (pos.x += value),
|
|
5394
5417
|
radius,
|
|
5395
5418
|
});
|
|
5396
5419
|
};
|
|
5397
|
-
|
|
5420
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5398
5421
|
fixOutMode({
|
|
5399
5422
|
outMode,
|
|
5400
5423
|
checkModes: [OutMode.bounce],
|
|
5401
5424
|
coord: pos.y,
|
|
5402
|
-
maxCoord: this.
|
|
5425
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5403
5426
|
setCb: (value) => (pos.y += value),
|
|
5404
5427
|
radius,
|
|
5405
5428
|
});
|
|
5406
5429
|
};
|
|
5407
|
-
|
|
5430
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5431
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5432
|
+
if (direction === OutModeDirection.bottom) {
|
|
5433
|
+
return {
|
|
5434
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5435
|
+
reason: "default",
|
|
5436
|
+
};
|
|
5437
|
+
}
|
|
5438
|
+
if (direction === OutModeDirection.left) {
|
|
5439
|
+
return {
|
|
5440
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5441
|
+
reason: "default",
|
|
5442
|
+
};
|
|
5443
|
+
}
|
|
5444
|
+
if (direction === OutModeDirection.right) {
|
|
5445
|
+
return {
|
|
5446
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5447
|
+
reason: "default",
|
|
5448
|
+
};
|
|
5449
|
+
}
|
|
5450
|
+
if (direction === OutModeDirection.top) {
|
|
5451
|
+
return {
|
|
5452
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5453
|
+
reason: "default",
|
|
5454
|
+
};
|
|
5455
|
+
}
|
|
5456
|
+
return {
|
|
5457
|
+
inside: position.x >= -radius &&
|
|
5458
|
+
position.y >= -radius &&
|
|
5459
|
+
position.y <= canvasSize.height + radius &&
|
|
5460
|
+
position.x <= canvasSize.width + radius,
|
|
5461
|
+
reason: "default",
|
|
5462
|
+
};
|
|
5463
|
+
};
|
|
5464
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5465
|
+
return {
|
|
5466
|
+
canvasSize: this.#container.canvas.size,
|
|
5467
|
+
direction,
|
|
5468
|
+
outMode,
|
|
5469
|
+
particle: this,
|
|
5470
|
+
radius: this.getRadius(),
|
|
5471
|
+
};
|
|
5472
|
+
};
|
|
5473
|
+
#getInsideCanvasResult = (data) => {
|
|
5474
|
+
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;
|
|
5475
|
+
if (!shapeCheck && !effectCheck) {
|
|
5476
|
+
return defaultResult;
|
|
5477
|
+
}
|
|
5478
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5479
|
+
if (shapeResult && effectResult) {
|
|
5480
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5481
|
+
return {
|
|
5482
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5483
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5484
|
+
reason: "combined",
|
|
5485
|
+
};
|
|
5486
|
+
}
|
|
5487
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5488
|
+
};
|
|
5489
|
+
#getRollColor = color => {
|
|
5408
5490
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5409
5491
|
return color;
|
|
5410
5492
|
}
|
|
@@ -5419,8 +5501,8 @@
|
|
|
5419
5501
|
}
|
|
5420
5502
|
return color;
|
|
5421
5503
|
};
|
|
5422
|
-
|
|
5423
|
-
const container = this
|
|
5504
|
+
#initPosition = position => {
|
|
5505
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5424
5506
|
if (!initialPosition) {
|
|
5425
5507
|
throw new Error("a valid position cannot be found for particle");
|
|
5426
5508
|
}
|
|
@@ -5443,45 +5525,58 @@
|
|
|
5443
5525
|
}
|
|
5444
5526
|
this.offset = Vector.origin;
|
|
5445
5527
|
};
|
|
5528
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5529
|
+
if (typeof result === "boolean") {
|
|
5530
|
+
return {
|
|
5531
|
+
inside: result,
|
|
5532
|
+
reason,
|
|
5533
|
+
};
|
|
5534
|
+
}
|
|
5535
|
+
return {
|
|
5536
|
+
inside: result.inside,
|
|
5537
|
+
margin: result.margin,
|
|
5538
|
+
reason: result.reason ?? reason,
|
|
5539
|
+
};
|
|
5540
|
+
};
|
|
5446
5541
|
}
|
|
5447
5542
|
|
|
5448
5543
|
class SpatialHashGrid {
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5544
|
+
#cellSize;
|
|
5545
|
+
#cells = new Map();
|
|
5546
|
+
#circlePool = [];
|
|
5547
|
+
#circlePoolIdx;
|
|
5548
|
+
#pendingCellSize;
|
|
5549
|
+
#rectanglePool = [];
|
|
5550
|
+
#rectanglePoolIdx;
|
|
5456
5551
|
constructor(cellSize) {
|
|
5457
|
-
this
|
|
5458
|
-
this
|
|
5459
|
-
this
|
|
5552
|
+
this.#cellSize = cellSize;
|
|
5553
|
+
this.#circlePoolIdx = 0;
|
|
5554
|
+
this.#rectanglePoolIdx = 0;
|
|
5460
5555
|
}
|
|
5461
5556
|
clear() {
|
|
5462
|
-
this.
|
|
5463
|
-
const pendingCellSize = this
|
|
5557
|
+
this.#cells.clear();
|
|
5558
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5464
5559
|
if (pendingCellSize) {
|
|
5465
|
-
this
|
|
5560
|
+
this.#cellSize = pendingCellSize;
|
|
5466
5561
|
}
|
|
5467
|
-
this
|
|
5562
|
+
this.#pendingCellSize = undefined;
|
|
5468
5563
|
}
|
|
5469
5564
|
insert(particle) {
|
|
5470
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5471
|
-
if (!this.
|
|
5472
|
-
this.
|
|
5565
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5566
|
+
if (!this.#cells.has(key)) {
|
|
5567
|
+
this.#cells.set(key, []);
|
|
5473
5568
|
}
|
|
5474
|
-
this.
|
|
5569
|
+
this.#cells.get(key)?.push(particle);
|
|
5475
5570
|
}
|
|
5476
5571
|
query(range, check, out = []) {
|
|
5477
|
-
const bounds = this
|
|
5572
|
+
const bounds = this.#getRangeBounds(range);
|
|
5478
5573
|
if (!bounds) {
|
|
5479
5574
|
return out;
|
|
5480
5575
|
}
|
|
5481
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5576
|
+
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);
|
|
5482
5577
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5483
5578
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5484
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5579
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5485
5580
|
if (!cellParticles) {
|
|
5486
5581
|
continue;
|
|
5487
5582
|
}
|
|
@@ -5498,29 +5593,29 @@
|
|
|
5498
5593
|
return out;
|
|
5499
5594
|
}
|
|
5500
5595
|
queryCircle(position, radius, check, out = []) {
|
|
5501
|
-
const circle = this
|
|
5502
|
-
this
|
|
5596
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5597
|
+
this.#releaseShapes();
|
|
5503
5598
|
return result;
|
|
5504
5599
|
}
|
|
5505
5600
|
queryRectangle(position, size, check, out = []) {
|
|
5506
|
-
const rect = this
|
|
5507
|
-
this
|
|
5601
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5602
|
+
this.#releaseShapes();
|
|
5508
5603
|
return result;
|
|
5509
5604
|
}
|
|
5510
5605
|
setCellSize(cellSize) {
|
|
5511
|
-
this
|
|
5606
|
+
this.#pendingCellSize = cellSize;
|
|
5512
5607
|
}
|
|
5513
|
-
|
|
5514
|
-
return (this
|
|
5608
|
+
#acquireCircle(x, y, r) {
|
|
5609
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5515
5610
|
}
|
|
5516
|
-
|
|
5517
|
-
return (this
|
|
5611
|
+
#acquireRectangle(x, y, w, h) {
|
|
5612
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5518
5613
|
}
|
|
5519
|
-
|
|
5520
|
-
const cellX = Math.floor(x / this
|
|
5614
|
+
#cellKeyFromCoords(x, y) {
|
|
5615
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5521
5616
|
return `${cellX}_${cellY}`;
|
|
5522
5617
|
}
|
|
5523
|
-
|
|
5618
|
+
#getRangeBounds(range) {
|
|
5524
5619
|
if (range instanceof Circle) {
|
|
5525
5620
|
const r = range.radius, { x, y } = range.position;
|
|
5526
5621
|
return {
|
|
@@ -5541,53 +5636,53 @@
|
|
|
5541
5636
|
}
|
|
5542
5637
|
return null;
|
|
5543
5638
|
}
|
|
5544
|
-
|
|
5545
|
-
this
|
|
5546
|
-
this
|
|
5639
|
+
#releaseShapes() {
|
|
5640
|
+
this.#circlePoolIdx = 0;
|
|
5641
|
+
this.#rectanglePoolIdx = 0;
|
|
5547
5642
|
}
|
|
5548
5643
|
}
|
|
5549
5644
|
|
|
5550
5645
|
class ParticlesManager {
|
|
5551
5646
|
checkParticlePositionPlugins;
|
|
5552
5647
|
grid;
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5648
|
+
#array;
|
|
5649
|
+
#container;
|
|
5650
|
+
#groupLimits;
|
|
5651
|
+
#limit;
|
|
5652
|
+
#nextId;
|
|
5653
|
+
#particleBuckets;
|
|
5654
|
+
#particleResetPlugins;
|
|
5655
|
+
#particleUpdatePlugins;
|
|
5656
|
+
#pluginManager;
|
|
5657
|
+
#pool;
|
|
5658
|
+
#postParticleUpdatePlugins;
|
|
5659
|
+
#postUpdatePlugins;
|
|
5660
|
+
#resizeFactor;
|
|
5661
|
+
#updatePlugins;
|
|
5662
|
+
#zBuckets;
|
|
5568
5663
|
constructor(pluginManager, container) {
|
|
5569
|
-
this
|
|
5570
|
-
this
|
|
5571
|
-
this
|
|
5572
|
-
this
|
|
5573
|
-
this
|
|
5574
|
-
this
|
|
5575
|
-
this
|
|
5576
|
-
this
|
|
5577
|
-
this
|
|
5664
|
+
this.#pluginManager = pluginManager;
|
|
5665
|
+
this.#container = container;
|
|
5666
|
+
this.#nextId = 0;
|
|
5667
|
+
this.#array = [];
|
|
5668
|
+
this.#pool = [];
|
|
5669
|
+
this.#limit = 0;
|
|
5670
|
+
this.#groupLimits = new Map();
|
|
5671
|
+
this.#particleBuckets = new Map();
|
|
5672
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5578
5673
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5579
5674
|
this.checkParticlePositionPlugins = [];
|
|
5580
|
-
this
|
|
5581
|
-
this
|
|
5582
|
-
this
|
|
5583
|
-
this
|
|
5584
|
-
this
|
|
5675
|
+
this.#particleResetPlugins = [];
|
|
5676
|
+
this.#particleUpdatePlugins = [];
|
|
5677
|
+
this.#postUpdatePlugins = [];
|
|
5678
|
+
this.#postParticleUpdatePlugins = [];
|
|
5679
|
+
this.#updatePlugins = [];
|
|
5585
5680
|
}
|
|
5586
5681
|
get count() {
|
|
5587
|
-
return this.
|
|
5682
|
+
return this.#array.length;
|
|
5588
5683
|
}
|
|
5589
5684
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5590
|
-
const limitMode = this.
|
|
5685
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5591
5686
|
if (limit > minLimit) {
|
|
5592
5687
|
switch (limitMode) {
|
|
5593
5688
|
case LimitMode.delete: {
|
|
@@ -5605,20 +5700,20 @@
|
|
|
5605
5700
|
}
|
|
5606
5701
|
}
|
|
5607
5702
|
try {
|
|
5608
|
-
const particle = this.
|
|
5609
|
-
particle.init(this
|
|
5703
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5704
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5610
5705
|
let canAdd = true;
|
|
5611
5706
|
if (initializer) {
|
|
5612
5707
|
canAdd = initializer(particle);
|
|
5613
5708
|
}
|
|
5614
5709
|
if (!canAdd) {
|
|
5615
|
-
this.
|
|
5710
|
+
this.#pool.push(particle);
|
|
5616
5711
|
return;
|
|
5617
5712
|
}
|
|
5618
|
-
this.
|
|
5619
|
-
this
|
|
5620
|
-
this
|
|
5621
|
-
this.
|
|
5713
|
+
this.#array.push(particle);
|
|
5714
|
+
this.#insertParticleIntoBucket(particle);
|
|
5715
|
+
this.#nextId++;
|
|
5716
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5622
5717
|
particle,
|
|
5623
5718
|
});
|
|
5624
5719
|
return particle;
|
|
@@ -5629,25 +5724,25 @@
|
|
|
5629
5724
|
return undefined;
|
|
5630
5725
|
}
|
|
5631
5726
|
clear() {
|
|
5632
|
-
this
|
|
5633
|
-
this.
|
|
5634
|
-
this
|
|
5727
|
+
this.#array = [];
|
|
5728
|
+
this.#particleBuckets.clear();
|
|
5729
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5635
5730
|
}
|
|
5636
5731
|
destroy() {
|
|
5637
|
-
this
|
|
5638
|
-
this.
|
|
5639
|
-
this.
|
|
5640
|
-
this
|
|
5732
|
+
this.#array = [];
|
|
5733
|
+
this.#pool.length = 0;
|
|
5734
|
+
this.#particleBuckets.clear();
|
|
5735
|
+
this.#zBuckets = [];
|
|
5641
5736
|
this.checkParticlePositionPlugins = [];
|
|
5642
|
-
this
|
|
5643
|
-
this
|
|
5644
|
-
this
|
|
5645
|
-
this
|
|
5646
|
-
this
|
|
5737
|
+
this.#particleResetPlugins = [];
|
|
5738
|
+
this.#particleUpdatePlugins = [];
|
|
5739
|
+
this.#postUpdatePlugins = [];
|
|
5740
|
+
this.#postParticleUpdatePlugins = [];
|
|
5741
|
+
this.#updatePlugins = [];
|
|
5647
5742
|
}
|
|
5648
5743
|
drawParticles(delta) {
|
|
5649
|
-
for (let i = this.
|
|
5650
|
-
const bucket = this
|
|
5744
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5745
|
+
const bucket = this.#zBuckets[i];
|
|
5651
5746
|
if (!bucket) {
|
|
5652
5747
|
continue;
|
|
5653
5748
|
}
|
|
@@ -5657,24 +5752,24 @@
|
|
|
5657
5752
|
}
|
|
5658
5753
|
}
|
|
5659
5754
|
filter(condition) {
|
|
5660
|
-
return this.
|
|
5755
|
+
return this.#array.filter(condition);
|
|
5661
5756
|
}
|
|
5662
5757
|
find(condition) {
|
|
5663
|
-
return this.
|
|
5758
|
+
return this.#array.find(condition);
|
|
5664
5759
|
}
|
|
5665
5760
|
get(index) {
|
|
5666
|
-
return this
|
|
5761
|
+
return this.#array[index];
|
|
5667
5762
|
}
|
|
5668
5763
|
async init() {
|
|
5669
|
-
const container = this
|
|
5764
|
+
const container = this.#container, options = container.actualOptions;
|
|
5670
5765
|
this.checkParticlePositionPlugins = [];
|
|
5671
|
-
this
|
|
5672
|
-
this
|
|
5673
|
-
this
|
|
5674
|
-
this
|
|
5675
|
-
this
|
|
5676
|
-
this.
|
|
5677
|
-
this
|
|
5766
|
+
this.#updatePlugins = [];
|
|
5767
|
+
this.#particleUpdatePlugins = [];
|
|
5768
|
+
this.#postUpdatePlugins = [];
|
|
5769
|
+
this.#particleResetPlugins = [];
|
|
5770
|
+
this.#postParticleUpdatePlugins = [];
|
|
5771
|
+
this.#particleBuckets.clear();
|
|
5772
|
+
this.#resetBuckets(container.zLayers);
|
|
5678
5773
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5679
5774
|
for (const plugin of container.plugins) {
|
|
5680
5775
|
if (plugin.redrawInit) {
|
|
@@ -5684,26 +5779,26 @@
|
|
|
5684
5779
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5685
5780
|
}
|
|
5686
5781
|
if (plugin.update) {
|
|
5687
|
-
this.
|
|
5782
|
+
this.#updatePlugins.push(plugin);
|
|
5688
5783
|
}
|
|
5689
5784
|
if (plugin.particleUpdate) {
|
|
5690
|
-
this.
|
|
5785
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5691
5786
|
}
|
|
5692
5787
|
if (plugin.postUpdate) {
|
|
5693
|
-
this.
|
|
5788
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5694
5789
|
}
|
|
5695
5790
|
if (plugin.particleReset) {
|
|
5696
|
-
this.
|
|
5791
|
+
this.#particleResetPlugins.push(plugin);
|
|
5697
5792
|
}
|
|
5698
5793
|
if (plugin.postParticleUpdate) {
|
|
5699
|
-
this.
|
|
5794
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5700
5795
|
}
|
|
5701
5796
|
}
|
|
5702
|
-
await this.
|
|
5703
|
-
for (const drawer of this.
|
|
5797
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5798
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5704
5799
|
await drawer.init?.(container);
|
|
5705
5800
|
}
|
|
5706
|
-
for (const drawer of this.
|
|
5801
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5707
5802
|
await drawer.init?.(container);
|
|
5708
5803
|
}
|
|
5709
5804
|
let handled = false;
|
|
@@ -5737,10 +5832,10 @@
|
|
|
5737
5832
|
async redraw() {
|
|
5738
5833
|
this.clear();
|
|
5739
5834
|
await this.init();
|
|
5740
|
-
this.
|
|
5835
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5741
5836
|
}
|
|
5742
5837
|
remove(particle, group, override) {
|
|
5743
|
-
this.removeAt(this.
|
|
5838
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5744
5839
|
}
|
|
5745
5840
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5746
5841
|
if (index < minIndex || index > this.count) {
|
|
@@ -5748,7 +5843,7 @@
|
|
|
5748
5843
|
}
|
|
5749
5844
|
let deleted = 0;
|
|
5750
5845
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5751
|
-
if (this
|
|
5846
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5752
5847
|
i--;
|
|
5753
5848
|
deleted++;
|
|
5754
5849
|
}
|
|
@@ -5758,9 +5853,9 @@
|
|
|
5758
5853
|
this.removeAt(minIndex, quantity, group);
|
|
5759
5854
|
}
|
|
5760
5855
|
setDensity() {
|
|
5761
|
-
const options = this.
|
|
5856
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5762
5857
|
let pluginsCount = 0;
|
|
5763
|
-
for (const plugin of this.
|
|
5858
|
+
for (const plugin of this.#container.plugins) {
|
|
5764
5859
|
if (plugin.particlesDensityCount) {
|
|
5765
5860
|
pluginsCount += plugin.particlesDensityCount();
|
|
5766
5861
|
}
|
|
@@ -5770,51 +5865,51 @@
|
|
|
5770
5865
|
if (!groupData) {
|
|
5771
5866
|
continue;
|
|
5772
5867
|
}
|
|
5773
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5774
|
-
this
|
|
5868
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5869
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5775
5870
|
}
|
|
5776
|
-
this
|
|
5871
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5777
5872
|
}
|
|
5778
5873
|
setResizeFactor(factor) {
|
|
5779
|
-
this
|
|
5874
|
+
this.#resizeFactor = factor;
|
|
5780
5875
|
}
|
|
5781
5876
|
update(delta) {
|
|
5782
5877
|
this.grid.clear();
|
|
5783
|
-
for (const plugin of this
|
|
5878
|
+
for (const plugin of this.#updatePlugins) {
|
|
5784
5879
|
plugin.update?.(delta);
|
|
5785
5880
|
}
|
|
5786
|
-
const particlesToDelete = this
|
|
5787
|
-
for (const plugin of this
|
|
5881
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5882
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5788
5883
|
plugin.postUpdate?.(delta);
|
|
5789
5884
|
}
|
|
5790
|
-
this
|
|
5885
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5791
5886
|
if (particlesToDelete.size) {
|
|
5792
5887
|
for (const particle of particlesToDelete) {
|
|
5793
5888
|
this.remove(particle);
|
|
5794
5889
|
}
|
|
5795
5890
|
}
|
|
5796
|
-
|
|
5891
|
+
this.#resizeFactor = undefined;
|
|
5797
5892
|
}
|
|
5798
|
-
|
|
5799
|
-
this.
|
|
5893
|
+
#addToPool = (...particles) => {
|
|
5894
|
+
this.#pool.push(...particles);
|
|
5800
5895
|
};
|
|
5801
|
-
|
|
5896
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5802
5897
|
const numberOptions = options.number;
|
|
5803
5898
|
if (!numberOptions.density.enable) {
|
|
5804
5899
|
if (group === undefined) {
|
|
5805
|
-
this
|
|
5900
|
+
this.#limit = numberOptions.limit.value;
|
|
5806
5901
|
}
|
|
5807
5902
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5808
|
-
this.
|
|
5903
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5809
5904
|
}
|
|
5810
5905
|
return;
|
|
5811
5906
|
}
|
|
5812
|
-
const densityFactor = this
|
|
5907
|
+
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);
|
|
5813
5908
|
if (group === undefined) {
|
|
5814
|
-
this
|
|
5909
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5815
5910
|
}
|
|
5816
5911
|
else {
|
|
5817
|
-
this.
|
|
5912
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5818
5913
|
}
|
|
5819
5914
|
if (particlesCount < particlesNumber) {
|
|
5820
5915
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5823,18 +5918,18 @@
|
|
|
5823
5918
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5824
5919
|
}
|
|
5825
5920
|
};
|
|
5826
|
-
|
|
5921
|
+
#createBuckets = (zLayers) => {
|
|
5827
5922
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5828
5923
|
return Array.from({ length: bucketCount }, () => []);
|
|
5829
5924
|
};
|
|
5830
|
-
|
|
5831
|
-
const maxBucketIndex = this.
|
|
5925
|
+
#getBucketIndex = (zIndex) => {
|
|
5926
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5832
5927
|
if (maxBucketIndex <= minIndex) {
|
|
5833
5928
|
return minIndex;
|
|
5834
5929
|
}
|
|
5835
5930
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5836
5931
|
};
|
|
5837
|
-
|
|
5932
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5838
5933
|
let start = minIndex, end = bucket.length;
|
|
5839
5934
|
while (start < end) {
|
|
5840
5935
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5851,8 +5946,8 @@
|
|
|
5851
5946
|
}
|
|
5852
5947
|
return start;
|
|
5853
5948
|
};
|
|
5854
|
-
|
|
5855
|
-
const container = this
|
|
5949
|
+
#initDensityFactor = densityOptions => {
|
|
5950
|
+
const container = this.#container;
|
|
5856
5951
|
if (!densityOptions.enable) {
|
|
5857
5952
|
return defaultDensityFactor;
|
|
5858
5953
|
}
|
|
@@ -5862,82 +5957,82 @@
|
|
|
5862
5957
|
}
|
|
5863
5958
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5864
5959
|
};
|
|
5865
|
-
|
|
5866
|
-
const bucketIndex = this
|
|
5960
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5961
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5867
5962
|
if (!bucket) {
|
|
5868
5963
|
return;
|
|
5869
5964
|
}
|
|
5870
|
-
bucket.splice(this
|
|
5871
|
-
this.
|
|
5965
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5966
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5872
5967
|
};
|
|
5873
|
-
|
|
5874
|
-
const particle = this
|
|
5968
|
+
#removeParticle = (index, group, override) => {
|
|
5969
|
+
const particle = this.#array[index];
|
|
5875
5970
|
if (!particle) {
|
|
5876
5971
|
return false;
|
|
5877
5972
|
}
|
|
5878
5973
|
if (particle.group !== group) {
|
|
5879
5974
|
return false;
|
|
5880
5975
|
}
|
|
5881
|
-
this.
|
|
5882
|
-
this
|
|
5976
|
+
this.#array.splice(index, deleteCount);
|
|
5977
|
+
this.#removeParticleFromBucket(particle);
|
|
5883
5978
|
particle.destroy(override);
|
|
5884
|
-
this.
|
|
5979
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5885
5980
|
particle,
|
|
5886
5981
|
});
|
|
5887
|
-
this
|
|
5982
|
+
this.#addToPool(particle);
|
|
5888
5983
|
return true;
|
|
5889
5984
|
};
|
|
5890
|
-
|
|
5891
|
-
const bucketIndex = this.
|
|
5985
|
+
#removeParticleFromBucket = (particle) => {
|
|
5986
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5892
5987
|
if (!bucket) {
|
|
5893
|
-
this.
|
|
5988
|
+
this.#particleBuckets.delete(particle.id);
|
|
5894
5989
|
return;
|
|
5895
5990
|
}
|
|
5896
|
-
const particleIndex = this
|
|
5991
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5897
5992
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5898
|
-
this.
|
|
5993
|
+
this.#particleBuckets.delete(particle.id);
|
|
5899
5994
|
return;
|
|
5900
5995
|
}
|
|
5901
5996
|
bucket.splice(particleIndex, deleteCount);
|
|
5902
|
-
this.
|
|
5997
|
+
this.#particleBuckets.delete(particle.id);
|
|
5903
5998
|
};
|
|
5904
|
-
|
|
5999
|
+
#resetBuckets = (zLayers) => {
|
|
5905
6000
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5906
|
-
if (this.
|
|
5907
|
-
this
|
|
6001
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6002
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5908
6003
|
return;
|
|
5909
6004
|
}
|
|
5910
|
-
for (const bucket of this
|
|
6005
|
+
for (const bucket of this.#zBuckets) {
|
|
5911
6006
|
bucket.length = minIndex;
|
|
5912
6007
|
}
|
|
5913
6008
|
};
|
|
5914
|
-
|
|
5915
|
-
const newBucketIndex = this
|
|
6009
|
+
#updateParticleBucket = (particle) => {
|
|
6010
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5916
6011
|
if (currentBucketIndex === undefined) {
|
|
5917
|
-
this
|
|
6012
|
+
this.#insertParticleIntoBucket(particle);
|
|
5918
6013
|
return;
|
|
5919
6014
|
}
|
|
5920
6015
|
if (currentBucketIndex === newBucketIndex) {
|
|
5921
6016
|
return;
|
|
5922
6017
|
}
|
|
5923
|
-
const currentBucket = this
|
|
6018
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5924
6019
|
if (currentBucket) {
|
|
5925
|
-
const particleIndex = this
|
|
6020
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5926
6021
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5927
6022
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5928
6023
|
}
|
|
5929
6024
|
}
|
|
5930
|
-
const newBucket = this
|
|
6025
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5931
6026
|
if (!newBucket) {
|
|
5932
|
-
this.
|
|
6027
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5933
6028
|
return;
|
|
5934
6029
|
}
|
|
5935
|
-
newBucket.splice(this
|
|
5936
|
-
this.
|
|
6030
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6031
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5937
6032
|
};
|
|
5938
|
-
|
|
5939
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5940
|
-
for (const particle of this
|
|
6033
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6034
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6035
|
+
for (const particle of this.#array) {
|
|
5941
6036
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5942
6037
|
particle.position.x *= resizeFactor.width;
|
|
5943
6038
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5945,10 +6040,10 @@
|
|
|
5945
6040
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5946
6041
|
}
|
|
5947
6042
|
particle.ignoresResizeRatio = false;
|
|
5948
|
-
for (const plugin of this
|
|
6043
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5949
6044
|
plugin.particleReset?.(particle);
|
|
5950
6045
|
}
|
|
5951
|
-
for (const plugin of this
|
|
6046
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5952
6047
|
if (particle.destroyed) {
|
|
5953
6048
|
break;
|
|
5954
6049
|
}
|
|
@@ -5962,36 +6057,36 @@
|
|
|
5962
6057
|
}
|
|
5963
6058
|
return particlesToDelete;
|
|
5964
6059
|
};
|
|
5965
|
-
|
|
5966
|
-
for (const particle of this
|
|
6060
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6061
|
+
for (const particle of this.#array) {
|
|
5967
6062
|
if (particle.destroyed) {
|
|
5968
6063
|
particlesToDelete.add(particle);
|
|
5969
6064
|
continue;
|
|
5970
6065
|
}
|
|
5971
|
-
for (const updater of this.
|
|
6066
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5972
6067
|
updater.update(particle, delta);
|
|
5973
6068
|
}
|
|
5974
6069
|
if (!particle.spawning) {
|
|
5975
|
-
for (const plugin of this
|
|
6070
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5976
6071
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5977
6072
|
}
|
|
5978
6073
|
}
|
|
5979
|
-
this
|
|
6074
|
+
this.#updateParticleBucket(particle);
|
|
5980
6075
|
}
|
|
5981
6076
|
};
|
|
5982
6077
|
}
|
|
5983
6078
|
|
|
5984
6079
|
class Retina {
|
|
5985
|
-
container;
|
|
5986
6080
|
pixelRatio;
|
|
5987
6081
|
reduceFactor;
|
|
6082
|
+
#container;
|
|
5988
6083
|
constructor(container) {
|
|
5989
|
-
this
|
|
6084
|
+
this.#container = container;
|
|
5990
6085
|
this.pixelRatio = defaultRatio;
|
|
5991
6086
|
this.reduceFactor = defaultReduceFactor;
|
|
5992
6087
|
}
|
|
5993
6088
|
init() {
|
|
5994
|
-
const container = this
|
|
6089
|
+
const container = this.#container, options = container.actualOptions;
|
|
5995
6090
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
5996
6091
|
this.reduceFactor = defaultReduceFactor;
|
|
5997
6092
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6005,7 +6100,6 @@
|
|
|
6005
6100
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6006
6101
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6007
6102
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6008
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6009
6103
|
const maxDistance = props.maxDistance;
|
|
6010
6104
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6011
6105
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6043,73 +6137,73 @@
|
|
|
6043
6137
|
shapeDrawers;
|
|
6044
6138
|
started;
|
|
6045
6139
|
zLayers;
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6140
|
+
#delay;
|
|
6141
|
+
#delayTimeout;
|
|
6142
|
+
#delta = { value: 0, factor: 0 };
|
|
6143
|
+
#dispatchCallback;
|
|
6144
|
+
#drawAnimationFrame;
|
|
6145
|
+
#duration;
|
|
6146
|
+
#eventListeners;
|
|
6147
|
+
#firstStart;
|
|
6148
|
+
#initialSourceOptions;
|
|
6149
|
+
#lastFrameTime;
|
|
6150
|
+
#lifeTime;
|
|
6151
|
+
#onDestroy;
|
|
6152
|
+
#options;
|
|
6153
|
+
#paused;
|
|
6154
|
+
#pluginManager;
|
|
6155
|
+
#smooth;
|
|
6156
|
+
#sourceOptions;
|
|
6063
6157
|
constructor(params) {
|
|
6064
6158
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6065
|
-
this
|
|
6066
|
-
this
|
|
6067
|
-
this
|
|
6159
|
+
this.#pluginManager = pluginManager;
|
|
6160
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6161
|
+
this.#onDestroy = onDestroy;
|
|
6068
6162
|
this.id = Symbol(id);
|
|
6069
6163
|
this.fpsLimit = 120;
|
|
6070
6164
|
this.hdr = false;
|
|
6071
|
-
this
|
|
6072
|
-
this
|
|
6073
|
-
this
|
|
6074
|
-
this
|
|
6075
|
-
this
|
|
6165
|
+
this.#smooth = false;
|
|
6166
|
+
this.#delay = 0;
|
|
6167
|
+
this.#duration = 0;
|
|
6168
|
+
this.#lifeTime = 0;
|
|
6169
|
+
this.#firstStart = true;
|
|
6076
6170
|
this.started = false;
|
|
6077
6171
|
this.destroyed = false;
|
|
6078
|
-
this
|
|
6079
|
-
this
|
|
6172
|
+
this.#paused = true;
|
|
6173
|
+
this.#lastFrameTime = 0;
|
|
6080
6174
|
this.zLayers = 100;
|
|
6081
6175
|
this.pageHidden = false;
|
|
6082
|
-
this
|
|
6083
|
-
this
|
|
6176
|
+
this.#sourceOptions = sourceOptions;
|
|
6177
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6084
6178
|
this.effectDrawers = new Map();
|
|
6085
6179
|
this.shapeDrawers = new Map();
|
|
6086
6180
|
this.particleUpdaters = [];
|
|
6087
6181
|
this.retina = new Retina(this);
|
|
6088
|
-
this.canvas = new CanvasManager(this
|
|
6089
|
-
this.particles = new ParticlesManager(this
|
|
6182
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6183
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6090
6184
|
this.plugins = [];
|
|
6091
6185
|
this.particleDestroyedPlugins = [];
|
|
6092
6186
|
this.particleCreatedPlugins = [];
|
|
6093
6187
|
this.particlePositionPlugins = [];
|
|
6094
|
-
this
|
|
6095
|
-
this.actualOptions = loadContainerOptions(this
|
|
6096
|
-
this
|
|
6188
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6189
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6190
|
+
this.#eventListeners = new EventListeners(this);
|
|
6097
6191
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6098
6192
|
}
|
|
6099
6193
|
get animationStatus() {
|
|
6100
|
-
return !this
|
|
6194
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6101
6195
|
}
|
|
6102
6196
|
get options() {
|
|
6103
|
-
return this
|
|
6197
|
+
return this.#options;
|
|
6104
6198
|
}
|
|
6105
6199
|
get sourceOptions() {
|
|
6106
|
-
return this
|
|
6200
|
+
return this.#sourceOptions;
|
|
6107
6201
|
}
|
|
6108
6202
|
addLifeTime(value) {
|
|
6109
|
-
this
|
|
6203
|
+
this.#lifeTime += value;
|
|
6110
6204
|
}
|
|
6111
6205
|
alive() {
|
|
6112
|
-
return !this
|
|
6206
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6113
6207
|
}
|
|
6114
6208
|
destroy(remove = true) {
|
|
6115
6209
|
if (!guardCheck(this)) {
|
|
@@ -6131,13 +6225,13 @@
|
|
|
6131
6225
|
this.shapeDrawers = new Map();
|
|
6132
6226
|
this.particleUpdaters = [];
|
|
6133
6227
|
this.plugins.length = 0;
|
|
6134
|
-
this.
|
|
6228
|
+
this.#pluginManager.clearPlugins(this);
|
|
6135
6229
|
this.destroyed = true;
|
|
6136
|
-
this
|
|
6230
|
+
this.#onDestroy(remove);
|
|
6137
6231
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6138
6232
|
}
|
|
6139
6233
|
dispatchEvent(type, data) {
|
|
6140
|
-
this
|
|
6234
|
+
this.#dispatchCallback(type, {
|
|
6141
6235
|
container: this,
|
|
6142
6236
|
data,
|
|
6143
6237
|
});
|
|
@@ -6147,12 +6241,12 @@
|
|
|
6147
6241
|
return;
|
|
6148
6242
|
}
|
|
6149
6243
|
let refreshTime = force;
|
|
6150
|
-
this
|
|
6244
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6151
6245
|
if (refreshTime) {
|
|
6152
|
-
this
|
|
6246
|
+
this.#lastFrameTime = undefined;
|
|
6153
6247
|
refreshTime = false;
|
|
6154
6248
|
}
|
|
6155
|
-
this
|
|
6249
|
+
this.#nextFrame(timestamp);
|
|
6156
6250
|
});
|
|
6157
6251
|
}
|
|
6158
6252
|
async export(type, options = {}) {
|
|
@@ -6174,7 +6268,7 @@
|
|
|
6174
6268
|
return;
|
|
6175
6269
|
}
|
|
6176
6270
|
const allContainerPlugins = new Map();
|
|
6177
|
-
for (const plugin of this.
|
|
6271
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6178
6272
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6179
6273
|
if (containerPlugin.preInit) {
|
|
6180
6274
|
await containerPlugin.preInit();
|
|
@@ -6182,8 +6276,8 @@
|
|
|
6182
6276
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6183
6277
|
}
|
|
6184
6278
|
await this.initDrawersAndUpdaters();
|
|
6185
|
-
this
|
|
6186
|
-
this.actualOptions = loadContainerOptions(this
|
|
6279
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6280
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6187
6281
|
this.plugins.length = 0;
|
|
6188
6282
|
this.particleDestroyedPlugins.length = 0;
|
|
6189
6283
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6210,11 +6304,11 @@
|
|
|
6210
6304
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6211
6305
|
this.hdr = hdr;
|
|
6212
6306
|
this.zLayers = zLayers;
|
|
6213
|
-
this
|
|
6214
|
-
this
|
|
6215
|
-
this
|
|
6307
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6308
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6309
|
+
this.#lifeTime = 0;
|
|
6216
6310
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6217
|
-
this
|
|
6311
|
+
this.#smooth = smooth;
|
|
6218
6312
|
for (const plugin of this.plugins) {
|
|
6219
6313
|
await plugin.init?.();
|
|
6220
6314
|
}
|
|
@@ -6227,7 +6321,7 @@
|
|
|
6227
6321
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6228
6322
|
}
|
|
6229
6323
|
async initDrawersAndUpdaters() {
|
|
6230
|
-
const pluginManager = this
|
|
6324
|
+
const pluginManager = this.#pluginManager;
|
|
6231
6325
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6232
6326
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6233
6327
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6236,18 +6330,18 @@
|
|
|
6236
6330
|
if (!guardCheck(this)) {
|
|
6237
6331
|
return;
|
|
6238
6332
|
}
|
|
6239
|
-
if (this
|
|
6240
|
-
cancelAnimation(this
|
|
6241
|
-
|
|
6333
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6334
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6335
|
+
this.#drawAnimationFrame = undefined;
|
|
6242
6336
|
}
|
|
6243
|
-
if (this
|
|
6337
|
+
if (this.#paused) {
|
|
6244
6338
|
return;
|
|
6245
6339
|
}
|
|
6246
6340
|
for (const plugin of this.plugins) {
|
|
6247
6341
|
plugin.pause?.();
|
|
6248
6342
|
}
|
|
6249
6343
|
if (!this.pageHidden) {
|
|
6250
|
-
this
|
|
6344
|
+
this.#paused = true;
|
|
6251
6345
|
}
|
|
6252
6346
|
this.dispatchEvent(EventType.containerPaused);
|
|
6253
6347
|
}
|
|
@@ -6255,13 +6349,13 @@
|
|
|
6255
6349
|
if (!guardCheck(this)) {
|
|
6256
6350
|
return;
|
|
6257
6351
|
}
|
|
6258
|
-
const needsUpdate = this
|
|
6259
|
-
if (this
|
|
6260
|
-
this
|
|
6352
|
+
const needsUpdate = this.#paused || force;
|
|
6353
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6354
|
+
this.#firstStart = false;
|
|
6261
6355
|
return;
|
|
6262
6356
|
}
|
|
6263
|
-
if (this
|
|
6264
|
-
this
|
|
6357
|
+
if (this.#paused) {
|
|
6358
|
+
this.#paused = false;
|
|
6265
6359
|
}
|
|
6266
6360
|
if (needsUpdate) {
|
|
6267
6361
|
for (const plugin of this.plugins) {
|
|
@@ -6284,10 +6378,10 @@
|
|
|
6284
6378
|
if (!guardCheck(this)) {
|
|
6285
6379
|
return;
|
|
6286
6380
|
}
|
|
6287
|
-
this
|
|
6288
|
-
this
|
|
6289
|
-
this
|
|
6290
|
-
this.actualOptions = loadContainerOptions(this
|
|
6381
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6382
|
+
this.#sourceOptions = sourceOptions;
|
|
6383
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6384
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6291
6385
|
return this.refresh();
|
|
6292
6386
|
}
|
|
6293
6387
|
async start() {
|
|
@@ -6298,7 +6392,7 @@
|
|
|
6298
6392
|
this.started = true;
|
|
6299
6393
|
await new Promise(resolve => {
|
|
6300
6394
|
const start = async () => {
|
|
6301
|
-
this.
|
|
6395
|
+
this.#eventListeners.addListeners();
|
|
6302
6396
|
for (const plugin of this.plugins) {
|
|
6303
6397
|
await plugin.start?.();
|
|
6304
6398
|
}
|
|
@@ -6306,20 +6400,20 @@
|
|
|
6306
6400
|
this.play();
|
|
6307
6401
|
resolve();
|
|
6308
6402
|
};
|
|
6309
|
-
this
|
|
6403
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6310
6404
|
});
|
|
6311
6405
|
}
|
|
6312
6406
|
stop() {
|
|
6313
6407
|
if (!guardCheck(this) || !this.started) {
|
|
6314
6408
|
return;
|
|
6315
6409
|
}
|
|
6316
|
-
if (this
|
|
6317
|
-
clearTimeout(this
|
|
6318
|
-
|
|
6410
|
+
if (this.#delayTimeout) {
|
|
6411
|
+
clearTimeout(this.#delayTimeout);
|
|
6412
|
+
this.#delayTimeout = undefined;
|
|
6319
6413
|
}
|
|
6320
|
-
this
|
|
6414
|
+
this.#firstStart = true;
|
|
6321
6415
|
this.started = false;
|
|
6322
|
-
this.
|
|
6416
|
+
this.#eventListeners.removeListeners();
|
|
6323
6417
|
this.pause();
|
|
6324
6418
|
this.particles.clear();
|
|
6325
6419
|
this.canvas.stop();
|
|
@@ -6329,7 +6423,7 @@
|
|
|
6329
6423
|
this.particleCreatedPlugins.length = 0;
|
|
6330
6424
|
this.particleDestroyedPlugins.length = 0;
|
|
6331
6425
|
this.particlePositionPlugins.length = 0;
|
|
6332
|
-
this
|
|
6426
|
+
this.#sourceOptions = this.#options;
|
|
6333
6427
|
this.dispatchEvent(EventType.containerStopped);
|
|
6334
6428
|
}
|
|
6335
6429
|
updateActualOptions() {
|
|
@@ -6341,23 +6435,23 @@
|
|
|
6341
6435
|
}
|
|
6342
6436
|
return refresh;
|
|
6343
6437
|
}
|
|
6344
|
-
|
|
6438
|
+
#nextFrame = (timestamp) => {
|
|
6345
6439
|
try {
|
|
6346
|
-
if (!this
|
|
6347
|
-
this
|
|
6348
|
-
timestamp < this
|
|
6440
|
+
if (!this.#smooth &&
|
|
6441
|
+
this.#lastFrameTime !== undefined &&
|
|
6442
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6349
6443
|
this.draw(false);
|
|
6350
6444
|
return;
|
|
6351
6445
|
}
|
|
6352
|
-
this
|
|
6353
|
-
updateDelta(this
|
|
6354
|
-
this.addLifeTime(this.
|
|
6355
|
-
this
|
|
6356
|
-
if (this.
|
|
6446
|
+
this.#lastFrameTime ??= timestamp;
|
|
6447
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6448
|
+
this.addLifeTime(this.#delta.value);
|
|
6449
|
+
this.#lastFrameTime = timestamp;
|
|
6450
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6357
6451
|
this.draw(false);
|
|
6358
6452
|
return;
|
|
6359
6453
|
}
|
|
6360
|
-
this.canvas.render.drawParticles(this
|
|
6454
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6361
6455
|
if (!this.alive()) {
|
|
6362
6456
|
this.destroy();
|
|
6363
6457
|
return;
|
|
@@ -6378,10 +6472,10 @@
|
|
|
6378
6472
|
});
|
|
6379
6473
|
|
|
6380
6474
|
class BlendPluginInstance {
|
|
6381
|
-
|
|
6382
|
-
|
|
6475
|
+
#container;
|
|
6476
|
+
#defaultCompositeValue;
|
|
6383
6477
|
constructor(container) {
|
|
6384
|
-
this
|
|
6478
|
+
this.#container = container;
|
|
6385
6479
|
}
|
|
6386
6480
|
drawParticleCleanup(context, particle) {
|
|
6387
6481
|
if (!particle.options.blend?.enable) {
|
|
@@ -6398,14 +6492,14 @@
|
|
|
6398
6492
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6399
6493
|
}
|
|
6400
6494
|
drawSettingsCleanup(context) {
|
|
6401
|
-
if (!this
|
|
6495
|
+
if (!this.#defaultCompositeValue) {
|
|
6402
6496
|
return;
|
|
6403
6497
|
}
|
|
6404
|
-
context.globalCompositeOperation = this
|
|
6498
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6405
6499
|
}
|
|
6406
6500
|
drawSettingsSetup(context) {
|
|
6407
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6408
|
-
this
|
|
6501
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6502
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6409
6503
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6410
6504
|
}
|
|
6411
6505
|
}
|
|
@@ -6548,11 +6642,11 @@
|
|
|
6548
6642
|
class MovePluginInstance {
|
|
6549
6643
|
availablePathGenerators;
|
|
6550
6644
|
pathGenerators;
|
|
6551
|
-
|
|
6552
|
-
|
|
6645
|
+
#container;
|
|
6646
|
+
#pluginManager;
|
|
6553
6647
|
constructor(pluginManager, container) {
|
|
6554
|
-
this
|
|
6555
|
-
this
|
|
6648
|
+
this.#pluginManager = pluginManager;
|
|
6649
|
+
this.#container = container;
|
|
6556
6650
|
this.availablePathGenerators = new Map();
|
|
6557
6651
|
this.pathGenerators = new Map();
|
|
6558
6652
|
}
|
|
@@ -6583,7 +6677,7 @@
|
|
|
6583
6677
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6584
6678
|
inverse: gravityOptions.inverse,
|
|
6585
6679
|
};
|
|
6586
|
-
initSpin(this
|
|
6680
|
+
initSpin(this.#container, particle);
|
|
6587
6681
|
}
|
|
6588
6682
|
particleDestroyed(particle) {
|
|
6589
6683
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6594,7 +6688,7 @@
|
|
|
6594
6688
|
if (!moveOptions.enable) {
|
|
6595
6689
|
return;
|
|
6596
6690
|
}
|
|
6597
|
-
const container = this
|
|
6691
|
+
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;
|
|
6598
6692
|
if (moveOptions.spin.enable) {
|
|
6599
6693
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6600
6694
|
}
|
|
@@ -6604,18 +6698,18 @@
|
|
|
6604
6698
|
applyDistance(particle);
|
|
6605
6699
|
}
|
|
6606
6700
|
preInit() {
|
|
6607
|
-
return this
|
|
6701
|
+
return this.#init();
|
|
6608
6702
|
}
|
|
6609
6703
|
redrawInit() {
|
|
6610
|
-
return this
|
|
6704
|
+
return this.#init();
|
|
6611
6705
|
}
|
|
6612
6706
|
update() {
|
|
6613
6707
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6614
6708
|
pathGenerator.update();
|
|
6615
6709
|
}
|
|
6616
6710
|
}
|
|
6617
|
-
async
|
|
6618
|
-
const availablePathGenerators = await this.
|
|
6711
|
+
async #init() {
|
|
6712
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6619
6713
|
if (!availablePathGenerators) {
|
|
6620
6714
|
return;
|
|
6621
6715
|
}
|
|
@@ -6634,65 +6728,65 @@
|
|
|
6634
6728
|
|
|
6635
6729
|
const touchDelay = 500;
|
|
6636
6730
|
class InteractivityEventListeners {
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6731
|
+
#canPush = true;
|
|
6732
|
+
#clickPositionPlugins;
|
|
6733
|
+
#container;
|
|
6734
|
+
#handlers;
|
|
6735
|
+
#interactionManager;
|
|
6736
|
+
#touches;
|
|
6643
6737
|
constructor(container, interactionManager) {
|
|
6644
|
-
this
|
|
6645
|
-
this
|
|
6646
|
-
this
|
|
6647
|
-
this
|
|
6648
|
-
this
|
|
6738
|
+
this.#container = container;
|
|
6739
|
+
this.#clickPositionPlugins = [];
|
|
6740
|
+
this.#interactionManager = interactionManager;
|
|
6741
|
+
this.#touches = new Map();
|
|
6742
|
+
this.#handlers = {
|
|
6649
6743
|
mouseDown: () => {
|
|
6650
|
-
this
|
|
6744
|
+
this.#mouseDown();
|
|
6651
6745
|
},
|
|
6652
6746
|
mouseLeave: () => {
|
|
6653
|
-
this
|
|
6747
|
+
this.#mouseTouchFinish();
|
|
6654
6748
|
},
|
|
6655
6749
|
mouseMove: (e) => {
|
|
6656
|
-
this
|
|
6750
|
+
this.#mouseTouchMove(e);
|
|
6657
6751
|
},
|
|
6658
6752
|
mouseUp: (e) => {
|
|
6659
|
-
this
|
|
6753
|
+
this.#mouseTouchClick(e);
|
|
6660
6754
|
},
|
|
6661
6755
|
touchStart: (e) => {
|
|
6662
|
-
this
|
|
6756
|
+
this.#touchStart(e);
|
|
6663
6757
|
},
|
|
6664
6758
|
touchMove: (e) => {
|
|
6665
|
-
this
|
|
6759
|
+
this.#mouseTouchMove(e);
|
|
6666
6760
|
},
|
|
6667
6761
|
touchEnd: (e) => {
|
|
6668
|
-
this
|
|
6762
|
+
this.#touchEnd(e);
|
|
6669
6763
|
},
|
|
6670
6764
|
touchCancel: (e) => {
|
|
6671
|
-
this
|
|
6765
|
+
this.#touchEnd(e);
|
|
6672
6766
|
},
|
|
6673
6767
|
touchEndClick: (e) => {
|
|
6674
|
-
this
|
|
6768
|
+
this.#touchEndClick(e);
|
|
6675
6769
|
},
|
|
6676
6770
|
visibilityChange: () => {
|
|
6677
|
-
this
|
|
6771
|
+
this.#handleVisibilityChange();
|
|
6678
6772
|
},
|
|
6679
6773
|
};
|
|
6680
6774
|
}
|
|
6681
6775
|
addListeners() {
|
|
6682
|
-
this
|
|
6776
|
+
this.#manageListeners(true);
|
|
6683
6777
|
}
|
|
6684
6778
|
init() {
|
|
6685
|
-
this.
|
|
6686
|
-
for (const plugin of this.
|
|
6687
|
-
this.
|
|
6779
|
+
this.#clickPositionPlugins.length = 0;
|
|
6780
|
+
for (const plugin of this.#container.plugins.filter(p => !!p.clickPositionValid)) {
|
|
6781
|
+
this.#clickPositionPlugins.push(plugin);
|
|
6688
6782
|
}
|
|
6689
6783
|
}
|
|
6690
6784
|
removeListeners() {
|
|
6691
|
-
this
|
|
6785
|
+
this.#manageListeners(false);
|
|
6692
6786
|
}
|
|
6693
|
-
|
|
6694
|
-
const container = this
|
|
6695
|
-
if (this
|
|
6787
|
+
#doMouseTouchClick = e => {
|
|
6788
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions;
|
|
6789
|
+
if (this.#canPush) {
|
|
6696
6790
|
const mouseInteractivity = interactionManager.interactivityData.mouse, mousePos = mouseInteractivity.position;
|
|
6697
6791
|
if (!mousePos) {
|
|
6698
6792
|
return;
|
|
@@ -6709,15 +6803,15 @@
|
|
|
6709
6803
|
}
|
|
6710
6804
|
if (e.type === "touchend") {
|
|
6711
6805
|
setTimeout(() => {
|
|
6712
|
-
this
|
|
6806
|
+
this.#mouseTouchFinish();
|
|
6713
6807
|
}, touchDelay);
|
|
6714
6808
|
}
|
|
6715
6809
|
};
|
|
6716
|
-
|
|
6717
|
-
this
|
|
6810
|
+
#handleVisibilityChange = () => {
|
|
6811
|
+
this.#mouseTouchFinish();
|
|
6718
6812
|
};
|
|
6719
|
-
|
|
6720
|
-
const handlers = this
|
|
6813
|
+
#manageInteractivityListeners = add => {
|
|
6814
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivityEl = interactionManager.interactivityData.element;
|
|
6721
6815
|
if (!interactivityEl) {
|
|
6722
6816
|
return;
|
|
6723
6817
|
}
|
|
@@ -6748,8 +6842,8 @@
|
|
|
6748
6842
|
manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
|
|
6749
6843
|
manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
|
6750
6844
|
};
|
|
6751
|
-
|
|
6752
|
-
const handlers = this
|
|
6845
|
+
#manageListeners = add => {
|
|
6846
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, detectType = options.interactivity?.detectsOn, canvasEl = container.canvas.domElement;
|
|
6753
6847
|
if (detectType === InteractivityDetect.window) {
|
|
6754
6848
|
interactionManager.interactivityData.element = safeDocument();
|
|
6755
6849
|
}
|
|
@@ -6759,35 +6853,35 @@
|
|
|
6759
6853
|
else {
|
|
6760
6854
|
interactionManager.interactivityData.element = canvasEl;
|
|
6761
6855
|
}
|
|
6762
|
-
this
|
|
6856
|
+
this.#manageInteractivityListeners(add);
|
|
6763
6857
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
6764
6858
|
};
|
|
6765
|
-
|
|
6766
|
-
const { interactivityData } = this
|
|
6859
|
+
#mouseDown = () => {
|
|
6860
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
6767
6861
|
mouse.clicking = true;
|
|
6768
6862
|
mouse.downPosition = mouse.position;
|
|
6769
6863
|
};
|
|
6770
|
-
|
|
6771
|
-
const container = this
|
|
6864
|
+
#mouseTouchClick = e => {
|
|
6865
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
|
|
6772
6866
|
mouse.inside = true;
|
|
6773
6867
|
let handled = false;
|
|
6774
6868
|
const mousePosition = mouse.position;
|
|
6775
6869
|
if (!mousePosition || !options.interactivity?.events.onClick.enable) {
|
|
6776
6870
|
return;
|
|
6777
6871
|
}
|
|
6778
|
-
for (const plugin of this
|
|
6872
|
+
for (const plugin of this.#clickPositionPlugins) {
|
|
6779
6873
|
handled = plugin.clickPositionValid?.(mousePosition) ?? false;
|
|
6780
6874
|
if (handled) {
|
|
6781
6875
|
break;
|
|
6782
6876
|
}
|
|
6783
6877
|
}
|
|
6784
6878
|
if (!handled) {
|
|
6785
|
-
this
|
|
6879
|
+
this.#doMouseTouchClick(e);
|
|
6786
6880
|
}
|
|
6787
6881
|
mouse.clicking = false;
|
|
6788
6882
|
};
|
|
6789
|
-
|
|
6790
|
-
const { interactivityData } = this
|
|
6883
|
+
#mouseTouchFinish = () => {
|
|
6884
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
6791
6885
|
delete mouse.position;
|
|
6792
6886
|
delete mouse.clickPosition;
|
|
6793
6887
|
delete mouse.downPosition;
|
|
@@ -6795,15 +6889,15 @@
|
|
|
6795
6889
|
mouse.inside = false;
|
|
6796
6890
|
mouse.clicking = false;
|
|
6797
6891
|
};
|
|
6798
|
-
|
|
6799
|
-
const container = this
|
|
6892
|
+
#mouseTouchMove = e => {
|
|
6893
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivity = interactionManager.interactivityData, canvasEl = container.canvas.domElement;
|
|
6800
6894
|
if (!interactivity.element) {
|
|
6801
6895
|
return;
|
|
6802
6896
|
}
|
|
6803
6897
|
interactivity.mouse.inside = true;
|
|
6804
6898
|
let pos;
|
|
6805
6899
|
if (e.type.startsWith("pointer")) {
|
|
6806
|
-
this
|
|
6900
|
+
this.#canPush = true;
|
|
6807
6901
|
const mouseEvent = e;
|
|
6808
6902
|
if (interactivity.element === safeDocument()) {
|
|
6809
6903
|
if (canvasEl) {
|
|
@@ -6838,7 +6932,7 @@
|
|
|
6838
6932
|
}
|
|
6839
6933
|
}
|
|
6840
6934
|
else {
|
|
6841
|
-
this
|
|
6935
|
+
this.#canPush = e.type !== "touchmove";
|
|
6842
6936
|
if (canvasEl) {
|
|
6843
6937
|
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
|
|
6844
6938
|
if (!lastTouch) {
|
|
@@ -6858,60 +6952,60 @@
|
|
|
6858
6952
|
interactivity.mouse.position = pos;
|
|
6859
6953
|
interactivity.status = mouseMoveEvent;
|
|
6860
6954
|
};
|
|
6861
|
-
|
|
6955
|
+
#touchEnd = e => {
|
|
6862
6956
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6863
6957
|
for (const touch of touches) {
|
|
6864
|
-
this.
|
|
6958
|
+
this.#touches.delete(touch.identifier);
|
|
6865
6959
|
}
|
|
6866
|
-
this
|
|
6960
|
+
this.#mouseTouchFinish();
|
|
6867
6961
|
};
|
|
6868
|
-
|
|
6962
|
+
#touchEndClick = e => {
|
|
6869
6963
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6870
6964
|
for (const touch of touches) {
|
|
6871
|
-
this.
|
|
6965
|
+
this.#touches.delete(touch.identifier);
|
|
6872
6966
|
}
|
|
6873
|
-
this
|
|
6967
|
+
this.#mouseTouchClick(e);
|
|
6874
6968
|
};
|
|
6875
|
-
|
|
6969
|
+
#touchStart = e => {
|
|
6876
6970
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6877
6971
|
for (const touch of touches) {
|
|
6878
|
-
this.
|
|
6972
|
+
this.#touches.set(touch.identifier, performance.now());
|
|
6879
6973
|
}
|
|
6880
|
-
this
|
|
6974
|
+
this.#mouseTouchMove(e);
|
|
6881
6975
|
};
|
|
6882
6976
|
}
|
|
6883
6977
|
|
|
6884
6978
|
const clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0;
|
|
6885
6979
|
class InteractionManager {
|
|
6886
|
-
container;
|
|
6887
6980
|
interactivityData;
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6981
|
+
#clickHandlers;
|
|
6982
|
+
#container;
|
|
6983
|
+
#eventListeners;
|
|
6984
|
+
#externalInteractors;
|
|
6985
|
+
#interactors;
|
|
6986
|
+
#intersectionObserver;
|
|
6987
|
+
#particleInteractors;
|
|
6988
|
+
#pluginManager;
|
|
6895
6989
|
constructor(pluginManager, container) {
|
|
6896
|
-
this
|
|
6897
|
-
this
|
|
6898
|
-
this
|
|
6899
|
-
this
|
|
6900
|
-
this
|
|
6901
|
-
this
|
|
6902
|
-
this
|
|
6990
|
+
this.#container = container;
|
|
6991
|
+
this.#pluginManager = pluginManager;
|
|
6992
|
+
this.#interactors = [];
|
|
6993
|
+
this.#externalInteractors = [];
|
|
6994
|
+
this.#particleInteractors = [];
|
|
6995
|
+
this.#clickHandlers = new Map();
|
|
6996
|
+
this.#eventListeners = new InteractivityEventListeners(container, this);
|
|
6903
6997
|
this.interactivityData = {
|
|
6904
6998
|
mouse: {
|
|
6905
6999
|
clicking: false,
|
|
6906
7000
|
inside: false,
|
|
6907
7001
|
},
|
|
6908
7002
|
};
|
|
6909
|
-
this
|
|
6910
|
-
this
|
|
7003
|
+
this.#intersectionObserver = safeIntersectionObserver(entries => {
|
|
7004
|
+
this.#intersectionManager(entries);
|
|
6911
7005
|
});
|
|
6912
7006
|
}
|
|
6913
7007
|
addClickHandler(callback) {
|
|
6914
|
-
const
|
|
7008
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
6915
7009
|
if (container.destroyed) {
|
|
6916
7010
|
return;
|
|
6917
7011
|
}
|
|
@@ -6973,119 +7067,119 @@
|
|
|
6973
7067
|
touchMoved = false;
|
|
6974
7068
|
};
|
|
6975
7069
|
let touched = false, touchMoved = false;
|
|
6976
|
-
this.
|
|
6977
|
-
this.
|
|
6978
|
-
this.
|
|
6979
|
-
this.
|
|
6980
|
-
this.
|
|
6981
|
-
for (const [key, handler] of this
|
|
7070
|
+
this.#clickHandlers.set(clickEvent, clickHandler);
|
|
7071
|
+
this.#clickHandlers.set(touchStartEvent, touchStartHandler);
|
|
7072
|
+
this.#clickHandlers.set(touchMoveEvent, touchMoveHandler);
|
|
7073
|
+
this.#clickHandlers.set(touchEndEvent, touchEndHandler);
|
|
7074
|
+
this.#clickHandlers.set(touchCancelEvent, touchCancelHandler);
|
|
7075
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
6982
7076
|
el.addEventListener(key, handler);
|
|
6983
7077
|
}
|
|
6984
7078
|
}
|
|
6985
7079
|
addListeners() {
|
|
6986
|
-
this.
|
|
7080
|
+
this.#eventListeners.addListeners();
|
|
6987
7081
|
}
|
|
6988
7082
|
clearClickHandlers() {
|
|
6989
|
-
const
|
|
7083
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
6990
7084
|
if (container.destroyed) {
|
|
6991
7085
|
return;
|
|
6992
7086
|
}
|
|
6993
|
-
for (const [key, handler] of this
|
|
7087
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
6994
7088
|
interactivityData.element?.removeEventListener(key, handler);
|
|
6995
7089
|
}
|
|
6996
|
-
this.
|
|
7090
|
+
this.#clickHandlers.clear();
|
|
6997
7091
|
}
|
|
6998
7092
|
externalInteract(delta) {
|
|
6999
|
-
for (const interactor of this
|
|
7000
|
-
const
|
|
7093
|
+
for (const interactor of this.#externalInteractors) {
|
|
7094
|
+
const interactivityData = this.interactivityData;
|
|
7001
7095
|
if (interactor.isEnabled(interactivityData)) {
|
|
7002
7096
|
interactor.interact(interactivityData, delta);
|
|
7003
7097
|
}
|
|
7004
7098
|
}
|
|
7005
7099
|
}
|
|
7006
7100
|
handleClickMode(mode) {
|
|
7007
|
-
if (this
|
|
7101
|
+
if (this.#container.destroyed) {
|
|
7008
7102
|
return;
|
|
7009
7103
|
}
|
|
7010
|
-
const
|
|
7011
|
-
for (const interactor of this
|
|
7104
|
+
const interactivityData = this.interactivityData;
|
|
7105
|
+
for (const interactor of this.#externalInteractors) {
|
|
7012
7106
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
7013
7107
|
}
|
|
7014
7108
|
}
|
|
7015
7109
|
init() {
|
|
7016
|
-
this.
|
|
7017
|
-
for (const interactor of this
|
|
7110
|
+
this.#eventListeners.init();
|
|
7111
|
+
for (const interactor of this.#interactors) {
|
|
7018
7112
|
switch (interactor.type) {
|
|
7019
7113
|
case InteractorType.external:
|
|
7020
|
-
this.
|
|
7114
|
+
this.#externalInteractors.push(interactor);
|
|
7021
7115
|
break;
|
|
7022
7116
|
case InteractorType.particles:
|
|
7023
|
-
this.
|
|
7117
|
+
this.#particleInteractors.push(interactor);
|
|
7024
7118
|
break;
|
|
7025
7119
|
}
|
|
7026
7120
|
interactor.init();
|
|
7027
7121
|
}
|
|
7028
7122
|
}
|
|
7029
7123
|
async initInteractors() {
|
|
7030
|
-
const interactors = await this.
|
|
7124
|
+
const interactors = await this.#pluginManager.getInteractors?.(this.#container, true);
|
|
7031
7125
|
if (!interactors) {
|
|
7032
7126
|
return;
|
|
7033
7127
|
}
|
|
7034
|
-
this
|
|
7035
|
-
this
|
|
7036
|
-
this
|
|
7128
|
+
this.#interactors = interactors;
|
|
7129
|
+
this.#externalInteractors = [];
|
|
7130
|
+
this.#particleInteractors = [];
|
|
7037
7131
|
}
|
|
7038
7132
|
particlesInteract(particle, delta) {
|
|
7039
|
-
const
|
|
7040
|
-
for (const interactor of this
|
|
7133
|
+
const interactivityData = this.interactivityData;
|
|
7134
|
+
for (const interactor of this.#externalInteractors) {
|
|
7041
7135
|
interactor.clear(particle, delta);
|
|
7042
7136
|
}
|
|
7043
|
-
for (const interactor of this
|
|
7137
|
+
for (const interactor of this.#particleInteractors) {
|
|
7044
7138
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7045
7139
|
interactor.interact(particle, interactivityData, delta);
|
|
7046
7140
|
}
|
|
7047
7141
|
}
|
|
7048
7142
|
}
|
|
7049
7143
|
removeListeners() {
|
|
7050
|
-
this.
|
|
7144
|
+
this.#eventListeners.removeListeners();
|
|
7051
7145
|
}
|
|
7052
7146
|
reset(particle) {
|
|
7053
|
-
const
|
|
7054
|
-
for (const interactor of this
|
|
7147
|
+
const interactivityData = this.interactivityData;
|
|
7148
|
+
for (const interactor of this.#externalInteractors) {
|
|
7055
7149
|
if (interactor.isEnabled(interactivityData)) {
|
|
7056
7150
|
interactor.reset(interactivityData, particle);
|
|
7057
7151
|
}
|
|
7058
7152
|
}
|
|
7059
|
-
for (const interactor of this
|
|
7153
|
+
for (const interactor of this.#particleInteractors) {
|
|
7060
7154
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7061
7155
|
interactor.reset(interactivityData, particle);
|
|
7062
7156
|
}
|
|
7063
7157
|
}
|
|
7064
7158
|
}
|
|
7065
7159
|
startObserving() {
|
|
7066
|
-
const
|
|
7067
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7068
|
-
this.
|
|
7160
|
+
const interactivityData = this.interactivityData;
|
|
7161
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7162
|
+
this.#intersectionObserver.observe(interactivityData.element);
|
|
7069
7163
|
}
|
|
7070
7164
|
}
|
|
7071
7165
|
stopObserving() {
|
|
7072
|
-
const
|
|
7073
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7074
|
-
this.
|
|
7166
|
+
const interactivityData = this.interactivityData;
|
|
7167
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7168
|
+
this.#intersectionObserver.unobserve(interactivityData.element);
|
|
7075
7169
|
}
|
|
7076
7170
|
}
|
|
7077
7171
|
updateMaxDistance() {
|
|
7078
7172
|
let maxTotalDistance = 0;
|
|
7079
|
-
for (const interactor of this
|
|
7173
|
+
for (const interactor of this.#interactors) {
|
|
7080
7174
|
if (interactor.maxDistance > maxTotalDistance) {
|
|
7081
7175
|
maxTotalDistance = interactor.maxDistance;
|
|
7082
7176
|
}
|
|
7083
7177
|
}
|
|
7084
|
-
const container = this
|
|
7178
|
+
const container = this.#container;
|
|
7085
7179
|
container.particles.grid.setCellSize(maxTotalDistance * container.retina.pixelRatio);
|
|
7086
7180
|
}
|
|
7087
|
-
|
|
7088
|
-
const
|
|
7181
|
+
#intersectionManager = entries => {
|
|
7182
|
+
const container = this.#container;
|
|
7089
7183
|
if (container.destroyed || !container.actualOptions.pauseOnOutsideViewport) {
|
|
7090
7184
|
return;
|
|
7091
7185
|
}
|
|
@@ -7105,13 +7199,13 @@
|
|
|
7105
7199
|
|
|
7106
7200
|
class InteractivityPluginInstance {
|
|
7107
7201
|
interactionManager;
|
|
7108
|
-
|
|
7109
|
-
|
|
7202
|
+
#container;
|
|
7203
|
+
#pluginManager;
|
|
7110
7204
|
constructor(pluginManager, container) {
|
|
7111
|
-
this
|
|
7112
|
-
this
|
|
7205
|
+
this.#container = container;
|
|
7206
|
+
this.#pluginManager = pluginManager;
|
|
7113
7207
|
this.interactionManager = new InteractionManager(pluginManager, container);
|
|
7114
|
-
this.
|
|
7208
|
+
this.#container.addClickHandler = (callback) => {
|
|
7115
7209
|
this.interactionManager.addClickHandler(callback);
|
|
7116
7210
|
};
|
|
7117
7211
|
}
|
|
@@ -7123,11 +7217,11 @@
|
|
|
7123
7217
|
}
|
|
7124
7218
|
destroy() {
|
|
7125
7219
|
this.clearClickHandlers();
|
|
7126
|
-
this.
|
|
7220
|
+
this.#pluginManager.interactors?.delete(this.#container);
|
|
7127
7221
|
}
|
|
7128
7222
|
particleCreated(particle) {
|
|
7129
|
-
const interactivityParticle = particle, interactivity = new Interactivity(this
|
|
7130
|
-
interactivity.load(this.
|
|
7223
|
+
const interactivityParticle = particle, interactivity = new Interactivity(this.#pluginManager, this.#container);
|
|
7224
|
+
interactivity.load(this.#container.actualOptions.interactivity);
|
|
7131
7225
|
interactivity.load(interactivityParticle.options.interactivity);
|
|
7132
7226
|
interactivityParticle.interactivity = interactivity;
|
|
7133
7227
|
}
|
|
@@ -7180,14 +7274,14 @@
|
|
|
7180
7274
|
|
|
7181
7275
|
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;
|
|
7182
7276
|
class LinkInstance {
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7277
|
+
#colorCache = new Map();
|
|
7278
|
+
#container;
|
|
7279
|
+
#freqs;
|
|
7280
|
+
#pluginManager;
|
|
7187
7281
|
constructor(pluginManager, container) {
|
|
7188
|
-
this
|
|
7189
|
-
this
|
|
7190
|
-
this
|
|
7282
|
+
this.#pluginManager = pluginManager;
|
|
7283
|
+
this.#container = container;
|
|
7284
|
+
this.#freqs = { links: new Map(), triangles: new Map() };
|
|
7191
7285
|
}
|
|
7192
7286
|
drawParticle(context, particle) {
|
|
7193
7287
|
const { links, options } = particle;
|
|
@@ -7204,13 +7298,13 @@
|
|
|
7204
7298
|
};
|
|
7205
7299
|
for (const link of links) {
|
|
7206
7300
|
if (linkOpts.frequency < maxFrequency &&
|
|
7207
|
-
this
|
|
7301
|
+
this.#getLinkFrequency(particle, link.destination) > linkOpts.frequency) {
|
|
7208
7302
|
continue;
|
|
7209
7303
|
}
|
|
7210
7304
|
const pos2 = link.destination.getPosition();
|
|
7211
7305
|
if (trianglesEnabled && !link.isWarped && p1Destinations) {
|
|
7212
7306
|
flushLines();
|
|
7213
|
-
this
|
|
7307
|
+
this.#drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);
|
|
7214
7308
|
}
|
|
7215
7309
|
if (link.opacity <= minOpacity || width <= minWidth) {
|
|
7216
7310
|
continue;
|
|
@@ -7220,7 +7314,7 @@
|
|
|
7220
7314
|
}
|
|
7221
7315
|
let opacity = link.opacity, colorLine = link.color;
|
|
7222
7316
|
const twinkleRgb = twinkle?.enable && getRandom() < twinkle.frequency
|
|
7223
|
-
? rangeColorToRgb(this
|
|
7317
|
+
? rangeColorToRgb(this.#pluginManager, twinkle.color)
|
|
7224
7318
|
: undefined;
|
|
7225
7319
|
if (twinkle && twinkleRgb) {
|
|
7226
7320
|
colorLine = twinkleRgb;
|
|
@@ -7228,14 +7322,14 @@
|
|
|
7228
7322
|
}
|
|
7229
7323
|
if (!colorLine) {
|
|
7230
7324
|
const linkColor = linkOpts.id !== undefined
|
|
7231
|
-
? this.
|
|
7232
|
-
: this.
|
|
7325
|
+
? this.#container.particles.linksColors.get(linkOpts.id)
|
|
7326
|
+
: this.#container.particles.linksColor;
|
|
7233
7327
|
colorLine = getLinkColor(particle, link.destination, linkColor);
|
|
7234
7328
|
}
|
|
7235
7329
|
if (!colorLine) {
|
|
7236
7330
|
continue;
|
|
7237
7331
|
}
|
|
7238
|
-
const colorStyle = this
|
|
7332
|
+
const colorStyle = this.#getCachedStyle(colorLine);
|
|
7239
7333
|
if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {
|
|
7240
7334
|
flushLines();
|
|
7241
7335
|
context.strokeStyle = colorStyle;
|
|
@@ -7248,7 +7342,7 @@
|
|
|
7248
7342
|
pathOpen = true;
|
|
7249
7343
|
}
|
|
7250
7344
|
if (link.isWarped) {
|
|
7251
|
-
const canvasSize = this.
|
|
7345
|
+
const canvasSize = this.#container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
7252
7346
|
let sx = originPoint.x, sy = originPoint.y;
|
|
7253
7347
|
if (Math.abs(dx) > canvasSize.width * half) {
|
|
7254
7348
|
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
@@ -7270,9 +7364,9 @@
|
|
|
7270
7364
|
context.globalAlpha = originalAlpha;
|
|
7271
7365
|
}
|
|
7272
7366
|
init() {
|
|
7273
|
-
this.
|
|
7274
|
-
this.
|
|
7275
|
-
this.
|
|
7367
|
+
this.#freqs.links.clear();
|
|
7368
|
+
this.#freqs.triangles.clear();
|
|
7369
|
+
this.#colorCache.clear();
|
|
7276
7370
|
return Promise.resolve();
|
|
7277
7371
|
}
|
|
7278
7372
|
particleCreated(particle) {
|
|
@@ -7282,14 +7376,14 @@
|
|
|
7282
7376
|
}
|
|
7283
7377
|
particle.linksDistance = particle.options.links.distance;
|
|
7284
7378
|
particle.linksWidth = particle.options.links.width;
|
|
7285
|
-
const ratio = this.
|
|
7379
|
+
const ratio = this.#container.retina.pixelRatio;
|
|
7286
7380
|
particle.retina.linksDistance = particle.linksDistance * ratio;
|
|
7287
7381
|
particle.retina.linksWidth = particle.linksWidth * ratio;
|
|
7288
7382
|
}
|
|
7289
7383
|
particleDestroyed(particle) {
|
|
7290
7384
|
particle.links = [];
|
|
7291
7385
|
}
|
|
7292
|
-
|
|
7386
|
+
#drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {
|
|
7293
7387
|
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
7294
7388
|
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
7295
7389
|
return;
|
|
@@ -7300,21 +7394,21 @@
|
|
|
7300
7394
|
}
|
|
7301
7395
|
for (const vertex of p2Links) {
|
|
7302
7396
|
if (vertex.isWarped ||
|
|
7303
|
-
this
|
|
7397
|
+
this.#getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency ||
|
|
7304
7398
|
!p1Destinations.has(vertex.destination.id)) {
|
|
7305
7399
|
continue;
|
|
7306
7400
|
}
|
|
7307
7401
|
const p3 = vertex.destination;
|
|
7308
|
-
if (this
|
|
7402
|
+
if (this.#getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
7309
7403
|
continue;
|
|
7310
7404
|
}
|
|
7311
|
-
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this
|
|
7405
|
+
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this.#pluginManager, triangleOptions.color) ?? link.color;
|
|
7312
7406
|
if (!colorTriangle || opacityTriangle <= minOpacity) {
|
|
7313
7407
|
continue;
|
|
7314
7408
|
}
|
|
7315
7409
|
const pos3 = p3.getPosition();
|
|
7316
7410
|
context.save();
|
|
7317
|
-
context.fillStyle = this
|
|
7411
|
+
context.fillStyle = this.#getCachedStyle(colorTriangle);
|
|
7318
7412
|
context.globalAlpha = opacityTriangle;
|
|
7319
7413
|
context.beginPath();
|
|
7320
7414
|
context.moveTo(pos1.x, pos1.y);
|
|
@@ -7325,20 +7419,20 @@
|
|
|
7325
7419
|
context.restore();
|
|
7326
7420
|
}
|
|
7327
7421
|
}
|
|
7328
|
-
|
|
7422
|
+
#getCachedStyle(rgb) {
|
|
7329
7423
|
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
7330
|
-
let style = this.
|
|
7424
|
+
let style = this.#colorCache.get(key);
|
|
7331
7425
|
if (!style) {
|
|
7332
|
-
style = getStyleFromRgb(rgb, this.
|
|
7333
|
-
this.
|
|
7426
|
+
style = getStyleFromRgb(rgb, this.#container.hdr);
|
|
7427
|
+
this.#colorCache.set(key, style);
|
|
7334
7428
|
}
|
|
7335
7429
|
return style;
|
|
7336
7430
|
}
|
|
7337
|
-
|
|
7338
|
-
return setLinkFrequency([p1, p2], this.
|
|
7431
|
+
#getLinkFrequency(p1, p2) {
|
|
7432
|
+
return setLinkFrequency([p1, p2], this.#freqs.links);
|
|
7339
7433
|
}
|
|
7340
|
-
|
|
7341
|
-
return setLinkFrequency([p1, p2, p3], this.
|
|
7434
|
+
#getTriangleFrequency(p1, p2, p3) {
|
|
7435
|
+
return setLinkFrequency([p1, p2, p3], this.#freqs.triangles);
|
|
7342
7436
|
}
|
|
7343
7437
|
}
|
|
7344
7438
|
|