@tsparticles/preset-confetti-cannon 4.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* Preset v4.0
|
|
2
|
+
/* Preset v4.1.0 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -717,38 +717,38 @@
|
|
|
717
717
|
}
|
|
718
718
|
|
|
719
719
|
class EventDispatcher {
|
|
720
|
-
|
|
720
|
+
#listeners;
|
|
721
721
|
constructor() {
|
|
722
|
-
this
|
|
722
|
+
this.#listeners = new Map();
|
|
723
723
|
}
|
|
724
724
|
addEventListener(type, listener) {
|
|
725
725
|
this.removeEventListener(type, listener);
|
|
726
|
-
let arr = this.
|
|
726
|
+
let arr = this.#listeners.get(type);
|
|
727
727
|
if (!arr) {
|
|
728
728
|
arr = [];
|
|
729
|
-
this.
|
|
729
|
+
this.#listeners.set(type, arr);
|
|
730
730
|
}
|
|
731
731
|
arr.push(listener);
|
|
732
732
|
}
|
|
733
733
|
dispatchEvent(type, args) {
|
|
734
|
-
const listeners = this.
|
|
734
|
+
const listeners = this.#listeners.get(type);
|
|
735
735
|
listeners?.forEach(handler => {
|
|
736
736
|
handler(args);
|
|
737
737
|
});
|
|
738
738
|
}
|
|
739
739
|
hasEventListener(type) {
|
|
740
|
-
return !!this.
|
|
740
|
+
return !!this.#listeners.get(type);
|
|
741
741
|
}
|
|
742
742
|
removeAllEventListeners(type) {
|
|
743
743
|
if (!type) {
|
|
744
|
-
this
|
|
744
|
+
this.#listeners = new Map();
|
|
745
745
|
}
|
|
746
746
|
else {
|
|
747
|
-
this.
|
|
747
|
+
this.#listeners.delete(type);
|
|
748
748
|
}
|
|
749
749
|
}
|
|
750
750
|
removeEventListener(type, listener) {
|
|
751
|
-
const arr = this.
|
|
751
|
+
const arr = this.#listeners.get(type);
|
|
752
752
|
if (!arr) {
|
|
753
753
|
return;
|
|
754
754
|
}
|
|
@@ -757,7 +757,7 @@
|
|
|
757
757
|
return;
|
|
758
758
|
}
|
|
759
759
|
if (length === deleteCount) {
|
|
760
|
-
this.
|
|
760
|
+
this.#listeners.delete(type);
|
|
761
761
|
}
|
|
762
762
|
else {
|
|
763
763
|
arr.splice(idx, deleteCount);
|
|
@@ -795,19 +795,19 @@
|
|
|
795
795
|
presets = new Map();
|
|
796
796
|
shapeDrawers = new Map();
|
|
797
797
|
updaters = new Map();
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
798
|
+
#allLoadersSet = new Set();
|
|
799
|
+
#configs = new Map();
|
|
800
|
+
#engine;
|
|
801
|
+
#executedSet = new Set();
|
|
802
|
+
#initialized = false;
|
|
803
|
+
#isRunningLoaders = false;
|
|
804
|
+
#loadPromises = new Set();
|
|
805
805
|
constructor(engine) {
|
|
806
|
-
this
|
|
806
|
+
this.#engine = engine;
|
|
807
807
|
}
|
|
808
808
|
get configs() {
|
|
809
809
|
const res = {};
|
|
810
|
-
for (const [name, config] of this
|
|
810
|
+
for (const [name, config] of this.#configs) {
|
|
811
811
|
res[name] = config;
|
|
812
812
|
}
|
|
813
813
|
return res;
|
|
@@ -817,8 +817,8 @@
|
|
|
817
817
|
}
|
|
818
818
|
addConfig(config) {
|
|
819
819
|
const key = config.key ?? config.name ?? "default";
|
|
820
|
-
this.
|
|
821
|
-
this.
|
|
820
|
+
this.#configs.set(key, config);
|
|
821
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
822
822
|
}
|
|
823
823
|
addEasing(name, easing) {
|
|
824
824
|
if (this.easingFunctions.get(name)) {
|
|
@@ -879,21 +879,21 @@
|
|
|
879
879
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
880
880
|
}
|
|
881
881
|
async init() {
|
|
882
|
-
if (this
|
|
882
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
883
883
|
return;
|
|
884
884
|
}
|
|
885
|
-
this
|
|
886
|
-
this
|
|
887
|
-
this
|
|
885
|
+
this.#isRunningLoaders = true;
|
|
886
|
+
this.#executedSet = new Set();
|
|
887
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
888
888
|
try {
|
|
889
|
-
for (const loader of this
|
|
890
|
-
await this
|
|
889
|
+
for (const loader of this.#allLoadersSet) {
|
|
890
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
891
891
|
}
|
|
892
892
|
}
|
|
893
893
|
finally {
|
|
894
|
-
this.
|
|
895
|
-
this
|
|
896
|
-
this
|
|
894
|
+
this.#loadPromises.clear();
|
|
895
|
+
this.#isRunningLoaders = false;
|
|
896
|
+
this.#initialized = true;
|
|
897
897
|
}
|
|
898
898
|
}
|
|
899
899
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -904,24 +904,24 @@
|
|
|
904
904
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
905
905
|
}
|
|
906
906
|
async register(...loaders) {
|
|
907
|
-
if (this
|
|
907
|
+
if (this.#initialized) {
|
|
908
908
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
909
909
|
}
|
|
910
910
|
for (const loader of loaders) {
|
|
911
|
-
if (this
|
|
912
|
-
await this
|
|
911
|
+
if (this.#isRunningLoaders) {
|
|
912
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
913
913
|
}
|
|
914
914
|
else {
|
|
915
|
-
this.
|
|
915
|
+
this.#loadPromises.add(loader);
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
|
-
async
|
|
919
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
920
920
|
if (executed.has(loader))
|
|
921
921
|
return;
|
|
922
922
|
executed.add(loader);
|
|
923
923
|
allLoaders.add(loader);
|
|
924
|
-
await loader(this
|
|
924
|
+
await loader(this.#engine);
|
|
925
925
|
}
|
|
926
926
|
}
|
|
927
927
|
|
|
@@ -1001,17 +1001,17 @@
|
|
|
1001
1001
|
};
|
|
1002
1002
|
class Engine {
|
|
1003
1003
|
pluginManager = new PluginManager(this);
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1004
|
+
#domArray = [];
|
|
1005
|
+
#eventDispatcher = new EventDispatcher();
|
|
1006
|
+
#initialized = false;
|
|
1007
1007
|
get items() {
|
|
1008
|
-
return this
|
|
1008
|
+
return this.#domArray;
|
|
1009
1009
|
}
|
|
1010
1010
|
get version() {
|
|
1011
|
-
return "4.0
|
|
1011
|
+
return "4.1.0";
|
|
1012
1012
|
}
|
|
1013
1013
|
addEventListener(type, listener) {
|
|
1014
|
-
this.
|
|
1014
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1015
1015
|
}
|
|
1016
1016
|
checkVersion(pluginVersion) {
|
|
1017
1017
|
if (this.version === pluginVersion) {
|
|
@@ -1020,17 +1020,17 @@
|
|
|
1020
1020
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1021
1021
|
}
|
|
1022
1022
|
dispatchEvent(type, args) {
|
|
1023
|
-
this.
|
|
1023
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1024
1024
|
}
|
|
1025
1025
|
async init() {
|
|
1026
|
-
if (this
|
|
1026
|
+
if (this.#initialized) {
|
|
1027
1027
|
return;
|
|
1028
1028
|
}
|
|
1029
1029
|
await this.pluginManager.init();
|
|
1030
|
-
this
|
|
1030
|
+
this.#initialized = true;
|
|
1031
1031
|
}
|
|
1032
1032
|
item(index) {
|
|
1033
|
-
const
|
|
1033
|
+
const items = this.items, item = items[index];
|
|
1034
1034
|
if (item?.destroyed) {
|
|
1035
1035
|
items.splice(index, removeDeleteCount);
|
|
1036
1036
|
return;
|
|
@@ -1084,7 +1084,7 @@
|
|
|
1084
1084
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1085
1085
|
}
|
|
1086
1086
|
removeEventListener(type, listener) {
|
|
1087
|
-
this.
|
|
1087
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1088
1088
|
}
|
|
1089
1089
|
}
|
|
1090
1090
|
|
|
@@ -1855,43 +1855,6 @@
|
|
|
1855
1855
|
}
|
|
1856
1856
|
}
|
|
1857
1857
|
|
|
1858
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1859
|
-
destroy;
|
|
1860
|
-
constructor() {
|
|
1861
|
-
super();
|
|
1862
|
-
this.destroy = DestroyType.none;
|
|
1863
|
-
this.speed = 2;
|
|
1864
|
-
}
|
|
1865
|
-
load(data) {
|
|
1866
|
-
super.load(data);
|
|
1867
|
-
if (isNull(data)) {
|
|
1868
|
-
return;
|
|
1869
|
-
}
|
|
1870
|
-
if (data.destroy !== undefined) {
|
|
1871
|
-
this.destroy = data.destroy;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1877
|
-
animation;
|
|
1878
|
-
constructor() {
|
|
1879
|
-
super();
|
|
1880
|
-
this.animation = new OpacityAnimation();
|
|
1881
|
-
this.value = 1;
|
|
1882
|
-
}
|
|
1883
|
-
load(data) {
|
|
1884
|
-
if (isNull(data)) {
|
|
1885
|
-
return;
|
|
1886
|
-
}
|
|
1887
|
-
super.load(data);
|
|
1888
|
-
const animation = data.animation;
|
|
1889
|
-
if (animation !== undefined) {
|
|
1890
|
-
this.animation.load(animation);
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
1858
|
class Stroke {
|
|
1896
1859
|
color;
|
|
1897
1860
|
opacity;
|
|
@@ -2059,43 +2022,6 @@
|
|
|
2059
2022
|
}
|
|
2060
2023
|
}
|
|
2061
2024
|
|
|
2062
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2063
|
-
destroy;
|
|
2064
|
-
constructor() {
|
|
2065
|
-
super();
|
|
2066
|
-
this.destroy = DestroyType.none;
|
|
2067
|
-
this.speed = 5;
|
|
2068
|
-
}
|
|
2069
|
-
load(data) {
|
|
2070
|
-
super.load(data);
|
|
2071
|
-
if (isNull(data)) {
|
|
2072
|
-
return;
|
|
2073
|
-
}
|
|
2074
|
-
if (data.destroy !== undefined) {
|
|
2075
|
-
this.destroy = data.destroy;
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2081
|
-
animation;
|
|
2082
|
-
constructor() {
|
|
2083
|
-
super();
|
|
2084
|
-
this.animation = new SizeAnimation();
|
|
2085
|
-
this.value = 3;
|
|
2086
|
-
}
|
|
2087
|
-
load(data) {
|
|
2088
|
-
super.load(data);
|
|
2089
|
-
if (isNull(data)) {
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
const animation = data.animation;
|
|
2093
|
-
if (animation !== undefined) {
|
|
2094
|
-
this.animation.load(animation);
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
2025
|
class ZIndex extends ValueWithRandom {
|
|
2100
2026
|
opacityRate;
|
|
2101
2027
|
sizeRate;
|
|
@@ -2129,24 +2055,21 @@
|
|
|
2129
2055
|
groups;
|
|
2130
2056
|
move;
|
|
2131
2057
|
number;
|
|
2132
|
-
opacity;
|
|
2133
2058
|
paint;
|
|
2134
2059
|
palette;
|
|
2135
2060
|
reduceDuplicates;
|
|
2136
2061
|
shape;
|
|
2137
|
-
size;
|
|
2138
2062
|
zIndex;
|
|
2139
|
-
|
|
2140
|
-
|
|
2063
|
+
#container;
|
|
2064
|
+
#pluginManager;
|
|
2141
2065
|
constructor(pluginManager, container) {
|
|
2142
|
-
this
|
|
2143
|
-
this
|
|
2066
|
+
this.#pluginManager = pluginManager;
|
|
2067
|
+
this.#container = container;
|
|
2144
2068
|
this.bounce = new ParticlesBounce();
|
|
2145
2069
|
this.effect = new Effect();
|
|
2146
2070
|
this.groups = {};
|
|
2147
2071
|
this.move = new Move();
|
|
2148
2072
|
this.number = new ParticlesNumber();
|
|
2149
|
-
this.opacity = new Opacity();
|
|
2150
2073
|
this.paint = new Paint();
|
|
2151
2074
|
this.paint.color = new AnimatableColor();
|
|
2152
2075
|
this.paint.color.value = "#fff";
|
|
@@ -2154,7 +2077,6 @@
|
|
|
2154
2077
|
this.paint.fill.enable = true;
|
|
2155
2078
|
this.reduceDuplicates = false;
|
|
2156
2079
|
this.shape = new Shape();
|
|
2157
|
-
this.size = new Size();
|
|
2158
2080
|
this.zIndex = new ZIndex();
|
|
2159
2081
|
}
|
|
2160
2082
|
load(data) {
|
|
@@ -2163,7 +2085,7 @@
|
|
|
2163
2085
|
}
|
|
2164
2086
|
if (data.palette) {
|
|
2165
2087
|
this.palette = data.palette;
|
|
2166
|
-
this
|
|
2088
|
+
this.#importPalette(this.palette);
|
|
2167
2089
|
}
|
|
2168
2090
|
if (data.groups !== undefined) {
|
|
2169
2091
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2183,7 +2105,6 @@
|
|
|
2183
2105
|
this.effect.load(data.effect);
|
|
2184
2106
|
this.move.load(data.move);
|
|
2185
2107
|
this.number.load(data.number);
|
|
2186
|
-
this.opacity.load(data.opacity);
|
|
2187
2108
|
const paintToLoad = data.paint;
|
|
2188
2109
|
if (paintToLoad) {
|
|
2189
2110
|
if (isArray(paintToLoad)) {
|
|
@@ -2202,15 +2123,14 @@
|
|
|
2202
2123
|
}
|
|
2203
2124
|
}
|
|
2204
2125
|
this.shape.load(data.shape);
|
|
2205
|
-
this.size.load(data.size);
|
|
2206
2126
|
this.zIndex.load(data.zIndex);
|
|
2207
|
-
if (this
|
|
2208
|
-
for (const plugin of this.
|
|
2127
|
+
if (this.#container) {
|
|
2128
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2209
2129
|
if (plugin.loadParticlesOptions) {
|
|
2210
|
-
plugin.loadParticlesOptions(this
|
|
2130
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2211
2131
|
}
|
|
2212
2132
|
}
|
|
2213
|
-
const updaters = this.
|
|
2133
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2214
2134
|
if (updaters) {
|
|
2215
2135
|
for (const updater of updaters) {
|
|
2216
2136
|
if (updater.loadOptions) {
|
|
@@ -2220,8 +2140,8 @@
|
|
|
2220
2140
|
}
|
|
2221
2141
|
}
|
|
2222
2142
|
}
|
|
2223
|
-
|
|
2224
|
-
const paletteData = this.
|
|
2143
|
+
#importPalette = (palette) => {
|
|
2144
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2225
2145
|
if (!paletteData) {
|
|
2226
2146
|
return;
|
|
2227
2147
|
}
|
|
@@ -2300,11 +2220,11 @@
|
|
|
2300
2220
|
smooth;
|
|
2301
2221
|
style;
|
|
2302
2222
|
zLayers;
|
|
2303
|
-
|
|
2304
|
-
|
|
2223
|
+
#container;
|
|
2224
|
+
#pluginManager;
|
|
2305
2225
|
constructor(pluginManager, container) {
|
|
2306
|
-
this
|
|
2307
|
-
this
|
|
2226
|
+
this.#pluginManager = pluginManager;
|
|
2227
|
+
this.#container = container;
|
|
2308
2228
|
this.autoPlay = true;
|
|
2309
2229
|
this.background = new Background();
|
|
2310
2230
|
this.clear = true;
|
|
@@ -2315,7 +2235,7 @@
|
|
|
2315
2235
|
this.duration = 0;
|
|
2316
2236
|
this.fpsLimit = 120;
|
|
2317
2237
|
this.hdr = true;
|
|
2318
|
-
this.particles = loadParticlesOptions(this
|
|
2238
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2319
2239
|
this.pauseOnBlur = true;
|
|
2320
2240
|
this.pauseOnOutsideViewport = true;
|
|
2321
2241
|
this.resize = new ResizeEvent();
|
|
@@ -2330,12 +2250,12 @@
|
|
|
2330
2250
|
if (data.preset !== undefined) {
|
|
2331
2251
|
this.preset = data.preset;
|
|
2332
2252
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2333
|
-
this
|
|
2253
|
+
this.#importPreset(preset);
|
|
2334
2254
|
});
|
|
2335
2255
|
}
|
|
2336
2256
|
if (data.palette !== undefined) {
|
|
2337
2257
|
this.palette = data.palette;
|
|
2338
|
-
this
|
|
2258
|
+
this.#importPalette(this.palette);
|
|
2339
2259
|
}
|
|
2340
2260
|
if (data.autoPlay !== undefined) {
|
|
2341
2261
|
this.autoPlay = data.autoPlay;
|
|
@@ -2389,12 +2309,12 @@
|
|
|
2389
2309
|
if (data.smooth !== undefined) {
|
|
2390
2310
|
this.smooth = data.smooth;
|
|
2391
2311
|
}
|
|
2392
|
-
this.
|
|
2393
|
-
plugin.loadOptions(this
|
|
2312
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2313
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2394
2314
|
});
|
|
2395
2315
|
}
|
|
2396
|
-
|
|
2397
|
-
const paletteData = this.
|
|
2316
|
+
#importPalette = palette => {
|
|
2317
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2398
2318
|
if (!paletteData) {
|
|
2399
2319
|
return;
|
|
2400
2320
|
}
|
|
@@ -2411,8 +2331,8 @@
|
|
|
2411
2331
|
},
|
|
2412
2332
|
});
|
|
2413
2333
|
};
|
|
2414
|
-
|
|
2415
|
-
this.load(this.
|
|
2334
|
+
#importPreset = preset => {
|
|
2335
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2416
2336
|
};
|
|
2417
2337
|
}
|
|
2418
2338
|
|
|
@@ -2881,7 +2801,7 @@
|
|
|
2881
2801
|
}
|
|
2882
2802
|
|
|
2883
2803
|
async function loadBlendPlugin(engine) {
|
|
2884
|
-
engine.checkVersion("4.0
|
|
2804
|
+
engine.checkVersion("4.1.0");
|
|
2885
2805
|
await engine.pluginManager.register(e => {
|
|
2886
2806
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2887
2807
|
});
|
|
@@ -2918,7 +2838,7 @@
|
|
|
2918
2838
|
}
|
|
2919
2839
|
|
|
2920
2840
|
async function loadCircleShape(engine) {
|
|
2921
|
-
engine.checkVersion("4.0
|
|
2841
|
+
engine.checkVersion("4.1.0");
|
|
2922
2842
|
await engine.pluginManager.register(e => {
|
|
2923
2843
|
e.pluginManager.addShape(["circle"], () => {
|
|
2924
2844
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2939,15 +2859,15 @@
|
|
|
2939
2859
|
return input.startsWith("#");
|
|
2940
2860
|
}
|
|
2941
2861
|
handleColor(color) {
|
|
2942
|
-
return this
|
|
2862
|
+
return this.#parseString(color.value);
|
|
2943
2863
|
}
|
|
2944
2864
|
handleRangeColor(color) {
|
|
2945
|
-
return this
|
|
2865
|
+
return this.#parseString(color.value);
|
|
2946
2866
|
}
|
|
2947
2867
|
parseString(input) {
|
|
2948
|
-
return this
|
|
2868
|
+
return this.#parseString(input);
|
|
2949
2869
|
}
|
|
2950
|
-
|
|
2870
|
+
#parseString(hexColor) {
|
|
2951
2871
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
2952
2872
|
return;
|
|
2953
2873
|
}
|
|
@@ -2966,7 +2886,7 @@
|
|
|
2966
2886
|
}
|
|
2967
2887
|
|
|
2968
2888
|
async function loadHexColorPlugin(engine) {
|
|
2969
|
-
engine.checkVersion("4.0
|
|
2889
|
+
engine.checkVersion("4.1.0");
|
|
2970
2890
|
await engine.pluginManager.register(e => {
|
|
2971
2891
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2972
2892
|
});
|
|
@@ -3019,7 +2939,7 @@
|
|
|
3019
2939
|
}
|
|
3020
2940
|
|
|
3021
2941
|
async function loadHslColorPlugin(engine) {
|
|
3022
|
-
engine.checkVersion("4.0
|
|
2942
|
+
engine.checkVersion("4.1.0");
|
|
3023
2943
|
await engine.pluginManager.register(e => {
|
|
3024
2944
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3025
2945
|
});
|
|
@@ -3027,13 +2947,13 @@
|
|
|
3027
2947
|
|
|
3028
2948
|
class MovePlugin {
|
|
3029
2949
|
id = "move";
|
|
3030
|
-
|
|
2950
|
+
#pluginManager;
|
|
3031
2951
|
constructor(pluginManager) {
|
|
3032
|
-
this
|
|
2952
|
+
this.#pluginManager = pluginManager;
|
|
3033
2953
|
}
|
|
3034
2954
|
async getPlugin(container) {
|
|
3035
2955
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3036
|
-
return new MovePluginInstance(this
|
|
2956
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3037
2957
|
}
|
|
3038
2958
|
loadOptions() {
|
|
3039
2959
|
}
|
|
@@ -3043,7 +2963,7 @@
|
|
|
3043
2963
|
}
|
|
3044
2964
|
|
|
3045
2965
|
async function loadMovePlugin(engine) {
|
|
3046
|
-
engine.checkVersion("4.0
|
|
2966
|
+
engine.checkVersion("4.1.0");
|
|
3047
2967
|
await engine.pluginManager.register(e => {
|
|
3048
2968
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3049
2969
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3061,18 +2981,58 @@
|
|
|
3061
2981
|
});
|
|
3062
2982
|
}
|
|
3063
2983
|
|
|
2984
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
2985
|
+
destroy;
|
|
2986
|
+
constructor() {
|
|
2987
|
+
super();
|
|
2988
|
+
this.destroy = DestroyType.none;
|
|
2989
|
+
this.speed = 2;
|
|
2990
|
+
}
|
|
2991
|
+
load(data) {
|
|
2992
|
+
super.load(data);
|
|
2993
|
+
if (isNull(data)) {
|
|
2994
|
+
return;
|
|
2995
|
+
}
|
|
2996
|
+
if (data.destroy !== undefined) {
|
|
2997
|
+
this.destroy = data.destroy;
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3003
|
+
animation;
|
|
3004
|
+
constructor() {
|
|
3005
|
+
super();
|
|
3006
|
+
this.animation = new OpacityAnimation();
|
|
3007
|
+
this.value = 1;
|
|
3008
|
+
}
|
|
3009
|
+
load(data) {
|
|
3010
|
+
if (isNull(data)) {
|
|
3011
|
+
return;
|
|
3012
|
+
}
|
|
3013
|
+
super.load(data);
|
|
3014
|
+
const animation = data.animation;
|
|
3015
|
+
if (animation !== undefined) {
|
|
3016
|
+
this.animation.load(animation);
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3064
3021
|
class OpacityUpdater {
|
|
3065
|
-
container;
|
|
3022
|
+
#container;
|
|
3066
3023
|
constructor(container) {
|
|
3067
|
-
this
|
|
3024
|
+
this.#container = container;
|
|
3068
3025
|
}
|
|
3069
3026
|
init(particle) {
|
|
3070
3027
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3028
|
+
if (!opacityOptions) {
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3071
3031
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3072
3032
|
const opacityAnimation = opacityOptions.animation;
|
|
3073
3033
|
if (opacityAnimation.enable) {
|
|
3074
3034
|
particle.opacity.velocity =
|
|
3075
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3035
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3076
3036
|
if (!opacityAnimation.sync) {
|
|
3077
3037
|
particle.opacity.velocity *= getRandom();
|
|
3078
3038
|
}
|
|
@@ -3088,6 +3048,12 @@
|
|
|
3088
3048
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3089
3049
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3090
3050
|
}
|
|
3051
|
+
loadOptions(options, ...sources) {
|
|
3052
|
+
options.opacity ??= new Opacity();
|
|
3053
|
+
for (const source of sources) {
|
|
3054
|
+
options.opacity.load(source?.opacity);
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3091
3057
|
reset(particle) {
|
|
3092
3058
|
if (!particle.opacity) {
|
|
3093
3059
|
return;
|
|
@@ -3096,7 +3062,7 @@
|
|
|
3096
3062
|
particle.opacity.loops = 0;
|
|
3097
3063
|
}
|
|
3098
3064
|
update(particle, delta) {
|
|
3099
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3065
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3100
3066
|
return;
|
|
3101
3067
|
}
|
|
3102
3068
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3104,7 +3070,7 @@
|
|
|
3104
3070
|
}
|
|
3105
3071
|
|
|
3106
3072
|
async function loadOpacityUpdater(engine) {
|
|
3107
|
-
engine.checkVersion("4.0
|
|
3073
|
+
engine.checkVersion("4.1.0");
|
|
3108
3074
|
await engine.pluginManager.register(e => {
|
|
3109
3075
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3110
3076
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3126,10 +3092,9 @@
|
|
|
3126
3092
|
}
|
|
3127
3093
|
const velocity = data.particle.velocity.x;
|
|
3128
3094
|
let bounced = false;
|
|
3129
|
-
if (
|
|
3130
|
-
data.
|
|
3131
|
-
|
|
3132
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3095
|
+
if (data.outOfCanvas &&
|
|
3096
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3097
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3133
3098
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3134
3099
|
data.particle.velocity.x *= -newVelocity;
|
|
3135
3100
|
bounced = true;
|
|
@@ -3138,10 +3103,10 @@
|
|
|
3138
3103
|
return;
|
|
3139
3104
|
}
|
|
3140
3105
|
const minPos = data.offset.x + data.size;
|
|
3141
|
-
if (data.
|
|
3106
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3142
3107
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3143
3108
|
}
|
|
3144
|
-
else if (data.
|
|
3109
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3145
3110
|
data.particle.position.x = minPos;
|
|
3146
3111
|
}
|
|
3147
3112
|
if (data.outMode === OutMode.split) {
|
|
@@ -3161,10 +3126,9 @@
|
|
|
3161
3126
|
}
|
|
3162
3127
|
const velocity = data.particle.velocity.y;
|
|
3163
3128
|
let bounced = false;
|
|
3164
|
-
if (
|
|
3165
|
-
data.
|
|
3166
|
-
|
|
3167
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3129
|
+
if (data.outOfCanvas &&
|
|
3130
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3131
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3168
3132
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3169
3133
|
data.particle.velocity.y *= -newVelocity;
|
|
3170
3134
|
bounced = true;
|
|
@@ -3173,10 +3137,10 @@
|
|
|
3173
3137
|
return;
|
|
3174
3138
|
}
|
|
3175
3139
|
const minPos = data.offset.y + data.size;
|
|
3176
|
-
if (data.
|
|
3140
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3177
3141
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3178
3142
|
}
|
|
3179
|
-
else if (data.
|
|
3143
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3180
3144
|
data.particle.position.y = minPos;
|
|
3181
3145
|
}
|
|
3182
3146
|
if (data.outMode === OutMode.split) {
|
|
@@ -3185,24 +3149,24 @@
|
|
|
3185
3149
|
}
|
|
3186
3150
|
|
|
3187
3151
|
class BounceOutMode {
|
|
3188
|
-
container;
|
|
3189
3152
|
modes;
|
|
3190
|
-
|
|
3153
|
+
#container;
|
|
3154
|
+
#particleBouncePlugins;
|
|
3191
3155
|
constructor(container) {
|
|
3192
|
-
this
|
|
3156
|
+
this.#container = container;
|
|
3193
3157
|
this.modes = [
|
|
3194
3158
|
OutMode.bounce,
|
|
3195
3159
|
OutMode.split,
|
|
3196
3160
|
];
|
|
3197
|
-
this
|
|
3161
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3198
3162
|
}
|
|
3199
3163
|
update(particle, direction, delta, outMode) {
|
|
3200
3164
|
if (!this.modes.includes(outMode)) {
|
|
3201
3165
|
return;
|
|
3202
3166
|
}
|
|
3203
|
-
const container = this
|
|
3167
|
+
const container = this.#container;
|
|
3204
3168
|
let handled = false;
|
|
3205
|
-
for (const plugin of this
|
|
3169
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3206
3170
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3207
3171
|
if (handled) {
|
|
3208
3172
|
break;
|
|
@@ -3211,29 +3175,26 @@
|
|
|
3211
3175
|
if (handled) {
|
|
3212
3176
|
return;
|
|
3213
3177
|
}
|
|
3214
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3215
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3216
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3178
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3179
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3180
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3217
3181
|
}
|
|
3218
3182
|
}
|
|
3219
3183
|
|
|
3220
3184
|
const minVelocity$3 = 0;
|
|
3221
3185
|
class DestroyOutMode {
|
|
3222
|
-
container;
|
|
3223
3186
|
modes;
|
|
3224
|
-
constructor(
|
|
3225
|
-
this.container = container;
|
|
3187
|
+
constructor(_container) {
|
|
3226
3188
|
this.modes = [OutMode.destroy];
|
|
3227
3189
|
}
|
|
3228
3190
|
update(particle, direction, _delta, outMode) {
|
|
3229
3191
|
if (!this.modes.includes(outMode)) {
|
|
3230
3192
|
return;
|
|
3231
3193
|
}
|
|
3232
|
-
const container = this.container;
|
|
3233
3194
|
switch (particle.outType) {
|
|
3234
3195
|
case ParticleOutType.normal:
|
|
3235
3196
|
case ParticleOutType.outside:
|
|
3236
|
-
if (
|
|
3197
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3237
3198
|
return;
|
|
3238
3199
|
}
|
|
3239
3200
|
break;
|
|
@@ -3254,10 +3215,10 @@
|
|
|
3254
3215
|
|
|
3255
3216
|
const minVelocity$2 = 0;
|
|
3256
3217
|
class NoneOutMode {
|
|
3257
|
-
container;
|
|
3258
3218
|
modes;
|
|
3219
|
+
#container;
|
|
3259
3220
|
constructor(container) {
|
|
3260
|
-
this
|
|
3221
|
+
this.#container = container;
|
|
3261
3222
|
this.modes = [OutMode.none];
|
|
3262
3223
|
}
|
|
3263
3224
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3270,7 +3231,7 @@
|
|
|
3270
3231
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3271
3232
|
return;
|
|
3272
3233
|
}
|
|
3273
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3234
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3274
3235
|
if (!gravityOptions.enable) {
|
|
3275
3236
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3276
3237
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3296,17 +3257,17 @@
|
|
|
3296
3257
|
|
|
3297
3258
|
const minVelocity$1 = 0, minDistance$1 = 0, updateVector = Vector.origin;
|
|
3298
3259
|
class OutOutMode {
|
|
3299
|
-
container;
|
|
3300
3260
|
modes;
|
|
3261
|
+
#container;
|
|
3301
3262
|
constructor(container) {
|
|
3302
|
-
this
|
|
3263
|
+
this.#container = container;
|
|
3303
3264
|
this.modes = [OutMode.out];
|
|
3304
3265
|
}
|
|
3305
3266
|
update(particle, direction, _delta, outMode) {
|
|
3306
3267
|
if (!this.modes.includes(outMode)) {
|
|
3307
3268
|
return;
|
|
3308
3269
|
}
|
|
3309
|
-
const container = this
|
|
3270
|
+
const container = this.#container;
|
|
3310
3271
|
switch (particle.outType) {
|
|
3311
3272
|
case ParticleOutType.inside: {
|
|
3312
3273
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3336,7 +3297,7 @@
|
|
|
3336
3297
|
break;
|
|
3337
3298
|
}
|
|
3338
3299
|
default: {
|
|
3339
|
-
if (
|
|
3300
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3340
3301
|
return;
|
|
3341
3302
|
}
|
|
3342
3303
|
switch (particle.outType) {
|
|
@@ -3420,16 +3381,16 @@
|
|
|
3420
3381
|
};
|
|
3421
3382
|
class OutOfCanvasUpdater {
|
|
3422
3383
|
updaters;
|
|
3423
|
-
container;
|
|
3384
|
+
#container;
|
|
3424
3385
|
constructor(container) {
|
|
3425
|
-
this
|
|
3386
|
+
this.#container = container;
|
|
3426
3387
|
this.updaters = new Map();
|
|
3427
3388
|
}
|
|
3428
3389
|
init(particle) {
|
|
3429
|
-
this
|
|
3430
|
-
this
|
|
3431
|
-
this
|
|
3432
|
-
this
|
|
3390
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3391
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3392
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3393
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3433
3394
|
}
|
|
3434
3395
|
isEnabled(particle) {
|
|
3435
3396
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3437,18 +3398,18 @@
|
|
|
3437
3398
|
update(particle, delta) {
|
|
3438
3399
|
const outModes = particle.options.move.outModes;
|
|
3439
3400
|
particle.justWarped = false;
|
|
3440
|
-
this
|
|
3441
|
-
this
|
|
3442
|
-
this
|
|
3443
|
-
this
|
|
3401
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3402
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3403
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3404
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3444
3405
|
}
|
|
3445
|
-
|
|
3406
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3446
3407
|
const outModes = particle.options.move.outModes;
|
|
3447
3408
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3448
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3409
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3449
3410
|
}
|
|
3450
3411
|
};
|
|
3451
|
-
|
|
3412
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3452
3413
|
for (const updater of this.updaters.values()) {
|
|
3453
3414
|
updater.update(particle, direction, delta, outMode);
|
|
3454
3415
|
}
|
|
@@ -3456,7 +3417,7 @@
|
|
|
3456
3417
|
}
|
|
3457
3418
|
|
|
3458
3419
|
async function loadOutModesUpdater(engine) {
|
|
3459
|
-
engine.checkVersion("4.0
|
|
3420
|
+
engine.checkVersion("4.1.0");
|
|
3460
3421
|
await engine.pluginManager.register(e => {
|
|
3461
3422
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3462
3423
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3466,20 +3427,20 @@
|
|
|
3466
3427
|
|
|
3467
3428
|
const defaultOpacity = 1;
|
|
3468
3429
|
class PaintUpdater {
|
|
3469
|
-
|
|
3470
|
-
|
|
3430
|
+
#container;
|
|
3431
|
+
#pluginManager;
|
|
3471
3432
|
constructor(pluginManager, container) {
|
|
3472
|
-
this
|
|
3473
|
-
this
|
|
3433
|
+
this.#container = container;
|
|
3434
|
+
this.#pluginManager = pluginManager;
|
|
3474
3435
|
}
|
|
3475
3436
|
init(particle) {
|
|
3476
|
-
const container = this
|
|
3437
|
+
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;
|
|
3477
3438
|
if (fill) {
|
|
3478
3439
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3479
3440
|
particle.fillEnabled = fill.enable;
|
|
3480
3441
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3481
3442
|
particle.fillAnimation = fillColor.animation;
|
|
3482
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3443
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3483
3444
|
if (fillHslColor) {
|
|
3484
3445
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3485
3446
|
}
|
|
@@ -3495,7 +3456,7 @@
|
|
|
3495
3456
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3496
3457
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3497
3458
|
particle.strokeAnimation = strokeColor.animation;
|
|
3498
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3459
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3499
3460
|
if (strokeHslColor) {
|
|
3500
3461
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3501
3462
|
}
|
|
@@ -3527,7 +3488,7 @@
|
|
|
3527
3488
|
}
|
|
3528
3489
|
|
|
3529
3490
|
async function loadPaintUpdater(engine) {
|
|
3530
|
-
engine.checkVersion("4.0
|
|
3491
|
+
engine.checkVersion("4.1.0");
|
|
3531
3492
|
await engine.pluginManager.register(e => {
|
|
3532
3493
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3533
3494
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3582,27 +3543,69 @@
|
|
|
3582
3543
|
}
|
|
3583
3544
|
|
|
3584
3545
|
async function loadRgbColorPlugin(engine) {
|
|
3585
|
-
engine.checkVersion("4.0
|
|
3546
|
+
engine.checkVersion("4.1.0");
|
|
3586
3547
|
await engine.pluginManager.register(e => {
|
|
3587
3548
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3588
3549
|
});
|
|
3589
3550
|
}
|
|
3590
3551
|
|
|
3552
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3553
|
+
destroy;
|
|
3554
|
+
constructor() {
|
|
3555
|
+
super();
|
|
3556
|
+
this.destroy = DestroyType.none;
|
|
3557
|
+
this.speed = 5;
|
|
3558
|
+
}
|
|
3559
|
+
load(data) {
|
|
3560
|
+
super.load(data);
|
|
3561
|
+
if (isNull(data)) {
|
|
3562
|
+
return;
|
|
3563
|
+
}
|
|
3564
|
+
if (data.destroy !== undefined) {
|
|
3565
|
+
this.destroy = data.destroy;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3570
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3571
|
+
animation;
|
|
3572
|
+
constructor() {
|
|
3573
|
+
super();
|
|
3574
|
+
this.animation = new SizeAnimation();
|
|
3575
|
+
this.value = 3;
|
|
3576
|
+
}
|
|
3577
|
+
load(data) {
|
|
3578
|
+
super.load(data);
|
|
3579
|
+
if (isNull(data)) {
|
|
3580
|
+
return;
|
|
3581
|
+
}
|
|
3582
|
+
const animation = data.animation;
|
|
3583
|
+
if (animation !== undefined) {
|
|
3584
|
+
this.animation.load(animation);
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3591
3589
|
const minLoops = 0;
|
|
3592
3590
|
class SizeUpdater {
|
|
3593
|
-
|
|
3591
|
+
#container;
|
|
3594
3592
|
constructor(container) {
|
|
3595
|
-
this
|
|
3593
|
+
this.#container = container;
|
|
3596
3594
|
}
|
|
3597
3595
|
init(particle) {
|
|
3598
|
-
const container = this
|
|
3599
|
-
if (
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3596
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3597
|
+
if (!sizeOptions) {
|
|
3598
|
+
return;
|
|
3599
|
+
}
|
|
3600
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3601
|
+
if (!sizeAnimation.enable) {
|
|
3602
|
+
return;
|
|
3603
|
+
}
|
|
3604
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3605
|
+
if (sizeAnimation.sync) {
|
|
3606
|
+
return;
|
|
3605
3607
|
}
|
|
3608
|
+
particle.size.velocity *= getRandom();
|
|
3606
3609
|
}
|
|
3607
3610
|
isEnabled(particle) {
|
|
3608
3611
|
return (!particle.destroyed &&
|
|
@@ -3612,12 +3615,26 @@
|
|
|
3612
3615
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3613
3616
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3614
3617
|
}
|
|
3618
|
+
loadOptions(options, ...sources) {
|
|
3619
|
+
options.size ??= new Size();
|
|
3620
|
+
for (const source of sources) {
|
|
3621
|
+
options.size.load(source?.size);
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
preInit(particle) {
|
|
3625
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3626
|
+
if (!sizeOptions) {
|
|
3627
|
+
return;
|
|
3628
|
+
}
|
|
3629
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3630
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3631
|
+
}
|
|
3615
3632
|
reset(particle) {
|
|
3616
3633
|
particle.size.time = 0;
|
|
3617
3634
|
particle.size.loops = 0;
|
|
3618
3635
|
}
|
|
3619
3636
|
update(particle, delta) {
|
|
3620
|
-
if (!this.isEnabled(particle)) {
|
|
3637
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3621
3638
|
return;
|
|
3622
3639
|
}
|
|
3623
3640
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3625,7 +3642,7 @@
|
|
|
3625
3642
|
}
|
|
3626
3643
|
|
|
3627
3644
|
async function loadSizeUpdater(engine) {
|
|
3628
|
-
engine.checkVersion("4.0
|
|
3645
|
+
engine.checkVersion("4.1.0");
|
|
3629
3646
|
await engine.pluginManager.register(e => {
|
|
3630
3647
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3631
3648
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3634,7 +3651,7 @@
|
|
|
3634
3651
|
}
|
|
3635
3652
|
|
|
3636
3653
|
async function loadBasic(engine) {
|
|
3637
|
-
engine.checkVersion("4.0
|
|
3654
|
+
engine.checkVersion("4.1.0");
|
|
3638
3655
|
await engine.pluginManager.register(async (e) => {
|
|
3639
3656
|
await Promise.all([
|
|
3640
3657
|
loadBlendPlugin(e),
|
|
@@ -3791,20 +3808,20 @@
|
|
|
3791
3808
|
})(InteractivityDetect || (InteractivityDetect = {}));
|
|
3792
3809
|
|
|
3793
3810
|
class Modes {
|
|
3794
|
-
|
|
3795
|
-
|
|
3811
|
+
#container;
|
|
3812
|
+
#pluginManager;
|
|
3796
3813
|
constructor(pluginManager, container) {
|
|
3797
|
-
this
|
|
3798
|
-
this
|
|
3814
|
+
this.#pluginManager = pluginManager;
|
|
3815
|
+
this.#container = container;
|
|
3799
3816
|
}
|
|
3800
3817
|
load(data) {
|
|
3801
3818
|
if (isNull(data)) {
|
|
3802
3819
|
return;
|
|
3803
3820
|
}
|
|
3804
|
-
if (!this
|
|
3821
|
+
if (!this.#container) {
|
|
3805
3822
|
return;
|
|
3806
3823
|
}
|
|
3807
|
-
const interactors = this.
|
|
3824
|
+
const interactors = this.#pluginManager.interactors?.get(this.#container);
|
|
3808
3825
|
if (!interactors) {
|
|
3809
3826
|
return;
|
|
3810
3827
|
}
|
|
@@ -3841,13 +3858,13 @@
|
|
|
3841
3858
|
|
|
3842
3859
|
class InteractivityPlugin {
|
|
3843
3860
|
id = "interactivity";
|
|
3844
|
-
|
|
3861
|
+
#pluginManager;
|
|
3845
3862
|
constructor(pluginManager) {
|
|
3846
|
-
this
|
|
3863
|
+
this.#pluginManager = pluginManager;
|
|
3847
3864
|
}
|
|
3848
3865
|
async getPlugin(container) {
|
|
3849
3866
|
const { InteractivityPluginInstance } = await Promise.resolve().then(function () { return InteractivityPluginInstance$1; });
|
|
3850
|
-
return new InteractivityPluginInstance(this
|
|
3867
|
+
return new InteractivityPluginInstance(this.#pluginManager, container);
|
|
3851
3868
|
}
|
|
3852
3869
|
loadOptions(container, options, source) {
|
|
3853
3870
|
if (!this.needsPlugin()) {
|
|
@@ -3855,10 +3872,10 @@
|
|
|
3855
3872
|
}
|
|
3856
3873
|
let interactivityOptions = options.interactivity;
|
|
3857
3874
|
if (!interactivityOptions?.load) {
|
|
3858
|
-
options.interactivity = interactivityOptions = new Interactivity(this
|
|
3875
|
+
options.interactivity = interactivityOptions = new Interactivity(this.#pluginManager, container);
|
|
3859
3876
|
}
|
|
3860
3877
|
interactivityOptions.load(source?.interactivity);
|
|
3861
|
-
const interactors = this.
|
|
3878
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
3862
3879
|
if (!interactors) {
|
|
3863
3880
|
return;
|
|
3864
3881
|
}
|
|
@@ -3872,7 +3889,7 @@
|
|
|
3872
3889
|
if (source?.interactivity) {
|
|
3873
3890
|
options.interactivity = deepExtend({}, source.interactivity);
|
|
3874
3891
|
}
|
|
3875
|
-
const interactors = this.
|
|
3892
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
3876
3893
|
if (!interactors) {
|
|
3877
3894
|
return;
|
|
3878
3895
|
}
|
|
@@ -3902,7 +3919,7 @@
|
|
|
3902
3919
|
const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
|
|
3903
3920
|
|
|
3904
3921
|
async function loadInteractivityPlugin(engine) {
|
|
3905
|
-
engine.checkVersion("4.0
|
|
3922
|
+
engine.checkVersion("4.1.0");
|
|
3906
3923
|
await engine.pluginManager.register(e => {
|
|
3907
3924
|
const interactivityEngine = e, interactivityPluginManager = interactivityEngine.pluginManager;
|
|
3908
3925
|
interactivityPluginManager.addPlugin(new InteractivityPlugin(interactivityPluginManager));
|
|
@@ -3948,7 +3965,7 @@
|
|
|
3948
3965
|
this.spread = 30;
|
|
3949
3966
|
this.velocityFactor = 0.5;
|
|
3950
3967
|
this.particleFactor = 0.2;
|
|
3951
|
-
this.maxDragDistance =
|
|
3968
|
+
this.maxDragDistance = 0;
|
|
3952
3969
|
this.minParticles = 5;
|
|
3953
3970
|
this.maxParticles = 200;
|
|
3954
3971
|
this.drawVector = true;
|
|
@@ -3973,6 +3990,9 @@
|
|
|
3973
3990
|
if (data.maxParticles !== undefined) {
|
|
3974
3991
|
this.maxParticles = data.maxParticles;
|
|
3975
3992
|
}
|
|
3993
|
+
if (data.maxDragDistance !== undefined) {
|
|
3994
|
+
this.maxDragDistance = data.maxDragDistance;
|
|
3995
|
+
}
|
|
3976
3996
|
if (data.drawVector !== undefined) {
|
|
3977
3997
|
this.drawVector = data.drawVector;
|
|
3978
3998
|
}
|
|
@@ -3994,14 +4014,14 @@
|
|
|
3994
4014
|
}
|
|
3995
4015
|
class Cannoner extends ExternalInteractorBase {
|
|
3996
4016
|
maxDistance = 0;
|
|
3997
|
-
|
|
3998
|
-
|
|
4017
|
+
#data;
|
|
4018
|
+
#gesture = {
|
|
3999
4019
|
origin: Vector.origin,
|
|
4000
4020
|
current: Vector.origin,
|
|
4001
4021
|
active: false,
|
|
4002
4022
|
};
|
|
4003
|
-
|
|
4004
|
-
|
|
4023
|
+
#lastDownPosition = undefined;
|
|
4024
|
+
#state = CannonState.idle;
|
|
4005
4025
|
constructor(container) {
|
|
4006
4026
|
super(container);
|
|
4007
4027
|
}
|
|
@@ -4009,7 +4029,7 @@
|
|
|
4009
4029
|
}
|
|
4010
4030
|
init() {
|
|
4011
4031
|
const options = this.container.actualOptions.interactivity?.modes.cannon ?? new Cannon();
|
|
4012
|
-
this
|
|
4032
|
+
this.#data = {
|
|
4013
4033
|
spread: degToRad(options.spread),
|
|
4014
4034
|
maxDragDistance: options.maxDragDistance,
|
|
4015
4035
|
velocityFactor: options.velocityFactor,
|
|
@@ -4022,27 +4042,27 @@
|
|
|
4022
4042
|
}
|
|
4023
4043
|
interact(interactivityData, _delta) {
|
|
4024
4044
|
const mouse = interactivityData.mouse, mousePos = mouse.position, clicking = mouse.clicking, downPos = mouse.downPosition;
|
|
4025
|
-
if (clicking && downPos && downPos !== this
|
|
4026
|
-
this
|
|
4027
|
-
this
|
|
4045
|
+
if (clicking && downPos && downPos !== this.#lastDownPosition && this.#state === CannonState.idle) {
|
|
4046
|
+
this.#lastDownPosition = downPos;
|
|
4047
|
+
this.#gesture = {
|
|
4028
4048
|
origin: { x: downPos.x, y: downPos.y },
|
|
4029
4049
|
current: { x: downPos.x, y: downPos.y },
|
|
4030
4050
|
active: true,
|
|
4031
4051
|
};
|
|
4032
|
-
this
|
|
4052
|
+
this.#state = CannonState.aiming;
|
|
4033
4053
|
}
|
|
4034
|
-
if (this
|
|
4035
|
-
this.
|
|
4036
|
-
this
|
|
4054
|
+
if (this.#state === CannonState.aiming && mousePos) {
|
|
4055
|
+
this.#gesture.current = { x: mousePos.x, y: mousePos.y };
|
|
4056
|
+
this.#drawVector();
|
|
4037
4057
|
}
|
|
4038
|
-
if (!clicking && this
|
|
4039
|
-
this.
|
|
4040
|
-
this
|
|
4041
|
-
this
|
|
4058
|
+
if (!clicking && this.#state === CannonState.aiming) {
|
|
4059
|
+
this.#gesture.active = false;
|
|
4060
|
+
this.#fire();
|
|
4061
|
+
this.#state = CannonState.idle;
|
|
4042
4062
|
}
|
|
4043
4063
|
}
|
|
4044
4064
|
isEnabled(interactivityData) {
|
|
4045
|
-
const
|
|
4065
|
+
const container = this.container, events = container.actualOptions.interactivity?.events;
|
|
4046
4066
|
if (!events?.onClick.enable) {
|
|
4047
4067
|
return false;
|
|
4048
4068
|
}
|
|
@@ -4050,7 +4070,7 @@
|
|
|
4050
4070
|
if (!modeEnabled) {
|
|
4051
4071
|
return false;
|
|
4052
4072
|
}
|
|
4053
|
-
return this
|
|
4073
|
+
return this.#state !== CannonState.idle || interactivityData.mouse.clicking;
|
|
4054
4074
|
}
|
|
4055
4075
|
loadModeOptions(options, ...sources) {
|
|
4056
4076
|
options.cannon ??= new Cannon();
|
|
@@ -4060,13 +4080,13 @@
|
|
|
4060
4080
|
}
|
|
4061
4081
|
reset(_interactivityData, _particle) {
|
|
4062
4082
|
}
|
|
4063
|
-
|
|
4083
|
+
#drawVector() {
|
|
4064
4084
|
this.container.canvas.render.draw(ctx => {
|
|
4065
|
-
const opts = this
|
|
4085
|
+
const opts = this.#data;
|
|
4066
4086
|
if (!opts) {
|
|
4067
4087
|
return;
|
|
4068
4088
|
}
|
|
4069
|
-
const { origin, current } = this
|
|
4089
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dragDist = getDistance(origin, current), clampedDist = opts.maxDragDistance > none ? Math.min(dragDist, opts.maxDragDistance * pxRatio) : dragDist, clampRatio = dragDist > minDistance ? clampedDist / dragDist : minDistance, clampedX = origin.x + (current.x - origin.x) * clampRatio, clampedY = origin.y + (current.y - origin.y) * clampRatio;
|
|
4070
4090
|
ctx.save();
|
|
4071
4091
|
ctx.strokeStyle = opts.vectorColor;
|
|
4072
4092
|
ctx.lineWidth = double * pxRatio;
|
|
@@ -4083,12 +4103,12 @@
|
|
|
4083
4103
|
ctx.restore();
|
|
4084
4104
|
});
|
|
4085
4105
|
}
|
|
4086
|
-
|
|
4087
|
-
const opts = this
|
|
4106
|
+
#fire() {
|
|
4107
|
+
const opts = this.#data;
|
|
4088
4108
|
if (!opts) {
|
|
4089
4109
|
return;
|
|
4090
4110
|
}
|
|
4091
|
-
const { origin, current } = this
|
|
4111
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dist = getDistance(origin, current), dragLength = opts.maxDragDistance > none ? Math.min(dist, opts.maxDragDistance * pxRatio) : dist;
|
|
4092
4112
|
if (dragLength < minTapsLength) {
|
|
4093
4113
|
return;
|
|
4094
4114
|
}
|
|
@@ -4107,7 +4127,7 @@
|
|
|
4107
4127
|
}
|
|
4108
4128
|
|
|
4109
4129
|
async function loadExternalCannonInteraction(engine) {
|
|
4110
|
-
engine.checkVersion("4.0
|
|
4130
|
+
engine.checkVersion("4.1.0");
|
|
4111
4131
|
await engine.pluginManager.register((e) => {
|
|
4112
4132
|
ensureInteractivityPluginLoaded(e);
|
|
4113
4133
|
e.pluginManager.addInteractor?.("externalCannon", container => {
|
|
@@ -4226,12 +4246,12 @@
|
|
|
4226
4246
|
|
|
4227
4247
|
const noTime = 0, identity$2 = 1, infiniteValue = -1;
|
|
4228
4248
|
class LifeUpdater {
|
|
4229
|
-
container;
|
|
4249
|
+
#container;
|
|
4230
4250
|
constructor(container) {
|
|
4231
|
-
this
|
|
4251
|
+
this.#container = container;
|
|
4232
4252
|
}
|
|
4233
4253
|
init(particle) {
|
|
4234
|
-
const container = this
|
|
4254
|
+
const container = this.#container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
4235
4255
|
if (!lifeOptions) {
|
|
4236
4256
|
return;
|
|
4237
4257
|
}
|
|
@@ -4270,12 +4290,12 @@
|
|
|
4270
4290
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
4271
4291
|
return;
|
|
4272
4292
|
}
|
|
4273
|
-
updateLife(particle, delta, this
|
|
4293
|
+
updateLife(particle, delta, this.#container.canvas.size);
|
|
4274
4294
|
}
|
|
4275
4295
|
}
|
|
4276
4296
|
|
|
4277
4297
|
async function loadLifeUpdater(engine) {
|
|
4278
|
-
engine.checkVersion("4.0
|
|
4298
|
+
engine.checkVersion("4.1.0");
|
|
4279
4299
|
await engine.pluginManager.register(e => {
|
|
4280
4300
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
4281
4301
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -4343,7 +4363,7 @@
|
|
|
4343
4363
|
}
|
|
4344
4364
|
|
|
4345
4365
|
async function loadMotionPlugin(engine) {
|
|
4346
|
-
engine.checkVersion("4.0
|
|
4366
|
+
engine.checkVersion("4.1.0");
|
|
4347
4367
|
await engine.pluginManager.register(e => {
|
|
4348
4368
|
e.pluginManager.addPlugin(new MotionPlugin());
|
|
4349
4369
|
});
|
|
@@ -4467,9 +4487,9 @@
|
|
|
4467
4487
|
}
|
|
4468
4488
|
|
|
4469
4489
|
class RollUpdater {
|
|
4470
|
-
|
|
4490
|
+
#pluginManager;
|
|
4471
4491
|
constructor(pluginManager) {
|
|
4472
|
-
this
|
|
4492
|
+
this.#pluginManager = pluginManager;
|
|
4473
4493
|
}
|
|
4474
4494
|
getTransformValues(particle) {
|
|
4475
4495
|
const roll = particle.roll?.enable && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
@@ -4479,7 +4499,7 @@
|
|
|
4479
4499
|
};
|
|
4480
4500
|
}
|
|
4481
4501
|
init(particle) {
|
|
4482
|
-
initParticle(this
|
|
4502
|
+
initParticle(this.#pluginManager, particle);
|
|
4483
4503
|
}
|
|
4484
4504
|
isEnabled(particle) {
|
|
4485
4505
|
const roll = particle.options.roll;
|
|
@@ -4500,7 +4520,7 @@
|
|
|
4500
4520
|
}
|
|
4501
4521
|
|
|
4502
4522
|
async function loadRollUpdater(engine) {
|
|
4503
|
-
engine.checkVersion("4.0
|
|
4523
|
+
engine.checkVersion("4.1.0");
|
|
4504
4524
|
await engine.pluginManager.register(e => {
|
|
4505
4525
|
e.pluginManager.addParticleUpdater("roll", () => {
|
|
4506
4526
|
return Promise.resolve(new RollUpdater(e.pluginManager));
|
|
@@ -4566,9 +4586,9 @@
|
|
|
4566
4586
|
|
|
4567
4587
|
const doublePIDeg = 360;
|
|
4568
4588
|
class RotateUpdater {
|
|
4569
|
-
container;
|
|
4589
|
+
#container;
|
|
4570
4590
|
constructor(container) {
|
|
4571
|
-
this
|
|
4591
|
+
this.#container = container;
|
|
4572
4592
|
}
|
|
4573
4593
|
init(particle) {
|
|
4574
4594
|
const rotateOptions = particle.options.rotate;
|
|
@@ -4600,7 +4620,7 @@
|
|
|
4600
4620
|
if (rotateAnimation.enable) {
|
|
4601
4621
|
particle.rotate.decay = identity$3 - getRangeValue(rotateAnimation.decay);
|
|
4602
4622
|
particle.rotate.velocity =
|
|
4603
|
-
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this
|
|
4623
|
+
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
|
|
4604
4624
|
if (!rotateAnimation.sync) {
|
|
4605
4625
|
particle.rotate.velocity *= getRandom();
|
|
4606
4626
|
}
|
|
@@ -4634,7 +4654,7 @@
|
|
|
4634
4654
|
}
|
|
4635
4655
|
|
|
4636
4656
|
async function loadRotateUpdater(engine) {
|
|
4637
|
-
engine.checkVersion("4.0
|
|
4657
|
+
engine.checkVersion("4.1.0");
|
|
4638
4658
|
await engine.pluginManager.register(e => {
|
|
4639
4659
|
e.pluginManager.addParticleUpdater("rotate", container => {
|
|
4640
4660
|
return Promise.resolve(new RotateUpdater(container));
|
|
@@ -4658,7 +4678,7 @@
|
|
|
4658
4678
|
}
|
|
4659
4679
|
|
|
4660
4680
|
async function loadSquareShape(engine) {
|
|
4661
|
-
engine.checkVersion("4.0
|
|
4681
|
+
engine.checkVersion("4.1.0");
|
|
4662
4682
|
await engine.pluginManager.register(e => {
|
|
4663
4683
|
e.pluginManager.addShape(["edge", "square"], () => Promise.resolve(new SquareDrawer()));
|
|
4664
4684
|
});
|
|
@@ -4729,9 +4749,9 @@
|
|
|
4729
4749
|
|
|
4730
4750
|
const maxAngle$1 = 360;
|
|
4731
4751
|
class TiltUpdater {
|
|
4732
|
-
container;
|
|
4752
|
+
#container;
|
|
4733
4753
|
constructor(container) {
|
|
4734
|
-
this
|
|
4754
|
+
this.#container = container;
|
|
4735
4755
|
}
|
|
4736
4756
|
getTransformValues(particle) {
|
|
4737
4757
|
const tilt = particle.tilt?.enable && particle.tilt;
|
|
@@ -4770,7 +4790,7 @@
|
|
|
4770
4790
|
const tiltAnimation = particle.options.tilt?.animation;
|
|
4771
4791
|
if (tiltAnimation?.enable) {
|
|
4772
4792
|
particle.tilt.decay = identity$3 - getRangeValue(tiltAnimation.decay);
|
|
4773
|
-
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this
|
|
4793
|
+
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this.#container.retina.reduceFactor;
|
|
4774
4794
|
if (!tiltAnimation.sync) {
|
|
4775
4795
|
particle.tilt.velocity *= getRandom();
|
|
4776
4796
|
}
|
|
@@ -4795,7 +4815,7 @@
|
|
|
4795
4815
|
}
|
|
4796
4816
|
|
|
4797
4817
|
async function loadTiltUpdater(engine) {
|
|
4798
|
-
engine.checkVersion("4.0
|
|
4818
|
+
engine.checkVersion("4.1.0");
|
|
4799
4819
|
await engine.pluginManager.register(e => {
|
|
4800
4820
|
e.pluginManager.addParticleUpdater("tilt", container => {
|
|
4801
4821
|
return Promise.resolve(new TiltUpdater(container));
|
|
@@ -4876,9 +4896,9 @@
|
|
|
4876
4896
|
|
|
4877
4897
|
const maxAngle = 360, moveSpeedFactor$1 = 10, defaultDistance = 0;
|
|
4878
4898
|
class WobbleUpdater {
|
|
4879
|
-
|
|
4899
|
+
#container;
|
|
4880
4900
|
constructor(container) {
|
|
4881
|
-
this
|
|
4901
|
+
this.#container = container;
|
|
4882
4902
|
}
|
|
4883
4903
|
init(particle) {
|
|
4884
4904
|
const wobbleOpt = particle.options.wobble;
|
|
@@ -4897,7 +4917,7 @@
|
|
|
4897
4917
|
};
|
|
4898
4918
|
}
|
|
4899
4919
|
particle.retina.wobbleDistance =
|
|
4900
|
-
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.
|
|
4920
|
+
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.#container.retina.pixelRatio;
|
|
4901
4921
|
}
|
|
4902
4922
|
isEnabled(particle) {
|
|
4903
4923
|
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
|
|
@@ -4912,12 +4932,12 @@
|
|
|
4912
4932
|
if (!this.isEnabled(particle)) {
|
|
4913
4933
|
return;
|
|
4914
4934
|
}
|
|
4915
|
-
updateWobble(this
|
|
4935
|
+
updateWobble(this.#container, particle, delta);
|
|
4916
4936
|
}
|
|
4917
4937
|
}
|
|
4918
4938
|
|
|
4919
4939
|
async function loadWobbleUpdater(engine) {
|
|
4920
|
-
engine.checkVersion("4.0
|
|
4940
|
+
engine.checkVersion("4.1.0");
|
|
4921
4941
|
await engine.pluginManager.register(e => {
|
|
4922
4942
|
e.pluginManager.addParticleUpdater("wobble", container => {
|
|
4923
4943
|
return Promise.resolve(new WobbleUpdater(container));
|
|
@@ -5072,58 +5092,58 @@
|
|
|
5072
5092
|
}
|
|
5073
5093
|
}
|
|
5074
5094
|
class RenderManager {
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
+
#canvasClearPlugins;
|
|
5096
|
+
#canvasManager;
|
|
5097
|
+
#canvasPaintPlugins;
|
|
5098
|
+
#clearDrawPlugins;
|
|
5099
|
+
#colorPlugins;
|
|
5100
|
+
#container;
|
|
5101
|
+
#context;
|
|
5102
|
+
#contextSettings;
|
|
5103
|
+
#drawParticlePlugins;
|
|
5104
|
+
#drawParticlesCleanupPlugins;
|
|
5105
|
+
#drawParticlesSetupPlugins;
|
|
5106
|
+
#drawPlugins;
|
|
5107
|
+
#drawSettingsCleanupPlugins;
|
|
5108
|
+
#drawSettingsSetupPlugins;
|
|
5109
|
+
#pluginManager;
|
|
5110
|
+
#postDrawUpdaters;
|
|
5111
|
+
#preDrawUpdaters;
|
|
5112
|
+
#reusableColorStyles = {};
|
|
5113
|
+
#reusablePluginColors = [undefined, undefined];
|
|
5114
|
+
#reusableTransform = {};
|
|
5095
5115
|
constructor(pluginManager, container, canvasManager) {
|
|
5096
|
-
this
|
|
5097
|
-
this
|
|
5098
|
-
this
|
|
5099
|
-
this
|
|
5100
|
-
this
|
|
5101
|
-
this
|
|
5102
|
-
this
|
|
5103
|
-
this
|
|
5104
|
-
this
|
|
5105
|
-
this
|
|
5106
|
-
this
|
|
5107
|
-
this
|
|
5108
|
-
this
|
|
5109
|
-
this
|
|
5110
|
-
this
|
|
5111
|
-
this
|
|
5116
|
+
this.#pluginManager = pluginManager;
|
|
5117
|
+
this.#container = container;
|
|
5118
|
+
this.#canvasManager = canvasManager;
|
|
5119
|
+
this.#context = null;
|
|
5120
|
+
this.#preDrawUpdaters = [];
|
|
5121
|
+
this.#postDrawUpdaters = [];
|
|
5122
|
+
this.#colorPlugins = [];
|
|
5123
|
+
this.#canvasClearPlugins = [];
|
|
5124
|
+
this.#canvasPaintPlugins = [];
|
|
5125
|
+
this.#clearDrawPlugins = [];
|
|
5126
|
+
this.#drawParticlePlugins = [];
|
|
5127
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5128
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5129
|
+
this.#drawPlugins = [];
|
|
5130
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5131
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5112
5132
|
}
|
|
5113
5133
|
get settings() {
|
|
5114
|
-
return this
|
|
5134
|
+
return this.#contextSettings;
|
|
5115
5135
|
}
|
|
5116
5136
|
canvasClear() {
|
|
5117
|
-
if (!this.
|
|
5137
|
+
if (!this.#container.actualOptions.clear) {
|
|
5118
5138
|
return;
|
|
5119
5139
|
}
|
|
5120
5140
|
this.draw(ctx => {
|
|
5121
|
-
clear(ctx, this.
|
|
5141
|
+
clear(ctx, this.#canvasManager.size);
|
|
5122
5142
|
});
|
|
5123
5143
|
}
|
|
5124
5144
|
clear() {
|
|
5125
5145
|
let pluginHandled = false;
|
|
5126
|
-
for (const plugin of this
|
|
5146
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
5127
5147
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
5128
5148
|
if (pluginHandled) {
|
|
5129
5149
|
break;
|
|
@@ -5136,21 +5156,21 @@
|
|
|
5136
5156
|
}
|
|
5137
5157
|
destroy() {
|
|
5138
5158
|
this.stop();
|
|
5139
|
-
this
|
|
5140
|
-
this
|
|
5141
|
-
this
|
|
5142
|
-
this
|
|
5143
|
-
this
|
|
5144
|
-
this
|
|
5145
|
-
this
|
|
5146
|
-
this
|
|
5147
|
-
this
|
|
5148
|
-
this
|
|
5149
|
-
this
|
|
5150
|
-
this
|
|
5159
|
+
this.#preDrawUpdaters = [];
|
|
5160
|
+
this.#postDrawUpdaters = [];
|
|
5161
|
+
this.#colorPlugins = [];
|
|
5162
|
+
this.#canvasClearPlugins = [];
|
|
5163
|
+
this.#canvasPaintPlugins = [];
|
|
5164
|
+
this.#clearDrawPlugins = [];
|
|
5165
|
+
this.#drawParticlePlugins = [];
|
|
5166
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5167
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5168
|
+
this.#drawPlugins = [];
|
|
5169
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5170
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5151
5171
|
}
|
|
5152
5172
|
draw(cb) {
|
|
5153
|
-
const ctx = this
|
|
5173
|
+
const ctx = this.#context;
|
|
5154
5174
|
if (!ctx) {
|
|
5155
5175
|
return;
|
|
5156
5176
|
}
|
|
@@ -5165,21 +5185,21 @@
|
|
|
5165
5185
|
return;
|
|
5166
5186
|
}
|
|
5167
5187
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
5168
|
-
let [fColor, sColor] = this
|
|
5188
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
5169
5189
|
fColor ??= pfColor;
|
|
5170
5190
|
sColor ??= psColor;
|
|
5171
5191
|
if (!fColor && !sColor) {
|
|
5172
5192
|
return;
|
|
5173
5193
|
}
|
|
5174
|
-
const container = this
|
|
5194
|
+
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;
|
|
5175
5195
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
5176
5196
|
colorStyles.fill = fill;
|
|
5177
5197
|
colorStyles.stroke = stroke;
|
|
5178
5198
|
this.draw((context) => {
|
|
5179
|
-
for (const plugin of this
|
|
5199
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
5180
5200
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
5181
5201
|
}
|
|
5182
|
-
this
|
|
5202
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
5183
5203
|
drawParticle({
|
|
5184
5204
|
container,
|
|
5185
5205
|
context,
|
|
@@ -5190,35 +5210,35 @@
|
|
|
5190
5210
|
opacity: opacity,
|
|
5191
5211
|
transform,
|
|
5192
5212
|
});
|
|
5193
|
-
this
|
|
5194
|
-
for (const plugin of this
|
|
5213
|
+
this.#applyPostDrawUpdaters(particle);
|
|
5214
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
5195
5215
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
5196
5216
|
}
|
|
5197
5217
|
});
|
|
5198
5218
|
}
|
|
5199
5219
|
drawParticlePlugins(particle, delta) {
|
|
5200
5220
|
this.draw(ctx => {
|
|
5201
|
-
for (const plugin of this
|
|
5221
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
5202
5222
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
5203
5223
|
}
|
|
5204
5224
|
});
|
|
5205
5225
|
}
|
|
5206
5226
|
drawParticles(delta) {
|
|
5207
|
-
const { particles } = this
|
|
5227
|
+
const { particles } = this.#container;
|
|
5208
5228
|
this.clear();
|
|
5209
5229
|
particles.update(delta);
|
|
5210
5230
|
this.draw(ctx => {
|
|
5211
|
-
for (const plugin of this
|
|
5231
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
5212
5232
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
5213
5233
|
}
|
|
5214
|
-
for (const plugin of this
|
|
5234
|
+
for (const plugin of this.#drawPlugins) {
|
|
5215
5235
|
plugin.draw?.(ctx, delta);
|
|
5216
5236
|
}
|
|
5217
5237
|
particles.drawParticles(delta);
|
|
5218
|
-
for (const plugin of this
|
|
5238
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
5219
5239
|
plugin.clearDraw?.(ctx, delta);
|
|
5220
5240
|
}
|
|
5221
|
-
for (const plugin of this
|
|
5241
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
5222
5242
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
5223
5243
|
}
|
|
5224
5244
|
});
|
|
@@ -5229,64 +5249,64 @@
|
|
|
5229
5249
|
this.paint();
|
|
5230
5250
|
}
|
|
5231
5251
|
initPlugins() {
|
|
5232
|
-
this
|
|
5233
|
-
this
|
|
5234
|
-
this
|
|
5235
|
-
this
|
|
5236
|
-
this
|
|
5237
|
-
this
|
|
5238
|
-
this
|
|
5239
|
-
this
|
|
5240
|
-
this
|
|
5241
|
-
this
|
|
5242
|
-
for (const plugin of this.
|
|
5252
|
+
this.#colorPlugins = [];
|
|
5253
|
+
this.#canvasClearPlugins = [];
|
|
5254
|
+
this.#canvasPaintPlugins = [];
|
|
5255
|
+
this.#clearDrawPlugins = [];
|
|
5256
|
+
this.#drawParticlePlugins = [];
|
|
5257
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5258
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5259
|
+
this.#drawPlugins = [];
|
|
5260
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5261
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5262
|
+
for (const plugin of this.#container.plugins) {
|
|
5243
5263
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
5244
|
-
this.
|
|
5264
|
+
this.#colorPlugins.push(plugin);
|
|
5245
5265
|
}
|
|
5246
5266
|
if (plugin.canvasClear) {
|
|
5247
|
-
this.
|
|
5267
|
+
this.#canvasClearPlugins.push(plugin);
|
|
5248
5268
|
}
|
|
5249
5269
|
if (plugin.canvasPaint) {
|
|
5250
|
-
this.
|
|
5270
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
5251
5271
|
}
|
|
5252
5272
|
if (plugin.drawParticle) {
|
|
5253
|
-
this.
|
|
5273
|
+
this.#drawParticlePlugins.push(plugin);
|
|
5254
5274
|
}
|
|
5255
5275
|
if (plugin.drawParticleSetup) {
|
|
5256
|
-
this.
|
|
5276
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
5257
5277
|
}
|
|
5258
5278
|
if (plugin.drawParticleCleanup) {
|
|
5259
|
-
this.
|
|
5279
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
5260
5280
|
}
|
|
5261
5281
|
if (plugin.draw) {
|
|
5262
|
-
this.
|
|
5282
|
+
this.#drawPlugins.push(plugin);
|
|
5263
5283
|
}
|
|
5264
5284
|
if (plugin.drawSettingsSetup) {
|
|
5265
|
-
this.
|
|
5285
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
5266
5286
|
}
|
|
5267
5287
|
if (plugin.drawSettingsCleanup) {
|
|
5268
|
-
this.
|
|
5288
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
5269
5289
|
}
|
|
5270
5290
|
if (plugin.clearDraw) {
|
|
5271
|
-
this.
|
|
5291
|
+
this.#clearDrawPlugins.push(plugin);
|
|
5272
5292
|
}
|
|
5273
5293
|
}
|
|
5274
5294
|
}
|
|
5275
5295
|
initUpdaters() {
|
|
5276
|
-
this
|
|
5277
|
-
this
|
|
5278
|
-
for (const updater of this.
|
|
5296
|
+
this.#preDrawUpdaters = [];
|
|
5297
|
+
this.#postDrawUpdaters = [];
|
|
5298
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5279
5299
|
if (updater.afterDraw) {
|
|
5280
|
-
this.
|
|
5300
|
+
this.#postDrawUpdaters.push(updater);
|
|
5281
5301
|
}
|
|
5282
5302
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
5283
|
-
this.
|
|
5303
|
+
this.#preDrawUpdaters.push(updater);
|
|
5284
5304
|
}
|
|
5285
5305
|
}
|
|
5286
5306
|
}
|
|
5287
5307
|
paint() {
|
|
5288
5308
|
let handled = false;
|
|
5289
|
-
for (const plugin of this
|
|
5309
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
5290
5310
|
handled = plugin.canvasPaint?.() ?? false;
|
|
5291
5311
|
if (handled) {
|
|
5292
5312
|
break;
|
|
@@ -5299,35 +5319,35 @@
|
|
|
5299
5319
|
}
|
|
5300
5320
|
paintBase(baseColor) {
|
|
5301
5321
|
this.draw(ctx => {
|
|
5302
|
-
paintBase(ctx, this.
|
|
5322
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
5303
5323
|
});
|
|
5304
5324
|
}
|
|
5305
5325
|
paintImage(image, opacity) {
|
|
5306
5326
|
this.draw(ctx => {
|
|
5307
|
-
paintImage(ctx, this.
|
|
5327
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
5308
5328
|
});
|
|
5309
5329
|
}
|
|
5310
5330
|
setContext(context) {
|
|
5311
|
-
this
|
|
5312
|
-
if (this
|
|
5313
|
-
this.
|
|
5331
|
+
this.#context = context;
|
|
5332
|
+
if (this.#context) {
|
|
5333
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
5314
5334
|
}
|
|
5315
5335
|
}
|
|
5316
5336
|
setContextSettings(settings) {
|
|
5317
|
-
this
|
|
5337
|
+
this.#contextSettings = settings;
|
|
5318
5338
|
}
|
|
5319
5339
|
stop() {
|
|
5320
5340
|
this.draw(ctx => {
|
|
5321
|
-
clear(ctx, this.
|
|
5341
|
+
clear(ctx, this.#canvasManager.size);
|
|
5322
5342
|
});
|
|
5323
5343
|
}
|
|
5324
|
-
|
|
5325
|
-
for (const updater of this
|
|
5344
|
+
#applyPostDrawUpdaters = particle => {
|
|
5345
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
5326
5346
|
updater.afterDraw?.(particle);
|
|
5327
5347
|
}
|
|
5328
5348
|
};
|
|
5329
|
-
|
|
5330
|
-
for (const updater of this
|
|
5349
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
5350
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
5331
5351
|
if (updater.getColorStyles) {
|
|
5332
5352
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
5333
5353
|
if (fill) {
|
|
@@ -5346,22 +5366,22 @@
|
|
|
5346
5366
|
updater.beforeDraw?.(particle);
|
|
5347
5367
|
}
|
|
5348
5368
|
};
|
|
5349
|
-
|
|
5369
|
+
#getPluginParticleColors = particle => {
|
|
5350
5370
|
let fColor, sColor;
|
|
5351
|
-
for (const plugin of this
|
|
5371
|
+
for (const plugin of this.#colorPlugins) {
|
|
5352
5372
|
if (!fColor && plugin.particleFillColor) {
|
|
5353
|
-
fColor = rangeColorToHsl(this
|
|
5373
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
5354
5374
|
}
|
|
5355
5375
|
if (!sColor && plugin.particleStrokeColor) {
|
|
5356
|
-
sColor = rangeColorToHsl(this
|
|
5376
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
5357
5377
|
}
|
|
5358
5378
|
if (fColor && sColor) {
|
|
5359
5379
|
break;
|
|
5360
5380
|
}
|
|
5361
5381
|
}
|
|
5362
|
-
this
|
|
5363
|
-
this
|
|
5364
|
-
return this
|
|
5382
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
5383
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
5384
|
+
return this.#reusablePluginColors;
|
|
5365
5385
|
};
|
|
5366
5386
|
}
|
|
5367
5387
|
|
|
@@ -5419,53 +5439,53 @@
|
|
|
5419
5439
|
renderCanvas;
|
|
5420
5440
|
size;
|
|
5421
5441
|
zoom = defaultZoom;
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5442
|
+
#container;
|
|
5443
|
+
#generated;
|
|
5444
|
+
#mutationObserver;
|
|
5445
|
+
#originalStyle;
|
|
5446
|
+
#pluginManager;
|
|
5447
|
+
#pointerEvents;
|
|
5448
|
+
#resizePlugins;
|
|
5449
|
+
#standardSize;
|
|
5450
|
+
#zoomCenter;
|
|
5431
5451
|
constructor(pluginManager, container) {
|
|
5432
|
-
this
|
|
5433
|
-
this
|
|
5452
|
+
this.#pluginManager = pluginManager;
|
|
5453
|
+
this.#container = container;
|
|
5434
5454
|
this.render = new RenderManager(pluginManager, container, this);
|
|
5435
|
-
this
|
|
5455
|
+
this.#standardSize = {
|
|
5436
5456
|
height: 0,
|
|
5437
5457
|
width: 0,
|
|
5438
5458
|
};
|
|
5439
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
5459
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
5440
5460
|
this.size = {
|
|
5441
5461
|
height: stdSize.height * pxRatio,
|
|
5442
5462
|
width: stdSize.width * pxRatio,
|
|
5443
5463
|
};
|
|
5444
|
-
this
|
|
5445
|
-
this
|
|
5446
|
-
this
|
|
5464
|
+
this.#generated = false;
|
|
5465
|
+
this.#resizePlugins = [];
|
|
5466
|
+
this.#pointerEvents = "none";
|
|
5447
5467
|
}
|
|
5448
|
-
get
|
|
5449
|
-
return this.
|
|
5468
|
+
get #fullScreen() {
|
|
5469
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
5450
5470
|
}
|
|
5451
5471
|
destroy() {
|
|
5452
5472
|
this.stop();
|
|
5453
|
-
if (this
|
|
5473
|
+
if (this.#generated) {
|
|
5454
5474
|
const element = this.domElement;
|
|
5455
5475
|
element?.remove();
|
|
5456
5476
|
this.domElement = undefined;
|
|
5457
5477
|
this.renderCanvas = undefined;
|
|
5458
5478
|
}
|
|
5459
5479
|
else {
|
|
5460
|
-
this
|
|
5480
|
+
this.#resetOriginalStyle();
|
|
5461
5481
|
}
|
|
5462
5482
|
this.render.destroy();
|
|
5463
|
-
this
|
|
5483
|
+
this.#resizePlugins = [];
|
|
5464
5484
|
}
|
|
5465
5485
|
getZoomCenter() {
|
|
5466
|
-
const pxRatio = this.
|
|
5467
|
-
if (this
|
|
5468
|
-
return this
|
|
5486
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
5487
|
+
if (this.#zoomCenter) {
|
|
5488
|
+
return this.#zoomCenter;
|
|
5469
5489
|
}
|
|
5470
5490
|
return {
|
|
5471
5491
|
x: (width * half) / pxRatio,
|
|
@@ -5473,20 +5493,20 @@
|
|
|
5473
5493
|
};
|
|
5474
5494
|
}
|
|
5475
5495
|
init() {
|
|
5476
|
-
this
|
|
5496
|
+
this.#safeMutationObserver(obs => {
|
|
5477
5497
|
obs.disconnect();
|
|
5478
5498
|
});
|
|
5479
|
-
this
|
|
5499
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
5480
5500
|
for (const record of records) {
|
|
5481
5501
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
5482
|
-
this
|
|
5502
|
+
this.#repairStyle();
|
|
5483
5503
|
}
|
|
5484
5504
|
}
|
|
5485
5505
|
});
|
|
5486
5506
|
this.resize();
|
|
5487
|
-
this
|
|
5507
|
+
this.#initStyle();
|
|
5488
5508
|
this.initBackground();
|
|
5489
|
-
this
|
|
5509
|
+
this.#safeMutationObserver(obs => {
|
|
5490
5510
|
const element = this.domElement;
|
|
5491
5511
|
if (!element || !(element instanceof Node)) {
|
|
5492
5512
|
return;
|
|
@@ -5497,13 +5517,13 @@
|
|
|
5497
5517
|
this.render.init();
|
|
5498
5518
|
}
|
|
5499
5519
|
initBackground() {
|
|
5500
|
-
const
|
|
5520
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
5501
5521
|
if (!element) {
|
|
5502
5522
|
return;
|
|
5503
5523
|
}
|
|
5504
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
5524
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
5505
5525
|
if (color) {
|
|
5506
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
5526
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
5507
5527
|
}
|
|
5508
5528
|
else {
|
|
5509
5529
|
elementStyle.backgroundColor = "";
|
|
@@ -5514,27 +5534,27 @@
|
|
|
5514
5534
|
elementStyle.backgroundSize = background.size || "";
|
|
5515
5535
|
}
|
|
5516
5536
|
initPlugins() {
|
|
5517
|
-
this
|
|
5518
|
-
for (const plugin of this.
|
|
5537
|
+
this.#resizePlugins = [];
|
|
5538
|
+
for (const plugin of this.#container.plugins) {
|
|
5519
5539
|
if (plugin.resize) {
|
|
5520
|
-
this.
|
|
5540
|
+
this.#resizePlugins.push(plugin);
|
|
5521
5541
|
}
|
|
5522
5542
|
}
|
|
5523
5543
|
}
|
|
5524
5544
|
loadCanvas(canvas) {
|
|
5525
|
-
if (this
|
|
5545
|
+
if (this.#generated && this.domElement) {
|
|
5526
5546
|
this.domElement.remove();
|
|
5527
5547
|
}
|
|
5528
|
-
const container = this
|
|
5548
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
5529
5549
|
this.domElement = domCanvas;
|
|
5530
|
-
this
|
|
5550
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
5531
5551
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
5532
5552
|
const domElement = this.domElement;
|
|
5533
5553
|
if (domElement) {
|
|
5534
5554
|
domElement.ariaHidden = "true";
|
|
5535
|
-
this
|
|
5555
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
5536
5556
|
}
|
|
5537
|
-
const standardSize = this
|
|
5557
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
5538
5558
|
if (domElement) {
|
|
5539
5559
|
standardSize.height = domElement.offsetHeight;
|
|
5540
5560
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -5543,7 +5563,7 @@
|
|
|
5543
5563
|
standardSize.height = renderCanvas.height;
|
|
5544
5564
|
standardSize.width = renderCanvas.width;
|
|
5545
5565
|
}
|
|
5546
|
-
const pxRatio = this.
|
|
5566
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
5547
5567
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
5548
5568
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
5549
5569
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -5554,12 +5574,12 @@
|
|
|
5554
5574
|
willReadFrequently: false,
|
|
5555
5575
|
});
|
|
5556
5576
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
5557
|
-
this
|
|
5577
|
+
this.#safeMutationObserver(obs => {
|
|
5558
5578
|
obs.disconnect();
|
|
5559
5579
|
});
|
|
5560
5580
|
container.retina.init();
|
|
5561
5581
|
this.initBackground();
|
|
5562
|
-
this
|
|
5582
|
+
this.#safeMutationObserver(obs => {
|
|
5563
5583
|
const element = this.domElement;
|
|
5564
5584
|
if (!element || !(element instanceof Node)) {
|
|
5565
5585
|
return;
|
|
@@ -5572,11 +5592,11 @@
|
|
|
5572
5592
|
if (!element) {
|
|
5573
5593
|
return false;
|
|
5574
5594
|
}
|
|
5575
|
-
const container = this
|
|
5595
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
5576
5596
|
if (renderCanvas === undefined) {
|
|
5577
5597
|
return false;
|
|
5578
5598
|
}
|
|
5579
|
-
const currentSize = container.canvas
|
|
5599
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
5580
5600
|
width: element.offsetWidth,
|
|
5581
5601
|
height: element.offsetHeight,
|
|
5582
5602
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -5595,7 +5615,7 @@
|
|
|
5595
5615
|
const canvasSize = this.size;
|
|
5596
5616
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
5597
5617
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
5598
|
-
if (this.
|
|
5618
|
+
if (this.#container.started) {
|
|
5599
5619
|
container.particles.setResizeFactor({
|
|
5600
5620
|
width: currentSize.width / oldSize.width,
|
|
5601
5621
|
height: currentSize.height / oldSize.height,
|
|
@@ -5608,46 +5628,46 @@
|
|
|
5608
5628
|
if (!element) {
|
|
5609
5629
|
return;
|
|
5610
5630
|
}
|
|
5611
|
-
this
|
|
5612
|
-
this
|
|
5631
|
+
this.#pointerEvents = type;
|
|
5632
|
+
this.#repairStyle();
|
|
5613
5633
|
}
|
|
5614
5634
|
setZoom(zoomLevel, center) {
|
|
5615
5635
|
this.zoom = zoomLevel;
|
|
5616
|
-
this
|
|
5636
|
+
this.#zoomCenter = center;
|
|
5617
5637
|
}
|
|
5618
5638
|
stop() {
|
|
5619
|
-
this
|
|
5639
|
+
this.#safeMutationObserver(obs => {
|
|
5620
5640
|
obs.disconnect();
|
|
5621
5641
|
});
|
|
5622
|
-
this
|
|
5642
|
+
this.#mutationObserver = undefined;
|
|
5623
5643
|
this.render.stop();
|
|
5624
5644
|
}
|
|
5625
5645
|
async windowResize() {
|
|
5626
5646
|
if (!this.domElement || !this.resize()) {
|
|
5627
5647
|
return;
|
|
5628
5648
|
}
|
|
5629
|
-
const container = this
|
|
5649
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
5630
5650
|
container.particles.setDensity();
|
|
5631
|
-
this
|
|
5651
|
+
this.#applyResizePlugins();
|
|
5632
5652
|
if (needsRefresh) {
|
|
5633
5653
|
await container.refresh();
|
|
5634
5654
|
}
|
|
5635
5655
|
}
|
|
5636
|
-
|
|
5637
|
-
for (const plugin of this
|
|
5656
|
+
#applyResizePlugins = () => {
|
|
5657
|
+
for (const plugin of this.#resizePlugins) {
|
|
5638
5658
|
plugin.resize?.();
|
|
5639
5659
|
}
|
|
5640
5660
|
};
|
|
5641
|
-
|
|
5642
|
-
const element = this.domElement, options = this.
|
|
5661
|
+
#initStyle = () => {
|
|
5662
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
5643
5663
|
if (!element) {
|
|
5644
5664
|
return;
|
|
5645
5665
|
}
|
|
5646
|
-
if (this
|
|
5647
|
-
this
|
|
5666
|
+
if (this.#fullScreen) {
|
|
5667
|
+
this.#setFullScreenStyle();
|
|
5648
5668
|
}
|
|
5649
5669
|
else {
|
|
5650
|
-
this
|
|
5670
|
+
this.#resetOriginalStyle();
|
|
5651
5671
|
}
|
|
5652
5672
|
for (const key in options.style) {
|
|
5653
5673
|
if (!key || !(key in options.style)) {
|
|
@@ -5660,72 +5680,72 @@
|
|
|
5660
5680
|
element.style.setProperty(key, value, "important");
|
|
5661
5681
|
}
|
|
5662
5682
|
};
|
|
5663
|
-
|
|
5683
|
+
#repairStyle = () => {
|
|
5664
5684
|
const element = this.domElement;
|
|
5665
5685
|
if (!element) {
|
|
5666
5686
|
return;
|
|
5667
5687
|
}
|
|
5668
|
-
this
|
|
5688
|
+
this.#safeMutationObserver(observer => {
|
|
5669
5689
|
observer.disconnect();
|
|
5670
5690
|
});
|
|
5671
|
-
this
|
|
5691
|
+
this.#initStyle();
|
|
5672
5692
|
this.initBackground();
|
|
5673
|
-
const pointerEvents = this
|
|
5693
|
+
const pointerEvents = this.#pointerEvents;
|
|
5674
5694
|
element.style.pointerEvents = pointerEvents;
|
|
5675
5695
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
5676
|
-
this
|
|
5696
|
+
this.#safeMutationObserver(observer => {
|
|
5677
5697
|
if (!(element instanceof Node)) {
|
|
5678
5698
|
return;
|
|
5679
5699
|
}
|
|
5680
5700
|
observer.observe(element, { attributes: true });
|
|
5681
5701
|
});
|
|
5682
5702
|
};
|
|
5683
|
-
|
|
5684
|
-
const element = this.domElement, originalStyle = this
|
|
5703
|
+
#resetOriginalStyle = () => {
|
|
5704
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
5685
5705
|
if (!element || !originalStyle) {
|
|
5686
5706
|
return;
|
|
5687
5707
|
}
|
|
5688
5708
|
setStyle(element, originalStyle, true);
|
|
5689
5709
|
};
|
|
5690
|
-
|
|
5691
|
-
if (!this
|
|
5710
|
+
#safeMutationObserver = callback => {
|
|
5711
|
+
if (!this.#mutationObserver) {
|
|
5692
5712
|
return;
|
|
5693
5713
|
}
|
|
5694
|
-
callback(this
|
|
5714
|
+
callback(this.#mutationObserver);
|
|
5695
5715
|
};
|
|
5696
|
-
|
|
5716
|
+
#setFullScreenStyle = () => {
|
|
5697
5717
|
const element = this.domElement;
|
|
5698
5718
|
if (!element) {
|
|
5699
5719
|
return;
|
|
5700
5720
|
}
|
|
5701
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5721
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
5702
5722
|
};
|
|
5703
5723
|
}
|
|
5704
5724
|
|
|
5705
5725
|
class EventListeners {
|
|
5706
|
-
container;
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5726
|
+
#container;
|
|
5727
|
+
#handlers;
|
|
5728
|
+
#resizeObserver;
|
|
5729
|
+
#resizeTimeout;
|
|
5710
5730
|
constructor(container) {
|
|
5711
|
-
this
|
|
5712
|
-
this
|
|
5731
|
+
this.#container = container;
|
|
5732
|
+
this.#handlers = {
|
|
5713
5733
|
visibilityChange: () => {
|
|
5714
|
-
this
|
|
5734
|
+
this.#handleVisibilityChange();
|
|
5715
5735
|
},
|
|
5716
5736
|
resize: () => {
|
|
5717
|
-
this
|
|
5737
|
+
this.#handleWindowResize();
|
|
5718
5738
|
},
|
|
5719
5739
|
};
|
|
5720
5740
|
}
|
|
5721
5741
|
addListeners() {
|
|
5722
|
-
this
|
|
5742
|
+
this.#manageListeners(true);
|
|
5723
5743
|
}
|
|
5724
5744
|
removeListeners() {
|
|
5725
|
-
this
|
|
5745
|
+
this.#manageListeners(false);
|
|
5726
5746
|
}
|
|
5727
|
-
|
|
5728
|
-
const container = this
|
|
5747
|
+
#handleVisibilityChange = () => {
|
|
5748
|
+
const container = this.#container, options = container.actualOptions;
|
|
5729
5749
|
if (!options.pauseOnBlur) {
|
|
5730
5750
|
return;
|
|
5731
5751
|
}
|
|
@@ -5743,24 +5763,24 @@
|
|
|
5743
5763
|
}
|
|
5744
5764
|
}
|
|
5745
5765
|
};
|
|
5746
|
-
|
|
5747
|
-
if (this
|
|
5748
|
-
clearTimeout(this
|
|
5749
|
-
|
|
5766
|
+
#handleWindowResize = () => {
|
|
5767
|
+
if (this.#resizeTimeout) {
|
|
5768
|
+
clearTimeout(this.#resizeTimeout);
|
|
5769
|
+
this.#resizeTimeout = undefined;
|
|
5750
5770
|
}
|
|
5751
5771
|
const handleResize = async () => {
|
|
5752
|
-
const canvas = this
|
|
5772
|
+
const canvas = this.#container.canvas;
|
|
5753
5773
|
await canvas.windowResize();
|
|
5754
5774
|
};
|
|
5755
|
-
this
|
|
5775
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5756
5776
|
};
|
|
5757
|
-
|
|
5758
|
-
const handlers = this
|
|
5759
|
-
this
|
|
5777
|
+
#manageListeners = add => {
|
|
5778
|
+
const handlers = this.#handlers;
|
|
5779
|
+
this.#manageResize(add);
|
|
5760
5780
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5761
5781
|
};
|
|
5762
|
-
|
|
5763
|
-
const handlers = this
|
|
5782
|
+
#manageResize = add => {
|
|
5783
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5764
5784
|
if (!options.resize.enable) {
|
|
5765
5785
|
return;
|
|
5766
5786
|
}
|
|
@@ -5769,22 +5789,22 @@
|
|
|
5769
5789
|
return;
|
|
5770
5790
|
}
|
|
5771
5791
|
const canvasEl = container.canvas.domElement;
|
|
5772
|
-
if (this
|
|
5792
|
+
if (this.#resizeObserver && !add) {
|
|
5773
5793
|
if (canvasEl) {
|
|
5774
|
-
this.
|
|
5794
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5775
5795
|
}
|
|
5776
|
-
this.
|
|
5777
|
-
|
|
5796
|
+
this.#resizeObserver.disconnect();
|
|
5797
|
+
this.#resizeObserver = undefined;
|
|
5778
5798
|
}
|
|
5779
|
-
else if (!this
|
|
5780
|
-
this
|
|
5799
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5800
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5781
5801
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5782
5802
|
if (!entry) {
|
|
5783
5803
|
return;
|
|
5784
5804
|
}
|
|
5785
|
-
this
|
|
5805
|
+
this.#handleWindowResize();
|
|
5786
5806
|
});
|
|
5787
|
-
this.
|
|
5807
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5788
5808
|
}
|
|
5789
5809
|
};
|
|
5790
5810
|
}
|
|
@@ -5857,24 +5877,24 @@
|
|
|
5857
5877
|
unbreakable;
|
|
5858
5878
|
velocity;
|
|
5859
5879
|
zIndexFactor;
|
|
5860
|
-
|
|
5880
|
+
#cachedOpacityData = {
|
|
5861
5881
|
fillOpacity: defaultOpacity$1,
|
|
5862
5882
|
opacity: defaultOpacity$1,
|
|
5863
5883
|
strokeOpacity: defaultOpacity$1,
|
|
5864
5884
|
};
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5885
|
+
#cachedPosition = Vector3d.origin;
|
|
5886
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5887
|
+
#cachedTransform = {
|
|
5868
5888
|
a: 1,
|
|
5869
5889
|
b: 0,
|
|
5870
5890
|
c: 0,
|
|
5871
5891
|
d: 1,
|
|
5872
5892
|
};
|
|
5873
|
-
|
|
5874
|
-
|
|
5893
|
+
#container;
|
|
5894
|
+
#pluginManager;
|
|
5875
5895
|
constructor(pluginManager, container) {
|
|
5876
|
-
this
|
|
5877
|
-
this
|
|
5896
|
+
this.#pluginManager = pluginManager;
|
|
5897
|
+
this.#container = container;
|
|
5878
5898
|
}
|
|
5879
5899
|
destroy(override) {
|
|
5880
5900
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5883,7 +5903,7 @@
|
|
|
5883
5903
|
this.destroyed = true;
|
|
5884
5904
|
this.bubble.inRange = false;
|
|
5885
5905
|
this.slow.inRange = false;
|
|
5886
|
-
const container = this
|
|
5906
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5887
5907
|
shapeDrawer?.particleDestroy?.(this);
|
|
5888
5908
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5889
5909
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5891,12 +5911,12 @@
|
|
|
5891
5911
|
for (const updater of container.particleUpdaters) {
|
|
5892
5912
|
updater.particleDestroyed?.(this, override);
|
|
5893
5913
|
}
|
|
5894
|
-
this.
|
|
5914
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5895
5915
|
particle: this,
|
|
5896
5916
|
});
|
|
5897
5917
|
}
|
|
5898
5918
|
draw(delta) {
|
|
5899
|
-
const container = this
|
|
5919
|
+
const container = this.#container, render = container.canvas.render;
|
|
5900
5920
|
render.drawParticlePlugins(this, delta);
|
|
5901
5921
|
render.drawParticle(this, delta);
|
|
5902
5922
|
}
|
|
@@ -5904,50 +5924,50 @@
|
|
|
5904
5924
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5905
5925
|
}
|
|
5906
5926
|
getFillColor() {
|
|
5907
|
-
return this
|
|
5927
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5908
5928
|
}
|
|
5909
5929
|
getMass() {
|
|
5910
5930
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5911
5931
|
}
|
|
5912
5932
|
getOpacity() {
|
|
5913
5933
|
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;
|
|
5914
|
-
this.
|
|
5915
|
-
this.
|
|
5916
|
-
this.
|
|
5917
|
-
return this
|
|
5934
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5935
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5936
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5937
|
+
return this.#cachedOpacityData;
|
|
5918
5938
|
}
|
|
5919
5939
|
getPosition() {
|
|
5920
|
-
this.
|
|
5921
|
-
this.
|
|
5922
|
-
this.
|
|
5923
|
-
return this
|
|
5940
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5941
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5942
|
+
this.#cachedPosition.z = this.position.z;
|
|
5943
|
+
return this.#cachedPosition;
|
|
5924
5944
|
}
|
|
5925
5945
|
getRadius() {
|
|
5926
5946
|
return this.bubble.radius ?? this.size.value;
|
|
5927
5947
|
}
|
|
5928
5948
|
getRotateData() {
|
|
5929
5949
|
const angle = this.getAngle();
|
|
5930
|
-
this.
|
|
5931
|
-
this.
|
|
5932
|
-
return this
|
|
5950
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5951
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5952
|
+
return this.#cachedRotateData;
|
|
5933
5953
|
}
|
|
5934
5954
|
getStrokeColor() {
|
|
5935
|
-
return this
|
|
5955
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5936
5956
|
}
|
|
5937
5957
|
getTransformData(externalTransform) {
|
|
5938
5958
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5939
|
-
this.
|
|
5940
|
-
this.
|
|
5959
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5960
|
+
this.#cachedTransform.b = rotating
|
|
5941
5961
|
? rotateData.sin * (externalTransform.b ?? identity$3)
|
|
5942
5962
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5943
|
-
this.
|
|
5963
|
+
this.#cachedTransform.c = rotating
|
|
5944
5964
|
? -rotateData.sin * (externalTransform.c ?? identity$3)
|
|
5945
5965
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5946
|
-
this.
|
|
5947
|
-
return this
|
|
5966
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5967
|
+
return this.#cachedTransform;
|
|
5948
5968
|
}
|
|
5949
5969
|
init(id, position, overrideOptions, group) {
|
|
5950
|
-
const container = this
|
|
5970
|
+
const container = this.#container;
|
|
5951
5971
|
this.id = id;
|
|
5952
5972
|
this.group = group;
|
|
5953
5973
|
this.justWarped = false;
|
|
@@ -5967,21 +5987,27 @@
|
|
|
5967
5987
|
moveSpeed: 0,
|
|
5968
5988
|
sizeAnimationSpeed: 0,
|
|
5969
5989
|
};
|
|
5990
|
+
this.size = {
|
|
5991
|
+
value: 1,
|
|
5992
|
+
max: 1,
|
|
5993
|
+
min: 1,
|
|
5994
|
+
enable: false,
|
|
5995
|
+
};
|
|
5970
5996
|
this.outType = ParticleOutType.normal;
|
|
5971
5997
|
this.ignoresResizeRatio = true;
|
|
5972
|
-
const
|
|
5998
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5973
5999
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5974
6000
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5975
6001
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5976
6002
|
if (overrideOptions) {
|
|
5977
|
-
if (overrideOptions.effect?.type) {
|
|
6003
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5978
6004
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5979
6005
|
if (effect) {
|
|
5980
6006
|
this.effect = effect;
|
|
5981
6007
|
effectOptions.load(overrideOptions.effect);
|
|
5982
6008
|
}
|
|
5983
6009
|
}
|
|
5984
|
-
if (overrideOptions.shape?.type) {
|
|
6010
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5985
6011
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5986
6012
|
if (shape) {
|
|
5987
6013
|
this.shape = shape;
|
|
@@ -5990,21 +6016,20 @@
|
|
|
5990
6016
|
}
|
|
5991
6017
|
}
|
|
5992
6018
|
if (this.effect === randomColorValue) {
|
|
5993
|
-
const availableEffects = [...this.
|
|
6019
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5994
6020
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5995
6021
|
}
|
|
5996
6022
|
if (this.shape === randomColorValue) {
|
|
5997
|
-
const availableShapes = [...this.
|
|
6023
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5998
6024
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5999
6025
|
}
|
|
6000
6026
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
6001
6027
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
6002
6028
|
particlesOptions.load(overrideOptions);
|
|
6003
|
-
const effectData = this.effectData;
|
|
6029
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
6004
6030
|
if (effectData) {
|
|
6005
6031
|
particlesOptions.load(effectData.particles);
|
|
6006
6032
|
}
|
|
6007
|
-
const shapeData = this.shapeData;
|
|
6008
6033
|
if (shapeData) {
|
|
6009
6034
|
particlesOptions.load(shapeData.particles);
|
|
6010
6035
|
}
|
|
@@ -6012,7 +6037,9 @@
|
|
|
6012
6037
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
6013
6038
|
this.options = particlesOptions;
|
|
6014
6039
|
container.retina.initParticle(this);
|
|
6015
|
-
|
|
6040
|
+
for (const updater of container.particleUpdaters) {
|
|
6041
|
+
updater.preInit?.(this);
|
|
6042
|
+
}
|
|
6016
6043
|
this.bubble = {
|
|
6017
6044
|
inRange: false,
|
|
6018
6045
|
};
|
|
@@ -6020,8 +6047,8 @@
|
|
|
6020
6047
|
inRange: false,
|
|
6021
6048
|
factor: 1,
|
|
6022
6049
|
};
|
|
6023
|
-
this
|
|
6024
|
-
this.initialVelocity = this
|
|
6050
|
+
this.#initPosition(position);
|
|
6051
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
6025
6052
|
this.velocity = this.initialVelocity.copy();
|
|
6026
6053
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
6027
6054
|
this.sides = 24;
|
|
@@ -6052,12 +6079,11 @@
|
|
|
6052
6079
|
plugin.particleCreated?.(this);
|
|
6053
6080
|
}
|
|
6054
6081
|
}
|
|
6055
|
-
isInsideCanvas() {
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
position.x <= canvasSize.width + radius);
|
|
6082
|
+
isInsideCanvas(direction) {
|
|
6083
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
6084
|
+
}
|
|
6085
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
6086
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
6061
6087
|
}
|
|
6062
6088
|
isShowingBack() {
|
|
6063
6089
|
if (!this.roll) {
|
|
@@ -6082,13 +6108,13 @@
|
|
|
6082
6108
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
6083
6109
|
}
|
|
6084
6110
|
reset() {
|
|
6085
|
-
for (const updater of this.
|
|
6111
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6086
6112
|
updater.reset?.(this);
|
|
6087
6113
|
}
|
|
6088
6114
|
}
|
|
6089
|
-
|
|
6115
|
+
#calcPosition = (position, zIndex) => {
|
|
6090
6116
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
6091
|
-
const container = this
|
|
6117
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
6092
6118
|
while (!signal.aborted) {
|
|
6093
6119
|
for (const plugin of plugins) {
|
|
6094
6120
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -6100,10 +6126,10 @@
|
|
|
6100
6126
|
size: canvasSize,
|
|
6101
6127
|
position: posVec,
|
|
6102
6128
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
6103
|
-
this
|
|
6104
|
-
this
|
|
6105
|
-
this
|
|
6106
|
-
this
|
|
6129
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
6130
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
6131
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
6132
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
6107
6133
|
let isValidPosition = true;
|
|
6108
6134
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
6109
6135
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -6119,8 +6145,8 @@
|
|
|
6119
6145
|
}
|
|
6120
6146
|
return posVec;
|
|
6121
6147
|
};
|
|
6122
|
-
|
|
6123
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
6148
|
+
#calculateVelocity = () => {
|
|
6149
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
6124
6150
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
6125
6151
|
return res;
|
|
6126
6152
|
}
|
|
@@ -6136,27 +6162,86 @@
|
|
|
6136
6162
|
}
|
|
6137
6163
|
return res;
|
|
6138
6164
|
};
|
|
6139
|
-
|
|
6165
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
6140
6166
|
fixOutMode({
|
|
6141
6167
|
outMode,
|
|
6142
6168
|
checkModes: [OutMode.bounce],
|
|
6143
6169
|
coord: pos.x,
|
|
6144
|
-
maxCoord: this.
|
|
6170
|
+
maxCoord: this.#container.canvas.size.width,
|
|
6145
6171
|
setCb: (value) => (pos.x += value),
|
|
6146
6172
|
radius,
|
|
6147
6173
|
});
|
|
6148
6174
|
};
|
|
6149
|
-
|
|
6175
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
6150
6176
|
fixOutMode({
|
|
6151
6177
|
outMode,
|
|
6152
6178
|
checkModes: [OutMode.bounce],
|
|
6153
6179
|
coord: pos.y,
|
|
6154
|
-
maxCoord: this.
|
|
6180
|
+
maxCoord: this.#container.canvas.size.height,
|
|
6155
6181
|
setCb: (value) => (pos.y += value),
|
|
6156
6182
|
radius,
|
|
6157
6183
|
});
|
|
6158
6184
|
};
|
|
6159
|
-
|
|
6185
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
6186
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
6187
|
+
if (direction === OutModeDirection.bottom) {
|
|
6188
|
+
return {
|
|
6189
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
6190
|
+
reason: "default",
|
|
6191
|
+
};
|
|
6192
|
+
}
|
|
6193
|
+
if (direction === OutModeDirection.left) {
|
|
6194
|
+
return {
|
|
6195
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
6196
|
+
reason: "default",
|
|
6197
|
+
};
|
|
6198
|
+
}
|
|
6199
|
+
if (direction === OutModeDirection.right) {
|
|
6200
|
+
return {
|
|
6201
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
6202
|
+
reason: "default",
|
|
6203
|
+
};
|
|
6204
|
+
}
|
|
6205
|
+
if (direction === OutModeDirection.top) {
|
|
6206
|
+
return {
|
|
6207
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
6208
|
+
reason: "default",
|
|
6209
|
+
};
|
|
6210
|
+
}
|
|
6211
|
+
return {
|
|
6212
|
+
inside: position.x >= -radius &&
|
|
6213
|
+
position.y >= -radius &&
|
|
6214
|
+
position.y <= canvasSize.height + radius &&
|
|
6215
|
+
position.x <= canvasSize.width + radius,
|
|
6216
|
+
reason: "default",
|
|
6217
|
+
};
|
|
6218
|
+
};
|
|
6219
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
6220
|
+
return {
|
|
6221
|
+
canvasSize: this.#container.canvas.size,
|
|
6222
|
+
direction,
|
|
6223
|
+
outMode,
|
|
6224
|
+
particle: this,
|
|
6225
|
+
radius: this.getRadius(),
|
|
6226
|
+
};
|
|
6227
|
+
};
|
|
6228
|
+
#getInsideCanvasResult = (data) => {
|
|
6229
|
+
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;
|
|
6230
|
+
if (!shapeCheck && !effectCheck) {
|
|
6231
|
+
return defaultResult;
|
|
6232
|
+
}
|
|
6233
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
6234
|
+
if (shapeResult && effectResult) {
|
|
6235
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
6236
|
+
return {
|
|
6237
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
6238
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
6239
|
+
reason: "combined",
|
|
6240
|
+
};
|
|
6241
|
+
}
|
|
6242
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
6243
|
+
};
|
|
6244
|
+
#getRollColor = color => {
|
|
6160
6245
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
6161
6246
|
return color;
|
|
6162
6247
|
}
|
|
@@ -6171,8 +6256,8 @@
|
|
|
6171
6256
|
}
|
|
6172
6257
|
return color;
|
|
6173
6258
|
};
|
|
6174
|
-
|
|
6175
|
-
const container = this
|
|
6259
|
+
#initPosition = position => {
|
|
6260
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
6176
6261
|
if (!initialPosition) {
|
|
6177
6262
|
throw new Error("a valid position cannot be found for particle");
|
|
6178
6263
|
}
|
|
@@ -6195,45 +6280,58 @@
|
|
|
6195
6280
|
}
|
|
6196
6281
|
this.offset = Vector.origin;
|
|
6197
6282
|
};
|
|
6283
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
6284
|
+
if (typeof result === "boolean") {
|
|
6285
|
+
return {
|
|
6286
|
+
inside: result,
|
|
6287
|
+
reason,
|
|
6288
|
+
};
|
|
6289
|
+
}
|
|
6290
|
+
return {
|
|
6291
|
+
inside: result.inside,
|
|
6292
|
+
margin: result.margin,
|
|
6293
|
+
reason: result.reason ?? reason,
|
|
6294
|
+
};
|
|
6295
|
+
};
|
|
6198
6296
|
}
|
|
6199
6297
|
|
|
6200
6298
|
class SpatialHashGrid {
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6299
|
+
#cellSize;
|
|
6300
|
+
#cells = new Map();
|
|
6301
|
+
#circlePool = [];
|
|
6302
|
+
#circlePoolIdx;
|
|
6303
|
+
#pendingCellSize;
|
|
6304
|
+
#rectanglePool = [];
|
|
6305
|
+
#rectanglePoolIdx;
|
|
6208
6306
|
constructor(cellSize) {
|
|
6209
|
-
this
|
|
6210
|
-
this
|
|
6211
|
-
this
|
|
6307
|
+
this.#cellSize = cellSize;
|
|
6308
|
+
this.#circlePoolIdx = 0;
|
|
6309
|
+
this.#rectanglePoolIdx = 0;
|
|
6212
6310
|
}
|
|
6213
6311
|
clear() {
|
|
6214
|
-
this.
|
|
6215
|
-
const pendingCellSize = this
|
|
6312
|
+
this.#cells.clear();
|
|
6313
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
6216
6314
|
if (pendingCellSize) {
|
|
6217
|
-
this
|
|
6315
|
+
this.#cellSize = pendingCellSize;
|
|
6218
6316
|
}
|
|
6219
|
-
this
|
|
6317
|
+
this.#pendingCellSize = undefined;
|
|
6220
6318
|
}
|
|
6221
6319
|
insert(particle) {
|
|
6222
|
-
const { x, y } = particle.getPosition(), key = this
|
|
6223
|
-
if (!this.
|
|
6224
|
-
this.
|
|
6320
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
6321
|
+
if (!this.#cells.has(key)) {
|
|
6322
|
+
this.#cells.set(key, []);
|
|
6225
6323
|
}
|
|
6226
|
-
this.
|
|
6324
|
+
this.#cells.get(key)?.push(particle);
|
|
6227
6325
|
}
|
|
6228
6326
|
query(range, check, out = []) {
|
|
6229
|
-
const bounds = this
|
|
6327
|
+
const bounds = this.#getRangeBounds(range);
|
|
6230
6328
|
if (!bounds) {
|
|
6231
6329
|
return out;
|
|
6232
6330
|
}
|
|
6233
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
6331
|
+
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);
|
|
6234
6332
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
6235
6333
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
6236
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
6334
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
6237
6335
|
if (!cellParticles) {
|
|
6238
6336
|
continue;
|
|
6239
6337
|
}
|
|
@@ -6250,29 +6348,29 @@
|
|
|
6250
6348
|
return out;
|
|
6251
6349
|
}
|
|
6252
6350
|
queryCircle(position, radius, check, out = []) {
|
|
6253
|
-
const circle = this
|
|
6254
|
-
this
|
|
6351
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
6352
|
+
this.#releaseShapes();
|
|
6255
6353
|
return result;
|
|
6256
6354
|
}
|
|
6257
6355
|
queryRectangle(position, size, check, out = []) {
|
|
6258
|
-
const rect = this
|
|
6259
|
-
this
|
|
6356
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
6357
|
+
this.#releaseShapes();
|
|
6260
6358
|
return result;
|
|
6261
6359
|
}
|
|
6262
6360
|
setCellSize(cellSize) {
|
|
6263
|
-
this
|
|
6361
|
+
this.#pendingCellSize = cellSize;
|
|
6264
6362
|
}
|
|
6265
|
-
|
|
6266
|
-
return (this
|
|
6363
|
+
#acquireCircle(x, y, r) {
|
|
6364
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
6267
6365
|
}
|
|
6268
|
-
|
|
6269
|
-
return (this
|
|
6366
|
+
#acquireRectangle(x, y, w, h) {
|
|
6367
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
6270
6368
|
}
|
|
6271
|
-
|
|
6272
|
-
const cellX = Math.floor(x / this
|
|
6369
|
+
#cellKeyFromCoords(x, y) {
|
|
6370
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
6273
6371
|
return `${cellX}_${cellY}`;
|
|
6274
6372
|
}
|
|
6275
|
-
|
|
6373
|
+
#getRangeBounds(range) {
|
|
6276
6374
|
if (range instanceof Circle) {
|
|
6277
6375
|
const r = range.radius, { x, y } = range.position;
|
|
6278
6376
|
return {
|
|
@@ -6293,53 +6391,53 @@
|
|
|
6293
6391
|
}
|
|
6294
6392
|
return null;
|
|
6295
6393
|
}
|
|
6296
|
-
|
|
6297
|
-
this
|
|
6298
|
-
this
|
|
6394
|
+
#releaseShapes() {
|
|
6395
|
+
this.#circlePoolIdx = 0;
|
|
6396
|
+
this.#rectanglePoolIdx = 0;
|
|
6299
6397
|
}
|
|
6300
6398
|
}
|
|
6301
6399
|
|
|
6302
6400
|
class ParticlesManager {
|
|
6303
6401
|
checkParticlePositionPlugins;
|
|
6304
6402
|
grid;
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6403
|
+
#array;
|
|
6404
|
+
#container;
|
|
6405
|
+
#groupLimits;
|
|
6406
|
+
#limit;
|
|
6407
|
+
#nextId;
|
|
6408
|
+
#particleBuckets;
|
|
6409
|
+
#particleResetPlugins;
|
|
6410
|
+
#particleUpdatePlugins;
|
|
6411
|
+
#pluginManager;
|
|
6412
|
+
#pool;
|
|
6413
|
+
#postParticleUpdatePlugins;
|
|
6414
|
+
#postUpdatePlugins;
|
|
6415
|
+
#resizeFactor;
|
|
6416
|
+
#updatePlugins;
|
|
6417
|
+
#zBuckets;
|
|
6320
6418
|
constructor(pluginManager, container) {
|
|
6321
|
-
this
|
|
6322
|
-
this
|
|
6323
|
-
this
|
|
6324
|
-
this
|
|
6325
|
-
this
|
|
6326
|
-
this
|
|
6327
|
-
this
|
|
6328
|
-
this
|
|
6329
|
-
this
|
|
6419
|
+
this.#pluginManager = pluginManager;
|
|
6420
|
+
this.#container = container;
|
|
6421
|
+
this.#nextId = 0;
|
|
6422
|
+
this.#array = [];
|
|
6423
|
+
this.#pool = [];
|
|
6424
|
+
this.#limit = 0;
|
|
6425
|
+
this.#groupLimits = new Map();
|
|
6426
|
+
this.#particleBuckets = new Map();
|
|
6427
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
6330
6428
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
6331
6429
|
this.checkParticlePositionPlugins = [];
|
|
6332
|
-
this
|
|
6333
|
-
this
|
|
6334
|
-
this
|
|
6335
|
-
this
|
|
6336
|
-
this
|
|
6430
|
+
this.#particleResetPlugins = [];
|
|
6431
|
+
this.#particleUpdatePlugins = [];
|
|
6432
|
+
this.#postUpdatePlugins = [];
|
|
6433
|
+
this.#postParticleUpdatePlugins = [];
|
|
6434
|
+
this.#updatePlugins = [];
|
|
6337
6435
|
}
|
|
6338
6436
|
get count() {
|
|
6339
|
-
return this.
|
|
6437
|
+
return this.#array.length;
|
|
6340
6438
|
}
|
|
6341
6439
|
addParticle(position, overrideOptions, group, initializer) {
|
|
6342
|
-
const limitMode = this.
|
|
6440
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
6343
6441
|
if (limit > minLimit) {
|
|
6344
6442
|
switch (limitMode) {
|
|
6345
6443
|
case LimitMode.delete: {
|
|
@@ -6357,20 +6455,20 @@
|
|
|
6357
6455
|
}
|
|
6358
6456
|
}
|
|
6359
6457
|
try {
|
|
6360
|
-
const particle = this.
|
|
6361
|
-
particle.init(this
|
|
6458
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
6459
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
6362
6460
|
let canAdd = true;
|
|
6363
6461
|
if (initializer) {
|
|
6364
6462
|
canAdd = initializer(particle);
|
|
6365
6463
|
}
|
|
6366
6464
|
if (!canAdd) {
|
|
6367
|
-
this.
|
|
6465
|
+
this.#pool.push(particle);
|
|
6368
6466
|
return;
|
|
6369
6467
|
}
|
|
6370
|
-
this.
|
|
6371
|
-
this
|
|
6372
|
-
this
|
|
6373
|
-
this.
|
|
6468
|
+
this.#array.push(particle);
|
|
6469
|
+
this.#insertParticleIntoBucket(particle);
|
|
6470
|
+
this.#nextId++;
|
|
6471
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
6374
6472
|
particle,
|
|
6375
6473
|
});
|
|
6376
6474
|
return particle;
|
|
@@ -6381,25 +6479,25 @@
|
|
|
6381
6479
|
return undefined;
|
|
6382
6480
|
}
|
|
6383
6481
|
clear() {
|
|
6384
|
-
this
|
|
6385
|
-
this.
|
|
6386
|
-
this
|
|
6482
|
+
this.#array = [];
|
|
6483
|
+
this.#particleBuckets.clear();
|
|
6484
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
6387
6485
|
}
|
|
6388
6486
|
destroy() {
|
|
6389
|
-
this
|
|
6390
|
-
this.
|
|
6391
|
-
this.
|
|
6392
|
-
this
|
|
6487
|
+
this.#array = [];
|
|
6488
|
+
this.#pool.length = 0;
|
|
6489
|
+
this.#particleBuckets.clear();
|
|
6490
|
+
this.#zBuckets = [];
|
|
6393
6491
|
this.checkParticlePositionPlugins = [];
|
|
6394
|
-
this
|
|
6395
|
-
this
|
|
6396
|
-
this
|
|
6397
|
-
this
|
|
6398
|
-
this
|
|
6492
|
+
this.#particleResetPlugins = [];
|
|
6493
|
+
this.#particleUpdatePlugins = [];
|
|
6494
|
+
this.#postUpdatePlugins = [];
|
|
6495
|
+
this.#postParticleUpdatePlugins = [];
|
|
6496
|
+
this.#updatePlugins = [];
|
|
6399
6497
|
}
|
|
6400
6498
|
drawParticles(delta) {
|
|
6401
|
-
for (let i = this.
|
|
6402
|
-
const bucket = this
|
|
6499
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
6500
|
+
const bucket = this.#zBuckets[i];
|
|
6403
6501
|
if (!bucket) {
|
|
6404
6502
|
continue;
|
|
6405
6503
|
}
|
|
@@ -6409,24 +6507,24 @@
|
|
|
6409
6507
|
}
|
|
6410
6508
|
}
|
|
6411
6509
|
filter(condition) {
|
|
6412
|
-
return this.
|
|
6510
|
+
return this.#array.filter(condition);
|
|
6413
6511
|
}
|
|
6414
6512
|
find(condition) {
|
|
6415
|
-
return this.
|
|
6513
|
+
return this.#array.find(condition);
|
|
6416
6514
|
}
|
|
6417
6515
|
get(index) {
|
|
6418
|
-
return this
|
|
6516
|
+
return this.#array[index];
|
|
6419
6517
|
}
|
|
6420
6518
|
async init() {
|
|
6421
|
-
const container = this
|
|
6519
|
+
const container = this.#container, options = container.actualOptions;
|
|
6422
6520
|
this.checkParticlePositionPlugins = [];
|
|
6423
|
-
this
|
|
6424
|
-
this
|
|
6425
|
-
this
|
|
6426
|
-
this
|
|
6427
|
-
this
|
|
6428
|
-
this.
|
|
6429
|
-
this
|
|
6521
|
+
this.#updatePlugins = [];
|
|
6522
|
+
this.#particleUpdatePlugins = [];
|
|
6523
|
+
this.#postUpdatePlugins = [];
|
|
6524
|
+
this.#particleResetPlugins = [];
|
|
6525
|
+
this.#postParticleUpdatePlugins = [];
|
|
6526
|
+
this.#particleBuckets.clear();
|
|
6527
|
+
this.#resetBuckets(container.zLayers);
|
|
6430
6528
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
6431
6529
|
for (const plugin of container.plugins) {
|
|
6432
6530
|
if (plugin.redrawInit) {
|
|
@@ -6436,26 +6534,26 @@
|
|
|
6436
6534
|
this.checkParticlePositionPlugins.push(plugin);
|
|
6437
6535
|
}
|
|
6438
6536
|
if (plugin.update) {
|
|
6439
|
-
this.
|
|
6537
|
+
this.#updatePlugins.push(plugin);
|
|
6440
6538
|
}
|
|
6441
6539
|
if (plugin.particleUpdate) {
|
|
6442
|
-
this.
|
|
6540
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
6443
6541
|
}
|
|
6444
6542
|
if (plugin.postUpdate) {
|
|
6445
|
-
this.
|
|
6543
|
+
this.#postUpdatePlugins.push(plugin);
|
|
6446
6544
|
}
|
|
6447
6545
|
if (plugin.particleReset) {
|
|
6448
|
-
this.
|
|
6546
|
+
this.#particleResetPlugins.push(plugin);
|
|
6449
6547
|
}
|
|
6450
6548
|
if (plugin.postParticleUpdate) {
|
|
6451
|
-
this.
|
|
6549
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
6452
6550
|
}
|
|
6453
6551
|
}
|
|
6454
|
-
await this.
|
|
6455
|
-
for (const drawer of this.
|
|
6552
|
+
await this.#container.initDrawersAndUpdaters();
|
|
6553
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
6456
6554
|
await drawer.init?.(container);
|
|
6457
6555
|
}
|
|
6458
|
-
for (const drawer of this.
|
|
6556
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
6459
6557
|
await drawer.init?.(container);
|
|
6460
6558
|
}
|
|
6461
6559
|
let handled = false;
|
|
@@ -6489,10 +6587,10 @@
|
|
|
6489
6587
|
async redraw() {
|
|
6490
6588
|
this.clear();
|
|
6491
6589
|
await this.init();
|
|
6492
|
-
this.
|
|
6590
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
6493
6591
|
}
|
|
6494
6592
|
remove(particle, group, override) {
|
|
6495
|
-
this.removeAt(this.
|
|
6593
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
6496
6594
|
}
|
|
6497
6595
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
6498
6596
|
if (index < minIndex || index > this.count) {
|
|
@@ -6500,7 +6598,7 @@
|
|
|
6500
6598
|
}
|
|
6501
6599
|
let deleted = 0;
|
|
6502
6600
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
6503
|
-
if (this
|
|
6601
|
+
if (this.#removeParticle(i, group, override)) {
|
|
6504
6602
|
i--;
|
|
6505
6603
|
deleted++;
|
|
6506
6604
|
}
|
|
@@ -6510,9 +6608,9 @@
|
|
|
6510
6608
|
this.removeAt(minIndex, quantity, group);
|
|
6511
6609
|
}
|
|
6512
6610
|
setDensity() {
|
|
6513
|
-
const options = this.
|
|
6611
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
6514
6612
|
let pluginsCount = 0;
|
|
6515
|
-
for (const plugin of this.
|
|
6613
|
+
for (const plugin of this.#container.plugins) {
|
|
6516
6614
|
if (plugin.particlesDensityCount) {
|
|
6517
6615
|
pluginsCount += plugin.particlesDensityCount();
|
|
6518
6616
|
}
|
|
@@ -6522,51 +6620,51 @@
|
|
|
6522
6620
|
if (!groupData) {
|
|
6523
6621
|
continue;
|
|
6524
6622
|
}
|
|
6525
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
6526
|
-
this
|
|
6623
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
6624
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
6527
6625
|
}
|
|
6528
|
-
this
|
|
6626
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
6529
6627
|
}
|
|
6530
6628
|
setResizeFactor(factor) {
|
|
6531
|
-
this
|
|
6629
|
+
this.#resizeFactor = factor;
|
|
6532
6630
|
}
|
|
6533
6631
|
update(delta) {
|
|
6534
6632
|
this.grid.clear();
|
|
6535
|
-
for (const plugin of this
|
|
6633
|
+
for (const plugin of this.#updatePlugins) {
|
|
6536
6634
|
plugin.update?.(delta);
|
|
6537
6635
|
}
|
|
6538
|
-
const particlesToDelete = this
|
|
6539
|
-
for (const plugin of this
|
|
6636
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
6637
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
6540
6638
|
plugin.postUpdate?.(delta);
|
|
6541
6639
|
}
|
|
6542
|
-
this
|
|
6640
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
6543
6641
|
if (particlesToDelete.size) {
|
|
6544
6642
|
for (const particle of particlesToDelete) {
|
|
6545
6643
|
this.remove(particle);
|
|
6546
6644
|
}
|
|
6547
6645
|
}
|
|
6548
|
-
|
|
6646
|
+
this.#resizeFactor = undefined;
|
|
6549
6647
|
}
|
|
6550
|
-
|
|
6551
|
-
this.
|
|
6648
|
+
#addToPool = (...particles) => {
|
|
6649
|
+
this.#pool.push(...particles);
|
|
6552
6650
|
};
|
|
6553
|
-
|
|
6651
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
6554
6652
|
const numberOptions = options.number;
|
|
6555
6653
|
if (!numberOptions.density.enable) {
|
|
6556
6654
|
if (group === undefined) {
|
|
6557
|
-
this
|
|
6655
|
+
this.#limit = numberOptions.limit.value;
|
|
6558
6656
|
}
|
|
6559
6657
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
6560
|
-
this.
|
|
6658
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
6561
6659
|
}
|
|
6562
6660
|
return;
|
|
6563
6661
|
}
|
|
6564
|
-
const densityFactor = this
|
|
6662
|
+
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);
|
|
6565
6663
|
if (group === undefined) {
|
|
6566
|
-
this
|
|
6664
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
6567
6665
|
}
|
|
6568
6666
|
else {
|
|
6569
|
-
this.
|
|
6667
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
6570
6668
|
}
|
|
6571
6669
|
if (particlesCount < particlesNumber) {
|
|
6572
6670
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -6575,18 +6673,18 @@
|
|
|
6575
6673
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
6576
6674
|
}
|
|
6577
6675
|
};
|
|
6578
|
-
|
|
6676
|
+
#createBuckets = (zLayers) => {
|
|
6579
6677
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6580
6678
|
return Array.from({ length: bucketCount }, () => []);
|
|
6581
6679
|
};
|
|
6582
|
-
|
|
6583
|
-
const maxBucketIndex = this.
|
|
6680
|
+
#getBucketIndex = (zIndex) => {
|
|
6681
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
6584
6682
|
if (maxBucketIndex <= minIndex) {
|
|
6585
6683
|
return minIndex;
|
|
6586
6684
|
}
|
|
6587
6685
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
6588
6686
|
};
|
|
6589
|
-
|
|
6687
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
6590
6688
|
let start = minIndex, end = bucket.length;
|
|
6591
6689
|
while (start < end) {
|
|
6592
6690
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -6603,8 +6701,8 @@
|
|
|
6603
6701
|
}
|
|
6604
6702
|
return start;
|
|
6605
6703
|
};
|
|
6606
|
-
|
|
6607
|
-
const container = this
|
|
6704
|
+
#initDensityFactor = densityOptions => {
|
|
6705
|
+
const container = this.#container;
|
|
6608
6706
|
if (!densityOptions.enable) {
|
|
6609
6707
|
return defaultDensityFactor;
|
|
6610
6708
|
}
|
|
@@ -6614,82 +6712,82 @@
|
|
|
6614
6712
|
}
|
|
6615
6713
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
6616
6714
|
};
|
|
6617
|
-
|
|
6618
|
-
const bucketIndex = this
|
|
6715
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6716
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6619
6717
|
if (!bucket) {
|
|
6620
6718
|
return;
|
|
6621
6719
|
}
|
|
6622
|
-
bucket.splice(this
|
|
6623
|
-
this.
|
|
6720
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6721
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
6624
6722
|
};
|
|
6625
|
-
|
|
6626
|
-
const particle = this
|
|
6723
|
+
#removeParticle = (index, group, override) => {
|
|
6724
|
+
const particle = this.#array[index];
|
|
6627
6725
|
if (!particle) {
|
|
6628
6726
|
return false;
|
|
6629
6727
|
}
|
|
6630
6728
|
if (particle.group !== group) {
|
|
6631
6729
|
return false;
|
|
6632
6730
|
}
|
|
6633
|
-
this.
|
|
6634
|
-
this
|
|
6731
|
+
this.#array.splice(index, deleteCount);
|
|
6732
|
+
this.#removeParticleFromBucket(particle);
|
|
6635
6733
|
particle.destroy(override);
|
|
6636
|
-
this.
|
|
6734
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
6637
6735
|
particle,
|
|
6638
6736
|
});
|
|
6639
|
-
this
|
|
6737
|
+
this.#addToPool(particle);
|
|
6640
6738
|
return true;
|
|
6641
6739
|
};
|
|
6642
|
-
|
|
6643
|
-
const bucketIndex = this.
|
|
6740
|
+
#removeParticleFromBucket = (particle) => {
|
|
6741
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6644
6742
|
if (!bucket) {
|
|
6645
|
-
this.
|
|
6743
|
+
this.#particleBuckets.delete(particle.id);
|
|
6646
6744
|
return;
|
|
6647
6745
|
}
|
|
6648
|
-
const particleIndex = this
|
|
6746
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
6649
6747
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
6650
|
-
this.
|
|
6748
|
+
this.#particleBuckets.delete(particle.id);
|
|
6651
6749
|
return;
|
|
6652
6750
|
}
|
|
6653
6751
|
bucket.splice(particleIndex, deleteCount);
|
|
6654
|
-
this.
|
|
6752
|
+
this.#particleBuckets.delete(particle.id);
|
|
6655
6753
|
};
|
|
6656
|
-
|
|
6754
|
+
#resetBuckets = (zLayers) => {
|
|
6657
6755
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6658
|
-
if (this.
|
|
6659
|
-
this
|
|
6756
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6757
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
6660
6758
|
return;
|
|
6661
6759
|
}
|
|
6662
|
-
for (const bucket of this
|
|
6760
|
+
for (const bucket of this.#zBuckets) {
|
|
6663
6761
|
bucket.length = minIndex;
|
|
6664
6762
|
}
|
|
6665
6763
|
};
|
|
6666
|
-
|
|
6667
|
-
const newBucketIndex = this
|
|
6764
|
+
#updateParticleBucket = (particle) => {
|
|
6765
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
6668
6766
|
if (currentBucketIndex === undefined) {
|
|
6669
|
-
this
|
|
6767
|
+
this.#insertParticleIntoBucket(particle);
|
|
6670
6768
|
return;
|
|
6671
6769
|
}
|
|
6672
6770
|
if (currentBucketIndex === newBucketIndex) {
|
|
6673
6771
|
return;
|
|
6674
6772
|
}
|
|
6675
|
-
const currentBucket = this
|
|
6773
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
6676
6774
|
if (currentBucket) {
|
|
6677
|
-
const particleIndex = this
|
|
6775
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
6678
6776
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
6679
6777
|
currentBucket.splice(particleIndex, deleteCount);
|
|
6680
6778
|
}
|
|
6681
6779
|
}
|
|
6682
|
-
const newBucket = this
|
|
6780
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
6683
6781
|
if (!newBucket) {
|
|
6684
|
-
this.
|
|
6782
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6685
6783
|
return;
|
|
6686
6784
|
}
|
|
6687
|
-
newBucket.splice(this
|
|
6688
|
-
this.
|
|
6785
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6786
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6689
6787
|
};
|
|
6690
|
-
|
|
6691
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
6692
|
-
for (const particle of this
|
|
6788
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6789
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6790
|
+
for (const particle of this.#array) {
|
|
6693
6791
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
6694
6792
|
particle.position.x *= resizeFactor.width;
|
|
6695
6793
|
particle.position.y *= resizeFactor.height;
|
|
@@ -6697,10 +6795,10 @@
|
|
|
6697
6795
|
particle.initialPosition.y *= resizeFactor.height;
|
|
6698
6796
|
}
|
|
6699
6797
|
particle.ignoresResizeRatio = false;
|
|
6700
|
-
for (const plugin of this
|
|
6798
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
6701
6799
|
plugin.particleReset?.(particle);
|
|
6702
6800
|
}
|
|
6703
|
-
for (const plugin of this
|
|
6801
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
6704
6802
|
if (particle.destroyed) {
|
|
6705
6803
|
break;
|
|
6706
6804
|
}
|
|
@@ -6714,36 +6812,36 @@
|
|
|
6714
6812
|
}
|
|
6715
6813
|
return particlesToDelete;
|
|
6716
6814
|
};
|
|
6717
|
-
|
|
6718
|
-
for (const particle of this
|
|
6815
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6816
|
+
for (const particle of this.#array) {
|
|
6719
6817
|
if (particle.destroyed) {
|
|
6720
6818
|
particlesToDelete.add(particle);
|
|
6721
6819
|
continue;
|
|
6722
6820
|
}
|
|
6723
|
-
for (const updater of this.
|
|
6821
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6724
6822
|
updater.update(particle, delta);
|
|
6725
6823
|
}
|
|
6726
6824
|
if (!particle.spawning) {
|
|
6727
|
-
for (const plugin of this
|
|
6825
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6728
6826
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6729
6827
|
}
|
|
6730
6828
|
}
|
|
6731
|
-
this
|
|
6829
|
+
this.#updateParticleBucket(particle);
|
|
6732
6830
|
}
|
|
6733
6831
|
};
|
|
6734
6832
|
}
|
|
6735
6833
|
|
|
6736
6834
|
class Retina {
|
|
6737
|
-
container;
|
|
6738
6835
|
pixelRatio;
|
|
6739
6836
|
reduceFactor;
|
|
6837
|
+
#container;
|
|
6740
6838
|
constructor(container) {
|
|
6741
|
-
this
|
|
6839
|
+
this.#container = container;
|
|
6742
6840
|
this.pixelRatio = defaultRatio;
|
|
6743
6841
|
this.reduceFactor = defaultReduceFactor;
|
|
6744
6842
|
}
|
|
6745
6843
|
init() {
|
|
6746
|
-
const container = this
|
|
6844
|
+
const container = this.#container, options = container.actualOptions;
|
|
6747
6845
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6748
6846
|
this.reduceFactor = defaultReduceFactor;
|
|
6749
6847
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6757,7 +6855,6 @@
|
|
|
6757
6855
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6758
6856
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6759
6857
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6760
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6761
6858
|
const maxDistance = props.maxDistance;
|
|
6762
6859
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6763
6860
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6795,73 +6892,73 @@
|
|
|
6795
6892
|
shapeDrawers;
|
|
6796
6893
|
started;
|
|
6797
6894
|
zLayers;
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6895
|
+
#delay;
|
|
6896
|
+
#delayTimeout;
|
|
6897
|
+
#delta = { value: 0, factor: 0 };
|
|
6898
|
+
#dispatchCallback;
|
|
6899
|
+
#drawAnimationFrame;
|
|
6900
|
+
#duration;
|
|
6901
|
+
#eventListeners;
|
|
6902
|
+
#firstStart;
|
|
6903
|
+
#initialSourceOptions;
|
|
6904
|
+
#lastFrameTime;
|
|
6905
|
+
#lifeTime;
|
|
6906
|
+
#onDestroy;
|
|
6907
|
+
#options;
|
|
6908
|
+
#paused;
|
|
6909
|
+
#pluginManager;
|
|
6910
|
+
#smooth;
|
|
6911
|
+
#sourceOptions;
|
|
6815
6912
|
constructor(params) {
|
|
6816
6913
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6817
|
-
this
|
|
6818
|
-
this
|
|
6819
|
-
this
|
|
6914
|
+
this.#pluginManager = pluginManager;
|
|
6915
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6916
|
+
this.#onDestroy = onDestroy;
|
|
6820
6917
|
this.id = Symbol(id);
|
|
6821
6918
|
this.fpsLimit = 120;
|
|
6822
6919
|
this.hdr = false;
|
|
6823
|
-
this
|
|
6824
|
-
this
|
|
6825
|
-
this
|
|
6826
|
-
this
|
|
6827
|
-
this
|
|
6920
|
+
this.#smooth = false;
|
|
6921
|
+
this.#delay = 0;
|
|
6922
|
+
this.#duration = 0;
|
|
6923
|
+
this.#lifeTime = 0;
|
|
6924
|
+
this.#firstStart = true;
|
|
6828
6925
|
this.started = false;
|
|
6829
6926
|
this.destroyed = false;
|
|
6830
|
-
this
|
|
6831
|
-
this
|
|
6927
|
+
this.#paused = true;
|
|
6928
|
+
this.#lastFrameTime = 0;
|
|
6832
6929
|
this.zLayers = 100;
|
|
6833
6930
|
this.pageHidden = false;
|
|
6834
|
-
this
|
|
6835
|
-
this
|
|
6931
|
+
this.#sourceOptions = sourceOptions;
|
|
6932
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6836
6933
|
this.effectDrawers = new Map();
|
|
6837
6934
|
this.shapeDrawers = new Map();
|
|
6838
6935
|
this.particleUpdaters = [];
|
|
6839
6936
|
this.retina = new Retina(this);
|
|
6840
|
-
this.canvas = new CanvasManager(this
|
|
6841
|
-
this.particles = new ParticlesManager(this
|
|
6937
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6938
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6842
6939
|
this.plugins = [];
|
|
6843
6940
|
this.particleDestroyedPlugins = [];
|
|
6844
6941
|
this.particleCreatedPlugins = [];
|
|
6845
6942
|
this.particlePositionPlugins = [];
|
|
6846
|
-
this
|
|
6847
|
-
this.actualOptions = loadContainerOptions(this
|
|
6848
|
-
this
|
|
6943
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6944
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6945
|
+
this.#eventListeners = new EventListeners(this);
|
|
6849
6946
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6850
6947
|
}
|
|
6851
6948
|
get animationStatus() {
|
|
6852
|
-
return !this
|
|
6949
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6853
6950
|
}
|
|
6854
6951
|
get options() {
|
|
6855
|
-
return this
|
|
6952
|
+
return this.#options;
|
|
6856
6953
|
}
|
|
6857
6954
|
get sourceOptions() {
|
|
6858
|
-
return this
|
|
6955
|
+
return this.#sourceOptions;
|
|
6859
6956
|
}
|
|
6860
6957
|
addLifeTime(value) {
|
|
6861
|
-
this
|
|
6958
|
+
this.#lifeTime += value;
|
|
6862
6959
|
}
|
|
6863
6960
|
alive() {
|
|
6864
|
-
return !this
|
|
6961
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6865
6962
|
}
|
|
6866
6963
|
destroy(remove = true) {
|
|
6867
6964
|
if (!guardCheck(this)) {
|
|
@@ -6883,13 +6980,13 @@
|
|
|
6883
6980
|
this.shapeDrawers = new Map();
|
|
6884
6981
|
this.particleUpdaters = [];
|
|
6885
6982
|
this.plugins.length = 0;
|
|
6886
|
-
this.
|
|
6983
|
+
this.#pluginManager.clearPlugins(this);
|
|
6887
6984
|
this.destroyed = true;
|
|
6888
|
-
this
|
|
6985
|
+
this.#onDestroy(remove);
|
|
6889
6986
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6890
6987
|
}
|
|
6891
6988
|
dispatchEvent(type, data) {
|
|
6892
|
-
this
|
|
6989
|
+
this.#dispatchCallback(type, {
|
|
6893
6990
|
container: this,
|
|
6894
6991
|
data,
|
|
6895
6992
|
});
|
|
@@ -6899,12 +6996,12 @@
|
|
|
6899
6996
|
return;
|
|
6900
6997
|
}
|
|
6901
6998
|
let refreshTime = force;
|
|
6902
|
-
this
|
|
6999
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6903
7000
|
if (refreshTime) {
|
|
6904
|
-
this
|
|
7001
|
+
this.#lastFrameTime = undefined;
|
|
6905
7002
|
refreshTime = false;
|
|
6906
7003
|
}
|
|
6907
|
-
this
|
|
7004
|
+
this.#nextFrame(timestamp);
|
|
6908
7005
|
});
|
|
6909
7006
|
}
|
|
6910
7007
|
async export(type, options = {}) {
|
|
@@ -6926,7 +7023,7 @@
|
|
|
6926
7023
|
return;
|
|
6927
7024
|
}
|
|
6928
7025
|
const allContainerPlugins = new Map();
|
|
6929
|
-
for (const plugin of this.
|
|
7026
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6930
7027
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6931
7028
|
if (containerPlugin.preInit) {
|
|
6932
7029
|
await containerPlugin.preInit();
|
|
@@ -6934,8 +7031,8 @@
|
|
|
6934
7031
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6935
7032
|
}
|
|
6936
7033
|
await this.initDrawersAndUpdaters();
|
|
6937
|
-
this
|
|
6938
|
-
this.actualOptions = loadContainerOptions(this
|
|
7034
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
7035
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6939
7036
|
this.plugins.length = 0;
|
|
6940
7037
|
this.particleDestroyedPlugins.length = 0;
|
|
6941
7038
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6962,11 +7059,11 @@
|
|
|
6962
7059
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6963
7060
|
this.hdr = hdr;
|
|
6964
7061
|
this.zLayers = zLayers;
|
|
6965
|
-
this
|
|
6966
|
-
this
|
|
6967
|
-
this
|
|
7062
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
7063
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
7064
|
+
this.#lifeTime = 0;
|
|
6968
7065
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6969
|
-
this
|
|
7066
|
+
this.#smooth = smooth;
|
|
6970
7067
|
for (const plugin of this.plugins) {
|
|
6971
7068
|
await plugin.init?.();
|
|
6972
7069
|
}
|
|
@@ -6979,7 +7076,7 @@
|
|
|
6979
7076
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6980
7077
|
}
|
|
6981
7078
|
async initDrawersAndUpdaters() {
|
|
6982
|
-
const pluginManager = this
|
|
7079
|
+
const pluginManager = this.#pluginManager;
|
|
6983
7080
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6984
7081
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6985
7082
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6988,18 +7085,18 @@
|
|
|
6988
7085
|
if (!guardCheck(this)) {
|
|
6989
7086
|
return;
|
|
6990
7087
|
}
|
|
6991
|
-
if (this
|
|
6992
|
-
cancelAnimation(this
|
|
6993
|
-
|
|
7088
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
7089
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
7090
|
+
this.#drawAnimationFrame = undefined;
|
|
6994
7091
|
}
|
|
6995
|
-
if (this
|
|
7092
|
+
if (this.#paused) {
|
|
6996
7093
|
return;
|
|
6997
7094
|
}
|
|
6998
7095
|
for (const plugin of this.plugins) {
|
|
6999
7096
|
plugin.pause?.();
|
|
7000
7097
|
}
|
|
7001
7098
|
if (!this.pageHidden) {
|
|
7002
|
-
this
|
|
7099
|
+
this.#paused = true;
|
|
7003
7100
|
}
|
|
7004
7101
|
this.dispatchEvent(EventType.containerPaused);
|
|
7005
7102
|
}
|
|
@@ -7007,13 +7104,13 @@
|
|
|
7007
7104
|
if (!guardCheck(this)) {
|
|
7008
7105
|
return;
|
|
7009
7106
|
}
|
|
7010
|
-
const needsUpdate = this
|
|
7011
|
-
if (this
|
|
7012
|
-
this
|
|
7107
|
+
const needsUpdate = this.#paused || force;
|
|
7108
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
7109
|
+
this.#firstStart = false;
|
|
7013
7110
|
return;
|
|
7014
7111
|
}
|
|
7015
|
-
if (this
|
|
7016
|
-
this
|
|
7112
|
+
if (this.#paused) {
|
|
7113
|
+
this.#paused = false;
|
|
7017
7114
|
}
|
|
7018
7115
|
if (needsUpdate) {
|
|
7019
7116
|
for (const plugin of this.plugins) {
|
|
@@ -7036,10 +7133,10 @@
|
|
|
7036
7133
|
if (!guardCheck(this)) {
|
|
7037
7134
|
return;
|
|
7038
7135
|
}
|
|
7039
|
-
this
|
|
7040
|
-
this
|
|
7041
|
-
this
|
|
7042
|
-
this.actualOptions = loadContainerOptions(this
|
|
7136
|
+
this.#initialSourceOptions = sourceOptions;
|
|
7137
|
+
this.#sourceOptions = sourceOptions;
|
|
7138
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
7139
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
7043
7140
|
return this.refresh();
|
|
7044
7141
|
}
|
|
7045
7142
|
async start() {
|
|
@@ -7050,7 +7147,7 @@
|
|
|
7050
7147
|
this.started = true;
|
|
7051
7148
|
await new Promise(resolve => {
|
|
7052
7149
|
const start = async () => {
|
|
7053
|
-
this.
|
|
7150
|
+
this.#eventListeners.addListeners();
|
|
7054
7151
|
for (const plugin of this.plugins) {
|
|
7055
7152
|
await plugin.start?.();
|
|
7056
7153
|
}
|
|
@@ -7058,20 +7155,20 @@
|
|
|
7058
7155
|
this.play();
|
|
7059
7156
|
resolve();
|
|
7060
7157
|
};
|
|
7061
|
-
this
|
|
7158
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
7062
7159
|
});
|
|
7063
7160
|
}
|
|
7064
7161
|
stop() {
|
|
7065
7162
|
if (!guardCheck(this) || !this.started) {
|
|
7066
7163
|
return;
|
|
7067
7164
|
}
|
|
7068
|
-
if (this
|
|
7069
|
-
clearTimeout(this
|
|
7070
|
-
|
|
7165
|
+
if (this.#delayTimeout) {
|
|
7166
|
+
clearTimeout(this.#delayTimeout);
|
|
7167
|
+
this.#delayTimeout = undefined;
|
|
7071
7168
|
}
|
|
7072
|
-
this
|
|
7169
|
+
this.#firstStart = true;
|
|
7073
7170
|
this.started = false;
|
|
7074
|
-
this.
|
|
7171
|
+
this.#eventListeners.removeListeners();
|
|
7075
7172
|
this.pause();
|
|
7076
7173
|
this.particles.clear();
|
|
7077
7174
|
this.canvas.stop();
|
|
@@ -7081,7 +7178,7 @@
|
|
|
7081
7178
|
this.particleCreatedPlugins.length = 0;
|
|
7082
7179
|
this.particleDestroyedPlugins.length = 0;
|
|
7083
7180
|
this.particlePositionPlugins.length = 0;
|
|
7084
|
-
this
|
|
7181
|
+
this.#sourceOptions = this.#options;
|
|
7085
7182
|
this.dispatchEvent(EventType.containerStopped);
|
|
7086
7183
|
}
|
|
7087
7184
|
updateActualOptions() {
|
|
@@ -7093,23 +7190,23 @@
|
|
|
7093
7190
|
}
|
|
7094
7191
|
return refresh;
|
|
7095
7192
|
}
|
|
7096
|
-
|
|
7193
|
+
#nextFrame = (timestamp) => {
|
|
7097
7194
|
try {
|
|
7098
|
-
if (!this
|
|
7099
|
-
this
|
|
7100
|
-
timestamp < this
|
|
7195
|
+
if (!this.#smooth &&
|
|
7196
|
+
this.#lastFrameTime !== undefined &&
|
|
7197
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
7101
7198
|
this.draw(false);
|
|
7102
7199
|
return;
|
|
7103
7200
|
}
|
|
7104
|
-
this
|
|
7105
|
-
updateDelta(this
|
|
7106
|
-
this.addLifeTime(this.
|
|
7107
|
-
this
|
|
7108
|
-
if (this.
|
|
7201
|
+
this.#lastFrameTime ??= timestamp;
|
|
7202
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
7203
|
+
this.addLifeTime(this.#delta.value);
|
|
7204
|
+
this.#lastFrameTime = timestamp;
|
|
7205
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
7109
7206
|
this.draw(false);
|
|
7110
7207
|
return;
|
|
7111
7208
|
}
|
|
7112
|
-
this.canvas.render.drawParticles(this
|
|
7209
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
7113
7210
|
if (!this.alive()) {
|
|
7114
7211
|
this.destroy();
|
|
7115
7212
|
return;
|
|
@@ -7130,10 +7227,10 @@
|
|
|
7130
7227
|
});
|
|
7131
7228
|
|
|
7132
7229
|
class BlendPluginInstance {
|
|
7133
|
-
|
|
7134
|
-
|
|
7230
|
+
#container;
|
|
7231
|
+
#defaultCompositeValue;
|
|
7135
7232
|
constructor(container) {
|
|
7136
|
-
this
|
|
7233
|
+
this.#container = container;
|
|
7137
7234
|
}
|
|
7138
7235
|
drawParticleCleanup(context, particle) {
|
|
7139
7236
|
if (!particle.options.blend?.enable) {
|
|
@@ -7150,14 +7247,14 @@
|
|
|
7150
7247
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
7151
7248
|
}
|
|
7152
7249
|
drawSettingsCleanup(context) {
|
|
7153
|
-
if (!this
|
|
7250
|
+
if (!this.#defaultCompositeValue) {
|
|
7154
7251
|
return;
|
|
7155
7252
|
}
|
|
7156
|
-
context.globalCompositeOperation = this
|
|
7253
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
7157
7254
|
}
|
|
7158
7255
|
drawSettingsSetup(context) {
|
|
7159
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
7160
|
-
this
|
|
7256
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
7257
|
+
this.#defaultCompositeValue = previousComposite;
|
|
7161
7258
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
7162
7259
|
}
|
|
7163
7260
|
}
|
|
@@ -7300,11 +7397,11 @@
|
|
|
7300
7397
|
class MovePluginInstance {
|
|
7301
7398
|
availablePathGenerators;
|
|
7302
7399
|
pathGenerators;
|
|
7303
|
-
|
|
7304
|
-
|
|
7400
|
+
#container;
|
|
7401
|
+
#pluginManager;
|
|
7305
7402
|
constructor(pluginManager, container) {
|
|
7306
|
-
this
|
|
7307
|
-
this
|
|
7403
|
+
this.#pluginManager = pluginManager;
|
|
7404
|
+
this.#container = container;
|
|
7308
7405
|
this.availablePathGenerators = new Map();
|
|
7309
7406
|
this.pathGenerators = new Map();
|
|
7310
7407
|
}
|
|
@@ -7335,7 +7432,7 @@
|
|
|
7335
7432
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
7336
7433
|
inverse: gravityOptions.inverse,
|
|
7337
7434
|
};
|
|
7338
|
-
initSpin(this
|
|
7435
|
+
initSpin(this.#container, particle);
|
|
7339
7436
|
}
|
|
7340
7437
|
particleDestroyed(particle) {
|
|
7341
7438
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -7346,7 +7443,7 @@
|
|
|
7346
7443
|
if (!moveOptions.enable) {
|
|
7347
7444
|
return;
|
|
7348
7445
|
}
|
|
7349
|
-
const container = this
|
|
7446
|
+
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;
|
|
7350
7447
|
if (moveOptions.spin.enable) {
|
|
7351
7448
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
7352
7449
|
}
|
|
@@ -7356,18 +7453,18 @@
|
|
|
7356
7453
|
applyDistance(particle);
|
|
7357
7454
|
}
|
|
7358
7455
|
preInit() {
|
|
7359
|
-
return this
|
|
7456
|
+
return this.#init();
|
|
7360
7457
|
}
|
|
7361
7458
|
redrawInit() {
|
|
7362
|
-
return this
|
|
7459
|
+
return this.#init();
|
|
7363
7460
|
}
|
|
7364
7461
|
update() {
|
|
7365
7462
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
7366
7463
|
pathGenerator.update();
|
|
7367
7464
|
}
|
|
7368
7465
|
}
|
|
7369
|
-
async
|
|
7370
|
-
const availablePathGenerators = await this.
|
|
7466
|
+
async #init() {
|
|
7467
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
7371
7468
|
if (!availablePathGenerators) {
|
|
7372
7469
|
return;
|
|
7373
7470
|
}
|
|
@@ -7386,65 +7483,65 @@
|
|
|
7386
7483
|
|
|
7387
7484
|
const touchDelay = 500;
|
|
7388
7485
|
class InteractivityEventListeners {
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7486
|
+
#canPush = true;
|
|
7487
|
+
#clickPositionPlugins;
|
|
7488
|
+
#container;
|
|
7489
|
+
#handlers;
|
|
7490
|
+
#interactionManager;
|
|
7491
|
+
#touches;
|
|
7395
7492
|
constructor(container, interactionManager) {
|
|
7396
|
-
this
|
|
7397
|
-
this
|
|
7398
|
-
this
|
|
7399
|
-
this
|
|
7400
|
-
this
|
|
7493
|
+
this.#container = container;
|
|
7494
|
+
this.#clickPositionPlugins = [];
|
|
7495
|
+
this.#interactionManager = interactionManager;
|
|
7496
|
+
this.#touches = new Map();
|
|
7497
|
+
this.#handlers = {
|
|
7401
7498
|
mouseDown: () => {
|
|
7402
|
-
this
|
|
7499
|
+
this.#mouseDown();
|
|
7403
7500
|
},
|
|
7404
7501
|
mouseLeave: () => {
|
|
7405
|
-
this
|
|
7502
|
+
this.#mouseTouchFinish();
|
|
7406
7503
|
},
|
|
7407
7504
|
mouseMove: (e) => {
|
|
7408
|
-
this
|
|
7505
|
+
this.#mouseTouchMove(e);
|
|
7409
7506
|
},
|
|
7410
7507
|
mouseUp: (e) => {
|
|
7411
|
-
this
|
|
7508
|
+
this.#mouseTouchClick(e);
|
|
7412
7509
|
},
|
|
7413
7510
|
touchStart: (e) => {
|
|
7414
|
-
this
|
|
7511
|
+
this.#touchStart(e);
|
|
7415
7512
|
},
|
|
7416
7513
|
touchMove: (e) => {
|
|
7417
|
-
this
|
|
7514
|
+
this.#mouseTouchMove(e);
|
|
7418
7515
|
},
|
|
7419
7516
|
touchEnd: (e) => {
|
|
7420
|
-
this
|
|
7517
|
+
this.#touchEnd(e);
|
|
7421
7518
|
},
|
|
7422
7519
|
touchCancel: (e) => {
|
|
7423
|
-
this
|
|
7520
|
+
this.#touchEnd(e);
|
|
7424
7521
|
},
|
|
7425
7522
|
touchEndClick: (e) => {
|
|
7426
|
-
this
|
|
7523
|
+
this.#touchEndClick(e);
|
|
7427
7524
|
},
|
|
7428
7525
|
visibilityChange: () => {
|
|
7429
|
-
this
|
|
7526
|
+
this.#handleVisibilityChange();
|
|
7430
7527
|
},
|
|
7431
7528
|
};
|
|
7432
7529
|
}
|
|
7433
7530
|
addListeners() {
|
|
7434
|
-
this
|
|
7531
|
+
this.#manageListeners(true);
|
|
7435
7532
|
}
|
|
7436
7533
|
init() {
|
|
7437
|
-
this.
|
|
7438
|
-
for (const plugin of this.
|
|
7439
|
-
this.
|
|
7534
|
+
this.#clickPositionPlugins.length = 0;
|
|
7535
|
+
for (const plugin of this.#container.plugins.filter(p => !!p.clickPositionValid)) {
|
|
7536
|
+
this.#clickPositionPlugins.push(plugin);
|
|
7440
7537
|
}
|
|
7441
7538
|
}
|
|
7442
7539
|
removeListeners() {
|
|
7443
|
-
this
|
|
7540
|
+
this.#manageListeners(false);
|
|
7444
7541
|
}
|
|
7445
|
-
|
|
7446
|
-
const container = this
|
|
7447
|
-
if (this
|
|
7542
|
+
#doMouseTouchClick = e => {
|
|
7543
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions;
|
|
7544
|
+
if (this.#canPush) {
|
|
7448
7545
|
const mouseInteractivity = interactionManager.interactivityData.mouse, mousePos = mouseInteractivity.position;
|
|
7449
7546
|
if (!mousePos) {
|
|
7450
7547
|
return;
|
|
@@ -7461,15 +7558,15 @@
|
|
|
7461
7558
|
}
|
|
7462
7559
|
if (e.type === "touchend") {
|
|
7463
7560
|
setTimeout(() => {
|
|
7464
|
-
this
|
|
7561
|
+
this.#mouseTouchFinish();
|
|
7465
7562
|
}, touchDelay);
|
|
7466
7563
|
}
|
|
7467
7564
|
};
|
|
7468
|
-
|
|
7469
|
-
this
|
|
7565
|
+
#handleVisibilityChange = () => {
|
|
7566
|
+
this.#mouseTouchFinish();
|
|
7470
7567
|
};
|
|
7471
|
-
|
|
7472
|
-
const handlers = this
|
|
7568
|
+
#manageInteractivityListeners = add => {
|
|
7569
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivityEl = interactionManager.interactivityData.element;
|
|
7473
7570
|
if (!interactivityEl) {
|
|
7474
7571
|
return;
|
|
7475
7572
|
}
|
|
@@ -7500,8 +7597,8 @@
|
|
|
7500
7597
|
manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
|
|
7501
7598
|
manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
|
7502
7599
|
};
|
|
7503
|
-
|
|
7504
|
-
const handlers = this
|
|
7600
|
+
#manageListeners = add => {
|
|
7601
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, detectType = options.interactivity?.detectsOn, canvasEl = container.canvas.domElement;
|
|
7505
7602
|
if (detectType === InteractivityDetect.window) {
|
|
7506
7603
|
interactionManager.interactivityData.element = safeDocument();
|
|
7507
7604
|
}
|
|
@@ -7511,35 +7608,35 @@
|
|
|
7511
7608
|
else {
|
|
7512
7609
|
interactionManager.interactivityData.element = canvasEl;
|
|
7513
7610
|
}
|
|
7514
|
-
this
|
|
7611
|
+
this.#manageInteractivityListeners(add);
|
|
7515
7612
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
7516
7613
|
};
|
|
7517
|
-
|
|
7518
|
-
const { interactivityData } = this
|
|
7614
|
+
#mouseDown = () => {
|
|
7615
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
7519
7616
|
mouse.clicking = true;
|
|
7520
7617
|
mouse.downPosition = mouse.position;
|
|
7521
7618
|
};
|
|
7522
|
-
|
|
7523
|
-
const container = this
|
|
7619
|
+
#mouseTouchClick = e => {
|
|
7620
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
|
|
7524
7621
|
mouse.inside = true;
|
|
7525
7622
|
let handled = false;
|
|
7526
7623
|
const mousePosition = mouse.position;
|
|
7527
7624
|
if (!mousePosition || !options.interactivity?.events.onClick.enable) {
|
|
7528
7625
|
return;
|
|
7529
7626
|
}
|
|
7530
|
-
for (const plugin of this
|
|
7627
|
+
for (const plugin of this.#clickPositionPlugins) {
|
|
7531
7628
|
handled = plugin.clickPositionValid?.(mousePosition) ?? false;
|
|
7532
7629
|
if (handled) {
|
|
7533
7630
|
break;
|
|
7534
7631
|
}
|
|
7535
7632
|
}
|
|
7536
7633
|
if (!handled) {
|
|
7537
|
-
this
|
|
7634
|
+
this.#doMouseTouchClick(e);
|
|
7538
7635
|
}
|
|
7539
7636
|
mouse.clicking = false;
|
|
7540
7637
|
};
|
|
7541
|
-
|
|
7542
|
-
const { interactivityData } = this
|
|
7638
|
+
#mouseTouchFinish = () => {
|
|
7639
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
7543
7640
|
delete mouse.position;
|
|
7544
7641
|
delete mouse.clickPosition;
|
|
7545
7642
|
delete mouse.downPosition;
|
|
@@ -7547,15 +7644,15 @@
|
|
|
7547
7644
|
mouse.inside = false;
|
|
7548
7645
|
mouse.clicking = false;
|
|
7549
7646
|
};
|
|
7550
|
-
|
|
7551
|
-
const container = this
|
|
7647
|
+
#mouseTouchMove = e => {
|
|
7648
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivity = interactionManager.interactivityData, canvasEl = container.canvas.domElement;
|
|
7552
7649
|
if (!interactivity.element) {
|
|
7553
7650
|
return;
|
|
7554
7651
|
}
|
|
7555
7652
|
interactivity.mouse.inside = true;
|
|
7556
7653
|
let pos;
|
|
7557
7654
|
if (e.type.startsWith("pointer")) {
|
|
7558
|
-
this
|
|
7655
|
+
this.#canPush = true;
|
|
7559
7656
|
const mouseEvent = e;
|
|
7560
7657
|
if (interactivity.element === safeDocument()) {
|
|
7561
7658
|
if (canvasEl) {
|
|
@@ -7590,7 +7687,7 @@
|
|
|
7590
7687
|
}
|
|
7591
7688
|
}
|
|
7592
7689
|
else {
|
|
7593
|
-
this
|
|
7690
|
+
this.#canPush = e.type !== "touchmove";
|
|
7594
7691
|
if (canvasEl) {
|
|
7595
7692
|
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
|
|
7596
7693
|
if (!lastTouch) {
|
|
@@ -7610,60 +7707,60 @@
|
|
|
7610
7707
|
interactivity.mouse.position = pos;
|
|
7611
7708
|
interactivity.status = mouseMoveEvent;
|
|
7612
7709
|
};
|
|
7613
|
-
|
|
7710
|
+
#touchEnd = e => {
|
|
7614
7711
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
7615
7712
|
for (const touch of touches) {
|
|
7616
|
-
this.
|
|
7713
|
+
this.#touches.delete(touch.identifier);
|
|
7617
7714
|
}
|
|
7618
|
-
this
|
|
7715
|
+
this.#mouseTouchFinish();
|
|
7619
7716
|
};
|
|
7620
|
-
|
|
7717
|
+
#touchEndClick = e => {
|
|
7621
7718
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
7622
7719
|
for (const touch of touches) {
|
|
7623
|
-
this.
|
|
7720
|
+
this.#touches.delete(touch.identifier);
|
|
7624
7721
|
}
|
|
7625
|
-
this
|
|
7722
|
+
this.#mouseTouchClick(e);
|
|
7626
7723
|
};
|
|
7627
|
-
|
|
7724
|
+
#touchStart = e => {
|
|
7628
7725
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
7629
7726
|
for (const touch of touches) {
|
|
7630
|
-
this.
|
|
7727
|
+
this.#touches.set(touch.identifier, performance.now());
|
|
7631
7728
|
}
|
|
7632
|
-
this
|
|
7729
|
+
this.#mouseTouchMove(e);
|
|
7633
7730
|
};
|
|
7634
7731
|
}
|
|
7635
7732
|
|
|
7636
7733
|
const clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0;
|
|
7637
7734
|
class InteractionManager {
|
|
7638
|
-
container;
|
|
7639
7735
|
interactivityData;
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7736
|
+
#clickHandlers;
|
|
7737
|
+
#container;
|
|
7738
|
+
#eventListeners;
|
|
7739
|
+
#externalInteractors;
|
|
7740
|
+
#interactors;
|
|
7741
|
+
#intersectionObserver;
|
|
7742
|
+
#particleInteractors;
|
|
7743
|
+
#pluginManager;
|
|
7647
7744
|
constructor(pluginManager, container) {
|
|
7648
|
-
this
|
|
7649
|
-
this
|
|
7650
|
-
this
|
|
7651
|
-
this
|
|
7652
|
-
this
|
|
7653
|
-
this
|
|
7654
|
-
this
|
|
7745
|
+
this.#container = container;
|
|
7746
|
+
this.#pluginManager = pluginManager;
|
|
7747
|
+
this.#interactors = [];
|
|
7748
|
+
this.#externalInteractors = [];
|
|
7749
|
+
this.#particleInteractors = [];
|
|
7750
|
+
this.#clickHandlers = new Map();
|
|
7751
|
+
this.#eventListeners = new InteractivityEventListeners(container, this);
|
|
7655
7752
|
this.interactivityData = {
|
|
7656
7753
|
mouse: {
|
|
7657
7754
|
clicking: false,
|
|
7658
7755
|
inside: false,
|
|
7659
7756
|
},
|
|
7660
7757
|
};
|
|
7661
|
-
this
|
|
7662
|
-
this
|
|
7758
|
+
this.#intersectionObserver = safeIntersectionObserver(entries => {
|
|
7759
|
+
this.#intersectionManager(entries);
|
|
7663
7760
|
});
|
|
7664
7761
|
}
|
|
7665
7762
|
addClickHandler(callback) {
|
|
7666
|
-
const
|
|
7763
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
7667
7764
|
if (container.destroyed) {
|
|
7668
7765
|
return;
|
|
7669
7766
|
}
|
|
@@ -7725,119 +7822,119 @@
|
|
|
7725
7822
|
touchMoved = false;
|
|
7726
7823
|
};
|
|
7727
7824
|
let touched = false, touchMoved = false;
|
|
7728
|
-
this.
|
|
7729
|
-
this.
|
|
7730
|
-
this.
|
|
7731
|
-
this.
|
|
7732
|
-
this.
|
|
7733
|
-
for (const [key, handler] of this
|
|
7825
|
+
this.#clickHandlers.set(clickEvent, clickHandler);
|
|
7826
|
+
this.#clickHandlers.set(touchStartEvent, touchStartHandler);
|
|
7827
|
+
this.#clickHandlers.set(touchMoveEvent, touchMoveHandler);
|
|
7828
|
+
this.#clickHandlers.set(touchEndEvent, touchEndHandler);
|
|
7829
|
+
this.#clickHandlers.set(touchCancelEvent, touchCancelHandler);
|
|
7830
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7734
7831
|
el.addEventListener(key, handler);
|
|
7735
7832
|
}
|
|
7736
7833
|
}
|
|
7737
7834
|
addListeners() {
|
|
7738
|
-
this.
|
|
7835
|
+
this.#eventListeners.addListeners();
|
|
7739
7836
|
}
|
|
7740
7837
|
clearClickHandlers() {
|
|
7741
|
-
const
|
|
7838
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
7742
7839
|
if (container.destroyed) {
|
|
7743
7840
|
return;
|
|
7744
7841
|
}
|
|
7745
|
-
for (const [key, handler] of this
|
|
7842
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7746
7843
|
interactivityData.element?.removeEventListener(key, handler);
|
|
7747
7844
|
}
|
|
7748
|
-
this.
|
|
7845
|
+
this.#clickHandlers.clear();
|
|
7749
7846
|
}
|
|
7750
7847
|
externalInteract(delta) {
|
|
7751
|
-
for (const interactor of this
|
|
7752
|
-
const
|
|
7848
|
+
for (const interactor of this.#externalInteractors) {
|
|
7849
|
+
const interactivityData = this.interactivityData;
|
|
7753
7850
|
if (interactor.isEnabled(interactivityData)) {
|
|
7754
7851
|
interactor.interact(interactivityData, delta);
|
|
7755
7852
|
}
|
|
7756
7853
|
}
|
|
7757
7854
|
}
|
|
7758
7855
|
handleClickMode(mode) {
|
|
7759
|
-
if (this
|
|
7856
|
+
if (this.#container.destroyed) {
|
|
7760
7857
|
return;
|
|
7761
7858
|
}
|
|
7762
|
-
const
|
|
7763
|
-
for (const interactor of this
|
|
7859
|
+
const interactivityData = this.interactivityData;
|
|
7860
|
+
for (const interactor of this.#externalInteractors) {
|
|
7764
7861
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
7765
7862
|
}
|
|
7766
7863
|
}
|
|
7767
7864
|
init() {
|
|
7768
|
-
this.
|
|
7769
|
-
for (const interactor of this
|
|
7865
|
+
this.#eventListeners.init();
|
|
7866
|
+
for (const interactor of this.#interactors) {
|
|
7770
7867
|
switch (interactor.type) {
|
|
7771
7868
|
case InteractorType.external:
|
|
7772
|
-
this.
|
|
7869
|
+
this.#externalInteractors.push(interactor);
|
|
7773
7870
|
break;
|
|
7774
7871
|
case InteractorType.particles:
|
|
7775
|
-
this.
|
|
7872
|
+
this.#particleInteractors.push(interactor);
|
|
7776
7873
|
break;
|
|
7777
7874
|
}
|
|
7778
7875
|
interactor.init();
|
|
7779
7876
|
}
|
|
7780
7877
|
}
|
|
7781
7878
|
async initInteractors() {
|
|
7782
|
-
const interactors = await this.
|
|
7879
|
+
const interactors = await this.#pluginManager.getInteractors?.(this.#container, true);
|
|
7783
7880
|
if (!interactors) {
|
|
7784
7881
|
return;
|
|
7785
7882
|
}
|
|
7786
|
-
this
|
|
7787
|
-
this
|
|
7788
|
-
this
|
|
7883
|
+
this.#interactors = interactors;
|
|
7884
|
+
this.#externalInteractors = [];
|
|
7885
|
+
this.#particleInteractors = [];
|
|
7789
7886
|
}
|
|
7790
7887
|
particlesInteract(particle, delta) {
|
|
7791
|
-
const
|
|
7792
|
-
for (const interactor of this
|
|
7888
|
+
const interactivityData = this.interactivityData;
|
|
7889
|
+
for (const interactor of this.#externalInteractors) {
|
|
7793
7890
|
interactor.clear(particle, delta);
|
|
7794
7891
|
}
|
|
7795
|
-
for (const interactor of this
|
|
7892
|
+
for (const interactor of this.#particleInteractors) {
|
|
7796
7893
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7797
7894
|
interactor.interact(particle, interactivityData, delta);
|
|
7798
7895
|
}
|
|
7799
7896
|
}
|
|
7800
7897
|
}
|
|
7801
7898
|
removeListeners() {
|
|
7802
|
-
this.
|
|
7899
|
+
this.#eventListeners.removeListeners();
|
|
7803
7900
|
}
|
|
7804
7901
|
reset(particle) {
|
|
7805
|
-
const
|
|
7806
|
-
for (const interactor of this
|
|
7902
|
+
const interactivityData = this.interactivityData;
|
|
7903
|
+
for (const interactor of this.#externalInteractors) {
|
|
7807
7904
|
if (interactor.isEnabled(interactivityData)) {
|
|
7808
7905
|
interactor.reset(interactivityData, particle);
|
|
7809
7906
|
}
|
|
7810
7907
|
}
|
|
7811
|
-
for (const interactor of this
|
|
7908
|
+
for (const interactor of this.#particleInteractors) {
|
|
7812
7909
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7813
7910
|
interactor.reset(interactivityData, particle);
|
|
7814
7911
|
}
|
|
7815
7912
|
}
|
|
7816
7913
|
}
|
|
7817
7914
|
startObserving() {
|
|
7818
|
-
const
|
|
7819
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7820
|
-
this.
|
|
7915
|
+
const interactivityData = this.interactivityData;
|
|
7916
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7917
|
+
this.#intersectionObserver.observe(interactivityData.element);
|
|
7821
7918
|
}
|
|
7822
7919
|
}
|
|
7823
7920
|
stopObserving() {
|
|
7824
|
-
const
|
|
7825
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7826
|
-
this.
|
|
7921
|
+
const interactivityData = this.interactivityData;
|
|
7922
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7923
|
+
this.#intersectionObserver.unobserve(interactivityData.element);
|
|
7827
7924
|
}
|
|
7828
7925
|
}
|
|
7829
7926
|
updateMaxDistance() {
|
|
7830
7927
|
let maxTotalDistance = 0;
|
|
7831
|
-
for (const interactor of this
|
|
7928
|
+
for (const interactor of this.#interactors) {
|
|
7832
7929
|
if (interactor.maxDistance > maxTotalDistance) {
|
|
7833
7930
|
maxTotalDistance = interactor.maxDistance;
|
|
7834
7931
|
}
|
|
7835
7932
|
}
|
|
7836
|
-
const container = this
|
|
7933
|
+
const container = this.#container;
|
|
7837
7934
|
container.particles.grid.setCellSize(maxTotalDistance * container.retina.pixelRatio);
|
|
7838
7935
|
}
|
|
7839
|
-
|
|
7840
|
-
const
|
|
7936
|
+
#intersectionManager = entries => {
|
|
7937
|
+
const container = this.#container;
|
|
7841
7938
|
if (container.destroyed || !container.actualOptions.pauseOnOutsideViewport) {
|
|
7842
7939
|
return;
|
|
7843
7940
|
}
|
|
@@ -7857,13 +7954,13 @@
|
|
|
7857
7954
|
|
|
7858
7955
|
class InteractivityPluginInstance {
|
|
7859
7956
|
interactionManager;
|
|
7860
|
-
|
|
7861
|
-
|
|
7957
|
+
#container;
|
|
7958
|
+
#pluginManager;
|
|
7862
7959
|
constructor(pluginManager, container) {
|
|
7863
|
-
this
|
|
7864
|
-
this
|
|
7960
|
+
this.#container = container;
|
|
7961
|
+
this.#pluginManager = pluginManager;
|
|
7865
7962
|
this.interactionManager = new InteractionManager(pluginManager, container);
|
|
7866
|
-
this.
|
|
7963
|
+
this.#container.addClickHandler = (callback) => {
|
|
7867
7964
|
this.interactionManager.addClickHandler(callback);
|
|
7868
7965
|
};
|
|
7869
7966
|
}
|
|
@@ -7875,11 +7972,11 @@
|
|
|
7875
7972
|
}
|
|
7876
7973
|
destroy() {
|
|
7877
7974
|
this.clearClickHandlers();
|
|
7878
|
-
this.
|
|
7975
|
+
this.#pluginManager.interactors?.delete(this.#container);
|
|
7879
7976
|
}
|
|
7880
7977
|
particleCreated(particle) {
|
|
7881
|
-
const interactivityParticle = particle, interactivity = new Interactivity(this
|
|
7882
|
-
interactivity.load(this.
|
|
7978
|
+
const interactivityParticle = particle, interactivity = new Interactivity(this.#pluginManager, this.#container);
|
|
7979
|
+
interactivity.load(this.#container.actualOptions.interactivity);
|
|
7883
7980
|
interactivity.load(interactivityParticle.options.interactivity);
|
|
7884
7981
|
interactivityParticle.interactivity = interactivity;
|
|
7885
7982
|
}
|
|
@@ -7919,12 +8016,12 @@
|
|
|
7919
8016
|
|
|
7920
8017
|
const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
|
|
7921
8018
|
class MotionPluginInstance {
|
|
7922
|
-
|
|
8019
|
+
#container;
|
|
7923
8020
|
constructor(container) {
|
|
7924
|
-
this
|
|
8021
|
+
this.#container = container;
|
|
7925
8022
|
}
|
|
7926
8023
|
async init() {
|
|
7927
|
-
const container = this
|
|
8024
|
+
const container = this.#container, options = container.actualOptions.motion;
|
|
7928
8025
|
if (!(options && (options.disable || options.reduce.value))) {
|
|
7929
8026
|
container.retina.reduceFactor = 1;
|
|
7930
8027
|
return;
|
|
@@ -7934,10 +8031,10 @@
|
|
|
7934
8031
|
container.retina.reduceFactor = defaultFactor;
|
|
7935
8032
|
return;
|
|
7936
8033
|
}
|
|
7937
|
-
this
|
|
8034
|
+
this.#handleMotionChange(mediaQuery);
|
|
7938
8035
|
const handleChange = () => {
|
|
7939
8036
|
void (async () => {
|
|
7940
|
-
this
|
|
8037
|
+
this.#handleMotionChange(mediaQuery);
|
|
7941
8038
|
try {
|
|
7942
8039
|
await container.refresh();
|
|
7943
8040
|
}
|
|
@@ -7948,8 +8045,8 @@
|
|
|
7948
8045
|
mediaQuery.addEventListener("change", handleChange);
|
|
7949
8046
|
await Promise.resolve();
|
|
7950
8047
|
}
|
|
7951
|
-
|
|
7952
|
-
const container = this
|
|
8048
|
+
#handleMotionChange = mediaQuery => {
|
|
8049
|
+
const container = this.#container, motion = container.actualOptions.motion;
|
|
7953
8050
|
if (!motion) {
|
|
7954
8051
|
return;
|
|
7955
8052
|
}
|