@tsparticles/preset-bubbles 4.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* Preset v4.0
|
|
2
|
+
/* Preset v4.1.0 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -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),
|
|
@@ -3864,13 +3881,13 @@
|
|
|
3864
3881
|
|
|
3865
3882
|
class EmittersPlugin {
|
|
3866
3883
|
id = "emitters";
|
|
3867
|
-
|
|
3884
|
+
#instancesManager;
|
|
3868
3885
|
constructor(instancesManager) {
|
|
3869
|
-
this
|
|
3886
|
+
this.#instancesManager = instancesManager;
|
|
3870
3887
|
}
|
|
3871
3888
|
async getPlugin(container) {
|
|
3872
3889
|
const { EmittersPluginInstance } = await Promise.resolve().then(function () { return EmittersPluginInstance$1; });
|
|
3873
|
-
return new EmittersPluginInstance(this
|
|
3890
|
+
return new EmittersPluginInstance(this.#instancesManager, container);
|
|
3874
3891
|
}
|
|
3875
3892
|
loadOptions(_container, options, source) {
|
|
3876
3893
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -3923,7 +3940,7 @@
|
|
|
3923
3940
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
3924
3941
|
|
|
3925
3942
|
async function loadEmittersPluginSimple(engine) {
|
|
3926
|
-
engine.checkVersion("4.0
|
|
3943
|
+
engine.checkVersion("4.1.0");
|
|
3927
3944
|
await engine.pluginManager.register(async (e) => {
|
|
3928
3945
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
3929
3946
|
await addEmittersShapesManager(e);
|
|
@@ -4008,58 +4025,58 @@
|
|
|
4008
4025
|
}
|
|
4009
4026
|
}
|
|
4010
4027
|
class RenderManager {
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4028
|
+
#canvasClearPlugins;
|
|
4029
|
+
#canvasManager;
|
|
4030
|
+
#canvasPaintPlugins;
|
|
4031
|
+
#clearDrawPlugins;
|
|
4032
|
+
#colorPlugins;
|
|
4033
|
+
#container;
|
|
4034
|
+
#context;
|
|
4035
|
+
#contextSettings;
|
|
4036
|
+
#drawParticlePlugins;
|
|
4037
|
+
#drawParticlesCleanupPlugins;
|
|
4038
|
+
#drawParticlesSetupPlugins;
|
|
4039
|
+
#drawPlugins;
|
|
4040
|
+
#drawSettingsCleanupPlugins;
|
|
4041
|
+
#drawSettingsSetupPlugins;
|
|
4042
|
+
#pluginManager;
|
|
4043
|
+
#postDrawUpdaters;
|
|
4044
|
+
#preDrawUpdaters;
|
|
4045
|
+
#reusableColorStyles = {};
|
|
4046
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4047
|
+
#reusableTransform = {};
|
|
4031
4048
|
constructor(pluginManager, container, canvasManager) {
|
|
4032
|
-
this
|
|
4033
|
-
this
|
|
4034
|
-
this
|
|
4035
|
-
this
|
|
4036
|
-
this
|
|
4037
|
-
this
|
|
4038
|
-
this
|
|
4039
|
-
this
|
|
4040
|
-
this
|
|
4041
|
-
this
|
|
4042
|
-
this
|
|
4043
|
-
this
|
|
4044
|
-
this
|
|
4045
|
-
this
|
|
4046
|
-
this
|
|
4047
|
-
this
|
|
4049
|
+
this.#pluginManager = pluginManager;
|
|
4050
|
+
this.#container = container;
|
|
4051
|
+
this.#canvasManager = canvasManager;
|
|
4052
|
+
this.#context = null;
|
|
4053
|
+
this.#preDrawUpdaters = [];
|
|
4054
|
+
this.#postDrawUpdaters = [];
|
|
4055
|
+
this.#colorPlugins = [];
|
|
4056
|
+
this.#canvasClearPlugins = [];
|
|
4057
|
+
this.#canvasPaintPlugins = [];
|
|
4058
|
+
this.#clearDrawPlugins = [];
|
|
4059
|
+
this.#drawParticlePlugins = [];
|
|
4060
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4061
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4062
|
+
this.#drawPlugins = [];
|
|
4063
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4064
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4048
4065
|
}
|
|
4049
4066
|
get settings() {
|
|
4050
|
-
return this
|
|
4067
|
+
return this.#contextSettings;
|
|
4051
4068
|
}
|
|
4052
4069
|
canvasClear() {
|
|
4053
|
-
if (!this.
|
|
4070
|
+
if (!this.#container.actualOptions.clear) {
|
|
4054
4071
|
return;
|
|
4055
4072
|
}
|
|
4056
4073
|
this.draw(ctx => {
|
|
4057
|
-
clear(ctx, this.
|
|
4074
|
+
clear(ctx, this.#canvasManager.size);
|
|
4058
4075
|
});
|
|
4059
4076
|
}
|
|
4060
4077
|
clear() {
|
|
4061
4078
|
let pluginHandled = false;
|
|
4062
|
-
for (const plugin of this
|
|
4079
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4063
4080
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4064
4081
|
if (pluginHandled) {
|
|
4065
4082
|
break;
|
|
@@ -4072,21 +4089,21 @@
|
|
|
4072
4089
|
}
|
|
4073
4090
|
destroy() {
|
|
4074
4091
|
this.stop();
|
|
4075
|
-
this
|
|
4076
|
-
this
|
|
4077
|
-
this
|
|
4078
|
-
this
|
|
4079
|
-
this
|
|
4080
|
-
this
|
|
4081
|
-
this
|
|
4082
|
-
this
|
|
4083
|
-
this
|
|
4084
|
-
this
|
|
4085
|
-
this
|
|
4086
|
-
this
|
|
4092
|
+
this.#preDrawUpdaters = [];
|
|
4093
|
+
this.#postDrawUpdaters = [];
|
|
4094
|
+
this.#colorPlugins = [];
|
|
4095
|
+
this.#canvasClearPlugins = [];
|
|
4096
|
+
this.#canvasPaintPlugins = [];
|
|
4097
|
+
this.#clearDrawPlugins = [];
|
|
4098
|
+
this.#drawParticlePlugins = [];
|
|
4099
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4100
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4101
|
+
this.#drawPlugins = [];
|
|
4102
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4103
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4087
4104
|
}
|
|
4088
4105
|
draw(cb) {
|
|
4089
|
-
const ctx = this
|
|
4106
|
+
const ctx = this.#context;
|
|
4090
4107
|
if (!ctx) {
|
|
4091
4108
|
return;
|
|
4092
4109
|
}
|
|
@@ -4101,21 +4118,21 @@
|
|
|
4101
4118
|
return;
|
|
4102
4119
|
}
|
|
4103
4120
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4104
|
-
let [fColor, sColor] = this
|
|
4121
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4105
4122
|
fColor ??= pfColor;
|
|
4106
4123
|
sColor ??= psColor;
|
|
4107
4124
|
if (!fColor && !sColor) {
|
|
4108
4125
|
return;
|
|
4109
4126
|
}
|
|
4110
|
-
const container = this
|
|
4127
|
+
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;
|
|
4111
4128
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4112
4129
|
colorStyles.fill = fill;
|
|
4113
4130
|
colorStyles.stroke = stroke;
|
|
4114
4131
|
this.draw((context) => {
|
|
4115
|
-
for (const plugin of this
|
|
4132
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4116
4133
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4117
4134
|
}
|
|
4118
|
-
this
|
|
4135
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4119
4136
|
drawParticle({
|
|
4120
4137
|
container,
|
|
4121
4138
|
context,
|
|
@@ -4126,35 +4143,35 @@
|
|
|
4126
4143
|
opacity: opacity,
|
|
4127
4144
|
transform,
|
|
4128
4145
|
});
|
|
4129
|
-
this
|
|
4130
|
-
for (const plugin of this
|
|
4146
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4147
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4131
4148
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4132
4149
|
}
|
|
4133
4150
|
});
|
|
4134
4151
|
}
|
|
4135
4152
|
drawParticlePlugins(particle, delta) {
|
|
4136
4153
|
this.draw(ctx => {
|
|
4137
|
-
for (const plugin of this
|
|
4154
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4138
4155
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4139
4156
|
}
|
|
4140
4157
|
});
|
|
4141
4158
|
}
|
|
4142
4159
|
drawParticles(delta) {
|
|
4143
|
-
const { particles } = this
|
|
4160
|
+
const { particles } = this.#container;
|
|
4144
4161
|
this.clear();
|
|
4145
4162
|
particles.update(delta);
|
|
4146
4163
|
this.draw(ctx => {
|
|
4147
|
-
for (const plugin of this
|
|
4164
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4148
4165
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4149
4166
|
}
|
|
4150
|
-
for (const plugin of this
|
|
4167
|
+
for (const plugin of this.#drawPlugins) {
|
|
4151
4168
|
plugin.draw?.(ctx, delta);
|
|
4152
4169
|
}
|
|
4153
4170
|
particles.drawParticles(delta);
|
|
4154
|
-
for (const plugin of this
|
|
4171
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4155
4172
|
plugin.clearDraw?.(ctx, delta);
|
|
4156
4173
|
}
|
|
4157
|
-
for (const plugin of this
|
|
4174
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4158
4175
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4159
4176
|
}
|
|
4160
4177
|
});
|
|
@@ -4165,64 +4182,64 @@
|
|
|
4165
4182
|
this.paint();
|
|
4166
4183
|
}
|
|
4167
4184
|
initPlugins() {
|
|
4168
|
-
this
|
|
4169
|
-
this
|
|
4170
|
-
this
|
|
4171
|
-
this
|
|
4172
|
-
this
|
|
4173
|
-
this
|
|
4174
|
-
this
|
|
4175
|
-
this
|
|
4176
|
-
this
|
|
4177
|
-
this
|
|
4178
|
-
for (const plugin of this.
|
|
4185
|
+
this.#colorPlugins = [];
|
|
4186
|
+
this.#canvasClearPlugins = [];
|
|
4187
|
+
this.#canvasPaintPlugins = [];
|
|
4188
|
+
this.#clearDrawPlugins = [];
|
|
4189
|
+
this.#drawParticlePlugins = [];
|
|
4190
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4191
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4192
|
+
this.#drawPlugins = [];
|
|
4193
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4194
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4195
|
+
for (const plugin of this.#container.plugins) {
|
|
4179
4196
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4180
|
-
this.
|
|
4197
|
+
this.#colorPlugins.push(plugin);
|
|
4181
4198
|
}
|
|
4182
4199
|
if (plugin.canvasClear) {
|
|
4183
|
-
this.
|
|
4200
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4184
4201
|
}
|
|
4185
4202
|
if (plugin.canvasPaint) {
|
|
4186
|
-
this.
|
|
4203
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4187
4204
|
}
|
|
4188
4205
|
if (plugin.drawParticle) {
|
|
4189
|
-
this.
|
|
4206
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4190
4207
|
}
|
|
4191
4208
|
if (plugin.drawParticleSetup) {
|
|
4192
|
-
this.
|
|
4209
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4193
4210
|
}
|
|
4194
4211
|
if (plugin.drawParticleCleanup) {
|
|
4195
|
-
this.
|
|
4212
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4196
4213
|
}
|
|
4197
4214
|
if (plugin.draw) {
|
|
4198
|
-
this.
|
|
4215
|
+
this.#drawPlugins.push(plugin);
|
|
4199
4216
|
}
|
|
4200
4217
|
if (plugin.drawSettingsSetup) {
|
|
4201
|
-
this.
|
|
4218
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4202
4219
|
}
|
|
4203
4220
|
if (plugin.drawSettingsCleanup) {
|
|
4204
|
-
this.
|
|
4221
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4205
4222
|
}
|
|
4206
4223
|
if (plugin.clearDraw) {
|
|
4207
|
-
this.
|
|
4224
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4208
4225
|
}
|
|
4209
4226
|
}
|
|
4210
4227
|
}
|
|
4211
4228
|
initUpdaters() {
|
|
4212
|
-
this
|
|
4213
|
-
this
|
|
4214
|
-
for (const updater of this.
|
|
4229
|
+
this.#preDrawUpdaters = [];
|
|
4230
|
+
this.#postDrawUpdaters = [];
|
|
4231
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4215
4232
|
if (updater.afterDraw) {
|
|
4216
|
-
this.
|
|
4233
|
+
this.#postDrawUpdaters.push(updater);
|
|
4217
4234
|
}
|
|
4218
4235
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4219
|
-
this.
|
|
4236
|
+
this.#preDrawUpdaters.push(updater);
|
|
4220
4237
|
}
|
|
4221
4238
|
}
|
|
4222
4239
|
}
|
|
4223
4240
|
paint() {
|
|
4224
4241
|
let handled = false;
|
|
4225
|
-
for (const plugin of this
|
|
4242
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4226
4243
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4227
4244
|
if (handled) {
|
|
4228
4245
|
break;
|
|
@@ -4235,35 +4252,35 @@
|
|
|
4235
4252
|
}
|
|
4236
4253
|
paintBase(baseColor) {
|
|
4237
4254
|
this.draw(ctx => {
|
|
4238
|
-
paintBase(ctx, this.
|
|
4255
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4239
4256
|
});
|
|
4240
4257
|
}
|
|
4241
4258
|
paintImage(image, opacity) {
|
|
4242
4259
|
this.draw(ctx => {
|
|
4243
|
-
paintImage(ctx, this.
|
|
4260
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4244
4261
|
});
|
|
4245
4262
|
}
|
|
4246
4263
|
setContext(context) {
|
|
4247
|
-
this
|
|
4248
|
-
if (this
|
|
4249
|
-
this.
|
|
4264
|
+
this.#context = context;
|
|
4265
|
+
if (this.#context) {
|
|
4266
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4250
4267
|
}
|
|
4251
4268
|
}
|
|
4252
4269
|
setContextSettings(settings) {
|
|
4253
|
-
this
|
|
4270
|
+
this.#contextSettings = settings;
|
|
4254
4271
|
}
|
|
4255
4272
|
stop() {
|
|
4256
4273
|
this.draw(ctx => {
|
|
4257
|
-
clear(ctx, this.
|
|
4274
|
+
clear(ctx, this.#canvasManager.size);
|
|
4258
4275
|
});
|
|
4259
4276
|
}
|
|
4260
|
-
|
|
4261
|
-
for (const updater of this
|
|
4277
|
+
#applyPostDrawUpdaters = particle => {
|
|
4278
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4262
4279
|
updater.afterDraw?.(particle);
|
|
4263
4280
|
}
|
|
4264
4281
|
};
|
|
4265
|
-
|
|
4266
|
-
for (const updater of this
|
|
4282
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4283
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4267
4284
|
if (updater.getColorStyles) {
|
|
4268
4285
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4269
4286
|
if (fill) {
|
|
@@ -4282,22 +4299,22 @@
|
|
|
4282
4299
|
updater.beforeDraw?.(particle);
|
|
4283
4300
|
}
|
|
4284
4301
|
};
|
|
4285
|
-
|
|
4302
|
+
#getPluginParticleColors = particle => {
|
|
4286
4303
|
let fColor, sColor;
|
|
4287
|
-
for (const plugin of this
|
|
4304
|
+
for (const plugin of this.#colorPlugins) {
|
|
4288
4305
|
if (!fColor && plugin.particleFillColor) {
|
|
4289
|
-
fColor = rangeColorToHsl(this
|
|
4306
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4290
4307
|
}
|
|
4291
4308
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4292
|
-
sColor = rangeColorToHsl(this
|
|
4309
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4293
4310
|
}
|
|
4294
4311
|
if (fColor && sColor) {
|
|
4295
4312
|
break;
|
|
4296
4313
|
}
|
|
4297
4314
|
}
|
|
4298
|
-
this
|
|
4299
|
-
this
|
|
4300
|
-
return this
|
|
4315
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4316
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4317
|
+
return this.#reusablePluginColors;
|
|
4301
4318
|
};
|
|
4302
4319
|
}
|
|
4303
4320
|
|
|
@@ -4355,53 +4372,53 @@
|
|
|
4355
4372
|
renderCanvas;
|
|
4356
4373
|
size;
|
|
4357
4374
|
zoom = defaultZoom;
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4375
|
+
#container;
|
|
4376
|
+
#generated;
|
|
4377
|
+
#mutationObserver;
|
|
4378
|
+
#originalStyle;
|
|
4379
|
+
#pluginManager;
|
|
4380
|
+
#pointerEvents;
|
|
4381
|
+
#resizePlugins;
|
|
4382
|
+
#standardSize;
|
|
4383
|
+
#zoomCenter;
|
|
4367
4384
|
constructor(pluginManager, container) {
|
|
4368
|
-
this
|
|
4369
|
-
this
|
|
4385
|
+
this.#pluginManager = pluginManager;
|
|
4386
|
+
this.#container = container;
|
|
4370
4387
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4371
|
-
this
|
|
4388
|
+
this.#standardSize = {
|
|
4372
4389
|
height: 0,
|
|
4373
4390
|
width: 0,
|
|
4374
4391
|
};
|
|
4375
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4392
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4376
4393
|
this.size = {
|
|
4377
4394
|
height: stdSize.height * pxRatio,
|
|
4378
4395
|
width: stdSize.width * pxRatio,
|
|
4379
4396
|
};
|
|
4380
|
-
this
|
|
4381
|
-
this
|
|
4382
|
-
this
|
|
4397
|
+
this.#generated = false;
|
|
4398
|
+
this.#resizePlugins = [];
|
|
4399
|
+
this.#pointerEvents = "none";
|
|
4383
4400
|
}
|
|
4384
|
-
get
|
|
4385
|
-
return this.
|
|
4401
|
+
get #fullScreen() {
|
|
4402
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4386
4403
|
}
|
|
4387
4404
|
destroy() {
|
|
4388
4405
|
this.stop();
|
|
4389
|
-
if (this
|
|
4406
|
+
if (this.#generated) {
|
|
4390
4407
|
const element = this.domElement;
|
|
4391
4408
|
element?.remove();
|
|
4392
4409
|
this.domElement = undefined;
|
|
4393
4410
|
this.renderCanvas = undefined;
|
|
4394
4411
|
}
|
|
4395
4412
|
else {
|
|
4396
|
-
this
|
|
4413
|
+
this.#resetOriginalStyle();
|
|
4397
4414
|
}
|
|
4398
4415
|
this.render.destroy();
|
|
4399
|
-
this
|
|
4416
|
+
this.#resizePlugins = [];
|
|
4400
4417
|
}
|
|
4401
4418
|
getZoomCenter() {
|
|
4402
|
-
const pxRatio = this.
|
|
4403
|
-
if (this
|
|
4404
|
-
return this
|
|
4419
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4420
|
+
if (this.#zoomCenter) {
|
|
4421
|
+
return this.#zoomCenter;
|
|
4405
4422
|
}
|
|
4406
4423
|
return {
|
|
4407
4424
|
x: (width * half) / pxRatio,
|
|
@@ -4409,20 +4426,20 @@
|
|
|
4409
4426
|
};
|
|
4410
4427
|
}
|
|
4411
4428
|
init() {
|
|
4412
|
-
this
|
|
4429
|
+
this.#safeMutationObserver(obs => {
|
|
4413
4430
|
obs.disconnect();
|
|
4414
4431
|
});
|
|
4415
|
-
this
|
|
4432
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4416
4433
|
for (const record of records) {
|
|
4417
4434
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4418
|
-
this
|
|
4435
|
+
this.#repairStyle();
|
|
4419
4436
|
}
|
|
4420
4437
|
}
|
|
4421
4438
|
});
|
|
4422
4439
|
this.resize();
|
|
4423
|
-
this
|
|
4440
|
+
this.#initStyle();
|
|
4424
4441
|
this.initBackground();
|
|
4425
|
-
this
|
|
4442
|
+
this.#safeMutationObserver(obs => {
|
|
4426
4443
|
const element = this.domElement;
|
|
4427
4444
|
if (!element || !(element instanceof Node)) {
|
|
4428
4445
|
return;
|
|
@@ -4433,13 +4450,13 @@
|
|
|
4433
4450
|
this.render.init();
|
|
4434
4451
|
}
|
|
4435
4452
|
initBackground() {
|
|
4436
|
-
const
|
|
4453
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4437
4454
|
if (!element) {
|
|
4438
4455
|
return;
|
|
4439
4456
|
}
|
|
4440
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4457
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4441
4458
|
if (color) {
|
|
4442
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4459
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4443
4460
|
}
|
|
4444
4461
|
else {
|
|
4445
4462
|
elementStyle.backgroundColor = "";
|
|
@@ -4450,27 +4467,27 @@
|
|
|
4450
4467
|
elementStyle.backgroundSize = background.size || "";
|
|
4451
4468
|
}
|
|
4452
4469
|
initPlugins() {
|
|
4453
|
-
this
|
|
4454
|
-
for (const plugin of this.
|
|
4470
|
+
this.#resizePlugins = [];
|
|
4471
|
+
for (const plugin of this.#container.plugins) {
|
|
4455
4472
|
if (plugin.resize) {
|
|
4456
|
-
this.
|
|
4473
|
+
this.#resizePlugins.push(plugin);
|
|
4457
4474
|
}
|
|
4458
4475
|
}
|
|
4459
4476
|
}
|
|
4460
4477
|
loadCanvas(canvas) {
|
|
4461
|
-
if (this
|
|
4478
|
+
if (this.#generated && this.domElement) {
|
|
4462
4479
|
this.domElement.remove();
|
|
4463
4480
|
}
|
|
4464
|
-
const container = this
|
|
4481
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4465
4482
|
this.domElement = domCanvas;
|
|
4466
|
-
this
|
|
4483
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4467
4484
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4468
4485
|
const domElement = this.domElement;
|
|
4469
4486
|
if (domElement) {
|
|
4470
4487
|
domElement.ariaHidden = "true";
|
|
4471
|
-
this
|
|
4488
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4472
4489
|
}
|
|
4473
|
-
const standardSize = this
|
|
4490
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4474
4491
|
if (domElement) {
|
|
4475
4492
|
standardSize.height = domElement.offsetHeight;
|
|
4476
4493
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4479,7 +4496,7 @@
|
|
|
4479
4496
|
standardSize.height = renderCanvas.height;
|
|
4480
4497
|
standardSize.width = renderCanvas.width;
|
|
4481
4498
|
}
|
|
4482
|
-
const pxRatio = this.
|
|
4499
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4483
4500
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4484
4501
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4485
4502
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4490,12 +4507,12 @@
|
|
|
4490
4507
|
willReadFrequently: false,
|
|
4491
4508
|
});
|
|
4492
4509
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4493
|
-
this
|
|
4510
|
+
this.#safeMutationObserver(obs => {
|
|
4494
4511
|
obs.disconnect();
|
|
4495
4512
|
});
|
|
4496
4513
|
container.retina.init();
|
|
4497
4514
|
this.initBackground();
|
|
4498
|
-
this
|
|
4515
|
+
this.#safeMutationObserver(obs => {
|
|
4499
4516
|
const element = this.domElement;
|
|
4500
4517
|
if (!element || !(element instanceof Node)) {
|
|
4501
4518
|
return;
|
|
@@ -4508,11 +4525,11 @@
|
|
|
4508
4525
|
if (!element) {
|
|
4509
4526
|
return false;
|
|
4510
4527
|
}
|
|
4511
|
-
const container = this
|
|
4528
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4512
4529
|
if (renderCanvas === undefined) {
|
|
4513
4530
|
return false;
|
|
4514
4531
|
}
|
|
4515
|
-
const currentSize = container.canvas
|
|
4532
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4516
4533
|
width: element.offsetWidth,
|
|
4517
4534
|
height: element.offsetHeight,
|
|
4518
4535
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4531,7 +4548,7 @@
|
|
|
4531
4548
|
const canvasSize = this.size;
|
|
4532
4549
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4533
4550
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4534
|
-
if (this.
|
|
4551
|
+
if (this.#container.started) {
|
|
4535
4552
|
container.particles.setResizeFactor({
|
|
4536
4553
|
width: currentSize.width / oldSize.width,
|
|
4537
4554
|
height: currentSize.height / oldSize.height,
|
|
@@ -4544,46 +4561,46 @@
|
|
|
4544
4561
|
if (!element) {
|
|
4545
4562
|
return;
|
|
4546
4563
|
}
|
|
4547
|
-
this
|
|
4548
|
-
this
|
|
4564
|
+
this.#pointerEvents = type;
|
|
4565
|
+
this.#repairStyle();
|
|
4549
4566
|
}
|
|
4550
4567
|
setZoom(zoomLevel, center) {
|
|
4551
4568
|
this.zoom = zoomLevel;
|
|
4552
|
-
this
|
|
4569
|
+
this.#zoomCenter = center;
|
|
4553
4570
|
}
|
|
4554
4571
|
stop() {
|
|
4555
|
-
this
|
|
4572
|
+
this.#safeMutationObserver(obs => {
|
|
4556
4573
|
obs.disconnect();
|
|
4557
4574
|
});
|
|
4558
|
-
this
|
|
4575
|
+
this.#mutationObserver = undefined;
|
|
4559
4576
|
this.render.stop();
|
|
4560
4577
|
}
|
|
4561
4578
|
async windowResize() {
|
|
4562
4579
|
if (!this.domElement || !this.resize()) {
|
|
4563
4580
|
return;
|
|
4564
4581
|
}
|
|
4565
|
-
const container = this
|
|
4582
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4566
4583
|
container.particles.setDensity();
|
|
4567
|
-
this
|
|
4584
|
+
this.#applyResizePlugins();
|
|
4568
4585
|
if (needsRefresh) {
|
|
4569
4586
|
await container.refresh();
|
|
4570
4587
|
}
|
|
4571
4588
|
}
|
|
4572
|
-
|
|
4573
|
-
for (const plugin of this
|
|
4589
|
+
#applyResizePlugins = () => {
|
|
4590
|
+
for (const plugin of this.#resizePlugins) {
|
|
4574
4591
|
plugin.resize?.();
|
|
4575
4592
|
}
|
|
4576
4593
|
};
|
|
4577
|
-
|
|
4578
|
-
const element = this.domElement, options = this.
|
|
4594
|
+
#initStyle = () => {
|
|
4595
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4579
4596
|
if (!element) {
|
|
4580
4597
|
return;
|
|
4581
4598
|
}
|
|
4582
|
-
if (this
|
|
4583
|
-
this
|
|
4599
|
+
if (this.#fullScreen) {
|
|
4600
|
+
this.#setFullScreenStyle();
|
|
4584
4601
|
}
|
|
4585
4602
|
else {
|
|
4586
|
-
this
|
|
4603
|
+
this.#resetOriginalStyle();
|
|
4587
4604
|
}
|
|
4588
4605
|
for (const key in options.style) {
|
|
4589
4606
|
if (!key || !(key in options.style)) {
|
|
@@ -4596,72 +4613,72 @@
|
|
|
4596
4613
|
element.style.setProperty(key, value, "important");
|
|
4597
4614
|
}
|
|
4598
4615
|
};
|
|
4599
|
-
|
|
4616
|
+
#repairStyle = () => {
|
|
4600
4617
|
const element = this.domElement;
|
|
4601
4618
|
if (!element) {
|
|
4602
4619
|
return;
|
|
4603
4620
|
}
|
|
4604
|
-
this
|
|
4621
|
+
this.#safeMutationObserver(observer => {
|
|
4605
4622
|
observer.disconnect();
|
|
4606
4623
|
});
|
|
4607
|
-
this
|
|
4624
|
+
this.#initStyle();
|
|
4608
4625
|
this.initBackground();
|
|
4609
|
-
const pointerEvents = this
|
|
4626
|
+
const pointerEvents = this.#pointerEvents;
|
|
4610
4627
|
element.style.pointerEvents = pointerEvents;
|
|
4611
4628
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4612
|
-
this
|
|
4629
|
+
this.#safeMutationObserver(observer => {
|
|
4613
4630
|
if (!(element instanceof Node)) {
|
|
4614
4631
|
return;
|
|
4615
4632
|
}
|
|
4616
4633
|
observer.observe(element, { attributes: true });
|
|
4617
4634
|
});
|
|
4618
4635
|
};
|
|
4619
|
-
|
|
4620
|
-
const element = this.domElement, originalStyle = this
|
|
4636
|
+
#resetOriginalStyle = () => {
|
|
4637
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4621
4638
|
if (!element || !originalStyle) {
|
|
4622
4639
|
return;
|
|
4623
4640
|
}
|
|
4624
4641
|
setStyle(element, originalStyle, true);
|
|
4625
4642
|
};
|
|
4626
|
-
|
|
4627
|
-
if (!this
|
|
4643
|
+
#safeMutationObserver = callback => {
|
|
4644
|
+
if (!this.#mutationObserver) {
|
|
4628
4645
|
return;
|
|
4629
4646
|
}
|
|
4630
|
-
callback(this
|
|
4647
|
+
callback(this.#mutationObserver);
|
|
4631
4648
|
};
|
|
4632
|
-
|
|
4649
|
+
#setFullScreenStyle = () => {
|
|
4633
4650
|
const element = this.domElement;
|
|
4634
4651
|
if (!element) {
|
|
4635
4652
|
return;
|
|
4636
4653
|
}
|
|
4637
|
-
setStyle(element, getFullScreenStyle(this.
|
|
4654
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4638
4655
|
};
|
|
4639
4656
|
}
|
|
4640
4657
|
|
|
4641
4658
|
class EventListeners {
|
|
4642
|
-
container;
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4659
|
+
#container;
|
|
4660
|
+
#handlers;
|
|
4661
|
+
#resizeObserver;
|
|
4662
|
+
#resizeTimeout;
|
|
4646
4663
|
constructor(container) {
|
|
4647
|
-
this
|
|
4648
|
-
this
|
|
4664
|
+
this.#container = container;
|
|
4665
|
+
this.#handlers = {
|
|
4649
4666
|
visibilityChange: () => {
|
|
4650
|
-
this
|
|
4667
|
+
this.#handleVisibilityChange();
|
|
4651
4668
|
},
|
|
4652
4669
|
resize: () => {
|
|
4653
|
-
this
|
|
4670
|
+
this.#handleWindowResize();
|
|
4654
4671
|
},
|
|
4655
4672
|
};
|
|
4656
4673
|
}
|
|
4657
4674
|
addListeners() {
|
|
4658
|
-
this
|
|
4675
|
+
this.#manageListeners(true);
|
|
4659
4676
|
}
|
|
4660
4677
|
removeListeners() {
|
|
4661
|
-
this
|
|
4678
|
+
this.#manageListeners(false);
|
|
4662
4679
|
}
|
|
4663
|
-
|
|
4664
|
-
const container = this
|
|
4680
|
+
#handleVisibilityChange = () => {
|
|
4681
|
+
const container = this.#container, options = container.actualOptions;
|
|
4665
4682
|
if (!options.pauseOnBlur) {
|
|
4666
4683
|
return;
|
|
4667
4684
|
}
|
|
@@ -4679,24 +4696,24 @@
|
|
|
4679
4696
|
}
|
|
4680
4697
|
}
|
|
4681
4698
|
};
|
|
4682
|
-
|
|
4683
|
-
if (this
|
|
4684
|
-
clearTimeout(this
|
|
4685
|
-
|
|
4699
|
+
#handleWindowResize = () => {
|
|
4700
|
+
if (this.#resizeTimeout) {
|
|
4701
|
+
clearTimeout(this.#resizeTimeout);
|
|
4702
|
+
this.#resizeTimeout = undefined;
|
|
4686
4703
|
}
|
|
4687
4704
|
const handleResize = async () => {
|
|
4688
|
-
const canvas = this
|
|
4705
|
+
const canvas = this.#container.canvas;
|
|
4689
4706
|
await canvas.windowResize();
|
|
4690
4707
|
};
|
|
4691
|
-
this
|
|
4708
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4692
4709
|
};
|
|
4693
|
-
|
|
4694
|
-
const handlers = this
|
|
4695
|
-
this
|
|
4710
|
+
#manageListeners = add => {
|
|
4711
|
+
const handlers = this.#handlers;
|
|
4712
|
+
this.#manageResize(add);
|
|
4696
4713
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
4697
4714
|
};
|
|
4698
|
-
|
|
4699
|
-
const handlers = this
|
|
4715
|
+
#manageResize = add => {
|
|
4716
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
4700
4717
|
if (!options.resize.enable) {
|
|
4701
4718
|
return;
|
|
4702
4719
|
}
|
|
@@ -4705,22 +4722,22 @@
|
|
|
4705
4722
|
return;
|
|
4706
4723
|
}
|
|
4707
4724
|
const canvasEl = container.canvas.domElement;
|
|
4708
|
-
if (this
|
|
4725
|
+
if (this.#resizeObserver && !add) {
|
|
4709
4726
|
if (canvasEl) {
|
|
4710
|
-
this.
|
|
4727
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
4711
4728
|
}
|
|
4712
|
-
this.
|
|
4713
|
-
|
|
4729
|
+
this.#resizeObserver.disconnect();
|
|
4730
|
+
this.#resizeObserver = undefined;
|
|
4714
4731
|
}
|
|
4715
|
-
else if (!this
|
|
4716
|
-
this
|
|
4732
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4733
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4717
4734
|
const entry = entries.find(e => e.target === canvasEl);
|
|
4718
4735
|
if (!entry) {
|
|
4719
4736
|
return;
|
|
4720
4737
|
}
|
|
4721
|
-
this
|
|
4738
|
+
this.#handleWindowResize();
|
|
4722
4739
|
});
|
|
4723
|
-
this.
|
|
4740
|
+
this.#resizeObserver.observe(canvasEl);
|
|
4724
4741
|
}
|
|
4725
4742
|
};
|
|
4726
4743
|
}
|
|
@@ -4793,24 +4810,24 @@
|
|
|
4793
4810
|
unbreakable;
|
|
4794
4811
|
velocity;
|
|
4795
4812
|
zIndexFactor;
|
|
4796
|
-
|
|
4813
|
+
#cachedOpacityData = {
|
|
4797
4814
|
fillOpacity: defaultOpacity$1,
|
|
4798
4815
|
opacity: defaultOpacity$1,
|
|
4799
4816
|
strokeOpacity: defaultOpacity$1,
|
|
4800
4817
|
};
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4818
|
+
#cachedPosition = Vector3d.origin;
|
|
4819
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
4820
|
+
#cachedTransform = {
|
|
4804
4821
|
a: 1,
|
|
4805
4822
|
b: 0,
|
|
4806
4823
|
c: 0,
|
|
4807
4824
|
d: 1,
|
|
4808
4825
|
};
|
|
4809
|
-
|
|
4810
|
-
|
|
4826
|
+
#container;
|
|
4827
|
+
#pluginManager;
|
|
4811
4828
|
constructor(pluginManager, container) {
|
|
4812
|
-
this
|
|
4813
|
-
this
|
|
4829
|
+
this.#pluginManager = pluginManager;
|
|
4830
|
+
this.#container = container;
|
|
4814
4831
|
}
|
|
4815
4832
|
destroy(override) {
|
|
4816
4833
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -4819,7 +4836,7 @@
|
|
|
4819
4836
|
this.destroyed = true;
|
|
4820
4837
|
this.bubble.inRange = false;
|
|
4821
4838
|
this.slow.inRange = false;
|
|
4822
|
-
const container = this
|
|
4839
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
4823
4840
|
shapeDrawer?.particleDestroy?.(this);
|
|
4824
4841
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
4825
4842
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -4827,12 +4844,12 @@
|
|
|
4827
4844
|
for (const updater of container.particleUpdaters) {
|
|
4828
4845
|
updater.particleDestroyed?.(this, override);
|
|
4829
4846
|
}
|
|
4830
|
-
this.
|
|
4847
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
4831
4848
|
particle: this,
|
|
4832
4849
|
});
|
|
4833
4850
|
}
|
|
4834
4851
|
draw(delta) {
|
|
4835
|
-
const container = this
|
|
4852
|
+
const container = this.#container, render = container.canvas.render;
|
|
4836
4853
|
render.drawParticlePlugins(this, delta);
|
|
4837
4854
|
render.drawParticle(this, delta);
|
|
4838
4855
|
}
|
|
@@ -4840,50 +4857,50 @@
|
|
|
4840
4857
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
4841
4858
|
}
|
|
4842
4859
|
getFillColor() {
|
|
4843
|
-
return this
|
|
4860
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
4844
4861
|
}
|
|
4845
4862
|
getMass() {
|
|
4846
4863
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
4847
4864
|
}
|
|
4848
4865
|
getOpacity() {
|
|
4849
4866
|
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;
|
|
4850
|
-
this.
|
|
4851
|
-
this.
|
|
4852
|
-
this.
|
|
4853
|
-
return this
|
|
4867
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
4868
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
4869
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
4870
|
+
return this.#cachedOpacityData;
|
|
4854
4871
|
}
|
|
4855
4872
|
getPosition() {
|
|
4856
|
-
this.
|
|
4857
|
-
this.
|
|
4858
|
-
this.
|
|
4859
|
-
return this
|
|
4873
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
4874
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
4875
|
+
this.#cachedPosition.z = this.position.z;
|
|
4876
|
+
return this.#cachedPosition;
|
|
4860
4877
|
}
|
|
4861
4878
|
getRadius() {
|
|
4862
4879
|
return this.bubble.radius ?? this.size.value;
|
|
4863
4880
|
}
|
|
4864
4881
|
getRotateData() {
|
|
4865
4882
|
const angle = this.getAngle();
|
|
4866
|
-
this.
|
|
4867
|
-
this.
|
|
4868
|
-
return this
|
|
4883
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
4884
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
4885
|
+
return this.#cachedRotateData;
|
|
4869
4886
|
}
|
|
4870
4887
|
getStrokeColor() {
|
|
4871
|
-
return this
|
|
4888
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
4872
4889
|
}
|
|
4873
4890
|
getTransformData(externalTransform) {
|
|
4874
4891
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
4875
|
-
this.
|
|
4876
|
-
this.
|
|
4892
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
4893
|
+
this.#cachedTransform.b = rotating
|
|
4877
4894
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
4878
4895
|
: (externalTransform.b ?? defaultTransform.b);
|
|
4879
|
-
this.
|
|
4896
|
+
this.#cachedTransform.c = rotating
|
|
4880
4897
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
4881
4898
|
: (externalTransform.c ?? defaultTransform.c);
|
|
4882
|
-
this.
|
|
4883
|
-
return this
|
|
4899
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
4900
|
+
return this.#cachedTransform;
|
|
4884
4901
|
}
|
|
4885
4902
|
init(id, position, overrideOptions, group) {
|
|
4886
|
-
const container = this
|
|
4903
|
+
const container = this.#container;
|
|
4887
4904
|
this.id = id;
|
|
4888
4905
|
this.group = group;
|
|
4889
4906
|
this.justWarped = false;
|
|
@@ -4903,21 +4920,27 @@
|
|
|
4903
4920
|
moveSpeed: 0,
|
|
4904
4921
|
sizeAnimationSpeed: 0,
|
|
4905
4922
|
};
|
|
4923
|
+
this.size = {
|
|
4924
|
+
value: 1,
|
|
4925
|
+
max: 1,
|
|
4926
|
+
min: 1,
|
|
4927
|
+
enable: false,
|
|
4928
|
+
};
|
|
4906
4929
|
this.outType = ParticleOutType.normal;
|
|
4907
4930
|
this.ignoresResizeRatio = true;
|
|
4908
|
-
const
|
|
4931
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
4909
4932
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
4910
4933
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
4911
4934
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
4912
4935
|
if (overrideOptions) {
|
|
4913
|
-
if (overrideOptions.effect?.type) {
|
|
4936
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
4914
4937
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
4915
4938
|
if (effect) {
|
|
4916
4939
|
this.effect = effect;
|
|
4917
4940
|
effectOptions.load(overrideOptions.effect);
|
|
4918
4941
|
}
|
|
4919
4942
|
}
|
|
4920
|
-
if (overrideOptions.shape?.type) {
|
|
4943
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
4921
4944
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
4922
4945
|
if (shape) {
|
|
4923
4946
|
this.shape = shape;
|
|
@@ -4926,21 +4949,20 @@
|
|
|
4926
4949
|
}
|
|
4927
4950
|
}
|
|
4928
4951
|
if (this.effect === randomColorValue) {
|
|
4929
|
-
const availableEffects = [...this.
|
|
4952
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
4930
4953
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
4931
4954
|
}
|
|
4932
4955
|
if (this.shape === randomColorValue) {
|
|
4933
|
-
const availableShapes = [...this.
|
|
4956
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
4934
4957
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
4935
4958
|
}
|
|
4936
4959
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
4937
4960
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
4938
4961
|
particlesOptions.load(overrideOptions);
|
|
4939
|
-
const effectData = this.effectData;
|
|
4962
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
4940
4963
|
if (effectData) {
|
|
4941
4964
|
particlesOptions.load(effectData.particles);
|
|
4942
4965
|
}
|
|
4943
|
-
const shapeData = this.shapeData;
|
|
4944
4966
|
if (shapeData) {
|
|
4945
4967
|
particlesOptions.load(shapeData.particles);
|
|
4946
4968
|
}
|
|
@@ -4948,7 +4970,9 @@
|
|
|
4948
4970
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
4949
4971
|
this.options = particlesOptions;
|
|
4950
4972
|
container.retina.initParticle(this);
|
|
4951
|
-
|
|
4973
|
+
for (const updater of container.particleUpdaters) {
|
|
4974
|
+
updater.preInit?.(this);
|
|
4975
|
+
}
|
|
4952
4976
|
this.bubble = {
|
|
4953
4977
|
inRange: false,
|
|
4954
4978
|
};
|
|
@@ -4956,8 +4980,8 @@
|
|
|
4956
4980
|
inRange: false,
|
|
4957
4981
|
factor: 1,
|
|
4958
4982
|
};
|
|
4959
|
-
this
|
|
4960
|
-
this.initialVelocity = this
|
|
4983
|
+
this.#initPosition(position);
|
|
4984
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
4961
4985
|
this.velocity = this.initialVelocity.copy();
|
|
4962
4986
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
4963
4987
|
this.sides = 24;
|
|
@@ -4988,12 +5012,11 @@
|
|
|
4988
5012
|
plugin.particleCreated?.(this);
|
|
4989
5013
|
}
|
|
4990
5014
|
}
|
|
4991
|
-
isInsideCanvas() {
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
position.x <= canvasSize.width + radius);
|
|
5015
|
+
isInsideCanvas(direction) {
|
|
5016
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5017
|
+
}
|
|
5018
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5019
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
4997
5020
|
}
|
|
4998
5021
|
isShowingBack() {
|
|
4999
5022
|
if (!this.roll) {
|
|
@@ -5018,13 +5041,13 @@
|
|
|
5018
5041
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5019
5042
|
}
|
|
5020
5043
|
reset() {
|
|
5021
|
-
for (const updater of this.
|
|
5044
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5022
5045
|
updater.reset?.(this);
|
|
5023
5046
|
}
|
|
5024
5047
|
}
|
|
5025
|
-
|
|
5048
|
+
#calcPosition = (position, zIndex) => {
|
|
5026
5049
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5027
|
-
const container = this
|
|
5050
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5028
5051
|
while (!signal.aborted) {
|
|
5029
5052
|
for (const plugin of plugins) {
|
|
5030
5053
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5036,10 +5059,10 @@
|
|
|
5036
5059
|
size: canvasSize,
|
|
5037
5060
|
position: posVec,
|
|
5038
5061
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5039
|
-
this
|
|
5040
|
-
this
|
|
5041
|
-
this
|
|
5042
|
-
this
|
|
5062
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5063
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5064
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5065
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5043
5066
|
let isValidPosition = true;
|
|
5044
5067
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5045
5068
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5055,8 +5078,8 @@
|
|
|
5055
5078
|
}
|
|
5056
5079
|
return posVec;
|
|
5057
5080
|
};
|
|
5058
|
-
|
|
5059
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5081
|
+
#calculateVelocity = () => {
|
|
5082
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5060
5083
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5061
5084
|
return res;
|
|
5062
5085
|
}
|
|
@@ -5072,27 +5095,86 @@
|
|
|
5072
5095
|
}
|
|
5073
5096
|
return res;
|
|
5074
5097
|
};
|
|
5075
|
-
|
|
5098
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5076
5099
|
fixOutMode({
|
|
5077
5100
|
outMode,
|
|
5078
5101
|
checkModes: [OutMode.bounce],
|
|
5079
5102
|
coord: pos.x,
|
|
5080
|
-
maxCoord: this.
|
|
5103
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5081
5104
|
setCb: (value) => (pos.x += value),
|
|
5082
5105
|
radius,
|
|
5083
5106
|
});
|
|
5084
5107
|
};
|
|
5085
|
-
|
|
5108
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5086
5109
|
fixOutMode({
|
|
5087
5110
|
outMode,
|
|
5088
5111
|
checkModes: [OutMode.bounce],
|
|
5089
5112
|
coord: pos.y,
|
|
5090
|
-
maxCoord: this.
|
|
5113
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5091
5114
|
setCb: (value) => (pos.y += value),
|
|
5092
5115
|
radius,
|
|
5093
5116
|
});
|
|
5094
5117
|
};
|
|
5095
|
-
|
|
5118
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5119
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5120
|
+
if (direction === OutModeDirection.bottom) {
|
|
5121
|
+
return {
|
|
5122
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5123
|
+
reason: "default",
|
|
5124
|
+
};
|
|
5125
|
+
}
|
|
5126
|
+
if (direction === OutModeDirection.left) {
|
|
5127
|
+
return {
|
|
5128
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5129
|
+
reason: "default",
|
|
5130
|
+
};
|
|
5131
|
+
}
|
|
5132
|
+
if (direction === OutModeDirection.right) {
|
|
5133
|
+
return {
|
|
5134
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5135
|
+
reason: "default",
|
|
5136
|
+
};
|
|
5137
|
+
}
|
|
5138
|
+
if (direction === OutModeDirection.top) {
|
|
5139
|
+
return {
|
|
5140
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5141
|
+
reason: "default",
|
|
5142
|
+
};
|
|
5143
|
+
}
|
|
5144
|
+
return {
|
|
5145
|
+
inside: position.x >= -radius &&
|
|
5146
|
+
position.y >= -radius &&
|
|
5147
|
+
position.y <= canvasSize.height + radius &&
|
|
5148
|
+
position.x <= canvasSize.width + radius,
|
|
5149
|
+
reason: "default",
|
|
5150
|
+
};
|
|
5151
|
+
};
|
|
5152
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5153
|
+
return {
|
|
5154
|
+
canvasSize: this.#container.canvas.size,
|
|
5155
|
+
direction,
|
|
5156
|
+
outMode,
|
|
5157
|
+
particle: this,
|
|
5158
|
+
radius: this.getRadius(),
|
|
5159
|
+
};
|
|
5160
|
+
};
|
|
5161
|
+
#getInsideCanvasResult = (data) => {
|
|
5162
|
+
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;
|
|
5163
|
+
if (!shapeCheck && !effectCheck) {
|
|
5164
|
+
return defaultResult;
|
|
5165
|
+
}
|
|
5166
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5167
|
+
if (shapeResult && effectResult) {
|
|
5168
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5169
|
+
return {
|
|
5170
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5171
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5172
|
+
reason: "combined",
|
|
5173
|
+
};
|
|
5174
|
+
}
|
|
5175
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5176
|
+
};
|
|
5177
|
+
#getRollColor = color => {
|
|
5096
5178
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5097
5179
|
return color;
|
|
5098
5180
|
}
|
|
@@ -5107,8 +5189,8 @@
|
|
|
5107
5189
|
}
|
|
5108
5190
|
return color;
|
|
5109
5191
|
};
|
|
5110
|
-
|
|
5111
|
-
const container = this
|
|
5192
|
+
#initPosition = position => {
|
|
5193
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5112
5194
|
if (!initialPosition) {
|
|
5113
5195
|
throw new Error("a valid position cannot be found for particle");
|
|
5114
5196
|
}
|
|
@@ -5131,45 +5213,58 @@
|
|
|
5131
5213
|
}
|
|
5132
5214
|
this.offset = Vector.origin;
|
|
5133
5215
|
};
|
|
5216
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5217
|
+
if (typeof result === "boolean") {
|
|
5218
|
+
return {
|
|
5219
|
+
inside: result,
|
|
5220
|
+
reason,
|
|
5221
|
+
};
|
|
5222
|
+
}
|
|
5223
|
+
return {
|
|
5224
|
+
inside: result.inside,
|
|
5225
|
+
margin: result.margin,
|
|
5226
|
+
reason: result.reason ?? reason,
|
|
5227
|
+
};
|
|
5228
|
+
};
|
|
5134
5229
|
}
|
|
5135
5230
|
|
|
5136
5231
|
class SpatialHashGrid {
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5232
|
+
#cellSize;
|
|
5233
|
+
#cells = new Map();
|
|
5234
|
+
#circlePool = [];
|
|
5235
|
+
#circlePoolIdx;
|
|
5236
|
+
#pendingCellSize;
|
|
5237
|
+
#rectanglePool = [];
|
|
5238
|
+
#rectanglePoolIdx;
|
|
5144
5239
|
constructor(cellSize) {
|
|
5145
|
-
this
|
|
5146
|
-
this
|
|
5147
|
-
this
|
|
5240
|
+
this.#cellSize = cellSize;
|
|
5241
|
+
this.#circlePoolIdx = 0;
|
|
5242
|
+
this.#rectanglePoolIdx = 0;
|
|
5148
5243
|
}
|
|
5149
5244
|
clear() {
|
|
5150
|
-
this.
|
|
5151
|
-
const pendingCellSize = this
|
|
5245
|
+
this.#cells.clear();
|
|
5246
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5152
5247
|
if (pendingCellSize) {
|
|
5153
|
-
this
|
|
5248
|
+
this.#cellSize = pendingCellSize;
|
|
5154
5249
|
}
|
|
5155
|
-
this
|
|
5250
|
+
this.#pendingCellSize = undefined;
|
|
5156
5251
|
}
|
|
5157
5252
|
insert(particle) {
|
|
5158
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5159
|
-
if (!this.
|
|
5160
|
-
this.
|
|
5253
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5254
|
+
if (!this.#cells.has(key)) {
|
|
5255
|
+
this.#cells.set(key, []);
|
|
5161
5256
|
}
|
|
5162
|
-
this.
|
|
5257
|
+
this.#cells.get(key)?.push(particle);
|
|
5163
5258
|
}
|
|
5164
5259
|
query(range, check, out = []) {
|
|
5165
|
-
const bounds = this
|
|
5260
|
+
const bounds = this.#getRangeBounds(range);
|
|
5166
5261
|
if (!bounds) {
|
|
5167
5262
|
return out;
|
|
5168
5263
|
}
|
|
5169
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5264
|
+
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);
|
|
5170
5265
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5171
5266
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5172
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5267
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5173
5268
|
if (!cellParticles) {
|
|
5174
5269
|
continue;
|
|
5175
5270
|
}
|
|
@@ -5186,29 +5281,29 @@
|
|
|
5186
5281
|
return out;
|
|
5187
5282
|
}
|
|
5188
5283
|
queryCircle(position, radius, check, out = []) {
|
|
5189
|
-
const circle = this
|
|
5190
|
-
this
|
|
5284
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5285
|
+
this.#releaseShapes();
|
|
5191
5286
|
return result;
|
|
5192
5287
|
}
|
|
5193
5288
|
queryRectangle(position, size, check, out = []) {
|
|
5194
|
-
const rect = this
|
|
5195
|
-
this
|
|
5289
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5290
|
+
this.#releaseShapes();
|
|
5196
5291
|
return result;
|
|
5197
5292
|
}
|
|
5198
5293
|
setCellSize(cellSize) {
|
|
5199
|
-
this
|
|
5294
|
+
this.#pendingCellSize = cellSize;
|
|
5200
5295
|
}
|
|
5201
|
-
|
|
5202
|
-
return (this
|
|
5296
|
+
#acquireCircle(x, y, r) {
|
|
5297
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5203
5298
|
}
|
|
5204
|
-
|
|
5205
|
-
return (this
|
|
5299
|
+
#acquireRectangle(x, y, w, h) {
|
|
5300
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5206
5301
|
}
|
|
5207
|
-
|
|
5208
|
-
const cellX = Math.floor(x / this
|
|
5302
|
+
#cellKeyFromCoords(x, y) {
|
|
5303
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5209
5304
|
return `${cellX}_${cellY}`;
|
|
5210
5305
|
}
|
|
5211
|
-
|
|
5306
|
+
#getRangeBounds(range) {
|
|
5212
5307
|
if (range instanceof Circle) {
|
|
5213
5308
|
const r = range.radius, { x, y } = range.position;
|
|
5214
5309
|
return {
|
|
@@ -5229,53 +5324,53 @@
|
|
|
5229
5324
|
}
|
|
5230
5325
|
return null;
|
|
5231
5326
|
}
|
|
5232
|
-
|
|
5233
|
-
this
|
|
5234
|
-
this
|
|
5327
|
+
#releaseShapes() {
|
|
5328
|
+
this.#circlePoolIdx = 0;
|
|
5329
|
+
this.#rectanglePoolIdx = 0;
|
|
5235
5330
|
}
|
|
5236
5331
|
}
|
|
5237
5332
|
|
|
5238
5333
|
class ParticlesManager {
|
|
5239
5334
|
checkParticlePositionPlugins;
|
|
5240
5335
|
grid;
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5336
|
+
#array;
|
|
5337
|
+
#container;
|
|
5338
|
+
#groupLimits;
|
|
5339
|
+
#limit;
|
|
5340
|
+
#nextId;
|
|
5341
|
+
#particleBuckets;
|
|
5342
|
+
#particleResetPlugins;
|
|
5343
|
+
#particleUpdatePlugins;
|
|
5344
|
+
#pluginManager;
|
|
5345
|
+
#pool;
|
|
5346
|
+
#postParticleUpdatePlugins;
|
|
5347
|
+
#postUpdatePlugins;
|
|
5348
|
+
#resizeFactor;
|
|
5349
|
+
#updatePlugins;
|
|
5350
|
+
#zBuckets;
|
|
5256
5351
|
constructor(pluginManager, container) {
|
|
5257
|
-
this
|
|
5258
|
-
this
|
|
5259
|
-
this
|
|
5260
|
-
this
|
|
5261
|
-
this
|
|
5262
|
-
this
|
|
5263
|
-
this
|
|
5264
|
-
this
|
|
5265
|
-
this
|
|
5352
|
+
this.#pluginManager = pluginManager;
|
|
5353
|
+
this.#container = container;
|
|
5354
|
+
this.#nextId = 0;
|
|
5355
|
+
this.#array = [];
|
|
5356
|
+
this.#pool = [];
|
|
5357
|
+
this.#limit = 0;
|
|
5358
|
+
this.#groupLimits = new Map();
|
|
5359
|
+
this.#particleBuckets = new Map();
|
|
5360
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5266
5361
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5267
5362
|
this.checkParticlePositionPlugins = [];
|
|
5268
|
-
this
|
|
5269
|
-
this
|
|
5270
|
-
this
|
|
5271
|
-
this
|
|
5272
|
-
this
|
|
5363
|
+
this.#particleResetPlugins = [];
|
|
5364
|
+
this.#particleUpdatePlugins = [];
|
|
5365
|
+
this.#postUpdatePlugins = [];
|
|
5366
|
+
this.#postParticleUpdatePlugins = [];
|
|
5367
|
+
this.#updatePlugins = [];
|
|
5273
5368
|
}
|
|
5274
5369
|
get count() {
|
|
5275
|
-
return this.
|
|
5370
|
+
return this.#array.length;
|
|
5276
5371
|
}
|
|
5277
5372
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5278
|
-
const limitMode = this.
|
|
5373
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5279
5374
|
if (limit > minLimit) {
|
|
5280
5375
|
switch (limitMode) {
|
|
5281
5376
|
case LimitMode.delete: {
|
|
@@ -5293,20 +5388,20 @@
|
|
|
5293
5388
|
}
|
|
5294
5389
|
}
|
|
5295
5390
|
try {
|
|
5296
|
-
const particle = this.
|
|
5297
|
-
particle.init(this
|
|
5391
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5392
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5298
5393
|
let canAdd = true;
|
|
5299
5394
|
if (initializer) {
|
|
5300
5395
|
canAdd = initializer(particle);
|
|
5301
5396
|
}
|
|
5302
5397
|
if (!canAdd) {
|
|
5303
|
-
this.
|
|
5398
|
+
this.#pool.push(particle);
|
|
5304
5399
|
return;
|
|
5305
5400
|
}
|
|
5306
|
-
this.
|
|
5307
|
-
this
|
|
5308
|
-
this
|
|
5309
|
-
this.
|
|
5401
|
+
this.#array.push(particle);
|
|
5402
|
+
this.#insertParticleIntoBucket(particle);
|
|
5403
|
+
this.#nextId++;
|
|
5404
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5310
5405
|
particle,
|
|
5311
5406
|
});
|
|
5312
5407
|
return particle;
|
|
@@ -5317,25 +5412,25 @@
|
|
|
5317
5412
|
return undefined;
|
|
5318
5413
|
}
|
|
5319
5414
|
clear() {
|
|
5320
|
-
this
|
|
5321
|
-
this.
|
|
5322
|
-
this
|
|
5415
|
+
this.#array = [];
|
|
5416
|
+
this.#particleBuckets.clear();
|
|
5417
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5323
5418
|
}
|
|
5324
5419
|
destroy() {
|
|
5325
|
-
this
|
|
5326
|
-
this.
|
|
5327
|
-
this.
|
|
5328
|
-
this
|
|
5420
|
+
this.#array = [];
|
|
5421
|
+
this.#pool.length = 0;
|
|
5422
|
+
this.#particleBuckets.clear();
|
|
5423
|
+
this.#zBuckets = [];
|
|
5329
5424
|
this.checkParticlePositionPlugins = [];
|
|
5330
|
-
this
|
|
5331
|
-
this
|
|
5332
|
-
this
|
|
5333
|
-
this
|
|
5334
|
-
this
|
|
5425
|
+
this.#particleResetPlugins = [];
|
|
5426
|
+
this.#particleUpdatePlugins = [];
|
|
5427
|
+
this.#postUpdatePlugins = [];
|
|
5428
|
+
this.#postParticleUpdatePlugins = [];
|
|
5429
|
+
this.#updatePlugins = [];
|
|
5335
5430
|
}
|
|
5336
5431
|
drawParticles(delta) {
|
|
5337
|
-
for (let i = this.
|
|
5338
|
-
const bucket = this
|
|
5432
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5433
|
+
const bucket = this.#zBuckets[i];
|
|
5339
5434
|
if (!bucket) {
|
|
5340
5435
|
continue;
|
|
5341
5436
|
}
|
|
@@ -5345,24 +5440,24 @@
|
|
|
5345
5440
|
}
|
|
5346
5441
|
}
|
|
5347
5442
|
filter(condition) {
|
|
5348
|
-
return this.
|
|
5443
|
+
return this.#array.filter(condition);
|
|
5349
5444
|
}
|
|
5350
5445
|
find(condition) {
|
|
5351
|
-
return this.
|
|
5446
|
+
return this.#array.find(condition);
|
|
5352
5447
|
}
|
|
5353
5448
|
get(index) {
|
|
5354
|
-
return this
|
|
5449
|
+
return this.#array[index];
|
|
5355
5450
|
}
|
|
5356
5451
|
async init() {
|
|
5357
|
-
const container = this
|
|
5452
|
+
const container = this.#container, options = container.actualOptions;
|
|
5358
5453
|
this.checkParticlePositionPlugins = [];
|
|
5359
|
-
this
|
|
5360
|
-
this
|
|
5361
|
-
this
|
|
5362
|
-
this
|
|
5363
|
-
this
|
|
5364
|
-
this.
|
|
5365
|
-
this
|
|
5454
|
+
this.#updatePlugins = [];
|
|
5455
|
+
this.#particleUpdatePlugins = [];
|
|
5456
|
+
this.#postUpdatePlugins = [];
|
|
5457
|
+
this.#particleResetPlugins = [];
|
|
5458
|
+
this.#postParticleUpdatePlugins = [];
|
|
5459
|
+
this.#particleBuckets.clear();
|
|
5460
|
+
this.#resetBuckets(container.zLayers);
|
|
5366
5461
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5367
5462
|
for (const plugin of container.plugins) {
|
|
5368
5463
|
if (plugin.redrawInit) {
|
|
@@ -5372,26 +5467,26 @@
|
|
|
5372
5467
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5373
5468
|
}
|
|
5374
5469
|
if (plugin.update) {
|
|
5375
|
-
this.
|
|
5470
|
+
this.#updatePlugins.push(plugin);
|
|
5376
5471
|
}
|
|
5377
5472
|
if (plugin.particleUpdate) {
|
|
5378
|
-
this.
|
|
5473
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5379
5474
|
}
|
|
5380
5475
|
if (plugin.postUpdate) {
|
|
5381
|
-
this.
|
|
5476
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5382
5477
|
}
|
|
5383
5478
|
if (plugin.particleReset) {
|
|
5384
|
-
this.
|
|
5479
|
+
this.#particleResetPlugins.push(plugin);
|
|
5385
5480
|
}
|
|
5386
5481
|
if (plugin.postParticleUpdate) {
|
|
5387
|
-
this.
|
|
5482
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5388
5483
|
}
|
|
5389
5484
|
}
|
|
5390
|
-
await this.
|
|
5391
|
-
for (const drawer of this.
|
|
5485
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5486
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5392
5487
|
await drawer.init?.(container);
|
|
5393
5488
|
}
|
|
5394
|
-
for (const drawer of this.
|
|
5489
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5395
5490
|
await drawer.init?.(container);
|
|
5396
5491
|
}
|
|
5397
5492
|
let handled = false;
|
|
@@ -5425,10 +5520,10 @@
|
|
|
5425
5520
|
async redraw() {
|
|
5426
5521
|
this.clear();
|
|
5427
5522
|
await this.init();
|
|
5428
|
-
this.
|
|
5523
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5429
5524
|
}
|
|
5430
5525
|
remove(particle, group, override) {
|
|
5431
|
-
this.removeAt(this.
|
|
5526
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5432
5527
|
}
|
|
5433
5528
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5434
5529
|
if (index < minIndex || index > this.count) {
|
|
@@ -5436,7 +5531,7 @@
|
|
|
5436
5531
|
}
|
|
5437
5532
|
let deleted = 0;
|
|
5438
5533
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5439
|
-
if (this
|
|
5534
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5440
5535
|
i--;
|
|
5441
5536
|
deleted++;
|
|
5442
5537
|
}
|
|
@@ -5446,9 +5541,9 @@
|
|
|
5446
5541
|
this.removeAt(minIndex, quantity, group);
|
|
5447
5542
|
}
|
|
5448
5543
|
setDensity() {
|
|
5449
|
-
const options = this.
|
|
5544
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5450
5545
|
let pluginsCount = 0;
|
|
5451
|
-
for (const plugin of this.
|
|
5546
|
+
for (const plugin of this.#container.plugins) {
|
|
5452
5547
|
if (plugin.particlesDensityCount) {
|
|
5453
5548
|
pluginsCount += plugin.particlesDensityCount();
|
|
5454
5549
|
}
|
|
@@ -5458,51 +5553,51 @@
|
|
|
5458
5553
|
if (!groupData) {
|
|
5459
5554
|
continue;
|
|
5460
5555
|
}
|
|
5461
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5462
|
-
this
|
|
5556
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5557
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5463
5558
|
}
|
|
5464
|
-
this
|
|
5559
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5465
5560
|
}
|
|
5466
5561
|
setResizeFactor(factor) {
|
|
5467
|
-
this
|
|
5562
|
+
this.#resizeFactor = factor;
|
|
5468
5563
|
}
|
|
5469
5564
|
update(delta) {
|
|
5470
5565
|
this.grid.clear();
|
|
5471
|
-
for (const plugin of this
|
|
5566
|
+
for (const plugin of this.#updatePlugins) {
|
|
5472
5567
|
plugin.update?.(delta);
|
|
5473
5568
|
}
|
|
5474
|
-
const particlesToDelete = this
|
|
5475
|
-
for (const plugin of this
|
|
5569
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5570
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5476
5571
|
plugin.postUpdate?.(delta);
|
|
5477
5572
|
}
|
|
5478
|
-
this
|
|
5573
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5479
5574
|
if (particlesToDelete.size) {
|
|
5480
5575
|
for (const particle of particlesToDelete) {
|
|
5481
5576
|
this.remove(particle);
|
|
5482
5577
|
}
|
|
5483
5578
|
}
|
|
5484
|
-
|
|
5579
|
+
this.#resizeFactor = undefined;
|
|
5485
5580
|
}
|
|
5486
|
-
|
|
5487
|
-
this.
|
|
5581
|
+
#addToPool = (...particles) => {
|
|
5582
|
+
this.#pool.push(...particles);
|
|
5488
5583
|
};
|
|
5489
|
-
|
|
5584
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5490
5585
|
const numberOptions = options.number;
|
|
5491
5586
|
if (!numberOptions.density.enable) {
|
|
5492
5587
|
if (group === undefined) {
|
|
5493
|
-
this
|
|
5588
|
+
this.#limit = numberOptions.limit.value;
|
|
5494
5589
|
}
|
|
5495
5590
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5496
|
-
this.
|
|
5591
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5497
5592
|
}
|
|
5498
5593
|
return;
|
|
5499
5594
|
}
|
|
5500
|
-
const densityFactor = this
|
|
5595
|
+
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);
|
|
5501
5596
|
if (group === undefined) {
|
|
5502
|
-
this
|
|
5597
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5503
5598
|
}
|
|
5504
5599
|
else {
|
|
5505
|
-
this.
|
|
5600
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5506
5601
|
}
|
|
5507
5602
|
if (particlesCount < particlesNumber) {
|
|
5508
5603
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5511,18 +5606,18 @@
|
|
|
5511
5606
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5512
5607
|
}
|
|
5513
5608
|
};
|
|
5514
|
-
|
|
5609
|
+
#createBuckets = (zLayers) => {
|
|
5515
5610
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5516
5611
|
return Array.from({ length: bucketCount }, () => []);
|
|
5517
5612
|
};
|
|
5518
|
-
|
|
5519
|
-
const maxBucketIndex = this.
|
|
5613
|
+
#getBucketIndex = (zIndex) => {
|
|
5614
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5520
5615
|
if (maxBucketIndex <= minIndex) {
|
|
5521
5616
|
return minIndex;
|
|
5522
5617
|
}
|
|
5523
5618
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5524
5619
|
};
|
|
5525
|
-
|
|
5620
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5526
5621
|
let start = minIndex, end = bucket.length;
|
|
5527
5622
|
while (start < end) {
|
|
5528
5623
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5539,8 +5634,8 @@
|
|
|
5539
5634
|
}
|
|
5540
5635
|
return start;
|
|
5541
5636
|
};
|
|
5542
|
-
|
|
5543
|
-
const container = this
|
|
5637
|
+
#initDensityFactor = densityOptions => {
|
|
5638
|
+
const container = this.#container;
|
|
5544
5639
|
if (!densityOptions.enable) {
|
|
5545
5640
|
return defaultDensityFactor;
|
|
5546
5641
|
}
|
|
@@ -5550,82 +5645,82 @@
|
|
|
5550
5645
|
}
|
|
5551
5646
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5552
5647
|
};
|
|
5553
|
-
|
|
5554
|
-
const bucketIndex = this
|
|
5648
|
+
#insertParticleIntoBucket = (particle) => {
|
|
5649
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5555
5650
|
if (!bucket) {
|
|
5556
5651
|
return;
|
|
5557
5652
|
}
|
|
5558
|
-
bucket.splice(this
|
|
5559
|
-
this.
|
|
5653
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
5654
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5560
5655
|
};
|
|
5561
|
-
|
|
5562
|
-
const particle = this
|
|
5656
|
+
#removeParticle = (index, group, override) => {
|
|
5657
|
+
const particle = this.#array[index];
|
|
5563
5658
|
if (!particle) {
|
|
5564
5659
|
return false;
|
|
5565
5660
|
}
|
|
5566
5661
|
if (particle.group !== group) {
|
|
5567
5662
|
return false;
|
|
5568
5663
|
}
|
|
5569
|
-
this.
|
|
5570
|
-
this
|
|
5664
|
+
this.#array.splice(index, deleteCount);
|
|
5665
|
+
this.#removeParticleFromBucket(particle);
|
|
5571
5666
|
particle.destroy(override);
|
|
5572
|
-
this.
|
|
5667
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5573
5668
|
particle,
|
|
5574
5669
|
});
|
|
5575
|
-
this
|
|
5670
|
+
this.#addToPool(particle);
|
|
5576
5671
|
return true;
|
|
5577
5672
|
};
|
|
5578
|
-
|
|
5579
|
-
const bucketIndex = this.
|
|
5673
|
+
#removeParticleFromBucket = (particle) => {
|
|
5674
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5580
5675
|
if (!bucket) {
|
|
5581
|
-
this.
|
|
5676
|
+
this.#particleBuckets.delete(particle.id);
|
|
5582
5677
|
return;
|
|
5583
5678
|
}
|
|
5584
|
-
const particleIndex = this
|
|
5679
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5585
5680
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5586
|
-
this.
|
|
5681
|
+
this.#particleBuckets.delete(particle.id);
|
|
5587
5682
|
return;
|
|
5588
5683
|
}
|
|
5589
5684
|
bucket.splice(particleIndex, deleteCount);
|
|
5590
|
-
this.
|
|
5685
|
+
this.#particleBuckets.delete(particle.id);
|
|
5591
5686
|
};
|
|
5592
|
-
|
|
5687
|
+
#resetBuckets = (zLayers) => {
|
|
5593
5688
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5594
|
-
if (this.
|
|
5595
|
-
this
|
|
5689
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
5690
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5596
5691
|
return;
|
|
5597
5692
|
}
|
|
5598
|
-
for (const bucket of this
|
|
5693
|
+
for (const bucket of this.#zBuckets) {
|
|
5599
5694
|
bucket.length = minIndex;
|
|
5600
5695
|
}
|
|
5601
5696
|
};
|
|
5602
|
-
|
|
5603
|
-
const newBucketIndex = this
|
|
5697
|
+
#updateParticleBucket = (particle) => {
|
|
5698
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5604
5699
|
if (currentBucketIndex === undefined) {
|
|
5605
|
-
this
|
|
5700
|
+
this.#insertParticleIntoBucket(particle);
|
|
5606
5701
|
return;
|
|
5607
5702
|
}
|
|
5608
5703
|
if (currentBucketIndex === newBucketIndex) {
|
|
5609
5704
|
return;
|
|
5610
5705
|
}
|
|
5611
|
-
const currentBucket = this
|
|
5706
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5612
5707
|
if (currentBucket) {
|
|
5613
|
-
const particleIndex = this
|
|
5708
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5614
5709
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5615
5710
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5616
5711
|
}
|
|
5617
5712
|
}
|
|
5618
|
-
const newBucket = this
|
|
5713
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5619
5714
|
if (!newBucket) {
|
|
5620
|
-
this.
|
|
5715
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5621
5716
|
return;
|
|
5622
5717
|
}
|
|
5623
|
-
newBucket.splice(this
|
|
5624
|
-
this.
|
|
5718
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
5719
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5625
5720
|
};
|
|
5626
|
-
|
|
5627
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5628
|
-
for (const particle of this
|
|
5721
|
+
#updateParticlesPhase1 = (delta) => {
|
|
5722
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
5723
|
+
for (const particle of this.#array) {
|
|
5629
5724
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5630
5725
|
particle.position.x *= resizeFactor.width;
|
|
5631
5726
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5633,10 +5728,10 @@
|
|
|
5633
5728
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5634
5729
|
}
|
|
5635
5730
|
particle.ignoresResizeRatio = false;
|
|
5636
|
-
for (const plugin of this
|
|
5731
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5637
5732
|
plugin.particleReset?.(particle);
|
|
5638
5733
|
}
|
|
5639
|
-
for (const plugin of this
|
|
5734
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5640
5735
|
if (particle.destroyed) {
|
|
5641
5736
|
break;
|
|
5642
5737
|
}
|
|
@@ -5650,36 +5745,36 @@
|
|
|
5650
5745
|
}
|
|
5651
5746
|
return particlesToDelete;
|
|
5652
5747
|
};
|
|
5653
|
-
|
|
5654
|
-
for (const particle of this
|
|
5748
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
5749
|
+
for (const particle of this.#array) {
|
|
5655
5750
|
if (particle.destroyed) {
|
|
5656
5751
|
particlesToDelete.add(particle);
|
|
5657
5752
|
continue;
|
|
5658
5753
|
}
|
|
5659
|
-
for (const updater of this.
|
|
5754
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5660
5755
|
updater.update(particle, delta);
|
|
5661
5756
|
}
|
|
5662
5757
|
if (!particle.spawning) {
|
|
5663
|
-
for (const plugin of this
|
|
5758
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
5664
5759
|
plugin.postParticleUpdate?.(particle, delta);
|
|
5665
5760
|
}
|
|
5666
5761
|
}
|
|
5667
|
-
this
|
|
5762
|
+
this.#updateParticleBucket(particle);
|
|
5668
5763
|
}
|
|
5669
5764
|
};
|
|
5670
5765
|
}
|
|
5671
5766
|
|
|
5672
5767
|
class Retina {
|
|
5673
|
-
container;
|
|
5674
5768
|
pixelRatio;
|
|
5675
5769
|
reduceFactor;
|
|
5770
|
+
#container;
|
|
5676
5771
|
constructor(container) {
|
|
5677
|
-
this
|
|
5772
|
+
this.#container = container;
|
|
5678
5773
|
this.pixelRatio = defaultRatio;
|
|
5679
5774
|
this.reduceFactor = defaultReduceFactor;
|
|
5680
5775
|
}
|
|
5681
5776
|
init() {
|
|
5682
|
-
const container = this
|
|
5777
|
+
const container = this.#container, options = container.actualOptions;
|
|
5683
5778
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
5684
5779
|
this.reduceFactor = defaultReduceFactor;
|
|
5685
5780
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -5693,7 +5788,6 @@
|
|
|
5693
5788
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
5694
5789
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
5695
5790
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
5696
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
5697
5791
|
const maxDistance = props.maxDistance;
|
|
5698
5792
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
5699
5793
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -5731,73 +5825,73 @@
|
|
|
5731
5825
|
shapeDrawers;
|
|
5732
5826
|
started;
|
|
5733
5827
|
zLayers;
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5828
|
+
#delay;
|
|
5829
|
+
#delayTimeout;
|
|
5830
|
+
#delta = { value: 0, factor: 0 };
|
|
5831
|
+
#dispatchCallback;
|
|
5832
|
+
#drawAnimationFrame;
|
|
5833
|
+
#duration;
|
|
5834
|
+
#eventListeners;
|
|
5835
|
+
#firstStart;
|
|
5836
|
+
#initialSourceOptions;
|
|
5837
|
+
#lastFrameTime;
|
|
5838
|
+
#lifeTime;
|
|
5839
|
+
#onDestroy;
|
|
5840
|
+
#options;
|
|
5841
|
+
#paused;
|
|
5842
|
+
#pluginManager;
|
|
5843
|
+
#smooth;
|
|
5844
|
+
#sourceOptions;
|
|
5751
5845
|
constructor(params) {
|
|
5752
5846
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
5753
|
-
this
|
|
5754
|
-
this
|
|
5755
|
-
this
|
|
5847
|
+
this.#pluginManager = pluginManager;
|
|
5848
|
+
this.#dispatchCallback = dispatchCallback;
|
|
5849
|
+
this.#onDestroy = onDestroy;
|
|
5756
5850
|
this.id = Symbol(id);
|
|
5757
5851
|
this.fpsLimit = 120;
|
|
5758
5852
|
this.hdr = false;
|
|
5759
|
-
this
|
|
5760
|
-
this
|
|
5761
|
-
this
|
|
5762
|
-
this
|
|
5763
|
-
this
|
|
5853
|
+
this.#smooth = false;
|
|
5854
|
+
this.#delay = 0;
|
|
5855
|
+
this.#duration = 0;
|
|
5856
|
+
this.#lifeTime = 0;
|
|
5857
|
+
this.#firstStart = true;
|
|
5764
5858
|
this.started = false;
|
|
5765
5859
|
this.destroyed = false;
|
|
5766
|
-
this
|
|
5767
|
-
this
|
|
5860
|
+
this.#paused = true;
|
|
5861
|
+
this.#lastFrameTime = 0;
|
|
5768
5862
|
this.zLayers = 100;
|
|
5769
5863
|
this.pageHidden = false;
|
|
5770
|
-
this
|
|
5771
|
-
this
|
|
5864
|
+
this.#sourceOptions = sourceOptions;
|
|
5865
|
+
this.#initialSourceOptions = sourceOptions;
|
|
5772
5866
|
this.effectDrawers = new Map();
|
|
5773
5867
|
this.shapeDrawers = new Map();
|
|
5774
5868
|
this.particleUpdaters = [];
|
|
5775
5869
|
this.retina = new Retina(this);
|
|
5776
|
-
this.canvas = new CanvasManager(this
|
|
5777
|
-
this.particles = new ParticlesManager(this
|
|
5870
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
5871
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
5778
5872
|
this.plugins = [];
|
|
5779
5873
|
this.particleDestroyedPlugins = [];
|
|
5780
5874
|
this.particleCreatedPlugins = [];
|
|
5781
5875
|
this.particlePositionPlugins = [];
|
|
5782
|
-
this
|
|
5783
|
-
this.actualOptions = loadContainerOptions(this
|
|
5784
|
-
this
|
|
5876
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
5877
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
5878
|
+
this.#eventListeners = new EventListeners(this);
|
|
5785
5879
|
this.dispatchEvent(EventType.containerBuilt);
|
|
5786
5880
|
}
|
|
5787
5881
|
get animationStatus() {
|
|
5788
|
-
return !this
|
|
5882
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
5789
5883
|
}
|
|
5790
5884
|
get options() {
|
|
5791
|
-
return this
|
|
5885
|
+
return this.#options;
|
|
5792
5886
|
}
|
|
5793
5887
|
get sourceOptions() {
|
|
5794
|
-
return this
|
|
5888
|
+
return this.#sourceOptions;
|
|
5795
5889
|
}
|
|
5796
5890
|
addLifeTime(value) {
|
|
5797
|
-
this
|
|
5891
|
+
this.#lifeTime += value;
|
|
5798
5892
|
}
|
|
5799
5893
|
alive() {
|
|
5800
|
-
return !this
|
|
5894
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
5801
5895
|
}
|
|
5802
5896
|
destroy(remove = true) {
|
|
5803
5897
|
if (!guardCheck(this)) {
|
|
@@ -5819,13 +5913,13 @@
|
|
|
5819
5913
|
this.shapeDrawers = new Map();
|
|
5820
5914
|
this.particleUpdaters = [];
|
|
5821
5915
|
this.plugins.length = 0;
|
|
5822
|
-
this.
|
|
5916
|
+
this.#pluginManager.clearPlugins(this);
|
|
5823
5917
|
this.destroyed = true;
|
|
5824
|
-
this
|
|
5918
|
+
this.#onDestroy(remove);
|
|
5825
5919
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
5826
5920
|
}
|
|
5827
5921
|
dispatchEvent(type, data) {
|
|
5828
|
-
this
|
|
5922
|
+
this.#dispatchCallback(type, {
|
|
5829
5923
|
container: this,
|
|
5830
5924
|
data,
|
|
5831
5925
|
});
|
|
@@ -5835,12 +5929,12 @@
|
|
|
5835
5929
|
return;
|
|
5836
5930
|
}
|
|
5837
5931
|
let refreshTime = force;
|
|
5838
|
-
this
|
|
5932
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
5839
5933
|
if (refreshTime) {
|
|
5840
|
-
this
|
|
5934
|
+
this.#lastFrameTime = undefined;
|
|
5841
5935
|
refreshTime = false;
|
|
5842
5936
|
}
|
|
5843
|
-
this
|
|
5937
|
+
this.#nextFrame(timestamp);
|
|
5844
5938
|
});
|
|
5845
5939
|
}
|
|
5846
5940
|
async export(type, options = {}) {
|
|
@@ -5862,7 +5956,7 @@
|
|
|
5862
5956
|
return;
|
|
5863
5957
|
}
|
|
5864
5958
|
const allContainerPlugins = new Map();
|
|
5865
|
-
for (const plugin of this.
|
|
5959
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
5866
5960
|
const containerPlugin = await plugin.getPlugin(this);
|
|
5867
5961
|
if (containerPlugin.preInit) {
|
|
5868
5962
|
await containerPlugin.preInit();
|
|
@@ -5870,8 +5964,8 @@
|
|
|
5870
5964
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
5871
5965
|
}
|
|
5872
5966
|
await this.initDrawersAndUpdaters();
|
|
5873
|
-
this
|
|
5874
|
-
this.actualOptions = loadContainerOptions(this
|
|
5967
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5968
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5875
5969
|
this.plugins.length = 0;
|
|
5876
5970
|
this.particleDestroyedPlugins.length = 0;
|
|
5877
5971
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -5898,11 +5992,11 @@
|
|
|
5898
5992
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
5899
5993
|
this.hdr = hdr;
|
|
5900
5994
|
this.zLayers = zLayers;
|
|
5901
|
-
this
|
|
5902
|
-
this
|
|
5903
|
-
this
|
|
5995
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
5996
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
5997
|
+
this.#lifeTime = 0;
|
|
5904
5998
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
5905
|
-
this
|
|
5999
|
+
this.#smooth = smooth;
|
|
5906
6000
|
for (const plugin of this.plugins) {
|
|
5907
6001
|
await plugin.init?.();
|
|
5908
6002
|
}
|
|
@@ -5915,7 +6009,7 @@
|
|
|
5915
6009
|
this.dispatchEvent(EventType.particlesSetup);
|
|
5916
6010
|
}
|
|
5917
6011
|
async initDrawersAndUpdaters() {
|
|
5918
|
-
const pluginManager = this
|
|
6012
|
+
const pluginManager = this.#pluginManager;
|
|
5919
6013
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
5920
6014
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
5921
6015
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -5924,18 +6018,18 @@
|
|
|
5924
6018
|
if (!guardCheck(this)) {
|
|
5925
6019
|
return;
|
|
5926
6020
|
}
|
|
5927
|
-
if (this
|
|
5928
|
-
cancelAnimation(this
|
|
5929
|
-
|
|
6021
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6022
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6023
|
+
this.#drawAnimationFrame = undefined;
|
|
5930
6024
|
}
|
|
5931
|
-
if (this
|
|
6025
|
+
if (this.#paused) {
|
|
5932
6026
|
return;
|
|
5933
6027
|
}
|
|
5934
6028
|
for (const plugin of this.plugins) {
|
|
5935
6029
|
plugin.pause?.();
|
|
5936
6030
|
}
|
|
5937
6031
|
if (!this.pageHidden) {
|
|
5938
|
-
this
|
|
6032
|
+
this.#paused = true;
|
|
5939
6033
|
}
|
|
5940
6034
|
this.dispatchEvent(EventType.containerPaused);
|
|
5941
6035
|
}
|
|
@@ -5943,13 +6037,13 @@
|
|
|
5943
6037
|
if (!guardCheck(this)) {
|
|
5944
6038
|
return;
|
|
5945
6039
|
}
|
|
5946
|
-
const needsUpdate = this
|
|
5947
|
-
if (this
|
|
5948
|
-
this
|
|
6040
|
+
const needsUpdate = this.#paused || force;
|
|
6041
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6042
|
+
this.#firstStart = false;
|
|
5949
6043
|
return;
|
|
5950
6044
|
}
|
|
5951
|
-
if (this
|
|
5952
|
-
this
|
|
6045
|
+
if (this.#paused) {
|
|
6046
|
+
this.#paused = false;
|
|
5953
6047
|
}
|
|
5954
6048
|
if (needsUpdate) {
|
|
5955
6049
|
for (const plugin of this.plugins) {
|
|
@@ -5972,10 +6066,10 @@
|
|
|
5972
6066
|
if (!guardCheck(this)) {
|
|
5973
6067
|
return;
|
|
5974
6068
|
}
|
|
5975
|
-
this
|
|
5976
|
-
this
|
|
5977
|
-
this
|
|
5978
|
-
this.actualOptions = loadContainerOptions(this
|
|
6069
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6070
|
+
this.#sourceOptions = sourceOptions;
|
|
6071
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6072
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5979
6073
|
return this.refresh();
|
|
5980
6074
|
}
|
|
5981
6075
|
async start() {
|
|
@@ -5986,7 +6080,7 @@
|
|
|
5986
6080
|
this.started = true;
|
|
5987
6081
|
await new Promise(resolve => {
|
|
5988
6082
|
const start = async () => {
|
|
5989
|
-
this.
|
|
6083
|
+
this.#eventListeners.addListeners();
|
|
5990
6084
|
for (const plugin of this.plugins) {
|
|
5991
6085
|
await plugin.start?.();
|
|
5992
6086
|
}
|
|
@@ -5994,20 +6088,20 @@
|
|
|
5994
6088
|
this.play();
|
|
5995
6089
|
resolve();
|
|
5996
6090
|
};
|
|
5997
|
-
this
|
|
6091
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
5998
6092
|
});
|
|
5999
6093
|
}
|
|
6000
6094
|
stop() {
|
|
6001
6095
|
if (!guardCheck(this) || !this.started) {
|
|
6002
6096
|
return;
|
|
6003
6097
|
}
|
|
6004
|
-
if (this
|
|
6005
|
-
clearTimeout(this
|
|
6006
|
-
|
|
6098
|
+
if (this.#delayTimeout) {
|
|
6099
|
+
clearTimeout(this.#delayTimeout);
|
|
6100
|
+
this.#delayTimeout = undefined;
|
|
6007
6101
|
}
|
|
6008
|
-
this
|
|
6102
|
+
this.#firstStart = true;
|
|
6009
6103
|
this.started = false;
|
|
6010
|
-
this.
|
|
6104
|
+
this.#eventListeners.removeListeners();
|
|
6011
6105
|
this.pause();
|
|
6012
6106
|
this.particles.clear();
|
|
6013
6107
|
this.canvas.stop();
|
|
@@ -6017,7 +6111,7 @@
|
|
|
6017
6111
|
this.particleCreatedPlugins.length = 0;
|
|
6018
6112
|
this.particleDestroyedPlugins.length = 0;
|
|
6019
6113
|
this.particlePositionPlugins.length = 0;
|
|
6020
|
-
this
|
|
6114
|
+
this.#sourceOptions = this.#options;
|
|
6021
6115
|
this.dispatchEvent(EventType.containerStopped);
|
|
6022
6116
|
}
|
|
6023
6117
|
updateActualOptions() {
|
|
@@ -6029,23 +6123,23 @@
|
|
|
6029
6123
|
}
|
|
6030
6124
|
return refresh;
|
|
6031
6125
|
}
|
|
6032
|
-
|
|
6126
|
+
#nextFrame = (timestamp) => {
|
|
6033
6127
|
try {
|
|
6034
|
-
if (!this
|
|
6035
|
-
this
|
|
6036
|
-
timestamp < this
|
|
6128
|
+
if (!this.#smooth &&
|
|
6129
|
+
this.#lastFrameTime !== undefined &&
|
|
6130
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6037
6131
|
this.draw(false);
|
|
6038
6132
|
return;
|
|
6039
6133
|
}
|
|
6040
|
-
this
|
|
6041
|
-
updateDelta(this
|
|
6042
|
-
this.addLifeTime(this.
|
|
6043
|
-
this
|
|
6044
|
-
if (this.
|
|
6134
|
+
this.#lastFrameTime ??= timestamp;
|
|
6135
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6136
|
+
this.addLifeTime(this.#delta.value);
|
|
6137
|
+
this.#lastFrameTime = timestamp;
|
|
6138
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6045
6139
|
this.draw(false);
|
|
6046
6140
|
return;
|
|
6047
6141
|
}
|
|
6048
|
-
this.canvas.render.drawParticles(this
|
|
6142
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6049
6143
|
if (!this.alive()) {
|
|
6050
6144
|
this.destroy();
|
|
6051
6145
|
return;
|
|
@@ -6066,10 +6160,10 @@
|
|
|
6066
6160
|
});
|
|
6067
6161
|
|
|
6068
6162
|
class BlendPluginInstance {
|
|
6069
|
-
|
|
6070
|
-
|
|
6163
|
+
#container;
|
|
6164
|
+
#defaultCompositeValue;
|
|
6071
6165
|
constructor(container) {
|
|
6072
|
-
this
|
|
6166
|
+
this.#container = container;
|
|
6073
6167
|
}
|
|
6074
6168
|
drawParticleCleanup(context, particle) {
|
|
6075
6169
|
if (!particle.options.blend?.enable) {
|
|
@@ -6086,14 +6180,14 @@
|
|
|
6086
6180
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6087
6181
|
}
|
|
6088
6182
|
drawSettingsCleanup(context) {
|
|
6089
|
-
if (!this
|
|
6183
|
+
if (!this.#defaultCompositeValue) {
|
|
6090
6184
|
return;
|
|
6091
6185
|
}
|
|
6092
|
-
context.globalCompositeOperation = this
|
|
6186
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6093
6187
|
}
|
|
6094
6188
|
drawSettingsSetup(context) {
|
|
6095
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6096
|
-
this
|
|
6189
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6190
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6097
6191
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6098
6192
|
}
|
|
6099
6193
|
}
|
|
@@ -6236,11 +6330,11 @@
|
|
|
6236
6330
|
class MovePluginInstance {
|
|
6237
6331
|
availablePathGenerators;
|
|
6238
6332
|
pathGenerators;
|
|
6239
|
-
|
|
6240
|
-
|
|
6333
|
+
#container;
|
|
6334
|
+
#pluginManager;
|
|
6241
6335
|
constructor(pluginManager, container) {
|
|
6242
|
-
this
|
|
6243
|
-
this
|
|
6336
|
+
this.#pluginManager = pluginManager;
|
|
6337
|
+
this.#container = container;
|
|
6244
6338
|
this.availablePathGenerators = new Map();
|
|
6245
6339
|
this.pathGenerators = new Map();
|
|
6246
6340
|
}
|
|
@@ -6271,7 +6365,7 @@
|
|
|
6271
6365
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6272
6366
|
inverse: gravityOptions.inverse,
|
|
6273
6367
|
};
|
|
6274
|
-
initSpin(this
|
|
6368
|
+
initSpin(this.#container, particle);
|
|
6275
6369
|
}
|
|
6276
6370
|
particleDestroyed(particle) {
|
|
6277
6371
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6282,7 +6376,7 @@
|
|
|
6282
6376
|
if (!moveOptions.enable) {
|
|
6283
6377
|
return;
|
|
6284
6378
|
}
|
|
6285
|
-
const container = this
|
|
6379
|
+
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;
|
|
6286
6380
|
if (moveOptions.spin.enable) {
|
|
6287
6381
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6288
6382
|
}
|
|
@@ -6292,18 +6386,18 @@
|
|
|
6292
6386
|
applyDistance(particle);
|
|
6293
6387
|
}
|
|
6294
6388
|
preInit() {
|
|
6295
|
-
return this
|
|
6389
|
+
return this.#init();
|
|
6296
6390
|
}
|
|
6297
6391
|
redrawInit() {
|
|
6298
|
-
return this
|
|
6392
|
+
return this.#init();
|
|
6299
6393
|
}
|
|
6300
6394
|
update() {
|
|
6301
6395
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6302
6396
|
pathGenerator.update();
|
|
6303
6397
|
}
|
|
6304
6398
|
}
|
|
6305
|
-
async
|
|
6306
|
-
const availablePathGenerators = await this.
|
|
6399
|
+
async #init() {
|
|
6400
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6307
6401
|
if (!availablePathGenerators) {
|
|
6308
6402
|
return;
|
|
6309
6403
|
}
|
|
@@ -6321,44 +6415,44 @@
|
|
|
6321
6415
|
});
|
|
6322
6416
|
|
|
6323
6417
|
class EmittersPluginInstance {
|
|
6324
|
-
container;
|
|
6325
|
-
|
|
6418
|
+
#container;
|
|
6419
|
+
#instancesManager;
|
|
6326
6420
|
constructor(instancesManager, container) {
|
|
6327
|
-
this
|
|
6328
|
-
this
|
|
6329
|
-
this.
|
|
6421
|
+
this.#instancesManager = instancesManager;
|
|
6422
|
+
this.#container = container;
|
|
6423
|
+
this.#instancesManager.initContainer(container);
|
|
6330
6424
|
}
|
|
6331
6425
|
async init() {
|
|
6332
|
-
const emittersOptions = this
|
|
6426
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
6333
6427
|
if (isArray(emittersOptions)) {
|
|
6334
6428
|
for (const emitterOptions of emittersOptions) {
|
|
6335
|
-
await this.
|
|
6429
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
6336
6430
|
}
|
|
6337
6431
|
}
|
|
6338
6432
|
else {
|
|
6339
|
-
await this.
|
|
6433
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
6340
6434
|
}
|
|
6341
6435
|
}
|
|
6342
6436
|
pause() {
|
|
6343
|
-
for (const emitter of this.
|
|
6437
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6344
6438
|
emitter.pause();
|
|
6345
6439
|
}
|
|
6346
6440
|
}
|
|
6347
6441
|
play() {
|
|
6348
|
-
for (const emitter of this.
|
|
6442
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6349
6443
|
emitter.play();
|
|
6350
6444
|
}
|
|
6351
6445
|
}
|
|
6352
6446
|
resize() {
|
|
6353
|
-
for (const emitter of this.
|
|
6447
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6354
6448
|
emitter.resize();
|
|
6355
6449
|
}
|
|
6356
6450
|
}
|
|
6357
6451
|
stop() {
|
|
6358
|
-
this.
|
|
6452
|
+
this.#instancesManager.clear(this.#container);
|
|
6359
6453
|
}
|
|
6360
6454
|
update(delta) {
|
|
6361
|
-
this.
|
|
6455
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
6362
6456
|
emitter.update(delta);
|
|
6363
6457
|
});
|
|
6364
6458
|
}
|
|
@@ -6391,16 +6485,16 @@
|
|
|
6391
6485
|
|
|
6392
6486
|
const defaultIndex = 0;
|
|
6393
6487
|
class EmittersInstancesManager {
|
|
6394
|
-
|
|
6395
|
-
|
|
6488
|
+
#containerArrays;
|
|
6489
|
+
#pluginManager;
|
|
6396
6490
|
constructor(pluginManager) {
|
|
6397
|
-
this
|
|
6398
|
-
this
|
|
6491
|
+
this.#containerArrays = new Map();
|
|
6492
|
+
this.#pluginManager = pluginManager;
|
|
6399
6493
|
}
|
|
6400
6494
|
async addEmitter(container, options, position) {
|
|
6401
6495
|
const emitterOptions = new Emitter();
|
|
6402
6496
|
emitterOptions.load(options);
|
|
6403
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
6497
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
6404
6498
|
this.removeEmitter(container, emitter);
|
|
6405
6499
|
}, emitterOptions, position);
|
|
6406
6500
|
await emitter.init();
|
|
@@ -6409,22 +6503,22 @@
|
|
|
6409
6503
|
}
|
|
6410
6504
|
clear(container) {
|
|
6411
6505
|
this.initContainer(container);
|
|
6412
|
-
this.
|
|
6506
|
+
this.#containerArrays.set(container, []);
|
|
6413
6507
|
}
|
|
6414
6508
|
getArray(container) {
|
|
6415
6509
|
this.initContainer(container);
|
|
6416
|
-
let array = this.
|
|
6510
|
+
let array = this.#containerArrays.get(container);
|
|
6417
6511
|
if (!array) {
|
|
6418
6512
|
array = [];
|
|
6419
|
-
this.
|
|
6513
|
+
this.#containerArrays.set(container, array);
|
|
6420
6514
|
}
|
|
6421
6515
|
return array;
|
|
6422
6516
|
}
|
|
6423
6517
|
initContainer(container) {
|
|
6424
|
-
if (this.
|
|
6518
|
+
if (this.#containerArrays.has(container)) {
|
|
6425
6519
|
return;
|
|
6426
6520
|
}
|
|
6427
|
-
this.
|
|
6521
|
+
this.#containerArrays.set(container, []);
|
|
6428
6522
|
container.getEmitter = (idxOrName) => {
|
|
6429
6523
|
const array = this.getArray(container);
|
|
6430
6524
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -6493,34 +6587,34 @@
|
|
|
6493
6587
|
spawnStrokeColor;
|
|
6494
6588
|
spawnStrokeOpacity;
|
|
6495
6589
|
spawnStrokeWidth;
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6590
|
+
#container;
|
|
6591
|
+
#currentDuration;
|
|
6592
|
+
#currentEmitDelay;
|
|
6593
|
+
#currentSpawnDelay;
|
|
6594
|
+
#duration;
|
|
6595
|
+
#emitDelay;
|
|
6596
|
+
#firstSpawn;
|
|
6597
|
+
#immortal;
|
|
6598
|
+
#initialPosition;
|
|
6599
|
+
#lifeCount;
|
|
6600
|
+
#mutationObserver;
|
|
6601
|
+
#particlesOptions;
|
|
6602
|
+
#paused;
|
|
6603
|
+
#pluginManager;
|
|
6604
|
+
#removeCallback;
|
|
6605
|
+
#resizeObserver;
|
|
6606
|
+
#shape;
|
|
6607
|
+
#size;
|
|
6608
|
+
#spawnDelay;
|
|
6609
|
+
#startParticlesAdded;
|
|
6516
6610
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
6517
|
-
this
|
|
6518
|
-
this
|
|
6519
|
-
this
|
|
6520
|
-
this
|
|
6521
|
-
this
|
|
6522
|
-
this
|
|
6523
|
-
this
|
|
6611
|
+
this.#pluginManager = pluginManager;
|
|
6612
|
+
this.#container = container;
|
|
6613
|
+
this.#removeCallback = removeCallback;
|
|
6614
|
+
this.#currentDuration = 0;
|
|
6615
|
+
this.#currentEmitDelay = 0;
|
|
6616
|
+
this.#currentSpawnDelay = 0;
|
|
6617
|
+
this.#initialPosition = position;
|
|
6524
6618
|
if (options instanceof Emitter) {
|
|
6525
6619
|
this.options = options;
|
|
6526
6620
|
}
|
|
@@ -6528,159 +6622,159 @@
|
|
|
6528
6622
|
this.options = new Emitter();
|
|
6529
6623
|
this.options.load(options);
|
|
6530
6624
|
}
|
|
6531
|
-
this
|
|
6625
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
6532
6626
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
6533
6627
|
container.retina.reduceFactor
|
|
6534
6628
|
: Infinity;
|
|
6535
|
-
this.position = this
|
|
6629
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
6536
6630
|
this.name = this.options.name;
|
|
6537
6631
|
this.fill = this.options.fill;
|
|
6538
|
-
this
|
|
6539
|
-
this
|
|
6632
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
6633
|
+
this.#startParticlesAdded = false;
|
|
6540
6634
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
6541
6635
|
particlesOptions.move ??= {};
|
|
6542
6636
|
particlesOptions.move.direction ??= this.options.direction;
|
|
6543
6637
|
if (this.options.spawn.fill?.color) {
|
|
6544
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
6638
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
6545
6639
|
}
|
|
6546
6640
|
if (this.options.spawn.stroke?.color) {
|
|
6547
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
6548
|
-
}
|
|
6549
|
-
this
|
|
6550
|
-
this
|
|
6551
|
-
this
|
|
6552
|
-
this.size = getSize(this
|
|
6553
|
-
this
|
|
6554
|
-
this
|
|
6641
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
6642
|
+
}
|
|
6643
|
+
this.#paused = !this.options.autoPlay;
|
|
6644
|
+
this.#particlesOptions = particlesOptions;
|
|
6645
|
+
this.#size = this.#calcSize();
|
|
6646
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
6647
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
6648
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
6555
6649
|
if (this.options.domId) {
|
|
6556
6650
|
const element = safeDocument().getElementById(this.options.domId);
|
|
6557
6651
|
if (element) {
|
|
6558
|
-
this
|
|
6652
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
6559
6653
|
this.resize();
|
|
6560
6654
|
});
|
|
6561
|
-
this
|
|
6655
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
6562
6656
|
this.resize();
|
|
6563
6657
|
});
|
|
6564
|
-
this.
|
|
6658
|
+
this.#mutationObserver.observe(element, {
|
|
6565
6659
|
attributes: true,
|
|
6566
6660
|
attributeFilter: ["style", "width", "height"],
|
|
6567
6661
|
});
|
|
6568
|
-
this.
|
|
6662
|
+
this.#resizeObserver.observe(element);
|
|
6569
6663
|
}
|
|
6570
6664
|
}
|
|
6571
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
6665
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
6572
6666
|
if (shapeGenerator) {
|
|
6573
|
-
this
|
|
6667
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
6574
6668
|
}
|
|
6575
|
-
this.
|
|
6669
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
6576
6670
|
emitter: this,
|
|
6577
6671
|
});
|
|
6578
6672
|
this.play();
|
|
6579
6673
|
}
|
|
6580
6674
|
externalPause() {
|
|
6581
|
-
this
|
|
6675
|
+
this.#paused = true;
|
|
6582
6676
|
this.pause();
|
|
6583
6677
|
}
|
|
6584
6678
|
externalPlay() {
|
|
6585
|
-
this
|
|
6679
|
+
this.#paused = false;
|
|
6586
6680
|
this.play();
|
|
6587
6681
|
}
|
|
6588
6682
|
async init() {
|
|
6589
|
-
await this
|
|
6683
|
+
await this.#shape?.init();
|
|
6590
6684
|
}
|
|
6591
6685
|
pause() {
|
|
6592
|
-
if (this
|
|
6686
|
+
if (this.#paused) {
|
|
6593
6687
|
return;
|
|
6594
6688
|
}
|
|
6595
|
-
|
|
6689
|
+
this.#emitDelay = undefined;
|
|
6596
6690
|
}
|
|
6597
6691
|
play() {
|
|
6598
|
-
if (this
|
|
6692
|
+
if (this.#paused) {
|
|
6599
6693
|
return;
|
|
6600
6694
|
}
|
|
6601
|
-
if (!((this
|
|
6602
|
-
(this
|
|
6695
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
6696
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
6603
6697
|
return;
|
|
6604
6698
|
}
|
|
6605
|
-
const container = this
|
|
6606
|
-
if (this
|
|
6699
|
+
const container = this.#container;
|
|
6700
|
+
if (this.#emitDelay === undefined) {
|
|
6607
6701
|
const delay = getRangeValue(this.options.rate.delay);
|
|
6608
|
-
this
|
|
6702
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
6609
6703
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
6610
6704
|
: Infinity;
|
|
6611
6705
|
}
|
|
6612
|
-
if (this
|
|
6613
|
-
this
|
|
6706
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
6707
|
+
this.#prepareToDie();
|
|
6614
6708
|
}
|
|
6615
6709
|
}
|
|
6616
6710
|
resize() {
|
|
6617
|
-
const initialPosition = this
|
|
6711
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
6618
6712
|
this.position =
|
|
6619
6713
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
6620
6714
|
? initialPosition
|
|
6621
|
-
: this
|
|
6622
|
-
this
|
|
6623
|
-
this.size = getSize(this
|
|
6624
|
-
this
|
|
6715
|
+
: this.#calcPosition();
|
|
6716
|
+
this.#size = this.#calcSize();
|
|
6717
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
6718
|
+
this.#shape?.resize(this.position, this.size);
|
|
6625
6719
|
}
|
|
6626
6720
|
update(delta) {
|
|
6627
|
-
if (this
|
|
6721
|
+
if (this.#paused) {
|
|
6628
6722
|
return;
|
|
6629
6723
|
}
|
|
6630
|
-
const container = this
|
|
6631
|
-
if (this
|
|
6632
|
-
this
|
|
6633
|
-
this
|
|
6634
|
-
this
|
|
6724
|
+
const container = this.#container;
|
|
6725
|
+
if (this.#firstSpawn) {
|
|
6726
|
+
this.#firstSpawn = false;
|
|
6727
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
6728
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
6635
6729
|
}
|
|
6636
|
-
if (!this
|
|
6637
|
-
this
|
|
6638
|
-
this
|
|
6730
|
+
if (!this.#startParticlesAdded) {
|
|
6731
|
+
this.#startParticlesAdded = true;
|
|
6732
|
+
this.#emitParticles(this.options.startCount);
|
|
6639
6733
|
}
|
|
6640
|
-
if (this
|
|
6641
|
-
this
|
|
6642
|
-
if (this
|
|
6734
|
+
if (this.#duration !== undefined) {
|
|
6735
|
+
this.#currentDuration += delta.value;
|
|
6736
|
+
if (this.#currentDuration >= this.#duration) {
|
|
6643
6737
|
this.pause();
|
|
6644
|
-
if (this
|
|
6645
|
-
|
|
6738
|
+
if (this.#spawnDelay !== undefined) {
|
|
6739
|
+
this.#spawnDelay = undefined;
|
|
6646
6740
|
}
|
|
6647
|
-
if (!this
|
|
6648
|
-
this
|
|
6741
|
+
if (!this.#immortal) {
|
|
6742
|
+
this.#lifeCount--;
|
|
6649
6743
|
}
|
|
6650
|
-
if (this
|
|
6651
|
-
this.position = this
|
|
6652
|
-
this
|
|
6653
|
-
this
|
|
6744
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
6745
|
+
this.position = this.#calcPosition();
|
|
6746
|
+
this.#shape?.resize(this.position, this.size);
|
|
6747
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
6654
6748
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
6655
6749
|
container.retina.reduceFactor
|
|
6656
6750
|
: Infinity;
|
|
6657
6751
|
}
|
|
6658
6752
|
else {
|
|
6659
|
-
this
|
|
6753
|
+
this.#destroy();
|
|
6660
6754
|
}
|
|
6661
|
-
this
|
|
6662
|
-
|
|
6755
|
+
this.#currentDuration -= this.#duration;
|
|
6756
|
+
this.#duration = undefined;
|
|
6663
6757
|
}
|
|
6664
6758
|
}
|
|
6665
|
-
if (this
|
|
6666
|
-
this
|
|
6667
|
-
if (this
|
|
6668
|
-
this.
|
|
6759
|
+
if (this.#spawnDelay !== undefined) {
|
|
6760
|
+
this.#currentSpawnDelay += delta.value;
|
|
6761
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
6762
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
6669
6763
|
this.play();
|
|
6670
|
-
this
|
|
6671
|
-
|
|
6764
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
6765
|
+
this.#spawnDelay = undefined;
|
|
6672
6766
|
}
|
|
6673
6767
|
}
|
|
6674
|
-
if (this
|
|
6675
|
-
this
|
|
6676
|
-
if (this
|
|
6677
|
-
this
|
|
6678
|
-
this
|
|
6768
|
+
if (this.#emitDelay !== undefined) {
|
|
6769
|
+
this.#currentEmitDelay += delta.value;
|
|
6770
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
6771
|
+
this.#emit();
|
|
6772
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
6679
6773
|
}
|
|
6680
6774
|
}
|
|
6681
6775
|
}
|
|
6682
|
-
|
|
6683
|
-
const container = this
|
|
6776
|
+
#calcPosition() {
|
|
6777
|
+
const container = this.#container;
|
|
6684
6778
|
if (this.options.domId) {
|
|
6685
6779
|
const element = safeDocument().getElementById(this.options.domId);
|
|
6686
6780
|
if (element) {
|
|
@@ -6696,8 +6790,8 @@
|
|
|
6696
6790
|
position: this.options.position,
|
|
6697
6791
|
});
|
|
6698
6792
|
}
|
|
6699
|
-
|
|
6700
|
-
const container = this
|
|
6793
|
+
#calcSize() {
|
|
6794
|
+
const container = this.#container;
|
|
6701
6795
|
if (this.options.domId) {
|
|
6702
6796
|
const element = safeDocument().getElementById(this.options.domId);
|
|
6703
6797
|
if (element) {
|
|
@@ -6720,32 +6814,32 @@
|
|
|
6720
6814
|
return size;
|
|
6721
6815
|
})());
|
|
6722
6816
|
}
|
|
6723
|
-
|
|
6724
|
-
this
|
|
6725
|
-
this
|
|
6726
|
-
this
|
|
6727
|
-
this
|
|
6728
|
-
this
|
|
6729
|
-
this.
|
|
6817
|
+
#destroy = () => {
|
|
6818
|
+
this.#mutationObserver?.disconnect();
|
|
6819
|
+
this.#mutationObserver = undefined;
|
|
6820
|
+
this.#resizeObserver?.disconnect();
|
|
6821
|
+
this.#resizeObserver = undefined;
|
|
6822
|
+
this.#removeCallback(this);
|
|
6823
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
6730
6824
|
emitter: this,
|
|
6731
6825
|
});
|
|
6732
6826
|
};
|
|
6733
|
-
|
|
6734
|
-
if (this
|
|
6827
|
+
#emit() {
|
|
6828
|
+
if (this.#paused) {
|
|
6735
6829
|
return;
|
|
6736
6830
|
}
|
|
6737
6831
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
6738
|
-
this
|
|
6832
|
+
this.#emitParticles(quantity);
|
|
6739
6833
|
}
|
|
6740
|
-
|
|
6741
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
6834
|
+
#emitParticles(quantity) {
|
|
6835
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
6742
6836
|
{}), 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
|
|
6743
6837
|
? defaultOpacity$1
|
|
6744
6838
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
6745
6839
|
? defaultOpacity$1
|
|
6746
6840
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
6747
6841
|
? defaultStrokeWidth
|
|
6748
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
6842
|
+
: 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;
|
|
6749
6843
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
6750
6844
|
const particlesOptions = needsCopy
|
|
6751
6845
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -6756,23 +6850,23 @@
|
|
|
6756
6850
|
this.spawnStrokeWidth = strokeWidth;
|
|
6757
6851
|
if (this.spawnFillColor) {
|
|
6758
6852
|
if (fillHslAnimation && maxValues) {
|
|
6759
|
-
this.spawnFillColor.h = this
|
|
6760
|
-
this.spawnFillColor.s = this
|
|
6761
|
-
this.spawnFillColor.l = this
|
|
6853
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
6854
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
6855
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
6762
6856
|
}
|
|
6763
6857
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
6764
6858
|
}
|
|
6765
6859
|
if (this.spawnStrokeColor) {
|
|
6766
6860
|
if (strokeHslAnimation && maxValues) {
|
|
6767
|
-
this.spawnStrokeColor.h = this
|
|
6768
|
-
this.spawnStrokeColor.s = this
|
|
6769
|
-
this.spawnStrokeColor.l = this
|
|
6861
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
6862
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
6863
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
6770
6864
|
}
|
|
6771
6865
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
6772
6866
|
}
|
|
6773
6867
|
let position = this.position;
|
|
6774
|
-
if (this
|
|
6775
|
-
const shapePosData = this.
|
|
6868
|
+
if (this.#shape) {
|
|
6869
|
+
const shapePosData = this.#shape.randomPosition();
|
|
6776
6870
|
if (shapePosData) {
|
|
6777
6871
|
position = shapePosData.position;
|
|
6778
6872
|
const replaceData = shapeOptions.replace;
|
|
@@ -6785,21 +6879,21 @@
|
|
|
6785
6879
|
}
|
|
6786
6880
|
}
|
|
6787
6881
|
if (position) {
|
|
6788
|
-
this.
|
|
6882
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
6789
6883
|
}
|
|
6790
6884
|
}
|
|
6791
6885
|
}
|
|
6792
|
-
|
|
6793
|
-
if (this
|
|
6886
|
+
#prepareToDie = () => {
|
|
6887
|
+
if (this.#paused) {
|
|
6794
6888
|
return;
|
|
6795
6889
|
}
|
|
6796
6890
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
6797
|
-
if ((this
|
|
6798
|
-
this
|
|
6891
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
6892
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
6799
6893
|
}
|
|
6800
6894
|
};
|
|
6801
|
-
|
|
6802
|
-
const container = this
|
|
6895
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
6896
|
+
const container = this.#container;
|
|
6803
6897
|
if (!animation.enable) {
|
|
6804
6898
|
return initValue;
|
|
6805
6899
|
}
|