@tsparticles/preset-triangles 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);
|
|
@@ -4326,58 +4343,58 @@
|
|
|
4326
4343
|
}
|
|
4327
4344
|
}
|
|
4328
4345
|
class RenderManager {
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4346
|
+
#canvasClearPlugins;
|
|
4347
|
+
#canvasManager;
|
|
4348
|
+
#canvasPaintPlugins;
|
|
4349
|
+
#clearDrawPlugins;
|
|
4350
|
+
#colorPlugins;
|
|
4351
|
+
#container;
|
|
4352
|
+
#context;
|
|
4353
|
+
#contextSettings;
|
|
4354
|
+
#drawParticlePlugins;
|
|
4355
|
+
#drawParticlesCleanupPlugins;
|
|
4356
|
+
#drawParticlesSetupPlugins;
|
|
4357
|
+
#drawPlugins;
|
|
4358
|
+
#drawSettingsCleanupPlugins;
|
|
4359
|
+
#drawSettingsSetupPlugins;
|
|
4360
|
+
#pluginManager;
|
|
4361
|
+
#postDrawUpdaters;
|
|
4362
|
+
#preDrawUpdaters;
|
|
4363
|
+
#reusableColorStyles = {};
|
|
4364
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4365
|
+
#reusableTransform = {};
|
|
4349
4366
|
constructor(pluginManager, container, canvasManager) {
|
|
4350
|
-
this
|
|
4351
|
-
this
|
|
4352
|
-
this
|
|
4353
|
-
this
|
|
4354
|
-
this
|
|
4355
|
-
this
|
|
4356
|
-
this
|
|
4357
|
-
this
|
|
4358
|
-
this
|
|
4359
|
-
this
|
|
4360
|
-
this
|
|
4361
|
-
this
|
|
4362
|
-
this
|
|
4363
|
-
this
|
|
4364
|
-
this
|
|
4365
|
-
this
|
|
4367
|
+
this.#pluginManager = pluginManager;
|
|
4368
|
+
this.#container = container;
|
|
4369
|
+
this.#canvasManager = canvasManager;
|
|
4370
|
+
this.#context = null;
|
|
4371
|
+
this.#preDrawUpdaters = [];
|
|
4372
|
+
this.#postDrawUpdaters = [];
|
|
4373
|
+
this.#colorPlugins = [];
|
|
4374
|
+
this.#canvasClearPlugins = [];
|
|
4375
|
+
this.#canvasPaintPlugins = [];
|
|
4376
|
+
this.#clearDrawPlugins = [];
|
|
4377
|
+
this.#drawParticlePlugins = [];
|
|
4378
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4379
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4380
|
+
this.#drawPlugins = [];
|
|
4381
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4382
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4366
4383
|
}
|
|
4367
4384
|
get settings() {
|
|
4368
|
-
return this
|
|
4385
|
+
return this.#contextSettings;
|
|
4369
4386
|
}
|
|
4370
4387
|
canvasClear() {
|
|
4371
|
-
if (!this.
|
|
4388
|
+
if (!this.#container.actualOptions.clear) {
|
|
4372
4389
|
return;
|
|
4373
4390
|
}
|
|
4374
4391
|
this.draw(ctx => {
|
|
4375
|
-
clear(ctx, this.
|
|
4392
|
+
clear(ctx, this.#canvasManager.size);
|
|
4376
4393
|
});
|
|
4377
4394
|
}
|
|
4378
4395
|
clear() {
|
|
4379
4396
|
let pluginHandled = false;
|
|
4380
|
-
for (const plugin of this
|
|
4397
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4381
4398
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4382
4399
|
if (pluginHandled) {
|
|
4383
4400
|
break;
|
|
@@ -4390,21 +4407,21 @@
|
|
|
4390
4407
|
}
|
|
4391
4408
|
destroy() {
|
|
4392
4409
|
this.stop();
|
|
4393
|
-
this
|
|
4394
|
-
this
|
|
4395
|
-
this
|
|
4396
|
-
this
|
|
4397
|
-
this
|
|
4398
|
-
this
|
|
4399
|
-
this
|
|
4400
|
-
this
|
|
4401
|
-
this
|
|
4402
|
-
this
|
|
4403
|
-
this
|
|
4404
|
-
this
|
|
4410
|
+
this.#preDrawUpdaters = [];
|
|
4411
|
+
this.#postDrawUpdaters = [];
|
|
4412
|
+
this.#colorPlugins = [];
|
|
4413
|
+
this.#canvasClearPlugins = [];
|
|
4414
|
+
this.#canvasPaintPlugins = [];
|
|
4415
|
+
this.#clearDrawPlugins = [];
|
|
4416
|
+
this.#drawParticlePlugins = [];
|
|
4417
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4418
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4419
|
+
this.#drawPlugins = [];
|
|
4420
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4421
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4405
4422
|
}
|
|
4406
4423
|
draw(cb) {
|
|
4407
|
-
const ctx = this
|
|
4424
|
+
const ctx = this.#context;
|
|
4408
4425
|
if (!ctx) {
|
|
4409
4426
|
return;
|
|
4410
4427
|
}
|
|
@@ -4419,21 +4436,21 @@
|
|
|
4419
4436
|
return;
|
|
4420
4437
|
}
|
|
4421
4438
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4422
|
-
let [fColor, sColor] = this
|
|
4439
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4423
4440
|
fColor ??= pfColor;
|
|
4424
4441
|
sColor ??= psColor;
|
|
4425
4442
|
if (!fColor && !sColor) {
|
|
4426
4443
|
return;
|
|
4427
4444
|
}
|
|
4428
|
-
const container = this
|
|
4445
|
+
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;
|
|
4429
4446
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4430
4447
|
colorStyles.fill = fill;
|
|
4431
4448
|
colorStyles.stroke = stroke;
|
|
4432
4449
|
this.draw((context) => {
|
|
4433
|
-
for (const plugin of this
|
|
4450
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4434
4451
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4435
4452
|
}
|
|
4436
|
-
this
|
|
4453
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4437
4454
|
drawParticle({
|
|
4438
4455
|
container,
|
|
4439
4456
|
context,
|
|
@@ -4444,35 +4461,35 @@
|
|
|
4444
4461
|
opacity: opacity,
|
|
4445
4462
|
transform,
|
|
4446
4463
|
});
|
|
4447
|
-
this
|
|
4448
|
-
for (const plugin of this
|
|
4464
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4465
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4449
4466
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4450
4467
|
}
|
|
4451
4468
|
});
|
|
4452
4469
|
}
|
|
4453
4470
|
drawParticlePlugins(particle, delta) {
|
|
4454
4471
|
this.draw(ctx => {
|
|
4455
|
-
for (const plugin of this
|
|
4472
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4456
4473
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4457
4474
|
}
|
|
4458
4475
|
});
|
|
4459
4476
|
}
|
|
4460
4477
|
drawParticles(delta) {
|
|
4461
|
-
const { particles } = this
|
|
4478
|
+
const { particles } = this.#container;
|
|
4462
4479
|
this.clear();
|
|
4463
4480
|
particles.update(delta);
|
|
4464
4481
|
this.draw(ctx => {
|
|
4465
|
-
for (const plugin of this
|
|
4482
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4466
4483
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4467
4484
|
}
|
|
4468
|
-
for (const plugin of this
|
|
4485
|
+
for (const plugin of this.#drawPlugins) {
|
|
4469
4486
|
plugin.draw?.(ctx, delta);
|
|
4470
4487
|
}
|
|
4471
4488
|
particles.drawParticles(delta);
|
|
4472
|
-
for (const plugin of this
|
|
4489
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4473
4490
|
plugin.clearDraw?.(ctx, delta);
|
|
4474
4491
|
}
|
|
4475
|
-
for (const plugin of this
|
|
4492
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4476
4493
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4477
4494
|
}
|
|
4478
4495
|
});
|
|
@@ -4483,64 +4500,64 @@
|
|
|
4483
4500
|
this.paint();
|
|
4484
4501
|
}
|
|
4485
4502
|
initPlugins() {
|
|
4486
|
-
this
|
|
4487
|
-
this
|
|
4488
|
-
this
|
|
4489
|
-
this
|
|
4490
|
-
this
|
|
4491
|
-
this
|
|
4492
|
-
this
|
|
4493
|
-
this
|
|
4494
|
-
this
|
|
4495
|
-
this
|
|
4496
|
-
for (const plugin of this.
|
|
4503
|
+
this.#colorPlugins = [];
|
|
4504
|
+
this.#canvasClearPlugins = [];
|
|
4505
|
+
this.#canvasPaintPlugins = [];
|
|
4506
|
+
this.#clearDrawPlugins = [];
|
|
4507
|
+
this.#drawParticlePlugins = [];
|
|
4508
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4509
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4510
|
+
this.#drawPlugins = [];
|
|
4511
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4512
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4513
|
+
for (const plugin of this.#container.plugins) {
|
|
4497
4514
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4498
|
-
this.
|
|
4515
|
+
this.#colorPlugins.push(plugin);
|
|
4499
4516
|
}
|
|
4500
4517
|
if (plugin.canvasClear) {
|
|
4501
|
-
this.
|
|
4518
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4502
4519
|
}
|
|
4503
4520
|
if (plugin.canvasPaint) {
|
|
4504
|
-
this.
|
|
4521
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4505
4522
|
}
|
|
4506
4523
|
if (plugin.drawParticle) {
|
|
4507
|
-
this.
|
|
4524
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4508
4525
|
}
|
|
4509
4526
|
if (plugin.drawParticleSetup) {
|
|
4510
|
-
this.
|
|
4527
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4511
4528
|
}
|
|
4512
4529
|
if (plugin.drawParticleCleanup) {
|
|
4513
|
-
this.
|
|
4530
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4514
4531
|
}
|
|
4515
4532
|
if (plugin.draw) {
|
|
4516
|
-
this.
|
|
4533
|
+
this.#drawPlugins.push(plugin);
|
|
4517
4534
|
}
|
|
4518
4535
|
if (plugin.drawSettingsSetup) {
|
|
4519
|
-
this.
|
|
4536
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4520
4537
|
}
|
|
4521
4538
|
if (plugin.drawSettingsCleanup) {
|
|
4522
|
-
this.
|
|
4539
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4523
4540
|
}
|
|
4524
4541
|
if (plugin.clearDraw) {
|
|
4525
|
-
this.
|
|
4542
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4526
4543
|
}
|
|
4527
4544
|
}
|
|
4528
4545
|
}
|
|
4529
4546
|
initUpdaters() {
|
|
4530
|
-
this
|
|
4531
|
-
this
|
|
4532
|
-
for (const updater of this.
|
|
4547
|
+
this.#preDrawUpdaters = [];
|
|
4548
|
+
this.#postDrawUpdaters = [];
|
|
4549
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4533
4550
|
if (updater.afterDraw) {
|
|
4534
|
-
this.
|
|
4551
|
+
this.#postDrawUpdaters.push(updater);
|
|
4535
4552
|
}
|
|
4536
4553
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4537
|
-
this.
|
|
4554
|
+
this.#preDrawUpdaters.push(updater);
|
|
4538
4555
|
}
|
|
4539
4556
|
}
|
|
4540
4557
|
}
|
|
4541
4558
|
paint() {
|
|
4542
4559
|
let handled = false;
|
|
4543
|
-
for (const plugin of this
|
|
4560
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4544
4561
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4545
4562
|
if (handled) {
|
|
4546
4563
|
break;
|
|
@@ -4553,35 +4570,35 @@
|
|
|
4553
4570
|
}
|
|
4554
4571
|
paintBase(baseColor) {
|
|
4555
4572
|
this.draw(ctx => {
|
|
4556
|
-
paintBase(ctx, this.
|
|
4573
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4557
4574
|
});
|
|
4558
4575
|
}
|
|
4559
4576
|
paintImage(image, opacity) {
|
|
4560
4577
|
this.draw(ctx => {
|
|
4561
|
-
paintImage(ctx, this.
|
|
4578
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4562
4579
|
});
|
|
4563
4580
|
}
|
|
4564
4581
|
setContext(context) {
|
|
4565
|
-
this
|
|
4566
|
-
if (this
|
|
4567
|
-
this.
|
|
4582
|
+
this.#context = context;
|
|
4583
|
+
if (this.#context) {
|
|
4584
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4568
4585
|
}
|
|
4569
4586
|
}
|
|
4570
4587
|
setContextSettings(settings) {
|
|
4571
|
-
this
|
|
4588
|
+
this.#contextSettings = settings;
|
|
4572
4589
|
}
|
|
4573
4590
|
stop() {
|
|
4574
4591
|
this.draw(ctx => {
|
|
4575
|
-
clear(ctx, this.
|
|
4592
|
+
clear(ctx, this.#canvasManager.size);
|
|
4576
4593
|
});
|
|
4577
4594
|
}
|
|
4578
|
-
|
|
4579
|
-
for (const updater of this
|
|
4595
|
+
#applyPostDrawUpdaters = particle => {
|
|
4596
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4580
4597
|
updater.afterDraw?.(particle);
|
|
4581
4598
|
}
|
|
4582
4599
|
};
|
|
4583
|
-
|
|
4584
|
-
for (const updater of this
|
|
4600
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4601
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4585
4602
|
if (updater.getColorStyles) {
|
|
4586
4603
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4587
4604
|
if (fill) {
|
|
@@ -4600,22 +4617,22 @@
|
|
|
4600
4617
|
updater.beforeDraw?.(particle);
|
|
4601
4618
|
}
|
|
4602
4619
|
};
|
|
4603
|
-
|
|
4620
|
+
#getPluginParticleColors = particle => {
|
|
4604
4621
|
let fColor, sColor;
|
|
4605
|
-
for (const plugin of this
|
|
4622
|
+
for (const plugin of this.#colorPlugins) {
|
|
4606
4623
|
if (!fColor && plugin.particleFillColor) {
|
|
4607
|
-
fColor = rangeColorToHsl(this
|
|
4624
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4608
4625
|
}
|
|
4609
4626
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4610
|
-
sColor = rangeColorToHsl(this
|
|
4627
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4611
4628
|
}
|
|
4612
4629
|
if (fColor && sColor) {
|
|
4613
4630
|
break;
|
|
4614
4631
|
}
|
|
4615
4632
|
}
|
|
4616
|
-
this
|
|
4617
|
-
this
|
|
4618
|
-
return this
|
|
4633
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4634
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4635
|
+
return this.#reusablePluginColors;
|
|
4619
4636
|
};
|
|
4620
4637
|
}
|
|
4621
4638
|
|
|
@@ -4673,53 +4690,53 @@
|
|
|
4673
4690
|
renderCanvas;
|
|
4674
4691
|
size;
|
|
4675
4692
|
zoom = defaultZoom;
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4693
|
+
#container;
|
|
4694
|
+
#generated;
|
|
4695
|
+
#mutationObserver;
|
|
4696
|
+
#originalStyle;
|
|
4697
|
+
#pluginManager;
|
|
4698
|
+
#pointerEvents;
|
|
4699
|
+
#resizePlugins;
|
|
4700
|
+
#standardSize;
|
|
4701
|
+
#zoomCenter;
|
|
4685
4702
|
constructor(pluginManager, container) {
|
|
4686
|
-
this
|
|
4687
|
-
this
|
|
4703
|
+
this.#pluginManager = pluginManager;
|
|
4704
|
+
this.#container = container;
|
|
4688
4705
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4689
|
-
this
|
|
4706
|
+
this.#standardSize = {
|
|
4690
4707
|
height: 0,
|
|
4691
4708
|
width: 0,
|
|
4692
4709
|
};
|
|
4693
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4710
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4694
4711
|
this.size = {
|
|
4695
4712
|
height: stdSize.height * pxRatio,
|
|
4696
4713
|
width: stdSize.width * pxRatio,
|
|
4697
4714
|
};
|
|
4698
|
-
this
|
|
4699
|
-
this
|
|
4700
|
-
this
|
|
4715
|
+
this.#generated = false;
|
|
4716
|
+
this.#resizePlugins = [];
|
|
4717
|
+
this.#pointerEvents = "none";
|
|
4701
4718
|
}
|
|
4702
|
-
get
|
|
4703
|
-
return this.
|
|
4719
|
+
get #fullScreen() {
|
|
4720
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4704
4721
|
}
|
|
4705
4722
|
destroy() {
|
|
4706
4723
|
this.stop();
|
|
4707
|
-
if (this
|
|
4724
|
+
if (this.#generated) {
|
|
4708
4725
|
const element = this.domElement;
|
|
4709
4726
|
element?.remove();
|
|
4710
4727
|
this.domElement = undefined;
|
|
4711
4728
|
this.renderCanvas = undefined;
|
|
4712
4729
|
}
|
|
4713
4730
|
else {
|
|
4714
|
-
this
|
|
4731
|
+
this.#resetOriginalStyle();
|
|
4715
4732
|
}
|
|
4716
4733
|
this.render.destroy();
|
|
4717
|
-
this
|
|
4734
|
+
this.#resizePlugins = [];
|
|
4718
4735
|
}
|
|
4719
4736
|
getZoomCenter() {
|
|
4720
|
-
const pxRatio = this.
|
|
4721
|
-
if (this
|
|
4722
|
-
return this
|
|
4737
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4738
|
+
if (this.#zoomCenter) {
|
|
4739
|
+
return this.#zoomCenter;
|
|
4723
4740
|
}
|
|
4724
4741
|
return {
|
|
4725
4742
|
x: (width * half) / pxRatio,
|
|
@@ -4727,20 +4744,20 @@
|
|
|
4727
4744
|
};
|
|
4728
4745
|
}
|
|
4729
4746
|
init() {
|
|
4730
|
-
this
|
|
4747
|
+
this.#safeMutationObserver(obs => {
|
|
4731
4748
|
obs.disconnect();
|
|
4732
4749
|
});
|
|
4733
|
-
this
|
|
4750
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4734
4751
|
for (const record of records) {
|
|
4735
4752
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4736
|
-
this
|
|
4753
|
+
this.#repairStyle();
|
|
4737
4754
|
}
|
|
4738
4755
|
}
|
|
4739
4756
|
});
|
|
4740
4757
|
this.resize();
|
|
4741
|
-
this
|
|
4758
|
+
this.#initStyle();
|
|
4742
4759
|
this.initBackground();
|
|
4743
|
-
this
|
|
4760
|
+
this.#safeMutationObserver(obs => {
|
|
4744
4761
|
const element = this.domElement;
|
|
4745
4762
|
if (!element || !(element instanceof Node)) {
|
|
4746
4763
|
return;
|
|
@@ -4751,13 +4768,13 @@
|
|
|
4751
4768
|
this.render.init();
|
|
4752
4769
|
}
|
|
4753
4770
|
initBackground() {
|
|
4754
|
-
const
|
|
4771
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4755
4772
|
if (!element) {
|
|
4756
4773
|
return;
|
|
4757
4774
|
}
|
|
4758
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4775
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4759
4776
|
if (color) {
|
|
4760
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4777
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4761
4778
|
}
|
|
4762
4779
|
else {
|
|
4763
4780
|
elementStyle.backgroundColor = "";
|
|
@@ -4768,27 +4785,27 @@
|
|
|
4768
4785
|
elementStyle.backgroundSize = background.size || "";
|
|
4769
4786
|
}
|
|
4770
4787
|
initPlugins() {
|
|
4771
|
-
this
|
|
4772
|
-
for (const plugin of this.
|
|
4788
|
+
this.#resizePlugins = [];
|
|
4789
|
+
for (const plugin of this.#container.plugins) {
|
|
4773
4790
|
if (plugin.resize) {
|
|
4774
|
-
this.
|
|
4791
|
+
this.#resizePlugins.push(plugin);
|
|
4775
4792
|
}
|
|
4776
4793
|
}
|
|
4777
4794
|
}
|
|
4778
4795
|
loadCanvas(canvas) {
|
|
4779
|
-
if (this
|
|
4796
|
+
if (this.#generated && this.domElement) {
|
|
4780
4797
|
this.domElement.remove();
|
|
4781
4798
|
}
|
|
4782
|
-
const container = this
|
|
4799
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4783
4800
|
this.domElement = domCanvas;
|
|
4784
|
-
this
|
|
4801
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4785
4802
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4786
4803
|
const domElement = this.domElement;
|
|
4787
4804
|
if (domElement) {
|
|
4788
4805
|
domElement.ariaHidden = "true";
|
|
4789
|
-
this
|
|
4806
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4790
4807
|
}
|
|
4791
|
-
const standardSize = this
|
|
4808
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4792
4809
|
if (domElement) {
|
|
4793
4810
|
standardSize.height = domElement.offsetHeight;
|
|
4794
4811
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4797,7 +4814,7 @@
|
|
|
4797
4814
|
standardSize.height = renderCanvas.height;
|
|
4798
4815
|
standardSize.width = renderCanvas.width;
|
|
4799
4816
|
}
|
|
4800
|
-
const pxRatio = this.
|
|
4817
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4801
4818
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4802
4819
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4803
4820
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4808,12 +4825,12 @@
|
|
|
4808
4825
|
willReadFrequently: false,
|
|
4809
4826
|
});
|
|
4810
4827
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4811
|
-
this
|
|
4828
|
+
this.#safeMutationObserver(obs => {
|
|
4812
4829
|
obs.disconnect();
|
|
4813
4830
|
});
|
|
4814
4831
|
container.retina.init();
|
|
4815
4832
|
this.initBackground();
|
|
4816
|
-
this
|
|
4833
|
+
this.#safeMutationObserver(obs => {
|
|
4817
4834
|
const element = this.domElement;
|
|
4818
4835
|
if (!element || !(element instanceof Node)) {
|
|
4819
4836
|
return;
|
|
@@ -4826,11 +4843,11 @@
|
|
|
4826
4843
|
if (!element) {
|
|
4827
4844
|
return false;
|
|
4828
4845
|
}
|
|
4829
|
-
const container = this
|
|
4846
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4830
4847
|
if (renderCanvas === undefined) {
|
|
4831
4848
|
return false;
|
|
4832
4849
|
}
|
|
4833
|
-
const currentSize = container.canvas
|
|
4850
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4834
4851
|
width: element.offsetWidth,
|
|
4835
4852
|
height: element.offsetHeight,
|
|
4836
4853
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4849,7 +4866,7 @@
|
|
|
4849
4866
|
const canvasSize = this.size;
|
|
4850
4867
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4851
4868
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4852
|
-
if (this.
|
|
4869
|
+
if (this.#container.started) {
|
|
4853
4870
|
container.particles.setResizeFactor({
|
|
4854
4871
|
width: currentSize.width / oldSize.width,
|
|
4855
4872
|
height: currentSize.height / oldSize.height,
|
|
@@ -4862,46 +4879,46 @@
|
|
|
4862
4879
|
if (!element) {
|
|
4863
4880
|
return;
|
|
4864
4881
|
}
|
|
4865
|
-
this
|
|
4866
|
-
this
|
|
4882
|
+
this.#pointerEvents = type;
|
|
4883
|
+
this.#repairStyle();
|
|
4867
4884
|
}
|
|
4868
4885
|
setZoom(zoomLevel, center) {
|
|
4869
4886
|
this.zoom = zoomLevel;
|
|
4870
|
-
this
|
|
4887
|
+
this.#zoomCenter = center;
|
|
4871
4888
|
}
|
|
4872
4889
|
stop() {
|
|
4873
|
-
this
|
|
4890
|
+
this.#safeMutationObserver(obs => {
|
|
4874
4891
|
obs.disconnect();
|
|
4875
4892
|
});
|
|
4876
|
-
this
|
|
4893
|
+
this.#mutationObserver = undefined;
|
|
4877
4894
|
this.render.stop();
|
|
4878
4895
|
}
|
|
4879
4896
|
async windowResize() {
|
|
4880
4897
|
if (!this.domElement || !this.resize()) {
|
|
4881
4898
|
return;
|
|
4882
4899
|
}
|
|
4883
|
-
const container = this
|
|
4900
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4884
4901
|
container.particles.setDensity();
|
|
4885
|
-
this
|
|
4902
|
+
this.#applyResizePlugins();
|
|
4886
4903
|
if (needsRefresh) {
|
|
4887
4904
|
await container.refresh();
|
|
4888
4905
|
}
|
|
4889
4906
|
}
|
|
4890
|
-
|
|
4891
|
-
for (const plugin of this
|
|
4907
|
+
#applyResizePlugins = () => {
|
|
4908
|
+
for (const plugin of this.#resizePlugins) {
|
|
4892
4909
|
plugin.resize?.();
|
|
4893
4910
|
}
|
|
4894
4911
|
};
|
|
4895
|
-
|
|
4896
|
-
const element = this.domElement, options = this.
|
|
4912
|
+
#initStyle = () => {
|
|
4913
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4897
4914
|
if (!element) {
|
|
4898
4915
|
return;
|
|
4899
4916
|
}
|
|
4900
|
-
if (this
|
|
4901
|
-
this
|
|
4917
|
+
if (this.#fullScreen) {
|
|
4918
|
+
this.#setFullScreenStyle();
|
|
4902
4919
|
}
|
|
4903
4920
|
else {
|
|
4904
|
-
this
|
|
4921
|
+
this.#resetOriginalStyle();
|
|
4905
4922
|
}
|
|
4906
4923
|
for (const key in options.style) {
|
|
4907
4924
|
if (!key || !(key in options.style)) {
|
|
@@ -4914,72 +4931,72 @@
|
|
|
4914
4931
|
element.style.setProperty(key, value, "important");
|
|
4915
4932
|
}
|
|
4916
4933
|
};
|
|
4917
|
-
|
|
4934
|
+
#repairStyle = () => {
|
|
4918
4935
|
const element = this.domElement;
|
|
4919
4936
|
if (!element) {
|
|
4920
4937
|
return;
|
|
4921
4938
|
}
|
|
4922
|
-
this
|
|
4939
|
+
this.#safeMutationObserver(observer => {
|
|
4923
4940
|
observer.disconnect();
|
|
4924
4941
|
});
|
|
4925
|
-
this
|
|
4942
|
+
this.#initStyle();
|
|
4926
4943
|
this.initBackground();
|
|
4927
|
-
const pointerEvents = this
|
|
4944
|
+
const pointerEvents = this.#pointerEvents;
|
|
4928
4945
|
element.style.pointerEvents = pointerEvents;
|
|
4929
4946
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4930
|
-
this
|
|
4947
|
+
this.#safeMutationObserver(observer => {
|
|
4931
4948
|
if (!(element instanceof Node)) {
|
|
4932
4949
|
return;
|
|
4933
4950
|
}
|
|
4934
4951
|
observer.observe(element, { attributes: true });
|
|
4935
4952
|
});
|
|
4936
4953
|
};
|
|
4937
|
-
|
|
4938
|
-
const element = this.domElement, originalStyle = this
|
|
4954
|
+
#resetOriginalStyle = () => {
|
|
4955
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4939
4956
|
if (!element || !originalStyle) {
|
|
4940
4957
|
return;
|
|
4941
4958
|
}
|
|
4942
4959
|
setStyle(element, originalStyle, true);
|
|
4943
4960
|
};
|
|
4944
|
-
|
|
4945
|
-
if (!this
|
|
4961
|
+
#safeMutationObserver = callback => {
|
|
4962
|
+
if (!this.#mutationObserver) {
|
|
4946
4963
|
return;
|
|
4947
4964
|
}
|
|
4948
|
-
callback(this
|
|
4965
|
+
callback(this.#mutationObserver);
|
|
4949
4966
|
};
|
|
4950
|
-
|
|
4967
|
+
#setFullScreenStyle = () => {
|
|
4951
4968
|
const element = this.domElement;
|
|
4952
4969
|
if (!element) {
|
|
4953
4970
|
return;
|
|
4954
4971
|
}
|
|
4955
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4972
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4956
4973
|
};
|
|
4957
4974
|
}
|
|
4958
4975
|
|
|
4959
4976
|
class EventListeners {
|
|
4960
|
-
container;
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4977
|
+
#container;
|
|
4978
|
+
#handlers;
|
|
4979
|
+
#resizeObserver;
|
|
4980
|
+
#resizeTimeout;
|
|
4964
4981
|
constructor(container) {
|
|
4965
|
-
this
|
|
4966
|
-
this
|
|
4982
|
+
this.#container = container;
|
|
4983
|
+
this.#handlers = {
|
|
4967
4984
|
visibilityChange: () => {
|
|
4968
|
-
this
|
|
4985
|
+
this.#handleVisibilityChange();
|
|
4969
4986
|
},
|
|
4970
4987
|
resize: () => {
|
|
4971
|
-
this
|
|
4988
|
+
this.#handleWindowResize();
|
|
4972
4989
|
},
|
|
4973
4990
|
};
|
|
4974
4991
|
}
|
|
4975
4992
|
addListeners() {
|
|
4976
|
-
this
|
|
4993
|
+
this.#manageListeners(true);
|
|
4977
4994
|
}
|
|
4978
4995
|
removeListeners() {
|
|
4979
|
-
this
|
|
4996
|
+
this.#manageListeners(false);
|
|
4980
4997
|
}
|
|
4981
|
-
|
|
4982
|
-
const container = this
|
|
4998
|
+
#handleVisibilityChange = () => {
|
|
4999
|
+
const container = this.#container, options = container.actualOptions;
|
|
4983
5000
|
if (!options.pauseOnBlur) {
|
|
4984
5001
|
return;
|
|
4985
5002
|
}
|
|
@@ -4997,24 +5014,24 @@
|
|
|
4997
5014
|
}
|
|
4998
5015
|
}
|
|
4999
5016
|
};
|
|
5000
|
-
|
|
5001
|
-
if (this
|
|
5002
|
-
clearTimeout(this
|
|
5003
|
-
|
|
5017
|
+
#handleWindowResize = () => {
|
|
5018
|
+
if (this.#resizeTimeout) {
|
|
5019
|
+
clearTimeout(this.#resizeTimeout);
|
|
5020
|
+
this.#resizeTimeout = undefined;
|
|
5004
5021
|
}
|
|
5005
5022
|
const handleResize = async () => {
|
|
5006
|
-
const canvas = this
|
|
5023
|
+
const canvas = this.#container.canvas;
|
|
5007
5024
|
await canvas.windowResize();
|
|
5008
5025
|
};
|
|
5009
|
-
this
|
|
5026
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5010
5027
|
};
|
|
5011
|
-
|
|
5012
|
-
const handlers = this
|
|
5013
|
-
this
|
|
5028
|
+
#manageListeners = add => {
|
|
5029
|
+
const handlers = this.#handlers;
|
|
5030
|
+
this.#manageResize(add);
|
|
5014
5031
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5015
5032
|
};
|
|
5016
|
-
|
|
5017
|
-
const handlers = this
|
|
5033
|
+
#manageResize = add => {
|
|
5034
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5018
5035
|
if (!options.resize.enable) {
|
|
5019
5036
|
return;
|
|
5020
5037
|
}
|
|
@@ -5023,22 +5040,22 @@
|
|
|
5023
5040
|
return;
|
|
5024
5041
|
}
|
|
5025
5042
|
const canvasEl = container.canvas.domElement;
|
|
5026
|
-
if (this
|
|
5043
|
+
if (this.#resizeObserver && !add) {
|
|
5027
5044
|
if (canvasEl) {
|
|
5028
|
-
this.
|
|
5045
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5029
5046
|
}
|
|
5030
|
-
this.
|
|
5031
|
-
|
|
5047
|
+
this.#resizeObserver.disconnect();
|
|
5048
|
+
this.#resizeObserver = undefined;
|
|
5032
5049
|
}
|
|
5033
|
-
else if (!this
|
|
5034
|
-
this
|
|
5050
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5051
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5035
5052
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5036
5053
|
if (!entry) {
|
|
5037
5054
|
return;
|
|
5038
5055
|
}
|
|
5039
|
-
this
|
|
5056
|
+
this.#handleWindowResize();
|
|
5040
5057
|
});
|
|
5041
|
-
this.
|
|
5058
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5042
5059
|
}
|
|
5043
5060
|
};
|
|
5044
5061
|
}
|
|
@@ -5111,24 +5128,24 @@
|
|
|
5111
5128
|
unbreakable;
|
|
5112
5129
|
velocity;
|
|
5113
5130
|
zIndexFactor;
|
|
5114
|
-
|
|
5131
|
+
#cachedOpacityData = {
|
|
5115
5132
|
fillOpacity: defaultOpacity$1,
|
|
5116
5133
|
opacity: defaultOpacity$1,
|
|
5117
5134
|
strokeOpacity: defaultOpacity$1,
|
|
5118
5135
|
};
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5136
|
+
#cachedPosition = Vector3d.origin;
|
|
5137
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5138
|
+
#cachedTransform = {
|
|
5122
5139
|
a: 1,
|
|
5123
5140
|
b: 0,
|
|
5124
5141
|
c: 0,
|
|
5125
5142
|
d: 1,
|
|
5126
5143
|
};
|
|
5127
|
-
|
|
5128
|
-
|
|
5144
|
+
#container;
|
|
5145
|
+
#pluginManager;
|
|
5129
5146
|
constructor(pluginManager, container) {
|
|
5130
|
-
this
|
|
5131
|
-
this
|
|
5147
|
+
this.#pluginManager = pluginManager;
|
|
5148
|
+
this.#container = container;
|
|
5132
5149
|
}
|
|
5133
5150
|
destroy(override) {
|
|
5134
5151
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5137,7 +5154,7 @@
|
|
|
5137
5154
|
this.destroyed = true;
|
|
5138
5155
|
this.bubble.inRange = false;
|
|
5139
5156
|
this.slow.inRange = false;
|
|
5140
|
-
const container = this
|
|
5157
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5141
5158
|
shapeDrawer?.particleDestroy?.(this);
|
|
5142
5159
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5143
5160
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5145,12 +5162,12 @@
|
|
|
5145
5162
|
for (const updater of container.particleUpdaters) {
|
|
5146
5163
|
updater.particleDestroyed?.(this, override);
|
|
5147
5164
|
}
|
|
5148
|
-
this.
|
|
5165
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5149
5166
|
particle: this,
|
|
5150
5167
|
});
|
|
5151
5168
|
}
|
|
5152
5169
|
draw(delta) {
|
|
5153
|
-
const container = this
|
|
5170
|
+
const container = this.#container, render = container.canvas.render;
|
|
5154
5171
|
render.drawParticlePlugins(this, delta);
|
|
5155
5172
|
render.drawParticle(this, delta);
|
|
5156
5173
|
}
|
|
@@ -5158,50 +5175,50 @@
|
|
|
5158
5175
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5159
5176
|
}
|
|
5160
5177
|
getFillColor() {
|
|
5161
|
-
return this
|
|
5178
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5162
5179
|
}
|
|
5163
5180
|
getMass() {
|
|
5164
5181
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5165
5182
|
}
|
|
5166
5183
|
getOpacity() {
|
|
5167
5184
|
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;
|
|
5168
|
-
this.
|
|
5169
|
-
this.
|
|
5170
|
-
this.
|
|
5171
|
-
return this
|
|
5185
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5186
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5187
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5188
|
+
return this.#cachedOpacityData;
|
|
5172
5189
|
}
|
|
5173
5190
|
getPosition() {
|
|
5174
|
-
this.
|
|
5175
|
-
this.
|
|
5176
|
-
this.
|
|
5177
|
-
return this
|
|
5191
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5192
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5193
|
+
this.#cachedPosition.z = this.position.z;
|
|
5194
|
+
return this.#cachedPosition;
|
|
5178
5195
|
}
|
|
5179
5196
|
getRadius() {
|
|
5180
5197
|
return this.bubble.radius ?? this.size.value;
|
|
5181
5198
|
}
|
|
5182
5199
|
getRotateData() {
|
|
5183
5200
|
const angle = this.getAngle();
|
|
5184
|
-
this.
|
|
5185
|
-
this.
|
|
5186
|
-
return this
|
|
5201
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5202
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5203
|
+
return this.#cachedRotateData;
|
|
5187
5204
|
}
|
|
5188
5205
|
getStrokeColor() {
|
|
5189
|
-
return this
|
|
5206
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5190
5207
|
}
|
|
5191
5208
|
getTransformData(externalTransform) {
|
|
5192
5209
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5193
|
-
this.
|
|
5194
|
-
this.
|
|
5210
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5211
|
+
this.#cachedTransform.b = rotating
|
|
5195
5212
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
5196
5213
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5197
|
-
this.
|
|
5214
|
+
this.#cachedTransform.c = rotating
|
|
5198
5215
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
5199
5216
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5200
|
-
this.
|
|
5201
|
-
return this
|
|
5217
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5218
|
+
return this.#cachedTransform;
|
|
5202
5219
|
}
|
|
5203
5220
|
init(id, position, overrideOptions, group) {
|
|
5204
|
-
const container = this
|
|
5221
|
+
const container = this.#container;
|
|
5205
5222
|
this.id = id;
|
|
5206
5223
|
this.group = group;
|
|
5207
5224
|
this.justWarped = false;
|
|
@@ -5221,21 +5238,27 @@
|
|
|
5221
5238
|
moveSpeed: 0,
|
|
5222
5239
|
sizeAnimationSpeed: 0,
|
|
5223
5240
|
};
|
|
5241
|
+
this.size = {
|
|
5242
|
+
value: 1,
|
|
5243
|
+
max: 1,
|
|
5244
|
+
min: 1,
|
|
5245
|
+
enable: false,
|
|
5246
|
+
};
|
|
5224
5247
|
this.outType = ParticleOutType.normal;
|
|
5225
5248
|
this.ignoresResizeRatio = true;
|
|
5226
|
-
const
|
|
5249
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5227
5250
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5228
5251
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5229
5252
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5230
5253
|
if (overrideOptions) {
|
|
5231
|
-
if (overrideOptions.effect?.type) {
|
|
5254
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5232
5255
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5233
5256
|
if (effect) {
|
|
5234
5257
|
this.effect = effect;
|
|
5235
5258
|
effectOptions.load(overrideOptions.effect);
|
|
5236
5259
|
}
|
|
5237
5260
|
}
|
|
5238
|
-
if (overrideOptions.shape?.type) {
|
|
5261
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5239
5262
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5240
5263
|
if (shape) {
|
|
5241
5264
|
this.shape = shape;
|
|
@@ -5244,21 +5267,20 @@
|
|
|
5244
5267
|
}
|
|
5245
5268
|
}
|
|
5246
5269
|
if (this.effect === randomColorValue) {
|
|
5247
|
-
const availableEffects = [...this.
|
|
5270
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5248
5271
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5249
5272
|
}
|
|
5250
5273
|
if (this.shape === randomColorValue) {
|
|
5251
|
-
const availableShapes = [...this.
|
|
5274
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5252
5275
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5253
5276
|
}
|
|
5254
5277
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5255
5278
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5256
5279
|
particlesOptions.load(overrideOptions);
|
|
5257
|
-
const effectData = this.effectData;
|
|
5280
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5258
5281
|
if (effectData) {
|
|
5259
5282
|
particlesOptions.load(effectData.particles);
|
|
5260
5283
|
}
|
|
5261
|
-
const shapeData = this.shapeData;
|
|
5262
5284
|
if (shapeData) {
|
|
5263
5285
|
particlesOptions.load(shapeData.particles);
|
|
5264
5286
|
}
|
|
@@ -5266,7 +5288,9 @@
|
|
|
5266
5288
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5267
5289
|
this.options = particlesOptions;
|
|
5268
5290
|
container.retina.initParticle(this);
|
|
5269
|
-
|
|
5291
|
+
for (const updater of container.particleUpdaters) {
|
|
5292
|
+
updater.preInit?.(this);
|
|
5293
|
+
}
|
|
5270
5294
|
this.bubble = {
|
|
5271
5295
|
inRange: false,
|
|
5272
5296
|
};
|
|
@@ -5274,8 +5298,8 @@
|
|
|
5274
5298
|
inRange: false,
|
|
5275
5299
|
factor: 1,
|
|
5276
5300
|
};
|
|
5277
|
-
this
|
|
5278
|
-
this.initialVelocity = this
|
|
5301
|
+
this.#initPosition(position);
|
|
5302
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5279
5303
|
this.velocity = this.initialVelocity.copy();
|
|
5280
5304
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5281
5305
|
this.sides = 24;
|
|
@@ -5306,12 +5330,11 @@
|
|
|
5306
5330
|
plugin.particleCreated?.(this);
|
|
5307
5331
|
}
|
|
5308
5332
|
}
|
|
5309
|
-
isInsideCanvas() {
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
position.x <= canvasSize.width + radius);
|
|
5333
|
+
isInsideCanvas(direction) {
|
|
5334
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5335
|
+
}
|
|
5336
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5337
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5315
5338
|
}
|
|
5316
5339
|
isShowingBack() {
|
|
5317
5340
|
if (!this.roll) {
|
|
@@ -5336,13 +5359,13 @@
|
|
|
5336
5359
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5337
5360
|
}
|
|
5338
5361
|
reset() {
|
|
5339
|
-
for (const updater of this.
|
|
5362
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5340
5363
|
updater.reset?.(this);
|
|
5341
5364
|
}
|
|
5342
5365
|
}
|
|
5343
|
-
|
|
5366
|
+
#calcPosition = (position, zIndex) => {
|
|
5344
5367
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5345
|
-
const container = this
|
|
5368
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5346
5369
|
while (!signal.aborted) {
|
|
5347
5370
|
for (const plugin of plugins) {
|
|
5348
5371
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5354,10 +5377,10 @@
|
|
|
5354
5377
|
size: canvasSize,
|
|
5355
5378
|
position: posVec,
|
|
5356
5379
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5357
|
-
this
|
|
5358
|
-
this
|
|
5359
|
-
this
|
|
5360
|
-
this
|
|
5380
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5381
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5382
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5383
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5361
5384
|
let isValidPosition = true;
|
|
5362
5385
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5363
5386
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5373,8 +5396,8 @@
|
|
|
5373
5396
|
}
|
|
5374
5397
|
return posVec;
|
|
5375
5398
|
};
|
|
5376
|
-
|
|
5377
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5399
|
+
#calculateVelocity = () => {
|
|
5400
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5378
5401
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5379
5402
|
return res;
|
|
5380
5403
|
}
|
|
@@ -5390,27 +5413,86 @@
|
|
|
5390
5413
|
}
|
|
5391
5414
|
return res;
|
|
5392
5415
|
};
|
|
5393
|
-
|
|
5416
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5394
5417
|
fixOutMode({
|
|
5395
5418
|
outMode,
|
|
5396
5419
|
checkModes: [OutMode.bounce],
|
|
5397
5420
|
coord: pos.x,
|
|
5398
|
-
maxCoord: this.
|
|
5421
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5399
5422
|
setCb: (value) => (pos.x += value),
|
|
5400
5423
|
radius,
|
|
5401
5424
|
});
|
|
5402
5425
|
};
|
|
5403
|
-
|
|
5426
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5404
5427
|
fixOutMode({
|
|
5405
5428
|
outMode,
|
|
5406
5429
|
checkModes: [OutMode.bounce],
|
|
5407
5430
|
coord: pos.y,
|
|
5408
|
-
maxCoord: this.
|
|
5431
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5409
5432
|
setCb: (value) => (pos.y += value),
|
|
5410
5433
|
radius,
|
|
5411
5434
|
});
|
|
5412
5435
|
};
|
|
5413
|
-
|
|
5436
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5437
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5438
|
+
if (direction === OutModeDirection.bottom) {
|
|
5439
|
+
return {
|
|
5440
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5441
|
+
reason: "default",
|
|
5442
|
+
};
|
|
5443
|
+
}
|
|
5444
|
+
if (direction === OutModeDirection.left) {
|
|
5445
|
+
return {
|
|
5446
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5447
|
+
reason: "default",
|
|
5448
|
+
};
|
|
5449
|
+
}
|
|
5450
|
+
if (direction === OutModeDirection.right) {
|
|
5451
|
+
return {
|
|
5452
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5453
|
+
reason: "default",
|
|
5454
|
+
};
|
|
5455
|
+
}
|
|
5456
|
+
if (direction === OutModeDirection.top) {
|
|
5457
|
+
return {
|
|
5458
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5459
|
+
reason: "default",
|
|
5460
|
+
};
|
|
5461
|
+
}
|
|
5462
|
+
return {
|
|
5463
|
+
inside: position.x >= -radius &&
|
|
5464
|
+
position.y >= -radius &&
|
|
5465
|
+
position.y <= canvasSize.height + radius &&
|
|
5466
|
+
position.x <= canvasSize.width + radius,
|
|
5467
|
+
reason: "default",
|
|
5468
|
+
};
|
|
5469
|
+
};
|
|
5470
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5471
|
+
return {
|
|
5472
|
+
canvasSize: this.#container.canvas.size,
|
|
5473
|
+
direction,
|
|
5474
|
+
outMode,
|
|
5475
|
+
particle: this,
|
|
5476
|
+
radius: this.getRadius(),
|
|
5477
|
+
};
|
|
5478
|
+
};
|
|
5479
|
+
#getInsideCanvasResult = (data) => {
|
|
5480
|
+
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;
|
|
5481
|
+
if (!shapeCheck && !effectCheck) {
|
|
5482
|
+
return defaultResult;
|
|
5483
|
+
}
|
|
5484
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5485
|
+
if (shapeResult && effectResult) {
|
|
5486
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5487
|
+
return {
|
|
5488
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5489
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5490
|
+
reason: "combined",
|
|
5491
|
+
};
|
|
5492
|
+
}
|
|
5493
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5494
|
+
};
|
|
5495
|
+
#getRollColor = color => {
|
|
5414
5496
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5415
5497
|
return color;
|
|
5416
5498
|
}
|
|
@@ -5425,8 +5507,8 @@
|
|
|
5425
5507
|
}
|
|
5426
5508
|
return color;
|
|
5427
5509
|
};
|
|
5428
|
-
|
|
5429
|
-
const container = this
|
|
5510
|
+
#initPosition = position => {
|
|
5511
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5430
5512
|
if (!initialPosition) {
|
|
5431
5513
|
throw new Error("a valid position cannot be found for particle");
|
|
5432
5514
|
}
|
|
@@ -5449,45 +5531,58 @@
|
|
|
5449
5531
|
}
|
|
5450
5532
|
this.offset = Vector.origin;
|
|
5451
5533
|
};
|
|
5534
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5535
|
+
if (typeof result === "boolean") {
|
|
5536
|
+
return {
|
|
5537
|
+
inside: result,
|
|
5538
|
+
reason,
|
|
5539
|
+
};
|
|
5540
|
+
}
|
|
5541
|
+
return {
|
|
5542
|
+
inside: result.inside,
|
|
5543
|
+
margin: result.margin,
|
|
5544
|
+
reason: result.reason ?? reason,
|
|
5545
|
+
};
|
|
5546
|
+
};
|
|
5452
5547
|
}
|
|
5453
5548
|
|
|
5454
5549
|
class SpatialHashGrid {
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5550
|
+
#cellSize;
|
|
5551
|
+
#cells = new Map();
|
|
5552
|
+
#circlePool = [];
|
|
5553
|
+
#circlePoolIdx;
|
|
5554
|
+
#pendingCellSize;
|
|
5555
|
+
#rectanglePool = [];
|
|
5556
|
+
#rectanglePoolIdx;
|
|
5462
5557
|
constructor(cellSize) {
|
|
5463
|
-
this
|
|
5464
|
-
this
|
|
5465
|
-
this
|
|
5558
|
+
this.#cellSize = cellSize;
|
|
5559
|
+
this.#circlePoolIdx = 0;
|
|
5560
|
+
this.#rectanglePoolIdx = 0;
|
|
5466
5561
|
}
|
|
5467
5562
|
clear() {
|
|
5468
|
-
this.
|
|
5469
|
-
const pendingCellSize = this
|
|
5563
|
+
this.#cells.clear();
|
|
5564
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5470
5565
|
if (pendingCellSize) {
|
|
5471
|
-
this
|
|
5566
|
+
this.#cellSize = pendingCellSize;
|
|
5472
5567
|
}
|
|
5473
|
-
this
|
|
5568
|
+
this.#pendingCellSize = undefined;
|
|
5474
5569
|
}
|
|
5475
5570
|
insert(particle) {
|
|
5476
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5477
|
-
if (!this.
|
|
5478
|
-
this.
|
|
5571
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5572
|
+
if (!this.#cells.has(key)) {
|
|
5573
|
+
this.#cells.set(key, []);
|
|
5479
5574
|
}
|
|
5480
|
-
this.
|
|
5575
|
+
this.#cells.get(key)?.push(particle);
|
|
5481
5576
|
}
|
|
5482
5577
|
query(range, check, out = []) {
|
|
5483
|
-
const bounds = this
|
|
5578
|
+
const bounds = this.#getRangeBounds(range);
|
|
5484
5579
|
if (!bounds) {
|
|
5485
5580
|
return out;
|
|
5486
5581
|
}
|
|
5487
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5582
|
+
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);
|
|
5488
5583
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5489
5584
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5490
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5585
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5491
5586
|
if (!cellParticles) {
|
|
5492
5587
|
continue;
|
|
5493
5588
|
}
|
|
@@ -5504,29 +5599,29 @@
|
|
|
5504
5599
|
return out;
|
|
5505
5600
|
}
|
|
5506
5601
|
queryCircle(position, radius, check, out = []) {
|
|
5507
|
-
const circle = this
|
|
5508
|
-
this
|
|
5602
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5603
|
+
this.#releaseShapes();
|
|
5509
5604
|
return result;
|
|
5510
5605
|
}
|
|
5511
5606
|
queryRectangle(position, size, check, out = []) {
|
|
5512
|
-
const rect = this
|
|
5513
|
-
this
|
|
5607
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5608
|
+
this.#releaseShapes();
|
|
5514
5609
|
return result;
|
|
5515
5610
|
}
|
|
5516
5611
|
setCellSize(cellSize) {
|
|
5517
|
-
this
|
|
5612
|
+
this.#pendingCellSize = cellSize;
|
|
5518
5613
|
}
|
|
5519
|
-
|
|
5520
|
-
return (this
|
|
5614
|
+
#acquireCircle(x, y, r) {
|
|
5615
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5521
5616
|
}
|
|
5522
|
-
|
|
5523
|
-
return (this
|
|
5617
|
+
#acquireRectangle(x, y, w, h) {
|
|
5618
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5524
5619
|
}
|
|
5525
|
-
|
|
5526
|
-
const cellX = Math.floor(x / this
|
|
5620
|
+
#cellKeyFromCoords(x, y) {
|
|
5621
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5527
5622
|
return `${cellX}_${cellY}`;
|
|
5528
5623
|
}
|
|
5529
|
-
|
|
5624
|
+
#getRangeBounds(range) {
|
|
5530
5625
|
if (range instanceof Circle) {
|
|
5531
5626
|
const r = range.radius, { x, y } = range.position;
|
|
5532
5627
|
return {
|
|
@@ -5547,53 +5642,53 @@
|
|
|
5547
5642
|
}
|
|
5548
5643
|
return null;
|
|
5549
5644
|
}
|
|
5550
|
-
|
|
5551
|
-
this
|
|
5552
|
-
this
|
|
5645
|
+
#releaseShapes() {
|
|
5646
|
+
this.#circlePoolIdx = 0;
|
|
5647
|
+
this.#rectanglePoolIdx = 0;
|
|
5553
5648
|
}
|
|
5554
5649
|
}
|
|
5555
5650
|
|
|
5556
5651
|
class ParticlesManager {
|
|
5557
5652
|
checkParticlePositionPlugins;
|
|
5558
5653
|
grid;
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5654
|
+
#array;
|
|
5655
|
+
#container;
|
|
5656
|
+
#groupLimits;
|
|
5657
|
+
#limit;
|
|
5658
|
+
#nextId;
|
|
5659
|
+
#particleBuckets;
|
|
5660
|
+
#particleResetPlugins;
|
|
5661
|
+
#particleUpdatePlugins;
|
|
5662
|
+
#pluginManager;
|
|
5663
|
+
#pool;
|
|
5664
|
+
#postParticleUpdatePlugins;
|
|
5665
|
+
#postUpdatePlugins;
|
|
5666
|
+
#resizeFactor;
|
|
5667
|
+
#updatePlugins;
|
|
5668
|
+
#zBuckets;
|
|
5574
5669
|
constructor(pluginManager, container) {
|
|
5575
|
-
this
|
|
5576
|
-
this
|
|
5577
|
-
this
|
|
5578
|
-
this
|
|
5579
|
-
this
|
|
5580
|
-
this
|
|
5581
|
-
this
|
|
5582
|
-
this
|
|
5583
|
-
this
|
|
5670
|
+
this.#pluginManager = pluginManager;
|
|
5671
|
+
this.#container = container;
|
|
5672
|
+
this.#nextId = 0;
|
|
5673
|
+
this.#array = [];
|
|
5674
|
+
this.#pool = [];
|
|
5675
|
+
this.#limit = 0;
|
|
5676
|
+
this.#groupLimits = new Map();
|
|
5677
|
+
this.#particleBuckets = new Map();
|
|
5678
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5584
5679
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5585
5680
|
this.checkParticlePositionPlugins = [];
|
|
5586
|
-
this
|
|
5587
|
-
this
|
|
5588
|
-
this
|
|
5589
|
-
this
|
|
5590
|
-
this
|
|
5681
|
+
this.#particleResetPlugins = [];
|
|
5682
|
+
this.#particleUpdatePlugins = [];
|
|
5683
|
+
this.#postUpdatePlugins = [];
|
|
5684
|
+
this.#postParticleUpdatePlugins = [];
|
|
5685
|
+
this.#updatePlugins = [];
|
|
5591
5686
|
}
|
|
5592
5687
|
get count() {
|
|
5593
|
-
return this.
|
|
5688
|
+
return this.#array.length;
|
|
5594
5689
|
}
|
|
5595
5690
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5596
|
-
const limitMode = this.
|
|
5691
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5597
5692
|
if (limit > minLimit) {
|
|
5598
5693
|
switch (limitMode) {
|
|
5599
5694
|
case LimitMode.delete: {
|
|
@@ -5611,20 +5706,20 @@
|
|
|
5611
5706
|
}
|
|
5612
5707
|
}
|
|
5613
5708
|
try {
|
|
5614
|
-
const particle = this.
|
|
5615
|
-
particle.init(this
|
|
5709
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5710
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5616
5711
|
let canAdd = true;
|
|
5617
5712
|
if (initializer) {
|
|
5618
5713
|
canAdd = initializer(particle);
|
|
5619
5714
|
}
|
|
5620
5715
|
if (!canAdd) {
|
|
5621
|
-
this.
|
|
5716
|
+
this.#pool.push(particle);
|
|
5622
5717
|
return;
|
|
5623
5718
|
}
|
|
5624
|
-
this.
|
|
5625
|
-
this
|
|
5626
|
-
this
|
|
5627
|
-
this.
|
|
5719
|
+
this.#array.push(particle);
|
|
5720
|
+
this.#insertParticleIntoBucket(particle);
|
|
5721
|
+
this.#nextId++;
|
|
5722
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5628
5723
|
particle,
|
|
5629
5724
|
});
|
|
5630
5725
|
return particle;
|
|
@@ -5635,25 +5730,25 @@
|
|
|
5635
5730
|
return undefined;
|
|
5636
5731
|
}
|
|
5637
5732
|
clear() {
|
|
5638
|
-
this
|
|
5639
|
-
this.
|
|
5640
|
-
this
|
|
5733
|
+
this.#array = [];
|
|
5734
|
+
this.#particleBuckets.clear();
|
|
5735
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5641
5736
|
}
|
|
5642
5737
|
destroy() {
|
|
5643
|
-
this
|
|
5644
|
-
this.
|
|
5645
|
-
this.
|
|
5646
|
-
this
|
|
5738
|
+
this.#array = [];
|
|
5739
|
+
this.#pool.length = 0;
|
|
5740
|
+
this.#particleBuckets.clear();
|
|
5741
|
+
this.#zBuckets = [];
|
|
5647
5742
|
this.checkParticlePositionPlugins = [];
|
|
5648
|
-
this
|
|
5649
|
-
this
|
|
5650
|
-
this
|
|
5651
|
-
this
|
|
5652
|
-
this
|
|
5743
|
+
this.#particleResetPlugins = [];
|
|
5744
|
+
this.#particleUpdatePlugins = [];
|
|
5745
|
+
this.#postUpdatePlugins = [];
|
|
5746
|
+
this.#postParticleUpdatePlugins = [];
|
|
5747
|
+
this.#updatePlugins = [];
|
|
5653
5748
|
}
|
|
5654
5749
|
drawParticles(delta) {
|
|
5655
|
-
for (let i = this.
|
|
5656
|
-
const bucket = this
|
|
5750
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5751
|
+
const bucket = this.#zBuckets[i];
|
|
5657
5752
|
if (!bucket) {
|
|
5658
5753
|
continue;
|
|
5659
5754
|
}
|
|
@@ -5663,24 +5758,24 @@
|
|
|
5663
5758
|
}
|
|
5664
5759
|
}
|
|
5665
5760
|
filter(condition) {
|
|
5666
|
-
return this.
|
|
5761
|
+
return this.#array.filter(condition);
|
|
5667
5762
|
}
|
|
5668
5763
|
find(condition) {
|
|
5669
|
-
return this.
|
|
5764
|
+
return this.#array.find(condition);
|
|
5670
5765
|
}
|
|
5671
5766
|
get(index) {
|
|
5672
|
-
return this
|
|
5767
|
+
return this.#array[index];
|
|
5673
5768
|
}
|
|
5674
5769
|
async init() {
|
|
5675
|
-
const container = this
|
|
5770
|
+
const container = this.#container, options = container.actualOptions;
|
|
5676
5771
|
this.checkParticlePositionPlugins = [];
|
|
5677
|
-
this
|
|
5678
|
-
this
|
|
5679
|
-
this
|
|
5680
|
-
this
|
|
5681
|
-
this
|
|
5682
|
-
this.
|
|
5683
|
-
this
|
|
5772
|
+
this.#updatePlugins = [];
|
|
5773
|
+
this.#particleUpdatePlugins = [];
|
|
5774
|
+
this.#postUpdatePlugins = [];
|
|
5775
|
+
this.#particleResetPlugins = [];
|
|
5776
|
+
this.#postParticleUpdatePlugins = [];
|
|
5777
|
+
this.#particleBuckets.clear();
|
|
5778
|
+
this.#resetBuckets(container.zLayers);
|
|
5684
5779
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5685
5780
|
for (const plugin of container.plugins) {
|
|
5686
5781
|
if (plugin.redrawInit) {
|
|
@@ -5690,26 +5785,26 @@
|
|
|
5690
5785
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5691
5786
|
}
|
|
5692
5787
|
if (plugin.update) {
|
|
5693
|
-
this.
|
|
5788
|
+
this.#updatePlugins.push(plugin);
|
|
5694
5789
|
}
|
|
5695
5790
|
if (plugin.particleUpdate) {
|
|
5696
|
-
this.
|
|
5791
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5697
5792
|
}
|
|
5698
5793
|
if (plugin.postUpdate) {
|
|
5699
|
-
this.
|
|
5794
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5700
5795
|
}
|
|
5701
5796
|
if (plugin.particleReset) {
|
|
5702
|
-
this.
|
|
5797
|
+
this.#particleResetPlugins.push(plugin);
|
|
5703
5798
|
}
|
|
5704
5799
|
if (plugin.postParticleUpdate) {
|
|
5705
|
-
this.
|
|
5800
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5706
5801
|
}
|
|
5707
5802
|
}
|
|
5708
|
-
await this.
|
|
5709
|
-
for (const drawer of this.
|
|
5803
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5804
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5710
5805
|
await drawer.init?.(container);
|
|
5711
5806
|
}
|
|
5712
|
-
for (const drawer of this.
|
|
5807
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5713
5808
|
await drawer.init?.(container);
|
|
5714
5809
|
}
|
|
5715
5810
|
let handled = false;
|
|
@@ -5743,10 +5838,10 @@
|
|
|
5743
5838
|
async redraw() {
|
|
5744
5839
|
this.clear();
|
|
5745
5840
|
await this.init();
|
|
5746
|
-
this.
|
|
5841
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5747
5842
|
}
|
|
5748
5843
|
remove(particle, group, override) {
|
|
5749
|
-
this.removeAt(this.
|
|
5844
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5750
5845
|
}
|
|
5751
5846
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5752
5847
|
if (index < minIndex || index > this.count) {
|
|
@@ -5754,7 +5849,7 @@
|
|
|
5754
5849
|
}
|
|
5755
5850
|
let deleted = 0;
|
|
5756
5851
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5757
|
-
if (this
|
|
5852
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5758
5853
|
i--;
|
|
5759
5854
|
deleted++;
|
|
5760
5855
|
}
|
|
@@ -5764,9 +5859,9 @@
|
|
|
5764
5859
|
this.removeAt(minIndex, quantity, group);
|
|
5765
5860
|
}
|
|
5766
5861
|
setDensity() {
|
|
5767
|
-
const options = this.
|
|
5862
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5768
5863
|
let pluginsCount = 0;
|
|
5769
|
-
for (const plugin of this.
|
|
5864
|
+
for (const plugin of this.#container.plugins) {
|
|
5770
5865
|
if (plugin.particlesDensityCount) {
|
|
5771
5866
|
pluginsCount += plugin.particlesDensityCount();
|
|
5772
5867
|
}
|
|
@@ -5776,51 +5871,51 @@
|
|
|
5776
5871
|
if (!groupData) {
|
|
5777
5872
|
continue;
|
|
5778
5873
|
}
|
|
5779
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5780
|
-
this
|
|
5874
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5875
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5781
5876
|
}
|
|
5782
|
-
this
|
|
5877
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5783
5878
|
}
|
|
5784
5879
|
setResizeFactor(factor) {
|
|
5785
|
-
this
|
|
5880
|
+
this.#resizeFactor = factor;
|
|
5786
5881
|
}
|
|
5787
5882
|
update(delta) {
|
|
5788
5883
|
this.grid.clear();
|
|
5789
|
-
for (const plugin of this
|
|
5884
|
+
for (const plugin of this.#updatePlugins) {
|
|
5790
5885
|
plugin.update?.(delta);
|
|
5791
5886
|
}
|
|
5792
|
-
const particlesToDelete = this
|
|
5793
|
-
for (const plugin of this
|
|
5887
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5888
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5794
5889
|
plugin.postUpdate?.(delta);
|
|
5795
5890
|
}
|
|
5796
|
-
this
|
|
5891
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5797
5892
|
if (particlesToDelete.size) {
|
|
5798
5893
|
for (const particle of particlesToDelete) {
|
|
5799
5894
|
this.remove(particle);
|
|
5800
5895
|
}
|
|
5801
5896
|
}
|
|
5802
|
-
|
|
5897
|
+
this.#resizeFactor = undefined;
|
|
5803
5898
|
}
|
|
5804
|
-
|
|
5805
|
-
this.
|
|
5899
|
+
#addToPool = (...particles) => {
|
|
5900
|
+
this.#pool.push(...particles);
|
|
5806
5901
|
};
|
|
5807
|
-
|
|
5902
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5808
5903
|
const numberOptions = options.number;
|
|
5809
5904
|
if (!numberOptions.density.enable) {
|
|
5810
5905
|
if (group === undefined) {
|
|
5811
|
-
this
|
|
5906
|
+
this.#limit = numberOptions.limit.value;
|
|
5812
5907
|
}
|
|
5813
5908
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5814
|
-
this.
|
|
5909
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5815
5910
|
}
|
|
5816
5911
|
return;
|
|
5817
5912
|
}
|
|
5818
|
-
const densityFactor = this
|
|
5913
|
+
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);
|
|
5819
5914
|
if (group === undefined) {
|
|
5820
|
-
this
|
|
5915
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5821
5916
|
}
|
|
5822
5917
|
else {
|
|
5823
|
-
this.
|
|
5918
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5824
5919
|
}
|
|
5825
5920
|
if (particlesCount < particlesNumber) {
|
|
5826
5921
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5829,18 +5924,18 @@
|
|
|
5829
5924
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5830
5925
|
}
|
|
5831
5926
|
};
|
|
5832
|
-
|
|
5927
|
+
#createBuckets = (zLayers) => {
|
|
5833
5928
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5834
5929
|
return Array.from({ length: bucketCount }, () => []);
|
|
5835
5930
|
};
|
|
5836
|
-
|
|
5837
|
-
const maxBucketIndex = this.
|
|
5931
|
+
#getBucketIndex = (zIndex) => {
|
|
5932
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5838
5933
|
if (maxBucketIndex <= minIndex) {
|
|
5839
5934
|
return minIndex;
|
|
5840
5935
|
}
|
|
5841
5936
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5842
5937
|
};
|
|
5843
|
-
|
|
5938
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5844
5939
|
let start = minIndex, end = bucket.length;
|
|
5845
5940
|
while (start < end) {
|
|
5846
5941
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5857,8 +5952,8 @@
|
|
|
5857
5952
|
}
|
|
5858
5953
|
return start;
|
|
5859
5954
|
};
|
|
5860
|
-
|
|
5861
|
-
const container = this
|
|
5955
|
+
#initDensityFactor = densityOptions => {
|
|
5956
|
+
const container = this.#container;
|
|
5862
5957
|
if (!densityOptions.enable) {
|
|
5863
5958
|
return defaultDensityFactor;
|
|
5864
5959
|
}
|
|
@@ -5868,82 +5963,82 @@
|
|
|
5868
5963
|
}
|
|
5869
5964
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5870
5965
|
};
|
|
5871
|
-
|
|
5872
|
-
const bucketIndex = this
|
|
5966
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5967
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5873
5968
|
if (!bucket) {
|
|
5874
5969
|
return;
|
|
5875
5970
|
}
|
|
5876
|
-
bucket.splice(this
|
|
5877
|
-
this.
|
|
5971
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5972
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5878
5973
|
};
|
|
5879
|
-
|
|
5880
|
-
const particle = this
|
|
5974
|
+
#removeParticle = (index, group, override) => {
|
|
5975
|
+
const particle = this.#array[index];
|
|
5881
5976
|
if (!particle) {
|
|
5882
5977
|
return false;
|
|
5883
5978
|
}
|
|
5884
5979
|
if (particle.group !== group) {
|
|
5885
5980
|
return false;
|
|
5886
5981
|
}
|
|
5887
|
-
this.
|
|
5888
|
-
this
|
|
5982
|
+
this.#array.splice(index, deleteCount);
|
|
5983
|
+
this.#removeParticleFromBucket(particle);
|
|
5889
5984
|
particle.destroy(override);
|
|
5890
|
-
this.
|
|
5985
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5891
5986
|
particle,
|
|
5892
5987
|
});
|
|
5893
|
-
this
|
|
5988
|
+
this.#addToPool(particle);
|
|
5894
5989
|
return true;
|
|
5895
5990
|
};
|
|
5896
|
-
|
|
5897
|
-
const bucketIndex = this.
|
|
5991
|
+
#removeParticleFromBucket = (particle) => {
|
|
5992
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5898
5993
|
if (!bucket) {
|
|
5899
|
-
this.
|
|
5994
|
+
this.#particleBuckets.delete(particle.id);
|
|
5900
5995
|
return;
|
|
5901
5996
|
}
|
|
5902
|
-
const particleIndex = this
|
|
5997
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5903
5998
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5904
|
-
this.
|
|
5999
|
+
this.#particleBuckets.delete(particle.id);
|
|
5905
6000
|
return;
|
|
5906
6001
|
}
|
|
5907
6002
|
bucket.splice(particleIndex, deleteCount);
|
|
5908
|
-
this.
|
|
6003
|
+
this.#particleBuckets.delete(particle.id);
|
|
5909
6004
|
};
|
|
5910
|
-
|
|
6005
|
+
#resetBuckets = (zLayers) => {
|
|
5911
6006
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5912
|
-
if (this.
|
|
5913
|
-
this
|
|
6007
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6008
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5914
6009
|
return;
|
|
5915
6010
|
}
|
|
5916
|
-
for (const bucket of this
|
|
6011
|
+
for (const bucket of this.#zBuckets) {
|
|
5917
6012
|
bucket.length = minIndex;
|
|
5918
6013
|
}
|
|
5919
6014
|
};
|
|
5920
|
-
|
|
5921
|
-
const newBucketIndex = this
|
|
6015
|
+
#updateParticleBucket = (particle) => {
|
|
6016
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5922
6017
|
if (currentBucketIndex === undefined) {
|
|
5923
|
-
this
|
|
6018
|
+
this.#insertParticleIntoBucket(particle);
|
|
5924
6019
|
return;
|
|
5925
6020
|
}
|
|
5926
6021
|
if (currentBucketIndex === newBucketIndex) {
|
|
5927
6022
|
return;
|
|
5928
6023
|
}
|
|
5929
|
-
const currentBucket = this
|
|
6024
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5930
6025
|
if (currentBucket) {
|
|
5931
|
-
const particleIndex = this
|
|
6026
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5932
6027
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5933
6028
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5934
6029
|
}
|
|
5935
6030
|
}
|
|
5936
|
-
const newBucket = this
|
|
6031
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5937
6032
|
if (!newBucket) {
|
|
5938
|
-
this.
|
|
6033
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5939
6034
|
return;
|
|
5940
6035
|
}
|
|
5941
|
-
newBucket.splice(this
|
|
5942
|
-
this.
|
|
6036
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6037
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5943
6038
|
};
|
|
5944
|
-
|
|
5945
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5946
|
-
for (const particle of this
|
|
6039
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6040
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6041
|
+
for (const particle of this.#array) {
|
|
5947
6042
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5948
6043
|
particle.position.x *= resizeFactor.width;
|
|
5949
6044
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5951,10 +6046,10 @@
|
|
|
5951
6046
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5952
6047
|
}
|
|
5953
6048
|
particle.ignoresResizeRatio = false;
|
|
5954
|
-
for (const plugin of this
|
|
6049
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5955
6050
|
plugin.particleReset?.(particle);
|
|
5956
6051
|
}
|
|
5957
|
-
for (const plugin of this
|
|
6052
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5958
6053
|
if (particle.destroyed) {
|
|
5959
6054
|
break;
|
|
5960
6055
|
}
|
|
@@ -5968,36 +6063,36 @@
|
|
|
5968
6063
|
}
|
|
5969
6064
|
return particlesToDelete;
|
|
5970
6065
|
};
|
|
5971
|
-
|
|
5972
|
-
for (const particle of this
|
|
6066
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6067
|
+
for (const particle of this.#array) {
|
|
5973
6068
|
if (particle.destroyed) {
|
|
5974
6069
|
particlesToDelete.add(particle);
|
|
5975
6070
|
continue;
|
|
5976
6071
|
}
|
|
5977
|
-
for (const updater of this.
|
|
6072
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5978
6073
|
updater.update(particle, delta);
|
|
5979
6074
|
}
|
|
5980
6075
|
if (!particle.spawning) {
|
|
5981
|
-
for (const plugin of this
|
|
6076
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5982
6077
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5983
6078
|
}
|
|
5984
6079
|
}
|
|
5985
|
-
this
|
|
6080
|
+
this.#updateParticleBucket(particle);
|
|
5986
6081
|
}
|
|
5987
6082
|
};
|
|
5988
6083
|
}
|
|
5989
6084
|
|
|
5990
6085
|
class Retina {
|
|
5991
|
-
container;
|
|
5992
6086
|
pixelRatio;
|
|
5993
6087
|
reduceFactor;
|
|
6088
|
+
#container;
|
|
5994
6089
|
constructor(container) {
|
|
5995
|
-
this
|
|
6090
|
+
this.#container = container;
|
|
5996
6091
|
this.pixelRatio = defaultRatio;
|
|
5997
6092
|
this.reduceFactor = defaultReduceFactor;
|
|
5998
6093
|
}
|
|
5999
6094
|
init() {
|
|
6000
|
-
const container = this
|
|
6095
|
+
const container = this.#container, options = container.actualOptions;
|
|
6001
6096
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6002
6097
|
this.reduceFactor = defaultReduceFactor;
|
|
6003
6098
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6011,7 +6106,6 @@
|
|
|
6011
6106
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6012
6107
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6013
6108
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6014
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6015
6109
|
const maxDistance = props.maxDistance;
|
|
6016
6110
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6017
6111
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6049,73 +6143,73 @@
|
|
|
6049
6143
|
shapeDrawers;
|
|
6050
6144
|
started;
|
|
6051
6145
|
zLayers;
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6146
|
+
#delay;
|
|
6147
|
+
#delayTimeout;
|
|
6148
|
+
#delta = { value: 0, factor: 0 };
|
|
6149
|
+
#dispatchCallback;
|
|
6150
|
+
#drawAnimationFrame;
|
|
6151
|
+
#duration;
|
|
6152
|
+
#eventListeners;
|
|
6153
|
+
#firstStart;
|
|
6154
|
+
#initialSourceOptions;
|
|
6155
|
+
#lastFrameTime;
|
|
6156
|
+
#lifeTime;
|
|
6157
|
+
#onDestroy;
|
|
6158
|
+
#options;
|
|
6159
|
+
#paused;
|
|
6160
|
+
#pluginManager;
|
|
6161
|
+
#smooth;
|
|
6162
|
+
#sourceOptions;
|
|
6069
6163
|
constructor(params) {
|
|
6070
6164
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6071
|
-
this
|
|
6072
|
-
this
|
|
6073
|
-
this
|
|
6165
|
+
this.#pluginManager = pluginManager;
|
|
6166
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6167
|
+
this.#onDestroy = onDestroy;
|
|
6074
6168
|
this.id = Symbol(id);
|
|
6075
6169
|
this.fpsLimit = 120;
|
|
6076
6170
|
this.hdr = false;
|
|
6077
|
-
this
|
|
6078
|
-
this
|
|
6079
|
-
this
|
|
6080
|
-
this
|
|
6081
|
-
this
|
|
6171
|
+
this.#smooth = false;
|
|
6172
|
+
this.#delay = 0;
|
|
6173
|
+
this.#duration = 0;
|
|
6174
|
+
this.#lifeTime = 0;
|
|
6175
|
+
this.#firstStart = true;
|
|
6082
6176
|
this.started = false;
|
|
6083
6177
|
this.destroyed = false;
|
|
6084
|
-
this
|
|
6085
|
-
this
|
|
6178
|
+
this.#paused = true;
|
|
6179
|
+
this.#lastFrameTime = 0;
|
|
6086
6180
|
this.zLayers = 100;
|
|
6087
6181
|
this.pageHidden = false;
|
|
6088
|
-
this
|
|
6089
|
-
this
|
|
6182
|
+
this.#sourceOptions = sourceOptions;
|
|
6183
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6090
6184
|
this.effectDrawers = new Map();
|
|
6091
6185
|
this.shapeDrawers = new Map();
|
|
6092
6186
|
this.particleUpdaters = [];
|
|
6093
6187
|
this.retina = new Retina(this);
|
|
6094
|
-
this.canvas = new CanvasManager(this
|
|
6095
|
-
this.particles = new ParticlesManager(this
|
|
6188
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6189
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6096
6190
|
this.plugins = [];
|
|
6097
6191
|
this.particleDestroyedPlugins = [];
|
|
6098
6192
|
this.particleCreatedPlugins = [];
|
|
6099
6193
|
this.particlePositionPlugins = [];
|
|
6100
|
-
this
|
|
6101
|
-
this.actualOptions = loadContainerOptions(this
|
|
6102
|
-
this
|
|
6194
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6195
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6196
|
+
this.#eventListeners = new EventListeners(this);
|
|
6103
6197
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6104
6198
|
}
|
|
6105
6199
|
get animationStatus() {
|
|
6106
|
-
return !this
|
|
6200
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6107
6201
|
}
|
|
6108
6202
|
get options() {
|
|
6109
|
-
return this
|
|
6203
|
+
return this.#options;
|
|
6110
6204
|
}
|
|
6111
6205
|
get sourceOptions() {
|
|
6112
|
-
return this
|
|
6206
|
+
return this.#sourceOptions;
|
|
6113
6207
|
}
|
|
6114
6208
|
addLifeTime(value) {
|
|
6115
|
-
this
|
|
6209
|
+
this.#lifeTime += value;
|
|
6116
6210
|
}
|
|
6117
6211
|
alive() {
|
|
6118
|
-
return !this
|
|
6212
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6119
6213
|
}
|
|
6120
6214
|
destroy(remove = true) {
|
|
6121
6215
|
if (!guardCheck(this)) {
|
|
@@ -6137,13 +6231,13 @@
|
|
|
6137
6231
|
this.shapeDrawers = new Map();
|
|
6138
6232
|
this.particleUpdaters = [];
|
|
6139
6233
|
this.plugins.length = 0;
|
|
6140
|
-
this.
|
|
6234
|
+
this.#pluginManager.clearPlugins(this);
|
|
6141
6235
|
this.destroyed = true;
|
|
6142
|
-
this
|
|
6236
|
+
this.#onDestroy(remove);
|
|
6143
6237
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6144
6238
|
}
|
|
6145
6239
|
dispatchEvent(type, data) {
|
|
6146
|
-
this
|
|
6240
|
+
this.#dispatchCallback(type, {
|
|
6147
6241
|
container: this,
|
|
6148
6242
|
data,
|
|
6149
6243
|
});
|
|
@@ -6153,12 +6247,12 @@
|
|
|
6153
6247
|
return;
|
|
6154
6248
|
}
|
|
6155
6249
|
let refreshTime = force;
|
|
6156
|
-
this
|
|
6250
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6157
6251
|
if (refreshTime) {
|
|
6158
|
-
this
|
|
6252
|
+
this.#lastFrameTime = undefined;
|
|
6159
6253
|
refreshTime = false;
|
|
6160
6254
|
}
|
|
6161
|
-
this
|
|
6255
|
+
this.#nextFrame(timestamp);
|
|
6162
6256
|
});
|
|
6163
6257
|
}
|
|
6164
6258
|
async export(type, options = {}) {
|
|
@@ -6180,7 +6274,7 @@
|
|
|
6180
6274
|
return;
|
|
6181
6275
|
}
|
|
6182
6276
|
const allContainerPlugins = new Map();
|
|
6183
|
-
for (const plugin of this.
|
|
6277
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6184
6278
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6185
6279
|
if (containerPlugin.preInit) {
|
|
6186
6280
|
await containerPlugin.preInit();
|
|
@@ -6188,8 +6282,8 @@
|
|
|
6188
6282
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6189
6283
|
}
|
|
6190
6284
|
await this.initDrawersAndUpdaters();
|
|
6191
|
-
this
|
|
6192
|
-
this.actualOptions = loadContainerOptions(this
|
|
6285
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6286
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6193
6287
|
this.plugins.length = 0;
|
|
6194
6288
|
this.particleDestroyedPlugins.length = 0;
|
|
6195
6289
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6216,11 +6310,11 @@
|
|
|
6216
6310
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6217
6311
|
this.hdr = hdr;
|
|
6218
6312
|
this.zLayers = zLayers;
|
|
6219
|
-
this
|
|
6220
|
-
this
|
|
6221
|
-
this
|
|
6313
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6314
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6315
|
+
this.#lifeTime = 0;
|
|
6222
6316
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6223
|
-
this
|
|
6317
|
+
this.#smooth = smooth;
|
|
6224
6318
|
for (const plugin of this.plugins) {
|
|
6225
6319
|
await plugin.init?.();
|
|
6226
6320
|
}
|
|
@@ -6233,7 +6327,7 @@
|
|
|
6233
6327
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6234
6328
|
}
|
|
6235
6329
|
async initDrawersAndUpdaters() {
|
|
6236
|
-
const pluginManager = this
|
|
6330
|
+
const pluginManager = this.#pluginManager;
|
|
6237
6331
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6238
6332
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6239
6333
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6242,18 +6336,18 @@
|
|
|
6242
6336
|
if (!guardCheck(this)) {
|
|
6243
6337
|
return;
|
|
6244
6338
|
}
|
|
6245
|
-
if (this
|
|
6246
|
-
cancelAnimation(this
|
|
6247
|
-
|
|
6339
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6340
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6341
|
+
this.#drawAnimationFrame = undefined;
|
|
6248
6342
|
}
|
|
6249
|
-
if (this
|
|
6343
|
+
if (this.#paused) {
|
|
6250
6344
|
return;
|
|
6251
6345
|
}
|
|
6252
6346
|
for (const plugin of this.plugins) {
|
|
6253
6347
|
plugin.pause?.();
|
|
6254
6348
|
}
|
|
6255
6349
|
if (!this.pageHidden) {
|
|
6256
|
-
this
|
|
6350
|
+
this.#paused = true;
|
|
6257
6351
|
}
|
|
6258
6352
|
this.dispatchEvent(EventType.containerPaused);
|
|
6259
6353
|
}
|
|
@@ -6261,13 +6355,13 @@
|
|
|
6261
6355
|
if (!guardCheck(this)) {
|
|
6262
6356
|
return;
|
|
6263
6357
|
}
|
|
6264
|
-
const needsUpdate = this
|
|
6265
|
-
if (this
|
|
6266
|
-
this
|
|
6358
|
+
const needsUpdate = this.#paused || force;
|
|
6359
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6360
|
+
this.#firstStart = false;
|
|
6267
6361
|
return;
|
|
6268
6362
|
}
|
|
6269
|
-
if (this
|
|
6270
|
-
this
|
|
6363
|
+
if (this.#paused) {
|
|
6364
|
+
this.#paused = false;
|
|
6271
6365
|
}
|
|
6272
6366
|
if (needsUpdate) {
|
|
6273
6367
|
for (const plugin of this.plugins) {
|
|
@@ -6290,10 +6384,10 @@
|
|
|
6290
6384
|
if (!guardCheck(this)) {
|
|
6291
6385
|
return;
|
|
6292
6386
|
}
|
|
6293
|
-
this
|
|
6294
|
-
this
|
|
6295
|
-
this
|
|
6296
|
-
this.actualOptions = loadContainerOptions(this
|
|
6387
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6388
|
+
this.#sourceOptions = sourceOptions;
|
|
6389
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6390
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6297
6391
|
return this.refresh();
|
|
6298
6392
|
}
|
|
6299
6393
|
async start() {
|
|
@@ -6304,7 +6398,7 @@
|
|
|
6304
6398
|
this.started = true;
|
|
6305
6399
|
await new Promise(resolve => {
|
|
6306
6400
|
const start = async () => {
|
|
6307
|
-
this.
|
|
6401
|
+
this.#eventListeners.addListeners();
|
|
6308
6402
|
for (const plugin of this.plugins) {
|
|
6309
6403
|
await plugin.start?.();
|
|
6310
6404
|
}
|
|
@@ -6312,20 +6406,20 @@
|
|
|
6312
6406
|
this.play();
|
|
6313
6407
|
resolve();
|
|
6314
6408
|
};
|
|
6315
|
-
this
|
|
6409
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6316
6410
|
});
|
|
6317
6411
|
}
|
|
6318
6412
|
stop() {
|
|
6319
6413
|
if (!guardCheck(this) || !this.started) {
|
|
6320
6414
|
return;
|
|
6321
6415
|
}
|
|
6322
|
-
if (this
|
|
6323
|
-
clearTimeout(this
|
|
6324
|
-
|
|
6416
|
+
if (this.#delayTimeout) {
|
|
6417
|
+
clearTimeout(this.#delayTimeout);
|
|
6418
|
+
this.#delayTimeout = undefined;
|
|
6325
6419
|
}
|
|
6326
|
-
this
|
|
6420
|
+
this.#firstStart = true;
|
|
6327
6421
|
this.started = false;
|
|
6328
|
-
this.
|
|
6422
|
+
this.#eventListeners.removeListeners();
|
|
6329
6423
|
this.pause();
|
|
6330
6424
|
this.particles.clear();
|
|
6331
6425
|
this.canvas.stop();
|
|
@@ -6335,7 +6429,7 @@
|
|
|
6335
6429
|
this.particleCreatedPlugins.length = 0;
|
|
6336
6430
|
this.particleDestroyedPlugins.length = 0;
|
|
6337
6431
|
this.particlePositionPlugins.length = 0;
|
|
6338
|
-
this
|
|
6432
|
+
this.#sourceOptions = this.#options;
|
|
6339
6433
|
this.dispatchEvent(EventType.containerStopped);
|
|
6340
6434
|
}
|
|
6341
6435
|
updateActualOptions() {
|
|
@@ -6347,23 +6441,23 @@
|
|
|
6347
6441
|
}
|
|
6348
6442
|
return refresh;
|
|
6349
6443
|
}
|
|
6350
|
-
|
|
6444
|
+
#nextFrame = (timestamp) => {
|
|
6351
6445
|
try {
|
|
6352
|
-
if (!this
|
|
6353
|
-
this
|
|
6354
|
-
timestamp < this
|
|
6446
|
+
if (!this.#smooth &&
|
|
6447
|
+
this.#lastFrameTime !== undefined &&
|
|
6448
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6355
6449
|
this.draw(false);
|
|
6356
6450
|
return;
|
|
6357
6451
|
}
|
|
6358
|
-
this
|
|
6359
|
-
updateDelta(this
|
|
6360
|
-
this.addLifeTime(this.
|
|
6361
|
-
this
|
|
6362
|
-
if (this.
|
|
6452
|
+
this.#lastFrameTime ??= timestamp;
|
|
6453
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6454
|
+
this.addLifeTime(this.#delta.value);
|
|
6455
|
+
this.#lastFrameTime = timestamp;
|
|
6456
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6363
6457
|
this.draw(false);
|
|
6364
6458
|
return;
|
|
6365
6459
|
}
|
|
6366
|
-
this.canvas.render.drawParticles(this
|
|
6460
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6367
6461
|
if (!this.alive()) {
|
|
6368
6462
|
this.destroy();
|
|
6369
6463
|
return;
|
|
@@ -6384,10 +6478,10 @@
|
|
|
6384
6478
|
});
|
|
6385
6479
|
|
|
6386
6480
|
class BlendPluginInstance {
|
|
6387
|
-
|
|
6388
|
-
|
|
6481
|
+
#container;
|
|
6482
|
+
#defaultCompositeValue;
|
|
6389
6483
|
constructor(container) {
|
|
6390
|
-
this
|
|
6484
|
+
this.#container = container;
|
|
6391
6485
|
}
|
|
6392
6486
|
drawParticleCleanup(context, particle) {
|
|
6393
6487
|
if (!particle.options.blend?.enable) {
|
|
@@ -6404,14 +6498,14 @@
|
|
|
6404
6498
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6405
6499
|
}
|
|
6406
6500
|
drawSettingsCleanup(context) {
|
|
6407
|
-
if (!this
|
|
6501
|
+
if (!this.#defaultCompositeValue) {
|
|
6408
6502
|
return;
|
|
6409
6503
|
}
|
|
6410
|
-
context.globalCompositeOperation = this
|
|
6504
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6411
6505
|
}
|
|
6412
6506
|
drawSettingsSetup(context) {
|
|
6413
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6414
|
-
this
|
|
6507
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6508
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6415
6509
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6416
6510
|
}
|
|
6417
6511
|
}
|
|
@@ -6554,11 +6648,11 @@
|
|
|
6554
6648
|
class MovePluginInstance {
|
|
6555
6649
|
availablePathGenerators;
|
|
6556
6650
|
pathGenerators;
|
|
6557
|
-
|
|
6558
|
-
|
|
6651
|
+
#container;
|
|
6652
|
+
#pluginManager;
|
|
6559
6653
|
constructor(pluginManager, container) {
|
|
6560
|
-
this
|
|
6561
|
-
this
|
|
6654
|
+
this.#pluginManager = pluginManager;
|
|
6655
|
+
this.#container = container;
|
|
6562
6656
|
this.availablePathGenerators = new Map();
|
|
6563
6657
|
this.pathGenerators = new Map();
|
|
6564
6658
|
}
|
|
@@ -6589,7 +6683,7 @@
|
|
|
6589
6683
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6590
6684
|
inverse: gravityOptions.inverse,
|
|
6591
6685
|
};
|
|
6592
|
-
initSpin(this
|
|
6686
|
+
initSpin(this.#container, particle);
|
|
6593
6687
|
}
|
|
6594
6688
|
particleDestroyed(particle) {
|
|
6595
6689
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6600,7 +6694,7 @@
|
|
|
6600
6694
|
if (!moveOptions.enable) {
|
|
6601
6695
|
return;
|
|
6602
6696
|
}
|
|
6603
|
-
const container = this
|
|
6697
|
+
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;
|
|
6604
6698
|
if (moveOptions.spin.enable) {
|
|
6605
6699
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6606
6700
|
}
|
|
@@ -6610,18 +6704,18 @@
|
|
|
6610
6704
|
applyDistance(particle);
|
|
6611
6705
|
}
|
|
6612
6706
|
preInit() {
|
|
6613
|
-
return this
|
|
6707
|
+
return this.#init();
|
|
6614
6708
|
}
|
|
6615
6709
|
redrawInit() {
|
|
6616
|
-
return this
|
|
6710
|
+
return this.#init();
|
|
6617
6711
|
}
|
|
6618
6712
|
update() {
|
|
6619
6713
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6620
6714
|
pathGenerator.update();
|
|
6621
6715
|
}
|
|
6622
6716
|
}
|
|
6623
|
-
async
|
|
6624
|
-
const availablePathGenerators = await this.
|
|
6717
|
+
async #init() {
|
|
6718
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6625
6719
|
if (!availablePathGenerators) {
|
|
6626
6720
|
return;
|
|
6627
6721
|
}
|
|
@@ -6640,65 +6734,65 @@
|
|
|
6640
6734
|
|
|
6641
6735
|
const touchDelay = 500;
|
|
6642
6736
|
class InteractivityEventListeners {
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6737
|
+
#canPush = true;
|
|
6738
|
+
#clickPositionPlugins;
|
|
6739
|
+
#container;
|
|
6740
|
+
#handlers;
|
|
6741
|
+
#interactionManager;
|
|
6742
|
+
#touches;
|
|
6649
6743
|
constructor(container, interactionManager) {
|
|
6650
|
-
this
|
|
6651
|
-
this
|
|
6652
|
-
this
|
|
6653
|
-
this
|
|
6654
|
-
this
|
|
6744
|
+
this.#container = container;
|
|
6745
|
+
this.#clickPositionPlugins = [];
|
|
6746
|
+
this.#interactionManager = interactionManager;
|
|
6747
|
+
this.#touches = new Map();
|
|
6748
|
+
this.#handlers = {
|
|
6655
6749
|
mouseDown: () => {
|
|
6656
|
-
this
|
|
6750
|
+
this.#mouseDown();
|
|
6657
6751
|
},
|
|
6658
6752
|
mouseLeave: () => {
|
|
6659
|
-
this
|
|
6753
|
+
this.#mouseTouchFinish();
|
|
6660
6754
|
},
|
|
6661
6755
|
mouseMove: (e) => {
|
|
6662
|
-
this
|
|
6756
|
+
this.#mouseTouchMove(e);
|
|
6663
6757
|
},
|
|
6664
6758
|
mouseUp: (e) => {
|
|
6665
|
-
this
|
|
6759
|
+
this.#mouseTouchClick(e);
|
|
6666
6760
|
},
|
|
6667
6761
|
touchStart: (e) => {
|
|
6668
|
-
this
|
|
6762
|
+
this.#touchStart(e);
|
|
6669
6763
|
},
|
|
6670
6764
|
touchMove: (e) => {
|
|
6671
|
-
this
|
|
6765
|
+
this.#mouseTouchMove(e);
|
|
6672
6766
|
},
|
|
6673
6767
|
touchEnd: (e) => {
|
|
6674
|
-
this
|
|
6768
|
+
this.#touchEnd(e);
|
|
6675
6769
|
},
|
|
6676
6770
|
touchCancel: (e) => {
|
|
6677
|
-
this
|
|
6771
|
+
this.#touchEnd(e);
|
|
6678
6772
|
},
|
|
6679
6773
|
touchEndClick: (e) => {
|
|
6680
|
-
this
|
|
6774
|
+
this.#touchEndClick(e);
|
|
6681
6775
|
},
|
|
6682
6776
|
visibilityChange: () => {
|
|
6683
|
-
this
|
|
6777
|
+
this.#handleVisibilityChange();
|
|
6684
6778
|
},
|
|
6685
6779
|
};
|
|
6686
6780
|
}
|
|
6687
6781
|
addListeners() {
|
|
6688
|
-
this
|
|
6782
|
+
this.#manageListeners(true);
|
|
6689
6783
|
}
|
|
6690
6784
|
init() {
|
|
6691
|
-
this.
|
|
6692
|
-
for (const plugin of this.
|
|
6693
|
-
this.
|
|
6785
|
+
this.#clickPositionPlugins.length = 0;
|
|
6786
|
+
for (const plugin of this.#container.plugins.filter(p => !!p.clickPositionValid)) {
|
|
6787
|
+
this.#clickPositionPlugins.push(plugin);
|
|
6694
6788
|
}
|
|
6695
6789
|
}
|
|
6696
6790
|
removeListeners() {
|
|
6697
|
-
this
|
|
6791
|
+
this.#manageListeners(false);
|
|
6698
6792
|
}
|
|
6699
|
-
|
|
6700
|
-
const container = this
|
|
6701
|
-
if (this
|
|
6793
|
+
#doMouseTouchClick = e => {
|
|
6794
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions;
|
|
6795
|
+
if (this.#canPush) {
|
|
6702
6796
|
const mouseInteractivity = interactionManager.interactivityData.mouse, mousePos = mouseInteractivity.position;
|
|
6703
6797
|
if (!mousePos) {
|
|
6704
6798
|
return;
|
|
@@ -6715,15 +6809,15 @@
|
|
|
6715
6809
|
}
|
|
6716
6810
|
if (e.type === "touchend") {
|
|
6717
6811
|
setTimeout(() => {
|
|
6718
|
-
this
|
|
6812
|
+
this.#mouseTouchFinish();
|
|
6719
6813
|
}, touchDelay);
|
|
6720
6814
|
}
|
|
6721
6815
|
};
|
|
6722
|
-
|
|
6723
|
-
this
|
|
6816
|
+
#handleVisibilityChange = () => {
|
|
6817
|
+
this.#mouseTouchFinish();
|
|
6724
6818
|
};
|
|
6725
|
-
|
|
6726
|
-
const handlers = this
|
|
6819
|
+
#manageInteractivityListeners = add => {
|
|
6820
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivityEl = interactionManager.interactivityData.element;
|
|
6727
6821
|
if (!interactivityEl) {
|
|
6728
6822
|
return;
|
|
6729
6823
|
}
|
|
@@ -6754,8 +6848,8 @@
|
|
|
6754
6848
|
manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
|
|
6755
6849
|
manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
|
6756
6850
|
};
|
|
6757
|
-
|
|
6758
|
-
const handlers = this
|
|
6851
|
+
#manageListeners = add => {
|
|
6852
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, detectType = options.interactivity?.detectsOn, canvasEl = container.canvas.domElement;
|
|
6759
6853
|
if (detectType === InteractivityDetect.window) {
|
|
6760
6854
|
interactionManager.interactivityData.element = safeDocument();
|
|
6761
6855
|
}
|
|
@@ -6765,35 +6859,35 @@
|
|
|
6765
6859
|
else {
|
|
6766
6860
|
interactionManager.interactivityData.element = canvasEl;
|
|
6767
6861
|
}
|
|
6768
|
-
this
|
|
6862
|
+
this.#manageInteractivityListeners(add);
|
|
6769
6863
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
6770
6864
|
};
|
|
6771
|
-
|
|
6772
|
-
const { interactivityData } = this
|
|
6865
|
+
#mouseDown = () => {
|
|
6866
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
6773
6867
|
mouse.clicking = true;
|
|
6774
6868
|
mouse.downPosition = mouse.position;
|
|
6775
6869
|
};
|
|
6776
|
-
|
|
6777
|
-
const container = this
|
|
6870
|
+
#mouseTouchClick = e => {
|
|
6871
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
|
|
6778
6872
|
mouse.inside = true;
|
|
6779
6873
|
let handled = false;
|
|
6780
6874
|
const mousePosition = mouse.position;
|
|
6781
6875
|
if (!mousePosition || !options.interactivity?.events.onClick.enable) {
|
|
6782
6876
|
return;
|
|
6783
6877
|
}
|
|
6784
|
-
for (const plugin of this
|
|
6878
|
+
for (const plugin of this.#clickPositionPlugins) {
|
|
6785
6879
|
handled = plugin.clickPositionValid?.(mousePosition) ?? false;
|
|
6786
6880
|
if (handled) {
|
|
6787
6881
|
break;
|
|
6788
6882
|
}
|
|
6789
6883
|
}
|
|
6790
6884
|
if (!handled) {
|
|
6791
|
-
this
|
|
6885
|
+
this.#doMouseTouchClick(e);
|
|
6792
6886
|
}
|
|
6793
6887
|
mouse.clicking = false;
|
|
6794
6888
|
};
|
|
6795
|
-
|
|
6796
|
-
const { interactivityData } = this
|
|
6889
|
+
#mouseTouchFinish = () => {
|
|
6890
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
6797
6891
|
delete mouse.position;
|
|
6798
6892
|
delete mouse.clickPosition;
|
|
6799
6893
|
delete mouse.downPosition;
|
|
@@ -6801,15 +6895,15 @@
|
|
|
6801
6895
|
mouse.inside = false;
|
|
6802
6896
|
mouse.clicking = false;
|
|
6803
6897
|
};
|
|
6804
|
-
|
|
6805
|
-
const container = this
|
|
6898
|
+
#mouseTouchMove = e => {
|
|
6899
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivity = interactionManager.interactivityData, canvasEl = container.canvas.domElement;
|
|
6806
6900
|
if (!interactivity.element) {
|
|
6807
6901
|
return;
|
|
6808
6902
|
}
|
|
6809
6903
|
interactivity.mouse.inside = true;
|
|
6810
6904
|
let pos;
|
|
6811
6905
|
if (e.type.startsWith("pointer")) {
|
|
6812
|
-
this
|
|
6906
|
+
this.#canPush = true;
|
|
6813
6907
|
const mouseEvent = e;
|
|
6814
6908
|
if (interactivity.element === safeDocument()) {
|
|
6815
6909
|
if (canvasEl) {
|
|
@@ -6844,7 +6938,7 @@
|
|
|
6844
6938
|
}
|
|
6845
6939
|
}
|
|
6846
6940
|
else {
|
|
6847
|
-
this
|
|
6941
|
+
this.#canPush = e.type !== "touchmove";
|
|
6848
6942
|
if (canvasEl) {
|
|
6849
6943
|
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
|
|
6850
6944
|
if (!lastTouch) {
|
|
@@ -6864,60 +6958,60 @@
|
|
|
6864
6958
|
interactivity.mouse.position = pos;
|
|
6865
6959
|
interactivity.status = mouseMoveEvent;
|
|
6866
6960
|
};
|
|
6867
|
-
|
|
6961
|
+
#touchEnd = e => {
|
|
6868
6962
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6869
6963
|
for (const touch of touches) {
|
|
6870
|
-
this.
|
|
6964
|
+
this.#touches.delete(touch.identifier);
|
|
6871
6965
|
}
|
|
6872
|
-
this
|
|
6966
|
+
this.#mouseTouchFinish();
|
|
6873
6967
|
};
|
|
6874
|
-
|
|
6968
|
+
#touchEndClick = e => {
|
|
6875
6969
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6876
6970
|
for (const touch of touches) {
|
|
6877
|
-
this.
|
|
6971
|
+
this.#touches.delete(touch.identifier);
|
|
6878
6972
|
}
|
|
6879
|
-
this
|
|
6973
|
+
this.#mouseTouchClick(e);
|
|
6880
6974
|
};
|
|
6881
|
-
|
|
6975
|
+
#touchStart = e => {
|
|
6882
6976
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
6883
6977
|
for (const touch of touches) {
|
|
6884
|
-
this.
|
|
6978
|
+
this.#touches.set(touch.identifier, performance.now());
|
|
6885
6979
|
}
|
|
6886
|
-
this
|
|
6980
|
+
this.#mouseTouchMove(e);
|
|
6887
6981
|
};
|
|
6888
6982
|
}
|
|
6889
6983
|
|
|
6890
6984
|
const clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0;
|
|
6891
6985
|
class InteractionManager {
|
|
6892
|
-
container;
|
|
6893
6986
|
interactivityData;
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6987
|
+
#clickHandlers;
|
|
6988
|
+
#container;
|
|
6989
|
+
#eventListeners;
|
|
6990
|
+
#externalInteractors;
|
|
6991
|
+
#interactors;
|
|
6992
|
+
#intersectionObserver;
|
|
6993
|
+
#particleInteractors;
|
|
6994
|
+
#pluginManager;
|
|
6901
6995
|
constructor(pluginManager, container) {
|
|
6902
|
-
this
|
|
6903
|
-
this
|
|
6904
|
-
this
|
|
6905
|
-
this
|
|
6906
|
-
this
|
|
6907
|
-
this
|
|
6908
|
-
this
|
|
6996
|
+
this.#container = container;
|
|
6997
|
+
this.#pluginManager = pluginManager;
|
|
6998
|
+
this.#interactors = [];
|
|
6999
|
+
this.#externalInteractors = [];
|
|
7000
|
+
this.#particleInteractors = [];
|
|
7001
|
+
this.#clickHandlers = new Map();
|
|
7002
|
+
this.#eventListeners = new InteractivityEventListeners(container, this);
|
|
6909
7003
|
this.interactivityData = {
|
|
6910
7004
|
mouse: {
|
|
6911
7005
|
clicking: false,
|
|
6912
7006
|
inside: false,
|
|
6913
7007
|
},
|
|
6914
7008
|
};
|
|
6915
|
-
this
|
|
6916
|
-
this
|
|
7009
|
+
this.#intersectionObserver = safeIntersectionObserver(entries => {
|
|
7010
|
+
this.#intersectionManager(entries);
|
|
6917
7011
|
});
|
|
6918
7012
|
}
|
|
6919
7013
|
addClickHandler(callback) {
|
|
6920
|
-
const
|
|
7014
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
6921
7015
|
if (container.destroyed) {
|
|
6922
7016
|
return;
|
|
6923
7017
|
}
|
|
@@ -6979,119 +7073,119 @@
|
|
|
6979
7073
|
touchMoved = false;
|
|
6980
7074
|
};
|
|
6981
7075
|
let touched = false, touchMoved = false;
|
|
6982
|
-
this.
|
|
6983
|
-
this.
|
|
6984
|
-
this.
|
|
6985
|
-
this.
|
|
6986
|
-
this.
|
|
6987
|
-
for (const [key, handler] of this
|
|
7076
|
+
this.#clickHandlers.set(clickEvent, clickHandler);
|
|
7077
|
+
this.#clickHandlers.set(touchStartEvent, touchStartHandler);
|
|
7078
|
+
this.#clickHandlers.set(touchMoveEvent, touchMoveHandler);
|
|
7079
|
+
this.#clickHandlers.set(touchEndEvent, touchEndHandler);
|
|
7080
|
+
this.#clickHandlers.set(touchCancelEvent, touchCancelHandler);
|
|
7081
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
6988
7082
|
el.addEventListener(key, handler);
|
|
6989
7083
|
}
|
|
6990
7084
|
}
|
|
6991
7085
|
addListeners() {
|
|
6992
|
-
this.
|
|
7086
|
+
this.#eventListeners.addListeners();
|
|
6993
7087
|
}
|
|
6994
7088
|
clearClickHandlers() {
|
|
6995
|
-
const
|
|
7089
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
6996
7090
|
if (container.destroyed) {
|
|
6997
7091
|
return;
|
|
6998
7092
|
}
|
|
6999
|
-
for (const [key, handler] of this
|
|
7093
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7000
7094
|
interactivityData.element?.removeEventListener(key, handler);
|
|
7001
7095
|
}
|
|
7002
|
-
this.
|
|
7096
|
+
this.#clickHandlers.clear();
|
|
7003
7097
|
}
|
|
7004
7098
|
externalInteract(delta) {
|
|
7005
|
-
for (const interactor of this
|
|
7006
|
-
const
|
|
7099
|
+
for (const interactor of this.#externalInteractors) {
|
|
7100
|
+
const interactivityData = this.interactivityData;
|
|
7007
7101
|
if (interactor.isEnabled(interactivityData)) {
|
|
7008
7102
|
interactor.interact(interactivityData, delta);
|
|
7009
7103
|
}
|
|
7010
7104
|
}
|
|
7011
7105
|
}
|
|
7012
7106
|
handleClickMode(mode) {
|
|
7013
|
-
if (this
|
|
7107
|
+
if (this.#container.destroyed) {
|
|
7014
7108
|
return;
|
|
7015
7109
|
}
|
|
7016
|
-
const
|
|
7017
|
-
for (const interactor of this
|
|
7110
|
+
const interactivityData = this.interactivityData;
|
|
7111
|
+
for (const interactor of this.#externalInteractors) {
|
|
7018
7112
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
7019
7113
|
}
|
|
7020
7114
|
}
|
|
7021
7115
|
init() {
|
|
7022
|
-
this.
|
|
7023
|
-
for (const interactor of this
|
|
7116
|
+
this.#eventListeners.init();
|
|
7117
|
+
for (const interactor of this.#interactors) {
|
|
7024
7118
|
switch (interactor.type) {
|
|
7025
7119
|
case InteractorType.external:
|
|
7026
|
-
this.
|
|
7120
|
+
this.#externalInteractors.push(interactor);
|
|
7027
7121
|
break;
|
|
7028
7122
|
case InteractorType.particles:
|
|
7029
|
-
this.
|
|
7123
|
+
this.#particleInteractors.push(interactor);
|
|
7030
7124
|
break;
|
|
7031
7125
|
}
|
|
7032
7126
|
interactor.init();
|
|
7033
7127
|
}
|
|
7034
7128
|
}
|
|
7035
7129
|
async initInteractors() {
|
|
7036
|
-
const interactors = await this.
|
|
7130
|
+
const interactors = await this.#pluginManager.getInteractors?.(this.#container, true);
|
|
7037
7131
|
if (!interactors) {
|
|
7038
7132
|
return;
|
|
7039
7133
|
}
|
|
7040
|
-
this
|
|
7041
|
-
this
|
|
7042
|
-
this
|
|
7134
|
+
this.#interactors = interactors;
|
|
7135
|
+
this.#externalInteractors = [];
|
|
7136
|
+
this.#particleInteractors = [];
|
|
7043
7137
|
}
|
|
7044
7138
|
particlesInteract(particle, delta) {
|
|
7045
|
-
const
|
|
7046
|
-
for (const interactor of this
|
|
7139
|
+
const interactivityData = this.interactivityData;
|
|
7140
|
+
for (const interactor of this.#externalInteractors) {
|
|
7047
7141
|
interactor.clear(particle, delta);
|
|
7048
7142
|
}
|
|
7049
|
-
for (const interactor of this
|
|
7143
|
+
for (const interactor of this.#particleInteractors) {
|
|
7050
7144
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7051
7145
|
interactor.interact(particle, interactivityData, delta);
|
|
7052
7146
|
}
|
|
7053
7147
|
}
|
|
7054
7148
|
}
|
|
7055
7149
|
removeListeners() {
|
|
7056
|
-
this.
|
|
7150
|
+
this.#eventListeners.removeListeners();
|
|
7057
7151
|
}
|
|
7058
7152
|
reset(particle) {
|
|
7059
|
-
const
|
|
7060
|
-
for (const interactor of this
|
|
7153
|
+
const interactivityData = this.interactivityData;
|
|
7154
|
+
for (const interactor of this.#externalInteractors) {
|
|
7061
7155
|
if (interactor.isEnabled(interactivityData)) {
|
|
7062
7156
|
interactor.reset(interactivityData, particle);
|
|
7063
7157
|
}
|
|
7064
7158
|
}
|
|
7065
|
-
for (const interactor of this
|
|
7159
|
+
for (const interactor of this.#particleInteractors) {
|
|
7066
7160
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7067
7161
|
interactor.reset(interactivityData, particle);
|
|
7068
7162
|
}
|
|
7069
7163
|
}
|
|
7070
7164
|
}
|
|
7071
7165
|
startObserving() {
|
|
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.observe(interactivityData.element);
|
|
7075
7169
|
}
|
|
7076
7170
|
}
|
|
7077
7171
|
stopObserving() {
|
|
7078
|
-
const
|
|
7079
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7080
|
-
this.
|
|
7172
|
+
const interactivityData = this.interactivityData;
|
|
7173
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7174
|
+
this.#intersectionObserver.unobserve(interactivityData.element);
|
|
7081
7175
|
}
|
|
7082
7176
|
}
|
|
7083
7177
|
updateMaxDistance() {
|
|
7084
7178
|
let maxTotalDistance = 0;
|
|
7085
|
-
for (const interactor of this
|
|
7179
|
+
for (const interactor of this.#interactors) {
|
|
7086
7180
|
if (interactor.maxDistance > maxTotalDistance) {
|
|
7087
7181
|
maxTotalDistance = interactor.maxDistance;
|
|
7088
7182
|
}
|
|
7089
7183
|
}
|
|
7090
|
-
const container = this
|
|
7184
|
+
const container = this.#container;
|
|
7091
7185
|
container.particles.grid.setCellSize(maxTotalDistance * container.retina.pixelRatio);
|
|
7092
7186
|
}
|
|
7093
|
-
|
|
7094
|
-
const
|
|
7187
|
+
#intersectionManager = entries => {
|
|
7188
|
+
const container = this.#container;
|
|
7095
7189
|
if (container.destroyed || !container.actualOptions.pauseOnOutsideViewport) {
|
|
7096
7190
|
return;
|
|
7097
7191
|
}
|
|
@@ -7111,13 +7205,13 @@
|
|
|
7111
7205
|
|
|
7112
7206
|
class InteractivityPluginInstance {
|
|
7113
7207
|
interactionManager;
|
|
7114
|
-
|
|
7115
|
-
|
|
7208
|
+
#container;
|
|
7209
|
+
#pluginManager;
|
|
7116
7210
|
constructor(pluginManager, container) {
|
|
7117
|
-
this
|
|
7118
|
-
this
|
|
7211
|
+
this.#container = container;
|
|
7212
|
+
this.#pluginManager = pluginManager;
|
|
7119
7213
|
this.interactionManager = new InteractionManager(pluginManager, container);
|
|
7120
|
-
this.
|
|
7214
|
+
this.#container.addClickHandler = (callback) => {
|
|
7121
7215
|
this.interactionManager.addClickHandler(callback);
|
|
7122
7216
|
};
|
|
7123
7217
|
}
|
|
@@ -7129,11 +7223,11 @@
|
|
|
7129
7223
|
}
|
|
7130
7224
|
destroy() {
|
|
7131
7225
|
this.clearClickHandlers();
|
|
7132
|
-
this.
|
|
7226
|
+
this.#pluginManager.interactors?.delete(this.#container);
|
|
7133
7227
|
}
|
|
7134
7228
|
particleCreated(particle) {
|
|
7135
|
-
const interactivityParticle = particle, interactivity = new Interactivity(this
|
|
7136
|
-
interactivity.load(this.
|
|
7229
|
+
const interactivityParticle = particle, interactivity = new Interactivity(this.#pluginManager, this.#container);
|
|
7230
|
+
interactivity.load(this.#container.actualOptions.interactivity);
|
|
7137
7231
|
interactivity.load(interactivityParticle.options.interactivity);
|
|
7138
7232
|
interactivityParticle.interactivity = interactivity;
|
|
7139
7233
|
}
|
|
@@ -7186,14 +7280,14 @@
|
|
|
7186
7280
|
|
|
7187
7281
|
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;
|
|
7188
7282
|
class LinkInstance {
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7283
|
+
#colorCache = new Map();
|
|
7284
|
+
#container;
|
|
7285
|
+
#freqs;
|
|
7286
|
+
#pluginManager;
|
|
7193
7287
|
constructor(pluginManager, container) {
|
|
7194
|
-
this
|
|
7195
|
-
this
|
|
7196
|
-
this
|
|
7288
|
+
this.#pluginManager = pluginManager;
|
|
7289
|
+
this.#container = container;
|
|
7290
|
+
this.#freqs = { links: new Map(), triangles: new Map() };
|
|
7197
7291
|
}
|
|
7198
7292
|
drawParticle(context, particle) {
|
|
7199
7293
|
const { links, options } = particle;
|
|
@@ -7210,13 +7304,13 @@
|
|
|
7210
7304
|
};
|
|
7211
7305
|
for (const link of links) {
|
|
7212
7306
|
if (linkOpts.frequency < maxFrequency &&
|
|
7213
|
-
this
|
|
7307
|
+
this.#getLinkFrequency(particle, link.destination) > linkOpts.frequency) {
|
|
7214
7308
|
continue;
|
|
7215
7309
|
}
|
|
7216
7310
|
const pos2 = link.destination.getPosition();
|
|
7217
7311
|
if (trianglesEnabled && !link.isWarped && p1Destinations) {
|
|
7218
7312
|
flushLines();
|
|
7219
|
-
this
|
|
7313
|
+
this.#drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);
|
|
7220
7314
|
}
|
|
7221
7315
|
if (link.opacity <= minOpacity || width <= minWidth) {
|
|
7222
7316
|
continue;
|
|
@@ -7226,7 +7320,7 @@
|
|
|
7226
7320
|
}
|
|
7227
7321
|
let opacity = link.opacity, colorLine = link.color;
|
|
7228
7322
|
const twinkleRgb = twinkle?.enable && getRandom() < twinkle.frequency
|
|
7229
|
-
? rangeColorToRgb(this
|
|
7323
|
+
? rangeColorToRgb(this.#pluginManager, twinkle.color)
|
|
7230
7324
|
: undefined;
|
|
7231
7325
|
if (twinkle && twinkleRgb) {
|
|
7232
7326
|
colorLine = twinkleRgb;
|
|
@@ -7234,14 +7328,14 @@
|
|
|
7234
7328
|
}
|
|
7235
7329
|
if (!colorLine) {
|
|
7236
7330
|
const linkColor = linkOpts.id !== undefined
|
|
7237
|
-
? this.
|
|
7238
|
-
: this.
|
|
7331
|
+
? this.#container.particles.linksColors.get(linkOpts.id)
|
|
7332
|
+
: this.#container.particles.linksColor;
|
|
7239
7333
|
colorLine = getLinkColor(particle, link.destination, linkColor);
|
|
7240
7334
|
}
|
|
7241
7335
|
if (!colorLine) {
|
|
7242
7336
|
continue;
|
|
7243
7337
|
}
|
|
7244
|
-
const colorStyle = this
|
|
7338
|
+
const colorStyle = this.#getCachedStyle(colorLine);
|
|
7245
7339
|
if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {
|
|
7246
7340
|
flushLines();
|
|
7247
7341
|
context.strokeStyle = colorStyle;
|
|
@@ -7254,7 +7348,7 @@
|
|
|
7254
7348
|
pathOpen = true;
|
|
7255
7349
|
}
|
|
7256
7350
|
if (link.isWarped) {
|
|
7257
|
-
const canvasSize = this.
|
|
7351
|
+
const canvasSize = this.#container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
7258
7352
|
let sx = originPoint.x, sy = originPoint.y;
|
|
7259
7353
|
if (Math.abs(dx) > canvasSize.width * half) {
|
|
7260
7354
|
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
@@ -7276,9 +7370,9 @@
|
|
|
7276
7370
|
context.globalAlpha = originalAlpha;
|
|
7277
7371
|
}
|
|
7278
7372
|
init() {
|
|
7279
|
-
this.
|
|
7280
|
-
this.
|
|
7281
|
-
this.
|
|
7373
|
+
this.#freqs.links.clear();
|
|
7374
|
+
this.#freqs.triangles.clear();
|
|
7375
|
+
this.#colorCache.clear();
|
|
7282
7376
|
return Promise.resolve();
|
|
7283
7377
|
}
|
|
7284
7378
|
particleCreated(particle) {
|
|
@@ -7288,14 +7382,14 @@
|
|
|
7288
7382
|
}
|
|
7289
7383
|
particle.linksDistance = particle.options.links.distance;
|
|
7290
7384
|
particle.linksWidth = particle.options.links.width;
|
|
7291
|
-
const ratio = this.
|
|
7385
|
+
const ratio = this.#container.retina.pixelRatio;
|
|
7292
7386
|
particle.retina.linksDistance = particle.linksDistance * ratio;
|
|
7293
7387
|
particle.retina.linksWidth = particle.linksWidth * ratio;
|
|
7294
7388
|
}
|
|
7295
7389
|
particleDestroyed(particle) {
|
|
7296
7390
|
particle.links = [];
|
|
7297
7391
|
}
|
|
7298
|
-
|
|
7392
|
+
#drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {
|
|
7299
7393
|
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
7300
7394
|
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
7301
7395
|
return;
|
|
@@ -7306,21 +7400,21 @@
|
|
|
7306
7400
|
}
|
|
7307
7401
|
for (const vertex of p2Links) {
|
|
7308
7402
|
if (vertex.isWarped ||
|
|
7309
|
-
this
|
|
7403
|
+
this.#getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency ||
|
|
7310
7404
|
!p1Destinations.has(vertex.destination.id)) {
|
|
7311
7405
|
continue;
|
|
7312
7406
|
}
|
|
7313
7407
|
const p3 = vertex.destination;
|
|
7314
|
-
if (this
|
|
7408
|
+
if (this.#getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
7315
7409
|
continue;
|
|
7316
7410
|
}
|
|
7317
|
-
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this
|
|
7411
|
+
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this.#pluginManager, triangleOptions.color) ?? link.color;
|
|
7318
7412
|
if (!colorTriangle || opacityTriangle <= minOpacity) {
|
|
7319
7413
|
continue;
|
|
7320
7414
|
}
|
|
7321
7415
|
const pos3 = p3.getPosition();
|
|
7322
7416
|
context.save();
|
|
7323
|
-
context.fillStyle = this
|
|
7417
|
+
context.fillStyle = this.#getCachedStyle(colorTriangle);
|
|
7324
7418
|
context.globalAlpha = opacityTriangle;
|
|
7325
7419
|
context.beginPath();
|
|
7326
7420
|
context.moveTo(pos1.x, pos1.y);
|
|
@@ -7331,20 +7425,20 @@
|
|
|
7331
7425
|
context.restore();
|
|
7332
7426
|
}
|
|
7333
7427
|
}
|
|
7334
|
-
|
|
7428
|
+
#getCachedStyle(rgb) {
|
|
7335
7429
|
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
7336
|
-
let style = this.
|
|
7430
|
+
let style = this.#colorCache.get(key);
|
|
7337
7431
|
if (!style) {
|
|
7338
|
-
style = getStyleFromRgb(rgb, this.
|
|
7339
|
-
this.
|
|
7432
|
+
style = getStyleFromRgb(rgb, this.#container.hdr);
|
|
7433
|
+
this.#colorCache.set(key, style);
|
|
7340
7434
|
}
|
|
7341
7435
|
return style;
|
|
7342
7436
|
}
|
|
7343
|
-
|
|
7344
|
-
return setLinkFrequency([p1, p2], this.
|
|
7437
|
+
#getLinkFrequency(p1, p2) {
|
|
7438
|
+
return setLinkFrequency([p1, p2], this.#freqs.links);
|
|
7345
7439
|
}
|
|
7346
|
-
|
|
7347
|
-
return setLinkFrequency([p1, p2, p3], this.
|
|
7440
|
+
#getTriangleFrequency(p1, p2, p3) {
|
|
7441
|
+
return setLinkFrequency([p1, p2, p3], this.#freqs.triangles);
|
|
7348
7442
|
}
|
|
7349
7443
|
}
|
|
7350
7444
|
|