@tsparticles/preset-fountain 4.0.5 → 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
|
}
|
|
@@ -721,38 +721,38 @@
|
|
|
721
721
|
}
|
|
722
722
|
|
|
723
723
|
class EventDispatcher {
|
|
724
|
-
|
|
724
|
+
#listeners;
|
|
725
725
|
constructor() {
|
|
726
|
-
this
|
|
726
|
+
this.#listeners = new Map();
|
|
727
727
|
}
|
|
728
728
|
addEventListener(type, listener) {
|
|
729
729
|
this.removeEventListener(type, listener);
|
|
730
|
-
let arr = this.
|
|
730
|
+
let arr = this.#listeners.get(type);
|
|
731
731
|
if (!arr) {
|
|
732
732
|
arr = [];
|
|
733
|
-
this.
|
|
733
|
+
this.#listeners.set(type, arr);
|
|
734
734
|
}
|
|
735
735
|
arr.push(listener);
|
|
736
736
|
}
|
|
737
737
|
dispatchEvent(type, args) {
|
|
738
|
-
const listeners = this.
|
|
738
|
+
const listeners = this.#listeners.get(type);
|
|
739
739
|
listeners?.forEach(handler => {
|
|
740
740
|
handler(args);
|
|
741
741
|
});
|
|
742
742
|
}
|
|
743
743
|
hasEventListener(type) {
|
|
744
|
-
return !!this.
|
|
744
|
+
return !!this.#listeners.get(type);
|
|
745
745
|
}
|
|
746
746
|
removeAllEventListeners(type) {
|
|
747
747
|
if (!type) {
|
|
748
|
-
this
|
|
748
|
+
this.#listeners = new Map();
|
|
749
749
|
}
|
|
750
750
|
else {
|
|
751
|
-
this.
|
|
751
|
+
this.#listeners.delete(type);
|
|
752
752
|
}
|
|
753
753
|
}
|
|
754
754
|
removeEventListener(type, listener) {
|
|
755
|
-
const arr = this.
|
|
755
|
+
const arr = this.#listeners.get(type);
|
|
756
756
|
if (!arr) {
|
|
757
757
|
return;
|
|
758
758
|
}
|
|
@@ -761,7 +761,7 @@
|
|
|
761
761
|
return;
|
|
762
762
|
}
|
|
763
763
|
if (length === deleteCount) {
|
|
764
|
-
this.
|
|
764
|
+
this.#listeners.delete(type);
|
|
765
765
|
}
|
|
766
766
|
else {
|
|
767
767
|
arr.splice(idx, deleteCount);
|
|
@@ -799,19 +799,19 @@
|
|
|
799
799
|
presets = new Map();
|
|
800
800
|
shapeDrawers = new Map();
|
|
801
801
|
updaters = new Map();
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
802
|
+
#allLoadersSet = new Set();
|
|
803
|
+
#configs = new Map();
|
|
804
|
+
#engine;
|
|
805
|
+
#executedSet = new Set();
|
|
806
|
+
#initialized = false;
|
|
807
|
+
#isRunningLoaders = false;
|
|
808
|
+
#loadPromises = new Set();
|
|
809
809
|
constructor(engine) {
|
|
810
|
-
this
|
|
810
|
+
this.#engine = engine;
|
|
811
811
|
}
|
|
812
812
|
get configs() {
|
|
813
813
|
const res = {};
|
|
814
|
-
for (const [name, config] of this
|
|
814
|
+
for (const [name, config] of this.#configs) {
|
|
815
815
|
res[name] = config;
|
|
816
816
|
}
|
|
817
817
|
return res;
|
|
@@ -821,8 +821,8 @@
|
|
|
821
821
|
}
|
|
822
822
|
addConfig(config) {
|
|
823
823
|
const key = config.key ?? config.name ?? "default";
|
|
824
|
-
this.
|
|
825
|
-
this.
|
|
824
|
+
this.#configs.set(key, config);
|
|
825
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
826
826
|
}
|
|
827
827
|
addEasing(name, easing) {
|
|
828
828
|
if (this.easingFunctions.get(name)) {
|
|
@@ -883,21 +883,21 @@
|
|
|
883
883
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
884
884
|
}
|
|
885
885
|
async init() {
|
|
886
|
-
if (this
|
|
886
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
887
887
|
return;
|
|
888
888
|
}
|
|
889
|
-
this
|
|
890
|
-
this
|
|
891
|
-
this
|
|
889
|
+
this.#isRunningLoaders = true;
|
|
890
|
+
this.#executedSet = new Set();
|
|
891
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
892
892
|
try {
|
|
893
|
-
for (const loader of this
|
|
894
|
-
await this
|
|
893
|
+
for (const loader of this.#allLoadersSet) {
|
|
894
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
895
895
|
}
|
|
896
896
|
}
|
|
897
897
|
finally {
|
|
898
|
-
this.
|
|
899
|
-
this
|
|
900
|
-
this
|
|
898
|
+
this.#loadPromises.clear();
|
|
899
|
+
this.#isRunningLoaders = false;
|
|
900
|
+
this.#initialized = true;
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -908,24 +908,24 @@
|
|
|
908
908
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
909
909
|
}
|
|
910
910
|
async register(...loaders) {
|
|
911
|
-
if (this
|
|
911
|
+
if (this.#initialized) {
|
|
912
912
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
913
913
|
}
|
|
914
914
|
for (const loader of loaders) {
|
|
915
|
-
if (this
|
|
916
|
-
await this
|
|
915
|
+
if (this.#isRunningLoaders) {
|
|
916
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
917
917
|
}
|
|
918
918
|
else {
|
|
919
|
-
this.
|
|
919
|
+
this.#loadPromises.add(loader);
|
|
920
920
|
}
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
|
-
async
|
|
923
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
924
924
|
if (executed.has(loader))
|
|
925
925
|
return;
|
|
926
926
|
executed.add(loader);
|
|
927
927
|
allLoaders.add(loader);
|
|
928
|
-
await loader(this
|
|
928
|
+
await loader(this.#engine);
|
|
929
929
|
}
|
|
930
930
|
}
|
|
931
931
|
|
|
@@ -1005,17 +1005,17 @@
|
|
|
1005
1005
|
};
|
|
1006
1006
|
class Engine {
|
|
1007
1007
|
pluginManager = new PluginManager(this);
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1008
|
+
#domArray = [];
|
|
1009
|
+
#eventDispatcher = new EventDispatcher();
|
|
1010
|
+
#initialized = false;
|
|
1011
1011
|
get items() {
|
|
1012
|
-
return this
|
|
1012
|
+
return this.#domArray;
|
|
1013
1013
|
}
|
|
1014
1014
|
get version() {
|
|
1015
|
-
return "4.0
|
|
1015
|
+
return "4.1.0";
|
|
1016
1016
|
}
|
|
1017
1017
|
addEventListener(type, listener) {
|
|
1018
|
-
this.
|
|
1018
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1019
1019
|
}
|
|
1020
1020
|
checkVersion(pluginVersion) {
|
|
1021
1021
|
if (this.version === pluginVersion) {
|
|
@@ -1024,17 +1024,17 @@
|
|
|
1024
1024
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1025
1025
|
}
|
|
1026
1026
|
dispatchEvent(type, args) {
|
|
1027
|
-
this.
|
|
1027
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1028
1028
|
}
|
|
1029
1029
|
async init() {
|
|
1030
|
-
if (this
|
|
1030
|
+
if (this.#initialized) {
|
|
1031
1031
|
return;
|
|
1032
1032
|
}
|
|
1033
1033
|
await this.pluginManager.init();
|
|
1034
|
-
this
|
|
1034
|
+
this.#initialized = true;
|
|
1035
1035
|
}
|
|
1036
1036
|
item(index) {
|
|
1037
|
-
const
|
|
1037
|
+
const items = this.items, item = items[index];
|
|
1038
1038
|
if (item?.destroyed) {
|
|
1039
1039
|
items.splice(index, removeDeleteCount);
|
|
1040
1040
|
return;
|
|
@@ -1088,7 +1088,7 @@
|
|
|
1088
1088
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1089
1089
|
}
|
|
1090
1090
|
removeEventListener(type, listener) {
|
|
1091
|
-
this.
|
|
1091
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
1094
|
|
|
@@ -1859,43 +1859,6 @@
|
|
|
1859
1859
|
}
|
|
1860
1860
|
}
|
|
1861
1861
|
|
|
1862
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1863
|
-
destroy;
|
|
1864
|
-
constructor() {
|
|
1865
|
-
super();
|
|
1866
|
-
this.destroy = DestroyType.none;
|
|
1867
|
-
this.speed = 2;
|
|
1868
|
-
}
|
|
1869
|
-
load(data) {
|
|
1870
|
-
super.load(data);
|
|
1871
|
-
if (isNull(data)) {
|
|
1872
|
-
return;
|
|
1873
|
-
}
|
|
1874
|
-
if (data.destroy !== undefined) {
|
|
1875
|
-
this.destroy = data.destroy;
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1881
|
-
animation;
|
|
1882
|
-
constructor() {
|
|
1883
|
-
super();
|
|
1884
|
-
this.animation = new OpacityAnimation();
|
|
1885
|
-
this.value = 1;
|
|
1886
|
-
}
|
|
1887
|
-
load(data) {
|
|
1888
|
-
if (isNull(data)) {
|
|
1889
|
-
return;
|
|
1890
|
-
}
|
|
1891
|
-
super.load(data);
|
|
1892
|
-
const animation = data.animation;
|
|
1893
|
-
if (animation !== undefined) {
|
|
1894
|
-
this.animation.load(animation);
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
1862
|
class Stroke {
|
|
1900
1863
|
color;
|
|
1901
1864
|
opacity;
|
|
@@ -2063,43 +2026,6 @@
|
|
|
2063
2026
|
}
|
|
2064
2027
|
}
|
|
2065
2028
|
|
|
2066
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2067
|
-
destroy;
|
|
2068
|
-
constructor() {
|
|
2069
|
-
super();
|
|
2070
|
-
this.destroy = DestroyType.none;
|
|
2071
|
-
this.speed = 5;
|
|
2072
|
-
}
|
|
2073
|
-
load(data) {
|
|
2074
|
-
super.load(data);
|
|
2075
|
-
if (isNull(data)) {
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
if (data.destroy !== undefined) {
|
|
2079
|
-
this.destroy = data.destroy;
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2085
|
-
animation;
|
|
2086
|
-
constructor() {
|
|
2087
|
-
super();
|
|
2088
|
-
this.animation = new SizeAnimation();
|
|
2089
|
-
this.value = 3;
|
|
2090
|
-
}
|
|
2091
|
-
load(data) {
|
|
2092
|
-
super.load(data);
|
|
2093
|
-
if (isNull(data)) {
|
|
2094
|
-
return;
|
|
2095
|
-
}
|
|
2096
|
-
const animation = data.animation;
|
|
2097
|
-
if (animation !== undefined) {
|
|
2098
|
-
this.animation.load(animation);
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
2029
|
class ZIndex extends ValueWithRandom {
|
|
2104
2030
|
opacityRate;
|
|
2105
2031
|
sizeRate;
|
|
@@ -2133,24 +2059,21 @@
|
|
|
2133
2059
|
groups;
|
|
2134
2060
|
move;
|
|
2135
2061
|
number;
|
|
2136
|
-
opacity;
|
|
2137
2062
|
paint;
|
|
2138
2063
|
palette;
|
|
2139
2064
|
reduceDuplicates;
|
|
2140
2065
|
shape;
|
|
2141
|
-
size;
|
|
2142
2066
|
zIndex;
|
|
2143
|
-
|
|
2144
|
-
|
|
2067
|
+
#container;
|
|
2068
|
+
#pluginManager;
|
|
2145
2069
|
constructor(pluginManager, container) {
|
|
2146
|
-
this
|
|
2147
|
-
this
|
|
2070
|
+
this.#pluginManager = pluginManager;
|
|
2071
|
+
this.#container = container;
|
|
2148
2072
|
this.bounce = new ParticlesBounce();
|
|
2149
2073
|
this.effect = new Effect();
|
|
2150
2074
|
this.groups = {};
|
|
2151
2075
|
this.move = new Move();
|
|
2152
2076
|
this.number = new ParticlesNumber();
|
|
2153
|
-
this.opacity = new Opacity();
|
|
2154
2077
|
this.paint = new Paint();
|
|
2155
2078
|
this.paint.color = new AnimatableColor();
|
|
2156
2079
|
this.paint.color.value = "#fff";
|
|
@@ -2158,7 +2081,6 @@
|
|
|
2158
2081
|
this.paint.fill.enable = true;
|
|
2159
2082
|
this.reduceDuplicates = false;
|
|
2160
2083
|
this.shape = new Shape();
|
|
2161
|
-
this.size = new Size();
|
|
2162
2084
|
this.zIndex = new ZIndex();
|
|
2163
2085
|
}
|
|
2164
2086
|
load(data) {
|
|
@@ -2167,7 +2089,7 @@
|
|
|
2167
2089
|
}
|
|
2168
2090
|
if (data.palette) {
|
|
2169
2091
|
this.palette = data.palette;
|
|
2170
|
-
this
|
|
2092
|
+
this.#importPalette(this.palette);
|
|
2171
2093
|
}
|
|
2172
2094
|
if (data.groups !== undefined) {
|
|
2173
2095
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2187,7 +2109,6 @@
|
|
|
2187
2109
|
this.effect.load(data.effect);
|
|
2188
2110
|
this.move.load(data.move);
|
|
2189
2111
|
this.number.load(data.number);
|
|
2190
|
-
this.opacity.load(data.opacity);
|
|
2191
2112
|
const paintToLoad = data.paint;
|
|
2192
2113
|
if (paintToLoad) {
|
|
2193
2114
|
if (isArray(paintToLoad)) {
|
|
@@ -2206,15 +2127,14 @@
|
|
|
2206
2127
|
}
|
|
2207
2128
|
}
|
|
2208
2129
|
this.shape.load(data.shape);
|
|
2209
|
-
this.size.load(data.size);
|
|
2210
2130
|
this.zIndex.load(data.zIndex);
|
|
2211
|
-
if (this
|
|
2212
|
-
for (const plugin of this.
|
|
2131
|
+
if (this.#container) {
|
|
2132
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2213
2133
|
if (plugin.loadParticlesOptions) {
|
|
2214
|
-
plugin.loadParticlesOptions(this
|
|
2134
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2215
2135
|
}
|
|
2216
2136
|
}
|
|
2217
|
-
const updaters = this.
|
|
2137
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2218
2138
|
if (updaters) {
|
|
2219
2139
|
for (const updater of updaters) {
|
|
2220
2140
|
if (updater.loadOptions) {
|
|
@@ -2224,8 +2144,8 @@
|
|
|
2224
2144
|
}
|
|
2225
2145
|
}
|
|
2226
2146
|
}
|
|
2227
|
-
|
|
2228
|
-
const paletteData = this.
|
|
2147
|
+
#importPalette = (palette) => {
|
|
2148
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2229
2149
|
if (!paletteData) {
|
|
2230
2150
|
return;
|
|
2231
2151
|
}
|
|
@@ -2304,11 +2224,11 @@
|
|
|
2304
2224
|
smooth;
|
|
2305
2225
|
style;
|
|
2306
2226
|
zLayers;
|
|
2307
|
-
|
|
2308
|
-
|
|
2227
|
+
#container;
|
|
2228
|
+
#pluginManager;
|
|
2309
2229
|
constructor(pluginManager, container) {
|
|
2310
|
-
this
|
|
2311
|
-
this
|
|
2230
|
+
this.#pluginManager = pluginManager;
|
|
2231
|
+
this.#container = container;
|
|
2312
2232
|
this.autoPlay = true;
|
|
2313
2233
|
this.background = new Background();
|
|
2314
2234
|
this.clear = true;
|
|
@@ -2319,7 +2239,7 @@
|
|
|
2319
2239
|
this.duration = 0;
|
|
2320
2240
|
this.fpsLimit = 120;
|
|
2321
2241
|
this.hdr = true;
|
|
2322
|
-
this.particles = loadParticlesOptions(this
|
|
2242
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2323
2243
|
this.pauseOnBlur = true;
|
|
2324
2244
|
this.pauseOnOutsideViewport = true;
|
|
2325
2245
|
this.resize = new ResizeEvent();
|
|
@@ -2334,12 +2254,12 @@
|
|
|
2334
2254
|
if (data.preset !== undefined) {
|
|
2335
2255
|
this.preset = data.preset;
|
|
2336
2256
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2337
|
-
this
|
|
2257
|
+
this.#importPreset(preset);
|
|
2338
2258
|
});
|
|
2339
2259
|
}
|
|
2340
2260
|
if (data.palette !== undefined) {
|
|
2341
2261
|
this.palette = data.palette;
|
|
2342
|
-
this
|
|
2262
|
+
this.#importPalette(this.palette);
|
|
2343
2263
|
}
|
|
2344
2264
|
if (data.autoPlay !== undefined) {
|
|
2345
2265
|
this.autoPlay = data.autoPlay;
|
|
@@ -2393,12 +2313,12 @@
|
|
|
2393
2313
|
if (data.smooth !== undefined) {
|
|
2394
2314
|
this.smooth = data.smooth;
|
|
2395
2315
|
}
|
|
2396
|
-
this.
|
|
2397
|
-
plugin.loadOptions(this
|
|
2316
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2317
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2398
2318
|
});
|
|
2399
2319
|
}
|
|
2400
|
-
|
|
2401
|
-
const paletteData = this.
|
|
2320
|
+
#importPalette = palette => {
|
|
2321
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2402
2322
|
if (!paletteData) {
|
|
2403
2323
|
return;
|
|
2404
2324
|
}
|
|
@@ -2415,8 +2335,8 @@
|
|
|
2415
2335
|
},
|
|
2416
2336
|
});
|
|
2417
2337
|
};
|
|
2418
|
-
|
|
2419
|
-
this.load(this.
|
|
2338
|
+
#importPreset = preset => {
|
|
2339
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2420
2340
|
};
|
|
2421
2341
|
}
|
|
2422
2342
|
|
|
@@ -2885,7 +2805,7 @@
|
|
|
2885
2805
|
}
|
|
2886
2806
|
|
|
2887
2807
|
async function loadBlendPlugin(engine) {
|
|
2888
|
-
engine.checkVersion("4.0
|
|
2808
|
+
engine.checkVersion("4.1.0");
|
|
2889
2809
|
await engine.pluginManager.register(e => {
|
|
2890
2810
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2891
2811
|
});
|
|
@@ -2922,7 +2842,7 @@
|
|
|
2922
2842
|
}
|
|
2923
2843
|
|
|
2924
2844
|
async function loadCircleShape(engine) {
|
|
2925
|
-
engine.checkVersion("4.0
|
|
2845
|
+
engine.checkVersion("4.1.0");
|
|
2926
2846
|
await engine.pluginManager.register(e => {
|
|
2927
2847
|
e.pluginManager.addShape(["circle"], () => {
|
|
2928
2848
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2943,15 +2863,15 @@
|
|
|
2943
2863
|
return input.startsWith("#");
|
|
2944
2864
|
}
|
|
2945
2865
|
handleColor(color) {
|
|
2946
|
-
return this
|
|
2866
|
+
return this.#parseString(color.value);
|
|
2947
2867
|
}
|
|
2948
2868
|
handleRangeColor(color) {
|
|
2949
|
-
return this
|
|
2869
|
+
return this.#parseString(color.value);
|
|
2950
2870
|
}
|
|
2951
2871
|
parseString(input) {
|
|
2952
|
-
return this
|
|
2872
|
+
return this.#parseString(input);
|
|
2953
2873
|
}
|
|
2954
|
-
|
|
2874
|
+
#parseString(hexColor) {
|
|
2955
2875
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
2956
2876
|
return;
|
|
2957
2877
|
}
|
|
@@ -2970,7 +2890,7 @@
|
|
|
2970
2890
|
}
|
|
2971
2891
|
|
|
2972
2892
|
async function loadHexColorPlugin(engine) {
|
|
2973
|
-
engine.checkVersion("4.0
|
|
2893
|
+
engine.checkVersion("4.1.0");
|
|
2974
2894
|
await engine.pluginManager.register(e => {
|
|
2975
2895
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2976
2896
|
});
|
|
@@ -3023,7 +2943,7 @@
|
|
|
3023
2943
|
}
|
|
3024
2944
|
|
|
3025
2945
|
async function loadHslColorPlugin(engine) {
|
|
3026
|
-
engine.checkVersion("4.0
|
|
2946
|
+
engine.checkVersion("4.1.0");
|
|
3027
2947
|
await engine.pluginManager.register(e => {
|
|
3028
2948
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3029
2949
|
});
|
|
@@ -3031,13 +2951,13 @@
|
|
|
3031
2951
|
|
|
3032
2952
|
class MovePlugin {
|
|
3033
2953
|
id = "move";
|
|
3034
|
-
|
|
2954
|
+
#pluginManager;
|
|
3035
2955
|
constructor(pluginManager) {
|
|
3036
|
-
this
|
|
2956
|
+
this.#pluginManager = pluginManager;
|
|
3037
2957
|
}
|
|
3038
2958
|
async getPlugin(container) {
|
|
3039
2959
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3040
|
-
return new MovePluginInstance(this
|
|
2960
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3041
2961
|
}
|
|
3042
2962
|
loadOptions() {
|
|
3043
2963
|
}
|
|
@@ -3047,7 +2967,7 @@
|
|
|
3047
2967
|
}
|
|
3048
2968
|
|
|
3049
2969
|
async function loadMovePlugin(engine) {
|
|
3050
|
-
engine.checkVersion("4.0
|
|
2970
|
+
engine.checkVersion("4.1.0");
|
|
3051
2971
|
await engine.pluginManager.register(e => {
|
|
3052
2972
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3053
2973
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3065,18 +2985,58 @@
|
|
|
3065
2985
|
});
|
|
3066
2986
|
}
|
|
3067
2987
|
|
|
2988
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
2989
|
+
destroy;
|
|
2990
|
+
constructor() {
|
|
2991
|
+
super();
|
|
2992
|
+
this.destroy = DestroyType.none;
|
|
2993
|
+
this.speed = 2;
|
|
2994
|
+
}
|
|
2995
|
+
load(data) {
|
|
2996
|
+
super.load(data);
|
|
2997
|
+
if (isNull(data)) {
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
if (data.destroy !== undefined) {
|
|
3001
|
+
this.destroy = data.destroy;
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3007
|
+
animation;
|
|
3008
|
+
constructor() {
|
|
3009
|
+
super();
|
|
3010
|
+
this.animation = new OpacityAnimation();
|
|
3011
|
+
this.value = 1;
|
|
3012
|
+
}
|
|
3013
|
+
load(data) {
|
|
3014
|
+
if (isNull(data)) {
|
|
3015
|
+
return;
|
|
3016
|
+
}
|
|
3017
|
+
super.load(data);
|
|
3018
|
+
const animation = data.animation;
|
|
3019
|
+
if (animation !== undefined) {
|
|
3020
|
+
this.animation.load(animation);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
|
|
3068
3025
|
class OpacityUpdater {
|
|
3069
|
-
container;
|
|
3026
|
+
#container;
|
|
3070
3027
|
constructor(container) {
|
|
3071
|
-
this
|
|
3028
|
+
this.#container = container;
|
|
3072
3029
|
}
|
|
3073
3030
|
init(particle) {
|
|
3074
3031
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3032
|
+
if (!opacityOptions) {
|
|
3033
|
+
return;
|
|
3034
|
+
}
|
|
3075
3035
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3076
3036
|
const opacityAnimation = opacityOptions.animation;
|
|
3077
3037
|
if (opacityAnimation.enable) {
|
|
3078
3038
|
particle.opacity.velocity =
|
|
3079
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3039
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3080
3040
|
if (!opacityAnimation.sync) {
|
|
3081
3041
|
particle.opacity.velocity *= getRandom();
|
|
3082
3042
|
}
|
|
@@ -3092,6 +3052,12 @@
|
|
|
3092
3052
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3093
3053
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3094
3054
|
}
|
|
3055
|
+
loadOptions(options, ...sources) {
|
|
3056
|
+
options.opacity ??= new Opacity();
|
|
3057
|
+
for (const source of sources) {
|
|
3058
|
+
options.opacity.load(source?.opacity);
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3095
3061
|
reset(particle) {
|
|
3096
3062
|
if (!particle.opacity) {
|
|
3097
3063
|
return;
|
|
@@ -3100,7 +3066,7 @@
|
|
|
3100
3066
|
particle.opacity.loops = 0;
|
|
3101
3067
|
}
|
|
3102
3068
|
update(particle, delta) {
|
|
3103
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3069
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3104
3070
|
return;
|
|
3105
3071
|
}
|
|
3106
3072
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3108,7 +3074,7 @@
|
|
|
3108
3074
|
}
|
|
3109
3075
|
|
|
3110
3076
|
async function loadOpacityUpdater(engine) {
|
|
3111
|
-
engine.checkVersion("4.0
|
|
3077
|
+
engine.checkVersion("4.1.0");
|
|
3112
3078
|
await engine.pluginManager.register(e => {
|
|
3113
3079
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3114
3080
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3130,10 +3096,9 @@
|
|
|
3130
3096
|
}
|
|
3131
3097
|
const velocity = data.particle.velocity.x;
|
|
3132
3098
|
let bounced = false;
|
|
3133
|
-
if (
|
|
3134
|
-
data.
|
|
3135
|
-
|
|
3136
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3099
|
+
if (data.outOfCanvas &&
|
|
3100
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3101
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3137
3102
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3138
3103
|
data.particle.velocity.x *= -newVelocity;
|
|
3139
3104
|
bounced = true;
|
|
@@ -3142,10 +3107,10 @@
|
|
|
3142
3107
|
return;
|
|
3143
3108
|
}
|
|
3144
3109
|
const minPos = data.offset.x + data.size;
|
|
3145
|
-
if (data.
|
|
3110
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3146
3111
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3147
3112
|
}
|
|
3148
|
-
else if (data.
|
|
3113
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3149
3114
|
data.particle.position.x = minPos;
|
|
3150
3115
|
}
|
|
3151
3116
|
if (data.outMode === OutMode.split) {
|
|
@@ -3165,10 +3130,9 @@
|
|
|
3165
3130
|
}
|
|
3166
3131
|
const velocity = data.particle.velocity.y;
|
|
3167
3132
|
let bounced = false;
|
|
3168
|
-
if (
|
|
3169
|
-
data.
|
|
3170
|
-
|
|
3171
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3133
|
+
if (data.outOfCanvas &&
|
|
3134
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3135
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3172
3136
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3173
3137
|
data.particle.velocity.y *= -newVelocity;
|
|
3174
3138
|
bounced = true;
|
|
@@ -3177,10 +3141,10 @@
|
|
|
3177
3141
|
return;
|
|
3178
3142
|
}
|
|
3179
3143
|
const minPos = data.offset.y + data.size;
|
|
3180
|
-
if (data.
|
|
3144
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3181
3145
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3182
3146
|
}
|
|
3183
|
-
else if (data.
|
|
3147
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3184
3148
|
data.particle.position.y = minPos;
|
|
3185
3149
|
}
|
|
3186
3150
|
if (data.outMode === OutMode.split) {
|
|
@@ -3189,24 +3153,24 @@
|
|
|
3189
3153
|
}
|
|
3190
3154
|
|
|
3191
3155
|
class BounceOutMode {
|
|
3192
|
-
container;
|
|
3193
3156
|
modes;
|
|
3194
|
-
|
|
3157
|
+
#container;
|
|
3158
|
+
#particleBouncePlugins;
|
|
3195
3159
|
constructor(container) {
|
|
3196
|
-
this
|
|
3160
|
+
this.#container = container;
|
|
3197
3161
|
this.modes = [
|
|
3198
3162
|
OutMode.bounce,
|
|
3199
3163
|
OutMode.split,
|
|
3200
3164
|
];
|
|
3201
|
-
this
|
|
3165
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3202
3166
|
}
|
|
3203
3167
|
update(particle, direction, delta, outMode) {
|
|
3204
3168
|
if (!this.modes.includes(outMode)) {
|
|
3205
3169
|
return;
|
|
3206
3170
|
}
|
|
3207
|
-
const container = this
|
|
3171
|
+
const container = this.#container;
|
|
3208
3172
|
let handled = false;
|
|
3209
|
-
for (const plugin of this
|
|
3173
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3210
3174
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3211
3175
|
if (handled) {
|
|
3212
3176
|
break;
|
|
@@ -3215,29 +3179,26 @@
|
|
|
3215
3179
|
if (handled) {
|
|
3216
3180
|
return;
|
|
3217
3181
|
}
|
|
3218
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3219
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3220
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3182
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3183
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3184
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3221
3185
|
}
|
|
3222
3186
|
}
|
|
3223
3187
|
|
|
3224
3188
|
const minVelocity$3 = 0;
|
|
3225
3189
|
class DestroyOutMode {
|
|
3226
|
-
container;
|
|
3227
3190
|
modes;
|
|
3228
|
-
constructor(
|
|
3229
|
-
this.container = container;
|
|
3191
|
+
constructor(_container) {
|
|
3230
3192
|
this.modes = [OutMode.destroy];
|
|
3231
3193
|
}
|
|
3232
3194
|
update(particle, direction, _delta, outMode) {
|
|
3233
3195
|
if (!this.modes.includes(outMode)) {
|
|
3234
3196
|
return;
|
|
3235
3197
|
}
|
|
3236
|
-
const container = this.container;
|
|
3237
3198
|
switch (particle.outType) {
|
|
3238
3199
|
case ParticleOutType.normal:
|
|
3239
3200
|
case ParticleOutType.outside:
|
|
3240
|
-
if (
|
|
3201
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3241
3202
|
return;
|
|
3242
3203
|
}
|
|
3243
3204
|
break;
|
|
@@ -3258,10 +3219,10 @@
|
|
|
3258
3219
|
|
|
3259
3220
|
const minVelocity$2 = 0;
|
|
3260
3221
|
class NoneOutMode {
|
|
3261
|
-
container;
|
|
3262
3222
|
modes;
|
|
3223
|
+
#container;
|
|
3263
3224
|
constructor(container) {
|
|
3264
|
-
this
|
|
3225
|
+
this.#container = container;
|
|
3265
3226
|
this.modes = [OutMode.none];
|
|
3266
3227
|
}
|
|
3267
3228
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3274,7 +3235,7 @@
|
|
|
3274
3235
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3275
3236
|
return;
|
|
3276
3237
|
}
|
|
3277
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3238
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3278
3239
|
if (!gravityOptions.enable) {
|
|
3279
3240
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3280
3241
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3300,17 +3261,17 @@
|
|
|
3300
3261
|
|
|
3301
3262
|
const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
|
|
3302
3263
|
class OutOutMode {
|
|
3303
|
-
container;
|
|
3304
3264
|
modes;
|
|
3265
|
+
#container;
|
|
3305
3266
|
constructor(container) {
|
|
3306
|
-
this
|
|
3267
|
+
this.#container = container;
|
|
3307
3268
|
this.modes = [OutMode.out];
|
|
3308
3269
|
}
|
|
3309
3270
|
update(particle, direction, _delta, outMode) {
|
|
3310
3271
|
if (!this.modes.includes(outMode)) {
|
|
3311
3272
|
return;
|
|
3312
3273
|
}
|
|
3313
|
-
const container = this
|
|
3274
|
+
const container = this.#container;
|
|
3314
3275
|
switch (particle.outType) {
|
|
3315
3276
|
case ParticleOutType.inside: {
|
|
3316
3277
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3340,7 +3301,7 @@
|
|
|
3340
3301
|
break;
|
|
3341
3302
|
}
|
|
3342
3303
|
default: {
|
|
3343
|
-
if (
|
|
3304
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3344
3305
|
return;
|
|
3345
3306
|
}
|
|
3346
3307
|
switch (particle.outType) {
|
|
@@ -3424,16 +3385,16 @@
|
|
|
3424
3385
|
};
|
|
3425
3386
|
class OutOfCanvasUpdater {
|
|
3426
3387
|
updaters;
|
|
3427
|
-
container;
|
|
3388
|
+
#container;
|
|
3428
3389
|
constructor(container) {
|
|
3429
|
-
this
|
|
3390
|
+
this.#container = container;
|
|
3430
3391
|
this.updaters = new Map();
|
|
3431
3392
|
}
|
|
3432
3393
|
init(particle) {
|
|
3433
|
-
this
|
|
3434
|
-
this
|
|
3435
|
-
this
|
|
3436
|
-
this
|
|
3394
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3395
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3396
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3397
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3437
3398
|
}
|
|
3438
3399
|
isEnabled(particle) {
|
|
3439
3400
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3441,18 +3402,18 @@
|
|
|
3441
3402
|
update(particle, delta) {
|
|
3442
3403
|
const outModes = particle.options.move.outModes;
|
|
3443
3404
|
particle.justWarped = false;
|
|
3444
|
-
this
|
|
3445
|
-
this
|
|
3446
|
-
this
|
|
3447
|
-
this
|
|
3405
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3406
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3407
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3408
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3448
3409
|
}
|
|
3449
|
-
|
|
3410
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3450
3411
|
const outModes = particle.options.move.outModes;
|
|
3451
3412
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3452
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3413
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3453
3414
|
}
|
|
3454
3415
|
};
|
|
3455
|
-
|
|
3416
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3456
3417
|
for (const updater of this.updaters.values()) {
|
|
3457
3418
|
updater.update(particle, direction, delta, outMode);
|
|
3458
3419
|
}
|
|
@@ -3460,7 +3421,7 @@
|
|
|
3460
3421
|
}
|
|
3461
3422
|
|
|
3462
3423
|
async function loadOutModesUpdater(engine) {
|
|
3463
|
-
engine.checkVersion("4.0
|
|
3424
|
+
engine.checkVersion("4.1.0");
|
|
3464
3425
|
await engine.pluginManager.register(e => {
|
|
3465
3426
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3466
3427
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3470,20 +3431,20 @@
|
|
|
3470
3431
|
|
|
3471
3432
|
const defaultOpacity = 1;
|
|
3472
3433
|
class PaintUpdater {
|
|
3473
|
-
|
|
3474
|
-
|
|
3434
|
+
#container;
|
|
3435
|
+
#pluginManager;
|
|
3475
3436
|
constructor(pluginManager, container) {
|
|
3476
|
-
this
|
|
3477
|
-
this
|
|
3437
|
+
this.#container = container;
|
|
3438
|
+
this.#pluginManager = pluginManager;
|
|
3478
3439
|
}
|
|
3479
3440
|
init(particle) {
|
|
3480
|
-
const container = this
|
|
3441
|
+
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;
|
|
3481
3442
|
if (fill) {
|
|
3482
3443
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3483
3444
|
particle.fillEnabled = fill.enable;
|
|
3484
3445
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3485
3446
|
particle.fillAnimation = fillColor.animation;
|
|
3486
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3447
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3487
3448
|
if (fillHslColor) {
|
|
3488
3449
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3489
3450
|
}
|
|
@@ -3499,7 +3460,7 @@
|
|
|
3499
3460
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3500
3461
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3501
3462
|
particle.strokeAnimation = strokeColor.animation;
|
|
3502
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3463
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3503
3464
|
if (strokeHslColor) {
|
|
3504
3465
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3505
3466
|
}
|
|
@@ -3531,7 +3492,7 @@
|
|
|
3531
3492
|
}
|
|
3532
3493
|
|
|
3533
3494
|
async function loadPaintUpdater(engine) {
|
|
3534
|
-
engine.checkVersion("4.0
|
|
3495
|
+
engine.checkVersion("4.1.0");
|
|
3535
3496
|
await engine.pluginManager.register(e => {
|
|
3536
3497
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3537
3498
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3586,27 +3547,69 @@
|
|
|
3586
3547
|
}
|
|
3587
3548
|
|
|
3588
3549
|
async function loadRgbColorPlugin(engine) {
|
|
3589
|
-
engine.checkVersion("4.0
|
|
3550
|
+
engine.checkVersion("4.1.0");
|
|
3590
3551
|
await engine.pluginManager.register(e => {
|
|
3591
3552
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3592
3553
|
});
|
|
3593
3554
|
}
|
|
3594
3555
|
|
|
3556
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3557
|
+
destroy;
|
|
3558
|
+
constructor() {
|
|
3559
|
+
super();
|
|
3560
|
+
this.destroy = DestroyType.none;
|
|
3561
|
+
this.speed = 5;
|
|
3562
|
+
}
|
|
3563
|
+
load(data) {
|
|
3564
|
+
super.load(data);
|
|
3565
|
+
if (isNull(data)) {
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
if (data.destroy !== undefined) {
|
|
3569
|
+
this.destroy = data.destroy;
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3574
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3575
|
+
animation;
|
|
3576
|
+
constructor() {
|
|
3577
|
+
super();
|
|
3578
|
+
this.animation = new SizeAnimation();
|
|
3579
|
+
this.value = 3;
|
|
3580
|
+
}
|
|
3581
|
+
load(data) {
|
|
3582
|
+
super.load(data);
|
|
3583
|
+
if (isNull(data)) {
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
const animation = data.animation;
|
|
3587
|
+
if (animation !== undefined) {
|
|
3588
|
+
this.animation.load(animation);
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3595
3593
|
const minLoops = 0;
|
|
3596
3594
|
class SizeUpdater {
|
|
3597
|
-
|
|
3595
|
+
#container;
|
|
3598
3596
|
constructor(container) {
|
|
3599
|
-
this
|
|
3597
|
+
this.#container = container;
|
|
3600
3598
|
}
|
|
3601
3599
|
init(particle) {
|
|
3602
|
-
const container = this
|
|
3603
|
-
if (
|
|
3604
|
-
|
|
3605
|
-
(particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3606
|
-
if (!sizeAnimation.sync) {
|
|
3607
|
-
particle.size.velocity *= getRandom();
|
|
3608
|
-
}
|
|
3600
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3601
|
+
if (!sizeOptions) {
|
|
3602
|
+
return;
|
|
3609
3603
|
}
|
|
3604
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3605
|
+
if (!sizeAnimation.enable) {
|
|
3606
|
+
return;
|
|
3607
|
+
}
|
|
3608
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3609
|
+
if (sizeAnimation.sync) {
|
|
3610
|
+
return;
|
|
3611
|
+
}
|
|
3612
|
+
particle.size.velocity *= getRandom();
|
|
3610
3613
|
}
|
|
3611
3614
|
isEnabled(particle) {
|
|
3612
3615
|
return (!particle.destroyed &&
|
|
@@ -3616,12 +3619,26 @@
|
|
|
3616
3619
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3617
3620
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3618
3621
|
}
|
|
3622
|
+
loadOptions(options, ...sources) {
|
|
3623
|
+
options.size ??= new Size();
|
|
3624
|
+
for (const source of sources) {
|
|
3625
|
+
options.size.load(source?.size);
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
preInit(particle) {
|
|
3629
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3630
|
+
if (!sizeOptions) {
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3634
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3635
|
+
}
|
|
3619
3636
|
reset(particle) {
|
|
3620
3637
|
particle.size.time = 0;
|
|
3621
3638
|
particle.size.loops = 0;
|
|
3622
3639
|
}
|
|
3623
3640
|
update(particle, delta) {
|
|
3624
|
-
if (!this.isEnabled(particle)) {
|
|
3641
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3625
3642
|
return;
|
|
3626
3643
|
}
|
|
3627
3644
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3629,7 +3646,7 @@
|
|
|
3629
3646
|
}
|
|
3630
3647
|
|
|
3631
3648
|
async function loadSizeUpdater(engine) {
|
|
3632
|
-
engine.checkVersion("4.0
|
|
3649
|
+
engine.checkVersion("4.1.0");
|
|
3633
3650
|
await engine.pluginManager.register(e => {
|
|
3634
3651
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3635
3652
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3638,7 +3655,7 @@
|
|
|
3638
3655
|
}
|
|
3639
3656
|
|
|
3640
3657
|
async function loadBasic(engine) {
|
|
3641
|
-
engine.checkVersion("4.0
|
|
3658
|
+
engine.checkVersion("4.1.0");
|
|
3642
3659
|
await engine.pluginManager.register(async (e) => {
|
|
3643
3660
|
await Promise.all([
|
|
3644
3661
|
loadBlendPlugin(e),
|
|
@@ -3855,13 +3872,15 @@
|
|
|
3855
3872
|
mode: PixelMode.precise,
|
|
3856
3873
|
},
|
|
3857
3874
|
});
|
|
3858
|
-
const factor = identity$1 / getRangeValue(splitOptions.factor.value);
|
|
3859
|
-
if (
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3875
|
+
const factor = identity$1 / getRangeValue(splitOptions.factor.value), sizeOptions = splitParticleOptions["size"];
|
|
3876
|
+
if (sizeOptions) {
|
|
3877
|
+
if (isNumber(sizeOptions.value)) {
|
|
3878
|
+
sizeOptions.value *= factor;
|
|
3879
|
+
}
|
|
3880
|
+
else {
|
|
3881
|
+
sizeOptions.value.min *= factor;
|
|
3882
|
+
sizeOptions.value.max *= factor;
|
|
3883
|
+
}
|
|
3865
3884
|
}
|
|
3866
3885
|
splitParticleOptions.load(splitParticlesOptions);
|
|
3867
3886
|
const splitParticlePaintOptions = itemFromSingleOrMultiple(splitParticleOptions.paint), splitParticleFillOptions = splitParticlePaintOptions?.fill, splitParticleStrokeOptions = splitParticlePaintOptions?.stroke, fillColor = resolveSplitColor(splitOptions.fillColorOffset, splitFillColor, splitParticleFillOptions?.color, parentFillColor), strokeColor = resolveSplitColor(splitOptions.strokeColorOffset, splitStrokeColor, splitParticleStrokeOptions?.color, parentStrokeColor);
|
|
@@ -3906,14 +3925,14 @@
|
|
|
3906
3925
|
|
|
3907
3926
|
const defaultDeltaFactor$1 = 1, fpsFactor = 60, minExplodeSpeed = 0.01, maxExplodeProgress = 1;
|
|
3908
3927
|
class DestroyUpdater {
|
|
3909
|
-
|
|
3910
|
-
|
|
3928
|
+
#container;
|
|
3929
|
+
#pluginManager;
|
|
3911
3930
|
constructor(pluginManager, container) {
|
|
3912
|
-
this
|
|
3913
|
-
this
|
|
3931
|
+
this.#container = container;
|
|
3932
|
+
this.#pluginManager = pluginManager;
|
|
3914
3933
|
}
|
|
3915
3934
|
init(particle) {
|
|
3916
|
-
const container = this
|
|
3935
|
+
const container = this.#container, particlesOptions = particle.options, destroyOptions = particlesOptions.destroy;
|
|
3917
3936
|
if (!destroyOptions) {
|
|
3918
3937
|
return;
|
|
3919
3938
|
}
|
|
@@ -3952,7 +3971,7 @@
|
|
|
3952
3971
|
const destroyOptions = particle.options.destroy;
|
|
3953
3972
|
switch (destroyOptions?.mode) {
|
|
3954
3973
|
case DestroyMode.split:
|
|
3955
|
-
split(this
|
|
3974
|
+
split(this.#pluginManager, this.#container, particle);
|
|
3956
3975
|
break;
|
|
3957
3976
|
case DestroyMode.explode: {
|
|
3958
3977
|
if (particle.exploding) {
|
|
@@ -4008,7 +4027,7 @@
|
|
|
4008
4027
|
}
|
|
4009
4028
|
|
|
4010
4029
|
async function loadDestroyUpdater(engine) {
|
|
4011
|
-
engine.checkVersion("4.0
|
|
4030
|
+
engine.checkVersion("4.1.0");
|
|
4012
4031
|
await engine.pluginManager.register(e => {
|
|
4013
4032
|
e.pluginManager.addParticleUpdater("destroy", container => {
|
|
4014
4033
|
return Promise.resolve(new DestroyUpdater(e.pluginManager, container));
|
|
@@ -4225,13 +4244,13 @@
|
|
|
4225
4244
|
|
|
4226
4245
|
class EmittersPlugin {
|
|
4227
4246
|
id = "emitters";
|
|
4228
|
-
|
|
4247
|
+
#instancesManager;
|
|
4229
4248
|
constructor(instancesManager) {
|
|
4230
|
-
this
|
|
4249
|
+
this.#instancesManager = instancesManager;
|
|
4231
4250
|
}
|
|
4232
4251
|
async getPlugin(container) {
|
|
4233
4252
|
const { EmittersPluginInstance } = await Promise.resolve().then(function () { return EmittersPluginInstance$1; });
|
|
4234
|
-
return new EmittersPluginInstance(this
|
|
4253
|
+
return new EmittersPluginInstance(this.#instancesManager, container);
|
|
4235
4254
|
}
|
|
4236
4255
|
loadOptions(_container, options, source) {
|
|
4237
4256
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -4284,7 +4303,7 @@
|
|
|
4284
4303
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
4285
4304
|
|
|
4286
4305
|
async function loadEmittersPluginSimple(engine) {
|
|
4287
|
-
engine.checkVersion("4.0
|
|
4306
|
+
engine.checkVersion("4.1.0");
|
|
4288
4307
|
await engine.pluginManager.register(async (e) => {
|
|
4289
4308
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
4290
4309
|
await addEmittersShapesManager(e);
|
|
@@ -4335,13 +4354,13 @@
|
|
|
4335
4354
|
|
|
4336
4355
|
class TrailPlugin {
|
|
4337
4356
|
id = "trail";
|
|
4338
|
-
|
|
4357
|
+
#pluginManager;
|
|
4339
4358
|
constructor(pluginManager) {
|
|
4340
|
-
this
|
|
4359
|
+
this.#pluginManager = pluginManager;
|
|
4341
4360
|
}
|
|
4342
4361
|
async getPlugin(container) {
|
|
4343
4362
|
const { TrailPluginInstance } = await Promise.resolve().then(function () { return TrailPluginInstance$1; });
|
|
4344
|
-
return new TrailPluginInstance(this
|
|
4363
|
+
return new TrailPluginInstance(this.#pluginManager, container);
|
|
4345
4364
|
}
|
|
4346
4365
|
loadOptions(_container, options, source) {
|
|
4347
4366
|
if (!this.needsPlugin()) {
|
|
@@ -4359,7 +4378,7 @@
|
|
|
4359
4378
|
}
|
|
4360
4379
|
|
|
4361
4380
|
async function loadTrailPlugin(engine) {
|
|
4362
|
-
engine.checkVersion("4.0
|
|
4381
|
+
engine.checkVersion("4.1.0");
|
|
4363
4382
|
await engine.pluginManager.register(e => {
|
|
4364
4383
|
e.pluginManager.addPlugin(new TrailPlugin(e.pluginManager));
|
|
4365
4384
|
});
|
|
@@ -4488,58 +4507,58 @@
|
|
|
4488
4507
|
}
|
|
4489
4508
|
}
|
|
4490
4509
|
class RenderManager {
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4510
|
+
#canvasClearPlugins;
|
|
4511
|
+
#canvasManager;
|
|
4512
|
+
#canvasPaintPlugins;
|
|
4513
|
+
#clearDrawPlugins;
|
|
4514
|
+
#colorPlugins;
|
|
4515
|
+
#container;
|
|
4516
|
+
#context;
|
|
4517
|
+
#contextSettings;
|
|
4518
|
+
#drawParticlePlugins;
|
|
4519
|
+
#drawParticlesCleanupPlugins;
|
|
4520
|
+
#drawParticlesSetupPlugins;
|
|
4521
|
+
#drawPlugins;
|
|
4522
|
+
#drawSettingsCleanupPlugins;
|
|
4523
|
+
#drawSettingsSetupPlugins;
|
|
4524
|
+
#pluginManager;
|
|
4525
|
+
#postDrawUpdaters;
|
|
4526
|
+
#preDrawUpdaters;
|
|
4527
|
+
#reusableColorStyles = {};
|
|
4528
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4529
|
+
#reusableTransform = {};
|
|
4511
4530
|
constructor(pluginManager, container, canvasManager) {
|
|
4512
|
-
this
|
|
4513
|
-
this
|
|
4514
|
-
this
|
|
4515
|
-
this
|
|
4516
|
-
this
|
|
4517
|
-
this
|
|
4518
|
-
this
|
|
4519
|
-
this
|
|
4520
|
-
this
|
|
4521
|
-
this
|
|
4522
|
-
this
|
|
4523
|
-
this
|
|
4524
|
-
this
|
|
4525
|
-
this
|
|
4526
|
-
this
|
|
4527
|
-
this
|
|
4531
|
+
this.#pluginManager = pluginManager;
|
|
4532
|
+
this.#container = container;
|
|
4533
|
+
this.#canvasManager = canvasManager;
|
|
4534
|
+
this.#context = null;
|
|
4535
|
+
this.#preDrawUpdaters = [];
|
|
4536
|
+
this.#postDrawUpdaters = [];
|
|
4537
|
+
this.#colorPlugins = [];
|
|
4538
|
+
this.#canvasClearPlugins = [];
|
|
4539
|
+
this.#canvasPaintPlugins = [];
|
|
4540
|
+
this.#clearDrawPlugins = [];
|
|
4541
|
+
this.#drawParticlePlugins = [];
|
|
4542
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4543
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4544
|
+
this.#drawPlugins = [];
|
|
4545
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4546
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4528
4547
|
}
|
|
4529
4548
|
get settings() {
|
|
4530
|
-
return this
|
|
4549
|
+
return this.#contextSettings;
|
|
4531
4550
|
}
|
|
4532
4551
|
canvasClear() {
|
|
4533
|
-
if (!this.
|
|
4552
|
+
if (!this.#container.actualOptions.clear) {
|
|
4534
4553
|
return;
|
|
4535
4554
|
}
|
|
4536
4555
|
this.draw(ctx => {
|
|
4537
|
-
clear(ctx, this.
|
|
4556
|
+
clear(ctx, this.#canvasManager.size);
|
|
4538
4557
|
});
|
|
4539
4558
|
}
|
|
4540
4559
|
clear() {
|
|
4541
4560
|
let pluginHandled = false;
|
|
4542
|
-
for (const plugin of this
|
|
4561
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4543
4562
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4544
4563
|
if (pluginHandled) {
|
|
4545
4564
|
break;
|
|
@@ -4552,21 +4571,21 @@
|
|
|
4552
4571
|
}
|
|
4553
4572
|
destroy() {
|
|
4554
4573
|
this.stop();
|
|
4555
|
-
this
|
|
4556
|
-
this
|
|
4557
|
-
this
|
|
4558
|
-
this
|
|
4559
|
-
this
|
|
4560
|
-
this
|
|
4561
|
-
this
|
|
4562
|
-
this
|
|
4563
|
-
this
|
|
4564
|
-
this
|
|
4565
|
-
this
|
|
4566
|
-
this
|
|
4574
|
+
this.#preDrawUpdaters = [];
|
|
4575
|
+
this.#postDrawUpdaters = [];
|
|
4576
|
+
this.#colorPlugins = [];
|
|
4577
|
+
this.#canvasClearPlugins = [];
|
|
4578
|
+
this.#canvasPaintPlugins = [];
|
|
4579
|
+
this.#clearDrawPlugins = [];
|
|
4580
|
+
this.#drawParticlePlugins = [];
|
|
4581
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4582
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4583
|
+
this.#drawPlugins = [];
|
|
4584
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4585
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4567
4586
|
}
|
|
4568
4587
|
draw(cb) {
|
|
4569
|
-
const ctx = this
|
|
4588
|
+
const ctx = this.#context;
|
|
4570
4589
|
if (!ctx) {
|
|
4571
4590
|
return;
|
|
4572
4591
|
}
|
|
@@ -4581,21 +4600,21 @@
|
|
|
4581
4600
|
return;
|
|
4582
4601
|
}
|
|
4583
4602
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4584
|
-
let [fColor, sColor] = this
|
|
4603
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4585
4604
|
fColor ??= pfColor;
|
|
4586
4605
|
sColor ??= psColor;
|
|
4587
4606
|
if (!fColor && !sColor) {
|
|
4588
4607
|
return;
|
|
4589
4608
|
}
|
|
4590
|
-
const container = this
|
|
4609
|
+
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;
|
|
4591
4610
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4592
4611
|
colorStyles.fill = fill;
|
|
4593
4612
|
colorStyles.stroke = stroke;
|
|
4594
4613
|
this.draw((context) => {
|
|
4595
|
-
for (const plugin of this
|
|
4614
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4596
4615
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4597
4616
|
}
|
|
4598
|
-
this
|
|
4617
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4599
4618
|
drawParticle({
|
|
4600
4619
|
container,
|
|
4601
4620
|
context,
|
|
@@ -4606,35 +4625,35 @@
|
|
|
4606
4625
|
opacity: opacity,
|
|
4607
4626
|
transform,
|
|
4608
4627
|
});
|
|
4609
|
-
this
|
|
4610
|
-
for (const plugin of this
|
|
4628
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4629
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4611
4630
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4612
4631
|
}
|
|
4613
4632
|
});
|
|
4614
4633
|
}
|
|
4615
4634
|
drawParticlePlugins(particle, delta) {
|
|
4616
4635
|
this.draw(ctx => {
|
|
4617
|
-
for (const plugin of this
|
|
4636
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4618
4637
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4619
4638
|
}
|
|
4620
4639
|
});
|
|
4621
4640
|
}
|
|
4622
4641
|
drawParticles(delta) {
|
|
4623
|
-
const { particles } = this
|
|
4642
|
+
const { particles } = this.#container;
|
|
4624
4643
|
this.clear();
|
|
4625
4644
|
particles.update(delta);
|
|
4626
4645
|
this.draw(ctx => {
|
|
4627
|
-
for (const plugin of this
|
|
4646
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4628
4647
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4629
4648
|
}
|
|
4630
|
-
for (const plugin of this
|
|
4649
|
+
for (const plugin of this.#drawPlugins) {
|
|
4631
4650
|
plugin.draw?.(ctx, delta);
|
|
4632
4651
|
}
|
|
4633
4652
|
particles.drawParticles(delta);
|
|
4634
|
-
for (const plugin of this
|
|
4653
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4635
4654
|
plugin.clearDraw?.(ctx, delta);
|
|
4636
4655
|
}
|
|
4637
|
-
for (const plugin of this
|
|
4656
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4638
4657
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4639
4658
|
}
|
|
4640
4659
|
});
|
|
@@ -4645,64 +4664,64 @@
|
|
|
4645
4664
|
this.paint();
|
|
4646
4665
|
}
|
|
4647
4666
|
initPlugins() {
|
|
4648
|
-
this
|
|
4649
|
-
this
|
|
4650
|
-
this
|
|
4651
|
-
this
|
|
4652
|
-
this
|
|
4653
|
-
this
|
|
4654
|
-
this
|
|
4655
|
-
this
|
|
4656
|
-
this
|
|
4657
|
-
this
|
|
4658
|
-
for (const plugin of this.
|
|
4667
|
+
this.#colorPlugins = [];
|
|
4668
|
+
this.#canvasClearPlugins = [];
|
|
4669
|
+
this.#canvasPaintPlugins = [];
|
|
4670
|
+
this.#clearDrawPlugins = [];
|
|
4671
|
+
this.#drawParticlePlugins = [];
|
|
4672
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4673
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4674
|
+
this.#drawPlugins = [];
|
|
4675
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4676
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4677
|
+
for (const plugin of this.#container.plugins) {
|
|
4659
4678
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4660
|
-
this.
|
|
4679
|
+
this.#colorPlugins.push(plugin);
|
|
4661
4680
|
}
|
|
4662
4681
|
if (plugin.canvasClear) {
|
|
4663
|
-
this.
|
|
4682
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4664
4683
|
}
|
|
4665
4684
|
if (plugin.canvasPaint) {
|
|
4666
|
-
this.
|
|
4685
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4667
4686
|
}
|
|
4668
4687
|
if (plugin.drawParticle) {
|
|
4669
|
-
this.
|
|
4688
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4670
4689
|
}
|
|
4671
4690
|
if (plugin.drawParticleSetup) {
|
|
4672
|
-
this.
|
|
4691
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4673
4692
|
}
|
|
4674
4693
|
if (plugin.drawParticleCleanup) {
|
|
4675
|
-
this.
|
|
4694
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4676
4695
|
}
|
|
4677
4696
|
if (plugin.draw) {
|
|
4678
|
-
this.
|
|
4697
|
+
this.#drawPlugins.push(plugin);
|
|
4679
4698
|
}
|
|
4680
4699
|
if (plugin.drawSettingsSetup) {
|
|
4681
|
-
this.
|
|
4700
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4682
4701
|
}
|
|
4683
4702
|
if (plugin.drawSettingsCleanup) {
|
|
4684
|
-
this.
|
|
4703
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4685
4704
|
}
|
|
4686
4705
|
if (plugin.clearDraw) {
|
|
4687
|
-
this.
|
|
4706
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4688
4707
|
}
|
|
4689
4708
|
}
|
|
4690
4709
|
}
|
|
4691
4710
|
initUpdaters() {
|
|
4692
|
-
this
|
|
4693
|
-
this
|
|
4694
|
-
for (const updater of this.
|
|
4711
|
+
this.#preDrawUpdaters = [];
|
|
4712
|
+
this.#postDrawUpdaters = [];
|
|
4713
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4695
4714
|
if (updater.afterDraw) {
|
|
4696
|
-
this.
|
|
4715
|
+
this.#postDrawUpdaters.push(updater);
|
|
4697
4716
|
}
|
|
4698
4717
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4699
|
-
this.
|
|
4718
|
+
this.#preDrawUpdaters.push(updater);
|
|
4700
4719
|
}
|
|
4701
4720
|
}
|
|
4702
4721
|
}
|
|
4703
4722
|
paint() {
|
|
4704
4723
|
let handled = false;
|
|
4705
|
-
for (const plugin of this
|
|
4724
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4706
4725
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4707
4726
|
if (handled) {
|
|
4708
4727
|
break;
|
|
@@ -4715,35 +4734,35 @@
|
|
|
4715
4734
|
}
|
|
4716
4735
|
paintBase(baseColor) {
|
|
4717
4736
|
this.draw(ctx => {
|
|
4718
|
-
paintBase(ctx, this.
|
|
4737
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4719
4738
|
});
|
|
4720
4739
|
}
|
|
4721
4740
|
paintImage(image, opacity) {
|
|
4722
4741
|
this.draw(ctx => {
|
|
4723
|
-
paintImage(ctx, this.
|
|
4742
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4724
4743
|
});
|
|
4725
4744
|
}
|
|
4726
4745
|
setContext(context) {
|
|
4727
|
-
this
|
|
4728
|
-
if (this
|
|
4729
|
-
this.
|
|
4746
|
+
this.#context = context;
|
|
4747
|
+
if (this.#context) {
|
|
4748
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4730
4749
|
}
|
|
4731
4750
|
}
|
|
4732
4751
|
setContextSettings(settings) {
|
|
4733
|
-
this
|
|
4752
|
+
this.#contextSettings = settings;
|
|
4734
4753
|
}
|
|
4735
4754
|
stop() {
|
|
4736
4755
|
this.draw(ctx => {
|
|
4737
|
-
clear(ctx, this.
|
|
4756
|
+
clear(ctx, this.#canvasManager.size);
|
|
4738
4757
|
});
|
|
4739
4758
|
}
|
|
4740
|
-
|
|
4741
|
-
for (const updater of this
|
|
4759
|
+
#applyPostDrawUpdaters = particle => {
|
|
4760
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4742
4761
|
updater.afterDraw?.(particle);
|
|
4743
4762
|
}
|
|
4744
4763
|
};
|
|
4745
|
-
|
|
4746
|
-
for (const updater of this
|
|
4764
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4765
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4747
4766
|
if (updater.getColorStyles) {
|
|
4748
4767
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4749
4768
|
if (fill) {
|
|
@@ -4762,22 +4781,22 @@
|
|
|
4762
4781
|
updater.beforeDraw?.(particle);
|
|
4763
4782
|
}
|
|
4764
4783
|
};
|
|
4765
|
-
|
|
4784
|
+
#getPluginParticleColors = particle => {
|
|
4766
4785
|
let fColor, sColor;
|
|
4767
|
-
for (const plugin of this
|
|
4786
|
+
for (const plugin of this.#colorPlugins) {
|
|
4768
4787
|
if (!fColor && plugin.particleFillColor) {
|
|
4769
|
-
fColor = rangeColorToHsl(this
|
|
4788
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4770
4789
|
}
|
|
4771
4790
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4772
|
-
sColor = rangeColorToHsl(this
|
|
4791
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4773
4792
|
}
|
|
4774
4793
|
if (fColor && sColor) {
|
|
4775
4794
|
break;
|
|
4776
4795
|
}
|
|
4777
4796
|
}
|
|
4778
|
-
this
|
|
4779
|
-
this
|
|
4780
|
-
return this
|
|
4797
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4798
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4799
|
+
return this.#reusablePluginColors;
|
|
4781
4800
|
};
|
|
4782
4801
|
}
|
|
4783
4802
|
|
|
@@ -4835,53 +4854,53 @@
|
|
|
4835
4854
|
renderCanvas;
|
|
4836
4855
|
size;
|
|
4837
4856
|
zoom = defaultZoom;
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4857
|
+
#container;
|
|
4858
|
+
#generated;
|
|
4859
|
+
#mutationObserver;
|
|
4860
|
+
#originalStyle;
|
|
4861
|
+
#pluginManager;
|
|
4862
|
+
#pointerEvents;
|
|
4863
|
+
#resizePlugins;
|
|
4864
|
+
#standardSize;
|
|
4865
|
+
#zoomCenter;
|
|
4847
4866
|
constructor(pluginManager, container) {
|
|
4848
|
-
this
|
|
4849
|
-
this
|
|
4867
|
+
this.#pluginManager = pluginManager;
|
|
4868
|
+
this.#container = container;
|
|
4850
4869
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4851
|
-
this
|
|
4870
|
+
this.#standardSize = {
|
|
4852
4871
|
height: 0,
|
|
4853
4872
|
width: 0,
|
|
4854
4873
|
};
|
|
4855
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4874
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4856
4875
|
this.size = {
|
|
4857
4876
|
height: stdSize.height * pxRatio,
|
|
4858
4877
|
width: stdSize.width * pxRatio,
|
|
4859
4878
|
};
|
|
4860
|
-
this
|
|
4861
|
-
this
|
|
4862
|
-
this
|
|
4879
|
+
this.#generated = false;
|
|
4880
|
+
this.#resizePlugins = [];
|
|
4881
|
+
this.#pointerEvents = "none";
|
|
4863
4882
|
}
|
|
4864
|
-
get
|
|
4865
|
-
return this.
|
|
4883
|
+
get #fullScreen() {
|
|
4884
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4866
4885
|
}
|
|
4867
4886
|
destroy() {
|
|
4868
4887
|
this.stop();
|
|
4869
|
-
if (this
|
|
4888
|
+
if (this.#generated) {
|
|
4870
4889
|
const element = this.domElement;
|
|
4871
4890
|
element?.remove();
|
|
4872
4891
|
this.domElement = undefined;
|
|
4873
4892
|
this.renderCanvas = undefined;
|
|
4874
4893
|
}
|
|
4875
4894
|
else {
|
|
4876
|
-
this
|
|
4895
|
+
this.#resetOriginalStyle();
|
|
4877
4896
|
}
|
|
4878
4897
|
this.render.destroy();
|
|
4879
|
-
this
|
|
4898
|
+
this.#resizePlugins = [];
|
|
4880
4899
|
}
|
|
4881
4900
|
getZoomCenter() {
|
|
4882
|
-
const pxRatio = this.
|
|
4883
|
-
if (this
|
|
4884
|
-
return this
|
|
4901
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4902
|
+
if (this.#zoomCenter) {
|
|
4903
|
+
return this.#zoomCenter;
|
|
4885
4904
|
}
|
|
4886
4905
|
return {
|
|
4887
4906
|
x: (width * half) / pxRatio,
|
|
@@ -4889,20 +4908,20 @@
|
|
|
4889
4908
|
};
|
|
4890
4909
|
}
|
|
4891
4910
|
init() {
|
|
4892
|
-
this
|
|
4911
|
+
this.#safeMutationObserver(obs => {
|
|
4893
4912
|
obs.disconnect();
|
|
4894
4913
|
});
|
|
4895
|
-
this
|
|
4914
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4896
4915
|
for (const record of records) {
|
|
4897
4916
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4898
|
-
this
|
|
4917
|
+
this.#repairStyle();
|
|
4899
4918
|
}
|
|
4900
4919
|
}
|
|
4901
4920
|
});
|
|
4902
4921
|
this.resize();
|
|
4903
|
-
this
|
|
4922
|
+
this.#initStyle();
|
|
4904
4923
|
this.initBackground();
|
|
4905
|
-
this
|
|
4924
|
+
this.#safeMutationObserver(obs => {
|
|
4906
4925
|
const element = this.domElement;
|
|
4907
4926
|
if (!element || !(element instanceof Node)) {
|
|
4908
4927
|
return;
|
|
@@ -4913,13 +4932,13 @@
|
|
|
4913
4932
|
this.render.init();
|
|
4914
4933
|
}
|
|
4915
4934
|
initBackground() {
|
|
4916
|
-
const
|
|
4935
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4917
4936
|
if (!element) {
|
|
4918
4937
|
return;
|
|
4919
4938
|
}
|
|
4920
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4939
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4921
4940
|
if (color) {
|
|
4922
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4941
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4923
4942
|
}
|
|
4924
4943
|
else {
|
|
4925
4944
|
elementStyle.backgroundColor = "";
|
|
@@ -4930,27 +4949,27 @@
|
|
|
4930
4949
|
elementStyle.backgroundSize = background.size || "";
|
|
4931
4950
|
}
|
|
4932
4951
|
initPlugins() {
|
|
4933
|
-
this
|
|
4934
|
-
for (const plugin of this.
|
|
4952
|
+
this.#resizePlugins = [];
|
|
4953
|
+
for (const plugin of this.#container.plugins) {
|
|
4935
4954
|
if (plugin.resize) {
|
|
4936
|
-
this.
|
|
4955
|
+
this.#resizePlugins.push(plugin);
|
|
4937
4956
|
}
|
|
4938
4957
|
}
|
|
4939
4958
|
}
|
|
4940
4959
|
loadCanvas(canvas) {
|
|
4941
|
-
if (this
|
|
4960
|
+
if (this.#generated && this.domElement) {
|
|
4942
4961
|
this.domElement.remove();
|
|
4943
4962
|
}
|
|
4944
|
-
const container = this
|
|
4963
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4945
4964
|
this.domElement = domCanvas;
|
|
4946
|
-
this
|
|
4965
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4947
4966
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4948
4967
|
const domElement = this.domElement;
|
|
4949
4968
|
if (domElement) {
|
|
4950
4969
|
domElement.ariaHidden = "true";
|
|
4951
|
-
this
|
|
4970
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4952
4971
|
}
|
|
4953
|
-
const standardSize = this
|
|
4972
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4954
4973
|
if (domElement) {
|
|
4955
4974
|
standardSize.height = domElement.offsetHeight;
|
|
4956
4975
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4959,7 +4978,7 @@
|
|
|
4959
4978
|
standardSize.height = renderCanvas.height;
|
|
4960
4979
|
standardSize.width = renderCanvas.width;
|
|
4961
4980
|
}
|
|
4962
|
-
const pxRatio = this.
|
|
4981
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4963
4982
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4964
4983
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4965
4984
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4970,12 +4989,12 @@
|
|
|
4970
4989
|
willReadFrequently: false,
|
|
4971
4990
|
});
|
|
4972
4991
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4973
|
-
this
|
|
4992
|
+
this.#safeMutationObserver(obs => {
|
|
4974
4993
|
obs.disconnect();
|
|
4975
4994
|
});
|
|
4976
4995
|
container.retina.init();
|
|
4977
4996
|
this.initBackground();
|
|
4978
|
-
this
|
|
4997
|
+
this.#safeMutationObserver(obs => {
|
|
4979
4998
|
const element = this.domElement;
|
|
4980
4999
|
if (!element || !(element instanceof Node)) {
|
|
4981
5000
|
return;
|
|
@@ -4988,11 +5007,11 @@
|
|
|
4988
5007
|
if (!element) {
|
|
4989
5008
|
return false;
|
|
4990
5009
|
}
|
|
4991
|
-
const container = this
|
|
5010
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4992
5011
|
if (renderCanvas === undefined) {
|
|
4993
5012
|
return false;
|
|
4994
5013
|
}
|
|
4995
|
-
const currentSize = container.canvas
|
|
5014
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4996
5015
|
width: element.offsetWidth,
|
|
4997
5016
|
height: element.offsetHeight,
|
|
4998
5017
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -5011,7 +5030,7 @@
|
|
|
5011
5030
|
const canvasSize = this.size;
|
|
5012
5031
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
5013
5032
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
5014
|
-
if (this.
|
|
5033
|
+
if (this.#container.started) {
|
|
5015
5034
|
container.particles.setResizeFactor({
|
|
5016
5035
|
width: currentSize.width / oldSize.width,
|
|
5017
5036
|
height: currentSize.height / oldSize.height,
|
|
@@ -5024,46 +5043,46 @@
|
|
|
5024
5043
|
if (!element) {
|
|
5025
5044
|
return;
|
|
5026
5045
|
}
|
|
5027
|
-
this
|
|
5028
|
-
this
|
|
5046
|
+
this.#pointerEvents = type;
|
|
5047
|
+
this.#repairStyle();
|
|
5029
5048
|
}
|
|
5030
5049
|
setZoom(zoomLevel, center) {
|
|
5031
5050
|
this.zoom = zoomLevel;
|
|
5032
|
-
this
|
|
5051
|
+
this.#zoomCenter = center;
|
|
5033
5052
|
}
|
|
5034
5053
|
stop() {
|
|
5035
|
-
this
|
|
5054
|
+
this.#safeMutationObserver(obs => {
|
|
5036
5055
|
obs.disconnect();
|
|
5037
5056
|
});
|
|
5038
|
-
this
|
|
5057
|
+
this.#mutationObserver = undefined;
|
|
5039
5058
|
this.render.stop();
|
|
5040
5059
|
}
|
|
5041
5060
|
async windowResize() {
|
|
5042
5061
|
if (!this.domElement || !this.resize()) {
|
|
5043
5062
|
return;
|
|
5044
5063
|
}
|
|
5045
|
-
const container = this
|
|
5064
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
5046
5065
|
container.particles.setDensity();
|
|
5047
|
-
this
|
|
5066
|
+
this.#applyResizePlugins();
|
|
5048
5067
|
if (needsRefresh) {
|
|
5049
5068
|
await container.refresh();
|
|
5050
5069
|
}
|
|
5051
5070
|
}
|
|
5052
|
-
|
|
5053
|
-
for (const plugin of this
|
|
5071
|
+
#applyResizePlugins = () => {
|
|
5072
|
+
for (const plugin of this.#resizePlugins) {
|
|
5054
5073
|
plugin.resize?.();
|
|
5055
5074
|
}
|
|
5056
5075
|
};
|
|
5057
|
-
|
|
5058
|
-
const element = this.domElement, options = this.
|
|
5076
|
+
#initStyle = () => {
|
|
5077
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
5059
5078
|
if (!element) {
|
|
5060
5079
|
return;
|
|
5061
5080
|
}
|
|
5062
|
-
if (this
|
|
5063
|
-
this
|
|
5081
|
+
if (this.#fullScreen) {
|
|
5082
|
+
this.#setFullScreenStyle();
|
|
5064
5083
|
}
|
|
5065
5084
|
else {
|
|
5066
|
-
this
|
|
5085
|
+
this.#resetOriginalStyle();
|
|
5067
5086
|
}
|
|
5068
5087
|
for (const key in options.style) {
|
|
5069
5088
|
if (!key || !(key in options.style)) {
|
|
@@ -5076,72 +5095,72 @@
|
|
|
5076
5095
|
element.style.setProperty(key, value, "important");
|
|
5077
5096
|
}
|
|
5078
5097
|
};
|
|
5079
|
-
|
|
5098
|
+
#repairStyle = () => {
|
|
5080
5099
|
const element = this.domElement;
|
|
5081
5100
|
if (!element) {
|
|
5082
5101
|
return;
|
|
5083
5102
|
}
|
|
5084
|
-
this
|
|
5103
|
+
this.#safeMutationObserver(observer => {
|
|
5085
5104
|
observer.disconnect();
|
|
5086
5105
|
});
|
|
5087
|
-
this
|
|
5106
|
+
this.#initStyle();
|
|
5088
5107
|
this.initBackground();
|
|
5089
|
-
const pointerEvents = this
|
|
5108
|
+
const pointerEvents = this.#pointerEvents;
|
|
5090
5109
|
element.style.pointerEvents = pointerEvents;
|
|
5091
5110
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
5092
|
-
this
|
|
5111
|
+
this.#safeMutationObserver(observer => {
|
|
5093
5112
|
if (!(element instanceof Node)) {
|
|
5094
5113
|
return;
|
|
5095
5114
|
}
|
|
5096
5115
|
observer.observe(element, { attributes: true });
|
|
5097
5116
|
});
|
|
5098
5117
|
};
|
|
5099
|
-
|
|
5100
|
-
const element = this.domElement, originalStyle = this
|
|
5118
|
+
#resetOriginalStyle = () => {
|
|
5119
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
5101
5120
|
if (!element || !originalStyle) {
|
|
5102
5121
|
return;
|
|
5103
5122
|
}
|
|
5104
5123
|
setStyle(element, originalStyle, true);
|
|
5105
5124
|
};
|
|
5106
|
-
|
|
5107
|
-
if (!this
|
|
5125
|
+
#safeMutationObserver = callback => {
|
|
5126
|
+
if (!this.#mutationObserver) {
|
|
5108
5127
|
return;
|
|
5109
5128
|
}
|
|
5110
|
-
callback(this
|
|
5129
|
+
callback(this.#mutationObserver);
|
|
5111
5130
|
};
|
|
5112
|
-
|
|
5131
|
+
#setFullScreenStyle = () => {
|
|
5113
5132
|
const element = this.domElement;
|
|
5114
5133
|
if (!element) {
|
|
5115
5134
|
return;
|
|
5116
5135
|
}
|
|
5117
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5136
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
5118
5137
|
};
|
|
5119
5138
|
}
|
|
5120
5139
|
|
|
5121
5140
|
class EventListeners {
|
|
5122
|
-
container;
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5141
|
+
#container;
|
|
5142
|
+
#handlers;
|
|
5143
|
+
#resizeObserver;
|
|
5144
|
+
#resizeTimeout;
|
|
5126
5145
|
constructor(container) {
|
|
5127
|
-
this
|
|
5128
|
-
this
|
|
5146
|
+
this.#container = container;
|
|
5147
|
+
this.#handlers = {
|
|
5129
5148
|
visibilityChange: () => {
|
|
5130
|
-
this
|
|
5149
|
+
this.#handleVisibilityChange();
|
|
5131
5150
|
},
|
|
5132
5151
|
resize: () => {
|
|
5133
|
-
this
|
|
5152
|
+
this.#handleWindowResize();
|
|
5134
5153
|
},
|
|
5135
5154
|
};
|
|
5136
5155
|
}
|
|
5137
5156
|
addListeners() {
|
|
5138
|
-
this
|
|
5157
|
+
this.#manageListeners(true);
|
|
5139
5158
|
}
|
|
5140
5159
|
removeListeners() {
|
|
5141
|
-
this
|
|
5160
|
+
this.#manageListeners(false);
|
|
5142
5161
|
}
|
|
5143
|
-
|
|
5144
|
-
const container = this
|
|
5162
|
+
#handleVisibilityChange = () => {
|
|
5163
|
+
const container = this.#container, options = container.actualOptions;
|
|
5145
5164
|
if (!options.pauseOnBlur) {
|
|
5146
5165
|
return;
|
|
5147
5166
|
}
|
|
@@ -5159,24 +5178,24 @@
|
|
|
5159
5178
|
}
|
|
5160
5179
|
}
|
|
5161
5180
|
};
|
|
5162
|
-
|
|
5163
|
-
if (this
|
|
5164
|
-
clearTimeout(this
|
|
5165
|
-
|
|
5181
|
+
#handleWindowResize = () => {
|
|
5182
|
+
if (this.#resizeTimeout) {
|
|
5183
|
+
clearTimeout(this.#resizeTimeout);
|
|
5184
|
+
this.#resizeTimeout = undefined;
|
|
5166
5185
|
}
|
|
5167
5186
|
const handleResize = async () => {
|
|
5168
|
-
const canvas = this
|
|
5187
|
+
const canvas = this.#container.canvas;
|
|
5169
5188
|
await canvas.windowResize();
|
|
5170
5189
|
};
|
|
5171
|
-
this
|
|
5190
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5172
5191
|
};
|
|
5173
|
-
|
|
5174
|
-
const handlers = this
|
|
5175
|
-
this
|
|
5192
|
+
#manageListeners = add => {
|
|
5193
|
+
const handlers = this.#handlers;
|
|
5194
|
+
this.#manageResize(add);
|
|
5176
5195
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5177
5196
|
};
|
|
5178
|
-
|
|
5179
|
-
const handlers = this
|
|
5197
|
+
#manageResize = add => {
|
|
5198
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5180
5199
|
if (!options.resize.enable) {
|
|
5181
5200
|
return;
|
|
5182
5201
|
}
|
|
@@ -5185,22 +5204,22 @@
|
|
|
5185
5204
|
return;
|
|
5186
5205
|
}
|
|
5187
5206
|
const canvasEl = container.canvas.domElement;
|
|
5188
|
-
if (this
|
|
5207
|
+
if (this.#resizeObserver && !add) {
|
|
5189
5208
|
if (canvasEl) {
|
|
5190
|
-
this.
|
|
5209
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5191
5210
|
}
|
|
5192
|
-
this.
|
|
5193
|
-
|
|
5211
|
+
this.#resizeObserver.disconnect();
|
|
5212
|
+
this.#resizeObserver = undefined;
|
|
5194
5213
|
}
|
|
5195
|
-
else if (!this
|
|
5196
|
-
this
|
|
5214
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5215
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5197
5216
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5198
5217
|
if (!entry) {
|
|
5199
5218
|
return;
|
|
5200
5219
|
}
|
|
5201
|
-
this
|
|
5220
|
+
this.#handleWindowResize();
|
|
5202
5221
|
});
|
|
5203
|
-
this.
|
|
5222
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5204
5223
|
}
|
|
5205
5224
|
};
|
|
5206
5225
|
}
|
|
@@ -5273,24 +5292,24 @@
|
|
|
5273
5292
|
unbreakable;
|
|
5274
5293
|
velocity;
|
|
5275
5294
|
zIndexFactor;
|
|
5276
|
-
|
|
5295
|
+
#cachedOpacityData = {
|
|
5277
5296
|
fillOpacity: defaultOpacity$1,
|
|
5278
5297
|
opacity: defaultOpacity$1,
|
|
5279
5298
|
strokeOpacity: defaultOpacity$1,
|
|
5280
5299
|
};
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5300
|
+
#cachedPosition = Vector3d.origin;
|
|
5301
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5302
|
+
#cachedTransform = {
|
|
5284
5303
|
a: 1,
|
|
5285
5304
|
b: 0,
|
|
5286
5305
|
c: 0,
|
|
5287
5306
|
d: 1,
|
|
5288
5307
|
};
|
|
5289
|
-
|
|
5290
|
-
|
|
5308
|
+
#container;
|
|
5309
|
+
#pluginManager;
|
|
5291
5310
|
constructor(pluginManager, container) {
|
|
5292
|
-
this
|
|
5293
|
-
this
|
|
5311
|
+
this.#pluginManager = pluginManager;
|
|
5312
|
+
this.#container = container;
|
|
5294
5313
|
}
|
|
5295
5314
|
destroy(override) {
|
|
5296
5315
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5299,7 +5318,7 @@
|
|
|
5299
5318
|
this.destroyed = true;
|
|
5300
5319
|
this.bubble.inRange = false;
|
|
5301
5320
|
this.slow.inRange = false;
|
|
5302
|
-
const container = this
|
|
5321
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5303
5322
|
shapeDrawer?.particleDestroy?.(this);
|
|
5304
5323
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5305
5324
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5307,12 +5326,12 @@
|
|
|
5307
5326
|
for (const updater of container.particleUpdaters) {
|
|
5308
5327
|
updater.particleDestroyed?.(this, override);
|
|
5309
5328
|
}
|
|
5310
|
-
this.
|
|
5329
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5311
5330
|
particle: this,
|
|
5312
5331
|
});
|
|
5313
5332
|
}
|
|
5314
5333
|
draw(delta) {
|
|
5315
|
-
const container = this
|
|
5334
|
+
const container = this.#container, render = container.canvas.render;
|
|
5316
5335
|
render.drawParticlePlugins(this, delta);
|
|
5317
5336
|
render.drawParticle(this, delta);
|
|
5318
5337
|
}
|
|
@@ -5320,50 +5339,50 @@
|
|
|
5320
5339
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5321
5340
|
}
|
|
5322
5341
|
getFillColor() {
|
|
5323
|
-
return this
|
|
5342
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5324
5343
|
}
|
|
5325
5344
|
getMass() {
|
|
5326
5345
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5327
5346
|
}
|
|
5328
5347
|
getOpacity() {
|
|
5329
5348
|
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;
|
|
5330
|
-
this.
|
|
5331
|
-
this.
|
|
5332
|
-
this.
|
|
5333
|
-
return this
|
|
5349
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5350
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5351
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5352
|
+
return this.#cachedOpacityData;
|
|
5334
5353
|
}
|
|
5335
5354
|
getPosition() {
|
|
5336
|
-
this.
|
|
5337
|
-
this.
|
|
5338
|
-
this.
|
|
5339
|
-
return this
|
|
5355
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5356
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5357
|
+
this.#cachedPosition.z = this.position.z;
|
|
5358
|
+
return this.#cachedPosition;
|
|
5340
5359
|
}
|
|
5341
5360
|
getRadius() {
|
|
5342
5361
|
return this.bubble.radius ?? this.size.value;
|
|
5343
5362
|
}
|
|
5344
5363
|
getRotateData() {
|
|
5345
5364
|
const angle = this.getAngle();
|
|
5346
|
-
this.
|
|
5347
|
-
this.
|
|
5348
|
-
return this
|
|
5365
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5366
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5367
|
+
return this.#cachedRotateData;
|
|
5349
5368
|
}
|
|
5350
5369
|
getStrokeColor() {
|
|
5351
|
-
return this
|
|
5370
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5352
5371
|
}
|
|
5353
5372
|
getTransformData(externalTransform) {
|
|
5354
5373
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5355
|
-
this.
|
|
5356
|
-
this.
|
|
5374
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5375
|
+
this.#cachedTransform.b = rotating
|
|
5357
5376
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
5358
5377
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5359
|
-
this.
|
|
5378
|
+
this.#cachedTransform.c = rotating
|
|
5360
5379
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
5361
5380
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5362
|
-
this.
|
|
5363
|
-
return this
|
|
5381
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5382
|
+
return this.#cachedTransform;
|
|
5364
5383
|
}
|
|
5365
5384
|
init(id, position, overrideOptions, group) {
|
|
5366
|
-
const container = this
|
|
5385
|
+
const container = this.#container;
|
|
5367
5386
|
this.id = id;
|
|
5368
5387
|
this.group = group;
|
|
5369
5388
|
this.justWarped = false;
|
|
@@ -5383,21 +5402,27 @@
|
|
|
5383
5402
|
moveSpeed: 0,
|
|
5384
5403
|
sizeAnimationSpeed: 0,
|
|
5385
5404
|
};
|
|
5405
|
+
this.size = {
|
|
5406
|
+
value: 1,
|
|
5407
|
+
max: 1,
|
|
5408
|
+
min: 1,
|
|
5409
|
+
enable: false,
|
|
5410
|
+
};
|
|
5386
5411
|
this.outType = ParticleOutType.normal;
|
|
5387
5412
|
this.ignoresResizeRatio = true;
|
|
5388
|
-
const
|
|
5413
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5389
5414
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5390
5415
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5391
5416
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5392
5417
|
if (overrideOptions) {
|
|
5393
|
-
if (overrideOptions.effect?.type) {
|
|
5418
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5394
5419
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5395
5420
|
if (effect) {
|
|
5396
5421
|
this.effect = effect;
|
|
5397
5422
|
effectOptions.load(overrideOptions.effect);
|
|
5398
5423
|
}
|
|
5399
5424
|
}
|
|
5400
|
-
if (overrideOptions.shape?.type) {
|
|
5425
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5401
5426
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5402
5427
|
if (shape) {
|
|
5403
5428
|
this.shape = shape;
|
|
@@ -5406,21 +5431,20 @@
|
|
|
5406
5431
|
}
|
|
5407
5432
|
}
|
|
5408
5433
|
if (this.effect === randomColorValue) {
|
|
5409
|
-
const availableEffects = [...this.
|
|
5434
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5410
5435
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5411
5436
|
}
|
|
5412
5437
|
if (this.shape === randomColorValue) {
|
|
5413
|
-
const availableShapes = [...this.
|
|
5438
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5414
5439
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5415
5440
|
}
|
|
5416
5441
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5417
5442
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5418
5443
|
particlesOptions.load(overrideOptions);
|
|
5419
|
-
const effectData = this.effectData;
|
|
5444
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5420
5445
|
if (effectData) {
|
|
5421
5446
|
particlesOptions.load(effectData.particles);
|
|
5422
5447
|
}
|
|
5423
|
-
const shapeData = this.shapeData;
|
|
5424
5448
|
if (shapeData) {
|
|
5425
5449
|
particlesOptions.load(shapeData.particles);
|
|
5426
5450
|
}
|
|
@@ -5428,7 +5452,9 @@
|
|
|
5428
5452
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5429
5453
|
this.options = particlesOptions;
|
|
5430
5454
|
container.retina.initParticle(this);
|
|
5431
|
-
|
|
5455
|
+
for (const updater of container.particleUpdaters) {
|
|
5456
|
+
updater.preInit?.(this);
|
|
5457
|
+
}
|
|
5432
5458
|
this.bubble = {
|
|
5433
5459
|
inRange: false,
|
|
5434
5460
|
};
|
|
@@ -5436,8 +5462,8 @@
|
|
|
5436
5462
|
inRange: false,
|
|
5437
5463
|
factor: 1,
|
|
5438
5464
|
};
|
|
5439
|
-
this
|
|
5440
|
-
this.initialVelocity = this
|
|
5465
|
+
this.#initPosition(position);
|
|
5466
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5441
5467
|
this.velocity = this.initialVelocity.copy();
|
|
5442
5468
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5443
5469
|
this.sides = 24;
|
|
@@ -5468,12 +5494,11 @@
|
|
|
5468
5494
|
plugin.particleCreated?.(this);
|
|
5469
5495
|
}
|
|
5470
5496
|
}
|
|
5471
|
-
isInsideCanvas() {
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
position.x <= canvasSize.width + radius);
|
|
5497
|
+
isInsideCanvas(direction) {
|
|
5498
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5499
|
+
}
|
|
5500
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5501
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5477
5502
|
}
|
|
5478
5503
|
isShowingBack() {
|
|
5479
5504
|
if (!this.roll) {
|
|
@@ -5498,13 +5523,13 @@
|
|
|
5498
5523
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5499
5524
|
}
|
|
5500
5525
|
reset() {
|
|
5501
|
-
for (const updater of this.
|
|
5526
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5502
5527
|
updater.reset?.(this);
|
|
5503
5528
|
}
|
|
5504
5529
|
}
|
|
5505
|
-
|
|
5530
|
+
#calcPosition = (position, zIndex) => {
|
|
5506
5531
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5507
|
-
const container = this
|
|
5532
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5508
5533
|
while (!signal.aborted) {
|
|
5509
5534
|
for (const plugin of plugins) {
|
|
5510
5535
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5516,10 +5541,10 @@
|
|
|
5516
5541
|
size: canvasSize,
|
|
5517
5542
|
position: posVec,
|
|
5518
5543
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5519
|
-
this
|
|
5520
|
-
this
|
|
5521
|
-
this
|
|
5522
|
-
this
|
|
5544
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5545
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5546
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5547
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5523
5548
|
let isValidPosition = true;
|
|
5524
5549
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5525
5550
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5535,8 +5560,8 @@
|
|
|
5535
5560
|
}
|
|
5536
5561
|
return posVec;
|
|
5537
5562
|
};
|
|
5538
|
-
|
|
5539
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5563
|
+
#calculateVelocity = () => {
|
|
5564
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5540
5565
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5541
5566
|
return res;
|
|
5542
5567
|
}
|
|
@@ -5552,27 +5577,86 @@
|
|
|
5552
5577
|
}
|
|
5553
5578
|
return res;
|
|
5554
5579
|
};
|
|
5555
|
-
|
|
5580
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5556
5581
|
fixOutMode({
|
|
5557
5582
|
outMode,
|
|
5558
5583
|
checkModes: [OutMode.bounce],
|
|
5559
5584
|
coord: pos.x,
|
|
5560
|
-
maxCoord: this.
|
|
5585
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5561
5586
|
setCb: (value) => (pos.x += value),
|
|
5562
5587
|
radius,
|
|
5563
5588
|
});
|
|
5564
5589
|
};
|
|
5565
|
-
|
|
5590
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5566
5591
|
fixOutMode({
|
|
5567
5592
|
outMode,
|
|
5568
5593
|
checkModes: [OutMode.bounce],
|
|
5569
5594
|
coord: pos.y,
|
|
5570
|
-
maxCoord: this.
|
|
5595
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5571
5596
|
setCb: (value) => (pos.y += value),
|
|
5572
5597
|
radius,
|
|
5573
5598
|
});
|
|
5574
5599
|
};
|
|
5575
|
-
|
|
5600
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5601
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5602
|
+
if (direction === OutModeDirection.bottom) {
|
|
5603
|
+
return {
|
|
5604
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5605
|
+
reason: "default",
|
|
5606
|
+
};
|
|
5607
|
+
}
|
|
5608
|
+
if (direction === OutModeDirection.left) {
|
|
5609
|
+
return {
|
|
5610
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5611
|
+
reason: "default",
|
|
5612
|
+
};
|
|
5613
|
+
}
|
|
5614
|
+
if (direction === OutModeDirection.right) {
|
|
5615
|
+
return {
|
|
5616
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5617
|
+
reason: "default",
|
|
5618
|
+
};
|
|
5619
|
+
}
|
|
5620
|
+
if (direction === OutModeDirection.top) {
|
|
5621
|
+
return {
|
|
5622
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5623
|
+
reason: "default",
|
|
5624
|
+
};
|
|
5625
|
+
}
|
|
5626
|
+
return {
|
|
5627
|
+
inside: position.x >= -radius &&
|
|
5628
|
+
position.y >= -radius &&
|
|
5629
|
+
position.y <= canvasSize.height + radius &&
|
|
5630
|
+
position.x <= canvasSize.width + radius,
|
|
5631
|
+
reason: "default",
|
|
5632
|
+
};
|
|
5633
|
+
};
|
|
5634
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5635
|
+
return {
|
|
5636
|
+
canvasSize: this.#container.canvas.size,
|
|
5637
|
+
direction,
|
|
5638
|
+
outMode,
|
|
5639
|
+
particle: this,
|
|
5640
|
+
radius: this.getRadius(),
|
|
5641
|
+
};
|
|
5642
|
+
};
|
|
5643
|
+
#getInsideCanvasResult = (data) => {
|
|
5644
|
+
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;
|
|
5645
|
+
if (!shapeCheck && !effectCheck) {
|
|
5646
|
+
return defaultResult;
|
|
5647
|
+
}
|
|
5648
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5649
|
+
if (shapeResult && effectResult) {
|
|
5650
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5651
|
+
return {
|
|
5652
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5653
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5654
|
+
reason: "combined",
|
|
5655
|
+
};
|
|
5656
|
+
}
|
|
5657
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5658
|
+
};
|
|
5659
|
+
#getRollColor = color => {
|
|
5576
5660
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5577
5661
|
return color;
|
|
5578
5662
|
}
|
|
@@ -5587,8 +5671,8 @@
|
|
|
5587
5671
|
}
|
|
5588
5672
|
return color;
|
|
5589
5673
|
};
|
|
5590
|
-
|
|
5591
|
-
const container = this
|
|
5674
|
+
#initPosition = position => {
|
|
5675
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5592
5676
|
if (!initialPosition) {
|
|
5593
5677
|
throw new Error("a valid position cannot be found for particle");
|
|
5594
5678
|
}
|
|
@@ -5611,45 +5695,58 @@
|
|
|
5611
5695
|
}
|
|
5612
5696
|
this.offset = Vector.origin;
|
|
5613
5697
|
};
|
|
5698
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5699
|
+
if (typeof result === "boolean") {
|
|
5700
|
+
return {
|
|
5701
|
+
inside: result,
|
|
5702
|
+
reason,
|
|
5703
|
+
};
|
|
5704
|
+
}
|
|
5705
|
+
return {
|
|
5706
|
+
inside: result.inside,
|
|
5707
|
+
margin: result.margin,
|
|
5708
|
+
reason: result.reason ?? reason,
|
|
5709
|
+
};
|
|
5710
|
+
};
|
|
5614
5711
|
}
|
|
5615
5712
|
|
|
5616
5713
|
class SpatialHashGrid {
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5714
|
+
#cellSize;
|
|
5715
|
+
#cells = new Map();
|
|
5716
|
+
#circlePool = [];
|
|
5717
|
+
#circlePoolIdx;
|
|
5718
|
+
#pendingCellSize;
|
|
5719
|
+
#rectanglePool = [];
|
|
5720
|
+
#rectanglePoolIdx;
|
|
5624
5721
|
constructor(cellSize) {
|
|
5625
|
-
this
|
|
5626
|
-
this
|
|
5627
|
-
this
|
|
5722
|
+
this.#cellSize = cellSize;
|
|
5723
|
+
this.#circlePoolIdx = 0;
|
|
5724
|
+
this.#rectanglePoolIdx = 0;
|
|
5628
5725
|
}
|
|
5629
5726
|
clear() {
|
|
5630
|
-
this.
|
|
5631
|
-
const pendingCellSize = this
|
|
5727
|
+
this.#cells.clear();
|
|
5728
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5632
5729
|
if (pendingCellSize) {
|
|
5633
|
-
this
|
|
5730
|
+
this.#cellSize = pendingCellSize;
|
|
5634
5731
|
}
|
|
5635
|
-
this
|
|
5732
|
+
this.#pendingCellSize = undefined;
|
|
5636
5733
|
}
|
|
5637
5734
|
insert(particle) {
|
|
5638
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5639
|
-
if (!this.
|
|
5640
|
-
this.
|
|
5735
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5736
|
+
if (!this.#cells.has(key)) {
|
|
5737
|
+
this.#cells.set(key, []);
|
|
5641
5738
|
}
|
|
5642
|
-
this.
|
|
5739
|
+
this.#cells.get(key)?.push(particle);
|
|
5643
5740
|
}
|
|
5644
5741
|
query(range, check, out = []) {
|
|
5645
|
-
const bounds = this
|
|
5742
|
+
const bounds = this.#getRangeBounds(range);
|
|
5646
5743
|
if (!bounds) {
|
|
5647
5744
|
return out;
|
|
5648
5745
|
}
|
|
5649
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5746
|
+
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);
|
|
5650
5747
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5651
5748
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5652
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5749
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5653
5750
|
if (!cellParticles) {
|
|
5654
5751
|
continue;
|
|
5655
5752
|
}
|
|
@@ -5666,29 +5763,29 @@
|
|
|
5666
5763
|
return out;
|
|
5667
5764
|
}
|
|
5668
5765
|
queryCircle(position, radius, check, out = []) {
|
|
5669
|
-
const circle = this
|
|
5670
|
-
this
|
|
5766
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5767
|
+
this.#releaseShapes();
|
|
5671
5768
|
return result;
|
|
5672
5769
|
}
|
|
5673
5770
|
queryRectangle(position, size, check, out = []) {
|
|
5674
|
-
const rect = this
|
|
5675
|
-
this
|
|
5771
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5772
|
+
this.#releaseShapes();
|
|
5676
5773
|
return result;
|
|
5677
5774
|
}
|
|
5678
5775
|
setCellSize(cellSize) {
|
|
5679
|
-
this
|
|
5776
|
+
this.#pendingCellSize = cellSize;
|
|
5680
5777
|
}
|
|
5681
|
-
|
|
5682
|
-
return (this
|
|
5778
|
+
#acquireCircle(x, y, r) {
|
|
5779
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5683
5780
|
}
|
|
5684
|
-
|
|
5685
|
-
return (this
|
|
5781
|
+
#acquireRectangle(x, y, w, h) {
|
|
5782
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5686
5783
|
}
|
|
5687
|
-
|
|
5688
|
-
const cellX = Math.floor(x / this
|
|
5784
|
+
#cellKeyFromCoords(x, y) {
|
|
5785
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5689
5786
|
return `${cellX}_${cellY}`;
|
|
5690
5787
|
}
|
|
5691
|
-
|
|
5788
|
+
#getRangeBounds(range) {
|
|
5692
5789
|
if (range instanceof Circle) {
|
|
5693
5790
|
const r = range.radius, { x, y } = range.position;
|
|
5694
5791
|
return {
|
|
@@ -5709,53 +5806,53 @@
|
|
|
5709
5806
|
}
|
|
5710
5807
|
return null;
|
|
5711
5808
|
}
|
|
5712
|
-
|
|
5713
|
-
this
|
|
5714
|
-
this
|
|
5809
|
+
#releaseShapes() {
|
|
5810
|
+
this.#circlePoolIdx = 0;
|
|
5811
|
+
this.#rectanglePoolIdx = 0;
|
|
5715
5812
|
}
|
|
5716
5813
|
}
|
|
5717
5814
|
|
|
5718
5815
|
class ParticlesManager {
|
|
5719
5816
|
checkParticlePositionPlugins;
|
|
5720
5817
|
grid;
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5818
|
+
#array;
|
|
5819
|
+
#container;
|
|
5820
|
+
#groupLimits;
|
|
5821
|
+
#limit;
|
|
5822
|
+
#nextId;
|
|
5823
|
+
#particleBuckets;
|
|
5824
|
+
#particleResetPlugins;
|
|
5825
|
+
#particleUpdatePlugins;
|
|
5826
|
+
#pluginManager;
|
|
5827
|
+
#pool;
|
|
5828
|
+
#postParticleUpdatePlugins;
|
|
5829
|
+
#postUpdatePlugins;
|
|
5830
|
+
#resizeFactor;
|
|
5831
|
+
#updatePlugins;
|
|
5832
|
+
#zBuckets;
|
|
5736
5833
|
constructor(pluginManager, container) {
|
|
5737
|
-
this
|
|
5738
|
-
this
|
|
5739
|
-
this
|
|
5740
|
-
this
|
|
5741
|
-
this
|
|
5742
|
-
this
|
|
5743
|
-
this
|
|
5744
|
-
this
|
|
5745
|
-
this
|
|
5834
|
+
this.#pluginManager = pluginManager;
|
|
5835
|
+
this.#container = container;
|
|
5836
|
+
this.#nextId = 0;
|
|
5837
|
+
this.#array = [];
|
|
5838
|
+
this.#pool = [];
|
|
5839
|
+
this.#limit = 0;
|
|
5840
|
+
this.#groupLimits = new Map();
|
|
5841
|
+
this.#particleBuckets = new Map();
|
|
5842
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5746
5843
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5747
5844
|
this.checkParticlePositionPlugins = [];
|
|
5748
|
-
this
|
|
5749
|
-
this
|
|
5750
|
-
this
|
|
5751
|
-
this
|
|
5752
|
-
this
|
|
5845
|
+
this.#particleResetPlugins = [];
|
|
5846
|
+
this.#particleUpdatePlugins = [];
|
|
5847
|
+
this.#postUpdatePlugins = [];
|
|
5848
|
+
this.#postParticleUpdatePlugins = [];
|
|
5849
|
+
this.#updatePlugins = [];
|
|
5753
5850
|
}
|
|
5754
5851
|
get count() {
|
|
5755
|
-
return this.
|
|
5852
|
+
return this.#array.length;
|
|
5756
5853
|
}
|
|
5757
5854
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5758
|
-
const limitMode = this.
|
|
5855
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5759
5856
|
if (limit > minLimit) {
|
|
5760
5857
|
switch (limitMode) {
|
|
5761
5858
|
case LimitMode.delete: {
|
|
@@ -5773,20 +5870,20 @@
|
|
|
5773
5870
|
}
|
|
5774
5871
|
}
|
|
5775
5872
|
try {
|
|
5776
|
-
const particle = this.
|
|
5777
|
-
particle.init(this
|
|
5873
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5874
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5778
5875
|
let canAdd = true;
|
|
5779
5876
|
if (initializer) {
|
|
5780
5877
|
canAdd = initializer(particle);
|
|
5781
5878
|
}
|
|
5782
5879
|
if (!canAdd) {
|
|
5783
|
-
this.
|
|
5880
|
+
this.#pool.push(particle);
|
|
5784
5881
|
return;
|
|
5785
5882
|
}
|
|
5786
|
-
this.
|
|
5787
|
-
this
|
|
5788
|
-
this
|
|
5789
|
-
this.
|
|
5883
|
+
this.#array.push(particle);
|
|
5884
|
+
this.#insertParticleIntoBucket(particle);
|
|
5885
|
+
this.#nextId++;
|
|
5886
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5790
5887
|
particle,
|
|
5791
5888
|
});
|
|
5792
5889
|
return particle;
|
|
@@ -5797,25 +5894,25 @@
|
|
|
5797
5894
|
return undefined;
|
|
5798
5895
|
}
|
|
5799
5896
|
clear() {
|
|
5800
|
-
this
|
|
5801
|
-
this.
|
|
5802
|
-
this
|
|
5897
|
+
this.#array = [];
|
|
5898
|
+
this.#particleBuckets.clear();
|
|
5899
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5803
5900
|
}
|
|
5804
5901
|
destroy() {
|
|
5805
|
-
this
|
|
5806
|
-
this.
|
|
5807
|
-
this.
|
|
5808
|
-
this
|
|
5902
|
+
this.#array = [];
|
|
5903
|
+
this.#pool.length = 0;
|
|
5904
|
+
this.#particleBuckets.clear();
|
|
5905
|
+
this.#zBuckets = [];
|
|
5809
5906
|
this.checkParticlePositionPlugins = [];
|
|
5810
|
-
this
|
|
5811
|
-
this
|
|
5812
|
-
this
|
|
5813
|
-
this
|
|
5814
|
-
this
|
|
5907
|
+
this.#particleResetPlugins = [];
|
|
5908
|
+
this.#particleUpdatePlugins = [];
|
|
5909
|
+
this.#postUpdatePlugins = [];
|
|
5910
|
+
this.#postParticleUpdatePlugins = [];
|
|
5911
|
+
this.#updatePlugins = [];
|
|
5815
5912
|
}
|
|
5816
5913
|
drawParticles(delta) {
|
|
5817
|
-
for (let i = this.
|
|
5818
|
-
const bucket = this
|
|
5914
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5915
|
+
const bucket = this.#zBuckets[i];
|
|
5819
5916
|
if (!bucket) {
|
|
5820
5917
|
continue;
|
|
5821
5918
|
}
|
|
@@ -5825,24 +5922,24 @@
|
|
|
5825
5922
|
}
|
|
5826
5923
|
}
|
|
5827
5924
|
filter(condition) {
|
|
5828
|
-
return this.
|
|
5925
|
+
return this.#array.filter(condition);
|
|
5829
5926
|
}
|
|
5830
5927
|
find(condition) {
|
|
5831
|
-
return this.
|
|
5928
|
+
return this.#array.find(condition);
|
|
5832
5929
|
}
|
|
5833
5930
|
get(index) {
|
|
5834
|
-
return this
|
|
5931
|
+
return this.#array[index];
|
|
5835
5932
|
}
|
|
5836
5933
|
async init() {
|
|
5837
|
-
const container = this
|
|
5934
|
+
const container = this.#container, options = container.actualOptions;
|
|
5838
5935
|
this.checkParticlePositionPlugins = [];
|
|
5839
|
-
this
|
|
5840
|
-
this
|
|
5841
|
-
this
|
|
5842
|
-
this
|
|
5843
|
-
this
|
|
5844
|
-
this.
|
|
5845
|
-
this
|
|
5936
|
+
this.#updatePlugins = [];
|
|
5937
|
+
this.#particleUpdatePlugins = [];
|
|
5938
|
+
this.#postUpdatePlugins = [];
|
|
5939
|
+
this.#particleResetPlugins = [];
|
|
5940
|
+
this.#postParticleUpdatePlugins = [];
|
|
5941
|
+
this.#particleBuckets.clear();
|
|
5942
|
+
this.#resetBuckets(container.zLayers);
|
|
5846
5943
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5847
5944
|
for (const plugin of container.plugins) {
|
|
5848
5945
|
if (plugin.redrawInit) {
|
|
@@ -5852,26 +5949,26 @@
|
|
|
5852
5949
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5853
5950
|
}
|
|
5854
5951
|
if (plugin.update) {
|
|
5855
|
-
this.
|
|
5952
|
+
this.#updatePlugins.push(plugin);
|
|
5856
5953
|
}
|
|
5857
5954
|
if (plugin.particleUpdate) {
|
|
5858
|
-
this.
|
|
5955
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5859
5956
|
}
|
|
5860
5957
|
if (plugin.postUpdate) {
|
|
5861
|
-
this.
|
|
5958
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5862
5959
|
}
|
|
5863
5960
|
if (plugin.particleReset) {
|
|
5864
|
-
this.
|
|
5961
|
+
this.#particleResetPlugins.push(plugin);
|
|
5865
5962
|
}
|
|
5866
5963
|
if (plugin.postParticleUpdate) {
|
|
5867
|
-
this.
|
|
5964
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5868
5965
|
}
|
|
5869
5966
|
}
|
|
5870
|
-
await this.
|
|
5871
|
-
for (const drawer of this.
|
|
5967
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5968
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5872
5969
|
await drawer.init?.(container);
|
|
5873
5970
|
}
|
|
5874
|
-
for (const drawer of this.
|
|
5971
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5875
5972
|
await drawer.init?.(container);
|
|
5876
5973
|
}
|
|
5877
5974
|
let handled = false;
|
|
@@ -5905,10 +6002,10 @@
|
|
|
5905
6002
|
async redraw() {
|
|
5906
6003
|
this.clear();
|
|
5907
6004
|
await this.init();
|
|
5908
|
-
this.
|
|
6005
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5909
6006
|
}
|
|
5910
6007
|
remove(particle, group, override) {
|
|
5911
|
-
this.removeAt(this.
|
|
6008
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5912
6009
|
}
|
|
5913
6010
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5914
6011
|
if (index < minIndex || index > this.count) {
|
|
@@ -5916,7 +6013,7 @@
|
|
|
5916
6013
|
}
|
|
5917
6014
|
let deleted = 0;
|
|
5918
6015
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5919
|
-
if (this
|
|
6016
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5920
6017
|
i--;
|
|
5921
6018
|
deleted++;
|
|
5922
6019
|
}
|
|
@@ -5926,9 +6023,9 @@
|
|
|
5926
6023
|
this.removeAt(minIndex, quantity, group);
|
|
5927
6024
|
}
|
|
5928
6025
|
setDensity() {
|
|
5929
|
-
const options = this.
|
|
6026
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5930
6027
|
let pluginsCount = 0;
|
|
5931
|
-
for (const plugin of this.
|
|
6028
|
+
for (const plugin of this.#container.plugins) {
|
|
5932
6029
|
if (plugin.particlesDensityCount) {
|
|
5933
6030
|
pluginsCount += plugin.particlesDensityCount();
|
|
5934
6031
|
}
|
|
@@ -5938,51 +6035,51 @@
|
|
|
5938
6035
|
if (!groupData) {
|
|
5939
6036
|
continue;
|
|
5940
6037
|
}
|
|
5941
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5942
|
-
this
|
|
6038
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
6039
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5943
6040
|
}
|
|
5944
|
-
this
|
|
6041
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5945
6042
|
}
|
|
5946
6043
|
setResizeFactor(factor) {
|
|
5947
|
-
this
|
|
6044
|
+
this.#resizeFactor = factor;
|
|
5948
6045
|
}
|
|
5949
6046
|
update(delta) {
|
|
5950
6047
|
this.grid.clear();
|
|
5951
|
-
for (const plugin of this
|
|
6048
|
+
for (const plugin of this.#updatePlugins) {
|
|
5952
6049
|
plugin.update?.(delta);
|
|
5953
6050
|
}
|
|
5954
|
-
const particlesToDelete = this
|
|
5955
|
-
for (const plugin of this
|
|
6051
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
6052
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5956
6053
|
plugin.postUpdate?.(delta);
|
|
5957
6054
|
}
|
|
5958
|
-
this
|
|
6055
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5959
6056
|
if (particlesToDelete.size) {
|
|
5960
6057
|
for (const particle of particlesToDelete) {
|
|
5961
6058
|
this.remove(particle);
|
|
5962
6059
|
}
|
|
5963
6060
|
}
|
|
5964
|
-
|
|
6061
|
+
this.#resizeFactor = undefined;
|
|
5965
6062
|
}
|
|
5966
|
-
|
|
5967
|
-
this.
|
|
6063
|
+
#addToPool = (...particles) => {
|
|
6064
|
+
this.#pool.push(...particles);
|
|
5968
6065
|
};
|
|
5969
|
-
|
|
6066
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5970
6067
|
const numberOptions = options.number;
|
|
5971
6068
|
if (!numberOptions.density.enable) {
|
|
5972
6069
|
if (group === undefined) {
|
|
5973
|
-
this
|
|
6070
|
+
this.#limit = numberOptions.limit.value;
|
|
5974
6071
|
}
|
|
5975
6072
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5976
|
-
this.
|
|
6073
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5977
6074
|
}
|
|
5978
6075
|
return;
|
|
5979
6076
|
}
|
|
5980
|
-
const densityFactor = this
|
|
6077
|
+
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);
|
|
5981
6078
|
if (group === undefined) {
|
|
5982
|
-
this
|
|
6079
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5983
6080
|
}
|
|
5984
6081
|
else {
|
|
5985
|
-
this.
|
|
6082
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5986
6083
|
}
|
|
5987
6084
|
if (particlesCount < particlesNumber) {
|
|
5988
6085
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5991,18 +6088,18 @@
|
|
|
5991
6088
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5992
6089
|
}
|
|
5993
6090
|
};
|
|
5994
|
-
|
|
6091
|
+
#createBuckets = (zLayers) => {
|
|
5995
6092
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5996
6093
|
return Array.from({ length: bucketCount }, () => []);
|
|
5997
6094
|
};
|
|
5998
|
-
|
|
5999
|
-
const maxBucketIndex = this.
|
|
6095
|
+
#getBucketIndex = (zIndex) => {
|
|
6096
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
6000
6097
|
if (maxBucketIndex <= minIndex) {
|
|
6001
6098
|
return minIndex;
|
|
6002
6099
|
}
|
|
6003
6100
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
6004
6101
|
};
|
|
6005
|
-
|
|
6102
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
6006
6103
|
let start = minIndex, end = bucket.length;
|
|
6007
6104
|
while (start < end) {
|
|
6008
6105
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -6019,8 +6116,8 @@
|
|
|
6019
6116
|
}
|
|
6020
6117
|
return start;
|
|
6021
6118
|
};
|
|
6022
|
-
|
|
6023
|
-
const container = this
|
|
6119
|
+
#initDensityFactor = densityOptions => {
|
|
6120
|
+
const container = this.#container;
|
|
6024
6121
|
if (!densityOptions.enable) {
|
|
6025
6122
|
return defaultDensityFactor;
|
|
6026
6123
|
}
|
|
@@ -6030,82 +6127,82 @@
|
|
|
6030
6127
|
}
|
|
6031
6128
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
6032
6129
|
};
|
|
6033
|
-
|
|
6034
|
-
const bucketIndex = this
|
|
6130
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6131
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6035
6132
|
if (!bucket) {
|
|
6036
6133
|
return;
|
|
6037
6134
|
}
|
|
6038
|
-
bucket.splice(this
|
|
6039
|
-
this.
|
|
6135
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6136
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
6040
6137
|
};
|
|
6041
|
-
|
|
6042
|
-
const particle = this
|
|
6138
|
+
#removeParticle = (index, group, override) => {
|
|
6139
|
+
const particle = this.#array[index];
|
|
6043
6140
|
if (!particle) {
|
|
6044
6141
|
return false;
|
|
6045
6142
|
}
|
|
6046
6143
|
if (particle.group !== group) {
|
|
6047
6144
|
return false;
|
|
6048
6145
|
}
|
|
6049
|
-
this.
|
|
6050
|
-
this
|
|
6146
|
+
this.#array.splice(index, deleteCount);
|
|
6147
|
+
this.#removeParticleFromBucket(particle);
|
|
6051
6148
|
particle.destroy(override);
|
|
6052
|
-
this.
|
|
6149
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
6053
6150
|
particle,
|
|
6054
6151
|
});
|
|
6055
|
-
this
|
|
6152
|
+
this.#addToPool(particle);
|
|
6056
6153
|
return true;
|
|
6057
6154
|
};
|
|
6058
|
-
|
|
6059
|
-
const bucketIndex = this.
|
|
6155
|
+
#removeParticleFromBucket = (particle) => {
|
|
6156
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6060
6157
|
if (!bucket) {
|
|
6061
|
-
this.
|
|
6158
|
+
this.#particleBuckets.delete(particle.id);
|
|
6062
6159
|
return;
|
|
6063
6160
|
}
|
|
6064
|
-
const particleIndex = this
|
|
6161
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
6065
6162
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
6066
|
-
this.
|
|
6163
|
+
this.#particleBuckets.delete(particle.id);
|
|
6067
6164
|
return;
|
|
6068
6165
|
}
|
|
6069
6166
|
bucket.splice(particleIndex, deleteCount);
|
|
6070
|
-
this.
|
|
6167
|
+
this.#particleBuckets.delete(particle.id);
|
|
6071
6168
|
};
|
|
6072
|
-
|
|
6169
|
+
#resetBuckets = (zLayers) => {
|
|
6073
6170
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6074
|
-
if (this.
|
|
6075
|
-
this
|
|
6171
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6172
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
6076
6173
|
return;
|
|
6077
6174
|
}
|
|
6078
|
-
for (const bucket of this
|
|
6175
|
+
for (const bucket of this.#zBuckets) {
|
|
6079
6176
|
bucket.length = minIndex;
|
|
6080
6177
|
}
|
|
6081
6178
|
};
|
|
6082
|
-
|
|
6083
|
-
const newBucketIndex = this
|
|
6179
|
+
#updateParticleBucket = (particle) => {
|
|
6180
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
6084
6181
|
if (currentBucketIndex === undefined) {
|
|
6085
|
-
this
|
|
6182
|
+
this.#insertParticleIntoBucket(particle);
|
|
6086
6183
|
return;
|
|
6087
6184
|
}
|
|
6088
6185
|
if (currentBucketIndex === newBucketIndex) {
|
|
6089
6186
|
return;
|
|
6090
6187
|
}
|
|
6091
|
-
const currentBucket = this
|
|
6188
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
6092
6189
|
if (currentBucket) {
|
|
6093
|
-
const particleIndex = this
|
|
6190
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
6094
6191
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
6095
6192
|
currentBucket.splice(particleIndex, deleteCount);
|
|
6096
6193
|
}
|
|
6097
6194
|
}
|
|
6098
|
-
const newBucket = this
|
|
6195
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
6099
6196
|
if (!newBucket) {
|
|
6100
|
-
this.
|
|
6197
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6101
6198
|
return;
|
|
6102
6199
|
}
|
|
6103
|
-
newBucket.splice(this
|
|
6104
|
-
this.
|
|
6200
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6201
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6105
6202
|
};
|
|
6106
|
-
|
|
6107
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
6108
|
-
for (const particle of this
|
|
6203
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6204
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6205
|
+
for (const particle of this.#array) {
|
|
6109
6206
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
6110
6207
|
particle.position.x *= resizeFactor.width;
|
|
6111
6208
|
particle.position.y *= resizeFactor.height;
|
|
@@ -6113,10 +6210,10 @@
|
|
|
6113
6210
|
particle.initialPosition.y *= resizeFactor.height;
|
|
6114
6211
|
}
|
|
6115
6212
|
particle.ignoresResizeRatio = false;
|
|
6116
|
-
for (const plugin of this
|
|
6213
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
6117
6214
|
plugin.particleReset?.(particle);
|
|
6118
6215
|
}
|
|
6119
|
-
for (const plugin of this
|
|
6216
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
6120
6217
|
if (particle.destroyed) {
|
|
6121
6218
|
break;
|
|
6122
6219
|
}
|
|
@@ -6130,36 +6227,36 @@
|
|
|
6130
6227
|
}
|
|
6131
6228
|
return particlesToDelete;
|
|
6132
6229
|
};
|
|
6133
|
-
|
|
6134
|
-
for (const particle of this
|
|
6230
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6231
|
+
for (const particle of this.#array) {
|
|
6135
6232
|
if (particle.destroyed) {
|
|
6136
6233
|
particlesToDelete.add(particle);
|
|
6137
6234
|
continue;
|
|
6138
6235
|
}
|
|
6139
|
-
for (const updater of this.
|
|
6236
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6140
6237
|
updater.update(particle, delta);
|
|
6141
6238
|
}
|
|
6142
6239
|
if (!particle.spawning) {
|
|
6143
|
-
for (const plugin of this
|
|
6240
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6144
6241
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6145
6242
|
}
|
|
6146
6243
|
}
|
|
6147
|
-
this
|
|
6244
|
+
this.#updateParticleBucket(particle);
|
|
6148
6245
|
}
|
|
6149
6246
|
};
|
|
6150
6247
|
}
|
|
6151
6248
|
|
|
6152
6249
|
class Retina {
|
|
6153
|
-
container;
|
|
6154
6250
|
pixelRatio;
|
|
6155
6251
|
reduceFactor;
|
|
6252
|
+
#container;
|
|
6156
6253
|
constructor(container) {
|
|
6157
|
-
this
|
|
6254
|
+
this.#container = container;
|
|
6158
6255
|
this.pixelRatio = defaultRatio;
|
|
6159
6256
|
this.reduceFactor = defaultReduceFactor;
|
|
6160
6257
|
}
|
|
6161
6258
|
init() {
|
|
6162
|
-
const container = this
|
|
6259
|
+
const container = this.#container, options = container.actualOptions;
|
|
6163
6260
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6164
6261
|
this.reduceFactor = defaultReduceFactor;
|
|
6165
6262
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6173,7 +6270,6 @@
|
|
|
6173
6270
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6174
6271
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6175
6272
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6176
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6177
6273
|
const maxDistance = props.maxDistance;
|
|
6178
6274
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6179
6275
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6211,73 +6307,73 @@
|
|
|
6211
6307
|
shapeDrawers;
|
|
6212
6308
|
started;
|
|
6213
6309
|
zLayers;
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6310
|
+
#delay;
|
|
6311
|
+
#delayTimeout;
|
|
6312
|
+
#delta = { value: 0, factor: 0 };
|
|
6313
|
+
#dispatchCallback;
|
|
6314
|
+
#drawAnimationFrame;
|
|
6315
|
+
#duration;
|
|
6316
|
+
#eventListeners;
|
|
6317
|
+
#firstStart;
|
|
6318
|
+
#initialSourceOptions;
|
|
6319
|
+
#lastFrameTime;
|
|
6320
|
+
#lifeTime;
|
|
6321
|
+
#onDestroy;
|
|
6322
|
+
#options;
|
|
6323
|
+
#paused;
|
|
6324
|
+
#pluginManager;
|
|
6325
|
+
#smooth;
|
|
6326
|
+
#sourceOptions;
|
|
6231
6327
|
constructor(params) {
|
|
6232
6328
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6233
|
-
this
|
|
6234
|
-
this
|
|
6235
|
-
this
|
|
6329
|
+
this.#pluginManager = pluginManager;
|
|
6330
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6331
|
+
this.#onDestroy = onDestroy;
|
|
6236
6332
|
this.id = Symbol(id);
|
|
6237
6333
|
this.fpsLimit = 120;
|
|
6238
6334
|
this.hdr = false;
|
|
6239
|
-
this
|
|
6240
|
-
this
|
|
6241
|
-
this
|
|
6242
|
-
this
|
|
6243
|
-
this
|
|
6335
|
+
this.#smooth = false;
|
|
6336
|
+
this.#delay = 0;
|
|
6337
|
+
this.#duration = 0;
|
|
6338
|
+
this.#lifeTime = 0;
|
|
6339
|
+
this.#firstStart = true;
|
|
6244
6340
|
this.started = false;
|
|
6245
6341
|
this.destroyed = false;
|
|
6246
|
-
this
|
|
6247
|
-
this
|
|
6342
|
+
this.#paused = true;
|
|
6343
|
+
this.#lastFrameTime = 0;
|
|
6248
6344
|
this.zLayers = 100;
|
|
6249
6345
|
this.pageHidden = false;
|
|
6250
|
-
this
|
|
6251
|
-
this
|
|
6346
|
+
this.#sourceOptions = sourceOptions;
|
|
6347
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6252
6348
|
this.effectDrawers = new Map();
|
|
6253
6349
|
this.shapeDrawers = new Map();
|
|
6254
6350
|
this.particleUpdaters = [];
|
|
6255
6351
|
this.retina = new Retina(this);
|
|
6256
|
-
this.canvas = new CanvasManager(this
|
|
6257
|
-
this.particles = new ParticlesManager(this
|
|
6352
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6353
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6258
6354
|
this.plugins = [];
|
|
6259
6355
|
this.particleDestroyedPlugins = [];
|
|
6260
6356
|
this.particleCreatedPlugins = [];
|
|
6261
6357
|
this.particlePositionPlugins = [];
|
|
6262
|
-
this
|
|
6263
|
-
this.actualOptions = loadContainerOptions(this
|
|
6264
|
-
this
|
|
6358
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6359
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6360
|
+
this.#eventListeners = new EventListeners(this);
|
|
6265
6361
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6266
6362
|
}
|
|
6267
6363
|
get animationStatus() {
|
|
6268
|
-
return !this
|
|
6364
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6269
6365
|
}
|
|
6270
6366
|
get options() {
|
|
6271
|
-
return this
|
|
6367
|
+
return this.#options;
|
|
6272
6368
|
}
|
|
6273
6369
|
get sourceOptions() {
|
|
6274
|
-
return this
|
|
6370
|
+
return this.#sourceOptions;
|
|
6275
6371
|
}
|
|
6276
6372
|
addLifeTime(value) {
|
|
6277
|
-
this
|
|
6373
|
+
this.#lifeTime += value;
|
|
6278
6374
|
}
|
|
6279
6375
|
alive() {
|
|
6280
|
-
return !this
|
|
6376
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6281
6377
|
}
|
|
6282
6378
|
destroy(remove = true) {
|
|
6283
6379
|
if (!guardCheck(this)) {
|
|
@@ -6299,13 +6395,13 @@
|
|
|
6299
6395
|
this.shapeDrawers = new Map();
|
|
6300
6396
|
this.particleUpdaters = [];
|
|
6301
6397
|
this.plugins.length = 0;
|
|
6302
|
-
this.
|
|
6398
|
+
this.#pluginManager.clearPlugins(this);
|
|
6303
6399
|
this.destroyed = true;
|
|
6304
|
-
this
|
|
6400
|
+
this.#onDestroy(remove);
|
|
6305
6401
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6306
6402
|
}
|
|
6307
6403
|
dispatchEvent(type, data) {
|
|
6308
|
-
this
|
|
6404
|
+
this.#dispatchCallback(type, {
|
|
6309
6405
|
container: this,
|
|
6310
6406
|
data,
|
|
6311
6407
|
});
|
|
@@ -6315,12 +6411,12 @@
|
|
|
6315
6411
|
return;
|
|
6316
6412
|
}
|
|
6317
6413
|
let refreshTime = force;
|
|
6318
|
-
this
|
|
6414
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6319
6415
|
if (refreshTime) {
|
|
6320
|
-
this
|
|
6416
|
+
this.#lastFrameTime = undefined;
|
|
6321
6417
|
refreshTime = false;
|
|
6322
6418
|
}
|
|
6323
|
-
this
|
|
6419
|
+
this.#nextFrame(timestamp);
|
|
6324
6420
|
});
|
|
6325
6421
|
}
|
|
6326
6422
|
async export(type, options = {}) {
|
|
@@ -6342,7 +6438,7 @@
|
|
|
6342
6438
|
return;
|
|
6343
6439
|
}
|
|
6344
6440
|
const allContainerPlugins = new Map();
|
|
6345
|
-
for (const plugin of this.
|
|
6441
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6346
6442
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6347
6443
|
if (containerPlugin.preInit) {
|
|
6348
6444
|
await containerPlugin.preInit();
|
|
@@ -6350,8 +6446,8 @@
|
|
|
6350
6446
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6351
6447
|
}
|
|
6352
6448
|
await this.initDrawersAndUpdaters();
|
|
6353
|
-
this
|
|
6354
|
-
this.actualOptions = loadContainerOptions(this
|
|
6449
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6450
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6355
6451
|
this.plugins.length = 0;
|
|
6356
6452
|
this.particleDestroyedPlugins.length = 0;
|
|
6357
6453
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6378,11 +6474,11 @@
|
|
|
6378
6474
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6379
6475
|
this.hdr = hdr;
|
|
6380
6476
|
this.zLayers = zLayers;
|
|
6381
|
-
this
|
|
6382
|
-
this
|
|
6383
|
-
this
|
|
6477
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6478
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6479
|
+
this.#lifeTime = 0;
|
|
6384
6480
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6385
|
-
this
|
|
6481
|
+
this.#smooth = smooth;
|
|
6386
6482
|
for (const plugin of this.plugins) {
|
|
6387
6483
|
await plugin.init?.();
|
|
6388
6484
|
}
|
|
@@ -6395,7 +6491,7 @@
|
|
|
6395
6491
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6396
6492
|
}
|
|
6397
6493
|
async initDrawersAndUpdaters() {
|
|
6398
|
-
const pluginManager = this
|
|
6494
|
+
const pluginManager = this.#pluginManager;
|
|
6399
6495
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6400
6496
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6401
6497
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6404,18 +6500,18 @@
|
|
|
6404
6500
|
if (!guardCheck(this)) {
|
|
6405
6501
|
return;
|
|
6406
6502
|
}
|
|
6407
|
-
if (this
|
|
6408
|
-
cancelAnimation(this
|
|
6409
|
-
|
|
6503
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6504
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6505
|
+
this.#drawAnimationFrame = undefined;
|
|
6410
6506
|
}
|
|
6411
|
-
if (this
|
|
6507
|
+
if (this.#paused) {
|
|
6412
6508
|
return;
|
|
6413
6509
|
}
|
|
6414
6510
|
for (const plugin of this.plugins) {
|
|
6415
6511
|
plugin.pause?.();
|
|
6416
6512
|
}
|
|
6417
6513
|
if (!this.pageHidden) {
|
|
6418
|
-
this
|
|
6514
|
+
this.#paused = true;
|
|
6419
6515
|
}
|
|
6420
6516
|
this.dispatchEvent(EventType.containerPaused);
|
|
6421
6517
|
}
|
|
@@ -6423,13 +6519,13 @@
|
|
|
6423
6519
|
if (!guardCheck(this)) {
|
|
6424
6520
|
return;
|
|
6425
6521
|
}
|
|
6426
|
-
const needsUpdate = this
|
|
6427
|
-
if (this
|
|
6428
|
-
this
|
|
6522
|
+
const needsUpdate = this.#paused || force;
|
|
6523
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6524
|
+
this.#firstStart = false;
|
|
6429
6525
|
return;
|
|
6430
6526
|
}
|
|
6431
|
-
if (this
|
|
6432
|
-
this
|
|
6527
|
+
if (this.#paused) {
|
|
6528
|
+
this.#paused = false;
|
|
6433
6529
|
}
|
|
6434
6530
|
if (needsUpdate) {
|
|
6435
6531
|
for (const plugin of this.plugins) {
|
|
@@ -6452,10 +6548,10 @@
|
|
|
6452
6548
|
if (!guardCheck(this)) {
|
|
6453
6549
|
return;
|
|
6454
6550
|
}
|
|
6455
|
-
this
|
|
6456
|
-
this
|
|
6457
|
-
this
|
|
6458
|
-
this.actualOptions = loadContainerOptions(this
|
|
6551
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6552
|
+
this.#sourceOptions = sourceOptions;
|
|
6553
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6554
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6459
6555
|
return this.refresh();
|
|
6460
6556
|
}
|
|
6461
6557
|
async start() {
|
|
@@ -6466,7 +6562,7 @@
|
|
|
6466
6562
|
this.started = true;
|
|
6467
6563
|
await new Promise(resolve => {
|
|
6468
6564
|
const start = async () => {
|
|
6469
|
-
this.
|
|
6565
|
+
this.#eventListeners.addListeners();
|
|
6470
6566
|
for (const plugin of this.plugins) {
|
|
6471
6567
|
await plugin.start?.();
|
|
6472
6568
|
}
|
|
@@ -6474,20 +6570,20 @@
|
|
|
6474
6570
|
this.play();
|
|
6475
6571
|
resolve();
|
|
6476
6572
|
};
|
|
6477
|
-
this
|
|
6573
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6478
6574
|
});
|
|
6479
6575
|
}
|
|
6480
6576
|
stop() {
|
|
6481
6577
|
if (!guardCheck(this) || !this.started) {
|
|
6482
6578
|
return;
|
|
6483
6579
|
}
|
|
6484
|
-
if (this
|
|
6485
|
-
clearTimeout(this
|
|
6486
|
-
|
|
6580
|
+
if (this.#delayTimeout) {
|
|
6581
|
+
clearTimeout(this.#delayTimeout);
|
|
6582
|
+
this.#delayTimeout = undefined;
|
|
6487
6583
|
}
|
|
6488
|
-
this
|
|
6584
|
+
this.#firstStart = true;
|
|
6489
6585
|
this.started = false;
|
|
6490
|
-
this.
|
|
6586
|
+
this.#eventListeners.removeListeners();
|
|
6491
6587
|
this.pause();
|
|
6492
6588
|
this.particles.clear();
|
|
6493
6589
|
this.canvas.stop();
|
|
@@ -6497,7 +6593,7 @@
|
|
|
6497
6593
|
this.particleCreatedPlugins.length = 0;
|
|
6498
6594
|
this.particleDestroyedPlugins.length = 0;
|
|
6499
6595
|
this.particlePositionPlugins.length = 0;
|
|
6500
|
-
this
|
|
6596
|
+
this.#sourceOptions = this.#options;
|
|
6501
6597
|
this.dispatchEvent(EventType.containerStopped);
|
|
6502
6598
|
}
|
|
6503
6599
|
updateActualOptions() {
|
|
@@ -6509,23 +6605,23 @@
|
|
|
6509
6605
|
}
|
|
6510
6606
|
return refresh;
|
|
6511
6607
|
}
|
|
6512
|
-
|
|
6608
|
+
#nextFrame = (timestamp) => {
|
|
6513
6609
|
try {
|
|
6514
|
-
if (!this
|
|
6515
|
-
this
|
|
6516
|
-
timestamp < this
|
|
6610
|
+
if (!this.#smooth &&
|
|
6611
|
+
this.#lastFrameTime !== undefined &&
|
|
6612
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6517
6613
|
this.draw(false);
|
|
6518
6614
|
return;
|
|
6519
6615
|
}
|
|
6520
|
-
this
|
|
6521
|
-
updateDelta(this
|
|
6522
|
-
this.addLifeTime(this.
|
|
6523
|
-
this
|
|
6524
|
-
if (this.
|
|
6616
|
+
this.#lastFrameTime ??= timestamp;
|
|
6617
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6618
|
+
this.addLifeTime(this.#delta.value);
|
|
6619
|
+
this.#lastFrameTime = timestamp;
|
|
6620
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6525
6621
|
this.draw(false);
|
|
6526
6622
|
return;
|
|
6527
6623
|
}
|
|
6528
|
-
this.canvas.render.drawParticles(this
|
|
6624
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6529
6625
|
if (!this.alive()) {
|
|
6530
6626
|
this.destroy();
|
|
6531
6627
|
return;
|
|
@@ -6546,10 +6642,10 @@
|
|
|
6546
6642
|
});
|
|
6547
6643
|
|
|
6548
6644
|
class BlendPluginInstance {
|
|
6549
|
-
|
|
6550
|
-
|
|
6645
|
+
#container;
|
|
6646
|
+
#defaultCompositeValue;
|
|
6551
6647
|
constructor(container) {
|
|
6552
|
-
this
|
|
6648
|
+
this.#container = container;
|
|
6553
6649
|
}
|
|
6554
6650
|
drawParticleCleanup(context, particle) {
|
|
6555
6651
|
if (!particle.options.blend?.enable) {
|
|
@@ -6566,14 +6662,14 @@
|
|
|
6566
6662
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6567
6663
|
}
|
|
6568
6664
|
drawSettingsCleanup(context) {
|
|
6569
|
-
if (!this
|
|
6665
|
+
if (!this.#defaultCompositeValue) {
|
|
6570
6666
|
return;
|
|
6571
6667
|
}
|
|
6572
|
-
context.globalCompositeOperation = this
|
|
6668
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6573
6669
|
}
|
|
6574
6670
|
drawSettingsSetup(context) {
|
|
6575
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6576
|
-
this
|
|
6671
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6672
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6577
6673
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6578
6674
|
}
|
|
6579
6675
|
}
|
|
@@ -6716,11 +6812,11 @@
|
|
|
6716
6812
|
class MovePluginInstance {
|
|
6717
6813
|
availablePathGenerators;
|
|
6718
6814
|
pathGenerators;
|
|
6719
|
-
|
|
6720
|
-
|
|
6815
|
+
#container;
|
|
6816
|
+
#pluginManager;
|
|
6721
6817
|
constructor(pluginManager, container) {
|
|
6722
|
-
this
|
|
6723
|
-
this
|
|
6818
|
+
this.#pluginManager = pluginManager;
|
|
6819
|
+
this.#container = container;
|
|
6724
6820
|
this.availablePathGenerators = new Map();
|
|
6725
6821
|
this.pathGenerators = new Map();
|
|
6726
6822
|
}
|
|
@@ -6751,7 +6847,7 @@
|
|
|
6751
6847
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6752
6848
|
inverse: gravityOptions.inverse,
|
|
6753
6849
|
};
|
|
6754
|
-
initSpin(this
|
|
6850
|
+
initSpin(this.#container, particle);
|
|
6755
6851
|
}
|
|
6756
6852
|
particleDestroyed(particle) {
|
|
6757
6853
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6762,7 +6858,7 @@
|
|
|
6762
6858
|
if (!moveOptions.enable) {
|
|
6763
6859
|
return;
|
|
6764
6860
|
}
|
|
6765
|
-
const container = this
|
|
6861
|
+
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;
|
|
6766
6862
|
if (moveOptions.spin.enable) {
|
|
6767
6863
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6768
6864
|
}
|
|
@@ -6772,18 +6868,18 @@
|
|
|
6772
6868
|
applyDistance(particle);
|
|
6773
6869
|
}
|
|
6774
6870
|
preInit() {
|
|
6775
|
-
return this
|
|
6871
|
+
return this.#init();
|
|
6776
6872
|
}
|
|
6777
6873
|
redrawInit() {
|
|
6778
|
-
return this
|
|
6874
|
+
return this.#init();
|
|
6779
6875
|
}
|
|
6780
6876
|
update() {
|
|
6781
6877
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6782
6878
|
pathGenerator.update();
|
|
6783
6879
|
}
|
|
6784
6880
|
}
|
|
6785
|
-
async
|
|
6786
|
-
const availablePathGenerators = await this.
|
|
6881
|
+
async #init() {
|
|
6882
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6787
6883
|
if (!availablePathGenerators) {
|
|
6788
6884
|
return;
|
|
6789
6885
|
}
|
|
@@ -6801,44 +6897,44 @@
|
|
|
6801
6897
|
});
|
|
6802
6898
|
|
|
6803
6899
|
class EmittersPluginInstance {
|
|
6804
|
-
container;
|
|
6805
|
-
|
|
6900
|
+
#container;
|
|
6901
|
+
#instancesManager;
|
|
6806
6902
|
constructor(instancesManager, container) {
|
|
6807
|
-
this
|
|
6808
|
-
this
|
|
6809
|
-
this.
|
|
6903
|
+
this.#instancesManager = instancesManager;
|
|
6904
|
+
this.#container = container;
|
|
6905
|
+
this.#instancesManager.initContainer(container);
|
|
6810
6906
|
}
|
|
6811
6907
|
async init() {
|
|
6812
|
-
const emittersOptions = this
|
|
6908
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
6813
6909
|
if (isArray(emittersOptions)) {
|
|
6814
6910
|
for (const emitterOptions of emittersOptions) {
|
|
6815
|
-
await this.
|
|
6911
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
6816
6912
|
}
|
|
6817
6913
|
}
|
|
6818
6914
|
else {
|
|
6819
|
-
await this.
|
|
6915
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
6820
6916
|
}
|
|
6821
6917
|
}
|
|
6822
6918
|
pause() {
|
|
6823
|
-
for (const emitter of this.
|
|
6919
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6824
6920
|
emitter.pause();
|
|
6825
6921
|
}
|
|
6826
6922
|
}
|
|
6827
6923
|
play() {
|
|
6828
|
-
for (const emitter of this.
|
|
6924
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6829
6925
|
emitter.play();
|
|
6830
6926
|
}
|
|
6831
6927
|
}
|
|
6832
6928
|
resize() {
|
|
6833
|
-
for (const emitter of this.
|
|
6929
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6834
6930
|
emitter.resize();
|
|
6835
6931
|
}
|
|
6836
6932
|
}
|
|
6837
6933
|
stop() {
|
|
6838
|
-
this.
|
|
6934
|
+
this.#instancesManager.clear(this.#container);
|
|
6839
6935
|
}
|
|
6840
6936
|
update(delta) {
|
|
6841
|
-
this.
|
|
6937
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
6842
6938
|
emitter.update(delta);
|
|
6843
6939
|
});
|
|
6844
6940
|
}
|
|
@@ -6871,16 +6967,16 @@
|
|
|
6871
6967
|
|
|
6872
6968
|
const defaultIndex = 0;
|
|
6873
6969
|
class EmittersInstancesManager {
|
|
6874
|
-
|
|
6875
|
-
|
|
6970
|
+
#containerArrays;
|
|
6971
|
+
#pluginManager;
|
|
6876
6972
|
constructor(pluginManager) {
|
|
6877
|
-
this
|
|
6878
|
-
this
|
|
6973
|
+
this.#containerArrays = new Map();
|
|
6974
|
+
this.#pluginManager = pluginManager;
|
|
6879
6975
|
}
|
|
6880
6976
|
async addEmitter(container, options, position) {
|
|
6881
6977
|
const emitterOptions = new Emitter();
|
|
6882
6978
|
emitterOptions.load(options);
|
|
6883
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
6979
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
6884
6980
|
this.removeEmitter(container, emitter);
|
|
6885
6981
|
}, emitterOptions, position);
|
|
6886
6982
|
await emitter.init();
|
|
@@ -6889,22 +6985,22 @@
|
|
|
6889
6985
|
}
|
|
6890
6986
|
clear(container) {
|
|
6891
6987
|
this.initContainer(container);
|
|
6892
|
-
this.
|
|
6988
|
+
this.#containerArrays.set(container, []);
|
|
6893
6989
|
}
|
|
6894
6990
|
getArray(container) {
|
|
6895
6991
|
this.initContainer(container);
|
|
6896
|
-
let array = this.
|
|
6992
|
+
let array = this.#containerArrays.get(container);
|
|
6897
6993
|
if (!array) {
|
|
6898
6994
|
array = [];
|
|
6899
|
-
this.
|
|
6995
|
+
this.#containerArrays.set(container, array);
|
|
6900
6996
|
}
|
|
6901
6997
|
return array;
|
|
6902
6998
|
}
|
|
6903
6999
|
initContainer(container) {
|
|
6904
|
-
if (this.
|
|
7000
|
+
if (this.#containerArrays.has(container)) {
|
|
6905
7001
|
return;
|
|
6906
7002
|
}
|
|
6907
|
-
this.
|
|
7003
|
+
this.#containerArrays.set(container, []);
|
|
6908
7004
|
container.getEmitter = (idxOrName) => {
|
|
6909
7005
|
const array = this.getArray(container);
|
|
6910
7006
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -6946,15 +7042,15 @@
|
|
|
6946
7042
|
|
|
6947
7043
|
const minimumLength = 0;
|
|
6948
7044
|
class TrailPluginInstance {
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
7045
|
+
#container;
|
|
7046
|
+
#pluginManager;
|
|
7047
|
+
#trailFill;
|
|
6952
7048
|
constructor(pluginManager, container) {
|
|
6953
|
-
this
|
|
6954
|
-
this
|
|
7049
|
+
this.#container = container;
|
|
7050
|
+
this.#pluginManager = pluginManager;
|
|
6955
7051
|
}
|
|
6956
7052
|
canvasClear() {
|
|
6957
|
-
const container = this
|
|
7053
|
+
const container = this.#container, trail = container.actualOptions.trail, trailFill = this.#trailFill;
|
|
6958
7054
|
if (!trail?.enable || !trailFill || trail.length <= minimumLength) {
|
|
6959
7055
|
return false;
|
|
6960
7056
|
}
|
|
@@ -6972,24 +7068,24 @@
|
|
|
6972
7068
|
}
|
|
6973
7069
|
async init() {
|
|
6974
7070
|
try {
|
|
6975
|
-
await this
|
|
7071
|
+
await this.#initTrail();
|
|
6976
7072
|
}
|
|
6977
7073
|
catch (e) {
|
|
6978
7074
|
getLogger().error(e);
|
|
6979
7075
|
}
|
|
6980
7076
|
}
|
|
6981
|
-
|
|
6982
|
-
const options = this.
|
|
7077
|
+
#initTrail = async () => {
|
|
7078
|
+
const options = this.#container.actualOptions, trail = options.trail;
|
|
6983
7079
|
if (!trail?.enable) {
|
|
6984
7080
|
return;
|
|
6985
7081
|
}
|
|
6986
7082
|
const trailFill = trail.fill, opacity = inverseFactorNumerator / trail.length;
|
|
6987
7083
|
if (trailFill.color) {
|
|
6988
|
-
const fillColor = rangeColorToRgb(this
|
|
7084
|
+
const fillColor = rangeColorToRgb(this.#pluginManager, trailFill.color);
|
|
6989
7085
|
if (!fillColor) {
|
|
6990
7086
|
return;
|
|
6991
7087
|
}
|
|
6992
|
-
this
|
|
7088
|
+
this.#trailFill = {
|
|
6993
7089
|
color: {
|
|
6994
7090
|
...fillColor,
|
|
6995
7091
|
},
|
|
@@ -7003,7 +7099,7 @@
|
|
|
7003
7099
|
}
|
|
7004
7100
|
const img = safeDocument().createElement("img");
|
|
7005
7101
|
img.addEventListener("load", () => {
|
|
7006
|
-
this
|
|
7102
|
+
this.#trailFill = {
|
|
7007
7103
|
image: img,
|
|
7008
7104
|
opacity,
|
|
7009
7105
|
};
|
|
@@ -7053,34 +7149,34 @@
|
|
|
7053
7149
|
spawnStrokeColor;
|
|
7054
7150
|
spawnStrokeOpacity;
|
|
7055
7151
|
spawnStrokeWidth;
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7152
|
+
#container;
|
|
7153
|
+
#currentDuration;
|
|
7154
|
+
#currentEmitDelay;
|
|
7155
|
+
#currentSpawnDelay;
|
|
7156
|
+
#duration;
|
|
7157
|
+
#emitDelay;
|
|
7158
|
+
#firstSpawn;
|
|
7159
|
+
#immortal;
|
|
7160
|
+
#initialPosition;
|
|
7161
|
+
#lifeCount;
|
|
7162
|
+
#mutationObserver;
|
|
7163
|
+
#particlesOptions;
|
|
7164
|
+
#paused;
|
|
7165
|
+
#pluginManager;
|
|
7166
|
+
#removeCallback;
|
|
7167
|
+
#resizeObserver;
|
|
7168
|
+
#shape;
|
|
7169
|
+
#size;
|
|
7170
|
+
#spawnDelay;
|
|
7171
|
+
#startParticlesAdded;
|
|
7076
7172
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
7077
|
-
this
|
|
7078
|
-
this
|
|
7079
|
-
this
|
|
7080
|
-
this
|
|
7081
|
-
this
|
|
7082
|
-
this
|
|
7083
|
-
this
|
|
7173
|
+
this.#pluginManager = pluginManager;
|
|
7174
|
+
this.#container = container;
|
|
7175
|
+
this.#removeCallback = removeCallback;
|
|
7176
|
+
this.#currentDuration = 0;
|
|
7177
|
+
this.#currentEmitDelay = 0;
|
|
7178
|
+
this.#currentSpawnDelay = 0;
|
|
7179
|
+
this.#initialPosition = position;
|
|
7084
7180
|
if (options instanceof Emitter) {
|
|
7085
7181
|
this.options = options;
|
|
7086
7182
|
}
|
|
@@ -7088,159 +7184,159 @@
|
|
|
7088
7184
|
this.options = new Emitter();
|
|
7089
7185
|
this.options.load(options);
|
|
7090
7186
|
}
|
|
7091
|
-
this
|
|
7187
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
7092
7188
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
7093
7189
|
container.retina.reduceFactor
|
|
7094
7190
|
: Infinity;
|
|
7095
|
-
this.position = this
|
|
7191
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
7096
7192
|
this.name = this.options.name;
|
|
7097
7193
|
this.fill = this.options.fill;
|
|
7098
|
-
this
|
|
7099
|
-
this
|
|
7194
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
7195
|
+
this.#startParticlesAdded = false;
|
|
7100
7196
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
7101
7197
|
particlesOptions.move ??= {};
|
|
7102
7198
|
particlesOptions.move.direction ??= this.options.direction;
|
|
7103
7199
|
if (this.options.spawn.fill?.color) {
|
|
7104
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
7200
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
7105
7201
|
}
|
|
7106
7202
|
if (this.options.spawn.stroke?.color) {
|
|
7107
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
7108
|
-
}
|
|
7109
|
-
this
|
|
7110
|
-
this
|
|
7111
|
-
this
|
|
7112
|
-
this.size = getSize(this
|
|
7113
|
-
this
|
|
7114
|
-
this
|
|
7203
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
7204
|
+
}
|
|
7205
|
+
this.#paused = !this.options.autoPlay;
|
|
7206
|
+
this.#particlesOptions = particlesOptions;
|
|
7207
|
+
this.#size = this.#calcSize();
|
|
7208
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
7209
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
7210
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
7115
7211
|
if (this.options.domId) {
|
|
7116
7212
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7117
7213
|
if (element) {
|
|
7118
|
-
this
|
|
7214
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
7119
7215
|
this.resize();
|
|
7120
7216
|
});
|
|
7121
|
-
this
|
|
7217
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
7122
7218
|
this.resize();
|
|
7123
7219
|
});
|
|
7124
|
-
this.
|
|
7220
|
+
this.#mutationObserver.observe(element, {
|
|
7125
7221
|
attributes: true,
|
|
7126
7222
|
attributeFilter: ["style", "width", "height"],
|
|
7127
7223
|
});
|
|
7128
|
-
this.
|
|
7224
|
+
this.#resizeObserver.observe(element);
|
|
7129
7225
|
}
|
|
7130
7226
|
}
|
|
7131
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
7227
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
7132
7228
|
if (shapeGenerator) {
|
|
7133
|
-
this
|
|
7229
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
7134
7230
|
}
|
|
7135
|
-
this.
|
|
7231
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
7136
7232
|
emitter: this,
|
|
7137
7233
|
});
|
|
7138
7234
|
this.play();
|
|
7139
7235
|
}
|
|
7140
7236
|
externalPause() {
|
|
7141
|
-
this
|
|
7237
|
+
this.#paused = true;
|
|
7142
7238
|
this.pause();
|
|
7143
7239
|
}
|
|
7144
7240
|
externalPlay() {
|
|
7145
|
-
this
|
|
7241
|
+
this.#paused = false;
|
|
7146
7242
|
this.play();
|
|
7147
7243
|
}
|
|
7148
7244
|
async init() {
|
|
7149
|
-
await this
|
|
7245
|
+
await this.#shape?.init();
|
|
7150
7246
|
}
|
|
7151
7247
|
pause() {
|
|
7152
|
-
if (this
|
|
7248
|
+
if (this.#paused) {
|
|
7153
7249
|
return;
|
|
7154
7250
|
}
|
|
7155
|
-
|
|
7251
|
+
this.#emitDelay = undefined;
|
|
7156
7252
|
}
|
|
7157
7253
|
play() {
|
|
7158
|
-
if (this
|
|
7254
|
+
if (this.#paused) {
|
|
7159
7255
|
return;
|
|
7160
7256
|
}
|
|
7161
|
-
if (!((this
|
|
7162
|
-
(this
|
|
7257
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
7258
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
7163
7259
|
return;
|
|
7164
7260
|
}
|
|
7165
|
-
const container = this
|
|
7166
|
-
if (this
|
|
7261
|
+
const container = this.#container;
|
|
7262
|
+
if (this.#emitDelay === undefined) {
|
|
7167
7263
|
const delay = getRangeValue(this.options.rate.delay);
|
|
7168
|
-
this
|
|
7264
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
7169
7265
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
7170
7266
|
: Infinity;
|
|
7171
7267
|
}
|
|
7172
|
-
if (this
|
|
7173
|
-
this
|
|
7268
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
7269
|
+
this.#prepareToDie();
|
|
7174
7270
|
}
|
|
7175
7271
|
}
|
|
7176
7272
|
resize() {
|
|
7177
|
-
const initialPosition = this
|
|
7273
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
7178
7274
|
this.position =
|
|
7179
7275
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
7180
7276
|
? initialPosition
|
|
7181
|
-
: this
|
|
7182
|
-
this
|
|
7183
|
-
this.size = getSize(this
|
|
7184
|
-
this
|
|
7277
|
+
: this.#calcPosition();
|
|
7278
|
+
this.#size = this.#calcSize();
|
|
7279
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
7280
|
+
this.#shape?.resize(this.position, this.size);
|
|
7185
7281
|
}
|
|
7186
7282
|
update(delta) {
|
|
7187
|
-
if (this
|
|
7283
|
+
if (this.#paused) {
|
|
7188
7284
|
return;
|
|
7189
7285
|
}
|
|
7190
|
-
const container = this
|
|
7191
|
-
if (this
|
|
7192
|
-
this
|
|
7193
|
-
this
|
|
7194
|
-
this
|
|
7286
|
+
const container = this.#container;
|
|
7287
|
+
if (this.#firstSpawn) {
|
|
7288
|
+
this.#firstSpawn = false;
|
|
7289
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
7290
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
7195
7291
|
}
|
|
7196
|
-
if (!this
|
|
7197
|
-
this
|
|
7198
|
-
this
|
|
7292
|
+
if (!this.#startParticlesAdded) {
|
|
7293
|
+
this.#startParticlesAdded = true;
|
|
7294
|
+
this.#emitParticles(this.options.startCount);
|
|
7199
7295
|
}
|
|
7200
|
-
if (this
|
|
7201
|
-
this
|
|
7202
|
-
if (this
|
|
7296
|
+
if (this.#duration !== undefined) {
|
|
7297
|
+
this.#currentDuration += delta.value;
|
|
7298
|
+
if (this.#currentDuration >= this.#duration) {
|
|
7203
7299
|
this.pause();
|
|
7204
|
-
if (this
|
|
7205
|
-
|
|
7300
|
+
if (this.#spawnDelay !== undefined) {
|
|
7301
|
+
this.#spawnDelay = undefined;
|
|
7206
7302
|
}
|
|
7207
|
-
if (!this
|
|
7208
|
-
this
|
|
7303
|
+
if (!this.#immortal) {
|
|
7304
|
+
this.#lifeCount--;
|
|
7209
7305
|
}
|
|
7210
|
-
if (this
|
|
7211
|
-
this.position = this
|
|
7212
|
-
this
|
|
7213
|
-
this
|
|
7306
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
7307
|
+
this.position = this.#calcPosition();
|
|
7308
|
+
this.#shape?.resize(this.position, this.size);
|
|
7309
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
7214
7310
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
7215
7311
|
container.retina.reduceFactor
|
|
7216
7312
|
: Infinity;
|
|
7217
7313
|
}
|
|
7218
7314
|
else {
|
|
7219
|
-
this
|
|
7315
|
+
this.#destroy();
|
|
7220
7316
|
}
|
|
7221
|
-
this
|
|
7222
|
-
|
|
7317
|
+
this.#currentDuration -= this.#duration;
|
|
7318
|
+
this.#duration = undefined;
|
|
7223
7319
|
}
|
|
7224
7320
|
}
|
|
7225
|
-
if (this
|
|
7226
|
-
this
|
|
7227
|
-
if (this
|
|
7228
|
-
this.
|
|
7321
|
+
if (this.#spawnDelay !== undefined) {
|
|
7322
|
+
this.#currentSpawnDelay += delta.value;
|
|
7323
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
7324
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
7229
7325
|
this.play();
|
|
7230
|
-
this
|
|
7231
|
-
|
|
7326
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
7327
|
+
this.#spawnDelay = undefined;
|
|
7232
7328
|
}
|
|
7233
7329
|
}
|
|
7234
|
-
if (this
|
|
7235
|
-
this
|
|
7236
|
-
if (this
|
|
7237
|
-
this
|
|
7238
|
-
this
|
|
7330
|
+
if (this.#emitDelay !== undefined) {
|
|
7331
|
+
this.#currentEmitDelay += delta.value;
|
|
7332
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
7333
|
+
this.#emit();
|
|
7334
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
7239
7335
|
}
|
|
7240
7336
|
}
|
|
7241
7337
|
}
|
|
7242
|
-
|
|
7243
|
-
const container = this
|
|
7338
|
+
#calcPosition() {
|
|
7339
|
+
const container = this.#container;
|
|
7244
7340
|
if (this.options.domId) {
|
|
7245
7341
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7246
7342
|
if (element) {
|
|
@@ -7256,8 +7352,8 @@
|
|
|
7256
7352
|
position: this.options.position,
|
|
7257
7353
|
});
|
|
7258
7354
|
}
|
|
7259
|
-
|
|
7260
|
-
const container = this
|
|
7355
|
+
#calcSize() {
|
|
7356
|
+
const container = this.#container;
|
|
7261
7357
|
if (this.options.domId) {
|
|
7262
7358
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7263
7359
|
if (element) {
|
|
@@ -7280,32 +7376,32 @@
|
|
|
7280
7376
|
return size;
|
|
7281
7377
|
})());
|
|
7282
7378
|
}
|
|
7283
|
-
|
|
7284
|
-
this
|
|
7285
|
-
this
|
|
7286
|
-
this
|
|
7287
|
-
this
|
|
7288
|
-
this
|
|
7289
|
-
this.
|
|
7379
|
+
#destroy = () => {
|
|
7380
|
+
this.#mutationObserver?.disconnect();
|
|
7381
|
+
this.#mutationObserver = undefined;
|
|
7382
|
+
this.#resizeObserver?.disconnect();
|
|
7383
|
+
this.#resizeObserver = undefined;
|
|
7384
|
+
this.#removeCallback(this);
|
|
7385
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
7290
7386
|
emitter: this,
|
|
7291
7387
|
});
|
|
7292
7388
|
};
|
|
7293
|
-
|
|
7294
|
-
if (this
|
|
7389
|
+
#emit() {
|
|
7390
|
+
if (this.#paused) {
|
|
7295
7391
|
return;
|
|
7296
7392
|
}
|
|
7297
7393
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
7298
|
-
this
|
|
7394
|
+
this.#emitParticles(quantity);
|
|
7299
7395
|
}
|
|
7300
|
-
|
|
7301
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
7396
|
+
#emitParticles(quantity) {
|
|
7397
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
7302
7398
|
{}), fillHslAnimation = this.options.spawn.fill?.color?.animation, fillEnabled = this.options.spawn.fill?.enable ?? !!this.options.spawn.fill?.color, fillOpacity = this.options.spawn.fill?.opacity === undefined
|
|
7303
7399
|
? defaultOpacity$1
|
|
7304
7400
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
7305
7401
|
? defaultOpacity$1
|
|
7306
7402
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
7307
7403
|
? defaultStrokeWidth
|
|
7308
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
7404
|
+
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.#container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this.#shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
|
|
7309
7405
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
7310
7406
|
const particlesOptions = needsCopy
|
|
7311
7407
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -7316,23 +7412,23 @@
|
|
|
7316
7412
|
this.spawnStrokeWidth = strokeWidth;
|
|
7317
7413
|
if (this.spawnFillColor) {
|
|
7318
7414
|
if (fillHslAnimation && maxValues) {
|
|
7319
|
-
this.spawnFillColor.h = this
|
|
7320
|
-
this.spawnFillColor.s = this
|
|
7321
|
-
this.spawnFillColor.l = this
|
|
7415
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
7416
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
7417
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
7322
7418
|
}
|
|
7323
7419
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
7324
7420
|
}
|
|
7325
7421
|
if (this.spawnStrokeColor) {
|
|
7326
7422
|
if (strokeHslAnimation && maxValues) {
|
|
7327
|
-
this.spawnStrokeColor.h = this
|
|
7328
|
-
this.spawnStrokeColor.s = this
|
|
7329
|
-
this.spawnStrokeColor.l = this
|
|
7423
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
7424
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
7425
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
7330
7426
|
}
|
|
7331
7427
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
7332
7428
|
}
|
|
7333
7429
|
let position = this.position;
|
|
7334
|
-
if (this
|
|
7335
|
-
const shapePosData = this.
|
|
7430
|
+
if (this.#shape) {
|
|
7431
|
+
const shapePosData = this.#shape.randomPosition();
|
|
7336
7432
|
if (shapePosData) {
|
|
7337
7433
|
position = shapePosData.position;
|
|
7338
7434
|
const replaceData = shapeOptions.replace;
|
|
@@ -7345,21 +7441,21 @@
|
|
|
7345
7441
|
}
|
|
7346
7442
|
}
|
|
7347
7443
|
if (position) {
|
|
7348
|
-
this.
|
|
7444
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
7349
7445
|
}
|
|
7350
7446
|
}
|
|
7351
7447
|
}
|
|
7352
|
-
|
|
7353
|
-
if (this
|
|
7448
|
+
#prepareToDie = () => {
|
|
7449
|
+
if (this.#paused) {
|
|
7354
7450
|
return;
|
|
7355
7451
|
}
|
|
7356
7452
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
7357
|
-
if ((this
|
|
7358
|
-
this
|
|
7453
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
7454
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
7359
7455
|
}
|
|
7360
7456
|
};
|
|
7361
|
-
|
|
7362
|
-
const container = this
|
|
7457
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
7458
|
+
const container = this.#container;
|
|
7363
7459
|
if (!animation.enable) {
|
|
7364
7460
|
return initValue;
|
|
7365
7461
|
}
|